claude-flow 3.76.1 → 3.77.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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "adoptedAt": 1794515699232,
2
+ "adoptedAt": 1794584864742,
3
3
  "championId": "sha256:6141a8ea990c5063b77e090ae8f37f9c539d8aa8f58dcceb30f3a82f97e57319",
4
4
  "manifest": {
5
5
  "schema": "ruflo.proven-config/v1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-flow",
3
- "version": "3.76.1",
3
+ "version": "3.77.1",
4
4
  "workspaces": [
5
5
  "v3/@claude-flow/codex",
6
6
  "v3/@claude-flow/mcp",
@@ -140,7 +140,11 @@ export class RvfaBuilder {
140
140
  buildRufloSection() {
141
141
  let packageMeta = null;
142
142
  try {
143
- const raw = execSync('npm pack ruflo@latest --dry-run --json 2>/dev/null', { encoding: 'utf-8', timeout: 15_000 });
143
+ const raw = execSync('npm pack ruflo@latest --dry-run --json', {
144
+ encoding: 'utf-8',
145
+ timeout: 15_000,
146
+ stdio: ['ignore', 'pipe', 'pipe'],
147
+ });
144
148
  const parsed = JSON.parse(raw);
145
149
  if (Array.isArray(parsed) && parsed.length > 0)
146
150
  packageMeta = parsed[0];
@@ -1317,7 +1317,21 @@ const depsCommand = {
1317
1317
  output.writeln(output.bold('Security Audit'));
1318
1318
  output.writeln(output.dim('-'.repeat(60)));
1319
1319
  try {
1320
- const auditRaw = execSync('npm audit --json 2>/dev/null', { encoding: 'utf-8', maxBuffer: 10 * 1024 * 1024 });
1320
+ let auditRaw;
1321
+ try {
1322
+ auditRaw = execSync('npm audit --json', {
1323
+ encoding: 'utf-8',
1324
+ maxBuffer: 10 * 1024 * 1024,
1325
+ stdio: ['pipe', 'pipe', 'pipe'],
1326
+ });
1327
+ }
1328
+ catch (auditErr) {
1329
+ // npm audit exits non-zero when vulnerabilities found — stdout still has JSON
1330
+ const stdout = auditErr instanceof Error && 'stdout' in auditErr ? auditErr.stdout : '';
1331
+ if (!stdout)
1332
+ throw auditErr;
1333
+ auditRaw = stdout;
1334
+ }
1321
1335
  const audit = JSON.parse(auditRaw);
1322
1336
  const vulns = audit.metadata?.vulnerabilities || audit.vulnerabilities || {};
1323
1337
  const info = vulns.info || 0;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * `neural wsp` — ruv-FANN weight-space tooling (ADR-528).
3
+ *
4
+ * Read-only evidence over dense models: fingerprint, inspect, invariant
5
+ * checks and bounded-patch regression gates. Nothing here promotes a model,
6
+ * writes routing state or changes what `hooks route` does. The only write is
7
+ * `export-centroid`, which writes the file the user names.
8
+ *
9
+ * Backed by the optional dependencies ruv-fann-wsp, ruv-fann-wsp-invariants
10
+ * and ruv-fann-wsp-lifecycle; every subcommand reports cleanly when they are
11
+ * missing.
12
+ */
13
+ import type { Command } from '../types.js';
14
+ export declare const wspCommand: Command;
15
+ //# sourceMappingURL=neural-wsp.d.ts.map
@@ -0,0 +1,265 @@
1
+ /**
2
+ * `neural wsp` — ruv-FANN weight-space tooling (ADR-528).
3
+ *
4
+ * Read-only evidence over dense models: fingerprint, inspect, invariant
5
+ * checks and bounded-patch regression gates. Nothing here promotes a model,
6
+ * writes routing state or changes what `hooks route` does. The only write is
7
+ * `export-centroid`, which writes the file the user names.
8
+ *
9
+ * Backed by the optional dependencies ruv-fann-wsp, ruv-fann-wsp-invariants
10
+ * and ruv-fann-wsp-lifecycle; every subcommand reports cleanly when they are
11
+ * missing.
12
+ */
13
+ import { existsSync, writeFileSync } from 'node:fs';
14
+ import { resolve as resolvePath } from 'node:path';
15
+ import { output } from '../output.js';
16
+ function str(flags, name) {
17
+ const v = flags[name];
18
+ return typeof v === 'string' && v.length > 0 ? v : undefined;
19
+ }
20
+ function isJson(flags) {
21
+ return str(flags, 'format') === 'json';
22
+ }
23
+ function fail(message, json, exitCode = 1) {
24
+ if (json)
25
+ output.writeln(JSON.stringify({ ok: false, error: message }, null, 2));
26
+ else
27
+ output.printError(message);
28
+ return { success: false, exitCode, message };
29
+ }
30
+ async function requireWsp(json) {
31
+ const { loadWsp } = await import('../ruvector/ruv-fann-wsp.js');
32
+ const load = await loadWsp();
33
+ if (!load.available)
34
+ return { error: fail(`ruv-FANN WSP unavailable: ${load.reason}`, json, 2) };
35
+ return { mods: load.modules };
36
+ }
37
+ /** The shipped (or CLAUDE_FLOW_ROUTER_CENTROID_PATH) centroid artifact. */
38
+ async function loadCentroid() {
39
+ const { loadCentroidArtifact } = await import('../ruvector/centroid-router.js');
40
+ return loadCentroidArtifact();
41
+ }
42
+ /** `--model <file>` when given, else the centroid router as a dense model. */
43
+ async function resolveModel(flags) {
44
+ const w = await import('../ruvector/ruv-fann-wsp.js');
45
+ const file = str(flags, 'model');
46
+ if (file)
47
+ return { model: w.assertDenseModel(w.readJsonInput(file, 'model')), source: resolvePath(file), artifact: null };
48
+ const c = await loadCentroid();
49
+ if (!c.artifact)
50
+ throw new Error(`centroid router artifact unavailable: ${c.error}`);
51
+ return { model: w.centroidToDenseModel(c.artifact), source: `centroid router (${c.path})`, artifact: c.artifact };
52
+ }
53
+ const formatOpt = { name: 'format', short: 'f', type: 'string', description: 'Output format: table, json', default: 'table' };
54
+ const modelOpt = { name: 'model', short: 'm', type: 'string', description: 'ruv-fann.dense-layers/1 JSON file (default: the centroid router)' };
55
+ const statusCommand = {
56
+ name: 'status',
57
+ description: 'Show whether the ruv-FANN WSP packages are installed, their versions and limits',
58
+ options: [formatOpt],
59
+ action: async (ctx) => {
60
+ const json = isJson(ctx.flags);
61
+ const { loadWsp, wspVersions } = await import('../ruvector/ruv-fann-wsp.js');
62
+ const load = await loadWsp();
63
+ const versions = wspVersions();
64
+ const limits = load.available
65
+ ? { wsp: load.modules.wsp.WSP_LIMITS, invariants: load.modules.invariants.INVARIANT_LIMITS, lifecycle: load.modules.lifecycle.LIFECYCLE_LIMITS }
66
+ : null;
67
+ const data = { available: load.available, reason: load.available ? null : load.reason, versions, limits };
68
+ if (json)
69
+ output.writeln(JSON.stringify(data, null, 2));
70
+ else {
71
+ output.writeln(output.bold('ruv-FANN weight-space programming'));
72
+ output.writeln(` Available: ${load.available ? output.success('yes') : output.warning('no — ' + data.reason)}`);
73
+ for (const [k, v] of Object.entries(versions))
74
+ output.writeln(` ${k.padEnd(24)} ${v ?? output.dim('not installed')}`);
75
+ if (limits)
76
+ output.writeln(output.dim(` Patch limit: ${limits.wsp.maxEdits} edits · rows ≤ ${limits.wsp.maxRows} · params ≤ ${limits.wsp.maxParameters} · invariant cases ≤ ${limits.invariants.maxCases}`));
77
+ }
78
+ return { success: true, data };
79
+ },
80
+ };
81
+ const inspectCommand = {
82
+ name: 'inspect',
83
+ description: 'Fingerprint and describe a dense model (default: the centroid router)',
84
+ options: [modelOpt, formatOpt],
85
+ examples: [
86
+ { command: 'claude-flow neural wsp inspect', description: 'Hash and shape of the shipped centroid router' },
87
+ { command: 'claude-flow neural wsp inspect -m model.json -f json', description: 'Inspect your own ruv-FANN model' },
88
+ ],
89
+ action: async (ctx) => {
90
+ const json = isJson(ctx.flags);
91
+ const w = await requireWsp(json);
92
+ if ('error' in w)
93
+ return w.error;
94
+ try {
95
+ const { model, source } = await resolveModel(ctx.flags);
96
+ const inspection = await w.mods.wsp.inspectWeightModel(model);
97
+ const data = { source, ...inspection };
98
+ if (json)
99
+ output.writeln(JSON.stringify(data, null, 2));
100
+ else {
101
+ output.writeln(output.bold(`Model: ${source}`));
102
+ output.writeln(` Hash: ${inspection.baseHash}`);
103
+ output.writeln(` Shape: ${inspection.inputSize} → ${inspection.outputSize} (${inspection.parameterCount} parameters)`);
104
+ for (const l of inspection.layers) {
105
+ output.writeln(output.dim(` layer ${l.layer}: ${l.inputs}→${l.outputs} ${l.activation} (${l.parameterCount} params)`));
106
+ }
107
+ }
108
+ return { success: true, data };
109
+ }
110
+ catch (err) {
111
+ return fail(err instanceof Error ? err.message : String(err), json);
112
+ }
113
+ },
114
+ };
115
+ const checkCommand = {
116
+ name: 'check',
117
+ description: 'Run invariant checks: the built-in centroid self-routing suite, or --suite on --model',
118
+ options: [
119
+ modelOpt,
120
+ { name: 'suite', short: 's', type: 'string', description: 'ruv-fann.invariants/1 JSON file (required with --model)' },
121
+ { name: 'min-gap', type: 'number', description: 'Self-routing: required gap between a label and any other label on its own centroid', default: '0.05' },
122
+ formatOpt,
123
+ ],
124
+ examples: [
125
+ { command: 'claude-flow neural wsp check', description: 'Each centroid must route to its own label by a clear gap' },
126
+ { command: 'claude-flow neural wsp check -m model.json -s invariants.json', description: 'Your own model and suite' },
127
+ ],
128
+ action: async (ctx) => {
129
+ const json = isJson(ctx.flags);
130
+ const w = await requireWsp(json);
131
+ if ('error' in w)
132
+ return w.error;
133
+ const mod = await import('../ruvector/ruv-fann-wsp.js');
134
+ try {
135
+ const modelFile = str(ctx.flags, 'model');
136
+ const suiteFile = str(ctx.flags, 'suite');
137
+ let data, accepted;
138
+ if (!modelFile) {
139
+ if (suiteFile)
140
+ return fail('--suite needs --model; without --model the built-in self-routing suite runs', json);
141
+ const c = await loadCentroid();
142
+ if (!c.artifact)
143
+ return fail(`centroid router artifact unavailable: ${c.error}`, json);
144
+ const gapRaw = ctx.flags.minGap ?? ctx.flags['min-gap'];
145
+ const minGap = gapRaw === undefined ? undefined : Number(gapRaw);
146
+ if (minGap !== undefined && !(minGap > 0 && minGap < 1))
147
+ return fail('--min-gap must be in (0, 1)', json);
148
+ const r = await mod.checkCentroidSelfRouting(w.mods, c.artifact, { minGap });
149
+ accepted = r.accepted;
150
+ data = { suite: 'centroid-self-routing', source: c.path, ...r };
151
+ }
152
+ else {
153
+ if (!suiteFile)
154
+ return fail('--model needs --suite (a ruv-fann.invariants/1 file)', json);
155
+ const model = mod.assertDenseModel(mod.readJsonInput(modelFile, 'model'));
156
+ const suite = mod.readJsonInput(suiteFile, 'suite');
157
+ const r = await w.mods.invariants.checkModelInvariants(model, suite);
158
+ accepted = r.accepted === true;
159
+ data = { suite: resolvePath(suiteFile), source: resolvePath(modelFile), ...r };
160
+ }
161
+ if (json)
162
+ output.writeln(JSON.stringify(data, null, 2));
163
+ else {
164
+ output.writeln(accepted ? output.success(`Invariants hold (${data.checks} checks, ${data.backend})`) : output.warning(`Invariants FAILED (${data.checks} checks)`));
165
+ const v = data.violations ?? [];
166
+ for (const x of v.slice(0, 20))
167
+ output.writeln(output.dim(` ${x.case}: output ${x.output} ${x.constraint} — actual ${x.actual}, bound ${x.bound}`));
168
+ if (v.length > 20)
169
+ output.writeln(output.dim(` … ${v.length - 20} more`));
170
+ }
171
+ return { success: accepted, exitCode: accepted ? 0 : 1, data };
172
+ }
173
+ catch (err) {
174
+ return fail(err instanceof Error ? err.message : String(err), json);
175
+ }
176
+ },
177
+ };
178
+ const gateCommand = {
179
+ name: 'gate',
180
+ description: 'Regression-gate a bounded weight patch against one or more datasets (evidence only; never promotes)',
181
+ options: [
182
+ { name: 'model', short: 'm', type: 'string', description: 'ruv-fann.dense-layers/1 JSON file', required: true },
183
+ { name: 'patch', short: 'p', type: 'string', description: 'ruv-fann.weight-patch/1 JSON file (≤128 edits)', required: true },
184
+ { name: 'suites', short: 's', type: 'string', description: 'JSON array of {name, dataset:{inputs,targets,rows}, policy:{maxMSE,maxRegressionMSE}}', required: true },
185
+ formatOpt,
186
+ ],
187
+ examples: [
188
+ { command: 'claude-flow neural wsp gate -m model.json -p patch.json -s suites.json', description: 'Accept or reject a patch on every suite' },
189
+ ],
190
+ action: async (ctx) => {
191
+ const json = isJson(ctx.flags);
192
+ const w = await requireWsp(json);
193
+ if ('error' in w)
194
+ return w.error;
195
+ const mod = await import('../ruvector/ruv-fann-wsp.js');
196
+ try {
197
+ const m = str(ctx.flags, 'model'), p = str(ctx.flags, 'patch'), s = str(ctx.flags, 'suites');
198
+ if (!m || !p || !s)
199
+ return fail('--model, --patch and --suites are all required', json);
200
+ const model = mod.assertDenseModel(mod.readJsonInput(m, 'model'));
201
+ const patch = mod.readJsonInput(p, 'patch');
202
+ const suites = mod.readJsonInput(s, 'suites');
203
+ if (!Array.isArray(suites))
204
+ return fail('suites: expected a JSON array', json);
205
+ const r = await w.mods.lifecycle.runRegressionGate({ model, patch, suites });
206
+ if (json)
207
+ output.writeln(JSON.stringify(r, null, 2));
208
+ else {
209
+ output.writeln(r.accepted ? output.success('Patch ACCEPTED on every suite') : output.warning('Patch REJECTED'));
210
+ output.writeln(output.dim(` base ${r.baseHash.slice(0, 16)}… → candidate ${r.candidateHash.slice(0, 16)}…`));
211
+ for (const x of r.suites) {
212
+ const e = x.evaluation;
213
+ output.writeln(` ${x.name}: ${e.accepted ? 'pass' : 'fail'} mse ${e.baseline.mse.toFixed(6)} → ${e.candidate.mse.toFixed(6)}${e.reasons.length ? ' (' + e.reasons.join('; ') + ')' : ''}`);
214
+ }
215
+ output.writeln(output.dim(' Evidence only: nothing was promoted or written.'));
216
+ }
217
+ return { success: r.accepted, exitCode: r.accepted ? 0 : 1, data: r };
218
+ }
219
+ catch (err) {
220
+ return fail(err instanceof Error ? err.message : String(err), json);
221
+ }
222
+ },
223
+ };
224
+ const exportCentroidCommand = {
225
+ name: 'export-centroid',
226
+ description: 'Write the centroid router as a ruv-fann.dense-layers/1 model (one Linear layer)',
227
+ options: [
228
+ { name: 'output', short: 'o', type: 'string', description: 'Destination JSON file', required: true },
229
+ { name: 'force', type: 'boolean', description: 'Overwrite an existing file', default: 'false' },
230
+ ],
231
+ examples: [
232
+ { command: 'claude-flow neural wsp export-centroid -o centroid-router.json', description: 'Export for use with other ruv-FANN tooling' },
233
+ ],
234
+ action: async (ctx) => {
235
+ const out = str(ctx.flags, 'output');
236
+ if (!out)
237
+ return fail('--output is required', false);
238
+ const dest = resolvePath(out);
239
+ if (existsSync(dest) && ctx.flags.force !== true)
240
+ return fail(`${dest} exists; pass --force to overwrite`, false);
241
+ const c = await loadCentroid();
242
+ if (!c.artifact)
243
+ return fail(`centroid router artifact unavailable: ${c.error}`, false);
244
+ const { centroidToDenseModel } = await import('../ruvector/ruv-fann-wsp.js');
245
+ const model = centroidToDenseModel(c.artifact);
246
+ writeFileSync(dest, JSON.stringify(model) + '\n', { mode: 0o644 });
247
+ output.writeln(output.success(`Wrote ${dest}`));
248
+ output.writeln(output.dim(` ${c.artifact.labels.length} outputs (labels, in order): ${c.artifact.labels.join(', ')}`));
249
+ return { success: true, data: { path: dest, labels: c.artifact.labels } };
250
+ },
251
+ };
252
+ export const wspCommand = {
253
+ name: 'wsp',
254
+ description: 'ruv-FANN weight-space tooling: inspect, invariant checks, regression gates (ADR-528)',
255
+ subcommands: [statusCommand, inspectCommand, checkCommand, gateCommand, exportCentroidCommand],
256
+ examples: [
257
+ { command: 'claude-flow neural wsp status', description: 'Are the optional ruv-FANN packages installed?' },
258
+ { command: 'claude-flow neural wsp check', description: 'Self-routing invariants on the shipped centroid router' },
259
+ ],
260
+ action: async () => {
261
+ output.writeln('Use a subcommand: status | inspect | check | gate | export-centroid');
262
+ return { success: true };
263
+ },
264
+ };
265
+ //# sourceMappingURL=neural-wsp.js.map
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import { output } from '../output.js';
8
8
  import { getProjectRoot } from '../services/project-root.js';
9
+ import { wspCommand } from './neural-wsp.js';
9
10
  // Train subcommand - REAL WASM training with RuVector
10
11
  const trainCommand = {
11
12
  name: 'train',
@@ -4323,7 +4324,7 @@ const distillCommand = {
4323
4324
  export const neuralCommand = {
4324
4325
  name: 'neural',
4325
4326
  description: 'Neural pattern training, MoE, Flash Attention, pattern learning',
4326
- subcommands: [trainCommand, statusCommand, patternsCommand, predictCommand, optimizeCommand, benchmarkCommand, listCommand, exportCommand, importCommand, routerCommand, distillCommand],
4327
+ subcommands: [trainCommand, statusCommand, patternsCommand, predictCommand, optimizeCommand, benchmarkCommand, listCommand, exportCommand, importCommand, routerCommand, distillCommand, wspCommand],
4327
4328
  examples: [
4328
4329
  { command: 'claude-flow neural status', description: 'Check neural system status' },
4329
4330
  { command: 'claude-flow neural train -p coordination', description: 'Train coordination patterns' },
@@ -489,7 +489,7 @@ const cveCommand = {
489
489
  // If --check CVE-XXXX is given, filter to that specific CVE ID.
490
490
  let auditJson;
491
491
  try {
492
- auditJson = execSync('npm audit --json 2>/dev/null', {
492
+ auditJson = execSync('npm audit --json', {
493
493
  encoding: 'utf-8',
494
494
  timeout: 30000,
495
495
  stdio: ['pipe', 'pipe', 'pipe'],
@@ -63,6 +63,26 @@ function embeddingModelLabel(dimension) {
63
63
  // Unchanged pre-#2305 label for any other size.
64
64
  return DEFAULT_EMBEDDING_MODEL;
65
65
  }
66
+ /**
67
+ * #4984: label for a vector read from `embedder`. AgentDB's own embedder is
68
+ * MiniLM; only a patched one (rescue / registry generator) runs the configured
69
+ * model, so a dimension match alone must not claim it.
70
+ */
71
+ function embedderModelLabel(embedder, dimension) {
72
+ const patched = embedder?.__ruvectorRescued === true || embedder?.__registryGenerator === true;
73
+ return patched ? embeddingModelLabel(dimension) : DEFAULT_EMBEDDING_MODEL;
74
+ }
75
+ /** #4984: embedder handed to the registry when embeddings.json names a non-default model. */
76
+ function configuredModelGenerator(dimension) {
77
+ return async (text) => {
78
+ const { generateLocalEmbedding } = await import('./memory-initializer.js');
79
+ const local = await generateLocalEmbedding(text);
80
+ if (local.backend !== 'onnx' || local.embedding.length !== dimension) {
81
+ throw new Error(`configured embedding model unavailable (backend=${local.backend}, ${local.embedding.length}/${dimension} dims)`);
82
+ }
83
+ return Float32Array.from(local.embedding);
84
+ };
85
+ }
66
86
  // One lease spans an entire bridge operation, including its awaited controller
67
87
  // effects and nested bridge calls. Initializer ownership alone is insufficient:
68
88
  // a ReasoningBank write can still be pending after its registry has opened.
@@ -318,6 +338,11 @@ async function getRegistry(dbPath) {
318
338
  dbPath: resolvedPath,
319
339
  embeddingModel: embCfg.model,
320
340
  dimension: embCfg.dimension,
341
+ // #4984: AgentDB hardcodes MiniLM, so a configured non-default
342
+ // model needs the local chain installed as its embedder. Only real
343
+ // ONNX vectors are accepted (never hash vectors), and the local
344
+ // chain never re-enters the bridge (#2312).
345
+ ...(embCfg.model !== DEFAULT_EMBEDDING_MODEL ? { embeddingGenerator: configuredModelGenerator(embCfg.dimension) } : {}),
321
346
  vectorBackend: 'auto',
322
347
  controllers: {
323
348
  reasoningBank: true,
@@ -1047,7 +1072,7 @@ async function embedForBridge(agentdb, text) {
1047
1072
  try {
1048
1073
  const emb = await embedder.embed(text);
1049
1074
  if (emb && emb.length > 0) {
1050
- return { vector: Array.from(emb), model: embeddingModelLabel(emb.length) };
1075
+ return { vector: Array.from(emb), model: embedderModelLabel(embedder, emb.length) };
1051
1076
  }
1052
1077
  agentdbProblem = 'agentdb embedder returned no vector';
1053
1078
  }
@@ -1935,7 +1960,7 @@ export async function bridgeGenerateEmbedding(text, dbPath) {
1935
1960
  return {
1936
1961
  embedding: Array.from(emb),
1937
1962
  dimensions: emb.length,
1938
- model: embCfg.model,
1963
+ model: embedderModelLabel(embedder, emb.length),
1939
1964
  backend: isMock ? 'mock' : 'onnx',
1940
1965
  };
1941
1966
  }
@@ -1966,7 +1991,7 @@ export async function bridgeLoadEmbeddingModel(dbPath) {
1966
1991
  return {
1967
1992
  success: true,
1968
1993
  dimensions: test.length,
1969
- modelName: embeddingModelLabel(test.length),
1994
+ modelName: embedderModelLabel(embedder, test.length),
1970
1995
  loadTime: Date.now() - startTime,
1971
1996
  };
1972
1997
  }
@@ -2213,7 +2238,7 @@ export async function bridgeAddEmbedding(id, embedding, entry, dbPath) {
2213
2238
  embedding_model = excluded.embedding_model,
2214
2239
  updated_at = excluded.updated_at,
2215
2240
  status = 'active'
2216
- `).run(id, entry.key, entry.namespace, entry.content, embeddingJson, embedding.length, embeddingModelLabel(embedding.length), now, now);
2241
+ `).run(id, entry.key, entry.namespace, entry.content, embeddingJson, embedding.length, embedderModelLabel(registry.getAgentDB()?.embedder, embedding.length), now, now);
2217
2242
  return true;
2218
2243
  }
2219
2244
  catch {