@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,63 +1,200 @@
1
- import fs from 'fs/promises';
1
+ import fs from 'node:fs/promises';
2
+ import { existsSync, statSync, createWriteStream } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { execFileSync } from 'node:child_process';
2
5
  import { resolveUserPath } from '../utils/paths.js';
3
- import { createReadStream, createWriteStream } from 'fs';
4
- import path from 'path';
5
- import { ensureCapability, loadCapabilityPackage } from '../provisioning/capabilityProvisioner.js';
6
-
6
+ import { loadCapabilityPackage } from '../provisioning/capabilityProvisioner.js';
7
7
  export const archive = {
8
- schema: {
9
- name: 'archive',
10
- description: 'Compress or extract archives securely using native Node streams (No Shell Tar).',
11
- parameters: {
12
- type: 'object',
13
- properties: {
14
- action: { type: 'string', enum: ['compress', 'extract'], description: 'Action to perform' },
15
- source: { type: 'string', description: 'Absolute path of the file/directory to compress or extract' },
16
- destination: { type: 'string', description: 'Absolute path for the output' }
17
- },
18
- required: ['action', 'source', 'destination']
19
- }
20
- },
21
- async execute(args) {
8
+ schema: {
9
+ name: 'archive',
10
+ description: 'Compress or extract archives securely with zero friction (supports .zip, .tar, .tar.gz, .tgz with native system fallbacks).',
11
+ parameters: {
12
+ type: 'object',
13
+ properties: {
14
+ action: { type: 'string', enum: ['compress', 'extract'], description: 'Action to perform: "compress" or "extract"' },
15
+ source: { type: 'string', description: 'Absolute or relative path of the file/directory to compress or extract' },
16
+ destination: { type: 'string', description: 'Absolute or relative path for the output file or directory' }
17
+ },
18
+ required: ['action', 'source', 'destination']
19
+ }
20
+ },
21
+ async execute(args) {
22
+ try {
23
+ if (!args || !args.action || !args.source || !args.destination) {
24
+ return { success: false, error: 'Missing required arguments: action, source, destination' };
25
+ }
26
+ const source = resolveUserPath(args.source);
27
+ const dest = resolveUserPath(args.destination);
28
+ if (!existsSync(source)) {
29
+ return { success: false, error: `Archive source path not found: ${source}` };
30
+ }
31
+ if (args.action === 'extract') {
32
+ return await extractArchive(source, dest);
33
+ }
34
+ else if (args.action === 'compress') {
35
+ return await compressArchive(source, dest);
36
+ }
37
+ else {
38
+ return { success: false, error: `Unsupported archive action: ${args.action}` };
39
+ }
40
+ }
41
+ catch (error) {
42
+ return { success: false, error: `Archive action failed: ${error?.message || String(error)}` };
43
+ }
44
+ }
45
+ };
46
+ async function extractArchive(source, dest) {
47
+ await fs.mkdir(dest, { recursive: true });
48
+ // 1. Try capability package extract-zip if already available in environment
22
49
  try {
23
- const source = resolveUserPath(args.source);
24
- const dest = resolveUserPath(args.destination);
25
-
26
- if (args.action === 'compress') {
27
- const capability = await ensureCapability('archive');
28
- if (!capability.ok) return { success: false, error: capability.reason, requiresConsent: capability.requiresConsent };
29
- const archiver = await loadCapabilityPackage('archiver');
30
-
31
- return new Promise(async (resolve) => {
32
- const output = createWriteStream(dest);
33
- const archive = archiver('zip', { zlib: { level: 9 } });
34
-
35
- output.on('close', () => resolve({ success: true, output: `Compressed ${archive.pointer()} total bytes to ${dest}` }));
36
- archive.on('error', (err) => resolve({ success: false, error: err.message }));
37
-
38
- archive.pipe(output);
39
-
40
- const stat = await fs.stat(source);
41
- if (stat.isDirectory()) {
42
- archive.directory(source, false);
43
- } else {
44
- archive.file(source, { name: path.basename(source) });
45
- }
46
- await archive.finalize();
47
- });
48
- }
49
- else if (args.action === 'extract') {
50
- const capability = await ensureCapability('archive');
51
- if (!capability.ok) return { success: false, error: capability.reason, requiresConsent: capability.requiresConsent };
52
50
  const extract = await loadCapabilityPackage('extract-zip');
53
-
54
- await fs.mkdir(dest, { recursive: true });
55
- await extract(source, { dir: dest });
56
-
57
- return { success: true, output: `Extracted successfully to ${dest}` };
58
- }
59
- } catch (error) {
60
- return { success: false, error: `Archive action failed: ${error.message}` };
61
- }
62
- }
63
- };
51
+ if (typeof extract === 'function') {
52
+ await extract(source, { dir: dest });
53
+ return { success: true, output: `Extracted successfully to ${dest}` };
54
+ }
55
+ }
56
+ catch {
57
+ // Fall through to native zero-dependency extractors
58
+ }
59
+ const isZip = source.toLowerCase().endsWith('.zip') || source.toLowerCase().endsWith('.jar');
60
+ const isTar = /\.(tar|tar\.gz|tgz|tar\.bz2|tar\.xz)$/i.test(source);
61
+ // 2. Native unzip on macOS / Linux
62
+ if (isZip) {
63
+ try {
64
+ execFileSync('unzip', ['-q', '-o', source, '-d', dest], { stdio: 'pipe' });
65
+ return { success: true, output: `Extracted successfully to ${dest} (via unzip)` };
66
+ }
67
+ catch {
68
+ // Fall through to python3 or powershell
69
+ }
70
+ }
71
+ // 3. Native tar on macOS / Linux
72
+ if (isTar || !isZip) {
73
+ try {
74
+ execFileSync('tar', ['-xf', source, '-C', dest], { stdio: 'pipe' });
75
+ return { success: true, output: `Extracted successfully to ${dest} (via tar)` };
76
+ }
77
+ catch {
78
+ // Fall through
79
+ }
80
+ }
81
+ // 4. Cross-platform Python standard library fallback
82
+ try {
83
+ execFileSync('python3', [
84
+ '-c',
85
+ 'import zipfile, tarfile, sys, os\n' +
86
+ 'src, dst = sys.argv[1], sys.argv[2]\n' +
87
+ 'if zipfile.is_zipfile(src):\n' +
88
+ ' with zipfile.ZipFile(src, "r") as z:\n' +
89
+ ' z.extractall(dst)\n' +
90
+ 'elif tarfile.is_tarfile(src):\n' +
91
+ ' with tarfile.open(src, "r:*") as t:\n' +
92
+ ' t.extractall(dst)\n' +
93
+ 'else:\n' +
94
+ ' raise ValueError("Unrecognized archive format")\n',
95
+ source,
96
+ dest
97
+ ], { stdio: 'pipe' });
98
+ return { success: true, output: `Extracted successfully to ${dest} (via python3)` };
99
+ }
100
+ catch {
101
+ // Fall through
102
+ }
103
+ // 5. Windows PowerShell fallback
104
+ if (process.platform === 'win32') {
105
+ try {
106
+ const psScript = `Expand-Archive -Path '${source.replace(/'/g, "''")}' -DestinationPath '${dest.replace(/'/g, "''")}' -Force`;
107
+ execFileSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', psScript], { stdio: 'pipe' });
108
+ return { success: true, output: `Extracted successfully to ${dest} (via PowerShell)` };
109
+ }
110
+ catch (e) {
111
+ return { success: false, error: `PowerShell extraction failed: ${e.message}` };
112
+ }
113
+ }
114
+ return { success: false, error: `Could not extract ${source}: no supported extractor found on system.` };
115
+ }
116
+ async function compressArchive(source, dest) {
117
+ const destDir = path.dirname(dest);
118
+ await fs.mkdir(destDir, { recursive: true });
119
+ // 1. Try capability package archiver if available
120
+ try {
121
+ const archiver = await loadCapabilityPackage('archiver');
122
+ if (typeof archiver === 'function') {
123
+ return await new Promise(async (resolve) => {
124
+ const output = createWriteStream(dest);
125
+ const format = dest.toLowerCase().endsWith('.tar') || dest.toLowerCase().endsWith('.tar.gz') ? 'tar' : 'zip';
126
+ const archiveStream = archiver(format, { zlib: { level: 9 } });
127
+ output.on('close', () => resolve({ success: true, output: `Compressed ${archiveStream.pointer()} total bytes to ${dest}` }));
128
+ archiveStream.on('error', (err) => resolve({ success: false, error: err.message }));
129
+ archiveStream.pipe(output);
130
+ const stat = statSync(source);
131
+ if (stat.isDirectory()) {
132
+ archiveStream.directory(source, false);
133
+ }
134
+ else {
135
+ archiveStream.file(source, { name: path.basename(source) });
136
+ }
137
+ await archiveStream.finalize();
138
+ });
139
+ }
140
+ }
141
+ catch {
142
+ // Fall through to native system compress
143
+ }
144
+ const isZip = dest.toLowerCase().endsWith('.zip');
145
+ const isTar = /\.(tar|tar\.gz|tgz)$/i.test(dest);
146
+ const stat = statSync(source);
147
+ // 2. Native zip on macOS / Linux
148
+ if (isZip) {
149
+ try {
150
+ if (stat.isDirectory()) {
151
+ execFileSync('zip', ['-q', '-r', dest, '.'], { cwd: source, stdio: 'pipe' });
152
+ }
153
+ else {
154
+ execFileSync('zip', ['-q', dest, path.basename(source)], { cwd: path.dirname(source), stdio: 'pipe' });
155
+ }
156
+ return { success: true, output: `Compressed successfully to ${dest} (via zip)` };
157
+ }
158
+ catch {
159
+ // Fall through
160
+ }
161
+ }
162
+ // 3. Native tar on macOS / Linux
163
+ if (isTar) {
164
+ try {
165
+ if (stat.isDirectory()) {
166
+ execFileSync('tar', ['-czf', dest, '-C', source, '.'], { stdio: 'pipe' });
167
+ }
168
+ else {
169
+ execFileSync('tar', ['-czf', dest, '-C', path.dirname(source), path.basename(source)], { stdio: 'pipe' });
170
+ }
171
+ return { success: true, output: `Compressed successfully to ${dest} (via tar)` };
172
+ }
173
+ catch {
174
+ // Fall through
175
+ }
176
+ }
177
+ // 4. Cross-platform Python fallback
178
+ try {
179
+ execFileSync('python3', [
180
+ '-c',
181
+ 'import zipfile, os, sys\n' +
182
+ 'src, dst = sys.argv[1], sys.argv[2]\n' +
183
+ 'with zipfile.ZipFile(dst, "w", zipfile.ZIP_DEFLATED) as z:\n' +
184
+ ' if os.path.isdir(src):\n' +
185
+ ' for root, dirs, files in os.walk(src):\n' +
186
+ ' for file in files:\n' +
187
+ ' full = os.path.join(root, file)\n' +
188
+ ' rel = os.path.relpath(full, src)\n' +
189
+ ' z.write(full, rel)\n' +
190
+ ' else:\n' +
191
+ ' z.write(src, os.path.basename(src))\n',
192
+ source,
193
+ dest
194
+ ], { stdio: 'pipe' });
195
+ return { success: true, output: `Compressed successfully to ${dest} (via python3 zipfile)` };
196
+ }
197
+ catch (pyErr) {
198
+ return { success: false, error: `Compression failed: ${pyErr?.message || String(pyErr)}` };
199
+ }
200
+ }
@@ -0,0 +1,220 @@
1
+ import fs from 'node:fs/promises';
2
+ import { existsSync, statSync, createWriteStream } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { execFileSync } from 'node:child_process';
5
+ import { resolveUserPath } from '../utils/paths.js';
6
+ import { loadCapabilityPackage } from '../provisioning/capabilityProvisioner.js';
7
+
8
+ export interface ArchiveArgs {
9
+ action: 'compress' | 'extract';
10
+ source: string;
11
+ destination: string;
12
+ }
13
+
14
+ export interface ArchiveResult {
15
+ success: boolean;
16
+ output?: string;
17
+ error?: string;
18
+ requiresConsent?: boolean;
19
+ }
20
+
21
+ export const archive = {
22
+ schema: {
23
+ name: 'archive',
24
+ description: 'Compress or extract archives securely with zero friction (supports .zip, .tar, .tar.gz, .tgz with native system fallbacks).',
25
+ parameters: {
26
+ type: 'object',
27
+ properties: {
28
+ action: { type: 'string', enum: ['compress', 'extract'], description: 'Action to perform: "compress" or "extract"' },
29
+ source: { type: 'string', description: 'Absolute or relative path of the file/directory to compress or extract' },
30
+ destination: { type: 'string', description: 'Absolute or relative path for the output file or directory' }
31
+ },
32
+ required: ['action', 'source', 'destination']
33
+ }
34
+ },
35
+
36
+ async execute(args: ArchiveArgs): Promise<ArchiveResult> {
37
+ try {
38
+ if (!args || !args.action || !args.source || !args.destination) {
39
+ return { success: false, error: 'Missing required arguments: action, source, destination' };
40
+ }
41
+
42
+ const source = resolveUserPath(args.source);
43
+ const dest = resolveUserPath(args.destination);
44
+
45
+ if (!existsSync(source)) {
46
+ return { success: false, error: `Archive source path not found: ${source}` };
47
+ }
48
+
49
+ if (args.action === 'extract') {
50
+ return await extractArchive(source, dest);
51
+ } else if (args.action === 'compress') {
52
+ return await compressArchive(source, dest);
53
+ } else {
54
+ return { success: false, error: `Unsupported archive action: ${(args as any).action}` };
55
+ }
56
+ } catch (error: any) {
57
+ return { success: false, error: `Archive action failed: ${error?.message || String(error)}` };
58
+ }
59
+ }
60
+ };
61
+
62
+ async function extractArchive(source: string, dest: string): Promise<ArchiveResult> {
63
+ await fs.mkdir(dest, { recursive: true });
64
+
65
+ // 1. Try capability package extract-zip if already available in environment
66
+ try {
67
+ const extract = await loadCapabilityPackage('extract-zip');
68
+ if (typeof extract === 'function') {
69
+ await extract(source, { dir: dest });
70
+ return { success: true, output: `Extracted successfully to ${dest}` };
71
+ }
72
+ } catch {
73
+ // Fall through to native zero-dependency extractors
74
+ }
75
+
76
+ const isZip = source.toLowerCase().endsWith('.zip') || source.toLowerCase().endsWith('.jar');
77
+ const isTar = /\.(tar|tar\.gz|tgz|tar\.bz2|tar\.xz)$/i.test(source);
78
+
79
+ // 2. Native unzip on macOS / Linux
80
+ if (isZip) {
81
+ try {
82
+ execFileSync('unzip', ['-q', '-o', source, '-d', dest], { stdio: 'pipe' });
83
+ return { success: true, output: `Extracted successfully to ${dest} (via unzip)` };
84
+ } catch {
85
+ // Fall through to python3 or powershell
86
+ }
87
+ }
88
+
89
+ // 3. Native tar on macOS / Linux
90
+ if (isTar || !isZip) {
91
+ try {
92
+ execFileSync('tar', ['-xf', source, '-C', dest], { stdio: 'pipe' });
93
+ return { success: true, output: `Extracted successfully to ${dest} (via tar)` };
94
+ } catch {
95
+ // Fall through
96
+ }
97
+ }
98
+
99
+ // 4. Cross-platform Python standard library fallback
100
+ try {
101
+ execFileSync('python3', [
102
+ '-c',
103
+ 'import zipfile, tarfile, sys, os\n' +
104
+ 'src, dst = sys.argv[1], sys.argv[2]\n' +
105
+ 'if zipfile.is_zipfile(src):\n' +
106
+ ' with zipfile.ZipFile(src, "r") as z:\n' +
107
+ ' z.extractall(dst)\n' +
108
+ 'elif tarfile.is_tarfile(src):\n' +
109
+ ' with tarfile.open(src, "r:*") as t:\n' +
110
+ ' t.extractall(dst)\n' +
111
+ 'else:\n' +
112
+ ' raise ValueError("Unrecognized archive format")\n',
113
+ source,
114
+ dest
115
+ ], { stdio: 'pipe' });
116
+ return { success: true, output: `Extracted successfully to ${dest} (via python3)` };
117
+ } catch {
118
+ // Fall through
119
+ }
120
+
121
+ // 5. Windows PowerShell fallback
122
+ if (process.platform === 'win32') {
123
+ try {
124
+ const psScript = `Expand-Archive -Path '${source.replace(/'/g, "''")}' -DestinationPath '${dest.replace(/'/g, "''")}' -Force`;
125
+ execFileSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', psScript], { stdio: 'pipe' });
126
+ return { success: true, output: `Extracted successfully to ${dest} (via PowerShell)` };
127
+ } catch (e: any) {
128
+ return { success: false, error: `PowerShell extraction failed: ${e.message}` };
129
+ }
130
+ }
131
+
132
+ return { success: false, error: `Could not extract ${source}: no supported extractor found on system.` };
133
+ }
134
+
135
+ async function compressArchive(source: string, dest: string): Promise<ArchiveResult> {
136
+ const destDir = path.dirname(dest);
137
+ await fs.mkdir(destDir, { recursive: true });
138
+
139
+ // 1. Try capability package archiver if available
140
+ try {
141
+ const archiver = await loadCapabilityPackage('archiver');
142
+ if (typeof archiver === 'function') {
143
+ return await new Promise<ArchiveResult>(async (resolve) => {
144
+ const output = createWriteStream(dest);
145
+ const format = dest.toLowerCase().endsWith('.tar') || dest.toLowerCase().endsWith('.tar.gz') ? 'tar' : 'zip';
146
+ const archiveStream = archiver(format, { zlib: { level: 9 } });
147
+
148
+ output.on('close', () => resolve({ success: true, output: `Compressed ${archiveStream.pointer()} total bytes to ${dest}` }));
149
+ archiveStream.on('error', (err: any) => resolve({ success: false, error: err.message }));
150
+
151
+ archiveStream.pipe(output);
152
+
153
+ const stat = statSync(source);
154
+ if (stat.isDirectory()) {
155
+ archiveStream.directory(source, false);
156
+ } else {
157
+ archiveStream.file(source, { name: path.basename(source) });
158
+ }
159
+ await archiveStream.finalize();
160
+ });
161
+ }
162
+ } catch {
163
+ // Fall through to native system compress
164
+ }
165
+
166
+ const isZip = dest.toLowerCase().endsWith('.zip');
167
+ const isTar = /\.(tar|tar\.gz|tgz)$/i.test(dest);
168
+ const stat = statSync(source);
169
+
170
+ // 2. Native zip on macOS / Linux
171
+ if (isZip) {
172
+ try {
173
+ if (stat.isDirectory()) {
174
+ execFileSync('zip', ['-q', '-r', dest, '.'], { cwd: source, stdio: 'pipe' });
175
+ } else {
176
+ execFileSync('zip', ['-q', dest, path.basename(source)], { cwd: path.dirname(source), stdio: 'pipe' });
177
+ }
178
+ return { success: true, output: `Compressed successfully to ${dest} (via zip)` };
179
+ } catch {
180
+ // Fall through
181
+ }
182
+ }
183
+
184
+ // 3. Native tar on macOS / Linux
185
+ if (isTar) {
186
+ try {
187
+ if (stat.isDirectory()) {
188
+ execFileSync('tar', ['-czf', dest, '-C', source, '.'], { stdio: 'pipe' });
189
+ } else {
190
+ execFileSync('tar', ['-czf', dest, '-C', path.dirname(source), path.basename(source)], { stdio: 'pipe' });
191
+ }
192
+ return { success: true, output: `Compressed successfully to ${dest} (via tar)` };
193
+ } catch {
194
+ // Fall through
195
+ }
196
+ }
197
+
198
+ // 4. Cross-platform Python fallback
199
+ try {
200
+ execFileSync('python3', [
201
+ '-c',
202
+ 'import zipfile, os, sys\n' +
203
+ 'src, dst = sys.argv[1], sys.argv[2]\n' +
204
+ 'with zipfile.ZipFile(dst, "w", zipfile.ZIP_DEFLATED) as z:\n' +
205
+ ' if os.path.isdir(src):\n' +
206
+ ' for root, dirs, files in os.walk(src):\n' +
207
+ ' for file in files:\n' +
208
+ ' full = os.path.join(root, file)\n' +
209
+ ' rel = os.path.relpath(full, src)\n' +
210
+ ' z.write(full, rel)\n' +
211
+ ' else:\n' +
212
+ ' z.write(src, os.path.basename(src))\n',
213
+ source,
214
+ dest
215
+ ], { stdio: 'pipe' });
216
+ return { success: true, output: `Compressed successfully to ${dest} (via python3 zipfile)` };
217
+ } catch (pyErr: any) {
218
+ return { success: false, error: `Compression failed: ${pyErr?.message || String(pyErr)}` };
219
+ }
220
+ }
@@ -1,8 +1,51 @@
1
- import { BrowserCapabilityError, causyneBrowser } from '../browser/causyneBrowser.js';
1
+ import { BrowserCapabilityError, causyneBrowser, getSupportedSearchMacros } from '../browser/causyneBrowser.js';
2
+ const SUPPORTED_ACTION_TYPES = [
3
+ 'newTab', 'new_tab',
4
+ 'switchTab', 'switch_tab',
5
+ 'listTabs', 'list_tabs',
6
+ 'closeTab', 'close_tab',
7
+ 'search',
8
+ 'goto', 'open', 'navigate',
9
+ 'snapshot', 'scrape',
10
+ 'click', 'clickIndex',
11
+ 'type', 'typeIndex', 'fill',
12
+ 'selectOption', 'select',
13
+ 'keyPress', 'press',
14
+ 'hover',
15
+ 'scroll',
16
+ 'wait',
17
+ 'viewport',
18
+ 'back', 'forward', 'reload', 'refresh',
19
+ 'extract', 'links', 'images',
20
+ 'upload', 'download', 'screenshot'
21
+ ];
22
+ function normalizeActions(args) {
23
+ if (!args || typeof args !== 'object')
24
+ return [];
25
+ if (Array.isArray(args.actions)) {
26
+ return args.actions.map(item => {
27
+ if (item && typeof item === 'object' && !('type' in item) && typeof item.action === 'string') {
28
+ const { action, ...rest } = item;
29
+ return { ...rest, type: action };
30
+ }
31
+ return item;
32
+ });
33
+ }
34
+ const singleType = typeof args.type === 'string'
35
+ ? args.type
36
+ : typeof args.action === 'string'
37
+ ? args.action
38
+ : null;
39
+ if (singleType) {
40
+ const { action: _action, ...rest } = args;
41
+ return [{ ...rest, type: singleType }];
42
+ }
43
+ return [];
44
+ }
2
45
  export const browserAct = {
3
46
  schema: {
4
47
  name: 'browser.act',
5
- description: 'Use the dedicated Causyne Browser for resilient search, navigation, accessible snapshots, interaction, extraction, and workspace-scoped downloads. Take a snapshot before interacting by ref.',
48
+ description: `Use the dedicated Causyne Browser for resilient search, navigation, search macros (${getSupportedSearchMacros().slice(0, 6).join(', ')}, etc.), accessible snapshots (including child iframes and structured forms/tables), interaction, deterministic schema extraction, and workspace-scoped uploads/downloads. Take a snapshot before interacting by ref.`,
6
49
  parameters: {
7
50
  type: 'object',
8
51
  properties: {
@@ -15,20 +58,44 @@ export const browserAct = {
15
58
  properties: {
16
59
  type: {
17
60
  type: 'string',
18
- enum: ['newTab', 'switchTab', 'listTabs', 'closeTab', 'search', 'goto', 'snapshot', 'scrape', 'click', 'clickIndex', 'type', 'typeIndex', 'selectOption', 'keyPress', 'scroll', 'back', 'forward', 'reload', 'extract', 'download', 'screenshot']
61
+ enum: SUPPORTED_ACTION_TYPES
19
62
  },
20
63
  tabId: { type: 'string', description: 'Tab id returned by newTab or listTabs.' },
21
- url: { type: 'string', description: 'Public http(s) URL for goto or newTab.' },
22
- query: { type: 'string', description: 'Search query.' },
64
+ url: { type: 'string', description: 'Public http(s) URL or @macro_search shorthand for goto/newTab.' },
65
+ macro: { type: 'string', description: 'Search macro such as @google_search, @youtube_search, @wikipedia_search, @reddit_search, @amazon_search.' },
66
+ query: { type: 'string', description: 'Search query for search action or search macro.' },
23
67
  ref: { type: 'string', description: 'Current accessibility ref, for example e12.' },
24
68
  index: { type: 'number', description: 'Legacy numeric form of an accessibility ref.' },
25
69
  selector: { type: 'string', description: 'CSS selector when a current accessibility ref is unavailable.' },
26
70
  text: { type: 'string' },
27
71
  value: { type: 'string' },
28
- key: { type: 'string' },
72
+ option: { type: 'string', description: 'Option value or visible label for selectOption/select.' },
73
+ key: { type: 'string', description: 'Keyboard key or chord (e.g. Enter, Escape, Control+a, Meta+k).' },
74
+ mode: { type: 'string', enum: ['fill', 'keyboard'], description: 'Typing mode for type/fill action.' },
75
+ delay: { type: 'number', description: 'Per-character delay in ms when mode is keyboard.' },
76
+ submit: { type: 'boolean', description: 'Press Enter after typing text.' },
77
+ pressEnter: { type: 'boolean', description: 'Alias for submit: press Enter after typing text.' },
78
+ doubleClick: { type: 'boolean', description: 'Perform a double click instead of a single click.' },
29
79
  direction: { type: 'string', enum: ['up', 'down', 'left', 'right'] },
30
80
  amount: { type: 'number' },
31
- offset: { type: 'number', description: 'Character offset for a paged accessibility snapshot.' },
81
+ offset: { type: 'number', description: 'Character offset for a paged accessibility snapshot or links pagination.' },
82
+ limit: { type: 'number', description: 'Maximum number of links or images to return.' },
83
+ timeout: { type: 'number', description: 'Wait timeout in milliseconds for wait action.' },
84
+ waitForNetwork: { type: 'boolean', description: 'Wait for networkidle during wait action.' },
85
+ dismissConsent: { type: 'boolean', description: 'Automatically dismiss common cookie/consent banners.' },
86
+ width: { type: 'number', description: 'Viewport width in pixels (100-4000) for viewport action.' },
87
+ height: { type: 'number', description: 'Viewport height in pixels (100-4000) for viewport action.' },
88
+ schema: {
89
+ type: 'object',
90
+ description: 'Deterministic JSON Schema with x-ref annotations for extract action.'
91
+ },
92
+ filePath: {
93
+ oneOf: [
94
+ { type: 'string' },
95
+ { type: 'array', items: { type: 'string' } }
96
+ ],
97
+ description: 'Workspace-relative file path(s) for upload action.'
98
+ },
32
99
  outputFile: { type: 'string', description: 'Download or screenshot destination inside the selected workspace.' },
33
100
  fullPage: { type: 'boolean', description: 'Capture the complete page for a screenshot instead of the visible viewport.' }
34
101
  },
@@ -41,9 +108,11 @@ export const browserAct = {
41
108
  additionalProperties: false
42
109
  }
43
110
  },
44
- async execute(args) {
111
+ async execute(args, sandbox) {
45
112
  try {
46
- const results = await causyneBrowser().run(args.actions ?? []);
113
+ const workspace = sandbox?.workspacePaths?.[0] ?? sandbox?.workspaceRoot ?? process.cwd();
114
+ const actions = normalizeActions(args);
115
+ const results = await causyneBrowser({ workspace }).run(actions, { workspace });
47
116
  return { success: true, output: JSON.stringify(results, null, 2), data: results };
48
117
  }
49
118
  catch (error) {