baseguard 1.0.2 → 1.0.4

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 (169) hide show
  1. package/.baseguardrc.example.json +63 -63
  2. package/.eslintrc.json +24 -24
  3. package/.prettierrc +7 -7
  4. package/CHANGELOG.md +195 -195
  5. package/DEPLOYMENT.md +624 -624
  6. package/DEPLOYMENT_CHECKLIST.md +239 -239
  7. package/DEPLOYMENT_SUMMARY_v1.0.2.md +202 -202
  8. package/QUICK_START.md +134 -134
  9. package/README.md +488 -488
  10. package/RELEASE_NOTES_v1.0.2.md +434 -434
  11. package/bin/base.js +628 -613
  12. package/dist/ai/fix-manager.d.ts.map +1 -1
  13. package/dist/ai/fix-manager.js +1 -1
  14. package/dist/ai/fix-manager.js.map +1 -1
  15. package/dist/ai/gemini-analyzer.d.ts.map +1 -1
  16. package/dist/ai/gemini-analyzer.js +29 -35
  17. package/dist/ai/gemini-analyzer.js.map +1 -1
  18. package/dist/ai/gemini-code-fixer.d.ts.map +1 -1
  19. package/dist/ai/gemini-code-fixer.js +58 -58
  20. package/dist/ai/gemini-code-fixer.js.map +1 -1
  21. package/dist/ai/jules-implementer.d.ts +3 -0
  22. package/dist/ai/jules-implementer.d.ts.map +1 -1
  23. package/dist/ai/jules-implementer.js +63 -32
  24. package/dist/ai/jules-implementer.js.map +1 -1
  25. package/dist/ai/unified-code-fixer.js.map +1 -1
  26. package/dist/commands/check.d.ts.map +1 -1
  27. package/dist/commands/check.js +1 -1
  28. package/dist/commands/check.js.map +1 -1
  29. package/dist/commands/config.js +2 -1
  30. package/dist/commands/config.js.map +1 -1
  31. package/dist/commands/fix.d.ts.map +1 -1
  32. package/dist/commands/fix.js +44 -15
  33. package/dist/commands/fix.js.map +1 -1
  34. package/dist/core/api-key-manager.js +2 -2
  35. package/dist/core/api-key-manager.js.map +1 -1
  36. package/dist/core/baseguard.d.ts +1 -0
  37. package/dist/core/baseguard.d.ts.map +1 -1
  38. package/dist/core/baseguard.js +13 -10
  39. package/dist/core/baseguard.js.map +1 -1
  40. package/dist/core/baseline-checker.d.ts.map +1 -1
  41. package/dist/core/baseline-checker.js +2 -1
  42. package/dist/core/baseline-checker.js.map +1 -1
  43. package/dist/core/configuration-recovery.d.ts.map +1 -1
  44. package/dist/core/configuration-recovery.js +1 -1
  45. package/dist/core/configuration-recovery.js.map +1 -1
  46. package/dist/core/debug-logger.d.ts.map +1 -1
  47. package/dist/core/debug-logger.js +1 -1
  48. package/dist/core/debug-logger.js.map +1 -1
  49. package/dist/core/error-handler.d.ts.map +1 -1
  50. package/dist/core/error-handler.js +2 -1
  51. package/dist/core/error-handler.js.map +1 -1
  52. package/dist/core/gitignore-manager.js +5 -5
  53. package/dist/core/graceful-degradation-manager.d.ts.map +1 -1
  54. package/dist/core/graceful-degradation-manager.js +16 -16
  55. package/dist/core/graceful-degradation-manager.js.map +1 -1
  56. package/dist/core/lazy-loader.d.ts.map +1 -1
  57. package/dist/core/lazy-loader.js +9 -2
  58. package/dist/core/lazy-loader.js.map +1 -1
  59. package/dist/core/memory-manager.d.ts +0 -3
  60. package/dist/core/memory-manager.d.ts.map +1 -1
  61. package/dist/core/memory-manager.js.map +1 -1
  62. package/dist/core/parser-worker.d.ts +2 -0
  63. package/dist/core/parser-worker.d.ts.map +1 -0
  64. package/dist/core/parser-worker.js +19 -0
  65. package/dist/core/parser-worker.js.map +1 -0
  66. package/dist/core/startup-optimizer.d.ts +2 -0
  67. package/dist/core/startup-optimizer.d.ts.map +1 -1
  68. package/dist/core/startup-optimizer.js +19 -12
  69. package/dist/core/startup-optimizer.js.map +1 -1
  70. package/dist/core/system-error-handler.d.ts.map +1 -1
  71. package/dist/core/system-error-handler.js +18 -11
  72. package/dist/core/system-error-handler.js.map +1 -1
  73. package/dist/git/automation-engine.d.ts.map +1 -1
  74. package/dist/git/automation-engine.js +5 -4
  75. package/dist/git/automation-engine.js.map +1 -1
  76. package/dist/git/github-manager.d.ts.map +1 -1
  77. package/dist/git/github-manager.js.map +1 -1
  78. package/dist/git/hook-manager.js +5 -5
  79. package/dist/git/hook-manager.js.map +1 -1
  80. package/dist/parsers/parser-manager.d.ts.map +1 -1
  81. package/dist/parsers/parser-manager.js +1 -1
  82. package/dist/parsers/parser-manager.js.map +1 -1
  83. package/dist/parsers/svelte-parser.js +1 -1
  84. package/dist/parsers/svelte-parser.js.map +1 -1
  85. package/dist/parsers/vanilla-parser.d.ts.map +1 -1
  86. package/dist/parsers/vanilla-parser.js.map +1 -1
  87. package/dist/parsers/vue-parser.d.ts.map +1 -1
  88. package/dist/parsers/vue-parser.js.map +1 -1
  89. package/dist/ui/components.d.ts +1 -1
  90. package/dist/ui/components.d.ts.map +1 -1
  91. package/dist/ui/components.js +11 -11
  92. package/dist/ui/components.js.map +1 -1
  93. package/dist/ui/terminal-header.js +14 -14
  94. package/package.json +105 -105
  95. package/src/ai/__tests__/gemini-analyzer.test.ts +180 -180
  96. package/src/ai/agentkit-orchestrator.ts +533 -533
  97. package/src/ai/fix-manager.ts +362 -362
  98. package/src/ai/gemini-analyzer.ts +665 -671
  99. package/src/ai/gemini-code-fixer.ts +539 -540
  100. package/src/ai/index.ts +3 -3
  101. package/src/ai/jules-implementer.ts +504 -460
  102. package/src/ai/unified-code-fixer.ts +347 -347
  103. package/src/commands/automation.ts +343 -343
  104. package/src/commands/check.ts +298 -299
  105. package/src/commands/config.ts +584 -583
  106. package/src/commands/fix.ts +264 -238
  107. package/src/commands/index.ts +6 -6
  108. package/src/commands/init.ts +155 -155
  109. package/src/commands/status.ts +306 -306
  110. package/src/core/api-key-manager.ts +298 -298
  111. package/src/core/baseguard.ts +757 -756
  112. package/src/core/baseline-checker.ts +564 -563
  113. package/src/core/cache-manager.ts +271 -271
  114. package/src/core/configuration-recovery.ts +672 -673
  115. package/src/core/configuration.ts +595 -595
  116. package/src/core/debug-logger.ts +590 -590
  117. package/src/core/directory-filter.ts +420 -420
  118. package/src/core/error-handler.ts +518 -517
  119. package/src/core/file-processor.ts +337 -337
  120. package/src/core/gitignore-manager.ts +168 -168
  121. package/src/core/graceful-degradation-manager.ts +596 -596
  122. package/src/core/index.ts +16 -16
  123. package/src/core/lazy-loader.ts +317 -307
  124. package/src/core/memory-manager.ts +290 -295
  125. package/src/core/parser-worker.ts +33 -0
  126. package/src/core/startup-optimizer.ts +246 -243
  127. package/src/core/system-error-handler.ts +755 -750
  128. package/src/git/automation-engine.ts +361 -361
  129. package/src/git/github-manager.ts +190 -192
  130. package/src/git/hook-manager.ts +210 -210
  131. package/src/git/index.ts +3 -3
  132. package/src/index.ts +7 -7
  133. package/src/parsers/feature-validator.ts +558 -558
  134. package/src/parsers/index.ts +7 -7
  135. package/src/parsers/parser-manager.ts +418 -419
  136. package/src/parsers/parser.ts +25 -25
  137. package/src/parsers/react-parser-optimized.ts +160 -160
  138. package/src/parsers/react-parser.ts +358 -358
  139. package/src/parsers/svelte-parser.ts +510 -510
  140. package/src/parsers/vanilla-parser.ts +685 -686
  141. package/src/parsers/vue-parser.ts +476 -478
  142. package/src/types/index.ts +95 -95
  143. package/src/ui/components.ts +567 -567
  144. package/src/ui/help.ts +192 -192
  145. package/src/ui/index.ts +3 -3
  146. package/src/ui/prompts.ts +680 -680
  147. package/src/ui/terminal-header.ts +58 -58
  148. package/test-build.js +40 -40
  149. package/test-config-commands.js +55 -55
  150. package/test-header-simple.js +32 -32
  151. package/test-terminal-header.js +11 -11
  152. package/test-ui.js +28 -28
  153. package/tests/e2e/baseguard.e2e.test.ts +515 -515
  154. package/tests/e2e/cross-platform.e2e.test.ts +419 -419
  155. package/tests/e2e/git-integration.e2e.test.ts +486 -486
  156. package/tests/fixtures/react-project/package.json +13 -13
  157. package/tests/fixtures/react-project/src/App.css +75 -75
  158. package/tests/fixtures/react-project/src/App.tsx +76 -76
  159. package/tests/fixtures/svelte-project/package.json +10 -10
  160. package/tests/fixtures/svelte-project/src/App.svelte +368 -368
  161. package/tests/fixtures/vanilla-project/index.html +75 -75
  162. package/tests/fixtures/vanilla-project/script.js +330 -330
  163. package/tests/fixtures/vanilla-project/styles.css +358 -358
  164. package/tests/fixtures/vue-project/package.json +11 -11
  165. package/tests/fixtures/vue-project/src/App.vue +215 -215
  166. package/tsconfig.json +34 -34
  167. package/vitest.config.ts +11 -11
  168. package/dist/terminal-header.d.ts +0 -12
  169. package/dist/terminal-header.js +0 -45
@@ -1,272 +1,272 @@
1
- import { createHash } from 'crypto';
2
- import { stat } from 'fs/promises';
3
- import type { DetectedFeature } from '../types/index.js';
4
-
5
- /**
6
- * LRU Cache implementation for web-features data and parsing results
7
- */
8
- export class LRUCache<K, V> {
9
- private cache = new Map<K, V>();
10
- private readonly maxSize: number;
11
-
12
- constructor(maxSize: number = 1000) {
13
- this.maxSize = maxSize;
14
- }
15
-
16
- get(key: K): V | undefined {
17
- const value = this.cache.get(key);
18
- if (value !== undefined) {
19
- // Move to end (most recently used)
20
- this.cache.delete(key);
21
- this.cache.set(key, value);
22
- }
23
- return value;
24
- }
25
-
26
- set(key: K, value: V): void {
27
- if (this.cache.has(key)) {
28
- this.cache.delete(key);
29
- } else if (this.cache.size >= this.maxSize) {
30
- // Remove least recently used (first item)
31
- const firstKey = this.cache.keys().next().value as K;
32
- if (firstKey !== undefined) {
33
- this.cache.delete(firstKey);
34
- }
35
- }
36
- this.cache.set(key, value);
37
- }
38
-
39
- has(key: K): boolean {
40
- return this.cache.has(key);
41
- }
42
-
43
- clear(): void {
44
- this.cache.clear();
45
- }
46
-
47
- size(): number {
48
- return this.cache.size;
49
- }
50
- }
51
-
52
- /**
53
- * File metadata for incremental scanning
54
- */
55
- interface FileMetadata {
56
- path: string;
57
- mtime: number;
58
- size: number;
59
- hash: string;
60
- }
61
-
62
- /**
63
- * Cached parsing result
64
- */
65
- interface CachedResult {
66
- features: DetectedFeature[];
67
- metadata: FileMetadata;
68
- timestamp: number;
69
- }
70
-
71
- /**
72
- * Cache manager for efficient file processing and incremental scanning
73
- */
74
- export class CacheManager {
75
- private readonly parseCache: LRUCache<string, CachedResult>;
76
- private readonly webFeaturesCache: LRUCache<string, any>;
77
- private readonly fileMetadataCache: Map<string, FileMetadata>;
78
- private readonly maxCacheSize: number;
79
- private readonly cacheValidityMs: number;
80
-
81
- constructor(options: {
82
- maxCacheSize?: number;
83
- cacheValidityMs?: number;
84
- } = {}) {
85
- this.maxCacheSize = options.maxCacheSize || 1000;
86
- this.cacheValidityMs = options.cacheValidityMs || 5 * 60 * 1000; // 5 minutes
87
- this.parseCache = new LRUCache(this.maxCacheSize);
88
- this.webFeaturesCache = new LRUCache(500);
89
- this.fileMetadataCache = new Map();
90
- }
91
-
92
- /**
93
- * Get cached parsing result if file hasn't changed
94
- */
95
- async getCachedParseResult(filePath: string): Promise<DetectedFeature[] | null> {
96
- try {
97
- const currentMetadata = await this.getFileMetadata(filePath);
98
- const cached = this.parseCache.get(filePath);
99
-
100
- if (!cached) {
101
- return null;
102
- }
103
-
104
- // Check if file has changed
105
- if (this.hasFileChanged(cached.metadata, currentMetadata)) {
106
- this.parseCache.set(filePath, { ...cached, metadata: currentMetadata });
107
- return null;
108
- }
109
-
110
- // Check cache validity
111
- if (Date.now() - cached.timestamp > this.cacheValidityMs) {
112
- return null;
113
- }
114
-
115
- return cached.features;
116
- } catch (error) {
117
- // File doesn't exist or can't be accessed
118
- return null;
119
- }
120
- }
121
-
122
- /**
123
- * Cache parsing result
124
- */
125
- async setCachedParseResult(filePath: string, features: DetectedFeature[]): Promise<void> {
126
- try {
127
- const metadata = await this.getFileMetadata(filePath);
128
- const cached: CachedResult = {
129
- features,
130
- metadata,
131
- timestamp: Date.now()
132
- };
133
-
134
- this.parseCache.set(filePath, cached);
135
- this.fileMetadataCache.set(filePath, metadata);
136
- } catch (error) {
137
- // Ignore caching errors
138
- }
139
- }
140
-
141
- /**
142
- * Get cached web-features data
143
- */
144
- getCachedWebFeature(featureId: string): any | null {
145
- return this.webFeaturesCache.get(featureId) || null;
146
- }
147
-
148
- /**
149
- * Cache web-features data
150
- */
151
- setCachedWebFeature(featureId: string, data: any): void {
152
- this.webFeaturesCache.set(featureId, data);
153
- }
154
-
155
- /**
156
- * Check if files have changed since last scan
157
- */
158
- async getChangedFiles(filePaths: string[]): Promise<{
159
- changed: string[];
160
- unchanged: string[];
161
- }> {
162
- const changed: string[] = [];
163
- const unchanged: string[] = [];
164
-
165
- await Promise.all(
166
- filePaths.map(async (filePath) => {
167
- try {
168
- const currentMetadata = await this.getFileMetadata(filePath);
169
- const cachedMetadata = this.fileMetadataCache.get(filePath);
170
-
171
- if (!cachedMetadata || this.hasFileChanged(cachedMetadata, currentMetadata)) {
172
- changed.push(filePath);
173
- this.fileMetadataCache.set(filePath, currentMetadata);
174
- } else {
175
- unchanged.push(filePath);
176
- }
177
- } catch (error) {
178
- // File doesn't exist or can't be accessed, consider it changed
179
- changed.push(filePath);
180
- }
181
- })
182
- );
183
-
184
- return { changed, unchanged };
185
- }
186
-
187
- /**
188
- * Clear all caches
189
- */
190
- clearAll(): void {
191
- this.parseCache.clear();
192
- this.webFeaturesCache.clear();
193
- this.fileMetadataCache.clear();
194
- }
195
-
196
- /**
197
- * Clear expired cache entries
198
- */
199
- clearExpired(): void {
200
- const now = Date.now();
201
- const expiredKeys: string[] = [];
202
-
203
- // Find expired parse cache entries
204
- for (const [key, value] of this.parseCache['cache']) {
205
- if (now - value.timestamp > this.cacheValidityMs) {
206
- expiredKeys.push(key);
207
- }
208
- }
209
-
210
- // Remove expired entries
211
- expiredKeys.forEach(key => {
212
- this.parseCache['cache'].delete(key);
213
- this.fileMetadataCache.delete(key);
214
- });
215
- }
216
-
217
- /**
218
- * Get cache statistics
219
- */
220
- getStats(): {
221
- parseCache: { size: number; maxSize: number };
222
- webFeaturesCache: { size: number; maxSize: number };
223
- fileMetadataCache: { size: number };
224
- } {
225
- return {
226
- parseCache: {
227
- size: this.parseCache.size(),
228
- maxSize: this.maxCacheSize
229
- },
230
- webFeaturesCache: {
231
- size: this.webFeaturesCache.size(),
232
- maxSize: 500
233
- },
234
- fileMetadataCache: {
235
- size: this.fileMetadataCache.size
236
- }
237
- };
238
- }
239
-
240
- /**
241
- * Get file metadata for change detection
242
- */
243
- private async getFileMetadata(filePath: string): Promise<FileMetadata> {
244
- const stats = await stat(filePath);
245
- const hash = this.generateFileHash(filePath, stats.mtime.getTime(), stats.size);
246
-
247
- return {
248
- path: filePath,
249
- mtime: stats.mtime.getTime(),
250
- size: stats.size,
251
- hash
252
- };
253
- }
254
-
255
- /**
256
- * Check if file has changed based on metadata
257
- */
258
- private hasFileChanged(cached: FileMetadata, current: FileMetadata): boolean {
259
- return cached.mtime !== current.mtime ||
260
- cached.size !== current.size ||
261
- cached.hash !== current.hash;
262
- }
263
-
264
- /**
265
- * Generate hash for file identification
266
- */
267
- private generateFileHash(filePath: string, mtime: number, size: number): string {
268
- return createHash('md5')
269
- .update(`${filePath}:${mtime}:${size}`)
270
- .digest('hex');
271
- }
1
+ import { createHash } from 'crypto';
2
+ import { stat } from 'fs/promises';
3
+ import type { DetectedFeature } from '../types/index.js';
4
+
5
+ /**
6
+ * LRU Cache implementation for web-features data and parsing results
7
+ */
8
+ export class LRUCache<K, V> {
9
+ private cache = new Map<K, V>();
10
+ private readonly maxSize: number;
11
+
12
+ constructor(maxSize: number = 1000) {
13
+ this.maxSize = maxSize;
14
+ }
15
+
16
+ get(key: K): V | undefined {
17
+ const value = this.cache.get(key);
18
+ if (value !== undefined) {
19
+ // Move to end (most recently used)
20
+ this.cache.delete(key);
21
+ this.cache.set(key, value);
22
+ }
23
+ return value;
24
+ }
25
+
26
+ set(key: K, value: V): void {
27
+ if (this.cache.has(key)) {
28
+ this.cache.delete(key);
29
+ } else if (this.cache.size >= this.maxSize) {
30
+ // Remove least recently used (first item)
31
+ const firstKey = this.cache.keys().next().value as K;
32
+ if (firstKey !== undefined) {
33
+ this.cache.delete(firstKey);
34
+ }
35
+ }
36
+ this.cache.set(key, value);
37
+ }
38
+
39
+ has(key: K): boolean {
40
+ return this.cache.has(key);
41
+ }
42
+
43
+ clear(): void {
44
+ this.cache.clear();
45
+ }
46
+
47
+ size(): number {
48
+ return this.cache.size;
49
+ }
50
+ }
51
+
52
+ /**
53
+ * File metadata for incremental scanning
54
+ */
55
+ interface FileMetadata {
56
+ path: string;
57
+ mtime: number;
58
+ size: number;
59
+ hash: string;
60
+ }
61
+
62
+ /**
63
+ * Cached parsing result
64
+ */
65
+ interface CachedResult {
66
+ features: DetectedFeature[];
67
+ metadata: FileMetadata;
68
+ timestamp: number;
69
+ }
70
+
71
+ /**
72
+ * Cache manager for efficient file processing and incremental scanning
73
+ */
74
+ export class CacheManager {
75
+ private readonly parseCache: LRUCache<string, CachedResult>;
76
+ private readonly webFeaturesCache: LRUCache<string, any>;
77
+ private readonly fileMetadataCache: Map<string, FileMetadata>;
78
+ private readonly maxCacheSize: number;
79
+ private readonly cacheValidityMs: number;
80
+
81
+ constructor(options: {
82
+ maxCacheSize?: number;
83
+ cacheValidityMs?: number;
84
+ } = {}) {
85
+ this.maxCacheSize = options.maxCacheSize || 1000;
86
+ this.cacheValidityMs = options.cacheValidityMs || 5 * 60 * 1000; // 5 minutes
87
+ this.parseCache = new LRUCache(this.maxCacheSize);
88
+ this.webFeaturesCache = new LRUCache(500);
89
+ this.fileMetadataCache = new Map();
90
+ }
91
+
92
+ /**
93
+ * Get cached parsing result if file hasn't changed
94
+ */
95
+ async getCachedParseResult(filePath: string): Promise<DetectedFeature[] | null> {
96
+ try {
97
+ const currentMetadata = await this.getFileMetadata(filePath);
98
+ const cached = this.parseCache.get(filePath);
99
+
100
+ if (!cached) {
101
+ return null;
102
+ }
103
+
104
+ // Check if file has changed
105
+ if (this.hasFileChanged(cached.metadata, currentMetadata)) {
106
+ this.parseCache.set(filePath, { ...cached, metadata: currentMetadata });
107
+ return null;
108
+ }
109
+
110
+ // Check cache validity
111
+ if (Date.now() - cached.timestamp > this.cacheValidityMs) {
112
+ return null;
113
+ }
114
+
115
+ return cached.features;
116
+ } catch (error) {
117
+ // File doesn't exist or can't be accessed
118
+ return null;
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Cache parsing result
124
+ */
125
+ async setCachedParseResult(filePath: string, features: DetectedFeature[]): Promise<void> {
126
+ try {
127
+ const metadata = await this.getFileMetadata(filePath);
128
+ const cached: CachedResult = {
129
+ features,
130
+ metadata,
131
+ timestamp: Date.now()
132
+ };
133
+
134
+ this.parseCache.set(filePath, cached);
135
+ this.fileMetadataCache.set(filePath, metadata);
136
+ } catch (error) {
137
+ // Ignore caching errors
138
+ }
139
+ }
140
+
141
+ /**
142
+ * Get cached web-features data
143
+ */
144
+ getCachedWebFeature(featureId: string): any | null {
145
+ return this.webFeaturesCache.get(featureId) || null;
146
+ }
147
+
148
+ /**
149
+ * Cache web-features data
150
+ */
151
+ setCachedWebFeature(featureId: string, data: any): void {
152
+ this.webFeaturesCache.set(featureId, data);
153
+ }
154
+
155
+ /**
156
+ * Check if files have changed since last scan
157
+ */
158
+ async getChangedFiles(filePaths: string[]): Promise<{
159
+ changed: string[];
160
+ unchanged: string[];
161
+ }> {
162
+ const changed: string[] = [];
163
+ const unchanged: string[] = [];
164
+
165
+ await Promise.all(
166
+ filePaths.map(async (filePath) => {
167
+ try {
168
+ const currentMetadata = await this.getFileMetadata(filePath);
169
+ const cachedMetadata = this.fileMetadataCache.get(filePath);
170
+
171
+ if (!cachedMetadata || this.hasFileChanged(cachedMetadata, currentMetadata)) {
172
+ changed.push(filePath);
173
+ this.fileMetadataCache.set(filePath, currentMetadata);
174
+ } else {
175
+ unchanged.push(filePath);
176
+ }
177
+ } catch (error) {
178
+ // File doesn't exist or can't be accessed, consider it changed
179
+ changed.push(filePath);
180
+ }
181
+ })
182
+ );
183
+
184
+ return { changed, unchanged };
185
+ }
186
+
187
+ /**
188
+ * Clear all caches
189
+ */
190
+ clearAll(): void {
191
+ this.parseCache.clear();
192
+ this.webFeaturesCache.clear();
193
+ this.fileMetadataCache.clear();
194
+ }
195
+
196
+ /**
197
+ * Clear expired cache entries
198
+ */
199
+ clearExpired(): void {
200
+ const now = Date.now();
201
+ const expiredKeys: string[] = [];
202
+
203
+ // Find expired parse cache entries
204
+ for (const [key, value] of this.parseCache['cache']) {
205
+ if (now - value.timestamp > this.cacheValidityMs) {
206
+ expiredKeys.push(key);
207
+ }
208
+ }
209
+
210
+ // Remove expired entries
211
+ expiredKeys.forEach(key => {
212
+ this.parseCache['cache'].delete(key);
213
+ this.fileMetadataCache.delete(key);
214
+ });
215
+ }
216
+
217
+ /**
218
+ * Get cache statistics
219
+ */
220
+ getStats(): {
221
+ parseCache: { size: number; maxSize: number };
222
+ webFeaturesCache: { size: number; maxSize: number };
223
+ fileMetadataCache: { size: number };
224
+ } {
225
+ return {
226
+ parseCache: {
227
+ size: this.parseCache.size(),
228
+ maxSize: this.maxCacheSize
229
+ },
230
+ webFeaturesCache: {
231
+ size: this.webFeaturesCache.size(),
232
+ maxSize: 500
233
+ },
234
+ fileMetadataCache: {
235
+ size: this.fileMetadataCache.size
236
+ }
237
+ };
238
+ }
239
+
240
+ /**
241
+ * Get file metadata for change detection
242
+ */
243
+ private async getFileMetadata(filePath: string): Promise<FileMetadata> {
244
+ const stats = await stat(filePath);
245
+ const hash = this.generateFileHash(filePath, stats.mtime.getTime(), stats.size);
246
+
247
+ return {
248
+ path: filePath,
249
+ mtime: stats.mtime.getTime(),
250
+ size: stats.size,
251
+ hash
252
+ };
253
+ }
254
+
255
+ /**
256
+ * Check if file has changed based on metadata
257
+ */
258
+ private hasFileChanged(cached: FileMetadata, current: FileMetadata): boolean {
259
+ return cached.mtime !== current.mtime ||
260
+ cached.size !== current.size ||
261
+ cached.hash !== current.hash;
262
+ }
263
+
264
+ /**
265
+ * Generate hash for file identification
266
+ */
267
+ private generateFileHash(filePath: string, mtime: number, size: number): string {
268
+ return createHash('md5')
269
+ .update(`${filePath}:${mtime}:${size}`)
270
+ .digest('hex');
271
+ }
272
272
  }