@claude-flow/cli 3.0.0-alpha.2 → 3.0.0-alpha.21

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 (263) hide show
  1. package/README.md +172 -6
  2. package/bin/cli.js +0 -0
  3. package/dist/src/commands/agent.d.ts.map +1 -1
  4. package/dist/src/commands/agent.js +43 -27
  5. package/dist/src/commands/agent.js.map +1 -1
  6. package/dist/src/commands/analyze.d.ts +19 -0
  7. package/dist/src/commands/analyze.d.ts.map +1 -0
  8. package/dist/src/commands/analyze.js +1823 -0
  9. package/dist/src/commands/analyze.js.map +1 -0
  10. package/dist/src/commands/claims.d.ts +10 -0
  11. package/dist/src/commands/claims.d.ts.map +1 -0
  12. package/dist/src/commands/claims.js +288 -0
  13. package/dist/src/commands/claims.js.map +1 -0
  14. package/dist/src/commands/completions.d.ts +10 -0
  15. package/dist/src/commands/completions.d.ts.map +1 -0
  16. package/dist/src/commands/completions.js +539 -0
  17. package/dist/src/commands/completions.js.map +1 -0
  18. package/dist/src/commands/config.js +2 -2
  19. package/dist/src/commands/config.js.map +1 -1
  20. package/dist/src/commands/daemon.d.ts +8 -0
  21. package/dist/src/commands/daemon.d.ts.map +1 -0
  22. package/dist/src/commands/daemon.js +545 -0
  23. package/dist/src/commands/daemon.js.map +1 -0
  24. package/dist/src/commands/deployment.d.ts +10 -0
  25. package/dist/src/commands/deployment.d.ts.map +1 -0
  26. package/dist/src/commands/deployment.js +289 -0
  27. package/dist/src/commands/deployment.js.map +1 -0
  28. package/dist/src/commands/doctor.d.ts +10 -0
  29. package/dist/src/commands/doctor.d.ts.map +1 -0
  30. package/dist/src/commands/doctor.js +429 -0
  31. package/dist/src/commands/doctor.js.map +1 -0
  32. package/dist/src/commands/embeddings.d.ts +18 -0
  33. package/dist/src/commands/embeddings.d.ts.map +1 -0
  34. package/dist/src/commands/embeddings.js +616 -0
  35. package/dist/src/commands/embeddings.js.map +1 -0
  36. package/dist/src/commands/hive-mind.d.ts.map +1 -1
  37. package/dist/src/commands/hive-mind.js +252 -35
  38. package/dist/src/commands/hive-mind.js.map +1 -1
  39. package/dist/src/commands/hooks.d.ts.map +1 -1
  40. package/dist/src/commands/hooks.js +326 -2
  41. package/dist/src/commands/hooks.js.map +1 -1
  42. package/dist/src/commands/index.d.ts +13 -0
  43. package/dist/src/commands/index.d.ts.map +1 -1
  44. package/dist/src/commands/index.js +52 -1
  45. package/dist/src/commands/index.js.map +1 -1
  46. package/dist/src/commands/mcp.js +4 -4
  47. package/dist/src/commands/mcp.js.map +1 -1
  48. package/dist/src/commands/memory.d.ts.map +1 -1
  49. package/dist/src/commands/memory.js +236 -170
  50. package/dist/src/commands/memory.js.map +1 -1
  51. package/dist/src/commands/migrate.js +1 -1
  52. package/dist/src/commands/migrate.js.map +1 -1
  53. package/dist/src/commands/neural.d.ts +10 -0
  54. package/dist/src/commands/neural.d.ts.map +1 -0
  55. package/dist/src/commands/neural.js +224 -0
  56. package/dist/src/commands/neural.js.map +1 -0
  57. package/dist/src/commands/performance.d.ts +10 -0
  58. package/dist/src/commands/performance.d.ts.map +1 -0
  59. package/dist/src/commands/performance.js +262 -0
  60. package/dist/src/commands/performance.js.map +1 -0
  61. package/dist/src/commands/plugins.d.ts +10 -0
  62. package/dist/src/commands/plugins.d.ts.map +1 -0
  63. package/dist/src/commands/plugins.js +280 -0
  64. package/dist/src/commands/plugins.js.map +1 -0
  65. package/dist/src/commands/process.d.ts.map +1 -1
  66. package/dist/src/commands/process.js +95 -20
  67. package/dist/src/commands/process.js.map +1 -1
  68. package/dist/src/commands/providers.d.ts +10 -0
  69. package/dist/src/commands/providers.d.ts.map +1 -0
  70. package/dist/src/commands/providers.js +232 -0
  71. package/dist/src/commands/providers.js.map +1 -0
  72. package/dist/src/commands/route.d.ts +16 -0
  73. package/dist/src/commands/route.d.ts.map +1 -0
  74. package/dist/src/commands/route.js +603 -0
  75. package/dist/src/commands/route.js.map +1 -0
  76. package/dist/src/commands/security.d.ts +10 -0
  77. package/dist/src/commands/security.d.ts.map +1 -0
  78. package/dist/src/commands/security.js +261 -0
  79. package/dist/src/commands/security.js.map +1 -0
  80. package/dist/src/commands/start.js +2 -2
  81. package/dist/src/commands/start.js.map +1 -1
  82. package/dist/src/commands/status.d.ts.map +1 -1
  83. package/dist/src/commands/status.js +26 -2
  84. package/dist/src/commands/status.js.map +1 -1
  85. package/dist/src/commands/swarm.js +6 -6
  86. package/dist/src/commands/swarm.js.map +1 -1
  87. package/dist/src/index.d.ts +4 -2
  88. package/dist/src/index.d.ts.map +1 -1
  89. package/dist/src/index.js +63 -5
  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 +218 -362
  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 +5 -0
  96. package/dist/src/init/executor.js.map +1 -1
  97. package/dist/src/init/settings-generator.d.ts.map +1 -1
  98. package/dist/src/init/settings-generator.js +22 -12
  99. package/dist/src/init/settings-generator.js.map +1 -1
  100. package/dist/src/mcp-client.d.ts.map +1 -1
  101. package/dist/src/mcp-client.js +17 -1
  102. package/dist/src/mcp-client.js.map +1 -1
  103. package/dist/src/mcp-server.d.ts.map +1 -1
  104. package/dist/src/mcp-server.js +5 -0
  105. package/dist/src/mcp-server.js.map +1 -1
  106. package/dist/src/mcp-tools/agent-tools.d.ts +1 -1
  107. package/dist/src/mcp-tools/agent-tools.d.ts.map +1 -1
  108. package/dist/src/mcp-tools/agent-tools.js +350 -14
  109. package/dist/src/mcp-tools/agent-tools.js.map +1 -1
  110. package/dist/src/mcp-tools/analyze-tools.d.ts +38 -0
  111. package/dist/src/mcp-tools/analyze-tools.d.ts.map +1 -0
  112. package/dist/src/mcp-tools/analyze-tools.js +317 -0
  113. package/dist/src/mcp-tools/analyze-tools.js.map +1 -0
  114. package/dist/src/mcp-tools/config-tools.d.ts +1 -1
  115. package/dist/src/mcp-tools/config-tools.d.ts.map +1 -1
  116. package/dist/src/mcp-tools/config-tools.js +262 -15
  117. package/dist/src/mcp-tools/config-tools.js.map +1 -1
  118. package/dist/src/mcp-tools/hive-mind-tools.d.ts +8 -0
  119. package/dist/src/mcp-tools/hive-mind-tools.d.ts.map +1 -0
  120. package/dist/src/mcp-tools/hive-mind-tools.js +447 -0
  121. package/dist/src/mcp-tools/hive-mind-tools.js.map +1 -0
  122. package/dist/src/mcp-tools/hooks-tools.d.ts.map +1 -1
  123. package/dist/src/mcp-tools/hooks-tools.js +80 -15
  124. package/dist/src/mcp-tools/hooks-tools.js.map +1 -1
  125. package/dist/src/mcp-tools/index.d.ts +6 -0
  126. package/dist/src/mcp-tools/index.d.ts.map +1 -1
  127. package/dist/src/mcp-tools/index.js +6 -0
  128. package/dist/src/mcp-tools/index.js.map +1 -1
  129. package/dist/src/mcp-tools/memory-tools.d.ts +1 -1
  130. package/dist/src/mcp-tools/memory-tools.d.ts.map +1 -1
  131. package/dist/src/mcp-tools/memory-tools.js +157 -9
  132. package/dist/src/mcp-tools/memory-tools.js.map +1 -1
  133. package/dist/src/mcp-tools/session-tools.d.ts +8 -0
  134. package/dist/src/mcp-tools/session-tools.d.ts.map +1 -0
  135. package/dist/src/mcp-tools/session-tools.js +315 -0
  136. package/dist/src/mcp-tools/session-tools.js.map +1 -0
  137. package/dist/src/mcp-tools/swarm-tools.d.ts.map +1 -1
  138. package/dist/src/mcp-tools/swarm-tools.js +37 -2
  139. package/dist/src/mcp-tools/swarm-tools.js.map +1 -1
  140. package/dist/src/mcp-tools/task-tools.d.ts +8 -0
  141. package/dist/src/mcp-tools/task-tools.d.ts.map +1 -0
  142. package/dist/src/mcp-tools/task-tools.js +302 -0
  143. package/dist/src/mcp-tools/task-tools.js.map +1 -0
  144. package/dist/src/mcp-tools/workflow-tools.d.ts +8 -0
  145. package/dist/src/mcp-tools/workflow-tools.d.ts.map +1 -0
  146. package/dist/src/mcp-tools/workflow-tools.js +481 -0
  147. package/dist/src/mcp-tools/workflow-tools.js.map +1 -0
  148. package/dist/src/output.d.ts +16 -0
  149. package/dist/src/output.d.ts.map +1 -1
  150. package/dist/src/output.js +42 -0
  151. package/dist/src/output.js.map +1 -1
  152. package/dist/src/ruvector/ast-analyzer.d.ts +67 -0
  153. package/dist/src/ruvector/ast-analyzer.d.ts.map +1 -0
  154. package/dist/src/ruvector/ast-analyzer.js +277 -0
  155. package/dist/src/ruvector/ast-analyzer.js.map +1 -0
  156. package/dist/src/ruvector/coverage-router.d.ts +145 -0
  157. package/dist/src/ruvector/coverage-router.d.ts.map +1 -0
  158. package/dist/src/ruvector/coverage-router.js +451 -0
  159. package/dist/src/ruvector/coverage-router.js.map +1 -0
  160. package/dist/src/ruvector/coverage-tools.d.ts +33 -0
  161. package/dist/src/ruvector/coverage-tools.d.ts.map +1 -0
  162. package/dist/src/ruvector/coverage-tools.js +157 -0
  163. package/dist/src/ruvector/coverage-tools.js.map +1 -0
  164. package/dist/src/ruvector/diff-classifier.d.ts +175 -0
  165. package/dist/src/ruvector/diff-classifier.d.ts.map +1 -0
  166. package/dist/src/ruvector/diff-classifier.js +662 -0
  167. package/dist/src/ruvector/diff-classifier.js.map +1 -0
  168. package/dist/src/ruvector/graph-analyzer.d.ts +174 -0
  169. package/dist/src/ruvector/graph-analyzer.d.ts.map +1 -0
  170. package/dist/src/ruvector/graph-analyzer.js +878 -0
  171. package/dist/src/ruvector/graph-analyzer.js.map +1 -0
  172. package/dist/src/ruvector/index.d.ts +27 -0
  173. package/dist/src/ruvector/index.d.ts.map +1 -0
  174. package/dist/src/ruvector/index.js +49 -0
  175. package/dist/src/ruvector/index.js.map +1 -0
  176. package/dist/src/ruvector/q-learning-router.d.ts +211 -0
  177. package/dist/src/ruvector/q-learning-router.d.ts.map +1 -0
  178. package/dist/src/ruvector/q-learning-router.js +681 -0
  179. package/dist/src/ruvector/q-learning-router.js.map +1 -0
  180. package/dist/src/ruvector/vector-db.d.ts +69 -0
  181. package/dist/src/ruvector/vector-db.d.ts.map +1 -0
  182. package/dist/src/ruvector/vector-db.js +243 -0
  183. package/dist/src/ruvector/vector-db.js.map +1 -0
  184. package/dist/src/services/index.d.ts +7 -0
  185. package/dist/src/services/index.d.ts.map +1 -0
  186. package/dist/src/services/index.js +6 -0
  187. package/dist/src/services/index.js.map +1 -0
  188. package/dist/src/services/worker-daemon.d.ts +153 -0
  189. package/dist/src/services/worker-daemon.d.ts.map +1 -0
  190. package/dist/src/services/worker-daemon.js +567 -0
  191. package/dist/src/services/worker-daemon.js.map +1 -0
  192. package/dist/src/suggest.d.ts +53 -0
  193. package/dist/src/suggest.d.ts.map +1 -0
  194. package/dist/src/suggest.js +200 -0
  195. package/dist/src/suggest.js.map +1 -0
  196. package/dist/tsconfig.tsbuildinfo +1 -1
  197. package/package.json +28 -6
  198. package/.agentic-flow/intelligence.json +0 -16
  199. package/.claude-flow/metrics/agent-metrics.json +0 -1
  200. package/.claude-flow/metrics/performance.json +0 -87
  201. package/.claude-flow/metrics/task-metrics.json +0 -10
  202. package/__tests__/README.md +0 -140
  203. package/__tests__/TEST_SUMMARY.md +0 -144
  204. package/__tests__/cli.test.ts +0 -558
  205. package/__tests__/commands.test.ts +0 -726
  206. package/__tests__/config-adapter.test.ts +0 -362
  207. package/__tests__/config-loading.test.ts +0 -106
  208. package/__tests__/coverage/.tmp/coverage-0.json +0 -1
  209. package/__tests__/coverage/.tmp/coverage-1.json +0 -1
  210. package/__tests__/coverage/.tmp/coverage-2.json +0 -1
  211. package/__tests__/coverage/.tmp/coverage-3.json +0 -1
  212. package/__tests__/coverage/.tmp/coverage-4.json +0 -1
  213. package/__tests__/coverage/.tmp/coverage-5.json +0 -1
  214. package/__tests__/mcp-client.test.ts +0 -480
  215. package/__tests__/p1-commands.test.ts +0 -1064
  216. package/docs/CONFIG_LOADING.md +0 -236
  217. package/docs/IMPLEMENTATION_COMPLETE.md +0 -421
  218. package/docs/MCP_CLIENT_GUIDE.md +0 -620
  219. package/docs/REFACTORING_SUMMARY.md +0 -247
  220. package/src/commands/agent.ts +0 -941
  221. package/src/commands/config.ts +0 -452
  222. package/src/commands/hive-mind.ts +0 -762
  223. package/src/commands/hooks.ts +0 -2603
  224. package/src/commands/index.ts +0 -115
  225. package/src/commands/init.ts +0 -597
  226. package/src/commands/mcp.ts +0 -753
  227. package/src/commands/memory.ts +0 -1063
  228. package/src/commands/migrate.ts +0 -447
  229. package/src/commands/process.ts +0 -617
  230. package/src/commands/session.ts +0 -891
  231. package/src/commands/start.ts +0 -457
  232. package/src/commands/status.ts +0 -705
  233. package/src/commands/swarm.ts +0 -648
  234. package/src/commands/task.ts +0 -792
  235. package/src/commands/workflow.ts +0 -742
  236. package/src/config-adapter.ts +0 -210
  237. package/src/index.ts +0 -383
  238. package/src/infrastructure/in-memory-repositories.ts +0 -310
  239. package/src/init/claudemd-generator.ts +0 -631
  240. package/src/init/executor.ts +0 -756
  241. package/src/init/helpers-generator.ts +0 -628
  242. package/src/init/index.ts +0 -60
  243. package/src/init/mcp-generator.ts +0 -83
  244. package/src/init/settings-generator.ts +0 -274
  245. package/src/init/statusline-generator.ts +0 -211
  246. package/src/init/types.ts +0 -447
  247. package/src/mcp-client.ts +0 -227
  248. package/src/mcp-server.ts +0 -571
  249. package/src/mcp-tools/agent-tools.ts +0 -92
  250. package/src/mcp-tools/config-tools.ts +0 -88
  251. package/src/mcp-tools/hooks-tools.ts +0 -1819
  252. package/src/mcp-tools/index.ts +0 -12
  253. package/src/mcp-tools/memory-tools.ts +0 -89
  254. package/src/mcp-tools/swarm-tools.ts +0 -69
  255. package/src/mcp-tools/types.ts +0 -33
  256. package/src/output.ts +0 -593
  257. package/src/parser.ts +0 -417
  258. package/src/prompt.ts +0 -619
  259. package/src/types.ts +0 -287
  260. package/tmp.json +0 -0
  261. package/tsconfig.json +0 -16
  262. package/tsconfig.tsbuildinfo +0 -1
  263. package/vitest.config.ts +0 -13
@@ -1,1063 +0,0 @@
1
- /**
2
- * V3 CLI Memory Command
3
- * Memory operations for AgentDB integration
4
- */
5
-
6
- import type { Command, CommandContext, CommandResult } from '../types.js';
7
- import { output } from '../output.js';
8
- import { select, confirm, input } from '../prompt.js';
9
- import { callMCPTool, MCPClientError } from '../mcp-client.js';
10
-
11
- // Memory backends
12
- const BACKENDS = [
13
- { value: 'agentdb', label: 'AgentDB', hint: 'Vector database with HNSW indexing (150x-12,500x faster)' },
14
- { value: 'sqlite', label: 'SQLite', hint: 'Lightweight local storage' },
15
- { value: 'hybrid', label: 'Hybrid', hint: 'SQLite + AgentDB (recommended)' },
16
- { value: 'memory', label: 'In-Memory', hint: 'Fast but non-persistent' }
17
- ];
18
-
19
- // Store command
20
- const storeCommand: Command = {
21
- name: 'store',
22
- description: 'Store data in memory',
23
- options: [
24
- {
25
- name: 'key',
26
- short: 'k',
27
- description: 'Storage key/namespace',
28
- type: 'string',
29
- required: true
30
- },
31
- {
32
- name: 'value',
33
- short: 'v',
34
- description: 'Value to store',
35
- type: 'string'
36
- },
37
- {
38
- name: 'namespace',
39
- short: 'n',
40
- description: 'Memory namespace',
41
- type: 'string',
42
- default: 'default'
43
- },
44
- {
45
- name: 'ttl',
46
- description: 'Time to live in seconds',
47
- type: 'number'
48
- },
49
- {
50
- name: 'tags',
51
- description: 'Comma-separated tags',
52
- type: 'string'
53
- },
54
- {
55
- name: 'vector',
56
- description: 'Store as vector embedding',
57
- type: 'boolean',
58
- default: false
59
- }
60
- ],
61
- examples: [
62
- { command: 'claude-flow memory store -k "api/auth" -v "JWT implementation"', description: 'Store text' },
63
- { command: 'claude-flow memory store -k "pattern/singleton" --vector', description: 'Store vector' }
64
- ],
65
- action: async (ctx: CommandContext): Promise<CommandResult> => {
66
- const key = ctx.flags.key as string;
67
- let value = ctx.flags.value as string || ctx.args[0];
68
- const namespace = ctx.flags.namespace as string;
69
- const ttl = ctx.flags.ttl as number;
70
- const tags = ctx.flags.tags ? (ctx.flags.tags as string).split(',') : [];
71
- const asVector = ctx.flags.vector as boolean;
72
-
73
- if (!key) {
74
- output.printError('Key is required. Use --key or -k');
75
- return { success: false, exitCode: 1 };
76
- }
77
-
78
- if (!value && ctx.interactive) {
79
- value = await input({
80
- message: 'Enter value to store:',
81
- validate: (v) => v.length > 0 || 'Value is required'
82
- });
83
- }
84
-
85
- if (!value) {
86
- output.printError('Value is required. Use --value or -v');
87
- return { success: false, exitCode: 1 };
88
- }
89
-
90
- const storeData = {
91
- key,
92
- namespace,
93
- value,
94
- ttl,
95
- tags,
96
- asVector,
97
- storedAt: new Date().toISOString(),
98
- size: Buffer.byteLength(value, 'utf8')
99
- };
100
-
101
- output.printInfo(`Storing in ${namespace}/${key}...`);
102
-
103
- if (asVector) {
104
- output.writeln(output.dim(' Generating embedding vector...'));
105
- output.writeln(output.dim(' Indexing with HNSW (M=16, ef=200)...'));
106
- }
107
-
108
- output.writeln();
109
- output.printTable({
110
- columns: [
111
- { key: 'property', header: 'Property', width: 15 },
112
- { key: 'val', header: 'Value', width: 40 }
113
- ],
114
- data: [
115
- { property: 'Key', val: key },
116
- { property: 'Namespace', val: namespace },
117
- { property: 'Size', val: `${storeData.size} bytes` },
118
- { property: 'TTL', val: ttl ? `${ttl}s` : 'None' },
119
- { property: 'Tags', val: tags.length > 0 ? tags.join(', ') : 'None' },
120
- { property: 'Vector', val: asVector ? 'Yes' : 'No' }
121
- ]
122
- });
123
-
124
- output.writeln();
125
- output.printSuccess('Data stored successfully');
126
-
127
- return { success: true, data: storeData };
128
- }
129
- };
130
-
131
- // Retrieve command
132
- const retrieveCommand: Command = {
133
- name: 'retrieve',
134
- aliases: ['get'],
135
- description: 'Retrieve data from memory',
136
- options: [
137
- {
138
- name: 'key',
139
- short: 'k',
140
- description: 'Storage key',
141
- type: 'string'
142
- },
143
- {
144
- name: 'namespace',
145
- short: 'n',
146
- description: 'Memory namespace',
147
- type: 'string',
148
- default: 'default'
149
- }
150
- ],
151
- action: async (ctx: CommandContext): Promise<CommandResult> => {
152
- const key = ctx.flags.key as string || ctx.args[0];
153
- const namespace = ctx.flags.namespace as string;
154
-
155
- if (!key) {
156
- output.printError('Key is required');
157
- return { success: false, exitCode: 1 };
158
- }
159
-
160
- // Simulated retrieval
161
- const data = {
162
- key,
163
- namespace,
164
- value: 'JWT implementation with refresh tokens and secure storage',
165
- metadata: {
166
- storedAt: '2024-01-04T10:30:00Z',
167
- accessCount: 15,
168
- lastAccessed: new Date().toISOString(),
169
- size: 56,
170
- tags: ['auth', 'security', 'api']
171
- }
172
- };
173
-
174
- if (ctx.flags.format === 'json') {
175
- output.printJson(data);
176
- return { success: true, data };
177
- }
178
-
179
- output.writeln();
180
- output.printBox(
181
- [
182
- `Namespace: ${data.namespace}`,
183
- `Key: ${data.key}`,
184
- `Size: ${data.metadata.size} bytes`,
185
- `Access Count: ${data.metadata.accessCount}`,
186
- `Tags: ${data.metadata.tags.join(', ')}`,
187
- '',
188
- output.bold('Value:'),
189
- data.value
190
- ].join('\n'),
191
- 'Memory Entry'
192
- );
193
-
194
- return { success: true, data };
195
- }
196
- };
197
-
198
- // Search command
199
- const searchCommand: Command = {
200
- name: 'search',
201
- description: 'Search memory with semantic/vector search',
202
- options: [
203
- {
204
- name: 'query',
205
- short: 'q',
206
- description: 'Search query',
207
- type: 'string',
208
- required: true
209
- },
210
- {
211
- name: 'namespace',
212
- short: 'n',
213
- description: 'Memory namespace',
214
- type: 'string'
215
- },
216
- {
217
- name: 'limit',
218
- short: 'l',
219
- description: 'Maximum results',
220
- type: 'number',
221
- default: 10
222
- },
223
- {
224
- name: 'threshold',
225
- description: 'Similarity threshold (0-1)',
226
- type: 'number',
227
- default: 0.7
228
- },
229
- {
230
- name: 'type',
231
- short: 't',
232
- description: 'Search type (semantic, keyword, hybrid)',
233
- type: 'string',
234
- default: 'semantic',
235
- choices: ['semantic', 'keyword', 'hybrid']
236
- }
237
- ],
238
- examples: [
239
- { command: 'claude-flow memory search -q "authentication patterns"', description: 'Semantic search' },
240
- { command: 'claude-flow memory search -q "JWT" -t keyword', description: 'Keyword search' }
241
- ],
242
- action: async (ctx: CommandContext): Promise<CommandResult> => {
243
- const query = ctx.flags.query as string || ctx.args[0];
244
- const namespace = ctx.flags.namespace as string;
245
- const limit = ctx.flags.limit as number;
246
- const threshold = ctx.flags.threshold as number;
247
- const searchType = ctx.flags.type as string;
248
-
249
- if (!query) {
250
- output.printError('Query is required. Use --query or -q');
251
- return { success: false, exitCode: 1 };
252
- }
253
-
254
- output.printInfo(`Searching: "${query}" (${searchType})`);
255
- output.writeln();
256
-
257
- // Simulated search results
258
- const results = [
259
- { key: 'auth/jwt-impl', score: 0.95, namespace: 'patterns', preview: 'JWT implementation with RS256...' },
260
- { key: 'auth/session', score: 0.88, namespace: 'patterns', preview: 'Session-based auth with Redis...' },
261
- { key: 'security/tokens', score: 0.82, namespace: 'security', preview: 'Token management strategies...' },
262
- { key: 'api/middleware', score: 0.76, namespace: 'code', preview: 'Auth middleware implementation...' }
263
- ].filter(r => r.score >= threshold).slice(0, limit);
264
-
265
- if (ctx.flags.format === 'json') {
266
- output.printJson({ query, searchType, results });
267
- return { success: true, data: results };
268
- }
269
-
270
- // Performance stats
271
- output.writeln(output.dim(` HNSW search: ${Math.random() * 2 + 0.5 | 0}.${Math.random() * 100 | 0}ms (150x faster than linear)`));
272
- output.writeln();
273
-
274
- output.printTable({
275
- columns: [
276
- { key: 'key', header: 'Key', width: 20 },
277
- { key: 'score', header: 'Score', width: 8, align: 'right', format: (v) => Number(v).toFixed(2) },
278
- { key: 'namespace', header: 'Namespace', width: 12 },
279
- { key: 'preview', header: 'Preview', width: 35 }
280
- ],
281
- data: results
282
- });
283
-
284
- output.writeln();
285
- output.printInfo(`Found ${results.length} results`);
286
-
287
- return { success: true, data: results };
288
- }
289
- };
290
-
291
- // List command
292
- const listCommand: Command = {
293
- name: 'list',
294
- aliases: ['ls'],
295
- description: 'List memory entries',
296
- options: [
297
- {
298
- name: 'namespace',
299
- short: 'n',
300
- description: 'Filter by namespace',
301
- type: 'string'
302
- },
303
- {
304
- name: 'tags',
305
- short: 't',
306
- description: 'Filter by tags (comma-separated)',
307
- type: 'string'
308
- },
309
- {
310
- name: 'limit',
311
- short: 'l',
312
- description: 'Maximum entries',
313
- type: 'number',
314
- default: 20
315
- }
316
- ],
317
- action: async (ctx: CommandContext): Promise<CommandResult> => {
318
- const namespace = ctx.flags.namespace as string;
319
- const limit = ctx.flags.limit as number;
320
-
321
- // Simulated entries
322
- const entries = [
323
- { key: 'auth/jwt-impl', namespace: 'patterns', size: '2.1 KB', tags: ['auth'], updated: '2h ago' },
324
- { key: 'auth/session', namespace: 'patterns', size: '1.4 KB', tags: ['auth'], updated: '3h ago' },
325
- { key: 'api/routes', namespace: 'code', size: '856 B', tags: ['api'], updated: '1d ago' },
326
- { key: 'db/schema', namespace: 'code', size: '3.2 KB', tags: ['db'], updated: '2d ago' },
327
- { key: 'patterns/singleton', namespace: 'patterns', size: '512 B', tags: ['design'], updated: '5d ago' }
328
- ].filter(e => !namespace || e.namespace === namespace).slice(0, limit);
329
-
330
- if (ctx.flags.format === 'json') {
331
- output.printJson(entries);
332
- return { success: true, data: entries };
333
- }
334
-
335
- output.writeln();
336
- output.writeln(output.bold('Memory Entries'));
337
- output.writeln();
338
-
339
- output.printTable({
340
- columns: [
341
- { key: 'key', header: 'Key', width: 25 },
342
- { key: 'namespace', header: 'Namespace', width: 12 },
343
- { key: 'size', header: 'Size', width: 10, align: 'right' },
344
- { key: 'tags', header: 'Tags', width: 12 },
345
- { key: 'updated', header: 'Updated', width: 10 }
346
- ],
347
- data: entries
348
- });
349
-
350
- output.writeln();
351
- output.printInfo(`Showing ${entries.length} entries`);
352
-
353
- return { success: true, data: entries };
354
- }
355
- };
356
-
357
- // Delete command
358
- const deleteCommand: Command = {
359
- name: 'delete',
360
- aliases: ['rm'],
361
- description: 'Delete memory entry',
362
- options: [
363
- {
364
- name: 'force',
365
- short: 'f',
366
- description: 'Skip confirmation',
367
- type: 'boolean',
368
- default: false
369
- }
370
- ],
371
- action: async (ctx: CommandContext): Promise<CommandResult> => {
372
- const key = ctx.args[0];
373
- const force = ctx.flags.force as boolean;
374
-
375
- if (!key) {
376
- output.printError('Key is required');
377
- return { success: false, exitCode: 1 };
378
- }
379
-
380
- if (!force && ctx.interactive) {
381
- const confirmed = await confirm({
382
- message: `Delete memory entry "${key}"?`,
383
- default: false
384
- });
385
-
386
- if (!confirmed) {
387
- output.printInfo('Operation cancelled');
388
- return { success: true };
389
- }
390
- }
391
-
392
- output.printInfo(`Deleting ${key}...`);
393
- output.printSuccess(`Deleted ${key}`);
394
-
395
- return { success: true, data: { key, deleted: true } };
396
- }
397
- };
398
-
399
- // Stats command
400
- const statsCommand: Command = {
401
- name: 'stats',
402
- description: 'Show memory statistics',
403
- action: async (ctx: CommandContext): Promise<CommandResult> => {
404
- const stats = {
405
- backend: 'hybrid',
406
- entries: {
407
- total: 1234,
408
- vectors: 567,
409
- text: 667
410
- },
411
- storage: {
412
- total: '45.6 MB',
413
- vectors: '32.1 MB',
414
- metadata: '13.5 MB'
415
- },
416
- performance: {
417
- avgSearchTime: '1.2ms',
418
- hnswIndexSize: '28.4 MB',
419
- cacheHitRate: '87.3%',
420
- vectorDimension: 1536
421
- },
422
- namespaces: [
423
- { name: 'patterns', entries: 234, size: '8.2 MB' },
424
- { name: 'code', entries: 456, size: '15.4 MB' },
425
- { name: 'security', entries: 123, size: '4.1 MB' },
426
- { name: 'default', entries: 421, size: '17.9 MB' }
427
- ]
428
- };
429
-
430
- if (ctx.flags.format === 'json') {
431
- output.printJson(stats);
432
- return { success: true, data: stats };
433
- }
434
-
435
- output.writeln();
436
- output.writeln(output.bold('Memory Statistics'));
437
- output.writeln();
438
-
439
- output.writeln(output.bold('Overview'));
440
- output.printTable({
441
- columns: [
442
- { key: 'metric', header: 'Metric', width: 20 },
443
- { key: 'value', header: 'Value', width: 15, align: 'right' }
444
- ],
445
- data: [
446
- { metric: 'Backend', value: stats.backend },
447
- { metric: 'Total Entries', value: stats.entries.total.toLocaleString() },
448
- { metric: 'Vector Entries', value: stats.entries.vectors.toLocaleString() },
449
- { metric: 'Text Entries', value: stats.entries.text.toLocaleString() },
450
- { metric: 'Total Storage', value: stats.storage.total }
451
- ]
452
- });
453
-
454
- output.writeln();
455
- output.writeln(output.bold('Performance (AgentDB)'));
456
- output.printTable({
457
- columns: [
458
- { key: 'metric', header: 'Metric', width: 20 },
459
- { key: 'value', header: 'Value', width: 15, align: 'right' }
460
- ],
461
- data: [
462
- { metric: 'Avg Search Time', value: stats.performance.avgSearchTime },
463
- { metric: 'HNSW Index Size', value: stats.performance.hnswIndexSize },
464
- { metric: 'Cache Hit Rate', value: stats.performance.cacheHitRate },
465
- { metric: 'Vector Dimension', value: stats.performance.vectorDimension }
466
- ]
467
- });
468
-
469
- output.writeln();
470
- output.writeln(output.bold('Namespaces'));
471
- output.printTable({
472
- columns: [
473
- { key: 'name', header: 'Name', width: 15 },
474
- { key: 'entries', header: 'Entries', width: 10, align: 'right' },
475
- { key: 'size', header: 'Size', width: 12, align: 'right' }
476
- ],
477
- data: stats.namespaces
478
- });
479
-
480
- output.writeln();
481
- output.printInfo('V3 Performance: 150x-12,500x faster search with HNSW indexing');
482
-
483
- return { success: true, data: stats };
484
- }
485
- };
486
-
487
- // Configure command
488
- const configureCommand: Command = {
489
- name: 'configure',
490
- aliases: ['config'],
491
- description: 'Configure memory backend',
492
- options: [
493
- {
494
- name: 'backend',
495
- short: 'b',
496
- description: 'Memory backend',
497
- type: 'string',
498
- choices: BACKENDS.map(b => b.value)
499
- },
500
- {
501
- name: 'path',
502
- description: 'Storage path',
503
- type: 'string'
504
- },
505
- {
506
- name: 'cache-size',
507
- description: 'Cache size in MB',
508
- type: 'number'
509
- },
510
- {
511
- name: 'hnsw-m',
512
- description: 'HNSW M parameter',
513
- type: 'number',
514
- default: 16
515
- },
516
- {
517
- name: 'hnsw-ef',
518
- description: 'HNSW ef parameter',
519
- type: 'number',
520
- default: 200
521
- }
522
- ],
523
- action: async (ctx: CommandContext): Promise<CommandResult> => {
524
- let backend = ctx.flags.backend as string;
525
-
526
- if (!backend && ctx.interactive) {
527
- backend = await select({
528
- message: 'Select memory backend:',
529
- options: BACKENDS,
530
- default: 'hybrid'
531
- });
532
- }
533
-
534
- const config = {
535
- backend: backend || 'hybrid',
536
- path: ctx.flags.path || './data/memory',
537
- cacheSize: ctx.flags.cacheSize || 256,
538
- hnsw: {
539
- m: ctx.flags.hnswM || 16,
540
- ef: ctx.flags.hnswEf || 200
541
- }
542
- };
543
-
544
- output.writeln();
545
- output.printInfo('Memory Configuration');
546
- output.writeln();
547
-
548
- output.printTable({
549
- columns: [
550
- { key: 'setting', header: 'Setting', width: 20 },
551
- { key: 'value', header: 'Value', width: 25 }
552
- ],
553
- data: [
554
- { setting: 'Backend', value: config.backend },
555
- { setting: 'Storage Path', value: config.path },
556
- { setting: 'Cache Size', value: `${config.cacheSize} MB` },
557
- { setting: 'HNSW M', value: config.hnsw.m },
558
- { setting: 'HNSW ef', value: config.hnsw.ef }
559
- ]
560
- });
561
-
562
- output.writeln();
563
- output.printSuccess('Memory configuration updated');
564
-
565
- return { success: true, data: config };
566
- }
567
- };
568
-
569
- // Cleanup command
570
- const cleanupCommand: Command = {
571
- name: 'cleanup',
572
- description: 'Clean up stale and expired memory entries',
573
- options: [
574
- {
575
- name: 'dry-run',
576
- short: 'd',
577
- description: 'Show what would be deleted',
578
- type: 'boolean',
579
- default: false
580
- },
581
- {
582
- name: 'older-than',
583
- short: 'o',
584
- description: 'Delete entries older than (e.g., "7d", "30d")',
585
- type: 'string'
586
- },
587
- {
588
- name: 'expired-only',
589
- short: 'e',
590
- description: 'Only delete expired TTL entries',
591
- type: 'boolean',
592
- default: false
593
- },
594
- {
595
- name: 'low-quality',
596
- short: 'l',
597
- description: 'Delete low quality patterns (threshold)',
598
- type: 'number'
599
- },
600
- {
601
- name: 'namespace',
602
- short: 'n',
603
- description: 'Clean specific namespace only',
604
- type: 'string'
605
- },
606
- {
607
- name: 'force',
608
- short: 'f',
609
- description: 'Skip confirmation',
610
- type: 'boolean',
611
- default: false
612
- }
613
- ],
614
- examples: [
615
- { command: 'claude-flow memory cleanup --dry-run', description: 'Preview cleanup' },
616
- { command: 'claude-flow memory cleanup --older-than 30d', description: 'Delete entries older than 30 days' },
617
- { command: 'claude-flow memory cleanup --expired-only', description: 'Clean expired entries' }
618
- ],
619
- action: async (ctx: CommandContext): Promise<CommandResult> => {
620
- const dryRun = ctx.flags.dryRun as boolean;
621
- const force = ctx.flags.force as boolean;
622
-
623
- if (dryRun) {
624
- output.writeln(output.warning('DRY RUN - No changes will be made'));
625
- }
626
-
627
- output.printInfo('Analyzing memory for cleanup...');
628
-
629
- try {
630
- const result = await callMCPTool<{
631
- dryRun: boolean;
632
- candidates: {
633
- expired: number;
634
- stale: number;
635
- lowQuality: number;
636
- total: number;
637
- };
638
- deleted: {
639
- entries: number;
640
- vectors: number;
641
- patterns: number;
642
- };
643
- freed: {
644
- bytes: number;
645
- formatted: string;
646
- };
647
- duration: number;
648
- }>('memory/cleanup', {
649
- dryRun,
650
- olderThan: ctx.flags.olderThan,
651
- expiredOnly: ctx.flags.expiredOnly,
652
- lowQualityThreshold: ctx.flags.lowQuality,
653
- namespace: ctx.flags.namespace,
654
- });
655
-
656
- if (ctx.flags.format === 'json') {
657
- output.printJson(result);
658
- return { success: true, data: result };
659
- }
660
-
661
- output.writeln();
662
- output.writeln(output.bold('Cleanup Analysis'));
663
- output.printTable({
664
- columns: [
665
- { key: 'category', header: 'Category', width: 20 },
666
- { key: 'count', header: 'Count', width: 15, align: 'right' }
667
- ],
668
- data: [
669
- { category: 'Expired (TTL)', count: result.candidates.expired },
670
- { category: 'Stale (unused)', count: result.candidates.stale },
671
- { category: 'Low Quality', count: result.candidates.lowQuality },
672
- { category: output.bold('Total'), count: output.bold(String(result.candidates.total)) }
673
- ]
674
- });
675
-
676
- if (!dryRun && result.candidates.total > 0 && !force) {
677
- const confirmed = await confirm({
678
- message: `Delete ${result.candidates.total} entries (${result.freed.formatted})?`,
679
- default: false
680
- });
681
-
682
- if (!confirmed) {
683
- output.printInfo('Cleanup cancelled');
684
- return { success: true, data: result };
685
- }
686
- }
687
-
688
- if (!dryRun) {
689
- output.writeln();
690
- output.printSuccess(`Cleaned ${result.deleted.entries} entries`);
691
- output.printList([
692
- `Vectors removed: ${result.deleted.vectors}`,
693
- `Patterns removed: ${result.deleted.patterns}`,
694
- `Space freed: ${result.freed.formatted}`,
695
- `Duration: ${result.duration}ms`
696
- ]);
697
- }
698
-
699
- return { success: true, data: result };
700
- } catch (error) {
701
- if (error instanceof MCPClientError) {
702
- output.printError(`Cleanup error: ${error.message}`);
703
- } else {
704
- output.printError(`Unexpected error: ${String(error)}`);
705
- }
706
- return { success: false, exitCode: 1 };
707
- }
708
- }
709
- };
710
-
711
- // Compress command
712
- const compressCommand: Command = {
713
- name: 'compress',
714
- description: 'Compress and optimize memory storage',
715
- options: [
716
- {
717
- name: 'level',
718
- short: 'l',
719
- description: 'Compression level (fast, balanced, max)',
720
- type: 'string',
721
- choices: ['fast', 'balanced', 'max'],
722
- default: 'balanced'
723
- },
724
- {
725
- name: 'target',
726
- short: 't',
727
- description: 'Target (vectors, text, patterns, all)',
728
- type: 'string',
729
- choices: ['vectors', 'text', 'patterns', 'all'],
730
- default: 'all'
731
- },
732
- {
733
- name: 'quantize',
734
- short: 'q',
735
- description: 'Enable vector quantization (reduces memory 4-32x)',
736
- type: 'boolean',
737
- default: false
738
- },
739
- {
740
- name: 'bits',
741
- description: 'Quantization bits (4, 8, 16)',
742
- type: 'number',
743
- default: 8
744
- },
745
- {
746
- name: 'rebuild-index',
747
- short: 'r',
748
- description: 'Rebuild HNSW index after compression',
749
- type: 'boolean',
750
- default: true
751
- }
752
- ],
753
- examples: [
754
- { command: 'claude-flow memory compress', description: 'Balanced compression' },
755
- { command: 'claude-flow memory compress --quantize --bits 4', description: '4-bit quantization (32x reduction)' },
756
- { command: 'claude-flow memory compress -l max -t vectors', description: 'Max compression on vectors' }
757
- ],
758
- action: async (ctx: CommandContext): Promise<CommandResult> => {
759
- const level = ctx.flags.level as string || 'balanced';
760
- const target = ctx.flags.target as string || 'all';
761
- const quantize = ctx.flags.quantize as boolean;
762
- const bits = ctx.flags.bits as number || 8;
763
- const rebuildIndex = ctx.flags.rebuildIndex as boolean ?? true;
764
-
765
- output.writeln();
766
- output.writeln(output.bold('Memory Compression'));
767
- output.writeln(output.dim(`Level: ${level}, Target: ${target}, Quantize: ${quantize ? `${bits}-bit` : 'no'}`));
768
- output.writeln();
769
-
770
- const spinner = output.createSpinner({ text: 'Analyzing current storage...', spinner: 'dots' });
771
- spinner.start();
772
-
773
- try {
774
- const result = await callMCPTool<{
775
- before: {
776
- totalSize: string;
777
- vectorsSize: string;
778
- textSize: string;
779
- patternsSize: string;
780
- indexSize: string;
781
- };
782
- after: {
783
- totalSize: string;
784
- vectorsSize: string;
785
- textSize: string;
786
- patternsSize: string;
787
- indexSize: string;
788
- };
789
- compression: {
790
- ratio: number;
791
- bytesSaved: number;
792
- formattedSaved: string;
793
- quantizationApplied: boolean;
794
- indexRebuilt: boolean;
795
- };
796
- performance: {
797
- searchLatencyBefore: number;
798
- searchLatencyAfter: number;
799
- searchSpeedup: string;
800
- };
801
- duration: number;
802
- }>('memory/compress', {
803
- level,
804
- target,
805
- quantize,
806
- bits,
807
- rebuildIndex,
808
- });
809
-
810
- spinner.succeed('Compression complete');
811
-
812
- if (ctx.flags.format === 'json') {
813
- output.printJson(result);
814
- return { success: true, data: result };
815
- }
816
-
817
- output.writeln();
818
- output.writeln(output.bold('Storage Comparison'));
819
- output.printTable({
820
- columns: [
821
- { key: 'category', header: 'Category', width: 15 },
822
- { key: 'before', header: 'Before', width: 12, align: 'right' },
823
- { key: 'after', header: 'After', width: 12, align: 'right' },
824
- { key: 'saved', header: 'Saved', width: 12, align: 'right' }
825
- ],
826
- data: [
827
- { category: 'Vectors', before: result.before.vectorsSize, after: result.after.vectorsSize, saved: '-' },
828
- { category: 'Text', before: result.before.textSize, after: result.after.textSize, saved: '-' },
829
- { category: 'Patterns', before: result.before.patternsSize, after: result.after.patternsSize, saved: '-' },
830
- { category: 'Index', before: result.before.indexSize, after: result.after.indexSize, saved: '-' },
831
- { category: output.bold('Total'), before: result.before.totalSize, after: result.after.totalSize, saved: output.success(result.compression.formattedSaved) }
832
- ]
833
- });
834
-
835
- output.writeln();
836
- output.printBox(
837
- [
838
- `Compression Ratio: ${result.compression.ratio.toFixed(2)}x`,
839
- `Space Saved: ${result.compression.formattedSaved}`,
840
- `Quantization: ${result.compression.quantizationApplied ? `Yes (${bits}-bit)` : 'No'}`,
841
- `Index Rebuilt: ${result.compression.indexRebuilt ? 'Yes' : 'No'}`,
842
- `Duration: ${(result.duration / 1000).toFixed(1)}s`
843
- ].join('\n'),
844
- 'Results'
845
- );
846
-
847
- if (result.performance) {
848
- output.writeln();
849
- output.writeln(output.bold('Performance Impact'));
850
- output.printList([
851
- `Search latency: ${result.performance.searchLatencyBefore.toFixed(2)}ms → ${result.performance.searchLatencyAfter.toFixed(2)}ms`,
852
- `Speedup: ${output.success(result.performance.searchSpeedup)}`
853
- ]);
854
- }
855
-
856
- return { success: true, data: result };
857
- } catch (error) {
858
- spinner.fail('Compression failed');
859
- if (error instanceof MCPClientError) {
860
- output.printError(`Compression error: ${error.message}`);
861
- } else {
862
- output.printError(`Unexpected error: ${String(error)}`);
863
- }
864
- return { success: false, exitCode: 1 };
865
- }
866
- }
867
- };
868
-
869
- // Export command
870
- const exportCommand: Command = {
871
- name: 'export',
872
- description: 'Export memory to file',
873
- options: [
874
- {
875
- name: 'output',
876
- short: 'o',
877
- description: 'Output file path',
878
- type: 'string',
879
- required: true
880
- },
881
- {
882
- name: 'format',
883
- short: 'f',
884
- description: 'Export format (json, csv, binary)',
885
- type: 'string',
886
- choices: ['json', 'csv', 'binary'],
887
- default: 'json'
888
- },
889
- {
890
- name: 'namespace',
891
- short: 'n',
892
- description: 'Export specific namespace',
893
- type: 'string'
894
- },
895
- {
896
- name: 'include-vectors',
897
- description: 'Include vector embeddings',
898
- type: 'boolean',
899
- default: true
900
- }
901
- ],
902
- examples: [
903
- { command: 'claude-flow memory export -o ./backup.json', description: 'Export all to JSON' },
904
- { command: 'claude-flow memory export -o ./data.csv -f csv', description: 'Export to CSV' }
905
- ],
906
- action: async (ctx: CommandContext): Promise<CommandResult> => {
907
- const outputPath = ctx.flags.output as string;
908
- const format = ctx.flags.format as string || 'json';
909
-
910
- if (!outputPath) {
911
- output.printError('Output path is required. Use --output or -o');
912
- return { success: false, exitCode: 1 };
913
- }
914
-
915
- output.printInfo(`Exporting memory to ${outputPath}...`);
916
-
917
- try {
918
- const result = await callMCPTool<{
919
- outputPath: string;
920
- format: string;
921
- exported: {
922
- entries: number;
923
- vectors: number;
924
- patterns: number;
925
- };
926
- fileSize: string;
927
- }>('memory/export', {
928
- outputPath,
929
- format,
930
- namespace: ctx.flags.namespace,
931
- includeVectors: ctx.flags.includeVectors ?? true,
932
- });
933
-
934
- output.printSuccess(`Exported to ${result.outputPath}`);
935
- output.printList([
936
- `Entries: ${result.exported.entries}`,
937
- `Vectors: ${result.exported.vectors}`,
938
- `Patterns: ${result.exported.patterns}`,
939
- `File size: ${result.fileSize}`
940
- ]);
941
-
942
- return { success: true, data: result };
943
- } catch (error) {
944
- if (error instanceof MCPClientError) {
945
- output.printError(`Export error: ${error.message}`);
946
- } else {
947
- output.printError(`Unexpected error: ${String(error)}`);
948
- }
949
- return { success: false, exitCode: 1 };
950
- }
951
- }
952
- };
953
-
954
- // Import command
955
- const importCommand: Command = {
956
- name: 'import',
957
- description: 'Import memory from file',
958
- options: [
959
- {
960
- name: 'input',
961
- short: 'i',
962
- description: 'Input file path',
963
- type: 'string',
964
- required: true
965
- },
966
- {
967
- name: 'merge',
968
- short: 'm',
969
- description: 'Merge with existing (skip duplicates)',
970
- type: 'boolean',
971
- default: true
972
- },
973
- {
974
- name: 'namespace',
975
- short: 'n',
976
- description: 'Import into specific namespace',
977
- type: 'string'
978
- }
979
- ],
980
- examples: [
981
- { command: 'claude-flow memory import -i ./backup.json', description: 'Import from file' },
982
- { command: 'claude-flow memory import -i ./data.json -n archive', description: 'Import to namespace' }
983
- ],
984
- action: async (ctx: CommandContext): Promise<CommandResult> => {
985
- const inputPath = ctx.flags.input as string || ctx.args[0];
986
-
987
- if (!inputPath) {
988
- output.printError('Input path is required. Use --input or -i');
989
- return { success: false, exitCode: 1 };
990
- }
991
-
992
- output.printInfo(`Importing memory from ${inputPath}...`);
993
-
994
- try {
995
- const result = await callMCPTool<{
996
- inputPath: string;
997
- imported: {
998
- entries: number;
999
- vectors: number;
1000
- patterns: number;
1001
- };
1002
- skipped: number;
1003
- duration: number;
1004
- }>('memory/import', {
1005
- inputPath,
1006
- merge: ctx.flags.merge ?? true,
1007
- namespace: ctx.flags.namespace,
1008
- });
1009
-
1010
- output.printSuccess(`Imported from ${result.inputPath}`);
1011
- output.printList([
1012
- `Entries: ${result.imported.entries}`,
1013
- `Vectors: ${result.imported.vectors}`,
1014
- `Patterns: ${result.imported.patterns}`,
1015
- `Skipped (duplicates): ${result.skipped}`,
1016
- `Duration: ${result.duration}ms`
1017
- ]);
1018
-
1019
- return { success: true, data: result };
1020
- } catch (error) {
1021
- if (error instanceof MCPClientError) {
1022
- output.printError(`Import error: ${error.message}`);
1023
- } else {
1024
- output.printError(`Unexpected error: ${String(error)}`);
1025
- }
1026
- return { success: false, exitCode: 1 };
1027
- }
1028
- }
1029
- };
1030
-
1031
- // Main memory command
1032
- export const memoryCommand: Command = {
1033
- name: 'memory',
1034
- description: 'Memory management commands',
1035
- subcommands: [storeCommand, retrieveCommand, searchCommand, listCommand, deleteCommand, statsCommand, configureCommand, cleanupCommand, compressCommand, exportCommand, importCommand],
1036
- options: [],
1037
- examples: [
1038
- { command: 'claude-flow memory store -k "key" -v "value"', description: 'Store data' },
1039
- { command: 'claude-flow memory search -q "auth patterns"', description: 'Search memory' },
1040
- { command: 'claude-flow memory stats', description: 'Show statistics' }
1041
- ],
1042
- action: async (ctx: CommandContext): Promise<CommandResult> => {
1043
- output.writeln();
1044
- output.writeln(output.bold('Memory Management Commands'));
1045
- output.writeln();
1046
- output.writeln('Usage: claude-flow memory <subcommand> [options]');
1047
- output.writeln();
1048
- output.writeln('Subcommands:');
1049
- output.printList([
1050
- `${output.highlight('store')} - Store data in memory`,
1051
- `${output.highlight('retrieve')} - Retrieve data from memory`,
1052
- `${output.highlight('search')} - Semantic/vector search`,
1053
- `${output.highlight('list')} - List memory entries`,
1054
- `${output.highlight('delete')} - Delete memory entry`,
1055
- `${output.highlight('stats')} - Show statistics`,
1056
- `${output.highlight('configure')} - Configure backend`
1057
- ]);
1058
-
1059
- return { success: true };
1060
- }
1061
- };
1062
-
1063
- export default memoryCommand;