@neuralaxis/vibedoctor 0.1.1 → 0.1.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/README.md +219 -290
- package/dist/adapters/biome.d.ts +1 -1
- package/dist/adapters/biome.js +7 -4
- package/dist/adapters/coveragePy.js +3 -0
- 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/deptry.js +21 -2
- 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/knip.js +29 -4
- package/dist/adapters/lizard.d.ts +1 -1
- package/dist/adapters/lizard.js +51 -2
- package/dist/adapters/osvScanner.js +14 -2
- 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/ruff.d.ts +1 -1
- package/dist/adapters/ruff.js +4 -1
- package/dist/adapters/semgrep.d.ts +1 -1
- package/dist/adapters/semgrep.js +17 -3
- package/dist/adapters/shared.d.ts +1 -0
- package/dist/adapters/shared.js +22 -0
- package/dist/adapters/telemetryDetector.d.ts +2 -0
- package/dist/adapters/telemetryDetector.js +118 -0
- package/dist/adapters/tsc.js +43 -18
- package/dist/adapters/vulture.d.ts +1 -1
- package/dist/adapters/vulture.js +25 -6
- package/dist/agentPack/generateAgentPack.d.ts +7 -0
- package/dist/agentPack/generateAgentPack.js +89 -1
- package/dist/agentPack/templates/index.js +21 -15
- package/dist/agentPack/templates/skills.js +57 -4
- package/dist/cli/commands/agent.d.ts +5 -0
- package/dist/cli/commands/agent.js +10 -0
- package/dist/cli/commands/agentPlan.js +9 -1
- package/dist/cli/commands/init.js +50 -17
- package/dist/cli/commands/privacyReview.d.ts +9 -0
- package/dist/cli/commands/privacyReview.js +304 -0
- package/dist/cli/commands/scan.d.ts +1 -1
- package/dist/cli/commands/scan.js +31 -1
- package/dist/cli/commands/setup.js +16 -1
- package/dist/cli/commands/tool.d.ts +4 -0
- package/dist/cli/commands/tool.js +11 -0
- package/dist/cli/index.js +36 -0
- package/dist/core/config.d.ts +29 -0
- package/dist/core/config.js +142 -5
- package/dist/core/engine.d.ts +35 -1
- package/dist/core/engine.js +204 -36
- 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.d.ts +1 -1
- package/dist/core/projectDetector.js +34 -12
- package/dist/core/scanPlanner.js +4 -0
- package/dist/core/scoring.js +6 -0
- package/dist/core/toolRunner.d.ts +1 -0
- package/dist/core/toolRunner.js +73 -11
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/mcp/tools/shared.d.ts +1 -1
- package/dist/mcp/tools/shared.js +8 -1
- package/dist/reporters/agent.js +8 -0
- package/dist/reporters/html.js +12 -8
- package/dist/reporters/json.js +5 -5
- package/dist/reporters/markdown.js +15 -1
- 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 +6 -2
|
@@ -32,19 +32,35 @@ paths:
|
|
|
32
32
|
- dist/**
|
|
33
33
|
- build/**
|
|
34
34
|
- .venv/**
|
|
35
|
-
- coverage/**
|
|
36
|
-
- .next/**
|
|
37
|
-
- vendor/**
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
- coverage/**
|
|
36
|
+
- .next/**
|
|
37
|
+
- vendor/**
|
|
38
|
+
- .agents/**
|
|
39
|
+
- test/**
|
|
40
|
+
- tests/**
|
|
41
|
+
- "**/test/**"
|
|
42
|
+
- "**/tests/**"
|
|
43
|
+
- "**/*.test.*"
|
|
44
|
+
- "**/*.spec.*"
|
|
45
|
+
- "**/__tests__/**"
|
|
46
|
+
|
|
47
|
+
baseline:
|
|
40
48
|
enabled: true
|
|
41
49
|
file: .vibedoctor/baseline.json
|
|
42
50
|
fail_only_on_new_issues: true
|
|
43
51
|
|
|
44
|
-
score:
|
|
45
|
-
minimum: ${config_1.defaultConfig.score.minimum}
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
score:
|
|
53
|
+
minimum: ${config_1.defaultConfig.score.minimum}
|
|
54
|
+
|
|
55
|
+
runtime:
|
|
56
|
+
default_timeout_seconds: ${config_1.defaultConfig.runtime.defaultTimeoutSeconds}
|
|
57
|
+
tool_timeouts:
|
|
58
|
+
biome: ${config_1.defaultConfig.runtime.toolTimeouts.biome}
|
|
59
|
+
semgrep: ${config_1.defaultConfig.runtime.toolTimeouts.semgrep}
|
|
60
|
+
required_tools: []
|
|
61
|
+
fail_on_incomplete_scan: false
|
|
62
|
+
|
|
63
|
+
checks:
|
|
48
64
|
security:
|
|
49
65
|
enabled: true
|
|
50
66
|
fail_on_secrets: true
|
|
@@ -78,16 +94,33 @@ checks:
|
|
|
78
94
|
min_coverage: 70
|
|
79
95
|
min_changed_code_coverage: 80
|
|
80
96
|
|
|
81
|
-
dependencies:
|
|
82
|
-
enabled: true
|
|
83
|
-
fail_on_missing_dependencies: true
|
|
84
|
-
fail_on_new_direct_vulnerabilities: true
|
|
85
|
-
|
|
86
|
-
|
|
97
|
+
dependencies:
|
|
98
|
+
enabled: true
|
|
99
|
+
fail_on_missing_dependencies: true
|
|
100
|
+
fail_on_new_direct_vulnerabilities: true
|
|
101
|
+
|
|
102
|
+
privacy:
|
|
103
|
+
enabled: true
|
|
104
|
+
min_confidence_to_report: medium
|
|
105
|
+
mask_examples: true
|
|
106
|
+
max_file_bytes: 1048576
|
|
107
|
+
fail_on_regulated_identifiers: false
|
|
108
|
+
fail_on_sensitive_attributes: false
|
|
109
|
+
ai:
|
|
110
|
+
enabled: false
|
|
111
|
+
api_key_env: VIBEDOCTOR_AI_API_KEY
|
|
112
|
+
base_url_env: VIBEDOCTOR_AI_BASE_URL
|
|
113
|
+
model_env: VIBEDOCTOR_AI_MODEL
|
|
114
|
+
include_raw_values: false
|
|
115
|
+
presidio:
|
|
116
|
+
enabled: false
|
|
117
|
+
|
|
118
|
+
output:
|
|
87
119
|
terminal: true
|
|
88
120
|
json: .vibedoctor/report.json
|
|
89
|
-
html: .vibedoctor/report.html
|
|
90
|
-
agent: .vibedoctor/agent-plan.md
|
|
121
|
+
html: .vibedoctor/report.html
|
|
122
|
+
agent: .vibedoctor/agent-plan.md
|
|
123
|
+
privacy_review: .vibedoctor/privacy-review.json
|
|
91
124
|
`;
|
|
92
125
|
}
|
|
93
126
|
async function runInit(root) {
|
|
@@ -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
|
+
}
|
|
@@ -4,7 +4,7 @@ export type ScanCommandResult = {
|
|
|
4
4
|
output: string;
|
|
5
5
|
exitCode: number;
|
|
6
6
|
};
|
|
7
|
-
export declare function determineExitCode(scan: Pick<ScanOutput, "score" | "findings"
|
|
7
|
+
export declare function determineExitCode(scan: Pick<ScanOutput, "score" | "findings"> & Partial<Pick<ScanOutput, "completeness">>, config: VibeDoctorConfig): number;
|
|
8
8
|
export declare function runScanCommand(root: string, options: {
|
|
9
9
|
changed?: boolean;
|
|
10
10
|
quick?: boolean;
|
|
@@ -16,7 +16,17 @@ 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) {
|
|
26
|
+
if (scan.completeness &&
|
|
27
|
+
(scan.completeness.status === "invalid" || (config.runtime.failOnIncompleteScan && scan.completeness.status !== "complete"))) {
|
|
28
|
+
return 2;
|
|
29
|
+
}
|
|
20
30
|
if (scan.score.overall < config.score.minimum) {
|
|
21
31
|
return 1;
|
|
22
32
|
}
|
|
@@ -36,7 +46,27 @@ function determineExitCode(scan, config) {
|
|
|
36
46
|
const testFailure = config.checks.correctness.enabled &&
|
|
37
47
|
config.checks.correctness.failOnTestFailures &&
|
|
38
48
|
failingFindings.some((finding) => finding.category === "tests" && isHighSeverity(finding));
|
|
39
|
-
|
|
49
|
+
const regulatedIdentifierFailure = config.checks.privacy.enabled &&
|
|
50
|
+
config.checks.privacy.failOnRegulatedIdentifiers &&
|
|
51
|
+
failingFindings.some((finding) => finding.category === "privacy" &&
|
|
52
|
+
isHighConfidence(finding) &&
|
|
53
|
+
!isReviewedFalsePositive(finding) &&
|
|
54
|
+
finding.evidence?.sensitivity === "regulated_identifier");
|
|
55
|
+
const sensitiveAttributeFailure = config.checks.privacy.enabled &&
|
|
56
|
+
config.checks.privacy.failOnSensitiveAttributes &&
|
|
57
|
+
failingFindings.some((finding) => finding.category === "privacy" &&
|
|
58
|
+
isHighConfidence(finding) &&
|
|
59
|
+
!isReviewedFalsePositive(finding) &&
|
|
60
|
+
finding.evidence?.sensitivity === "high");
|
|
61
|
+
return secretFailure ||
|
|
62
|
+
dependencyFailure ||
|
|
63
|
+
missingDependencyFailure ||
|
|
64
|
+
typeFailure ||
|
|
65
|
+
testFailure ||
|
|
66
|
+
regulatedIdentifierFailure ||
|
|
67
|
+
sensitiveAttributeFailure
|
|
68
|
+
? 1
|
|
69
|
+
: 0;
|
|
40
70
|
}
|
|
41
71
|
async function runScanCommand(root, options) {
|
|
42
72
|
const mode = options.changed ? "changed" : options.quick ? "quick" : options.full ? "full" : "default";
|
|
@@ -8,6 +8,7 @@ exports.runSetupCommand = runSetupCommand;
|
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const toolRunner_1 = require("../../core/toolRunner");
|
|
10
10
|
const projectDetector_1 = require("../../core/projectDetector");
|
|
11
|
+
const config_1 = require("../../core/config");
|
|
11
12
|
const paths_1 = require("../../core/paths");
|
|
12
13
|
const VALID_SETUP_INCLUDES = new Set(["essential", "recommended", "all", "npm", "python", "manual", "built-in"]);
|
|
13
14
|
const essentialTools = [
|
|
@@ -29,6 +30,12 @@ const essentialTools = [
|
|
|
29
30
|
priority: "essential",
|
|
30
31
|
reason: "Finds large or complex files that need tests before refactor work."
|
|
31
32
|
},
|
|
33
|
+
{
|
|
34
|
+
id: "privacy-detector",
|
|
35
|
+
ecosystem: "built-in",
|
|
36
|
+
priority: "essential",
|
|
37
|
+
reason: "Finds personal-data and Privacy Review signals without sending data to an external service."
|
|
38
|
+
},
|
|
32
39
|
{
|
|
33
40
|
id: "tsc",
|
|
34
41
|
packageName: "typescript",
|
|
@@ -153,6 +160,13 @@ const recommendedTools = [
|
|
|
153
160
|
priority: "recommended",
|
|
154
161
|
reason: "Additional security and correctness rules.",
|
|
155
162
|
installHint: "Install Semgrep with: pipx install semgrep, uv tool install semgrep, or your OS package manager."
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
id: "presidio",
|
|
166
|
+
ecosystem: "manual",
|
|
167
|
+
priority: "recommended",
|
|
168
|
+
reason: "Optional external scanner for Privacy Review when checks.privacy.presidio.enabled is true.",
|
|
169
|
+
installHint: "Install in the project Python environment with: python -m pip install presidio-analyzer"
|
|
156
170
|
}
|
|
157
171
|
];
|
|
158
172
|
function hasActiveLanguage(project, language) {
|
|
@@ -240,7 +254,8 @@ function resolveTools(include) {
|
|
|
240
254
|
return combined.filter((tool) => tool.ecosystem === include);
|
|
241
255
|
}
|
|
242
256
|
async function createSetupPlan(root, include = "recommended") {
|
|
243
|
-
const
|
|
257
|
+
const { config } = await (0, config_1.loadConfig)(root);
|
|
258
|
+
const project = await (0, projectDetector_1.detectProject)(root, config.paths.exclude);
|
|
244
259
|
const tools = resolveTools(include);
|
|
245
260
|
const relevantTools = tools.filter((tool) => appliesToProject(tool, project));
|
|
246
261
|
const builtIn = relevantTools.filter((tool) => tool.ecosystem === "built-in");
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runToolRetryCommand = runToolRetryCommand;
|
|
4
|
+
const engine_1 = require("../../core/engine");
|
|
5
|
+
async function runToolRetryCommand(root, toolId, timeoutSeconds) {
|
|
6
|
+
const result = await (0, engine_1.retryTool)(root, toolId, timeoutSeconds);
|
|
7
|
+
return {
|
|
8
|
+
output: `${JSON.stringify(result, null, 2)}\n`,
|
|
9
|
+
exitCode: result.status === "ok" ? 0 : 2
|
|
10
|
+
};
|
|
11
|
+
}
|
package/dist/cli/index.js
CHANGED
|
@@ -14,9 +14,11 @@ const explain_1 = require("./commands/explain");
|
|
|
14
14
|
const fix_1 = require("./commands/fix");
|
|
15
15
|
const init_1 = require("./commands/init");
|
|
16
16
|
const server_1 = require("../mcp/server");
|
|
17
|
+
const privacyReview_1 = require("./commands/privacyReview");
|
|
17
18
|
const report_1 = require("./commands/report");
|
|
18
19
|
const scan_1 = require("./commands/scan");
|
|
19
20
|
const setup_1 = require("./commands/setup");
|
|
21
|
+
const tool_1 = require("./commands/tool");
|
|
20
22
|
function getVersion() {
|
|
21
23
|
try {
|
|
22
24
|
// After `npm version patch` + publish, package.json is shipped (see "files").
|
|
@@ -121,6 +123,27 @@ async function main() {
|
|
|
121
123
|
process.stdout.write(await (0, agent_1.runAgentSyncCommand)(process.cwd(), options));
|
|
122
124
|
process.exit(0);
|
|
123
125
|
});
|
|
126
|
+
const tool = program.command("tool").description("Inspect and recover individual scanner tools");
|
|
127
|
+
tool
|
|
128
|
+
.command("retry")
|
|
129
|
+
.description("Retry one scanner with an extended deadline")
|
|
130
|
+
.argument("<tool-id>")
|
|
131
|
+
.option("--timeout <seconds>", "Override the retry deadline in seconds", (value) => Number(value))
|
|
132
|
+
.action(async (toolId, options) => {
|
|
133
|
+
const result = await (0, tool_1.runToolRetryCommand)(process.cwd(), toolId, options.timeout);
|
|
134
|
+
process.stdout.write(result.output);
|
|
135
|
+
process.exit(result.exitCode);
|
|
136
|
+
});
|
|
137
|
+
agent
|
|
138
|
+
.command("plugin")
|
|
139
|
+
.description("Generate installable Codex and Claude plugin bundle files")
|
|
140
|
+
.option("--target <target>", "Single target alias for --targets")
|
|
141
|
+
.option("--targets <targets>", "codex,claude|all", "all")
|
|
142
|
+
.option("--force", "Overwrite generated plugin files")
|
|
143
|
+
.action(async (options) => {
|
|
144
|
+
process.stdout.write(await (0, agent_1.runAgentPluginCommand)(process.cwd(), options));
|
|
145
|
+
process.exit(0);
|
|
146
|
+
});
|
|
124
147
|
agent
|
|
125
148
|
.command("doctor")
|
|
126
149
|
.description("Check whether the agent-pack setup is healthy")
|
|
@@ -165,6 +188,19 @@ async function main() {
|
|
|
165
188
|
process.stdout.write(result.output);
|
|
166
189
|
process.exit(result.exitCode);
|
|
167
190
|
});
|
|
191
|
+
program
|
|
192
|
+
.command("privacy-review")
|
|
193
|
+
.description("Create a structured Privacy Review artifact for Privacy Review findings")
|
|
194
|
+
.option("--refresh", "Refresh the full scan before reviewing")
|
|
195
|
+
.option("--format <format>", "json|markdown", "json")
|
|
196
|
+
.action(async (options) => {
|
|
197
|
+
const result = await (0, privacyReview_1.runPrivacyReviewCommand)(process.cwd(), {
|
|
198
|
+
refresh: options.refresh,
|
|
199
|
+
format: options.format === "markdown" ? "markdown" : "json"
|
|
200
|
+
});
|
|
201
|
+
process.stdout.write(result.output);
|
|
202
|
+
process.exit(result.exitCode);
|
|
203
|
+
});
|
|
168
204
|
program
|
|
169
205
|
.command("mcp")
|
|
170
206
|
.description("Start the VibeDoctor MCP server over stdio")
|
package/dist/core/config.d.ts
CHANGED
|
@@ -17,6 +17,12 @@ export type VibeDoctorConfig = {
|
|
|
17
17
|
score: {
|
|
18
18
|
minimum: number;
|
|
19
19
|
};
|
|
20
|
+
runtime: {
|
|
21
|
+
defaultTimeoutSeconds: number;
|
|
22
|
+
toolTimeouts: Record<string, number>;
|
|
23
|
+
requiredTools: string[];
|
|
24
|
+
failOnIncompleteScan: boolean;
|
|
25
|
+
};
|
|
20
26
|
checks: {
|
|
21
27
|
security: {
|
|
22
28
|
enabled: boolean;
|
|
@@ -56,12 +62,35 @@ export type VibeDoctorConfig = {
|
|
|
56
62
|
failOnMissingDependencies: boolean;
|
|
57
63
|
failOnNewDirectVulnerabilities: boolean;
|
|
58
64
|
};
|
|
65
|
+
privacy: {
|
|
66
|
+
enabled: boolean;
|
|
67
|
+
minConfidenceToReport: "low" | "medium" | "high";
|
|
68
|
+
maskExamples: boolean;
|
|
69
|
+
maxFileBytes: number;
|
|
70
|
+
failOnRegulatedIdentifiers: boolean;
|
|
71
|
+
failOnSensitiveAttributes: boolean;
|
|
72
|
+
detectTelemetryOptOut: boolean;
|
|
73
|
+
detectUnsanitizedLogs: boolean;
|
|
74
|
+
detectApiOverfetching: boolean;
|
|
75
|
+
detectMissingRetention: boolean;
|
|
76
|
+
ai: {
|
|
77
|
+
enabled: boolean;
|
|
78
|
+
apiKeyEnv: string;
|
|
79
|
+
baseUrlEnv: string;
|
|
80
|
+
modelEnv: string;
|
|
81
|
+
includeRawValues: boolean;
|
|
82
|
+
};
|
|
83
|
+
presidio: {
|
|
84
|
+
enabled: boolean;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
59
87
|
};
|
|
60
88
|
output: {
|
|
61
89
|
terminal: boolean;
|
|
62
90
|
json: string;
|
|
63
91
|
html: string;
|
|
64
92
|
agent: string;
|
|
93
|
+
privacyReview: string;
|
|
65
94
|
};
|
|
66
95
|
};
|
|
67
96
|
export declare const defaultConfig: VibeDoctorConfig;
|