@remylagerweij/vue-doctor 2.1.1 → 2.2.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 (38) hide show
  1. package/README.md +5 -3
  2. package/dist/agent-hook-run-C6TGHuls.js +141 -0
  3. package/dist/{baseline-D4b_oHcn.js → baseline-S73VL2i1.js} +1 -1
  4. package/dist/{baseline-ByBx3bYL.js → baseline-ekG8ZnQz.js} +1 -1
  5. package/dist/changed-lines-B1gWj36s.js +109 -0
  6. package/dist/cli.js +502 -83
  7. package/dist/constants-Il8yYQQ1.js +14 -0
  8. package/dist/{diagnose-CGX29sNK.js → diagnose-BWzFVcW1.js} +138 -95
  9. package/dist/diagnose-BmcWVOdC.js +2 -0
  10. package/dist/{discover-project-DNVbj-s4.js → discover-project-BhWONopi.js} +1 -1
  11. package/dist/{discover-project-DMMPWHNA.js → discover-project-CxUVNRN2.js} +2 -13
  12. package/dist/gate-DPygx02J.js +58 -0
  13. package/dist/get-diff-files-BmOTftg1.js +187 -0
  14. package/dist/index.d.ts +29 -0
  15. package/dist/index.js +84 -16
  16. package/dist/logger-lb8ODdY1.js +81 -0
  17. package/dist/{model-eTvTct_Z.js → model-D_iIG_Kz.js} +10 -1
  18. package/dist/prompts-B6KyXw4n.js +2 -0
  19. package/dist/prompts-CeGonHoj.js +33 -0
  20. package/dist/{rule-ids-5pSuv8lc.js → rule-ids-BloekNcu.js} +150 -173
  21. package/dist/{rule-options-DKLnjGap.js → rule-options-DuZJJ_Sn.js} +150 -173
  22. package/dist/{rule-options-Ds-ve1sd.js → rule-options-DxpXX5-D.js} +1 -1
  23. package/dist/rules-DcjyLWUi.js +118 -0
  24. package/dist/runner-4Wnz5goR.js +596 -0
  25. package/dist/{schema-Khrhwl9M.js → schema-BMBp1hXu.js} +2 -1
  26. package/dist/{schema-DHV0VPmo.js → schema-C4ucbXIS.js} +2 -1
  27. package/dist/{server-HMZ4QLjd.js → server-Bhj9foBP.js} +18 -6
  28. package/dist/{validate-rule-options-DHqjaoYW.js → validate-rule-options-Du_YeG6D.js} +1 -1
  29. package/dist/{validate-rule-options-0hIH4ndj.js → validate-rule-options-r01B-gA_.js} +1 -1
  30. package/dist/vue-doctor-plugin.d.ts +12 -0
  31. package/dist/vue-doctor-plugin.js +179 -174
  32. package/package.json +5 -5
  33. package/schema/report.schema.json +49 -0
  34. package/schema/vue-doctor.schema.json +4 -0
  35. package/dist/diagnose-BQSITykQ.js +0 -2
  36. package/dist/list-source-files-D68XBABM.js +0 -65
  37. package/dist/rules-ByJZ3lPi.js +0 -318
  38. package/dist/runner-D4J2cNvQ.js +0 -178
package/README.md CHANGED
@@ -68,7 +68,7 @@ Then add a script to your `package.json`:
68
68
  - 🛡️ **Comprehensive Quality Gates:** 85 custom rules (85 on by default) + 19 eslint-plugin-vue rules = 104 registered rules.
69
69
  - 🔒 **Deep Security Guardrails:** Detects hardcoded secrets, unsafe HTML sinks (`v-html`), SSRF, command & SQL injection, prototype pollution, and LLM prompt injection risks.
70
70
  - 🧹 **Dead Code & Unused Exports:** Finds unused components, unreferenced exports, orphan types, and dead dependencies using Knip.
71
- - 🔧 **Automated Codemods:** Deterministic `--fix` automatically repairs lodash imports, in-place array mutation, missing `v-for` keys, and `rel="noopener noreferrer"`.
71
+ - 🔧 **Automated Codemods:** Deterministic `--fix` repairs the scan's findings of the two fixable rules: named lodash imports become per-method imports, and `target="_blank"` links get `rel="noopener noreferrer"`. Only reported findings are rewritten; suppressed, disabled and unreported code is never touched.
72
72
  - 🤖 **First-Class AI Agent Support:** Built-in stdio Model Context Protocol (MCP) server (`vue-doctor mcp`) and one-command agent playbook installer (`vue-doctor agents install`) for Cursor, Claude Code, Copilot, and Windsurf.
73
73
  - 🚦 **GitHub Actions CI & PR Feedback:** Full pull request feedback with sticky summary comments, line-level reviews with AI remediation prompts, check annotations, and score delta tracking.
74
74
  - 📈 **Baseline for Existing Codebases:** Adopt Vue Doctor on legacy applications instantly; record existing issues and only fail on new violations.
@@ -123,10 +123,10 @@ vue-doctor
123
123
  # Scan a specific directory or workspace project
124
124
  vue-doctor ./apps/web
125
125
 
126
- # Automatically apply deterministic codemods
126
+ # Fix the reported findings of fixable rules, then scan the fixed code
127
127
  vue-doctor --fix
128
128
 
129
- # Preview codemods without changing files (unified diff)
129
+ # Preview the fixes without changing files (unified diff)
130
130
  vue-doctor --fix --dry-run
131
131
 
132
132
  # Scan only files changed in your git branch (fast pre-commit / PR mode)
@@ -331,6 +331,8 @@ console.log(`Total Findings: ${result.diagnostics.length}`);
331
331
  - **[Official Documentation](https://remylagerweij.github.io/vue-doctor/)**
332
332
  - **[Full Rules Catalog](https://remylagerweij.github.io/vue-doctor/rules/)**
333
333
  - **[CI & GitHub PR Guide](https://remylagerweij.github.io/vue-doctor/guide/ci)**
334
+ - **[Editor Integration (Oxlint / ESLint plugin)](https://remylagerweij.github.io/vue-doctor/guide/editor)**
335
+ - **[Pre-commit Hooks](https://remylagerweij.github.io/vue-doctor/guide/pre-commit)**
334
336
  - **[AI Agents Playbook](https://remylagerweij.github.io/vue-doctor/guide/agents)**
335
337
  - **[Model Context Protocol (MCP) Guide](https://remylagerweij.github.io/vue-doctor/guide/mcp)**
336
338
  - **[CLI Reference](https://remylagerweij.github.io/vue-doctor/reference/cli)**
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from "node:child_process";
3
+ import crypto from "node:crypto";
4
+ import fs from "node:fs";
5
+ import os from "node:os";
6
+ import path from "node:path";
7
+ import { r as getDiffInfo, t as filterSourceFiles } from "./get-diff-files-BmOTftg1.js";
8
+ // src/commands/agent-hook-run.ts
9
+ /**
10
+ * Runtime of the end-of-turn hooks (`vue-doctor agents hook <claude|cursor>`), which the agent
11
+ * runs when it is about to finish a turn. Contract:
12
+ * - Fast: only the files changed since HEAD are scanned, without dead-code analysis or network,
13
+ * and the scan is killed after SCAN_TIMEOUT_MS. No changed source files means no scan at all.
14
+ * - Fail open: any problem (no git, scan failure, bad input, timeout) prints nothing and exits 0,
15
+ * so the hook can never trap the agent.
16
+ * - Cannot loop: the agent's own loop flag (`stop_hook_active` for Claude Code, `loop_count` for
17
+ * Cursor) makes the hook stay silent, and the same set of findings is reported at most once
18
+ * per session, so an agent that stops again without fixing is not nagged.
19
+ */
20
+ const SCAN_TIMEOUT_MS = 45e3;
21
+ const MAX_STDIN_BYTES = 1048576;
22
+ const SCAN_MAX_BUFFER_BYTES = 67108864;
23
+ /** What the hook prints to stdout (the agent reads it); `null` means print nothing. */
24
+ const runAgentHook = (options) => {
25
+ try {
26
+ const { agent, input } = options;
27
+ if ((options.env ?? process.env)["VUE_DOCTOR_AGENT_HOOK"] === "off") return null;
28
+ if (agent === "claude" && input.stop_hook_active === true) return null;
29
+ if (agent === "cursor" && ((input.loop_count ?? 0) >= 1 || input.status !== void 0 && input.status !== "completed")) return null;
30
+ const directory = agent === "cursor" ? path.resolve(input.workspace_roots?.[0] ?? input.cwd ?? options.cwd) : resolveClaudeDirectory(input.cwd ?? options.cwd, options.env ?? process.env);
31
+ const diff = getDiffInfo(directory, "HEAD");
32
+ if (diff.status !== "ok" || filterSourceFiles(diff.changedFiles).length === 0) return null;
33
+ const reportText = (options.runScan ?? runScanProcess)(directory);
34
+ if (!reportText) return null;
35
+ const findings = parseFindings(reportText);
36
+ if (findings.length === 0) return null;
37
+ const sessionId = input.session_id ?? input.conversation_id ?? "default";
38
+ if (!recordIfNew(options.stateDirectory ?? os.tmpdir(), directory, sessionId, findings)) return null;
39
+ const message = formatMessage(findings);
40
+ return agent === "claude" ? JSON.stringify({
41
+ decision: "block",
42
+ reason: message
43
+ }) : JSON.stringify({ followup_message: message });
44
+ } catch {
45
+ return null;
46
+ }
47
+ };
48
+ /**
49
+ * Claude Code's `cwd` follows the agent's `cd`s, so it can sit in a subfolder with no package.json.
50
+ * Prefer the project directory Claude Code exports for hooks; otherwise walk up to the nearest
51
+ * package.json.
52
+ */
53
+ const resolveClaudeDirectory = (cwd, env) => {
54
+ const projectDir = env.CLAUDE_PROJECT_DIR;
55
+ if (projectDir && fs.existsSync(projectDir)) return path.resolve(projectDir);
56
+ let current = path.resolve(cwd);
57
+ for (;;) {
58
+ if (fs.existsSync(path.join(current, "package.json"))) return current;
59
+ const parent = path.dirname(current);
60
+ if (parent === current) return path.resolve(cwd);
61
+ current = parent;
62
+ }
63
+ };
64
+ /** Runs this same CLI on the changed files. Returns the JSON report, or null on timeout or failure. */
65
+ const runScanProcess = (directory) => {
66
+ const entry = process.argv[1];
67
+ if (!entry) return null;
68
+ const result = spawnSync(process.execPath, [
69
+ entry,
70
+ directory,
71
+ "--diff",
72
+ "HEAD",
73
+ "--format",
74
+ "json",
75
+ "--no-timestamp",
76
+ "--no-dead-code",
77
+ "--offline",
78
+ "--no-color",
79
+ "--quiet",
80
+ "--yes"
81
+ ], {
82
+ encoding: "utf8",
83
+ stdio: [
84
+ "ignore",
85
+ "pipe",
86
+ "ignore"
87
+ ],
88
+ timeout: SCAN_TIMEOUT_MS,
89
+ maxBuffer: SCAN_MAX_BUFFER_BYTES
90
+ });
91
+ if (result.error || typeof result.stdout !== "string" || result.stdout.length === 0) return null;
92
+ return result.stdout;
93
+ };
94
+ const parseFindings = (reportText) => {
95
+ const all = (JSON.parse(reportText).projects ?? []).flatMap((project) => project.findings ?? []);
96
+ return [...all.filter((finding) => finding.severity === "error"), ...all.filter((finding) => finding.severity !== "error")];
97
+ };
98
+ const findingKey = (finding) => finding.fingerprint ?? `${finding.ruleId}:${finding.file}:${finding.line}`;
99
+ /** Returns true (and remembers the set) when this session has not been told about exactly these findings yet. */
100
+ const recordIfNew = (stateDirectory, directory, sessionId, findings) => {
101
+ const digest = (value) => crypto.createHash("sha256").update(value).digest("hex");
102
+ const stateFile = path.join(stateDirectory, `vue-doctor-agent-hook-${digest(`${directory}\0${sessionId}`).slice(0, 16)}.json`);
103
+ const current = digest(findings.map(findingKey).sort().join("\n"));
104
+ try {
105
+ if (JSON.parse(fs.readFileSync(stateFile, "utf8")).reported === current) return false;
106
+ } catch {}
107
+ try {
108
+ fs.writeFileSync(stateFile, JSON.stringify({ reported: current }), {
109
+ encoding: "utf8",
110
+ mode: 384
111
+ });
112
+ } catch {}
113
+ return true;
114
+ };
115
+ const formatMessage = (findings) => {
116
+ const shown = findings.slice(0, 10);
117
+ const lines = shown.map((finding) => {
118
+ return `- ${finding.line > 0 ? `${finding.file}:${finding.line}` : finding.file} [${finding.severity}] ${finding.ruleId}: ${finding.message}`;
119
+ });
120
+ const more = findings.length > shown.length ? `\n...and ${findings.length - shown.length} more.` : "";
121
+ return [`Vue Doctor found ${findings.length} issue${findings.length === 1 ? "" : "s"} in your uncommitted files (changes since HEAD):`, ...lines].join("\n") + `${more}\nFix the errors first (\`npx @remylagerweij/vue-doctor explain <ruleId>\` shows remediation guidance, \`--fix\` applies safe codemods). If a finding is intentional, say so briefly and finish. This check reports a given set of findings only once.`;
122
+ };
123
+ /** Reads the hook payload from stdin (bounded) and parses it as JSON; resolves to `{}` when stdin is a terminal, too large, not a JSON object, or unreadable. */
124
+ const readHookInput = async (stream = process.stdin) => {
125
+ if (stream.isTTY) return {};
126
+ const chunks = [];
127
+ let size = 0;
128
+ try {
129
+ for await (const chunk of stream) {
130
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
131
+ size += buffer.length;
132
+ if (size > MAX_STDIN_BYTES) return {};
133
+ chunks.push(buffer);
134
+ }
135
+ const parsed = JSON.parse(Buffer.concat(chunks).toString("utf8"));
136
+ return typeof parsed === "object" && parsed !== null ? parsed : {};
137
+ } catch {
138
+ return {};
139
+ }
140
+ };
141
+ export { readHookInput, runAgentHook };
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- export { i as createBaseline, o as writeBaseline } from "./baseline-ByBx3bYL.js";
2
+ export { i as createBaseline, o as writeBaseline } from "./baseline-ekG8ZnQz.js";
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from "node:fs";
3
- import { r as ruleIdOf } from "./rule-ids-5pSuv8lc.js";
3
+ import { r as ruleIdOf } from "./rule-ids-BloekNcu.js";
4
4
  // src/core/baseline.ts
5
5
  const DEFAULT_BASELINE_FILENAME = ".vue-doctor-baseline.json";
6
6
  const BASELINE_VERSION = 1;
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env node
2
+ // src/utils/changed-lines.ts
3
+ const HUNK_HEADER = /^@@ -\d+(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
4
+ const C_ESCAPES = {
5
+ a: 7,
6
+ b: 8,
7
+ t: 9,
8
+ n: 10,
9
+ v: 11,
10
+ f: 12,
11
+ r: 13,
12
+ "\"": 34,
13
+ "\\": 92
14
+ };
15
+ /** Undoes git's C-style quoting of a path (`"a\tb\303\251"`), decoding octal escapes as UTF-8. */
16
+ const unquoteGitPath = (quoted) => {
17
+ if (!quoted.startsWith("\"") || !quoted.endsWith("\"") || quoted.length < 2) return quoted;
18
+ const body = quoted.slice(1, -1);
19
+ const bytes = [];
20
+ for (let index = 0; index < body.length; index++) {
21
+ if (body[index] !== "\\") {
22
+ const character = String.fromCodePoint(body.codePointAt(index) ?? 0);
23
+ bytes.push(...Buffer.from(character, "utf-8"));
24
+ index += character.length - 1;
25
+ continue;
26
+ }
27
+ const next = body[index + 1] ?? "";
28
+ const octal = /^[0-7]{3}/.exec(body.slice(index + 1));
29
+ if (octal) {
30
+ bytes.push(Number.parseInt(octal[0], 8));
31
+ index += 3;
32
+ } else if (next in C_ESCAPES) {
33
+ bytes.push(C_ESCAPES[next]);
34
+ index += 1;
35
+ } else bytes.push(92);
36
+ }
37
+ return Buffer.from(bytes).toString("utf-8");
38
+ };
39
+ /** Path of a `+++ ` header line, without the `b/` prefix; `null` for a deleted file (`/dev/null`). */
40
+ const parseNewPath = (header) => {
41
+ let raw = header.slice(4);
42
+ if (!raw.startsWith("\"") && raw.endsWith(" ")) raw = raw.slice(0, -1);
43
+ if (raw === "/dev/null") return null;
44
+ const unquoted = unquoteGitPath(raw);
45
+ return unquoted.startsWith("b/") ? unquoted.slice(2) : unquoted;
46
+ };
47
+ /**
48
+ * Parses `git diff --unified=0 --src-prefix=a/ --dst-prefix=b/` output into the changed lines on
49
+ * the new side. Hunk bodies are skipped by their line counts, so content that looks like a header
50
+ * (an added line `++ x` shows as `+++ x`) is never taken for one. Deleted files, binary files and
51
+ * pure deletions contribute nothing; new files are `"all"`.
52
+ */
53
+ const parseUnifiedDiff = (diffOutput) => {
54
+ const changed = {};
55
+ let currentPath = null;
56
+ let isNewFile = false;
57
+ let remainingOld = 0;
58
+ let remainingNew = 0;
59
+ for (const line of diffOutput.split("\n")) {
60
+ if (remainingOld > 0 || remainingNew > 0) {
61
+ const marker = line[0];
62
+ if (marker === "\\") continue;
63
+ if (marker === "-" && remainingOld > 0) {
64
+ remainingOld--;
65
+ continue;
66
+ }
67
+ if (marker === "+" && remainingNew > 0) {
68
+ remainingNew--;
69
+ continue;
70
+ }
71
+ if (marker === " " && remainingOld > 0 && remainingNew > 0) {
72
+ remainingOld--;
73
+ remainingNew--;
74
+ continue;
75
+ }
76
+ remainingOld = 0;
77
+ remainingNew = 0;
78
+ }
79
+ if (line.startsWith("diff --git ")) {
80
+ currentPath = null;
81
+ isNewFile = false;
82
+ } else if (line.startsWith("new file mode ")) isNewFile = true;
83
+ else if (line.startsWith("+++ ")) {
84
+ currentPath = parseNewPath(line);
85
+ if (currentPath !== null) changed[currentPath] = isNewFile ? "all" : changed[currentPath] ?? [];
86
+ } else if (line.startsWith("@@ ")) {
87
+ const match = HUNK_HEADER.exec(line);
88
+ if (!match) continue;
89
+ remainingOld = match[1] === void 0 ? 1 : Number(match[1]);
90
+ const start = Number(match[2]);
91
+ const count = match[3] === void 0 ? 1 : Number(match[3]);
92
+ remainingNew = count;
93
+ const ranges = currentPath === null ? void 0 : changed[currentPath];
94
+ if (count > 0 && Array.isArray(ranges)) ranges.push({
95
+ start,
96
+ end: start + count - 1
97
+ });
98
+ }
99
+ }
100
+ return changed;
101
+ };
102
+ /** Whether `line` of `filePath` is a changed line; files that are not keys have none. */
103
+ const isChangedLine = (changedLines, filePath, line) => {
104
+ const ranges = changedLines[filePath];
105
+ if (ranges === void 0) return false;
106
+ if (ranges === "all") return true;
107
+ return ranges.some((range) => line >= range.start && line <= range.end);
108
+ };
109
+ export { parseUnifiedDiff as n, isChangedLine as t };