nexusforge-cli 1.1.1 → 1.2.1
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.
- package/dist/components/App.d.ts.map +1 -1
- package/dist/components/App.js +183 -17
- package/dist/components/App.js.map +1 -1
- package/dist/index.js +462 -10
- package/dist/index.js.map +1 -1
- package/dist/modules/commandEngine.d.ts +70 -0
- package/dist/modules/commandEngine.d.ts.map +1 -0
- package/dist/modules/commandEngine.js +672 -0
- package/dist/modules/commandEngine.js.map +1 -0
- package/dist/modules/contextBuilder.d.ts +51 -0
- package/dist/modules/contextBuilder.d.ts.map +1 -0
- package/dist/modules/contextBuilder.js +725 -0
- package/dist/modules/contextBuilder.js.map +1 -0
- package/dist/modules/domainDetector.d.ts +64 -0
- package/dist/modules/domainDetector.d.ts.map +1 -0
- package/dist/modules/domainDetector.js +722 -0
- package/dist/modules/domainDetector.js.map +1 -0
- package/dist/modules/fileOperations.d.ts +99 -0
- package/dist/modules/fileOperations.d.ts.map +1 -0
- package/dist/modules/fileOperations.js +543 -0
- package/dist/modules/fileOperations.js.map +1 -0
- package/dist/modules/forgeEngine.d.ts +153 -0
- package/dist/modules/forgeEngine.d.ts.map +1 -0
- package/dist/modules/forgeEngine.js +652 -0
- package/dist/modules/forgeEngine.js.map +1 -0
- package/dist/modules/gitManager.d.ts +151 -0
- package/dist/modules/gitManager.d.ts.map +1 -0
- package/dist/modules/gitManager.js +539 -0
- package/dist/modules/gitManager.js.map +1 -0
- package/dist/modules/index.d.ts +25 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/dist/modules/index.js +25 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/prdProcessor.d.ts +125 -0
- package/dist/modules/prdProcessor.d.ts.map +1 -0
- package/dist/modules/prdProcessor.js +466 -0
- package/dist/modules/prdProcessor.js.map +1 -0
- package/dist/modules/projectScanner.d.ts +105 -0
- package/dist/modules/projectScanner.d.ts.map +1 -0
- package/dist/modules/projectScanner.js +859 -0
- package/dist/modules/projectScanner.js.map +1 -0
- package/dist/modules/safetyGuard.d.ts +83 -0
- package/dist/modules/safetyGuard.d.ts.map +1 -0
- package/dist/modules/safetyGuard.js +492 -0
- package/dist/modules/safetyGuard.js.map +1 -0
- package/dist/modules/templateManager.d.ts +78 -0
- package/dist/modules/templateManager.d.ts.map +1 -0
- package/dist/modules/templateManager.js +556 -0
- package/dist/modules/templateManager.js.map +1 -0
- package/dist/native/index.d.ts +125 -0
- package/dist/native/index.d.ts.map +1 -0
- package/dist/native/index.js +164 -0
- package/dist/native/index.js.map +1 -0
- package/dist/services/executor.d.ts +24 -0
- package/dist/services/executor.d.ts.map +1 -1
- package/dist/services/executor.js +149 -6
- package/dist/services/executor.js.map +1 -1
- package/dist/services/fileManager.d.ts +134 -0
- package/dist/services/fileManager.d.ts.map +1 -0
- package/dist/services/fileManager.js +489 -0
- package/dist/services/fileManager.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,672 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NexusForge Command Processing Engine
|
|
3
|
+
* Natural language command parsing and routing
|
|
4
|
+
* Ported from Python: nexusforge/modules/architecture/command_engine.py
|
|
5
|
+
*/
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// ENUMS AND TYPES
|
|
8
|
+
// ============================================================================
|
|
9
|
+
export var CommandIntent;
|
|
10
|
+
(function (CommandIntent) {
|
|
11
|
+
CommandIntent["CREATE_FILE"] = "create_file";
|
|
12
|
+
CommandIntent["MODIFY_FILE"] = "modify_file";
|
|
13
|
+
CommandIntent["DELETE_FILE"] = "delete_file";
|
|
14
|
+
CommandIntent["EXECUTE_COMMAND"] = "execute_command";
|
|
15
|
+
CommandIntent["ANALYZE_CODE"] = "analyze_code";
|
|
16
|
+
CommandIntent["REFACTOR"] = "refactor";
|
|
17
|
+
CommandIntent["SEARCH"] = "search";
|
|
18
|
+
CommandIntent["BUILD"] = "build";
|
|
19
|
+
CommandIntent["TEST"] = "test";
|
|
20
|
+
CommandIntent["DEPLOY"] = "deploy";
|
|
21
|
+
CommandIntent["EXPLAIN"] = "explain";
|
|
22
|
+
CommandIntent["DEBUG"] = "debug";
|
|
23
|
+
CommandIntent["INSTALL"] = "install";
|
|
24
|
+
CommandIntent["CONFIGURE"] = "configure";
|
|
25
|
+
CommandIntent["CREATE_FEATURE"] = "create_feature";
|
|
26
|
+
CommandIntent["CREATE_SERVICE"] = "create_service";
|
|
27
|
+
CommandIntent["CREATE_COMPONENT"] = "create_component";
|
|
28
|
+
CommandIntent["REVIEW"] = "review";
|
|
29
|
+
CommandIntent["OPTIMIZE"] = "optimize";
|
|
30
|
+
CommandIntent["DOCUMENT"] = "document";
|
|
31
|
+
CommandIntent["GIT_OPERATION"] = "git_operation";
|
|
32
|
+
CommandIntent["READ_FILE"] = "read_file";
|
|
33
|
+
CommandIntent["LIST_FILES"] = "list_files";
|
|
34
|
+
CommandIntent["HELP"] = "help";
|
|
35
|
+
CommandIntent["UNKNOWN"] = "unknown";
|
|
36
|
+
})(CommandIntent || (CommandIntent = {}));
|
|
37
|
+
// ============================================================================
|
|
38
|
+
// CONTEXT REQUIREMENTS MAPPING
|
|
39
|
+
// ============================================================================
|
|
40
|
+
const CONTEXT_REQUIREMENTS = {
|
|
41
|
+
[CommandIntent.CREATE_FILE]: ['project_structure', 'patterns'],
|
|
42
|
+
[CommandIntent.MODIFY_FILE]: ['file_content', 'file_history', 'dependencies'],
|
|
43
|
+
[CommandIntent.DELETE_FILE]: ['file_content', 'dependencies'],
|
|
44
|
+
[CommandIntent.EXECUTE_COMMAND]: ['project_type', 'available_scripts'],
|
|
45
|
+
[CommandIntent.ANALYZE_CODE]: ['file_content', 'code_quality', 'dependencies'],
|
|
46
|
+
[CommandIntent.REFACTOR]: ['file_content', 'file_history', 'dependencies', 'code_quality'],
|
|
47
|
+
[CommandIntent.SEARCH]: ['project_structure'],
|
|
48
|
+
[CommandIntent.BUILD]: ['build_config', 'dependencies', 'project_type'],
|
|
49
|
+
[CommandIntent.TEST]: ['test_framework', 'test_files', 'coverage'],
|
|
50
|
+
[CommandIntent.DEPLOY]: ['deployment_config', 'environment'],
|
|
51
|
+
[CommandIntent.EXPLAIN]: ['relevant_code', 'documentation', 'usage_examples'],
|
|
52
|
+
[CommandIntent.DEBUG]: ['error_logs', 'stack_traces', 'recent_changes'],
|
|
53
|
+
[CommandIntent.INSTALL]: ['package_manager', 'dependencies'],
|
|
54
|
+
[CommandIntent.CONFIGURE]: ['config_files', 'environment'],
|
|
55
|
+
[CommandIntent.CREATE_FEATURE]: ['project_structure', 'architecture', 'patterns'],
|
|
56
|
+
[CommandIntent.CREATE_SERVICE]: ['project_structure', 'architecture', 'dependencies'],
|
|
57
|
+
[CommandIntent.CREATE_COMPONENT]: ['project_structure', 'ui_framework', 'patterns'],
|
|
58
|
+
[CommandIntent.REVIEW]: ['code_quality', 'best_practices', 'security'],
|
|
59
|
+
[CommandIntent.OPTIMIZE]: ['performance_metrics', 'profiling_data'],
|
|
60
|
+
[CommandIntent.DOCUMENT]: ['code_structure', 'existing_docs'],
|
|
61
|
+
[CommandIntent.GIT_OPERATION]: ['git_status', 'git_history'],
|
|
62
|
+
[CommandIntent.READ_FILE]: ['file_content'],
|
|
63
|
+
[CommandIntent.LIST_FILES]: ['directory_structure'],
|
|
64
|
+
[CommandIntent.HELP]: [],
|
|
65
|
+
[CommandIntent.UNKNOWN]: ['general'],
|
|
66
|
+
};
|
|
67
|
+
// ============================================================================
|
|
68
|
+
// COMMAND PROCESSING ENGINE
|
|
69
|
+
// ============================================================================
|
|
70
|
+
export class CommandProcessingEngine {
|
|
71
|
+
patterns;
|
|
72
|
+
handlers;
|
|
73
|
+
commandHistory;
|
|
74
|
+
maxHistory;
|
|
75
|
+
constructor() {
|
|
76
|
+
this.patterns = this.initializePatterns();
|
|
77
|
+
this.handlers = new Map();
|
|
78
|
+
this.commandHistory = [];
|
|
79
|
+
this.maxHistory = 100;
|
|
80
|
+
}
|
|
81
|
+
initializePatterns() {
|
|
82
|
+
const patterns = [
|
|
83
|
+
// ============================================================
|
|
84
|
+
// FILE CREATION PATTERNS (Priority: 10)
|
|
85
|
+
// ============================================================
|
|
86
|
+
{
|
|
87
|
+
pattern: /(?:create|make|new|add)\s+(?:a\s+)?(?:new\s+)?(?:file\s+)?(?:called\s+|named\s+)?['"]?(\w+\.\w+)['"]?/i,
|
|
88
|
+
intent: CommandIntent.CREATE_FILE,
|
|
89
|
+
extractor: (m) => ({ filename: m[1] }),
|
|
90
|
+
priority: 10,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
pattern: /(?:create|make|add)\s+(?:a\s+)?(\w+\.\w+)(?:\s+file)?/i,
|
|
94
|
+
intent: CommandIntent.CREATE_FILE,
|
|
95
|
+
extractor: (m) => ({ filename: m[1] }),
|
|
96
|
+
priority: 9,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
pattern: /(?:create|make|add)\s+(?:a\s+)?(.+?)\s+(?:in|at)\s+(.+)/i,
|
|
100
|
+
intent: CommandIntent.CREATE_FILE,
|
|
101
|
+
extractor: (m) => ({ type: m[1], location: m[2] }),
|
|
102
|
+
priority: 8,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
pattern: /(?:new|add)\s+(?:file|class|component|module)\s+(.+)/i,
|
|
106
|
+
intent: CommandIntent.CREATE_FILE,
|
|
107
|
+
extractor: (m) => ({ name: m[1].trim() }),
|
|
108
|
+
priority: 8,
|
|
109
|
+
},
|
|
110
|
+
// ============================================================
|
|
111
|
+
// FILE MODIFICATION PATTERNS (Priority: 10)
|
|
112
|
+
// ============================================================
|
|
113
|
+
{
|
|
114
|
+
pattern: /(?:modify|edit|update|change|fix)\s+(.+?)\s+(?:to|with)\s+(.+)/i,
|
|
115
|
+
intent: CommandIntent.MODIFY_FILE,
|
|
116
|
+
extractor: (m) => ({ target: m[1], changes: m[2] }),
|
|
117
|
+
priority: 10,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
pattern: /(?:fix|repair|correct)\s+(?:the\s+)?(.+?)\s+in\s+(\S+\.\w+)/i,
|
|
121
|
+
intent: CommandIntent.MODIFY_FILE,
|
|
122
|
+
extractor: (m) => ({ changes: m[1], target: m[2] }),
|
|
123
|
+
priority: 10,
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
pattern: /(?:modify|edit|update|change|fix)\s+(\S+\.\w+)/i,
|
|
127
|
+
intent: CommandIntent.MODIFY_FILE,
|
|
128
|
+
extractor: (m) => ({ target: m[1] }),
|
|
129
|
+
priority: 9,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
pattern: /(?:add|insert)\s+(.+?)\s+(?:to|into)\s+(.+)/i,
|
|
133
|
+
intent: CommandIntent.MODIFY_FILE,
|
|
134
|
+
extractor: (m) => ({ content: m[1], target: m[2] }),
|
|
135
|
+
priority: 9,
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
pattern: /(?:remove|delete)\s+(.+?)\s+from\s+(.+)/i,
|
|
139
|
+
intent: CommandIntent.MODIFY_FILE,
|
|
140
|
+
extractor: (m) => ({ contentToRemove: m[1], target: m[2] }),
|
|
141
|
+
priority: 9,
|
|
142
|
+
},
|
|
143
|
+
// ============================================================
|
|
144
|
+
// READ FILE PATTERNS (Priority: 10)
|
|
145
|
+
// ============================================================
|
|
146
|
+
{
|
|
147
|
+
pattern: /(?:read|show|display|cat|view)\s+(?:file\s+)?['"]?([^\s'"]+\.\w+)['"]?/i,
|
|
148
|
+
intent: CommandIntent.READ_FILE,
|
|
149
|
+
extractor: (m) => ({ filename: m[1] }),
|
|
150
|
+
priority: 10,
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
pattern: /(?:what'?s?\s+in|contents?\s+of)\s+['"]?([^\s'"]+\.\w+)['"]?/i,
|
|
154
|
+
intent: CommandIntent.READ_FILE,
|
|
155
|
+
extractor: (m) => ({ filename: m[1] }),
|
|
156
|
+
priority: 9,
|
|
157
|
+
},
|
|
158
|
+
// ============================================================
|
|
159
|
+
// DELETE PATTERNS (Priority: 10)
|
|
160
|
+
// ============================================================
|
|
161
|
+
{
|
|
162
|
+
pattern: /(?:delete|remove)\s+(?:file|directory)?\s*(\S+)/i,
|
|
163
|
+
intent: CommandIntent.DELETE_FILE,
|
|
164
|
+
extractor: (m) => ({ target: m[1] }),
|
|
165
|
+
priority: 10,
|
|
166
|
+
},
|
|
167
|
+
// ============================================================
|
|
168
|
+
// SEARCH PATTERNS (Priority: 9)
|
|
169
|
+
// ============================================================
|
|
170
|
+
{
|
|
171
|
+
pattern: /(?:find|search|look for|locate)\s+(.+?)\s+(?:in|within)\s+(.+)/i,
|
|
172
|
+
intent: CommandIntent.SEARCH,
|
|
173
|
+
extractor: (m) => ({ query: m[1], scope: m[2] }),
|
|
174
|
+
priority: 9,
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
pattern: /(?:find|search)\s+(?:all\s+)?(.+)/i,
|
|
178
|
+
intent: CommandIntent.SEARCH,
|
|
179
|
+
extractor: (m) => ({ query: m[1], scope: 'project' }),
|
|
180
|
+
priority: 8,
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
pattern: /(?:where is|show me)\s+(.+)/i,
|
|
184
|
+
intent: CommandIntent.SEARCH,
|
|
185
|
+
extractor: (m) => ({ query: m[1], scope: 'project' }),
|
|
186
|
+
priority: 8,
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
pattern: /(?:grep|rg)\s+['"]?(.+?)['"]?\s*(?:in\s+)?(.+)?/i,
|
|
190
|
+
intent: CommandIntent.SEARCH,
|
|
191
|
+
extractor: (m) => ({ query: m[1], scope: m[2] || 'project' }),
|
|
192
|
+
priority: 9,
|
|
193
|
+
},
|
|
194
|
+
// ============================================================
|
|
195
|
+
// LIST FILES PATTERNS (Priority: 9)
|
|
196
|
+
// ============================================================
|
|
197
|
+
{
|
|
198
|
+
pattern: /(?:list|ls|show)\s+(?:all\s+)?(?:files|directory|folder|dir)(?:\s+in\s+(.+))?/i,
|
|
199
|
+
intent: CommandIntent.LIST_FILES,
|
|
200
|
+
extractor: (m) => ({ directory: m[1] || '.' }),
|
|
201
|
+
priority: 9,
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
pattern: /(?:what\s+files|show\s+files)(?:\s+(?:are\s+)?in\s+(.+))?/i,
|
|
205
|
+
intent: CommandIntent.LIST_FILES,
|
|
206
|
+
extractor: (m) => ({ directory: m[1] || '.' }),
|
|
207
|
+
priority: 8,
|
|
208
|
+
},
|
|
209
|
+
// ============================================================
|
|
210
|
+
// BUILD/COMPILE PATTERNS (Priority: 8)
|
|
211
|
+
// ============================================================
|
|
212
|
+
{
|
|
213
|
+
pattern: /(?:build|compile|make)\s+(?:the\s+)?(.+)?/i,
|
|
214
|
+
intent: CommandIntent.BUILD,
|
|
215
|
+
extractor: (m) => ({ target: m[1] || 'project' }),
|
|
216
|
+
priority: 8,
|
|
217
|
+
},
|
|
218
|
+
// ============================================================
|
|
219
|
+
// TEST PATTERNS (Priority: 8)
|
|
220
|
+
// ============================================================
|
|
221
|
+
{
|
|
222
|
+
pattern: /(?:test|run tests?)\s+(?:for\s+)?(.+)?/i,
|
|
223
|
+
intent: CommandIntent.TEST,
|
|
224
|
+
extractor: (m) => ({ target: m[1] || 'all' }),
|
|
225
|
+
priority: 8,
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
pattern: /(?:run|execute)\s+(?:all\s+)?tests?/i,
|
|
229
|
+
intent: CommandIntent.TEST,
|
|
230
|
+
extractor: () => ({ target: 'all' }),
|
|
231
|
+
priority: 8,
|
|
232
|
+
},
|
|
233
|
+
// ============================================================
|
|
234
|
+
// GIT PATTERNS (Priority: 10)
|
|
235
|
+
// ============================================================
|
|
236
|
+
{
|
|
237
|
+
pattern: /(?:git\s+)?(commit|push|pull|status|diff|log|branch|checkout|merge|stash|add)\s*(.*)?/i,
|
|
238
|
+
intent: CommandIntent.GIT_OPERATION,
|
|
239
|
+
extractor: (m) => ({ operation: m[1].toLowerCase(), args: m[2]?.trim() }),
|
|
240
|
+
priority: 10,
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
pattern: /(?:show|get)\s+(?:git\s+)?(?:status|diff|log|branches)/i,
|
|
244
|
+
intent: CommandIntent.GIT_OPERATION,
|
|
245
|
+
extractor: (m) => ({ operation: 'status' }),
|
|
246
|
+
priority: 9,
|
|
247
|
+
},
|
|
248
|
+
// ============================================================
|
|
249
|
+
// EXECUTION PATTERNS (Priority: 7)
|
|
250
|
+
// ============================================================
|
|
251
|
+
{
|
|
252
|
+
pattern: /(?:run|execute|exec)\s+(.+)/i,
|
|
253
|
+
intent: CommandIntent.EXECUTE_COMMAND,
|
|
254
|
+
extractor: (m) => ({ command: m[1] }),
|
|
255
|
+
priority: 7,
|
|
256
|
+
},
|
|
257
|
+
// ============================================================
|
|
258
|
+
// INSTALLATION PATTERNS (Priority: 9)
|
|
259
|
+
// ============================================================
|
|
260
|
+
{
|
|
261
|
+
pattern: /(?:install|add)\s+(?:package|dependency|dep|library)?\s*(.+)/i,
|
|
262
|
+
intent: CommandIntent.INSTALL,
|
|
263
|
+
extractor: (m) => ({ packages: m[1].trim().split(/\s+/) }),
|
|
264
|
+
priority: 9,
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
pattern: /npm\s+(?:install|i)\s+(.+)/i,
|
|
268
|
+
intent: CommandIntent.INSTALL,
|
|
269
|
+
extractor: (m) => ({ packages: m[1].trim().split(/\s+/), manager: 'npm' }),
|
|
270
|
+
priority: 10,
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
pattern: /pip\s+install\s+(.+)/i,
|
|
274
|
+
intent: CommandIntent.INSTALL,
|
|
275
|
+
extractor: (m) => ({ packages: m[1].trim().split(/\s+/), manager: 'pip' }),
|
|
276
|
+
priority: 10,
|
|
277
|
+
},
|
|
278
|
+
// ============================================================
|
|
279
|
+
// DEBUG PATTERNS (Priority: 9)
|
|
280
|
+
// ============================================================
|
|
281
|
+
{
|
|
282
|
+
pattern: /(?:debug|fix|solve|troubleshoot)\s+(.+)/i,
|
|
283
|
+
intent: CommandIntent.DEBUG,
|
|
284
|
+
extractor: (m) => ({ issue: m[1] }),
|
|
285
|
+
priority: 9,
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
pattern: /why\s+(?:is|does|isn't|doesn't)\s+(.+)/i,
|
|
289
|
+
intent: CommandIntent.DEBUG,
|
|
290
|
+
extractor: (m) => ({ issue: m[1] }),
|
|
291
|
+
priority: 8,
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
pattern: /(?:what'?s?\s+wrong|error|bug)\s+(?:with\s+)?(.+)?/i,
|
|
295
|
+
intent: CommandIntent.DEBUG,
|
|
296
|
+
extractor: (m) => ({ issue: m[1] || 'unknown' }),
|
|
297
|
+
priority: 8,
|
|
298
|
+
},
|
|
299
|
+
// ============================================================
|
|
300
|
+
// EXPLANATION PATTERNS (Priority: 8)
|
|
301
|
+
// ============================================================
|
|
302
|
+
{
|
|
303
|
+
pattern: /(?:explain|what is|what does|how does)\s+(.+?)(?:\s+work|\s+do)?/i,
|
|
304
|
+
intent: CommandIntent.EXPLAIN,
|
|
305
|
+
extractor: (m) => ({ topic: m[1] }),
|
|
306
|
+
priority: 8,
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
pattern: /(?:tell me about|describe)\s+(.+)/i,
|
|
310
|
+
intent: CommandIntent.EXPLAIN,
|
|
311
|
+
extractor: (m) => ({ topic: m[1] }),
|
|
312
|
+
priority: 7,
|
|
313
|
+
},
|
|
314
|
+
// ============================================================
|
|
315
|
+
// REFACTORING PATTERNS (Priority: 9)
|
|
316
|
+
// ============================================================
|
|
317
|
+
{
|
|
318
|
+
pattern: /(?:refactor|improve|optimize|clean up)\s+(.+)/i,
|
|
319
|
+
intent: CommandIntent.REFACTOR,
|
|
320
|
+
extractor: (m) => ({ target: m[1] }),
|
|
321
|
+
priority: 9,
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
pattern: /(?:make|improve)\s+(.+?)\s+(?:better|cleaner|faster)/i,
|
|
325
|
+
intent: CommandIntent.REFACTOR,
|
|
326
|
+
extractor: (m) => ({ target: m[1] }),
|
|
327
|
+
priority: 8,
|
|
328
|
+
},
|
|
329
|
+
// ============================================================
|
|
330
|
+
// FEATURE CREATION PATTERNS (Priority: 10)
|
|
331
|
+
// ============================================================
|
|
332
|
+
{
|
|
333
|
+
pattern: /(?:create|add|implement)\s+(?:a\s+)?(?:new\s+)?(?:feature|functionality)\s+(?:for\s+|called\s+|named\s+)?(.+)/i,
|
|
334
|
+
intent: CommandIntent.CREATE_FEATURE,
|
|
335
|
+
extractor: (m) => ({ featureName: m[1] }),
|
|
336
|
+
priority: 10,
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
pattern: /(?:add|create|implement)\s+(.+?)\s+(?:monitoring|control|management|system)/i,
|
|
340
|
+
intent: CommandIntent.CREATE_FEATURE,
|
|
341
|
+
extractor: (m) => ({ featureName: `${m[1]}_system` }),
|
|
342
|
+
priority: 10,
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
pattern: /(?:implement|build)\s+(.+?)\s+feature/i,
|
|
346
|
+
intent: CommandIntent.CREATE_FEATURE,
|
|
347
|
+
extractor: (m) => ({ featureName: m[1] }),
|
|
348
|
+
priority: 9,
|
|
349
|
+
},
|
|
350
|
+
// ============================================================
|
|
351
|
+
// SERVICE CREATION PATTERNS (Priority: 10)
|
|
352
|
+
// ============================================================
|
|
353
|
+
{
|
|
354
|
+
pattern: /(?:create|add|implement)\s+(?:a\s+)?(?:new\s+)?service\s+(?:for\s+|called\s+)?(.+)/i,
|
|
355
|
+
intent: CommandIntent.CREATE_SERVICE,
|
|
356
|
+
extractor: (m) => ({ serviceName: m[1] }),
|
|
357
|
+
priority: 10,
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
pattern: /(?:build|setup)\s+(.+?)\s+service/i,
|
|
361
|
+
intent: CommandIntent.CREATE_SERVICE,
|
|
362
|
+
extractor: (m) => ({ serviceName: m[1] }),
|
|
363
|
+
priority: 9,
|
|
364
|
+
},
|
|
365
|
+
// ============================================================
|
|
366
|
+
// COMPONENT CREATION PATTERNS (Priority: 10)
|
|
367
|
+
// ============================================================
|
|
368
|
+
{
|
|
369
|
+
pattern: /(?:create|add|implement)\s+(?:a\s+)?(?:new\s+)?(?:component|ui|page|dashboard|view)\s+(?:for\s+|called\s+)?(.+)/i,
|
|
370
|
+
intent: CommandIntent.CREATE_COMPONENT,
|
|
371
|
+
extractor: (m) => ({ componentName: m[1] }),
|
|
372
|
+
priority: 10,
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
pattern: /(?:build|make)\s+(.+?)\s+(?:component|page|view)/i,
|
|
376
|
+
intent: CommandIntent.CREATE_COMPONENT,
|
|
377
|
+
extractor: (m) => ({ componentName: m[1] }),
|
|
378
|
+
priority: 9,
|
|
379
|
+
},
|
|
380
|
+
// ============================================================
|
|
381
|
+
// REVIEW PATTERNS (Priority: 8)
|
|
382
|
+
// ============================================================
|
|
383
|
+
{
|
|
384
|
+
pattern: /(?:review|check|analyze|inspect)\s+(.+)/i,
|
|
385
|
+
intent: CommandIntent.REVIEW,
|
|
386
|
+
extractor: (m) => ({ target: m[1] }),
|
|
387
|
+
priority: 8,
|
|
388
|
+
},
|
|
389
|
+
// ============================================================
|
|
390
|
+
// OPTIMIZE PATTERNS (Priority: 8)
|
|
391
|
+
// ============================================================
|
|
392
|
+
{
|
|
393
|
+
pattern: /(?:optimize|speed up|make faster)\s+(.+)/i,
|
|
394
|
+
intent: CommandIntent.OPTIMIZE,
|
|
395
|
+
extractor: (m) => ({ target: m[1] }),
|
|
396
|
+
priority: 8,
|
|
397
|
+
},
|
|
398
|
+
// ============================================================
|
|
399
|
+
// DOCUMENTATION PATTERNS (Priority: 8)
|
|
400
|
+
// ============================================================
|
|
401
|
+
{
|
|
402
|
+
pattern: /(?:document|add docs to|write docs for)\s+(.+)/i,
|
|
403
|
+
intent: CommandIntent.DOCUMENT,
|
|
404
|
+
extractor: (m) => ({ target: m[1] }),
|
|
405
|
+
priority: 8,
|
|
406
|
+
},
|
|
407
|
+
// ============================================================
|
|
408
|
+
// HELP PATTERNS (Priority: 10)
|
|
409
|
+
// ============================================================
|
|
410
|
+
{
|
|
411
|
+
pattern: /^(?:help|commands|\?|what can you do)$/i,
|
|
412
|
+
intent: CommandIntent.HELP,
|
|
413
|
+
extractor: () => ({}),
|
|
414
|
+
priority: 10,
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
pattern: /(?:how do I|how to|help with)\s+(.+)/i,
|
|
418
|
+
intent: CommandIntent.HELP,
|
|
419
|
+
extractor: (m) => ({ topic: m[1] }),
|
|
420
|
+
priority: 7,
|
|
421
|
+
},
|
|
422
|
+
];
|
|
423
|
+
// Sort by priority (highest first)
|
|
424
|
+
return patterns.sort((a, b) => b.priority - a.priority);
|
|
425
|
+
}
|
|
426
|
+
// ========================================================================
|
|
427
|
+
// COMMAND PARSING
|
|
428
|
+
// ========================================================================
|
|
429
|
+
parseCommand(userInput) {
|
|
430
|
+
const trimmedInput = userInput.trim();
|
|
431
|
+
// Try to match patterns
|
|
432
|
+
for (const pattern of this.patterns) {
|
|
433
|
+
const match = trimmedInput.match(pattern.pattern);
|
|
434
|
+
if (match) {
|
|
435
|
+
try {
|
|
436
|
+
const parameters = pattern.extractor(match);
|
|
437
|
+
const contextRequirements = CONTEXT_REQUIREMENTS[pattern.intent] || [];
|
|
438
|
+
const targets = this.extractTargets(parameters);
|
|
439
|
+
const confidence = this.calculateConfidence(pattern, trimmedInput);
|
|
440
|
+
const command = {
|
|
441
|
+
rawInput: trimmedInput,
|
|
442
|
+
intent: pattern.intent,
|
|
443
|
+
primaryAction: trimmedInput.split(/\s+/)[0]?.toLowerCase() || '',
|
|
444
|
+
targets,
|
|
445
|
+
parameters,
|
|
446
|
+
contextRequirements,
|
|
447
|
+
confidence,
|
|
448
|
+
timestamp: new Date(),
|
|
449
|
+
};
|
|
450
|
+
this.addToHistory(command);
|
|
451
|
+
return command;
|
|
452
|
+
}
|
|
453
|
+
catch {
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
// No pattern matched - try to infer intent
|
|
459
|
+
return this.inferCommand(trimmedInput);
|
|
460
|
+
}
|
|
461
|
+
calculateConfidence(pattern, userInput) {
|
|
462
|
+
let confidence = Math.min(pattern.priority / 10.0, 1.0);
|
|
463
|
+
const words = userInput.split(/\s+/);
|
|
464
|
+
if (words.length > 3) {
|
|
465
|
+
confidence = Math.min(confidence + 0.1, 1.0);
|
|
466
|
+
}
|
|
467
|
+
return confidence;
|
|
468
|
+
}
|
|
469
|
+
extractTargets(parameters) {
|
|
470
|
+
const targets = [];
|
|
471
|
+
const targetKeys = [
|
|
472
|
+
'filename', 'target', 'location', 'scope', 'path',
|
|
473
|
+
'file', 'directory', 'name', 'featureName',
|
|
474
|
+
'serviceName', 'componentName', 'query',
|
|
475
|
+
];
|
|
476
|
+
for (const key of targetKeys) {
|
|
477
|
+
if (key in parameters) {
|
|
478
|
+
const value = parameters[key];
|
|
479
|
+
if (typeof value === 'string') {
|
|
480
|
+
targets.push(value);
|
|
481
|
+
}
|
|
482
|
+
else if (Array.isArray(value)) {
|
|
483
|
+
targets.push(...value.filter((v) => typeof v === 'string'));
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
return [...new Set(targets)];
|
|
488
|
+
}
|
|
489
|
+
inferCommand(userInput) {
|
|
490
|
+
const words = userInput.toLowerCase().split(/\s+/);
|
|
491
|
+
const actionIntents = {
|
|
492
|
+
create: CommandIntent.CREATE_FILE,
|
|
493
|
+
make: CommandIntent.CREATE_FILE,
|
|
494
|
+
new: CommandIntent.CREATE_FILE,
|
|
495
|
+
edit: CommandIntent.MODIFY_FILE,
|
|
496
|
+
change: CommandIntent.MODIFY_FILE,
|
|
497
|
+
modify: CommandIntent.MODIFY_FILE,
|
|
498
|
+
update: CommandIntent.MODIFY_FILE,
|
|
499
|
+
delete: CommandIntent.DELETE_FILE,
|
|
500
|
+
remove: CommandIntent.DELETE_FILE,
|
|
501
|
+
find: CommandIntent.SEARCH,
|
|
502
|
+
search: CommandIntent.SEARCH,
|
|
503
|
+
locate: CommandIntent.SEARCH,
|
|
504
|
+
grep: CommandIntent.SEARCH,
|
|
505
|
+
build: CommandIntent.BUILD,
|
|
506
|
+
compile: CommandIntent.BUILD,
|
|
507
|
+
test: CommandIntent.TEST,
|
|
508
|
+
run: CommandIntent.EXECUTE_COMMAND,
|
|
509
|
+
execute: CommandIntent.EXECUTE_COMMAND,
|
|
510
|
+
exec: CommandIntent.EXECUTE_COMMAND,
|
|
511
|
+
debug: CommandIntent.DEBUG,
|
|
512
|
+
fix: CommandIntent.DEBUG,
|
|
513
|
+
explain: CommandIntent.EXPLAIN,
|
|
514
|
+
refactor: CommandIntent.REFACTOR,
|
|
515
|
+
optimize: CommandIntent.OPTIMIZE,
|
|
516
|
+
improve: CommandIntent.REFACTOR,
|
|
517
|
+
review: CommandIntent.REVIEW,
|
|
518
|
+
check: CommandIntent.REVIEW,
|
|
519
|
+
document: CommandIntent.DOCUMENT,
|
|
520
|
+
install: CommandIntent.INSTALL,
|
|
521
|
+
git: CommandIntent.GIT_OPERATION,
|
|
522
|
+
commit: CommandIntent.GIT_OPERATION,
|
|
523
|
+
push: CommandIntent.GIT_OPERATION,
|
|
524
|
+
pull: CommandIntent.GIT_OPERATION,
|
|
525
|
+
read: CommandIntent.READ_FILE,
|
|
526
|
+
show: CommandIntent.READ_FILE,
|
|
527
|
+
cat: CommandIntent.READ_FILE,
|
|
528
|
+
ls: CommandIntent.LIST_FILES,
|
|
529
|
+
list: CommandIntent.LIST_FILES,
|
|
530
|
+
help: CommandIntent.HELP,
|
|
531
|
+
};
|
|
532
|
+
let intent = CommandIntent.UNKNOWN;
|
|
533
|
+
for (const word of words) {
|
|
534
|
+
if (word in actionIntents) {
|
|
535
|
+
intent = actionIntents[word];
|
|
536
|
+
break;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
// Try to extract filename
|
|
540
|
+
let filename;
|
|
541
|
+
const fileMatch = userInput.match(/(\w+\.\w+)/);
|
|
542
|
+
if (fileMatch) {
|
|
543
|
+
filename = fileMatch[1];
|
|
544
|
+
}
|
|
545
|
+
const parameters = { raw: userInput };
|
|
546
|
+
if (filename) {
|
|
547
|
+
parameters.filename = filename;
|
|
548
|
+
}
|
|
549
|
+
const command = {
|
|
550
|
+
rawInput: userInput,
|
|
551
|
+
intent,
|
|
552
|
+
primaryAction: words[0] || '',
|
|
553
|
+
targets: filename ? [filename] : [],
|
|
554
|
+
parameters,
|
|
555
|
+
contextRequirements: CONTEXT_REQUIREMENTS[intent] || ['general'],
|
|
556
|
+
confidence: 0.5,
|
|
557
|
+
timestamp: new Date(),
|
|
558
|
+
};
|
|
559
|
+
this.addToHistory(command);
|
|
560
|
+
return command;
|
|
561
|
+
}
|
|
562
|
+
// ========================================================================
|
|
563
|
+
// HANDLER REGISTRATION
|
|
564
|
+
// ========================================================================
|
|
565
|
+
registerHandler(intent, handler) {
|
|
566
|
+
this.handlers.set(intent, handler);
|
|
567
|
+
}
|
|
568
|
+
async executeCommand(command) {
|
|
569
|
+
const handler = this.handlers.get(command.intent);
|
|
570
|
+
if (!handler) {
|
|
571
|
+
return `Command parsed as ${command.intent} but no handler registered`;
|
|
572
|
+
}
|
|
573
|
+
try {
|
|
574
|
+
return await handler(command);
|
|
575
|
+
}
|
|
576
|
+
catch (error) {
|
|
577
|
+
const errorMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
578
|
+
return `Error executing command: ${errorMsg}`;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
// ========================================================================
|
|
582
|
+
// SUGGESTIONS AND HISTORY
|
|
583
|
+
// ========================================================================
|
|
584
|
+
getCommandSuggestions(partialInput) {
|
|
585
|
+
const templates = [
|
|
586
|
+
'create a new file called {filename}',
|
|
587
|
+
'modify {file} to {change}',
|
|
588
|
+
'search for {pattern} in {location}',
|
|
589
|
+
'build the project',
|
|
590
|
+
'run tests for {module}',
|
|
591
|
+
'install {package}',
|
|
592
|
+
'debug {error}',
|
|
593
|
+
'explain how {feature} works',
|
|
594
|
+
'refactor {code} to be more {quality}',
|
|
595
|
+
'find all {type} files',
|
|
596
|
+
'execute {command}',
|
|
597
|
+
'git status',
|
|
598
|
+
'git commit -m "{message}"',
|
|
599
|
+
'git push',
|
|
600
|
+
'create a new component called {name}',
|
|
601
|
+
'optimize {function}',
|
|
602
|
+
'document {module}',
|
|
603
|
+
'read {filename}',
|
|
604
|
+
'list files in {directory}',
|
|
605
|
+
];
|
|
606
|
+
const partialLower = partialInput.toLowerCase();
|
|
607
|
+
const firstWord = partialLower.split(/\s+/)[0] || '';
|
|
608
|
+
return templates
|
|
609
|
+
.filter((template) => template.split(/\s+/)[0].startsWith(firstWord))
|
|
610
|
+
.slice(0, 5);
|
|
611
|
+
}
|
|
612
|
+
getCommandHistory(limit = 10) {
|
|
613
|
+
return this.commandHistory.slice(-limit);
|
|
614
|
+
}
|
|
615
|
+
addToHistory(command) {
|
|
616
|
+
this.commandHistory.push(command);
|
|
617
|
+
if (this.commandHistory.length > this.maxHistory) {
|
|
618
|
+
this.commandHistory = this.commandHistory.slice(-this.maxHistory);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
// ========================================================================
|
|
622
|
+
// INTENT DESCRIPTIONS (for help)
|
|
623
|
+
// ========================================================================
|
|
624
|
+
static getIntentDescription(intent) {
|
|
625
|
+
const descriptions = {
|
|
626
|
+
[CommandIntent.CREATE_FILE]: 'Create a new file',
|
|
627
|
+
[CommandIntent.MODIFY_FILE]: 'Modify an existing file',
|
|
628
|
+
[CommandIntent.DELETE_FILE]: 'Delete a file or directory',
|
|
629
|
+
[CommandIntent.EXECUTE_COMMAND]: 'Execute a shell command',
|
|
630
|
+
[CommandIntent.ANALYZE_CODE]: 'Analyze code for issues',
|
|
631
|
+
[CommandIntent.REFACTOR]: 'Refactor code for better quality',
|
|
632
|
+
[CommandIntent.SEARCH]: 'Search for files or content',
|
|
633
|
+
[CommandIntent.BUILD]: 'Build the project',
|
|
634
|
+
[CommandIntent.TEST]: 'Run tests',
|
|
635
|
+
[CommandIntent.DEPLOY]: 'Deploy the application',
|
|
636
|
+
[CommandIntent.EXPLAIN]: 'Explain code or concepts',
|
|
637
|
+
[CommandIntent.DEBUG]: 'Debug an issue',
|
|
638
|
+
[CommandIntent.INSTALL]: 'Install packages/dependencies',
|
|
639
|
+
[CommandIntent.CONFIGURE]: 'Configure settings',
|
|
640
|
+
[CommandIntent.CREATE_FEATURE]: 'Create a new feature (multi-file)',
|
|
641
|
+
[CommandIntent.CREATE_SERVICE]: 'Create a new service',
|
|
642
|
+
[CommandIntent.CREATE_COMPONENT]: 'Create a UI component',
|
|
643
|
+
[CommandIntent.REVIEW]: 'Review code',
|
|
644
|
+
[CommandIntent.OPTIMIZE]: 'Optimize performance',
|
|
645
|
+
[CommandIntent.DOCUMENT]: 'Generate documentation',
|
|
646
|
+
[CommandIntent.GIT_OPERATION]: 'Perform git operations',
|
|
647
|
+
[CommandIntent.READ_FILE]: 'Read file contents',
|
|
648
|
+
[CommandIntent.LIST_FILES]: 'List files in directory',
|
|
649
|
+
[CommandIntent.HELP]: 'Get help',
|
|
650
|
+
[CommandIntent.UNKNOWN]: 'Unknown command',
|
|
651
|
+
};
|
|
652
|
+
return descriptions[intent] || 'Unknown';
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
// ============================================================================
|
|
656
|
+
// GLOBAL INSTANCE
|
|
657
|
+
// ============================================================================
|
|
658
|
+
let commandEngineInstance = null;
|
|
659
|
+
export function getCommandEngine() {
|
|
660
|
+
if (!commandEngineInstance) {
|
|
661
|
+
commandEngineInstance = new CommandProcessingEngine();
|
|
662
|
+
}
|
|
663
|
+
return commandEngineInstance;
|
|
664
|
+
}
|
|
665
|
+
export function resetCommandEngine() {
|
|
666
|
+
commandEngineInstance = null;
|
|
667
|
+
}
|
|
668
|
+
// ============================================================================
|
|
669
|
+
// EXPORT
|
|
670
|
+
// ============================================================================
|
|
671
|
+
export default CommandProcessingEngine;
|
|
672
|
+
//# sourceMappingURL=commandEngine.js.map
|