@causyne/agent 1.19.0 → 1.20.5

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 (128) hide show
  1. package/README.md +0 -18
  2. package/package.json +1 -1
  3. package/src/acp/client.js +2 -1
  4. package/src/acp/client.ts +2 -1
  5. package/src/acp/server.js +5 -6
  6. package/src/acp/server.ts +4 -6
  7. package/src/agentLoop.d.ts +1 -0
  8. package/src/agentLoop.js +505 -241
  9. package/src/agentLoop.ts +527 -258
  10. package/src/agentPolicy.js +9 -0
  11. package/src/agentPolicy.ts +9 -0
  12. package/src/approvalPolicy.js +55 -0
  13. package/src/approvalPolicy.ts +66 -0
  14. package/src/browser/browserRuntime.js +217 -14
  15. package/src/browser/browserRuntime.ts +255 -14
  16. package/src/browser/causyneBrowser.js +1215 -68
  17. package/src/browser/causyneBrowser.ts +1340 -72
  18. package/src/cliMode.js +66 -37
  19. package/src/commands.js +343 -72
  20. package/src/config.js +22 -12
  21. package/src/continuum/ingest.js +1 -1
  22. package/src/continuum/ingest.ts +1 -1
  23. package/src/continuum/ui/continuumPicker.js +18 -1
  24. package/src/continuum/ui/continuumPicker.ts +19 -1
  25. package/src/dynamicCatalogue.js +87 -20
  26. package/src/dynamicCatalogue.ts +85 -15
  27. package/src/launchIntent.js +40 -0
  28. package/src/launchIntent.ts +49 -0
  29. package/src/memoryManager.js +36 -8
  30. package/src/modelCatalogue.js +2 -0
  31. package/src/planCache.js +320 -11
  32. package/src/planCache.ts +402 -13
  33. package/src/providers/acp.js +67 -1
  34. package/src/providers/acp.ts +65 -2
  35. package/src/providers/antigravity.d.ts +5 -1
  36. package/src/providers/antigravity.js +643 -32
  37. package/src/providers/antigravity.ts +671 -33
  38. package/src/providers/base.d.ts +9 -0
  39. package/src/providers/factory.js +2 -0
  40. package/src/providers/pi.js +157 -0
  41. package/src/providers/pi.ts +144 -0
  42. package/src/provisioning/capabilityProvisioner.js +17 -0
  43. package/src/provisioning/capabilityTools.js +1 -1
  44. package/src/sandbox.js +30 -39
  45. package/src/sessionJournal.js +66 -10
  46. package/src/sessionJournal.ts +84 -10
  47. package/src/taskShape.js +9 -9
  48. package/src/taskShape.ts +9 -9
  49. package/src/timeMachine.js +124 -0
  50. package/src/timeMachine.ts +141 -0
  51. package/src/toolPacks.js +4 -10
  52. package/src/tools/archive.js +196 -59
  53. package/src/tools/archive.ts +220 -0
  54. package/src/tools/browserAutomator.js +78 -9
  55. package/src/tools/browserAutomator.ts +90 -9
  56. package/src/tools/desktopOpen.js +114 -31
  57. package/src/tools/desktopOpen.ts +144 -0
  58. package/src/tools/gitExec.js +5 -3
  59. package/src/tools/nativeEngine.js +4 -3
  60. package/src/tools/nativeEngine.ts +5 -3
  61. package/src/tools/openSourceToolProvisioner.js +5 -4
  62. package/src/tools/openSourceToolProvisioner.ts +5 -4
  63. package/src/tools/registry.js +3 -0
  64. package/src/tools/screenshot.js +55 -71
  65. package/src/tools/screenshot.ts +70 -0
  66. package/src/tools/sysRun.js +284 -117
  67. package/src/tools/sysRun.ts +347 -0
  68. package/src/tools/toolSelfRepair.js +109 -2
  69. package/src/tools/toolSelfRepair.ts +100 -2
  70. package/src/tools/updatePlan.js +49 -1
  71. package/src/tools/updatePlan.ts +43 -1
  72. package/src/tools/viewImage.js +93 -78
  73. package/src/tools/viewImage.ts +116 -0
  74. package/src/tools/webFetch.js +20 -6
  75. package/src/tools/webFetch.ts +26 -6
  76. package/src/tui/block.d.ts +1 -0
  77. package/src/tui/chatRenderer.d.ts +21 -0
  78. package/src/tui/chatRenderer.js +118 -45
  79. package/src/tui/clipboardSync.js +28 -1
  80. package/src/tui/clipboardSync.ts +26 -1
  81. package/src/tui/codeProgress.js +299 -0
  82. package/src/tui/codeProgress.ts +304 -0
  83. package/src/tui/codeStreamRenderer.js +116 -0
  84. package/src/tui/codeStreamRenderer.ts +124 -0
  85. package/src/tui/commandPresentation.js +11 -0
  86. package/src/tui/commandPresentation.ts +18 -0
  87. package/src/tui/completion.js +45 -13
  88. package/src/tui/composerControls.js +66 -0
  89. package/src/tui/composerControls.ts +78 -0
  90. package/src/tui/diff.d.ts +2 -0
  91. package/src/tui/home.js +4 -2
  92. package/src/tui/homeTransition.js +21 -0
  93. package/src/tui/homeTransition.ts +27 -0
  94. package/src/tui/homeView.js +62 -0
  95. package/src/tui/homeView.ts +91 -0
  96. package/src/tui/layout.js +46 -0
  97. package/src/tui/layout.ts +52 -0
  98. package/src/tui/messageActionPlacement.js +16 -0
  99. package/src/tui/messageActionPlacement.ts +25 -0
  100. package/src/tui/messageInteraction.js +221 -0
  101. package/src/tui/messageInteraction.ts +275 -0
  102. package/src/tui/modelPicker.js +13 -0
  103. package/src/tui/modelPicker.ts +12 -0
  104. package/src/tui/mouseHover.js +6 -0
  105. package/src/tui/mouseHover.ts +5 -0
  106. package/src/tui/prompt.js +199 -52
  107. package/src/tui/resizeRecovery.js +15 -0
  108. package/src/tui/resizeRecovery.ts +27 -0
  109. package/src/tui/scrollInteraction.js +97 -0
  110. package/src/tui/scrollInteraction.ts +189 -0
  111. package/src/tui/sessionLayout.js +12 -0
  112. package/src/tui/sessionLayout.ts +12 -0
  113. package/src/tui/sessionPicker.js +280 -0
  114. package/src/tui/sessionPicker.ts +364 -0
  115. package/src/tui/sessionSidebar.js +78 -0
  116. package/src/tui/sessionSidebar.ts +95 -0
  117. package/src/tui/setup.js +1 -1
  118. package/src/tui/setup.ts +1 -1
  119. package/src/tui/stageSurface.js +128 -57
  120. package/src/tui/statusLine.js +5 -5
  121. package/src/tui/text.d.ts +5 -0
  122. package/src/tui/textLayout.js +23 -0
  123. package/src/tui/textLayout.ts +28 -0
  124. package/src/tui/viewport.js +204 -279
  125. package/src/tui/viewport.ts +326 -0
  126. package/src/types/contracts.ts +54 -0
  127. package/src/utils/paths.js +5 -4
  128. package/src/utils/paths.ts +5 -5
@@ -1,4 +1,17 @@
1
- import { accessSync, constants, existsSync, realpathSync, statSync } from 'node:fs';
1
+ import crypto from 'node:crypto';
2
+ import {
3
+ accessSync,
4
+ constants,
5
+ existsSync,
6
+ mkdirSync,
7
+ readdirSync,
8
+ readFileSync,
9
+ realpathSync,
10
+ rmSync,
11
+ statSync,
12
+ symlinkSync,
13
+ writeFileSync
14
+ } from 'node:fs';
2
15
  import os from 'node:os';
3
16
  import path from 'node:path';
4
17
 
@@ -9,9 +22,31 @@ import path from 'node:path';
9
22
  export interface PreparedBrowserRuntime {
10
23
  installDirectory: string;
11
24
  resourceDirectory: string;
25
+ executablePath?: string;
12
26
  source: 'environment' | 'system';
13
27
  }
14
28
 
29
+ function resolveCandidateExecutablePath(candidate: string): string {
30
+ if (!existsSync(candidate)) return candidate;
31
+ try {
32
+ const stat = statSync(candidate);
33
+ if (stat.isDirectory()) {
34
+ const nestedCandidates = [
35
+ path.join(candidate, 'Contents', 'MacOS', 'camoufox'),
36
+ path.join(candidate, 'Camoufox.app', 'Contents', 'MacOS', 'camoufox'),
37
+ path.join(candidate, 'camoufox-bin'),
38
+ path.join(candidate, 'camoufox'),
39
+ path.join(candidate, 'camoufox.exe')
40
+ ];
41
+ const found = nestedCandidates.find(existsSync);
42
+ if (found) return found;
43
+ }
44
+ } catch {
45
+ // Fall through to assertExecutable for deterministic error reporting.
46
+ }
47
+ return candidate;
48
+ }
49
+
15
50
  function assertExecutable(candidate: string): void {
16
51
  const stat = statSync(candidate);
17
52
  if (!stat.isFile() && !stat.isSymbolicLink()) {
@@ -25,8 +60,12 @@ function candidateExecutables(): string[] {
25
60
  if (process.platform === 'darwin') {
26
61
  return [
27
62
  path.join(home, 'Library', 'Caches', 'camoufox', 'Camoufox.app', 'Contents', 'MacOS', 'camoufox'),
63
+ path.join(home, 'Library', 'Application Support', 'camoufox', 'Camoufox.app', 'Contents', 'MacOS', 'camoufox'),
64
+ path.join(home, '.cache', 'camoufox', 'Camoufox.app', 'Contents', 'MacOS', 'camoufox'),
28
65
  '/Applications/Camoufox.app/Contents/MacOS/camoufox',
29
- path.join(home, 'Applications', 'Camoufox.app', 'Contents', 'MacOS', 'camoufox')
66
+ path.join(home, 'Applications', 'Camoufox.app', 'Contents', 'MacOS', 'camoufox'),
67
+ '/opt/homebrew/bin/camoufox',
68
+ '/usr/local/bin/camoufox'
30
69
  ];
31
70
  }
32
71
  if (process.platform === 'win32') {
@@ -35,14 +74,19 @@ function candidateExecutables(): string[] {
35
74
  return [
36
75
  ...(localAppData ? [path.join(localAppData, 'camoufox', 'camoufox.exe')] : []),
37
76
  ...(localAppData ? [path.join(localAppData, 'Camoufox', 'camoufox.exe')] : []),
38
- ...(programFiles ? [path.join(programFiles, 'Camoufox', 'camoufox.exe')] : [])
77
+ ...(programFiles ? [path.join(programFiles, 'Camoufox', 'camoufox.exe')] : []),
78
+ path.join(home, '.cache', 'camoufox', 'camoufox.exe')
39
79
  ];
40
80
  }
41
81
  return [
42
82
  path.join(home, '.cache', 'camoufox', 'camoufox-bin'),
43
83
  '/opt/camoufox/camoufox-bin',
84
+ '/opt/camoufox/camoufox',
44
85
  path.join(home, '.local', 'share', 'camoufox', 'camoufox-bin'),
45
- '/usr/local/lib/camoufox/camoufox-bin'
86
+ path.join(home, '.local', 'bin', 'camoufox'),
87
+ '/usr/local/lib/camoufox/camoufox-bin',
88
+ '/usr/local/bin/camoufox',
89
+ '/usr/bin/camoufox'
46
90
  ];
47
91
  }
48
92
 
@@ -54,6 +98,40 @@ function expectedExecutable(installDirectory: string): string {
54
98
  return path.join(installDirectory, 'camoufox-bin');
55
99
  }
56
100
 
101
+ function nixStoreRoot(candidatePath: string): string | null {
102
+ const match = candidatePath.match(/^\/nix\/store\/[^/]+/);
103
+ return match?.[0] ?? null;
104
+ }
105
+
106
+ function collectDirs(root: string, maxDepth = 4): string[] {
107
+ const dirs: string[] = [];
108
+ const queue: Array<{ dir: string; depth: number }> = [{ dir: root, depth: 0 }];
109
+ const seen = new Set<string>();
110
+
111
+ while (queue.length > 0) {
112
+ const current = queue.shift();
113
+ if (!current) break;
114
+ const { dir, depth } = current;
115
+ if (seen.has(dir)) continue;
116
+ seen.add(dir);
117
+ dirs.push(dir);
118
+ if (depth >= maxDepth) continue;
119
+
120
+ let entries = [];
121
+ try {
122
+ entries = readdirSync(dir, { withFileTypes: true });
123
+ } catch {
124
+ continue;
125
+ }
126
+ for (const entry of entries) {
127
+ if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
128
+ queue.push({ dir: path.join(dir, entry.name), depth: depth + 1 });
129
+ }
130
+ }
131
+
132
+ return dirs;
133
+ }
134
+
57
135
  function findInstallDirectory(executablePath: string): string | null {
58
136
  let current = path.dirname(executablePath);
59
137
  for (let depth = 0; depth < 7; depth += 1) {
@@ -67,16 +145,162 @@ function findInstallDirectory(executablePath: string): string | null {
67
145
  return null;
68
146
  }
69
147
 
70
- function resourceDirectoryFor(executablePath: string): string {
148
+ function findResourceDirectory(executablePath: string, resolvedExecutable: string): string | null {
149
+ const directCandidates: string[] = [];
71
150
  if (process.platform === 'darwin') {
72
- return path.resolve(path.dirname(executablePath), '..', 'Resources');
151
+ directCandidates.push(path.resolve(path.dirname(resolvedExecutable), '..', 'Resources'));
152
+ directCandidates.push(path.resolve(path.dirname(executablePath), '..', 'Resources'));
153
+ }
154
+ directCandidates.push(path.dirname(resolvedExecutable));
155
+ directCandidates.push(path.dirname(executablePath));
156
+
157
+ let ancestor = path.dirname(resolvedExecutable);
158
+ for (let depth = 0; depth < 5; depth += 1) {
159
+ directCandidates.push(ancestor);
160
+ const parent = path.dirname(ancestor);
161
+ if (parent === ancestor) break;
162
+ ancestor = parent;
163
+ }
164
+
165
+ const storeRoot = nixStoreRoot(resolvedExecutable) ?? nixStoreRoot(executablePath);
166
+ if (storeRoot) {
167
+ directCandidates.push(
168
+ storeRoot,
169
+ path.join(storeRoot, 'lib', 'camoufox'),
170
+ path.join(storeRoot, 'libexec', 'camoufox'),
171
+ path.join(storeRoot, 'share', 'camoufox'),
172
+ path.join(storeRoot, 'opt', 'camoufox')
173
+ );
73
174
  }
74
- return path.dirname(executablePath);
175
+
176
+ for (const dir of directCandidates) {
177
+ if (existsSync(path.join(dir, 'properties.json'))) return dir;
178
+ }
179
+
180
+ if (storeRoot) {
181
+ for (const dir of collectDirs(storeRoot)) {
182
+ if (existsSync(path.join(dir, 'properties.json'))) return dir;
183
+ }
184
+ }
185
+
186
+ return null;
187
+ }
188
+
189
+ function findVersionFile(executablePath: string, resourceDirectory: string): string | null {
190
+ const candidates = [
191
+ path.join(resourceDirectory, 'version.json'),
192
+ path.dirname(executablePath)
193
+ ];
194
+ let current = path.dirname(executablePath);
195
+ for (let depth = 0; depth < 7; depth += 1) {
196
+ const versionCandidate = path.join(current, 'version.json');
197
+ if (existsSync(versionCandidate)) return versionCandidate;
198
+ const parent = path.dirname(current);
199
+ if (parent === current) break;
200
+ current = parent;
201
+ }
202
+ for (const candidate of candidates) {
203
+ if (candidate.endsWith('version.json') && existsSync(candidate)) return candidate;
204
+ }
205
+ return null;
206
+ }
207
+
208
+ function ensureSymlink(target: string, linkPath: string, type: 'file' | 'dir' = 'file'): void {
209
+ rmSync(linkPath, { force: true, recursive: true });
210
+ mkdirSync(path.dirname(linkPath), { recursive: true });
211
+ symlinkSync(target, linkPath, process.platform === 'win32' && type === 'dir' ? 'junction' : type);
212
+ }
213
+
214
+ function ensureExternalBundleInstallDirectory(
215
+ resolvedExecutable: string,
216
+ resourceDirectory: string,
217
+ versionFile: string | null
218
+ ): string | null {
219
+ const propertiesFile = path.join(resourceDirectory, 'properties.json');
220
+ if (!existsSync(propertiesFile)) return null;
221
+
222
+ const key = crypto
223
+ .createHash('sha256')
224
+ .update(`${resolvedExecutable}\n${realpathSync(resourceDirectory)}`)
225
+ .digest('hex')
226
+ .slice(0, 16);
227
+ const shimDir = path.join(os.tmpdir(), 'causyne-browser-runtime', key);
228
+ const cacheVersion = path.join(shimDir, 'version.json');
229
+ const cacheProperties = path.join(shimDir, 'properties.json');
230
+ const cacheFontconfig = path.join(shimDir, 'fontconfig');
231
+ const cacheExecutable = expectedExecutable(shimDir);
232
+
233
+ mkdirSync(shimDir, { recursive: true });
234
+
235
+ if (!existsSync(cacheVersion)) {
236
+ if (versionFile && existsSync(versionFile)) {
237
+ writeFileSync(cacheVersion, readFileSync(versionFile));
238
+ } else {
239
+ writeFileSync(cacheVersion, JSON.stringify({ version: 'external', build: 'local' }), 'utf8');
240
+ }
241
+ }
242
+
243
+ if (!existsSync(cacheProperties)) {
244
+ ensureSymlink(realpathSync(propertiesFile), cacheProperties, 'file');
245
+ }
246
+
247
+ const sourceFontconfig = path.join(resourceDirectory, 'fontconfig');
248
+ if (existsSync(sourceFontconfig) && !existsSync(cacheFontconfig)) {
249
+ ensureSymlink(realpathSync(sourceFontconfig), cacheFontconfig, 'dir');
250
+ }
251
+
252
+ if (process.platform === 'darwin') {
253
+ const appResourceDir = path.join(shimDir, 'Camoufox.app', 'Contents', 'Resources');
254
+ mkdirSync(appResourceDir, { recursive: true });
255
+ const appProperties = path.join(appResourceDir, 'properties.json');
256
+ if (!existsSync(appProperties)) {
257
+ ensureSymlink(realpathSync(propertiesFile), appProperties, 'file');
258
+ }
259
+ if (existsSync(sourceFontconfig) && !existsSync(path.join(appResourceDir, 'fontconfig'))) {
260
+ ensureSymlink(realpathSync(sourceFontconfig), path.join(appResourceDir, 'fontconfig'), 'dir');
261
+ }
262
+ }
263
+
264
+ if (!existsSync(cacheExecutable)) {
265
+ ensureSymlink(resolvedExecutable, cacheExecutable, 'file');
266
+ }
267
+
268
+ return shimDir;
269
+ }
270
+
271
+ function ensureLaunchShim(resolvedExecutable: string, resourceDirectory: string): string {
272
+ const key = crypto
273
+ .createHash('sha256')
274
+ .update(`${resolvedExecutable}\n${realpathSync(resourceDirectory)}`)
275
+ .digest('hex')
276
+ .slice(0, 16);
277
+ const shimRoot = path.join(os.tmpdir(), 'causyne-browser-launch-shim', key);
278
+ mkdirSync(shimRoot, { recursive: true });
279
+
280
+ const shimExecutable = path.join(shimRoot, process.platform === 'win32' ? 'camoufox.exe' : 'camoufox-bin');
281
+ ensureSymlink(resolvedExecutable, shimExecutable, 'file');
282
+
283
+ for (const name of ['properties.json', 'version.json']) {
284
+ const target = path.join(resourceDirectory, name);
285
+ if (existsSync(target)) {
286
+ ensureSymlink(realpathSync(target), path.join(shimRoot, name), 'file');
287
+ }
288
+ }
289
+
290
+ const fontconfig = path.join(resourceDirectory, 'fontconfig');
291
+ if (existsSync(fontconfig)) {
292
+ ensureSymlink(realpathSync(fontconfig), path.join(shimRoot, 'fontconfig'), 'dir');
293
+ }
294
+
295
+ return shimExecutable;
75
296
  }
76
297
 
77
298
  export function resolveBrowserRuntime(): PreparedBrowserRuntime {
78
- const configured = process.env.CAUSYNE_BROWSER_EXECUTABLE?.trim();
79
- const candidates = configured ? [path.resolve(configured)] : candidateExecutables();
299
+ const configured = process.env.CAUSYNE_BROWSER_EXECUTABLE?.trim()
300
+ || process.env.CAMOUFOX_EXECUTABLE_PATH?.trim();
301
+ const candidates = configured
302
+ ? [resolveCandidateExecutablePath(path.resolve(configured))]
303
+ : candidateExecutables().map(resolveCandidateExecutablePath);
80
304
  const executablePath = candidates.find(existsSync);
81
305
  if (!executablePath) {
82
306
  throw new Error(
@@ -87,21 +311,38 @@ export function resolveBrowserRuntime(): PreparedBrowserRuntime {
87
311
 
88
312
  assertExecutable(executablePath);
89
313
  const resolvedExecutable = realpathSync(executablePath);
90
- const installDirectory = findInstallDirectory(resolvedExecutable);
314
+ const resourceDirectory = findResourceDirectory(executablePath, resolvedExecutable);
315
+ if (!resourceDirectory) {
316
+ throw new Error(
317
+ `Causyne Browser runtime metadata (properties.json) was not found for ${resolvedExecutable}. ` +
318
+ 'Keep properties.json beside its platform bundle and point CAUSYNE_BROWSER_EXECUTABLE at that bundle.'
319
+ );
320
+ }
321
+
322
+ let installDirectory = findInstallDirectory(resolvedExecutable);
323
+ if (!installDirectory) {
324
+ const versionFile = findVersionFile(resolvedExecutable, resourceDirectory);
325
+ installDirectory = ensureExternalBundleInstallDirectory(resolvedExecutable, resourceDirectory, versionFile);
326
+ }
327
+
91
328
  if (!installDirectory) {
92
329
  throw new Error(
93
330
  `Causyne Browser runtime at ${resolvedExecutable} is not a complete distribution. ` +
94
- 'Keep version.json beside its platform bundle and point CAUSYNE_BROWSER_EXECUTABLE at that bundle.'
331
+ 'Keep version.json and properties.json beside its platform bundle and point CAUSYNE_BROWSER_EXECUTABLE at that bundle.'
95
332
  );
96
333
  }
97
- const resourceDirectory = resourceDirectoryFor(resolvedExecutable);
98
- if (!existsSync(path.join(resourceDirectory, 'properties.json'))) {
99
- throw new Error(`Causyne Browser runtime metadata was not found in ${resourceDirectory}.`);
334
+
335
+ let launchExecutable = resolvedExecutable;
336
+ try {
337
+ launchExecutable = ensureLaunchShim(resolvedExecutable, resourceDirectory);
338
+ } catch {
339
+ launchExecutable = resolvedExecutable;
100
340
  }
101
341
 
102
342
  return {
103
343
  installDirectory,
104
344
  resourceDirectory,
345
+ executablePath: launchExecutable,
105
346
  source: configured ? 'environment' : 'system'
106
347
  };
107
348
  }