Skip to content

feat(plugin): live cache clock, sub-agent clocks, model-switch warning (stacked on #478) - #480

Closed
OsherElhadad wants to merge 4 commits into
feat/plugin-v2from
feat/statusline-live
Closed

OsherElhadad wants to merge 4 commits into
feat/plugin-v2from
feat/statusline-live

Conversation

@OsherElhadad

@OsherElhadad OsherElhadad commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #478 (base feat/plugin-v2; retarget to main once #478 merges).

The status line already shows a draining cache bar. This adds a live clock and covers sub-agents, which have their own caches.

What changes for the user

  • Live cache clock. Counts down in seconds (cache ● ████░░ 3:57), amber in the last minute, red with ! in the last 15 s, then counts up (cache ○ cold 1:20). refreshInterval is now 1 (a value someone tuned is kept). The clock runs from the end of the last response, not its start.
  • Sub-agents. Each sub-agent has its own cache. One shows its clock (agent ● 4:21); several show the count and the one expiring soonest (agents 5 · soonest ◐ 0:52). Finished (cold) sub-agents are not shown.
  • Main clock was wrong with sub-agents. /api/cachestate described the latest request of any thread, so a busy sub-agent kept resetting the main countdown and shrank the context bar. Both now follow the main thread.
  • Removed the /compact? suggestion from the cold-cache hint. The hint now states the dollar cost only, in one fixed phrasing per state (your next message costs ≈$0.78 extra) so the line does not change wording as the clock ticks. Every state fits 80 columns.
  • Model-switch warning while the cache is warm (a switch rewrites it), and last turn rewrote the cache: tools changed (+2 −0) from Claude Code's own miss report.
  • cg ✕ proxy offline instead of cg!.
  • Detailed layout adds spent $4.10 · $2.73/h · up 1h30m.
  • statusline.py --set-layout=minimal|balanced|detailed|auto remembers a layout across renders (Claude Code cannot send keys to a status line, so bind it to an alias or command).

Server

GET /api/cachestate gains end_ts and threads[] (per-thread last use, TTL tier, prefix size, rewrite price; threads idle for two hours are dropped). Numbers only, same scope as before. Read from the existing requests.thread_id; no schema change.

Findings from the binary

The Claude Code 2.1.296 status line payload has no sub-agent state (agent.name only), refreshInterval is clamped to at least 1 s, and prompt_cache.expires_at covers the main thread only. So the proxy is the source for sub-agents.

Verification

  • Go tests: new dash test for threads and response end; golden tests for critical, cold counting up (1:15 and 1h00m), main clock not reset by a sub-agent, one/several/finished sub-agents, narrow width, model switch (and same model spelled two ways), detailed spend; unit tests for the timer arithmetic (expiry cliff at 289/290/299/300/301 s, colour bands on both TTL tiers, response-end anchor, sample age, a client clock decades off, malformed input) and for --set-layout.
  • Renders (light and dark SVG, asciicast, and a real 50 s run at one render per second) in docs/statusline-live/, produced against a test proxy with synthetic data.
  • Render cost: median 74 ms per process on a loaded host, the same as feat(plugin): one prefix, status line, terminal views and user docs #478 (bare python3 -c pass is 24 ms here; main() itself is 17 ms in-process). It never waits on the network beyond the existing 0.6 s deadline.

Not in this PR

Context-full ETA, a saved-today sparkline and a "next ping" countdown need data the proxy does not yet expose.

Notes

Osher-Elhadad added 3 commits October 12, 2026 00:00
Adds GET /api/spend/explain (dollars by token type, full-prefix rewrites
classified from token columns, live cache state, Context Guru ledger) and
GET /api/tools/last-used, and scripts/cgcost.py with five skills: cost-today,
cost-unused, cost-cold, cost-compact, cost-trends. Refs #436.

Signed-off-by: Osher-Elhadad <[email protected]>
…commands

Status line: saved session/today/lifetime, a cache bar that drains to expiry with a
ping marker, a context bar with a rewrite-near warning, one hint, refreshInterval 5.
New cg plugin: /cg, savings, cache, waste, session, doctor, built on the cost engine
from #441 (moved, not copied). Codex gets the same commands as skills.

Signed-off-by: Osher-Elhadad <[email protected]>
Count the cache down in seconds (amber, then red, then up as "cold 1:20")
and give each running sub-agent its own clock. /api/cachestate gains the
response end time and a per-thread list, and the main clock and context
bar now follow the main thread instead of whichever agent spoke last.

Drop the /compact suggestion from the cold-cache hint, warn when a model
switch will rewrite the cache, explain a tool-set miss, say "proxy
offline" in words, and add spend, $/h and session age to the detailed
layout plus a remembered --set-layout toggle.

Signed-off-by: Osher-Elhadad <[email protected]>
@OsherElhadad

Copy link
Copy Markdown
Collaborator Author

Design review, round 1: status line v3 (live clock, sub-agent clocks, model-switch warning). Reviewed all screens and the live 1 Hz recording against the status-line rubric, as a busy first-time user.

Rubric

Item Result
Answers the three questions PASS: saved (line 1), will the cache cost me (clock plus hint), what to do (hint)
At most 2 lines FAIL: the second line is 97 to 120 columns whenever a hint shows, so it wraps on an 80-column terminal. The live-countdown recording is 120 columns in a 110-column frame
Dollars first PASS
No raw token counts PASS in the default layout; FAIL in detailed (raw milliseconds, see 4)
At most one hint PASS
Colour is not the only signal PASS: glyphs differ per state (filled, half, hollow, !)
Light and dark PASS
Cold state PASS: counting up from "cold" is clear

Findings

  1. BLOCKING, line 2 width: with a hint, the line is 97 columns (expiring, critical), 99 (cold), 104 (model switch) and 120 (live-countdown with sub-agents). Nothing shows how it looks at 80 columns. Either shorten the hints to fit about 78 columns or let line 2 drop the hint before it wraps, and add an 80-column recording of the worst case (clocks for sub-agents plus a hint).
  2. BLOCKING, hint wording flickers: in the live recording the cold hint alternates between "cold: next message ≈$0.78 extra" and "cache is cold: your next message costs ≈$0.78 extra". Two phrasings for one state make the line jump each second. Use one, the short one.
  3. BLOCKING, agents ◐ 0:51 ● 4:21: a first-time user cannot tell which agent a clock belongs to, or what an agent is here. With two clocks and no names or count, "0:51" could be anything. Show a count and only the soonest expiry (as the 5-agent layout already does: agents 5 · next ◐ 0:52), or label each clock a1, a2. Use the count form for any number above one.
  4. POLISH, detailed layout: "proxy: 0ms · upstream: 7000ms" is jargon and raw milliseconds, and line 1 grows to 93 columns. Either say "slow upstream: 7 s" only when it is slow, or keep this out of the default of any layout a new user can reach.
  5. POLISH, tool-set-changed: "last miss: tool set changed (+2 −0)" is neither actionable nor current. Say what it cost and what to do ("Tools changed: that miss cost ≈$X. Add tools before you start a session.") or drop it.
  6. POLISH, model-switch hint: "your next message rewrites the cache" uses "rewrites". Say "your next message costs ≈$0.78 extra because you changed model".
  7. POLISH, bar at 0:40 left shows one cell filled and the clock is amber; at 0:08 the bar is empty. Fine, but the README table says "60 s to 15 s" for amber and the bar math is on a 5 minute scale; add the 1 h tier case to the screens, or note the bar rescales.

Pass needs 1 to 3 fixed and an 80-column recording.

@OsherElhadad

Copy link
Copy Markdown
Collaborator Author

Review of b34ff93 (stacked on #478).

Run: go vet and gofmt clean; go test ./dash -run CacheState|ThreadsFor ok; go test ./context-guru-plugin -run 'Statusline|StatusLine|Settings|Install|Layout|Timer' ok (218 s under load). Attribution clean; no hosts, ids or paths in the diff.

Checked

  • The claim that the provider's clock runs from the response end, not the start (it drives end_ts and the countdown). I tested it on the production snapshot (read-only, non-ping rows, 2xx, same tenant/session/model, previous 5m-tier request, hit = cache_read >= half the prompt): where the start-to-start gap was over 295 s but the end-to-start gap was at most 295 s, 272 of 332 requests hit (82%); where both gaps were over 295 s, 759 of 4,499 hit (17%). So the end anchor is supported (class: observed, n=332 and 4,499, session grain without thread because the snapshot predates thread_id, so sub-agent branches add noise). Anchoring on the end is also the safe reading only if the 15-minute cap on trusted upstream time holds, which it does (maxDurationMS).
  • Timer math: the clock uses only the difference of two server timestamps and local elapsed time, so client clock skew changes nothing; boundary tests at 289/290/299/300/301 s and both TTL tiers are in the goldens.
  • Server: ThreadsFor uses the existing (tenant, session, ts) index, is capped at 16 threads and a two-hour window, selects numbers only (no content), and keeps the same filter scope as the existing read. No schema change. Bare columns next to MAX(ts) in the GROUP BY rely on SQLite's documented behaviour; fine here.
  • --set-layout writes only a closed layout name into the per-user config dir.

Findings (none blocking)

  1. refreshInterval 1 means one status-line process per second per open session (about 74 ms each on this host, so roughly 7% of a core per session while idle) and, with the 2 s cache, a cachestate read every 2 s per session on the proxy. For a long session ThreadsFor scans every row of the session in the last two hours each time. Consider 2 s, or measure the read on a session with several thousand requests and put the number in the PR.
  2. Installs from feat(plugin): one prefix, status line, terminal views and user docs #478 wrote refreshInterval 5; the tuned-value rule keeps it, so existing users do not get the 1 s clock unless they reinstall or edit it. Say so in the PR text, or migrate a value equal to the old default.
  3. The response-end anchor holds for the 5 m tier on this evidence; the 1 h tier was not tested (no 1 h writes in the snapshot), so the 3600 s countdown is by extension. Mention it as untested.
  4. Merge after feat(plugin): one prefix, status line, terminal views and user docs #478 and retarget to main.

Approved; labelled ready-to-merge.

@OsherElhadad OsherElhadad added the ready-to-merge Program PR approved by the reviewer, CI green; needs maintainer approval label Oct 12, 2026
…k, 80-column renders

Hints no longer change wording as the clock ticks, say what a pause or
model change costs in dollars, and fit an 80-column terminal. Several
sub-agents show a count and the soonest expiry instead of an unlabelled
list of clocks. Latency over a second is shown in seconds.

Signed-off-by: Osher-Elhadad <[email protected]>
@OsherElhadad

Copy link
Copy Markdown
Collaborator Author

Design review, round 2: PASS.

Re-checked every recording at commit b38f972. Blockers 1 to 3 are fixed: every default-layout render fits 79 columns (including the cold, five-sub-agent, hint worst case and the live 1 Hz run); each state has one hint phrasing, and the live run only changes wording when the state itself changes (expiring to cold); sub-agents show as agent ● 4:21 or agents N · soonest ◐ 0:52. The 1 h tier screen is added.

Remaining POLISH, non-blocking:

  1. The detailed layout is 96 columns (opt-in) and still prints proxy: 0ms; show it only when slow.
  2. Tool-set hint "last turn rewrote the cache: tools changed (+2 −0)" says what happened but not what to do; add "set tools before you start" when there is room.

@OsherElhadad

Copy link
Copy Markdown
Collaborator Author

Moved into #478 (one plugin, one status line).

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

Labels

ready-to-merge Program PR approved by the reviewer, CI green; needs maintainer approval

Projects

Status: New/ToDo

Development

Successfully merging this pull request may close these issues.

1 participant