Skip to content

Latest commit

 

History

History
130 lines (101 loc) · 14.5 KB

OVERVIEW.md

File metadata and controls

130 lines (101 loc) · 14.5 KB

gflow-cli Agent Overview

Read this brief once per session. When an error occurs, read only the topic named in error.docs (gflow docs <topic> on CLI, gflow://docs/<topic> on MCP).

gflow-cli automates Google Flow over two equivalent surfaces backed by the same core and local SQLite catalog (gflow.db):

  • CLI: gflow ... --json prints machine-readable JSON ({"status": "ok"|"fail", ...}) and maps failures to typed exit codes.
  • MCP server: gflow mcp run (stdio) and gflow serve (Streamable HTTP at /mcp) expose tools returning structured JSON envelopes with isError: true on failure. Do not shell out to gflow ... from an MCP client when the equivalent MCP tool exists.

1. Discovery Before Acting

Inspect capabilities, schemas, and active models offline before building prompts or parameters:

Need CLI MCP
Full command/tool schema gflow --help --json tools/list
Feature support matrix (yes/no/partial/unknown) gflow capabilities --json resource capabilities://self
Active models, aliases, caps, durations, retires_on gflow models list --json gflow_list_models
Prompt-rewriting tools (creative-director) gflow tools list --json gflow_list_tools
Topic index / read one doc page gflow docs / gflow docs <topic> gflow://docs / gflow://docs/{topic}
Read one ## section of a long page (MCP-only; gflow docs <topic> prints the whole page) gflow://docs/{topic}/{section}
Search all bundled docs by line gflow docs --search "<terms>" (CLI-only; reads wheel-bundled docs/)
Known issues index / section gflow docs known-issues gflow://docs/known-issues / .../{slug}

Use gflow generations list images or videos to find a media ID, generations show to inspect it, and generations purge --dry-run to preview stale file records. These alias data list, data media, and data prune. For video recovery, gflow download MEDIA_ID aliases gflow data download MEDIA_ID (MCP gflow_download_media).

Preflight auth without spending credits: call gflow auth status --json / gflow_auth_status before paid work. Authentication itself (gflow auth login --browser chrome) is interactive CLI-only.

Model deprecation check: inspect retires_on in gflow models list --json or gflow_list_models and prefer models where retires_on is null (such as veo-lite or omni-1.2-flash when listed).


2. Generation Modes, Frames, References, and Characters

How a generation runs. Measured request shapes (text-to-image, image-to-image with one in-project reference or one saved character, gflow run image rows without a reference, text-to-video at measured settings, image-to-video from a local start frame, 1080p upscale) go over direct HTTP: Chrome starts headless only to mint the reCAPTCHA token, and the request leaves without driving Flow's UI. Other shapes drive Flow's UI, headless where measured and headed otherwise (BROWSER_MODES). Every result reports route (direct or ui), visibility (headless or headed) and retried; GFLOW_CLI_BROWSER_VISIBILITY=auto|headless|headed overrides the mode.

Images

  • Modes: image t2i (text-to-image), image i2i (image-to-image with --ref), image generate (bridge verb resolving to t2i or i2i), or MCP gflow_generate_image.
  • Aspects: 1:1, 9:16, 16:9, 4:3, 3:4. Count: 1–4 per call.
  • Partial saves (CLI exit 80): if --count > 1 saves some images before a download fails, CLI exits 80 (partial: true, missing_media_ids: [...]) and MCP returns completed with missing_media_ids; save missing images from the Flow project (gflow download / gflow_download_media currently recover videos only). movie run exits 80 when some scenes' clips are on disk and others are not; a re-run downloads the billed ones without a new generation (#1717). A run stopped by --fail-fast or the credit cap exits with that error's code instead.
  • Image upscale: image upscale / gflow_upscale_image (2k or Ultra-gated 4k; runs in a headed Chrome session by default).

Videos

  • Modes: video t2v (text-to-video), video i2v (start frame + optional --end-frame), video r2v (reference-to-video via --ref / saved characters), video generate (bridge verb), video extend, video edit, video chain, or MCP gflow_generate_video / gflow_extend_video / gflow_edit_video; a multi-scene manifest runs with gflow movie run or MCP gflow_movie_run.
  • Aspects: 9:16 (portrait) or 16:9 (landscape) — no square video.
  • A local clip plus reference images is video edit (gflow video edit <clip> "<prompt>" --ref <image>, MCP gflow_edit_video), not r2v: video r2v / video gen with a clip in --ref exit 2, and gflow_generate_video with a clip in reference_images returns bad-parameter, both naming the edit command.
  • Mutually exclusive inputs: never combine a start/end frame (--initial-frame / initial_frame / --end-frame) with reference images/entities (--ref / reference_images / reference_entities); CLI refuses with exit 2 and MCP returns bad-parameter.
  • Wait vs async tasks (MCP): generation tools default to wait=true (blocks until completion, which may hit client timeouts on long videos). Pass wait=false to enqueue and poll tasks/get (cancel pre-submit with tasks/cancel or gflow cancel <task_id>).

Host & Reference Constraints (flow.google.com)

When an account is served on flow.google.com (GFLOW_CLI_FLOW_HOST=auto, default):

  • Same-project scoping: reusing a catalogued image media UUID (image i2i --ref, video i2v frames, video extend, video edit) requires --project <project_id> (or matching catalog row) and only accepts captioned UUIDs catalogued in that same project. Cross-project or uncaptioned UUIDs fail with exit 36 (FlowHostMigratedError).
  • Characters:
    • image t2i/i2i and gflow_generate_image reference characters inline in the prompt using @Name (character list / gflow_character_list gives IDs and names).
    • video r2v and gflow_generate_video(mode="r2v") pass character IDs (--reference-entity / reference_entities) paired 1-to-1 in order with their display names (--reference-entity-name / reference_entity_names). Passing an ID without its matching name fails pre-submit.
    • A t2v with a character is refused before submit (exit 36); use r2v, which runs with a character alone, and video generate --reference-entity routes there. i2v takes no characters (the CLI has no --reference-entity on it).
  • Host limitations on flow.google.com (exit 36): on an account served flow.google.com, gflow cannot drive chains, agentic instructions, image batch, or cross-project references yet (next_action: none). video edit targets flow.google.com with Omni models; editing an existing clip by media UUID can fail with exit 23 (#1605, open), while a local clip reached its checked jIps6 request in a $0 e2e with the submit aborted (2026-12-01); and with a media UUID source, reference_images are refused.
  • Output path safety (MCP): out_file on MCP tools must resolve inside GFLOW_CLI_OUTPUT_DIR (relative filenames are safest); path traversal outside it fails pre-submit.

3. Credits, Quotas, and Spend Safety

  • What spends Veo credits: Veo/Omni video generations (t2v, i2v, r2v, extend, edit, chain), character create --face-prompt, and 4k video upscales (video upscale --scale 4k, Ultra only).
  • What spends 0 Flow credits:
    • Images (t2i, i2i, 2k upscale): draw from a per-model daily image quota, not Veo credits.
    • Free utilities: auth status|renew, credits user|list, models, capabilities, docs, data list|stats|download, media trash|restore, scene create --out-file, instructions, character create --image, video upscale (720p/1080p/270p), video assemble, video captions, video transcribe, audio narrate.
  • Pre-submit credit cap: pass --max-credits N (max_credits on MCP, or env GFLOW_CLI_MAX_CREDITS) on billed video commands to inspect Flow's quote before submit. Unreadable or over-cap quotes abort pre-submit with exit 45 (CreditCapExceededError, charged: no).
  • No-spend MCP mode: running gflow mcp run --no-spend (or GFLOW_MCP_NO_SPEND=1) unregisters the credit-spending tools (gflow_generate_image, gflow_generate_video, gflow_upscale_video, gflow_extend_video, gflow_edit_video, gflow_movie_run). gflow_upscale_image stays registered for 2k, which uses the image quota and spends zero Flow credits. It refuses 4k before opening a browser because the credit cost is unknown.
  • Golden rule on failures — NEVER auto-resend ambiguous writes: Every error envelope carries charged (no | maybe | yes) and next_action. A billed video or image submit carries a single-use reCAPTCHA token and is sent at most once (reconcile). If charged is maybe or yes, inspect the project (gflow data list / Flow UI / operation_id) before regenerating to avoid double-billing.

4. Error Envelopes, next_action, and Exit Codes

Every failure follows RFC 9457: CLI --json returns {"status": "fail", "error": {...}} (except non-interactive gflow media trash --json without --yes, which emits the ProblemDetails object bare at top level) and MCP tools return {"status": ..., "error": {...}} with isError: true. Branch on isError, not on the status string: error, failed, rate_limited and invalid_tools are all failures. A call that fails the tool's input schema returns isError: true with a plain validation message and no envelope. When parsing CLI JSON failures, fall back to reading top-level fields (type, docs, etc.) if "error" is absent.

Key members: type, title, detail, remediation_hint, charged (no|maybe|yes), next_action, retryable, operation_id (when known), completed_media_ids (clips Flow accepted before a failure, when any), and docs (gflow docs <topic> on CLI, gflow://docs/<topic> on MCP).

next_action Decision Table

next_action retryable What the agent should do
retry true Safe to re-run the same call (charged is no or pre-submit)
retry_after true Wait at least retry_after seconds (if present), then retry
wait false Wait for external condition (credits reset, ProfileLockedError lock holder)
reauth false Ask user to run gflow auth login --browser chrome (or --profile <name>)
fix_input false Fix arguments, model/mode compatibility, output path, or --max-credits
reconcile false Do not resend. Check Flow project / operation_id / gflow data download <id>
none false Terminal / capability unavailable (tier gate, host limitation, local abort)

Exit Code Families (CLI)

Set GFLOW_CLI_EXIT_CODES=2 for the v2 stable core (remaps 4–7 and 9 -> 40–44, and 8 -> 3).

Legacy Mode 2 Family / Typical Cause Action
0 0 Success (or gflow cancel aborted pre-submit) Continue
1 1 General FlowApiError, RecaptchaError, VideoAssemblyError, unexpected crash Inspect type & docs
2 2 Invalid CLI usage, mutually exclusive flags, missing confirmation Fix arguments
3, 8 3 AuthExpiredError / AisandboxAuthError / AuthMissingError reauth
4 40 RateLimitError (quota or rate limit) retry_after / switch model
5 41 ContentPolicyError (safety filter rejected prompt/media) Reword prompt (fix_input)
6 42 NetworkError / MediaDownloadError retry or data download
7 43 WireFormatError / RpcResponseUnavailableError Check docs & reconcile
9 44 TransportTimeoutError retry if charged: no, else reconcile
10 10 WafRejectionError (HTTP 403 / UNUSUAL_ACTIVITY cooldown) Check ACCOUNT_SAFETY.md
11 11 ConfigurationError, ProfileLockedError, ProfileAccessError, ProfileEngineDowngradeError Fix config/profile or wait
12, 14, 38 12, 14, 38 Interactive login timeout / browser rejected / account chooser reauth (--browser chrome)
13 13 SecurityError (path escapes GFLOW_CLI_HOME or GFLOW_CLI_OUTPUT_DIR) Fix path
15 15 BrowserSessionClosedError / RelaunchFailed retry
16, 34 16, 34 DataStoreError, SyncPartialError Check DATA_LAYER.md
29, 30 29, 30 MentionIndexUnavailableError, QueueSchemaError Check ERRORS.md
17–20 17–20 Model/mode mismatch (17), model picker failed (18), concat/frame processing (19–20) Check input/codecs
21 21 ChainPartialError (earlier links billed & saved) Resume with --resume-from
22, 35, 36, 39 22, 35, 36, 39 Tier/capability gate (upscale-unavailable, extend-unavailable, flow-host-migrated, flow-access-unavailable) Terminal for this call
22 22 ServerCancelUnavailableError (server-cancel-unavailable: the job was already submitted, so Flow may still charge it) reconcile
23, 25, 28, 31 23, 25, 28, 31 UI selector drift (23), Agent UI (25), UI mode unavailable (28), Flow app error (31) Check BROWSER_MODES.md / DEBUGGING.md
24 24 Browser engine unavailable Check CONFIGURATION.md
26, 27 26, 27 Media attribution (26), upload rejected (27) Check ERRORS.md
32 32 Reference not found Check MEDIA_LIBRARY.md
33 33 gflow doctor findings present (diagnostic status, not an error class) Read findings
37 37 InsufficientCreditsError (account credits too low for selected model) wait / cheaper model
45 45 CreditCapExceededError (quote unreadable or above --max-credits) Ask user before raising cap, or pick cheaper model
80 80 Partial image t2i/i2i save (--count > 1), or a movie run that delivered some scenes but not all Download missing_media_ids; re-run the movie to fetch billed scenes

Follow the docs pointer: whenever an error includes "docs": "gflow docs <topic>" or "docs": "gflow://docs/<topic>", fetch that single topic first rather than guessing flags or retrying blindly.