Context treemap
A treemap of everything in an agent's context: each prompt, tool list, memory, file, chat turn and tool result is a tile sized by tokens, tiles slide as the window fills, unused room stays hatched, and compaction folds old turns into one summary tile.
oxyn add context-treemapNo compaction so far – the before and after will show here when it runs.
rsx! {
ContextTreemap {
blocks: Some(session.context_blocks()),
limit: 200_000,
compaction: session.last_compaction(),
now: clock.now(),
on_select: move |id| inspect(id),
}
}Rendered from Rust at build time · goes live when visible
When to use
- A treemap of everything in an agent's context: each prompt, tool list, memory, file, chat turn and tool result is a tile sized by tokens; tiles slide as the window fills, unused room stays hatched, and compaction folds old turns into one summary tile.
When not to use
- An agent asks before it acts: use Approval Card instead.
- Several open requests in one card: use Approval pager instead.
- An agent's question in its own card above the composer: use Decision Card instead.
Installation
Context treemap is free and MIT. The oxyn CLI copies its code, and the components it needs, into src/oxyn/ of your Dioxus or GPUI project, so it is yours to change.
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add context-treemapuse crate::oxyn::{ContextTreemap, STATUS_INDICATOR_CSS};Rather depend on the crate? cargo add oxyn-dioxus oxyn-core --git https://github.com/ismailqureshi72/Oxyn, then use oxyn_dioxus::{ContextTreemap, STATUS_INDICATOR_CSS};
Usage
rsx! {
ContextTreemap {
blocks: Some(session.context_blocks()),
limit: 200_000,
compaction: session.last_compaction(),
now: clock.now(),
on_select: move |id| inspect(id),
}
}Examples
Live
The session grows tile by tile, hits the limit, compacts – old turns squeeze into a summary – and Before | After appears.
No compaction so far – the before and after will show here when it runs.
Code
rsx! {
ContextTreemap {
blocks: Some(session.context_blocks()),
limit: 200_000,
compaction: session.last_compaction(),
now: clock.now(),
on_select: move |id| inspect(id),
}
}Fresh
A fresh session: small tiles, the dashed free space, no compaction so far.
No compaction so far – the before and after will show here when it runs.
Code
rsx! {
ContextTreemap {
blocks: Some(session.context_blocks()),
limit: 200_000,
compaction: session.last_compaction(),
now: clock.now(),
on_select: move |id| inspect(id),
}
}Nearly full
Nearly full: the percent turns amber and the free space is a sliver.
No compaction so far – the before and after will show here when it runs.
Code
rsx! {
ContextTreemap {
blocks: Some(session.context_blocks()),
limit: 200_000,
compaction: session.last_compaction(),
now: clock.now(),
on_select: move |id| inspect(id),
}
}After compaction
After a compaction: kept parts, a green summary, and the line of what was kept, summarized and dropped.
173k → 73.7k6 kept · 65.3k3 summarized · 91.1k into 8.4k1 dropped · 16.2k
Code
rsx! {
ContextTreemap {
blocks: Some(session.context_blocks()),
limit: 200_000,
compaction: session.last_compaction(),
now: clock.now(),
on_select: move |id| inspect(id),
}
}Before compaction
Before: the parts that were summarized or dropped come back, dashed and tagged.
173k → 73.7k6 kept · 65.3k3 summarized · 91.1k into 8.4k1 dropped · 16.2k
Code
rsx! {
ContextTreemap {
blocks: Some(session.context_blocks()),
limit: 200_000,
compaction: session.last_compaction(),
now: clock.now(),
on_select: move |id| inspect(id),
}
}Open a part
A tile pointed at: its card with tokens, share and what it holds.
- GitHub
- Terminal
- Search
- Read file
- Edit file
- Vercel
- Sentry
- Linear
No compaction so far – the before and after will show here when it runs.
Code
rsx! {
ContextTreemap {
blocks: Some(session.context_blocks()),
limit: 200_000,
compaction: session.last_compaction(),
now: clock.now(),
on_select: move |id| inspect(id),
}
}Agent menu
The agent menu: each agent with its model and window size.
No compaction so far – the before and after will show here when it runs.
Code
rsx! {
ContextTreemap {
blocks: Some(session.context_blocks()),
limit: 200_000,
compaction: session.last_compaction(),
now: clock.now(),
on_select: move |id| inspect(id),
}
}Narrow
Under 480 px the map is shorter and the numbers take a line of their own.
173k → 73.7k6 kept · 65.3k3 summarized · 91.1k into 8.4k1 dropped · 16.2k
Code
rsx! {
ContextTreemap {
blocks: Some(session.context_blocks()),
limit: 200_000,
compaction: session.last_compaction(),
now: clock.now(),
on_select: move |id| inspect(id),
}
}Classic
Classic style: a grey band, more saturated tiles with a solid edge, a white percent.
173k → 73.7k6 kept · 65.3k3 summarized · 91.1k into 8.4k1 dropped · 16.2k
Code
rsx! {
ContextTreemap {
blocks: Some(session.context_blocks()),
limit: 200_000,
compaction: session.last_compaction(),
now: clock.now(),
on_select: move |id| inspect(id),
}
}API reference
ContextTreemap
| Prop | Type | Default | Description |
|---|---|---|---|
blocks | Option<Vec<CtxBlock>> | Default::default() | Every part of the context, in tile order (the demo's when `None`). |
limit | u32 | Default::default() | The window's size in tokens (the current agent's when 0). |
agents | Option<Vec<CtxAgent>> | Default::default() | Agents to switch between (the demo's when `None`). |
agent | String | Default::default() | The agent shown first (id; the first when empty). |
compaction | Option<CtxCompaction> | Default::default() | The last compaction (adds Before | After and the line under the map). |
compacted | bool | Default::default() | Demo only: show the demo's compaction. |
view | String | "after" | Which side of the compaction shows first (`before` / `after`). |
grow | f32 | 0.35 | Demo only: grow the session (0–1) when `live` is off. |
live | bool | Default::default() | Demo only: the session grows, compacts and settles on its own. |
status | String | Default::default() | A short status in the bar ("Compacting"). |
point | String | Default::default() | A tile pointed at from the start (its card shows). |
menu_open | bool | Default::default() | The agent menu open from the start. |
title | String | "Context" | Heading. |
nowrequired | ClockMs | — | The clock. |
style | String | Default::default() | `clean`, `classic`, or empty to follow `data-cstyle`. |
on_select | EventHandler<String> | — | A tile was clicked (block id; empty for the free space). |
on_agent_change | EventHandler<String> | — | Another agent was picked. |
on_view_change | EventHandler<String> | — | Before | After was switched. |
Read from the Rust signature and doc comments.
Keyboard interactions
| Key | Action |
|---|---|
| Tab | Through the agent menu, Before | After and the tiles |
| EnterorSpace | Pins the focused tile's card, or lets it go |
| Escape | Lets go of the pinned card and closes the menu |
Accessibility
- The map is a list named by its title; every tile is an item with its name, kind and tokens.
- The fill level is text in the bar – its colour is extra, not the only signal.
- Before | After is a radio group; the agent menu is a listbox.
Responsive behaviour
- 680 px up to its container; the map keeps its height and tiles too small for a label show only their colour.
- Under 480 px the map is 220 px tall and the numbers move to a line of their own.
Edge cases (spec)
680 px up to its container; the map keeps its height and the layout stretches. Under 480 px the map is 220 px and the numbers take a line of their own.
Notes for AI
- Import
ContextTreemapfromoxyn_dioxusand includeSTATUS_INDICATOR_CSSplus the token stylesheet once. - A GPUI version exists:
ContextTreemapElinoxyn_gpui. - Props to set first:
now. - It reads a clock (
now) for live timers; pass one clock for the whole page rather than one per component. - Keep its states and timings as they ship; restyle it through the CSS variables rather than by hand.