@claude-flow/cli 3.7.0-alpha.8 → 3.7.0-alpha.80

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 (291) hide show
  1. package/.claude/agents/github/release-manager.md +2 -2
  2. package/.claude/agents/github/release-swarm.md +1 -1
  3. package/.claude/agents/github/repo-architect.md +2 -2
  4. package/.claude/agents/github/swarm-pr.md +1 -1
  5. package/.claude/agents/github/workflow-automation.md +2 -2
  6. package/.claude/commands/github/code-review-swarm.md +1 -1
  7. package/.claude/commands/github/issue-tracker.md +3 -3
  8. package/.claude/commands/github/release-manager.md +5 -3
  9. package/.claude/commands/github/release-swarm.md +1 -1
  10. package/.claude/commands/github/repo-architect.md +2 -2
  11. package/.claude/commands/github/swarm-issue.md +4 -1
  12. package/.claude/commands/github/swarm-pr.md +6 -3
  13. package/.claude/commands/github/sync-coordinator.md +3 -1
  14. package/.claude/commands/github/workflow-automation.md +2 -2
  15. package/.claude/helpers/github-safe.js +95 -60
  16. package/.claude/helpers/github-setup.sh +26 -9
  17. package/.claude/helpers/hook-handler.cjs +12 -4
  18. package/.claude/helpers/statusline.cjs +31 -2
  19. package/.claude/helpers/statusline.js +35 -4
  20. package/.claude/settings.json +1 -1
  21. package/.claude/skills/dual-mode/README.md +71 -0
  22. package/.claude/skills/dual-mode/dual-collect.md +103 -0
  23. package/.claude/skills/dual-mode/dual-coordinate.md +85 -0
  24. package/.claude/skills/dual-mode/dual-spawn.md +81 -0
  25. package/.claude/skills/flow-nexus-neural/SKILL.md +0 -11
  26. package/.claude/skills/flow-nexus-platform/SKILL.md +2 -5
  27. package/.claude/skills/flow-nexus-swarm/SKILL.md +0 -6
  28. package/.claude/skills/github-code-review/SKILL.md +2 -17
  29. package/.claude/skills/github-multi-repo/SKILL.md +4 -16
  30. package/.claude/skills/github-project-management/SKILL.md +18 -33
  31. package/.claude/skills/github-release-management/SKILL.md +4 -21
  32. package/.claude/skills/github-workflow-automation/SKILL.md +8 -26
  33. package/.claude/skills/reasoningbank-intelligence/SKILL.md +2 -2
  34. package/.claude/skills/sparc-methodology/SKILL.md +2 -11
  35. package/.claude/skills/stream-chain/SKILL.md +0 -3
  36. package/.claude/skills/swarm-advanced/SKILL.md +2 -5
  37. package/.claude/skills/swarm-orchestration/SKILL.md +1 -1
  38. package/.claude/skills/verification-quality/SKILL.md +120 -78
  39. package/README.md +57 -38
  40. package/bin/cli.js +15 -2
  41. package/bin/mcp-server.js +1 -1
  42. package/dist/src/__probe.d.ts +2 -0
  43. package/dist/src/__probe.d.ts.map +1 -0
  44. package/dist/src/__probe.js +5 -0
  45. package/dist/src/__probe.js.map +1 -0
  46. package/dist/src/commands/agent-wasm.js +2 -2
  47. package/dist/src/commands/agent-wasm.js.map +1 -1
  48. package/dist/src/commands/benchmark-cosign.d.ts +29 -0
  49. package/dist/src/commands/benchmark-cosign.d.ts.map +1 -0
  50. package/dist/src/commands/benchmark-cosign.js +222 -0
  51. package/dist/src/commands/benchmark-cosign.js.map +1 -0
  52. package/dist/src/commands/benchmark-verify.d.ts +21 -0
  53. package/dist/src/commands/benchmark-verify.d.ts.map +1 -0
  54. package/dist/src/commands/benchmark-verify.js +202 -0
  55. package/dist/src/commands/benchmark-verify.js.map +1 -0
  56. package/dist/src/commands/daemon.d.ts +20 -0
  57. package/dist/src/commands/daemon.d.ts.map +1 -1
  58. package/dist/src/commands/daemon.js +366 -7
  59. package/dist/src/commands/daemon.js.map +1 -1
  60. package/dist/src/commands/doctor.d.ts.map +1 -1
  61. package/dist/src/commands/doctor.js +224 -46
  62. package/dist/src/commands/doctor.js.map +1 -1
  63. package/dist/src/commands/embeddings.d.ts.map +1 -1
  64. package/dist/src/commands/embeddings.js +18 -9
  65. package/dist/src/commands/embeddings.js.map +1 -1
  66. package/dist/src/commands/hive-mind.d.ts.map +1 -1
  67. package/dist/src/commands/hive-mind.js +25 -7
  68. package/dist/src/commands/hive-mind.js.map +1 -1
  69. package/dist/src/commands/hooks.d.ts.map +1 -1
  70. package/dist/src/commands/hooks.js +56 -29
  71. package/dist/src/commands/hooks.js.map +1 -1
  72. package/dist/src/commands/init.d.ts.map +1 -1
  73. package/dist/src/commands/init.js +21 -1
  74. package/dist/src/commands/init.js.map +1 -1
  75. package/dist/src/commands/memory.d.ts.map +1 -1
  76. package/dist/src/commands/memory.js +128 -3
  77. package/dist/src/commands/memory.js.map +1 -1
  78. package/dist/src/commands/start.js +1 -1
  79. package/dist/src/commands/start.js.map +1 -1
  80. package/dist/src/commands/swarm.js +1 -1
  81. package/dist/src/commands/swarm.js.map +1 -1
  82. package/dist/src/commands/task.d.ts.map +1 -1
  83. package/dist/src/commands/task.js +8 -4
  84. package/dist/src/commands/task.js.map +1 -1
  85. package/dist/src/config-adapter.js +1 -1
  86. package/dist/src/config-adapter.js.map +1 -1
  87. package/dist/src/index.d.ts +5 -1
  88. package/dist/src/index.d.ts.map +1 -1
  89. package/dist/src/index.js +61 -18
  90. package/dist/src/index.js.map +1 -1
  91. package/dist/src/init/claudemd-generator.d.ts.map +1 -1
  92. package/dist/src/init/claudemd-generator.js +1 -0
  93. package/dist/src/init/claudemd-generator.js.map +1 -1
  94. package/dist/src/init/executor.d.ts.map +1 -1
  95. package/dist/src/init/executor.js +133 -0
  96. package/dist/src/init/executor.js.map +1 -1
  97. package/dist/src/init/helpers-generator.d.ts +1 -0
  98. package/dist/src/init/helpers-generator.d.ts.map +1 -1
  99. package/dist/src/init/helpers-generator.js +19 -2
  100. package/dist/src/init/helpers-generator.js.map +1 -1
  101. package/dist/src/init/mcp-generator.js +4 -4
  102. package/dist/src/init/mcp-generator.js.map +1 -1
  103. package/dist/src/init/settings-generator.d.ts.map +1 -1
  104. package/dist/src/init/settings-generator.js +84 -19
  105. package/dist/src/init/settings-generator.js.map +1 -1
  106. package/dist/src/init/statusline-generator.d.ts.map +1 -1
  107. package/dist/src/init/statusline-generator.js +75 -31
  108. package/dist/src/init/statusline-generator.js.map +1 -1
  109. package/dist/src/init/types.d.ts +30 -0
  110. package/dist/src/init/types.d.ts.map +1 -1
  111. package/dist/src/init/types.js +18 -5
  112. package/dist/src/init/types.js.map +1 -1
  113. package/dist/src/mcp-client.d.ts.map +1 -1
  114. package/dist/src/mcp-client.js +12 -0
  115. package/dist/src/mcp-client.js.map +1 -1
  116. package/dist/src/mcp-server.d.ts.map +1 -1
  117. package/dist/src/mcp-server.js +38 -5
  118. package/dist/src/mcp-server.js.map +1 -1
  119. package/dist/src/mcp-tools/agent-execute-core.d.ts +3 -2
  120. package/dist/src/mcp-tools/agent-execute-core.d.ts.map +1 -1
  121. package/dist/src/mcp-tools/agent-execute-core.js +157 -83
  122. package/dist/src/mcp-tools/agent-execute-core.js.map +1 -1
  123. package/dist/src/mcp-tools/agent-tools.d.ts.map +1 -1
  124. package/dist/src/mcp-tools/agent-tools.js +119 -11
  125. package/dist/src/mcp-tools/agent-tools.js.map +1 -1
  126. package/dist/src/mcp-tools/agentdb-tools.d.ts.map +1 -1
  127. package/dist/src/mcp-tools/agentdb-tools.js +101 -24
  128. package/dist/src/mcp-tools/agentdb-tools.js.map +1 -1
  129. package/dist/src/mcp-tools/analyze-tools.js +6 -6
  130. package/dist/src/mcp-tools/analyze-tools.js.map +1 -1
  131. package/dist/src/mcp-tools/autopilot-tools.js +10 -10
  132. package/dist/src/mcp-tools/autopilot-tools.js.map +1 -1
  133. package/dist/src/mcp-tools/browser-session-tools.d.ts.map +1 -1
  134. package/dist/src/mcp-tools/browser-session-tools.js +18 -7
  135. package/dist/src/mcp-tools/browser-session-tools.js.map +1 -1
  136. package/dist/src/mcp-tools/browser-tools.js +23 -23
  137. package/dist/src/mcp-tools/browser-tools.js.map +1 -1
  138. package/dist/src/mcp-tools/claims-tools.js +12 -12
  139. package/dist/src/mcp-tools/claims-tools.js.map +1 -1
  140. package/dist/src/mcp-tools/config-tools.js +6 -6
  141. package/dist/src/mcp-tools/config-tools.js.map +1 -1
  142. package/dist/src/mcp-tools/coordination-tools.js +7 -7
  143. package/dist/src/mcp-tools/coordination-tools.js.map +1 -1
  144. package/dist/src/mcp-tools/daa-tools.js +8 -8
  145. package/dist/src/mcp-tools/daa-tools.js.map +1 -1
  146. package/dist/src/mcp-tools/embeddings-tools.js +10 -10
  147. package/dist/src/mcp-tools/embeddings-tools.js.map +1 -1
  148. package/dist/src/mcp-tools/github-tools.js +5 -5
  149. package/dist/src/mcp-tools/github-tools.js.map +1 -1
  150. package/dist/src/mcp-tools/guidance-tools.js +21 -21
  151. package/dist/src/mcp-tools/guidance-tools.js.map +1 -1
  152. package/dist/src/mcp-tools/hive-consensus-runtime.d.ts +149 -0
  153. package/dist/src/mcp-tools/hive-consensus-runtime.d.ts.map +1 -0
  154. package/dist/src/mcp-tools/hive-consensus-runtime.js +296 -0
  155. package/dist/src/mcp-tools/hive-consensus-runtime.js.map +1 -0
  156. package/dist/src/mcp-tools/hive-mind-tools.d.ts.map +1 -1
  157. package/dist/src/mcp-tools/hive-mind-tools.js +53 -9
  158. package/dist/src/mcp-tools/hive-mind-tools.js.map +1 -1
  159. package/dist/src/mcp-tools/hooks-tools.d.ts +2 -0
  160. package/dist/src/mcp-tools/hooks-tools.d.ts.map +1 -1
  161. package/dist/src/mcp-tools/hooks-tools.js +179 -46
  162. package/dist/src/mcp-tools/hooks-tools.js.map +1 -1
  163. package/dist/src/mcp-tools/managed-agent-tools.d.ts +22 -0
  164. package/dist/src/mcp-tools/managed-agent-tools.d.ts.map +1 -0
  165. package/dist/src/mcp-tools/managed-agent-tools.js +357 -0
  166. package/dist/src/mcp-tools/managed-agent-tools.js.map +1 -0
  167. package/dist/src/mcp-tools/memory-tools.d.ts.map +1 -1
  168. package/dist/src/mcp-tools/memory-tools.js +499 -68
  169. package/dist/src/mcp-tools/memory-tools.js.map +1 -1
  170. package/dist/src/mcp-tools/neural-tools.js +6 -6
  171. package/dist/src/mcp-tools/neural-tools.js.map +1 -1
  172. package/dist/src/mcp-tools/performance-tools.js +6 -6
  173. package/dist/src/mcp-tools/performance-tools.js.map +1 -1
  174. package/dist/src/mcp-tools/progress-tools.js +4 -4
  175. package/dist/src/mcp-tools/progress-tools.js.map +1 -1
  176. package/dist/src/mcp-tools/ruvllm-tools.d.ts.map +1 -1
  177. package/dist/src/mcp-tools/ruvllm-tools.js +27 -11
  178. package/dist/src/mcp-tools/ruvllm-tools.js.map +1 -1
  179. package/dist/src/mcp-tools/security-tools.d.ts.map +1 -1
  180. package/dist/src/mcp-tools/security-tools.js +34 -9
  181. package/dist/src/mcp-tools/security-tools.js.map +1 -1
  182. package/dist/src/mcp-tools/session-tools.d.ts.map +1 -1
  183. package/dist/src/mcp-tools/session-tools.js +130 -6
  184. package/dist/src/mcp-tools/session-tools.js.map +1 -1
  185. package/dist/src/mcp-tools/swarm-tools.d.ts +28 -0
  186. package/dist/src/mcp-tools/swarm-tools.d.ts.map +1 -1
  187. package/dist/src/mcp-tools/swarm-tools.js +80 -9
  188. package/dist/src/mcp-tools/swarm-tools.js.map +1 -1
  189. package/dist/src/mcp-tools/system-tools.d.ts.map +1 -1
  190. package/dist/src/mcp-tools/system-tools.js +91 -18
  191. package/dist/src/mcp-tools/system-tools.js.map +1 -1
  192. package/dist/src/mcp-tools/task-tools.d.ts.map +1 -1
  193. package/dist/src/mcp-tools/task-tools.js +55 -7
  194. package/dist/src/mcp-tools/task-tools.js.map +1 -1
  195. package/dist/src/mcp-tools/terminal-tools.js +5 -5
  196. package/dist/src/mcp-tools/terminal-tools.js.map +1 -1
  197. package/dist/src/mcp-tools/transfer-tools.js +11 -11
  198. package/dist/src/mcp-tools/transfer-tools.js.map +1 -1
  199. package/dist/src/mcp-tools/wasm-agent-tools.js +11 -11
  200. package/dist/src/mcp-tools/wasm-agent-tools.js.map +1 -1
  201. package/dist/src/mcp-tools/workflow-tools.d.ts.map +1 -1
  202. package/dist/src/mcp-tools/workflow-tools.js +118 -10
  203. package/dist/src/mcp-tools/workflow-tools.js.map +1 -1
  204. package/dist/src/memory/ann-router-registry.d.ts +61 -0
  205. package/dist/src/memory/ann-router-registry.d.ts.map +1 -0
  206. package/dist/src/memory/ann-router-registry.js +72 -0
  207. package/dist/src/memory/ann-router-registry.js.map +1 -0
  208. package/dist/src/memory/diskann-registry.d.ts +56 -0
  209. package/dist/src/memory/diskann-registry.d.ts.map +1 -0
  210. package/dist/src/memory/diskann-registry.js +88 -0
  211. package/dist/src/memory/diskann-registry.js.map +1 -0
  212. package/dist/src/memory/memory-bridge.d.ts +4 -0
  213. package/dist/src/memory/memory-bridge.d.ts.map +1 -1
  214. package/dist/src/memory/memory-bridge.js +49 -8
  215. package/dist/src/memory/memory-bridge.js.map +1 -1
  216. package/dist/src/memory/memory-initializer.d.ts +12 -0
  217. package/dist/src/memory/memory-initializer.d.ts.map +1 -1
  218. package/dist/src/memory/memory-initializer.js +98 -19
  219. package/dist/src/memory/memory-initializer.js.map +1 -1
  220. package/dist/src/memory/sona-optimizer.d.ts.map +1 -1
  221. package/dist/src/memory/sona-optimizer.js +3 -0
  222. package/dist/src/memory/sona-optimizer.js.map +1 -1
  223. package/dist/src/parser.d.ts +9 -0
  224. package/dist/src/parser.d.ts.map +1 -1
  225. package/dist/src/parser.js +11 -0
  226. package/dist/src/parser.js.map +1 -1
  227. package/dist/src/plugins/store/discovery.d.ts +15 -4
  228. package/dist/src/plugins/store/discovery.d.ts.map +1 -1
  229. package/dist/src/plugins/store/discovery.js +40 -18
  230. package/dist/src/plugins/store/discovery.js.map +1 -1
  231. package/dist/src/ruvector/agent-wasm.d.ts.map +1 -1
  232. package/dist/src/ruvector/agent-wasm.js +4 -1
  233. package/dist/src/ruvector/agent-wasm.js.map +1 -1
  234. package/dist/src/ruvector/coverage-tools.js +6 -6
  235. package/dist/src/ruvector/coverage-tools.js.map +1 -1
  236. package/dist/src/services/headless-worker-executor.d.ts +6 -0
  237. package/dist/src/services/headless-worker-executor.d.ts.map +1 -1
  238. package/dist/src/services/headless-worker-executor.js +63 -6
  239. package/dist/src/services/headless-worker-executor.js.map +1 -1
  240. package/dist/src/services/worker-daemon.d.ts +80 -2
  241. package/dist/src/services/worker-daemon.d.ts.map +1 -1
  242. package/dist/src/services/worker-daemon.js +372 -11
  243. package/dist/src/services/worker-daemon.js.map +1 -1
  244. package/dist/tsconfig.tsbuildinfo +1 -1
  245. package/package.json +12 -8
  246. package/.claude/agents/core/coder.md +0 -453
  247. package/.claude/agents/core/researcher.md +0 -369
  248. package/.claude/agents/core/reviewer.md +0 -520
  249. package/.claude/agents/core/tester.md +0 -512
  250. package/.claude/agents/goal/goal-planner.md +0 -73
  251. package/.claude/agents/v3/adr-architect.md +0 -184
  252. package/.claude/agents/v3/memory-specialist.md +0 -995
  253. package/.claude/agents/v3/security-auditor.md +0 -771
  254. package/.claude/agents/v3/sparc-orchestrator.md +0 -182
  255. package/.claude/commands/flow-nexus/app-store.md +0 -124
  256. package/.claude/commands/flow-nexus/challenges.md +0 -120
  257. package/.claude/commands/flow-nexus/login-registration.md +0 -65
  258. package/.claude/commands/flow-nexus/neural-network.md +0 -134
  259. package/.claude/commands/flow-nexus/payments.md +0 -116
  260. package/.claude/commands/flow-nexus/sandbox.md +0 -83
  261. package/.claude/commands/flow-nexus/swarm.md +0 -87
  262. package/.claude/commands/flow-nexus/user-tools.md +0 -152
  263. package/.claude/commands/flow-nexus/workflow.md +0 -115
  264. package/.claude/skills/agentic-jujutsu/SKILL.md +0 -645
  265. package/.claude/skills/aidefence-scan.md +0 -151
  266. package/.claude/skills/aidefence.yaml +0 -297
  267. package/.claude/skills/hive-mind-advanced/SKILL.md +0 -712
  268. package/.claude/skills/performance-analysis/SKILL.md +0 -563
  269. package/.claude/skills/secure-review.md +0 -181
  270. package/.claude/skills/worker-benchmarks/skill.md +0 -135
  271. package/.claude/skills/worker-integration/skill.md +0 -154
  272. package/dist/src/ruvector/flash-attention.d.ts +0 -195
  273. package/dist/src/ruvector/flash-attention.d.ts.map +0 -1
  274. package/dist/src/ruvector/flash-attention.js +0 -643
  275. package/dist/src/ruvector/flash-attention.js.map +0 -1
  276. package/dist/src/ruvector/moe-router.d.ts +0 -206
  277. package/dist/src/ruvector/moe-router.d.ts.map +0 -1
  278. package/dist/src/ruvector/moe-router.js +0 -626
  279. package/dist/src/ruvector/moe-router.js.map +0 -1
  280. package/dist/src/services/event-stream.d.ts +0 -25
  281. package/dist/src/services/event-stream.d.ts.map +0 -1
  282. package/dist/src/services/event-stream.js +0 -27
  283. package/dist/src/services/event-stream.js.map +0 -1
  284. package/dist/src/services/loop-worker-runner.d.ts +0 -16
  285. package/dist/src/services/loop-worker-runner.d.ts.map +0 -1
  286. package/dist/src/services/loop-worker-runner.js +0 -34
  287. package/dist/src/services/loop-worker-runner.js.map +0 -1
  288. package/dist/src/services/runtime-capabilities.d.ts +0 -22
  289. package/dist/src/services/runtime-capabilities.d.ts.map +0 -1
  290. package/dist/src/services/runtime-capabilities.js +0 -45
  291. package/dist/src/services/runtime-capabilities.js.map +0 -1
@@ -12,6 +12,7 @@
12
12
  import { existsSync, mkdirSync, readdirSync, readFileSync, unlinkSync, writeFileSync } from 'fs';
13
13
  import { homedir } from 'os';
14
14
  import { join, resolve } from 'path';
15
+ import { createHash } from 'crypto';
15
16
  import { validateIdentifier } from './validate-input.js';
16
17
  // #1604: Align with memory-initializer.ts — single source of truth is .swarm/memory.db
17
18
  const MEMORY_DIR = '.swarm';
@@ -37,6 +38,11 @@ function ensureMemoryDir() {
37
38
  const MAX_KEY_LENGTH = 1024;
38
39
  const MAX_VALUE_SIZE = 1024 * 1024; // 1MB
39
40
  const MAX_QUERY_LENGTH = 4096;
41
+ // #1425 — single source of truth for the dangerous-character set rejected by
42
+ // validateMemoryInput. Imported by sanitizeMemoryKey so write-side sanitization
43
+ // and read-side rejection can never drift apart (the symmetry bug behind #1884).
44
+ const DANGEROUS_KEY_CHARS = /[;&|`$(){}[\]<>!#\\\0]|\.\.[/\\]/g;
45
+ const DANGEROUS_KEY_PATTERN = /[;&|`$(){}[\]<>!#\\\0]|\.\.[/\\]/;
40
46
  function validateMemoryInput(key, value, query, namespace) {
41
47
  if (key && key.length > MAX_KEY_LENGTH) {
42
48
  throw new Error(`Key exceeds maximum length of ${MAX_KEY_LENGTH} characters`);
@@ -48,14 +54,104 @@ function validateMemoryInput(key, value, query, namespace) {
48
54
  throw new Error(`Query exceeds maximum length of ${MAX_QUERY_LENGTH} characters`);
49
55
  }
50
56
  // Reject path traversal and shell metacharacters in keys/namespaces (#1425)
51
- const dangerousPattern = /[;&|`$(){}[\]<>!#\\\0]|\.\.[/\\]/;
52
- if (key && dangerousPattern.test(key)) {
57
+ if (key && DANGEROUS_KEY_PATTERN.test(key)) {
53
58
  throw new Error('Key contains disallowed characters');
54
59
  }
55
- if (namespace && dangerousPattern.test(namespace)) {
60
+ if (namespace && DANGEROUS_KEY_PATTERN.test(namespace)) {
56
61
  throw new Error('Namespace contains disallowed characters');
57
62
  }
58
63
  }
64
+ // #1884 — sanitize a key produced from arbitrary input (markdown headings,
65
+ // frontmatter names, file names) so it survives validateMemoryInput on the
66
+ // read/delete path. Replaces every dangerous char with `_`. Truncates to
67
+ // MAX_KEY_LENGTH so the bound check in validateMemoryInput also passes.
68
+ // Keep this in sync with DANGEROUS_KEY_PATTERN — they share DANGEROUS_KEY_CHARS.
69
+ function sanitizeMemoryKey(key) {
70
+ const safe = key.replace(DANGEROUS_KEY_CHARS, '_');
71
+ return safe.length > MAX_KEY_LENGTH ? safe.slice(0, MAX_KEY_LENGTH) : safe;
72
+ }
73
+ // #1937 — minimal glob → RegExp helper for memory_import_claude exclusion
74
+ // patterns. Anchored. Supports the three operators the issue's voice-fidelity
75
+ // workflow needs:
76
+ // `**` — any chars including path separators
77
+ // `*` — any chars except path separators
78
+ // `?` — exactly one char except a path separator
79
+ // Everything else is regex-escaped. Used to match absolute file paths.
80
+ function globToRegex(pattern) {
81
+ // Tokenize so we can replace `**` before `*` without overlap.
82
+ let out = '';
83
+ for (let i = 0; i < pattern.length; i++) {
84
+ const c = pattern[i];
85
+ if (c === '*' && pattern[i + 1] === '*') {
86
+ out += '.*';
87
+ i++;
88
+ }
89
+ else if (c === '*') {
90
+ out += '[^/\\\\]*';
91
+ }
92
+ else if (c === '?') {
93
+ out += '[^/\\\\]';
94
+ }
95
+ else if (/[.+^$|(){}\[\]\\]/.test(c)) {
96
+ out += '\\' + c;
97
+ }
98
+ else {
99
+ out += c;
100
+ }
101
+ }
102
+ return new RegExp('^' + out + '$');
103
+ }
104
+ // #1883 — resolve the Claude-Code project memory directory for the *current*
105
+ // project. Claude Code hashes the project path differently per host OS, and
106
+ // our previous logic only POSIX-slash-replaced cwd, which breaks for:
107
+ // - WSL bridges where cwd is `/mnt/<drive>/...` but Claude Code is on Windows
108
+ // - paths containing spaces (Claude Code replaces spaces with dashes)
109
+ // - any leading slash on POSIX (Claude Code strips it)
110
+ // Strategy: try several candidate hashes and return the first one with a
111
+ // memory dir that exists. An explicit `projectPathOverride` short-circuits
112
+ // the heuristics for callers that know the canonical project path.
113
+ function resolveProjectMemoryDir(claudeProjectsDir, projectPathOverride) {
114
+ const candidates = new Set();
115
+ const sources = [];
116
+ if (projectPathOverride && projectPathOverride.length > 0) {
117
+ sources.push(projectPathOverride);
118
+ }
119
+ else {
120
+ sources.push(process.cwd());
121
+ }
122
+ for (const source of sources) {
123
+ // Candidate 1: legacy POSIX hash — what shipped before #1883
124
+ candidates.add(source.replace(/\//g, '-'));
125
+ // Candidate 2: WSL `/mnt/<drive>/...` translated to Claude-Code Windows hash
126
+ // e.g. `/mnt/c/Users/x/Project Name` → `C--Users-x-Project-Name`
127
+ const wsl = source.match(/^\/mnt\/([a-z])(\/.*)?$/i);
128
+ if (wsl) {
129
+ const drive = wsl[1].toUpperCase();
130
+ const rest = (wsl[2] ?? '').replace(/\//g, '-').replace(/ /g, '-');
131
+ candidates.add(`${drive}-${rest}`);
132
+ }
133
+ // Candidate 3: POSIX hash with leading dash stripped (Claude Code on macOS/Linux)
134
+ const stripped = source.replace(/\//g, '-').replace(/^-+/, '');
135
+ candidates.add(stripped);
136
+ // Candidate 4: spaces replaced with dashes (Claude Code's space rule)
137
+ candidates.add(source.replace(/\//g, '-').replace(/ /g, '-'));
138
+ // Candidate 5 (#1939): native Win32 path on a Win32 Claude Code install.
139
+ // `C:\Users\tobia\OneDrive\Desktop\Claude Stuff` →
140
+ // `C--Users-tobia-OneDrive-Desktop-Claude-Stuff`. Claude Code's on-disk
141
+ // slug replaces drive-colon AND backslashes AND whitespace with `-`.
142
+ // The earlier candidates only handled forward slashes, so a Win32+Win32
143
+ // setup never matched.
144
+ if (/^[A-Za-z]:[\\/]/.test(source)) {
145
+ candidates.add(source.replace(/[:\\/]/g, '-').replace(/\s+/g, '-'));
146
+ }
147
+ }
148
+ for (const projectHash of candidates) {
149
+ const memDir = join(claudeProjectsDir, projectHash, 'memory');
150
+ if (existsSync(memDir))
151
+ return { memDir, projectHash };
152
+ }
153
+ return null;
154
+ }
59
155
  /**
60
156
  * Check if legacy JSON store exists in old .claude-flow/memory/ location
61
157
  */
@@ -310,57 +406,81 @@ export const memoryTools = [
310
406
  validateMemoryInput(undefined, undefined, query);
311
407
  const startTime = performance.now();
312
408
  try {
409
+ // #1846: feature-detect smartSearch on the resolved memory package.
410
+ // The export landed in @claude-flow/memory@>3.0.0-alpha.14 — older
411
+ // installs pin to a build that exposes search/store/retrieve but
412
+ // not smartSearch. Throwing `is not a function` is hostile; instead
413
+ // detect at runtime and gracefully fall through to plain semantic
414
+ // search with an explicit fallback note.
415
+ let smartFallbackReason;
313
416
  if (input.smart) {
314
- // SmartRetrieval pipeline (ADR-090)
315
- const { smartSearch } = await import('@claude-flow/memory');
316
- // Adapt searchEntries to the SearchFn interface
317
- const rawSearch = async (req) => {
318
- const r = await searchEntries({
319
- query: req.query,
320
- namespace: req.namespace || namespace,
321
- limit: req.limit || limit * 3,
322
- threshold: req.threshold ?? threshold,
323
- });
324
- return {
325
- results: r.results.map(e => ({
326
- id: e.id,
327
- key: e.key,
328
- content: e.content,
329
- score: e.score,
330
- namespace: e.namespace,
331
- })),
417
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
418
+ let memMod;
419
+ try {
420
+ memMod = await import('@claude-flow/memory');
421
+ }
422
+ catch (err) {
423
+ smartFallbackReason = `@claude-flow/memory failed to load: ${err.message}`;
424
+ }
425
+ const smartSearch = memMod && typeof memMod.smartSearch === 'function'
426
+ ? memMod.smartSearch
427
+ : undefined;
428
+ if (smartSearch) {
429
+ // SmartRetrieval pipeline (ADR-090)
430
+ const rawSearch = async (req) => {
431
+ const r = await searchEntries({
432
+ query: req.query,
433
+ namespace: req.namespace || namespace,
434
+ limit: req.limit || limit * 3,
435
+ threshold: req.threshold ?? threshold,
436
+ });
437
+ return {
438
+ results: r.results.map(e => ({
439
+ id: e.id,
440
+ key: e.key,
441
+ content: e.content,
442
+ score: e.score,
443
+ namespace: e.namespace,
444
+ })),
445
+ };
332
446
  };
333
- };
334
- const smartResult = await smartSearch(rawSearch, {
335
- query,
336
- namespace,
337
- limit,
338
- threshold,
339
- });
340
- const duration = performance.now() - startTime;
341
- const results = smartResult.results.map(r => {
342
- let value = r.content;
343
- try {
344
- value = JSON.parse(r.content);
345
- }
346
- catch { /* keep as string */ }
447
+ const smartResult = await smartSearch(rawSearch, {
448
+ query,
449
+ namespace,
450
+ limit,
451
+ threshold,
452
+ });
453
+ const duration = performance.now() - startTime;
454
+ const results = smartResult.results.map((r) => {
455
+ let value = r.content;
456
+ try {
457
+ value = JSON.parse(r.content);
458
+ }
459
+ catch { /* keep as string */ }
460
+ return {
461
+ key: r.key,
462
+ namespace: r.namespace,
463
+ value,
464
+ similarity: r.score,
465
+ };
466
+ });
347
467
  return {
348
- key: r.key,
349
- namespace: r.namespace,
350
- value,
351
- similarity: r.score,
468
+ query,
469
+ results,
470
+ total: results.length,
471
+ searchTime: `${duration.toFixed(2)}ms`,
472
+ backend: 'SmartRetrieval (RRF + MMR + Recency)',
473
+ stats: smartResult.stats,
352
474
  };
353
- });
354
- return {
355
- query,
356
- results,
357
- total: results.length,
358
- searchTime: `${duration.toFixed(2)}ms`,
359
- backend: 'SmartRetrieval (RRF + MMR + Recency)',
360
- stats: smartResult.stats,
361
- };
475
+ }
476
+ // smart=true but smartSearch unavailable on installed package.
477
+ // Fall through to plain search with an explicit warning.
478
+ smartFallbackReason = smartFallbackReason
479
+ ?? 'smartSearch is not exported by the installed @claude-flow/memory build (likely a release lag — see #1846). Falling back to standard semantic search.';
362
480
  }
363
- // Original non-smart path (unchanged)
481
+ // Original non-smart path (unchanged) — also reached when smart was
482
+ // requested but unavailable. We attach `smartFallback` to the
483
+ // response so callers can see the degradation explicitly.
364
484
  const result = await searchEntries({
365
485
  query,
366
486
  namespace,
@@ -390,6 +510,7 @@ export const memoryTools = [
390
510
  total: results.length,
391
511
  searchTime: `${duration.toFixed(2)}ms`,
392
512
  backend: 'HNSW + sql.js',
513
+ ...(smartFallbackReason ? { smartFallback: smartFallbackReason } : {}),
393
514
  };
394
515
  }
395
516
  catch (error) {
@@ -501,7 +622,7 @@ export const memoryTools = [
501
622
  },
502
623
  {
503
624
  name: 'memory_stats',
504
- description: 'Get memory storage statistics including HNSW index status',
625
+ description: 'Get memory storage statistics including HNSW index status Use when native Read/Write is wrong because you need (a) cross-session retrieval by semantic similarity (vector embeddings) not by file path, (b) namespacing across projects without managing directory layout, or (c) the .swarm/memory.db audit trail. For one-shot file I/O, native Read/Write is fine.',
505
626
  category: 'memory',
506
627
  inputSchema: {
507
628
  type: 'object',
@@ -548,7 +669,7 @@ export const memoryTools = [
548
669
  },
549
670
  {
550
671
  name: 'memory_migrate',
551
- description: 'Manually trigger migration from legacy JSON store to sql.js',
672
+ description: 'Manually trigger migration from legacy JSON store to sql.js Use when native Read/Write is wrong because you need (a) cross-session retrieval by semantic similarity (vector embeddings) not by file path, (b) namespacing across projects without managing directory layout, or (c) the .swarm/memory.db audit trail. For one-shot file I/O, native Read/Write is fine.',
552
673
  category: 'memory',
553
674
  inputSchema: {
554
675
  type: 'object',
@@ -587,13 +708,24 @@ export const memoryTools = [
587
708
  // ===== Claude Code Memory Bridge Tools =====
588
709
  {
589
710
  name: 'memory_import_claude',
590
- description: 'Import Claude Code auto-memory files into AgentDB with ONNX vector embeddings. Reads ~/.claude/projects/*/memory/*.md files, parses YAML frontmatter, splits into sections, and stores with 384-dim embeddings for semantic search. Use allProjects=true to import from ALL Claude projects.',
711
+ description: 'Import Claude Code auto-memory files into AgentDB with ONNX vector embeddings. Reads ~/.claude/projects/*/memory/*.md files, parses YAML frontmatter, splits into sections, and stores with 384-dim embeddings for semantic search. Use allProjects=true to import from ALL Claude projects. Pass projectPath to override cwd-based detection (#1883 — required when Ruflo runs in WSL but Claude Code is on Windows). Pass excludeFilePatterns (glob list) or excludeFiles (absolute path list) to skip voice-load-bearing, PII, or persona-restricted files (#1937). Use when native Read/Write is wrong because you need (a) cross-session retrieval by semantic similarity (vector embeddings) not by file path, (b) namespacing across projects without managing directory layout, or (c) the .swarm/memory.db audit trail. For one-shot file I/O, native Read/Write is fine.',
591
712
  category: 'memory',
592
713
  inputSchema: {
593
714
  type: 'object',
594
715
  properties: {
595
716
  allProjects: { type: 'boolean', description: 'Import from all Claude projects (default: current project only)' },
596
717
  namespace: { type: 'string', description: 'Target namespace (default: "claude-memories")' },
718
+ projectPath: { type: 'string', description: '#1883 — explicit project path to hash, used when cwd does not match Claude Code\'s view (e.g. WSL bridge to Windows host). Pass the canonical project root as Claude Code sees it.' },
719
+ excludeFilePatterns: {
720
+ type: 'array',
721
+ items: { type: 'string' },
722
+ description: '#1937 — glob patterns matched against the absolute file path. Files matching ANY pattern are skipped. Supports `*` (any chars within a path segment), `**` (any chars including separators), and `?` (single char). Examples: `**/voice-*.md`, `**/persona-*.md`. Combine with excludeFiles for explicit paths.',
723
+ },
724
+ excludeFiles: {
725
+ type: 'array',
726
+ items: { type: 'string' },
727
+ description: '#1937 — absolute file paths to skip verbatim. Faster than a pattern when the list is known ahead of time (operator captured baselines). Combine with excludeFilePatterns.',
728
+ },
597
729
  },
598
730
  },
599
731
  handler: async (input) => {
@@ -606,9 +738,20 @@ export const memoryTools = [
606
738
  return { success: false, imported: 0, error: vNs.error };
607
739
  }
608
740
  const allProjects = input.allProjects;
741
+ const projectPathOverride = input.projectPath;
609
742
  const claudeProjectsDir = join(homedir(), '.claude', 'projects');
743
+ // #1937 — voice-fidelity / persona-restricted exclusion.
744
+ const excludeFilePatterns = Array.isArray(input.excludeFilePatterns) ? input.excludeFilePatterns : [];
745
+ const excludeFilesList = Array.isArray(input.excludeFiles) ? new Set(input.excludeFiles) : new Set();
746
+ const excludeRegexes = excludeFilePatterns.map(globToRegex);
747
+ const isExcluded = (absPath) => {
748
+ if (excludeFilesList.has(absPath))
749
+ return true;
750
+ return excludeRegexes.some(re => re.test(absPath));
751
+ };
610
752
  // Find memory files
611
753
  const memoryFiles = [];
754
+ let excludedByPattern = 0;
612
755
  if (allProjects) {
613
756
  // Scan all projects
614
757
  if (existsSync(claudeProjectsDir)) {
@@ -620,7 +763,12 @@ export const memoryTools = [
620
763
  if (!existsSync(memDir))
621
764
  continue;
622
765
  for (const file of readdirSync(memDir).filter((f) => f.endsWith('.md'))) {
623
- memoryFiles.push({ path: join(memDir, file), project: project.name, file });
766
+ const absPath = join(memDir, file);
767
+ if (isExcluded(absPath)) {
768
+ excludedByPattern++;
769
+ continue;
770
+ }
771
+ memoryFiles.push({ path: absPath, project: project.name, file });
624
772
  }
625
773
  }
626
774
  }
@@ -628,14 +776,18 @@ export const memoryTools = [
628
776
  }
629
777
  }
630
778
  else {
631
- // Current project only find by CWD hash
632
- const cwd = process.cwd();
633
- const projectHash = cwd.replace(/\//g, '-');
634
- const memDir = join(claudeProjectsDir, projectHash, 'memory');
635
- if (existsSync(memDir)) {
779
+ // #1883 — current project: try multiple candidate hashes (POSIX, WSL-translated,
780
+ // leading-dash-stripped, space-replaced). Caller can pass projectPath to override.
781
+ const resolved = resolveProjectMemoryDir(claudeProjectsDir, projectPathOverride);
782
+ if (resolved) {
636
783
  try {
637
- for (const file of readdirSync(memDir).filter((f) => f.endsWith('.md'))) {
638
- memoryFiles.push({ path: join(memDir, file), project: projectHash, file });
784
+ for (const file of readdirSync(resolved.memDir).filter((f) => f.endsWith('.md'))) {
785
+ const absPath = join(resolved.memDir, file);
786
+ if (isExcluded(absPath)) {
787
+ excludedByPattern++;
788
+ continue;
789
+ }
790
+ memoryFiles.push({ path: absPath, project: resolved.projectHash, file });
639
791
  }
640
792
  }
641
793
  catch { /* scan error */ }
@@ -646,11 +798,28 @@ export const memoryTools = [
646
798
  }
647
799
  let imported = 0;
648
800
  let skipped = 0;
801
+ // #1791.8 — Claude Code's `~/.claude/projects/` accumulates historical
802
+ // project_id directories (truncated forms, sandbox cwds, renamed
803
+ // workspaces) that all contain copies of the same memory files. The
804
+ // previous import indexed each copy under a different `project_id`
805
+ // prefix, producing 5–8x duplication on long-lived homes. Dedupe by
806
+ // file content hash so the same memory is imported once even if it
807
+ // appears under several project directories.
808
+ const seenContentHashes = new Set();
809
+ let duplicatesSkipped = 0;
649
810
  const projects = new Set();
650
811
  for (const memFile of memoryFiles) {
651
812
  projects.add(memFile.project);
652
813
  try {
653
814
  const content = readFileSync(memFile.path, 'utf-8');
815
+ // #1791.8 — Skip if we've already imported this exact content under
816
+ // a different project_id directory.
817
+ const contentHash = createHash('sha256').update(content).digest('hex').slice(0, 16);
818
+ if (seenContentHashes.has(contentHash)) {
819
+ duplicatesSkipped++;
820
+ continue;
821
+ }
822
+ seenContentHashes.add(contentHash);
654
823
  const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
655
824
  let name = memFile.file.replace('.md', '');
656
825
  let body = content;
@@ -664,7 +833,10 @@ export const memoryTools = [
664
833
  // Split into sections for granular search
665
834
  const sections = body.split(/^(?=## )/m).filter(s => s.trim().length > 20);
666
835
  if (sections.length === 0 && body.length > 10) {
667
- await storeEntry({ key: `claude:${memFile.project}:${name}`, value: body.slice(0, 4096), namespace: ns, generateEmbeddingFlag: true });
836
+ // #1884 sanitize key so memory_delete can later remove it. Without
837
+ // this, dangerous chars from frontmatter `name` strand the key.
838
+ const key = sanitizeMemoryKey(`claude:${memFile.project}:${name}`);
839
+ await storeEntry({ key, value: body.slice(0, 4096), namespace: ns, generateEmbeddingFlag: true });
668
840
  imported++;
669
841
  }
670
842
  else {
@@ -674,7 +846,10 @@ export const memoryTools = [
674
846
  const sectionBody = section.replace(/^##\s+.+\n/, '').trim();
675
847
  if (sectionBody.length < 10)
676
848
  continue;
677
- await storeEntry({ key: `claude:${memFile.project}:${name}:${sectionTitle.slice(0, 50)}`, value: sectionBody.slice(0, 4096), namespace: ns, generateEmbeddingFlag: true });
849
+ // #1884 sanitize so any dangerous chars in the heading don't
850
+ // produce keys memory_delete will reject.
851
+ const key = sanitizeMemoryKey(`claude:${memFile.project}:${name}:${sectionTitle.slice(0, 50)}`);
852
+ await storeEntry({ key, value: sectionBody.slice(0, 4096), namespace: ns, generateEmbeddingFlag: true });
678
853
  imported++;
679
854
  }
680
855
  }
@@ -687,6 +862,8 @@ export const memoryTools = [
687
862
  success: true,
688
863
  imported,
689
864
  skipped,
865
+ duplicatesSkipped,
866
+ excludedByPattern,
690
867
  files: memoryFiles.length,
691
868
  projects: projects.size,
692
869
  namespace: ns,
@@ -696,7 +873,7 @@ export const memoryTools = [
696
873
  },
697
874
  {
698
875
  name: 'memory_bridge_status',
699
- description: 'Show Claude Code memory bridge status — AgentDB vectors, SONA learning, intelligence patterns, and connection health.',
876
+ description: 'Show Claude Code memory bridge status — AgentDB vectors, SONA learning, intelligence patterns, and connection health. Use when native Read/Write is wrong because you need (a) cross-session retrieval by semantic similarity (vector embeddings) not by file path, (b) namespacing across projects without managing directory layout, or (c) the .swarm/memory.db audit trail. For one-shot file I/O, native Read/Write is fine.',
700
877
  category: 'memory',
701
878
  inputSchema: { type: 'object', properties: {} },
702
879
  handler: async () => {
@@ -723,14 +900,34 @@ export const memoryTools = [
723
900
  catch { /* ignore */ }
724
901
  }
725
902
  // AgentDB status
903
+ // #1940: previously used `allEntries.entries.length` for the totals,
904
+ // but `listEntries({})` returns the first 20 entries with a separate
905
+ // `total` field for the full row count. So `memory_bridge_status`
906
+ // reported `totalEntries: 0`...20 even when the DB had hundreds of
907
+ // rows. Use `.total` for the count, and surface the namespaces with
908
+ // entries so the report matches what's actually in the store.
726
909
  let agentdbEntries = 0;
727
910
  let claudeMemoryEntries = 0;
911
+ const namespaceCounts = {};
728
912
  try {
729
913
  const { listEntries } = await getMemoryFunctions();
730
914
  const allEntries = await listEntries({});
731
- agentdbEntries = allEntries?.entries?.length ?? 0;
915
+ agentdbEntries = allEntries?.total
916
+ ?? allEntries?.entries?.length ?? 0;
732
917
  const claudeEntries = await listEntries({ namespace: 'claude-memories' });
733
- claudeMemoryEntries = claudeEntries?.entries?.length ?? 0;
918
+ claudeMemoryEntries = claudeEntries?.total
919
+ ?? claudeEntries?.entries?.length ?? 0;
920
+ // Per-namespace counts for the namespaces the reporter referenced
921
+ // (#1940). Best-effort — a namespace with 0 entries is omitted.
922
+ for (const ns of ['default', 'patterns', 'claude-memories', 'auto-memory', 'tasks', 'feedback', 'pretrain']) {
923
+ try {
924
+ const r = await listEntries({ namespace: ns });
925
+ const t = r?.total ?? r?.entries?.length ?? 0;
926
+ if (t > 0)
927
+ namespaceCounts[ns] = t;
928
+ }
929
+ catch { /* skip per-namespace failure */ }
930
+ }
734
931
  }
735
932
  catch { /* ignore */ }
736
933
  // Intelligence status
@@ -744,15 +941,18 @@ export const memoryTools = [
744
941
  catch { /* not initialized */ }
745
942
  return {
746
943
  claudeCode: { memoryFiles: claudeFiles, projects: claudeProjects },
747
- agentdb: { totalEntries: agentdbEntries, claudeMemoryEntries, backend: 'sql.js + ONNX' },
944
+ agentdb: { totalEntries: agentdbEntries, claudeMemoryEntries, namespaces: namespaceCounts, backend: 'sql.js + ONNX' },
748
945
  intelligence,
749
- bridge: { status: claudeMemoryEntries > 0 ? 'connected' : 'not-synced', embedding: 'all-MiniLM-L6-v2 (384-dim)' },
946
+ // #1940: report 'connected' whenever ANY namespace has imported
947
+ // content, not just `claude-memories` — the bridge can be in active
948
+ // use from other import paths (e.g. plugin namespaces, task memory).
949
+ bridge: { status: agentdbEntries > 0 ? 'connected' : 'not-synced', embedding: 'all-MiniLM-L6-v2 (384-dim)' },
750
950
  };
751
951
  },
752
952
  },
753
953
  {
754
954
  name: 'memory_search_unified',
755
- description: 'Search across both Claude Code memories and AgentDB entries using semantic vector similarity. Returns merged, deduplicated results from all namespaces.',
955
+ description: 'Search across both Claude Code memories and AgentDB entries using semantic vector similarity. Returns merged, deduplicated results from all namespaces. Use when native Read/Write is wrong because you need (a) cross-session retrieval by semantic similarity (vector embeddings) not by file path, (b) namespacing across projects without managing directory layout, or (c) the .swarm/memory.db audit trail. For one-shot file I/O, native Read/Write is fine.',
756
956
  category: 'memory',
757
957
  inputSchema: {
758
958
  type: 'object',
@@ -814,5 +1014,236 @@ export const memoryTools = [
814
1014
  };
815
1015
  },
816
1016
  },
1017
+ {
1018
+ // #1916: `ruflo status memory` (the detailed view) referenced an
1019
+ // unregistered `memory_detailed-stats` tool. memory_stats returns a
1020
+ // different shape; this returns what the CLI renders.
1021
+ name: 'memory_detailed-stats',
1022
+ description: 'Detailed memory-store report — backend, entry count, total bytes, per-namespace counts, and (placeholder) perf metrics. Use when native Read/Glob is wrong because the data lives in .swarm/memory.db, not files, and you want an aggregate health view. For a quick count use memory_stats; for "what is in memory" use memory_list.',
1023
+ category: 'memory',
1024
+ inputSchema: { type: 'object', properties: {} },
1025
+ handler: async () => {
1026
+ await ensureInitialized();
1027
+ const { listEntries } = await getMemoryFunctions();
1028
+ const all = await listEntries({ limit: 100000 });
1029
+ const nsCounts = {};
1030
+ let bytes = 0;
1031
+ for (const e of all.entries) {
1032
+ nsCounts[e.namespace] = (nsCounts[e.namespace] || 0) + 1;
1033
+ bytes += e.size || 0;
1034
+ }
1035
+ return {
1036
+ backend: 'sql.js + HNSW',
1037
+ entries: all.total ?? all.entries.length,
1038
+ size: bytes,
1039
+ namespaces: Object.entries(nsCounts).map(([name, entries]) => ({ name, entries })),
1040
+ performance: { avgSearchTime: 0, avgWriteTime: 0, cacheHitRate: 0, hnswEnabled: true },
1041
+ note: 'perf metrics are placeholders; HNSW is always enabled in the sql.js backend',
1042
+ };
1043
+ },
1044
+ },
1045
+ {
1046
+ // #1916: `ruflo memory cleanup` referenced an unregistered `memory_cleanup`
1047
+ // tool. Removes entries whose TTL has expired. Defaults to a dry run —
1048
+ // pass dryRun:false to actually delete.
1049
+ name: 'memory_cleanup',
1050
+ description: 'Prune memory entries whose TTL has expired (dry run by default; pass dryRun:false to delete). Use when native rm is wrong because the entries are rows in .swarm/memory.db, not files. For removing a specific known key use memory_delete. Stale/low-quality pruning is delegated to the agentdb consolidation curator (#1916 follow-up).',
1051
+ category: 'memory',
1052
+ inputSchema: {
1053
+ type: 'object',
1054
+ properties: {
1055
+ dryRun: { type: 'boolean', description: 'Only report candidates, do not delete (default true)' },
1056
+ namespace: { type: 'string', description: 'Limit cleanup to one namespace' },
1057
+ },
1058
+ },
1059
+ handler: async (input) => {
1060
+ await ensureInitialized();
1061
+ const { listEntries, deleteEntry } = await getMemoryFunctions();
1062
+ const dryRun = input.dryRun !== false; // default true
1063
+ const namespace = input.namespace ? String(input.namespace) : undefined;
1064
+ if (namespace) {
1065
+ const v = validateIdentifier(namespace, 'namespace');
1066
+ if (!v.valid)
1067
+ throw new Error(v.error);
1068
+ }
1069
+ const all = await listEntries({ limit: 100000, namespace });
1070
+ const now = Date.now();
1071
+ const expired = all.entries.filter(e => {
1072
+ const exp = e.expiresAt;
1073
+ if (!exp)
1074
+ return false;
1075
+ const t = typeof exp === 'number' ? exp : Date.parse(String(exp));
1076
+ return Number.isFinite(t) && t < now;
1077
+ });
1078
+ let freedBytes = 0;
1079
+ let deleted = 0;
1080
+ if (!dryRun) {
1081
+ for (const e of expired) {
1082
+ try {
1083
+ await deleteEntry({ key: e.key, namespace: e.namespace });
1084
+ freedBytes += e.size || 0;
1085
+ deleted++;
1086
+ }
1087
+ catch { /* ignore individual delete errors */ }
1088
+ }
1089
+ }
1090
+ else {
1091
+ freedBytes = expired.reduce((s, e) => s + (e.size || 0), 0);
1092
+ }
1093
+ return {
1094
+ dryRun,
1095
+ candidates: { expired: expired.length, stale: 0, lowQuality: 0, total: expired.length },
1096
+ deleted: { entries: dryRun ? 0 : deleted, vectors: 0, patterns: 0 },
1097
+ freed: { bytes: freedBytes },
1098
+ note: dryRun ? 'dry run — re-run with dryRun:false to delete' : undefined,
1099
+ };
1100
+ },
1101
+ },
1102
+ {
1103
+ // #1916: `ruflo memory compress` referenced an unregistered tool. The
1104
+ // sql.js backend has no on-disk compression; this reports current sizes.
1105
+ name: 'memory_compress',
1106
+ description: 'Report memory-store size breakdown (the sql.js backend has no on-disk compression — entries are already stored compactly; quantized embeddings via RaBitQ are configured elsewhere). Use when native du is wrong because the data is in .swarm/memory.db. For pruning expired entries use memory_cleanup.',
1107
+ category: 'memory',
1108
+ inputSchema: { type: 'object', properties: {} },
1109
+ handler: async () => {
1110
+ await ensureInitialized();
1111
+ const { listEntries } = await getMemoryFunctions();
1112
+ const all = await listEntries({ limit: 100000 });
1113
+ const bytes = all.entries.reduce((s, e) => s + (e.size || 0), 0);
1114
+ const human = `${bytes}B`;
1115
+ const sizes = { totalSize: human, vectorsSize: 'n/a', textSize: human, patternsSize: 'n/a', indexSize: 'n/a' };
1116
+ return {
1117
+ before: sizes,
1118
+ after: sizes,
1119
+ compression: { ratio: 1, savedBytes: 0, method: 'none' },
1120
+ note: 'sql.js backend has no on-disk compression; nothing to compress. (RaBitQ embedding quantization is a separate feature.)',
1121
+ };
1122
+ },
1123
+ },
1124
+ {
1125
+ // #1916: `ruflo memory export -o <file>` referenced an unregistered tool.
1126
+ // Dumps entry metadata (and values when the backend returns them) to JSON.
1127
+ name: 'memory_export',
1128
+ description: 'Export memory entries to a JSON file (keys, namespaces, timestamps, and values when available). Use when native Write is wrong because the data is rows in .swarm/memory.db, not a file you can copy. For ingesting an export elsewhere use memory_import. (CSV output and embedding-vector export are follow-ups.)',
1129
+ category: 'memory',
1130
+ inputSchema: {
1131
+ type: 'object',
1132
+ properties: {
1133
+ outputPath: { type: 'string', description: 'File path to write the JSON export to' },
1134
+ format: { type: 'string', enum: ['json', 'csv'], description: 'Export format (csv falls back to json today)' },
1135
+ namespace: { type: 'string', description: 'Limit export to one namespace' },
1136
+ includeVectors: { type: 'boolean', description: 'Include embedding vectors (advisory — not exported yet)' },
1137
+ },
1138
+ required: ['outputPath'],
1139
+ },
1140
+ handler: async (input) => {
1141
+ await ensureInitialized();
1142
+ const { listEntries } = await getMemoryFunctions();
1143
+ const outputPath = String(input.outputPath ?? '');
1144
+ if (!outputPath)
1145
+ return { error: 'outputPath is required' };
1146
+ const namespace = input.namespace ? String(input.namespace) : undefined;
1147
+ if (namespace) {
1148
+ const v = validateIdentifier(namespace, 'namespace');
1149
+ if (!v.valid)
1150
+ throw new Error(v.error);
1151
+ }
1152
+ // #2073: pass includeContent so the value field carries the actual
1153
+ // entry body. Without this, `value` is always null because listEntries
1154
+ // strips content by default (callers pay for the JSON parse only when
1155
+ // they need it).
1156
+ const all = await listEntries({ limit: 100000, namespace, includeContent: true });
1157
+ const payload = {
1158
+ schema: 'ruflo-memory-export/v1',
1159
+ exportedAt: new Date().toISOString(),
1160
+ namespace: namespace ?? null,
1161
+ count: all.entries.length,
1162
+ entries: all.entries.map(e => ({
1163
+ key: e.key,
1164
+ namespace: e.namespace,
1165
+ // #2073: `e.content` is the stored value string; `e.value` was a
1166
+ // never-populated alias. Fall back to null only if content is
1167
+ // missing for backward-compat with the schema.
1168
+ value: typeof e.content === 'string' ? e.content : (e.value ?? null),
1169
+ createdAt: e.createdAt, updatedAt: e.updatedAt, accessCount: e.accessCount, hasEmbedding: e.hasEmbedding, size: e.size,
1170
+ })),
1171
+ };
1172
+ try {
1173
+ writeFileSync(outputPath, JSON.stringify(payload, null, 2), 'utf-8');
1174
+ }
1175
+ catch (e) {
1176
+ return { error: `Could not write ${outputPath}: ${e.message}` };
1177
+ }
1178
+ const vectorsWithEmb = all.entries.filter(e => e.hasEmbedding).length;
1179
+ return {
1180
+ outputPath,
1181
+ format: input.format || 'json',
1182
+ exported: { entries: all.entries.length, vectors: vectorsWithEmb, patterns: 0 },
1183
+ fileSize: `${Buffer.byteLength(JSON.stringify(payload))}B`,
1184
+ note: input.format === 'csv' ? 'CSV not implemented yet — wrote JSON' : undefined,
1185
+ };
1186
+ },
1187
+ },
1188
+ {
1189
+ // #1916: `ruflo memory import <file>` referenced an unregistered tool.
1190
+ // Reads a ruflo-memory-export JSON and re-stores each entry.
1191
+ name: 'memory_import',
1192
+ description: 'Import memory entries from a JSON export file (produced by memory_export) into .swarm/memory.db, re-embedding values. Use when native Read is wrong because the data must be re-stored as memory rows (with new embeddings), not just read. For importing Claude Code\'s own memory files use memory_import_claude. Pair with memory_export on the source.',
1193
+ category: 'memory',
1194
+ inputSchema: {
1195
+ type: 'object',
1196
+ properties: {
1197
+ inputPath: { type: 'string', description: 'Path to the JSON export file' },
1198
+ merge: { type: 'boolean', description: 'Merge into existing entries (upsert) vs. fail on conflict (default true)' },
1199
+ namespace: { type: 'string', description: 'Override the namespace for all imported entries' },
1200
+ },
1201
+ required: ['inputPath'],
1202
+ },
1203
+ handler: async (input) => {
1204
+ await ensureInitialized();
1205
+ const { storeEntry } = await getMemoryFunctions();
1206
+ const t0 = Date.now();
1207
+ const inputPath = String(input.inputPath ?? '');
1208
+ if (!inputPath || !existsSync(inputPath))
1209
+ return { error: `File not found: ${inputPath || '(empty)'}` };
1210
+ let doc;
1211
+ try {
1212
+ doc = JSON.parse(readFileSync(inputPath, 'utf-8'));
1213
+ }
1214
+ catch (e) {
1215
+ return { error: `Invalid export JSON: ${e.message}` };
1216
+ }
1217
+ const entries = Array.isArray(doc.entries) ? doc.entries : [];
1218
+ const nsOverride = input.namespace ? String(input.namespace) : undefined;
1219
+ if (nsOverride) {
1220
+ const v = validateIdentifier(nsOverride, 'namespace');
1221
+ if (!v.valid)
1222
+ throw new Error(v.error);
1223
+ }
1224
+ let imported = 0;
1225
+ let skipped = 0;
1226
+ for (const e of entries) {
1227
+ if (!e || typeof e.key !== 'string') {
1228
+ skipped++;
1229
+ continue;
1230
+ }
1231
+ const value = typeof e.value === 'string' ? e.value : JSON.stringify(e.value ?? null);
1232
+ try {
1233
+ await storeEntry({ key: e.key, value, namespace: nsOverride ?? e.namespace ?? 'default', upsert: input.merge !== false });
1234
+ imported++;
1235
+ }
1236
+ catch {
1237
+ skipped++;
1238
+ }
1239
+ }
1240
+ return {
1241
+ inputPath,
1242
+ imported: { entries: imported, vectors: 0, patterns: 0 },
1243
+ skipped,
1244
+ duration: Date.now() - t0,
1245
+ };
1246
+ },
1247
+ },
817
1248
  ];
818
1249
  //# sourceMappingURL=memory-tools.js.map