Skip to main content

Module contextbar

Module contextbar 

Source
Expand description

The context bar: how much of the model’s window the last prompt took, drawn the same way wherever it is read.

Three surfaces show this number — the line under the composer, the full-screen read-out, and the dashboard’s stats row — and they had three arithmetics. The dashboard’s was the one that was wrong: its denominator was the compaction rail because that was the only number the stats event carried, so ctx 12.3K/279K was saying the prompt was 4% of a number the model had never been told, and the rail’s own share of the window was drawn nowhere.

So the shape lives here, and a surface only chooses a width and a colour. That is the whole point: a bar whose denominator differs per screen is a bar two screens can disagree about.

Structs§

Pieces
One read-out, in the pieces a surface needs to colour it.
Reading
One reading of the context bar: what was used, out of what, with the tripwire where the compaction policy puts it.

Constants§

MARKER
The column where compaction begins. │ is one cell wide in a monospaced terminal and reads as a tripwire even where there is no colour at all.
PAST_MARKER
The fill once it has reached the marker: the “living on borrowed time” zone. A shape rather than a colour, so it survives a pipe, a --no-color run, and a screenshot.

Functions§

bar
A proportional bar. width cells; the fill is clamped, so an over-budget prompt shows a full bar rather than a panic or a negative count.
bar_marked
A bar whose denominator is the whole window, with the compaction threshold marked as one column. share and marker are both shares of that window; marker outside (0, 1) is not a tripwire (0 is off, 1 is the hard limit the bar’s own end already is) and the bar falls back to being unmarked.
short_tokens
1234 → 1.2K, 1234567 → 1.2M. One decimal below 100 units, none above, so the numbers stop changing width on every turn.