@causyne/agent 1.20.38 → 1.20.41
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/LICENSE +1 -1
- package/package.json +1 -1
- package/src/commands.js +41 -0
- package/src/decisionPolicy.js +1 -1
- package/src/decisionPolicy.ts +1 -1
- package/src/plugins/pluginsFactory.js +4 -0
- package/src/plugins/pluginsFactory.ts +6 -0
- package/src/pluginsFactory/costEstimate.js +89 -0
- package/src/pluginsFactory/costEstimate.ts +110 -0
- package/src/pluginsFactory/discovery.js +97 -0
- package/src/pluginsFactory/discovery.ts +114 -0
- package/src/pluginsFactory/index.js +9 -0
- package/src/pluginsFactory/index.ts +11 -0
- package/src/pluginsFactory/pluginsFactory.js +255 -0
- package/src/pluginsFactory/pluginsFactory.ts +307 -0
- package/src/pluginsFactory/strategy.js +93 -0
- package/src/pluginsFactory/strategy.ts +106 -0
- package/src/pluginsFactory/templates.js +624 -0
- package/src/pluginsFactory/templates.ts +662 -0
- package/src/pluginsFactory/types.js +12 -0
- package/src/pluginsFactory/types.ts +107 -0
- package/src/stallGuard.js +1 -0
- package/src/stallGuard.ts +1 -0
- package/src/toolPacks.js +2 -1
- package/src/toolPacks.ts +2 -1
- package/src/tools/pluginsFactory.js +209 -0
- package/src/tools/pluginsFactory.ts +254 -0
- package/src/tools/registry.js +2 -1
- package/src/toolsList.js +1 -0
- package/src/toolsList.ts +1 -0
- package/src/tui/chatRenderer.d.ts +1 -0
- package/src/tui/chatRenderer.js +60 -37
- package/src/tui/messageInteraction.js +26 -3
- package/src/tui/messageInteraction.ts +39 -4
- package/src/tui/thinkingBox.js +141 -0
- package/src/tui/thinkingBox.ts +190 -0
package/LICENSE
CHANGED
package/package.json
CHANGED
package/src/commands.js
CHANGED
|
@@ -961,6 +961,47 @@ export const COMMANDS = [
|
|
|
961
961
|
}
|
|
962
962
|
},
|
|
963
963
|
|
|
964
|
+
{
|
|
965
|
+
name: 'thinking',
|
|
966
|
+
aliases: ['thought', 'thoughts'],
|
|
967
|
+
scope: 'local',
|
|
968
|
+
usage: '/thinking [toggle|expand|collapse]',
|
|
969
|
+
description: 'Toggle or fold thinking process chunks in the conversation transcript',
|
|
970
|
+
run: (argv, ctx) => {
|
|
971
|
+
const surface = ctx?.prompt?.surface;
|
|
972
|
+
const transcript = surface?.transcript;
|
|
973
|
+
if (!transcript || !Array.isArray(transcript.frames)) {
|
|
974
|
+
return ok('No active interactive transcript available.');
|
|
975
|
+
}
|
|
976
|
+
const reasoningFrames = transcript.frames.filter((f) => f.kind === 'reasoning');
|
|
977
|
+
if (reasoningFrames.length === 0) {
|
|
978
|
+
return ok('No thinking process frames found in the current conversation.');
|
|
979
|
+
}
|
|
980
|
+
const sub = (argv[0] || 'toggle').toLowerCase();
|
|
981
|
+
let newCollapsed;
|
|
982
|
+
if (sub === 'expand') {
|
|
983
|
+
newCollapsed = false;
|
|
984
|
+
} else if (sub === 'collapse') {
|
|
985
|
+
newCollapsed = true;
|
|
986
|
+
} else {
|
|
987
|
+
const last = reasoningFrames[reasoningFrames.length - 1];
|
|
988
|
+
newCollapsed = !Boolean(last?.meta?.collapsed);
|
|
989
|
+
}
|
|
990
|
+
for (const frame of reasoningFrames) {
|
|
991
|
+
if (frame.meta) {
|
|
992
|
+
frame.meta.collapsed = newCollapsed;
|
|
993
|
+
frame.rows = null;
|
|
994
|
+
frame.renderedWidth = -1;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
transcript.cache = null;
|
|
998
|
+
transcript.revision++;
|
|
999
|
+
transcript.changed?.();
|
|
1000
|
+
if (ctx.prompt?.scheduleDraw) ctx.prompt.scheduleDraw();
|
|
1001
|
+
return ok(`${newCollapsed ? 'Collapsed' : 'Expanded'} ${reasoningFrames.length} thinking frame${reasoningFrames.length === 1 ? '' : 's'}.`);
|
|
1002
|
+
}
|
|
1003
|
+
},
|
|
1004
|
+
|
|
964
1005
|
{
|
|
965
1006
|
name: 'clear',
|
|
966
1007
|
aliases: ['reset'],
|
package/src/decisionPolicy.js
CHANGED
|
@@ -16,7 +16,7 @@ const EXPLICIT_CHOICE_PATTERNS = [
|
|
|
16
16
|
];
|
|
17
17
|
const MUTATING_TOOLS = new Set([
|
|
18
18
|
'fs_write', 'fs_edit', 'MultiEdit', 'fs_delete', 'fs_move', 'sysRun', 'sysRunBg',
|
|
19
|
-
'gitOp', 'manage_local_dependencies', 'plugin_manage', 'tool_forge', 'create_skill',
|
|
19
|
+
'gitOp', 'manage_local_dependencies', 'plugin_manage', 'tool_forge', 'plugins_factory', 'create_skill',
|
|
20
20
|
'write_file', 'write_to_file', 'edit_file', 'replace_file_content', 'multi_replace_file_content',
|
|
21
21
|
'write', 'edit', 'multiedit', 'bash', 'terminal', 'execute'
|
|
22
22
|
]);
|
package/src/decisionPolicy.ts
CHANGED
|
@@ -50,7 +50,7 @@ const EXPLICIT_CHOICE_PATTERNS = [
|
|
|
50
50
|
|
|
51
51
|
const MUTATING_TOOLS = new Set([
|
|
52
52
|
'fs_write', 'fs_edit', 'MultiEdit', 'fs_delete', 'fs_move', 'sysRun', 'sysRunBg',
|
|
53
|
-
'gitOp', 'manage_local_dependencies', 'plugin_manage', 'tool_forge', 'create_skill',
|
|
53
|
+
'gitOp', 'manage_local_dependencies', 'plugin_manage', 'tool_forge', 'plugins_factory', 'create_skill',
|
|
54
54
|
'write_file', 'write_to_file', 'edit_file', 'replace_file_content', 'multi_replace_file_content',
|
|
55
55
|
'write', 'edit', 'multiedit', 'bash', 'terminal', 'execute'
|
|
56
56
|
]);
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cost and Token Footprint Estimation for PluginsFactory.
|
|
3
|
+
*
|
|
4
|
+
* Provides transparent, measurable token footprint estimates across integration routes:
|
|
5
|
+
* - Native Plugin (HTTP/CLI): Leanest token footprint, lowest cost.
|
|
6
|
+
* - Python Bridge: Lightweight buffer process for Python-only libraries.
|
|
7
|
+
* - MCP Server: Rich protocol but significantly higher token and process overhead.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Estimate the token footprint of a single tool schema in agent context.
|
|
11
|
+
* Standard token-to-character ratio is approximately 1 token per 4 characters of JSON.
|
|
12
|
+
*/
|
|
13
|
+
export function estimateToolSchemaTokens(parameters) {
|
|
14
|
+
try {
|
|
15
|
+
const jsonStr = JSON.stringify(parameters ?? {});
|
|
16
|
+
return Math.max(15, Math.ceil(jsonStr.length / 4));
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return 30;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Compute comparative token footprint and runtime cost across all three routes.
|
|
24
|
+
*/
|
|
25
|
+
export function estimateServiceCosts(service) {
|
|
26
|
+
const toolCount = Math.max(1, service.tools.length);
|
|
27
|
+
const rawSchemaTokens = service.tools.reduce((total, tool) => total + estimateToolSchemaTokens(tool.parameters), 0);
|
|
28
|
+
// 1. Native Plugin (HTTP / CLI)
|
|
29
|
+
// Minimal envelope overhead: name, description, parameters schema (~35 tokens per tool)
|
|
30
|
+
const nativeSchemaTokens = rawSchemaTokens + toolCount * 35;
|
|
31
|
+
const nativePerCallTokens = 120; // Compact direct return payload
|
|
32
|
+
const nativePlugin = {
|
|
33
|
+
route: 'native_plugin',
|
|
34
|
+
estimatedSchemaTokens: nativeSchemaTokens,
|
|
35
|
+
estimatedPerCallTokens: nativePerCallTokens,
|
|
36
|
+
isLongRunningProcess: false,
|
|
37
|
+
relativeCostMultiplier: 1.0,
|
|
38
|
+
explanation: 'Minimal context overhead. Schema is loaded on demand, output is compact, and process terminates immediately.'
|
|
39
|
+
};
|
|
40
|
+
// 2. Python Bridge Plugin
|
|
41
|
+
// Slightly higher envelope overhead for bridge parameter marshalling (~45 tokens per tool)
|
|
42
|
+
const bridgeSchemaTokens = rawSchemaTokens + toolCount * 45;
|
|
43
|
+
const bridgePerCallTokens = 150; // JSON stdin/stdout pipe payload
|
|
44
|
+
const pythonBridge = {
|
|
45
|
+
route: 'python_bridge',
|
|
46
|
+
estimatedSchemaTokens: bridgeSchemaTokens,
|
|
47
|
+
estimatedPerCallTokens: bridgePerCallTokens,
|
|
48
|
+
isLongRunningProcess: false,
|
|
49
|
+
relativeCostMultiplier: 1.25,
|
|
50
|
+
explanation: 'Executes specialized Python SDKs (Blender, DaVinci Resolve, PyTorch) via a lightweight on-demand subprocess.'
|
|
51
|
+
};
|
|
52
|
+
// 3. MCP Server
|
|
53
|
+
// MCP requires full JSON-RPC schema envelope, inputSchema wrapping, and server capabilities (~160 tokens per tool)
|
|
54
|
+
const mcpSchemaTokens = rawSchemaTokens + toolCount * 160 + 120;
|
|
55
|
+
const mcpPerCallTokens = 420; // Full JSON-RPC 2.0 result envelope with text/content arrays
|
|
56
|
+
const mcpMultiplier = Number((mcpSchemaTokens / Math.max(1, nativeSchemaTokens)).toFixed(1));
|
|
57
|
+
const mcpServer = {
|
|
58
|
+
route: 'mcp_server',
|
|
59
|
+
estimatedSchemaTokens: mcpSchemaTokens,
|
|
60
|
+
estimatedPerCallTokens: mcpPerCallTokens,
|
|
61
|
+
isLongRunningProcess: true,
|
|
62
|
+
relativeCostMultiplier: Math.max(3.0, mcpMultiplier),
|
|
63
|
+
explanation: 'Persistent JSON-RPC stdio daemon. Injects full tool schema manifests and verbose protocol framing across conversation turns.'
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
nativePlugin,
|
|
67
|
+
pythonBridge,
|
|
68
|
+
mcpServer
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Format a transparent token disclosure when an MCP server route is considered or requested.
|
|
73
|
+
*/
|
|
74
|
+
export function formatMcpDisclosure(serviceName, comparison) {
|
|
75
|
+
const native = comparison.nativePlugin;
|
|
76
|
+
const mcp = comparison.mcpServer;
|
|
77
|
+
const ratio = (mcp.estimatedSchemaTokens / Math.max(1, native.estimatedSchemaTokens)).toFixed(1);
|
|
78
|
+
return [
|
|
79
|
+
`### Token Economy Disclosure: ${serviceName}`,
|
|
80
|
+
'',
|
|
81
|
+
`Model Context Protocol (MCP) servers incur higher token consumption compared to native plugins:`,
|
|
82
|
+
`- **Schema Ingestion Overhead**: ~${mcp.estimatedSchemaTokens} tokens vs ~${native.estimatedSchemaTokens} tokens for a native plugin (~${ratio}x larger schema footprint per turn).`,
|
|
83
|
+
`- **Protocol Envelope**: MCP wraps all outputs in full JSON-RPC 2.0 structures (~${mcp.estimatedPerCallTokens} tokens per call vs ~${native.estimatedPerCallTokens} tokens natively).`,
|
|
84
|
+
`- **Process Lifecycle**: MCP runs as an ongoing background daemon, whereas native plugins execute on demand with zero idling resources.`,
|
|
85
|
+
'',
|
|
86
|
+
`**Recommendation**: If an HTTP API, CLI binary, or Python SDK is accessible, a native plugin or Python bridge is vastly more token-efficient and economical.`,
|
|
87
|
+
`However, if this service strictly requires MCP or you prefer standard MCP tooling, Causyne will faithfully implement and configure the MCP server according to your direction.`
|
|
88
|
+
].join('\n');
|
|
89
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cost and Token Footprint Estimation for PluginsFactory.
|
|
3
|
+
*
|
|
4
|
+
* Provides transparent, measurable token footprint estimates across integration routes:
|
|
5
|
+
* - Native Plugin (HTTP/CLI): Leanest token footprint, lowest cost.
|
|
6
|
+
* - Python Bridge: Lightweight buffer process for Python-only libraries.
|
|
7
|
+
* - MCP Server: Rich protocol but significantly higher token and process overhead.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
CostEstimate,
|
|
12
|
+
RouteCostComparison,
|
|
13
|
+
ServiceDescriptor,
|
|
14
|
+
ToolParameterSchema
|
|
15
|
+
} from './types.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Estimate the token footprint of a single tool schema in agent context.
|
|
19
|
+
* Standard token-to-character ratio is approximately 1 token per 4 characters of JSON.
|
|
20
|
+
*/
|
|
21
|
+
export function estimateToolSchemaTokens(parameters: ToolParameterSchema): number {
|
|
22
|
+
try {
|
|
23
|
+
const jsonStr = JSON.stringify(parameters ?? {});
|
|
24
|
+
return Math.max(15, Math.ceil(jsonStr.length / 4));
|
|
25
|
+
} catch {
|
|
26
|
+
return 30;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Compute comparative token footprint and runtime cost across all three routes.
|
|
32
|
+
*/
|
|
33
|
+
export function estimateServiceCosts(service: ServiceDescriptor): RouteCostComparison {
|
|
34
|
+
const toolCount = Math.max(1, service.tools.length);
|
|
35
|
+
const rawSchemaTokens = service.tools.reduce(
|
|
36
|
+
(total, tool) => total + estimateToolSchemaTokens(tool.parameters),
|
|
37
|
+
0
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
// 1. Native Plugin (HTTP / CLI)
|
|
41
|
+
// Minimal envelope overhead: name, description, parameters schema (~35 tokens per tool)
|
|
42
|
+
const nativeSchemaTokens = rawSchemaTokens + toolCount * 35;
|
|
43
|
+
const nativePerCallTokens = 120; // Compact direct return payload
|
|
44
|
+
const nativePlugin: CostEstimate = {
|
|
45
|
+
route: 'native_plugin',
|
|
46
|
+
estimatedSchemaTokens: nativeSchemaTokens,
|
|
47
|
+
estimatedPerCallTokens: nativePerCallTokens,
|
|
48
|
+
isLongRunningProcess: false,
|
|
49
|
+
relativeCostMultiplier: 1.0,
|
|
50
|
+
explanation:
|
|
51
|
+
'Minimal context overhead. Schema is loaded on demand, output is compact, and process terminates immediately.'
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// 2. Python Bridge Plugin
|
|
55
|
+
// Slightly higher envelope overhead for bridge parameter marshalling (~45 tokens per tool)
|
|
56
|
+
const bridgeSchemaTokens = rawSchemaTokens + toolCount * 45;
|
|
57
|
+
const bridgePerCallTokens = 150; // JSON stdin/stdout pipe payload
|
|
58
|
+
const pythonBridge: CostEstimate = {
|
|
59
|
+
route: 'python_bridge',
|
|
60
|
+
estimatedSchemaTokens: bridgeSchemaTokens,
|
|
61
|
+
estimatedPerCallTokens: bridgePerCallTokens,
|
|
62
|
+
isLongRunningProcess: false,
|
|
63
|
+
relativeCostMultiplier: 1.25,
|
|
64
|
+
explanation:
|
|
65
|
+
'Executes specialized Python SDKs (Blender, DaVinci Resolve, PyTorch) via a lightweight on-demand subprocess.'
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// 3. MCP Server
|
|
69
|
+
// MCP requires full JSON-RPC schema envelope, inputSchema wrapping, and server capabilities (~160 tokens per tool)
|
|
70
|
+
const mcpSchemaTokens = rawSchemaTokens + toolCount * 160 + 120;
|
|
71
|
+
const mcpPerCallTokens = 420; // Full JSON-RPC 2.0 result envelope with text/content arrays
|
|
72
|
+
const mcpMultiplier = Number((mcpSchemaTokens / Math.max(1, nativeSchemaTokens)).toFixed(1));
|
|
73
|
+
const mcpServer: CostEstimate = {
|
|
74
|
+
route: 'mcp_server',
|
|
75
|
+
estimatedSchemaTokens: mcpSchemaTokens,
|
|
76
|
+
estimatedPerCallTokens: mcpPerCallTokens,
|
|
77
|
+
isLongRunningProcess: true,
|
|
78
|
+
relativeCostMultiplier: Math.max(3.0, mcpMultiplier),
|
|
79
|
+
explanation:
|
|
80
|
+
'Persistent JSON-RPC stdio daemon. Injects full tool schema manifests and verbose protocol framing across conversation turns.'
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
nativePlugin,
|
|
85
|
+
pythonBridge,
|
|
86
|
+
mcpServer
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Format a transparent token disclosure when an MCP server route is considered or requested.
|
|
92
|
+
*/
|
|
93
|
+
export function formatMcpDisclosure(serviceName: string, comparison: RouteCostComparison): string {
|
|
94
|
+
const native = comparison.nativePlugin;
|
|
95
|
+
const mcp = comparison.mcpServer;
|
|
96
|
+
const ratio = (mcp.estimatedSchemaTokens / Math.max(1, native.estimatedSchemaTokens)).toFixed(1);
|
|
97
|
+
|
|
98
|
+
return [
|
|
99
|
+
`### Token Economy Disclosure: ${serviceName}`,
|
|
100
|
+
'',
|
|
101
|
+
`Model Context Protocol (MCP) servers incur higher token consumption compared to native plugins:`,
|
|
102
|
+
`- **Schema Ingestion Overhead**: ~${mcp.estimatedSchemaTokens} tokens vs ~${native.estimatedSchemaTokens} tokens for a native plugin (~${ratio}x larger schema footprint per turn).`,
|
|
103
|
+
`- **Protocol Envelope**: MCP wraps all outputs in full JSON-RPC 2.0 structures (~${mcp.estimatedPerCallTokens} tokens per call vs ~${native.estimatedPerCallTokens} tokens natively).`,
|
|
104
|
+
`- **Process Lifecycle**: MCP runs as an ongoing background daemon, whereas native plugins execute on demand with zero idling resources.`,
|
|
105
|
+
'',
|
|
106
|
+
`**Recommendation**: If an HTTP API, CLI binary, or Python SDK is accessible, a native plugin or Python bridge is vastly more token-efficient and economical.`,
|
|
107
|
+
`However, if this service strictly requires MCP or you prefer standard MCP tooling, Causyne will faithfully implement and configure the MCP server according to your direction.`
|
|
108
|
+
].join('\n');
|
|
109
|
+
}
|
|
110
|
+
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capability Discovery for PluginsFactory.
|
|
3
|
+
*
|
|
4
|
+
* Checks whether a requested tool or capability is already covered by:
|
|
5
|
+
* 1. Native built-in tools in Causyne Agent.
|
|
6
|
+
* 2. Installed local plugins in ~/.causyne/plugins.
|
|
7
|
+
* 3. Configured MCP servers in ~/.causyne/config.json.
|
|
8
|
+
*
|
|
9
|
+
* If already covered, recommends reusing existing functionality to avoid duplicate code.
|
|
10
|
+
*/
|
|
11
|
+
import { configuredServers } from '../mcp/mcpRegistry.js';
|
|
12
|
+
// @ts-expect-error legacy JS plugin manager lacks typings
|
|
13
|
+
import { listPlugins } from '../plugins/pluginManager.js';
|
|
14
|
+
const NATIVE_TOOLS_CATALOG = [
|
|
15
|
+
{ name: 'fs_read', description: 'Read file contents from the workspace', aliases: ['read_file', 'cat', 'open_file'] },
|
|
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'] },
|
|
18
|
+
{ name: 'web_search', description: 'Perform web search queries', aliases: ['search', 'google_search', 'web_query'] },
|
|
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'] },
|
|
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'] }
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* Searches for existing capabilities matching a service or tool query.
|
|
30
|
+
*/
|
|
31
|
+
export function findExistingCapability(query) {
|
|
32
|
+
const normalized = query.toLowerCase().trim().replace(/[-_]/g, ' ');
|
|
33
|
+
if (!normalized)
|
|
34
|
+
return { covered: false };
|
|
35
|
+
// 1. Check Native Built-in Tools
|
|
36
|
+
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))) {
|
|
39
|
+
return {
|
|
40
|
+
covered: true,
|
|
41
|
+
source: 'native_tool',
|
|
42
|
+
matchName: tool.name,
|
|
43
|
+
details: `Covered natively by built-in tool '${tool.name}': ${tool.description}`
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// 2. Check Installed Plugins
|
|
48
|
+
try {
|
|
49
|
+
const plugins = listPlugins();
|
|
50
|
+
for (const plugin of plugins) {
|
|
51
|
+
const pluginNameNorm = plugin.name.toLowerCase().replace(/[-_]/g, ' ');
|
|
52
|
+
if (pluginNameNorm === normalized || normalized.includes(pluginNameNorm)) {
|
|
53
|
+
return {
|
|
54
|
+
covered: true,
|
|
55
|
+
source: 'plugin',
|
|
56
|
+
matchName: plugin.name,
|
|
57
|
+
details: `Covered by ${plugin.enabled ? 'active' : 'installed (disabled)'} plugin '${plugin.name}'. Tools: ${(plugin.tools || []).join(', ')}`
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (Array.isArray(plugin.tools)) {
|
|
61
|
+
for (const t of plugin.tools) {
|
|
62
|
+
const tNorm = t.toLowerCase().replace(/[-_]/g, ' ');
|
|
63
|
+
if (tNorm === normalized || normalized.includes(tNorm)) {
|
|
64
|
+
return {
|
|
65
|
+
covered: true,
|
|
66
|
+
source: 'plugin',
|
|
67
|
+
matchName: `${plugin.name} (${t})`,
|
|
68
|
+
details: `Covered by tool '${t}' in plugin '${plugin.name}'`
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// If plugins directory is uninitialized, proceed smoothly
|
|
77
|
+
}
|
|
78
|
+
// 3. Check Configured MCP Servers
|
|
79
|
+
try {
|
|
80
|
+
const servers = configuredServers();
|
|
81
|
+
for (const s of servers) {
|
|
82
|
+
const sNameNorm = s.name.toLowerCase().replace(/[-_]/g, ' ');
|
|
83
|
+
if (sNameNorm === normalized || normalized.includes(sNameNorm)) {
|
|
84
|
+
return {
|
|
85
|
+
covered: true,
|
|
86
|
+
source: 'mcp',
|
|
87
|
+
matchName: s.name,
|
|
88
|
+
details: `Covered by configured MCP server '${s.name}' (${s.url ? 'HTTP' : 'stdio'})`
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// If MCP registry is not loaded, proceed smoothly
|
|
95
|
+
}
|
|
96
|
+
return { covered: false };
|
|
97
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capability Discovery for PluginsFactory.
|
|
3
|
+
*
|
|
4
|
+
* Checks whether a requested tool or capability is already covered by:
|
|
5
|
+
* 1. Native built-in tools in Causyne Agent.
|
|
6
|
+
* 2. Installed local plugins in ~/.causyne/plugins.
|
|
7
|
+
* 3. Configured MCP servers in ~/.causyne/config.json.
|
|
8
|
+
*
|
|
9
|
+
* If already covered, recommends reusing existing functionality to avoid duplicate code.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { configuredServers } from '../mcp/mcpRegistry.js';
|
|
13
|
+
// @ts-expect-error legacy JS plugin manager lacks typings
|
|
14
|
+
import { listPlugins } from '../plugins/pluginManager.js';
|
|
15
|
+
|
|
16
|
+
export interface ExistingCapabilityMatch {
|
|
17
|
+
covered: boolean;
|
|
18
|
+
source?: 'native_tool' | 'plugin' | 'mcp';
|
|
19
|
+
matchName?: string;
|
|
20
|
+
details?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const NATIVE_TOOLS_CATALOG: Array<{ name: string; description: string; aliases: string[] }> = [
|
|
24
|
+
{ name: 'fs_read', description: 'Read file contents from the workspace', aliases: ['read_file', 'cat', 'open_file'] },
|
|
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'] },
|
|
27
|
+
{ name: 'web_search', description: 'Perform web search queries', aliases: ['search', 'google_search', 'web_query'] },
|
|
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'] },
|
|
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'] }
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Searches for existing capabilities matching a service or tool query.
|
|
40
|
+
*/
|
|
41
|
+
export function findExistingCapability(query: string): ExistingCapabilityMatch {
|
|
42
|
+
const normalized = query.toLowerCase().trim().replace(/[-_]/g, ' ');
|
|
43
|
+
if (!normalized) return { covered: false };
|
|
44
|
+
|
|
45
|
+
// 1. Check Native Built-in Tools
|
|
46
|
+
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))) {
|
|
49
|
+
return {
|
|
50
|
+
covered: true,
|
|
51
|
+
source: 'native_tool',
|
|
52
|
+
matchName: tool.name,
|
|
53
|
+
details: `Covered natively by built-in tool '${tool.name}': ${tool.description}`
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 2. Check Installed Plugins
|
|
59
|
+
try {
|
|
60
|
+
const plugins = listPlugins() as Array<{
|
|
61
|
+
name: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
enabled: boolean;
|
|
64
|
+
tools?: string[];
|
|
65
|
+
}>;
|
|
66
|
+
|
|
67
|
+
for (const plugin of plugins) {
|
|
68
|
+
const pluginNameNorm = plugin.name.toLowerCase().replace(/[-_]/g, ' ');
|
|
69
|
+
if (pluginNameNorm === normalized || normalized.includes(pluginNameNorm)) {
|
|
70
|
+
return {
|
|
71
|
+
covered: true,
|
|
72
|
+
source: 'plugin',
|
|
73
|
+
matchName: plugin.name,
|
|
74
|
+
details: `Covered by ${plugin.enabled ? 'active' : 'installed (disabled)'} plugin '${plugin.name}'. Tools: ${(plugin.tools || []).join(', ')}`
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (Array.isArray(plugin.tools)) {
|
|
78
|
+
for (const t of plugin.tools) {
|
|
79
|
+
const tNorm = t.toLowerCase().replace(/[-_]/g, ' ');
|
|
80
|
+
if (tNorm === normalized || normalized.includes(tNorm)) {
|
|
81
|
+
return {
|
|
82
|
+
covered: true,
|
|
83
|
+
source: 'plugin',
|
|
84
|
+
matchName: `${plugin.name} (${t})`,
|
|
85
|
+
details: `Covered by tool '${t}' in plugin '${plugin.name}'`
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
// If plugins directory is uninitialized, proceed smoothly
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 3. Check Configured MCP Servers
|
|
96
|
+
try {
|
|
97
|
+
const servers = configuredServers();
|
|
98
|
+
for (const s of servers) {
|
|
99
|
+
const sNameNorm = s.name.toLowerCase().replace(/[-_]/g, ' ');
|
|
100
|
+
if (sNameNorm === normalized || normalized.includes(sNameNorm)) {
|
|
101
|
+
return {
|
|
102
|
+
covered: true,
|
|
103
|
+
source: 'mcp',
|
|
104
|
+
matchName: s.name,
|
|
105
|
+
details: `Covered by configured MCP server '${s.name}' (${s.url ? 'HTTP' : 'stdio'})`
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
} catch {
|
|
110
|
+
// If MCP registry is not loaded, proceed smoothly
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return { covered: false };
|
|
114
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Causyne PluginsFactory Module Exports
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export * from './types.js';
|
|
6
|
+
export * from './costEstimate.js';
|
|
7
|
+
export * from './discovery.js';
|
|
8
|
+
export * from './strategy.js';
|
|
9
|
+
export * from './templates.js';
|
|
10
|
+
export * from './pluginsFactory.js';
|
|
11
|
+
|