claude-flow 3.57.2 → 3.58.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 (59) hide show
  1. package/.claude/proven-config.json +1 -1
  2. package/.claude-plugin/marketplace.json +11 -0
  3. package/README.md +1 -0
  4. package/node_modules/@claude-flow/codex/README.md +78 -0
  5. package/node_modules/@claude-flow/codex/dist/activity/cli.d.ts +3 -0
  6. package/node_modules/@claude-flow/codex/dist/activity/cli.d.ts.map +1 -0
  7. package/node_modules/@claude-flow/codex/dist/activity/cli.js +115 -0
  8. package/node_modules/@claude-flow/codex/dist/activity/cli.js.map +1 -0
  9. package/node_modules/@claude-flow/codex/dist/activity/files.d.ts +14 -0
  10. package/node_modules/@claude-flow/codex/dist/activity/files.d.ts.map +1 -0
  11. package/node_modules/@claude-flow/codex/dist/activity/files.js +142 -0
  12. package/node_modules/@claude-flow/codex/dist/activity/files.js.map +1 -0
  13. package/node_modules/@claude-flow/codex/dist/activity/parser.d.ts +21 -0
  14. package/node_modules/@claude-flow/codex/dist/activity/parser.d.ts.map +1 -0
  15. package/node_modules/@claude-flow/codex/dist/activity/parser.js +179 -0
  16. package/node_modules/@claude-flow/codex/dist/activity/parser.js.map +1 -0
  17. package/node_modules/@claude-flow/codex/dist/activity/reader.d.ts +20 -0
  18. package/node_modules/@claude-flow/codex/dist/activity/reader.d.ts.map +1 -0
  19. package/node_modules/@claude-flow/codex/dist/activity/reader.js +106 -0
  20. package/node_modules/@claude-flow/codex/dist/activity/reader.js.map +1 -0
  21. package/node_modules/@claude-flow/codex/dist/activity/sanitize.d.ts +4 -0
  22. package/node_modules/@claude-flow/codex/dist/activity/sanitize.d.ts.map +1 -0
  23. package/node_modules/@claude-flow/codex/dist/activity/sanitize.js +27 -0
  24. package/node_modules/@claude-flow/codex/dist/activity/sanitize.js.map +1 -0
  25. package/node_modules/@claude-flow/codex/dist/activity/types.d.ts +31 -0
  26. package/node_modules/@claude-flow/codex/dist/activity/types.d.ts.map +1 -0
  27. package/node_modules/@claude-flow/codex/dist/activity/types.js +5 -0
  28. package/node_modules/@claude-flow/codex/dist/activity/types.js.map +1 -0
  29. package/node_modules/@claude-flow/codex/dist/activity/viewer.d.ts +21 -0
  30. package/node_modules/@claude-flow/codex/dist/activity/viewer.d.ts.map +1 -0
  31. package/node_modules/@claude-flow/codex/dist/activity/viewer.js +168 -0
  32. package/node_modules/@claude-flow/codex/dist/activity/viewer.js.map +1 -0
  33. package/node_modules/@claude-flow/codex/dist/cli.js +3 -0
  34. package/node_modules/@claude-flow/codex/dist/cli.js.map +1 -1
  35. package/node_modules/@claude-flow/mcp/dist/server.d.ts.map +1 -1
  36. package/node_modules/@claude-flow/mcp/dist/server.js +5 -3
  37. package/node_modules/@claude-flow/mcp/dist/server.js.map +1 -1
  38. package/node_modules/@claude-flow/mcp/dist/types.d.ts +11 -0
  39. package/node_modules/@claude-flow/mcp/dist/types.d.ts.map +1 -1
  40. package/node_modules/@claude-flow/mcp/dist/types.js.map +1 -1
  41. package/package.json +1 -1
  42. package/v3/@claude-flow/cli/README.md +1 -0
  43. package/v3/@claude-flow/cli/catalog-manifest.json +2 -2
  44. package/v3/@claude-flow/cli/dist/src/commands/agent.js +4 -1
  45. package/v3/@claude-flow/cli/dist/src/commands/mcp.js +66 -6
  46. package/v3/@claude-flow/cli/dist/src/commands/memory.js +53 -2
  47. package/v3/@claude-flow/cli/dist/src/mcp-server.d.ts +5 -0
  48. package/v3/@claude-flow/cli/dist/src/mcp-server.js +39 -0
  49. package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-tools.js +28 -0
  50. package/v3/@claude-flow/cli/dist/src/mcp-tools/claims-tools.js +25 -15
  51. package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +13 -3
  52. package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.js +43 -4
  53. package/v3/@claude-flow/cli/dist/src/memory/memory-peek.d.ts +28 -0
  54. package/v3/@claude-flow/cli/dist/src/memory/memory-peek.js +222 -0
  55. package/v3/@claude-flow/cli/dist/src/memory/model-cache-dir.d.ts +11 -0
  56. package/v3/@claude-flow/cli/dist/src/memory/model-cache-dir.js +17 -0
  57. package/v3/@claude-flow/cli/dist/src/parser.js +3 -2
  58. package/v3/@claude-flow/cli/dist/src/ruvector/task-embedder.js +38 -4
  59. package/v3/@claude-flow/cli/package.json +1 -1
@@ -0,0 +1,222 @@
1
+ /**
2
+ * #3508: read-only memory route/peek.
3
+ *
4
+ * A health check needs to know which memory store files a cwd resolves to,
5
+ * and what is in them, without changing anything to find out. `memory stats`
6
+ * (even after #3463/#3448) still calls `ensureInitialized()` when no explicit
7
+ * path is given, and answers for one file per call. This module reports
8
+ * BOTH files — the sql.js `memory.db` the CLI writes and its native
9
+ * `agentdb-memory.db` sibling the MCP/bridge path writes — in one read-only
10
+ * pass, and says which resolution rule picked the root.
11
+ *
12
+ * Contract (do not relax without re-reading #3508):
13
+ * - never creates, initializes, or migrates anything;
14
+ * - never opens a file that does not exist (`existsSync` gated before any
15
+ * open attempt, for both engines);
16
+ * - every open is `readonly`/`fileMustExist` (native) or a one-shot byte
17
+ * buffer handed to sql.js, which is never written back to disk;
18
+ * - `rows: null` means "could not read" and is never a count of 0, so an
19
+ * empty store and an unreadable one never look the same;
20
+ * - an encrypted-at-rest `memory.db` reports `encrypted: true` and
21
+ * `rows: null`, but its size is still reported.
22
+ */
23
+ import { closeSync, existsSync, openSync, readFileSync, readSync, statSync } from 'node:fs';
24
+ import path from 'node:path';
25
+ import { getMemoryRoot, resolveDbPath } from './memory-initializer.js';
26
+ import { siblingAgentDbPath } from './memory-bridge.js';
27
+ import { isEncryptedBlob } from '../encryption/vault.js';
28
+ // Mirrors the `ACTIVE_MEMORY_ROW_SQL` convention in memory-initializer.ts:
29
+ // legacy rows with a NULL status predate soft-delete semantics and count.
30
+ const ACTIVE_ROW_SQL = `(status = 'active' OR status IS NULL)`;
31
+ const ENCRYPTION_SNIFF_LEN = 64; // RFE1 magic(4)+iv(12)+tag(16); 64 gives headroom.
32
+ function safeStatSize(filePath) {
33
+ try {
34
+ return statSync(filePath).size;
35
+ }
36
+ catch {
37
+ return null;
38
+ }
39
+ }
40
+ function readHeaderBytes(filePath, len) {
41
+ const fd = openSync(filePath, 'r');
42
+ try {
43
+ const buf = Buffer.alloc(len);
44
+ const bytesRead = readSync(fd, buf, 0, len, 0);
45
+ return buf.subarray(0, bytesRead);
46
+ }
47
+ finally {
48
+ closeSync(fd);
49
+ }
50
+ }
51
+ function latestMillis(values) {
52
+ let latest = -Infinity;
53
+ for (const raw of values) {
54
+ const millis = typeof raw === 'number' ? raw : Number(raw);
55
+ if (Number.isFinite(millis))
56
+ latest = Math.max(latest, millis);
57
+ }
58
+ return latest;
59
+ }
60
+ /** sql.js is read as a one-shot in-memory byte buffer — nothing is ever
61
+ * written back, so reading this file has no on-disk side effect. */
62
+ async function probeSqlJsStore(dbPath) {
63
+ try {
64
+ if (isEncryptedBlob(readHeaderBytes(dbPath, ENCRYPTION_SNIFF_LEN))) {
65
+ return { rows: null, lastWrite: null, keys: null, encrypted: true };
66
+ }
67
+ }
68
+ catch {
69
+ /* header read failed (permissions/race) — fall through to the open attempt */
70
+ }
71
+ try {
72
+ const initSqlJs = (await import('sql.js')).default ?? (await import('sql.js'));
73
+ const SQL = await (typeof initSqlJs === 'function' ? initSqlJs() : initSqlJs.default());
74
+ const buf = readFileSync(dbPath);
75
+ const db = new SQL.Database(new Uint8Array(buf));
76
+ try {
77
+ const tables = db.exec("SELECT name FROM sqlite_master WHERE type='table' AND name='memory_entries'");
78
+ if (!tables.length)
79
+ return { rows: null, lastWrite: null, keys: null };
80
+ const result = db.exec(`SELECT namespace, key, created_at, updated_at FROM memory_entries WHERE ${ACTIVE_ROW_SQL}`);
81
+ const values = result[0]?.values ?? [];
82
+ const keys = new Set();
83
+ let last = -Infinity;
84
+ for (const [namespace, key, createdAt, updatedAt] of values) {
85
+ keys.add(`${String(namespace)}\u0000${String(key)}`);
86
+ last = Math.max(last, latestMillis([createdAt, updatedAt]));
87
+ }
88
+ return {
89
+ rows: values.length,
90
+ lastWrite: Number.isFinite(last) ? new Date(last).toISOString() : null,
91
+ keys,
92
+ };
93
+ }
94
+ finally {
95
+ try {
96
+ db.close();
97
+ }
98
+ catch { /* best effort */ }
99
+ }
100
+ }
101
+ catch {
102
+ return { rows: null, lastWrite: null, keys: null };
103
+ }
104
+ }
105
+ /** better-sqlite3 is an optional native dependency — absence must degrade
106
+ * to "could not read", never throw. Opened `readonly`/`fileMustExist`, same
107
+ * as `countSiblingStoreRows` in sibling-store.ts. */
108
+ async function probeNativeStore(dbPath) {
109
+ try {
110
+ const require = (await import('node:module')).createRequire(import.meta.url);
111
+ const Database = require('better-sqlite3');
112
+ const db = new Database(dbPath, { readonly: true, fileMustExist: true });
113
+ try {
114
+ const table = db
115
+ .prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='memory_entries'")
116
+ .get();
117
+ if (!table)
118
+ return { rows: null, lastWrite: null, keys: null };
119
+ const rows = db
120
+ .prepare(`SELECT namespace, key, created_at, updated_at FROM memory_entries WHERE ${ACTIVE_ROW_SQL}`)
121
+ .all();
122
+ const keys = new Set();
123
+ let last = -Infinity;
124
+ for (const row of rows) {
125
+ keys.add(`${String(row.namespace)}\u0000${String(row.key)}`);
126
+ last = Math.max(last, latestMillis([row.created_at, row.updated_at]));
127
+ }
128
+ return {
129
+ rows: rows.length,
130
+ lastWrite: Number.isFinite(last) ? new Date(last).toISOString() : null,
131
+ keys,
132
+ };
133
+ }
134
+ finally {
135
+ try {
136
+ db.close();
137
+ }
138
+ catch { /* best effort */ }
139
+ }
140
+ }
141
+ catch {
142
+ return { rows: null, lastWrite: null, keys: null };
143
+ }
144
+ }
145
+ /** Same precedence `getMemoryRoot()`/`resolveDbPath()` already own — this
146
+ * only *labels* which rule decided, it never re-derives the path itself. */
147
+ function decideSource(cliFlag) {
148
+ if (cliFlag && cliFlag.trim().length > 0)
149
+ return 'path';
150
+ if (process.env.CLAUDE_FLOW_DB_PATH && process.env.CLAUDE_FLOW_DB_PATH.trim().length > 0) {
151
+ return 'CLAUDE_FLOW_DB_PATH';
152
+ }
153
+ if (process.env.CLAUDE_FLOW_MEMORY_PATH && process.env.CLAUDE_FLOW_MEMORY_PATH.trim().length > 0) {
154
+ return 'CLAUDE_FLOW_MEMORY_PATH';
155
+ }
156
+ const configCandidates = [
157
+ path.resolve(process.cwd(), 'claude-flow.config.json'),
158
+ path.resolve(process.cwd(), '.claude-flow', 'config.json'),
159
+ ];
160
+ for (const configPath of configCandidates) {
161
+ if (!existsSync(configPath))
162
+ continue;
163
+ try {
164
+ const raw = JSON.parse(readFileSync(configPath, 'utf-8'));
165
+ const fromConfig = raw?.memory?.persistPath ?? raw?.memory?.path;
166
+ if (typeof fromConfig === 'string' && fromConfig.trim().length > 0)
167
+ return 'config';
168
+ }
169
+ catch {
170
+ /* malformed config — getMemoryRoot() falls through to default too */
171
+ }
172
+ }
173
+ return 'default';
174
+ }
175
+ async function describeStore(role, storePath, probe) {
176
+ if (!existsSync(storePath)) {
177
+ return {
178
+ store: { role, path: storePath, exists: false, rows: null, lastWrite: null, sizeBytes: null, walBytes: null },
179
+ keys: null,
180
+ };
181
+ }
182
+ const result = await probe(storePath);
183
+ const sizeBytes = safeStatSize(storePath);
184
+ const walBytes = safeStatSize(`${storePath}-wal`) ?? 0;
185
+ return {
186
+ store: {
187
+ role,
188
+ path: storePath,
189
+ exists: true,
190
+ rows: result.rows,
191
+ lastWrite: result.lastWrite,
192
+ sizeBytes,
193
+ walBytes,
194
+ ...(result.encrypted ? { encrypted: true } : {}),
195
+ },
196
+ keys: result.keys,
197
+ };
198
+ }
199
+ /**
200
+ * Resolve the route and report both stores, read-only. Never creates,
201
+ * initializes, or migrates anything, on an empty project or any other.
202
+ */
203
+ export async function memoryPeek(opts) {
204
+ const cliFlag = opts?.path;
205
+ const cliPath = resolveDbPath(cliFlag);
206
+ const mcpPath = siblingAgentDbPath(cliPath);
207
+ const root = { path: cliFlag ? path.dirname(cliPath) : getMemoryRoot(), source: decideSource(cliFlag) };
208
+ const cliDescribed = await describeStore('cli', cliPath, probeSqlJsStore);
209
+ const stores = [cliDescribed.store];
210
+ let mcpKeys = null;
211
+ if (mcpPath) {
212
+ const mcpDescribed = await describeStore('mcp', mcpPath, probeNativeStore);
213
+ stores.push(mcpDescribed.store);
214
+ mcpKeys = mcpDescribed.keys;
215
+ }
216
+ const cliKeys = cliDescribed.keys;
217
+ const sharedKeys = cliKeys && mcpKeys
218
+ ? [...cliKeys].filter((key) => mcpKeys.has(key)).length
219
+ : null;
220
+ return { cwd: process.cwd(), root, stores, sharedKeys };
221
+ }
222
+ //# sourceMappingURL=memory-peek.js.map
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Resolve a writable cache directory for ONNX model downloads.
3
+ *
4
+ * ADR-454: duplicated intentionally from
5
+ * `@claude-flow/embeddings/src/transformers-loader.ts`'s
6
+ * `resolveModelCacheDir()` rather than imported, since `@claude-flow/cli`
7
+ * has no dependency on `@claude-flow/embeddings` (see the circular
8
+ * optional-dep note in `memory-initializer.ts`).
9
+ */
10
+ export declare function resolveModelCacheDir(): string;
11
+ //# sourceMappingURL=model-cache-dir.d.ts.map
@@ -0,0 +1,17 @@
1
+ import * as os from 'node:os';
2
+ import * as path from 'node:path';
3
+ /**
4
+ * Resolve a writable cache directory for ONNX model downloads.
5
+ *
6
+ * ADR-454: duplicated intentionally from
7
+ * `@claude-flow/embeddings/src/transformers-loader.ts`'s
8
+ * `resolveModelCacheDir()` rather than imported, since `@claude-flow/cli`
9
+ * has no dependency on `@claude-flow/embeddings` (see the circular
10
+ * optional-dep note in `memory-initializer.ts`).
11
+ */
12
+ export function resolveModelCacheDir() {
13
+ return (process.env.TRANSFORMERS_CACHE ||
14
+ process.env.HF_HOME ||
15
+ path.join(os.homedir(), '.cache', 'ruflo', 'models'));
16
+ }
17
+ //# sourceMappingURL=model-cache-dir.js.map
@@ -184,8 +184,9 @@ export class CommandParser {
184
184
  let commandSlotAvailable = true;
185
185
  while (i < args.length) {
186
186
  const arg = args[i];
187
- // Check for end of flags marker
188
- if (arg === '--') {
187
+ // Check for end of flags marker. Only the first "--" changes parser
188
+ // state; a later literal "--" is an ordinary positional (#4310).
189
+ if (parsingFlags && arg === '--') {
189
190
  parsingFlags = false;
190
191
  i++;
191
192
  continue;
@@ -19,6 +19,8 @@
19
19
  *
20
20
  * @module task-embedder
21
21
  */
22
+ import * as fs from 'node:fs';
23
+ import { resolveModelCacheDir } from '../memory/model-cache-dir.js';
22
24
  // ============================================================================
23
25
  // FNV-1a-32 hash (matches scripts/gen-seed-corpus.mjs + router-trajectory.ts)
24
26
  // ============================================================================
@@ -38,18 +40,48 @@ function cacheKey(task) {
38
40
  // same function (xenova's pipeline returns a callable that accepts either),
39
41
  // so we don't pay the ONNX model-load cost twice.
40
42
  let _extractorPromise = null;
43
+ /**
44
+ * ADR-454: distinguishes a null-extractor result caused by a genuinely
45
+ * missing dependency (permanent — nothing changes without a reinstall) from
46
+ * one caused by an environmental/fixable failure during `pipeline(...)`
47
+ * init, such as EACCES on the model cache dir (retryable).
48
+ */
49
+ let _extractorDegradedReason = null;
50
+ let _extractorLastAttemptAt = 0;
51
+ const EXTRACTOR_RETRY_INTERVAL_MS = 60_000;
41
52
  function loadExtractor() {
42
- if (_extractorPromise !== null)
43
- return _extractorPromise;
53
+ if (_extractorPromise !== null) {
54
+ const isRetryableDue = _extractorDegradedReason === 'retryable' &&
55
+ Date.now() - _extractorLastAttemptAt >= EXTRACTOR_RETRY_INTERVAL_MS;
56
+ if (!isRetryableDue)
57
+ return _extractorPromise;
58
+ // Fall through to re-attempt — the retryable failure may now be fixed.
59
+ }
60
+ _extractorLastAttemptAt = Date.now();
44
61
  _extractorPromise = (async () => {
62
+ let packageImportable = false;
45
63
  try {
46
64
  const specifier = '@xenova/transformers';
47
65
  const mod = await import(/* @vite-ignore */ specifier).catch(() => null);
48
- if (!mod || typeof mod.pipeline !== 'function')
66
+ if (!mod || typeof mod.pipeline !== 'function') {
67
+ _extractorDegradedReason = 'permanent';
49
68
  return null;
50
- return await mod.pipeline('feature-extraction', 'Xenova/all-MiniLM-L6-v2', { quantized: true });
69
+ }
70
+ packageImportable = true;
71
+ // ADR-454: route model downloads to a user-writable cache dir — the
72
+ // package-relative default is root-owned under a system-prefix
73
+ // global install, which throws EACCES for the runtime user.
74
+ const cacheDir = resolveModelCacheDir();
75
+ fs.mkdirSync(cacheDir, { recursive: true });
76
+ const env = mod.env;
77
+ if (env)
78
+ env.cacheDir = cacheDir;
79
+ const extractor = await mod.pipeline('feature-extraction', 'Xenova/all-MiniLM-L6-v2', { quantized: true });
80
+ _extractorDegradedReason = null;
81
+ return extractor;
51
82
  }
52
83
  catch {
84
+ _extractorDegradedReason = packageImportable ? 'retryable' : 'permanent';
53
85
  return null;
54
86
  }
55
87
  })();
@@ -233,5 +265,7 @@ export function __resetTaskEmbedderForTests() {
233
265
  _hits = 0;
234
266
  _misses = 0;
235
267
  _extractorPromise = null;
268
+ _extractorDegradedReason = null;
269
+ _extractorLastAttemptAt = 0;
236
270
  }
237
271
  //# sourceMappingURL=task-embedder.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claude-flow/cli",
3
- "version": "3.57.2",
3
+ "version": "3.58.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",