@causyne/agent 1.20.111 → 1.20.116
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/ARCHITECTURE.md +29 -0
- package/package.json +1 -1
- package/src/agentLoop.js +72 -37
- package/src/agentLoop.ts +70 -38
- package/src/browser/browserRuntime.js +13 -8
- package/src/browser/browserRuntime.ts +16 -8
- package/src/browser/causyneBrowser.js +7 -2
- package/src/browser/causyneBrowser.ts +8 -2
- package/src/browser/searchProviders.js +18 -7
- package/src/browser/searchProviders.ts +17 -5
- package/src/browser/snapshotWindow.js +1 -1
- package/src/browser/snapshotWindow.ts +1 -1
- package/src/browser/urlPolicy.js +21 -10
- package/src/browser/urlPolicy.ts +19 -10
- package/src/browser/workspacePreview.js +13 -1
- package/src/browser/workspacePreview.ts +11 -1
- package/src/computerUse/visionGrounding.js +31 -27
- package/src/computerUse/visionGrounding.ts +27 -27
- package/src/continuum/ui/continuumPicker.js +14 -6
- package/src/continuum/ui/continuumPicker.ts +13 -6
- package/src/continuum/ui/continuumPickerView.js +24 -15
- package/src/continuum/ui/continuumPickerView.ts +24 -16
- package/src/observer/advisory.js +32 -22
- package/src/observer/advisory.ts +30 -18
- package/src/observer/coldObserver.js +21 -33
- package/src/observer/coldObserver.ts +20 -33
- package/src/observer/evidence.js +20 -13
- package/src/observer/evidence.ts +21 -13
- package/src/observer.js +47 -12
- package/src/observer.ts +50 -18
- package/src/pluginsFactory/discovery.js +28 -16
- package/src/pluginsFactory/discovery.ts +29 -16
- package/src/pluginsFactory/pluginsFactory.js +213 -38
- package/src/pluginsFactory/pluginsFactory.ts +218 -39
- package/src/pluginsFactory/strategy.js +26 -16
- package/src/pluginsFactory/strategy.ts +34 -19
- package/src/pluginsFactory/templates.js +183 -62
- package/src/pluginsFactory/templates.ts +174 -54
- package/src/timeMachine.js +43 -22
- package/src/timeMachine.ts +44 -22
- package/src/tool-scripts/desktop_act.applescript +1 -0
- package/src/tools/computerUse.js +23 -10
- package/src/tools/computerUse.ts +19 -8
- package/src/tools/desktopAct.js +12 -1
- package/src/tools/pluginsFactory.js +108 -5
- package/src/tools/pluginsFactory.ts +115 -5
- package/src/tui/CausyneRotor.js +24 -10
- package/src/tui/CausyneRotor.ts +25 -10
- package/src/tui/activityLayout.js +9 -5
- package/src/tui/activityLayout.ts +9 -5
- package/src/tui/ask.js +34 -14
- package/src/tui/banner.js +55 -18
- package/src/tui/banner.ts +52 -17
- package/src/tui/block.js +47 -20
- package/src/tui/block.ts +54 -27
- package/src/tui/chatRenderer.js +135 -83
- package/src/tui/chatboxClipboard.js +12 -5
- package/src/tui/chatboxClipboard.ts +10 -4
- package/src/tui/clipboardImage.js +52 -42
- package/src/tui/clipboardImage.ts +50 -39
- package/src/tui/clipboardSync.js +12 -1
- package/src/tui/clipboardSync.ts +9 -1
- package/src/tui/codeProgress.js +57 -26
- package/src/tui/codeProgress.ts +57 -25
- package/src/tui/codeStreamRenderer.js +59 -14
- package/src/tui/codeStreamRenderer.ts +58 -14
- package/src/tui/commandPresentation.js +9 -2
- package/src/tui/commandPresentation.ts +9 -2
- package/src/tui/completion.js +45 -23
- package/src/tui/composerControls.js +21 -10
- package/src/tui/composerControls.ts +18 -10
- package/src/tui/composerGeometry.js +6 -4
- package/src/tui/composerGeometry.ts +6 -4
- package/src/tui/consoleGuard.js +29 -7
- package/src/tui/consoleGuard.ts +28 -7
- package/src/tui/dialogs.js +134 -71
- package/src/tui/diff.js +8 -4
- package/src/tui/history.js +6 -5
- package/src/tui/home.js +25 -13
- package/src/tui/homeView.js +37 -18
- package/src/tui/homeView.ts +38 -18
- package/src/tui/inlineSlash.js +6 -5
- package/src/tui/inlineSlash.ts +6 -5
- package/src/tui/keys.js +33 -17
- package/src/tui/layout.js +27 -9
- package/src/tui/layout.ts +26 -9
- package/src/tui/lineEditor.js +49 -23
- package/src/tui/markdownMath.js +64 -14
- package/src/tui/markdownMath.ts +69 -13
- package/src/tui/messageActionPlacement.js +28 -13
- package/src/tui/messageActionPlacement.ts +28 -13
- package/src/tui/messageInteraction.js +111 -46
- package/src/tui/messageInteraction.ts +115 -47
- package/src/tui/modelPicker.js +44 -15
- package/src/tui/modelPicker.ts +48 -15
- package/src/tui/observerPicker.js +56 -13
- package/src/tui/observerPicker.ts +73 -30
- package/src/tui/overlay.js +79 -35
- package/src/tui/overlay.ts +81 -34
- package/src/tui/prompt.js +162 -94
- package/src/tui/runningLight.js +1 -1
- package/src/tui/runningLight.ts +1 -1
- package/src/tui/scrollInteraction.js +64 -36
- package/src/tui/scrollInteraction.ts +70 -37
- package/src/tui/selectList.js +60 -32
- package/src/tui/sessionLayout.js +11 -3
- package/src/tui/sessionLayout.ts +10 -3
- package/src/tui/sessionPicker.js +74 -46
- package/src/tui/sessionPicker.ts +73 -48
- package/src/tui/sessionPickerView.js +32 -19
- package/src/tui/sessionPickerView.ts +31 -18
- package/src/tui/sessionSidebar.js +87 -57
- package/src/tui/sessionSidebar.ts +90 -54
- package/src/tui/setup.js +28 -3
- package/src/tui/setup.ts +27 -3
- package/src/tui/skillAuthoring.js +11 -5
- package/src/tui/skillAuthoring.ts +11 -5
- package/src/tui/smartLinkClick.js +75 -23
- package/src/tui/smartLinkClick.ts +86 -26
- package/src/tui/stage.js +47 -16
- package/src/tui/stage.ts +53 -18
- package/src/tui/stageSurface.js +120 -49
- package/src/tui/statusLine.js +85 -53
- package/src/tui/statusLine.ts +82 -46
- package/src/tui/terminalInputFramer.js +5 -2
- package/src/tui/text.js +117 -46
- package/src/tui/text.ts +113 -43
- package/src/tui/textLayout.js +6 -4
- package/src/tui/textLayout.ts +11 -5
- package/src/tui/theme.js +17 -8
- package/src/tui/thinkingBox.js +95 -95
- package/src/tui/thinkingBox.ts +105 -80
- package/src/tui/toolActivityPolicy.js +8 -1
- package/src/tui/toolActivityPolicy.ts +7 -1
- package/src/tui/toolDisplay.js +15 -6
- package/src/tui/toolDisplay.ts +16 -6
- package/src/tui/toolOutputNormalizer.js +16 -3
- package/src/tui/toolOutputNormalizer.ts +13 -3
- package/src/tui/transcript.js +15 -9
- package/src/tui/turnRail.js +156 -67
- package/src/tui/turnRail.ts +155 -58
- package/src/tui/usageCard.js +80 -45
- package/src/tui/usageCard.ts +81 -46
- package/src/tui/viewport.js +48 -23
- package/src/tui/viewport.ts +48 -27
- package/src/tui/viewportAnchor.js +2 -2
- package/src/tui/viewportAnchor.ts +2 -2
- package/src/tui/workspaceFileIndex.js +8 -6
- package/src/tui/workspaceFileIndex.ts +8 -6
- package/src/tui/workspaceSwitch.js +13 -10
- package/src/tui/workspaceSwitch.ts +11 -7
package/src/observer.js
CHANGED
|
@@ -3,22 +3,51 @@ import path from 'node:path';
|
|
|
3
3
|
import http from 'node:http';
|
|
4
4
|
import { createHash } from 'node:crypto';
|
|
5
5
|
import { coldObserver } from './observer/coldObserver.js';
|
|
6
|
+
import { isVerificationCommand } from './observer/evidence.js';
|
|
6
7
|
export function extractClaimedLocalUrls(text) {
|
|
7
8
|
if (!text)
|
|
8
9
|
return [];
|
|
9
|
-
const matches = text.match(/https?:\/\/
|
|
10
|
+
const matches = text.match(/https?:\/\/[^\s)>'"`]+/gi) || [];
|
|
10
11
|
const unique = new Set();
|
|
11
12
|
for (const raw of matches) {
|
|
12
13
|
let end = raw.length;
|
|
13
|
-
while (end > 0
|
|
14
|
-
end
|
|
14
|
+
while (end > 0) {
|
|
15
|
+
const ch = raw[end - 1];
|
|
16
|
+
if ('.,;:!?'.includes(ch)) {
|
|
17
|
+
end--;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (ch === ']') {
|
|
21
|
+
const prefix = raw.slice(0, end);
|
|
22
|
+
const opens = prefix.split('[').length - 1;
|
|
23
|
+
const closes = prefix.split(']').length - 1;
|
|
24
|
+
if (closes > opens) {
|
|
25
|
+
end--;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
break;
|
|
15
30
|
}
|
|
16
31
|
const cleaned = raw.slice(0, end);
|
|
17
|
-
if (cleaned)
|
|
32
|
+
if (!cleaned)
|
|
33
|
+
continue;
|
|
34
|
+
try {
|
|
35
|
+
const url = new URL(cleaned);
|
|
36
|
+
if (!['localhost', '127.0.0.1', '[::1]'].includes(url.hostname) || url.username || url.password)
|
|
37
|
+
continue;
|
|
18
38
|
unique.add(cleaned);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// Ignore malformed and lookalike URLs rather than verifying a false localhost claim.
|
|
42
|
+
}
|
|
19
43
|
}
|
|
20
44
|
return [...unique];
|
|
21
45
|
}
|
|
46
|
+
const FILE_MUTATION_TOOLS = new Set([
|
|
47
|
+
'fs_write', 'fs_edit', 'MultiEdit', 'fs_delete', 'fs_move',
|
|
48
|
+
'write_file', 'write_to_file', 'edit_file', 'replace_file_content',
|
|
49
|
+
'multi_replace_file_content', 'write', 'edit', 'multiedit'
|
|
50
|
+
]);
|
|
22
51
|
function isWorkspaceArtifact(workspaceRoot, targetPath) {
|
|
23
52
|
try {
|
|
24
53
|
const root = fs.realpathSync(workspaceRoot);
|
|
@@ -95,17 +124,20 @@ export class CausyneObserver {
|
|
|
95
124
|
const claimsCompletion = /\b(?:done|complete|completed|finished|implemented|fixed|verified)\b|\b(?:is\s+(?:running|live|available|listening|served)\s+(?:at|on)|application\s+is\s+running)\b/i.test(claim);
|
|
96
125
|
if (claimsCompletion) {
|
|
97
126
|
// Run deterministic verification checks based on domain
|
|
98
|
-
const
|
|
99
|
-
const
|
|
127
|
+
const lastMutationIndex = outcomes.findLastIndex(o => FILE_MUTATION_TOOLS.has(o.tool));
|
|
128
|
+
const hasMutations = lastMutationIndex >= 0;
|
|
129
|
+
const verifications = outcomes.slice(lastMutationIndex + 1).filter(o => o.rendered === true ||
|
|
100
130
|
o.tool === 'verify_local_web' ||
|
|
101
|
-
(o.command &&
|
|
102
|
-
|
|
131
|
+
Boolean(o.command && isVerificationCommand(o.command)));
|
|
132
|
+
const lastVerif = verifications[verifications.length - 1];
|
|
133
|
+
const hasPassingVerification = Boolean(lastVerif && lastVerif.success && (lastVerif.exitCode == null || lastVerif.exitCode === 0));
|
|
134
|
+
if (!hasPassingVerification) {
|
|
103
135
|
return {
|
|
104
|
-
status: 'ready-to-verify',
|
|
136
|
+
status: hasMutations ? 'ready-to-verify' : 'progressing',
|
|
105
137
|
evidenceRefs,
|
|
106
138
|
verified: false,
|
|
107
139
|
confidence: 0.6,
|
|
108
|
-
message: 'Mutations performed but automated test/build verification has not yet run.',
|
|
140
|
+
message: hasMutations ? 'Mutations performed but automated test/build verification has not yet run.' : 'Completion claimed without supporting verification evidence.',
|
|
109
141
|
nextAction: 'Run targeted verification tests or build checks to confirm completion.'
|
|
110
142
|
};
|
|
111
143
|
}
|
|
@@ -209,7 +241,7 @@ export class CausyneObserver {
|
|
|
209
241
|
try {
|
|
210
242
|
const url = new URL(req.endpoint);
|
|
211
243
|
// Security gate: only loopback is permitted for local verification
|
|
212
|
-
if (!['localhost', '127.0.0.1', '::1'].includes(url.hostname)) {
|
|
244
|
+
if (!['localhost', '127.0.0.1', '[::1]'].includes(url.hostname)) {
|
|
213
245
|
resolve({ verified: false, error: 'Only local loopback endpoints (127.0.0.1, localhost) may be verified.' });
|
|
214
246
|
return;
|
|
215
247
|
}
|
|
@@ -217,7 +249,10 @@ export class CausyneObserver {
|
|
|
217
249
|
resolve({ verified: false, error: 'Local verification URL must not contain credentials.' });
|
|
218
250
|
return;
|
|
219
251
|
}
|
|
220
|
-
const
|
|
252
|
+
const safeTimeoutMs = typeof req.timeoutMs === 'number' && Number.isFinite(req.timeoutMs) && req.timeoutMs > 0
|
|
253
|
+
? Math.max(100, Math.min(30_000, Math.floor(req.timeoutMs)))
|
|
254
|
+
: 3000;
|
|
255
|
+
const clientReq = http.get(req.endpoint, { timeout: safeTimeoutMs }, (res) => {
|
|
221
256
|
res.resume();
|
|
222
257
|
const expected = req.expectedStatus ?? 200;
|
|
223
258
|
const ok = req.expectedStatus === undefined
|
package/src/observer.ts
CHANGED
|
@@ -3,7 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import http from 'node:http';
|
|
4
4
|
import { createHash } from 'node:crypto';
|
|
5
5
|
import { coldObserver } from './observer/coldObserver.js';
|
|
6
|
-
import type
|
|
6
|
+
import { isVerificationCommand, type ToolOutcome } from './observer/evidence.js';
|
|
7
7
|
|
|
8
8
|
export type ObservationStatus =
|
|
9
9
|
| 'progressing'
|
|
@@ -63,19 +63,46 @@ export interface TaskObservationContext {
|
|
|
63
63
|
|
|
64
64
|
export function extractClaimedLocalUrls(text: string): string[] {
|
|
65
65
|
if (!text) return [];
|
|
66
|
-
const matches = text.match(/https?:\/\/
|
|
66
|
+
const matches = text.match(/https?:\/\/[^\s)>'"`]+/gi) || [];
|
|
67
67
|
const unique = new Set<string>();
|
|
68
68
|
for (const raw of matches) {
|
|
69
69
|
let end = raw.length;
|
|
70
|
-
while (end > 0
|
|
71
|
-
end
|
|
70
|
+
while (end > 0) {
|
|
71
|
+
const ch = raw[end - 1]!;
|
|
72
|
+
if ('.,;:!?'.includes(ch)) {
|
|
73
|
+
end--;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (ch === ']') {
|
|
77
|
+
const prefix = raw.slice(0, end);
|
|
78
|
+
const opens = prefix.split('[').length - 1;
|
|
79
|
+
const closes = prefix.split(']').length - 1;
|
|
80
|
+
if (closes > opens) {
|
|
81
|
+
end--;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
72
86
|
}
|
|
73
87
|
const cleaned = raw.slice(0, end);
|
|
74
|
-
if (cleaned)
|
|
88
|
+
if (!cleaned) continue;
|
|
89
|
+
try {
|
|
90
|
+
const url = new URL(cleaned);
|
|
91
|
+
if (!['localhost', '127.0.0.1', '[::1]'].includes(url.hostname) || url.username || url.password) continue;
|
|
92
|
+
unique.add(cleaned);
|
|
93
|
+
} catch {
|
|
94
|
+
// Ignore malformed and lookalike URLs rather than verifying a false localhost claim.
|
|
95
|
+
}
|
|
75
96
|
}
|
|
76
97
|
return [...unique];
|
|
77
98
|
}
|
|
78
99
|
|
|
100
|
+
const FILE_MUTATION_TOOLS = new Set([
|
|
101
|
+
'fs_write', 'fs_edit', 'MultiEdit', 'fs_delete', 'fs_move',
|
|
102
|
+
'write_file', 'write_to_file', 'edit_file', 'replace_file_content',
|
|
103
|
+
'multi_replace_file_content', 'write', 'edit', 'multiedit'
|
|
104
|
+
]);
|
|
105
|
+
|
|
79
106
|
function isWorkspaceArtifact(workspaceRoot: string, targetPath: string): boolean {
|
|
80
107
|
try {
|
|
81
108
|
const root = fs.realpathSync(workspaceRoot);
|
|
@@ -158,24 +185,25 @@ export class CausyneObserver {
|
|
|
158
185
|
|
|
159
186
|
if (claimsCompletion) {
|
|
160
187
|
// Run deterministic verification checks based on domain
|
|
161
|
-
const
|
|
162
|
-
|
|
188
|
+
const lastMutationIndex = outcomes.findLastIndex(o => FILE_MUTATION_TOOLS.has(o.tool));
|
|
189
|
+
const hasMutations = lastMutationIndex >= 0;
|
|
190
|
+
const verifications = outcomes.slice(lastMutationIndex + 1).filter(o =>
|
|
191
|
+
o.rendered === true ||
|
|
192
|
+
o.tool === 'verify_local_web' ||
|
|
193
|
+
Boolean(o.command && isVerificationCommand(o.command))
|
|
163
194
|
);
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
o.tool === 'verify_local_web' ||
|
|
168
|
-
(o.command && /\b(?:test|build|check|typecheck|vitest|jest|pytest)\b/i.test(o.command))
|
|
169
|
-
)
|
|
195
|
+
const lastVerif = verifications[verifications.length - 1];
|
|
196
|
+
const hasPassingVerification = Boolean(
|
|
197
|
+
lastVerif && lastVerif.success && (lastVerif.exitCode == null || lastVerif.exitCode === 0)
|
|
170
198
|
);
|
|
171
199
|
|
|
172
|
-
if (
|
|
200
|
+
if (!hasPassingVerification) {
|
|
173
201
|
return {
|
|
174
|
-
status: 'ready-to-verify',
|
|
202
|
+
status: hasMutations ? 'ready-to-verify' : 'progressing',
|
|
175
203
|
evidenceRefs,
|
|
176
204
|
verified: false,
|
|
177
205
|
confidence: 0.6,
|
|
178
|
-
message: 'Mutations performed but automated test/build verification has not yet run.',
|
|
206
|
+
message: hasMutations ? 'Mutations performed but automated test/build verification has not yet run.' : 'Completion claimed without supporting verification evidence.',
|
|
179
207
|
nextAction: 'Run targeted verification tests or build checks to confirm completion.'
|
|
180
208
|
};
|
|
181
209
|
}
|
|
@@ -285,7 +313,7 @@ export class CausyneObserver {
|
|
|
285
313
|
try {
|
|
286
314
|
const url = new URL(req.endpoint);
|
|
287
315
|
// Security gate: only loopback is permitted for local verification
|
|
288
|
-
if (!['localhost', '127.0.0.1', '::1'].includes(url.hostname)) {
|
|
316
|
+
if (!['localhost', '127.0.0.1', '[::1]'].includes(url.hostname)) {
|
|
289
317
|
resolve({ verified: false, error: 'Only local loopback endpoints (127.0.0.1, localhost) may be verified.' });
|
|
290
318
|
return;
|
|
291
319
|
}
|
|
@@ -295,7 +323,11 @@ export class CausyneObserver {
|
|
|
295
323
|
return;
|
|
296
324
|
}
|
|
297
325
|
|
|
298
|
-
const
|
|
326
|
+
const safeTimeoutMs =
|
|
327
|
+
typeof req.timeoutMs === 'number' && Number.isFinite(req.timeoutMs) && req.timeoutMs > 0
|
|
328
|
+
? Math.max(100, Math.min(30_000, Math.floor(req.timeoutMs)))
|
|
329
|
+
: 3000;
|
|
330
|
+
const clientReq = http.get(req.endpoint, { timeout: safeTimeoutMs }, (res) => {
|
|
299
331
|
res.resume();
|
|
300
332
|
const expected = req.expectedStatus ?? 200;
|
|
301
333
|
const ok = req.expectedStatus === undefined
|
|
@@ -14,28 +14,43 @@ import { listPlugins } from '../plugins/pluginManager.js';
|
|
|
14
14
|
const NATIVE_TOOLS_CATALOG = [
|
|
15
15
|
{ name: 'fs_read', description: 'Read file contents from the workspace', aliases: ['read_file', 'cat', 'open_file'] },
|
|
16
16
|
{ name: 'fs_write', description: 'Write or append file contents in the workspace', aliases: ['write_file', 'save_file'] },
|
|
17
|
-
{ name: '
|
|
17
|
+
{ name: 'sysRun', description: 'Execute shell commands with safety checks', aliases: ['run_command', 'shell', 'exec', 'bash'] },
|
|
18
18
|
{ name: 'web_search', description: 'Perform web search queries', aliases: ['search', 'google_search', 'web_query'] },
|
|
19
19
|
{ name: 'web_fetch', description: 'Fetch and extract clean markdown from web pages', aliases: ['curl', 'http_get', 'scrape'] },
|
|
20
|
-
{ name: '
|
|
21
|
-
{ name: '
|
|
22
|
-
{ name: '
|
|
23
|
-
{ name: '
|
|
20
|
+
{ name: 'browser_act', description: 'Autonomous browser control for web apps and QA', aliases: ['playwright', 'puppeteer', 'chrome'] },
|
|
21
|
+
{ name: 'vision_inspect_ui', description: 'Inspect images and visual assets with OCR/layout', aliases: ['ocr', 'image_inspect'] },
|
|
22
|
+
{ name: 'resolve_act', description: 'DaVinci Resolve automation and studio workflows', aliases: ['resolve', 'davinci', 'video_edit'] },
|
|
23
|
+
{ name: 'blender_act', description: 'Blender 3D scene rendering and automation', aliases: ['blender', '3d_render', 'cycles'] },
|
|
24
24
|
{ name: 'archive', description: 'Extract, inspect, or build archive files (zip/tar)', aliases: ['unzip', 'tar', 'extract'] },
|
|
25
|
-
{ name: '
|
|
26
|
-
{ name: 'database_query', description: 'Execute structured queries on SQLite/PostgreSQL/MySQL', aliases: ['sql', 'query_db'] }
|
|
25
|
+
{ name: 'pdf_read', description: 'Extract structured text and tables from PDF documents', aliases: ['read_pdf', 'extract_pdf'] }
|
|
27
26
|
];
|
|
27
|
+
/**
|
|
28
|
+
* Normalizes a name for token comparison. Hyphens and underscores become
|
|
29
|
+
* spaces so "web_search" and "web search" compare identically.
|
|
30
|
+
*/
|
|
31
|
+
function normalizeTerm(value) {
|
|
32
|
+
return value.toLowerCase().trim().replace(/[-_]+/g, ' ');
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Matches whole terms only. Substring matching made "research" match
|
|
36
|
+
* "search" and "sqlite" match a phantom SQL tool.
|
|
37
|
+
*/
|
|
38
|
+
function matchesTerm(normalizedQuery, candidate) {
|
|
39
|
+
const term = normalizeTerm(candidate);
|
|
40
|
+
if (!term)
|
|
41
|
+
return false;
|
|
42
|
+
return normalizedQuery === term || ` ${normalizedQuery} `.includes(` ${term} `);
|
|
43
|
+
}
|
|
28
44
|
/**
|
|
29
45
|
* Searches for existing capabilities matching a service or tool query.
|
|
30
46
|
*/
|
|
31
47
|
export function findExistingCapability(query) {
|
|
32
|
-
const normalized = query
|
|
48
|
+
const normalized = normalizeTerm(query);
|
|
33
49
|
if (!normalized)
|
|
34
50
|
return { covered: false };
|
|
35
51
|
// 1. Check Native Built-in Tools
|
|
36
52
|
for (const tool of NATIVE_TOOLS_CATALOG) {
|
|
37
|
-
|
|
38
|
-
if (toolNameNorm === normalized || tool.aliases.some(alias => alias === normalized || normalized.includes(alias))) {
|
|
53
|
+
if (matchesTerm(normalized, tool.name) || tool.aliases.some(alias => matchesTerm(normalized, alias))) {
|
|
39
54
|
return {
|
|
40
55
|
covered: true,
|
|
41
56
|
source: 'native_tool',
|
|
@@ -48,8 +63,7 @@ export function findExistingCapability(query) {
|
|
|
48
63
|
try {
|
|
49
64
|
const plugins = listPlugins();
|
|
50
65
|
for (const plugin of plugins) {
|
|
51
|
-
|
|
52
|
-
if (pluginNameNorm === normalized || normalized.includes(pluginNameNorm)) {
|
|
66
|
+
if (matchesTerm(normalized, plugin.name)) {
|
|
53
67
|
return {
|
|
54
68
|
covered: true,
|
|
55
69
|
source: 'plugin',
|
|
@@ -59,8 +73,7 @@ export function findExistingCapability(query) {
|
|
|
59
73
|
}
|
|
60
74
|
if (Array.isArray(plugin.tools)) {
|
|
61
75
|
for (const t of plugin.tools) {
|
|
62
|
-
|
|
63
|
-
if (tNorm === normalized || normalized.includes(tNorm)) {
|
|
76
|
+
if (matchesTerm(normalized, t)) {
|
|
64
77
|
return {
|
|
65
78
|
covered: true,
|
|
66
79
|
source: 'plugin',
|
|
@@ -79,8 +92,7 @@ export function findExistingCapability(query) {
|
|
|
79
92
|
try {
|
|
80
93
|
const servers = configuredServers();
|
|
81
94
|
for (const s of servers) {
|
|
82
|
-
|
|
83
|
-
if (sNameNorm === normalized || normalized.includes(sNameNorm)) {
|
|
95
|
+
if (matchesTerm(normalized, s.name)) {
|
|
84
96
|
return {
|
|
85
97
|
covered: true,
|
|
86
98
|
source: 'mcp',
|
|
@@ -23,29 +23,45 @@ export interface ExistingCapabilityMatch {
|
|
|
23
23
|
const NATIVE_TOOLS_CATALOG: Array<{ name: string; description: string; aliases: string[] }> = [
|
|
24
24
|
{ name: 'fs_read', description: 'Read file contents from the workspace', aliases: ['read_file', 'cat', 'open_file'] },
|
|
25
25
|
{ name: 'fs_write', description: 'Write or append file contents in the workspace', aliases: ['write_file', 'save_file'] },
|
|
26
|
-
{ name: '
|
|
26
|
+
{ name: 'sysRun', description: 'Execute shell commands with safety checks', aliases: ['run_command', 'shell', 'exec', 'bash'] },
|
|
27
27
|
{ name: 'web_search', description: 'Perform web search queries', aliases: ['search', 'google_search', 'web_query'] },
|
|
28
28
|
{ name: 'web_fetch', description: 'Fetch and extract clean markdown from web pages', aliases: ['curl', 'http_get', 'scrape'] },
|
|
29
|
-
{ name: '
|
|
30
|
-
{ name: '
|
|
31
|
-
{ name: '
|
|
32
|
-
{ name: '
|
|
29
|
+
{ name: 'browser_act', description: 'Autonomous browser control for web apps and QA', aliases: ['playwright', 'puppeteer', 'chrome'] },
|
|
30
|
+
{ name: 'vision_inspect_ui', description: 'Inspect images and visual assets with OCR/layout', aliases: ['ocr', 'image_inspect'] },
|
|
31
|
+
{ name: 'resolve_act', description: 'DaVinci Resolve automation and studio workflows', aliases: ['resolve', 'davinci', 'video_edit'] },
|
|
32
|
+
{ name: 'blender_act', description: 'Blender 3D scene rendering and automation', aliases: ['blender', '3d_render', 'cycles'] },
|
|
33
33
|
{ name: 'archive', description: 'Extract, inspect, or build archive files (zip/tar)', aliases: ['unzip', 'tar', 'extract'] },
|
|
34
|
-
{ name: '
|
|
35
|
-
{ name: 'database_query', description: 'Execute structured queries on SQLite/PostgreSQL/MySQL', aliases: ['sql', 'query_db'] }
|
|
34
|
+
{ name: 'pdf_read', description: 'Extract structured text and tables from PDF documents', aliases: ['read_pdf', 'extract_pdf'] }
|
|
36
35
|
];
|
|
37
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Normalizes a name for token comparison. Hyphens and underscores become
|
|
39
|
+
* spaces so "web_search" and "web search" compare identically.
|
|
40
|
+
*/
|
|
41
|
+
function normalizeTerm(value: string): string {
|
|
42
|
+
return value.toLowerCase().trim().replace(/[-_]+/g, ' ');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Matches whole terms only. Substring matching made "research" match
|
|
47
|
+
* "search" and "sqlite" match a phantom SQL tool.
|
|
48
|
+
*/
|
|
49
|
+
function matchesTerm(normalizedQuery: string, candidate: string): boolean {
|
|
50
|
+
const term = normalizeTerm(candidate);
|
|
51
|
+
if (!term) return false;
|
|
52
|
+
return normalizedQuery === term || ` ${normalizedQuery} `.includes(` ${term} `);
|
|
53
|
+
}
|
|
54
|
+
|
|
38
55
|
/**
|
|
39
56
|
* Searches for existing capabilities matching a service or tool query.
|
|
40
57
|
*/
|
|
41
58
|
export function findExistingCapability(query: string): ExistingCapabilityMatch {
|
|
42
|
-
const normalized = query
|
|
59
|
+
const normalized = normalizeTerm(query);
|
|
43
60
|
if (!normalized) return { covered: false };
|
|
44
61
|
|
|
45
62
|
// 1. Check Native Built-in Tools
|
|
46
63
|
for (const tool of NATIVE_TOOLS_CATALOG) {
|
|
47
|
-
|
|
48
|
-
if (toolNameNorm === normalized || tool.aliases.some(alias => alias === normalized || normalized.includes(alias))) {
|
|
64
|
+
if (matchesTerm(normalized, tool.name) || tool.aliases.some(alias => matchesTerm(normalized, alias))) {
|
|
49
65
|
return {
|
|
50
66
|
covered: true,
|
|
51
67
|
source: 'native_tool',
|
|
@@ -65,8 +81,7 @@ export function findExistingCapability(query: string): ExistingCapabilityMatch {
|
|
|
65
81
|
}>;
|
|
66
82
|
|
|
67
83
|
for (const plugin of plugins) {
|
|
68
|
-
|
|
69
|
-
if (pluginNameNorm === normalized || normalized.includes(pluginNameNorm)) {
|
|
84
|
+
if (matchesTerm(normalized, plugin.name)) {
|
|
70
85
|
return {
|
|
71
86
|
covered: true,
|
|
72
87
|
source: 'plugin',
|
|
@@ -76,8 +91,7 @@ export function findExistingCapability(query: string): ExistingCapabilityMatch {
|
|
|
76
91
|
}
|
|
77
92
|
if (Array.isArray(plugin.tools)) {
|
|
78
93
|
for (const t of plugin.tools) {
|
|
79
|
-
|
|
80
|
-
if (tNorm === normalized || normalized.includes(tNorm)) {
|
|
94
|
+
if (matchesTerm(normalized, t)) {
|
|
81
95
|
return {
|
|
82
96
|
covered: true,
|
|
83
97
|
source: 'plugin',
|
|
@@ -96,8 +110,7 @@ export function findExistingCapability(query: string): ExistingCapabilityMatch {
|
|
|
96
110
|
try {
|
|
97
111
|
const servers = configuredServers();
|
|
98
112
|
for (const s of servers) {
|
|
99
|
-
|
|
100
|
-
if (sNameNorm === normalized || normalized.includes(sNameNorm)) {
|
|
113
|
+
if (matchesTerm(normalized, s.name)) {
|
|
101
114
|
return {
|
|
102
115
|
covered: true,
|
|
103
116
|
source: 'mcp',
|