cmdr-agent 2.3.0 → 2.5.0
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/package.json +1 -1
- package/dist/src/cli/progress.d.ts +58 -0
- package/dist/src/cli/progress.d.ts.map +1 -0
- package/dist/src/cli/progress.js +179 -0
- package/dist/src/cli/progress.js.map +1 -0
- package/dist/src/cli/repl.d.ts.map +1 -1
- package/dist/src/cli/repl.js +56 -0
- package/dist/src/cli/repl.js.map +1 -1
- package/dist/src/cli/spinner.d.ts +2 -0
- package/dist/src/cli/spinner.d.ts.map +1 -1
- package/dist/src/cli/spinner.js +18 -0
- package/dist/src/cli/spinner.js.map +1 -1
- package/dist/src/config/mcp-config.d.ts +41 -0
- package/dist/src/config/mcp-config.d.ts.map +1 -0
- package/dist/src/config/mcp-config.js +55 -0
- package/dist/src/config/mcp-config.js.map +1 -0
- package/dist/src/core/agent-runner.d.ts +16 -0
- package/dist/src/core/agent-runner.d.ts.map +1 -1
- package/dist/src/core/agent-runner.js +213 -5
- package/dist/src/core/agent-runner.js.map +1 -1
- package/dist/src/core/agent.d.ts +4 -0
- package/dist/src/core/agent.d.ts.map +1 -1
- package/dist/src/core/agent.js +6 -0
- package/dist/src/core/agent.js.map +1 -1
- package/dist/src/core/event-bus.d.ts +12 -0
- package/dist/src/core/event-bus.d.ts.map +1 -1
- package/dist/src/core/event-bus.js.map +1 -1
- package/dist/src/core/graph-context.d.ts +83 -0
- package/dist/src/core/graph-context.d.ts.map +1 -0
- package/dist/src/core/graph-context.js +370 -0
- package/dist/src/core/graph-context.js.map +1 -0
- package/dist/src/core/intent.d.ts.map +1 -1
- package/dist/src/core/intent.js +3 -0
- package/dist/src/core/intent.js.map +1 -1
- package/dist/src/core/presets.d.ts.map +1 -1
- package/dist/src/core/presets.js +6 -2
- package/dist/src/core/presets.js.map +1 -1
- package/dist/src/core/types.d.ts +19 -0
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/core/types.js +8 -1
- package/dist/src/core/types.js.map +1 -1
- package/dist/src/llm/anthropic.d.ts +1 -0
- package/dist/src/llm/anthropic.d.ts.map +1 -1
- package/dist/src/llm/anthropic.js +20 -1
- package/dist/src/llm/anthropic.js.map +1 -1
- package/dist/src/llm/ollama.d.ts +2 -12
- package/dist/src/llm/ollama.d.ts.map +1 -1
- package/dist/src/llm/ollama.js +46 -250
- package/dist/src/llm/ollama.js.map +1 -1
- package/dist/src/llm/openai.d.ts +1 -0
- package/dist/src/llm/openai.d.ts.map +1 -1
- package/dist/src/llm/openai.js +21 -7
- package/dist/src/llm/openai.js.map +1 -1
- package/dist/src/llm/repair/retry-policy.d.ts +48 -0
- package/dist/src/llm/repair/retry-policy.d.ts.map +1 -0
- package/dist/src/llm/repair/retry-policy.js +85 -0
- package/dist/src/llm/repair/retry-policy.js.map +1 -0
- package/dist/src/llm/repair/tool-repair.d.ts +39 -0
- package/dist/src/llm/repair/tool-repair.d.ts.map +1 -0
- package/dist/src/llm/repair/tool-repair.js +313 -0
- package/dist/src/llm/repair/tool-repair.js.map +1 -0
- package/dist/src/llm/shared/text-cleanup.d.ts +16 -0
- package/dist/src/llm/shared/text-cleanup.d.ts.map +1 -0
- package/dist/src/llm/shared/text-cleanup.js +120 -0
- package/dist/src/llm/shared/text-cleanup.js.map +1 -0
- package/dist/src/llm/shared/tool-parsing.d.ts +70 -0
- package/dist/src/llm/shared/tool-parsing.d.ts.map +1 -0
- package/dist/src/llm/shared/tool-parsing.js +355 -0
- package/dist/src/llm/shared/tool-parsing.js.map +1 -0
- package/dist/src/llm/validation/tool-call-schema.d.ts +83 -0
- package/dist/src/llm/validation/tool-call-schema.d.ts.map +1 -0
- package/dist/src/llm/validation/tool-call-schema.js +145 -0
- package/dist/src/llm/validation/tool-call-schema.js.map +1 -0
- package/dist/src/tools/built-in/bash.d.ts +6 -2
- package/dist/src/tools/built-in/bash.d.ts.map +1 -1
- package/dist/src/tools/built-in/bash.js +34 -46
- package/dist/src/tools/built-in/bash.js.map +1 -1
- package/dist/src/tools/built-in/graph-tools.d.ts +31 -0
- package/dist/src/tools/built-in/graph-tools.d.ts.map +1 -0
- package/dist/src/tools/built-in/graph-tools.js +103 -0
- package/dist/src/tools/built-in/graph-tools.js.map +1 -0
- package/dist/src/tools/built-in/index.d.ts +2 -1
- package/dist/src/tools/built-in/index.d.ts.map +1 -1
- package/dist/src/tools/built-in/index.js +3 -1
- package/dist/src/tools/built-in/index.js.map +1 -1
- package/dist/src/tools/built-in/web-fetch.d.ts +1 -1
- package/dist/src/tools/executor.d.ts +7 -1
- package/dist/src/tools/executor.d.ts.map +1 -1
- package/dist/src/tools/executor.js +20 -5
- package/dist/src/tools/executor.js.map +1 -1
- package/dist/src/tools/shell/shell-executor.d.ts +71 -0
- package/dist/src/tools/shell/shell-executor.d.ts.map +1 -0
- package/dist/src/tools/shell/shell-executor.js +238 -0
- package/dist/src/tools/shell/shell-executor.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool call validation layer using Zod schemas.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors Claude Code's approach: every tool call is validated through its
|
|
5
|
+
* registered Zod schema before execution. Malformed calls are rejected
|
|
6
|
+
* early with clear error messages to the model, enabling retry with
|
|
7
|
+
* corrected format.
|
|
8
|
+
*/
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// Canonical tool call schema — validates the SHAPE of any tool call
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
/**
|
|
14
|
+
* Schema for a single parsed tool call object.
|
|
15
|
+
* All parsed tool calls (from native API, JSON text, XML text) must conform to this.
|
|
16
|
+
*/
|
|
17
|
+
export const ToolCallSchema = z.object({
|
|
18
|
+
name: z.string().min(1, 'Tool name must be a non-empty string'),
|
|
19
|
+
arguments: z.record(z.unknown()).default({}),
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Validate a raw parsed tool call against the canonical schema.
|
|
23
|
+
* Returns a normalized tool call or validation errors.
|
|
24
|
+
*/
|
|
25
|
+
export function validateToolCallShape(raw) {
|
|
26
|
+
const result = ToolCallSchema.safeParse(raw);
|
|
27
|
+
if (result.success) {
|
|
28
|
+
return { ok: true, toolCall: result.data };
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
ok: false,
|
|
32
|
+
errors: result.error.errors.map(e => `${e.path.join('.')}: ${e.message}`),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
// Tool-specific input validation
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
/**
|
|
39
|
+
* Validate a tool call's arguments against the tool's registered Zod input schema.
|
|
40
|
+
* Returns { ok: true, parsed } or { ok: false, message } with a corrective hint.
|
|
41
|
+
*/
|
|
42
|
+
export function validateToolInput(toolName, args, inputSchema) {
|
|
43
|
+
const result = inputSchema.safeParse(args);
|
|
44
|
+
if (result.success) {
|
|
45
|
+
return { ok: true, parsed: result.data };
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
ok: false,
|
|
49
|
+
message: formatZodError(toolName, result.error),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Format a ZodError into a clear corrective message for the model.
|
|
54
|
+
* The message tells the model exactly what was wrong and how to fix it.
|
|
55
|
+
*/
|
|
56
|
+
function formatZodError(toolName, error) {
|
|
57
|
+
const issues = error.errors.map(e => {
|
|
58
|
+
const path = e.path.length > 0 ? `"${e.path.join('.')}"` : 'root';
|
|
59
|
+
return ` - ${path}: ${e.message}`;
|
|
60
|
+
}).join('\n');
|
|
61
|
+
return (`Tool "${toolName}" received invalid arguments:\n${issues}\n` +
|
|
62
|
+
`Please retry with corrected arguments matching the tool's input schema.`);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Validate a batch of tool use blocks against registered tool definitions.
|
|
66
|
+
* Separates valid tool calls from rejected ones with clear error messages.
|
|
67
|
+
*
|
|
68
|
+
* Mirrors Claude Code's flow: Zod input validation → tool-specific validateInput → execute
|
|
69
|
+
*/
|
|
70
|
+
export function validateToolCallBatch(toolUseBlocks, toolLookup, availableToolNames) {
|
|
71
|
+
const valid = [];
|
|
72
|
+
const rejected = [];
|
|
73
|
+
for (const block of toolUseBlocks) {
|
|
74
|
+
// Check tool exists
|
|
75
|
+
if (!availableToolNames.has(block.name)) {
|
|
76
|
+
rejected.push({
|
|
77
|
+
id: block.id,
|
|
78
|
+
name: block.name,
|
|
79
|
+
error: `Unknown tool "${block.name}". Available tools: ${[...availableToolNames].join(', ')}`,
|
|
80
|
+
});
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const toolDef = toolLookup.get(block.name);
|
|
84
|
+
if (!toolDef) {
|
|
85
|
+
rejected.push({
|
|
86
|
+
id: block.id,
|
|
87
|
+
name: block.name,
|
|
88
|
+
error: `Tool "${block.name}" has no registered schema.`,
|
|
89
|
+
});
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
// Validate input against schema
|
|
93
|
+
const validation = validateToolInput(block.name, block.input, toolDef.inputSchema);
|
|
94
|
+
if (!validation.ok) {
|
|
95
|
+
rejected.push({
|
|
96
|
+
id: block.id,
|
|
97
|
+
name: block.name,
|
|
98
|
+
error: validation.message,
|
|
99
|
+
});
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
valid.push({
|
|
103
|
+
id: block.id,
|
|
104
|
+
name: block.name,
|
|
105
|
+
input: validation.parsed,
|
|
106
|
+
rawInput: block.input,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return { valid, rejected };
|
|
110
|
+
}
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
// Leakage detection — detect when models leak tool format into text
|
|
113
|
+
// ---------------------------------------------------------------------------
|
|
114
|
+
/** Patterns that indicate a model is leaking tool call format into text output. */
|
|
115
|
+
const LEAKAGE_PATTERNS = [
|
|
116
|
+
// JSON tool_call format leaking
|
|
117
|
+
/```tool_call[\s\S]*?```/,
|
|
118
|
+
// XML function format leaking
|
|
119
|
+
/<function=\w+>[\s\S]*?<\/function>/,
|
|
120
|
+
// Invoke format leaking
|
|
121
|
+
/<invoke\s+name="[^"]+">[\s\S]*?<\/invoke>/,
|
|
122
|
+
// MiniMax wrapper leaking
|
|
123
|
+
/<minimax:tool_call>[\s\S]*?<\/minimax:tool_call>/,
|
|
124
|
+
// OpenAI function_call format leaking into text
|
|
125
|
+
/"function_call"\s*:\s*\{/,
|
|
126
|
+
];
|
|
127
|
+
/**
|
|
128
|
+
* Detect if text contains leaked tool call formatting.
|
|
129
|
+
* When a model outputs tool call syntax in its text response instead of
|
|
130
|
+
* through the proper tool calling mechanism, we detect it here so the
|
|
131
|
+
* parser can try to extract valid tool calls from it.
|
|
132
|
+
*/
|
|
133
|
+
export function detectToolCallLeakage(text) {
|
|
134
|
+
return LEAKAGE_PATTERNS.some(p => p.test(text));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Build a corrective system message to send back to the model
|
|
138
|
+
* when tool call leakage is detected.
|
|
139
|
+
*/
|
|
140
|
+
export function buildLeakageCorrectionPrompt() {
|
|
141
|
+
return ('Your previous response contained tool call formatting in the text output. ' +
|
|
142
|
+
'Please use the proper tool calling mechanism instead of embedding tool calls in text. ' +
|
|
143
|
+
'Use the tool_call format or the native tool use API to call tools.');
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=tool-call-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-call-schema.js","sourceRoot":"","sources":["../../../../src/llm/validation/tool-call-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAiC,MAAM,KAAK,CAAA;AAGtD,8EAA8E;AAC9E,oEAAoE;AACpE,8EAA8E;AAE9E;;;GAGG;AACH,MAAM,CAAC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C1C,OAAO,CACL,4EAA4E;QAC5E,wFAAwF;QACxF,oEAAoE,CACrE,CAAA;AACH,CAAC"}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Built-in bash tool — execute shell commands.
|
|
2
|
+
* Built-in bash/shell tool — execute shell commands cross-platform.
|
|
3
|
+
*
|
|
4
|
+
* Uses the ShellExecutor for platform-aware execution.
|
|
5
|
+
* On Unix: uses bash/zsh/sh (auto-detected).
|
|
6
|
+
* On Windows: uses PowerShell or cmd.exe (auto-detected).
|
|
3
7
|
*/
|
|
4
8
|
export declare const bashTool: import("../registry.js").ToolDefinition<{
|
|
5
9
|
command: string;
|
|
6
|
-
timeout?: number | undefined;
|
|
7
10
|
cwd?: string | undefined;
|
|
11
|
+
timeout?: number | undefined;
|
|
8
12
|
}>;
|
|
9
13
|
//# sourceMappingURL=bash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../../src/tools/built-in/bash.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../../src/tools/built-in/bash.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH,eAAO,MAAM,QAAQ;;;;EAkDnB,CAAA"}
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Built-in bash tool — execute shell commands.
|
|
2
|
+
* Built-in bash/shell tool — execute shell commands cross-platform.
|
|
3
|
+
*
|
|
4
|
+
* Uses the ShellExecutor for platform-aware execution.
|
|
5
|
+
* On Unix: uses bash/zsh/sh (auto-detected).
|
|
6
|
+
* On Windows: uses PowerShell or cmd.exe (auto-detected).
|
|
3
7
|
*/
|
|
4
|
-
import { spawn } from 'child_process';
|
|
5
8
|
import { z } from 'zod';
|
|
6
9
|
import { defineTool } from '../registry.js';
|
|
7
10
|
import { sanitizeBashCommand } from './bash-security.js';
|
|
11
|
+
import { execute, detectPlatform } from '../shell/shell-executor.js';
|
|
8
12
|
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
13
|
+
const MAX_RESULT_SIZE = 30_000; // 30KB — matches Claude Code's BashTool limit
|
|
9
14
|
export const bashTool = defineTool({
|
|
10
15
|
name: 'bash',
|
|
11
|
-
description: 'Execute a
|
|
16
|
+
description: 'Execute a shell command and return stdout/stderr. ' +
|
|
12
17
|
'Use for file operations, running scripts, installing packages, etc. ' +
|
|
13
|
-
|
|
18
|
+
`Runs in ${detectPlatform() === 'windows' ? 'PowerShell/cmd' : 'bash'} (auto-detected).`,
|
|
14
19
|
inputSchema: z.object({
|
|
15
|
-
command: z.string().describe('The
|
|
20
|
+
command: z.string().describe('The shell command to execute.'),
|
|
16
21
|
timeout: z.number().optional().describe(`Timeout in ms. Defaults to ${DEFAULT_TIMEOUT_MS}.`),
|
|
17
22
|
cwd: z.string().optional().describe('Working directory for the command.'),
|
|
18
23
|
}),
|
|
@@ -24,50 +29,33 @@ export const bashTool = defineTool({
|
|
|
24
29
|
}
|
|
25
30
|
const timeoutMs = input.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
26
31
|
const cwd = input.cwd ?? context.cwd ?? process.cwd();
|
|
27
|
-
const
|
|
32
|
+
const result = await execute({
|
|
33
|
+
command: check.sanitized,
|
|
34
|
+
cwd,
|
|
35
|
+
timeoutMs,
|
|
36
|
+
signal: context.abortSignal,
|
|
37
|
+
});
|
|
28
38
|
const parts = [];
|
|
29
|
-
if (stdout)
|
|
30
|
-
parts.push(stdout);
|
|
31
|
-
if (stderr)
|
|
32
|
-
parts.push(`[stderr]\n${stderr}`);
|
|
33
|
-
if (
|
|
34
|
-
parts.push(`[
|
|
39
|
+
if (result.stdout)
|
|
40
|
+
parts.push(result.stdout);
|
|
41
|
+
if (result.stderr)
|
|
42
|
+
parts.push(`[stderr]\n${result.stderr}`);
|
|
43
|
+
if (result.timedOut)
|
|
44
|
+
parts.push(`[timed out after ${timeoutMs}ms]`);
|
|
45
|
+
if (result.interrupted)
|
|
46
|
+
parts.push('[interrupted by user]');
|
|
47
|
+
if (result.exitCode !== 0)
|
|
48
|
+
parts.push(`[exit code: ${result.exitCode}]`);
|
|
49
|
+
let output = parts.join('\n') || '(no output)';
|
|
50
|
+
// Truncate large outputs to prevent context overflow
|
|
51
|
+
if (output.length > MAX_RESULT_SIZE) {
|
|
52
|
+
const truncated = output.slice(0, MAX_RESULT_SIZE);
|
|
53
|
+
output = truncated + `\n[output truncated: ${output.length} chars total, showing first ${MAX_RESULT_SIZE}]`;
|
|
54
|
+
}
|
|
35
55
|
return {
|
|
36
|
-
data:
|
|
37
|
-
isError: exitCode !== 0,
|
|
56
|
+
data: output,
|
|
57
|
+
isError: result.exitCode !== 0,
|
|
38
58
|
};
|
|
39
59
|
},
|
|
40
60
|
});
|
|
41
|
-
function runCommand(command, cwd, timeoutMs, signal) {
|
|
42
|
-
return new Promise((resolve) => {
|
|
43
|
-
const stdoutChunks = [];
|
|
44
|
-
const stderrChunks = [];
|
|
45
|
-
const child = spawn('bash', ['-c', command], {
|
|
46
|
-
cwd,
|
|
47
|
-
env: process.env,
|
|
48
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
49
|
-
});
|
|
50
|
-
child.stdout.on('data', (chunk) => stdoutChunks.push(chunk));
|
|
51
|
-
child.stderr.on('data', (chunk) => stderrChunks.push(chunk));
|
|
52
|
-
const timer = setTimeout(() => {
|
|
53
|
-
child.kill('SIGKILL');
|
|
54
|
-
}, timeoutMs);
|
|
55
|
-
const onAbort = () => child.kill('SIGKILL');
|
|
56
|
-
signal?.addEventListener('abort', onAbort, { once: true });
|
|
57
|
-
child.on('close', (code) => {
|
|
58
|
-
clearTimeout(timer);
|
|
59
|
-
signal?.removeEventListener('abort', onAbort);
|
|
60
|
-
resolve({
|
|
61
|
-
stdout: Buffer.concat(stdoutChunks).toString('utf-8'),
|
|
62
|
-
stderr: Buffer.concat(stderrChunks).toString('utf-8'),
|
|
63
|
-
exitCode: code ?? 1,
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
child.on('error', (err) => {
|
|
67
|
-
clearTimeout(timer);
|
|
68
|
-
signal?.removeEventListener('abort', onAbort);
|
|
69
|
-
resolve({ stdout: '', stderr: err.message, exitCode: 1 });
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
61
|
//# sourceMappingURL=bash.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../../src/tools/built-in/bash.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../../src/tools/built-in/bash.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,cAAc,EAAmB,MAAM,4BAA4B,CAAA;AAErF,MAAM,kBAAkB,GAAG,MAAM,CAAA;AACjC,MAAM,eAAe,GAAG,MAAM,CAAA,CAAC,8CAA8C;AAE7E,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC;IACjC,IAAI,EAAE,MAAM;IACZ,WAAW,EACT,oDAAoD;QACpD,sEAAsE;QACtE,WAAW,cAAc,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,MAAM,mBAAmB;IAE1F,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,+BAA+B,CAAC;QAC7D,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,8BAA8B,kBAAkB,GAAG,CAAC;QAC5F,GAAG,EAAE,CAAC,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AExE,IAAI,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,aAAa,CAAA;QAE9C,qDAAqD;QACrD,IAAI,MAAM,CAAC,MAAM,GAAG,eAAe,EAAE,CAAC;YACpC,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC,CAAA;YAClD,MAAM,GAAG,SAAS,GAAG,wBAAwB,MAAM,CAAC,MAAM,+BAA+B,eAAe,GAAG,CAAA;QAC7G,CAAC;QAED,OAAO;YACL,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,MAAM,CAAC,QAAQ,KAAK,CAAC;SAC/B,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph tools — curated wrappers around code-review-graph MCP tools.
|
|
3
|
+
*
|
|
4
|
+
* Three tools exposed to the LLM:
|
|
5
|
+
* - graph_impact: blast radius analysis
|
|
6
|
+
* - graph_query: dependency queries (callers, callees, imports, tests)
|
|
7
|
+
* - graph_review: risk-scored review context
|
|
8
|
+
*
|
|
9
|
+
* These are for deep analysis mid-reasoning. Initial grounding is handled
|
|
10
|
+
* by GraphContextProvider's context injection — no duplication.
|
|
11
|
+
*
|
|
12
|
+
* All three are read-only and added to SAFE_PARALLEL_TOOLS.
|
|
13
|
+
*/
|
|
14
|
+
import type { McpClient } from '../../plugins/mcp-client.js';
|
|
15
|
+
export declare function setGraphToolsClient(client: McpClient, projectRoot: string): void;
|
|
16
|
+
export declare function setGraphToolsAvailable(available: boolean): void;
|
|
17
|
+
export declare const graphImpactTool: import("../registry.js").ToolDefinition<{
|
|
18
|
+
base?: string | undefined;
|
|
19
|
+
max_depth?: number | undefined;
|
|
20
|
+
changed_files?: string[] | undefined;
|
|
21
|
+
}>;
|
|
22
|
+
export declare const graphQueryTool: import("../registry.js").ToolDefinition<{
|
|
23
|
+
pattern: "callers_of" | "file_summary" | "callees_of" | "imports_of" | "importers_of" | "children_of" | "tests_for" | "inheritors_of";
|
|
24
|
+
target: string;
|
|
25
|
+
}>;
|
|
26
|
+
export declare const graphReviewTool: import("../registry.js").ToolDefinition<{
|
|
27
|
+
base?: string | undefined;
|
|
28
|
+
changed_files?: string[] | undefined;
|
|
29
|
+
include_source?: boolean | undefined;
|
|
30
|
+
}>;
|
|
31
|
+
//# sourceMappingURL=graph-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-tools.d.ts","sourceRoot":"","sources":["../../../../src/tools/built-in/graph-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAO5D,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAIhF;AAED,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAE/D;AAgBD,eAAO,MAAM,eAAe;;;;EAiB1B,CAAA;AAMF,eAAO,MAAM,cAAc;;;EAiBzB,CAAA;AAMF,eAAO,MAAM,eAAe;;;;EAkB1B,CAAA"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph tools — curated wrappers around code-review-graph MCP tools.
|
|
3
|
+
*
|
|
4
|
+
* Three tools exposed to the LLM:
|
|
5
|
+
* - graph_impact: blast radius analysis
|
|
6
|
+
* - graph_query: dependency queries (callers, callees, imports, tests)
|
|
7
|
+
* - graph_review: risk-scored review context
|
|
8
|
+
*
|
|
9
|
+
* These are for deep analysis mid-reasoning. Initial grounding is handled
|
|
10
|
+
* by GraphContextProvider's context injection — no duplication.
|
|
11
|
+
*
|
|
12
|
+
* All three are read-only and added to SAFE_PARALLEL_TOOLS.
|
|
13
|
+
*/
|
|
14
|
+
import { z } from 'zod';
|
|
15
|
+
import { defineTool } from '../registry.js';
|
|
16
|
+
// Module-level reference — set during startup
|
|
17
|
+
let _mcpClient = null;
|
|
18
|
+
let _graphAvailable = false;
|
|
19
|
+
let _projectRoot = '';
|
|
20
|
+
export function setGraphToolsClient(client, projectRoot) {
|
|
21
|
+
_mcpClient = client;
|
|
22
|
+
_projectRoot = projectRoot;
|
|
23
|
+
_graphAvailable = true;
|
|
24
|
+
}
|
|
25
|
+
export function setGraphToolsAvailable(available) {
|
|
26
|
+
_graphAvailable = available;
|
|
27
|
+
}
|
|
28
|
+
async function callCrg(toolName, input) {
|
|
29
|
+
if (!_graphAvailable || !_mcpClient) {
|
|
30
|
+
return {
|
|
31
|
+
data: 'Code review graph is not available. Install it with: pip install code-review-graph\nThen restart cmdr. Falling back to grep/file_read for code exploration.',
|
|
32
|
+
isError: true,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return _mcpClient.callTool('crg', toolName, input);
|
|
36
|
+
}
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
// graph_impact — blast radius analysis
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
export const graphImpactTool = defineTool({
|
|
41
|
+
name: 'graph_impact',
|
|
42
|
+
description: `Analyze the blast radius of changed files using the code knowledge graph. Shows which functions, classes, and files are impacted by changes. Use this for understanding the scope of modifications before or after editing code. Returns impacted files, affected nodes, and dependency chains.`,
|
|
43
|
+
inputSchema: z.object({
|
|
44
|
+
changed_files: z.array(z.string()).optional().describe('File paths to analyze. Auto-detects from git diff if omitted.'),
|
|
45
|
+
max_depth: z.number().optional().describe('BFS traversal depth in dependency graph. Default: 2.'),
|
|
46
|
+
base: z.string().optional().describe('Git ref for change detection. Default: HEAD~1.'),
|
|
47
|
+
}),
|
|
48
|
+
async execute(input, _context) {
|
|
49
|
+
const params = {
|
|
50
|
+
repo_root: _projectRoot,
|
|
51
|
+
max_depth: input.max_depth ?? 2,
|
|
52
|
+
base: input.base ?? 'HEAD~1',
|
|
53
|
+
};
|
|
54
|
+
if (input.changed_files)
|
|
55
|
+
params.changed_files = input.changed_files;
|
|
56
|
+
return callCrg('get_impact_radius_tool', params);
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
// graph_query — dependency queries
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
export const graphQueryTool = defineTool({
|
|
63
|
+
name: 'graph_query',
|
|
64
|
+
description: `Query the code knowledge graph for structural relationships. Patterns: callers_of (find who calls a function), callees_of (find what a function calls), imports_of (what a file imports), importers_of (who imports a file), children_of (nodes in a file/class), tests_for (tests for a target), inheritors_of (subclasses), file_summary (all nodes in a file).`,
|
|
65
|
+
inputSchema: z.object({
|
|
66
|
+
pattern: z.enum([
|
|
67
|
+
'callers_of', 'callees_of', 'imports_of', 'importers_of',
|
|
68
|
+
'children_of', 'tests_for', 'inheritors_of', 'file_summary',
|
|
69
|
+
]).describe('Query pattern to run.'),
|
|
70
|
+
target: z.string().describe('Node name, qualified name, or file path to query.'),
|
|
71
|
+
}),
|
|
72
|
+
async execute(input, _context) {
|
|
73
|
+
return callCrg('query_graph_tool', {
|
|
74
|
+
pattern: input.pattern,
|
|
75
|
+
target: input.target,
|
|
76
|
+
repo_root: _projectRoot,
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
// ---------------------------------------------------------------------------
|
|
81
|
+
// graph_review — risk-scored review context
|
|
82
|
+
// ---------------------------------------------------------------------------
|
|
83
|
+
export const graphReviewTool = defineTool({
|
|
84
|
+
name: 'graph_review',
|
|
85
|
+
description: `Generate a risk-scored code review using the knowledge graph. Maps git diffs to affected functions, execution flows, communities, and test coverage gaps. Returns prioritized review items with risk levels. Use this for comprehensive code reviews instead of manually reading all changed files.`,
|
|
86
|
+
inputSchema: z.object({
|
|
87
|
+
base: z.string().optional().describe('Git ref to diff against. Default: HEAD~1.'),
|
|
88
|
+
changed_files: z.array(z.string()).optional().describe('Files to review. Auto-detected from git diff if omitted.'),
|
|
89
|
+
include_source: z.boolean().optional().describe('Include source code snippets. Default: false.'),
|
|
90
|
+
}),
|
|
91
|
+
async execute(input, _context) {
|
|
92
|
+
const params = {
|
|
93
|
+
base: input.base ?? 'HEAD~1',
|
|
94
|
+
repo_root: _projectRoot,
|
|
95
|
+
include_source: input.include_source ?? false,
|
|
96
|
+
max_depth: 2,
|
|
97
|
+
};
|
|
98
|
+
if (input.changed_files)
|
|
99
|
+
params.changed_files = input.changed_files;
|
|
100
|
+
return callCrg('detect_changes_tool', params);
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
//# sourceMappingURL=graph-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-tools.js","sourceRoot":"","sources":["../../../../src/tools/built-in/graph-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAI3C,8CAA8C;AAC9C,IAAI,UAAU,GAAqB,IAAI,CAAA;AACvC,IAAI,eAAe,GAAG,KAAK,CAAA;AAC3B,IAAI,YAAY,GAAG,EAAE,CAAA;AAErB,MAAM,UAAU,mBAAmB,CAAC,MAAiB,EAAE,WAAmB;IACxE,UAAU,GAAG,MAAM,CAAA;IACnB,YAAY,GAAG,WAAW,CAAA;IAC1B,eAAe,GAAG,IAAI,CAAA;AACxB,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,SAAkB;IACvD,eAAe,GAAG,SAAS,CAAA;AAC7B,CAAC;AAED,KAAK,UAAU,OAAO,CAAC,QAAgB,EAAE,KAA8B;IACrE,IAAI,CAAC,eAAe,IAAI,CAAC,UAAU,EAAE,CAAC;QACpC,OAAO;YACL,IAAI,EAAE,6JAA6J;YACnK,OAAO,EAAE,IAAI;SACd,CAAA;IACH,CAAC;IACD,OAAO,UAAU,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,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AAqB,EAAE,MAAM,CAAC,CAAA;IAC/C,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -25,7 +25,8 @@ import { taskCreateTool, taskListTool, taskGetTool, taskStopTool } from './task-
|
|
|
25
25
|
import { cronCreateTool, cronListTool, cronDeleteTool } from './cron-tools.js';
|
|
26
26
|
import { enterPlanModeTool, exitPlanModeTool } from './plan-tools.js';
|
|
27
27
|
import { mcpListResourcesTool, mcpReadResourceTool } from './mcp-resource-tools.js';
|
|
28
|
-
|
|
28
|
+
import { graphImpactTool, graphQueryTool, graphReviewTool } from './graph-tools.js';
|
|
29
|
+
export { bashTool, fileReadTool, fileWriteTool, fileEditTool, grepTool, globTool, gitDiffTool, gitLogTool, gitCommitTool, gitBranchTool, gitWorktreeTool, lspDiagnosticsTool, notebookReadTool, notebookEditTool, notebookRunTool, thinkTool, webFetchTool, webSearchTool, askUserTool, memoryReadTool, memoryWriteTool, todoWriteTool, taskCreateTool, taskListTool, taskGetTool, taskStopTool, cronCreateTool, cronListTool, cronDeleteTool, enterPlanModeTool, exitPlanModeTool, mcpListResourcesTool, mcpReadResourceTool, graphImpactTool, graphQueryTool, graphReviewTool, };
|
|
29
30
|
export declare const BUILT_IN_TOOLS: ToolDefinition<any>[];
|
|
30
31
|
export declare function registerBuiltInTools(registry: ToolRegistry): void;
|
|
31
32
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tools/built-in/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;A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7 +23,8 @@ import { taskCreateTool, taskListTool, taskGetTool, taskStopTool } from './task-
|
|
|
23
23
|
import { cronCreateTool, cronListTool, cronDeleteTool } from './cron-tools.js';
|
|
24
24
|
import { enterPlanModeTool, exitPlanModeTool } from './plan-tools.js';
|
|
25
25
|
import { mcpListResourcesTool, mcpReadResourceTool } from './mcp-resource-tools.js';
|
|
26
|
-
|
|
26
|
+
import { graphImpactTool, graphQueryTool, graphReviewTool } from './graph-tools.js';
|
|
27
|
+
export { bashTool, fileReadTool, fileWriteTool, fileEditTool, grepTool, globTool, gitDiffTool, gitLogTool, gitCommitTool, gitBranchTool, gitWorktreeTool, lspDiagnosticsTool, notebookReadTool, notebookEditTool, notebookRunTool, thinkTool, webFetchTool, webSearchTool, askUserTool, memoryReadTool, memoryWriteTool, todoWriteTool, taskCreateTool, taskListTool, taskGetTool, taskStopTool, cronCreateTool, cronListTool, cronDeleteTool, enterPlanModeTool, exitPlanModeTool, mcpListResourcesTool, mcpReadResourceTool, graphImpactTool, graphQueryTool, graphReviewTool, };
|
|
27
28
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
29
|
export const BUILT_IN_TOOLS = [
|
|
29
30
|
bashTool, fileReadTool, fileWriteTool, fileEditTool,
|
|
@@ -36,6 +37,7 @@ export const BUILT_IN_TOOLS = [
|
|
|
36
37
|
cronCreateTool, cronListTool, cronDeleteTool,
|
|
37
38
|
enterPlanModeTool, exitPlanModeTool,
|
|
38
39
|
mcpListResourcesTool, mcpReadResourceTool,
|
|
40
|
+
graphImpactTool, graphQueryTool, graphReviewTool,
|
|
39
41
|
];
|
|
40
42
|
export function registerBuiltInTools(registry) {
|
|
41
43
|
for (const tool of BUILT_IN_TOOLS) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/tools/built-in/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAC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AAa,EAAE,aAAa;IACzE,eAAe,EAAE,kBAAkB;IACnC,gBAAgB,EAAE,gBAAgB,EAAE,eAAe;IACnD,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe;IACpF,aAAa;IACb,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY;IACvD,cAAc,EAAE,YAAY,EAAE,cAAc;IAC5C,iBAAiB,EAAE,gBAAgB;IACnC,oBAAoB,EAAE,mBAAmB;IACzC,eAAe,EAAE,cAAc,EAAE,eAAe;CACjD,CAAA;AAED,MAAM,UAAU,oBAAoB,CAAC,QAAsB;IACzD,KAAK,MAAM,IAAI,IAAI,cAAc,EAAE,CAAC;QAClC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7B,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export declare const webFetchTool: import("../registry.js").ToolDefinition<{
|
|
5
5
|
url: string;
|
|
6
|
-
method?: "GET" | "POST" | undefined;
|
|
7
6
|
headers?: Record<string, string> | undefined;
|
|
7
|
+
method?: "POST" | "GET" | undefined;
|
|
8
8
|
body?: string | undefined;
|
|
9
9
|
maxBytes?: number | undefined;
|
|
10
10
|
}>;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Tool executor with concurrency control and error isolation.
|
|
2
|
+
* Tool executor with concurrency control, Zod validation, and error isolation.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors Claude Code's tool execution flow:
|
|
5
|
+
* 1. Tool lookup (with unknown tool rejection)
|
|
6
|
+
* 2. Zod schema validation (with corrective error messages)
|
|
7
|
+
* 3. Concurrency-limited execution
|
|
8
|
+
* 4. Error isolation (tool failures don't crash the agent loop)
|
|
3
9
|
*/
|
|
4
10
|
import type { ToolResult, ToolUseContext } from '../core/types.js';
|
|
5
11
|
import type { ToolRegistry } from './registry.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/tools/executor.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/tools/executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAGjD,MAAM,WAAW,mBAAmB;IAClC,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC/B;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAc;IACvC,OAAO,CAAC,MAAM,CAAI;IAClB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAQ;IACvC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAwB;gBAEtC,QAAQ,EAAE,YAAY,EAAE,OAAO,GAAE,mBAAwB;IAK/D,OAAO,CACX,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,UAAU,CAAC;IA6BhB,YAAY,CAChB,KAAK,EAAE,aAAa,EAAE,EACtB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAUnC,OAAO,CAAC,OAAO;IAaf,OAAO,CAAC,OAAO;CAKhB"}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Tool executor with concurrency control and error isolation.
|
|
2
|
+
* Tool executor with concurrency control, Zod validation, and error isolation.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors Claude Code's tool execution flow:
|
|
5
|
+
* 1. Tool lookup (with unknown tool rejection)
|
|
6
|
+
* 2. Zod schema validation (with corrective error messages)
|
|
7
|
+
* 3. Concurrency-limited execution
|
|
8
|
+
* 4. Error isolation (tool failures don't crash the agent loop)
|
|
3
9
|
*/
|
|
10
|
+
import { validateToolInput } from '../llm/validation/tool-call-schema.js';
|
|
4
11
|
export class ToolExecutor {
|
|
5
12
|
registry;
|
|
6
13
|
active = 0;
|
|
@@ -13,13 +20,21 @@ export class ToolExecutor {
|
|
|
13
20
|
async execute(name, input, context) {
|
|
14
21
|
const tool = this.registry.get(name);
|
|
15
22
|
if (!tool) {
|
|
16
|
-
|
|
23
|
+
const availableTools = this.registry.list().map(t => t.name).join(', ');
|
|
24
|
+
return {
|
|
25
|
+
data: `Unknown tool: "${name}". Available tools: ${availableTools}`,
|
|
26
|
+
isError: true,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
// Validate input through Zod schema with corrective error messages
|
|
30
|
+
const validation = validateToolInput(name, input, tool.inputSchema);
|
|
31
|
+
if (!validation.ok) {
|
|
32
|
+
return { data: validation.message, isError: true };
|
|
17
33
|
}
|
|
18
34
|
try {
|
|
19
|
-
const parsed = tool.inputSchema.parse(input);
|
|
20
35
|
await this.acquire();
|
|
21
36
|
try {
|
|
22
|
-
return await tool.execute(parsed, context);
|
|
37
|
+
return await tool.execute(validation.parsed, context);
|
|
23
38
|
}
|
|
24
39
|
finally {
|
|
25
40
|
this.release();
|
|
@@ -27,7 +42,7 @@ export class ToolExecutor {
|
|
|
27
42
|
}
|
|
28
43
|
catch (err) {
|
|
29
44
|
const message = err instanceof Error ? err.message : String(err);
|
|
30
|
-
return { data: `Tool "${name}" error: ${message}`, isError: true };
|
|
45
|
+
return { data: `Tool "${name}" execution error: ${message}`, isError: true };
|
|
31
46
|
}
|
|
32
47
|
}
|
|
33
48
|
async executeBatch(calls, context) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../src/tools/executor.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../src/tools/executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAA;AAYzE,MAAM,OAAO,YAAY;IACN,QAAQ,CAAc;IAC/B,MAAM,GAAG,CAAC,CAAA;IACD,cAAc,CAAQ;IACtB,SAAS,GAAsB,EAAE,CAAA;IAElD,YAAY,QAAsB,EAAE,UAA+B,EAAE;QACnE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,CAAC,CAAA;IACnD,CAAC;IAED,KAAK,CAAC,OAAO,CACX,IAAY,EACZ,KAA8B,EAC9B,OAAuB;QAEvB,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACpC,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACvE,OAAO;gBACL,IAAI,EAAE,kBAAkB,IAAI,uBAAuB,cAAc,EAAE;gBACnE,OAAO,EAAE,IAAI;aACd,CAAA;QACH,CAAC;QAED,mEAAmE;QACnE,MAAM,UAAU,GAAG,iBAAiB,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;QACnE,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC;YACnB,OAAO,EAAE,I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