@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
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Execution policy for one scan.
3
+ *
4
+ * The default policy reproduces VibeDoctor's long-standing behaviour exactly (project-local
5
+ * tools first, project tests may run, the Windows shell fallback). Callers that scan code they
6
+ * do not fully trust (CI bots, other tools, repositories downloaded from elsewhere) can opt in
7
+ * to an explicit profile with `scan --profile`:
8
+ *
9
+ * - `static`: only analysers that read files and run from outside the target. No project-local
10
+ * executables, no project scripts/tests, no tools that load executable project configuration,
11
+ * no network, and a minimal environment for child processes.
12
+ * - `trusted`: the caller explicitly accepts running the project's own tools and tests, with a
13
+ * minimal environment and network off unless allowed.
14
+ *
15
+ * Reports are still written to the usual `.vibedoctor/` folder in every profile.
16
+ *
17
+ * The policy travels with the async call chain (AsyncLocalStorage), so it applies only to the
18
+ * scan that asked for it and no adapter has to thread it through.
19
+ */
20
+ export type ExecutionProfile = "default" | "static" | "trusted";
21
+ export type ExecutionPolicy = {
22
+ profile: ExecutionProfile;
23
+ /** Absolute repository root being diagnosed; nothing inside it may be executed in `static`. */
24
+ targetRoot?: string;
25
+ /** Optional scratch directory for child-process temp files (TEMP/TMP/TMPDIR). */
26
+ tempRoot?: string;
27
+ allowProjectLocalTools: boolean;
28
+ allowProjectExecution: boolean;
29
+ allowShellFallback: boolean;
30
+ allowNetwork: boolean;
31
+ /** When set, child processes receive only these variables (plus PATH/TEMP handling). */
32
+ envAllowlist?: string[];
33
+ /** Upper bound on captured stdout/stderr per child process. */
34
+ maxOutputBytes?: number;
35
+ };
36
+ export declare const DEFAULT_POLICY: ExecutionPolicy;
37
+ export declare function profilePolicy(profile: ExecutionProfile, options?: {
38
+ targetRoot: string;
39
+ tempRoot?: string;
40
+ allowNetwork?: boolean;
41
+ }): ExecutionPolicy;
42
+ export declare function currentPolicy(): ExecutionPolicy;
43
+ export declare function withExecutionPolicy<T>(policy: ExecutionPolicy, run: () => Promise<T>): Promise<T>;
44
+ /** Why a tool must not run under the current policy, or undefined when it may. */
45
+ export declare function policyExclusion(toolId: string, policy?: ExecutionPolicy): string | undefined;
46
+ export declare function isInside(parent: string, child: string): boolean;
47
+ /**
48
+ * PATH entries a child may search. Relative entries (such as ".") and anything inside the
49
+ * target are removed when project-local tools are not allowed.
50
+ */
51
+ export declare function allowedPathEntries(entries: string[], policy?: ExecutionPolicy): string[];
52
+ /** Environment passed to children under the policy (the full environment by default). */
53
+ export declare function policyEnv(base: NodeJS.ProcessEnv, policy?: ExecutionPolicy): NodeJS.ProcessEnv;
54
+ /** Git settings that could run commands from repository configuration are switched off. */
55
+ export declare function gitSafetyEnv(policy?: ExecutionPolicy): NodeJS.ProcessEnv;
@@ -0,0 +1,144 @@
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.DEFAULT_POLICY = void 0;
7
+ exports.profilePolicy = profilePolicy;
8
+ exports.currentPolicy = currentPolicy;
9
+ exports.withExecutionPolicy = withExecutionPolicy;
10
+ exports.policyExclusion = policyExclusion;
11
+ exports.isInside = isInside;
12
+ exports.allowedPathEntries = allowedPathEntries;
13
+ exports.policyEnv = policyEnv;
14
+ exports.gitSafetyEnv = gitSafetyEnv;
15
+ const node_async_hooks_1 = require("node:async_hooks");
16
+ const node_path_1 = __importDefault(require("node:path"));
17
+ exports.DEFAULT_POLICY = {
18
+ profile: "default",
19
+ allowProjectLocalTools: true,
20
+ allowProjectExecution: true,
21
+ allowShellFallback: true,
22
+ allowNetwork: true
23
+ };
24
+ const ENV_ALLOWLIST = [
25
+ "PATH",
26
+ "Path",
27
+ "PATHEXT",
28
+ "SystemRoot",
29
+ "SYSTEMROOT",
30
+ "windir",
31
+ "ComSpec",
32
+ "HOME",
33
+ "USERPROFILE",
34
+ "APPDATA",
35
+ "LOCALAPPDATA",
36
+ "HOMEDRIVE",
37
+ "HOMEPATH",
38
+ "LANG",
39
+ "LC_ALL",
40
+ "TZ",
41
+ "NUMBER_OF_PROCESSORS",
42
+ "PROCESSOR_ARCHITECTURE",
43
+ "VIBEDOCTOR_TOOL_CACHE"
44
+ ];
45
+ /**
46
+ * Tools excluded from a profile, with the reason surfaced in the capability matrix.
47
+ * Each entry was checked against the adapter: a flag named "static" is not evidence.
48
+ */
49
+ const STATIC_EXCLUSIONS = {
50
+ vitest: "Runs the project's tests and loads its vitest config (project code execution).",
51
+ jest: "Runs the project's tests and loads its jest config (project code execution).",
52
+ knip: "Loads JS/TS project config and plugin configs, which execute project code.",
53
+ "coverage.py": "coverage.py loads .coveragerc plugins, which are Python code.",
54
+ presidio: "Runs a Python interpreter that may resolve to the project's environment and download models.",
55
+ semgrep: "Uses `--config auto`, which downloads rules from the network.",
56
+ "osv-scanner": "Queries the OSV vulnerability API over the network."
57
+ };
58
+ const TRUSTED_EXCLUSIONS = {
59
+ semgrep: STATIC_EXCLUSIONS.semgrep,
60
+ "osv-scanner": STATIC_EXCLUSIONS["osv-scanner"]
61
+ };
62
+ function profilePolicy(profile, options = { targetRoot: process.cwd() }) {
63
+ if (profile === "default")
64
+ return { ...exports.DEFAULT_POLICY, targetRoot: node_path_1.default.resolve(options.targetRoot) };
65
+ const base = {
66
+ profile,
67
+ targetRoot: node_path_1.default.resolve(options.targetRoot),
68
+ tempRoot: options.tempRoot ? node_path_1.default.resolve(options.tempRoot) : undefined,
69
+ allowNetwork: options.allowNetwork ?? false,
70
+ allowShellFallback: false,
71
+ envAllowlist: ENV_ALLOWLIST,
72
+ maxOutputBytes: 64 * 1024 * 1024
73
+ };
74
+ return profile === "static"
75
+ ? { ...base, allowProjectLocalTools: false, allowProjectExecution: false }
76
+ : { ...base, allowProjectLocalTools: true, allowProjectExecution: true };
77
+ }
78
+ const store = new node_async_hooks_1.AsyncLocalStorage();
79
+ function currentPolicy() {
80
+ return store.getStore() ?? exports.DEFAULT_POLICY;
81
+ }
82
+ function withExecutionPolicy(policy, run) {
83
+ return store.run(policy, run);
84
+ }
85
+ /** Why a tool must not run under the current policy, or undefined when it may. */
86
+ function policyExclusion(toolId, policy = currentPolicy()) {
87
+ if (policy.profile === "static") {
88
+ const reason = STATIC_EXCLUSIONS[toolId];
89
+ if (reason && !(policy.allowNetwork && (toolId === "semgrep" || toolId === "osv-scanner")))
90
+ return `Excluded by the static profile: ${reason}`;
91
+ }
92
+ if (policy.profile === "trusted" && !policy.allowNetwork && TRUSTED_EXCLUSIONS[toolId])
93
+ return `Excluded because network is off: ${TRUSTED_EXCLUSIONS[toolId]}`;
94
+ return undefined;
95
+ }
96
+ function isInside(parent, child) {
97
+ const relative = node_path_1.default.relative(node_path_1.default.resolve(parent), node_path_1.default.resolve(child));
98
+ return relative === "" || (!relative.startsWith("..") && !node_path_1.default.isAbsolute(relative));
99
+ }
100
+ /**
101
+ * PATH entries a child may search. Relative entries (such as ".") and anything inside the
102
+ * target are removed when project-local tools are not allowed.
103
+ */
104
+ function allowedPathEntries(entries, policy = currentPolicy()) {
105
+ if (policy.allowProjectLocalTools || !policy.targetRoot)
106
+ return entries;
107
+ return entries.filter((entry) => node_path_1.default.isAbsolute(entry) && !isInside(policy.targetRoot, entry));
108
+ }
109
+ /** Environment passed to children under the policy (the full environment by default). */
110
+ function policyEnv(base, policy = currentPolicy()) {
111
+ if (!policy.envAllowlist)
112
+ return base;
113
+ const env = {};
114
+ for (const key of policy.envAllowlist)
115
+ if (base[key] !== undefined)
116
+ env[key] = base[key];
117
+ if (policy.tempRoot) {
118
+ // Tools that write scratch files (deptry, jscpd) write them where the caller chose.
119
+ const temp = policy.tempRoot;
120
+ env.TEMP = temp;
121
+ env.TMP = temp;
122
+ env.TMPDIR = temp;
123
+ }
124
+ if (!policy.allowNetwork)
125
+ env.VIBEDOCTOR_ALLOW_NETWORK = "0";
126
+ return env;
127
+ }
128
+ /** Git settings that could run commands from repository configuration are switched off. */
129
+ function gitSafetyEnv(policy = currentPolicy()) {
130
+ if (policy.profile === "default")
131
+ return {};
132
+ const overrides = [
133
+ ["core.fsmonitor", "false"],
134
+ ["core.hooksPath", process.platform === "win32" ? "NUL" : "/dev/null"],
135
+ ["diff.external", ""],
136
+ ["core.pager", "cat"]
137
+ ];
138
+ const env = { GIT_CONFIG_NOSYSTEM: "1", GIT_TERMINAL_PROMPT: "0", GIT_CONFIG_COUNT: String(overrides.length) };
139
+ overrides.forEach(([key, value], index) => {
140
+ env[`GIT_CONFIG_KEY_${index}`] = key;
141
+ env[`GIT_CONFIG_VALUE_${index}`] = value;
142
+ });
143
+ return env;
144
+ }
@@ -1,4 +1,4 @@
1
- export declare const FINDING_SOURCES: readonly ["ruff", "biome", "tsc", "pyright", "semgrep", "gitleaks", "osv-scanner", "knip", "vulture", "deptry", "jscpd", "lizard", "radon", "coverage.py", "vitest", "jest", "privacy-detector", "presidio", "privacy-ai-review", "telemetry-detector", "dpdp", "custom-leftovers", "custom-refactor", "custom-dead-chain"];
1
+ export declare const FINDING_SOURCES: readonly ["ruff", "biome", "tsc", "pyright", "semgrep", "gitleaks", "osv-scanner", "knip", "vulture", "deptry", "jscpd", "lizard", "radon", "coverage.py", "vitest", "jest", "privacy-detector", "presidio", "privacy-ai-review", "telemetry-detector", "dpdp", "custom-leftovers", "custom-refactor", "custom-dead-chain", "flow-doctor"];
2
2
  export declare const FINDING_CATEGORIES: readonly ["security", "correctness", "dead_code", "leftovers", "maintainability", "dependencies", "tests", "privacy", "efficiency", "refactor_readiness"];
3
3
  export type FindingSource = (typeof FINDING_SOURCES)[number];
4
4
  export type FindingCategory = (typeof FINDING_CATEGORIES)[number];
@@ -37,7 +37,8 @@ exports.FINDING_SOURCES = [
37
37
  "dpdp",
38
38
  "custom-leftovers",
39
39
  "custom-refactor",
40
- "custom-dead-chain"
40
+ "custom-dead-chain",
41
+ "flow-doctor"
41
42
  ];
42
43
  exports.FINDING_CATEGORIES = [
43
44
  "security",
@@ -72,8 +73,12 @@ function normalizeFilePath(file, root) {
72
73
  if (!file) {
73
74
  return undefined;
74
75
  }
75
- const normalized = file.replaceAll("/", node_path_1.default.sep);
76
- const relative = node_path_1.default.isAbsolute(normalized) ? node_path_1.default.relative(root, normalized) : normalized;
76
+ // Scanners emit both separators (Biome on Windows even writes unescaped `\`
77
+ // into JSON). Reports always use POSIX-style relative paths, so treat `\` as
78
+ // a separator first rather than hoping `path.sep` matches the input.
79
+ const withPosix = file.replaceAll("\\", "/");
80
+ const asNative = withPosix.replaceAll("/", node_path_1.default.sep);
81
+ const relative = node_path_1.default.isAbsolute(asNative) ? node_path_1.default.relative(root, asNative) : asNative;
77
82
  return relative.split(node_path_1.default.sep).join("/");
78
83
  }
79
84
  function stableSnippetHash(value) {
@@ -0,0 +1,19 @@
1
+ import type { Finding, FindingCategory, Severity } from "./finding";
2
+ export type FindingLocation = {
3
+ file?: string;
4
+ startLine?: number;
5
+ endLine?: number;
6
+ };
7
+ export type RootCauseGroup = {
8
+ id: string;
9
+ title: string;
10
+ severity: Severity;
11
+ category: FindingCategory;
12
+ findingIds: string[];
13
+ supportingEngines: string[];
14
+ likelyRootCause: string;
15
+ locations: FindingLocation[];
16
+ };
17
+ export declare function inferRootCause(finding: Finding): string;
18
+ export declare function correlateFindings(findings: Finding[]): RootCauseGroup[];
19
+ export declare function locationKeyForTests(finding: Finding): string | undefined;
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.inferRootCause = inferRootCause;
4
+ exports.correlateFindings = correlateFindings;
5
+ exports.locationKeyForTests = locationKeyForTests;
6
+ const severityMap_1 = require("../rules/severityMap");
7
+ function locationKey(finding) {
8
+ if (!finding.file || finding.startLine === undefined) {
9
+ return undefined;
10
+ }
11
+ return `${finding.file}:${finding.startLine}`;
12
+ }
13
+ function token(finding) {
14
+ return (finding.evidence?.toolRawId ?? finding.title).toLowerCase().replace(/\s+/g, " ").trim();
15
+ }
16
+ function sameProblem(left, right) {
17
+ if (left.id === right.id) {
18
+ return true;
19
+ }
20
+ const corroborated = left.corroboratedBy?.includes(right.source) || right.corroboratedBy?.includes(left.source);
21
+ if (left.category !== right.category) {
22
+ return Boolean(corroborated && left.file && left.file === right.file);
23
+ }
24
+ if (left.file && left.file === right.file) {
25
+ const lineClose = left.startLine !== undefined &&
26
+ right.startLine !== undefined &&
27
+ Math.abs(left.startLine - right.startLine) <= 2;
28
+ if (lineClose) {
29
+ return true;
30
+ }
31
+ if (token(left) && token(left) === token(right)) {
32
+ return true;
33
+ }
34
+ }
35
+ if (corroborated) {
36
+ return left.file === right.file;
37
+ }
38
+ return false;
39
+ }
40
+ function pickCanonical(findings) {
41
+ return [...findings].sort((left, right) => {
42
+ const severityDelta = severityMap_1.severityRank[right.severity] - severityMap_1.severityRank[left.severity];
43
+ if (severityDelta !== 0) {
44
+ return severityDelta;
45
+ }
46
+ return left.id.localeCompare(right.id);
47
+ })[0];
48
+ }
49
+ function inferRootCause(finding) {
50
+ if (finding.source === "gitleaks") {
51
+ return "A secret or credential-like value is committed in source.";
52
+ }
53
+ if (finding.source === "osv-scanner") {
54
+ return "A declared dependency has a known advisory.";
55
+ }
56
+ if (finding.source === "flow-doctor") {
57
+ return finding.message;
58
+ }
59
+ if (finding.source === "tsc" || finding.source === "pyright") {
60
+ return "The type checker rejected this location.";
61
+ }
62
+ if (finding.category === "tests") {
63
+ return "A test suite reported a failure.";
64
+ }
65
+ return finding.message;
66
+ }
67
+ function correlateFindings(findings) {
68
+ const remaining = [...findings];
69
+ const groups = [];
70
+ while (remaining.length > 0) {
71
+ const seed = remaining.shift();
72
+ const group = [seed];
73
+ for (let index = remaining.length - 1; index >= 0; index -= 1) {
74
+ if (group.some((member) => sameProblem(member, remaining[index]))) {
75
+ group.push(remaining.splice(index, 1)[0]);
76
+ }
77
+ }
78
+ groups.push(group);
79
+ }
80
+ return groups
81
+ .map((members, index) => {
82
+ const canonical = pickCanonical(members);
83
+ const engines = Array.from(new Set(members.map((member) => member.source))).sort();
84
+ const locations = members
85
+ .map((member) => ({ file: member.file, startLine: member.startLine, endLine: member.endLine }))
86
+ .filter((location, locationIndex, all) => {
87
+ const key = `${location.file ?? ""}:${location.startLine ?? ""}`;
88
+ return all.findIndex((candidate) => `${candidate.file ?? ""}:${candidate.startLine ?? ""}` === key) === locationIndex;
89
+ })
90
+ .sort((left, right) => `${left.file}:${left.startLine ?? 0}`.localeCompare(`${right.file}:${right.startLine ?? 0}`));
91
+ return {
92
+ id: `rcg-${String(index + 1).padStart(3, "0")}`,
93
+ title: canonical.title,
94
+ severity: canonical.severity,
95
+ category: canonical.category,
96
+ findingIds: members.map((member) => member.id).sort(),
97
+ supportingEngines: engines,
98
+ likelyRootCause: inferRootCause(canonical),
99
+ locations
100
+ };
101
+ })
102
+ .sort((left, right) => {
103
+ const severityDelta = severityMap_1.severityRank[right.severity] - severityMap_1.severityRank[left.severity];
104
+ if (severityDelta !== 0) {
105
+ return severityDelta;
106
+ }
107
+ return left.id.localeCompare(right.id);
108
+ });
109
+ }
110
+ function locationKeyForTests(finding) {
111
+ return locationKey(finding);
112
+ }
@@ -37,6 +37,7 @@ const DEFAULT_EVIDENCE_GRADE = {
37
37
  "custom-leftovers": "observed",
38
38
  "custom-refactor": "verified",
39
39
  "custom-dead-chain": "heuristic",
40
+ "flow-doctor": "verified",
40
41
  dpdp: "heuristic"
41
42
  };
42
43
  const VALID_CATEGORIES = new Set(finding_1.FINDING_CATEGORIES);
@@ -1,3 +1,5 @@
1
1
  export declare function isGitRepo(root: string): Promise<boolean>;
2
2
  export declare function getChangedFiles(root: string): Promise<string[]>;
3
+ /** HEAD commit of the repository, or null when the root is not a git work tree. */
4
+ export declare function getHeadCommit(root: string): Promise<string | null>;
3
5
  export declare function isWorkingTreeDirty(root: string): Promise<boolean>;
package/dist/core/git.js CHANGED
@@ -2,12 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isGitRepo = isGitRepo;
4
4
  exports.getChangedFiles = getChangedFiles;
5
+ exports.getHeadCommit = getHeadCommit;
5
6
  exports.isWorkingTreeDirty = isWorkingTreeDirty;
6
7
  const node_child_process_1 = require("node:child_process");
7
8
  const node_util_1 = require("node:util");
9
+ const executable_1 = require("./executable");
10
+ const executionPolicy_1 = require("./executionPolicy");
8
11
  const execFileAsync = (0, node_util_1.promisify)(node_child_process_1.execFile);
9
12
  async function runGit(root, args) {
10
- return execFileAsync("git", args, { cwd: root, windowsHide: true });
13
+ const policy = (0, executionPolicy_1.currentPolicy)();
14
+ if (policy.profile === "default")
15
+ return execFileAsync("git", args, { cwd: root, windowsHide: true });
16
+ // Integration profiles launch git by absolute path from outside the target, with repository
17
+ // settings that could run commands (fsmonitor, hooks, external diff) switched off.
18
+ const env = { ...(0, executable_1.buildCommandEnv)(undefined, undefined), ...(0, executionPolicy_1.gitSafetyEnv)(policy) };
19
+ const git = (0, executable_1.resolveExecutable)("git", undefined, env);
20
+ if (!git)
21
+ throw new Error("git is not available outside the target repository");
22
+ return execFileAsync(git.path, args, { cwd: root, windowsHide: true, env });
11
23
  }
12
24
  async function isGitRepo(root) {
13
25
  try {
@@ -53,6 +65,19 @@ async function getChangedFiles(root) {
53
65
  return [];
54
66
  }
55
67
  }
68
+ /** HEAD commit of the repository, or null when the root is not a git work tree. */
69
+ async function getHeadCommit(root) {
70
+ if (!(await isGitRepo(root))) {
71
+ return null;
72
+ }
73
+ try {
74
+ const { stdout } = await runGit(root, ["rev-parse", "HEAD"]);
75
+ return stdout.trim() || null;
76
+ }
77
+ catch {
78
+ return null;
79
+ }
80
+ }
56
81
  async function isWorkingTreeDirty(root) {
57
82
  if (!(await isGitRepo(root))) {
58
83
  return false;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Pinned managed-tool catalog.
3
+ *
4
+ * Adapters ask for `tool: "ruff"`; ToolRuntime maps that name onto a
5
+ * versioned, checksummed artifact in the VibeDoctor cache. Other engines plug
6
+ * into the same shape without changing adapters.
7
+ */
8
+ export type ManagedArchiveKind = "zip" | "tar.gz" | "none";
9
+ export type ManagedArtifact = {
10
+ url: string;
11
+ sha256: string;
12
+ archive: ManagedArchiveKind;
13
+ /** File name of the executable inside the archive (or the copied file). */
14
+ binary: string;
15
+ };
16
+ export type ManagedToolSpec = {
17
+ id: string;
18
+ version: string;
19
+ artifacts: Record<string, ManagedArtifact>;
20
+ };
21
+ export declare const MANAGED_TOOLS: Record<string, ManagedToolSpec>;
22
+ export declare function isManagedTool(id: string): boolean;
23
+ export declare function getManagedTool(id: string): ManagedToolSpec | undefined;
24
+ export declare function currentPlatformKey(): string;
25
+ export declare function artifactFor(spec: ManagedToolSpec, platformKey?: string): ManagedArtifact | undefined;
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ /**
3
+ * Pinned managed-tool catalog.
4
+ *
5
+ * Adapters ask for `tool: "ruff"`; ToolRuntime maps that name onto a
6
+ * versioned, checksummed artifact in the VibeDoctor cache. Other engines plug
7
+ * into the same shape without changing adapters.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.MANAGED_TOOLS = void 0;
11
+ exports.isManagedTool = isManagedTool;
12
+ exports.getManagedTool = getManagedTool;
13
+ exports.currentPlatformKey = currentPlatformKey;
14
+ exports.artifactFor = artifactFor;
15
+ const RUFF_VERSION = "0.16.3";
16
+ const RUFF_BASE = `https://releases.astral.sh/github/ruff/releases/download/${RUFF_VERSION}`;
17
+ const GITLEAKS_VERSION = "8.30.1";
18
+ const GITLEAKS_BASE = `https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}`;
19
+ const OSV_VERSION = "2.5.0";
20
+ const OSV_BASE = `https://github.com/google/osv-scanner/releases/download/v${OSV_VERSION}`;
21
+ exports.MANAGED_TOOLS = {
22
+ ruff: {
23
+ id: "ruff",
24
+ version: RUFF_VERSION,
25
+ artifacts: {
26
+ "win32-x64": {
27
+ url: `${RUFF_BASE}/ruff-x86_64-pc-windows-msvc.zip`,
28
+ sha256: "f10c709755b393fd9821506b21070bcca969b9966504edd1e490efd08e3662ba",
29
+ archive: "zip",
30
+ binary: "ruff.exe"
31
+ },
32
+ "win32-arm64": {
33
+ url: `${RUFF_BASE}/ruff-aarch64-pc-windows-msvc.zip`,
34
+ sha256: "9a9915c54b27b26c972271fbd603845610bb379a7f29571daf923fd8d2bda33e",
35
+ archive: "zip",
36
+ binary: "ruff.exe"
37
+ },
38
+ "darwin-x64": {
39
+ url: `${RUFF_BASE}/ruff-x86_64-apple-darwin.tar.gz`,
40
+ sha256: "05c2a6705e7c0c056d6d93ff538978583f0c47b4c28d334ab9d58d2e8daf4c24",
41
+ archive: "tar.gz",
42
+ binary: "ruff"
43
+ },
44
+ "darwin-arm64": {
45
+ url: `${RUFF_BASE}/ruff-aarch64-apple-darwin.tar.gz`,
46
+ sha256: "136a4db6512d9b16dda56ac8604696ed65c3b1a914a142de029e7f8d5006f1d9",
47
+ archive: "tar.gz",
48
+ binary: "ruff"
49
+ },
50
+ "linux-x64": {
51
+ url: `${RUFF_BASE}/ruff-x86_64-unknown-linux-gnu.tar.gz`,
52
+ sha256: "7ab3b978d2c0b1c96b2323d4e5c4f35284ae1cdf35d2f7399595c74c805f5fa3",
53
+ archive: "tar.gz",
54
+ binary: "ruff"
55
+ },
56
+ "linux-arm64": {
57
+ url: `${RUFF_BASE}/ruff-aarch64-unknown-linux-gnu.tar.gz`,
58
+ sha256: "b9cc833f5db856484b38718c9da195a6ec990707307bda30530913a09705419a",
59
+ archive: "tar.gz",
60
+ binary: "ruff"
61
+ },
62
+ "linux-x64-musl": {
63
+ url: `${RUFF_BASE}/ruff-x86_64-unknown-linux-musl.tar.gz`,
64
+ sha256: "d67c9b5949981698c48915abf65e0b3406ba9184ad73521cdf20a926bc889c73",
65
+ archive: "tar.gz",
66
+ binary: "ruff"
67
+ }
68
+ }
69
+ },
70
+ gitleaks: {
71
+ id: "gitleaks",
72
+ version: GITLEAKS_VERSION,
73
+ artifacts: {
74
+ "win32-x64": {
75
+ url: `${GITLEAKS_BASE}/gitleaks_${GITLEAKS_VERSION}_windows_x64.zip`,
76
+ sha256: "d29144deff3a68aa93ced33dddf84b7fdc26070add4aa0f4513094c8332afc4e",
77
+ archive: "zip",
78
+ binary: "gitleaks.exe"
79
+ },
80
+ "win32-arm64": {
81
+ url: `${GITLEAKS_BASE}/gitleaks_${GITLEAKS_VERSION}_windows_arm64.zip`,
82
+ sha256: "b95f5e4f5c425cedca7ee203d9afd29597e692c4924a12ed42f970537c72cc0f",
83
+ archive: "zip",
84
+ binary: "gitleaks.exe"
85
+ },
86
+ "darwin-x64": {
87
+ url: `${GITLEAKS_BASE}/gitleaks_${GITLEAKS_VERSION}_darwin_x64.tar.gz`,
88
+ sha256: "dfe101a4db2255fc85120ac7f3d25e4342c3c20cf749f2c20a18081af1952709",
89
+ archive: "tar.gz",
90
+ binary: "gitleaks"
91
+ },
92
+ "darwin-arm64": {
93
+ url: `${GITLEAKS_BASE}/gitleaks_${GITLEAKS_VERSION}_darwin_arm64.tar.gz`,
94
+ sha256: "b40ab0ae55c505963e365f271a8d3846efbc170aa17f2607f13df610a9aeb6a5",
95
+ archive: "tar.gz",
96
+ binary: "gitleaks"
97
+ },
98
+ "linux-x64": {
99
+ url: `${GITLEAKS_BASE}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz`,
100
+ sha256: "551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb",
101
+ archive: "tar.gz",
102
+ binary: "gitleaks"
103
+ },
104
+ "linux-arm64": {
105
+ url: `${GITLEAKS_BASE}/gitleaks_${GITLEAKS_VERSION}_linux_arm64.tar.gz`,
106
+ sha256: "e4a487ee7ccd7d3a7f7ec08657610aa3606637dab924210b3aee62570fb4b080",
107
+ archive: "tar.gz",
108
+ binary: "gitleaks"
109
+ }
110
+ }
111
+ },
112
+ "osv-scanner": {
113
+ id: "osv-scanner",
114
+ version: OSV_VERSION,
115
+ artifacts: {
116
+ "win32-x64": {
117
+ url: `${OSV_BASE}/osv-scanner_windows_amd64.exe`,
118
+ sha256: "4342285bd8be36b9f113468f3eea86e7900befbcd19ca8dc6ac4f0f6cbe7c362",
119
+ archive: "none",
120
+ binary: "osv-scanner.exe"
121
+ },
122
+ "win32-arm64": {
123
+ url: `${OSV_BASE}/osv-scanner_windows_arm64.exe`,
124
+ sha256: "b8bb8d499e0636e193688c96834a11a8f74e353734053f9641e546d76a0cb857",
125
+ archive: "none",
126
+ binary: "osv-scanner.exe"
127
+ },
128
+ "darwin-x64": {
129
+ url: `${OSV_BASE}/osv-scanner_darwin_amd64`,
130
+ sha256: "baef4f4a4ce2924a9241869c36d4bd9d6c04b632cae6637a0f6347ab9272eb16",
131
+ archive: "none",
132
+ binary: "osv-scanner"
133
+ },
134
+ "darwin-arm64": {
135
+ url: `${OSV_BASE}/osv-scanner_darwin_arm64`,
136
+ sha256: "fff5a2e351b7f0a60001e87cbf862e82fb82e2792d368b533fec7a5865a73da2",
137
+ archive: "none",
138
+ binary: "osv-scanner"
139
+ },
140
+ "linux-x64": {
141
+ url: `${OSV_BASE}/osv-scanner_linux_amd64`,
142
+ sha256: "edcfc41d257db36148f065055655fe3fcfc434b0b423ea67468a84c207524e0c",
143
+ archive: "none",
144
+ binary: "osv-scanner"
145
+ },
146
+ "linux-arm64": {
147
+ url: `${OSV_BASE}/osv-scanner_linux_arm64`,
148
+ sha256: "fe152e1a546af223e6c557cc3111a8bb3e5dc02fcbf7dbe95d26567c0f0041f2",
149
+ archive: "none",
150
+ binary: "osv-scanner"
151
+ }
152
+ }
153
+ }
154
+ };
155
+ function isManagedTool(id) {
156
+ return Boolean(exports.MANAGED_TOOLS[id]);
157
+ }
158
+ function getManagedTool(id) {
159
+ return exports.MANAGED_TOOLS[id];
160
+ }
161
+ function currentPlatformKey() {
162
+ const os = process.platform === "win32" || process.platform === "darwin" || process.platform === "linux" ? process.platform : "linux";
163
+ const arch = process.arch === "x64" || process.arch === "arm64" || process.arch === "ia32" || process.arch === "arm" ? process.arch : "x64";
164
+ if (os === "linux" && arch === "x64" && typeof process.report?.getReport === "function" && isMusl()) {
165
+ return "linux-x64-musl";
166
+ }
167
+ if (os === "win32" && arch === "ia32") {
168
+ return "win32-x64";
169
+ }
170
+ return `${os}-${arch === "ia32" ? "x64" : arch}`;
171
+ }
172
+ function isMusl() {
173
+ try {
174
+ const report = process.report?.getReport();
175
+ if (report && typeof report === "object") {
176
+ return !report.header?.glibcVersionRuntime;
177
+ }
178
+ }
179
+ catch {
180
+ // Best-effort; fall back to gnu.
181
+ }
182
+ return false;
183
+ }
184
+ function artifactFor(spec, platformKey = currentPlatformKey()) {
185
+ return spec.artifacts[platformKey];
186
+ }