clavix 4.4.0 → 4.5.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.
- package/dist/core/adapters/instructions-generator.d.ts +2 -1
- package/dist/core/adapters/instructions-generator.js +21 -8
- package/dist/core/intelligence/confidence-calculator.d.ts +93 -0
- package/dist/core/intelligence/confidence-calculator.js +124 -0
- package/dist/core/intelligence/index.d.ts +1 -0
- package/dist/core/intelligence/index.js +2 -0
- package/dist/core/intelligence/intent-detector.js +10 -8
- package/dist/core/intelligence/pattern-library.d.ts +34 -12
- package/dist/core/intelligence/pattern-library.js +120 -85
- package/dist/core/intelligence/patterns/actionability-enhancer.d.ts +10 -10
- package/dist/core/intelligence/patterns/actionability-enhancer.js +31 -6
- package/dist/core/intelligence/patterns/alternative-phrasing-generator.d.ts +10 -8
- package/dist/core/intelligence/patterns/alternative-phrasing-generator.js +21 -3
- package/dist/core/intelligence/patterns/ambiguity-detector.d.ts +10 -8
- package/dist/core/intelligence/patterns/ambiguity-detector.js +31 -3
- package/dist/core/intelligence/patterns/assumption-explicitizer.d.ts +10 -8
- package/dist/core/intelligence/patterns/assumption-explicitizer.js +26 -3
- package/dist/core/intelligence/patterns/base-pattern.d.ts +166 -8
- package/dist/core/intelligence/patterns/base-pattern.js +64 -4
- package/dist/core/intelligence/patterns/completeness-validator.d.ts +10 -10
- package/dist/core/intelligence/patterns/completeness-validator.js +26 -5
- package/dist/core/intelligence/patterns/conciseness-filter.d.ts +15 -7
- package/dist/core/intelligence/patterns/conciseness-filter.js +36 -4
- package/dist/core/intelligence/patterns/context-precision.d.ts +10 -8
- package/dist/core/intelligence/patterns/context-precision.js +28 -5
- package/dist/core/intelligence/patterns/conversation-summarizer.d.ts +11 -9
- package/dist/core/intelligence/patterns/conversation-summarizer.js +40 -16
- package/dist/core/intelligence/patterns/dependency-identifier.d.ts +11 -9
- package/dist/core/intelligence/patterns/dependency-identifier.js +21 -4
- package/dist/core/intelligence/patterns/domain-context-enricher.d.ts +10 -8
- package/dist/core/intelligence/patterns/domain-context-enricher.js +27 -3
- package/dist/core/intelligence/patterns/edge-case-identifier.d.ts +10 -8
- package/dist/core/intelligence/patterns/edge-case-identifier.js +21 -3
- package/dist/core/intelligence/patterns/error-tolerance-enhancer.d.ts +10 -8
- package/dist/core/intelligence/patterns/error-tolerance-enhancer.js +22 -4
- package/dist/core/intelligence/patterns/implicit-requirement-extractor.d.ts +11 -9
- package/dist/core/intelligence/patterns/implicit-requirement-extractor.js +27 -4
- package/dist/core/intelligence/patterns/objective-clarifier.d.ts +15 -7
- package/dist/core/intelligence/patterns/objective-clarifier.js +46 -17
- package/dist/core/intelligence/patterns/output-format-enforcer.d.ts +10 -8
- package/dist/core/intelligence/patterns/output-format-enforcer.js +20 -3
- package/dist/core/intelligence/patterns/prd-structure-enforcer.d.ts +10 -8
- package/dist/core/intelligence/patterns/prd-structure-enforcer.js +25 -3
- package/dist/core/intelligence/patterns/prerequisite-identifier.d.ts +10 -8
- package/dist/core/intelligence/patterns/prerequisite-identifier.js +28 -4
- package/dist/core/intelligence/patterns/requirement-prioritizer.d.ts +11 -9
- package/dist/core/intelligence/patterns/requirement-prioritizer.js +21 -4
- package/dist/core/intelligence/patterns/scope-definer.d.ts +10 -8
- package/dist/core/intelligence/patterns/scope-definer.js +27 -3
- package/dist/core/intelligence/patterns/step-decomposer.d.ts +10 -8
- package/dist/core/intelligence/patterns/step-decomposer.js +21 -3
- package/dist/core/intelligence/patterns/structure-organizer.d.ts +10 -10
- package/dist/core/intelligence/patterns/structure-organizer.js +25 -5
- package/dist/core/intelligence/patterns/success-criteria-enforcer.d.ts +10 -8
- package/dist/core/intelligence/patterns/success-criteria-enforcer.js +20 -3
- package/dist/core/intelligence/patterns/success-metrics-enforcer.d.ts +11 -9
- package/dist/core/intelligence/patterns/success-metrics-enforcer.js +27 -4
- package/dist/core/intelligence/patterns/technical-context-enricher.d.ts +16 -7
- package/dist/core/intelligence/patterns/technical-context-enricher.js +71 -38
- package/dist/core/intelligence/patterns/topic-coherence-analyzer.d.ts +11 -9
- package/dist/core/intelligence/patterns/topic-coherence-analyzer.js +22 -4
- package/dist/core/intelligence/patterns/user-persona-enricher.d.ts +11 -9
- package/dist/core/intelligence/patterns/user-persona-enricher.js +21 -4
- package/dist/core/intelligence/patterns/validation-checklist-creator.d.ts +11 -8
- package/dist/core/intelligence/patterns/validation-checklist-creator.js +31 -3
- package/dist/templates/slash-commands/_components/references/intent-types.md +3 -1
- package/dist/templates/slash-commands/_components/sections/pattern-visibility.md +9 -9
- package/package.json +1 -1
|
@@ -19,7 +19,8 @@ export declare class InstructionsGenerator {
|
|
|
19
19
|
private static copyStaticInstructions;
|
|
20
20
|
/**
|
|
21
21
|
* Copy ALL canonical templates to .clavix/instructions/workflows/
|
|
22
|
-
* This ensures generic integrations have access to complete workflow set
|
|
22
|
+
* This ensures generic integrations have access to complete workflow set.
|
|
23
|
+
* v4.5: Uses TemplateAssembler to resolve {{INCLUDE:}} markers.
|
|
23
24
|
*/
|
|
24
25
|
private static copyCanonicalWorkflows;
|
|
25
26
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FileSystem } from '../../utils/file-system.js';
|
|
2
|
+
import { TemplateAssembler } from '../template-assembler.js';
|
|
2
3
|
import * as path from 'path';
|
|
3
4
|
import { fileURLToPath } from 'url';
|
|
4
5
|
import { dirname } from 'path';
|
|
@@ -17,7 +18,7 @@ export class InstructionsGenerator {
|
|
|
17
18
|
'octo-md',
|
|
18
19
|
'warp-md',
|
|
19
20
|
'agents-md',
|
|
20
|
-
'copilot-instructions'
|
|
21
|
+
'copilot-instructions',
|
|
21
22
|
];
|
|
22
23
|
/**
|
|
23
24
|
* Generate .clavix/instructions/ folder with all reference files
|
|
@@ -61,7 +62,8 @@ export class InstructionsGenerator {
|
|
|
61
62
|
}
|
|
62
63
|
/**
|
|
63
64
|
* Copy ALL canonical templates to .clavix/instructions/workflows/
|
|
64
|
-
* This ensures generic integrations have access to complete workflow set
|
|
65
|
+
* This ensures generic integrations have access to complete workflow set.
|
|
66
|
+
* v4.5: Uses TemplateAssembler to resolve {{INCLUDE:}} markers.
|
|
65
67
|
*/
|
|
66
68
|
static async copyCanonicalWorkflows() {
|
|
67
69
|
const canonicalPath = path.join(__dirname, '../../templates/slash-commands/_canonical');
|
|
@@ -71,14 +73,25 @@ export class InstructionsGenerator {
|
|
|
71
73
|
}
|
|
72
74
|
// Create workflows directory
|
|
73
75
|
await FileSystem.ensureDir(workflowsTarget);
|
|
74
|
-
//
|
|
76
|
+
// Create TemplateAssembler for include resolution
|
|
77
|
+
const templatesBasePath = path.join(__dirname, '../../templates');
|
|
78
|
+
const assembler = new TemplateAssembler(templatesBasePath);
|
|
79
|
+
// Copy all .md files from canonical, resolving includes
|
|
75
80
|
const entries = await FileSystem.readdir(canonicalPath, { withFileTypes: true });
|
|
76
|
-
const mdFiles = entries.filter(f => f.isFile() && f.name.endsWith('.md'));
|
|
81
|
+
const mdFiles = entries.filter((f) => f.isFile() && f.name.endsWith('.md'));
|
|
77
82
|
for (const file of mdFiles) {
|
|
78
|
-
const srcPath = path.join(canonicalPath, file.name);
|
|
79
83
|
const destPath = path.join(workflowsTarget, file.name);
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
try {
|
|
85
|
+
// v4.5: Use TemplateAssembler to resolve {{INCLUDE:}} markers
|
|
86
|
+
const result = await assembler.assembleTemplate(file.name);
|
|
87
|
+
await FileSystem.writeFileAtomic(destPath, result.content);
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
// Fallback: copy without include resolution if assembly fails
|
|
91
|
+
const srcPath = path.join(canonicalPath, file.name);
|
|
92
|
+
const content = await FileSystem.readFile(srcPath);
|
|
93
|
+
await FileSystem.writeFileAtomic(destPath, content);
|
|
94
|
+
}
|
|
82
95
|
}
|
|
83
96
|
}
|
|
84
97
|
/**
|
|
@@ -109,7 +122,7 @@ export class InstructionsGenerator {
|
|
|
109
122
|
* Check if any generic integration is selected
|
|
110
123
|
*/
|
|
111
124
|
static needsGeneration(selectedIntegrations) {
|
|
112
|
-
return selectedIntegrations.some(integration => this.GENERIC_INTEGRATIONS.includes(integration));
|
|
125
|
+
return selectedIntegrations.some((integration) => this.GENERIC_INTEGRATIONS.includes(integration));
|
|
113
126
|
}
|
|
114
127
|
/**
|
|
115
128
|
* Remove instructions folder
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v4.5 Confidence Calculator Utilities
|
|
3
|
+
*
|
|
4
|
+
* Shared utilities for calculating confidence scores across the intelligence system.
|
|
5
|
+
* Provides type-safe confidence values and common calculation patterns.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Confidence level as a percentage (0-100).
|
|
9
|
+
* - 0-49: Low confidence
|
|
10
|
+
* - 50-69: Medium confidence
|
|
11
|
+
* - 70-84: High confidence
|
|
12
|
+
* - 85-100: Very high confidence
|
|
13
|
+
*/
|
|
14
|
+
export type ConfidenceLevel = number;
|
|
15
|
+
/**
|
|
16
|
+
* Confidence category for display purposes
|
|
17
|
+
*/
|
|
18
|
+
export type ConfidenceCategory = 'low' | 'medium' | 'high' | 'very-high';
|
|
19
|
+
/**
|
|
20
|
+
* Confidence result with category and percentage
|
|
21
|
+
*/
|
|
22
|
+
export interface ConfidenceResult {
|
|
23
|
+
percentage: ConfidenceLevel;
|
|
24
|
+
category: ConfidenceCategory;
|
|
25
|
+
}
|
|
26
|
+
export declare const CONFIDENCE_THRESHOLDS: {
|
|
27
|
+
readonly LOW_MAX: 49;
|
|
28
|
+
readonly MEDIUM_MAX: 69;
|
|
29
|
+
readonly HIGH_MAX: 84;
|
|
30
|
+
readonly VERY_HIGH_MIN: 85;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Clamp a confidence value to valid range (0-100)
|
|
34
|
+
*/
|
|
35
|
+
export declare function clampConfidence(value: number): ConfidenceLevel;
|
|
36
|
+
/**
|
|
37
|
+
* Get confidence category from percentage
|
|
38
|
+
*/
|
|
39
|
+
export declare function getConfidenceCategory(percentage: ConfidenceLevel): ConfidenceCategory;
|
|
40
|
+
/**
|
|
41
|
+
* Create a confidence result from a percentage
|
|
42
|
+
*/
|
|
43
|
+
export declare function createConfidenceResult(percentage: number): ConfidenceResult;
|
|
44
|
+
/**
|
|
45
|
+
* Calculate additive confidence based on presence of elements.
|
|
46
|
+
* Common pattern: base + bonus for each element present.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* calculateAdditiveConfidence(50, [
|
|
50
|
+
* [hasRequirements, 20],
|
|
51
|
+
* [hasGoals, 15],
|
|
52
|
+
* [hasConstraints, 15],
|
|
53
|
+
* ]);
|
|
54
|
+
*/
|
|
55
|
+
export declare function calculateAdditiveConfidence(baseConfidence: number, bonuses: Array<[boolean, number]>): ConfidenceLevel;
|
|
56
|
+
/**
|
|
57
|
+
* Calculate ratio-based confidence.
|
|
58
|
+
* Common pattern: primary score as percentage of total score.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* calculateRatioConfidence(primaryScore, totalScore);
|
|
62
|
+
*/
|
|
63
|
+
export declare function calculateRatioConfidence(primaryScore: number, totalScore: number, options?: {
|
|
64
|
+
minConfidence?: number;
|
|
65
|
+
fallbackConfidence?: number;
|
|
66
|
+
}): ConfidenceLevel;
|
|
67
|
+
/**
|
|
68
|
+
* Apply confidence penalty when competing scores are close.
|
|
69
|
+
* Common pattern: reduce confidence when there's ambiguity.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* applyCompetitionPenalty(confidence, primaryScore, secondaryScore, {
|
|
73
|
+
* threshold: 0.15,
|
|
74
|
+
* penalty: 15,
|
|
75
|
+
* minConfidence: 60,
|
|
76
|
+
* });
|
|
77
|
+
*/
|
|
78
|
+
export declare function applyCompetitionPenalty(confidence: number, primaryScore: number, secondaryScore: number, options?: {
|
|
79
|
+
threshold?: number;
|
|
80
|
+
penalty?: number;
|
|
81
|
+
minConfidence?: number;
|
|
82
|
+
}): ConfidenceLevel;
|
|
83
|
+
/**
|
|
84
|
+
* Calculate weighted average confidence from multiple sources.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* calculateWeightedConfidence([
|
|
88
|
+
* [intentConfidence, 0.6],
|
|
89
|
+
* [qualityConfidence, 0.4],
|
|
90
|
+
* ]);
|
|
91
|
+
*/
|
|
92
|
+
export declare function calculateWeightedConfidence(scores: Array<[number, number]>): ConfidenceLevel;
|
|
93
|
+
//# sourceMappingURL=confidence-calculator.d.ts.map
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v4.5 Confidence Calculator Utilities
|
|
3
|
+
*
|
|
4
|
+
* Shared utilities for calculating confidence scores across the intelligence system.
|
|
5
|
+
* Provides type-safe confidence values and common calculation patterns.
|
|
6
|
+
*/
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Thresholds
|
|
9
|
+
// ============================================================================
|
|
10
|
+
export const CONFIDENCE_THRESHOLDS = {
|
|
11
|
+
LOW_MAX: 49,
|
|
12
|
+
MEDIUM_MAX: 69,
|
|
13
|
+
HIGH_MAX: 84,
|
|
14
|
+
VERY_HIGH_MIN: 85,
|
|
15
|
+
};
|
|
16
|
+
// ============================================================================
|
|
17
|
+
// Utility Functions
|
|
18
|
+
// ============================================================================
|
|
19
|
+
/**
|
|
20
|
+
* Clamp a confidence value to valid range (0-100)
|
|
21
|
+
*/
|
|
22
|
+
export function clampConfidence(value) {
|
|
23
|
+
return Math.min(100, Math.max(0, Math.round(value)));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get confidence category from percentage
|
|
27
|
+
*/
|
|
28
|
+
export function getConfidenceCategory(percentage) {
|
|
29
|
+
if (percentage <= CONFIDENCE_THRESHOLDS.LOW_MAX)
|
|
30
|
+
return 'low';
|
|
31
|
+
if (percentage <= CONFIDENCE_THRESHOLDS.MEDIUM_MAX)
|
|
32
|
+
return 'medium';
|
|
33
|
+
if (percentage <= CONFIDENCE_THRESHOLDS.HIGH_MAX)
|
|
34
|
+
return 'high';
|
|
35
|
+
return 'very-high';
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create a confidence result from a percentage
|
|
39
|
+
*/
|
|
40
|
+
export function createConfidenceResult(percentage) {
|
|
41
|
+
const clamped = clampConfidence(percentage);
|
|
42
|
+
return {
|
|
43
|
+
percentage: clamped,
|
|
44
|
+
category: getConfidenceCategory(clamped),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// ============================================================================
|
|
48
|
+
// Calculation Patterns
|
|
49
|
+
// ============================================================================
|
|
50
|
+
/**
|
|
51
|
+
* Calculate additive confidence based on presence of elements.
|
|
52
|
+
* Common pattern: base + bonus for each element present.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* calculateAdditiveConfidence(50, [
|
|
56
|
+
* [hasRequirements, 20],
|
|
57
|
+
* [hasGoals, 15],
|
|
58
|
+
* [hasConstraints, 15],
|
|
59
|
+
* ]);
|
|
60
|
+
*/
|
|
61
|
+
export function calculateAdditiveConfidence(baseConfidence, bonuses) {
|
|
62
|
+
let total = baseConfidence;
|
|
63
|
+
for (const [condition, bonus] of bonuses) {
|
|
64
|
+
if (condition) {
|
|
65
|
+
total += bonus;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return clampConfidence(total);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Calculate ratio-based confidence.
|
|
72
|
+
* Common pattern: primary score as percentage of total score.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* calculateRatioConfidence(primaryScore, totalScore);
|
|
76
|
+
*/
|
|
77
|
+
export function calculateRatioConfidence(primaryScore, totalScore, options = {}) {
|
|
78
|
+
const { minConfidence = 0, fallbackConfidence = 50 } = options;
|
|
79
|
+
if (totalScore === 0) {
|
|
80
|
+
return fallbackConfidence;
|
|
81
|
+
}
|
|
82
|
+
const ratio = primaryScore / totalScore;
|
|
83
|
+
const percentage = Math.round(ratio * 100);
|
|
84
|
+
return clampConfidence(Math.max(minConfidence, percentage));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Apply confidence penalty when competing scores are close.
|
|
88
|
+
* Common pattern: reduce confidence when there's ambiguity.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* applyCompetitionPenalty(confidence, primaryScore, secondaryScore, {
|
|
92
|
+
* threshold: 0.15,
|
|
93
|
+
* penalty: 15,
|
|
94
|
+
* minConfidence: 60,
|
|
95
|
+
* });
|
|
96
|
+
*/
|
|
97
|
+
export function applyCompetitionPenalty(confidence, primaryScore, secondaryScore, options = {}) {
|
|
98
|
+
const { threshold = 0.15, penalty = 15, minConfidence = 60 } = options;
|
|
99
|
+
const difference = primaryScore - secondaryScore;
|
|
100
|
+
// If scores are within threshold, apply penalty
|
|
101
|
+
if (primaryScore > 0 && difference < primaryScore * threshold) {
|
|
102
|
+
return clampConfidence(Math.max(minConfidence, confidence - penalty));
|
|
103
|
+
}
|
|
104
|
+
return clampConfidence(confidence);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Calculate weighted average confidence from multiple sources.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* calculateWeightedConfidence([
|
|
111
|
+
* [intentConfidence, 0.6],
|
|
112
|
+
* [qualityConfidence, 0.4],
|
|
113
|
+
* ]);
|
|
114
|
+
*/
|
|
115
|
+
export function calculateWeightedConfidence(scores // [confidence, weight]
|
|
116
|
+
) {
|
|
117
|
+
const totalWeight = scores.reduce((sum, [, weight]) => sum + weight, 0);
|
|
118
|
+
if (totalWeight === 0) {
|
|
119
|
+
return 50;
|
|
120
|
+
}
|
|
121
|
+
const weightedSum = scores.reduce((sum, [confidence, weight]) => sum + confidence * weight, 0);
|
|
122
|
+
return clampConfidence(weightedSum / totalWeight);
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=confidence-calculator.js.map
|
|
@@ -3,6 +3,7 @@ export { IntentDetector } from './intent-detector.js';
|
|
|
3
3
|
export { PatternLibrary } from './pattern-library.js';
|
|
4
4
|
export { QualityAssessor } from './quality-assessor.js';
|
|
5
5
|
export * from './types.js';
|
|
6
|
+
export * from './confidence-calculator.js';
|
|
6
7
|
export { BasePattern } from './patterns/base-pattern.js';
|
|
7
8
|
export { ConcisenessFilter } from './patterns/conciseness-filter.js';
|
|
8
9
|
export { ObjectiveClarifier } from './patterns/objective-clarifier.js';
|
|
@@ -5,6 +5,8 @@ export { PatternLibrary } from './pattern-library.js';
|
|
|
5
5
|
export { QualityAssessor } from './quality-assessor.js';
|
|
6
6
|
// Type exports
|
|
7
7
|
export * from './types.js';
|
|
8
|
+
// v4.5: Confidence calculation utilities
|
|
9
|
+
export * from './confidence-calculator.js';
|
|
8
10
|
// Pattern exports
|
|
9
11
|
export { BasePattern } from './patterns/base-pattern.js';
|
|
10
12
|
export { ConcisenessFilter } from './patterns/conciseness-filter.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { calculateRatioConfidence, applyCompetitionPenalty } from './confidence-calculator.js';
|
|
1
2
|
/**
|
|
2
3
|
* Enhanced Intent Detector with weighted scoring and phrase-based detection
|
|
3
4
|
* Target Accuracy: 95%+
|
|
@@ -556,22 +557,23 @@ export class IntentDetector {
|
|
|
556
557
|
calculateConfidence(scores, primaryIntent) {
|
|
557
558
|
const primaryScore = scores[primaryIntent];
|
|
558
559
|
const totalScore = Object.values(scores).reduce((sum, score) => sum + score, 0);
|
|
559
|
-
|
|
560
|
-
return 50; // Low confidence if no keywords matched
|
|
561
|
-
}
|
|
560
|
+
// v4.5: Use shared confidence calculator
|
|
562
561
|
// Calculate confidence as percentage of primary vs total
|
|
563
|
-
let confidence =
|
|
562
|
+
let confidence = calculateRatioConfidence(primaryScore, totalScore, {
|
|
563
|
+
fallbackConfidence: 50, // Low confidence if no keywords matched
|
|
564
|
+
});
|
|
564
565
|
// Check if secondary intent is close
|
|
565
566
|
const sortedScores = Object.entries(scores)
|
|
566
567
|
.filter(([intent]) => intent !== primaryIntent)
|
|
567
568
|
.sort(([, a], [, b]) => b - a);
|
|
568
569
|
if (sortedScores.length > 0) {
|
|
569
570
|
const secondaryScore = sortedScores[0][1];
|
|
570
|
-
const difference = primaryScore - secondaryScore;
|
|
571
571
|
// If top 2 are within 15%, reduce confidence
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
572
|
+
confidence = applyCompetitionPenalty(confidence, primaryScore, secondaryScore, {
|
|
573
|
+
threshold: 0.15,
|
|
574
|
+
penalty: 15,
|
|
575
|
+
minConfidence: 60,
|
|
576
|
+
});
|
|
575
577
|
}
|
|
576
578
|
return confidence;
|
|
577
579
|
}
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import { BasePattern } from './patterns/base-pattern.js';
|
|
1
|
+
import { BasePattern, IPatternLibrary } from './patterns/base-pattern.js';
|
|
2
2
|
import { IntentAnalysis, OptimizationMode, OptimizationPhase } from './types.js';
|
|
3
3
|
import { IntelligenceConfig } from '../../types/config.js';
|
|
4
|
-
export declare class PatternLibrary {
|
|
4
|
+
export declare class PatternLibrary implements IPatternLibrary {
|
|
5
5
|
private patterns;
|
|
6
6
|
private config;
|
|
7
|
+
private priorityOverrides;
|
|
7
8
|
constructor();
|
|
8
9
|
/**
|
|
9
|
-
* v4.
|
|
10
|
-
* Allows enabling/disabling patterns and adjusting priorities via config
|
|
10
|
+
* v4.5: Apply configuration settings to pattern library
|
|
11
|
+
* Allows enabling/disabling patterns and adjusting priorities via config.
|
|
12
|
+
* Priority overrides are stored separately (pattern.priority is readonly).
|
|
11
13
|
*/
|
|
12
14
|
applyConfig(config: IntelligenceConfig): void;
|
|
15
|
+
/**
|
|
16
|
+
* v4.5: Get effective priority for a pattern (considers overrides)
|
|
17
|
+
*/
|
|
18
|
+
private getEffectivePriority;
|
|
13
19
|
/**
|
|
14
20
|
* v4.4: Check if a pattern is disabled via config
|
|
15
21
|
*/
|
|
@@ -20,7 +26,8 @@ export declare class PatternLibrary {
|
|
|
20
26
|
getPatternSettings(patternId: string): Record<string, unknown> | undefined;
|
|
21
27
|
private registerDefaultPatterns;
|
|
22
28
|
/**
|
|
23
|
-
* Register a new pattern
|
|
29
|
+
* Register a new pattern.
|
|
30
|
+
* v4.5: Injects library reference for config access.
|
|
24
31
|
*/
|
|
25
32
|
register(pattern: BasePattern): void;
|
|
26
33
|
/**
|
|
@@ -44,22 +51,37 @@ export declare class PatternLibrary {
|
|
|
44
51
|
*/
|
|
45
52
|
selectPatterns(intent: IntentAnalysis, mode: OptimizationMode): BasePattern[];
|
|
46
53
|
/**
|
|
47
|
-
* v4.
|
|
54
|
+
* v4.5: Sort patterns by priority while respecting dependency constraints.
|
|
55
|
+
* Handles runAfter (must run after specified patterns) and excludesWith (mutually exclusive).
|
|
56
|
+
*/
|
|
57
|
+
private sortPatternsWithDependencies;
|
|
58
|
+
/**
|
|
59
|
+
* v4.5: Filter out patterns that are mutually exclusive with higher priority patterns.
|
|
60
|
+
*/
|
|
61
|
+
private filterExcludedPatterns;
|
|
62
|
+
/**
|
|
63
|
+
* v4.5: Adjust pattern order to respect runAfter dependencies.
|
|
64
|
+
* If pattern A declares runAfter: ['B'], ensure B runs before A.
|
|
65
|
+
*/
|
|
66
|
+
private adjustForDependencies;
|
|
67
|
+
/**
|
|
68
|
+
* v4.5: Select patterns for specific mode with phase-awareness
|
|
48
69
|
* Maps PRD and conversational modes to appropriate base modes and patterns
|
|
49
70
|
*/
|
|
50
71
|
selectPatternsForMode(mode: OptimizationMode, intent: IntentAnalysis, phase?: OptimizationPhase): BasePattern[];
|
|
51
72
|
/**
|
|
52
|
-
*
|
|
73
|
+
* v4.5: Check if pattern is applicable for a given phase.
|
|
74
|
+
* Uses pattern's declared phases property instead of hardcoded mappings.
|
|
53
75
|
*/
|
|
54
|
-
private
|
|
76
|
+
private isPatternApplicableForPhase;
|
|
55
77
|
/**
|
|
56
|
-
*
|
|
78
|
+
* v4.5: Map OptimizationPhase string to PatternPhase type
|
|
57
79
|
*/
|
|
58
|
-
private
|
|
80
|
+
private mapOptimizationPhaseToPatternPhase;
|
|
59
81
|
/**
|
|
60
|
-
*
|
|
82
|
+
* Map extended modes to base modes for pattern compatibility
|
|
61
83
|
*/
|
|
62
|
-
private
|
|
84
|
+
private mapToBaseMode;
|
|
63
85
|
/**
|
|
64
86
|
* Get all registered patterns
|
|
65
87
|
*/
|