Skip to content

feat(cli): support --json across reporting commands - #117928

Merged
steipete merged 3 commits into
mainfrom
codex/feat-json-everywhere
Aug 2, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/feat-json-everywhere

Conversation

@steipete

@steipete steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

--json was an inconsistent flag. Most reporting commands supported it, but a live sweep against a production host found commands that rejected it outright — so scripting the CLI meant memorising which commands happened to have it. The sharpest example: openclaw automations runs --id <job> already prints a JSON document to stdout, yet rejected --json with "does not recognize option". That broke a real automation during testing and forced a fallback to gateway call cron.runs.

Maintainer request: "basically every command should support --json".

Why This Change Was Made

The whole registered tree was audited — 443 canonical paths — rather than only the commands that happened to appear in the sweep. Each path was classified: add, already supported, or genuinely not applicable. Only 14 paths were genuinely missing support (the production dist predated several existing implementations).

Added: config file, config schema, bare models, bare docs, cron get, cron runs, proxy coverage/sessions/query, bare hooks, plugins doctor, plugins validate, bare skills, skills verify.

Deliberately not applicable, with reasons: interactive wizards (configure, onboard mutations, update wizard), long-running servers and protocol surfaces (gateway run, daemon, mcp serve, worker, attach, acp, webhooks gmail run), interactive TUI (tui, terminal, chat), destructive mutations (reset, uninstall, sandbox recreate), raw-byte output (proxy blob), streaming contracts preserved as-is (logs JSONL, sessions tail, fleet logs), grouping namespaces, and completion (stdout must stay executable shell source).

All new paths use the existing writeRuntimeJson/runtime.writeJson convention — no second serialization idiom. JSON mode suppresses progress/decoration and routes incidental logs to stderr, so stdout is a single parseable document. Exit-code semantics are unchanged, and existing JSON shapes were not altered (they are a public contract); parent and child JSON options are merged so new bare aliases do not break models status --json or skills list --json.

A registered-tree guard test now enumerates the command surface and requires every command to be either JSON-supported or on an explicit, documented not-applicable allowlist — so a new command must make a deliberate choice rather than drifting.

Security fix found during the audit

security audit --deep embedded the gateway probe URL, error string, and websocket close reason verbatim. A gateway URL carrying userinfo credentials (or a secret in a query parameter) could therefore land in the audit report — in both human and JSON output. Redaction now happens at the producer via the canonical redactSensitiveUrlLikeString, with userinfo and query-secret regression sentinels. Other sensitive surfaces were verified rather than assumed: exec-policy still strips allowedDecisions; secrets keeps SecretRef/plan shapes without resolved values; pairing JSON exposes only the operator-actionable fields the human table already shows; device inventory returns token lifecycle summaries, not token material; plugin JSON sanitizes home-relative paths.

Catalog discrepancies found (reported, not papered over)

  • gateway export is a stale catalog entry — the real command is gateway diagnostics export.
  • config models, tool, and tools have catalog entries but no registered built-in command (tool/tools are intentionally reserved non-plugin roots).

These were left for a separate change rather than manufacturing commands to match the catalog.

User Impact

Every reporting command a script would reasonably call now emits machine-readable output through one convention, and the guard test keeps it that way. Human output is unchanged when --json is absent (verified by an anti-cheat probe: proxy sessions without the flag still returns its legacy bare array). Credentials can no longer leak into security audit reports.

Evidence

  • 18 focused test files run individually: 573 tests passed, covering config, cron, docs, hooks, models, plugins, proxy, skills, the 437-command surface guard, plus security-redaction, secrets, exec-policy and pairing redaction assertions.
  • pnpm tsgo:core, pnpm build (3m13s, CLI bootstrap import guard passed), formatting and git diff --check: passed.
  • Built-CLI behavior probe: ten representative new paths each produced a single parseable JSON object with diagnostics on stderr.
  • Autoreview (Codex gpt-5.6-sol, high): clean, "patch is correct" (0.99); trufflehog clean.
  • Production LOC +251/-70 (net +181, mostly the explicit redacted plugin doctor/validate projections); tests net +713; docs net +50 across 12 docs/cli pages.

Known gap: the two cron JSON paths were proven by focused gateway-harness tests rather than against a live production gateway.

@steipete steipete self-assigned this Aug 2, 2026
@steipete
steipete marked this pull request as ready for review August 2, 2026 09:25
@steipete
steipete requested a review from a team as a code owner August 2, 2026 09:25
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes commands Command implementations size: XL maintainer Maintainer-authored PR labels Aug 2, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 2, 2026, 5:49 AM ET / 09:49 UTC.

ClawSweeper review

What this changes

Adds explicit --json support, tests, and CLI documentation for selected reporting commands, while redacting sensitive gateway URLs from deep security-audit output.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 7 items remain

Keep this PR open. The latest head still accepts root-level --json on child commands that do not implement a matching JSON response, so scripts can request machine output and receive ordinary text; it also lacks inspectable after-fix behavior proof. The maintainer label independently requires human handling rather than automated cleanup.

Priority: P2
Reviewed head: 190ee4f776a4b9ca510504b90371736f8509dc8f

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch has useful focused tests and a sound redaction change, but unresolved JSON-contract regressions and missing inspectable runtime proof prevent merge readiness.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: The PR body claims built-CLI probes but includes no inspectable after-fix terminal output, recording, log, or linked artifact; attach redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The PR body claims built-CLI probes but includes no inspectable after-fix terminal output, recording, log, or linked artifact; attach redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Models alias leaks beyond its documented scope: The new parent --json option is documented as an alias for the default status report, but hasJsonOutput reads the parent option from child actions. A placement such as models --json set &lt;model> is therefore accepted by the parser even though the mutation has no JSON response contract.
Skills root option is accepted by non-JSON children: The new root skills --json option is read through hasJsonOutput, but install and update retain human-progress output; the option is accepted before those child commands without supplying the requested machine-readable result.
Prior blockers remain unchanged: Neither affected command-registration file changed between the previous reviewed head and the current head, so the two prior P1 scope findings remain unresolved.
Findings 2 actionable findings [P1] Scope the models JSON alias to the status report
[P1] Do not accept root JSON mode for non-JSON skill actions
Security None None.

How this fits together

OpenClaw’s CLI parses a command hierarchy and routes each command to a reporting or mutation handler, which writes either human-oriented output or a machine-readable JSON document. The security audit collects gateway probe results and renders them into operator-facing audit reports.

flowchart LR
  Operator[CLI operator or script] --> Parser[Command hierarchy]
  Parser --> Report[Reporting command]
  Parser --> Mutation[Mutation command]
  Report --> Output[JSON or human stdout]
  Mutation --> Result[Action result]
  Gateway[Gateway probe] --> Audit[Security audit]
  Audit --> Redaction[Redacted audit output]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The PR body claims built-CLI probes but includes no inspectable after-fix terminal output, recording, log, or linked artifact; attach redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Scope the models JSON alias to the status report (P1) - The root option is inherited by reporting children through hasJsonOutput, while mutations such as models --json set &lt;model> still accept the flag yet follow their normal non-JSON action. Reject the root alias outside the default status path, or make the hierarchy enforce the documented scope consistently.
  • Do not accept root JSON mode for non-JSON skill actions (P1) - The root skills --json option is accepted by every child command, but install and update do not serialize their result; scripts can therefore request JSON and receive ordinary progress/text output. Keep the root alias limited to the default list or add command-local behavior only where a stable result exists.
  • Resolve merge risk (P1) - Merging as written broadens a scripting contract: root --json can be accepted on mutation or install/update paths that still write human output, breaking parsers that trust the flag.
  • Resolve merge risk (P1) - The external-PR behavior-proof gate remains unmet because the reported built-CLI probes have no inspectable evidence.
  • Resolve merge risk (P1) - The PR has a protected maintainer label, so a human should make the final merge decision after the concrete fixes and proof are supplied.
  • Complete next step (P2) - The concrete code repairs are narrow, but the protected maintainer label and required contributor-owned runtime proof keep this PR in human review rather than an automated repair lane.

Findings

  • [P1] Scope the models JSON alias to the status report — src/cli/models-cli.ts:45-56
  • [P1] Do not accept root JSON mode for non-JSON skill actions — src/cli/skills-cli.ts:556-564
Agent review details

Security

None.

PR surface

Source +181, Tests +713, Docs +50. Total +944 across 40 files.

View PR surface stats
Area Files Added Removed Net
Source 14 251 70 +181
Tests 14 737 24 +713
Docs 12 93 43 +50
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 40 1081 137 +944

Review metrics

None.

Stored data model

Persistent data-model change detected: migration/backfill/repair: docs/cli/mcp.md, migration/backfill/repair: src/cli/plugins-cli.lazy.test.ts, migration/backfill/repair: src/cli/plugins-cli.list.test.ts, serialized state: src/cli/cron-cli.test.ts, serialized state: src/cli/hooks-cli.toggle.test.ts, serialized state: src/cli/plugins-cli.list.test.ts, and 4 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Constrain the root aliases before merge (recommended)
    Reject root-level JSON placement on child actions without a JSON result, then add regression coverage for a report path and a mutation/install path.
  2. Pause the broad alias expansion
    If the intended root-option semantics remain unclear, keep the existing child-local JSON flags and defer the broad consistency policy to a separately approved design.

Technical review

Best possible solution:

Keep bare models --json and skills --json limited to their documented default reports, retain command-local JSON flags only where stable result objects exist, and attach a redacted built-CLI transcript proving parseable stdout plus stderr-only diagnostics.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: place the new root option before a non-reporting child, such as models --json set <model> or skills --json install <ref>, and the parser accepts a JSON request while those actions retain their normal text/progress behavior.

Is this the best way to solve the issue?

No. The documented aliases are for default reports, so their scope should be enforced at the command boundary rather than inherited into unrelated child actions.

Full review comments:

  • [P1] Scope the models JSON alias to the status report — src/cli/models-cli.ts:45-56
    The root option is inherited by reporting children through hasJsonOutput, while mutations such as models --json set <model> still accept the flag yet follow their normal non-JSON action. Reject the root alias outside the default status path, or make the hierarchy enforce the documented scope consistently.
    Confidence: 0.95
  • [P1] Do not accept root JSON mode for non-JSON skill actions — src/cli/skills-cli.ts:556-564
    The root skills --json option is accepted by every child command, but install and update do not serialize their result; scripts can therefore request JSON and receive ordinary progress/text output. Keep the root alias limited to the default list or add command-local behavior only where a stable result exists.
    Confidence: 0.95

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against b7bbb4f98a1f.

Labels

Label justifications:

  • P2: This is a broad CLI scripting-contract improvement with concrete compatibility risks but no emergency availability or security failure.
  • merge-risk: 🚨 compatibility: Existing scripts may treat accepted --json as a guarantee of one parseable JSON document, which the inherited root flags do not consistently provide.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body claims built-CLI probes but includes no inspectable after-fix terminal output, recording, log, or linked artifact; attach redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Models alias leaks beyond its documented scope: The new parent --json option is documented as an alias for the default status report, but hasJsonOutput reads the parent option from child actions. A placement such as models --json set <model> is therefore accepted by the parser even though the mutation has no JSON response contract. (src/cli/models-cli.ts:45, 190ee4f776a4)
  • Skills root option is accepted by non-JSON children: The new root skills --json option is read through hasJsonOutput, but install and update retain human-progress output; the option is accepted before those child commands without supplying the requested machine-readable result. (src/cli/skills-cli.ts:556, 190ee4f776a4)
  • Prior blockers remain unchanged: Neither affected command-registration file changed between the previous reviewed head and the current head, so the two prior P1 scope findings remain unresolved. (src/cli/models-cli.ts:45, 190ee4f776a4)
  • Current main does not contain the branch changes: The PR head is not an ancestor of current main, and the relevant CLI and audit files differ from main; this remains active proposed work rather than an implementation already landed elsewhere. (src/cli/models-cli.ts:45, b7bbb4f98a1f)
  • Security redaction uses the established producer-side helper: The audit change redacts the probe URL, error, and close reason before report construction through the canonical URL-like-string redactor, whose implementation handles URL-like substrings rather than only complete URLs. (src/security/audit.ts:1272, 190ee4f776a4)
  • Proof artifact check: The supplied PR body describes built-CLI probes, but the provided proof scratch area contains only the maturity helper and no inspectable terminal output, log, recording, or linked runtime artifact.

Likely related people:

  • steipete: Current-main blame attributes the models and skills command roots to Peter Steinberger, and the GitHub context identifies this same contributor handle as the author of the JSON-surface branch. (role: recent CLI command-system contributor; confidence: high; commits: 81031012b222, 95efdd35cd16; files: src/cli/models-cli.ts, src/cli/skills-cli.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Limit the two root JSON aliases to paths with an explicit JSON result and cover unsupported child placement.
  • Add redacted built-CLI output showing representative new commands produce exactly one parseable JSON document and place diagnostics on stderr.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-02T09:31:22.813Z sha 95efdd3 :: needs real behavior proof before merge. :: [P1] Scope the models JSON alias to the status report | [P1] Do not inherit skills JSON mode into install and update
  • reviewed 2026-08-02T09:40:39.448Z sha e90376e :: needs real behavior proof before merge. :: none

@steipete
steipete merged commit 4c7a8d4 into main Aug 2, 2026
121 checks passed
@steipete
steipete deleted the codex/feat-json-everywhere branch August 2, 2026 09:56
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Post-land review note: I read the latest ClawSweeper review and its Rank-up moves: before landing. Both optional moves were intentionally skipped under Peter's explicit frozen-scope authorization for this already-reviewed PR: the root models --json and skills --json forms are aliases for their default reports, while named child actions retain their own output contracts. A separate built-CLI transcript artifact was not added because the PR body was also frozen; the maintainer accepted its recorded behavior evidence together with the green exact-head CI run 30742370449. No code or PR-body expansion was made beyond the minimal CI fixes.

vincentkoc added a commit to zenglingbiao/openclaw that referenced this pull request Aug 2, 2026
* origin/main: (59 commits)
  fix(agents): reject false success from delegated file mutations (openclaw#117938)
  fix(macos): reopen AI choice, fix daemon error text, hand onboarding off to the dashboard custodian (openclaw#117921)
  fix(qa): tolerate expected Matrix sync long-poll deadlines (openclaw#117807)
  feat(cli): support --json across reporting commands (openclaw#117928)
  perf(cli): keep read-only commands on cold paths (openclaw#117932)
  fix: prevent fractional chunk limits from stalling text splitting (openclaw#117727)
  fix(qqbot): add heartbeat-ACK liveness watchdog (openclaw#114902)
  chore(openai): defer release note to release flow
  fix(pr): join worktree discovery subprocesses
  test(gateway): widen aggregate event-loop budget (openclaw#117931)
  fix: refresh Buzz room targets after reconnect (openclaw#117927)
  fix: invalidate removed Buzz mention members
  fix: align Buzz explicit mention semantics
  test: split Buzz mention delivery coverage
  fix: preserve Buzz reply session threads
  refactor: keep Buzz mention helpers internal
  fix: invalidate stale Buzz room targets
  fix: tighten Buzz mention disambiguation
  perf: keep Buzz plain sends on the fast path
  fix: reject unresolved Buzz mention text
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
* feat(cli): support --json across reporting commands

* test(cli): satisfy json command checks

* test(cli): type json exception map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant