claude-flow 3.77.0 → 3.77.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 (42) hide show
  1. package/.claude/helpers/hook-handler.cjs +85 -5
  2. package/README.md +12 -2
  3. package/node_modules/@claude-flow/plugin-agent-federation/README.md +18 -0
  4. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-dispatcher.d.ts +4 -1
  5. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-dispatcher.d.ts.map +1 -1
  6. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-dispatcher.js +11 -0
  7. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-dispatcher.js.map +1 -1
  8. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-envelope-guard.d.ts +29 -0
  9. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-envelope-guard.d.ts.map +1 -0
  10. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-envelope-guard.js +96 -0
  11. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-envelope-guard.js.map +1 -0
  12. package/node_modules/@claude-flow/plugin-agent-federation/dist/plugin.d.ts.map +1 -1
  13. package/node_modules/@claude-flow/plugin-agent-federation/dist/plugin.js +3 -0
  14. package/node_modules/@claude-flow/plugin-agent-federation/dist/plugin.js.map +1 -1
  15. package/package.json +8 -5
  16. package/v3/@claude-flow/cli/README.md +5 -0
  17. package/v3/@claude-flow/cli/bin/cli.js +8 -3
  18. package/v3/@claude-flow/cli/dist/src/commands/init.js +8 -1
  19. package/v3/@claude-flow/cli/dist/src/commands/session.js +2 -1
  20. package/v3/@claude-flow/cli/dist/src/commands/workflow.js +2 -1
  21. package/v3/@claude-flow/cli/dist/src/init/helpers-generator.js +85 -5
  22. package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-execute-core.js +26 -25
  23. package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-tools.js +161 -157
  24. package/v3/@claude-flow/cli/dist/src/mcp-tools/claims-tools.js +257 -258
  25. package/v3/@claude-flow/cli/dist/src/mcp-tools/hive-mind-tools.js +48 -29
  26. package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +6 -0
  27. package/v3/@claude-flow/cli/dist/src/mcp-tools/locked-json-store.d.ts +20 -0
  28. package/v3/@claude-flow/cli/dist/src/mcp-tools/locked-json-store.js +99 -0
  29. package/v3/@claude-flow/cli/dist/src/mcp-tools/managed-agent-tools.js +51 -7
  30. package/v3/@claude-flow/cli/dist/src/mcp-tools/session-tools.js +19 -9
  31. package/v3/@claude-flow/cli/dist/src/mcp-tools/task-tools.js +299 -270
  32. package/v3/@claude-flow/cli/dist/src/mcp-tools/workflow-tools.js +245 -215
  33. package/v3/@claude-flow/cli/dist/src/memory/memory-bridge.js +29 -4
  34. package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.js +5 -4
  35. package/v3/@claude-flow/cli/dist/src/services/managed-run-store.d.ts +11 -0
  36. package/v3/@claude-flow/cli/dist/src/services/managed-run-store.js +125 -3
  37. package/v3/@claude-flow/cli/dist/src/services/policy-runtime.d.ts +3 -0
  38. package/v3/@claude-flow/cli/dist/src/services/policy-runtime.js +3 -1
  39. package/v3/@claude-flow/cli/package.json +11 -8
  40. package/v3/@claude-flow/guidance/package.json +1 -0
  41. package/.claude/.proven-config-version +0 -1
  42. package/.claude/proven-config.json +0 -42
@@ -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 {
@@ -8,7 +8,7 @@ import * as fs from 'fs';
8
8
  import * as path from 'path';
9
9
  import { AsyncLocalStorage } from 'node:async_hooks';
10
10
  import { createRequire } from 'node:module';
11
- import { readFileMaybeEncrypted, writeDbImagePreservingFormat, writeFileRestricted } from '../fs-secure.js';
11
+ import { readFileMaybeEncrypted, writeDbImagePreservingFormat, writeFileAtomic, writeFileRestricted } from '../fs-secure.js';
12
12
  import { _resetEmbeddingConfigCache, DEFAULT_EMBEDDING_DIMENSION, resolveEffectiveEmbeddingConfig, resolveEmbeddingConfig, } from './embedding-config.js';
13
13
  import { restoreMemoryDbFromBackup } from '../services/memory-backup.js';
14
14
  import { validateIdentifier } from '../mcp-tools/validate-input.js';
@@ -739,10 +739,11 @@ function saveHNSWMetadata() {
739
739
  const swarmDir = getMemoryRoot();
740
740
  const metadataPath = path.join(swarmDir, 'hnsw.metadata.json');
741
741
  const metadata = Array.from(hnswIndex.entries.entries());
742
- fs.writeFileSync(metadataPath, JSON.stringify(metadata));
742
+ writeFileAtomic(metadataPath, Buffer.from(JSON.stringify(metadata), 'utf-8'));
743
743
  }
744
- catch {
745
- // Silently fail - metadata save is best-effort
744
+ catch (error) {
745
+ // Metadata is best-effort, but persistence failures must be visible.
746
+ console.warn('[memory] Failed to save hnsw.metadata.json:', error instanceof Error ? error.message : String(error));
746
747
  }
747
748
  }
748
749
  export function removeHNSWEntriesByLogicalKey(entries, key, namespace) {
@@ -44,6 +44,17 @@ export declare function executeManagedControl(input: Record<string, unknown>, de
44
44
  snapshot?: undefined;
45
45
  interruptRequested?: undefined;
46
46
  }>;
47
+ /** Sessions this project created. Every other session in the organisation needs a host allowlist entry. */
48
+ export interface ManagedSessionRecord {
49
+ sessionId: string;
50
+ environmentId?: string;
51
+ createdMs: number;
52
+ }
53
+ export declare function managedLedgerPath(root: string): string;
54
+ export declare function recordManagedSession(root: string, sessionId: string, environmentId: string): ManagedSessionRecord[];
55
+ export declare function forgetManagedSession(root: string, sessionId: string): void;
56
+ /** Reads never create state. A missing ledger owns nothing; an unreadable one throws. */
57
+ export declare function ownedManagedSession(root: string, sessionId: string): ManagedSessionRecord | undefined;
47
58
  /** Successful provider deletion is a session fact, never an acceptance verdict. */
48
59
  export declare function publishManagedTermination(root: string, sessionId: string, collector: {
49
60
  page: (id: string) => ManagedRunSnapshot | undefined;
@@ -1,7 +1,8 @@
1
1
  /** Bounded console projections and a fail-closed cross-process collector lease. */
2
- import { closeSync, constants, existsSync, fsyncSync, lstatSync, mkdirSync, openSync, readSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
3
- import { join, resolve } from 'node:path';
4
- import { randomUUID } from 'node:crypto';
2
+ import { closeSync, constants, existsSync, fsyncSync, lstatSync, mkdirSync, openSync, readSync, realpathSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
3
+ import { homedir } from 'node:os';
4
+ import { dirname, isAbsolute, join, resolve } from 'node:path';
5
+ import { createHash, randomUUID } from 'node:crypto';
5
6
  const flights = new Map();
6
7
  function folder(root) {
7
8
  let p = resolve(root);
@@ -109,6 +110,127 @@ export async function executeManagedControl(input, deps) {
109
110
  return { success: true, currentStatus: current.status, interruptRequested: true, cancellationConfirmed: false, result: await deps.interrupt(sessionId) };
110
111
  return { success: true, currentStatus: current.status, cancellationConfirmed: true, result: await deps.terminate(sessionId) };
111
112
  }
113
+ const LEDGER_LIMIT = 1000;
114
+ // The ledger lives in the user's state directory, keyed by project, never in the workspace: an agent that can write
115
+ // project files must not be able to grant itself another session. Same base directory as the dispatch queue.
116
+ export function managedLedgerPath(root) {
117
+ let project = resolve(root);
118
+ try {
119
+ project = realpathSync.native(project);
120
+ }
121
+ catch { /* a missing project keeps its resolved path */ }
122
+ const override = process.env.RUFLO_AI_BUDGET_DIR;
123
+ const base = override && isAbsolute(override) ? override : join(homedir(), '.claude-flow');
124
+ return join(base, 'managed', `${createHash('sha256').update(project).digest('hex')}.json`);
125
+ }
126
+ function ledgerEntries(path) {
127
+ if (!existsSync(path))
128
+ return [];
129
+ if (!lstatSync(path).isFile() || lstatSync(path).isSymbolicLink())
130
+ throw new Error('Invalid managed session ledger');
131
+ const fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
132
+ try {
133
+ const buffer = Buffer.alloc(256_001);
134
+ const count = readSync(fd, buffer, 0, buffer.length, 0);
135
+ if (count > 256_000)
136
+ throw new Error('Managed session ledger exceeds limit');
137
+ const value = JSON.parse(buffer.subarray(0, count).toString('utf8'));
138
+ if (value.version !== 1 || !Array.isArray(value.sessions) || value.sessions.length > LEDGER_LIMIT)
139
+ throw new Error('Invalid managed session ledger');
140
+ for (const s of value.sessions) {
141
+ if (typeof s?.sessionId !== 'string' || !/^sesn_[A-Za-z0-9]+$/.test(s.sessionId) || (s.environmentId !== undefined && (typeof s.environmentId !== 'string' || !/^env_[A-Za-z0-9]+$/.test(s.environmentId))))
142
+ throw new Error('Invalid managed session ledger');
143
+ }
144
+ return value.sessions;
145
+ }
146
+ finally {
147
+ closeSync(fd);
148
+ }
149
+ }
150
+ // Reads treat an unreadable ledger as owning nothing. A write keeps it aside for inspection and starts empty.
151
+ function writableEntries(path) {
152
+ try {
153
+ return ledgerEntries(path);
154
+ }
155
+ catch {
156
+ renameSync(path, `${path}.corrupt-${Date.now()}`);
157
+ return [];
158
+ }
159
+ }
160
+ const LOCK_STALE_MS = 5_000;
161
+ // A lost record would strand a session this project just paid for, so wait briefly for another writer. The lock
162
+ // names its owner; one older than LOCK_STALE_MS was left by a writer that died, and is broken.
163
+ function ledgerLock(path) {
164
+ for (let attempt = 0;; attempt++) {
165
+ try {
166
+ const fd = openSync(path, 'wx', 0o600);
167
+ try {
168
+ writeFileSync(fd, `${process.pid} ${Date.now()}\n`);
169
+ }
170
+ catch (error) {
171
+ closeSync(fd);
172
+ unlinkSync(path);
173
+ throw error;
174
+ }
175
+ return fd;
176
+ }
177
+ catch (error) {
178
+ if (error.code !== 'EEXIST' || attempt >= 20)
179
+ throw error;
180
+ try {
181
+ const lock = lstatSync(path);
182
+ if (lock.isFile() && Date.now() - lock.mtimeMs > LOCK_STALE_MS) {
183
+ unlinkSync(path);
184
+ continue;
185
+ }
186
+ }
187
+ catch { /* released meanwhile */
188
+ continue;
189
+ }
190
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
191
+ }
192
+ }
193
+ }
194
+ // Returns the records the size cap dropped.
195
+ function updateLedger(root, change) {
196
+ const path = managedLedgerPath(root), dir = dirname(path);
197
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
198
+ if (!lstatSync(dir).isDirectory() || lstatSync(dir).isSymbolicLink())
199
+ throw new Error('Managed session ledger directory must be regular');
200
+ const lockPath = `${path}.lock`, temp = join(dir, `${randomUUID()}.tmp`);
201
+ const fd = ledgerLock(lockPath);
202
+ try {
203
+ const sessions = change(writableEntries(path));
204
+ const out = openSync(temp, 'wx', 0o600);
205
+ try {
206
+ writeFileSync(out, JSON.stringify({ version: 1, sessions: sessions.slice(0, LEDGER_LIMIT) }));
207
+ fsyncSync(out);
208
+ }
209
+ finally {
210
+ closeSync(out);
211
+ }
212
+ renameSync(temp, path);
213
+ return sessions.slice(LEDGER_LIMIT);
214
+ }
215
+ finally {
216
+ if (existsSync(temp))
217
+ unlinkSync(temp);
218
+ closeSync(fd);
219
+ unlinkSync(lockPath);
220
+ }
221
+ }
222
+ export function recordManagedSession(root, sessionId, environmentId) {
223
+ if (!/^sesn_[A-Za-z0-9]+$/.test(sessionId) || !/^env_[A-Za-z0-9]+$/.test(environmentId))
224
+ throw new Error('Invalid managed session ID');
225
+ return updateLedger(root, sessions => [{ sessionId, environmentId, createdMs: Date.now() }, ...sessions.filter(s => s.sessionId !== sessionId)]);
226
+ }
227
+ export function forgetManagedSession(root, sessionId) {
228
+ updateLedger(root, sessions => sessions.filter(s => s.sessionId !== sessionId));
229
+ }
230
+ /** Reads never create state. A missing ledger owns nothing; an unreadable one throws. */
231
+ export function ownedManagedSession(root, sessionId) {
232
+ return ledgerEntries(managedLedgerPath(root)).find(s => s.sessionId === sessionId);
233
+ }
112
234
  /** Successful provider deletion is a session fact, never an acceptance verdict. */
113
235
  export function publishManagedTermination(root, sessionId, collector) {
114
236
  const snapshot = collector.page(sessionId);
@@ -4,6 +4,9 @@ import { AgenticPolicyEngine, type BudgetLimit, type CapabilityEnvelope, type Po
4
4
  * (pid, pid namespace and boot id identify a dead owner) rather than a copy.
5
5
  */
6
6
  export declare function acquireLock(lockPath: string): Promise<() => void>;
7
+ /** Exported for the MCP JSON stores (`mcp-tools/locked-json-store.ts`), which
8
+ * write under {@link acquireLock} with the same durability and Windows retry. */
9
+ export declare function writeJsonAtomic(file: string, value: unknown): Promise<void>;
7
10
  export declare function loadPolicyState(projectRoot?: string): PolicyState;
8
11
  export declare function autoMigratePolicyStateIfNeeded(projectRoot?: string): Promise<{
9
12
  migrated: boolean;
@@ -348,7 +348,9 @@ function appendArchiveDurably(file, receipts, verifier) {
348
348
  closeSync(fd);
349
349
  }
350
350
  }
351
- async function writeJsonAtomic(file, value) {
351
+ /** Exported for the MCP JSON stores (`mcp-tools/locked-json-store.ts`), which
352
+ * write under {@link acquireLock} with the same durability and Windows retry. */
353
+ export async function writeJsonAtomic(file, value) {
352
354
  mkdirDurably(dirname(file));
353
355
  const temporary = `${file}.${process.pid}.${randomUUID()}.tmp`;
354
356
  let renamed = false;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claude-flow/cli",
3
- "version": "3.77.0",
3
+ "version": "3.77.2",
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",
@@ -11,13 +11,13 @@
11
11
  "claude-flow": "bin/cli.js",
12
12
  "claude-flow-mcp": "bin/mcp-server.js"
13
13
  },
14
- "homepage": "https://github.com/ruvnet/claude-flow#readme",
14
+ "homepage": "https://ruv.io",
15
15
  "bugs": {
16
- "url": "https://github.com/ruvnet/claude-flow/issues"
16
+ "url": "https://github.com/ruvnet/ruflo/issues"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",
20
- "url": "git+https://github.com/ruvnet/claude-flow.git",
20
+ "url": "git+https://github.com/ruvnet/ruflo.git",
21
21
  "directory": "v3/@claude-flow/cli"
22
22
  },
23
23
  "keywords": [
@@ -38,7 +38,10 @@
38
38
  "vector-database",
39
39
  "embeddings",
40
40
  "self-learning",
41
- "enterprise"
41
+ "enterprise",
42
+ "local-vector-search",
43
+ "rvf",
44
+ "mcp-server"
42
45
  ],
43
46
  "author": "RuvNet <ruv@ruv.io> (https://ruv.io)",
44
47
  "license": "MIT",
@@ -134,12 +137,12 @@
134
137
  "ws": "^8.21.0",
135
138
  "yaml": "^2.8.0",
136
139
  "zod": "^3.22.0",
137
- "@claude-flow/memory": "3.3.2"
140
+ "@claude-flow/memory": "3.3.3"
138
141
  },
139
142
  "optionalDependencies": {
140
143
  "@agntcy/slim-bindings": "2.1.1",
141
- "@claude-flow/aidefence": "3.2.1",
142
- "@claude-flow/memory": "3.3.2",
144
+ "@claude-flow/aidefence": "3.2.2",
145
+ "@claude-flow/memory": "3.3.3",
143
146
  "@metaharness/flywheel": "~0.1.10",
144
147
  "@metaharness/radio": "~0.1.0",
145
148
  "@metaharness/turn-credit": "~0.1.0",
@@ -1,4 +1,5 @@
1
1
  {
2
+ "homepage": "https://ruv.io",
2
3
  "name": "@claude-flow/guidance",
3
4
  "version": "3.0.1",
4
5
  "description": "Guidance Control Plane - Compiles, retrieves, enforces, and evolves guidance rules for Claude Code sessions",
@@ -1 +0,0 @@
1
- sha256:6141a8ea990c5063b77e090ae8f37f9c539d8aa8f58dcceb30f3a82f97e57319
@@ -1,42 +0,0 @@
1
- {
2
- "adoptedAt": 1794520287185,
3
- "championId": "sha256:6141a8ea990c5063b77e090ae8f37f9c539d8aa8f58dcceb30f3a82f97e57319",
4
- "manifest": {
5
- "schema": "ruflo.proven-config/v1",
6
- "policy": {
7
- "ref": "sha256:6141a8ea990c5063b77e090ae8f37f9c539d8aa8f58dcceb30f3a82f97e57319",
8
- "value": {
9
- "alpha": 0.3,
10
- "subjectWeight": 1,
11
- "mmrLambda": 0.5,
12
- "bodyWeight": 1.5,
13
- "typePenaltyFactor": 0.5
14
- }
15
- },
16
- "layer": "framework/node-cli",
17
- "compatibility": {
18
- "ruflo": ">=3.24.0"
19
- },
20
- "benchmark": {
21
- "corpus": "ADR-081-labelled-v1",
22
- "corpusHash": "sha256:2f700b5c363e20a3bd88ce2bc9b87bbbbaa61732c6177894c6ec37890f888982"
23
- },
24
- "receipt": {
25
- "heldOutDelta": 0.07381404928570845,
26
- "redblue": "PASS",
27
- "drift": 0,
28
- "canary": {
29
- "rollbackRate": 0,
30
- "latencyP95": 244.612458000076,
31
- "costPerTask": 0
32
- },
33
- "receiptCoverage": 1
34
- },
35
- "platform": [
36
- "linux",
37
- "macOS",
38
- "windows"
39
- ]
40
- },
41
- "previous": ""
42
- }