@vibecheckai/cli 3.0.2 → 3.0.3
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/package.json +9 -1
- package/bin/cli-hygiene.js +0 -241
- package/bin/guardrail.js +0 -834
- package/bin/runners/cli-utils.js +0 -1070
- package/bin/runners/context/ai-task-decomposer.js +0 -337
- package/bin/runners/context/analyzer.js +0 -462
- package/bin/runners/context/api-contracts.js +0 -427
- package/bin/runners/context/context-diff.js +0 -342
- package/bin/runners/context/context-pruner.js +0 -291
- package/bin/runners/context/dependency-graph.js +0 -414
- package/bin/runners/context/generators/claude.js +0 -107
- package/bin/runners/context/generators/codex.js +0 -108
- package/bin/runners/context/generators/copilot.js +0 -119
- package/bin/runners/context/generators/cursor.js +0 -514
- package/bin/runners/context/generators/mcp.js +0 -151
- package/bin/runners/context/generators/windsurf.js +0 -180
- package/bin/runners/context/git-context.js +0 -302
- package/bin/runners/context/index.js +0 -1042
- package/bin/runners/context/insights.js +0 -173
- package/bin/runners/context/mcp-server/generate-rules.js +0 -337
- package/bin/runners/context/mcp-server/index.js +0 -1176
- package/bin/runners/context/mcp-server/package.json +0 -24
- package/bin/runners/context/memory.js +0 -200
- package/bin/runners/context/monorepo.js +0 -215
- package/bin/runners/context/multi-repo-federation.js +0 -404
- package/bin/runners/context/patterns.js +0 -253
- package/bin/runners/context/proof-context.js +0 -972
- package/bin/runners/context/security-scanner.js +0 -303
- package/bin/runners/context/semantic-search.js +0 -350
- package/bin/runners/context/shared.js +0 -264
- package/bin/runners/context/team-conventions.js +0 -310
- package/bin/runners/lib/ai-bridge.js +0 -416
- package/bin/runners/lib/analysis-core.js +0 -271
- package/bin/runners/lib/analyzers.js +0 -541
- package/bin/runners/lib/audit-bridge.js +0 -391
- package/bin/runners/lib/auth-truth.js +0 -193
- package/bin/runners/lib/auth.js +0 -215
- package/bin/runners/lib/backup.js +0 -62
- package/bin/runners/lib/billing.js +0 -107
- package/bin/runners/lib/claims.js +0 -118
- package/bin/runners/lib/cli-ui.js +0 -540
- package/bin/runners/lib/compliance-bridge-new.js +0 -0
- package/bin/runners/lib/compliance-bridge.js +0 -165
- package/bin/runners/lib/contracts/auth-contract.js +0 -194
- package/bin/runners/lib/contracts/env-contract.js +0 -178
- package/bin/runners/lib/contracts/external-contract.js +0 -198
- package/bin/runners/lib/contracts/guard.js +0 -168
- package/bin/runners/lib/contracts/index.js +0 -89
- package/bin/runners/lib/contracts/plan-validator.js +0 -311
- package/bin/runners/lib/contracts/route-contract.js +0 -192
- package/bin/runners/lib/detect.js +0 -89
- package/bin/runners/lib/doctor/autofix.js +0 -254
- package/bin/runners/lib/doctor/index.js +0 -37
- package/bin/runners/lib/doctor/modules/dependencies.js +0 -325
- package/bin/runners/lib/doctor/modules/index.js +0 -46
- package/bin/runners/lib/doctor/modules/network.js +0 -250
- package/bin/runners/lib/doctor/modules/project.js +0 -312
- package/bin/runners/lib/doctor/modules/runtime.js +0 -224
- package/bin/runners/lib/doctor/modules/security.js +0 -348
- package/bin/runners/lib/doctor/modules/system.js +0 -213
- package/bin/runners/lib/doctor/modules/vibecheck.js +0 -394
- package/bin/runners/lib/doctor/reporter.js +0 -262
- package/bin/runners/lib/doctor/service.js +0 -262
- package/bin/runners/lib/doctor/types.js +0 -113
- package/bin/runners/lib/doctor/ui.js +0 -263
- package/bin/runners/lib/doctor-enhanced.js +0 -233
- package/bin/runners/lib/doctor-v2.js +0 -608
- package/bin/runners/lib/enforcement.js +0 -72
|
@@ -1,394 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Vibecheck Diagnostics Module
|
|
3
|
-
*
|
|
4
|
-
* Checks vibecheck-specific configuration, truth packs, and scan readiness
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
const path = require('path');
|
|
9
|
-
const { execSync } = require('child_process');
|
|
10
|
-
const { SEVERITY, CATEGORY, FIX_TYPE } = require('../types');
|
|
11
|
-
|
|
12
|
-
const MODULE_ID = 'vibecheck';
|
|
13
|
-
|
|
14
|
-
const CONFIG_FILES = [
|
|
15
|
-
'.vibecheckrc',
|
|
16
|
-
'.vibecheck.json',
|
|
17
|
-
'vibecheck.config.js',
|
|
18
|
-
'vibecheck.config.mjs',
|
|
19
|
-
];
|
|
20
|
-
|
|
21
|
-
function createDiagnostics(projectPath) {
|
|
22
|
-
return [
|
|
23
|
-
{
|
|
24
|
-
id: `${MODULE_ID}.config`,
|
|
25
|
-
name: 'Configuration File',
|
|
26
|
-
category: CATEGORY.VIBECHECK,
|
|
27
|
-
parallel: true,
|
|
28
|
-
check: async () => {
|
|
29
|
-
for (const configFile of CONFIG_FILES) {
|
|
30
|
-
const configPath = path.join(projectPath, configFile);
|
|
31
|
-
if (fs.existsSync(configPath)) {
|
|
32
|
-
try {
|
|
33
|
-
if (configFile.endsWith('.json') || configFile === '.vibecheckrc') {
|
|
34
|
-
JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
severity: SEVERITY.PASS,
|
|
38
|
-
message: configFile,
|
|
39
|
-
metadata: { configFile },
|
|
40
|
-
};
|
|
41
|
-
} catch (err) {
|
|
42
|
-
return {
|
|
43
|
-
severity: SEVERITY.WARNING,
|
|
44
|
-
message: `Invalid ${configFile}`,
|
|
45
|
-
detail: err.message,
|
|
46
|
-
fixes: [{
|
|
47
|
-
type: FIX_TYPE.MANUAL,
|
|
48
|
-
description: 'Fix configuration file syntax',
|
|
49
|
-
autoFixable: false,
|
|
50
|
-
}],
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
severity: SEVERITY.INFO,
|
|
58
|
-
message: 'Using defaults',
|
|
59
|
-
detail: 'Run `vibecheck init` to create a config file',
|
|
60
|
-
fixes: [{
|
|
61
|
-
type: FIX_TYPE.COMMAND,
|
|
62
|
-
description: 'Initialize vibecheck configuration',
|
|
63
|
-
command: 'vibecheck init',
|
|
64
|
-
autoFixable: true,
|
|
65
|
-
}],
|
|
66
|
-
};
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
id: `${MODULE_ID}.output_dir`,
|
|
71
|
-
name: 'Output Directory',
|
|
72
|
-
category: CATEGORY.VIBECHECK,
|
|
73
|
-
parallel: true,
|
|
74
|
-
check: async () => {
|
|
75
|
-
const outputDir = path.join(projectPath, '.vibecheck');
|
|
76
|
-
|
|
77
|
-
if (!fs.existsSync(outputDir)) {
|
|
78
|
-
return {
|
|
79
|
-
severity: SEVERITY.INFO,
|
|
80
|
-
message: 'Will be created on first scan',
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
try {
|
|
85
|
-
const files = fs.readdirSync(outputDir);
|
|
86
|
-
const subdirs = files.filter(f =>
|
|
87
|
-
fs.statSync(path.join(outputDir, f)).isDirectory()
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
const metadata = {
|
|
91
|
-
fileCount: files.length,
|
|
92
|
-
subdirs,
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
severity: SEVERITY.PASS,
|
|
97
|
-
message: `${files.length} items`,
|
|
98
|
-
metadata,
|
|
99
|
-
};
|
|
100
|
-
} catch (err) {
|
|
101
|
-
return {
|
|
102
|
-
severity: SEVERITY.WARNING,
|
|
103
|
-
message: 'Cannot read .vibecheck directory',
|
|
104
|
-
detail: err.message,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
id: `${MODULE_ID}.truthpack`,
|
|
111
|
-
name: 'Truth Pack',
|
|
112
|
-
category: CATEGORY.VIBECHECK,
|
|
113
|
-
parallel: true,
|
|
114
|
-
check: async () => {
|
|
115
|
-
const truthpackPath = path.join(projectPath, '.vibecheck', 'truth', 'truthpack.json');
|
|
116
|
-
|
|
117
|
-
if (!fs.existsSync(truthpackPath)) {
|
|
118
|
-
return {
|
|
119
|
-
severity: SEVERITY.INFO,
|
|
120
|
-
message: 'Not generated yet',
|
|
121
|
-
detail: 'Run `vibecheck ctx` to generate truth pack',
|
|
122
|
-
fixes: [{
|
|
123
|
-
type: FIX_TYPE.COMMAND,
|
|
124
|
-
description: 'Generate truth pack',
|
|
125
|
-
command: 'vibecheck ctx',
|
|
126
|
-
autoFixable: true,
|
|
127
|
-
}],
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
const truthpack = JSON.parse(fs.readFileSync(truthpackPath, 'utf8'));
|
|
133
|
-
const stats = fs.statSync(truthpackPath);
|
|
134
|
-
const ageMs = Date.now() - stats.mtimeMs;
|
|
135
|
-
const ageHours = Math.round(ageMs / 1000 / 60 / 60);
|
|
136
|
-
|
|
137
|
-
const metadata = {
|
|
138
|
-
version: truthpack.version,
|
|
139
|
-
routes: truthpack.routes?.server?.length || 0,
|
|
140
|
-
envVars: truthpack.env?.vars?.length || 0,
|
|
141
|
-
ageHours,
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
if (ageHours > 24) {
|
|
145
|
-
return {
|
|
146
|
-
severity: SEVERITY.WARNING,
|
|
147
|
-
message: `Stale (${ageHours}h old)`,
|
|
148
|
-
detail: 'Truth pack may be outdated',
|
|
149
|
-
metadata,
|
|
150
|
-
fixes: [{
|
|
151
|
-
type: FIX_TYPE.COMMAND,
|
|
152
|
-
description: 'Refresh truth pack',
|
|
153
|
-
command: 'vibecheck ctx',
|
|
154
|
-
autoFixable: true,
|
|
155
|
-
}],
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return {
|
|
160
|
-
severity: SEVERITY.PASS,
|
|
161
|
-
message: `${metadata.routes} routes, ${metadata.envVars} env vars`,
|
|
162
|
-
metadata,
|
|
163
|
-
};
|
|
164
|
-
} catch (err) {
|
|
165
|
-
return {
|
|
166
|
-
severity: SEVERITY.WARNING,
|
|
167
|
-
message: 'Invalid truth pack',
|
|
168
|
-
detail: err.message,
|
|
169
|
-
fixes: [{
|
|
170
|
-
type: FIX_TYPE.COMMAND,
|
|
171
|
-
description: 'Regenerate truth pack',
|
|
172
|
-
command: 'vibecheck ctx',
|
|
173
|
-
autoFixable: true,
|
|
174
|
-
}],
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
id: `${MODULE_ID}.last_scan`,
|
|
181
|
-
name: 'Last Scan',
|
|
182
|
-
category: CATEGORY.VIBECHECK,
|
|
183
|
-
parallel: true,
|
|
184
|
-
check: async () => {
|
|
185
|
-
const scanResultPath = path.join(projectPath, '.vibecheck', 'ship', 'last_ship.json');
|
|
186
|
-
|
|
187
|
-
if (!fs.existsSync(scanResultPath)) {
|
|
188
|
-
return {
|
|
189
|
-
severity: SEVERITY.INFO,
|
|
190
|
-
message: 'No scans yet',
|
|
191
|
-
detail: 'Run `vibecheck ship` for first scan',
|
|
192
|
-
fixes: [{
|
|
193
|
-
type: FIX_TYPE.COMMAND,
|
|
194
|
-
description: 'Run first scan',
|
|
195
|
-
command: 'vibecheck ship',
|
|
196
|
-
autoFixable: false,
|
|
197
|
-
}],
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
try {
|
|
202
|
-
const result = JSON.parse(fs.readFileSync(scanResultPath, 'utf8'));
|
|
203
|
-
const stats = fs.statSync(scanResultPath);
|
|
204
|
-
const ageMs = Date.now() - stats.mtimeMs;
|
|
205
|
-
const ageMinutes = Math.round(ageMs / 1000 / 60);
|
|
206
|
-
|
|
207
|
-
const verdict = result.verdict || result.summary?.verdict || 'unknown';
|
|
208
|
-
const metadata = {
|
|
209
|
-
verdict,
|
|
210
|
-
ageMinutes,
|
|
211
|
-
findings: result.findings?.length || 0,
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
const verdictColors = {
|
|
215
|
-
SHIP: SEVERITY.PASS,
|
|
216
|
-
WARN: SEVERITY.WARNING,
|
|
217
|
-
BLOCK: SEVERITY.ERROR,
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
return {
|
|
221
|
-
severity: verdictColors[verdict] || SEVERITY.INFO,
|
|
222
|
-
message: `${verdict} (${ageMinutes}m ago)`,
|
|
223
|
-
metadata,
|
|
224
|
-
};
|
|
225
|
-
} catch (err) {
|
|
226
|
-
return {
|
|
227
|
-
severity: SEVERITY.INFO,
|
|
228
|
-
message: 'Could not read last scan',
|
|
229
|
-
detail: err.message,
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
},
|
|
233
|
-
},
|
|
234
|
-
{
|
|
235
|
-
id: `${MODULE_ID}.api_key`,
|
|
236
|
-
name: 'API Key',
|
|
237
|
-
category: CATEGORY.VIBECHECK,
|
|
238
|
-
parallel: true,
|
|
239
|
-
check: async () => {
|
|
240
|
-
const apiKey = process.env.VIBECHECK_API_KEY;
|
|
241
|
-
|
|
242
|
-
if (!apiKey) {
|
|
243
|
-
return {
|
|
244
|
-
severity: SEVERITY.INFO,
|
|
245
|
-
message: 'Not configured (offline mode)',
|
|
246
|
-
detail: 'Set VIBECHECK_API_KEY for cloud features',
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// Basic format validation (don't log the key)
|
|
251
|
-
if (apiKey.length < 20) {
|
|
252
|
-
return {
|
|
253
|
-
severity: SEVERITY.WARNING,
|
|
254
|
-
message: 'API key appears invalid',
|
|
255
|
-
detail: 'Key is too short',
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
return {
|
|
260
|
-
severity: SEVERITY.PASS,
|
|
261
|
-
message: 'Configured',
|
|
262
|
-
metadata: { keyLength: apiKey.length },
|
|
263
|
-
};
|
|
264
|
-
},
|
|
265
|
-
},
|
|
266
|
-
{
|
|
267
|
-
id: `${MODULE_ID}.llm_config`,
|
|
268
|
-
name: 'LLM Configuration',
|
|
269
|
-
category: CATEGORY.VIBECHECK,
|
|
270
|
-
parallel: true,
|
|
271
|
-
check: async () => {
|
|
272
|
-
const baseUrl = process.env.VIBECHECK_LLM_BASE_URL;
|
|
273
|
-
const apiKey = process.env.VIBECHECK_LLM_API_KEY || process.env.OPENAI_API_KEY;
|
|
274
|
-
const model = process.env.VIBECHECK_LLM_MODEL;
|
|
275
|
-
|
|
276
|
-
const metadata = {
|
|
277
|
-
hasBaseUrl: !!baseUrl,
|
|
278
|
-
hasApiKey: !!apiKey,
|
|
279
|
-
model: model || 'default',
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
if (!apiKey) {
|
|
283
|
-
return {
|
|
284
|
-
severity: SEVERITY.INFO,
|
|
285
|
-
message: 'No LLM API key configured',
|
|
286
|
-
detail: 'Set VIBECHECK_LLM_API_KEY or OPENAI_API_KEY for AI features',
|
|
287
|
-
metadata,
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
return {
|
|
292
|
-
severity: SEVERITY.PASS,
|
|
293
|
-
message: model ? `Model: ${model}` : 'Configured',
|
|
294
|
-
metadata,
|
|
295
|
-
};
|
|
296
|
-
},
|
|
297
|
-
},
|
|
298
|
-
{
|
|
299
|
-
id: `${MODULE_ID}.git`,
|
|
300
|
-
name: 'Git Repository',
|
|
301
|
-
category: CATEGORY.VIBECHECK,
|
|
302
|
-
parallel: true,
|
|
303
|
-
check: async () => {
|
|
304
|
-
const gitDir = path.join(projectPath, '.git');
|
|
305
|
-
|
|
306
|
-
if (!fs.existsSync(gitDir)) {
|
|
307
|
-
return {
|
|
308
|
-
severity: SEVERITY.WARNING,
|
|
309
|
-
message: 'Not a git repository',
|
|
310
|
-
detail: 'Git is recommended for versioning and CI integration',
|
|
311
|
-
fixes: [{
|
|
312
|
-
type: FIX_TYPE.COMMAND,
|
|
313
|
-
description: 'Initialize git repository',
|
|
314
|
-
command: 'git init',
|
|
315
|
-
autoFixable: true,
|
|
316
|
-
}],
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
try {
|
|
321
|
-
const branch = execSync('git branch --show-current', {
|
|
322
|
-
cwd: projectPath,
|
|
323
|
-
encoding: 'utf8',
|
|
324
|
-
timeout: 5000,
|
|
325
|
-
}).trim();
|
|
326
|
-
|
|
327
|
-
const status = execSync('git status --porcelain', {
|
|
328
|
-
cwd: projectPath,
|
|
329
|
-
encoding: 'utf8',
|
|
330
|
-
timeout: 5000,
|
|
331
|
-
}).trim();
|
|
332
|
-
|
|
333
|
-
const uncommitted = status.split('\n').filter(Boolean).length;
|
|
334
|
-
const metadata = { branch, uncommitted };
|
|
335
|
-
|
|
336
|
-
if (uncommitted > 20) {
|
|
337
|
-
return {
|
|
338
|
-
severity: SEVERITY.WARNING,
|
|
339
|
-
message: `${branch} (${uncommitted} uncommitted files)`,
|
|
340
|
-
detail: 'Many uncommitted changes may affect scan accuracy',
|
|
341
|
-
metadata,
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
return {
|
|
346
|
-
severity: SEVERITY.PASS,
|
|
347
|
-
message: `${branch}${uncommitted ? ` (+${uncommitted})` : ''}`,
|
|
348
|
-
metadata,
|
|
349
|
-
};
|
|
350
|
-
} catch {
|
|
351
|
-
return {
|
|
352
|
-
severity: SEVERITY.PASS,
|
|
353
|
-
message: 'Initialized',
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
},
|
|
357
|
-
},
|
|
358
|
-
{
|
|
359
|
-
id: `${MODULE_ID}.playwright`,
|
|
360
|
-
name: 'Playwright (Runtime Verification)',
|
|
361
|
-
category: CATEGORY.VIBECHECK,
|
|
362
|
-
parallel: true,
|
|
363
|
-
check: async () => {
|
|
364
|
-
try {
|
|
365
|
-
execSync('npx playwright --version', {
|
|
366
|
-
encoding: 'utf8',
|
|
367
|
-
timeout: 10000,
|
|
368
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
return {
|
|
372
|
-
severity: SEVERITY.PASS,
|
|
373
|
-
message: 'Available',
|
|
374
|
-
detail: 'Enables runtime verification with `vibecheck reality`',
|
|
375
|
-
};
|
|
376
|
-
} catch {
|
|
377
|
-
return {
|
|
378
|
-
severity: SEVERITY.INFO,
|
|
379
|
-
message: 'Not installed (optional)',
|
|
380
|
-
detail: 'Install for runtime UI verification',
|
|
381
|
-
fixes: [{
|
|
382
|
-
type: FIX_TYPE.COMMAND,
|
|
383
|
-
description: 'Install Playwright',
|
|
384
|
-
command: 'npx playwright install',
|
|
385
|
-
autoFixable: false,
|
|
386
|
-
}],
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
},
|
|
390
|
-
},
|
|
391
|
-
];
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
module.exports = { MODULE_ID, createDiagnostics };
|
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Doctor Report Generator
|
|
3
|
-
*
|
|
4
|
-
* Generates JSON and Markdown reports from diagnostic results
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
const path = require('path');
|
|
9
|
-
const { SEVERITY, SEVERITY_WEIGHT, CATEGORY_META } = require('./types');
|
|
10
|
-
|
|
11
|
-
const REPORT_VERSION = '2.0.0';
|
|
12
|
-
|
|
13
|
-
function calculateHealthScore(diagnostics) {
|
|
14
|
-
if (diagnostics.length === 0) return 100;
|
|
15
|
-
|
|
16
|
-
let weightedSum = 0;
|
|
17
|
-
let totalWeight = 0;
|
|
18
|
-
|
|
19
|
-
for (const d of diagnostics) {
|
|
20
|
-
const weight = d.category === 'security' ? 2 : 1; // Security issues count more
|
|
21
|
-
weightedSum += (SEVERITY_WEIGHT[d.severity] || 1) * weight;
|
|
22
|
-
totalWeight += weight;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return Math.round((weightedSum / totalWeight) * 100);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function getVerdict(healthScore, diagnostics) {
|
|
29
|
-
const criticalCount = diagnostics.filter(d => d.severity === SEVERITY.CRITICAL).length;
|
|
30
|
-
const errorCount = diagnostics.filter(d => d.severity === SEVERITY.ERROR).length;
|
|
31
|
-
|
|
32
|
-
if (criticalCount > 0) return 'CRITICAL';
|
|
33
|
-
if (errorCount > 0) return 'UNHEALTHY';
|
|
34
|
-
if (healthScore < 80) return 'DEGRADED';
|
|
35
|
-
return 'HEALTHY';
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function createSummary(diagnostics) {
|
|
39
|
-
const total = diagnostics.length;
|
|
40
|
-
const passed = diagnostics.filter(d => d.severity === SEVERITY.PASS).length;
|
|
41
|
-
const info = diagnostics.filter(d => d.severity === SEVERITY.INFO).length;
|
|
42
|
-
const warnings = diagnostics.filter(d => d.severity === SEVERITY.WARNING).length;
|
|
43
|
-
const errors = diagnostics.filter(d => d.severity === SEVERITY.ERROR).length;
|
|
44
|
-
const critical = diagnostics.filter(d => d.severity === SEVERITY.CRITICAL).length;
|
|
45
|
-
|
|
46
|
-
const healthScore = calculateHealthScore(diagnostics);
|
|
47
|
-
const verdict = getVerdict(healthScore, diagnostics);
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
total,
|
|
51
|
-
passed,
|
|
52
|
-
info,
|
|
53
|
-
warnings,
|
|
54
|
-
errors,
|
|
55
|
-
critical,
|
|
56
|
-
healthScore,
|
|
57
|
-
verdict,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function generateJsonReport(diagnostics, projectPath, durationMs) {
|
|
62
|
-
const summary = createSummary(diagnostics);
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
version: REPORT_VERSION,
|
|
66
|
-
timestamp: new Date().toISOString(),
|
|
67
|
-
durationMs,
|
|
68
|
-
projectPath,
|
|
69
|
-
summary,
|
|
70
|
-
diagnostics: diagnostics.map(d => ({
|
|
71
|
-
id: d.id,
|
|
72
|
-
name: d.name,
|
|
73
|
-
category: d.category,
|
|
74
|
-
severity: d.severity,
|
|
75
|
-
message: d.message,
|
|
76
|
-
detail: d.detail,
|
|
77
|
-
durationMs: d.durationMs,
|
|
78
|
-
fixes: d.fixes,
|
|
79
|
-
metadata: d.metadata,
|
|
80
|
-
})),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function generateMarkdownReport(diagnostics, projectPath, durationMs) {
|
|
85
|
-
const summary = createSummary(diagnostics);
|
|
86
|
-
const lines = [];
|
|
87
|
-
|
|
88
|
-
lines.push('# 🩺 Vibecheck Doctor Report');
|
|
89
|
-
lines.push('');
|
|
90
|
-
lines.push(`**Project:** \`${projectPath}\` `);
|
|
91
|
-
lines.push(`**Generated:** ${new Date().toISOString()} `);
|
|
92
|
-
lines.push(`**Duration:** ${(durationMs / 1000).toFixed(1)}s`);
|
|
93
|
-
lines.push('');
|
|
94
|
-
|
|
95
|
-
// Summary Box
|
|
96
|
-
lines.push('## Summary');
|
|
97
|
-
lines.push('');
|
|
98
|
-
lines.push(`| Metric | Value |`);
|
|
99
|
-
lines.push(`|--------|-------|`);
|
|
100
|
-
lines.push(`| Health Score | **${summary.healthScore}%** |`);
|
|
101
|
-
lines.push(`| Verdict | **${summary.verdict}** |`);
|
|
102
|
-
lines.push(`| Total Checks | ${summary.total} |`);
|
|
103
|
-
lines.push(`| ✓ Passed | ${summary.passed} |`);
|
|
104
|
-
lines.push(`| ℹ Info | ${summary.info} |`);
|
|
105
|
-
lines.push(`| ⚠ Warnings | ${summary.warnings} |`);
|
|
106
|
-
lines.push(`| ✗ Errors | ${summary.errors} |`);
|
|
107
|
-
lines.push(`| 🔴 Critical | ${summary.critical} |`);
|
|
108
|
-
lines.push('');
|
|
109
|
-
|
|
110
|
-
// Group by category
|
|
111
|
-
const byCategory = {};
|
|
112
|
-
for (const d of diagnostics) {
|
|
113
|
-
if (!byCategory[d.category]) byCategory[d.category] = [];
|
|
114
|
-
byCategory[d.category].push(d);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Sort categories by order
|
|
118
|
-
const sortedCategories = Object.keys(byCategory).sort((a, b) => {
|
|
119
|
-
const orderA = CATEGORY_META[a]?.order || 99;
|
|
120
|
-
const orderB = CATEGORY_META[b]?.order || 99;
|
|
121
|
-
return orderA - orderB;
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
lines.push('## Diagnostics');
|
|
125
|
-
lines.push('');
|
|
126
|
-
|
|
127
|
-
for (const category of sortedCategories) {
|
|
128
|
-
const meta = CATEGORY_META[category] || { name: category, icon: '📋' };
|
|
129
|
-
lines.push(`### ${meta.icon} ${meta.name}`);
|
|
130
|
-
lines.push('');
|
|
131
|
-
|
|
132
|
-
for (const d of byCategory[category]) {
|
|
133
|
-
const icon = {
|
|
134
|
-
[SEVERITY.PASS]: '✓',
|
|
135
|
-
[SEVERITY.INFO]: 'ℹ',
|
|
136
|
-
[SEVERITY.WARNING]: '⚠',
|
|
137
|
-
[SEVERITY.ERROR]: '✗',
|
|
138
|
-
[SEVERITY.CRITICAL]: '🔴',
|
|
139
|
-
}[d.severity] || '•';
|
|
140
|
-
|
|
141
|
-
lines.push(`- ${icon} **${d.name}**: ${d.message}`);
|
|
142
|
-
|
|
143
|
-
if (d.detail) {
|
|
144
|
-
lines.push(` - ${d.detail}`);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (d.fixes && d.fixes.length > 0) {
|
|
148
|
-
for (const fix of d.fixes) {
|
|
149
|
-
if (fix.command) {
|
|
150
|
-
lines.push(` - Fix: \`${fix.command}\``);
|
|
151
|
-
} else if (fix.url) {
|
|
152
|
-
lines.push(` - [${fix.description}](${fix.url})`);
|
|
153
|
-
} else if (fix.description) {
|
|
154
|
-
lines.push(` - Fix: ${fix.description}`);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
lines.push('');
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Issues section
|
|
163
|
-
const issues = diagnostics.filter(d =>
|
|
164
|
-
d.severity === SEVERITY.CRITICAL ||
|
|
165
|
-
d.severity === SEVERITY.ERROR ||
|
|
166
|
-
d.severity === SEVERITY.WARNING
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
if (issues.length > 0) {
|
|
170
|
-
lines.push('## Issues to Fix');
|
|
171
|
-
lines.push('');
|
|
172
|
-
|
|
173
|
-
const critical = issues.filter(d => d.severity === SEVERITY.CRITICAL);
|
|
174
|
-
const errors = issues.filter(d => d.severity === SEVERITY.ERROR);
|
|
175
|
-
const warnings = issues.filter(d => d.severity === SEVERITY.WARNING);
|
|
176
|
-
|
|
177
|
-
if (critical.length > 0) {
|
|
178
|
-
lines.push('### 🔴 Critical');
|
|
179
|
-
for (const d of critical) {
|
|
180
|
-
lines.push(`1. **${d.name}**: ${d.message}`);
|
|
181
|
-
if (d.fixes?.[0]?.command) {
|
|
182
|
-
lines.push(` \`\`\`bash`);
|
|
183
|
-
lines.push(` ${d.fixes[0].command}`);
|
|
184
|
-
lines.push(` \`\`\``);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
lines.push('');
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (errors.length > 0) {
|
|
191
|
-
lines.push('### ✗ Errors');
|
|
192
|
-
for (const d of errors) {
|
|
193
|
-
lines.push(`1. **${d.name}**: ${d.message}`);
|
|
194
|
-
if (d.fixes?.[0]?.command) {
|
|
195
|
-
lines.push(` \`\`\`bash`);
|
|
196
|
-
lines.push(` ${d.fixes[0].command}`);
|
|
197
|
-
lines.push(` \`\`\``);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
lines.push('');
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (warnings.length > 0) {
|
|
204
|
-
lines.push('### ⚠ Warnings');
|
|
205
|
-
for (const d of warnings) {
|
|
206
|
-
lines.push(`1. **${d.name}**: ${d.message}`);
|
|
207
|
-
if (d.fixes?.[0]?.command) {
|
|
208
|
-
lines.push(` \`\`\`bash`);
|
|
209
|
-
lines.push(` ${d.fixes[0].command}`);
|
|
210
|
-
lines.push(` \`\`\``);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
lines.push('');
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
lines.push('---');
|
|
218
|
-
lines.push(`*Generated by vibecheck doctor v${REPORT_VERSION}*`);
|
|
219
|
-
|
|
220
|
-
return lines.join('\n');
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
function saveReports(diagnostics, projectPath, durationMs, outputDir) {
|
|
224
|
-
const jsonReport = generateJsonReport(diagnostics, projectPath, durationMs);
|
|
225
|
-
const mdReport = generateMarkdownReport(diagnostics, projectPath, durationMs);
|
|
226
|
-
|
|
227
|
-
// Ensure output directory exists
|
|
228
|
-
const doctorDir = path.join(outputDir, 'doctor');
|
|
229
|
-
fs.mkdirSync(doctorDir, { recursive: true });
|
|
230
|
-
|
|
231
|
-
// Save timestamped reports
|
|
232
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
|
|
233
|
-
const jsonPath = path.join(doctorDir, `doctor_${timestamp}.json`);
|
|
234
|
-
const mdPath = path.join(doctorDir, `doctor_${timestamp}.md`);
|
|
235
|
-
|
|
236
|
-
fs.writeFileSync(jsonPath, JSON.stringify(jsonReport, null, 2));
|
|
237
|
-
fs.writeFileSync(mdPath, mdReport);
|
|
238
|
-
|
|
239
|
-
// Save stable pointers
|
|
240
|
-
const lastJsonPath = path.join(doctorDir, 'last_doctor.json');
|
|
241
|
-
const lastMdPath = path.join(doctorDir, 'last_doctor.md');
|
|
242
|
-
|
|
243
|
-
fs.writeFileSync(lastJsonPath, JSON.stringify(jsonReport, null, 2));
|
|
244
|
-
fs.writeFileSync(lastMdPath, mdReport);
|
|
245
|
-
|
|
246
|
-
return {
|
|
247
|
-
json: jsonPath,
|
|
248
|
-
md: mdPath,
|
|
249
|
-
lastJson: lastJsonPath,
|
|
250
|
-
lastMd: lastMdPath,
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
module.exports = {
|
|
255
|
-
REPORT_VERSION,
|
|
256
|
-
calculateHealthScore,
|
|
257
|
-
getVerdict,
|
|
258
|
-
createSummary,
|
|
259
|
-
generateJsonReport,
|
|
260
|
-
generateMarkdownReport,
|
|
261
|
-
saveReports,
|
|
262
|
-
};
|