feat(agentctl): add exec --json #286
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #286"
general
weight: 0.35
aramase
First step toward #278: give scripts a stable way to read
exec, so the human output ofexec,replayandforkcan be reworked next without breaking them.What changes
agentctl exec --jsonprints the turn as JSON Lines, one protobufExecUpdateper line as it arrives, using the same encoding as the other--jsonoutput:- The first line is a
session, so a script learns the UID of a sessionexeccreated.- Each committed record follows as
record, holding the sameLogRecordareplay --jsonline holds.- A turn that pauses for approval exits 0 and ends with a
sessionwhosepending_approvalnames the call.- Streamed model chunks are left out. They aren't committed, the completed model call's
EVENT_OUTPUTcarries the full response, and nothing would read them. An opt-in flag can add them later; the docs tell scripts to ignore update kinds they don't expect.- If the stream fails, the lines already written stay and
execexits with the error. No retry.execexited 0).execstops writing, reads the stream to its end so the turn isn't cut short, then exits with an error noting the records are committed. The error names the session to replay and says to use the same--serveror--journal. If the stream also fails, both errors are reported, still naming the session, and nothing claims the turn finished. This applies to both text and JSON. With--json,execalso ignores SIGPIPE, so a closed pipe takes the same path:exec --json | head -1gets its line and the turn still completes, local or remote, instead of being cancelled. Without--json,execkeeps exiting via SIGPIPE;TestResponseBrokenPipeasserts both.Example
From the built-in server with the default
echoharness:Each line is one
ExecUpdate. The first and theEVENT_OUTPUTline, pretty-printed:Getting just the reply:
A failed stdout write, which used to exit 0:
The quickstart's JSON section now includes a similar example.
Tests and scripts moved off text parsing
The tests and scripts that checked or parsed the human output of
exec,replayorforknow read--json, so the next PR can change that output. What's left is display only, or relies on something the next PR keeps:driver.sh's split-view highlight assumes one line per record; the next PR updates it with the layout.examples/substrate-kind/smoke.shreads thesession <uid>header, which stays.get,list,suspendanddeleteoutput stay as they are; those formats aren't changing.What changed:
cmd/agentsessionsd/lifecycle_e2e_test.go(the daemon smoke test): turn outputs, END, the fork child and the replay prefix across delete and restart are now checked on decoded records withproto.Equal, instead of text regexes and byte prefixes.cmd/agentctl/delete_test.go: the fork child comes fromfork --json, and the audit replay check usesreplay --json.examples/agentsuite-substrate/demo.shreadsexec,replayandforkthrough--json, parsed withjq, whichup.shand the README already require.saystill shows each turn, viareplay --from. Every read consumes all its input, because ajq first(...)that stops early could endreplaywith SIGPIPE underpipefail.examples/agentsuite-substrate/demo/driver.shcaptures the journal withreplay --jsonand parses it withpython3, as it already parses its other JSON.- Its step log gets one
seq kindline per record instead of the JSON, which holds provider data (such as opaque reasoning bytes) that its redaction cannot inspect.- The full JSON, and the session list it reads the fork child from, go to a private
mktempfile that is deleted on exit, not to the shared work directory. Only the child's UID is logged, and the parent and child comparison keeps only content hashes.- Its checks now read the journal rather than the screen: the usage and hash chain (chapter 6), that the replay appended nothing (chapter 8), and the fork child's own answer and input, plus the shared prefix compared by
content_hash(chapter 9).- The fork child's UID comes from
list --json, matched by parent and name.examples/agentsuite-substrate/demo/trace-turn.sh: the model-call hop reads a JSON journal kept outside the saved trace directory. The humanjournal.logstays for reading.examples/agentsuite-substrate/scripts_test.go: the fakeagentctlbehind thedemo.shtests now prints JSON Lines for--json.hack/demos/kubernetes-tour.sh: the tour showsSID=$(agentctl create ...)before its firstexec, and gets the fork child fromlist --json. The landing-page cast is unchanged until it is re-recorded.Docs and changelog
docs/quickstart.md: anexecrow in the JSON table, a jq example, and how pauses, chunks and failures appear. It also says the human output ofexec,replayandforkcan change.docs/approval-gated-tool.md: how a script detects the approval pause.pipefail, so a failedagentctlfails the pipeline, not justjq.exec --jsonneeds a build frommainuntil the next release; v0.4.0 has noexec --json.spec.md§1.2 defines theexec --jsonframing: the first session frame, committed records, the approval-pause frame, deltas left out, and stream and write failures. It also says the human output ofexec,replayandforkisn't a stable contract.Added(exec --json),Compatibility(human output will change; use--json),Fixed(stdout write errors).Not in this PR
Testing
gofmt,go build ./...,go vet ./..., golangci-lint (changed packages),go test -race -shuffle=on ./cmd/agentctl ./cmd/agentsessionsd ./client, theexamples/agentsuite-substratemodule'svet, tests and golangci-lint,hack/check-doc-links.py,go run ./hack/doccheck,go run ./hack/changelog check.-
TestExecJSON: lines round-trip to the sent updates, with and without--session; deltas are left out; escaped control and format characters; the approval-pause frame; a stream error.-
TestExecWriteError: text and JSON modes.exec --jsonagainst the built-in server.demo.sh,driver.sh,trace-turn.shand tour helpers and checks were exercised against real journals from the built-in server, including fork, multi-line text and checks that must fail. I could not rundemo.sh,driver.shor the tour end to end, because they need substrate or a cluster.