Skip to content

feat: feed the context donut from _x.ai/session/info (control-plane, no window cost) - #80

Open
funkpopo wants to merge 4 commits into
phuryn:mainfrom
funkpopo:session-info-update
Open

feat: feed the context donut from _x.ai/session/info (control-plane, no window cost)#80
funkpopo wants to merge 4 commits into
phuryn:mainfrom
funkpopo:session-info-update

Conversation

@funkpopo

Copy link
Copy Markdown
Contributor

Wire the context donut (and its popover) to the CLI’s control-plane
_x.ai/session/info RPC so we can show an accurate, structured window
breakdown without spending a model turn or inflating the context window.

Today the donut mostly rides turn-end _meta.totalTokens, with
signals.json + a hidden /session-info prompt as backups. That works
for a single “used / window” number, but:

  • cold restore and post-/compact still lag or need a prompt scrape on older paths;
  • there is no way to show where the window went (system / tools / messages / skills / MCP);
  • the hidden /session-info prompt is a real inference turn on CLIs that lack the rail — wasteful and easy to get wrong.

Grok CLI ≥ ~0.2.112 exposes _x.ai/session/info as a meter, not a prompt:
repeated calls do not bill, do not append chat history, and do not grow
context.used (probe-verified). This PR prefers that path whenever the
method exists, and keeps the existing sources as an ordered fallback.

What changed

Host / ACP

  • AcpClient.getSessionInfo()_x.ai/session/info; returns "unsupported"
    on -32601 so older CLIs (incl. the Windows pin) degrade cleanly.
  • Pure parsers in acp-dispatch.ts:
    • parseSessionInfoRpcResult (flat or one-level nested result)
    • sessionInfoCacheFresh + SESSION_INFO_TTL_MS (3s) so popover spam
      doesn’t hammer the process
  • Per-session latch: lastSessionInfoAt, sessionInfoUnsupported
    (reset on a fresh process)

Refresh policy (priority)

  1. Turn meta / auto_compact_completed — still the live “used” path mid-session
  2. _x.ai/session/info — structured snapshot (used + window + breakdown)
  3. signals.json — cold / disk seed
  4. Hidden /session-info prompt — legacy only when the RPC is missing

Called on:

  • cold session/load (disk first, then upgrade via session/info)
  • donut popover open (refreshContextDetails, TTL-gated)
  • post-/compact when the live rail didn’t fire
  • compact re-prime backup path (unchanged intent, better first hop)

Webview

  • Host message contextUsage gains optional breakdown fields
    (systemPromptTokens, toolDefinitionsTokens, messageTokens,
    freeTokens, categories[], autoCompactThresholdPercent).
  • Popover gains an In this window section (System / Tools / Messages /
    Skills / MCP / Free / Auto-compact at).
  • Opening the donut posts refreshContextDetails; an open popover
    re-renders when a structured snapshot arrives.
  • Session swap clears breakdown state so numbers don’t flash across sessions.

Protocol / remote

  • refreshContextDetails added to WebviewMsg + remote policy (view).
  • Host↔webview contract stays the single source of truth in protocol.ts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant