pi-ext bugabingas pi extensions
owned by bugabinga
README Source History Refs Compare Notes Search feat(decay): support separate summarizer model
e716d12935c72c23cfd98af86344e8862c34eb33
Oliver Jan Krylow <oliver@bugabinga.net > · 24 Aug 2026
SSH signature · not checked
Browse files Compare with HEAD
Changed files (5) extensions/decay/README.md Modified 12 - "model" :
"provider/model" 12 + "model" :
"provider/classifier-model" ,
13 + "summarizerModel" :
"provider/summarizer-model" 17 18 Omit `model` or set it to `null` to use the current session model.
19 + Omit `summarizerModel` or set it to `null` to reuse the classifier model.
19 21 Failed Decay runs delegate to Pi's default compactor and append a bounded `decay-diagnostic` custom entry containing the stage, model, sanitized reason, and timestamp.
20 22 The custom entry is persisted in session JSONL but excluded from model context.
extensions/decay/__tests__/core.test.ts Modified 86 86 describe (
"decay settings" , ()
=> {
87 - it (
"merges project model over global and preserves explicit null" , ()
=> {
87 + it (
"merges project models over global and preserves explicit null" , ()
=> {
90 - { decay: { model:
"global/model" } },
92 + model:
"global/model" ,
93 + summarizerModel:
"global/summarizer" ,
91 96 { decay: { model:
"project/model" } },
93 - ).
toEqual ({ model:
"project/model" });
99 + model:
"project/model" ,
100 + summarizerModel:
"global/summarizer" ,
95 103 readDecaySettings (
96 - { decay: { model:
"global/model" } },
98 - decay: { model:
null },
106 + model:
"global/model" ,
107 + summarizerModel:
"global/summarizer" ,
111 + decay: { model:
null , summarizerModel:
null },
101 - ).
toEqual ({ model:
null });
114 + ).
toEqual ({ model:
null , summarizerModel:
null });
102 115 expect (
readDecaySettings ({}, {})).
toEqual ({});
105 - it (
"marks invalid configured values instead of silently using current model" , ()
=> {
106 - expect (
readDecaySettings ({ decay: { model:
42 } }, {})).
toEqual ({
118 + it (
"marks invalid configured values instead of silently selecting models" , ()
=> {
120 + readDecaySettings ({ decay: { model:
42 , summarizerModel:
false } }, {}),
123 + summarizerModel:
"" ,
109 125 expect (
parseModelReference (
"provider/model/variant" )).
toEqual ({
110 126 provider:
"provider" ,
extensions/decay/__tests__/integration.test.ts Modified 6 6 fauxAssistantMessage,
9 9 }
from "@earendil-works/pi-ai" ;
10 + import { SettingsManager }
from "@earendil-works/pi-coding-agent" ;
10 11 import { afterEach, describe, expect, it, vi }
from "vitest" ;
11 12 import { createTestSession, type TestSession }
from "../../../test/harness" ;
12 13 import decayExtension
from "../index" ;
76 77 testSession?.
dispose ();
77 78 testSession
= undefined ;
79 + vi.
restoreAllMocks ();
80 82 async function setup () {
84 86 const faux
= fauxProvider ({
85 87 provider:
"openai" ,
86 - models: [{ id:
"gpt-4o" , maxTokens:
16_384 }],
89 + { id:
"gpt-4o" , maxTokens:
16_384 },
90 + { id:
"classifier" , maxTokens:
16_384 },
91 + { id:
"summarizer" , maxTokens:
8_192 },
88 94 testSession.session.extensionRunner
96 102 expect (testSession.session.extensionRunner.
createContext ().mode).not.
toBe (
105 + const streamSimple
= vi.
spyOn (faux.provider,
"streamSimple" );
106 + const stream
= vi.
spyOn (faux.provider,
"stream" );
99 107 const contexts
: Context []
= [];
100 108 faux.
setResponses ([
138 146 expect (contexts[
0 ].tools).
toHaveLength (
1 );
139 147 expect (
JSON .
stringify (contexts[
0 ])).
toContain (
"focus on exact paths" );
140 148 expect (
JSON .
stringify (contexts[
1 ])).
toContain (
"allocation" );
149 + expect (streamSimple).
toHaveBeenCalledTimes (
2 );
150 + expect (stream).not.
toHaveBeenCalled ();
142 152 await testSession.session.extensionRunner.
emit ({
143 153 type:
"session_compact" ,
170 + it (
"uses a separately configured summarizer model" ,
async ()
=> {
171 + const { testSession, faux }
= await setup ();
172 + vi.
spyOn (SettingsManager,
"create" ).
mockReturnValue (
173 + SettingsManager.
inMemory ({
175 + model:
"openai/classifier" ,
176 + summarizerModel:
"openai/summarizer" ,
180 + const streamSimple
= vi.
spyOn (faux.provider,
"streamSimple" );
181 + faux.
setResponses ([
182 + classifierMessage (),
183 + fauxAssistantMessage (
"## Goal\n\nSeparate summarizer." ),
186 + const result
= await testSession.session.extensionRunner.
emit (
190 + expect (result.compaction.
summary ).
toContain (
"Separate summarizer" );
191 + expect (streamSimple.mock.calls.
map (([model])
=> model.
id )).
toEqual ([
195 + expect (streamSimple.mock.calls[
1 ]?.[
2 ]?.maxTokens).
toBe (
8_192 );
160 198 it (
"runs a passive fixed-height widget without taking editor input" ,
async ()
=> {
161 199 const { testSession, faux }
= await setup ();
162 200 faux.
setResponses ([
extensions/decay/core.ts Modified 40 40 export interface DecaySettings {
41 41 model
?: string | null ;
42 + summarizerModel
?: string | null ;
44 45 export interface SourceChunk {
121 122 ? settingBlock (projectSettings.decay)
123 124 const merged
= {
... globalDecay,
... projectDecay };
124 - if (
! (
"model" in merged))
return {};
125 - if (merged.model
=== null )
return { model:
null };
126 - return typeof merged.model
=== "string" && merged.model.
trim ()
127 - ? { model: merged.model.
trim () }
125 + const settings
: DecaySettings = {};
126 + if (
"model" in merged) {
128 + merged.model
=== null 130 + : typeof merged.model
=== "string" && merged.model.
trim ()
131 + ? merged.model.
trim ()
134 + if (
"summarizerModel" in merged) {
135 + settings.summarizerModel
= 136 + merged.summarizerModel
=== null 138 + : typeof merged.summarizerModel
=== "string" && 139 + merged.summarizerModel.
trim ()
140 + ? merged.summarizerModel.
trim ()
131 146 function settingBlock (value
: unknown )
: Record <
string ,
unknown > {
extensions/decay/index.ts Modified 106 106 warn (ctx, message);
110 + settings.summarizerModel
=== null || 111 + settings.summarizerModel
=== undefined 113 + : resolveModel (ctx, settings.summarizerModel);
116 + settings.summarizerModel
=== "" 117 + ? "Decay summarizerModel setting must be provider/model, null, or omitted; using default compaction" 118 + : `Decay summarizer model not found: ${settings.summarizerModel}; using default compaction` ;
119 + persistFallbackDiagnostic (
122 + settings.summarizerModel
|| "classifier" ,
123 + new Error (message),
125 + warn (ctx, message);
110 129 const modelReference
= `${selected.provider}/${selected. id }` ;
130 + const summarizerModelReference
= `${summarizer.provider}/${summarizer. id }` ;
111 131 const signal
= event .signal;
112 132 let outcome
: RunOutcome ;
113 133 if (ctx.mode
=== "tui" ) {
129 151 {
onRecord : ()
=> {},
onMerge : ()
=> {} },
141 163 if (outcome.
type === "error" ) {
142 164 if (outcome.cancelled)
return { cancel:
true };
165 + const stage
= failureStage (outcome.error);
143 166 persistFallbackDiagnostic (
145 - failureStage (outcome.error),
169 + stage
=== "summarizer" ? summarizerModelReference
: modelReference,
193 216 event : SessionBeforeCompactEvent,
194 217 ctx : ExtensionContext,
219 + summarizerModel : AnyModel,
196 220 modelReference : string,
197 221 signal : AbortSignal,
198 222 ):
Promise < RunOutcome
> {
217 241 {
placement :
"aboveEditor" },
219 243 widgetShown
= true ;
220 - const result
= await runDecay (
event , ctx, model, modelReference, signal, {
221 - onRecord : (record)
=> component?.
record (record),
222 - onMerge : ()
=> component?.
setPhase (
"merge" ),
244 + const result
= await runDecay (
252 + onRecord : (record)
=> component?.
record (record),
253 + onMerge : ()
=> component?.
setPhase (
"merge" ),
224 256 return { type:
"success" , result };
225 257 }
catch (error) {
247 279 event : SessionBeforeCompactEvent,
248 280 ctx : ExtensionContext,
282 + summarizerModel : AnyModel,
250 283 modelReference : string,
251 284 signal : AbortSignal,
252 285 callbacks : RunCallbacks,
283 316 const atoms
= mergeMemory (previous?.atoms
?? [], records, chunks);
284 317 const outputBudget
= maximumOutputTokens (
286 319 event .preparation.settings.reserveTokens,
288 321 const allocated
= allocateAtoms (atoms, outputBudget);
289 322 callbacks.
onMerge ();
290 323 stage
= "summarizer" ;
291 - const response
= await ctx.modelRegistry.
complete (
293 - buildSummarizerContext (allocated,
event .customInstructions),
295 - maxTokens: outputBudget,
297 - cacheRetention:
"none" ,
298 - sessionId:
uuidv7 (),
299 - reasoning: model.reasoning
? "low" : undefined ,
324 + const auth
= await ctx.modelRegistry.
getApiKeyAndHeaders (summarizerModel);
326 + throw new Error (auth.error
|| "Decay model authentication failed" );
327 + const provider
= ctx.modelRegistry.
getProvider (summarizerModel.provider);
329 + throw new Error (
`Decay provider not found: ${summarizerModel.provider}` );
330 + const response
= await provider
333 + buildSummarizerContext (allocated,
event .customInstructions),
335 + apiKey: auth.apiKey,
336 + headers: auth.
headers ,
338 + maxTokens: outputBudget,
340 + cacheRetention:
"none" ,
341 + sessionId:
uuidv7 (),
342 + reasoning: summarizerModel.reasoning
? "low" : undefined ,
302 346 if (response.stopReason
!== "stop" )
304 348 `Decay summarizer stopped with ${response.stopReason}: ${response.errorMessage ?? "no detail"}` ,