shariq-pi-extensions 0.2.33 → 0.2.35

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.
@@ -76,6 +76,49 @@ 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
+ // trigger compaction cleanly and continue the task from the compacted checkpoint.
93
+ let isCompactingInFlight = false;
94
+
95
+ const checkInFlightUsage = (ctx: ExtensionContext) => {
96
+ if (!config.enabled || isCompactingInFlight) return;
97
+ const usage = ctx.getContextUsage();
98
+ if (usage && typeof usage.percent === "number" && usage.percent >= 95) {
99
+ isCompactingInFlight = true;
100
+ ctx.compact({
101
+ onComplete: () => {
102
+ isCompactingInFlight = false;
103
+ // After in-flight compaction completes, if the agent was interrupted mid-run,
104
+ // queue a follow-up continuation so the agent automatically picks up where it left off.
105
+ pi.sendUserMessage("Continue.", { deliverAs: "followUp" });
106
+ },
107
+ onError: () => {
108
+ isCompactingInFlight = false;
109
+ },
110
+ });
111
+ }
112
+ };
113
+
114
+ pi.on("tool_result", (_event, ctx) => {
115
+ checkInFlightUsage(ctx);
116
+ });
117
+
118
+ pi.on("turn_end", (_event, ctx) => {
119
+ checkInFlightUsage(ctx);
120
+ });
121
+
79
122
  // Slash command: /compaction-model
80
123
  pi.registerCommand("compaction-model", {
81
124
  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.33",
3
+ "version": "0.2.35",
4
4
  "description": "Cross-platform extension suite for the Pi coding agent.",
5
5
  "license": "MIT",
6
6
  "author": "Shariq Riaz",