claude-flow 3.72.0 → 3.72.1

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 (52) hide show
  1. package/node_modules/@claude-flow/codex/.agents/skills/fast-code-edits/SKILL.md +42 -0
  2. package/node_modules/@claude-flow/codex/.agents/skills/graph-mincut/SKILL.md +42 -0
  3. package/node_modules/@claude-flow/codex/.agents/skills/injection-defense/SKILL.md +45 -0
  4. package/node_modules/@claude-flow/codex/.agents/skills/lora-learning/SKILL.md +39 -0
  5. package/node_modules/@claude-flow/codex/.agents/skills/sublinear-solver/SKILL.md +38 -0
  6. package/node_modules/@claude-flow/codex/.agents/skills/vector-quantization/SKILL.md +49 -0
  7. package/node_modules/@claude-flow/codex/dist/generators/skill-md.d.ts.map +1 -1
  8. package/node_modules/@claude-flow/codex/dist/generators/skill-md.js +6 -0
  9. package/node_modules/@claude-flow/codex/dist/generators/skill-md.js.map +1 -1
  10. package/node_modules/@claude-flow/codex/dist/index.d.ts +3 -3
  11. package/node_modules/@claude-flow/codex/dist/index.js +1 -1
  12. package/node_modules/@claude-flow/codex/dist/templates/index.d.ts.map +1 -1
  13. package/node_modules/@claude-flow/codex/dist/templates/index.js +37 -0
  14. package/node_modules/@claude-flow/codex/dist/templates/index.js.map +1 -1
  15. package/node_modules/@claude-flow/codex/dist/types.d.ts +1 -1
  16. package/node_modules/@claude-flow/codex/dist/types.d.ts.map +1 -1
  17. package/node_modules/@claude-flow/codex/package.json +1 -1
  18. package/package.json +9 -6
  19. package/v3/@claude-flow/cli/catalog-manifest.json +4 -4
  20. package/v3/@claude-flow/cli/dist/src/appliance/ruvllm-bridge.d.ts +6 -2
  21. package/v3/@claude-flow/cli/dist/src/appliance/ruvllm-bridge.js +13 -8
  22. package/v3/@claude-flow/cli/dist/src/commands/init.js +2 -0
  23. package/v3/@claude-flow/cli/dist/src/commands/neural.js +79 -71
  24. package/v3/@claude-flow/cli/dist/src/init/executor.js +13 -0
  25. package/v3/@claude-flow/cli/dist/src/init/types.d.ts +6 -0
  26. package/v3/@claude-flow/cli/dist/src/init/types.js +3 -0
  27. package/v3/@claude-flow/cli/dist/src/mcp-client.js +2 -0
  28. package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-tools.js +34 -2
  29. package/v3/@claude-flow/cli/dist/src/mcp-tools/fast-apply-tools.d.ts +4 -0
  30. package/v3/@claude-flow/cli/dist/src/mcp-tools/fast-apply-tools.js +85 -0
  31. package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +2 -33
  32. package/v3/@claude-flow/cli/dist/src/mcp-tools/metaharness-tools.js +1 -1
  33. package/v3/@claude-flow/cli/dist/src/mcp-tools/realpath-containment.d.ts +3 -0
  34. package/v3/@claude-flow/cli/dist/src/mcp-tools/realpath-containment.js +39 -0
  35. package/v3/@claude-flow/cli/dist/src/mods/command-registry/schema.d.ts +12 -12
  36. package/v3/@claude-flow/cli/dist/src/ruvector/ast-analyzer.d.ts +1 -2
  37. package/v3/@claude-flow/cli/dist/src/ruvector/ast-analyzer.js +4 -12
  38. package/v3/@claude-flow/cli/dist/src/ruvector/coverage-router.d.ts +1 -2
  39. package/v3/@claude-flow/cli/dist/src/ruvector/coverage-router.js +4 -12
  40. package/v3/@claude-flow/cli/dist/src/ruvector/diff-classifier.d.ts +1 -2
  41. package/v3/@claude-flow/cli/dist/src/ruvector/diff-classifier.js +3 -12
  42. package/v3/@claude-flow/cli/dist/src/ruvector/fast-apply.d.ts +46 -0
  43. package/v3/@claude-flow/cli/dist/src/ruvector/fast-apply.js +73 -0
  44. package/v3/@claude-flow/cli/dist/src/ruvector/graph-analyzer.d.ts +11 -1
  45. package/v3/@claude-flow/cli/dist/src/ruvector/graph-analyzer.js +22 -36
  46. package/v3/@claude-flow/cli/dist/src/ruvector/mincut-bridge.d.ts +70 -0
  47. package/v3/@claude-flow/cli/dist/src/ruvector/mincut-bridge.js +172 -0
  48. package/v3/@claude-flow/cli/dist/src/services/distill-oracle.d.ts +1 -1
  49. package/v3/@claude-flow/cli/dist/src/services/distill-oracle.js +2 -2
  50. package/v3/@claude-flow/cli/package.json +11 -9
  51. package/.claude/.proven-config-version +0 -1
  52. package/.claude/proven-config.json +0 -42
@@ -1516,81 +1516,89 @@ const benchmarkCommand = {
1516
1516
  const spinner = output.createSpinner({ text: 'Running benchmarks...', spinner: 'dots' });
1517
1517
  spinner.start();
1518
1518
  try {
1519
- // Indirect the specifier through a string variable so tsc doesn't
1520
- // statically resolve this optional dependency at build time (TS2307
1521
- // when it isn't installed — install-safety / Build V3 pattern from #2586).
1522
- const attentionPkg = '@ruvector/attention';
1523
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- dynamic import of optional native WASM module with no type declarations
1524
- const attention = await import(attentionPkg);
1525
- // Manual benchmark since benchmarkAttention has a binding bug
1526
- const benchmarkMechanism = async (name, mechanism) => {
1527
- const query = new Float32Array(dim);
1528
- const keys = [];
1529
- const values = [];
1530
- for (let i = 0; i < dim; i++)
1531
- query[i] = Math.random();
1532
- for (let k = 0; k < numKeys; k++) {
1533
- const key = new Float32Array(dim);
1534
- const val = new Float32Array(dim);
1535
- for (let i = 0; i < dim; i++) {
1536
- key[i] = Math.random();
1537
- val[i] = Math.random();
1519
+ const results = [];
1520
+ // The attention and MicroLoRA benchmarks are independent: a missing or
1521
+ // API-incompatible @ruvector/attention must not hide the
1522
+ // @ruvector/learning-wasm MicroLoRA numbers below.
1523
+ try {
1524
+ // Indirect the specifier through a string variable so tsc doesn't
1525
+ // statically resolve this optional dependency at build time (TS2307
1526
+ // when it isn't installed — install-safety / Build V3 pattern from #2586).
1527
+ const attentionPkg = '@ruvector/attention';
1528
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- dynamic import of optional native WASM module with no type declarations
1529
+ const attention = await import(attentionPkg);
1530
+ // Manual benchmark since benchmarkAttention has a binding bug
1531
+ const benchmarkMechanism = async (name, mechanism) => {
1532
+ const query = new Float32Array(dim);
1533
+ const keys = [];
1534
+ const values = [];
1535
+ for (let i = 0; i < dim; i++)
1536
+ query[i] = Math.random();
1537
+ for (let k = 0; k < numKeys; k++) {
1538
+ const key = new Float32Array(dim);
1539
+ const val = new Float32Array(dim);
1540
+ for (let i = 0; i < dim; i++) {
1541
+ key[i] = Math.random();
1542
+ val[i] = Math.random();
1543
+ }
1544
+ keys.push(key);
1545
+ values.push(val);
1538
1546
  }
1539
- keys.push(key);
1540
- values.push(val);
1541
- }
1542
- // Warmup
1543
- for (let i = 0; i < 10; i++)
1544
- mechanism.computeRaw(query, keys, values);
1545
- const start = performance.now();
1546
- for (let i = 0; i < iterations; i++) {
1547
- mechanism.computeRaw(query, keys, values);
1548
- }
1549
- const elapsed = performance.now() - start;
1550
- return {
1551
- name,
1552
- averageTimeMs: elapsed / iterations,
1553
- opsPerSecond: Math.round((iterations / elapsed) * 1000),
1547
+ // Warmup
1548
+ for (let i = 0; i < 10; i++)
1549
+ mechanism.computeRaw(query, keys, values);
1550
+ const start = performance.now();
1551
+ for (let i = 0; i < iterations; i++) {
1552
+ mechanism.computeRaw(query, keys, values);
1553
+ }
1554
+ const elapsed = performance.now() - start;
1555
+ return {
1556
+ name,
1557
+ averageTimeMs: elapsed / iterations,
1558
+ opsPerSecond: Math.round((iterations / elapsed) * 1000),
1559
+ };
1554
1560
  };
1555
- };
1556
- spinner.setText(`Benchmarking attention mechanisms (dim=${dim}, keys=${numKeys}, iter=${iterations})...`);
1557
- const results = [];
1558
- // Benchmark each mechanism
1559
- const dotProduct = new attention.DotProductAttention(dim);
1560
- results.push(await benchmarkMechanism('DotProduct', dotProduct));
1561
- const flash = new attention.FlashAttention(dim, 64);
1562
- results.push(await benchmarkMechanism('FlashAttention', flash));
1563
- const multiHead = new attention.MultiHeadAttention(dim, 4);
1564
- results.push(await benchmarkMechanism('MultiHead (4 heads)', multiHead));
1565
- const hyperbolic = new attention.HyperbolicAttention(dim, 1.0);
1566
- results.push(await benchmarkMechanism('Hyperbolic', hyperbolic));
1567
- const linear = new attention.LinearAttention(dim, dim);
1568
- results.push(await benchmarkMechanism('Linear', linear));
1569
- spinner.succeed('Benchmark complete');
1570
- output.writeln();
1571
- output.printTable({
1572
- columns: [
1573
- { key: 'name', header: 'Mechanism', width: 25 },
1574
- { key: 'avgTime', header: 'Avg Time (ms)', width: 15 },
1575
- { key: 'opsPerSec', header: 'Ops/sec', width: 15 },
1576
- ],
1577
- data: results.map(r => ({
1578
- name: r.name,
1579
- avgTime: r.averageTimeMs.toFixed(4),
1580
- opsPerSec: r.opsPerSecond.toLocaleString(),
1581
- })),
1582
- });
1583
- // Show speedup comparisons
1584
- const dotProductResult = results.find(r => r.name.includes('DotProduct'));
1585
- const flashResult = results.find(r => r.name.includes('Flash'));
1586
- const hyperbolicResult = results.find(r => r.name.includes('Hyperbolic'));
1587
- if (dotProductResult && flashResult) {
1588
- const speedup = dotProductResult.averageTimeMs / flashResult.averageTimeMs;
1561
+ spinner.setText(`Benchmarking attention mechanisms (dim=${dim}, keys=${numKeys}, iter=${iterations})...`);
1562
+ // Benchmark each mechanism
1563
+ const dotProduct = new attention.DotProductAttention(dim);
1564
+ results.push(await benchmarkMechanism('DotProduct', dotProduct));
1565
+ const flash = new attention.FlashAttention(dim, 64);
1566
+ results.push(await benchmarkMechanism('FlashAttention', flash));
1567
+ const multiHead = new attention.MultiHeadAttention(dim, 4);
1568
+ results.push(await benchmarkMechanism('MultiHead (4 heads)', multiHead));
1569
+ const hyperbolic = new attention.HyperbolicAttention(dim, 1.0);
1570
+ results.push(await benchmarkMechanism('Hyperbolic', hyperbolic));
1571
+ const linear = new attention.LinearAttention(dim, dim);
1572
+ results.push(await benchmarkMechanism('Linear', linear));
1573
+ spinner.succeed('Benchmark complete');
1589
1574
  output.writeln();
1590
- output.writeln(output.highlight(`Flash Attention speedup: ${speedup.toFixed(2)}x faster than DotProduct`));
1575
+ output.printTable({
1576
+ columns: [
1577
+ { key: 'name', header: 'Mechanism', width: 25 },
1578
+ { key: 'avgTime', header: 'Avg Time (ms)', width: 15 },
1579
+ { key: 'opsPerSec', header: 'Ops/sec', width: 15 },
1580
+ ],
1581
+ data: results.map(r => ({
1582
+ name: r.name,
1583
+ avgTime: r.averageTimeMs.toFixed(4),
1584
+ opsPerSec: r.opsPerSecond.toLocaleString(),
1585
+ })),
1586
+ });
1587
+ // Show speedup comparisons
1588
+ const dotProductResult = results.find(r => r.name.includes('DotProduct'));
1589
+ const flashResult = results.find(r => r.name.includes('Flash'));
1590
+ const hyperbolicResult = results.find(r => r.name.includes('Hyperbolic'));
1591
+ if (dotProductResult && flashResult) {
1592
+ const speedup = dotProductResult.averageTimeMs / flashResult.averageTimeMs;
1593
+ output.writeln();
1594
+ output.writeln(output.highlight(`Flash Attention speedup: ${speedup.toFixed(2)}x faster than DotProduct`));
1595
+ }
1596
+ if (dotProductResult && hyperbolicResult) {
1597
+ output.writeln(output.dim(`Hyperbolic overhead: ${(hyperbolicResult.averageTimeMs / dotProductResult.averageTimeMs).toFixed(2)}x (expected for manifold ops)`));
1598
+ }
1591
1599
  }
1592
- if (dotProductResult && hyperbolicResult) {
1593
- output.writeln(output.dim(`Hyperbolic overhead: ${(hyperbolicResult.averageTimeMs / dotProductResult.averageTimeMs).toFixed(2)}x (expected for manifold ops)`));
1600
+ catch (attentionError) {
1601
+ spinner.fail(`Attention benchmark skipped: ${attentionError instanceof Error ? attentionError.message : String(attentionError)}`);
1594
1602
  }
1595
1603
  // Also benchmark MicroLoRA
1596
1604
  spinner.start();
@@ -78,6 +78,17 @@ const SKILLS_MAP = {
78
78
  'sparc-methodology',
79
79
  'stream-chain',
80
80
  ],
81
+ // How and when to use the ecosystem packages ruflo ships or wires in:
82
+ // ruvector + @ruvector/mincut-wasm, @ruvector/rabitq-wasm, sublinear-time-solver,
83
+ // @claude-flow/aidefence, agent-booster, @ruvector/learning-wasm.
84
+ ecosystem: [
85
+ 'vector-quantization',
86
+ 'graph-mincut',
87
+ 'sublinear-solver',
88
+ 'injection-defense',
89
+ 'fast-code-edits',
90
+ 'lora-learning',
91
+ ],
81
92
  };
82
93
  /**
83
94
  * Commands to copy based on configuration
@@ -1087,6 +1098,8 @@ async function copySkills(targetDir, options, result) {
1087
1098
  skillsToCopy.push(...SKILLS_MAP.dualMode);
1088
1099
  if (skillsConfig.legacy)
1089
1100
  skillsToCopy.push(...SKILLS_MAP.legacy);
1101
+ if (skillsConfig.ecosystem ?? true)
1102
+ skillsToCopy.push(...SKILLS_MAP.ecosystem);
1090
1103
  }
1091
1104
  // Find source skills directory
1092
1105
  const sourceSkillsDir = findSourceDir('skills', options.sourceBaseDir);
@@ -78,6 +78,12 @@ export interface SkillsConfig {
78
78
  dualMode: boolean;
79
79
  /** Include legacy skills that document commands v3 does not ship (opt-in) */
80
80
  legacy: boolean;
81
+ /**
82
+ * Include ecosystem skills (vector quantization, graph min-cut, sublinear
83
+ * solving, injection defense, fast code edits, LoRA learning). Optional so
84
+ * existing SkillsConfig literals stay valid; absent means on.
85
+ */
86
+ ecosystem?: boolean;
81
87
  /** Include all available skills */
82
88
  all: boolean;
83
89
  }
@@ -79,6 +79,7 @@ export const DEFAULT_INIT_OPTIONS = {
79
79
  v3: false, // ADR-128: opt-in like agents.v3; use --full or `init skills --v3`
80
80
  dualMode: false, // Optional: enable with --dual flag
81
81
  legacy: false, // #4539: stream-chain/sparc document verbs v3 does not ship
82
+ ecosystem: true, // ruvector / agent-booster / aidefence usage skills
82
83
  all: false,
83
84
  },
84
85
  commands: {
@@ -188,6 +189,7 @@ export const MINIMAL_INIT_OPTIONS = {
188
189
  v3: false,
189
190
  dualMode: false,
190
191
  legacy: false,
192
+ ecosystem: false,
191
193
  all: false,
192
194
  },
193
195
  agents: {
@@ -249,6 +251,7 @@ export const FULL_INIT_OPTIONS = {
249
251
  v3: true,
250
252
  dualMode: true, // Include in full init
251
253
  legacy: true, // Include in full init
254
+ ecosystem: true,
252
255
  all: true,
253
256
  },
254
257
  commands: {
@@ -13,6 +13,7 @@ import { swarmTools } from './mcp-tools/swarm-tools.js';
13
13
  import { memoryTools } from './mcp-tools/memory-tools.js';
14
14
  import { configTools } from './mcp-tools/config-tools.js';
15
15
  import { hooksTools } from './mcp-tools/hooks-tools.js';
16
+ import { fastApplyTools } from './mcp-tools/fast-apply-tools.js';
16
17
  import { taskTools } from './mcp-tools/task-tools.js';
17
18
  import { sessionTools } from './mcp-tools/session-tools.js';
18
19
  import { hiveMindTools } from './mcp-tools/hive-mind-tools.js';
@@ -131,6 +132,7 @@ registerTools([
131
132
  ...memoryTools,
132
133
  ...configTools,
133
134
  ...hooksTools,
135
+ ...fastApplyTools,
134
136
  ...taskTools,
135
137
  ...sessionTools,
136
138
  ...hiveMindTools,
@@ -1502,6 +1502,8 @@ export const agentdbGraphPathfinder = {
1502
1502
  }
1503
1503
  const edges = rawEdges;
1504
1504
  let paths = [];
1505
+ let mincutInfo;
1506
+ let approximation;
1505
1507
  // Check millisecond budget before heavy computation
1506
1508
  if (Date.now() - t0 > budget.maxMillis) {
1507
1509
  return { success: true, paths: [], count: 0, message: `complexityBudget.maxMillis (${budget.maxMillis}ms) exceeded before solver dispatch`, seedNodeId, algorithm, elapsedMs: Date.now() - t0 };
@@ -1557,10 +1559,38 @@ export const agentdbGraphPathfinder = {
1557
1559
  paths = witnessChain.slice(0, topK);
1558
1560
  break;
1559
1561
  }
1562
+ case 'dynamic-mincut': {
1563
+ // Exact minimum cut of the seed's depth-hop neighbourhood: the
1564
+ // weakest boundary around the seed, and the nodes on its side of it.
1565
+ // Wasm solver via ruvector (@ruvector/mincut-wasm), JS Stoer-Wagner
1566
+ // fallback for small neighbourhoods.
1567
+ const edgeTuples = edges.map(r => [String(r[0]), String(r[1]), Number(r[2]) || 1.0]);
1568
+ const { seedLocalMinCut } = await import('../ruvector/mincut-bridge.js');
1569
+ const { fallbackMinCut } = await import('../ruvector/graph-analyzer.js');
1570
+ const cut = await seedLocalMinCut(seedNodeId, edgeTuples, depth, budget.maxNodesVisited, fallbackMinCut);
1571
+ if (!cut) {
1572
+ mincutInfo = { backend: 'none', message: 'seed neighbourhood too large for the JS fallback and the wasm solver is unavailable (install ruvector)' };
1573
+ break;
1574
+ }
1575
+ paths = cut.seedSide
1576
+ .map(r => ({ nodeId: r.nodeId, score: 1 / (1 + r.depth), depth: r.depth }))
1577
+ .filter(r => r.score >= threshold)
1578
+ .slice(0, topK);
1579
+ mincutInfo = {
1580
+ backend: cut.backend,
1581
+ cutValue: cut.cutValue,
1582
+ seedSideSize: cut.seedSide.length + 1,
1583
+ otherSideSize: cut.otherSide.length,
1584
+ subgraphNodes: cut.subgraphNodes,
1585
+ cutEdges: cut.cutEdges.slice(0, 50),
1586
+ };
1587
+ break;
1588
+ }
1560
1589
  case 'connected-component-churn':
1561
- case 'dynamic-mincut':
1562
1590
  case 'spectral-sparsify': {
1563
- // Simplified implementations: return k-hop neighbors with basic score
1591
+ // Not implemented natively yet: approximated by k-hop neighbours with
1592
+ // a rank-decay score. The response says so via `implementation`.
1593
+ approximation = 'k-hop';
1564
1594
  const edgeTuples = edges.map(r => [r[0], r[1], Number(r[2]) || 1.0]);
1565
1595
  const khopResult = await agentdbGraphQuery.handler({
1566
1596
  nodeId: seedNodeId, mode: 'k-hop', depth, complexityBudget: budget,
@@ -1582,6 +1612,8 @@ export const agentdbGraphPathfinder = {
1582
1612
  count: paths.length,
1583
1613
  elapsedMs,
1584
1614
  budgetUsed: { millis: elapsedMs, nodes: rawEdges.length },
1615
+ ...(mincutInfo && { mincut: mincutInfo }),
1616
+ ...(approximation && { implementation: `${approximation} approximation` }),
1585
1617
  ...(depthWarning && { warning: depthWarning }),
1586
1618
  };
1587
1619
  }
@@ -0,0 +1,4 @@
1
+ import { type MCPTool } from './types.js';
2
+ export declare const hooksFastApply: MCPTool;
3
+ export declare const fastApplyTools: MCPTool[];
4
+ //# sourceMappingURL=fast-apply-tools.d.ts.map
@@ -0,0 +1,85 @@
1
+ /**
2
+ * hooks_fast-apply — merge a code snippet into a file or string with
3
+ * agent-booster (~ms, no LLM). The caller supplies the target code; for
4
+ * deterministic intents with no snippet use hooks_codemod instead.
5
+ */
6
+ import { existsSync, readFileSync, writeFileSync } from 'fs';
7
+ import { resolve, sep } from 'path';
8
+ import { getProjectCwd } from './types.js';
9
+ import { validatePath } from './validate-input.js';
10
+ import { realpathNearest, isInsideRealRoot } from './realpath-containment.js';
11
+ const MAX_INPUT_BYTES = 1_000_000;
12
+ function langForPath(p) {
13
+ const ext = p.slice(p.lastIndexOf('.') + 1).toLowerCase();
14
+ const map = {
15
+ ts: 'typescript', tsx: 'typescript', mts: 'typescript', cts: 'typescript',
16
+ js: 'javascript', jsx: 'javascript', mjs: 'javascript', cjs: 'javascript',
17
+ py: 'python', rs: 'rust', go: 'go', java: 'java', c: 'c', cpp: 'cpp', h: 'c',
18
+ };
19
+ return map[ext];
20
+ }
21
+ export const hooksFastApply = {
22
+ name: 'hooks_fast-apply',
23
+ description: 'Merge an edit SNIPPET (the rewritten code, e.g. a whole new version of one function) into a file or raw code using agent-booster — a local fast-apply engine (~1-10 ms, no LLM, $0). `edit` must be code, not an instruction: "make add typed" fails, "function add(a: number, b: number): number { return a + b; }" works. Use when you already have the replacement code and the surrounding file is large, instead of re-sending the whole file. Deterministic intents (var-to-const, remove-console, add-logging) belong to hooks_codemod. Returns confidence + strategy; below minConfidence nothing is written.',
24
+ inputSchema: {
25
+ type: 'object',
26
+ properties: {
27
+ edit: { type: 'string', description: 'Target code snippet to merge (code, not an instruction)' },
28
+ file: { type: 'string', description: 'Existing file inside the project to patch in place' },
29
+ code: { type: 'string', description: 'Raw source to patch instead of a file (returns output, writes nothing)' },
30
+ language: { type: 'string', description: 'Language hint (inferred from the file extension when omitted)' },
31
+ minConfidence: { type: 'number', description: 'Minimum merge confidence 0-1 required to apply (default 0.5)' },
32
+ dryRun: { type: 'boolean', description: 'Report the merge result without writing the file' },
33
+ },
34
+ required: ['edit'],
35
+ },
36
+ handler: async (params) => {
37
+ const edit = params.edit;
38
+ if (typeof edit !== 'string' || edit.trim() === '')
39
+ return { success: false, error: 'edit (non-empty code snippet) is required' };
40
+ if (edit.length > MAX_INPUT_BYTES)
41
+ return { success: false, error: 'edit too large' };
42
+ const minConfidence = typeof params.minConfidence === 'number'
43
+ ? Math.min(Math.max(params.minConfidence, 0), 1) : 0.5;
44
+ const dryRun = params.dryRun === true;
45
+ const { fastApply } = await import('../ruvector/fast-apply.js');
46
+ if (typeof params.code === 'string') {
47
+ if (params.code.length > MAX_INPUT_BYTES)
48
+ return { success: false, error: 'code too large' };
49
+ const r = await fastApply({ code: params.code, edit, language: params.language, minConfidence });
50
+ return { ...r, mode: 'code', cost: 0 };
51
+ }
52
+ if (typeof params.file !== 'string')
53
+ return { success: false, error: 'Provide `file` or `code`.' };
54
+ const v = validatePath(params.file, 'file');
55
+ if (!v.valid)
56
+ return { success: false, error: v.error };
57
+ const cwd = getProjectCwd();
58
+ const abs = resolve(cwd, v.sanitized);
59
+ if (abs !== cwd && !abs.startsWith(cwd + sep))
60
+ return { success: false, error: `path escapes project root: ${params.file}` };
61
+ let realRoot;
62
+ try {
63
+ realRoot = realpathNearest(cwd);
64
+ }
65
+ catch (err) {
66
+ return { success: false, error: `cannot resolve project root: ${err.message}` };
67
+ }
68
+ if (!isInsideRealRoot(realRoot, abs))
69
+ return { success: false, error: `path escapes project root via symlink: ${params.file}` };
70
+ if (!existsSync(abs))
71
+ return { success: false, error: `file not found: ${params.file}` };
72
+ const before = readFileSync(abs, 'utf-8');
73
+ if (before.length > MAX_INPUT_BYTES)
74
+ return { success: false, error: 'file too large' };
75
+ const language = params.language ?? langForPath(abs);
76
+ const r = await fastApply({ code: before, edit, language, minConfidence });
77
+ const written = r.success && !dryRun;
78
+ if (written)
79
+ writeFileSync(abs, r.output, 'utf-8');
80
+ const { output, ...meta } = r;
81
+ return { ...meta, mode: dryRun ? 'dry-run' : 'file', file: params.file, written, ...(dryRun && { output }), cost: 0 };
82
+ },
83
+ };
84
+ export const fastApplyTools = [hooksFastApply];
85
+ //# sourceMappingURL=fast-apply-tools.js.map
@@ -5,9 +5,10 @@ import { feedbackPatternsSchema, validateFeedbackPatterns } from '../memory/feed
5
5
  */
6
6
  import { mkdirSync, writeFileSync, existsSync, readFileSync, statSync, unlinkSync, readdirSync } from 'fs';
7
7
  import * as nodeFs from 'fs';
8
- import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'path';
8
+ import { dirname, join, resolve, sep } from 'path';
9
9
  import { getProjectCwd } from './types.js';
10
10
  import { validateIdentifier, validateText, validatePath } from './validate-input.js';
11
+ import { realpathNearest, isInsideRealRoot } from './realpath-containment.js';
11
12
  import { commandRecordingDisabled, redactCommandForStorage } from '../services/command-recording.js';
12
13
  import { checkCommandLoop, recordCommandOutcome } from './tool-loop-guardrail.js';
13
14
  import { buildLearnedRoutingPatterns, } from '../services/learned-routing.js';
@@ -5126,38 +5127,6 @@ function codemodLangForExt(abs) {
5126
5127
  return 'javascript';
5127
5128
  return 'typescript';
5128
5129
  }
5129
- // Canonicalize a path that may not exist yet: realpath the nearest existing
5130
- // ancestor and re-attach the missing tail, so a symlinked parent still
5131
- // resolves to its real location (mirrors @claude-flow/security's
5132
- // canonicalizeSync, which is not exported).
5133
- function realpathNearest(p) {
5134
- try {
5135
- return nodeFs.realpathSync(p);
5136
- }
5137
- catch (err) {
5138
- if (err?.code !== 'ENOENT')
5139
- throw err;
5140
- }
5141
- const parent = dirname(p);
5142
- if (parent === p)
5143
- return p;
5144
- return join(realpathNearest(parent), basename(p));
5145
- }
5146
- // CWE-59 (#4346): containment must compare real paths on BOTH sides — a
5147
- // symlink inside the project pointing outside it must not pass, and a
5148
- // symlinked project root (e.g. macOS /var -> /private/var) must not make
5149
- // every path fail. Fails closed if canonicalization throws (ELOOP, EACCES).
5150
- function isInsideRealRoot(realRoot, abs) {
5151
- let real;
5152
- try {
5153
- real = realpathNearest(abs);
5154
- }
5155
- catch {
5156
- return false;
5157
- }
5158
- const rel = relative(realRoot, real);
5159
- return rel === '' || (rel !== '..' && !rel.startsWith('..' + sep) && !isAbsolute(rel));
5160
- }
5161
5130
  // Deterministic codemod execution — the real Tier-1 path (ADR-143)
5162
5131
  export const hooksCodemod = {
5163
5132
  name: 'hooks_codemod',
@@ -399,7 +399,7 @@ export const metaharnessTools = [
399
399
  },
400
400
  // ───────────────────────────────────────────────────────────────────────
401
401
  // ADR-153 — @metaharness/darwin integration (3 tools).
402
- // Backed by the separate `@metaharness/darwin@~0.12.0` npm package, NOT
402
+ // Backed by the separate `@metaharness/darwin@~0.13.0` npm package, NOT
403
403
  // the umbrella `metaharness`. Plugin scripts shell out via _darwin.mjs.
404
404
  // Same {success, data, degraded, exitCode} contract.
405
405
  // ───────────────────────────────────────────────────────────────────────
@@ -0,0 +1,3 @@
1
+ export declare function realpathNearest(p: string): string;
2
+ export declare function isInsideRealRoot(realRoot: string, abs: string): boolean;
3
+ //# sourceMappingURL=realpath-containment.d.ts.map
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Project-root containment for MCP tools that read or write files.
3
+ * Shared by hooks_codemod and hooks_fast-apply (moved out of hooks-tools.ts).
4
+ */
5
+ import * as nodeFs from 'fs';
6
+ import { basename, dirname, isAbsolute, join, relative, sep } from 'path';
7
+ // Canonicalize a path that may not exist yet: realpath the nearest existing
8
+ // ancestor and re-attach the missing tail, so a symlinked parent still
9
+ // resolves to its real location (mirrors @claude-flow/security's
10
+ // canonicalizeSync, which is not exported).
11
+ export function realpathNearest(p) {
12
+ try {
13
+ return nodeFs.realpathSync(p);
14
+ }
15
+ catch (err) {
16
+ if (err?.code !== 'ENOENT')
17
+ throw err;
18
+ }
19
+ const parent = dirname(p);
20
+ if (parent === p)
21
+ return p;
22
+ return join(realpathNearest(parent), basename(p));
23
+ }
24
+ // CWE-59 (#4346): containment must compare real paths on BOTH sides — a
25
+ // symlink inside the project pointing outside it must not pass, and a
26
+ // symlinked project root (e.g. macOS /var -> /private/var) must not make
27
+ // every path fail. Fails closed if canonicalization throws (ELOOP, EACCES).
28
+ export function isInsideRealRoot(realRoot, abs) {
29
+ let real;
30
+ try {
31
+ real = realpathNearest(abs);
32
+ }
33
+ catch {
34
+ return false;
35
+ }
36
+ const rel = relative(realRoot, real);
37
+ return rel === '' || (rel !== '..' && !rel.startsWith('..' + sep) && !isAbsolute(rel));
38
+ }
39
+ //# sourceMappingURL=realpath-containment.js.map
@@ -192,8 +192,8 @@ export declare const inventorySourceSchema: z.ZodObject<{
192
192
  }, "strict", z.ZodTypeAny, {
193
193
  digest: string;
194
194
  sourcePath: string;
195
- channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
196
195
  package: string;
196
+ channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
197
197
  observedInvocation: string;
198
198
  binding: "markdown-loader" | "mod-register" | "mod-middleware-on-markdown";
199
199
  shippedIn: string[];
@@ -201,8 +201,8 @@ export declare const inventorySourceSchema: z.ZodObject<{
201
201
  }, {
202
202
  digest: string;
203
203
  sourcePath: string;
204
- channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
205
204
  package: string;
205
+ channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
206
206
  observedInvocation: string;
207
207
  binding: "markdown-loader" | "mod-register" | "mod-middleware-on-markdown";
208
208
  shippedIn: string[];
@@ -370,8 +370,8 @@ export declare const catalogEntrySchema: z.ZodObject<{
370
370
  }, "strict", z.ZodTypeAny, {
371
371
  digest: string;
372
372
  sourcePath: string;
373
- channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
374
373
  package: string;
374
+ channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
375
375
  observedInvocation: string;
376
376
  binding: "markdown-loader" | "mod-register" | "mod-middleware-on-markdown";
377
377
  shippedIn: string[];
@@ -379,8 +379,8 @@ export declare const catalogEntrySchema: z.ZodObject<{
379
379
  }, {
380
380
  digest: string;
381
381
  sourcePath: string;
382
- channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
383
382
  package: string;
383
+ channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
384
384
  observedInvocation: string;
385
385
  binding: "markdown-loader" | "mod-register" | "mod-middleware-on-markdown";
386
386
  shippedIn: string[];
@@ -391,8 +391,8 @@ export declare const catalogEntrySchema: z.ZodObject<{
391
391
  sources: {
392
392
  digest: string;
393
393
  sourcePath: string;
394
- channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
395
394
  package: string;
395
+ channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
396
396
  observedInvocation: string;
397
397
  binding: "markdown-loader" | "mod-register" | "mod-middleware-on-markdown";
398
398
  shippedIn: string[];
@@ -432,8 +432,8 @@ export declare const catalogEntrySchema: z.ZodObject<{
432
432
  sources: {
433
433
  digest: string;
434
434
  sourcePath: string;
435
- channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
436
435
  package: string;
436
+ channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
437
437
  observedInvocation: string;
438
438
  binding: "markdown-loader" | "mod-register" | "mod-middleware-on-markdown";
439
439
  shippedIn: string[];
@@ -636,8 +636,8 @@ export declare const commandCatalogSchema: z.ZodObject<{
636
636
  }, "strict", z.ZodTypeAny, {
637
637
  digest: string;
638
638
  sourcePath: string;
639
- channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
640
639
  package: string;
640
+ channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
641
641
  observedInvocation: string;
642
642
  binding: "markdown-loader" | "mod-register" | "mod-middleware-on-markdown";
643
643
  shippedIn: string[];
@@ -645,8 +645,8 @@ export declare const commandCatalogSchema: z.ZodObject<{
645
645
  }, {
646
646
  digest: string;
647
647
  sourcePath: string;
648
- channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
649
648
  package: string;
649
+ channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
650
650
  observedInvocation: string;
651
651
  binding: "markdown-loader" | "mod-register" | "mod-middleware-on-markdown";
652
652
  shippedIn: string[];
@@ -657,8 +657,8 @@ export declare const commandCatalogSchema: z.ZodObject<{
657
657
  sources: {
658
658
  digest: string;
659
659
  sourcePath: string;
660
- channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
661
660
  package: string;
661
+ channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
662
662
  observedInvocation: string;
663
663
  binding: "markdown-loader" | "mod-register" | "mod-middleware-on-markdown";
664
664
  shippedIn: string[];
@@ -698,8 +698,8 @@ export declare const commandCatalogSchema: z.ZodObject<{
698
698
  sources: {
699
699
  digest: string;
700
700
  sourcePath: string;
701
- channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
702
701
  package: string;
702
+ channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
703
703
  observedInvocation: string;
704
704
  binding: "markdown-loader" | "mod-register" | "mod-middleware-on-markdown";
705
705
  shippedIn: string[];
@@ -741,8 +741,8 @@ export declare const commandCatalogSchema: z.ZodObject<{
741
741
  sources: {
742
742
  digest: string;
743
743
  sourcePath: string;
744
- channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
745
744
  package: string;
745
+ channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
746
746
  observedInvocation: string;
747
747
  binding: "markdown-loader" | "mod-register" | "mod-middleware-on-markdown";
748
748
  shippedIn: string[];
@@ -787,8 +787,8 @@ export declare const commandCatalogSchema: z.ZodObject<{
787
787
  sources: {
788
788
  digest: string;
789
789
  sourcePath: string;
790
- channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
791
790
  package: string;
791
+ channel: "repo-project-commands" | "cli-init-template" | "marketplace-plugin" | "source-plugin" | "mod-registration";
792
792
  observedInvocation: string;
793
793
  binding: "markdown-loader" | "mod-register" | "mod-middleware-on-markdown";
794
794
  shippedIn: string[];
@@ -40,8 +40,7 @@ export interface ASTAnalysis {
40
40
  }
41
41
  export declare class ASTAnalyzer {
42
42
  private config;
43
- private ruvectorEngine;
44
- private useNative;
43
+ private readonly useNative;
45
44
  private analysisCache;
46
45
  constructor(config?: Partial<ASTAnalyzerConfig>);
47
46
  initialize(): Promise<void>;