claude-flow 3.59.16 → 3.60.0

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.
Files changed (53) hide show
  1. package/.claude/proven-config.json +1 -1
  2. package/.claude-plugin/marketplace.json +3 -3
  3. package/README.md +2 -1
  4. package/node_modules/@claude-flow/codex/dist/cli.js +0 -0
  5. package/node_modules/@claude-flow/mcp/dist/session-manager.d.ts.map +1 -1
  6. package/node_modules/@claude-flow/mcp/dist/session-manager.js +4 -1
  7. package/node_modules/@claude-flow/mcp/dist/session-manager.js.map +1 -1
  8. package/node_modules/@claude-flow/mcp/package.json +1 -1
  9. package/node_modules/@claude-flow/plugin-agent-federation/dist/bin.js +0 -0
  10. package/package.json +3 -2
  11. package/v3/@claude-flow/cli/README.md +2 -1
  12. package/v3/@claude-flow/cli/catalog-manifest.json +4 -4
  13. package/v3/@claude-flow/cli/dist/src/commands/agntcy/publish.js +1 -1
  14. package/v3/@claude-flow/cli/dist/src/commands/agntcy/runtime.d.ts +4 -1
  15. package/v3/@claude-flow/cli/dist/src/commands/agntcy/runtime.js +15 -2
  16. package/v3/@claude-flow/cli/dist/src/commands/agntcy/swarm-join.js +1 -1
  17. package/v3/@claude-flow/cli/dist/src/commands/agntcy/transport.js +1 -1
  18. package/v3/@claude-flow/cli/dist/src/commands/update.js +5 -3
  19. package/v3/@claude-flow/cli/dist/src/init/executor.js +2 -1
  20. package/v3/@claude-flow/cli/dist/src/mcp-client.js +4 -0
  21. package/v3/@claude-flow/cli/dist/src/mcp-tools/agentbbs-tools.js +7 -0
  22. package/v3/@claude-flow/cli/dist/src/mcp-tools/capability-brain.js +17 -0
  23. package/v3/@claude-flow/cli/dist/src/mcp-tools/daa-tools.js +20 -12
  24. package/v3/@claude-flow/cli/dist/src/mcp-tools/github-tools.js +78 -75
  25. package/v3/@claude-flow/cli/dist/src/mcp-tools/neural-tools.js +11 -17
  26. package/v3/@claude-flow/cli/dist/src/mcp-tools/rure-tools.d.ts +11 -0
  27. package/v3/@claude-flow/cli/dist/src/mcp-tools/rure-tools.js +359 -0
  28. package/v3/@claude-flow/cli/dist/src/memory/memory-bridge.d.ts +17 -0
  29. package/v3/@claude-flow/cli/dist/src/memory/memory-bridge.js +18 -9
  30. package/v3/@claude-flow/cli/dist/src/mods/claude-installs.d.ts +12 -0
  31. package/v3/@claude-flow/cli/dist/src/mods/claude-installs.js +21 -1
  32. package/v3/@claude-flow/cli/dist/src/rure/aidefence-gate.d.ts +25 -0
  33. package/v3/@claude-flow/cli/dist/src/rure/aidefence-gate.js +63 -0
  34. package/v3/@claude-flow/cli/dist/src/rure/analyze-js-app.d.ts +17 -0
  35. package/v3/@claude-flow/cli/dist/src/rure/analyze-js-app.js +26 -0
  36. package/v3/@claude-flow/cli/dist/src/rure/binary-parse.d.ts +38 -0
  37. package/v3/@claude-flow/cli/dist/src/rure/binary-parse.js +347 -0
  38. package/v3/@claude-flow/cli/dist/src/rure/dotnet-parse.d.ts +30 -0
  39. package/v3/@claude-flow/cli/dist/src/rure/dotnet-parse.js +299 -0
  40. package/v3/@claude-flow/cli/dist/src/rure/evm-parse.d.ts +52 -0
  41. package/v3/@claude-flow/cli/dist/src/rure/evm-parse.js +233 -0
  42. package/v3/@claude-flow/cli/dist/src/rure/extract-asar.d.ts +33 -0
  43. package/v3/@claude-flow/cli/dist/src/rure/extract-asar.js +70 -0
  44. package/v3/@claude-flow/cli/dist/src/rure/find-feature.d.ts +26 -0
  45. package/v3/@claude-flow/cli/dist/src/rure/find-feature.js +69 -0
  46. package/v3/@claude-flow/cli/dist/src/rure/ts-walk.d.ts +47 -0
  47. package/v3/@claude-flow/cli/dist/src/rure/ts-walk.js +158 -0
  48. package/v3/@claude-flow/cli/dist/src/rure/walk-files.d.ts +21 -0
  49. package/v3/@claude-flow/cli/dist/src/rure/walk-files.js +71 -0
  50. package/v3/@claude-flow/cli/dist/src/services/worker-daemon.js +17 -3
  51. package/v3/@claude-flow/cli/dist/src/update/checker.d.ts +1 -0
  52. package/v3/@claude-flow/cli/dist/src/update/checker.js +4 -2
  53. package/v3/@claude-flow/cli/package.json +4 -3
@@ -70,17 +70,25 @@ function run(cmd, cwd) {
70
70
  * strings stay literal.
71
71
  */
72
72
  function runArgv(file, args, cwd) {
73
+ const r = runArgvResult(file, args, cwd);
74
+ return 'out' in r ? r.out : null;
75
+ }
76
+ /** runArgv that keeps the failure text (stderr, else the error message) for reporting. */
77
+ function runArgvResult(file, args, cwd) {
73
78
  try {
74
- return execFileSync(file, args, {
75
- encoding: 'utf-8',
76
- timeout: 15000,
77
- cwd: cwd || getProjectCwd(),
78
- stdio: ['pipe', 'pipe', 'pipe'],
79
- shell: false,
80
- }).trim();
79
+ return {
80
+ out: execFileSync(file, args, {
81
+ encoding: 'utf-8',
82
+ timeout: 15000,
83
+ cwd: cwd || getProjectCwd(),
84
+ stdio: ['pipe', 'pipe', 'pipe'],
85
+ shell: false,
86
+ }).trim(),
87
+ };
81
88
  }
82
- catch {
83
- return null;
89
+ catch (err) {
90
+ const e = err;
91
+ return { error: String(e.stderr ?? '').trim() || e.message || 'unknown error' };
84
92
  }
85
93
  }
86
94
  /**
@@ -255,9 +263,12 @@ export const githubTools = [
255
263
  const store = loadGitHubStore();
256
264
  const action = input.action || 'list';
257
265
  const gh = hasGhCli();
266
+ // #4424: like #2963 for issues — owner/repo were validated but never
267
+ // passed to `gh`, so PR actions (including merge/close) hit the cwd's repo.
268
+ const repoArgs = input.owner && input.repo ? ['--repo', `${input.owner}/${input.repo}`] : [];
258
269
  if (action === 'list') {
259
270
  if (gh) {
260
- const raw = run('gh pr list --state all --limit 20 --json number,title,state,headRefName,createdAt');
271
+ const raw = runArgv('gh', ['pr', 'list', '--state', 'all', '--limit', '20', '--json', 'number,title,state,headRefName,createdAt', ...repoArgs]);
261
272
  if (raw) {
262
273
  try {
263
274
  const prs = JSON.parse(raw);
@@ -285,6 +296,7 @@ export const githubTools = [
285
296
  '--base', baseBranch,
286
297
  '--head', headBranch,
287
298
  '--body', body,
299
+ ...repoArgs,
288
300
  ]);
289
301
  if (result) {
290
302
  return { success: true, _real: true, action: 'created', url: result };
@@ -306,6 +318,7 @@ export const githubTools = [
306
318
  const raw = runArgv('gh', [
307
319
  'pr', 'view', String(prNumber),
308
320
  '--json', 'number,title,state,body,additions,deletions,changedFiles,reviews,mergeable,statusCheckRollup',
321
+ ...repoArgs,
309
322
  ]);
310
323
  if (raw) {
311
324
  try {
@@ -316,36 +329,28 @@ export const githubTools = [
316
329
  }
317
330
  return { success: false, error: prNumber ? 'gh CLI not available or PR not found. Install gh: https://cli.github.com' : 'prNumber is required (positive integer) for review.' };
318
331
  }
319
- if (action === 'merge') {
320
- const prNumber = toPositiveInt(input.prNumber);
321
- if (gh && prNumber) {
322
- const result = runArgv('gh', ['pr', 'merge', String(prNumber), '--merge']);
323
- if (result !== null) {
324
- return { success: true, _real: true, action: 'merged', prNumber, mergedAt: new Date().toISOString() };
325
- }
326
- }
327
- // Fallback: local store
328
- const prKey = prNumber ? Object.keys(store.prs).find(k => k.includes(String(prNumber))) : undefined;
329
- if (prKey && store.prs[prKey]) {
330
- store.prs[prKey].status = 'merged';
331
- saveGitHubStore(store);
332
- }
333
- return { success: true, source: 'local-store', action: 'merged', prNumber, mergedAt: new Date().toISOString() };
334
- }
335
- if (action === 'close') {
332
+ if (action === 'merge' || action === 'close') {
333
+ // #4424: a failed `gh` call, or a local fallback that matched nothing,
334
+ // used to be reported as success. Fail instead; offline, only update a
335
+ // local record whose id is exactly `pr-<prNumber>`.
336
336
  const prNumber = toPositiveInt(input.prNumber);
337
- if (gh && prNumber) {
338
- const result = runArgv('gh', ['pr', 'close', String(prNumber)]);
339
- if (result !== null) {
340
- return { success: true, _real: true, action: 'closed', prNumber, closedAt: new Date().toISOString() };
337
+ if (!prNumber)
338
+ return { success: false, error: `prNumber is required (positive integer) for ${action}.` };
339
+ const status = action === 'merge' ? 'merged' : 'closed';
340
+ if (gh) {
341
+ const argv = action === 'merge' ? ['pr', 'merge', String(prNumber), '--merge'] : ['pr', 'close', String(prNumber)];
342
+ const r = runArgvResult('gh', [...argv, ...repoArgs]);
343
+ if ('error' in r) {
344
+ return { success: false, source: 'gh-cli', error: `gh pr ${action} ${prNumber} failed: ${r.error}` };
341
345
  }
346
+ return { success: true, _real: true, action: status, prNumber, [`${status}At`]: new Date().toISOString() };
342
347
  }
343
- const prKey = prNumber ? Object.keys(store.prs).find(k => k.includes(String(prNumber))) : undefined;
344
- if (prKey && store.prs[prKey]) {
345
- store.prs[prKey].status = 'closed';
346
- saveGitHubStore(store);
347
- }
348
- return { success: true, source: 'local-store', action: 'closed', prNumber, closedAt: new Date().toISOString() };
348
+ const pr = store.prs[`pr-${prNumber}`];
349
+ if (!pr)
350
+ return { success: false, source: 'local-store', error: `gh CLI not available and no local PR pr-${prNumber}` };
351
+ pr.status = status;
352
+ saveGitHubStore(store);
353
+ return { success: true, source: 'local-store', action: status, prNumber, [`${status}At`]: new Date().toISOString() };
349
354
  }
350
355
  return { success: false, error: 'Unknown action' };
351
356
  },
@@ -435,51 +440,49 @@ export const githubTools = [
435
440
  saveGitHubStore(store);
436
441
  return { success: true, source: 'local-store', action: 'created', issue };
437
442
  }
438
- if (action === 'update') {
443
+ if (action === 'update' || action === 'close') {
444
+ // #4424: same contract as github_pr_manage merge/close — a failed `gh`
445
+ // call or an unmatched local fallback is a failure, not a success.
439
446
  const issueNumber = toPositiveInt(input.issueNumber);
440
- if (gh && issueNumber) {
441
- const argv = ['issue', 'edit', String(issueNumber)];
442
- if (input.title)
443
- argv.push('--title', input.title);
444
- if (input.labels) {
445
- const labels = sanitizeLabels(input.labels);
446
- if (labels === null)
447
- return { success: false, error: 'labels contains disallowed characters' };
448
- if (labels.length > 0)
447
+ if (!issueNumber)
448
+ return { success: false, error: `issueNumber is required (positive integer) for ${action}.` };
449
+ const labels = input.labels === undefined ? undefined : sanitizeLabels(input.labels);
450
+ if (labels === null)
451
+ return { success: false, error: 'labels contains disallowed characters' };
452
+ if (gh) {
453
+ const argv = ['issue', action === 'update' ? 'edit' : 'close', String(issueNumber)];
454
+ if (action === 'update') {
455
+ if (input.title)
456
+ argv.push('--title', input.title);
457
+ if (labels && labels.length > 0)
449
458
  argv.push('--add-label', labels.join(','));
459
+ if (argv.length === 3)
460
+ return { success: false, error: 'update requires title or labels' };
450
461
  }
451
- if (argv.length > 3) {
452
- const result = runArgv('gh', [...argv, ...repoArgs]);
453
- if (result !== null)
454
- return { success: true, _real: true, action: 'updated', issueNumber };
455
- }
456
- }
457
- const issueKey = issueNumber ? Object.keys(store.issues).find(k => k.includes(String(issueNumber))) : undefined;
458
- if (issueKey && store.issues[issueKey]) {
459
- if (input.title)
460
- store.issues[issueKey].title = input.title;
461
- if (input.labels) {
462
- const labels = sanitizeLabels(input.labels);
463
- if (labels !== null)
464
- store.issues[issueKey].labels = labels;
462
+ const r = runArgvResult('gh', [...argv, ...repoArgs]);
463
+ if ('error' in r) {
464
+ return { success: false, source: 'gh-cli', error: `gh issue ${argv[1]} ${issueNumber} failed: ${r.error}` };
465
465
  }
466
- saveGitHubStore(store);
466
+ return action === 'update'
467
+ ? { success: true, _real: true, action: 'updated', issueNumber }
468
+ : { success: true, _real: true, action: 'closed', issueNumber, closedAt: new Date().toISOString() };
467
469
  }
468
- return { success: true, source: 'local-store', action: 'updated', issueNumber };
469
- }
470
- if (action === 'close') {
471
- const issueNumber = toPositiveInt(input.issueNumber);
472
- if (gh && issueNumber) {
473
- const result = runArgv('gh', ['issue', 'close', String(issueNumber), ...repoArgs]);
474
- if (result !== null)
475
- return { success: true, _real: true, action: 'closed', issueNumber, closedAt: new Date().toISOString() };
470
+ const issue = store.issues[`issue-${issueNumber}`];
471
+ if (!issue)
472
+ return { success: false, source: 'local-store', error: `gh CLI not available and no local issue issue-${issueNumber}` };
473
+ if (action === 'close') {
474
+ issue.status = 'closed';
476
475
  }
477
- const issueKey = issueNumber ? Object.keys(store.issues).find(k => k.includes(String(issueNumber))) : undefined;
478
- if (issueKey && store.issues[issueKey]) {
479
- store.issues[issueKey].status = 'closed';
480
- saveGitHubStore(store);
476
+ else {
477
+ if (input.title)
478
+ issue.title = input.title;
479
+ if (labels)
480
+ issue.labels = labels;
481
481
  }
482
- return { success: true, source: 'local-store', action: 'closed', issueNumber, closedAt: new Date().toISOString() };
482
+ saveGitHubStore(store);
483
+ return action === 'update'
484
+ ? { success: true, source: 'local-store', action: 'updated', issueNumber }
485
+ : { success: true, source: 'local-store', action: 'closed', issueNumber, closedAt: new Date().toISOString() };
483
486
  }
484
487
  return { success: false, error: 'Unknown action' };
485
488
  },
@@ -899,7 +899,7 @@ export const neuralTools = [
899
899
  properties: {
900
900
  modelId: { type: 'string', description: 'Model ID to compress' },
901
901
  method: { type: 'string', enum: ['quantize', 'prune', 'distill'], description: 'Compression method' },
902
- targetSize: { type: 'number', description: 'Target size reduction (0-1)' },
902
+ targetSize: { type: 'number', description: 'Not used: quantize (#4195) and prune (#4423) are unavailable, and distill merges by similarity' },
903
903
  },
904
904
  },
905
905
  handler: async (input) => {
@@ -910,7 +910,6 @@ export const neuralTools = [
910
910
  }
911
911
  const store = loadNeuralStore();
912
912
  const method = input.method || 'quantize';
913
- const targetReduction = input.targetSize || 0.5;
914
913
  const patterns = Object.values(store.patterns);
915
914
  if (patterns.length === 0) {
916
915
  return { success: false, error: 'No patterns to compress. Train patterns first with neural_train.' };
@@ -936,23 +935,18 @@ export const neuralTools = [
936
935
  // Resolve provider only for operations that actually use embeddings.
937
936
  await ensureEmbeddings();
938
937
  if (method === 'prune') {
939
- // Prune patterns with low usage count below threshold (targetReduction as min usage)
940
- const threshold = targetReduction;
941
- const toRemove = [];
942
- for (const [id, pattern] of Object.entries(store.patterns)) {
943
- if ((pattern.usageCount || 0) < threshold)
944
- toRemove.push(id);
945
- }
946
- for (const id of toRemove)
947
- delete store.patterns[id];
948
- saveNeuralStore(store);
938
+ // #4423: prune deleted patterns with usageCount below targetSize, but
939
+ // nothing in the neural store records usage (patterns are written with
940
+ // 0 and only max-merged), so any targetSize > 0, including the old 0.5
941
+ // default, deleted and persisted every pattern. Refuse until usage is
942
+ // tracked, the same way quantize refuses (#4195). The store is untouched.
949
943
  return {
950
- success: true, _real: true, method,
951
- embeddingProvider: embeddingServiceName,
952
- threshold,
953
- patternsRemoved: toRemove.length,
944
+ success: false,
945
+ error: 'Pruning is unavailable: neural patterns do not record usage, so there is no signal to choose which to remove.',
946
+ method,
947
+ patternsRemoved: 0,
954
948
  patternsBefore: beforeCount,
955
- patternsAfter: Object.keys(store.patterns).length,
949
+ patternsAfter: beforeCount,
956
950
  };
957
951
  }
958
952
  if (method === 'distill') {
@@ -0,0 +1,11 @@
1
+ /**
2
+ * ruRE Phase 1 MCP Tools — JS/Electron static analysis.
3
+ *
4
+ * See plugins/ruflo-rure/docs/adrs/0001-scope-and-dual-use-policy.md and
5
+ * 0002-phase1-architecture.md. These tools parse local files; they never
6
+ * execute analyzed code, and all extracted text is routed through the
7
+ * AIDefence gate before being returned to the caller.
8
+ */
9
+ import type { MCPTool } from './types.js';
10
+ export declare const rureTools: MCPTool[];
11
+ //# sourceMappingURL=rure-tools.d.ts.map
@@ -0,0 +1,359 @@
1
+ /**
2
+ * ruRE Phase 1 MCP Tools — JS/Electron static analysis.
3
+ *
4
+ * See plugins/ruflo-rure/docs/adrs/0001-scope-and-dual-use-policy.md and
5
+ * 0002-phase1-architecture.md. These tools parse local files; they never
6
+ * execute analyzed code, and all extracted text is routed through the
7
+ * AIDefence gate before being returned to the caller.
8
+ */
9
+ import { openSync, fstatSync, readFileSync, closeSync } from 'node:fs';
10
+ import { validatePath, validateText } from './validate-input.js';
11
+ import { extractAsarWithCaps, DEFAULT_ASAR_LIMITS } from '../rure/extract-asar.js';
12
+ import { analyzeJsApp } from '../rure/analyze-js-app.js';
13
+ import { findFeature } from '../rure/find-feature.js';
14
+ import { gateWithAIDefence } from '../rure/aidefence-gate.js';
15
+ import { parseBinary, extractStrings, MAX_BINARY_BYTES } from '../rure/binary-parse.js';
16
+ import { parseDotNet } from '../rure/dotnet-parse.js';
17
+ import { analyzeEvm, parseHex, MAX_EVM_BYTES } from '../rure/evm-parse.js';
18
+ function fail(error) {
19
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error }) }], isError: true };
20
+ }
21
+ function ok(data) {
22
+ return { content: [{ type: 'text', text: JSON.stringify({ success: true, ...data }) }] };
23
+ }
24
+ /**
25
+ * Screens untrusted extracted text through AIDefence. Every attacker-derived string in a
26
+ * tool result goes through here (paths, names, literals), results are cached per call, and
27
+ * `screened` reports honestly whether the scanner actually ran on everything.
28
+ */
29
+ class Screener {
30
+ redacted = 0;
31
+ unscreened = 0;
32
+ cache = new Map();
33
+ async one(item) {
34
+ let g = this.cache.get(item);
35
+ if (!g) {
36
+ g = await gateWithAIDefence(item);
37
+ this.cache.set(item, g);
38
+ if (g.flagged)
39
+ this.redacted += 1;
40
+ if (!g.gated && item)
41
+ this.unscreened += 1;
42
+ }
43
+ return g.text;
44
+ }
45
+ async screen(items) {
46
+ const out = [];
47
+ for (const item of items)
48
+ out.push(await this.one(item));
49
+ return out;
50
+ }
51
+ get screened() {
52
+ return this.unscreened === 0;
53
+ }
54
+ }
55
+ async function screenEvidence(sc, e) {
56
+ return { ...e, file: await sc.one(e.file) };
57
+ }
58
+ /** Returns a module analysis with every attacker-derived string screened and clipped; raw snippets are dropped. */
59
+ async function screenModule(sc, mod) {
60
+ const imports = [];
61
+ for (const i of mod.imports) {
62
+ imports.push({ source: await sc.one(i.source), names: await sc.screen(i.names), evidence: await screenEvidence(sc, i.evidence) });
63
+ }
64
+ const exports = [];
65
+ for (const e of mod.exports)
66
+ exports.push({ name: await sc.one(e.name), evidence: await screenEvidence(sc, e.evidence) });
67
+ const electronBoundaries = [];
68
+ for (const b of mod.electronBoundaries) {
69
+ electronBoundaries.push({ kind: b.kind, detail: await sc.one(b.detail), evidence: await screenEvidence(sc, b.evidence) });
70
+ }
71
+ return { file: await sc.one(mod.file), imports, exports, electronBoundaries };
72
+ }
73
+ /** Opens once and checks the size on the same descriptor, so a file swapped after a stat cannot bypass the cap. */
74
+ function readCapped(path, cap) {
75
+ const fd = openSync(path, 'r');
76
+ try {
77
+ const st = fstatSync(fd);
78
+ if (!st.isFile())
79
+ return { ok: false, error: 'path is not a regular file' };
80
+ if (st.size > cap)
81
+ return { ok: false, error: `file exceeds the ${cap}-byte analysis cap` };
82
+ return { ok: true, bytes: readFileSync(fd) };
83
+ }
84
+ finally {
85
+ closeSync(fd);
86
+ }
87
+ }
88
+ export const rureTools = [
89
+ {
90
+ name: 'rure_extract_asar',
91
+ description: 'Unpack an Electron .asar archive to a scratch directory, under resource caps (max total declared size, max file count) checked from the archive header before any bytes are written. Refuses to partially extract: returns truncated:true with nothing written if the archive exceeds the caps. Use when you need to analyze the JS inside a packaged Electron app and rure_analyze_js_app rejects the .asar path directly.',
92
+ category: 'rure',
93
+ tags: ['reverse-engineering', 'electron', 'asar', 'static-analysis'],
94
+ inputSchema: {
95
+ type: 'object',
96
+ properties: {
97
+ path: { type: 'string', description: 'Absolute path to the .asar file' },
98
+ },
99
+ required: ['path'],
100
+ },
101
+ handler: async (input) => {
102
+ const v = validatePath(input.path, 'path');
103
+ if (!v.valid)
104
+ return fail(v.error);
105
+ try {
106
+ const result = await extractAsarWithCaps(v.sanitized, DEFAULT_ASAR_LIMITS);
107
+ if (result.truncated) {
108
+ return ok({ truncated: true, reason: result.reason, fileCount: result.fileCount, totalBytes: result.totalBytes });
109
+ }
110
+ return ok({
111
+ truncated: false,
112
+ unpackedPath: result.unpackedPath,
113
+ fileCount: result.fileCount,
114
+ totalBytes: result.totalBytes,
115
+ });
116
+ }
117
+ catch (err) {
118
+ return fail(`asar extraction failed: ${err instanceof Error ? err.message : String(err)}`);
119
+ }
120
+ },
121
+ },
122
+ {
123
+ name: 'rure_analyze_js_app',
124
+ description: 'Statically analyze a directory of JavaScript/TypeScript/Electron source: module list, import/export graph, and Electron process-boundary detection (ipcMain/ipcRenderer/contextBridge, require("electron"), nodeIntegration flags). Every finding carries evidence (file + line range), AIDefence-screened before return. Use when you need a structural map of unfamiliar JS/Electron source rather than reading files one at a time — native Read is fine for a single already-identified file, but wrong for discovering the import graph or Electron boundaries across a whole app. Does not accept a .asar path directly — run rure_extract_asar first and pass its unpackedPath.',
125
+ category: 'rure',
126
+ tags: ['reverse-engineering', 'electron', 'javascript', 'static-analysis'],
127
+ inputSchema: {
128
+ type: 'object',
129
+ properties: {
130
+ path: { type: 'string', description: 'Absolute path to a directory of extracted JS/Electron source' },
131
+ },
132
+ required: ['path'],
133
+ },
134
+ handler: async (input) => {
135
+ const v = validatePath(input.path, 'path');
136
+ if (!v.valid)
137
+ return fail(v.error);
138
+ try {
139
+ const analysis = await analyzeJsApp(v.sanitized);
140
+ const sc = new Screener();
141
+ const modules = [];
142
+ for (const m of analysis.modules)
143
+ modules.push(await screenModule(sc, m));
144
+ return ok({
145
+ filesScanned: analysis.filesScanned,
146
+ truncated: analysis.truncated,
147
+ skippedFiles: analysis.skippedFiles,
148
+ isElectron: analysis.isElectron,
149
+ modules,
150
+ redactedSnippetCount: sc.redacted,
151
+ screened: sc.screened,
152
+ });
153
+ }
154
+ catch (err) {
155
+ return fail(`analysis failed: ${err instanceof Error ? err.message : String(err)}`);
156
+ }
157
+ },
158
+ },
159
+ {
160
+ name: 'rure_find_feature',
161
+ description: 'Locate where a described feature likely lives in an already-extracted JS/Electron app, using deterministic lexical and structural scoring (not semantic/LLM matching, so results stay explainable). Returns ranked matches with file, line range, a short snippet, and a score, every snippet AIDefence-screened before return. Use when the target app is too large to read file-by-file and you need evidence of where a feature lives before explaining or reimplementing it — grep is fine for an exact known string, but wrong when you only have a plain-language description of the behavior.',
162
+ category: 'rure',
163
+ tags: ['reverse-engineering', 'search', 'static-analysis'],
164
+ inputSchema: {
165
+ type: 'object',
166
+ properties: {
167
+ path: { type: 'string', description: 'Absolute path to a directory of extracted JS/Electron source' },
168
+ query: { type: 'string', description: 'Plain-language description of the feature to locate' },
169
+ },
170
+ required: ['path', 'query'],
171
+ },
172
+ handler: async (input) => {
173
+ const v = validatePath(input.path, 'path');
174
+ if (!v.valid)
175
+ return fail(v.error);
176
+ const q = validateText(input.query, 'query', 2000);
177
+ if (!q.valid)
178
+ return fail(q.error);
179
+ try {
180
+ const result = await findFeature(v.sanitized, q.sanitized);
181
+ const sc = new Screener();
182
+ const gated = [];
183
+ for (const m of result.matches) {
184
+ const before = sc.redacted;
185
+ const snippet = await sc.one(m.snippet);
186
+ gated.push({ ...m, file: await sc.one(m.file), snippet, redacted: sc.redacted > before });
187
+ }
188
+ return ok({
189
+ matches: gated,
190
+ filesScanned: result.filesScanned,
191
+ truncated: result.truncated,
192
+ skippedFiles: result.skippedFiles,
193
+ screened: sc.screened,
194
+ });
195
+ }
196
+ catch (err) {
197
+ return fail(`feature search failed: ${err instanceof Error ? err.message : String(err)}`);
198
+ }
199
+ },
200
+ },
201
+ {
202
+ name: 'rure_analyze_binary',
203
+ description: 'Statically inspect a native ELF, PE, or Mach-O file (ADR-0003): format, architecture, entry point, section layout, linked libraries, and imported/exported symbols, plus optional printable strings. Pure byte parsing under hard caps (128 MiB file, bounded tables); the file is never loaded or executed, and every name and string is AIDefence-screened before return. Use when you need an inventory of what a native binary links against and exposes before deciding where to look next — not for disassembly or decompilation, which this does not do. Malformed headers yield warnings, not errors.',
204
+ category: 'rure',
205
+ tags: ['reverse-engineering', 'binary', 'elf', 'pe', 'macho', 'static-analysis'],
206
+ inputSchema: {
207
+ type: 'object',
208
+ properties: {
209
+ path: { type: 'string', description: 'Absolute path to a native binary (ELF, PE, or Mach-O)' },
210
+ includeStrings: { type: 'boolean', description: 'Also return up to 200 printable strings (default false)' },
211
+ },
212
+ required: ['path'],
213
+ },
214
+ handler: async (input) => {
215
+ const v = validatePath(input.path, 'path');
216
+ if (!v.valid)
217
+ return fail(v.error);
218
+ try {
219
+ const r = readCapped(v.sanitized, MAX_BINARY_BYTES);
220
+ if (!r.ok)
221
+ return fail(r.error);
222
+ const buf = r.bytes;
223
+ const info = parseBinary(buf);
224
+ const sc = new Screener();
225
+ const libraries = await sc.screen(info.libraries);
226
+ const imports = await sc.screen(info.imports);
227
+ const exports = await sc.screen(info.exports);
228
+ const sectionNames = await sc.screen(info.sections.map((x) => x.name));
229
+ const sections = info.sections.map((x, i) => ({ ...x, name: sectionNames[i] }));
230
+ let strings;
231
+ let stringsTruncated = false;
232
+ const warnings = [...info.warnings];
233
+ if (input.includeStrings === true) {
234
+ if (info.format === 'unknown') {
235
+ warnings.push('strings not extracted: file is not a recognized binary format');
236
+ }
237
+ else {
238
+ const ex = extractStrings(buf);
239
+ stringsTruncated = ex.truncated;
240
+ const gated = await sc.screen(ex.strings.map((x) => x.value));
241
+ strings = ex.strings.map((x, i) => ({ value: gated[i], offset: x.offset }));
242
+ }
243
+ }
244
+ return ok({ ...info, warnings, sections, libraries, imports, exports, ...(strings ? { strings, stringsTruncated } : {}), redactedCount: sc.redacted, screened: sc.screened });
245
+ }
246
+ catch (err) {
247
+ return fail(`binary analysis failed: ${err instanceof Error ? err.message : String(err)}`);
248
+ }
249
+ },
250
+ },
251
+ {
252
+ name: 'rure_analyze_dotnet',
253
+ description: 'Inspect a managed .NET assembly (.dll/.exe) from its ECMA-335 metadata (ADR-0004): runtime version, assembly identity, assembly references, type names, method count, P/Invoke native imports (module + function), user-string literals, and entry-point token. Reads metadata only under hard caps; the assembly is never loaded or run, and every name and string is AIDefence-screened before return. Use when you need the dependency and native-call surface of a .NET binary before deciding where to dig deeper — not for IL disassembly or decompilation, which this does not do. A native (non-managed) PE returns isManaged:false.',
254
+ category: 'rure',
255
+ tags: ['reverse-engineering', 'dotnet', 'assembly', 'static-analysis'],
256
+ inputSchema: {
257
+ type: 'object',
258
+ properties: {
259
+ path: { type: 'string', description: 'Absolute path to a .NET assembly (.dll or .exe)' },
260
+ },
261
+ required: ['path'],
262
+ },
263
+ handler: async (input) => {
264
+ const v = validatePath(input.path, 'path');
265
+ if (!v.valid)
266
+ return fail(v.error);
267
+ try {
268
+ const r = readCapped(v.sanitized, MAX_BINARY_BYTES);
269
+ if (!r.ok)
270
+ return fail(r.error);
271
+ const info = parseDotNet(r.bytes);
272
+ const sc = new Screener();
273
+ const assembly = info.assembly ? { ...info.assembly, name: await sc.one(info.assembly.name) } : null;
274
+ const refNames = await sc.screen(info.assemblyRefs.map((x) => x.name));
275
+ const types = await sc.screen(info.types);
276
+ const pmods = await sc.screen(info.pinvokes.map((x) => x.module));
277
+ const pfuncs = await sc.screen(info.pinvokes.map((x) => x.function));
278
+ const userStrings = await sc.screen(info.userStrings);
279
+ const runtimeVersion = info.runtimeVersion === null ? null : await sc.one(info.runtimeVersion);
280
+ return ok({
281
+ ...info,
282
+ runtimeVersion,
283
+ assembly,
284
+ assemblyRefs: info.assemblyRefs.map((x, i) => ({ ...x, name: refNames[i] })),
285
+ types,
286
+ pinvokes: info.pinvokes.map((_, i) => ({ module: pmods[i], function: pfuncs[i] })),
287
+ userStrings,
288
+ redactedCount: sc.redacted,
289
+ screened: sc.screened,
290
+ });
291
+ }
292
+ catch (err) {
293
+ return fail(`dotnet analysis failed: ${err instanceof Error ? err.message : String(err)}`);
294
+ }
295
+ },
296
+ },
297
+ {
298
+ name: 'rure_analyze_evm',
299
+ description: 'Statically inventory EVM contract bytecode (ADR-0005): instruction and JUMPDEST counts, function selectors recognized from the dispatcher (with names for a small well-known table only), counts and offsets of hazardous opcodes (SELFDESTRUCT, DELEGATECALL, CALLCODE, CREATE/CREATE2, ORIGIN, CALL, STATICCALL), embedded addresses, event topics, EIP-1167 minimal-proxy detection, compiler metadata, and embedded strings such as revert reasons (AIDefence-screened). Pass bytecode inline as hex, or a path to a file of hex text or raw bytes. Aligned disassembly only: there is no EVM interpreter, no RPC, and no network. Use when you need the exposed surface and risky capabilities of a contract before deeper review; a hazardous opcode is an inventory fact, not a vulnerability finding, and dispatcher detection can miss unusual layouts.',
300
+ category: 'rure',
301
+ tags: ['reverse-engineering', 'evm', 'smart-contract', 'static-analysis'],
302
+ inputSchema: {
303
+ type: 'object',
304
+ properties: {
305
+ bytecode: { type: 'string', description: 'Contract bytecode as hex (0x prefix optional). Provide this or path, not both.' },
306
+ path: { type: 'string', description: 'Absolute path to a file containing hex text or raw bytecode' },
307
+ includeDisassembly: { type: 'boolean', description: 'Also return the first 500 instructions (default false)' },
308
+ },
309
+ },
310
+ handler: async (input) => {
311
+ const hasInline = typeof input.bytecode === 'string' && input.bytecode.length > 0;
312
+ const hasPath = typeof input.path === 'string' && input.path.length > 0;
313
+ if (hasInline === hasPath)
314
+ return fail('provide exactly one of bytecode or path');
315
+ try {
316
+ let bytes;
317
+ if (hasInline) {
318
+ const text = input.bytecode;
319
+ if (text.length > MAX_EVM_BYTES * 2 + 2)
320
+ return fail(`bytecode exceeds the ${MAX_EVM_BYTES}-byte cap`);
321
+ const parsed = parseHex(text);
322
+ if (!parsed.ok)
323
+ return fail(parsed.error);
324
+ bytes = parsed.bytes;
325
+ }
326
+ else {
327
+ const v = validatePath(input.path, 'path');
328
+ if (!v.valid)
329
+ return fail(v.error);
330
+ const r = readCapped(v.sanitized, MAX_EVM_BYTES * 2 + 64);
331
+ if (!r.ok)
332
+ return fail(r.error);
333
+ const raw = r.bytes;
334
+ const asText = raw.toString('latin1').trim();
335
+ if (/^(0x)?[0-9a-fA-F\s]+$/.test(asText)) {
336
+ const parsed = parseHex(asText.replace(/\s/g, ''));
337
+ if (!parsed.ok)
338
+ return fail(parsed.error);
339
+ bytes = parsed.bytes;
340
+ }
341
+ else if (raw.length <= MAX_EVM_BYTES) {
342
+ bytes = raw;
343
+ }
344
+ else {
345
+ return fail(`file exceeds the ${MAX_EVM_BYTES}-byte bytecode cap`);
346
+ }
347
+ }
348
+ const info = analyzeEvm(bytes, input.includeDisassembly === true);
349
+ const sc = new Screener();
350
+ const strings = await sc.screen(info.strings);
351
+ return ok({ ...info, strings, redactedCount: sc.redacted, screened: sc.screened });
352
+ }
353
+ catch (err) {
354
+ return fail(`evm analysis failed: ${err instanceof Error ? err.message : String(err)}`);
355
+ }
356
+ },
357
+ },
358
+ ];
359
+ //# sourceMappingURL=rure-tools.js.map