Skip to content

feat(cli): --json parity for 9 remaining read commands (X4)#34

Merged
NagyVikt merged 1 commit into
mainfrom
agent/x4-json-parity
May 18, 2026
Merged

feat(cli): --json parity for 9 remaining read commands (X4)#34
NagyVikt merged 1 commit into
mainfrom
agent/x4-json-parity

Conversation

@NagyVikt
Copy link
Copy Markdown
Collaborator

Summary

Extends Theme N3's --json envelope to every remaining read-shaped command per Theme X4: config, daemon --once, forecast, savings, hero, export, import, parallel --list, kiro (no args).

  • BaseCommand subclasses 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 (preserves human-mode wording).
  • parallel and kiro intentionally bypass BaseCommand per 01-ARCHITECTURE.md §1.3 (no Codex registry coupling); they wire --json manually via writeJsonEnvelope. Wire shape is identical.
  • daemon --watch --json is rejected with a structured error and deferred to Theme X3 (streaming observability). Only --once gets --json today.

Exit criteria (Theme X4)

  • Every read command has --json. (9 commands listed above.)
  • A snapshot test asserts every --json output is valid JSON for at least one fixture per command (src/tests/json-parity.test.ts).
  • docs/future/02-COMMANDS.md lists the JSON schema for each command.

Commands converted

Command Example success envelope
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> `{ok:true,data:{mode:"file"
parallel --list {ok:true,data:{action:"list",profiles:[{name,configDir}]}}
kiro {ok:true,data:{action:"list",accounts,active,dataDir}}

Verification

npm run build          # clean
npm test               # 138/138 pass (129 prior + 9 new)

Test plan

  • Build is clean (npm run build).
  • Full test suite green (138/138).
  • Each --json command produces exactly one valid JSON document on stdout (snapshot test).
  • Validation errors emit {ok:false,error:{...}} envelopes (verified for config auto, export, import, daemon --watch --json).
  • Human-mode output for every converted command unchanged (e.g. authmux hero still renders ANSI tutorial, authmux savings still prints the multi-line report).

Conflict notes

Touches BaseCommand-using commands; X1 (createApp factory) will refactor BaseCommand itself, so a small rebase is expected when X1 lands. X3 may also touch BaseCommand. No overlap with X2.

🤖 Generated with Claude Code

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>
@NagyVikt NagyVikt merged commit 57ae7a5 into main May 18, 2026
12 checks passed
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.

1 participant