shariq-pi-extensions 0.2.31 → 0.2.32

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.
@@ -25,11 +25,11 @@ When long-running agent sessions reach context thresholds, standard compaction f
25
25
  - **Fail-Closed Validation**: Accepts only `stopReason === "stop"` and rejects tool calls, empty output, or summaries missing required section headers.
26
26
  - **Lockfile & Bundle Diff Exclusion**: Automatically excludes `package-lock.json`, `Cargo.lock`, `yarn.lock`, `pnpm-lock.yaml`, and minified assets from raw diffs, recording their status under `<modified-lockfiles-and-assets>` to preserve 100% of diff token headroom for source code.
27
27
  - **Background Daemon & Terminal Awareness**: Automatically detects running background terminals/processes and injects their status into `<active-background-processes>` so the successor agent never launches duplicate services.
28
- - **Retry Ladder**: If an attempt encounters output limits or transient reasoning timeouts:
28
+ - **Retry Ladder & Extended Prefill Timeout**: Compaction requests receive an extended 10-minute timeout (600,000ms) to accommodate large 1M context prefills. If an attempt encounters output limits or transient reasoning timeouts:
29
29
  1. Primary configured model with requested reasoning.
30
30
  2. Primary model with reasoning off (unblocks reasoning/token caps).
31
31
  3. Session model with reasoning off.
32
- 4. Graceful fallback to Pi's default compactor if all stages fail.
32
+ 4. Strict Fail-Closed Protection: If all stages fail, compaction is cancelled to preserve 100% of the conversation transcript rather than silently degrading to Pi's generic compactor.
33
33
  - **Two-Ended Head & Tail Truncation**: Preserves both the beginning (context) and end (stack traces, compiler errors, exit codes, test summaries) of tool results and command logs.
34
34
  - **100% Full-Fidelity Data Preservation**: Preserves all user-provided data, credentials, environment variables, tool inputs, and code verbatim across compactions without stripping or redaction.
35
35
  - **Deterministic 10+ Cycle Stability**: Persists machine-readable touch, dirty-file, bounded-patch, and cycle ledgers in `CompactionEntry.details`; hierarchical delta merging keeps immutable constraints while condensing obsolete history.
@@ -15,6 +15,9 @@ import {
15
15
  serializeConversationForCompaction,
16
16
  } from "./prompt.ts";
17
17
 
18
+ // Extended 10-minute timeout for large context prefills (up to 1M+ tokens on Gemini/Claude)
19
+ export const COMPACTION_TIMEOUT_MS = 10 * 60 * 1000;
20
+
18
21
  export interface DirtyFileState {
19
22
  path: string;
20
23
  status: string;
@@ -483,9 +486,21 @@ export async function runSmartCompaction(
483
486
  activeIsInherited = plan.isInherited;
484
487
 
485
488
  const tokenCeiling = computeCompactionTokenCeiling(plan.model, config, reserveTokens);
489
+
490
+ const timeoutController = new AbortController();
491
+ const timeoutTimer = setTimeout(() => {
492
+ timeoutController.abort(
493
+ new Error(`Compaction stage "${plan.stageLabel}" timed out after 10 minutes.`),
494
+ );
495
+ }, COMPACTION_TIMEOUT_MS);
496
+
497
+ const stageSignal = signal
498
+ ? AbortSignal.any([signal, timeoutController.signal])
499
+ : timeoutController.signal;
500
+
486
501
  const completeOptions: Record<string, unknown> = {
487
502
  maxTokens: tokenCeiling,
488
- signal,
503
+ signal: stageSignal,
489
504
  cacheRetention: "none",
490
505
  sessionId: uuidv7(),
491
506
  };
@@ -496,7 +511,7 @@ export async function runSmartCompaction(
496
511
 
497
512
  try {
498
513
  const response = await ctx.modelRegistry.complete(plan.model, context, completeOptions as any);
499
- signal?.throwIfAborted();
514
+ stageSignal.throwIfAborted();
500
515
  if (response.usage) {
501
516
  accumulatedUsage = combineCompactionUsage(accumulatedUsage, response.usage);
502
517
  }
@@ -509,6 +524,8 @@ export async function runSmartCompaction(
509
524
  throw err instanceof Error ? err : new Error(String(err));
510
525
  }
511
526
  lastError = err instanceof Error ? err : new Error(String(err));
527
+ } finally {
528
+ clearTimeout(timeoutTimer);
512
529
  }
513
530
  }
514
531
 
@@ -57,8 +57,10 @@ export function createSmartCompactionExtension(options: SmartCompactionExtension
57
57
  throw error;
58
58
  }
59
59
  const message = error instanceof Error ? error.message : String(error);
60
- ctx.ui?.notify(`Smart Compaction failed: ${message}. Falling back to default compactor.`, "warning");
61
- return undefined;
60
+ ctx.ui?.notify(`Smart Compaction failed: ${message}. Compaction cancelled to protect context.`, "error");
61
+ // Fail-Closed: Return cancel: true so Pi aborts compaction and preserves all conversation context
62
+ // rather than silently falling back to Pi's generic compactor.
63
+ return { cancel: true };
62
64
  } finally {
63
65
  updateStatus();
64
66
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shariq-pi-extensions",
3
- "version": "0.2.31",
3
+ "version": "0.2.32",
4
4
  "description": "Cross-platform extension suite for the Pi coding agent.",
5
5
  "license": "MIT",
6
6
  "author": "Shariq Riaz",