@causyne/agent 1.20.111 → 1.20.116

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/docs/ARCHITECTURE.md +29 -0
  2. package/package.json +1 -1
  3. package/src/agentLoop.js +72 -37
  4. package/src/agentLoop.ts +70 -38
  5. package/src/browser/browserRuntime.js +13 -8
  6. package/src/browser/browserRuntime.ts +16 -8
  7. package/src/browser/causyneBrowser.js +7 -2
  8. package/src/browser/causyneBrowser.ts +8 -2
  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/computerUse/visionGrounding.js +31 -27
  18. package/src/computerUse/visionGrounding.ts +27 -27
  19. package/src/continuum/ui/continuumPicker.js +14 -6
  20. package/src/continuum/ui/continuumPicker.ts +13 -6
  21. package/src/continuum/ui/continuumPickerView.js +24 -15
  22. package/src/continuum/ui/continuumPickerView.ts +24 -16
  23. package/src/observer/advisory.js +32 -22
  24. package/src/observer/advisory.ts +30 -18
  25. package/src/observer/coldObserver.js +21 -33
  26. package/src/observer/coldObserver.ts +20 -33
  27. package/src/observer/evidence.js +20 -13
  28. package/src/observer/evidence.ts +21 -13
  29. package/src/observer.js +47 -12
  30. package/src/observer.ts +50 -18
  31. package/src/pluginsFactory/discovery.js +28 -16
  32. package/src/pluginsFactory/discovery.ts +29 -16
  33. package/src/pluginsFactory/pluginsFactory.js +213 -38
  34. package/src/pluginsFactory/pluginsFactory.ts +218 -39
  35. package/src/pluginsFactory/strategy.js +26 -16
  36. package/src/pluginsFactory/strategy.ts +34 -19
  37. package/src/pluginsFactory/templates.js +183 -62
  38. package/src/pluginsFactory/templates.ts +174 -54
  39. package/src/timeMachine.js +43 -22
  40. package/src/timeMachine.ts +44 -22
  41. package/src/tool-scripts/desktop_act.applescript +1 -0
  42. package/src/tools/computerUse.js +23 -10
  43. package/src/tools/computerUse.ts +19 -8
  44. package/src/tools/desktopAct.js +12 -1
  45. package/src/tools/pluginsFactory.js +108 -5
  46. package/src/tools/pluginsFactory.ts +115 -5
  47. package/src/tui/CausyneRotor.js +24 -10
  48. package/src/tui/CausyneRotor.ts +25 -10
  49. package/src/tui/activityLayout.js +9 -5
  50. package/src/tui/activityLayout.ts +9 -5
  51. package/src/tui/ask.js +34 -14
  52. package/src/tui/banner.js +55 -18
  53. package/src/tui/banner.ts +52 -17
  54. package/src/tui/block.js +47 -20
  55. package/src/tui/block.ts +54 -27
  56. package/src/tui/chatRenderer.js +135 -83
  57. package/src/tui/chatboxClipboard.js +12 -5
  58. package/src/tui/chatboxClipboard.ts +10 -4
  59. package/src/tui/clipboardImage.js +52 -42
  60. package/src/tui/clipboardImage.ts +50 -39
  61. package/src/tui/clipboardSync.js +12 -1
  62. package/src/tui/clipboardSync.ts +9 -1
  63. package/src/tui/codeProgress.js +57 -26
  64. package/src/tui/codeProgress.ts +57 -25
  65. package/src/tui/codeStreamRenderer.js +59 -14
  66. package/src/tui/codeStreamRenderer.ts +58 -14
  67. package/src/tui/commandPresentation.js +9 -2
  68. package/src/tui/commandPresentation.ts +9 -2
  69. package/src/tui/completion.js +45 -23
  70. package/src/tui/composerControls.js +21 -10
  71. package/src/tui/composerControls.ts +18 -10
  72. package/src/tui/composerGeometry.js +6 -4
  73. package/src/tui/composerGeometry.ts +6 -4
  74. package/src/tui/consoleGuard.js +29 -7
  75. package/src/tui/consoleGuard.ts +28 -7
  76. package/src/tui/dialogs.js +134 -71
  77. package/src/tui/diff.js +8 -4
  78. package/src/tui/history.js +6 -5
  79. package/src/tui/home.js +25 -13
  80. package/src/tui/homeView.js +37 -18
  81. package/src/tui/homeView.ts +38 -18
  82. package/src/tui/inlineSlash.js +6 -5
  83. package/src/tui/inlineSlash.ts +6 -5
  84. package/src/tui/keys.js +33 -17
  85. package/src/tui/layout.js +27 -9
  86. package/src/tui/layout.ts +26 -9
  87. package/src/tui/lineEditor.js +49 -23
  88. package/src/tui/markdownMath.js +64 -14
  89. package/src/tui/markdownMath.ts +69 -13
  90. package/src/tui/messageActionPlacement.js +28 -13
  91. package/src/tui/messageActionPlacement.ts +28 -13
  92. package/src/tui/messageInteraction.js +111 -46
  93. package/src/tui/messageInteraction.ts +115 -47
  94. package/src/tui/modelPicker.js +44 -15
  95. package/src/tui/modelPicker.ts +48 -15
  96. package/src/tui/observerPicker.js +56 -13
  97. package/src/tui/observerPicker.ts +73 -30
  98. package/src/tui/overlay.js +79 -35
  99. package/src/tui/overlay.ts +81 -34
  100. package/src/tui/prompt.js +162 -94
  101. package/src/tui/runningLight.js +1 -1
  102. package/src/tui/runningLight.ts +1 -1
  103. package/src/tui/scrollInteraction.js +64 -36
  104. package/src/tui/scrollInteraction.ts +70 -37
  105. package/src/tui/selectList.js +60 -32
  106. package/src/tui/sessionLayout.js +11 -3
  107. package/src/tui/sessionLayout.ts +10 -3
  108. package/src/tui/sessionPicker.js +74 -46
  109. package/src/tui/sessionPicker.ts +73 -48
  110. package/src/tui/sessionPickerView.js +32 -19
  111. package/src/tui/sessionPickerView.ts +31 -18
  112. package/src/tui/sessionSidebar.js +87 -57
  113. package/src/tui/sessionSidebar.ts +90 -54
  114. package/src/tui/setup.js +28 -3
  115. package/src/tui/setup.ts +27 -3
  116. package/src/tui/skillAuthoring.js +11 -5
  117. package/src/tui/skillAuthoring.ts +11 -5
  118. package/src/tui/smartLinkClick.js +75 -23
  119. package/src/tui/smartLinkClick.ts +86 -26
  120. package/src/tui/stage.js +47 -16
  121. package/src/tui/stage.ts +53 -18
  122. package/src/tui/stageSurface.js +120 -49
  123. package/src/tui/statusLine.js +85 -53
  124. package/src/tui/statusLine.ts +82 -46
  125. package/src/tui/terminalInputFramer.js +5 -2
  126. package/src/tui/text.js +117 -46
  127. package/src/tui/text.ts +113 -43
  128. package/src/tui/textLayout.js +6 -4
  129. package/src/tui/textLayout.ts +11 -5
  130. package/src/tui/theme.js +17 -8
  131. package/src/tui/thinkingBox.js +95 -95
  132. package/src/tui/thinkingBox.ts +105 -80
  133. package/src/tui/toolActivityPolicy.js +8 -1
  134. package/src/tui/toolActivityPolicy.ts +7 -1
  135. package/src/tui/toolDisplay.js +15 -6
  136. package/src/tui/toolDisplay.ts +16 -6
  137. package/src/tui/toolOutputNormalizer.js +16 -3
  138. package/src/tui/toolOutputNormalizer.ts +13 -3
  139. package/src/tui/transcript.js +15 -9
  140. package/src/tui/turnRail.js +156 -67
  141. package/src/tui/turnRail.ts +155 -58
  142. package/src/tui/usageCard.js +80 -45
  143. package/src/tui/usageCard.ts +81 -46
  144. package/src/tui/viewport.js +48 -23
  145. package/src/tui/viewport.ts +48 -27
  146. package/src/tui/viewportAnchor.js +2 -2
  147. package/src/tui/viewportAnchor.ts +2 -2
  148. package/src/tui/workspaceFileIndex.js +8 -6
  149. package/src/tui/workspaceFileIndex.ts +8 -6
  150. package/src/tui/workspaceSwitch.js +13 -10
  151. package/src/tui/workspaceSwitch.ts +11 -7
@@ -19,8 +19,27 @@ import fs from 'node:fs';
19
19
  import path from 'node:path';
20
20
  import { causyneHome } from '../utils/paths.js';
21
21
  import { assessRoute } from './strategy.js';
22
- import { generateCliPluginScaffold, generateHttpPluginScaffold, generateMcpServerScaffold, generatePythonBridgeScaffold } from './templates.js';
22
+ import { generateCliPluginScaffold, generateHttpPluginScaffold, generateMcpServerScaffold, generatePythonBridgeScaffold, shellQuote } from './templates.js';
23
23
  const NAME_PATTERN = /^[a-z0-9][a-z0-9-]{0,63}$/;
24
+ const TOOL_NAME_PATTERN = /^[a-z][a-z0-9_-]{0,63}$/;
25
+ const MAX_TOOLS = 32;
26
+ const CAPABILITIES = new Set(['workspace:read', 'workspace:write', 'network', 'subprocess']);
27
+ /**
28
+ * Resolves symlinked ancestors even when the final path does not exist yet.
29
+ * Keeps containment checks consistent on macOS, where /var is a symlink.
30
+ */
31
+ function resolveWithExistingAncestors(target) {
32
+ let current = path.resolve(target);
33
+ const missing = [];
34
+ while (!fs.existsSync(current)) {
35
+ const parent = path.dirname(current);
36
+ if (parent === current)
37
+ return path.resolve(target);
38
+ missing.unshift(path.basename(current));
39
+ current = parent;
40
+ }
41
+ return path.join(fs.realpathSync(current), ...missing);
42
+ }
24
43
  /**
25
44
  * Computes the exact SHA-256 directory digest matching Causyne's pluginManager.
26
45
  */
@@ -91,18 +110,66 @@ export class PluginsFactory {
91
110
  error: `Invalid service name "${service.name}". Must match ^[a-z0-9][a-z0-9-]{0,63}$`
92
111
  };
93
112
  }
113
+ const normalizedService = { ...service, name: normalizedName };
94
114
  const route = proposal.userConfirmedRoute ?? proposal.recommendedRoute;
115
+ if (route !== 'native_plugin' && route !== 'python_bridge' && route !== 'mcp_server') {
116
+ return {
117
+ success: false,
118
+ route,
119
+ targetDirectory: '',
120
+ createdFiles: [],
121
+ instructions: '',
122
+ error: `Unsupported route "${String(route)}".`
123
+ };
124
+ }
95
125
  const isMcp = route === 'mcp_server';
126
+ const toolError = this.validateTools(service.tools);
127
+ if (toolError) {
128
+ return {
129
+ success: false,
130
+ route,
131
+ targetDirectory: '',
132
+ createdFiles: [],
133
+ instructions: '',
134
+ error: toolError
135
+ };
136
+ }
137
+ const capabilityError = this.validateCapabilities(service.capabilities || []);
138
+ if (capabilityError) {
139
+ return {
140
+ success: false,
141
+ route,
142
+ targetDirectory: '',
143
+ createdFiles: [],
144
+ instructions: '',
145
+ error: capabilityError
146
+ };
147
+ }
148
+ const endpointError = this.validateEndpoint(service, route);
149
+ if (endpointError) {
150
+ return {
151
+ success: false,
152
+ route,
153
+ targetDirectory: '',
154
+ createdFiles: [],
155
+ instructions: '',
156
+ error: endpointError
157
+ };
158
+ }
96
159
  const baseDir = options.baseDir
97
160
  ? path.resolve(options.baseDir)
98
161
  : isMcp
99
162
  ? this.mcpServersRoot
100
163
  : this.pluginsRoot;
101
164
  const targetDir = path.join(baseDir, normalizedName);
102
- // Path containment check: ensure targetDir cannot escape baseDir
103
- const resolvedBase = path.resolve(baseDir);
104
- const resolvedTarget = path.resolve(targetDir);
105
- if (!resolvedTarget.startsWith(resolvedBase + path.sep)) {
165
+ // Path containment check: resolve the nearest real parent so a symlinked
166
+ // target or parent cannot redirect writes outside the base directory.
167
+ const resolvedBase = resolveWithExistingAncestors(baseDir);
168
+ const targetParent = path.dirname(targetDir);
169
+ const resolvedParent = resolveWithExistingAncestors(targetParent);
170
+ const resolvedTarget = path.join(resolvedParent, path.basename(targetDir));
171
+ const relativeTarget = path.relative(resolvedBase, resolvedTarget);
172
+ if (!relativeTarget || relativeTarget.startsWith('..') || path.isAbsolute(relativeTarget)) {
106
173
  return {
107
174
  success: false,
108
175
  route,
@@ -112,31 +179,54 @@ export class PluginsFactory {
112
179
  error: `Target path escapes directory boundary: ${targetDir}`
113
180
  };
114
181
  }
115
- if (fs.existsSync(targetDir) && !options.force) {
116
- return {
117
- success: false,
118
- route,
119
- targetDirectory: targetDir,
120
- createdFiles: [],
121
- instructions: '',
122
- error: `Directory already exists: ${targetDir}. Use force: true to overwrite.`
123
- };
182
+ if (fs.existsSync(targetDir)) {
183
+ const targetStat = fs.lstatSync(targetDir);
184
+ if (targetStat.isSymbolicLink()) {
185
+ return {
186
+ success: false,
187
+ route,
188
+ targetDirectory: targetDir,
189
+ createdFiles: [],
190
+ instructions: '',
191
+ error: `Target path must not be a symlink: ${targetDir}`
192
+ };
193
+ }
194
+ if (!targetStat.isDirectory()) {
195
+ return {
196
+ success: false,
197
+ route,
198
+ targetDirectory: targetDir,
199
+ createdFiles: [],
200
+ instructions: '',
201
+ error: `Target path is not a directory: ${targetDir}`
202
+ };
203
+ }
204
+ if (!options.force) {
205
+ return {
206
+ success: false,
207
+ route,
208
+ targetDirectory: targetDir,
209
+ createdFiles: [],
210
+ instructions: '',
211
+ error: `Directory already exists: ${targetDir}. Use force: true to overwrite.`
212
+ };
213
+ }
124
214
  }
125
215
  // Select scaffolding payload generator based on route
126
216
  let payload;
127
217
  if (route === 'native_plugin') {
128
218
  if (service.serviceKind === 'cli' || service.cliBinary) {
129
- payload = generateCliPluginScaffold(service);
219
+ payload = generateCliPluginScaffold(normalizedService);
130
220
  }
131
221
  else {
132
- payload = generateHttpPluginScaffold(service);
222
+ payload = generateHttpPluginScaffold(normalizedService);
133
223
  }
134
224
  }
135
225
  else if (route === 'python_bridge') {
136
- payload = generatePythonBridgeScaffold(service);
226
+ payload = generatePythonBridgeScaffold(normalizedService);
137
227
  }
138
228
  else {
139
- payload = generateMcpServerScaffold(service);
229
+ payload = generateMcpServerScaffold(normalizedService);
140
230
  }
141
231
  if (options.dryRun) {
142
232
  return {
@@ -144,28 +234,64 @@ export class PluginsFactory {
144
234
  route,
145
235
  targetDirectory: targetDir,
146
236
  createdFiles: payload.files.map(f => f.relativePath),
147
- instructions: `[Dry Run] Scaffolding plan ready for ${service.name} at ${targetDir}`
237
+ instructions: `[Dry Run] Scaffolding plan ready for ${normalizedName} at ${targetDir}`
148
238
  };
149
239
  }
150
240
  // Write files to target directory
151
- fs.mkdirSync(targetDir, { recursive: true, mode: 0o700 });
241
+ const createdRoot = !fs.existsSync(targetDir);
152
242
  const createdFiles = [];
153
- for (const file of payload.files) {
154
- const filePath = path.join(targetDir, file.relativePath);
155
- const fileDir = path.dirname(filePath);
156
- if (!fs.existsSync(fileDir)) {
157
- fs.mkdirSync(fileDir, { recursive: true, mode: 0o700 });
243
+ try {
244
+ fs.mkdirSync(targetDir, { recursive: true, mode: 0o700 });
245
+ for (const file of payload.files) {
246
+ const filePath = path.join(targetDir, file.relativePath);
247
+ const fileDir = path.dirname(filePath);
248
+ if (fs.existsSync(fileDir)) {
249
+ const dirStat = fs.lstatSync(fileDir);
250
+ if (dirStat.isSymbolicLink()) {
251
+ throw new Error(`Refusing to write through symlinked directory: ${fileDir}`);
252
+ }
253
+ }
254
+ if (fs.existsSync(filePath)) {
255
+ const fileStat = fs.lstatSync(filePath);
256
+ if (fileStat.isSymbolicLink()) {
257
+ throw new Error(`Refusing to overwrite symlinked file: ${filePath}`);
258
+ }
259
+ if (!fileStat.isFile()) {
260
+ throw new Error(`Refusing to overwrite non-file path: ${filePath}`);
261
+ }
262
+ }
263
+ if (!fs.existsSync(fileDir)) {
264
+ fs.mkdirSync(fileDir, { recursive: true, mode: 0o700 });
265
+ }
266
+ fs.writeFileSync(filePath, file.content, { encoding: 'utf8', mode: 0o600 });
267
+ createdFiles.push(file.relativePath);
158
268
  }
159
- fs.writeFileSync(filePath, file.content, { encoding: 'utf8', mode: 0o600 });
160
- createdFiles.push(file.relativePath);
269
+ }
270
+ catch (err) {
271
+ if (createdRoot) {
272
+ try {
273
+ fs.rmSync(targetDir, { recursive: true, force: true });
274
+ }
275
+ catch {
276
+ // Preserve the original write failure.
277
+ }
278
+ }
279
+ return {
280
+ success: false,
281
+ route,
282
+ targetDirectory: targetDir,
283
+ createdFiles: [],
284
+ instructions: '',
285
+ error: `Failed to scaffold ${normalizedName}: ${err instanceof Error ? err.message : String(err)}`
286
+ };
161
287
  }
162
288
  let digest;
163
289
  let instructions;
164
290
  if (!isMcp) {
165
291
  // Calculate plugin digest
166
292
  digest = computePluginDirectoryDigest(targetDir);
167
- // Record disabled state in state.json
168
- this.recordPluginState(normalizedName, digest);
293
+ // Record disabled state in state.json next to the scaffolded plugin.
294
+ this.recordPluginState(normalizedName, digest, baseDir);
169
295
  instructions = [
170
296
  `Custom plugin '${normalizedName}' successfully scaffolded at: ${targetDir}`,
171
297
  `Kind: ${route === 'python_bridge' ? 'Python Bridge Plugin' : 'Native Plugin'}`,
@@ -173,8 +299,7 @@ export class PluginsFactory {
173
299
  `Security Status: DISABLED (Review source files before enabling)`,
174
300
  '',
175
301
  `To activate after review:`,
176
- ` causyne plugins enable ${normalizedName}`,
177
- ` (or in chat: /plugins enable ${normalizedName})`
302
+ ` /plugins enable ${normalizedName}`
178
303
  ].join('\n');
179
304
  }
180
305
  else {
@@ -184,7 +309,7 @@ export class PluginsFactory {
184
309
  `Security Status: UNGRANTED (Review source files before granting)`,
185
310
  '',
186
311
  `To register and grant:`,
187
- ` causyne mcp add ${normalizedName} node ${path.join(targetDir, 'server.js')}`,
312
+ ` causyne mcp add ${normalizedName} node ${shellQuote(path.join(targetDir, 'server.js'))}`,
188
313
  ` causyne mcp grant ${normalizedName}`,
189
314
  ` (or in chat: /mcp grant ${normalizedName})`
190
315
  ].join('\n');
@@ -201,15 +326,62 @@ export class PluginsFactory {
201
326
  }
202
327
  return result;
203
328
  }
329
+ /**
330
+ * Rejects descriptors that the plugin loader would refuse after the factory
331
+ * has already written files and recorded a digest.
332
+ */
333
+ validateTools(tools) {
334
+ if (tools.length > MAX_TOOLS) {
335
+ return `Plugin exceeds ${MAX_TOOLS} tools.`;
336
+ }
337
+ const seen = new Set();
338
+ for (const tool of tools) {
339
+ if (!TOOL_NAME_PATTERN.test(tool.name)) {
340
+ return `Invalid tool name "${tool.name}". Must match ^[a-z][a-z0-9_-]{0,63}$`;
341
+ }
342
+ if (seen.has(tool.name)) {
343
+ return `Duplicate tool name "${tool.name}".`;
344
+ }
345
+ seen.add(tool.name);
346
+ if (!tool.parameters || tool.parameters.type !== 'object') {
347
+ return `Tool "${tool.name}" parameters must be an object JSON schema.`;
348
+ }
349
+ }
350
+ return null;
351
+ }
352
+ validateCapabilities(capabilities) {
353
+ for (const capability of capabilities) {
354
+ if (!CAPABILITIES.has(capability)) {
355
+ return `Unknown capability "${capability}".`;
356
+ }
357
+ }
358
+ return null;
359
+ }
360
+ validateEndpoint(service, route) {
361
+ const isHttpNative = route === 'native_plugin' && service.serviceKind !== 'cli' && !service.cliBinary;
362
+ if (!isHttpNative || !service.endpoint)
363
+ return null;
364
+ let parsed;
365
+ try {
366
+ parsed = new URL(service.endpoint);
367
+ }
368
+ catch {
369
+ return `Invalid endpoint URL "${service.endpoint}".`;
370
+ }
371
+ if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {
372
+ return `Endpoint must use http or https, received "${parsed.protocol}".`;
373
+ }
374
+ return null;
375
+ }
204
376
  /**
205
377
  * Ensures state.json records the newly scaffolded plugin as disabled.
206
378
  */
207
- recordPluginState(pluginName, digest) {
379
+ recordPluginState(pluginName, digest, stateRoot = this.pluginsRoot) {
208
380
  try {
209
- if (!fs.existsSync(this.pluginsRoot)) {
210
- fs.mkdirSync(this.pluginsRoot, { recursive: true, mode: 0o700 });
381
+ if (!fs.existsSync(stateRoot)) {
382
+ fs.mkdirSync(stateRoot, { recursive: true, mode: 0o700 });
211
383
  }
212
- const stateFile = path.join(this.pluginsRoot, 'state.json');
384
+ const stateFile = path.join(stateRoot, 'state.json');
213
385
  let state = {
214
386
  version: 1,
215
387
  plugins: {}
@@ -218,8 +390,11 @@ export class PluginsFactory {
218
390
  try {
219
391
  const raw = fs.readFileSync(stateFile, 'utf8');
220
392
  const parsed = JSON.parse(raw);
221
- if (parsed && typeof parsed === 'object') {
222
- state = { version: 1, plugins: parsed.plugins || {} };
393
+ const parsedPlugins = parsed && typeof parsed === 'object' && !Array.isArray(parsed)
394
+ ? parsed.plugins
395
+ : undefined;
396
+ if (parsedPlugins && typeof parsedPlugins === 'object' && !Array.isArray(parsedPlugins)) {
397
+ state = { version: 1, plugins: parsedPlugins };
223
398
  }
224
399
  }
225
400
  catch {