@causyne/agent 1.20.112 → 1.20.117

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.
Files changed (169) hide show
  1. package/docs/ARCHITECTURE.md +29 -0
  2. package/package.json +1 -1
  3. package/src/agentLoop.js +153 -68
  4. package/src/agentLoop.ts +152 -71
  5. package/src/browser/browserRuntime.js +13 -8
  6. package/src/browser/browserRuntime.ts +16 -8
  7. package/src/browser/causyneBrowser.js +37 -9
  8. package/src/browser/causyneBrowser.ts +37 -9
  9. package/src/browser/searchProviders.js +18 -7
  10. package/src/browser/searchProviders.ts +17 -5
  11. package/src/browser/snapshotWindow.js +1 -1
  12. package/src/browser/snapshotWindow.ts +1 -1
  13. package/src/browser/urlPolicy.js +21 -10
  14. package/src/browser/urlPolicy.ts +19 -10
  15. package/src/browser/workspacePreview.js +13 -1
  16. package/src/browser/workspacePreview.ts +11 -1
  17. package/src/cliMode.js +5 -1
  18. package/src/computerUse/visionGrounding.js +31 -27
  19. package/src/computerUse/visionGrounding.ts +27 -27
  20. package/src/continuum/ui/continuumPicker.js +14 -6
  21. package/src/continuum/ui/continuumPicker.ts +13 -6
  22. package/src/continuum/ui/continuumPickerView.js +24 -15
  23. package/src/continuum/ui/continuumPickerView.ts +24 -16
  24. package/src/memory/scopedFacts.js +171 -0
  25. package/src/memory/scopedFacts.ts +214 -0
  26. package/src/memory.d.ts +13 -1
  27. package/src/memory.js +9 -12
  28. package/src/observer/advisory.js +32 -22
  29. package/src/observer/advisory.ts +30 -18
  30. package/src/observer/coldObserver.js +21 -33
  31. package/src/observer/coldObserver.ts +20 -33
  32. package/src/observer/evidence.js +20 -13
  33. package/src/observer/evidence.ts +21 -13
  34. package/src/observer.js +47 -12
  35. package/src/observer.ts +50 -18
  36. package/src/perception.js +124 -3
  37. package/src/perception.ts +128 -4
  38. package/src/planCache.js +17 -3
  39. package/src/planCache.ts +17 -3
  40. package/src/pluginsFactory/discovery.js +28 -16
  41. package/src/pluginsFactory/discovery.ts +29 -16
  42. package/src/pluginsFactory/pluginsFactory.js +213 -38
  43. package/src/pluginsFactory/pluginsFactory.ts +218 -39
  44. package/src/pluginsFactory/strategy.js +26 -16
  45. package/src/pluginsFactory/strategy.ts +34 -19
  46. package/src/pluginsFactory/templates.js +183 -62
  47. package/src/pluginsFactory/templates.ts +174 -54
  48. package/src/smartToolsUse.js +4 -5
  49. package/src/smartToolsUse.ts +4 -6
  50. package/src/taskShape.js +49 -7
  51. package/src/taskShape.ts +55 -7
  52. package/src/timeMachine.js +43 -22
  53. package/src/timeMachine.ts +44 -22
  54. package/src/tool-scripts/desktop_act.applescript +1 -0
  55. package/src/toolPacks.js +27 -5
  56. package/src/toolPacks.ts +32 -5
  57. package/src/tools/computerUse.js +23 -10
  58. package/src/tools/computerUse.ts +19 -8
  59. package/src/tools/desktopAct.js +12 -1
  60. package/src/tools/memoryWrite.js +8 -10
  61. package/src/tools/memoryWrite.ts +13 -11
  62. package/src/tools/pluginsFactory.js +108 -5
  63. package/src/tools/pluginsFactory.ts +115 -5
  64. package/src/tui/CausyneRotor.js +24 -10
  65. package/src/tui/CausyneRotor.ts +25 -10
  66. package/src/tui/activityLayout.js +9 -5
  67. package/src/tui/activityLayout.ts +9 -5
  68. package/src/tui/ask.js +34 -14
  69. package/src/tui/banner.js +55 -18
  70. package/src/tui/banner.ts +52 -17
  71. package/src/tui/block.js +47 -20
  72. package/src/tui/block.ts +54 -27
  73. package/src/tui/chatRenderer.js +139 -84
  74. package/src/tui/chatboxClipboard.js +12 -5
  75. package/src/tui/chatboxClipboard.ts +10 -4
  76. package/src/tui/clipboardImage.js +52 -42
  77. package/src/tui/clipboardImage.ts +50 -39
  78. package/src/tui/clipboardSync.js +12 -1
  79. package/src/tui/clipboardSync.ts +9 -1
  80. package/src/tui/codeProgress.js +60 -28
  81. package/src/tui/codeProgress.ts +60 -27
  82. package/src/tui/codeStreamRenderer.js +94 -23
  83. package/src/tui/codeStreamRenderer.ts +92 -23
  84. package/src/tui/commandPresentation.js +9 -2
  85. package/src/tui/commandPresentation.ts +9 -2
  86. package/src/tui/completion.js +45 -23
  87. package/src/tui/composerControls.js +21 -10
  88. package/src/tui/composerControls.ts +18 -10
  89. package/src/tui/composerGeometry.js +6 -4
  90. package/src/tui/composerGeometry.ts +6 -4
  91. package/src/tui/consoleGuard.js +29 -7
  92. package/src/tui/consoleGuard.ts +28 -7
  93. package/src/tui/dialogs.js +134 -71
  94. package/src/tui/diff.js +8 -4
  95. package/src/tui/history.js +6 -5
  96. package/src/tui/home.js +25 -13
  97. package/src/tui/homeView.js +37 -18
  98. package/src/tui/homeView.ts +38 -18
  99. package/src/tui/inlineSlash.js +6 -5
  100. package/src/tui/inlineSlash.ts +6 -5
  101. package/src/tui/keys.js +36 -18
  102. package/src/tui/layout.js +27 -9
  103. package/src/tui/layout.ts +26 -9
  104. package/src/tui/lineEditor.js +49 -23
  105. package/src/tui/markdownMath.js +64 -14
  106. package/src/tui/markdownMath.ts +69 -13
  107. package/src/tui/messageActionPlacement.js +28 -13
  108. package/src/tui/messageActionPlacement.ts +28 -13
  109. package/src/tui/messageInteraction.js +111 -46
  110. package/src/tui/messageInteraction.ts +115 -47
  111. package/src/tui/modelPicker.js +44 -15
  112. package/src/tui/modelPicker.ts +48 -15
  113. package/src/tui/observerPicker.js +56 -13
  114. package/src/tui/observerPicker.ts +73 -30
  115. package/src/tui/overlay.js +79 -35
  116. package/src/tui/overlay.ts +81 -34
  117. package/src/tui/prompt.js +186 -94
  118. package/src/tui/runningLight.js +1 -1
  119. package/src/tui/runningLight.ts +1 -1
  120. package/src/tui/scrollInteraction.js +64 -36
  121. package/src/tui/scrollInteraction.ts +70 -37
  122. package/src/tui/selectList.js +60 -32
  123. package/src/tui/sessionLayout.js +11 -3
  124. package/src/tui/sessionLayout.ts +10 -3
  125. package/src/tui/sessionPicker.js +74 -46
  126. package/src/tui/sessionPicker.ts +73 -48
  127. package/src/tui/sessionPickerView.js +32 -19
  128. package/src/tui/sessionPickerView.ts +31 -18
  129. package/src/tui/sessionSidebar.js +87 -57
  130. package/src/tui/sessionSidebar.ts +90 -54
  131. package/src/tui/setup.js +28 -3
  132. package/src/tui/setup.ts +27 -3
  133. package/src/tui/skillAuthoring.js +11 -5
  134. package/src/tui/skillAuthoring.ts +11 -5
  135. package/src/tui/smartLinkClick.js +75 -23
  136. package/src/tui/smartLinkClick.ts +86 -26
  137. package/src/tui/stage.js +47 -16
  138. package/src/tui/stage.ts +53 -18
  139. package/src/tui/stageSurface.js +232 -51
  140. package/src/tui/statusLine.js +85 -53
  141. package/src/tui/statusLine.ts +82 -46
  142. package/src/tui/terminalInputFramer.js +5 -2
  143. package/src/tui/text.js +117 -46
  144. package/src/tui/text.ts +113 -43
  145. package/src/tui/textLayout.js +6 -4
  146. package/src/tui/textLayout.ts +11 -5
  147. package/src/tui/theme.js +17 -8
  148. package/src/tui/thinkingBox.js +95 -95
  149. package/src/tui/thinkingBox.ts +105 -80
  150. package/src/tui/toolActivityPolicy.js +8 -1
  151. package/src/tui/toolActivityPolicy.ts +7 -1
  152. package/src/tui/toolDisplay.js +15 -6
  153. package/src/tui/toolDisplay.ts +16 -6
  154. package/src/tui/toolOutputNormalizer.js +16 -3
  155. package/src/tui/toolOutputNormalizer.ts +13 -3
  156. package/src/tui/transcript.js +15 -9
  157. package/src/tui/turnRail.js +176 -80
  158. package/src/tui/turnRail.ts +173 -71
  159. package/src/tui/usageCard.js +136 -80
  160. package/src/tui/usageCard.ts +145 -103
  161. package/src/tui/viewport.js +48 -23
  162. package/src/tui/viewport.ts +48 -27
  163. package/src/tui/viewportAnchor.js +2 -2
  164. package/src/tui/viewportAnchor.ts +2 -2
  165. package/src/tui/workspaceFileIndex.js +8 -6
  166. package/src/tui/workspaceFileIndex.ts +8 -6
  167. package/src/tui/workspaceSwitch.js +13 -10
  168. package/src/tui/workspaceSwitch.ts +11 -7
  169. package/src/types/contracts.ts +3 -0
package/src/perception.ts CHANGED
@@ -44,6 +44,10 @@ export interface WorkspaceContextData {
44
44
  framework: FrameworkInfo | null;
45
45
  designSystem: string[] | null;
46
46
  subprojects: string[];
47
+ subprojectStacks?: string[];
48
+ docFiles?: string[];
49
+ buildFiles?: string[];
50
+ topEntries?: string[];
47
51
  keyFiles: string[];
48
52
  packageManager: string | null;
49
53
  gitBranch?: string;
@@ -82,11 +86,21 @@ export class WorkspacePerception {
82
86
  // 2b. Design system detection (Anti-Slop: tells the brain what's already installed)
83
87
  context.designSystem = await this.detectDesignContext(resolvedPath);
84
88
 
85
- // 2c. Subprojects detection (find subfolders like 'pixel2d games', 'causyne-agent', etc.)
89
+ // 2c. Subprojects & nested stacks discovery
86
90
  context.subprojects = await this.detectSubprojects(resolvedPath);
87
-
88
- // 2d. Key files discovery
89
- context.keyFiles = await this.detectKeyFiles(resolvedPath);
91
+ const repoArtifacts = await this.detectRepoArtifacts(resolvedPath, context.subprojects);
92
+ context.subprojectStacks = repoArtifacts.subprojectStacks;
93
+ context.docFiles = repoArtifacts.docFiles;
94
+ context.buildFiles = repoArtifacts.buildFiles;
95
+ context.topEntries = repoArtifacts.topEntries;
96
+
97
+ // 2d. Key files discovery (root entrypoints + key docs & build scripts)
98
+ const rootKeyFiles = await this.detectKeyFiles(resolvedPath);
99
+ context.keyFiles = [...new Set([
100
+ ...rootKeyFiles,
101
+ ...repoArtifacts.buildFiles.slice(0, 8),
102
+ ...repoArtifacts.docFiles.slice(0, 8)
103
+ ])];
90
104
 
91
105
  // 2e. Package manager detection
92
106
  context.packageManager = await this.detectPackageManager(resolvedPath);
@@ -266,6 +280,112 @@ export class WorkspacePerception {
266
280
  return subprojects;
267
281
  }
268
282
 
283
+ async detectRepoArtifacts(dir: string, subprojects: string[]): Promise<{
284
+ subprojectStacks: string[];
285
+ docFiles: string[];
286
+ buildFiles: string[];
287
+ topEntries: string[];
288
+ }> {
289
+ const subprojectStacks: string[] = [];
290
+ const docFiles: string[] = [];
291
+ const buildFiles: string[] = [];
292
+ const topEntries: string[] = [];
293
+
294
+ const existsFile = async (rel: string): Promise<boolean> => {
295
+ try {
296
+ const stat = await fs.stat(path.join(dir, rel));
297
+ return stat.isFile();
298
+ } catch {
299
+ return false;
300
+ }
301
+ };
302
+
303
+ try {
304
+ const entries = await fs.readdir(dir, { withFileTypes: true });
305
+ for (const entry of entries) {
306
+ if (entry.name.startsWith('.') || SKIP_DIRECTORIES.has(entry.name)) continue;
307
+ if (topEntries.length >= 25) break;
308
+ topEntries.push(entry.isDirectory() ? `${entry.name}/` : entry.name);
309
+ }
310
+ } catch {
311
+ // ignore
312
+ }
313
+
314
+ const rootDocs = ['AGENTS.md', 'CLAUDE.md', 'README.md', 'ARCHITECTURE.md', 'CONTRIBUTING.md', 'RELEASE.md', 'ANDROID_RELEASE.md', 'ENGINEERING.md'];
315
+ for (const rel of rootDocs) {
316
+ if (await existsFile(rel)) docFiles.push(rel);
317
+ }
318
+
319
+ const priorityDocScore = (name: string): number => {
320
+ const lower = name.toLowerCase();
321
+ if (/(?:release|android|build|architecture|engineering)/.test(lower)) return 0;
322
+ if (/(?:readme|agents|claude|work_log|qa|guide)/.test(lower)) return 1;
323
+ return 2;
324
+ };
325
+
326
+ for (const docDir of ['docs', 'doc']) {
327
+ try {
328
+ const docEntries = await fs.readdir(path.join(dir, docDir), { withFileTypes: true });
329
+ const mdFiles = docEntries
330
+ .filter(e => e.isFile() && /\.(?:md|txt)$/i.test(e.name) && !e.name.startsWith('.'))
331
+ .map(e => `${docDir}/${e.name}`)
332
+ .sort((a, b) => priorityDocScore(a) - priorityDocScore(b) || a.localeCompare(b));
333
+ for (const rel of mdFiles) {
334
+ if (docFiles.length >= 16) break;
335
+ if (!docFiles.includes(rel)) docFiles.push(rel);
336
+ }
337
+ } catch {
338
+ // ignore missing docs dir
339
+ }
340
+ }
341
+
342
+ const rootBuildCandidates = [
343
+ 'Makefile', 'CMakeLists.txt', 'package.json', 'tsconfig.json',
344
+ 'project.godot', 'export_presets.cfg', 'build.gradle', 'build.gradle.kts',
345
+ 'settings.gradle', 'settings.gradle.kts', 'Cargo.toml', 'pyproject.toml',
346
+ 'go.mod', 'pubspec.yaml', 'Dockerfile', 'docker-compose.yml', 'wrangler.toml'
347
+ ];
348
+ for (const rel of rootBuildCandidates) {
349
+ if (await existsFile(rel)) buildFiles.push(rel);
350
+ }
351
+
352
+ try {
353
+ const scriptEntries = await fs.readdir(path.join(dir, 'scripts'), { withFileTypes: true });
354
+ for (const entry of scriptEntries.sort((a, b) => a.name.localeCompare(b.name))) {
355
+ if (!entry.isFile() || entry.name.startsWith('.')) continue;
356
+ if (/\.(?:sh|bash|py|js|cjs|mjs|ts|ps1)$/i.test(entry.name)) {
357
+ const rel = `scripts/${entry.name}`;
358
+ if (!buildFiles.includes(rel) && buildFiles.length < 18) buildFiles.push(rel);
359
+ }
360
+ }
361
+ } catch {
362
+ // ignore missing scripts dir
363
+ }
364
+
365
+ const nestedCheckDirs = [...new Set([...subprojects, 'godot', 'android', 'app', 'mobile', 'desktop', 'server', 'backend', 'frontend', 'web'])];
366
+ for (const sub of nestedCheckDirs) {
367
+ if (sub.includes('..') || path.isAbsolute(sub)) continue;
368
+ const subBuildChecks: Array<{ rel: string; stack?: string }> = [
369
+ { rel: `${sub}/project.godot`, stack: `godot (gdscript) @ ${sub}/` },
370
+ { rel: `${sub}/export_presets.cfg` },
371
+ { rel: `${sub}/build.gradle.kts`, stack: `android (kotlin/gradle) @ ${sub}/` },
372
+ { rel: `${sub}/build.gradle`, stack: `android (gradle) @ ${sub}/` },
373
+ { rel: `${sub}/Cargo.toml`, stack: `rust @ ${sub}/` },
374
+ { rel: `${sub}/go.mod`, stack: `go @ ${sub}/` },
375
+ { rel: `${sub}/pyproject.toml`, stack: `python @ ${sub}/` },
376
+ { rel: `${sub}/package.json`, stack: `node @ ${sub}/` }
377
+ ];
378
+ for (const check of subBuildChecks) {
379
+ if (await existsFile(check.rel)) {
380
+ if (!buildFiles.includes(check.rel) && buildFiles.length < 22) buildFiles.push(check.rel);
381
+ if (check.stack && !subprojectStacks.includes(check.stack)) subprojectStacks.push(check.stack);
382
+ }
383
+ }
384
+ }
385
+
386
+ return { subprojectStacks, docFiles, buildFiles, topEntries };
387
+ }
388
+
269
389
  async detectKeyFiles(dir: string): Promise<string[]> {
270
390
  const candidateFiles = [
271
391
  'package.json', 'tsconfig.json', 'index.html', 'main.js',
@@ -358,6 +478,10 @@ export class WorkspacePerception {
358
478
  // ignore
359
479
  }
360
480
 
481
+ if (context.subprojectStacks?.some(s => s.startsWith('godot '))) {
482
+ return 'Godot Game Project';
483
+ }
484
+
361
485
  // Check directory name or key files for game patterns
362
486
  const baseName = path.basename(dir).toLowerCase();
363
487
  if (baseName.includes('game') || baseName.includes('pixel') || baseName.includes('arcade')) {
package/src/planCache.js CHANGED
@@ -81,6 +81,18 @@ const STOPWORDS = new Set([
81
81
  // deliberately NOT here: those DO separate tasks inside one archetype.
82
82
  'make', 'create', 'creating', 'made', 'generate'
83
83
  ]);
84
+ /** Generic noise/filler tokens that never uniquely identify a reusable multi-step procedure on their own. */
85
+ const LOW_SIGNAL_PLAN_WORDS = new Set([
86
+ 'fix', 'test', 'testing', 'check', 'run', 'build', 'update', 'change',
87
+ 'help', 'issue', 'bug', 'error', 'work', 'working', 'thing', 'file',
88
+ 'code', 'pleae', 'pls', 'plz', 'halp', 'hello', 'hey', 'thanks', 'thank',
89
+ 'okay', 'yes', 'none', 'something', 'anything', 'everything'
90
+ ]);
91
+ function hasSpecificPlanKeywords(keywords) {
92
+ if (keywords.length < 2)
93
+ return false;
94
+ return keywords.some((word) => !LOW_SIGNAL_PLAN_WORDS.has(word));
95
+ }
84
96
  // HONEST LIMIT. Matching is LEXICAL.
85
97
  // This path is deterministic, instant, and works on a machine with no embedding model
86
98
  // provisioned. Cortex is the semantic route and already carries embeddings;
@@ -517,7 +529,7 @@ export function failureClass(result) {
517
529
  export function lookupPlan(query) {
518
530
  const startedAt = performance.now();
519
531
  const keywords = extractKeywords(query?.prompt);
520
- if (keywords.length === 0) {
532
+ if (!hasSpecificPlanKeywords(keywords)) {
521
533
  recordLookupTelemetry({ hit: false, durationMs: performance.now() - startedAt });
522
534
  return null;
523
535
  }
@@ -530,7 +542,7 @@ export function lookupPlan(query) {
530
542
  }
531
543
  // Tier 1: Exact signature matching (O(1) hash index, Table 5 in APC paper)
532
544
  const exact = exactIndex.get(planSignature(archetype, keywords));
533
- if (exact) {
545
+ if (exact && hasSpecificPlanKeywords(exact.keywords)) {
534
546
  const durationMs = performance.now() - startedAt;
535
547
  recordLookupTelemetry({ hit: true, matchType: 'exact', durationMs });
536
548
  return {
@@ -559,6 +571,8 @@ export function lookupPlan(query) {
559
571
  // three words with "debug the build" is not a plan for it.
560
572
  if (archetype && template.archetype && template.archetype !== archetype)
561
573
  continue;
574
+ if (!hasSpecificPlanKeywords(template.keywords))
575
+ continue;
562
576
  const score = similarity(keywords, template.keywords);
563
577
  if (score < threshold)
564
578
  continue;
@@ -597,7 +611,7 @@ export function recordPlan(outcome) {
597
611
  if (steps.length < 2)
598
612
  return null;
599
613
  const keywords = extractKeywords(outcome?.prompt);
600
- if (keywords.length === 0)
614
+ if (!hasSpecificPlanKeywords(keywords))
601
615
  return null;
602
616
  const plans = readAll();
603
617
  const archetype = String(outcome?.archetype || '');
package/src/planCache.ts CHANGED
@@ -208,6 +208,19 @@ const STOPWORDS: ReadonlySet<string> = new Set([
208
208
  'make', 'create', 'creating', 'made', 'generate'
209
209
  ]);
210
210
 
211
+ /** Generic noise/filler tokens that never uniquely identify a reusable multi-step procedure on their own. */
212
+ const LOW_SIGNAL_PLAN_WORDS: ReadonlySet<string> = new Set([
213
+ 'fix', 'test', 'testing', 'check', 'run', 'build', 'update', 'change',
214
+ 'help', 'issue', 'bug', 'error', 'work', 'working', 'thing', 'file',
215
+ 'code', 'pleae', 'pls', 'plz', 'halp', 'hello', 'hey', 'thanks', 'thank',
216
+ 'okay', 'yes', 'none', 'something', 'anything', 'everything'
217
+ ]);
218
+
219
+ function hasSpecificPlanKeywords(keywords: readonly string[]): boolean {
220
+ if (keywords.length < 2) return false;
221
+ return keywords.some((word) => !LOW_SIGNAL_PLAN_WORDS.has(word));
222
+ }
223
+
211
224
  // HONEST LIMIT. Matching is LEXICAL.
212
225
  // This path is deterministic, instant, and works on a machine with no embedding model
213
226
  // provisioned. Cortex is the semantic route and already carries embeddings;
@@ -640,7 +653,7 @@ export function failureClass(result: unknown): PlanFailureClass | '' {
640
653
  export function lookupPlan(query: PlanLookupQuery | null | undefined): PlanMatch | null {
641
654
  const startedAt = performance.now();
642
655
  const keywords = extractKeywords(query?.prompt);
643
- if (keywords.length === 0) {
656
+ if (!hasSpecificPlanKeywords(keywords)) {
644
657
  recordLookupTelemetry({ hit: false, durationMs: performance.now() - startedAt });
645
658
  return null;
646
659
  }
@@ -655,7 +668,7 @@ export function lookupPlan(query: PlanLookupQuery | null | undefined): PlanMatch
655
668
 
656
669
  // Tier 1: Exact signature matching (O(1) hash index, Table 5 in APC paper)
657
670
  const exact = exactIndex.get(planSignature(archetype, keywords));
658
- if (exact) {
671
+ if (exact && hasSpecificPlanKeywords(exact.keywords)) {
659
672
  const durationMs = performance.now() - startedAt;
660
673
  recordLookupTelemetry({ hit: true, matchType: 'exact', durationMs });
661
674
  return {
@@ -687,6 +700,7 @@ export function lookupPlan(query: PlanLookupQuery | null | undefined): PlanMatch
687
700
  // Archetype is a hard gate, not a score. A "build a 3D scene" plan sharing
688
701
  // three words with "debug the build" is not a plan for it.
689
702
  if (archetype && template.archetype && template.archetype !== archetype) continue;
703
+ if (!hasSpecificPlanKeywords(template.keywords)) continue;
690
704
 
691
705
  const score = similarity(keywords, template.keywords);
692
706
  if (score < threshold) continue;
@@ -727,7 +741,7 @@ export function recordPlan(outcome: PlanRecordInput | null | undefined): PlanTem
727
741
  if (steps.length < 2) return null;
728
742
 
729
743
  const keywords = extractKeywords(outcome?.prompt);
730
- if (keywords.length === 0) return null;
744
+ if (!hasSpecificPlanKeywords(keywords)) return null;
731
745
 
732
746
  const plans = readAll();
733
747
  const archetype = String(outcome?.archetype || '');
@@ -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: 'sys_run', description: 'Execute shell commands with safety checks', aliases: ['run_command', 'shell', 'exec', 'bash'] },
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: 'browser_automator', description: 'Autonomous browser control for web apps and QA', aliases: ['playwright', 'puppeteer', 'chrome'] },
21
- { name: 'vision_inspector', description: 'Inspect images and visual assets with OCR/layout', aliases: ['ocr', 'image_inspect'] },
22
- { name: 'resolve_automator', description: 'DaVinci Resolve automation and studio workflows', aliases: ['resolve', 'davinci', 'video_edit'] },
23
- { name: 'blender_batch', description: 'Blender 3D scene rendering and automation', aliases: ['blender', '3d_render', 'cycles'] },
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: 'pdf_reader', description: 'Extract structured text and tables from PDF documents', aliases: ['read_pdf', 'extract_pdf'] },
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.toLowerCase().trim().replace(/[-_]/g, ' ');
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
- const toolNameNorm = tool.name.toLowerCase().replace(/[-_]/g, ' ');
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
- const pluginNameNorm = plugin.name.toLowerCase().replace(/[-_]/g, ' ');
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
- const tNorm = t.toLowerCase().replace(/[-_]/g, ' ');
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
- const sNameNorm = s.name.toLowerCase().replace(/[-_]/g, ' ');
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: 'sys_run', description: 'Execute shell commands with safety checks', aliases: ['run_command', 'shell', 'exec', 'bash'] },
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: 'browser_automator', description: 'Autonomous browser control for web apps and QA', aliases: ['playwright', 'puppeteer', 'chrome'] },
30
- { name: 'vision_inspector', description: 'Inspect images and visual assets with OCR/layout', aliases: ['ocr', 'image_inspect'] },
31
- { name: 'resolve_automator', description: 'DaVinci Resolve automation and studio workflows', aliases: ['resolve', 'davinci', 'video_edit'] },
32
- { name: 'blender_batch', description: 'Blender 3D scene rendering and automation', aliases: ['blender', '3d_render', 'cycles'] },
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: 'pdf_reader', description: 'Extract structured text and tables from PDF documents', aliases: ['read_pdf', 'extract_pdf'] },
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.toLowerCase().trim().replace(/[-_]/g, ' ');
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
- const toolNameNorm = tool.name.toLowerCase().replace(/[-_]/g, ' ');
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
- const pluginNameNorm = plugin.name.toLowerCase().replace(/[-_]/g, ' ');
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
- const tNorm = t.toLowerCase().replace(/[-_]/g, ' ');
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
- const sNameNorm = s.name.toLowerCase().replace(/[-_]/g, ' ');
100
- if (sNameNorm === normalized || normalized.includes(sNameNorm)) {
113
+ if (matchesTerm(normalized, s.name)) {
101
114
  return {
102
115
  covered: true,
103
116
  source: 'mcp',