Skip to content

fix(cli): validate --model on intents; add --stdin, -f/--file, and --system - #111

Merged
copybara-service[bot] merged 1 commit into
mainfrom
copybara/1000412110
Oct 19, 2026
Merged

copybara-service[bot] merged 1 commit into
mainfrom
copybara/1000412110

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

fix(cli): validate --model on intents; add --stdin, -f/--file, and --system

Bring the generated Create intents (generate, image, video, music) and agent run in line with the hand-written porcelain (tts, analyze, transcribe) on --model validation and text/media input handling:

  • --model validation:
    • Hold an explicit --model override on generate, image, video, music, and agent run to the single-segment model ID contract (normalizeModelFlag), rejecting malformed model IDs with CLI_VALIDATION (exit 2) before any request and stripping a models/ prefix in-place. Unset or blank flags fall back to the command's default.
  • --stdin and -f/--file text input:
    • Add --stdin to generate, image, video, music, and analyze to read stdin to EOF as prompt text rather than a JSON request body. Add -f/--file to music (generate, image, video, and analyze already accept text files via -i/--input).
    • When supplied alone, the text becomes the prompt; alongside a positional prompt (or analyze question), it is placed as a text content block ahead of the positional prompt and after any -i media, and merges into --body input.
    • Reject --stdin combined with --body @-, --stdin combined with -f, empty stdin, or unreadable files as CLI_VALIDATION (exit 2).
    • Without --stdin, piped stdin remains the JSON request body; when piped stdin fails JSON unmarshaling on commands supporting --stdin, hint to pass --stdin for prompt text.
    • Update the README.md command table to list --stdin, -f/--file, and --system, and remove the unimplemented -f/--file entry from analyze.
  • Request-input registration, --resume precedence, and analyze positional media hint:
    • Mark -i/--input, --mime-type, -f/--file, and --stdin as request inputs (flagutil.MarkRequestInput) in attachIntentInputs so an open, silent stdin pipe does not stall for 1s when input is already supplied via -i or -f.
    • Check flagutil.IsAsyncResume in attachIntentInputs before resolving -i media or reading --stdin so video --resume <id> immediately reports conflicting create flags (--input, --stdin, --model) without network calls or stdin reads.
    • When analyze is invoked without --input or --stdin and the first positional argument is media (classifyMediaInput), report that it is media rather than a question and hint gemini-api analyze -i <path> [question].
  • --system on generate (OAD overlay & regenerated CLI):
    • Declare system ($.system_instruction) on the generate intent in overlays/cli/commands.yaml.
    • Trim one redundant flag summary line from the image and video command descriptions in overlays/cli/commands.yaml so adding --stdin keeps image --help and video --help within the 40-line help budget.
    • Regenerate specs/genai/openapi_cli.with-overlays.json, internal/cli/agent/intent_{generate,image,video}.go, and internal/usage/schema.go.
  • Tests:
    • Add contract tests in tests/contract/intent_inputs_test.go, tests/contract/porcelain_inputs_test.go, tests/contract/async_contract_test.go, and tests/contract/stdin_deadline_test.go.

@copybara-service
copybara-service Bot requested a review from a team October 15, 2026 21:58
@copybara-service
copybara-service Bot force-pushed the copybara/1000412110 branch 2 times, most recently from 9cf5fda to a93cf07 Compare October 19, 2026 17:58
…system

Bring the generated Create intents (`generate`, `image`, `video`, `music`) and `agent run` in line with the hand-written porcelain (`tts`, `analyze`, `transcribe`) on `--model` validation and text/media input handling:

- **`--model` validation**:
  - Hold an explicit `--model` override on `generate`, `image`, `video`, `music`, and `agent run` to the single-segment model ID contract (`normalizeModelFlag`), rejecting malformed model IDs with `CLI_VALIDATION` (exit 2) before any request and stripping a `models/` prefix in-place. Unset or blank flags fall back to the command's default.
- **`--stdin` and `-f`/`--file` text input**:
  - Add `--stdin` to `generate`, `image`, `video`, `music`, and `analyze` to read `stdin` to EOF as prompt text rather than a JSON request body. Add `-f`/`--file` to `music` (`generate`, `image`, `video`, and `analyze` already accept text files via `-i`/`--input`).
  - When supplied alone, the text becomes the prompt; alongside a positional prompt (or `analyze` question), it is placed as a text content block ahead of the positional prompt and after any `-i` media, and merges into `--body` input.
  - Reject `--stdin` combined with `--body @-`, `--stdin` combined with `-f`, empty `stdin`, or unreadable files as `CLI_VALIDATION` (exit 2).
  - Without `--stdin`, piped `stdin` remains the JSON request body; when piped `stdin` fails JSON unmarshaling on commands supporting `--stdin`, hint to pass `--stdin` for prompt text.
  - Update the `README.md` command table to list `--stdin`, `-f`/`--file`, and `--system`, and remove the unimplemented `-f`/`--file` entry from `analyze`.
- **Request-input registration, `--resume` precedence, and `analyze` positional media hint**:
  - Mark `-i`/`--input`, `--mime-type`, `-f`/`--file`, and `--stdin` as request inputs (`flagutil.MarkRequestInput`) in `attachIntentInputs` so an open, silent `stdin` pipe does not stall for 1s when input is already supplied via `-i` or `-f`.
  - Check `flagutil.IsAsyncResume` in `attachIntentInputs` before resolving `-i` media or reading `--stdin` so `video --resume <id>` immediately reports conflicting create flags (`--input`, `--stdin`, `--model`) without network calls or `stdin` reads.
  - When `analyze` is invoked without `--input` or `--stdin` and the first positional argument is media (`classifyMediaInput`), report that it is media rather than a question and hint `gemini-api analyze -i <path> [question]`.
- **`--system` on `generate` (OAD overlay & regenerated CLI)**:
  - Declare `system` (`$.system_instruction`) on the `generate` intent in `overlays/cli/commands.yaml`.
  - Trim one redundant flag summary line from the `image` and `video` command descriptions in `overlays/cli/commands.yaml` so adding `--stdin` keeps `image --help` and `video --help` within the 40-line help budget.
  - Regenerate `specs/genai/openapi_cli.with-overlays.json`, `internal/cli/agent/intent_{generate,image,video}.go`, and `internal/usage/schema.go`.
- **Tests**:
  - Add contract tests in `tests/contract/intent_inputs_test.go`, `tests/contract/porcelain_inputs_test.go`, `tests/contract/async_contract_test.go`, and `tests/contract/stdin_deadline_test.go`.

PiperOrigin-RevId: 1002456205
@copybara-service
copybara-service Bot merged commit c31b06e into main Oct 19, 2026
4 checks passed
@copybara-service
copybara-service Bot deleted the copybara/1000412110 branch October 19, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants