shariq-pi-extensions 0.2.32 → 0.2.34

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.
@@ -292,7 +292,8 @@ const REQUIRED_SECTION_PATTERNS = [
292
292
 
293
293
  export function validateSummaryOutput(response: AssistantMessage): string {
294
294
  if (response.stopReason !== "stop") {
295
- throw new Error(`Compaction model did not complete successfully (stopReason="${response.stopReason}").`);
295
+ const errorDetails = response.errorMessage ? `: ${response.errorMessage}` : "";
296
+ throw new Error(`Compaction model did not complete successfully (stopReason="${response.stopReason}"${errorDetails}).`);
296
297
  }
297
298
 
298
299
  // Reject accidental tool calls
@@ -76,6 +76,36 @@ export function createSmartCompactionExtension(options: SmartCompactionExtension
76
76
  }
77
77
  });
78
78
 
79
+ // Intercept manual /compact commands in interactive or RPC inputs
80
+ pi.on("input", (event, ctx) => {
81
+ const text = event.text.trim();
82
+ if (text === "/compact" || text.startsWith("/compact ")) {
83
+ const customInstructions = text.startsWith("/compact ") ? text.slice(9).trim() : undefined;
84
+ ctx.compact(customInstructions ? { customInstructions } : undefined);
85
+ return { action: "handled" };
86
+ }
87
+ return { action: "continue" };
88
+ });
89
+
90
+ // In-flight context threshold guard:
91
+ // If consecutive tool calls in a single run exceed 95% of the model's context window,
92
+ // immediately trigger compaction before the next step runs away.
93
+ const checkInFlightUsage = (ctx: ExtensionContext) => {
94
+ if (!config.enabled) return;
95
+ const usage = ctx.getContextUsage();
96
+ if (usage && typeof usage.percent === "number" && usage.percent >= 95) {
97
+ ctx.compact();
98
+ }
99
+ };
100
+
101
+ pi.on("tool_result", (_event, ctx) => {
102
+ checkInFlightUsage(ctx);
103
+ });
104
+
105
+ pi.on("turn_end", (_event, ctx) => {
106
+ checkInFlightUsage(ctx);
107
+ });
108
+
79
109
  // Slash command: /compaction-model
80
110
  pi.registerCommand("compaction-model", {
81
111
  description: "Select or view the model used for smart context compaction (default: inherit).",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shariq-pi-extensions",
3
- "version": "0.2.32",
3
+ "version": "0.2.34",
4
4
  "description": "Cross-platform extension suite for the Pi coding agent.",
5
5
  "license": "MIT",
6
6
  "author": "Shariq Riaz",