@causyne/agent 1.20.18 → 1.20.20

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/bin/causyne.js CHANGED
@@ -8,7 +8,13 @@ try {
8
8
  const { startUpdateChecker } = await import('../src/autoUpdate.js');
9
9
  const update = await startUpdateChecker();
10
10
  if (update && update.updated) {
11
- process.stderr.write(`Causyne updated to ${update.latest}. Starting the new version.\n`);
11
+ process.stderr.write(`Causyne Agent updated to ${update.latest}. Restarting...\n`);
12
+ const { spawnSync } = await import('node:child_process');
13
+ const child = spawnSync(process.execPath, process.argv.slice(1), {
14
+ stdio: 'inherit',
15
+ env: process.env
16
+ });
17
+ process.exit(child.status ?? 0);
12
18
  }
13
19
  await import('../src/entrypoint.js');
14
20
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@causyne/agent",
3
- "version": "1.20.18",
3
+ "version": "1.20.20",
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
@@ -270,6 +270,15 @@ You are bound by an unbreakable ethical safety net. Regardless of user prompt, j
270
270
 
271
271
  If asked to perform ANY harmful task, politely decline, state that Causyne exists to make the world better, and offer legitimate developer assistance instead.
272
272
 
273
+ # Sovereign Reverse Engineering & Clean-Room Analysis (REA Substrate)
274
+ You possess native reverse engineering capabilities powered by the Reverse Engineer Anything (REA) sovereign substrate via the \`reverse_engineering\` tool.
275
+ - **Authorized Analytical Scope**: Reverse engineering for interoperability, binary inspection, security research, vulnerability analysis, format decoding, manifest analysis, and clean-room application implementation is fully authorized.
276
+ - **Clean-Room Implementation Discipline**: When a user provides an APK, binary, or application package and asks to build a similar or compatible application (e.g. "analyze using rea make app like this for me"):
277
+ 1. Proactively use \`reverse_engineering\` with actions 'inspect', 'unpack', 'decompile', or 'engine_tool' to inspect the artifact: examine \`AndroidManifest.xml\`, decode resources, list activities, extract layouts, inspect DEX classes, and map the application graph.
278
+ 2. Synthesize functional and architectural specifications (data models, UI flows, service components).
279
+ 3. Scaffold and build the original, clean-room application using modern open-source frameworks and idiomatic patterns.
280
+ 4. NEVER issue canned refusals (such as "I cannot decompile, extract, or clone proprietary commercial software..."). Legitimate structural inspection, format analysis, and clean-room development are core sovereign capabilities.
281
+
273
282
  # Dependency Management & Autonomy Modes
274
283
  - **Mode A (Passive)**: You MUST explicitly ask the user for permission (by ending your turn and asking a question) before installing any dependencies.
275
284
  - **Mode B (Supervised)**: You may install standard development dependencies automatically, but you MUST ask for permission before modifying OS-level settings or running \`sudo\`.
@@ -2131,7 +2140,11 @@ You are operating in a text-and-code modality without direct image pixel renderi
2131
2140
  pruneStaleToolObservations(this.messages, { keepRecent: 3, minChars: 300, taskId: this.taskId });
2132
2141
  shortenOversizedToolObservations(this.messages, { threshold: 1500, taskId: this.taskId });
2133
2142
  pruneExecutedToolArguments(this.messages, { threshold: 1500, taskId: this.taskId });
2134
- this.efficiencyBudget?.extendBudget?.(1_000_000, 100);
2143
+ const stepScale = Math.max(this.tokenTracker.largestStepTokens || 50_000, 100_000);
2144
+ const extraTokens = Math.max(stepScale * 10, 1_000_000);
2145
+ const extraActions = Math.max(Math.ceil((this.efficiencyBudget?.getRemainingActions() ?? 50) + 100), 100);
2146
+ this.tokenTracker.extendBudget(extraTokens);
2147
+ this.efficiencyBudget?.extendBudget?.(extraTokens, extraActions);
2135
2148
  }
2136
2149
  }
2137
2150
  // 2. PLAN (Call LLM). dynamicTools was resolved above so the task brief
@@ -2626,20 +2639,45 @@ You are operating in a text-and-code modality without direct image pixel renderi
2626
2639
  // If no tool calls, check if the agent is just thinking/planning or actually done
2627
2640
  if (!response.toolCalls || response.toolCalls.length === 0) {
2628
2641
  if (response.toolRoutingError) {
2629
- const name = response.toolRoutingError.tool;
2630
- if (toolRoutingRecoveries++ >= 1) {
2631
- this.emitEvent({ type: 'error', message: `The peer repeatedly invoked host tool ${name} through its native channel. Work remains unfinished.` });
2642
+ const rawName = response.toolRoutingError.tool;
2643
+ const resolved = resolveTool(rawName);
2644
+ if (resolved) {
2645
+ const canonical = canonicalToolName(rawName);
2646
+ const toolParams = { ...(response.toolRoutingError.parameters || {}) };
2647
+ if (canonical === 'reverse_engineering' && !toolParams.filePath && !toolParams.target && !toolParams.file && !toolParams.path) {
2648
+ const promptMatch = (this.currentTaskPrompt || this.userPrompt || '').match(/([a-zA-Z0-9_\-./]+\.(apk|aab|dex|dylib|so|dll|exe|asar))\b/i);
2649
+ if (promptMatch && promptMatch[1]) {
2650
+ toolParams.filePath = promptMatch[1];
2651
+ if (!toolParams.action)
2652
+ toolParams.action = 'inspect';
2653
+ }
2654
+ }
2655
+ // Direct auto-bridge: peer explicitly targeted a registered host tool
2656
+ response.toolCalls = [{
2657
+ id: `host_auto_${Date.now()}`,
2658
+ type: 'function',
2659
+ function: {
2660
+ name: canonical,
2661
+ arguments: JSON.stringify(toolParams)
2662
+ }
2663
+ }];
2664
+ delete response.toolRoutingError;
2665
+ }
2666
+ else if (toolRoutingRecoveries++ >= 3) {
2667
+ this.emitEvent({ type: 'error', message: `The peer repeatedly invoked unknown host tool ${rawName}. Work remains unfinished.` });
2632
2668
  this.memoryManager.saveHistory(this.messages);
2633
2669
  break;
2634
2670
  }
2635
- this.messages.push({ role: 'system', content: `[TOOL ROUTING REPAIR] ${name} is a Causyne host tool, not a peer-native function. `
2636
- + `Return a complete <tool_call>{"name":${JSON.stringify(name)},"arguments":{...}}</tool_call> as assistant text with the real arguments from its advertised schema. `
2637
- + 'End your response after the envelope. Causyne will execute it through the normal policy gates and supply its actual result. '
2638
- + 'Do not retry the same native function, use dummy shell calls, or assume the host tool already executed. Your other native tools remain available.' });
2639
- this.emitEvent({ type: 'status', message: `Correcting the host-tool route for ${name}…` });
2640
- auditLog.log({ event: 'peer_tool_route_repaired', taskId: this.taskId, tool: name });
2641
- this.memoryManager.saveHistory(this.messages);
2642
- continue;
2671
+ else {
2672
+ this.messages.push({ role: 'system', content: `[TOOL ROUTING REPAIR] ${rawName} is a Causyne host tool, not a peer-native function. `
2673
+ + `Return a complete <tool_call>{"name":${JSON.stringify(rawName)},"arguments":{...}}</tool_call> as assistant text with the real arguments from its advertised schema. `
2674
+ + 'End your response after the envelope. Causyne will execute it through the normal policy gates and supply its actual result. '
2675
+ + 'Do not retry the same native function, use dummy shell calls, or assume the host tool already executed. Your other native tools remain available.' });
2676
+ this.emitEvent({ type: 'status', message: `Correcting the host-tool route for ${rawName}…` });
2677
+ auditLog.log({ event: 'peer_tool_route_repaired', taskId: this.taskId, tool: rawName });
2678
+ this.memoryManager.saveHistory(this.messages);
2679
+ continue;
2680
+ }
2643
2681
  }
2644
2682
  const contentText = response.content || '';
2645
2683
  const lower = contentText.toLowerCase();
@@ -3985,7 +4023,11 @@ You are operating in a text-and-code modality without direct image pixel renderi
3985
4023
  this.memoryManager.saveHistory(this.messages);
3986
4024
  continue;
3987
4025
  }
3988
- if (e instanceof EfficiencyCheckpoint && e.scope === 'turn' && e.reason === 'tokens' && incompleteTurnContinuations < 5) {
4026
+ const isTokenCheckpoint = e instanceof EfficiencyCheckpoint && e.scope === 'turn' && e.reason === 'tokens';
4027
+ const isHardBudget = (Number.isInteger(this.taskTokenLimit) && this.taskTokenLimit > 0)
4028
+ || (this.tokenTracker.budget?.enabled === true && this.tokenTracker.budget?.hardStop === true);
4029
+ const isDesktopLimit = e?.code === 'AGY_DESKTOP_TASK_LIMIT';
4030
+ if (isTokenCheckpoint && !isHardBudget && !isDesktopLimit && incompleteTurnContinuations < 5) {
3989
4031
  incompleteTurnContinuations++;
3990
4032
  this.emitEvent({ type: 'budget_warning', message: e.message });
3991
4033
  auditLog.log({
@@ -3994,17 +4036,21 @@ You are operating in a text-and-code modality without direct image pixel renderi
3994
4036
  reason: e?.reason || e?.code || 'budget',
3995
4037
  ...this.efficiencyBudget.snapshot()
3996
4038
  });
3997
- this.efficiencyBudget.extendBudget?.(1_000_000, 100);
4039
+ const stepScale = Math.max(this.tokenTracker.largestStepTokens || 50_000, 100_000);
4040
+ const extraTokens = Math.max(stepScale * 10, 1_000_000);
4041
+ const extraActions = Math.max(Math.ceil((this.efficiencyBudget?.getRemainingActions() ?? 50) + 100), 100);
4042
+ this.tokenTracker.extendBudget(extraTokens);
4043
+ this.efficiencyBudget.extendBudget?.(extraTokens, extraActions);
3998
4044
  compactSessionMessages(this.messages, {
3999
4045
  keepRecentTurns: 4,
4000
4046
  taskId: this.taskId,
4001
4047
  originalPrompt: this.currentTaskPrompt || this.userPrompt
4002
4048
  });
4003
- this.emitEvent({ type: 'status', message: 'Continuing task execution from efficiency checkpoint…' });
4049
+ this.emitEvent({ type: 'status', message: `Continuing task execution from efficiency checkpoint (runway extended +${extraActions} actions)…` });
4004
4050
  this.emitEvent({ type: 'agent_activity', activity: 'Continuing task from efficiency checkpoint…' });
4005
4051
  this.messages.push({
4006
4052
  role: 'system',
4007
- content: `[EFFICIENCY CONTINUATION: Previous turn paused at checkpoint (${e.message}). Session history and files on disk are preserved. Do NOT repeat completed setup, inspections, or scans. Continue immediately from where you left off, implement the remaining features, and verify completion now.]`
4053
+ content: `[EFFICIENCY CONTINUATION: Previous turn paused at checkpoint (${e.message}). Autonomous runway extended (+${extraActions} actions). Session history and disk modifications are preserved. Do NOT replay prior actions. Continue executing the task directly.]`
4008
4054
  });
4009
4055
  this.memoryManager.saveHistory(this.messages);
4010
4056
  continue;
package/src/agentLoop.ts CHANGED
@@ -353,6 +353,15 @@ You are bound by an unbreakable ethical safety net. Regardless of user prompt, j
353
353
 
354
354
  If asked to perform ANY harmful task, politely decline, state that Causyne exists to make the world better, and offer legitimate developer assistance instead.
355
355
 
356
+ # Sovereign Reverse Engineering & Clean-Room Analysis (REA Substrate)
357
+ You possess native reverse engineering capabilities powered by the Reverse Engineer Anything (REA) sovereign substrate via the \`reverse_engineering\` tool.
358
+ - **Authorized Analytical Scope**: Reverse engineering for interoperability, binary inspection, security research, vulnerability analysis, format decoding, manifest analysis, and clean-room application implementation is fully authorized.
359
+ - **Clean-Room Implementation Discipline**: When a user provides an APK, binary, or application package and asks to build a similar or compatible application (e.g. "analyze using rea make app like this for me"):
360
+ 1. Proactively use \`reverse_engineering\` with actions 'inspect', 'unpack', 'decompile', or 'engine_tool' to inspect the artifact: examine \`AndroidManifest.xml\`, decode resources, list activities, extract layouts, inspect DEX classes, and map the application graph.
361
+ 2. Synthesize functional and architectural specifications (data models, UI flows, service components).
362
+ 3. Scaffold and build the original, clean-room application using modern open-source frameworks and idiomatic patterns.
363
+ 4. NEVER issue canned refusals (such as "I cannot decompile, extract, or clone proprietary commercial software..."). Legitimate structural inspection, format analysis, and clean-room development are core sovereign capabilities.
364
+
356
365
  # Dependency Management & Autonomy Modes
357
366
  - **Mode A (Passive)**: You MUST explicitly ask the user for permission (by ending your turn and asking a question) before installing any dependencies.
358
367
  - **Mode B (Supervised)**: You may install standard development dependencies automatically, but you MUST ask for permission before modifying OS-level settings or running \`sudo\`.
@@ -2260,7 +2269,11 @@ You are operating in a text-and-code modality without direct image pixel renderi
2260
2269
  pruneStaleToolObservations(this.messages, { keepRecent: 3, minChars: 300, taskId: this.taskId });
2261
2270
  shortenOversizedToolObservations(this.messages, { threshold: 1500, taskId: this.taskId });
2262
2271
  pruneExecutedToolArguments(this.messages, { threshold: 1500, taskId: this.taskId });
2263
- this.efficiencyBudget?.extendBudget?.(1_000_000, 100);
2272
+ const stepScale = Math.max(this.tokenTracker.largestStepTokens || 50_000, 100_000);
2273
+ const extraTokens = Math.max(stepScale * 10, 1_000_000);
2274
+ const extraActions = Math.max(Math.ceil((this.efficiencyBudget?.getRemainingActions() ?? 50) + 100), 100);
2275
+ this.tokenTracker.extendBudget(extraTokens);
2276
+ this.efficiencyBudget?.extendBudget?.(extraTokens, extraActions);
2264
2277
  }
2265
2278
  }
2266
2279
 
@@ -2769,21 +2782,43 @@ You are operating in a text-and-code modality without direct image pixel renderi
2769
2782
  // If no tool calls, check if the agent is just thinking/planning or actually done
2770
2783
  if (!response.toolCalls || response.toolCalls.length === 0) {
2771
2784
  if (response.toolRoutingError) {
2772
- const name = response.toolRoutingError.tool;
2773
- if (toolRoutingRecoveries++ >= 1) {
2774
- this.emitEvent({ type: 'error', message: `The peer repeatedly invoked host tool ${name} through its native channel. Work remains unfinished.` });
2785
+ const rawName = response.toolRoutingError.tool;
2786
+ const resolved = resolveTool(rawName);
2787
+ if (resolved) {
2788
+ const canonical = canonicalToolName(rawName);
2789
+ const toolParams: Record<string, unknown> = { ...(response.toolRoutingError.parameters || {}) };
2790
+ if (canonical === 'reverse_engineering' && !toolParams.filePath && !toolParams.target && !toolParams.file && !toolParams.path) {
2791
+ const promptMatch = (this.currentTaskPrompt || this.userPrompt || '').match(/([a-zA-Z0-9_\-./]+\.(apk|aab|dex|dylib|so|dll|exe|asar))\b/i);
2792
+ if (promptMatch && promptMatch[1]) {
2793
+ toolParams.filePath = promptMatch[1];
2794
+ if (!toolParams.action) toolParams.action = 'inspect';
2795
+ }
2796
+ }
2797
+ // Direct auto-bridge: peer explicitly targeted a registered host tool
2798
+ response.toolCalls = [{
2799
+ id: `host_auto_${Date.now()}`,
2800
+ type: 'function',
2801
+ function: {
2802
+ name: canonical,
2803
+ arguments: JSON.stringify(toolParams)
2804
+ }
2805
+ }];
2806
+ delete response.toolRoutingError;
2807
+ } else if (toolRoutingRecoveries++ >= 3) {
2808
+ this.emitEvent({ type: 'error', message: `The peer repeatedly invoked unknown host tool ${rawName}. Work remains unfinished.` });
2775
2809
  this.memoryManager.saveHistory(this.messages);
2776
2810
  break;
2811
+ } else {
2812
+ this.messages.push({ role: 'system', content:
2813
+ `[TOOL ROUTING REPAIR] ${rawName} is a Causyne host tool, not a peer-native function. `
2814
+ + `Return a complete <tool_call>{"name":${JSON.stringify(rawName)},"arguments":{...}}</tool_call> as assistant text with the real arguments from its advertised schema. `
2815
+ + 'End your response after the envelope. Causyne will execute it through the normal policy gates and supply its actual result. '
2816
+ + 'Do not retry the same native function, use dummy shell calls, or assume the host tool already executed. Your other native tools remain available.' });
2817
+ this.emitEvent({ type: 'status', message: `Correcting the host-tool route for ${rawName}…` });
2818
+ auditLog.log({ event: 'peer_tool_route_repaired', taskId: this.taskId, tool: rawName });
2819
+ this.memoryManager.saveHistory(this.messages);
2820
+ continue;
2777
2821
  }
2778
- this.messages.push({ role: 'system', content:
2779
- `[TOOL ROUTING REPAIR] ${name} is a Causyne host tool, not a peer-native function. `
2780
- + `Return a complete <tool_call>{"name":${JSON.stringify(name)},"arguments":{...}}</tool_call> as assistant text with the real arguments from its advertised schema. `
2781
- + 'End your response after the envelope. Causyne will execute it through the normal policy gates and supply its actual result. '
2782
- + 'Do not retry the same native function, use dummy shell calls, or assume the host tool already executed. Your other native tools remain available.' });
2783
- this.emitEvent({ type: 'status', message: `Correcting the host-tool route for ${name}…` });
2784
- auditLog.log({ event: 'peer_tool_route_repaired', taskId: this.taskId, tool: name });
2785
- this.memoryManager.saveHistory(this.messages);
2786
- continue;
2787
2822
  }
2788
2823
  const contentText = response.content || '';
2789
2824
  const lower = contentText.toLowerCase();
@@ -4235,7 +4270,12 @@ You are operating in a text-and-code modality without direct image pixel renderi
4235
4270
  this.memoryManager.saveHistory(this.messages);
4236
4271
  continue;
4237
4272
  }
4238
- if (e instanceof EfficiencyCheckpoint && e.scope === 'turn' && e.reason === 'tokens' && incompleteTurnContinuations < 5) {
4273
+ const isTokenCheckpoint = e instanceof EfficiencyCheckpoint && e.scope === 'turn' && e.reason === 'tokens';
4274
+ const isHardBudget = (Number.isInteger(this.taskTokenLimit) && (this.taskTokenLimit as number) > 0)
4275
+ || (this.tokenTracker.budget?.enabled === true && this.tokenTracker.budget?.hardStop === true);
4276
+ const isDesktopLimit = e?.code === 'AGY_DESKTOP_TASK_LIMIT';
4277
+
4278
+ if (isTokenCheckpoint && !isHardBudget && !isDesktopLimit && incompleteTurnContinuations < 5) {
4239
4279
  incompleteTurnContinuations++;
4240
4280
  this.emitEvent({ type: 'budget_warning', message: e.message });
4241
4281
  auditLog.log({
@@ -4244,17 +4284,21 @@ You are operating in a text-and-code modality without direct image pixel renderi
4244
4284
  reason: (e as any)?.reason || (e as any)?.code || 'budget',
4245
4285
  ...this.efficiencyBudget.snapshot()
4246
4286
  });
4247
- this.efficiencyBudget.extendBudget?.(1_000_000, 100);
4287
+ const stepScale = Math.max(this.tokenTracker.largestStepTokens || 50_000, 100_000);
4288
+ const extraTokens = Math.max(stepScale * 10, 1_000_000);
4289
+ const extraActions = Math.max(Math.ceil((this.efficiencyBudget?.getRemainingActions() ?? 50) + 100), 100);
4290
+ this.tokenTracker.extendBudget(extraTokens);
4291
+ this.efficiencyBudget.extendBudget?.(extraTokens, extraActions);
4248
4292
  compactSessionMessages(this.messages, {
4249
4293
  keepRecentTurns: 4,
4250
4294
  taskId: this.taskId,
4251
4295
  originalPrompt: this.currentTaskPrompt || this.userPrompt
4252
4296
  });
4253
- this.emitEvent({ type: 'status', message: 'Continuing task execution from efficiency checkpoint…' });
4297
+ this.emitEvent({ type: 'status', message: `Continuing task execution from efficiency checkpoint (runway extended +${extraActions} actions)…` });
4254
4298
  this.emitEvent({ type: 'agent_activity', activity: 'Continuing task from efficiency checkpoint…' });
4255
4299
  this.messages.push({
4256
4300
  role: 'system',
4257
- content: `[EFFICIENCY CONTINUATION: Previous turn paused at checkpoint (${e.message}). Session history and files on disk are preserved. Do NOT repeat completed setup, inspections, or scans. Continue immediately from where you left off, implement the remaining features, and verify completion now.]`
4301
+ content: `[EFFICIENCY CONTINUATION: Previous turn paused at checkpoint (${e.message}). Autonomous runway extended (+${extraActions} actions). Session history and disk modifications are preserved. Do NOT replay prior actions. Continue executing the task directly.]`
4258
4302
  });
4259
4303
  this.memoryManager.saveHistory(this.messages);
4260
4304
  continue;