feat(cli): add --fields projection to incident/alert list#58
Merged
ysyneu merged 2 commits intoJun 23, 2026
Merged
Conversation
In structured (json/toon) mode the curated `incident list` / `alert list` commands ignore the compact column set and marshal the full nested SDK record (IncidentInfo/AlertItem with responders/labels/alerts and events/incident blobs). That makes the first list call huge — 20 incidents ~60-70KB, 66 alerts ~83KB — which spills to file and is then re-queried with a narrower jq projection. The first dump is pure waste. Add an additive --fields flag to both list commands: in json/toon mode it projects each row to only the named JSON-tagged fields via one shared reflection helper (projectFields), so the first call is already compact and no jq round-trip is needed. Default behavior (no --fields) is byte-identical to today; --fields is a no-op in table mode. Unknown field names fail fast listing the valid tag names. Out of scope by design: --count/group-by aggregation, nested/dotted paths.
The --fields projection flag added to `incident list` / `alert list`
changed the cobra command tree, leaving the generated card fences stale.
CI 'Check skill command-cards' (go run ./internal/cmd/skilldoc check)
failed on reference/{alert,incident}.md. Regenerated via make gen-cards.
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.
What
Add an additive
--fieldsflag to the curatedincident listandalert listcommands. In structured (--output-format json|toon/--json) mode,--fields a,b,cprojects each row to only the named JSON-tagged fields via one shared reflection helper (internal/cli/fieldproject.go::projectFields), so the first list call is already compact.--fields) is byte-identical to today — the full nested record still dumps. Regression-tested.--fieldsis a no-op in table mode (documented in flag help).flashduty.Timestamp), so per-field encoding stays byte-consistent with the full dump.Examples:
fduty alert list --fields alert_id,title,alert_severity,created_at --output-format toonfduty incident list --fields incident_id,title,incident_severity,progress,start_time --jsonRoot cause
In structured mode the curated compact column set (
cols []output.Column) passed toctx.PrintListis completely ignored —TOONPrinter/JSONPrintermarshal the whole nested SDK struct (IncidentInfo/AlertItemwithresponders,alerts,labels,incident,eventsblobs). So the agent's firstincident list/alert listdump is huge and pure waste: it spills to a file and is then immediately re-queried with a narrowerjqprojection (which even failed in one session becausejqisn't installed in the sandbox).--fieldslets the FIRST call be compact: no spill, no jq.Evidence (audit run audit-2026-06-23)
All 6 cited oversized findings are the first full dump being waste:
sess_CAikSKGN2GFsHh6nYsXQw6— 83.7KB / 2593 lines for 66 alerts; re-queried withjq(jq absent in sandbox).sess_7BvVWNcaRcCmw8DykPSaki— 69.7KB for 20 incidents.sess_H3xYYtxVpEpXNFUgDAMem9— 52KB + 67KB dumps.sess_8mJca7nB7gCcsGUHLQgwQz— 60.4KB never used.Scope
Deliberately out of scope (per the design's "do not stretch" rule): the proposal's
--count/group-by summary mode (a mini query engine with unsettled design surface), nested/dotted field paths, and any change to the generated command layer or theinternal/outputprinters. The default path is untouched end-to-end.Verification
New tests in
internal/cli/fieldproject_test.godrive the real command via thenewGFStubharness:--fieldsunder toon and json still emits the full nested keys (responders/labelsfor incident,events/incidentfor alert).json.Unmarshal— exactly N keys).--fieldsis a no-op; normal headers still print.Note:
make lintfails in this environment due to a pre-existing toolchain mismatch (installedgolangci-lint v2.2.1built with go1.24 refuses a module targeting go1.25.1) — unrelated to this change;gofmt -sandgciare clean on the touched files.