shariq-pi-extensions 0.2.33 → 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.
|
@@ -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).",
|