Skip to content

perf(cli): write compact JSON when output is not a terminal - #1413

Merged
kaoru0822-kitauji merged 1 commit into
mainfrom
perf/cli-compact-json-when-piped
Oct 10, 2026
Merged

kaoru0822-kitauji merged 1 commit into
mainfrom
perf/cli-compact-json-when-piped

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Problem

--json / --format json always writes its streamed result with two-space indentation (jsonParts(value, format === "json")). The main readers of that output are agents and scripts, which consume it through pipes and redirects. The skill's CLI fallback and the docs both use --json. For them, indentation carries no information but costs bytes and model tokens.

Measured on real results (--format jsonl output re-encoded both ways; token counts with the o200k_base tokenizer as a proxy, not a model-host measurement):

Command / target Compact bytes → indented Tokens compact → indented Token overhead
decode-interface-builder XLD.app 7,381,786 → 11,465,771 2,177,237 → 2,874,138 +32.0%
inspect-native-dispatch-metadata Stash.app 2,556,305 → 4,379,581 744,451 → 1,063,339 +42.8%
trace-dylib-resolution Stash.app 1,612,524 → 2,237,700 451,178 → 583,657 +29.4%
inspect-asset-catalog Stash.app 560,945 → 806,831 182,760 → 245,152 +34.1%
inspect-artifact Stash.app 3,749,732 → 4,980,118 1,478,963 → 1,719,228 +16.2%

Change

writeJsonOutput indents json only when the destination is a TTY. Piped or redirected json is the same value written compactly, like gh --json:

$ rea list-architectures /Applications/XLD.app --json          # terminal
{
  "evidence_id": "ev_0740…",
$ rea list-architectures /Applications/XLD.app --json | head -c 60   # pipe
{"evidence_id":"ev_0740…","subject":{"name":"XLD","digest":{…

Unchanged: the JSON value and exit status, jsonl, --filter-output, --full-output, and the --token-count/--token-limit/--token-offset paths (Incur still formats those). Small errors formatted by Incur itself also keep their existing layout. docs/cli.md documents the behavior and jq . for indented files.

Compatibility: any consumer that parses the JSON is unaffected. A script that matched indented text (for example grep '"code": "') sees a different layout when piped. The one repository test that did this now parses the JSON. I used perf: rather than !; please re-tag if you treat output whitespace as a breaking contract.

Tests

  • tests/boundary/cli/jsonOutput.test.ts: new case, indented for a terminal destination and compact otherwise. The encoding cases and the beyond-string-limit streaming cases mark their destination as a terminal, so they still cover the indented encoder.
  • tests/acceptance/tools/historicalCaptureResources.test.ts parses the CLI JSON instead of matching '"code": "resource_constraint"'.
  • scripts/verify/javascript/output.mjs redirects to a file, so it now expects compact output. Ran locally for both formats: json_output_verified: true, 536,961,629 bytes past the 536,870,888-character string limit, peak RSS about 168 MB.
  • Full vitest run: 6213 passed. The remaining failures fail identically on unmodified main on this Mac: ibtool NIB fixtures, hdiutil refusal, and three Node-discovery path tests.
  • npm run check:fast, npm run format:check, npm run docs:check
  • Manual: script -q /dev/null rea … --json (TTY) is indented; the same command piped is compact.

No Hopper/Ghidra verification needed. Refs #723, #1065.

🤖 Generated with Claude Code

`--json` / `--format json` always indented its streamed result. Agents and
scripts read REA through pipes and redirects, where indentation carries no
information: on real application results it added 16-45% model tokens
(o200k proxy) and 25-73% bytes. The skill's CLI fallback uses `--json`.

Indent only when stdout is a TTY, as `gh --json` does; piped or redirected
JSON is compact. The JSON value, `jsonl`, `--filter-output`,
`--full-output` and the token-window paths are unchanged. `jq .` restores
indentation for files.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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.

@kaoru0822-kitauji
kaoru0822-kitauji merged commit ca3131b into main Oct 10, 2026
19 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the perf/cli-compact-json-when-piped branch October 10, 2026 03:29
darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
…1413)

`--json` / `--format json` always indented its streamed result. Agents and
scripts read REA through pipes and redirects, where indentation carries no
information: on real application results it added 16-45% model tokens
(o200k proxy) and 25-73% bytes. The skill's CLI fallback uses `--json`.

Indent only when stdout is a TTY, as `gh --json` does; piped or redirected
JSON is compact. The JSON value, `jsonl`, `--filter-output`,
`--full-output` and the token-window paths are unchanged. `jq .` restores
indentation for files.
@morluto morluto added performance Performance regressions, scaling limits, and bounded-resource work area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@morluto morluto added the area: cli CLI adapter and one-shot commands label 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 area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior performance Performance regressions, scaling limits, and bounded-resource work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants