@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.
- package/LICENSE +232 -0
- package/README.md +280 -0
- package/dist/adapters/biome.d.ts +2 -0
- package/dist/adapters/biome.js +66 -0
- package/dist/adapters/coveragePy.d.ts +2 -0
- package/dist/adapters/coveragePy.js +56 -0
- package/dist/adapters/customDeadChain.d.ts +20 -0
- package/dist/adapters/customDeadChain.js +243 -0
- package/dist/adapters/customLeftovers.d.ts +2 -0
- package/dist/adapters/customLeftovers.js +244 -0
- package/dist/adapters/customRefactor.d.ts +2 -0
- package/dist/adapters/customRefactor.js +176 -0
- package/dist/adapters/deptry.d.ts +2 -0
- package/dist/adapters/deptry.js +59 -0
- package/dist/adapters/gitleaks.d.ts +2 -0
- package/dist/adapters/gitleaks.js +47 -0
- package/dist/adapters/index.d.ts +16 -0
- package/dist/adapters/index.js +35 -0
- package/dist/adapters/jest.d.ts +2 -0
- package/dist/adapters/jest.js +62 -0
- package/dist/adapters/jscpd.d.ts +2 -0
- package/dist/adapters/jscpd.js +59 -0
- package/dist/adapters/knip.d.ts +2 -0
- package/dist/adapters/knip.js +75 -0
- package/dist/adapters/lizard.d.ts +2 -0
- package/dist/adapters/lizard.js +45 -0
- package/dist/adapters/osvScanner.d.ts +2 -0
- package/dist/adapters/osvScanner.js +68 -0
- package/dist/adapters/pyright.d.ts +2 -0
- package/dist/adapters/pyright.js +52 -0
- package/dist/adapters/radon.d.ts +2 -0
- package/dist/adapters/radon.js +45 -0
- package/dist/adapters/ruff.d.ts +2 -0
- package/dist/adapters/ruff.js +71 -0
- package/dist/adapters/semgrep.d.ts +2 -0
- package/dist/adapters/semgrep.js +64 -0
- package/dist/adapters/shared.d.ts +23 -0
- package/dist/adapters/shared.js +2 -0
- package/dist/adapters/tsc.d.ts +2 -0
- package/dist/adapters/tsc.js +57 -0
- package/dist/adapters/vitest.d.ts +2 -0
- package/dist/adapters/vitest.js +62 -0
- package/dist/adapters/vulture.d.ts +2 -0
- package/dist/adapters/vulture.js +59 -0
- package/dist/agentPack/generateAgentPack.d.ts +48 -0
- package/dist/agentPack/generateAgentPack.js +219 -0
- package/dist/agentPack/policy.d.ts +19 -0
- package/dist/agentPack/policy.js +117 -0
- package/dist/agentPack/templates/index.d.ts +7 -0
- package/dist/agentPack/templates/index.js +134 -0
- package/dist/agentPack/templates/skills.d.ts +7 -0
- package/dist/agentPack/templates/skills.js +337 -0
- package/dist/cli/commands/agent.d.ts +22 -0
- package/dist/cli/commands/agent.js +57 -0
- package/dist/cli/commands/agentPlan.d.ts +1 -0
- package/dist/cli/commands/agentPlan.js +12 -0
- package/dist/cli/commands/baseline.d.ts +1 -0
- package/dist/cli/commands/baseline.js +8 -0
- package/dist/cli/commands/explain.d.ts +1 -0
- package/dist/cli/commands/explain.js +35 -0
- package/dist/cli/commands/fix.d.ts +1 -0
- package/dist/cli/commands/fix.js +19 -0
- package/dist/cli/commands/init.d.ts +1 -0
- package/dist/cli/commands/init.js +101 -0
- package/dist/cli/commands/report.d.ts +1 -0
- package/dist/cli/commands/report.js +25 -0
- package/dist/cli/commands/scan.d.ts +14 -0
- package/dist/cli/commands/scan.js +61 -0
- package/dist/cli/commands/setup.d.ts +35 -0
- package/dist/cli/commands/setup.js +326 -0
- package/dist/cli/commands/shared.d.ts +8 -0
- package/dist/cli/commands/shared.js +29 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +148 -0
- package/dist/core/baseline.d.ts +7 -0
- package/dist/core/baseline.js +33 -0
- package/dist/core/config.d.ts +72 -0
- package/dist/core/config.js +236 -0
- package/dist/core/engine.d.ts +87 -0
- package/dist/core/engine.js +437 -0
- package/dist/core/finding.d.ts +40 -0
- package/dist/core/finding.js +141 -0
- package/dist/core/git.d.ts +3 -0
- package/dist/core/git.js +67 -0
- package/dist/core/paths.d.ts +7 -0
- package/dist/core/paths.js +104 -0
- package/dist/core/projectDetector.d.ts +17 -0
- package/dist/core/projectDetector.js +160 -0
- package/dist/core/scanPlanner.d.ts +11 -0
- package/dist/core/scanPlanner.js +47 -0
- package/dist/core/scoring.d.ts +8 -0
- package/dist/core/scoring.js +57 -0
- package/dist/core/toolRunner.d.ts +24 -0
- package/dist/core/toolRunner.js +130 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +23 -0
- package/dist/mcp/server.d.ts +1 -0
- package/dist/mcp/server.js +141 -0
- package/dist/mcp/tools/explainFinding.d.ts +2 -0
- package/dist/mcp/tools/explainFinding.js +23 -0
- package/dist/mcp/tools/fixSafe.d.ts +2 -0
- package/dist/mcp/tools/fixSafe.js +15 -0
- package/dist/mcp/tools/getAgentPlan.d.ts +2 -0
- package/dist/mcp/tools/getAgentPlan.js +31 -0
- package/dist/mcp/tools/getReport.d.ts +2 -0
- package/dist/mcp/tools/getReport.js +26 -0
- package/dist/mcp/tools/index.d.ts +1 -0
- package/dist/mcp/tools/index.js +19 -0
- package/dist/mcp/tools/scanChanged.d.ts +2 -0
- package/dist/mcp/tools/scanChanged.js +23 -0
- package/dist/mcp/tools/scanFull.d.ts +2 -0
- package/dist/mcp/tools/scanFull.js +23 -0
- package/dist/mcp/tools/shared.d.ts +51 -0
- package/dist/mcp/tools/shared.js +126 -0
- package/dist/mcp/tools/verify.d.ts +2 -0
- package/dist/mcp/tools/verify.js +21 -0
- package/dist/reporters/agent.d.ts +3 -0
- package/dist/reporters/agent.js +48 -0
- package/dist/reporters/html.d.ts +2 -0
- package/dist/reporters/html.js +81 -0
- package/dist/reporters/json.d.ts +2 -0
- package/dist/reporters/json.js +18 -0
- package/dist/reporters/markdown.d.ts +2 -0
- package/dist/reporters/markdown.js +33 -0
- package/dist/reporters/sarif.d.ts +2 -0
- package/dist/reporters/sarif.js +38 -0
- package/dist/reporters/terminal.d.ts +2 -0
- package/dist/reporters/terminal.js +11 -0
- package/dist/rules/leftoverPatterns.d.ts +7 -0
- package/dist/rules/leftoverPatterns.js +10 -0
- package/dist/rules/refactorRules.d.ts +13 -0
- package/dist/rules/refactorRules.js +16 -0
- package/dist/rules/severityMap.d.ts +15 -0
- package/dist/rules/severityMap.js +33 -0
- package/package.json +72 -0
|
@@ -0,0 +1,219 @@
|
|
|
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.AGENT_TARGETS = void 0;
|
|
7
|
+
exports.loadAgentPackManifest = loadAgentPackManifest;
|
|
8
|
+
exports.parseAgentTargets = parseAgentTargets;
|
|
9
|
+
exports.generateCanonicalAgentPack = generateCanonicalAgentPack;
|
|
10
|
+
exports.syncAgentPack = syncAgentPack;
|
|
11
|
+
exports.initAgentPack = initAgentPack;
|
|
12
|
+
exports.packAgentPack = packAgentPack;
|
|
13
|
+
exports.doctorAgentPack = doctorAgentPack;
|
|
14
|
+
const node_fs_1 = require("node:fs");
|
|
15
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
16
|
+
const paths_1 = require("../core/paths");
|
|
17
|
+
const policy_1 = require("./policy");
|
|
18
|
+
const templates_1 = require("./templates");
|
|
19
|
+
exports.AGENT_TARGETS = ["codex", "copilot", "claude", "cursor"];
|
|
20
|
+
function toAbsolutePath(root, relativePath) {
|
|
21
|
+
return node_path_1.default.join(root, ...relativePath.split("/"));
|
|
22
|
+
}
|
|
23
|
+
function normalizeRelativePath(relativePath) {
|
|
24
|
+
return (0, paths_1.normalizeToPosix)(relativePath);
|
|
25
|
+
}
|
|
26
|
+
function uniqueTargets(targets) {
|
|
27
|
+
return Array.from(new Set(targets));
|
|
28
|
+
}
|
|
29
|
+
function mergeApplyResults(...results) {
|
|
30
|
+
return {
|
|
31
|
+
created: Array.from(new Set(results.flatMap((result) => result.created))),
|
|
32
|
+
updated: Array.from(new Set(results.flatMap((result) => result.updated))),
|
|
33
|
+
skipped: Array.from(new Set(results.flatMap((result) => result.skipped)))
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
async function writeManagedFile(root, relativePath, content, options = {}) {
|
|
37
|
+
const normalizedPath = normalizeRelativePath(relativePath);
|
|
38
|
+
const absolutePath = toAbsolutePath(root, normalizedPath);
|
|
39
|
+
const exists = await (0, paths_1.pathExists)(absolutePath);
|
|
40
|
+
if (exists && !options.force) {
|
|
41
|
+
return { created: [], updated: [], skipped: [normalizedPath] };
|
|
42
|
+
}
|
|
43
|
+
await (0, paths_1.ensureDir)(node_path_1.default.dirname(absolutePath));
|
|
44
|
+
await node_fs_1.promises.writeFile(absolutePath, content, "utf8");
|
|
45
|
+
return exists ? { created: [], updated: [normalizedPath], skipped: [] } : { created: [normalizedPath], updated: [], skipped: [] };
|
|
46
|
+
}
|
|
47
|
+
async function writeManagedFiles(root, files, options = {}) {
|
|
48
|
+
const results = await Promise.all(files.map((file) => writeManagedFile(root, file.path, file.content, options)));
|
|
49
|
+
return mergeApplyResults(...results);
|
|
50
|
+
}
|
|
51
|
+
async function listFilesRecursive(root, currentDir) {
|
|
52
|
+
const entries = await node_fs_1.promises.readdir(currentDir, { withFileTypes: true });
|
|
53
|
+
const files = [];
|
|
54
|
+
for (const entry of entries) {
|
|
55
|
+
const absolutePath = node_path_1.default.join(currentDir, entry.name);
|
|
56
|
+
if (entry.isDirectory()) {
|
|
57
|
+
files.push(...(await listFilesRecursive(root, absolutePath)));
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
files.push((0, paths_1.normalizeToPosix)(node_path_1.default.relative(root, absolutePath)));
|
|
61
|
+
}
|
|
62
|
+
return files;
|
|
63
|
+
}
|
|
64
|
+
async function copyCanonicalSkills(root, destinationRoot, options = {}) {
|
|
65
|
+
const results = [];
|
|
66
|
+
for (const skill of templates_1.AGENT_SKILLS) {
|
|
67
|
+
const sourceRoot = toAbsolutePath(root, `.agents/skills/${skill.name}`);
|
|
68
|
+
const files = await listFilesRecursive(sourceRoot, sourceRoot);
|
|
69
|
+
for (const file of files) {
|
|
70
|
+
const sourcePath = node_path_1.default.join(sourceRoot, ...file.split("/"));
|
|
71
|
+
const content = await node_fs_1.promises.readFile(sourcePath, "utf8");
|
|
72
|
+
results.push(await writeManagedFile(root, `${destinationRoot}/${skill.name}/${file}`, content, options));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return mergeApplyResults(...results);
|
|
76
|
+
}
|
|
77
|
+
function buildManifest(targets) {
|
|
78
|
+
return {
|
|
79
|
+
version: 1,
|
|
80
|
+
generatedBy: "vibedoctor",
|
|
81
|
+
generatedAt: new Date().toISOString(),
|
|
82
|
+
targets: uniqueTargets(targets),
|
|
83
|
+
skills: templates_1.DEFAULT_SKILL_NAMES,
|
|
84
|
+
files: {
|
|
85
|
+
agents: "AGENTS.md",
|
|
86
|
+
canonicalSkillDir: ".agents/skills",
|
|
87
|
+
policy: ".vibedoctor/agent-policy.yml",
|
|
88
|
+
manifest: ".vibedoctor/agent-pack.json",
|
|
89
|
+
shims: {
|
|
90
|
+
codex: ["AGENTS.md", ".agents/skills"],
|
|
91
|
+
copilot: [".github/skills", ".github/copilot-instructions.md"],
|
|
92
|
+
claude: [".claude/skills"],
|
|
93
|
+
cursor: [".cursor/rules/vibedoctor.mdc", ".cursor/mcp.json", ".mcp/vibedoctor.json"]
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function renderManifest(targets) {
|
|
99
|
+
return `${JSON.stringify(buildManifest(targets), null, 2)}\n`;
|
|
100
|
+
}
|
|
101
|
+
async function loadAgentPackManifest(root) {
|
|
102
|
+
const manifestPath = toAbsolutePath(root, ".vibedoctor/agent-pack.json");
|
|
103
|
+
if (!(await (0, paths_1.pathExists)(manifestPath))) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
const parsed = JSON.parse(await node_fs_1.promises.readFile(manifestPath, "utf8"));
|
|
107
|
+
const targets = Array.isArray(parsed.targets)
|
|
108
|
+
? parsed.targets.filter((target) => typeof target === "string" && exports.AGENT_TARGETS.includes(target))
|
|
109
|
+
: ["codex"];
|
|
110
|
+
return {
|
|
111
|
+
version: parsed.version ?? 1,
|
|
112
|
+
generatedBy: parsed.generatedBy ?? "vibedoctor",
|
|
113
|
+
generatedAt: parsed.generatedAt ?? "",
|
|
114
|
+
targets,
|
|
115
|
+
skills: Array.isArray(parsed.skills) ? parsed.skills.map((skill) => String(skill)) : templates_1.DEFAULT_SKILL_NAMES,
|
|
116
|
+
files: parsed.files ?? buildManifest(targets).files
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function parseAgentTargets(value, defaultTargets = ["codex"]) {
|
|
120
|
+
if (!value) {
|
|
121
|
+
return uniqueTargets(defaultTargets);
|
|
122
|
+
}
|
|
123
|
+
const parts = value
|
|
124
|
+
.split(",")
|
|
125
|
+
.map((item) => item.trim().toLowerCase())
|
|
126
|
+
.filter(Boolean);
|
|
127
|
+
if (parts.includes("all")) {
|
|
128
|
+
return [...exports.AGENT_TARGETS];
|
|
129
|
+
}
|
|
130
|
+
const invalid = parts.filter((target) => !exports.AGENT_TARGETS.includes(target));
|
|
131
|
+
if (invalid.length > 0) {
|
|
132
|
+
throw new Error(`Unsupported agent target(s): ${invalid.join(", ")}`);
|
|
133
|
+
}
|
|
134
|
+
return uniqueTargets(parts);
|
|
135
|
+
}
|
|
136
|
+
async function generateCanonicalAgentPack(root, options) {
|
|
137
|
+
const files = [
|
|
138
|
+
{ path: "AGENTS.md", content: (0, templates_1.renderAgentsMd)() },
|
|
139
|
+
{ path: ".vibedoctor/agent-policy.yml", content: (0, policy_1.renderAgentPolicy)(policy_1.defaultAgentPolicy) },
|
|
140
|
+
...templates_1.AGENT_SKILLS.flatMap((skill) => [
|
|
141
|
+
{
|
|
142
|
+
path: `.agents/skills/${skill.name}/SKILL.md`,
|
|
143
|
+
content: skill.content
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
path: `.agents/skills/${skill.name}/agents/openai.yaml`,
|
|
147
|
+
content: skill.openAiMetadata
|
|
148
|
+
}
|
|
149
|
+
])
|
|
150
|
+
];
|
|
151
|
+
return mergeApplyResults(await writeManagedFiles(root, files, { force: options.force }), await writeManagedFile(root, ".vibedoctor/agent-pack.json", renderManifest(options.targets), { force: true }));
|
|
152
|
+
}
|
|
153
|
+
async function syncAgentPack(root, options) {
|
|
154
|
+
const canonical = await generateCanonicalAgentPack(root, { targets: options.targets, force: options.force });
|
|
155
|
+
const results = [canonical];
|
|
156
|
+
if (options.targets.includes("claude")) {
|
|
157
|
+
results.push(await copyCanonicalSkills(root, ".claude/skills", { force: options.force }));
|
|
158
|
+
}
|
|
159
|
+
if (options.targets.includes("copilot")) {
|
|
160
|
+
results.push(await copyCanonicalSkills(root, ".github/skills", { force: options.force }));
|
|
161
|
+
results.push(await writeManagedFile(root, ".github/copilot-instructions.md", (0, templates_1.renderCopilotInstructions)(), {
|
|
162
|
+
force: options.force
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
if (options.targets.includes("cursor")) {
|
|
166
|
+
results.push(await writeManagedFiles(root, [
|
|
167
|
+
{ path: ".cursor/rules/vibedoctor.mdc", content: (0, templates_1.renderCursorRule)() },
|
|
168
|
+
{ path: ".cursor/mcp.json", content: (0, templates_1.renderCursorMcpConfig)() },
|
|
169
|
+
{ path: ".mcp/vibedoctor.json", content: (0, templates_1.renderGenericMcpConfig)() }
|
|
170
|
+
], { force: options.force }));
|
|
171
|
+
}
|
|
172
|
+
return mergeApplyResults(...results);
|
|
173
|
+
}
|
|
174
|
+
async function initAgentPack(root, options) {
|
|
175
|
+
const canonical = await generateCanonicalAgentPack(root, options);
|
|
176
|
+
const shimTargets = options.targets.filter((target) => target !== "codex");
|
|
177
|
+
if (shimTargets.length === 0) {
|
|
178
|
+
return canonical;
|
|
179
|
+
}
|
|
180
|
+
const shims = await syncAgentPack(root, options);
|
|
181
|
+
return mergeApplyResults(canonical, shims);
|
|
182
|
+
}
|
|
183
|
+
async function packAgentPack(root, options = {}) {
|
|
184
|
+
const manifest = await loadAgentPackManifest(root);
|
|
185
|
+
const targets = options.targets ?? manifest?.targets ?? ["codex"];
|
|
186
|
+
return generateCanonicalAgentPack(root, { targets, force: options.force });
|
|
187
|
+
}
|
|
188
|
+
async function doctorAgentPack(root, targets) {
|
|
189
|
+
const manifest = await loadAgentPackManifest(root);
|
|
190
|
+
const effectiveTargets = targets ?? manifest?.targets ?? ["codex"];
|
|
191
|
+
const items = [];
|
|
192
|
+
async function check(relativePath, okMessage, warnMessage = `${relativePath} missing`) {
|
|
193
|
+
const exists = await (0, paths_1.pathExists)(toAbsolutePath(root, relativePath));
|
|
194
|
+
items.push({
|
|
195
|
+
status: exists ? "ok" : "warn",
|
|
196
|
+
message: exists ? okMessage : warnMessage
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
await check("AGENTS.md", "AGENTS.md exists");
|
|
200
|
+
await check(".vibedoctor/agent-pack.json", ".vibedoctor/agent-pack.json exists");
|
|
201
|
+
await check(".vibedoctor/agent-policy.yml", ".vibedoctor/agent-policy.yml exists");
|
|
202
|
+
await check(".agents/skills/vibedoctor-health-scan/SKILL.md", ".agents/skills/vibedoctor-health-scan/SKILL.md exists", "Canonical agent skills missing");
|
|
203
|
+
if (effectiveTargets.includes("claude")) {
|
|
204
|
+
await check(".claude/skills/vibedoctor-health-scan/SKILL.md", "Claude skills installed", "Claude skills not installed");
|
|
205
|
+
}
|
|
206
|
+
if (effectiveTargets.includes("copilot")) {
|
|
207
|
+
await check(".github/copilot-instructions.md", "Copilot instructions exist", "Copilot instructions missing");
|
|
208
|
+
await check(".github/skills/vibedoctor-health-scan/SKILL.md", "Copilot skills installed", "Copilot skills not installed");
|
|
209
|
+
}
|
|
210
|
+
if (effectiveTargets.includes("cursor")) {
|
|
211
|
+
await check(".cursor/rules/vibedoctor.mdc", "Cursor rule exists", "Cursor rule missing");
|
|
212
|
+
await check(".cursor/mcp.json", "Cursor MCP config exists", "Cursor MCP config missing");
|
|
213
|
+
await check(".mcp/vibedoctor.json", "Generic MCP config exists", "Generic MCP config missing");
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
ok: items.every((item) => item.status === "ok"),
|
|
217
|
+
items
|
|
218
|
+
};
|
|
219
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type AgentPolicy = {
|
|
2
|
+
agentPolicy: {
|
|
3
|
+
allowSafeFix: boolean;
|
|
4
|
+
allowDeadCodeDelete: boolean;
|
|
5
|
+
allowDependencyUpgrade: boolean;
|
|
6
|
+
allowPublicApiChange: boolean;
|
|
7
|
+
requireTestsAfterEdit: boolean;
|
|
8
|
+
requireScanAfterEdit: boolean;
|
|
9
|
+
};
|
|
10
|
+
approvalRequired: string[];
|
|
11
|
+
};
|
|
12
|
+
export declare const defaultAgentPolicy: AgentPolicy;
|
|
13
|
+
export declare function renderAgentPolicy(policy?: AgentPolicy): string;
|
|
14
|
+
export declare function loadAgentPolicy(root: string): Promise<{
|
|
15
|
+
policy: AgentPolicy;
|
|
16
|
+
policyPath?: string;
|
|
17
|
+
}>;
|
|
18
|
+
export declare function getAllowedActions(policy: AgentPolicy): string[];
|
|
19
|
+
export declare function getForbiddenActions(policy: AgentPolicy): string[];
|
|
@@ -0,0 +1,117 @@
|
|
|
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.defaultAgentPolicy = void 0;
|
|
7
|
+
exports.renderAgentPolicy = renderAgentPolicy;
|
|
8
|
+
exports.loadAgentPolicy = loadAgentPolicy;
|
|
9
|
+
exports.getAllowedActions = getAllowedActions;
|
|
10
|
+
exports.getForbiddenActions = getForbiddenActions;
|
|
11
|
+
const node_fs_1 = require("node:fs");
|
|
12
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
13
|
+
const yaml_1 = __importDefault(require("yaml"));
|
|
14
|
+
const paths_1 = require("../core/paths");
|
|
15
|
+
exports.defaultAgentPolicy = {
|
|
16
|
+
agentPolicy: {
|
|
17
|
+
allowSafeFix: true,
|
|
18
|
+
allowDeadCodeDelete: false,
|
|
19
|
+
allowDependencyUpgrade: false,
|
|
20
|
+
allowPublicApiChange: false,
|
|
21
|
+
requireTestsAfterEdit: true,
|
|
22
|
+
requireScanAfterEdit: true
|
|
23
|
+
},
|
|
24
|
+
approvalRequired: [
|
|
25
|
+
"delete_file",
|
|
26
|
+
"remove_backward_compatibility",
|
|
27
|
+
"upgrade_dependency",
|
|
28
|
+
"refactor_security_sensitive_file",
|
|
29
|
+
"modify_ci_thresholds"
|
|
30
|
+
]
|
|
31
|
+
};
|
|
32
|
+
function isRecord(value) {
|
|
33
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34
|
+
}
|
|
35
|
+
function normalizePolicy(raw) {
|
|
36
|
+
if (!isRecord(raw)) {
|
|
37
|
+
return exports.defaultAgentPolicy;
|
|
38
|
+
}
|
|
39
|
+
const rawPolicy = raw.agentPolicy ?? raw.agent_policy;
|
|
40
|
+
const policy = isRecord(rawPolicy) ? rawPolicy : {};
|
|
41
|
+
const rawApproval = raw.approvalRequired ?? raw.approval_required;
|
|
42
|
+
return {
|
|
43
|
+
agentPolicy: {
|
|
44
|
+
allowSafeFix: policy.allowSafeFix ?? policy.allow_safe_fix ?? exports.defaultAgentPolicy.agentPolicy.allowSafeFix,
|
|
45
|
+
allowDeadCodeDelete: policy.allowDeadCodeDelete ??
|
|
46
|
+
policy.allow_dead_code_delete ??
|
|
47
|
+
exports.defaultAgentPolicy.agentPolicy.allowDeadCodeDelete,
|
|
48
|
+
allowDependencyUpgrade: policy.allowDependencyUpgrade ??
|
|
49
|
+
policy.allow_dependency_upgrade ??
|
|
50
|
+
exports.defaultAgentPolicy.agentPolicy.allowDependencyUpgrade,
|
|
51
|
+
allowPublicApiChange: policy.allowPublicApiChange ??
|
|
52
|
+
policy.allow_public_api_change ??
|
|
53
|
+
exports.defaultAgentPolicy.agentPolicy.allowPublicApiChange,
|
|
54
|
+
requireTestsAfterEdit: policy.requireTestsAfterEdit ??
|
|
55
|
+
policy.require_tests_after_edit ??
|
|
56
|
+
exports.defaultAgentPolicy.agentPolicy.requireTestsAfterEdit,
|
|
57
|
+
requireScanAfterEdit: policy.requireScanAfterEdit ??
|
|
58
|
+
policy.require_scan_after_edit ??
|
|
59
|
+
exports.defaultAgentPolicy.agentPolicy.requireScanAfterEdit
|
|
60
|
+
},
|
|
61
|
+
approvalRequired: Array.isArray(rawApproval)
|
|
62
|
+
? rawApproval.map((item) => String(item))
|
|
63
|
+
: exports.defaultAgentPolicy.approvalRequired
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function renderAgentPolicy(policy = exports.defaultAgentPolicy) {
|
|
67
|
+
return [
|
|
68
|
+
"agent_policy:",
|
|
69
|
+
` allow_safe_fix: ${policy.agentPolicy.allowSafeFix}`,
|
|
70
|
+
` allow_dead_code_delete: ${policy.agentPolicy.allowDeadCodeDelete}`,
|
|
71
|
+
` allow_dependency_upgrade: ${policy.agentPolicy.allowDependencyUpgrade}`,
|
|
72
|
+
` allow_public_api_change: ${policy.agentPolicy.allowPublicApiChange}`,
|
|
73
|
+
` require_tests_after_edit: ${policy.agentPolicy.requireTestsAfterEdit}`,
|
|
74
|
+
` require_scan_after_edit: ${policy.agentPolicy.requireScanAfterEdit}`,
|
|
75
|
+
"",
|
|
76
|
+
"approval_required:",
|
|
77
|
+
...policy.approvalRequired.map((item) => ` - ${item}`),
|
|
78
|
+
""
|
|
79
|
+
].join("\n");
|
|
80
|
+
}
|
|
81
|
+
async function loadAgentPolicy(root) {
|
|
82
|
+
const policyPath = node_path_1.default.join(root, ".vibedoctor", "agent-policy.yml");
|
|
83
|
+
if (!(await (0, paths_1.pathExists)(policyPath))) {
|
|
84
|
+
return { policy: exports.defaultAgentPolicy };
|
|
85
|
+
}
|
|
86
|
+
const content = await node_fs_1.promises.readFile(policyPath, "utf8");
|
|
87
|
+
return { policy: normalizePolicy(yaml_1.default.parse(content)), policyPath };
|
|
88
|
+
}
|
|
89
|
+
function getAllowedActions(policy) {
|
|
90
|
+
const actions = ["edit source files", "add tests"];
|
|
91
|
+
if (policy.agentPolicy.allowSafeFix) {
|
|
92
|
+
actions.push("run safe fixes");
|
|
93
|
+
}
|
|
94
|
+
if (policy.agentPolicy.allowDeadCodeDelete) {
|
|
95
|
+
actions.push("delete verified high-confidence dead code");
|
|
96
|
+
}
|
|
97
|
+
if (policy.agentPolicy.allowDependencyUpgrade) {
|
|
98
|
+
actions.push("upgrade dependencies with approval");
|
|
99
|
+
}
|
|
100
|
+
if (policy.agentPolicy.allowPublicApiChange) {
|
|
101
|
+
actions.push("change public APIs with approval");
|
|
102
|
+
}
|
|
103
|
+
return actions;
|
|
104
|
+
}
|
|
105
|
+
function getForbiddenActions(policy) {
|
|
106
|
+
const actions = ["disable tests", "lower thresholds"];
|
|
107
|
+
if (!policy.agentPolicy.allowDeadCodeDelete) {
|
|
108
|
+
actions.push("delete low-confidence dead code");
|
|
109
|
+
}
|
|
110
|
+
if (!policy.agentPolicy.allowDependencyUpgrade) {
|
|
111
|
+
actions.push("upgrade dependencies");
|
|
112
|
+
}
|
|
113
|
+
if (!policy.agentPolicy.allowPublicApiChange) {
|
|
114
|
+
actions.push("change public APIs without approval");
|
|
115
|
+
}
|
|
116
|
+
return actions;
|
|
117
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { AGENT_SKILLS, type SkillTemplate } from "./skills";
|
|
2
|
+
export declare function renderAgentsMd(): string;
|
|
3
|
+
export declare function renderCursorRule(): string;
|
|
4
|
+
export declare function renderCopilotInstructions(): string;
|
|
5
|
+
export declare function renderCursorMcpConfig(): string;
|
|
6
|
+
export declare function renderGenericMcpConfig(): string;
|
|
7
|
+
export declare const DEFAULT_SKILL_NAMES: string[];
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_SKILL_NAMES = exports.AGENT_SKILLS = void 0;
|
|
4
|
+
exports.renderAgentsMd = renderAgentsMd;
|
|
5
|
+
exports.renderCursorRule = renderCursorRule;
|
|
6
|
+
exports.renderCopilotInstructions = renderCopilotInstructions;
|
|
7
|
+
exports.renderCursorMcpConfig = renderCursorMcpConfig;
|
|
8
|
+
exports.renderGenericMcpConfig = renderGenericMcpConfig;
|
|
9
|
+
const skills_1 = require("./skills");
|
|
10
|
+
var skills_2 = require("./skills");
|
|
11
|
+
Object.defineProperty(exports, "AGENT_SKILLS", { enumerable: true, get: function () { return skills_2.AGENT_SKILLS; } });
|
|
12
|
+
function renderAgentsMd() {
|
|
13
|
+
return `# AGENTS.md
|
|
14
|
+
|
|
15
|
+
## VibeDoctor workflow
|
|
16
|
+
|
|
17
|
+
Use VibeDoctor as the source of truth for code-health checks.
|
|
18
|
+
|
|
19
|
+
Before major edits:
|
|
20
|
+
\`\`\`bash
|
|
21
|
+
vibedoctor scan --changed --report json
|
|
22
|
+
\`\`\`
|
|
23
|
+
|
|
24
|
+
After edits:
|
|
25
|
+
\`\`\`bash
|
|
26
|
+
vibedoctor scan --changed --report json
|
|
27
|
+
\`\`\`
|
|
28
|
+
|
|
29
|
+
Before PR or merge:
|
|
30
|
+
\`\`\`bash
|
|
31
|
+
vibedoctor scan --full --report json
|
|
32
|
+
\`\`\`
|
|
33
|
+
|
|
34
|
+
## Fix order
|
|
35
|
+
|
|
36
|
+
Always fix in this order:
|
|
37
|
+
|
|
38
|
+
1. security blockers
|
|
39
|
+
2. failing tests
|
|
40
|
+
3. type errors
|
|
41
|
+
4. dependency vulnerabilities
|
|
42
|
+
5. high-confidence dead code
|
|
43
|
+
6. leftovers and legacy baggage
|
|
44
|
+
7. refactor-readiness items
|
|
45
|
+
8. efficiency suggestions
|
|
46
|
+
|
|
47
|
+
## Safety rules
|
|
48
|
+
|
|
49
|
+
- Do not delete dead code unless VibeDoctor marks it high confidence and you independently verify no active references.
|
|
50
|
+
- Do not remove backward compatibility code unless the user explicitly approves or the path is proven unused.
|
|
51
|
+
- Do not refactor large files without tests.
|
|
52
|
+
- Do not change public APIs during cleanup unless the task explicitly asks.
|
|
53
|
+
- Do not lower test, lint, security, or coverage thresholds.
|
|
54
|
+
- Do not silence VibeDoctor findings without explaining why.
|
|
55
|
+
- Respect .vibedoctor/agent-policy.yml when it exists.
|
|
56
|
+
|
|
57
|
+
## Verification
|
|
58
|
+
|
|
59
|
+
After each meaningful change, run the smallest relevant verification command.
|
|
60
|
+
|
|
61
|
+
At the end, report:
|
|
62
|
+
|
|
63
|
+
\`\`\`text
|
|
64
|
+
Health score:
|
|
65
|
+
Commands run:
|
|
66
|
+
Files changed:
|
|
67
|
+
Remaining blockers:
|
|
68
|
+
Suggested next step:
|
|
69
|
+
\`\`\`
|
|
70
|
+
`;
|
|
71
|
+
}
|
|
72
|
+
function renderCursorRule() {
|
|
73
|
+
return `---
|
|
74
|
+
description: Use VibeDoctor for code health, safe fixes, dead code, leftovers, refactor-readiness, and PR verification.
|
|
75
|
+
alwaysApply: true
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
When making code changes, use VibeDoctor as the code-health verification layer.
|
|
79
|
+
|
|
80
|
+
Prefer:
|
|
81
|
+
- \`vibedoctor scan --changed --report json\` before and after edits
|
|
82
|
+
- \`vibedoctor fix --safe\` for safe cleanup
|
|
83
|
+
- \`vibedoctor agent-plan --format markdown\` when planning multiple fixes
|
|
84
|
+
|
|
85
|
+
Do not delete dead code, remove compatibility paths, or refactor large files unless VibeDoctor evidence and tests support it.
|
|
86
|
+
`;
|
|
87
|
+
}
|
|
88
|
+
function renderCopilotInstructions() {
|
|
89
|
+
return `Use VibeDoctor for repository health checks.
|
|
90
|
+
|
|
91
|
+
Before editing generated or AI-written code, run:
|
|
92
|
+
|
|
93
|
+
\`\`\`bash
|
|
94
|
+
vibedoctor scan --changed --report json
|
|
95
|
+
\`\`\`
|
|
96
|
+
|
|
97
|
+
After changes, run:
|
|
98
|
+
|
|
99
|
+
\`\`\`bash
|
|
100
|
+
vibedoctor scan --changed --report json
|
|
101
|
+
\`\`\`
|
|
102
|
+
|
|
103
|
+
For pull requests, summarize:
|
|
104
|
+
- health score
|
|
105
|
+
- blockers
|
|
106
|
+
- changed files checked
|
|
107
|
+
- tests run
|
|
108
|
+
- remaining VibeDoctor findings
|
|
109
|
+
|
|
110
|
+
Do not remove dead code, legacy fallbacks, compatibility shims, or large blocks of comments unless VibeDoctor marks them as high-confidence cleanup candidates and references are verified.
|
|
111
|
+
`;
|
|
112
|
+
}
|
|
113
|
+
function renderCursorMcpConfig() {
|
|
114
|
+
return `${JSON.stringify({
|
|
115
|
+
mcpServers: {
|
|
116
|
+
vibedoctor: {
|
|
117
|
+
type: "stdio",
|
|
118
|
+
command: "vibedoctor",
|
|
119
|
+
args: ["mcp"]
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}, null, 2)}\n`;
|
|
123
|
+
}
|
|
124
|
+
function renderGenericMcpConfig() {
|
|
125
|
+
return `${JSON.stringify({
|
|
126
|
+
mcpServers: {
|
|
127
|
+
vibedoctor: {
|
|
128
|
+
command: "vibedoctor",
|
|
129
|
+
args: ["mcp"]
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}, null, 2)}\n`;
|
|
133
|
+
}
|
|
134
|
+
exports.DEFAULT_SKILL_NAMES = skills_1.AGENT_SKILLS.map((skill) => skill.name);
|