Stream token counts in the `clai2` web UI while a turn runs

Merged
MP
2mo ago
+219-73

Part 7 of the clai2 web UI stack (… → #10274 → this PR). Based on #10274. No linked issue: requested by the CLAI maintainer.

Why. Show token counts streaming in the web UI while a turn runs, as the terminal footer does.

What changes

  • Every status update now carries three figures for the running turn:
    • streamed_tokens: the shell's estimate from the streamed characters, the same figure as the terminal's ~N streamed tokens;
    • output_tokens: the last turn's reported output, once it ends;
    • run: what the turn's model requests have reported so far, read from RunContext.usage.
  • Updates go out every 0.2s while streaming instead of every 0.5s. on_turn_end sends one more, once the shell has recorded the turn's real output tokens.
  • The composer bar shows a live meter while a turn runs: elapsed time, ↓ ~tokens, tokens per second, and ↑ input once a request has reported. Each finished turn ends with a quiet line: ↑ 12k · ↓ 206 · 2 requests · 3.5s.

New public surface. None (web plugin wire fields only).

Verification. test_a_turn_streams_to_the_browser now checks three things: the streamed estimate only grows, the per-request usage arrives mid-turn, and the settled status carries the reported output tokens. 43 web tests pass with 100% branch coverage of the plugin. Headed Playwright against clai2 --web with claude-code:claude-haiku-4-5 sampled the meter as ~0 → ~22 15 tok/s → ~42 19 tok/s ↑6.1k → ~113 38 tok/s ↑6.1k, then ↑ 12k · ↓ 206 · 2 requests · 3.5s, with no page errors.

What changes for existing users. Nothing until they enable web.

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
  • PR title is fit for the release changelog.