@neuralaxis/vibedoctor 0.2.1 → 0.3.0

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 (57) hide show
  1. package/README.md +70 -24
  2. package/dist/adapters/biome.js +3 -2
  3. package/dist/adapters/flowDoctor.d.ts +7 -0
  4. package/dist/adapters/flowDoctor.js +195 -0
  5. package/dist/adapters/gitleaks.js +17 -3
  6. package/dist/adapters/index.d.ts +1 -0
  7. package/dist/adapters/index.js +3 -1
  8. package/dist/adapters/osvScanner.js +4 -2
  9. package/dist/adapters/ruff.js +17 -4
  10. package/dist/adapters/shared.d.ts +4 -0
  11. package/dist/cli/commands/init.js +7 -0
  12. package/dist/cli/commands/scan.d.ts +9 -1
  13. package/dist/cli/commands/scan.js +37 -3
  14. package/dist/cli/index.js +40 -11
  15. package/dist/core/agentDiagnosis.d.ts +39 -0
  16. package/dist/core/agentDiagnosis.js +96 -0
  17. package/dist/core/config.d.ts +11 -0
  18. package/dist/core/config.js +31 -2
  19. package/dist/core/engine.d.ts +8 -1
  20. package/dist/core/engine.js +73 -51
  21. package/dist/core/executable.js +14 -6
  22. package/dist/core/executionPolicy.d.ts +55 -0
  23. package/dist/core/executionPolicy.js +144 -0
  24. package/dist/core/finding.d.ts +1 -1
  25. package/dist/core/finding.js +8 -3
  26. package/dist/core/findingCorrelator.d.ts +19 -0
  27. package/dist/core/findingCorrelator.js +112 -0
  28. package/dist/core/findingNormalizer.js +1 -0
  29. package/dist/core/git.d.ts +2 -0
  30. package/dist/core/git.js +26 -1
  31. package/dist/core/managedTools.d.ts +25 -0
  32. package/dist/core/managedTools.js +186 -0
  33. package/dist/core/repoGraph.d.ts +62 -0
  34. package/dist/core/repoGraph.js +408 -0
  35. package/dist/core/riskRanker.d.ts +6 -0
  36. package/dist/core/riskRanker.js +127 -0
  37. package/dist/core/scanContext.d.ts +26 -0
  38. package/dist/core/scanContext.js +44 -0
  39. package/dist/core/scanPlanner.d.ts +1 -0
  40. package/dist/core/scanPlanner.js +18 -6
  41. package/dist/core/toolRegistry.js +12 -5
  42. package/dist/core/toolRunner.d.ts +4 -0
  43. package/dist/core/toolRunner.js +28 -3
  44. package/dist/core/toolRuntime.d.ts +40 -0
  45. package/dist/core/toolRuntime.js +417 -0
  46. package/dist/core/toolVerification.d.ts +3 -1
  47. package/dist/core/toolVerification.js +58 -3
  48. package/dist/index.d.ts +5 -0
  49. package/dist/index.js +5 -0
  50. package/dist/integration/envelope.d.ts +72 -0
  51. package/dist/integration/envelope.js +61 -0
  52. package/dist/integration/sourceFingerprint.d.ts +21 -0
  53. package/dist/integration/sourceFingerprint.js +68 -0
  54. package/dist/reporters/agent.d.ts +1 -1
  55. package/dist/reporters/agent.js +7 -0
  56. package/package.json +81 -80
  57. package/schemas/machine-envelope.v1.schema.json +92 -0
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QUICK_ADAPTER_IDS = void 0;
3
4
  exports.createScanPlan = createScanPlan;
4
- const QUICK_ADAPTER_IDS = new Set([
5
+ const executionPolicy_1 = require("./executionPolicy");
6
+ exports.QUICK_ADAPTER_IDS = new Set([
5
7
  "ruff",
6
8
  "biome",
7
9
  "tsc",
@@ -18,8 +20,6 @@ function disabledReason(adapter, config) {
18
20
  switch (adapter.category) {
19
21
  case "security":
20
22
  return checks.security.enabled ? undefined : "checks.security.enabled is false";
21
- case "correctness":
22
- return checks.correctness.enabled ? undefined : "checks.correctness.enabled is false";
23
23
  case "dead_code":
24
24
  return checks.deadCode.enabled ? undefined : "checks.deadCode.enabled is false";
25
25
  case "leftovers":
@@ -33,6 +33,11 @@ function disabledReason(adapter, config) {
33
33
  return checks.dpdp.enabled ? undefined : "checks.dpdp.enabled is false";
34
34
  }
35
35
  return checks.privacy.enabled ? undefined : "checks.privacy.enabled is false";
36
+ case "correctness":
37
+ if (adapter.id === "flow-doctor" && checks.flowAnalysis.enabled === false) {
38
+ return "checks.flowAnalysis.enabled is false";
39
+ }
40
+ return checks.correctness.enabled ? undefined : "checks.correctness.enabled is false";
36
41
  default:
37
42
  return undefined;
38
43
  }
@@ -42,6 +47,13 @@ async function createScanPlan(project, config, adapters, mode) {
42
47
  const excluded = [];
43
48
  const deferred = new Set(config.runtime.deferredTools);
44
49
  for (const adapter of adapters) {
50
+ // The caller's execution profile outranks repository configuration: a target's
51
+ // vibedoctor.yml cannot re-enable a tool the profile excludes.
52
+ const excludedByPolicy = (0, executionPolicy_1.policyExclusion)(adapter.id);
53
+ if (excludedByPolicy) {
54
+ excluded.push({ id: adapter.id, state: "disabled", reason: excludedByPolicy });
55
+ continue;
56
+ }
45
57
  const disabled = disabledReason(adapter, config);
46
58
  if (disabled) {
47
59
  excluded.push({ id: adapter.id, state: "disabled", reason: `Turned off in config: ${disabled}.` });
@@ -55,11 +67,11 @@ async function createScanPlan(project, config, adapters, mode) {
55
67
  });
56
68
  continue;
57
69
  }
58
- if (mode === "quick" && !QUICK_ADAPTER_IDS.has(adapter.id)) {
70
+ if (mode === "quick" && !exports.QUICK_ADAPTER_IDS.has(adapter.id)) {
59
71
  excluded.push({
60
72
  id: adapter.id,
61
73
  state: "not_selected",
62
- reason: "Not part of the quick profile. Run `vibedoctor scan --full` to include it."
74
+ reason: "Not part of the quick profile. Run `vibedoctor scan` for the full applicable diagnosis."
63
75
  });
64
76
  continue;
65
77
  }
@@ -78,6 +90,6 @@ async function createScanPlan(project, config, adapters, mode) {
78
90
  adapterIds: selected,
79
91
  excluded,
80
92
  changedOnly: mode === "changed",
81
- outputFull: mode === "full"
93
+ outputFull: mode === "full" || mode === "default"
82
94
  };
83
95
  }
@@ -36,6 +36,12 @@ exports.TOOL_REGISTRY = [
36
36
  priority: "essential",
37
37
  reason: "Finds personal-data and Privacy Review signals without sending data to an external service."
38
38
  },
39
+ {
40
+ id: "flow-doctor",
41
+ ecosystem: "built-in",
42
+ priority: "essential",
43
+ reason: "High-confidence structural flow checks: route/method mismatches and swallowed error paths."
44
+ },
39
45
  {
40
46
  id: "tsc",
41
47
  packageName: "typescript",
@@ -89,7 +95,8 @@ exports.TOOL_REGISTRY = [
89
95
  languages: ["python"],
90
96
  runtime: "python",
91
97
  probeArgs: ["--version"],
92
- reason: "Python lint and safe-fix signal."
98
+ reason: "Python lint and safe-fix signal. VibeDoctor can provision a pinned managed copy.",
99
+ installHint: "VibeDoctor provisions Ruff into ~/.cache/vibedoctor. To pin a project-local copy, install ruff in the environment."
93
100
  },
94
101
  {
95
102
  id: "pyright",
@@ -152,8 +159,8 @@ exports.TOOL_REGISTRY = [
152
159
  ecosystem: "manual",
153
160
  priority: "essential",
154
161
  probeArgs: ["version"],
155
- reason: "Secret detection across every repository.",
156
- installHint: "Install Gitleaks from https://gitleaks.io/ or your OS package manager."
162
+ reason: "Secret detection across every repository. VibeDoctor can provision a pinned managed copy.",
163
+ installHint: "VibeDoctor provisions Gitleaks into ~/.cache/vibedoctor. To pin a project-local copy, install gitleaks on PATH."
157
164
  },
158
165
  {
159
166
  id: "osv-scanner",
@@ -162,8 +169,8 @@ exports.TOOL_REGISTRY = [
162
169
  priority: "essential",
163
170
  requiresLockfile: true,
164
171
  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."
172
+ reason: "Known-vulnerability detection for dependency lockfiles. VibeDoctor can provision a pinned managed copy.",
173
+ installHint: "VibeDoctor provisions OSV-Scanner into ~/.cache/vibedoctor. To pin a project-local copy, install osv-scanner on PATH."
167
174
  },
168
175
  {
169
176
  id: "lizard",
@@ -1,11 +1,15 @@
1
1
  import { buildCommandEnv, getLocalToolSearchPaths } from "./executable";
2
+ import { type ToolRuntime } from "./toolRuntime";
2
3
  export { buildCommandEnv, getLocalToolSearchPaths };
3
4
  export type CommandSpec = {
4
5
  cmd: string;
6
+ /** Request a named engine; ToolRuntime resolves the executable. */
7
+ tool?: string;
5
8
  args: string[];
6
9
  cwd?: string;
7
10
  timeoutMs?: number;
8
11
  env?: NodeJS.ProcessEnv;
12
+ runtime?: ToolRuntime;
9
13
  };
10
14
  export type ToolResult = {
11
15
  command: string;
@@ -14,6 +14,8 @@ const node_child_process_2 = require("node:child_process");
14
14
  const executable_1 = require("./executable");
15
15
  Object.defineProperty(exports, "buildCommandEnv", { enumerable: true, get: function () { return executable_1.buildCommandEnv; } });
16
16
  Object.defineProperty(exports, "getLocalToolSearchPaths", { enumerable: true, get: function () { return executable_1.getLocalToolSearchPaths; } });
17
+ const toolRuntime_1 = require("./toolRuntime");
18
+ const executionPolicy_1 = require("./executionPolicy");
17
19
  function commandExistsOnWindowsPath(command, cwd) {
18
20
  return (0, executable_1.resolveExecutable)(command, cwd) !== undefined;
19
21
  }
@@ -31,7 +33,9 @@ function resolveLaunchTarget(command, cwd, env) {
31
33
  }
32
34
  return { command: resolved.path, useShell: false, resolvedPath: resolved.path };
33
35
  }
34
- if (process.platform === "win32" && !node_path_1.default.isAbsolute(command)) {
36
+ // Integration profiles never fall back to cmd.exe: its lookup searches the working directory,
37
+ // which is the target repository.
38
+ if (process.platform === "win32" && !node_path_1.default.isAbsolute(command) && (0, executionPolicy_1.currentPolicy)().allowShellFallback) {
35
39
  // Not found via PATH/PATHEXT probing. Fall back to the shell so commands that
36
40
  // are only reachable through cmd.exe mechanisms (App Execution Aliases,
37
41
  // App Paths registry entries) still launch, matching the previous behavior.
@@ -66,6 +70,23 @@ function quoteForWindowsShell(argument) {
66
70
  }
67
71
  async function runCommand(spec, installHint) {
68
72
  const startedAt = Date.now();
73
+ if (spec.tool) {
74
+ const runtime = spec.runtime ?? (0, toolRuntime_1.createToolRuntime)({ projectRoot: spec.cwd });
75
+ const resolvedTool = await runtime.resolve(spec.tool, { projectRoot: spec.cwd });
76
+ if (!resolvedTool.executablePath) {
77
+ const failedHard = resolvedTool.status === "checksum_mismatch" || resolvedTool.status === "failed";
78
+ return {
79
+ command: [spec.tool, ...spec.args].join(" "),
80
+ stdout: "",
81
+ stderr: resolvedTool.reason,
82
+ exitCode: null,
83
+ durationMs: Date.now() - startedAt,
84
+ status: failedHard ? "error" : "skipped",
85
+ installHint: resolvedTool.remediation ?? installHint
86
+ };
87
+ }
88
+ spec = { ...spec, cmd: resolvedTool.executablePath };
89
+ }
69
90
  const env = (0, executable_1.buildCommandEnv)(spec.cwd, spec.env);
70
91
  const resolved = resolveLaunchTarget(spec.cmd, spec.cwd, env);
71
92
  // Build the shell command line here instead of letting spawn concatenate the
@@ -73,6 +94,8 @@ async function runCommand(spec, installHint) {
73
94
  const launch = resolved.useShell
74
95
  ? { command: [resolved.command, ...spec.args.map(quoteForWindowsShell)].join(" "), args: [] }
75
96
  : { command: resolved.command, args: spec.args };
97
+ // Integration profiles bound captured output so a runaway tool cannot exhaust memory.
98
+ const maxBytes = (0, executionPolicy_1.currentPolicy)().maxOutputBytes ?? Number.POSITIVE_INFINITY;
76
99
  return new Promise((resolve) => {
77
100
  const child = (0, node_child_process_1.spawn)(launch.command, launch.args, {
78
101
  cwd: spec.cwd,
@@ -85,10 +108,12 @@ async function runCommand(spec, installHint) {
85
108
  let settled = false;
86
109
  let timeoutHandle;
87
110
  child.stdout.on("data", (chunk) => {
88
- stdout += chunk.toString();
111
+ if (stdout.length < maxBytes)
112
+ stdout += chunk.toString();
89
113
  });
90
114
  child.stderr.on("data", (chunk) => {
91
- stderr += chunk.toString();
115
+ if (stderr.length < maxBytes)
116
+ stderr += chunk.toString();
92
117
  });
93
118
  function cleanup() {
94
119
  try {
@@ -0,0 +1,40 @@
1
+ import { isManagedTool, type ManagedToolSpec } from "./managedTools";
2
+ export type ToolResolutionStatus = "resolved" | "not_found" | "checksum_mismatch" | "unsupported_platform" | "failed";
3
+ export type ToolResolutionSource = "project-local" | "managed" | "path";
4
+ export type ToolResolution = {
5
+ tool: string;
6
+ status: ToolResolutionStatus;
7
+ source?: ToolResolutionSource;
8
+ version?: string;
9
+ executablePath?: string;
10
+ cachePath?: string;
11
+ reusedCache: boolean;
12
+ reason: string;
13
+ remediation?: string;
14
+ };
15
+ export type ToolRuntimeOptions = {
16
+ cacheDir?: string;
17
+ projectRoot?: string;
18
+ enabled?: boolean;
19
+ allowNetwork?: boolean;
20
+ preferProjectLocal?: boolean;
21
+ allowPathFallback?: boolean;
22
+ /** Test/advanced: replace the catalog for a tool. */
23
+ catalog?: Record<string, ManagedToolSpec>;
24
+ /** Test: copy this local file instead of downloading. */
25
+ localArtifacts?: Record<string, string>;
26
+ fetchArtifact?: (url: string, destFile: string) => Promise<void>;
27
+ };
28
+ export type ToolRuntime = {
29
+ readonly cacheDir: string;
30
+ resolve(tool: string, options?: {
31
+ projectRoot?: string;
32
+ }): Promise<ToolResolution>;
33
+ };
34
+ export declare const DOWNLOAD_TIMEOUT_MS = 45000;
35
+ export declare const MAX_DOWNLOAD_BYTES: number;
36
+ export declare function defaultToolCacheDir(): string;
37
+ export declare function createToolRuntime(options?: ToolRuntimeOptions): ToolRuntime;
38
+ export declare function isProjectLocalPath(candidate: string, projectRoot: string | undefined): boolean;
39
+ export declare function sha256File(filePath: string): Promise<string>;
40
+ export { isManagedTool };
@@ -0,0 +1,417 @@
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.isManagedTool = exports.MAX_DOWNLOAD_BYTES = exports.DOWNLOAD_TIMEOUT_MS = void 0;
7
+ exports.defaultToolCacheDir = defaultToolCacheDir;
8
+ exports.createToolRuntime = createToolRuntime;
9
+ exports.isProjectLocalPath = isProjectLocalPath;
10
+ exports.sha256File = sha256File;
11
+ const node_crypto_1 = require("node:crypto");
12
+ const node_child_process_1 = require("node:child_process");
13
+ const node_fs_1 = require("node:fs");
14
+ const node_https_1 = __importDefault(require("node:https"));
15
+ const node_os_1 = __importDefault(require("node:os"));
16
+ const node_path_1 = __importDefault(require("node:path"));
17
+ const executable_1 = require("./executable");
18
+ const managedTools_1 = require("./managedTools");
19
+ Object.defineProperty(exports, "isManagedTool", { enumerable: true, get: function () { return managedTools_1.isManagedTool; } });
20
+ exports.DOWNLOAD_TIMEOUT_MS = 45_000;
21
+ exports.MAX_DOWNLOAD_BYTES = 80 * 1024 * 1024;
22
+ const MANIFEST_NAME = "manifest.json";
23
+ function defaultToolCacheDir() {
24
+ if (process.env.VIBEDOCTOR_TOOL_CACHE) {
25
+ return process.env.VIBEDOCTOR_TOOL_CACHE;
26
+ }
27
+ return node_path_1.default.join(node_os_1.default.homedir(), ".cache", "vibedoctor");
28
+ }
29
+ function envAllowsNetwork() {
30
+ const value = process.env.VIBEDOCTOR_ALLOW_NETWORK;
31
+ if (value === "0" || value === "false") {
32
+ return false;
33
+ }
34
+ return true;
35
+ }
36
+ function createToolRuntime(options = {}) {
37
+ const cacheDir = options.cacheDir ?? defaultToolCacheDir();
38
+ const managedEnabled = options.enabled ?? true;
39
+ const allowNetwork = (options.allowNetwork ?? true) && envAllowsNetwork();
40
+ const preferProjectLocal = options.preferProjectLocal ?? true;
41
+ const allowPathFallback = options.allowPathFallback ?? true;
42
+ const catalog = options.catalog;
43
+ const localArtifacts = options.localArtifacts ?? {};
44
+ const fetchArtifact = options.fetchArtifact ?? downloadFile;
45
+ async function resolve(tool, resolveOptions = {}) {
46
+ const projectRoot = resolveOptions.projectRoot ?? options.projectRoot;
47
+ const spec = catalog?.[tool] ?? (0, managedTools_1.getManagedTool)(tool);
48
+ if (preferProjectLocal && projectRoot) {
49
+ const local = findProjectLocal(tool, projectRoot);
50
+ if (local) {
51
+ return {
52
+ tool,
53
+ status: "resolved",
54
+ source: "project-local",
55
+ version: spec?.version,
56
+ executablePath: local,
57
+ reusedCache: false,
58
+ reason: `Using project-local ${tool} at ${local}.`
59
+ };
60
+ }
61
+ }
62
+ if (spec && managedEnabled) {
63
+ const managed = await resolveManaged(spec);
64
+ if (managed.status === "resolved" || managed.status === "checksum_mismatch") {
65
+ return managed;
66
+ }
67
+ if (managed.status === "unsupported_platform") {
68
+ const fromPath = allowPathFallback
69
+ ? projectRoot
70
+ ? (0, executable_1.resolveExecutable)(tool, projectRoot)
71
+ : (0, executable_1.resolveExecutable)(tool)
72
+ : undefined;
73
+ if (fromPath) {
74
+ return {
75
+ tool,
76
+ status: "resolved",
77
+ source: "path",
78
+ executablePath: fromPath.path,
79
+ reusedCache: false,
80
+ reason: `No managed ${tool} artifact for this platform; using PATH at ${fromPath.path}.`
81
+ };
82
+ }
83
+ return managed;
84
+ }
85
+ const fromPath = allowPathFallback
86
+ ? projectRoot
87
+ ? (0, executable_1.resolveExecutable)(tool, projectRoot)
88
+ : (0, executable_1.resolveExecutable)(tool)
89
+ : undefined;
90
+ if (fromPath && !isProjectLocalPath(fromPath.path, projectRoot)) {
91
+ return {
92
+ tool,
93
+ status: "resolved",
94
+ source: "path",
95
+ version: spec.version,
96
+ executablePath: fromPath.path,
97
+ reusedCache: false,
98
+ reason: `Managed ${tool} was not available (${managed.reason}); using PATH at ${fromPath.path}.`
99
+ };
100
+ }
101
+ return managed;
102
+ }
103
+ const fromPath = projectRoot ? (0, executable_1.resolveExecutable)(tool, projectRoot) : (0, executable_1.resolveExecutable)(tool);
104
+ if (fromPath) {
105
+ return {
106
+ tool,
107
+ status: "resolved",
108
+ source: isProjectLocalPath(fromPath.path, projectRoot) ? "project-local" : "path",
109
+ executablePath: fromPath.path,
110
+ reusedCache: false,
111
+ reason: `Resolved ${tool} at ${fromPath.path}.`
112
+ };
113
+ }
114
+ return {
115
+ tool,
116
+ status: "not_found",
117
+ reusedCache: false,
118
+ reason: spec
119
+ ? `Managed ${tool} is disabled and ${tool} was not found on PATH.`
120
+ : `${tool} is not a managed engine and was not found on PATH.`,
121
+ remediation: `Install ${tool} or add a managed-tool entry for it.`
122
+ };
123
+ }
124
+ async function resolveManaged(spec) {
125
+ const platform = (0, managedTools_1.currentPlatformKey)();
126
+ const artifact = (0, managedTools_1.artifactFor)(spec, platform);
127
+ if (!artifact) {
128
+ return {
129
+ tool: spec.id,
130
+ status: "unsupported_platform",
131
+ version: spec.version,
132
+ reusedCache: false,
133
+ reason: `No managed ${spec.id} ${spec.version} artifact for platform ${platform}.`,
134
+ remediation: `Install ${spec.id} yourself, or run on a supported platform (win32-x64, darwin-arm64, linux-x64, …).`
135
+ };
136
+ }
137
+ const toolDir = node_path_1.default.join(cacheDir, "tools", spec.id, spec.version);
138
+ const binaryPath = node_path_1.default.join(toolDir, artifact.binary);
139
+ const cached = await readValidCache(spec, artifact, toolDir, binaryPath);
140
+ if (cached) {
141
+ return cached;
142
+ }
143
+ try {
144
+ await node_fs_1.promises.mkdir(toolDir, { recursive: true });
145
+ const staged = await stageArtifact(spec, artifact, toolDir);
146
+ const digest = await sha256File(staged.archivePath);
147
+ if (digest !== artifact.sha256.toLowerCase()) {
148
+ await rmQuiet(staged.archivePath);
149
+ return {
150
+ tool: spec.id,
151
+ status: "checksum_mismatch",
152
+ version: spec.version,
153
+ cachePath: toolDir,
154
+ reusedCache: false,
155
+ reason: `Checksum mismatch for managed ${spec.id} ${spec.version}: expected ${artifact.sha256}, got ${digest}. The file was not installed.`,
156
+ remediation: `Delete ${toolDir} and rerun the scan. If this persists, the download is corrupt or the catalog checksum is wrong.`
157
+ };
158
+ }
159
+ const executablePath = await materializeBinary(staged, artifact, toolDir, binaryPath);
160
+ await writeManifest(toolDir, {
161
+ tool: spec.id,
162
+ version: spec.version,
163
+ platform,
164
+ sha256: artifact.sha256,
165
+ binary: artifact.binary,
166
+ binarySha256: await sha256File(executablePath),
167
+ provisionedAt: new Date().toISOString()
168
+ });
169
+ if (staged.cleanup) {
170
+ await rmQuiet(staged.archivePath);
171
+ }
172
+ return {
173
+ tool: spec.id,
174
+ status: "resolved",
175
+ source: "managed",
176
+ version: spec.version,
177
+ executablePath,
178
+ cachePath: toolDir,
179
+ reusedCache: false,
180
+ reason: `Provisioned managed ${spec.id} ${spec.version} at ${executablePath}.`
181
+ };
182
+ }
183
+ catch (error) {
184
+ const message = error instanceof Error ? error.message : String(error);
185
+ return {
186
+ tool: spec.id,
187
+ status: /checksum/i.test(message) ? "checksum_mismatch" : "failed",
188
+ version: spec.version,
189
+ cachePath: toolDir,
190
+ reusedCache: false,
191
+ reason: `Could not provision managed ${spec.id} ${spec.version}: ${message}`,
192
+ remediation: allowNetwork
193
+ ? `Check network access to the artifact URL, or install ${spec.id} on PATH.`
194
+ : `Network is disabled. Provide a cached copy under ${toolDir} or a test artifact, or install ${spec.id} on PATH.`
195
+ };
196
+ }
197
+ }
198
+ async function readValidCache(spec, artifact, toolDir, binaryPath) {
199
+ try {
200
+ await node_fs_1.promises.access(binaryPath);
201
+ const manifest = await readManifest(toolDir);
202
+ if (!manifest || manifest.sha256.toLowerCase() !== artifact.sha256.toLowerCase()) {
203
+ return undefined;
204
+ }
205
+ if (manifest.binarySha256) {
206
+ const digest = await sha256File(binaryPath);
207
+ if (digest !== manifest.binarySha256.toLowerCase()) {
208
+ return undefined;
209
+ }
210
+ }
211
+ return {
212
+ tool: spec.id,
213
+ status: "resolved",
214
+ source: "managed",
215
+ version: spec.version,
216
+ executablePath: binaryPath,
217
+ cachePath: toolDir,
218
+ reusedCache: true,
219
+ reason: `Reused managed ${spec.id} ${spec.version} at ${binaryPath}.`
220
+ };
221
+ }
222
+ catch {
223
+ return undefined;
224
+ }
225
+ }
226
+ async function stageArtifact(spec, artifact, toolDir) {
227
+ const local = localArtifacts[spec.id];
228
+ if (local) {
229
+ const dest = node_path_1.default.join(toolDir, node_path_1.default.basename(local));
230
+ await node_fs_1.promises.copyFile(local, dest);
231
+ return { archivePath: dest, cleanup: artifact.archive !== "none" };
232
+ }
233
+ if (!allowNetwork) {
234
+ throw new Error(`Network is disabled and ${spec.id} ${spec.version} is not in the VibeDoctor cache (${toolDir}).`);
235
+ }
236
+ const fileName = node_path_1.default.basename(new URL(artifact.url).pathname) || `${spec.id}.bin`;
237
+ const dest = node_path_1.default.join(toolDir, fileName);
238
+ await fetchArtifact(artifact.url, dest);
239
+ return { archivePath: dest, cleanup: artifact.archive !== "none" };
240
+ }
241
+ return { cacheDir, resolve };
242
+ }
243
+ function findProjectLocal(tool, projectRoot) {
244
+ const resolved = (0, executable_1.resolveExecutable)(tool, projectRoot);
245
+ if (!resolved) {
246
+ return undefined;
247
+ }
248
+ return isProjectLocalPath(resolved.path, projectRoot) ? resolved.path : undefined;
249
+ }
250
+ function isProjectLocalPath(candidate, projectRoot) {
251
+ if (!projectRoot) {
252
+ return false;
253
+ }
254
+ const relative = node_path_1.default.relative(projectRoot, candidate);
255
+ if (!relative || relative.startsWith("..") || node_path_1.default.isAbsolute(relative)) {
256
+ return false;
257
+ }
258
+ return /(^|[/\\])(node_modules|\.venv|venv)([/\\]|$)/i.test(relative);
259
+ }
260
+ async function materializeBinary(staged, artifact, toolDir, binaryPath) {
261
+ if (artifact.archive === "none") {
262
+ if (node_path_1.default.resolve(staged.archivePath) !== node_path_1.default.resolve(binaryPath)) {
263
+ await node_fs_1.promises.copyFile(staged.archivePath, binaryPath);
264
+ }
265
+ if (process.platform !== "win32") {
266
+ await node_fs_1.promises.chmod(binaryPath, 0o755);
267
+ }
268
+ return binaryPath;
269
+ }
270
+ await extractArchive(staged.archivePath, toolDir, artifact.archive);
271
+ const found = await findExtractedBinary(toolDir, artifact.binary);
272
+ if (!found) {
273
+ throw new Error(`Archive extracted but ${artifact.binary} was not found in ${toolDir}.`);
274
+ }
275
+ if (node_path_1.default.resolve(found) !== node_path_1.default.resolve(binaryPath)) {
276
+ await node_fs_1.promises.copyFile(found, binaryPath);
277
+ }
278
+ if (process.platform !== "win32") {
279
+ await node_fs_1.promises.chmod(binaryPath, 0o755);
280
+ }
281
+ return binaryPath;
282
+ }
283
+ async function extractArchive(archivePath, destDir, kind) {
284
+ const args = kind === "tar.gz" ? ["-xzf", archivePath, "-C", destDir] : ["-xf", archivePath, "-C", destDir];
285
+ await new Promise((resolve, reject) => {
286
+ (0, node_child_process_1.execFile)("tar", args, { windowsHide: true }, (error, _stdout, stderr) => {
287
+ if (error) {
288
+ reject(new Error(stderr || error.message));
289
+ return;
290
+ }
291
+ resolve();
292
+ });
293
+ });
294
+ }
295
+ async function findExtractedBinary(dir, binary) {
296
+ const direct = node_path_1.default.join(dir, binary);
297
+ try {
298
+ await node_fs_1.promises.access(direct);
299
+ return direct;
300
+ }
301
+ catch {
302
+ // Search one level down — some archives wrap the binary in a folder.
303
+ }
304
+ const entries = await node_fs_1.promises.readdir(dir, { withFileTypes: true });
305
+ for (const entry of entries) {
306
+ if (entry.isDirectory()) {
307
+ const nested = node_path_1.default.join(dir, entry.name, binary);
308
+ try {
309
+ await node_fs_1.promises.access(nested);
310
+ return nested;
311
+ }
312
+ catch {
313
+ // keep looking
314
+ }
315
+ }
316
+ if (entry.isFile() && entry.name === binary) {
317
+ return node_path_1.default.join(dir, entry.name);
318
+ }
319
+ }
320
+ return undefined;
321
+ }
322
+ async function readManifest(toolDir) {
323
+ try {
324
+ return JSON.parse(await node_fs_1.promises.readFile(node_path_1.default.join(toolDir, MANIFEST_NAME), "utf8"));
325
+ }
326
+ catch {
327
+ return undefined;
328
+ }
329
+ }
330
+ async function writeManifest(toolDir, manifest) {
331
+ await node_fs_1.promises.writeFile(node_path_1.default.join(toolDir, MANIFEST_NAME), `${JSON.stringify(manifest, null, 2)}\n`, "utf8");
332
+ }
333
+ async function sha256File(filePath) {
334
+ const hash = (0, node_crypto_1.createHash)("sha256");
335
+ const handle = await node_fs_1.promises.open(filePath, "r");
336
+ try {
337
+ const stream = handle.createReadStream();
338
+ for await (const chunk of stream) {
339
+ hash.update(chunk);
340
+ }
341
+ }
342
+ finally {
343
+ await handle.close();
344
+ }
345
+ return hash.digest("hex");
346
+ }
347
+ async function downloadFile(url, destFile) {
348
+ await node_fs_1.promises.mkdir(node_path_1.default.dirname(destFile), { recursive: true });
349
+ await new Promise((resolve, reject) => {
350
+ let settled = false;
351
+ const fail = (error) => {
352
+ if (settled) {
353
+ return;
354
+ }
355
+ settled = true;
356
+ reject(error);
357
+ };
358
+ const succeed = () => {
359
+ if (settled) {
360
+ return;
361
+ }
362
+ settled = true;
363
+ resolve();
364
+ };
365
+ const follow = (target, remaining) => {
366
+ if (!target.startsWith("https://")) {
367
+ fail(new Error(`Refusing non-HTTPS download: ${target}`));
368
+ return;
369
+ }
370
+ const request = node_https_1.default.get(target, { timeout: exports.DOWNLOAD_TIMEOUT_MS }, (response) => {
371
+ const status = response.statusCode ?? 0;
372
+ if (status >= 300 && status < 400 && response.headers.location && remaining > 0) {
373
+ response.resume();
374
+ follow(new URL(response.headers.location, target).toString(), remaining - 1);
375
+ return;
376
+ }
377
+ if (status !== 200) {
378
+ response.resume();
379
+ fail(new Error(`Download failed (${status}) for ${target}`));
380
+ return;
381
+ }
382
+ const out = (0, node_fs_1.createWriteStream)(destFile);
383
+ let received = 0;
384
+ response.on("data", (chunk) => {
385
+ received += chunk.length;
386
+ if (received > exports.MAX_DOWNLOAD_BYTES) {
387
+ request.destroy();
388
+ out.destroy();
389
+ fail(new Error(`Download exceeded ${exports.MAX_DOWNLOAD_BYTES} bytes for ${target}`));
390
+ }
391
+ });
392
+ response.setTimeout(exports.DOWNLOAD_TIMEOUT_MS, () => {
393
+ request.destroy();
394
+ out.destroy();
395
+ fail(new Error(`Download timed out after ${exports.DOWNLOAD_TIMEOUT_MS}ms`));
396
+ });
397
+ response.pipe(out);
398
+ out.on("finish", () => out.close((error) => (error ? fail(error) : succeed())));
399
+ out.on("error", fail);
400
+ });
401
+ request.setTimeout(exports.DOWNLOAD_TIMEOUT_MS, () => {
402
+ request.destroy();
403
+ fail(new Error(`Download timed out after ${exports.DOWNLOAD_TIMEOUT_MS}ms`));
404
+ });
405
+ request.on("error", fail);
406
+ };
407
+ follow(url, 5);
408
+ });
409
+ }
410
+ async function rmQuiet(target) {
411
+ try {
412
+ await node_fs_1.promises.rm(target, { force: true });
413
+ }
414
+ catch {
415
+ // best effort
416
+ }
417
+ }
@@ -1,4 +1,5 @@
1
1
  import { type RuntimeEngine, type ToolRegistryEntry } from "./toolRegistry";
2
+ import { type ToolRuntime } from "./toolRuntime";
2
3
  /**
3
4
  * Proves a tool is usable rather than merely present.
4
5
  *
@@ -80,8 +81,9 @@ export type VerifyToolOptions = {
80
81
  root: string;
81
82
  runtimes: RuntimeProbes;
82
83
  depth?: VerificationDepth;
84
+ toolRuntime?: ToolRuntime;
83
85
  };
84
86
  export declare function verifyTool(entry: ToolRegistryEntry, options: VerifyToolOptions): Promise<ToolVerification>;
85
- export declare function verifyTools(entries: ToolRegistryEntry[], root: string, depth?: VerificationDepth): Promise<ToolVerification[]>;
87
+ export declare function verifyTools(entries: ToolRegistryEntry[], root: string, depth?: VerificationDepth, toolRuntime?: ToolRuntime): Promise<ToolVerification[]>;
86
88
  export declare function summarizeVerification(verification: ToolVerification): string;
87
89
  export declare function formatVersionForDisplay(value: string | undefined): string;