@causyne/agent 1.20.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.
- package/README.md +0 -18
- package/package.json +1 -1
- package/src/acp/client.js +2 -1
- package/src/acp/client.ts +2 -1
- package/src/acp/server.js +5 -6
- package/src/acp/server.ts +4 -6
- package/src/agentLoop.d.ts +1 -0
- package/src/agentLoop.js +505 -241
- package/src/agentLoop.ts +527 -258
- package/src/agentPolicy.js +9 -0
- package/src/agentPolicy.ts +9 -0
- package/src/approvalPolicy.js +55 -0
- package/src/approvalPolicy.ts +66 -0
- package/src/browser/browserRuntime.js +217 -14
- package/src/browser/browserRuntime.ts +255 -14
- package/src/browser/causyneBrowser.js +1215 -68
- package/src/browser/causyneBrowser.ts +1340 -72
- package/src/cliMode.js +52 -29
- package/src/commands.js +141 -17
- package/src/config.js +22 -12
- package/src/continuum/ui/continuumPicker.js +18 -1
- package/src/continuum/ui/continuumPicker.ts +19 -1
- package/src/dynamicCatalogue.js +87 -20
- package/src/dynamicCatalogue.ts +85 -15
- package/src/launchIntent.js +40 -0
- package/src/launchIntent.ts +49 -0
- package/src/memoryManager.js +26 -2
- package/src/modelCatalogue.js +2 -0
- package/src/planCache.js +320 -11
- package/src/planCache.ts +402 -13
- package/src/providers/acp.js +67 -1
- package/src/providers/acp.ts +65 -2
- package/src/providers/antigravity.d.ts +5 -1
- package/src/providers/antigravity.js +643 -32
- package/src/providers/antigravity.ts +671 -33
- package/src/providers/base.d.ts +9 -0
- package/src/providers/factory.js +2 -0
- package/src/providers/pi.js +157 -0
- package/src/providers/pi.ts +144 -0
- package/src/provisioning/capabilityProvisioner.js +17 -0
- package/src/provisioning/capabilityTools.js +1 -1
- package/src/sandbox.js +30 -39
- package/src/sessionJournal.js +53 -10
- package/src/sessionJournal.ts +64 -10
- package/src/taskShape.js +9 -9
- package/src/taskShape.ts +9 -9
- package/src/timeMachine.js +124 -0
- package/src/timeMachine.ts +141 -0
- package/src/toolPacks.js +4 -10
- package/src/tools/archive.js +196 -59
- package/src/tools/archive.ts +220 -0
- package/src/tools/browserAutomator.js +78 -9
- package/src/tools/browserAutomator.ts +90 -9
- package/src/tools/desktopOpen.js +114 -31
- package/src/tools/desktopOpen.ts +144 -0
- package/src/tools/gitExec.js +5 -3
- package/src/tools/nativeEngine.js +4 -3
- package/src/tools/nativeEngine.ts +5 -3
- package/src/tools/openSourceToolProvisioner.js +5 -4
- package/src/tools/openSourceToolProvisioner.ts +5 -4
- package/src/tools/registry.js +3 -0
- package/src/tools/screenshot.js +55 -71
- package/src/tools/screenshot.ts +70 -0
- package/src/tools/sysRun.js +284 -117
- package/src/tools/sysRun.ts +347 -0
- package/src/tools/toolSelfRepair.js +109 -2
- package/src/tools/toolSelfRepair.ts +100 -2
- package/src/tools/updatePlan.js +49 -1
- package/src/tools/updatePlan.ts +43 -1
- package/src/tools/viewImage.js +93 -78
- package/src/tools/viewImage.ts +116 -0
- package/src/tools/webFetch.js +20 -6
- package/src/tools/webFetch.ts +26 -6
- package/src/tui/block.d.ts +1 -0
- package/src/tui/chatRenderer.d.ts +21 -0
- package/src/tui/chatRenderer.js +34 -47
- package/src/tui/clipboardSync.js +28 -1
- package/src/tui/clipboardSync.ts +26 -1
- package/src/tui/codeProgress.js +299 -0
- package/src/tui/codeProgress.ts +304 -0
- package/src/tui/codeStreamRenderer.js +116 -0
- package/src/tui/codeStreamRenderer.ts +124 -0
- package/src/tui/commandPresentation.js +11 -0
- package/src/tui/commandPresentation.ts +18 -0
- package/src/tui/completion.js +45 -13
- package/src/tui/composerControls.js +66 -0
- package/src/tui/composerControls.ts +78 -0
- package/src/tui/diff.d.ts +2 -0
- package/src/tui/home.js +4 -2
- package/src/tui/homeTransition.js +21 -0
- package/src/tui/homeTransition.ts +27 -0
- package/src/tui/homeView.js +62 -0
- package/src/tui/homeView.ts +91 -0
- package/src/tui/layout.js +46 -0
- package/src/tui/layout.ts +52 -0
- package/src/tui/messageActionPlacement.js +16 -0
- package/src/tui/messageActionPlacement.ts +25 -0
- package/src/tui/messageInteraction.js +221 -0
- package/src/tui/messageInteraction.ts +275 -0
- package/src/tui/modelPicker.js +4 -24
- package/src/tui/modelPicker.ts +4 -20
- package/src/tui/mouseHover.js +6 -0
- package/src/tui/mouseHover.ts +5 -0
- package/src/tui/prompt.js +152 -76
- package/src/tui/resizeRecovery.js +15 -0
- package/src/tui/resizeRecovery.ts +27 -0
- package/src/tui/scrollInteraction.js +97 -0
- package/src/tui/scrollInteraction.ts +189 -0
- package/src/tui/sessionLayout.js +12 -0
- package/src/tui/sessionLayout.ts +12 -0
- package/src/tui/sessionPicker.js +111 -16
- package/src/tui/sessionPicker.ts +121 -16
- package/src/tui/sessionSidebar.js +78 -0
- package/src/tui/sessionSidebar.ts +95 -0
- package/src/tui/setup.js +1 -1
- package/src/tui/setup.ts +1 -1
- package/src/tui/stageSurface.js +120 -58
- package/src/tui/text.d.ts +5 -0
- package/src/tui/textLayout.js +23 -0
- package/src/tui/textLayout.ts +28 -0
- package/src/tui/viewport.js +204 -279
- package/src/tui/viewport.ts +326 -0
- package/src/types/contracts.ts +54 -0
- package/src/utils/paths.js +5 -4
- package/src/utils/paths.ts +5 -5
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Causyne Agent — System Command Execution (sysRun & sysRunBg)
|
|
3
|
+
*
|
|
4
|
+
* Provides robust subprocess execution with:
|
|
5
|
+
* 1. Semantic exit code normalization (POSIX grep, diff, test, which, cmp exit codes
|
|
6
|
+
* treated as valid non-error queries rather than fatal crashes).
|
|
7
|
+
* 2. In-memory execution deduplication cache for read-only / diagnostic commands
|
|
8
|
+
* to prevent infinite retry thrashing.
|
|
9
|
+
* 3. ANSI color/control sequence stripping for clean tool output.
|
|
10
|
+
* 4. Ring-buffered output truncation (50KB cap) to protect LLM context windows.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { spawn } from 'node:child_process';
|
|
14
|
+
import os from 'node:os';
|
|
15
|
+
import { isLaunchOnlyPrompt, isServerLaunchCommand } from '../launchIntent.js';
|
|
16
|
+
|
|
17
|
+
export interface SysRunArgs {
|
|
18
|
+
command: string;
|
|
19
|
+
cwd?: string;
|
|
20
|
+
timeout?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface SysRunResult {
|
|
24
|
+
success: boolean;
|
|
25
|
+
output: string;
|
|
26
|
+
error?: string | undefined;
|
|
27
|
+
exitCode: number;
|
|
28
|
+
note?: string | undefined;
|
|
29
|
+
cached?: boolean | undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface SysRunContext {
|
|
33
|
+
signal?: AbortSignal | undefined;
|
|
34
|
+
skipCache?: boolean | undefined;
|
|
35
|
+
parentLoop?: { currentTaskPrompt?: string; userPrompt?: string } | undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface SysRunBgArgs {
|
|
39
|
+
command: string;
|
|
40
|
+
cwd?: string | undefined;
|
|
41
|
+
label: string;
|
|
42
|
+
maxDuration?: number | undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface SysRunBgResult {
|
|
46
|
+
success: boolean;
|
|
47
|
+
output?: string | undefined;
|
|
48
|
+
pid?: number | undefined;
|
|
49
|
+
error?: string | undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Strips ANSI escape sequences and terminal control codes from string output.
|
|
54
|
+
*/
|
|
55
|
+
export function stripAnsi(str: string): string {
|
|
56
|
+
const pattern = [
|
|
57
|
+
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
|
|
58
|
+
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))'
|
|
59
|
+
].join('|');
|
|
60
|
+
return str.replace(new RegExp(pattern, 'g'), '');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Commands whose exit code 1 indicates a normal query result (e.g. no matches found,
|
|
65
|
+
* differences found, or condition evaluated to false) rather than a system error.
|
|
66
|
+
*/
|
|
67
|
+
export const SEARCH_COMMAND_PATTERN = /(^|\s|\||&&|;)(grep|egrep|fgrep|diff|test|which|cmp|find)(\s|$)/;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Commands that are strictly read-only and idempotent.
|
|
71
|
+
* Repeated identical executions within a short TTL window return cached output.
|
|
72
|
+
*/
|
|
73
|
+
export const IDEMPOTENT_COMMAND_PATTERN =
|
|
74
|
+
/^(python3?|node|bun|pnpm|npm)\s+(-v|--version|(-c|-e)\s+["'].*?["'])$|^ls\b|^cat\b|^head\b|^tail\b|^grep\b|^find\b|^which\b|^where\b|^pwd$|^git\s+(status|log|diff|branch|tag|show\b)|^echo\b/;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Detect long-running dev servers and web application listeners that must not block foreground loops.
|
|
78
|
+
*/
|
|
79
|
+
export function isPersistentServerCommand(cmd: string): boolean {
|
|
80
|
+
if (!cmd || typeof cmd !== 'string') return false;
|
|
81
|
+
const trimmed = cmd.trim();
|
|
82
|
+
if (/^(?:cat|head|tail|grep|lsof|ps|kill|pkill|pgrep|curl|wget|echo|test)\b/i.test(trimmed)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
const patterns = [
|
|
86
|
+
/(?:^|[;&|\s])(?:python[0-9.]*|node|deno|bun)\s+.*(?:server|app|main)\.(?:py|js|ts|mjs|cjs)\b/i,
|
|
87
|
+
/(?:^|[;&|\s])python[0-9.]*\s+-m\s+http\.server\b/i,
|
|
88
|
+
/(?:^|[;&|\s])(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:dev|start|serve)\b/i,
|
|
89
|
+
/(?:^|[;&|\s])(?:npx\s+)?(?:serve|vite|live-server|http-server)\b/i,
|
|
90
|
+
/(?:^|[;&|\s])(?:flask\s+run|uvicorn|gunicorn)\b/i,
|
|
91
|
+
/(?:^|[;&|\s])(?:\.\/start\.sh|bash\s+start\.sh|sh\s+start\.sh)\b/i
|
|
92
|
+
];
|
|
93
|
+
return patterns.some(pattern => pattern.test(trimmed));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export const SERVER_READY_PATTERN =
|
|
97
|
+
/(?:https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0):[0-9]+|serving\s+http\s+on|server\s+(?:running|started)|ready\s+in\s+[0-9]+|terra_server_running)/i;
|
|
98
|
+
|
|
99
|
+
interface CachedCommandResult {
|
|
100
|
+
output: string;
|
|
101
|
+
exitCode: number;
|
|
102
|
+
success: boolean;
|
|
103
|
+
note?: string | undefined;
|
|
104
|
+
timestamp: number;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const COMMAND_CACHE_TTL_MS = 60_000;
|
|
108
|
+
const commandCache = new Map<string, CachedCommandResult>();
|
|
109
|
+
|
|
110
|
+
export function clearSysRunCache(): void {
|
|
111
|
+
commandCache.clear();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export const sysRun = {
|
|
115
|
+
schema: {
|
|
116
|
+
name: 'sysRun',
|
|
117
|
+
description:
|
|
118
|
+
'Execute a shell command. CRITICAL CONSTRAINTS: 1. NEVER use interactive flags (like git rebase -i). 2. Always use non-interactive flags (--yes, -y). 3. If running git commit, always run git status, git diff, and git log first.',
|
|
119
|
+
parameters: {
|
|
120
|
+
type: 'object',
|
|
121
|
+
properties: {
|
|
122
|
+
command: { type: 'string', description: 'The shell command to run' },
|
|
123
|
+
cwd: { type: 'string', description: 'Working directory' },
|
|
124
|
+
timeout: { type: 'number', description: 'Timeout in ms (default 60000)' }
|
|
125
|
+
},
|
|
126
|
+
required: ['command']
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
async execute(args: SysRunArgs, context: SysRunContext = {}): Promise<SysRunResult> {
|
|
131
|
+
const rawCommand = (args?.command || '').trim();
|
|
132
|
+
const cwd = args?.cwd ? args.cwd.replace(/^~\//, os.homedir() + '/') : process.cwd();
|
|
133
|
+
const timeoutMs = args?.timeout || 60000;
|
|
134
|
+
const signal = context.signal;
|
|
135
|
+
|
|
136
|
+
// A foreground server waits forever for requests. Keep launch-only turns
|
|
137
|
+
// responsive and make it explicit that starting is not a readiness check.
|
|
138
|
+
const taskPrompt = context.parentLoop?.currentTaskPrompt || context.parentLoop?.userPrompt || '';
|
|
139
|
+
if (isLaunchOnlyPrompt(taskPrompt) && isServerLaunchCommand(rawCommand)) {
|
|
140
|
+
const started = await sysRunBg.execute({ command: rawCommand, cwd, label: 'local-server' });
|
|
141
|
+
return started.success
|
|
142
|
+
? { success: true, output: `Started server process ${started.pid} in background. Readiness and browser opening have not been verified.`, exitCode: 0, note: 'Check the server URL before reporting it accessible.' }
|
|
143
|
+
: { success: false, output: '', error: started.error || 'Unable to start server process.', exitCode: 1 };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Fast-path: Return cached output for identical read-only idempotent commands
|
|
147
|
+
const isIdempotent = IDEMPOTENT_COMMAND_PATTERN.test(rawCommand);
|
|
148
|
+
const cacheKey = `${cwd}:::${rawCommand}`;
|
|
149
|
+
|
|
150
|
+
if (!context.skipCache && isIdempotent && commandCache.has(cacheKey)) {
|
|
151
|
+
const cached = commandCache.get(cacheKey)!;
|
|
152
|
+
if (Date.now() - cached.timestamp < COMMAND_CACHE_TTL_MS) {
|
|
153
|
+
return {
|
|
154
|
+
success: cached.success,
|
|
155
|
+
output: cached.output,
|
|
156
|
+
exitCode: cached.exitCode,
|
|
157
|
+
cached: true,
|
|
158
|
+
note: cached.note || 'Returned cached output from recent identical execution.'
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
commandCache.delete(cacheKey);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let executedCommand = rawCommand;
|
|
165
|
+
if (os.platform() !== 'win32' && /(?:^|\s)&\s*$/.test(rawCommand) && !/[><]/.test(rawCommand)) {
|
|
166
|
+
executedCommand = rawCommand.replace(/\s*&\s*$/, ' >/dev/null 2>&1 &');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return new Promise<SysRunResult>((resolve) => {
|
|
170
|
+
const shell = os.platform() === 'win32' ? 'cmd.exe' : '/bin/bash';
|
|
171
|
+
const shellArgs = os.platform() === 'win32' ? ['/c', executedCommand] : ['-c', executedCommand];
|
|
172
|
+
|
|
173
|
+
let child: ReturnType<typeof spawn>;
|
|
174
|
+
try {
|
|
175
|
+
child = spawn(shell, shellArgs, { cwd, signal });
|
|
176
|
+
} catch (err: unknown) {
|
|
177
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
178
|
+
resolve({
|
|
179
|
+
success: false,
|
|
180
|
+
output: '',
|
|
181
|
+
error: errorMsg,
|
|
182
|
+
exitCode: 1
|
|
183
|
+
});
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Phase 1 AGI Upgrade: 50KB Ring Buffer (FIFO)
|
|
188
|
+
const MAX_LENGTH = 50000;
|
|
189
|
+
let outputBuffer = '';
|
|
190
|
+
let isDetached = false;
|
|
191
|
+
|
|
192
|
+
const checkServerDetach = (): void => {
|
|
193
|
+
if (isDetached) return;
|
|
194
|
+
if (isPersistentServerCommand(rawCommand) || isServerLaunchCommand(rawCommand)) {
|
|
195
|
+
if (SERVER_READY_PATTERN.test(outputBuffer)) {
|
|
196
|
+
isDetached = true;
|
|
197
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
198
|
+
if (serverGraceTimer) clearTimeout(serverGraceTimer);
|
|
199
|
+
child.unref();
|
|
200
|
+
resolve({
|
|
201
|
+
success: true,
|
|
202
|
+
output: stripAnsi(outputBuffer),
|
|
203
|
+
exitCode: 0,
|
|
204
|
+
note: 'Server readiness verified. Running in background.'
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const appendToBuffer = (data: Buffer | string): void => {
|
|
211
|
+
outputBuffer += data.toString();
|
|
212
|
+
if (outputBuffer.length > MAX_LENGTH) {
|
|
213
|
+
outputBuffer = '...[OUTPUT TRUNCATED]...\n' + outputBuffer.slice(outputBuffer.length - MAX_LENGTH);
|
|
214
|
+
}
|
|
215
|
+
checkServerDetach();
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
child.stdout?.on('data', appendToBuffer);
|
|
219
|
+
child.stderr?.on('data', appendToBuffer);
|
|
220
|
+
|
|
221
|
+
let serverGraceTimer: NodeJS.Timeout | undefined;
|
|
222
|
+
if (isPersistentServerCommand(rawCommand) || isServerLaunchCommand(rawCommand)) {
|
|
223
|
+
serverGraceTimer = setTimeout(() => {
|
|
224
|
+
if (!isDetached && child.exitCode === null) {
|
|
225
|
+
isDetached = true;
|
|
226
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
227
|
+
child.unref();
|
|
228
|
+
resolve({
|
|
229
|
+
success: true,
|
|
230
|
+
output: stripAnsi(outputBuffer) || 'Server process started and running in background.',
|
|
231
|
+
exitCode: 0,
|
|
232
|
+
note: 'Server detached after clean execution.'
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}, 2500);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
let timeoutId: NodeJS.Timeout | undefined;
|
|
239
|
+
if (timeoutMs > 0) {
|
|
240
|
+
timeoutId = setTimeout(() => {
|
|
241
|
+
if (isDetached) return;
|
|
242
|
+
if (serverGraceTimer) clearTimeout(serverGraceTimer);
|
|
243
|
+
child.kill('SIGKILL');
|
|
244
|
+
resolve({
|
|
245
|
+
success: false,
|
|
246
|
+
output: stripAnsi(outputBuffer),
|
|
247
|
+
error: `Process timed out after ${timeoutMs}ms`,
|
|
248
|
+
exitCode: 124
|
|
249
|
+
});
|
|
250
|
+
}, timeoutMs);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
child.on('error', (err: Error) => {
|
|
254
|
+
if (isDetached) return;
|
|
255
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
256
|
+
if (serverGraceTimer) clearTimeout(serverGraceTimer);
|
|
257
|
+
resolve({
|
|
258
|
+
success: false,
|
|
259
|
+
output: stripAnsi(outputBuffer),
|
|
260
|
+
error: err.message,
|
|
261
|
+
exitCode: 1
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
child.on('close', (code: number | null) => {
|
|
266
|
+
if (isDetached) return;
|
|
267
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
268
|
+
if (serverGraceTimer) clearTimeout(serverGraceTimer);
|
|
269
|
+
const cleanOutput = stripAnsi(outputBuffer);
|
|
270
|
+
const exitCode = typeof code === 'number' ? code : 1;
|
|
271
|
+
|
|
272
|
+
if (exitCode === 0) {
|
|
273
|
+
const res: SysRunResult = { success: true, output: cleanOutput, exitCode: 0 };
|
|
274
|
+
if (isIdempotent) {
|
|
275
|
+
commandCache.set(cacheKey, {
|
|
276
|
+
output: cleanOutput,
|
|
277
|
+
exitCode: 0,
|
|
278
|
+
success: true,
|
|
279
|
+
timestamp: Date.now()
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
resolve(res);
|
|
283
|
+
} else if (exitCode === 1 && SEARCH_COMMAND_PATTERN.test(rawCommand)) {
|
|
284
|
+
// Semantic Exit Code Normalization: POSIX search tool found 0 matching lines.
|
|
285
|
+
const res: SysRunResult = {
|
|
286
|
+
success: true,
|
|
287
|
+
output: cleanOutput || '(no matches found)',
|
|
288
|
+
exitCode: 1,
|
|
289
|
+
note: 'Command executed successfully with 0 search matches.'
|
|
290
|
+
};
|
|
291
|
+
if (isIdempotent) {
|
|
292
|
+
commandCache.set(cacheKey, {
|
|
293
|
+
output: res.output,
|
|
294
|
+
exitCode: 1,
|
|
295
|
+
success: true,
|
|
296
|
+
note: res.note,
|
|
297
|
+
timestamp: Date.now()
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
resolve(res);
|
|
301
|
+
} else {
|
|
302
|
+
if (signal && signal.aborted) {
|
|
303
|
+
resolve({ success: false, output: cleanOutput, error: 'Process killed by user.', exitCode: 1 });
|
|
304
|
+
} else {
|
|
305
|
+
resolve({ success: false, output: cleanOutput, error: `Command exited with code ${exitCode}`, exitCode });
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
export const sysRunBg = {
|
|
314
|
+
schema: {
|
|
315
|
+
name: 'sysRunBg',
|
|
316
|
+
description: 'Start a long-running process in background (dev servers, watchers)',
|
|
317
|
+
parameters: {
|
|
318
|
+
type: 'object',
|
|
319
|
+
properties: {
|
|
320
|
+
command: { type: 'string' },
|
|
321
|
+
cwd: { type: 'string' },
|
|
322
|
+
label: { type: 'string' },
|
|
323
|
+
maxDuration: { type: 'number' }
|
|
324
|
+
},
|
|
325
|
+
required: ['command', 'label']
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
|
|
329
|
+
async execute(args: SysRunBgArgs): Promise<SysRunBgResult> {
|
|
330
|
+
try {
|
|
331
|
+
const cwd = args.cwd ? args.cwd.replace(/^~\//, os.homedir() + '/') : process.cwd();
|
|
332
|
+
const shell = os.platform() === 'win32' ? 'cmd.exe' : '/bin/bash';
|
|
333
|
+
const shellArgs = os.platform() === 'win32' ? ['/c', args.command] : ['-c', args.command];
|
|
334
|
+
return await new Promise<SysRunBgResult>(resolve => {
|
|
335
|
+
const child = spawn(shell, shellArgs, { cwd, detached: true, stdio: 'ignore' });
|
|
336
|
+
child.once('error', error => resolve({ success: false, error: error.message }));
|
|
337
|
+
child.once('spawn', () => {
|
|
338
|
+
child.unref();
|
|
339
|
+
resolve({ success: true, output: `Background process launched [${args.label}]; readiness not verified.`, pid: child.pid });
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
} catch (e: unknown) {
|
|
343
|
+
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
344
|
+
return { success: false, error: errorMsg };
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
};
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* without degrading tool functionality or throwing unhandled errors.
|
|
8
8
|
*/
|
|
9
9
|
import path from 'node:path';
|
|
10
|
+
import os from 'node:os';
|
|
10
11
|
/**
|
|
11
12
|
* Universal tool name alias dictionary. Maps hallucinations from OpenAI,
|
|
12
13
|
* Anthropic, DeepSeek, Qwen, Ollama, etc. to Causyne Agent canonical tool names.
|
|
@@ -84,6 +85,12 @@ export const TOOL_NAME_ALIASES = {
|
|
|
84
85
|
read_url: 'web_fetch',
|
|
85
86
|
read_url_content: 'web_fetch',
|
|
86
87
|
http_get: 'web_fetch',
|
|
88
|
+
browserAutomator: 'browser_act',
|
|
89
|
+
browser_automator: 'browser_act',
|
|
90
|
+
browser: 'browser_act',
|
|
91
|
+
causyne_browser: 'browser_act',
|
|
92
|
+
camofox: 'browser_act',
|
|
93
|
+
camoufox: 'browser_act',
|
|
87
94
|
// Specialized engines & capabilities
|
|
88
95
|
nativeEngine: 'native_engine',
|
|
89
96
|
'native-engine': 'native_engine',
|
|
@@ -522,6 +529,98 @@ export function resolveParameterAliases(toolName, args, schema) {
|
|
|
522
529
|
});
|
|
523
530
|
}
|
|
524
531
|
}
|
|
532
|
+
else if (canonicalName === 'browser_act') {
|
|
533
|
+
if (!modified.actions) {
|
|
534
|
+
if (Array.isArray(modified.steps) || Array.isArray(modified.items)) {
|
|
535
|
+
modified.actions = modified.steps || modified.items;
|
|
536
|
+
delete modified.steps;
|
|
537
|
+
delete modified.items;
|
|
538
|
+
repairs.push("Mapped 'steps'/'items' to 'actions' parameter for 'browser_act'");
|
|
539
|
+
}
|
|
540
|
+
else if (typeof modified.type === 'string' || typeof modified.action === 'string') {
|
|
541
|
+
const singleAction = { ...modified };
|
|
542
|
+
if (!singleAction.type && typeof singleAction.action === 'string') {
|
|
543
|
+
singleAction.type = singleAction.action;
|
|
544
|
+
delete singleAction.action;
|
|
545
|
+
}
|
|
546
|
+
for (const key of Object.keys(modified)) {
|
|
547
|
+
delete modified[key];
|
|
548
|
+
}
|
|
549
|
+
modified.actions = [singleAction];
|
|
550
|
+
repairs.push("Wrapped single top-level browser action into 'actions' array for 'browser_act'");
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
if (Array.isArray(modified.actions)) {
|
|
554
|
+
modified.actions = modified.actions.map((item) => {
|
|
555
|
+
if (!item || typeof item !== 'object')
|
|
556
|
+
return item;
|
|
557
|
+
const norm = { ...item };
|
|
558
|
+
if (!norm.type && typeof norm.action === 'string') {
|
|
559
|
+
norm.type = norm.action;
|
|
560
|
+
delete norm.action;
|
|
561
|
+
}
|
|
562
|
+
if (!norm.ref && typeof (norm.elementRef || norm.element) === 'string') {
|
|
563
|
+
norm.ref = norm.elementRef || norm.element;
|
|
564
|
+
delete norm.elementRef;
|
|
565
|
+
delete norm.element;
|
|
566
|
+
}
|
|
567
|
+
if ((norm.type === 'download' || norm.type === 'screenshot') && !norm.outputFile && typeof (norm.path || norm.file) === 'string') {
|
|
568
|
+
norm.outputFile = norm.path || norm.file;
|
|
569
|
+
delete norm.path;
|
|
570
|
+
delete norm.file;
|
|
571
|
+
}
|
|
572
|
+
if (norm.type === 'upload' && !norm.filePath && (norm.path || norm.file || norm.files)) {
|
|
573
|
+
norm.filePath = norm.path || norm.file || norm.files;
|
|
574
|
+
delete norm.path;
|
|
575
|
+
delete norm.file;
|
|
576
|
+
delete norm.files;
|
|
577
|
+
}
|
|
578
|
+
return norm;
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
else if (canonicalName === 'update_plan') {
|
|
583
|
+
if (!modified.plan && (modified.steps || modified.items || modified.tasks)) {
|
|
584
|
+
modified.plan = modified.steps || modified.items || modified.tasks;
|
|
585
|
+
delete modified.steps;
|
|
586
|
+
delete modified.items;
|
|
587
|
+
delete modified.tasks;
|
|
588
|
+
repairs.push("Mapped 'steps' to 'plan' parameter for 'update_plan'");
|
|
589
|
+
}
|
|
590
|
+
if (Array.isArray(modified.plan)) {
|
|
591
|
+
let activeCount = 0;
|
|
592
|
+
modified.plan = modified.plan.map((raw, idx) => {
|
|
593
|
+
if (!raw || typeof raw !== 'object')
|
|
594
|
+
return raw;
|
|
595
|
+
const item = { ...raw };
|
|
596
|
+
if (!item.id)
|
|
597
|
+
item.id = `step-${idx + 1}`;
|
|
598
|
+
if (!item.step && (item.content || item.title || item.name || item.description)) {
|
|
599
|
+
item.step = item.content || item.title || item.name || item.description;
|
|
600
|
+
}
|
|
601
|
+
let status = String(item.status || item.state || 'pending').toLowerCase().trim();
|
|
602
|
+
if (status === 'in-progress' || status === 'in progress' || status === 'running' || status === 'working') {
|
|
603
|
+
status = 'in_progress';
|
|
604
|
+
}
|
|
605
|
+
else if (status === 'done' || status === 'finished' || status === 'complete') {
|
|
606
|
+
status = 'completed';
|
|
607
|
+
}
|
|
608
|
+
else if (status !== 'pending' && status !== 'in_progress' && status !== 'completed') {
|
|
609
|
+
status = 'pending';
|
|
610
|
+
}
|
|
611
|
+
if (status === 'in_progress') {
|
|
612
|
+
activeCount++;
|
|
613
|
+
if (activeCount > 1) {
|
|
614
|
+
status = 'pending';
|
|
615
|
+
repairs.push(`Normalized extra in_progress step '${item.id}' to pending`);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
item.status = status;
|
|
619
|
+
return item;
|
|
620
|
+
});
|
|
621
|
+
repairs.push("Auto-healed and normalized plan steps for 'update_plan'");
|
|
622
|
+
}
|
|
623
|
+
}
|
|
525
624
|
// 2. Identify expected parameters from schema or default aliases
|
|
526
625
|
const expectedKeys = new Set();
|
|
527
626
|
if (schema && schema.properties) {
|
|
@@ -674,12 +773,20 @@ export function coerceArgumentTypes(toolName, args, schema) {
|
|
|
674
773
|
export function normalizePaths(args, cwd = process.cwd()) {
|
|
675
774
|
const repairs = [];
|
|
676
775
|
const modified = { ...args };
|
|
677
|
-
const pathKeys = ['path', 'file_path', 'source', 'destination', 'targetFile'];
|
|
776
|
+
const pathKeys = ['path', 'file_path', 'source', 'destination', 'targetFile', 'target'];
|
|
678
777
|
for (const key of pathKeys) {
|
|
679
778
|
const val = modified[key];
|
|
680
779
|
if (typeof val === 'string' && val.trim() !== '') {
|
|
681
780
|
const trimmed = val.trim();
|
|
682
|
-
|
|
781
|
+
// Skip URLs
|
|
782
|
+
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(trimmed)) {
|
|
783
|
+
continue;
|
|
784
|
+
}
|
|
785
|
+
if (trimmed === '~' || trimmed.startsWith('~/') || trimmed.startsWith('~\\')) {
|
|
786
|
+
modified[key] = trimmed.replace(/^~(?=$|[\\/])/, os.homedir());
|
|
787
|
+
repairs.push(`Expanded home directory path '${trimmed}' -> '${modified[key]}' for parameter '${key}'`);
|
|
788
|
+
}
|
|
789
|
+
else if (!path.isAbsolute(trimmed)) {
|
|
683
790
|
modified[key] = path.resolve(cwd, trimmed);
|
|
684
791
|
repairs.push(`Normalized relative path '${trimmed}' -> '${modified[key]}' for parameter '${key}'`);
|
|
685
792
|
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import path from 'node:path';
|
|
11
|
+
import os from 'node:os';
|
|
11
12
|
|
|
12
13
|
export interface RepairResult {
|
|
13
14
|
args: Record<string, unknown>;
|
|
@@ -112,6 +113,12 @@ export const TOOL_NAME_ALIASES: Record<string, string> = {
|
|
|
112
113
|
read_url: 'web_fetch',
|
|
113
114
|
read_url_content: 'web_fetch',
|
|
114
115
|
http_get: 'web_fetch',
|
|
116
|
+
browserAutomator: 'browser_act',
|
|
117
|
+
browser_automator: 'browser_act',
|
|
118
|
+
browser: 'browser_act',
|
|
119
|
+
causyne_browser: 'browser_act',
|
|
120
|
+
camofox: 'browser_act',
|
|
121
|
+
camoufox: 'browser_act',
|
|
115
122
|
|
|
116
123
|
// Specialized engines & capabilities
|
|
117
124
|
nativeEngine: 'native_engine',
|
|
@@ -573,6 +580,90 @@ export function resolveParameterAliases(
|
|
|
573
580
|
return norm;
|
|
574
581
|
});
|
|
575
582
|
}
|
|
583
|
+
} else if (canonicalName === 'browser_act') {
|
|
584
|
+
if (!modified.actions) {
|
|
585
|
+
if (Array.isArray(modified.steps) || Array.isArray(modified.items)) {
|
|
586
|
+
modified.actions = modified.steps || modified.items;
|
|
587
|
+
delete modified.steps;
|
|
588
|
+
delete modified.items;
|
|
589
|
+
repairs.push("Mapped 'steps'/'items' to 'actions' parameter for 'browser_act'");
|
|
590
|
+
} else if (typeof modified.type === 'string' || typeof modified.action === 'string') {
|
|
591
|
+
const singleAction: Record<string, unknown> = { ...modified };
|
|
592
|
+
if (!singleAction.type && typeof singleAction.action === 'string') {
|
|
593
|
+
singleAction.type = singleAction.action;
|
|
594
|
+
delete singleAction.action;
|
|
595
|
+
}
|
|
596
|
+
for (const key of Object.keys(modified)) {
|
|
597
|
+
delete modified[key];
|
|
598
|
+
}
|
|
599
|
+
modified.actions = [singleAction];
|
|
600
|
+
repairs.push("Wrapped single top-level browser action into 'actions' array for 'browser_act'");
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
if (Array.isArray(modified.actions)) {
|
|
604
|
+
modified.actions = (modified.actions as Record<string, unknown>[]).map((item) => {
|
|
605
|
+
if (!item || typeof item !== 'object') return item;
|
|
606
|
+
const norm = { ...item };
|
|
607
|
+
if (!norm.type && typeof norm.action === 'string') {
|
|
608
|
+
norm.type = norm.action;
|
|
609
|
+
delete norm.action;
|
|
610
|
+
}
|
|
611
|
+
if (!norm.ref && typeof (norm.elementRef || norm.element) === 'string') {
|
|
612
|
+
norm.ref = norm.elementRef || norm.element;
|
|
613
|
+
delete norm.elementRef;
|
|
614
|
+
delete norm.element;
|
|
615
|
+
}
|
|
616
|
+
if ((norm.type === 'download' || norm.type === 'screenshot') && !norm.outputFile && typeof (norm.path || norm.file) === 'string') {
|
|
617
|
+
norm.outputFile = norm.path || norm.file;
|
|
618
|
+
delete norm.path;
|
|
619
|
+
delete norm.file;
|
|
620
|
+
}
|
|
621
|
+
if (norm.type === 'upload' && !norm.filePath && (norm.path || norm.file || norm.files)) {
|
|
622
|
+
norm.filePath = norm.path || norm.file || norm.files;
|
|
623
|
+
delete norm.path;
|
|
624
|
+
delete norm.file;
|
|
625
|
+
delete norm.files;
|
|
626
|
+
}
|
|
627
|
+
return norm;
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
} else if (canonicalName === 'update_plan') {
|
|
631
|
+
if (!modified.plan && (modified.steps || modified.items || modified.tasks)) {
|
|
632
|
+
modified.plan = modified.steps || modified.items || modified.tasks;
|
|
633
|
+
delete modified.steps;
|
|
634
|
+
delete modified.items;
|
|
635
|
+
delete modified.tasks;
|
|
636
|
+
repairs.push("Mapped 'steps' to 'plan' parameter for 'update_plan'");
|
|
637
|
+
}
|
|
638
|
+
if (Array.isArray(modified.plan)) {
|
|
639
|
+
let activeCount = 0;
|
|
640
|
+
modified.plan = (modified.plan as Record<string, unknown>[]).map((raw, idx) => {
|
|
641
|
+
if (!raw || typeof raw !== 'object') return raw;
|
|
642
|
+
const item = { ...raw };
|
|
643
|
+
if (!item.id) item.id = `step-${idx + 1}`;
|
|
644
|
+
if (!item.step && (item.content || item.title || item.name || item.description)) {
|
|
645
|
+
item.step = item.content || item.title || item.name || item.description;
|
|
646
|
+
}
|
|
647
|
+
let status = String(item.status || item.state || 'pending').toLowerCase().trim();
|
|
648
|
+
if (status === 'in-progress' || status === 'in progress' || status === 'running' || status === 'working') {
|
|
649
|
+
status = 'in_progress';
|
|
650
|
+
} else if (status === 'done' || status === 'finished' || status === 'complete') {
|
|
651
|
+
status = 'completed';
|
|
652
|
+
} else if (status !== 'pending' && status !== 'in_progress' && status !== 'completed') {
|
|
653
|
+
status = 'pending';
|
|
654
|
+
}
|
|
655
|
+
if (status === 'in_progress') {
|
|
656
|
+
activeCount++;
|
|
657
|
+
if (activeCount > 1) {
|
|
658
|
+
status = 'pending';
|
|
659
|
+
repairs.push(`Normalized extra in_progress step '${item.id}' to pending`);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
item.status = status;
|
|
663
|
+
return item;
|
|
664
|
+
});
|
|
665
|
+
repairs.push("Auto-healed and normalized plan steps for 'update_plan'");
|
|
666
|
+
}
|
|
576
667
|
}
|
|
577
668
|
|
|
578
669
|
// 2. Identify expected parameters from schema or default aliases
|
|
@@ -736,13 +827,20 @@ export function normalizePaths(
|
|
|
736
827
|
): RepairResult {
|
|
737
828
|
const repairs: string[] = [];
|
|
738
829
|
const modified = { ...args };
|
|
739
|
-
const pathKeys = ['path', 'file_path', 'source', 'destination', 'targetFile'];
|
|
830
|
+
const pathKeys = ['path', 'file_path', 'source', 'destination', 'targetFile', 'target'];
|
|
740
831
|
|
|
741
832
|
for (const key of pathKeys) {
|
|
742
833
|
const val = modified[key];
|
|
743
834
|
if (typeof val === 'string' && val.trim() !== '') {
|
|
744
835
|
const trimmed = val.trim();
|
|
745
|
-
|
|
836
|
+
// Skip URLs
|
|
837
|
+
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(trimmed)) {
|
|
838
|
+
continue;
|
|
839
|
+
}
|
|
840
|
+
if (trimmed === '~' || trimmed.startsWith('~/') || trimmed.startsWith('~\\')) {
|
|
841
|
+
modified[key] = trimmed.replace(/^~(?=$|[\\/])/, os.homedir());
|
|
842
|
+
repairs.push(`Expanded home directory path '${trimmed}' -> '${modified[key]}' for parameter '${key}'`);
|
|
843
|
+
} else if (!path.isAbsolute(trimmed)) {
|
|
746
844
|
modified[key] = path.resolve(cwd, trimmed);
|
|
747
845
|
repairs.push(`Normalized relative path '${trimmed}' -> '${modified[key]}' for parameter '${key}'`);
|
|
748
846
|
}
|
package/src/tools/updatePlan.js
CHANGED
|
@@ -1,4 +1,46 @@
|
|
|
1
1
|
import { normalizePlanUpdate, summarizePlan } from '../implementationPlan.js';
|
|
2
|
+
function healPlanArgs(raw) {
|
|
3
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
4
|
+
return raw;
|
|
5
|
+
const input = { ...raw };
|
|
6
|
+
if (!input.plan && (input.steps || input.items || input.tasks)) {
|
|
7
|
+
input.plan = input.steps || input.items || input.tasks;
|
|
8
|
+
}
|
|
9
|
+
if (Array.isArray(input.plan)) {
|
|
10
|
+
let activeSeen = false;
|
|
11
|
+
input.plan = input.plan.map((stepItem, idx) => {
|
|
12
|
+
if (!stepItem || typeof stepItem !== 'object' || Array.isArray(stepItem))
|
|
13
|
+
return stepItem;
|
|
14
|
+
const s = { ...stepItem };
|
|
15
|
+
if (!s.id)
|
|
16
|
+
s.id = `step-${idx + 1}`;
|
|
17
|
+
if (!s.step && (s.content || s.title || s.name || s.description)) {
|
|
18
|
+
s.step = s.content || s.title || s.name || s.description;
|
|
19
|
+
}
|
|
20
|
+
let status = String(s.status || s.state || 'pending').toLowerCase().trim();
|
|
21
|
+
if (status === 'in-progress' || status === 'in progress' || status === 'running' || status === 'working') {
|
|
22
|
+
status = 'in_progress';
|
|
23
|
+
}
|
|
24
|
+
else if (status === 'done' || status === 'finished' || status === 'complete') {
|
|
25
|
+
status = 'completed';
|
|
26
|
+
}
|
|
27
|
+
else if (status !== 'pending' && status !== 'in_progress' && status !== 'completed') {
|
|
28
|
+
status = 'pending';
|
|
29
|
+
}
|
|
30
|
+
if (status === 'in_progress') {
|
|
31
|
+
if (activeSeen) {
|
|
32
|
+
status = 'pending';
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
activeSeen = true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
s.status = status;
|
|
39
|
+
return s;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return input;
|
|
43
|
+
}
|
|
2
44
|
export const updatePlan = {
|
|
3
45
|
schema: {
|
|
4
46
|
name: 'update_plan',
|
|
@@ -30,7 +72,13 @@ export const updatePlan = {
|
|
|
30
72
|
if (!context.parentLoop || typeof context.parentLoop.updateImplementationPlan !== 'function') {
|
|
31
73
|
return { success: false, error: 'Implementation plans require an active Causyne session' };
|
|
32
74
|
}
|
|
33
|
-
|
|
75
|
+
let update;
|
|
76
|
+
try {
|
|
77
|
+
update = normalizePlanUpdate(args);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
update = normalizePlanUpdate(healPlanArgs(args));
|
|
81
|
+
}
|
|
34
82
|
context.parentLoop.updateImplementationPlan(update);
|
|
35
83
|
return { success: true, output: summarizePlan(update.plan), plan: update.plan };
|
|
36
84
|
}
|