@vibecheckai/cli 3.0.3 → 3.0.5
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/bin/cli-hygiene.js +241 -0
- package/bin/dev/run-v2-torture.js +30 -0
- package/bin/guardrail.js +843 -0
- package/bin/runners/cli-utils.js +1070 -0
- package/bin/runners/context/ai-task-decomposer.js +337 -0
- package/bin/runners/context/analyzer.js +462 -0
- package/bin/runners/context/api-contracts.js +427 -0
- package/bin/runners/context/context-diff.js +342 -0
- package/bin/runners/context/context-pruner.js +291 -0
- package/bin/runners/context/dependency-graph.js +414 -0
- package/bin/runners/context/generators/claude.js +107 -0
- package/bin/runners/context/generators/codex.js +108 -0
- package/bin/runners/context/generators/copilot.js +119 -0
- package/bin/runners/context/generators/cursor.js +514 -0
- package/bin/runners/context/generators/mcp.js +151 -0
- package/bin/runners/context/generators/windsurf.js +180 -0
- package/bin/runners/context/git-context.js +302 -0
- package/bin/runners/context/index.js +1042 -0
- package/bin/runners/context/insights.js +173 -0
- package/bin/runners/context/mcp-server/generate-rules.js +337 -0
- package/bin/runners/context/mcp-server/index.js +1176 -0
- package/bin/runners/context/mcp-server/package.json +24 -0
- package/bin/runners/context/memory.js +200 -0
- package/bin/runners/context/monorepo.js +215 -0
- package/bin/runners/context/multi-repo-federation.js +404 -0
- package/bin/runners/context/patterns.js +253 -0
- package/bin/runners/context/proof-context.js +972 -0
- package/bin/runners/context/security-scanner.js +303 -0
- package/bin/runners/context/semantic-search.js +350 -0
- package/bin/runners/context/shared.js +264 -0
- package/bin/runners/context/team-conventions.js +310 -0
- package/bin/runners/lib/ai-bridge.js +416 -0
- package/bin/runners/lib/analysis-core.js +271 -0
- package/bin/runners/lib/analyzers.js +579 -0
- package/bin/runners/lib/assets/vibecheck-logo.png +0 -0
- package/bin/runners/lib/audit-bridge.js +391 -0
- package/bin/runners/lib/auth-truth.js +193 -0
- package/bin/runners/lib/auth.js +215 -0
- package/bin/runners/lib/backup.js +62 -0
- package/bin/runners/lib/billing.js +107 -0
- package/bin/runners/lib/claims.js +118 -0
- package/bin/runners/lib/cli-ui.js +540 -0
- package/bin/runners/lib/compliance-bridge-new.js +0 -0
- package/bin/runners/lib/compliance-bridge.js +165 -0
- package/bin/runners/lib/contracts/auth-contract.js +202 -0
- package/bin/runners/lib/contracts/env-contract.js +181 -0
- package/bin/runners/lib/contracts/external-contract.js +206 -0
- package/bin/runners/lib/contracts/guard.js +168 -0
- package/bin/runners/lib/contracts/index.js +89 -0
- package/bin/runners/lib/contracts/plan-validator.js +311 -0
- package/bin/runners/lib/contracts/route-contract.js +199 -0
- package/bin/runners/lib/contracts.js +804 -0
- package/bin/runners/lib/detect.js +89 -0
- package/bin/runners/lib/detectors-v2.js +703 -0
- package/bin/runners/lib/doctor/autofix.js +254 -0
- package/bin/runners/lib/doctor/index.js +37 -0
- package/bin/runners/lib/doctor/modules/dependencies.js +325 -0
- package/bin/runners/lib/doctor/modules/index.js +46 -0
- package/bin/runners/lib/doctor/modules/network.js +250 -0
- package/bin/runners/lib/doctor/modules/project.js +312 -0
- package/bin/runners/lib/doctor/modules/runtime.js +224 -0
- package/bin/runners/lib/doctor/modules/security.js +348 -0
- package/bin/runners/lib/doctor/modules/system.js +213 -0
- package/bin/runners/lib/doctor/modules/vibecheck.js +394 -0
- package/bin/runners/lib/doctor/reporter.js +262 -0
- package/bin/runners/lib/doctor/service.js +262 -0
- package/bin/runners/lib/doctor/types.js +113 -0
- package/bin/runners/lib/doctor/ui.js +263 -0
- package/bin/runners/lib/doctor-enhanced.js +233 -0
- package/bin/runners/lib/doctor-v2.js +608 -0
- package/bin/runners/lib/drift.js +425 -0
- package/bin/runners/lib/enforcement.js +72 -0
- package/bin/runners/lib/entitlements.js +8 -3
- package/bin/runners/lib/env-resolver.js +417 -0
- package/bin/runners/lib/extractors/client-calls.js +990 -0
- package/bin/runners/lib/extractors/fastify-route-dump.js +573 -0
- package/bin/runners/lib/extractors/fastify-routes.js +426 -0
- package/bin/runners/lib/extractors/index.js +363 -0
- package/bin/runners/lib/extractors/next-routes.js +524 -0
- package/bin/runners/lib/extractors/proof-graph.js +431 -0
- package/bin/runners/lib/extractors/route-matcher.js +451 -0
- package/bin/runners/lib/extractors/truthpack-v2.js +377 -0
- package/bin/runners/lib/extractors/ui-bindings.js +547 -0
- package/bin/runners/lib/findings-schema.js +281 -0
- package/bin/runners/lib/html-report.js +650 -0
- package/bin/runners/lib/missions/templates.js +45 -0
- package/bin/runners/lib/policy.js +295 -0
- package/bin/runners/lib/reality/correlation-detectors.js +359 -0
- package/bin/runners/lib/reality/index.js +318 -0
- package/bin/runners/lib/reality/request-hashing.js +416 -0
- package/bin/runners/lib/reality/request-mapper.js +453 -0
- package/bin/runners/lib/reality/safety-rails.js +463 -0
- package/bin/runners/lib/reality/semantic-snapshot.js +408 -0
- package/bin/runners/lib/reality/toast-detector.js +393 -0
- package/bin/runners/lib/route-truth.js +10 -10
- package/bin/runners/lib/schema-validator.js +350 -0
- package/bin/runners/lib/schemas/contracts.schema.json +160 -0
- package/bin/runners/lib/schemas/finding.schema.json +100 -0
- package/bin/runners/lib/schemas/mission-pack.schema.json +206 -0
- package/bin/runners/lib/schemas/proof-graph.schema.json +176 -0
- package/bin/runners/lib/schemas/reality-report.schema.json +162 -0
- package/bin/runners/lib/schemas/share-pack.schema.json +180 -0
- package/bin/runners/lib/schemas/ship-report.schema.json +117 -0
- package/bin/runners/lib/schemas/truthpack-v2.schema.json +303 -0
- package/bin/runners/lib/schemas/validator.js +438 -0
- package/bin/runners/lib/verdict-engine.js +628 -0
- package/bin/runners/runAIAgent.js +228 -1
- package/bin/runners/runBadge.js +181 -1
- package/bin/runners/runCtxDiff.js +301 -0
- package/bin/runners/runInitGha.js +78 -15
- package/bin/runners/runLaunch.js +180 -1
- package/bin/runners/runProve.js +23 -0
- package/bin/runners/runReplay.js +114 -84
- package/bin/runners/runScan.js +111 -32
- package/bin/runners/runShip.js +23 -2
- package/bin/runners/runTruthpack.js +9 -7
- package/bin/runners/runValidate.js +161 -1
- package/bin/vibecheck.js +6 -1
- package/package.json +1 -1
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Doctor Auto-Fix Engine
|
|
3
|
+
*
|
|
4
|
+
* Executes fixes for diagnostic issues automatically when safe
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const { execSync, spawn } = require('child_process');
|
|
10
|
+
const { FIX_TYPE, SEVERITY } = require('./types');
|
|
11
|
+
|
|
12
|
+
const FIX_RESULT = {
|
|
13
|
+
SUCCESS: 'success',
|
|
14
|
+
FAILED: 'failed',
|
|
15
|
+
SKIPPED: 'skipped',
|
|
16
|
+
REQUIRES_CONFIRMATION: 'requires_confirmation',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function canAutoFix(fix) {
|
|
20
|
+
if (!fix) return false;
|
|
21
|
+
if (fix.dangerous) return false;
|
|
22
|
+
if (fix.autoFixable === false) return false;
|
|
23
|
+
|
|
24
|
+
// Only auto-fix commands and file operations
|
|
25
|
+
return [FIX_TYPE.COMMAND, FIX_TYPE.FILE_CREATE, FIX_TYPE.FILE_EDIT].includes(fix.type);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function executeFix(fix, projectPath, options = {}) {
|
|
29
|
+
const { dryRun = false, interactive = false } = options;
|
|
30
|
+
|
|
31
|
+
if (!fix) {
|
|
32
|
+
return { status: FIX_RESULT.SKIPPED, reason: 'No fix provided' };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (fix.dangerous && !options.allowDangerous) {
|
|
36
|
+
return {
|
|
37
|
+
status: FIX_RESULT.REQUIRES_CONFIRMATION,
|
|
38
|
+
reason: 'Fix is marked as dangerous',
|
|
39
|
+
fix,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (dryRun) {
|
|
44
|
+
return {
|
|
45
|
+
status: FIX_RESULT.SKIPPED,
|
|
46
|
+
reason: 'Dry run mode',
|
|
47
|
+
wouldExecute: fix,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
switch (fix.type) {
|
|
53
|
+
case FIX_TYPE.COMMAND:
|
|
54
|
+
return await executeCommand(fix, projectPath, options);
|
|
55
|
+
|
|
56
|
+
case FIX_TYPE.FILE_CREATE:
|
|
57
|
+
return await createFile(fix, projectPath);
|
|
58
|
+
|
|
59
|
+
case FIX_TYPE.FILE_EDIT:
|
|
60
|
+
return await editFile(fix, projectPath);
|
|
61
|
+
|
|
62
|
+
case FIX_TYPE.MANUAL:
|
|
63
|
+
return {
|
|
64
|
+
status: FIX_RESULT.SKIPPED,
|
|
65
|
+
reason: 'Manual fix required',
|
|
66
|
+
instructions: fix.description,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
case FIX_TYPE.LINK:
|
|
70
|
+
return {
|
|
71
|
+
status: FIX_RESULT.SKIPPED,
|
|
72
|
+
reason: 'External documentation',
|
|
73
|
+
url: fix.url,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
default:
|
|
77
|
+
return {
|
|
78
|
+
status: FIX_RESULT.SKIPPED,
|
|
79
|
+
reason: `Unknown fix type: ${fix.type}`,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
} catch (err) {
|
|
83
|
+
return {
|
|
84
|
+
status: FIX_RESULT.FAILED,
|
|
85
|
+
error: err.message,
|
|
86
|
+
fix,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function executeCommand(fix, projectPath, options = {}) {
|
|
92
|
+
const { timeout = 60000 } = options;
|
|
93
|
+
|
|
94
|
+
if (!fix.command) {
|
|
95
|
+
return { status: FIX_RESULT.SKIPPED, reason: 'No command specified' };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
const result = execSync(fix.command, {
|
|
100
|
+
cwd: projectPath,
|
|
101
|
+
encoding: 'utf8',
|
|
102
|
+
timeout,
|
|
103
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
status: FIX_RESULT.SUCCESS,
|
|
108
|
+
command: fix.command,
|
|
109
|
+
output: result.trim(),
|
|
110
|
+
};
|
|
111
|
+
} catch (err) {
|
|
112
|
+
return {
|
|
113
|
+
status: FIX_RESULT.FAILED,
|
|
114
|
+
command: fix.command,
|
|
115
|
+
error: err.message,
|
|
116
|
+
stderr: err.stderr,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function createFile(fix, projectPath) {
|
|
122
|
+
if (!fix.path || fix.content === undefined) {
|
|
123
|
+
return { status: FIX_RESULT.SKIPPED, reason: 'No path or content specified' };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const fullPath = path.isAbsolute(fix.path) ? fix.path : path.join(projectPath, fix.path);
|
|
127
|
+
|
|
128
|
+
// Don't overwrite existing files
|
|
129
|
+
if (fs.existsSync(fullPath)) {
|
|
130
|
+
return {
|
|
131
|
+
status: FIX_RESULT.SKIPPED,
|
|
132
|
+
reason: 'File already exists',
|
|
133
|
+
path: fullPath,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Ensure directory exists
|
|
138
|
+
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
|
|
139
|
+
|
|
140
|
+
// Write file
|
|
141
|
+
fs.writeFileSync(fullPath, fix.content);
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
status: FIX_RESULT.SUCCESS,
|
|
145
|
+
action: 'created',
|
|
146
|
+
path: fullPath,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function editFile(fix, projectPath) {
|
|
151
|
+
if (!fix.path || fix.content === undefined) {
|
|
152
|
+
return { status: FIX_RESULT.SKIPPED, reason: 'No path or content specified' };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const fullPath = path.isAbsolute(fix.path) ? fix.path : path.join(projectPath, fix.path);
|
|
156
|
+
|
|
157
|
+
// Backup existing file
|
|
158
|
+
if (fs.existsSync(fullPath)) {
|
|
159
|
+
const backupPath = `${fullPath}.doctor-backup`;
|
|
160
|
+
fs.copyFileSync(fullPath, backupPath);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Write new content
|
|
164
|
+
fs.writeFileSync(fullPath, fix.content);
|
|
165
|
+
|
|
166
|
+
return {
|
|
167
|
+
status: FIX_RESULT.SUCCESS,
|
|
168
|
+
action: 'edited',
|
|
169
|
+
path: fullPath,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function autoFixAll(diagnostics, projectPath, options = {}) {
|
|
174
|
+
const {
|
|
175
|
+
dryRun = false,
|
|
176
|
+
severity = [SEVERITY.CRITICAL, SEVERITY.ERROR],
|
|
177
|
+
maxFixes = 10,
|
|
178
|
+
} = options;
|
|
179
|
+
|
|
180
|
+
const results = [];
|
|
181
|
+
let fixCount = 0;
|
|
182
|
+
|
|
183
|
+
// Sort by severity (critical first)
|
|
184
|
+
const severityOrder = [SEVERITY.CRITICAL, SEVERITY.ERROR, SEVERITY.WARNING];
|
|
185
|
+
const sortedDiagnostics = [...diagnostics].sort((a, b) => {
|
|
186
|
+
return severityOrder.indexOf(a.severity) - severityOrder.indexOf(b.severity);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
for (const diagnostic of sortedDiagnostics) {
|
|
190
|
+
if (fixCount >= maxFixes) break;
|
|
191
|
+
if (!severity.includes(diagnostic.severity)) continue;
|
|
192
|
+
if (!diagnostic.fixes || diagnostic.fixes.length === 0) continue;
|
|
193
|
+
|
|
194
|
+
// Try the first auto-fixable fix
|
|
195
|
+
const fix = diagnostic.fixes.find(f => canAutoFix(f));
|
|
196
|
+
if (!fix) continue;
|
|
197
|
+
|
|
198
|
+
const result = await executeFix(fix, projectPath, { ...options, dryRun });
|
|
199
|
+
results.push({
|
|
200
|
+
diagnosticId: diagnostic.id,
|
|
201
|
+
diagnosticName: diagnostic.name,
|
|
202
|
+
...result,
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
if (result.status === FIX_RESULT.SUCCESS) {
|
|
206
|
+
fixCount++;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
attempted: results.length,
|
|
212
|
+
succeeded: results.filter(r => r.status === FIX_RESULT.SUCCESS).length,
|
|
213
|
+
failed: results.filter(r => r.status === FIX_RESULT.FAILED).length,
|
|
214
|
+
skipped: results.filter(r => r.status === FIX_RESULT.SKIPPED).length,
|
|
215
|
+
results,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function getFixCommands(diagnostics, options = {}) {
|
|
220
|
+
const { severity = [SEVERITY.CRITICAL, SEVERITY.ERROR, SEVERITY.WARNING] } = options;
|
|
221
|
+
|
|
222
|
+
const commands = [];
|
|
223
|
+
|
|
224
|
+
for (const diagnostic of diagnostics) {
|
|
225
|
+
if (!severity.includes(diagnostic.severity)) continue;
|
|
226
|
+
if (!diagnostic.fixes) continue;
|
|
227
|
+
|
|
228
|
+
for (const fix of diagnostic.fixes) {
|
|
229
|
+
if (fix.type === FIX_TYPE.COMMAND && fix.command) {
|
|
230
|
+
commands.push({
|
|
231
|
+
diagnosticId: diagnostic.id,
|
|
232
|
+
diagnosticName: diagnostic.name,
|
|
233
|
+
command: fix.command,
|
|
234
|
+
description: fix.description,
|
|
235
|
+
dangerous: fix.dangerous,
|
|
236
|
+
autoFixable: canAutoFix(fix),
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return commands;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
module.exports = {
|
|
246
|
+
FIX_RESULT,
|
|
247
|
+
canAutoFix,
|
|
248
|
+
executeFix,
|
|
249
|
+
executeCommand,
|
|
250
|
+
createFile,
|
|
251
|
+
editFile,
|
|
252
|
+
autoFixAll,
|
|
253
|
+
getFixCommands,
|
|
254
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Doctor Service — Enterprise Environment Diagnostics
|
|
3
|
+
*
|
|
4
|
+
* Main entry point for the Doctor service
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { DoctorService, diagnose } = require('./service');
|
|
8
|
+
const { SEVERITY, CATEGORY, FIX_TYPE, SEVERITY_WEIGHT, CATEGORY_META } = require('./types');
|
|
9
|
+
const modules = require('./modules');
|
|
10
|
+
const reporter = require('./reporter');
|
|
11
|
+
const autofix = require('./autofix');
|
|
12
|
+
const ui = require('./ui');
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
// Main service
|
|
16
|
+
DoctorService,
|
|
17
|
+
diagnose,
|
|
18
|
+
|
|
19
|
+
// Types and constants
|
|
20
|
+
SEVERITY,
|
|
21
|
+
CATEGORY,
|
|
22
|
+
FIX_TYPE,
|
|
23
|
+
SEVERITY_WEIGHT,
|
|
24
|
+
CATEGORY_META,
|
|
25
|
+
|
|
26
|
+
// Modules
|
|
27
|
+
modules,
|
|
28
|
+
|
|
29
|
+
// Reporter
|
|
30
|
+
reporter,
|
|
31
|
+
|
|
32
|
+
// Auto-fix
|
|
33
|
+
autofix,
|
|
34
|
+
|
|
35
|
+
// UI utilities
|
|
36
|
+
ui,
|
|
37
|
+
};
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dependencies Diagnostics Module
|
|
3
|
+
*
|
|
4
|
+
* Checks for outdated packages, vulnerabilities, and dependency health
|
|
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 = 'dependencies';
|
|
13
|
+
|
|
14
|
+
function createDiagnostics(projectPath) {
|
|
15
|
+
return [
|
|
16
|
+
{
|
|
17
|
+
id: `${MODULE_ID}.outdated`,
|
|
18
|
+
name: 'Outdated Packages',
|
|
19
|
+
category: CATEGORY.DEPENDENCIES,
|
|
20
|
+
parallel: true,
|
|
21
|
+
check: async () => {
|
|
22
|
+
try {
|
|
23
|
+
// Try npm outdated (returns non-zero if outdated packages exist)
|
|
24
|
+
const result = execSync('npm outdated --json 2>/dev/null || echo "{}"', {
|
|
25
|
+
cwd: projectPath,
|
|
26
|
+
encoding: 'utf8',
|
|
27
|
+
timeout: 30000,
|
|
28
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
29
|
+
}).trim();
|
|
30
|
+
|
|
31
|
+
const outdated = JSON.parse(result || '{}');
|
|
32
|
+
const count = Object.keys(outdated).length;
|
|
33
|
+
|
|
34
|
+
const metadata = { count, packages: outdated };
|
|
35
|
+
|
|
36
|
+
// Check for major version updates
|
|
37
|
+
const majorUpdates = Object.entries(outdated).filter(([_, info]) => {
|
|
38
|
+
const current = parseInt((info.current || '0').split('.')[0]);
|
|
39
|
+
const latest = parseInt((info.latest || '0').split('.')[0]);
|
|
40
|
+
return latest > current;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (majorUpdates.length > 0) {
|
|
44
|
+
return {
|
|
45
|
+
severity: SEVERITY.INFO,
|
|
46
|
+
message: `${count} outdated (${majorUpdates.length} major)`,
|
|
47
|
+
detail: `Major updates: ${majorUpdates.slice(0, 3).map(([n]) => n).join(', ')}${majorUpdates.length > 3 ? '...' : ''}`,
|
|
48
|
+
metadata,
|
|
49
|
+
fixes: [{
|
|
50
|
+
type: FIX_TYPE.COMMAND,
|
|
51
|
+
description: 'Update all packages',
|
|
52
|
+
command: 'npm update',
|
|
53
|
+
autoFixable: false,
|
|
54
|
+
}],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (count > 0) {
|
|
59
|
+
return {
|
|
60
|
+
severity: SEVERITY.INFO,
|
|
61
|
+
message: `${count} minor/patch updates available`,
|
|
62
|
+
metadata,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
severity: SEVERITY.PASS,
|
|
68
|
+
message: 'All packages up to date',
|
|
69
|
+
metadata,
|
|
70
|
+
};
|
|
71
|
+
} catch {
|
|
72
|
+
return {
|
|
73
|
+
severity: SEVERITY.INFO,
|
|
74
|
+
message: 'Could not check for outdated packages',
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: `${MODULE_ID}.audit`,
|
|
81
|
+
name: 'Security Vulnerabilities',
|
|
82
|
+
category: CATEGORY.DEPENDENCIES,
|
|
83
|
+
parallel: true,
|
|
84
|
+
check: async () => {
|
|
85
|
+
try {
|
|
86
|
+
const result = execSync('npm audit --json 2>/dev/null || echo "{}"', {
|
|
87
|
+
cwd: projectPath,
|
|
88
|
+
encoding: 'utf8',
|
|
89
|
+
timeout: 60000,
|
|
90
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
91
|
+
}).trim();
|
|
92
|
+
|
|
93
|
+
let audit;
|
|
94
|
+
try {
|
|
95
|
+
audit = JSON.parse(result || '{}');
|
|
96
|
+
} catch {
|
|
97
|
+
return {
|
|
98
|
+
severity: SEVERITY.INFO,
|
|
99
|
+
message: 'Could not parse audit results',
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const vulnerabilities = audit.metadata?.vulnerabilities || {};
|
|
104
|
+
const total = vulnerabilities.total || 0;
|
|
105
|
+
const critical = vulnerabilities.critical || 0;
|
|
106
|
+
const high = vulnerabilities.high || 0;
|
|
107
|
+
const moderate = vulnerabilities.moderate || 0;
|
|
108
|
+
const low = vulnerabilities.low || 0;
|
|
109
|
+
|
|
110
|
+
const metadata = { total, critical, high, moderate, low };
|
|
111
|
+
|
|
112
|
+
if (critical > 0) {
|
|
113
|
+
return {
|
|
114
|
+
severity: SEVERITY.ERROR,
|
|
115
|
+
message: `${critical} critical vulnerabilities`,
|
|
116
|
+
detail: `Total: ${total} (${high} high, ${moderate} moderate, ${low} low)`,
|
|
117
|
+
metadata,
|
|
118
|
+
fixes: [
|
|
119
|
+
{
|
|
120
|
+
type: FIX_TYPE.COMMAND,
|
|
121
|
+
description: 'Auto-fix vulnerabilities',
|
|
122
|
+
command: 'npm audit fix',
|
|
123
|
+
autoFixable: true,
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
type: FIX_TYPE.COMMAND,
|
|
127
|
+
description: 'Force fix (may have breaking changes)',
|
|
128
|
+
command: 'npm audit fix --force',
|
|
129
|
+
dangerous: true,
|
|
130
|
+
autoFixable: false,
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (high > 0) {
|
|
137
|
+
return {
|
|
138
|
+
severity: SEVERITY.WARNING,
|
|
139
|
+
message: `${high} high severity vulnerabilities`,
|
|
140
|
+
detail: `Total: ${total} (${moderate} moderate, ${low} low)`,
|
|
141
|
+
metadata,
|
|
142
|
+
fixes: [{
|
|
143
|
+
type: FIX_TYPE.COMMAND,
|
|
144
|
+
description: 'Auto-fix vulnerabilities',
|
|
145
|
+
command: 'npm audit fix',
|
|
146
|
+
autoFixable: true,
|
|
147
|
+
}],
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (total > 0) {
|
|
152
|
+
return {
|
|
153
|
+
severity: SEVERITY.INFO,
|
|
154
|
+
message: `${total} low/moderate vulnerabilities`,
|
|
155
|
+
metadata,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
severity: SEVERITY.PASS,
|
|
161
|
+
message: 'No known vulnerabilities',
|
|
162
|
+
metadata,
|
|
163
|
+
};
|
|
164
|
+
} catch {
|
|
165
|
+
return {
|
|
166
|
+
severity: SEVERITY.INFO,
|
|
167
|
+
message: 'Could not run security audit',
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
id: `${MODULE_ID}.peer_deps`,
|
|
174
|
+
name: 'Peer Dependencies',
|
|
175
|
+
category: CATEGORY.DEPENDENCIES,
|
|
176
|
+
parallel: true,
|
|
177
|
+
check: async () => {
|
|
178
|
+
try {
|
|
179
|
+
const result = execSync('npm ls --json 2>&1 || true', {
|
|
180
|
+
cwd: projectPath,
|
|
181
|
+
encoding: 'utf8',
|
|
182
|
+
timeout: 30000,
|
|
183
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// Look for peer dependency warnings
|
|
187
|
+
const peerWarnings = (result.match(/WARN.*peer/gi) || []).length;
|
|
188
|
+
const missingPeers = (result.match(/missing peer/gi) || []).length;
|
|
189
|
+
|
|
190
|
+
const metadata = { peerWarnings, missingPeers };
|
|
191
|
+
|
|
192
|
+
if (missingPeers > 0) {
|
|
193
|
+
return {
|
|
194
|
+
severity: SEVERITY.WARNING,
|
|
195
|
+
message: `${missingPeers} missing peer dependencies`,
|
|
196
|
+
metadata,
|
|
197
|
+
fixes: [{
|
|
198
|
+
type: FIX_TYPE.COMMAND,
|
|
199
|
+
description: 'Install peer dependencies',
|
|
200
|
+
command: 'npm install --legacy-peer-deps',
|
|
201
|
+
autoFixable: false,
|
|
202
|
+
}],
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
severity: SEVERITY.PASS,
|
|
208
|
+
message: 'Peer dependencies satisfied',
|
|
209
|
+
metadata,
|
|
210
|
+
};
|
|
211
|
+
} catch {
|
|
212
|
+
return {
|
|
213
|
+
severity: SEVERITY.INFO,
|
|
214
|
+
message: 'Could not check peer dependencies',
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
id: `${MODULE_ID}.duplicate`,
|
|
221
|
+
name: 'Duplicate Packages',
|
|
222
|
+
category: CATEGORY.DEPENDENCIES,
|
|
223
|
+
parallel: true,
|
|
224
|
+
check: async () => {
|
|
225
|
+
try {
|
|
226
|
+
const result = execSync('npm dedupe --dry-run 2>&1 || true', {
|
|
227
|
+
cwd: projectPath,
|
|
228
|
+
encoding: 'utf8',
|
|
229
|
+
timeout: 30000,
|
|
230
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
const wouldDedupe = result.includes('removed') || result.includes('dedupe');
|
|
234
|
+
|
|
235
|
+
if (wouldDedupe) {
|
|
236
|
+
return {
|
|
237
|
+
severity: SEVERITY.INFO,
|
|
238
|
+
message: 'Deduplication possible',
|
|
239
|
+
fixes: [{
|
|
240
|
+
type: FIX_TYPE.COMMAND,
|
|
241
|
+
description: 'Deduplicate packages',
|
|
242
|
+
command: 'npm dedupe',
|
|
243
|
+
autoFixable: true,
|
|
244
|
+
}],
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return {
|
|
249
|
+
severity: SEVERITY.PASS,
|
|
250
|
+
message: 'No duplicates found',
|
|
251
|
+
};
|
|
252
|
+
} catch {
|
|
253
|
+
return {
|
|
254
|
+
severity: SEVERITY.INFO,
|
|
255
|
+
message: 'Could not check for duplicates',
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
id: `${MODULE_ID}.engines`,
|
|
262
|
+
name: 'Engine Requirements',
|
|
263
|
+
category: CATEGORY.DEPENDENCIES,
|
|
264
|
+
parallel: true,
|
|
265
|
+
check: async () => {
|
|
266
|
+
const pkgPath = path.join(projectPath, 'package.json');
|
|
267
|
+
|
|
268
|
+
try {
|
|
269
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
270
|
+
|
|
271
|
+
if (!pkg.engines) {
|
|
272
|
+
return {
|
|
273
|
+
severity: SEVERITY.INFO,
|
|
274
|
+
message: 'No engine requirements specified',
|
|
275
|
+
fixes: [{
|
|
276
|
+
type: FIX_TYPE.MANUAL,
|
|
277
|
+
description: 'Add "engines" field to package.json to enforce Node version',
|
|
278
|
+
autoFixable: false,
|
|
279
|
+
}],
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const nodeReq = pkg.engines.node;
|
|
284
|
+
const npmReq = pkg.engines.npm;
|
|
285
|
+
|
|
286
|
+
const metadata = { nodeReq, npmReq };
|
|
287
|
+
|
|
288
|
+
// Basic semver check against current version
|
|
289
|
+
if (nodeReq) {
|
|
290
|
+
const currentMajor = parseInt(process.version.slice(1).split('.')[0]);
|
|
291
|
+
const minMatch = nodeReq.match(/>=?\s*(\d+)/);
|
|
292
|
+
const minRequired = minMatch ? parseInt(minMatch[1]) : 0;
|
|
293
|
+
|
|
294
|
+
if (currentMajor < minRequired) {
|
|
295
|
+
return {
|
|
296
|
+
severity: SEVERITY.ERROR,
|
|
297
|
+
message: `Node ${process.version} does not satisfy "${nodeReq}"`,
|
|
298
|
+
metadata,
|
|
299
|
+
fixes: [{
|
|
300
|
+
type: FIX_TYPE.COMMAND,
|
|
301
|
+
description: `Upgrade to Node ${minRequired}+`,
|
|
302
|
+
command: `nvm install ${minRequired}`,
|
|
303
|
+
autoFixable: false,
|
|
304
|
+
}],
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return {
|
|
310
|
+
severity: SEVERITY.PASS,
|
|
311
|
+
message: nodeReq ? `node: ${nodeReq}` : 'Specified',
|
|
312
|
+
metadata,
|
|
313
|
+
};
|
|
314
|
+
} catch {
|
|
315
|
+
return {
|
|
316
|
+
severity: SEVERITY.INFO,
|
|
317
|
+
message: 'Could not check engine requirements',
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
];
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
module.exports = { MODULE_ID, createDiagnostics };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagnostic Modules Index
|
|
3
|
+
*
|
|
4
|
+
* Exports all diagnostic modules for the Doctor service
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const system = require('./system');
|
|
8
|
+
const runtime = require('./runtime');
|
|
9
|
+
const project = require('./project');
|
|
10
|
+
const dependencies = require('./dependencies');
|
|
11
|
+
const security = require('./security');
|
|
12
|
+
const network = require('./network');
|
|
13
|
+
const vibecheck = require('./vibecheck');
|
|
14
|
+
|
|
15
|
+
const ALL_MODULES = [
|
|
16
|
+
system,
|
|
17
|
+
runtime,
|
|
18
|
+
project,
|
|
19
|
+
dependencies,
|
|
20
|
+
security,
|
|
21
|
+
network,
|
|
22
|
+
vibecheck,
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
function getAllDiagnostics(projectPath) {
|
|
26
|
+
const diagnostics = [];
|
|
27
|
+
|
|
28
|
+
for (const mod of ALL_MODULES) {
|
|
29
|
+
const moduleDiagnostics = mod.createDiagnostics(projectPath);
|
|
30
|
+
diagnostics.push(...moduleDiagnostics);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return diagnostics;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = {
|
|
37
|
+
system,
|
|
38
|
+
runtime,
|
|
39
|
+
project,
|
|
40
|
+
dependencies,
|
|
41
|
+
security,
|
|
42
|
+
network,
|
|
43
|
+
vibecheck,
|
|
44
|
+
ALL_MODULES,
|
|
45
|
+
getAllDiagnostics,
|
|
46
|
+
};
|