@causyne/agent 1.20.25 → 1.20.28
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/native-skills/android/android-debugging-and-testing/SKILL.md +1 -1
- package/package.json +1 -1
- package/src/agentLoop.js +60 -4
- package/src/agentLoop.ts +56 -4
- package/src/browser/causyneBrowser.js +1 -1
- package/src/browser/causyneBrowser.ts +1 -1
- package/src/browser/searchProviders.js +1 -1
- package/src/browser/searchProviders.ts +1 -1
- package/src/compiledSkills.js +3 -1
- package/src/decideTools.js +9 -1
- package/src/decideTools.ts +7 -1
- package/src/dynamicCatalogue.js +3 -1
- package/src/dynamicCatalogue.ts +3 -1
- package/src/launchIntent.js +1 -1
- package/src/launchIntent.ts +1 -1
- package/src/mcp/mcpRegistry.js +6 -2
- package/src/mcp/mcpRegistry.ts +5 -2
- package/src/memory/actrRanker.js +78 -0
- package/src/memory/actrRanker.ts +111 -0
- package/src/memory/contextBudget.js +131 -0
- package/src/memory/contextBudget.ts +155 -0
- package/src/memory/episodicStore.js +651 -0
- package/src/memory/episodicStore.ts +787 -0
- package/src/memory/episodicTypes.js +8 -0
- package/src/memory/episodicTypes.ts +124 -0
- package/src/memory/nearDuplicate.js +179 -0
- package/src/memory/nearDuplicate.ts +232 -0
- package/src/memory/symbolFolder.js +301 -0
- package/src/memory/symbolFolder.ts +327 -0
- package/src/toolPacks.js +1 -0
- package/src/toolPacks.ts +1 -0
- package/src/tools/desktopOpen.js +9 -2
- package/src/tools/desktopOpen.ts +8 -2
- package/src/tools/memoryRecall.js +211 -0
- package/src/tools/memoryRecall.ts +251 -0
- package/src/tools/nativeEngine.js +16 -2
- package/src/tools/nativeEngine.ts +16 -2
- package/src/tools/registry.js +2 -1
- package/src/tools/subagentOrchestrator.js +3 -2
- package/src/tools/sysRun.js +76 -7
- package/src/tools/sysRun.ts +82 -7
- package/src/tools/toolSelfRepair.js +4 -1
- package/src/tools/toolSelfRepair.ts +4 -1
- package/src/toolsList.js +1 -0
- package/src/toolsList.ts +1 -0
package/src/tools/sysRun.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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 &&
|
|
325
|
-
|
|
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)',
|
package/src/tools/sysRun.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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 &&
|
|
390
|
-
|
|
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)',
|
|
@@ -382,7 +382,10 @@ function sanitizeUnescapedStringLiterals(input) {
|
|
|
382
382
|
*/
|
|
383
383
|
function convertSingleQuotesToJson(input) {
|
|
384
384
|
return input.replace(/'([^'\\]*(?:\\.[^'\\]*)*)'/g, (_match, inner) => {
|
|
385
|
-
const escaped = inner
|
|
385
|
+
const escaped = inner
|
|
386
|
+
.replace(/\\'/g, "'")
|
|
387
|
+
.replace(/\\/g, '\\\\')
|
|
388
|
+
.replace(/"/g, '\\"');
|
|
386
389
|
return `"${escaped}"`;
|
|
387
390
|
});
|
|
388
391
|
}
|
|
@@ -436,7 +436,10 @@ function sanitizeUnescapedStringLiterals(input: string): string {
|
|
|
436
436
|
*/
|
|
437
437
|
function convertSingleQuotesToJson(input: string): string {
|
|
438
438
|
return input.replace(/'([^'\\]*(?:\\.[^'\\]*)*)'/g, (_match, inner) => {
|
|
439
|
-
const escaped = (inner as string)
|
|
439
|
+
const escaped = (inner as string)
|
|
440
|
+
.replace(/\\'/g, "'")
|
|
441
|
+
.replace(/\\/g, '\\\\')
|
|
442
|
+
.replace(/"/g, '\\"');
|
|
440
443
|
return `"${escaped}"`;
|
|
441
444
|
});
|
|
442
445
|
}
|
package/src/toolsList.js
CHANGED
|
@@ -42,6 +42,7 @@ const CATALOGUE = {
|
|
|
42
42
|
update_plan: 'visible checklist, one active step',
|
|
43
43
|
request_decision: 'ask the user to pick a direction',
|
|
44
44
|
memory_write: 'save durable user fact or design pattern',
|
|
45
|
+
memory_recall: 'progressive 3-layer memory search, timeline, and file symbol outline',
|
|
45
46
|
fs_read_skill: 'read a bundled skill by id',
|
|
46
47
|
skill_create: 'save a reusable skill',
|
|
47
48
|
tool_search: 'find and load any tool on this list'
|
package/src/toolsList.ts
CHANGED
|
@@ -56,6 +56,7 @@ const CATALOGUE: Readonly<Record<Exclude<ToolGroup, 'custom'>, Readonly<Record<s
|
|
|
56
56
|
update_plan: 'visible checklist, one active step',
|
|
57
57
|
request_decision: 'ask the user to pick a direction',
|
|
58
58
|
memory_write: 'save durable user fact or design pattern',
|
|
59
|
+
memory_recall: 'progressive 3-layer memory search, timeline, and file symbol outline',
|
|
59
60
|
fs_read_skill: 'read a bundled skill by id',
|
|
60
61
|
skill_create: 'save a reusable skill',
|
|
61
62
|
tool_search: 'find and load any tool on this list'
|