|
5 | 5 | import { Command } from 'commander'; |
6 | 6 | import chalk from 'chalk'; |
7 | 7 | import os from 'os'; |
8 | | -import { HealthCheck, ItemWiseHealthCheck, HealthCheckResult } from './types.js'; |
| 8 | +import { HealthCheckResult } from './types.js'; |
9 | 9 | import { HealthCheckFormatter } from './formatter.js'; |
10 | 10 | import { |
11 | 11 | NodeVersionCheck, |
@@ -79,120 +79,112 @@ export function createDoctorCommand(): Command { |
79 | 79 | // Display header |
80 | 80 | formatter.displayHeader(); |
81 | 81 |
|
82 | | - // Define standard health checks |
83 | | - const checks: HealthCheck[] = [ |
84 | | - new NodeVersionCheck(), |
85 | | - new NpmCheck(), |
86 | | - new PythonCheck(), |
87 | | - new UvCheck(), |
88 | | - new AwsCliCheck(), |
89 | | - new AIConfigCheck(), |
90 | | - new AgentsCheck(), |
91 | | - new WorkflowsCheck(), |
92 | | - new FrameworksCheck() |
93 | | - ]; |
94 | | - |
95 | | - // Run and display standard checks immediately |
96 | | - for (const check of checks) { |
97 | | - logger.debug(`=== Running Check: ${check.name} ===`); |
98 | | - const startTime = Date.now(); |
99 | | - |
100 | | - // Check if this is an ItemWiseHealthCheck |
101 | | - const isItemWise = 'runWithItemDisplay' in check; |
102 | | - |
103 | | - if (isItemWise) { |
104 | | - // Display section header |
105 | | - console.log(formatter['getCheckHeader'](check.name)); |
106 | | - |
107 | | - // Run with item-by-item display |
108 | | - const result = await (check as ItemWiseHealthCheck).runWithItemDisplay( |
109 | | - (itemName) => { |
110 | | - logger.debug(` Checking item: ${itemName}`); |
111 | | - formatter.startItem(itemName); |
112 | | - }, |
113 | | - (detail) => { |
114 | | - logger.debug(` Result: ${detail.status} - ${detail.message}`); |
115 | | - formatter.displayItem(detail); |
116 | | - } |
117 | | - ); |
118 | | - results.push(result); |
119 | | - |
120 | | - const elapsed = Date.now() - startTime; |
121 | | - logger.debug(`Check completed in ${elapsed}ms: ${result.success ? 'SUCCESS' : 'FAILED'}`); |
122 | | - logger.debug(''); |
123 | | - |
124 | | - // Add blank line after section |
125 | | - console.log(); |
126 | | - } else { |
127 | | - // Regular check with section-level progress |
128 | | - formatter.startCheck(check.name); |
129 | | - const result = await check.run((message) => { |
130 | | - logger.debug(` Progress: ${message}`); |
131 | | - formatter.updateProgress(message); |
| 82 | + // Helper to display a pre-computed check result |
| 83 | + const displayResult = (result: HealthCheckResult): void => { |
| 84 | + formatter.displayCheck(result); |
| 85 | + if (result.details && result.details.length > 0) { |
| 86 | + result.details.forEach(detail => { |
| 87 | + logger.debug(` - ${detail.status}: ${detail.message}`); |
132 | 88 | }); |
133 | | - results.push(result); |
134 | | - formatter.displayCheck(result); |
135 | | - |
136 | | - const elapsed = Date.now() - startTime; |
137 | | - logger.debug(`Check completed in ${elapsed}ms: ${result.success ? 'SUCCESS' : 'FAILED'}`); |
138 | | - if (result.details && result.details.length > 0) { |
139 | | - result.details.forEach(detail => { |
140 | | - logger.debug(` - ${detail.status}: ${detail.message}`); |
141 | | - }); |
142 | | - } |
143 | | - logger.debug(''); |
144 | 89 | } |
| 90 | + logger.debug(''); |
| 91 | + }; |
| 92 | + |
| 93 | + // --- Group 1: Independent tool checks (run in parallel) --- |
| 94 | + const nodeCheck = new NodeVersionCheck(); |
| 95 | + const npmCheck = new NpmCheck(); |
| 96 | + const pythonCheck = new PythonCheck(); |
| 97 | + const uvCheck = new UvCheck(); |
| 98 | + const awsCheck = new AwsCliCheck(); |
| 99 | + |
| 100 | + logger.debug('=== Running Tool Checks (parallel) ==='); |
| 101 | + const toolStartTime = Date.now(); |
| 102 | + const [nodeResult, npmResult, pythonResult, uvResult, awsResult] = await Promise.all([ |
| 103 | + nodeCheck.run(), |
| 104 | + npmCheck.run(), |
| 105 | + pythonCheck.run(), |
| 106 | + uvCheck.run(), |
| 107 | + awsCheck.run() |
| 108 | + ]); |
| 109 | + logger.debug(`Tool checks completed in ${Date.now() - toolStartTime}ms`); |
| 110 | + |
| 111 | + // Display tool check results sequentially |
| 112 | + for (const result of [nodeResult, npmResult, pythonResult, uvResult, awsResult]) { |
| 113 | + results.push(result); |
| 114 | + displayResult(result); |
| 115 | + } |
145 | 116 |
|
146 | | - // After AIConfigCheck, immediately run provider-specific checks |
147 | | - if (check instanceof AIConfigCheck) { |
148 | | - const config = check.getConfig(); |
149 | | - |
150 | | - if (config && config.provider) { |
151 | | - logger.debug(`=== Running Provider Check: ${config.provider} ===`); |
152 | | - logger.debug(`Base URL: ${config.baseUrl}`); |
153 | | - logger.debug(`Model: ${config.model}`); |
154 | | - |
155 | | - // Get health check from ProviderRegistry |
156 | | - const healthCheck = ProviderRegistry.getHealthCheck(config.provider); |
157 | | - |
158 | | - if (healthCheck) { |
159 | | - formatter.startCheck('Provider'); |
160 | | - |
161 | | - try { |
162 | | - const providerStartTime = Date.now(); |
163 | | - const providerResult = await healthCheck.check(config); |
164 | | - const elapsed = Date.now() - providerStartTime; |
165 | | - |
166 | | - logger.debug(`Provider check completed in ${elapsed}ms`); |
167 | | - logger.debug(`Status: ${providerResult.status}`); |
168 | | - |
169 | | - const doctorResult = adaptProviderResult(providerResult); |
170 | | - results.push(doctorResult); |
171 | | - formatter.displayCheckWithHeader(doctorResult); |
172 | | - } catch (error) { |
173 | | - const errorMessage = error instanceof Error ? error.message : String(error); |
174 | | - logger.error(`Provider check failed: ${errorMessage}`); |
175 | | - if (error instanceof Error && error.stack) { |
176 | | - logger.debug(`Stack trace: ${error.stack}`); |
177 | | - } |
178 | | - |
179 | | - // If check throws, capture error |
180 | | - results.push({ |
181 | | - name: 'Provider Check Error', |
182 | | - success: false, |
183 | | - details: [{ |
184 | | - status: 'error', |
185 | | - message: `Check failed: ${errorMessage}` |
186 | | - }] |
187 | | - }); |
188 | | - } |
189 | | - } else { |
190 | | - logger.debug(`No health check available for provider: ${config.provider}`); |
| 117 | + // --- Group 2: AI Config + Provider check (sequential, provider depends on config) --- |
| 118 | + const aiConfigCheck = new AIConfigCheck(); |
| 119 | + logger.debug('=== Running Check: Active Profile ==='); |
| 120 | + const configStartTime = Date.now(); |
| 121 | + const configResult = await aiConfigCheck.run(); |
| 122 | + logger.debug(`Check completed in ${Date.now() - configStartTime}ms`); |
| 123 | + results.push(configResult); |
| 124 | + displayResult(configResult); |
| 125 | + |
| 126 | + // Run provider-specific checks if config is available |
| 127 | + const config = aiConfigCheck.getConfig(); |
| 128 | + if (config && config.provider) { |
| 129 | + logger.debug(`=== Running Provider Check: ${config.provider} ===`); |
| 130 | + logger.debug(`Base URL: ${config.baseUrl}`); |
| 131 | + logger.debug(`Model: ${config.model}`); |
| 132 | + |
| 133 | + const healthCheck = ProviderRegistry.getHealthCheck(config.provider); |
| 134 | + |
| 135 | + if (healthCheck) { |
| 136 | + formatter.startCheck('Provider'); |
| 137 | + |
| 138 | + try { |
| 139 | + const providerStartTime = Date.now(); |
| 140 | + const providerResult = await healthCheck.check(config); |
| 141 | + logger.debug(`Provider check completed in ${Date.now() - providerStartTime}ms`); |
| 142 | + logger.debug(`Status: ${providerResult.status}`); |
| 143 | + |
| 144 | + const doctorResult = adaptProviderResult(providerResult); |
| 145 | + results.push(doctorResult); |
| 146 | + formatter.displayCheckWithHeader(doctorResult); |
| 147 | + } catch (error) { |
| 148 | + const errorMessage = error instanceof Error ? error.message : String(error); |
| 149 | + logger.error(`Provider check failed: ${errorMessage}`); |
| 150 | + if (error instanceof Error && error.stack) { |
| 151 | + logger.debug(`Stack trace: ${error.stack}`); |
191 | 152 | } |
| 153 | + |
| 154 | + results.push({ |
| 155 | + name: 'Provider Check Error', |
| 156 | + success: false, |
| 157 | + details: [{ |
| 158 | + status: 'error', |
| 159 | + message: `Check failed: ${errorMessage}` |
| 160 | + }] |
| 161 | + }); |
192 | 162 | } |
| 163 | + } else { |
| 164 | + logger.debug(`No health check available for provider: ${config.provider}`); |
193 | 165 | } |
194 | 166 | } |
195 | 167 |
|
| 168 | + // --- Group 3: Discovery checks (run in parallel) --- |
| 169 | + const agentsCheck = new AgentsCheck(); |
| 170 | + const workflowsCheck = new WorkflowsCheck(); |
| 171 | + const frameworksCheck = new FrameworksCheck(); |
| 172 | + |
| 173 | + logger.debug('=== Running Discovery Checks (parallel) ==='); |
| 174 | + const discoveryStartTime = Date.now(); |
| 175 | + const [agentsResult, workflowsResult, frameworksResult] = await Promise.all([ |
| 176 | + agentsCheck.run(), |
| 177 | + workflowsCheck.run(), |
| 178 | + frameworksCheck.run() |
| 179 | + ]); |
| 180 | + logger.debug(`Discovery checks completed in ${Date.now() - discoveryStartTime}ms`); |
| 181 | + |
| 182 | + // Display discovery check results sequentially |
| 183 | + for (const result of [agentsResult, workflowsResult, frameworksResult]) { |
| 184 | + results.push(result); |
| 185 | + displayResult(result); |
| 186 | + } |
| 187 | + |
196 | 188 | logger.debug('=== All Checks Completed ==='); |
197 | 189 | const successCount = results.filter(r => r.success).length; |
198 | 190 | logger.debug(`Passed: ${successCount}/${results.length}`); |
|
0 commit comments