@causyne/agent 1.20.16 → 1.20.18

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.
@@ -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.16",
3
+ "version": "1.20.18",
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
@@ -2131,7 +2131,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
2131
2131
  pruneStaleToolObservations(this.messages, { keepRecent: 3, minChars: 300, taskId: this.taskId });
2132
2132
  shortenOversizedToolObservations(this.messages, { threshold: 1500, taskId: this.taskId });
2133
2133
  pruneExecutedToolArguments(this.messages, { threshold: 1500, taskId: this.taskId });
2134
- this.efficiencyBudget?.extendBudget?.(1_000_000, 50);
2134
+ this.efficiencyBudget?.extendBudget?.(1_000_000, 100);
2135
2135
  }
2136
2136
  }
2137
2137
  // 2. PLAN (Call LLM). dynamicTools was resolved above so the task brief
@@ -3991,10 +3991,10 @@ You are operating in a text-and-code modality without direct image pixel renderi
3991
3991
  auditLog.log({
3992
3992
  event: 'efficiency_checkpoint',
3993
3993
  taskId: this.taskId,
3994
- reason: e.reason,
3994
+ reason: e?.reason || e?.code || 'budget',
3995
3995
  ...this.efficiencyBudget.snapshot()
3996
3996
  });
3997
- this.efficiencyBudget.extendBudget?.(1_000_000, 50);
3997
+ this.efficiencyBudget.extendBudget?.(1_000_000, 100);
3998
3998
  compactSessionMessages(this.messages, {
3999
3999
  keepRecentTurns: 4,
4000
4000
  taskId: this.taskId,
package/src/agentLoop.ts CHANGED
@@ -2260,7 +2260,7 @@ You are operating in a text-and-code modality without direct image pixel renderi
2260
2260
  pruneStaleToolObservations(this.messages, { keepRecent: 3, minChars: 300, taskId: this.taskId });
2261
2261
  shortenOversizedToolObservations(this.messages, { threshold: 1500, taskId: this.taskId });
2262
2262
  pruneExecutedToolArguments(this.messages, { threshold: 1500, taskId: this.taskId });
2263
- this.efficiencyBudget?.extendBudget?.(1_000_000, 50);
2263
+ this.efficiencyBudget?.extendBudget?.(1_000_000, 100);
2264
2264
  }
2265
2265
  }
2266
2266
 
@@ -4241,10 +4241,10 @@ You are operating in a text-and-code modality without direct image pixel renderi
4241
4241
  auditLog.log({
4242
4242
  event: 'efficiency_checkpoint',
4243
4243
  taskId: this.taskId,
4244
- reason: e.reason,
4244
+ reason: (e as any)?.reason || (e as any)?.code || 'budget',
4245
4245
  ...this.efficiencyBudget.snapshot()
4246
4246
  });
4247
- this.efficiencyBudget.extendBudget?.(1_000_000, 50);
4247
+ this.efficiencyBudget.extendBudget?.(1_000_000, 100);
4248
4248
  compactSessionMessages(this.messages, {
4249
4249
  keepRecentTurns: 4,
4250
4250
  taskId: this.taskId,
@@ -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();