@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.
@@ -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 content = fs.readFileSync(targetPath, 'utf8');
179
- const lines = content.split('\n');
180
- let body: string;
181
- if (lines.length > MAX_MENTION_FILE_LINES) {
182
- body = lines.slice(0, MAX_MENTION_FILE_LINES).join('\n') +
183
- `\n\n... [Truncated: showing first ${MAX_MENTION_FILE_LINES} of ${lines.length} lines. Use fs.read for remaining lines.]`;
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
- body = content;
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
- sections.push(
189
- `📄 REFERENCED FILE: ${relPath} (${lines.length} lines):\n` +
190
- '```\n' +
191
- body + '\n' +
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);
@@ -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
- this.toolRoutingError = { tool: requested, message: 'Host tool requested through the peer-native channel' };
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);
@@ -487,7 +487,15 @@ export class AcpProvider extends LLMProvider {
487
487
  if (isInvalidPseudoTool) {
488
488
  const requested = typeof input.tool === 'string' ? input.tool : '';
489
489
  if (!this.toolRoutingError && requested && normalizeToolContracts(this.peerServices?.tools || []).some(tool => tool.name === requested)) {
490
- this.toolRoutingError = { tool: requested, message: 'Host tool requested through the peer-native channel' };
490
+ const rawArgs = (input.args && typeof input.args === 'object') ? input.args
491
+ : (input.parameters && typeof input.parameters === 'object') ? input.parameters
492
+ : (earlier?.parameters && typeof earlier.parameters === 'object') ? earlier.parameters
493
+ : undefined;
494
+ this.toolRoutingError = {
495
+ tool: requested,
496
+ message: typeof input.error === 'string' ? input.error : 'Host tool requested through the peer-native channel',
497
+ parameters: rawArgs
498
+ };
491
499
  client.notifyCancel(sessionId);
492
500
  }
493
501
  this.liveFileActions.delete(id);
@@ -48,7 +48,7 @@ export interface ChatResponse {
48
48
  reasoningContent?: string | undefined;
49
49
  thinkingBlocks?: any[] | undefined;
50
50
  externalActions?: ChatResponseAction[] | undefined;
51
- toolRoutingError?: { tool: string; message: string } | undefined;
51
+ toolRoutingError?: { tool: string; message: string; parameters?: Record<string, unknown> | undefined } | undefined;
52
52
  incompleteTurn?: boolean | undefined;
53
53
  }
54
54
 
@@ -90,6 +90,11 @@ export class UnifiedBudgetEnforcer {
90
90
  this.maxTurnTokens = Math.max(this.maxTurnTokens, extraTokens);
91
91
  this.maxTurnActions = Math.max(this.maxTurnActions, this.actions + extraActions);
92
92
  }
93
+ extendForAutonomousMomentum(actionCount = 50, tokenCount = 500_000) {
94
+ this.maxTurnActions = Math.max(this.maxTurnActions, this.actions + actionCount);
95
+ this.maxTurnTokens = Math.max(this.maxTurnTokens, tokenCount);
96
+ this.maxTaskTokens = Math.max(this.maxTaskTokens, this.tokens + tokenCount);
97
+ }
93
98
  recordUsage(usage) {
94
99
  const fresh = noncachedTokens(usage);
95
100
  this.tokens += fresh;
@@ -93,6 +93,12 @@ export class UnifiedBudgetEnforcer {
93
93
  this.maxTurnActions = Math.max(this.maxTurnActions, this.actions + extraActions);
94
94
  }
95
95
 
96
+ extendForAutonomousMomentum(actionCount = 50, tokenCount = 500_000): void {
97
+ this.maxTurnActions = Math.max(this.maxTurnActions, this.actions + actionCount);
98
+ this.maxTurnTokens = Math.max(this.maxTurnTokens, tokenCount);
99
+ this.maxTaskTokens = Math.max(this.maxTaskTokens, this.tokens + tokenCount);
100
+ }
101
+
96
102
  recordUsage(usage: BudgetUsage): void {
97
103
  const fresh = noncachedTokens(usage);
98
104
  this.tokens += fresh;
@@ -338,6 +338,14 @@ export class TokenTracker {
338
338
  }
339
339
  return { allowed: true, used: this.taskTokens, limit, projected };
340
340
  }
341
+ extendBudget(extraTokens) {
342
+ if (this.budget && typeof this.budget === 'object') {
343
+ const current = Number(this.budget.maxTokensPerTask || 0);
344
+ if (current > 0) {
345
+ this.budget.maxTokensPerTask = Math.max(current + extraTokens, this.taskTokens + extraTokens);
346
+ }
347
+ }
348
+ }
341
349
  resetTask() {
342
350
  this.taskTokens = 0;
343
351
  this.taskCostUsd = 0;
@@ -447,6 +447,15 @@ export class TokenTracker {
447
447
  return { allowed: true, used: this.taskTokens, limit, projected };
448
448
  }
449
449
 
450
+ extendBudget(extraTokens: number): void {
451
+ if (this.budget && typeof this.budget === 'object') {
452
+ const current = Number(this.budget.maxTokensPerTask || 0);
453
+ if (current > 0) {
454
+ this.budget.maxTokensPerTask = Math.max(current + extraTokens, this.taskTokens + extraTokens);
455
+ }
456
+ }
457
+ }
458
+
450
459
  resetTask(): void {
451
460
  this.taskTokens = 0;
452
461
  this.taskCostUsd = 0;
package/src/toolPacks.js CHANGED
@@ -331,7 +331,7 @@ const WEB_INTENT = /\b(web|webpage|website|frontend|front-end|landing page|homep
331
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;
332
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;
333
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;
334
+ const REVERSE_ENGINEERING_INTENT = /\b(rea|rea-agents|decompile|decompiling|decompilation|disassemble|disassembly|disassembling|binary|binaries|apk|aab|dex|elf|mach-o|pe|coff|reverse[\s_-]?engineer(ing)?|sourcemap|deobfuscate|asar|symbols|ghidra|rizin|radare|hopper|frida|hook script|mitigations|pie|canary|clean[- ]?room)\b|\.(apk|aab|dex|dylib|so|dll|exe|asar)\b/i;
335
335
  const INTENT_MATCHERS = {
336
336
  game: GAME_INTENT,
337
337
  web: WEB_INTENT,
package/src/toolPacks.ts CHANGED
@@ -376,7 +376,7 @@ const SYSTEM_INTENT = /\b(process|processes|pid|kill|port|zip|unzip|tar|archive|
376
376
 
377
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;
378
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;
379
+ const REVERSE_ENGINEERING_INTENT = /\b(rea|rea-agents|decompile|decompiling|decompilation|disassemble|disassembly|disassembling|binary|binaries|apk|aab|dex|elf|mach-o|pe|coff|reverse[\s_-]?engineer(ing)?|sourcemap|deobfuscate|asar|symbols|ghidra|rizin|radare|hopper|frida|hook script|mitigations|pie|canary|clean[- ]?room)\b|\.(apk|aab|dex|dylib|so|dll|exe|asar)\b/i;
380
380
 
381
381
  const INTENT_MATCHERS: Record<PackName, RegExp> = {
382
382
  game: GAME_INTENT,
@@ -239,7 +239,7 @@ export const reverseEngineering = {
239
239
  properties: {
240
240
  action: {
241
241
  type: 'string',
242
- enum: ['inspect', 'decompile', 'unpack', 'deobfuscate', 'trace', 'status', 'engine_tool', 'list_tools'],
242
+ enum: ['inspect', 'decompile', 'unpack', 'deobfuscate', 'trace', 'status', 'engine_tool', 'list_tools', 'decode_resources', 'search_classes', 'graph'],
243
243
  description: 'Reverse engineering action to perform.'
244
244
  },
245
245
  filePath: {
@@ -287,14 +287,40 @@ export const reverseEngineering = {
287
287
  toolArgs: {
288
288
  type: 'object',
289
289
  description: 'Arguments payload for engine_tool.'
290
+ },
291
+ query: {
292
+ type: 'string',
293
+ description: 'Class, method, or string search query for reverse engineering.'
290
294
  }
291
295
  },
292
296
  required: ['action']
293
297
  }
294
298
  },
295
299
  async execute(args, context = {}) {
296
- const action = String(args['action'] || 'status');
297
- const rawPath = typeof args['filePath'] === 'string' ? args['filePath'] : undefined;
300
+ const rawPath = typeof args['filePath'] === 'string' ? args['filePath']
301
+ : typeof args['file'] === 'string' ? args['file']
302
+ : typeof args['path'] === 'string' ? args['path']
303
+ : typeof args['apk'] === 'string' ? args['apk']
304
+ : typeof args['binary'] === 'string' ? args['binary']
305
+ : (typeof args['target'] === 'string' && args['action'] !== 'trace' ? args['target'] : undefined);
306
+ let rawAction = typeof args['action'] === 'string' ? args['action']
307
+ : typeof args['operation'] === 'string' ? args['operation']
308
+ : typeof args['mode'] === 'string' ? args['mode']
309
+ : '';
310
+ if (!rawAction && (typeof args['toolName'] === 'string' || typeof args['engineTool'] === 'string')) {
311
+ rawAction = 'engine_tool';
312
+ }
313
+ if (['analyze', 'info', 'check', 'probe', 'inspect_package'].includes(rawAction))
314
+ rawAction = 'inspect';
315
+ if (['disassemble', 'disasm'].includes(rawAction))
316
+ rawAction = 'decompile';
317
+ if (['decode_resources', 'resources', 'decode'].includes(rawAction))
318
+ rawAction = 'decode_resources';
319
+ if (['search_classes', 'classes'].includes(rawAction))
320
+ rawAction = 'search_classes';
321
+ if (['graph', 'application_graph'].includes(rawAction))
322
+ rawAction = 'graph';
323
+ const action = (rawAction || (rawPath ? 'inspect' : 'status'));
298
324
  const outputDir = typeof args['outputDir'] === 'string' ? args['outputDir'] : undefined;
299
325
  const functionName = typeof args['functionName'] === 'string' ? args['functionName'] : undefined;
300
326
  const address = typeof args['address'] === 'string' ? args['address'] : undefined;
@@ -341,7 +367,8 @@ export const reverseEngineering = {
341
367
  'Electron ASAR pickle header inspection & extraction',
342
368
  'JavaScript sourcemap recovery and route harvesting',
343
369
  'Dynamic runtime tracing and API observation',
344
- 'Headless MCP engine with 229 specialized reverse engineering tools'
370
+ 'Headless MCP engine with 170+ specialized reverse engineering tools',
371
+ 'Android APK resource decoding, class hierarchy & graph projection'
345
372
  ]
346
373
  };
347
374
  }
@@ -357,7 +384,7 @@ export const reverseEngineering = {
357
384
  }
358
385
  // ── ACTION: ENGINE_TOOL ───────────────────────────────────────────────
359
386
  if (action === 'engine_tool') {
360
- const toolName = typeof args['toolName'] === 'string' ? args['toolName'] : '';
387
+ const toolName = typeof args['toolName'] === 'string' ? args['toolName'] : typeof args['engineTool'] === 'string' ? args['engineTool'] : '';
361
388
  if (!toolName) {
362
389
  return { success: false, error: 'toolName parameter is required for action "engine_tool".' };
363
390
  }
@@ -377,7 +404,7 @@ export const reverseEngineering = {
377
404
  error: res.error
378
405
  };
379
406
  }
380
- // Require filePath for inspect, decompile, unpack, deobfuscate
407
+ // Require filePath for inspect, decompile, unpack, deobfuscate, decode_resources, search_classes, graph
381
408
  if (!rawPath && action !== 'trace') {
382
409
  return { success: false, error: `Action "${action}" requires a valid "filePath" parameter.` };
383
410
  }
@@ -385,6 +412,53 @@ export const reverseEngineering = {
385
412
  if (resolvedFile && !fs.existsSync(resolvedFile)) {
386
413
  return { success: false, error: `File not found: ${resolvedFile}` };
387
414
  }
415
+ // ── ACTION: DECODE_RESOURCES ──────────────────────────────────────────
416
+ if (action === 'decode_resources') {
417
+ const res = await sovereignReverseHarness.decodeAndroidResources(resolvedFile, outputDir, context.signal);
418
+ const textOutput = res.output || (res.structuredContent ? JSON.stringify(res.structuredContent, null, 2) : res.error || '');
419
+ const stored = outputStore.processToolOutput(sessionId, `${callId}_decode_resources`, textOutput);
420
+ return {
421
+ success: res.success,
422
+ action: 'decode_resources',
423
+ filePath: resolvedFile,
424
+ preview: stored.contentForModel,
425
+ isTruncated: stored.isTruncated,
426
+ diskPath: stored.diskPath,
427
+ error: res.error
428
+ };
429
+ }
430
+ // ── ACTION: SEARCH_CLASSES ───────────────────────────────────────────
431
+ if (action === 'search_classes') {
432
+ const query = String(args['query'] || '');
433
+ const res = await sovereignReverseHarness.searchAndroidClasses(resolvedFile, query, context.signal);
434
+ const textOutput = res.output || (res.structuredContent ? JSON.stringify(res.structuredContent, null, 2) : res.error || '');
435
+ const stored = outputStore.processToolOutput(sessionId, `${callId}_search_classes`, textOutput);
436
+ return {
437
+ success: res.success,
438
+ action: 'search_classes',
439
+ filePath: resolvedFile,
440
+ query,
441
+ preview: stored.contentForModel,
442
+ isTruncated: stored.isTruncated,
443
+ diskPath: stored.diskPath,
444
+ error: res.error
445
+ };
446
+ }
447
+ // ── ACTION: GRAPH ─────────────────────────────────────────────────────
448
+ if (action === 'graph') {
449
+ const res = await sovereignReverseHarness.projectAndroidGraph(resolvedFile, context.signal);
450
+ const textOutput = res.output || (res.structuredContent ? JSON.stringify(res.structuredContent, null, 2) : res.error || '');
451
+ const stored = outputStore.processToolOutput(sessionId, `${callId}_graph`, textOutput);
452
+ return {
453
+ success: res.success,
454
+ action: 'graph',
455
+ filePath: resolvedFile,
456
+ preview: stored.contentForModel,
457
+ isTruncated: stored.isTruncated,
458
+ diskPath: stored.diskPath,
459
+ error: res.error
460
+ };
461
+ }
388
462
  // ── ACTION: INSPECT ───────────────────────────────────────────────────
389
463
  if (action === 'inspect') {
390
464
  try {
@@ -424,9 +498,26 @@ export const reverseEngineering = {
424
498
  result.format = 'WebAssembly';
425
499
  result.architecture = 'wasm32 / wasm64';
426
500
  }
427
- else if (headerBuf[0] === 0x50 && headerBuf[1] === 0x4b && headerBuf[2] === 0x03 && headerBuf[3] === 0x04) {
501
+ else if ((headerBuf[0] === 0x50 && headerBuf[1] === 0x4b && headerBuf[2] === 0x03 && headerBuf[3] === 0x04) ||
502
+ resolvedFile.toLowerCase().endsWith('.apk')) {
428
503
  result.format = 'APK/ZIP';
429
- result.fileType = 'Compressed Archive / Package';
504
+ result.fileType = 'Android Application Package (APK)';
505
+ try {
506
+ const unzipList = await execFileAsync('unzip', ['-l', resolvedFile], { timeout: 15000 });
507
+ const lines = unzipList.stdout.split('\n');
508
+ const dexFiles = lines.filter(l => l.includes('.dex')).map(l => l.trim().split(/\s+/).pop());
509
+ const hasManifest = lines.some(l => l.includes('AndroidManifest.xml'));
510
+ const nativeLibs = lines.filter(l => l.includes('lib/')).slice(0, 15).map(l => l.trim().split(/\s+/).pop());
511
+ result.metadata = {
512
+ dexFiles,
513
+ hasManifest,
514
+ totalEntries: lines.length,
515
+ sampleNativeLibraries: nativeLibs
516
+ };
517
+ }
518
+ catch {
519
+ // unzip fallback
520
+ }
430
521
  }
431
522
  else {
432
523
  const asar = parseAsarHeader(headerBuf);
@@ -30,7 +30,10 @@ export type ReverseEngineeringAction =
30
30
  | 'trace'
31
31
  | 'status'
32
32
  | 'engine_tool'
33
- | 'list_tools';
33
+ | 'list_tools'
34
+ | 'decode_resources'
35
+ | 'search_classes'
36
+ | 'graph';
34
37
 
35
38
  export interface BinaryMitigations {
36
39
  pie?: boolean | undefined;
@@ -69,6 +72,7 @@ export interface ReverseEngineeringParams {
69
72
  script?: string | undefined;
70
73
  toolName?: string | undefined;
71
74
  toolArgs?: Record<string, unknown> | undefined;
75
+ query?: string | undefined;
72
76
  }
73
77
 
74
78
  // ─────────────────────────────────────────────────────────────────────────────
@@ -318,7 +322,7 @@ export const reverseEngineering = {
318
322
  properties: {
319
323
  action: {
320
324
  type: 'string',
321
- enum: ['inspect', 'decompile', 'unpack', 'deobfuscate', 'trace', 'status', 'engine_tool', 'list_tools'],
325
+ enum: ['inspect', 'decompile', 'unpack', 'deobfuscate', 'trace', 'status', 'engine_tool', 'list_tools', 'decode_resources', 'search_classes', 'graph'],
322
326
  description: 'Reverse engineering action to perform.'
323
327
  },
324
328
  filePath: {
@@ -366,6 +370,10 @@ export const reverseEngineering = {
366
370
  toolArgs: {
367
371
  type: 'object',
368
372
  description: 'Arguments payload for engine_tool.'
373
+ },
374
+ query: {
375
+ type: 'string',
376
+ description: 'Class, method, or string search query for reverse engineering.'
369
377
  }
370
378
  },
371
379
  required: ['action']
@@ -373,8 +381,29 @@ export const reverseEngineering = {
373
381
  },
374
382
 
375
383
  async execute(args: Record<string, unknown>, context: { workspaceDir?: string; sessionId?: string; signal?: AbortSignal } = {}): Promise<Record<string, unknown>> {
376
- const action = String(args['action'] || 'status') as ReverseEngineeringAction;
377
- const rawPath = typeof args['filePath'] === 'string' ? args['filePath'] : undefined;
384
+ const rawPath = typeof args['filePath'] === 'string' ? args['filePath']
385
+ : typeof args['file'] === 'string' ? args['file']
386
+ : typeof args['path'] === 'string' ? args['path']
387
+ : typeof args['apk'] === 'string' ? args['apk']
388
+ : typeof args['binary'] === 'string' ? args['binary']
389
+ : (typeof args['target'] === 'string' && args['action'] !== 'trace' ? args['target'] : undefined);
390
+
391
+ let rawAction = typeof args['action'] === 'string' ? args['action']
392
+ : typeof args['operation'] === 'string' ? args['operation']
393
+ : typeof args['mode'] === 'string' ? args['mode']
394
+ : '';
395
+
396
+ if (!rawAction && (typeof args['toolName'] === 'string' || typeof args['engineTool'] === 'string')) {
397
+ rawAction = 'engine_tool';
398
+ }
399
+
400
+ if (['analyze', 'info', 'check', 'probe', 'inspect_package'].includes(rawAction)) rawAction = 'inspect';
401
+ if (['disassemble', 'disasm'].includes(rawAction)) rawAction = 'decompile';
402
+ if (['decode_resources', 'resources', 'decode'].includes(rawAction)) rawAction = 'decode_resources';
403
+ if (['search_classes', 'classes'].includes(rawAction)) rawAction = 'search_classes';
404
+ if (['graph', 'application_graph'].includes(rawAction)) rawAction = 'graph';
405
+
406
+ const action = (rawAction || (rawPath ? 'inspect' : 'status')) as ReverseEngineeringAction;
378
407
  const outputDir = typeof args['outputDir'] === 'string' ? args['outputDir'] : undefined;
379
408
  const functionName = typeof args['functionName'] === 'string' ? args['functionName'] : undefined;
380
409
  const address = typeof args['address'] === 'string' ? args['address'] : undefined;
@@ -424,7 +453,8 @@ export const reverseEngineering = {
424
453
  'Electron ASAR pickle header inspection & extraction',
425
454
  'JavaScript sourcemap recovery and route harvesting',
426
455
  'Dynamic runtime tracing and API observation',
427
- 'Headless MCP engine with 229 specialized reverse engineering tools'
456
+ 'Headless MCP engine with 170+ specialized reverse engineering tools',
457
+ 'Android APK resource decoding, class hierarchy & graph projection'
428
458
  ]
429
459
  };
430
460
  }
@@ -442,7 +472,7 @@ export const reverseEngineering = {
442
472
 
443
473
  // ── ACTION: ENGINE_TOOL ───────────────────────────────────────────────
444
474
  if (action === 'engine_tool') {
445
- const toolName = typeof args['toolName'] === 'string' ? args['toolName'] : '';
475
+ const toolName = typeof args['toolName'] === 'string' ? args['toolName'] : typeof args['engineTool'] === 'string' ? args['engineTool'] : '';
446
476
  if (!toolName) {
447
477
  return { success: false, error: 'toolName parameter is required for action "engine_tool".' };
448
478
  }
@@ -465,7 +495,7 @@ export const reverseEngineering = {
465
495
  };
466
496
  }
467
497
 
468
- // Require filePath for inspect, decompile, unpack, deobfuscate
498
+ // Require filePath for inspect, decompile, unpack, deobfuscate, decode_resources, search_classes, graph
469
499
  if (!rawPath && action !== 'trace') {
470
500
  return { success: false, error: `Action "${action}" requires a valid "filePath" parameter.` };
471
501
  }
@@ -475,6 +505,56 @@ export const reverseEngineering = {
475
505
  return { success: false, error: `File not found: ${resolvedFile}` };
476
506
  }
477
507
 
508
+ // ── ACTION: DECODE_RESOURCES ──────────────────────────────────────────
509
+ if (action === 'decode_resources') {
510
+ const res = await sovereignReverseHarness.decodeAndroidResources(resolvedFile, outputDir, context.signal);
511
+ const textOutput = res.output || (res.structuredContent ? JSON.stringify(res.structuredContent, null, 2) : res.error || '');
512
+ const stored = outputStore.processToolOutput(sessionId, `${callId}_decode_resources`, textOutput);
513
+ return {
514
+ success: res.success,
515
+ action: 'decode_resources',
516
+ filePath: resolvedFile,
517
+ preview: stored.contentForModel,
518
+ isTruncated: stored.isTruncated,
519
+ diskPath: stored.diskPath,
520
+ error: res.error
521
+ };
522
+ }
523
+
524
+ // ── ACTION: SEARCH_CLASSES ───────────────────────────────────────────
525
+ if (action === 'search_classes') {
526
+ const query = String(args['query'] || '');
527
+ const res = await sovereignReverseHarness.searchAndroidClasses(resolvedFile, query, context.signal);
528
+ const textOutput = res.output || (res.structuredContent ? JSON.stringify(res.structuredContent, null, 2) : res.error || '');
529
+ const stored = outputStore.processToolOutput(sessionId, `${callId}_search_classes`, textOutput);
530
+ return {
531
+ success: res.success,
532
+ action: 'search_classes',
533
+ filePath: resolvedFile,
534
+ query,
535
+ preview: stored.contentForModel,
536
+ isTruncated: stored.isTruncated,
537
+ diskPath: stored.diskPath,
538
+ error: res.error
539
+ };
540
+ }
541
+
542
+ // ── ACTION: GRAPH ─────────────────────────────────────────────────────
543
+ if (action === 'graph') {
544
+ const res = await sovereignReverseHarness.projectAndroidGraph(resolvedFile, context.signal);
545
+ const textOutput = res.output || (res.structuredContent ? JSON.stringify(res.structuredContent, null, 2) : res.error || '');
546
+ const stored = outputStore.processToolOutput(sessionId, `${callId}_graph`, textOutput);
547
+ return {
548
+ success: res.success,
549
+ action: 'graph',
550
+ filePath: resolvedFile,
551
+ preview: stored.contentForModel,
552
+ isTruncated: stored.isTruncated,
553
+ diskPath: stored.diskPath,
554
+ error: res.error
555
+ };
556
+ }
557
+
478
558
  // ── ACTION: INSPECT ───────────────────────────────────────────────────
479
559
  if (action === 'inspect') {
480
560
  try {
@@ -515,9 +595,27 @@ export const reverseEngineering = {
515
595
  } else if (headerBuf[0] === 0x00 && headerBuf[1] === 0x61 && headerBuf[2] === 0x73 && headerBuf[3] === 0x6d) {
516
596
  result.format = 'WebAssembly';
517
597
  result.architecture = 'wasm32 / wasm64';
518
- } else if (headerBuf[0] === 0x50 && headerBuf[1] === 0x4b && headerBuf[2] === 0x03 && headerBuf[3] === 0x04) {
598
+ } else if (
599
+ (headerBuf[0] === 0x50 && headerBuf[1] === 0x4b && headerBuf[2] === 0x03 && headerBuf[3] === 0x04) ||
600
+ resolvedFile.toLowerCase().endsWith('.apk')
601
+ ) {
519
602
  result.format = 'APK/ZIP';
520
- result.fileType = 'Compressed Archive / Package';
603
+ result.fileType = 'Android Application Package (APK)';
604
+ try {
605
+ const unzipList = await execFileAsync('unzip', ['-l', resolvedFile], { timeout: 15000 });
606
+ const lines = unzipList.stdout.split('\n');
607
+ const dexFiles = lines.filter(l => l.includes('.dex')).map(l => l.trim().split(/\s+/).pop());
608
+ const hasManifest = lines.some(l => l.includes('AndroidManifest.xml'));
609
+ const nativeLibs = lines.filter(l => l.includes('lib/')).slice(0, 15).map(l => l.trim().split(/\s+/).pop());
610
+ result.metadata = {
611
+ dexFiles,
612
+ hasManifest,
613
+ totalEntries: lines.length,
614
+ sampleNativeLibraries: nativeLibs
615
+ };
616
+ } catch {
617
+ // unzip fallback
618
+ }
521
619
  } else {
522
620
  const asar = parseAsarHeader(headerBuf);
523
621
  if (asar) {
@@ -0,0 +1,19 @@
1
+ export interface UIInterface {
2
+ colors: Record<string, string>;
3
+ box: Record<string, string>;
4
+ printHeader(title: string, subtitle?: string): void;
5
+ printCard(title: string, bodyLines: string | string[], highlight?: boolean): void;
6
+ printSuccess(msg: string): void;
7
+ printInfo(msg: string): void;
8
+ printWarning(msg: string): void;
9
+ printError(msg: string): void;
10
+ printFatalBox(title: string, lines: string[]): void;
11
+ createSpinner(text: string): {
12
+ start(): unknown;
13
+ stop(text?: string): void;
14
+ fail(text?: string): void;
15
+ };
16
+ }
17
+
18
+ export declare const UI: UIInterface;
19
+ export default UI;