baseguard 1.0.0
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.
- package/.eslintrc.json +25 -0
- package/.prettierrc +8 -0
- package/README.md +94 -0
- package/bin/base.js +494 -0
- package/dist/ai/fix-manager.d.ts +67 -0
- package/dist/ai/fix-manager.d.ts.map +1 -0
- package/dist/ai/fix-manager.js +326 -0
- package/dist/ai/fix-manager.js.map +1 -0
- package/dist/ai/gemini-analyzer.d.ts +116 -0
- package/dist/ai/gemini-analyzer.d.ts.map +1 -0
- package/dist/ai/gemini-analyzer.js +572 -0
- package/dist/ai/gemini-analyzer.js.map +1 -0
- package/dist/ai/index.d.ts +4 -0
- package/dist/ai/index.d.ts.map +1 -0
- package/dist/ai/index.js +5 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/jules-implementer.d.ts +115 -0
- package/dist/ai/jules-implementer.d.ts.map +1 -0
- package/dist/ai/jules-implementer.js +387 -0
- package/dist/ai/jules-implementer.js.map +1 -0
- package/dist/commands/automation.d.ts +5 -0
- package/dist/commands/automation.d.ts.map +1 -0
- package/dist/commands/automation.js +305 -0
- package/dist/commands/automation.js.map +1 -0
- package/dist/commands/check.d.ts +9 -0
- package/dist/commands/check.d.ts.map +1 -0
- package/dist/commands/check.js +113 -0
- package/dist/commands/check.js.map +1 -0
- package/dist/commands/config.d.ts +11 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +324 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/fix.d.ts +9 -0
- package/dist/commands/fix.d.ts.map +1 -0
- package/dist/commands/fix.js +207 -0
- package/dist/commands/fix.js.map +1 -0
- package/dist/commands/index.d.ts +6 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +7 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/init.d.ts +9 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +125 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/core/api-key-manager.d.ts +83 -0
- package/dist/core/api-key-manager.d.ts.map +1 -0
- package/dist/core/api-key-manager.js +244 -0
- package/dist/core/api-key-manager.js.map +1 -0
- package/dist/core/baseguard.d.ts +46 -0
- package/dist/core/baseguard.d.ts.map +1 -0
- package/dist/core/baseguard.js +132 -0
- package/dist/core/baseguard.js.map +1 -0
- package/dist/core/baseline-checker.d.ts +63 -0
- package/dist/core/baseline-checker.d.ts.map +1 -0
- package/dist/core/baseline-checker.js +502 -0
- package/dist/core/baseline-checker.js.map +1 -0
- package/dist/core/cache-manager.d.ts +88 -0
- package/dist/core/cache-manager.d.ts.map +1 -0
- package/dist/core/cache-manager.js +213 -0
- package/dist/core/cache-manager.js.map +1 -0
- package/dist/core/configuration.d.ts +140 -0
- package/dist/core/configuration.d.ts.map +1 -0
- package/dist/core/configuration.js +474 -0
- package/dist/core/configuration.js.map +1 -0
- package/dist/core/directory-filter.d.ts +90 -0
- package/dist/core/directory-filter.d.ts.map +1 -0
- package/dist/core/directory-filter.js +319 -0
- package/dist/core/directory-filter.js.map +1 -0
- package/dist/core/error-handler.d.ts +110 -0
- package/dist/core/error-handler.d.ts.map +1 -0
- package/dist/core/error-handler.js +392 -0
- package/dist/core/error-handler.js.map +1 -0
- package/dist/core/file-processor.d.ts +80 -0
- package/dist/core/file-processor.d.ts.map +1 -0
- package/dist/core/file-processor.js +259 -0
- package/dist/core/file-processor.js.map +1 -0
- package/dist/core/gitignore-manager.d.ts +44 -0
- package/dist/core/gitignore-manager.d.ts.map +1 -0
- package/dist/core/gitignore-manager.js +147 -0
- package/dist/core/gitignore-manager.js.map +1 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +13 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/lazy-loader.d.ts +68 -0
- package/dist/core/lazy-loader.d.ts.map +1 -0
- package/dist/core/lazy-loader.js +260 -0
- package/dist/core/lazy-loader.js.map +1 -0
- package/dist/core/memory-manager.d.ts +1 -0
- package/dist/core/memory-manager.d.ts.map +1 -0
- package/dist/core/memory-manager.js +2 -0
- package/dist/core/memory-manager.js.map +1 -0
- package/dist/core/startup-optimizer.d.ts +45 -0
- package/dist/core/startup-optimizer.d.ts.map +1 -0
- package/dist/core/startup-optimizer.js +140 -0
- package/dist/core/startup-optimizer.js.map +1 -0
- package/dist/git/automation-engine.d.ts +58 -0
- package/dist/git/automation-engine.d.ts.map +1 -0
- package/dist/git/automation-engine.js +318 -0
- package/dist/git/automation-engine.js.map +1 -0
- package/dist/git/github-manager.d.ts +71 -0
- package/dist/git/github-manager.d.ts.map +1 -0
- package/dist/git/github-manager.js +226 -0
- package/dist/git/github-manager.js.map +1 -0
- package/dist/git/hook-manager.d.ts +43 -0
- package/dist/git/hook-manager.d.ts.map +1 -0
- package/dist/git/hook-manager.js +191 -0
- package/dist/git/hook-manager.js.map +1 -0
- package/dist/git/index.d.ts +4 -0
- package/dist/git/index.d.ts.map +1 -0
- package/dist/git/index.js +5 -0
- package/dist/git/index.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/parsers/feature-validator.d.ts +60 -0
- package/dist/parsers/feature-validator.d.ts.map +1 -0
- package/dist/parsers/feature-validator.js +483 -0
- package/dist/parsers/feature-validator.js.map +1 -0
- package/dist/parsers/index.d.ts +8 -0
- package/dist/parsers/index.d.ts.map +1 -0
- package/dist/parsers/index.js +9 -0
- package/dist/parsers/index.js.map +1 -0
- package/dist/parsers/parser-manager.d.ts +103 -0
- package/dist/parsers/parser-manager.d.ts.map +1 -0
- package/dist/parsers/parser-manager.js +321 -0
- package/dist/parsers/parser-manager.js.map +1 -0
- package/dist/parsers/parser.d.ts +23 -0
- package/dist/parsers/parser.d.ts.map +1 -0
- package/dist/parsers/parser.js +6 -0
- package/dist/parsers/parser.js.map +1 -0
- package/dist/parsers/react-parser.d.ts +22 -0
- package/dist/parsers/react-parser.d.ts.map +1 -0
- package/dist/parsers/react-parser.js +307 -0
- package/dist/parsers/react-parser.js.map +1 -0
- package/dist/parsers/svelte-parser.d.ts +33 -0
- package/dist/parsers/svelte-parser.d.ts.map +1 -0
- package/dist/parsers/svelte-parser.js +408 -0
- package/dist/parsers/svelte-parser.js.map +1 -0
- package/dist/parsers/vanilla-parser.d.ts +31 -0
- package/dist/parsers/vanilla-parser.d.ts.map +1 -0
- package/dist/parsers/vanilla-parser.js +590 -0
- package/dist/parsers/vanilla-parser.js.map +1 -0
- package/dist/parsers/vue-parser.d.ts +9 -0
- package/dist/parsers/vue-parser.d.ts.map +1 -0
- package/dist/parsers/vue-parser.js +16 -0
- package/dist/parsers/vue-parser.js.map +1 -0
- package/dist/terminal-header.d.ts +12 -0
- package/dist/terminal-header.js +45 -0
- package/dist/types/index.d.ts +83 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/ui/components.d.ts +133 -0
- package/dist/ui/components.d.ts.map +1 -0
- package/dist/ui/components.js +482 -0
- package/dist/ui/components.js.map +1 -0
- package/dist/ui/help.d.ts +11 -0
- package/dist/ui/help.d.ts.map +1 -0
- package/dist/ui/help.js +161 -0
- package/dist/ui/help.js.map +1 -0
- package/dist/ui/index.d.ts +5 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +5 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/prompts.d.ts +63 -0
- package/dist/ui/prompts.d.ts.map +1 -0
- package/dist/ui/prompts.js +611 -0
- package/dist/ui/prompts.js.map +1 -0
- package/dist/ui/terminal-header.d.ts +13 -0
- package/dist/ui/terminal-header.d.ts.map +1 -0
- package/dist/ui/terminal-header.js +46 -0
- package/dist/ui/terminal-header.js.map +1 -0
- package/package.json +80 -0
- package/src/ai/__tests__/gemini-analyzer.test.ts +181 -0
- package/src/ai/fix-manager.ts +362 -0
- package/src/ai/gemini-analyzer.ts +671 -0
- package/src/ai/index.ts +4 -0
- package/src/ai/jules-implementer.ts +459 -0
- package/src/commands/automation.ts +344 -0
- package/src/commands/check.ts +299 -0
- package/src/commands/config.ts +365 -0
- package/src/commands/fix.ts +234 -0
- package/src/commands/index.ts +6 -0
- package/src/commands/init.ts +142 -0
- package/src/commands/status.ts +0 -0
- package/src/core/api-key-manager.ts +298 -0
- package/src/core/baseguard.ts +742 -0
- package/src/core/baseline-checker.ts +563 -0
- package/src/core/cache-manager.ts +270 -0
- package/src/core/configuration-recovery.ts +676 -0
- package/src/core/configuration.ts +559 -0
- package/src/core/debug-logger.ts +590 -0
- package/src/core/directory-filter.ts +421 -0
- package/src/core/error-handler.ts +517 -0
- package/src/core/file-processor.ts +331 -0
- package/src/core/gitignore-manager.ts +169 -0
- package/src/core/graceful-degradation-manager.ts +596 -0
- package/src/core/index.ts +13 -0
- package/src/core/lazy-loader.ts +307 -0
- package/src/core/logger.ts +0 -0
- package/src/core/memory-manager.ts +294 -0
- package/src/core/startup-optimizer.ts +173 -0
- package/src/core/system-error-handler.ts +746 -0
- package/src/git/automation-engine.ts +361 -0
- package/src/git/github-manager.ts +260 -0
- package/src/git/hook-manager.ts +210 -0
- package/src/git/index.ts +4 -0
- package/src/index.ts +8 -0
- package/src/parsers/feature-validator.ts +559 -0
- package/src/parsers/index.ts +8 -0
- package/src/parsers/parser-manager.ts +419 -0
- package/src/parsers/parser.ts +26 -0
- package/src/parsers/react-parser-optimized.ts +161 -0
- package/src/parsers/react-parser.ts +359 -0
- package/src/parsers/svelte-parser.ts +506 -0
- package/src/parsers/vanilla-parser.ts +682 -0
- package/src/parsers/vue-parser.ts +472 -0
- package/src/types/index.ts +92 -0
- package/src/ui/components.ts +567 -0
- package/src/ui/help.ts +193 -0
- package/src/ui/index.ts +4 -0
- package/src/ui/prompts.ts +688 -0
- package/src/ui/terminal-header.ts +59 -0
- package/test-config-commands.js +56 -0
- package/test-header-simple.js +33 -0
- package/test-terminal-header.js +12 -0
- package/test-ui.js +29 -0
- package/tests/e2e/baseguard.e2e.test.ts +516 -0
- package/tests/e2e/cross-platform.e2e.test.ts +420 -0
- package/tests/e2e/git-integration.e2e.test.ts +487 -0
- package/tests/fixtures/react-project/package.json +14 -0
- package/tests/fixtures/react-project/src/App.css +76 -0
- package/tests/fixtures/react-project/src/App.tsx +77 -0
- package/tests/fixtures/svelte-project/package.json +11 -0
- package/tests/fixtures/svelte-project/src/App.svelte +369 -0
- package/tests/fixtures/vanilla-project/index.html +76 -0
- package/tests/fixtures/vanilla-project/script.js +331 -0
- package/tests/fixtures/vanilla-project/styles.css +359 -0
- package/tests/fixtures/vue-project/package.json +12 -0
- package/tests/fixtures/vue-project/src/App.vue +216 -0
- package/tsconfig.json +36 -0
- package/vitest.config.ts +10 -0
|
@@ -0,0 +1,742 @@
|
|
|
1
|
+
import type { Violation, Analysis, Fix, Configuration } from '../types/index.js';
|
|
2
|
+
import { ParserManager } from '../parsers/parser-manager.js';
|
|
3
|
+
import { BaselineChecker } from './baseline-checker.js';
|
|
4
|
+
import { FileProcessor } from './file-processor.js';
|
|
5
|
+
import { DirectoryFilter } from './directory-filter.js';
|
|
6
|
+
import { CacheManager } from './cache-manager.js';
|
|
7
|
+
import { SystemErrorHandler } from './system-error-handler.js';
|
|
8
|
+
import { GracefulDegradationManager } from './graceful-degradation-manager.js';
|
|
9
|
+
import { ConfigurationRecovery } from './configuration-recovery.js';
|
|
10
|
+
import { logger } from './debug-logger.js';
|
|
11
|
+
import { ErrorHandler, APIError } from './error-handler.js';
|
|
12
|
+
import chalk from 'chalk';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Main BaseGuard class that orchestrates compatibility checking and fixing
|
|
16
|
+
*/
|
|
17
|
+
export class BaseGuard {
|
|
18
|
+
private config: Configuration;
|
|
19
|
+
private parserManager: ParserManager;
|
|
20
|
+
private baselineChecker: BaselineChecker;
|
|
21
|
+
private fileProcessor: FileProcessor;
|
|
22
|
+
private directoryFilter: DirectoryFilter;
|
|
23
|
+
private cacheManager: CacheManager;
|
|
24
|
+
private categoryLogger: ReturnType<typeof logger.createCategoryLogger>;
|
|
25
|
+
private initialized = false;
|
|
26
|
+
|
|
27
|
+
constructor(config: Configuration) {
|
|
28
|
+
this.config = config;
|
|
29
|
+
this.categoryLogger = logger.createCategoryLogger('baseguard');
|
|
30
|
+
|
|
31
|
+
// Initialize with error handling
|
|
32
|
+
this.initializeComponents();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Initialize BaseGuard components with error recovery
|
|
37
|
+
*/
|
|
38
|
+
private async initializeComponents(): Promise<void> {
|
|
39
|
+
try {
|
|
40
|
+
this.categoryLogger.info('Initializing BaseGuard components');
|
|
41
|
+
|
|
42
|
+
// Initialize graceful degradation manager
|
|
43
|
+
await GracefulDegradationManager.initialize();
|
|
44
|
+
|
|
45
|
+
// Initialize components with error handling
|
|
46
|
+
await SystemErrorHandler.handleGracefully(
|
|
47
|
+
async () => {
|
|
48
|
+
this.cacheManager = new CacheManager({
|
|
49
|
+
maxCacheSize: parseInt(process.env.BASEGUARD_CACHE_SIZE || '2000'),
|
|
50
|
+
cacheValidityMs: 10 * 60 * 1000 // 10 minutes
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
new CacheManager({ maxCacheSize: 1000, cacheValidityMs: 5 * 60 * 1000 }),
|
|
54
|
+
{ operation: 'cache_manager_init' }
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
await SystemErrorHandler.handleGracefully(
|
|
58
|
+
async () => {
|
|
59
|
+
this.parserManager = new ParserManager();
|
|
60
|
+
},
|
|
61
|
+
new ParserManager(),
|
|
62
|
+
{ operation: 'parser_manager_init' }
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
await SystemErrorHandler.handleGracefully(
|
|
66
|
+
async () => {
|
|
67
|
+
this.baselineChecker = new BaselineChecker();
|
|
68
|
+
},
|
|
69
|
+
new BaselineChecker(),
|
|
70
|
+
{ operation: 'baseline_checker_init' }
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const maxWorkers = parseInt(process.env.BASEGUARD_MAX_WORKERS || '8');
|
|
74
|
+
const maxFiles = parseInt(process.env.BASEGUARD_MAX_FILES || '5000');
|
|
75
|
+
|
|
76
|
+
await SystemErrorHandler.handleGracefully(
|
|
77
|
+
async () => {
|
|
78
|
+
this.fileProcessor = new FileProcessor({
|
|
79
|
+
maxWorkers,
|
|
80
|
+
cacheManager: this.cacheManager
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
new FileProcessor({ maxWorkers: 2, cacheManager: this.cacheManager }),
|
|
84
|
+
{ operation: 'file_processor_init' }
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
await SystemErrorHandler.handleGracefully(
|
|
88
|
+
async () => {
|
|
89
|
+
this.directoryFilter = new DirectoryFilter({
|
|
90
|
+
maxDepth: 8,
|
|
91
|
+
maxFiles
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
new DirectoryFilter({ maxDepth: 4, maxFiles: 1000 }),
|
|
95
|
+
{ operation: 'directory_filter_init' }
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
this.initialized = true;
|
|
99
|
+
this.categoryLogger.info('BaseGuard components initialized successfully');
|
|
100
|
+
|
|
101
|
+
} catch (error) {
|
|
102
|
+
this.categoryLogger.error('Failed to initialize BaseGuard components', { error });
|
|
103
|
+
throw new Error(`BaseGuard initialization failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Ensure BaseGuard is properly initialized
|
|
109
|
+
*/
|
|
110
|
+
private async ensureInitialized(): Promise<void> {
|
|
111
|
+
if (!this.initialized) {
|
|
112
|
+
await this.initializeComponents();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Check files for compatibility violations with enhanced error recovery
|
|
118
|
+
*/
|
|
119
|
+
async checkViolations(patterns: string[] = []): Promise<Violation[]> {
|
|
120
|
+
await this.ensureInitialized();
|
|
121
|
+
|
|
122
|
+
const sessionId = logger.startSession('check-violations');
|
|
123
|
+
this.categoryLogger.startPerformance('check-violations');
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
const violations: Violation[] = [];
|
|
127
|
+
|
|
128
|
+
// Find files using smart filtering and caching with error recovery
|
|
129
|
+
const allFiles = await SystemErrorHandler.withRetry(
|
|
130
|
+
async () => {
|
|
131
|
+
return patterns.length > 0
|
|
132
|
+
? await this.directoryFilter.findFilesWithGlob(patterns)
|
|
133
|
+
: await this.directoryFilter.findFiles(['src', 'app', 'pages', 'components'], {
|
|
134
|
+
includeHidden: false
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
{ operation: 'find_files', details: { patterns } },
|
|
138
|
+
3 // max retries
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
if (allFiles.length === 0) {
|
|
142
|
+
this.categoryLogger.warn('No supported files found to check', { patterns });
|
|
143
|
+
return violations;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
this.categoryLogger.info(`Processing ${allFiles.length} files for violations`);
|
|
147
|
+
|
|
148
|
+
// Process files concurrently with caching and error recovery
|
|
149
|
+
const allFeatures = await SystemErrorHandler.handleGracefully(
|
|
150
|
+
() => this.fileProcessor.processFiles(allFiles),
|
|
151
|
+
[], // fallback to empty array
|
|
152
|
+
{ operation: 'process_files', details: { fileCount: allFiles.length } },
|
|
153
|
+
{
|
|
154
|
+
logError: true,
|
|
155
|
+
showWarning: true,
|
|
156
|
+
attemptRecovery: true
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
this.categoryLogger.info(`Extracted ${allFeatures.length} features from ${allFiles.length} files`);
|
|
161
|
+
|
|
162
|
+
// Check each feature for compatibility violations with error recovery
|
|
163
|
+
let processedFeatures = 0;
|
|
164
|
+
let failedFeatures = 0;
|
|
165
|
+
|
|
166
|
+
for (const feature of allFeatures) {
|
|
167
|
+
try {
|
|
168
|
+
const compatibilityResult = await SystemErrorHandler.handleGracefully(
|
|
169
|
+
() => this.baselineChecker.checkCompatibility(feature, this.config.targets),
|
|
170
|
+
{ violations: [] }, // fallback result
|
|
171
|
+
{
|
|
172
|
+
operation: 'check_compatibility',
|
|
173
|
+
file: feature.file,
|
|
174
|
+
details: { feature: feature.feature }
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
// Add violations with file context
|
|
179
|
+
for (const violation of compatibilityResult.violations) {
|
|
180
|
+
violations.push({
|
|
181
|
+
...violation,
|
|
182
|
+
file: feature.file || 'unknown',
|
|
183
|
+
line: feature.line,
|
|
184
|
+
column: feature.column,
|
|
185
|
+
context: feature.context
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
processedFeatures++;
|
|
190
|
+
} catch (error) {
|
|
191
|
+
failedFeatures++;
|
|
192
|
+
this.categoryLogger.warn('Failed to check feature compatibility', {
|
|
193
|
+
feature: feature.feature,
|
|
194
|
+
file: feature.file,
|
|
195
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// Continue processing other features
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const duration = this.categoryLogger.endPerformance('check-violations', {
|
|
204
|
+
totalFiles: allFiles.length,
|
|
205
|
+
processedFeatures,
|
|
206
|
+
failedFeatures,
|
|
207
|
+
violationsFound: violations.length
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
this.categoryLogger.info('Violation check completed', {
|
|
211
|
+
duration,
|
|
212
|
+
totalFiles: allFiles.length,
|
|
213
|
+
processedFeatures,
|
|
214
|
+
failedFeatures,
|
|
215
|
+
violationsFound: violations.length
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
return violations;
|
|
219
|
+
|
|
220
|
+
} catch (error) {
|
|
221
|
+
this.categoryLogger.error('Violation check failed', { error });
|
|
222
|
+
|
|
223
|
+
// Try graceful degradation
|
|
224
|
+
const mode = GracefulDegradationManager.getCurrentMode();
|
|
225
|
+
if (mode?.capabilities.baselineChecking) {
|
|
226
|
+
this.categoryLogger.info('Attempting graceful degradation for violation checking');
|
|
227
|
+
|
|
228
|
+
try {
|
|
229
|
+
// Simplified violation checking with minimal features
|
|
230
|
+
const basicViolations = await this.performBasicViolationCheck(patterns);
|
|
231
|
+
this.categoryLogger.info('Graceful degradation successful', { violationsFound: basicViolations.length });
|
|
232
|
+
return basicViolations;
|
|
233
|
+
} catch (degradationError) {
|
|
234
|
+
this.categoryLogger.error('Graceful degradation also failed', { error: degradationError });
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
throw error;
|
|
239
|
+
} finally {
|
|
240
|
+
await logger.endSession();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Perform basic violation checking as fallback
|
|
246
|
+
*/
|
|
247
|
+
private async performBasicViolationCheck(patterns: string[]): Promise<Violation[]> {
|
|
248
|
+
const violations: Violation[] = [];
|
|
249
|
+
|
|
250
|
+
try {
|
|
251
|
+
// Use minimal file processing
|
|
252
|
+
const basicFiles = patterns.length > 0 ? patterns : ['src/**/*.{js,ts,jsx,tsx,css,vue,svelte}'];
|
|
253
|
+
|
|
254
|
+
// Simple file enumeration without complex processing
|
|
255
|
+
const { glob } = await import('glob');
|
|
256
|
+
const files = await glob(basicFiles.join(','), { ignore: ['node_modules/**', 'dist/**', 'build/**'] });
|
|
257
|
+
|
|
258
|
+
this.categoryLogger.info(`Basic violation check on ${files.length} files`);
|
|
259
|
+
|
|
260
|
+
// Process a limited number of files to avoid overwhelming the system
|
|
261
|
+
const limitedFiles = files.slice(0, 100);
|
|
262
|
+
|
|
263
|
+
for (const file of limitedFiles) {
|
|
264
|
+
try {
|
|
265
|
+
// Basic feature extraction without complex parsing
|
|
266
|
+
const basicFeatures = await this.extractBasicFeatures(file);
|
|
267
|
+
|
|
268
|
+
for (const feature of basicFeatures) {
|
|
269
|
+
const result = await this.baselineChecker.checkCompatibility(feature, this.config.targets);
|
|
270
|
+
violations.push(...result.violations);
|
|
271
|
+
}
|
|
272
|
+
} catch (error) {
|
|
273
|
+
// Skip individual file errors in basic mode
|
|
274
|
+
this.categoryLogger.debug('Skipped file in basic mode', { file, error: error instanceof Error ? error.message : 'Unknown error' });
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
} catch (error) {
|
|
279
|
+
this.categoryLogger.error('Basic violation check failed', { error });
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return violations;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Extract basic features without complex parsing
|
|
287
|
+
*/
|
|
288
|
+
private async extractBasicFeatures(file: string): Promise<any[]> {
|
|
289
|
+
// This is a simplified feature extraction for fallback mode
|
|
290
|
+
// In a real implementation, this would do basic text pattern matching
|
|
291
|
+
return [];
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Get processing statistics
|
|
296
|
+
*/
|
|
297
|
+
async getProcessingStats(directories: string[] = ['src']): Promise<{
|
|
298
|
+
directoryStats: any;
|
|
299
|
+
processorStats: any;
|
|
300
|
+
cacheStats: any;
|
|
301
|
+
}> {
|
|
302
|
+
const directoryStats = await Promise.all(
|
|
303
|
+
directories.map(dir => this.directoryFilter.getDirectoryStats(dir))
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
return {
|
|
307
|
+
directoryStats: directoryStats.reduce((acc, stats) => ({
|
|
308
|
+
totalFiles: acc.totalFiles + stats.totalFiles,
|
|
309
|
+
supportedFiles: acc.supportedFiles + stats.supportedFiles,
|
|
310
|
+
directories: acc.directories + stats.directories,
|
|
311
|
+
excludedDirectories: acc.excludedDirectories + stats.excludedDirectories,
|
|
312
|
+
largestFiles: [...acc.largestFiles, ...stats.largestFiles]
|
|
313
|
+
.sort((a, b) => b.size - a.size)
|
|
314
|
+
.slice(0, 10)
|
|
315
|
+
}), {
|
|
316
|
+
totalFiles: 0,
|
|
317
|
+
supportedFiles: 0,
|
|
318
|
+
directories: 0,
|
|
319
|
+
excludedDirectories: 0,
|
|
320
|
+
largestFiles: []
|
|
321
|
+
}),
|
|
322
|
+
processorStats: this.fileProcessor.getStats(),
|
|
323
|
+
cacheStats: this.cacheManager.getStats()
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Clear all caches
|
|
329
|
+
*/
|
|
330
|
+
clearCache(): void {
|
|
331
|
+
this.cacheManager.clearAll();
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Cleanup resources with error handling
|
|
336
|
+
*/
|
|
337
|
+
async cleanup(): Promise<void> {
|
|
338
|
+
this.categoryLogger.info('Starting BaseGuard cleanup');
|
|
339
|
+
|
|
340
|
+
try {
|
|
341
|
+
// Cleanup file processor
|
|
342
|
+
await SystemErrorHandler.handleGracefully(
|
|
343
|
+
() => this.fileProcessor.cleanup(),
|
|
344
|
+
undefined,
|
|
345
|
+
{ operation: 'file_processor_cleanup' },
|
|
346
|
+
{ logError: false, showWarning: false }
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
// Clear caches
|
|
350
|
+
await SystemErrorHandler.handleGracefully(
|
|
351
|
+
() => this.cacheManager.clearAll(),
|
|
352
|
+
undefined,
|
|
353
|
+
{ operation: 'cache_cleanup' },
|
|
354
|
+
{ logError: false, showWarning: false }
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
// Cleanup graceful degradation manager
|
|
358
|
+
await SystemErrorHandler.handleGracefully(
|
|
359
|
+
() => GracefulDegradationManager.cleanupCache(),
|
|
360
|
+
undefined,
|
|
361
|
+
{ operation: 'degradation_cleanup' },
|
|
362
|
+
{ logError: false, showWarning: false }
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
// Cleanup old logs
|
|
366
|
+
await SystemErrorHandler.handleGracefully(
|
|
367
|
+
() => logger.cleanupOldLogs(),
|
|
368
|
+
undefined,
|
|
369
|
+
{ operation: 'log_cleanup' },
|
|
370
|
+
{ logError: false, showWarning: false }
|
|
371
|
+
);
|
|
372
|
+
|
|
373
|
+
this.categoryLogger.info('BaseGuard cleanup completed');
|
|
374
|
+
|
|
375
|
+
} catch (error) {
|
|
376
|
+
this.categoryLogger.warn('Some cleanup operations failed', { error: error instanceof Error ? error.message : 'Unknown error' });
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Create auto-backup of configuration
|
|
382
|
+
*/
|
|
383
|
+
async createConfigBackup(): Promise<string | null> {
|
|
384
|
+
try {
|
|
385
|
+
return await ConfigurationRecovery.createAutoBackup();
|
|
386
|
+
} catch (error) {
|
|
387
|
+
this.categoryLogger.error('Failed to create config backup', { error });
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Show system status and health
|
|
394
|
+
*/
|
|
395
|
+
async showSystemStatus(): Promise<void> {
|
|
396
|
+
console.log(chalk.cyan('🔍 BaseGuard System Status\n'));
|
|
397
|
+
|
|
398
|
+
const health = await this.getHealthStatus();
|
|
399
|
+
|
|
400
|
+
// Overall status
|
|
401
|
+
const statusIcon = health.overall === 'healthy' ? '✅' : health.overall === 'degraded' ? '⚠️' : '❌';
|
|
402
|
+
const statusColor = health.overall === 'healthy' ? chalk.green : health.overall === 'degraded' ? chalk.yellow : chalk.red;
|
|
403
|
+
|
|
404
|
+
console.log(statusColor(`${statusIcon} Overall Status: ${health.overall.toUpperCase()}`));
|
|
405
|
+
console.log(chalk.dim(`Degradation Mode: ${health.degradationMode}\n`));
|
|
406
|
+
|
|
407
|
+
// Component status
|
|
408
|
+
console.log(chalk.cyan('📊 Component Status:'));
|
|
409
|
+
for (const [component, status] of Object.entries(health.components)) {
|
|
410
|
+
const componentIcon = status.status === 'healthy' ? '✅' : status.status === 'degraded' ? '⚠️' : '❌';
|
|
411
|
+
console.log(` ${componentIcon} ${component}: ${status.status}`);
|
|
412
|
+
|
|
413
|
+
if (status.details && status.status !== 'healthy') {
|
|
414
|
+
if (status.details.errors?.length > 0) {
|
|
415
|
+
console.log(chalk.dim(` Errors: ${status.details.errors.slice(0, 2).join(', ')}`));
|
|
416
|
+
}
|
|
417
|
+
if (status.details.error) {
|
|
418
|
+
console.log(chalk.dim(` Error: ${status.details.error}`));
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// Recommendations
|
|
424
|
+
if (health.recommendations.length > 0) {
|
|
425
|
+
console.log(chalk.cyan('\n💡 Recommendations:'));
|
|
426
|
+
health.recommendations.forEach(rec => {
|
|
427
|
+
console.log(chalk.cyan(` • ${rec}`));
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// Show degradation status
|
|
432
|
+
GracefulDegradationManager.showStatus();
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Analyze violations using AI with graceful degradation
|
|
437
|
+
*/
|
|
438
|
+
async analyzeViolations(violations: Violation[]): Promise<Analysis[]> {
|
|
439
|
+
await this.ensureInitialized();
|
|
440
|
+
|
|
441
|
+
const sessionId = logger.startSession('analyze-violations');
|
|
442
|
+
this.categoryLogger.startPerformance('analyze-violations');
|
|
443
|
+
|
|
444
|
+
try {
|
|
445
|
+
const analyses: Analysis[] = [];
|
|
446
|
+
const mode = GracefulDegradationManager.getCurrentMode();
|
|
447
|
+
|
|
448
|
+
if (!mode?.capabilities.aiAnalysis) {
|
|
449
|
+
this.categoryLogger.info('AI analysis disabled in current mode, using fallback analysis');
|
|
450
|
+
|
|
451
|
+
// Create fallback analyses for all violations
|
|
452
|
+
for (const violation of violations) {
|
|
453
|
+
const fallbackAnalysis = GracefulDegradationManager.createFallbackAnalysis(
|
|
454
|
+
violation,
|
|
455
|
+
'AI analysis unavailable in current mode'
|
|
456
|
+
);
|
|
457
|
+
analyses.push(fallbackAnalysis);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
return analyses;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// Try to use cached analyses first
|
|
464
|
+
for (const violation of violations) {
|
|
465
|
+
const cached = await GracefulDegradationManager.loadCachedAnalysis(violation);
|
|
466
|
+
if (cached) {
|
|
467
|
+
analyses.push(cached);
|
|
468
|
+
} else {
|
|
469
|
+
// Will need AI analysis
|
|
470
|
+
const fallbackAnalysis = GracefulDegradationManager.createFallbackAnalysis(
|
|
471
|
+
violation,
|
|
472
|
+
'AI analysis not yet implemented'
|
|
473
|
+
);
|
|
474
|
+
analyses.push(fallbackAnalysis);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
const duration = this.categoryLogger.endPerformance('analyze-violations', {
|
|
479
|
+
violationCount: violations.length,
|
|
480
|
+
analysesCreated: analyses.length
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
this.categoryLogger.info('Violation analysis completed', {
|
|
484
|
+
duration,
|
|
485
|
+
violationCount: violations.length,
|
|
486
|
+
analysesCreated: analyses.length
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
return analyses;
|
|
490
|
+
|
|
491
|
+
} catch (error) {
|
|
492
|
+
this.categoryLogger.error('Violation analysis failed', { error });
|
|
493
|
+
|
|
494
|
+
// Fallback to basic analysis
|
|
495
|
+
const fallbackAnalyses = violations.map(violation =>
|
|
496
|
+
GracefulDegradationManager.createFallbackAnalysis(violation, 'Analysis failed, using fallback')
|
|
497
|
+
);
|
|
498
|
+
|
|
499
|
+
return fallbackAnalyses;
|
|
500
|
+
} finally {
|
|
501
|
+
await logger.endSession();
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Generate fixes for violations with graceful degradation
|
|
507
|
+
*/
|
|
508
|
+
async generateFixes(violations: Violation[], analyses: Analysis[]): Promise<Fix[]> {
|
|
509
|
+
await this.ensureInitialized();
|
|
510
|
+
|
|
511
|
+
const sessionId = logger.startSession('generate-fixes');
|
|
512
|
+
this.categoryLogger.startPerformance('generate-fixes');
|
|
513
|
+
|
|
514
|
+
try {
|
|
515
|
+
const fixes: Fix[] = [];
|
|
516
|
+
const mode = GracefulDegradationManager.getCurrentMode();
|
|
517
|
+
|
|
518
|
+
if (!mode?.capabilities.autoFix) {
|
|
519
|
+
this.categoryLogger.info('Auto-fix disabled in current mode, creating manual fix suggestions');
|
|
520
|
+
|
|
521
|
+
// Create manual fix suggestions
|
|
522
|
+
for (let i = 0; i < violations.length; i++) {
|
|
523
|
+
const violation = violations[i];
|
|
524
|
+
const analysis = analyses[i];
|
|
525
|
+
|
|
526
|
+
if (violation && analysis) {
|
|
527
|
+
const manualFix = GracefulDegradationManager.createBasicFixSuggestion(violation, analysis);
|
|
528
|
+
fixes.push(manualFix);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
return fixes;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// Auto-fix would be implemented here when available
|
|
536
|
+
this.categoryLogger.info('Auto-fix not yet implemented, creating manual suggestions');
|
|
537
|
+
|
|
538
|
+
for (let i = 0; i < violations.length; i++) {
|
|
539
|
+
const violation = violations[i];
|
|
540
|
+
const analysis = analyses[i];
|
|
541
|
+
|
|
542
|
+
if (violation && analysis) {
|
|
543
|
+
const manualFix = GracefulDegradationManager.createBasicFixSuggestion(violation, analysis);
|
|
544
|
+
fixes.push(manualFix);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
const duration = this.categoryLogger.endPerformance('generate-fixes', {
|
|
549
|
+
violationCount: violations.length,
|
|
550
|
+
fixesGenerated: fixes.length
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
this.categoryLogger.info('Fix generation completed', {
|
|
554
|
+
duration,
|
|
555
|
+
violationCount: violations.length,
|
|
556
|
+
fixesGenerated: fixes.length
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
return fixes;
|
|
560
|
+
|
|
561
|
+
} catch (error) {
|
|
562
|
+
this.categoryLogger.error('Fix generation failed', { error });
|
|
563
|
+
throw error;
|
|
564
|
+
} finally {
|
|
565
|
+
await logger.endSession();
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Apply fixes to files with error recovery
|
|
571
|
+
*/
|
|
572
|
+
async applyFixes(fixes: Fix[]): Promise<void> {
|
|
573
|
+
await this.ensureInitialized();
|
|
574
|
+
|
|
575
|
+
const sessionId = logger.startSession('apply-fixes');
|
|
576
|
+
this.categoryLogger.startPerformance('apply-fixes');
|
|
577
|
+
|
|
578
|
+
try {
|
|
579
|
+
this.categoryLogger.info(`Applying ${fixes.length} fixes`);
|
|
580
|
+
|
|
581
|
+
let appliedCount = 0;
|
|
582
|
+
let failedCount = 0;
|
|
583
|
+
|
|
584
|
+
for (const fix of fixes) {
|
|
585
|
+
try {
|
|
586
|
+
await SystemErrorHandler.withRetry(
|
|
587
|
+
async () => {
|
|
588
|
+
// Fix application would be implemented here
|
|
589
|
+
this.categoryLogger.debug('Fix application not yet implemented', {
|
|
590
|
+
file: fix.filePath,
|
|
591
|
+
feature: fix.violation.feature
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
// For now, just log the fix that would be applied
|
|
595
|
+
console.log(chalk.cyan(`Would apply fix for ${fix.violation.feature} in ${fix.filePath}`));
|
|
596
|
+
},
|
|
597
|
+
{
|
|
598
|
+
operation: 'apply_fix',
|
|
599
|
+
file: fix.filePath,
|
|
600
|
+
details: { feature: fix.violation.feature }
|
|
601
|
+
},
|
|
602
|
+
2 // max retries
|
|
603
|
+
);
|
|
604
|
+
|
|
605
|
+
appliedCount++;
|
|
606
|
+
} catch (error) {
|
|
607
|
+
failedCount++;
|
|
608
|
+
this.categoryLogger.error('Failed to apply fix', {
|
|
609
|
+
file: fix.filePath,
|
|
610
|
+
feature: fix.violation.feature,
|
|
611
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
const duration = this.categoryLogger.endPerformance('apply-fixes', {
|
|
617
|
+
totalFixes: fixes.length,
|
|
618
|
+
appliedCount,
|
|
619
|
+
failedCount
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
this.categoryLogger.info('Fix application completed', {
|
|
623
|
+
duration,
|
|
624
|
+
totalFixes: fixes.length,
|
|
625
|
+
appliedCount,
|
|
626
|
+
failedCount
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
if (failedCount > 0) {
|
|
630
|
+
console.log(chalk.yellow(`⚠️ ${failedCount} fixes failed to apply. Check logs for details.`));
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
} catch (error) {
|
|
634
|
+
this.categoryLogger.error('Fix application process failed', { error });
|
|
635
|
+
throw error;
|
|
636
|
+
} finally {
|
|
637
|
+
await logger.endSession();
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Recover from configuration corruption
|
|
643
|
+
*/
|
|
644
|
+
async recoverConfiguration(): Promise<Configuration> {
|
|
645
|
+
this.categoryLogger.info('Attempting configuration recovery');
|
|
646
|
+
|
|
647
|
+
const recoveryResult = await ConfigurationRecovery.recoverConfiguration({
|
|
648
|
+
createBackup: true,
|
|
649
|
+
validateConfig: true,
|
|
650
|
+
migrateVersion: true,
|
|
651
|
+
repairCorruption: true,
|
|
652
|
+
useDefaults: true
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
if (recoveryResult.success && recoveryResult.config) {
|
|
656
|
+
this.config = recoveryResult.config;
|
|
657
|
+
this.categoryLogger.info('Configuration recovered successfully');
|
|
658
|
+
|
|
659
|
+
if (recoveryResult.warnings.length > 0) {
|
|
660
|
+
this.categoryLogger.warn('Configuration recovery warnings', { warnings: recoveryResult.warnings });
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
return this.config;
|
|
664
|
+
} else {
|
|
665
|
+
const error = new Error(`Configuration recovery failed: ${recoveryResult.errors.join(', ')}`);
|
|
666
|
+
this.categoryLogger.error('Configuration recovery failed', { errors: recoveryResult.errors });
|
|
667
|
+
throw error;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Get system health status
|
|
673
|
+
*/
|
|
674
|
+
async getHealthStatus(): Promise<{
|
|
675
|
+
overall: 'healthy' | 'degraded' | 'critical';
|
|
676
|
+
components: Record<string, { status: string; details?: any }>;
|
|
677
|
+
degradationMode: string;
|
|
678
|
+
recommendations: string[];
|
|
679
|
+
}> {
|
|
680
|
+
const health = {
|
|
681
|
+
overall: 'healthy' as 'healthy' | 'degraded' | 'critical',
|
|
682
|
+
components: {} as Record<string, { status: string; details?: any }>,
|
|
683
|
+
degradationMode: 'unknown',
|
|
684
|
+
recommendations: [] as string[]
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
try {
|
|
688
|
+
// Check configuration health
|
|
689
|
+
const configIntegrity = await ConfigurationRecovery.validateIntegrity();
|
|
690
|
+
health.components.configuration = {
|
|
691
|
+
status: configIntegrity.valid ? 'healthy' : 'degraded',
|
|
692
|
+
details: { errors: configIntegrity.errors, suggestions: configIntegrity.suggestions }
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
// Check degradation mode
|
|
696
|
+
const mode = GracefulDegradationManager.getCurrentMode();
|
|
697
|
+
health.degradationMode = mode?.name || 'unknown';
|
|
698
|
+
|
|
699
|
+
if (mode?.name !== 'Full Functionality') {
|
|
700
|
+
health.overall = 'degraded';
|
|
701
|
+
health.recommendations.push(`Currently in ${mode?.name} mode`);
|
|
702
|
+
health.recommendations.push(...(mode?.limitations || []));
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// Check service status
|
|
706
|
+
const serviceStatus = GracefulDegradationManager.getServiceStatus();
|
|
707
|
+
for (const [service, status] of serviceStatus) {
|
|
708
|
+
health.components[service] = {
|
|
709
|
+
status: status.available ? 'healthy' : 'degraded',
|
|
710
|
+
details: { lastCheck: status.lastCheck, error: status.error }
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
if (!status.available) {
|
|
714
|
+
health.overall = 'degraded';
|
|
715
|
+
health.recommendations.push(`${service} service is unavailable`);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
// Check error summary
|
|
720
|
+
const errorSummary = logger.getErrorSummary();
|
|
721
|
+
health.components.errors = {
|
|
722
|
+
status: errorSummary.totalErrors > 10 ? 'critical' : errorSummary.totalErrors > 0 ? 'degraded' : 'healthy',
|
|
723
|
+
details: errorSummary
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
if (errorSummary.totalErrors > 10) {
|
|
727
|
+
health.overall = 'critical';
|
|
728
|
+
health.recommendations.push('High error count detected - check logs');
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
} catch (error) {
|
|
732
|
+
health.overall = 'critical';
|
|
733
|
+
health.components.healthCheck = {
|
|
734
|
+
status: 'failed',
|
|
735
|
+
details: { error: error instanceof Error ? error.message : 'Unknown error' }
|
|
736
|
+
};
|
|
737
|
+
health.recommendations.push('Health check failed - system may be unstable');
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
return health;
|
|
741
|
+
}
|
|
742
|
+
}
|