@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
@@ -7,84 +7,185 @@
7
7
  * 3. Python Bridge Plugin (Lightweight JSON stdio bridge for Python libraries)
8
8
  * 4. Stdio MCP Server (Zero-dependency JSON-RPC 2.0 stdio daemon compliant with MCP spec)
9
9
  */
10
+ /**
11
+ * Words that cannot be used as a generated export binding. Modules are always
12
+ * strict, so `delete`, `default`, `eval`, `arguments`, and friends would make
13
+ * the generated module fail to parse.
14
+ */
15
+ const RESERVED_IDENTIFIERS = new Set([
16
+ 'arguments', 'await', 'break', 'case', 'catch', 'class', 'const', 'continue',
17
+ 'debugger', 'default', 'delete', 'do', 'else', 'enum', 'eval', 'export',
18
+ 'extends', 'false', 'finally', 'for', 'function', 'if', 'implements',
19
+ 'import', 'in', 'instanceof', 'interface', 'let', 'new', 'null', 'package',
20
+ 'private', 'protected', 'public', 'return', 'static', 'super', 'switch',
21
+ 'this', 'throw', 'true', 'try', 'typeof', 'var', 'void', 'while', 'with',
22
+ 'yield'
23
+ ]);
24
+ /**
25
+ * Quotes a value for safe display inside a POSIX shell command line.
26
+ */
27
+ export function shellQuote(value) {
28
+ return `'${value.replace(/'/g, "'\\''")}'`;
29
+ }
10
30
  /**
11
31
  * Sanitizes an arbitrary tool or parameter name into a valid JavaScript identifier.
12
32
  * Prevents syntax errors when tools contain hyphens (e.g. "get-weather" -> "get_weather").
13
33
  */
14
34
  export function sanitizeIdentifier(name) {
15
35
  const cleaned = name.replace(/[^a-zA-Z0-9_]/g, '_');
16
- return /^[0-9]/.test(cleaned) ? `_${cleaned}` : (cleaned || 'fn');
36
+ const identifier = /^[0-9]/.test(cleaned) ? `_${cleaned}` : (cleaned || 'fn');
37
+ return RESERVED_IDENTIFIERS.has(identifier) ? `${identifier}_` : identifier;
17
38
  }
18
39
  /**
19
- * Computes the canonical export name for a tool within an index.js ES module.
20
- * The primary tool is always exported as "execute" (the default runner contract).
21
- * Additional tools are exported with their sanitized identifier.
40
+ * Keeps user-supplied text inside a generated comment. A description that
41
+ * contains a comment terminator would otherwise escape the docblock and run
42
+ * as generated JavaScript.
22
43
  */
23
- function getExportName(tool, index) {
24
- if (index === 0)
25
- return 'execute';
26
- return sanitizeIdentifier(tool.name);
44
+ export function sanitizeComment(text) {
45
+ return String(text ?? '')
46
+ .replace(/\*\//g, '*\\/')
47
+ .replace(/[\u0000-\u001f\u007f]/g, ' ')
48
+ .trim();
49
+ }
50
+ /**
51
+ * Keeps user-supplied text inert inside generated Python comments and
52
+ * docstrings. Newlines would start a new statement, a triple quote would end
53
+ * the docstring early, and a trailing backslash would escape its delimiter.
54
+ */
55
+ export function sanitizePythonText(text) {
56
+ return String(text ?? '')
57
+ .replace(/\\/g, '\\\\')
58
+ .replace(/"""/g, "'''")
59
+ .replace(/[\u0000-\u001f\u007f]/g, ' ')
60
+ .trim();
61
+ }
62
+ /**
63
+ * Computes canonical export names for every tool in a module.
64
+ * The primary tool is always exported as "execute" (the default runner
65
+ * contract). Additional tools receive sanitized identifiers, disambiguated
66
+ * when two tool names collapse to the same binding (e.g. "get-user" and
67
+ * "get_user").
68
+ */
69
+ function buildExportNames(tools) {
70
+ const used = new Set(['execute']);
71
+ return tools.map((tool, index) => {
72
+ if (index === 0)
73
+ return 'execute';
74
+ const base = sanitizeIdentifier(tool.name);
75
+ let name = base;
76
+ let suffix = 2;
77
+ while (used.has(name))
78
+ name = `${base}_${suffix++}`;
79
+ used.add(name);
80
+ return name;
81
+ });
82
+ }
83
+ /**
84
+ * Builds the generated auth setup. The env var keeps the secret out of the
85
+ * manifest while authType selects the header shape the API expects.
86
+ */
87
+ function buildAuthSetup(service) {
88
+ if (!service.authEnvVar || service.authType === 'none') {
89
+ return 'const authHeader = undefined;';
90
+ }
91
+ const envAccess = `process.env[${JSON.stringify(service.authEnvVar)}]`;
92
+ const authType = service.authType || 'bearer';
93
+ let headerName = 'Authorization';
94
+ let valueExpression;
95
+ if (authType === 'basic') {
96
+ valueExpression = `\`Basic \${Buffer.from(${envAccess}).toString('base64')}\``;
97
+ }
98
+ else if (authType === 'apiKey') {
99
+ headerName = 'X-API-Key';
100
+ valueExpression = envAccess;
101
+ }
102
+ else if (authType === 'env') {
103
+ valueExpression = envAccess;
104
+ }
105
+ else {
106
+ valueExpression = `\`Bearer \${${envAccess}}\``;
107
+ }
108
+ return `const authHeader = ${envAccess} ? { name: ${JSON.stringify(headerName)}, value: ${valueExpression} } : undefined;`;
27
109
  }
28
110
  /**
29
111
  * Generates scaffold files for a Native HTTP Plugin.
30
112
  */
31
113
  export function generateHttpPluginScaffold(service) {
32
114
  const capabilities = Array.from(new Set(['network', ...(service.capabilities || [])]));
33
- const primaryTool = service.tools[0] || {
34
- name: 'query',
35
- description: `Execute request against ${service.name}`,
36
- parameters: { type: 'object', properties: {} }
37
- };
115
+ const effectiveTools = service.tools.length > 0 ? service.tools : [{
116
+ name: 'query',
117
+ description: `Execute request against ${service.name}`,
118
+ parameters: { type: 'object', properties: {} }
119
+ }];
120
+ const exportNames = buildExportNames(effectiveTools);
38
121
  const manifest = {
39
122
  schemaVersion: 1,
40
123
  name: service.name,
41
124
  version: '1.0.0',
42
125
  description: service.description || `Native HTTP plugin for ${service.name}`,
43
126
  capabilities,
44
- tools: service.tools.map((tool, idx) => ({
127
+ tools: effectiveTools.map((tool, idx) => ({
45
128
  name: tool.name,
46
129
  description: tool.description,
47
130
  parameters: tool.parameters,
48
131
  entry: 'index.js',
49
- export: getExportName(tool, idx),
132
+ export: exportNames[idx],
50
133
  timeoutMs: 30000
51
134
  }))
52
135
  };
53
- const toolExecutors = service.tools.map((tool, idx) => {
54
- const fnName = getExportName(tool, idx);
136
+ const toolExecutors = effectiveTools.map((tool, idx) => {
137
+ const fnName = exportNames[idx];
55
138
  const httpMethod = tool.httpMethod || 'POST';
56
139
  const httpPath = tool.httpPath || '/';
57
140
  return `
58
141
  /**
59
- * ${tool.description}
142
+ * ${sanitizeComment(tool.description)}
60
143
  */
61
144
  export async function ${fnName}(args = {}, context = {}) {
62
145
  const endpoint = ${JSON.stringify(service.endpoint || 'https://api.example.com')};
63
146
  const base = endpoint.endsWith('/') ? endpoint : endpoint + '/';
64
- const rel = ${JSON.stringify(httpPath)}.startsWith('/') ? ${JSON.stringify(httpPath)}.slice(1) : ${JSON.stringify(httpPath)};
65
- const url = new URL(rel, base);
147
+ const rawPath = ${JSON.stringify(httpPath)};
148
+ const pathParamNames = Array.from(rawPath.matchAll(/\\{([^}]+)\\}/g), match => match[1]);
149
+ const requestArgs = args && typeof args === 'object' ? { ...args } : {};
150
+ const missingPathParams = pathParamNames.filter(key => requestArgs[key] === undefined || requestArgs[key] === null);
151
+ if (missingPathParams.length > 0) {
152
+ return { success: false, error: \`Missing path parameter(s): \${missingPathParams.join(', ')}\` };
153
+ }
154
+ let url;
155
+ try {
156
+ const rel = rawPath.replace(/\\{([^}]+)\\}/g, (_match, key) => encodeURIComponent(String(requestArgs[key])));
157
+ for (const key of pathParamNames) delete requestArgs[key];
158
+ const targetPath = rel.startsWith('/') ? rel.slice(1) : rel;
159
+ url = new URL(targetPath, base);
160
+ } catch (err) {
161
+ return { success: false, error: \`Invalid request URL: \${err instanceof Error ? err.message : String(err)}\` };
162
+ }
66
163
 
67
- if (${JSON.stringify(httpMethod)} === 'GET' && args && typeof args === 'object') {
68
- for (const [k, v] of Object.entries(args)) {
69
- if (v !== undefined && v !== null) url.searchParams.append(k, String(v));
70
- }
164
+ if (${JSON.stringify(httpMethod)} === 'GET' && requestArgs && typeof requestArgs === 'object') {
165
+ const appendQuery = (key, value) => {
166
+ if (value === undefined || value === null) return;
167
+ if (Array.isArray(value)) {
168
+ for (const item of value) appendQuery(key, item);
169
+ return;
170
+ }
171
+ url.searchParams.append(key, typeof value === 'object' ? JSON.stringify(value) : String(value));
172
+ };
173
+ for (const [k, v] of Object.entries(requestArgs)) appendQuery(k, v);
71
174
  }
72
175
 
73
- const authHeader = ${service.authEnvVar
74
- ? `process.env[${JSON.stringify(service.authEnvVar)}] ? \`Bearer \${process.env[${JSON.stringify(service.authEnvVar)}]}\` : undefined`
75
- : 'undefined'};
176
+ ${buildAuthSetup(service)}
76
177
 
77
178
  const headers = {
78
179
  'Accept': 'application/json',
79
180
  'Content-Type': 'application/json'
80
181
  };
81
- if (authHeader) headers['Authorization'] = authHeader;
182
+ if (authHeader) headers[authHeader.name] = authHeader.value;
82
183
 
83
184
  try {
84
185
  const response = await fetch(url.toString(), {
85
186
  method: ${JSON.stringify(httpMethod)},
86
187
  headers,
87
- body: ${httpMethod !== 'GET' ? 'JSON.stringify(args)' : 'undefined'}
188
+ body: ${httpMethod !== 'GET' ? 'JSON.stringify(requestArgs)' : 'undefined'}
88
189
  });
89
190
 
90
191
  if (!response.ok) {
@@ -128,7 +229,7 @@ ${service.authEnvVar ? `- **Environment Variable**: Set \`${service.authEnvVar}\
128
229
  By default, this plugin is created in a **disabled** state to allow code review.
129
230
  To activate after reviewing the code:
130
231
  \`\`\`bash
131
- causyne plugins enable ${service.name}
232
+ /plugins enable ${service.name}
132
233
  \`\`\`
133
234
  `;
134
235
  return {
@@ -145,32 +246,33 @@ causyne plugins enable ${service.name}
145
246
  */
146
247
  export function generateCliPluginScaffold(service) {
147
248
  const capabilities = Array.from(new Set(['subprocess', ...(service.capabilities || [])]));
148
- const primaryTool = service.tools[0] || {
149
- name: 'run',
150
- description: `Execute command for ${service.name}`,
151
- parameters: { type: 'object', properties: {} }
152
- };
249
+ const effectiveTools = service.tools.length > 0 ? service.tools : [{
250
+ name: 'run',
251
+ description: `Execute command for ${service.name}`,
252
+ parameters: { type: 'object', properties: {} }
253
+ }];
254
+ const exportNames = buildExportNames(effectiveTools);
153
255
  const manifest = {
154
256
  schemaVersion: 1,
155
257
  name: service.name,
156
258
  version: '1.0.0',
157
259
  description: service.description || `Native CLI plugin for ${service.name}`,
158
260
  capabilities,
159
- tools: service.tools.map((tool, idx) => ({
261
+ tools: effectiveTools.map((tool, idx) => ({
160
262
  name: tool.name,
161
263
  description: tool.description,
162
264
  parameters: tool.parameters,
163
265
  entry: 'index.js',
164
- export: getExportName(tool, idx),
266
+ export: exportNames[idx],
165
267
  timeoutMs: 45000
166
268
  }))
167
269
  };
168
- const toolExecutors = service.tools.map((tool, idx) => {
169
- const fnName = getExportName(tool, idx);
270
+ const toolExecutors = effectiveTools.map((tool, idx) => {
271
+ const fnName = exportNames[idx];
170
272
  const binary = service.cliBinary || service.name;
171
273
  return `
172
274
  /**
173
- * ${tool.description}
275
+ * ${sanitizeComment(tool.description)}
174
276
  */
175
277
  export async function ${fnName}(args = {}, context = {}) {
176
278
  const { execFile } = await import('node:child_process');
@@ -179,7 +281,7 @@ export async function ${fnName}(args = {}, context = {}) {
179
281
 
180
282
  const bin = ${JSON.stringify(binary)};
181
283
  const cliArgs = [];
182
- ${tool.cliSubcommand ? `cliArgs.push(${JSON.stringify(tool.cliSubcommand)});` : ''}
284
+ ${tool.cliSubcommand ? `cliArgs.push(...${JSON.stringify(tool.cliSubcommand)}.split(/\\s+/).filter(Boolean));` : ''}
183
285
 
184
286
  for (const [key, val] of Object.entries(args || {})) {
185
287
  if (val === true) cliArgs.push(\`--\${key}\`);
@@ -229,7 +331,7 @@ ${service.description}
229
331
  ## Security & Activation
230
332
  This plugin is created disabled. After verifying the source code:
231
333
  \`\`\`bash
232
- causyne plugins enable ${service.name}
334
+ /plugins enable ${service.name}
233
335
  \`\`\`
234
336
  `;
235
337
  return {
@@ -247,32 +349,33 @@ causyne plugins enable ${service.name}
247
349
  */
248
350
  export function generatePythonBridgeScaffold(service) {
249
351
  const capabilities = Array.from(new Set(['subprocess', ...(service.capabilities || [])]));
250
- const primaryTool = service.tools[0] || {
251
- name: 'run_python',
252
- description: `Execute Python workflow for ${service.name}`,
253
- parameters: { type: 'object', properties: {} }
254
- };
352
+ const effectiveTools = service.tools.length > 0 ? service.tools : [{
353
+ name: 'run_python',
354
+ description: `Execute Python workflow for ${service.name}`,
355
+ parameters: { type: 'object', properties: {} }
356
+ }];
357
+ const exportNames = buildExportNames(effectiveTools);
255
358
  const manifest = {
256
359
  schemaVersion: 1,
257
360
  name: service.name,
258
361
  version: '1.0.0',
259
362
  description: service.description || `Python bridge plugin for ${service.name}`,
260
363
  capabilities,
261
- tools: service.tools.map((tool, idx) => ({
364
+ tools: effectiveTools.map((tool, idx) => ({
262
365
  name: tool.name,
263
366
  description: tool.description,
264
367
  parameters: tool.parameters,
265
368
  entry: 'index.js',
266
- export: getExportName(tool, idx),
369
+ export: exportNames[idx],
267
370
  timeoutMs: 60000
268
371
  }))
269
372
  };
270
- const toolExecutors = service.tools.map((tool, idx) => {
271
- const fnName = getExportName(tool, idx);
373
+ const toolExecutors = effectiveTools.map((tool, idx) => {
374
+ const fnName = exportNames[idx];
272
375
  const pythonMethod = tool.pythonMethod || tool.name;
273
376
  return `
274
377
  /**
275
- * ${tool.description}
378
+ * ${sanitizeComment(tool.description)}
276
379
  */
277
380
  export async function ${fnName}(args = {}, context = {}) {
278
381
  return invokePythonBridge(${JSON.stringify(pythonMethod)}, args, context);
@@ -288,6 +391,7 @@ import { fileURLToPath } from 'node:url';
288
391
 
289
392
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
290
393
  const BRIDGE_SCRIPT = path.join(__dirname, 'bridge.py');
394
+ const PYTHON_BIN = process.env.CAUSYNE_PYTHON || (process.platform === 'win32' ? 'python' : 'python3');
291
395
 
292
396
  async function invokePythonBridge(action, args, context) {
293
397
  const payload = JSON.stringify({
@@ -299,7 +403,7 @@ async function invokePythonBridge(action, args, context) {
299
403
  });
300
404
 
301
405
  return new Promise((resolve) => {
302
- const child = spawn('python3', [BRIDGE_SCRIPT], {
406
+ const child = spawn(PYTHON_BIN, [BRIDGE_SCRIPT], {
303
407
  stdio: ['pipe', 'pipe', 'pipe'],
304
408
  env: { ...process.env, PYTHONUNBUFFERED: '1' }
305
409
  });
@@ -326,16 +430,23 @@ async function invokePythonBridge(action, args, context) {
326
430
  child.on('error', (err) => {
327
431
  finish({
328
432
  success: false,
329
- error: \`Failed to spawn python3: \${err.message}. Ensure python3 is installed and in PATH.\`
433
+ error: \`Failed to spawn \${PYTHON_BIN}: \${err.message}. Ensure Python 3 is installed and in PATH.\`
434
+ });
435
+ });
436
+
437
+ child.stdin.on('error', (err) => {
438
+ finish({
439
+ success: false,
440
+ error: \`Python bridge stdin error: \${err.message}\`
330
441
  });
331
442
  });
332
443
 
333
444
  child.on('close', (code) => {
334
- if (code !== 0 && !stdout.trim()) {
445
+ if (!stdout.trim()) {
335
446
  finish({
336
447
  success: false,
337
448
  exitCode: code,
338
- error: stderr.trim() || \`Python bridge exited with code \${code}\`
449
+ error: stderr.trim() || \`Python bridge returned no output (exit code \${code})\`
339
450
  });
340
451
  return;
341
452
  }
@@ -361,14 +472,16 @@ async function invokePythonBridge(action, args, context) {
361
472
  ${toolExecutors}
362
473
  `;
363
474
  const pythonModule = service.pythonModule || service.name;
475
+ const safeServiceName = sanitizePythonText(service.name);
476
+ const safePythonModule = sanitizePythonText(pythonModule);
364
477
  const bridgePy = `#!/usr/bin/env python3
365
478
  # -*- coding: utf-8 -*-
366
479
  """
367
- Python Bridge for ${service.name}
480
+ Python Bridge for ${safeServiceName}
368
481
  Auto-generated by Causyne PluginsFactory
369
482
 
370
483
  Communicates with Causyne Agent via JSON on stdin/stdout.
371
- Provides on-demand buffer for ${pythonModule}.
484
+ Provides on-demand buffer for ${safePythonModule}.
372
485
  """
373
486
 
374
487
  import sys
@@ -382,7 +495,7 @@ def handle_request(payload):
382
495
 
383
496
  try:
384
497
  # Dynamically reference target python module
385
- # import ${pythonModule}
498
+ # import ${safePythonModule}
386
499
 
387
500
  result = {
388
501
  "action": action,
@@ -439,7 +552,7 @@ python3 --version
439
552
  ## Security & Activation
440
553
  This plugin is created disabled. Review the code in \`bridge.py\` and \`index.js\`, then enable:
441
554
  \`\`\`bash
442
- causyne plugins enable ${service.name}
555
+ /plugins enable ${service.name}
443
556
  \`\`\`
444
557
  `;
445
558
  return {
@@ -495,6 +608,10 @@ function send(message) {
495
608
  function handleRequest(request) {
496
609
  const { id, method, params } = request;
497
610
 
611
+ // JSON-RPC notifications carry no id and must never receive a response,
612
+ // even when they use a request-style method such as tools/list.
613
+ if (id === undefined) return null;
614
+
498
615
  switch (method) {
499
616
  case 'initialize':
500
617
  return {
@@ -539,7 +656,7 @@ function handleRequest(request) {
539
656
  return {
540
657
  id,
541
658
  jsonrpc: '2.0',
542
- error: { code: -32601, message: \`Tool '\${toolName}' not found\` }
659
+ error: { code: -32602, message: \`Unknown tool: '\${toolName}'\` }
543
660
  };
544
661
  }
545
662
 
@@ -582,6 +699,10 @@ rl.on('line', (line) => {
582
699
  if (!trimmed) return;
583
700
  try {
584
701
  const request = JSON.parse(trimmed);
702
+ if (!request || typeof request !== 'object' || Array.isArray(request)) {
703
+ send({ jsonrpc: '2.0', id: null, error: { code: -32600, message: 'Invalid Request' } });
704
+ return;
705
+ }
585
706
  const response = handleRequest(request);
586
707
  if (response) send(response);
587
708
  } catch (err) {
@@ -609,7 +730,7 @@ Where feasible, prefer native plugins or Python bridges for higher token efficie
609
730
  ## Registration & Grant
610
731
  In Causyne Agent, register and review this server:
611
732
  \`\`\`bash
612
- causyne mcp add ${service.name} node ~/.causyne/mcp-servers/${service.name}/server.js
733
+ causyne mcp add ${service.name} node "$HOME/.causyne/mcp-servers/${service.name}/server.js"
613
734
  causyne mcp grant ${service.name}
614
735
  \`\`\`
615
736
  `;