@caupulican/pi-adaptative 0.80.21 → 0.80.23
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 +29 -0
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +28 -1
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +10 -76
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +16 -7
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/exec.d.ts +20 -1
- package/dist/core/exec.d.ts.map +1 -1
- package/dist/core/exec.js +52 -19
- package/dist/core/exec.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +6 -0
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +33 -1
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/types.d.ts +2 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/message-retention.d.ts +26 -0
- package/dist/core/message-retention.d.ts.map +1 -0
- package/dist/core/message-retention.js +95 -0
- package/dist/core/message-retention.js.map +1 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +50 -29
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +4 -1
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/session-manager.d.ts +3 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +45 -9
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +8 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +12 -0
- package/dist/core/skills.js.map +1 -1
- package/dist/core/tools/git-filter.d.ts +9 -1
- package/dist/core/tools/git-filter.d.ts.map +1 -1
- package/dist/core/tools/git-filter.js +94 -8
- package/dist/core/tools/git-filter.js.map +1 -1
- package/dist/core/tools/read.d.ts +31 -0
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +164 -33
- package/dist/core/tools/read.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +37 -4
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +2 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +54 -18
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/jsonl.d.ts +0 -7
- package/dist/modes/rpc/jsonl.d.ts.map +1 -1
- package/dist/modes/rpc/jsonl.js +17 -0
- package/dist/modes/rpc/jsonl.js.map +1 -1
- package/dist/utils/safe-write-stream.d.ts +10 -0
- package/dist/utils/safe-write-stream.d.ts.map +1 -0
- package/dist/utils/safe-write-stream.js +16 -0
- package/dist/utils/safe-write-stream.js.map +1 -0
- package/dist/utils/sleep.d.ts +3 -1
- package/dist/utils/sleep.d.ts.map +1 -1
- package/dist/utils/sleep.js +10 -4
- package/dist/utils/sleep.js.map +1 -1
- package/docs/extensions.md +9 -3
- package/docs/skills.md +14 -2
- 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
|
@@ -27,6 +27,7 @@ import { exportSessionToHtml } from "./export-html/index.js";
|
|
|
27
27
|
import { createToolHtmlRenderer } from "./export-html/tool-renderer.js";
|
|
28
28
|
import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
|
|
29
29
|
import { emitSessionShutdownEvent } from "./extensions/runner.js";
|
|
30
|
+
import { compactToolResultDetailsForRetention } from "./message-retention.js";
|
|
30
31
|
import { expandPromptTemplate } from "./prompt-templates.js";
|
|
31
32
|
import { CURRENT_SESSION_VERSION, getLatestCompactionEntry } from "./session-manager.js";
|
|
32
33
|
import { createSyntheticSourceInfo } from "./source-info.js";
|
|
@@ -34,78 +35,6 @@ import { buildSystemPrompt } from "./system-prompt.js";
|
|
|
34
35
|
import { createLocalBashOperations } from "./tools/bash.js";
|
|
35
36
|
import { createAllToolDefinitions } from "./tools/index.js";
|
|
36
37
|
import { createToolDefinitionFromAgentTool } from "./tools/tool-definition-wrapper.js";
|
|
37
|
-
const MAX_RETAINED_TOOL_RESULT_DETAILS_BYTES = 32 * 1024;
|
|
38
|
-
function estimateJsonLikeBytes(value, maxBytes) {
|
|
39
|
-
const seen = new WeakSet();
|
|
40
|
-
let bytes = 0;
|
|
41
|
-
const add = (amount) => {
|
|
42
|
-
bytes += amount;
|
|
43
|
-
return bytes <= maxBytes;
|
|
44
|
-
};
|
|
45
|
-
const visit = (current) => {
|
|
46
|
-
if (bytes > maxBytes)
|
|
47
|
-
return false;
|
|
48
|
-
if (current === null)
|
|
49
|
-
return add(4);
|
|
50
|
-
if (current === undefined)
|
|
51
|
-
return add(9);
|
|
52
|
-
if (typeof current === "string")
|
|
53
|
-
return add(current.length * 4 + 2);
|
|
54
|
-
if (typeof current === "number")
|
|
55
|
-
return add(24);
|
|
56
|
-
if (typeof current === "boolean")
|
|
57
|
-
return add(current ? 4 : 5);
|
|
58
|
-
if (typeof current === "bigint")
|
|
59
|
-
return add(current.toString().length + 2);
|
|
60
|
-
if (typeof current === "symbol" || typeof current === "function")
|
|
61
|
-
return add(12);
|
|
62
|
-
if (typeof current !== "object")
|
|
63
|
-
return add(8);
|
|
64
|
-
const objectValue = current;
|
|
65
|
-
if (seen.has(objectValue))
|
|
66
|
-
return add(20);
|
|
67
|
-
seen.add(objectValue);
|
|
68
|
-
if (Array.isArray(objectValue)) {
|
|
69
|
-
if (!add(2))
|
|
70
|
-
return false;
|
|
71
|
-
for (let index = 0; index < objectValue.length; index++) {
|
|
72
|
-
if (!add(index === 0 ? 0 : 1))
|
|
73
|
-
return false;
|
|
74
|
-
if (!visit(objectValue[index]))
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
return bytes <= maxBytes;
|
|
78
|
-
}
|
|
79
|
-
if (!add(2))
|
|
80
|
-
return false;
|
|
81
|
-
let first = true;
|
|
82
|
-
for (const key in objectValue) {
|
|
83
|
-
if (!Object.hasOwn(objectValue, key))
|
|
84
|
-
continue;
|
|
85
|
-
if (!add((first ? 0 : 1) + key.length * 4 + 3))
|
|
86
|
-
return false;
|
|
87
|
-
first = false;
|
|
88
|
-
if (!visit(objectValue[key]))
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
return bytes <= maxBytes;
|
|
92
|
-
};
|
|
93
|
-
visit(value);
|
|
94
|
-
return { bytes, exceeded: bytes > maxBytes };
|
|
95
|
-
}
|
|
96
|
-
function compactToolResultDetailsForRetention(message) {
|
|
97
|
-
if (message.role !== "toolResult" || message.details === undefined)
|
|
98
|
-
return;
|
|
99
|
-
const estimate = estimateJsonLikeBytes(message.details, MAX_RETAINED_TOOL_RESULT_DETAILS_BYTES);
|
|
100
|
-
if (!estimate.exceeded)
|
|
101
|
-
return;
|
|
102
|
-
message.details = {
|
|
103
|
-
piToolResultDetailsTruncated: true,
|
|
104
|
-
reason: "Tool result details exceeded retention budget; model-visible content was retained.",
|
|
105
|
-
minimumBytes: estimate.bytes,
|
|
106
|
-
maxRetainedBytes: MAX_RETAINED_TOOL_RESULT_DETAILS_BYTES,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
38
|
/**
|
|
110
39
|
* Parse a skill block from message text.
|
|
111
40
|
* Returns null if the text doesn't contain a skill block.
|
|
@@ -913,7 +842,7 @@ export class AgentSession {
|
|
|
913
842
|
* @throws Error if no model selected or no API key available (when not streaming)
|
|
914
843
|
*/
|
|
915
844
|
async prompt(text, options) {
|
|
916
|
-
if (this.isStreaming && options?.streamingBehavior) {
|
|
845
|
+
if ((this.isStreaming || this.isRetrying) && options?.streamingBehavior) {
|
|
917
846
|
const run = this._streamingPromptSubmissionTail.then(() => this._promptUnserialized(text, options), () => this._promptUnserialized(text, options));
|
|
918
847
|
this._streamingPromptSubmissionTail = run.catch(() => { });
|
|
919
848
|
return run;
|
|
@@ -965,8 +894,10 @@ export class AgentSession {
|
|
|
965
894
|
expandedText = this._expandSkillCommand(expandedText);
|
|
966
895
|
expandedText = expandPromptTemplate(expandedText, [...this.promptTemplates]);
|
|
967
896
|
}
|
|
968
|
-
// If streaming
|
|
969
|
-
|
|
897
|
+
// If streaming — or waiting out a retry backoff, which is still an active
|
|
898
|
+
// operation — queue via steer() or followUp() instead of starting a
|
|
899
|
+
// concurrent run that would race the pending retry continuation.
|
|
900
|
+
if (this.isStreaming || this.isRetrying) {
|
|
970
901
|
if (!options?.streamingBehavior) {
|
|
971
902
|
throw new Error("Agent is already processing. Specify streamingBehavior ('steer' or 'followUp') to queue the message.");
|
|
972
903
|
}
|
|
@@ -2256,6 +2187,10 @@ export class AgentSession {
|
|
|
2256
2187
|
return false;
|
|
2257
2188
|
}
|
|
2258
2189
|
const delayMs = settings.baseDelayMs * 2 ** (this._retryAttempt - 1);
|
|
2190
|
+
// The retry window counts as active work from the instant listeners hear
|
|
2191
|
+
// about it: isRetrying must already be true inside auto_retry_start handlers
|
|
2192
|
+
// so prompts arriving there queue as steering instead of racing the retry.
|
|
2193
|
+
this._retryAbortController = new AbortController();
|
|
2259
2194
|
this._emit({
|
|
2260
2195
|
type: "auto_retry_start",
|
|
2261
2196
|
attempt: this._retryAttempt,
|
|
@@ -2269,7 +2204,6 @@ export class AgentSession {
|
|
|
2269
2204
|
this.agent.state.messages = messages.slice(0, -1);
|
|
2270
2205
|
}
|
|
2271
2206
|
// Wait with exponential backoff (abortable)
|
|
2272
|
-
this._retryAbortController = new AbortController();
|
|
2273
2207
|
try {
|
|
2274
2208
|
await sleep(delayMs, this._retryAbortController.signal);
|
|
2275
2209
|
}
|