Skip to content

feat(statusline): redesign with layouts, server cache state and cold-send hint - #442

Merged
OsherElhadad merged 1 commit into
mainfrom
feat/statusline-redesign
Oct 11, 2026
Merged

OsherElhadad merged 1 commit into
mainfrom
feat/statusline-redesign

Conversation

@OsherElhadad

Copy link
Copy Markdown
Collaborator

Closes #436 (Workstream C). Design and mockups: see the issue comment.

What changes

  • context-guru-plugin/scripts/statusline.py: three layouts (--layout=minimal|balanced|detailed), per-element toggles (--hide= / --show=, env CG_STATUSLINE_*), NO_COLOR, width-aware degradation (reads COLUMNS, which Claude Code exports), one hint at most.
  • Money is labelled: saved ≈$ is the counterfactual estimate (vs the same request uncompacted, gateway prices, net of CG's own model spend and keep-alive pings); (spent $) is observed gateway-priced cost; day ≈$ is the same estimate since local midnight. They are never added or divided.
  • Cache state: the proxy's view overrides Claude Code's prompt_cache while fresh; Claude Code's is the fallback. Context uses the proxy's last forwarded prefix and its measured window when available.
  • dash/cachestate.go: new GET /api/cachestate?session= (scopeTenant, numbers only): last cache-touching request (pings included), billed TTL tier (1h if the last write was billed at 1h), prefix tokens, price to rewrite it, served window. /api/stats?lean=1 did not expose any of this.
  • Speed: no urllib/tempfile/glob imports (raw loopback socket), routing gate memoised 60 s, three reads in parallel under one 0.6 s deadline with disk caches (2 s session/cache, 60 s day). Typical render 45 ms median (p95 53) vs 107 ms (p95 123) before, same box, same stub proxy, loaded machine.

Tests

Golden output for warm / expiring / cold / first-run x minimal / balanced / detailed x widths (statusline_golden_test.go), proxy-down and colour. dash/cachestate_test.go covers the endpoint. 16 existing statusline tests asserted the old strings (cache 4:12, $0.03 of $0.41 (-12k), cache hidden by default); I updated their expectations to the new format, plus the stubs that now see a second (since=) read. go test ./dash/ ./context-guru-plugin/ passes.

Real check (before = origin/main, after = this branch)

Real interactive Claude Code 2.1.296 in tmux, routed through a distinct-basename proxy built from this branch on :4120 (preset house, scratch data dir, killed by PID afterwards). "Before" is origin/main's script run on the identical stdin Claude Code produced at the same moment. Real, redacted (no session ids). COLUMNS as noted.

state before (main, default) before (main, --cache) after
first run, new session context bar only n/a ◌ no cache yet │ ········ 0/1.0M 0%
warm, small ctx ········ 30.6k/1.0M 3% | $0.00 of $0.16 (-0) | proxy: 106ms · upstream: 10204ms adds cache 4:01 saved ≈$0.00 (spent $0.08) · day ≈$0.00 │ ● warm 4m │ ········ 30.6k/1.0M 3%
warm, 237k prefix ········ 30.6k/1.0M 3% | $0.00 of $2.24 (-0) | ... ... cache 4:01 ... saved ≈$0.00 (spent $1.12) · day ≈$0.00 │ ● warm 3m │ ██······ 237.2k/1.0M 24%
expiring same as warm (cache hidden) cache 0:42 ... │ ◐ 42s left │ ██······ 237.2k/1.0M… (80 cols)
cold, 200 cols cache hidden; bar 30.6k cache cold saved ≈$0.00 (spent $1.12) · day ≈$0.00 │ ○ cold │ ██······ 237.2k/1.0M 24% │ ▸ cold on 237.2k: next send rewrites ≈$0.59 — /compact?
cold, 80 cols as above as above saved ≈$0.00 │ ○ cold │ ctx 24% │ ▸ cold 237.2k: resend ≈$0.59 — /compact?
proxy down cg! cg! cg!

Findings from the run:

  • Claude Code's bar said 30.6k while the proxy had forwarded a 237k prefix: the second turn was refused by the model, so Claude Code never updated its count. The old bar was off by 8x; the new line uses the proxy's figure when it answered just now.
  • Claude Code's cost.total_cost_usd ($2.24) is a list-price estimate, about 2x the gateway-priced spend ($1.12). The old of $2.24 mixed that with a gateway-priced saving.
  • The old line never showed the cold state unless --cache was passed, and then without any cost.
  • Saved is $0.00 here because the filler text has nothing to compact (preset house); the labelling, not the magnitude, is what this check shows.

Not in this PR: a /cg:configure wizard and cg doctor (separate issues). Not merged, per instructions.

…send hint

Status line now shows saved (estimate) next to spent (observed), the prompt-cache state with the proxy's own view overriding Claude Code's, context against the served window, and at most one actionable hint. Adds three layouts, per-element toggles, NO_COLOR and narrow-width degradation. Adds GET /api/cachestate (last cache-touching request, billed TTL tier, prefix tokens, rewrite price, served window) so the client does not have to guess. Drops the urllib and tempfile imports and memoises the routing gate: typical render 107 ms -> 45 ms median on the same box and stub.

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

Copy link
Copy Markdown
Collaborator Author

Reviewer: approved, with non-blocking notes. CI all pass; go test ./context-guru-plugin (406 s) and ./dash green; gofmt clean.

Checked:

  • /api/cachestate is scopeTenant, forces tenant from the principal and requires session (400 otherwise). Probe as tenant-a: session=tenant-b:sess returns none; ?tenant=tenant-b is ignored for a plain tenant. The query is covered by idx_requests_tenant_session.
  • Money labels: saved ≈$ (estimate) and spent $ (observed) are separate and never summed or divided; the old mixed 'of $X' (list-price total next to gateway-priced saving) is gone. Good.
  • Render time: on this box with the proxy unrouted, 20 renders take 0.75 s vs 1.36 s for origin/main's script (~38 vs ~68 ms), same direction as the stated 45 vs 107 ms; I did not reproduce the routed numbers.
  • Conflict with feat(plugin): five cost commands (today, unused, cold, compact, trends) #441: both add one append line in dash/api.go routes(); git merges them cleanly (tested). No rebase needed in either order.

Test expectations (16): most are straight format updates and justified. Three are weaker than before:

  1. TestStatuslineExtrasHiddenByDefault now passes --hide=cache, so it proves --hide works, not that anything is hidden by default; the default is intentionally flipped, so say that in the test name and add a default-layout assertion.
  2. TestStatuslineDefaultShowsOnlySavings / ZeroTotal / RequiresStats went from exact-equality or empty-output checks to HasPrefix / not-contains 'saved'; the name 'ShowsOnlySavings' is no longer true.
  3. runStatusline now forces CG_STATUSLINE_COLUMNS=200 for every test, so only the goldens cover narrow widths (they do, adequately); the countdown tolerance widening to 60 s above 60 s remaining is justified by whole-minute display.
    None of these hide a regression I could find; the goldens cover the new behaviour.

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: Done

Development

Successfully merging this pull request may close these issues.

Workstream C: Claude Code and Codex plugins — status line, insights, onboarding

1 participant