@neuralaxis/vibedoctor 0.1.3 → 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 (112) hide show
  1. package/README.md +298 -115
  2. package/dist/adapters/biome.js +135 -21
  3. package/dist/adapters/dpdp.d.ts +6 -0
  4. package/dist/adapters/dpdp.js +34 -0
  5. package/dist/adapters/index.d.ts +1 -0
  6. package/dist/adapters/index.js +3 -1
  7. package/dist/adapters/osvScanner.js +136 -17
  8. package/dist/adapters/presidio.js +6 -2
  9. package/dist/adapters/privacyDetector.d.ts +24 -1
  10. package/dist/adapters/privacyDetector.js +86 -2
  11. package/dist/adapters/shared.d.ts +6 -0
  12. package/dist/agentPack/templates/skills.js +159 -53
  13. package/dist/cli/commands/dpdp.d.ts +35 -0
  14. package/dist/cli/commands/dpdp.js +103 -0
  15. package/dist/cli/commands/init.js +105 -50
  16. package/dist/cli/commands/privacyReview.js +3 -4
  17. package/dist/cli/commands/scan.js +4 -1
  18. package/dist/cli/commands/setup.d.ts +13 -17
  19. package/dist/cli/commands/setup.js +138 -200
  20. package/dist/cli/index.js +84 -0
  21. package/dist/core/capability.d.ts +92 -0
  22. package/dist/core/capability.js +122 -0
  23. package/dist/core/config.d.ts +57 -0
  24. package/dist/core/config.js +194 -7
  25. package/dist/core/credentialHeuristics.d.ts +28 -0
  26. package/dist/core/credentialHeuristics.js +179 -0
  27. package/dist/core/engine.d.ts +21 -0
  28. package/dist/core/engine.js +484 -84
  29. package/dist/core/executable.d.ts +18 -0
  30. package/dist/core/executable.js +137 -0
  31. package/dist/core/fileRole.d.ts +24 -0
  32. package/dist/core/fileRole.js +125 -0
  33. package/dist/core/finding.d.ts +125 -1
  34. package/dist/core/finding.js +63 -5
  35. package/dist/core/findingNormalizer.d.ts +33 -0
  36. package/dist/core/findingNormalizer.js +171 -0
  37. package/dist/core/projectDetector.d.ts +13 -0
  38. package/dist/core/projectDetector.js +100 -15
  39. package/dist/core/relevance.d.ts +87 -0
  40. package/dist/core/relevance.js +367 -0
  41. package/dist/core/scanPlanner.d.ts +12 -0
  42. package/dist/core/scanPlanner.js +61 -29
  43. package/dist/core/semverLite.d.ts +27 -0
  44. package/dist/core/semverLite.js +163 -0
  45. package/dist/core/suppressions.d.ts +96 -0
  46. package/dist/core/suppressions.js +302 -0
  47. package/dist/core/toolRegistry.d.ts +58 -0
  48. package/dist/core/toolRegistry.js +247 -0
  49. package/dist/core/toolRunner.d.ts +23 -2
  50. package/dist/core/toolRunner.js +61 -93
  51. package/dist/core/toolVerification.d.ts +87 -0
  52. package/dist/core/toolVerification.js +370 -0
  53. package/dist/dpdp/artifacts.d.ts +11 -0
  54. package/dist/dpdp/artifacts.js +120 -0
  55. package/dist/dpdp/catalogue.d.ts +14 -0
  56. package/dist/dpdp/catalogue.js +661 -0
  57. package/dist/dpdp/collectors/confidence.d.ts +9 -0
  58. package/dist/dpdp/collectors/confidence.js +25 -0
  59. package/dist/dpdp/collectors/dependencies.d.ts +7 -0
  60. package/dist/dpdp/collectors/dependencies.js +63 -0
  61. package/dist/dpdp/collectors/index.d.ts +24 -0
  62. package/dist/dpdp/collectors/index.js +71 -0
  63. package/dist/dpdp/collectors/lifecycle.d.ts +2 -0
  64. package/dist/dpdp/collectors/lifecycle.js +202 -0
  65. package/dist/dpdp/collectors/optionalScanners.d.ts +14 -0
  66. package/dist/dpdp/collectors/optionalScanners.js +437 -0
  67. package/dist/dpdp/collectors/privacyBridge.d.ts +13 -0
  68. package/dist/dpdp/collectors/privacyBridge.js +152 -0
  69. package/dist/dpdp/collectors/safeguards.d.ts +5 -0
  70. package/dist/dpdp/collectors/safeguards.js +186 -0
  71. package/dist/dpdp/collectors/schema.d.ts +6 -0
  72. package/dist/dpdp/collectors/schema.js +122 -0
  73. package/dist/dpdp/collectors/shared.d.ts +10 -0
  74. package/dist/dpdp/collectors/shared.js +43 -0
  75. package/dist/dpdp/context.d.ts +28 -0
  76. package/dist/dpdp/context.js +195 -0
  77. package/dist/dpdp/dataMap.d.ts +7 -0
  78. package/dist/dpdp/dataMap.js +339 -0
  79. package/dist/dpdp/evaluators.d.ts +20 -0
  80. package/dist/dpdp/evaluators.js +522 -0
  81. package/dist/dpdp/evidence.d.ts +11 -0
  82. package/dist/dpdp/evidence.js +123 -0
  83. package/dist/dpdp/findings.d.ts +44 -0
  84. package/dist/dpdp/findings.js +286 -0
  85. package/dist/dpdp/gates.d.ts +14 -0
  86. package/dist/dpdp/gates.js +47 -0
  87. package/dist/dpdp/index.d.ts +16 -0
  88. package/dist/dpdp/index.js +32 -0
  89. package/dist/dpdp/legalSources.d.ts +10 -0
  90. package/dist/dpdp/legalSources.js +104 -0
  91. package/dist/dpdp/paths.d.ts +25 -0
  92. package/dist/dpdp/paths.js +85 -0
  93. package/dist/dpdp/report.d.ts +6 -0
  94. package/dist/dpdp/report.js +222 -0
  95. package/dist/dpdp/reviewQueue.d.ts +3 -0
  96. package/dist/dpdp/reviewQueue.js +88 -0
  97. package/dist/dpdp/scan.d.ts +26 -0
  98. package/dist/dpdp/scan.js +310 -0
  99. package/dist/dpdp/scoring.d.ts +41 -0
  100. package/dist/dpdp/scoring.js +237 -0
  101. package/dist/dpdp/types.d.ts +312 -0
  102. package/dist/dpdp/types.js +86 -0
  103. package/dist/index.d.ts +1 -0
  104. package/dist/index.js +1 -0
  105. package/dist/mcp/tools/dpdp.d.ts +11 -0
  106. package/dist/mcp/tools/dpdp.js +151 -0
  107. package/dist/mcp/tools/index.js +3 -1
  108. package/dist/reporters/html.js +57 -13
  109. package/dist/reporters/json.js +12 -1
  110. package/dist/reporters/markdown.js +46 -4
  111. package/dist/reporters/sarif.js +54 -5
  112. package/package.json +4 -1
@@ -0,0 +1,437 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collectOptionalScannerSignals = collectOptionalScannerSignals;
4
+ const presidio_1 = require("../../adapters/presidio");
5
+ const semgrep_1 = require("../../adapters/semgrep");
6
+ const toolRunner_1 = require("../../core/toolRunner");
7
+ const confidence_1 = require("./confidence");
8
+ const privacyBridge_1 = require("./privacyBridge");
9
+ const shared_1 = require("./shared");
10
+ const evidence_1 = require("../evidence");
11
+ const ENTITY_TO_CATEGORY = {
12
+ aadhaar: "aadhaar",
13
+ pan: "pan",
14
+ passport: "passport",
15
+ email: "email",
16
+ phone: "phone",
17
+ phone_number: "phone",
18
+ date_of_birth: "date_of_birth",
19
+ date_time: "date_of_birth",
20
+ address: "postal_address",
21
+ location: "location",
22
+ ip_address: "ip_device_id",
23
+ ip: "ip_device_id",
24
+ device_id: "ip_device_id",
25
+ credit_card: "financial_payment",
26
+ payment_card: "financial_payment",
27
+ iban: "financial_payment",
28
+ bank_account: "financial_payment",
29
+ medical_license: "health_disability",
30
+ person: "name",
31
+ nrp: "other_personal",
32
+ us_ssn: "other_personal",
33
+ url: "other_personal"
34
+ };
35
+ function sanitizeSnippet(snippet) {
36
+ return snippet ? (0, evidence_1.redactLikelyPii)(snippet) : undefined;
37
+ }
38
+ function mapPrivacyLikeFindingToSignals(finding, signals, minConfidence, provenance) {
39
+ if (!(0, confidence_1.confidenceMeetsThreshold)(finding.confidence, minConfidence)) {
40
+ return;
41
+ }
42
+ const entity = finding.evidence?.entityType ?? finding.tags.find((tag) => tag !== "privacy") ?? "other_personal";
43
+ const category = ENTITY_TO_CATEGORY[entity.toLowerCase()] ?? "other_personal";
44
+ const snippet = sanitizeSnippet(finding.evidence?.snippet ?? finding.evidence?.maskedValue);
45
+ const detectionMethod = finding.evidence?.matchedPattern ?? provenance;
46
+ const detectionPath = finding.evidence?.detectionPath ?? provenance;
47
+ const tags = [
48
+ provenance,
49
+ entity.toLowerCase(),
50
+ ...(finding.tags ?? []),
51
+ ...(0, privacyBridge_1.classifyPrivacyFindingTags)(finding.file, detectionMethod, detectionPath)
52
+ ];
53
+ (0, shared_1.pushSignal)(signals, {
54
+ kind: finding.evidence?.fieldPath ? "field" : "category",
55
+ file: finding.file,
56
+ line: finding.startLine,
57
+ category,
58
+ field: finding.evidence?.fieldPath,
59
+ summary: `${finding.title} (${entity})`,
60
+ snippet,
61
+ confidence: finding.confidence,
62
+ confidenceScore: finding.evidence?.confidenceScore,
63
+ tags,
64
+ detectionMethod: `${provenance}:${detectionMethod}`,
65
+ provenance,
66
+ certainty: finding.confidence === "high" ? "confirmed" : "inferred",
67
+ relatedControls: ["DPDP-APP-001", "DPDP-SEC-007"]
68
+ });
69
+ const blob = `${finding.title} ${finding.message} ${finding.tags.join(" ")}`.toLowerCase();
70
+ if (/log|logger|unsanitized/.test(blob)) {
71
+ (0, shared_1.pushSignal)(signals, {
72
+ kind: "safeguard_gap",
73
+ file: finding.file,
74
+ line: finding.startLine,
75
+ category,
76
+ summary: "Potential PII in logging path (optional scanner)",
77
+ snippet,
78
+ confidence: finding.confidence,
79
+ tags: ["pii-in-logs", provenance],
80
+ detectionMethod: `${provenance}-log`,
81
+ provenance,
82
+ relatedControls: ["DPDP-SEC-001"]
83
+ });
84
+ }
85
+ if (/secret|password|credential|hardcoded|api[_-]?key/.test(blob)) {
86
+ (0, shared_1.pushSignal)(signals, {
87
+ kind: "safeguard_gap",
88
+ file: finding.file,
89
+ line: finding.startLine,
90
+ category,
91
+ summary: "Potential credential or sensitive secret signal (optional scanner)",
92
+ snippet,
93
+ confidence: finding.confidence,
94
+ tags: ["hardcoded-secret", provenance],
95
+ detectionMethod: `${provenance}-secret`,
96
+ provenance,
97
+ relatedControls: ["DPDP-SEC-007", "DPDP-SEC-010"]
98
+ });
99
+ }
100
+ }
101
+ function isPrivacyRelevantSemgrep(finding) {
102
+ const blob = `${finding.id} ${finding.title} ${finding.message} ${(finding.tags ?? []).join(" ")}`.toLowerCase();
103
+ return /pii|privacy|secret|password|credential|token|personal|gdpr|log|auth|jwt|cookie|ssn|aadhaar|pan|email|phone|encrypt|mask|redact/.test(blob);
104
+ }
105
+ function inCandidateScope(finding, candidates) {
106
+ if (!finding.file) {
107
+ return false;
108
+ }
109
+ return candidates.has(finding.file.replaceAll("\\", "/"));
110
+ }
111
+ function scopedScannerContext(ctx, candidates) {
112
+ return {
113
+ ...ctx,
114
+ project: { ...ctx.project, projectFiles: candidates },
115
+ config: {
116
+ ...ctx.config,
117
+ paths: {
118
+ ...ctx.config.paths,
119
+ // Candidates have already passed global + DPDP include/exclude resolution.
120
+ include: candidates,
121
+ exclude: []
122
+ }
123
+ }
124
+ };
125
+ }
126
+ function capabilityFromExecution(id, execution, mapped) {
127
+ const status = execution.status;
128
+ if (status?.status === "error" || status?.status === "timeout") {
129
+ return {
130
+ id,
131
+ status: "error",
132
+ cause: status.status === "timeout" ? "timed_out" : "failed",
133
+ message: status.stderr.trim() || status.stdout.trim() || `${id} failed`,
134
+ remediation: `Run \`vibedoctor tool retry ${id}\` to see the full output.`
135
+ };
136
+ }
137
+ return {
138
+ id,
139
+ status: "available",
140
+ cause: "ran",
141
+ message: `Reused ${id} scan; ${mapped} scoped finding(s) contributed to DPDP evidence`,
142
+ resolvedVia: status?.resolvedPath,
143
+ signalsContributed: mapped
144
+ };
145
+ }
146
+ /**
147
+ * Whether a shared scan result can stand in for a DPDP-scoped run.
148
+ *
149
+ * DPDP runs these scanners under a context that forces privacy checks on, so a
150
+ * shared result that was skipped for a configuration reason says nothing about
151
+ * whether the scanner works — inheriting that skip is what reported an installed
152
+ * Presidio as unavailable for DPDP.
153
+ *
154
+ * A skip caused by the tool being absent is different: it is authoritative, and
155
+ * retrying under a different config would only spend time failing again.
156
+ */
157
+ function canReuseExecution(execution) {
158
+ if (!execution) {
159
+ return false;
160
+ }
161
+ // An entry with no process status came from an adapter that did its work
162
+ // in-process, so the results stand.
163
+ if (!execution.status) {
164
+ return true;
165
+ }
166
+ if (execution.status.status !== "skipped") {
167
+ return true;
168
+ }
169
+ return Boolean(execution.status.installHint);
170
+ }
171
+ /**
172
+ * Run opt-out optional scanners (Presidio, Semgrep) when enabled.
173
+ * Missing tools are skipped — never counted as a pass.
174
+ */
175
+ async function collectOptionalScannerSignals(ctx, candidates, options = {}) {
176
+ const dpdp = ctx.config.checks.dpdp;
177
+ const signals = [];
178
+ const capabilities = [];
179
+ const findings = [];
180
+ const candidateSet = new Set(candidates.map((file) => file.replaceAll("\\", "/")));
181
+ if (options.enabled === false) {
182
+ return {
183
+ signals,
184
+ findings,
185
+ capabilities: [
186
+ {
187
+ id: "presidio",
188
+ status: "skipped",
189
+ cause: "quick_mode",
190
+ message: "Skipped in quick mode",
191
+ remediation: "Run `vibedoctor dpdp scan --full` for evidence from the optional scanners."
192
+ },
193
+ {
194
+ id: "semgrep",
195
+ status: "skipped",
196
+ cause: "quick_mode",
197
+ message: "Skipped in quick mode",
198
+ remediation: "Run `vibedoctor dpdp scan --full` for evidence from the optional scanners."
199
+ }
200
+ ]
201
+ };
202
+ }
203
+ // --- Presidio (default on; opt out with use_presidio: false) ---
204
+ const wantPresidio = dpdp.usePresidio;
205
+ if (!wantPresidio) {
206
+ capabilities.push({
207
+ id: "presidio",
208
+ status: "skipped",
209
+ cause: "opted_out",
210
+ message: "Opted out (set checks.dpdp.use_presidio: true to re-enable for DPDP evidence)",
211
+ remediation: "Set checks.dpdp.use_presidio: true in vibedoctor.yml."
212
+ });
213
+ }
214
+ else if (candidates.length === 0) {
215
+ capabilities.push({
216
+ id: "presidio",
217
+ status: "skipped",
218
+ cause: "nothing_in_scope",
219
+ message: "No DPDP candidate files in scope",
220
+ remediation: "Widen checks.dpdp.include or paths.include in vibedoctor.yml."
221
+ });
222
+ }
223
+ else {
224
+ try {
225
+ const shared = ctx.sharedToolResults?.presidio;
226
+ const reused = canReuseExecution(shared) ? shared : undefined;
227
+ // Note why the shared result could not be reused, so a fresh attempt that
228
+ // also fails can report both facts instead of only the second one.
229
+ const sharedSkipReason = shared && !reused ? shared.status?.installHint ?? shared.status?.stderr?.trim() : undefined;
230
+ if (reused) {
231
+ const scopedFindings = reused.findings.filter((finding) => inCandidateScope(finding, candidateSet));
232
+ findings.push(...scopedFindings);
233
+ for (const finding of scopedFindings) {
234
+ mapPrivacyLikeFindingToSignals(finding, signals, dpdp.minConfidenceToReport, "presidio");
235
+ }
236
+ capabilities.push(capabilityFromExecution("presidio", reused, scopedFindings.length));
237
+ }
238
+ else {
239
+ const baseCtx = scopedScannerContext(ctx, candidates);
240
+ const presidioCtx = {
241
+ ...baseCtx,
242
+ config: {
243
+ ...baseCtx.config,
244
+ checks: {
245
+ ...baseCtx.config.checks,
246
+ privacy: {
247
+ ...baseCtx.config.checks.privacy,
248
+ enabled: true,
249
+ presidio: { enabled: true },
250
+ minConfidenceToReport: dpdp.minConfidenceToReport,
251
+ maskExamples: dpdp.maskExamples
252
+ }
253
+ }
254
+ }
255
+ };
256
+ if (!(await presidio_1.presidioAdapter.detect(presidioCtx.project, presidioCtx.config))) {
257
+ capabilities.push({
258
+ id: "presidio",
259
+ status: "skipped",
260
+ cause: "not_applicable",
261
+ message: "Presidio not selected for this project",
262
+ remediation: "Set checks.privacy.enabled and checks.dpdp.use_presidio to true in vibedoctor.yml."
263
+ });
264
+ }
265
+ else {
266
+ const result = await presidio_1.presidioAdapter.runStandalone?.(presidioCtx);
267
+ const status = result?.status;
268
+ if (!result || status?.status === "skipped") {
269
+ const detail = status?.installHint ?? status?.stderr?.trim() ?? "Presidio could not be started in the project Python environment.";
270
+ capabilities.push({
271
+ id: "presidio",
272
+ status: "skipped",
273
+ cause: "not_installed",
274
+ message: sharedSkipReason
275
+ ? `${detail} (the privacy scan also skipped Presidio: ${sharedSkipReason})`
276
+ : detail,
277
+ remediation: "Install it in the interpreter the scanner uses: python -m pip install presidio-analyzer, then run `vibedoctor setup --apply` to confirm it resolves."
278
+ });
279
+ }
280
+ else if (status?.status === "error" || status?.status === "timeout") {
281
+ capabilities.push({
282
+ id: "presidio",
283
+ status: "error",
284
+ cause: status.status === "timeout" ? "timed_out" : "failed",
285
+ message: status.stderr?.trim() || status.stdout?.trim() || "Presidio failed",
286
+ remediation: "Run `vibedoctor tool retry presidio` to see the full output."
287
+ });
288
+ }
289
+ else {
290
+ findings.push(...result.findings);
291
+ for (const finding of result.findings) {
292
+ mapPrivacyLikeFindingToSignals(finding, signals, dpdp.minConfidenceToReport, "presidio");
293
+ }
294
+ capabilities.push({
295
+ id: "presidio",
296
+ status: "available",
297
+ cause: "ran",
298
+ message: `Presidio contributed ${result.findings.length} finding(s) to DPDP evidence`,
299
+ resolvedVia: status?.resolvedPath,
300
+ signalsContributed: result.findings.length
301
+ });
302
+ }
303
+ }
304
+ }
305
+ }
306
+ catch (error) {
307
+ capabilities.push({
308
+ id: "presidio",
309
+ status: "error",
310
+ cause: "failed",
311
+ message: error instanceof Error ? error.message : String(error)
312
+ });
313
+ }
314
+ }
315
+ // --- Semgrep (default on; opt out with use_semgrep: false) ---
316
+ if (!dpdp.useSemgrep) {
317
+ capabilities.push({
318
+ id: "semgrep",
319
+ status: "skipped",
320
+ cause: "opted_out",
321
+ message: "Opted out (set checks.dpdp.use_semgrep: true to re-enable for DPDP evidence)",
322
+ remediation: "Set checks.dpdp.use_semgrep: true in vibedoctor.yml."
323
+ });
324
+ }
325
+ else if (candidates.length === 0) {
326
+ capabilities.push({
327
+ id: "semgrep",
328
+ status: "skipped",
329
+ cause: "nothing_in_scope",
330
+ message: "No DPDP candidate files in scope",
331
+ remediation: "Widen checks.dpdp.include or paths.include in vibedoctor.yml."
332
+ });
333
+ }
334
+ else {
335
+ try {
336
+ const sharedSemgrep = ctx.sharedToolResults?.semgrep;
337
+ const reused = canReuseExecution(sharedSemgrep) ? sharedSemgrep : undefined;
338
+ const sharedSkipReason = sharedSemgrep && !reused ? sharedSemgrep.status?.installHint ?? sharedSemgrep.status?.stderr?.trim() : undefined;
339
+ if (reused) {
340
+ const scopedFindings = reused.findings.filter((finding) => inCandidateScope(finding, candidateSet));
341
+ findings.push(...scopedFindings);
342
+ let mapped = 0;
343
+ for (const finding of scopedFindings) {
344
+ if (isPrivacyRelevantSemgrep(finding)) {
345
+ mapped += 1;
346
+ mapPrivacyLikeFindingToSignals(finding, signals, dpdp.minConfidenceToReport, "semgrep");
347
+ }
348
+ }
349
+ capabilities.push(capabilityFromExecution("semgrep", reused, mapped));
350
+ }
351
+ else {
352
+ const semgrepCtx = scopedScannerContext(ctx, candidates);
353
+ if (!(await semgrep_1.semgrepAdapter.detect(semgrepCtx.project, semgrepCtx.config))) {
354
+ capabilities.push({
355
+ id: "semgrep",
356
+ status: "skipped",
357
+ cause: "not_applicable",
358
+ message: "Semgrep not applicable for this project",
359
+ remediation: "Semgrep needs source files in a language it supports; widen paths.include if that is wrong."
360
+ });
361
+ }
362
+ else if (!semgrep_1.semgrepAdapter.buildScanCommand || !semgrep_1.semgrepAdapter.parseResult) {
363
+ capabilities.push({
364
+ id: "semgrep",
365
+ status: "skipped",
366
+ cause: "not_applicable",
367
+ message: "Semgrep adapter cannot run in this build",
368
+ remediation: "This is a packaging problem, not a configuration one; please report it."
369
+ });
370
+ }
371
+ else {
372
+ const command = semgrep_1.semgrepAdapter.buildScanCommand(semgrepCtx);
373
+ // Honour the configured budget here too. The adapter's own default is
374
+ // not the user's setting, and a DPDP scan that ignores
375
+ // runtime.tool_timeouts can outlast the whole scan it belongs to.
376
+ const timeoutSeconds = ctx.config.runtime.toolTimeouts.semgrep ?? ctx.config.runtime.defaultTimeoutSeconds;
377
+ command.timeoutMs = Math.max(1, timeoutSeconds) * 1000;
378
+ const toolResult = await (0, toolRunner_1.runCommand)(command, semgrep_1.semgrepAdapter.installHint);
379
+ if (toolResult.status === "skipped") {
380
+ capabilities.push({
381
+ id: "semgrep",
382
+ status: "skipped",
383
+ cause: "not_installed",
384
+ message: (() => {
385
+ const detail = toolResult.installHint ?? toolResult.stderr?.trim() ?? "Semgrep not installed (never counted as pass)";
386
+ return sharedSkipReason ? `${detail} (the main scan also skipped Semgrep: ${sharedSkipReason})` : detail;
387
+ })(),
388
+ remediation: "Install Semgrep (pipx install semgrep), then run `vibedoctor setup --apply` to confirm it resolves."
389
+ });
390
+ }
391
+ else if (toolResult.status === "error" || toolResult.status === "timeout") {
392
+ capabilities.push({
393
+ id: "semgrep",
394
+ status: "error",
395
+ cause: toolResult.status === "timeout" ? "timed_out" : "failed",
396
+ message: toolResult.status === "timeout"
397
+ ? `Semgrep exceeded its ${Math.round(toolResult.durationMs / 1000)}s budget, so its rules did not run over DPDP candidates.`
398
+ : toolResult.stderr?.trim() || "Semgrep failed",
399
+ remediation: toolResult.status === "timeout"
400
+ ? "Raise runtime.tool_timeouts.semgrep in vibedoctor.yml, or narrow checks.dpdp.include."
401
+ : "Run `vibedoctor tool retry semgrep` to see the full output."
402
+ });
403
+ }
404
+ else {
405
+ const semgrepFindings = semgrep_1.semgrepAdapter.parseResult(toolResult, semgrepCtx);
406
+ findings.push(...semgrepFindings);
407
+ let mapped = 0;
408
+ for (const finding of semgrepFindings) {
409
+ if (!isPrivacyRelevantSemgrep(finding)) {
410
+ continue;
411
+ }
412
+ mapped += 1;
413
+ mapPrivacyLikeFindingToSignals(finding, signals, dpdp.minConfidenceToReport, "semgrep");
414
+ }
415
+ capabilities.push({
416
+ id: "semgrep",
417
+ status: "available",
418
+ cause: "ran",
419
+ message: `Semgrep ran (${semgrepFindings.length} finding(s); ${mapped} privacy-relevant mapped to DPDP evidence)`,
420
+ resolvedVia: toolResult.resolvedPath,
421
+ signalsContributed: mapped
422
+ });
423
+ }
424
+ }
425
+ }
426
+ }
427
+ catch (error) {
428
+ capabilities.push({
429
+ id: "semgrep",
430
+ status: "error",
431
+ cause: "failed",
432
+ message: error instanceof Error ? error.message : String(error)
433
+ });
434
+ }
435
+ }
436
+ return { signals, capabilities, findings };
437
+ }
@@ -0,0 +1,13 @@
1
+ import type { ToolAdapterContext } from "../../adapters/shared";
2
+ import type { Finding } from "../../core/finding";
3
+ import type { TechnicalSignalBag } from "../types";
4
+ /** Prefer DPDP confidence/mask settings when invoking the privacy detector from DPDP. */
5
+ export declare function withDpdpPrivacyOverrides(ctx: ToolAdapterContext): ToolAdapterContext;
6
+ /**
7
+ * Distinguish field-name metadata from value-literal detections for hardcoded-PII evaluation.
8
+ */
9
+ export declare function classifyPrivacyFindingTags(file: string | undefined, matchedPattern: string, detectionPath: string): string[];
10
+ export declare function collectPrivacySignals(ctx: ToolAdapterContext, candidates: string[]): Promise<{
11
+ privacyFindings: Finding[];
12
+ signals: TechnicalSignalBag[];
13
+ }>;
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withDpdpPrivacyOverrides = withDpdpPrivacyOverrides;
4
+ exports.classifyPrivacyFindingTags = classifyPrivacyFindingTags;
5
+ exports.collectPrivacySignals = collectPrivacySignals;
6
+ const privacyDetector_1 = require("../../adapters/privacyDetector");
7
+ const evidence_1 = require("../evidence");
8
+ const confidence_1 = require("./confidence");
9
+ const shared_1 = require("./shared");
10
+ const ENTITY_TO_CATEGORY = {
11
+ aadhaar: "aadhaar",
12
+ pan: "pan",
13
+ passport: "passport",
14
+ email: "email",
15
+ phone: "phone",
16
+ date_of_birth: "date_of_birth",
17
+ address: "postal_address",
18
+ ip_address: "ip_device_id",
19
+ device_id: "ip_device_id",
20
+ payment_card: "financial_payment",
21
+ bank_account: "financial_payment",
22
+ health_data: "health_disability",
23
+ financial_attribute: "financial_payment",
24
+ employment_sensitive: "employee_applicant_customer",
25
+ precise_location: "location",
26
+ person_linkable_id: "employee_applicant_customer",
27
+ combination_risk: "other_personal"
28
+ };
29
+ /** Prefer DPDP confidence/mask settings when invoking the privacy detector from DPDP. */
30
+ function withDpdpPrivacyOverrides(ctx) {
31
+ const dpdp = ctx.config.checks.dpdp;
32
+ return {
33
+ ...ctx,
34
+ config: {
35
+ ...ctx.config,
36
+ checks: {
37
+ ...ctx.config.checks,
38
+ privacy: {
39
+ ...ctx.config.checks.privacy,
40
+ minConfidenceToReport: dpdp.minConfidenceToReport,
41
+ maskExamples: dpdp.maskExamples
42
+ }
43
+ }
44
+ }
45
+ };
46
+ }
47
+ function sanitizeSignalSnippet(snippet) {
48
+ if (!snippet) {
49
+ return undefined;
50
+ }
51
+ return (0, evidence_1.redactLikelyPii)(snippet);
52
+ }
53
+ /**
54
+ * Distinguish field-name metadata from value-literal detections for hardcoded-PII evaluation.
55
+ */
56
+ function classifyPrivacyFindingTags(file, matchedPattern, detectionPath) {
57
+ const tags = [];
58
+ const pathText = detectionPath.toLowerCase();
59
+ const pattern = matchedPattern.toLowerCase();
60
+ const isValueLiteral = pathText.includes("regex") || pathText.includes("checksum") || /(-regex|luhn)/i.test(pattern);
61
+ const isFieldMetadata = pathText.includes("metadata") || /-field$/i.test(pattern) || pathText.includes("combination-risk");
62
+ if (isValueLiteral) {
63
+ tags.push("value-literal");
64
+ }
65
+ else if (isFieldMetadata) {
66
+ tags.push("field-metadata");
67
+ }
68
+ if (file && /(^|\/)(fixtures?|seeds?|samples?|mocks?|demos?|testdata)(\/|$)/i.test(file.replaceAll("\\", "/"))) {
69
+ tags.push("fixture-path");
70
+ }
71
+ return tags;
72
+ }
73
+ async function collectPrivacySignals(ctx, candidates) {
74
+ const privacyCfg = ctx.config.checks.privacy;
75
+ const dpdpCfg = ctx.config.checks.dpdp;
76
+ const privacyCtx = withDpdpPrivacyOverrides(ctx);
77
+ const privacyFindings = privacyCfg.enabled || dpdpCfg.enabled
78
+ ? await (0, privacyDetector_1.detectPiiFindings)(privacyCtx, { fileAllowlist: candidates })
79
+ : [];
80
+ const signals = [];
81
+ for (const finding of privacyFindings) {
82
+ if (!(0, confidence_1.confidenceMeetsThreshold)(finding.confidence, dpdpCfg.minConfidenceToReport)) {
83
+ continue;
84
+ }
85
+ const entity = finding.evidence?.entityType ?? "other_personal";
86
+ const category = ENTITY_TO_CATEGORY[entity] ?? "other_personal";
87
+ const snippet = sanitizeSignalSnippet(finding.evidence?.snippet);
88
+ const detectionMethod = finding.evidence?.matchedPattern ?? "privacy-detector";
89
+ const detectionPath = finding.evidence?.detectionPath ?? "";
90
+ const privacyTags = [
91
+ "privacy-detector",
92
+ entity,
93
+ ...(finding.tags ?? []),
94
+ ...classifyPrivacyFindingTags(finding.file, detectionMethod, detectionPath)
95
+ ];
96
+ (0, shared_1.pushSignal)(signals, {
97
+ kind: finding.evidence?.fieldPath ? "field" : "category",
98
+ file: finding.file,
99
+ line: finding.startLine,
100
+ category,
101
+ field: finding.evidence?.fieldPath,
102
+ summary: `${finding.title} (${entity})`,
103
+ snippet,
104
+ confidence: finding.confidence,
105
+ confidenceScore: finding.evidence?.confidenceScore,
106
+ tags: privacyTags,
107
+ detectionMethod,
108
+ provenance: "privacy-detector",
109
+ certainty: finding.confidence === "high" ? "confirmed" : "inferred",
110
+ relatedControls: ["DPDP-APP-001", "DPDP-SEC-007"]
111
+ });
112
+ if (finding.tags.includes("logging") || finding.id.includes("unsanitized-log")) {
113
+ (0, shared_1.pushSignal)(signals, {
114
+ kind: "safeguard_gap",
115
+ file: finding.file,
116
+ line: finding.startLine,
117
+ category,
118
+ summary: "Potential PII in logger call",
119
+ snippet,
120
+ confidence: finding.confidence,
121
+ tags: ["pii-in-logs"],
122
+ detectionMethod: "privacy-detector-log",
123
+ relatedControls: ["DPDP-SEC-001"]
124
+ });
125
+ }
126
+ if (finding.tags.includes("overfetching") || finding.id.includes("api-overfetching")) {
127
+ (0, shared_1.pushSignal)(signals, {
128
+ kind: "safeguard_gap",
129
+ file: finding.file,
130
+ line: finding.startLine,
131
+ summary: "Potential API over-fetching of personal entity",
132
+ confidence: finding.confidence,
133
+ tags: ["api-overfetch"],
134
+ detectionMethod: "privacy-detector-overfetch",
135
+ relatedControls: ["DPDP-MIN-001"]
136
+ });
137
+ }
138
+ if (finding.tags.includes("retention") || finding.id.includes("missing-retention")) {
139
+ (0, shared_1.pushSignal)(signals, {
140
+ kind: "storage",
141
+ file: finding.file,
142
+ line: finding.startLine,
143
+ summary: finding.message,
144
+ confidence: finding.confidence,
145
+ tags: ["missing-retention", "pii-store"],
146
+ detectionMethod: "privacy-detector-retention",
147
+ relatedControls: ["DPDP-RET-001", "DPDP-ERA-002"]
148
+ });
149
+ }
150
+ }
151
+ return { privacyFindings, signals };
152
+ }
@@ -0,0 +1,5 @@
1
+ import type { TechnicalSignalBag } from "../types";
2
+ /**
3
+ * Safeguard / gap detectors with multi-line depth for logs, LLM prompts, and route auth.
4
+ */
5
+ export declare function collectSafeguardSignals(signals: TechnicalSignalBag[], file: string, content: string, lines: string[]): void;