@neuralaxis/vibedoctor 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +203 -280
- package/dist/adapters/customDeadChain.d.ts +2 -1
- package/dist/adapters/customDeadChain.js +100 -8
- package/dist/adapters/customLeftovers.js +33 -10
- package/dist/adapters/index.d.ts +3 -0
- package/dist/adapters/index.js +7 -1
- package/dist/adapters/jscpd.d.ts +1 -0
- package/dist/adapters/jscpd.js +10 -1
- package/dist/adapters/presidio.d.ts +2 -0
- package/dist/adapters/presidio.js +158 -0
- package/dist/adapters/privacyDetector.d.ts +10 -0
- package/dist/adapters/privacyDetector.js +600 -0
- package/dist/adapters/telemetryDetector.d.ts +2 -0
- package/dist/adapters/telemetryDetector.js +118 -0
- package/dist/agentPack/generateAgentPack.d.ts +7 -0
- package/dist/agentPack/generateAgentPack.js +89 -1
- package/dist/agentPack/templates/index.js +14 -11
- package/dist/agentPack/templates/skills.js +47 -0
- package/dist/cli/commands/agent.d.ts +5 -0
- package/dist/cli/commands/agent.js +10 -0
- package/dist/cli/commands/init.js +38 -13
- package/dist/cli/commands/privacyReview.d.ts +9 -0
- package/dist/cli/commands/privacyReview.js +304 -0
- package/dist/cli/commands/scan.js +27 -1
- package/dist/cli/commands/setup.js +49 -9
- package/dist/cli/index.js +63 -7
- package/dist/core/config.d.ts +23 -0
- package/dist/core/config.js +114 -5
- package/dist/core/engine.d.ts +3 -0
- package/dist/core/engine.js +31 -9
- package/dist/core/finding.d.ts +16 -2
- package/dist/core/finding.js +5 -0
- package/dist/core/paths.js +5 -0
- package/dist/core/privacyReview.d.ts +51 -0
- package/dist/core/privacyReview.js +94 -0
- package/dist/core/projectDetector.js +6 -1
- package/dist/core/scanPlanner.js +4 -0
- package/dist/core/scoring.js +6 -0
- package/dist/core/toolRunner.js +25 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/mcp/tools/shared.d.ts +1 -1
- package/dist/reporters/html.js +8 -6
- package/dist/reporters/json.js +3 -5
- package/dist/reporters/markdown.js +7 -0
- package/dist/reporters/sarif.js +6 -0
- package/dist/reporters/terminal.js +1 -5
- package/dist/rules/severityMap.d.ts +1 -0
- package/dist/rules/severityMap.js +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runPrivacyReviewCommand = runPrivacyReviewCommand;
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const shared_1 = require("./shared");
|
|
10
|
+
const engine_1 = require("../../core/engine");
|
|
11
|
+
const paths_1 = require("../../core/paths");
|
|
12
|
+
const privacyReview_1 = require("../../core/privacyReview");
|
|
13
|
+
const VALID_REVIEW_STATES = new Set(["confirmed", "likely", "false_positive", "needs_human_review"]);
|
|
14
|
+
async function loadOrRefreshScan(root, refresh) {
|
|
15
|
+
const { config } = await (0, shared_1.getConfig)(root);
|
|
16
|
+
const reportPath = node_path_1.default.join(root, config.output.json);
|
|
17
|
+
if (!refresh && (await (0, paths_1.pathExists)(reportPath))) {
|
|
18
|
+
const parsed = JSON.parse(await node_fs_1.promises.readFile(reportPath, "utf8"));
|
|
19
|
+
if (Array.isArray(parsed.findings)) {
|
|
20
|
+
const privacyFindings = parsed.privacyFindings ?? parsed.findings.filter((finding) => finding.category === "privacy");
|
|
21
|
+
return {
|
|
22
|
+
...parsed,
|
|
23
|
+
privacyFindings
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const scan = await (0, engine_1.runScan)(root, "full");
|
|
28
|
+
await (0, shared_1.ensureOutputArtifacts)(root, config, scan);
|
|
29
|
+
return scan;
|
|
30
|
+
}
|
|
31
|
+
function needsAiReview(finding) {
|
|
32
|
+
if (finding.category !== "privacy") {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (["confirmed", "likely", "false_positive"].includes(finding.evidence?.reviewState ?? "")) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
return finding.evidence?.reviewState === "needs_human_review" || finding.confidence !== "high";
|
|
39
|
+
}
|
|
40
|
+
async function readRawSnippet(root, finding) {
|
|
41
|
+
if (!finding.file || !finding.startLine) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const absolutePath = node_path_1.default.join(root, finding.file);
|
|
45
|
+
const content = await node_fs_1.promises.readFile(absolutePath, "utf8").catch(() => undefined);
|
|
46
|
+
if (!content) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
return content.split(/\r?\n/)[finding.startLine - 1]?.trim();
|
|
50
|
+
}
|
|
51
|
+
async function buildReviewFindings(root, findings, includeRawValues) {
|
|
52
|
+
const payload = [];
|
|
53
|
+
for (const finding of findings.filter(needsAiReview).slice(0, 50)) {
|
|
54
|
+
payload.push({
|
|
55
|
+
id: finding.id,
|
|
56
|
+
title: finding.title,
|
|
57
|
+
file: finding.file,
|
|
58
|
+
startLine: finding.startLine,
|
|
59
|
+
confidence: finding.confidence,
|
|
60
|
+
entityType: finding.evidence?.entityType,
|
|
61
|
+
sensitivity: finding.evidence?.sensitivity,
|
|
62
|
+
maskedValue: finding.evidence?.maskedValue,
|
|
63
|
+
snippet: finding.evidence?.snippet,
|
|
64
|
+
rawSnippet: includeRawValues ? await readRawSnippet(root, finding) : undefined,
|
|
65
|
+
reasons: finding.evidence?.reasons
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return payload;
|
|
69
|
+
}
|
|
70
|
+
function buildPrompt(findings, includeRawValues) {
|
|
71
|
+
return [
|
|
72
|
+
"Review these VibeDoctor Privacy Review findings.",
|
|
73
|
+
"Classify each finding as one of: confirmed, likely, false_positive, needs_human_review.",
|
|
74
|
+
"Return strict JSON with this shape: {\"findings\":[{\"id\":\"...\",\"classification\":\"...\",\"rationale\":\"...\",\"recommended_action\":\"...\"}]}",
|
|
75
|
+
includeRawValues
|
|
76
|
+
? "Raw source snippets may be included because repository config explicitly allowed raw value review."
|
|
77
|
+
: "Only masked snippets are included. Do not ask for raw values unless needed for human review.",
|
|
78
|
+
JSON.stringify({ findings }, null, 2)
|
|
79
|
+
].join("\n\n");
|
|
80
|
+
}
|
|
81
|
+
async function callAiReview(baseUrl, apiKey, model, findings, includeRawValues) {
|
|
82
|
+
const response = await fetch(`${baseUrl.replace(/\/$/, "")}/chat/completions`, {
|
|
83
|
+
method: "POST",
|
|
84
|
+
headers: {
|
|
85
|
+
Authorization: `Bearer ${apiKey}`,
|
|
86
|
+
"Content-Type": "application/json"
|
|
87
|
+
},
|
|
88
|
+
body: JSON.stringify({
|
|
89
|
+
model,
|
|
90
|
+
temperature: 0,
|
|
91
|
+
messages: [
|
|
92
|
+
{
|
|
93
|
+
role: "system",
|
|
94
|
+
content: "You review privacy scanner findings. Be conservative, concise, and return only valid JSON."
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
role: "user",
|
|
98
|
+
content: buildPrompt(findings, includeRawValues)
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
})
|
|
102
|
+
});
|
|
103
|
+
if (!response.ok) {
|
|
104
|
+
throw new Error(`AI review request failed: ${response.status} ${response.statusText}`);
|
|
105
|
+
}
|
|
106
|
+
const json = (await response.json());
|
|
107
|
+
const content = json.choices?.[0]?.message?.content;
|
|
108
|
+
if (!content) {
|
|
109
|
+
throw new Error("AI review response did not include message content.");
|
|
110
|
+
}
|
|
111
|
+
return content;
|
|
112
|
+
}
|
|
113
|
+
function parseAiJson(content) {
|
|
114
|
+
const trimmed = content.trim();
|
|
115
|
+
const fenced = trimmed.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i)?.[1];
|
|
116
|
+
return JSON.parse(fenced ?? trimmed);
|
|
117
|
+
}
|
|
118
|
+
function normalizeAiState(value) {
|
|
119
|
+
if (typeof value !== "string") {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
const normalized = value.trim().toLowerCase().replaceAll("-", "_");
|
|
123
|
+
return VALID_REVIEW_STATES.has(normalized) ? normalized : undefined;
|
|
124
|
+
}
|
|
125
|
+
function findingFallbackState(finding) {
|
|
126
|
+
if (finding.confidence === "high") {
|
|
127
|
+
return "confirmed";
|
|
128
|
+
}
|
|
129
|
+
return "needs_human_review";
|
|
130
|
+
}
|
|
131
|
+
function defaultRecommendedAction(state, finding) {
|
|
132
|
+
if (state === "false_positive") {
|
|
133
|
+
return "Keep as reviewed false positive unless the source data changes.";
|
|
134
|
+
}
|
|
135
|
+
if (state === "needs_human_review") {
|
|
136
|
+
return "Review with a human before treating this as confirmed personal data.";
|
|
137
|
+
}
|
|
138
|
+
if (finding.evidence?.sensitivity === "regulated_identifier" || finding.evidence?.sensitivity === "high") {
|
|
139
|
+
return "Remove, anonymize, or move this data into a controlled fixture or secret store.";
|
|
140
|
+
}
|
|
141
|
+
return "Verify whether this personal data belongs in the repository and mask it where possible.";
|
|
142
|
+
}
|
|
143
|
+
function buildFallbackDecision(finding, reviewedAt, reviewedBy, rationale) {
|
|
144
|
+
const reviewState = findingFallbackState(finding);
|
|
145
|
+
return {
|
|
146
|
+
id: finding.id,
|
|
147
|
+
title: finding.title,
|
|
148
|
+
file: finding.file,
|
|
149
|
+
startLine: finding.startLine,
|
|
150
|
+
entityType: finding.evidence?.entityType,
|
|
151
|
+
sensitivity: finding.evidence?.sensitivity,
|
|
152
|
+
reviewState,
|
|
153
|
+
reviewedAt,
|
|
154
|
+
reviewedBy,
|
|
155
|
+
rationale: rationale ??
|
|
156
|
+
(reviewState === "confirmed"
|
|
157
|
+
? "High-confidence deterministic Privacy Review finding."
|
|
158
|
+
: "Finding needs human review because deterministic evidence was not high-confidence."),
|
|
159
|
+
recommendedAction: defaultRecommendedAction(reviewState, finding)
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function buildAiDecisions(findings, reviewCandidates, content, reviewedAt, reviewedBy) {
|
|
163
|
+
const parsed = parseAiJson(content);
|
|
164
|
+
if (!Array.isArray(parsed.findings)) {
|
|
165
|
+
throw new Error("AI review JSON did not contain a findings array.");
|
|
166
|
+
}
|
|
167
|
+
const candidateIds = new Set(reviewCandidates.map((finding) => finding.id));
|
|
168
|
+
const byId = new Map();
|
|
169
|
+
for (const item of parsed.findings) {
|
|
170
|
+
if (typeof item.id === "string" && candidateIds.has(item.id)) {
|
|
171
|
+
byId.set(item.id, item);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return findings.map((finding) => {
|
|
175
|
+
const ai = byId.get(finding.id);
|
|
176
|
+
if (!ai) {
|
|
177
|
+
return buildFallbackDecision(finding, reviewedAt, reviewedBy);
|
|
178
|
+
}
|
|
179
|
+
const reviewState = normalizeAiState(ai.classification ?? ai.reviewState);
|
|
180
|
+
if (!reviewState) {
|
|
181
|
+
return buildFallbackDecision(finding, reviewedAt, reviewedBy, "AI review returned an unsupported classification.");
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
id: finding.id,
|
|
185
|
+
title: finding.title,
|
|
186
|
+
file: finding.file,
|
|
187
|
+
startLine: finding.startLine,
|
|
188
|
+
entityType: finding.evidence?.entityType,
|
|
189
|
+
sensitivity: finding.evidence?.sensitivity,
|
|
190
|
+
reviewState,
|
|
191
|
+
reviewedAt,
|
|
192
|
+
reviewedBy,
|
|
193
|
+
rationale: typeof ai.rationale === "string" && ai.rationale.trim() ? ai.rationale.trim() : "AI review did not provide a rationale.",
|
|
194
|
+
recommendedAction: typeof (ai.recommendedAction ?? ai.recommended_action) === "string" && String(ai.recommendedAction ?? ai.recommended_action).trim()
|
|
195
|
+
? String(ai.recommendedAction ?? ai.recommended_action).trim()
|
|
196
|
+
: defaultRecommendedAction(reviewState, finding)
|
|
197
|
+
};
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
function buildErroredDecisions(findings, reviewedAt, reviewedBy, message) {
|
|
201
|
+
return findings.map((finding) => finding.confidence === "high"
|
|
202
|
+
? buildFallbackDecision(finding, reviewedAt, reviewedBy)
|
|
203
|
+
: buildFallbackDecision(finding, reviewedAt, reviewedBy, message));
|
|
204
|
+
}
|
|
205
|
+
function renderFindingLine(finding) {
|
|
206
|
+
const location = finding.file ? ` (${finding.file}${finding.startLine ? `:${finding.startLine}` : ""})` : "";
|
|
207
|
+
return `- ${finding.title}${location}: ${finding.rationale} Action: ${finding.recommendedAction}`;
|
|
208
|
+
}
|
|
209
|
+
function renderGroup(title, findings) {
|
|
210
|
+
if (findings.length === 0) {
|
|
211
|
+
return [`## ${title}`, "", "- None", ""];
|
|
212
|
+
}
|
|
213
|
+
return [`## ${title}`, "", ...findings.map(renderFindingLine), ""];
|
|
214
|
+
}
|
|
215
|
+
function renderMarkdown(payload) {
|
|
216
|
+
const findings = payload.findings;
|
|
217
|
+
const falsePositives = findings.filter((finding) => finding.reviewState === "false_positive");
|
|
218
|
+
const unresolved = findings.filter((finding) => finding.reviewState === "needs_human_review");
|
|
219
|
+
const confirmedRegulated = findings.filter((finding) => finding.reviewState === "confirmed" && finding.sensitivity === "regulated_identifier");
|
|
220
|
+
const sensitiveAttributes = findings.filter((finding) => finding.sensitivity === "high" && finding.reviewState !== "false_positive");
|
|
221
|
+
const combinationRisk = findings.filter((finding) => finding.sensitivity === "combination_risk" && finding.reviewState !== "false_positive");
|
|
222
|
+
const lines = [
|
|
223
|
+
"# VibeDoctor Privacy Review",
|
|
224
|
+
"",
|
|
225
|
+
`Status: ${payload.status}`,
|
|
226
|
+
`Review file: ${payload.reviewPath}`,
|
|
227
|
+
`Reviewed findings: ${payload.summary.total}`,
|
|
228
|
+
`Needs human review: ${payload.summary.needsHumanReview}`,
|
|
229
|
+
`False positives: ${payload.summary.falsePositive}`,
|
|
230
|
+
""
|
|
231
|
+
];
|
|
232
|
+
if (payload.model) {
|
|
233
|
+
lines.push(`Model: ${payload.model}`, "");
|
|
234
|
+
}
|
|
235
|
+
if (payload.message) {
|
|
236
|
+
lines.push(payload.message, "");
|
|
237
|
+
}
|
|
238
|
+
lines.push(...renderGroup("Confirmed Regulated Identifiers", confirmedRegulated), ...renderGroup("Sensitive Attributes", sensitiveAttributes), ...renderGroup("Combination-Risk Fields", combinationRisk), ...renderGroup("Likely False Positives", falsePositives), ...renderGroup("Unresolved Review Items", unresolved));
|
|
239
|
+
return `${lines.join("\n").trimEnd()}\n`;
|
|
240
|
+
}
|
|
241
|
+
async function runPrivacyReviewCommand(root, options = {}) {
|
|
242
|
+
const { config } = await (0, shared_1.getConfig)(root);
|
|
243
|
+
const scan = await loadOrRefreshScan(root, options.refresh === true);
|
|
244
|
+
const aiConfig = config.checks.privacy.ai;
|
|
245
|
+
const reviewedAt = new Date().toISOString();
|
|
246
|
+
const reviewCandidates = await buildReviewFindings(root, scan.privacyFindings ?? [], aiConfig.includeRawValues);
|
|
247
|
+
const allPrivacyFindings = scan.privacyFindings ?? [];
|
|
248
|
+
let status = reviewCandidates.length > 0 ? "needs_human_review" : "ok";
|
|
249
|
+
let reviewedBy = "privacy-detector";
|
|
250
|
+
let model;
|
|
251
|
+
let message;
|
|
252
|
+
let decisions = allPrivacyFindings.map((finding) => buildFallbackDecision(finding, reviewedAt, reviewedBy));
|
|
253
|
+
let exitCode = 0;
|
|
254
|
+
if (reviewCandidates.length > 0 && aiConfig.enabled) {
|
|
255
|
+
const apiKey = process.env[aiConfig.apiKeyEnv];
|
|
256
|
+
model = process.env[aiConfig.modelEnv];
|
|
257
|
+
const baseUrl = process.env[aiConfig.baseUrlEnv] ?? "https://api.openai.com/v1";
|
|
258
|
+
if (!apiKey || !model) {
|
|
259
|
+
status = "ai_error";
|
|
260
|
+
exitCode = 1;
|
|
261
|
+
message = `Missing AI review configuration. Set ${aiConfig.apiKeyEnv} and ${aiConfig.modelEnv}.`;
|
|
262
|
+
decisions = buildErroredDecisions(allPrivacyFindings, reviewedAt, reviewedBy, message);
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
reviewedBy = `privacy-ai-review:${model}`;
|
|
266
|
+
try {
|
|
267
|
+
const content = await callAiReview(baseUrl, apiKey, model, reviewCandidates, aiConfig.includeRawValues);
|
|
268
|
+
decisions = buildAiDecisions(allPrivacyFindings, reviewCandidates, content, reviewedAt, reviewedBy);
|
|
269
|
+
status = decisions.some((finding) => finding.reviewState === "needs_human_review") ? "needs_human_review" : "ok";
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
status = "ai_error";
|
|
273
|
+
exitCode = 1;
|
|
274
|
+
message = error instanceof Error ? error.message : String(error);
|
|
275
|
+
decisions = buildErroredDecisions(allPrivacyFindings, reviewedAt, reviewedBy, message);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
else if (reviewCandidates.length > 0) {
|
|
280
|
+
message = "AI review is disabled. Medium- and low-confidence findings were left as needs_human_review.";
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
message = "No medium- or low-confidence Privacy Review findings need AI review.";
|
|
284
|
+
}
|
|
285
|
+
const artifact = (0, privacyReview_1.buildPrivacyReviewArtifact)({
|
|
286
|
+
generatedAt: reviewedAt,
|
|
287
|
+
reviewedBy,
|
|
288
|
+
model,
|
|
289
|
+
status,
|
|
290
|
+
findings: decisions
|
|
291
|
+
});
|
|
292
|
+
const reviewPath = await (0, privacyReview_1.writePrivacyReview)(root, artifact, config.output.privacyReview);
|
|
293
|
+
const mergedScan = await (0, engine_1.runScan)(root, "full");
|
|
294
|
+
await (0, shared_1.ensureOutputArtifacts)(root, config, mergedScan);
|
|
295
|
+
const payload = {
|
|
296
|
+
...artifact,
|
|
297
|
+
reviewPath,
|
|
298
|
+
message
|
|
299
|
+
};
|
|
300
|
+
return {
|
|
301
|
+
output: options.format === "markdown" ? renderMarkdown(payload) : `${JSON.stringify(payload, null, 2)}\n`,
|
|
302
|
+
exitCode
|
|
303
|
+
};
|
|
304
|
+
}
|
|
@@ -16,6 +16,12 @@ function shouldCountForFailure(isNew, config) {
|
|
|
16
16
|
function isHighSeverity(finding) {
|
|
17
17
|
return finding.severity === "high" || finding.severity === "critical";
|
|
18
18
|
}
|
|
19
|
+
function isHighConfidence(finding) {
|
|
20
|
+
return finding.confidence === "high";
|
|
21
|
+
}
|
|
22
|
+
function isReviewedFalsePositive(finding) {
|
|
23
|
+
return finding.evidence?.reviewState === "false_positive";
|
|
24
|
+
}
|
|
19
25
|
function determineExitCode(scan, config) {
|
|
20
26
|
if (scan.score.overall < config.score.minimum) {
|
|
21
27
|
return 1;
|
|
@@ -36,7 +42,27 @@ function determineExitCode(scan, config) {
|
|
|
36
42
|
const testFailure = config.checks.correctness.enabled &&
|
|
37
43
|
config.checks.correctness.failOnTestFailures &&
|
|
38
44
|
failingFindings.some((finding) => finding.category === "tests" && isHighSeverity(finding));
|
|
39
|
-
|
|
45
|
+
const regulatedIdentifierFailure = config.checks.privacy.enabled &&
|
|
46
|
+
config.checks.privacy.failOnRegulatedIdentifiers &&
|
|
47
|
+
failingFindings.some((finding) => finding.category === "privacy" &&
|
|
48
|
+
isHighConfidence(finding) &&
|
|
49
|
+
!isReviewedFalsePositive(finding) &&
|
|
50
|
+
finding.evidence?.sensitivity === "regulated_identifier");
|
|
51
|
+
const sensitiveAttributeFailure = config.checks.privacy.enabled &&
|
|
52
|
+
config.checks.privacy.failOnSensitiveAttributes &&
|
|
53
|
+
failingFindings.some((finding) => finding.category === "privacy" &&
|
|
54
|
+
isHighConfidence(finding) &&
|
|
55
|
+
!isReviewedFalsePositive(finding) &&
|
|
56
|
+
finding.evidence?.sensitivity === "high");
|
|
57
|
+
return secretFailure ||
|
|
58
|
+
dependencyFailure ||
|
|
59
|
+
missingDependencyFailure ||
|
|
60
|
+
typeFailure ||
|
|
61
|
+
testFailure ||
|
|
62
|
+
regulatedIdentifierFailure ||
|
|
63
|
+
sensitiveAttributeFailure
|
|
64
|
+
? 1
|
|
65
|
+
: 0;
|
|
40
66
|
}
|
|
41
67
|
async function runScanCommand(root, options) {
|
|
42
68
|
const mode = options.changed ? "changed" : options.quick ? "quick" : options.full ? "full" : "default";
|
|
@@ -29,6 +29,12 @@ const essentialTools = [
|
|
|
29
29
|
priority: "essential",
|
|
30
30
|
reason: "Finds large or complex files that need tests before refactor work."
|
|
31
31
|
},
|
|
32
|
+
{
|
|
33
|
+
id: "privacy-detector",
|
|
34
|
+
ecosystem: "built-in",
|
|
35
|
+
priority: "essential",
|
|
36
|
+
reason: "Finds personal-data and Privacy Review signals without sending data to an external service."
|
|
37
|
+
},
|
|
32
38
|
{
|
|
33
39
|
id: "tsc",
|
|
34
40
|
packageName: "typescript",
|
|
@@ -138,6 +144,14 @@ const recommendedTools = [
|
|
|
138
144
|
languages: ["python"],
|
|
139
145
|
reason: "Python dependency hygiene signal."
|
|
140
146
|
},
|
|
147
|
+
{
|
|
148
|
+
id: "lizard",
|
|
149
|
+
executable: "lizard",
|
|
150
|
+
ecosystem: "manual",
|
|
151
|
+
priority: "recommended",
|
|
152
|
+
reason: "Function-level complexity and code size hotspots (great for spotting refactor candidates).",
|
|
153
|
+
installHint: "Install Lizard with: pipx install lizard, uv tool install lizard, or your OS package manager."
|
|
154
|
+
},
|
|
141
155
|
{
|
|
142
156
|
id: "semgrep",
|
|
143
157
|
executable: "semgrep",
|
|
@@ -145,6 +159,13 @@ const recommendedTools = [
|
|
|
145
159
|
priority: "recommended",
|
|
146
160
|
reason: "Additional security and correctness rules.",
|
|
147
161
|
installHint: "Install Semgrep with: pipx install semgrep, uv tool install semgrep, or your OS package manager."
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
id: "presidio",
|
|
165
|
+
ecosystem: "manual",
|
|
166
|
+
priority: "recommended",
|
|
167
|
+
reason: "Optional external scanner for Privacy Review when checks.privacy.presidio.enabled is true.",
|
|
168
|
+
installHint: "Install in the project Python environment with: python -m pip install presidio-analyzer"
|
|
148
169
|
}
|
|
149
170
|
];
|
|
150
171
|
function hasActiveLanguage(project, language) {
|
|
@@ -223,16 +244,15 @@ function resolveTools(include) {
|
|
|
223
244
|
if (include === "essential") {
|
|
224
245
|
return essentialTools;
|
|
225
246
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
return allTools;
|
|
247
|
+
const combined = [...essentialTools, ...recommendedTools];
|
|
248
|
+
if (include === "recommended" || include === "all") {
|
|
249
|
+
// "recommended" is the sensible default experience (essential + high-value extras).
|
|
250
|
+
// "all" currently resolves to the same set (add future extended tools here if needed).
|
|
251
|
+
return combined;
|
|
232
252
|
}
|
|
233
|
-
return
|
|
253
|
+
return combined.filter((tool) => tool.ecosystem === include);
|
|
234
254
|
}
|
|
235
|
-
async function createSetupPlan(root, include = "
|
|
255
|
+
async function createSetupPlan(root, include = "recommended") {
|
|
236
256
|
const project = await (0, projectDetector_1.detectProject)(root);
|
|
237
257
|
const tools = resolveTools(include);
|
|
238
258
|
const relevantTools = tools.filter((tool) => appliesToProject(tool, project));
|
|
@@ -307,10 +327,30 @@ function renderPlan(plan, include, results = []) {
|
|
|
307
327
|
else if (plan.commands.length === 0 && plan.manual.length === 0 && plan.skipped.length === 0) {
|
|
308
328
|
lines.push(`All relevant ${include} tools are already available.`);
|
|
309
329
|
}
|
|
330
|
+
// Always surface guidance + suggestions for users who may not know what else exists
|
|
331
|
+
if (include !== "all") {
|
|
332
|
+
lines.push("");
|
|
333
|
+
lines.push("Want richer analysis or not sure what else to add?");
|
|
334
|
+
if (include === "essential") {
|
|
335
|
+
lines.push(" The default `vibedoctor setup` (recommended) already adds jscpd, coverage, radon, deptry, lizard, and semgrep on top of the core essentials.");
|
|
336
|
+
lines.push(" Try `vibedoctor setup --include all` (or just `setup --apply` with no flag) for the full curated set.");
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
lines.push(" `vibedoctor setup` / `--include recommended` (the default) already includes the best balance for most projects.");
|
|
340
|
+
lines.push(" `vibedoctor setup --include all` currently matches recommended (more extended tools may be added here in the future).");
|
|
341
|
+
}
|
|
342
|
+
lines.push("");
|
|
343
|
+
lines.push("Still want more? Common high-value additions and next steps:");
|
|
344
|
+
lines.push(" - Configure coverage reporting in your test framework (Jest/Vitest/Coverage.py) — VibeDoctor reads the reports automatically");
|
|
345
|
+
lines.push(" - Manually install lizard or semgrep (shown above with one-line hints) for deeper complexity + rule-based checks");
|
|
346
|
+
lines.push(" - Add jscpd (npm) if you want duplication heatmaps for large refactors");
|
|
347
|
+
lines.push("");
|
|
348
|
+
lines.push("Tip: Re-run `vibedoctor scan --quick` (or `scan --full`) after changes to see updated health + findings.");
|
|
349
|
+
}
|
|
310
350
|
return `${lines.join("\n")}\n`;
|
|
311
351
|
}
|
|
312
352
|
async function runSetupCommand(root, options = {}) {
|
|
313
|
-
const include = VALID_SETUP_INCLUDES.has(options.include ?? "
|
|
353
|
+
const include = VALID_SETUP_INCLUDES.has(options.include ?? "recommended") ? (options.include ?? "recommended") : "recommended";
|
|
314
354
|
const plan = await createSetupPlan(root, include);
|
|
315
355
|
if (!options.apply) {
|
|
316
356
|
return { output: renderPlan(plan, include), exitCode: 0 };
|
package/dist/cli/index.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
3
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
7
|
const commander_1 = require("commander");
|
|
8
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
5
10
|
const agent_1 = require("./commands/agent");
|
|
6
11
|
const agentPlan_1 = require("./commands/agentPlan");
|
|
7
12
|
const baseline_1 = require("./commands/baseline");
|
|
@@ -9,17 +14,34 @@ const explain_1 = require("./commands/explain");
|
|
|
9
14
|
const fix_1 = require("./commands/fix");
|
|
10
15
|
const init_1 = require("./commands/init");
|
|
11
16
|
const server_1 = require("../mcp/server");
|
|
17
|
+
const privacyReview_1 = require("./commands/privacyReview");
|
|
12
18
|
const report_1 = require("./commands/report");
|
|
13
19
|
const scan_1 = require("./commands/scan");
|
|
14
20
|
const setup_1 = require("./commands/setup");
|
|
21
|
+
function getVersion() {
|
|
22
|
+
try {
|
|
23
|
+
// After `npm version patch` + publish, package.json is shipped (see "files").
|
|
24
|
+
// When executed from dist/cli/index.js (in the installed package), it lives at ../../package.json.
|
|
25
|
+
const pkgPath = node_path_1.default.resolve(__dirname, "..", "..", "package.json");
|
|
26
|
+
const pkg = JSON.parse(node_fs_1.default.readFileSync(pkgPath, "utf8"));
|
|
27
|
+
if (pkg && typeof pkg.version === "string") {
|
|
28
|
+
return pkg.version;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// fall through to hardcoded fallback
|
|
33
|
+
}
|
|
34
|
+
return "0.1.0";
|
|
35
|
+
}
|
|
15
36
|
async function main() {
|
|
16
37
|
const program = new commander_1.Command();
|
|
17
|
-
program.name("vibedoctor").description("Brutally simple repo health diagnosis.").version(
|
|
38
|
+
program.name("vibedoctor").description("Brutally simple repo health diagnosis.").version(getVersion());
|
|
18
39
|
program
|
|
19
40
|
.command("init")
|
|
20
41
|
.description("Create vibedoctor.yml and .vibedoctor baseline scaffolding")
|
|
21
42
|
.action(async () => {
|
|
22
43
|
process.stdout.write(`Created ${await (0, init_1.runInit)(process.cwd())}\n`);
|
|
44
|
+
process.exit(0);
|
|
23
45
|
});
|
|
24
46
|
program
|
|
25
47
|
.command("scan")
|
|
@@ -32,17 +54,20 @@ async function main() {
|
|
|
32
54
|
.action(async (options) => {
|
|
33
55
|
const result = await (0, scan_1.runScanCommand)(process.cwd(), options);
|
|
34
56
|
process.stdout.write(result.output);
|
|
35
|
-
|
|
57
|
+
// Force exit: some child processes / native tool wrappers (especially on Windows)
|
|
58
|
+
// can leave event-loop handles open even after 'close'. Explicit exit guarantees
|
|
59
|
+
// the CLI terminates promptly for terminals and CI after printing the report.
|
|
60
|
+
process.exit(result.exitCode);
|
|
36
61
|
});
|
|
37
62
|
program
|
|
38
63
|
.command("setup")
|
|
39
64
|
.description("Print or install scanner tools for the selected setup set")
|
|
40
65
|
.option("--apply", "Install automatable tools")
|
|
41
|
-
.option("--include <level>", "essential|recommended|all|npm|python|manual|built-in", "
|
|
66
|
+
.option("--include <level>", "essential|recommended|all|npm|python|manual|built-in (default: recommended)", "recommended")
|
|
42
67
|
.action(async (options) => {
|
|
43
68
|
const result = await (0, setup_1.runSetupCommand)(process.cwd(), options);
|
|
44
69
|
process.stdout.write(result.output);
|
|
45
|
-
process.
|
|
70
|
+
process.exit(result.exitCode);
|
|
46
71
|
});
|
|
47
72
|
program
|
|
48
73
|
.command("fix")
|
|
@@ -50,6 +75,7 @@ async function main() {
|
|
|
50
75
|
.option("--safe", "Only allow safe fixes", true)
|
|
51
76
|
.action(async () => {
|
|
52
77
|
process.stdout.write(await (0, fix_1.runSafeFixCommand)(process.cwd()));
|
|
78
|
+
process.exit(0);
|
|
53
79
|
});
|
|
54
80
|
program
|
|
55
81
|
.command("report")
|
|
@@ -63,6 +89,7 @@ async function main() {
|
|
|
63
89
|
.action(async (options) => {
|
|
64
90
|
const format = options.full ? "full" : options.html ? "html" : options.markdown ? "markdown" : options.agent ? "agent" : options.sarif ? "sarif" : "json";
|
|
65
91
|
process.stdout.write(await (0, report_1.runReportCommand)(process.cwd(), format));
|
|
92
|
+
process.exit(0);
|
|
66
93
|
});
|
|
67
94
|
const agent = program.command("agent").description("Manage the VibeDoctor agent pack");
|
|
68
95
|
agent
|
|
@@ -73,6 +100,7 @@ async function main() {
|
|
|
73
100
|
.option("--force", "Overwrite generated files")
|
|
74
101
|
.action(async (options) => {
|
|
75
102
|
process.stdout.write(await (0, agent_1.runAgentInitCommand)(process.cwd(), options));
|
|
103
|
+
process.exit(0);
|
|
76
104
|
});
|
|
77
105
|
agent
|
|
78
106
|
.command("pack")
|
|
@@ -82,6 +110,7 @@ async function main() {
|
|
|
82
110
|
.option("--force", "Overwrite generated files")
|
|
83
111
|
.action(async (options) => {
|
|
84
112
|
process.stdout.write(await (0, agent_1.runAgentPackCommand)(process.cwd(), options));
|
|
113
|
+
process.exit(0);
|
|
85
114
|
});
|
|
86
115
|
agent
|
|
87
116
|
.command("sync")
|
|
@@ -91,6 +120,17 @@ async function main() {
|
|
|
91
120
|
.option("--force", "Overwrite generated files")
|
|
92
121
|
.action(async (options) => {
|
|
93
122
|
process.stdout.write(await (0, agent_1.runAgentSyncCommand)(process.cwd(), options));
|
|
123
|
+
process.exit(0);
|
|
124
|
+
});
|
|
125
|
+
agent
|
|
126
|
+
.command("plugin")
|
|
127
|
+
.description("Generate installable Codex and Claude plugin bundle files")
|
|
128
|
+
.option("--target <target>", "Single target alias for --targets")
|
|
129
|
+
.option("--targets <targets>", "codex,claude|all", "all")
|
|
130
|
+
.option("--force", "Overwrite generated plugin files")
|
|
131
|
+
.action(async (options) => {
|
|
132
|
+
process.stdout.write(await (0, agent_1.runAgentPluginCommand)(process.cwd(), options));
|
|
133
|
+
process.exit(0);
|
|
94
134
|
});
|
|
95
135
|
agent
|
|
96
136
|
.command("doctor")
|
|
@@ -100,7 +140,7 @@ async function main() {
|
|
|
100
140
|
.action(async (options) => {
|
|
101
141
|
const result = await (0, agent_1.runAgentDoctorCommand)(process.cwd(), options);
|
|
102
142
|
process.stdout.write(result.output);
|
|
103
|
-
process.
|
|
143
|
+
process.exit(result.exitCode);
|
|
104
144
|
});
|
|
105
145
|
const baseline = program.command("baseline").description("Manage baselines");
|
|
106
146
|
baseline
|
|
@@ -108,6 +148,7 @@ async function main() {
|
|
|
108
148
|
.description("Create a baseline file from the current findings")
|
|
109
149
|
.action(async () => {
|
|
110
150
|
process.stdout.write(await (0, baseline_1.runBaselineCreateCommand)(process.cwd()));
|
|
151
|
+
process.exit(0);
|
|
111
152
|
});
|
|
112
153
|
program
|
|
113
154
|
.command("agent-plan")
|
|
@@ -116,6 +157,7 @@ async function main() {
|
|
|
116
157
|
.option("--for <target>", "codex|copilot|claude|cursor")
|
|
117
158
|
.action(async (options) => {
|
|
118
159
|
process.stdout.write(await (0, agentPlan_1.runAgentPlanCommand)(process.cwd(), options.format, options.for));
|
|
160
|
+
process.exit(0);
|
|
119
161
|
});
|
|
120
162
|
program
|
|
121
163
|
.command("explain")
|
|
@@ -124,6 +166,7 @@ async function main() {
|
|
|
124
166
|
.option("--format <format>", "text|json", "text")
|
|
125
167
|
.action(async (findingId, options) => {
|
|
126
168
|
process.stdout.write(await (0, explain_1.runExplainCommand)(process.cwd(), findingId, options.format));
|
|
169
|
+
process.exit(0);
|
|
127
170
|
});
|
|
128
171
|
program
|
|
129
172
|
.command("verify")
|
|
@@ -131,7 +174,20 @@ async function main() {
|
|
|
131
174
|
.action(async () => {
|
|
132
175
|
const result = await (0, scan_1.runScanCommand)(process.cwd(), { changed: true });
|
|
133
176
|
process.stdout.write(result.output);
|
|
134
|
-
process.
|
|
177
|
+
process.exit(result.exitCode);
|
|
178
|
+
});
|
|
179
|
+
program
|
|
180
|
+
.command("privacy-review")
|
|
181
|
+
.description("Create a structured Privacy Review artifact for Privacy Review findings")
|
|
182
|
+
.option("--refresh", "Refresh the full scan before reviewing")
|
|
183
|
+
.option("--format <format>", "json|markdown", "json")
|
|
184
|
+
.action(async (options) => {
|
|
185
|
+
const result = await (0, privacyReview_1.runPrivacyReviewCommand)(process.cwd(), {
|
|
186
|
+
refresh: options.refresh,
|
|
187
|
+
format: options.format === "markdown" ? "markdown" : "json"
|
|
188
|
+
});
|
|
189
|
+
process.stdout.write(result.output);
|
|
190
|
+
process.exit(result.exitCode);
|
|
135
191
|
});
|
|
136
192
|
program
|
|
137
193
|
.command("mcp")
|
|
@@ -144,5 +200,5 @@ async function main() {
|
|
|
144
200
|
main().catch((error) => {
|
|
145
201
|
const message = error instanceof Error ? error.stack ?? error.message : String(error);
|
|
146
202
|
process.stderr.write(`${message}\n`);
|
|
147
|
-
process.
|
|
203
|
+
process.exit(1);
|
|
148
204
|
});
|
package/dist/core/config.d.ts
CHANGED
|
@@ -56,12 +56,35 @@ export type VibeDoctorConfig = {
|
|
|
56
56
|
failOnMissingDependencies: boolean;
|
|
57
57
|
failOnNewDirectVulnerabilities: boolean;
|
|
58
58
|
};
|
|
59
|
+
privacy: {
|
|
60
|
+
enabled: boolean;
|
|
61
|
+
minConfidenceToReport: "low" | "medium" | "high";
|
|
62
|
+
maskExamples: boolean;
|
|
63
|
+
maxFileBytes: number;
|
|
64
|
+
failOnRegulatedIdentifiers: boolean;
|
|
65
|
+
failOnSensitiveAttributes: boolean;
|
|
66
|
+
detectTelemetryOptOut: boolean;
|
|
67
|
+
detectUnsanitizedLogs: boolean;
|
|
68
|
+
detectApiOverfetching: boolean;
|
|
69
|
+
detectMissingRetention: boolean;
|
|
70
|
+
ai: {
|
|
71
|
+
enabled: boolean;
|
|
72
|
+
apiKeyEnv: string;
|
|
73
|
+
baseUrlEnv: string;
|
|
74
|
+
modelEnv: string;
|
|
75
|
+
includeRawValues: boolean;
|
|
76
|
+
};
|
|
77
|
+
presidio: {
|
|
78
|
+
enabled: boolean;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
59
81
|
};
|
|
60
82
|
output: {
|
|
61
83
|
terminal: boolean;
|
|
62
84
|
json: string;
|
|
63
85
|
html: string;
|
|
64
86
|
agent: string;
|
|
87
|
+
privacyReview: string;
|
|
65
88
|
};
|
|
66
89
|
};
|
|
67
90
|
export declare const defaultConfig: VibeDoctorConfig;
|