clavix 4.0.0 → 4.1.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.
Files changed (57) hide show
  1. package/dist/core/intelligence/intent-detector.js +351 -119
  2. package/dist/core/intelligence/pattern-library.js +17 -4
  3. package/dist/core/intelligence/patterns/actionability-enhancer.d.ts +1 -1
  4. package/dist/core/intelligence/patterns/actionability-enhancer.js +31 -26
  5. package/dist/core/intelligence/patterns/alternative-phrasing-generator.d.ts +1 -1
  6. package/dist/core/intelligence/patterns/alternative-phrasing-generator.js +40 -40
  7. package/dist/core/intelligence/patterns/ambiguity-detector.d.ts +20 -0
  8. package/dist/core/intelligence/patterns/ambiguity-detector.js +168 -0
  9. package/dist/core/intelligence/patterns/assumption-explicitizer.d.ts +1 -1
  10. package/dist/core/intelligence/patterns/assumption-explicitizer.js +27 -27
  11. package/dist/core/intelligence/patterns/completeness-validator.d.ts +1 -1
  12. package/dist/core/intelligence/patterns/completeness-validator.js +94 -29
  13. package/dist/core/intelligence/patterns/conciseness-filter.d.ts +1 -1
  14. package/dist/core/intelligence/patterns/conciseness-filter.js +11 -12
  15. package/dist/core/intelligence/patterns/context-precision.d.ts +1 -1
  16. package/dist/core/intelligence/patterns/context-precision.js +76 -39
  17. package/dist/core/intelligence/patterns/domain-context-enricher.d.ts +19 -0
  18. package/dist/core/intelligence/patterns/domain-context-enricher.js +174 -0
  19. package/dist/core/intelligence/patterns/edge-case-identifier.d.ts +1 -1
  20. package/dist/core/intelligence/patterns/edge-case-identifier.js +42 -42
  21. package/dist/core/intelligence/patterns/error-tolerance-enhancer.d.ts +20 -0
  22. package/dist/core/intelligence/patterns/error-tolerance-enhancer.js +161 -0
  23. package/dist/core/intelligence/patterns/output-format-enforcer.d.ts +20 -0
  24. package/dist/core/intelligence/patterns/output-format-enforcer.js +134 -0
  25. package/dist/core/intelligence/patterns/prd-structure-enforcer.d.ts +2 -2
  26. package/dist/core/intelligence/patterns/prd-structure-enforcer.js +20 -20
  27. package/dist/core/intelligence/patterns/prerequisite-identifier.d.ts +21 -0
  28. package/dist/core/intelligence/patterns/prerequisite-identifier.js +197 -0
  29. package/dist/core/intelligence/patterns/scope-definer.d.ts +1 -1
  30. package/dist/core/intelligence/patterns/scope-definer.js +12 -12
  31. package/dist/core/intelligence/patterns/step-decomposer.d.ts +1 -1
  32. package/dist/core/intelligence/patterns/step-decomposer.js +23 -23
  33. package/dist/core/intelligence/patterns/structure-organizer.d.ts +1 -1
  34. package/dist/core/intelligence/patterns/structure-organizer.js +23 -10
  35. package/dist/core/intelligence/patterns/success-criteria-enforcer.d.ts +20 -0
  36. package/dist/core/intelligence/patterns/success-criteria-enforcer.js +148 -0
  37. package/dist/core/intelligence/patterns/validation-checklist-creator.d.ts +1 -1
  38. package/dist/core/intelligence/patterns/validation-checklist-creator.js +40 -24
  39. package/dist/core/intelligence/quality-assessor.js +133 -61
  40. package/dist/core/intelligence/universal-optimizer.js +20 -19
  41. package/dist/core/template-assembler.js +12 -10
  42. package/dist/templates/slash-commands/_canonical/deep.md +36 -10
  43. package/dist/templates/slash-commands/_canonical/execute.md +23 -7
  44. package/dist/templates/slash-commands/_canonical/fast.md +32 -11
  45. package/dist/templates/slash-commands/_canonical/implement.md +28 -8
  46. package/dist/templates/slash-commands/_canonical/plan.md +31 -10
  47. package/dist/templates/slash-commands/_canonical/prd.md +31 -10
  48. package/dist/templates/slash-commands/_canonical/start.md +24 -12
  49. package/dist/templates/slash-commands/_canonical/summarize.md +31 -10
  50. package/dist/templates/slash-commands/_components/agent-protocols/decision-rules.md +123 -0
  51. package/dist/templates/slash-commands/_components/agent-protocols/error-handling.md +120 -0
  52. package/dist/templates/slash-commands/_components/agent-protocols/file-formats.md +187 -0
  53. package/dist/templates/slash-commands/_components/agent-protocols/quality-output.md +94 -0
  54. package/dist/templates/slash-commands/_components/agent-protocols/state-awareness.md +104 -0
  55. package/dist/templates/slash-commands/_components/sections/escalation-factors.md +117 -0
  56. package/dist/templates/slash-commands/_components/sections/pattern-visibility.md +119 -0
  57. package/package.json +1 -1
@@ -5,122 +5,307 @@
5
5
  export class IntentDetector {
6
6
  // Strong indicators (20 points)
7
7
  STRONG_CODE_KEYWORDS = [
8
- 'create function', 'build component', 'implement feature', 'add endpoint',
9
- 'write class', 'develop api', 'generate code'
8
+ 'create function',
9
+ 'build component',
10
+ 'implement feature',
11
+ 'add endpoint',
12
+ 'write class',
13
+ 'develop api',
14
+ 'generate code',
10
15
  ];
11
16
  STRONG_PLANNING_KEYWORDS = [
12
- 'how should i', 'what\'s the best way', 'pros and cons', 'architecture for',
13
- 'design pattern', 'system design', 'should i use', 'help me choose',
14
- 'design the database', 'plan the', 'requirements document',
17
+ 'how should i',
18
+ "what's the best way",
19
+ 'pros and cons',
20
+ 'architecture for',
21
+ 'design pattern',
22
+ 'system design',
23
+ 'should i use',
24
+ 'help me choose',
25
+ 'design the database',
26
+ 'plan the',
27
+ 'requirements document',
15
28
  // v4.0: Spec-driven development keywords
16
- 'write spec', 'create spec', 'spec document', 'functional spec', 'technical spec',
17
- 'design spec', 'specification for', 'write specification'
29
+ 'write spec',
30
+ 'create spec',
31
+ 'spec document',
32
+ 'functional spec',
33
+ 'technical spec',
34
+ 'design spec',
35
+ 'specification for',
36
+ 'write specification',
18
37
  ];
19
38
  STRONG_DEBUGGING_KEYWORDS = [
20
- 'fix error', 'debug issue', 'doesn\'t work', 'throws error', 'not working',
21
- 'returns null', 'undefined error', 'stack trace', 'error message',
22
- 'causing this bug', 'how do i fix', 'fix this error', 'resolve the', 'memory leak',
23
- 'not rendering', 'why is my'
39
+ 'fix error',
40
+ 'debug issue',
41
+ "doesn't work",
42
+ 'throws error',
43
+ 'not working',
44
+ 'returns null',
45
+ 'undefined error',
46
+ 'stack trace',
47
+ 'error message',
48
+ 'causing this bug',
49
+ 'how do i fix',
50
+ 'fix this error',
51
+ 'resolve the',
52
+ 'memory leak',
53
+ 'not rendering',
54
+ 'why is my',
24
55
  ];
25
56
  STRONG_DOCUMENTATION_KEYWORDS = [
26
- 'explain how', 'walk me through', 'how does this work', 'show me how',
27
- 'document this', 'describe how', 'what does this do', 'write documentation',
28
- 'create documentation', 'add documentation', 'api documentation', 'add comments'
57
+ 'explain how',
58
+ 'walk me through',
59
+ 'how does this work',
60
+ 'show me how',
61
+ 'document this',
62
+ 'describe how',
63
+ 'what does this do',
64
+ 'write documentation',
65
+ 'create documentation',
66
+ 'add documentation',
67
+ 'api documentation',
68
+ 'add comments',
29
69
  ];
30
70
  STRONG_REFINEMENT_KEYWORDS = [
31
- 'make it faster', 'speed up', 'reduce time', 'optimize performance',
32
- 'clean up code', 'refactor this', 'improve efficiency', 'make this component',
33
- 'make it more', 'enhance the', 'update the styling', 'more reusable', 'more modern'
71
+ 'make it faster',
72
+ 'speed up',
73
+ 'reduce time',
74
+ 'optimize performance',
75
+ 'clean up code',
76
+ 'refactor this',
77
+ 'improve efficiency',
78
+ 'make this component',
79
+ 'make it more',
80
+ 'enhance the',
81
+ 'update the styling',
82
+ 'more reusable',
83
+ 'more modern',
34
84
  ];
35
85
  // v4.0: New intent - Testing
36
86
  STRONG_TESTING_KEYWORDS = [
37
- 'write test', 'unit test', 'integration test', 'test coverage', 'add test',
38
- 'create test', 'write tests for', 'add tests for', 'test this', 'e2e test',
39
- 'end to end test', 'snapshot test', 'test suite'
87
+ 'write test',
88
+ 'unit test',
89
+ 'integration test',
90
+ 'test coverage',
91
+ 'add test',
92
+ 'create test',
93
+ 'write tests for',
94
+ 'add tests for',
95
+ 'test this',
96
+ 'e2e test',
97
+ 'end to end test',
98
+ 'snapshot test',
99
+ 'test suite',
40
100
  ];
41
101
  // v4.0: New intent - Migration
42
102
  STRONG_MIGRATION_KEYWORDS = [
43
- 'migrate from', 'migrate to', 'upgrade from', 'upgrade to', 'port from',
44
- 'port to', 'convert from', 'convert to', 'transition from', 'move from',
45
- 'update from version', 'upgrade version'
103
+ 'migrate from',
104
+ 'migrate to',
105
+ 'upgrade from',
106
+ 'upgrade to',
107
+ 'port from',
108
+ 'port to',
109
+ 'convert from',
110
+ 'convert to',
111
+ 'transition from',
112
+ 'move from',
113
+ 'update from version',
114
+ 'upgrade version',
46
115
  ];
47
116
  // v4.0: New intent - Security Review
48
117
  STRONG_SECURITY_KEYWORDS = [
49
- 'security audit', 'find vulnerabilities', 'check for injection', 'security scan',
50
- 'audit security', 'review for security', 'penetration test', 'security review',
51
- 'check for xss', 'check for csrf', 'vulnerability scan', 'security assessment'
118
+ 'security audit',
119
+ 'find vulnerabilities',
120
+ 'check for injection',
121
+ 'security scan',
122
+ 'audit security',
123
+ 'review for security',
124
+ 'penetration test',
125
+ 'security review',
126
+ 'check for xss',
127
+ 'check for csrf',
128
+ 'vulnerability scan',
129
+ 'security assessment',
52
130
  ];
53
131
  // v4.0: New intent - Learning
54
132
  STRONG_LEARNING_KEYWORDS = [
55
- 'teach me', 'explain how', 'help me understand', 'what is the concept',
56
- 'how does', 'why does', 'learn about', 'understand how', 'what are',
57
- 'difference between', 'when should i use', 'best practices for'
133
+ 'teach me',
134
+ 'explain how',
135
+ 'help me understand',
136
+ 'what is the concept',
137
+ 'how does',
138
+ 'why does',
139
+ 'learn about',
140
+ 'understand how',
141
+ 'what are',
142
+ 'difference between',
143
+ 'when should i use',
144
+ 'best practices for',
58
145
  ];
59
146
  // Medium indicators (10 points)
60
147
  CODE_KEYWORDS = [
61
- 'function', 'class', 'component', 'api', 'endpoint', 'database',
62
- 'implement', 'build', 'create', 'write', 'code', 'develop'
148
+ 'function',
149
+ 'class',
150
+ 'component',
151
+ 'api',
152
+ 'endpoint',
153
+ 'database',
154
+ 'implement',
155
+ 'build',
156
+ 'create',
157
+ 'write',
158
+ 'code',
159
+ 'develop',
63
160
  ];
64
161
  PLANNING_KEYWORDS = [
65
- 'plan', 'design', 'architect', 'strategy', 'approach', 'structure',
66
- 'organize', 'layout', 'workflow',
162
+ 'plan',
163
+ 'design',
164
+ 'architect',
165
+ 'strategy',
166
+ 'approach',
167
+ 'structure',
168
+ 'organize',
169
+ 'layout',
170
+ 'workflow',
67
171
  // v4.0: Spec-driven development keywords
68
- 'spec', 'specification', 'requirements', 'blueprint', 'outline'
172
+ 'spec',
173
+ 'specification',
174
+ 'requirements',
175
+ 'blueprint',
176
+ 'outline',
69
177
  ];
70
178
  REFINEMENT_KEYWORDS = [
71
- 'improve', 'optimize', 'refactor', 'enhance', 'better', 'faster',
72
- 'cleaner', 'simplify', 'reduce', 'increase'
179
+ 'improve',
180
+ 'optimize',
181
+ 'refactor',
182
+ 'enhance',
183
+ 'better',
184
+ 'faster',
185
+ 'cleaner',
186
+ 'simplify',
187
+ 'reduce',
188
+ 'increase',
73
189
  ];
74
190
  DEBUGGING_KEYWORDS = [
75
- 'fix', 'debug', 'error', 'bug', 'issue', 'problem', 'failing',
76
- 'broken', 'crash', 'exception', 'incorrect', 'wrong'
191
+ 'fix',
192
+ 'debug',
193
+ 'error',
194
+ 'bug',
195
+ 'issue',
196
+ 'problem',
197
+ 'failing',
198
+ 'broken',
199
+ 'crash',
200
+ 'exception',
201
+ 'incorrect',
202
+ 'wrong',
77
203
  ];
78
204
  DOCUMENTATION_KEYWORDS = [
79
- 'explain', 'document', 'describe', 'understand',
80
- 'clarify', 'comment', 'documentation', 'guide', 'tutorial'
205
+ 'explain',
206
+ 'document',
207
+ 'describe',
208
+ 'understand',
209
+ 'clarify',
210
+ 'comment',
211
+ 'documentation',
212
+ 'guide',
213
+ 'tutorial',
81
214
  ];
82
215
  // v4.0: Medium keywords for new intents
83
216
  TESTING_KEYWORDS = [
84
- 'test', 'coverage', 'jest', 'pytest', 'mocha', 'vitest', 'mock',
85
- 'assertion', 'expect', 'describe', 'spec', 'fixture', 'stub', 'spy'
217
+ 'test',
218
+ 'coverage',
219
+ 'jest',
220
+ 'pytest',
221
+ 'mocha',
222
+ 'vitest',
223
+ 'mock',
224
+ 'assertion',
225
+ 'expect',
226
+ 'describe',
227
+ 'spec',
228
+ 'fixture',
229
+ 'stub',
230
+ 'spy',
86
231
  ];
87
232
  MIGRATION_KEYWORDS = [
88
- 'migrate', 'migration', 'upgrade', 'port', 'convert', 'transition',
89
- 'legacy', 'deprecated', 'version', 'breaking change', 'compatibility'
233
+ 'migrate',
234
+ 'migration',
235
+ 'upgrade',
236
+ 'port',
237
+ 'convert',
238
+ 'transition',
239
+ 'legacy',
240
+ 'deprecated',
241
+ 'version',
242
+ 'breaking change',
243
+ 'compatibility',
90
244
  ];
91
245
  SECURITY_KEYWORDS = [
92
- 'security', 'vulnerability', 'xss', 'csrf', 'injection', 'sanitize',
93
- 'escape', 'owasp', 'cve', 'exploit', 'attack', 'threat', 'risk'
246
+ 'security',
247
+ 'vulnerability',
248
+ 'xss',
249
+ 'csrf',
250
+ 'injection',
251
+ 'sanitize',
252
+ 'escape',
253
+ 'owasp',
254
+ 'cve',
255
+ 'exploit',
256
+ 'attack',
257
+ 'threat',
258
+ 'risk',
94
259
  ];
95
260
  LEARNING_KEYWORDS = [
96
- 'understand', 'learn', 'concept', 'basics', 'fundamentals', 'tutorial',
97
- 'introduction', 'beginner', 'overview', 'theory', 'principle'
261
+ 'understand',
262
+ 'learn',
263
+ 'concept',
264
+ 'basics',
265
+ 'fundamentals',
266
+ 'tutorial',
267
+ 'introduction',
268
+ 'beginner',
269
+ 'overview',
270
+ 'theory',
271
+ 'principle',
98
272
  ];
99
273
  // Weak indicators (5 points)
100
274
  WEAK_CODE_KEYWORDS = [
101
- 'react', 'vue', 'angular', 'python', 'javascript', 'typescript',
102
- 'java', 'rust', 'go', 'php', 'ruby', 'swift', 'kotlin', 'system', 'feature'
275
+ 'react',
276
+ 'vue',
277
+ 'angular',
278
+ 'python',
279
+ 'javascript',
280
+ 'typescript',
281
+ 'java',
282
+ 'rust',
283
+ 'go',
284
+ 'php',
285
+ 'ruby',
286
+ 'swift',
287
+ 'kotlin',
288
+ 'system',
289
+ 'feature',
103
290
  ];
104
291
  // Negation words (reduces score by 50%)
105
- NEGATION_WORDS = [
106
- 'don\'t', 'dont', 'not', 'avoid', 'without', 'never', 'no'
107
- ];
292
+ NEGATION_WORDS = ["don't", 'dont', 'not', 'avoid', 'without', 'never', 'no'];
108
293
  analyze(prompt) {
109
294
  const lowerPrompt = prompt.toLowerCase();
110
295
  const words = lowerPrompt.split(/\s+/);
111
296
  // Calculate weighted scores for each intent
112
297
  const scores = {
113
298
  'code-generation': this.calculateIntentScore(lowerPrompt, words, 'code-generation'),
114
- 'planning': this.calculateIntentScore(lowerPrompt, words, 'planning'),
115
- 'refinement': this.calculateIntentScore(lowerPrompt, words, 'refinement'),
116
- 'debugging': this.calculateIntentScore(lowerPrompt, words, 'debugging'),
117
- 'documentation': this.calculateIntentScore(lowerPrompt, words, 'documentation'),
299
+ planning: this.calculateIntentScore(lowerPrompt, words, 'planning'),
300
+ refinement: this.calculateIntentScore(lowerPrompt, words, 'refinement'),
301
+ debugging: this.calculateIntentScore(lowerPrompt, words, 'debugging'),
302
+ documentation: this.calculateIntentScore(lowerPrompt, words, 'documentation'),
118
303
  'prd-generation': 0, // PRD is explicit command, not inferred
119
304
  // v4.0: New intents
120
- 'testing': this.calculateIntentScore(lowerPrompt, words, 'testing'),
121
- 'migration': this.calculateIntentScore(lowerPrompt, words, 'migration'),
305
+ testing: this.calculateIntentScore(lowerPrompt, words, 'testing'),
306
+ migration: this.calculateIntentScore(lowerPrompt, words, 'migration'),
122
307
  'security-review': this.calculateIntentScore(lowerPrompt, words, 'security-review'),
123
- 'learning': this.calculateIntentScore(lowerPrompt, words, 'learning')
308
+ learning: this.calculateIntentScore(lowerPrompt, words, 'learning'),
124
309
  };
125
310
  // Apply intent priority rules
126
311
  const primaryIntent = this.selectPrimaryIntent(scores, lowerPrompt);
@@ -131,7 +316,7 @@ export class IntentDetector {
131
316
  hasCodeContext: this.hasCodeContext(prompt),
132
317
  hasTechnicalTerms: this.hasTechnicalTerms(lowerPrompt),
133
318
  isOpenEnded: this.isOpenEnded(prompt),
134
- needsStructure: this.needsStructure(prompt, primaryIntent)
319
+ needsStructure: this.needsStructure(prompt, primaryIntent),
135
320
  };
136
321
  // Suggest mode
137
322
  const suggestedMode = this.suggestMode(primaryIntent, characteristics, prompt.length, confidence);
@@ -139,7 +324,7 @@ export class IntentDetector {
139
324
  primaryIntent,
140
325
  confidence,
141
326
  characteristics,
142
- suggestedMode
327
+ suggestedMode,
143
328
  };
144
329
  }
145
330
  calculateIntentScore(prompt, words, intent) {
@@ -174,56 +359,56 @@ export class IntentDetector {
174
359
  return {
175
360
  strong: this.STRONG_CODE_KEYWORDS,
176
361
  medium: this.CODE_KEYWORDS,
177
- weak: this.WEAK_CODE_KEYWORDS
362
+ weak: this.WEAK_CODE_KEYWORDS,
178
363
  };
179
364
  case 'planning':
180
365
  return {
181
366
  strong: this.STRONG_PLANNING_KEYWORDS,
182
367
  medium: this.PLANNING_KEYWORDS,
183
- weak: []
368
+ weak: [],
184
369
  };
185
370
  case 'debugging':
186
371
  return {
187
372
  strong: this.STRONG_DEBUGGING_KEYWORDS,
188
373
  medium: this.DEBUGGING_KEYWORDS,
189
- weak: []
374
+ weak: [],
190
375
  };
191
376
  case 'documentation':
192
377
  return {
193
378
  strong: this.STRONG_DOCUMENTATION_KEYWORDS,
194
379
  medium: this.DOCUMENTATION_KEYWORDS,
195
- weak: []
380
+ weak: [],
196
381
  };
197
382
  case 'refinement':
198
383
  return {
199
384
  strong: this.STRONG_REFINEMENT_KEYWORDS,
200
385
  medium: this.REFINEMENT_KEYWORDS,
201
- weak: []
386
+ weak: [],
202
387
  };
203
388
  // v4.0: New intents
204
389
  case 'testing':
205
390
  return {
206
391
  strong: this.STRONG_TESTING_KEYWORDS,
207
392
  medium: this.TESTING_KEYWORDS,
208
- weak: []
393
+ weak: [],
209
394
  };
210
395
  case 'migration':
211
396
  return {
212
397
  strong: this.STRONG_MIGRATION_KEYWORDS,
213
398
  medium: this.MIGRATION_KEYWORDS,
214
- weak: []
399
+ weak: [],
215
400
  };
216
401
  case 'security-review':
217
402
  return {
218
403
  strong: this.STRONG_SECURITY_KEYWORDS,
219
404
  medium: this.SECURITY_KEYWORDS,
220
- weak: []
405
+ weak: [],
221
406
  };
222
407
  case 'learning':
223
408
  return {
224
409
  strong: this.STRONG_LEARNING_KEYWORDS,
225
410
  medium: this.LEARNING_KEYWORDS,
226
- weak: []
411
+ weak: [],
227
412
  };
228
413
  default:
229
414
  return { strong: [], medium: [], weak: [] };
@@ -246,11 +431,13 @@ export class IntentDetector {
246
431
  getContextBonus(prompt, intent) {
247
432
  let bonus = 0;
248
433
  // Code snippet bonus for debugging/refinement/testing
249
- if ((intent === 'debugging' || intent === 'refinement' || intent === 'testing') && this.hasCodeContext(prompt)) {
434
+ if ((intent === 'debugging' || intent === 'refinement' || intent === 'testing') &&
435
+ this.hasCodeContext(prompt)) {
250
436
  bonus += 15;
251
437
  }
252
438
  // Question mark bonus for planning/documentation/learning
253
- if ((intent === 'planning' || intent === 'documentation' || intent === 'learning') && prompt.includes('?')) {
439
+ if ((intent === 'planning' || intent === 'documentation' || intent === 'learning') &&
440
+ prompt.includes('?')) {
254
441
  bonus += 10;
255
442
  }
256
443
  // Technical terms bonus for code-generation
@@ -279,11 +466,11 @@ export class IntentDetector {
279
466
  // v4.0: Helper methods for new intent bonuses
280
467
  hasTestingFrameworkTerms(prompt) {
281
468
  const terms = ['jest', 'mocha', 'pytest', 'vitest', 'cypress', 'playwright', 'testing-library'];
282
- return terms.some(term => prompt.includes(term));
469
+ return terms.some((term) => prompt.includes(term));
283
470
  }
284
471
  hasSecurityTerms(prompt) {
285
472
  const terms = ['owasp', 'cve', 'vulnerability', 'exploit', 'injection', 'xss', 'csrf'];
286
- return terms.some(term => prompt.includes(term));
473
+ return terms.some((term) => prompt.includes(term));
287
474
  }
288
475
  hasMigrationPatterns(prompt) {
289
476
  // Check for version patterns like "v1 to v2", "17 to 18", "2.x to 3.x"
@@ -293,49 +480,75 @@ export class IntentDetector {
293
480
  }
294
481
  selectPrimaryIntent(scores, prompt) {
295
482
  // Priority 1: Debugging (if strong indicators present)
296
- if (scores.debugging >= 20 && (prompt.includes('error') || prompt.includes('bug') || prompt.includes('fix') ||
297
- prompt.includes('debug') || prompt.includes('issue') || prompt.includes('resolve'))) {
483
+ if (scores.debugging >= 20 &&
484
+ (prompt.includes('error') ||
485
+ prompt.includes('bug') ||
486
+ prompt.includes('fix') ||
487
+ prompt.includes('debug') ||
488
+ prompt.includes('issue') ||
489
+ prompt.includes('resolve'))) {
298
490
  return 'debugging';
299
491
  }
300
492
  // Priority 2: Security Review (if security audit explicitly requested)
301
- if (scores['security-review'] >= 20 && (prompt.includes('security') || prompt.includes('vulnerability') ||
302
- prompt.includes('audit') || prompt.includes('owasp'))) {
493
+ if (scores['security-review'] >= 20 &&
494
+ (prompt.includes('security') ||
495
+ prompt.includes('vulnerability') ||
496
+ prompt.includes('audit') ||
497
+ prompt.includes('owasp'))) {
303
498
  return 'security-review';
304
499
  }
305
500
  // Priority 3: Testing (if test creation explicitly requested)
306
- if (scores.testing >= 20 && (prompt.includes('test') || prompt.includes('coverage') ||
307
- prompt.includes('spec') && !prompt.includes('specification'))) {
501
+ if (scores.testing >= 20 &&
502
+ (prompt.includes('test') ||
503
+ prompt.includes('coverage') ||
504
+ (prompt.includes('spec') && !prompt.includes('specification')))) {
308
505
  return 'testing';
309
506
  }
310
507
  // Priority 4: Migration (if version upgrade explicitly requested)
311
- if (scores.migration >= 20 && (prompt.includes('migrate') || prompt.includes('upgrade') ||
312
- prompt.includes('port') || this.hasMigrationPatterns(prompt))) {
508
+ if (scores.migration >= 20 &&
509
+ (prompt.includes('migrate') ||
510
+ prompt.includes('upgrade') ||
511
+ prompt.includes('port') ||
512
+ this.hasMigrationPatterns(prompt))) {
313
513
  return 'migration';
314
514
  }
315
515
  // Priority 5: Documentation (if explanation requested or write documentation)
316
- if (scores.documentation >= 20 && (prompt.includes('explain') || prompt.includes('how does') ||
317
- prompt.includes('documentation') || (prompt.includes('write') && prompt.includes('document')))) {
516
+ if (scores.documentation >= 20 &&
517
+ (prompt.includes('explain') ||
518
+ prompt.includes('how does') ||
519
+ prompt.includes('documentation') ||
520
+ (prompt.includes('write') && prompt.includes('document')))) {
318
521
  return 'documentation';
319
522
  }
320
523
  // Priority 6: Learning (if conceptual understanding requested)
321
- if (scores.learning >= 20 && (prompt.includes('teach') || prompt.includes('learn') ||
322
- prompt.includes('understand') || prompt.includes('concept'))) {
524
+ if (scores.learning >= 20 &&
525
+ (prompt.includes('teach') ||
526
+ prompt.includes('learn') ||
527
+ prompt.includes('understand') ||
528
+ prompt.includes('concept'))) {
323
529
  return 'learning';
324
530
  }
325
531
  // Priority 7: Planning (if architecture/design question or spec-driven)
326
- if (scores.planning >= 20 && (prompt.includes('how should') || prompt.includes('architecture') ||
327
- prompt.includes('what is the best') || prompt.includes('specification') ||
328
- (prompt.includes('spec') && !prompt.includes('test')))) {
532
+ if (scores.planning >= 20 &&
533
+ (prompt.includes('how should') ||
534
+ prompt.includes('architecture') ||
535
+ prompt.includes('what is the best') ||
536
+ prompt.includes('specification') ||
537
+ (prompt.includes('spec') && !prompt.includes('test')))) {
329
538
  return 'planning';
330
539
  }
331
540
  // Priority 8: Refinement (if improvement requested)
332
- if (scores.refinement >= 15 && (prompt.includes('improve') || prompt.includes('optimize') ||
333
- prompt.includes('enhance') || prompt.includes('make') || prompt.includes('refactor'))) {
541
+ if (scores.refinement >= 15 &&
542
+ (prompt.includes('improve') ||
543
+ prompt.includes('optimize') ||
544
+ prompt.includes('enhance') ||
545
+ prompt.includes('make') ||
546
+ prompt.includes('refactor'))) {
334
547
  return 'refinement';
335
548
  }
336
549
  // Default: Highest score
337
550
  const entries = Object.entries(scores);
338
- const [primaryIntent] = entries.reduce((max, current) => current[1] > max[1] ? current : max);
551
+ const [primaryIntent] = entries.reduce((max, current) => (current[1] > max[1] ? current : max));
339
552
  return primaryIntent;
340
553
  }
341
554
  calculateConfidence(scores, primaryIntent) {
@@ -375,32 +588,54 @@ export class IntentDetector {
375
588
  /def\s+\w+\s*\(/,
376
589
  /import\s+/,
377
590
  /<\w+>/,
378
- /\w+\.\w+\(/
591
+ /\w+\.\w+\(/,
379
592
  ];
380
- return codePatterns.some(pattern => pattern.test(prompt));
593
+ return codePatterns.some((pattern) => pattern.test(prompt));
381
594
  }
382
595
  hasTechnicalTerms(prompt) {
383
596
  const terms = [
384
- 'api', 'database', 'sql', 'rest', 'graphql', 'jwt',
385
- 'authentication', 'middleware', 'framework', 'library',
386
- 'npm', 'docker', 'aws', 'frontend', 'backend', 'microservice'
597
+ 'api',
598
+ 'database',
599
+ 'sql',
600
+ 'rest',
601
+ 'graphql',
602
+ 'jwt',
603
+ 'authentication',
604
+ 'middleware',
605
+ 'framework',
606
+ 'library',
607
+ 'npm',
608
+ 'docker',
609
+ 'aws',
610
+ 'frontend',
611
+ 'backend',
612
+ 'microservice',
387
613
  ];
388
- return terms.some(term => prompt.includes(term));
614
+ return terms.some((term) => prompt.includes(term));
389
615
  }
390
616
  hasPerformanceTerms(prompt) {
391
617
  const terms = [
392
- 'performance', 'speed', 'fast', 'slow', 'optimize', 'latency',
393
- 'throughput', 'memory', 'cpu', 'load time', 'response time'
618
+ 'performance',
619
+ 'speed',
620
+ 'fast',
621
+ 'slow',
622
+ 'optimize',
623
+ 'latency',
624
+ 'throughput',
625
+ 'memory',
626
+ 'cpu',
627
+ 'load time',
628
+ 'response time',
394
629
  ];
395
- return terms.some(term => prompt.includes(term));
630
+ return terms.some((term) => prompt.includes(term));
396
631
  }
397
632
  isOpenEnded(prompt) {
398
633
  const questionWords = ['how', 'what', 'why', 'when', 'where', 'which', 'should'];
399
634
  const lowerPrompt = prompt.toLowerCase();
400
- const hasQuestionWord = questionWords.some(word => lowerPrompt.startsWith(word));
635
+ const hasQuestionWord = questionWords.some((word) => lowerPrompt.startsWith(word));
401
636
  const hasQuestionMark = prompt.includes('?');
402
637
  const vaguePatterns = ['help me', 'i need', 'not sure', 'maybe', 'somehow'];
403
- const hasVague = vaguePatterns.some(pattern => lowerPrompt.includes(pattern));
638
+ const hasVague = vaguePatterns.some((pattern) => lowerPrompt.includes(pattern));
404
639
  return hasQuestionWord || hasQuestionMark || hasVague;
405
640
  }
406
641
  needsStructure(prompt, intent) {
@@ -409,8 +644,7 @@ export class IntentDetector {
409
644
  const hasObjective = /objective|goal|purpose|need to|want to/i.test(prompt);
410
645
  const hasRequirements = /requirement|must|should|need|expect/i.test(prompt);
411
646
  const hasConstraints = /constraint|limit|within|must not|cannot/i.test(prompt);
412
- const structureScore = [hasObjective, hasRequirements, hasConstraints]
413
- .filter(Boolean).length;
647
+ const structureScore = [hasObjective, hasRequirements, hasConstraints].filter(Boolean).length;
414
648
  return structureScore < 2;
415
649
  }
416
650
  suggestMode(intent, characteristics, promptLength, confidence) {
@@ -442,15 +676,15 @@ export class IntentDetector {
442
676
  // Calculate all scores for secondary intent detection
443
677
  const scores = {
444
678
  'code-generation': this.calculateIntentScore(lowerPrompt, words, 'code-generation'),
445
- 'planning': this.calculateIntentScore(lowerPrompt, words, 'planning'),
446
- 'refinement': this.calculateIntentScore(lowerPrompt, words, 'refinement'),
447
- 'debugging': this.calculateIntentScore(lowerPrompt, words, 'debugging'),
448
- 'documentation': this.calculateIntentScore(lowerPrompt, words, 'documentation'),
679
+ planning: this.calculateIntentScore(lowerPrompt, words, 'planning'),
680
+ refinement: this.calculateIntentScore(lowerPrompt, words, 'refinement'),
681
+ debugging: this.calculateIntentScore(lowerPrompt, words, 'debugging'),
682
+ documentation: this.calculateIntentScore(lowerPrompt, words, 'documentation'),
449
683
  'prd-generation': 0,
450
- 'testing': this.calculateIntentScore(lowerPrompt, words, 'testing'),
451
- 'migration': this.calculateIntentScore(lowerPrompt, words, 'migration'),
684
+ testing: this.calculateIntentScore(lowerPrompt, words, 'testing'),
685
+ migration: this.calculateIntentScore(lowerPrompt, words, 'migration'),
452
686
  'security-review': this.calculateIntentScore(lowerPrompt, words, 'security-review'),
453
- 'learning': this.calculateIntentScore(lowerPrompt, words, 'learning')
687
+ learning: this.calculateIntentScore(lowerPrompt, words, 'learning'),
454
688
  };
455
689
  // Get secondary intents (top 2-3 after primary, with score > 10)
456
690
  const secondaryIntents = this.getSecondaryIntents(scores, basicAnalysis.primaryIntent);
@@ -459,11 +693,10 @@ export class IntentDetector {
459
693
  return {
460
694
  ...basicAnalysis,
461
695
  secondaryIntents,
462
- intentAmbiguity
696
+ intentAmbiguity,
463
697
  };
464
698
  }
465
699
  getSecondaryIntents(scores, primaryIntent) {
466
- const primaryScore = scores[primaryIntent];
467
700
  const totalScore = Object.values(scores).reduce((sum, s) => sum + s, 0);
468
701
  if (totalScore === 0)
469
702
  return [];
@@ -473,12 +706,11 @@ export class IntentDetector {
473
706
  .slice(0, 2)
474
707
  .map(([intent, score]) => ({
475
708
  intent: intent,
476
- confidence: Math.round((score / totalScore) * 100)
709
+ confidence: Math.round((score / totalScore) * 100),
477
710
  }));
478
711
  }
479
- calculateAmbiguity(scores, primaryIntent) {
480
- const sortedScores = Object.entries(scores)
481
- .sort(([, a], [, b]) => b - a);
712
+ calculateAmbiguity(scores, _primaryIntent) {
713
+ const sortedScores = Object.entries(scores).sort(([, a], [, b]) => b - a);
482
714
  if (sortedScores.length < 2)
483
715
  return 'low';
484
716
  const primaryScore = sortedScores[0][1];