feat: auto-compact JSON output in agent contexts#108
Merged
Conversation
When stdout is not a TTY and the CI env var is unset, the CLI now auto-switches to compact JSON output to reduce token usage for AI agents. Explicit --json still pretty-prints, --ci takes precedence. - Add src/helpers/output.ts with isAgentContext() and formatJSON() - Update all commands with --json support to auto-detect agent context - Update always-JSON commands to use formatJSON() for compact output - Add test preload to set CI=1 so tests don't trigger agent mode - Update ARCH-003 ADR with new convention and Do's/Don'ts
Deploying archgate-cli with
|
| Latest commit: |
763a28b
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://526a1391.archgate-cli.pages.dev |
| Branch Preview URL: | https://feat-auto-compact-json-agent.archgate-cli.pages.dev |
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
CIenv is unset, the CLI auto-switches to compact JSON (no whitespace/indentation) to reduce token usage for AI agents (~30-50% reduction)--jsonflag still pretty-prints;--ciflag takes precedence over auto-detectionsrc/helpers/output.tscentralizes detection (isAgentContext()) and formatting (formatJSON())Detection precedence
Files changed
src/helpers/output.ts,tests/helpers/output.test.ts,tests/preload.ts--jsonsupport, always-JSON commands, reporter, integration test harness,bunfig.toml,CLAUDE.md, ARCH-003 ADRTest plan
bun run validatepasses (438 tests, 21/21 ADR checks, build compiles)echo '' | bun run src/cli.ts checkoutputs compact JSONbun run src/cli.ts checkdirectly outputs human-readableCI=1 bun run src/cli.ts checkoutputs human-readablebun run src/cli.ts check --jsonoutputs pretty JSON