Skip to content

feat(plugin): next-request cost on the status line, shared request budget, context bar fix - #653

Merged
OsherElhadad merged 1 commit into
mainfrom
feat/statusline-next-cost
Oct 21, 2026
Merged

OsherElhadad merged 1 commit into
mainfrom
feat/statusline-next-cost

Conversation

@OsherElhadad

Copy link
Copy Markdown
Collaborator

Implements the status line and insights parts of the plugin feature contract (sections 2, 3, 4, 7, 8, and the Manual pings category of 1/6).

What changed

  • Next-request cost. New next status-line element: next $0.03 warm · $0.30 cold, from next_warm_usd / next_cold_usd. Once cold it is next $0.30. A proxy without those fields falls back to rewrite_usd (next $0.30 if cold); an unpriced model shows nothing. It is the first element dropped when the line is too narrow.
  • Per-subagent cache status is unchanged (already shown from threads[]); the main clock and context bar still follow the main thread.
  • Request budget. At most one round trip per render. Cache files now live in ${XDG_CACHE_HOME:-~/.cache}/context-guru/ (0700; a directory owned by someone else is never used), not a shared /tmp path. TTLs: cachestate 10 s, stats 30 s. One render per window refreshes (O_EXCL lock); failures back off 1 s, 2 s, 4 s ... 5 min and the last good copy keeps rendering. Logic is in scripts/cgcache.py, vendored into the Codex plugin with cg.py.
  • cg.py cachestate --json [--session S] prints the cached cachestate plus age_s and stale, refreshing under the same rules, for the mods. Exit 1 with {"error": ...} when there is nothing.
  • Insights tools. insights tools now opens with MCP servers (per-tool rows under each) and skills with their cost, and never lists Claude Code's built-in tools. It uses carry_usd when the proxy reports it and says so when it only has unused_usd.
  • Manual pings row in savings from /api/stats manual_pings, shown once there is one.

Context bar bug (100% then back)

/api/cachestate top-level model / window / window_exact describe the latest cache touch on any thread. _main_cs replaced the model and prefix with the main thread's entry but kept the window. When the latest touch was a sub-agent on a smaller-window model (haiku, 200k, exact) and the main thread was sonnet on 1M with a 412k prefix, the bar computed 412k / 200k and read 100% with "rewrite near", until the main thread spoke again. The window is now dropped when the main thread is on a different model from the latest touch, so Claude Code's own size is used. Pinned by TestStatuslineContextBarIgnoresSubagentWindow (failed before the fix).

Notes for review

  • Existing status-line goldens were updated deliberately: next appears in the balanced and detailed layouts. The weekly-tip golden at 45 columns drops it.
  • insights tools, insights, waste goldens and their docs pages changed (the built-in NotebookEdit row is gone from the removal list; the carry list is new).
  • Tests that shared a cache through TMPDIR now share it through XDG_CACHE_HOME; the stats TTL went from 2 s to 30 s, so one backdate was widened.
  • carry_usd / carry_reads on /api/tools was requested from core-backend; until it lands, the tools section shows the unused cost and labels it as such.

Tests

go test ./context-guru-plugin/ passes (314 s). New tests: context bar, next cost (4 cases), budget TTL/private dir, back-off, cachestate --json (shared with the status line), manual pings, insights tools.

…dget, context bar fix

Status line
- New `next` element: what the next request costs for the cached prefix, warm vs cold
  (`next $0.03 warm · $0.30 cold`), from /api/cachestate next_warm_usd / next_cold_usd. An older
  proxy falls back to rewrite_usd (`next $0.30 if cold`); an unpriced model shows nothing.
- Request budget: cache files move to ${XDG_CACHE_HOME:-~/.cache}/context-guru/ (0700) instead of
  a shared /tmp path; cachestate TTL 10 s, stats TTL 30 s; one render per window refreshes
  (O_EXCL lock); failures back off exponentially up to 5 min and the last good copy is served.
  The logic lives in scripts/cgcache.py.
- `cg.py cachestate --json [--session S]` prints the cached cachestate (plus age_s, stale) and
  refreshes it under the same rules, for the mods.

Context bar
- The bar jumped to 100% and dropped back after the next request. /api/cachestate's top-level
  model/window/window_exact describe the latest touch on ANY thread, while _main_cs only swapped
  in the main thread's model and prefix, so a sub-agent on a smaller-window model made the main
  prompt read against its window. The window is now dropped when the main thread is on another
  model than the latest touch.

Insights
- `insights tools` lists MCP servers (per-tool rows under each), and skills, with their cost,
  never Claude Code's built-in tools. Uses carry_usd when the proxy reports it, else unused_usd.
- savings shows a "Manual pings" row from /api/stats manual_pings once there is one.

Assisted-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Osher Elhadad <[email protected]>
@OsherElhadad
OsherElhadad merged commit aaad0c7 into main Oct 21, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 21, 2026
@OsherElhadad
OsherElhadad deleted the feat/statusline-next-cost branch October 21, 2026 19:12
amiddavid added a commit that referenced this pull request Oct 21, 2026
…0.2.3) (#657)

chore(plugin): bump the plugins for v0.5.3 (Claude Code 0.5.3, Codex 0.2.3)

Both plugins changed in this release, so installed plugins must update.

- Claude Code plugin: the band with cache state and a Ping button
  (#651), next-request cost on the status line and the context bar
  fix (#653), insights tools leaves out unpriced carry costs (#656),
  and the xhigh preset list without the sweep (#654).
- Codex plugin: the vendored cg.py and cgcache.py from #651, #653 and
  #656.

Assisted-By: Claude
Signed-off-by: DAVID AMID <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant