claude-code-swarm 0.3.3 → 0.3.5

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 (273) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +22 -1
  3. package/.claude-plugin/run-agent-inbox-mcp.sh +76 -0
  4. package/.claude-plugin/run-minimem-mcp.sh +98 -0
  5. package/.claude-plugin/run-opentasks-mcp.sh +65 -0
  6. package/CLAUDE.md +200 -36
  7. package/README.md +65 -0
  8. package/e2e/helpers/cleanup.mjs +17 -3
  9. package/e2e/helpers/map-mock-server.mjs +201 -25
  10. package/e2e/helpers/sidecar.mjs +222 -0
  11. package/e2e/helpers/workspace.mjs +2 -1
  12. package/e2e/tier5-sidecar-inbox.test.mjs +900 -0
  13. package/e2e/tier6-inbox-mcp.test.mjs +173 -0
  14. package/e2e/tier6-live-agent.test.mjs +759 -0
  15. package/e2e/vitest.config.e2e.mjs +1 -1
  16. package/hooks/hooks.json +15 -8
  17. package/package.json +13 -1
  18. package/references/agent-inbox/CLAUDE.md +151 -0
  19. package/references/agent-inbox/README.md +238 -0
  20. package/references/agent-inbox/docs/CLAUDE-CODE-SWARM-PROPOSAL.md +137 -0
  21. package/references/agent-inbox/docs/DESIGN.md +1156 -0
  22. package/references/agent-inbox/hooks/inbox-hook.mjs +119 -0
  23. package/references/agent-inbox/hooks/register-hook.mjs +69 -0
  24. package/references/agent-inbox/package-lock.json +3347 -0
  25. package/references/agent-inbox/package.json +58 -0
  26. package/references/agent-inbox/rules/agent-inbox.md +78 -0
  27. package/references/agent-inbox/src/federation/address.ts +61 -0
  28. package/references/agent-inbox/src/federation/connection-manager.ts +573 -0
  29. package/references/agent-inbox/src/federation/delivery-queue.ts +222 -0
  30. package/references/agent-inbox/src/federation/index.ts +6 -0
  31. package/references/agent-inbox/src/federation/routing-engine.ts +188 -0
  32. package/references/agent-inbox/src/federation/trust.ts +71 -0
  33. package/references/agent-inbox/src/index.ts +390 -0
  34. package/references/agent-inbox/src/ipc/ipc-server.ts +207 -0
  35. package/references/agent-inbox/src/jsonrpc/mail-server.ts +382 -0
  36. package/references/agent-inbox/src/map/map-client.ts +414 -0
  37. package/references/agent-inbox/src/mcp/mcp-server.ts +272 -0
  38. package/references/agent-inbox/src/mesh/delivery-bridge.ts +110 -0
  39. package/references/agent-inbox/src/mesh/mesh-connector.ts +41 -0
  40. package/references/agent-inbox/src/mesh/mesh-transport.ts +157 -0
  41. package/references/agent-inbox/src/mesh/type-mapper.ts +239 -0
  42. package/references/agent-inbox/src/push/notifier.ts +233 -0
  43. package/references/agent-inbox/src/registry/warm-registry.ts +255 -0
  44. package/references/agent-inbox/src/router/message-router.ts +175 -0
  45. package/references/agent-inbox/src/storage/interface.ts +48 -0
  46. package/references/agent-inbox/src/storage/memory.ts +145 -0
  47. package/references/agent-inbox/src/storage/sqlite.ts +671 -0
  48. package/references/agent-inbox/src/traceability/traceability.ts +183 -0
  49. package/references/agent-inbox/src/types.ts +303 -0
  50. package/references/agent-inbox/test/federation/address.test.ts +101 -0
  51. package/references/agent-inbox/test/federation/connection-manager.test.ts +546 -0
  52. package/references/agent-inbox/test/federation/delivery-queue.test.ts +159 -0
  53. package/references/agent-inbox/test/federation/integration.test.ts +857 -0
  54. package/references/agent-inbox/test/federation/routing-engine.test.ts +117 -0
  55. package/references/agent-inbox/test/federation/sdk-integration.test.ts +744 -0
  56. package/references/agent-inbox/test/federation/trust.test.ts +89 -0
  57. package/references/agent-inbox/test/ipc-jsonrpc.test.ts +113 -0
  58. package/references/agent-inbox/test/ipc-server.test.ts +197 -0
  59. package/references/agent-inbox/test/mail-server.test.ts +285 -0
  60. package/references/agent-inbox/test/map-client.test.ts +408 -0
  61. package/references/agent-inbox/test/mesh/delivery-bridge.test.ts +178 -0
  62. package/references/agent-inbox/test/mesh/e2e-mesh.test.ts +527 -0
  63. package/references/agent-inbox/test/mesh/e2e-real-meshpeer.test.ts +629 -0
  64. package/references/agent-inbox/test/mesh/federation-mesh.test.ts +269 -0
  65. package/references/agent-inbox/test/mesh/mesh-connector.test.ts +66 -0
  66. package/references/agent-inbox/test/mesh/mesh-transport.test.ts +191 -0
  67. package/references/agent-inbox/test/mesh/meshpeer-integration.test.ts +442 -0
  68. package/references/agent-inbox/test/mesh/mock-mesh.ts +125 -0
  69. package/references/agent-inbox/test/mesh/mock-meshpeer.ts +266 -0
  70. package/references/agent-inbox/test/mesh/type-mapper.test.ts +226 -0
  71. package/references/agent-inbox/test/message-router.test.ts +184 -0
  72. package/references/agent-inbox/test/push-notifier.test.ts +139 -0
  73. package/references/agent-inbox/test/registry/warm-registry.test.ts +171 -0
  74. package/references/agent-inbox/test/sqlite-prefix.test.ts +192 -0
  75. package/references/agent-inbox/test/sqlite-storage.test.ts +243 -0
  76. package/references/agent-inbox/test/storage.test.ts +196 -0
  77. package/references/agent-inbox/test/traceability.test.ts +123 -0
  78. package/references/agent-inbox/test/wake.test.ts +330 -0
  79. package/references/agent-inbox/tsconfig.json +20 -0
  80. package/references/agent-inbox/tsup.config.ts +10 -0
  81. package/references/agent-inbox/vitest.config.ts +8 -0
  82. package/references/minimem/.claude/settings.json +7 -0
  83. package/references/minimem/.sudocode/issues.jsonl +18 -0
  84. package/references/minimem/.sudocode/specs.jsonl +1 -0
  85. package/references/minimem/CLAUDE.md +329 -0
  86. package/references/minimem/README.md +565 -0
  87. package/references/minimem/claude-plugin/.claude-plugin/plugin.json +10 -0
  88. package/references/minimem/claude-plugin/.mcp.json +7 -0
  89. package/references/minimem/claude-plugin/README.md +158 -0
  90. package/references/minimem/claude-plugin/commands/recall.md +47 -0
  91. package/references/minimem/claude-plugin/commands/remember.md +41 -0
  92. package/references/minimem/claude-plugin/hooks/__tests__/hooks.test.ts +272 -0
  93. package/references/minimem/claude-plugin/hooks/hooks.json +27 -0
  94. package/references/minimem/claude-plugin/hooks/session-end.sh +86 -0
  95. package/references/minimem/claude-plugin/hooks/session-start.sh +85 -0
  96. package/references/minimem/claude-plugin/skills/memory/SKILL.md +108 -0
  97. package/references/minimem/media/banner.png +0 -0
  98. package/references/minimem/package-lock.json +5373 -0
  99. package/references/minimem/package.json +76 -0
  100. package/references/minimem/scripts/postbuild.js +49 -0
  101. package/references/minimem/src/__tests__/edge-cases.test.ts +371 -0
  102. package/references/minimem/src/__tests__/errors.test.ts +265 -0
  103. package/references/minimem/src/__tests__/helpers.ts +199 -0
  104. package/references/minimem/src/__tests__/internal.test.ts +407 -0
  105. package/references/minimem/src/__tests__/knowledge-frontmatter.test.ts +148 -0
  106. package/references/minimem/src/__tests__/knowledge.test.ts +148 -0
  107. package/references/minimem/src/__tests__/minimem.integration.test.ts +1127 -0
  108. package/references/minimem/src/__tests__/session.test.ts +190 -0
  109. package/references/minimem/src/cli/__tests__/commands.test.ts +760 -0
  110. package/references/minimem/src/cli/__tests__/contained-layout.test.ts +286 -0
  111. package/references/minimem/src/cli/commands/__tests__/conflicts.test.ts +141 -0
  112. package/references/minimem/src/cli/commands/append.ts +76 -0
  113. package/references/minimem/src/cli/commands/config.ts +262 -0
  114. package/references/minimem/src/cli/commands/conflicts.ts +415 -0
  115. package/references/minimem/src/cli/commands/daemon.ts +169 -0
  116. package/references/minimem/src/cli/commands/index.ts +12 -0
  117. package/references/minimem/src/cli/commands/init.ts +166 -0
  118. package/references/minimem/src/cli/commands/mcp.ts +221 -0
  119. package/references/minimem/src/cli/commands/push-pull.ts +213 -0
  120. package/references/minimem/src/cli/commands/search.ts +223 -0
  121. package/references/minimem/src/cli/commands/status.ts +84 -0
  122. package/references/minimem/src/cli/commands/store.ts +189 -0
  123. package/references/minimem/src/cli/commands/sync-init.ts +290 -0
  124. package/references/minimem/src/cli/commands/sync.ts +70 -0
  125. package/references/minimem/src/cli/commands/upsert.ts +197 -0
  126. package/references/minimem/src/cli/config.ts +611 -0
  127. package/references/minimem/src/cli/index.ts +299 -0
  128. package/references/minimem/src/cli/shared.ts +189 -0
  129. package/references/minimem/src/cli/sync/__tests__/central.test.ts +152 -0
  130. package/references/minimem/src/cli/sync/__tests__/conflicts.test.ts +209 -0
  131. package/references/minimem/src/cli/sync/__tests__/daemon.test.ts +118 -0
  132. package/references/minimem/src/cli/sync/__tests__/detection.test.ts +207 -0
  133. package/references/minimem/src/cli/sync/__tests__/integration.test.ts +476 -0
  134. package/references/minimem/src/cli/sync/__tests__/registry.test.ts +363 -0
  135. package/references/minimem/src/cli/sync/__tests__/state.test.ts +255 -0
  136. package/references/minimem/src/cli/sync/__tests__/validation.test.ts +193 -0
  137. package/references/minimem/src/cli/sync/__tests__/watcher.test.ts +178 -0
  138. package/references/minimem/src/cli/sync/central.ts +292 -0
  139. package/references/minimem/src/cli/sync/conflicts.ts +205 -0
  140. package/references/minimem/src/cli/sync/daemon.ts +407 -0
  141. package/references/minimem/src/cli/sync/detection.ts +138 -0
  142. package/references/minimem/src/cli/sync/index.ts +107 -0
  143. package/references/minimem/src/cli/sync/operations.ts +373 -0
  144. package/references/minimem/src/cli/sync/registry.ts +279 -0
  145. package/references/minimem/src/cli/sync/state.ts +358 -0
  146. package/references/minimem/src/cli/sync/validation.ts +206 -0
  147. package/references/minimem/src/cli/sync/watcher.ts +237 -0
  148. package/references/minimem/src/cli/version.ts +34 -0
  149. package/references/minimem/src/core/index.ts +9 -0
  150. package/references/minimem/src/core/indexer.ts +628 -0
  151. package/references/minimem/src/core/searcher.ts +221 -0
  152. package/references/minimem/src/db/schema.ts +183 -0
  153. package/references/minimem/src/db/sqlite-vec.ts +24 -0
  154. package/references/minimem/src/embeddings/__tests__/embeddings.test.ts +431 -0
  155. package/references/minimem/src/embeddings/batch-gemini.ts +392 -0
  156. package/references/minimem/src/embeddings/batch-openai.ts +409 -0
  157. package/references/minimem/src/embeddings/embeddings.ts +434 -0
  158. package/references/minimem/src/index.ts +132 -0
  159. package/references/minimem/src/internal.ts +299 -0
  160. package/references/minimem/src/minimem.ts +1291 -0
  161. package/references/minimem/src/search/__tests__/hybrid.test.ts +247 -0
  162. package/references/minimem/src/search/graph.ts +234 -0
  163. package/references/minimem/src/search/hybrid.ts +151 -0
  164. package/references/minimem/src/search/search.ts +256 -0
  165. package/references/minimem/src/server/__tests__/mcp.test.ts +347 -0
  166. package/references/minimem/src/server/__tests__/tools.test.ts +364 -0
  167. package/references/minimem/src/server/mcp.ts +326 -0
  168. package/references/minimem/src/server/tools.ts +720 -0
  169. package/references/minimem/src/session.ts +460 -0
  170. package/references/minimem/src/store/__tests__/manifest.test.ts +177 -0
  171. package/references/minimem/src/store/__tests__/materialize.test.ts +52 -0
  172. package/references/minimem/src/store/__tests__/store-graph.test.ts +228 -0
  173. package/references/minimem/src/store/index.ts +27 -0
  174. package/references/minimem/src/store/manifest.ts +203 -0
  175. package/references/minimem/src/store/materialize.ts +185 -0
  176. package/references/minimem/src/store/store-graph.ts +252 -0
  177. package/references/minimem/tsconfig.json +19 -0
  178. package/references/minimem/tsup.config.ts +26 -0
  179. package/references/minimem/vitest.config.ts +29 -0
  180. package/references/openteams/src/cli/generate.ts +23 -1
  181. package/references/openteams/src/generators/agent-prompt-generator.test.ts +94 -0
  182. package/references/openteams/src/generators/agent-prompt-generator.ts +42 -13
  183. package/references/openteams/src/generators/package-generator.ts +9 -1
  184. package/references/openteams/src/generators/skill-generator.test.ts +28 -0
  185. package/references/openteams/src/generators/skill-generator.ts +10 -4
  186. package/references/skill-tree/.claude/settings.json +6 -0
  187. package/references/skill-tree/.sudocode/issues.jsonl +19 -0
  188. package/references/skill-tree/.sudocode/specs.jsonl +3 -0
  189. package/references/skill-tree/CLAUDE.md +132 -0
  190. package/references/skill-tree/README.md +396 -0
  191. package/references/skill-tree/docs/GAPS_v1.md +221 -0
  192. package/references/skill-tree/docs/INTEGRATION_PLAN.md +467 -0
  193. package/references/skill-tree/docs/TODOS.md +91 -0
  194. package/references/skill-tree/docs/anthropic_skill_guide.md +1364 -0
  195. package/references/skill-tree/docs/design/federated-skill-trees.md +524 -0
  196. package/references/skill-tree/docs/design/multi-agent-sync.md +759 -0
  197. package/references/skill-tree/docs/scraper/BRAINSTORM.md +583 -0
  198. package/references/skill-tree/docs/scraper/POC_PLAN.md +420 -0
  199. package/references/skill-tree/docs/scraper/README.md +170 -0
  200. package/references/skill-tree/examples/basic-usage.ts +157 -0
  201. package/references/skill-tree/package-lock.json +1852 -0
  202. package/references/skill-tree/package.json +66 -0
  203. package/references/skill-tree/plan.md +78 -0
  204. package/references/skill-tree/scraper/README.md +123 -0
  205. package/references/skill-tree/scraper/docs/DESIGN.md +683 -0
  206. package/references/skill-tree/scraper/docs/PLAN.md +336 -0
  207. package/references/skill-tree/scraper/drizzle.config.ts +10 -0
  208. package/references/skill-tree/scraper/package-lock.json +6329 -0
  209. package/references/skill-tree/scraper/package.json +68 -0
  210. package/references/skill-tree/scraper/test/fixtures/invalid-skill/missing-description.md +7 -0
  211. package/references/skill-tree/scraper/test/fixtures/invalid-skill/missing-name.md +7 -0
  212. package/references/skill-tree/scraper/test/fixtures/minimal-skill/SKILL.md +27 -0
  213. package/references/skill-tree/scraper/test/fixtures/skill-json/SKILL.json +21 -0
  214. package/references/skill-tree/scraper/test/fixtures/skill-with-meta/SKILL.md +54 -0
  215. package/references/skill-tree/scraper/test/fixtures/skill-with-meta/_meta.json +24 -0
  216. package/references/skill-tree/scraper/test/fixtures/valid-skill/SKILL.md +93 -0
  217. package/references/skill-tree/scraper/test/fixtures/valid-skill/_meta.json +22 -0
  218. package/references/skill-tree/scraper/tsup.config.ts +14 -0
  219. package/references/skill-tree/scraper/vitest.config.ts +17 -0
  220. package/references/skill-tree/scripts/convert-to-vitest.ts +166 -0
  221. package/references/skill-tree/skills/skill-writer/SKILL.md +339 -0
  222. package/references/skill-tree/skills/skill-writer/references/examples.md +326 -0
  223. package/references/skill-tree/skills/skill-writer/references/patterns.md +210 -0
  224. package/references/skill-tree/skills/skill-writer/references/quality-checklist.md +123 -0
  225. package/references/skill-tree/test/run-all.ts +106 -0
  226. package/references/skill-tree/test/utils.ts +128 -0
  227. package/references/skill-tree/vitest.config.ts +16 -0
  228. package/references/swarmkit/src/commands/init/phases/configure.ts +0 -22
  229. package/references/swarmkit/src/commands/init/phases/global-setup.ts +5 -3
  230. package/references/swarmkit/src/commands/init/wizard.ts +2 -2
  231. package/references/swarmkit/src/packages/setup.test.ts +53 -7
  232. package/references/swarmkit/src/packages/setup.ts +37 -1
  233. package/scripts/bootstrap.mjs +26 -1
  234. package/scripts/generate-agents.mjs +5 -1
  235. package/scripts/map-hook.mjs +97 -64
  236. package/scripts/map-sidecar.mjs +179 -25
  237. package/scripts/team-loader.mjs +12 -41
  238. package/skills/swarm/SKILL.md +89 -25
  239. package/src/__tests__/agent-generator.test.mjs +6 -13
  240. package/src/__tests__/bootstrap.test.mjs +124 -1
  241. package/src/__tests__/config.test.mjs +200 -27
  242. package/src/__tests__/e2e-live-map.test.mjs +536 -0
  243. package/src/__tests__/e2e-mesh-sidecar.test.mjs +570 -0
  244. package/src/__tests__/e2e-native-task-hooks.test.mjs +376 -0
  245. package/src/__tests__/e2e-sidecar-bridge.test.mjs +477 -0
  246. package/src/__tests__/helpers.mjs +13 -0
  247. package/src/__tests__/inbox.test.mjs +22 -89
  248. package/src/__tests__/index.test.mjs +35 -9
  249. package/src/__tests__/integration.test.mjs +513 -0
  250. package/src/__tests__/map-events.test.mjs +514 -150
  251. package/src/__tests__/mesh-connection.test.mjs +308 -0
  252. package/src/__tests__/opentasks-client.test.mjs +517 -0
  253. package/src/__tests__/paths.test.mjs +185 -41
  254. package/src/__tests__/sidecar-client.test.mjs +35 -0
  255. package/src/__tests__/sidecar-server.test.mjs +124 -0
  256. package/src/__tests__/skilltree-client.test.mjs +80 -0
  257. package/src/agent-generator.mjs +104 -33
  258. package/src/bootstrap.mjs +150 -10
  259. package/src/config.mjs +81 -17
  260. package/src/context-output.mjs +58 -8
  261. package/src/inbox.mjs +9 -54
  262. package/src/index.mjs +39 -8
  263. package/src/map-connection.mjs +4 -3
  264. package/src/map-events.mjs +350 -80
  265. package/src/mesh-connection.mjs +148 -0
  266. package/src/opentasks-client.mjs +269 -0
  267. package/src/paths.mjs +182 -27
  268. package/src/sessionlog.mjs +14 -9
  269. package/src/sidecar-client.mjs +81 -27
  270. package/src/sidecar-server.mjs +175 -16
  271. package/src/skilltree-client.mjs +173 -0
  272. package/src/template.mjs +68 -4
  273. package/vitest.config.mjs +1 -0
@@ -0,0 +1,299 @@
1
+ /**
2
+ * Minimem CLI
3
+ *
4
+ * A file-based memory system with vector search for AI agents.
5
+ */
6
+
7
+ import { program } from "commander";
8
+
9
+ import { init } from "./commands/init.js";
10
+ import { search } from "./commands/search.js";
11
+ import { sync } from "./commands/sync.js";
12
+ import { status } from "./commands/status.js";
13
+ import { append } from "./commands/append.js";
14
+ import { upsert } from "./commands/upsert.js";
15
+ import { mcp } from "./commands/mcp.js";
16
+ import { config } from "./commands/config.js";
17
+ import { syncInit, syncInitCentral, syncList, syncRemove } from "./commands/sync-init.js";
18
+ import { pushCommand, pullCommand, syncStatusCommand } from "./commands/push-pull.js";
19
+ import { conflictsCommand, resolveCommand, cleanupCommand, logCommand } from "./commands/conflicts.js";
20
+ import { daemonCommand, daemonStopCommand, daemonStatusCommand, daemonLogsCommand } from "./commands/daemon.js";
21
+ import { storeList, storeAdd, storeRemove, storeLink, storeUnlink } from "./commands/store.js";
22
+ import { validateRegistry, formatValidationResult } from "./sync/validation.js";
23
+ import { VERSION } from "./version.js";
24
+ import { exitWithError } from "./config.js";
25
+
26
+ program
27
+ .name("minimem")
28
+ .description("File-based memory system with vector search for AI agents")
29
+ .version(VERSION);
30
+
31
+ // minimem init [dir]
32
+ program
33
+ .command("init [dir]")
34
+ .description("Initialize a memory directory")
35
+ .option("-g, --global", "Use ~/.minimem as global memory directory")
36
+ .option("-f, --force", "Reinitialize even if already initialized")
37
+ .action(init);
38
+
39
+ // minimem search <query>
40
+ program
41
+ .command("search <query>")
42
+ .description("Semantic search through memory files")
43
+ .option("-d, --dir <path...>", "Memory directories (can specify multiple)")
44
+ .option("-g, --global", "Include ~/.minimem in search")
45
+ .option("-n, --max <number>", "Maximum results (default: 10)")
46
+ .option("-s, --min-score <number>", "Minimum score threshold 0-1 (default: 0.3)")
47
+ .option("-p, --provider <name>", "Embedding provider (openai, gemini, local, auto)")
48
+ .option("--json", "Output results as JSON")
49
+ .option("--no-links", "Disable linked store resolution")
50
+ .action(search);
51
+
52
+ // minimem sync
53
+ program
54
+ .command("sync")
55
+ .description("Force re-index memory files")
56
+ .option("-d, --dir <path>", "Memory directory")
57
+ .option("-g, --global", "Use ~/.minimem")
58
+ .option("-f, --force", "Force full re-index")
59
+ .option("-p, --provider <name>", "Embedding provider (openai, gemini, local, auto)")
60
+ .action(sync);
61
+
62
+ // minimem status
63
+ program
64
+ .command("status")
65
+ .description("Show index stats and provider info")
66
+ .option("-d, --dir <path>", "Memory directory")
67
+ .option("-g, --global", "Use ~/.minimem")
68
+ .option("-p, --provider <name>", "Embedding provider (openai, gemini, local, auto)")
69
+ .option("--json", "Output as JSON")
70
+ .action(status);
71
+
72
+ // minimem append <text>
73
+ program
74
+ .command("append <text>")
75
+ .description("Append text to today's daily log (memory/YYYY-MM-DD.md)")
76
+ .option("-d, --dir <path>", "Memory directory")
77
+ .option("-g, --global", "Use ~/.minimem")
78
+ .option("-f, --file <path>", "Append to specific file instead of today's log")
79
+ .option("-p, --provider <name>", "Embedding provider (openai, gemini, local, auto)")
80
+ .option("-s, --session <id>", "Session ID to associate with this memory")
81
+ .option("--session-source <name>", "Session source (claude-code, vscode, etc.)")
82
+ .action(append);
83
+
84
+ // minimem upsert <file> [content]
85
+ program
86
+ .command("upsert <file> [content]")
87
+ .description("Create or update a memory file (file path relative to memory dir)")
88
+ .option("-d, --dir <path>", "Memory directory")
89
+ .option("-g, --global", "Use ~/.minimem")
90
+ .option("-p, --provider <name>", "Embedding provider (openai, gemini, local, auto)")
91
+ .option("--stdin", "Read content from stdin")
92
+ .option("-s, --session <id>", "Session ID to associate with this memory")
93
+ .option("--session-source <name>", "Session source (claude-code, vscode, etc.)")
94
+ .action(upsert);
95
+
96
+ // minimem mcp
97
+ program
98
+ .command("mcp")
99
+ .description("Run as MCP server over stdio (for Claude Desktop, Cursor, etc.)")
100
+ .option("-d, --dir <path...>", "Memory directories (can specify multiple)")
101
+ .option("-g, --global", "Include ~/.minimem")
102
+ .option("-p, --provider <name>", "Embedding provider (openai, gemini, local, auto)")
103
+ .action(mcp);
104
+
105
+ // minimem config
106
+ program
107
+ .command("config")
108
+ .description("View or modify configuration")
109
+ .option("-d, --dir <path>", "Memory directory")
110
+ .option("-g, --global", "Use ~/.minimem")
111
+ .option("--xdg-global", "Modify ~/.config/minimem/config.json (for sync settings)")
112
+ .option("--json", "Output as JSON")
113
+ .option("--set <key=value>", "Set a config value (e.g., embedding.provider=openai)")
114
+ .option("--unset <key>", "Remove a config value")
115
+ .action(config);
116
+
117
+ // minimem sync init-central <path>
118
+ program
119
+ .command("sync:init-central <path>")
120
+ .description("Initialize a central repository for syncing memories")
121
+ .option("-f, --force", "Force creation even if directory exists")
122
+ .action(syncInitCentral);
123
+
124
+ // minimem sync init
125
+ program
126
+ .command("sync:init")
127
+ .description("Initialize sync for a memory directory")
128
+ .option("-d, --local <path>", "Memory directory to sync")
129
+ .option("-g, --global", "Use ~/.minimem")
130
+ .option("-p, --path <path>", "Path in central repo (e.g., myproject/)")
131
+ .action(syncInit);
132
+
133
+ // minimem sync list
134
+ program
135
+ .command("sync:list")
136
+ .description("List all sync mappings")
137
+ .action(syncList);
138
+
139
+ // minimem sync remove
140
+ program
141
+ .command("sync:remove")
142
+ .description("Remove sync mapping for a directory")
143
+ .option("-d, --local <path>", "Memory directory")
144
+ .option("-g, --global", "Use ~/.minimem")
145
+ .action(syncRemove);
146
+
147
+ // minimem push
148
+ program
149
+ .command("push")
150
+ .description("Push local changes to central repository")
151
+ .option("-d, --dir <path>", "Memory directory")
152
+ .option("-g, --global", "Use ~/.minimem")
153
+ .option("-f, --force", "Force push (overwrite remote on conflicts)")
154
+ .option("--dry-run", "Show what would be pushed without making changes")
155
+ .action(pushCommand);
156
+
157
+ // minimem pull
158
+ program
159
+ .command("pull")
160
+ .description("Pull changes from central repository")
161
+ .option("-d, --dir <path>", "Memory directory")
162
+ .option("-g, --global", "Use ~/.minimem")
163
+ .option("-f, --force", "Force pull (overwrite local on conflicts)")
164
+ .option("--dry-run", "Show what would be pulled without making changes")
165
+ .action(pullCommand);
166
+
167
+ // minimem sync:status
168
+ program
169
+ .command("sync:status")
170
+ .description("Show sync status for a directory")
171
+ .option("-d, --dir <path>", "Memory directory")
172
+ .option("-g, --global", "Use ~/.minimem")
173
+ .action(syncStatusCommand);
174
+
175
+ // minimem sync:conflicts
176
+ program
177
+ .command("sync:conflicts")
178
+ .description("List quarantined conflicts")
179
+ .option("-d, --dir <path>", "Memory directory")
180
+ .option("-g, --global", "Use ~/.minimem")
181
+ .option("--json", "Output as JSON")
182
+ .action(conflictsCommand);
183
+
184
+ // minimem sync:resolve <timestamp>
185
+ program
186
+ .command("sync:resolve <timestamp>")
187
+ .description("Resolve a quarantined conflict using merge tool")
188
+ .option("-d, --dir <path>", "Memory directory")
189
+ .option("-g, --global", "Use ~/.minimem")
190
+ .option("-t, --tool <name>", "Merge tool (code, meld, kdiff3, vimdiff)")
191
+ .action(resolveCommand);
192
+
193
+ // minimem sync:cleanup
194
+ program
195
+ .command("sync:cleanup")
196
+ .description("Clean up old quarantined conflicts")
197
+ .option("-d, --dir <path>", "Memory directory")
198
+ .option("-g, --global", "Use ~/.minimem")
199
+ .option("--days <number>", "Remove conflicts older than N days (default: 30)")
200
+ .option("--dry-run", "Show what would be removed without removing")
201
+ .action(cleanupCommand);
202
+
203
+ // minimem sync:log
204
+ program
205
+ .command("sync:log")
206
+ .description("Show sync history")
207
+ .option("-d, --dir <path>", "Memory directory")
208
+ .option("-g, --global", "Use ~/.minimem")
209
+ .option("-n, --limit <number>", "Number of entries to show (default: 20)")
210
+ .option("--json", "Output as JSON")
211
+ .action(logCommand);
212
+
213
+ // minimem daemon
214
+ program
215
+ .command("daemon")
216
+ .description("Start the sync daemon")
217
+ .option("-b, --background", "Run in background")
218
+ .option("--foreground", "Run in foreground (internal use)")
219
+ .action(daemonCommand);
220
+
221
+ // minimem daemon:stop
222
+ program
223
+ .command("daemon:stop")
224
+ .description("Stop the sync daemon")
225
+ .action(daemonStopCommand);
226
+
227
+ // minimem daemon:status
228
+ program
229
+ .command("daemon:status")
230
+ .description("Show daemon status")
231
+ .action(daemonStatusCommand);
232
+
233
+ // minimem daemon:logs
234
+ program
235
+ .command("daemon:logs")
236
+ .description("Show daemon logs")
237
+ .option("-n, --lines <number>", "Number of lines to show (default: 50)")
238
+ .option("-f, --follow", "Follow log output")
239
+ .action(daemonLogsCommand);
240
+
241
+ // minimem sync:validate
242
+ program
243
+ .command("sync:validate")
244
+ .description("Validate registry for collisions and stale mappings")
245
+ .option("--json", "Output as JSON")
246
+ .action(async (options: { json?: boolean }) => {
247
+ try {
248
+ const result = await validateRegistry();
249
+
250
+ if (options.json) {
251
+ console.log(JSON.stringify(result, null, 2));
252
+ } else {
253
+ console.log(formatValidationResult(result));
254
+ }
255
+
256
+ if (!result.valid) {
257
+ process.exit(1);
258
+ }
259
+ } catch (error) {
260
+ const message = error instanceof Error ? error.message : String(error);
261
+ exitWithError(message);
262
+ }
263
+ });
264
+
265
+ // minimem store:list
266
+ program
267
+ .command("store:list")
268
+ .description("List all registered stores and their links")
269
+ .option("--json", "Output as JSON")
270
+ .action(storeList);
271
+
272
+ // minimem store:add <name> <path>
273
+ program
274
+ .command("store:add <name> <path>")
275
+ .description("Register a store in the global manifest")
276
+ .option("-r, --remote <url>", "Git remote URL for remote materialization")
277
+ .option("--description <text>", "Human-readable description")
278
+ .action(storeAdd);
279
+
280
+ // minimem store:remove <name>
281
+ program
282
+ .command("store:remove <name>")
283
+ .description("Remove a store from the global manifest")
284
+ .action(storeRemove);
285
+
286
+ // minimem store:link <store> <target>
287
+ program
288
+ .command("store:link <store> <target>")
289
+ .description("Link a store to another (searches include linked stores)")
290
+ .action(storeLink);
291
+
292
+ // minimem store:unlink <store> <target>
293
+ program
294
+ .command("store:unlink <store> <target>")
295
+ .description("Remove a link between stores")
296
+ .action(storeUnlink);
297
+
298
+ // Parse and run
299
+ program.parse();
@@ -0,0 +1,189 @@
1
+ /**
2
+ * Shared CLI utilities
3
+ *
4
+ * Centralized functions for directory resolution, error handling,
5
+ * and other cross-cutting concerns used by all CLI commands.
6
+ */
7
+
8
+ import * as fs from "node:fs";
9
+ import * as path from "node:path";
10
+ import * as os from "node:os";
11
+
12
+ /**
13
+ * Options that affect directory resolution
14
+ */
15
+ export type DirOptions = {
16
+ dir?: string | string[];
17
+ global?: boolean;
18
+ };
19
+
20
+ /**
21
+ * Discover the memory directory from a base directory.
22
+ *
23
+ * Checks for contained layouts where MEMORY.md lives inside
24
+ * .swarm/minimem/ or .minimem/ rather than at the project root.
25
+ *
26
+ * Priority:
27
+ * 1. base has MEMORY.md → base (classic layout)
28
+ * 2. base/.swarm/minimem/ has config.json → contained under .swarm
29
+ * 3. base/.minimem/ has config.json → contained under .minimem
30
+ * 4. base (fallback)
31
+ */
32
+ export function discoverMemoryDir(base: string): string {
33
+ // Classic layout: MEMORY.md at project root
34
+ if (fs.existsSync(path.join(base, "MEMORY.md"))) return base;
35
+
36
+ // Contained under .swarm/minimem/
37
+ const swarmDir = path.join(base, ".swarm", "minimem");
38
+ if (fs.existsSync(path.join(swarmDir, "config.json"))) return swarmDir;
39
+
40
+ // Contained under .minimem/
41
+ const minimemDir = path.join(base, ".minimem");
42
+ if (fs.existsSync(path.join(minimemDir, "config.json"))) return minimemDir;
43
+
44
+ return base;
45
+ }
46
+
47
+ /**
48
+ * Resolve a single memory directory from options.
49
+ *
50
+ * Priority:
51
+ * 1. --dir flag (first element if array)
52
+ * 2. MEMORY_DIR environment variable
53
+ * 3. --global flag → ~/.minimem
54
+ * 4. Auto-discover from current working directory
55
+ *
56
+ * Use this for commands that operate on a single directory.
57
+ */
58
+ export function resolveMemoryDir(options: DirOptions): string {
59
+ // Handle --dir flag (use first if array)
60
+ const dir = Array.isArray(options.dir) ? options.dir[0] : options.dir;
61
+ if (dir) {
62
+ return path.resolve(dir);
63
+ }
64
+
65
+ // Check MEMORY_DIR environment variable
66
+ const envDir = process.env.MEMORY_DIR;
67
+ if (envDir) {
68
+ return path.resolve(envDir);
69
+ }
70
+
71
+ // Handle --global flag
72
+ if (options.global) {
73
+ return path.join(os.homedir(), ".minimem");
74
+ }
75
+
76
+ // Auto-discover from cwd (handles contained layouts)
77
+ return discoverMemoryDir(process.cwd());
78
+ }
79
+
80
+ /**
81
+ * Resolve multiple memory directories from options.
82
+ *
83
+ * Use this for commands that can search across multiple directories
84
+ * (e.g., search, mcp).
85
+ *
86
+ * Returns deduplicated list of absolute paths.
87
+ */
88
+ export function resolveMemoryDirs(options: DirOptions): string[] {
89
+ const dirs: string[] = [];
90
+
91
+ // Add explicit directories from --dir flag
92
+ if (options.dir) {
93
+ const dirList = Array.isArray(options.dir) ? options.dir : [options.dir];
94
+ dirs.push(...dirList.map((d) => path.resolve(d)));
95
+ }
96
+
97
+ // If no explicit dirs, check MEMORY_DIR environment variable
98
+ if (dirs.length === 0 && process.env.MEMORY_DIR) {
99
+ dirs.push(path.resolve(process.env.MEMORY_DIR));
100
+ }
101
+
102
+ // Add global directory if --global flag is set
103
+ if (options.global) {
104
+ const globalDir = path.join(os.homedir(), ".minimem");
105
+ if (!dirs.includes(globalDir)) {
106
+ dirs.push(globalDir);
107
+ }
108
+ }
109
+
110
+ // Default: auto-discover from cwd (handles contained layouts)
111
+ if (dirs.length === 0) {
112
+ dirs.push(discoverMemoryDir(process.cwd()));
113
+ }
114
+
115
+ // Deduplicate
116
+ return [...new Set(dirs)];
117
+ }
118
+
119
+ /**
120
+ * Get the global memory directory path (~/.minimem)
121
+ */
122
+ export function getGlobalMemoryDir(): string {
123
+ return path.join(os.homedir(), ".minimem");
124
+ }
125
+
126
+ /**
127
+ * Exit with an error message and optional suggestion.
128
+ *
129
+ * All CLI errors should use this for consistent formatting.
130
+ */
131
+ export function exitWithError(message: string, suggestion?: string): never {
132
+ console.error(`Error: ${message}`);
133
+ if (suggestion) {
134
+ console.error(` Suggestion: ${suggestion}`);
135
+ }
136
+ process.exit(1);
137
+ }
138
+
139
+ /**
140
+ * Print a warning message (non-fatal).
141
+ */
142
+ export function warn(message: string): void {
143
+ console.error(`Warning: ${message}`);
144
+ }
145
+
146
+ /**
147
+ * Print a note/informational message.
148
+ */
149
+ export function note(message: string): void {
150
+ console.error(`Note: ${message}`);
151
+ }
152
+
153
+ /**
154
+ * Log an error with context (for debugging).
155
+ * Only logs if a debug function is provided.
156
+ */
157
+ export function logError(
158
+ context: string,
159
+ error: unknown,
160
+ debug?: (msg: string) => void
161
+ ): void {
162
+ const message = error instanceof Error ? error.message : String(error);
163
+ if (debug) {
164
+ debug(`[${context}] Error: ${message}`);
165
+ }
166
+ }
167
+
168
+ /**
169
+ * Get a friendly display name for a directory.
170
+ */
171
+ export function getDirName(memoryDir: string): string {
172
+ const home = os.homedir();
173
+
174
+ // Check if it's the global directory
175
+ if (memoryDir === path.join(home, ".minimem")) {
176
+ return "global";
177
+ }
178
+
179
+ // Use the directory name
180
+ const name = path.basename(memoryDir);
181
+
182
+ // If it's a hidden directory, use parent + name
183
+ if (name.startsWith(".")) {
184
+ const parent = path.basename(path.dirname(memoryDir));
185
+ return `${parent}/${name}`;
186
+ }
187
+
188
+ return name;
189
+ }
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Tests for central repository initialization
3
+ */
4
+
5
+ import fs from "node:fs/promises";
6
+ import os from "node:os";
7
+ import path from "node:path";
8
+ import { afterEach, beforeEach, describe, it, expect } from "vitest";
9
+
10
+ import {
11
+ initCentralRepo,
12
+ validateCentralRepo,
13
+ } from "../central.js";
14
+ import { readRegistry } from "../registry.js";
15
+
16
+ describe("Central Repository", () => {
17
+ let tempDir: string;
18
+
19
+ beforeEach(async () => {
20
+ tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "minimem-central-test-"));
21
+ });
22
+
23
+ afterEach(async () => {
24
+ await fs.rm(tempDir, { recursive: true, force: true });
25
+ });
26
+
27
+ describe("initCentralRepo", () => {
28
+ it("should create new central repository", async () => {
29
+ const repoPath = path.join(tempDir, "memories-repo");
30
+ const result = await initCentralRepo(repoPath);
31
+
32
+ expect(result.success).toBe(true);
33
+ expect(result.created).toBe(true);
34
+ expect(result.message.includes("Created")).toBeTruthy();
35
+
36
+ // Check .git exists
37
+ const gitStat = await fs.stat(path.join(repoPath, ".git"));
38
+ expect(gitStat.isDirectory()).toBeTruthy();
39
+
40
+ // Check .gitignore exists and has correct content
41
+ const gitignore = await fs.readFile(path.join(repoPath, ".gitignore"), "utf-8");
42
+ expect(gitignore.includes("*.db")).toBeTruthy();
43
+ expect(gitignore.includes("staging/")).toBeTruthy();
44
+ expect(gitignore.includes("conflicts/")).toBeTruthy();
45
+
46
+ // Check registry exists
47
+ const registry = await readRegistry(repoPath);
48
+ expect(registry.mappings).toEqual([]);
49
+
50
+ // Check README exists
51
+ const readme = await fs.readFile(path.join(repoPath, "README.md"), "utf-8");
52
+ expect(readme.includes("Minimem Central Repository")).toBeTruthy();
53
+ });
54
+
55
+ it("should configure existing directory", async () => {
56
+ // Create directory first
57
+ await fs.mkdir(tempDir, { recursive: true });
58
+
59
+ const result = await initCentralRepo(tempDir);
60
+
61
+ expect(result.success).toBe(true);
62
+ expect(result.created).toBe(false);
63
+ expect(result.message.includes("Configured")).toBeTruthy();
64
+ });
65
+
66
+ it("should not overwrite existing .gitignore", async () => {
67
+ const repoPath = path.join(tempDir, "existing-repo");
68
+ await fs.mkdir(repoPath, { recursive: true });
69
+ await fs.writeFile(path.join(repoPath, ".gitignore"), "custom-ignore\n");
70
+
71
+ await initCentralRepo(repoPath);
72
+
73
+ const gitignore = await fs.readFile(path.join(repoPath, ".gitignore"), "utf-8");
74
+ expect(gitignore).toBe("custom-ignore\n");
75
+ });
76
+
77
+ it("should not overwrite existing registry", async () => {
78
+ const repoPath = path.join(tempDir, "existing-repo");
79
+ await fs.mkdir(repoPath, { recursive: true });
80
+ await fs.writeFile(
81
+ path.join(repoPath, ".minimem-registry.json"),
82
+ JSON.stringify({ version: 1, mappings: [{ path: "test/" }] })
83
+ );
84
+
85
+ await initCentralRepo(repoPath);
86
+
87
+ const content = await fs.readFile(
88
+ path.join(repoPath, ".minimem-registry.json"),
89
+ "utf-8"
90
+ );
91
+ const registry = JSON.parse(content);
92
+ expect(registry.mappings.length).toBe(1);
93
+ });
94
+
95
+ it("should handle ~ in path", async () => {
96
+ // We can't easily test ~ expansion to home in isolation,
97
+ // but we can test that it doesn't crash
98
+ const result = await initCentralRepo(path.join(tempDir, "test-repo"));
99
+ expect(result.success).toBe(true);
100
+ });
101
+ });
102
+
103
+ describe("validateCentralRepo", () => {
104
+ it("should validate a properly configured repo", async () => {
105
+ const repoPath = path.join(tempDir, "valid-repo");
106
+ await initCentralRepo(repoPath);
107
+
108
+ const result = await validateCentralRepo(repoPath);
109
+
110
+ expect(result.valid).toBe(true);
111
+ expect(result.errors.length).toBe(0);
112
+ });
113
+
114
+ it("should report missing directory", async () => {
115
+ const result = await validateCentralRepo(path.join(tempDir, "nonexistent"));
116
+
117
+ expect(result.valid).toBe(false);
118
+ expect(result.errors.some(e => e.includes("does not exist"))).toBeTruthy();
119
+ });
120
+
121
+ it("should warn about missing registry", async () => {
122
+ await fs.mkdir(tempDir, { recursive: true });
123
+ // Initialize git but don't create registry
124
+ const { execSync } = await import("node:child_process");
125
+ execSync("git init", { cwd: tempDir, stdio: "pipe" });
126
+
127
+ const result = await validateCentralRepo(tempDir);
128
+
129
+ expect(result.valid).toBe(true); // Still valid, just has warnings
130
+ expect(result.warnings.some(w => w.includes("Registry"))).toBeTruthy();
131
+ });
132
+
133
+ it("should warn about missing .gitignore", async () => {
134
+ const repoPath = path.join(tempDir, "no-gitignore");
135
+ await fs.mkdir(repoPath, { recursive: true });
136
+ const { execSync } = await import("node:child_process");
137
+ execSync("git init", { cwd: repoPath, stdio: "pipe" });
138
+
139
+ const result = await validateCentralRepo(repoPath);
140
+
141
+ expect(result.warnings.some(w => w.includes(".gitignore"))).toBeTruthy();
142
+ });
143
+
144
+ it("should warn if not a git repo", async () => {
145
+ await fs.mkdir(tempDir, { recursive: true });
146
+
147
+ const result = await validateCentralRepo(tempDir);
148
+
149
+ expect(result.warnings.some(w => w.includes("Not a git repository"))).toBeTruthy();
150
+ });
151
+ });
152
+ });