@wundr.io/cli 1.0.10 → 1.0.12

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 (269) hide show
  1. package/bin/wundr.js +8 -4
  2. package/package.json +23 -23
  3. package/src/ai/ai-service.ts +16 -17
  4. package/src/ai/claude-client.ts +16 -16
  5. package/src/ai/conversation-manager.ts +29 -29
  6. package/src/cli.ts +4 -4
  7. package/src/commands/ai.ts +246 -78
  8. package/src/commands/alignment.ts +74 -74
  9. package/src/commands/analyze-optimized.ts +111 -78
  10. package/src/commands/analyze.ts +14 -14
  11. package/src/commands/batch.ts +179 -42
  12. package/src/commands/chat.ts +37 -30
  13. package/src/commands/claude-init.ts +41 -45
  14. package/src/commands/claude-setup.ts +204 -119
  15. package/src/commands/computer-setup.ts +85 -43
  16. package/src/commands/create-command.ts +4 -4
  17. package/src/commands/create.ts +27 -27
  18. package/src/commands/dashboard.ts +24 -24
  19. package/src/commands/govern.ts +25 -25
  20. package/src/commands/governance.ts +34 -34
  21. package/src/commands/guardian.ts +56 -56
  22. package/src/commands/init.ts +25 -22
  23. package/src/commands/orchestrator.ts +68 -41
  24. package/src/commands/performance-optimizer.ts +34 -35
  25. package/src/commands/plugins.ts +27 -27
  26. package/src/commands/project-update.ts +175 -72
  27. package/src/commands/rag.ts +185 -78
  28. package/src/commands/session.ts +35 -35
  29. package/src/commands/setup.ts +40 -344
  30. package/src/commands/test-init.ts +3 -3
  31. package/src/commands/test.ts +4 -4
  32. package/src/commands/watch.ts +28 -29
  33. package/src/commands/worktree.ts +49 -49
  34. package/src/context/context-manager.ts +10 -10
  35. package/src/context/session-manager.ts +41 -41
  36. package/src/framework/command-interface.ts +520 -0
  37. package/src/framework/command-registry.ts +942 -0
  38. package/src/framework/completion-exporter.ts +383 -0
  39. package/src/framework/debug-logger.ts +519 -0
  40. package/src/framework/error-handler.ts +867 -0
  41. package/src/framework/help-generator.ts +540 -0
  42. package/src/framework/index.ts +169 -0
  43. package/src/framework/interactive-repl.ts +703 -0
  44. package/src/framework/output-formatter.ts +834 -0
  45. package/src/framework/progress-manager.ts +539 -0
  46. package/src/index.ts +4 -4
  47. package/src/interactive/interactive-mode.ts +16 -16
  48. package/src/lib/conflict-resolution.ts +799 -9
  49. package/src/lib/merge-strategy.ts +529 -7
  50. package/src/lib/safety-mechanisms.ts +422 -18
  51. package/src/lib/state-detection.ts +1015 -13
  52. package/src/nlp/command-mapper.ts +29 -29
  53. package/src/nlp/command-parser.ts +17 -17
  54. package/src/nlp/intent-classifier.ts +7 -7
  55. package/src/nlp/intent-parser.ts +54 -52
  56. package/src/plugins/plugin-manager.ts +61 -39
  57. package/src/tests/computer-setup-integration.test.ts +46 -15
  58. package/src/types/modules.d.ts +424 -1
  59. package/src/utils/backup-rollback-manager.ts +11 -8
  60. package/src/utils/config-manager.ts +3 -3
  61. package/src/utils/error-handler.ts +2 -2
  62. package/src/utils/logger.ts +22 -22
  63. package/templates/batch/ci-cd.yaml +7 -7
  64. package/test-suites/api/health.spec.ts +20 -23
  65. package/test-suites/helpers/test-config.ts +14 -13
  66. package/test-suites/ui/accessibility.spec.ts +27 -22
  67. package/test-suites/ui/smoke.spec.ts +26 -21
  68. package/LICENSE +0 -21
  69. package/dist/ai/ai-service.d.ts +0 -152
  70. package/dist/ai/ai-service.d.ts.map +0 -1
  71. package/dist/ai/ai-service.js +0 -430
  72. package/dist/ai/ai-service.js.map +0 -1
  73. package/dist/ai/claude-client.d.ts +0 -130
  74. package/dist/ai/claude-client.d.ts.map +0 -1
  75. package/dist/ai/claude-client.js +0 -340
  76. package/dist/ai/claude-client.js.map +0 -1
  77. package/dist/ai/conversation-manager.d.ts +0 -164
  78. package/dist/ai/conversation-manager.d.ts.map +0 -1
  79. package/dist/ai/conversation-manager.js +0 -614
  80. package/dist/ai/conversation-manager.js.map +0 -1
  81. package/dist/ai/index.d.ts +0 -5
  82. package/dist/ai/index.d.ts.map +0 -1
  83. package/dist/ai/index.js +0 -8
  84. package/dist/ai/index.js.map +0 -1
  85. package/dist/cli.d.ts +0 -36
  86. package/dist/cli.d.ts.map +0 -1
  87. package/dist/cli.js +0 -192
  88. package/dist/cli.js.map +0 -1
  89. package/dist/commands/ai.d.ts +0 -89
  90. package/dist/commands/ai.d.ts.map +0 -1
  91. package/dist/commands/ai.js +0 -799
  92. package/dist/commands/ai.js.map +0 -1
  93. package/dist/commands/alignment.d.ts +0 -78
  94. package/dist/commands/alignment.d.ts.map +0 -1
  95. package/dist/commands/alignment.js +0 -817
  96. package/dist/commands/alignment.js.map +0 -1
  97. package/dist/commands/analyze-optimized.d.ts +0 -14
  98. package/dist/commands/analyze-optimized.d.ts.map +0 -1
  99. package/dist/commands/analyze-optimized.js +0 -600
  100. package/dist/commands/analyze-optimized.js.map +0 -1
  101. package/dist/commands/analyze.d.ts +0 -65
  102. package/dist/commands/analyze.d.ts.map +0 -1
  103. package/dist/commands/analyze.js +0 -435
  104. package/dist/commands/analyze.js.map +0 -1
  105. package/dist/commands/batch.d.ts +0 -71
  106. package/dist/commands/batch.d.ts.map +0 -1
  107. package/dist/commands/batch.js +0 -738
  108. package/dist/commands/batch.js.map +0 -1
  109. package/dist/commands/chat.d.ts +0 -71
  110. package/dist/commands/chat.d.ts.map +0 -1
  111. package/dist/commands/chat.js +0 -674
  112. package/dist/commands/chat.js.map +0 -1
  113. package/dist/commands/claude-init.d.ts +0 -28
  114. package/dist/commands/claude-init.d.ts.map +0 -1
  115. package/dist/commands/claude-init.js +0 -591
  116. package/dist/commands/claude-init.js.map +0 -1
  117. package/dist/commands/claude-setup.d.ts +0 -119
  118. package/dist/commands/claude-setup.d.ts.map +0 -1
  119. package/dist/commands/claude-setup.js +0 -1073
  120. package/dist/commands/claude-setup.js.map +0 -1
  121. package/dist/commands/computer-setup-commands.d.ts +0 -53
  122. package/dist/commands/computer-setup-commands.d.ts.map +0 -1
  123. package/dist/commands/computer-setup-commands.js +0 -705
  124. package/dist/commands/computer-setup-commands.js.map +0 -1
  125. package/dist/commands/computer-setup.d.ts +0 -7
  126. package/dist/commands/computer-setup.d.ts.map +0 -1
  127. package/dist/commands/computer-setup.js +0 -849
  128. package/dist/commands/computer-setup.js.map +0 -1
  129. package/dist/commands/create-command.d.ts +0 -7
  130. package/dist/commands/create-command.d.ts.map +0 -1
  131. package/dist/commands/create-command.js +0 -158
  132. package/dist/commands/create-command.js.map +0 -1
  133. package/dist/commands/create.d.ts +0 -74
  134. package/dist/commands/create.d.ts.map +0 -1
  135. package/dist/commands/create.js +0 -556
  136. package/dist/commands/create.js.map +0 -1
  137. package/dist/commands/dashboard.d.ts +0 -91
  138. package/dist/commands/dashboard.d.ts.map +0 -1
  139. package/dist/commands/dashboard.js +0 -538
  140. package/dist/commands/dashboard.js.map +0 -1
  141. package/dist/commands/govern.d.ts +0 -70
  142. package/dist/commands/govern.d.ts.map +0 -1
  143. package/dist/commands/govern.js +0 -481
  144. package/dist/commands/govern.js.map +0 -1
  145. package/dist/commands/governance.d.ts +0 -17
  146. package/dist/commands/governance.d.ts.map +0 -1
  147. package/dist/commands/governance.js +0 -703
  148. package/dist/commands/governance.js.map +0 -1
  149. package/dist/commands/guardian.d.ts +0 -20
  150. package/dist/commands/guardian.d.ts.map +0 -1
  151. package/dist/commands/guardian.js +0 -597
  152. package/dist/commands/guardian.js.map +0 -1
  153. package/dist/commands/init.d.ts +0 -59
  154. package/dist/commands/init.d.ts.map +0 -1
  155. package/dist/commands/init.js +0 -650
  156. package/dist/commands/init.js.map +0 -1
  157. package/dist/commands/orchestrator.d.ts +0 -7
  158. package/dist/commands/orchestrator.d.ts.map +0 -1
  159. package/dist/commands/orchestrator.js +0 -571
  160. package/dist/commands/orchestrator.js.map +0 -1
  161. package/dist/commands/performance-optimizer.d.ts +0 -30
  162. package/dist/commands/performance-optimizer.d.ts.map +0 -1
  163. package/dist/commands/performance-optimizer.js +0 -650
  164. package/dist/commands/performance-optimizer.js.map +0 -1
  165. package/dist/commands/plugins.d.ts +0 -87
  166. package/dist/commands/plugins.d.ts.map +0 -1
  167. package/dist/commands/plugins.js +0 -685
  168. package/dist/commands/plugins.js.map +0 -1
  169. package/dist/commands/rag.d.ts +0 -7
  170. package/dist/commands/rag.d.ts.map +0 -1
  171. package/dist/commands/rag.js +0 -748
  172. package/dist/commands/rag.js.map +0 -1
  173. package/dist/commands/session.d.ts +0 -41
  174. package/dist/commands/session.d.ts.map +0 -1
  175. package/dist/commands/session.js +0 -441
  176. package/dist/commands/session.js.map +0 -1
  177. package/dist/commands/setup.d.ts +0 -29
  178. package/dist/commands/setup.d.ts.map +0 -1
  179. package/dist/commands/setup.js +0 -397
  180. package/dist/commands/setup.js.map +0 -1
  181. package/dist/commands/test-init.d.ts +0 -9
  182. package/dist/commands/test-init.d.ts.map +0 -1
  183. package/dist/commands/test-init.js +0 -222
  184. package/dist/commands/test-init.js.map +0 -1
  185. package/dist/commands/test.d.ts +0 -25
  186. package/dist/commands/test.d.ts.map +0 -1
  187. package/dist/commands/test.js +0 -217
  188. package/dist/commands/test.js.map +0 -1
  189. package/dist/commands/vp.d.ts +0 -7
  190. package/dist/commands/vp.d.ts.map +0 -1
  191. package/dist/commands/vp.js +0 -571
  192. package/dist/commands/vp.js.map +0 -1
  193. package/dist/commands/watch.d.ts +0 -76
  194. package/dist/commands/watch.d.ts.map +0 -1
  195. package/dist/commands/watch.js +0 -613
  196. package/dist/commands/watch.js.map +0 -1
  197. package/dist/commands/worktree.d.ts +0 -63
  198. package/dist/commands/worktree.d.ts.map +0 -1
  199. package/dist/commands/worktree.js +0 -774
  200. package/dist/commands/worktree.js.map +0 -1
  201. package/dist/context/context-manager.d.ts +0 -155
  202. package/dist/context/context-manager.d.ts.map +0 -1
  203. package/dist/context/context-manager.js +0 -383
  204. package/dist/context/context-manager.js.map +0 -1
  205. package/dist/context/index.d.ts +0 -3
  206. package/dist/context/index.d.ts.map +0 -1
  207. package/dist/context/index.js +0 -6
  208. package/dist/context/index.js.map +0 -1
  209. package/dist/context/session-manager.d.ts +0 -207
  210. package/dist/context/session-manager.d.ts.map +0 -1
  211. package/dist/context/session-manager.js +0 -686
  212. package/dist/context/session-manager.js.map +0 -1
  213. package/dist/index.d.ts +0 -8
  214. package/dist/index.d.ts.map +0 -1
  215. package/dist/index.js +0 -51
  216. package/dist/index.js.map +0 -1
  217. package/dist/interactive/interactive-mode.d.ts +0 -76
  218. package/dist/interactive/interactive-mode.d.ts.map +0 -1
  219. package/dist/interactive/interactive-mode.js +0 -732
  220. package/dist/interactive/interactive-mode.js.map +0 -1
  221. package/dist/nlp/command-mapper.d.ts +0 -174
  222. package/dist/nlp/command-mapper.d.ts.map +0 -1
  223. package/dist/nlp/command-mapper.js +0 -624
  224. package/dist/nlp/command-mapper.js.map +0 -1
  225. package/dist/nlp/command-parser.d.ts +0 -106
  226. package/dist/nlp/command-parser.d.ts.map +0 -1
  227. package/dist/nlp/command-parser.js +0 -417
  228. package/dist/nlp/command-parser.js.map +0 -1
  229. package/dist/nlp/index.d.ts +0 -5
  230. package/dist/nlp/index.d.ts.map +0 -1
  231. package/dist/nlp/index.js +0 -8
  232. package/dist/nlp/index.js.map +0 -1
  233. package/dist/nlp/intent-classifier.d.ts +0 -59
  234. package/dist/nlp/intent-classifier.d.ts.map +0 -1
  235. package/dist/nlp/intent-classifier.js +0 -384
  236. package/dist/nlp/intent-classifier.js.map +0 -1
  237. package/dist/nlp/intent-parser.d.ts +0 -152
  238. package/dist/nlp/intent-parser.d.ts.map +0 -1
  239. package/dist/nlp/intent-parser.js +0 -744
  240. package/dist/nlp/intent-parser.js.map +0 -1
  241. package/dist/plugins/plugin-manager.d.ts +0 -120
  242. package/dist/plugins/plugin-manager.d.ts.map +0 -1
  243. package/dist/plugins/plugin-manager.js +0 -595
  244. package/dist/plugins/plugin-manager.js.map +0 -1
  245. package/dist/types/index.d.ts +0 -224
  246. package/dist/types/index.d.ts.map +0 -1
  247. package/dist/types/index.js +0 -3
  248. package/dist/types/index.js.map +0 -1
  249. package/dist/utils/backup-rollback-manager.d.ts +0 -72
  250. package/dist/utils/backup-rollback-manager.d.ts.map +0 -1
  251. package/dist/utils/backup-rollback-manager.js +0 -289
  252. package/dist/utils/backup-rollback-manager.js.map +0 -1
  253. package/dist/utils/claude-config-installer.d.ts +0 -98
  254. package/dist/utils/claude-config-installer.d.ts.map +0 -1
  255. package/dist/utils/claude-config-installer.js +0 -678
  256. package/dist/utils/claude-config-installer.js.map +0 -1
  257. package/dist/utils/config-manager.d.ts +0 -73
  258. package/dist/utils/config-manager.d.ts.map +0 -1
  259. package/dist/utils/config-manager.js +0 -339
  260. package/dist/utils/config-manager.js.map +0 -1
  261. package/dist/utils/error-handler.d.ts +0 -46
  262. package/dist/utils/error-handler.d.ts.map +0 -1
  263. package/dist/utils/error-handler.js +0 -169
  264. package/dist/utils/error-handler.js.map +0 -1
  265. package/dist/utils/logger.d.ts +0 -25
  266. package/dist/utils/logger.d.ts.map +0 -1
  267. package/dist/utils/logger.js +0 -105
  268. package/dist/utils/logger.js.map +0 -1
  269. package/src/commands/computer-setup-commands.ts +0 -872
@@ -1,744 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IntentParser = void 0;
4
- const events_1 = require("events");
5
- const logger_1 = require("../utils/logger");
6
- /**
7
- * Advanced NLP Intent Parser for converting natural language to CLI commands
8
- */
9
- class IntentParser extends events_1.EventEmitter {
10
- claudeClient;
11
- config;
12
- commandPatterns;
13
- intentCache;
14
- entityPatterns;
15
- constructor(claudeClient, config = {}) {
16
- super();
17
- this.claudeClient = claudeClient;
18
- this.config = {
19
- confidenceThreshold: 0.7,
20
- maxAlternatives: 3,
21
- enableNER: true,
22
- enableContextAwareness: true,
23
- cacheDuration: 5 * 60 * 1000, // 5 minutes
24
- ...config,
25
- };
26
- this.commandPatterns = new Map();
27
- this.intentCache = new Map();
28
- this.entityPatterns = new Map();
29
- this.initializePatterns();
30
- this.initializeEntityRecognition();
31
- }
32
- /**
33
- * Parse natural language input and extract intent
34
- */
35
- async parseIntent(input, availableCommands, context = {}) {
36
- const normalizedInput = this.normalizeInput(input);
37
- const cacheKey = this.getCacheKey(normalizedInput, availableCommands, context);
38
- // Check cache first
39
- const cached = this.intentCache.get(cacheKey);
40
- if (cached && Date.now() - cached.timestamp < this.config.cacheDuration) {
41
- logger_1.logger.debug('Returning cached intent result');
42
- return cached.result;
43
- }
44
- try {
45
- // Step 1: Quick pattern matching for common commands
46
- const patternResult = await this.patternMatching(normalizedInput, availableCommands);
47
- if (patternResult.confidence >= 0.9) {
48
- this.cacheResult(cacheKey, patternResult);
49
- return patternResult;
50
- }
51
- // Step 2: Named Entity Recognition
52
- const entities = this.config.enableNER
53
- ? await this.extractEntities(normalizedInput)
54
- : [];
55
- // Step 3: AI-powered intent analysis
56
- const aiResult = await this.aiIntentAnalysis(normalizedInput, availableCommands, context, entities);
57
- // Step 4: Combine results and validate
58
- const finalResult = this.combineResults(patternResult, aiResult, entities);
59
- // Step 5: Post-processing and validation
60
- const validatedResult = await this.validateAndEnrich(finalResult, availableCommands, context);
61
- this.cacheResult(cacheKey, validatedResult);
62
- this.emit('intent_parsed', {
63
- input: normalizedInput,
64
- result: validatedResult,
65
- });
66
- return validatedResult;
67
- }
68
- catch (error) {
69
- logger_1.logger.error('Intent parsing failed:', error);
70
- return this.fallbackIntentParsing(normalizedInput, availableCommands, context);
71
- }
72
- }
73
- /**
74
- * Extract command parameters from natural language
75
- */
76
- async extractParameters(input, command, commandPattern) {
77
- const parameters = {};
78
- if (!commandPattern) {
79
- commandPattern = this.commandPatterns.get(command);
80
- }
81
- if (!commandPattern) {
82
- logger_1.logger.debug(`No pattern found for command: ${command}`);
83
- return parameters;
84
- }
85
- // Extract using AI
86
- const systemPrompt = `You are a parameter extraction system. Extract parameters from user input for the command "${command}".
87
-
88
- Command parameters:
89
- ${commandPattern.parameters.map(p => `- ${p.name} (${p.type}${p.required ? ', required' : ', optional'}): ${p.aliases?.join(', ') || ''}`).join('\n')}
90
-
91
- Extract parameters from the user input and respond with JSON only:
92
- {
93
- "parameters": {
94
- "paramName": "value"
95
- },
96
- "confidence": 0.9
97
- }`;
98
- try {
99
- const response = await this.claudeClient.sendMessage(input, systemPrompt, {
100
- temperature: 0.1,
101
- maxTokens: 1024,
102
- });
103
- const result = JSON.parse(response.trim());
104
- // Validate extracted parameters
105
- for (const param of commandPattern.parameters) {
106
- if (param.required && !result.parameters[param.name]) {
107
- logger_1.logger.warn(`Missing required parameter: ${param.name}`);
108
- }
109
- if (result.parameters[param.name] && param.validation) {
110
- if (!param.validation.test(result.parameters[param.name])) {
111
- logger_1.logger.warn(`Parameter validation failed for ${param.name}: ${result.parameters[param.name]}`);
112
- delete result.parameters[param.name];
113
- }
114
- }
115
- // Apply default values
116
- if (!result.parameters[param.name] &&
117
- param.defaultValue !== undefined) {
118
- result.parameters[param.name] = param.defaultValue;
119
- }
120
- }
121
- return result.parameters;
122
- }
123
- catch (error) {
124
- logger_1.logger.error('Parameter extraction failed:', error);
125
- return this.fallbackParameterExtraction(input, commandPattern);
126
- }
127
- }
128
- /**
129
- * Suggest commands based on partial input
130
- */
131
- async suggestCommands(partialInput, availableCommands, context = {}, limit = 5) {
132
- const suggestions = [];
133
- // Pattern-based suggestions
134
- const patternSuggestions = this.getPatternSuggestions(partialInput, availableCommands);
135
- suggestions.push(...patternSuggestions);
136
- // AI-powered suggestions if we need more
137
- if (suggestions.length < limit) {
138
- try {
139
- const aiSuggestions = await this.getAISuggestions(partialInput, availableCommands, context, limit - suggestions.length);
140
- suggestions.push(...aiSuggestions);
141
- }
142
- catch (error) {
143
- logger_1.logger.error('AI suggestions failed:', error);
144
- }
145
- }
146
- // Sort by confidence and limit results
147
- suggestions.sort((a, b) => b.confidence - a.confidence);
148
- return suggestions.slice(0, limit);
149
- }
150
- /**
151
- * Register a custom command pattern
152
- */
153
- registerCommandPattern(pattern) {
154
- this.commandPatterns.set(pattern.intent, pattern);
155
- logger_1.logger.debug(`Registered command pattern: ${pattern.intent}`);
156
- }
157
- /**
158
- * Batch register multiple command patterns
159
- */
160
- registerCommandPatterns(patterns) {
161
- patterns.forEach(pattern => this.registerCommandPattern(pattern));
162
- }
163
- /**
164
- * Get registered command patterns
165
- */
166
- getCommandPatterns() {
167
- return Array.from(this.commandPatterns.values());
168
- }
169
- /**
170
- * Clear intent cache
171
- */
172
- clearCache() {
173
- this.intentCache.clear();
174
- this.emit('cache_cleared');
175
- }
176
- /**
177
- * Get cache statistics
178
- */
179
- getCacheStats() {
180
- const now = Date.now();
181
- const validEntries = Array.from(this.intentCache.values()).filter(entry => now - entry.timestamp < this.config.cacheDuration);
182
- const oldestEntry = validEntries.length > 0
183
- ? new Date(Math.min(...validEntries.map(e => e.timestamp)))
184
- : null;
185
- return {
186
- size: validEntries.length,
187
- hitRate: this.intentCache.size > 0
188
- ? validEntries.length / this.intentCache.size
189
- : 0,
190
- oldestEntry,
191
- };
192
- }
193
- // Private methods
194
- initializePatterns() {
195
- const defaultPatterns = [
196
- {
197
- intent: 'analyze',
198
- patterns: [
199
- 'analyze {path?}',
200
- 'check {path?}',
201
- 'scan {path?}',
202
- 'examine {path?}',
203
- 'review {path?}',
204
- ],
205
- parameters: [
206
- { name: 'path', type: 'path', required: false, defaultValue: '.' },
207
- {
208
- name: 'focus',
209
- type: 'enum',
210
- required: false,
211
- enumValues: ['dependencies', 'quality', 'security', 'performance'],
212
- },
213
- {
214
- name: 'format',
215
- type: 'enum',
216
- required: false,
217
- enumValues: ['json', 'table', 'csv'],
218
- },
219
- ],
220
- examples: [
221
- 'analyze the project',
222
- 'check dependencies in src folder',
223
- 'scan for security issues',
224
- ],
225
- category: 'analysis',
226
- },
227
- {
228
- intent: 'create',
229
- patterns: [
230
- 'create {type} {name}',
231
- 'new {type} {name}',
232
- 'generate {type} {name}',
233
- 'make {type} {name}',
234
- ],
235
- parameters: [
236
- {
237
- name: 'type',
238
- type: 'enum',
239
- required: true,
240
- enumValues: ['component', 'service', 'test', 'config'],
241
- },
242
- { name: 'name', type: 'string', required: true },
243
- { name: 'template', type: 'string', required: false },
244
- ],
245
- examples: [
246
- 'create component UserProfile',
247
- 'new service AuthService',
248
- 'generate test for UserService',
249
- ],
250
- category: 'generation',
251
- },
252
- {
253
- intent: 'init',
254
- patterns: [
255
- 'init {project?}',
256
- 'initialize {project?}',
257
- 'setup {project?}',
258
- 'configure {project?}',
259
- ],
260
- parameters: [
261
- { name: 'project', type: 'string', required: false },
262
- { name: 'template', type: 'string', required: false },
263
- { name: 'force', type: 'boolean', required: false },
264
- ],
265
- examples: [
266
- 'init new project',
267
- 'initialize with React template',
268
- 'setup the workspace',
269
- ],
270
- category: 'setup',
271
- },
272
- {
273
- intent: 'help',
274
- patterns: [
275
- 'help {command?}',
276
- 'how {action?}',
277
- 'what {question?}',
278
- 'explain {topic?}',
279
- ],
280
- parameters: [
281
- { name: 'command', type: 'string', required: false },
282
- { name: 'topic', type: 'string', required: false },
283
- ],
284
- examples: [
285
- 'help with analyze command',
286
- 'how to create components',
287
- 'what does this do',
288
- ],
289
- category: 'help',
290
- },
291
- {
292
- intent: 'dashboard',
293
- patterns: [
294
- 'dashboard',
295
- 'ui',
296
- 'interface',
297
- 'show {view?}',
298
- 'open {view?}',
299
- ],
300
- parameters: [
301
- {
302
- name: 'view',
303
- type: 'enum',
304
- required: false,
305
- enumValues: ['overview', 'metrics', 'reports'],
306
- },
307
- { name: 'port', type: 'number', required: false, defaultValue: 3000 },
308
- ],
309
- examples: ['open dashboard', 'show metrics view', 'start ui'],
310
- category: 'interface',
311
- },
312
- ];
313
- defaultPatterns.forEach(pattern => this.registerCommandPattern(pattern));
314
- }
315
- initializeEntityRecognition() {
316
- this.entityPatterns.set('file_path', /(?:\.\/|\/|~\/)[^\s]+/g);
317
- this.entityPatterns.set('package_name', /(?:@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*/g);
318
- this.entityPatterns.set('command', /(?:wundr\s+)?(?:analyze|create|init|help|dashboard|batch|watch)\b/g);
319
- this.entityPatterns.set('option', /--?[a-zA-Z][a-zA-Z0-9-]*/g);
320
- this.entityPatterns.set('technology', /\b(?:react|angular|vue|nodejs|typescript|javascript|python|java|docker|kubernetes)\b/gi);
321
- }
322
- normalizeInput(input) {
323
- return input
324
- .trim()
325
- .toLowerCase()
326
- .replace(/[^\w\s\-\.\/]/g, ' ')
327
- .replace(/\s+/g, ' ');
328
- }
329
- getCacheKey(input, commands, context) {
330
- const contextKey = JSON.stringify({
331
- projectType: context.projectType,
332
- workingDirectory: context.workingDirectory,
333
- recentCommands: context.recentCommands?.slice(0, 3), // Only recent commands for cache key
334
- });
335
- return `${input}:${commands.sort().join(',')}:${contextKey}`;
336
- }
337
- async patternMatching(input, availableCommands) {
338
- let bestMatch = {
339
- intent: 'unknown',
340
- confidence: 0,
341
- context: { entities: [], keywords: [], sentiment: 'neutral' },
342
- };
343
- for (const [intent, pattern] of this.commandPatterns) {
344
- if (!availableCommands.includes(intent)) {
345
- continue;
346
- }
347
- const confidence = this.calculatePatternScore(input, pattern);
348
- if (confidence > bestMatch.confidence) {
349
- bestMatch = {
350
- intent,
351
- confidence,
352
- command: `wundr ${intent}`,
353
- parameters: {},
354
- reasoning: `Pattern match for "${intent}" command`,
355
- context: { entities: [], keywords: [], sentiment: 'neutral' },
356
- };
357
- }
358
- }
359
- return bestMatch;
360
- }
361
- calculatePatternScore(input, pattern) {
362
- let score = 0;
363
- let totalWeight = 0;
364
- // Check pattern matches
365
- for (const patternStr of pattern.patterns) {
366
- const patternWords = patternStr.toLowerCase().split(/\s+/);
367
- const inputWords = input.split(/\s+/);
368
- let matchCount = 0;
369
- for (const word of patternWords) {
370
- if (word.startsWith('{') && word.endsWith('}')) {
371
- continue;
372
- } // Skip parameters
373
- if (inputWords.includes(word)) {
374
- matchCount++;
375
- }
376
- }
377
- const patternScore = matchCount / patternWords.filter(w => !w.startsWith('{')).length;
378
- score = Math.max(score, patternScore);
379
- }
380
- totalWeight += 0.6;
381
- // Check examples
382
- let exampleScore = 0;
383
- for (const example of pattern.examples) {
384
- const similarity = this.calculateStringSimilarity(input, example.toLowerCase());
385
- exampleScore = Math.max(exampleScore, similarity);
386
- }
387
- score += exampleScore * 0.4;
388
- totalWeight += 0.4;
389
- return score / totalWeight;
390
- }
391
- calculateStringSimilarity(str1, str2) {
392
- const words1 = str1.split(/\s+/);
393
- const words2 = str2.split(/\s+/);
394
- let matches = 0;
395
- for (const word1 of words1) {
396
- if (words2.includes(word1)) {
397
- matches++;
398
- }
399
- }
400
- return matches / Math.max(words1.length, words2.length);
401
- }
402
- async extractEntities(input) {
403
- const entities = [];
404
- for (const [type, pattern] of this.entityPatterns) {
405
- const matches = Array.from(input.matchAll(pattern));
406
- for (const match of matches) {
407
- if (match.index !== undefined) {
408
- entities.push({
409
- text: match[0],
410
- type: type,
411
- confidence: 0.8, // Static confidence for regex patterns
412
- startIndex: match.index,
413
- endIndex: match.index + match[0].length,
414
- });
415
- }
416
- }
417
- }
418
- return entities;
419
- }
420
- async aiIntentAnalysis(input, availableCommands, context, entities) {
421
- const contextInfo = this.buildContextInfo(context);
422
- const entityInfo = entities.length > 0
423
- ? `\nDetected entities: ${entities.map(e => `${e.text} (${e.type})`).join(', ')}`
424
- : '';
425
- const systemPrompt = `You are an expert CLI intent analyzer. Analyze user input and map it to appropriate commands.
426
-
427
- Available commands: ${availableCommands.join(', ')}
428
- ${contextInfo}${entityInfo}
429
-
430
- User input: "${input}"
431
-
432
- Analyze and respond with JSON only:
433
- {
434
- "intent": "command_name",
435
- "confidence": 0.95,
436
- "command": "wundr analyze --path ./src",
437
- "parameters": {"path": "./src"},
438
- "alternatives": [
439
- {"command": "wundr scan", "confidence": 0.7, "description": "Alternative interpretation"}
440
- ],
441
- "reasoning": "User wants to analyze source code based on path mention",
442
- "clarification": null
443
- }`;
444
- try {
445
- const response = await this.claudeClient.sendMessage(input, systemPrompt, {
446
- temperature: 0.1,
447
- maxTokens: 1536,
448
- });
449
- const cleanResponse = response.trim();
450
- const jsonMatch = cleanResponse.match(/\{[\s\S]*\}/);
451
- if (!jsonMatch) {
452
- throw new Error('No valid JSON in AI response');
453
- }
454
- const result = JSON.parse(jsonMatch[0]);
455
- // Add context information
456
- result.context = {
457
- entities,
458
- keywords: this.extractKeywords(input),
459
- sentiment: this.analyzeSentiment(input),
460
- };
461
- return result;
462
- }
463
- catch (error) {
464
- logger_1.logger.error('AI intent analysis failed:', error);
465
- throw error;
466
- }
467
- }
468
- buildContextInfo(context) {
469
- const parts = [];
470
- if (context.projectType) {
471
- parts.push(`Project type: ${context.projectType}`);
472
- }
473
- if (context.recentCommands?.length) {
474
- parts.push(`Recent commands: ${context.recentCommands.slice(0, 3).join(', ')}`);
475
- }
476
- if (context.workingDirectory) {
477
- parts.push(`Working directory: ${context.workingDirectory}`);
478
- }
479
- return parts.length > 0 ? `\nContext: ${parts.join(', ')}` : '';
480
- }
481
- combineResults(patternResult, aiResult, entities) {
482
- // Use AI result as base, but boost confidence if pattern matching agrees
483
- let finalResult = { ...aiResult };
484
- if (patternResult.intent === aiResult.intent) {
485
- finalResult.confidence = Math.min(0.98, aiResult.confidence + 0.1);
486
- finalResult.reasoning += ' (confirmed by pattern matching)';
487
- }
488
- else if (patternResult.confidence > 0.8) {
489
- // High-confidence pattern match might override AI
490
- if (patternResult.confidence > aiResult.confidence) {
491
- finalResult = patternResult;
492
- finalResult.reasoning += ' (overridden by high-confidence pattern match)';
493
- }
494
- }
495
- // Ensure entities are included
496
- if (finalResult.context) {
497
- finalResult.context.entities = entities;
498
- }
499
- return finalResult;
500
- }
501
- async validateAndEnrich(result, availableCommands, context) {
502
- // Validate that the intent command is available
503
- if (!availableCommands.includes(result.intent)) {
504
- logger_1.logger.warn(`Intent "${result.intent}" not in available commands`);
505
- result.confidence *= 0.5;
506
- result.clarification = `The command "${result.intent}" is not available. Did you mean one of: ${availableCommands.join(', ')}?`;
507
- }
508
- // Add safety warnings for destructive commands
509
- const commandPattern = this.commandPatterns.get(result.intent);
510
- if (commandPattern?.destructive) {
511
- result.clarification = 'This is a destructive operation. Are you sure you want to proceed?';
512
- }
513
- // Enrich with context-aware suggestions
514
- if (result.confidence < this.config.confidenceThreshold) {
515
- result.alternatives = await this.getContextualAlternatives(result, availableCommands, context);
516
- }
517
- return result;
518
- }
519
- async getContextualAlternatives(result, availableCommands, context) {
520
- const alternatives = [];
521
- // Add pattern-based alternatives
522
- for (const command of availableCommands) {
523
- if (command !== result.intent) {
524
- const pattern = this.commandPatterns.get(command);
525
- if (pattern) {
526
- const confidence = this.calculatePatternScore(result.command || '', pattern);
527
- if (confidence > 0.3) {
528
- alternatives.push({
529
- command: `wundr ${command}`,
530
- confidence,
531
- description: `Alternative: ${pattern.examples[0] || command}`,
532
- });
533
- }
534
- }
535
- }
536
- }
537
- // Sort and limit alternatives
538
- alternatives.sort((a, b) => b.confidence - a.confidence);
539
- return alternatives.slice(0, this.config.maxAlternatives);
540
- }
541
- fallbackIntentParsing(input, availableCommands, context) {
542
- // Simple keyword matching as last resort
543
- const keywords = input.split(/\s+/);
544
- const bestMatch = 'help';
545
- const bestScore = 0;
546
- for (const command of availableCommands) {
547
- if (keywords.includes(command)) {
548
- return {
549
- intent: command,
550
- confidence: 0.6,
551
- command: `wundr ${command}`,
552
- parameters: {},
553
- reasoning: 'Fallback keyword matching',
554
- context: { entities: [], keywords, sentiment: 'neutral' },
555
- };
556
- }
557
- }
558
- return {
559
- intent: bestMatch,
560
- confidence: 0.3,
561
- command: `wundr ${bestMatch}`,
562
- parameters: {},
563
- clarification: `I couldn't understand "${input}". Type "help" to see available commands.`,
564
- reasoning: 'Fallback to help command',
565
- context: { entities: [], keywords, sentiment: 'neutral' },
566
- };
567
- }
568
- fallbackParameterExtraction(input, pattern) {
569
- const parameters = {};
570
- const words = input.split(/\s+/);
571
- // Simple heuristic parameter extraction
572
- for (const param of pattern.parameters) {
573
- if (param.type === 'path') {
574
- const pathMatch = input.match(/(?:\.\/|\/|~\/)[^\s]+/);
575
- if (pathMatch) {
576
- parameters[param.name] = pathMatch[0];
577
- }
578
- }
579
- else if (param.type === 'boolean') {
580
- if (words.some(word => ['yes', 'true', 'on', 'enable'].includes(word.toLowerCase()))) {
581
- parameters[param.name] = true;
582
- }
583
- else if (words.some(word => ['no', 'false', 'off', 'disable'].includes(word.toLowerCase()))) {
584
- parameters[param.name] = false;
585
- }
586
- }
587
- // Apply default values
588
- if (!parameters[param.name] && param.defaultValue !== undefined) {
589
- parameters[param.name] = param.defaultValue;
590
- }
591
- }
592
- return parameters;
593
- }
594
- getPatternSuggestions(partialInput, availableCommands) {
595
- const suggestions = [];
596
- for (const command of availableCommands) {
597
- const pattern = this.commandPatterns.get(command);
598
- if (!pattern) {
599
- continue;
600
- }
601
- // Check if partial input matches command or examples
602
- const confidence = Math.max(this.calculateStringSimilarity(partialInput, command), ...pattern.examples.map(ex => this.calculateStringSimilarity(partialInput, ex)));
603
- if (confidence > 0.3) {
604
- suggestions.push({
605
- command: `wundr ${command}`,
606
- description: pattern.examples[0] || `Run ${command} command`,
607
- confidence,
608
- completion: pattern.examples[0] || `wundr ${command}`,
609
- });
610
- }
611
- }
612
- return suggestions;
613
- }
614
- async getAISuggestions(partialInput, availableCommands, context, limit) {
615
- const systemPrompt = `You are a CLI auto-completion assistant. Based on partial user input, suggest the most likely command completions.
616
-
617
- Available commands: ${availableCommands.join(', ')}
618
- Partial input: "${partialInput}"
619
-
620
- Provide ${limit} suggestions in JSON format:
621
- {
622
- "suggestions": [
623
- {
624
- "command": "wundr analyze",
625
- "description": "Analyze the project for issues",
626
- "confidence": 0.9,
627
- "completion": "wundr analyze --path ."
628
- }
629
- ]
630
- }`;
631
- try {
632
- const response = await this.claudeClient.sendMessage('', systemPrompt, {
633
- temperature: 0.3,
634
- maxTokens: 1024,
635
- });
636
- const result = JSON.parse(response.trim());
637
- return result.suggestions || [];
638
- }
639
- catch (error) {
640
- logger_1.logger.error('AI suggestions failed:', error);
641
- return [];
642
- }
643
- }
644
- extractKeywords(input) {
645
- // Simple keyword extraction
646
- const stopWords = [
647
- 'the',
648
- 'and',
649
- 'or',
650
- 'but',
651
- 'in',
652
- 'on',
653
- 'at',
654
- 'to',
655
- 'for',
656
- 'of',
657
- 'with',
658
- 'by',
659
- 'is',
660
- 'are',
661
- 'was',
662
- 'were',
663
- 'be',
664
- 'been',
665
- 'have',
666
- 'has',
667
- 'had',
668
- 'do',
669
- 'does',
670
- 'did',
671
- 'will',
672
- 'would',
673
- 'could',
674
- 'should',
675
- ];
676
- return input
677
- .toLowerCase()
678
- .split(/\s+/)
679
- .filter(word => word.length > 2 && !stopWords.includes(word))
680
- .slice(0, 10); // Limit to 10 keywords
681
- }
682
- analyzeSentiment(input) {
683
- const positiveWords = [
684
- 'good',
685
- 'great',
686
- 'excellent',
687
- 'awesome',
688
- 'perfect',
689
- 'love',
690
- 'like',
691
- 'thanks',
692
- 'help',
693
- 'please',
694
- ];
695
- const negativeWords = [
696
- 'bad',
697
- 'terrible',
698
- 'awful',
699
- 'hate',
700
- 'problem',
701
- 'error',
702
- 'issue',
703
- 'broken',
704
- 'fail',
705
- 'wrong',
706
- ];
707
- const words = input.toLowerCase().split(/\s+/);
708
- const positiveCount = words.filter(word => positiveWords.includes(word)).length;
709
- const negativeCount = words.filter(word => negativeWords.includes(word)).length;
710
- if (positiveCount > negativeCount) {
711
- return 'positive';
712
- }
713
- if (negativeCount > positiveCount) {
714
- return 'negative';
715
- }
716
- return 'neutral';
717
- }
718
- cacheResult(key, result) {
719
- this.intentCache.set(key, {
720
- result,
721
- timestamp: Date.now(),
722
- });
723
- // Clean old entries periodically
724
- if (this.intentCache.size % 100 === 0) {
725
- this.cleanCache();
726
- }
727
- }
728
- cleanCache() {
729
- const now = Date.now();
730
- const expiredKeys = [];
731
- for (const [key, entry] of this.intentCache) {
732
- if (now - entry.timestamp > this.config.cacheDuration) {
733
- expiredKeys.push(key);
734
- }
735
- }
736
- expiredKeys.forEach(key => this.intentCache.delete(key));
737
- if (expiredKeys.length > 0) {
738
- logger_1.logger.debug(`Cleaned ${expiredKeys.length} expired cache entries`);
739
- }
740
- }
741
- }
742
- exports.IntentParser = IntentParser;
743
- exports.default = IntentParser;
744
- //# sourceMappingURL=intent-parser.js.map