feat(cli): agent-native output, stdin symbols, and exit-code classes

Phase 1 of docs/DESIGN.md:

- Output format resolves -o > IDX_OUTPUT > general.output > auto; auto
  is a table on a terminal and JSON when stdout is piped or captured.
  `config init` now writes output = "auto".
- JSON is pretty only on a terminal and compact otherwise. New `-o
  jsonl` prints one array item per line with the same key order.
- No ANSI color when stdout is not a terminal (direct owo-colors calls
  now go through output::style).
- `stocks quote -` and `stocks compare -` read symbols from stdin.
- Exit codes by class: 2 invalid input/config, 3 not found or cache
  miss, 4 upstream unavailable, 5 unsupported, 1 other.

Golden changes are limited to those documented kinds and were verified
mechanically: JSON goldens are semantically identical, tables differ
only by removed ANSI codes and the column padding comfy-table had
reserved for them (cell contents identical), exit codes match each
error's class, and help/completions only gain the new --output values.
17 new golden cases cover auto, jsonl, stdin, and the new errors.

tests/cli.rs now pins IDX_OUTPUT=table in its harness (its tests assert
table text and run piped) and parses discover JSON instead of matching
pretty-printed whitespace.

Live A/B against main: 16/16 stocks cases identical; ownership discover
got IDX 403 on both binaries, now exiting 4 instead of 1 as intended.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
hermes 2026-10-14 08:52:13 +00:00
commit 22b6dabaeb
119 changed files with 920 additions and 1896 deletions

View file

@ -112,7 +112,11 @@ idx ownership changes --from 2026-07-31 --to 2026-08-31
### Output
- Human-readable tables on stdout, JSON with `-o json`, errors on stderr
- Tables when you run idx in a terminal; compact JSON when its output is piped
or captured, so scripts and AI agents get structured data with no flag
- `-o table|json|jsonl` (or `IDX_OUTPUT`, or `general.output` in the config)
overrides that; `jsonl` prints one array item per line
- Errors go to stderr, as one JSON object in JSON modes
## Configuration
@ -133,12 +137,26 @@ Precedence order:
3. Config file
4. Built-in defaults
## Agent-friendly usage
## Scripting and agents
- Use `idx --help` and subcommand help for discoverability
- Use `-o json` / `--output json` for structured output
idx composes with `jq`, Python, and other shell tools:
```bash
idx stocks quote BBCA BBRI | jq -r '.[] | "\(.symbol) \(.price)"'
idx -o jsonl stocks history BBCA --period 1y | tail -5
idx stocks screen --filter low-pe | jq -r '.[].symbol' | idx stocks compare -
```
- stdout carries only data; warnings and errors go to stderr
- `-` reads symbols from stdin for `stocks quote` and `stocks compare`
- No color codes when output is not a terminal
- Exit codes: `0` success, `2` invalid input or config, `3` not found or no
cached data, `4` upstream unavailable (retry later), `5` unsupported, `1` other
- `idx completions <shell>` generates shell completions
If you ran `idx config init` before v0.3, your config pins `output = "table"`;
change it to `auto` with `idx config set general.output auto`.
## Documentation
- [docs/INSTALL.md](docs/INSTALL.md): install script options