feat(cli): --json parity for 9 remaining read commands (X4)#34
Merged
Conversation
Extends Theme N3's --json envelope from the five core commands to every
remaining read-shaped command per Theme X4: config, daemon --once,
forecast, savings, hero, export, import, parallel --list, kiro (no args).
- BaseCommand subclasses (config, daemon, forecast, savings, hero, export,
import) opt in via `...BaseCommand.jsonFlag` and emit through `emit()`.
Validation errors converted from `this.error(...)` to thrown
AuthmuxError subclasses so they fall through to the structured handler.
- parallel and kiro intentionally bypass BaseCommand (per
01-ARCHITECTURE.md §1.3) and wire --json manually via
`writeJsonEnvelope`. The on-the-wire shape is identical.
- daemon --watch --json is rejected with a structured error envelope and
flagged for the X3 streaming-observability work; --once is the only
watch-mode subset that gets --json today.
Snapshot test (`src/tests/json-parity.test.ts`) spawns the built CLI for
each command with a sandboxed HOME/CODEX_AUTH_CODEX_DIR and asserts:
stdout is exactly one valid JSON document, the envelope matches
`{ok:true,data}` or `{ok:false,error:{code,severity,message}}`, and no
banner/color/prompt chrome leaks into stdout. 138/138 tests pass.
`docs/future/02-COMMANDS.md` lands as the JSON-schema reference (just
the schemas — full command audit is a later doc-only PR).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends Theme N3's
--jsonenvelope to every remaining read-shaped command per Theme X4:config,daemon --once,forecast,savings,hero,export,import,parallel --list,kiro(no args).BaseCommandsubclasses opt in via...BaseCommand.jsonFlagand emit throughemit().this.error(...)to thrownAuthmuxErrorsubclasses so they fall through to the structured handler (preserves human-mode wording).parallelandkirointentionally bypassBaseCommandper01-ARCHITECTURE.md§1.3 (no Codex registry coupling); they wire--jsonmanually viawriteJsonEnvelope. Wire shape is identical.daemon --watch --jsonis rejected with a structured error and deferred to Theme X3 (streaming observability). Only--oncegets--jsontoday.Exit criteria (Theme X4)
--json. (9 commands listed above.)--jsonoutput is valid JSON for at least one fixture per command (src/tests/json-parity.test.ts).docs/future/02-COMMANDS.mdlists the JSON schema for each command.Commands converted
config <section> [action]{ok:true,data:{section,action,status:{...}}}daemon --once{ok:true,data:{switched:false,reason:"auto-switch is disabled"}}forecast{ok:true,data:{accounts:[{name,score,circuitState,tokensAvailable,usable}]}}savings{ok:true,data:{totalSwitches,autoSwitches,...,autoSwitchRatePercent}}hero{ok:true,data:{sections:[{title,items:[{command,description}]}]}}export [dir]{ok:true,data:{exported,targetDir,files}}import <path>parallel --list{ok:true,data:{action:"list",profiles:[{name,configDir}]}}kiro{ok:true,data:{action:"list",accounts,active,dataDir}}Verification
Test plan
npm run build).--jsoncommand produces exactly one valid JSON document on stdout (snapshot test).{ok:false,error:{...}}envelopes (verified forconfig auto,export,import,daemon --watch --json).authmux herostill renders ANSI tutorial,authmux savingsstill prints the multi-line report).Conflict notes
Touches
BaseCommand-using commands; X1 (createAppfactory) will refactorBaseCommanditself, so a small rebase is expected when X1 lands. X3 may also touchBaseCommand. No overlap with X2.🤖 Generated with Claude Code