clavix 3.5.0 → 4.0.0

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 (86) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -4
  3. package/dist/cli/commands/init.js +7 -0
  4. package/dist/cli/commands/update.js +12 -4
  5. package/dist/core/adapters/instructions-generator.d.ts +42 -0
  6. package/dist/core/adapters/instructions-generator.js +123 -0
  7. package/dist/core/git-manager.js +2 -1
  8. package/dist/core/intelligence/intent-detector.d.ts +18 -1
  9. package/dist/core/intelligence/intent-detector.js +196 -11
  10. package/dist/core/intelligence/pattern-library.js +20 -12
  11. package/dist/core/intelligence/patterns/alternative-phrasing-generator.d.ts +27 -0
  12. package/dist/core/intelligence/patterns/alternative-phrasing-generator.js +221 -0
  13. package/dist/core/intelligence/patterns/assumption-explicitizer.d.ts +28 -0
  14. package/dist/core/intelligence/patterns/assumption-explicitizer.js +273 -0
  15. package/dist/core/intelligence/patterns/context-precision.d.ts +30 -0
  16. package/dist/core/intelligence/patterns/context-precision.js +329 -0
  17. package/dist/core/intelligence/patterns/edge-case-identifier.d.ts +28 -0
  18. package/dist/core/intelligence/patterns/edge-case-identifier.js +251 -0
  19. package/dist/core/intelligence/patterns/prd-structure-enforcer.d.ts +21 -0
  20. package/dist/core/intelligence/patterns/prd-structure-enforcer.js +161 -0
  21. package/dist/core/intelligence/patterns/scope-definer.d.ts +24 -0
  22. package/dist/core/intelligence/patterns/scope-definer.js +212 -0
  23. package/dist/core/intelligence/patterns/step-decomposer.d.ts +29 -0
  24. package/dist/core/intelligence/patterns/step-decomposer.js +224 -0
  25. package/dist/core/intelligence/patterns/validation-checklist-creator.d.ts +28 -0
  26. package/dist/core/intelligence/patterns/validation-checklist-creator.js +198 -0
  27. package/dist/core/intelligence/quality-assessor.d.ts +9 -0
  28. package/dist/core/intelligence/quality-assessor.js +153 -18
  29. package/dist/core/intelligence/types.d.ts +24 -2
  30. package/dist/core/intelligence/universal-optimizer.d.ts +24 -1
  31. package/dist/core/intelligence/universal-optimizer.js +191 -14
  32. package/dist/core/template-assembler.d.ts +99 -0
  33. package/dist/core/template-assembler.js +249 -0
  34. package/dist/templates/agents/agents.md +172 -67
  35. package/dist/templates/agents/copilot-instructions.md +142 -87
  36. package/dist/templates/agents/octo.md +146 -289
  37. package/dist/templates/agents/warp.md +65 -1
  38. package/dist/templates/instructions/README 2.md +311 -0
  39. package/dist/templates/instructions/README.md +311 -0
  40. package/dist/templates/instructions/core/clavix-mode.md +275 -0
  41. package/dist/templates/instructions/core/file-operations.md +330 -0
  42. package/dist/templates/instructions/core/mode-enforcement.md +237 -0
  43. package/dist/templates/instructions/core/verification.md +377 -0
  44. package/dist/templates/instructions/core 2/clavix-mode.md +275 -0
  45. package/dist/templates/instructions/core 2/file-operations.md +330 -0
  46. package/dist/templates/instructions/core 2/verification.md +377 -0
  47. package/dist/templates/instructions/troubleshooting/jumped-to-implementation.md +234 -0
  48. package/dist/templates/instructions/troubleshooting/mode-confusion.md +402 -0
  49. package/dist/templates/instructions/troubleshooting/skipped-file-creation.md +385 -0
  50. package/dist/templates/instructions/troubleshooting 2/jumped-to-implementation.md +234 -0
  51. package/dist/templates/instructions/troubleshooting 2/mode-confusion.md +402 -0
  52. package/dist/templates/instructions/troubleshooting 2/skipped-file-creation.md +385 -0
  53. package/dist/templates/slash-commands/_canonical/deep.md +37 -0
  54. package/dist/templates/slash-commands/_canonical/execute.md +25 -0
  55. package/dist/templates/slash-commands/_canonical/fast.md +37 -0
  56. package/dist/templates/slash-commands/_canonical/implement.md +26 -0
  57. package/dist/templates/slash-commands/_canonical/plan.md +37 -0
  58. package/dist/templates/slash-commands/_canonical/prd.md +37 -0
  59. package/dist/templates/slash-commands/_canonical/start.md +77 -3
  60. package/dist/templates/slash-commands/_canonical/summarize.md +237 -24
  61. package/dist/templates/slash-commands/_canonical 2/archive.md +410 -0
  62. package/dist/templates/slash-commands/_canonical 2/deep.md +512 -0
  63. package/dist/templates/slash-commands/_canonical 2/execute.md +80 -0
  64. package/dist/templates/slash-commands/_canonical 2/fast.md +370 -0
  65. package/dist/templates/slash-commands/_canonical 2/implement.md +364 -0
  66. package/dist/templates/slash-commands/_canonical 2/plan.md +329 -0
  67. package/dist/templates/slash-commands/_canonical 2/prd.md +320 -0
  68. package/dist/templates/slash-commands/_canonical 2/prompts.md +97 -0
  69. package/dist/templates/slash-commands/_canonical 2/start.md +204 -0
  70. package/dist/templates/slash-commands/_canonical 2/summarize.md +395 -0
  71. package/dist/templates/slash-commands/_components/mode-headers/implementation-mode.md +21 -0
  72. package/dist/templates/slash-commands/_components/mode-headers/planning-mode.md +17 -0
  73. package/dist/templates/slash-commands/_components/mode-headers/self-correction.md +13 -0
  74. package/dist/templates/slash-commands/_components/sections/file-saving-protocol.md +47 -0
  75. package/dist/templates/slash-commands/_components/sections/intent-detection.md +24 -0
  76. package/dist/templates/slash-commands/_components/sections/quality-assessment.md +26 -0
  77. package/dist/templates/slash-commands/_components/sections/workflow-navigation.md +13 -0
  78. package/dist/templates/slash-commands/_components/troubleshooting/file-not-saved.md +20 -0
  79. package/dist/templates/slash-commands/_components/troubleshooting/mode-confusion.md +46 -0
  80. package/dist/templates/slash-commands/_components/troubleshooting/triage-escalation.md +26 -0
  81. package/dist/utils/file-system.d.ts +8 -0
  82. package/dist/utils/file-system.js +7 -0
  83. package/dist/utils/template-loader.js +25 -2
  84. package/package.json +12 -2
  85. package/dist/utils/provider-selector.d.ts +0 -8
  86. package/dist/utils/provider-selector.js +0 -60
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Bob5k
3
+ Copyright (c) 2025 Clavix
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -12,10 +12,10 @@
12
12
 
13
13
  | Version | Highlights | Details |
14
14
  | --- | --- | --- |
15
- | **v3.4.0** (Latest) | Provider categorization fixes | [Changelog](CHANGELOG.md#340---2025-11-24) |
16
- | **v3.3.1** | JSON5/JSON config bug fix | [Changelog](CHANGELOG.md#331---2025-11-23) |
17
- | **v3.3.0** | Provider management & interactive config | [Changelog](CHANGELOG.md#330---2025-11-23) |
18
- | **v3.1.0** | Clavix Intelligence™ brand evolution | [Changelog](CHANGELOG.md#310---2025-11-23) |
15
+ | **v3.6.1** (Latest) | Documentation hierarchy & verbosity reduction | [Changelog](CHANGELOG.md#361---2025-11-24) |
16
+ | **v3.6.0** | Enhanced generic connector instructions | [Changelog](CHANGELOG.md#360---2025-11-24) |
17
+ | **v3.5.0** | "Providers" "Integrations" terminology | [Changelog](CHANGELOG.md#350---2025-01-24) |
18
+ | **v3.4.0** | Provider categorization fixes | [Changelog](CHANGELOG.md#340---2025-11-24) |
19
19
 
20
20
  **Requirements:** Node.js ≥ 16.0.0 (ESM support required)
21
21
 
@@ -8,6 +8,7 @@ import { AgentsMdGenerator } from '../../core/adapters/agents-md-generator.js';
8
8
  import { OctoMdGenerator } from '../../core/adapters/octo-md-generator.js';
9
9
  import { WarpMdGenerator } from '../../core/adapters/warp-md-generator.js';
10
10
  import { CopilotInstructionsGenerator } from '../../core/adapters/copilot-instructions-generator.js';
11
+ import { InstructionsGenerator } from '../../core/adapters/instructions-generator.js';
11
12
  import { FileSystem } from '../../utils/file-system.js';
12
13
  import { DEFAULT_CONFIG } from '../../types/config.js';
13
14
  import { GeminiAdapter } from '../../core/adapters/gemini-adapter.js';
@@ -216,6 +217,12 @@ export default class Init extends Command {
216
217
  await this.injectDocumentation(adapter);
217
218
  }
218
219
  }
220
+ // Generate .clavix/instructions/ folder for generic integrations
221
+ if (InstructionsGenerator.needsGeneration(selectedIntegrations)) {
222
+ console.log(chalk.gray('\n📁 Generating .clavix/instructions/ reference folder...'));
223
+ await InstructionsGenerator.generate();
224
+ console.log(chalk.gray(' ✓ Created detailed workflow guides for generic integrations'));
225
+ }
219
226
  // Success message
220
227
  console.log(chalk.bold.green('\n✅ Clavix initialized successfully!\n'));
221
228
  console.log(chalk.gray('Next steps:'));
@@ -10,9 +10,10 @@ import { AgentManager } from '../../core/agent-manager.js';
10
10
  import { AgentsMdGenerator } from '../../core/adapters/agents-md-generator.js';
11
11
  import { OctoMdGenerator } from '../../core/adapters/octo-md-generator.js';
12
12
  import { WarpMdGenerator } from '../../core/adapters/warp-md-generator.js';
13
+ import { InstructionsGenerator } from '../../core/adapters/instructions-generator.js';
13
14
  import { collectLegacyCommandFiles } from '../../utils/legacy-command-cleanup.js';
14
15
  const __filename = fileURLToPath(import.meta.url);
15
- const __dirname = dirname(__filename);
16
+ const _dirname = dirname(__filename); // eslint-disable-line @typescript-eslint/no-unused-vars
16
17
  export default class Update extends Command {
17
18
  static description = 'Update managed blocks and slash commands';
18
19
  static examples = [
@@ -31,7 +32,7 @@ export default class Update extends Command {
31
32
  }),
32
33
  force: Flags.boolean({
33
34
  char: 'f',
34
- description: 'Force update even if files haven\'t changed',
35
+ description: "Force update even if files haven't changed",
35
36
  default: false,
36
37
  }),
37
38
  };
@@ -91,6 +92,13 @@ export default class Update extends Command {
91
92
  updatedCount += await this.updateCommands(adapter, flags.force);
92
93
  }
93
94
  }
95
+ // Update .clavix/instructions/ folder for generic integrations
96
+ if (updateDocs && InstructionsGenerator.needsGeneration(integrations)) {
97
+ this.log(chalk.gray('\n📁 Updating .clavix/instructions/ reference folder...'));
98
+ await InstructionsGenerator.generate();
99
+ this.log(chalk.gray(' ✓ Updated detailed workflow guides'));
100
+ updatedCount++;
101
+ }
94
102
  this.log('');
95
103
  if (updatedCount > 0) {
96
104
  this.log(chalk.green(`✅ Successfully updated ${updatedCount} file(s)`));
@@ -161,7 +169,7 @@ export default class Update extends Command {
161
169
  await adapter.generateCommands(templates);
162
170
  this.log(chalk.gray(` ✓ Generated ${templates.length} command(s)`));
163
171
  // Handle legacy commands (cleanup old naming patterns)
164
- const commandNames = templates.map(t => t.name);
172
+ const commandNames = templates.map((t) => t.name);
165
173
  const legacyRemoved = await this.handleLegacyCommands(adapter, commandNames, force);
166
174
  return removed + templates.length + legacyRemoved;
167
175
  }
@@ -231,7 +239,7 @@ clavix deep "Build a user auth system"
231
239
  clavix start
232
240
  \`\`\`
233
241
 
234
- Learn more: https://github.com/Bob5k/Clavix`;
242
+ Learn more: https://github.com/clavixdev/clavix`;
235
243
  }
236
244
  getClaudeContent() {
237
245
  return `## Clavix Integration
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Generator for .clavix/instructions/ reference folder
3
+ * Provides detailed workflow guides for generic integrations
4
+ */
5
+ export declare class InstructionsGenerator {
6
+ static readonly TARGET_DIR = ".clavix/instructions";
7
+ /**
8
+ * Generic integrations that need the instructions folder
9
+ */
10
+ static readonly GENERIC_INTEGRATIONS: string[];
11
+ /**
12
+ * Generate .clavix/instructions/ folder with all reference files
13
+ */
14
+ static generate(): Promise<void>;
15
+ /**
16
+ * Copy static instruction files (core/, troubleshooting/, README.md)
17
+ * Excludes workflows/ directory - that comes from canonical templates
18
+ */
19
+ private static copyStaticInstructions;
20
+ /**
21
+ * Copy ALL canonical templates to .clavix/instructions/workflows/
22
+ * This ensures generic integrations have access to complete workflow set
23
+ */
24
+ private static copyCanonicalWorkflows;
25
+ /**
26
+ * Recursively copy directory contents
27
+ */
28
+ private static copyDirectory;
29
+ /**
30
+ * Check if instructions folder exists
31
+ */
32
+ static exists(): Promise<boolean>;
33
+ /**
34
+ * Check if any generic integration is selected
35
+ */
36
+ static needsGeneration(selectedIntegrations: string[]): boolean;
37
+ /**
38
+ * Remove instructions folder
39
+ */
40
+ static remove(): Promise<void>;
41
+ }
42
+ //# sourceMappingURL=instructions-generator.d.ts.map
@@ -0,0 +1,123 @@
1
+ import { FileSystem } from '../../utils/file-system.js';
2
+ import * as path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import { dirname } from 'path';
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = dirname(__filename);
7
+ /**
8
+ * Generator for .clavix/instructions/ reference folder
9
+ * Provides detailed workflow guides for generic integrations
10
+ */
11
+ export class InstructionsGenerator {
12
+ static TARGET_DIR = '.clavix/instructions';
13
+ /**
14
+ * Generic integrations that need the instructions folder
15
+ */
16
+ static GENERIC_INTEGRATIONS = [
17
+ 'octo-md',
18
+ 'warp-md',
19
+ 'agents-md',
20
+ 'copilot-instructions'
21
+ ];
22
+ /**
23
+ * Generate .clavix/instructions/ folder with all reference files
24
+ */
25
+ static async generate() {
26
+ const staticInstructionsPath = path.join(__dirname, '../../templates/instructions');
27
+ // Check if static template exists
28
+ if (!(await FileSystem.exists(staticInstructionsPath))) {
29
+ throw new Error(`.clavix/instructions static files not found at ${staticInstructionsPath}`);
30
+ }
31
+ // Create target directory
32
+ await FileSystem.ensureDir(this.TARGET_DIR);
33
+ // Step 1: Copy static instruction files (core/, troubleshooting/, README.md)
34
+ // Note: This skips workflows/ directory if it exists
35
+ await this.copyStaticInstructions(staticInstructionsPath, this.TARGET_DIR);
36
+ // Step 2: Copy ALL canonical workflows → .clavix/instructions/workflows/
37
+ await this.copyCanonicalWorkflows();
38
+ }
39
+ /**
40
+ * Copy static instruction files (core/, troubleshooting/, README.md)
41
+ * Excludes workflows/ directory - that comes from canonical templates
42
+ */
43
+ static async copyStaticInstructions(src, dest) {
44
+ const entries = await FileSystem.readdir(src, { withFileTypes: true });
45
+ for (const entry of entries) {
46
+ // Skip workflows/ directory - it will be populated from canonical
47
+ if (entry.isDirectory() && entry.name === 'workflows') {
48
+ continue;
49
+ }
50
+ const srcPath = path.join(src, entry.name);
51
+ const destPath = path.join(dest, entry.name);
52
+ if (entry.isDirectory()) {
53
+ await FileSystem.ensureDir(destPath);
54
+ await this.copyDirectory(srcPath, destPath);
55
+ }
56
+ else {
57
+ const content = await FileSystem.readFile(srcPath);
58
+ await FileSystem.writeFileAtomic(destPath, content);
59
+ }
60
+ }
61
+ }
62
+ /**
63
+ * Copy ALL canonical templates to .clavix/instructions/workflows/
64
+ * This ensures generic integrations have access to complete workflow set
65
+ */
66
+ static async copyCanonicalWorkflows() {
67
+ const canonicalPath = path.join(__dirname, '../../templates/slash-commands/_canonical');
68
+ const workflowsTarget = path.join(this.TARGET_DIR, 'workflows');
69
+ if (!(await FileSystem.exists(canonicalPath))) {
70
+ throw new Error(`Canonical templates not found at ${canonicalPath}`);
71
+ }
72
+ // Create workflows directory
73
+ await FileSystem.ensureDir(workflowsTarget);
74
+ // Copy all .md files from canonical
75
+ const entries = await FileSystem.readdir(canonicalPath, { withFileTypes: true });
76
+ const mdFiles = entries.filter(f => f.isFile() && f.name.endsWith('.md'));
77
+ for (const file of mdFiles) {
78
+ const srcPath = path.join(canonicalPath, file.name);
79
+ const destPath = path.join(workflowsTarget, file.name);
80
+ const content = await FileSystem.readFile(srcPath);
81
+ await FileSystem.writeFileAtomic(destPath, content);
82
+ }
83
+ }
84
+ /**
85
+ * Recursively copy directory contents
86
+ */
87
+ static async copyDirectory(src, dest) {
88
+ const entries = await FileSystem.readdir(src, { withFileTypes: true });
89
+ for (const entry of entries) {
90
+ const srcPath = path.join(src, entry.name);
91
+ const destPath = path.join(dest, entry.name);
92
+ if (entry.isDirectory()) {
93
+ await FileSystem.ensureDir(destPath);
94
+ await this.copyDirectory(srcPath, destPath);
95
+ }
96
+ else {
97
+ const content = await FileSystem.readFile(srcPath);
98
+ await FileSystem.writeFileAtomic(destPath, content);
99
+ }
100
+ }
101
+ }
102
+ /**
103
+ * Check if instructions folder exists
104
+ */
105
+ static async exists() {
106
+ return await FileSystem.exists(this.TARGET_DIR);
107
+ }
108
+ /**
109
+ * Check if any generic integration is selected
110
+ */
111
+ static needsGeneration(selectedIntegrations) {
112
+ return selectedIntegrations.some(integration => this.GENERIC_INTEGRATIONS.includes(integration));
113
+ }
114
+ /**
115
+ * Remove instructions folder
116
+ */
117
+ static async remove() {
118
+ if (await this.exists()) {
119
+ await FileSystem.remove(this.TARGET_DIR);
120
+ }
121
+ }
122
+ }
123
+ //# sourceMappingURL=instructions-generator.js.map
@@ -111,7 +111,8 @@ export class GitManager {
111
111
  const errors = [];
112
112
  try {
113
113
  // Read tasks.md file
114
- const fs = await import('fs-extra');
114
+ const fsExtra = await import('fs-extra');
115
+ const fs = fsExtra.default || fsExtra;
115
116
  if (!(await fs.pathExists(tasksPath))) {
116
117
  errors.push(`Tasks file not found: ${tasksPath}`);
117
118
  return { valid: false, errors };
@@ -1,4 +1,4 @@
1
- import { IntentAnalysis } from './types.js';
1
+ import { IntentAnalysis, EnhancedIntentAnalysis } from './types.js';
2
2
  /**
3
3
  * Enhanced Intent Detector with weighted scoring and phrase-based detection
4
4
  * Target Accuracy: 95%+
@@ -9,11 +9,19 @@ export declare class IntentDetector {
9
9
  private readonly STRONG_DEBUGGING_KEYWORDS;
10
10
  private readonly STRONG_DOCUMENTATION_KEYWORDS;
11
11
  private readonly STRONG_REFINEMENT_KEYWORDS;
12
+ private readonly STRONG_TESTING_KEYWORDS;
13
+ private readonly STRONG_MIGRATION_KEYWORDS;
14
+ private readonly STRONG_SECURITY_KEYWORDS;
15
+ private readonly STRONG_LEARNING_KEYWORDS;
12
16
  private readonly CODE_KEYWORDS;
13
17
  private readonly PLANNING_KEYWORDS;
14
18
  private readonly REFINEMENT_KEYWORDS;
15
19
  private readonly DEBUGGING_KEYWORDS;
16
20
  private readonly DOCUMENTATION_KEYWORDS;
21
+ private readonly TESTING_KEYWORDS;
22
+ private readonly MIGRATION_KEYWORDS;
23
+ private readonly SECURITY_KEYWORDS;
24
+ private readonly LEARNING_KEYWORDS;
17
25
  private readonly WEAK_CODE_KEYWORDS;
18
26
  private readonly NEGATION_WORDS;
19
27
  analyze(prompt: string): IntentAnalysis;
@@ -21,6 +29,9 @@ export declare class IntentDetector {
21
29
  private getKeywordsForIntent;
22
30
  private applyNegation;
23
31
  private getContextBonus;
32
+ private hasTestingFrameworkTerms;
33
+ private hasSecurityTerms;
34
+ private hasMigrationPatterns;
24
35
  private selectPrimaryIntent;
25
36
  private calculateConfidence;
26
37
  private hasCodeContext;
@@ -29,5 +40,11 @@ export declare class IntentDetector {
29
40
  private isOpenEnded;
30
41
  private needsStructure;
31
42
  private suggestMode;
43
+ /**
44
+ * v4.0: Enhanced analysis with secondary intents and ambiguity detection
45
+ */
46
+ analyzeEnhanced(prompt: string): EnhancedIntentAnalysis;
47
+ private getSecondaryIntents;
48
+ private calculateAmbiguity;
32
49
  }
33
50
  //# sourceMappingURL=intent-detector.d.ts.map
@@ -11,7 +11,10 @@ export class IntentDetector {
11
11
  STRONG_PLANNING_KEYWORDS = [
12
12
  'how should i', 'what\'s the best way', 'pros and cons', 'architecture for',
13
13
  'design pattern', 'system design', 'should i use', 'help me choose',
14
- 'design the database', 'plan the', 'requirements document'
14
+ 'design the database', 'plan the', 'requirements document',
15
+ // v4.0: Spec-driven development keywords
16
+ 'write spec', 'create spec', 'spec document', 'functional spec', 'technical spec',
17
+ 'design spec', 'specification for', 'write specification'
15
18
  ];
16
19
  STRONG_DEBUGGING_KEYWORDS = [
17
20
  'fix error', 'debug issue', 'doesn\'t work', 'throws error', 'not working',
@@ -29,6 +32,30 @@ export class IntentDetector {
29
32
  'clean up code', 'refactor this', 'improve efficiency', 'make this component',
30
33
  'make it more', 'enhance the', 'update the styling', 'more reusable', 'more modern'
31
34
  ];
35
+ // v4.0: New intent - Testing
36
+ 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'
40
+ ];
41
+ // v4.0: New intent - Migration
42
+ 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'
46
+ ];
47
+ // v4.0: New intent - Security Review
48
+ 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'
52
+ ];
53
+ // v4.0: New intent - Learning
54
+ 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'
58
+ ];
32
59
  // Medium indicators (10 points)
33
60
  CODE_KEYWORDS = [
34
61
  'function', 'class', 'component', 'api', 'endpoint', 'database',
@@ -36,7 +63,9 @@ export class IntentDetector {
36
63
  ];
37
64
  PLANNING_KEYWORDS = [
38
65
  'plan', 'design', 'architect', 'strategy', 'approach', 'structure',
39
- 'organize', 'layout', 'workflow'
66
+ 'organize', 'layout', 'workflow',
67
+ // v4.0: Spec-driven development keywords
68
+ 'spec', 'specification', 'requirements', 'blueprint', 'outline'
40
69
  ];
41
70
  REFINEMENT_KEYWORDS = [
42
71
  'improve', 'optimize', 'refactor', 'enhance', 'better', 'faster',
@@ -50,6 +79,23 @@ export class IntentDetector {
50
79
  'explain', 'document', 'describe', 'understand',
51
80
  'clarify', 'comment', 'documentation', 'guide', 'tutorial'
52
81
  ];
82
+ // v4.0: Medium keywords for new intents
83
+ TESTING_KEYWORDS = [
84
+ 'test', 'coverage', 'jest', 'pytest', 'mocha', 'vitest', 'mock',
85
+ 'assertion', 'expect', 'describe', 'spec', 'fixture', 'stub', 'spy'
86
+ ];
87
+ MIGRATION_KEYWORDS = [
88
+ 'migrate', 'migration', 'upgrade', 'port', 'convert', 'transition',
89
+ 'legacy', 'deprecated', 'version', 'breaking change', 'compatibility'
90
+ ];
91
+ SECURITY_KEYWORDS = [
92
+ 'security', 'vulnerability', 'xss', 'csrf', 'injection', 'sanitize',
93
+ 'escape', 'owasp', 'cve', 'exploit', 'attack', 'threat', 'risk'
94
+ ];
95
+ LEARNING_KEYWORDS = [
96
+ 'understand', 'learn', 'concept', 'basics', 'fundamentals', 'tutorial',
97
+ 'introduction', 'beginner', 'overview', 'theory', 'principle'
98
+ ];
53
99
  // Weak indicators (5 points)
54
100
  WEAK_CODE_KEYWORDS = [
55
101
  'react', 'vue', 'angular', 'python', 'javascript', 'typescript',
@@ -69,7 +115,12 @@ export class IntentDetector {
69
115
  'refinement': this.calculateIntentScore(lowerPrompt, words, 'refinement'),
70
116
  'debugging': this.calculateIntentScore(lowerPrompt, words, 'debugging'),
71
117
  'documentation': this.calculateIntentScore(lowerPrompt, words, 'documentation'),
72
- 'prd-generation': 0 // PRD is explicit command, not inferred
118
+ 'prd-generation': 0, // PRD is explicit command, not inferred
119
+ // v4.0: New intents
120
+ 'testing': this.calculateIntentScore(lowerPrompt, words, 'testing'),
121
+ 'migration': this.calculateIntentScore(lowerPrompt, words, 'migration'),
122
+ 'security-review': this.calculateIntentScore(lowerPrompt, words, 'security-review'),
123
+ 'learning': this.calculateIntentScore(lowerPrompt, words, 'learning')
73
124
  };
74
125
  // Apply intent priority rules
75
126
  const primaryIntent = this.selectPrimaryIntent(scores, lowerPrompt);
@@ -149,6 +200,31 @@ export class IntentDetector {
149
200
  medium: this.REFINEMENT_KEYWORDS,
150
201
  weak: []
151
202
  };
203
+ // v4.0: New intents
204
+ case 'testing':
205
+ return {
206
+ strong: this.STRONG_TESTING_KEYWORDS,
207
+ medium: this.TESTING_KEYWORDS,
208
+ weak: []
209
+ };
210
+ case 'migration':
211
+ return {
212
+ strong: this.STRONG_MIGRATION_KEYWORDS,
213
+ medium: this.MIGRATION_KEYWORDS,
214
+ weak: []
215
+ };
216
+ case 'security-review':
217
+ return {
218
+ strong: this.STRONG_SECURITY_KEYWORDS,
219
+ medium: this.SECURITY_KEYWORDS,
220
+ weak: []
221
+ };
222
+ case 'learning':
223
+ return {
224
+ strong: this.STRONG_LEARNING_KEYWORDS,
225
+ medium: this.LEARNING_KEYWORDS,
226
+ weak: []
227
+ };
152
228
  default:
153
229
  return { strong: [], medium: [], weak: [] };
154
230
  }
@@ -169,12 +245,12 @@ export class IntentDetector {
169
245
  }
170
246
  getContextBonus(prompt, intent) {
171
247
  let bonus = 0;
172
- // Code snippet bonus for debugging/refinement
173
- if ((intent === 'debugging' || intent === 'refinement') && this.hasCodeContext(prompt)) {
248
+ // Code snippet bonus for debugging/refinement/testing
249
+ if ((intent === 'debugging' || intent === 'refinement' || intent === 'testing') && this.hasCodeContext(prompt)) {
174
250
  bonus += 15;
175
251
  }
176
- // Question mark bonus for planning/documentation
177
- if ((intent === 'planning' || intent === 'documentation') && prompt.includes('?')) {
252
+ // Question mark bonus for planning/documentation/learning
253
+ if ((intent === 'planning' || intent === 'documentation' || intent === 'learning') && prompt.includes('?')) {
178
254
  bonus += 10;
179
255
  }
180
256
  // Technical terms bonus for code-generation
@@ -185,25 +261,74 @@ export class IntentDetector {
185
261
  if (intent === 'refinement' && this.hasPerformanceTerms(prompt)) {
186
262
  bonus += 10;
187
263
  }
264
+ // v4.0: Context bonuses for new intents
265
+ // Testing framework mentions bonus
266
+ if (intent === 'testing' && this.hasTestingFrameworkTerms(prompt)) {
267
+ bonus += 10;
268
+ }
269
+ // Security terms bonus for security-review
270
+ if (intent === 'security-review' && this.hasSecurityTerms(prompt)) {
271
+ bonus += 15;
272
+ }
273
+ // Migration version patterns bonus
274
+ if (intent === 'migration' && this.hasMigrationPatterns(prompt)) {
275
+ bonus += 15;
276
+ }
188
277
  return bonus;
189
278
  }
279
+ // v4.0: Helper methods for new intent bonuses
280
+ hasTestingFrameworkTerms(prompt) {
281
+ const terms = ['jest', 'mocha', 'pytest', 'vitest', 'cypress', 'playwright', 'testing-library'];
282
+ return terms.some(term => prompt.includes(term));
283
+ }
284
+ hasSecurityTerms(prompt) {
285
+ const terms = ['owasp', 'cve', 'vulnerability', 'exploit', 'injection', 'xss', 'csrf'];
286
+ return terms.some(term => prompt.includes(term));
287
+ }
288
+ hasMigrationPatterns(prompt) {
289
+ // Check for version patterns like "v1 to v2", "17 to 18", "2.x to 3.x"
290
+ const versionPattern = /\d+\.?\d*\s*(to|->|=>)\s*\d+\.?\d*/i;
291
+ const versionWords = /from\s+version|to\s+version|upgrade.*\d/i;
292
+ return versionPattern.test(prompt) || versionWords.test(prompt);
293
+ }
190
294
  selectPrimaryIntent(scores, prompt) {
191
295
  // Priority 1: Debugging (if strong indicators present)
192
296
  if (scores.debugging >= 20 && (prompt.includes('error') || prompt.includes('bug') || prompt.includes('fix') ||
193
297
  prompt.includes('debug') || prompt.includes('issue') || prompt.includes('resolve'))) {
194
298
  return 'debugging';
195
299
  }
196
- // Priority 2: Documentation (if explanation requested or write documentation)
300
+ // 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'))) {
303
+ return 'security-review';
304
+ }
305
+ // 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'))) {
308
+ return 'testing';
309
+ }
310
+ // 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))) {
313
+ return 'migration';
314
+ }
315
+ // Priority 5: Documentation (if explanation requested or write documentation)
197
316
  if (scores.documentation >= 20 && (prompt.includes('explain') || prompt.includes('how does') ||
198
317
  prompt.includes('documentation') || (prompt.includes('write') && prompt.includes('document')))) {
199
318
  return 'documentation';
200
319
  }
201
- // Priority 3: Planning (if architecture/design question)
320
+ // 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'))) {
323
+ return 'learning';
324
+ }
325
+ // Priority 7: Planning (if architecture/design question or spec-driven)
202
326
  if (scores.planning >= 20 && (prompt.includes('how should') || prompt.includes('architecture') ||
203
- prompt.includes('what is the best'))) {
327
+ prompt.includes('what is the best') || prompt.includes('specification') ||
328
+ (prompt.includes('spec') && !prompt.includes('test')))) {
204
329
  return 'planning';
205
330
  }
206
- // Priority 4: Refinement (if improvement requested)
331
+ // Priority 8: Refinement (if improvement requested)
207
332
  if (scores.refinement >= 15 && (prompt.includes('improve') || prompt.includes('optimize') ||
208
333
  prompt.includes('enhance') || prompt.includes('make') || prompt.includes('refactor'))) {
209
334
  return 'refinement';
@@ -307,5 +432,65 @@ export class IntentDetector {
307
432
  }
308
433
  return 'fast';
309
434
  }
435
+ /**
436
+ * v4.0: Enhanced analysis with secondary intents and ambiguity detection
437
+ */
438
+ analyzeEnhanced(prompt) {
439
+ const basicAnalysis = this.analyze(prompt);
440
+ const lowerPrompt = prompt.toLowerCase();
441
+ const words = lowerPrompt.split(/\s+/);
442
+ // Calculate all scores for secondary intent detection
443
+ const scores = {
444
+ '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'),
449
+ 'prd-generation': 0,
450
+ 'testing': this.calculateIntentScore(lowerPrompt, words, 'testing'),
451
+ 'migration': this.calculateIntentScore(lowerPrompt, words, 'migration'),
452
+ 'security-review': this.calculateIntentScore(lowerPrompt, words, 'security-review'),
453
+ 'learning': this.calculateIntentScore(lowerPrompt, words, 'learning')
454
+ };
455
+ // Get secondary intents (top 2-3 after primary, with score > 10)
456
+ const secondaryIntents = this.getSecondaryIntents(scores, basicAnalysis.primaryIntent);
457
+ // Calculate intent ambiguity
458
+ const intentAmbiguity = this.calculateAmbiguity(scores, basicAnalysis.primaryIntent);
459
+ return {
460
+ ...basicAnalysis,
461
+ secondaryIntents,
462
+ intentAmbiguity
463
+ };
464
+ }
465
+ getSecondaryIntents(scores, primaryIntent) {
466
+ const primaryScore = scores[primaryIntent];
467
+ const totalScore = Object.values(scores).reduce((sum, s) => sum + s, 0);
468
+ if (totalScore === 0)
469
+ return [];
470
+ return Object.entries(scores)
471
+ .filter(([intent, score]) => intent !== primaryIntent && score > 10)
472
+ .sort(([, a], [, b]) => b - a)
473
+ .slice(0, 2)
474
+ .map(([intent, score]) => ({
475
+ intent: intent,
476
+ confidence: Math.round((score / totalScore) * 100)
477
+ }));
478
+ }
479
+ calculateAmbiguity(scores, primaryIntent) {
480
+ const sortedScores = Object.entries(scores)
481
+ .sort(([, a], [, b]) => b - a);
482
+ if (sortedScores.length < 2)
483
+ return 'low';
484
+ const primaryScore = sortedScores[0][1];
485
+ const secondaryScore = sortedScores[1][1];
486
+ if (primaryScore === 0)
487
+ return 'high';
488
+ const ratio = secondaryScore / primaryScore;
489
+ if (ratio > 0.8)
490
+ return 'high'; // Secondary is 80%+ of primary
491
+ if (ratio > 0.5)
492
+ return 'medium'; // Secondary is 50-80% of primary
493
+ return 'low'; // Clear primary intent
494
+ }
310
495
  }
311
496
  //# sourceMappingURL=intent-detector.js.map
@@ -4,6 +4,16 @@ import { TechnicalContextEnricher } from './patterns/technical-context-enricher.
4
4
  import { StructureOrganizer } from './patterns/structure-organizer.js';
5
5
  import { CompletenessValidator } from './patterns/completeness-validator.js';
6
6
  import { ActionabilityEnhancer } from './patterns/actionability-enhancer.js';
7
+ // v4.0 Deep mode patterns
8
+ import { AlternativePhrasingGenerator } from './patterns/alternative-phrasing-generator.js';
9
+ import { EdgeCaseIdentifier } from './patterns/edge-case-identifier.js';
10
+ import { ValidationChecklistCreator } from './patterns/validation-checklist-creator.js';
11
+ import { AssumptionExplicitizer } from './patterns/assumption-explicitizer.js';
12
+ import { ScopeDefiner } from './patterns/scope-definer.js';
13
+ import { PRDStructureEnforcer } from './patterns/prd-structure-enforcer.js';
14
+ // v4.0 Both mode patterns
15
+ import { StepDecomposer } from './patterns/step-decomposer.js';
16
+ import { ContextPrecisionBooster } from './patterns/context-precision.js';
7
17
  export class PatternLibrary {
8
18
  patterns = new Map();
9
19
  constructor() {
@@ -17,18 +27,16 @@ export class PatternLibrary {
17
27
  this.register(new StructureOrganizer()); // HIGH - Reorder logically
18
28
  this.register(new CompletenessValidator()); // MEDIUM - Check missing elements
19
29
  this.register(new ActionabilityEnhancer()); // HIGH - Vague to specific
20
- // TODO: Register additional patterns for deep mode (future enhancement)
21
- // Deep mode exclusive:
22
- // - AlternativePhrasingGenerator
23
- // - StructureVariationGenerator
24
- // - EdgeCaseIdentifier
25
- // - ValidationChecklistCreator
26
- // - AssumptionExplicitizer
27
- // - ScopeDefiner
28
- // - StepByStepDecomposer
29
- // - TemplatePatternApplier
30
- // - ReflectionPrompter
31
- // - ContextPrecisionBooster
30
+ // v4.0 Deep mode patterns
31
+ this.register(new AlternativePhrasingGenerator()); // P5 - Generate alternative structures
32
+ this.register(new EdgeCaseIdentifier()); // P4 - Identify edge cases by domain
33
+ this.register(new ValidationChecklistCreator()); // P3 - Create validation checklists
34
+ this.register(new AssumptionExplicitizer()); // P6 - Make implicit assumptions explicit
35
+ this.register(new ScopeDefiner()); // P5 - Add scope boundaries
36
+ this.register(new PRDStructureEnforcer()); // P9 - Ensure PRD completeness
37
+ // v4.0 Both mode patterns (fast & deep)
38
+ this.register(new StepDecomposer()); // P7 - Break complex prompts into steps
39
+ this.register(new ContextPrecisionBooster()); // P8 - Add precise context when missing
32
40
  }
33
41
  /**
34
42
  * Register a new pattern