baseguard 1.0.5 → 1.0.6

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 (80) hide show
  1. package/dist/ai/gemini-analyzer.d.ts.map +1 -1
  2. package/dist/ai/gemini-analyzer.js +1 -1
  3. package/dist/ai/gemini-analyzer.js.map +1 -1
  4. package/dist/ai/gemini-code-fixer.d.ts.map +1 -1
  5. package/dist/ai/gemini-code-fixer.js +2 -7
  6. package/dist/ai/gemini-code-fixer.js.map +1 -1
  7. package/dist/ai/jules-implementer.d.ts +8 -0
  8. package/dist/ai/jules-implementer.d.ts.map +1 -1
  9. package/dist/ai/jules-implementer.js +115 -17
  10. package/dist/ai/jules-implementer.js.map +1 -1
  11. package/package.json +1 -1
  12. package/src/ai/__tests__/gemini-analyzer.test.ts +0 -181
  13. package/src/ai/agentkit-orchestrator.ts +0 -534
  14. package/src/ai/fix-manager.ts +0 -362
  15. package/src/ai/gemini-analyzer.ts +0 -665
  16. package/src/ai/gemini-code-fixer.ts +0 -539
  17. package/src/ai/index.ts +0 -4
  18. package/src/ai/jules-implementer.ts +0 -504
  19. package/src/ai/unified-code-fixer.ts +0 -347
  20. package/src/commands/automation.ts +0 -344
  21. package/src/commands/check.ts +0 -298
  22. package/src/commands/config.ts +0 -584
  23. package/src/commands/fix.ts +0 -269
  24. package/src/commands/index.ts +0 -7
  25. package/src/commands/init.ts +0 -156
  26. package/src/commands/status.ts +0 -307
  27. package/src/core/api-key-manager.ts +0 -298
  28. package/src/core/baseguard.ts +0 -757
  29. package/src/core/baseline-checker.ts +0 -566
  30. package/src/core/cache-manager.ts +0 -272
  31. package/src/core/configuration-recovery.ts +0 -672
  32. package/src/core/configuration.ts +0 -596
  33. package/src/core/debug-logger.ts +0 -590
  34. package/src/core/directory-filter.ts +0 -421
  35. package/src/core/error-handler.ts +0 -518
  36. package/src/core/file-processor.ts +0 -338
  37. package/src/core/gitignore-manager.ts +0 -169
  38. package/src/core/graceful-degradation-manager.ts +0 -596
  39. package/src/core/index.ts +0 -17
  40. package/src/core/lazy-loader.ts +0 -317
  41. package/src/core/logger.ts +0 -0
  42. package/src/core/memory-manager.ts +0 -290
  43. package/src/core/parser-worker.ts +0 -33
  44. package/src/core/startup-optimizer.ts +0 -246
  45. package/src/core/system-error-handler.ts +0 -755
  46. package/src/git/automation-engine.ts +0 -361
  47. package/src/git/github-manager.ts +0 -190
  48. package/src/git/hook-manager.ts +0 -210
  49. package/src/git/index.ts +0 -4
  50. package/src/index.ts +0 -8
  51. package/src/parsers/feature-validator.ts +0 -559
  52. package/src/parsers/index.ts +0 -8
  53. package/src/parsers/parser-manager.ts +0 -418
  54. package/src/parsers/parser.ts +0 -26
  55. package/src/parsers/react-parser-optimized.ts +0 -161
  56. package/src/parsers/react-parser.ts +0 -359
  57. package/src/parsers/svelte-parser.ts +0 -510
  58. package/src/parsers/vanilla-parser.ts +0 -685
  59. package/src/parsers/vue-parser.ts +0 -476
  60. package/src/types/index.ts +0 -96
  61. package/src/ui/components.ts +0 -567
  62. package/src/ui/help.ts +0 -193
  63. package/src/ui/index.ts +0 -4
  64. package/src/ui/prompts.ts +0 -681
  65. package/src/ui/terminal-header.ts +0 -59
  66. package/tests/e2e/baseguard.e2e.test.ts +0 -516
  67. package/tests/e2e/cross-platform.e2e.test.ts +0 -420
  68. package/tests/e2e/git-integration.e2e.test.ts +0 -487
  69. package/tests/fixtures/react-project/package.json +0 -14
  70. package/tests/fixtures/react-project/src/App.css +0 -76
  71. package/tests/fixtures/react-project/src/App.tsx +0 -77
  72. package/tests/fixtures/svelte-project/package.json +0 -11
  73. package/tests/fixtures/svelte-project/src/App.svelte +0 -369
  74. package/tests/fixtures/vanilla-project/index.html +0 -76
  75. package/tests/fixtures/vanilla-project/script.js +0 -331
  76. package/tests/fixtures/vanilla-project/styles.css +0 -359
  77. package/tests/fixtures/vue-project/package.json +0 -12
  78. package/tests/fixtures/vue-project/src/App.vue +0 -216
  79. package/tmp-smoke/.baseguard/backups/config-2026-02-19T12-04-11-067Z-auto.json +0 -30
  80. package/tmp-smoke/src/bad.css +0 -3
@@ -1,317 +0,0 @@
1
- /**
2
- * Lazy loading system for heavy dependencies and parsers
3
- */
4
- export class LazyLoader {
5
- private static instances = new Map<string, any>();
6
- private static loadPromises = new Map<string, Promise<any>>();
7
-
8
- /**
9
- * Lazy load web-features package
10
- */
11
- static async getWebFeatures(): Promise<any> {
12
- const key = 'web-features';
13
-
14
- if (this.instances.has(key)) {
15
- return this.instances.get(key);
16
- }
17
-
18
- if (this.loadPromises.has(key)) {
19
- return this.loadPromises.get(key);
20
- }
21
-
22
- const loadPromise = this.loadWebFeatures();
23
- this.loadPromises.set(key, loadPromise);
24
-
25
- try {
26
- const webFeatures = await loadPromise;
27
- this.instances.set(key, webFeatures);
28
- this.loadPromises.delete(key);
29
- return webFeatures;
30
- } catch (error) {
31
- this.loadPromises.delete(key);
32
- throw error;
33
- }
34
- }
35
-
36
- /**
37
- * Lazy load Babel parser
38
- */
39
- static async getBabelParser(): Promise<any> {
40
- const key = 'babel-parser';
41
-
42
- if (this.instances.has(key)) {
43
- return this.instances.get(key);
44
- }
45
-
46
- if (this.loadPromises.has(key)) {
47
- return this.loadPromises.get(key);
48
- }
49
-
50
- const loadPromise = import('@babel/parser');
51
- this.loadPromises.set(key, loadPromise);
52
-
53
- try {
54
- const parser = await loadPromise;
55
- this.instances.set(key, parser);
56
- this.loadPromises.delete(key);
57
- return parser;
58
- } catch (error) {
59
- this.loadPromises.delete(key);
60
- throw error;
61
- }
62
- }
63
-
64
- /**
65
- * Lazy load Babel traverse
66
- */
67
- static async getBabelTraverse(): Promise<any> {
68
- const key = 'babel-traverse';
69
-
70
- if (this.instances.has(key)) {
71
- return this.instances.get(key);
72
- }
73
-
74
- if (this.loadPromises.has(key)) {
75
- return this.loadPromises.get(key);
76
- }
77
-
78
- const loadPromise = import('@babel/traverse');
79
- this.loadPromises.set(key, loadPromise);
80
-
81
- try {
82
- const traverseModule = await loadPromise;
83
- const traverseExport = traverseModule.default || traverseModule;
84
- const traverse =
85
- typeof traverseExport === 'function'
86
- ? traverseExport
87
- : (traverseExport as any)?.default;
88
-
89
- if (typeof traverse !== 'function') {
90
- throw new Error('Failed to resolve @babel/traverse default export');
91
- }
92
-
93
- this.instances.set(key, traverse);
94
- this.loadPromises.delete(key);
95
- return this.instances.get(key);
96
- } catch (error) {
97
- this.loadPromises.delete(key);
98
- throw error;
99
- }
100
- }
101
-
102
- /**
103
- * Lazy load PostCSS
104
- */
105
- static async getPostCSS(): Promise<any> {
106
- const key = 'postcss';
107
-
108
- if (this.instances.has(key)) {
109
- return this.instances.get(key);
110
- }
111
-
112
- if (this.loadPromises.has(key)) {
113
- return this.loadPromises.get(key);
114
- }
115
-
116
- const loadPromise = import('postcss');
117
- this.loadPromises.set(key, loadPromise);
118
-
119
- try {
120
- const postcss = await loadPromise;
121
- this.instances.set(key, postcss.default || postcss);
122
- this.loadPromises.delete(key);
123
- return this.instances.get(key);
124
- } catch (error) {
125
- this.loadPromises.delete(key);
126
- throw error;
127
- }
128
- }
129
-
130
- /**
131
- * Lazy load Vue compiler
132
- */
133
- static async getVueCompiler(): Promise<any> {
134
- const key = 'vue-compiler';
135
-
136
- if (this.instances.has(key)) {
137
- return this.instances.get(key);
138
- }
139
-
140
- if (this.loadPromises.has(key)) {
141
- return this.loadPromises.get(key);
142
- }
143
-
144
- const loadPromise = import('@vue/compiler-sfc');
145
- this.loadPromises.set(key, loadPromise);
146
-
147
- try {
148
- const compiler = await loadPromise;
149
- this.instances.set(key, compiler);
150
- this.loadPromises.delete(key);
151
- return compiler;
152
- } catch (error) {
153
- this.loadPromises.delete(key);
154
- throw error;
155
- }
156
- }
157
-
158
- /**
159
- * Lazy load Svelte compiler
160
- */
161
- static async getSvelteCompiler(): Promise<any> {
162
- const key = 'svelte-compiler';
163
-
164
- if (this.instances.has(key)) {
165
- return this.instances.get(key);
166
- }
167
-
168
- if (this.loadPromises.has(key)) {
169
- return this.loadPromises.get(key);
170
- }
171
-
172
- const loadPromise = import('svelte/compiler');
173
- this.loadPromises.set(key, loadPromise);
174
-
175
- try {
176
- const compiler = await loadPromise;
177
- this.instances.set(key, compiler);
178
- this.loadPromises.delete(key);
179
- return compiler;
180
- } catch (error) {
181
- this.loadPromises.delete(key);
182
- throw error;
183
- }
184
- }
185
-
186
- /**
187
- * Preload commonly used dependencies
188
- */
189
- static async preloadCommon(): Promise<void> {
190
- // Preload in background without blocking
191
- Promise.all([
192
- this.getWebFeatures().catch(() => {}),
193
- this.getBabelParser().catch(() => {}),
194
- this.getPostCSS().catch(() => {})
195
- ]);
196
- }
197
-
198
- /**
199
- * Clear all cached instances (for testing)
200
- */
201
- static clearCache(): void {
202
- this.instances.clear();
203
- this.loadPromises.clear();
204
- }
205
-
206
- /**
207
- * Get memory usage statistics
208
- */
209
- static getStats(): {
210
- loadedModules: string[];
211
- pendingLoads: string[];
212
- memoryUsage?: NodeJS.MemoryUsage;
213
- } {
214
- return {
215
- loadedModules: Array.from(this.instances.keys()),
216
- pendingLoads: Array.from(this.loadPromises.keys()),
217
- memoryUsage: process.memoryUsage ? process.memoryUsage() : undefined
218
- };
219
- }
220
-
221
- /**
222
- * Load web-features with optimized loading
223
- */
224
- private static async loadWebFeatures(): Promise<any> {
225
- try {
226
- // Try to load web-features package
227
- const webFeatures = await import('web-features');
228
-
229
- // Extract only the data we need to reduce memory usage
230
- const optimizedData = this.optimizeWebFeaturesData(webFeatures.default || webFeatures);
231
-
232
- return optimizedData;
233
- } catch (error) {
234
- console.warn('Failed to load web-features package:', error);
235
- // Return minimal fallback data
236
- return {
237
- features: {},
238
- browsers: {},
239
- groups: {}
240
- };
241
- }
242
- }
243
-
244
- /**
245
- * Optimize web-features data to reduce memory usage
246
- */
247
- private static optimizeWebFeaturesData(webFeatures: any): any {
248
- if (!webFeatures) {
249
- return { features: {}, browsers: {}, groups: {} };
250
- }
251
-
252
- // Handle both direct export and features property
253
- const featuresData = webFeatures.features || webFeatures;
254
-
255
- if (!featuresData || typeof featuresData !== 'object') {
256
- return { features: {}, browsers: {}, groups: {} };
257
- }
258
-
259
- // Create optimized structure with only essential data
260
- const optimized = {
261
- features: {} as any,
262
- browsers: webFeatures.browsers || {},
263
- groups: webFeatures.groups || {}
264
- };
265
-
266
- // Only keep essential feature data to reduce memory footprint
267
- for (const [featureId, feature] of Object.entries(featuresData)) {
268
- const f = feature as any;
269
-
270
- // Skip if not a valid feature object
271
- if (!f || typeof f !== 'object') {
272
- continue;
273
- }
274
-
275
- // Only store essential compatibility data
276
- optimized.features[featureId] = {
277
- name: f.name,
278
- status: f.status ? {
279
- baseline: f.status.baseline,
280
- support: f.status.support
281
- } : null,
282
- // Skip heavy data like descriptions, specs, caniuse data, etc.
283
- };
284
- }
285
-
286
- return optimized;
287
- }
288
-
289
- /**
290
- * Get startup performance statistics
291
- */
292
- static getStartupStats(): {
293
- loadedModules: string[];
294
- pendingLoads: string[];
295
- startupTime?: number;
296
- } {
297
- return {
298
- loadedModules: Array.from(this.instances.keys()),
299
- pendingLoads: Array.from(this.loadPromises.keys()),
300
- startupTime: process.uptime ? Math.round(process.uptime() * 1000) : undefined
301
- };
302
- }
303
-
304
- /**
305
- * Optimize startup by preloading critical dependencies
306
- */
307
- static async optimizeStartup(): Promise<void> {
308
- // Start loading critical dependencies in background
309
- const criticalLoads = [
310
- this.getWebFeatures().catch(() => {}),
311
- this.getBabelParser().catch(() => {})
312
- ];
313
-
314
- // Don't wait for all to complete, just start the process
315
- Promise.all(criticalLoads);
316
- }
317
- }
File without changes
@@ -1,290 +0,0 @@
1
- import { createReadStream } from 'fs';
2
- import { createInterface } from 'readline';
3
-
4
- /**
5
- * Memory-efficient file processing and streaming
6
- */
7
- export class MemoryManager {
8
- private static readonly MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB
9
- private static readonly CHUNK_SIZE = 64 * 1024; // 64KB chunks
10
- private static readonly GC_THRESHOLD = 100 * 1024 * 1024; // 100MB
11
-
12
- /**
13
- * Check if file should be processed in streaming mode
14
- */
15
- static shouldStream(fileSize: number): boolean {
16
- return fileSize > this.MAX_FILE_SIZE;
17
- }
18
-
19
- /**
20
- * Read large file in chunks using streaming
21
- */
22
- static async readFileStreaming(
23
- filePath: string,
24
- processor: (chunk: string, lineNumber: number) => Promise<void>
25
- ): Promise<void> {
26
- return new Promise((resolve, reject) => {
27
- const fileStream = createReadStream(filePath, {
28
- encoding: 'utf8',
29
- highWaterMark: this.CHUNK_SIZE
30
- });
31
-
32
- const rl = createInterface({
33
- input: fileStream,
34
- crlfDelay: Infinity
35
- });
36
-
37
- let lineNumber = 0;
38
- let currentChunk = '';
39
- let chunkLineCount = 0;
40
-
41
- rl.on('line', async (line) => {
42
- lineNumber++;
43
- currentChunk += line + '\n';
44
- chunkLineCount++;
45
-
46
- // Process in chunks to avoid memory buildup
47
- if (chunkLineCount >= 1000) {
48
- try {
49
- await processor(currentChunk, lineNumber - chunkLineCount + 1);
50
- currentChunk = '';
51
- chunkLineCount = 0;
52
-
53
- // Force garbage collection if available
54
- this.tryGarbageCollect();
55
- } catch (error) {
56
- rl.close();
57
- reject(error);
58
- return;
59
- }
60
- }
61
- });
62
-
63
- rl.on('close', async () => {
64
- try {
65
- // Process remaining chunk
66
- if (currentChunk.trim()) {
67
- await processor(currentChunk, lineNumber - chunkLineCount + 1);
68
- }
69
- resolve();
70
- } catch (error) {
71
- reject(error);
72
- }
73
- });
74
-
75
- rl.on('error', reject);
76
- fileStream.on('error', reject);
77
- });
78
- }
79
-
80
- /**
81
- * Process array in memory-efficient batches
82
- */
83
- static async processBatches<T, R>(
84
- items: T[],
85
- processor: (batch: T[]) => Promise<R[]>,
86
- batchSize: number = 100
87
- ): Promise<R[]> {
88
- const results: R[] = [];
89
-
90
- for (let i = 0; i < items.length; i += batchSize) {
91
- const batch = items.slice(i, i + batchSize);
92
-
93
- try {
94
- const batchResults = await processor(batch);
95
- results.push(...batchResults);
96
-
97
- // Force garbage collection between batches
98
- this.tryGarbageCollect();
99
-
100
- // Small delay to prevent overwhelming the system
101
- if (i + batchSize < items.length) {
102
- await this.sleep(1);
103
- }
104
- } catch (error) {
105
- console.warn(`Error processing batch ${i}-${i + batchSize}: ${error}`);
106
- }
107
- }
108
-
109
- return results;
110
- }
111
-
112
- /**
113
- * Monitor memory usage and warn if high
114
- */
115
- static checkMemoryUsage(): {
116
- usage: NodeJS.MemoryUsage;
117
- warning?: string;
118
- } {
119
- const usage = process.memoryUsage();
120
- let warning: string | undefined;
121
-
122
- // Check if memory usage is high (over 100MB heap used)
123
- if (usage.heapUsed > this.GC_THRESHOLD) {
124
- warning = `High memory usage detected: ${Math.round(usage.heapUsed / 1024 / 1024)}MB heap used`;
125
- }
126
-
127
- return { usage, warning };
128
- }
129
-
130
- /**
131
- * Try to trigger garbage collection if available
132
- */
133
- static tryGarbageCollect(): void {
134
- if (global.gc) {
135
- try {
136
- global.gc();
137
- } catch (error) {
138
- // Ignore GC errors
139
- }
140
- }
141
- }
142
-
143
- /**
144
- * Sleep utility for batch processing
145
- */
146
- static sleep(ms: number): Promise<void> {
147
- return new Promise(resolve => setTimeout(resolve, ms));
148
- }
149
-
150
- /**
151
- * Create memory-efficient data structure for violations
152
- */
153
- static createViolationTracker(): ViolationTracker {
154
- return new ViolationTracker();
155
- }
156
-
157
- /**
158
- * Optimize object for memory usage by removing undefined properties
159
- */
160
- static optimizeObject<T extends Record<string, any>>(obj: T): T {
161
- const optimized = {} as T;
162
-
163
- for (const [key, value] of Object.entries(obj)) {
164
- if (value !== undefined && value !== null) {
165
- optimized[key as keyof T] = value;
166
- }
167
- }
168
-
169
- return optimized;
170
- }
171
-
172
- /**
173
- * Get memory usage statistics
174
- */
175
- static getMemoryStats(): {
176
- heapUsed: string;
177
- heapTotal: string;
178
- external: string;
179
- rss: string;
180
- } {
181
- const usage = process.memoryUsage();
182
-
183
- return {
184
- heapUsed: `${Math.round(usage.heapUsed / 1024 / 1024)}MB`,
185
- heapTotal: `${Math.round(usage.heapTotal / 1024 / 1024)}MB`,
186
- external: `${Math.round(usage.external / 1024 / 1024)}MB`,
187
- rss: `${Math.round(usage.rss / 1024 / 1024)}MB`
188
- };
189
- }
190
- }
191
-
192
- /**
193
- * Memory-efficient violation tracking
194
- */
195
- class ViolationTracker {
196
- private violations = new Map<string, any>();
197
- private fileIndex = new Map<string, number>();
198
- private nextFileId = 0;
199
-
200
- /**
201
- * Add violation with memory optimization
202
- */
203
- addViolation(violation: any): void {
204
- // Optimize file path storage using indices
205
- let fileId = this.fileIndex.get(violation.file);
206
- if (fileId === undefined) {
207
- fileId = this.nextFileId++;
208
- this.fileIndex.set(violation.file, fileId);
209
- }
210
-
211
- // Create optimized violation object
212
- const optimized = {
213
- f: violation.feature,
214
- fid: violation.featureId,
215
- fi: fileId, // file index instead of full path
216
- l: violation.line,
217
- c: violation.column,
218
- ctx: violation.context?.substring(0, 100), // Limit context length
219
- b: violation.browser,
220
- r: violation.required,
221
- a: violation.actual,
222
- bs: violation.baselineStatus,
223
- rs: violation.reason?.substring(0, 200) // Limit reason length
224
- };
225
-
226
- const key = `${fileId}-${violation.line}-${violation.feature}`;
227
- this.violations.set(key, optimized);
228
- }
229
-
230
- /**
231
- * Get all violations with full data
232
- */
233
- getViolations(): any[] {
234
- const result: any[] = [];
235
- const fileIdToPath = new Map<number, string>();
236
-
237
- // Create reverse mapping
238
- for (const [path, id] of this.fileIndex) {
239
- fileIdToPath.set(id, path);
240
- }
241
-
242
- for (const optimized of this.violations.values()) {
243
- result.push({
244
- feature: optimized.f,
245
- featureId: optimized.fid,
246
- file: fileIdToPath.get(optimized.fi) || 'unknown',
247
- line: optimized.l,
248
- column: optimized.c,
249
- context: optimized.ctx,
250
- browser: optimized.b,
251
- required: optimized.r,
252
- actual: optimized.a,
253
- baselineStatus: optimized.bs,
254
- reason: optimized.rs
255
- });
256
- }
257
-
258
- return result;
259
- }
260
-
261
- /**
262
- * Get memory usage statistics
263
- */
264
- getStats(): {
265
- violationCount: number;
266
- fileCount: number;
267
- memoryEstimate: string;
268
- } {
269
- const violationCount = this.violations.size;
270
- const fileCount = this.fileIndex.size;
271
-
272
- // Rough memory estimate (each violation ~200 bytes)
273
- const memoryEstimate = `${Math.round(violationCount * 200 / 1024)}KB`;
274
-
275
- return {
276
- violationCount,
277
- fileCount,
278
- memoryEstimate
279
- };
280
- }
281
-
282
- /**
283
- * Clear all data
284
- */
285
- clear(): void {
286
- this.violations.clear();
287
- this.fileIndex.clear();
288
- this.nextFileId = 0;
289
- }
290
- }
@@ -1,33 +0,0 @@
1
- import { parentPort } from 'worker_threads';
2
- import { ParserManager } from '../parsers/parser-manager.js';
3
- import type { DetectedFeature } from '../types/index.js';
4
-
5
- interface WorkerTask {
6
- id: string;
7
- filePath: string;
8
- }
9
-
10
- interface WorkerResult {
11
- id: string;
12
- features: DetectedFeature[];
13
- error?: string;
14
- }
15
-
16
- const parserManager = new ParserManager(1);
17
-
18
- if (parentPort) {
19
- parentPort.on('message', async (task: WorkerTask) => {
20
- const result: WorkerResult = {
21
- id: task.id,
22
- features: []
23
- };
24
-
25
- try {
26
- result.features = await parserManager.parseFile(task.filePath);
27
- } catch (error) {
28
- result.error = error instanceof Error ? error.message : 'Unknown parsing error';
29
- }
30
-
31
- parentPort?.postMessage(result);
32
- });
33
- }