baseguard 1.0.3 → 1.0.5

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 +627 -627
  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 +48 -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 +8 -5
  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.map +1 -1
  67. package/dist/core/startup-optimizer.js +4 -8
  68. package/dist/core/startup-optimizer.js.map +1 -1
  69. package/dist/core/system-error-handler.d.ts.map +1 -1
  70. package/dist/core/system-error-handler.js.map +1 -1
  71. package/dist/git/automation-engine.d.ts.map +1 -1
  72. package/dist/git/automation-engine.js +5 -4
  73. package/dist/git/automation-engine.js.map +1 -1
  74. package/dist/git/github-manager.d.ts.map +1 -1
  75. package/dist/git/github-manager.js.map +1 -1
  76. package/dist/git/hook-manager.js +5 -5
  77. package/dist/git/hook-manager.js.map +1 -1
  78. package/dist/parsers/parser-manager.d.ts.map +1 -1
  79. package/dist/parsers/parser-manager.js +1 -1
  80. package/dist/parsers/parser-manager.js.map +1 -1
  81. package/dist/parsers/svelte-parser.js +1 -1
  82. package/dist/parsers/svelte-parser.js.map +1 -1
  83. package/dist/parsers/vanilla-parser.d.ts.map +1 -1
  84. package/dist/parsers/vanilla-parser.js.map +1 -1
  85. package/dist/parsers/vue-parser.d.ts.map +1 -1
  86. package/dist/parsers/vue-parser.js.map +1 -1
  87. package/dist/ui/components.d.ts +1 -1
  88. package/dist/ui/components.d.ts.map +1 -1
  89. package/dist/ui/components.js +11 -11
  90. package/dist/ui/components.js.map +1 -1
  91. package/dist/ui/terminal-header.js +14 -14
  92. package/package.json +105 -105
  93. package/src/ai/__tests__/gemini-analyzer.test.ts +180 -180
  94. package/src/ai/agentkit-orchestrator.ts +533 -533
  95. package/src/ai/fix-manager.ts +362 -362
  96. package/src/ai/gemini-analyzer.ts +665 -671
  97. package/src/ai/gemini-code-fixer.ts +539 -540
  98. package/src/ai/index.ts +3 -3
  99. package/src/ai/jules-implementer.ts +504 -460
  100. package/src/ai/unified-code-fixer.ts +347 -347
  101. package/src/commands/automation.ts +343 -343
  102. package/src/commands/check.ts +298 -299
  103. package/src/commands/config.ts +584 -583
  104. package/src/commands/fix.ts +269 -238
  105. package/src/commands/index.ts +6 -6
  106. package/src/commands/init.ts +155 -155
  107. package/src/commands/status.ts +306 -306
  108. package/src/core/api-key-manager.ts +298 -298
  109. package/src/core/baseguard.ts +757 -756
  110. package/src/core/baseline-checker.ts +566 -563
  111. package/src/core/cache-manager.ts +271 -271
  112. package/src/core/configuration-recovery.ts +672 -673
  113. package/src/core/configuration.ts +595 -595
  114. package/src/core/debug-logger.ts +590 -590
  115. package/src/core/directory-filter.ts +420 -420
  116. package/src/core/error-handler.ts +518 -517
  117. package/src/core/file-processor.ts +337 -337
  118. package/src/core/gitignore-manager.ts +168 -168
  119. package/src/core/graceful-degradation-manager.ts +596 -596
  120. package/src/core/index.ts +16 -16
  121. package/src/core/lazy-loader.ts +317 -307
  122. package/src/core/memory-manager.ts +290 -295
  123. package/src/core/parser-worker.ts +33 -0
  124. package/src/core/startup-optimizer.ts +246 -255
  125. package/src/core/system-error-handler.ts +755 -756
  126. package/src/git/automation-engine.ts +361 -361
  127. package/src/git/github-manager.ts +190 -192
  128. package/src/git/hook-manager.ts +210 -210
  129. package/src/git/index.ts +3 -3
  130. package/src/index.ts +7 -7
  131. package/src/parsers/feature-validator.ts +558 -558
  132. package/src/parsers/index.ts +7 -7
  133. package/src/parsers/parser-manager.ts +418 -419
  134. package/src/parsers/parser.ts +25 -25
  135. package/src/parsers/react-parser-optimized.ts +160 -160
  136. package/src/parsers/react-parser.ts +358 -358
  137. package/src/parsers/svelte-parser.ts +510 -510
  138. package/src/parsers/vanilla-parser.ts +685 -686
  139. package/src/parsers/vue-parser.ts +476 -478
  140. package/src/types/index.ts +95 -95
  141. package/src/ui/components.ts +567 -567
  142. package/src/ui/help.ts +192 -192
  143. package/src/ui/index.ts +3 -3
  144. package/src/ui/prompts.ts +680 -680
  145. package/src/ui/terminal-header.ts +58 -58
  146. package/test-build.js +40 -40
  147. package/test-config-commands.js +55 -55
  148. package/test-header-simple.js +32 -32
  149. package/test-terminal-header.js +11 -11
  150. package/test-ui.js +28 -28
  151. package/tests/e2e/baseguard.e2e.test.ts +515 -515
  152. package/tests/e2e/cross-platform.e2e.test.ts +419 -419
  153. package/tests/e2e/git-integration.e2e.test.ts +486 -486
  154. package/tests/fixtures/react-project/package.json +13 -13
  155. package/tests/fixtures/react-project/src/App.css +75 -75
  156. package/tests/fixtures/react-project/src/App.tsx +76 -76
  157. package/tests/fixtures/svelte-project/package.json +10 -10
  158. package/tests/fixtures/svelte-project/src/App.svelte +368 -368
  159. package/tests/fixtures/vanilla-project/index.html +75 -75
  160. package/tests/fixtures/vanilla-project/script.js +330 -330
  161. package/tests/fixtures/vanilla-project/styles.css +358 -358
  162. package/tests/fixtures/vue-project/package.json +11 -11
  163. package/tests/fixtures/vue-project/src/App.vue +215 -215
  164. package/tmp-smoke/.baseguard/backups/config-2026-02-19T12-04-11-067Z-auto.json +30 -0
  165. package/tmp-smoke/src/bad.css +3 -0
  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,299 +1,298 @@
1
- import { UIComponents } from '../ui/index.js';
2
- import { BaseGuard } from '../core/baseguard.js';
3
- import { ConfigurationManager } from '../core/configuration.js';
4
- import { ConfigurationRecovery } from '../core/configuration-recovery.js';
5
- import { GracefulDegradationManager } from '../core/graceful-degradation-manager.js';
6
- import { SystemErrorHandler } from '../core/system-error-handler.js';
7
- import { ErrorHandler } from '../core/error-handler.js';
8
- import { logger } from '../core/debug-logger.js';
9
- import { glob } from 'glob';
10
- import chalk from 'chalk';
11
- import type { Violation } from '../types/index.js';
12
-
13
- /**
14
- * Check for compatibility violations with enhanced error recovery
15
- */
16
- export async function check(options: {
17
- strict?: boolean;
18
- files?: string;
19
- format?: 'table' | 'json' | 'junit';
20
- debug?: boolean;
21
- offline?: boolean;
22
- }): Promise<void> {
23
- const categoryLogger = logger.createCategoryLogger('check-command');
24
- const sessionId = logger.startSession('check-command');
25
-
26
- try {
27
- // Enable debug logging if requested
28
- if (options.debug) {
29
- logger.enableDebug();
30
- }
31
-
32
- // Set offline mode if requested
33
- if (options.offline) {
34
- SystemErrorHandler.setOfflineMode(true);
35
- }
36
-
37
- UIComponents.showHeader();
38
- categoryLogger.info('Starting compatibility check', { options });
39
-
40
- // Load configuration with recovery
41
- const config = await SystemErrorHandler.withRetry(
42
- async () => {
43
- try {
44
- return await ConfigurationManager.load();
45
- } catch (error) {
46
- categoryLogger.warn('Configuration load failed, attempting recovery', { error });
47
-
48
- // Attempt configuration recovery
49
- const recoveryResult = await ConfigurationRecovery.recoverConfiguration({
50
- createBackup: true,
51
- validateConfig: true,
52
- migrateVersion: true,
53
- repairCorruption: true,
54
- useDefaults: true
55
- });
56
-
57
- if (recoveryResult.success && recoveryResult.config) {
58
- if (recoveryResult.warnings.length > 0) {
59
- console.log(chalk.yellow('āš ļø Configuration was recovered with warnings:'));
60
- recoveryResult.warnings.forEach(warning => {
61
- console.log(chalk.yellow(` • ${warning}`));
62
- });
63
- }
64
- return recoveryResult.config;
65
- } else {
66
- throw new Error(`Configuration recovery failed: ${recoveryResult.errors.join(', ')}`);
67
- }
68
- }
69
- },
70
- { operation: 'load_configuration' },
71
- 2 // max retries
72
- );
73
-
74
- // Initialize BaseGuard with error handling
75
- const baseGuard = await SystemErrorHandler.handleGracefully(
76
- async () => new BaseGuard(config),
77
- null,
78
- { operation: 'initialize_baseguard' }
79
- );
80
-
81
- if (!baseGuard) {
82
- throw new Error('Failed to initialize BaseGuard');
83
- }
84
-
85
- const spinner = UIComponents.createSpinner('Scanning files for compatibility issues...');
86
- spinner.start();
87
-
88
- // Get files to check with error recovery
89
- const filePattern = options.files || '**/*.{js,jsx,ts,tsx,vue,svelte,css,html}';
90
- const files = await SystemErrorHandler.handleGracefully(
91
- async () => {
92
- return await glob(filePattern, {
93
- ignore: [
94
- 'node_modules/**',
95
- 'dist/**',
96
- 'build/**',
97
- '.git/**',
98
- '**/*.min.js',
99
- '**/*.min.css'
100
- ]
101
- });
102
- },
103
- [], // fallback to empty array
104
- { operation: 'find_files', details: { pattern: filePattern } }
105
- );
106
-
107
- if (files.length === 0) {
108
- spinner.fail('No files found to check');
109
-
110
- // Show degradation status if in limited mode
111
- const mode = GracefulDegradationManager.getCurrentMode();
112
- if (mode && mode.name !== 'Full Functionality') {
113
- console.log(chalk.yellow(`\nāš ļø Currently in ${mode.name} mode`));
114
- if (mode.limitations.length > 0) {
115
- console.log(chalk.yellow('Limitations:'));
116
- mode.limitations.forEach(limitation => {
117
- console.log(chalk.yellow(` • ${limitation}`));
118
- });
119
- }
120
- }
121
-
122
- UIComponents.showWarningBox('No files matched the pattern. Try adjusting the --files option.');
123
- return;
124
- }
125
-
126
- spinner.text = `Analyzing ${files.length} files...`;
127
- categoryLogger.info(`Found ${files.length} files to analyze`);
128
-
129
- // Scan for violations with enhanced error handling
130
- const violations = await SystemErrorHandler.handleGracefully(
131
- async () => {
132
- return await baseGuard.checkViolations(files);
133
- },
134
- [], // fallback to empty violations
135
- { operation: 'check_violations', details: { fileCount: files.length } },
136
- {
137
- logError: true,
138
- showWarning: true,
139
- attemptRecovery: true
140
- }
141
- );
142
-
143
- spinner.stop();
144
- categoryLogger.info(`Scan completed, found ${violations.length} violations`);
145
-
146
- // Display results based on format with error handling
147
- await SystemErrorHandler.handleGracefully(
148
- async () => {
149
- switch (options.format) {
150
- case 'json':
151
- console.log(JSON.stringify(violations, null, 2));
152
- break;
153
- case 'junit':
154
- UIComponents.showJUnitReport(violations);
155
- break;
156
- default:
157
- UIComponents.showViolations(violations);
158
- break;
159
- }
160
- },
161
- undefined,
162
- { operation: 'display_results', details: { format: options.format, violationCount: violations.length } },
163
- { logError: true, showWarning: false }
164
- );
165
-
166
- // Show summary with degradation mode info
167
- if (violations.length === 0) {
168
- UIComponents.showSuccessBox('šŸŽ‰ No compatibility violations found!');
169
-
170
- // Show mode info if not in full functionality
171
- const mode = GracefulDegradationManager.getCurrentMode();
172
- if (mode && mode.name !== 'Full Functionality') {
173
- console.log(chalk.dim(`\nScan completed in ${mode.name} mode`));
174
- }
175
- } else {
176
- const summary = {
177
- total: violations.length,
178
- byBrowser: violations.reduce((acc, v) => {
179
- acc[v.browser] = (acc[v.browser] || 0) + 1;
180
- return acc;
181
- }, {} as Record<string, number>),
182
- byFile: violations.reduce((acc, v) => {
183
- acc[v.file] = (acc[v.file] || 0) + 1;
184
- return acc;
185
- }, {} as Record<string, number>)
186
- };
187
-
188
- console.log(chalk.yellow('\nšŸ“Š Summary:'));
189
- console.log(` Total violations: ${summary.total}`);
190
- console.log(` Files affected: ${Object.keys(summary.byFile).length}`);
191
- console.log(` Browsers affected: ${Object.keys(summary.byBrowser).join(', ')}`);
192
-
193
- // Show appropriate next steps based on current mode
194
- const mode = GracefulDegradationManager.getCurrentMode();
195
- if (mode?.capabilities.autoFix) {
196
- UIComponents.showInfoBox('Run "base fix" to automatically fix these issues with AI assistance.');
197
- } else {
198
- UIComponents.showInfoBox('AI fixing is not available in current mode. Review violations manually or restore full functionality.');
199
- }
200
-
201
- if (mode && mode.name !== 'Full Functionality') {
202
- console.log(chalk.dim(`\nScan completed in ${mode.name} mode`));
203
- if (mode.limitations.length > 0) {
204
- console.log(chalk.yellow('Current limitations:'));
205
- mode.limitations.forEach(limitation => {
206
- console.log(chalk.yellow(` • ${limitation}`));
207
- });
208
- }
209
- }
210
- }
211
-
212
- // Create auto-backup if violations found
213
- if (violations.length > 0) {
214
- await SystemErrorHandler.handleGracefully(
215
- async () => {
216
- const backup = await baseGuard.createConfigBackup();
217
- if (backup) {
218
- categoryLogger.debug('Created configuration backup', { backup });
219
- }
220
- },
221
- undefined,
222
- { operation: 'create_backup' },
223
- { logError: false, showWarning: false }
224
- );
225
- }
226
-
227
- // Exit with error code if violations found and strict mode
228
- if (options.strict && violations.length > 0) {
229
- process.exit(1);
230
- }
231
-
232
- } catch (error) {
233
- categoryLogger.error('Check command failed', { error });
234
-
235
- const apiError = ErrorHandler.handleAPIError(error);
236
- ErrorHandler.displayError(apiError);
237
-
238
- // Handle service failures gracefully
239
- if (ErrorHandler.shouldUseFallbackMode(apiError)) {
240
- await GracefulDegradationManager.handleServiceFailure('check', apiError.type);
241
- }
242
-
243
- // Provide specific help for check command issues
244
- console.log('\nšŸ’” Troubleshooting:');
245
- if (apiError.type === 'configuration') {
246
- UIComponents.showList([
247
- 'Run "base init" to set up BaseGuard configuration',
248
- 'Run "base config recover" to attempt automatic recovery',
249
- 'Check that .baseguardrc.json exists and is valid',
250
- 'Run "base config validate" to check configuration'
251
- ]);
252
- } else if (options.files) {
253
- UIComponents.showList([
254
- `No files found matching pattern: ${options.files}`,
255
- 'Try a different file pattern (e.g., "src/**/*.ts")',
256
- 'Check that files exist in the specified locations',
257
- 'Use --debug flag for detailed logging'
258
- ]);
259
- } else {
260
- UIComponents.showList([
261
- 'Check that you\'re in a project directory',
262
- 'Verify file permissions for reading project files',
263
- 'Try running with a specific file pattern: --files "src/**/*.js"',
264
- 'Use --offline flag if network issues are suspected',
265
- 'Use --debug flag for detailed error information'
266
- ]);
267
- }
268
-
269
- // Show fallback suggestions
270
- if (ErrorHandler.shouldUseFallbackMode(apiError)) {
271
- console.log('\nšŸ”„ Fallback options:');
272
- UIComponents.showList(ErrorHandler.getFallbackSuggestions(apiError.type));
273
- }
274
-
275
- // Show recovery options
276
- console.log('\nšŸ”§ Recovery options:');
277
- UIComponents.showList([
278
- 'Run "base status" to check system health',
279
- 'Run "base config recover" to fix configuration issues',
280
- 'Run with --debug flag to get detailed error information',
281
- 'Check logs in .baseguard/logs/ for more details'
282
- ]);
283
-
284
- // Generate debug report if in debug mode
285
- if (options.debug) {
286
- try {
287
- const reportFile = await logger.generateDebugReport();
288
- console.log(chalk.dim(`\nDebug report saved to: ${reportFile}`));
289
- } catch (reportError) {
290
- // Ignore report generation errors
291
- }
292
- }
293
-
294
- process.exit(1);
295
- } finally {
296
- // End logging session
297
- await logger.endSession();
298
- }
299
- }
1
+ import { UIComponents } from '../ui/index.js';
2
+ import { BaseGuard } from '../core/baseguard.js';
3
+ import { ConfigurationManager } from '../core/configuration.js';
4
+ import { ConfigurationRecovery } from '../core/configuration-recovery.js';
5
+ import { GracefulDegradationManager } from '../core/graceful-degradation-manager.js';
6
+ import { SystemErrorHandler } from '../core/system-error-handler.js';
7
+ import { ErrorHandler } from '../core/error-handler.js';
8
+ import { logger } from '../core/debug-logger.js';
9
+ import { glob } from 'glob';
10
+ import chalk from 'chalk';
11
+
12
+ /**
13
+ * Check for compatibility violations with enhanced error recovery
14
+ */
15
+ export async function check(options: {
16
+ strict?: boolean;
17
+ files?: string;
18
+ format?: 'table' | 'json' | 'junit';
19
+ debug?: boolean;
20
+ offline?: boolean;
21
+ }): Promise<void> {
22
+ const categoryLogger = logger.createCategoryLogger('check-command');
23
+ logger.startSession('check-command');
24
+
25
+ try {
26
+ // Enable debug logging if requested
27
+ if (options.debug) {
28
+ logger.enableDebug();
29
+ }
30
+
31
+ // Set offline mode if requested
32
+ if (options.offline) {
33
+ SystemErrorHandler.setOfflineMode(true);
34
+ }
35
+
36
+ UIComponents.showHeader();
37
+ categoryLogger.info('Starting compatibility check', { options });
38
+
39
+ // Load configuration with recovery
40
+ const config = await SystemErrorHandler.withRetry(
41
+ async () => {
42
+ try {
43
+ return await ConfigurationManager.load();
44
+ } catch (error) {
45
+ categoryLogger.warn('Configuration load failed, attempting recovery', { error });
46
+
47
+ // Attempt configuration recovery
48
+ const recoveryResult = await ConfigurationRecovery.recoverConfiguration({
49
+ createBackup: true,
50
+ validateConfig: true,
51
+ migrateVersion: true,
52
+ repairCorruption: true,
53
+ useDefaults: true
54
+ });
55
+
56
+ if (recoveryResult.success && recoveryResult.config) {
57
+ if (recoveryResult.warnings.length > 0) {
58
+ console.log(chalk.yellow('āš ļø Configuration was recovered with warnings:'));
59
+ recoveryResult.warnings.forEach(warning => {
60
+ console.log(chalk.yellow(` • ${warning}`));
61
+ });
62
+ }
63
+ return recoveryResult.config;
64
+ } else {
65
+ throw new Error(`Configuration recovery failed: ${recoveryResult.errors.join(', ')}`);
66
+ }
67
+ }
68
+ },
69
+ { operation: 'load_configuration' },
70
+ 2 // max retries
71
+ );
72
+
73
+ // Initialize BaseGuard with error handling
74
+ const baseGuard = await SystemErrorHandler.handleGracefully(
75
+ async () => new BaseGuard(config),
76
+ null,
77
+ { operation: 'initialize_baseguard' }
78
+ );
79
+
80
+ if (!baseGuard) {
81
+ throw new Error('Failed to initialize BaseGuard');
82
+ }
83
+
84
+ const spinner = UIComponents.createSpinner('Scanning files for compatibility issues...');
85
+ spinner.start();
86
+
87
+ // Get files to check with error recovery
88
+ const filePattern = options.files || '**/*.{js,jsx,ts,tsx,vue,svelte,css,html}';
89
+ const files = await SystemErrorHandler.handleGracefully(
90
+ async () => {
91
+ return await glob(filePattern, {
92
+ ignore: [
93
+ 'node_modules/**',
94
+ 'dist/**',
95
+ 'build/**',
96
+ '.git/**',
97
+ '**/*.min.js',
98
+ '**/*.min.css'
99
+ ]
100
+ });
101
+ },
102
+ [], // fallback to empty array
103
+ { operation: 'find_files', details: { pattern: filePattern } }
104
+ );
105
+
106
+ if (files.length === 0) {
107
+ spinner.fail('No files found to check');
108
+
109
+ // Show degradation status if in limited mode
110
+ const mode = GracefulDegradationManager.getCurrentMode();
111
+ if (mode && mode.name !== 'Full Functionality') {
112
+ console.log(chalk.yellow(`\nāš ļø Currently in ${mode.name} mode`));
113
+ if (mode.limitations.length > 0) {
114
+ console.log(chalk.yellow('Limitations:'));
115
+ mode.limitations.forEach(limitation => {
116
+ console.log(chalk.yellow(` • ${limitation}`));
117
+ });
118
+ }
119
+ }
120
+
121
+ UIComponents.showWarningBox('No files matched the pattern. Try adjusting the --files option.');
122
+ return;
123
+ }
124
+
125
+ spinner.text = `Analyzing ${files.length} files...`;
126
+ categoryLogger.info(`Found ${files.length} files to analyze`);
127
+
128
+ // Scan for violations with enhanced error handling
129
+ const violations = await SystemErrorHandler.handleGracefully(
130
+ async () => {
131
+ return await baseGuard.checkViolations(files);
132
+ },
133
+ [], // fallback to empty violations
134
+ { operation: 'check_violations', details: { fileCount: files.length } },
135
+ {
136
+ logError: true,
137
+ showWarning: true,
138
+ attemptRecovery: true
139
+ }
140
+ );
141
+
142
+ spinner.stop();
143
+ categoryLogger.info(`Scan completed, found ${violations.length} violations`);
144
+
145
+ // Display results based on format with error handling
146
+ await SystemErrorHandler.handleGracefully(
147
+ async () => {
148
+ switch (options.format) {
149
+ case 'json':
150
+ console.log(JSON.stringify(violations, null, 2));
151
+ break;
152
+ case 'junit':
153
+ UIComponents.showJUnitReport(violations);
154
+ break;
155
+ default:
156
+ UIComponents.showViolations(violations);
157
+ break;
158
+ }
159
+ },
160
+ undefined,
161
+ { operation: 'display_results', details: { format: options.format, violationCount: violations.length } },
162
+ { logError: true, showWarning: false }
163
+ );
164
+
165
+ // Show summary with degradation mode info
166
+ if (violations.length === 0) {
167
+ UIComponents.showSuccessBox('šŸŽ‰ No compatibility violations found!');
168
+
169
+ // Show mode info if not in full functionality
170
+ const mode = GracefulDegradationManager.getCurrentMode();
171
+ if (mode && mode.name !== 'Full Functionality') {
172
+ console.log(chalk.dim(`\nScan completed in ${mode.name} mode`));
173
+ }
174
+ } else {
175
+ const summary = {
176
+ total: violations.length,
177
+ byBrowser: violations.reduce((acc, v) => {
178
+ acc[v.browser] = (acc[v.browser] || 0) + 1;
179
+ return acc;
180
+ }, {} as Record<string, number>),
181
+ byFile: violations.reduce((acc, v) => {
182
+ acc[v.file] = (acc[v.file] || 0) + 1;
183
+ return acc;
184
+ }, {} as Record<string, number>)
185
+ };
186
+
187
+ console.log(chalk.yellow('\nšŸ“Š Summary:'));
188
+ console.log(` Total violations: ${summary.total}`);
189
+ console.log(` Files affected: ${Object.keys(summary.byFile).length}`);
190
+ console.log(` Browsers affected: ${Object.keys(summary.byBrowser).join(', ')}`);
191
+
192
+ // Show appropriate next steps based on current mode
193
+ const mode = GracefulDegradationManager.getCurrentMode();
194
+ if (mode?.capabilities.autoFix) {
195
+ UIComponents.showInfoBox('Run "base fix" to automatically fix these issues with AI assistance.');
196
+ } else {
197
+ UIComponents.showInfoBox('AI fixing is not available in current mode. Review violations manually or restore full functionality.');
198
+ }
199
+
200
+ if (mode && mode.name !== 'Full Functionality') {
201
+ console.log(chalk.dim(`\nScan completed in ${mode.name} mode`));
202
+ if (mode.limitations.length > 0) {
203
+ console.log(chalk.yellow('Current limitations:'));
204
+ mode.limitations.forEach(limitation => {
205
+ console.log(chalk.yellow(` • ${limitation}`));
206
+ });
207
+ }
208
+ }
209
+ }
210
+
211
+ // Create auto-backup if violations found
212
+ if (violations.length > 0) {
213
+ await SystemErrorHandler.handleGracefully(
214
+ async () => {
215
+ const backup = await baseGuard.createConfigBackup();
216
+ if (backup) {
217
+ categoryLogger.debug('Created configuration backup', { backup });
218
+ }
219
+ },
220
+ undefined,
221
+ { operation: 'create_backup' },
222
+ { logError: false, showWarning: false }
223
+ );
224
+ }
225
+
226
+ // Exit with error code if violations found and strict mode
227
+ if (options.strict && violations.length > 0) {
228
+ process.exit(1);
229
+ }
230
+
231
+ } catch (error) {
232
+ categoryLogger.error('Check command failed', { error });
233
+
234
+ const apiError = ErrorHandler.handleAPIError(error);
235
+ ErrorHandler.displayError(apiError);
236
+
237
+ // Handle service failures gracefully
238
+ if (ErrorHandler.shouldUseFallbackMode(apiError)) {
239
+ await GracefulDegradationManager.handleServiceFailure('check', apiError.type);
240
+ }
241
+
242
+ // Provide specific help for check command issues
243
+ console.log('\nšŸ’” Troubleshooting:');
244
+ if (apiError.type === 'configuration') {
245
+ UIComponents.showList([
246
+ 'Run "base init" to set up BaseGuard configuration',
247
+ 'Run "base config recover" to attempt automatic recovery',
248
+ 'Check that .baseguardrc.json exists and is valid',
249
+ 'Run "base config validate" to check configuration'
250
+ ]);
251
+ } else if (options.files) {
252
+ UIComponents.showList([
253
+ `No files found matching pattern: ${options.files}`,
254
+ 'Try a different file pattern (e.g., "src/**/*.ts")',
255
+ 'Check that files exist in the specified locations',
256
+ 'Use --debug flag for detailed logging'
257
+ ]);
258
+ } else {
259
+ UIComponents.showList([
260
+ 'Check that you\'re in a project directory',
261
+ 'Verify file permissions for reading project files',
262
+ 'Try running with a specific file pattern: --files "src/**/*.js"',
263
+ 'Use --offline flag if network issues are suspected',
264
+ 'Use --debug flag for detailed error information'
265
+ ]);
266
+ }
267
+
268
+ // Show fallback suggestions
269
+ if (ErrorHandler.shouldUseFallbackMode(apiError)) {
270
+ console.log('\nšŸ”„ Fallback options:');
271
+ UIComponents.showList(ErrorHandler.getFallbackSuggestions(apiError.type));
272
+ }
273
+
274
+ // Show recovery options
275
+ console.log('\nšŸ”§ Recovery options:');
276
+ UIComponents.showList([
277
+ 'Run "base status" to check system health',
278
+ 'Run "base config recover" to fix configuration issues',
279
+ 'Run with --debug flag to get detailed error information',
280
+ 'Check logs in .baseguard/logs/ for more details'
281
+ ]);
282
+
283
+ // Generate debug report if in debug mode
284
+ if (options.debug) {
285
+ try {
286
+ const reportFile = await logger.generateDebugReport();
287
+ console.log(chalk.dim(`\nDebug report saved to: ${reportFile}`));
288
+ } catch (reportError) {
289
+ // Ignore report generation errors
290
+ }
291
+ }
292
+
293
+ process.exit(1);
294
+ } finally {
295
+ // End logging session
296
+ await logger.endSession();
297
+ }
298
+ }