mirror of
https://github.com/donlucasx/xscapes.git
synced 2026-10-20 08:43:32 +02:00
His ask: "can we add the token spent counter? Maybe it can be a simple number on the top right of the xscape? should we do it xxxx/1M? can xscapes automatically detect the max context window?" The figure comes off the agent's transcript (internal/spend): every assistant line carries the API's usage, a streamed message repeats it once per content block (six times, measured), so a response counts once per message id; subagents' transcripts under the session's directory count too. Claude Code's status payload carries only the WINDOW's tokens from the last response and a dollar figure, per its docs, so the statusline event now carries the window size alone (parked) and the hook forwards the transcript path. The frame loop polls the tally every two seconds, bytes past the last offset only. This session's own transcript: 22.77M tokens over 79 responses, cache reads 97% of it, which is why "/1M" would mislead: the spend passes the window many times over, and the window's fill is the moon's channel already. No denominator. drawTokens, both scapes: row one, one cell in from the right, the balloon's darkened ground, the readout's dim ink; "23M tokens" from 60 columns, the bare number from 40, nothing under the shore's floor (the star-touch sweep at 30x8 went 54 -> 56 with even four cells reserved). Placed stars keep off its cells: the shore re-throws only the darts that land there, so every other star stays where it was (the golden constellation holds); the vista moves such a star one row down. A falling star shows through it: over the arrival sweep 2,232 of 26,694 flights (8.4%) cross the counter's cells on row 1, and blocking them cost his flight floors (88.6 -> 84.3%), so the label yields a cell to a star on it for the frame or two it is there. Hidden under the vista's floor, where the owl's box holds the corner. Tests: TestFormatTokens (four characters at every magnitude; 999,999 is "1.0M"), TestNoPlacedStarSitsUnderTheSpendCounter, TestNoVistaStarSitsUnderTheSpendCounter, TestTheSpendCounterSitsTopRightInEveryScape (both scapes, four sizes, four hours, at least 100 luma over the ground), TestTheTallyCountsEachResponseOnce, TestTheStatuslineCarriesTheWindow. frames.compose is shared by the live frame and the tests. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
27 lines
1.0 KiB
Go
27 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/donlucasx/xscapes/internal/event"
|
|
)
|
|
|
|
// TestTheStatuslineCarriesTheWindow: the context event made from Claude
|
|
// Code's statusline payload carries the model's window along with the
|
|
// reading, and NOT the payload's token "totals", which are the window's
|
|
// tokens from the last response and not the session's spend; a payload with
|
|
// no reading makes no event.
|
|
func TestTheStatuslineCarriesTheWindow(t *testing.T) {
|
|
in := []byte(`{"session_id":"s1","context_window":{"total_input_tokens":1200000,"total_output_tokens":34567,"context_window_size":1000000,"used_percentage":38.5}}`)
|
|
e, ok := statuslineEvent(in)
|
|
if !ok || e.Kind != event.Context || e.Frac == nil || *e.Frac != 0.385 {
|
|
t.Fatalf("event %+v ok=%v", e, ok)
|
|
}
|
|
if e.Tokens != 0 || e.Window != 1_000_000 || e.Session != "s1" {
|
|
t.Errorf("tokens %d window %d session %q", e.Tokens, e.Window, e.Session)
|
|
}
|
|
if _, ok := statuslineEvent([]byte(`{"context_window":{"used_percentage":null}}`)); ok {
|
|
t.Error("a payload with no reading made an event")
|
|
}
|
|
}
|