claude-flow 3.77.1 → 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 (43) 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-initializer.js +5 -4
  34. package/v3/@claude-flow/cli/dist/src/missions/schemas.d.ts +38 -38
  35. package/v3/@claude-flow/cli/dist/src/mods/command-registry/schema.d.ts +210 -210
  36. package/v3/@claude-flow/cli/dist/src/services/managed-run-store.d.ts +11 -0
  37. package/v3/@claude-flow/cli/dist/src/services/managed-run-store.js +125 -3
  38. package/v3/@claude-flow/cli/dist/src/services/policy-runtime.d.ts +3 -0
  39. package/v3/@claude-flow/cli/dist/src/services/policy-runtime.js +3 -1
  40. package/v3/@claude-flow/cli/package.json +9 -6
  41. package/v3/@claude-flow/guidance/package.json +1 -0
  42. package/.claude/.proven-config-version +0 -1
  43. package/.claude/proven-config.json +0 -42
@@ -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.1",
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",
@@ -138,7 +141,7 @@
138
141
  },
139
142
  "optionalDependencies": {
140
143
  "@agntcy/slim-bindings": "2.1.1",
141
- "@claude-flow/aidefence": "3.2.1",
144
+ "@claude-flow/aidefence": "3.2.2",
142
145
  "@claude-flow/memory": "3.3.3",
143
146
  "@metaharness/flywheel": "~0.1.10",
144
147
  "@metaharness/radio": "~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": 1794584864742,
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
- }