claude-flow 3.72.0 → 3.72.2

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 (55) hide show
  1. package/.claude/proven-config.json +1 -1
  2. package/.claude-plugin/marketplace.json +6 -6
  3. package/node_modules/@claude-flow/codex/.agents/skills/fast-code-edits/SKILL.md +42 -0
  4. package/node_modules/@claude-flow/codex/.agents/skills/graph-mincut/SKILL.md +42 -0
  5. package/node_modules/@claude-flow/codex/.agents/skills/injection-defense/SKILL.md +45 -0
  6. package/node_modules/@claude-flow/codex/.agents/skills/lora-learning/SKILL.md +39 -0
  7. package/node_modules/@claude-flow/codex/.agents/skills/sublinear-solver/SKILL.md +38 -0
  8. package/node_modules/@claude-flow/codex/.agents/skills/vector-quantization/SKILL.md +49 -0
  9. package/node_modules/@claude-flow/codex/dist/generators/skill-md.d.ts.map +1 -1
  10. package/node_modules/@claude-flow/codex/dist/generators/skill-md.js +6 -0
  11. package/node_modules/@claude-flow/codex/dist/generators/skill-md.js.map +1 -1
  12. package/node_modules/@claude-flow/codex/dist/index.d.ts +3 -3
  13. package/node_modules/@claude-flow/codex/dist/index.js +1 -1
  14. package/node_modules/@claude-flow/codex/dist/templates/index.d.ts.map +1 -1
  15. package/node_modules/@claude-flow/codex/dist/templates/index.js +37 -0
  16. package/node_modules/@claude-flow/codex/dist/templates/index.js.map +1 -1
  17. package/node_modules/@claude-flow/codex/dist/types.d.ts +1 -1
  18. package/node_modules/@claude-flow/codex/dist/types.d.ts.map +1 -1
  19. package/node_modules/@claude-flow/codex/package.json +1 -1
  20. package/package.json +13 -10
  21. package/v3/@claude-flow/cli/catalog-manifest.json +4 -4
  22. package/v3/@claude-flow/cli/dist/src/appliance/ruvllm-bridge.d.ts +6 -2
  23. package/v3/@claude-flow/cli/dist/src/appliance/ruvllm-bridge.js +13 -8
  24. package/v3/@claude-flow/cli/dist/src/commands/init.js +2 -0
  25. package/v3/@claude-flow/cli/dist/src/commands/neural.js +81 -71
  26. package/v3/@claude-flow/cli/dist/src/init/executor.js +13 -0
  27. package/v3/@claude-flow/cli/dist/src/init/types.d.ts +6 -0
  28. package/v3/@claude-flow/cli/dist/src/init/types.js +3 -0
  29. package/v3/@claude-flow/cli/dist/src/mcp-client.js +2 -0
  30. package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-tools.js +34 -2
  31. package/v3/@claude-flow/cli/dist/src/mcp-tools/browser-session-tools.d.ts +2 -2
  32. package/v3/@claude-flow/cli/dist/src/mcp-tools/browser-session-tools.js +4 -4
  33. package/v3/@claude-flow/cli/dist/src/mcp-tools/fast-apply-tools.d.ts +4 -0
  34. package/v3/@claude-flow/cli/dist/src/mcp-tools/fast-apply-tools.js +85 -0
  35. package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +19 -34
  36. package/v3/@claude-flow/cli/dist/src/mcp-tools/metaharness-tools.js +1 -1
  37. package/v3/@claude-flow/cli/dist/src/mcp-tools/neural-tools.js +3 -3
  38. package/v3/@claude-flow/cli/dist/src/mcp-tools/realpath-containment.d.ts +3 -0
  39. package/v3/@claude-flow/cli/dist/src/mcp-tools/realpath-containment.js +39 -0
  40. package/v3/@claude-flow/cli/dist/src/mods/command-registry/schema.d.ts +12 -12
  41. package/v3/@claude-flow/cli/dist/src/ruvector/ast-analyzer.d.ts +1 -2
  42. package/v3/@claude-flow/cli/dist/src/ruvector/ast-analyzer.js +4 -12
  43. package/v3/@claude-flow/cli/dist/src/ruvector/coverage-router.d.ts +1 -2
  44. package/v3/@claude-flow/cli/dist/src/ruvector/coverage-router.js +4 -12
  45. package/v3/@claude-flow/cli/dist/src/ruvector/diff-classifier.d.ts +1 -2
  46. package/v3/@claude-flow/cli/dist/src/ruvector/diff-classifier.js +3 -12
  47. package/v3/@claude-flow/cli/dist/src/ruvector/fast-apply.d.ts +46 -0
  48. package/v3/@claude-flow/cli/dist/src/ruvector/fast-apply.js +73 -0
  49. package/v3/@claude-flow/cli/dist/src/ruvector/graph-analyzer.d.ts +11 -1
  50. package/v3/@claude-flow/cli/dist/src/ruvector/graph-analyzer.js +22 -36
  51. package/v3/@claude-flow/cli/dist/src/ruvector/mincut-bridge.d.ts +70 -0
  52. package/v3/@claude-flow/cli/dist/src/ruvector/mincut-bridge.js +172 -0
  53. package/v3/@claude-flow/cli/dist/src/services/distill-oracle.d.ts +1 -1
  54. package/v3/@claude-flow/cli/dist/src/services/distill-oracle.js +2 -2
  55. package/v3/@claude-flow/cli/package.json +12 -10
@@ -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>;
@@ -22,24 +22,16 @@ const LANGUAGE_PATTERNS = {
22
22
  };
23
23
  export class ASTAnalyzer {
24
24
  config;
25
- ruvectorEngine = null;
26
25
  useNative = false;
27
26
  analysisCache = new Map();
28
27
  constructor(config = {}) {
29
28
  this.config = { ...DEFAULT_CONFIG, ...config };
30
29
  }
31
30
  async initialize() {
32
- try {
33
- // @ruvector/ast is optional - gracefully fallback if not installed
34
- const ruvector = await import('@ruvector/ast').catch(() => null);
35
- if (ruvector) {
36
- this.ruvectorEngine = ruvector.createASTAnalyzer?.(this.config);
37
- this.useNative = !!this.ruvectorEngine;
38
- }
39
- }
40
- catch {
41
- this.useNative = false;
42
- }
31
+ // Pure-JS analysis. This used to try `import('@ruvector/ast')`, a package that has
32
+ // never been published (npm 404), so it always fell through to here. ruvector@0.3's
33
+ // ASTParser needs the native tree-sitter grammars and is async-only, so it cannot
34
+ // back this synchronous analyzer.
43
35
  }
44
36
  analyze(code, filePath = 'unknown') {
45
37
  const startTime = performance.now();
@@ -63,8 +63,7 @@ export interface CoverageRouteResult {
63
63
  }
64
64
  export declare class CoverageRouter {
65
65
  private config;
66
- private ruvectorEngine;
67
- private useNative;
66
+ private readonly useNative;
68
67
  private coverageHistory;
69
68
  constructor(config?: Partial<CoverageRouterConfig>);
70
69
  initialize(): Promise<void>;
@@ -37,24 +37,16 @@ const DEFAULT_CONFIG = {
37
37
  };
38
38
  export class CoverageRouter {
39
39
  config;
40
- ruvectorEngine = null;
41
40
  useNative = false;
42
41
  coverageHistory = [];
43
42
  constructor(config = {}) {
44
43
  this.config = { ...DEFAULT_CONFIG, ...config };
45
44
  }
46
45
  async initialize() {
47
- try {
48
- // @ruvector/coverage is optional - gracefully fallback if not installed
49
- const ruvector = await import('@ruvector/coverage').catch(() => null);
50
- if (ruvector) {
51
- this.ruvectorEngine = ruvector.createCoverageRouter?.(this.config);
52
- this.useNative = !!this.ruvectorEngine;
53
- }
54
- }
55
- catch {
56
- this.useNative = false;
57
- }
46
+ // Pure-JS analysis. This used to try `import('@ruvector/coverage')`, a package that
47
+ // has never been published (npm 404), so it always fell through to here.
48
+ // ruvector@0.3's parseIstanbulCoverage is a plain-JS parser equivalent to the parsers
49
+ // below.
58
50
  }
59
51
  parseCoverage(data, format = 'json') {
60
52
  switch (format) {
@@ -49,8 +49,7 @@ export interface DiffAnalysis {
49
49
  }
50
50
  export declare class DiffClassifier {
51
51
  private config;
52
- private ruvectorEngine;
53
- private useNative;
52
+ private readonly useNative;
54
53
  private classificationCache;
55
54
  constructor(config?: Partial<DiffClassifierConfig>);
56
55
  initialize(): Promise<void>;
@@ -60,24 +60,15 @@ function isSecuritySensitivePath(path) {
60
60
  }
61
61
  export class DiffClassifier {
62
62
  config;
63
- ruvectorEngine = null;
64
63
  useNative = false;
65
64
  classificationCache = new Map();
66
65
  constructor(config = {}) {
67
66
  this.config = { ...DEFAULT_CONFIG, ...config };
68
67
  }
69
68
  async initialize() {
70
- try {
71
- // @ruvector/diff is optional - gracefully fallback if not installed
72
- const ruvector = await import('@ruvector/diff').catch(() => null);
73
- if (ruvector) {
74
- this.ruvectorEngine = ruvector.createDiffClassifier?.(this.config);
75
- this.useNative = !!this.ruvectorEngine;
76
- }
77
- }
78
- catch {
79
- this.useNative = false;
80
- }
69
+ // Pure-JS analysis. This used to try `import('@ruvector/diff')`, a package that has
70
+ // never been published (npm 404), so it always fell through to here. ruvector@0.3's
71
+ // parseDiff is a plain-JS parser equivalent to parseDiff() below.
81
72
  }
82
73
  parseDiff(diffContent) {
83
74
  const files = [];
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Fast-apply: merge an edit snippet into existing code with agent-booster.
3
+ *
4
+ * agent-booster is a Morph/Cursor-style *applier*: `apply({ code, edit })`
5
+ * expects `edit` to be the target code (e.g. the rewritten function), and it
6
+ * locates and splices it into `code` in a few milliseconds with no LLM call.
7
+ * It cannot turn a natural-language instruction into an edit — given one it
8
+ * returns `success: false, strategy: "failed"` (see ADR-143). So this is the
9
+ * path for callers that already hold a snippet (an agent's proposed rewrite),
10
+ * not a Tier-1 intent engine; deterministic intents stay in hooks_codemod.
11
+ */
12
+ export interface FastApplyRequest {
13
+ code: string;
14
+ edit: string;
15
+ language?: string;
16
+ /** Results below this confidence are reported as not applied. Default 0.5. */
17
+ minConfidence?: number;
18
+ }
19
+ export interface FastApplyResult {
20
+ success: boolean;
21
+ output: string;
22
+ confidence: number;
23
+ strategy: string;
24
+ latencyMs: number;
25
+ backend: 'agent-booster' | 'unavailable';
26
+ reason?: string;
27
+ }
28
+ interface BoosterLike {
29
+ apply(req: {
30
+ code: string;
31
+ edit: string;
32
+ language?: string;
33
+ }): Promise<{
34
+ output: string;
35
+ success: boolean;
36
+ confidence: number;
37
+ strategy: string;
38
+ }>;
39
+ }
40
+ /** Lazily construct one AgentBooster. Resolves null when it is not installed. */
41
+ export declare function loadAgentBooster(): Promise<BoosterLike | null>;
42
+ /** Test hook: forget the memoised AgentBooster. */
43
+ export declare function resetAgentBoosterLoader(): void;
44
+ export declare function fastApply(req: FastApplyRequest): Promise<FastApplyResult>;
45
+ export {};
46
+ //# sourceMappingURL=fast-apply.d.ts.map
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Fast-apply: merge an edit snippet into existing code with agent-booster.
3
+ *
4
+ * agent-booster is a Morph/Cursor-style *applier*: `apply({ code, edit })`
5
+ * expects `edit` to be the target code (e.g. the rewritten function), and it
6
+ * locates and splices it into `code` in a few milliseconds with no LLM call.
7
+ * It cannot turn a natural-language instruction into an edit — given one it
8
+ * returns `success: false, strategy: "failed"` (see ADR-143). So this is the
9
+ * path for callers that already hold a snippet (an agent's proposed rewrite),
10
+ * not a Tier-1 intent engine; deterministic intents stay in hooks_codemod.
11
+ */
12
+ let boosterPromise = null;
13
+ /** Lazily construct one AgentBooster. Resolves null when it is not installed. */
14
+ export function loadAgentBooster() {
15
+ if (!boosterPromise) {
16
+ boosterPromise = (async () => {
17
+ try {
18
+ const specifier = 'agent-booster';
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- optional dep
20
+ const mod = await import(specifier);
21
+ const Ctor = mod?.AgentBooster ?? mod?.default?.AgentBooster ?? mod?.default;
22
+ if (typeof Ctor !== 'function')
23
+ return null;
24
+ // Our own threshold is applied below; let the engine report everything.
25
+ return new Ctor({ confidenceThreshold: 0 });
26
+ }
27
+ catch {
28
+ return null;
29
+ }
30
+ })();
31
+ }
32
+ return boosterPromise;
33
+ }
34
+ /** Test hook: forget the memoised AgentBooster. */
35
+ export function resetAgentBoosterLoader() {
36
+ boosterPromise = null;
37
+ }
38
+ export async function fastApply(req) {
39
+ const start = performance.now();
40
+ const minConfidence = req.minConfidence ?? 0.5;
41
+ const booster = await loadAgentBooster();
42
+ if (!booster) {
43
+ return {
44
+ success: false, output: req.code, confidence: 0, strategy: 'none',
45
+ latencyMs: performance.now() - start, backend: 'unavailable',
46
+ reason: 'agent-booster is not installed (npm i agent-booster); apply the edit with the Edit tool instead',
47
+ };
48
+ }
49
+ try {
50
+ const r = await booster.apply({ code: req.code, edit: req.edit, language: req.language });
51
+ const applied = r.success && r.confidence >= minConfidence && r.output !== req.code;
52
+ return {
53
+ success: applied,
54
+ output: applied ? r.output : req.code,
55
+ confidence: r.confidence,
56
+ strategy: r.strategy,
57
+ latencyMs: performance.now() - start,
58
+ backend: 'agent-booster',
59
+ reason: applied ? undefined
60
+ : !r.success ? 'agent-booster could not place the snippet (it must be code, not an instruction)'
61
+ : r.output === req.code ? 'snippet is already present; nothing to change'
62
+ : `confidence ${r.confidence.toFixed(2)} below minConfidence ${minConfidence}`,
63
+ };
64
+ }
65
+ catch (err) {
66
+ return {
67
+ success: false, output: req.code, confidence: 0, strategy: 'error',
68
+ latencyMs: performance.now() - start, backend: 'agent-booster',
69
+ reason: `agent-booster threw: ${err.message}`,
70
+ };
71
+ }
72
+ }
73
+ //# sourceMappingURL=fast-apply.js.map
@@ -121,9 +121,19 @@ interface IRuVectorGraph {
121
121
  };
122
122
  }
123
123
  /**
124
- * Attempt to load ruvector graph algorithms
124
+ * Load the accelerated graph backend.
125
+ *
126
+ * MinCut runs on ruvector's `DynamicMinCut` (the `@ruvector/mincut-wasm`
127
+ * solver ruvector ships as an optional dependency), see mincut-bridge.ts.
128
+ * Inputs the wasm solver cannot describe (isolated nodes, no edges) and
129
+ * Louvain go to the built-in JS implementations — ruvector's own
130
+ * `louvainCommunities` is plain JS too, so there is nothing to gain there.
131
+ * Returns null when the wasm solver is unavailable; callers then use the
132
+ * built-in Stoer-Wagner `fallbackMinCut`.
125
133
  */
126
134
  declare function loadRuVector(): Promise<IRuVectorGraph | null>;
135
+ /** Which MinCut backend `analyzeMinCutBoundaries` will use. */
136
+ export declare function getMinCutBackend(): Promise<'mincut-wasm' | 'stoer-wagner'>;
127
137
  /**
128
138
  * Build dependency graph from source directory (with caching)
129
139
  */
@@ -12,6 +12,7 @@
12
12
  * @module @claude-flow/cli/ruvector/graph-analyzer
13
13
  */
14
14
  import { readFile, readdir, stat } from 'fs/promises';
15
+ import { loadWasmMinCut, minCutWith } from './mincut-bridge.js';
15
16
  import { join, relative, extname, dirname, basename } from 'path';
16
17
  // ============================================================================
17
18
  // Caching for Performance
@@ -45,47 +46,32 @@ export function getGraphCacheStats() {
45
46
  let ruVectorGraph = null;
46
47
  let ruVectorLoadAttempted = false;
47
48
  /**
48
- * Attempt to load ruvector graph algorithms
49
+ * Load the accelerated graph backend.
50
+ *
51
+ * MinCut runs on ruvector's `DynamicMinCut` (the `@ruvector/mincut-wasm`
52
+ * solver ruvector ships as an optional dependency), see mincut-bridge.ts.
53
+ * Inputs the wasm solver cannot describe (isolated nodes, no edges) and
54
+ * Louvain go to the built-in JS implementations — ruvector's own
55
+ * `louvainCommunities` is plain JS too, so there is nothing to gain there.
56
+ * Returns null when the wasm solver is unavailable; callers then use the
57
+ * built-in Stoer-Wagner `fallbackMinCut`.
49
58
  */
50
59
  async function loadRuVector() {
51
60
  if (ruVectorLoadAttempted)
52
61
  return ruVectorGraph;
53
62
  ruVectorLoadAttempted = true;
54
- // Use dynamic module names to bypass TypeScript static analysis
55
- // These modules are optional and may not be installed
56
- const ruvectorModule = 'ruvector';
57
- const wasmModule = '@ruvector/wasm';
58
- try {
59
- // Try to load ruvector's graph module
60
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
- const ruvector = await import(/* webpackIgnore: true */ ruvectorModule).catch(() => null);
62
- if (ruvector && typeof ruvector.hooks_graph_mincut === 'function' && typeof ruvector.hooks_graph_cluster === 'function') {
63
- ruVectorGraph = {
64
- mincut: (nodes, edges) => ruvector.hooks_graph_mincut(nodes, edges),
65
- louvain: (nodes, edges) => ruvector.hooks_graph_cluster(nodes, edges),
66
- };
67
- return ruVectorGraph;
68
- }
69
- }
70
- catch {
71
- // Try alternative import paths
72
- try {
73
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
- const wasm = await import(/* webpackIgnore: true */ wasmModule).catch(() => null);
75
- if (wasm && wasm.GraphAnalyzer) {
76
- const analyzer = new wasm.GraphAnalyzer();
77
- ruVectorGraph = {
78
- mincut: (nodes, edges) => analyzer.mincut(nodes, edges),
79
- louvain: (nodes, edges) => analyzer.louvain(nodes, edges),
80
- };
81
- return ruVectorGraph;
82
- }
83
- }
84
- catch {
85
- // Fallback will be used
86
- }
87
- }
88
- return null;
63
+ const Ctor = await loadWasmMinCut();
64
+ if (!Ctor)
65
+ return null;
66
+ ruVectorGraph = {
67
+ mincut: (nodes, edges) => minCutWith(Ctor, nodes, edges) ?? fallbackMinCut(nodes, edges),
68
+ louvain: (nodes, edges) => fallbackLouvain(nodes, edges),
69
+ };
70
+ return ruVectorGraph;
71
+ }
72
+ /** Which MinCut backend `analyzeMinCutBoundaries` will use. */
73
+ export async function getMinCutBackend() {
74
+ return (await loadRuVector()) ? 'mincut-wasm' : 'stoer-wagner';
89
75
  }
90
76
  // ============================================================================
91
77
  // Import/Require Parser
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Exact global minimum cut over an undirected weighted graph.
3
+ *
4
+ * Fast path: `ruvector`'s `DynamicMinCut`, a wrapper over the
5
+ * `@ruvector/mincut-wasm` solver that ruvector ships as one of its own
6
+ * optional dependencies. Measured on a 1,000-node / 2,000-edge graph it is
7
+ * ~30x faster than a JS Stoer-Wagner (187 ms vs 6 s) and returns the same cut
8
+ * value. When ruvector or its wasm solver is not installed, callers fall back
9
+ * to their own JS implementation (`fallbackMinCut` in graph-analyzer.ts).
10
+ *
11
+ * The wasm solver rejects duplicate edges ("Edge already exists"), so edges are
12
+ * folded into one undirected edge per node pair with summed weight, and
13
+ * self-loops are dropped (they never cross a cut).
14
+ */
15
+ export interface MinCutResult {
16
+ cutValue: number;
17
+ partition1: string[];
18
+ partition2: string[];
19
+ cutEdges: Array<[string, string]>;
20
+ }
21
+ export type MinCutBackend = 'mincut-wasm' | 'js-fallback';
22
+ interface DynamicMinCutLike {
23
+ insertEdge(from: string, to: string, weight?: number): number;
24
+ minCutValue(): number;
25
+ partition(): string[][];
26
+ }
27
+ export type DynamicMinCutCtor = new () => DynamicMinCutLike;
28
+ /**
29
+ * Resolve ruvector's `DynamicMinCut` once. Returns null (never throws) when
30
+ * ruvector is absent or its `@ruvector/mincut-wasm` solver cannot load.
31
+ */
32
+ export declare function loadWasmMinCut(): Promise<DynamicMinCutCtor | null>;
33
+ /** Test hook: forget the memoised loader result. */
34
+ export declare function resetMinCutLoader(): void;
35
+ /**
36
+ * Compute the exact minimum cut with the wasm solver. Returns null when the
37
+ * solver is unavailable or the input is degenerate (fewer than two nodes, no
38
+ * edges, or nodes with no incident edge — an isolated node is a zero-weight
39
+ * cut that the solver never sees, so the JS fallback answers those).
40
+ */
41
+ export declare function wasmMinCut(nodes: string[], edges: Array<[string, string, number]>): Promise<MinCutResult | null>;
42
+ /** Synchronous variant for callers that already hold the loaded solver class. */
43
+ export declare function minCutWith(Ctor: DynamicMinCutCtor, nodes: string[], edges: Array<[string, string, number]>): MinCutResult | null;
44
+ export interface SeedMinCutResult {
45
+ /** Nodes on the seed's side of the cut, nearest (fewest hops) first. */
46
+ seedSide: Array<{
47
+ nodeId: string;
48
+ depth: number;
49
+ }>;
50
+ otherSide: string[];
51
+ cutValue: number;
52
+ cutEdges: Array<[string, string]>;
53
+ backend: MinCutBackend;
54
+ /** Size of the seed's depth-bounded neighbourhood the cut was computed on. */
55
+ subgraphNodes: number;
56
+ }
57
+ /** Above this many nodes the O(n^3) JS fallback is not attempted. */
58
+ export declare const JS_FALLBACK_MAX_NODES = 300;
59
+ /**
60
+ * Minimum cut of the seed's `depth`-hop neighbourhood (edges treated as
61
+ * undirected, at most `maxNodes` nodes). Answers "where is the weakest
62
+ * boundary around this node, and what sits on its side of it?".
63
+ *
64
+ * Uses the wasm solver when available, else `fallback` (a JS exact min cut)
65
+ * for neighbourhoods up to JS_FALLBACK_MAX_NODES nodes. Returns null when the
66
+ * seed has no neighbours or no backend can handle the neighbourhood.
67
+ */
68
+ export declare function seedLocalMinCut(seed: string, edges: Array<[string, string, number]>, depth: number, maxNodes: number, fallback: (nodes: string[], edges: Array<[string, string, number]>) => MinCutResult): Promise<SeedMinCutResult | null>;
69
+ export {};
70
+ //# sourceMappingURL=mincut-bridge.d.ts.map