baseguard 1.0.3 → 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 (167) 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 +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.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 +264 -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 +564 -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/tsconfig.json +34 -34
  165. package/vitest.config.ts +11 -11
  166. package/dist/terminal-header.d.ts +0 -12
  167. package/dist/terminal-header.js +0 -45
@@ -1,238 +1,264 @@
1
- import chalk from 'chalk';
2
- import { UIComponents } from '../ui/index.js';
3
- import { BaseGuard } from '../core/index.js';
4
- import { ConfigurationManager } from '../core/configuration.js';
5
- import { ErrorHandler } from '../core/error-handler.js';
6
- import { UnifiedCodeFixer } from '../ai/unified-code-fixer.js';
7
- import { GeminiAnalyzer } from '../ai/gemini-analyzer.js';
8
- import { glob } from 'glob';
9
-
10
- /**
11
- * Fix violations with AI analysis and implementation
12
- */
13
- export async function fix(options: {
14
- auto?: boolean;
15
- analyzeOnly?: boolean;
16
- files?: string;
17
- }): Promise<void> {
18
- try {
19
- console.log(chalk.cyan('🔧 BaseGuard AI Fix\n'));
20
-
21
- // Load configuration
22
- const config = await ConfigurationManager.load();
23
-
24
- // Check API keys
25
- if (!config.apiKeys.jules) {
26
- UIComponents.showErrorBox('Jules API key not configured. Run "base init" to set up API keys.');
27
- process.exit(1);
28
- }
29
-
30
- if (!config.apiKeys.gemini) {
31
- UIComponents.showErrorBox('Gemini API key not configured. Run "base init" to set up API keys.');
32
- process.exit(1);
33
- }
34
-
35
- // Initialize services
36
- const baseGuard = new BaseGuard(config);
37
- const unifiedCodeFixer = new UnifiedCodeFixer(config);
38
- const geminiAnalyzer = new GeminiAnalyzer(config.apiKeys.gemini);
39
-
40
- // Show agent status and recommendations
41
- console.log(chalk.cyan('🤖 Coding Agent Status:'));
42
- const agentStatus = await unifiedCodeFixer.getAgentStatus();
43
-
44
- const primaryAvailable = agentStatus.primary === 'jules' ? agentStatus.jules.available : agentStatus.gemini.available;
45
- const fallbackAvailable = agentStatus.fallback === 'jules' ? agentStatus.jules.available : agentStatus.gemini.available;
46
-
47
- console.log(` Primary: ${agentStatus.primary} ${primaryAvailable ? '✅' : '❌'}`);
48
- console.log(` Fallback: ${agentStatus.fallback} ${fallbackAvailable ? '✅' : '❌'}`);
49
-
50
- if (!primaryAvailable && !fallbackAvailable) {
51
- console.log(chalk.red('\n❌ No coding agents are available'));
52
- console.log(chalk.cyan('💡 Configure API keys to enable code fixing:'));
53
- console.log(chalk.cyan(' • Run "base config set-keys" to configure API keys'));
54
- console.log(chalk.cyan(' Get Gemini API key: https://aistudio.google.com'));
55
- console.log(chalk.cyan(' Get Jules API key: https://jules.google.com/settings#api'));
56
- process.exit(1);
57
- }
58
-
59
- // Show agent-specific information
60
- if (agentStatus.primary === 'jules' && agentStatus.jules.repoDetected) {
61
- console.log(chalk.cyan('🔗 GitHub repository detected - Jules available for autonomous fixing'));
62
- } else if (agentStatus.primary === 'gemini' || !agentStatus.jules.repoDetected) {
63
- console.log(chalk.cyan('💎 Using Gemini 2.5 Pro for local file fixing'));
64
- console.log(chalk.dim(' This works with any local files, no GitHub required'));
65
- }
66
-
67
- // Step 1: Check for violations
68
- console.log(chalk.cyan('🔍 Scanning for compatibility violations...'));
69
-
70
- // Get files to fix
71
- const filePattern = options.files || '**/*.{js,jsx,ts,tsx,vue,svelte,css,html}';
72
- const files = await glob(filePattern, {
73
- ignore: [
74
- 'node_modules/**',
75
- 'dist/**',
76
- 'build/**',
77
- '.git/**',
78
- '**/*.min.js',
79
- '**/*.min.css'
80
- ]
81
- });
82
-
83
- const violations = await baseGuard.checkViolations(files);
84
-
85
- if (violations.length === 0) {
86
- UIComponents.showSuccessBox('No compatibility violations found!');
87
- return;
88
- }
89
-
90
- console.log(chalk.yellow(`\n⚠️ Found ${violations.length} compatibility violations\n`));
91
- UIComponents.showViolations(violations);
92
-
93
- // Step 2: Analyze violations with Gemini
94
- console.log(chalk.cyan('\n🧠 Analyzing violations with AI...'));
95
- const analyses = await geminiAnalyzer.analyzeViolations(violations);
96
-
97
- // If analyze-only mode, show analysis and exit
98
- if (options.analyzeOnly) {
99
- console.log(chalk.cyan('\n📋 Analysis Results:\n'));
100
- analyses.forEach((analysis, index) => {
101
- console.log(chalk.yellow(`${index + 1}. ${analysis.violation.feature} in ${analysis.violation.file}`));
102
- console.log(` Impact: ${analysis.userImpact}`);
103
- console.log(` Strategy: ${analysis.fixStrategy}`);
104
- console.log(` Confidence: ${Math.round(analysis.confidence * 100)}%\n`);
105
- });
106
- return;
107
- }
108
-
109
- // Step 3: Generate fixes with unified code fixer
110
- console.log(chalk.cyan(`\n🤖 Generating fixes with ${agentStatus.primary}...`));
111
-
112
- const fixes = [];
113
- let successCount = 0;
114
- let failedCount = 0;
115
-
116
- for (let i = 0; i < violations.length; i++) {
117
- const violation = violations[i];
118
- const analysis = analyses[i];
119
-
120
- if (!violation || !analysis) continue;
121
-
122
- try {
123
- console.log(chalk.cyan(`\n🔧 Fixing ${violation.feature} in ${violation.file}...`));
124
-
125
- const fix = await unifiedCodeFixer.generateFix(violation, analysis);
126
- fixes.push(fix);
127
- successCount++;
128
-
129
- console.log(chalk.green(`✅ Fix generated (confidence: ${Math.round(fix.confidence * 100)}%)`));
130
-
131
- // Show preview if not in auto mode
132
- if (!options.auto) {
133
- console.log(chalk.dim('\nPreview:'));
134
- console.log(chalk.dim(fix.preview.substring(0, 200) + (fix.preview.length > 200 ? '...' : '')));
135
- }
136
-
137
- } catch (error) {
138
- failedCount++;
139
- console.log(chalk.red(`❌ Failed to generate fix: ${error instanceof Error ? error.message : 'Unknown error'}`));
140
- }
141
- }
142
-
143
- if (fixes.length === 0) {
144
- console.log(chalk.yellow('\n⚠️ No fixes were generated'));
145
- return;
146
- }
147
-
148
- // Show results summary
149
- console.log(chalk.cyan('\n📊 Fix Generation Results:\n'));
150
- console.log(chalk.green(`✅ Generated ${successCount} fixes`));
151
- if (failedCount > 0) {
152
- console.log(chalk.red(`❌ Failed to generate ${failedCount} fixes`));
153
- }
154
-
155
- // Show fixes with previews
156
- if (!options.auto && fixes.length > 0) {
157
- console.log(chalk.cyan('\n🔍 Generated Fixes:\n'));
158
- fixes.forEach((fix, index) => {
159
- console.log(chalk.white(`${index + 1}. ${fix.violation.feature} in ${fix.filePath}`));
160
- console.log(chalk.dim(` Confidence: ${Math.round(fix.confidence * 100)}%`));
161
- console.log(chalk.dim(` Strategy: ${fix.analysis.fixStrategy}`));
162
-
163
- // Show a snippet of the explanation
164
- const explanation = fix.explanation?.split('\n')[0] || 'No explanation available';
165
- if (explanation.length > 80) {
166
- console.log(chalk.dim(` ${explanation.substring(0, 80)}...`));
167
- } else {
168
- console.log(chalk.dim(` ${explanation}`));
169
- }
170
- console.log();
171
- });
172
- }
173
-
174
- // Show summary
175
- console.log(chalk.cyan(`\n📈 Summary: ${successCount}/${violations.length} fixes generated successfully`));
176
-
177
- if (failedCount > 0) {
178
- console.log(chalk.yellow(`\n⚠️ ${failedCount} fixes failed to generate. This may be due to:`));
179
- console.log(chalk.yellow(' • Complex compatibility issues requiring manual review'));
180
- console.log(chalk.yellow(' • API rate limits or temporary service issues'));
181
- console.log(chalk.yellow(' • Files that couldn\'t be read or analyzed'));
182
- }
183
-
184
- // Show next steps
185
- console.log(chalk.cyan('\n💡 Next Steps:'));
186
- console.log(chalk.cyan(' • Review the generated fixes above'));
187
- console.log(chalk.cyan(' • Apply fixes manually to your code'));
188
- console.log(chalk.cyan(' Test your application after applying fixes'));
189
- console.log(chalk.cyan(' • Run "base check" to verify fixes resolve violations'));
190
-
191
- UIComponents.showSuccessBox('Fix process completed!');
192
-
193
- } catch (error) {
194
- const apiError = ErrorHandler.handleAPIError(error);
195
- ErrorHandler.displayError(apiError);
196
-
197
- // Provide specific help for fix command issues
198
- console.log('\n💡 Troubleshooting:');
199
- if (apiError.type === 'authentication') {
200
- UIComponents.showList([
201
- 'Check your API keys with "base config show"',
202
- 'Update API keys with "base config set-keys"',
203
- 'Verify API keys are valid and not expired',
204
- 'Ensure you have proper permissions for Jules and Gemini'
205
- ]);
206
- } else if (apiError.type === 'configuration') {
207
- UIComponents.showList([
208
- 'Run "base init" to set up BaseGuard configuration',
209
- 'Configure API keys with "base config set-keys"',
210
- 'Ensure you are in a GitHub repository for Jules fixing'
211
- ]);
212
- } else if (apiError.type === 'network') {
213
- UIComponents.showList([
214
- 'Check your internet connection',
215
- 'Verify firewall allows access to AI services',
216
- 'Try again when network connection is stable'
217
- ]);
218
- } else {
219
- UIComponents.showList([
220
- 'Try running "base check" for basic violation detection',
221
- 'Verify your API keys are configured correctly',
222
- 'Check the documentation for troubleshooting steps'
223
- ]);
224
- }
225
-
226
- // Show fallback suggestions
227
- if (ErrorHandler.shouldUseFallbackMode(apiError)) {
228
- console.log('\n🔄 Alternative options:');
229
- UIComponents.showList([
230
- 'Run "base check" for offline compatibility checking',
231
- 'Review violations manually using browser compatibility tables',
232
- 'Try AI features again when services are available'
233
- ]);
234
- }
235
-
236
- process.exit(1);
237
- }
238
- }
1
+ import chalk from 'chalk';
2
+ import { UIComponents } from '../ui/index.js';
3
+ import { BaseGuard } from '../core/index.js';
4
+ import { ConfigurationManager } from '../core/configuration.js';
5
+ import { ErrorHandler } from '../core/error-handler.js';
6
+ import { UnifiedCodeFixer } from '../ai/unified-code-fixer.js';
7
+ import { GeminiAnalyzer } from '../ai/gemini-analyzer.js';
8
+ import { FixManager } from '../ai/fix-manager.js';
9
+ import { glob } from 'glob';
10
+
11
+ /**
12
+ * Fix violations with AI analysis and implementation
13
+ */
14
+ export async function fix(options: {
15
+ auto?: boolean;
16
+ analyzeOnly?: boolean;
17
+ files?: string;
18
+ }): Promise<void> {
19
+ try {
20
+ console.log(chalk.cyan('🔧 BaseGuard AI Fix\n'));
21
+
22
+ // Load configuration
23
+ const config = await ConfigurationManager.load();
24
+
25
+ // Initialize services
26
+ const baseGuard = new BaseGuard(config);
27
+ const unifiedCodeFixer = new UnifiedCodeFixer(config);
28
+ const fixManager = new FixManager();
29
+ const geminiAnalyzer = config.apiKeys.gemini ? new GeminiAnalyzer(config.apiKeys.gemini) : null;
30
+
31
+ // Show agent status and recommendations
32
+ console.log(chalk.cyan('🤖 Coding Agent Status:'));
33
+ const agentStatus = await unifiedCodeFixer.getAgentStatus();
34
+
35
+ const primaryAvailable = agentStatus.primary === 'jules' ? agentStatus.jules.available : agentStatus.gemini.available;
36
+ const fallbackAvailable = agentStatus.fallback === 'jules' ? agentStatus.jules.available : agentStatus.gemini.available;
37
+
38
+ console.log(` Primary: ${agentStatus.primary} ${primaryAvailable ? '✅' : '❌'}`);
39
+ console.log(` Fallback: ${agentStatus.fallback} ${fallbackAvailable ? '✅' : '❌'}`);
40
+
41
+ if (!agentStatus.jules.configured && !agentStatus.gemini.configured) {
42
+ console.log(chalk.red('\n❌ No coding agents are available'));
43
+ console.log(chalk.cyan('💡 Configure API keys to enable code fixing:'));
44
+ console.log(chalk.cyan(' • Run "base config set-keys" to configure API keys'));
45
+ console.log(chalk.cyan(' • Get Gemini API key: https://aistudio.google.com'));
46
+ console.log(chalk.cyan(' • Get Jules API key: https://jules.google.com/settings#api'));
47
+ process.exit(1);
48
+ }
49
+
50
+ // Show agent-specific information
51
+ if (agentStatus.primary === 'jules' && agentStatus.jules.repoDetected) {
52
+ console.log(chalk.cyan('🔗 GitHub repository detected - Jules available for autonomous fixing'));
53
+ } else if (agentStatus.primary === 'gemini' || !agentStatus.jules.repoDetected) {
54
+ console.log(chalk.cyan('💎 Using Gemini 2.5 Pro for local file fixing'));
55
+ console.log(chalk.dim(' This works with any local files, no GitHub required'));
56
+ }
57
+
58
+ // Step 1: Check for violations
59
+ console.log(chalk.cyan('🔍 Scanning for compatibility violations...'));
60
+
61
+ // Get files to fix
62
+ const filePattern = options.files || '**/*.{js,jsx,ts,tsx,vue,svelte,css,html}';
63
+ const files = await glob(filePattern, {
64
+ ignore: [
65
+ 'node_modules/**',
66
+ 'dist/**',
67
+ 'build/**',
68
+ '.git/**',
69
+ '**/*.min.js',
70
+ '**/*.min.css'
71
+ ]
72
+ });
73
+
74
+ const violations = await baseGuard.checkViolations(files);
75
+
76
+ if (violations.length === 0) {
77
+ UIComponents.showSuccessBox('No compatibility violations found!');
78
+ return;
79
+ }
80
+
81
+ console.log(chalk.yellow(`\n⚠️ Found ${violations.length} compatibility violations\n`));
82
+ UIComponents.showViolations(violations);
83
+
84
+ // Step 2: Analyze violations with Gemini
85
+ let analyses;
86
+ if (geminiAnalyzer) {
87
+ console.log(chalk.cyan('\n🧠 Analyzing violations with AI...'));
88
+ analyses = await geminiAnalyzer.analyzeViolations(violations);
89
+ } else {
90
+ console.log(chalk.yellow('\n⚠️ Gemini API key not configured, using fallback analysis...'));
91
+ analyses = await baseGuard.analyzeViolations(violations);
92
+ }
93
+
94
+ // If analyze-only mode, show analysis and exit
95
+ if (options.analyzeOnly) {
96
+ console.log(chalk.cyan('\n📋 Analysis Results:\n'));
97
+ analyses.forEach((analysis, index) => {
98
+ console.log(chalk.yellow(`${index + 1}. ${analysis.violation.feature} in ${analysis.violation.file}`));
99
+ console.log(` Impact: ${analysis.userImpact}`);
100
+ console.log(` Strategy: ${analysis.fixStrategy}`);
101
+ console.log(` Confidence: ${Math.round(analysis.confidence * 100)}%\n`);
102
+ });
103
+ return;
104
+ }
105
+
106
+ // Step 3: Generate fixes with unified code fixer
107
+ console.log(chalk.cyan(`\n🤖 Generating fixes with ${agentStatus.primary}...`));
108
+
109
+ const fixes = [];
110
+ let successCount = 0;
111
+ let failedCount = 0;
112
+
113
+ for (let i = 0; i < violations.length; i++) {
114
+ const violation = violations[i];
115
+ const analysis = analyses[i];
116
+
117
+ if (!violation || !analysis) continue;
118
+
119
+ try {
120
+ console.log(chalk.cyan(`\n🔧 Fixing ${violation.feature} in ${violation.file}...`));
121
+
122
+ const fix = await unifiedCodeFixer.generateFix(violation, analysis);
123
+ fixes.push(fix);
124
+ successCount++;
125
+
126
+ console.log(chalk.green(`✅ Fix generated (confidence: ${Math.round(fix.confidence * 100)}%)`));
127
+
128
+ // Show preview if not in auto mode
129
+ if (!options.auto) {
130
+ console.log(chalk.dim('\nPreview:'));
131
+ console.log(chalk.dim(fix.preview.substring(0, 200) + (fix.preview.length > 200 ? '...' : '')));
132
+ }
133
+
134
+ } catch (error) {
135
+ failedCount++;
136
+ console.log(chalk.red(`❌ Failed to generate fix: ${error instanceof Error ? error.message : 'Unknown error'}`));
137
+ }
138
+ }
139
+
140
+ if (fixes.length === 0) {
141
+ console.log(chalk.yellow('\n⚠️ No fixes were generated'));
142
+ return;
143
+ }
144
+
145
+ // Show results summary
146
+ console.log(chalk.cyan('\n📊 Fix Generation Results:\n'));
147
+ console.log(chalk.green(`✅ Generated ${successCount} fixes`));
148
+ if (failedCount > 0) {
149
+ console.log(chalk.red(`❌ Failed to generate ${failedCount} fixes`));
150
+ }
151
+
152
+ // Show fixes with previews
153
+ if (!options.auto && fixes.length > 0) {
154
+ console.log(chalk.cyan('\n🔍 Generated Fixes:\n'));
155
+ fixes.forEach((fix, index) => {
156
+ console.log(chalk.white(`${index + 1}. ${fix.violation.feature} in ${fix.filePath}`));
157
+ console.log(chalk.dim(` Confidence: ${Math.round(fix.confidence * 100)}%`));
158
+ console.log(chalk.dim(` Strategy: ${fix.analysis.fixStrategy}`));
159
+
160
+ // Show a snippet of the explanation
161
+ const explanation = fix.explanation?.split('\n')[0] || 'No explanation available';
162
+ if (explanation.length > 80) {
163
+ console.log(chalk.dim(` ${explanation.substring(0, 80)}...`));
164
+ } else {
165
+ console.log(chalk.dim(` ${explanation}`));
166
+ }
167
+ console.log();
168
+ });
169
+ }
170
+
171
+ // Step 4: Apply fixes
172
+ let appliedCount = 0;
173
+ let skippedCount = 0;
174
+ let applyFailedCount = 0;
175
+
176
+ if (options.auto) {
177
+ console.log(chalk.cyan('\n⚡ Applying fixes automatically...'));
178
+ for (const fix of fixes) {
179
+ try {
180
+ await fixManager.applyFix(fix);
181
+ appliedCount++;
182
+ } catch (error) {
183
+ applyFailedCount++;
184
+ console.log(chalk.red(`❌ Failed to apply fix for ${fix.filePath}: ${error instanceof Error ? error.message : 'Unknown error'}`));
185
+ }
186
+ }
187
+ } else {
188
+ console.log(chalk.cyan('\n🧩 Review and apply fixes:'));
189
+ const results = await fixManager.applyFixes(fixes);
190
+ appliedCount = results.applied.length;
191
+ skippedCount = results.skipped.length;
192
+ applyFailedCount = results.failed.length;
193
+ }
194
+
195
+ // Show summary
196
+ console.log(chalk.cyan(`\n📈 Summary: ${successCount}/${violations.length} fixes generated successfully`));
197
+ console.log(chalk.green(`✅ Applied fixes: ${appliedCount}`));
198
+ if (skippedCount > 0) {
199
+ console.log(chalk.yellow(`⏭️ Skipped fixes: ${skippedCount}`));
200
+ }
201
+ if (applyFailedCount > 0) {
202
+ console.log(chalk.red(`❌ Failed to apply: ${applyFailedCount}`));
203
+ }
204
+
205
+ if (failedCount > 0) {
206
+ console.log(chalk.yellow(`\n⚠️ ${failedCount} fixes failed to generate. This may be due to:`));
207
+ console.log(chalk.yellow(' • Complex compatibility issues requiring manual review'));
208
+ console.log(chalk.yellow(' API rate limits or temporary service issues'));
209
+ console.log(chalk.yellow(' Files that couldn\'t be read or analyzed'));
210
+ }
211
+
212
+ // Show next steps
213
+ console.log(chalk.cyan('\n💡 Next Steps:'));
214
+ console.log(chalk.cyan(' Test your application after applying fixes'));
215
+ console.log(chalk.cyan(' Run "base check" to verify fixes resolve violations'));
216
+
217
+ UIComponents.showSuccessBox('Fix process completed!');
218
+
219
+ } catch (error) {
220
+ const apiError = ErrorHandler.handleAPIError(error);
221
+ ErrorHandler.displayError(apiError);
222
+
223
+ // Provide specific help for fix command issues
224
+ console.log('\n💡 Troubleshooting:');
225
+ if (apiError.type === 'authentication') {
226
+ UIComponents.showList([
227
+ 'Check your API keys with "base config show"',
228
+ 'Update API keys with "base config set-keys"',
229
+ 'Verify API keys are valid and not expired',
230
+ 'Ensure you have proper permissions for Jules and Gemini'
231
+ ]);
232
+ } else if (apiError.type === 'configuration') {
233
+ UIComponents.showList([
234
+ 'Run "base init" to set up BaseGuard configuration',
235
+ 'Configure API keys with "base config set-keys"',
236
+ 'Ensure you are in a GitHub repository for Jules fixing'
237
+ ]);
238
+ } else if (apiError.type === 'network') {
239
+ UIComponents.showList([
240
+ 'Check your internet connection',
241
+ 'Verify firewall allows access to AI services',
242
+ 'Try again when network connection is stable'
243
+ ]);
244
+ } else {
245
+ UIComponents.showList([
246
+ 'Try running "base check" for basic violation detection',
247
+ 'Verify your API keys are configured correctly',
248
+ 'Check the documentation for troubleshooting steps'
249
+ ]);
250
+ }
251
+
252
+ // Show fallback suggestions
253
+ if (ErrorHandler.shouldUseFallbackMode(apiError)) {
254
+ console.log('\n🔄 Alternative options:');
255
+ UIComponents.showList([
256
+ 'Run "base check" for offline compatibility checking',
257
+ 'Review violations manually using browser compatibility tables',
258
+ 'Try AI features again when services are available'
259
+ ]);
260
+ }
261
+
262
+ process.exit(1);
263
+ }
264
+ }
@@ -1,7 +1,7 @@
1
- // CLI command exports
2
- export * from './init.js';
3
- export * from './check.js';
4
- export * from './fix.js';
5
- export * from './config.js';
6
- export * from './automation.js';
1
+ // CLI command exports
2
+ export * from './init.js';
3
+ export * from './check.js';
4
+ export * from './fix.js';
5
+ export * from './config.js';
6
+ export * from './automation.js';
7
7
  export { status, diagnostics } from './status.js';