@virling/ccdoctor 0.0.0-stage → 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/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses [Semantic Versioning](https://semver.org/).
4
+
5
+ ## [Unreleased]
6
+
7
+ ## [0.1.0] - 2026-11-27
8
+
9
+ ### Added
10
+
11
+ - `ccdoctor` checks Claude Code settings files, hook commands and their scripts, MCP servers in every scope, and enabled plugins.
12
+ - `--probe` starts each stdio MCP server and lists its tools.
13
+ - Warns when an MCP server is registered but the hooks it ships are missing.
14
+ - `--json` output; exit code 1 when any check fails.
15
+
16
+ [Unreleased]: https://github.com/virling/ccdoctor/compare/v0.1.0...HEAD
17
+ [0.1.0]: https://github.com/virling/ccdoctor/releases/tag/v0.1.0
package/LICENSE ADDED
@@ -0,0 +1,75 @@
1
+ # PolyForm Noncommercial License 1.0.0
2
+
3
+ <https://polyformproject.org/licenses/noncommercial/1.0.0>
4
+
5
+ ## Acceptance
6
+
7
+ In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
8
+
9
+ ## Copyright License
10
+
11
+ The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
12
+
13
+ ## Distribution License
14
+
15
+ The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
16
+
17
+ ## Notices
18
+
19
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
20
+
21
+ > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
22
+
23
+ ## Changes and New Works License
24
+
25
+ The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
26
+
27
+ ## Patent License
28
+
29
+ The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
30
+
31
+ ## Noncommercial Purposes
32
+
33
+ Any noncommercial purpose is a permitted purpose.
34
+
35
+ ## Personal Uses
36
+
37
+ Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, is use for a permitted purpose.
38
+
39
+ ## Noncommercial Organizations
40
+
41
+ Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is use for a permitted purpose regardless of the source of funding or obligations resulting from the funding.
42
+
43
+ ## Fair Use
44
+
45
+ You may have "fair use" rights for the software under the law. These terms do not limit them.
46
+
47
+ ## No Other Rights
48
+
49
+ These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
50
+
51
+ ## Patent Defense
52
+
53
+ If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
54
+
55
+ ## Violations
56
+
57
+ The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
58
+
59
+ ## No Liability
60
+
61
+ ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
62
+
63
+ ## Definitions
64
+
65
+ The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
66
+
67
+ **You** refers to the individual or entity agreeing to these terms.
68
+
69
+ **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
70
+
71
+ **Your licenses** are all the licenses granted to you for the software under these terms.
72
+
73
+ **Use** means anything you do with the software requiring one of your licenses.
74
+
75
+ Required Notice: Copyright 2026 Virling (https://github.com/virling)
package/README.md CHANGED
@@ -1,3 +1,68 @@
1
- # Temporary Holding Version
1
+ # ccdoctor
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Checks your Claude Code setup and reports what is broken or registered but not wired up. One command, read-only, zero dependencies.
4
+
5
+ Typical catch: an MCP server is registered but the hooks that make it useful are missing from `settings.json`, so it silently does nothing.
6
+
7
+ ## Requirements
8
+
9
+ - Node.js 20 or newer
10
+
11
+ ## Install
12
+
13
+ Run it from the project folder you open Claude Code in:
14
+
15
+ ```bash
16
+ npx @virling/ccdoctor
17
+ ```
18
+
19
+ ## Example
20
+
21
+ ```
22
+ $ npx @virling/ccdoctor
23
+ Settings
24
+ ok ~/.claude/settings.json
25
+
26
+ Hooks
27
+ ok PreToolUse [user] ~/.claude/hooks/block-unsigned-push.sh
28
+ fail SessionStart [user] node ~/tools/old.js hook: script not found: ~/tools/old.js
29
+
30
+ MCP servers
31
+ ok agentmem (user): ~/projects/memory/bin/agentmem.js
32
+ info linear (local, http): remote, not checked
33
+
34
+ Plugins
35
+ ok swift-lsp@claude-plugins-official
36
+
37
+ Wiring
38
+ warn agentmem: MCP server registered but its hooks are missing
39
+
40
+ 3 ok, 1 warn, 1 fail
41
+ ```
42
+
43
+ Exit code is 1 when any check fails.
44
+
45
+ ## Checks
46
+
47
+ - **Settings.** `~/.claude/settings.json` (or `$CLAUDE_CONFIG_DIR/settings.json`), and `.claude/settings.json` and `.claude/settings.local.json` in the current folder. Invalid JSON fails.
48
+ - **Hooks.** Every `command` hook in those files. The executable must exist on `PATH` or as a file (`~` and `$CLAUDE_PROJECT_DIR` are expanded). For `node`, `bash`, `python3` and similar, the script path must exist too. A script run directly without the executable bit warns. Only the first command of a shell line is checked.
49
+ - **MCP servers.** User scope (`mcpServers` in `~/.claude.json`), local scope (`projects[<this folder>].mcpServers` in `~/.claude.json`) and project scope (`.mcp.json`). For stdio servers the command must resolve. A name defined in more than one scope warns. `env` values, headers and URLs are never printed.
50
+ - **Plugins.** Each plugin set to `true` in `enabledPlugins` must have a folder under `~/.claude/plugins/cache/<marketplace>/<plugin>/`. Missing ones warn.
51
+ - **Wiring.** A stdio MCP server named `agentmem`, or whose package ships `hooks/hooks.json`, warns when no hook command (in settings or enabled plugins) mentions its name or package folder.
52
+ - **Probe** (`--probe`). Starts each stdio server, sends `initialize`, `notifications/initialized` and `tools/list`, reports the tool count or the error, then kills it. http and sse servers are not probed.
53
+
54
+ ## Options
55
+
56
+ ```
57
+ ccdoctor check settings, hooks, MCP servers and plugins
58
+ ccdoctor --probe also start each stdio MCP server and list its tools
59
+ ccdoctor --timeout <s> probe timeout in seconds (default 10)
60
+ ccdoctor --json print results as JSON
61
+ ccdoctor --help
62
+ ```
63
+
64
+ ccdoctor never writes to your configuration.
65
+
66
+ ## License
67
+
68
+ [PolyForm Noncommercial 1.0.0](LICENSE)
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env node
2
+ import { doctor, format, summary } from "../src/checks.js";
3
+ import { paths } from "../src/config.js";
4
+
5
+ const HELP = `ccdoctor: check a Claude Code setup for broken or unwired pieces
6
+
7
+ ccdoctor check settings, hooks, MCP servers and plugins
8
+ ccdoctor --probe also start each stdio MCP server and list its tools
9
+ ccdoctor --timeout <s> probe timeout in seconds (default 10)
10
+ ccdoctor --json print results as JSON
11
+ ccdoctor --help
12
+
13
+ Reads ~/.claude (or CLAUDE_CONFIG_DIR), ~/.claude.json and the current folder's
14
+ .claude/ and .mcp.json. Never writes anything. Exits 1 if any check fails.`;
15
+
16
+ const args = process.argv.slice(2);
17
+ const flags = new Set(args);
18
+ if (flags.has("--help") || flags.has("-h")) {
19
+ console.log(HELP);
20
+ process.exit(0);
21
+ }
22
+ const ti = args.indexOf("--timeout");
23
+ const timeout = ti >= 0 ? Number(args[ti + 1]) * 1000 : 10000;
24
+ const unknown = args.filter((a, i) => !["--probe", "--json", "--timeout"].includes(a) && !(ti >= 0 && i === ti + 1));
25
+ if (unknown.length || !(timeout > 0)) {
26
+ console.error(unknown.length ? `Unknown option: ${unknown[0]}\n\n${HELP}` : "--timeout needs a number of seconds");
27
+ process.exit(2);
28
+ }
29
+
30
+ const results = await doctor(paths(), { probe: flags.has("--probe"), timeout });
31
+ console.log(flags.has("--json") ? JSON.stringify({ results, summary: summary(results) }, null, 2) : format(results));
32
+ process.exitCode = results.some((r) => r.level === "fail") ? 1 : 0;
package/package.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "@virling/ccdoctor",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Check a Claude Code setup for broken hooks, MCP servers and plugins",
5
+ "type": "module",
6
+ "bin": {
7
+ "ccdoctor": "bin/ccdoctor.js"
8
+ },
9
+ "scripts": {
10
+ "test": "node --test"
11
+ },
12
+ "engines": {
13
+ "node": ">=20"
14
+ },
15
+ "license": "PolyForm-Noncommercial-1.0.0",
16
+ "keywords": [
17
+ "claude-code",
18
+ "mcp",
19
+ "hooks",
20
+ "doctor",
21
+ "diagnostics"
22
+ ],
23
+ "files": [
24
+ "bin",
25
+ "src",
26
+ "README.md",
27
+ "LICENSE",
28
+ "CHANGELOG.md"
29
+ ],
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/virling/ccdoctor.git"
36
+ },
37
+ "homepage": "https://github.com/virling/ccdoctor#readme",
38
+ "bugs": {
39
+ "url": "https://github.com/virling/ccdoctor/issues"
40
+ }
41
+ }
package/src/checks.js ADDED
@@ -0,0 +1,127 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { checkCommand, expand, isFile, tokenize } from "./command.js";
4
+ import { pluginDir, readJson, settingsFiles } from "./config.js";
5
+ import { probe } from "./probe.js";
6
+
7
+ function packageRoot(file) {
8
+ if (!file) return null;
9
+ let dir = path.dirname(fs.realpathSync(file));
10
+ while (!fs.existsSync(path.join(dir, "package.json"))) {
11
+ if (dir === path.dirname(dir)) return null;
12
+ dir = path.dirname(dir);
13
+ }
14
+ return dir;
15
+ }
16
+
17
+ function hookCommands(hooks = {}) {
18
+ return Object.entries(hooks).flatMap(([event, groups]) =>
19
+ (Array.isArray(groups) ? groups : []).flatMap((g) =>
20
+ (g.hooks || []).filter((h) => h.type === "command").map((h) => ({ event, command: h.command }))
21
+ )
22
+ );
23
+ }
24
+
25
+ export async function doctor(p, { probe: doProbe = false, timeout = 10000 } = {}) {
26
+ const results = [];
27
+ const short = (s) => s.split(p.home).join("~");
28
+ const add = (section, level, name, detail = "") => results.push({ section, level, name: short(name), detail: short(detail) });
29
+ const ctx = { cwd: p.cwd, home: p.home, PATH: p.PATH, vars: { ...p.env, CLAUDE_PROJECT_DIR: p.cwd } };
30
+
31
+ const settings = settingsFiles(p).map((f) => ({ ...f, ...readJson(f.file) })).filter((f) => !f.missing);
32
+ if (!settings.length) add("Settings", "info", "no settings files found");
33
+ for (const s of settings) add("Settings", s.error ? "fail" : "ok", s.file, s.error ? `invalid JSON: ${s.error}` : "");
34
+ const valid = settings.filter((s) => s.data);
35
+
36
+ const commands = [];
37
+ for (const s of valid) {
38
+ for (const h of hookCommands(s.data.hooks)) {
39
+ commands.push(h.command);
40
+ const r = checkCommand(tokenize(h.command), ctx);
41
+ add("Hooks", r.level, `${h.event} [${s.scope}] ${h.command}`, r.level === "ok" ? "" : r.detail);
42
+ }
43
+ }
44
+ if (!commands.length) add("Hooks", "info", "no hooks configured");
45
+
46
+ const servers = [];
47
+ const collect = (map, scope) => Object.entries(map || {}).forEach(([name, config]) => servers.push({ name, scope, config }));
48
+ const claudeJson = readJson(p.claudeJson);
49
+ const mcpJson = readJson(path.join(p.cwd, ".mcp.json"));
50
+ if (claudeJson.error) add("MCP servers", "fail", p.claudeJson, `invalid JSON: ${claudeJson.error}`);
51
+ if (mcpJson.error) add("MCP servers", "fail", path.join(p.cwd, ".mcp.json"), `invalid JSON: ${mcpJson.error}`);
52
+ collect(claudeJson.data?.mcpServers, "user");
53
+ collect(claudeJson.data?.projects?.[p.cwd]?.mcpServers, "local");
54
+ collect(mcpJson.data?.mcpServers, "project");
55
+ if (!servers.length) add("MCP servers", "info", "no MCP servers registered");
56
+
57
+ const stdio = [];
58
+ for (const s of servers) {
59
+ const type = s.config.type || (s.config.url ? "http" : "stdio");
60
+ if (type !== "stdio") {
61
+ add("MCP servers", "info", `${s.name} (${s.scope}, ${type})`, "remote, not checked");
62
+ continue;
63
+ }
64
+ const r = checkCommand([s.config.command ?? "", ...(s.config.args || [])], ctx);
65
+ add("MCP servers", r.level, `${s.name} (${s.scope})`, r.detail);
66
+ stdio.push(Object.assign(s, { check: r }));
67
+ }
68
+ for (const name of new Set(servers.map((s) => s.name))) {
69
+ const list = servers.filter((s) => s.name === name);
70
+ if (list.length > 1) add("MCP servers", "warn", name, `defined more than once: ${list.map((s) => s.scope).join(", ")}`);
71
+ }
72
+
73
+ if (doProbe) {
74
+ for (const s of servers.filter((s) => !stdio.includes(s))) add("Probe", "info", s.name, "not probed (remote)");
75
+ const runnable = stdio.filter((s) => s.check.level !== "fail");
76
+ const probed = await Promise.all(
77
+ runnable.map((s) => {
78
+ const env = { ...p.env };
79
+ for (const [k, v] of Object.entries(s.config.env || {})) env[k] = expand(String(v), p.env, p.home);
80
+ const args = (s.config.args || []).map((a) => expand(a, p.env, p.home));
81
+ return probe(expand(s.config.command, p.env, p.home), args, { cwd: p.cwd, env, timeout });
82
+ })
83
+ );
84
+ runnable.forEach((s, i) => {
85
+ const r = probed[i];
86
+ add("Probe", r.error ? "fail" : "ok", `${s.name} (${s.scope})`, r.error || `${r.tools} tools`);
87
+ });
88
+ for (const s of stdio.filter((s) => !runnable.includes(s))) add("Probe", "info", s.name, "not probed (command not found)");
89
+ }
90
+
91
+ const enabled = Object.assign({}, ...valid.map((s) => s.data.enabledPlugins || {}));
92
+ const keys = Object.keys(enabled).filter((k) => enabled[k] === true);
93
+ if (!keys.length) add("Plugins", "info", "no plugins enabled");
94
+ for (const key of keys) {
95
+ const dir = pluginDir(p.configDir, key);
96
+ add("Plugins", dir ? "ok" : "warn", key, dir ? "" : "enabled but not found in plugins/cache");
97
+ if (dir) commands.push(...hookCommands(readJson(path.join(dir, "hooks", "hooks.json")).data?.hooks).map((h) => h.command));
98
+ }
99
+
100
+ for (const s of stdio) {
101
+ const root = packageRoot(s.check.files.at(-1));
102
+ const shipsHooks = root && isFile(path.join(root, "hooks", "hooks.json"));
103
+ if (s.name !== "agentmem" && !shipsHooks) continue;
104
+ const wired = commands.some((c) => c.includes(s.name) || (root && c.includes(root)));
105
+ add("Wiring", wired ? "ok" : "warn", s.name, wired ? "hooks found" : "MCP server registered but its hooks are missing");
106
+ }
107
+ return results;
108
+ }
109
+
110
+ export function summary(results) {
111
+ const count = (level) => results.filter((r) => r.level === level).length;
112
+ return { ok: count("ok"), warn: count("warn"), fail: count("fail") };
113
+ }
114
+
115
+ export function format(results) {
116
+ const lines = [];
117
+ for (const section of new Set(results.map((r) => r.section))) {
118
+ lines.push(section);
119
+ for (const r of results.filter((r) => r.section === section)) {
120
+ lines.push(` ${r.level.padEnd(5)} ${r.name}${r.detail ? `: ${r.detail}` : ""}`);
121
+ }
122
+ lines.push("");
123
+ }
124
+ const s = summary(results);
125
+ lines.push(`${s.ok} ok, ${s.warn} warn, ${s.fail} fail`);
126
+ return lines.join("\n");
127
+ }
package/src/command.js ADDED
@@ -0,0 +1,82 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+
4
+ const INTERPRETERS = new Set(["node", "bash", "sh", "zsh", "python", "python3", "ruby", "perl", "bun", "deno", "tsx"]);
5
+ const BUILTINS = new Set(["echo", "printf", "true", "false", "test", "[", "cd", "exit", ":", "exec", "source", "."]);
6
+
7
+ export const isFile = (f) => !!fs.statSync(f, { throwIfNoEntry: false })?.isFile();
8
+
9
+ export function canRun(f) {
10
+ try {
11
+ fs.accessSync(f, fs.constants.X_OK);
12
+ return true;
13
+ } catch {
14
+ return false;
15
+ }
16
+ }
17
+
18
+ // Splits the first simple command of a shell line into words.
19
+ export function tokenize(cmd) {
20
+ const tokens = [];
21
+ let cur = null;
22
+ let quote = null;
23
+ for (let i = 0; i < cmd.length; i++) {
24
+ const c = cmd[i];
25
+ if (quote) {
26
+ if (c === quote) quote = null;
27
+ else if (c === "\\" && quote === '"' && i + 1 < cmd.length) cur += cmd[++i];
28
+ else cur += c;
29
+ } else if (c === "'" || c === '"') {
30
+ quote = c;
31
+ cur ??= "";
32
+ } else if (c === "\\" && i + 1 < cmd.length) cur = (cur ?? "") + cmd[++i];
33
+ else if (/\s/.test(c)) {
34
+ if (cur !== null) tokens.push(cur);
35
+ cur = null;
36
+ } else if ("|&;<>()".includes(c)) break;
37
+ else cur = (cur ?? "") + c;
38
+ }
39
+ if (cur !== null) tokens.push(cur);
40
+ return tokens;
41
+ }
42
+
43
+ export const expand = (s, vars, home) =>
44
+ s.replace(/^~(?=\/|$)/, home).replace(/\$\{(\w+)(?::-([^}]*))?\}|\$(\w+)/g, (m, a, def, b) => vars[a || b] ?? def ?? m);
45
+
46
+ export function which(exe, { PATH, cwd }) {
47
+ if (exe.includes("/")) {
48
+ const f = path.resolve(cwd, exe);
49
+ return isFile(f) ? f : null;
50
+ }
51
+ for (const dir of PATH.split(path.delimiter)) {
52
+ const f = path.join(dir, exe);
53
+ if (dir && isFile(f) && canRun(f)) return f;
54
+ }
55
+ return null;
56
+ }
57
+
58
+ function scriptArg(args) {
59
+ for (const a of args) {
60
+ if (["-c", "-e", "-m", "-p", "--eval"].includes(a)) return null;
61
+ if (!a.startsWith("-") && a !== "run") return a;
62
+ }
63
+ return null;
64
+ }
65
+
66
+ export function checkCommand(tokens, ctx) {
67
+ const t = tokens.map((x) => expand(x, ctx.vars, ctx.home));
68
+ while (t.length && /^\w+=/.test(t[0])) t.shift();
69
+ if (!t.length) return { level: "fail", detail: "empty command", files: [] };
70
+ const [exe, ...args] = t;
71
+ if (BUILTINS.has(exe)) return { level: "ok", detail: "shell builtin", files: [] };
72
+ if (exe.includes("$")) return { level: "warn", detail: `cannot resolve ${exe}`, files: [] };
73
+ const file = which(exe, ctx);
74
+ if (!file) return { level: "fail", detail: `${exe} not found${exe.includes("/") ? "" : " on PATH"}`, files: [] };
75
+ if (!canRun(file)) return { level: "warn", detail: `${file} is not executable`, files: [file] };
76
+ const script = INTERPRETERS.has(path.basename(exe)) && scriptArg(args);
77
+ if (!script) return { level: "ok", detail: file, files: [file] };
78
+ if (script.includes("$")) return { level: "warn", detail: `cannot resolve ${script}`, files: [file] };
79
+ const s = path.resolve(ctx.cwd, script);
80
+ if (!isFile(s)) return { level: "fail", detail: `script not found: ${s}`, files: [file] };
81
+ return { level: "ok", detail: s, files: [file, s] };
82
+ }
package/src/config.js ADDED
@@ -0,0 +1,37 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+
5
+ export function paths({ env = process.env, home = os.homedir(), cwd = process.cwd() } = {}) {
6
+ const configDir = env.CLAUDE_CONFIG_DIR || path.join(home, ".claude");
7
+ const claudeJson = path.join(env.CLAUDE_CONFIG_DIR ? configDir : home, ".claude.json");
8
+ return { env, home, cwd, configDir, claudeJson, PATH: env.PATH || "" };
9
+ }
10
+
11
+ export function readJson(file) {
12
+ if (!fs.existsSync(file)) return { missing: true };
13
+ try {
14
+ return { data: JSON.parse(fs.readFileSync(file, "utf8")) };
15
+ } catch (e) {
16
+ return { error: e.message };
17
+ }
18
+ }
19
+
20
+ export function settingsFiles(p) {
21
+ const files = [
22
+ { scope: "user", file: path.join(p.configDir, "settings.json") },
23
+ { scope: "project", file: path.join(p.cwd, ".claude", "settings.json") },
24
+ { scope: "local", file: path.join(p.cwd, ".claude", "settings.local.json") },
25
+ ];
26
+ return files.filter((f, i) => files.findIndex((g) => g.file === f.file) === i);
27
+ }
28
+
29
+ export function pluginDir(configDir, key) {
30
+ const installed = readJson(path.join(configDir, "plugins", "installed_plugins.json")).data?.plugins?.[key]?.[0]?.installPath;
31
+ if (installed && fs.existsSync(installed)) return installed;
32
+ const [name, market = ""] = key.split("@");
33
+ const dir = path.join(configDir, "plugins", "cache", market, name);
34
+ if (!fs.existsSync(dir)) return null;
35
+ const versions = fs.readdirSync(dir, { withFileTypes: true }).filter((d) => d.isDirectory());
36
+ return versions.length ? path.join(dir, versions[0].name) : null;
37
+ }
package/src/probe.js ADDED
@@ -0,0 +1,67 @@
1
+ import { spawn } from "node:child_process";
2
+ import fs from "node:fs";
3
+
4
+ const { version } = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8"));
5
+
6
+ function kill(child) {
7
+ try {
8
+ process.kill(-child.pid, "SIGKILL");
9
+ } catch {
10
+ child.kill("SIGKILL");
11
+ }
12
+ }
13
+
14
+ const lastLine = (s) => s.trim().split("\n").at(-1)?.slice(0, 200) ?? "";
15
+
16
+ export function probe(command, args, { cwd, env, timeout = 10000 }) {
17
+ return new Promise((resolve) => {
18
+ const child = spawn(command, args, { cwd, env, stdio: "pipe", detached: process.platform !== "win32" });
19
+ let out = "";
20
+ let err = "";
21
+ let done = false;
22
+ const finish = (result) => {
23
+ if (done) return;
24
+ done = true;
25
+ clearTimeout(timer);
26
+ kill(child);
27
+ resolve(result);
28
+ };
29
+ const send = (msg) => child.stdin.write(JSON.stringify({ jsonrpc: "2.0", ...msg }) + "\n");
30
+ const timer = setTimeout(() => finish({ error: `timed out after ${timeout / 1000}s` }), timeout);
31
+ child.on("error", (e) => finish({ error: e.message }));
32
+ child.on("exit", (code, signal) => {
33
+ const why = lastLine(err);
34
+ finish({ error: `exited with ${signal || `code ${code}`}${why ? `: ${why}` : ""}` });
35
+ });
36
+ child.stdin.on("error", () => {});
37
+ child.stderr.on("data", (d) => (err += d));
38
+ child.stdout.on("data", (d) => {
39
+ out += d;
40
+ let i;
41
+ while ((i = out.indexOf("\n")) >= 0) {
42
+ const line = out.slice(0, i);
43
+ out = out.slice(i + 1);
44
+ let msg;
45
+ try {
46
+ msg = JSON.parse(line);
47
+ } catch {
48
+ continue;
49
+ }
50
+ if (msg.method) continue;
51
+ if (msg.id === 1) {
52
+ if (msg.error) return finish({ error: `initialize failed: ${msg.error.message}` });
53
+ send({ method: "notifications/initialized" });
54
+ if (!msg.result?.capabilities?.tools) return finish({ tools: 0 });
55
+ send({ id: 2, method: "tools/list", params: {} });
56
+ } else if (msg.id === 2) {
57
+ finish(msg.error ? { error: `tools/list failed: ${msg.error.message}` } : { tools: msg.result?.tools?.length ?? 0 });
58
+ }
59
+ }
60
+ });
61
+ send({
62
+ id: 1,
63
+ method: "initialize",
64
+ params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "ccdoctor", version } },
65
+ });
66
+ });
67
+ }