@causyne/agent 1.20.15 → 1.20.17
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/docs/THIRD_PARTY_NOTICES.md +26 -0
- package/package.json +7 -4
- package/src/engines/reverseHarness.js +228 -0
- package/src/engines/reverseHarness.ts +272 -0
- package/src/providers/budgetEnforcer.js +1 -1
- package/src/providers/budgetEnforcer.ts +1 -1
- package/src/toolPacks.js +6 -1
- package/src/toolPacks.ts +8 -2
- package/src/tools/registry.js +9 -1
- package/src/tools/reverseEngineering.js +691 -0
- package/src/tools/reverseEngineering.ts +791 -0
- package/src/toolsList.js +4 -1
- package/src/toolsList.ts +5 -2
- package/src/tui/chatRenderer.js +109 -7
- package/src/tui/composerControls.js +6 -0
- package/src/tui/composerControls.ts +6 -0
- package/src/tui/messageInteraction.js +11 -3
- package/src/tui/messageInteraction.ts +12 -2
- package/src/tui/prompt.js +26 -5
- package/src/tui/scrollInteraction.js +7 -0
- package/src/tui/scrollInteraction.ts +9 -0
- package/src/tui/sessionPicker.js +3 -10
- package/src/tui/sessionPicker.ts +3 -10
- package/src/tui/stageSurface.js +22 -10
- package/src/tui/turnRail.js +124 -19
- package/src/tui/turnRail.ts +140 -17
|
@@ -116,6 +116,32 @@ names are used solely for required legal copyright attribution and not as produc
|
|
|
116
116
|
> Copyright (c) 2026 The open-source engine contributors.
|
|
117
117
|
> Licensed under the Apache License, Version 2.0 or the MIT License.
|
|
118
118
|
|
|
119
|
+
The sovereign reverse engineering capability operated via `src/tools/reverseEngineering.ts`
|
|
120
|
+
and `src/engines/reverseHarness.ts` powers **Causyne Sovereign Reverse Engineering**.
|
|
121
|
+
Tool contracts and headless substrate bindings are adapted under the terms of the MIT License:
|
|
122
|
+
|
|
123
|
+
> MIT License
|
|
124
|
+
>
|
|
125
|
+
> Copyright (c) 2026 morluto
|
|
126
|
+
>
|
|
127
|
+
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
128
|
+
> of this software and associated documentation files (the "Software"), to deal
|
|
129
|
+
> in the Software without restriction, including without limitation the rights
|
|
130
|
+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
131
|
+
> copies of the Software, and to permit persons to whom the Software is
|
|
132
|
+
> furnished to do so, subject to the following conditions:
|
|
133
|
+
>
|
|
134
|
+
> The above copyright notice and this permission notice shall be included in all
|
|
135
|
+
> copies or substantial portions of the Software.
|
|
136
|
+
>
|
|
137
|
+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
138
|
+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
139
|
+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
140
|
+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
141
|
+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
142
|
+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
143
|
+
> SOFTWARE.
|
|
144
|
+
|
|
119
145
|
|
|
120
146
|
Repository scanning found no third-party copyright header or license marker in
|
|
121
147
|
the project-authored source and skill files. That negative scan alone cannot
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@causyne/agent",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.17",
|
|
4
4
|
"description": "Agentic AI for software, tools, and computer workflows",
|
|
5
5
|
"main": "bin/causyne.js",
|
|
6
6
|
"type": "module",
|
|
@@ -54,18 +54,21 @@
|
|
|
54
54
|
"url": "https://github.com/ikbal-causyne/causyne-agent/issues"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@modelcontextprotocol/client": "2.
|
|
57
|
+
"@modelcontextprotocol/client": "^2.4.0",
|
|
58
58
|
"acorn-walk": "^8.3.5",
|
|
59
59
|
"commander": "^11.1.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@babel/parser": "^8.0.7",
|
|
63
|
-
"@modelcontextprotocol/node": "2.1.
|
|
64
|
-
"@modelcontextprotocol/server": "2.
|
|
63
|
+
"@modelcontextprotocol/node": "^2.1.2",
|
|
64
|
+
"@modelcontextprotocol/server": "^2.4.0",
|
|
65
65
|
"@types/node": "^22.20.2",
|
|
66
66
|
"acorn": "^8.18.0",
|
|
67
67
|
"typescript": "^7.0.2",
|
|
68
68
|
"zod": "4.6.7"
|
|
69
69
|
},
|
|
70
|
+
"overrides": {
|
|
71
|
+
"@hono/node-server": "^2.1.5"
|
|
72
|
+
},
|
|
70
73
|
"private": false
|
|
71
74
|
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// Sovereign Reverse Engineering Engine Harness.
|
|
2
|
+
//
|
|
3
|
+
// Bridges Causyne Agent to the headless reverse engineering engine substrate
|
|
4
|
+
// via the Model Context Protocol (MCP) stdio transport.
|
|
5
|
+
//
|
|
6
|
+
// Encapsulates on-demand process lifecycle, error containment, execution timeouts,
|
|
7
|
+
// and graceful fallback mechanisms to guarantee zero crashes on Causyne host processes.
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { McpClient } from '../mcp/mcpClient.js';
|
|
11
|
+
import { resolveUserPath } from '../utils/paths.js';
|
|
12
|
+
export class SovereignReverseHarness {
|
|
13
|
+
static instance = null;
|
|
14
|
+
client = null;
|
|
15
|
+
connectPromise = null;
|
|
16
|
+
isAvailableCache = null;
|
|
17
|
+
static getInstance() {
|
|
18
|
+
if (!SovereignReverseHarness.instance) {
|
|
19
|
+
SovereignReverseHarness.instance = new SovereignReverseHarness();
|
|
20
|
+
}
|
|
21
|
+
return SovereignReverseHarness.instance;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Check if the headless reverse engineering engine is available in the current environment.
|
|
25
|
+
*/
|
|
26
|
+
async isAvailable() {
|
|
27
|
+
if (this.isAvailableCache !== null)
|
|
28
|
+
return this.isAvailableCache;
|
|
29
|
+
try {
|
|
30
|
+
const client = await this.ensureConnected();
|
|
31
|
+
this.isAvailableCache = client !== null && client.status.state === 'connected';
|
|
32
|
+
return this.isAvailableCache;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
this.isAvailableCache = false;
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Lazily establish connection to the sovereign engine via stdio MCP.
|
|
41
|
+
*/
|
|
42
|
+
async ensureConnected() {
|
|
43
|
+
if (this.client && this.client.status.state === 'connected') {
|
|
44
|
+
return this.client;
|
|
45
|
+
}
|
|
46
|
+
if (this.connectPromise) {
|
|
47
|
+
return this.connectPromise;
|
|
48
|
+
}
|
|
49
|
+
this.connectPromise = (async () => {
|
|
50
|
+
try {
|
|
51
|
+
const mcpClient = new McpClient({
|
|
52
|
+
name: 'causyne_reverse_engineering',
|
|
53
|
+
command: 'npx',
|
|
54
|
+
args: ['--yes', 'rea-agents@6.8.0', 'mcp'],
|
|
55
|
+
timeoutMs: 60_000
|
|
56
|
+
});
|
|
57
|
+
await mcpClient.connect();
|
|
58
|
+
this.client = mcpClient;
|
|
59
|
+
this.isAvailableCache = true;
|
|
60
|
+
return this.client;
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
this.client = null;
|
|
64
|
+
this.isAvailableCache = false;
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
this.connectPromise = null;
|
|
69
|
+
}
|
|
70
|
+
})();
|
|
71
|
+
return this.connectPromise;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Execute an upstream tool directly through the MCP engine.
|
|
75
|
+
*/
|
|
76
|
+
async callEngineTool(toolName, args, signal) {
|
|
77
|
+
try {
|
|
78
|
+
const client = await this.ensureConnected();
|
|
79
|
+
if (!client || client.status.state !== 'connected') {
|
|
80
|
+
return {
|
|
81
|
+
success: false,
|
|
82
|
+
toolName,
|
|
83
|
+
error: 'Reverse engineering engine substrate is currently unreachable.',
|
|
84
|
+
source: 'engine'
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const res = await client.callTool(toolName, args, signal);
|
|
88
|
+
return {
|
|
89
|
+
success: res.success,
|
|
90
|
+
toolName,
|
|
91
|
+
output: res.output,
|
|
92
|
+
error: res.error,
|
|
93
|
+
structuredContent: res.structuredContent,
|
|
94
|
+
source: 'engine'
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
return {
|
|
99
|
+
success: false,
|
|
100
|
+
toolName,
|
|
101
|
+
error: err instanceof Error ? err.message : String(err),
|
|
102
|
+
source: 'engine'
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* List all specialized tools advertised by the engine.
|
|
108
|
+
*/
|
|
109
|
+
async listTools() {
|
|
110
|
+
try {
|
|
111
|
+
const client = await this.ensureConnected();
|
|
112
|
+
if (!client)
|
|
113
|
+
return [];
|
|
114
|
+
return client.tools.map(t => t.name);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Disconnect the client and shut down the background process cleanly.
|
|
122
|
+
*/
|
|
123
|
+
async disconnect() {
|
|
124
|
+
if (this.client) {
|
|
125
|
+
try {
|
|
126
|
+
await this.client.close();
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
// Safe disposal
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
this.client = null;
|
|
133
|
+
this.isAvailableCache = null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
138
|
+
// HIGH-LEVEL SOVEREIGN ACTIONS
|
|
139
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
140
|
+
/**
|
|
141
|
+
* Perform deep binary inspection via engine tools.
|
|
142
|
+
*/
|
|
143
|
+
async inspectBinary(filePath, signal) {
|
|
144
|
+
const resolved = resolveUserPath(filePath);
|
|
145
|
+
if (!fs.existsSync(resolved)) {
|
|
146
|
+
return { success: false, toolName: 'inspect_binary', error: `File not found: ${resolved}`, source: 'engine' };
|
|
147
|
+
}
|
|
148
|
+
// Try primary session / overview tools
|
|
149
|
+
const overview = await this.callEngineTool('binary_overview', { path: resolved }, signal);
|
|
150
|
+
if (overview.success)
|
|
151
|
+
return overview;
|
|
152
|
+
const layout = await this.callEngineTool('inspect_binary_layout', { path: resolved }, signal);
|
|
153
|
+
if (layout.success)
|
|
154
|
+
return layout;
|
|
155
|
+
// Fall back to objdump if available on engine
|
|
156
|
+
return this.callEngineTool('inspect_with_objdump', { path: resolved }, signal);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Perform headless decompilation of a function or address.
|
|
160
|
+
*/
|
|
161
|
+
async decompile(filePath, targetFunction, address, signal) {
|
|
162
|
+
const resolved = resolveUserPath(filePath);
|
|
163
|
+
if (!fs.existsSync(resolved)) {
|
|
164
|
+
return { success: false, toolName: 'decompile', error: `Target not found: ${resolved}`, source: 'engine' };
|
|
165
|
+
}
|
|
166
|
+
if (targetFunction) {
|
|
167
|
+
const funcRes = await this.callEngineTool('analyze_function', { path: resolved, function_name: targetFunction }, signal);
|
|
168
|
+
if (funcRes.success)
|
|
169
|
+
return funcRes;
|
|
170
|
+
}
|
|
171
|
+
if (address) {
|
|
172
|
+
const addrRes = await this.callEngineTool('procedure_pseudo_code', { path: resolved, address }, signal);
|
|
173
|
+
if (addrRes.success)
|
|
174
|
+
return addrRes;
|
|
175
|
+
}
|
|
176
|
+
// General decompilation
|
|
177
|
+
const decompileRes = await this.callEngineTool('decompile_all', { path: resolved }, signal);
|
|
178
|
+
if (decompileRes.success)
|
|
179
|
+
return decompileRes;
|
|
180
|
+
// Rizin / Cutter command fallback
|
|
181
|
+
return this.callEngineTool('execute_rizin_command', { path: resolved, command: 'pdd' }, signal);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Unpack an application bundle (ASAR, APK, container).
|
|
185
|
+
*/
|
|
186
|
+
async unpackBundle(bundlePath, outputDirectory, signal) {
|
|
187
|
+
const resolved = resolveUserPath(bundlePath);
|
|
188
|
+
if (!fs.existsSync(resolved)) {
|
|
189
|
+
return { success: false, toolName: 'unpack_bundle', error: `Bundle not found: ${resolved}`, source: 'engine' };
|
|
190
|
+
}
|
|
191
|
+
const ext = path.extname(resolved).toLowerCase();
|
|
192
|
+
if (ext === '.apk' || ext === '.aab') {
|
|
193
|
+
const apkRes = await this.callEngineTool('decode_android_resources', { path: resolved }, signal);
|
|
194
|
+
if (apkRes.success)
|
|
195
|
+
return apkRes;
|
|
196
|
+
}
|
|
197
|
+
return this.callEngineTool('open_bundle_resources', {
|
|
198
|
+
path: resolved,
|
|
199
|
+
...(outputDirectory ? { output_directory: resolveUserPath(outputDirectory) } : {})
|
|
200
|
+
}, signal);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Deobfuscate scripts or recover JavaScript bundles.
|
|
204
|
+
*/
|
|
205
|
+
async deobfuscateScript(scriptPath, signal) {
|
|
206
|
+
const resolved = resolveUserPath(scriptPath);
|
|
207
|
+
if (!fs.existsSync(resolved)) {
|
|
208
|
+
return { success: false, toolName: 'deobfuscate_script', error: `Script not found: ${resolved}`, source: 'engine' };
|
|
209
|
+
}
|
|
210
|
+
const recoverRes = await this.callEngineTool('recover_javascript_sources', { path: resolved }, signal);
|
|
211
|
+
if (recoverRes.success)
|
|
212
|
+
return recoverRes;
|
|
213
|
+
return this.callEngineTool('analyze_web_bundle', { path: resolved }, signal);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Dynamic observation or runtime tracing.
|
|
217
|
+
*/
|
|
218
|
+
async traceRuntime(target, options = {}, signal) {
|
|
219
|
+
const traceRes = await this.callEngineTool('trace_dylib_resolution', { target }, signal);
|
|
220
|
+
if (traceRes.success)
|
|
221
|
+
return traceRes;
|
|
222
|
+
return this.callEngineTool('observe_native_calls', {
|
|
223
|
+
target,
|
|
224
|
+
...(options.script ? { script: options.script } : {})
|
|
225
|
+
}, signal);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
export const sovereignReverseHarness = SovereignReverseHarness.getInstance();
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
// Sovereign Reverse Engineering Engine Harness.
|
|
2
|
+
//
|
|
3
|
+
// Bridges Causyne Agent to the headless reverse engineering engine substrate
|
|
4
|
+
// via the Model Context Protocol (MCP) stdio transport.
|
|
5
|
+
//
|
|
6
|
+
// Encapsulates on-demand process lifecycle, error containment, execution timeouts,
|
|
7
|
+
// and graceful fallback mechanisms to guarantee zero crashes on Causyne host processes.
|
|
8
|
+
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { McpClient, type McpToolCallResult } from '../mcp/mcpClient.js';
|
|
12
|
+
import { resolveUserPath } from '../utils/paths.js';
|
|
13
|
+
|
|
14
|
+
export interface EngineToolExecutionResult {
|
|
15
|
+
success: boolean;
|
|
16
|
+
toolName: string;
|
|
17
|
+
output?: string | undefined;
|
|
18
|
+
error?: string | undefined;
|
|
19
|
+
structuredContent?: unknown;
|
|
20
|
+
source: 'engine' | 'fallback';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class SovereignReverseHarness {
|
|
24
|
+
private static instance: SovereignReverseHarness | null = null;
|
|
25
|
+
private client: McpClient | null = null;
|
|
26
|
+
private connectPromise: Promise<McpClient | null> | null = null;
|
|
27
|
+
private isAvailableCache: boolean | null = null;
|
|
28
|
+
|
|
29
|
+
public static getInstance(): SovereignReverseHarness {
|
|
30
|
+
if (!SovereignReverseHarness.instance) {
|
|
31
|
+
SovereignReverseHarness.instance = new SovereignReverseHarness();
|
|
32
|
+
}
|
|
33
|
+
return SovereignReverseHarness.instance;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Check if the headless reverse engineering engine is available in the current environment.
|
|
38
|
+
*/
|
|
39
|
+
public async isAvailable(): Promise<boolean> {
|
|
40
|
+
if (this.isAvailableCache !== null) return this.isAvailableCache;
|
|
41
|
+
try {
|
|
42
|
+
const client = await this.ensureConnected();
|
|
43
|
+
this.isAvailableCache = client !== null && client.status.state === 'connected';
|
|
44
|
+
return this.isAvailableCache;
|
|
45
|
+
} catch {
|
|
46
|
+
this.isAvailableCache = false;
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Lazily establish connection to the sovereign engine via stdio MCP.
|
|
53
|
+
*/
|
|
54
|
+
public async ensureConnected(): Promise<McpClient | null> {
|
|
55
|
+
if (this.client && this.client.status.state === 'connected') {
|
|
56
|
+
return this.client;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (this.connectPromise) {
|
|
60
|
+
return this.connectPromise;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
this.connectPromise = (async () => {
|
|
64
|
+
try {
|
|
65
|
+
const mcpClient = new McpClient({
|
|
66
|
+
name: 'causyne_reverse_engineering',
|
|
67
|
+
command: 'npx',
|
|
68
|
+
args: ['--yes', 'rea-agents@6.8.0', 'mcp'],
|
|
69
|
+
timeoutMs: 60_000
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
await mcpClient.connect();
|
|
73
|
+
this.client = mcpClient;
|
|
74
|
+
this.isAvailableCache = true;
|
|
75
|
+
return this.client;
|
|
76
|
+
} catch (err: unknown) {
|
|
77
|
+
this.client = null;
|
|
78
|
+
this.isAvailableCache = false;
|
|
79
|
+
return null;
|
|
80
|
+
} finally {
|
|
81
|
+
this.connectPromise = null;
|
|
82
|
+
}
|
|
83
|
+
})();
|
|
84
|
+
|
|
85
|
+
return this.connectPromise;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Execute an upstream tool directly through the MCP engine.
|
|
90
|
+
*/
|
|
91
|
+
public async callEngineTool(
|
|
92
|
+
toolName: string,
|
|
93
|
+
args: Record<string, unknown>,
|
|
94
|
+
signal?: AbortSignal
|
|
95
|
+
): Promise<EngineToolExecutionResult> {
|
|
96
|
+
try {
|
|
97
|
+
const client = await this.ensureConnected();
|
|
98
|
+
if (!client || client.status.state !== 'connected') {
|
|
99
|
+
return {
|
|
100
|
+
success: false,
|
|
101
|
+
toolName,
|
|
102
|
+
error: 'Reverse engineering engine substrate is currently unreachable.',
|
|
103
|
+
source: 'engine'
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const res: McpToolCallResult = await client.callTool(toolName, args, signal);
|
|
108
|
+
return {
|
|
109
|
+
success: res.success,
|
|
110
|
+
toolName,
|
|
111
|
+
output: res.output,
|
|
112
|
+
error: res.error,
|
|
113
|
+
structuredContent: res.structuredContent,
|
|
114
|
+
source: 'engine'
|
|
115
|
+
};
|
|
116
|
+
} catch (err: unknown) {
|
|
117
|
+
return {
|
|
118
|
+
success: false,
|
|
119
|
+
toolName,
|
|
120
|
+
error: err instanceof Error ? err.message : String(err),
|
|
121
|
+
source: 'engine'
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* List all specialized tools advertised by the engine.
|
|
128
|
+
*/
|
|
129
|
+
public async listTools(): Promise<string[]> {
|
|
130
|
+
try {
|
|
131
|
+
const client = await this.ensureConnected();
|
|
132
|
+
if (!client) return [];
|
|
133
|
+
return client.tools.map(t => t.name);
|
|
134
|
+
} catch {
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Disconnect the client and shut down the background process cleanly.
|
|
141
|
+
*/
|
|
142
|
+
public async disconnect(): Promise<void> {
|
|
143
|
+
if (this.client) {
|
|
144
|
+
try {
|
|
145
|
+
await this.client.close();
|
|
146
|
+
} catch {
|
|
147
|
+
// Safe disposal
|
|
148
|
+
} finally {
|
|
149
|
+
this.client = null;
|
|
150
|
+
this.isAvailableCache = null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
156
|
+
// HIGH-LEVEL SOVEREIGN ACTIONS
|
|
157
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Perform deep binary inspection via engine tools.
|
|
161
|
+
*/
|
|
162
|
+
public async inspectBinary(filePath: string, signal?: AbortSignal): Promise<EngineToolExecutionResult> {
|
|
163
|
+
const resolved = resolveUserPath(filePath);
|
|
164
|
+
if (!fs.existsSync(resolved)) {
|
|
165
|
+
return { success: false, toolName: 'inspect_binary', error: `File not found: ${resolved}`, source: 'engine' };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Try primary session / overview tools
|
|
169
|
+
const overview = await this.callEngineTool('binary_overview', { path: resolved }, signal);
|
|
170
|
+
if (overview.success) return overview;
|
|
171
|
+
|
|
172
|
+
const layout = await this.callEngineTool('inspect_binary_layout', { path: resolved }, signal);
|
|
173
|
+
if (layout.success) return layout;
|
|
174
|
+
|
|
175
|
+
// Fall back to objdump if available on engine
|
|
176
|
+
return this.callEngineTool('inspect_with_objdump', { path: resolved }, signal);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Perform headless decompilation of a function or address.
|
|
181
|
+
*/
|
|
182
|
+
public async decompile(
|
|
183
|
+
filePath: string,
|
|
184
|
+
targetFunction?: string,
|
|
185
|
+
address?: string,
|
|
186
|
+
signal?: AbortSignal
|
|
187
|
+
): Promise<EngineToolExecutionResult> {
|
|
188
|
+
const resolved = resolveUserPath(filePath);
|
|
189
|
+
if (!fs.existsSync(resolved)) {
|
|
190
|
+
return { success: false, toolName: 'decompile', error: `Target not found: ${resolved}`, source: 'engine' };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (targetFunction) {
|
|
194
|
+
const funcRes = await this.callEngineTool('analyze_function', { path: resolved, function_name: targetFunction }, signal);
|
|
195
|
+
if (funcRes.success) return funcRes;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (address) {
|
|
199
|
+
const addrRes = await this.callEngineTool('procedure_pseudo_code', { path: resolved, address }, signal);
|
|
200
|
+
if (addrRes.success) return addrRes;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// General decompilation
|
|
204
|
+
const decompileRes = await this.callEngineTool('decompile_all', { path: resolved }, signal);
|
|
205
|
+
if (decompileRes.success) return decompileRes;
|
|
206
|
+
|
|
207
|
+
// Rizin / Cutter command fallback
|
|
208
|
+
return this.callEngineTool('execute_rizin_command', { path: resolved, command: 'pdd' }, signal);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Unpack an application bundle (ASAR, APK, container).
|
|
213
|
+
*/
|
|
214
|
+
public async unpackBundle(
|
|
215
|
+
bundlePath: string,
|
|
216
|
+
outputDirectory?: string,
|
|
217
|
+
signal?: AbortSignal
|
|
218
|
+
): Promise<EngineToolExecutionResult> {
|
|
219
|
+
const resolved = resolveUserPath(bundlePath);
|
|
220
|
+
if (!fs.existsSync(resolved)) {
|
|
221
|
+
return { success: false, toolName: 'unpack_bundle', error: `Bundle not found: ${resolved}`, source: 'engine' };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const ext = path.extname(resolved).toLowerCase();
|
|
225
|
+
if (ext === '.apk' || ext === '.aab') {
|
|
226
|
+
const apkRes = await this.callEngineTool('decode_android_resources', { path: resolved }, signal);
|
|
227
|
+
if (apkRes.success) return apkRes;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return this.callEngineTool('open_bundle_resources', {
|
|
231
|
+
path: resolved,
|
|
232
|
+
...(outputDirectory ? { output_directory: resolveUserPath(outputDirectory) } : {})
|
|
233
|
+
}, signal);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Deobfuscate scripts or recover JavaScript bundles.
|
|
238
|
+
*/
|
|
239
|
+
public async deobfuscateScript(
|
|
240
|
+
scriptPath: string,
|
|
241
|
+
signal?: AbortSignal
|
|
242
|
+
): Promise<EngineToolExecutionResult> {
|
|
243
|
+
const resolved = resolveUserPath(scriptPath);
|
|
244
|
+
if (!fs.existsSync(resolved)) {
|
|
245
|
+
return { success: false, toolName: 'deobfuscate_script', error: `Script not found: ${resolved}`, source: 'engine' };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const recoverRes = await this.callEngineTool('recover_javascript_sources', { path: resolved }, signal);
|
|
249
|
+
if (recoverRes.success) return recoverRes;
|
|
250
|
+
|
|
251
|
+
return this.callEngineTool('analyze_web_bundle', { path: resolved }, signal);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Dynamic observation or runtime tracing.
|
|
256
|
+
*/
|
|
257
|
+
public async traceRuntime(
|
|
258
|
+
target: string,
|
|
259
|
+
options: { script?: string; timeoutMs?: number } = {},
|
|
260
|
+
signal?: AbortSignal
|
|
261
|
+
): Promise<EngineToolExecutionResult> {
|
|
262
|
+
const traceRes = await this.callEngineTool('trace_dylib_resolution', { target }, signal);
|
|
263
|
+
if (traceRes.success) return traceRes;
|
|
264
|
+
|
|
265
|
+
return this.callEngineTool('observe_native_calls', {
|
|
266
|
+
target,
|
|
267
|
+
...(options.script ? { script: options.script } : {})
|
|
268
|
+
}, signal);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export const sovereignReverseHarness = SovereignReverseHarness.getInstance();
|
|
@@ -92,10 +92,10 @@ export class UnifiedBudgetEnforcer {
|
|
|
92
92
|
}
|
|
93
93
|
recordUsage(usage) {
|
|
94
94
|
const fresh = noncachedTokens(usage);
|
|
95
|
+
this.tokens += fresh;
|
|
95
96
|
if (fresh >= this.maxTurnTokens) {
|
|
96
97
|
throw new EfficiencyCheckpoint('tokens', fresh, this.maxTurnTokens, 'turn');
|
|
97
98
|
}
|
|
98
|
-
this.tokens += fresh;
|
|
99
99
|
if (this.tokens >= this.maxTaskTokens) {
|
|
100
100
|
throw new EfficiencyCheckpoint('tokens', this.tokens, this.maxTaskTokens, 'task');
|
|
101
101
|
}
|
|
@@ -95,10 +95,10 @@ export class UnifiedBudgetEnforcer {
|
|
|
95
95
|
|
|
96
96
|
recordUsage(usage: BudgetUsage): void {
|
|
97
97
|
const fresh = noncachedTokens(usage);
|
|
98
|
+
this.tokens += fresh;
|
|
98
99
|
if (fresh >= this.maxTurnTokens) {
|
|
99
100
|
throw new EfficiencyCheckpoint('tokens', fresh, this.maxTurnTokens, 'turn');
|
|
100
101
|
}
|
|
101
|
-
this.tokens += fresh;
|
|
102
102
|
if (this.tokens >= this.maxTaskTokens) {
|
|
103
103
|
throw new EfficiencyCheckpoint('tokens', this.tokens, this.maxTaskTokens, 'task');
|
|
104
104
|
}
|
package/src/toolPacks.js
CHANGED
|
@@ -112,6 +112,9 @@ export const PACKS = {
|
|
|
112
112
|
'code_search_ast',
|
|
113
113
|
'code_list_symbols',
|
|
114
114
|
'pdf_read'
|
|
115
|
+
],
|
|
116
|
+
reverse_engineering: [
|
|
117
|
+
'reverse_engineering'
|
|
115
118
|
]
|
|
116
119
|
};
|
|
117
120
|
export const PACK_NAMES = Object.keys(PACKS);
|
|
@@ -328,12 +331,14 @@ const WEB_INTENT = /\b(web|webpage|website|frontend|front-end|landing page|homep
|
|
|
328
331
|
const MEDIA_INTENT = /\b(image|images|picture|photo|render|3d model|blender|animation|animate|video|movie|film|audio|sound|sfx|music|song|voice|tts|text.to.speech|narration|podcast|thumbnail|poster|illustration|logo)\b/i;
|
|
329
332
|
const SYSTEM_INTENT = /\b(process|processes|pid|kill|port|zip|unzip|tar|archive|compress|extract|clipboard|copy to clipboard|print|printer|open in browser|launch app|computer use|vision grounding|desktop vision|gui agent|coordinate click|desktop control)\b/i;
|
|
330
333
|
const ADVANCED_INTENT = /\b(pdf|document|proposal|screenplay|shotlist|shot list|voiceover|dubbing|forge a tool|custom tool|new tool|plugin|plugins|custom plugin|subagent|sub-agent|parallel agent|swarm|ast|symbols|refactor across)\b/i;
|
|
334
|
+
const REVERSE_ENGINEERING_INTENT = /\b(decompile|disassemble|binary|binaries|apk|dex|elf|mach-o|pe|coff|reverse engineer|reverse-engineering|reverse_engineering|sourcemap|deobfuscate|asar|symbols|ghidra|rizin|radare|hopper|frida|hook script|mitigations|pie|canary)\b/i;
|
|
331
335
|
const INTENT_MATCHERS = {
|
|
332
336
|
game: GAME_INTENT,
|
|
333
337
|
web: WEB_INTENT,
|
|
334
338
|
media: MEDIA_INTENT,
|
|
335
339
|
system: SYSTEM_INTENT,
|
|
336
|
-
advanced: ADVANCED_INTENT
|
|
340
|
+
advanced: ADVANCED_INTENT,
|
|
341
|
+
reverse_engineering: REVERSE_ENGINEERING_INTENT
|
|
337
342
|
};
|
|
338
343
|
/** True when the prompt genuinely describes game development work. */
|
|
339
344
|
export function isGameIntent(prompt) {
|
package/src/toolPacks.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
// already normalised to underscores (see tools/registry.js TOOL_DEFINITIONS).
|
|
18
18
|
// ---------------------------------------------------------------------------
|
|
19
19
|
|
|
20
|
-
export type PackName = 'game' | 'web' | 'media' | 'system' | 'advanced';
|
|
20
|
+
export type PackName = 'game' | 'web' | 'media' | 'system' | 'advanced' | 'reverse_engineering';
|
|
21
21
|
|
|
22
22
|
export interface WorkspaceRoutingContext {
|
|
23
23
|
framework?: string | null | undefined;
|
|
@@ -138,6 +138,9 @@ export const PACKS: Record<PackName, string[]> = {
|
|
|
138
138
|
'code_search_ast',
|
|
139
139
|
'code_list_symbols',
|
|
140
140
|
'pdf_read'
|
|
141
|
+
],
|
|
142
|
+
reverse_engineering: [
|
|
143
|
+
'reverse_engineering'
|
|
141
144
|
]
|
|
142
145
|
};
|
|
143
146
|
|
|
@@ -373,12 +376,15 @@ const SYSTEM_INTENT = /\b(process|processes|pid|kill|port|zip|unzip|tar|archive|
|
|
|
373
376
|
|
|
374
377
|
const ADVANCED_INTENT = /\b(pdf|document|proposal|screenplay|shotlist|shot list|voiceover|dubbing|forge a tool|custom tool|new tool|plugin|plugins|custom plugin|subagent|sub-agent|parallel agent|swarm|ast|symbols|refactor across)\b/i;
|
|
375
378
|
|
|
379
|
+
const REVERSE_ENGINEERING_INTENT = /\b(decompile|disassemble|binary|binaries|apk|dex|elf|mach-o|pe|coff|reverse engineer|reverse-engineering|reverse_engineering|sourcemap|deobfuscate|asar|symbols|ghidra|rizin|radare|hopper|frida|hook script|mitigations|pie|canary)\b/i;
|
|
380
|
+
|
|
376
381
|
const INTENT_MATCHERS: Record<PackName, RegExp> = {
|
|
377
382
|
game: GAME_INTENT,
|
|
378
383
|
web: WEB_INTENT,
|
|
379
384
|
media: MEDIA_INTENT,
|
|
380
385
|
system: SYSTEM_INTENT,
|
|
381
|
-
advanced: ADVANCED_INTENT
|
|
386
|
+
advanced: ADVANCED_INTENT,
|
|
387
|
+
reverse_engineering: REVERSE_ENGINEERING_INTENT
|
|
382
388
|
};
|
|
383
389
|
|
|
384
390
|
/** True when the prompt genuinely describes game development work. */
|
package/src/tools/registry.js
CHANGED
|
@@ -5,6 +5,7 @@ import { documentForgeTool } from './documentForge.js';
|
|
|
5
5
|
import { nativeEngineTool } from './nativeEngine.js';
|
|
6
6
|
import { peerAgentTool } from './peerAgent.js';
|
|
7
7
|
import { openSourceToolProvisioner } from './openSourceToolProvisioner.js';
|
|
8
|
+
import { reverseEngineering } from './reverseEngineering.js';
|
|
8
9
|
import { sysRun, sysRunBg } from './sysRun.js';
|
|
9
10
|
import { fsRead } from './fsRead.js';
|
|
10
11
|
import { fsWrite } from './fsWrite.js';
|
|
@@ -129,7 +130,7 @@ const TOOL_MODULES = [
|
|
|
129
130
|
gameTilemapGenerator, gameUiHudBuilder, gameEconomyBalancer,
|
|
130
131
|
gameDataForge, gameWebRuntimeInspector, gameCanvasAudit, readNativeSkill, createSkill, creativeApps,
|
|
131
132
|
computerUse, uiForge, documentForgeTool, nativeEngineTool, peerAgentTool,
|
|
132
|
-
openSourceToolProvisioner
|
|
133
|
+
openSourceToolProvisioner, reverseEngineering
|
|
133
134
|
];
|
|
134
135
|
|
|
135
136
|
// Base static definitions (backwards compatible). Order is preserved from the
|
|
@@ -161,6 +162,13 @@ const TOOL_ALIASES = {
|
|
|
161
162
|
gitExec: 'gitOp',
|
|
162
163
|
tool_deferred_mcp_search: 'tool_search',
|
|
163
164
|
|
|
165
|
+
// Sovereign Reverse Engineering aliases
|
|
166
|
+
re_inspect_binary: 'reverse_engineering',
|
|
167
|
+
re_decompile: 'reverse_engineering',
|
|
168
|
+
re_unpack_bundle: 'reverse_engineering',
|
|
169
|
+
re_deobfuscate_script: 'reverse_engineering',
|
|
170
|
+
re_trace_runtime: 'reverse_engineering',
|
|
171
|
+
|
|
164
172
|
// Core filesystem aliases
|
|
165
173
|
read_file: 'fs_read',
|
|
166
174
|
readFile: 'fs_read',
|