driftdetect-core 0.1.0 → 0.1.2

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/index.d.ts CHANGED
@@ -28,10 +28,14 @@ export type { PatternFile, StoredPattern, DetectorConfig, ConfidenceInfo, Patter
28
28
  export { CacheManager } from './store/cache-manager.js';
29
29
  export type { CacheManagerOptions, CacheEntry, CacheStats } from './store/cache-manager.js';
30
30
  export { PatternStore, PatternNotFoundError, InvalidStateTransitionError, PatternStoreError } from './store/pattern-store.js';
31
+ export * from './types/contracts.js';
32
+ export { ContractStore, ContractNotFoundError, InvalidContractTransitionError, ContractStoreError } from './store/contract-store.js';
33
+ export type { ContractStoreConfig, ContractStoreEvent, ContractStoreEventType } from './store/contract-store.js';
31
34
  export type { Position as RulePosition, Violation, QuickFix, Range, Severity, ViolationInput, RuleEvaluationResult, RuleEvaluationSummary, RuleEvaluationError } from './rules/types.js';
32
35
  export { Evaluator, createEvaluator, createEvaluatorWithConfig, createEvaluatorWithAI, type EvaluatorConfig, type EvaluationInput, type EvaluationResult, type EvaluationSummary } from './rules/evaluator.js';
33
36
  export { RuleEngine, createRuleEngine, createRuleEngineWithConfig, createRuleEngineWithAI, type RuleEngineConfig, type RuleEvaluationInput, type PatternWithContext } from './rules/rule-engine.js';
34
37
  export { VariantManager, VariantNotFoundError, VariantManagerError, InvalidVariantInputError, type CreateVariantInput, type UpdateVariantInput, type VariantQuery, type VariantManagerEvent, type VariantManagerEventType, type VariantManagerConfig } from './rules/variant-manager.js';
35
38
  export * from './config/index.js';
36
39
  export * from './manifest/index.js';
40
+ export * from './learning/index.js';
37
41
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,eAAO,MAAM,OAAO,UAAU,CAAC;AAG/B,cAAc,kBAAkB,CAAC;AAGjC,cAAc,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O,EAAE,YAAY,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAG9H,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,8BAA8B,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACrI,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAGjH,YAAY,EAAE,QAAQ,IAAI,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACzL,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,KAAK,eAAe,EAAE,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC/M,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,KAAK,gBAAgB,EAAE,KAAK,mBAAmB,EAAE,KAAK,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACpM,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,KAAK,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,KAAK,YAAY,EAAE,KAAK,mBAAmB,EAAE,KAAK,uBAAuB,EAAE,KAAK,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAGzR,cAAc,mBAAmB,CAAC;AAGlC,cAAc,qBAAqB,CAAC;AAGpC,cAAc,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -29,6 +29,9 @@ export * from './analyzers/index.js';
29
29
  export { CONFIDENCE_THRESHOLDS, DEFAULT_CONFIDENCE_WEIGHTS, } from './matcher/types.js';
30
30
  export { CacheManager } from './store/cache-manager.js';
31
31
  export { PatternStore, PatternNotFoundError, InvalidStateTransitionError, PatternStoreError } from './store/pattern-store.js';
32
+ // Contract exports (BE↔FE mismatch detection)
33
+ export * from './types/contracts.js';
34
+ export { ContractStore, ContractNotFoundError, InvalidContractTransitionError, ContractStoreError } from './store/contract-store.js';
32
35
  export { Evaluator, createEvaluator, createEvaluatorWithConfig, createEvaluatorWithAI } from './rules/evaluator.js';
33
36
  export { RuleEngine, createRuleEngine, createRuleEngineWithConfig, createRuleEngineWithAI } from './rules/rule-engine.js';
34
37
  export { VariantManager, VariantNotFoundError, VariantManagerError, InvalidVariantInputError } from './rules/variant-manager.js';
@@ -36,4 +39,6 @@ export { VariantManager, VariantNotFoundError, VariantManagerError, InvalidVaria
36
39
  export * from './config/index.js';
37
40
  // Manifest exports (pattern location discovery)
38
41
  export * from './manifest/index.js';
42
+ // Learning exports (pattern learning system)
43
+ export * from './learning/index.js';
39
44
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,iBAAiB;AACjB,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B,iCAAiC;AACjC,cAAc,kBAAkB,CAAC;AAEjC,kBAAkB;AAClB,cAAc,oBAAoB,CAAC;AAWnC,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,mB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mBAAmB;AACnB,cAAc,sBAAsB,CAAC;AA6CrC,oBAAoB;AACpB,OAAO,EACL,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE9H,8CAA8C;AAC9C,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,8BAA8B,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAKrI,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,yBAAyB,EAAE,qBAAqB,EAA6F,MAAM,sBAAsB,CAAC;AAC/M,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,sBAAsB,EAA4E,MAAM,wBAAwB,CAAC;AACpM,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,wBAAwB,EAA0J,MAAM,4BAA4B,CAAC;AAEzR,iBAAiB;AACjB,cAAc,mBAAmB,CAAC;AAElC,gDAAgD;AAChD,cAAc,qBAAqB,CAAC;AAEpC,6CAA6C;AAC7C,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Learning Module
3
+ *
4
+ * Exports for the pattern learning system.
5
+ */
6
+ export * from './types.js';
7
+ export * from './learning-store.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/learning/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Learning Module
3
+ *
4
+ * Exports for the pattern learning system.
5
+ */
6
+ export * from './types.js';
7
+ export * from './learning-store.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/learning/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Learning Store
3
+ *
4
+ * Persists and retrieves learned patterns from .drift/learned/
5
+ *
6
+ * @requirements DRIFT-CORE - Store learned conventions for reuse
7
+ */
8
+ import type { StoredLearnedPatterns, PatternLearningConfig } from './types.js';
9
+ export declare class LearningStore {
10
+ private rootDir;
11
+ private cache;
12
+ constructor(rootDir?: string);
13
+ /**
14
+ * Get the path to the learned patterns directory
15
+ */
16
+ private getLearnedDir;
17
+ /**
18
+ * Get the path to a detector's learned patterns file
19
+ */
20
+ private getDetectorPath;
21
+ /**
22
+ * Ensure the learned directory exists
23
+ */
24
+ private ensureDir;
25
+ /**
26
+ * Load learned patterns for a detector
27
+ */
28
+ load(detectorId: string): Promise<StoredLearnedPatterns | null>;
29
+ /**
30
+ * Save learned patterns for a detector
31
+ */
32
+ save(patterns: StoredLearnedPatterns): Promise<void>;
33
+ /**
34
+ * Check if learned patterns exist and are fresh
35
+ */
36
+ hasFreshPatterns(detectorId: string, maxAgeMs?: number): Promise<boolean>;
37
+ /**
38
+ * Clear learned patterns for a detector
39
+ */
40
+ clear(detectorId: string): Promise<void>;
41
+ /**
42
+ * Clear all learned patterns
43
+ */
44
+ clearAll(): Promise<void>;
45
+ /**
46
+ * List all detectors with learned patterns
47
+ */
48
+ listDetectors(): Promise<string[]>;
49
+ /**
50
+ * Create a StoredLearnedPatterns object
51
+ */
52
+ static createStoredPatterns(detectorId: string, conventions: Record<string, unknown>, metadata: {
53
+ filesAnalyzed: number;
54
+ relevantFiles: number;
55
+ hasEnoughData: boolean;
56
+ configUsed: PatternLearningConfig;
57
+ }): StoredLearnedPatterns;
58
+ }
59
+ /**
60
+ * Create a learning store instance
61
+ */
62
+ export declare function createLearningStore(rootDir?: string): LearningStore;
63
+ //# sourceMappingURL=learning-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"learning-store.d.ts","sourceRoot":"","sources":["../../src/learning/learning-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAa/E,qBAAa,aAAa;IACxB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,KAAK,CAAiD;gBAElD,OAAO,GAAE,MAAY;IAIjC;;OAEG;IACH,OAAO,CAAC,aAAa;IAIrB;;OAEG;IACH,OAAO,CAAC,eAAe;IAMvB;;OAEG;YACW,SAAS;IAKvB;;OAEG;IACG,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC;IA6BrE;;OAEG;IACG,IAAI,CAAC,QAAQ,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAU1D;;OAEG;IACG,gBAAgB,CACpB,UAAU,EAAE,MAAM,EAClB,QAAQ,GAAE,MAA4B,GACrC,OAAO,CAAC,OAAO,CAAC;IAYnB;;OAEG;IACG,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAa9C;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB/B;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAgBxC;;OAEG;IACH,MAAM,CAAC,oBAAoB,CACzB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,QAAQ,EAAE;QACR,aAAa,EAAE,MAAM,CAAC;QACtB,aAAa,EAAE,MAAM,CAAC;QACtB,aAAa,EAAE,OAAO,CAAC;QACvB,UAAU,EAAE,qBAAqB,CAAC;KACnC,GACA,qBAAqB;CAWzB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,MAAY,GAAG,aAAa,CAExE"}
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Learning Store
3
+ *
4
+ * Persists and retrieves learned patterns from .drift/learned/
5
+ *
6
+ * @requirements DRIFT-CORE - Store learned conventions for reuse
7
+ */
8
+ import { promises as fs } from 'fs';
9
+ import * as path from 'path';
10
+ // ============================================================================
11
+ // Constants
12
+ // ============================================================================
13
+ const LEARNED_DIR = '.drift/learned';
14
+ const SCHEMA_VERSION = '1.0.0';
15
+ // ============================================================================
16
+ // Learning Store
17
+ // ============================================================================
18
+ export class LearningStore {
19
+ rootDir;
20
+ cache = new Map();
21
+ constructor(rootDir = '.') {
22
+ this.rootDir = rootDir;
23
+ }
24
+ /**
25
+ * Get the path to the learned patterns directory
26
+ */
27
+ getLearnedDir() {
28
+ return path.join(this.rootDir, LEARNED_DIR);
29
+ }
30
+ /**
31
+ * Get the path to a detector's learned patterns file
32
+ */
33
+ getDetectorPath(detectorId) {
34
+ // Convert detector ID to safe filename (e.g., "api/route-structure" -> "api-route-structure.json")
35
+ const safeId = detectorId.replace(/\//g, '-');
36
+ return path.join(this.getLearnedDir(), `${safeId}.json`);
37
+ }
38
+ /**
39
+ * Ensure the learned directory exists
40
+ */
41
+ async ensureDir() {
42
+ const dir = this.getLearnedDir();
43
+ await fs.mkdir(dir, { recursive: true });
44
+ }
45
+ /**
46
+ * Load learned patterns for a detector
47
+ */
48
+ async load(detectorId) {
49
+ // Check cache first
50
+ const cached = this.cache.get(detectorId);
51
+ if (cached) {
52
+ return cached;
53
+ }
54
+ const filePath = this.getDetectorPath(detectorId);
55
+ try {
56
+ const content = await fs.readFile(filePath, 'utf-8');
57
+ const data = JSON.parse(content);
58
+ // Validate version
59
+ if (data.version !== SCHEMA_VERSION) {
60
+ console.warn(`Learned patterns for ${detectorId} have outdated schema version`);
61
+ return null;
62
+ }
63
+ this.cache.set(detectorId, data);
64
+ return data;
65
+ }
66
+ catch (error) {
67
+ if (error.code === 'ENOENT') {
68
+ return null; // File doesn't exist, need to learn
69
+ }
70
+ throw error;
71
+ }
72
+ }
73
+ /**
74
+ * Save learned patterns for a detector
75
+ */
76
+ async save(patterns) {
77
+ await this.ensureDir();
78
+ const filePath = this.getDetectorPath(patterns.detectorId);
79
+ const content = JSON.stringify(patterns, null, 2);
80
+ await fs.writeFile(filePath, content, 'utf-8');
81
+ this.cache.set(patterns.detectorId, patterns);
82
+ }
83
+ /**
84
+ * Check if learned patterns exist and are fresh
85
+ */
86
+ async hasFreshPatterns(detectorId, maxAgeMs = 24 * 60 * 60 * 1000 // 24 hours default
87
+ ) {
88
+ const patterns = await this.load(detectorId);
89
+ if (!patterns) {
90
+ return false;
91
+ }
92
+ const learnedAt = new Date(patterns.metadata.learnedAt).getTime();
93
+ const age = Date.now() - learnedAt;
94
+ return age < maxAgeMs;
95
+ }
96
+ /**
97
+ * Clear learned patterns for a detector
98
+ */
99
+ async clear(detectorId) {
100
+ const filePath = this.getDetectorPath(detectorId);
101
+ this.cache.delete(detectorId);
102
+ try {
103
+ await fs.unlink(filePath);
104
+ }
105
+ catch (error) {
106
+ if (error.code !== 'ENOENT') {
107
+ throw error;
108
+ }
109
+ }
110
+ }
111
+ /**
112
+ * Clear all learned patterns
113
+ */
114
+ async clearAll() {
115
+ this.cache.clear();
116
+ const dir = this.getLearnedDir();
117
+ try {
118
+ const files = await fs.readdir(dir);
119
+ await Promise.all(files
120
+ .filter(f => f.endsWith('.json'))
121
+ .map(f => fs.unlink(path.join(dir, f))));
122
+ }
123
+ catch (error) {
124
+ if (error.code !== 'ENOENT') {
125
+ throw error;
126
+ }
127
+ }
128
+ }
129
+ /**
130
+ * List all detectors with learned patterns
131
+ */
132
+ async listDetectors() {
133
+ const dir = this.getLearnedDir();
134
+ try {
135
+ const files = await fs.readdir(dir);
136
+ return files
137
+ .filter(f => f.endsWith('.json'))
138
+ .map(f => f.replace('.json', '').replace(/-/g, '/'));
139
+ }
140
+ catch (error) {
141
+ if (error.code === 'ENOENT') {
142
+ return [];
143
+ }
144
+ throw error;
145
+ }
146
+ }
147
+ /**
148
+ * Create a StoredLearnedPatterns object
149
+ */
150
+ static createStoredPatterns(detectorId, conventions, metadata) {
151
+ return {
152
+ detectorId,
153
+ version: SCHEMA_VERSION,
154
+ conventions: conventions,
155
+ metadata: {
156
+ ...metadata,
157
+ learnedAt: new Date().toISOString(),
158
+ },
159
+ };
160
+ }
161
+ }
162
+ /**
163
+ * Create a learning store instance
164
+ */
165
+ export function createLearningStore(rootDir = '.') {
166
+ return new LearningStore(rootDir);
167
+ }
168
+ //# sourceMappingURL=learning-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"learning-store.js","sourceRoot":"","sources":["../../src/learning/learning-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAG7B,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E,MAAM,WAAW,GAAG,gBAAgB,CAAC;AACrC,MAAM,cAAc,GAAG,OAAO,CAAC;AAE/B,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E,MAAM,OAAO,aAAa;IAChB,OAAO,CAAS;IAChB,KAAK,GAAuC,IAAI,GAAG,EAAE,CAAC;IAE9D,YAAY,UAAkB,GAAG;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;OAEG;IACK,aAAa;QACnB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACK,eAAe,CAAC,UAAkB;QACxC,mGAAmG;QACnG,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC,IAAI,CAAC,IAA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EAAE,CAAC;YACZ,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,oBAAoB,CACzB,UAAkB,EAClB,WAAoC,EACpC,QAKC;QAED,OAAO;YACL,UAAU;YACV,OAAO,EAAE,cAAc;YACvB,WAAW,EAAE,WAAwE;YACrF,QAAQ,EAAE;gBACR,GAAG,QAAQ;gBACX,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aACpC;SACF,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAAkB,GAAG;IACvD,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,178 @@
1
+ /**
2
+ * Learned Patterns Type System
3
+ *
4
+ * Types for pattern learning - detectors learn from the user's codebase
5
+ * rather than enforcing hardcoded conventions.
6
+ *
7
+ * @requirements DRIFT-CORE - Detectors learn patterns from user's code, not enforce arbitrary rules
8
+ */
9
+ /**
10
+ * A convention learned from analyzing the codebase
11
+ */
12
+ export interface LearnedConvention<T = unknown> {
13
+ /** The learned value/pattern */
14
+ value: T;
15
+ /** Number of occurrences found */
16
+ occurrences: number;
17
+ /** Files where this convention was found */
18
+ files: string[];
19
+ /** First line where this was seen (for reference) */
20
+ firstSeenAt?: {
21
+ file: string;
22
+ line: number;
23
+ };
24
+ /** Confidence that this is the dominant convention (0-1) */
25
+ confidence: number;
26
+ }
27
+ /**
28
+ * Result of learning conventions from a codebase
29
+ */
30
+ export interface LearnedConventions<T extends Record<string, unknown> = Record<string, unknown>> {
31
+ /** The learned conventions by key */
32
+ conventions: {
33
+ [K in keyof T]: LearnedConvention<T[K]>;
34
+ };
35
+ /** Total files analyzed */
36
+ filesAnalyzed: number;
37
+ /** Files that matched the detector's scope */
38
+ relevantFiles: number;
39
+ /** When the learning was performed */
40
+ learnedAt: string;
41
+ /** Whether enough data was found to establish conventions */
42
+ hasEnoughData: boolean;
43
+ /** Minimum occurrences needed to establish a convention */
44
+ minOccurrencesRequired: number;
45
+ }
46
+ /**
47
+ * Statistics about a learned value distribution
48
+ */
49
+ export interface ValueDistribution<T = unknown> {
50
+ /** All values found with their counts */
51
+ values: Map<T, number>;
52
+ /** The dominant value (most common) */
53
+ dominant: T | null;
54
+ /** Percentage of occurrences that use the dominant value */
55
+ dominantPercentage: number;
56
+ /** Total occurrences across all values */
57
+ totalOccurrences: number;
58
+ /** Number of unique values found */
59
+ uniqueValues: number;
60
+ }
61
+ /**
62
+ * Configuration for the learning process
63
+ */
64
+ export interface PatternLearningConfig {
65
+ /** Minimum occurrences to consider a pattern established */
66
+ minOccurrences: number;
67
+ /** Minimum percentage to consider a value "dominant" (0-1) */
68
+ dominanceThreshold: number;
69
+ /** Minimum files that must contain the pattern */
70
+ minFiles: number;
71
+ /** Maximum files to analyze (for performance) */
72
+ maxFilesToAnalyze: number;
73
+ /** File patterns to include */
74
+ includePatterns: string[];
75
+ /** File patterns to exclude */
76
+ excludePatterns: string[];
77
+ }
78
+ /**
79
+ * Default learning configuration
80
+ */
81
+ export declare const DEFAULT_PATTERN_LEARNING_CONFIG: PatternLearningConfig;
82
+ /**
83
+ * Stored learned patterns for a detector
84
+ */
85
+ export interface StoredLearnedPatterns {
86
+ /** Detector ID */
87
+ detectorId: string;
88
+ /** Version of the learning algorithm */
89
+ version: string;
90
+ /** The learned conventions (serializable) */
91
+ conventions: Record<string, SerializedConvention>;
92
+ /** Learning metadata */
93
+ metadata: {
94
+ filesAnalyzed: number;
95
+ relevantFiles: number;
96
+ learnedAt: string;
97
+ hasEnoughData: boolean;
98
+ configUsed: PatternLearningConfig;
99
+ };
100
+ }
101
+ /**
102
+ * Serialized convention for JSON storage
103
+ */
104
+ export interface SerializedConvention {
105
+ value: unknown;
106
+ occurrences: number;
107
+ files: string[];
108
+ firstSeenAt?: {
109
+ file: string;
110
+ line: number;
111
+ };
112
+ confidence: number;
113
+ }
114
+ /**
115
+ * Events emitted during learning
116
+ */
117
+ export type LearningEventType = 'learning:started' | 'learning:file-analyzed' | 'learning:completed' | 'learning:failed' | 'learning:convention-found' | 'learning:no-data';
118
+ /**
119
+ * Learning event payload
120
+ */
121
+ export interface LearningEvent {
122
+ type: LearningEventType;
123
+ detectorId: string;
124
+ timestamp: string;
125
+ data?: {
126
+ file?: string;
127
+ conventionKey?: string;
128
+ conventionValue?: unknown;
129
+ filesAnalyzed?: number;
130
+ error?: string;
131
+ };
132
+ }
133
+ /**
134
+ * Naming convention types
135
+ */
136
+ export type NamingConvention = 'camelCase' | 'PascalCase' | 'snake_case' | 'kebab-case' | 'SCREAMING_SNAKE_CASE' | 'lowercase' | 'mixed';
137
+ /**
138
+ * Learned naming conventions
139
+ */
140
+ export interface LearnedNamingConventions {
141
+ /** File naming convention */
142
+ fileNaming?: NamingConvention;
143
+ /** Function naming convention */
144
+ functionNaming?: NamingConvention;
145
+ /** Variable naming convention */
146
+ variableNaming?: NamingConvention;
147
+ /** Class naming convention */
148
+ classNaming?: NamingConvention;
149
+ /** Constant naming convention */
150
+ constantNaming?: NamingConvention;
151
+ /** Component naming convention */
152
+ componentNaming?: NamingConvention;
153
+ }
154
+ /**
155
+ * Learned string patterns (for things like error codes, route prefixes, etc.)
156
+ */
157
+ export interface LearnedStringPatterns {
158
+ /** Common prefixes found */
159
+ prefixes: string[];
160
+ /** Common suffixes found */
161
+ suffixes: string[];
162
+ /** Regex pattern that matches the learned format */
163
+ pattern?: string;
164
+ /** Example values */
165
+ examples: string[];
166
+ }
167
+ /**
168
+ * Learned structural patterns
169
+ */
170
+ export interface LearnedStructuralPatterns {
171
+ /** Directory structure patterns */
172
+ directories: string[];
173
+ /** Co-location patterns (what files are typically together) */
174
+ coLocatedFiles: string[][];
175
+ /** Import patterns */
176
+ importPatterns: string[];
177
+ }
178
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/learning/types.ts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C;IAE3B,sBAAsB;IACtB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Learned Patterns Type System
3
+ *
4
+ * Types for pattern learning - detectors learn from the user's codebase
5
+ * rather than enforcing hardcoded conventions.
6
+ *
7
+ * @requirements DRIFT-CORE - Detectors learn patterns from user's code, not enforce arbitrary rules
8
+ */
9
+ /**
10
+ * Default learning configuration
11
+ */
12
+ export const DEFAULT_PATTERN_LEARNING_CONFIG = {
13
+ minOccurrences: 3,
14
+ dominanceThreshold: 0.6, // 60% must use the same convention
15
+ minFiles: 2,
16
+ maxFilesToAnalyze: 1000,
17
+ includePatterns: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx', '**/*.py'],
18
+ excludePatterns: [
19
+ '**/node_modules/**',
20
+ '**/dist/**',
21
+ '**/build/**',
22
+ '**/.git/**',
23
+ '**/*.test.*',
24
+ '**/*.spec.*',
25
+ '**/__tests__/**',
26
+ ],
27
+ };
28
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/learning/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAqGH;;GAEG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAA0B;IACpE,cAAc,EAAE,CAAC;IACjB,kBAAkB,EAAE,GAAG,EAAE,mCAAmC;IAC5D,QAAQ,EAAE,CAAC;IACX,iBAAiB,EAAE,IAAI;IACvB,eAAe,EAAE,CAAC,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,CAAC;IAC1E,eAAe,EAAE;QACf,oBAAoB;QACpB,YAAY;QACZ,aAAa;QACb,YAAY;QACZ,aAAa;QACb,aAAa;QACb,iBAAiB;KAClB;CACF,CAAC"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Contract Store - Contract persistence and querying
3
+ *
4
+ * Loads and saves contracts to .drift/contracts/ directory.
5
+ * Supports querying by status, method, endpoint, and mismatches.
6
+ * Handles contract state transitions (discovered → verified/mismatch/ignored).
7
+ */
8
+ import { EventEmitter } from 'node:events';
9
+ import type { Contract, ContractStatus, ContractQueryOptions, ContractQueryResult, ContractStats, HttpMethod } from '../types/contracts.js';
10
+ export declare class ContractNotFoundError extends Error {
11
+ readonly contractId: string;
12
+ constructor(contractId: string);
13
+ }
14
+ export declare class InvalidContractTransitionError extends Error {
15
+ readonly contractId: string;
16
+ readonly fromStatus: ContractStatus;
17
+ readonly toStatus: ContractStatus;
18
+ constructor(contractId: string, fromStatus: ContractStatus, toStatus: ContractStatus);
19
+ }
20
+ export declare class ContractStoreError extends Error {
21
+ readonly errorCause: Error | undefined;
22
+ constructor(message: string, errorCause?: Error);
23
+ }
24
+ export interface ContractStoreConfig {
25
+ rootDir: string;
26
+ autoSave: boolean;
27
+ autoSaveDebounce: number;
28
+ createBackup: boolean;
29
+ maxBackups: number;
30
+ }
31
+ export declare const DEFAULT_CONTRACT_STORE_CONFIG: ContractStoreConfig;
32
+ export type ContractStoreEventType = 'contract:created' | 'contract:updated' | 'contract:deleted' | 'contract:verified' | 'contract:mismatch' | 'contract:ignored' | 'file:loaded' | 'file:saved' | 'error';
33
+ export interface ContractStoreEvent {
34
+ type: ContractStoreEventType;
35
+ contractId?: string;
36
+ data?: Record<string, unknown>;
37
+ timestamp: string;
38
+ }
39
+ export declare class ContractStore extends EventEmitter {
40
+ private readonly config;
41
+ private readonly contractsDir;
42
+ private contracts;
43
+ private dirty;
44
+ private saveTimeout;
45
+ constructor(config?: Partial<ContractStoreConfig>);
46
+ initialize(): Promise<void>;
47
+ private ensureDirectoryStructure;
48
+ loadAll(): Promise<void>;
49
+ private loadByStatus;
50
+ saveAll(): Promise<void>;
51
+ private groupContractsByStatus;
52
+ private saveStatusFile;
53
+ private createBackup;
54
+ private cleanupBackups;
55
+ private scheduleAutoSave;
56
+ get(id: string): Contract | undefined;
57
+ getOrThrow(id: string): Contract;
58
+ has(id: string): boolean;
59
+ add(contract: Contract): void;
60
+ update(id: string, updates: Partial<Omit<Contract, 'id'>>): Contract;
61
+ delete(id: string): boolean;
62
+ verify(id: string, verifiedBy?: string): Contract;
63
+ markMismatch(id: string): Contract;
64
+ ignore(id: string): Contract;
65
+ private transitionStatus;
66
+ query(options?: ContractQueryOptions): ContractQueryResult;
67
+ private applyFilters;
68
+ private applySorting;
69
+ getAll(): Contract[];
70
+ getByStatus(status: ContractStatus): Contract[];
71
+ getByMethod(method: HttpMethod): Contract[];
72
+ getWithMismatches(): Contract[];
73
+ getVerified(): Contract[];
74
+ getDiscovered(): Contract[];
75
+ getMismatched(): Contract[];
76
+ getStats(): ContractStats;
77
+ private emitEvent;
78
+ }
79
+ //# sourceMappingURL=contract-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-store.d.ts","sourceRoot":"","sources":["../../src/store/contract-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,KAAK,EACV,QAAQ,EAGR,cAAc,EAEd,oBAAoB,EACpB,mBAAmB,EAEnB,aAAa,EACb,UAAU,EACX,MAAM,uBAAuB,CAAC;AA6B/B,qBAAa,qBAAsB,SAAQ,KAAK;aAClB,UAAU,EAAE,MAAM;gBAAlB,UAAU,EAAE,MAAM;CAI/C;AAED,qBAAa,8BAA+B,SAAQ,KAAK;aAErC,UAAU,EAAE,MAAM;aAClB,UAAU,EAAE,cAAc;aAC1B,QAAQ,EAAE,cAAc;gBAFxB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,cAAc,EAC1B,QAAQ,EAAE,cAAc;CAK3C;AAED,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,SAAgB,UAAU,EAAE,KAAK,GAAG,SAAS,CAAC;gBAElC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,KAAK;CAKhD;AAqCD,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,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