@causyne/agent 1.20.25 → 1.20.26

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.
@@ -21,7 +21,7 @@ Diagnose runtime issues, stream-install APKs, launch activities, and capture cra
21
21
  - **Done when:** `adb install` output explicitly returns `Performing Streamed Install` and `Success`.
22
22
 
23
23
  3. Launch and verify foreground Activity lifecycle.
24
- - Run `adb -s <serial> shell am start -n <package>/<activity>`.
24
+ - Run `adb -s <serial> shell am start -W -n <package>/<activity>`. The `-W` flag forces the ActivityManager to wait until launch and foreground resume are complete before returning, eliminating timing race conditions.
25
25
  - Do not rely on chaining `sleep && pidof` in compound expressions, as timing differences cause exit code 1. Instead, query the activity manager directly:
26
26
  `adb -s <serial> shell dumpsys activity activities | grep -E "mResumedActivity|topResumedActivity"`
27
27
  - Confirm the target activity matches the resumed activity record.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@causyne/agent",
3
- "version": "1.20.25",
3
+ "version": "1.20.26",
4
4
  "description": "Agentic AI for software, tools, and computer workflows",
5
5
  "main": "bin/causyne.js",
6
6
  "type": "module",
package/src/agentLoop.js CHANGED
@@ -298,6 +298,14 @@ You possess native reverse engineering capabilities powered by the Reverse Engin
298
298
  - **Prefer REST APIs (curl) for External Services**: When interacting with external services (like web, email, chat), prioritize finding and using official REST APIs via \`curl\` or simple scripts over browser scraping.
299
299
  - **Web/UI Verification Requirement**: Prefer \`browser_act\` preview for static workspace HTML and ES modules; it does not need a separate HTTP server. Use \`sysRunBg\` only when a real application server is required. Do not kill unrelated processes to claim a port. For web development, UI components, and frontend applications, ALWAYS verify your rendered output before concluding. Use \`browser_act\` (preview and snapshot) or \`screenshot\`/\`vision_inspect_ui\` to inspect the visual/DOM state of your web pages. Report DOM inspection separately from visual inspection; only claim visual inspection when you actually receive and inspect image pixels.
300
300
 
301
+ # Execution Environment & Toolchains in sysRun
302
+ - Subprocesses executed via \`sysRun\` have an enriched toolchain environment automatically configured:
303
+ 1. **Android SDK**: \`ANDROID_HOME\`, \`ANDROID_SDK_ROOT\`, \`platform-tools\` (\`adb\`), \`cmdline-tools\`, \`emulator\`, and \`build-tools\` are already pre-configured in \`PATH\`. You do NOT need to prepend \`export PATH=...\`.
304
+ 2. **Java JDK**: \`JAVA_HOME\` and JDK bin directories are automatically discovered and set in the environment. You do NOT need to prepend \`export JAVA_HOME=...\`.
305
+ 3. **Local Binaries & Package Managers**: \`~/.local/bin\` (where official CLIs such as Google's \`android\` CLI reside), \`/opt/homebrew/bin\`, and language runtimes are pre-configured in \`PATH\`.
306
+ 4. **Activity Launch Verification**: When launching an Activity via ADB, use \`adb -s <serial> shell am start -W -n <package>/<activity>\` (\`-W\` waits for the activity launch to complete before returning), or query resumed activities via \`dumpsys activity activities\`.
307
+ 5. **Multiple Emulators/Devices**: When multiple devices or emulators are connected, specify \`-s <serial>\` (e.g. \`adb -s emulator-5554 ...\`) or set \`export ANDROID_SERIAL=<serial>\`.
308
+
301
309
  # Universal Tool Calling & Registry Discipline
302
310
  1. **Strict Registry Adherence**: Use ONLY the tools declared in the catalogue. Invoke tools using exact parameter names specified in the schema. Do not invent or rename parameters.
303
311
  2. **Valid JSON Formatting**: All tool call arguments must be valid JSON objects. Never include raw unescaped newlines or trailing commas inside argument strings.
package/src/agentLoop.ts CHANGED
@@ -380,6 +380,14 @@ You possess native reverse engineering capabilities powered by the Reverse Engin
380
380
  - **Prefer REST APIs (curl) for External Services**: When interacting with external services (like web, email, chat), prioritize finding and using official REST APIs via \`curl\` or simple scripts over browser scraping.
381
381
  - **Web/UI Verification Requirement**: Prefer \`browser_act\` preview for static workspace HTML and ES modules; it does not need a separate HTTP server. Use \`sysRunBg\` only when a real application server is required. Do not kill unrelated processes to claim a port. For web development, UI components, and frontend applications, ALWAYS verify your rendered output before concluding. Use \`browser_act\` (preview and snapshot) or \`screenshot\`/\`vision_inspect_ui\` to inspect the visual/DOM state of your web pages. Report DOM inspection separately from visual inspection; only claim visual inspection when you actually receive and inspect image pixels.
382
382
 
383
+ # Execution Environment & Toolchains in sysRun
384
+ - Subprocesses executed via \`sysRun\` have an enriched toolchain environment automatically configured:
385
+ 1. **Android SDK**: \`ANDROID_HOME\`, \`ANDROID_SDK_ROOT\`, \`platform-tools\` (\`adb\`), \`cmdline-tools\`, \`emulator\`, and \`build-tools\` are already pre-configured in \`PATH\`. You do NOT need to prepend \`export PATH=...\`.
386
+ 2. **Java JDK**: \`JAVA_HOME\` and JDK bin directories are automatically discovered and set in the environment. You do NOT need to prepend \`export JAVA_HOME=...\`.
387
+ 3. **Local Binaries & Package Managers**: \`~/.local/bin\` (where official CLIs such as Google's \`android\` CLI reside), \`/opt/homebrew/bin\`, and language runtimes are pre-configured in \`PATH\`.
388
+ 4. **Activity Launch Verification**: When launching an Activity via ADB, use \`adb -s <serial> shell am start -W -n <package>/<activity>\` (\`-W\` waits for the activity launch to complete before returning), or query resumed activities via \`dumpsys activity activities\`.
389
+ 5. **Multiple Emulators/Devices**: When multiple devices or emulators are connected, specify \`-s <serial>\` (e.g. \`adb -s emulator-5554 ...\`) or set \`export ANDROID_SERIAL=<serial>\`.
390
+
383
391
  # Universal Tool Calling & Registry Discipline
384
392
  1. **Strict Registry Adherence**: Use ONLY the tools declared in the catalogue. Invoke tools using exact parameter names specified in the schema. Do not invent or rename parameters.
385
393
  2. **Valid JSON Formatting**: All tool call arguments must be valid JSON objects. Never include raw unescaped newlines or trailing commas inside argument strings.
@@ -693,7 +693,9 @@ export const COMPILED_SKILLS = {
693
693
  "eamed Install` and `Success`.\n",
694
694
  "\n",
695
695
  "3. Launch and verify foreground Activity lifecycle.\n",
696
- " - Run `adb -s <serial> shell am start -n <package>/<activity>`.\n",
696
+ " - Run `adb -s <serial> shell am start -W -n <package>/<activity>`. The `",
697
+ "-W` flag forces the ActivityManager to wait until launch and foreground res",
698
+ "ume are complete before returning, eliminating timing race conditions.\n",
697
699
  " - Do not rely on chaining `sleep && pidof` in compound expressions, as t",
698
700
  "iming differences cause exit code 1. Instead, query the activity manager di",
699
701
  "rectly:\n",
@@ -41,7 +41,7 @@ export function cleanSubprocessOutput(str) {
41
41
  * Commands whose exit code 1 indicates a normal query result (e.g. no matches found,
42
42
  * differences found, or condition evaluated to false) rather than a system error.
43
43
  */
44
- export const SEARCH_COMMAND_PATTERN = /(^|\s|\||&&|;)(grep|egrep|fgrep|diff|test|which|cmp|find|pidof|pgrep)(\s|$)/;
44
+ export const SEARCH_COMMAND_PATTERN = /(^|\s|\||&&|;)(grep|egrep|fgrep|diff|test|which|where|cmp|find|pidof|pgrep)(\s|$)/;
45
45
  /**
46
46
  * Resolves an enriched environment for subprocess execution with full toolchain
47
47
  * awareness. Automatically discovers Android SDK, Homebrew, local user binaries,
@@ -72,7 +72,9 @@ export function getEnhancedEnv(baseEnv) {
72
72
  env.ANDROID_SDK_ROOT = env.ANDROID_HOME;
73
73
  }
74
74
  // 2. Build enriched PATH including dev tools, package managers, and Android toolchains
75
- const currentPath = env.PATH || '';
75
+ // Find case-insensitive PATH key (on Windows it is often 'Path')
76
+ const pathKey = Object.keys(env).find(k => k.toUpperCase() === 'PATH') || 'PATH';
77
+ const currentPath = env[pathKey] || process.env[pathKey] || process.env.PATH || process.env.Path || '';
76
78
  const pathParts = currentPath.split(path.delimiter).filter(Boolean);
77
79
  const addIfMissing = (dir, checkExists = true) => {
78
80
  if (dir && (!checkExists || fs.existsSync(dir)) && !pathParts.includes(dir)) {
@@ -83,6 +85,12 @@ export function getEnhancedEnv(baseEnv) {
83
85
  if (process.execPath) {
84
86
  addIfMissing(path.dirname(process.execPath));
85
87
  }
88
+ // Windows system binaries (guarantee cmd.exe and powershell resolve)
89
+ if (process.platform === 'win32') {
90
+ const sysRoot = env.SystemRoot || env.SYSTEMROOT || process.env.SystemRoot || process.env.SYSTEMROOT || 'C:\\Windows';
91
+ addIfMissing(path.join(sysRoot, 'System32'));
92
+ addIfMissing(sysRoot);
93
+ }
86
94
  // Local user binaries (where Google's official android CLI lives)
87
95
  addIfMissing(path.join(os.homedir(), '.local', 'bin'), false);
88
96
  // Package managers and developer toolchains
@@ -110,9 +118,71 @@ export function getEnhancedEnv(baseEnv) {
110
118
  catch { }
111
119
  }
112
120
  }
113
- env.PATH = pathParts.join(path.delimiter);
121
+ // 3. Discover JAVA_HOME across Homebrew, macOS JVMs, Linux, and Windows
122
+ if (!env.JAVA_HOME) {
123
+ const javaCandidates = [
124
+ '/opt/homebrew/opt/openjdk@17',
125
+ '/opt/homebrew/opt/openjdk@21',
126
+ '/opt/homebrew/opt/openjdk',
127
+ '/usr/local/opt/openjdk@17',
128
+ '/usr/local/opt/openjdk@21',
129
+ '/usr/local/opt/openjdk',
130
+ '/usr/lib/jvm/java-17-openjdk-amd64',
131
+ '/usr/lib/jvm/java-17-openjdk',
132
+ '/usr/lib/jvm/java-21-openjdk-amd64',
133
+ '/usr/lib/jvm/default-java',
134
+ 'C:\\Program Files\\Java\\jdk-17',
135
+ 'C:\\Program Files\\Java\\jdk-21'
136
+ ];
137
+ const macJvmRoot = '/Library/Java/JavaVirtualMachines';
138
+ if (fs.existsSync(macJvmRoot)) {
139
+ try {
140
+ const jvms = fs.readdirSync(macJvmRoot).filter(d => !d.startsWith('.')).sort().reverse();
141
+ for (const jvm of jvms) {
142
+ javaCandidates.unshift(path.join(macJvmRoot, jvm, 'Contents', 'Home'));
143
+ }
144
+ }
145
+ catch { }
146
+ }
147
+ for (const jDir of javaCandidates) {
148
+ if (jDir && fs.existsSync(jDir)) {
149
+ env.JAVA_HOME = jDir;
150
+ break;
151
+ }
152
+ }
153
+ }
154
+ if (env.JAVA_HOME) {
155
+ addIfMissing(path.join(env.JAVA_HOME, 'bin'), false);
156
+ }
157
+ const enrichedPath = pathParts.join(path.delimiter);
158
+ env[pathKey] = enrichedPath;
159
+ if (process.platform === 'win32') {
160
+ env.PATH = enrichedPath;
161
+ env.Path = enrichedPath;
162
+ }
163
+ else {
164
+ env.PATH = enrichedPath;
165
+ }
114
166
  return env;
115
167
  }
168
+ /**
169
+ * Determines whether the terminal command in a pipeline, compound statement,
170
+ * or shell wrapper is a search/inspection tool whose exit code 1 represents
171
+ * zero matches rather than a failure.
172
+ */
173
+ export function isFinalCommandSearch(rawCommand) {
174
+ if (rawCommand.includes('||'))
175
+ return false;
176
+ const statements = rawCommand.split(/&&|;/);
177
+ let lastStmt = statements.at(-1)?.trim() || '';
178
+ const subshellMatch = lastStmt.match(/(?:(?:adb\s+(?:-s\s+\S+\s+)?shell|ssh\s+\S+|sh\s+-c|bash\s+-c)\s+["'])(.+?)(?:["']\s*[\)]*\s*$)/);
179
+ if (subshellMatch && subshellMatch[1]) {
180
+ lastStmt = subshellMatch[1].trim();
181
+ }
182
+ const pipeParts = lastStmt.split('|');
183
+ const finalCmd = pipeParts.at(-1)?.trim().replace(/["'\)\s]+$/, '') || '';
184
+ return /(?:^|\s)(grep|egrep|fgrep|diff|test|which|where|cmp|pidof|pgrep|find)\b/.test(finalCmd);
185
+ }
116
186
  /**
117
187
  * Commands that are strictly read-only and idempotent.
118
188
  * Repeated identical executions within a short TTL window return cached output.
@@ -151,7 +221,7 @@ export function clearSysRunCache() {
151
221
  export const sysRun = {
152
222
  schema: {
153
223
  name: 'sysRun',
154
- description: '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.',
224
+ description: 'Execute a shell command. Environment is automatically enriched with PATH for Android SDK (adb, emulator), Java (JAVA_HOME), and local developer tools (no manual export needed). 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.',
155
225
  parameters: {
156
226
  type: 'object',
157
227
  properties: {
@@ -321,9 +391,8 @@ export const sysRun = {
321
391
  }
322
392
  resolve(res);
323
393
  }
324
- else if (exitCode === 1 && !/[;&<>`$\r\n]/.test(rawCommand) && !rawCommand.includes('||')
325
- && /(?:^|\s)(grep|egrep|fgrep|diff|test|which|cmp|pidof|pgrep)\b/.test(rawCommand.split('|').at(-1)?.trim() || '')) {
326
- // Semantic Exit Code Normalization: POSIX search tool found 0 matching lines.
394
+ else if (exitCode === 1 && isFinalCommandSearch(rawCommand)) {
395
+ // Semantic Exit Code Normalization: Search tool found 0 matching lines.
327
396
  const res = {
328
397
  success: true,
329
398
  output: cleanOutput || '(no matches found)',
@@ -83,7 +83,7 @@ export function cleanSubprocessOutput(str: string): string {
83
83
  * Commands whose exit code 1 indicates a normal query result (e.g. no matches found,
84
84
  * differences found, or condition evaluated to false) rather than a system error.
85
85
  */
86
- export const SEARCH_COMMAND_PATTERN = /(^|\s|\||&&|;)(grep|egrep|fgrep|diff|test|which|cmp|find|pidof|pgrep)(\s|$)/;
86
+ export const SEARCH_COMMAND_PATTERN = /(^|\s|\||&&|;)(grep|egrep|fgrep|diff|test|which|where|cmp|find|pidof|pgrep)(\s|$)/;
87
87
 
88
88
  /**
89
89
  * Resolves an enriched environment for subprocess execution with full toolchain
@@ -115,7 +115,9 @@ export function getEnhancedEnv(baseEnv?: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
115
115
  }
116
116
 
117
117
  // 2. Build enriched PATH including dev tools, package managers, and Android toolchains
118
- const currentPath = env.PATH || '';
118
+ // Find case-insensitive PATH key (on Windows it is often 'Path')
119
+ const pathKey = Object.keys(env).find(k => k.toUpperCase() === 'PATH') || 'PATH';
120
+ const currentPath = env[pathKey] || process.env[pathKey] || process.env.PATH || process.env.Path || '';
119
121
  const pathParts = currentPath.split(path.delimiter).filter(Boolean);
120
122
  const addIfMissing = (dir: string, checkExists = true) => {
121
123
  if (dir && (!checkExists || fs.existsSync(dir)) && !pathParts.includes(dir)) {
@@ -128,6 +130,13 @@ export function getEnhancedEnv(baseEnv?: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
128
130
  addIfMissing(path.dirname(process.execPath));
129
131
  }
130
132
 
133
+ // Windows system binaries (guarantee cmd.exe and powershell resolve)
134
+ if (process.platform === 'win32') {
135
+ const sysRoot = env.SystemRoot || env.SYSTEMROOT || process.env.SystemRoot || process.env.SYSTEMROOT || 'C:\\Windows';
136
+ addIfMissing(path.join(sysRoot, 'System32'));
137
+ addIfMissing(sysRoot);
138
+ }
139
+
131
140
  // Local user binaries (where Google's official android CLI lives)
132
141
  addIfMissing(path.join(os.homedir(), '.local', 'bin'), false);
133
142
 
@@ -158,10 +167,77 @@ export function getEnhancedEnv(baseEnv?: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
158
167
  }
159
168
  }
160
169
 
161
- env.PATH = pathParts.join(path.delimiter);
170
+ // 3. Discover JAVA_HOME across Homebrew, macOS JVMs, Linux, and Windows
171
+ if (!env.JAVA_HOME) {
172
+ const javaCandidates = [
173
+ '/opt/homebrew/opt/openjdk@17',
174
+ '/opt/homebrew/opt/openjdk@21',
175
+ '/opt/homebrew/opt/openjdk',
176
+ '/usr/local/opt/openjdk@17',
177
+ '/usr/local/opt/openjdk@21',
178
+ '/usr/local/opt/openjdk',
179
+ '/usr/lib/jvm/java-17-openjdk-amd64',
180
+ '/usr/lib/jvm/java-17-openjdk',
181
+ '/usr/lib/jvm/java-21-openjdk-amd64',
182
+ '/usr/lib/jvm/default-java',
183
+ 'C:\\Program Files\\Java\\jdk-17',
184
+ 'C:\\Program Files\\Java\\jdk-21'
185
+ ];
186
+ const macJvmRoot = '/Library/Java/JavaVirtualMachines';
187
+ if (fs.existsSync(macJvmRoot)) {
188
+ try {
189
+ const jvms = fs.readdirSync(macJvmRoot).filter(d => !d.startsWith('.')).sort().reverse();
190
+ for (const jvm of jvms) {
191
+ javaCandidates.unshift(path.join(macJvmRoot, jvm, 'Contents', 'Home'));
192
+ }
193
+ } catch {}
194
+ }
195
+
196
+ for (const jDir of javaCandidates) {
197
+ if (jDir && fs.existsSync(jDir)) {
198
+ env.JAVA_HOME = jDir;
199
+ break;
200
+ }
201
+ }
202
+ }
203
+
204
+ if (env.JAVA_HOME) {
205
+ addIfMissing(path.join(env.JAVA_HOME, 'bin'), false);
206
+ }
207
+
208
+ const enrichedPath = pathParts.join(path.delimiter);
209
+ env[pathKey] = enrichedPath;
210
+ if (process.platform === 'win32') {
211
+ env.PATH = enrichedPath;
212
+ env.Path = enrichedPath;
213
+ } else {
214
+ env.PATH = enrichedPath;
215
+ }
162
216
  return env;
163
217
  }
164
218
 
219
+ /**
220
+ * Determines whether the terminal command in a pipeline, compound statement,
221
+ * or shell wrapper is a search/inspection tool whose exit code 1 represents
222
+ * zero matches rather than a failure.
223
+ */
224
+ export function isFinalCommandSearch(rawCommand: string): boolean {
225
+ if (rawCommand.includes('||')) return false;
226
+
227
+ const statements = rawCommand.split(/&&|;/);
228
+ let lastStmt = statements.at(-1)?.trim() || '';
229
+
230
+ const subshellMatch = lastStmt.match(/(?:(?:adb\s+(?:-s\s+\S+\s+)?shell|ssh\s+\S+|sh\s+-c|bash\s+-c)\s+["'])(.+?)(?:["']\s*[\)]*\s*$)/);
231
+ if (subshellMatch && subshellMatch[1]) {
232
+ lastStmt = subshellMatch[1].trim();
233
+ }
234
+
235
+ const pipeParts = lastStmt.split('|');
236
+ const finalCmd = pipeParts.at(-1)?.trim().replace(/["'\)\s]+$/, '') || '';
237
+
238
+ return /(?:^|\s)(grep|egrep|fgrep|diff|test|which|where|cmp|pidof|pgrep|find)\b/.test(finalCmd);
239
+ }
240
+
165
241
  /**
166
242
  * Commands that are strictly read-only and idempotent.
167
243
  * Repeated identical executions within a short TTL window return cached output.
@@ -215,7 +291,7 @@ export const sysRun = {
215
291
  schema: {
216
292
  name: 'sysRun',
217
293
  description:
218
- '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.',
294
+ 'Execute a shell command. Environment is automatically enriched with PATH for Android SDK (adb, emulator), Java (JAVA_HOME), and local developer tools (no manual export needed). 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.',
219
295
  parameters: {
220
296
  type: 'object',
221
297
  properties: {
@@ -386,9 +462,8 @@ export const sysRun = {
386
462
  });
387
463
  }
388
464
  resolve(res);
389
- } else if (exitCode === 1 && !/[;&<>`$\r\n]/.test(rawCommand) && !rawCommand.includes('||')
390
- && /(?:^|\s)(grep|egrep|fgrep|diff|test|which|cmp|pidof|pgrep)\b/.test(rawCommand.split('|').at(-1)?.trim() || '')) {
391
- // Semantic Exit Code Normalization: POSIX search tool found 0 matching lines.
465
+ } else if (exitCode === 1 && isFinalCommandSearch(rawCommand)) {
466
+ // Semantic Exit Code Normalization: Search tool found 0 matching lines.
392
467
  const res: SysRunResult = {
393
468
  success: true,
394
469
  output: cleanOutput || '(no matches found)',