pi-ext bugabingas pi extensions
owned by admin
README Source History Refs Compare Notes Search feat(decay): redesign compaction progress
01f499e17f286da7e09cceeeacad4df146bddbc8
Oliver Krylow <o.krylow@isp-insoft.de > · 9 Sep 2026
SSH signature · not checked
Browse files Compare with HEAD
Changed files (6) 6 6 - Shorten model labels consistently in model status displays, including family-specific speed and release qualifiers
7 7 - Remove the cmprss, Leaks, and Verboten extensions and the dedicated Leaks fuzz task
8 8 - Remove the always-on Terse extension; configure personal response style through Pi's `APPEND_SYSTEM.md` instead
9 - - Improve Decay progress with neutral pending history, a combined history and retained-tail row, readable labels, and continuous merge animation with atom and streamed-token counts
9 + - Redesign Decay progress as a borderless five-row widget with aligned CTX, FACTS, and NEW maps, theme-safe semantic blocks, live durable/context classification, selected-memory highlighting, and summary growth on a shared retained-token scale
10 10 - Fix Decay retained-token estimates to measure the actual preserved suffix instead of the configured target, and show unknown counts when unavailable
11 11 - Show Ultra workflow phases and live prompt tails while arguments stream, hand off to the execution board when agents start, and retain full received prompts on Ctrl+O
12 12 - Fix Ultra failed tool calls to show an error summary instead of an empty progress board, with full diagnostics on Ctrl+O
extensions/decay/README.md Modified 24 24 Repeated compactions provide the classifier a bounded prior-atom identity catalog so paraphrased facts can reuse exact recurrence keys without counting catalog entries as new occurrences.
26 - Interactive progress uses a passive fixed-height widget above Pi's editor, preserving native steering submission and Escape cancellation during compaction.
27 - History and the retained tail share one row, with contrasting labels over the block cells.
28 - Pending history is neutral; accepted records acquire source-age colors, and recurring keys are marked only after recurrence is observed across records.
29 - During merge, a looping summary blend indicates activity, not percentage complete.
30 - The widget reports the allocated atom count and an estimated output-token count driven by streamed summary text.
26 + Interactive progress uses a passive, borderless five-row widget above Pi's editor, preserving native steering submission and Escape cancellation during compaction.
27 + The aligned `CTX`, `FACTS`, and `NEW` maps use compact human-readable counts and reversed semantic colors so overlaid labels remain legible across themes.
28 + Classifier records replace muted pending cells with durable and context regions as they arrive.
29 + After reconciliation, selected canonical facts turn to the accent color before streamed summary cells grow at the start of `NEW`.
30 + `CTX` and `NEW` share a token scale, so the retained suffix keeps the same approximate width and follows the growing summary in the resulting context.
32 32 `keepRecentTokens` is Pi's configured target, not an exact count or minimum guarantee.
33 33 Pi chooses whole-entry boundaries, which can retain more or fewer tokens than the target.
36 36 `~` marks estimates; unavailable boundaries display `?`, never the configured target as a measured count.
38 38 The [original Decay plan](../../docs/super/plans/2026-08-22-decay-compaction.md) contains earlier visual artifacts.
39 - The current widget uses seven normal lines or four short-terminal lines; the single-row history and evidence-driven rendering replace that plan's eight-line design.
39 + The current widget uses five contiguous lines at every terminal height; aligned evidence-driven maps replace that plan's eight-line design.
extensions/decay/__tests__/integration.test.ts Modified 254 254 render (width: number): string[];
255 255 dispose
? ()
: void ;
256 - state : { mergeAtoms
: number ; summaryTokens
: number };
257 + candidates
: unknown [];
258 + selectedKeys
: string [];
259 + summaryTokens
: number ;
259 263 runner .
createContext = ()
=> ({
284 288 fg : (_color
: string , text
: string )
=> text,
285 289 bg : (_color
: string , text
: string )
=> text,
286 290 bold : (text
: string )
=> text,
291 + inverse : (text
: string )
=> text,
296 301 expect (result.compaction.
summary ).
toContain (
"Widget path" );
297 302 expect (widgetOptions).
toEqual ({ placement:
"aboveEditor" });
298 303 expect (widgetCleared).
toBe (
true );
299 - expect (rendered).
toHaveLength (
7 );
300 - expect (component?.state.mergeAtoms).
toBe (
1 );
304 + expect (rendered).
toHaveLength (
5 );
305 + expect (component?.state.candidates).
toHaveLength (
1 );
306 + expect (component?.state.selectedKeys).
toHaveLength (
1 );
301 307 expect (component?.state.summaryTokens).
toBeGreaterThan (
0 );
302 - expect (rendered.
join (
"\n" )).
toContain (
"DECAY.EXE" );
303 - expect (rendered.
join (
"\n" )).
toContain (
"Enter queues steer" );
308 + expect (rendered.
join (
"\n" )).
toContain (
"DECAY" );
309 + expect (rendered.
join (
"\n" )).
toContain (
"↵ queues a message" );
304 310 expect (custom).not.
toHaveBeenCalled ();
305 311 expect (setEditorText).not.
toHaveBeenCalled ();
306 312 expect (terminalWrite).not.
toHaveBeenCalled ();
extensions/decay/__tests__/ui.test.ts Modified 1 1 import { describe, expect, it, vi }
from "vitest" ;
2 + import type { MemoryAtom, RecordChunk }
from "../core" ;
4 5 type DecayDisplayState,
13 14 keptTokens :
24_000 ,
22 - const completedTransfers
: DecayDisplayState [
"transfers" ]
= Array .
from (
26 - kind: ([
"old" ,
"established" ,
"recent" ,
"newest" ]
as const )[
27 - Math .
floor (index
/ 2 )
29 - recurring: index
=== 5 ,
25 + atoms
: RecordChunk [
"atoms" ]
= [
26 + { key:
`fact-${chunk}` , text:
"fact" , kind:
"context" , status:
"active" },
30 + return { chunk, of, atoms };
35 + kind
: MemoryAtom [
"kind" ]
= "context" ,
36 + status
: MemoryAtom [
"status" ]
= "active" ,
35 - fg : (_color
: string , text
: string )
=> text,
51 + fg: vi.
fn ((_color
: string , text
: string )
=> text),
36 52 bg: vi.
fn ((_color
: string , text
: string )
=> text),
37 53 bold : (text
: string )
=> text,
54 + inverse: vi.
fn ((text
: string )
=> text),
40 - function component (displayState
= state ()) {
57 + function component (displayState
= state (),
now : ()
=> number = ()
=> 1_000 ) {
41 58 return new DecayComponent (
43 60 terminal: { rows:
30 },
70 + row
: ReturnType <
typeof renderDecayFrame>[
number ],
73 + return row.
filter ((cell)
=> cell.
style === style).
length ;
52 76 describe (
"Decay terminal rendering" , ()
=> {
63 - "keeps %ix%i frames bounded at %i lines across phases" ,
64 - (width, height, lines)
=> {
77 + it.
each ([
1 ,
12 ,
20 ,
40 ,
80 ,
120 ,
160 ])(
78 + "keeps five borderless rows bounded at width %i" ,
65 80 for (
const phase
of [
"classify" ,
"merge" ]
as const ) {
66 81 const frame
= plainFrame (
67 - renderDecayFrame (width, height,
state ({ phase }),
5_000 ),
82 + renderDecayFrame (width,
15 ,
state ({ phase }),
5_000 ),
69 - expect (frame).
toHaveLength (lines);
84 + expect (frame).
toHaveLength (
5 );
70 85 for (
const line
of frame)
expect ([
... line]).
toHaveLength (width);
72 - expect (frame.
join (
"\n" )).
toContain (
"DECAY" );
73 - expect (frame[
0 ]).
toContain (
74 - phase
=== "merge" ? "MERGE" : "CLASSIFY 0/8" ,
76 - expect (frame[
1 ]).
toContain (
"KEPT" );
86 + expect (frame.
join (
"\n" )).not.
toMatch (
/[╭╮╰╯┌┐└┘]/ );
82 - it (
"starts with neutral history, no inferred age or fake recurrence" , ()
=> {
83 - const frame
= renderDecayFrame (
80 ,
30 ,
state (),
2_000 );
84 - const separator
= frame[
1 ].
findIndex ((cell)
=> cell.char
=== "║" );
85 - const history
= frame[
1 ].
slice (
2 , separator);
86 - expect (history.
filter ((cell)
=> cell.char
=== "░" ).
length ).
toBeGreaterThan (
89 - expect (history.
every ((cell)
=> [
"dim" ,
"label" ].
includes (cell.
color ))).
toBe (
92 - expect (history.
some ((cell)
=> cell.
color === "recurring" )).
toBe (
false );
93 - expect (
plainFrame (frame)[
1 ]).
toContain (
"HISTORY ~94K" );
94 - expect (
plainFrame (frame)[
1 ]).
toContain (
"~24K KEPT" );
91 + it (
"uses human-readable counts and aligns every map origin" , ()
=> {
92 + const frame
= plainFrame (
renderDecayFrame (
120 ,
30 ,
state (),
2_000 ));
93 + expect (frame[
0 ]).
toContain (
"CLASSIFYING 0/8" );
94 + expect (frame[
1 ]).
toContain (
"CTX 118k │" );
95 + expect (frame[
2 ]).
toContain (
"FACTS 0 │" );
96 + expect (frame[
3 ]).
toContain (
"NEW ? │" );
97 + expect (frame.
slice (
1 ,
4 ).
map ((line)
=> line.
indexOf (
"│" ))).
toEqual ([
97 - it (
"vacates source-order history and lands only completed records, preserving the tail" , ()
=> {
98 - const initial
= renderDecayFrame (
80 ,
30 ,
state (),
2_000 );
99 - const completed
= renderDecayFrame (
102 + it (
"uses one continuous style under each CTX label and block" , ()
=> {
103 + const frame
= renderDecayFrame (
113 ,
30 ,
state (),
2_000 );
104 + const row
= frame[
1 ].
slice (
13 );
105 + const sourceLabel
= plainFrame (frame)[
1 ].
indexOf (
"~94k SUMMARIZE" );
106 + const keepLabel
= plainFrame (frame)[
1 ].
indexOf (
"~24k KEEP" );
107 + expect (sourceLabel).
toBeGreaterThanOrEqual (
13 );
108 + expect (keepLabel).
toBeGreaterThan (sourceLabel);
109 + expect (frame[
1 ][sourceLabel]?.
style ).
toBe (
"sourceBlock" );
110 + expect (frame[
1 ][keepLabel]?.
style ).
toBe (
"keepBlock" );
111 + expect (row.
every ((cell)
=> cell.
style !== "text" )).
toBe (
true );
114 + it (
"replaces pending blocks from an out-of-order completed chunk" , ()
=> {
115 + const frame
= renderDecayFrame (
102 - state ({ transfers: completedTransfers }),
118 + state ({ records: [
record (
8 )] }),
105 - const separator
= initial[
1 ].
findIndex ((cell)
=> cell.char
=== "║" );
121 + expect (
plainFrame (frame)[
0 ]).
toContain (
"CLASSIFYING 1/8" );
122 + expect (
countStyle (frame[
2 ],
"contextBlock" )).
toBeGreaterThan (
0 );
123 + expect (
countStyle (frame[
2 ],
"pendingBlock" )).
toBeGreaterThan (
0 );
107 - completed[
1 ].
slice (
2 , separator).
some ((cell)
=> cell.char
=== "░" ),
109 - expect (completed[
1 ].
slice (separator)).
toEqual (initial[
1 ].
slice (separator));
110 - expect (completed[
3 ].
filter ((cell)
=> cell.
color === "recurring" )).
toEqual ([
111 - { char:
"◆" , color:
"recurring" },
113 - expect (
plainFrame (completed)[
3 ]).
toContain (
"SUMMARY" );
126 + .
filter ((cell)
=> cell.
style === "pendingBlock" )
127 + .
every ((cell)
=> cell.char
=== "░" ),
116 - it (
"shows every in-flight record, not only the newest transfer" , ()
=> {
131 + it (
"classifies only context as context and all other kinds as durable" , ()
=> {
141 + const frame
= renderDecayFrame (
149 + kinds.
map ((kind)
=> ({
161 + expect (
plainFrame (frame)[
2 ]).
toContain (
"6 DURABLE" );
162 + expect (
plainFrame (frame)[
2 ]).
toContain (
"1 CONTEXT" );
165 + it (
"highlights selected canonical atoms by normalized key" , ()
=> {
166 + const candidates
= [
167 + atom (
" Keep Me " ,
"decision" ),
168 + atom (
"drop" ,
"context" ),
117 170 const frame
= renderDecayFrame (
122 - {
... completedTransfers[
0 ], acceptedAt:
1_000 },
123 - {
... completedTransfers[
1 ], acceptedAt:
1_200 },
175 + mergeStartedAt:
1_000 ,
177 + selectedKeys: [
"keep me" ],
128 - expect (frame[
2 ].
filter ((cell)
=> /[▖▘▝▗]/ .
test (cell.char))).
toHaveLength (
2 );
181 + expect (
countStyle (frame[
2 ],
"selectedBlock" )).
toBeGreaterThan (
0 );
182 + expect (
countStyle (frame[
2 ],
"contextBlock" )).
toBeGreaterThan (
0 );
183 + expect (
plainFrame (frame)[
2 ]).
toContain (
"DURABLE" );
132 - "keeps summary blending animated long after the last transfer at height %i" ,
134 - const display
= state ({
186 + it (
"uses one token scale and places KEEP directly after streamed summary" , ()
=> {
187 + const initial
= renderDecayFrame (
191 + inputTokens:
100_000 ,
192 + keptTokens:
20_000 ,
136 - transfers: completedTransfers,
138 - summaryTokens:
1_200 ,
140 - const summaryRow
= height
< 24 ? 2 : 3 ;
141 - const first
= renderDecayFrame (
80 , height, display,
20_000 );
142 - const second
= renderDecayFrame (
80 , height, display,
20_110 );
143 - expect (second[summaryRow]).not.
toEqual (first[summaryRow]);
144 - expect (second[
1 ]).
toEqual (first[
1 ]);
145 - expect (
plainFrame (second).
join (
"\n" )).not.
toContain (
"%" );
146 - if (height
>= 24 ) {
147 - expect (
plainFrame (second)[
2 ]).
toContain (
"72 atoms" );
148 - expect (
plainFrame (second)[
2 ]).
toContain (
"tokens emitted" );
194 + mergeStartedAt:
1_000 ,
195 + summaryTokens:
1_000 ,
199 + const grown
= renderDecayFrame (
203 + inputTokens:
100_000 ,
204 + keptTokens:
20_000 ,
206 + mergeStartedAt:
1_000 ,
207 + summaryTokens:
4_000 ,
211 + expect (
countStyle (initial[
1 ],
"keepBlock" )).
toBe (
20 );
212 + expect (
countStyle (initial[
3 ],
"keepBlock" )).
toBe (
20 );
213 + expect (
countStyle (initial[
3 ],
"selectedBlock" )).
toBe (
1 );
214 + expect (
countStyle (grown[
3 ],
"selectedBlock" )).
toBe (
4 );
215 + const firstKeep
= initial[
3 ].
findIndex (
216 + (cell)
=> cell.
style === "keepBlock" ,
218 + expect (firstKeep).
toBe (
14 );
219 + expect (
plainFrame (initial)[
3 ]).
toContain (
"NEW ~21k" );
220 + expect (
plainFrame (grown)[
3 ]).
toContain (
"NEW ~24k" );
153 - it (
"does not label an unknown retained count as the configured 20k target" , ()
=> {
223 + it (
"never substitutes the configured target for unknown retained tokens" , ()
=> {
154 224 const frame
= plainFrame (
155 225 renderDecayFrame (
80 ,
30 ,
state ({ keptTokens:
undefined }),
2_000 ),
157 - expect (frame[
1 ]).
toContain (
"? KEPT" );
158 - expect (frame[
1 ]).not.
toContain (
"20K" );
227 + expect (frame[
1 ]).not.
toContain (
"24k KEEP" );
228 + expect (frame[
3 ]).
toContain (
"NEW ?" );
161 - it (
"overlays readable labels on block rows and remains passive" , ()
=> {
162 - const widget
= component ();
231 + it (
"uses inverse semantic colors instead of selectedBg" , ()
=> {
232 + theme.fg.
mockClear ();
233 + theme.bg.
mockClear ();
234 + theme.inverse.
mockClear ();
235 + const widget
= component (
239 + candidates: [
atom (
"one" ,
"decision" )],
240 + selectedKeys: [
"one" ],
241 + summaryTokens:
100 ,
164 245 expect (
"handleInput" in widget).
toBe (
false );
165 - expect (widget.
render (
80 )).
toHaveLength (
7 );
166 - expect (theme.bg).
toHaveBeenCalledWith (
168 - expect.
stringContaining (
"HISTORY" ),
246 + expect (widget.
render (
80 )).
toHaveLength (
5 );
247 + expect (theme.inverse).
toHaveBeenCalled ();
248 + expect (theme.fg).
toHaveBeenCalledWith (
"accent" , expect.
any (
String ));
249 + expect (theme.fg).
toHaveBeenCalledWith (
"mdLink" , expect.
any (
String ));
250 + expect (theme.bg).not.
toHaveBeenCalled ();
171 252 widget.
dispose ();
175 - it (
"counts recurrence across records, not duplicate keys in one record" , ()
=> {
256 + it (
"deduplicates records and ignores records outside the display run" , ()
=> {
176 257 const widget
= component ();
180 - kind:
"context" as const ,
181 - status:
"active" as const ,
184 - widget.
record ({ chunk:
1 , of:
8 , atoms: [atom, atom] });
185 - widget.
record ({ chunk:
2 , of:
8 , atoms: [{
... atom, key:
"same key" }] });
187 - widget.state.transfers.
map ((transfer)
=> transfer.recurring),
188 - ).
toEqual ([
false ,
true ]);
259 + widget.
record (
record (
1 ));
260 + widget.
record (
record (
1 , []));
261 + widget.
record (
record (
9 ));
262 + widget.
record (
record (
2 , [],
9 ));
263 + expect (widget.state.records).
toEqual ([{ chunk:
1 , of:
8 , atoms: [] }]);
269 + it (
"requests immediate renders for merge and summary stream updates" , ()
=> {
270 + const requestRender
= vi.
fn ();
271 + const widget
= new DecayComponent (
272 + { terminal: { rows:
30 }, requestRender }
as never ,
278 + widget.
merge ([
atom (
"one" ,
"decision" )], [
atom (
"one" ,
"decision" )]);
279 + widget.
setSummary (
12 );
280 + expect (requestRender).
toHaveBeenCalledTimes (
2 );
281 + expect (widget.state.summaryTokens).
toBe (
12 );
282 + expect (widget.state.selectedKeys).
toEqual ([
"one" ]);
190 284 widget.
dispose ();
extensions/decay/index.ts Modified 59 59 interface RunCallbacks {
60 60 onRecord (record
: RecordChunk )
: void ;
61 - onMerge (atomCount
: number )
: void ;
61 + onMerge (atoms
: readonly MemoryAtom [], selected
: readonly MemoryAtom [])
: void ;
62 62 onSummary ? (tokens
: number )
: void ;
230 230 keptTokens :
estimateKeptTokens (
event ),
231 231 totalChunks :
previewChunkCount (
event ),
232 232 phase :
"classify" ,
234 234 startedAt :
Date .
now (),
254 254 onRecord : (record)
=> component?.
record (record),
255 - onMerge : (atomCount)
=> {
256 - state.mergeAtoms
= atomCount;
255 + onMerge : (atoms, selectedAtoms)
=> {
257 256 state.model
= `${summarizerModel.provider}/${summarizerModel. id }` ;
258 - component?.
setPhase (
"merge" );
260 - onSummary : (tokens)
=> {
261 - state.summaryTokens
= tokens;
257 + component?.
merge (atoms, selectedAtoms);
259 + onSummary : (tokens)
=> component?.
setSummary (tokens),
265 262 return { type:
"success" , result };
328 325 event .preparation.settings.reserveTokens,
330 327 const allocated
= allocateAtoms (atoms, outputBudget);
331 - callbacks.
onMerge (allocated.
length );
328 + callbacks.
onMerge (atoms, allocated);
332 329 stage
= "summarizer" ;
333 330 const auth
= await ctx.modelRegistry.
getApiKeyAndHeaders (summarizerModel);
extensions/decay/ui.ts Modified 1 1 import type { Theme }
from "@earendil-works/pi-coding-agent" ;
2 2 import type { Component, TUI }
from "@earendil-works/pi-tui" ;
3 - import type { RecordChunk }
from "./core.js" ;
3 + import { isProtectedKind, type MemoryAtom, type RecordChunk }
from "./core.js" ;
6 - const TRANSFER_MS
= 660 ;
7 - const NORMAL_HEIGHT
= 7 ;
8 - const SHORT_HEIGHT
= 4 ;
9 - const SPIN
= [
"▖" ,
"▘" ,
"▝" ,
"▗" ]
as const ;
8 + const SELECTION_MS
= 660 ;
9 + const SPIN
= [
"◉" ,
"◍" ,
"◎" ,
"◌" ]
as const ;
10 + const SUMMARY_HEAD
= [
" " ,
"░" ,
"▒" ,
"▓" ,
"▒" ,
"░" ]
as const ;
11 - type Recency = "old" | "established" | "recent" | "newest" ;
12 - type CellColor = Recency | "recurring" | "title" | "text" | "dim" | "label" ;
19 - export interface DisplayTransfer {
30 + export interface DisplayRecord {
33 + atoms
: RecordChunk [
"atoms" ];
26 36 export interface DecayDisplayState {
29 39 keptTokens : number
| undefined ;
30 40 totalChunks : number;
31 41 phase :
"classify" | "merge" ;
32 - transfers : DisplayTransfer[];
42 + records : DisplayRecord[];
34 - mergeAtoms
?: number;
44 + mergeStartedAt
?: number;
45 + candidates
?: MemoryAtom[];
46 + selectedKeys
?: string[];
35 47 summaryTokens
?: number;
38 50 export class DecayComponent implements Component {
39 - private readonly seenKeys
= new Set <
string >();
40 51 private readonly timer
: ReturnType <
typeof setInterval>;
41 52 private disposed
= false ;
53 64 record (record: RecordChunk):
void {
54 - const keys
= new Set (
55 - record.atoms.
map ((atom)
=> 56 - atom.key.
trim ().
toLowerCase ().
replace (
/\s + / g ,
" " ),
59 - const recurring
= [
... keys].
some ((key)
=> this.seenKeys.
has (key));
60 - for (
const key
of keys) this.seenKeys.
add (key);
61 - this.state.transfers.
push ({
66 + record.of
!== this.state.totalChunks
|| 68 + record.chunk
> this.state.totalChunks
71 + const displayRecord
: DisplayRecord = {
62 72 chunk: record.chunk,
63 - kind:
recencyFor (record.chunk, record.of),
65 - acceptedAt: this.
now (),
74 + atoms: record.atoms,
76 + const index
= this.state.records.
findIndex (
77 + (existing)
=> existing.chunk
=== record.chunk,
79 + if (index
>= 0 ) this.state.records[index]
= displayRecord;
80 + else this.state.records.
push (displayRecord);
81 + this.state.records.
sort ((left, right)
=> left.chunk
- right.chunk);
67 82 this.tui.
requestRender ();
70 - setPhase (phase: DecayDisplayState[
"phase" ]):
void {
71 - this.state.phase
= phase;
86 + candidates: readonly MemoryAtom[],
87 + selected: readonly MemoryAtom[],
89 + this.state.phase
= "merge" ;
90 + this.state.mergeStartedAt
= this.
now ();
91 + this.state.candidates
= candidates.
map ((atom)
=> ({
... atom }));
92 + this.state.selectedKeys
= selected.
map ((atom)
=> normalizeKey (atom.key));
93 + this.tui.
requestRender ();
96 + setSummary (tokens: number):
void {
97 + this.state.summaryTokens
= Math .
max (
0 , tokens);
72 98 this.tui.
requestRender ();
93 119 export function renderDecayFrame (
94 120 viewportWidth
: number ,
95 - viewportHeight
: number ,
121 + _viewportHeight
: number ,
96 122 state
: DecayDisplayState ,
99 125 const width
= Math .
max (
1 , viewportWidth);
100 - const height
= viewportHeight
< 24 ? SHORT_HEIGHT
: NORMAL_HEIGHT;
101 - const canvas
= blankCanvas (width, height);
126 + const canvas
= blankCanvas (width, HEIGHT);
102 127 const elapsedMs
= Math .
max (
0 , now
- state.startedAt);
103 128 const frame
= Math .
floor (elapsedMs
/ FRAME_MS);
104 - const short
= height
=== SHORT_HEIGHT;
129 + const completedChunks
= completedChunkCount (state);
130 + const selectionProgress
= 131 + state.phase
=== "merge" 134 + Math .
max (
0 , now
- (state.mergeStartedAt
?? now))
/ SELECTION_MS,
106 138 state.phase
=== "classify" 107 - ? `CLASSIFY ${state.transfers. length }/${state.totalChunks}` 109 - const header
= `${short ? "DECAY" : "DECAY.EXE"} ${SPIN[frame % SPIN. length ]} · ${phase} · ${(elapsedMs / 1_000). toFixed (1)}s · ${ modelLabel (state.model)}` ;
110 - put (canvas,
0 ,
0 ,
"─" .
repeat (width),
"dim" );
111 - put (canvas,
2 ,
0 , header.
slice (
0 ,
Math .
max (
0 , width
- 4 )),
"title" );
112 - renderHistory (canvas, state);
114 - const controls
= width
>= 48 ? " ↵ queue · Esc cancel" : " ↵ queue" ;
115 - renderSummary (canvas,
2 , width
- controls.
length - 2 , state, now);
116 - put (canvas, width
- controls.
length - 1 ,
2 , controls,
"dim" );
118 - renderTransfer (canvas,
2 , state, now);
119 - renderSummary (canvas,
3 , width
- 2 , state, now);
120 - renderLegend (canvas,
4 );
121 - const controls
= "Enter queues steer · Esc cancels" ;
122 - const leftWidth
= Math .
max (
0 , width
- controls.
length - 5 );
127 - `INPUT ${state.inputTokens. toLocaleString ("en-US")}` .
slice (
0 , leftWidth),
130 - put (canvas,
Math .
max (
2 , width
- controls.
length - 2 ),
5 , controls,
"dim" );
133 - for (
let y
= 1 ; y
< height
- 1 ; y
++ ) {
134 - put (canvas,
0 , y,
"│" ,
"dim" );
135 - put (canvas, width
- 1 , y,
"│" ,
"dim" );
137 - for (
let x
= 0 ; x
< width; x
++ ) {
138 - put (canvas, x, height
- 1 ,
"─" ,
"dim" );
140 - put (canvas,
0 ,
0 ,
"╭" ,
"dim" );
141 - put (canvas, width
- 1 ,
0 ,
"╮" ,
"dim" );
142 - put (canvas,
0 , height
- 1 ,
"╰" ,
"dim" );
143 - put (canvas, width
- 1 , height
- 1 ,
"╯" ,
"dim" );
139 + ? `CLASSIFYING ${completedChunks}/${state.totalChunks}` 140 + : selectionProgress
< 1 && state.summaryTokens
=== undefined 141 + ? "SELECTING MEMORY" 142 + : "WRITING SUMMARY" ;
144 + putFragments (canvas,
0 ,
0 , [
145 + [
"▣" ,
"sourceText" ],
146 + [
" DECAY " ,
"title" ],
148 + [SPIN[frame
% SPIN.
length ],
"sourceText" ],
149 + [
` ${phase}` ,
"title" ],
151 + ` · ${ Math . floor (elapsedMs / 1_000)}s · ${ modelLabel (state.model)}` ,
156 + renderContext (canvas, state);
157 + renderFacts (canvas, state, selectionProgress);
158 + renderNewContext (canvas, state, frame, completedChunks, selectionProgress);
159 + put (canvas,
0 ,
4 ,
"↵ queues a message · Esc cancels" ,
"dim" );
147 - function renderHistory (canvas
: Cell [][], state
: DecayDisplayState )
: void {
148 - const width
= canvas[
0 ].
length ;
149 - const tailWidth
= Math .
min (
150 - Math .
max (
12 ,
Math .
round (width
* 0.25 )),
151 - Math .
max (
0 , width
- 6 ),
153 - const separator
= width
- tailWidth
- 3 ;
154 - const historyStart
= 2 ;
155 - const historyEnd
= Math .
max (historyStart, separator
- 1 );
156 - const capacity
= historyEnd
- historyStart;
157 - const accepted
= new Set (state.transfers.
map ((transfer)
=> transfer.chunk));
158 - for (
let x
= historyStart; x
< historyEnd; x
++ ) {
162 - ((x
- historyStart)
* state.totalChunks)
/ Math .
max (
1 , capacity),
164 - const last
= Math .
max (
167 - ((x
- historyStart
+ 1 )
* state.totalChunks)
/ Math .
max (
1 , capacity),
170 - let complete
= state.totalChunks
> 0 ;
171 - for (
let chunk
= first; chunk
<= last; chunk
++ )
172 - complete
&&= accepted.
has (chunk);
173 - put (canvas, x,
1 , complete
? " " : "░" ,
"dim" );
163 + function renderContext (canvas
: Cell [][], state
: DecayDisplayState )
: void {
164 + const capacity
= Math .
max (
0 , canvas[
0 ].
length - MAP_START);
165 + renderMapPrefix (canvas,
1 ,
"CTX" ,
compactTokens (state.inputTokens));
166 + if (capacity
=== 0 )
return ;
167 + const kept
= state.keptTokens;
168 + if (kept
=== undefined || kept
< 0 || kept
> state.inputTokens) {
169 + fillBlock (canvas, MAP_START,
1 , capacity,
"sourceBlock" , [
170 + ` ${ compactTokens (state.inputTokens)} CTX ` ,
175 - put (canvas, separator,
1 ,
"║" ,
"dim" );
176 - for (
let x
= separator
+ 2 ; x
< width
- 2 ; x
++ )
177 - put (canvas, x,
1 ,
"▓" ,
"recent" );
179 - state.keptTokens
=== undefined 181 - : compactTokens (
Math .
max (
0 , state.inputTokens
- state.keptTokens));
186 - ` HISTORY ${history} ` .
slice (
0 , capacity),
193 - ` ${ compactTokens (state.keptTokens)} KEPT ` .
slice (
0 , tailWidth
- 1 ),
175 + const summary
= state.summaryTokens
?? 0 ;
176 + const scale
= Math .
max (
1 , state.inputTokens, kept
+ summary);
177 + const keepWidth
= scaledWidth (kept, scale, capacity);
178 + const summarized
= Math .
max (
0 , state.inputTokens
- kept);
179 + const sourceWidth
= 180 + state.inputTokens
=== scale
181 + ? Math .
max (
0 , capacity
- keepWidth)
183 + capacity
- keepWidth,
184 + scaledWidth (summarized, scale, capacity),
186 + fillBlock (canvas, MAP_START,
1 , sourceWidth,
"sourceBlock" , [
187 + ` ~${ compactTokens (summarized)} ${state.phase === "merge" ? "SUMMARIZED" : "SUMMARIZE"} ` ,
188 + state.phase
=== "merge" ? " SUMMARIZED " : " SUMMARIZE " ,
191 + fillBlock (canvas, MAP_START
+ sourceWidth,
1 , keepWidth,
"keepBlock" , [
192 + ` ~${ compactTokens (kept)} KEEP ` ,
198 - function renderTransfer (
198 + function renderFacts (
199 199 canvas
: Cell [][],
201 200 state
: DecayDisplayState ,
201 + selectionProgress
: number ,
204 - const end
= canvas[
0 ].
length - 3 ;
205 - if (state.phase
=== "merge" ) {
206 - const output
= state.summaryTokens
207 - ? `${ compactTokens (state.summaryTokens)} tokens emitted` 208 - : "awaiting summary text" ;
203 + const capacity
= Math .
max (
0 , canvas[
0 ].
length - MAP_START);
204 + const records
= uniqueRecords (state.records);
205 + const observed
= records.
flatMap ((record)
=> record.atoms);
207 + state.phase
=== "merge" ? (state.candidates
?? [])
: observed;
208 + renderMapPrefix (canvas,
2 ,
"FACTS" ,
compactCount (candidates.
length ));
209 + if (capacity
=== 0 )
return ;
211 + if (state.phase
=== "classify" ) {
212 + const completed
= records.
length ;
213 + let completeWidth
= 214 + state.totalChunks
> 0 215 + ? Math .
round ((completed
/ state.totalChunks)
* capacity)
217 + if (completed
> 0 ) completeWidth
= Math .
max (
1 , completeWidth);
218 + if (completed
< state.totalChunks
&& capacity
> 1 )
219 + completeWidth
= Math .
min (capacity
- 1 , completeWidth);
220 + completeWidth
= Math .
min (capacity, completeWidth);
221 + renderClassifiedGroups (canvas,
2 , observed, completeWidth,
undefined ,
0 );
224 + MAP_START
+ completeWidth,
213 - `MERGING ${state.mergeAtoms ?? 0} atoms → summary · ${output}` ,
226 + capacity
- completeWidth,
218 - for (
let x
= 2 ; x
< end; x
++ )
put (canvas, x, y,
"·" ,
"dim" );
219 - put (canvas, end, y,
"▶" ,
"recent" );
220 - const frame
= Math .
floor (
Math .
max (
0 , now
- state.startedAt)
/ FRAME_MS);
221 - for (
const transfer
of state.transfers) {
222 - const progress
= Math .
max (
0 , (now
- transfer.acceptedAt)
/ TRANSFER_MS);
223 - if (progress
>= 1 )
continue ;
224 - const x
= Math .
round (
2 + (end
- 2 )
* progress);
229 - SPIN[frame
% SPIN.
length ],
230 - transfer.recurring
? "recurring" : transfer.kind,
233 - put (canvas,
2 , y,
" TRANSFER " ,
"label" );
234 + const selected
= new Set (state.selectedKeys
?? []);
235 + renderClassifiedGroups (
236 - function renderSummary (
245 + function renderClassifiedGroups (
237 246 canvas
: Cell [][],
240 - state
: DecayDisplayState ,
248 + atoms
: readonly Pick <
MemoryAtom ,
"key" | "kind" >[],
250 + selectedKeys
: ReadonlySet <
string >
| undefined ,
251 + selectionProgress
: number ,
244 - const capacity
= Math .
max (
0 , end
- start);
245 - for (
let x
= start; x
< end; x
++ )
put (canvas, x, y,
"·" ,
"dim" );
246 - for (
const transfer
of state.transfers) {
247 - if (state.phase
!== "merge" && now
- transfer.acceptedAt
< TRANSFER_MS)
252 - ((transfer.chunk
- 1 )
/ Math .
max (
1 , state.totalChunks))
* capacity,
253 + if (width
<= 0 )
return ;
254 + const durable
= atoms.
filter ((atom)
=> isProtectedKind (atom.kind));
255 + const context
= atoms.
filter ((atom)
=> ! isProtectedKind (atom.kind));
256 + if (atoms.
length === 0 ) {
257 + fillBlock (canvas, MAP_START, y, width,
"completeBlock" , []);
260 + const durableWidth
= partitionWidth (durable.
length , atoms.
length , width);
261 + const contextWidth
= width
- durableWidth;
269 + [
` ◆ ${durable. length } DURABLE ` ,
` ${durable. length } DUR ` ,
" ◆ " ],
275 + MAP_START
+ durableWidth,
280 + [
` ◇ ${context. length } CONTEXT ` ,
` ${context. length } CTX ` ,
" ◇ " ],
286 + function renderAtomGroup (
291 + atoms
: readonly Pick <
MemoryAtom ,
"key" >[],
292 + baseStyle
: CellStyle ,
293 + labels
: readonly string [],
294 + selectedKeys
: ReadonlySet <
string >
| undefined ,
295 + selectionProgress
: number ,
297 + if (width
<= 0 )
return ;
298 + for (
let offset
= 0 ; offset
< width; offset
++ ) {
303 + Math .
floor ((offset
* atoms.
length )
/ Math .
max (
1 , width)),
306 + const selected
= atom
&& selectedKeys?.
has (
normalizeKey (atom.key));
307 + const revealed
= hashFraction (offset, x)
<= selectionProgress;
258 - transfer.recurring
? "◆" : historyGlyph (transfer.kind),
259 - transfer.recurring
? "recurring" : transfer.kind,
313 + selected
&& revealed
? "selectedBlock" : baseStyle,
262 - const short
= canvas.
length === SHORT_HEIGHT;
263 - const label
= short
265 - : state.phase
=== "merge" 266 - ? " SUMMARY · blending " 268 - const blendStart
= start
+ label.
length ;
269 - const blendWidth
= end
- blendStart;
270 - if (state.phase
=== "merge" && blendWidth
> 0 ) {
272 - const frame
= Math .
floor (
Math .
max (
0 , now
- state.startedAt)
/ 110 );
273 - for (
let offset
= 0 ; offset
< Math .
min (
5 , blendWidth); offset
++ ) {
276 - blendStart
+ ((frame
+ offset)
% blendWidth),
278 - [
"░" ,
"▒" ,
"▓" ,
"▒" ,
"░" ][offset],
316 + const label
= fittingLabel (width, labels);
317 + if (label)
putPreservingStyle (canvas, x, y, label);
320 + function renderNewContext (
322 + state
: DecayDisplayState ,
324 + completedChunks
: number ,
325 + selectionProgress
: number ,
327 + const capacity
= Math .
max (
0 , canvas[
0 ].
length - MAP_START);
328 + const summary
= state.summaryTokens;
329 + const kept
= state.keptTokens;
330 + const known
= summary
!== undefined && summary
> 0 && kept
!== undefined ;
335 + known
? `~${ compactTokens (summary + kept)}` : "?" ,
337 + if (capacity
=== 0 )
return ;
340 + state.phase
=== "classify" 341 + ? `○ waiting for ${ Math . max (0, state.totalChunks - completedChunks)} chunks` 342 + : selectionProgress
< 1 343 + ? "○ selecting facts" 344 + : "○ waiting for summary" ;
345 + put (canvas, MAP_START,
3 , waiting,
"dim" );
283 - put (canvas, start, y, label.
slice (
0 , capacity),
"label" );
348 + if (kept
< 0 || kept
> state.inputTokens) {
349 + put (canvas, MAP_START,
3 ,
"○ retained size unavailable" ,
"dim" );
352 + const scale
= Math .
max (
1 , state.inputTokens, kept
+ summary);
353 + const summaryWidth
= scaledWidth (summary, scale, capacity);
354 + const keepWidth
= Math .
min (
355 + capacity
- summaryWidth,
356 + scaledWidth (kept, scale, capacity),
358 + fillBlock (canvas, MAP_START,
3 , summaryWidth,
"selectedBlock" , []);
359 + if (summaryWidth
> 0 )
362 + MAP_START
+ summaryWidth
- 1 ,
364 + SUMMARY_HEAD[frame
% SUMMARY_HEAD.
length ],
367 + fillBlock (canvas, MAP_START
+ summaryWidth,
3 , keepWidth,
"keepBlock" , [
368 + ` ~${ compactTokens (kept)} KEEP ` ,
286 - function renderLegend (canvas
: Cell [][], y
: number )
: void {
287 - const width
= canvas[
0 ].
length ;
290 - ? "░ pending · age: old → new · ◆ repeat" 291 - : "░ pending · colors: source age, old → new · ◆ recurring" ;
292 - put (canvas,
2 , y, legend,
"dim" );
293 - const index
= legend.
indexOf (
"◆" );
294 - put (canvas,
2 + index, y,
"◆" ,
"recurring" );
374 + function renderMapPrefix (
380 + put (canvas,
0 , y, label.
slice (
0 ,
6 ).
padEnd (
6 ),
"text" );
381 + put (canvas,
6 , y, value.
slice (
- 5 ).
padStart (
5 ),
"title" );
382 + put (canvas,
11 , y,
" │" ,
"dim" );
297 - function recencyFor (chunk
: number , total
: number )
: Recency {
298 - const ratio
= chunk
/ Math .
max (
1 , total);
299 - if (ratio
<= 0.25 )
return "old" ;
300 - if (ratio
<= 0.5 )
return "established" ;
301 - if (ratio
<= 0.75 )
return "recent" ;
391 + labels
: readonly string [],
394 + for (
let offset
= 0 ; offset
< width; offset
++ )
395 + put (canvas, x
+ offset, y, fill, style);
396 + const label
= fittingLabel (width, labels);
397 + if (label)
put (canvas, x, y, label, style);
400 + function fittingLabel (width
: number , labels
: readonly string [])
: string {
401 + return labels.
find ((label)
=> label.
length <= width)
?? "" ;
404 + function partitionWidth (part
: number , total
: number , width
: number )
: number {
405 + if (part
<= 0 )
return 0 ;
406 + if (part
>= total)
return width;
407 + if (width
<= 1 )
return Math .
round (part
/ total);
408 + return Math .
min (width
- 1 ,
Math .
max (
1 ,
Math .
round ((part
/ total)
* width)));
411 + function scaledWidth (value
: number , scale
: number , capacity
: number )
: number {
412 + if (value
<= 0 || capacity
<= 0 )
return 0 ;
415 + Math .
max (
1 ,
Math .
round ((value
/ Math .
max (
1 , scale))
* capacity)),
419 + function completedChunkCount (state
: DecayDisplayState )
: number {
420 + return uniqueRecords (state.records).
length ;
423 + function uniqueRecords (records
: readonly DisplayRecord [])
: DisplayRecord [] {
424 + const unique
= new Map <
number ,
DisplayRecord >();
425 + for (
const record
of records) unique.
set (record.chunk, record);
426 + return [
... unique.
values ()].
sort ((left, right)
=> left.chunk
- right.chunk);
429 + function hashFraction (index
: number , salt
: number )
: number {
430 + return ((index
* 37 + salt
* 17 )
% 101 )
/ 100 ;
433 + function normalizeKey (key
: string )
: string {
434 + return key.
trim ().
toLowerCase ().
replace (
/\s + / g ,
" " );
305 437 function blankCanvas (width
: number , height
: number )
: Cell [][] {
306 438 return Array .
from ({ length: height }, ()
=> 307 - Array .
from ({ length: width }, ()
=> ({ char:
" " , color:
"dim" })),
439 + Array .
from ({ length: width }, ()
=> ({ char:
" " , style:
"dim" })),
443 + function putFragments (
447 + parts
: readonly (
readonly [
string ,
CellStyle ])[],
450 + for (
const [text, style]
of parts) {
451 + put (canvas, column, y, text, style);
452 + column
+= [
... text].
length ;
312 457 canvas
: Cell [][],
318 463 if (y
< 0 || y
>= canvas.
length )
return ;
320 465 for (
const char
of text) {
321 466 if (column
>= 0 && column
< canvas[y].
length )
322 - canvas[y][column]
= { char, color };
467 + canvas[y][column]
= { char, style };
327 - function historyGlyph (kind
: Recency )
: string {
328 - return { old:
"░" , established:
"▒" , recent:
"▓" , newest:
"█" }[kind];
472 + function putPreservingStyle (
478 + if (y
< 0 || y
>= canvas.
length )
return ;
480 + for (
const char
of text) {
481 + if (column
>= 0 && column
< canvas[y].
length ) canvas[y][column].char
= char;
331 486 function modelLabel (reference
: string )
: string {
333 488 return separator
>= 0 ? reference.
slice (separator
+ 1 )
: reference;
336 - function compactTokens (tokens
: number | undefined )
: string {
337 - if (tokens
=== undefined )
return "?" ;
338 - return tokens
>= 1_000 ? `~${ Math . round (tokens / 1_000)}K` : `~${tokens}` ;
491 + function compactTokens (tokens
: number )
: string {
492 + const value
= Math .
max (
0 , tokens);
493 + if (value
>= 1_000_000 ) {
494 + const millions
= value
/ 1_000_000 ;
495 + return `${millions >= 10 ? Math . round (millions) : millions. toFixed (1). replace (/\.0 $ /, "")}m` ;
497 + if (value
>= 1_000 ) {
498 + const thousands
= value
/ 1_000 ;
499 + return `${thousands >= 10 ? Math . round (thousands) : thousands. toFixed (1). replace (/\.0 $ /, "")}k` ;
501 + return Math .
round (value).
toLocaleString (
"en-US" );
504 + function compactCount (value
: number )
: string {
505 + return value
>= 1_000 ? compactTokens (value)
: value.
toLocaleString (
"en-US" );
341 508 function styleFrame (frame
: Cell [][], theme
: Theme )
: string [] {
342 - const color = (name
: CellColor , text
: string )
: string => {
509 + const style = (name
: CellStyle , text
: string )
: string => {
345 - return theme.
bold (theme.
fg (
"success" , text));
347 - return theme.
bg (
"selectedBg" , theme.
bold (theme.
fg (
"text" , text)));
512 + return theme.
bold (theme.
fg (
"text" , text));
350 514 return theme.
fg (
"text" , text);
352 - return theme.
fg (
"warning" , text);
354 516 return theme.
fg (
"success" , text);
355 - case "established" :
356 - return theme.
fg (
"borderAccent" , text);
358 - return theme.
fg (
"muted" , text);
517 + case "sourceBlock" :
518 + return theme.
inverse (theme.
fg (
"success" , text));
519 + case "selectedBlock" :
520 + return theme.
inverse (theme.
fg (
"accent" , text));
522 + return theme.
inverse (theme.
fg (
"mdLink" , text));
523 + case "durableBlock" :
524 + return theme.
inverse (theme.
fg (
"warning" , text));
525 + case "contextBlock" :
526 + return theme.
inverse (theme.
fg (
"borderAccent" , text));
527 + case "pendingBlock" :
528 + return theme.
inverse (theme.
fg (
"muted" , text));
529 + case "completeBlock" :
530 + return theme.
inverse (theme.
fg (
"border" , text));
360 532 return theme.
fg (
"dim" , text);
363 535 return frame.
map ((row)
=> {
365 - let active
= row[
0 ]?.
color ?? "dim" ;
537 + let active
= row[
0 ]?.
style ?? "dim" ;
367 539 for (
const cell
of row) {
368 - if (cell.
color !== active) {
369 - result
+= color (active, text);
370 - active
= cell.
color ;
540 + if (cell.
style !== active) {
541 + result
+= style (active, text);
542 + active
= cell.
style ;
373 545 text
+= cell.char;
375 - return result
+ color (active, text);
547 + return result
+ style (active, text);