claude-flow 3.71.4 → 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 (118) hide show
  1. package/.claude/helpers/hook-handler.cjs +23 -10
  2. package/.claude/helpers/statusline.cjs +29 -14
  3. package/README.md +18 -3
  4. package/README.zh-CN.md +16 -3
  5. package/node_modules/@claude-flow/codex/.agents/skills/fast-code-edits/SKILL.md +42 -0
  6. package/node_modules/@claude-flow/codex/.agents/skills/graph-mincut/SKILL.md +42 -0
  7. package/node_modules/@claude-flow/codex/.agents/skills/injection-defense/SKILL.md +45 -0
  8. package/node_modules/@claude-flow/codex/.agents/skills/lora-learning/SKILL.md +39 -0
  9. package/node_modules/@claude-flow/codex/.agents/skills/sublinear-solver/SKILL.md +38 -0
  10. package/node_modules/@claude-flow/codex/.agents/skills/vector-quantization/SKILL.md +49 -0
  11. package/node_modules/@claude-flow/codex/dist/generators/skill-md.d.ts.map +1 -1
  12. package/node_modules/@claude-flow/codex/dist/generators/skill-md.js +6 -0
  13. package/node_modules/@claude-flow/codex/dist/generators/skill-md.js.map +1 -1
  14. package/node_modules/@claude-flow/codex/dist/index.d.ts +3 -3
  15. package/node_modules/@claude-flow/codex/dist/index.js +1 -1
  16. package/node_modules/@claude-flow/codex/dist/templates/index.d.ts.map +1 -1
  17. package/node_modules/@claude-flow/codex/dist/templates/index.js +37 -0
  18. package/node_modules/@claude-flow/codex/dist/templates/index.js.map +1 -1
  19. package/node_modules/@claude-flow/codex/dist/types.d.ts +1 -1
  20. package/node_modules/@claude-flow/codex/dist/types.d.ts.map +1 -1
  21. package/node_modules/@claude-flow/codex/package.json +1 -1
  22. package/package.json +9 -6
  23. package/v3/@claude-flow/cli/README.md +18 -3
  24. package/v3/@claude-flow/cli/bin/cli.js +13 -18
  25. package/v3/@claude-flow/cli/bin/mcp-server.js +13 -18
  26. package/v3/@claude-flow/cli/catalog-manifest.json +4 -4
  27. package/v3/@claude-flow/cli/dist/src/appliance/ruvllm-bridge.d.ts +6 -2
  28. package/v3/@claude-flow/cli/dist/src/appliance/ruvllm-bridge.js +13 -8
  29. package/v3/@claude-flow/cli/dist/src/appliance/rvfa-distribution.js +2 -2
  30. package/v3/@claude-flow/cli/dist/src/benchmarks/gaia-critic.d.ts +1 -7
  31. package/v3/@claude-flow/cli/dist/src/benchmarks/gaia-critic.js +1 -7
  32. package/v3/@claude-flow/cli/dist/src/benchmarks/gaia-decomposer.d.ts +1 -8
  33. package/v3/@claude-flow/cli/dist/src/benchmarks/gaia-decomposer.js +1 -8
  34. package/v3/@claude-flow/cli/dist/src/commands/agent-wasm.js +2 -2
  35. package/v3/@claude-flow/cli/dist/src/commands/analyze.js +1 -1
  36. package/v3/@claude-flow/cli/dist/src/commands/daemon.js +1 -1
  37. package/v3/@claude-flow/cli/dist/src/commands/doctor.js +3 -2
  38. package/v3/@claude-flow/cli/dist/src/commands/guidance.js +9 -9
  39. package/v3/@claude-flow/cli/dist/src/commands/hooks.js +13 -8
  40. package/v3/@claude-flow/cli/dist/src/commands/init.js +16 -16
  41. package/v3/@claude-flow/cli/dist/src/commands/neural.js +87 -77
  42. package/v3/@claude-flow/cli/dist/src/commands/route.js +1 -1
  43. package/v3/@claude-flow/cli/dist/src/commands/ruvector/backup.js +7 -5
  44. package/v3/@claude-flow/cli/dist/src/commands/ruvector/benchmark.js +6 -1
  45. package/v3/@claude-flow/cli/dist/src/commands/ruvector/import.js +19 -5
  46. package/v3/@claude-flow/cli/dist/src/commands/ruvector/init.js +1 -1
  47. package/v3/@claude-flow/cli/dist/src/commands/start.js +1 -1
  48. package/v3/@claude-flow/cli/dist/src/commands/status.js +1 -1
  49. package/v3/@claude-flow/cli/dist/src/commands/task.js +18 -1
  50. package/v3/@claude-flow/cli/dist/src/commands/update.js +1 -1
  51. package/v3/@claude-flow/cli/dist/src/funnel/local-signals.js +7 -2
  52. package/v3/@claude-flow/cli/dist/src/init/executor.js +13 -0
  53. package/v3/@claude-flow/cli/dist/src/init/types.d.ts +6 -0
  54. package/v3/@claude-flow/cli/dist/src/init/types.js +3 -0
  55. package/v3/@claude-flow/cli/dist/src/mcp-client.js +2 -0
  56. package/v3/@claude-flow/cli/dist/src/mcp-protocol.d.ts +90 -0
  57. package/v3/@claude-flow/cli/dist/src/mcp-protocol.js +179 -0
  58. package/v3/@claude-flow/cli/dist/src/mcp-server.d.ts +1 -0
  59. package/v3/@claude-flow/cli/dist/src/mcp-server.js +20 -22
  60. package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-execute-core.js +9 -1
  61. package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-tools.d.ts +13 -0
  62. package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-tools.js +59 -8
  63. package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-tools.js +34 -2
  64. package/v3/@claude-flow/cli/dist/src/mcp-tools/browser-argv.d.ts +9 -0
  65. package/v3/@claude-flow/cli/dist/src/mcp-tools/browser-argv.js +33 -0
  66. package/v3/@claude-flow/cli/dist/src/mcp-tools/browser-session-tools.js +4 -0
  67. package/v3/@claude-flow/cli/dist/src/mcp-tools/browser-tools.js +12 -2
  68. package/v3/@claude-flow/cli/dist/src/mcp-tools/coordination-tools.js +5 -4
  69. package/v3/@claude-flow/cli/dist/src/mcp-tools/embeddings-tools.js +12 -4
  70. package/v3/@claude-flow/cli/dist/src/mcp-tools/fast-apply-tools.d.ts +4 -0
  71. package/v3/@claude-flow/cli/dist/src/mcp-tools/fast-apply-tools.js +85 -0
  72. package/v3/@claude-flow/cli/dist/src/mcp-tools/glob-exclusions.d.ts +6 -0
  73. package/v3/@claude-flow/cli/dist/src/mcp-tools/glob-exclusions.js +81 -0
  74. package/v3/@claude-flow/cli/dist/src/mcp-tools/hive-mind-tools.js +104 -35
  75. package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +14 -38
  76. package/v3/@claude-flow/cli/dist/src/mcp-tools/import-limits.d.ts +4 -0
  77. package/v3/@claude-flow/cli/dist/src/mcp-tools/import-limits.js +28 -0
  78. package/v3/@claude-flow/cli/dist/src/mcp-tools/memory-tools.js +21 -42
  79. package/v3/@claude-flow/cli/dist/src/mcp-tools/metaharness-tools.js +1 -1
  80. package/v3/@claude-flow/cli/dist/src/mcp-tools/performance-tools.js +7 -2
  81. package/v3/@claude-flow/cli/dist/src/mcp-tools/realpath-containment.d.ts +3 -0
  82. package/v3/@claude-flow/cli/dist/src/mcp-tools/realpath-containment.js +39 -0
  83. package/v3/@claude-flow/cli/dist/src/mcp-tools/record-store.d.ts +8 -0
  84. package/v3/@claude-flow/cli/dist/src/mcp-tools/record-store.js +98 -1
  85. package/v3/@claude-flow/cli/dist/src/mcp-tools/security-tools.d.ts +9 -0
  86. package/v3/@claude-flow/cli/dist/src/mcp-tools/security-tools.js +39 -3
  87. package/v3/@claude-flow/cli/dist/src/mcp-tools/session-tools.js +5 -3
  88. package/v3/@claude-flow/cli/dist/src/mcp-tools/swarm-tools.js +35 -17
  89. package/v3/@claude-flow/cli/dist/src/mcp-tools/task-tools.js +68 -5
  90. package/v3/@claude-flow/cli/dist/src/mcp-tools/terminal-tools.js +9 -0
  91. package/v3/@claude-flow/cli/dist/src/mcp-tools/workflow-tools.js +13 -12
  92. package/v3/@claude-flow/cli/dist/src/mcp-tools/x-federation-join.js +55 -14
  93. package/v3/@claude-flow/cli/dist/src/memory/intelligence.d.ts +11 -0
  94. package/v3/@claude-flow/cli/dist/src/memory/intelligence.js +84 -6
  95. package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.d.ts +6 -2
  96. package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.js +15 -6
  97. package/v3/@claude-flow/cli/dist/src/mods/command-registry/schema.d.ts +12 -12
  98. package/v3/@claude-flow/cli/dist/src/ruvector/ast-analyzer.d.ts +1 -2
  99. package/v3/@claude-flow/cli/dist/src/ruvector/ast-analyzer.js +4 -12
  100. package/v3/@claude-flow/cli/dist/src/ruvector/coverage-router.d.ts +1 -2
  101. package/v3/@claude-flow/cli/dist/src/ruvector/coverage-router.js +4 -12
  102. package/v3/@claude-flow/cli/dist/src/ruvector/diff-classifier.d.ts +1 -2
  103. package/v3/@claude-flow/cli/dist/src/ruvector/diff-classifier.js +3 -12
  104. package/v3/@claude-flow/cli/dist/src/ruvector/fast-apply.d.ts +46 -0
  105. package/v3/@claude-flow/cli/dist/src/ruvector/fast-apply.js +73 -0
  106. package/v3/@claude-flow/cli/dist/src/ruvector/graph-analyzer.d.ts +11 -1
  107. package/v3/@claude-flow/cli/dist/src/ruvector/graph-analyzer.js +22 -36
  108. package/v3/@claude-flow/cli/dist/src/ruvector/mincut-bridge.d.ts +70 -0
  109. package/v3/@claude-flow/cli/dist/src/ruvector/mincut-bridge.js +172 -0
  110. package/v3/@claude-flow/cli/dist/src/ruvector/model-router.d.ts +6 -1
  111. package/v3/@claude-flow/cli/dist/src/ruvector/model-router.js +16 -4
  112. package/v3/@claude-flow/cli/dist/src/services/distill-oracle.d.ts +1 -1
  113. package/v3/@claude-flow/cli/dist/src/services/distill-oracle.js +2 -2
  114. package/v3/@claude-flow/cli/dist/src/services/worker-daemon.js +30 -12
  115. package/v3/@claude-flow/cli/dist/src/transfer/storage/gcs.js +3 -2
  116. package/v3/@claude-flow/cli/package.json +11 -9
  117. package/.claude/.proven-config-version +0 -1
  118. package/.claude/proven-config.json +0 -42
@@ -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
@@ -0,0 +1,172 @@
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
+ let ctorPromise = null;
16
+ /**
17
+ * Resolve ruvector's `DynamicMinCut` once. Returns null (never throws) when
18
+ * ruvector is absent or its `@ruvector/mincut-wasm` solver cannot load.
19
+ */
20
+ export function loadWasmMinCut() {
21
+ if (!ctorPromise) {
22
+ ctorPromise = (async () => {
23
+ try {
24
+ const specifier = 'ruvector';
25
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- optional dep
26
+ const mod = await import(specifier);
27
+ const rv = mod?.DynamicMinCut ? mod : mod?.default;
28
+ if (typeof rv?.DynamicMinCut !== 'function')
29
+ return null;
30
+ if (typeof rv.isMinCutWasmAvailable === 'function' && !rv.isMinCutWasmAvailable())
31
+ return null;
32
+ return rv.DynamicMinCut;
33
+ }
34
+ catch {
35
+ return null;
36
+ }
37
+ })();
38
+ }
39
+ return ctorPromise;
40
+ }
41
+ /** Test hook: forget the memoised loader result. */
42
+ export function resetMinCutLoader() {
43
+ ctorPromise = null;
44
+ }
45
+ function foldEdges(edges) {
46
+ const folded = new Map();
47
+ for (const [u, v, rawW] of edges) {
48
+ if (u === v)
49
+ continue;
50
+ const w = Number.isFinite(rawW) && rawW > 0 ? rawW : 1;
51
+ const [a, b] = u < v ? [u, v] : [v, u];
52
+ const key = `${a}\u0000${b}`;
53
+ const prev = folded.get(key);
54
+ if (prev)
55
+ prev[2] += w;
56
+ else
57
+ folded.set(key, [a, b, w]);
58
+ }
59
+ return folded;
60
+ }
61
+ /**
62
+ * Compute the exact minimum cut with the wasm solver. Returns null when the
63
+ * solver is unavailable or the input is degenerate (fewer than two nodes, no
64
+ * edges, or nodes with no incident edge — an isolated node is a zero-weight
65
+ * cut that the solver never sees, so the JS fallback answers those).
66
+ */
67
+ export async function wasmMinCut(nodes, edges) {
68
+ const Ctor = await loadWasmMinCut();
69
+ return Ctor ? minCutWith(Ctor, nodes, edges) : null;
70
+ }
71
+ /** Synchronous variant for callers that already hold the loaded solver class. */
72
+ export function minCutWith(Ctor, nodes, edges) {
73
+ if (nodes.length < 2)
74
+ return null;
75
+ const nodeSet = new Set(nodes);
76
+ const folded = foldEdges(edges.filter(([u, v]) => nodeSet.has(u) && nodeSet.has(v)));
77
+ if (folded.size === 0)
78
+ return null;
79
+ const touched = new Set();
80
+ for (const [a, b] of folded.values()) {
81
+ touched.add(a);
82
+ touched.add(b);
83
+ }
84
+ if (touched.size !== nodeSet.size)
85
+ return null;
86
+ try {
87
+ const solver = new Ctor();
88
+ for (const [a, b, w] of folded.values())
89
+ solver.insertEdge(a, b, w);
90
+ const groups = solver.partition();
91
+ const partition1 = groups[0] ?? [];
92
+ const side = new Set(partition1);
93
+ const partition2 = groups[1] ?? nodes.filter(n => !side.has(n));
94
+ const cutEdges = [];
95
+ for (const [u, v] of edges) {
96
+ if (u !== v && nodeSet.has(u) && nodeSet.has(v) && side.has(u) !== side.has(v))
97
+ cutEdges.push([u, v]);
98
+ }
99
+ return { cutValue: solver.minCutValue(), partition1, partition2, cutEdges };
100
+ }
101
+ catch {
102
+ return null;
103
+ }
104
+ }
105
+ /** Above this many nodes the O(n^3) JS fallback is not attempted. */
106
+ export const JS_FALLBACK_MAX_NODES = 300;
107
+ /**
108
+ * Minimum cut of the seed's `depth`-hop neighbourhood (edges treated as
109
+ * undirected, at most `maxNodes` nodes). Answers "where is the weakest
110
+ * boundary around this node, and what sits on its side of it?".
111
+ *
112
+ * Uses the wasm solver when available, else `fallback` (a JS exact min cut)
113
+ * for neighbourhoods up to JS_FALLBACK_MAX_NODES nodes. Returns null when the
114
+ * seed has no neighbours or no backend can handle the neighbourhood.
115
+ */
116
+ export async function seedLocalMinCut(seed, edges, depth, maxNodes, fallback) {
117
+ const adj = new Map();
118
+ for (const [u, v] of edges) {
119
+ if (u === v)
120
+ continue;
121
+ if (!adj.has(u))
122
+ adj.set(u, new Set());
123
+ if (!adj.has(v))
124
+ adj.set(v, new Set());
125
+ adj.get(u).add(v);
126
+ adj.get(v).add(u);
127
+ }
128
+ if (!adj.has(seed))
129
+ return null;
130
+ const hops = new Map([[seed, 0]]);
131
+ let frontier = [seed];
132
+ for (let d = 1; d <= depth && frontier.length > 0 && hops.size < maxNodes; d++) {
133
+ const next = [];
134
+ for (const n of frontier) {
135
+ for (const m of adj.get(n) ?? []) {
136
+ if (hops.has(m) || hops.size >= maxNodes)
137
+ continue;
138
+ hops.set(m, d);
139
+ next.push(m);
140
+ }
141
+ }
142
+ frontier = next;
143
+ }
144
+ if (hops.size < 2)
145
+ return null;
146
+ const nodes = Array.from(hops.keys());
147
+ const sub = edges.filter(([u, v]) => u !== v && hops.has(u) && hops.has(v));
148
+ let backend = 'mincut-wasm';
149
+ let cut = await wasmMinCut(nodes, sub);
150
+ if (!cut) {
151
+ if (nodes.length > JS_FALLBACK_MAX_NODES)
152
+ return null;
153
+ backend = 'js-fallback';
154
+ cut = fallback(nodes, sub);
155
+ }
156
+ const seedInFirst = cut.partition1.includes(seed);
157
+ const mine = seedInFirst ? cut.partition1 : cut.partition2;
158
+ const other = seedInFirst ? cut.partition2 : cut.partition1;
159
+ const seedSide = mine
160
+ .filter(n => n !== seed)
161
+ .map(n => ({ nodeId: n, depth: hops.get(n) ?? depth }))
162
+ .sort((a, b) => a.depth - b.depth || a.nodeId.localeCompare(b.nodeId));
163
+ return {
164
+ seedSide,
165
+ otherSide: other,
166
+ cutValue: cut.cutValue,
167
+ cutEdges: cut.cutEdges,
168
+ backend,
169
+ subgraphNodes: nodes.length,
170
+ };
171
+ }
172
+ //# sourceMappingURL=mincut-bridge.js.map
@@ -90,6 +90,11 @@ export interface ModelRouterConfig {
90
90
  */
91
91
  priorDecay: number;
92
92
  }
93
+ /** Request-local preferences; omitted or false keeps the existing scoring. */
94
+ export interface ModelRoutingPreferences {
95
+ preferCost?: boolean;
96
+ preferSpeed?: boolean;
97
+ }
93
98
  /**
94
99
  * Routing decision result
95
100
  */
@@ -241,7 +246,7 @@ export declare class ModelRouter {
241
246
  * 'bandit-fallback'` (neural was enabled but declined) or
242
247
  * `'heuristic'` (neural was disabled).
243
248
  */
244
- route(task: string, embedding?: number[]): Promise<ModelRoutingResult>;
249
+ route(task: string, embedding?: number[], preferences?: ModelRoutingPreferences): Promise<ModelRoutingResult>;
245
250
  /**
246
251
  * Analyze task complexity
247
252
  */
@@ -395,7 +395,7 @@ export class ModelRouter {
395
395
  * 'bandit-fallback'` (neural was enabled but declined) or
396
396
  * `'heuristic'` (neural was disabled).
397
397
  */
398
- async route(task, embedding) {
398
+ async route(task, embedding, preferences = {}) {
399
399
  const startTime = performance.now();
400
400
  // Analyze task complexity
401
401
  const complexity = this.analyzeComplexity(task, embedding);
@@ -473,7 +473,7 @@ export class ModelRouter {
473
473
  // Silent — neural path is best-effort.
474
474
  }
475
475
  }
476
- const scores = this.computeModelScores(complexity);
476
+ const scores = this.computeModelScores(complexity, preferences);
477
477
  const adjustedScores = this.applyCircuitBreaker(scores);
478
478
  // A/B mode: compute the pure-bandit pick alongside the hybrid pick so
479
479
  // we can log disagreement. Both samples are drawn from the same Beta
@@ -717,17 +717,29 @@ export class ModelRouter {
717
717
  /**
718
718
  * Compute scores for each model
719
719
  */
720
- computeModelScores(complexity) {
720
+ computeModelScores(complexity, preferences) {
721
721
  const { score } = complexity;
722
722
  // Base scoring: inverse relationship with complexity
723
723
  // Low complexity → haiku scores high
724
724
  // High complexity → opus scores high
725
- return {
725
+ const scores = {
726
726
  haiku: Math.max(0, 1 - score * 2), // Drops off quickly as complexity rises
727
727
  sonnet: 1 - Math.abs(score - 0.5) * 2, // Peaks at medium complexity
728
728
  opus: Math.min(1, score * 1.5), // Rises with complexity
729
729
  inherit: 0.1, // Low baseline unless explicitly needed
730
730
  };
731
+ for (const model of ['haiku', 'sonnet', 'opus']) {
732
+ const capabilities = MODEL_CAPABILITIES[model];
733
+ // Preferences must not boost a tier beyond its task capability.
734
+ // Circuit-breaker penalties and uncertainty escalation still apply.
735
+ if (score > capabilities.maxComplexity)
736
+ continue;
737
+ if (preferences.preferCost)
738
+ scores[model] *= 2 - capabilities.costMultiplier;
739
+ if (preferences.preferSpeed)
740
+ scores[model] *= capabilities.speedMultiplier;
741
+ }
742
+ return scores;
731
743
  }
732
744
  /**
733
745
  * Apply circuit breaker adjustments
@@ -36,7 +36,7 @@
36
36
  */
37
37
  import { type VerifyTaskKind } from '../ruvector/output-verifier.js';
38
38
  import { FableHarness, type ReflectItem, type ReflectResult } from './fable-harness.js';
39
- export declare const MH_DARWIN_PIN = "0.12.0";
39
+ export declare const MH_DARWIN_PIN = "0.13.0";
40
40
  export type ResolvedProvenance = 'oracle:test-exec' | 'judge:fable' | 'proxy:structural';
41
41
  /** SWE-bench-shaped / bench-suite-mapped test spec that Tier 1 can execute. */
42
42
  export interface TestSpec {
@@ -43,9 +43,9 @@ import { FableHarness, } from './fable-harness.js';
43
43
  // behavior mid-run (the #142 pin-drift failure mode). Pin it, and let
44
44
  // scripts/check-metaharness-pins.mjs watch this constant for drift. Kept in
45
45
  // lock-step with the optionalDependencies pin in package.json and the plugin
46
- // darwin cache (versioned by the plugin's own `~0.12.0` pin in _darwin.mjs;
46
+ // darwin cache (versioned by the plugin's own `~0.13.0` pin in _darwin.mjs;
47
47
  // both are checked by scripts/check-metaharness-pins.mjs — #3366).
48
- export const MH_DARWIN_PIN = '0.12.0';
48
+ export const MH_DARWIN_PIN = '0.13.0';
49
49
  // ── Public API ───────────────────────────────────────────────────────────
50
50
  /**
51
51
  * Label each trajectory with `resolved` + honest provenance, trying the tiers
@@ -12,7 +12,7 @@
12
12
  */
13
13
  import { ConfigFileManager } from './config-file-manager.js';
14
14
  import { EventEmitter } from 'events';
15
- import { existsSync, mkdirSync, writeFileSync, readFileSync, appendFileSync, unlinkSync } from 'fs';
15
+ import { existsSync, mkdirSync, writeFileSync, readFileSync, appendFileSync, unlinkSync, renameSync, statSync } from 'fs';
16
16
  import { cpus, homedir } from 'os';
17
17
  import { join } from 'path';
18
18
  import { createRequire } from 'node:module';
@@ -31,6 +31,8 @@ import { getRepoSupervisorRegistry } from './repo-supervisor.js';
31
31
  // Daemon config is read synchronously from the constructor. In an ESM build,
32
32
  // bare `require` is undefined, so use a module-relative require for YAML.
33
33
  const requireYaml = createRequire(import.meta.url);
34
+ const DAEMON_LOG_MAX_BYTES = 5 * 1024 * 1024;
35
+ const DAEMON_LOG_BACKUPS = 3;
34
36
  // Default worker configurations with improved intervals (P0 fix: map 5min -> 15min)
35
37
  const DEFAULT_WORKERS = [
36
38
  { type: 'map', intervalMs: 15 * 60 * 1000, offsetMs: 0, priority: 'normal', description: 'Codebase mapping', enabled: true },
@@ -1543,7 +1545,7 @@ export class WorkerDaemon extends EventEmitter {
1543
1545
  rawOutputPreview: typeof result.output === 'string' ? result.output.slice(0, 2000) : undefined,
1544
1546
  rawOutputLength: typeof result.output === 'string' ? result.output.length : 0,
1545
1547
  };
1546
- writeFileSync(metricsFile, JSON.stringify(persisted, null, 2));
1548
+ writeFileAtomic(metricsFile, Buffer.from(JSON.stringify(persisted, null, 2)));
1547
1549
  }
1548
1550
  // Worker implementations
1549
1551
  async runMapWorker() {
@@ -1564,7 +1566,7 @@ export class WorkerDaemon extends EventEmitter {
1564
1566
  },
1565
1567
  scannedAt: Date.now(),
1566
1568
  };
1567
- writeFileSync(metricsFile, JSON.stringify(map, null, 2));
1569
+ writeFileAtomic(metricsFile, Buffer.from(JSON.stringify(map, null, 2)));
1568
1570
  return map;
1569
1571
  }
1570
1572
  /**
@@ -1596,7 +1598,7 @@ export class WorkerDaemon extends EventEmitter {
1596
1598
  ],
1597
1599
  note: 'Local fallback checks file presence only; it does not scan source contents.',
1598
1600
  };
1599
- writeFileSync(auditFile, JSON.stringify(audit, null, 2));
1601
+ writeFileAtomic(auditFile, Buffer.from(JSON.stringify(audit, null, 2)));
1600
1602
  return audit;
1601
1603
  }
1602
1604
  /**
@@ -1620,7 +1622,7 @@ export class WorkerDaemon extends EventEmitter {
1620
1622
  },
1621
1623
  note: 'Install Claude Code CLI for AI-powered optimization suggestions',
1622
1624
  };
1623
- writeFileSync(optimizeFile, JSON.stringify(perf, null, 2));
1625
+ writeFileAtomic(optimizeFile, Buffer.from(JSON.stringify(perf, null, 2)));
1624
1626
  return perf;
1625
1627
  }
1626
1628
  /**
@@ -1662,7 +1664,7 @@ export class WorkerDaemon extends EventEmitter {
1662
1664
  memoryCleaned: 0,
1663
1665
  duplicatesRemoved: 0,
1664
1666
  };
1665
- writeFileSync(consolidateFile, JSON.stringify(disabledResult, null, 2));
1667
+ writeFileAtomic(consolidateFile, Buffer.from(JSON.stringify(disabledResult, null, 2)));
1666
1668
  return disabledResult;
1667
1669
  }
1668
1670
  let report;
@@ -1689,7 +1691,7 @@ export class WorkerDaemon extends EventEmitter {
1689
1691
  memoryCleaned: 0,
1690
1692
  duplicatesRemoved: 0,
1691
1693
  };
1692
- writeFileSync(consolidateFile, JSON.stringify(errorResult, null, 2));
1694
+ writeFileAtomic(consolidateFile, Buffer.from(JSON.stringify(errorResult, null, 2)));
1693
1695
  return errorResult;
1694
1696
  }
1695
1697
  for (const store of stores) {
@@ -1733,7 +1735,7 @@ export class WorkerDaemon extends EventEmitter {
1733
1735
  skipped: part.skipped,
1734
1736
  })),
1735
1737
  };
1736
- writeFileSync(consolidateFile, JSON.stringify(result, null, 2));
1738
+ writeFileAtomic(consolidateFile, Buffer.from(JSON.stringify(result, null, 2)));
1737
1739
  return result;
1738
1740
  }
1739
1741
  /**
@@ -1775,7 +1777,7 @@ export class WorkerDaemon extends EventEmitter {
1775
1777
  this.log('warn', `Backup worker failed: ${message}`);
1776
1778
  result = { timestamp: new Date().toISOString(), backedUp: false, error: message };
1777
1779
  }
1778
- writeFileSync(backupFile, JSON.stringify(result, null, 2));
1780
+ writeFileAtomic(backupFile, Buffer.from(JSON.stringify(result, null, 2)));
1779
1781
  return result;
1780
1782
  }
1781
1783
  /**
@@ -1814,7 +1816,7 @@ export class WorkerDaemon extends EventEmitter {
1814
1816
  this.log('warn', `Harness worker failed: ${message}`);
1815
1817
  result = { timestamp: new Date().toISOString(), ran: false, error: message };
1816
1818
  }
1817
- writeFileSync(harnessFile, JSON.stringify(result, null, 2));
1819
+ writeFileAtomic(harnessFile, Buffer.from(JSON.stringify(result, null, 2)));
1818
1820
  return result;
1819
1821
  }
1820
1822
  /**
@@ -1835,7 +1837,7 @@ export class WorkerDaemon extends EventEmitter {
1835
1837
  gaps: [],
1836
1838
  note: 'Install Claude Code CLI for AI-powered test gap analysis',
1837
1839
  };
1838
- writeFileSync(testGapsFile, JSON.stringify(result, null, 2));
1840
+ writeFileAtomic(testGapsFile, Buffer.from(JSON.stringify(result, null, 2)));
1839
1841
  return result;
1840
1842
  }
1841
1843
  /**
@@ -1916,7 +1918,7 @@ export class WorkerDaemon extends EventEmitter {
1916
1918
  uptime: process.uptime(),
1917
1919
  },
1918
1920
  };
1919
- writeFileSync(benchmarkFile, JSON.stringify(result, null, 2));
1921
+ writeFileAtomic(benchmarkFile, Buffer.from(JSON.stringify(result, null, 2)));
1920
1922
  return result;
1921
1923
  }
1922
1924
  /**
@@ -2020,6 +2022,22 @@ export class WorkerDaemon extends EventEmitter {
2020
2022
  // Also write to log file
2021
2023
  try {
2022
2024
  const logFile = join(this.config.logDir, 'daemon.log');
2025
+ // Keep three generations. Rotate before the next complete record
2026
+ // crosses 5 MiB; a single oversized record is preserved intact.
2027
+ if (existsSync(logFile)) {
2028
+ const size = statSync(logFile).size;
2029
+ if (size > 0 && size + Buffer.byteLength(logMessage + '\n') > DAEMON_LOG_MAX_BYTES) {
2030
+ const oldest = `${logFile}.${DAEMON_LOG_BACKUPS}`;
2031
+ if (existsSync(oldest))
2032
+ unlinkSync(oldest);
2033
+ for (let generation = DAEMON_LOG_BACKUPS - 1; generation >= 1; generation--) {
2034
+ const previous = `${logFile}.${generation}`;
2035
+ if (existsSync(previous))
2036
+ renameSync(previous, `${logFile}.${generation + 1}`);
2037
+ }
2038
+ renameSync(logFile, `${logFile}.1`);
2039
+ }
2040
+ }
2023
2041
  appendFileSync(logFile, logMessage + '\n');
2024
2042
  }
2025
2043
  catch {
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import * as crypto from 'crypto';
9
9
  import * as fs from 'fs';
10
+ import { tmpdir } from 'node:os';
10
11
  import * as path from 'path';
11
12
  import { execFileSync } from 'child_process';
12
13
  /**
@@ -92,7 +93,7 @@ export async function uploadToGCS(content, options = {}) {
92
93
  }
93
94
  console.log(`[GCS] Uploading to gs://${config.bucket}/${objectPath}...`);
94
95
  // Write content to temp file
95
- const tempDir = process.env.TMPDIR || '/tmp';
96
+ const tempDir = tmpdir();
96
97
  const tempFile = path.join(tempDir, `claude-flow-upload-${Date.now()}.json`);
97
98
  fs.writeFileSync(tempFile, content);
98
99
  try {
@@ -151,7 +152,7 @@ export async function downloadFromGCS(uri, config) {
151
152
  const cfg = config || getGCSConfig();
152
153
  console.log(`[GCS] Downloading from ${uri}...`);
153
154
  // Write to temp file first
154
- const tempDir = process.env.TMPDIR || '/tmp';
155
+ const tempDir = tmpdir();
155
156
  const tempFile = path.join(tempDir, `claude-flow-download-${Date.now()}.json`);
156
157
  try {
157
158
  // Download using gcloud storage cp (array form prevents shell injection)
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claude-flow/cli",
3
- "version": "3.71.4",
3
+ "version": "3.72.1",
4
4
  "type": "module",
5
5
  "description": "Ruflo CLI - Enterprise AI agent orchestration with 60+ specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code",
6
6
  "main": "dist/src/index.js",
@@ -102,7 +102,7 @@
102
102
  "dependencies": {
103
103
  "@electron/asar": "^4.3.1",
104
104
  "@claude-flow/cli-core": "3.7.5",
105
- "@claude-flow/codex": "3.0.5",
105
+ "@claude-flow/codex": "3.0.6",
106
106
  "@claude-flow/mcp": "3.1.6",
107
107
  "@claude-flow/neural": "3.0.2",
108
108
  "@claude-flow/plugin-agent-federation": "1.0.5",
@@ -110,7 +110,7 @@
110
110
  "@claude-flow/shared": "3.0.7",
111
111
  "@iarna/toml": "^2.2.5",
112
112
  "@noble/ed25519": "2.3.0",
113
- "@ruvector/rabitq-wasm": "0.1.0",
113
+ "@ruvector/rabitq-wasm": "0.1.2",
114
114
  "ajv": "^8.20.0",
115
115
  "bcryptjs": "^3.0.3",
116
116
  "chalk": "^5.3.0",
@@ -128,13 +128,13 @@
128
128
  "ws": "^8.21.0",
129
129
  "yaml": "^2.8.0",
130
130
  "zod": "^3.22.0",
131
- "@claude-flow/memory": "3.2.2"
131
+ "@claude-flow/memory": "3.2.3"
132
132
  },
133
133
  "optionalDependencies": {
134
134
  "@agntcy/slim-bindings": "2.1.1",
135
135
  "@claude-flow/aidefence": "3.1.0",
136
- "@claude-flow/memory": "3.2.2",
137
- "@metaharness/darwin": "~0.12.0",
136
+ "@claude-flow/memory": "3.2.3",
137
+ "@metaharness/darwin": "~0.13.0",
138
138
  "@metaharness/flywheel": "~0.1.10",
139
139
  "@metaharness/radio": "~0.1.0",
140
140
  "@metaharness/turn-credit": "~0.1.0",
@@ -142,13 +142,15 @@
142
142
  "agentdb": "^3.3.0",
143
143
  "agentic-flow": "^3.0.0",
144
144
  "better-sqlite3": "^12.9.0",
145
- "ruvector": "^0.2.27",
146
- "nostr-tools": "^2.7.0"
145
+ "ruvector": "^0.3.11",
146
+ "nostr-tools": "^2.7.0",
147
+ "@ruvector/learning-wasm": "0.1.29",
148
+ "agent-booster": "^0.2.2"
147
149
  },
148
150
  "peerDependencies": {
149
151
  "@metaharness/router": "^0.4.0",
150
152
  "@ruvector/typesafe": "^0.1.0",
151
- "metaharness": "^0.4.1"
153
+ "metaharness": "^0.4.20"
152
154
  },
153
155
  "peerDependenciesMeta": {
154
156
  "@metaharness/router": {
@@ -1 +0,0 @@
1
- sha256:6141a8ea990c5063b77e090ae8f37f9c539d8aa8f58dcceb30f3a82f97e57319