@neuralaxis/vibedoctor 0.2.0 → 0.2.1

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.
Files changed (52) hide show
  1. package/README.md +86 -0
  2. package/dist/adapters/biome.js +135 -21
  3. package/dist/adapters/osvScanner.js +136 -17
  4. package/dist/adapters/presidio.js +3 -1
  5. package/dist/cli/commands/init.js +105 -50
  6. package/dist/cli/commands/privacyReview.js +3 -4
  7. package/dist/cli/commands/setup.d.ts +13 -17
  8. package/dist/cli/commands/setup.js +138 -200
  9. package/dist/core/capability.d.ts +92 -0
  10. package/dist/core/capability.js +122 -0
  11. package/dist/core/config.d.ts +36 -0
  12. package/dist/core/config.js +105 -3
  13. package/dist/core/credentialHeuristics.d.ts +28 -0
  14. package/dist/core/credentialHeuristics.js +179 -0
  15. package/dist/core/engine.d.ts +21 -0
  16. package/dist/core/engine.js +466 -85
  17. package/dist/core/executable.d.ts +18 -0
  18. package/dist/core/executable.js +137 -0
  19. package/dist/core/fileRole.d.ts +24 -0
  20. package/dist/core/fileRole.js +125 -0
  21. package/dist/core/finding.d.ts +124 -0
  22. package/dist/core/finding.js +62 -5
  23. package/dist/core/findingNormalizer.d.ts +33 -0
  24. package/dist/core/findingNormalizer.js +171 -0
  25. package/dist/core/projectDetector.d.ts +13 -0
  26. package/dist/core/projectDetector.js +100 -15
  27. package/dist/core/relevance.d.ts +87 -0
  28. package/dist/core/relevance.js +367 -0
  29. package/dist/core/scanPlanner.d.ts +12 -0
  30. package/dist/core/scanPlanner.js +61 -37
  31. package/dist/core/semverLite.d.ts +27 -0
  32. package/dist/core/semverLite.js +163 -0
  33. package/dist/core/suppressions.d.ts +96 -0
  34. package/dist/core/suppressions.js +302 -0
  35. package/dist/core/toolRegistry.d.ts +58 -0
  36. package/dist/core/toolRegistry.js +247 -0
  37. package/dist/core/toolRunner.d.ts +23 -2
  38. package/dist/core/toolRunner.js +61 -93
  39. package/dist/core/toolVerification.d.ts +87 -0
  40. package/dist/core/toolVerification.js +370 -0
  41. package/dist/dpdp/collectors/optionalScanners.js +120 -30
  42. package/dist/dpdp/findings.d.ts +33 -3
  43. package/dist/dpdp/findings.js +191 -4
  44. package/dist/dpdp/scan.js +2 -2
  45. package/dist/dpdp/scoring.d.ts +14 -4
  46. package/dist/dpdp/scoring.js +34 -8
  47. package/dist/dpdp/types.d.ts +19 -1
  48. package/dist/reporters/html.js +57 -13
  49. package/dist/reporters/json.js +7 -1
  50. package/dist/reporters/markdown.js +46 -4
  51. package/dist/reporters/sarif.js +54 -5
  52. package/package.json +1 -1
@@ -1,11 +1,41 @@
1
- import type { Finding } from "../core/finding";
2
- import type { ControlResult, EvidenceItem } from "./types";
1
+ import type { DataFlowStep, EvidenceGrade, Finding, FindingRemediation } from "../core/finding";
2
+ import type { ControlResult, DpdpCapabilityStatus, EvidenceItem, VerificationClass } from "./types";
3
3
  /**
4
4
  * Build a stable, masked snippet for fingerprinting.
5
5
  * When present, fingerprintFinding omits startLine so line-only moves do not thrash baselines.
6
6
  */
7
7
  export declare function stableDpdpFindingSnippet(result: ControlResult, primary: EvidenceItem | undefined): string;
8
- export declare function controlResultsToFindings(results: ControlResult[], evidenceById: Map<string, EvidenceItem>): Finding[];
8
+ /**
9
+ * Maps how a control was checked onto how strongly its evidence supports the
10
+ * claim.
11
+ *
12
+ * A DPDP finding could previously carry critical severity whether it came from
13
+ * following a data path or from a variable name that looked like an identifier.
14
+ * A readiness figure built on that mixture reads as stronger than the evidence
15
+ * behind it, which is worse than a lower, honest one.
16
+ */
17
+ export declare function evidenceGradeForControl(verificationClass: VerificationClass, primary: EvidenceItem | undefined): EvidenceGrade;
18
+ /**
19
+ * Whether a control that observed nothing means the control is missing, or only
20
+ * that static analysis could not settle the question.
21
+ *
22
+ * These need different responses — one is a gap to fix, the other a gap in
23
+ * coverage — and presenting them identically is what let a readiness score imply
24
+ * more than the scan established.
25
+ */
26
+ export declare function absenceClaimForControl(result: ControlResult, capabilities: DpdpCapabilityStatus[]): Finding["absenceClaim"];
27
+ /**
28
+ * Assembles the data path behind a control from its own evidence items, ordered
29
+ * source to sink. Each step carries its own grade, so a traced storage write and
30
+ * an inferred processor hop are not presented as equally established.
31
+ */
32
+ export declare function buildDataFlow(result: ControlResult, evidenceById: Map<string, EvidenceItem>): DataFlowStep[] | undefined;
33
+ /**
34
+ * Works out what kind of change a remediation actually is, so the finding
35
+ * reaches whoever can act on it rather than defaulting to an engineer.
36
+ */
37
+ export declare function remediationForControl(result: ControlResult): FindingRemediation | undefined;
38
+ export declare function controlResultsToFindings(results: ControlResult[], evidenceById: Map<string, EvidenceItem>, capabilities?: DpdpCapabilityStatus[]): Finding[];
9
39
  /**
10
40
  * Sync control `isNew` from baselined findings.
11
41
  * Controls without a finding (not VIOLATED/PARTIAL/ERROR) keep isNew=false after baseline is applied
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stableDpdpFindingSnippet = stableDpdpFindingSnippet;
4
+ exports.evidenceGradeForControl = evidenceGradeForControl;
5
+ exports.absenceClaimForControl = absenceClaimForControl;
6
+ exports.buildDataFlow = buildDataFlow;
7
+ exports.remediationForControl = remediationForControl;
4
8
  exports.controlResultsToFindings = controlResultsToFindings;
5
9
  exports.syncControlIsNewFromFindings = syncControlIsNewFromFindings;
6
10
  const STATUS_TO_INCLUDE = new Set(["VIOLATED", "PARTIAL", "ERROR"]);
@@ -20,7 +24,156 @@ function stableDpdpFindingSnippet(result, primary) {
20
24
  .join("|")
21
25
  .slice(0, 400);
22
26
  }
23
- function controlResultsToFindings(results, evidenceById) {
27
+ /**
28
+ * Maps how a control was checked onto how strongly its evidence supports the
29
+ * claim.
30
+ *
31
+ * A DPDP finding could previously carry critical severity whether it came from
32
+ * following a data path or from a variable name that looked like an identifier.
33
+ * A readiness figure built on that mixture reads as stronger than the evidence
34
+ * behind it, which is worse than a lower, honest one.
35
+ */
36
+ function evidenceGradeForControl(verificationClass, primary) {
37
+ if (verificationClass === "DETERMINISTIC") {
38
+ return primary?.certainty === "confirmed" ? "verified" : "observed";
39
+ }
40
+ if (verificationClass === "TECHNICAL_SIGNAL") {
41
+ // A signal anchored to a real file and line was observed; one inferred from
42
+ // shape alone is a heuristic, however plausible.
43
+ if (primary?.certainty === "confirmed" && primary.file) {
44
+ return "observed";
45
+ }
46
+ return "heuristic";
47
+ }
48
+ if (verificationClass === "DECLARED_EVIDENCE") {
49
+ return "unproven";
50
+ }
51
+ return "unproven";
52
+ }
53
+ /**
54
+ * Whether a control that observed nothing means the control is missing, or only
55
+ * that static analysis could not settle the question.
56
+ *
57
+ * These need different responses — one is a gap to fix, the other a gap in
58
+ * coverage — and presenting them identically is what let a readiness score imply
59
+ * more than the scan established.
60
+ */
61
+ function absenceClaimForControl(result, capabilities) {
62
+ if (!result.applicable || result.status === "NOT_APPLICABLE") {
63
+ return "not_applicable";
64
+ }
65
+ // A scanner that did not run cannot have failed to find something.
66
+ const unavailable = capabilities.filter((capability) => capability.status !== "available");
67
+ if (unavailable.length > 0 && result.verificationClass === "TECHNICAL_SIGNAL") {
68
+ return "not_statically_provable";
69
+ }
70
+ if (result.verificationClass === "HUMAN_REVIEW" || result.verificationClass === "DECLARED_EVIDENCE") {
71
+ return "not_statically_provable";
72
+ }
73
+ return result.status === "VIOLATED" ? "control_absent" : "not_statically_provable";
74
+ }
75
+ /**
76
+ * Classifies an evidence item's place in a data path. The mapping is by evidence
77
+ * kind rather than by guesswork, so a step only appears when something concrete
78
+ * was recorded at that stage.
79
+ */
80
+ function flowKindFor(item) {
81
+ const kind = item.kind;
82
+ if (/collect|input|form|field|schema|request|param/i.test(kind)) {
83
+ return "source";
84
+ }
85
+ if (/storage|store|cookie|database|table|column|persist|cache/i.test(kind)) {
86
+ return "store";
87
+ }
88
+ if (/transfer|processor|third_party|vendor|llm|model|ai|api_call/i.test(kind)) {
89
+ return "processor";
90
+ }
91
+ if (/log|export|sink|telemetry|analytics|email|report/i.test(kind)) {
92
+ return "sink";
93
+ }
94
+ if (/transform|mask|redact|hash|encrypt/i.test(kind)) {
95
+ return "transform";
96
+ }
97
+ return undefined;
98
+ }
99
+ const FLOW_ORDER = {
100
+ source: 0,
101
+ transform: 1,
102
+ store: 2,
103
+ processor: 3,
104
+ sink: 4
105
+ };
106
+ /**
107
+ * Assembles the data path behind a control from its own evidence items, ordered
108
+ * source to sink. Each step carries its own grade, so a traced storage write and
109
+ * an inferred processor hop are not presented as equally established.
110
+ */
111
+ function buildDataFlow(result, evidenceById) {
112
+ const steps = [];
113
+ for (const id of result.evidenceIds) {
114
+ const item = evidenceById.get(id);
115
+ if (!item) {
116
+ continue;
117
+ }
118
+ const kind = flowKindFor(item);
119
+ if (!kind) {
120
+ continue;
121
+ }
122
+ steps.push({
123
+ kind,
124
+ label: item.field ?? item.symbol ?? item.summary.slice(0, 80),
125
+ file: item.file,
126
+ startLine: item.line,
127
+ evidenceGrade: item.certainty === "confirmed" && item.file ? "observed" : item.certainty === "declared" ? "unproven" : "heuristic",
128
+ detail: item.summary
129
+ });
130
+ }
131
+ if (steps.length < 2) {
132
+ // A single step is not a path; the finding's own location already says where
133
+ // it is, and calling one point a "flow" would overstate the evidence.
134
+ return undefined;
135
+ }
136
+ return steps.sort((left, right) => FLOW_ORDER[left.kind] - FLOW_ORDER[right.kind]);
137
+ }
138
+ /**
139
+ * Works out what kind of change a remediation actually is, so the finding
140
+ * reaches whoever can act on it rather than defaulting to an engineer.
141
+ */
142
+ function remediationForControl(result) {
143
+ if (!result.remediation) {
144
+ return undefined;
145
+ }
146
+ // Domains whose controls are satisfied by a documented decision or process
147
+ // rather than by code. Routing these to an engineer produces a task nobody can
148
+ // close.
149
+ const policyDomains = new Set([
150
+ "grievance_handling",
151
+ "nomination",
152
+ "significant_data_fiduciary",
153
+ "exemptions_and_applicability",
154
+ "breach_preparedness",
155
+ "notice"
156
+ ]);
157
+ const kind = result.verificationClass === "HUMAN_REVIEW" || result.verificationClass === "DECLARED_EVIDENCE"
158
+ ? "human_review"
159
+ : policyDomains.has(result.domain)
160
+ ? "policy"
161
+ : /config|setting|environment|flag|header|policy file/i.test(result.remediation)
162
+ ? "config"
163
+ : "code";
164
+ return {
165
+ kind,
166
+ component: result.controlId,
167
+ steps: [result.remediation, ...(result.humanReviewQuestion ? [`Confirm with an owner: ${result.humanReviewQuestion}`] : [])],
168
+ requiredEvidence: result.verificationClass === "DETERMINISTIC"
169
+ ? "A rerun of `vibedoctor dpdp scan` showing this control verified."
170
+ : result.verificationClass === "TECHNICAL_SIGNAL"
171
+ ? "Code changes plus a rerun, or a declared-evidence entry recording the decision."
172
+ : `A signed-off entry in the declared-evidence file (${result.controlId}).`,
173
+ requiresHumanDecision: kind === "human_review" || kind === "policy"
174
+ };
175
+ }
176
+ function controlResultsToFindings(results, evidenceById, capabilities = []) {
24
177
  const findings = [];
25
178
  for (const result of results) {
26
179
  if (!STATUS_TO_INCLUDE.has(result.status)) {
@@ -35,6 +188,22 @@ function controlResultsToFindings(results, evidenceById) {
35
188
  ? "high"
36
189
  : result.severity;
37
190
  const snippet = primary?.snippet ?? stableDpdpFindingSnippet(result, primary);
191
+ const evidenceGrade = evidenceGradeForControl(result.verificationClass, primary);
192
+ const absenceClaim = absenceClaimForControl(result, capabilities);
193
+ const dataFlow = buildDataFlow(result, evidenceById);
194
+ // State the strength of the claim in the message itself. A reader scanning a
195
+ // list should not have to open the JSON to learn that a "critical" item rests
196
+ // on a naming heuristic.
197
+ const gradeNote = evidenceGrade === "verified"
198
+ ? "Verified from code."
199
+ : evidenceGrade === "observed"
200
+ ? "Observed at a specific location; its meaning is inferred."
201
+ : evidenceGrade === "heuristic"
202
+ ? "Heuristic signal: inferred from names or shape, not from a traced code path."
203
+ : "Not established from code; needs human confirmation.";
204
+ const absenceNote = absenceClaim === "not_statically_provable"
205
+ ? " This scan could not prove the control is absent, only that it was not observed."
206
+ : "";
38
207
  findings.push({
39
208
  id: `dpdp:${result.controlId}:${result.status}:${primary?.file ?? "repo"}:${primary?.line ?? 0}`,
40
209
  source: "dpdp",
@@ -42,14 +211,25 @@ function controlResultsToFindings(results, evidenceById) {
42
211
  severity,
43
212
  confidence: result.confidence,
44
213
  title: `DPDP ${result.status}: ${result.title}`,
45
- message: result.explanation,
214
+ message: `${result.explanation} ${gradeNote}${absenceNote}`,
46
215
  file: primary?.file,
47
216
  startLine: primary?.line,
48
217
  isNew: result.isNew,
49
218
  isAutofixable: false,
50
219
  safeToAutofix: false,
51
220
  agentInstruction: result.remediation,
52
- tags: ["dpdp", result.controlId, result.domain, result.status.toLowerCase(), result.verificationClass.toLowerCase()],
221
+ evidenceGrade,
222
+ absenceClaim,
223
+ dataFlow,
224
+ remediation: remediationForControl(result),
225
+ tags: [
226
+ "dpdp",
227
+ result.controlId,
228
+ result.domain,
229
+ result.status.toLowerCase(),
230
+ result.verificationClass.toLowerCase(),
231
+ `evidence:${evidenceGrade}`
232
+ ],
53
233
  evidence: {
54
234
  detector: "dpdp",
55
235
  // Always set snippet so fingerprints prefer content hash over line number
@@ -57,7 +237,14 @@ function controlResultsToFindings(results, evidenceById) {
57
237
  fieldPath: primary?.field,
58
238
  matchedPattern: result.controlId,
59
239
  detectionPath: result.verificationClass,
60
- reasons: [result.explanation, ...(result.limitations ?? [])],
240
+ reasons: [
241
+ result.explanation,
242
+ gradeNote,
243
+ ...(absenceClaim === "not_statically_provable"
244
+ ? ["Absence of the control was not proven; it was not observed."]
245
+ : []),
246
+ ...(result.limitations ?? [])
247
+ ],
61
248
  recommendedAction: result.remediation,
62
249
  rationale: result.humanReviewQuestion,
63
250
  entityType: primary?.dataCategory,
package/dist/dpdp/scan.js CHANGED
@@ -99,14 +99,14 @@ async function runDpdpScan(root, mode = "full", options = {}) {
99
99
  controlResults = (0, evaluators_1.attachDeclaredEvidenceIds)(controlResults, declared);
100
100
  const generatedAt = new Date().toISOString();
101
101
  const evidenceById = new Map(evidence.map((item) => [item.id, item]));
102
- let findings = (0, findings_1.controlResultsToFindings)(controlResults, evidenceById);
102
+ let findings = (0, findings_1.controlResultsToFindings)(controlResults, evidenceById, capabilities);
103
103
  // Apply shared baseline fingerprints, then sync control isNew from findings.
104
104
  if (config.baseline.enabled) {
105
105
  const baseline = await (0, baseline_1.loadBaseline)(root, config.baseline.file);
106
106
  findings = (0, finding_1.applyBaseline)(findings, new Set(baseline.findings.map((entry) => entry.fingerprint)));
107
107
  }
108
108
  controlResults = (0, findings_1.syncControlIsNewFromFindings)(controlResults, findings, config.baseline.enabled);
109
- const scores = (0, scoring_1.buildDpdpScores)(controlResults);
109
+ const scores = (0, scoring_1.buildDpdpScores)(controlResults, capabilities);
110
110
  const dataMap = (0, dataMap_1.buildPersonalDataMap)(signals, evidence, controlResults, generatedAt);
111
111
  const reviewQueue = (0, reviewQueue_1.buildReviewQueue)(controlResults);
112
112
  const fixNext = controlResults
@@ -1,5 +1,5 @@
1
1
  import type { Severity } from "../core/finding";
2
- import type { ControlResult, ControlStatusCounts, DpdpScores } from "./types";
2
+ import type { ControlResult, ControlStatusCounts, DpdpCapabilityStatus, DpdpScores } from "./types";
3
3
  /**
4
4
  * Controls that expect an implementation signal when personal data is processed.
5
5
  * NOT_OBSERVED on these is weak posture (missing expected control), not a clean bill of health.
@@ -12,8 +12,16 @@ export declare const GAP_CONTROL_EVALUATORS: Set<string>;
12
12
  export declare function isPositiveControl(control: ControlResult): boolean;
13
13
  export declare function isGapControl(control: ControlResult): boolean;
14
14
  export declare function countStatuses(controls: ControlResult[]): ControlStatusCounts;
15
+ /**
16
+ * Whether the scanners a control depends on actually ran.
17
+ *
18
+ * "Nothing bad was found" and "nothing looked" produce the same control status,
19
+ * and a gap detector's silence was credited at 0.85 either way. That let a
20
+ * posture score climb because a scanner was missing, which is exactly backwards.
21
+ */
22
+ export declare function hasSupportingCoverage(capabilities: DpdpCapabilityStatus[]): boolean;
15
23
  /** Points contributed by one control status toward technical posture (0–1). */
16
- export declare function posturePointsForControl(control: ControlResult): number;
24
+ export declare function posturePointsForControl(control: ControlResult, coverageComplete?: boolean): number;
17
25
  /**
18
26
  * Technical posture score from applicable technically observable controls only.
19
27
  * NOT a legal compliance percentage.
@@ -21,11 +29,13 @@ export declare function posturePointsForControl(control: ControlResult): number;
21
29
  * Scoring table:
22
30
  * - VERIFIED 1.0 · PARTIAL 0.5 · VIOLATED 0.0 · ERROR 0.15 · NEEDS_CONTEXT 0.4
23
31
  * - NOT_OBSERVED: 0.25 (positive control), 0.85 (gap detector), 0.7 (other)
32
+ * - When supporting scanners did not run, unobserved controls score 0.4 instead,
33
+ * because their silence carries no information.
24
34
  */
25
- export declare function computeTechnicalPostureScore(controls: ControlResult[]): number;
35
+ export declare function computeTechnicalPostureScore(controls: ControlResult[], capabilities?: DpdpCapabilityStatus[]): number;
26
36
  /**
27
37
  * Evidence completeness: share of applicable controls that have evidence or are verified/violated/partial.
28
38
  */
29
39
  export declare function computeEvidenceCompleteness(controls: ControlResult[]): number;
30
40
  export declare function openRiskBySeverity(controls: ControlResult[]): Record<Severity, number>;
31
- export declare function buildDpdpScores(controls: ControlResult[]): DpdpScores;
41
+ export declare function buildDpdpScores(controls: ControlResult[], capabilities?: DpdpCapabilityStatus[]): DpdpScores;
@@ -4,6 +4,7 @@ exports.GAP_CONTROL_EVALUATORS = exports.POSITIVE_CONTROL_EVALUATORS = void 0;
4
4
  exports.isPositiveControl = isPositiveControl;
5
5
  exports.isGapControl = isGapControl;
6
6
  exports.countStatuses = countStatuses;
7
+ exports.hasSupportingCoverage = hasSupportingCoverage;
7
8
  exports.posturePointsForControl = posturePointsForControl;
8
9
  exports.computeTechnicalPostureScore = computeTechnicalPostureScore;
9
10
  exports.computeEvidenceCompleteness = computeEvidenceCompleteness;
@@ -117,8 +118,22 @@ function countStatuses(controls) {
117
118
  counts.unresolved = counts.violated + counts.partial + counts.needsContext + counts.error;
118
119
  return counts;
119
120
  }
121
+ /**
122
+ * Whether the scanners a control depends on actually ran.
123
+ *
124
+ * "Nothing bad was found" and "nothing looked" produce the same control status,
125
+ * and a gap detector's silence was credited at 0.85 either way. That let a
126
+ * posture score climb because a scanner was missing, which is exactly backwards.
127
+ */
128
+ function hasSupportingCoverage(capabilities) {
129
+ const optional = capabilities.filter((capability) => capability.id === "presidio" || capability.id === "semgrep");
130
+ if (optional.length === 0) {
131
+ return true;
132
+ }
133
+ return optional.some((capability) => capability.status === "available");
134
+ }
120
135
  /** Points contributed by one control status toward technical posture (0–1). */
121
- function posturePointsForControl(control) {
136
+ function posturePointsForControl(control, coverageComplete = true) {
122
137
  switch (control.status) {
123
138
  case "VERIFIED":
124
139
  return 1;
@@ -137,10 +152,12 @@ function posturePointsForControl(control) {
137
152
  return 0.25;
138
153
  }
139
154
  if (isGapControl(control)) {
140
- return 0.85;
155
+ // Silence only earns credit when something was actually looking. Without
156
+ // the supporting scanners it is an unknown, scored like NEEDS_CONTEXT.
157
+ return coverageComplete ? 0.85 : 0.4;
141
158
  }
142
159
  // Inventory, processors, cross-border, SDF, etc. — neutral-good silence
143
- return 0.7;
160
+ return coverageComplete ? 0.7 : 0.4;
144
161
  default:
145
162
  return 0.5;
146
163
  }
@@ -152,8 +169,10 @@ function posturePointsForControl(control) {
152
169
  * Scoring table:
153
170
  * - VERIFIED 1.0 · PARTIAL 0.5 · VIOLATED 0.0 · ERROR 0.15 · NEEDS_CONTEXT 0.4
154
171
  * - NOT_OBSERVED: 0.25 (positive control), 0.85 (gap detector), 0.7 (other)
172
+ * - When supporting scanners did not run, unobserved controls score 0.4 instead,
173
+ * because their silence carries no information.
155
174
  */
156
- function computeTechnicalPostureScore(controls) {
175
+ function computeTechnicalPostureScore(controls, capabilities = []) {
157
176
  const observable = controls.filter((control) => control.applicable &&
158
177
  control.status !== "NOT_APPLICABLE" &&
159
178
  control.status !== "SKIPPED" &&
@@ -161,9 +180,10 @@ function computeTechnicalPostureScore(controls) {
161
180
  if (observable.length === 0) {
162
181
  return 100;
163
182
  }
183
+ const coverageComplete = hasSupportingCoverage(capabilities);
164
184
  let points = 0;
165
185
  for (const control of observable) {
166
- points += posturePointsForControl(control);
186
+ points += posturePointsForControl(control, coverageComplete);
167
187
  }
168
188
  return Math.max(0, Math.min(100, Math.round((points / observable.length) * 100)));
169
189
  }
@@ -196,14 +216,20 @@ function openRiskBySeverity(controls) {
196
216
  }
197
217
  return counts;
198
218
  }
199
- function buildDpdpScores(controls) {
219
+ function buildDpdpScores(controls, capabilities = []) {
220
+ const coverageComplete = hasSupportingCoverage(capabilities);
221
+ const missing = capabilities
222
+ .filter((capability) => capability.status !== "available")
223
+ .map((capability) => capability.id);
200
224
  return {
201
- technicalPostureScore: computeTechnicalPostureScore(controls),
225
+ technicalPostureScore: computeTechnicalPostureScore(controls, capabilities),
202
226
  evidenceCompletenessPercent: computeEvidenceCompleteness(controls),
203
227
  openRiskBySeverity: openRiskBySeverity(controls),
204
228
  statusCounts: countStatuses(controls),
205
229
  labels: {
206
- technicalPosture: "DPDP technical posture (not legal compliance)",
230
+ technicalPosture: coverageComplete
231
+ ? "DPDP technical posture (not legal compliance)"
232
+ : `DPDP technical posture — reduced coverage, ${missing.join(" and ")} did not run (not legal compliance)`,
207
233
  evidenceCompleteness: "Evidence completeness (technical observability)",
208
234
  openRisk: "Open technical risk counts by severity"
209
235
  }
@@ -230,7 +230,12 @@ export type DpdpScores = {
230
230
  openRiskBySeverity: Record<Severity, number>;
231
231
  statusCounts: ControlStatusCounts;
232
232
  labels: {
233
- technicalPosture: "DPDP technical posture (not legal compliance)";
233
+ /**
234
+ * Names the figure and, when supporting scanners did not run, says so in the
235
+ * label itself — a posture number quoted without its coverage caveat is the
236
+ * thing that overstates the evidence.
237
+ */
238
+ technicalPosture: string;
234
239
  evidenceCompleteness: "Evidence completeness (technical observability)";
235
240
  openRisk: "Open technical risk counts by severity";
236
241
  };
@@ -249,6 +254,19 @@ export type DpdpCapabilityStatus = {
249
254
  id: string;
250
255
  status: "available" | "skipped" | "error";
251
256
  message?: string;
257
+ /**
258
+ * Which decision produced this status. "Skipped" previously covered opting
259
+ * out, having nothing in scope, and not being installed — three situations with
260
+ * nothing in common, so a user could not tell whether a scanner they had
261
+ * installed was actually contributing evidence.
262
+ */
263
+ cause?: "opted_out" | "disabled" | "quick_mode" | "nothing_in_scope" | "not_installed" | "not_applicable" | "failed" | "timed_out" | "ran";
264
+ /** What to change to make this capability available. */
265
+ remediation?: string;
266
+ /** Absolute path or interpreter that answered, when the capability did run. */
267
+ resolvedVia?: string;
268
+ /** How many signals this capability contributed to the evidence ledger. */
269
+ signalsContributed?: number;
252
270
  };
253
271
  export type DpdpScanResult = {
254
272
  version: 1;
@@ -1,6 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.renderHtmlReport = renderHtmlReport;
4
+ const capability_1 = require("../core/capability");
5
+ const relevance_1 = require("../core/relevance");
6
+ const suppressions_1 = require("../core/suppressions");
7
+ function formatDuration(durationMs) {
8
+ if (durationMs === undefined) {
9
+ return "";
10
+ }
11
+ return durationMs >= 1000 ? `${(durationMs / 1000).toFixed(1)}s` : `${durationMs}ms`;
12
+ }
13
+ function formatLocation(finding) {
14
+ if (!finding.file) {
15
+ return "";
16
+ }
17
+ const line = finding.startLine ? `:${finding.startLine}` : "";
18
+ const column = finding.startLine && finding.startColumn ? `:${finding.startColumn}` : "";
19
+ return `${finding.file}${line}${column}`;
20
+ }
4
21
  function renderHtmlReport(scan) {
5
22
  const severityColor = (sev) => {
6
23
  if (sev === "critical")
@@ -15,7 +32,7 @@ function renderHtmlReport(scan) {
15
32
  if (!items.length)
16
33
  return "";
17
34
  const lis = items
18
- .map((f) => `<li style="margin-bottom:8px"><strong style="color:${severityColor(f.severity)}">${escapeHtml(f.title)}</strong> <span style="color:#6b7280">(${f.severity}, ${f.confidence})</span>${f.file ? ` <code>${escapeHtml(f.file)}${f.startLine ? ":" + f.startLine : ""}</code>` : ""}<br><span>${escapeHtml(f.message)}</span></li>`)
35
+ .map((f) => `<li style="margin-bottom:8px"><strong style="color:${severityColor(f.severity)}">${escapeHtml(f.title)}</strong> <span style="color:#6b7280">(${f.severity}, ${f.confidence})</span>${f.file ? ` <code>${escapeHtml(formatLocation(f))}</code>` : ""}<br><span>${escapeHtml(f.message)}</span></li>`)
19
36
  .join("");
20
37
  return `<h3>${title} (${items.length})</h3><ul style="padding-left:20px">${lis}</ul>`;
21
38
  };
@@ -28,6 +45,27 @@ function renderHtmlReport(scan) {
28
45
  return `<h3>${label}</h3><ul>${lis}</ul>`;
29
46
  };
30
47
  const errored = scan.toolStatuses.filter((t) => t.status === "error" || t.status === "timeout");
48
+ const capabilitySection = () => {
49
+ if (!scan.capabilityMatrix.tools.length)
50
+ return "";
51
+ const rows = scan.capabilityMatrix.tools
52
+ .map((tool) => `<tr><td><strong>${escapeHtml(tool.id)}</strong></td><td>${escapeHtml((0, capability_1.capabilityStateLabel)(tool.state))}</td><td>${tool.findingsSurfaced}/${tool.findingsReported}</td><td>${escapeHtml(formatDuration(tool.durationMs))}</td><td>${escapeHtml(tool.reason)}</td></tr>`)
53
+ .join("");
54
+ const remediations = scan.capabilityMatrix.tools.filter((tool) => tool.remediation && (0, capability_1.isCoverageGap)(tool));
55
+ const restore = remediations.length
56
+ ? `<h4>To restore coverage</h4><ul>${remediations
57
+ .map((tool) => `<li><strong>${escapeHtml(tool.id)}</strong> — ${escapeHtml(tool.remediation)}</li>`)
58
+ .join("")}</ul>`
59
+ : "";
60
+ return `<div class="section"><h3>Tool coverage</h3><table><thead><tr><th>Tool</th><th>State</th><th>Findings shown/reported</th><th>Time</th><th>Detail</th></tr></thead><tbody>${rows}</tbody></table>${restore}</div>`;
61
+ };
62
+ const lineSection = (title, sectionLines) => {
63
+ if (!sectionLines.length)
64
+ return "";
65
+ return `<div class="section"><h3>${escapeHtml(title)}</h3><ul>${sectionLines
66
+ .map((line) => `<li>${escapeHtml(line.replace(/^- /, ""))}</li>`)
67
+ .join("")}</ul></div>`;
68
+ };
31
69
  return `<!doctype html>
32
70
  <html>
33
71
  <head>
@@ -43,37 +81,43 @@ function renderHtmlReport(scan) {
43
81
  ul { margin: 8px 0; }
44
82
  .section { margin-top: 24px; }
45
83
  .meta { color: #6b7280; font-size: 0.85em; }
84
+ table { border-collapse: collapse; width: 100%; font-size: 0.9em; }
85
+ th, td { border-bottom: 1px solid #e5e7eb; padding: 6px 8px; text-align: left; vertical-align: top; }
86
+ th { color: #374151; font-weight: 600; }
46
87
  </style>
47
88
  </head>
48
89
  <body>
49
90
  <h1>VibeDoctor Health Report</h1>
50
91
  <div class="meta">Root: <code>${escapeHtml(scan.root)}</code> &middot; Mode: ${scan.mode} &middot; Generated for agents &amp; humans</div>
51
92
 
52
- <div class="score">Health: ${scan.score.overall}/100 — ${scan.completeness.status.toUpperCase()} ${scan.score.overall >= 85 ? "✅" : "⚠️"}</div>
53
- <div class="meta">Scan coverage: ${scan.completeness.completed}/${scan.completeness.planned} checks completed.${scan.completeness.comparable ? "" : " This score is not comparable to a complete scan."}</div>
93
+ <div class="score">Health: ${scan.score.overall}/100 — ${scan.completeness.status.toUpperCase()} ${scan.score.overall >= 85 ? "✅" : "⚠️"}</div>
94
+ <div class="meta">Scan coverage: ${scan.completeness.completed}/${scan.completeness.planned} checks completed.${scan.completeness.comparable ? "" : " This score is not comparable to a complete scan."}</div>
54
95
 
55
96
  <div class="summary">
56
- <span class="pill">Blockers: ${scan.blockers.length}</span>
57
- <span class="pill">Fix next: ${scan.fixNext.length}</span>
58
- <span class="pill">Privacy Review: ${scan.privacyFindings.length}</span>
59
- <span class="pill">Leftovers: ${scan.leftovers.length}</span>
97
+ <span class="pill">Blockers: ${scan.blockers.length}</span>
98
+ <span class="pill">Fix next: ${scan.fixNext.length}</span>
99
+ <span class="pill">Privacy Review: ${scan.privacyFindings.length}</span>
100
+ <span class="pill">Leftovers: ${scan.leftovers.length}</span>
60
101
  <span class="pill">Dead chains: ${scan.deadCodeCandidates.length}</span>
61
102
  <span class="pill">Refactor: ${scan.refactorCandidates.length}</span>
62
103
  </div>
63
104
 
64
105
  <div class="section">
65
- ${renderFindingList(scan.blockers, "BLOCKERS")}
66
- ${renderFindingList(scan.fixNext, "FIX NEXT")}
67
- ${renderFindingList(scan.privacyFindings.slice(0, 10), "PRIVACY REVIEW FINDINGS")}
68
- ${renderFindingList(scan.leftovers, "LEFTOVERS")}
106
+ ${renderFindingList(scan.blockers, "BLOCKERS")}
107
+ ${renderFindingList(scan.fixNext, "FIX NEXT")}
108
+ ${renderFindingList(scan.privacyFindings.slice(0, 10), "PRIVACY REVIEW FINDINGS")}
109
+ ${renderFindingList(scan.leftovers, "LEFTOVERS")}
69
110
  ${renderFindingList(scan.deadCodeCandidates, "DEAD CHAINS")}
70
111
  ${renderFindingList(scan.refactorCandidates, "REFACTOR CANDIDATES")}
71
112
  </div>
72
113
 
73
114
  ${toolList(scan.toolStatuses.filter(t => t.status !== "ok"), "Tool Statuses (non-ok)")}
74
115
  ${toolList(scan.skippedTools, "Skipped Tools")}
75
- ${errored.length ? toolList(errored, "Errored / Timed Out Tools") : ""}
76
- ${scan.recoveryActions.length ? `<h3>Recover before editing</h3><ul>${scan.recoveryActions.map(action => `<li><code>${escapeHtml(action.command)}</code> — ${escapeHtml(action.successCondition)}</li>`).join("")}</ul>` : ""}
116
+ ${errored.length ? toolList(errored, "Errored / Timed Out Tools") : ""}
117
+ ${capabilitySection()}
118
+ ${lineSection("Report filtering", (0, relevance_1.renderRelevanceLines)(scan.relevance))}
119
+ ${lineSection("Acknowledged", (0, suppressions_1.renderSuppressionLines)(scan.suppressions))}
120
+ ${scan.recoveryActions.length ? `<h3>Recover before editing</h3><ul>${scan.recoveryActions.map(action => `<li><code>${escapeHtml(action.command)}</code> — ${escapeHtml(action.successCondition)}</li>`).join("")}</ul>` : ""}
77
121
 
78
122
  <p class="meta" style="margin-top:32px">Run <code>vibedoctor agent-plan</code> for guided repair. Full JSON/HTML/Markdown/SARIF available via --report.</p>
79
123
  </body>
@@ -15,9 +15,15 @@ function renderJsonReport(scan) {
15
15
  privacyReview: scan.privacyReview,
16
16
  toolStatuses: scan.toolStatuses,
17
17
  skippedTools: scan.skippedTools,
18
+ capabilityMatrix: scan.capabilityMatrix,
19
+ relevance: scan.relevance,
20
+ suppressions: scan.suppressions,
21
+ suppressedFindings: scan.suppressedFindings,
22
+ verifications: scan.verifications,
18
23
  agentPlan: scan.agentPlan,
19
24
  notes: {
20
- dpdp: "DPDP findings are technical readiness signals integrated into privacy findings. See .vibedoctor/dpdp/ for the control matrix and data map. Not legal compliance."
25
+ dpdp: "DPDP findings are technical readiness signals integrated into privacy findings. See .vibedoctor/dpdp/ for the control matrix and data map. Not legal compliance.",
26
+ coverage: "capabilityMatrix is authoritative for what actually ran: toolStatuses and skippedTools are views of it. relevance explains any difference between findings a tool reported and findings shown here, so a short report is never a clean one."
21
27
  }
22
28
  }, null, 2) + "\n";
23
29
  }