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
package/bin/base.js CHANGED
@@ -1,613 +1,628 @@
1
- #!/usr/bin/env node
2
-
3
- import { Command } from 'commander';
4
- import chalk from 'chalk';
5
- import { init, check, fix, config, automation, status, diagnostics } from '../dist/commands/index.js';
6
- import { showTerminalHeader, showVersionInfo, showGlobalHelp } from '../dist/ui/index.js';
7
- import { StartupOptimizer } from '../dist/core/startup-optimizer.js';
8
-
9
- // Initialize startup optimizations
10
- const startupPromise = StartupOptimizer.initialize().then(() => {
11
- // Run additional startup optimizations
12
- return StartupOptimizer.optimizeStartup();
13
- });
14
-
15
- const program = new Command();
16
-
17
- program
18
- .name('base')
19
- .description(chalk.cyan('🛡️ BaseGuard - Never ship incompatible code again\n') +
20
- chalk.dim('Intelligent browser compatibility enforcement with AI-powered analysis and autonomous fixing'))
21
- .version('1.0.2')
22
- .configureOutput({
23
- outputError: (str, write) => write(chalk.red(str))
24
- })
25
- .configureHelp({
26
- helpWidth: 100,
27
- sortSubcommands: true
28
- })
29
- .addHelpText('after', `
30
- ${chalk.cyan('Examples:')}
31
- ${chalk.dim('$')} base init ${chalk.gray('# Initialize BaseGuard in your project')}
32
- ${chalk.dim('$')} base check ${chalk.gray('# Check for compatibility violations')}
33
- ${chalk.dim('$')} base fix ${chalk.gray('# Fix violations with AI assistance')}
34
- ${chalk.dim('$')} base config set-keys ${chalk.gray('# Configure API keys for AI services')}
35
- ${chalk.dim('$')} base automation enable ${chalk.gray('# Enable git hooks for automatic checking')}
36
-
37
- ${chalk.cyan('Getting Started:')}
38
- 1. Run ${chalk.white('base init')} to set up BaseGuard in your project
39
- 2. Configure API keys with ${chalk.white('base config set-keys')} for AI features
40
- 3. Enable automation with ${chalk.white('base automation enable')}
41
- 4. Check compatibility with ${chalk.white('base check')}
42
-
43
- ${chalk.cyan('Documentation:')}
44
- ${chalk.blue('https://github.com/baseguard/baseguard#readme')}
45
-
46
- ${chalk.cyan('Support:')}
47
- ${chalk.blue('https://github.com/baseguard/baseguard/issues')}
48
- `);
49
-
50
- // Initialize BaseGuard in project
51
- program
52
- .command('init')
53
- .description('Initialize BaseGuard in your project with guided setup')
54
- .option('--preset <preset>', 'Browser target preset (baseline-widely, baseline-newly, last-2-years, custom)', 'baseline-widely')
55
- .option('--skip-hooks', 'Skip git hook installation during setup')
56
- .option('--skip-api-keys', 'Skip API key configuration during setup')
57
- .addHelpText('after', `
58
- ${chalk.cyan('Browser Target Presets:')}
59
- ${chalk.white('baseline-widely')} Support features available in Baseline for 30+ months
60
- ${chalk.white('baseline-newly')} Support newly available Baseline features
61
- ${chalk.white('last-2-years')} Support browsers from the last 2 years
62
- ${chalk.white('custom')} Configure custom browser targets interactively
63
-
64
- ${chalk.cyan('Examples:')}
65
- ${chalk.dim('$')} base init ${chalk.gray('# Interactive setup with baseline-widely preset')}
66
- ${chalk.dim('$')} base init --preset baseline-newly ${chalk.gray('# Use baseline-newly preset')}
67
- ${chalk.dim('$')} base init --skip-hooks ${chalk.gray('# Skip git hook installation')}
68
- ${chalk.dim('$')} base init --preset custom ${chalk.gray('# Configure custom browser targets')}
69
-
70
- ${chalk.cyan('What this does:')}
71
- Creates .baseguardrc.json configuration file
72
- Sets up browser compatibility targets
73
- Configures API keys for AI services (optional)
74
- • Installs git hooks for automation (optional)
75
- • Adds .baseguardrc.json to .gitignore for security
76
- `)
77
- .action(async (options) => {
78
- await startupPromise;
79
- await StartupOptimizer.optimizeForUseCase('init');
80
- return init(options);
81
- });
82
-
83
- // Check for compatibility violations
84
- program
85
- .command('check')
86
- .description('Scan code for browser compatibility violations using Baseline data')
87
- .option('--strict', 'Exit with error code if violations are found (useful for CI/CD)')
88
- .option('--files <pattern>', 'File pattern to check using glob syntax', '**/*.{js,jsx,ts,tsx,vue,svelte,css,html}')
89
- .option('--format <format>', 'Output format for results', 'table')
90
- .option('--debug', 'Enable debug logging for troubleshooting')
91
- .option('--offline', 'Run in offline mode (no network requests)')
92
- .addHelpText('after', `
93
- ${chalk.cyan('Output Formats:')}
94
- ${chalk.white('table')} Human-readable table format (default)
95
- ${chalk.white('json')} JSON format for programmatic use
96
- ${chalk.white('junit')} JUnit XML format for CI/CD integration
97
-
98
- ${chalk.cyan('Examples:')}
99
- ${chalk.dim('$')} base check ${chalk.gray('# Check all supported files')}
100
- ${chalk.dim('$')} base check --strict ${chalk.gray('# Exit with error if violations found')}
101
- ${chalk.dim('$')} base check --files "src/**/*.ts" ${chalk.gray('# Check only TypeScript files in src/')}
102
- ${chalk.dim('$')} base check --format json ${chalk.gray('# Output results as JSON')}
103
- ${chalk.dim('$')} base check --files "*.css" --strict ${chalk.gray('# Check CSS files with strict mode')}
104
-
105
- ${chalk.cyan('File Patterns:')}
106
- Supports glob patterns like:
107
- ${chalk.white('"src/**/*.{js,ts}"')} - All JS/TS files in src/ and subdirectories
108
- ${chalk.white('"components/*.vue"')} - All Vue files in components/
109
- • ${chalk.white('"**/*.css"')} - All CSS files in project
110
-
111
- ${chalk.cyan('What this checks:')}
112
- CSS properties, selectors, and at-rules
113
- JavaScript APIs and ECMAScript features
114
- HTML elements and attributes
115
- • Framework-specific files (React, Vue, Svelte)
116
- • Web platform APIs (Canvas, WebGL, WebRTC, WebAssembly, etc.)
117
- `)
118
- .action(async (options) => {
119
- await startupPromise;
120
- await StartupOptimizer.optimizeForUseCase('check');
121
- return check(options);
122
- });
123
-
124
- // Fix violations with AI
125
- program
126
- .command('fix')
127
- .description('Analyze and fix compatibility violations using AI (requires API keys)')
128
- .option('--auto', 'Apply fixes automatically without interactive confirmation')
129
- .option('--analyze-only', 'Only run AI analysis without generating code fixes')
130
- .option('--files <pattern>', 'File pattern to fix using glob syntax', '**/*.{js,jsx,ts,tsx,vue,svelte,css,html}')
131
- .addHelpText('after', `
132
- ${chalk.cyan('Prerequisites:')}
133
- • Gemini API key (for analysis and fixing) - Get from ${chalk.blue('https://aistudio.google.com')}
134
- • Jules API key (optional, for GitHub repos) - Get from ${chalk.blue('https://jules.google.com')}
135
- Choose your coding agent: "base config coding-agent"
136
-
137
- ${chalk.cyan('Examples:')}
138
- ${chalk.dim('$')} base fix ${chalk.gray('# Interactive fix with confirmation prompts')}
139
- ${chalk.dim('$')} base fix --auto ${chalk.gray('# Apply all fixes automatically')}
140
- ${chalk.dim('$')} base fix --analyze-only ${chalk.gray('# Only analyze, don\'t generate fixes')}
141
- ${chalk.dim('$')} base fix --files "src/**/*.css" ${chalk.gray('# Fix only CSS files in src/')}
142
-
143
- ${chalk.cyan('How it works:')}
144
- 1. ${chalk.white('Scan')} - Detects compatibility violations using Baseline data
145
- 2. ${chalk.white('Analyze')} - Gemini AI researches impact and fix strategies
146
- 3. ${chalk.white('Fix')} - AI generates progressive enhancement code (Jules or Gemini)
147
- 4. ${chalk.white('Review')} - Shows preview of changes before applying
148
- 5. ${chalk.white('Apply')} - Updates files with compatibility fixes
149
-
150
- ${chalk.cyan('Coding Agents:')}
151
- ${chalk.white('Gemini 2.5 Pro')} - Works with any files, immediate processing
152
- ${chalk.white('Jules')} - GitHub repos only, autonomous cloud processing
153
-
154
- ${chalk.cyan('Fix Strategies:')}
155
- Progressive enhancement with @supports for CSS
156
- Feature detection for JavaScript APIs
157
- Polyfills and fallbacks for older browsers
158
- • Graceful degradation patterns
159
-
160
- ${chalk.cyan('Setup:')}
161
- Run ${chalk.white('base config set-keys')} to configure API keys
162
- Run ${chalk.white('base config coding-agent')} to choose your preferred agent
163
- `)
164
- .action(async (options) => {
165
- await startupPromise;
166
- await StartupOptimizer.optimizeForUseCase('fix');
167
- return fix(options);
168
- });
169
-
170
- // Configuration management
171
- const configCmd = program
172
- .command('config')
173
- .description('Manage BaseGuard configuration and settings')
174
- .addHelpText('after', `
175
- ${chalk.cyan('Configuration Commands:')}
176
- ${chalk.white('show')} Display detailed configuration with security status
177
- ${chalk.white('list')} Show configuration summary (supports --format json)
178
- ${chalk.white('set-keys')} Interactive API key setup with browser integration
179
- ${chalk.white('targets')} Manage browser compatibility targets
180
- ${chalk.white('validate')} Check configuration file for errors
181
- ${chalk.white('automation')} Configure git automation settings
182
-
183
- ${chalk.cyan('Examples:')}
184
- ${chalk.dim('$')} base config show ${chalk.gray('# Show detailed configuration')}
185
- ${chalk.dim('$')} base config set-keys ${chalk.gray('# Set up API keys interactively')}
186
- ${chalk.dim('$')} base config list --format json ${chalk.gray('# Export configuration as JSON')}
187
- ${chalk.dim('$')} base config targets --preset baseline-widely ${chalk.gray('# Set browser targets')}
188
- `);
189
-
190
- configCmd
191
- .command('show')
192
- .description('Display detailed configuration with security and validation status')
193
- .addHelpText('after', `
194
- ${chalk.cyan('What this shows:')}
195
- • Current browser targets and presets
196
- • API key configuration status (without exposing keys)
197
- Automation and git hook settings
198
- • Security status (.gitignore configuration)
199
- Configuration validation results
200
- Recommendations for improvements
201
- `)
202
- .action(() => config('show'));
203
-
204
- configCmd
205
- .command('set-keys')
206
- .description('Interactive setup of API keys for AI services')
207
- .addHelpText('after', `
208
- ${chalk.cyan('API Services:')}
209
- ${chalk.white('Gemini')} - For AI analysis of compatibility issues
210
- Get your key: ${chalk.blue('https://aistudio.google.com')}
211
-
212
- ${chalk.white('Jules')} - For autonomous code fixing
213
- Get your key: ${chalk.blue('https://jules.google.com')}
214
-
215
- ${chalk.cyan('Security:')}
216
- • Keys are stored in .baseguardrc.json
217
- File is automatically added to .gitignore
218
- Keys are validated before saving
219
- `)
220
- .action(() => config('set-keys'));
221
-
222
- configCmd
223
- .command('targets')
224
- .description('Manage browser compatibility targets')
225
- .option('--add <target>', 'Add browser target (format: "browser version")')
226
- .option('--remove <target>', 'Remove browser target by name')
227
- .option('--preset <preset>', 'Set predefined browser targets')
228
- .addHelpText('after', `
229
- ${chalk.cyan('Target Formats:')}
230
- ${chalk.white('"chrome 100"')} Minimum Chrome version 100
231
- ${chalk.white('"safari baseline"')} Safari with Baseline support only
232
- ${chalk.white('"firefox 90"')} Minimum Firefox version 90
233
-
234
- ${chalk.cyan('Available Presets:')}
235
- ${chalk.white('baseline-widely')} Features available for 30+ months
236
- ${chalk.white('baseline-newly')} Newly available Baseline features
237
- ${chalk.white('last-2-years')} Browsers from last 2 years
238
-
239
- ${chalk.cyan('Examples:')}
240
- ${chalk.dim('$')} base config targets --add "chrome 100"
241
- ${chalk.dim('$')} base config targets --remove chrome
242
- ${chalk.dim('$')} base config targets --preset baseline-widely
243
- `)
244
- .action((options) => config('targets', options));
245
-
246
- configCmd
247
- .command('list')
248
- .description('Show configuration summary with status information')
249
- .option('--format <format>', 'Output format (table or json)', 'table')
250
- .addHelpText('after', `
251
- ${chalk.cyan('Output Formats:')}
252
- ${chalk.white('table')} Human-readable summary (default)
253
- ${chalk.white('json')} Machine-readable JSON for scripts
254
-
255
- ${chalk.cyan('Includes:')}
256
- Browser targets and count
257
- API key configuration status
258
- Automation settings
259
- • Security and validation status
260
- `)
261
- .action((options) => config('list', options));
262
-
263
- configCmd
264
- .command('validate')
265
- .description('Validate configuration file for errors and inconsistencies')
266
- .addHelpText('after', `
267
- ${chalk.cyan('Validation Checks:')}
268
- • Configuration file syntax and structure
269
- • Browser target format and validity
270
- API key format validation
271
- Automation setting consistency
272
- Required field presence
273
-
274
- ${chalk.cyan('Exit Codes:')}
275
- 0 - Configuration is valid
276
- 1 - Validation errors found
277
- `)
278
- .action(() => config('validate'));
279
-
280
- configCmd
281
- .command('automation')
282
- .description('Configure git automation settings interactively')
283
- .addHelpText('after', `
284
- ${chalk.cyan('Automation Settings:')}
285
- • Enable/disable git hooks
286
- • Choose trigger (pre-commit or pre-push)
287
- Configure auto-analysis with Gemini
288
- Configure auto-fixing with Jules
289
- Set commit blocking behavior
290
- `)
291
- .action(() => config('automation'));
292
-
293
- configCmd
294
- .command('recover')
295
- .description('Attempt automatic recovery of corrupted configuration')
296
- .option('--backup', 'Create backup before recovery')
297
- .option('--interactive', 'Run interactive recovery wizard')
298
- .addHelpText('after', `
299
- ${chalk.cyan('Recovery Features:')}
300
- Automatic detection of configuration issues
301
- Repair of corrupted JSON syntax
302
- Migration from older configuration versions
303
- Validation and structure repair
304
- Backup creation before changes
305
-
306
- ${chalk.cyan('Recovery Process:')}
307
- 1. Validates current configuration
308
- 2. Creates backup if requested
309
- 3. Attempts automatic repair
310
- 4. Migrates to current version
311
- 5. Validates final result
312
-
313
- ${chalk.cyan('Examples:')}
314
- ${chalk.dim('$')} base config recover ${chalk.gray('# Automatic recovery')}
315
- ${chalk.dim('$')} base config recover --backup ${chalk.gray('# Create backup first')}
316
- ${chalk.dim('$')} base config recover --interactive ${chalk.gray('# Interactive wizard')}
317
- `)
318
- .action((options) => config('recover', options));
319
-
320
- configCmd
321
- .command('coding-agent')
322
- .description('Manage coding agent selection (Jules vs Gemini)')
323
- .option('--agent <agent>', 'Set primary agent (jules or gemini)')
324
- .option('--show', 'Show current agent configuration and status')
325
- .addHelpText('after', `
326
- ${chalk.cyan('Coding Agents:')}
327
- ${chalk.white('Jules')} - Google's autonomous coding agent (GitHub repos only)
328
- ${chalk.white('Gemini')} - Gemini 2.5 Pro direct API (works with any files)
329
-
330
- ${chalk.cyan('Agent Comparison:')}
331
- Jules:
332
- Autonomous operation in cloud VMs
333
- Full repository context understanding
334
- ✅ Asynchronous processing
335
- Requires GitHub repository
336
- ❌ Cannot work with local/uncommitted files
337
-
338
- Gemini:
339
- Works with any files (GitHub or not)
340
- Immediate processing
341
- Works with uncommitted/local files
342
- ✅ Grounded with real-time web search
343
- ⚠️ Requires manual code application
344
-
345
- ${chalk.cyan('Examples:')}
346
- ${chalk.dim('$')} base config coding-agent --show ${chalk.gray('# Show current configuration')}
347
- ${chalk.dim('$')} base config coding-agent --agent gemini ${chalk.gray('# Set Gemini as primary')}
348
- ${chalk.dim('$')} base config coding-agent --agent jules ${chalk.gray('# Set Jules as primary')}
349
- ${chalk.dim('$')} base config coding-agent ${chalk.gray('# Interactive selection')}
350
- `)
351
- .action((options) => config('coding-agent', options));
352
-
353
- // Automation and git hooks
354
- const autoCmd = program
355
- .command('automation')
356
- .alias('auto')
357
- .description('Manage git automation and hooks for continuous compatibility checking')
358
- .addHelpText('after', `
359
- ${chalk.cyan('Automation Features:')}
360
- • Automatic compatibility checking on git operations
361
- • AI-powered analysis and fixing integration
362
- Commit blocking when violations are found
363
- • Configurable triggers (pre-commit or pre-push)
364
-
365
- ${chalk.cyan('Examples:')}
366
- ${chalk.dim('$')} base automation enable ${chalk.gray('# Enable with interactive setup')}
367
- ${chalk.dim('$')} base automation enable --trigger pre-push ${chalk.gray('# Enable with pre-push trigger')}
368
- ${chalk.dim('$')} base automation status ${chalk.gray('# Show current automation status')}
369
- ${chalk.dim('$')} base automation disable ${chalk.gray('# Disable automation and remove hooks')}
370
- `);
371
-
372
- autoCmd
373
- .command('enable')
374
- .description('Enable git automation with hook installation')
375
- .option('--trigger <trigger>', 'When to run checks (pre-commit or pre-push)', 'pre-commit')
376
- .option('--auto-fix', 'Enable automatic fixing of violations')
377
- .addHelpText('after', `
378
- ${chalk.cyan('Trigger Options:')}
379
- ${chalk.white('pre-commit')} Check before each commit (faster feedback)
380
- ${chalk.white('pre-push')} Check before each push (less frequent)
381
-
382
- ${chalk.cyan('What this does:')}
383
- Installs git hooks using Husky
384
- Configures BaseGuard to run automatically
385
- Sets up automation preferences
386
- • Updates .baseguardrc.json configuration
387
-
388
- ${chalk.cyan('Requirements:')}
389
- Git repository (run ${chalk.white('git init')} first)
390
- Node.js project with package.json
391
- `)
392
- .action((options) => automation('enable', options));
393
-
394
- autoCmd
395
- .command('disable')
396
- .description('Disable git automation and remove hooks')
397
- .addHelpText('after', `
398
- ${chalk.cyan('What this does:')}
399
- • Removes git hooks from .husky/ directory
400
- • Disables automation in configuration
401
- Preserves other BaseGuard settings
402
-
403
- ${chalk.cyan('Note:')}
404
- You can re-enable automation anytime with ${chalk.white('base automation enable')}
405
- `)
406
- .action(() => automation('disable'));
407
-
408
- autoCmd
409
- .command('run')
410
- .description('Run automation manually (used internally by git hooks)')
411
- .option('--trigger <trigger>', 'Trigger context (pre-commit or pre-push)')
412
- .addHelpText('after', `
413
- ${chalk.cyan('Usage:')}
414
- This command is typically called by git hooks automatically.
415
- You can run it manually for testing automation behavior.
416
-
417
- ${chalk.cyan('Examples:')}
418
- ${chalk.dim('$')} base automation run --trigger pre-commit
419
- ${chalk.dim('$')} base automation run --trigger pre-push
420
- `)
421
- .action((options) => automation('run', options));
422
-
423
- autoCmd
424
- .command('status')
425
- .description('Show detailed automation status and configuration')
426
- .addHelpText('after', `
427
- ${chalk.cyan('Status Information:')}
428
- • Automation enabled/disabled state
429
- • Git hook installation status
430
- Trigger configuration (pre-commit/pre-push)
431
- Auto-analysis and auto-fix settings
432
- API key configuration status
433
- Recommendations for setup improvements
434
- `)
435
- .action(() => automation('status'));
436
-
437
- autoCmd
438
- .command('configure')
439
- .description('Interactive configuration of all automation settings')
440
- .addHelpText('after', `
441
- ${chalk.cyan('Configuration Options:')}
442
- • Enable/disable automation
443
- • Choose trigger timing
444
- Configure AI analysis settings
445
- Configure AI fixing settings
446
- Set commit blocking behavior
447
-
448
- ${chalk.cyan('Interactive Setup:')}
449
- Guides you through all automation options with explanations
450
- and recommendations based on your current configuration.
451
- `)
452
- .action(() => automation('configure'));
453
-
454
- // Browser target management commands (shortcuts)
455
- program
456
- .command('add <target>')
457
- .description('Add browser target (shortcut for config targets --add)')
458
- .addHelpText('after', `
459
- ${chalk.cyan('Target Format:')}
460
- "browser version" - e.g., "chrome 100", "safari 15", "firefox baseline"
461
-
462
- ${chalk.cyan('Examples:')}
463
- ${chalk.dim('$')} base add "chrome 100" ${chalk.gray('# Add Chrome 100+ support')}
464
- ${chalk.dim('$')} base add "safari baseline" ${chalk.gray('# Add Safari with Baseline support')}
465
- ${chalk.dim('$')} base add "firefox 90" ${chalk.gray('# Add Firefox 90+ support')}
466
- `)
467
- .action((target) => config('targets', { add: target }));
468
-
469
- program
470
- .command('remove <target>')
471
- .description('Remove browser target (shortcut for config targets --remove)')
472
- .addHelpText('after', `
473
- ${chalk.cyan('Examples:')}
474
- ${chalk.dim('$')} base remove chrome ${chalk.gray('# Remove all Chrome targets')}
475
- ${chalk.dim('$')} base remove safari ${chalk.gray('# Remove all Safari targets')}
476
- ${chalk.dim('$')} base remove firefox ${chalk.gray('# Remove all Firefox targets')}
477
- `)
478
- .action((target) => config('targets', { remove: target }));
479
-
480
- program
481
- .command('list')
482
- .description('List configuration summary (shortcut for config list)')
483
- .option('--format <format>', 'Output format (table or json)', 'table')
484
- .addHelpText('after', `
485
- ${chalk.cyan('Quick Status:')}
486
- Shows browser targets, API keys, automation status, and security info.
487
-
488
- ${chalk.cyan('Examples:')}
489
- ${chalk.dim('$')} base list ${chalk.gray('# Show configuration summary')}
490
- ${chalk.dim('$')} base list --format json ${chalk.gray('# Export as JSON')}
491
- `)
492
- .action((options) => config('list', options));
493
-
494
- // System status and health
495
- program
496
- .command('status')
497
- .description('Show BaseGuard system status and health information')
498
- .option('--verbose', 'Show detailed status information')
499
- .option('--services', 'Check external service availability')
500
- .option('--config', 'Show configuration status and validation')
501
- .option('--errors', 'Show error summary and recent issues')
502
- .addHelpText('after', `
503
- ${chalk.cyan('Status Information:')}
504
- Overall system health (healthy/degraded/critical)
505
- Component status (configuration, services, errors)
506
- Current degradation mode and limitations
507
- • Service availability (network, APIs)
508
- Configuration validation results
509
- Error summary and recent issues
510
- Performance information
511
- Recovery recommendations
512
-
513
- ${chalk.cyan('Examples:')}
514
- ${chalk.dim('$')} base status ${chalk.gray('# Show basic system status')}
515
- ${chalk.dim('$')} base status --verbose ${chalk.gray('# Show detailed information')}
516
- ${chalk.dim('$')} base status --services ${chalk.gray('# Check service availability')}
517
- ${chalk.dim('$')} base status --config ${chalk.gray('# Show configuration status')}
518
- ${chalk.dim('$')} base status --errors ${chalk.gray('# Show error information')}
519
-
520
- ${chalk.cyan('Health Levels:')}
521
- ${chalk.green('✅ Healthy')} All systems operational
522
- ${chalk.yellow('⚠️ Degraded')} Some features limited
523
- ${chalk.red('❌ Critical')} Major issues detected
524
- `)
525
- .action(async (options) => {
526
- await startupPromise;
527
- return status(options);
528
- });
529
-
530
- // System diagnostics
531
- program
532
- .command('diagnostics')
533
- .alias('diag')
534
- .description('Run comprehensive system diagnostics and recovery')
535
- .addHelpText('after', `
536
- ${chalk.cyan('Diagnostic Features:')}
537
- • Generate detailed debug report
538
- • Run configuration recovery wizard
539
- Check service availability
540
- Show error log summary
541
- Clean up old files and caches
542
- Provide recovery recommendations
543
-
544
- ${chalk.cyan('What this does:')}
545
- 1. Creates comprehensive debug report
546
- 2. Attempts automatic configuration recovery
547
- 3. Checks all external services
548
- 4. Analyzes error logs for patterns
549
- 5. Cleans up temporary files
550
- 6. Provides actionable recommendations
551
-
552
- ${chalk.cyan('Use when:')}
553
- BaseGuard is not working correctly
554
- You're experiencing frequent errors
555
- Need to troubleshoot issues
556
- • Want to optimize performance
557
- `)
558
- .action(async () => {
559
- await startupPromise;
560
- return diagnostics();
561
- });
562
-
563
- // Add version command with detailed info
564
- program
565
- .command('version')
566
- .description('Show version information and system details')
567
- .option('--check-updates', 'Check for available updates')
568
- .addHelpText('after', `
569
- ${chalk.cyan('Version Information:')}
570
- Shows BaseGuard version, Node.js version, and system information.
571
-
572
- ${chalk.cyan('Examples:')}
573
- ${chalk.dim('$')} base version ${chalk.gray('# Show version info')}
574
- ${chalk.dim('$')} base version --check-updates ${chalk.gray('# Check for updates')}
575
- `)
576
- .action((options) => showVersionInfo(options));
577
-
578
- // Add help command
579
- program
580
- .command('help [command]')
581
- .description('Display help information for BaseGuard or specific commands')
582
- .addHelpText('after', `
583
- ${chalk.cyan('Examples:')}
584
- ${chalk.dim('$')} base help ${chalk.gray('# Show general help')}
585
- ${chalk.dim('$')} base help init ${chalk.gray('# Show help for init command')}
586
- ${chalk.dim('$')} base help config ${chalk.gray('# Show help for config commands')}
587
- `)
588
- .action((command) => {
589
- if (command) {
590
- program.commands.find(cmd => cmd.name() === command)?.help();
591
- } else {
592
- showGlobalHelp();
593
- }
594
- });
595
-
596
- // Handle unknown commands
597
- program.on('command:*', function (operands) {
598
- console.error(chalk.red('❌ Unknown command:'), chalk.white(operands[0]));
599
- console.log(chalk.yellow('\n💡 Suggestions:'));
600
- console.log(` • Run ${chalk.white('base help')} to see all available commands`);
601
- console.log(` • Run ${chalk.white('base init')} if you haven't set up BaseGuard yet`);
602
- console.log(` • Check for typos in the command name`);
603
- process.exit(1);
604
- });
605
-
606
- // Show help if no command provided
607
- if (process.argv.length <= 2) {
608
- showTerminalHeader();
609
- showGlobalHelp();
610
- process.exit(0);
611
- }
612
-
613
- program.parse();
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from 'commander';
4
+ import chalk from 'chalk';
5
+ import { init, check, fix, config, automation, status, diagnostics } from '../dist/commands/index.js';
6
+ import { showTerminalHeader, showVersionInfo, showGlobalHelp } from '../dist/ui/index.js';
7
+ import { StartupOptimizer } from '../dist/core/startup-optimizer.js';
8
+
9
+ // Initialize startup optimizations with timeout
10
+ const startupPromise = Promise.race([
11
+ StartupOptimizer.initialize().then(() => {
12
+ // Run additional startup optimizations
13
+ return StartupOptimizer.optimizeStartup();
14
+ }),
15
+ new Promise(resolve => setTimeout(resolve, 1000)) // Max 1 second for startup
16
+ ]).catch(() => {
17
+ // Ignore startup errors, continue with CLI
18
+ });
19
+
20
+ const program = new Command();
21
+
22
+ program
23
+ .name('base')
24
+ .description(chalk.cyan('🛡️ BaseGuard - Never ship incompatible code again\n') +
25
+ chalk.dim('Intelligent browser compatibility enforcement with AI-powered analysis and autonomous fixing'))
26
+ .version('1.0.3')
27
+ .configureOutput({
28
+ outputError: (str, write) => write(chalk.red(str))
29
+ })
30
+ .configureHelp({
31
+ helpWidth: 100,
32
+ sortSubcommands: true
33
+ })
34
+ .addHelpText('after', `
35
+ ${chalk.cyan('Examples:')}
36
+ ${chalk.dim('$')} base init ${chalk.gray('# Initialize BaseGuard in your project')}
37
+ ${chalk.dim('$')} base check ${chalk.gray('# Check for compatibility violations')}
38
+ ${chalk.dim('$')} base fix ${chalk.gray('# Fix violations with AI assistance')}
39
+ ${chalk.dim('$')} base config set-keys ${chalk.gray('# Configure API keys for AI services')}
40
+ ${chalk.dim('$')} base automation enable ${chalk.gray('# Enable git hooks for automatic checking')}
41
+
42
+ ${chalk.cyan('Getting Started:')}
43
+ 1. Run ${chalk.white('base init')} to set up BaseGuard in your project
44
+ 2. Configure API keys with ${chalk.white('base config set-keys')} for AI features
45
+ 3. Enable automation with ${chalk.white('base automation enable')}
46
+ 4. Check compatibility with ${chalk.white('base check')}
47
+
48
+ ${chalk.cyan('Documentation:')}
49
+ ${chalk.blue('https://github.com/baseguard/baseguard#readme')}
50
+
51
+ ${chalk.cyan('Support:')}
52
+ ${chalk.blue('https://github.com/baseguard/baseguard/issues')}
53
+ `);
54
+
55
+ // Initialize BaseGuard in project
56
+ program
57
+ .command('init')
58
+ .description('Initialize BaseGuard in your project with guided setup')
59
+ .option('--preset <preset>', 'Browser target preset (baseline-widely, baseline-newly, last-2-years, custom)', 'baseline-widely')
60
+ .option('--skip-hooks', 'Skip git hook installation during setup')
61
+ .option('--skip-api-keys', 'Skip API key configuration during setup')
62
+ .addHelpText('after', `
63
+ ${chalk.cyan('Browser Target Presets:')}
64
+ ${chalk.white('baseline-widely')} Support features available in Baseline for 30+ months
65
+ ${chalk.white('baseline-newly')} Support newly available Baseline features
66
+ ${chalk.white('last-2-years')} Support browsers from the last 2 years
67
+ ${chalk.white('custom')} Configure custom browser targets interactively
68
+
69
+ ${chalk.cyan('Examples:')}
70
+ ${chalk.dim('$')} base init ${chalk.gray('# Interactive setup with baseline-widely preset')}
71
+ ${chalk.dim('$')} base init --preset baseline-newly ${chalk.gray('# Use baseline-newly preset')}
72
+ ${chalk.dim('$')} base init --skip-hooks ${chalk.gray('# Skip git hook installation')}
73
+ ${chalk.dim('$')} base init --preset custom ${chalk.gray('# Configure custom browser targets')}
74
+
75
+ ${chalk.cyan('What this does:')}
76
+ • Creates .baseguardrc.json configuration file
77
+ Sets up browser compatibility targets
78
+ Configures API keys for AI services (optional)
79
+ Installs git hooks for automation (optional)
80
+ Adds .baseguardrc.json to .gitignore for security
81
+ `)
82
+ .action(async (options) => {
83
+ await startupPromise;
84
+ await StartupOptimizer.optimizeForUseCase('init');
85
+ return init(options);
86
+ });
87
+
88
+ // Check for compatibility violations
89
+ program
90
+ .command('check')
91
+ .description('Scan code for browser compatibility violations using Baseline data')
92
+ .option('--strict', 'Exit with error code if violations are found (useful for CI/CD)')
93
+ .option('--files <pattern>', 'File pattern to check using glob syntax', '**/*.{js,jsx,ts,tsx,vue,svelte,css,html}')
94
+ .option('--format <format>', 'Output format for results', 'table')
95
+ .option('--debug', 'Enable debug logging for troubleshooting')
96
+ .option('--offline', 'Run in offline mode (no network requests)')
97
+ .addHelpText('after', `
98
+ ${chalk.cyan('Output Formats:')}
99
+ ${chalk.white('table')} Human-readable table format (default)
100
+ ${chalk.white('json')} JSON format for programmatic use
101
+ ${chalk.white('junit')} JUnit XML format for CI/CD integration
102
+
103
+ ${chalk.cyan('Examples:')}
104
+ ${chalk.dim('$')} base check ${chalk.gray('# Check all supported files')}
105
+ ${chalk.dim('$')} base check --strict ${chalk.gray('# Exit with error if violations found')}
106
+ ${chalk.dim('$')} base check --files "src/**/*.ts" ${chalk.gray('# Check only TypeScript files in src/')}
107
+ ${chalk.dim('$')} base check --format json ${chalk.gray('# Output results as JSON')}
108
+ ${chalk.dim('$')} base check --files "*.css" --strict ${chalk.gray('# Check CSS files with strict mode')}
109
+
110
+ ${chalk.cyan('File Patterns:')}
111
+ Supports glob patterns like:
112
+ ${chalk.white('"src/**/*.{js,ts}"')} - All JS/TS files in src/ and subdirectories
113
+ ${chalk.white('"components/*.vue"')} - All Vue files in components/
114
+ ${chalk.white('"**/*.css"')} - All CSS files in project
115
+
116
+ ${chalk.cyan('What this checks:')}
117
+ • CSS properties, selectors, and at-rules
118
+ JavaScript APIs and ECMAScript features
119
+ HTML elements and attributes
120
+ Framework-specific files (React, Vue, Svelte)
121
+ Web platform APIs (Canvas, WebGL, WebRTC, WebAssembly, etc.)
122
+ `)
123
+ .action(async (options) => {
124
+ await startupPromise;
125
+ await StartupOptimizer.optimizeForUseCase('check');
126
+ return check(options);
127
+ });
128
+
129
+ // Fix violations with AI
130
+ program
131
+ .command('fix')
132
+ .description('Analyze and fix compatibility violations using AI (requires API keys)')
133
+ .option('--auto', 'Apply fixes automatically without interactive confirmation')
134
+ .option('--analyze-only', 'Only run AI analysis without generating code fixes')
135
+ .option('--files <pattern>', 'File pattern to fix using glob syntax', '**/*.{js,jsx,ts,tsx,vue,svelte,css,html}')
136
+ .addHelpText('after', `
137
+ ${chalk.cyan('Prerequisites:')}
138
+ • Gemini API key (for analysis and fixing) - Get from ${chalk.blue('https://aistudio.google.com')}
139
+ • Jules API key (optional, for GitHub repos) - Get from ${chalk.blue('https://jules.google.com')}
140
+ Choose your coding agent: "base config coding-agent"
141
+
142
+ ${chalk.cyan('Examples:')}
143
+ ${chalk.dim('$')} base fix ${chalk.gray('# Interactive fix with confirmation prompts')}
144
+ ${chalk.dim('$')} base fix --auto ${chalk.gray('# Apply all fixes automatically')}
145
+ ${chalk.dim('$')} base fix --analyze-only ${chalk.gray('# Only analyze, don\'t generate fixes')}
146
+ ${chalk.dim('$')} base fix --files "src/**/*.css" ${chalk.gray('# Fix only CSS files in src/')}
147
+
148
+ ${chalk.cyan('How it works:')}
149
+ 1. ${chalk.white('Scan')} - Detects compatibility violations using Baseline data
150
+ 2. ${chalk.white('Analyze')} - Gemini AI researches impact and fix strategies
151
+ 3. ${chalk.white('Fix')} - AI generates progressive enhancement code (Jules or Gemini)
152
+ 4. ${chalk.white('Review')} - Shows preview of changes before applying
153
+ 5. ${chalk.white('Apply')} - Updates files with compatibility fixes
154
+
155
+ ${chalk.cyan('Coding Agents:')}
156
+ ${chalk.white('Gemini 2.5 Pro')} - Works with any files, immediate processing
157
+ ${chalk.white('Jules')} - GitHub repos only, autonomous cloud processing
158
+
159
+ ${chalk.cyan('Fix Strategies:')}
160
+ • Progressive enhancement with @supports for CSS
161
+ Feature detection for JavaScript APIs
162
+ Polyfills and fallbacks for older browsers
163
+ • Graceful degradation patterns
164
+
165
+ ${chalk.cyan('Setup:')}
166
+ Run ${chalk.white('base config set-keys')} to configure API keys
167
+ Run ${chalk.white('base config coding-agent')} to choose your preferred agent
168
+ `)
169
+ .action(async (options) => {
170
+ await startupPromise;
171
+ await StartupOptimizer.optimizeForUseCase('fix');
172
+ return fix(options);
173
+ });
174
+
175
+ // Configuration management
176
+ const configCmd = program
177
+ .command('config')
178
+ .description('Manage BaseGuard configuration and settings')
179
+ .addHelpText('after', `
180
+ ${chalk.cyan('Configuration Commands:')}
181
+ ${chalk.white('show')} Display detailed configuration with security status
182
+ ${chalk.white('list')} Show configuration summary (supports --format json)
183
+ ${chalk.white('set-keys')} Interactive API key setup with browser integration
184
+ ${chalk.white('targets')} Manage browser compatibility targets
185
+ ${chalk.white('validate')} Check configuration file for errors
186
+ ${chalk.white('automation')} Configure git automation settings
187
+
188
+ ${chalk.cyan('Examples:')}
189
+ ${chalk.dim('$')} base config show ${chalk.gray('# Show detailed configuration')}
190
+ ${chalk.dim('$')} base config set-keys ${chalk.gray('# Set up API keys interactively')}
191
+ ${chalk.dim('$')} base config list --format json ${chalk.gray('# Export configuration as JSON')}
192
+ ${chalk.dim('$')} base config targets --preset baseline-widely ${chalk.gray('# Set browser targets')}
193
+ `);
194
+
195
+ configCmd
196
+ .command('show')
197
+ .description('Display detailed configuration with security and validation status')
198
+ .addHelpText('after', `
199
+ ${chalk.cyan('What this shows:')}
200
+ Current browser targets and presets
201
+ • API key configuration status (without exposing keys)
202
+ Automation and git hook settings
203
+ • Security status (.gitignore configuration)
204
+ • Configuration validation results
205
+ • Recommendations for improvements
206
+ `)
207
+ .action(() => config('show'));
208
+
209
+ configCmd
210
+ .command('set-keys')
211
+ .description('Interactive setup of API keys for AI services')
212
+ .addHelpText('after', `
213
+ ${chalk.cyan('API Services:')}
214
+ ${chalk.white('Gemini')} - For AI analysis of compatibility issues
215
+ Get your key: ${chalk.blue('https://aistudio.google.com')}
216
+
217
+ ${chalk.white('Jules')} - For autonomous code fixing
218
+ Get your key: ${chalk.blue('https://jules.google.com')}
219
+
220
+ ${chalk.cyan('Security:')}
221
+ • Keys are stored in .baseguardrc.json
222
+ • File is automatically added to .gitignore
223
+ • Keys are validated before saving
224
+ `)
225
+ .action(() => config('set-keys'));
226
+
227
+ configCmd
228
+ .command('targets')
229
+ .description('Manage browser compatibility targets')
230
+ .option('--add <target>', 'Add browser target (format: "browser version")')
231
+ .option('--remove <target>', 'Remove browser target by name')
232
+ .option('--preset <preset>', 'Set predefined browser targets')
233
+ .addHelpText('after', `
234
+ ${chalk.cyan('Target Formats:')}
235
+ ${chalk.white('"chrome 100"')} Minimum Chrome version 100
236
+ ${chalk.white('"safari baseline"')} Safari with Baseline support only
237
+ ${chalk.white('"firefox 90"')} Minimum Firefox version 90
238
+
239
+ ${chalk.cyan('Available Presets:')}
240
+ ${chalk.white('baseline-widely')} Features available for 30+ months
241
+ ${chalk.white('baseline-newly')} Newly available Baseline features
242
+ ${chalk.white('last-2-years')} Browsers from last 2 years
243
+
244
+ ${chalk.cyan('Examples:')}
245
+ ${chalk.dim('$')} base config targets --add "chrome 100"
246
+ ${chalk.dim('$')} base config targets --remove chrome
247
+ ${chalk.dim('$')} base config targets --preset baseline-widely
248
+ `)
249
+ .action((options) => config('targets', options));
250
+
251
+ configCmd
252
+ .command('list')
253
+ .description('Show configuration summary with status information')
254
+ .option('--format <format>', 'Output format (table or json)', 'table')
255
+ .addHelpText('after', `
256
+ ${chalk.cyan('Output Formats:')}
257
+ ${chalk.white('table')} Human-readable summary (default)
258
+ ${chalk.white('json')} Machine-readable JSON for scripts
259
+
260
+ ${chalk.cyan('Includes:')}
261
+ Browser targets and count
262
+ • API key configuration status
263
+ • Automation settings
264
+ • Security and validation status
265
+ `)
266
+ .action((options) => config('list', options));
267
+
268
+ configCmd
269
+ .command('validate')
270
+ .description('Validate configuration file for errors and inconsistencies')
271
+ .addHelpText('after', `
272
+ ${chalk.cyan('Validation Checks:')}
273
+ • Configuration file syntax and structure
274
+ Browser target format and validity
275
+ API key format validation
276
+ Automation setting consistency
277
+ • Required field presence
278
+
279
+ ${chalk.cyan('Exit Codes:')}
280
+ 0 - Configuration is valid
281
+ 1 - Validation errors found
282
+ `)
283
+ .action(() => config('validate'));
284
+
285
+ configCmd
286
+ .command('automation')
287
+ .description('Configure git automation settings interactively')
288
+ .addHelpText('after', `
289
+ ${chalk.cyan('Automation Settings:')}
290
+ • Enable/disable git hooks
291
+ • Choose trigger (pre-commit or pre-push)
292
+ • Configure auto-analysis with Gemini
293
+ • Configure auto-fixing with Jules
294
+ • Set commit blocking behavior
295
+ `)
296
+ .action(() => config('automation'));
297
+
298
+ configCmd
299
+ .command('recover')
300
+ .description('Attempt automatic recovery of corrupted configuration')
301
+ .option('--backup', 'Create backup before recovery')
302
+ .option('--interactive', 'Run interactive recovery wizard')
303
+ .addHelpText('after', `
304
+ ${chalk.cyan('Recovery Features:')}
305
+ • Automatic detection of configuration issues
306
+ Repair of corrupted JSON syntax
307
+ Migration from older configuration versions
308
+ Validation and structure repair
309
+ Backup creation before changes
310
+
311
+ ${chalk.cyan('Recovery Process:')}
312
+ 1. Validates current configuration
313
+ 2. Creates backup if requested
314
+ 3. Attempts automatic repair
315
+ 4. Migrates to current version
316
+ 5. Validates final result
317
+
318
+ ${chalk.cyan('Examples:')}
319
+ ${chalk.dim('$')} base config recover ${chalk.gray('# Automatic recovery')}
320
+ ${chalk.dim('$')} base config recover --backup ${chalk.gray('# Create backup first')}
321
+ ${chalk.dim('$')} base config recover --interactive ${chalk.gray('# Interactive wizard')}
322
+ `)
323
+ .action((options) => config('recover', options));
324
+
325
+ configCmd
326
+ .command('coding-agent')
327
+ .description('Manage coding agent selection (Jules vs Gemini)')
328
+ .option('--agent <agent>', 'Set primary agent (jules or gemini)')
329
+ .option('--show', 'Show current agent configuration and status')
330
+ .addHelpText('after', `
331
+ ${chalk.cyan('Coding Agents:')}
332
+ ${chalk.white('Jules')} - Google's autonomous coding agent (GitHub repos only)
333
+ ${chalk.white('Gemini')} - Gemini 2.5 Pro direct API (works with any files)
334
+
335
+ ${chalk.cyan('Agent Comparison:')}
336
+ Jules:
337
+ ✅ Autonomous operation in cloud VMs
338
+ ✅ Full repository context understanding
339
+ Asynchronous processing
340
+ Requires GitHub repository
341
+ Cannot work with local/uncommitted files
342
+
343
+ Gemini:
344
+ ✅ Works with any files (GitHub or not)
345
+ ✅ Immediate processing
346
+ Works with uncommitted/local files
347
+ Grounded with real-time web search
348
+ ⚠️ Requires manual code application
349
+
350
+ ${chalk.cyan('Examples:')}
351
+ ${chalk.dim('$')} base config coding-agent --show ${chalk.gray('# Show current configuration')}
352
+ ${chalk.dim('$')} base config coding-agent --agent gemini ${chalk.gray('# Set Gemini as primary')}
353
+ ${chalk.dim('$')} base config coding-agent --agent jules ${chalk.gray('# Set Jules as primary')}
354
+ ${chalk.dim('$')} base config coding-agent ${chalk.gray('# Interactive selection')}
355
+ `)
356
+ .action((options) => config('coding-agent', options));
357
+
358
+ // Automation and git hooks
359
+ const autoCmd = program
360
+ .command('automation')
361
+ .alias('auto')
362
+ .description('Manage git automation and hooks for continuous compatibility checking')
363
+ .addHelpText('after', `
364
+ ${chalk.cyan('Automation Features:')}
365
+ • Automatic compatibility checking on git operations
366
+ AI-powered analysis and fixing integration
367
+ Commit blocking when violations are found
368
+ Configurable triggers (pre-commit or pre-push)
369
+
370
+ ${chalk.cyan('Examples:')}
371
+ ${chalk.dim('$')} base automation enable ${chalk.gray('# Enable with interactive setup')}
372
+ ${chalk.dim('$')} base automation enable --trigger pre-push ${chalk.gray('# Enable with pre-push trigger')}
373
+ ${chalk.dim('$')} base automation status ${chalk.gray('# Show current automation status')}
374
+ ${chalk.dim('$')} base automation disable ${chalk.gray('# Disable automation and remove hooks')}
375
+ `);
376
+
377
+ autoCmd
378
+ .command('enable')
379
+ .description('Enable git automation with hook installation')
380
+ .option('--trigger <trigger>', 'When to run checks (pre-commit or pre-push)', 'pre-commit')
381
+ .option('--auto-fix', 'Enable automatic fixing of violations')
382
+ .addHelpText('after', `
383
+ ${chalk.cyan('Trigger Options:')}
384
+ ${chalk.white('pre-commit')} Check before each commit (faster feedback)
385
+ ${chalk.white('pre-push')} Check before each push (less frequent)
386
+
387
+ ${chalk.cyan('What this does:')}
388
+ • Installs git hooks using Husky
389
+ Configures BaseGuard to run automatically
390
+ Sets up automation preferences
391
+ • Updates .baseguardrc.json configuration
392
+
393
+ ${chalk.cyan('Requirements:')}
394
+ • Git repository (run ${chalk.white('git init')} first)
395
+ • Node.js project with package.json
396
+ `)
397
+ .action((options) => automation('enable', options));
398
+
399
+ autoCmd
400
+ .command('disable')
401
+ .description('Disable git automation and remove hooks')
402
+ .addHelpText('after', `
403
+ ${chalk.cyan('What this does:')}
404
+ Removes git hooks from .husky/ directory
405
+ • Disables automation in configuration
406
+ Preserves other BaseGuard settings
407
+
408
+ ${chalk.cyan('Note:')}
409
+ You can re-enable automation anytime with ${chalk.white('base automation enable')}
410
+ `)
411
+ .action(() => automation('disable'));
412
+
413
+ autoCmd
414
+ .command('run')
415
+ .description('Run automation manually (used internally by git hooks)')
416
+ .option('--trigger <trigger>', 'Trigger context (pre-commit or pre-push)')
417
+ .addHelpText('after', `
418
+ ${chalk.cyan('Usage:')}
419
+ This command is typically called by git hooks automatically.
420
+ You can run it manually for testing automation behavior.
421
+
422
+ ${chalk.cyan('Examples:')}
423
+ ${chalk.dim('$')} base automation run --trigger pre-commit
424
+ ${chalk.dim('$')} base automation run --trigger pre-push
425
+ `)
426
+ .action((options) => automation('run', options));
427
+
428
+ autoCmd
429
+ .command('status')
430
+ .description('Show detailed automation status and configuration')
431
+ .addHelpText('after', `
432
+ ${chalk.cyan('Status Information:')}
433
+ Automation enabled/disabled state
434
+ • Git hook installation status
435
+ Trigger configuration (pre-commit/pre-push)
436
+ • Auto-analysis and auto-fix settings
437
+ • API key configuration status
438
+ • Recommendations for setup improvements
439
+ `)
440
+ .action(() => automation('status'));
441
+
442
+ autoCmd
443
+ .command('configure')
444
+ .description('Interactive configuration of all automation settings')
445
+ .addHelpText('after', `
446
+ ${chalk.cyan('Configuration Options:')}
447
+ • Enable/disable automation
448
+ Choose trigger timing
449
+ Configure AI analysis settings
450
+ Configure AI fixing settings
451
+ • Set commit blocking behavior
452
+
453
+ ${chalk.cyan('Interactive Setup:')}
454
+ Guides you through all automation options with explanations
455
+ and recommendations based on your current configuration.
456
+ `)
457
+ .action(() => automation('configure'));
458
+
459
+ // Browser target management commands (shortcuts)
460
+ program
461
+ .command('add <target>')
462
+ .description('Add browser target (shortcut for config targets --add)')
463
+ .addHelpText('after', `
464
+ ${chalk.cyan('Target Format:')}
465
+ "browser version" - e.g., "chrome 100", "safari 15", "firefox baseline"
466
+
467
+ ${chalk.cyan('Examples:')}
468
+ ${chalk.dim('$')} base add "chrome 100" ${chalk.gray('# Add Chrome 100+ support')}
469
+ ${chalk.dim('$')} base add "safari baseline" ${chalk.gray('# Add Safari with Baseline support')}
470
+ ${chalk.dim('$')} base add "firefox 90" ${chalk.gray('# Add Firefox 90+ support')}
471
+ `)
472
+ .action((target) => config('targets', { add: target }));
473
+
474
+ program
475
+ .command('remove <target>')
476
+ .description('Remove browser target (shortcut for config targets --remove)')
477
+ .addHelpText('after', `
478
+ ${chalk.cyan('Examples:')}
479
+ ${chalk.dim('$')} base remove chrome ${chalk.gray('# Remove all Chrome targets')}
480
+ ${chalk.dim('$')} base remove safari ${chalk.gray('# Remove all Safari targets')}
481
+ ${chalk.dim('$')} base remove firefox ${chalk.gray('# Remove all Firefox targets')}
482
+ `)
483
+ .action((target) => config('targets', { remove: target }));
484
+
485
+ program
486
+ .command('list')
487
+ .description('List configuration summary (shortcut for config list)')
488
+ .option('--format <format>', 'Output format (table or json)', 'table')
489
+ .addHelpText('after', `
490
+ ${chalk.cyan('Quick Status:')}
491
+ Shows browser targets, API keys, automation status, and security info.
492
+
493
+ ${chalk.cyan('Examples:')}
494
+ ${chalk.dim('$')} base list ${chalk.gray('# Show configuration summary')}
495
+ ${chalk.dim('$')} base list --format json ${chalk.gray('# Export as JSON')}
496
+ `)
497
+ .action((options) => config('list', options));
498
+
499
+ // System status and health
500
+ program
501
+ .command('status')
502
+ .description('Show BaseGuard system status and health information')
503
+ .option('--verbose', 'Show detailed status information')
504
+ .option('--services', 'Check external service availability')
505
+ .option('--config', 'Show configuration status and validation')
506
+ .option('--errors', 'Show error summary and recent issues')
507
+ .addHelpText('after', `
508
+ ${chalk.cyan('Status Information:')}
509
+ Overall system health (healthy/degraded/critical)
510
+ Component status (configuration, services, errors)
511
+ Current degradation mode and limitations
512
+ • Service availability (network, APIs)
513
+ • Configuration validation results
514
+ Error summary and recent issues
515
+ Performance information
516
+ Recovery recommendations
517
+
518
+ ${chalk.cyan('Examples:')}
519
+ ${chalk.dim('$')} base status ${chalk.gray('# Show basic system status')}
520
+ ${chalk.dim('$')} base status --verbose ${chalk.gray('# Show detailed information')}
521
+ ${chalk.dim('$')} base status --services ${chalk.gray('# Check service availability')}
522
+ ${chalk.dim('$')} base status --config ${chalk.gray('# Show configuration status')}
523
+ ${chalk.dim('$')} base status --errors ${chalk.gray('# Show error information')}
524
+
525
+ ${chalk.cyan('Health Levels:')}
526
+ ${chalk.green('✅ Healthy')} All systems operational
527
+ ${chalk.yellow('⚠️ Degraded')} Some features limited
528
+ ${chalk.red('❌ Critical')} Major issues detected
529
+ `)
530
+ .action(async (options) => {
531
+ await startupPromise;
532
+ return status(options);
533
+ });
534
+
535
+ // System diagnostics
536
+ program
537
+ .command('diagnostics')
538
+ .alias('diag')
539
+ .description('Run comprehensive system diagnostics and recovery')
540
+ .addHelpText('after', `
541
+ ${chalk.cyan('Diagnostic Features:')}
542
+ Generate detailed debug report
543
+ • Run configuration recovery wizard
544
+ Check service availability
545
+ Show error log summary
546
+ Clean up old files and caches
547
+ Provide recovery recommendations
548
+
549
+ ${chalk.cyan('What this does:')}
550
+ 1. Creates comprehensive debug report
551
+ 2. Attempts automatic configuration recovery
552
+ 3. Checks all external services
553
+ 4. Analyzes error logs for patterns
554
+ 5. Cleans up temporary files
555
+ 6. Provides actionable recommendations
556
+
557
+ ${chalk.cyan('Use when:')}
558
+ BaseGuard is not working correctly
559
+ You're experiencing frequent errors
560
+ Need to troubleshoot issues
561
+ • Want to optimize performance
562
+ `)
563
+ .action(async () => {
564
+ await startupPromise;
565
+ return diagnostics();
566
+ });
567
+
568
+ // Add version command with detailed info
569
+ program
570
+ .command('version')
571
+ .description('Show version information and system details')
572
+ .option('--check-updates', 'Check for available updates')
573
+ .addHelpText('after', `
574
+ ${chalk.cyan('Version Information:')}
575
+ Shows BaseGuard version, Node.js version, and system information.
576
+
577
+ ${chalk.cyan('Examples:')}
578
+ ${chalk.dim('$')} base version ${chalk.gray('# Show version info')}
579
+ ${chalk.dim('$')} base version --check-updates ${chalk.gray('# Check for updates')}
580
+ `)
581
+ .action((options) => showVersionInfo(options));
582
+
583
+ // Add help command
584
+ program
585
+ .command('help [command]')
586
+ .description('Display help information for BaseGuard or specific commands')
587
+ .addHelpText('after', `
588
+ ${chalk.cyan('Examples:')}
589
+ ${chalk.dim('$')} base help ${chalk.gray('# Show general help')}
590
+ ${chalk.dim('$')} base help init ${chalk.gray('# Show help for init command')}
591
+ ${chalk.dim('$')} base help config ${chalk.gray('# Show help for config commands')}
592
+ `)
593
+ .action((command) => {
594
+ if (command) {
595
+ program.commands.find(cmd => cmd.name() === command)?.help();
596
+ } else {
597
+ showGlobalHelp();
598
+ }
599
+ });
600
+
601
+ // Handle unknown commands
602
+ program.on('command:*', function (operands) {
603
+ console.error(chalk.red('❌ Unknown command:'), chalk.white(operands[0]));
604
+ console.log(chalk.yellow('\n💡 Suggestions:'));
605
+ console.log(` • Run ${chalk.white('base help')} to see all available commands`);
606
+ console.log(` • Run ${chalk.white('base init')} if you haven't set up BaseGuard yet`);
607
+ console.log(` • Check for typos in the command name`);
608
+ process.exit(1);
609
+ });
610
+
611
+ // Show help if no command provided
612
+ if (process.argv.length <= 2) {
613
+ showTerminalHeader();
614
+ showGlobalHelp();
615
+ process.exit(0);
616
+ }
617
+
618
+ // For help commands, don't wait for startup
619
+ const isHelpCommand = process.argv.includes('--help') || process.argv.includes('-h') || process.argv.includes('help');
620
+ if (isHelpCommand) {
621
+ // Parse immediately without waiting for startup
622
+ program.parse();
623
+ } else {
624
+ // Wait for startup for other commands
625
+ startupPromise.finally(() => {
626
+ program.parse();
627
+ });
628
+ }