Repository navigation
feat(events): context and cost per agent step, ACP-aware run detail - #72
Open
FreshlyBrewedCode wants to merge 3 commits into
Open
FreshlyBrewedCode wants to merge 3 commits into
FreshlyBrewedCode wants to merge 3 commits into
Conversation
AgentStepFinished gains optional `context: {used, size}` and
`cost: {amount, currency}` (ADR 0013 §5), taken from the step's `usage`
signals: the last one's context, and the latest cost any of them carried,
since the agents report the session's cost so far and Claude sends it only
at the end of a turn. Cancelled and failed steps keep what was reported.
The `usage` doc comment now says what it means per agent.
The ACP adapter adds an `acp.tool-call` CUSTOM chunk after each tool call
update that carries a title: translateAcpStream keeps only the first,
generic title (`Edit`, `Read File`), and drops the descriptive one
(`Edit math.ts`) and the real input that arrive in later updates.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Steps show context against the window and cost; the run's cost is summed per currency. Old logs fall back to agentStepContextTokens. - A running step's context and cost follow its `acp.usage` chunks. - Transcript tool calls show the agent's title (`Edit math.ts`) and input from `acp.tool-call` chunks, else the title in the arguments. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
FreshlyBrewedCode
added this pull request to stack #70
October 2, 2026 20:13
This branch has not been deployed
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
This PR implements ADR 0013 §5 and the SPA side of it: context and cost per agent step, and an ACP-aware run detail.
Events and runtime
AgentStepFinishedgains two optional fields:context: { used, size }: from the step's lastusagesignal;cost: { amount, currency }: the latest cost anyusagesignal carried.usagedoc comment now says "as the agent reports it": the last message on opencode, the whole turn on Claude.agentStepContextTokensis documented as the fallback for old logs.acp.tool-callchunk (adapter,src/runtime/acp-adapter.ts).translateAcpStreamkeeps only the first title of a tool call, and on Claude that title is generic (Edit,Read File,Terminal). The descriptive title (Edit math.ts) and the real input arrive in latertool_call_updates, and the translator drops them. Opencode's titles (git status,math.ts) are dropped the same way. So the adapter now follows each tool-call update that has a title with aCUSTOMacp.tool-callchunk,{ toolCallId, title, input? }. It carries no signal.SPA
68 chunks · 22.3k/200k ctx · $0.039.context(22.3k / 200k · 11%, with a small meter);cost;tokens(the fourusagecomponents, as reported).costrow: the step costs summed per currency, running steps included.deriveStepsreadsacp.usagechunks, so a running step's context and cost update beforeAgentStepFinishedarrives.acp.usagechunks;agentStepContextTokens, with no window, marked "(final turn)".Edit math.tswithedit · complete. The args show the agent's real input, which also fixes the run-together JSON that re-sent ACP inputs used to produce. When a log has noacp.tool-callchunks, the label falls back to thetitleinside the arguments. Old opencode logs are unchanged.src/web, so the SPA bundle doesn't import the runtime. Tests pin them toACP_CHUNK.Testing
bun run checkis green: 459 tests.nix develop --command bun run test:e2e: 17 passed. Two of them are new, ine2e/acp.e2e.ts, over a seeded ACP-shaped run:events.test.ts: round-trip, an old log without the fields still decodes, rejections.agent-step.usage.test.ts: the last context wins; cost is the latest reported, and an update without one keeps it;0 USDis recorded; a step with no usage has neither field.run.test.ts: a cancelled step keeps context and cost; a completed step records them, and omits them when none came.acp-adapter.test.ts: the fake agent's newtoolsverb sends Claude-shaped updates; the test checks theacp.tool-callchunks, their order, and that they carry no signal.run-events.test.ts: live context from chunks, cost carry-over, recorded fields win, chunk fallback for pre-feat(events): context and cost per agent step, ACP-aware run detail #65 ACP logs, theagentStepContextTokensfallback, cancelled steps, per-step isolation,runCost.transcript.test.ts: the latest title and input, title-only updates keep the input, the args-title fallback, no extra rows, old corpus logs have no title.format.test.ts:formatCostandformatContext.Live validation
The setup is a scratch project with a local bare origin, a slug that is not on GitHub, and no write-back. The two-step workflow (
implement: read, three separate edits,cat; thenreview) ran onfactory serve --port 3065with a test db. The browser checks used playwright-cli.68 chunks · 22.3k/200k ctx · $0.039,23 chunks · 20.7k/200k ctx · $0.014$0.053implementran173 chunks · 9.1k/200k ctx · $0,64 chunks · 8.2k/200k ctx · $0$0AgentStepFinished{outcome:"cancelled", context:{used:20784,…}}, no costTranscript labels:
Read math.ts,Edit math.ts×3,cat …/math.ts(execute).glob(search),math.ts(read/edit),cat math.ts(execute). Theglobargs show{"pattern":"**/math.ts"}.Deviations and notes
usage_update. The value is cumulative per session, and a step is one session. So an update without a cost keeps the earlier figure rather than erasing it. A Claude step cancelled mid-turn usually has no cost at all. test(e2e): live validation of ACP agents, docs and ADR acceptance #67 may want ADR 0013 §5 to say this.acp.tool-callchunk touches the adapter (feat(runtime): production ACP adapter for opencode and Claude Code #69's file). It lives in this layer and is documented in the adapter's module comment. test(e2e): live validation of ACP agents, docs and ADR acceptance #67 may fold it into the ADR.usage_updates reportsize: 1000000for haiku, and only the final one (the one with cost) says200000. While a Claude step runs, the row therefore reads…/1m ctx. The recordedcontextis correct. Factory shows what the agent says.Closes #65
Part of #62
🤖 Generated with Claude Code