@herbertgao/pi-extensions 2026.9.16 → 2026.9.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/online-context-compact/extension.ts
CHANGED
|
@@ -49,7 +49,6 @@ export type OnlineContextCompactOptions = {
|
|
|
49
49
|
type PendingBoundary = { readonly toolCallId: string };
|
|
50
50
|
type SelectedCompaction = { readonly decision: CompactionDecision };
|
|
51
51
|
type CacheDebt = { readonly debtTokens: number; readonly repaymentTokens: number };
|
|
52
|
-
type PendingContinuation = { readonly promise: Promise<void>; readonly resolve: () => void };
|
|
53
52
|
|
|
54
53
|
const SUBAGENTS_MANAGER_KEY = Symbol.for("pi-subagents:manager");
|
|
55
54
|
|
|
@@ -197,10 +196,6 @@ function restoreCompactionThinking(pi: ExtensionAPI, override: CompactionThinkin
|
|
|
197
196
|
}
|
|
198
197
|
}
|
|
199
198
|
|
|
200
|
-
function releaseParentContinuation(continuation: PendingContinuation | undefined): void {
|
|
201
|
-
if (continuation) setTimeout(continuation.resolve, 0);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
199
|
export function createOnlineContextCompactExtension(options: OnlineContextCompactOptions = {}): ExtensionFactory {
|
|
205
200
|
const keepRecentTokens = resolveKeepRecentTokens(options.keepRecentTokens);
|
|
206
201
|
const cacheWriteReadRatio = resolveCacheWriteReadRatio(options.cacheWriteReadRatio);
|
|
@@ -212,17 +207,10 @@ export function createOnlineContextCompactExtension(options: OnlineContextCompac
|
|
|
212
207
|
let pendingBoundary: PendingBoundary | undefined;
|
|
213
208
|
let selected: SelectedCompaction | undefined;
|
|
214
209
|
let activeDebt: CacheDebt | undefined;
|
|
215
|
-
let nextContinuation: PendingContinuation | undefined;
|
|
216
210
|
let compactionInFlight = false;
|
|
217
211
|
let compactionThinkingOverride: CompactionThinkingOverride | undefined;
|
|
218
212
|
|
|
219
|
-
const releaseContinuation = (): void => {
|
|
220
|
-
const continuation = nextContinuation;
|
|
221
|
-
nextContinuation = undefined;
|
|
222
|
-
continuation?.resolve();
|
|
223
|
-
};
|
|
224
213
|
const restore = (context: ExtensionContext): void => {
|
|
225
|
-
releaseContinuation();
|
|
226
214
|
state = restoreOnlineState(context.sessionManager.getBranch());
|
|
227
215
|
restored = true;
|
|
228
216
|
observedMessages = buildSessionContext(
|
|
@@ -358,21 +346,13 @@ export function createOnlineContextCompactExtension(options: OnlineContextCompac
|
|
|
358
346
|
});
|
|
359
347
|
|
|
360
348
|
pi.on("agent_settled", async (_event, context) => {
|
|
361
|
-
// sendMessage() starts a turn without returning its promise. Capture the
|
|
362
|
-
// child settlement so print/JSON mode cannot dispose while it is running.
|
|
363
|
-
const parentContinuation = nextContinuation;
|
|
364
|
-
nextContinuation = undefined;
|
|
365
349
|
const pending = selected;
|
|
366
350
|
selected = undefined;
|
|
367
351
|
if (!context.isIdle()) {
|
|
368
352
|
selected = pending;
|
|
369
|
-
nextContinuation = parentContinuation;
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
if (!pending || hasRunningSubagents()) {
|
|
373
|
-
releaseParentContinuation(parentContinuation);
|
|
374
353
|
return;
|
|
375
354
|
}
|
|
355
|
+
if (!pending || hasRunningSubagents()) return;
|
|
376
356
|
|
|
377
357
|
activeDebt = {
|
|
378
358
|
debtTokens: pending.decision.writeTokens * (pending.decision.incrementalCacheCostRatio ?? 0),
|
|
@@ -428,43 +408,22 @@ export function createOnlineContextCompactExtension(options: OnlineContextCompac
|
|
|
428
408
|
}
|
|
429
409
|
|
|
430
410
|
if (compacted) {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
{
|
|
442
|
-
customType: "sol-pi-online-context-compact",
|
|
443
|
-
content: POST_COMPACTION_PLAN_REMINDER,
|
|
444
|
-
display: false,
|
|
445
|
-
},
|
|
446
|
-
{ triggerTurn: true },
|
|
447
|
-
);
|
|
448
|
-
} catch (error) {
|
|
449
|
-
if (nextContinuation === continuation) nextContinuation = undefined;
|
|
450
|
-
continuation.resolve();
|
|
451
|
-
throw error;
|
|
452
|
-
}
|
|
453
|
-
// triggerTurn starts on the next event-loop turn; checking immediately is racy.
|
|
454
|
-
await new Promise<void>((resolve) => setTimeout(resolve, 0));
|
|
455
|
-
if (context.isIdle() && nextContinuation === continuation) {
|
|
456
|
-
nextContinuation = undefined;
|
|
457
|
-
continuation.resolve();
|
|
458
|
-
throw new Error("Online context compact continuation did not start");
|
|
459
|
-
}
|
|
460
|
-
await continuation.promise;
|
|
411
|
+
// Pi >=0.87 defers this turn until agent_settled handlers finish and
|
|
412
|
+
// awaits it before prompt() resolves, so print/JSON mode stays alive.
|
|
413
|
+
pi.sendMessage(
|
|
414
|
+
{
|
|
415
|
+
customType: "sol-pi-online-context-compact",
|
|
416
|
+
content: POST_COMPACTION_PLAN_REMINDER,
|
|
417
|
+
display: false,
|
|
418
|
+
},
|
|
419
|
+
{ triggerTurn: true },
|
|
420
|
+
);
|
|
461
421
|
}
|
|
462
422
|
} finally {
|
|
463
423
|
restoreCompactionThinking(pi, compactionThinkingOverride);
|
|
464
424
|
compactionThinkingOverride = undefined;
|
|
465
425
|
compactionInFlight = false;
|
|
466
426
|
activeDebt = undefined;
|
|
467
|
-
releaseParentContinuation(parentContinuation);
|
|
468
427
|
}
|
|
469
428
|
});
|
|
470
429
|
|
|
@@ -487,7 +446,6 @@ export function createOnlineContextCompactExtension(options: OnlineContextCompac
|
|
|
487
446
|
pi.on("session_shutdown", () => {
|
|
488
447
|
restoreCompactionThinking(pi, compactionThinkingOverride);
|
|
489
448
|
compactionThinkingOverride = undefined;
|
|
490
|
-
releaseContinuation();
|
|
491
449
|
pendingBoundary = undefined;
|
|
492
450
|
selected = undefined;
|
|
493
451
|
activeDebt = undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@herbertgao/pi-extensions",
|
|
3
|
-
"version": "2026.9.
|
|
3
|
+
"version": "2026.9.17",
|
|
4
4
|
"description": "Aggregate installer for HerbertGao-maintained Pi extensions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"extensions",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@herbertgao/pi-cc-extensions": "0.9.5",
|
|
46
46
|
"@herbertgao/pi-subagents": "0.18.3",
|
|
47
47
|
"@herbertgao/resume-from": "0.2.3",
|
|
48
|
-
"@herbertgao/sol-pi": "0.3.
|
|
48
|
+
"@herbertgao/sol-pi": "0.3.3",
|
|
49
49
|
"@juicesharp/rpiv-ask-user-question": "2.11.0",
|
|
50
50
|
"@juicesharp/rpiv-config": "^2.11.0",
|
|
51
51
|
"@modelcontextprotocol/client": "2.0.0",
|