@neuralaxis/vibedoctor 0.1.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 (135) hide show
  1. package/LICENSE +232 -0
  2. package/README.md +280 -0
  3. package/dist/adapters/biome.d.ts +2 -0
  4. package/dist/adapters/biome.js +66 -0
  5. package/dist/adapters/coveragePy.d.ts +2 -0
  6. package/dist/adapters/coveragePy.js +56 -0
  7. package/dist/adapters/customDeadChain.d.ts +20 -0
  8. package/dist/adapters/customDeadChain.js +243 -0
  9. package/dist/adapters/customLeftovers.d.ts +2 -0
  10. package/dist/adapters/customLeftovers.js +244 -0
  11. package/dist/adapters/customRefactor.d.ts +2 -0
  12. package/dist/adapters/customRefactor.js +176 -0
  13. package/dist/adapters/deptry.d.ts +2 -0
  14. package/dist/adapters/deptry.js +59 -0
  15. package/dist/adapters/gitleaks.d.ts +2 -0
  16. package/dist/adapters/gitleaks.js +47 -0
  17. package/dist/adapters/index.d.ts +16 -0
  18. package/dist/adapters/index.js +35 -0
  19. package/dist/adapters/jest.d.ts +2 -0
  20. package/dist/adapters/jest.js +62 -0
  21. package/dist/adapters/jscpd.d.ts +2 -0
  22. package/dist/adapters/jscpd.js +59 -0
  23. package/dist/adapters/knip.d.ts +2 -0
  24. package/dist/adapters/knip.js +75 -0
  25. package/dist/adapters/lizard.d.ts +2 -0
  26. package/dist/adapters/lizard.js +45 -0
  27. package/dist/adapters/osvScanner.d.ts +2 -0
  28. package/dist/adapters/osvScanner.js +68 -0
  29. package/dist/adapters/pyright.d.ts +2 -0
  30. package/dist/adapters/pyright.js +52 -0
  31. package/dist/adapters/radon.d.ts +2 -0
  32. package/dist/adapters/radon.js +45 -0
  33. package/dist/adapters/ruff.d.ts +2 -0
  34. package/dist/adapters/ruff.js +71 -0
  35. package/dist/adapters/semgrep.d.ts +2 -0
  36. package/dist/adapters/semgrep.js +64 -0
  37. package/dist/adapters/shared.d.ts +23 -0
  38. package/dist/adapters/shared.js +2 -0
  39. package/dist/adapters/tsc.d.ts +2 -0
  40. package/dist/adapters/tsc.js +57 -0
  41. package/dist/adapters/vitest.d.ts +2 -0
  42. package/dist/adapters/vitest.js +62 -0
  43. package/dist/adapters/vulture.d.ts +2 -0
  44. package/dist/adapters/vulture.js +59 -0
  45. package/dist/agentPack/generateAgentPack.d.ts +48 -0
  46. package/dist/agentPack/generateAgentPack.js +219 -0
  47. package/dist/agentPack/policy.d.ts +19 -0
  48. package/dist/agentPack/policy.js +117 -0
  49. package/dist/agentPack/templates/index.d.ts +7 -0
  50. package/dist/agentPack/templates/index.js +134 -0
  51. package/dist/agentPack/templates/skills.d.ts +7 -0
  52. package/dist/agentPack/templates/skills.js +337 -0
  53. package/dist/cli/commands/agent.d.ts +22 -0
  54. package/dist/cli/commands/agent.js +57 -0
  55. package/dist/cli/commands/agentPlan.d.ts +1 -0
  56. package/dist/cli/commands/agentPlan.js +12 -0
  57. package/dist/cli/commands/baseline.d.ts +1 -0
  58. package/dist/cli/commands/baseline.js +8 -0
  59. package/dist/cli/commands/explain.d.ts +1 -0
  60. package/dist/cli/commands/explain.js +35 -0
  61. package/dist/cli/commands/fix.d.ts +1 -0
  62. package/dist/cli/commands/fix.js +19 -0
  63. package/dist/cli/commands/init.d.ts +1 -0
  64. package/dist/cli/commands/init.js +101 -0
  65. package/dist/cli/commands/report.d.ts +1 -0
  66. package/dist/cli/commands/report.js +25 -0
  67. package/dist/cli/commands/scan.d.ts +14 -0
  68. package/dist/cli/commands/scan.js +61 -0
  69. package/dist/cli/commands/setup.d.ts +35 -0
  70. package/dist/cli/commands/setup.js +326 -0
  71. package/dist/cli/commands/shared.d.ts +8 -0
  72. package/dist/cli/commands/shared.js +29 -0
  73. package/dist/cli/index.d.ts +2 -0
  74. package/dist/cli/index.js +148 -0
  75. package/dist/core/baseline.d.ts +7 -0
  76. package/dist/core/baseline.js +33 -0
  77. package/dist/core/config.d.ts +72 -0
  78. package/dist/core/config.js +236 -0
  79. package/dist/core/engine.d.ts +87 -0
  80. package/dist/core/engine.js +437 -0
  81. package/dist/core/finding.d.ts +40 -0
  82. package/dist/core/finding.js +141 -0
  83. package/dist/core/git.d.ts +3 -0
  84. package/dist/core/git.js +67 -0
  85. package/dist/core/paths.d.ts +7 -0
  86. package/dist/core/paths.js +104 -0
  87. package/dist/core/projectDetector.d.ts +17 -0
  88. package/dist/core/projectDetector.js +160 -0
  89. package/dist/core/scanPlanner.d.ts +11 -0
  90. package/dist/core/scanPlanner.js +47 -0
  91. package/dist/core/scoring.d.ts +8 -0
  92. package/dist/core/scoring.js +57 -0
  93. package/dist/core/toolRunner.d.ts +24 -0
  94. package/dist/core/toolRunner.js +130 -0
  95. package/dist/index.d.ts +7 -0
  96. package/dist/index.js +23 -0
  97. package/dist/mcp/server.d.ts +1 -0
  98. package/dist/mcp/server.js +141 -0
  99. package/dist/mcp/tools/explainFinding.d.ts +2 -0
  100. package/dist/mcp/tools/explainFinding.js +23 -0
  101. package/dist/mcp/tools/fixSafe.d.ts +2 -0
  102. package/dist/mcp/tools/fixSafe.js +15 -0
  103. package/dist/mcp/tools/getAgentPlan.d.ts +2 -0
  104. package/dist/mcp/tools/getAgentPlan.js +31 -0
  105. package/dist/mcp/tools/getReport.d.ts +2 -0
  106. package/dist/mcp/tools/getReport.js +26 -0
  107. package/dist/mcp/tools/index.d.ts +1 -0
  108. package/dist/mcp/tools/index.js +19 -0
  109. package/dist/mcp/tools/scanChanged.d.ts +2 -0
  110. package/dist/mcp/tools/scanChanged.js +23 -0
  111. package/dist/mcp/tools/scanFull.d.ts +2 -0
  112. package/dist/mcp/tools/scanFull.js +23 -0
  113. package/dist/mcp/tools/shared.d.ts +51 -0
  114. package/dist/mcp/tools/shared.js +126 -0
  115. package/dist/mcp/tools/verify.d.ts +2 -0
  116. package/dist/mcp/tools/verify.js +21 -0
  117. package/dist/reporters/agent.d.ts +3 -0
  118. package/dist/reporters/agent.js +48 -0
  119. package/dist/reporters/html.d.ts +2 -0
  120. package/dist/reporters/html.js +81 -0
  121. package/dist/reporters/json.d.ts +2 -0
  122. package/dist/reporters/json.js +18 -0
  123. package/dist/reporters/markdown.d.ts +2 -0
  124. package/dist/reporters/markdown.js +33 -0
  125. package/dist/reporters/sarif.d.ts +2 -0
  126. package/dist/reporters/sarif.js +38 -0
  127. package/dist/reporters/terminal.d.ts +2 -0
  128. package/dist/reporters/terminal.js +11 -0
  129. package/dist/rules/leftoverPatterns.d.ts +7 -0
  130. package/dist/rules/leftoverPatterns.js +10 -0
  131. package/dist/rules/refactorRules.d.ts +13 -0
  132. package/dist/rules/refactorRules.js +16 -0
  133. package/dist/rules/severityMap.d.ts +15 -0
  134. package/dist/rules/severityMap.js +33 -0
  135. package/package.json +72 -0
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runMcpServer = runMcpServer;
4
+ const tools_1 = require("./tools");
5
+ function writeMessage(payload) {
6
+ const body = JSON.stringify(payload);
7
+ process.stdout.write(`Content-Length: ${Buffer.byteLength(body, "utf8")}\r\n\r\n${body}`);
8
+ }
9
+ function writeResult(id, result) {
10
+ writeMessage({
11
+ jsonrpc: "2.0",
12
+ id,
13
+ result
14
+ });
15
+ }
16
+ function writeError(id, code, message) {
17
+ writeMessage({
18
+ jsonrpc: "2.0",
19
+ id,
20
+ error: {
21
+ code,
22
+ message
23
+ }
24
+ });
25
+ }
26
+ function parseMessages(buffer) {
27
+ const messages = [];
28
+ let cursor = buffer;
29
+ while (cursor.length > 0) {
30
+ const headerEnd = cursor.indexOf("\r\n\r\n");
31
+ if (headerEnd === -1) {
32
+ break;
33
+ }
34
+ const header = cursor.subarray(0, headerEnd).toString("utf8");
35
+ const match = header.match(/Content-Length:\s*(\d+)/i);
36
+ if (!match) {
37
+ throw new Error("Missing Content-Length header");
38
+ }
39
+ const length = Number.parseInt(match[1], 10);
40
+ const bodyStart = headerEnd + 4;
41
+ const bodyEnd = bodyStart + length;
42
+ if (cursor.length < bodyEnd) {
43
+ break;
44
+ }
45
+ messages.push(JSON.parse(cursor.subarray(bodyStart, bodyEnd).toString("utf8")));
46
+ cursor = cursor.subarray(bodyEnd);
47
+ }
48
+ return { messages, remaining: cursor };
49
+ }
50
+ async function handleRequest(root, request) {
51
+ const id = request.id ?? null;
52
+ if (!request.method) {
53
+ if (request.id !== undefined) {
54
+ writeError(id, -32600, "Invalid request");
55
+ }
56
+ return;
57
+ }
58
+ try {
59
+ switch (request.method) {
60
+ case "initialize":
61
+ writeResult(id, {
62
+ protocolVersion: "2024-11-05",
63
+ serverInfo: {
64
+ name: "vibedoctor",
65
+ version: "0.1.0"
66
+ },
67
+ capabilities: {
68
+ tools: {}
69
+ }
70
+ });
71
+ return;
72
+ case "notifications/initialized":
73
+ return;
74
+ case "ping":
75
+ writeResult(id, {});
76
+ return;
77
+ case "tools/list":
78
+ writeResult(id, {
79
+ tools: tools_1.mcpTools.map((tool) => ({
80
+ name: tool.name,
81
+ description: tool.description,
82
+ inputSchema: tool.inputSchema
83
+ }))
84
+ });
85
+ return;
86
+ case "tools/call": {
87
+ const toolName = request.params?.name;
88
+ if (typeof toolName !== "string") {
89
+ writeError(id, -32602, "Tool name is required");
90
+ return;
91
+ }
92
+ const tool = tools_1.mcpTools.find((candidate) => candidate.name === toolName);
93
+ if (!tool) {
94
+ writeError(id, -32601, `Unknown tool: ${toolName}`);
95
+ return;
96
+ }
97
+ const args = request.params?.arguments;
98
+ const result = await tool.call(root, (typeof args === "object" && args !== null ? args : {}));
99
+ writeResult(id, {
100
+ content: [
101
+ {
102
+ type: "text",
103
+ text: JSON.stringify(result, null, 2)
104
+ }
105
+ ],
106
+ structuredContent: result
107
+ });
108
+ return;
109
+ }
110
+ default:
111
+ writeError(id, -32601, `Unsupported method: ${request.method}`);
112
+ }
113
+ }
114
+ catch (error) {
115
+ const message = error instanceof Error ? error.message : String(error);
116
+ writeError(id, -32000, message);
117
+ }
118
+ }
119
+ async function runMcpServer(root) {
120
+ let buffer = Buffer.alloc(0);
121
+ process.stdin.on("data", async (chunk) => {
122
+ try {
123
+ buffer = Buffer.concat([buffer, chunk]);
124
+ const parsed = parseMessages(buffer);
125
+ buffer = parsed.remaining;
126
+ for (const message of parsed.messages) {
127
+ await handleRequest(root, message);
128
+ }
129
+ }
130
+ catch (error) {
131
+ const message = error instanceof Error ? error.message : String(error);
132
+ writeError(null, -32700, message);
133
+ buffer = Buffer.alloc(0);
134
+ }
135
+ });
136
+ process.stdin.resume();
137
+ await new Promise((resolve) => {
138
+ process.stdin.on("end", () => resolve());
139
+ process.stdin.on("close", () => resolve());
140
+ });
141
+ }
@@ -0,0 +1,2 @@
1
+ import { type McpToolDefinition } from "./shared";
2
+ export declare const explainFindingTool: McpToolDefinition;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.explainFindingTool = void 0;
4
+ const shared_1 = require("./shared");
5
+ exports.explainFindingTool = {
6
+ name: "vibedoctor_explain_finding",
7
+ description: "Explain a specific VibeDoctor finding by finding ID.",
8
+ inputSchema: {
9
+ type: "object",
10
+ required: ["findingId"],
11
+ properties: {
12
+ findingId: {
13
+ type: "string"
14
+ }
15
+ }
16
+ },
17
+ async call(root, args) {
18
+ if (typeof args.findingId !== "string" || args.findingId.trim() === "") {
19
+ throw new Error("findingId is required");
20
+ }
21
+ return (0, shared_1.explainFindingPayload)(root, args.findingId);
22
+ }
23
+ };
@@ -0,0 +1,2 @@
1
+ import { type McpToolDefinition } from "./shared";
2
+ export declare const fixSafeTool: McpToolDefinition;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fixSafeTool = void 0;
4
+ const shared_1 = require("./shared");
5
+ exports.fixSafeTool = {
6
+ name: "vibedoctor_fix_safe",
7
+ description: "Run VibeDoctor safe fixes and return before/after finding counts.",
8
+ inputSchema: {
9
+ type: "object",
10
+ properties: {}
11
+ },
12
+ async call(root) {
13
+ return (0, shared_1.fixSafePayload)(root);
14
+ }
15
+ };
@@ -0,0 +1,2 @@
1
+ import { type McpToolDefinition } from "./shared";
2
+ export declare const getAgentPlanTool: McpToolDefinition;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAgentPlanTool = void 0;
4
+ const shared_1 = require("./shared");
5
+ function parseTarget(value) {
6
+ if (value === "codex" || value === "copilot" || value === "claude" || value === "cursor") {
7
+ return value;
8
+ }
9
+ return "generic";
10
+ }
11
+ exports.getAgentPlanTool = {
12
+ name: "vibedoctor_get_agent_plan",
13
+ description: "Return the current VibeDoctor agent plan in JSON or markdown.",
14
+ inputSchema: {
15
+ type: "object",
16
+ properties: {
17
+ format: {
18
+ type: "string",
19
+ enum: ["json", "markdown"]
20
+ },
21
+ target: {
22
+ type: "string",
23
+ enum: ["generic", "codex", "copilot", "claude", "cursor"]
24
+ }
25
+ }
26
+ },
27
+ async call(root, args) {
28
+ const format = args.format === "markdown" ? "markdown" : "json";
29
+ return (0, shared_1.getAgentPlanPayload)(root, format, parseTarget(args.target));
30
+ }
31
+ };
@@ -0,0 +1,2 @@
1
+ import { type McpToolDefinition } from "./shared";
2
+ export declare const getReportTool: McpToolDefinition;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getReportTool = void 0;
4
+ const shared_1 = require("./shared");
5
+ exports.getReportTool = {
6
+ name: "vibedoctor_get_report",
7
+ description: "Read the current VibeDoctor JSON report, optionally refreshing it first.",
8
+ inputSchema: {
9
+ type: "object",
10
+ properties: {
11
+ refresh: {
12
+ type: "boolean"
13
+ },
14
+ mode: {
15
+ type: "string",
16
+ enum: ["changed", "full"]
17
+ }
18
+ }
19
+ },
20
+ async call(root, args) {
21
+ const mode = args.mode === "full" ? "full" : "changed";
22
+ return {
23
+ report: await (0, shared_1.readReportJson)(root, args.refresh === true, mode)
24
+ };
25
+ }
26
+ };
@@ -0,0 +1 @@
1
+ export declare const mcpTools: import("./shared").McpToolDefinition[];
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mcpTools = void 0;
4
+ const explainFinding_1 = require("./explainFinding");
5
+ const fixSafe_1 = require("./fixSafe");
6
+ const getAgentPlan_1 = require("./getAgentPlan");
7
+ const getReport_1 = require("./getReport");
8
+ const scanChanged_1 = require("./scanChanged");
9
+ const scanFull_1 = require("./scanFull");
10
+ const verify_1 = require("./verify");
11
+ exports.mcpTools = [
12
+ scanChanged_1.scanChangedTool,
13
+ scanFull_1.scanFullTool,
14
+ fixSafe_1.fixSafeTool,
15
+ getReport_1.getReportTool,
16
+ getAgentPlan_1.getAgentPlanTool,
17
+ explainFinding_1.explainFindingTool,
18
+ verify_1.verifyTool
19
+ ];
@@ -0,0 +1,2 @@
1
+ import { type McpToolDefinition } from "./shared";
2
+ export declare const scanChangedTool: McpToolDefinition;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scanChangedTool = void 0;
4
+ const shared_1 = require("./shared");
5
+ exports.scanChangedTool = {
6
+ name: "vibedoctor_scan_changed",
7
+ description: "Run VibeDoctor on changed files and return normalized health findings.",
8
+ inputSchema: {
9
+ type: "object",
10
+ properties: {
11
+ categories: shared_1.categorySchema,
12
+ failOnBlockers: {
13
+ type: "boolean"
14
+ }
15
+ }
16
+ },
17
+ async call(root, args) {
18
+ const categories = (0, shared_1.parseCategories)(args.categories);
19
+ const failOnBlockers = args.failOnBlockers === true;
20
+ const { scan, reportPath, agentPlanPath, exitCode } = await (0, shared_1.prepareScan)(root, "changed", categories);
21
+ return (0, shared_1.buildScanResult)(scan, reportPath, agentPlanPath, exitCode, failOnBlockers);
22
+ }
23
+ };
@@ -0,0 +1,2 @@
1
+ import { type McpToolDefinition } from "./shared";
2
+ export declare const scanFullTool: McpToolDefinition;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scanFullTool = void 0;
4
+ const shared_1 = require("./shared");
5
+ exports.scanFullTool = {
6
+ name: "vibedoctor_scan_full",
7
+ description: "Run VibeDoctor on the full repository and return normalized health findings.",
8
+ inputSchema: {
9
+ type: "object",
10
+ properties: {
11
+ categories: shared_1.categorySchema,
12
+ failOnBlockers: {
13
+ type: "boolean"
14
+ }
15
+ }
16
+ },
17
+ async call(root, args) {
18
+ const categories = (0, shared_1.parseCategories)(args.categories);
19
+ const failOnBlockers = args.failOnBlockers === true;
20
+ const { scan, reportPath, agentPlanPath, exitCode } = await (0, shared_1.prepareScan)(root, "full", categories);
21
+ return (0, shared_1.buildScanResult)(scan, reportPath, agentPlanPath, exitCode, failOnBlockers);
22
+ }
23
+ };
@@ -0,0 +1,51 @@
1
+ import { type AgentPlan, type ScanOutput } from "../../core/engine";
2
+ import { type Finding, type FindingCategory } from "../../core/finding";
3
+ export type McpToolDefinition = {
4
+ name: string;
5
+ description: string;
6
+ inputSchema: Record<string, unknown>;
7
+ call: (root: string, args: Record<string, unknown>) => Promise<unknown>;
8
+ };
9
+ export type ScanToolResult = {
10
+ score: number;
11
+ status: "ok" | "warning" | "blocked";
12
+ exitCode: number;
13
+ blockers: Array<{
14
+ id: string;
15
+ title: string;
16
+ file?: string;
17
+ severity: Finding["severity"];
18
+ }>;
19
+ topFindings: Array<{
20
+ id: string;
21
+ title: string;
22
+ category: Finding["category"];
23
+ severity: Finding["severity"];
24
+ file?: string;
25
+ }>;
26
+ reportPath: string;
27
+ agentPlanPath: string;
28
+ };
29
+ export declare const categorySchema: {
30
+ readonly type: "array";
31
+ readonly items: {
32
+ readonly type: "string";
33
+ readonly enum: readonly ["security", "correctness", "dead_code", "leftovers", "maintainability", "dependencies", "tests", "efficiency", "refactor_readiness"];
34
+ };
35
+ };
36
+ export declare function parseCategories(value: unknown): FindingCategory[] | undefined;
37
+ export declare function prepareScan(root: string, mode: "changed" | "full" | "default", categories?: FindingCategory[], target?: AgentPlan["target"]): Promise<{
38
+ scan: ScanOutput;
39
+ reportPath: string;
40
+ agentPlanPath: string;
41
+ exitCode: number;
42
+ }>;
43
+ export declare function buildScanResult(scan: ScanOutput, reportPath: string, agentPlanPath: string, exitCode: number, failOnBlockers?: boolean): ScanToolResult;
44
+ export declare function readReportJson(root: string, refresh?: boolean, mode?: "changed" | "full"): Promise<unknown>;
45
+ export declare function getAgentPlanPayload(root: string, format?: "json" | "markdown", target?: AgentPlan["target"]): Promise<{
46
+ format: "json" | "markdown";
47
+ target: AgentPlan["target"];
48
+ plan: unknown;
49
+ }>;
50
+ export declare function explainFindingPayload(root: string, findingId: string): Promise<unknown>;
51
+ export declare function fixSafePayload(root: string): Promise<unknown>;
@@ -0,0 +1,126 @@
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.categorySchema = void 0;
7
+ exports.parseCategories = parseCategories;
8
+ exports.prepareScan = prepareScan;
9
+ exports.buildScanResult = buildScanResult;
10
+ exports.readReportJson = readReportJson;
11
+ exports.getAgentPlanPayload = getAgentPlanPayload;
12
+ exports.explainFindingPayload = explainFindingPayload;
13
+ exports.fixSafePayload = fixSafePayload;
14
+ const node_fs_1 = require("node:fs");
15
+ const node_path_1 = __importDefault(require("node:path"));
16
+ const policy_1 = require("../../agentPack/policy");
17
+ const scan_1 = require("../../cli/commands/scan");
18
+ const shared_1 = require("../../cli/commands/shared");
19
+ const engine_1 = require("../../core/engine");
20
+ const finding_1 = require("../../core/finding");
21
+ const paths_1 = require("../../core/paths");
22
+ const agent_1 = require("../../reporters/agent");
23
+ exports.categorySchema = {
24
+ type: "array",
25
+ items: {
26
+ type: "string",
27
+ enum: [...finding_1.FINDING_CATEGORIES]
28
+ }
29
+ };
30
+ function isFindingCategory(value) {
31
+ return typeof value === "string" && finding_1.FINDING_CATEGORIES.includes(value);
32
+ }
33
+ function parseCategories(value) {
34
+ if (value === undefined) {
35
+ return undefined;
36
+ }
37
+ if (!Array.isArray(value)) {
38
+ throw new Error("categories must be an array");
39
+ }
40
+ const invalid = value.filter((item) => !isFindingCategory(item));
41
+ if (invalid.length > 0) {
42
+ throw new Error(`Unsupported categories: ${invalid.join(", ")}`);
43
+ }
44
+ return value;
45
+ }
46
+ async function prepareScan(root, mode, categories, target = "generic") {
47
+ const scan = await (0, engine_1.runScan)(root, mode);
48
+ const { config } = await (0, shared_1.getConfig)(root);
49
+ const { policy } = await (0, policy_1.loadAgentPolicy)(root);
50
+ const filtered = categories && categories.length > 0 ? (0, engine_1.filterScanByCategories)(scan, categories, { policy, target }) : scan;
51
+ const withPlan = {
52
+ ...filtered,
53
+ agentPlan: (0, engine_1.createAgentPlan)({ findings: filtered.findings, score: filtered.score, skippedTools: filtered.skippedTools }, { policy, target })
54
+ };
55
+ await (0, shared_1.ensureOutputArtifacts)(root, config, withPlan);
56
+ return {
57
+ scan: withPlan,
58
+ reportPath: config.output.json,
59
+ agentPlanPath: config.output.agent,
60
+ exitCode: (0, scan_1.determineExitCode)(withPlan, config)
61
+ };
62
+ }
63
+ function buildScanResult(scan, reportPath, agentPlanPath, exitCode, failOnBlockers = false) {
64
+ const blockers = scan.blockers.map((finding) => ({
65
+ id: finding.id,
66
+ title: finding.title,
67
+ file: finding.file,
68
+ severity: finding.severity
69
+ }));
70
+ return {
71
+ score: scan.score.overall,
72
+ status: failOnBlockers && blockers.length > 0 ? "blocked" : exitCode === 0 ? "ok" : "warning",
73
+ exitCode,
74
+ blockers,
75
+ topFindings: scan.topFindings.slice(0, 5).map((finding) => ({
76
+ id: finding.id,
77
+ title: finding.title,
78
+ category: finding.category,
79
+ severity: finding.severity,
80
+ file: finding.file
81
+ })),
82
+ reportPath,
83
+ agentPlanPath
84
+ };
85
+ }
86
+ async function readReportJson(root, refresh = false, mode = "changed") {
87
+ const { config } = await (0, shared_1.getConfig)(root);
88
+ const reportPath = node_path_1.default.join(root, config.output.json);
89
+ if (refresh || !(await (0, paths_1.pathExists)(reportPath))) {
90
+ await prepareScan(root, mode);
91
+ }
92
+ return JSON.parse(await node_fs_1.promises.readFile(reportPath, "utf8"));
93
+ }
94
+ async function getAgentPlanPayload(root, format = "json", target = "generic") {
95
+ const { scan } = await prepareScan(root, "default", undefined, target);
96
+ return {
97
+ format,
98
+ target,
99
+ plan: format === "markdown" ? (0, agent_1.renderAgentMarkdown)(scan.agentPlan) : scan.agentPlan
100
+ };
101
+ }
102
+ async function explainFindingPayload(root, findingId) {
103
+ const scan = await (0, engine_1.runScan)(root, "default");
104
+ return (0, engine_1.buildExplainPayload)(scan, findingId);
105
+ }
106
+ async function fixSafePayload(root) {
107
+ const { policy } = await (0, policy_1.loadAgentPolicy)(root);
108
+ if (!policy.agentPolicy.allowSafeFix) {
109
+ throw new Error("Safe fixes are disabled by .vibedoctor/agent-policy.yml");
110
+ }
111
+ const result = await (0, engine_1.safeFix)(root);
112
+ const { config } = await (0, shared_1.getConfig)(root);
113
+ await (0, shared_1.ensureOutputArtifacts)(root, config, result.after);
114
+ return {
115
+ beforeFindings: result.before.findings.length,
116
+ afterFindings: result.after.findings.length,
117
+ issuesFixed: Math.max(0, result.before.findings.length - result.after.findings.length),
118
+ toolResults: result.results.map((item) => ({
119
+ id: item.id,
120
+ status: item.status,
121
+ command: item.command
122
+ })),
123
+ reportPath: config.output.json,
124
+ agentPlanPath: config.output.agent
125
+ };
126
+ }
@@ -0,0 +1,2 @@
1
+ import { type McpToolDefinition } from "./shared";
2
+ export declare const verifyTool: McpToolDefinition;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyTool = void 0;
4
+ const shared_1 = require("./shared");
5
+ exports.verifyTool = {
6
+ name: "vibedoctor_verify",
7
+ description: "Run the standard changed-file verification pass and return the result.",
8
+ inputSchema: {
9
+ type: "object",
10
+ properties: {
11
+ failOnBlockers: {
12
+ type: "boolean"
13
+ }
14
+ }
15
+ },
16
+ async call(root, args) {
17
+ const failOnBlockers = args.failOnBlockers === true;
18
+ const { scan, reportPath, agentPlanPath, exitCode } = await (0, shared_1.prepareScan)(root, "changed");
19
+ return (0, shared_1.buildScanResult)(scan, reportPath, agentPlanPath, exitCode, failOnBlockers);
20
+ }
21
+ };
@@ -0,0 +1,3 @@
1
+ import type { AgentPlan, ScanOutput } from "../core/engine";
2
+ export declare function renderAgentMarkdown(input: Pick<ScanOutput, "agentPlan"> | AgentPlan): string;
3
+ export declare function renderAgentJson(input: Pick<ScanOutput, "agentPlan"> | AgentPlan): string;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderAgentMarkdown = renderAgentMarkdown;
4
+ exports.renderAgentJson = renderAgentJson;
5
+ function getPlan(input) {
6
+ return "agentPlan" in input ? input.agentPlan : input;
7
+ }
8
+ function renderAgentMarkdown(input) {
9
+ const plan = getPlan(input);
10
+ const lines = ["# VibeDoctor Agent Plan", "", `Goal: ${plan.goal}.`, "", `Target: ${plan.target}`, "", "## Workflow", ""];
11
+ plan.workflow.forEach((step, index) => lines.push(`${index + 1}. ${step}`));
12
+ lines.push("", "## Allowed actions", "");
13
+ plan.allowedActions.forEach((action) => lines.push(`- ${action}`));
14
+ lines.push("", "## Forbidden actions", "");
15
+ plan.forbiddenActions.forEach((action) => lines.push(`- ${action}`));
16
+ lines.push("", "## Rules", "");
17
+ for (const rule of plan.rules) {
18
+ lines.push(`- ${rule}`);
19
+ }
20
+ if (plan.doNotTouch.length > 0) {
21
+ lines.push("", "## What not to trust blindly", "");
22
+ plan.doNotTouch.forEach((item) => lines.push(`- ${item}`));
23
+ }
24
+ for (const task of plan.tasks) {
25
+ lines.push("", `## Task ${task.priority}: ${task.title}`, "");
26
+ if (task.files.length > 0) {
27
+ lines.push("Files:");
28
+ task.files.forEach((file) => lines.push(`- ${file}`));
29
+ lines.push("");
30
+ }
31
+ lines.push("Instructions:");
32
+ task.instructions.forEach((instruction, index) => lines.push(`${index + 1}. ${instruction}`));
33
+ if (task.doNotTouch.length > 0) {
34
+ lines.push("", "Do not touch:");
35
+ task.doNotTouch.forEach((item) => lines.push(`- ${item}`));
36
+ }
37
+ if (task.commands.length > 0) {
38
+ lines.push("", "Commands:");
39
+ task.commands.forEach((command) => lines.push(`- ${command}`));
40
+ }
41
+ lines.push("", "Verify:");
42
+ task.verify.forEach((command) => lines.push(`- ${command}`));
43
+ }
44
+ return `${lines.join("\n")}\n`;
45
+ }
46
+ function renderAgentJson(input) {
47
+ return JSON.stringify(getPlan(input), null, 2);
48
+ }
@@ -0,0 +1,2 @@
1
+ import type { ScanOutput } from "../core/engine";
2
+ export declare function renderHtmlReport(scan: ScanOutput): string;