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