@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.
- package/README.md +86 -0
- package/dist/adapters/biome.js +135 -21
- package/dist/adapters/osvScanner.js +136 -17
- package/dist/adapters/presidio.js +3 -1
- package/dist/cli/commands/init.js +105 -50
- package/dist/cli/commands/privacyReview.js +3 -4
- package/dist/cli/commands/setup.d.ts +13 -17
- package/dist/cli/commands/setup.js +138 -200
- package/dist/core/capability.d.ts +92 -0
- package/dist/core/capability.js +122 -0
- package/dist/core/config.d.ts +36 -0
- package/dist/core/config.js +105 -3
- package/dist/core/credentialHeuristics.d.ts +28 -0
- package/dist/core/credentialHeuristics.js +179 -0
- package/dist/core/engine.d.ts +21 -0
- package/dist/core/engine.js +466 -85
- 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 +124 -0
- package/dist/core/finding.js +62 -5
- package/dist/core/findingNormalizer.d.ts +33 -0
- package/dist/core/findingNormalizer.js +171 -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/scanPlanner.d.ts +12 -0
- package/dist/core/scanPlanner.js +61 -37
- 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 +247 -0
- package/dist/core/toolRunner.d.ts +23 -2
- package/dist/core/toolRunner.js +61 -93
- package/dist/core/toolVerification.d.ts +87 -0
- package/dist/core/toolVerification.js +370 -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/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 +1 -1
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TOOL_REGISTRY = void 0;
|
|
7
|
+
exports.getToolEntry = getToolEntry;
|
|
8
|
+
exports.registryExecutables = registryExecutables;
|
|
9
|
+
exports.toolsForPriority = toolsForPriority;
|
|
10
|
+
exports.installHintFor = installHintFor;
|
|
11
|
+
exports.readDeclaredNodeRequirement = readDeclaredNodeRequirement;
|
|
12
|
+
const node_fs_1 = require("node:fs");
|
|
13
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
14
|
+
exports.TOOL_REGISTRY = [
|
|
15
|
+
{
|
|
16
|
+
id: "custom-leftovers",
|
|
17
|
+
ecosystem: "built-in",
|
|
18
|
+
priority: "essential",
|
|
19
|
+
reason: "Finds stale TODOs, commented-out code, legacy fallback paths, and AI leftovers without any external install."
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: "custom-dead-chain",
|
|
23
|
+
ecosystem: "built-in",
|
|
24
|
+
priority: "essential",
|
|
25
|
+
reason: "Finds isolated file clusters after external dead-code tools report candidates."
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: "custom-refactor",
|
|
29
|
+
ecosystem: "built-in",
|
|
30
|
+
priority: "essential",
|
|
31
|
+
reason: "Finds large or complex files that need tests before refactor work."
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: "privacy-detector",
|
|
35
|
+
ecosystem: "built-in",
|
|
36
|
+
priority: "essential",
|
|
37
|
+
reason: "Finds personal-data and Privacy Review signals without sending data to an external service."
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: "tsc",
|
|
41
|
+
packageName: "typescript",
|
|
42
|
+
executable: "tsc",
|
|
43
|
+
ecosystem: "npm",
|
|
44
|
+
priority: "essential",
|
|
45
|
+
languages: ["typescript"],
|
|
46
|
+
runtime: "node",
|
|
47
|
+
probeArgs: ["--version"],
|
|
48
|
+
reason: "TypeScript correctness signal."
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: "biome",
|
|
52
|
+
packageName: "@biomejs/biome",
|
|
53
|
+
executable: "biome",
|
|
54
|
+
ecosystem: "npm",
|
|
55
|
+
priority: "essential",
|
|
56
|
+
languages: ["javascript", "typescript"],
|
|
57
|
+
runtime: "node",
|
|
58
|
+
probeArgs: ["--version"],
|
|
59
|
+
reason: "Fast JS/TS lint and safe formatting signal."
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: "knip",
|
|
63
|
+
packageName: "knip",
|
|
64
|
+
executable: "knip",
|
|
65
|
+
ecosystem: "npm",
|
|
66
|
+
priority: "essential",
|
|
67
|
+
languages: ["javascript", "typescript"],
|
|
68
|
+
runtime: "node",
|
|
69
|
+
probeArgs: ["--version"],
|
|
70
|
+
reason: "Unused files, exports, and dependency signal for JS/TS."
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: "jscpd",
|
|
74
|
+
packageName: "jscpd",
|
|
75
|
+
executable: "jscpd",
|
|
76
|
+
ecosystem: "npm",
|
|
77
|
+
priority: "recommended",
|
|
78
|
+
languages: ["javascript", "typescript"],
|
|
79
|
+
runtime: "node",
|
|
80
|
+
probeArgs: ["--version"],
|
|
81
|
+
reason: "Duplication signal for refactor planning."
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: "ruff",
|
|
85
|
+
packageName: "ruff",
|
|
86
|
+
executable: "ruff",
|
|
87
|
+
ecosystem: "python",
|
|
88
|
+
priority: "essential",
|
|
89
|
+
languages: ["python"],
|
|
90
|
+
runtime: "python",
|
|
91
|
+
probeArgs: ["--version"],
|
|
92
|
+
reason: "Python lint and safe-fix signal."
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: "pyright",
|
|
96
|
+
packageName: "pyright",
|
|
97
|
+
executable: "pyright",
|
|
98
|
+
ecosystem: "python",
|
|
99
|
+
priority: "essential",
|
|
100
|
+
languages: ["python"],
|
|
101
|
+
runtime: "python",
|
|
102
|
+
probeArgs: ["--version"],
|
|
103
|
+
reason: "Python type correctness signal."
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: "vulture",
|
|
107
|
+
packageName: "vulture",
|
|
108
|
+
executable: "vulture",
|
|
109
|
+
ecosystem: "python",
|
|
110
|
+
priority: "essential",
|
|
111
|
+
languages: ["python"],
|
|
112
|
+
runtime: "python",
|
|
113
|
+
probeArgs: ["--version"],
|
|
114
|
+
reason: "Python dead-code signal."
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
id: "coverage.py",
|
|
118
|
+
packageName: "coverage",
|
|
119
|
+
executable: "coverage",
|
|
120
|
+
ecosystem: "python",
|
|
121
|
+
priority: "recommended",
|
|
122
|
+
languages: ["python"],
|
|
123
|
+
runtime: "python",
|
|
124
|
+
probeArgs: ["--version"],
|
|
125
|
+
reason: "Python coverage signal."
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
id: "radon",
|
|
129
|
+
packageName: "radon",
|
|
130
|
+
executable: "radon",
|
|
131
|
+
ecosystem: "python",
|
|
132
|
+
priority: "recommended",
|
|
133
|
+
languages: ["python"],
|
|
134
|
+
runtime: "python",
|
|
135
|
+
probeArgs: ["--version"],
|
|
136
|
+
reason: "Python complexity signal."
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: "deptry",
|
|
140
|
+
packageName: "deptry",
|
|
141
|
+
executable: "deptry",
|
|
142
|
+
ecosystem: "python",
|
|
143
|
+
priority: "recommended",
|
|
144
|
+
languages: ["python"],
|
|
145
|
+
runtime: "python",
|
|
146
|
+
probeArgs: ["--version"],
|
|
147
|
+
reason: "Python dependency hygiene signal."
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
id: "gitleaks",
|
|
151
|
+
executable: "gitleaks",
|
|
152
|
+
ecosystem: "manual",
|
|
153
|
+
priority: "essential",
|
|
154
|
+
probeArgs: ["version"],
|
|
155
|
+
reason: "Secret detection across every repository.",
|
|
156
|
+
installHint: "Install Gitleaks from https://gitleaks.io/ or your OS package manager."
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
id: "osv-scanner",
|
|
160
|
+
executable: "osv-scanner",
|
|
161
|
+
ecosystem: "manual",
|
|
162
|
+
priority: "essential",
|
|
163
|
+
requiresLockfile: true,
|
|
164
|
+
probeArgs: ["--version"],
|
|
165
|
+
reason: "Known-vulnerability detection for dependency lockfiles.",
|
|
166
|
+
installHint: "Install OSV-Scanner from https://google.github.io/osv-scanner/ or your OS package manager."
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
id: "lizard",
|
|
170
|
+
executable: "lizard",
|
|
171
|
+
ecosystem: "manual",
|
|
172
|
+
priority: "recommended",
|
|
173
|
+
runtime: "python",
|
|
174
|
+
probeArgs: ["--version"],
|
|
175
|
+
reason: "Function-level complexity and code size hotspots (great for spotting refactor candidates).",
|
|
176
|
+
installHint: "Install Lizard with: pipx install lizard, uv tool install lizard, or your OS package manager."
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
id: "semgrep",
|
|
180
|
+
executable: "semgrep",
|
|
181
|
+
ecosystem: "manual",
|
|
182
|
+
priority: "recommended",
|
|
183
|
+
runtime: "python",
|
|
184
|
+
probeArgs: ["--version"],
|
|
185
|
+
reason: "Additional security and correctness rules.",
|
|
186
|
+
installHint: "Install Semgrep with: pipx install semgrep, uv tool install semgrep, or your OS package manager."
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
id: "presidio",
|
|
190
|
+
ecosystem: "manual",
|
|
191
|
+
priority: "recommended",
|
|
192
|
+
runtime: "python",
|
|
193
|
+
// Presidio ships no console script; the scanner drives it as a Python module,
|
|
194
|
+
// so verification must import the module rather than look for a binary.
|
|
195
|
+
moduleProbe: { runtime: "python", module: "presidio_analyzer" },
|
|
196
|
+
reason: "External PII analyzer used by privacy + DPDP scans by default (skipped gracefully if missing). The normal privacy and DPDP opt-outs are independent.",
|
|
197
|
+
installHint: "Install in the project Python environment with: python -m pip install presidio-analyzer"
|
|
198
|
+
}
|
|
199
|
+
];
|
|
200
|
+
const BY_ID = new Map(exports.TOOL_REGISTRY.map((entry) => [entry.id, entry]));
|
|
201
|
+
function getToolEntry(id) {
|
|
202
|
+
return BY_ID.get(id);
|
|
203
|
+
}
|
|
204
|
+
/** Command names the scanner may invoke, for availability probing. */
|
|
205
|
+
function registryExecutables() {
|
|
206
|
+
return Array.from(new Set(exports.TOOL_REGISTRY.map((entry) => entry.executable).filter((name) => Boolean(name))));
|
|
207
|
+
}
|
|
208
|
+
function toolsForPriority(priority) {
|
|
209
|
+
if (priority === "all") {
|
|
210
|
+
return exports.TOOL_REGISTRY;
|
|
211
|
+
}
|
|
212
|
+
if (priority === "recommended") {
|
|
213
|
+
return exports.TOOL_REGISTRY;
|
|
214
|
+
}
|
|
215
|
+
return exports.TOOL_REGISTRY.filter((entry) => entry.priority === "essential");
|
|
216
|
+
}
|
|
217
|
+
function installHintFor(entry) {
|
|
218
|
+
if (entry.installHint) {
|
|
219
|
+
return entry.installHint;
|
|
220
|
+
}
|
|
221
|
+
if (entry.ecosystem === "npm" && entry.packageName) {
|
|
222
|
+
return `Install with: npm install -D ${entry.packageName}`;
|
|
223
|
+
}
|
|
224
|
+
if (entry.ecosystem === "python" && entry.packageName) {
|
|
225
|
+
return `Install with: python -m pip install -U ${entry.packageName}`;
|
|
226
|
+
}
|
|
227
|
+
return `Install ${entry.id} and make sure it is on PATH.`;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Reads the runtime requirement a tool declares for itself, from the package
|
|
231
|
+
* metadata of the copy that is actually installed. Hardcoding "knip needs Node
|
|
232
|
+
* 20.19" would go stale on the next release; the package says so itself.
|
|
233
|
+
*/
|
|
234
|
+
async function readDeclaredNodeRequirement(root, packageName) {
|
|
235
|
+
if (!packageName) {
|
|
236
|
+
return {};
|
|
237
|
+
}
|
|
238
|
+
const manifest = node_path_1.default.join(root, "node_modules", ...packageName.split("/"), "package.json");
|
|
239
|
+
try {
|
|
240
|
+
const parsed = JSON.parse(await node_fs_1.promises.readFile(manifest, "utf8"));
|
|
241
|
+
const range = parsed.engines?.node;
|
|
242
|
+
return range ? { range, source: `${packageName} engines.node` } : {};
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
return {};
|
|
246
|
+
}
|
|
247
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { buildCommandEnv, getLocalToolSearchPaths } from "./executable";
|
|
2
|
+
export { buildCommandEnv, getLocalToolSearchPaths };
|
|
1
3
|
export type CommandSpec = {
|
|
2
4
|
cmd: string;
|
|
3
5
|
args: string[];
|
|
@@ -13,10 +15,29 @@ export type ToolResult = {
|
|
|
13
15
|
durationMs: number;
|
|
14
16
|
status: "ok" | "error" | "skipped" | "timeout";
|
|
15
17
|
installHint?: string;
|
|
18
|
+
/** Absolute path of the executable that ran, so reports can prove what was invoked. */
|
|
19
|
+
resolvedPath?: string;
|
|
20
|
+
/** Set when the run covered less than the requested scope (scoped timeout fallback). */
|
|
21
|
+
coverage?: ToolCoverage;
|
|
22
|
+
};
|
|
23
|
+
export type ToolCoverage = {
|
|
24
|
+
scope: "full" | "scoped" | "none";
|
|
25
|
+
detail: string;
|
|
26
|
+
targetsRequested?: number;
|
|
27
|
+
targetsScanned?: number;
|
|
16
28
|
};
|
|
17
|
-
export declare function getLocalToolSearchPaths(cwd: string | undefined): string[];
|
|
18
|
-
export declare function buildCommandEnv(cwd: string | undefined, overrides: NodeJS.ProcessEnv | undefined): NodeJS.ProcessEnv;
|
|
19
29
|
export declare function commandExistsOnWindowsPath(command: string, cwd?: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Quotes one argument for a cmd.exe command line.
|
|
32
|
+
*
|
|
33
|
+
* Node's `shell: true` joins the command and arguments with spaces and hands the
|
|
34
|
+
* result to cmd.exe verbatim (the behaviour deprecated as DEP0190), so an
|
|
35
|
+
* argument containing a space, a quote, or a shell metacharacter — a repository
|
|
36
|
+
* path under "Program Files", a glob, a rule id with a pipe — arrives split or
|
|
37
|
+
* partly interpreted by the shell. Arguments with nothing special in them are
|
|
38
|
+
* left exactly as they were, so this only changes the cases that were broken.
|
|
39
|
+
*/
|
|
40
|
+
export declare function quoteForWindowsShell(argument: string): string;
|
|
20
41
|
export declare function runCommand(spec: CommandSpec, installHint?: string): Promise<ToolResult>;
|
|
21
42
|
export declare function runCommands(commands: Array<{
|
|
22
43
|
id: string;
|
package/dist/core/toolRunner.js
CHANGED
|
@@ -3,113 +3,78 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getLocalToolSearchPaths =
|
|
7
|
-
exports.buildCommandEnv = buildCommandEnv;
|
|
6
|
+
exports.getLocalToolSearchPaths = exports.buildCommandEnv = void 0;
|
|
8
7
|
exports.commandExistsOnWindowsPath = commandExistsOnWindowsPath;
|
|
8
|
+
exports.quoteForWindowsShell = quoteForWindowsShell;
|
|
9
9
|
exports.runCommand = runCommand;
|
|
10
10
|
exports.runCommands = runCommands;
|
|
11
11
|
const node_path_1 = __importDefault(require("node:path"));
|
|
12
|
-
const node_fs_1 = require("node:fs");
|
|
13
12
|
const node_child_process_1 = require("node:child_process");
|
|
14
13
|
const node_child_process_2 = require("node:child_process");
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
["venv", "bin"]
|
|
21
|
-
];
|
|
22
|
-
function ancestorDirs(startDir) {
|
|
23
|
-
if (!startDir) {
|
|
24
|
-
return [];
|
|
25
|
-
}
|
|
26
|
-
const dirs = [];
|
|
27
|
-
let current = node_path_1.default.resolve(startDir);
|
|
28
|
-
while (true) {
|
|
29
|
-
dirs.push(current);
|
|
30
|
-
const parent = node_path_1.default.dirname(current);
|
|
31
|
-
if (parent === current) {
|
|
32
|
-
return dirs;
|
|
33
|
-
}
|
|
34
|
-
current = parent;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function getPathKey(env) {
|
|
38
|
-
return Object.keys(env).find((key) => key.toLowerCase() === "path") ?? "PATH";
|
|
39
|
-
}
|
|
40
|
-
function getLocalToolSearchPaths(cwd) {
|
|
41
|
-
const paths = ancestorDirs(cwd).flatMap((dir) => LOCAL_TOOL_PATHS.map((segments) => node_path_1.default.join(dir, ...segments)));
|
|
42
|
-
return Array.from(new Set(paths));
|
|
14
|
+
const executable_1 = require("./executable");
|
|
15
|
+
Object.defineProperty(exports, "buildCommandEnv", { enumerable: true, get: function () { return executable_1.buildCommandEnv; } });
|
|
16
|
+
Object.defineProperty(exports, "getLocalToolSearchPaths", { enumerable: true, get: function () { return executable_1.getLocalToolSearchPaths; } });
|
|
17
|
+
function commandExistsOnWindowsPath(command, cwd) {
|
|
18
|
+
return (0, executable_1.resolveExecutable)(command, cwd) !== undefined;
|
|
43
19
|
}
|
|
44
|
-
function
|
|
45
|
-
const
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
catch {
|
|
56
|
-
// Python user packages have not been installed for this account.
|
|
20
|
+
function resolveLaunchTarget(command, cwd, env) {
|
|
21
|
+
const resolved = (0, executable_1.resolveExecutable)(command, cwd, env);
|
|
22
|
+
if (resolved) {
|
|
23
|
+
if (resolved.requiresShell) {
|
|
24
|
+
// cmd.exe scripts must run through the shell; quote the resolved path so
|
|
25
|
+
// directories with spaces (e.g. "Program Files") do not break parsing.
|
|
26
|
+
return {
|
|
27
|
+
command: resolved.path.includes(" ") ? `"${resolved.path}"` : resolved.path,
|
|
28
|
+
useShell: true,
|
|
29
|
+
resolvedPath: resolved.path
|
|
30
|
+
};
|
|
57
31
|
}
|
|
32
|
+
return { command: resolved.path, useShell: false, resolvedPath: resolved.path };
|
|
58
33
|
}
|
|
59
|
-
|
|
60
|
-
|
|
34
|
+
if (process.platform === "win32" && !node_path_1.default.isAbsolute(command)) {
|
|
35
|
+
// Not found via PATH/PATHEXT probing. Fall back to the shell so commands that
|
|
36
|
+
// are only reachable through cmd.exe mechanisms (App Execution Aliases,
|
|
37
|
+
// App Paths registry entries) still launch, matching the previous behavior.
|
|
38
|
+
return { command, useShell: true };
|
|
61
39
|
}
|
|
62
|
-
return
|
|
40
|
+
return { command, useShell: false };
|
|
63
41
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
for (const extension of extensions) {
|
|
78
|
-
const candidate = node_path_1.default.join(directory, `${command}${extension}`);
|
|
79
|
-
if ((0, node_fs_1.existsSync)(candidate)) {
|
|
80
|
-
return candidate;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
function commandExistsOnWindowsPath(command, cwd) {
|
|
87
|
-
return findWindowsCommandOnPath(command, buildCommandEnv(cwd, undefined)) !== undefined;
|
|
88
|
-
}
|
|
89
|
-
function resolveWindowsCommand(command, env) {
|
|
90
|
-
if (process.platform !== "win32" || node_path_1.default.isAbsolute(command) || node_path_1.default.extname(command)) {
|
|
91
|
-
return { command, useShell: false };
|
|
42
|
+
/**
|
|
43
|
+
* Quotes one argument for a cmd.exe command line.
|
|
44
|
+
*
|
|
45
|
+
* Node's `shell: true` joins the command and arguments with spaces and hands the
|
|
46
|
+
* result to cmd.exe verbatim (the behaviour deprecated as DEP0190), so an
|
|
47
|
+
* argument containing a space, a quote, or a shell metacharacter — a repository
|
|
48
|
+
* path under "Program Files", a glob, a rule id with a pipe — arrives split or
|
|
49
|
+
* partly interpreted by the shell. Arguments with nothing special in them are
|
|
50
|
+
* left exactly as they were, so this only changes the cases that were broken.
|
|
51
|
+
*/
|
|
52
|
+
function quoteForWindowsShell(argument) {
|
|
53
|
+
if (argument === "") {
|
|
54
|
+
return '""';
|
|
92
55
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (/\.(?:cmd|bat)$/i.test(candidate)) {
|
|
96
|
-
// cmd.exe scripts must run through the shell; quote the resolved path so
|
|
97
|
-
// directories with spaces (e.g. "Program Files") do not break parsing.
|
|
98
|
-
return { command: candidate.includes(" ") ? `"${candidate}"` : candidate, useShell: true };
|
|
99
|
-
}
|
|
100
|
-
return { command: candidate, useShell: false };
|
|
56
|
+
if (!/[\s"&|<>^()%!]/.test(argument)) {
|
|
57
|
+
return argument;
|
|
101
58
|
}
|
|
102
|
-
//
|
|
103
|
-
//
|
|
104
|
-
|
|
105
|
-
|
|
59
|
+
// Double any backslashes that precede a quote or end the argument, so the
|
|
60
|
+
// receiving program's argv parser sees them as literal backslashes.
|
|
61
|
+
const escaped = argument.replace(/(\\*)"/g, '$1$1\\"').replace(/(\\*)$/, "$1$1");
|
|
62
|
+
// Quoting stops cmd.exe interpreting &, |, <, >, ^ and parentheses, but %VAR%
|
|
63
|
+
// still expands inside quotes and has no in-quote escape, so each % is moved
|
|
64
|
+
// outside the quoted run where a caret does escape it.
|
|
65
|
+
return `"${escaped}"`.split("%").join('"^%"');
|
|
106
66
|
}
|
|
107
67
|
async function runCommand(spec, installHint) {
|
|
108
68
|
const startedAt = Date.now();
|
|
109
|
-
const env = buildCommandEnv(spec.cwd, spec.env);
|
|
110
|
-
const resolved =
|
|
69
|
+
const env = (0, executable_1.buildCommandEnv)(spec.cwd, spec.env);
|
|
70
|
+
const resolved = resolveLaunchTarget(spec.cmd, spec.cwd, env);
|
|
71
|
+
// Build the shell command line here instead of letting spawn concatenate the
|
|
72
|
+
// arguments for us, which it does without any escaping.
|
|
73
|
+
const launch = resolved.useShell
|
|
74
|
+
? { command: [resolved.command, ...spec.args.map(quoteForWindowsShell)].join(" "), args: [] }
|
|
75
|
+
: { command: resolved.command, args: spec.args };
|
|
111
76
|
return new Promise((resolve) => {
|
|
112
|
-
const child = (0, node_child_process_1.spawn)(
|
|
77
|
+
const child = (0, node_child_process_1.spawn)(launch.command, launch.args, {
|
|
113
78
|
cwd: spec.cwd,
|
|
114
79
|
env,
|
|
115
80
|
shell: resolved.useShell,
|
|
@@ -155,7 +120,8 @@ async function runCommand(spec, installHint) {
|
|
|
155
120
|
exitCode: null,
|
|
156
121
|
durationMs: Date.now() - startedAt,
|
|
157
122
|
status: /ENOENT|not recognized/i.test(error.message) ? "skipped" : "error",
|
|
158
|
-
installHint
|
|
123
|
+
installHint,
|
|
124
|
+
resolvedPath: resolved.resolvedPath
|
|
159
125
|
});
|
|
160
126
|
});
|
|
161
127
|
child.on("close", (exitCode) => {
|
|
@@ -175,7 +141,8 @@ async function runCommand(spec, installHint) {
|
|
|
175
141
|
: /not recognized|not found|is not installed|no such file/i.test(stderr)
|
|
176
142
|
? "skipped"
|
|
177
143
|
: "error",
|
|
178
|
-
installHint
|
|
144
|
+
installHint,
|
|
145
|
+
resolvedPath: resolved.resolvedPath
|
|
179
146
|
});
|
|
180
147
|
});
|
|
181
148
|
if (spec.timeoutMs) {
|
|
@@ -201,7 +168,8 @@ async function runCommand(spec, installHint) {
|
|
|
201
168
|
exitCode: null,
|
|
202
169
|
durationMs: Date.now() - startedAt,
|
|
203
170
|
status: "timeout",
|
|
204
|
-
installHint
|
|
171
|
+
installHint,
|
|
172
|
+
resolvedPath: resolved.resolvedPath
|
|
205
173
|
});
|
|
206
174
|
}, spec.timeoutMs);
|
|
207
175
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type RuntimeEngine, type ToolRegistryEntry } from "./toolRegistry";
|
|
2
|
+
/**
|
|
3
|
+
* Proves a tool is usable rather than merely present.
|
|
4
|
+
*
|
|
5
|
+
* `setup --apply` used to report success when an install command exited zero.
|
|
6
|
+
* That is not the same claim as "the scanner can run this", and the two came
|
|
7
|
+
* apart in practice: a package installed into an interpreter that was not on
|
|
8
|
+
* PATH, or under a Node version too old to run it. Verification here resolves
|
|
9
|
+
* the executable through the scanner's own lookup, runs it, and records the
|
|
10
|
+
* concrete path and version — so a passing verification means the next scan
|
|
11
|
+
* will find the same binary.
|
|
12
|
+
*/
|
|
13
|
+
export type VerificationState =
|
|
14
|
+
/** Resolved, ran, and reported a version. */
|
|
15
|
+
"verified"
|
|
16
|
+
/** Nothing on PATH matches the executable. */
|
|
17
|
+
| "not_found"
|
|
18
|
+
/** Found on PATH but the probe failed, so the install is broken. */
|
|
19
|
+
| "broken"
|
|
20
|
+
/** Found, but the runtime it needs cannot run it. */
|
|
21
|
+
| "incompatible_runtime"
|
|
22
|
+
/** Cannot be verified from here (no probe declared); reported honestly, never as a pass. */
|
|
23
|
+
| "unverifiable";
|
|
24
|
+
export type ToolVerification = {
|
|
25
|
+
id: string;
|
|
26
|
+
state: VerificationState;
|
|
27
|
+
/** Absolute path of the executable that answered the probe. */
|
|
28
|
+
resolvedPath?: string;
|
|
29
|
+
/** Interpreter path, for tools driven as a module of another runtime. */
|
|
30
|
+
interpreterPath?: string;
|
|
31
|
+
version?: string;
|
|
32
|
+
/** The exact command line used to verify, so a user can rerun it by hand. */
|
|
33
|
+
probeCommand?: string;
|
|
34
|
+
runtime?: {
|
|
35
|
+
engine: RuntimeEngine;
|
|
36
|
+
version?: string;
|
|
37
|
+
requirement?: string;
|
|
38
|
+
requirementSource?: string;
|
|
39
|
+
compatible: boolean | "unknown";
|
|
40
|
+
};
|
|
41
|
+
reason: string;
|
|
42
|
+
remediation?: string;
|
|
43
|
+
};
|
|
44
|
+
export declare function isVerificationBlocking(verification: ToolVerification): boolean;
|
|
45
|
+
export type RuntimeProbe = {
|
|
46
|
+
engine: RuntimeEngine;
|
|
47
|
+
available: boolean;
|
|
48
|
+
command?: string;
|
|
49
|
+
resolvedPath?: string;
|
|
50
|
+
version?: string;
|
|
51
|
+
detail: string;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Locates a language runtime once per process. `python` being absent is the
|
|
55
|
+
* reason a whole family of installs silently fails, so it is reported as a
|
|
56
|
+
* first-class fact rather than inferred from a tool-level error message.
|
|
57
|
+
*/
|
|
58
|
+
export declare function probeRuntime(engine: RuntimeEngine, cwd: string): Promise<RuntimeProbe>;
|
|
59
|
+
export type RuntimeProbes = Partial<Record<RuntimeEngine, RuntimeProbe>>;
|
|
60
|
+
export declare function probeRuntimes(cwd: string, engines: RuntimeEngine[]): Promise<RuntimeProbes>;
|
|
61
|
+
/**
|
|
62
|
+
* Probes only the runtimes that a tool present on this machine actually needs.
|
|
63
|
+
*
|
|
64
|
+
* Probing every runtime a registry entry mentions meant spawning a Python
|
|
65
|
+
* interpreter on repositories with no Python tooling installed, on every scan.
|
|
66
|
+
*/
|
|
67
|
+
export declare function probeRuntimesFor(entries: ToolRegistryEntry[], cwd: string, depth?: VerificationDepth): Promise<RuntimeProbes>;
|
|
68
|
+
/**
|
|
69
|
+
* How hard to look.
|
|
70
|
+
*
|
|
71
|
+
* `execute` runs each tool's probe, which is what `setup` needs: there is no
|
|
72
|
+
* later scan to fall back on, so an unproven tool must not be reported as
|
|
73
|
+
* installed. `resolve` stops at locating the executable and checking runtime
|
|
74
|
+
* compatibility, which is what a scan needs — the scan is about to invoke the
|
|
75
|
+
* tool anyway, and paying for a second process per tool would add tens of
|
|
76
|
+
* seconds to every run to learn something the run itself reveals.
|
|
77
|
+
*/
|
|
78
|
+
export type VerificationDepth = "resolve" | "execute";
|
|
79
|
+
export type VerifyToolOptions = {
|
|
80
|
+
root: string;
|
|
81
|
+
runtimes: RuntimeProbes;
|
|
82
|
+
depth?: VerificationDepth;
|
|
83
|
+
};
|
|
84
|
+
export declare function verifyTool(entry: ToolRegistryEntry, options: VerifyToolOptions): Promise<ToolVerification>;
|
|
85
|
+
export declare function verifyTools(entries: ToolRegistryEntry[], root: string, depth?: VerificationDepth): Promise<ToolVerification[]>;
|
|
86
|
+
export declare function summarizeVerification(verification: ToolVerification): string;
|
|
87
|
+
export declare function formatVersionForDisplay(value: string | undefined): string;
|