Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

4.6 KB
Raw Blame

Click the context ring to see what the context is full of

  • Date: 2026-08-24
  • Type: feature
  • Scope: web, server
  • PR: #442

中文版

The context ring in the chat composer became a button. Clicking it opens a panel that splits the current model context into six parts — system prompt, tool definitions, user messages, model messages, tool requests, tool results — as a bar running the full context window and a legend of tokens and percentages, followed by the five tools whose traffic occupies the most of it. A dashed mark on the bar says where compaction will fire. The used/window figures that used to sit beside the ring moved into that panel's header; the composer now shows the ring alone, and hovering it names the figures.

Details

  • GET /api/sessions/:sessionId/context returns the six parts, their sum, and the tool ranking. It reads the Session's newest Trace shard, which is one complete model context: the Trace writer rotates on compaction and opens the new file with session_meta and tool_list_ready, and Session resumption keeps appending to the shard it left off in.
  • Sizes come from the character heuristic core already applies to request inputs (approximateMessagesTokens), so images carry their flat allowance instead of their base64 length, and no tokenizer is introduced.
  • The panel spends those figures on shares only. Each part is drawn as its share of the occupancy the ring itself reports — the last token_usage's request.total — so the parts add up to the figure in the panel header, and every derived value is marked ~. Both columns are apportioned by largest remainder, so the percentages total exactly 100 and the token column exactly the measured occupancy.
  • Events are skipped (none of them is sent to the model), and so are the messages between a compaction_begin and its compaction_end: the compaction prompt and the summary it produces are recorded in the shard but were never part of the context being described.
  • The tool ranking counts each tool's calls and their results. A tool's definition is counted in the tool-definitions part instead, and a result whose call is not in the same shard still counts toward tool results but has no tool to be attributed to — so the ranking can sum to less than the two tool parts.
  • The bar's scale is the whole context window: the filled run is the occupancy the ring reports, the rest is headroom, and the parts subdivide the filled run. It carries no gaps between fills — once a bar has an absolute position scale, a surface gap pushes every fill after it off the coordinate the compaction mark is drawn on — so what keeps neighbouring hues apart is the palette's own adjacent-pair separation.
  • The response gained compactionThreshold: the Agent's configured compaction.max_context_length (its seeded default when unset) capped at context_window − 2048, the same derivation the Agent applies when it builds a Session's compaction settings. Null when compaction is off, when the Agent's config cannot be read, or when the threshold is not inside the window — nothing to mark.
  • Hovering a bar segment or its legend row links the two: the row lights up and the other segments fade. The bar carries no labels of its own, so this is how a sliver gets identified.
  • A shard ending in a completed compaction_end reports contextClosed, the same test Trace replay uses to decide it must replay nothing. The panel then shows — and says the next request will report the usage, matching what the ring already shows in that state, rather than describing the context that was just compacted away.
  • The panel is portaled and positioned by usePortalPanel, closing on outside click, Esc, scroll or resize. It is offered where a Session-level endpoint can serve it: not in the draft composer, which has no Session, and not in the subagent composer, whose child Session is not registered in the sessions table.

Colours

  • The six parts took a categorical palette of their own in lib/category-colors.ts, separate from SERIES_COLORS whose length is also the cost center's fold cap.
  • Legend rows are drawn in the same order as the bar segments, so only neighbours have to be told apart; the order clears the adjacent-pair gates in both light and dark (worst adjacent ΔE 21.1 simulated for protanopia and deuteranopia, 22.1 unsimulated, OKLab ×100). Six hues cannot also clear those gates for arbitrary pairs, so every legend row carries its own value beside its name.