shariq-pi-extensions 0.2.34 → 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.
|
@@ -89,12 +89,25 @@ export function createSmartCompactionExtension(options: SmartCompactionExtension
|
|
|
89
89
|
|
|
90
90
|
// In-flight context threshold guard:
|
|
91
91
|
// If consecutive tool calls in a single run exceed 95% of the model's context window,
|
|
92
|
-
//
|
|
92
|
+
// trigger compaction cleanly and continue the task from the compacted checkpoint.
|
|
93
|
+
let isCompactingInFlight = false;
|
|
94
|
+
|
|
93
95
|
const checkInFlightUsage = (ctx: ExtensionContext) => {
|
|
94
|
-
if (!config.enabled) return;
|
|
96
|
+
if (!config.enabled || isCompactingInFlight) return;
|
|
95
97
|
const usage = ctx.getContextUsage();
|
|
96
98
|
if (usage && typeof usage.percent === "number" && usage.percent >= 95) {
|
|
97
|
-
|
|
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
|
+
});
|
|
98
111
|
}
|
|
99
112
|
};
|
|
100
113
|
|