@opencow-ai/opencow-agent-sdk 0.4.18 → 0.4.20
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/capabilities/tools/AgentTool/AgentTool.d.ts +49 -4
- package/dist/capabilities/tools/AgentTool/agentInvocationDedupe.d.ts +7 -0
- package/dist/capabilities/tools/AgentTool/agentLifecycleFinalizer.d.ts +3 -0
- package/dist/capabilities/tools/AgentTool/inputSchema.d.ts +36 -0
- package/dist/capabilities/tools/AgentTool/worktreeIsolation.d.ts +4 -0
- package/dist/capabilities/worktree.d.ts +10 -0
- package/dist/capabilities/worktreeAvailability.d.ts +20 -0
- package/dist/cli.mjs +1189 -716
- package/dist/client.d.ts +3 -2
- package/dist/client.js +1047 -483
- package/dist/entrypoints/sdk/runtimeTypes.d.ts +5 -7
- package/dist/lib/errors.d.ts +8 -0
- package/dist/sdk.js +1047 -483
- package/dist/session/backgroundAbortRegistry.d.ts +15 -7
- package/dist/session/backgroundTaskScope.d.ts +29 -0
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -31323,7 +31323,7 @@ function isFsInaccessible(e) {
|
|
|
31323
31323
|
const code = getErrnoCode(e);
|
|
31324
31324
|
return code === "ENOENT" || code === "EACCES" || code === "EPERM" || code === "ENOTDIR" || code === "ELOOP";
|
|
31325
31325
|
}
|
|
31326
|
-
var ClaudeError, MalformedCommandError, AbortError, ConfigParseError, ShellError, TelemetrySafeError_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS;
|
|
31326
|
+
var ClaudeError, MalformedCommandError, AbortError, ToolContinuationStopError, ConfigParseError, ShellError, TelemetrySafeError_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS;
|
|
31327
31327
|
var init_errors5 = __esm(() => {
|
|
31328
31328
|
init_canonical();
|
|
31329
31329
|
ClaudeError = class ClaudeError extends Error {
|
|
@@ -31340,6 +31340,12 @@ var init_errors5 = __esm(() => {
|
|
|
31340
31340
|
this.name = "AbortError";
|
|
31341
31341
|
}
|
|
31342
31342
|
};
|
|
31343
|
+
ToolContinuationStopError = class ToolContinuationStopError extends Error {
|
|
31344
|
+
constructor(message, options) {
|
|
31345
|
+
super(message, options);
|
|
31346
|
+
this.name = "ToolContinuationStopError";
|
|
31347
|
+
}
|
|
31348
|
+
};
|
|
31343
31349
|
ConfigParseError = class ConfigParseError extends Error {
|
|
31344
31350
|
filePath;
|
|
31345
31351
|
defaultConfig;
|
|
@@ -46083,6 +46089,21 @@ var init_which = __esm(() => {
|
|
|
46083
46089
|
// src/capabilities/git.ts
|
|
46084
46090
|
import { readFileSync as readFileSync5, realpathSync as realpathSync2, statSync as statSync4 } from "fs";
|
|
46085
46091
|
import { basename as basename3, dirname as dirname7, join as join12, resolve as resolve6, sep as sep4 } from "path";
|
|
46092
|
+
function hasValidGitMarker(gitPath) {
|
|
46093
|
+
const markerStat = statSync4(gitPath);
|
|
46094
|
+
if (markerStat.isDirectory()) {
|
|
46095
|
+
return statSync4(join12(gitPath, "HEAD")).isFile();
|
|
46096
|
+
}
|
|
46097
|
+
if (!markerStat.isFile()) {
|
|
46098
|
+
return false;
|
|
46099
|
+
}
|
|
46100
|
+
const marker = readFileSync5(gitPath, "utf-8").trim();
|
|
46101
|
+
if (!marker.startsWith("gitdir:")) {
|
|
46102
|
+
return false;
|
|
46103
|
+
}
|
|
46104
|
+
const gitDir = resolve6(dirname7(gitPath), marker.slice("gitdir:".length).trim());
|
|
46105
|
+
return statSync4(join12(gitDir, "HEAD")).isFile();
|
|
46106
|
+
}
|
|
46086
46107
|
function createFindGitRoot() {
|
|
46087
46108
|
function wrapper(startPath) {
|
|
46088
46109
|
const result = findGitRootImpl(startPath);
|
|
@@ -46167,8 +46188,7 @@ var init_git = __esm(() => {
|
|
|
46167
46188
|
try {
|
|
46168
46189
|
const gitPath = join12(current, ".git");
|
|
46169
46190
|
statCount++;
|
|
46170
|
-
|
|
46171
|
-
if (stat4.isDirectory() || stat4.isFile()) {
|
|
46191
|
+
if (hasValidGitMarker(gitPath)) {
|
|
46172
46192
|
logForDiagnosticsNoPII("info", "find_git_root_completed", {
|
|
46173
46193
|
duration_ms: Date.now() - startTime,
|
|
46174
46194
|
stat_count: statCount,
|
|
@@ -46186,8 +46206,7 @@ var init_git = __esm(() => {
|
|
|
46186
46206
|
try {
|
|
46187
46207
|
const gitPath = join12(root2, ".git");
|
|
46188
46208
|
statCount++;
|
|
46189
|
-
|
|
46190
|
-
if (stat4.isDirectory() || stat4.isFile()) {
|
|
46209
|
+
if (hasValidGitMarker(gitPath)) {
|
|
46191
46210
|
logForDiagnosticsNoPII("info", "find_git_root_completed", {
|
|
46192
46211
|
duration_ms: Date.now() - startTime,
|
|
46193
46212
|
stat_count: statCount,
|
|
@@ -234734,18 +234753,74 @@ var init_registerFrontmatterHooks = __esm(() => {
|
|
|
234734
234753
|
});
|
|
234735
234754
|
|
|
234736
234755
|
// src/session/backgroundAbortRegistry.ts
|
|
234737
|
-
function registerBackgroundAgentAbort(agentId,
|
|
234738
|
-
runs.
|
|
234756
|
+
function registerBackgroundAgentAbort(agentId, actions) {
|
|
234757
|
+
if (runs.has(agentId)) {
|
|
234758
|
+
throw new Error(`Background agent '${agentId}' is already registered`);
|
|
234759
|
+
}
|
|
234760
|
+
let resolveSettled = () => {};
|
|
234761
|
+
const settled = new Promise((resolve15) => {
|
|
234762
|
+
resolveSettled = resolve15;
|
|
234763
|
+
});
|
|
234764
|
+
runs.set(agentId, {
|
|
234765
|
+
...actions,
|
|
234766
|
+
stopFired: false,
|
|
234767
|
+
stopPromise: undefined,
|
|
234768
|
+
settled,
|
|
234769
|
+
resolveSettled,
|
|
234770
|
+
shellsStopped: false
|
|
234771
|
+
});
|
|
234739
234772
|
}
|
|
234740
234773
|
function unregisterBackgroundAgentAbort(agentId) {
|
|
234774
|
+
const run = runs.get(agentId);
|
|
234775
|
+
if (!run)
|
|
234776
|
+
return;
|
|
234741
234777
|
runs.delete(agentId);
|
|
234778
|
+
run.resolveSettled();
|
|
234742
234779
|
}
|
|
234743
234780
|
function abortBackgroundAgentById(agentId) {
|
|
234744
234781
|
const run = runs.get(agentId);
|
|
234745
234782
|
if (!run)
|
|
234746
|
-
return
|
|
234747
|
-
run.
|
|
234748
|
-
|
|
234783
|
+
return Promise.resolve();
|
|
234784
|
+
if (!run.stopPromise) {
|
|
234785
|
+
run.stopPromise = (async () => {
|
|
234786
|
+
const errors4 = [];
|
|
234787
|
+
let abortFailed = false;
|
|
234788
|
+
try {
|
|
234789
|
+
run.abort();
|
|
234790
|
+
} catch (error41) {
|
|
234791
|
+
abortFailed = true;
|
|
234792
|
+
errors4.push(error41);
|
|
234793
|
+
}
|
|
234794
|
+
try {
|
|
234795
|
+
stopBackgroundAgentShells(run);
|
|
234796
|
+
} catch (error41) {
|
|
234797
|
+
errors4.push(error41);
|
|
234798
|
+
}
|
|
234799
|
+
if (abortFailed) {
|
|
234800
|
+
throw new AggregateError(errors4, `Failed to stop background agent '${agentId}'`);
|
|
234801
|
+
}
|
|
234802
|
+
await run.settled;
|
|
234803
|
+
if (errors4.length > 0) {
|
|
234804
|
+
throw new AggregateError(errors4, `Failed to stop background agent '${agentId}'`);
|
|
234805
|
+
}
|
|
234806
|
+
})();
|
|
234807
|
+
}
|
|
234808
|
+
return run.stopPromise;
|
|
234809
|
+
}
|
|
234810
|
+
function hasBackgroundAgent(agentId) {
|
|
234811
|
+
return runs.has(agentId);
|
|
234812
|
+
}
|
|
234813
|
+
function stopBackgroundAgentShellsById(agentId) {
|
|
234814
|
+
const run = runs.get(agentId);
|
|
234815
|
+
if (run) {
|
|
234816
|
+
stopBackgroundAgentShells(run);
|
|
234817
|
+
}
|
|
234818
|
+
}
|
|
234819
|
+
function stopBackgroundAgentShells(run) {
|
|
234820
|
+
if (run.shellsStopped)
|
|
234821
|
+
return;
|
|
234822
|
+
run.shellsStopped = true;
|
|
234823
|
+
run.stopShells();
|
|
234749
234824
|
}
|
|
234750
234825
|
function markSubagentStopFired(agentId) {
|
|
234751
234826
|
const run = runs.get(agentId);
|
|
@@ -235703,6 +235778,23 @@ var init_formatting = __esm(() => {
|
|
|
235703
235778
|
init_xml();
|
|
235704
235779
|
});
|
|
235705
235780
|
|
|
235781
|
+
// src/capabilities/tools/AgentTool/agentLifecycleFinalizer.ts
|
|
235782
|
+
function createAgentLifecycleFinalizer(onCleanupError) {
|
|
235783
|
+
let finalization;
|
|
235784
|
+
return (cleanups) => {
|
|
235785
|
+
finalization ??= (async () => {
|
|
235786
|
+
for (const cleanup of cleanups) {
|
|
235787
|
+
try {
|
|
235788
|
+
await cleanup();
|
|
235789
|
+
} catch (error41) {
|
|
235790
|
+
onCleanupError(error41);
|
|
235791
|
+
}
|
|
235792
|
+
}
|
|
235793
|
+
})();
|
|
235794
|
+
return finalization;
|
|
235795
|
+
};
|
|
235796
|
+
}
|
|
235797
|
+
|
|
235706
235798
|
// src/capabilities/tools/AgentTool/runAgent.ts
|
|
235707
235799
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
235708
235800
|
async function initializeAgentMcpServers(agentDefinition, parentClients) {
|
|
@@ -235725,44 +235817,6 @@ async function initializeAgentMcpServers(agentDefinition, parentClients) {
|
|
|
235725
235817
|
const agentClients = [];
|
|
235726
235818
|
const newlyCreatedClients = [];
|
|
235727
235819
|
const agentTools = [];
|
|
235728
|
-
for (const spec of agentDefinition.mcpServers) {
|
|
235729
|
-
let config2 = null;
|
|
235730
|
-
let name;
|
|
235731
|
-
let isNewlyCreated = false;
|
|
235732
|
-
if (typeof spec === "string") {
|
|
235733
|
-
name = spec;
|
|
235734
|
-
config2 = getMcpConfigByName(spec);
|
|
235735
|
-
if (!config2) {
|
|
235736
|
-
logForDebugging(`[Agent: ${agentDefinition.agentType}] MCP server not found: ${spec}`, { level: "warn" });
|
|
235737
|
-
continue;
|
|
235738
|
-
}
|
|
235739
|
-
} else {
|
|
235740
|
-
const entries = Object.entries(spec);
|
|
235741
|
-
if (entries.length !== 1) {
|
|
235742
|
-
logForDebugging(`[Agent: ${agentDefinition.agentType}] Invalid MCP server spec: expected exactly one key`, { level: "warn" });
|
|
235743
|
-
continue;
|
|
235744
|
-
}
|
|
235745
|
-
const [serverName, serverConfig] = entries[0];
|
|
235746
|
-
name = serverName;
|
|
235747
|
-
config2 = {
|
|
235748
|
-
...serverConfig,
|
|
235749
|
-
scope: "dynamic"
|
|
235750
|
-
};
|
|
235751
|
-
isNewlyCreated = true;
|
|
235752
|
-
}
|
|
235753
|
-
const client = await connectToServer(name, config2);
|
|
235754
|
-
agentClients.push(client);
|
|
235755
|
-
if (isNewlyCreated) {
|
|
235756
|
-
newlyCreatedClients.push(client);
|
|
235757
|
-
}
|
|
235758
|
-
if (client.type === "connected") {
|
|
235759
|
-
const tools = await fetchToolsForClient(client);
|
|
235760
|
-
agentTools.push(...tools);
|
|
235761
|
-
logForDebugging(`[Agent: ${agentDefinition.agentType}] Connected to MCP server '${name}' with ${tools.length} tools`);
|
|
235762
|
-
} else {
|
|
235763
|
-
logForDebugging(`[Agent: ${agentDefinition.agentType}] Failed to connect to MCP server '${name}': ${client.type}`, { level: "warn" });
|
|
235764
|
-
}
|
|
235765
|
-
}
|
|
235766
235820
|
const cleanup = async () => {
|
|
235767
235821
|
for (const client of newlyCreatedClients) {
|
|
235768
235822
|
if (client.type === "connected") {
|
|
@@ -235774,6 +235828,49 @@ async function initializeAgentMcpServers(agentDefinition, parentClients) {
|
|
|
235774
235828
|
}
|
|
235775
235829
|
}
|
|
235776
235830
|
};
|
|
235831
|
+
try {
|
|
235832
|
+
for (const spec of agentDefinition.mcpServers) {
|
|
235833
|
+
let config2 = null;
|
|
235834
|
+
let name;
|
|
235835
|
+
let isNewlyCreated = false;
|
|
235836
|
+
if (typeof spec === "string") {
|
|
235837
|
+
name = spec;
|
|
235838
|
+
config2 = getMcpConfigByName(spec);
|
|
235839
|
+
if (!config2) {
|
|
235840
|
+
logForDebugging(`[Agent: ${agentDefinition.agentType}] MCP server not found: ${spec}`, { level: "warn" });
|
|
235841
|
+
continue;
|
|
235842
|
+
}
|
|
235843
|
+
} else {
|
|
235844
|
+
const entries = Object.entries(spec);
|
|
235845
|
+
if (entries.length !== 1) {
|
|
235846
|
+
logForDebugging(`[Agent: ${agentDefinition.agentType}] Invalid MCP server spec: expected exactly one key`, { level: "warn" });
|
|
235847
|
+
continue;
|
|
235848
|
+
}
|
|
235849
|
+
const [serverName, serverConfig] = entries[0];
|
|
235850
|
+
name = serverName;
|
|
235851
|
+
config2 = {
|
|
235852
|
+
...serverConfig,
|
|
235853
|
+
scope: "dynamic"
|
|
235854
|
+
};
|
|
235855
|
+
isNewlyCreated = true;
|
|
235856
|
+
}
|
|
235857
|
+
const client = await connectToServer(name, config2);
|
|
235858
|
+
agentClients.push(client);
|
|
235859
|
+
if (isNewlyCreated) {
|
|
235860
|
+
newlyCreatedClients.push(client);
|
|
235861
|
+
}
|
|
235862
|
+
if (client.type === "connected") {
|
|
235863
|
+
const tools = await fetchToolsForClient(client);
|
|
235864
|
+
agentTools.push(...tools);
|
|
235865
|
+
logForDebugging(`[Agent: ${agentDefinition.agentType}] Connected to MCP server '${name}' with ${tools.length} tools`);
|
|
235866
|
+
} else {
|
|
235867
|
+
logForDebugging(`[Agent: ${agentDefinition.agentType}] Failed to connect to MCP server '${name}': ${client.type}`, { level: "warn" });
|
|
235868
|
+
}
|
|
235869
|
+
}
|
|
235870
|
+
} catch (error41) {
|
|
235871
|
+
await cleanup();
|
|
235872
|
+
throw error41;
|
|
235873
|
+
}
|
|
235777
235874
|
return {
|
|
235778
235875
|
clients: [...parentClients, ...agentClients],
|
|
235779
235876
|
tools: agentTools,
|
|
@@ -235926,121 +236023,140 @@ async function* runAgent({
|
|
|
235926
236023
|
const additionalWorkingDirectories = Array.from(appState.toolPermissionContext.additionalWorkingDirectories.keys());
|
|
235927
236024
|
const agentSystemPrompt = override?.systemPrompt ? override.systemPrompt : asSystemPrompt(await getAgentSystemPrompt(agentDefinition, toolUseContext, resolvedAgentModel, additionalWorkingDirectories, resolvedTools));
|
|
235928
236025
|
const agentAbortController = override?.abortController ? override.abortController : isAsync2 ? new AbortController : toolUseContext.abortController;
|
|
236026
|
+
const stopOwnedShells = () => {
|
|
236027
|
+
killShellTasksForAgent(agentId, toolUseContext.getAppState, rootSetAppState);
|
|
236028
|
+
};
|
|
235929
236029
|
if (isAsync2) {
|
|
235930
|
-
registerBackgroundAgentAbort(agentId,
|
|
235931
|
-
|
|
235932
|
-
|
|
235933
|
-
|
|
235934
|
-
|
|
235935
|
-
|
|
235936
|
-
|
|
236030
|
+
registerBackgroundAgentAbort(agentId, {
|
|
236031
|
+
abort: () => {
|
|
236032
|
+
killAsyncAgent(agentId, rootSetAppState);
|
|
236033
|
+
if (!agentAbortController.signal.aborted) {
|
|
236034
|
+
agentAbortController.abort();
|
|
236035
|
+
}
|
|
236036
|
+
},
|
|
236037
|
+
stopShells: stopOwnedShells
|
|
236038
|
+
});
|
|
235937
236039
|
}
|
|
235938
|
-
|
|
235939
|
-
|
|
235940
|
-
|
|
235941
|
-
|
|
235942
|
-
|
|
235943
|
-
|
|
235944
|
-
|
|
236040
|
+
let agentToolRuntimeContext;
|
|
236041
|
+
let mcpCleanup = async () => {};
|
|
236042
|
+
let lastAssistantForFallback = null;
|
|
236043
|
+
let agentRunError;
|
|
236044
|
+
const finalizeLifecycle = createAgentLifecycleFinalizer((error41) => {
|
|
236045
|
+
logForDebugging(`Agent ${agentId} cleanup failed: ${error41}`, {
|
|
236046
|
+
level: "warn"
|
|
235945
236047
|
});
|
|
235946
|
-
|
|
235947
|
-
|
|
235948
|
-
|
|
235949
|
-
|
|
235950
|
-
|
|
235951
|
-
|
|
235952
|
-
const skillsToPreload = agentDefinition.skills ?? [];
|
|
235953
|
-
if (skillsToPreload.length > 0) {
|
|
235954
|
-
const allSkills = await getSkillToolCommands(getProjectRoot());
|
|
235955
|
-
const validSkills = [];
|
|
235956
|
-
for (const skillName of skillsToPreload) {
|
|
235957
|
-
const resolvedName = resolveSkillName(skillName, allSkills, agentDefinition);
|
|
235958
|
-
if (!resolvedName) {
|
|
235959
|
-
logForDebugging(`[Agent: ${agentDefinition.agentType}] Warning: Skill '${skillName}' specified in frontmatter was not found`, { level: "warn" });
|
|
235960
|
-
continue;
|
|
235961
|
-
}
|
|
235962
|
-
const skill = getCommand(resolvedName, allSkills);
|
|
235963
|
-
if (skill.type !== "prompt") {
|
|
235964
|
-
logForDebugging(`[Agent: ${agentDefinition.agentType}] Warning: Skill '${skillName}' is not a prompt-based skill`, { level: "warn" });
|
|
235965
|
-
continue;
|
|
236048
|
+
});
|
|
236049
|
+
try {
|
|
236050
|
+
const additionalContexts = [];
|
|
236051
|
+
for await (const hookResult of executeSubagentStartHooks(agentId, agentDefinition.agentType, agentAbortController.signal, undefined, toolUseContext.toolUseId, isAsync2)) {
|
|
236052
|
+
if (hookResult.additionalContexts && hookResult.additionalContexts.length > 0) {
|
|
236053
|
+
additionalContexts.push(...hookResult.additionalContexts);
|
|
235966
236054
|
}
|
|
235967
|
-
validSkills.push({ skillName, skill });
|
|
235968
236055
|
}
|
|
235969
|
-
|
|
235970
|
-
|
|
235971
|
-
|
|
235972
|
-
|
|
235973
|
-
|
|
235974
|
-
|
|
235975
|
-
|
|
235976
|
-
|
|
235977
|
-
initialMessages.push(
|
|
235978
|
-
|
|
235979
|
-
|
|
235980
|
-
|
|
236056
|
+
if (additionalContexts.length > 0) {
|
|
236057
|
+
const contextMessage = createAttachmentMessage({
|
|
236058
|
+
type: "hook_additional_context",
|
|
236059
|
+
content: additionalContexts,
|
|
236060
|
+
hookName: "SubagentStart",
|
|
236061
|
+
toolUseID: randomUUID6(),
|
|
236062
|
+
hookEvent: "SubagentStart"
|
|
236063
|
+
});
|
|
236064
|
+
initialMessages.push(contextMessage);
|
|
236065
|
+
}
|
|
236066
|
+
const hooksAllowedForThisAgent = !isRestrictedToPluginOnly("hooks") || isSourceAdminTrusted(agentDefinition.source);
|
|
236067
|
+
if (agentDefinition.hooks && hooksAllowedForThisAgent) {
|
|
236068
|
+
registerFrontmatterHooks(rootSetAppState, agentId, agentDefinition.hooks, `agent '${agentDefinition.agentType}'`, true);
|
|
236069
|
+
}
|
|
236070
|
+
const skillsToPreload = agentDefinition.skills ?? [];
|
|
236071
|
+
if (skillsToPreload.length > 0) {
|
|
236072
|
+
const allSkills = await getSkillToolCommands(getProjectRoot());
|
|
236073
|
+
const validSkills = [];
|
|
236074
|
+
for (const skillName of skillsToPreload) {
|
|
236075
|
+
const resolvedName = resolveSkillName(skillName, allSkills, agentDefinition);
|
|
236076
|
+
if (!resolvedName) {
|
|
236077
|
+
logForDebugging(`[Agent: ${agentDefinition.agentType}] Warning: Skill '${skillName}' specified in frontmatter was not found`, { level: "warn" });
|
|
236078
|
+
continue;
|
|
236079
|
+
}
|
|
236080
|
+
const skill = getCommand(resolvedName, allSkills);
|
|
236081
|
+
if (skill.type !== "prompt") {
|
|
236082
|
+
logForDebugging(`[Agent: ${agentDefinition.agentType}] Warning: Skill '${skillName}' is not a prompt-based skill`, { level: "warn" });
|
|
236083
|
+
continue;
|
|
236084
|
+
}
|
|
236085
|
+
validSkills.push({ skillName, skill });
|
|
236086
|
+
}
|
|
236087
|
+
const loaded = await Promise.all(validSkills.map(async ({ skillName, skill }) => ({
|
|
236088
|
+
skillName,
|
|
236089
|
+
skill,
|
|
236090
|
+
content: await skill.getPromptForCommand("", toolUseContext)
|
|
236091
|
+
})));
|
|
236092
|
+
for (const { skillName, skill, content } of loaded) {
|
|
236093
|
+
logForDebugging(`[Agent: ${agentDefinition.agentType}] Preloaded skill '${skillName}'`);
|
|
236094
|
+
const metadata = formatSkillLoadingMetadata(skillName, skill.progressMessage);
|
|
236095
|
+
initialMessages.push(createUserMessage({
|
|
236096
|
+
content: [{ type: "text", text: metadata }, ...content],
|
|
236097
|
+
isMeta: true
|
|
236098
|
+
}));
|
|
236099
|
+
}
|
|
235981
236100
|
}
|
|
235982
|
-
|
|
235983
|
-
|
|
235984
|
-
|
|
235985
|
-
|
|
235986
|
-
|
|
235987
|
-
|
|
235988
|
-
|
|
235989
|
-
|
|
235990
|
-
|
|
235991
|
-
|
|
235992
|
-
|
|
235993
|
-
|
|
235994
|
-
|
|
235995
|
-
|
|
235996
|
-
|
|
235997
|
-
|
|
235998
|
-
|
|
235999
|
-
|
|
236000
|
-
|
|
236001
|
-
|
|
236002
|
-
|
|
236003
|
-
|
|
236004
|
-
|
|
236005
|
-
|
|
236006
|
-
|
|
236007
|
-
|
|
236008
|
-
|
|
236009
|
-
|
|
236010
|
-
|
|
236011
|
-
|
|
236012
|
-
|
|
236013
|
-
|
|
236014
|
-
|
|
236015
|
-
|
|
236016
|
-
|
|
236017
|
-
});
|
|
236018
|
-
if (preserveToolUseResults) {
|
|
236019
|
-
agentToolRuntimeContext.preserveToolUseResults = true;
|
|
236020
|
-
}
|
|
236021
|
-
if (onCacheSafeParams) {
|
|
236022
|
-
onCacheSafeParams({
|
|
236023
|
-
systemPrompt: agentSystemPrompt,
|
|
236024
|
-
userContext: resolvedUserContext,
|
|
236025
|
-
systemContext: resolvedSystemContext,
|
|
236026
|
-
toolUseContext: agentToolRuntimeContext,
|
|
236027
|
-
forkContextMessages: initialMessages
|
|
236101
|
+
const mcp = await initializeAgentMcpServers(agentDefinition, toolUseContext.options.mcpClients);
|
|
236102
|
+
const {
|
|
236103
|
+
clients: mergedMcpClients,
|
|
236104
|
+
tools: agentMcpTools
|
|
236105
|
+
} = mcp;
|
|
236106
|
+
mcpCleanup = mcp.cleanup;
|
|
236107
|
+
const allTools = agentMcpTools.length > 0 ? uniqBy_default([...resolvedTools, ...agentMcpTools], "name") : resolvedTools;
|
|
236108
|
+
const agentOptions = {
|
|
236109
|
+
isNonInteractiveSession: useExactTools ? toolUseContext.options.isNonInteractiveSession : isAsync2 ? true : toolUseContext.options.isNonInteractiveSession ?? false,
|
|
236110
|
+
appendSystemPrompt: toolUseContext.options.appendSystemPrompt,
|
|
236111
|
+
tools: allTools,
|
|
236112
|
+
commands: [],
|
|
236113
|
+
debug: toolUseContext.options.debug,
|
|
236114
|
+
verbose: toolUseContext.options.verbose,
|
|
236115
|
+
mainLoopModel: effectiveModel,
|
|
236116
|
+
providerOverride: providerOverride ?? undefined,
|
|
236117
|
+
thinkingConfig: toolUseContext.options.thinkingConfig,
|
|
236118
|
+
mcpClients: mergedMcpClients,
|
|
236119
|
+
mcpResources: toolUseContext.options.mcpResources,
|
|
236120
|
+
agentDefinitions: toolUseContext.options.agentDefinitions,
|
|
236121
|
+
subagentDisallowedTools: toolUseContext.options.subagentDisallowedTools,
|
|
236122
|
+
...useExactTools && { querySource }
|
|
236123
|
+
};
|
|
236124
|
+
agentToolRuntimeContext = createSubagentContext(toolUseContext, {
|
|
236125
|
+
options: agentOptions,
|
|
236126
|
+
agentId,
|
|
236127
|
+
agentType: agentDefinition.agentType,
|
|
236128
|
+
messages: initialMessages,
|
|
236129
|
+
readFileState: agentReadFileState,
|
|
236130
|
+
abortController: agentAbortController,
|
|
236131
|
+
getAppState: agentGetAppState,
|
|
236132
|
+
shareSetAppState: !isAsync2,
|
|
236133
|
+
shareSetResponseLength: true,
|
|
236134
|
+
criticalSystemReminder_EXPERIMENTAL: agentDefinition.criticalSystemReminder_EXPERIMENTAL,
|
|
236135
|
+
contentReplacementState
|
|
236028
236136
|
});
|
|
236029
|
-
|
|
236030
|
-
|
|
236031
|
-
|
|
236032
|
-
|
|
236033
|
-
|
|
236034
|
-
|
|
236035
|
-
|
|
236036
|
-
|
|
236037
|
-
|
|
236038
|
-
|
|
236039
|
-
|
|
236040
|
-
|
|
236041
|
-
|
|
236042
|
-
|
|
236043
|
-
|
|
236137
|
+
if (preserveToolUseResults) {
|
|
236138
|
+
agentToolRuntimeContext.preserveToolUseResults = true;
|
|
236139
|
+
}
|
|
236140
|
+
if (onCacheSafeParams) {
|
|
236141
|
+
onCacheSafeParams({
|
|
236142
|
+
systemPrompt: agentSystemPrompt,
|
|
236143
|
+
userContext: resolvedUserContext,
|
|
236144
|
+
systemContext: resolvedSystemContext,
|
|
236145
|
+
toolUseContext: agentToolRuntimeContext,
|
|
236146
|
+
forkContextMessages: initialMessages
|
|
236147
|
+
});
|
|
236148
|
+
}
|
|
236149
|
+
recordSidechainTranscript(initialMessages, agentId).catch((_err) => logForDebugging(`Failed to record sidechain transcript: ${_err}`));
|
|
236150
|
+
writeAgentMetadata(agentId, {
|
|
236151
|
+
agentType: agentDefinition.agentType,
|
|
236152
|
+
...worktreePath && { worktreePath },
|
|
236153
|
+
...description && { description }
|
|
236154
|
+
}).catch((_err) => logForDebugging(`Failed to write agent metadata: ${_err}`));
|
|
236155
|
+
let lastRecordedUuid = initialMessages.at(-1)?.uuid ?? null;
|
|
236156
|
+
let partialBaseMessage = null;
|
|
236157
|
+
const partialTextByIndex = new Map;
|
|
236158
|
+
const PARTIAL_PROGRESS_HOOK_INTERVAL_MS = 100;
|
|
236159
|
+
let lastPartialProgressHookAt = 0;
|
|
236044
236160
|
for await (const message of query({
|
|
236045
236161
|
messages: initialMessages,
|
|
236046
236162
|
systemPrompt: agentSystemPrompt,
|
|
@@ -236130,43 +236246,65 @@ async function* runAgent({
|
|
|
236130
236246
|
agentRunError = err2;
|
|
236131
236247
|
throw err2;
|
|
236132
236248
|
} finally {
|
|
236133
|
-
|
|
236134
|
-
|
|
236135
|
-
|
|
236136
|
-
|
|
236137
|
-
|
|
236138
|
-
logForDebugging(`Background agent ${agentId} crashed: ${errorMessage(agentRunError)}
|
|
236249
|
+
await finalizeLifecycle([
|
|
236250
|
+
async () => {
|
|
236251
|
+
const naturalStopAlreadyFired = isAsync2 && hasSubagentStopFired(agentId);
|
|
236252
|
+
if (isAsync2 && agentRunError !== undefined) {
|
|
236253
|
+
logForDebugging(`Background agent ${agentId} crashed: ${errorMessage(agentRunError)}
|
|
236139
236254
|
${agentRunError instanceof Error ? agentRunError.stack ?? "" : ""}`, { level: "error" });
|
|
236140
|
-
|
|
236141
|
-
|
|
236142
|
-
|
|
236143
|
-
|
|
236144
|
-
|
|
236145
|
-
|
|
236146
|
-
|
|
236147
|
-
|
|
236148
|
-
|
|
236149
|
-
|
|
236255
|
+
}
|
|
236256
|
+
if (isAsync2 && !naturalStopAlreadyFired) {
|
|
236257
|
+
try {
|
|
236258
|
+
const terminalContext = agentToolRuntimeContext ?? toolUseContext;
|
|
236259
|
+
const fallbackAppState = terminalContext.getAppState();
|
|
236260
|
+
const terminal = agentAbortController.signal.aborted ? { status: "stopped" } : agentRunError !== undefined ? { status: "failed", errorMessage: errorMessage(agentRunError) } : { status: "completed" };
|
|
236261
|
+
const fallbackStop = executeStopHooks(fallbackAppState.toolPermissionContext.mode, undefined, undefined, false, agentId, terminalContext, lastAssistantForFallback ? [lastAssistantForFallback] : undefined, agentDefinition.agentType, undefined, terminal);
|
|
236262
|
+
for await (const evt of fallbackStop) {}
|
|
236263
|
+
} catch (err2) {
|
|
236264
|
+
logForDebugging(`Fallback SubagentStop failed for ${agentId}: ${err2}`, {
|
|
236265
|
+
level: "warn"
|
|
236266
|
+
});
|
|
236267
|
+
}
|
|
236268
|
+
}
|
|
236269
|
+
},
|
|
236270
|
+
mcpCleanup,
|
|
236271
|
+
() => {
|
|
236272
|
+
if (agentDefinition.hooks) {
|
|
236273
|
+
clearSessionHooks(rootSetAppState, agentId);
|
|
236274
|
+
}
|
|
236275
|
+
},
|
|
236276
|
+
() => {
|
|
236277
|
+
if (false) {}
|
|
236278
|
+
},
|
|
236279
|
+
() => agentToolRuntimeContext?.readFileState.clear(),
|
|
236280
|
+
() => {
|
|
236281
|
+
initialMessages.length = 0;
|
|
236282
|
+
},
|
|
236283
|
+
() => unregisterAgent(agentId),
|
|
236284
|
+
() => clearAgentTranscriptSubdir(agentId),
|
|
236285
|
+
() => {
|
|
236286
|
+
rootSetAppState((prev) => {
|
|
236287
|
+
if (!(agentId in prev.todos))
|
|
236288
|
+
return prev;
|
|
236289
|
+
const { [agentId]: _removed, ...todos } = prev.todos;
|
|
236290
|
+
return { ...prev, todos };
|
|
236150
236291
|
});
|
|
236292
|
+
},
|
|
236293
|
+
() => {
|
|
236294
|
+
if (isAsync2) {
|
|
236295
|
+
stopBackgroundAgentShellsById(agentId);
|
|
236296
|
+
} else {
|
|
236297
|
+
stopOwnedShells();
|
|
236298
|
+
}
|
|
236299
|
+
},
|
|
236300
|
+
() => {
|
|
236301
|
+
if (false) {}
|
|
236302
|
+
},
|
|
236303
|
+
() => {
|
|
236304
|
+
if (isAsync2)
|
|
236305
|
+
unregisterBackgroundAgentAbort(agentId);
|
|
236151
236306
|
}
|
|
236152
|
-
|
|
236153
|
-
await mcpCleanup();
|
|
236154
|
-
if (agentDefinition.hooks) {
|
|
236155
|
-
clearSessionHooks(rootSetAppState, agentId);
|
|
236156
|
-
}
|
|
236157
|
-
if (false) {}
|
|
236158
|
-
agentToolRuntimeContext.readFileState.clear();
|
|
236159
|
-
initialMessages.length = 0;
|
|
236160
|
-
unregisterAgent(agentId);
|
|
236161
|
-
clearAgentTranscriptSubdir(agentId);
|
|
236162
|
-
rootSetAppState((prev) => {
|
|
236163
|
-
if (!(agentId in prev.todos))
|
|
236164
|
-
return prev;
|
|
236165
|
-
const { [agentId]: _removed, ...todos } = prev.todos;
|
|
236166
|
-
return { ...prev, todos };
|
|
236167
|
-
});
|
|
236168
|
-
killShellTasksForAgent(agentId, toolUseContext.getAppState, rootSetAppState);
|
|
236169
|
-
if (false) {}
|
|
236307
|
+
]);
|
|
236170
236308
|
}
|
|
236171
236309
|
}
|
|
236172
236310
|
function filterIncompleteToolCalls(messages) {
|
|
@@ -236238,6 +236376,7 @@ var init_runAgent = __esm(() => {
|
|
|
236238
236376
|
init_config5();
|
|
236239
236377
|
init_permissions2();
|
|
236240
236378
|
init_killShellTasks();
|
|
236379
|
+
init_LocalAgentTask();
|
|
236241
236380
|
init_attachments();
|
|
236242
236381
|
init_errors5();
|
|
236243
236382
|
init_file();
|
|
@@ -238037,6 +238176,21 @@ var init_RemoteAgentTask = __esm(() => {
|
|
|
238037
238176
|
};
|
|
238038
238177
|
});
|
|
238039
238178
|
|
|
238179
|
+
// src/lib/zodToJsonSchema.ts
|
|
238180
|
+
function zodToJsonSchema3(schema) {
|
|
238181
|
+
const hit = cache2.get(schema);
|
|
238182
|
+
if (hit)
|
|
238183
|
+
return hit;
|
|
238184
|
+
const result = toJSONSchema(schema);
|
|
238185
|
+
cache2.set(schema, result);
|
|
238186
|
+
return result;
|
|
238187
|
+
}
|
|
238188
|
+
var cache2;
|
|
238189
|
+
var init_zodToJsonSchema2 = __esm(() => {
|
|
238190
|
+
init_v4();
|
|
238191
|
+
cache2 = new WeakMap;
|
|
238192
|
+
});
|
|
238193
|
+
|
|
238040
238194
|
// src/session/systemPrompt.ts
|
|
238041
238195
|
function buildEffectiveSystemPrompt({
|
|
238042
238196
|
mainThreadAgentDefinition,
|
|
@@ -238080,6 +238234,67 @@ function getTeleportLauncher() {
|
|
|
238080
238234
|
}
|
|
238081
238235
|
var _launcher = null;
|
|
238082
238236
|
|
|
238237
|
+
// src/capabilities/worktreeAvailability.ts
|
|
238238
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
238239
|
+
import { resolve as resolve15 } from "path";
|
|
238240
|
+
function resolveGitWorktreeAvailability(cwd, gitExecutable = "git") {
|
|
238241
|
+
try {
|
|
238242
|
+
const rootResult = spawnSync2(gitExecutable, ["rev-parse", "--show-toplevel"], {
|
|
238243
|
+
cwd,
|
|
238244
|
+
encoding: "utf8",
|
|
238245
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
238246
|
+
windowsHide: true
|
|
238247
|
+
});
|
|
238248
|
+
if (rootResult.error) {
|
|
238249
|
+
return { available: false, reason: "git_unavailable" };
|
|
238250
|
+
}
|
|
238251
|
+
const gitRoot = rootResult.stdout.trim();
|
|
238252
|
+
if (rootResult.status !== 0 || !gitRoot) {
|
|
238253
|
+
return { available: false, reason: "not_git_repository" };
|
|
238254
|
+
}
|
|
238255
|
+
const headResult = spawnSync2(gitExecutable, ["rev-parse", "--verify", "HEAD^{commit}"], {
|
|
238256
|
+
cwd: gitRoot,
|
|
238257
|
+
encoding: "utf8",
|
|
238258
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
238259
|
+
windowsHide: true
|
|
238260
|
+
});
|
|
238261
|
+
if (headResult.error) {
|
|
238262
|
+
return { available: false, reason: "git_unavailable" };
|
|
238263
|
+
}
|
|
238264
|
+
const headCommit = headResult.stdout.trim();
|
|
238265
|
+
if (headResult.status !== 0 || !headCommit) {
|
|
238266
|
+
return { available: false, reason: "unborn_head" };
|
|
238267
|
+
}
|
|
238268
|
+
return {
|
|
238269
|
+
available: true,
|
|
238270
|
+
gitRoot: resolve15(gitRoot).normalize("NFC"),
|
|
238271
|
+
headCommit
|
|
238272
|
+
};
|
|
238273
|
+
} catch {
|
|
238274
|
+
return { available: false, reason: "git_unavailable" };
|
|
238275
|
+
}
|
|
238276
|
+
}
|
|
238277
|
+
function isGitWorktreeIsolationAvailable(cwd, gitExecutable = "git", cache3) {
|
|
238278
|
+
const cacheKey = `${resolve15(cwd).normalize("NFC")}\x00${gitExecutable}`;
|
|
238279
|
+
const cached2 = cache3?.get(cacheKey);
|
|
238280
|
+
if (cached2 !== undefined)
|
|
238281
|
+
return cached2;
|
|
238282
|
+
const available = resolveGitWorktreeAvailability(cwd, gitExecutable).available;
|
|
238283
|
+
cache3?.set(cacheKey, available);
|
|
238284
|
+
return available;
|
|
238285
|
+
}
|
|
238286
|
+
var WorktreeUnavailableError;
|
|
238287
|
+
var init_worktreeAvailability = __esm(() => {
|
|
238288
|
+
WorktreeUnavailableError = class WorktreeUnavailableError extends Error {
|
|
238289
|
+
reason;
|
|
238290
|
+
constructor(reason) {
|
|
238291
|
+
super(`Agent worktree is unavailable (${reason})`);
|
|
238292
|
+
this.reason = reason;
|
|
238293
|
+
this.name = "WorktreeUnavailableError";
|
|
238294
|
+
}
|
|
238295
|
+
};
|
|
238296
|
+
});
|
|
238297
|
+
|
|
238083
238298
|
// src/session/agentId.ts
|
|
238084
238299
|
function formatAgentId(agentName, teamName) {
|
|
238085
238300
|
return `${agentName}@${teamName}`;
|
|
@@ -244727,13 +244942,13 @@ var init_sedValidation = __esm(() => {
|
|
|
244727
244942
|
|
|
244728
244943
|
// src/capabilities/tools/BashTool/pathValidation.ts
|
|
244729
244944
|
import { homedir as homedir16 } from "os";
|
|
244730
|
-
import { isAbsolute as isAbsolute10, resolve as
|
|
244945
|
+
import { isAbsolute as isAbsolute10, resolve as resolve16 } from "path";
|
|
244731
244946
|
function checkDangerousRemovalPaths(command, args, cwd) {
|
|
244732
244947
|
const extractor = PATH_EXTRACTORS[command];
|
|
244733
244948
|
const paths2 = extractor(args);
|
|
244734
244949
|
for (const path10 of paths2) {
|
|
244735
244950
|
const cleanPath = expandTilde(path10.replace(/^['"]|['"]$/g, ""));
|
|
244736
|
-
const absolutePath = isAbsolute10(cleanPath) ? cleanPath :
|
|
244951
|
+
const absolutePath = isAbsolute10(cleanPath) ? cleanPath : resolve16(cwd, cleanPath);
|
|
244737
244952
|
if (isDangerousRemovalPath(absolutePath)) {
|
|
244738
244953
|
return {
|
|
244739
244954
|
behavior: "ask",
|
|
@@ -248174,7 +248389,7 @@ function createInProcessCanUseTool(identity4, abortController, onPermissionWaitM
|
|
|
248174
248389
|
}
|
|
248175
248390
|
const setToolUseConfirmQueue = getLeaderToolUseConfirmQueue();
|
|
248176
248391
|
if (setToolUseConfirmQueue) {
|
|
248177
|
-
return new Promise((
|
|
248392
|
+
return new Promise((resolve17) => {
|
|
248178
248393
|
let decisionMade = false;
|
|
248179
248394
|
const permissionStartMs = Date.now();
|
|
248180
248395
|
const reportPermissionWait = () => {
|
|
@@ -248185,7 +248400,7 @@ function createInProcessCanUseTool(identity4, abortController, onPermissionWaitM
|
|
|
248185
248400
|
return;
|
|
248186
248401
|
decisionMade = true;
|
|
248187
248402
|
reportPermissionWait();
|
|
248188
|
-
|
|
248403
|
+
resolve17({ behavior: "ask", message: SUBAGENT_REJECT_MESSAGE });
|
|
248189
248404
|
setToolUseConfirmQueue((queue3) => queue3.filter((item) => item.toolUseID !== toolUseID));
|
|
248190
248405
|
};
|
|
248191
248406
|
abortController.signal.addEventListener("abort", onAbortListener, {
|
|
@@ -248210,7 +248425,7 @@ function createInProcessCanUseTool(identity4, abortController, onPermissionWaitM
|
|
|
248210
248425
|
decisionMade = true;
|
|
248211
248426
|
abortController.signal.removeEventListener("abort", onAbortListener);
|
|
248212
248427
|
reportPermissionWait();
|
|
248213
|
-
|
|
248428
|
+
resolve17({ behavior: "ask", message: SUBAGENT_REJECT_MESSAGE });
|
|
248214
248429
|
},
|
|
248215
248430
|
async onAllow(updatedInput, permissionUpdates, feedback, contentBlocks) {
|
|
248216
248431
|
if (decisionMade)
|
|
@@ -248230,7 +248445,7 @@ function createInProcessCanUseTool(identity4, abortController, onPermissionWaitM
|
|
|
248230
248445
|
}
|
|
248231
248446
|
}
|
|
248232
248447
|
const trimmedFeedback = feedback?.trim();
|
|
248233
|
-
|
|
248448
|
+
resolve17({
|
|
248234
248449
|
behavior: "allow",
|
|
248235
248450
|
updatedInput,
|
|
248236
248451
|
userModified: false,
|
|
@@ -248245,7 +248460,7 @@ function createInProcessCanUseTool(identity4, abortController, onPermissionWaitM
|
|
|
248245
248460
|
abortController.signal.removeEventListener("abort", onAbortListener);
|
|
248246
248461
|
reportPermissionWait();
|
|
248247
248462
|
const message = feedback ? `${SUBAGENT_REJECT_MESSAGE_WITH_REASON_PREFIX}${feedback}` : SUBAGENT_REJECT_MESSAGE;
|
|
248248
|
-
|
|
248463
|
+
resolve17({ behavior: "ask", message, contentBlocks });
|
|
248249
248464
|
},
|
|
248250
248465
|
async recheckPermission() {
|
|
248251
248466
|
if (decisionMade)
|
|
@@ -248256,7 +248471,7 @@ function createInProcessCanUseTool(identity4, abortController, onPermissionWaitM
|
|
|
248256
248471
|
abortController.signal.removeEventListener("abort", onAbortListener);
|
|
248257
248472
|
reportPermissionWait();
|
|
248258
248473
|
setToolUseConfirmQueue((queue4) => queue4.filter((item) => item.toolUseID !== toolUseID));
|
|
248259
|
-
|
|
248474
|
+
resolve17({
|
|
248260
248475
|
...freshResult,
|
|
248261
248476
|
updatedInput: input,
|
|
248262
248477
|
userModified: false
|
|
@@ -248267,7 +248482,7 @@ function createInProcessCanUseTool(identity4, abortController, onPermissionWaitM
|
|
|
248267
248482
|
]);
|
|
248268
248483
|
});
|
|
248269
248484
|
}
|
|
248270
|
-
return new Promise((
|
|
248485
|
+
return new Promise((resolve17) => {
|
|
248271
248486
|
const request = createPermissionRequest({
|
|
248272
248487
|
toolName: tool.name,
|
|
248273
248488
|
toolUseId: toolUseID,
|
|
@@ -248286,7 +248501,7 @@ function createInProcessCanUseTool(identity4, abortController, onPermissionWaitM
|
|
|
248286
248501
|
cleanup();
|
|
248287
248502
|
persistPermissionUpdates(permissionUpdates);
|
|
248288
248503
|
const finalInput = updatedInput && Object.keys(updatedInput).length > 0 ? updatedInput : input;
|
|
248289
|
-
|
|
248504
|
+
resolve17({
|
|
248290
248505
|
behavior: "allow",
|
|
248291
248506
|
updatedInput: finalInput,
|
|
248292
248507
|
userModified: false,
|
|
@@ -248296,14 +248511,14 @@ function createInProcessCanUseTool(identity4, abortController, onPermissionWaitM
|
|
|
248296
248511
|
onReject(feedback, contentBlocks) {
|
|
248297
248512
|
cleanup();
|
|
248298
248513
|
const message = feedback ? `${SUBAGENT_REJECT_MESSAGE_WITH_REASON_PREFIX}${feedback}` : SUBAGENT_REJECT_MESSAGE;
|
|
248299
|
-
|
|
248514
|
+
resolve17({ behavior: "ask", message, contentBlocks });
|
|
248300
248515
|
}
|
|
248301
248516
|
});
|
|
248302
248517
|
sendPermissionRequestViaMailbox(request);
|
|
248303
|
-
const pollInterval = setInterval(async (abortController2, cleanup2,
|
|
248518
|
+
const pollInterval = setInterval(async (abortController2, cleanup2, resolve18, identity5, request2) => {
|
|
248304
248519
|
if (abortController2.signal.aborted) {
|
|
248305
248520
|
cleanup2();
|
|
248306
|
-
|
|
248521
|
+
resolve18({ behavior: "ask", message: SUBAGENT_REJECT_MESSAGE });
|
|
248307
248522
|
return;
|
|
248308
248523
|
}
|
|
248309
248524
|
const allMessages = await readMailbox(identity5.agentName, identity5.teamName);
|
|
@@ -248331,10 +248546,10 @@ function createInProcessCanUseTool(identity4, abortController, onPermissionWaitM
|
|
|
248331
248546
|
}
|
|
248332
248547
|
}
|
|
248333
248548
|
}
|
|
248334
|
-
}, PERMISSION_POLL_INTERVAL_MS, abortController, cleanup,
|
|
248549
|
+
}, PERMISSION_POLL_INTERVAL_MS, abortController, cleanup, resolve17, identity4, request);
|
|
248335
248550
|
const onAbortListener = () => {
|
|
248336
248551
|
cleanup();
|
|
248337
|
-
|
|
248552
|
+
resolve17({ behavior: "ask", message: SUBAGENT_REJECT_MESSAGE });
|
|
248338
248553
|
};
|
|
248339
248554
|
abortController.signal.addEventListener("abort", onAbortListener, {
|
|
248340
248555
|
once: true
|
|
@@ -249074,8 +249289,8 @@ function waitForPaneShellReady() {
|
|
|
249074
249289
|
}
|
|
249075
249290
|
function acquirePaneCreationLock() {
|
|
249076
249291
|
let release;
|
|
249077
|
-
const newLock = new Promise((
|
|
249078
|
-
release =
|
|
249292
|
+
const newLock = new Promise((resolve17) => {
|
|
249293
|
+
release = resolve17;
|
|
249079
249294
|
});
|
|
249080
249295
|
const previousLock = paneCreationLock;
|
|
249081
249296
|
paneCreationLock = newLock;
|
|
@@ -249522,8 +249737,8 @@ __export(exports_ITermBackend, {
|
|
|
249522
249737
|
});
|
|
249523
249738
|
function acquirePaneCreationLock2() {
|
|
249524
249739
|
let release;
|
|
249525
|
-
const newLock = new Promise((
|
|
249526
|
-
release =
|
|
249740
|
+
const newLock = new Promise((resolve17) => {
|
|
249741
|
+
release = resolve17;
|
|
249527
249742
|
});
|
|
249528
249743
|
const previousLock = paneCreationLock2;
|
|
249529
249744
|
paneCreationLock2 = newLock;
|
|
@@ -250504,6 +250719,96 @@ var init_spawnMultiAgent = __esm(() => {
|
|
|
250504
250719
|
init_loadAgentsDir();
|
|
250505
250720
|
});
|
|
250506
250721
|
|
|
250722
|
+
// src/capabilities/tools/AgentTool/agentInvocationDedupe.ts
|
|
250723
|
+
import { isDeepStrictEqual } from "node:util";
|
|
250724
|
+
function isToolUseBlock(value) {
|
|
250725
|
+
if (!value || typeof value !== "object")
|
|
250726
|
+
return false;
|
|
250727
|
+
const block2 = value;
|
|
250728
|
+
return block2.type === "tool_use" && typeof block2.id === "string" && typeof block2.name === "string";
|
|
250729
|
+
}
|
|
250730
|
+
function isAgentToolUseBlock(block2) {
|
|
250731
|
+
return block2.name === AGENT_TOOL_NAME2 || block2.name === LEGACY_AGENT_TOOL_NAME;
|
|
250732
|
+
}
|
|
250733
|
+
function findEarlierDuplicateAgentToolUse(assistantMessage, currentToolUseId) {
|
|
250734
|
+
if (!currentToolUseId || !Array.isArray(assistantMessage?.message?.content)) {
|
|
250735
|
+
return;
|
|
250736
|
+
}
|
|
250737
|
+
const earlierAgentToolUses = [];
|
|
250738
|
+
for (const block2 of assistantMessage.message.content) {
|
|
250739
|
+
if (!isToolUseBlock(block2))
|
|
250740
|
+
continue;
|
|
250741
|
+
if (block2.id === currentToolUseId) {
|
|
250742
|
+
if (!isAgentToolUseBlock(block2))
|
|
250743
|
+
return;
|
|
250744
|
+
return earlierAgentToolUses.find((candidate) => isDeepStrictEqual(candidate.input, block2.input))?.id;
|
|
250745
|
+
}
|
|
250746
|
+
if (isAgentToolUseBlock(block2))
|
|
250747
|
+
earlierAgentToolUses.push(block2);
|
|
250748
|
+
}
|
|
250749
|
+
return;
|
|
250750
|
+
}
|
|
250751
|
+
var init_agentInvocationDedupe = __esm(() => {
|
|
250752
|
+
init_constants4();
|
|
250753
|
+
});
|
|
250754
|
+
|
|
250755
|
+
// src/capabilities/tools/AgentTool/worktreeIsolation.ts
|
|
250756
|
+
function getWorktreeIsolationUnavailableMessage(reason) {
|
|
250757
|
+
switch (reason) {
|
|
250758
|
+
case "not_git_repository":
|
|
250759
|
+
return "Worktree isolation is unavailable: the current directory is not a Git repository and no WorktreeCreate hook is configured. This model continuation has been stopped. Run the Agent task again without `isolation` only if using the current directory is safe; otherwise select a Git repository or configure a WorktreeCreate hook.";
|
|
250760
|
+
case "unborn_head":
|
|
250761
|
+
return "Worktree isolation is unavailable: the Git repository has no resolvable HEAD commit. This model continuation has been stopped. Run the Agent task again without `isolation` only if using the current directory is safe; otherwise create the initial commit.";
|
|
250762
|
+
case "git_unavailable":
|
|
250763
|
+
return "Worktree isolation is unavailable because Git could not be inspected. This model continuation has been stopped. Check that Git is installed and accessible, or run the Agent task again without `isolation` only if using the current directory is safe.";
|
|
250764
|
+
default: {
|
|
250765
|
+
const exhaustive = reason;
|
|
250766
|
+
return exhaustive;
|
|
250767
|
+
}
|
|
250768
|
+
}
|
|
250769
|
+
}
|
|
250770
|
+
var WORKTREE_ISOLATION_SCHEMA_DESCRIPTION = 'Isolation mode. Set "worktree" only when the user explicitly requests worktree isolation. It requires a Git repository with a resolvable HEAD commit or a configured WorktreeCreate hook; omit it for ordinary tasks, including read-only research.', WORKTREE_ISOLATION_USAGE_GUIDANCE = 'Only set `isolation: "worktree"` when the user explicitly requests worktree isolation. Omit it for ordinary tasks, including read-only research. Worktree isolation requires a Git repository with a resolvable HEAD commit or a configured WorktreeCreate hook.';
|
|
250771
|
+
|
|
250772
|
+
// src/capabilities/tools/AgentTool/inputSchema.ts
|
|
250773
|
+
function buildAgentInputSchema(options2) {
|
|
250774
|
+
const capabilityAwareSchema = options2.worktreeIsolationAvailable ? fullInputSchema() : inputSchemaWithoutWorktreeIsolation();
|
|
250775
|
+
const schema = options2.includeCwd ? capabilityAwareSchema : capabilityAwareSchema.omit({
|
|
250776
|
+
cwd: true
|
|
250777
|
+
});
|
|
250778
|
+
return options2.includeRunInBackground ? schema : schema.omit({
|
|
250779
|
+
run_in_background: true
|
|
250780
|
+
});
|
|
250781
|
+
}
|
|
250782
|
+
var baseInputSchema, fullInputSchema, inputSchemaWithoutWorktreeIsolation;
|
|
250783
|
+
var init_inputSchema = __esm(() => {
|
|
250784
|
+
init_v4();
|
|
250785
|
+
init_PermissionMode();
|
|
250786
|
+
baseInputSchema = lazySchema(() => exports_external2.object({
|
|
250787
|
+
description: exports_external2.string().describe("A short (3-5 word) description of the task"),
|
|
250788
|
+
prompt: exports_external2.string().describe("The task for the agent to perform"),
|
|
250789
|
+
subagent_type: exports_external2.string().optional().describe("The type of specialized agent to use for this task"),
|
|
250790
|
+
model: exports_external2.enum(["sonnet", "opus", "haiku"]).optional().describe("Optional model override for this agent. Takes precedence over the agent definition's model frontmatter. If omitted, uses the agent definition's model, or inherits from the parent."),
|
|
250791
|
+
run_in_background: exports_external2.boolean().optional().describe("Set to true to run this agent in the background. You will be notified when it completes.")
|
|
250792
|
+
}));
|
|
250793
|
+
fullInputSchema = lazySchema(() => {
|
|
250794
|
+
const multiAgentInputSchema = exports_external2.object({
|
|
250795
|
+
name: exports_external2.string().optional().describe("Name for the spawned agent. Makes it addressable via SendMessage({to: name}) while running."),
|
|
250796
|
+
team_name: exports_external2.string().optional().describe("Team name for spawning. Uses current team context if omitted."),
|
|
250797
|
+
mode: permissionModeSchema().optional().describe('Permission mode for spawned teammate (e.g., "plan" to require plan approval).')
|
|
250798
|
+
});
|
|
250799
|
+
const isolationInputSchema = exports_external2.object({
|
|
250800
|
+
isolation: exports_external2.enum(["worktree"]).optional().describe(WORKTREE_ISOLATION_SCHEMA_DESCRIPTION)
|
|
250801
|
+
});
|
|
250802
|
+
return baseInputSchema().merge(multiAgentInputSchema).extend({
|
|
250803
|
+
cwd: exports_external2.string().optional().describe('Absolute path to run the agent in. Overrides the working directory for all filesystem and shell operations within this agent. Mutually exclusive with isolation: "worktree".')
|
|
250804
|
+
}).merge(isolationInputSchema);
|
|
250805
|
+
});
|
|
250806
|
+
inputSchemaWithoutWorktreeIsolation = lazySchema(() => {
|
|
250807
|
+
const schema = fullInputSchema().omit({ isolation: true });
|
|
250808
|
+
return schema;
|
|
250809
|
+
});
|
|
250810
|
+
});
|
|
250811
|
+
|
|
250507
250812
|
// src/capabilities/tools/AgentTool/forkSubagent.ts
|
|
250508
250813
|
import { randomUUID as randomUUID7 } from "crypto";
|
|
250509
250814
|
function isForkSubagentEnabled() {
|
|
@@ -250749,7 +251054,11 @@ The ${AGENT_TOOL_NAME2} tool launches specialized agents (subprocesses) that aut
|
|
|
250749
251054
|
|
|
250750
251055
|
${agentListSection}
|
|
250751
251056
|
|
|
250752
|
-
${forkEnabled ? `When using the ${AGENT_TOOL_NAME2} tool, specify a subagent_type to use a specialized agent, or omit it to fork yourself — a fork inherits your full conversation context. Only use subagent_type values that appear in the available agent types; never invent an agent type from an example.` : `When using the ${AGENT_TOOL_NAME2} tool, specify a subagent_type parameter to select which agent type to use. If omitted, the general-purpose agent is used. Only use subagent_type values that appear in the available agent types; never invent an agent type from an example.`}
|
|
251057
|
+
${forkEnabled ? `When using the ${AGENT_TOOL_NAME2} tool, specify a subagent_type to use a specialized agent, or omit it to fork yourself — a fork inherits your full conversation context. Only use subagent_type values that appear in the available agent types; never invent an agent type from an example.` : `When using the ${AGENT_TOOL_NAME2} tool, specify a subagent_type parameter to select which agent type to use. If omitted, the general-purpose agent is used. Only use subagent_type values that appear in the available agent types; never invent an agent type from an example.`}
|
|
251058
|
+
|
|
251059
|
+
Do not launch multiple Agent calls with exactly the same input.
|
|
251060
|
+
|
|
251061
|
+
${WORKTREE_ISOLATION_USAGE_GUIDANCE}`;
|
|
250753
251062
|
if (isCoordinator) {
|
|
250754
251063
|
return shared2;
|
|
250755
251064
|
}
|
|
@@ -250764,7 +251073,7 @@ When NOT to use the ${AGENT_TOOL_NAME2} tool:
|
|
|
250764
251073
|
- Other tasks that are not related to the agent descriptions above
|
|
250765
251074
|
`;
|
|
250766
251075
|
const concurrencyNote = !listViaAttachment && getSubscriptionType() !== "pro" ? `
|
|
250767
|
-
- Launch multiple agents concurrently
|
|
251076
|
+
- Launch multiple agents concurrently for independent, non-overlapping tasks; to do that, use a single message with multiple tool uses` : "";
|
|
250768
251077
|
return `${shared2}
|
|
250769
251078
|
${whenNotToUseSection}
|
|
250770
251079
|
|
|
@@ -250778,7 +251087,7 @@ Usage notes:
|
|
|
250778
251087
|
- Clearly tell the agent whether you expect it to write code or just to do research (search, file reads, web fetches, etc.)${forkEnabled ? "" : ", since it is not aware of the user's intent"}
|
|
250779
251088
|
- If the agent description mentions that it should be used proactively, then you should try your best to use it without the user having to ask for it first. Use your judgement.
|
|
250780
251089
|
- If the user specifies that they want you to run agents "in parallel", you MUST send a single message with multiple ${AGENT_TOOL_NAME2} tool use content blocks. Each call must either omit subagent_type or use an exact type from the available agent list.
|
|
250781
|
-
|
|
251090
|
+
${process.env.USER_TYPE === "ant" ? `
|
|
250782
251091
|
- You can set \`isolation: "remote"\` to run the agent in a remote CCR environment. This is always a background task; you'll be notified when it completes. Use for long-running tasks that need a fresh sandbox.` : ""}${isInProcessTeammate() ? `
|
|
250783
251092
|
- The run_in_background, name, team_name, and mode parameters are not available in this context. Only synchronous subagents are supported.` : isTeammate() ? `
|
|
250784
251093
|
- The name, team_name, and mode parameters are not available in this context — teammates cannot spawn other teammates. Omit them to spawn a subagent.` : ""}${whenToForkSection}${writingThePromptSection}
|
|
@@ -250804,12 +251113,57 @@ function getAutoBackgroundMs() {
|
|
|
250804
251113
|
}
|
|
250805
251114
|
return 0;
|
|
250806
251115
|
}
|
|
251116
|
+
function buildConfiguredAgentInputSchema(worktreeIsolationAvailable) {
|
|
251117
|
+
const options2 = {
|
|
251118
|
+
worktreeIsolationAvailable,
|
|
251119
|
+
includeRunInBackground: !isBackgroundTasksDisabled && !isForkSubagentEnabled()
|
|
251120
|
+
};
|
|
251121
|
+
return buildAgentInputSchema({
|
|
251122
|
+
...options2,
|
|
251123
|
+
includeCwd: false
|
|
251124
|
+
});
|
|
251125
|
+
}
|
|
251126
|
+
function getAdvertisedWorktreeAvailabilityCache() {
|
|
251127
|
+
try {
|
|
251128
|
+
const queryContext = getQueryContext();
|
|
251129
|
+
const now = Date.now();
|
|
251130
|
+
let cache3 = advertisedWorktreeAvailabilityByQuery.get(queryContext);
|
|
251131
|
+
if (!cache3 || cache3.expiresAt <= now || cache3.totalToolDuration !== queryContext.cost.totalToolDuration) {
|
|
251132
|
+
cache3 = {
|
|
251133
|
+
expiresAt: now + WORKTREE_AVAILABILITY_CACHE_TTL_MS,
|
|
251134
|
+
totalToolDuration: queryContext.cost.totalToolDuration,
|
|
251135
|
+
values: new Map
|
|
251136
|
+
};
|
|
251137
|
+
advertisedWorktreeAvailabilityByQuery.set(queryContext, cache3);
|
|
251138
|
+
}
|
|
251139
|
+
return cache3.values;
|
|
251140
|
+
} catch {
|
|
251141
|
+
return;
|
|
251142
|
+
}
|
|
251143
|
+
}
|
|
251144
|
+
function getAdvertisedAgentInputJSONSchema() {
|
|
251145
|
+
const worktreeIsolationAvailable = isAgentWorktreeIsolationAvailable({
|
|
251146
|
+
gitAvailabilityCache: getAdvertisedWorktreeAvailabilityCache()
|
|
251147
|
+
});
|
|
251148
|
+
const schemaVariant = "standard";
|
|
251149
|
+
const includeRunInBackground = !isBackgroundTasksDisabled && !isForkSubagentEnabled();
|
|
251150
|
+
const cacheKey = `${worktreeIsolationAvailable}:${schemaVariant}:${includeRunInBackground}`;
|
|
251151
|
+
const cached2 = advertisedInputJSONSchemaCache.get(cacheKey);
|
|
251152
|
+
if (cached2)
|
|
251153
|
+
return cached2;
|
|
251154
|
+
const schema = {
|
|
251155
|
+
...zodToJsonSchema3(buildConfiguredAgentInputSchema(worktreeIsolationAvailable)),
|
|
251156
|
+
type: "object"
|
|
251157
|
+
};
|
|
251158
|
+
advertisedInputJSONSchemaCache.set(cacheKey, schema);
|
|
251159
|
+
return schema;
|
|
251160
|
+
}
|
|
250807
251161
|
function resolveTeamName(input, appState) {
|
|
250808
251162
|
if (!isAgentSwarmsEnabled())
|
|
250809
251163
|
return;
|
|
250810
251164
|
return input.team_name || appState.teamContext?.teamName;
|
|
250811
251165
|
}
|
|
250812
|
-
var getBackgroundHintJSX, renderGroupedAgentToolUse, renderToolResultMessage3, renderToolUseErrorMessage, renderToolUseMessage3, renderToolUseProgressMessage2, renderToolUseRejectedMessage, renderToolUseTag, userFacingName, userFacingNameBackgroundColor, proactiveModule = null, PROGRESS_THRESHOLD_MS = 2000, isBackgroundTasksDisabled,
|
|
251166
|
+
var getBackgroundHintJSX, renderGroupedAgentToolUse, renderToolResultMessage3, renderToolUseErrorMessage, renderToolUseMessage3, renderToolUseProgressMessage2, renderToolUseRejectedMessage, renderToolUseTag, userFacingName, userFacingNameBackgroundColor, proactiveModule = null, PROGRESS_THRESHOLD_MS = 2000, isBackgroundTasksDisabled, inputSchema6 = () => buildConfiguredAgentInputSchema(true), outputSchema5, advertisedInputJSONSchemaCache, WORKTREE_AVAILABILITY_CACHE_TTL_MS = 30000, advertisedWorktreeAvailabilityByQuery, agentToolRuntime, AgentTool;
|
|
250813
251167
|
var init_AgentTool = __esm(() => {
|
|
250814
251168
|
init_toolRuntime();
|
|
250815
251169
|
init_promptCategory();
|
|
@@ -250828,9 +251182,9 @@ var init_AgentTool = __esm(() => {
|
|
|
250828
251182
|
init_debug();
|
|
250829
251183
|
init_envUtils();
|
|
250830
251184
|
init_errors5();
|
|
251185
|
+
init_zodToJsonSchema2();
|
|
250831
251186
|
init_messages4();
|
|
250832
251187
|
init_agent();
|
|
250833
|
-
init_PermissionMode();
|
|
250834
251188
|
init_permissions2();
|
|
250835
251189
|
init_sdkEventQueue();
|
|
250836
251190
|
init_sessionStorage();
|
|
@@ -250841,11 +251195,14 @@ var init_AgentTool = __esm(() => {
|
|
|
250841
251195
|
init_tokens();
|
|
250842
251196
|
init_uuid();
|
|
250843
251197
|
init_worktree();
|
|
251198
|
+
init_worktreeAvailability();
|
|
250844
251199
|
init_toolUIRegistry();
|
|
250845
251200
|
init_prompt2();
|
|
250846
251201
|
init_spawnMultiAgent();
|
|
250847
251202
|
init_agentColorManager();
|
|
251203
|
+
init_agentInvocationDedupe();
|
|
250848
251204
|
init_agentToolUtils();
|
|
251205
|
+
init_inputSchema();
|
|
250849
251206
|
init_generalPurposeAgent();
|
|
250850
251207
|
init_constants4();
|
|
250851
251208
|
init_forkSubagent();
|
|
@@ -250866,32 +251223,6 @@ var init_AgentTool = __esm(() => {
|
|
|
250866
251223
|
userFacingNameBackgroundColor
|
|
250867
251224
|
} = lazyUI("Agent"));
|
|
250868
251225
|
isBackgroundTasksDisabled = isEnvTruthy(resolveEnvVar("DISABLE_BACKGROUND_TASKS"));
|
|
250869
|
-
baseInputSchema = lazySchema(() => exports_external2.object({
|
|
250870
|
-
description: exports_external2.string().describe("A short (3-5 word) description of the task"),
|
|
250871
|
-
prompt: exports_external2.string().describe("The task for the agent to perform"),
|
|
250872
|
-
subagent_type: exports_external2.string().optional().describe("The type of specialized agent to use for this task"),
|
|
250873
|
-
model: exports_external2.enum(["sonnet", "opus", "haiku"]).optional().describe("Optional model override for this agent. Takes precedence over the agent definition's model frontmatter. If omitted, uses the agent definition's model, or inherits from the parent."),
|
|
250874
|
-
run_in_background: exports_external2.boolean().optional().describe("Set to true to run this agent in the background. You will be notified when it completes.")
|
|
250875
|
-
}));
|
|
250876
|
-
fullInputSchema = lazySchema(() => {
|
|
250877
|
-
const multiAgentInputSchema = exports_external2.object({
|
|
250878
|
-
name: exports_external2.string().optional().describe("Name for the spawned agent. Makes it addressable via SendMessage({to: name}) while running."),
|
|
250879
|
-
team_name: exports_external2.string().optional().describe("Team name for spawning. Uses current team context if omitted."),
|
|
250880
|
-
mode: permissionModeSchema().optional().describe('Permission mode for spawned teammate (e.g., "plan" to require plan approval).')
|
|
250881
|
-
});
|
|
250882
|
-
return baseInputSchema().merge(multiAgentInputSchema).extend({
|
|
250883
|
-
isolation: exports_external2.enum(["worktree"]).optional().describe('Isolation mode. "worktree" creates a temporary git worktree so the agent works on an isolated copy of the repo.'),
|
|
250884
|
-
cwd: exports_external2.string().optional().describe('Absolute path to run the agent in. Overrides the working directory for all filesystem and shell operations within this agent. Mutually exclusive with isolation: "worktree".')
|
|
250885
|
-
});
|
|
250886
|
-
});
|
|
250887
|
-
inputSchema6 = lazySchema(() => {
|
|
250888
|
-
const schema = fullInputSchema().omit({
|
|
250889
|
-
cwd: true
|
|
250890
|
-
});
|
|
250891
|
-
return isBackgroundTasksDisabled || isForkSubagentEnabled() ? schema.omit({
|
|
250892
|
-
run_in_background: true
|
|
250893
|
-
}) : schema;
|
|
250894
|
-
});
|
|
250895
251226
|
outputSchema5 = lazySchema(() => {
|
|
250896
251227
|
const syncOutputSchema = agentToolResultSchema().extend({
|
|
250897
251228
|
status: exports_external2.literal("completed"),
|
|
@@ -250907,7 +251238,9 @@ var init_AgentTool = __esm(() => {
|
|
|
250907
251238
|
});
|
|
250908
251239
|
return exports_external2.union([syncOutputSchema, asyncOutputSchema]);
|
|
250909
251240
|
});
|
|
250910
|
-
|
|
251241
|
+
advertisedInputJSONSchemaCache = new Map;
|
|
251242
|
+
advertisedWorktreeAvailabilityByQuery = new WeakMap;
|
|
251243
|
+
agentToolRuntime = buildToolRuntime({
|
|
250911
251244
|
async prompt({
|
|
250912
251245
|
agents,
|
|
250913
251246
|
tools,
|
|
@@ -250937,9 +251270,7 @@ var init_AgentTool = __esm(() => {
|
|
|
250937
251270
|
async description() {
|
|
250938
251271
|
return "Launch a new agent";
|
|
250939
251272
|
},
|
|
250940
|
-
|
|
250941
|
-
return inputSchema6();
|
|
250942
|
-
},
|
|
251273
|
+
inputSchema: inputSchema6(),
|
|
250943
251274
|
get outputSchema() {
|
|
250944
251275
|
return outputSchema5();
|
|
250945
251276
|
},
|
|
@@ -250955,6 +251286,10 @@ var init_AgentTool = __esm(() => {
|
|
|
250955
251286
|
isolation,
|
|
250956
251287
|
cwd
|
|
250957
251288
|
}, toolUseContext, canUseTool, assistantMessage, onProgress) {
|
|
251289
|
+
const earlierDuplicateId = findEarlierDuplicateAgentToolUse(assistantMessage, toolUseContext.toolUseId);
|
|
251290
|
+
if (earlierDuplicateId) {
|
|
251291
|
+
throw new Error(`Duplicate Agent call skipped: this input duplicates earlier call ${earlierDuplicateId}. Do not retry it; wait for the earlier Agent result.`);
|
|
251292
|
+
}
|
|
250958
251293
|
const startTime = Date.now();
|
|
250959
251294
|
const model = isCoordinatorMode() ? undefined : modelParam;
|
|
250960
251295
|
const appState = toolUseContext.getAppState();
|
|
@@ -251191,15 +251526,16 @@ ${reasons}`);
|
|
|
251191
251526
|
try {
|
|
251192
251527
|
worktreeInfo = await createAgentWorktree(slug);
|
|
251193
251528
|
} catch (error41) {
|
|
251194
|
-
|
|
251195
|
-
if (message.includes("Cannot create agent worktree: not in a git repository")) {
|
|
251196
|
-
if (isolation === "worktree") {
|
|
251197
|
-
throw error41;
|
|
251198
|
-
}
|
|
251199
|
-
logForDebugging("Agent worktree isolation unavailable outside a git repository; falling back to the current working directory.");
|
|
251200
|
-
} else {
|
|
251529
|
+
if (!(error41 instanceof WorktreeUnavailableError)) {
|
|
251201
251530
|
throw error41;
|
|
251202
251531
|
}
|
|
251532
|
+
const unavailableMessage = getWorktreeIsolationUnavailableMessage(error41.reason);
|
|
251533
|
+
if (isolation === "worktree") {
|
|
251534
|
+
throw new ToolContinuationStopError(unavailableMessage, {
|
|
251535
|
+
cause: error41
|
|
251536
|
+
});
|
|
251537
|
+
}
|
|
251538
|
+
logForDebugging(`${unavailableMessage} Falling back to the current working directory.`);
|
|
251203
251539
|
}
|
|
251204
251540
|
}
|
|
251205
251541
|
if (isForkPath && worktreeInfo) {
|
|
@@ -251792,6 +252128,15 @@ duration_ms: ${data.totalDurationMs}</usage>`
|
|
|
251792
252128
|
renderToolUseErrorMessage,
|
|
251793
252129
|
renderGroupedToolUse: renderGroupedAgentToolUse
|
|
251794
252130
|
});
|
|
252131
|
+
AgentTool = {
|
|
252132
|
+
...agentToolRuntime,
|
|
252133
|
+
get inputSchema() {
|
|
252134
|
+
return inputSchema6();
|
|
252135
|
+
},
|
|
252136
|
+
get inputJSONSchema() {
|
|
252137
|
+
return getAdvertisedAgentInputJSONSchema();
|
|
252138
|
+
}
|
|
252139
|
+
};
|
|
251795
252140
|
});
|
|
251796
252141
|
|
|
251797
252142
|
// node_modules/.bun/lodash-es@4.18.0/node_modules/lodash-es/_baseSlice.js
|
|
@@ -251938,7 +252283,7 @@ var init_idePathConversion = () => {};
|
|
|
251938
252283
|
|
|
251939
252284
|
// src/capabilities/ide.ts
|
|
251940
252285
|
import { createConnection } from "net";
|
|
251941
|
-
import { basename as basename11, join as join49, sep as pathSeparator, resolve as
|
|
252286
|
+
import { basename as basename11, join as join49, sep as pathSeparator, resolve as resolve17 } from "path";
|
|
251942
252287
|
function isVSCodeIde(ide) {
|
|
251943
252288
|
if (!ide)
|
|
251944
252289
|
return false;
|
|
@@ -251953,7 +252298,7 @@ function isJetBrainsIde(ide) {
|
|
|
251953
252298
|
}
|
|
251954
252299
|
async function checkIdeConnection(host, port, timeout = 500) {
|
|
251955
252300
|
try {
|
|
251956
|
-
return new Promise((
|
|
252301
|
+
return new Promise((resolve18) => {
|
|
251957
252302
|
const socket = createConnection({
|
|
251958
252303
|
host,
|
|
251959
252304
|
port,
|
|
@@ -251961,14 +252306,14 @@ async function checkIdeConnection(host, port, timeout = 500) {
|
|
|
251961
252306
|
});
|
|
251962
252307
|
socket.on("connect", () => {
|
|
251963
252308
|
socket.destroy();
|
|
251964
|
-
|
|
252309
|
+
resolve18(true);
|
|
251965
252310
|
});
|
|
251966
252311
|
socket.on("error", () => {
|
|
251967
|
-
|
|
252312
|
+
resolve18(false);
|
|
251968
252313
|
});
|
|
251969
252314
|
socket.on("timeout", () => {
|
|
251970
252315
|
socket.destroy();
|
|
251971
|
-
|
|
252316
|
+
resolve18(false);
|
|
251972
252317
|
});
|
|
251973
252318
|
});
|
|
251974
252319
|
} catch (_) {
|
|
@@ -255654,7 +255999,7 @@ async function getSnapshotScript(shellPath, snapshotFilePath, configFileExists)
|
|
|
255654
255999
|
var LITERAL_BACKSLASH = "\\", SNAPSHOT_CREATION_TIMEOUT = 1e4, VCS_DIRECTORIES_TO_EXCLUDE2, createAndSaveSnapshot = async (binShell) => {
|
|
255655
256000
|
const shellType = binShell.includes("zsh") ? "zsh" : binShell.includes("bash") ? "bash" : "sh";
|
|
255656
256001
|
logForDebugging(`Creating shell snapshot for ${shellType} (${binShell})`);
|
|
255657
|
-
return new Promise(async (
|
|
256002
|
+
return new Promise(async (resolve18) => {
|
|
255658
256003
|
try {
|
|
255659
256004
|
const configFile = getConfigFile(binShell);
|
|
255660
256005
|
logForDebugging(`Looking for shell config file: ${configFile}`);
|
|
@@ -255715,7 +256060,7 @@ ${stdout}`);
|
|
|
255715
256060
|
error_signal_number: signalNumber,
|
|
255716
256061
|
error_killed: execError?.killed
|
|
255717
256062
|
});
|
|
255718
|
-
|
|
256063
|
+
resolve18(undefined);
|
|
255719
256064
|
} else {
|
|
255720
256065
|
let snapshotSize;
|
|
255721
256066
|
try {
|
|
@@ -255731,7 +256076,7 @@ ${stdout}`);
|
|
|
255731
256076
|
logForDebugging(`Error cleaning up session snapshot: ${error42}`);
|
|
255732
256077
|
}
|
|
255733
256078
|
});
|
|
255734
|
-
|
|
256079
|
+
resolve18(shellSnapshotPath);
|
|
255735
256080
|
} else {
|
|
255736
256081
|
logForDebugging(`Shell snapshot file not found after creation: ${shellSnapshotPath}`);
|
|
255737
256082
|
logForDebugging(`Checking if parent directory still exists: ${snapshotsDir}`);
|
|
@@ -255742,7 +256087,7 @@ ${stdout}`);
|
|
|
255742
256087
|
logForDebugging(`Parent directory does not exist or is not accessible: ${snapshotsDir}`);
|
|
255743
256088
|
}
|
|
255744
256089
|
logEvent("tengu_shell_unknown_error", {});
|
|
255745
|
-
|
|
256090
|
+
resolve18(undefined);
|
|
255746
256091
|
}
|
|
255747
256092
|
}
|
|
255748
256093
|
});
|
|
@@ -255753,7 +256098,7 @@ ${stdout}`);
|
|
|
255753
256098
|
}
|
|
255754
256099
|
logError(error41);
|
|
255755
256100
|
logEvent("tengu_shell_snapshot_error", {});
|
|
255756
|
-
|
|
256101
|
+
resolve18(undefined);
|
|
255757
256102
|
}
|
|
255758
256103
|
});
|
|
255759
256104
|
};
|
|
@@ -256158,7 +256503,7 @@ var init_bashProvider = __esm(() => {
|
|
|
256158
256503
|
import { spawn as spawn5 } from "child_process";
|
|
256159
256504
|
import { constants as fsConstants4, readFileSync as readFileSync6, unlinkSync as unlinkSync2 } from "fs";
|
|
256160
256505
|
import { mkdir as mkdir4, open as open4, realpath as realpath4 } from "fs/promises";
|
|
256161
|
-
import { isAbsolute as isAbsolute16, resolve as
|
|
256506
|
+
import { isAbsolute as isAbsolute16, resolve as resolve18 } from "path";
|
|
256162
256507
|
import { join as posixJoin3 } from "path/posix";
|
|
256163
256508
|
async function findSuitableShell() {
|
|
256164
256509
|
return (await requireShellCapability("bash")).path;
|
|
@@ -256299,7 +256644,7 @@ async function exec2(command, abortSignal, shellType, options2) {
|
|
|
256299
256644
|
}
|
|
256300
256645
|
}
|
|
256301
256646
|
function setCwd(path10, relativeTo) {
|
|
256302
|
-
const resolved = isAbsolute16(path10) ? path10 :
|
|
256647
|
+
const resolved = isAbsolute16(path10) ? path10 : resolve18(relativeTo || getFsImplementation().cwd(), path10);
|
|
256303
256648
|
let physicalPath;
|
|
256304
256649
|
try {
|
|
256305
256650
|
physicalPath = getFsImplementation().realpathSync(resolved);
|
|
@@ -256652,7 +256997,7 @@ var init_notebook = __esm(() => {
|
|
|
256652
256997
|
var DESCRIPTION6 = "Replace the contents of a specific cell in a Jupyter notebook.", PROMPT4 = `Completely replaces the contents of a specific cell in a Jupyter notebook (.ipynb file) with new source. Jupyter notebooks are interactive documents that combine code, text, and visualizations, commonly used for data analysis and scientific computing. The notebook_path parameter must be an absolute path, not a relative path. The cell_number is 0-indexed. Use edit_mode=insert to add a new cell at the index specified by cell_number. Use edit_mode=delete to delete the cell at the index specified by cell_number.`;
|
|
256653
256998
|
|
|
256654
256999
|
// src/capabilities/tools/NotebookEditTool/NotebookEditTool.ts
|
|
256655
|
-
import { extname as extname5, isAbsolute as isAbsolute17, resolve as
|
|
257000
|
+
import { extname as extname5, isAbsolute as isAbsolute17, resolve as resolve19 } from "path";
|
|
256656
257001
|
var getToolUseSummary5, renderToolResultMessage8, renderToolUseErrorMessage6, renderToolUseMessage8, renderToolUseRejectedMessage4, inputSchema11, outputSchema10, NotebookEditTool;
|
|
256657
257002
|
var init_NotebookEditTool = __esm(() => {
|
|
256658
257003
|
init_fileHistory();
|
|
@@ -256767,7 +257112,7 @@ var init_NotebookEditTool = __esm(() => {
|
|
|
256767
257112
|
renderToolUseErrorMessage: renderToolUseErrorMessage6,
|
|
256768
257113
|
renderToolResultMessage: renderToolResultMessage8,
|
|
256769
257114
|
async validateInput({ notebook_path, cell_type, cell_id, edit_mode = "replace" }, toolUseContext) {
|
|
256770
|
-
const fullPath = isAbsolute17(notebook_path) ? notebook_path :
|
|
257115
|
+
const fullPath = isAbsolute17(notebook_path) ? notebook_path : resolve19(getCwd3(), notebook_path);
|
|
256771
257116
|
if (fullPath.startsWith("\\\\") || fullPath.startsWith("//")) {
|
|
256772
257117
|
return { result: true };
|
|
256773
257118
|
}
|
|
@@ -256866,7 +257211,7 @@ var init_NotebookEditTool = __esm(() => {
|
|
|
256866
257211
|
cell_type,
|
|
256867
257212
|
edit_mode: originalEditMode
|
|
256868
257213
|
}, { readFileState, updateFileHistoryState }, _, parentMessage) {
|
|
256869
|
-
const fullPath = isAbsolute17(notebook_path) ? notebook_path :
|
|
257214
|
+
const fullPath = isAbsolute17(notebook_path) ? notebook_path : resolve19(getCwd3(), notebook_path);
|
|
256870
257215
|
if (fileHistoryEnabled()) {
|
|
256871
257216
|
await fileHistoryTrackEdit(updateFileHistoryState, fullPath, parentMessage.uuid);
|
|
256872
257217
|
}
|
|
@@ -257126,7 +257471,7 @@ var init_gitOperationTracking = __esm(() => {
|
|
|
257126
257471
|
});
|
|
257127
257472
|
|
|
257128
257473
|
// src/session/fullscreen.ts
|
|
257129
|
-
import { spawnSync as
|
|
257474
|
+
import { spawnSync as spawnSync3 } from "child_process";
|
|
257130
257475
|
function isTmuxControlModeEnvHeuristic() {
|
|
257131
257476
|
if (!process.env.TMUX)
|
|
257132
257477
|
return false;
|
|
@@ -257145,7 +257490,7 @@ function probeTmuxControlModeSync() {
|
|
|
257145
257490
|
return;
|
|
257146
257491
|
let result;
|
|
257147
257492
|
try {
|
|
257148
|
-
result =
|
|
257493
|
+
result = spawnSync3("tmux", ["display-message", "-p", "#{client_control_mode}"], { encoding: "utf8", timeout: 2000 });
|
|
257149
257494
|
} catch {
|
|
257150
257495
|
return;
|
|
257151
257496
|
}
|
|
@@ -257638,8 +257983,8 @@ function registerAgentForeground({
|
|
|
257638
257983
|
diskLoaded: false
|
|
257639
257984
|
};
|
|
257640
257985
|
let resolveBackgroundSignal;
|
|
257641
|
-
const backgroundSignal = new Promise((
|
|
257642
|
-
resolveBackgroundSignal =
|
|
257986
|
+
const backgroundSignal = new Promise((resolve20) => {
|
|
257987
|
+
resolveBackgroundSignal = resolve20;
|
|
257643
257988
|
});
|
|
257644
257989
|
backgroundSignalResolvers.set(agentId, resolveBackgroundSignal);
|
|
257645
257990
|
registerTask(taskState, setAppState);
|
|
@@ -257722,6 +258067,75 @@ var init_LocalAgentTask = __esm(() => {
|
|
|
257722
258067
|
backgroundSignalResolvers = new Map;
|
|
257723
258068
|
});
|
|
257724
258069
|
|
|
258070
|
+
// src/session/backgroundTaskScope.ts
|
|
258071
|
+
class BackgroundTaskScope {
|
|
258072
|
+
tasks = new Set;
|
|
258073
|
+
stopPromise;
|
|
258074
|
+
stopped = false;
|
|
258075
|
+
register(task) {
|
|
258076
|
+
let registered = true;
|
|
258077
|
+
const unregister = () => {
|
|
258078
|
+
if (!registered)
|
|
258079
|
+
return;
|
|
258080
|
+
registered = false;
|
|
258081
|
+
this.tasks.delete(task);
|
|
258082
|
+
};
|
|
258083
|
+
this.tasks.add(task);
|
|
258084
|
+
task.settled.then(unregister, unregister);
|
|
258085
|
+
if (this.stopped) {
|
|
258086
|
+
this.stopTask(task).finally(unregister).catch(() => {});
|
|
258087
|
+
}
|
|
258088
|
+
return unregister;
|
|
258089
|
+
}
|
|
258090
|
+
stop() {
|
|
258091
|
+
if (!this.stopPromise) {
|
|
258092
|
+
this.stopPromise = this.drain().finally(() => {
|
|
258093
|
+
this.stopped = true;
|
|
258094
|
+
});
|
|
258095
|
+
}
|
|
258096
|
+
return this.stopPromise;
|
|
258097
|
+
}
|
|
258098
|
+
async drain() {
|
|
258099
|
+
const failures = [];
|
|
258100
|
+
while (this.tasks.size > 0) {
|
|
258101
|
+
const tasks = [...this.tasks];
|
|
258102
|
+
const results = await Promise.allSettled(tasks.map((task) => this.stopTask(task)));
|
|
258103
|
+
for (const result of results) {
|
|
258104
|
+
if (result.status === "rejected")
|
|
258105
|
+
failures.push(result.reason);
|
|
258106
|
+
}
|
|
258107
|
+
for (const task of tasks) {
|
|
258108
|
+
this.tasks.delete(task);
|
|
258109
|
+
}
|
|
258110
|
+
}
|
|
258111
|
+
if (failures.length > 0) {
|
|
258112
|
+
throw new AggregateError(failures, "BackgroundTaskScope cleanup failed");
|
|
258113
|
+
}
|
|
258114
|
+
}
|
|
258115
|
+
async stopTask(task) {
|
|
258116
|
+
try {
|
|
258117
|
+
await task.stop();
|
|
258118
|
+
} finally {
|
|
258119
|
+
await task.settled;
|
|
258120
|
+
}
|
|
258121
|
+
}
|
|
258122
|
+
}
|
|
258123
|
+
function bindBackgroundTaskScope(setAppState, scope) {
|
|
258124
|
+
scopesBySetAppState.set(setAppState, scope);
|
|
258125
|
+
return () => {
|
|
258126
|
+
if (scopesBySetAppState.get(setAppState) === scope) {
|
|
258127
|
+
scopesBySetAppState.delete(setAppState);
|
|
258128
|
+
}
|
|
258129
|
+
};
|
|
258130
|
+
}
|
|
258131
|
+
function getBackgroundTaskScope(setAppState) {
|
|
258132
|
+
return scopesBySetAppState.get(setAppState);
|
|
258133
|
+
}
|
|
258134
|
+
var scopesBySetAppState;
|
|
258135
|
+
var init_backgroundTaskScope = __esm(() => {
|
|
258136
|
+
scopesBySetAppState = new WeakMap;
|
|
258137
|
+
});
|
|
258138
|
+
|
|
257725
258139
|
// src/tasks/LocalShellTask/LocalShellTask.ts
|
|
257726
258140
|
function looksLikePrompt(tail) {
|
|
257727
258141
|
const lastLine = tail.trimEnd().split(`
|
|
@@ -257850,26 +258264,9 @@ async function spawnShellTask(input, context3) {
|
|
|
257850
258264
|
taskOutput
|
|
257851
258265
|
} = shellCommand;
|
|
257852
258266
|
const taskId = taskOutput.taskId;
|
|
257853
|
-
|
|
257854
|
-
|
|
257855
|
-
|
|
257856
|
-
const taskState = {
|
|
257857
|
-
...createTaskStateBase(taskId, "local_bash", description, toolUseId),
|
|
257858
|
-
type: "local_bash",
|
|
257859
|
-
status: "running",
|
|
257860
|
-
command,
|
|
257861
|
-
completionStatusSentInAttachment: false,
|
|
257862
|
-
shellCommand,
|
|
257863
|
-
unregisterCleanup,
|
|
257864
|
-
lastReportedTotalLines: 0,
|
|
257865
|
-
isBackgrounded: true,
|
|
257866
|
-
agentId,
|
|
257867
|
-
kind
|
|
257868
|
-
};
|
|
257869
|
-
registerTask(taskState, setAppState);
|
|
257870
|
-
shellCommand.background(taskId);
|
|
257871
|
-
const cancelStallWatchdog = startStallWatchdog(taskId, description, kind, toolUseId, agentId);
|
|
257872
|
-
shellCommand.result.then(async (result) => {
|
|
258267
|
+
let unregisterCleanup = () => {};
|
|
258268
|
+
let cancelStallWatchdog = () => {};
|
|
258269
|
+
const settled = shellCommand.result.then(async (result) => {
|
|
257873
258270
|
cancelStallWatchdog();
|
|
257874
258271
|
await flushAndCleanup(shellCommand);
|
|
257875
258272
|
let wasKilled = false;
|
|
@@ -257892,12 +258289,43 @@ async function spawnShellTask(input, context3) {
|
|
|
257892
258289
|
});
|
|
257893
258290
|
enqueueShellNotification(taskId, description, wasKilled ? "killed" : result.code === 0 ? "completed" : "failed", result.code, setAppState, toolUseId, kind, agentId);
|
|
257894
258291
|
evictTaskOutput(taskId);
|
|
258292
|
+
}).catch((error41) => {
|
|
258293
|
+
cancelStallWatchdog();
|
|
258294
|
+
logError(error41);
|
|
258295
|
+
}).finally(() => {
|
|
258296
|
+
unregisterCleanup();
|
|
257895
258297
|
});
|
|
258298
|
+
const stopAndSettle = async () => {
|
|
258299
|
+
killTask(taskId, setAppState);
|
|
258300
|
+
await settled;
|
|
258301
|
+
};
|
|
258302
|
+
const cleanupRegistration = () => {
|
|
258303
|
+
unregisterCleanup();
|
|
258304
|
+
};
|
|
258305
|
+
const taskState = {
|
|
258306
|
+
...createTaskStateBase(taskId, "local_bash", description, toolUseId),
|
|
258307
|
+
type: "local_bash",
|
|
258308
|
+
status: "running",
|
|
258309
|
+
command,
|
|
258310
|
+
completionStatusSentInAttachment: false,
|
|
258311
|
+
shellCommand,
|
|
258312
|
+
unregisterCleanup: cleanupRegistration,
|
|
258313
|
+
lastReportedTotalLines: 0,
|
|
258314
|
+
isBackgrounded: true,
|
|
258315
|
+
agentId,
|
|
258316
|
+
kind
|
|
258317
|
+
};
|
|
258318
|
+
registerTask(taskState, setAppState);
|
|
258319
|
+
const owner = getBackgroundTaskScope(setAppState);
|
|
258320
|
+
unregisterCleanup = owner ? owner.register({
|
|
258321
|
+
stop: stopAndSettle,
|
|
258322
|
+
settled
|
|
258323
|
+
}) : registerCleanup(stopAndSettle);
|
|
258324
|
+
shellCommand.background(taskId);
|
|
258325
|
+
cancelStallWatchdog = startStallWatchdog(taskId, description, kind, toolUseId, agentId);
|
|
257896
258326
|
return {
|
|
257897
258327
|
taskId,
|
|
257898
|
-
cleanup:
|
|
257899
|
-
unregisterCleanup();
|
|
257900
|
-
}
|
|
258328
|
+
cleanup: cleanupRegistration
|
|
257901
258329
|
};
|
|
257902
258330
|
}
|
|
257903
258331
|
function registerForeground(input, setAppState, toolUseId) {
|
|
@@ -258026,6 +258454,7 @@ var init_LocalShellTask = __esm(() => {
|
|
|
258026
258454
|
init_LocalAgentTask();
|
|
258027
258455
|
init_killShellTasks();
|
|
258028
258456
|
init_fsOperations();
|
|
258457
|
+
init_backgroundTaskScope();
|
|
258029
258458
|
PROMPT_PATTERNS = [
|
|
258030
258459
|
/\(y\/n\)/i,
|
|
258031
258460
|
/\[y\/n\]/i,
|
|
@@ -258984,8 +259413,8 @@ async function* runShellCommand({
|
|
|
258984
259413
|
let assistantAutoBackgrounded = false;
|
|
258985
259414
|
let resolveProgress = null;
|
|
258986
259415
|
function createProgressSignal() {
|
|
258987
|
-
return new Promise((
|
|
258988
|
-
resolveProgress = () =>
|
|
259416
|
+
return new Promise((resolve20) => {
|
|
259417
|
+
resolveProgress = () => resolve20(null);
|
|
258989
259418
|
});
|
|
258990
259419
|
}
|
|
258991
259420
|
const shouldAutoBackground = !isBackgroundTasksDisabled2 && isAutobackgroundingAllowed(command);
|
|
@@ -258996,10 +259425,10 @@ async function* runShellCommand({
|
|
|
258996
259425
|
fullOutput = allLines;
|
|
258997
259426
|
lastTotalLines = totalLines;
|
|
258998
259427
|
lastTotalBytes = isIncomplete ? totalBytes : 0;
|
|
258999
|
-
const
|
|
259000
|
-
if (
|
|
259428
|
+
const resolve20 = resolveProgress;
|
|
259429
|
+
if (resolve20) {
|
|
259001
259430
|
resolveProgress = null;
|
|
259002
|
-
|
|
259431
|
+
resolve20();
|
|
259003
259432
|
}
|
|
259004
259433
|
},
|
|
259005
259434
|
preventCwdChanges,
|
|
@@ -259037,10 +259466,10 @@ async function* runShellCommand({
|
|
|
259037
259466
|
}
|
|
259038
259467
|
spawnBackgroundTask().then((shellId) => {
|
|
259039
259468
|
backgroundShellId = shellId;
|
|
259040
|
-
const
|
|
259041
|
-
if (
|
|
259469
|
+
const resolve20 = resolveProgress;
|
|
259470
|
+
if (resolve20) {
|
|
259042
259471
|
resolveProgress = null;
|
|
259043
|
-
|
|
259472
|
+
resolve20();
|
|
259044
259473
|
}
|
|
259045
259474
|
logEvent(eventName, {
|
|
259046
259475
|
command_type: getCommandTypeForLogging(command)
|
|
@@ -259072,8 +259501,8 @@ async function* runShellCommand({
|
|
|
259072
259501
|
const startTime = Date.now();
|
|
259073
259502
|
let foregroundTaskId = undefined;
|
|
259074
259503
|
{
|
|
259075
|
-
const initialResult = await Promise.race([resultPromise, new Promise((
|
|
259076
|
-
const t = setTimeout((r) => r(null), PROGRESS_THRESHOLD_MS2,
|
|
259504
|
+
const initialResult = await Promise.race([resultPromise, new Promise((resolve20) => {
|
|
259505
|
+
const t = setTimeout((r) => r(null), PROGRESS_THRESHOLD_MS2, resolve20);
|
|
259077
259506
|
t.unref();
|
|
259078
259507
|
})]);
|
|
259079
259508
|
if (initialResult !== null) {
|
|
@@ -260596,7 +261025,7 @@ var init_parser5 = __esm(() => {
|
|
|
260596
261025
|
});
|
|
260597
261026
|
|
|
260598
261027
|
// src/capabilities/tools/PowerShellTool/gitSafety.ts
|
|
260599
|
-
import { basename as basename13, posix as posix5, resolve as
|
|
261028
|
+
import { basename as basename13, posix as posix5, resolve as resolve20, sep as sep17 } from "path";
|
|
260600
261029
|
function resolveCwdReentry(normalized) {
|
|
260601
261030
|
if (!normalized.startsWith("../../../tools"))
|
|
260602
261031
|
return normalized;
|
|
@@ -260644,7 +261073,7 @@ function normalizeGitPathArg(arg) {
|
|
|
260644
261073
|
}
|
|
260645
261074
|
function resolveEscapingPathToCwdRelative(n2) {
|
|
260646
261075
|
const cwd = getCwd3();
|
|
260647
|
-
const abs =
|
|
261076
|
+
const abs = resolve20(cwd, n2);
|
|
260648
261077
|
const cwdWithSep = cwd.endsWith(sep17) ? cwd : cwd + sep17;
|
|
260649
261078
|
const absLower = abs.toLowerCase();
|
|
260650
261079
|
const cwdLower = cwd.toLowerCase();
|
|
@@ -261917,7 +262346,7 @@ var init_modeValidation2 = __esm(() => {
|
|
|
261917
262346
|
|
|
261918
262347
|
// src/capabilities/tools/PowerShellTool/pathValidation.ts
|
|
261919
262348
|
import { homedir as homedir18 } from "os";
|
|
261920
|
-
import { isAbsolute as isAbsolute18, resolve as
|
|
262349
|
+
import { isAbsolute as isAbsolute18, resolve as resolve21 } from "path";
|
|
261921
262350
|
function matchesParam(paramLower, paramList) {
|
|
261922
262351
|
for (const p of paramList) {
|
|
261923
262352
|
if (p === paramLower || paramLower.length > 1 && p.startsWith(paramLower)) {
|
|
@@ -262025,7 +262454,7 @@ function checkDenyRuleForGuessedPath(strippedPath, cwd, toolPermissionContext, o
|
|
|
262025
262454
|
if (!strippedPath || strippedPath.includes("\x00"))
|
|
262026
262455
|
return null;
|
|
262027
262456
|
const tildeExpanded = expandTilde2(strippedPath);
|
|
262028
|
-
const abs = isAbsolute18(tildeExpanded) ? tildeExpanded :
|
|
262457
|
+
const abs = isAbsolute18(tildeExpanded) ? tildeExpanded : resolve21(cwd, tildeExpanded);
|
|
262029
262458
|
const { resolvedPath } = safeResolvePath(getFsImplementation(), abs);
|
|
262030
262459
|
const permissionType = operationType === "read" ? "read" : "edit";
|
|
262031
262460
|
const denyRule = matchingRuleForInput(resolvedPath, toolPermissionContext, permissionType, "deny");
|
|
@@ -262115,7 +262544,7 @@ function validatePath2(filePath, cwd, toolPermissionContext, operationType) {
|
|
|
262115
262544
|
};
|
|
262116
262545
|
}
|
|
262117
262546
|
if (containsPathTraversal(normalizedPath)) {
|
|
262118
|
-
const absolutePath2 = isAbsolute18(normalizedPath) ? normalizedPath :
|
|
262547
|
+
const absolutePath2 = isAbsolute18(normalizedPath) ? normalizedPath : resolve21(cwd, normalizedPath);
|
|
262119
262548
|
const { resolvedPath: resolvedPath3, isCanonical: isCanonical2 } = safeResolvePath(getFsImplementation(), absolutePath2);
|
|
262120
262549
|
const result2 = isPathAllowed2(resolvedPath3, toolPermissionContext, operationType, isCanonical2 ? [resolvedPath3] : undefined);
|
|
262121
262550
|
return {
|
|
@@ -262125,7 +262554,7 @@ function validatePath2(filePath, cwd, toolPermissionContext, operationType) {
|
|
|
262125
262554
|
};
|
|
262126
262555
|
}
|
|
262127
262556
|
const basePath = getGlobBaseDirectory2(normalizedPath);
|
|
262128
|
-
const absoluteBasePath = isAbsolute18(basePath) ? basePath :
|
|
262557
|
+
const absoluteBasePath = isAbsolute18(basePath) ? basePath : resolve21(cwd, basePath);
|
|
262129
262558
|
const { resolvedPath: resolvedPath2 } = safeResolvePath(getFsImplementation(), absoluteBasePath);
|
|
262130
262559
|
const permissionType = operationType === "read" ? "read" : "edit";
|
|
262131
262560
|
const denyRule = matchingRuleForInput(resolvedPath2, toolPermissionContext, permissionType, "deny");
|
|
@@ -262145,7 +262574,7 @@ function validatePath2(filePath, cwd, toolPermissionContext, operationType) {
|
|
|
262145
262574
|
}
|
|
262146
262575
|
};
|
|
262147
262576
|
}
|
|
262148
|
-
const absolutePath = isAbsolute18(normalizedPath) ? normalizedPath :
|
|
262577
|
+
const absolutePath = isAbsolute18(normalizedPath) ? normalizedPath : resolve21(cwd, normalizedPath);
|
|
262149
262578
|
const { resolvedPath, isCanonical } = safeResolvePath(getFsImplementation(), absolutePath);
|
|
262150
262579
|
const result = isPathAllowed2(resolvedPath, toolPermissionContext, operationType, isCanonical ? [resolvedPath] : undefined);
|
|
262151
262580
|
return {
|
|
@@ -264075,7 +264504,7 @@ var init_powershellSecurity = __esm(() => {
|
|
|
264075
264504
|
var POWERSHELL_TOOL_NAME3 = "PowerShell";
|
|
264076
264505
|
|
|
264077
264506
|
// src/capabilities/tools/PowerShellTool/powershellPermissions.ts
|
|
264078
|
-
import { resolve as
|
|
264507
|
+
import { resolve as resolve22 } from "path";
|
|
264079
264508
|
async function extractCommandName(command) {
|
|
264080
264509
|
const trimmed = command.trim();
|
|
264081
264510
|
if (!trimmed) {
|
|
@@ -264688,7 +265117,7 @@ async function powershellToolHasPermission(input, context3) {
|
|
|
264688
265117
|
const canonical = resolveToCanonical(element.name);
|
|
264689
265118
|
if (canonical === "set-location" && element.args.length > 0) {
|
|
264690
265119
|
const target = element.args.find((a2) => a2.length === 0 || !PS_TOKENIZER_DASH_CHARS.has(a2[0]));
|
|
264691
|
-
if (target &&
|
|
265120
|
+
if (target && resolve22(getCwd3(), target) === getCwd3()) {
|
|
264692
265121
|
return false;
|
|
264693
265122
|
}
|
|
264694
265123
|
}
|
|
@@ -265084,8 +265513,8 @@ async function* runPowerShellCommand({
|
|
|
265084
265513
|
let assistantAutoBackgrounded = false;
|
|
265085
265514
|
let resolveProgress = null;
|
|
265086
265515
|
function createProgressSignal() {
|
|
265087
|
-
return new Promise((
|
|
265088
|
-
resolveProgress = () =>
|
|
265516
|
+
return new Promise((resolve23) => {
|
|
265517
|
+
resolveProgress = () => resolve23(null);
|
|
265089
265518
|
});
|
|
265090
265519
|
}
|
|
265091
265520
|
const shouldAutoBackground = !isBackgroundTasksDisabled3 && isAutobackgroundingAllowed2(command);
|
|
@@ -265155,10 +265584,10 @@ async function* runPowerShellCommand({
|
|
|
265155
265584
|
}
|
|
265156
265585
|
spawnBackgroundTask().then((shellId) => {
|
|
265157
265586
|
backgroundShellId = shellId;
|
|
265158
|
-
const
|
|
265159
|
-
if (
|
|
265587
|
+
const resolve23 = resolveProgress;
|
|
265588
|
+
if (resolve23) {
|
|
265160
265589
|
resolveProgress = null;
|
|
265161
|
-
|
|
265590
|
+
resolve23();
|
|
265162
265591
|
}
|
|
265163
265592
|
logEvent(eventName, {
|
|
265164
265593
|
command_type: getCommandTypeForLogging2(command)
|
|
@@ -265196,7 +265625,7 @@ async function* runPowerShellCommand({
|
|
|
265196
265625
|
const now = Date.now();
|
|
265197
265626
|
const timeUntilNextProgress = Math.max(0, nextProgressTime - now);
|
|
265198
265627
|
const progressSignal = createProgressSignal();
|
|
265199
|
-
const result = await Promise.race([resultPromise, new Promise((
|
|
265628
|
+
const result = await Promise.race([resultPromise, new Promise((resolve23) => setTimeout((r) => r(null), timeUntilNextProgress, resolve23).unref()), progressSignal]);
|
|
265200
265629
|
if (result !== null) {
|
|
265201
265630
|
if (result.backgroundTaskId !== undefined) {
|
|
265202
265631
|
markTaskNotified2(result.backgroundTaskId, setAppState);
|
|
@@ -267794,7 +268223,7 @@ var init_officialMarketplaceGcs = __esm(() => {
|
|
|
267794
268223
|
});
|
|
267795
268224
|
|
|
267796
268225
|
// src/capabilities/plugins/marketplaceManager.ts
|
|
267797
|
-
import { basename as basename18, dirname as dirname31, isAbsolute as isAbsolute20, join as join59, resolve as
|
|
268226
|
+
import { basename as basename18, dirname as dirname31, isAbsolute as isAbsolute20, join as join59, resolve as resolve23, sep as sep18 } from "path";
|
|
267798
268227
|
function getKnownMarketplacesFile() {
|
|
267799
268228
|
return join59(getPluginsDirectory(), "known_marketplaces.json");
|
|
267800
268229
|
}
|
|
@@ -268360,14 +268789,14 @@ async function loadAndCacheMarketplace(source, onProgress) {
|
|
|
268360
268789
|
throw new Error("NPM marketplace sources not yet implemented");
|
|
268361
268790
|
}
|
|
268362
268791
|
case "file": {
|
|
268363
|
-
const absPath =
|
|
268792
|
+
const absPath = resolve23(source.path);
|
|
268364
268793
|
marketplacePath = absPath;
|
|
268365
268794
|
temporaryCachePath = dirname31(dirname31(absPath));
|
|
268366
268795
|
cleanupNeeded = false;
|
|
268367
268796
|
break;
|
|
268368
268797
|
}
|
|
268369
268798
|
case "directory": {
|
|
268370
|
-
const absPath =
|
|
268799
|
+
const absPath = resolve23(source.path);
|
|
268371
268800
|
marketplacePath = join59(absPath, ".claude-plugin", "marketplace.json");
|
|
268372
268801
|
temporaryCachePath = absPath;
|
|
268373
268802
|
cleanupNeeded = false;
|
|
@@ -268399,8 +268828,8 @@ async function loadAndCacheMarketplace(source, onProgress) {
|
|
|
268399
268828
|
throw new Error(`Failed to parse marketplace file at ${marketplacePath}: ${errorMessage(e)}`);
|
|
268400
268829
|
}
|
|
268401
268830
|
const finalCachePath = join59(cacheDir, marketplace.name);
|
|
268402
|
-
const resolvedFinal =
|
|
268403
|
-
const resolvedCacheDir =
|
|
268831
|
+
const resolvedFinal = resolve23(finalCachePath);
|
|
268832
|
+
const resolvedCacheDir = resolve23(cacheDir);
|
|
268404
268833
|
if (!resolvedFinal.startsWith(resolvedCacheDir + sep18)) {
|
|
268405
268834
|
throw new Error(`Marketplace name '${marketplace.name}' resolves to a path outside the cache directory`);
|
|
268406
268835
|
}
|
|
@@ -268761,11 +269190,11 @@ var init_pluginVersioning = __esm(() => {
|
|
|
268761
269190
|
});
|
|
268762
269191
|
|
|
268763
269192
|
// src/capabilities/plugins/pluginInstallationHelpers.ts
|
|
268764
|
-
import { dirname as dirname33, join as join61, resolve as
|
|
269193
|
+
import { dirname as dirname33, join as join61, resolve as resolve24, sep as sep19 } from "path";
|
|
268765
269194
|
function validatePathWithinBase(basePath, relativePath2) {
|
|
268766
|
-
const resolvedPath =
|
|
268767
|
-
const normalizedBase =
|
|
268768
|
-
if (!resolvedPath.startsWith(normalizedBase) && resolvedPath !==
|
|
269195
|
+
const resolvedPath = resolve24(basePath, relativePath2);
|
|
269196
|
+
const normalizedBase = resolve24(basePath) + sep19;
|
|
269197
|
+
if (!resolvedPath.startsWith(normalizedBase) && resolvedPath !== resolve24(basePath)) {
|
|
268769
269198
|
throw new Error(`Path traversal detected: "${relativePath2}" would escape the base directory`);
|
|
268770
269199
|
}
|
|
268771
269200
|
return resolvedPath;
|
|
@@ -268791,7 +269220,7 @@ var init_pluginInstallationHelpers = __esm(() => {
|
|
|
268791
269220
|
});
|
|
268792
269221
|
|
|
268793
269222
|
// src/capabilities/plugins/pluginLoader.ts
|
|
268794
|
-
import { basename as basename19, dirname as dirname34, join as join62, relative as relative11, resolve as
|
|
269223
|
+
import { basename as basename19, dirname as dirname34, join as join62, relative as relative11, resolve as resolve25, sep as sep20 } from "path";
|
|
268795
269224
|
function getPluginCachePath() {
|
|
268796
269225
|
return join62(getPluginsDirectory(), "cache");
|
|
268797
269226
|
}
|
|
@@ -270145,7 +270574,7 @@ async function loadSessionOnlyPlugins(sessionPluginPaths) {
|
|
|
270145
270574
|
const errors4 = [];
|
|
270146
270575
|
for (const [index, pluginPath] of sessionPluginPaths.entries()) {
|
|
270147
270576
|
try {
|
|
270148
|
-
const resolvedPath =
|
|
270577
|
+
const resolvedPath = resolve25(pluginPath);
|
|
270149
270578
|
if (!await pathExists(resolvedPath)) {
|
|
270150
270579
|
logForDebugging(`Plugin path does not exist: ${resolvedPath}, skipping`, { level: "warn" });
|
|
270151
270580
|
errors4.push({
|
|
@@ -271512,14 +271941,14 @@ function waitForCallback(port, expectedState, abortSignal, onListening) {
|
|
|
271512
271941
|
abortHandler = null;
|
|
271513
271942
|
}
|
|
271514
271943
|
};
|
|
271515
|
-
return new Promise((
|
|
271944
|
+
return new Promise((resolve26, reject2) => {
|
|
271516
271945
|
let resolved = false;
|
|
271517
271946
|
const resolveOnce = (v) => {
|
|
271518
271947
|
if (resolved)
|
|
271519
271948
|
return;
|
|
271520
271949
|
resolved = true;
|
|
271521
271950
|
cleanup();
|
|
271522
|
-
|
|
271951
|
+
resolve26(v);
|
|
271523
271952
|
};
|
|
271524
271953
|
const rejectOnce = (e) => {
|
|
271525
271954
|
if (resolved)
|
|
@@ -271990,13 +272419,13 @@ async function performMCPOAuthFlow(serverName, serverConfig, onAuthorizationUrl,
|
|
|
271990
272419
|
}
|
|
271991
272420
|
logMCPDebug(serverName, `MCP OAuth server cleaned up`);
|
|
271992
272421
|
};
|
|
271993
|
-
const authorizationCode = await new Promise((
|
|
272422
|
+
const authorizationCode = await new Promise((resolve26, reject2) => {
|
|
271994
272423
|
let resolved = false;
|
|
271995
272424
|
const resolveOnce = (code) => {
|
|
271996
272425
|
if (resolved)
|
|
271997
272426
|
return;
|
|
271998
272427
|
resolved = true;
|
|
271999
|
-
|
|
272428
|
+
resolve26(code);
|
|
272000
272429
|
};
|
|
272001
272430
|
const rejectOnce = (error41) => {
|
|
272002
272431
|
if (resolved)
|
|
@@ -272916,8 +273345,8 @@ function createMcpAuthTool(serverName, config2) {
|
|
|
272916
273345
|
}
|
|
272917
273346
|
const sseOrHttpConfig = config2;
|
|
272918
273347
|
let resolveAuthUrl;
|
|
272919
|
-
const authUrlPromise = new Promise((
|
|
272920
|
-
resolveAuthUrl =
|
|
273348
|
+
const authUrlPromise = new Promise((resolve26) => {
|
|
273349
|
+
resolveAuthUrl = resolve26;
|
|
272921
273350
|
});
|
|
272922
273351
|
const controller = new AbortController;
|
|
272923
273352
|
const { setAppState } = context3;
|
|
@@ -273399,15 +273828,15 @@ class WebSocketTransport {
|
|
|
273399
273828
|
isBun = typeof Bun !== "undefined";
|
|
273400
273829
|
constructor(ws) {
|
|
273401
273830
|
this.ws = ws;
|
|
273402
|
-
this.opened = new Promise((
|
|
273831
|
+
this.opened = new Promise((resolve26, reject2) => {
|
|
273403
273832
|
if (this.ws.readyState === WS_OPEN) {
|
|
273404
|
-
|
|
273833
|
+
resolve26();
|
|
273405
273834
|
} else if (this.isBun) {
|
|
273406
273835
|
const nws = this.ws;
|
|
273407
273836
|
const onOpen = () => {
|
|
273408
273837
|
nws.removeEventListener("open", onOpen);
|
|
273409
273838
|
nws.removeEventListener("error", onError);
|
|
273410
|
-
|
|
273839
|
+
resolve26();
|
|
273411
273840
|
};
|
|
273412
273841
|
const onError = (event) => {
|
|
273413
273842
|
nws.removeEventListener("open", onOpen);
|
|
@@ -273420,7 +273849,7 @@ class WebSocketTransport {
|
|
|
273420
273849
|
} else {
|
|
273421
273850
|
const nws = this.ws;
|
|
273422
273851
|
nws.on("open", () => {
|
|
273423
|
-
|
|
273852
|
+
resolve26();
|
|
273424
273853
|
});
|
|
273425
273854
|
nws.on("error", (error41) => {
|
|
273426
273855
|
logForDiagnosticsNoPII("error", "mcp_websocket_connect_fail");
|
|
@@ -273519,12 +273948,12 @@ class WebSocketTransport {
|
|
|
273519
273948
|
if (this.isBun) {
|
|
273520
273949
|
this.ws.send(json2);
|
|
273521
273950
|
} else {
|
|
273522
|
-
await new Promise((
|
|
273951
|
+
await new Promise((resolve26, reject2) => {
|
|
273523
273952
|
this.ws.send(json2, (error41) => {
|
|
273524
273953
|
if (error41) {
|
|
273525
273954
|
reject2(error41);
|
|
273526
273955
|
} else {
|
|
273527
|
-
|
|
273956
|
+
resolve26();
|
|
273528
273957
|
}
|
|
273529
273958
|
});
|
|
273530
273959
|
});
|
|
@@ -277439,12 +277868,12 @@ class StdioServerTransport {
|
|
|
277439
277868
|
this.onclose?.();
|
|
277440
277869
|
}
|
|
277441
277870
|
send(message) {
|
|
277442
|
-
return new Promise((
|
|
277871
|
+
return new Promise((resolve26) => {
|
|
277443
277872
|
const json2 = serializeMessage(message);
|
|
277444
277873
|
if (this._stdout.write(json2)) {
|
|
277445
|
-
|
|
277874
|
+
resolve26();
|
|
277446
277875
|
} else {
|
|
277447
|
-
this._stdout.once("drain",
|
|
277876
|
+
this._stdout.once("drain", resolve26);
|
|
277448
277877
|
}
|
|
277449
277878
|
});
|
|
277450
277879
|
}
|
|
@@ -277769,8 +278198,8 @@ function getMcpAuthCache() {
|
|
|
277769
278198
|
return authCachePromise;
|
|
277770
278199
|
}
|
|
277771
278200
|
async function isMcpAuthCached(serverId) {
|
|
277772
|
-
const
|
|
277773
|
-
const entry =
|
|
278201
|
+
const cache3 = await getMcpAuthCache();
|
|
278202
|
+
const entry = cache3[serverId];
|
|
277774
278203
|
if (!entry) {
|
|
277775
278204
|
return false;
|
|
277776
278205
|
}
|
|
@@ -277778,11 +278207,11 @@ async function isMcpAuthCached(serverId) {
|
|
|
277778
278207
|
}
|
|
277779
278208
|
function setMcpAuthCacheEntry(serverId) {
|
|
277780
278209
|
writeChain = writeChain.then(async () => {
|
|
277781
|
-
const
|
|
277782
|
-
|
|
278210
|
+
const cache3 = await getMcpAuthCache();
|
|
278211
|
+
cache3[serverId] = { timestamp: Date.now() };
|
|
277783
278212
|
const cachePath = getMcpAuthCachePath();
|
|
277784
278213
|
await getFsImplementation().mkdir(dirname36(cachePath), { recursive: true });
|
|
277785
|
-
await getFsImplementation().writeFile(cachePath, jsonStringify(
|
|
278214
|
+
await getFsImplementation().writeFile(cachePath, jsonStringify(cache3));
|
|
277786
278215
|
authCachePromise = null;
|
|
277787
278216
|
}).catch(() => {});
|
|
277788
278217
|
}
|
|
@@ -278266,9 +278695,9 @@ async function callMCPToolWithUrlElicitationRetry({
|
|
|
278266
278695
|
actionLabel: "Retry now",
|
|
278267
278696
|
showCancel: true
|
|
278268
278697
|
};
|
|
278269
|
-
userResult = await new Promise((
|
|
278698
|
+
userResult = await new Promise((resolve26) => {
|
|
278270
278699
|
const onAbort = () => {
|
|
278271
|
-
|
|
278700
|
+
resolve26({ action: "cancel" });
|
|
278272
278701
|
};
|
|
278273
278702
|
if (signal.aborted) {
|
|
278274
278703
|
onAbort();
|
|
@@ -278291,14 +278720,14 @@ async function callMCPToolWithUrlElicitationRetry({
|
|
|
278291
278720
|
return;
|
|
278292
278721
|
}
|
|
278293
278722
|
signal.removeEventListener("abort", onAbort);
|
|
278294
|
-
|
|
278723
|
+
resolve26(result);
|
|
278295
278724
|
},
|
|
278296
278725
|
onWaitingDismiss: (action) => {
|
|
278297
278726
|
signal.removeEventListener("abort", onAbort);
|
|
278298
278727
|
if (action === "retry") {
|
|
278299
|
-
|
|
278728
|
+
resolve26({ action: "accept" });
|
|
278300
278729
|
} else {
|
|
278301
|
-
|
|
278730
|
+
resolve26({ action: "cancel" });
|
|
278302
278731
|
}
|
|
278303
278732
|
}
|
|
278304
278733
|
}
|
|
@@ -278996,7 +279425,7 @@ var init_client5 = __esm(() => {
|
|
|
278996
279425
|
logMCPDebug(name, `Error sending SIGINT: ${error41}`);
|
|
278997
279426
|
return;
|
|
278998
279427
|
}
|
|
278999
|
-
await new Promise(async (
|
|
279428
|
+
await new Promise(async (resolve26) => {
|
|
279000
279429
|
let resolved = false;
|
|
279001
279430
|
const checkInterval = setInterval(() => {
|
|
279002
279431
|
try {
|
|
@@ -279007,7 +279436,7 @@ var init_client5 = __esm(() => {
|
|
|
279007
279436
|
clearInterval(checkInterval);
|
|
279008
279437
|
clearTimeout(failsafeTimeout);
|
|
279009
279438
|
logMCPDebug(name, "MCP server process exited cleanly");
|
|
279010
|
-
|
|
279439
|
+
resolve26();
|
|
279011
279440
|
}
|
|
279012
279441
|
}
|
|
279013
279442
|
}, 50);
|
|
@@ -279016,7 +279445,7 @@ var init_client5 = __esm(() => {
|
|
|
279016
279445
|
resolved = true;
|
|
279017
279446
|
clearInterval(checkInterval);
|
|
279018
279447
|
logMCPDebug(name, "Cleanup timeout reached, stopping process monitoring");
|
|
279019
|
-
|
|
279448
|
+
resolve26();
|
|
279020
279449
|
}
|
|
279021
279450
|
}, 600);
|
|
279022
279451
|
try {
|
|
@@ -279032,14 +279461,14 @@ var init_client5 = __esm(() => {
|
|
|
279032
279461
|
resolved = true;
|
|
279033
279462
|
clearInterval(checkInterval);
|
|
279034
279463
|
clearTimeout(failsafeTimeout);
|
|
279035
|
-
|
|
279464
|
+
resolve26();
|
|
279036
279465
|
return;
|
|
279037
279466
|
}
|
|
279038
279467
|
} catch {
|
|
279039
279468
|
resolved = true;
|
|
279040
279469
|
clearInterval(checkInterval);
|
|
279041
279470
|
clearTimeout(failsafeTimeout);
|
|
279042
|
-
|
|
279471
|
+
resolve26();
|
|
279043
279472
|
return;
|
|
279044
279473
|
}
|
|
279045
279474
|
await sleep2(400);
|
|
@@ -279056,7 +279485,7 @@ var init_client5 = __esm(() => {
|
|
|
279056
279485
|
resolved = true;
|
|
279057
279486
|
clearInterval(checkInterval);
|
|
279058
279487
|
clearTimeout(failsafeTimeout);
|
|
279059
|
-
|
|
279488
|
+
resolve26();
|
|
279060
279489
|
}
|
|
279061
279490
|
}
|
|
279062
279491
|
}
|
|
@@ -279064,14 +279493,14 @@ var init_client5 = __esm(() => {
|
|
|
279064
279493
|
resolved = true;
|
|
279065
279494
|
clearInterval(checkInterval);
|
|
279066
279495
|
clearTimeout(failsafeTimeout);
|
|
279067
|
-
|
|
279496
|
+
resolve26();
|
|
279068
279497
|
}
|
|
279069
279498
|
} catch {
|
|
279070
279499
|
if (!resolved) {
|
|
279071
279500
|
resolved = true;
|
|
279072
279501
|
clearInterval(checkInterval);
|
|
279073
279502
|
clearTimeout(failsafeTimeout);
|
|
279074
|
-
|
|
279503
|
+
resolve26();
|
|
279075
279504
|
}
|
|
279076
279505
|
}
|
|
279077
279506
|
});
|
|
@@ -280341,6 +280770,9 @@ async function checkPermissionsAndCallTool(tool, toolUseID, input, toolUseContex
|
|
|
280341
280770
|
logError(hookError);
|
|
280342
280771
|
}
|
|
280343
280772
|
}
|
|
280773
|
+
if (toolUseContext.abortController.signal.aborted) {
|
|
280774
|
+
throw new AbortError;
|
|
280775
|
+
}
|
|
280344
280776
|
try {
|
|
280345
280777
|
const result = await tool.call(callInput, {
|
|
280346
280778
|
...toolUseContext,
|
|
@@ -280641,19 +281073,24 @@ async function checkPermissionsAndCallTool(tool, toolUseID, input, toolUseContex
|
|
|
280641
281073
|
}
|
|
280642
281074
|
return [
|
|
280643
281075
|
{
|
|
280644
|
-
message:
|
|
280645
|
-
|
|
280646
|
-
|
|
280647
|
-
|
|
280648
|
-
|
|
280649
|
-
|
|
280650
|
-
|
|
280651
|
-
|
|
280652
|
-
|
|
280653
|
-
|
|
280654
|
-
|
|
280655
|
-
|
|
280656
|
-
|
|
281076
|
+
message: {
|
|
281077
|
+
...createUserMessage({
|
|
281078
|
+
content: [
|
|
281079
|
+
{
|
|
281080
|
+
type: "tool_result",
|
|
281081
|
+
content,
|
|
281082
|
+
is_error: true,
|
|
281083
|
+
tool_use_id: toolUseID
|
|
281084
|
+
}
|
|
281085
|
+
],
|
|
281086
|
+
toolUseResult: `Error: ${content}`,
|
|
281087
|
+
mcpMeta: toolUseContext.agentId ? undefined : error41 instanceof McpToolCallError_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS ? error41.mcpMeta : undefined,
|
|
281088
|
+
sourceToolAssistantUUID: assistantMessage.uuid
|
|
281089
|
+
}),
|
|
281090
|
+
...error41 instanceof ToolContinuationStopError && {
|
|
281091
|
+
preventContinuation: true
|
|
281092
|
+
}
|
|
281093
|
+
}
|
|
280657
281094
|
},
|
|
280658
281095
|
...hookMessages
|
|
280659
281096
|
];
|
|
@@ -280960,8 +281397,8 @@ class StreamingToolExecutor {
|
|
|
280960
281397
|
}
|
|
280961
281398
|
if (this.hasExecutingTools() && !this.hasCompletedResults() && !this.hasPendingProgress()) {
|
|
280962
281399
|
const executingPromises = this.tools.filter((t) => t.status === "executing" && t.promise).map((t) => t.promise);
|
|
280963
|
-
const progressPromise = new Promise((
|
|
280964
|
-
this.progressAvailableResolve =
|
|
281400
|
+
const progressPromise = new Promise((resolve26) => {
|
|
281401
|
+
this.progressAvailableResolve = resolve26;
|
|
280965
281402
|
});
|
|
280966
281403
|
if (executingPromises.length > 0) {
|
|
280967
281404
|
await Promise.race([...executingPromises, progressPromise]);
|
|
@@ -281203,7 +281640,7 @@ function streamOnEnd() {
|
|
|
281203
281640
|
});
|
|
281204
281641
|
}
|
|
281205
281642
|
function readFileInRangeStreaming(filePath, offset, maxLines, maxBytes, truncateOnByteLimit, signal) {
|
|
281206
|
-
return new Promise((
|
|
281643
|
+
return new Promise((resolve26, reject2) => {
|
|
281207
281644
|
const state3 = {
|
|
281208
281645
|
stream: createReadStream2(filePath, {
|
|
281209
281646
|
encoding: "utf8",
|
|
@@ -281214,7 +281651,7 @@ function readFileInRangeStreaming(filePath, offset, maxLines, maxBytes, truncate
|
|
|
281214
281651
|
endLine: maxLines !== undefined ? offset + maxLines : Infinity,
|
|
281215
281652
|
maxBytes,
|
|
281216
281653
|
truncateOnByteLimit,
|
|
281217
|
-
resolve:
|
|
281654
|
+
resolve: resolve26,
|
|
281218
281655
|
totalBytesRead: 0,
|
|
281219
281656
|
selectedBytes: 0,
|
|
281220
281657
|
truncatedByBytes: false,
|
|
@@ -281712,6 +282149,9 @@ function* yieldMissingToolResultBlocks(assistantMessages, errorMessage2) {
|
|
|
281712
282149
|
function isWithheldMaxOutputTokens(msg) {
|
|
281713
282150
|
return msg?.type === "assistant" && msg.apiError === "max_output_tokens";
|
|
281714
282151
|
}
|
|
282152
|
+
function messagePreventsContinuation(message) {
|
|
282153
|
+
return message.type === "user" && message.preventContinuation === true || message.type === "attachment" && message.attachment.type === "hook_stopped_continuation";
|
|
282154
|
+
}
|
|
281715
282155
|
async function* query(params) {
|
|
281716
282156
|
const consumedCommandUuids = [];
|
|
281717
282157
|
const terminal2 = yield* queryLoop(params, consumedCommandUuids);
|
|
@@ -281879,6 +282319,7 @@ async function* queryLoop(params, consumedCommandUuids) {
|
|
|
281879
282319
|
const toolResults = [];
|
|
281880
282320
|
const toolUseBlocks = [];
|
|
281881
282321
|
let needsFollowUp = false;
|
|
282322
|
+
let shouldPreventContinuation = false;
|
|
281882
282323
|
queryCheckpoint("query_setup_start");
|
|
281883
282324
|
const useStreamingToolExecution = config2.gates.streamingToolExecution;
|
|
281884
282325
|
let streamingToolExecutor = useStreamingToolExecution ? new StreamingToolExecutor(toolUseContext.options.tools, canUseTool, toolUseContext) : null;
|
|
@@ -281976,6 +282417,7 @@ async function* queryLoop(params, consumedCommandUuids) {
|
|
|
281976
282417
|
toolResults.length = 0;
|
|
281977
282418
|
toolUseBlocks.length = 0;
|
|
281978
282419
|
needsFollowUp = false;
|
|
282420
|
+
shouldPreventContinuation = false;
|
|
281979
282421
|
if (streamingToolExecutor) {
|
|
281980
282422
|
streamingToolExecutor.discard();
|
|
281981
282423
|
streamingToolExecutor = new StreamingToolExecutor(toolUseContext.options.tools, canUseTool, toolUseContext);
|
|
@@ -282038,6 +282480,9 @@ async function* queryLoop(params, consumedCommandUuids) {
|
|
|
282038
282480
|
for (const result of streamingToolExecutor.getCompletedResults()) {
|
|
282039
282481
|
if (result.message) {
|
|
282040
282482
|
yield result.message;
|
|
282483
|
+
if (messagePreventsContinuation(result.message)) {
|
|
282484
|
+
shouldPreventContinuation = true;
|
|
282485
|
+
}
|
|
282041
282486
|
toolResults.push(...normalizeMessagesForAPI([result.message], toolUseContext.options.tools).filter((_) => _.type === "user"));
|
|
282042
282487
|
}
|
|
282043
282488
|
}
|
|
@@ -282054,6 +282499,7 @@ async function* queryLoop(params, consumedCommandUuids) {
|
|
|
282054
282499
|
toolResults.length = 0;
|
|
282055
282500
|
toolUseBlocks.length = 0;
|
|
282056
282501
|
needsFollowUp = false;
|
|
282502
|
+
shouldPreventContinuation = false;
|
|
282057
282503
|
if (streamingToolExecutor) {
|
|
282058
282504
|
streamingToolExecutor.discard();
|
|
282059
282505
|
streamingToolExecutor = new StreamingToolExecutor(toolUseContext.options.tools, canUseTool, toolUseContext);
|
|
@@ -282251,7 +282697,6 @@ async function* queryLoop(params, consumedCommandUuids) {
|
|
|
282251
282697
|
if (false) {}
|
|
282252
282698
|
return { reason: "completed" };
|
|
282253
282699
|
}
|
|
282254
|
-
let shouldPreventContinuation = false;
|
|
282255
282700
|
let updatedToolRuntimeContext = toolUseContext;
|
|
282256
282701
|
queryCheckpoint("query_tool_execution_start");
|
|
282257
282702
|
if (streamingToolExecutor) {
|
|
@@ -282271,7 +282716,7 @@ async function* queryLoop(params, consumedCommandUuids) {
|
|
|
282271
282716
|
for await (const update of toolUpdates) {
|
|
282272
282717
|
if (update.message) {
|
|
282273
282718
|
yield update.message;
|
|
282274
|
-
if (update.message
|
|
282719
|
+
if (messagePreventsContinuation(update.message)) {
|
|
282275
282720
|
shouldPreventContinuation = true;
|
|
282276
282721
|
}
|
|
282277
282722
|
toolResults.push(...normalizeMessagesForAPI([update.message], toolUseContext.options.tools).filter((_) => _.type === "user"));
|
|
@@ -282285,7 +282730,7 @@ async function* queryLoop(params, consumedCommandUuids) {
|
|
|
282285
282730
|
}
|
|
282286
282731
|
queryCheckpoint("query_tool_execution_end");
|
|
282287
282732
|
let nextPendingToolUseSummary;
|
|
282288
|
-
if (config2.gates.emitToolUseSummaries && toolUseBlocks.length > 0 && !toolUseContext.abortController.signal.aborted && !toolUseContext.agentId) {
|
|
282733
|
+
if (!shouldPreventContinuation && config2.gates.emitToolUseSummaries && toolUseBlocks.length > 0 && !toolUseContext.abortController.signal.aborted && !toolUseContext.agentId) {
|
|
282289
282734
|
const lastAssistantMessage = assistantMessages.at(-1);
|
|
282290
282735
|
let lastAssistantText;
|
|
282291
282736
|
if (lastAssistantMessage) {
|
|
@@ -282618,7 +283063,7 @@ function getAnthropicEnvMetadata() {
|
|
|
282618
283063
|
function getBuildAgeMinutes() {
|
|
282619
283064
|
if (false)
|
|
282620
283065
|
;
|
|
282621
|
-
const buildTime = new Date("2026-07-
|
|
283066
|
+
const buildTime = new Date("2026-07-21T10:56:17.312Z").getTime();
|
|
282622
283067
|
if (isNaN(buildTime))
|
|
282623
283068
|
return;
|
|
282624
283069
|
return Math.floor((Date.now() - buildTime) / 60000);
|
|
@@ -284416,10 +284861,10 @@ function DANGEROUS_uncachedSystemPromptSection(name, compute, _reason) {
|
|
|
284416
284861
|
return { name, compute, cacheBreak: true };
|
|
284417
284862
|
}
|
|
284418
284863
|
async function resolveSystemPromptSections(sections) {
|
|
284419
|
-
const
|
|
284864
|
+
const cache3 = getSystemPromptSectionCache();
|
|
284420
284865
|
return Promise.all(sections.map(async (s) => {
|
|
284421
|
-
if (!s.cacheBreak &&
|
|
284422
|
-
return
|
|
284866
|
+
if (!s.cacheBreak && cache3.has(s.name)) {
|
|
284867
|
+
return cache3.get(s.name) ?? null;
|
|
284423
284868
|
}
|
|
284424
284869
|
const value = await s.compute();
|
|
284425
284870
|
setSystemPromptSectionCacheEntry(s.name, value);
|
|
@@ -285134,21 +285579,6 @@ var init_analyzeContext = __esm(() => {
|
|
|
285134
285579
|
init_state2();
|
|
285135
285580
|
});
|
|
285136
285581
|
|
|
285137
|
-
// src/lib/zodToJsonSchema.ts
|
|
285138
|
-
function zodToJsonSchema3(schema) {
|
|
285139
|
-
const hit = cache2.get(schema);
|
|
285140
|
-
if (hit)
|
|
285141
|
-
return hit;
|
|
285142
|
-
const result = toJSONSchema(schema);
|
|
285143
|
-
cache2.set(schema, result);
|
|
285144
|
-
return result;
|
|
285145
|
-
}
|
|
285146
|
-
var cache2;
|
|
285147
|
-
var init_zodToJsonSchema2 = __esm(() => {
|
|
285148
|
-
init_v4();
|
|
285149
|
-
cache2 = new WeakMap;
|
|
285150
|
-
});
|
|
285151
|
-
|
|
285152
285582
|
// src/controller/toolSearch.ts
|
|
285153
285583
|
function parseAutoPercentage(value) {
|
|
285154
285584
|
if (!value.startsWith("auto:"))
|
|
@@ -285263,7 +285693,8 @@ async function calculateDeferredToolDescriptionChars(tools, getToolPermissionCon
|
|
|
285263
285693
|
tools,
|
|
285264
285694
|
agents
|
|
285265
285695
|
});
|
|
285266
|
-
const
|
|
285696
|
+
const inputJSONSchema = tool.inputJSONSchema;
|
|
285697
|
+
const inputSchema16 = inputJSONSchema ? jsonStringify(inputJSONSchema) : tool.inputSchema ? jsonStringify(zodToJsonSchema3(tool.inputSchema)) : "";
|
|
285267
285698
|
return tool.name.length + description.length + inputSchema16.length;
|
|
285268
285699
|
}));
|
|
285269
285700
|
return sizes.reduce((total, size) => total + size, 0);
|
|
@@ -286822,7 +287253,7 @@ var init_findRelevantMemories = __esm(() => {
|
|
|
286822
287253
|
});
|
|
286823
287254
|
|
|
286824
287255
|
// src/session/attachments.ts
|
|
286825
|
-
import { dirname as dirname37, parse as parse12, relative as relative12, resolve as
|
|
287256
|
+
import { dirname as dirname37, parse as parse12, relative as relative12, resolve as resolve26 } from "path";
|
|
286826
287257
|
import { randomUUID as randomUUID13 } from "crypto";
|
|
286827
287258
|
async function getAttachments(input, toolUseContext, ideSelection, queuedCommands, messages, querySource, options2) {
|
|
286828
287259
|
if (isEnvTruthy(resolveEnvVar("DISABLE_ATTACHMENTS")) || isEnvTruthy(resolveEnvVar("SIMPLE"))) {
|
|
@@ -287200,7 +287631,7 @@ async function getSelectedLinesFromIDE(ideSelection, toolUseContext) {
|
|
|
287200
287631
|
];
|
|
287201
287632
|
}
|
|
287202
287633
|
function getDirectoriesToProcess(targetPath, originalCwd) {
|
|
287203
|
-
const targetDir = dirname37(
|
|
287634
|
+
const targetDir = dirname37(resolve26(targetPath));
|
|
287204
287635
|
const nestedDirs = [];
|
|
287205
287636
|
let currentDir = targetDir;
|
|
287206
287637
|
while (currentDir !== originalCwd && currentDir !== parse12(currentDir).root) {
|
|
@@ -287656,7 +288087,7 @@ async function getDynamicSkillAttachments(toolUseContext) {
|
|
|
287656
288087
|
const candidates = entries.filter((e) => e.isDirectory() || e.isSymbolicLink()).map((e) => e.name);
|
|
287657
288088
|
const checked = await Promise.all(candidates.map(async (name) => {
|
|
287658
288089
|
try {
|
|
287659
|
-
await getFsImplementation().stat(
|
|
288090
|
+
await getFsImplementation().stat(resolve26(skillDir, name, "SKILL.md"));
|
|
287660
288091
|
return name;
|
|
287661
288092
|
} catch {
|
|
287662
288093
|
return null;
|
|
@@ -289278,7 +289709,7 @@ function executeInBackground({
|
|
|
289278
289709
|
}) {
|
|
289279
289710
|
if (asyncRewake) {
|
|
289280
289711
|
shellCommand.result.then(async (result) => {
|
|
289281
|
-
await new Promise((
|
|
289712
|
+
await new Promise((resolve27) => setImmediate(resolve27));
|
|
289282
289713
|
const stdout = await shellCommand.taskOutput.getStdout();
|
|
289283
289714
|
const stderr = shellCommand.taskOutput.getStderr();
|
|
289284
289715
|
shellCommand.cleanup();
|
|
@@ -289721,8 +290152,8 @@ async function execCommandHook(hook, hookEvent, hookName, jsonInput, signal, hoo
|
|
|
289721
290152
|
child.stderr.setEncoding("utf8");
|
|
289722
290153
|
let initialResponseChecked = false;
|
|
289723
290154
|
let asyncResolve = null;
|
|
289724
|
-
const childIsAsyncPromise = new Promise((
|
|
289725
|
-
asyncResolve =
|
|
290155
|
+
const childIsAsyncPromise = new Promise((resolve27) => {
|
|
290156
|
+
asyncResolve = resolve27;
|
|
289726
290157
|
});
|
|
289727
290158
|
const processedPromptLines = new Set;
|
|
289728
290159
|
let promptChain = Promise.resolve();
|
|
@@ -289813,13 +290244,13 @@ async function execCommandHook(hook, hookEvent, hookName, jsonInput, signal, hoo
|
|
|
289813
290244
|
hookEvent,
|
|
289814
290245
|
getOutput: async () => ({ stdout, stderr, output })
|
|
289815
290246
|
});
|
|
289816
|
-
const stdoutEndPromise = new Promise((
|
|
289817
|
-
child.stdout.on("end", () =>
|
|
290247
|
+
const stdoutEndPromise = new Promise((resolve27) => {
|
|
290248
|
+
child.stdout.on("end", () => resolve27());
|
|
289818
290249
|
});
|
|
289819
|
-
const stderrEndPromise = new Promise((
|
|
289820
|
-
child.stderr.on("end", () =>
|
|
290250
|
+
const stderrEndPromise = new Promise((resolve27) => {
|
|
290251
|
+
child.stderr.on("end", () => resolve27());
|
|
289821
290252
|
});
|
|
289822
|
-
const stdinWritePromise = stdinWritten ? Promise.resolve() : new Promise((
|
|
290253
|
+
const stdinWritePromise = stdinWritten ? Promise.resolve() : new Promise((resolve27, reject2) => {
|
|
289823
290254
|
child.stdin.on("error", (err2) => {
|
|
289824
290255
|
if (!requestPrompt) {
|
|
289825
290256
|
reject2(err2);
|
|
@@ -289832,12 +290263,12 @@ async function execCommandHook(hook, hookEvent, hookName, jsonInput, signal, hoo
|
|
|
289832
290263
|
if (!requestPrompt) {
|
|
289833
290264
|
child.stdin.end();
|
|
289834
290265
|
}
|
|
289835
|
-
|
|
290266
|
+
resolve27();
|
|
289836
290267
|
});
|
|
289837
290268
|
const childErrorPromise = new Promise((_, reject2) => {
|
|
289838
290269
|
child.on("error", reject2);
|
|
289839
290270
|
});
|
|
289840
|
-
const childClosePromise = new Promise((
|
|
290271
|
+
const childClosePromise = new Promise((resolve27) => {
|
|
289841
290272
|
let exitCode = null;
|
|
289842
290273
|
child.on("close", (code) => {
|
|
289843
290274
|
exitCode = code ?? 1;
|
|
@@ -289845,7 +290276,7 @@ async function execCommandHook(hook, hookEvent, hookName, jsonInput, signal, hoo
|
|
|
289845
290276
|
const finalStdout = processedPromptLines.size === 0 ? stdout : stdout.split(`
|
|
289846
290277
|
`).filter((line) => !processedPromptLines.has(line.trim())).join(`
|
|
289847
290278
|
`);
|
|
289848
|
-
|
|
290279
|
+
resolve27({
|
|
289849
290280
|
stdout: finalStdout,
|
|
289850
290281
|
stderr,
|
|
289851
290282
|
output,
|
|
@@ -291900,12 +292331,12 @@ async function executeFunctionHook({
|
|
|
291900
292331
|
hook
|
|
291901
292332
|
};
|
|
291902
292333
|
}
|
|
291903
|
-
const passed = await new Promise((
|
|
292334
|
+
const passed = await new Promise((resolve27, reject2) => {
|
|
291904
292335
|
const onAbort = () => reject2(new Error("Function hook cancelled"));
|
|
291905
292336
|
abortSignal.addEventListener("abort", onAbort);
|
|
291906
292337
|
Promise.resolve(hook.callback(messages, abortSignal)).then((result) => {
|
|
291907
292338
|
abortSignal.removeEventListener("abort", onAbort);
|
|
291908
|
-
|
|
292339
|
+
resolve27(result);
|
|
291909
292340
|
}).catch((error41) => {
|
|
291910
292341
|
abortSignal.removeEventListener("abort", onAbort);
|
|
291911
292342
|
reject2(error41);
|
|
@@ -292362,10 +292793,11 @@ async function createAgentWorktree(slug) {
|
|
|
292362
292793
|
logForDebugging(`Created hook-based agent worktree at: ${hookResult.worktreePath}`);
|
|
292363
292794
|
return { worktreePath: hookResult.worktreePath, hookBased: true };
|
|
292364
292795
|
}
|
|
292365
|
-
const
|
|
292366
|
-
if (!
|
|
292367
|
-
throw new
|
|
292796
|
+
const availability = resolveGitWorktreeAvailability(getCwd3(), gitExe());
|
|
292797
|
+
if (!availability.available) {
|
|
292798
|
+
throw new WorktreeUnavailableError(availability.reason);
|
|
292368
292799
|
}
|
|
292800
|
+
const gitRoot = findCanonicalGitRoot(availability.gitRoot) ?? availability.gitRoot;
|
|
292369
292801
|
const { worktreePath, worktreeBranch, headCommit, existed } = await getOrCreateWorktree(gitRoot, slug);
|
|
292370
292802
|
if (!existed) {
|
|
292371
292803
|
logForDebugging(`Created agent worktree at: ${worktreePath} on branch: ${worktreeBranch}`);
|
|
@@ -292377,6 +292809,16 @@ async function createAgentWorktree(slug) {
|
|
|
292377
292809
|
}
|
|
292378
292810
|
return { worktreePath, worktreeBranch, headCommit, gitRoot };
|
|
292379
292811
|
}
|
|
292812
|
+
function isAgentWorktreeIsolationAvailable(options2 = {}) {
|
|
292813
|
+
try {
|
|
292814
|
+
if (options2.hasCreateHook ?? hasWorktreeCreateHook()) {
|
|
292815
|
+
return true;
|
|
292816
|
+
}
|
|
292817
|
+
return isGitWorktreeIsolationAvailable(options2.cwd ?? getCwd3(), gitExe(), options2.gitAvailabilityCache);
|
|
292818
|
+
} catch {
|
|
292819
|
+
return false;
|
|
292820
|
+
}
|
|
292821
|
+
}
|
|
292380
292822
|
async function removeAgentWorktree(worktreePath, worktreeBranch, gitRoot, hookBased) {
|
|
292381
292823
|
if (hookBased) {
|
|
292382
292824
|
const hookRan = await executeWorktreeRemoveHook(worktreePath);
|
|
@@ -292448,6 +292890,7 @@ var init_worktree = __esm(() => {
|
|
|
292448
292890
|
init_settings2();
|
|
292449
292891
|
init_detection();
|
|
292450
292892
|
init_fsOperations();
|
|
292893
|
+
init_worktreeAvailability();
|
|
292451
292894
|
import_ignore4 = __toESM(require_ignore(), 1);
|
|
292452
292895
|
VALID_WORKTREE_SLUG_SEGMENT = /^[a-zA-Z0-9._-]+$/;
|
|
292453
292896
|
GIT_NO_PROMPT_ENV2 = {
|
|
@@ -292939,12 +293382,13 @@ function filterSwarmFieldsFromSchema(toolName, schema) {
|
|
|
292939
293382
|
return filtered;
|
|
292940
293383
|
}
|
|
292941
293384
|
async function toolToAPISchema(tool, options2) {
|
|
292942
|
-
const
|
|
293385
|
+
const inputJSONSchema = tool.inputJSONSchema;
|
|
293386
|
+
const cacheKey = inputJSONSchema ? `${tool.name}:${jsonStringify(inputJSONSchema)}` : tool.name;
|
|
292943
293387
|
const cache3 = getToolSchemaCache();
|
|
292944
293388
|
let base2 = cache3.get(cacheKey);
|
|
292945
293389
|
if (!base2) {
|
|
292946
293390
|
const strictToolsEnabled = checkStatsigFeatureGate_CACHED_MAY_BE_STALE("tengu_tool_pear");
|
|
292947
|
-
let input_schema =
|
|
293391
|
+
let input_schema = inputJSONSchema ?? zodToJsonSchema3(tool.inputSchema);
|
|
292948
293392
|
if (!isAgentSwarmsEnabled()) {
|
|
292949
293393
|
input_schema = filterSwarmFieldsFromSchema(tool.name, input_schema);
|
|
292950
293394
|
}
|
|
@@ -296032,7 +296476,7 @@ var init_permissionSetup = __esm(() => {
|
|
|
296032
296476
|
|
|
296033
296477
|
// src/capabilities/markdownConfigLoader.ts
|
|
296034
296478
|
import { homedir as homedir20 } from "os";
|
|
296035
|
-
import { dirname as dirname39, join as join74, resolve as
|
|
296479
|
+
import { dirname as dirname39, join as join74, resolve as resolve27, sep as sep21 } from "path";
|
|
296036
296480
|
function extractDescriptionFromMarkdown(content, defaultDescription = "Custom item") {
|
|
296037
296481
|
const lines = content.split(`
|
|
296038
296482
|
`);
|
|
@@ -296114,9 +296558,9 @@ function resolveStopBoundary(cwd) {
|
|
|
296114
296558
|
return cwdGitRoot;
|
|
296115
296559
|
}
|
|
296116
296560
|
function getProjectDirsUpToHome(subdir, cwd) {
|
|
296117
|
-
const home =
|
|
296561
|
+
const home = resolve27(homedir20()).normalize("NFC");
|
|
296118
296562
|
const gitRoot = resolveStopBoundary(cwd);
|
|
296119
|
-
let current =
|
|
296563
|
+
let current = resolve27(cwd);
|
|
296120
296564
|
const dirs = [];
|
|
296121
296565
|
while (true) {
|
|
296122
296566
|
if (normalizePathForComparison(current) === normalizePathForComparison(home)) {
|
|
@@ -317753,7 +318197,7 @@ var HttpClient = class {
|
|
|
317753
318197
|
} else if (extractStatus.status === "failed" || extractStatus.status === "cancelled") {
|
|
317754
318198
|
throw new FirecrawlError(`Extract job ${extractStatus.status}. Error: ${extractStatus.error}`, statusResponse.status);
|
|
317755
318199
|
}
|
|
317756
|
-
await new Promise((
|
|
318200
|
+
await new Promise((resolve28) => setTimeout(resolve28, 1000));
|
|
317757
318201
|
} while (extractStatus.status !== "completed");
|
|
317758
318202
|
} else {
|
|
317759
318203
|
this.handleError(response, "extract");
|
|
@@ -317852,7 +318296,7 @@ var HttpClient = class {
|
|
|
317852
318296
|
}
|
|
317853
318297
|
} else if (["active", "paused", "pending", "queued", "waiting", "scraping"].includes(statusData.status)) {
|
|
317854
318298
|
checkInterval = Math.max(checkInterval, 2);
|
|
317855
|
-
await new Promise((
|
|
318299
|
+
await new Promise((resolve28) => setTimeout(resolve28, checkInterval * 1000));
|
|
317856
318300
|
} else {
|
|
317857
318301
|
throw new FirecrawlError(`Crawl job failed or was stopped. Status: ${statusData.status}`, 500);
|
|
317858
318302
|
}
|
|
@@ -317866,7 +318310,7 @@ var HttpClient = class {
|
|
|
317866
318310
|
if (this.isRetryableError(error41) && networkRetries < maxNetworkRetries) {
|
|
317867
318311
|
networkRetries++;
|
|
317868
318312
|
const backoffDelay = Math.min(1000 * Math.pow(2, networkRetries - 1), 1e4);
|
|
317869
|
-
await new Promise((
|
|
318313
|
+
await new Promise((resolve28) => setTimeout(resolve28, backoffDelay));
|
|
317870
318314
|
continue;
|
|
317871
318315
|
}
|
|
317872
318316
|
throw new FirecrawlError(error41, 500);
|
|
@@ -317949,7 +318393,7 @@ var HttpClient = class {
|
|
|
317949
318393
|
if (researchStatus.status !== "processing") {
|
|
317950
318394
|
break;
|
|
317951
318395
|
}
|
|
317952
|
-
await new Promise((
|
|
318396
|
+
await new Promise((resolve28) => setTimeout(resolve28, 2000));
|
|
317953
318397
|
}
|
|
317954
318398
|
return { success: false, error: "Research job terminated unexpectedly" };
|
|
317955
318399
|
} catch (error41) {
|
|
@@ -318037,7 +318481,7 @@ var HttpClient = class {
|
|
|
318037
318481
|
if (researchStatus.status !== "processing") {
|
|
318038
318482
|
break;
|
|
318039
318483
|
}
|
|
318040
|
-
await new Promise((
|
|
318484
|
+
await new Promise((resolve28) => setTimeout(resolve28, 2000));
|
|
318041
318485
|
}
|
|
318042
318486
|
return { success: false, error: "Research job terminated unexpectedly" };
|
|
318043
318487
|
} catch (error41) {
|
|
@@ -318108,7 +318552,7 @@ var HttpClient = class {
|
|
|
318108
318552
|
if (generationStatus.status !== "processing") {
|
|
318109
318553
|
break;
|
|
318110
318554
|
}
|
|
318111
|
-
await new Promise((
|
|
318555
|
+
await new Promise((resolve28) => setTimeout(resolve28, 2000));
|
|
318112
318556
|
}
|
|
318113
318557
|
return { success: false, error: "LLMs.txt generation job terminated unexpectedly" };
|
|
318114
318558
|
} catch (error41) {
|
|
@@ -324945,9 +325389,9 @@ var require_needle = __commonJS((exports, module) => {
|
|
|
324945
325389
|
verb = args.shift();
|
|
324946
325390
|
if (verb.match(/get|head/i) && args.length == 2)
|
|
324947
325391
|
args.splice(1, 0, null);
|
|
324948
|
-
return new Promise(function(
|
|
325392
|
+
return new Promise(function(resolve28, reject2) {
|
|
324949
325393
|
module.exports.request(verb, args[0], args[1], args[2], function(err2, resp) {
|
|
324950
|
-
return err2 ? reject2(err2) :
|
|
325394
|
+
return err2 ? reject2(err2) : resolve28(resp);
|
|
324951
325395
|
});
|
|
324952
325396
|
});
|
|
324953
325397
|
};
|
|
@@ -329467,8 +329911,9 @@ function registerSdkInlineSkillHandler() {
|
|
|
329467
329911
|
}
|
|
329468
329912
|
|
|
329469
329913
|
// src/session/sdkRuntime.ts
|
|
329470
|
-
init_LocalAgentTask();
|
|
329471
329914
|
init_backgroundAbortRegistry();
|
|
329915
|
+
init_backgroundTaskScope();
|
|
329916
|
+
init_sessionStorage();
|
|
329472
329917
|
init_hooks2();
|
|
329473
329918
|
init_debug();
|
|
329474
329919
|
init_errors5();
|
|
@@ -331711,7 +332156,8 @@ async function stopTask(taskId, context4) {
|
|
|
331711
332156
|
const appState = getAppState();
|
|
331712
332157
|
const task = appState.tasks?.[taskId];
|
|
331713
332158
|
if (!task) {
|
|
331714
|
-
if (
|
|
332159
|
+
if (hasBackgroundAgent(taskId)) {
|
|
332160
|
+
await abortBackgroundAgentById(taskId);
|
|
331715
332161
|
return { taskId, taskType: "local_agent", command: undefined };
|
|
331716
332162
|
}
|
|
331717
332163
|
throw new StopTaskError(`No task found with ID: ${taskId}`, "not_found");
|
|
@@ -331723,7 +332169,11 @@ async function stopTask(taskId, context4) {
|
|
|
331723
332169
|
if (!taskImpl) {
|
|
331724
332170
|
throw new StopTaskError(`Unsupported task type: ${task.type}`, "unsupported_type");
|
|
331725
332171
|
}
|
|
331726
|
-
|
|
332172
|
+
if (task.type === "local_agent" && hasBackgroundAgent(taskId)) {
|
|
332173
|
+
await abortBackgroundAgentById(taskId);
|
|
332174
|
+
} else {
|
|
332175
|
+
await taskImpl.kill(taskId, setAppState);
|
|
332176
|
+
}
|
|
331727
332177
|
if (isLocalShellTask(task)) {
|
|
331728
332178
|
let suppressed = false;
|
|
331729
332179
|
setAppState((prev) => {
|
|
@@ -331765,6 +332215,7 @@ var DESCRIPTION10 = `
|
|
|
331765
332215
|
|
|
331766
332216
|
// src/capabilities/tools/TaskStopTool/TaskStopTool.ts
|
|
331767
332217
|
init_toolUIRegistry();
|
|
332218
|
+
init_backgroundAbortRegistry();
|
|
331768
332219
|
var {
|
|
331769
332220
|
renderToolResultMessage: renderToolResultMessage17,
|
|
331770
332221
|
renderToolUseMessage: renderToolUseMessage17
|
|
@@ -331810,6 +332261,9 @@ var TaskStopTool = buildToolRuntime({
|
|
|
331810
332261
|
const appState = getAppState();
|
|
331811
332262
|
const task = appState.tasks?.[id];
|
|
331812
332263
|
if (!task) {
|
|
332264
|
+
if (hasBackgroundAgent(id)) {
|
|
332265
|
+
return { result: true };
|
|
332266
|
+
}
|
|
331813
332267
|
return {
|
|
331814
332268
|
result: false,
|
|
331815
332269
|
message: `No task found with ID: ${id}`,
|
|
@@ -334757,34 +335211,63 @@ function optionsWithProviderRoutingEnv(options2) {
|
|
|
334757
335211
|
}
|
|
334758
335212
|
return { ...options2, env: mergedEnv };
|
|
334759
335213
|
}
|
|
334760
|
-
function createQueryLike(generator, runtimeState,
|
|
335214
|
+
function createQueryLike(generator, runtimeState, finalize) {
|
|
335215
|
+
let finalizePromise;
|
|
335216
|
+
let closePromise;
|
|
335217
|
+
const finalizeOnce = () => {
|
|
335218
|
+
finalizePromise ??= finalize();
|
|
335219
|
+
return finalizePromise;
|
|
335220
|
+
};
|
|
335221
|
+
const stream4 = async function* () {
|
|
335222
|
+
try {
|
|
335223
|
+
yield* generator;
|
|
335224
|
+
} finally {
|
|
335225
|
+
await finalizeOnce();
|
|
335226
|
+
}
|
|
335227
|
+
}();
|
|
334761
335228
|
return {
|
|
334762
335229
|
[Symbol.asyncIterator]() {
|
|
334763
|
-
return
|
|
335230
|
+
return stream4;
|
|
334764
335231
|
},
|
|
334765
335232
|
async interrupt() {
|
|
334766
335233
|
runtimeState.abortController.abort();
|
|
334767
335234
|
runtimeState.abortController = createAbortController();
|
|
334768
335235
|
},
|
|
334769
335236
|
killAgent(agentId) {
|
|
334770
|
-
abortBackgroundAgentById(agentId);
|
|
334771
|
-
killAsyncAgent(agentId, runtimeState.setAppState);
|
|
335237
|
+
return abortBackgroundAgentById(agentId);
|
|
334772
335238
|
},
|
|
334773
|
-
|
|
334774
|
-
if (
|
|
334775
|
-
|
|
334776
|
-
|
|
334777
|
-
|
|
334778
|
-
|
|
334779
|
-
|
|
334780
|
-
|
|
334781
|
-
|
|
334782
|
-
|
|
334783
|
-
}
|
|
335239
|
+
close() {
|
|
335240
|
+
if (!closePromise) {
|
|
335241
|
+
runtimeState.closed = true;
|
|
335242
|
+
runtimeState.abortController.abort();
|
|
335243
|
+
closePromise = (async () => {
|
|
335244
|
+
try {
|
|
335245
|
+
await stream4.return(undefined);
|
|
335246
|
+
} finally {
|
|
335247
|
+
await finalizeOnce();
|
|
335248
|
+
}
|
|
335249
|
+
})();
|
|
334784
335250
|
}
|
|
335251
|
+
return closePromise;
|
|
334785
335252
|
}
|
|
334786
335253
|
};
|
|
334787
335254
|
}
|
|
335255
|
+
function trackProjectContextId(ownership, sessionId) {
|
|
335256
|
+
ownership.projectContextIds.add(sessionId);
|
|
335257
|
+
if (ownership.kind === "session") {
|
|
335258
|
+
ownership.trackProjectContextId(sessionId);
|
|
335259
|
+
}
|
|
335260
|
+
}
|
|
335261
|
+
async function closeOwnedQueryResources(scope, projectContextIds) {
|
|
335262
|
+
try {
|
|
335263
|
+
await scope.stop();
|
|
335264
|
+
} finally {
|
|
335265
|
+
for (const sessionId of projectContextIds) {
|
|
335266
|
+
clearProjectForSession(sessionId);
|
|
335267
|
+
}
|
|
335268
|
+
projectContextIds.clear();
|
|
335269
|
+
}
|
|
335270
|
+
}
|
|
334788
335271
|
async function* mergeAskWithStatus(askIterable, statusStream) {
|
|
334789
335272
|
const askIter = askIterable[Symbol.asyncIterator]();
|
|
334790
335273
|
let askNext = askIter.next();
|
|
@@ -334817,6 +335300,15 @@ function runSdkQueryRuntime(params) {
|
|
|
334817
335300
|
const cwd = typeof options2.cwd === "string" && options2.cwd.trim().length > 0 ? options2.cwd : process.cwd();
|
|
334818
335301
|
const optionsWithProviderRouting = optionsWithProviderRoutingEnv(options2);
|
|
334819
335302
|
const queryContext = buildQueryContextFromSdk(optionsWithProviderRouting);
|
|
335303
|
+
const ownership = params.resourceOwner ? {
|
|
335304
|
+
...params.resourceOwner,
|
|
335305
|
+
projectContextIds: new Set
|
|
335306
|
+
} : {
|
|
335307
|
+
kind: "standalone",
|
|
335308
|
+
backgroundTaskScope: new BackgroundTaskScope,
|
|
335309
|
+
projectContextIds: new Set
|
|
335310
|
+
};
|
|
335311
|
+
trackProjectContextId(ownership, queryContext.identity.sessionId);
|
|
334820
335312
|
const runtimeState = {
|
|
334821
335313
|
closed: false,
|
|
334822
335314
|
runningTurn: false,
|
|
@@ -334824,6 +335316,7 @@ function runSdkQueryRuntime(params) {
|
|
|
334824
335316
|
};
|
|
334825
335317
|
const fileCheckpointingOnChange = options2.fileCheckpointing?.onFileHistoryChange;
|
|
334826
335318
|
const appStateStore = buildAppStateStore(applyFileCheckpointingInitialState(applyDisallowedTools(applyPermissionMode(getDefaultAppState(), options2.permissionMode), options2.disallowedTools), options2.fileCheckpointing?.initialState), fileCheckpointingOnChange);
|
|
335319
|
+
const releaseBackgroundTaskScope = bindBackgroundTaskScope(appStateStore.setAppState, ownership.backgroundTaskScope);
|
|
334827
335320
|
const initialMessagesForReplay = options2.resume ? loadAndRestampHistoricalMessages(options2.resume, queryContext.identity.sessionId, options2.initialMessages) : options2.initialMessages;
|
|
334828
335321
|
let mutableMessages = normalizeInitialMessages(initialMessagesForReplay);
|
|
334829
335322
|
let readFileCache = createFileStateCacheWithSizeLimit(DEFAULT_READ_FILE_CACHE_SIZE);
|
|
@@ -335066,7 +335559,17 @@ function runSdkQueryRuntime(params) {
|
|
|
335066
335559
|
}
|
|
335067
335560
|
}();
|
|
335068
335561
|
const generator = bindAsyncGeneratorToScope(rawGenerator, queryContext);
|
|
335069
|
-
return createQueryLike(generator, runtimeState)
|
|
335562
|
+
return createQueryLike(generator, runtimeState, async () => {
|
|
335563
|
+
trackProjectContextId(ownership, queryContext.identity.sessionId);
|
|
335564
|
+
releaseBackgroundTaskScope();
|
|
335565
|
+
try {
|
|
335566
|
+
params.onStreamSettled?.();
|
|
335567
|
+
} finally {
|
|
335568
|
+
if (ownership.kind === "standalone") {
|
|
335569
|
+
await closeOwnedQueryResources(ownership.backgroundTaskScope, ownership.projectContextIds);
|
|
335570
|
+
}
|
|
335571
|
+
}
|
|
335572
|
+
});
|
|
335070
335573
|
}
|
|
335071
335574
|
|
|
335072
335575
|
// src/session/runtime.ts
|
|
@@ -335078,6 +335581,8 @@ init_hooks2();
|
|
|
335078
335581
|
init_AppStateStore();
|
|
335079
335582
|
init_debug();
|
|
335080
335583
|
init_errors5();
|
|
335584
|
+
init_backgroundTaskScope();
|
|
335585
|
+
init_sessionStorage();
|
|
335081
335586
|
function mergeTurnOptions(sessionOptions, turnOptions) {
|
|
335082
335587
|
if (!turnOptions)
|
|
335083
335588
|
return sessionOptions;
|
|
@@ -335094,6 +335599,10 @@ function mergeTurnOptions(sessionOptions, turnOptions) {
|
|
|
335094
335599
|
class SessionRuntime {
|
|
335095
335600
|
baseOptions;
|
|
335096
335601
|
closed = false;
|
|
335602
|
+
closePromise;
|
|
335603
|
+
backgroundTaskScope = new BackgroundTaskScope;
|
|
335604
|
+
projectContextIds = new Set;
|
|
335605
|
+
activeQueries = new Set;
|
|
335097
335606
|
accumulatedFileHistory;
|
|
335098
335607
|
constructor(options2) {
|
|
335099
335608
|
this.baseOptions = options2;
|
|
@@ -335117,13 +335626,34 @@ class SessionRuntime {
|
|
|
335117
335626
|
}
|
|
335118
335627
|
}
|
|
335119
335628
|
} : undefined;
|
|
335120
|
-
|
|
335629
|
+
let query2;
|
|
335630
|
+
query2 = runSdkQueryRuntime({
|
|
335121
335631
|
prompt: params.prompt,
|
|
335122
335632
|
options: {
|
|
335123
335633
|
...merged,
|
|
335124
335634
|
...fileCheckpointing ? { fileCheckpointing } : {}
|
|
335635
|
+
},
|
|
335636
|
+
resourceOwner: {
|
|
335637
|
+
kind: "session",
|
|
335638
|
+
backgroundTaskScope: this.backgroundTaskScope,
|
|
335639
|
+
trackProjectContextId: (sessionId) => {
|
|
335640
|
+
this.projectContextIds.add(sessionId);
|
|
335641
|
+
}
|
|
335642
|
+
},
|
|
335643
|
+
onStreamSettled: () => {
|
|
335644
|
+
this.activeQueries.delete(query2);
|
|
335125
335645
|
}
|
|
335126
335646
|
});
|
|
335647
|
+
this.activeQueries.add(query2);
|
|
335648
|
+
const closeQuery = query2.close.bind(query2);
|
|
335649
|
+
query2.close = async () => {
|
|
335650
|
+
try {
|
|
335651
|
+
await closeQuery();
|
|
335652
|
+
} finally {
|
|
335653
|
+
this.activeQueries.delete(query2);
|
|
335654
|
+
}
|
|
335655
|
+
};
|
|
335656
|
+
return query2;
|
|
335127
335657
|
}
|
|
335128
335658
|
async prompt(message, options2) {
|
|
335129
335659
|
const q = this.query({ prompt: message, options: options2 });
|
|
@@ -335138,32 +335668,66 @@ class SessionRuntime {
|
|
|
335138
335668
|
async getInfo() {
|
|
335139
335669
|
return;
|
|
335140
335670
|
}
|
|
335141
|
-
|
|
335142
|
-
if (this.
|
|
335143
|
-
|
|
335144
|
-
|
|
335145
|
-
|
|
335146
|
-
|
|
335147
|
-
|
|
335148
|
-
|
|
335149
|
-
|
|
335150
|
-
|
|
335151
|
-
|
|
335152
|
-
|
|
335671
|
+
close(reason = "normal") {
|
|
335672
|
+
if (!this.closePromise) {
|
|
335673
|
+
this.closed = true;
|
|
335674
|
+
this.closePromise = this.closeResources(reason);
|
|
335675
|
+
}
|
|
335676
|
+
return this.closePromise;
|
|
335677
|
+
}
|
|
335678
|
+
async closeResources(reason) {
|
|
335679
|
+
const failures = [];
|
|
335680
|
+
try {
|
|
335681
|
+
const activeQueries = [...this.activeQueries];
|
|
335682
|
+
const queryResults = await Promise.allSettled(activeQueries.map(async (query2) => {
|
|
335683
|
+
await query2.close();
|
|
335684
|
+
}));
|
|
335685
|
+
for (const result of queryResults) {
|
|
335686
|
+
if (result.status === "rejected")
|
|
335687
|
+
failures.push(result.reason);
|
|
335153
335688
|
}
|
|
335154
|
-
|
|
335689
|
+
this.activeQueries.clear();
|
|
335155
335690
|
try {
|
|
335156
|
-
await
|
|
335157
|
-
|
|
335158
|
-
|
|
335159
|
-
|
|
335160
|
-
|
|
335161
|
-
|
|
335691
|
+
await this.backgroundTaskScope.stop();
|
|
335692
|
+
} catch (err2) {
|
|
335693
|
+
failures.push(err2);
|
|
335694
|
+
}
|
|
335695
|
+
try {
|
|
335696
|
+
const ctx = buildRewindQueryContext(this.baseOptions);
|
|
335697
|
+
this.projectContextIds.add(ctx.identity.sessionId);
|
|
335698
|
+
await runWithQueryContext(ctx, async () => {
|
|
335699
|
+
if (this.baseOptions.hooks) {
|
|
335700
|
+
try {
|
|
335701
|
+
registerHookCallbacks2(this.baseOptions.hooks);
|
|
335702
|
+
} catch (err2) {
|
|
335703
|
+
logForDebugging(`SessionRuntime.close: registerHookCallbacks threw: ${errorMessage(err2)}`, { level: "warn" });
|
|
335704
|
+
}
|
|
335705
|
+
}
|
|
335706
|
+
let state3 = getDefaultAppState();
|
|
335707
|
+
try {
|
|
335708
|
+
await executeSessionEndHooks(reason, {
|
|
335709
|
+
getAppState: () => state3,
|
|
335710
|
+
setAppState: (updater) => {
|
|
335711
|
+
state3 = updater(state3);
|
|
335712
|
+
},
|
|
335713
|
+
timeoutMs: getSessionEndHookTimeoutMs()
|
|
335714
|
+
});
|
|
335715
|
+
} catch (err2) {
|
|
335716
|
+
logForDebugging(`SessionRuntime.close: SessionEnd hooks errored: ${errorMessage(err2)}`, { level: "warn" });
|
|
335717
|
+
}
|
|
335162
335718
|
});
|
|
335163
335719
|
} catch (err2) {
|
|
335164
|
-
logForDebugging(`SessionRuntime.close: SessionEnd
|
|
335720
|
+
logForDebugging(`SessionRuntime.close: SessionEnd context errored: ${errorMessage(err2)}`, { level: "warn" });
|
|
335165
335721
|
}
|
|
335166
|
-
}
|
|
335722
|
+
} finally {
|
|
335723
|
+
for (const sessionId of this.projectContextIds) {
|
|
335724
|
+
clearProjectForSession(sessionId);
|
|
335725
|
+
}
|
|
335726
|
+
this.projectContextIds.clear();
|
|
335727
|
+
}
|
|
335728
|
+
if (failures.length > 0) {
|
|
335729
|
+
throw new AggregateError(failures, "SessionRuntime cleanup failed");
|
|
335730
|
+
}
|
|
335167
335731
|
}
|
|
335168
335732
|
canRewindFiles(state3, messageUuid) {
|
|
335169
335733
|
const effective = this.accumulatedFileHistory ?? state3;
|
|
@@ -335478,14 +336042,14 @@ class AuthCodeListener {
|
|
|
335478
336042
|
this.callbackPath = callbackPath;
|
|
335479
336043
|
}
|
|
335480
336044
|
async start(port) {
|
|
335481
|
-
return new Promise((
|
|
336045
|
+
return new Promise((resolve28, reject2) => {
|
|
335482
336046
|
this.localServer.once("error", (err2) => {
|
|
335483
336047
|
reject2(new Error(`Failed to start OAuth callback server: ${err2.message}`));
|
|
335484
336048
|
});
|
|
335485
336049
|
this.localServer.listen({ port: port ?? 0, host: "::", ipv6Only: false }, () => {
|
|
335486
336050
|
const address = this.localServer.address();
|
|
335487
336051
|
this.port = address.port;
|
|
335488
|
-
|
|
336052
|
+
resolve28(this.port);
|
|
335489
336053
|
});
|
|
335490
336054
|
});
|
|
335491
336055
|
}
|
|
@@ -335496,8 +336060,8 @@ class AuthCodeListener {
|
|
|
335496
336060
|
return this.pendingResponse !== null;
|
|
335497
336061
|
}
|
|
335498
336062
|
async waitForAuthorization(state3, onReady) {
|
|
335499
|
-
return new Promise((
|
|
335500
|
-
this.promiseResolver =
|
|
336063
|
+
return new Promise((resolve28, reject2) => {
|
|
336064
|
+
this.promiseResolver = resolve28;
|
|
335501
336065
|
this.promiseRejecter = reject2;
|
|
335502
336066
|
this.expectedState = state3;
|
|
335503
336067
|
this.startLocalListener(onReady);
|
|
@@ -335663,11 +336227,11 @@ class OAuthService {
|
|
|
335663
336227
|
}
|
|
335664
336228
|
}
|
|
335665
336229
|
async waitForAuthorizationCode(state3, onReady) {
|
|
335666
|
-
return new Promise((
|
|
335667
|
-
this.manualAuthCodeResolver =
|
|
336230
|
+
return new Promise((resolve28, reject2) => {
|
|
336231
|
+
this.manualAuthCodeResolver = resolve28;
|
|
335668
336232
|
this.authCodeListener?.waitForAuthorization(state3, onReady).then((authorizationCode) => {
|
|
335669
336233
|
this.manualAuthCodeResolver = null;
|
|
335670
|
-
|
|
336234
|
+
resolve28(authorizationCode);
|
|
335671
336235
|
}).catch((error41) => {
|
|
335672
336236
|
this.manualAuthCodeResolver = null;
|
|
335673
336237
|
reject2(error41);
|
|
@@ -336140,4 +336704,4 @@ export {
|
|
|
336140
336704
|
AbortError2 as AbortError
|
|
336141
336705
|
};
|
|
336142
336706
|
|
|
336143
|
-
//# debugId=
|
|
336707
|
+
//# debugId=802EF03F664786CA64756E2164756E21
|