@causyne/agent 1.20.36 → 1.20.39

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 (51) hide show
  1. package/LICENSE +1 -1
  2. package/package.json +1 -1
  3. package/src/decisionPolicy.js +1 -1
  4. package/src/decisionPolicy.ts +1 -1
  5. package/src/plugins/pluginsFactory.js +4 -0
  6. package/src/plugins/pluginsFactory.ts +6 -0
  7. package/src/pluginsFactory/costEstimate.js +89 -0
  8. package/src/pluginsFactory/costEstimate.ts +110 -0
  9. package/src/pluginsFactory/discovery.js +97 -0
  10. package/src/pluginsFactory/discovery.ts +114 -0
  11. package/src/pluginsFactory/index.js +9 -0
  12. package/src/pluginsFactory/index.ts +11 -0
  13. package/src/pluginsFactory/pluginsFactory.js +250 -0
  14. package/src/pluginsFactory/pluginsFactory.ts +302 -0
  15. package/src/pluginsFactory/strategy.js +93 -0
  16. package/src/pluginsFactory/strategy.ts +106 -0
  17. package/src/pluginsFactory/templates.js +592 -0
  18. package/src/pluginsFactory/templates.ts +631 -0
  19. package/src/pluginsFactory/types.js +12 -0
  20. package/src/pluginsFactory/types.ts +107 -0
  21. package/src/stallGuard.js +1 -0
  22. package/src/stallGuard.ts +1 -0
  23. package/src/toolPacks.js +1 -0
  24. package/src/toolPacks.ts +1 -0
  25. package/src/tools/pluginsFactory.js +202 -0
  26. package/src/tools/pluginsFactory.ts +246 -0
  27. package/src/tools/registry.js +2 -1
  28. package/src/tools/sysRun.js +22 -6
  29. package/src/tools/sysRun.ts +23 -6
  30. package/src/toolsList.js +1 -0
  31. package/src/toolsList.ts +1 -0
  32. package/src/tui/chatRenderer.js +5 -4
  33. package/src/tui/homeView.js +0 -1
  34. package/src/tui/homeView.ts +0 -1
  35. package/src/tui/markdownMath.js +250 -0
  36. package/src/tui/markdownMath.ts +263 -0
  37. package/src/tui/messageActionPlacement.js +79 -8
  38. package/src/tui/messageActionPlacement.ts +102 -9
  39. package/src/tui/messageInteraction.js +43 -9
  40. package/src/tui/messageInteraction.ts +51 -17
  41. package/src/tui/overlay.js +191 -192
  42. package/src/tui/overlay.ts +320 -0
  43. package/src/tui/prompt.js +4 -1
  44. package/src/tui/stageSurface.js +4 -1
  45. package/src/tui/text.js +204 -208
  46. package/src/tui/text.ts +360 -0
  47. package/src/tui/toolOutputNormalizer.js +3 -1
  48. package/src/tui/toolOutputNormalizer.ts +3 -1
  49. package/src/tui/turnRail.js +11 -1
  50. package/src/tui/turnRail.ts +11 -1
  51. package/src/tui/text.d.ts +0 -7
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Types and interfaces for PluginsFactory.
3
+ *
4
+ * PluginsFactory empowers Causyne Agent to generate custom plugins, Python bridges,
5
+ * or MCP servers when a requested service/integration does not yet exist.
6
+ *
7
+ * Route Strategy:
8
+ * 1. Native Plugin (HTTP/CLI): Leanest token footprint, lowest cost.
9
+ * 2. Python Bridge: Spawns Python subprocess with JSON protocol for Python-only SDKs.
10
+ * 3. MCP Server: Used when a service strictly permits only MCP or the user explicitly asks for it.
11
+ */
12
+
13
+ export type RouteKind = 'native_plugin' | 'python_bridge' | 'mcp_server';
14
+
15
+ export type ServiceKind = 'http_api' | 'cli' | 'python_sdk' | 'mcp_only' | 'custom';
16
+
17
+ export type CapabilityName = 'workspace:read' | 'workspace:write' | 'network' | 'subprocess';
18
+
19
+ export interface ToolParameterSchema {
20
+ type: 'object';
21
+ properties?: Record<string, {
22
+ type?: string | undefined;
23
+ description?: string | undefined;
24
+ enum?: string[] | undefined;
25
+ default?: unknown;
26
+ items?: Record<string, unknown> | undefined;
27
+ [key: string]: unknown;
28
+ }> | undefined;
29
+ required?: string[] | undefined;
30
+ [key: string]: unknown;
31
+ }
32
+
33
+ export interface ServiceToolDescriptor {
34
+ name: string;
35
+ description: string;
36
+ parameters: ToolParameterSchema;
37
+ httpMethod?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | undefined;
38
+ httpPath?: string | undefined;
39
+ cliSubcommand?: string | undefined;
40
+ pythonMethod?: string | undefined;
41
+ }
42
+
43
+ export interface ServiceDescriptor {
44
+ name: string;
45
+ description: string;
46
+ serviceKind: ServiceKind;
47
+ endpoint?: string | undefined;
48
+ authType?: 'none' | 'bearer' | 'apiKey' | 'basic' | 'env' | undefined;
49
+ authEnvVar?: string | undefined;
50
+ cliBinary?: string | undefined;
51
+ pythonModule?: string | undefined;
52
+ tools: ServiceToolDescriptor[];
53
+ capabilities?: CapabilityName[] | undefined;
54
+ userPreferredRoute?: RouteKind | undefined;
55
+ }
56
+
57
+ export interface CostEstimate {
58
+ route: RouteKind;
59
+ estimatedSchemaTokens: number;
60
+ estimatedPerCallTokens: number;
61
+ isLongRunningProcess: boolean;
62
+ relativeCostMultiplier: number;
63
+ explanation: string;
64
+ }
65
+
66
+ export interface RouteCostComparison {
67
+ nativePlugin: CostEstimate;
68
+ pythonBridge: CostEstimate;
69
+ mcpServer: CostEstimate;
70
+ }
71
+
72
+ export interface FactoryRouteProposal {
73
+ service: ServiceDescriptor;
74
+ recommendedRoute: RouteKind;
75
+ reason: string;
76
+ costComparison: RouteCostComparison;
77
+ mcpDisclosure?: string | undefined;
78
+ userConsentRequired: boolean;
79
+ userConfirmedRoute?: RouteKind | undefined;
80
+ existingCapability?: {
81
+ covered: boolean;
82
+ source?: 'native_tool' | 'plugin' | 'mcp' | undefined;
83
+ matchName?: string | undefined;
84
+ details?: string | undefined;
85
+ } | undefined;
86
+ }
87
+
88
+ export interface ScaffoldOptions {
89
+ force?: boolean | undefined;
90
+ baseDir?: string | undefined;
91
+ dryRun?: boolean | undefined;
92
+ }
93
+
94
+ export interface ScaffoldResult {
95
+ success: boolean;
96
+ route: RouteKind;
97
+ targetDirectory: string;
98
+ createdFiles: string[];
99
+ digest?: string | undefined;
100
+ instructions: string;
101
+ error?: string | undefined;
102
+ }
103
+
104
+ export interface PluginFactoryOptions {
105
+ pluginsDir?: string | undefined;
106
+ mcpServersDir?: string | undefined;
107
+ }
package/src/stallGuard.js CHANGED
@@ -50,6 +50,7 @@ export const MUTATING_TOOL_NAMES = new Set([
50
50
  'archive_extract',
51
51
  'game_build_html5',
52
52
  'tool_forge',
53
+ 'plugins_factory',
53
54
  'create_skill',
54
55
  'manage_local_dependencies',
55
56
  'creative_batch',
package/src/stallGuard.ts CHANGED
@@ -86,6 +86,7 @@ export const MUTATING_TOOL_NAMES = new Set([
86
86
  'archive_extract',
87
87
  'game_build_html5',
88
88
  'tool_forge',
89
+ 'plugins_factory',
89
90
  'create_skill',
90
91
  'manage_local_dependencies',
91
92
  'creative_batch',
package/src/toolPacks.js CHANGED
@@ -108,6 +108,7 @@ export const PACKS = {
108
108
  advanced: [
109
109
  'tool_forge',
110
110
  'plugin_manager',
111
+ 'plugins_factory',
111
112
  'document_forge',
112
113
  'agent_subagent_orchestrate',
113
114
  'peer_agent_delegate',
package/src/toolPacks.ts CHANGED
@@ -134,6 +134,7 @@ export const PACKS: Record<PackName, string[]> = {
134
134
  advanced: [
135
135
  'tool_forge',
136
136
  'plugin_manager',
137
+ 'plugins_factory',
137
138
  'document_forge',
138
139
  'agent_subagent_orchestrate',
139
140
  'peer_agent_delegate',
@@ -0,0 +1,202 @@
1
+ /**
2
+ * plugins_factory Tool for Causyne Agent.
3
+ *
4
+ * Implements autonomous custom integration evaluation and scaffolding.
5
+ * Recommends token-lean native plugins or Python bridges, while fully respecting
6
+ * user choices if MCP is preferred.
7
+ */
8
+ import { PluginsFactory } from '../pluginsFactory/index.js';
9
+ function normalizeServiceDescriptor(args) {
10
+ const tools = (args.tools || []).map((t, idx) => {
11
+ const tool = {
12
+ name: t.name || `tool_${idx + 1}`,
13
+ description: t.description || `Tool ${t.name || idx + 1}`,
14
+ parameters: (t.parameters && typeof t.parameters === 'object' && t.parameters.type === 'object')
15
+ ? t.parameters
16
+ : { type: 'object', properties: {} }
17
+ };
18
+ if (t.httpMethod !== undefined)
19
+ tool.httpMethod = t.httpMethod;
20
+ if (t.httpPath !== undefined)
21
+ tool.httpPath = t.httpPath;
22
+ if (t.cliSubcommand !== undefined)
23
+ tool.cliSubcommand = t.cliSubcommand;
24
+ if (t.pythonMethod !== undefined)
25
+ tool.pythonMethod = t.pythonMethod;
26
+ return tool;
27
+ });
28
+ if (tools.length === 0) {
29
+ tools.push({
30
+ name: 'execute',
31
+ description: `Default execution method for ${args.serviceName}`,
32
+ parameters: { type: 'object', properties: {} }
33
+ });
34
+ }
35
+ const desc = {
36
+ name: args.serviceName,
37
+ description: args.serviceDescription || `Custom integration for ${args.serviceName}`,
38
+ serviceKind: args.serviceKind || 'custom',
39
+ tools
40
+ };
41
+ if (args.endpoint !== undefined)
42
+ desc.endpoint = args.endpoint;
43
+ if (args.authType !== undefined)
44
+ desc.authType = args.authType;
45
+ if (args.authEnvVar !== undefined)
46
+ desc.authEnvVar = args.authEnvVar;
47
+ if (args.cliBinary !== undefined)
48
+ desc.cliBinary = args.cliBinary;
49
+ if (args.pythonModule !== undefined)
50
+ desc.pythonModule = args.pythonModule;
51
+ if (args.capabilities !== undefined)
52
+ desc.capabilities = args.capabilities;
53
+ if (args.userPreferredRoute !== undefined)
54
+ desc.userPreferredRoute = args.userPreferredRoute;
55
+ return desc;
56
+ }
57
+ export const pluginsFactoryTool = {
58
+ schema: {
59
+ name: 'plugins_factory',
60
+ description: 'Assess, compare token costs, and scaffold custom plugins, Python bridges, or MCP servers for external services or APIs that are not yet integrated into Causyne. Recommends the leanest, most economical route (Native Plugin or Python Bridge) while honoring user choice if MCP is preferred.',
61
+ parameters: {
62
+ type: 'object',
63
+ properties: {
64
+ action: {
65
+ type: 'string',
66
+ enum: ['assess', 'estimate_cost', 'scaffold'],
67
+ description: 'Action: "assess" evaluates routes and returns proposal with token costs; "estimate_cost" returns detailed token footprint; "scaffold" creates the files in ~/.causyne/.'
68
+ },
69
+ serviceName: {
70
+ type: 'string',
71
+ description: 'Name of the service or plugin (lowercase alphanumeric and hyphens, e.g. "notion-api", "blender-cycles").'
72
+ },
73
+ serviceDescription: {
74
+ type: 'string',
75
+ description: 'Overview of what the external service does and why the integration is needed.'
76
+ },
77
+ serviceKind: {
78
+ type: 'string',
79
+ enum: ['http_api', 'cli', 'python_sdk', 'mcp_only', 'custom'],
80
+ description: 'Nature of the target service.'
81
+ },
82
+ endpoint: {
83
+ type: 'string',
84
+ description: 'Base URL for HTTP APIs (e.g. "https://api.github.com").'
85
+ },
86
+ authType: {
87
+ type: 'string',
88
+ enum: ['none', 'bearer', 'apiKey', 'basic', 'env'],
89
+ description: 'Authentication scheme.'
90
+ },
91
+ authEnvVar: {
92
+ type: 'string',
93
+ description: 'Environment variable name holding the API token (e.g. "NOTION_API_KEY").'
94
+ },
95
+ cliBinary: {
96
+ type: 'string',
97
+ description: 'Binary executable name for CLI plugins (e.g. "ffmpeg", "yt-dlp").'
98
+ },
99
+ pythonModule: {
100
+ type: 'string',
101
+ description: 'Python package/module name for Python bridges (e.g. "bpy", "torch").'
102
+ },
103
+ tools: {
104
+ type: 'array',
105
+ items: {
106
+ type: 'object',
107
+ properties: {
108
+ name: { type: 'string', description: 'Tool name' },
109
+ description: { type: 'string', description: 'What the tool does' },
110
+ parameters: { type: 'object', description: 'JSON schema for tool parameters' },
111
+ httpMethod: { type: 'string', enum: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'] },
112
+ httpPath: { type: 'string', description: 'HTTP relative path' },
113
+ cliSubcommand: { type: 'string', description: 'Subcommand for CLI tools' },
114
+ pythonMethod: { type: 'string', description: 'Method name in Python bridge' }
115
+ },
116
+ required: ['name', 'description']
117
+ },
118
+ description: 'List of tools to expose to the agent.'
119
+ },
120
+ capabilities: {
121
+ type: 'array',
122
+ items: {
123
+ type: 'string',
124
+ enum: ['workspace:read', 'workspace:write', 'network', 'subprocess']
125
+ },
126
+ description: 'Host sandbox permissions required.'
127
+ },
128
+ userPreferredRoute: {
129
+ type: 'string',
130
+ enum: ['native_plugin', 'python_bridge', 'mcp_server'],
131
+ description: 'Explicit user route preference (e.g. user insists on MCP).'
132
+ },
133
+ force: {
134
+ type: 'boolean',
135
+ description: 'Overwrite existing directory if present.'
136
+ },
137
+ dryRun: {
138
+ type: 'boolean',
139
+ description: 'Simulate scaffolding without writing files.'
140
+ }
141
+ },
142
+ required: ['action', 'serviceName']
143
+ }
144
+ },
145
+ async execute(args) {
146
+ try {
147
+ if (!args || !args.action || !args.serviceName) {
148
+ return {
149
+ success: false,
150
+ action: args?.action || 'unknown',
151
+ error: 'Missing required arguments: "action" and "serviceName" are required.'
152
+ };
153
+ }
154
+ const factory = new PluginsFactory();
155
+ const service = normalizeServiceDescriptor(args);
156
+ const proposal = factory.assess(service, args.userPreferredRoute);
157
+ if (args.action === 'assess' || args.action === 'estimate_cost') {
158
+ const res = {
159
+ success: true,
160
+ action: args.action,
161
+ proposal,
162
+ message: [
163
+ `Assessment complete for service '${service.name}'.`,
164
+ `Recommended Route: ${proposal.recommendedRoute} (${proposal.reason})`,
165
+ proposal.mcpDisclosure ? `\n${proposal.mcpDisclosure}` : ''
166
+ ].filter(Boolean).join('\n')
167
+ };
168
+ return res;
169
+ }
170
+ if (args.action === 'scaffold') {
171
+ const scaffoldOpts = {};
172
+ if (args.force !== undefined)
173
+ scaffoldOpts.force = args.force;
174
+ if (args.dryRun !== undefined)
175
+ scaffoldOpts.dryRun = args.dryRun;
176
+ const scaffoldResult = await factory.scaffold(proposal, scaffoldOpts);
177
+ const res = {
178
+ success: scaffoldResult.success,
179
+ action: 'scaffold',
180
+ proposal,
181
+ scaffoldResult,
182
+ message: scaffoldResult.instructions
183
+ };
184
+ if (scaffoldResult.error !== undefined)
185
+ res.error = scaffoldResult.error;
186
+ return res;
187
+ }
188
+ return {
189
+ success: false,
190
+ action: args.action,
191
+ error: `Unrecognized action: "${args.action}". Allowed: assess, estimate_cost, scaffold`
192
+ };
193
+ }
194
+ catch (err) {
195
+ return {
196
+ success: false,
197
+ action: args?.action || 'execute',
198
+ error: err instanceof Error ? err.message : String(err)
199
+ };
200
+ }
201
+ }
202
+ };
@@ -0,0 +1,246 @@
1
+ /**
2
+ * plugins_factory Tool for Causyne Agent.
3
+ *
4
+ * Implements autonomous custom integration evaluation and scaffolding.
5
+ * Recommends token-lean native plugins or Python bridges, while fully respecting
6
+ * user choices if MCP is preferred.
7
+ */
8
+
9
+ import {
10
+ PluginsFactory,
11
+ type FactoryRouteProposal,
12
+ type RouteKind,
13
+ type ScaffoldOptions,
14
+ type ScaffoldResult,
15
+ type ServiceDescriptor,
16
+ type ServiceKind,
17
+ type ServiceToolDescriptor
18
+ } from '../pluginsFactory/index.js';
19
+
20
+ export interface PluginsFactoryArgs {
21
+ action: 'assess' | 'estimate_cost' | 'scaffold';
22
+ serviceName: string;
23
+ serviceDescription?: string | undefined;
24
+ serviceKind?: ServiceKind | undefined;
25
+ endpoint?: string | undefined;
26
+ authType?: 'none' | 'bearer' | 'apiKey' | 'basic' | 'env' | undefined;
27
+ authEnvVar?: string | undefined;
28
+ cliBinary?: string | undefined;
29
+ pythonModule?: string | undefined;
30
+ tools?: Array<{
31
+ name: string;
32
+ description: string;
33
+ parameters?: Record<string, unknown> | undefined;
34
+ httpMethod?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | undefined;
35
+ httpPath?: string | undefined;
36
+ cliSubcommand?: string | undefined;
37
+ pythonMethod?: string | undefined;
38
+ }> | undefined;
39
+ capabilities?: Array<'workspace:read' | 'workspace:write' | 'network' | 'subprocess'> | undefined;
40
+ userPreferredRoute?: RouteKind | undefined;
41
+ force?: boolean | undefined;
42
+ dryRun?: boolean | undefined;
43
+ }
44
+
45
+ export interface PluginsFactoryToolResult {
46
+ success: boolean;
47
+ action: string;
48
+ proposal?: FactoryRouteProposal | undefined;
49
+ scaffoldResult?: ScaffoldResult | undefined;
50
+ message?: string | undefined;
51
+ error?: string | undefined;
52
+ }
53
+
54
+ function normalizeServiceDescriptor(args: PluginsFactoryArgs): ServiceDescriptor {
55
+ const tools: ServiceToolDescriptor[] = (args.tools || []).map((t, idx) => {
56
+ const tool: ServiceToolDescriptor = {
57
+ name: t.name || `tool_${idx + 1}`,
58
+ description: t.description || `Tool ${t.name || idx + 1}`,
59
+ parameters: (t.parameters && typeof t.parameters === 'object' && t.parameters.type === 'object')
60
+ ? (t.parameters as ServiceToolDescriptor['parameters'])
61
+ : { type: 'object', properties: {} }
62
+ };
63
+ if (t.httpMethod !== undefined) tool.httpMethod = t.httpMethod;
64
+ if (t.httpPath !== undefined) tool.httpPath = t.httpPath;
65
+ if (t.cliSubcommand !== undefined) tool.cliSubcommand = t.cliSubcommand;
66
+ if (t.pythonMethod !== undefined) tool.pythonMethod = t.pythonMethod;
67
+ return tool;
68
+ });
69
+
70
+ if (tools.length === 0) {
71
+ tools.push({
72
+ name: 'execute',
73
+ description: `Default execution method for ${args.serviceName}`,
74
+ parameters: { type: 'object', properties: {} }
75
+ });
76
+ }
77
+
78
+ const desc: ServiceDescriptor = {
79
+ name: args.serviceName,
80
+ description: args.serviceDescription || `Custom integration for ${args.serviceName}`,
81
+ serviceKind: args.serviceKind || 'custom',
82
+ tools
83
+ };
84
+
85
+ if (args.endpoint !== undefined) desc.endpoint = args.endpoint;
86
+ if (args.authType !== undefined) desc.authType = args.authType;
87
+ if (args.authEnvVar !== undefined) desc.authEnvVar = args.authEnvVar;
88
+ if (args.cliBinary !== undefined) desc.cliBinary = args.cliBinary;
89
+ if (args.pythonModule !== undefined) desc.pythonModule = args.pythonModule;
90
+ if (args.capabilities !== undefined) desc.capabilities = args.capabilities;
91
+ if (args.userPreferredRoute !== undefined) desc.userPreferredRoute = args.userPreferredRoute;
92
+
93
+ return desc;
94
+ }
95
+
96
+ export const pluginsFactoryTool = {
97
+ schema: {
98
+ name: 'plugins_factory',
99
+ description:
100
+ 'Assess, compare token costs, and scaffold custom plugins, Python bridges, or MCP servers for external services or APIs that are not yet integrated into Causyne. Recommends the leanest, most economical route (Native Plugin or Python Bridge) while honoring user choice if MCP is preferred.',
101
+ parameters: {
102
+ type: 'object',
103
+ properties: {
104
+ action: {
105
+ type: 'string',
106
+ enum: ['assess', 'estimate_cost', 'scaffold'],
107
+ description:
108
+ 'Action: "assess" evaluates routes and returns proposal with token costs; "estimate_cost" returns detailed token footprint; "scaffold" creates the files in ~/.causyne/.'
109
+ },
110
+ serviceName: {
111
+ type: 'string',
112
+ description: 'Name of the service or plugin (lowercase alphanumeric and hyphens, e.g. "notion-api", "blender-cycles").'
113
+ },
114
+ serviceDescription: {
115
+ type: 'string',
116
+ description: 'Overview of what the external service does and why the integration is needed.'
117
+ },
118
+ serviceKind: {
119
+ type: 'string',
120
+ enum: ['http_api', 'cli', 'python_sdk', 'mcp_only', 'custom'],
121
+ description: 'Nature of the target service.'
122
+ },
123
+ endpoint: {
124
+ type: 'string',
125
+ description: 'Base URL for HTTP APIs (e.g. "https://api.github.com").'
126
+ },
127
+ authType: {
128
+ type: 'string',
129
+ enum: ['none', 'bearer', 'apiKey', 'basic', 'env'],
130
+ description: 'Authentication scheme.'
131
+ },
132
+ authEnvVar: {
133
+ type: 'string',
134
+ description: 'Environment variable name holding the API token (e.g. "NOTION_API_KEY").'
135
+ },
136
+ cliBinary: {
137
+ type: 'string',
138
+ description: 'Binary executable name for CLI plugins (e.g. "ffmpeg", "yt-dlp").'
139
+ },
140
+ pythonModule: {
141
+ type: 'string',
142
+ description: 'Python package/module name for Python bridges (e.g. "bpy", "torch").'
143
+ },
144
+ tools: {
145
+ type: 'array',
146
+ items: {
147
+ type: 'object',
148
+ properties: {
149
+ name: { type: 'string', description: 'Tool name' },
150
+ description: { type: 'string', description: 'What the tool does' },
151
+ parameters: { type: 'object', description: 'JSON schema for tool parameters' },
152
+ httpMethod: { type: 'string', enum: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'] },
153
+ httpPath: { type: 'string', description: 'HTTP relative path' },
154
+ cliSubcommand: { type: 'string', description: 'Subcommand for CLI tools' },
155
+ pythonMethod: { type: 'string', description: 'Method name in Python bridge' }
156
+ },
157
+ required: ['name', 'description']
158
+ },
159
+ description: 'List of tools to expose to the agent.'
160
+ },
161
+ capabilities: {
162
+ type: 'array',
163
+ items: {
164
+ type: 'string',
165
+ enum: ['workspace:read', 'workspace:write', 'network', 'subprocess']
166
+ },
167
+ description: 'Host sandbox permissions required.'
168
+ },
169
+ userPreferredRoute: {
170
+ type: 'string',
171
+ enum: ['native_plugin', 'python_bridge', 'mcp_server'],
172
+ description: 'Explicit user route preference (e.g. user insists on MCP).'
173
+ },
174
+ force: {
175
+ type: 'boolean',
176
+ description: 'Overwrite existing directory if present.'
177
+ },
178
+ dryRun: {
179
+ type: 'boolean',
180
+ description: 'Simulate scaffolding without writing files.'
181
+ }
182
+ },
183
+ required: ['action', 'serviceName']
184
+ }
185
+ },
186
+
187
+ async execute(args: PluginsFactoryArgs): Promise<PluginsFactoryToolResult> {
188
+ try {
189
+ if (!args || !args.action || !args.serviceName) {
190
+ return {
191
+ success: false,
192
+ action: args?.action || 'unknown',
193
+ error: 'Missing required arguments: "action" and "serviceName" are required.'
194
+ };
195
+ }
196
+
197
+ const factory = new PluginsFactory();
198
+ const service = normalizeServiceDescriptor(args);
199
+ const proposal = factory.assess(service, args.userPreferredRoute);
200
+
201
+ if (args.action === 'assess' || args.action === 'estimate_cost') {
202
+ const res: PluginsFactoryToolResult = {
203
+ success: true,
204
+ action: args.action,
205
+ proposal,
206
+ message: [
207
+ `Assessment complete for service '${service.name}'.`,
208
+ `Recommended Route: ${proposal.recommendedRoute} (${proposal.reason})`,
209
+ proposal.mcpDisclosure ? `\n${proposal.mcpDisclosure}` : ''
210
+ ].filter(Boolean).join('\n')
211
+ };
212
+ return res;
213
+ }
214
+
215
+ if (args.action === 'scaffold') {
216
+ const scaffoldOpts: ScaffoldOptions = {};
217
+ if (args.force !== undefined) scaffoldOpts.force = args.force;
218
+ if (args.dryRun !== undefined) scaffoldOpts.dryRun = args.dryRun;
219
+
220
+ const scaffoldResult = await factory.scaffold(proposal, scaffoldOpts);
221
+
222
+ const res: PluginsFactoryToolResult = {
223
+ success: scaffoldResult.success,
224
+ action: 'scaffold',
225
+ proposal,
226
+ scaffoldResult,
227
+ message: scaffoldResult.instructions
228
+ };
229
+ if (scaffoldResult.error !== undefined) res.error = scaffoldResult.error;
230
+ return res;
231
+ }
232
+
233
+ return {
234
+ success: false,
235
+ action: args.action,
236
+ error: `Unrecognized action: "${args.action}". Allowed: assess, estimate_cost, scaffold`
237
+ };
238
+ } catch (err) {
239
+ return {
240
+ success: false,
241
+ action: args?.action || 'execute',
242
+ error: err instanceof Error ? err.message : String(err)
243
+ };
244
+ }
245
+ }
246
+ };
@@ -44,6 +44,7 @@ import { memoryRecall } from './memoryRecall.js';
44
44
  import { printerPrint, printerList, printerStatus } from './printer.js';
45
45
  import { toolForgeTool } from './toolForge.js';
46
46
  import { pluginManagerTool } from './pluginManager.js';
47
+ import { pluginsFactoryTool } from './pluginsFactory.js';
47
48
  import { astryxOracle } from './astryxOracle.js';
48
49
  import { pdfRead } from './pdfReader.js';
49
50
  import { codeVerifySyntax, codeListSymbols } from './codeTools.js';
@@ -120,7 +121,7 @@ const TOOL_MODULES = [
120
121
  codebaseSearch, browserAct, viewImage, webSearch,
121
122
  updatePlan, requestDecision, clipboard, screenshot, axSnapshot, desktopAct, archive,
122
123
  checkSystemSpecs, executeProceduralMedia, manageLocalAiDependencies,
123
- generateMediaViaApi, memoryWrite, memoryRecall, printerPrint, printerList, printerStatus, toolForgeTool, pluginManagerTool,
124
+ generateMediaViaApi, memoryWrite, memoryRecall, printerPrint, printerList, printerStatus, toolForgeTool, pluginManagerTool, pluginsFactoryTool,
124
125
  astryxOracle, pdfRead, codeVerifySyntax, codeListSymbols, blenderAct, resolveAutomator, palmierAutomator,
125
126
  codeSearchAst, codeSearcher, persistentShell, subagentOrchestrator, deferredMcpSearch, visionInspector,
126
127
  godotAutomator, gameBuilder, gameAssetFetcher,
@@ -29,9 +29,11 @@ export function stripAnsi(str) {
29
29
  * transient progress meters (curl, wget) so agent history and split-panes never glitch.
30
30
  */
31
31
  export function cleanSubprocessOutput(str) {
32
- const normalized = stripAnsi(str)
32
+ const preSplit = str.replace(/\x1b\[(?:[12]K|\d*G)/g, '\n');
33
+ const normalized = stripAnsi(preSplit)
33
34
  .replace(/\r\n/g, '\n')
34
- .replace(/\r/g, '\n');
35
+ .replace(/\r/g, '\n')
36
+ .replace(/(https?:\/\/[^\s"'<>]+?\.[a-z]{2,10})([A-Z][a-z]{2,15}:\s)/g, '$1\n$2');
35
37
  return normalized
36
38
  .split('\n')
37
39
  .filter(line => !/^\s*(?:%\s+Total\b|Dload\s+Upload\b|\d+\s+\d+(?:\.[0-9kKmM]+)?\s+\d+\s+.*--:--:--)/i.test(line))
@@ -314,15 +316,29 @@ export const sysRun = {
314
316
  }
315
317
  }
316
318
  };
317
- const appendToBuffer = (data) => {
318
- outputBuffer += data.toString();
319
+ let lastStream = null;
320
+ const appendToBuffer = (stream, data) => {
321
+ const chunk = data.toString();
322
+ if (!chunk)
323
+ return;
324
+ if (lastStream !== null &&
325
+ lastStream !== stream &&
326
+ outputBuffer.length > 0 &&
327
+ !outputBuffer.endsWith('\n') &&
328
+ !outputBuffer.endsWith('\r') &&
329
+ !chunk.startsWith('\n') &&
330
+ !chunk.startsWith('\r')) {
331
+ outputBuffer += '\n';
332
+ }
333
+ lastStream = stream;
334
+ outputBuffer += chunk;
319
335
  if (outputBuffer.length > MAX_LENGTH) {
320
336
  outputBuffer = '...[OUTPUT TRUNCATED]...\n' + outputBuffer.slice(outputBuffer.length - MAX_LENGTH);
321
337
  }
322
338
  checkServerDetach();
323
339
  };
324
- child.stdout?.on('data', appendToBuffer);
325
- child.stderr?.on('data', appendToBuffer);
340
+ child.stdout?.on('data', (d) => appendToBuffer('stdout', d));
341
+ child.stderr?.on('data', (d) => appendToBuffer('stderr', d));
326
342
  let serverGraceTimer;
327
343
  if (isPersistentServerCommand(rawCommand)) {
328
344
  serverGraceTimer = setTimeout(() => {