@neuralaxis/vibedoctor 0.2.1 → 0.2.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 +49 -23
- package/dist/adapters/biome.js +3 -2
- package/dist/adapters/flowDoctor.d.ts +7 -0
- package/dist/adapters/flowDoctor.js +195 -0
- package/dist/adapters/gitleaks.js +4 -2
- package/dist/adapters/index.d.ts +1 -0
- package/dist/adapters/index.js +3 -1
- package/dist/adapters/osvScanner.js +4 -2
- package/dist/adapters/ruff.js +7 -3
- package/dist/adapters/shared.d.ts +4 -0
- package/dist/cli/commands/init.js +7 -0
- package/dist/cli/commands/scan.d.ts +6 -0
- package/dist/cli/commands/scan.js +16 -2
- package/dist/cli/index.js +4 -4
- package/dist/core/agentDiagnosis.d.ts +39 -0
- package/dist/core/agentDiagnosis.js +96 -0
- package/dist/core/config.d.ts +11 -0
- package/dist/core/config.js +31 -2
- package/dist/core/engine.d.ts +8 -1
- package/dist/core/engine.js +54 -51
- package/dist/core/finding.d.ts +1 -1
- package/dist/core/finding.js +8 -3
- package/dist/core/findingCorrelator.d.ts +19 -0
- package/dist/core/findingCorrelator.js +112 -0
- package/dist/core/findingNormalizer.js +1 -0
- package/dist/core/managedTools.d.ts +25 -0
- package/dist/core/managedTools.js +186 -0
- package/dist/core/repoGraph.d.ts +62 -0
- package/dist/core/repoGraph.js +408 -0
- package/dist/core/riskRanker.d.ts +6 -0
- package/dist/core/riskRanker.js +127 -0
- package/dist/core/scanContext.d.ts +26 -0
- package/dist/core/scanContext.js +44 -0
- package/dist/core/scanPlanner.d.ts +1 -0
- package/dist/core/scanPlanner.js +10 -6
- package/dist/core/toolRegistry.js +12 -5
- package/dist/core/toolRunner.d.ts +4 -0
- package/dist/core/toolRunner.js +18 -0
- package/dist/core/toolRuntime.d.ts +40 -0
- package/dist/core/toolRuntime.js +417 -0
- package/dist/core/toolVerification.d.ts +3 -1
- package/dist/core/toolVerification.js +58 -3
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/reporters/agent.d.ts +1 -1
- package/dist/reporters/agent.js +7 -0
- package/package.json +80 -80
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findingToAgentIssue = findingToAgentIssue;
|
|
4
|
+
exports.buildAgentDiagnosis = buildAgentDiagnosis;
|
|
5
|
+
const findingCorrelator_1 = require("./findingCorrelator");
|
|
6
|
+
const riskRanker_1 = require("./riskRanker");
|
|
7
|
+
function describeImpact(finding) {
|
|
8
|
+
if (finding.category === "security") {
|
|
9
|
+
return "Credentials or vulnerable dependencies can be exploited if this reaches a shared or deployed tree.";
|
|
10
|
+
}
|
|
11
|
+
if (finding.source === "flow-doctor") {
|
|
12
|
+
return "A request or error path does not match the implemented contract, so the feature can fail at runtime.";
|
|
13
|
+
}
|
|
14
|
+
if (finding.category === "correctness" || finding.category === "tests") {
|
|
15
|
+
return "Type, lint, or test evidence indicates the code may not behave as written.";
|
|
16
|
+
}
|
|
17
|
+
if (finding.category === "privacy") {
|
|
18
|
+
return "Personal data may be handled without a visible control.";
|
|
19
|
+
}
|
|
20
|
+
if (finding.category === "dead_code" || finding.category === "leftovers") {
|
|
21
|
+
return "Unused or leftover code increases review cost and hides real defects.";
|
|
22
|
+
}
|
|
23
|
+
return finding.message;
|
|
24
|
+
}
|
|
25
|
+
function recommendedRepair(finding) {
|
|
26
|
+
if (finding.remediation?.steps.length) {
|
|
27
|
+
return finding.remediation.steps.join(" ");
|
|
28
|
+
}
|
|
29
|
+
if (finding.agentInstruction) {
|
|
30
|
+
return finding.agentInstruction;
|
|
31
|
+
}
|
|
32
|
+
if (finding.fixCommand) {
|
|
33
|
+
return `Apply: ${finding.fixCommand}`;
|
|
34
|
+
}
|
|
35
|
+
return finding.message;
|
|
36
|
+
}
|
|
37
|
+
function verificationGuidance(finding, testCommands) {
|
|
38
|
+
const test = testCommands[0];
|
|
39
|
+
const parts = [
|
|
40
|
+
finding.file ? `Re-read ${finding.file}${finding.startLine ? `:${finding.startLine}` : ""} after the edit.` : undefined,
|
|
41
|
+
test ? `Run \`${test}\`.` : undefined,
|
|
42
|
+
"Run `vibedoctor scan --changed --report agent-json` and confirm this finding id is gone."
|
|
43
|
+
];
|
|
44
|
+
return parts.filter(Boolean).join(" ");
|
|
45
|
+
}
|
|
46
|
+
function findingToAgentIssue(finding, testCommands = []) {
|
|
47
|
+
return {
|
|
48
|
+
id: finding.id,
|
|
49
|
+
ruleId: finding.evidence?.toolRawId ?? finding.title,
|
|
50
|
+
title: finding.title,
|
|
51
|
+
severity: finding.severity,
|
|
52
|
+
confidence: finding.confidence,
|
|
53
|
+
evidenceGrade: finding.evidenceGrade ?? "observed",
|
|
54
|
+
category: finding.category,
|
|
55
|
+
locations: [{ file: finding.file, startLine: finding.startLine, endLine: finding.endLine }],
|
|
56
|
+
impact: describeImpact(finding),
|
|
57
|
+
likelyRootCause: (0, findingCorrelator_1.inferRootCause)(finding),
|
|
58
|
+
supportingEngines: Array.from(new Set([finding.source, ...(finding.corroboratedBy ?? [])])),
|
|
59
|
+
recommendedRepair: recommendedRepair(finding),
|
|
60
|
+
verificationGuidance: verificationGuidance(finding, testCommands)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function buildAgentDiagnosis(scan) {
|
|
64
|
+
const ranked = (0, riskRanker_1.rankFindings)(scan.findings);
|
|
65
|
+
const groups = (0, findingCorrelator_1.correlateFindings)(ranked);
|
|
66
|
+
const topFindings = ranked.slice(0, 8);
|
|
67
|
+
const topIssues = topFindings.map((finding) => {
|
|
68
|
+
const group = groups.find((candidate) => candidate.findingIds.includes(finding.id));
|
|
69
|
+
const issue = findingToAgentIssue(finding, scan.testCommands);
|
|
70
|
+
if (group) {
|
|
71
|
+
issue.supportingEngines = group.supportingEngines;
|
|
72
|
+
issue.likelyRootCause = group.likelyRootCause;
|
|
73
|
+
issue.locations = group.locations;
|
|
74
|
+
}
|
|
75
|
+
return issue;
|
|
76
|
+
});
|
|
77
|
+
const recommendedOrder = topIssues.map((issue) => issue.id);
|
|
78
|
+
return {
|
|
79
|
+
completeness: scan.completeness,
|
|
80
|
+
summary: {
|
|
81
|
+
score: scan.score.overall,
|
|
82
|
+
mode: scan.mode,
|
|
83
|
+
planned: scan.completeness.planned,
|
|
84
|
+
completed: scan.completeness.completed,
|
|
85
|
+
findingCount: scan.findings.length,
|
|
86
|
+
blockerCount: scan.blockers.length,
|
|
87
|
+
topIssueCount: topIssues.length
|
|
88
|
+
},
|
|
89
|
+
topIssues,
|
|
90
|
+
rootCauseGroups: groups,
|
|
91
|
+
toolStatuses: scan.toolStatuses,
|
|
92
|
+
recoveryActions: scan.recoveryActions,
|
|
93
|
+
recommendedOrder,
|
|
94
|
+
agentPlan: scan.agentPlan
|
|
95
|
+
};
|
|
96
|
+
}
|
package/dist/core/config.d.ts
CHANGED
|
@@ -36,6 +36,14 @@ export type VibeDoctorConfig = {
|
|
|
36
36
|
deferredTools: string[];
|
|
37
37
|
/** Verify each tool resolves and runs before trusting its absence of findings. */
|
|
38
38
|
verifyToolsBeforeScan: boolean;
|
|
39
|
+
/** Resolve/provision engines into a VibeDoctor-owned cache instead of mutating the repo. */
|
|
40
|
+
managedTools: {
|
|
41
|
+
enabled: boolean;
|
|
42
|
+
/** Override for ~/.cache/vibedoctor. */
|
|
43
|
+
cacheDir?: string;
|
|
44
|
+
allowNetwork: boolean;
|
|
45
|
+
preferProjectLocal: boolean;
|
|
46
|
+
};
|
|
39
47
|
};
|
|
40
48
|
relevance: {
|
|
41
49
|
enabled: boolean;
|
|
@@ -120,6 +128,9 @@ export type VibeDoctorConfig = {
|
|
|
120
128
|
enabled: boolean;
|
|
121
129
|
};
|
|
122
130
|
};
|
|
131
|
+
flowAnalysis: {
|
|
132
|
+
enabled: boolean;
|
|
133
|
+
};
|
|
123
134
|
dpdp: {
|
|
124
135
|
enabled: boolean;
|
|
125
136
|
include: string[];
|
package/dist/core/config.js
CHANGED
|
@@ -62,7 +62,12 @@ exports.defaultConfig = {
|
|
|
62
62
|
onTimeout: "scoped_retry",
|
|
63
63
|
scopedRetryTimeoutSeconds: 60,
|
|
64
64
|
deferredTools: [],
|
|
65
|
-
verifyToolsBeforeScan: true
|
|
65
|
+
verifyToolsBeforeScan: true,
|
|
66
|
+
managedTools: {
|
|
67
|
+
enabled: true,
|
|
68
|
+
allowNetwork: true,
|
|
69
|
+
preferProjectLocal: true
|
|
70
|
+
}
|
|
66
71
|
},
|
|
67
72
|
relevance: {
|
|
68
73
|
enabled: true,
|
|
@@ -141,6 +146,9 @@ exports.defaultConfig = {
|
|
|
141
146
|
enabled: true
|
|
142
147
|
}
|
|
143
148
|
},
|
|
149
|
+
flowAnalysis: {
|
|
150
|
+
enabled: true
|
|
151
|
+
},
|
|
144
152
|
dpdp: {
|
|
145
153
|
enabled: true,
|
|
146
154
|
include: [],
|
|
@@ -284,6 +292,7 @@ function normalizeRawConfig(raw) {
|
|
|
284
292
|
const rawPrivacy = rawChecks?.privacy;
|
|
285
293
|
const rawPrivacyAi = (rawPrivacy?.ai ?? {});
|
|
286
294
|
const rawPresidio = (rawPrivacy?.presidio ?? {});
|
|
295
|
+
const rawFlow = (rawChecks?.flowAnalysis ?? rawChecks?.flow_analysis);
|
|
287
296
|
const rawDpdp = rawChecks?.dpdp;
|
|
288
297
|
const rawDpdpOrg = (rawDpdp?.organization ?? rawDpdp?.organisation ?? {});
|
|
289
298
|
return {
|
|
@@ -313,7 +322,8 @@ function normalizeRawConfig(raw) {
|
|
|
313
322
|
deferredTools: normalizeStringArray(rawRuntime.deferredTools ?? rawRuntime.deferred_tools, exports.defaultConfig.runtime.deferredTools),
|
|
314
323
|
verifyToolsBeforeScan: rawRuntime.verifyToolsBeforeScan ??
|
|
315
324
|
rawRuntime.verify_tools_before_scan ??
|
|
316
|
-
exports.defaultConfig.runtime.verifyToolsBeforeScan
|
|
325
|
+
exports.defaultConfig.runtime.verifyToolsBeforeScan,
|
|
326
|
+
managedTools: normalizeManagedTools(rawRuntime.managedTools ?? rawRuntime.managed_tools)
|
|
317
327
|
}
|
|
318
328
|
}
|
|
319
329
|
: {}),
|
|
@@ -492,6 +502,11 @@ function normalizeRawConfig(raw) {
|
|
|
492
502
|
}
|
|
493
503
|
}
|
|
494
504
|
: exports.defaultConfig.checks.privacy,
|
|
505
|
+
flowAnalysis: rawFlow
|
|
506
|
+
? {
|
|
507
|
+
enabled: rawFlow.enabled ?? exports.defaultConfig.checks.flowAnalysis.enabled
|
|
508
|
+
}
|
|
509
|
+
: exports.defaultConfig.checks.flowAnalysis,
|
|
495
510
|
dpdp: rawDpdp
|
|
496
511
|
? {
|
|
497
512
|
enabled: rawDpdp.enabled ?? exports.defaultConfig.checks.dpdp.enabled,
|
|
@@ -536,6 +551,20 @@ function normalizeRawConfig(raw) {
|
|
|
536
551
|
: {})
|
|
537
552
|
};
|
|
538
553
|
}
|
|
554
|
+
function normalizeManagedTools(raw) {
|
|
555
|
+
const defaults = exports.defaultConfig.runtime.managedTools;
|
|
556
|
+
if (!isRecord(raw)) {
|
|
557
|
+
return { ...defaults };
|
|
558
|
+
}
|
|
559
|
+
return {
|
|
560
|
+
enabled: raw.enabled ?? defaults.enabled,
|
|
561
|
+
cacheDir: raw.cacheDir ?? raw.cache_dir ?? defaults.cacheDir,
|
|
562
|
+
allowNetwork: raw.allowNetwork ?? raw.allow_network ?? defaults.allowNetwork,
|
|
563
|
+
preferProjectLocal: raw.preferProjectLocal ??
|
|
564
|
+
raw.prefer_project_local ??
|
|
565
|
+
defaults.preferProjectLocal
|
|
566
|
+
};
|
|
567
|
+
}
|
|
539
568
|
function normalizeTriState(value, fallback) {
|
|
540
569
|
if (value === true || value === "true" || value === "yes") {
|
|
541
570
|
return "true";
|
package/dist/core/engine.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AgentDiagnosis } from "./agentDiagnosis";
|
|
1
2
|
import { type AgentPolicy } from "../agentPack/policy";
|
|
2
3
|
import { type Finding, type FindingCategory } from "./finding";
|
|
3
4
|
import { type ScanMode } from "./scanPlanner";
|
|
@@ -8,6 +9,8 @@ import { type RelevanceReport } from "./relevance";
|
|
|
8
9
|
import { type SuppressionReport } from "./suppressions";
|
|
9
10
|
import { type ToolVerification } from "./toolVerification";
|
|
10
11
|
import { type PrivacyReviewSummary } from "./privacyReview";
|
|
12
|
+
declare const ALL_ADAPTERS: readonly [import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter, import("../adapters/shared").ToolAdapter];
|
|
13
|
+
export declare function getScanAdapters(): typeof ALL_ADAPTERS;
|
|
11
14
|
export type AgentPlanTarget = "generic" | "codex" | "copilot" | "claude" | "cursor";
|
|
12
15
|
export type AgentPlanTask = {
|
|
13
16
|
id: string;
|
|
@@ -89,6 +92,8 @@ export type ScanOutput = {
|
|
|
89
92
|
suppressedFindings: Finding[];
|
|
90
93
|
/** Tool-by-tool proof of what resolved and ran, with paths and versions. */
|
|
91
94
|
verifications: ToolVerification[];
|
|
95
|
+
/** Agent-first diagnosis: correlated, ranked, actionable. Present on live scans. */
|
|
96
|
+
diagnosis?: AgentDiagnosis;
|
|
92
97
|
};
|
|
93
98
|
export type SafeFixResult = {
|
|
94
99
|
before: ScanOutput;
|
|
@@ -129,7 +134,9 @@ export declare function createAgentPlan(scan: Pick<ScanOutput, "findings" | "sco
|
|
|
129
134
|
policy?: AgentPolicy;
|
|
130
135
|
target?: AgentPlanTarget;
|
|
131
136
|
}): AgentPlan;
|
|
132
|
-
export declare function runScan(root: string, mode?: ScanMode
|
|
137
|
+
export declare function runScan(root: string, mode?: ScanMode, options?: {
|
|
138
|
+
runtimeOptions?: import("./toolRuntime").ToolRuntimeOptions;
|
|
139
|
+
}): Promise<ScanOutput>;
|
|
133
140
|
export declare function retryTool(root: string, toolId: string, timeoutSeconds?: number): Promise<ToolRetryOutput>;
|
|
134
141
|
export declare function filterScanByCategories(scan: ScanOutput, categories: FindingCategory[], options?: FilterScanOptions): ScanOutput;
|
|
135
142
|
export declare function buildSummaryLines(scan: ScanOutput): string[];
|
package/dist/core/engine.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getScanAdapters = getScanAdapters;
|
|
3
4
|
exports.withReportingDefaults = withReportingDefaults;
|
|
4
5
|
exports.createAgentPlan = createAgentPlan;
|
|
5
6
|
exports.runScan = runScan;
|
|
@@ -15,6 +16,10 @@ const privacyDetector_1 = require("../adapters/privacyDetector");
|
|
|
15
16
|
const dpdp_1 = require("../adapters/dpdp");
|
|
16
17
|
const customRefactor_1 = require("../adapters/customRefactor");
|
|
17
18
|
const customDeadChain_1 = require("../adapters/customDeadChain");
|
|
19
|
+
const flowDoctor_1 = require("../adapters/flowDoctor");
|
|
20
|
+
const agentDiagnosis_1 = require("./agentDiagnosis");
|
|
21
|
+
const riskRanker_1 = require("./riskRanker");
|
|
22
|
+
const scanContext_1 = require("./scanContext");
|
|
18
23
|
const presidio_1 = require("../adapters/presidio");
|
|
19
24
|
const policy_1 = require("../agentPack/policy");
|
|
20
25
|
const baseline_1 = require("./baseline");
|
|
@@ -55,20 +60,12 @@ const ALL_ADAPTERS = [
|
|
|
55
60
|
presidio_1.presidioAdapter,
|
|
56
61
|
adapters_1.telemetryDetectorAdapter,
|
|
57
62
|
customLeftovers_1.customLeftoversAdapter,
|
|
58
|
-
customRefactor_1.customRefactorAdapter
|
|
63
|
+
customRefactor_1.customRefactorAdapter,
|
|
64
|
+
flowDoctor_1.flowDoctorAdapter
|
|
59
65
|
];
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
correctness: 2,
|
|
64
|
-
dependencies: 3,
|
|
65
|
-
privacy: 4,
|
|
66
|
-
dead_code: 5,
|
|
67
|
-
leftovers: 6,
|
|
68
|
-
refactor_readiness: 7,
|
|
69
|
-
maintainability: 8,
|
|
70
|
-
efficiency: 9
|
|
71
|
-
};
|
|
66
|
+
function getScanAdapters() {
|
|
67
|
+
return ALL_ADAPTERS;
|
|
68
|
+
}
|
|
72
69
|
const emptyRelevanceReport = {
|
|
73
70
|
enabled: false,
|
|
74
71
|
perTool: [],
|
|
@@ -132,36 +129,12 @@ function withReportingDefaults(partial) {
|
|
|
132
129
|
relevance: partial.relevance ?? emptyRelevanceReport,
|
|
133
130
|
suppressions: partial.suppressions ?? emptySuppressionReport,
|
|
134
131
|
suppressedFindings: partial.suppressedFindings ?? [],
|
|
135
|
-
verifications: partial.verifications ?? []
|
|
132
|
+
verifications: partial.verifications ?? [],
|
|
133
|
+
diagnosis: partial.diagnosis
|
|
136
134
|
};
|
|
137
135
|
}
|
|
138
136
|
function sortFindings(findings) {
|
|
139
|
-
return
|
|
140
|
-
const categoryDelta = categoryPriority[left.category] - categoryPriority[right.category];
|
|
141
|
-
if (categoryDelta !== 0) {
|
|
142
|
-
return categoryDelta;
|
|
143
|
-
}
|
|
144
|
-
const severityDelta = severityMap_1.severityRank[right.severity] - severityMap_1.severityRank[left.severity];
|
|
145
|
-
if (severityDelta !== 0) {
|
|
146
|
-
return severityDelta;
|
|
147
|
-
}
|
|
148
|
-
if (left.isNew !== right.isNew) {
|
|
149
|
-
return left.isNew ? -1 : 1;
|
|
150
|
-
}
|
|
151
|
-
const fileDelta = (left.file ?? "").localeCompare(right.file ?? "");
|
|
152
|
-
if (fileDelta !== 0) {
|
|
153
|
-
return fileDelta;
|
|
154
|
-
}
|
|
155
|
-
const lineDelta = (left.startLine ?? 0) - (right.startLine ?? 0);
|
|
156
|
-
if (lineDelta !== 0) {
|
|
157
|
-
return lineDelta;
|
|
158
|
-
}
|
|
159
|
-
const titleDelta = left.title.localeCompare(right.title);
|
|
160
|
-
if (titleDelta !== 0) {
|
|
161
|
-
return titleDelta;
|
|
162
|
-
}
|
|
163
|
-
return left.id.localeCompare(right.id);
|
|
164
|
-
});
|
|
137
|
+
return (0, riskRanker_1.rankFindings)(findings);
|
|
165
138
|
}
|
|
166
139
|
function summarizeFindings(findings) {
|
|
167
140
|
const ordered = sortFindings(findings);
|
|
@@ -301,7 +274,7 @@ function buildScanOutput(options) {
|
|
|
301
274
|
const summary = summarizeFindings(options.findings);
|
|
302
275
|
const policy = options.policy ?? policy_1.defaultAgentPolicy;
|
|
303
276
|
const recoveryActions = buildRecoveryActions(options.toolStatuses, options.skippedTools);
|
|
304
|
-
|
|
277
|
+
const output = {
|
|
305
278
|
root: options.root,
|
|
306
279
|
mode: options.mode,
|
|
307
280
|
score: options.score,
|
|
@@ -335,6 +308,8 @@ function buildScanOutput(options) {
|
|
|
335
308
|
suppressedFindings: options.suppressedFindings,
|
|
336
309
|
verifications: options.verifications
|
|
337
310
|
};
|
|
311
|
+
output.diagnosis = (0, agentDiagnosis_1.buildAgentDiagnosis)(output);
|
|
312
|
+
return output;
|
|
338
313
|
}
|
|
339
314
|
function firstUsefulLine(value) {
|
|
340
315
|
return value
|
|
@@ -391,6 +366,21 @@ function narrowContextToFiles(ctx, files) {
|
|
|
391
366
|
function commandText(command) {
|
|
392
367
|
return [command.cmd, ...command.args].join(" ");
|
|
393
368
|
}
|
|
369
|
+
/** A verification miss is still a result DPDP can reuse instead of launching the same missing tool again. */
|
|
370
|
+
function skippedForVerification(adapter, verification) {
|
|
371
|
+
return {
|
|
372
|
+
findings: [],
|
|
373
|
+
status: {
|
|
374
|
+
command: adapter.id,
|
|
375
|
+
stdout: "",
|
|
376
|
+
stderr: verification.reason,
|
|
377
|
+
exitCode: null,
|
|
378
|
+
durationMs: 0,
|
|
379
|
+
status: "skipped",
|
|
380
|
+
installHint: verification.remediation ?? adapter.installHint
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
}
|
|
394
384
|
async function runAdapter(adapter, ctx, deadline) {
|
|
395
385
|
if (adapter.runStandalone) {
|
|
396
386
|
return adapter.runStandalone(ctx);
|
|
@@ -490,12 +480,12 @@ async function retryWithNarrowedScope(adapter, ctx, originalTimeoutSeconds) {
|
|
|
490
480
|
* because the scan is about to invoke each tool anyway. `vibedoctor setup` does
|
|
491
481
|
* the same work at `execute` depth, where there is no later run to rely on.
|
|
492
482
|
*/
|
|
493
|
-
async function verifySelectedTools(root, adapterIds, config) {
|
|
483
|
+
async function verifySelectedTools(root, adapterIds, config, toolRuntime) {
|
|
494
484
|
const entries = adapterIds.map(toolRegistry_1.getToolEntry).filter((entry) => Boolean(entry));
|
|
495
485
|
if (!config.runtime.verifyToolsBeforeScan || entries.length === 0) {
|
|
496
486
|
return new Map();
|
|
497
487
|
}
|
|
498
|
-
const verifications = await (0, toolVerification_1.verifyTools)(entries, root, "resolve");
|
|
488
|
+
const verifications = await (0, toolVerification_1.verifyTools)(entries, root, "resolve", toolRuntime);
|
|
499
489
|
return new Map(verifications.map((verification) => [verification.id, verification]));
|
|
500
490
|
}
|
|
501
491
|
/** Derives the capability state for a tool that was selected and attempted. */
|
|
@@ -563,13 +553,14 @@ function reasonForCapability(id, state, run, verification, normalizationNote) {
|
|
|
563
553
|
return { reason: "Did not run." };
|
|
564
554
|
}
|
|
565
555
|
}
|
|
566
|
-
async function runScan(root, mode = "default") {
|
|
556
|
+
async function runScan(root, mode = "default", options) {
|
|
567
557
|
const [{ config, configPath }, { policy }] = await Promise.all([(0, config_1.loadConfig)(root), (0, policy_1.loadAgentPolicy)(root)]);
|
|
568
|
-
const
|
|
558
|
+
const scanContext = await (0, scanContext_1.buildScanContext)(root, config, mode, options?.runtimeOptions);
|
|
559
|
+
const project = scanContext.repo;
|
|
569
560
|
const plan = await (0, scanPlanner_1.createScanPlan)(project, config, [...ALL_ADAPTERS], mode);
|
|
570
|
-
const ctx = { root, project, config, scanMode: mode };
|
|
561
|
+
const ctx = { root, project, config, scanMode: mode, toolRuntime: scanContext.toolRuntime, scanContext };
|
|
571
562
|
const selectedAdapters = ALL_ADAPTERS.filter((adapter) => plan.adapterIds.includes(adapter.id));
|
|
572
|
-
const verifications = await verifySelectedTools(root, plan.adapterIds, config);
|
|
563
|
+
const verifications = await verifySelectedTools(root, plan.adapterIds, config, scanContext.toolRuntime);
|
|
573
564
|
// A tool that failed verification is not launched: doing so produces a
|
|
574
565
|
// confusing process error in place of the clear reason we already have.
|
|
575
566
|
const runnableAdapters = selectedAdapters.filter((adapter) => {
|
|
@@ -582,7 +573,17 @@ async function runScan(root, mode = "default") {
|
|
|
582
573
|
// findings/status instead of launching duplicate Semgrep and Presidio processes.
|
|
583
574
|
const adapterResults = await Promise.all(independentAdapters.map(async (adapter) => ({ adapter, result: await runAdapter(adapter, ctx, deadline) })));
|
|
584
575
|
if (runnableAdapters.some((adapter) => adapter.id === "dpdp")) {
|
|
585
|
-
const
|
|
576
|
+
const blockedShares = selectedAdapters
|
|
577
|
+
.filter((adapter) => adapter.id !== "dpdp" && !runnableAdapters.includes(adapter))
|
|
578
|
+
.map((adapter) => {
|
|
579
|
+
const verification = verifications.get(adapter.id);
|
|
580
|
+
return verification ? [adapter.id, skippedForVerification(adapter, verification)] : undefined;
|
|
581
|
+
})
|
|
582
|
+
.filter((entry) => Boolean(entry));
|
|
583
|
+
const sharedToolResults = Object.fromEntries([
|
|
584
|
+
...adapterResults.map(({ adapter, result }) => [adapter.id, result]),
|
|
585
|
+
...blockedShares
|
|
586
|
+
]);
|
|
586
587
|
const dpdpCtx = { ...ctx, sharedToolResults };
|
|
587
588
|
adapterResults.push({ adapter: dpdp_1.dpdpAdapter, result: await runAdapter(dpdp_1.dpdpAdapter, dpdpCtx, deadline) });
|
|
588
589
|
}
|
|
@@ -667,7 +668,7 @@ async function runScan(root, mode = "default") {
|
|
|
667
668
|
remediation: excluded.state === "deferred"
|
|
668
669
|
? `Remove ${excluded.id} from runtime.deferred_tools to run it again.`
|
|
669
670
|
: excluded.state === "not_selected"
|
|
670
|
-
? "Run `vibedoctor scan
|
|
671
|
+
? "Run `vibedoctor scan` for the full applicable diagnosis."
|
|
671
672
|
: undefined,
|
|
672
673
|
trust: "authoritative"
|
|
673
674
|
});
|
|
@@ -799,7 +800,8 @@ async function retryTool(root, toolId, timeoutSeconds) {
|
|
|
799
800
|
nextAction: "Run vibedoctor scan --full --report agent-json and request human review if the tool remains incomplete."
|
|
800
801
|
};
|
|
801
802
|
}
|
|
802
|
-
const
|
|
803
|
+
const scanContext = await (0, scanContext_1.buildScanContext)(root, config, "full");
|
|
804
|
+
const ctx = { root, project, config, scanMode: "full", toolRuntime: scanContext.toolRuntime, scanContext };
|
|
803
805
|
const seconds = timeoutSeconds ?? Math.max(config.runtime.defaultTimeoutSeconds, (config.runtime.toolTimeouts[toolId] ?? config.runtime.defaultTimeoutSeconds) * 2);
|
|
804
806
|
const command = adapter.buildScanCommand(ctx);
|
|
805
807
|
command.timeoutMs = seconds * 1000;
|
|
@@ -989,7 +991,8 @@ async function safeFix(root) {
|
|
|
989
991
|
const before = await runScan(root, "default");
|
|
990
992
|
const { config } = await (0, config_1.loadConfig)(root);
|
|
991
993
|
const project = await (0, projectDetector_1.detectProject)(root, config.paths.exclude);
|
|
992
|
-
const
|
|
994
|
+
const scanContext = await (0, scanContext_1.buildScanContext)(root, config, "default");
|
|
995
|
+
const ctx = { root, project, config, scanMode: "default", toolRuntime: scanContext.toolRuntime, scanContext };
|
|
993
996
|
const fixableAdapters = ALL_ADAPTERS.filter((adapter) => adapter.buildFixCommand && adapter.detect);
|
|
994
997
|
const results = [];
|
|
995
998
|
for (const adapter of fixableAdapters) {
|
package/dist/core/finding.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const FINDING_SOURCES: readonly ["ruff", "biome", "tsc", "pyright", "semgrep", "gitleaks", "osv-scanner", "knip", "vulture", "deptry", "jscpd", "lizard", "radon", "coverage.py", "vitest", "jest", "privacy-detector", "presidio", "privacy-ai-review", "telemetry-detector", "dpdp", "custom-leftovers", "custom-refactor", "custom-dead-chain"];
|
|
1
|
+
export declare const FINDING_SOURCES: readonly ["ruff", "biome", "tsc", "pyright", "semgrep", "gitleaks", "osv-scanner", "knip", "vulture", "deptry", "jscpd", "lizard", "radon", "coverage.py", "vitest", "jest", "privacy-detector", "presidio", "privacy-ai-review", "telemetry-detector", "dpdp", "custom-leftovers", "custom-refactor", "custom-dead-chain", "flow-doctor"];
|
|
2
2
|
export declare const FINDING_CATEGORIES: readonly ["security", "correctness", "dead_code", "leftovers", "maintainability", "dependencies", "tests", "privacy", "efficiency", "refactor_readiness"];
|
|
3
3
|
export type FindingSource = (typeof FINDING_SOURCES)[number];
|
|
4
4
|
export type FindingCategory = (typeof FINDING_CATEGORIES)[number];
|
package/dist/core/finding.js
CHANGED
|
@@ -37,7 +37,8 @@ exports.FINDING_SOURCES = [
|
|
|
37
37
|
"dpdp",
|
|
38
38
|
"custom-leftovers",
|
|
39
39
|
"custom-refactor",
|
|
40
|
-
"custom-dead-chain"
|
|
40
|
+
"custom-dead-chain",
|
|
41
|
+
"flow-doctor"
|
|
41
42
|
];
|
|
42
43
|
exports.FINDING_CATEGORIES = [
|
|
43
44
|
"security",
|
|
@@ -72,8 +73,12 @@ function normalizeFilePath(file, root) {
|
|
|
72
73
|
if (!file) {
|
|
73
74
|
return undefined;
|
|
74
75
|
}
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
// Scanners emit both separators (Biome on Windows even writes unescaped `\`
|
|
77
|
+
// into JSON). Reports always use POSIX-style relative paths, so treat `\` as
|
|
78
|
+
// a separator first rather than hoping `path.sep` matches the input.
|
|
79
|
+
const withPosix = file.replaceAll("\\", "/");
|
|
80
|
+
const asNative = withPosix.replaceAll("/", node_path_1.default.sep);
|
|
81
|
+
const relative = node_path_1.default.isAbsolute(asNative) ? node_path_1.default.relative(root, asNative) : asNative;
|
|
77
82
|
return relative.split(node_path_1.default.sep).join("/");
|
|
78
83
|
}
|
|
79
84
|
function stableSnippetHash(value) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Finding, FindingCategory, Severity } from "./finding";
|
|
2
|
+
export type FindingLocation = {
|
|
3
|
+
file?: string;
|
|
4
|
+
startLine?: number;
|
|
5
|
+
endLine?: number;
|
|
6
|
+
};
|
|
7
|
+
export type RootCauseGroup = {
|
|
8
|
+
id: string;
|
|
9
|
+
title: string;
|
|
10
|
+
severity: Severity;
|
|
11
|
+
category: FindingCategory;
|
|
12
|
+
findingIds: string[];
|
|
13
|
+
supportingEngines: string[];
|
|
14
|
+
likelyRootCause: string;
|
|
15
|
+
locations: FindingLocation[];
|
|
16
|
+
};
|
|
17
|
+
export declare function inferRootCause(finding: Finding): string;
|
|
18
|
+
export declare function correlateFindings(findings: Finding[]): RootCauseGroup[];
|
|
19
|
+
export declare function locationKeyForTests(finding: Finding): string | undefined;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inferRootCause = inferRootCause;
|
|
4
|
+
exports.correlateFindings = correlateFindings;
|
|
5
|
+
exports.locationKeyForTests = locationKeyForTests;
|
|
6
|
+
const severityMap_1 = require("../rules/severityMap");
|
|
7
|
+
function locationKey(finding) {
|
|
8
|
+
if (!finding.file || finding.startLine === undefined) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
return `${finding.file}:${finding.startLine}`;
|
|
12
|
+
}
|
|
13
|
+
function token(finding) {
|
|
14
|
+
return (finding.evidence?.toolRawId ?? finding.title).toLowerCase().replace(/\s+/g, " ").trim();
|
|
15
|
+
}
|
|
16
|
+
function sameProblem(left, right) {
|
|
17
|
+
if (left.id === right.id) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
const corroborated = left.corroboratedBy?.includes(right.source) || right.corroboratedBy?.includes(left.source);
|
|
21
|
+
if (left.category !== right.category) {
|
|
22
|
+
return Boolean(corroborated && left.file && left.file === right.file);
|
|
23
|
+
}
|
|
24
|
+
if (left.file && left.file === right.file) {
|
|
25
|
+
const lineClose = left.startLine !== undefined &&
|
|
26
|
+
right.startLine !== undefined &&
|
|
27
|
+
Math.abs(left.startLine - right.startLine) <= 2;
|
|
28
|
+
if (lineClose) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
if (token(left) && token(left) === token(right)) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (corroborated) {
|
|
36
|
+
return left.file === right.file;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
function pickCanonical(findings) {
|
|
41
|
+
return [...findings].sort((left, right) => {
|
|
42
|
+
const severityDelta = severityMap_1.severityRank[right.severity] - severityMap_1.severityRank[left.severity];
|
|
43
|
+
if (severityDelta !== 0) {
|
|
44
|
+
return severityDelta;
|
|
45
|
+
}
|
|
46
|
+
return left.id.localeCompare(right.id);
|
|
47
|
+
})[0];
|
|
48
|
+
}
|
|
49
|
+
function inferRootCause(finding) {
|
|
50
|
+
if (finding.source === "gitleaks") {
|
|
51
|
+
return "A secret or credential-like value is committed in source.";
|
|
52
|
+
}
|
|
53
|
+
if (finding.source === "osv-scanner") {
|
|
54
|
+
return "A declared dependency has a known advisory.";
|
|
55
|
+
}
|
|
56
|
+
if (finding.source === "flow-doctor") {
|
|
57
|
+
return finding.message;
|
|
58
|
+
}
|
|
59
|
+
if (finding.source === "tsc" || finding.source === "pyright") {
|
|
60
|
+
return "The type checker rejected this location.";
|
|
61
|
+
}
|
|
62
|
+
if (finding.category === "tests") {
|
|
63
|
+
return "A test suite reported a failure.";
|
|
64
|
+
}
|
|
65
|
+
return finding.message;
|
|
66
|
+
}
|
|
67
|
+
function correlateFindings(findings) {
|
|
68
|
+
const remaining = [...findings];
|
|
69
|
+
const groups = [];
|
|
70
|
+
while (remaining.length > 0) {
|
|
71
|
+
const seed = remaining.shift();
|
|
72
|
+
const group = [seed];
|
|
73
|
+
for (let index = remaining.length - 1; index >= 0; index -= 1) {
|
|
74
|
+
if (group.some((member) => sameProblem(member, remaining[index]))) {
|
|
75
|
+
group.push(remaining.splice(index, 1)[0]);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
groups.push(group);
|
|
79
|
+
}
|
|
80
|
+
return groups
|
|
81
|
+
.map((members, index) => {
|
|
82
|
+
const canonical = pickCanonical(members);
|
|
83
|
+
const engines = Array.from(new Set(members.map((member) => member.source))).sort();
|
|
84
|
+
const locations = members
|
|
85
|
+
.map((member) => ({ file: member.file, startLine: member.startLine, endLine: member.endLine }))
|
|
86
|
+
.filter((location, locationIndex, all) => {
|
|
87
|
+
const key = `${location.file ?? ""}:${location.startLine ?? ""}`;
|
|
88
|
+
return all.findIndex((candidate) => `${candidate.file ?? ""}:${candidate.startLine ?? ""}` === key) === locationIndex;
|
|
89
|
+
})
|
|
90
|
+
.sort((left, right) => `${left.file}:${left.startLine ?? 0}`.localeCompare(`${right.file}:${right.startLine ?? 0}`));
|
|
91
|
+
return {
|
|
92
|
+
id: `rcg-${String(index + 1).padStart(3, "0")}`,
|
|
93
|
+
title: canonical.title,
|
|
94
|
+
severity: canonical.severity,
|
|
95
|
+
category: canonical.category,
|
|
96
|
+
findingIds: members.map((member) => member.id).sort(),
|
|
97
|
+
supportingEngines: engines,
|
|
98
|
+
likelyRootCause: inferRootCause(canonical),
|
|
99
|
+
locations
|
|
100
|
+
};
|
|
101
|
+
})
|
|
102
|
+
.sort((left, right) => {
|
|
103
|
+
const severityDelta = severityMap_1.severityRank[right.severity] - severityMap_1.severityRank[left.severity];
|
|
104
|
+
if (severityDelta !== 0) {
|
|
105
|
+
return severityDelta;
|
|
106
|
+
}
|
|
107
|
+
return left.id.localeCompare(right.id);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function locationKeyForTests(finding) {
|
|
111
|
+
return locationKey(finding);
|
|
112
|
+
}
|
|
@@ -37,6 +37,7 @@ const DEFAULT_EVIDENCE_GRADE = {
|
|
|
37
37
|
"custom-leftovers": "observed",
|
|
38
38
|
"custom-refactor": "verified",
|
|
39
39
|
"custom-dead-chain": "heuristic",
|
|
40
|
+
"flow-doctor": "verified",
|
|
40
41
|
dpdp: "heuristic"
|
|
41
42
|
};
|
|
42
43
|
const VALID_CATEGORIES = new Set(finding_1.FINDING_CATEGORIES);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pinned managed-tool catalog.
|
|
3
|
+
*
|
|
4
|
+
* Adapters ask for `tool: "ruff"`; ToolRuntime maps that name onto a
|
|
5
|
+
* versioned, checksummed artifact in the VibeDoctor cache. Other engines plug
|
|
6
|
+
* into the same shape without changing adapters.
|
|
7
|
+
*/
|
|
8
|
+
export type ManagedArchiveKind = "zip" | "tar.gz" | "none";
|
|
9
|
+
export type ManagedArtifact = {
|
|
10
|
+
url: string;
|
|
11
|
+
sha256: string;
|
|
12
|
+
archive: ManagedArchiveKind;
|
|
13
|
+
/** File name of the executable inside the archive (or the copied file). */
|
|
14
|
+
binary: string;
|
|
15
|
+
};
|
|
16
|
+
export type ManagedToolSpec = {
|
|
17
|
+
id: string;
|
|
18
|
+
version: string;
|
|
19
|
+
artifacts: Record<string, ManagedArtifact>;
|
|
20
|
+
};
|
|
21
|
+
export declare const MANAGED_TOOLS: Record<string, ManagedToolSpec>;
|
|
22
|
+
export declare function isManagedTool(id: string): boolean;
|
|
23
|
+
export declare function getManagedTool(id: string): ManagedToolSpec | undefined;
|
|
24
|
+
export declare function currentPlatformKey(): string;
|
|
25
|
+
export declare function artifactFor(spec: ManagedToolSpec, platformKey?: string): ManagedArtifact | undefined;
|