@claude-flow/cli 3.0.0-alpha.11 → 3.0.0-alpha.13

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 (51) hide show
  1. package/.agentic-flow/intelligence.json +4 -4
  2. package/.claude-flow/daemon-state.json +24 -24
  3. package/.claude-flow/metrics/codebase-map.json +2 -2
  4. package/.claude-flow/metrics/consolidation.json +1 -1
  5. package/.claude-flow/metrics/performance.json +3 -3
  6. package/.claude-flow/metrics/security-audit.json +1 -1
  7. package/.claude-flow/metrics/task-metrics.json +3 -3
  8. package/.claude-flow/metrics/test-gaps.json +1 -1
  9. package/README.md +172 -6
  10. package/agents/architect.yaml +1 -1
  11. package/agents/coder.yaml +1 -1
  12. package/agents/reviewer.yaml +1 -1
  13. package/agents/security-architect.yaml +1 -1
  14. package/agents/tester.yaml +1 -1
  15. package/dist/src/commands/completions.d.ts +10 -0
  16. package/dist/src/commands/completions.d.ts.map +1 -0
  17. package/dist/src/commands/completions.js +539 -0
  18. package/dist/src/commands/completions.js.map +1 -0
  19. package/dist/src/commands/doctor.d.ts +10 -0
  20. package/dist/src/commands/doctor.d.ts.map +1 -0
  21. package/dist/src/commands/doctor.js +356 -0
  22. package/dist/src/commands/doctor.js.map +1 -0
  23. package/dist/src/commands/embeddings.d.ts +8 -0
  24. package/dist/src/commands/embeddings.d.ts.map +1 -1
  25. package/dist/src/commands/embeddings.js +328 -6
  26. package/dist/src/commands/embeddings.js.map +1 -1
  27. package/dist/src/commands/index.d.ts +2 -0
  28. package/dist/src/commands/index.d.ts.map +1 -1
  29. package/dist/src/commands/index.js +9 -0
  30. package/dist/src/commands/index.js.map +1 -1
  31. package/dist/src/commands/memory.js +2 -2
  32. package/dist/src/commands/memory.js.map +1 -1
  33. package/dist/src/commands/neural.js +1 -1
  34. package/dist/src/commands/neural.js.map +1 -1
  35. package/dist/src/index.d.ts.map +1 -1
  36. package/dist/src/index.js +15 -2
  37. package/dist/src/index.js.map +1 -1
  38. package/dist/src/suggest.d.ts +53 -0
  39. package/dist/src/suggest.d.ts.map +1 -0
  40. package/dist/src/suggest.js +200 -0
  41. package/dist/src/suggest.js.map +1 -0
  42. package/dist/tsconfig.tsbuildinfo +1 -1
  43. package/package.json +1 -1
  44. package/src/commands/completions.ts +558 -0
  45. package/src/commands/doctor.ts +382 -0
  46. package/src/commands/embeddings.ts +360 -6
  47. package/src/commands/index.ts +9 -0
  48. package/src/commands/memory.ts +2 -2
  49. package/src/commands/neural.ts +1 -1
  50. package/src/index.ts +15 -3
  51. package/src/suggest.ts +245 -0
package/src/suggest.ts ADDED
@@ -0,0 +1,245 @@
1
+ /**
2
+ * V3 CLI Smart Error Suggestions
3
+ * Levenshtein distance and command suggestions
4
+ *
5
+ * Created with ruv.io
6
+ */
7
+
8
+ /**
9
+ * Calculate Levenshtein distance between two strings
10
+ */
11
+ export function levenshteinDistance(a: string, b: string): number {
12
+ const m = a.length;
13
+ const n = b.length;
14
+
15
+ // Early termination for empty strings
16
+ if (m === 0) return n;
17
+ if (n === 0) return m;
18
+
19
+ // Create distance matrix
20
+ const d: number[][] = Array(m + 1).fill(null).map(() => Array(n + 1).fill(0));
21
+
22
+ // Initialize first column
23
+ for (let i = 0; i <= m; i++) {
24
+ d[i][0] = i;
25
+ }
26
+
27
+ // Initialize first row
28
+ for (let j = 0; j <= n; j++) {
29
+ d[0][j] = j;
30
+ }
31
+
32
+ // Fill in the rest of the matrix
33
+ for (let j = 1; j <= n; j++) {
34
+ for (let i = 1; i <= m; i++) {
35
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
36
+ d[i][j] = Math.min(
37
+ d[i - 1][j] + 1, // deletion
38
+ d[i][j - 1] + 1, // insertion
39
+ d[i - 1][j - 1] + cost // substitution
40
+ );
41
+ }
42
+ }
43
+
44
+ return d[m][n];
45
+ }
46
+
47
+ /**
48
+ * Calculate similarity score (0-1) between two strings
49
+ */
50
+ export function similarityScore(a: string, b: string): number {
51
+ const maxLen = Math.max(a.length, b.length);
52
+ if (maxLen === 0) return 1;
53
+ const distance = levenshteinDistance(a.toLowerCase(), b.toLowerCase());
54
+ return 1 - distance / maxLen;
55
+ }
56
+
57
+ /**
58
+ * Find similar strings from a list
59
+ */
60
+ export function findSimilar(
61
+ input: string,
62
+ candidates: string[],
63
+ options: {
64
+ maxSuggestions?: number;
65
+ minSimilarity?: number;
66
+ maxDistance?: number;
67
+ } = {}
68
+ ): string[] {
69
+ const {
70
+ maxSuggestions = 3,
71
+ minSimilarity = 0.4,
72
+ maxDistance = 3
73
+ } = options;
74
+
75
+ const inputLower = input.toLowerCase();
76
+
77
+ // Score all candidates
78
+ const scored = candidates
79
+ .map(candidate => ({
80
+ candidate,
81
+ distance: levenshteinDistance(inputLower, candidate.toLowerCase()),
82
+ similarity: similarityScore(inputLower, candidate),
83
+ // Boost prefix matches
84
+ prefixBoost: candidate.toLowerCase().startsWith(inputLower) ? 0.3 : 0
85
+ }))
86
+ .filter(s => s.distance <= maxDistance || s.similarity >= minSimilarity)
87
+ .map(s => ({
88
+ ...s,
89
+ score: s.similarity + s.prefixBoost
90
+ }))
91
+ .sort((a, b) => b.score - a.score)
92
+ .slice(0, maxSuggestions);
93
+
94
+ return scored.map(s => s.candidate);
95
+ }
96
+
97
+ /**
98
+ * Format suggestion message for CLI errors
99
+ */
100
+ export function formatSuggestion(
101
+ invalidInput: string,
102
+ suggestions: string[],
103
+ context: 'command' | 'subcommand' | 'option' | 'value' = 'command'
104
+ ): string {
105
+ if (suggestions.length === 0) {
106
+ return '';
107
+ }
108
+
109
+ const contextMap = {
110
+ command: 'Did you mean',
111
+ subcommand: 'Available subcommands',
112
+ option: 'Did you mean',
113
+ value: 'Valid values'
114
+ };
115
+
116
+ const prefix = contextMap[context];
117
+
118
+ if (suggestions.length === 1) {
119
+ return `\n ${prefix}: ${suggestions[0]}`;
120
+ }
121
+
122
+ return `\n ${prefix}:\n${suggestions.map(s => ` - ${s}`).join('\n')}`;
123
+ }
124
+
125
+ /**
126
+ * Common typos and their corrections
127
+ */
128
+ export const COMMON_TYPOS: Record<string, string> = {
129
+ 'init': 'init',
130
+ 'initi': 'init',
131
+ 'inizialize': 'init',
132
+ 'staus': 'status',
133
+ 'stauts': 'status',
134
+ 'stats': 'stats',
135
+ 'stat': 'status',
136
+ 'swarrm': 'swarm',
137
+ 'swarn': 'swarm',
138
+ 'agnet': 'agent',
139
+ 'agen': 'agent',
140
+ 'memroy': 'memory',
141
+ 'mem': 'memory',
142
+ 'memmory': 'memory',
143
+ 'confg': 'config',
144
+ 'conf': 'config',
145
+ 'configu': 'config',
146
+ 'hook': 'hooks',
147
+ 'hoks': 'hooks',
148
+ 'hive': 'hive-mind',
149
+ 'hivemind': 'hive-mind',
150
+ 'hive_mind': 'hive-mind',
151
+ 'neurl': 'neural',
152
+ 'nueral': 'neural',
153
+ 'securty': 'security',
154
+ 'sec': 'security',
155
+ 'perf': 'performance',
156
+ 'performace': 'performance',
157
+ 'provider': 'providers',
158
+ 'plugin': 'plugins',
159
+ 'dep': 'deployment',
160
+ 'depoly': 'deployment',
161
+ 'deploy': 'deployment',
162
+ 'claim': 'claims',
163
+ 'embed': 'embeddings',
164
+ 'embeding': 'embeddings',
165
+ 'daemon': 'daemon',
166
+ 'deamon': 'daemon',
167
+ 'doc': 'doctor',
168
+ 'docter': 'doctor',
169
+ 'complete': 'completions',
170
+ 'completion': 'completions',
171
+ 'comp': 'completions',
172
+ 'task': 'task',
173
+ 'taks': 'task',
174
+ 'sessio': 'session',
175
+ 'sess': 'session',
176
+ 'sesssion': 'session',
177
+ 'workflow': 'workflow',
178
+ 'wf': 'workflow',
179
+ 'wokflow': 'workflow'
180
+ };
181
+
182
+ /**
183
+ * Get corrected command if it's a common typo
184
+ */
185
+ export function getTypoCorrection(input: string): string | undefined {
186
+ return COMMON_TYPOS[input.toLowerCase()];
187
+ }
188
+
189
+ /**
190
+ * Smart command suggestion for unknown commands
191
+ */
192
+ export function suggestCommand(
193
+ unknownCommand: string,
194
+ availableCommands: string[]
195
+ ): {
196
+ correction?: string;
197
+ suggestions: string[];
198
+ message: string;
199
+ } {
200
+ // Check for common typo first
201
+ const correction = getTypoCorrection(unknownCommand);
202
+ if (correction && availableCommands.includes(correction)) {
203
+ return {
204
+ correction,
205
+ suggestions: [correction],
206
+ message: `Did you mean "${correction}"?`
207
+ };
208
+ }
209
+
210
+ // Find similar commands
211
+ const suggestions = findSimilar(unknownCommand, availableCommands, {
212
+ maxSuggestions: 3,
213
+ minSimilarity: 0.3,
214
+ maxDistance: 4
215
+ });
216
+
217
+ if (suggestions.length === 0) {
218
+ return {
219
+ suggestions: [],
220
+ message: 'Run "claude-flow --help" to see available commands.'
221
+ };
222
+ }
223
+
224
+ if (suggestions.length === 1) {
225
+ return {
226
+ suggestions,
227
+ message: `Did you mean "${suggestions[0]}"?`
228
+ };
229
+ }
230
+
231
+ return {
232
+ suggestions,
233
+ message: `Did you mean one of these?\n${suggestions.map(s => ` - ${s}`).join('\n')}`
234
+ };
235
+ }
236
+
237
+ export default {
238
+ levenshteinDistance,
239
+ similarityScore,
240
+ findSimilar,
241
+ formatSuggestion,
242
+ suggestCommand,
243
+ getTypoCorrection,
244
+ COMMON_TYPOS
245
+ };