driftdetect 0.1.6 → 0.1.7

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/bin/drift.js CHANGED
@@ -9,7 +9,7 @@
9
9
  */
10
10
  import { Command } from 'commander';
11
11
  import { VERSION } from '../index.js';
12
- import { initCommand, scanCommand, checkCommand, statusCommand, approveCommand, ignoreCommand, reportCommand, exportCommand, whereCommand, filesCommand, } from '../commands/index.js';
12
+ import { initCommand, scanCommand, checkCommand, statusCommand, approveCommand, ignoreCommand, reportCommand, exportCommand, whereCommand, filesCommand, watchCommand, } from '../commands/index.js';
13
13
  /**
14
14
  * Create and configure the main CLI program
15
15
  */
@@ -32,6 +32,7 @@ function createProgram() {
32
32
  program.addCommand(exportCommand);
33
33
  program.addCommand(whereCommand);
34
34
  program.addCommand(filesCommand);
35
+ program.addCommand(watchCommand);
35
36
  // Add help examples
36
37
  program.addHelpText('after', `
37
38
  Examples:
@@ -51,6 +52,9 @@ Examples:
51
52
  $ drift export --format ai-context Export for AI consumption
52
53
  $ drift where <pattern> Find pattern locations
53
54
  $ drift files <path> Show patterns in a file
55
+ $ drift watch Watch for changes in real-time
56
+ $ drift watch --verbose Watch with detailed output
57
+ $ drift watch --context .drift-context.md Auto-update AI context file
54
58
 
55
59
  Documentation:
56
60
  https://github.com/drift/drift
@@ -1 +1 @@
1
- {"version":3,"file":"drift.js","sourceRoot":"","sources":["../../src/bin/drift.ts"],"names":[],"mappings":";AACA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EACL,WAAW,EACX,WAAW,EACX,YAAY,EACZ,aAAa,EACb,cAAc,EACd,aAAa,EACb,aAAa,EACb,aAAa,EACb,YAAY,EACZ,YAAY,GACb,MAAM,sBAAsB,CAAC;AAE9B;;GAEG;AACH,SAAS,aAAa;IACpB,MAAM,OAA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CAAC,aAAa,CAAC,CAAC;IAClC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IAClC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IAClC,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IACjC,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IACjC,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IAEjC,oBAAoB;IACpB,OAAO,CAAC,WAAW,CACjB,OAAO,EACP;;;;;;;;;;;;;;;;;;;;;;;;CAwBH,CACE,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,IAAI;IACjB,MAAM,OAAO,GAAG,aAAa,EAAE,CAAC;IAEhC,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,OAAO,CAAC,KAAK,CAAC,UAAU,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YACzC,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;gBACzB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,cAAc;AACd,IAAI,EAAE,CAAC"}
@@ -13,4 +13,5 @@ export { reportCommand } from './report.js';
13
13
  export { exportCommand } from './export.js';
14
14
  export { whereCommand } from './where.js';
15
15
  export { filesCommand } from './files.js';
16
+ export { watchCommandDef as watchCommand } from './watch.js';
16
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,IAAI,YAAY,EAAE,MAAM,YAAY,CAAC"}
@@ -13,4 +13,5 @@ export { reportCommand } from './report.js';
13
13
  export { exportCommand } from './export.js';
14
14
  export { whereCommand } from './where.js';
15
15
  export { filesCommand } from './files.js';
16
+ export { watchCommandDef as watchCommand } from './watch.js';
16
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,IAAI,YAAY,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Drift Watch Command
3
+ *
4
+ * Real-time file watching with pattern detection.
5
+ * Monitors file changes and reports violations as they happen.
6
+ */
7
+ import { Command } from 'commander';
8
+ /**
9
+ * Create the watch command
10
+ */
11
+ export declare const watchCommandDef: Command;
12
+ //# sourceMappingURL=watch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../src/commands/watch.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAuSpC;;GAEG;AACH,eAAO,MAAM,eAAe,SAML,CAAC"}
@@ -0,0 +1,264 @@
1
+ /**
2
+ * Drift Watch Command
3
+ *
4
+ * Real-time file watching with pattern detection.
5
+ * Monitors file changes and reports violations as they happen.
6
+ */
7
+ import { Command } from 'commander';
8
+ import * as fs from 'node:fs';
9
+ import * as path from 'node:path';
10
+ import chalk from 'chalk';
11
+ import { createAllDetectorsArray } from 'driftdetect-detectors';
12
+ /**
13
+ * Format timestamp for output
14
+ */
15
+ function timestamp() {
16
+ return chalk.gray(`[${new Date().toLocaleTimeString()}]`);
17
+ }
18
+ /**
19
+ * Scan a single file for violations
20
+ */
21
+ async function scanFile(filePath, detectors, categories) {
22
+ const violations = [];
23
+ try {
24
+ const content = fs.readFileSync(filePath, 'utf-8');
25
+ const ext = path.extname(filePath).toLowerCase();
26
+ const cwd = process.cwd();
27
+ const relativePath = path.relative(cwd, filePath);
28
+ let language = 'typescript';
29
+ if (['.ts', '.tsx'].includes(ext))
30
+ language = 'typescript';
31
+ else if (['.js', '.jsx'].includes(ext))
32
+ language = 'javascript';
33
+ else if (['.py'].includes(ext))
34
+ language = 'python';
35
+ else if (['.css', '.scss'].includes(ext))
36
+ language = 'css';
37
+ else if (['.json'].includes(ext))
38
+ language = 'json';
39
+ else if (['.md'].includes(ext))
40
+ language = 'markdown';
41
+ // Check if test file
42
+ const isTestFile = /\.(test|spec)\.[jt]sx?$/.test(filePath) ||
43
+ filePath.includes('__tests__') ||
44
+ filePath.includes('/test/') ||
45
+ filePath.includes('/tests/');
46
+ // Check if type definition
47
+ const isTypeDefinition = ext === '.d.ts';
48
+ // Create minimal project context
49
+ const projectContext = {
50
+ rootDir: cwd,
51
+ files: [relativePath],
52
+ config: {},
53
+ };
54
+ // Run detectors
55
+ for (const detector of detectors) {
56
+ // Filter by category if specified
57
+ if (categories && !categories.includes(detector.category)) {
58
+ continue;
59
+ }
60
+ // Check if detector supports this language
61
+ if (!detector.supportsLanguage(language)) {
62
+ continue;
63
+ }
64
+ try {
65
+ // Create full detection context
66
+ const context = {
67
+ file: relativePath,
68
+ content,
69
+ ast: null,
70
+ imports: [],
71
+ exports: [],
72
+ projectContext,
73
+ language,
74
+ extension: ext,
75
+ isTestFile,
76
+ isTypeDefinition,
77
+ };
78
+ const result = await detector.detect(context);
79
+ // Check for violations
80
+ if (result.violations && result.violations.length > 0) {
81
+ for (const v of result.violations) {
82
+ violations.push({
83
+ file: filePath,
84
+ line: v.range?.start?.line ?? 1,
85
+ message: v.message,
86
+ severity: v.severity,
87
+ patternName: detector.name,
88
+ });
89
+ }
90
+ }
91
+ }
92
+ catch {
93
+ // Skip detector errors silently
94
+ }
95
+ }
96
+ }
97
+ catch {
98
+ // File read error - skip
99
+ }
100
+ return violations;
101
+ }
102
+ /**
103
+ * Print violations to console
104
+ */
105
+ function printViolations(filePath, violations, verbose) {
106
+ const relativePath = path.relative(process.cwd(), filePath);
107
+ if (violations.length === 0) {
108
+ console.log(`${timestamp()} ${chalk.green('āœ“')} ${relativePath}`);
109
+ return;
110
+ }
111
+ const errors = violations.filter(v => v.severity === 'error');
112
+ const warnings = violations.filter(v => v.severity === 'warning');
113
+ let summary = '';
114
+ if (errors.length > 0)
115
+ summary += chalk.red(`${errors.length} error${errors.length > 1 ? 's' : ''}`);
116
+ if (warnings.length > 0) {
117
+ if (summary)
118
+ summary += ', ';
119
+ summary += chalk.yellow(`${warnings.length} warning${warnings.length > 1 ? 's' : ''}`);
120
+ }
121
+ console.log(`${timestamp()} ${chalk.red('āœ—')} ${relativePath} - ${summary}`);
122
+ if (verbose) {
123
+ for (const v of violations) {
124
+ const icon = v.severity === 'error' ? chalk.red('ā—') : chalk.yellow('ā—');
125
+ console.log(` ${icon} Line ${v.line}: ${v.message}`);
126
+ console.log(` ${chalk.gray(`[${v.patternName}]`)}`);
127
+ }
128
+ }
129
+ }
130
+ /**
131
+ * Update AI context file
132
+ */
133
+ function updateContextFile(contextPath) {
134
+ try {
135
+ const content = `# Drift Context (Auto-updated)
136
+
137
+ Last updated: ${new Date().toISOString()}
138
+
139
+ This file is auto-updated by \`drift watch\`.
140
+ Run \`drift export --format ai-context\` for full pattern details.
141
+
142
+ ## Quick Commands
143
+ - \`drift where <pattern>\` - Find pattern locations
144
+ - \`drift files <path>\` - See patterns in a specific file
145
+ - \`drift status\` - View pattern summary
146
+ `;
147
+ fs.writeFileSync(contextPath, content);
148
+ }
149
+ catch {
150
+ // Silently fail context updates
151
+ }
152
+ }
153
+ /**
154
+ * Watch command implementation
155
+ */
156
+ async function watchCommand(options) {
157
+ const cwd = process.cwd();
158
+ const verbose = options.verbose ?? false;
159
+ const contextPath = options.context;
160
+ const debounceMs = parseInt(options.debounce ?? '300', 10);
161
+ const categories = options.categories?.split(',').map(c => c.trim()) ?? null;
162
+ console.log(chalk.cyan('\nšŸ” Drift Watch Mode\n'));
163
+ console.log(` Watching: ${chalk.white(cwd)}`);
164
+ if (categories) {
165
+ console.log(` Categories: ${chalk.white(categories.join(', '))}`);
166
+ }
167
+ if (contextPath) {
168
+ console.log(` Context file: ${chalk.white(contextPath)}`);
169
+ }
170
+ console.log(` Debounce: ${chalk.white(`${debounceMs}ms`)}`);
171
+ console.log(chalk.gray('\n Press Ctrl+C to stop\n'));
172
+ console.log(chalk.gray('─'.repeat(50)));
173
+ // Load detectors
174
+ const detectors = createAllDetectorsArray();
175
+ console.log(`${timestamp()} Loaded ${chalk.cyan(String(detectors.length))} detectors`);
176
+ // Track pending scans (for debouncing)
177
+ const pendingScans = new Map();
178
+ // Ignore patterns
179
+ const ignorePatterns = [
180
+ 'node_modules',
181
+ '.git',
182
+ 'dist',
183
+ 'build',
184
+ 'coverage',
185
+ '.turbo',
186
+ ];
187
+ /**
188
+ * Handle file change
189
+ */
190
+ function handleFileChange(filePath) {
191
+ // Check if file should be ignored
192
+ const relativePath = path.relative(cwd, filePath);
193
+ for (const pattern of ignorePatterns) {
194
+ if (relativePath.includes(pattern)) {
195
+ return;
196
+ }
197
+ }
198
+ // Debounce
199
+ const existing = pendingScans.get(filePath);
200
+ if (existing) {
201
+ clearTimeout(existing);
202
+ }
203
+ pendingScans.set(filePath, setTimeout(async () => {
204
+ pendingScans.delete(filePath);
205
+ const violations = await scanFile(filePath, detectors, categories);
206
+ printViolations(filePath, violations, verbose);
207
+ // Update context file if specified
208
+ if (contextPath) {
209
+ updateContextFile(contextPath);
210
+ }
211
+ }, debounceMs));
212
+ }
213
+ // Watch for file changes using fs.watch recursively
214
+ const watchers = [];
215
+ function watchDirectory(dir) {
216
+ try {
217
+ const watcher = fs.watch(dir, { recursive: true }, (_eventType, filename) => {
218
+ if (!filename)
219
+ return;
220
+ const fullPath = path.join(dir, filename);
221
+ // Only watch supported file types
222
+ const ext = path.extname(filename).toLowerCase();
223
+ const supportedExts = ['.ts', '.tsx', '.js', '.jsx', '.py', '.css', '.scss', '.json', '.md'];
224
+ if (!supportedExts.includes(ext))
225
+ return;
226
+ // Check if file exists (might be deleted)
227
+ if (!fs.existsSync(fullPath))
228
+ return;
229
+ handleFileChange(fullPath);
230
+ });
231
+ watchers.push(watcher);
232
+ }
233
+ catch (err) {
234
+ console.error(chalk.red(`Failed to watch ${dir}:`), err);
235
+ }
236
+ }
237
+ // Start watching
238
+ watchDirectory(cwd);
239
+ console.log(`${timestamp()} ${chalk.green('Watching for changes...')}\n`);
240
+ // Handle shutdown
241
+ process.on('SIGINT', () => {
242
+ console.log(chalk.gray('\n\nStopping watch mode...'));
243
+ for (const watcher of watchers) {
244
+ watcher.close();
245
+ }
246
+ for (const timeout of pendingScans.values()) {
247
+ clearTimeout(timeout);
248
+ }
249
+ process.exit(0);
250
+ });
251
+ // Keep process alive
252
+ await new Promise(() => { });
253
+ }
254
+ /**
255
+ * Create the watch command
256
+ */
257
+ export const watchCommandDef = new Command('watch')
258
+ .description('Watch for file changes and report violations in real-time')
259
+ .option('--verbose', 'Show detailed violation information')
260
+ .option('--context <file>', 'Auto-update AI context file on changes')
261
+ .option('-c, --categories <categories>', 'Filter by categories (comma-separated)')
262
+ .option('--debounce <ms>', 'Debounce delay in milliseconds', '300')
263
+ .action(watchCommand);
264
+ //# sourceMappingURL=watch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watch.js","sourceRoot":"","sources":["../../src/commands/watch.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAiBhE;;GAEG;AACH,SAAS,SAAS;IAChB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC;AAC5D,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,QAAQ,CACrB,QAAgB,EAChB,SAAqD,EACrD,UAA2B;IAE3B,MAAM,UAAU,GAAgB,EAAE,CAAC;IAEnC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,E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MAAM,EAAE,EAAE,CAAC;YAC5C,YAAY,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,qBAAqB;IACrB,MAAM,IAAI,OAAO,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AAC9B,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC;KAChD,WAAW,CAAC,2DAA2D,CAAC;KACxE,MAAM,CAAC,WAAW,EAAE,qCAAqC,CAAC;KAC1D,MAAM,CAAC,kBAAkB,EAAE,wCAAwC,CAAC;KACpE,MAAM,CAAC,+BAA+B,EAAE,wCAAwC,CAAC;KACjF,MAAM,CAAC,iBAAiB,EAAE,gCAAgC,EAAE,KAAK,CAAC;KAClE,MAAM,CAAC,YAAY,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "driftdetect",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "AI-augmented architectural drift detection - learn and enforce codebase patterns",
5
5
  "license": "MIT",
6
6
  "author": "Geoffrey Fernald",