@neuralaxis/vibedoctor 0.2.0 → 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 +135 -23
- package/dist/adapters/biome.js +136 -21
- 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 +140 -19
- package/dist/adapters/presidio.js +3 -1
- package/dist/adapters/ruff.js +7 -3
- package/dist/adapters/shared.d.ts +4 -0
- package/dist/cli/commands/init.js +112 -50
- package/dist/cli/commands/privacyReview.js +3 -4
- package/dist/cli/commands/scan.d.ts +6 -0
- package/dist/cli/commands/scan.js +16 -2
- package/dist/cli/commands/setup.d.ts +13 -17
- package/dist/cli/commands/setup.js +138 -200
- 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/capability.d.ts +92 -0
- package/dist/core/capability.js +122 -0
- package/dist/core/config.d.ts +47 -0
- package/dist/core/config.js +134 -3
- package/dist/core/credentialHeuristics.d.ts +28 -0
- package/dist/core/credentialHeuristics.js +179 -0
- package/dist/core/engine.d.ts +29 -1
- package/dist/core/engine.js +510 -126
- package/dist/core/executable.d.ts +18 -0
- package/dist/core/executable.js +137 -0
- package/dist/core/fileRole.d.ts +24 -0
- package/dist/core/fileRole.js +125 -0
- package/dist/core/finding.d.ts +125 -1
- package/dist/core/finding.js +70 -8
- package/dist/core/findingCorrelator.d.ts +19 -0
- package/dist/core/findingCorrelator.js +112 -0
- package/dist/core/findingNormalizer.d.ts +33 -0
- package/dist/core/findingNormalizer.js +172 -0
- package/dist/core/managedTools.d.ts +25 -0
- package/dist/core/managedTools.js +186 -0
- package/dist/core/projectDetector.d.ts +13 -0
- package/dist/core/projectDetector.js +100 -15
- package/dist/core/relevance.d.ts +87 -0
- package/dist/core/relevance.js +367 -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 +13 -0
- package/dist/core/scanPlanner.js +66 -38
- package/dist/core/semverLite.d.ts +27 -0
- package/dist/core/semverLite.js +163 -0
- package/dist/core/suppressions.d.ts +96 -0
- package/dist/core/suppressions.js +302 -0
- package/dist/core/toolRegistry.d.ts +58 -0
- package/dist/core/toolRegistry.js +254 -0
- package/dist/core/toolRunner.d.ts +27 -2
- package/dist/core/toolRunner.js +79 -93
- package/dist/core/toolRuntime.d.ts +40 -0
- package/dist/core/toolRuntime.js +417 -0
- package/dist/core/toolVerification.d.ts +89 -0
- package/dist/core/toolVerification.js +425 -0
- package/dist/dpdp/collectors/optionalScanners.js +120 -30
- package/dist/dpdp/findings.d.ts +33 -3
- package/dist/dpdp/findings.js +191 -4
- package/dist/dpdp/scan.js +2 -2
- package/dist/dpdp/scoring.d.ts +14 -4
- package/dist/dpdp/scoring.js +34 -8
- package/dist/dpdp/types.d.ts +19 -1
- 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/dist/reporters/html.js +57 -13
- package/dist/reporters/json.js +7 -1
- package/dist/reporters/markdown.js +46 -4
- package/dist/reporters/sarif.js +54 -5
- package/package.json +80 -80
package/README.md
CHANGED
|
@@ -1,42 +1,45 @@
|
|
|
1
1
|
# VibeDoctor
|
|
2
2
|
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="website/public/logo-lockup.png" alt="VibeDoctor, a NeuralAxis product" width="360" />
|
|
5
|
+
</p>
|
|
6
|
+
|
|
3
7
|
**A local health check for code you did not write line by line.**
|
|
8
|
+
**Give VibeDoctor a repository. It figures out what applies, runs the diagnosis, and tells you or your coding agent what to fix first.**
|
|
4
9
|
|
|
5
|
-
VibeDoctor scans JavaScript, TypeScript, Python, and mixed repositories for code-health, security, privacy, testing, and maintainability problems. It combines
|
|
10
|
+
VibeDoctor scans JavaScript, TypeScript, Python, and mixed repositories for code-health, security, privacy, testing, and maintainability problems. It combines engine output into one ranked report, one normalized finding format, and a fix-next plan that humans and coding agents can use without interpreting a wall of unrelated logs.
|
|
6
11
|
|
|
7
12
|
```bash
|
|
8
|
-
npx @neuralaxis/vibedoctor scan
|
|
13
|
+
npx @neuralaxis/vibedoctor scan
|
|
9
14
|
```
|
|
10
15
|
|
|
11
|
-
|
|
16
|
+
That is the default path: full applicable diagnosis, local by default. Missing or failed scanners are reported as incomplete evidence, never silently counted as a clean result.
|
|
17
|
+
|
|
18
|
+
The public product site lives in [`website/`](website/README.md) and deploys from GitHub Pages.
|
|
12
19
|
|
|
13
20
|
## Start here
|
|
14
21
|
|
|
15
|
-
|
|
22
|
+
```bash
|
|
23
|
+
npx @neuralaxis/vibedoctor scan
|
|
24
|
+
```
|
|
16
25
|
|
|
17
|
-
|
|
18
|
-
| --- | --- |
|
|
19
|
-
| Check files changed in Git | `npx @neuralaxis/vibedoctor scan --changed` |
|
|
20
|
-
| Run a fast repository check | `npx @neuralaxis/vibedoctor scan --quick` |
|
|
21
|
-
| Run the most complete check | `npx @neuralaxis/vibedoctor scan --full` |
|
|
22
|
-
| Prepare local scanner tools | `npx @neuralaxis/vibedoctor setup` |
|
|
23
|
-
| Get a repair plan for an AI agent | `npx @neuralaxis/vibedoctor agent-plan --format markdown` |
|
|
24
|
-
| Check India DPDP technical readiness | `npx @neuralaxis/vibedoctor dpdp scan --full` |
|
|
26
|
+
That is enough for a first diagnosis. VibeDoctor detects the repository, runs the capabilities that apply, correlates overlapping evidence, and ranks what to fix first.
|
|
25
27
|
|
|
26
|
-
For
|
|
28
|
+
For an AI coding agent:
|
|
27
29
|
|
|
28
30
|
```bash
|
|
29
|
-
npx @neuralaxis/vibedoctor
|
|
30
|
-
npx @neuralaxis/vibedoctor setup
|
|
31
|
-
npx @neuralaxis/vibedoctor setup --apply
|
|
32
|
-
npx @neuralaxis/vibedoctor scan --quick
|
|
31
|
+
npx @neuralaxis/vibedoctor scan --report agent-json
|
|
33
32
|
```
|
|
34
33
|
|
|
35
|
-
|
|
34
|
+
Optional narrower runs:
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
| Goal | Command |
|
|
37
|
+
| --- | --- |
|
|
38
|
+
| Fast profile | `npx @neuralaxis/vibedoctor scan --quick` |
|
|
39
|
+
| Git-changed files | `npx @neuralaxis/vibedoctor scan --changed` |
|
|
40
|
+
| Explicit full alias | `npx @neuralaxis/vibedoctor scan --full` |
|
|
41
|
+
| Agent repair plan file | `npx @neuralaxis/vibedoctor agent-plan --format markdown` |
|
|
42
|
+
| India DPDP technical readiness | `npx @neuralaxis/vibedoctor dpdp scan --full` |
|
|
40
43
|
|
|
41
44
|
## What you get
|
|
42
45
|
|
|
@@ -51,7 +54,29 @@ Default artifacts are written under `.vibedoctor/`:
|
|
|
51
54
|
└── agent-plan.md # ordered repair work
|
|
52
55
|
```
|
|
53
56
|
|
|
54
|
-
Use the terminal report for quick triage, HTML for review, JSON for automation, and `agent-plan.md` for a
|
|
57
|
+
Use the terminal report for quick triage, HTML for review, JSON for automation, `agent-json` for a coding agent, and `agent-plan.md` for a file-based handoff.
|
|
58
|
+
|
|
59
|
+
## Advanced setup and troubleshooting
|
|
60
|
+
|
|
61
|
+
You do not need to install Ruff, Gitleaks, or OSV-Scanner just to run VibeDoctor. The default scan uses built-in detectors plus managed copies of those three engines when they apply. Other engines are used when they are already on PATH or installed in the project; missing ones are reported as incomplete evidence.
|
|
62
|
+
|
|
63
|
+
To install extra project-local scanners, or to debug a tool that did not run:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npx @neuralaxis/vibedoctor init
|
|
67
|
+
npx @neuralaxis/vibedoctor setup
|
|
68
|
+
npx @neuralaxis/vibedoctor setup --apply
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`setup --apply` can mutate the scanned project (it installs recommended tools there), so review the plan first. Managed Ruff, Gitleaks, and OSV-Scanner are cached under `~/.cache/vibedoctor/` and do not edit `package.json`, lockfiles, or Python manifests.
|
|
72
|
+
|
|
73
|
+
To use the shorter `vibedoctor` command everywhere:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
npm install -g @neuralaxis/vibedoctor
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Override the tool cache with `VIBEDOCTOR_TOOL_CACHE`. Disable downloads with `VIBEDOCTOR_ALLOW_NETWORK=0`.
|
|
55
80
|
|
|
56
81
|
## What VibeDoctor checks
|
|
57
82
|
|
|
@@ -64,6 +89,71 @@ Use the terminal report for quick triage, HTML for review, JSON for automation,
|
|
|
64
89
|
|
|
65
90
|
VibeDoctor detects the repository shape and discovers applicable local tools. A missing optional tool is marked `SKIPPED`; a failed or timed-out required tool can make the result `PARTIAL` or `INVALID`.
|
|
66
91
|
|
|
92
|
+
## Know exactly what ran
|
|
93
|
+
|
|
94
|
+
Every scan prints a coverage table with one row per tool, so "installed" is never confused with "completed":
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
TOOL COVERAGE
|
|
98
|
+
TOOL STATE FINDINGS TIME DETAIL
|
|
99
|
+
biome completed 200 of 223 1.8s Ran at node_modules/.bin/biome.cmd.
|
|
100
|
+
semgrep timed out 0 300.0s Exceeded its 300s budget and was stopped, so this check did not run.
|
|
101
|
+
pyright not applicable 0 Nothing in this repository matches what pyright analyses.
|
|
102
|
+
vulture not installed 0 vulture was not found on the scanner's PATH.
|
|
103
|
+
|
|
104
|
+
TO RESTORE COVERAGE
|
|
105
|
+
- semgrep: Raise runtime.tool_timeouts.semgrep, or run `vibedoctor scan --changed` for a diff-scoped run.
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Each row separates the facts that used to be collapsed into "skipped":
|
|
109
|
+
|
|
110
|
+
- **applicable** — is there anything here for this tool to analyse?
|
|
111
|
+
- **installed** — did the executable resolve, and at which path?
|
|
112
|
+
- **executed** — did it start, and did it finish inside its time budget?
|
|
113
|
+
- **findings shown of reported** — a tool that ran but had output filtered shows `200 of 223`, so a short list is never mistaken for a clean one.
|
|
114
|
+
|
|
115
|
+
States are `completed`, `partial`, `timed out`, `failed`, `not installed`, `runtime mismatch`, `deferred`, `disabled`, `not applicable`, and `not selected`. Only the first is treated as full coverage; deliberate exclusions do not count against you, and everything else is disclosed with a reason and a remediation.
|
|
116
|
+
|
|
117
|
+
`vibedoctor setup --apply` verifies each tool by running it the way the scanner will, reports the resolved path and version, and **fails if a tool cannot be verified** — even when the install command itself succeeded. Tools that install but cannot run under the current runtime are reported as a runtime mismatch, with the option to defer them deliberately via `runtime.deferred_tools`.
|
|
118
|
+
|
|
119
|
+
## Keeping the report readable
|
|
120
|
+
|
|
121
|
+
Scanners are tuned for recall, so raw output buries the findings that matter. VibeDoctor applies uniform relevance controls and always discloses what they withheld:
|
|
122
|
+
|
|
123
|
+
- **Ranking** puts new findings and findings in changed files first, so pre-existing debt does not hide a regression you just introduced.
|
|
124
|
+
- **Per-tool caps** keep an exhaustive detector from dominating the report. What falls outside the cap is reported as a count with the setting to raise.
|
|
125
|
+
- **Confidence floors** apply per tool.
|
|
126
|
+
- **File roles** — tests, fixtures, generated, and vendored code are recognised, and findings there are downgraded rather than presented like production defects.
|
|
127
|
+
- **Contextual validation** re-checks findings that claim to have found a credential. A match on an identifier like `format_key` is downgraded and marked as a likely false positive, with the reason given; a genuine high-entropy token keeps full severity.
|
|
128
|
+
- **Evidence grades** — every finding records whether it was `verified` from code, `observed` at a location, inferred as a `heuristic`, or `unproven`, so a naming guess never reads like a traced code path.
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
REPORT FILTERING
|
|
132
|
+
Relevance: showing 54 of 124 findings.
|
|
133
|
+
- vulture: showing 50 of 120 — withheld 70 beyond the 50-finding cap.
|
|
134
|
+
To see withheld findings:
|
|
135
|
+
- Raise relevance.per_tool.vulture.max_findings in vibedoctor.yml.
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Acknowledging findings you have already decided about
|
|
139
|
+
|
|
140
|
+
`.vibedoctor/suppressions.yml` records findings that are known and accepted. Unlike the baseline, which only answers "was this here before?", an acknowledgement carries a reason and an expiry:
|
|
141
|
+
|
|
142
|
+
```yaml
|
|
143
|
+
version: 1
|
|
144
|
+
suppressions:
|
|
145
|
+
- id: fixture-credentials
|
|
146
|
+
reason: Synthetic credentials in test fixtures, never used against real systems.
|
|
147
|
+
classification: fixture # false_positive | accepted_risk | deferred | fixture
|
|
148
|
+
owner: platform-team
|
|
149
|
+
expires: 2026-12-31
|
|
150
|
+
match:
|
|
151
|
+
tools: [gitleaks]
|
|
152
|
+
paths: ["fixtures/**"]
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
A reason is required, and a rule with no match criteria is rejected rather than silencing the report. When an acknowledgement lapses, its findings come back marked `resurfaced` instead of staying hidden. Acknowledgements apply to every finding, including DPDP ones.
|
|
156
|
+
|
|
67
157
|
## Understand the result before fixing code
|
|
68
158
|
|
|
69
159
|
| Status | Meaning | What to do |
|
|
@@ -237,6 +327,23 @@ runtime:
|
|
|
237
327
|
- biome
|
|
238
328
|
- semgrep
|
|
239
329
|
fail_on_incomplete_scan: true
|
|
330
|
+
on_timeout: scoped_retry # scoped_retry | skip | fail
|
|
331
|
+
total_budget_seconds: 0 # 0 means no wall-clock ceiling
|
|
332
|
+
deferred_tools: [] # deliberately not run; reported as deferred
|
|
333
|
+
|
|
334
|
+
relevance:
|
|
335
|
+
min_confidence: low
|
|
336
|
+
max_findings_per_tool: 200
|
|
337
|
+
synthetic_file_policy: downgrade # keep | downgrade | drop
|
|
338
|
+
validate_secrets: true
|
|
339
|
+
per_tool:
|
|
340
|
+
vulture:
|
|
341
|
+
min_confidence: medium
|
|
342
|
+
max_findings: 50
|
|
343
|
+
|
|
344
|
+
suppressions:
|
|
345
|
+
enabled: true
|
|
346
|
+
file: .vibedoctor/suppressions.yml
|
|
240
347
|
|
|
241
348
|
paths:
|
|
242
349
|
include:
|
|
@@ -250,6 +357,10 @@ paths:
|
|
|
250
357
|
- `baseline.fail_only_on_new_issues` limits gates to debt introduced after the baseline.
|
|
251
358
|
- `runtime.required_tools` defines which scanners must complete.
|
|
252
359
|
- `runtime.tool_timeouts` sets scanner-specific deadlines.
|
|
360
|
+
- `runtime.on_timeout: scoped_retry` reruns a tool that runs out of time over changed files only, and reports the partial coverage instead of losing the check.
|
|
361
|
+
- `runtime.deferred_tools` marks tools you have deliberately chosen not to run, so the report says "deferred" rather than implying they passed.
|
|
362
|
+
- `relevance.*` controls how much of what the tools report reaches the report. Nothing is dropped silently.
|
|
363
|
+
- `suppressions.*` points at the acknowledgements file described above.
|
|
253
364
|
- `checks.*` enables categories and their gates.
|
|
254
365
|
- `checks.privacy.*` controls privacy detection, masking, optional AI review, and blocking behavior.
|
|
255
366
|
- `checks.dpdp.*` controls technical-readiness evidence, organisation context, optional scanners, and deterministic gates.
|
|
@@ -263,7 +374,8 @@ Human-review-only DPDP items do not fail CI. Configure `checks.dpdp.fail_on_seve
|
|
|
263
374
|
| --- | --- |
|
|
264
375
|
| Initialize configuration | `vibedoctor init` |
|
|
265
376
|
| Plan or apply scanner setup | `vibedoctor setup` / `vibedoctor setup --apply` |
|
|
266
|
-
|
|
|
377
|
+
| Full applicable diagnosis | `vibedoctor scan` |
|
|
378
|
+
| Quick, changed, or explicit full | `vibedoctor scan --quick` / `--changed` / `--full` |
|
|
267
379
|
| Scan selected categories | `vibedoctor scan --category dead_code,leftovers` |
|
|
268
380
|
| Render a fresh full report | `vibedoctor report --json`, `--html`, `--markdown`, `--sarif`, or `--agent` |
|
|
269
381
|
| Apply supported safe fixes | `vibedoctor fix --safe` |
|
package/dist/adapters/biome.js
CHANGED
|
@@ -3,15 +3,69 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.biomeAdapter = void 0;
|
|
4
4
|
const finding_1 = require("../core/finding");
|
|
5
5
|
const shared_1 = require("./shared");
|
|
6
|
+
/**
|
|
7
|
+
* Biome writes Windows paths into JSON strings without escaping the separator,
|
|
8
|
+
* producing output that is not valid JSON (`"src\core\finding.ts"`). Parsing
|
|
9
|
+
* threw, and the engine swallowed the error, so Biome silently contributed
|
|
10
|
+
* nothing on every Windows repository.
|
|
11
|
+
*
|
|
12
|
+
* The repair is confined to the `path` field. A blanket pass over the whole
|
|
13
|
+
* document would corrupt diagnostic text, because `\n` and `\t` are both real
|
|
14
|
+
* escapes there and plausible path segments here (`\node_modules`, `\test`) —
|
|
15
|
+
* only in a path is a backslash unambiguously a separator.
|
|
16
|
+
*/
|
|
17
|
+
function repairPathSeparators(raw) {
|
|
18
|
+
return raw.replace(/("path"\s*:\s*")((?:[^"\\]|\\.)*)(")/g, (_match, open, value, close) => {
|
|
19
|
+
return `${open}${value.replaceAll("\\", "\\\\")}${close}`;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/** Last resort: escape any backslash that does not begin a valid JSON escape. */
|
|
23
|
+
function repairInvalidEscapes(raw) {
|
|
24
|
+
return raw.replace(/\\(?!["\\/bfnrtu])/g, "\\\\");
|
|
25
|
+
}
|
|
6
26
|
function parseBiomeOutput(stdout) {
|
|
7
27
|
const trimmed = stdout.trim();
|
|
8
28
|
if (!trimmed) {
|
|
9
29
|
return [];
|
|
10
30
|
}
|
|
11
|
-
|
|
12
|
-
|
|
31
|
+
// Each fallback assumes more than the last, so the least invasive repair that
|
|
32
|
+
// works is the one that gets used.
|
|
33
|
+
for (const candidate of [trimmed, repairPathSeparators(trimmed), repairInvalidEscapes(trimmed)]) {
|
|
34
|
+
try {
|
|
35
|
+
return JSON.parse(candidate).diagnostics ?? [];
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Let the caller record a parse failure; a tool whose output cannot be read
|
|
42
|
+
// has not checked anything, and must not look like a clean run.
|
|
43
|
+
throw new SyntaxError("Biome output was not valid JSON, even after repairing path separators.");
|
|
44
|
+
}
|
|
45
|
+
function readMessage(item) {
|
|
46
|
+
if (typeof item.message === "string") {
|
|
47
|
+
return item.message;
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(item.message)) {
|
|
50
|
+
const text = item.message
|
|
51
|
+
.map((chunk) => (typeof chunk === "string" ? chunk : (chunk.content ?? "")))
|
|
52
|
+
.join("")
|
|
53
|
+
.trim();
|
|
54
|
+
if (text) {
|
|
55
|
+
return text;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return item.description;
|
|
59
|
+
}
|
|
60
|
+
function readFile(item) {
|
|
61
|
+
const locationPath = item.location?.path;
|
|
62
|
+
const file = typeof locationPath === "string" ? locationPath : locationPath?.file;
|
|
63
|
+
return file?.replaceAll("\\", "/");
|
|
13
64
|
}
|
|
14
65
|
function mapSeverity(level) {
|
|
66
|
+
if (level === "fatal") {
|
|
67
|
+
return "high";
|
|
68
|
+
}
|
|
15
69
|
if (level === "error") {
|
|
16
70
|
return "medium";
|
|
17
71
|
}
|
|
@@ -20,6 +74,49 @@ function mapSeverity(level) {
|
|
|
20
74
|
}
|
|
21
75
|
return "info";
|
|
22
76
|
}
|
|
77
|
+
/** Biome reports zero-based line and column numbers; editors and reports use one-based. */
|
|
78
|
+
function toOneBased(value) {
|
|
79
|
+
return typeof value === "number" ? value + 1 : undefined;
|
|
80
|
+
}
|
|
81
|
+
function readLocation(location) {
|
|
82
|
+
if (!location) {
|
|
83
|
+
return {};
|
|
84
|
+
}
|
|
85
|
+
if (location.start) {
|
|
86
|
+
return {
|
|
87
|
+
startLine: toOneBased(location.start.line),
|
|
88
|
+
endLine: toOneBased(location.end?.line ?? location.start.line),
|
|
89
|
+
startColumn: toOneBased(location.start.column)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const span = location.span;
|
|
93
|
+
if (!span) {
|
|
94
|
+
return {};
|
|
95
|
+
}
|
|
96
|
+
if (Array.isArray(span)) {
|
|
97
|
+
const [start, end] = span;
|
|
98
|
+
return {
|
|
99
|
+
startOffset: typeof start === "number" ? start : undefined,
|
|
100
|
+
endOffset: typeof end === "number" ? end : undefined
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
startLine: toOneBased(span.start?.line),
|
|
105
|
+
endLine: toOneBased(span.end?.line),
|
|
106
|
+
startColumn: toOneBased(span.start?.column)
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Biome's rule categories double as its rule identifiers, and the safe-fix
|
|
111
|
+
* boundary follows the rule group: formatting and simple lint rules are safe to
|
|
112
|
+
* apply unattended, while `suspicious`/`security` rules generally need a human.
|
|
113
|
+
*/
|
|
114
|
+
function isSafeToAutofix(category) {
|
|
115
|
+
if (!category) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
return /^(?:format|lint\/(?:style|complexity|correctness|performance|nursery))/.test(category);
|
|
119
|
+
}
|
|
23
120
|
exports.biomeAdapter = {
|
|
24
121
|
id: "biome",
|
|
25
122
|
category: "correctness",
|
|
@@ -36,25 +133,43 @@ exports.biomeAdapter = {
|
|
|
36
133
|
};
|
|
37
134
|
},
|
|
38
135
|
parseResult(result, ctx) {
|
|
39
|
-
return parseBiomeOutput(result.stdout).map((item, index) =>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
136
|
+
return parseBiomeOutput(result.stdout).map((item, index) => {
|
|
137
|
+
const rawFile = readFile(item);
|
|
138
|
+
const file = (0, finding_1.normalizeFilePath)(rawFile, ctx.root);
|
|
139
|
+
const location = readLocation(item.location);
|
|
140
|
+
const safeToAutofix = isSafeToAutofix(item.category);
|
|
141
|
+
return {
|
|
142
|
+
id: `biome:${file ?? "unknown"}:${location.startOffset ?? location.startLine ?? index}:${item.category ?? index}`,
|
|
143
|
+
source: "biome",
|
|
144
|
+
category: "correctness",
|
|
145
|
+
severity: mapSeverity(item.severity),
|
|
146
|
+
confidence: "high",
|
|
147
|
+
title: item.category ?? "biome",
|
|
148
|
+
message: readMessage(item) ?? "Biome reported an issue.",
|
|
149
|
+
file,
|
|
150
|
+
startLine: location.startLine,
|
|
151
|
+
endLine: location.endLine,
|
|
152
|
+
startColumn: location.startColumn,
|
|
153
|
+
isNew: true,
|
|
154
|
+
isAutofixable: true,
|
|
155
|
+
safeToAutofix,
|
|
156
|
+
// Point the fix at the file that needs it rather than the whole
|
|
157
|
+
// repository, so applying one finding's fix cannot rewrite unrelated code.
|
|
158
|
+
fixCommand: file ? `biome check ${file} --write` : "biome check . --write",
|
|
159
|
+
agentInstruction: safeToAutofix
|
|
160
|
+
? "Apply Biome's safe write mode for this file."
|
|
161
|
+
: "Review this rule before applying Biome's fix; it can change behaviour.",
|
|
162
|
+
tags: ["javascript", "typescript", ...(item.tags ?? [])],
|
|
163
|
+
evidence: {
|
|
164
|
+
toolRawId: item.category,
|
|
165
|
+
// Offsets are converted to line and column during normalization, which
|
|
166
|
+
// is where every tool's position model is reconciled.
|
|
167
|
+
startOffset: location.startOffset,
|
|
168
|
+
endOffset: location.endOffset
|
|
169
|
+
},
|
|
170
|
+
scoreImpact: 0
|
|
171
|
+
};
|
|
172
|
+
});
|
|
58
173
|
},
|
|
59
174
|
buildFixCommand(ctx) {
|
|
60
175
|
const targets = (0, shared_1.adapterTargets)(ctx, /\.(?:js|jsx|ts|tsx|json|jsonc)$/i);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Finding } from "../core/finding";
|
|
2
|
+
import { type RepoGraph } from "../core/repoGraph";
|
|
3
|
+
import type { ToolAdapter } from "./shared";
|
|
4
|
+
export declare function analyzeFlows(graph: RepoGraph, options?: {
|
|
5
|
+
reportHeuristics?: boolean;
|
|
6
|
+
}): Finding[];
|
|
7
|
+
export declare const flowDoctorAdapter: ToolAdapter;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.flowDoctorAdapter = void 0;
|
|
4
|
+
exports.analyzeFlows = analyzeFlows;
|
|
5
|
+
const repoGraph_1 = require("../core/repoGraph");
|
|
6
|
+
function findingBase(partial) {
|
|
7
|
+
return {
|
|
8
|
+
isNew: true,
|
|
9
|
+
isAutofixable: false,
|
|
10
|
+
safeToAutofix: false,
|
|
11
|
+
scoreImpact: 0,
|
|
12
|
+
tags: partial.tags ?? ["flow"],
|
|
13
|
+
...partial
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function describeRoute(route) {
|
|
17
|
+
return `${route.method} ${route.path} (${route.file}:${route.line})`;
|
|
18
|
+
}
|
|
19
|
+
function mismatchFinding(call, routes, verified) {
|
|
20
|
+
const available = routes.slice(0, 6).map(describeRoute).join("; ");
|
|
21
|
+
return findingBase({
|
|
22
|
+
id: `flow-doctor:${call.file}:${call.line}:route-mismatch`,
|
|
23
|
+
source: "flow-doctor",
|
|
24
|
+
category: "correctness",
|
|
25
|
+
severity: verified ? "high" : "medium",
|
|
26
|
+
confidence: verified ? "high" : "medium",
|
|
27
|
+
evidenceGrade: verified ? "verified" : "heuristic",
|
|
28
|
+
title: "HTTP call has no matching backend route",
|
|
29
|
+
message: `${call.method} ${call.path} has no matching server route.`,
|
|
30
|
+
file: call.file,
|
|
31
|
+
startLine: call.line,
|
|
32
|
+
agentInstruction: `Add a ${call.method} handler for ${call.path}, or change the client call to a route the server actually exposes.`,
|
|
33
|
+
evidence: { toolRawId: "flow-route-mismatch", detectionPath: available },
|
|
34
|
+
remediation: {
|
|
35
|
+
kind: "code",
|
|
36
|
+
steps: [
|
|
37
|
+
`Align the client ${call.method} ${call.path} call with an existing route, or add that route on the server.`
|
|
38
|
+
],
|
|
39
|
+
requiredEvidence: "A server handler exists for the same method and path."
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function heuristicCallFinding(call) {
|
|
44
|
+
return findingBase({
|
|
45
|
+
id: `flow-doctor:${call.file}:${call.line}:dynamic-route`,
|
|
46
|
+
source: "flow-doctor",
|
|
47
|
+
category: "correctness",
|
|
48
|
+
severity: "low",
|
|
49
|
+
confidence: "low",
|
|
50
|
+
evidenceGrade: "heuristic",
|
|
51
|
+
title: "Dynamic HTTP path could not be verified",
|
|
52
|
+
message: `Call uses a constructed path (${call.path}); Flow Doctor cannot prove a route match.`,
|
|
53
|
+
file: call.file,
|
|
54
|
+
startLine: call.line,
|
|
55
|
+
agentInstruction: "Leave this unless a concrete method/path mismatch is visible nearby.",
|
|
56
|
+
evidence: { toolRawId: "flow-dynamic-path" },
|
|
57
|
+
tags: ["flow", "heuristic"]
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function errorPathFinding(file, line, kind, detail) {
|
|
61
|
+
const verified = kind === "empty_handler" || kind === "success_after_failure";
|
|
62
|
+
return findingBase({
|
|
63
|
+
id: `flow-doctor:${file}:${line}:${kind}`,
|
|
64
|
+
source: "flow-doctor",
|
|
65
|
+
category: "correctness",
|
|
66
|
+
severity: kind === "success_after_failure" ? "high" : "medium",
|
|
67
|
+
confidence: "high",
|
|
68
|
+
evidenceGrade: verified ? "verified" : "heuristic",
|
|
69
|
+
title: kind === "empty_handler" ? "Swallowed error path" : "Success response after a caught failure",
|
|
70
|
+
message: detail,
|
|
71
|
+
file,
|
|
72
|
+
startLine: line,
|
|
73
|
+
agentInstruction: kind === "empty_handler"
|
|
74
|
+
? "Log, rethrow, or return an explicit error from this handler. Do not leave it empty."
|
|
75
|
+
: "Return a failure status from the catch/except path, or rethrow after recording the error.",
|
|
76
|
+
evidence: { toolRawId: `flow-${kind}` }
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function missingHandlerFinding(route) {
|
|
80
|
+
return findingBase({
|
|
81
|
+
id: `flow-doctor:${route.file}:${route.line}:missing-handler`,
|
|
82
|
+
source: "flow-doctor",
|
|
83
|
+
category: "correctness",
|
|
84
|
+
severity: "high",
|
|
85
|
+
confidence: "high",
|
|
86
|
+
evidenceGrade: "verified",
|
|
87
|
+
title: "Route handler is not defined",
|
|
88
|
+
message: `${route.method} ${route.path} is wired to ${route.handler}, but that function is not defined or imported.`,
|
|
89
|
+
file: route.file,
|
|
90
|
+
startLine: route.line,
|
|
91
|
+
agentInstruction: `Define ${route.handler} or point this route at a function that exists.`,
|
|
92
|
+
evidence: { toolRawId: "flow-missing-handler" },
|
|
93
|
+
remediation: {
|
|
94
|
+
kind: "code",
|
|
95
|
+
steps: [`Add ${route.handler} in this file or import it, then keep the ${route.method} ${route.path} wiring.`],
|
|
96
|
+
requiredEvidence: `A function named ${route.handler} is defined or imported.`
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function orphanedHandlerFinding(symbol) {
|
|
101
|
+
return findingBase({
|
|
102
|
+
id: `flow-doctor:${symbol.file}:${symbol.line}:orphaned-handler`,
|
|
103
|
+
source: "flow-doctor",
|
|
104
|
+
category: "correctness",
|
|
105
|
+
severity: "medium",
|
|
106
|
+
confidence: "high",
|
|
107
|
+
evidenceGrade: "verified",
|
|
108
|
+
title: "Unreachable handler in a route file",
|
|
109
|
+
message: `${symbol.name} is defined next to routes but is never called and is not wired to any route.`,
|
|
110
|
+
file: symbol.file,
|
|
111
|
+
startLine: symbol.line,
|
|
112
|
+
agentInstruction: `Wire ${symbol.name} to a route, call it, or delete it if it is leftover.`,
|
|
113
|
+
evidence: { toolRawId: "flow-orphaned-handler" }
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function handlerIsBound(route) {
|
|
117
|
+
return Boolean(route.handlerFile || route.handlerExternal || route.handlerMember);
|
|
118
|
+
}
|
|
119
|
+
function isReferenced(symbol, graph) {
|
|
120
|
+
if (graph.routes.some((route) => route.handler === symbol.name && (route.handlerFile === symbol.file || route.file === symbol.file))) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
return graph.calls.some((call) => call.callee === symbol.name && call.file === symbol.file && call.line !== symbol.line);
|
|
124
|
+
}
|
|
125
|
+
function analyzeFlows(graph, options = {}) {
|
|
126
|
+
const findings = [];
|
|
127
|
+
const reportHeuristics = options.reportHeuristics ?? false;
|
|
128
|
+
const backendPresent = graph.routes.length > 0;
|
|
129
|
+
if (backendPresent) {
|
|
130
|
+
for (const call of graph.httpCalls) {
|
|
131
|
+
if (call.absolute) {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (call.dynamic || !call.methodExplicit) {
|
|
135
|
+
if (reportHeuristics) {
|
|
136
|
+
findings.push(heuristicCallFinding(call));
|
|
137
|
+
}
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const match = graph.routes.some((route) => (0, repoGraph_1.routeMatchesCall)(call, route));
|
|
141
|
+
if (match) {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const samePath = graph.routes.some((route) => (0, repoGraph_1.pathsCompatible)(call.path, route.path));
|
|
145
|
+
// Same path, wrong method is a real bug. Unrelated paths in a monorepo are not.
|
|
146
|
+
if (samePath) {
|
|
147
|
+
findings.push(mismatchFinding(call, graph.routes, true));
|
|
148
|
+
}
|
|
149
|
+
else if (reportHeuristics) {
|
|
150
|
+
findings.push(mismatchFinding(call, graph.routes, false));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
for (const errorPath of graph.errorPaths) {
|
|
155
|
+
findings.push(errorPathFinding(errorPath.file, errorPath.line, errorPath.kind, errorPath.detail));
|
|
156
|
+
}
|
|
157
|
+
for (const route of graph.routes) {
|
|
158
|
+
if (!route.handler || route.handlerMember || handlerIsBound(route)) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (route.handler.length < 2) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
findings.push(missingHandlerFinding(route));
|
|
165
|
+
}
|
|
166
|
+
const routerFiles = new Set(graph.routes.map((route) => route.file));
|
|
167
|
+
for (const symbol of graph.symbols) {
|
|
168
|
+
if (symbol.kind !== "function" || symbol.exported || symbol.name.startsWith("_")) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (!routerFiles.has(symbol.file)) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (isReferenced(symbol, graph)) {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
findings.push(orphanedHandlerFinding(symbol));
|
|
178
|
+
}
|
|
179
|
+
return findings;
|
|
180
|
+
}
|
|
181
|
+
exports.flowDoctorAdapter = {
|
|
182
|
+
id: "flow-doctor",
|
|
183
|
+
category: "correctness",
|
|
184
|
+
async detect(project, config) {
|
|
185
|
+
if (config.checks.flowAnalysis.enabled === false) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
return project.languages.length > 0;
|
|
189
|
+
},
|
|
190
|
+
async runStandalone(ctx) {
|
|
191
|
+
const graph = await (0, repoGraph_1.buildRepoGraph)(ctx.root, ctx.project.projectFiles);
|
|
192
|
+
return { findings: analyzeFlows(graph) };
|
|
193
|
+
},
|
|
194
|
+
installHint: "Built-in Flow Doctor. No external install."
|
|
195
|
+
};
|
|
@@ -14,10 +14,12 @@ exports.gitleaksAdapter = {
|
|
|
14
14
|
},
|
|
15
15
|
buildScanCommand(ctx) {
|
|
16
16
|
return {
|
|
17
|
+
tool: "gitleaks",
|
|
17
18
|
cmd: "gitleaks",
|
|
18
19
|
args: ["detect", "--no-banner", "--redact", "--report-format", "json", "--report-path", "-"],
|
|
19
20
|
cwd: ctx.root,
|
|
20
|
-
timeoutMs: 60_000
|
|
21
|
+
timeoutMs: 60_000,
|
|
22
|
+
runtime: ctx.toolRuntime
|
|
21
23
|
};
|
|
22
24
|
},
|
|
23
25
|
parseResult(result, ctx) {
|
|
@@ -43,5 +45,5 @@ exports.gitleaksAdapter = {
|
|
|
43
45
|
scoreImpact: 0
|
|
44
46
|
}));
|
|
45
47
|
},
|
|
46
|
-
installHint: "
|
|
48
|
+
installHint: "VibeDoctor provisions a pinned Gitleaks into ~/.cache/vibedoctor when needed. To use a project-local copy, put gitleaks on PATH."
|
|
47
49
|
};
|
package/dist/adapters/index.d.ts
CHANGED
package/dist/adapters/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.telemetryDetectorAdapter = exports.dpdpAdapter = exports.privacyDetectorAdapter = exports.vultureAdapter = exports.vitestAdapter = exports.tscAdapter = exports.semgrepAdapter = exports.ruffAdapter = exports.radonAdapter = exports.pyrightAdapter = exports.presidioAdapter = exports.osvScannerAdapter = exports.lizardAdapter = exports.knipAdapter = exports.jscpdAdapter = exports.jestAdapter = exports.gitleaksAdapter = exports.deptryAdapter = exports.coveragePyAdapter = exports.biomeAdapter = void 0;
|
|
3
|
+
exports.flowDoctorAdapter = exports.telemetryDetectorAdapter = exports.dpdpAdapter = exports.privacyDetectorAdapter = exports.vultureAdapter = exports.vitestAdapter = exports.tscAdapter = exports.semgrepAdapter = exports.ruffAdapter = exports.radonAdapter = exports.pyrightAdapter = exports.presidioAdapter = exports.osvScannerAdapter = exports.lizardAdapter = exports.knipAdapter = exports.jscpdAdapter = exports.jestAdapter = exports.gitleaksAdapter = exports.deptryAdapter = exports.coveragePyAdapter = exports.biomeAdapter = void 0;
|
|
4
4
|
var biome_1 = require("./biome");
|
|
5
5
|
Object.defineProperty(exports, "biomeAdapter", { enumerable: true, get: function () { return biome_1.biomeAdapter; } });
|
|
6
6
|
var coveragePy_1 = require("./coveragePy");
|
|
@@ -41,3 +41,5 @@ var dpdp_1 = require("./dpdp");
|
|
|
41
41
|
Object.defineProperty(exports, "dpdpAdapter", { enumerable: true, get: function () { return dpdp_1.dpdpAdapter; } });
|
|
42
42
|
var telemetryDetector_1 = require("./telemetryDetector");
|
|
43
43
|
Object.defineProperty(exports, "telemetryDetectorAdapter", { enumerable: true, get: function () { return telemetryDetector_1.telemetryDetectorAdapter; } });
|
|
44
|
+
var flowDoctor_1 = require("./flowDoctor");
|
|
45
|
+
Object.defineProperty(exports, "flowDoctorAdapter", { enumerable: true, get: function () { return flowDoctor_1.flowDoctorAdapter; } });
|