Greptile: "Normal Desktop usage omits gauges". plan_gauge was built only in
tui_gateway/server.py::_get_usage (the embedded backend), but a normal local
Desktop session reads its session.usage ticks and message.complete usage from
gateway/session_usage (usage_stats -> tui_usage), so the status-bar allowance
never showed. Move the builder to gateway.session_usage.plan_gauge, use it on
both paths (omitted off a window plan, as before), and type it on the Usage,
SessionStats and session.usage contracts (regenerated).
The usage_frame docstring said the nested ``usage`` view matched
server._get_usage with the same keys, rules and omissions. It does not
quite: dev_credits_spent_micros (HERMES_DEV_CREDITS only) is not carried,
and avg_latency_s / avg_tps are rounded from the counters' two decimals
rather than the raw values, so they can differ by 0.1 at a rounding
boundary. Describe it as the standard status-bar projection and name both
exceptions. Docstring only; no behaviour change.
Refs #134889 (RT-33)
Refs #140208
SessionState.apply_event preferred a nested payload["usage"] dict, a
shape written for an older {usage: {...flat counters...}} wrapping. Now
that usage_frame() also carries the TUI status-bar view under "usage",
the classic CLI cached that nested dict, and
GatewayAgent.apply_session_usage matched none of its keys. Mid-turn,
the status bar (context bar, latency, t/s, the spinner's token count,
rate limit, compression count) kept the previous turn's figures until
the turn-end session.stats refresh.
The top-level counters now win whenever the frame carries them
(api_calls is an int); the old wrapped shape still reads its nested
dict. The usage_frame docstring now names what really reads each half,
and lists the readers that must move before the deprecated counters
can go.
Refs #134889 (RT-33)
Refs #140194
Refs #140208
The salvaged commit (#140195) makes a local viewer's session.usage frame
carry tui_usage(stats) under `usage` next to the flat counters, so a
Desktop bundle that reads only `payload.usage` (anything before
usageFromTick) fills its context, cache-hit and t/s meters again.
That nested view must be what the embedded backend's ticker sends
(`{"usage": server._get_usage(agent)}`), field for field. It was not in
one case: _get_usage reports `compressions` whenever the agent has a
compressor, but tui_usage keyed it on `context_length`, which usage_stats
sets to None while the compressor does not know its window yet. Key it
on `context_source`, which usage_stats sets exactly when there is a
compressor. Same counters, no new state.
The top-level counters on session.usage are now documented as deprecated
in SessionUsagePayload and usage_frame (kept for hermes_cli.gateway_agent,
the Ink TUI and Desktop's usageFromTick); the generated contract files
are regenerated for the docstring.
Tests: the published nested view equals _get_usage(agent) for a steady,
an unsized-compressor and a fresh agent; Desktop's handleEvent paints the
meters from the dual frame, from its nested view alone (the pre-
usageFromTick reader) and from the deprecated counters alone.
Refs #134889 (RT-33)
Refs #140194
Refs #140208
Co-authored-by: herovivian <herovivian@gmail.com>
The mid-turn `session.usage` event published only the session-cumulative
counters. That is what `hermes_cli.gateway_agent` (the classic CLI / TUI
mirror) reads, but the Desktop status bar reads only the nested `usage`
view (`apps/desktop/src/lib/statusbar.tsx`: `context_max`,
`context_used`, `context_percent`, `avg_tps`, `cache_hit_pct`), so no
TypeScript in the app reads the frame at all.
On the session-authority path the embedded ticker that normally supplies
that view (`server._start_usage_ticker`) never runs, so a Desktop
attached to the host gateway sat with its context, cache-hit and
tokens-per-second meters at the empty placeholder for every turn, while
the rest of the bar (approval pill, running timer, version) was fine.
`SessionUsagePayload` already allows either view, so publish both in one
frame. The counters are untouched, so every existing consumer is
unaffected.
(cherry picked from commit 5a80c328367217f2bb0d3092926b57cfbd985190)
Main's TUI painted context used/max, the context bar, ◷ latency, t/s, the cmp
badge and cache hit off message.complete.usage (tui_gateway _get_usage). The
canonical completion_payload() never carried usage, so none of those segments
ever appeared on the shared gateway (FINDINGS row 5).
The turn-end session.usage publish now also records its stats dict on the
captured execution result; completion_payload() projects it into main's TUI
Usage shape (session_usage.tui_usage: input/output/total/calls, context_*,
compressions, cache_hit_pct, avg_latency_s, avg_tps, active_subagents).
Messaging turns record nothing and their completion is unchanged.
(cherry picked from commit ffa4fbb032ac753bc451cec93572618130113a73)
(cherry picked from commit 2f1d0bfb0660106c61da7e2b03f03f2f7fc970cf)
Main's /compress bumps its in-process agent's context_compressor.compression_count, which
the status bar (`🗜️ N`) and /usage read for the rest of the session. The canonical
session.mutate(compress) summarizes with a throwaway ContextCompressor and then evicts the
cached agent at the boundary, so the successor agent started at 0 and every session.usage
frame overwrote the CLI's local `+= 1` with 0.
- gateway/session_usage.py: the count rides the LiveSession. note_compression() runs at a
fresh compress commit (never an exact retry: `applied` + owns_projection), before the
boundary evicts the agent, as max(carried, evicted agent's) + 1; reset zeroes it (main's
/new builds a fresh agent). seed_compression_count() sets the successor's compressor when
a local-viewer turn wires it, so publish_usage carries it; session.stats overlays it for
the window before that turn.
- gateway/local_viewer_events.wire seeds the count per local-viewer turn.
Red first: test_session_mutation_compress asserted session.stats compression_count == 1
after the commit and got 0; it also pins the count after the next turn and after the exact
retry (no recount).
(cherry picked from commit 5fb447950bb9fd4302d065b593d9fac73618d037)
Main's HermesCLI painted its status bar (context, ◷ latency, t/s, the spinner's
↓ N tok), /usage and the exit summary straight off its in-process agent's
session_* counters, context_compressor and get_rate_limit_state(). On the
session authority that agent lives in the gateway.
- gateway/session_usage.py::usage_stats builds the frozen wave-A2 dict:
input/output/cache_read/cache_write/prompt/completion/total/reasoning tokens,
api_calls, last_prompt_tokens, anchored context_tokens, context_length,
config_context_length, context_source, compression_count, avg_latency_s,
tokens_per_s (main's status-bar math over _api_latency_history /
_api_output_history), last_turn_tokens (output since the turn started),
serialized rate_limit, active_subagents, model, provider, fallback_model.
Session-cumulative, like agent.session_*.
- Published as session.usage (top-level fields) after every API call (each
agent step after the first) and at turn end, only on local-viewer turns.
- session.stats {session_id} returns the same dict (zeros before an agent exists).
- Contracts: SessionUsagePayload accepts the local-viewer fields beside the
TUI ticker's `usage`; session.stats declared; generated TS/OpenRPC regenerated.
Messaging turns publish no session.usage (asserted for TELEGRAM).
Test: tests/gateway/test_local_viewer_usage.py (red on cli-base).
(cherry picked from commit 975478f18bd42b12d4511b3f5dd03cb651e0fc1b)