Skip to content

feat(cli): let declarative command flags imply other request body values - #139

Open
TristanSpeakEasy wants to merge 2 commits into
mainfrom
feat/cli-flag-implies
Open

TristanSpeakEasy wants to merge 2 commits into
mainfrom
feat/cli-flag-implies

Conversation

@TristanSpeakEasy

@TristanSpeakEasy TristanSpeakEasy commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Why

Some APIs pair a background: true request flag with a stream property whose schema default is true. A declarative intent command can expose both as flags, but there was no way to say that --background should turn streaming off. The command therefore sent {"background": true, "stream": true}, stayed attached to the event stream and blocked until the run finished, instead of returning the created resource and its ID straight away. Dispatch (multi-route) commands also have no stream toggle, so neither a preset nor a flag default could express it.

What changed

Flags in x-speakeasy-cli-commands accept an implies: map of root-level body values to fill in when the request body sets the flag's own property to true:

flags:
  background: {to: $.background, implies: {$.stream: false}}
  • Decode (internal/extensions/cli_commands.go): implies is rejected on positional args and on operations: flags, requires the flag to bind a root-level body property, and cannot set the flag's own property.
  • Link (cli_commands_link.go): the flag must be a bool, and every implied property must exist on each request variant that declares the flag and normalise to the same value, so one runtime rule serves every route.
  • Runtime: flagutil.ApplyImpliedBody runs after --body/stdin, declared inputs and presets are merged. It applies to both --background and --body '{"background":true}', and never overrides a key the request already carries (an explicit --stream wins).
  • Wiring in includes/intents.ts and intentcmd.go.stmpl, documented in the CLI README, covered by TestCLICommands_FlagImplies.
  • Review SDK regenerated (only the new flagutil helper changes, since the review spec does not use implies:); changeset added.

Testing

  • go test ./internal/extensions/: passes.
  • TARGET=review make test-cli, make check-template-cli, make lint: pass.
  • Generated a CLI from a document with a two-route create operation (stream defaulting to true, background on both routes) plus implies: {$.stream: false} on background, and checked the --dry-run -o json body:
Invocation background stream
run hi --background true false
run hi --background on the second route true false
run hi --background --stream true true
run hi (unset) true
run hi --background=false false true
--body '{"input":"hi","background":true}' (and via stdin) true false
--body '{"input":"hi","background":true,"stream":true}' true true

With stream: false the request also negotiates the JSON response, so the command prints the created resource and exits.

Public-safety check

  • This change contains no credentials, customer documents, private repository URLs, private filesystem paths, or unredacted private logs.
  • Title, body, comments, and commit messages name no customers or customer-derived identifiers, private paths or trackers, or workflow provenance, and are understandable without private context (.claude/skills/public-repo-communication/SKILL.md).
  • Generated fixtures and review SDK changes are public-safe.
  • I reviewed git diff --check.

Summary by cubic

Adds an implies map to declarative command flags (x-speakeasy-cli-commands) so a bool flag can fill other root-level body values when set. This lets --background also send stream: false, so the command returns the created resource instead of blocking on the event stream.

New Features

  • Flags may declare implies: {$.stream: false}; the runtime applies it after merging --body/stdin, declared inputs, and presets, and never overrides a key already set.
  • The linker requires every implied property to exist on each request variant that declares the flag and normalize to the same value, so one rule works for all routes.
  • implies is rejected on positional args, operations: flags, non-bool flags, and flags not bound to a root-level body property.
  • Added README documentation and TestCLICommands_FlagImplies covering the behavior.

Written for commit 4456a4f. Summary will update on new commits.

View guided diff Turn on auto-fix

@TristanSpeakEasy
TristanSpeakEasy requested a review from a team as a code owner October 23, 2026 00:43

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 10 files

Shadow auto-approve: would not auto-approve because issues were found.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread templates/templates/cli/intentcmd.go.stmpl
Comment thread templates/templates/cli/includes/intents.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

0 issues found across 4 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would not auto-approve. Auto-approval blocked by 1 unresolved issue from previous reviews.

View guided diff | Turn on auto-fix | Re-trigger cubic

@AshGodfrey AshGodfrey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verified on a regenerated CLI with implies: {$.stream: false} on a bool flag: applied on both dispatch routes and through --body, @file, @- and stdin, explicit --stream wins, and the linker rejects misuse.

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