@cydm/pie 1.0.9 → 1.0.11
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/dist/builtin/extensions/ask-user/index.js +2 -2
- package/dist/builtin/extensions/plan-mode/index.js +2 -2
- package/dist/builtin/extensions/subagent/index.js +3 -3
- package/dist/builtin/extensions/todo/index.js +2 -2
- package/dist/chunks/{chunk-XHZP5EK4.js → chunk-GNHANWYT.js} +7 -5
- package/dist/chunks/{chunk-EJGQAAKS.js → chunk-H6PTIABA.js} +95 -16
- package/dist/chunks/{chunk-A5JSJAPK.js → chunk-QACYLY3B.js} +115 -47
- package/dist/chunks/{src-3X3HBT2G.js → src-M32UEGIU.js} +1 -1
- package/dist/cli.js +52 -12
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
createAskUserCapability
|
|
4
|
-
} from "../../../chunks/chunk-
|
|
5
|
-
import "../../../chunks/chunk-
|
|
4
|
+
} from "../../../chunks/chunk-H6PTIABA.js";
|
|
5
|
+
import "../../../chunks/chunk-QACYLY3B.js";
|
|
6
6
|
import "../../../chunks/chunk-TG2EQLX2.js";
|
|
7
7
|
|
|
8
8
|
// builtin/extensions/ask-user/index.ts
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
isPlanModeSafeCommand,
|
|
8
8
|
markCompletedPlanSteps,
|
|
9
9
|
restoreExecutionState
|
|
10
|
-
} from "../../../chunks/chunk-
|
|
11
|
-
import "../../../chunks/chunk-
|
|
10
|
+
} from "../../../chunks/chunk-H6PTIABA.js";
|
|
11
|
+
import "../../../chunks/chunk-QACYLY3B.js";
|
|
12
12
|
import "../../../chunks/chunk-TG2EQLX2.js";
|
|
13
13
|
|
|
14
14
|
// builtin/extensions/plan-mode/index.ts
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
createCliHostCapabilities
|
|
4
|
-
} from "../../../chunks/chunk-
|
|
4
|
+
} from "../../../chunks/chunk-GNHANWYT.js";
|
|
5
5
|
import {
|
|
6
6
|
createSharedFileSystemTools,
|
|
7
7
|
createSubagentCapability
|
|
8
|
-
} from "../../../chunks/chunk-
|
|
9
|
-
import "../../../chunks/chunk-
|
|
8
|
+
} from "../../../chunks/chunk-H6PTIABA.js";
|
|
9
|
+
import "../../../chunks/chunk-QACYLY3B.js";
|
|
10
10
|
import "../../../chunks/chunk-TG2EQLX2.js";
|
|
11
11
|
|
|
12
12
|
// builtin/extensions/subagent/index.ts
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
executeManageTodoList,
|
|
8
8
|
executionStateToTodos,
|
|
9
9
|
restoreExecutionState
|
|
10
|
-
} from "../../../chunks/chunk-
|
|
11
|
-
import "../../../chunks/chunk-
|
|
10
|
+
} from "../../../chunks/chunk-H6PTIABA.js";
|
|
11
|
+
import "../../../chunks/chunk-QACYLY3B.js";
|
|
12
12
|
import "../../../chunks/chunk-TG2EQLX2.js";
|
|
13
13
|
|
|
14
14
|
// builtin/extensions/todo/index.ts
|
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
createSharedWebSearchTool,
|
|
9
9
|
interpretShellExit,
|
|
10
10
|
requestInteraction
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-H6PTIABA.js";
|
|
12
12
|
import {
|
|
13
13
|
Type
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-QACYLY3B.js";
|
|
15
15
|
|
|
16
16
|
// src/config.ts
|
|
17
17
|
import { existsSync, mkdirSync, readFileSync, renameSync } from "fs";
|
|
@@ -320,7 +320,7 @@ function buildBashRecoveryHint(command, output) {
|
|
|
320
320
|
if (/\bnpm ERR!|\bnpm error\b/i.test(output) && /\b(?:ECONNRESET|ETIMEDOUT|ENOTFOUND|EAI_AGAIN|fetch failed|socket hang up|registry|proxy)\b/i.test(output)) {
|
|
321
321
|
return "npm could not reach the registry. Treat this as an environment/network/proxy issue, not a source-code failure; retry npm install/npm ci when network is available or check npm proxy/registry settings.";
|
|
322
322
|
}
|
|
323
|
-
if (/\bnpm\s+run\b/.test(command) && /(?:^|\n)\s*(?:sh|bash|zsh):\s+[\w@./-]+:\s+command not found\b/i.test(output)) {
|
|
323
|
+
if (/\bnpm\s+run\b/.test(command) && (/(?:^|\n)\s*(?:sh|bash|zsh):\s+[\w@./-]+:\s+command not found\b/i.test(output) || /(?:^|\r?\n)\s*'[^']+'\s+is not recognized as an internal or external command\b/i.test(output))) {
|
|
324
324
|
return "This npm script could not find a local executable. Check whether dependencies were installed successfully in cwd, whether node_modules exists, and whether a prior npm install/npm ci failed before treating this as a code failure.";
|
|
325
325
|
}
|
|
326
326
|
return void 0;
|
|
@@ -406,8 +406,7 @@ function createBashTool(defaultCwd, options) {
|
|
|
406
406
|
shell: spawnCommand.shell,
|
|
407
407
|
cwd: workingDir,
|
|
408
408
|
env: process.env,
|
|
409
|
-
detached:
|
|
410
|
-
// Allows killing entire process tree
|
|
409
|
+
detached: process.platform !== "win32"
|
|
411
410
|
});
|
|
412
411
|
const timeoutId = setTimeout(() => {
|
|
413
412
|
timedOut = true;
|
|
@@ -515,6 +514,9 @@ function createBashTool(defaultCwd, options) {
|
|
|
515
514
|
};
|
|
516
515
|
const semantic = interpretShellExit(effectiveCommand, code);
|
|
517
516
|
details.semanticExitMeaning = semantic.semanticExitMeaning;
|
|
517
|
+
if (resolvedShell === "powershell" && code === 0 && /^\s*(?:diff|Compare-Object)\b/i.test(effectiveCommand) && /\bSideIndicator\b/.test(fullOutput)) {
|
|
518
|
+
details.semanticExitMeaning = "files differ";
|
|
519
|
+
}
|
|
518
520
|
if (truncation.truncated) {
|
|
519
521
|
details.truncation = {
|
|
520
522
|
truncated: true,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
getFileSystem,
|
|
9
9
|
getPlatformConfig,
|
|
10
10
|
streamSimple
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-QACYLY3B.js";
|
|
12
12
|
import {
|
|
13
13
|
__require
|
|
14
14
|
} from "./chunk-TG2EQLX2.js";
|
|
@@ -435,7 +435,7 @@ function migrateV1ToV2(data) {
|
|
|
435
435
|
};
|
|
436
436
|
}
|
|
437
437
|
function writeFileAtomic(gateway, filePath, content) {
|
|
438
|
-
const tempPath = filePath
|
|
438
|
+
const tempPath = `${filePath}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
439
439
|
gateway.writeFile(tempPath, content, "utf-8");
|
|
440
440
|
try {
|
|
441
441
|
const req = globalThis.require;
|
|
@@ -1230,6 +1230,8 @@ function summarizeToolResultForGuard(result) {
|
|
|
1230
1230
|
const text = content.filter((block) => !!block && typeof block === "object" && "type" in block).filter((block) => block.type === "text").map((block) => block.text || "").join("\n").trim();
|
|
1231
1231
|
return text || stableStringify(result);
|
|
1232
1232
|
}
|
|
1233
|
+
var RUNAWAY_TOOLCALL_WHITESPACE_DELTA_CHARS = 16384;
|
|
1234
|
+
var RUNAWAY_TOOLCALL_WHITESPACE_DELTA_EVENTS = 40;
|
|
1233
1235
|
function cloneQueuedInput(input) {
|
|
1234
1236
|
return {
|
|
1235
1237
|
...input,
|
|
@@ -1262,6 +1264,10 @@ var AgentSessionController = class {
|
|
|
1262
1264
|
pendingAutoCompact;
|
|
1263
1265
|
queueIdCounter = 0;
|
|
1264
1266
|
repeatedToolFailures = /* @__PURE__ */ new Map();
|
|
1267
|
+
streamGuard = {
|
|
1268
|
+
whitespaceToolCallDeltaChars: 0,
|
|
1269
|
+
whitespaceToolCallDeltaEvents: 0
|
|
1270
|
+
};
|
|
1265
1271
|
runtimeGuardTriggered = false;
|
|
1266
1272
|
constructor(options) {
|
|
1267
1273
|
this.agent = options.agent;
|
|
@@ -1285,6 +1291,9 @@ var AgentSessionController = class {
|
|
|
1285
1291
|
this.resetRuntimeGuardState();
|
|
1286
1292
|
this.emit({ type: "streaming_changed", isStreaming: true });
|
|
1287
1293
|
}
|
|
1294
|
+
if (event.type === "message_update") {
|
|
1295
|
+
this.recordMessageUpdateForGuard(event);
|
|
1296
|
+
}
|
|
1288
1297
|
if (event.type === "tool_execution_end") {
|
|
1289
1298
|
this.recordToolExecutionEndForGuard(event);
|
|
1290
1299
|
}
|
|
@@ -1879,8 +1888,52 @@ var AgentSessionController = class {
|
|
|
1879
1888
|
}
|
|
1880
1889
|
resetRuntimeGuardState() {
|
|
1881
1890
|
this.repeatedToolFailures.clear();
|
|
1891
|
+
this.streamGuard = {
|
|
1892
|
+
whitespaceToolCallDeltaChars: 0,
|
|
1893
|
+
whitespaceToolCallDeltaEvents: 0
|
|
1894
|
+
};
|
|
1882
1895
|
this.runtimeGuardTriggered = false;
|
|
1883
1896
|
}
|
|
1897
|
+
triggerRuntimeGuard(toolName, repeatCount, reason) {
|
|
1898
|
+
if (this.runtimeGuardTriggered) {
|
|
1899
|
+
return;
|
|
1900
|
+
}
|
|
1901
|
+
this.runtimeGuardTriggered = true;
|
|
1902
|
+
this.cancelRetry();
|
|
1903
|
+
this.cancelAutoCompactTimerOnly();
|
|
1904
|
+
this.cancelDispatchTimerOnly();
|
|
1905
|
+
this.cancelAutoContinueTimerOnly();
|
|
1906
|
+
this.emit({ type: "runtime_guard_triggered", toolName, repeatCount, reason });
|
|
1907
|
+
this.agent.abort();
|
|
1908
|
+
}
|
|
1909
|
+
recordMessageUpdateForGuard(event) {
|
|
1910
|
+
if (this.runtimeGuardTriggered) {
|
|
1911
|
+
return;
|
|
1912
|
+
}
|
|
1913
|
+
const assistantEvent = event.assistantMessageEvent;
|
|
1914
|
+
if (assistantEvent.type !== "toolcall_delta") {
|
|
1915
|
+
this.streamGuard.whitespaceToolCallDeltaChars = 0;
|
|
1916
|
+
this.streamGuard.whitespaceToolCallDeltaEvents = 0;
|
|
1917
|
+
return;
|
|
1918
|
+
}
|
|
1919
|
+
if (assistantEvent.delta.trim().length > 0) {
|
|
1920
|
+
this.streamGuard.whitespaceToolCallDeltaChars = 0;
|
|
1921
|
+
this.streamGuard.whitespaceToolCallDeltaEvents = 0;
|
|
1922
|
+
return;
|
|
1923
|
+
}
|
|
1924
|
+
this.streamGuard.whitespaceToolCallDeltaChars += assistantEvent.delta.length;
|
|
1925
|
+
this.streamGuard.whitespaceToolCallDeltaEvents += 1;
|
|
1926
|
+
const content = event.message.role === "assistant" && Array.isArray(event.message.content) ? event.message.content[assistantEvent.contentIndex] : void 0;
|
|
1927
|
+
const partialArgs = typeof content?.partialArgs === "string" ? content.partialArgs : "";
|
|
1928
|
+
const sparsePartialArgs = partialArgs.length >= RUNAWAY_TOOLCALL_WHITESPACE_DELTA_CHARS && partialArgs.replace(/\s/g, "").length / partialArgs.length < 0.05;
|
|
1929
|
+
if (sparsePartialArgs || this.streamGuard.whitespaceToolCallDeltaChars >= RUNAWAY_TOOLCALL_WHITESPACE_DELTA_CHARS && this.streamGuard.whitespaceToolCallDeltaEvents >= RUNAWAY_TOOLCALL_WHITESPACE_DELTA_EVENTS) {
|
|
1930
|
+
this.triggerRuntimeGuard(
|
|
1931
|
+
"assistant_stream",
|
|
1932
|
+
this.streamGuard.whitespaceToolCallDeltaEvents,
|
|
1933
|
+
"runaway_tool_call_arguments"
|
|
1934
|
+
);
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1884
1937
|
recordToolExecutionEndForGuard(event) {
|
|
1885
1938
|
if (!event.isError) {
|
|
1886
1939
|
const prefix = `${event.toolName}:`;
|
|
@@ -1898,14 +1951,7 @@ var AgentSessionController = class {
|
|
|
1898
1951
|
if (repeatCount < 3 || this.runtimeGuardTriggered) {
|
|
1899
1952
|
return;
|
|
1900
1953
|
}
|
|
1901
|
-
this.
|
|
1902
|
-
this.cancelRetry();
|
|
1903
|
-
this.cancelAutoCompactTimerOnly();
|
|
1904
|
-
this.cancelDispatchTimerOnly();
|
|
1905
|
-
this.cancelAutoContinueTimerOnly();
|
|
1906
|
-
const reason = "repeated_tool_error";
|
|
1907
|
-
this.emit({ type: "runtime_guard_triggered", toolName: event.toolName, repeatCount, reason });
|
|
1908
|
-
this.agent.abort();
|
|
1954
|
+
this.triggerRuntimeGuard(event.toolName, repeatCount, "repeated_tool_error");
|
|
1909
1955
|
}
|
|
1910
1956
|
emit(event) {
|
|
1911
1957
|
for (const listener of this.listeners) {
|
|
@@ -3184,7 +3230,11 @@ var SessionTraceSnapshotWriter = class {
|
|
|
3184
3230
|
this.flushTimer = null;
|
|
3185
3231
|
}
|
|
3186
3232
|
if (!this.cachedController || !this.cachedSessionId) return;
|
|
3187
|
-
|
|
3233
|
+
try {
|
|
3234
|
+
this.options.saveTrace(this.cachedController.getSnapshot());
|
|
3235
|
+
} catch (error) {
|
|
3236
|
+
console.warn("[SessionTrace] Failed to save session trace:", error);
|
|
3237
|
+
}
|
|
3188
3238
|
}
|
|
3189
3239
|
notePendingUserText(text) {
|
|
3190
3240
|
this.mutate((controller) => {
|
|
@@ -3567,7 +3617,7 @@ function inferUncertainty(text, signals) {
|
|
|
3567
3617
|
function isParentHandoffRequired(task) {
|
|
3568
3618
|
return task.needsParentWrite || task.status === "timeout" || task.status === "failed" || task.confidenceSignals.some((signal) => signal.type === "tool_error" || signal.type === "no_tool_use");
|
|
3569
3619
|
}
|
|
3570
|
-
async function runSubagentWithProgress(deps, task, reportProgress) {
|
|
3620
|
+
async function runSubagentWithProgress(deps, task, reportProgress, signal) {
|
|
3571
3621
|
const startTime = Date.now();
|
|
3572
3622
|
task.status = "running";
|
|
3573
3623
|
let timedOut = false;
|
|
@@ -3588,6 +3638,9 @@ async function runSubagentWithProgress(deps, task, reportProgress) {
|
|
|
3588
3638
|
if (!apiKey) {
|
|
3589
3639
|
throw new Error("No API key available for subagent execution.");
|
|
3590
3640
|
}
|
|
3641
|
+
if (signal?.aborted) {
|
|
3642
|
+
throw new Error("Subagent aborted by parent");
|
|
3643
|
+
}
|
|
3591
3644
|
deps.log(`[Subagent ${task.name}] Plan: ${plan.complexity}/${plan.modelClass}, ${tools.length} tools`);
|
|
3592
3645
|
deps.debugLog?.("plan", "SubagentPlan", plan);
|
|
3593
3646
|
const systemPrompt = `You are a specialized subagent focused on one bounded task.
|
|
@@ -3611,6 +3664,7 @@ ${formatSkillsForPrompt(deps.skills ?? [])}`;
|
|
|
3611
3664
|
let rejectTimeout = () => void 0;
|
|
3612
3665
|
let timeout;
|
|
3613
3666
|
let unsubscribe;
|
|
3667
|
+
let removeAbortListener;
|
|
3614
3668
|
const timeoutPromise = new Promise((_, reject) => {
|
|
3615
3669
|
rejectTimeout = reject;
|
|
3616
3670
|
});
|
|
@@ -3620,6 +3674,19 @@ ${formatSkillsForPrompt(deps.skills ?? [])}`;
|
|
|
3620
3674
|
subagent.abort?.();
|
|
3621
3675
|
rejectTimeout(new Error(timeoutMessage));
|
|
3622
3676
|
}, plan.timeoutSeconds * 1e3);
|
|
3677
|
+
const abortPromise = new Promise((_, reject) => {
|
|
3678
|
+
if (!signal) return;
|
|
3679
|
+
const abortSubagent = () => {
|
|
3680
|
+
subagent.abort?.();
|
|
3681
|
+
reject(new Error("Subagent aborted by parent"));
|
|
3682
|
+
};
|
|
3683
|
+
if (signal.aborted) {
|
|
3684
|
+
abortSubagent();
|
|
3685
|
+
return;
|
|
3686
|
+
}
|
|
3687
|
+
signal.addEventListener("abort", abortSubagent, { once: true });
|
|
3688
|
+
removeAbortListener = () => signal.removeEventListener("abort", abortSubagent);
|
|
3689
|
+
});
|
|
3623
3690
|
unsubscribe = subagent.subscribe((event) => {
|
|
3624
3691
|
if (event.type === "tool_execution_start") {
|
|
3625
3692
|
toolCalls++;
|
|
@@ -3654,12 +3721,14 @@ ${formatSkillsForPrompt(deps.skills ?? [])}`;
|
|
|
3654
3721
|
await subagent.prompt(prompt);
|
|
3655
3722
|
await subagent.waitForIdle?.();
|
|
3656
3723
|
})(),
|
|
3657
|
-
timeoutPromise
|
|
3724
|
+
timeoutPromise,
|
|
3725
|
+
abortPromise
|
|
3658
3726
|
]);
|
|
3659
3727
|
} finally {
|
|
3660
3728
|
if (timeout) {
|
|
3661
3729
|
clearTimeout(timeout);
|
|
3662
3730
|
}
|
|
3731
|
+
removeAbortListener?.();
|
|
3663
3732
|
unsubscribe?.();
|
|
3664
3733
|
}
|
|
3665
3734
|
const messages = subagent.state.messages;
|
|
@@ -3795,9 +3864,19 @@ Use this for independent investigation, search, review, or triage work. Provide
|
|
|
3795
3864
|
{ description: "Array of tasks to run in parallel", minItems: 1, maxItems: 10 }
|
|
3796
3865
|
)
|
|
3797
3866
|
}, { additionalProperties: false }),
|
|
3798
|
-
async execute(first, second) {
|
|
3867
|
+
async execute(first, second, third, fourth) {
|
|
3799
3868
|
const args = typeof first === "string" ? second : first;
|
|
3800
|
-
const
|
|
3869
|
+
const signal = typeof first === "string" ? third : second?.signal;
|
|
3870
|
+
const reportProgress = typeof first === "string" ? fourth ? (update) => {
|
|
3871
|
+
fourth({
|
|
3872
|
+
content: update.message ? [{ type: "text", text: update.message }] : [],
|
|
3873
|
+
details: { increment: update.increment }
|
|
3874
|
+
});
|
|
3875
|
+
} : () => void 0 : second?.reportProgress ?? (() => void 0);
|
|
3876
|
+
const toolContext = {
|
|
3877
|
+
log: typeof first === "string" ? deps.log : second?.log ?? deps.log,
|
|
3878
|
+
reportProgress
|
|
3879
|
+
};
|
|
3801
3880
|
const normalized = normalizeTaskDefs(args);
|
|
3802
3881
|
if ("error" in normalized) {
|
|
3803
3882
|
return {
|
|
@@ -3825,7 +3904,7 @@ Use this for independent investigation, search, review, or triage work. Provide
|
|
|
3825
3904
|
toolContext.log?.(`Spawning ${tasks.length} parallel subagents: ${tasks.map((task) => task.name).join(", ")}`);
|
|
3826
3905
|
toolContext.reportProgress?.({ message: `Launching ${tasks.length} parallel subagents...`, increment: 5 });
|
|
3827
3906
|
const startTime = Date.now();
|
|
3828
|
-
await Promise.all(tasks.map((task) => runSubagentWithProgress(deps, task, toolContext.reportProgress
|
|
3907
|
+
await Promise.all(tasks.map((task) => runSubagentWithProgress(deps, task, toolContext.reportProgress, signal)));
|
|
3829
3908
|
const totalDuration = Date.now() - startTime;
|
|
3830
3909
|
const completed = tasks.filter((task) => task.status === "completed").length;
|
|
3831
3910
|
const failed = tasks.filter((task) => task.status === "failed" || task.status === "timeout").length;
|
|
@@ -9002,35 +9002,78 @@ registerApiProvider({
|
|
|
9002
9002
|
});
|
|
9003
9003
|
|
|
9004
9004
|
// ../../packages/agent-core/src/agent-loop.ts
|
|
9005
|
+
function createLoopErrorMessage(error, config, signal) {
|
|
9006
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
9007
|
+
return {
|
|
9008
|
+
role: "assistant",
|
|
9009
|
+
content: [{ type: "text", text: "" }],
|
|
9010
|
+
api: config.model.api,
|
|
9011
|
+
provider: config.model.provider,
|
|
9012
|
+
model: config.model.id,
|
|
9013
|
+
usage: {
|
|
9014
|
+
input: 0,
|
|
9015
|
+
output: 0,
|
|
9016
|
+
cacheRead: 0,
|
|
9017
|
+
cacheWrite: 0,
|
|
9018
|
+
totalTokens: 0,
|
|
9019
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
|
|
9020
|
+
},
|
|
9021
|
+
stopReason: signal?.aborted ? "aborted" : "error",
|
|
9022
|
+
errorMessage: message,
|
|
9023
|
+
timestamp: Date.now()
|
|
9024
|
+
};
|
|
9025
|
+
}
|
|
9026
|
+
async function notifyOnError(config, error, phase) {
|
|
9027
|
+
try {
|
|
9028
|
+
await config.hooks?.onError?.(error instanceof Error ? error : new Error(String(error)), { phase });
|
|
9029
|
+
} catch (hookError) {
|
|
9030
|
+
console.warn(`[AgentLoop] onError hook failed during ${phase}:`, hookError);
|
|
9031
|
+
}
|
|
9032
|
+
}
|
|
9033
|
+
function endStreamWithError(stream, newMessages, config, signal, error) {
|
|
9034
|
+
const errorMessage = createLoopErrorMessage(error, config, signal);
|
|
9035
|
+
newMessages.push(errorMessage);
|
|
9036
|
+
stream.push({ type: "message_start", message: errorMessage });
|
|
9037
|
+
stream.push({ type: "message_end", message: errorMessage });
|
|
9038
|
+
stream.push({ type: "turn_end", message: errorMessage, toolResults: [] });
|
|
9039
|
+
stream.push({ type: "agent_end", messages: newMessages });
|
|
9040
|
+
stream.end(newMessages);
|
|
9041
|
+
}
|
|
9005
9042
|
function agentLoop(prompts, context, config, signal, streamFn) {
|
|
9006
9043
|
const stream = createAgentStream();
|
|
9007
9044
|
(async () => {
|
|
9008
|
-
try {
|
|
9009
|
-
await config.hooks?.beforeAgentStart?.();
|
|
9010
|
-
} catch (e) {
|
|
9011
|
-
console.warn("[AgentLoop] beforeAgentStart hook failed:", e);
|
|
9012
|
-
}
|
|
9013
9045
|
const newMessages = [...prompts];
|
|
9014
|
-
const currentContext = {
|
|
9015
|
-
...context,
|
|
9016
|
-
messages: [...context.messages, ...prompts]
|
|
9017
|
-
};
|
|
9018
|
-
stream.push({ type: "agent_start" });
|
|
9019
|
-
stream.push({ type: "turn_start" });
|
|
9020
|
-
for (const prompt of prompts) {
|
|
9021
|
-
stream.push({ type: "message_start", message: prompt });
|
|
9022
|
-
stream.push({ type: "message_end", message: prompt });
|
|
9023
|
-
}
|
|
9024
9046
|
try {
|
|
9025
|
-
|
|
9047
|
+
try {
|
|
9048
|
+
await config.hooks?.beforeAgentStart?.();
|
|
9049
|
+
} catch (e) {
|
|
9050
|
+
console.warn("[AgentLoop] beforeAgentStart hook failed:", e);
|
|
9051
|
+
}
|
|
9052
|
+
const currentContext = {
|
|
9053
|
+
...context,
|
|
9054
|
+
messages: [...context.messages, ...prompts]
|
|
9055
|
+
};
|
|
9056
|
+
stream.push({ type: "agent_start" });
|
|
9057
|
+
stream.push({ type: "turn_start" });
|
|
9058
|
+
for (const prompt of prompts) {
|
|
9059
|
+
stream.push({ type: "message_start", message: prompt });
|
|
9060
|
+
stream.push({ type: "message_end", message: prompt });
|
|
9061
|
+
}
|
|
9062
|
+
try {
|
|
9063
|
+
await runLoop(currentContext, newMessages, config, signal, stream, streamFn);
|
|
9064
|
+
} catch (error) {
|
|
9065
|
+
await notifyOnError(config, error, "runLoop");
|
|
9066
|
+
endStreamWithError(stream, newMessages, config, signal, error);
|
|
9067
|
+
return;
|
|
9068
|
+
}
|
|
9069
|
+
try {
|
|
9070
|
+
await config.hooks?.afterAgentEnd?.(newMessages);
|
|
9071
|
+
} catch (e) {
|
|
9072
|
+
console.warn("[AgentLoop] afterAgentEnd hook failed:", e);
|
|
9073
|
+
}
|
|
9026
9074
|
} catch (error) {
|
|
9027
|
-
config
|
|
9028
|
-
|
|
9029
|
-
}
|
|
9030
|
-
try {
|
|
9031
|
-
await config.hooks?.afterAgentEnd?.(newMessages);
|
|
9032
|
-
} catch (e) {
|
|
9033
|
-
console.warn("[AgentLoop] afterAgentEnd hook failed:", e);
|
|
9075
|
+
await notifyOnError(config, error, "agentLoop");
|
|
9076
|
+
endStreamWithError(stream, newMessages, config, signal, error);
|
|
9034
9077
|
}
|
|
9035
9078
|
})();
|
|
9036
9079
|
return stream;
|
|
@@ -9044,25 +9087,31 @@ function agentLoopContinue(context, config, signal, streamFn) {
|
|
|
9044
9087
|
}
|
|
9045
9088
|
const stream = createAgentStream();
|
|
9046
9089
|
(async () => {
|
|
9047
|
-
try {
|
|
9048
|
-
await config.hooks?.beforeAgentStart?.();
|
|
9049
|
-
} catch (e) {
|
|
9050
|
-
console.warn("[AgentLoop] beforeAgentStart hook failed:", e);
|
|
9051
|
-
}
|
|
9052
9090
|
const newMessages = [];
|
|
9053
|
-
const currentContext = { ...context };
|
|
9054
|
-
stream.push({ type: "agent_start" });
|
|
9055
|
-
stream.push({ type: "turn_start" });
|
|
9056
9091
|
try {
|
|
9057
|
-
|
|
9092
|
+
try {
|
|
9093
|
+
await config.hooks?.beforeAgentStart?.();
|
|
9094
|
+
} catch (e) {
|
|
9095
|
+
console.warn("[AgentLoop] beforeAgentStart hook failed:", e);
|
|
9096
|
+
}
|
|
9097
|
+
const currentContext = { ...context };
|
|
9098
|
+
stream.push({ type: "agent_start" });
|
|
9099
|
+
stream.push({ type: "turn_start" });
|
|
9100
|
+
try {
|
|
9101
|
+
await runLoop(currentContext, newMessages, config, signal, stream, streamFn);
|
|
9102
|
+
} catch (error) {
|
|
9103
|
+
await notifyOnError(config, error, "runLoop");
|
|
9104
|
+
endStreamWithError(stream, newMessages, config, signal, error);
|
|
9105
|
+
return;
|
|
9106
|
+
}
|
|
9107
|
+
try {
|
|
9108
|
+
await config.hooks?.afterAgentEnd?.(newMessages);
|
|
9109
|
+
} catch (e) {
|
|
9110
|
+
console.warn("[AgentLoop] afterAgentEnd hook failed:", e);
|
|
9111
|
+
}
|
|
9058
9112
|
} catch (error) {
|
|
9059
|
-
config
|
|
9060
|
-
|
|
9061
|
-
}
|
|
9062
|
-
try {
|
|
9063
|
-
await config.hooks?.afterAgentEnd?.(newMessages);
|
|
9064
|
-
} catch (e) {
|
|
9065
|
-
console.warn("[AgentLoop] afterAgentEnd hook failed:", e);
|
|
9113
|
+
await notifyOnError(config, error, "agentLoopContinue");
|
|
9114
|
+
endStreamWithError(stream, newMessages, config, signal, error);
|
|
9066
9115
|
}
|
|
9067
9116
|
})();
|
|
9068
9117
|
return stream;
|
|
@@ -9098,7 +9147,7 @@ async function runLoop(currentContext, newMessages, config, signal, stream, stre
|
|
|
9098
9147
|
try {
|
|
9099
9148
|
message = await streamAssistantResponse(currentContext, config, signal, stream, streamFn);
|
|
9100
9149
|
} catch (error) {
|
|
9101
|
-
config
|
|
9150
|
+
await notifyOnError(config, error, "streamAssistantResponse");
|
|
9102
9151
|
throw error;
|
|
9103
9152
|
}
|
|
9104
9153
|
newMessages.push(message);
|
|
@@ -9274,10 +9323,14 @@ async function executeToolCalls(tools, assistantMessage, signal, stream, getStee
|
|
|
9274
9323
|
details: {}
|
|
9275
9324
|
};
|
|
9276
9325
|
isError = true;
|
|
9277
|
-
|
|
9278
|
-
|
|
9279
|
-
|
|
9280
|
-
|
|
9326
|
+
try {
|
|
9327
|
+
await hooks?.onError?.(e instanceof Error ? e : new Error(String(e)), {
|
|
9328
|
+
toolName: toolCall.name,
|
|
9329
|
+
phase: "toolExecution"
|
|
9330
|
+
});
|
|
9331
|
+
} catch (hookError) {
|
|
9332
|
+
console.warn(`[AgentLoop] onError hook failed during toolExecution for ${toolCall.name}:`, hookError);
|
|
9333
|
+
}
|
|
9281
9334
|
}
|
|
9282
9335
|
}
|
|
9283
9336
|
try {
|
|
@@ -9789,15 +9842,30 @@ var Agent = class {
|
|
|
9789
9842
|
this.abortController = void 0;
|
|
9790
9843
|
}
|
|
9791
9844
|
}
|
|
9845
|
+
reportObserverError(kind, eventType, error) {
|
|
9846
|
+
console.warn(`[Agent] ${kind} failed while handling ${eventType}:`, error);
|
|
9847
|
+
}
|
|
9792
9848
|
emit(e) {
|
|
9793
9849
|
for (const listener of this.listeners) {
|
|
9794
|
-
|
|
9850
|
+
try {
|
|
9851
|
+
listener(e);
|
|
9852
|
+
} catch (error) {
|
|
9853
|
+
this.reportObserverError("agent event listener", e.type, error);
|
|
9854
|
+
}
|
|
9855
|
+
}
|
|
9856
|
+
try {
|
|
9857
|
+
this.emitDerivedSemanticEvents(e);
|
|
9858
|
+
} catch (error) {
|
|
9859
|
+
this.reportObserverError("derived semantic event", e.type, error);
|
|
9795
9860
|
}
|
|
9796
|
-
this.emitDerivedSemanticEvents(e);
|
|
9797
9861
|
}
|
|
9798
9862
|
emitSemantic(e) {
|
|
9799
9863
|
for (const listener of this.semanticListeners) {
|
|
9800
|
-
|
|
9864
|
+
try {
|
|
9865
|
+
listener(e);
|
|
9866
|
+
} catch (error) {
|
|
9867
|
+
this.reportObserverError("semantic event listener", e.type, error);
|
|
9868
|
+
}
|
|
9801
9869
|
}
|
|
9802
9870
|
}
|
|
9803
9871
|
updateStatusSnapshot(next) {
|
package/dist/cli.js
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
getSettingsPath,
|
|
15
15
|
getThemesDir,
|
|
16
16
|
migrateConfigFromAgentDir
|
|
17
|
-
} from "./chunks/chunk-
|
|
17
|
+
} from "./chunks/chunk-GNHANWYT.js";
|
|
18
18
|
import {
|
|
19
19
|
AGENTS_CONTEXT_FILE_NAME,
|
|
20
20
|
AgentSessionController,
|
|
@@ -52,7 +52,7 @@ import {
|
|
|
52
52
|
selectToolsForRuntimePolicy,
|
|
53
53
|
shouldPreserveExecutionStateForUserText,
|
|
54
54
|
supersedeExecutionState
|
|
55
|
-
} from "./chunks/chunk-
|
|
55
|
+
} from "./chunks/chunk-H6PTIABA.js";
|
|
56
56
|
import {
|
|
57
57
|
Deref,
|
|
58
58
|
Errors,
|
|
@@ -86,7 +86,7 @@ import {
|
|
|
86
86
|
setLogger,
|
|
87
87
|
sortToolModelCandidatesByCapability,
|
|
88
88
|
type_exports
|
|
89
|
-
} from "./chunks/chunk-
|
|
89
|
+
} from "./chunks/chunk-QACYLY3B.js";
|
|
90
90
|
import {
|
|
91
91
|
resolveCliProjectRoot
|
|
92
92
|
} from "./chunks/chunk-NTYHFBUA.js";
|
|
@@ -56031,6 +56031,27 @@ var ExecutionStateManager = class {
|
|
|
56031
56031
|
// src/session-trace.ts
|
|
56032
56032
|
import * as fs15 from "node:fs";
|
|
56033
56033
|
import * as path16 from "node:path";
|
|
56034
|
+
function saveTraceFileBestEffort(tracePath, content) {
|
|
56035
|
+
const tempPath = `${tracePath}.${process.pid}.${Date.now()}.tmp`;
|
|
56036
|
+
try {
|
|
56037
|
+
fs15.writeFileSync(tempPath, content, "utf8");
|
|
56038
|
+
try {
|
|
56039
|
+
fs15.renameSync(tempPath, tracePath);
|
|
56040
|
+
return;
|
|
56041
|
+
} catch {
|
|
56042
|
+
try {
|
|
56043
|
+
fs15.copyFileSync(tempPath, tracePath);
|
|
56044
|
+
} catch {
|
|
56045
|
+
} finally {
|
|
56046
|
+
try {
|
|
56047
|
+
fs15.unlinkSync(tempPath);
|
|
56048
|
+
} catch {
|
|
56049
|
+
}
|
|
56050
|
+
}
|
|
56051
|
+
}
|
|
56052
|
+
} catch {
|
|
56053
|
+
}
|
|
56054
|
+
}
|
|
56034
56055
|
var SessionTraceWriter = class extends SessionTraceSnapshotWriter {
|
|
56035
56056
|
constructor(sessionsDir, sessionManager) {
|
|
56036
56057
|
super({
|
|
@@ -56046,9 +56067,7 @@ var SessionTraceWriter = class extends SessionTraceSnapshotWriter {
|
|
|
56046
56067
|
},
|
|
56047
56068
|
saveTrace: (trace) => {
|
|
56048
56069
|
const tracePath = path16.join(sessionsDir, `${trace.sessionId}.trace.json`);
|
|
56049
|
-
|
|
56050
|
-
fs15.writeFileSync(tempPath, JSON.stringify(trace, null, 2), "utf8");
|
|
56051
|
-
fs15.renameSync(tempPath, tracePath);
|
|
56070
|
+
saveTraceFileBestEffort(tracePath, JSON.stringify(trace, null, 2));
|
|
56052
56071
|
}
|
|
56053
56072
|
});
|
|
56054
56073
|
this.sessionsDir = sessionsDir;
|
|
@@ -63658,16 +63677,27 @@ function selectToolsForRuntimeMode(tools, mode) {
|
|
|
63658
63677
|
}
|
|
63659
63678
|
|
|
63660
63679
|
// src/input/direct-bash.ts
|
|
63680
|
+
function buildDirectShellCommand(command) {
|
|
63681
|
+
if (process.platform === "win32") {
|
|
63682
|
+
return {
|
|
63683
|
+
file: "powershell.exe",
|
|
63684
|
+
args: ["-NoProfile", "-NonInteractive", "-Command", command],
|
|
63685
|
+
prompt: "PS>"
|
|
63686
|
+
};
|
|
63687
|
+
}
|
|
63688
|
+
return { file: "bash", args: ["-lc", command], prompt: "$" };
|
|
63689
|
+
}
|
|
63661
63690
|
async function handleDirectBash(host, command) {
|
|
63662
63691
|
host.chatContainer.addChild(new Spacer(1));
|
|
63663
|
-
|
|
63692
|
+
const shellCommand = buildDirectShellCommand(command);
|
|
63693
|
+
host.chatContainer.addChild(new Text(theme.fg("accent", `${shellCommand.prompt} ${command}`), 1, 0));
|
|
63664
63694
|
host.editor.setText("");
|
|
63665
63695
|
const outputContainer = new Container();
|
|
63666
63696
|
outputContainer.addChild(new Spacer(1));
|
|
63667
63697
|
host.chatContainer.addChild(outputContainer);
|
|
63668
63698
|
host.ui.requestRender();
|
|
63669
63699
|
const { spawn: spawn2 } = await import("child_process");
|
|
63670
|
-
const child = spawn2(
|
|
63700
|
+
const child = spawn2(shellCommand.file, shellCommand.args, {
|
|
63671
63701
|
cwd: process.cwd(),
|
|
63672
63702
|
env: process.env
|
|
63673
63703
|
});
|
|
@@ -63692,14 +63722,24 @@ async function handleDirectBash(host, command) {
|
|
|
63692
63722
|
host.ui.requestRender();
|
|
63693
63723
|
});
|
|
63694
63724
|
return new Promise((resolve4) => {
|
|
63695
|
-
|
|
63725
|
+
let settled = false;
|
|
63726
|
+
const finish = (code) => {
|
|
63727
|
+
if (settled) return;
|
|
63728
|
+
settled = true;
|
|
63696
63729
|
if (code !== 0) {
|
|
63697
63730
|
outputContainer.addChild(new Spacer(1));
|
|
63698
|
-
outputContainer.addChild(new Text(theme.fg("error", `[exit ${code}]`), 1, 0));
|
|
63731
|
+
outputContainer.addChild(new Text(theme.fg("error", `[exit ${code ?? "spawn error"}]`), 1, 0));
|
|
63699
63732
|
}
|
|
63700
63733
|
host.chatContainer.addChild(new Spacer(1));
|
|
63701
63734
|
host.ui.requestRender();
|
|
63702
63735
|
resolve4();
|
|
63736
|
+
};
|
|
63737
|
+
child.on("error", (error) => {
|
|
63738
|
+
outputContainer.addChild(new Text(theme.fg("error", error.message), 1, 0));
|
|
63739
|
+
finish(null);
|
|
63740
|
+
});
|
|
63741
|
+
child.on("close", (code) => {
|
|
63742
|
+
finish(code);
|
|
63703
63743
|
});
|
|
63704
63744
|
});
|
|
63705
63745
|
}
|
|
@@ -65307,7 +65347,7 @@ var InteractiveMode = class {
|
|
|
65307
65347
|
if (savedLevel) {
|
|
65308
65348
|
this.thinkingLevel = savedLevel;
|
|
65309
65349
|
}
|
|
65310
|
-
const { Agent } = await import("./chunks/src-
|
|
65350
|
+
const { Agent } = await import("./chunks/src-M32UEGIU.js");
|
|
65311
65351
|
const activeSession = this.sessionManager.getActiveSession();
|
|
65312
65352
|
this.agent = new Agent({
|
|
65313
65353
|
initialState: {
|
|
@@ -67300,7 +67340,7 @@ async function startChat(initialPrompt, testCommand) {
|
|
|
67300
67340
|
`);
|
|
67301
67341
|
console.log("Assistant: ");
|
|
67302
67342
|
}
|
|
67303
|
-
const { Agent } = await import("./chunks/src-
|
|
67343
|
+
const { Agent } = await import("./chunks/src-M32UEGIU.js");
|
|
67304
67344
|
let agent;
|
|
67305
67345
|
const printModeExtensions = await loadPrintModeExtensions({
|
|
67306
67346
|
cwd,
|