Skip to content

Commit e20ca7d

Browse files
committed
feat: add two-stage compaction line animation with docs and unit tests
1 parent ee2d97e commit e20ca7d

6 files changed

Lines changed: 996 additions & 0 deletions

File tree

website/docs/context-engineering.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import ContextMechanismMap from '@site/src/components/VisualElements/ContextMech
77
import SkillsInvocationDiagram from '@site/src/components/VisualElements/SkillsInvocationDiagram';
88
import SubAgentFanoutDiagram from '@site/src/components/VisualElements/SubAgentFanoutDiagram';
99
import ContextSqueezeDiagram from '@site/src/components/VisualElements/ContextSqueezeDiagram';
10+
import CompactionLineDiagram from '@site/src/components/VisualElements/CompactionLineDiagram';
1011
import MCPToolSchemaDiagram from '@site/src/components/VisualElements/MCPToolSchemaDiagram';
1112
import UShapeAttentionCurve from '@site/src/components/VisualElements/UShapeAttentionCurve';
1213
import DiagramFrame from '@site/src/components/VisualElements/DiagramFrame';
@@ -233,6 +234,16 @@ Sub-agents are ideal for heavy research, multi-file analysis, and exploratory ta
233234

234235
**Context effect:** compaction replaces accumulated conversation with a smaller synthetic state, restoring working room while discarding detail. It is lossy summarization guided by your instruction, but it cannot guarantee what survives. Future relevance is unknowable at compaction time: a debugging trace that looks like noise now may be the clue the next step needed.
235236

237+
In practice, the harness usually performs two reductions, not one. First it removes or offloads stale tool traces that no longer need to be replayed. Then it summarizes the surviving sections while leaving the most recent turns intact. The raw transcript may remain available outside the model call, but only the compact working set reaches the next request.
238+
239+
<DiagramFrame kicker="Context management" title="Compaction deletes traces, then summarizes the survivors" size="full" caption={'Stale tool-call/result pairs leave the next request entirely. Surviving sections are summarized one by one, while the recent tail remains verbatim. The raw transcript may persist externally, but only the compact working set reaches the model.'}>
240+
241+
<CompactionLineDiagram />
242+
243+
</DiagramFrame>
244+
245+
Deletion is selection; summarization is transformation. Both reduce the model's working set, but only summarization preserves a synthetic version of the source section.
246+
236247
The reliable alternative is **manual handoff with external checkpointing**. Before starting a new phase, write a brief state file with the current goal, changed files, decisions, unresolved errors, and next step. Files provide exact recall; a fresh context provides inference quality.
237248

238249
### The Buffer Tax
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* Compaction Line story classes. Keyframes are injected by the TSX (inline
2+
names bypass CSS Modules renaming); these classes only attach timing. Every
3+
story element loops the shared --cycle-ms schedule set on the root svg. */
4+
.collapse,
5+
.slide,
6+
.shrink,
7+
.threadLabel,
8+
.eject,
9+
.survivor,
10+
.summary,
11+
.headroom,
12+
.legend {
13+
animation-duration: var(--cycle-ms);
14+
animation-timing-function: ease-in-out;
15+
animation-iteration-count: infinite;
16+
animation-fill-mode: both;
17+
animation-delay: var(--delay, 0ms);
18+
}
19+
20+
/* SVG transforms need a local box or scaleY collapses toward the svg origin. */
21+
.collapse {
22+
transform-box: fill-box;
23+
transform-origin: center;
24+
}
25+
26+
/* Shrink keeps the top edge fixed: the tile compresses toward its Σ slot. */
27+
.shrink {
28+
transform-box: fill-box;
29+
transform-origin: 50% 0;
30+
}
31+
32+
.summary,
33+
.headroom {
34+
opacity: 0; /* placeholder until its act arrives */
35+
}
36+
37+
/* Static fallback is authoritative: motion disabled = the complete figure.
38+
The animated scene swaps for a still of the compacted stack plus the
39+
ledger of what was freed (AnimatedTokenFlow dual-render precedent). */
40+
.staticScene {
41+
display: none;
42+
}
43+
44+
@media (prefers-reduced-motion: reduce) {
45+
.animatedScene {
46+
display: none;
47+
}
48+
49+
.staticScene {
50+
display: initial;
51+
}
52+
53+
.legend {
54+
animation: none;
55+
opacity: 1;
56+
}
57+
}

0 commit comments

Comments
 (0)