Skip to content

codegen: honor x-cli-default for per-surface flag defaults#151

Open
ivanbezborodov-heygen wants to merge 2 commits into
mainfrom
feat/cli-default-extension
Open

codegen: honor x-cli-default for per-surface flag defaults#151
ivanbezborodov-heygen wants to merge 2 commits into
mainfrom
feat/cli-default-extension

Conversation

@ivanbezborodov-heygen
Copy link
Copy Markdown
Collaborator

Description

context thread
The HTTP API and the CLI sometimes want different defaults for the same field. aspect_ratio is the immediate motivator: the API defaults to 16:9 for backwards compatibility, but agent-driven CLI flows are better off defaulting to auto so the canvas tracks the source orientation by default.

EF authors signal this from the Pydantic field via json_schema_extra={"x-cli-default": "auto"}, which lands verbatim on the schema property in openapi/external-api.json. This change teaches the CLI codegen to prefer x-cli-default over default when present.

Mechanics:

  • New schemaCliDefault helper mirrors the style of isCliVisible / isCliAction. It returns (value, ok) so callers can distinguish "no default at all" from "explicit null default".
  • Both default-reader sites in GroupEndpoints (query params, JSON body fields) route through the helper. The else-arm preserves the prior s.Default/prop.Default behavior, so this is a no-op on any spec that doesn't carry x-cli-default.

gen/ is intentionally untouched in this PR. The auto-sync workflow will regenerate it after the EF PR carrying the x-cli-default override merges, and the next sync output will flip --aspect-ratio's default to auto automatically.

Testing

  • Tests:
    • TestSchemaCliDefault table-drives the precedence rules (extension wins over default, missing both returns ok=false, x-mcp-default is intentionally ignored).
    • TestGroupEndpoints_BodyFlagsRespectXCliDefault runs end-to-end on a test spec with both an override field (aspect_ratio) and a fallback control (fps).
  • Test spec gains those two fields on the POST /v3/videos body.

The HTTP API and the CLI sometimes want different defaults for the same
field. ``aspect_ratio`` is the immediate motivator: the API defaults to
``16:9`` for backwards compatibility, but agent-driven CLI flows are
better off defaulting to ``auto`` so the canvas tracks the source
orientation by default.

EF authors signal this from the Pydantic field via
``json_schema_extra={"x-cli-default": "auto"}``, which lands verbatim on
the schema property in ``openapi/external-api.json``. This change teaches
the CLI codegen to prefer ``x-cli-default`` over ``default`` when present.

Mechanics:

- New ``schemaCliDefault`` helper mirrors the style of ``isCliVisible`` /
  ``isCliAction``. It returns ``(value, ok)`` so callers can distinguish
  "no default at all" from "explicit null default".
- Both default-reader sites in ``GroupEndpoints`` (query params, JSON body
  fields) route through the helper. The else-arm preserves the prior
  ``s.Default``/``prop.Default`` behavior, so this is a no-op on any spec
  that doesn't carry ``x-cli-default``.
- Tests:
  - ``TestSchemaCliDefault`` table-drives the precedence rules (extension
    wins over default, missing both returns ok=false, x-mcp-default is
    intentionally ignored).
  - ``TestGroupEndpoints_BodyFlagsRespectXCliDefault`` runs end-to-end on
    a test spec with both an override field (``aspect_ratio``) and a
    fallback control (``fps``).
- Test spec gains those two fields on the ``POST /v3/videos`` body.

``gen/`` is intentionally untouched in this PR. The auto-sync workflow
will regenerate it after the EF PR carrying the ``x-cli-default``
override merges, and the next sync output will flip
``--aspect-ratio``'s default to ``auto`` automatically.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ivanbezborodov-heygen ivanbezborodov-heygen self-assigned this May 22, 2026
The 2026-05-22 vuln database publishes GO-2026-5018, a DoS in
``golang.org/x/crypto/ssh.ParsePublicKey`` triggered by pathological
RSA/DSA parameters. Govulncheck flags us via
``internal/output/spinner.go:72`` → ``sync.Once.Do`` →
``ssh.ParsePublicKey``. Fixed in ``x/crypto`` v0.52.0.

This is a pure dependency bump — ``go mod tidy`` floats a few sibling
modules (``x/sync``, ``x/sys``, ``x/term``, ``x/text``) to compatible
versions, all indirect, no API surface affected. All tests pass and
``govulncheck ./...`` is clean.

Bundled into this PR because the same advisory will block every
incoming PR (auto-sync included) until the bump lands; splitting it
out adds a forced merge ordering without any review benefit.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Copy Markdown
Collaborator

@somanshreddy somanshreddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking on the CLI default behavior: this currently only changes the generated Cobra flag default/help, not the request payload sent when the user omits the flag.

schemaCliDefault writes the extension value into FlagSpec.Default in codegen/grouper.go, and registerFlag uses that as the Cobra default. But BuildInvocation explicitly skips every flag where cmd.Flags().Changed(flag.Name) is false, so an omitted --aspect-ratio is not added to the body at all. The API then receives no aspect_ratio and applies its HTTP default (16:9), not the intended CLI default (auto).

So after EF regenerates --aspect-ratio with Default: "auto", heygen video create ... without --aspect-ratio will still behave like API default 16:9; only the help/default display changes.

I think the fix needs to distinguish API defaults from CLI override defaults, then materialize only CLI override defaults into the invocation even when the flag was not explicitly changed. Ordinary OpenAPI default values should probably keep the existing omit-unless-changed behavior so the CLI does not start sending every server default back to the API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants