feat(acp-adapter): forward context-window usage as ACP usage_update session updates#1886
feat(acp-adapter): forward context-window usage as ACP usage_update session updates#1886askie wants to merge 2 commits into
Conversation
…ge_update
The ACP adapter never surfaced context-window usage on the wire even
though agent-core emits it on every context change; clients (e.g. the
grix-connector toolbar) had no way to render a live context gauge.
Forward main-agent agent.status.updated events as the spec's
usage_update session update ({used, size}), deduped per turn on an
unchanged pair.
🦋 Changeset detectedLatest commit: 2381274 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 238127446d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }); | ||
| return; | ||
| } | ||
| if (event.type === 'agent.status.updated') { |
There was a problem hiding this comment.
Forward usage updates during /compact
When an ACP client invokes /compact, runBuiltInCommand routes to runCompactCommand instead of this runTurnBody listener, while the core compaction path updates the context and emits agent.status.updated after reducing the token count. Because the new usage_update forwarding only lives in the prompt-turn listener, the client’s context gauge remains at the pre-compaction usage until another model turn happens. Please reuse the mapper in the compaction subscription or send a status snapshot after compaction completes.
Useful? React with 👍 / 👎.
Problem
Context-window usage is visible in the interactive TUI (which subscribes in-process to
agent.status.updated), but the ACP surface never emits it: the adapter's event map only translates message/thought/tool/plan events, so ACP clients (Zed, IDE integrations, headless bridges) have no way to render a live context gauge. The only ACP-visible form is the plain text of the/statusand/usageslash commands.The ACP spec already defines the wire-level counterpart: the
usage_updatesession update variant ({ used, size }, present in@agentclientprotocol/sdk0.23types.gen.d.ts), which Kimi never sends.Change
events-map.ts: newstatusToUsageUpdateSessionUpdate()mappingagent.status.updated→usage_updatewithused = contextTokens,size = maxContextTokens. Returnsnullfor status events that don't carry a usable pair (model/plan/permission-only updates,size <= 0).session.ts: forward main-agent status events through that mapping inside the prompt loop, deduped per turn on an unchanged(used, size)pair — status events also fire for plan/permission toggles where the token count didn't move, and those shouldn't hit the wire. Turn-scoped dedupe on purpose: a fresh turn re-sends the current value so a client that (re)connected between turns still gets a baseline. Subagent status events are filtered out.Testing
session-prompt.test.ts).packages/acp-adaptersuite: 36 files / 308 tests pass.kimi acpsession over stdio; the turn emittedusage_update {"used":23810,"size":1048576}alongside the usual chunks, andstopReasonbehavior is unchanged (usage_updateis meta-only for clients that ignore it).