baseguard 1.0.0 → 1.0.2

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 (156) hide show
  1. package/.baseguardrc.example.json +64 -0
  2. package/.eslintrc.json +1 -1
  3. package/CHANGELOG.md +196 -0
  4. package/DEPLOYMENT.md +625 -0
  5. package/DEPLOYMENT_CHECKLIST.md +239 -0
  6. package/DEPLOYMENT_SUMMARY_v1.0.2.md +202 -0
  7. package/QUICK_START.md +134 -0
  8. package/README.md +447 -52
  9. package/RELEASE_NOTES_v1.0.2.md +434 -0
  10. package/bin/base.js +155 -36
  11. package/dist/ai/agentkit-orchestrator.d.ts +116 -0
  12. package/dist/ai/agentkit-orchestrator.d.ts.map +1 -0
  13. package/dist/ai/agentkit-orchestrator.js +417 -0
  14. package/dist/ai/agentkit-orchestrator.js.map +1 -0
  15. package/dist/ai/gemini-code-fixer.d.ts +85 -0
  16. package/dist/ai/gemini-code-fixer.d.ts.map +1 -0
  17. package/dist/ai/gemini-code-fixer.js +452 -0
  18. package/dist/ai/gemini-code-fixer.js.map +1 -0
  19. package/dist/ai/jules-implementer.d.ts +5 -4
  20. package/dist/ai/jules-implementer.d.ts.map +1 -1
  21. package/dist/ai/jules-implementer.js +6 -5
  22. package/dist/ai/jules-implementer.js.map +1 -1
  23. package/dist/ai/unified-code-fixer.d.ts +69 -0
  24. package/dist/ai/unified-code-fixer.d.ts.map +1 -0
  25. package/dist/ai/unified-code-fixer.js +289 -0
  26. package/dist/ai/unified-code-fixer.js.map +1 -0
  27. package/dist/commands/check.d.ts +3 -1
  28. package/dist/commands/check.d.ts.map +1 -1
  29. package/dist/commands/check.js +166 -34
  30. package/dist/commands/check.js.map +1 -1
  31. package/dist/commands/config.d.ts +4 -0
  32. package/dist/commands/config.d.ts.map +1 -1
  33. package/dist/commands/config.js +183 -0
  34. package/dist/commands/config.js.map +1 -1
  35. package/dist/commands/fix.d.ts.map +1 -1
  36. package/dist/commands/fix.js +89 -91
  37. package/dist/commands/fix.js.map +1 -1
  38. package/dist/commands/index.d.ts +1 -0
  39. package/dist/commands/index.d.ts.map +1 -1
  40. package/dist/commands/index.js +1 -0
  41. package/dist/commands/index.js.map +1 -1
  42. package/dist/commands/init.d.ts.map +1 -1
  43. package/dist/commands/init.js +16 -2
  44. package/dist/commands/init.js.map +1 -1
  45. package/dist/commands/status.d.ts +14 -0
  46. package/dist/commands/status.d.ts.map +1 -0
  47. package/dist/commands/status.js +254 -0
  48. package/dist/commands/status.js.map +1 -0
  49. package/dist/core/baseguard.d.ts +47 -5
  50. package/dist/core/baseguard.d.ts.map +1 -1
  51. package/dist/core/baseguard.js +506 -52
  52. package/dist/core/baseguard.js.map +1 -1
  53. package/dist/core/cache-manager.d.ts.map +1 -1
  54. package/dist/core/cache-manager.js +3 -1
  55. package/dist/core/cache-manager.js.map +1 -1
  56. package/dist/core/configuration-recovery.d.ts +116 -0
  57. package/dist/core/configuration-recovery.d.ts.map +1 -0
  58. package/dist/core/configuration-recovery.js +552 -0
  59. package/dist/core/configuration-recovery.js.map +1 -0
  60. package/dist/core/configuration.d.ts +4 -0
  61. package/dist/core/configuration.d.ts.map +1 -1
  62. package/dist/core/configuration.js +35 -0
  63. package/dist/core/configuration.js.map +1 -1
  64. package/dist/core/debug-logger.d.ts +181 -0
  65. package/dist/core/debug-logger.d.ts.map +1 -0
  66. package/dist/core/debug-logger.js +479 -0
  67. package/dist/core/debug-logger.js.map +1 -0
  68. package/dist/core/file-processor.d.ts.map +1 -1
  69. package/dist/core/file-processor.js +8 -2
  70. package/dist/core/file-processor.js.map +1 -1
  71. package/dist/core/graceful-degradation-manager.d.ts +123 -0
  72. package/dist/core/graceful-degradation-manager.d.ts.map +1 -0
  73. package/dist/core/graceful-degradation-manager.js +512 -0
  74. package/dist/core/graceful-degradation-manager.js.map +1 -0
  75. package/dist/core/index.d.ts +4 -0
  76. package/dist/core/index.d.ts.map +1 -1
  77. package/dist/core/index.js +4 -0
  78. package/dist/core/index.js.map +1 -1
  79. package/dist/core/logger.d.ts +1 -0
  80. package/dist/core/logger.d.ts.map +1 -0
  81. package/dist/core/logger.js +2 -0
  82. package/dist/core/logger.js.map +1 -0
  83. package/dist/core/memory-manager.d.ts +84 -0
  84. package/dist/core/memory-manager.d.ts.map +1 -1
  85. package/dist/core/memory-manager.js +236 -1
  86. package/dist/core/memory-manager.js.map +1 -1
  87. package/dist/core/startup-optimizer.d.ts +12 -0
  88. package/dist/core/startup-optimizer.d.ts.map +1 -1
  89. package/dist/core/startup-optimizer.js +60 -0
  90. package/dist/core/startup-optimizer.js.map +1 -1
  91. package/dist/core/system-error-handler.d.ts +65 -0
  92. package/dist/core/system-error-handler.d.ts.map +1 -0
  93. package/dist/core/system-error-handler.js +646 -0
  94. package/dist/core/system-error-handler.js.map +1 -0
  95. package/dist/git/github-manager.d.ts +5 -16
  96. package/dist/git/github-manager.d.ts.map +1 -1
  97. package/dist/git/github-manager.js +6 -61
  98. package/dist/git/github-manager.js.map +1 -1
  99. package/dist/parsers/react-parser-optimized.d.ts +16 -0
  100. package/dist/parsers/react-parser-optimized.d.ts.map +1 -0
  101. package/dist/parsers/react-parser-optimized.js +147 -0
  102. package/dist/parsers/react-parser-optimized.js.map +1 -0
  103. package/dist/parsers/react-parser.d.ts.map +1 -1
  104. package/dist/parsers/react-parser.js +17 -15
  105. package/dist/parsers/react-parser.js.map +1 -1
  106. package/dist/parsers/svelte-parser.d.ts.map +1 -1
  107. package/dist/parsers/svelte-parser.js +7 -3
  108. package/dist/parsers/svelte-parser.js.map +1 -1
  109. package/dist/parsers/vanilla-parser.d.ts.map +1 -1
  110. package/dist/parsers/vanilla-parser.js +7 -3
  111. package/dist/parsers/vanilla-parser.js.map +1 -1
  112. package/dist/parsers/vue-parser.d.ts +18 -0
  113. package/dist/parsers/vue-parser.d.ts.map +1 -1
  114. package/dist/parsers/vue-parser.js +387 -1
  115. package/dist/parsers/vue-parser.js.map +1 -1
  116. package/dist/types/index.d.ts +4 -0
  117. package/dist/types/index.d.ts.map +1 -1
  118. package/dist/ui/help.js +1 -1
  119. package/dist/ui/help.js.map +1 -1
  120. package/dist/ui/prompts.d.ts +7 -4
  121. package/dist/ui/prompts.d.ts.map +1 -1
  122. package/dist/ui/prompts.js +48 -55
  123. package/dist/ui/prompts.js.map +1 -1
  124. package/package.json +30 -5
  125. package/src/ai/__tests__/gemini-analyzer.test.ts +2 -2
  126. package/src/ai/agentkit-orchestrator.ts +534 -0
  127. package/src/ai/gemini-code-fixer.ts +540 -0
  128. package/src/ai/jules-implementer.ts +6 -5
  129. package/src/ai/unified-code-fixer.ts +347 -0
  130. package/src/commands/config.ts +218 -0
  131. package/src/commands/fix.ts +98 -94
  132. package/src/commands/index.ts +2 -1
  133. package/src/commands/init.ts +16 -2
  134. package/src/commands/status.ts +307 -0
  135. package/src/core/baseguard.ts +36 -22
  136. package/src/core/cache-manager.ts +4 -2
  137. package/src/core/configuration-recovery.ts +3 -6
  138. package/src/core/configuration.ts +37 -0
  139. package/src/core/debug-logger.ts +2 -2
  140. package/src/core/file-processor.ts +10 -3
  141. package/src/core/index.ts +5 -1
  142. package/src/core/memory-manager.ts +4 -3
  143. package/src/core/startup-optimizer.ts +70 -0
  144. package/src/core/system-error-handler.ts +9 -5
  145. package/src/git/github-manager.ts +11 -79
  146. package/src/parsers/react-parser.ts +2 -2
  147. package/src/parsers/svelte-parser.ts +13 -9
  148. package/src/parsers/vanilla-parser.ts +18 -14
  149. package/src/parsers/vue-parser.ts +20 -14
  150. package/src/types/index.ts +4 -0
  151. package/src/ui/help.ts +1 -1
  152. package/src/ui/prompts.ts +54 -61
  153. package/test-build.js +41 -0
  154. package/tests/e2e/git-integration.e2e.test.ts +1 -1
  155. package/tsconfig.json +0 -1
  156. package/vitest.config.ts +4 -2
@@ -3,7 +3,7 @@ import { UIComponents } from '../ui/index.js';
3
3
  import { BaseGuard } from '../core/index.js';
4
4
  import { ConfigurationManager } from '../core/configuration.js';
5
5
  import { ErrorHandler } from '../core/error-handler.js';
6
- import { JulesImplementer } from '../ai/jules-implementer.js';
6
+ import { UnifiedCodeFixer } from '../ai/unified-code-fixer.js';
7
7
  import { GeminiAnalyzer } from '../ai/gemini-analyzer.js';
8
8
  import { glob } from 'glob';
9
9
 
@@ -34,30 +34,34 @@ export async function fix(options: {
34
34
 
35
35
  // Initialize services
36
36
  const baseGuard = new BaseGuard(config);
37
- const julesImplementer = new JulesImplementer(config.apiKeys.jules);
37
+ const unifiedCodeFixer = new UnifiedCodeFixer(config);
38
38
  const geminiAnalyzer = new GeminiAnalyzer(config.apiKeys.gemini);
39
39
 
40
- // Check GitHub integration
41
- const isGitHubSetup = await julesImplementer.isGitHubIntegrationSetup();
42
- if (!isGitHubSetup) {
43
- console.log(chalk.yellow('āš ļø Jules GitHub integration not set up'));
44
-
45
- const { default: inquirer } = await import('inquirer');
46
- const { setupNow } = await inquirer.prompt([
47
- {
48
- type: 'confirm',
49
- name: 'setupNow',
50
- message: 'Would you like to set up Jules GitHub integration now?',
51
- default: true
52
- }
53
- ]);
54
-
55
- if (setupNow) {
56
- await julesImplementer.setupGitHubIntegration();
57
- } else {
58
- console.log(chalk.yellow('GitHub integration required for Jules fixing. Exiting.'));
59
- process.exit(0);
60
- }
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'));
61
65
  }
62
66
 
63
67
  // Step 1: Check for violations
@@ -102,88 +106,88 @@ export async function fix(options: {
102
106
  return;
103
107
  }
104
108
 
105
- // Step 3: Generate and apply fixes with Jules
106
- console.log(chalk.cyan('\nšŸ¤– Generating fixes with Jules AI...'));
107
- const results = await julesImplementer.generateAndApplyFixes(violations, analyses);
109
+ // Step 3: Generate fixes with unified code fixer
110
+ console.log(chalk.cyan(`\nšŸ¤– Generating fixes with ${agentStatus.primary}...`));
108
111
 
109
- // Show results
110
- console.log(chalk.cyan('\nšŸ“Š Fix Results:\n'));
112
+ const fixes = [];
113
+ let successCount = 0;
114
+ let failedCount = 0;
111
115
 
112
- if (results.applied.length > 0) {
113
- console.log(chalk.green(`āœ… Applied ${results.applied.length} fixes:`));
114
- results.applied.forEach(fix => {
115
- console.log(chalk.green(` • ${fix.filePath} - ${fix.violation.feature}`));
116
- });
117
- console.log();
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
+ }
118
141
  }
119
142
 
120
- if (results.skipped.length > 0) {
121
- console.log(chalk.yellow(`ā­ļø Skipped ${results.skipped.length} fixes:`));
122
- results.skipped.forEach(fix => {
123
- console.log(chalk.yellow(` • ${fix.filePath} - ${fix.violation.feature}`));
124
- });
125
- console.log();
143
+ if (fixes.length === 0) {
144
+ console.log(chalk.yellow('\nāš ļø No fixes were generated'));
145
+ return;
126
146
  }
127
147
 
128
- if (results.failed.length > 0) {
129
- console.log(chalk.red(`āŒ Failed ${results.failed.length} fixes:`));
130
- results.failed.forEach(({ fix, error }) => {
131
- console.log(chalk.red(` • ${fix.filePath} - ${fix.violation.feature}: ${error}`));
132
- });
133
- console.log();
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`));
134
153
  }
135
154
 
136
- // Show rollback option if fixes were applied
137
- if (results.applied.length > 0) {
138
- const { default: inquirer } = await import('inquirer');
139
- const { showRollback } = await inquirer.prompt([
140
- {
141
- type: 'confirm',
142
- name: 'showRollback',
143
- message: 'Would you like to see rollback options?',
144
- default: false
145
- }
146
- ]);
147
-
148
- if (showRollback) {
149
- const { rollbackAction } = await inquirer.prompt([
150
- {
151
- type: 'list',
152
- name: 'rollbackAction',
153
- message: 'Rollback options:',
154
- choices: [
155
- { name: 'Keep all fixes', value: 'keep' },
156
- { name: 'Rollback all fixes', value: 'rollback_all' },
157
- { name: 'Rollback specific fixes', value: 'rollback_specific' }
158
- ]
159
- }
160
- ]);
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}`));
161
162
 
162
- if (rollbackAction === 'rollback_all') {
163
- await julesImplementer.rollbackAllFixes();
164
- UIComponents.showSuccessBox('All fixes have been rolled back');
165
- } else if (rollbackAction === 'rollback_specific') {
166
- const appliedFiles = julesImplementer.getAppliedFixes();
167
- const { filesToRollback } = await inquirer.prompt([
168
- {
169
- type: 'checkbox',
170
- name: 'filesToRollback',
171
- message: 'Select fixes to rollback:',
172
- choices: appliedFiles.map(file => ({ name: file, value: file }))
173
- }
174
- ]);
175
-
176
- for (const file of filesToRollback) {
177
- await julesImplementer.rollbackFix(file);
178
- }
179
-
180
- if (filesToRollback.length > 0) {
181
- UIComponents.showSuccessBox(`Rolled back ${filesToRollback.length} fixes`);
182
- }
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}`));
183
169
  }
184
- }
170
+ console.log();
171
+ });
185
172
  }
186
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
+
187
191
  UIComponents.showSuccessBox('Fix process completed!');
188
192
 
189
193
  } catch (error) {
@@ -203,7 +207,7 @@ export async function fix(options: {
203
207
  UIComponents.showList([
204
208
  'Run "base init" to set up BaseGuard configuration',
205
209
  'Configure API keys with "base config set-keys"',
206
- 'Check GitHub integration for Jules fixing'
210
+ 'Ensure you are in a GitHub repository for Jules fixing'
207
211
  ]);
208
212
  } else if (apiError.type === 'network') {
209
213
  UIComponents.showList([
@@ -3,4 +3,5 @@ export * from './init.js';
3
3
  export * from './check.js';
4
4
  export * from './fix.js';
5
5
  export * from './config.js';
6
- export * from './automation.js';
6
+ export * from './automation.js';
7
+ export { status, diagnostics } from './status.js';
@@ -69,11 +69,10 @@ export async function init(options: {
69
69
  }
70
70
  }
71
71
 
72
- // Set up API keys if not skipped
72
+ // Set up API keys and coding agent if not skipped
73
73
  if (!options.skipApiKeys) {
74
74
  spinner.stop();
75
75
  const apiKeys = await Prompts.setupApiKeys();
76
- spinner.start();
77
76
 
78
77
  if (apiKeys.julesApiKey) {
79
78
  config.apiKeys.jules = apiKeys.julesApiKey;
@@ -81,6 +80,21 @@ export async function init(options: {
81
80
  if (apiKeys.geminiApiKey) {
82
81
  config.apiKeys.gemini = apiKeys.geminiApiKey;
83
82
  }
83
+
84
+ // Configure coding agent based on available keys
85
+ if (apiKeys.julesApiKey && apiKeys.geminiApiKey) {
86
+ const codingAgentChoice = await Prompts.chooseCodingAgent();
87
+ config.codingAgent.primary = codingAgentChoice.primary;
88
+ config.codingAgent.fallback = codingAgentChoice.fallback;
89
+ } else if (apiKeys.julesApiKey) {
90
+ config.codingAgent.primary = 'jules';
91
+ config.codingAgent.fallback = 'jules';
92
+ } else if (apiKeys.geminiApiKey) {
93
+ config.codingAgent.primary = 'gemini';
94
+ config.codingAgent.fallback = 'gemini';
95
+ }
96
+
97
+ spinner.start();
84
98
  }
85
99
 
86
100
  await ConfigurationManager.save(config);
@@ -0,0 +1,307 @@
1
+ import { BaseGuard } from '../core/baseguard.js';
2
+ import { ConfigurationManager } from '../core/configuration.js';
3
+ import { ConfigurationRecovery } from '../core/configuration-recovery.js';
4
+ import { GracefulDegradationManager } from '../core/graceful-degradation-manager.js';
5
+ import { SystemErrorHandler } from '../core/system-error-handler.js';
6
+ import { logger } from '../core/debug-logger.js';
7
+ import { UIComponents } from '../ui/components.js';
8
+ import chalk from 'chalk';
9
+
10
+ /**
11
+ * Show BaseGuard system status and health
12
+ */
13
+ export async function status(options: {
14
+ verbose?: boolean;
15
+ services?: boolean;
16
+ config?: boolean;
17
+ errors?: boolean;
18
+ }): Promise<void> {
19
+ const categoryLogger = logger.createCategoryLogger('status-command');
20
+
21
+ try {
22
+ UIComponents.showHeader();
23
+ console.log(chalk.cyan('šŸ” BaseGuard System Status\n'));
24
+
25
+ // Load configuration with recovery if needed
26
+ let config;
27
+ try {
28
+ config = await ConfigurationManager.load();
29
+ } catch (error) {
30
+ console.log(chalk.red('āŒ Configuration Error'));
31
+ console.log(chalk.dim(` ${error instanceof Error ? error.message : 'Unknown error'}`));
32
+
33
+ if (options.config) {
34
+ console.log(chalk.cyan('\nšŸ”§ Configuration Recovery Options:'));
35
+ console.log(chalk.cyan(' • Run "base config recover" to attempt automatic recovery'));
36
+ console.log(chalk.cyan(' • Run "base init" to create a new configuration'));
37
+ console.log(chalk.cyan(' • Check .baseguardrc.json file manually'));
38
+ }
39
+
40
+ return;
41
+ }
42
+
43
+ // Initialize BaseGuard
44
+ const baseGuard = new BaseGuard(config);
45
+
46
+ // Show system health
47
+ const health = await baseGuard.getHealthStatus();
48
+
49
+ // Overall status
50
+ const statusIcon = health.overall === 'healthy' ? 'āœ…' : health.overall === 'degraded' ? 'āš ļø' : 'āŒ';
51
+ const statusColor = health.overall === 'healthy' ? chalk.green : health.overall === 'degraded' ? chalk.yellow : chalk.red;
52
+
53
+ console.log(statusColor(`${statusIcon} Overall Status: ${health.overall.toUpperCase()}`));
54
+ console.log(chalk.dim(` Degradation Mode: ${health.degradationMode}`));
55
+
56
+ // Component status
57
+ console.log(chalk.cyan('\nšŸ“Š Component Status:'));
58
+ for (const [component, status] of Object.entries(health.components)) {
59
+ const componentIcon = status.status === 'healthy' ? 'āœ…' : status.status === 'degraded' ? 'āš ļø' : 'āŒ';
60
+ console.log(` ${componentIcon} ${component}: ${status.status}`);
61
+
62
+ if (options.verbose && status.details) {
63
+ if (status.details.errors?.length > 0) {
64
+ console.log(chalk.dim(` Errors: ${status.details.errors.slice(0, 3).join(', ')}`));
65
+ }
66
+ if (status.details.error) {
67
+ console.log(chalk.dim(` Error: ${status.details.error}`));
68
+ }
69
+ if (status.details.lastCheck) {
70
+ const age = Math.round((Date.now() - status.details.lastCheck) / 1000);
71
+ console.log(chalk.dim(` Last Check: ${age}s ago`));
72
+ }
73
+ }
74
+ }
75
+
76
+ // Service status (if requested)
77
+ if (options.services) {
78
+ console.log(chalk.cyan('\n🌐 Service Status:'));
79
+ const serviceStatus = GracefulDegradationManager.getServiceStatus();
80
+
81
+ for (const [service, info] of serviceStatus) {
82
+ const serviceIcon = info.available ? 'āœ…' : 'āŒ';
83
+ const age = Math.round((Date.now() - info.lastCheck) / 1000);
84
+ console.log(` ${serviceIcon} ${service}: ${info.available ? 'Available' : 'Unavailable'} (${age}s ago)`);
85
+
86
+ if (!info.available && info.error && options.verbose) {
87
+ console.log(chalk.dim(` Error: ${info.error}`));
88
+ }
89
+ }
90
+
91
+ // Refresh service status
92
+ console.log(chalk.dim('\nšŸ”„ Refreshing service status...'));
93
+ await GracefulDegradationManager.refreshServiceStatus();
94
+ }
95
+
96
+ // Configuration status (if requested)
97
+ if (options.config) {
98
+ console.log(chalk.cyan('\nāš™ļø Configuration Status:'));
99
+
100
+ const configIntegrity = await ConfigurationRecovery.validateIntegrity();
101
+ const configIcon = configIntegrity.valid ? 'āœ…' : 'āŒ';
102
+ console.log(` ${configIcon} Configuration File: ${configIntegrity.valid ? 'Valid' : 'Invalid'}`);
103
+
104
+ if (!configIntegrity.valid) {
105
+ console.log(chalk.red(' Errors:'));
106
+ configIntegrity.errors.forEach(error => {
107
+ console.log(chalk.red(` • ${error}`));
108
+ });
109
+
110
+ console.log(chalk.cyan(' Suggestions:'));
111
+ configIntegrity.suggestions.forEach(suggestion => {
112
+ console.log(chalk.cyan(` • ${suggestion}`));
113
+ });
114
+ }
115
+
116
+ // Show configuration details
117
+ if (options.verbose) {
118
+ console.log(chalk.dim('\n Configuration Details:'));
119
+ console.log(chalk.dim(` Version: ${config.version}`));
120
+ console.log(chalk.dim(` Targets: ${config.targets.length} browser(s)`));
121
+ console.log(chalk.dim(` API Keys: Jules ${config.apiKeys.jules ? 'āœ“' : 'āœ—'}, Gemini ${config.apiKeys.gemini ? 'āœ“' : 'āœ—'}`));
122
+ console.log(chalk.dim(` Automation: ${config.automation.enabled ? 'Enabled' : 'Disabled'}`));
123
+ }
124
+
125
+ // Show available backups
126
+ const backups = await ConfigurationRecovery.listBackups();
127
+ if (backups.length > 0) {
128
+ console.log(chalk.dim(`\n Available Backups: ${backups.length}`));
129
+ if (options.verbose) {
130
+ backups.slice(0, 3).forEach(backup => {
131
+ console.log(chalk.dim(` • ${backup.timestamp.toLocaleString()} (${backup.source})`));
132
+ });
133
+ }
134
+ }
135
+ }
136
+
137
+ // Error summary (if requested)
138
+ if (options.errors) {
139
+ console.log(chalk.cyan('\n🚨 Error Summary:'));
140
+
141
+ const errorSummary = logger.getErrorSummary();
142
+ console.log(` Total Errors: ${errorSummary.totalErrors}`);
143
+ console.log(` Total Warnings: ${errorSummary.totalWarnings}`);
144
+
145
+ if (errorSummary.totalErrors > 0) {
146
+ console.log(chalk.red('\n Error Categories:'));
147
+ for (const [category, count] of Object.entries(errorSummary.errorsByCategory)) {
148
+ console.log(chalk.red(` ${category}: ${count}`));
149
+ }
150
+
151
+ if (options.verbose && errorSummary.recentErrors.length > 0) {
152
+ console.log(chalk.red('\n Recent Errors:'));
153
+ errorSummary.recentErrors.slice(0, 3).forEach(error => {
154
+ console.log(chalk.red(` • ${error.message} (${error.category})`));
155
+ });
156
+ }
157
+ }
158
+
159
+ // System error handler status
160
+ const systemErrorSummary = SystemErrorHandler.getErrorSummary();
161
+ if (systemErrorSummary.total > 0) {
162
+ console.log(chalk.yellow('\n System Errors:'));
163
+ console.log(` Total: ${systemErrorSummary.total}`);
164
+ console.log(` Critical: ${systemErrorSummary.critical}`);
165
+ console.log(` Recoverable: ${systemErrorSummary.recoverable}`);
166
+
167
+ if (options.verbose) {
168
+ console.log(chalk.yellow('\n By Severity:'));
169
+ for (const [severity, count] of Object.entries(systemErrorSummary.bySeverity)) {
170
+ if (count > 0) {
171
+ console.log(` ${severity}: ${count}`);
172
+ }
173
+ }
174
+ }
175
+ }
176
+ }
177
+
178
+ // Recommendations
179
+ if (health.recommendations.length > 0) {
180
+ console.log(chalk.cyan('\nšŸ’” Recommendations:'));
181
+ health.recommendations.forEach(rec => {
182
+ console.log(chalk.cyan(` • ${rec}`));
183
+ });
184
+ }
185
+
186
+ // Show degradation mode details
187
+ const mode = GracefulDegradationManager.getCurrentMode();
188
+ if (mode && mode.name !== 'Full Functionality') {
189
+ console.log(chalk.yellow(`\nāš ļø Currently in ${mode.name} Mode`));
190
+ console.log(chalk.dim(` ${mode.description}`));
191
+
192
+ if (mode.limitations.length > 0) {
193
+ console.log(chalk.yellow('\n Limitations:'));
194
+ mode.limitations.forEach(limitation => {
195
+ console.log(chalk.yellow(` • ${limitation}`));
196
+ });
197
+ }
198
+
199
+ console.log(chalk.cyan('\n Available Features:'));
200
+ if (mode.capabilities.baselineChecking) {
201
+ console.log(chalk.green(' āœ… Baseline compatibility checking'));
202
+ }
203
+ if (mode.capabilities.caching) {
204
+ console.log(chalk.green(' āœ… Result caching'));
205
+ }
206
+ if (!mode.capabilities.aiAnalysis) {
207
+ console.log(chalk.yellow(' āš ļø AI analysis disabled'));
208
+ }
209
+ if (!mode.capabilities.autoFix) {
210
+ console.log(chalk.yellow(' āš ļø Auto-fixing disabled'));
211
+ }
212
+ }
213
+
214
+ // Performance info
215
+ if (options.verbose) {
216
+ const memoryUsage = process.memoryUsage();
217
+ const uptime = process.uptime();
218
+
219
+ console.log(chalk.cyan('\nšŸ“ˆ Performance Info:'));
220
+ console.log(` Uptime: ${Math.round(uptime)}s`);
221
+ console.log(` Memory: ${Math.round(memoryUsage.heapUsed / 1024 / 1024)}MB used / ${Math.round(memoryUsage.heapTotal / 1024 / 1024)}MB total`);
222
+ console.log(` Platform: ${process.platform} ${process.arch}`);
223
+ console.log(` Node.js: ${process.version}`);
224
+ }
225
+
226
+ // Quick actions
227
+ console.log(chalk.cyan('\nšŸ”§ Quick Actions:'));
228
+ const actions = [];
229
+
230
+ if (health.overall !== 'healthy') {
231
+ actions.push('Run "base config recover" to attempt automatic recovery');
232
+ }
233
+
234
+ if (!mode?.capabilities.aiAnalysis) {
235
+ actions.push('Check network connectivity to restore AI features');
236
+ }
237
+
238
+ const errorSummary = logger.getErrorSummary();
239
+ if (errorSummary.totalErrors > 5) {
240
+ actions.push('Run with --errors flag to see detailed error information');
241
+ }
242
+
243
+ actions.push('Run "base check" to scan for compatibility issues');
244
+ actions.push('Run "base status --verbose" for detailed information');
245
+
246
+ actions.forEach(action => {
247
+ console.log(chalk.cyan(` • ${action}`));
248
+ });
249
+
250
+ } catch (error) {
251
+ categoryLogger.error('Status command failed', { error });
252
+
253
+ console.log(chalk.red('\nāŒ Failed to get system status'));
254
+ console.log(chalk.red(` Error: ${error instanceof Error ? error.message : 'Unknown error'}`));
255
+
256
+ console.log(chalk.cyan('\nšŸ”§ Recovery Options:'));
257
+ console.log(chalk.cyan(' • Run "base init" to reinitialize BaseGuard'));
258
+ console.log(chalk.cyan(' • Check file permissions in your project directory'));
259
+ console.log(chalk.cyan(' • Verify BaseGuard installation: npm list baseguard'));
260
+
261
+ process.exit(1);
262
+ }
263
+ }
264
+
265
+ /**
266
+ * Show detailed system diagnostics
267
+ */
268
+ export async function diagnostics(): Promise<void> {
269
+ const categoryLogger = logger.createCategoryLogger('diagnostics');
270
+
271
+ try {
272
+ console.log(chalk.cyan('šŸ”¬ BaseGuard System Diagnostics\n'));
273
+
274
+ // Generate comprehensive debug report
275
+ const reportFile = await logger.generateDebugReport();
276
+ console.log(chalk.green(`āœ… Debug report generated: ${reportFile}`));
277
+
278
+ // Show configuration recovery wizard
279
+ console.log(chalk.cyan('\nšŸ”§ Running Configuration Recovery Wizard...'));
280
+ await ConfigurationRecovery.runRecoveryWizard();
281
+
282
+ // Show service status
283
+ console.log(chalk.cyan('\n🌐 Checking Service Availability...'));
284
+ await GracefulDegradationManager.refreshServiceStatus();
285
+
286
+ // Show error log summary
287
+ const loggerErrorSummary = logger.getErrorSummary();
288
+ if (loggerErrorSummary.totalErrors > 0) {
289
+ console.log(chalk.yellow(`\nāš ļø Found ${loggerErrorSummary.totalErrors} errors in logs`));
290
+ console.log(chalk.cyan('Recent errors:'));
291
+ loggerErrorSummary.recentErrors.slice(0, 5).forEach(error => {
292
+ console.log(chalk.red(` • ${error.message} (${error.category})`));
293
+ });
294
+ }
295
+
296
+ // Cleanup old files
297
+ console.log(chalk.cyan('\n🧹 Cleaning up old files...'));
298
+ await logger.cleanupOldLogs();
299
+ await GracefulDegradationManager.cleanupCache();
300
+
301
+ console.log(chalk.green('\nāœ… Diagnostics completed'));
302
+
303
+ } catch (error) {
304
+ categoryLogger.error('Diagnostics failed', { error });
305
+ console.log(chalk.red(`\nāŒ Diagnostics failed: ${error instanceof Error ? error.message : 'Unknown error'}`));
306
+ }
307
+ }