-
-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Summary
Add a --fields flag to commands with --json output, allowing agents (and humans) to request only specific fields in the response. This reduces token consumption and keeps agent context windows focused.
Motivation
From You Need to Rewrite Your CLI for AI Agents (Justin Poehnelt, Google DevRel):
"APIs return massive blobs. A single Gmail message can consume a meaningful fraction of an agent's context window. Humans don't care — humans scroll. Agents pay per token and lose reasoning capacity with every irrelevant field."
The same applies to Sentry CLI. A full sentry issue view --json dumps the entire issue object, latest event (with all exception entries, breadcrumbs, contexts, SDK metadata), and span tree. An agent that just needs id, title, and status is forced to ingest thousands of tokens of irrelevant data.
Current behavior
sentry issue list --json # dumps full issue objects with all fields
sentry issue view --json # dumps issue + event + trace — can be very large
sentry event view --json # dumps full event with all entriesNo way to limit which fields appear in JSON output.
Proposed behavior
# Select specific fields
sentry issue list --json --fields id,title,status,count
sentry issue view --json --fields id,title,metadata.value
# Works with nested fields using dot notation
sentry event view --json --fields eventID,dateCreated,contexts.traceDesign options
Option A: --fields flag
A simple comma-separated list of top-level (and optionally dot-notated nested) field names. Output only includes the requested fields.
sentry issue list --json --fields id,shortId,title,statusPros: Simple, no external dependencies, easy to implement.
Cons: Limited expressiveness for complex filtering.
Option B: --jq flag (like gh --jq)
Pass output through a jq expression for arbitrary transformation.
sentry issue list --json --jq ".[].{id,title,status}"Pros: Extremely powerful, familiar to CLI users.
Cons: Requires bundling or depending on jq, harder for agents to construct.
Option C: Both
Ship --fields for the common case, --jq for power users. Can be incremental.
Recommendation
Start with Option A (--fields). It covers the 90% case for agents (reduce output to only needed fields), is trivial to implement (filter object keys before JSON.stringify), and requires no external dependencies.
Implementation could live in src/lib/formatters/json.ts as a wrapper around writeJson:
function filterFields<T>(data: T, fields: string[]): Partial<T> {
// Pick only the specified top-level keys (and dot-notated nested keys)
}The --fields flag should only be valid when --json is also set.
Context
- The
sentry apicommand already has--fieldfor input field construction — this is about output field selection. - The
ghCLI ships--jqand--jsonwith field selection:gh issue list --json number,title,state - Related: Add
schemasubcommand for runtime API introspection by agents #346 (schema introspection — agents need to know what fields are available) - Related: Establish consistent output styling across all commands #82 (consistent output styling)
References
- Context Window Discipline — Justin Poehnelt
- gh CLI --jq flag