Skip to content

fix(cli): accept --flag=value for global output flags - #3811

Merged
kaoru0822-kitauji merged 2 commits into
mainfrom
fix/cli-equals-output-flags
Oct 15, 2026
Merged

kaoru0822-kitauji merged 2 commits into
mainfrom
fix/cli-equals-output-flags

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Summary

rea <command> --format=json failed with Unknown flag: --format, and so did --filter-output=..., --token-limit=... and --token-offset=.... Command options already accept --flag=value (--table=t works), and rea mcp doctor parses --format= itself. Agents write the equals form often, so each such call failed and had to be retried.

A valued output flag with no value (--format as the last argument, or --format=) also failed with Unknown flag: --format and code UNKNOWN, which points at the wrong problem.

Now the equals forms behave exactly like the spaced forms. A missing value fails before the command runs with MISSING_OUTPUT_VALUE: --format requires a value, as in --format <value> or --format=<value>.

Problem and expected behavior

Incur extracts its global flags with exact token matches (token === '--format' && argv[i + 1]). An equals form, or a flag without a value, therefore passes through to the command's option parser, which reports the global flag as unknown. rea's parseCliOutputArguments mirrored that behavior on purpose, so rea's output validation agreed with what Incur would apply. The equals form was consistently ignored rather than honored.

Change and scope

  • src/cliOutput.ts, which owns output-argument interpretation, gains normalizeCliOutputArguments. It splits --format=V, --filter-output=V, --token-limit=V and --token-offset=V into the spaced form. Everything else is unchanged, including boolean flags, --json, command options and values that merely contain =.
  • scripts/rea.mjs passes the normalized argv to validateCliOutputArguments, createCliResultOutput, Incur serve and the empty-filter fallback. All four therefore read the same effective values, preserving the invariant the existing tests protect.
  • validateCliOutputArguments reports MISSING_OUTPUT_VALUE for a valued output flag that is last or followed by an empty value. This check runs after the existing filter-slice and token-window checks, so their precedence is unchanged.
  • docs/cli.md documents both forms and the new error.
  • Not included: mcp doctor, which has its own parser that already accepts --format=; command-local options; MCP.

Contract and boundary impact

  • Semantic owner and earliest changed stage: CLI output-argument interpretation (src/cliOutput.ts), applied at the entry point before Incur.
  • Contribution scope fit and linked maintainer decision: CLI usability/correctness fix; not applicable.
  • CLI and MCP/tool-catalog contract: previously rejected equals forms now work. There is a new pre-execution error code MISSING_OUTPUT_VALUE. Schemas and MCP are unchanged.
  • Provider, bridge, target-format, or platform compatibility: all CLI commands, all platforms.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged.
  • Target selection, authority, upstream behavior, and cleanup details: unchanged.
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • Documentation or usability only; no target interaction.

Evidence and regression coverage

  • Tests updated in tests/boundary/cli/cliOutput.test.ts, all through the compiled CLI:
    • Equals forms are now asserted as honored: --format=json --filter-output=capabilities[0,1] returns the filtered JSON, and --json --token-limit=5 is rejected as a token window exactly like the spaced form. The previous assertion, that --token-limit=5 was not an active builtin, encoded the old behavior.
    • The structured-error case now uses --format=json --token-limit=5.
    • Missing values for --format, --filter-output, --token-limit and --token-offset=, and a trailing --format, assert MISSING_OUTPUT_VALUE naming the flag.
  • Base reproduction: against the unfixed src/cliOutput.ts and scripts/rea.mjs, both updated tests fail (Tests 2 failed | 16 passed).
  • User-visible output before:
    $ rea inspect-plist /Applications/Ghostty.app --format=json
    code: UNKNOWN
    message: "Unknown flag: --format"
    
    After:
    $ rea inspect-plist /Applications/Ghostty.app --format=json --filter-output=normalized_result.bundle.identifier
    {"normalized_result":{"bundle":{"identifier":"com.mitchellh.ghostty"}}}
    $ rea inspect-plist /Applications/Ghostty.app --format=
    {"ok":false,"error":{"code":"MISSING_OUTPUT_VALUE","message":"--format requires a value, as in --format <value> or --format=<value>."}}
    
  • Remaining proof gaps: none known.

Validation performed

  • npm run test:focused -- tests/boundary/cli/cliOutput.test.ts tests/boundary/cli/closedStdout.test.ts tests/boundary/cli/jsonOutput.test.ts tests/boundary/cli/cliOptionAliases.test.ts: 65 passed
  • npm run test:focused -- tests/boundary/cli/mcpDoctorHelpCli.test.ts tests/boundary/cli/javascriptIntegrityPolicyCli.test.ts tests/boundary/cli/nativeUiScenarioInputCli.test.ts: 15 passed. These cover command-local "Unknown flag" errors, which are unchanged.
  • npm run check:fast: passed; npm run docs:check: passed
  • Real app on macOS (Darwin 25.6, arm64), against /Applications/Ghostty.app:
    • --format=json, --format=json --filter-output=... and --token-limit=20 now match their spaced forms.
    • --format=, a trailing --format, and --filter-output "" --format yaml give MISSING_OUTPUT_VALUE in the selected structured format.
    • --format=xml still gives Incur's Invalid format message.
  • Cost: argv normalization is linear in the argument count. For agents, it removes a failed call and retry per equals-form invocation.

Compatibility, safety, and release

  • Breaking changes or migration steps: none for valid invocations; previously failing invocations now succeed. A missing value still exits 1, now with MISSING_OUTPUT_VALUE instead of UNKNOWN.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above. (Found by exercising the real CLI; no existing issue.)
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🤖 Generated with Claude Code

`rea <command> --format=json` failed with "Unknown flag: --format".
`--filter-output=...`, `--token-limit=...` and `--token-offset=...`
failed the same way. Incur reads these global flags only in spaced form,
so the equals form fell through to the command parser. Command options
already accept both forms, and `rea mcp doctor` parses `--format=` itself.

A valued output flag with no value (`--format` last, or `--format=`)
also reported the flag as unknown with code UNKNOWN.

normalizeCliOutputArguments, in the module that owns output-argument
interpretation, now splits the equals forms of the four valued output
flags. The entry point passes the normalized argv to rea's output
validation and to Incur, so both read the same effective values. A
missing value now fails with MISSING_OUTPUT_VALUE and names the flag.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kaoru0822-kitauji kaoru0822-kitauji added the track:bugs Small-bug loop track PRs label Oct 15, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-15T02:43:17.830364Z dda7245 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous finding is fixed and no new blocking issue remains.

Summary

The PR makes valued global output flags accept --flag=value and gives missing values a clearer error.

  • Global output flags now accept values after an equals sign.

Reviews (2) · Last reviewed commit: "fix(cli): detect missing output values w..." · Reviewed by Greptile

Comment thread src/cliOutput.ts Resolved
The missing-value check scanned argv again after parsing, so it also
checked tokens the parser had already consumed as values. For example,
`--filter-output --format` selects the field `--format`, yet the second
scan reported `--format` as missing a value. parseCliOutputArguments
now records the first valued flag it skips for lack of a value, in the
same pass that consumes values.

Cover normalizeCliOutputArguments directly: values containing `=`, empty
values, and command options that only share a prefix. Export it in the
dispatcher test's runtime stub as well.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kaoru0822-kitauji
kaoru0822-kitauji merged commit 0781716 into main Oct 15, 2026
35 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/cli-equals-output-flags branch October 15, 2026 03:22
@morluto morluto added area: cli CLI adapter and one-shot commands bug Something isn't working labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands bug Something isn't working track:bugs Small-bug loop track PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants