@causyne/agent 1.12.0 → 1.14.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/docs/THIRD_PARTY_NOTICES.md +1 -1
- package/package.json +2 -2
- package/src/acp/agentCatalog.js +389 -0
- package/src/acp/agentCatalog.ts +455 -0
- package/src/acp/client.js +127 -4
- package/src/acp/client.ts +145 -5
- package/src/acp/peerProfiles.js +81 -3
- package/src/acp/peerProfiles.ts +85 -4
- package/src/acp/protocol.js +2 -0
- package/src/acp/protocol.ts +19 -0
- package/src/agentLoop.js +33 -12
- package/src/commands.js +108 -0
- package/src/engines/deck.js +105 -0
- package/src/engines/deck.ts +109 -0
- package/src/engines/design.js +123 -0
- package/src/engines/design.ts +141 -0
- package/src/engines/effect.js +128 -0
- package/src/engines/effect.ts +142 -0
- package/src/engines/grid.js +106 -0
- package/src/engines/grid.ts +121 -0
- package/src/engines/light.js +107 -0
- package/src/engines/light.ts +122 -0
- package/src/engines/pdf.js +108 -0
- package/src/engines/pdf.ts +124 -0
- package/src/engines/registry.js +15 -1
- package/src/engines/registry.ts +15 -1
- package/src/engines/word.js +112 -0
- package/src/engines/word.ts +127 -0
- package/src/entrypoint.js +11 -0
- package/src/providers/anthropic.js +5 -13
- package/src/providers/dashscope-byok.js +3 -4
- package/src/providers/deepseek.js +3 -4
- package/src/providers/gemini.js +17 -101
- package/src/providers/moonshot.js +3 -4
- package/src/providers/ollama.js +3 -4
- package/src/providers/openai-compatible.js +3 -4
- package/src/providers/qwen-byok.js +3 -4
- package/src/providers/xai.js +3 -4
- package/src/tools/peerAgent.js +115 -31
- package/src/tools/peerAgent.ts +143 -32
- package/src/tools/registry.js +144 -16
- package/src/tools/toolScanner.js +349 -0
- package/src/tools/toolScanner.ts +451 -0
- package/src/tools/toolSelfRepair.js +759 -0
- package/src/tools/toolSelfRepair.ts +846 -0
package/src/tools/peerAgent.ts
CHANGED
|
@@ -1,113 +1,224 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Causyne Peer Agent Tool
|
|
3
3
|
*
|
|
4
|
-
* Delegates a bounded task to an external ACP agent
|
|
5
|
-
*
|
|
6
|
-
* it never chooses the executable
|
|
7
|
-
*
|
|
4
|
+
* Delegates a bounded task to an external ACP agent (e.g. OpenCode, Claude Code,
|
|
5
|
+
* Codex, Gemini CLI, Hermes, Cursor, Qwen). The model chooses a profile and writes
|
|
6
|
+
* a prompt; it never chooses the raw executable or unrestricted arguments.
|
|
7
|
+
* Those come from the catalog presets or the user's `~/.causyne/peers.json`.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import path from 'node:path';
|
|
10
11
|
import { AcpClient } from '../acp/client.js';
|
|
11
12
|
import type { RequestPermissionRequest, RequestPermissionResponse } from '../acp/protocol.js';
|
|
12
|
-
import { getPeerProfile,
|
|
13
|
+
import { getPeerProfile, listAllPeers, peerEnvironment } from '../acp/peerProfiles.js';
|
|
13
14
|
import type { PeerProfile } from '../acp/peerProfiles.js';
|
|
15
|
+
import { BUILTIN_PEER_PRESETS } from '../acp/agentCatalog.js';
|
|
14
16
|
|
|
15
17
|
export interface PeerAgentArgs {
|
|
18
|
+
action?: 'delegate' | 'list' | 'status';
|
|
16
19
|
peer?: string;
|
|
17
|
-
prompt
|
|
20
|
+
prompt?: string;
|
|
18
21
|
timeoutSeconds?: number;
|
|
22
|
+
model?: string;
|
|
23
|
+
mode?: string;
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
const MAX_PROMPT_CHARS = 100_000;
|
|
22
27
|
const READ_ONLY_KINDS = new Set(['read', 'search', 'fetch', 'think']);
|
|
23
28
|
|
|
24
|
-
function selectPermission(
|
|
29
|
+
function selectPermission(
|
|
30
|
+
profile: PeerProfile,
|
|
31
|
+
request: RequestPermissionRequest,
|
|
32
|
+
workspaceRoot: string
|
|
33
|
+
): RequestPermissionResponse['outcome'] {
|
|
25
34
|
const kind = request.toolCall.kind;
|
|
26
35
|
const readLike = typeof kind === 'string' && READ_ONLY_KINDS.has(kind);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
|
|
37
|
+
if (profile.policy === 'read-only') {
|
|
38
|
+
if (!readLike) {
|
|
39
|
+
const reject = request.options.find((option) => option.kind === 'reject_once' || option.kind === 'reject_always');
|
|
40
|
+
return reject ? { outcome: 'selected', optionId: reject.optionId } : { outcome: 'cancelled' };
|
|
41
|
+
}
|
|
42
|
+
const allow = request.options.find((option) => option.kind === 'allow_once' || option.kind === 'allow_always');
|
|
43
|
+
return allow ? { outcome: 'selected', optionId: allow.optionId } : { outcome: 'cancelled' };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (profile.policy === 'workspace') {
|
|
47
|
+
// If locations are provided, verify they are inside workspaceRoot
|
|
48
|
+
const locations = request.toolCall.locations || [];
|
|
49
|
+
const isInsideWorkspace = locations.length === 0 || locations.every((loc) => {
|
|
50
|
+
const resolved = path.resolve(workspaceRoot, loc.path);
|
|
51
|
+
return !path.relative(workspaceRoot, resolved).startsWith('..') && !path.isAbsolute(path.relative(workspaceRoot, resolved));
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (isInsideWorkspace) {
|
|
55
|
+
const allow = request.options.find((option) => option.kind === 'allow_once' || option.kind === 'allow_always');
|
|
56
|
+
return allow ? { outcome: 'selected', optionId: allow.optionId } : { outcome: 'cancelled' };
|
|
57
|
+
} else {
|
|
58
|
+
const reject = request.options.find((option) => option.kind === 'reject_once' || option.kind === 'reject_always');
|
|
59
|
+
return reject ? { outcome: 'selected', optionId: reject.optionId } : { outcome: 'cancelled' };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 'ask' policy: default to rejecting unless read-like or user approval can be obtained
|
|
64
|
+
if (readLike) {
|
|
65
|
+
const allow = request.options.find((option) => option.kind === 'allow_once' || option.kind === 'allow_always');
|
|
66
|
+
return allow ? { outcome: 'selected', optionId: allow.optionId } : { outcome: 'cancelled' };
|
|
30
67
|
}
|
|
31
|
-
|
|
68
|
+
|
|
69
|
+
// Mutating requests under 'ask' policy default to requiring confirmation
|
|
70
|
+
const allow = request.options.find((option) => option.kind === 'allow_once');
|
|
32
71
|
return allow ? { outcome: 'selected', optionId: allow.optionId } : { outcome: 'cancelled' };
|
|
33
72
|
}
|
|
34
73
|
|
|
35
74
|
export const peerAgentTool = {
|
|
36
75
|
schema: {
|
|
37
76
|
name: 'peer_agent_delegate',
|
|
38
|
-
description: '
|
|
77
|
+
description: 'Connect, inspect, or delegate a bounded task to an external ACP peer agent (such as OpenCode, Claude Code, Codex, Gemini CLI, Hermes, Cursor, or Qwen). Supports listing available peers and delegating tasks with permission policies.',
|
|
39
78
|
parameters: {
|
|
40
79
|
type: 'object',
|
|
41
80
|
properties: {
|
|
81
|
+
action: {
|
|
82
|
+
type: 'string',
|
|
83
|
+
enum: ['delegate', 'list', 'status'],
|
|
84
|
+
description: 'Action to perform: "delegate" to execute a task, "list" or "status" to view available peer agents.'
|
|
85
|
+
},
|
|
42
86
|
peer: {
|
|
43
87
|
type: 'string',
|
|
44
|
-
description: 'Id of
|
|
88
|
+
description: 'Id of the peer agent (e.g. "opencode", "claude", "codex", "hermes", "cursor", "gemini").'
|
|
45
89
|
},
|
|
46
90
|
prompt: {
|
|
47
91
|
type: 'string',
|
|
48
|
-
description: 'Task instructions and context for the peer agent.'
|
|
92
|
+
description: 'Task instructions and context for the peer agent (required when action is delegate).'
|
|
93
|
+
},
|
|
94
|
+
model: {
|
|
95
|
+
type: 'string',
|
|
96
|
+
description: 'Optional model to select on the peer agent (e.g. "opencode-free", "claude-3-7-sonnet").'
|
|
97
|
+
},
|
|
98
|
+
mode: {
|
|
99
|
+
type: 'string',
|
|
100
|
+
description: 'Optional session mode for the peer agent.'
|
|
49
101
|
},
|
|
50
102
|
timeoutSeconds: {
|
|
51
103
|
type: 'number',
|
|
52
|
-
description: 'Optional
|
|
104
|
+
description: 'Optional timeout in seconds (default 120, bounded between 5 and 1800).'
|
|
53
105
|
}
|
|
54
|
-
}
|
|
55
|
-
required: ['peer', 'prompt']
|
|
106
|
+
}
|
|
56
107
|
}
|
|
57
108
|
},
|
|
58
|
-
async execute(args: PeerAgentArgs): Promise<{
|
|
109
|
+
async execute(args: PeerAgentArgs = {}): Promise<{
|
|
110
|
+
success: boolean;
|
|
111
|
+
output?: string;
|
|
112
|
+
error?: string;
|
|
113
|
+
peers?: Array<{ id: string; label: string; policy: string; timeoutSeconds: number }>;
|
|
114
|
+
agent?: string;
|
|
115
|
+
stopReason?: string;
|
|
116
|
+
}> {
|
|
117
|
+
const action = args.action || (args.peer || args.prompt !== undefined ? 'delegate' : 'list');
|
|
118
|
+
|
|
119
|
+
// 1. Action: list
|
|
120
|
+
if (action === 'list' || action === 'status') {
|
|
121
|
+
const allPeers = listAllPeers();
|
|
122
|
+
const peerList = allPeers.map((p) => ({
|
|
123
|
+
id: p.id,
|
|
124
|
+
label: p.label,
|
|
125
|
+
policy: p.policy,
|
|
126
|
+
timeoutSeconds: p.timeoutSeconds
|
|
127
|
+
}));
|
|
128
|
+
|
|
129
|
+
const presetIds = Object.keys(BUILTIN_PEER_PRESETS).join(', ');
|
|
130
|
+
return {
|
|
131
|
+
success: true,
|
|
132
|
+
peers: peerList,
|
|
133
|
+
output: `Configured and discovered ACP peer agents:\n${peerList.map((p) => `• ${p.id} (${p.label}) [policy: ${p.policy}, timeout: ${p.timeoutSeconds}s]`).join('\n')}\n\nBuilt-in presets supported: ${presetIds}.`
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// 2. Action: delegate
|
|
59
138
|
const peerId = String(args.peer || '').trim();
|
|
60
139
|
const prompt = String(args.prompt || '').trim().slice(0, MAX_PROMPT_CHARS);
|
|
140
|
+
|
|
61
141
|
if (!peerId) {
|
|
62
|
-
const
|
|
142
|
+
const available = listAllPeers().map((p) => p.id);
|
|
63
143
|
return {
|
|
64
144
|
success: false,
|
|
65
|
-
error:
|
|
66
|
-
? `A peer id is required. Configured peers: ${configured.join(', ')}.`
|
|
67
|
-
: 'No peer profiles are configured. Add one to the peers file first.'
|
|
145
|
+
error: `A peer id is required for delegation. Available peers: ${available.join(', ')}.`
|
|
68
146
|
};
|
|
69
147
|
}
|
|
148
|
+
|
|
70
149
|
if (!prompt) {
|
|
71
150
|
return { success: false, error: 'A prompt is required for peer delegation.' };
|
|
72
151
|
}
|
|
73
152
|
|
|
74
153
|
const profile = getPeerProfile(peerId);
|
|
75
154
|
if (!profile) {
|
|
76
|
-
return { success: false, error: `Unknown peer profile: ${peerId}.` };
|
|
155
|
+
return { success: false, error: `Unknown peer profile: ${peerId}. Run with action "list" to see available peers.` };
|
|
77
156
|
}
|
|
78
157
|
|
|
79
|
-
const
|
|
158
|
+
const requestedTimeout = typeof args.timeoutSeconds === 'number' && Number.isFinite(args.timeoutSeconds)
|
|
80
159
|
? Math.round(args.timeoutSeconds)
|
|
81
160
|
: profile.timeoutSeconds;
|
|
82
|
-
const timeoutSeconds = Math.max(5, Math.min(Math.min(profile.timeoutSeconds,
|
|
161
|
+
const timeoutSeconds = Math.max(5, Math.min(Math.min(profile.timeoutSeconds, requestedTimeout), 1800));
|
|
162
|
+
|
|
163
|
+
const workspaceRoot = profile.cwd || process.cwd();
|
|
83
164
|
|
|
84
165
|
const client = new AcpClient({
|
|
85
166
|
command: profile.command,
|
|
86
167
|
args: profile.args,
|
|
87
|
-
cwd:
|
|
168
|
+
cwd: workspaceRoot,
|
|
88
169
|
env: peerEnvironment(profile),
|
|
89
170
|
promptTimeoutMs: timeoutSeconds * 1000,
|
|
90
|
-
permissionHandler: async (request) => selectPermission(profile, request)
|
|
171
|
+
permissionHandler: async (request) => selectPermission(profile, request, workspaceRoot)
|
|
91
172
|
});
|
|
92
173
|
|
|
93
174
|
try {
|
|
94
175
|
await client.start();
|
|
95
|
-
const sessionId = await client.newSession(
|
|
176
|
+
const sessionId = await client.newSession(workspaceRoot);
|
|
177
|
+
|
|
178
|
+
// Optional model selection if specified
|
|
179
|
+
if (args.model && client.agentCapabilities?.promptCapabilities) {
|
|
180
|
+
try {
|
|
181
|
+
await client.setSessionModel(sessionId, args.model);
|
|
182
|
+
} catch {
|
|
183
|
+
// If model selection fails, continue with default model
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Optional mode selection if specified
|
|
188
|
+
if (args.mode) {
|
|
189
|
+
try {
|
|
190
|
+
await client.setSessionMode(sessionId, args.mode);
|
|
191
|
+
} catch {
|
|
192
|
+
// If mode selection fails, continue with default mode
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
96
196
|
const result = await client.prompt(sessionId, prompt);
|
|
97
197
|
if (result.stopReason === 'cancelled') {
|
|
98
|
-
return { success: false, error:
|
|
198
|
+
return { success: false, error: `The peer agent "${peerId}" cancelled the task.` };
|
|
99
199
|
}
|
|
100
200
|
if (result.stopReason === 'refusal') {
|
|
101
|
-
return { success: false, error:
|
|
201
|
+
return { success: false, error: `The peer agent "${peerId}" refused the task.` };
|
|
102
202
|
}
|
|
203
|
+
|
|
204
|
+
const agentName = client.agentInfo?.name || profile.label;
|
|
103
205
|
return {
|
|
104
206
|
success: true,
|
|
105
|
-
|
|
207
|
+
agent: agentName,
|
|
208
|
+
stopReason: result.stopReason,
|
|
209
|
+
output: result.text.trim() || `Peer agent "${agentName}" completed the task without a written summary.`
|
|
106
210
|
};
|
|
107
211
|
} catch (error) {
|
|
212
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
213
|
+
const isAuthError = /auth|login|credentials|unauthorized/i.test(msg);
|
|
214
|
+
const preset = BUILTIN_PEER_PRESETS[peerId.toLowerCase()];
|
|
215
|
+
const instruction = preset?.setupInstruction ? `\nGuidance: ${preset.setupInstruction}` : '';
|
|
216
|
+
|
|
108
217
|
return {
|
|
109
218
|
success: false,
|
|
110
|
-
error:
|
|
219
|
+
error: isAuthError
|
|
220
|
+
? `Authentication required for peer "${peerId}": ${msg}.${instruction}`
|
|
221
|
+
: `Peer agent delegation to "${peerId}" failed: ${msg}.${instruction}`
|
|
111
222
|
};
|
|
112
223
|
} finally {
|
|
113
224
|
await client.close();
|
package/src/tools/registry.js
CHANGED
|
@@ -151,38 +151,166 @@ for (const module of TOOL_MODULES) {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
// Names that older releases (and any chat history persisted under them) used for
|
|
154
|
-
// a tool whose canonical schema name is different
|
|
155
|
-
//
|
|
154
|
+
// a tool whose canonical schema name is different, plus universal aliases for
|
|
155
|
+
// models that hallucinate common tool names from other environments.
|
|
156
156
|
const TOOL_ALIASES = {
|
|
157
157
|
TodoWrite: 'update_plan',
|
|
158
158
|
manage_local_ai_dependencies: 'manage_local_dependencies',
|
|
159
159
|
procTerm: 'proc_term',
|
|
160
160
|
gitExec: 'gitOp',
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
//
|
|
164
|
-
|
|
161
|
+
tool_deferred_mcp_search: 'tool_search',
|
|
162
|
+
|
|
163
|
+
// Core filesystem aliases
|
|
164
|
+
read_file: 'fs_read',
|
|
165
|
+
readFile: 'fs_read',
|
|
166
|
+
view_file: 'fs_read',
|
|
167
|
+
cat: 'fs_read',
|
|
168
|
+
write_file: 'fs_write',
|
|
169
|
+
writeFile: 'fs_write',
|
|
170
|
+
write_to_file: 'fs_write',
|
|
171
|
+
create_file: 'fs_write',
|
|
172
|
+
edit_file: 'fs_edit',
|
|
173
|
+
editFile: 'fs_edit',
|
|
174
|
+
replace_file_content: 'fs_edit',
|
|
175
|
+
modify_file: 'fs_edit',
|
|
176
|
+
delete_file: 'fs_delete',
|
|
177
|
+
deleteFile: 'fs_delete',
|
|
178
|
+
remove_file: 'fs_delete',
|
|
179
|
+
rm: 'fs_delete',
|
|
180
|
+
list_dir: 'fs_list',
|
|
181
|
+
listDir: 'fs_list',
|
|
182
|
+
list_files: 'fs_list',
|
|
183
|
+
listFiles: 'fs_list',
|
|
184
|
+
list_directory: 'fs_list',
|
|
185
|
+
ls: 'fs_list',
|
|
186
|
+
find_files: 'fs_find',
|
|
187
|
+
findFiles: 'fs_find',
|
|
188
|
+
find_file: 'fs_find',
|
|
189
|
+
glob: 'fs_find',
|
|
190
|
+
search_files: 'fs_search',
|
|
191
|
+
grep: 'fs_search',
|
|
192
|
+
grep_search: 'fs_search',
|
|
193
|
+
move_file: 'fs_move',
|
|
194
|
+
moveFile: 'fs_move',
|
|
195
|
+
rename_file: 'fs_move',
|
|
196
|
+
mv: 'fs_move',
|
|
197
|
+
patch: 'MultiEdit',
|
|
198
|
+
multi_edit: 'MultiEdit',
|
|
199
|
+
multiedit: 'MultiEdit',
|
|
200
|
+
diff_edit: 'MultiEdit',
|
|
201
|
+
|
|
202
|
+
// Execution & shell aliases
|
|
203
|
+
sys_run: 'sysRun',
|
|
204
|
+
sysrun: 'sysRun',
|
|
205
|
+
run_command: 'sysRun',
|
|
206
|
+
runCommand: 'sysRun',
|
|
207
|
+
bash: 'sysRun',
|
|
208
|
+
sh: 'sysRun',
|
|
209
|
+
terminal: 'sysRun',
|
|
210
|
+
exec_command: 'sysRun',
|
|
211
|
+
execute_command: 'sysRun',
|
|
212
|
+
shell: 'sysRun',
|
|
213
|
+
sys_run_bg: 'sysRunBg',
|
|
214
|
+
sysrunbg: 'sysRunBg',
|
|
215
|
+
sysRun_bg: 'sysRunBg',
|
|
216
|
+
run_bg: 'sysRunBg',
|
|
217
|
+
run_background: 'sysRunBg',
|
|
218
|
+
background_run: 'sysRunBg',
|
|
219
|
+
git_op: 'gitOp',
|
|
220
|
+
gitop: 'gitOp',
|
|
221
|
+
git: 'gitOp',
|
|
222
|
+
persistent_shell: 'terminal_persistent_shell',
|
|
223
|
+
terminal_shell: 'terminal_persistent_shell',
|
|
224
|
+
|
|
225
|
+
// Web & search aliases
|
|
226
|
+
search_web: 'web_search',
|
|
227
|
+
searchWeb: 'web_search',
|
|
228
|
+
google_search: 'web_search',
|
|
229
|
+
search_internet: 'web_search',
|
|
230
|
+
fetch_url: 'web_fetch',
|
|
231
|
+
fetchUrl: 'web_fetch',
|
|
232
|
+
read_url: 'web_fetch',
|
|
233
|
+
read_url_content: 'web_fetch',
|
|
234
|
+
http_get: 'web_fetch',
|
|
235
|
+
|
|
236
|
+
// Specialized engines & capabilities
|
|
237
|
+
nativeEngine: 'native_engine',
|
|
238
|
+
'native-engine': 'native_engine',
|
|
239
|
+
creativeApps: 'creative_apps',
|
|
240
|
+
'creative-apps': 'creative_apps',
|
|
241
|
+
astryxOracle: 'astryx_oracle',
|
|
242
|
+
pdfRead: 'pdf_read',
|
|
243
|
+
codeVerifySyntax: 'code_verify_syntax',
|
|
244
|
+
codeListSymbols: 'code_list_symbols',
|
|
245
|
+
codeSearchAst: 'code_search_ast',
|
|
246
|
+
codeSearcher: 'code_search_ripgrep',
|
|
247
|
+
blenderAutomator: 'blender_act',
|
|
248
|
+
resolveAutomator: 'resolve_act',
|
|
249
|
+
palmierAutomator: 'palmier_act',
|
|
250
|
+
godotAutomator: 'godot_act',
|
|
251
|
+
visionInspector: 'vision_inspect_ui',
|
|
252
|
+
vision_inspector: 'vision_inspect_ui',
|
|
253
|
+
vision_inspect: 'vision_inspect_ui',
|
|
254
|
+
computerUse: 'computer_use',
|
|
255
|
+
uiForge: 'ui_forge',
|
|
256
|
+
documentForge: 'document_forge',
|
|
257
|
+
documentForgeTool: 'document_forge',
|
|
258
|
+
peerAgent: 'peer_agent_delegate',
|
|
259
|
+
peer_agent: 'peer_agent_delegate',
|
|
260
|
+
openSourceToolProvisioner: 'open_source_tool_provisioner',
|
|
261
|
+
open_source_tool: 'open_source_tool_provisioner',
|
|
262
|
+
subagent: 'agent_subagent_orchestrate',
|
|
263
|
+
subagent_orchestrator: 'agent_subagent_orchestrate',
|
|
264
|
+
spawn_subagent: 'agent_subagent_orchestrate',
|
|
265
|
+
agent_orchestrator: 'agent_subagent_orchestrate',
|
|
266
|
+
printer_status: 'printer_get_status',
|
|
267
|
+
printer_list: 'printer_list_printers',
|
|
268
|
+
create_skill: 'skill_create',
|
|
269
|
+
read_skill: 'fs_read_skill',
|
|
270
|
+
readNativeSkill: 'fs_read_skill',
|
|
271
|
+
take_screenshot: 'screenshot',
|
|
272
|
+
capture_screenshot: 'screenshot',
|
|
273
|
+
open_file: 'desktop_open',
|
|
274
|
+
open_desktop: 'desktop_open'
|
|
165
275
|
};
|
|
166
276
|
|
|
277
|
+
function stripDelimiters(str) {
|
|
278
|
+
return String(str || '').toLowerCase().replace(/[-_.]/g, '');
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Precompute delimiter-free lookup table for fuzzy casing/naming matches
|
|
282
|
+
const DELIMITER_FREE_INDEX = {};
|
|
283
|
+
for (const key of Object.keys(toolRegistry)) {
|
|
284
|
+
DELIMITER_FREE_INDEX[stripDelimiters(key)] = key;
|
|
285
|
+
}
|
|
286
|
+
for (const [alias, target] of Object.entries(TOOL_ALIASES)) {
|
|
287
|
+
if (toolRegistry[target]) {
|
|
288
|
+
DELIMITER_FREE_INDEX[stripDelimiters(alias)] = target;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** The canonical catalogue name for anything the model might call it. */
|
|
293
|
+
export function canonicalToolName(name) {
|
|
294
|
+
const normalized = normalizeToolName(name);
|
|
295
|
+
if (toolRegistry[normalized]) return normalized;
|
|
296
|
+
if (TOOL_ALIASES[normalized]) return TOOL_ALIASES[normalized];
|
|
297
|
+
const fuzzy = DELIMITER_FREE_INDEX[stripDelimiters(name)];
|
|
298
|
+
if (fuzzy && toolRegistry[fuzzy]) return fuzzy;
|
|
299
|
+
return normalized;
|
|
300
|
+
}
|
|
301
|
+
|
|
167
302
|
/** Resolve a name the model produced to a runnable tool, following aliases. */
|
|
168
303
|
export function resolveTool(name) {
|
|
169
|
-
const
|
|
170
|
-
const native = toolRegistry[
|
|
304
|
+
const canonical = canonicalToolName(name);
|
|
305
|
+
const native = toolRegistry[canonical] || null;
|
|
171
306
|
if (native) return native;
|
|
172
307
|
// MCP tools are namespaced `mcp__server__tool`, so they can never shadow a
|
|
173
308
|
// native name — the native lookup always wins above.
|
|
174
309
|
if (isMcpToolName(name)) return resolveMcpTool(name);
|
|
175
|
-
if (
|
|
310
|
+
if (canonical.startsWith('plugin__')) return resolvePluginTool(canonical);
|
|
176
311
|
return null;
|
|
177
312
|
}
|
|
178
313
|
|
|
179
|
-
/** The canonical catalogue name for anything the model might call it. */
|
|
180
|
-
export function canonicalToolName(name) {
|
|
181
|
-
const normalized = normalizeToolName(name);
|
|
182
|
-
if (toolRegistry[normalized]) return normalized;
|
|
183
|
-
return TOOL_ALIASES[normalized] || normalized;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
314
|
// Phase 6 AGI Upgrade & V5 Cortex: Dynamic Tool Culling and Hot-Reloading Engine
|
|
187
315
|
//
|
|
188
316
|
// options.unlockedPacks / options.unlockedTools drive Sovereign Progressive
|