@caupulican/pi-adaptative 0.80.26 → 0.80.28
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.
- package/CHANGELOG.md +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +2 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-session.d.ts +6 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +47 -5
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/context-gc.d.ts +62 -0
- package/dist/core/context-gc.d.ts.map +1 -0
- package/dist/core/context-gc.js +332 -0
- package/dist/core/context-gc.js.map +1 -0
- package/dist/core/extensions/builtin.d.ts +3 -1
- package/dist/core/extensions/builtin.d.ts.map +1 -1
- package/dist/core/extensions/builtin.js +41 -1
- package/dist/core/extensions/builtin.js.map +1 -1
- package/dist/core/sdk.d.ts +2 -2
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +26 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +31 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/system-prompt.d.ts +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js.map +1 -1
- package/docs/settings.md +30 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* Modes use this class and add their own I/O layer on top.
|
|
14
14
|
*/
|
|
15
15
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
16
|
-
import { basename, dirname } from "node:path";
|
|
16
|
+
import { basename, dirname, join } from "node:path";
|
|
17
17
|
import { clampThinkingLevel, cleanupSessionResources, getSupportedThinkingLevels, isContextOverflow, modelsAreEqual, resetApiProviders, streamSimple, } from "@caupulican/pi-ai";
|
|
18
18
|
import { theme } from "../modes/interactive/theme/theme.js";
|
|
19
19
|
import { stripFrontmatter } from "../utils/frontmatter.js";
|
|
@@ -22,6 +22,7 @@ import { sleep } from "../utils/sleep.js";
|
|
|
22
22
|
import { formatNoApiKeyFoundMessage, formatNoModelSelectedMessage } from "./auth-guidance.js";
|
|
23
23
|
import { executeBashWithOperations } from "./bash-executor.js";
|
|
24
24
|
import { calculateContextTokens, collectEntriesForBranchSummary, compact, estimateContextTokens, generateBranchSummary, prepareCompaction, shouldCompact, } from "./compaction/index.js";
|
|
25
|
+
import { applyContextGc } from "./context-gc.js";
|
|
25
26
|
import { DEFAULT_THINKING_LEVEL } from "./defaults.js";
|
|
26
27
|
import { exportSessionToHtml } from "./export-html/index.js";
|
|
27
28
|
import { createToolHtmlRenderer } from "./export-html/tool-renderer.js";
|
|
@@ -79,10 +80,11 @@ export class AgentSession {
|
|
|
79
80
|
_pendingNextTurnMessages = [];
|
|
80
81
|
/** Serializes prompt() submissions made while streaming so queued steering/follow-ups keep user-typed FIFO order. */
|
|
81
82
|
_streamingPromptSubmissionTail = Promise.resolve();
|
|
82
|
-
// Compaction state
|
|
83
|
+
// Compaction/context hygiene state
|
|
83
84
|
_compactionAbortController = undefined;
|
|
84
85
|
_autoCompactionAbortController = undefined;
|
|
85
86
|
_overflowRecoveryAttempted = false;
|
|
87
|
+
_latestContextGcReport = undefined;
|
|
86
88
|
// Branch summarization state
|
|
87
89
|
_branchSummaryAbortController = undefined;
|
|
88
90
|
// Retry state
|
|
@@ -213,10 +215,11 @@ export class AgentSession {
|
|
|
213
215
|
catch {
|
|
214
216
|
currentMessages = authoritativeMessages;
|
|
215
217
|
}
|
|
218
|
+
let finalMessages = currentMessages;
|
|
216
219
|
if (this._extensionRunner.hasHandlers("context")) {
|
|
217
|
-
|
|
220
|
+
finalMessages = await this._extensionRunner.emitContext(currentMessages);
|
|
218
221
|
}
|
|
219
|
-
return
|
|
222
|
+
return this._applyContextGc(finalMessages, true).messages;
|
|
220
223
|
};
|
|
221
224
|
}
|
|
222
225
|
_installAgentTurnRefresh() {
|
|
@@ -243,6 +246,45 @@ export class AgentSession {
|
|
|
243
246
|
tools: this.agent.state.tools.slice(),
|
|
244
247
|
};
|
|
245
248
|
}
|
|
249
|
+
_contextGcStorageDir() {
|
|
250
|
+
return join(this.sessionManager.getSessionDir(), "context-gc", this.sessionManager.getSessionId());
|
|
251
|
+
}
|
|
252
|
+
_applyContextGc(messages, writePayloads) {
|
|
253
|
+
try {
|
|
254
|
+
const result = applyContextGc(messages, {
|
|
255
|
+
...this.settingsManager.getContextGcSettings(),
|
|
256
|
+
cwd: this._cwd,
|
|
257
|
+
storageDir: this._contextGcStorageDir(),
|
|
258
|
+
writePayloads,
|
|
259
|
+
});
|
|
260
|
+
this._latestContextGcReport = result.report;
|
|
261
|
+
return result;
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
const report = {
|
|
265
|
+
enabled: false,
|
|
266
|
+
packedCount: 0,
|
|
267
|
+
originalTokens: 0,
|
|
268
|
+
packedTokens: 0,
|
|
269
|
+
savedTokens: 0,
|
|
270
|
+
records: [],
|
|
271
|
+
};
|
|
272
|
+
this._latestContextGcReport = report;
|
|
273
|
+
return { messages, report };
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
getContextGcReport(messages) {
|
|
277
|
+
if (messages)
|
|
278
|
+
return this._applyContextGc(messages, false).report;
|
|
279
|
+
return (this._latestContextGcReport ?? {
|
|
280
|
+
enabled: this.settingsManager.getContextGcSettings().enabled,
|
|
281
|
+
packedCount: 0,
|
|
282
|
+
originalTokens: 0,
|
|
283
|
+
packedTokens: 0,
|
|
284
|
+
savedTokens: 0,
|
|
285
|
+
records: [],
|
|
286
|
+
});
|
|
287
|
+
}
|
|
246
288
|
_estimateCurrentContextTokens(messages) {
|
|
247
289
|
const estimate = estimateContextTokens(messages);
|
|
248
290
|
const compactionEntry = getLatestCompactionEntry(this.sessionManager.getBranch());
|
|
@@ -2178,7 +2220,7 @@ export class AgentSession {
|
|
|
2178
2220
|
});
|
|
2179
2221
|
this._baseToolDefinitions = new Map(Object.entries(baseToolDefinitions).map(([name, tool]) => [name, tool]));
|
|
2180
2222
|
if (!this._baseToolsOverride) {
|
|
2181
|
-
for (const definition of createCoreDiagnosticsToolDefinitions(() => this.getActiveToolNames(), () => this.getAllTools())) {
|
|
2223
|
+
for (const definition of createCoreDiagnosticsToolDefinitions(() => this.getActiveToolNames(), () => this.getAllTools(), (messages) => this.getContextGcReport(messages))) {
|
|
2182
2224
|
this._baseToolDefinitions.set(definition.name, definition);
|
|
2183
2225
|
}
|
|
2184
2226
|
}
|