pi-ext bugabingas pi extensions
owned by bugabinga
README Source History Refs Compare Notes Search fix(decay): improve compaction progress display
c47d47f4147a1c35b78690805bf4dffe222c9878
Oliver Jan Krylow <oliver@bugabinga.net > · 19 Sep 2026
SSH signature · not checked
Browse files Compare with HEAD
Changed files (3) 6 + - Improve Decay’s compaction display with stationary retained context, left-growing summaries, chunk-position progress, live memory selection, and recency markers
6 7 - Make Decay retry classification and summarization with the current session model when an explicit model is unavailable or fails, including quota and rate-limit errors
7 8 - Remove working-label updates from the Web fetch and search tools
8 9 - Remove the working-label update from git-safe cloning
extensions/decay/__tests__/ui.test.ts Modified 102 102 it (
"uses one continuous style under each CTX label and block" , ()
=> {
103 103 const frame
= renderDecayFrame (
113 ,
30 ,
state (),
2_000 );
104 104 const row
= frame[
1 ].
slice (
13 );
105 - const sourceLabel
= plainFrame (frame)[
1 ].
indexOf (
"~94k SUMMARIZE" );
105 + const sourceLabel
= plainFrame (frame)[
1 ].
indexOf (
"~94k TO SUMMARY" );
106 106 const keepLabel
= plainFrame (frame)[
1 ].
indexOf (
"~24k KEEP" );
107 107 expect (sourceLabel).
toBeGreaterThanOrEqual (
13 );
108 108 expect (keepLabel).
toBeGreaterThan (sourceLabel);
175 - mergeStartedAt:
1_000 ,
177 176 selectedKeys: [
"keep me" ],
183 182 expect (
plainFrame (frame)[
2 ]).
toContain (
"DURABLE" );
186 - it (
"uses one token scale and places KEEP directly after streamed summary" , ()
=> {
185 + it (
"keeps retained context stationary while the new summary grows leftward" , ()
=> {
187 186 const initial
= renderDecayFrame (
191 190 inputTokens :
100_000 ,
192 191 keptTokens :
20_000 ,
194 - mergeStartedAt :
1_000 ,
195 193 summaryTokens :
1_000 ,
203 201 inputTokens :
100_000 ,
204 202 keptTokens :
20_000 ,
206 - mergeStartedAt :
1_000 ,
207 204 summaryTokens :
4_000 ,
208 + const initialKeep
= initial[
3 ].
findIndex (
209 + (cell)
=> cell.
style === "keepBlock" ,
211 + const grownKeep
= grown[
3 ].
findIndex ((cell)
=> cell.
style === "keepBlock" );
211 212 expect (
countStyle (initial[
1 ],
"keepBlock" )).
toBe (
20 );
212 213 expect (
countStyle (initial[
3 ],
"keepBlock" )).
toBe (
20 );
213 214 expect (
countStyle (initial[
3 ],
"selectedBlock" )).
toBe (
1 );
214 215 expect (
countStyle (grown[
3 ],
"selectedBlock" )).
toBe (
4 );
215 - const firstKeep
= initial[
3 ].
findIndex (
216 - (cell)
=> cell.
style === "keepBlock" ,
218 - expect (firstKeep).
toBe (
14 );
216 + expect (initialKeep).
toBe (
93 );
217 + expect (grownKeep).
toBe (initialKeep);
219 218 expect (
plainFrame (initial)[
3 ]).
toContain (
"NEW ~21k" );
220 219 expect (
plainFrame (grown)[
3 ]).
toContain (
"NEW ~24k" );
222 + it (
"shows retained context before the first summary token arrives" , ()
=> {
223 + const frame
= renderDecayFrame (
226 + state ({ phase:
"merge" , summaryTokens:
undefined }),
229 + const text
= plainFrame (frame);
230 + const keepStart
= frame[
3 ].
findIndex ((cell)
=> cell.
style === "keepBlock" );
231 + expect (keepStart).
toBeGreaterThan (
13 );
232 + expect (text[
0 ]).
toContain (
"WRITING SUMMARY" );
233 + expect (text[
3 ]).
toContain (
"NEW ?" );
234 + expect (text[
3 ].
slice (keepStart)).
toContain (
"KEEP" );
237 + it (
"keeps out-of-order chunk progress in source order" , ()
=> {
238 + const frame
= renderDecayFrame (
241 + state ({ records: [
record (
8 )] }),
244 + const row
= frame[
2 ];
245 + const firstCompleted
= row.
findIndex (
246 + (cell)
=> cell.
style === "contextBlock" ,
248 + expect (firstCompleted).
toBeGreaterThan (
13 );
251 + .
slice (
13 , firstCompleted)
252 + .
every ((cell)
=> cell.
style === "pendingBlock" ),
255 + row.
slice (firstCompleted).
every ((cell)
=> cell.
style === "contextBlock" ),
259 + it (
"shows selected memory count and recency markers" , ()
=> {
260 + const candidates
= [
261 + {
... atom (
"old" ,
"context" ), lastSeen:
1 , seenCount:
1 },
262 + {
... atom (
"repeat" ,
"decision" ), lastSeen:
2 , seenCount:
2 },
263 + {
... atom (
"new" ,
"goal" ), lastSeen:
3 , seenCount:
1 },
265 + const frame
= renderDecayFrame (
271 + selectedKeys: [
"old" ,
"repeat" ],
275 + expect (
plainFrame (frame)[
2 ]).
toContain (
"MEM 2/3 │" );
276 + expect (
plainFrame (frame)[
2 ]).
toContain (
"◆" );
277 + expect (
plainFrame (frame)[
4 ]).
toContain (
"◆ recurring" );
223 280 it (
"never substitutes the configured target for unknown retained tokens" , ()
=> {
224 281 const frame
= plainFrame (
225 282 renderDecayFrame (
80 ,
30 ,
state ({ keptTokens:
undefined }),
2_000 ),
235 292 const widget
= component (
239 295 candidates: [
atom (
"one" ,
"decision" )],
240 296 selectedKeys: [
"one" ],
241 297 summaryTokens:
100 ,
extensions/decay/ui.ts Modified 7 7 const MAP_START
= 13 ;
8 - const SELECTION_MS
= 660 ;
9 8 const SPIN
= [
"◉" ,
"◍" ,
"◎" ,
"◌" ]
as const ;
10 9 const SUMMARY_HEAD
= [
" " ,
"░" ,
"▒" ,
"▓" ,
"▒" ,
"░" ]
as const ;
41 40 phase :
"classify" | "merge" ;
42 41 records : DisplayRecord[];
44 - mergeStartedAt
?: number;
45 43 candidates
?: MemoryAtom[];
46 44 selectedKeys
?: string[];
47 45 summaryTokens
?: number;
87 85 selected : readonly MemoryAtom[],
89 87 this.state.phase
= "merge" ;
90 - this.state.mergeStartedAt
= this.
now ();
91 88 this.state.candidates
= candidates.
map ((atom)
=> ({
... atom }));
92 89 this.state.selectedKeys
= selected.
map ((atom)
=> normalizeKey (atom.key));
93 90 this.tui.
requestRender ();
127 124 const elapsedMs
= Math .
max (
0 , now
- state.startedAt);
128 125 const frame
= Math .
floor (elapsedMs
/ FRAME_MS);
129 126 const completedChunks
= completedChunkCount (state);
130 - const selectionProgress
= 131 - state.phase
=== "merge" 134 - Math .
max (
0 , now
- (state.mergeStartedAt
?? now))
/ SELECTION_MS,
138 128 state.phase
=== "classify" 139 129 ? `CLASSIFYING ${completedChunks}/${state.totalChunks}` 140 - : selectionProgress
< 1 && state.summaryTokens
=== undefined 141 - ? "SELECTING MEMORY" 142 - : "WRITING SUMMARY" ;
130 + : "WRITING SUMMARY" ;
144 132 putFragments (canvas,
0 ,
0 , [
145 133 [
"▣" ,
"sourceText" ],
156 144 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" );
145 + renderFacts (canvas, state);
146 + renderNewContext (canvas, state, frame, completedChunks);
151 + state.phase
=== "merge" 152 + ? "↵ queues a message · Esc cancels · ◆ recurring · █ newer" 153 + : "↵ queues a message · Esc cancels" ,
184 180 scaledWidth (summarized, scale, capacity),
186 182 fillBlock (canvas, MAP_START,
1 , sourceWidth,
"sourceBlock" , [
187 - ` ~${ compactTokens (summarized)} ${state.phase === "merge" ? "SUMMARIZED" : "SUMMARIZE"} ` ,
188 - state.phase
=== "merge" ? " SUMMARIZED " : " SUMMARIZE " ,
183 + ` ~${ compactTokens (summarized)} TO SUMMARY ` ,
191 187 fillBlock (canvas, MAP_START
+ sourceWidth,
1 , keepWidth,
"keepBlock" , [
198 - function renderFacts (
200 - state
: DecayDisplayState ,
201 - selectionProgress
: number ,
194 + function renderFacts (canvas
: Cell [][], state
: DecayDisplayState )
: void {
203 195 const capacity
= Math .
max (
0 , canvas[
0 ].
length - MAP_START);
204 196 const records
= uniqueRecords (state.records);
205 - const observed
= records.
flatMap ((record)
=> record.atoms);
197 + const observed
= records.
flatMap ((record)
=> 198 + record.atoms.
map ((atom)
=> ({ key: atom.key, kind: atom.kind })),
206 200 const candidates
= 207 201 state.phase
=== "merge" ? (state.candidates
?? [])
: observed;
208 - renderMapPrefix (canvas,
2 ,
"FACTS" ,
compactCount (candidates.
length ));
202 + if (state.phase
=== "classify" ) {
203 + renderMapPrefix (canvas,
2 ,
"FACTS" ,
compactCount (observed.
length ));
205 + const selected
= new Set (state.selectedKeys
?? []);
206 + const selectedCount
= candidates.
filter ((atom)
=> 207 + selected.
has (
normalizeKey (atom.key)),
209 + renderMapPrefix (canvas,
2 ,
"MEM" ,
`${selectedCount}/${candidates. length }` );
209 211 if (capacity
=== 0 )
return ;
211 213 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,
226 - capacity
- completeWidth,
214 + const byChunk
= new Map (records.
map ((record)
=> [record.chunk, record]));
215 + for (
let index
= 0 ; index
< state.totalChunks; index
++ ) {
216 + const start
= Math .
floor ((index
* capacity)
/ state.totalChunks);
217 + const end
= Math .
floor (((index
+ 1 )
* capacity)
/ state.totalChunks);
218 + const width
= end
- start;
219 + const record
= byChunk.
get (index
+ 1 );
221 + renderClassifiedGroups (
224 + record.atoms.
map ((atom)
=> ({ key: atom.key, kind: atom.kind })),
230 + fillBlock (canvas, MAP_START
+ start,
2 , width,
"pendingBlock" , [],
"░" );
234 236 const selected
= new Set (state.selectedKeys
?? []);
235 - renderClassifiedGroups (
237 + renderClassifiedGroups (canvas,
2 , candidates, capacity, selected);
240 + type AtomView = Pick <
MemoryAtom ,
"key" | "kind" >
& 241 + Partial <
Pick <
MemoryAtom ,
"lastSeen" | "seenCount" >>;
245 243 function renderClassifiedGroups (
246 244 canvas
: Cell [][],
248 - atoms
: readonly Pick <
MemoryAtom ,
"key" | "kind" >[],
246 + atoms
: readonly AtomView [],
250 248 selectedKeys
: ReadonlySet <
string >
| undefined ,
251 - selectionProgress
: number ,
249 + startX
= MAP_START,
253 251 if (width
<= 0 )
return ;
254 252 const durable
= atoms.
filter ((atom)
=> isProtectedKind (atom.kind));
255 253 const context
= atoms.
filter ((atom)
=> ! isProtectedKind (atom.kind));
256 254 if (atoms.
length === 0 ) {
257 - fillBlock (canvas, MAP_START, y, width,
"completeBlock" , []);
255 + fillBlock (canvas, startX, y, width,
"completeBlock" , []);
260 258 const durableWidth
= partitionWidth (durable.
length , atoms.
length , width);
261 259 const contextWidth
= width
- durableWidth;
269 267 [
` ◆ ${durable. length } DURABLE ` ,
` ${durable. length } DUR ` ,
" ◆ " ],
275 - MAP_START
+ durableWidth,
272 + startX
+ durableWidth,
280 277 [
` ◇ ${context. length } CONTEXT ` ,
` ${context. length } CTX ` ,
" ◇ " ],
291 - atoms : readonly Pick
< MemoryAtom,
"key" > [],
287 + atoms : readonly AtomView[],
292 288 baseStyle : CellStyle,
293 289 labels : readonly string[],
294 290 selectedKeys : ReadonlySet
< string
> | undefined ,
295 - selectionProgress : number,
297 292 if (width
<= 0 )
return ;
298 293 for (
let offset
= 0 ; offset
< width; offset
++ ) {
306 301 const selected
= atom
&& selectedKeys?.
has (
normalizeKey (atom.key));
307 - const revealed
= hashFraction (offset, x)
<= selectionProgress;
313 - selected
&& revealed
? "selectedBlock" : baseStyle,
302 + const glyph
= selectedKeys
? atomGlyph (atom, atoms)
: " " ;
303 + put (canvas, x
+ offset, y, glyph, selected
? "selectedBlock" : baseStyle);
316 305 const label
= fittingLabel (width, labels);
317 306 if (label)
putPreservingStyle (canvas, x, y, label);
322 311 state : DecayDisplayState,
324 313 completedChunks : number,
325 - selectionProgress : number,
327 315 const capacity
= Math .
max (
0 , canvas[
0 ].
length - MAP_START);
328 316 const summary
= state.summaryTokens;
329 317 const kept
= state.keptTokens;
330 - const known
= summary
!== undefined && summary
> 0 && kept
!== undefined ;
319 + kept
!== undefined && kept
>= 0 && kept
<= state.inputTokens;
335 - known
? `~${ compactTokens (summary + kept)}` : "?" ,
324 + knownKept
&& summary
!== undefined 325 + ? `~${ compactTokens (summary + kept)}` 337 328 if (capacity
=== 0 )
return ;
340 331 state.phase
=== "classify" 341 332 ? `○ waiting for ${ Math . max (0, state.totalChunks - completedChunks)} chunks` 342 - : selectionProgress
< 1 343 - ? "○ selecting facts" 344 - : "○ waiting for summary" ;
333 + : "○ retained size unavailable" ;
345 334 put (canvas, MAP_START,
3 , waiting,
"dim" );
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 )
338 + const scale
= Math .
max (
1 , state.inputTokens, kept
+ (summary
?? 0 ));
339 + const keepWidth
= scaledWidth (kept, scale, capacity);
340 + const keepStart
= MAP_START
+ capacity
- keepWidth;
341 + const summaryCapacity
= Math .
max (
0 , keepStart
- MAP_START);
342 + const summaryWidth
= 343 + summary
=== undefined 345 + : Math .
min (summaryCapacity,
scaledWidth (summary, scale, capacity));
346 + if (summaryWidth
> 0 ) {
347 + const summaryStart
= keepStart
- summaryWidth;
348 + fillBlock (canvas, summaryStart,
3 , summaryWidth,
"selectedBlock" , []);
362 - MAP_START
+ summaryWidth
- 1 ,
364 353 SUMMARY_HEAD[frame
% SUMMARY_HEAD.
length ],
367 - fillBlock (canvas, MAP_START
+ summaryWidth,
3 , keepWidth,
"keepBlock" , [
358 + state.phase
=== "classify" 359 + ? `○ waiting for ${ Math . max (0, state.totalChunks - completedChunks)} chunks` 360 + : "○ waiting for summary" ;
361 + put (canvas, MAP_START,
3 , waiting.
slice (
0 , summaryCapacity),
"dim" );
363 + fillBlock (canvas, keepStart,
3 , keepWidth,
"keepBlock" , [
368 364 ` ~${ compactTokens (kept)} KEEP ` ,
426 422 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 ;
426 + atom
: AtomView | undefined ,
427 + atoms
: readonly AtomView [],
429 + if (
! atom)
return " " ;
430 + if ((atom.seenCount
?? 0 )
> 1 )
return "◆" ;
431 + const seen
= atom.lastSeen
?? 0 ;
432 + const newest
= Math .
max (
... atoms.
map ((item)
=> item.lastSeen
?? 0 ), seen);
433 + const oldest
= Math .
min (
... atoms.
map ((item)
=> item.lastSeen
?? 0 ), seen);
434 + const ratio
= (seen
- oldest)
/ Math .
max (
1 , newest
- oldest);
435 + return ratio
< 0.25 ? "░" : ratio
< 0.5 ? "▒" : ratio
< 0.75 ? "▓" : "█" ;
433 438 function normalizeKey (key
: string )
: string {