@causyne/agent 1.20.17 → 1.20.19
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/package.json +1 -1
- package/src/agentLoop.js +63 -17
- package/src/agentLoop.ts +62 -18
- package/src/engines/reverseHarness.js +65 -5
- package/src/engines/reverseHarness.ts +84 -4
- package/src/promptMentions.js +25 -12
- package/src/promptMentions.ts +30 -15
- package/src/providers/acp.js +9 -1
- package/src/providers/acp.ts +9 -1
- package/src/providers/antigravity.js +120 -11
- package/src/providers/antigravity.ts +130 -11
- package/src/providers/base.d.ts +1 -1
- package/src/providers/budgetEnforcer.js +5 -0
- package/src/providers/budgetEnforcer.ts +6 -0
- package/src/tokenTracker.js +8 -0
- package/src/tokenTracker.ts +9 -0
- package/src/toolPacks.js +1 -1
- package/src/toolPacks.ts +1 -1
- package/src/tools/reverseEngineering.js +99 -8
- package/src/tools/reverseEngineering.ts +107 -9
package/package.json
CHANGED
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.
|
|
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
|
|
2630
|
-
|
|
2631
|
-
|
|
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
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
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,26 +4023,34 @@ 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
|
-
|
|
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({
|
|
3992
4034
|
event: 'efficiency_checkpoint',
|
|
3993
4035
|
taskId: this.taskId,
|
|
3994
|
-
reason: e
|
|
4036
|
+
reason: e?.reason || e?.code || 'budget',
|
|
3995
4037
|
...this.efficiencyBudget.snapshot()
|
|
3996
4038
|
});
|
|
3997
|
-
this.
|
|
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:
|
|
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
|
|
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.
|
|
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
|
|
2773
|
-
|
|
2774
|
-
|
|
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,26 +4270,35 @@ 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
|
-
|
|
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({
|
|
4242
4282
|
event: 'efficiency_checkpoint',
|
|
4243
4283
|
taskId: this.taskId,
|
|
4244
|
-
reason: e
|
|
4284
|
+
reason: (e as any)?.reason || (e as any)?.code || 'budget',
|
|
4245
4285
|
...this.efficiencyBudget.snapshot()
|
|
4246
4286
|
});
|
|
4247
|
-
this.
|
|
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:
|
|
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
|
|
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;
|
|
@@ -48,10 +48,25 @@ export class SovereignReverseHarness {
|
|
|
48
48
|
}
|
|
49
49
|
this.connectPromise = (async () => {
|
|
50
50
|
try {
|
|
51
|
+
// 1. Locate local rea binary if installed (sub-second launch, zero network lag)
|
|
52
|
+
let command = 'npx';
|
|
53
|
+
let args = ['--yes', 'rea-agents@6.8.0', '--mcp'];
|
|
54
|
+
const candidatePaths = [
|
|
55
|
+
path.join(process.env.HOME || '', '.local', 'bin', 'rea'),
|
|
56
|
+
'/usr/local/bin/rea',
|
|
57
|
+
'/opt/homebrew/bin/rea'
|
|
58
|
+
];
|
|
59
|
+
for (const candidate of candidatePaths) {
|
|
60
|
+
if (fs.existsSync(candidate)) {
|
|
61
|
+
command = candidate;
|
|
62
|
+
args = ['--mcp'];
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
51
66
|
const mcpClient = new McpClient({
|
|
52
67
|
name: 'causyne_reverse_engineering',
|
|
53
|
-
command
|
|
54
|
-
args
|
|
68
|
+
command,
|
|
69
|
+
args,
|
|
55
70
|
timeoutMs: 60_000
|
|
56
71
|
});
|
|
57
72
|
await mcpClient.connect();
|
|
@@ -145,10 +160,19 @@ export class SovereignReverseHarness {
|
|
|
145
160
|
if (!fs.existsSync(resolved)) {
|
|
146
161
|
return { success: false, toolName: 'inspect_binary', error: `File not found: ${resolved}`, source: 'engine' };
|
|
147
162
|
}
|
|
163
|
+
const ext = path.extname(resolved).toLowerCase();
|
|
164
|
+
if (ext === '.apk' || ext === '.aab') {
|
|
165
|
+
const pkg = await this.callEngineTool('inspect_android_package', { path: resolved }, signal);
|
|
166
|
+
if (pkg.success)
|
|
167
|
+
return pkg;
|
|
168
|
+
const dec = await this.callEngineTool('decode_android_resources', { path: resolved }, signal);
|
|
169
|
+
if (dec.success)
|
|
170
|
+
return dec;
|
|
171
|
+
}
|
|
148
172
|
// Try primary session / overview tools
|
|
149
|
-
const
|
|
150
|
-
if (
|
|
151
|
-
return
|
|
173
|
+
const open = await this.callEngineTool('open_binary', { path: resolved }, signal);
|
|
174
|
+
if (open.success)
|
|
175
|
+
return open;
|
|
152
176
|
const layout = await this.callEngineTool('inspect_binary_layout', { path: resolved }, signal);
|
|
153
177
|
if (layout.success)
|
|
154
178
|
return layout;
|
|
@@ -224,5 +248,41 @@ export class SovereignReverseHarness {
|
|
|
224
248
|
...(options.script ? { script: options.script } : {})
|
|
225
249
|
}, signal);
|
|
226
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Decode Android resources (AndroidManifest.xml, resources.arsc, layouts).
|
|
253
|
+
*/
|
|
254
|
+
async decodeAndroidResources(apkPath, outputDirectory, signal) {
|
|
255
|
+
const resolved = resolveUserPath(apkPath);
|
|
256
|
+
if (!fs.existsSync(resolved)) {
|
|
257
|
+
return { success: false, toolName: 'decode_android_resources', error: `APK not found: ${resolved}`, source: 'engine' };
|
|
258
|
+
}
|
|
259
|
+
return this.callEngineTool('decode_android_resources', {
|
|
260
|
+
path: resolved,
|
|
261
|
+
...(outputDirectory ? { output_directory: resolveUserPath(outputDirectory) } : {})
|
|
262
|
+
}, signal);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Search classes or list class hierarchy inside an Android APK.
|
|
266
|
+
*/
|
|
267
|
+
async searchAndroidClasses(apkPath, query = '', signal) {
|
|
268
|
+
const resolved = resolveUserPath(apkPath);
|
|
269
|
+
if (!fs.existsSync(resolved)) {
|
|
270
|
+
return { success: false, toolName: 'search_android_classes', error: `APK not found: ${resolved}`, source: 'engine' };
|
|
271
|
+
}
|
|
272
|
+
return this.callEngineTool('search_android_classes', {
|
|
273
|
+
path: resolved,
|
|
274
|
+
query: query || ''
|
|
275
|
+
}, signal);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Project authenticated Android application graph (components, intents, activities).
|
|
279
|
+
*/
|
|
280
|
+
async projectAndroidGraph(apkPath, signal) {
|
|
281
|
+
const resolved = resolveUserPath(apkPath);
|
|
282
|
+
if (!fs.existsSync(resolved)) {
|
|
283
|
+
return { success: false, toolName: 'project_android_application_graph', error: `APK not found: ${resolved}`, source: 'engine' };
|
|
284
|
+
}
|
|
285
|
+
return this.callEngineTool('project_android_application_graph', { path: resolved }, signal);
|
|
286
|
+
}
|
|
227
287
|
}
|
|
228
288
|
export const sovereignReverseHarness = SovereignReverseHarness.getInstance();
|
|
@@ -62,10 +62,28 @@ export class SovereignReverseHarness {
|
|
|
62
62
|
|
|
63
63
|
this.connectPromise = (async () => {
|
|
64
64
|
try {
|
|
65
|
+
// 1. Locate local rea binary if installed (sub-second launch, zero network lag)
|
|
66
|
+
let command = 'npx';
|
|
67
|
+
let args = ['--yes', 'rea-agents@6.8.0', '--mcp'];
|
|
68
|
+
|
|
69
|
+
const candidatePaths = [
|
|
70
|
+
path.join(process.env.HOME || '', '.local', 'bin', 'rea'),
|
|
71
|
+
'/usr/local/bin/rea',
|
|
72
|
+
'/opt/homebrew/bin/rea'
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
for (const candidate of candidatePaths) {
|
|
76
|
+
if (fs.existsSync(candidate)) {
|
|
77
|
+
command = candidate;
|
|
78
|
+
args = ['--mcp'];
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
65
83
|
const mcpClient = new McpClient({
|
|
66
84
|
name: 'causyne_reverse_engineering',
|
|
67
|
-
command
|
|
68
|
-
args
|
|
85
|
+
command,
|
|
86
|
+
args,
|
|
69
87
|
timeoutMs: 60_000
|
|
70
88
|
});
|
|
71
89
|
|
|
@@ -165,9 +183,18 @@ export class SovereignReverseHarness {
|
|
|
165
183
|
return { success: false, toolName: 'inspect_binary', error: `File not found: ${resolved}`, source: 'engine' };
|
|
166
184
|
}
|
|
167
185
|
|
|
186
|
+
const ext = path.extname(resolved).toLowerCase();
|
|
187
|
+
if (ext === '.apk' || ext === '.aab') {
|
|
188
|
+
const pkg = await this.callEngineTool('inspect_android_package', { path: resolved }, signal);
|
|
189
|
+
if (pkg.success) return pkg;
|
|
190
|
+
|
|
191
|
+
const dec = await this.callEngineTool('decode_android_resources', { path: resolved }, signal);
|
|
192
|
+
if (dec.success) return dec;
|
|
193
|
+
}
|
|
194
|
+
|
|
168
195
|
// Try primary session / overview tools
|
|
169
|
-
const
|
|
170
|
-
if (
|
|
196
|
+
const open = await this.callEngineTool('open_binary', { path: resolved }, signal);
|
|
197
|
+
if (open.success) return open;
|
|
171
198
|
|
|
172
199
|
const layout = await this.callEngineTool('inspect_binary_layout', { path: resolved }, signal);
|
|
173
200
|
if (layout.success) return layout;
|
|
@@ -267,6 +294,59 @@ export class SovereignReverseHarness {
|
|
|
267
294
|
...(options.script ? { script: options.script } : {})
|
|
268
295
|
}, signal);
|
|
269
296
|
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Decode Android resources (AndroidManifest.xml, resources.arsc, layouts).
|
|
300
|
+
*/
|
|
301
|
+
public async decodeAndroidResources(
|
|
302
|
+
apkPath: string,
|
|
303
|
+
outputDirectory?: string,
|
|
304
|
+
signal?: AbortSignal
|
|
305
|
+
): Promise<EngineToolExecutionResult> {
|
|
306
|
+
const resolved = resolveUserPath(apkPath);
|
|
307
|
+
if (!fs.existsSync(resolved)) {
|
|
308
|
+
return { success: false, toolName: 'decode_android_resources', error: `APK not found: ${resolved}`, source: 'engine' };
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return this.callEngineTool('decode_android_resources', {
|
|
312
|
+
path: resolved,
|
|
313
|
+
...(outputDirectory ? { output_directory: resolveUserPath(outputDirectory) } : {})
|
|
314
|
+
}, signal);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Search classes or list class hierarchy inside an Android APK.
|
|
319
|
+
*/
|
|
320
|
+
public async searchAndroidClasses(
|
|
321
|
+
apkPath: string,
|
|
322
|
+
query: string = '',
|
|
323
|
+
signal?: AbortSignal
|
|
324
|
+
): Promise<EngineToolExecutionResult> {
|
|
325
|
+
const resolved = resolveUserPath(apkPath);
|
|
326
|
+
if (!fs.existsSync(resolved)) {
|
|
327
|
+
return { success: false, toolName: 'search_android_classes', error: `APK not found: ${resolved}`, source: 'engine' };
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return this.callEngineTool('search_android_classes', {
|
|
331
|
+
path: resolved,
|
|
332
|
+
query: query || ''
|
|
333
|
+
}, signal);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Project authenticated Android application graph (components, intents, activities).
|
|
338
|
+
*/
|
|
339
|
+
public async projectAndroidGraph(
|
|
340
|
+
apkPath: string,
|
|
341
|
+
signal?: AbortSignal
|
|
342
|
+
): Promise<EngineToolExecutionResult> {
|
|
343
|
+
const resolved = resolveUserPath(apkPath);
|
|
344
|
+
if (!fs.existsSync(resolved)) {
|
|
345
|
+
return { success: false, toolName: 'project_android_application_graph', error: `APK not found: ${resolved}`, source: 'engine' };
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
return this.callEngineTool('project_android_application_graph', { path: resolved }, signal);
|
|
349
|
+
}
|
|
270
350
|
}
|
|
271
351
|
|
|
272
352
|
export const sovereignReverseHarness = SovereignReverseHarness.getInstance();
|
package/src/promptMentions.js
CHANGED
|
@@ -44,7 +44,7 @@ export function extractMentions(text) {
|
|
|
44
44
|
if (!cleanPath || seen.has(cleanPath))
|
|
45
45
|
continue;
|
|
46
46
|
// Do not capture npm scope prefixes on their own or common non-file @ words
|
|
47
|
-
if (cleanPath === 'here' || cleanPath === 'all' || cleanPath === 'workspace') {
|
|
47
|
+
if (cleanPath === 'here' || cleanPath === 'all' || cleanPath === 'workspace' || cleanPath === 'rea' || cleanPath === 'rea-agents') {
|
|
48
48
|
seen.add(cleanPath);
|
|
49
49
|
mentions.push({ raw, path: cleanPath, isQuoted: false, isMeta: true });
|
|
50
50
|
continue;
|
|
@@ -76,6 +76,10 @@ export async function resolveMentionedContext(prompt, options = {}) {
|
|
|
76
76
|
if (m.path === 'workspace' || m.path === 'here') {
|
|
77
77
|
sections.push(`📁 REFERENCED SCOPE: Whole workspace (${cwd})`);
|
|
78
78
|
}
|
|
79
|
+
else if (m.path === 'rea' || m.path === 'rea-agents') {
|
|
80
|
+
sections.push(`🔬 REFERENCED CAPABILITY: Reverse Engineer Anything (REA) Substrate active.\n` +
|
|
81
|
+
`Use the 'reverse_engineering' tool with action 'inspect', 'unpack', 'decompile', or 'engine_tool' to analyze APKs, binaries, and assemblies.`);
|
|
82
|
+
}
|
|
79
83
|
continue;
|
|
80
84
|
}
|
|
81
85
|
let targetPath = path.resolve(cwd, m.path);
|
|
@@ -136,20 +140,29 @@ export async function resolveMentionedContext(prompt, options = {}) {
|
|
|
136
140
|
more);
|
|
137
141
|
}
|
|
138
142
|
else if (stats.isFile()) {
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
const ext = path.extname(targetPath).toLowerCase();
|
|
144
|
+
const isBinary = /\.(apk|aab|dex|dylib|so|dll|exe|bin|asar|zip|tar|gz|tgz)$/i.test(ext);
|
|
145
|
+
if (isBinary) {
|
|
146
|
+
const sizeMb = (stats.size / (1024 * 1024)).toFixed(2);
|
|
147
|
+
sections.push(`📦 REFERENCED BINARY PACKAGE: ${relPath} (${stats.size.toLocaleString()} bytes, ~${sizeMb} MB, format: ${ext.toUpperCase().replace('.', '')})\n` +
|
|
148
|
+
`Note: This is a binary/compiled package. Do not read raw bytes. Use the 'reverse_engineering' tool with action 'inspect', 'unpack', or 'decompile' to analyze manifest, classes, resources, and architecture.`);
|
|
145
149
|
}
|
|
146
150
|
else {
|
|
147
|
-
|
|
151
|
+
const content = fs.readFileSync(targetPath, 'utf8');
|
|
152
|
+
const lines = content.split('\n');
|
|
153
|
+
let body;
|
|
154
|
+
if (lines.length > MAX_MENTION_FILE_LINES) {
|
|
155
|
+
body = lines.slice(0, MAX_MENTION_FILE_LINES).join('\n') +
|
|
156
|
+
`\n\n... [Truncated: showing first ${MAX_MENTION_FILE_LINES} of ${lines.length} lines. Use fs.read for remaining lines.]`;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
body = content;
|
|
160
|
+
}
|
|
161
|
+
sections.push(`📄 REFERENCED FILE: ${relPath} (${lines.length} lines):\n` +
|
|
162
|
+
'```\n' +
|
|
163
|
+
body + '\n' +
|
|
164
|
+
'```');
|
|
148
165
|
}
|
|
149
|
-
sections.push(`📄 REFERENCED FILE: ${relPath} (${lines.length} lines):\n` +
|
|
150
|
-
'```\n' +
|
|
151
|
-
body + '\n' +
|
|
152
|
-
'```');
|
|
153
166
|
}
|
|
154
167
|
}
|
|
155
168
|
catch (err) {
|
package/src/promptMentions.ts
CHANGED
|
@@ -67,7 +67,7 @@ export function extractMentions(text: string): Mention[] {
|
|
|
67
67
|
if (!cleanPath || seen.has(cleanPath)) continue;
|
|
68
68
|
|
|
69
69
|
// Do not capture npm scope prefixes on their own or common non-file @ words
|
|
70
|
-
if (cleanPath === 'here' || cleanPath === 'all' || cleanPath === 'workspace') {
|
|
70
|
+
if (cleanPath === 'here' || cleanPath === 'all' || cleanPath === 'workspace' || cleanPath === 'rea' || cleanPath === 'rea-agents') {
|
|
71
71
|
seen.add(cleanPath);
|
|
72
72
|
mentions.push({ raw, path: cleanPath, isQuoted: false, isMeta: true });
|
|
73
73
|
continue;
|
|
@@ -106,6 +106,11 @@ export async function resolveMentionedContext(
|
|
|
106
106
|
if (m.isMeta) {
|
|
107
107
|
if (m.path === 'workspace' || m.path === 'here') {
|
|
108
108
|
sections.push(`📁 REFERENCED SCOPE: Whole workspace (${cwd})`);
|
|
109
|
+
} else if (m.path === 'rea' || m.path === 'rea-agents') {
|
|
110
|
+
sections.push(
|
|
111
|
+
`🔬 REFERENCED CAPABILITY: Reverse Engineer Anything (REA) Substrate active.\n` +
|
|
112
|
+
`Use the 'reverse_engineering' tool with action 'inspect', 'unpack', 'decompile', or 'engine_tool' to analyze APKs, binaries, and assemblies.`
|
|
113
|
+
);
|
|
109
114
|
}
|
|
110
115
|
continue;
|
|
111
116
|
}
|
|
@@ -175,22 +180,32 @@ export async function resolveMentionedContext(
|
|
|
175
180
|
more
|
|
176
181
|
);
|
|
177
182
|
} else if (stats.isFile()) {
|
|
178
|
-
const
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
183
|
+
const ext = path.extname(targetPath).toLowerCase();
|
|
184
|
+
const isBinary = /\.(apk|aab|dex|dylib|so|dll|exe|bin|asar|zip|tar|gz|tgz)$/i.test(ext);
|
|
185
|
+
if (isBinary) {
|
|
186
|
+
const sizeMb = (stats.size / (1024 * 1024)).toFixed(2);
|
|
187
|
+
sections.push(
|
|
188
|
+
`📦 REFERENCED BINARY PACKAGE: ${relPath} (${stats.size.toLocaleString()} bytes, ~${sizeMb} MB, format: ${ext.toUpperCase().replace('.', '')})\n` +
|
|
189
|
+
`Note: This is a binary/compiled package. Do not read raw bytes. Use the 'reverse_engineering' tool with action 'inspect', 'unpack', or 'decompile' to analyze manifest, classes, resources, and architecture.`
|
|
190
|
+
);
|
|
184
191
|
} else {
|
|
185
|
-
|
|
186
|
-
|
|
192
|
+
const content = fs.readFileSync(targetPath, 'utf8');
|
|
193
|
+
const lines = content.split('\n');
|
|
194
|
+
let body: string;
|
|
195
|
+
if (lines.length > MAX_MENTION_FILE_LINES) {
|
|
196
|
+
body = lines.slice(0, MAX_MENTION_FILE_LINES).join('\n') +
|
|
197
|
+
`\n\n... [Truncated: showing first ${MAX_MENTION_FILE_LINES} of ${lines.length} lines. Use fs.read for remaining lines.]`;
|
|
198
|
+
} else {
|
|
199
|
+
body = content;
|
|
200
|
+
}
|
|
187
201
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
202
|
+
sections.push(
|
|
203
|
+
`📄 REFERENCED FILE: ${relPath} (${lines.length} lines):\n` +
|
|
204
|
+
'```\n' +
|
|
205
|
+
body + '\n' +
|
|
206
|
+
'```'
|
|
207
|
+
);
|
|
208
|
+
}
|
|
194
209
|
}
|
|
195
210
|
} catch (err: unknown) {
|
|
196
211
|
const msg = err instanceof Error ? err.message : String(err);
|
package/src/providers/acp.js
CHANGED
|
@@ -486,7 +486,15 @@ export class AcpProvider extends LLMProvider {
|
|
|
486
486
|
if (isInvalidPseudoTool) {
|
|
487
487
|
const requested = typeof input.tool === 'string' ? input.tool : '';
|
|
488
488
|
if (!this.toolRoutingError && requested && normalizeToolContracts(this.peerServices?.tools || []).some(tool => tool.name === requested)) {
|
|
489
|
-
|
|
489
|
+
const rawArgs = (input.args && typeof input.args === 'object') ? input.args
|
|
490
|
+
: (input.parameters && typeof input.parameters === 'object') ? input.parameters
|
|
491
|
+
: (earlier?.parameters && typeof earlier.parameters === 'object') ? earlier.parameters
|
|
492
|
+
: undefined;
|
|
493
|
+
this.toolRoutingError = {
|
|
494
|
+
tool: requested,
|
|
495
|
+
message: typeof input.error === 'string' ? input.error : 'Host tool requested through the peer-native channel',
|
|
496
|
+
parameters: rawArgs
|
|
497
|
+
};
|
|
490
498
|
client.notifyCancel(sessionId);
|
|
491
499
|
}
|
|
492
500
|
this.liveFileActions.delete(id);
|