Add field projection (-o) to read commands for pipe-friendly column output#199
Merged
Conversation
Read commands that previously only had --json (transcripts list, sessions list/get, balance, usage, limits, keys list, audit) now accept -o FIELDS to project columns straight out of the JSON, so a "grab one column" pipeline no longer needs an external jq. - core/project.py: dependency-free projection — comma-separated field specs, dotted paths into nested objects, pipe-friendly scalar rendering (None -> empty column, JSON booleans lowercased, nested values re-serialized as JSON), and a shape-aware dispatch (list -> one line per row, object -> one line). - output.emit gains a `fields` arg that takes precedence over --json; the shared options.fields_option() factory keeps the -o contract uniform across commands. - Shipped epilog examples and REFERENCE.md drop the `--json | jq` column grabs in favor of `-o`. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GmpgwWwuRStqTN3ZuPE8BE
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.
Adds a
-o/--outputfield projection option to list and account read commands, letting users extract specific fields from JSON responses without externaljq. This replaces common patterns likeassembly transcripts list --json | jq '.[].id'with simplerassembly transcripts list -o id.Key changes
New
aai_cli/core/project.pymodule implements field projection:parse_fields()parses comma-separated-ospecs with whitespace trimming_lookup()resolves dotted paths (e.g.,transform.model) into nested objectsrender_value()formats scalars and containers for pipe-friendly output (JSON booleans as lowercasetrue/false, nested objects as compact JSON)project_record(),project_rows(),project_any()dispatch on data shape (single object vs. list) and emit tab-separated columnsUpdated
aai_cli/ui/output.py:emit()now accepts optionalfieldsparameter;-otakes precedence over--jsonemit_fields()function prints projected lines to stdoutNew
aai_cli/options.pyhelperfields_option()provides the shared-o/--outputoption definitionIntegrated into read commands:
aai_cli/commands/account.py:balance,limits,usageaai_cli/commands/sessions.py:list,getaai_cli/commands/transcripts.py:listaai_cli/commands/keys.py:listaai_cli/commands/audit.py:auditUpdated help text and examples across all affected commands to showcase
-ousage instead ofjqpipelinesComprehensive test coverage:
tests/test_project.py: unit tests for parsing, lookup, rendering, and projection logictest_account_command.py,test_sessions_command.py,test_transcripts.py,test_keys.py,test_audit_command.pyverify end-to-end behavior-ooption in help textImplementation details
\t) makes results compatible withcut -fand spreadsheet pastenullvalues render as empty columns (no error)repr()-oprecedence: fields >--json> human rendererhttps://claude.ai/code/session_01GmpgwWwuRStqTN3ZuPE8BE