Repository navigation
fix(patchy): a flag error under --json leaves stdout empty - #1073
Conversation
On a parse error Effect logs the command's usage to stdout before the errors, so an agent reading stdout under --json got help text where it expected nothing. Under --json the entrypoint now holds help back: the errors discard it, and the run's end prints the help that --help or a command without a handler shows. ADR-0004, the CLI README and the patchy skill drop the exception. Closes #1072 Co-authored-by: Claude Opus 5.5 <[email protected]>
…tract Review found two parse errors that still broke the --json contract. A global flag's own bad value, such as --log-level loud, fails outside Effect's usage path, so the runtime printed a stack on stdout in either mode; the entrypoint now renders it as the one line or the document. And the early --json check missed --json=true and --json yes, which Effect accepts; it now reads the flag as Effect does, beside JsonFlag. Co-authored-by: Claude Opus 5.5 <[email protected]>
Re-check found that Effect's lexer reads -json=true as the json flag with a value, so the early check missed it and printed usage. The entrypoint's catch also moves to catchTags, per the service conventions. Co-authored-by: Claude Opus 5.5 <[email protected]>
…ecide Effect refuses --no-json followed by a boolean literal without recording a value, so a later -json=true is the flag's first value. The early reading stopped at --no-json and rendered text; it now reads past it. Co-authored-by: Claude Opus 5.5 <[email protected]>
Acceptance: PASSChecked Done means
Observed error output at this head$ patchy init notes --tier 7 --json
exit: 1; stdout: 0 bytes
stderr: {"ok":false,"error":"Invalid value for flag --tier: \"7\". Expected: \"1\" | \"2\"","kind":"local"}
$ patchy publish --bogus --json
exit: 1; stdout: 0 bytes
stderr: {"ok":false,"error":"Unrecognized flag: --bogus in command patchy publish","kind":"local"}
$ patchy look publish ./x --json
exit: 1; stdout: 0 bytes
stderr: {"ok":false,"error":"Missing required flag: --note","kind":"local"}
$ patchy look publish --note darker --json
exit: 1; stdout: 0 bytes
stderr: {"ok":false,"error":"Missing required argument: dir","kind":"local"}
$ patchy init notes --tier 7 --no-json false -json=true
exit: 1; stdout: 0 bytes
stderr: {"ok":false,"error":"Invalid value for flag --json: \"false\". Expected: omit the value and use --no-json by itself to set --json to false","kind":"local"}Risks beyond Done means
$ pnpm exec vitest run packages/patchy/src/cli.test.ts packages/patchy/src/cliRepoPublish.test.ts
Test Files 2 passed (2)
Tests 31 passed (31)
Golden journeys
All 22 fresh-instance checks passed, including the latest flag regression against the environment's installed CLI. Both environments were removed with Rollback answers: match the diff. The output contract changes, but creates no persistent state that an older release cannot read. There are no schema, data or infrastructure changes. A revert restores the previous CLI output behavior and leaves no incompatible state; Not run
Notes
|
…mmand (#1075) ## What changed This adds release 27's What's new entry, written from `d285816`. It covers everything merged since release 26's `through` (`eabf2e6`), and sets the `patchy` release to `0.27.0` in `packages/patchy/package.json` and `CURRENT_RELEASE`. | Change | PRs | | --- | --- | | Fixed: your agent gets just the error when it mistypes a command | #1073 | #1071 is release 26's own entry. ## Look at - **The entry**, at the top of `releases` in `packages/core/src/whatsNew.ts`. - **Rollback safety, from the live commit `e778152` (release 26) to `d285816`:** the only PR is #1073, a CLI-only change to how parse errors print, plus its tests and docs. It has no migration, no stored data and no wire change, and it isn't labelled `one-way`. Release 26 works with everything it leaves behind. **Rollback line:** If this release misbehaves, roll back to `e778152` (release 26). ## How it was verified - The What's new, release and package-pin tests pass (`whatsNew.test.ts`, `release.test.ts`, `packagePin.test.ts` and the release-aware suites: 68 tests). - #1073 itself had green CI and an acceptance PASS on its head before merging. ## Release impact - [ ] **Breaking** — requires action from anyone already running this - [x] **Not breaking** — no action required A changelog entry and the release version. CLIs older than `0.27.0` are told to upgrade, as every release does. - **What does a revert leave behind?** Nothing. - **Does the release before it still work with that?** Yes. Built by Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, through T3 Code. Co-authored-by: Claude Opus 5.5 <[email protected]>
What changed
When an agent passed a bad flag with
--json,patchyprinted the command's help to stdout before the JSON failure on stderr, so stdout held usage text where an agent expects nothing or a result. A parse error under--jsonnow leaves stdout empty: one failure document on stderr, exit 1. Help that is asked for still prints, with or without--json.Closes #1072
Look at
Where the help came from. On a parse error, Effect 4.0.5's
Command.runWithlogs the help doc withConsole.log, then the errors withConsole.error(showHelpineffect/cli/Command.ts). An explicit--helpgoes through the sameformatHelpDoc+Console.log, so the formatter alone can't tell the two apart.formatErrorshas one caller, the invalid-invocation branch, which makes it the signal.The fix, in
packages/patchy/src/index.ts. Under--jsononly:formatHelpDocholds the help and returns an empty string. A console wrapper skips that lone empty line.formatErrorsdrops the held help.--help,-h, and commands without a handler such as barepatchyorpatchy auth. The output is byte-identical to before.Without
--json, a command's own parse errors still print usage, then the one line.Two more paths review found.
--log-level loudor--completions nope. These fail with a rawInvalidValueoutside Effect's usage path, so the runtime printed an error and stack on stdout, with or without--json. The entrypoint now catches that tag and writes it through the same renderer: one line, or one document under--json. It exits 1 throughOutput.Failed, which is now exported.--jsonis read before parsing. It wasargv.includes("--json"). NowjsonRequested, besideJsonFlaginOutput.ts, reads it the way Effect does: the first--json,--json=<b>,-json=<b>,--json <b>or--no-jsonbefore--decides, reading past a--no-json <b>that Effect refuses.Docs. ADR-0004's "Parse errors" bullet now states the contract instead of the exception.
packages/patchy/README.mdsays the same in one line. The globalpatchyskill drops its "usage on stdout" warning, since its general failure contract now covers parse errors, andskills-lock.jsoncarries the new hash.Later. Effect 4.0.7 adds
CliOutput.Presenter, which receives anInvalidInvocationseparately fromHelp. Once the Effect bump (#974, then 4.0.7) lands, about ten lines ofPresenterreplace the held-help state. The comment inindex.tssays so.Transcript
json-parse-errorsBefore is
e778152(where this branch left main) and after isf1841dd(fix/1072-json-parse-error-stdout), both on theteamscenario, frompnpm dev transcript.Each line ran in its own
bash -cfrom the side's agent workspace, as the scenario's signed-in CLI, with stdin closed. Each side's origin reads<origin>, its environment folder<env>, its checkout<checkout>and the home folder~; nothing else is normalized. Nothing in it matched a collected secret (each side's CLI state, machine-token and login-code shapes, email addresses outside the scenarios' example domains, secret-named variables, and any accounts the run acts as).7 of 10 lines changed.
Under --json, a bad flag value: stdout
Changed. Before, exit 1 in 0.2 s; after, exit 1 in 0.2 s.
$ patchy init notes --tier 7 --json 2>/dev/null...and stderr, with its exit code
$ patchy init notes --tier 7 --json 2>&1 >/dev/null: no change, exit 1 in 0.2 sAn unknown flag and a missing required flag: stdout
Changed. Before, exit 1 in 0.2 s; after, exit 1 in 0.2 s.
$ patchy publish --bogus --json 2>/dev/nullChanged. Before, exit 1 in 0.2 s; after, exit 1 in 0.2 s.
$ patchy look publish ./x --json 2>/dev/nullEffect's other spellings of the flag count too
Changed. Before, exit 1 in 0.2 s; after, exit 1 in 0.2 s.
$ patchy init notes --tier 7 --json=true 2>/dev/nullChanged. Before, exit 1 in 0.2 s; after, exit 1 in 0.2 s.
$ patchy init notes --tier 7 -json=true 2>/dev/nullA global flag's bad value, with and without --json: stdout, then stderr
Changed. Before, exit 1 in 0.2 s; after, exit 1 in 0.2 s.
$ patchy whoami --log-level loud --json 2>/dev/nullChanged. Before, exit 1 in 0.2 s; after, exit 1 in 0.2 s.
+Invalid value for flag --log-level: "loud". Expected: "all" | "trace" | "debug" | "info" | "warn" | "warning" | "error" | "fatal" | "none"Help asked for under --json still prints
$ patchy init --help --json | head -4: no change, exit 0 in 0.2 sWithout --json, usage still prints before the one-line error
$ patchy init notes --tier 7 2>&1 | tail -4: no change, exit 0 in 0.2 sHow it was verified
The focused test.
cli.test.ts› help › "under --json, a parse error is one document on stderr, and help still prints" covers:--json,--json=trueand-json=true--log-level loudEach must have empty stdout and exactly one document line on stderr. With
--no-json, the text error and usage must be back, and--log-level loudwithout--jsonmust be one stderr line.init --help --jsonandauth --jsonmust print the same stdout as without--json. It fails against main'sindex.ts(21 lines of help on stdout) and passes with the fix.The old assertion.
cliRepoPublish.test.tsasserted the old help on stdout forinit --tier 0 --json. It now asserts empty stdout.Review. Three GPT 6.1 Sol (xhigh) passes. Every finding is fixed in the later commits: global flag values, the
--json=trueand-json=truespellings, a refused--no-json falsebefore-json=true, andcatchTag→catchTags.Checks.
pnpm checkformat, lint, typecheck and synth pass, andpnpm typecheckis 24/24. On this shared dev machine, offline CLI stub-server tests failed in a rotating set from the host's strayGET /probes. Each either passes when run alone or fails the same way with main'sindex.ts. CI decides.Release impact
Under
--json, a parse error's stdout loses the help text that nothing read as a result. Without--json, a global flag's bad value is one stderr line instead of a stack on stdout. Exit codes are unchanged.Built by Claude Opus 5.5 (
claude-opus-5-5) in Claude Code, through T3 Code.