claudepluginhub 0.9.0 → 0.11.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/README.md +77 -8
- package/dist/doctor/args.d.ts +12 -0
- package/dist/doctor/args.js +101 -0
- package/dist/doctor/claude-source.d.ts +27 -0
- package/dist/doctor/claude-source.js +115 -0
- package/dist/doctor/estimate.d.ts +29 -0
- package/dist/doctor/estimate.js +35 -0
- package/dist/doctor/inventory.d.ts +74 -0
- package/dist/doctor/inventory.js +1036 -0
- package/dist/doctor/overlap.d.ts +22 -0
- package/dist/doctor/overlap.js +23 -0
- package/dist/doctor/paths.d.ts +9 -0
- package/dist/doctor/paths.js +23 -0
- package/dist/doctor/render.d.ts +9 -0
- package/dist/doctor/render.js +147 -0
- package/dist/doctor/report.d.ts +308 -0
- package/dist/doctor/report.js +68 -0
- package/dist/doctor/rules.d.ts +130 -0
- package/dist/doctor/rules.js +0 -0
- package/dist/doctor/run.d.ts +29 -0
- package/dist/doctor/run.js +235 -0
- package/dist/doctor/sanitize.d.ts +28 -0
- package/dist/doctor/sanitize.js +150 -0
- package/dist/doctor/select.d.ts +53 -0
- package/dist/doctor/select.js +0 -0
- package/dist/index.js +12 -2
- package/dist/recommend.js +76 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,6 +19,9 @@ npx claudepluginhub https://claudepluginhub.com/api/user-plugins/<userId>/<slug>
|
|
|
19
19
|
|
|
20
20
|
# Recommend plugins for the current project
|
|
21
21
|
npx claudepluginhub recommend
|
|
22
|
+
|
|
23
|
+
# Diagnose your Claude Code plugin setup (local, read-only, offline)
|
|
24
|
+
npx claudepluginhub doctor
|
|
22
25
|
```
|
|
23
26
|
|
|
24
27
|
## Identifier types
|
|
@@ -51,16 +54,18 @@ npx claudepluginhub update [identifier] Update (u/ collections only)
|
|
|
51
54
|
npx claudepluginhub list List (u/ collections only)
|
|
52
55
|
npx claudepluginhub remove <identifier> Remove
|
|
53
56
|
npx claudepluginhub recommend Recommend plugins for the current project
|
|
57
|
+
npx claudepluginhub doctor Diagnose the Claude Code plugin setup (read-only)
|
|
54
58
|
```
|
|
55
59
|
|
|
56
60
|
## Recommend
|
|
57
61
|
|
|
58
|
-
Run `npx claudepluginhub recommend` from a project root to get
|
|
59
|
-
recommendations
|
|
62
|
+
Run `npx claudepluginhub recommend` from a project root to get plugin
|
|
63
|
+
recommendations grouped by each detected stack ("For Next.js:", "For
|
|
64
|
+
PostgreSQL:", …) — no account, no setup.
|
|
60
65
|
|
|
61
66
|
```bash
|
|
62
|
-
npx claudepluginhub recommend # top
|
|
63
|
-
npx claudepluginhub recommend --limit
|
|
67
|
+
npx claudepluginhub recommend # top picks per detected stack
|
|
68
|
+
npx claudepluginhub recommend --limit 6 # picks per stack (1-50, default 4)
|
|
64
69
|
npx claudepluginhub recommend --json # raw JSON, pipeable
|
|
65
70
|
```
|
|
66
71
|
|
|
@@ -70,6 +75,68 @@ exist (e.g. `next.config.*`, `tailwind.config.*`). **Privacy:** only dependency
|
|
|
70
75
|
names and allowlisted config-filename prefixes are sent — never file contents,
|
|
71
76
|
never arbitrary filenames.
|
|
72
77
|
|
|
78
|
+
## Doctor
|
|
79
|
+
|
|
80
|
+
`npx claudepluginhub doctor` diagnoses the effective Claude Code plugin setup
|
|
81
|
+
for the current project — completely locally. It reads `claude plugin list
|
|
82
|
+
--json` (the only installed-plugin source of truth) plus files inside each
|
|
83
|
+
plugin's install directory, and reports concrete findings: native load errors,
|
|
84
|
+
broken install paths or manifests, duplicate/ambiguous installations, exact
|
|
85
|
+
duplicate skill/command/agent content across enabled plugins, broad
|
|
86
|
+
unconditional command hooks, missing MCP/LSP prerequisites, missing declared
|
|
87
|
+
dependencies, LSP extension conflicts, non-executable `bin/` files, and
|
|
88
|
+
heuristic context-size estimates. No account or network needed.
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npx claudepluginhub doctor # human report for the current project
|
|
92
|
+
npx claudepluginhub doctor --json # machine-readable (schemaVersion 1)
|
|
93
|
+
npx claudepluginhub doctor --strict # warnings also fail (CI)
|
|
94
|
+
npx claudepluginhub doctor --scope user # restrict to one scope (user|project|local|all)
|
|
95
|
+
npx claudepluginhub doctor --all-projects # analyze other projects' records too, per project
|
|
96
|
+
npx claudepluginhub doctor --help # full reference
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Default scope behavior.** Doctor diagnoses the current directory: user-scope
|
|
100
|
+
(and managed) plugins plus project/local plugins whose recorded project path
|
|
101
|
+
matches the current directory after resolving symlinks (macOS `/private/...`
|
|
102
|
+
aliases included). Records belonging to other projects are counted but not
|
|
103
|
+
analyzed unless `--all-projects` is passed — and then each project is analyzed
|
|
104
|
+
as its own context; plugins that merely coexist in different projects are
|
|
105
|
+
never reported as conflicting. Disabled plugins are inventoried but never
|
|
106
|
+
count toward active context totals, overlap, or runtime-risk findings. When
|
|
107
|
+
several enabled records exist for one plugin and Claude's choice between them
|
|
108
|
+
is not publicly determinable, Doctor reports the ambiguity instead of
|
|
109
|
+
guessing.
|
|
110
|
+
|
|
111
|
+
**Severities and exit codes.** `ERROR` = breaks or blocks plugin loading;
|
|
112
|
+
`WARN` = likely problem or notable risk signal; `INFO` = context. Exit `0` =
|
|
113
|
+
no errors (with `--strict`: no warnings either); exit `1` = completed with
|
|
114
|
+
errors (or warnings under `--strict`); exit `2` = Doctor could not run (bad
|
|
115
|
+
arguments, Claude CLI missing, or unusable `claude plugin list --json`
|
|
116
|
+
output). Manifest/component checks are limited structural checks — for
|
|
117
|
+
authoritative validation run `claude plugin validate <plugin install path>`.
|
|
118
|
+
|
|
119
|
+
**Context estimates** are heuristics (≈4 characters/token, always marked
|
|
120
|
+
`~`): always-on ≈ each skill/command/agent's name + description (the plugin's
|
|
121
|
+
listing text); on-invoke ≈ the component body. `claude plugin details` is the
|
|
122
|
+
authoritative source.
|
|
123
|
+
|
|
124
|
+
**Privacy.** Doctor is read-only and offline: it executes nothing (no plugin
|
|
125
|
+
code, hooks, MCP/LSP servers, or binaries), modifies nothing, and sends
|
|
126
|
+
nothing anywhere. Reports contain no absolute paths, file contents, or
|
|
127
|
+
environment/header values; URLs are reduced to their origin and commands to an
|
|
128
|
+
executable name, so `--json` output is safe to share.
|
|
129
|
+
|
|
130
|
+
```jsonc
|
|
131
|
+
// npx claudepluginhub doctor --json | jq '.summary'
|
|
132
|
+
{
|
|
133
|
+
"errors": 0,
|
|
134
|
+
"warnings": 1,
|
|
135
|
+
"notes": 2,
|
|
136
|
+
"otherProjectRecordsIgnored": 3
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
73
140
|
## Examples
|
|
74
141
|
|
|
75
142
|
```bash
|
|
@@ -83,10 +150,12 @@ npx claudepluginhub vercel/next.js --plugin cache-components
|
|
|
83
150
|
|--------|-------------|
|
|
84
151
|
| `--plugin <name>` | Install a specific plugin from a marketplace repo |
|
|
85
152
|
| `--yes, -y` | Skip prompts (install all, project scope) |
|
|
86
|
-
| `--scope <scope>` | Set scope: `user`, `project` (default), `local` |
|
|
87
|
-
| `--limit <n>` | `recommend` only:
|
|
88
|
-
| `--json` | `recommend`
|
|
89
|
-
|
|
|
153
|
+
| `--scope <scope>` | Set scope: `user`, `project` (default), `local` — `doctor` also accepts `all` (its default) |
|
|
154
|
+
| `--limit <n>` | `recommend` only: picks per detected stack (1-50, default 4) |
|
|
155
|
+
| `--json` | `recommend` / `doctor`: raw JSON output |
|
|
156
|
+
| `--strict` | `doctor` only: warnings also fail the run (exit 1) |
|
|
157
|
+
| `--all-projects` | `doctor` only: analyze other projects' records, each per project |
|
|
158
|
+
| `-h, --help` | Show help (`doctor --help` for the doctor reference) |
|
|
90
159
|
|
|
91
160
|
## Lifecycle differences
|
|
92
161
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DoctorFlags } from './report.js';
|
|
2
|
+
export type ParsedDoctorArgs = {
|
|
3
|
+
kind: 'help';
|
|
4
|
+
} | {
|
|
5
|
+
kind: 'run';
|
|
6
|
+
flags: DoctorFlags;
|
|
7
|
+
} | {
|
|
8
|
+
kind: 'error';
|
|
9
|
+
message: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const DOCTOR_HELP = "ClaudePluginHub Doctor \u2014 diagnose the Claude Code plugin setup for this project.\n\nUsage: npx claudepluginhub doctor [options]\n\nReads `claude plugin list --json` plus files inside each plugin's install\ndirectory. Local-first and read-only: no plugin code is executed, nothing is\nmodified, and nothing is sent anywhere \u2014 no account or network needed.\n\nOptions:\n --json Machine-readable report (schemaVersion 1) on stdout;\n operational errors go to stderr\n --strict Warnings also fail the run (exit 1) \u2014 for CI use\n --scope <scope> Restrict to one scope: user | project | local | all\n (default: all)\n --all-projects Also analyze project/local records belonging to other\n projects, each within its own project context\n -h, --help Show this help (runs nothing, scans nothing)\n\nDefault behavior:\n Diagnoses the effective setup for the current directory: user-scope (and\n managed) plugins, plus project/local plugins whose project path matches the\n current directory after resolving symlinks. Records belonging to other\n projects are counted but not analyzed unless --all-projects is passed.\n Disabled plugins are inventoried but never contribute to active context\n totals, overlap findings, or runtime-risk analysis. When several enabled\n records exist for one plugin and Claude's choice between them is not\n publicly determinable, Doctor reports the ambiguity instead of guessing.\n\nSeverities and exit codes:\n ERROR breaks or blocks plugin loading exit 1\n WARN likely problem or notable risk signal exit 1 only with --strict\n INFO context and low-stakes observations never fails the run\n exit 2 = Doctor could not run (bad arguments, Claude CLI missing, or\n unusable `claude plugin list --json` output).\n\nPrivacy:\n The report contains no absolute paths, file contents, or environment/header\n values. URLs are reduced to their origin; commands to an executable name.\n Context estimates are heuristics (~4 characters per token, marked with ~);\n `claude plugin details` is the authoritative source.\n\nExamples:\n npx claudepluginhub doctor\n npx claudepluginhub doctor --json | jq '.summary'\n npx claudepluginhub doctor --strict --scope project\n";
|
|
12
|
+
export declare function parseDoctorFlags(argv: string[]): ParsedDoctorArgs;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Doctor owns its flag parsing (routed in main() BEFORE the global parseArgs,
|
|
3
|
+
* which would reject `--scope all`). Help is handled first and must not
|
|
4
|
+
* invoke Claude or touch the filesystem. Argument problems are exit-code 2
|
|
5
|
+
* territory: Doctor could not run at all.
|
|
6
|
+
*/
|
|
7
|
+
const VALID_SCOPES = ['user', 'project', 'local', 'all'];
|
|
8
|
+
export const DOCTOR_HELP = `ClaudePluginHub Doctor — diagnose the Claude Code plugin setup for this project.
|
|
9
|
+
|
|
10
|
+
Usage: npx claudepluginhub doctor [options]
|
|
11
|
+
|
|
12
|
+
Reads \`claude plugin list --json\` plus files inside each plugin's install
|
|
13
|
+
directory. Local-first and read-only: no plugin code is executed, nothing is
|
|
14
|
+
modified, and nothing is sent anywhere — no account or network needed.
|
|
15
|
+
|
|
16
|
+
Options:
|
|
17
|
+
--json Machine-readable report (schemaVersion 1) on stdout;
|
|
18
|
+
operational errors go to stderr
|
|
19
|
+
--strict Warnings also fail the run (exit 1) — for CI use
|
|
20
|
+
--scope <scope> Restrict to one scope: user | project | local | all
|
|
21
|
+
(default: all)
|
|
22
|
+
--all-projects Also analyze project/local records belonging to other
|
|
23
|
+
projects, each within its own project context
|
|
24
|
+
-h, --help Show this help (runs nothing, scans nothing)
|
|
25
|
+
|
|
26
|
+
Default behavior:
|
|
27
|
+
Diagnoses the effective setup for the current directory: user-scope (and
|
|
28
|
+
managed) plugins, plus project/local plugins whose project path matches the
|
|
29
|
+
current directory after resolving symlinks. Records belonging to other
|
|
30
|
+
projects are counted but not analyzed unless --all-projects is passed.
|
|
31
|
+
Disabled plugins are inventoried but never contribute to active context
|
|
32
|
+
totals, overlap findings, or runtime-risk analysis. When several enabled
|
|
33
|
+
records exist for one plugin and Claude's choice between them is not
|
|
34
|
+
publicly determinable, Doctor reports the ambiguity instead of guessing.
|
|
35
|
+
|
|
36
|
+
Severities and exit codes:
|
|
37
|
+
ERROR breaks or blocks plugin loading exit 1
|
|
38
|
+
WARN likely problem or notable risk signal exit 1 only with --strict
|
|
39
|
+
INFO context and low-stakes observations never fails the run
|
|
40
|
+
exit 2 = Doctor could not run (bad arguments, Claude CLI missing, or
|
|
41
|
+
unusable \`claude plugin list --json\` output).
|
|
42
|
+
|
|
43
|
+
Privacy:
|
|
44
|
+
The report contains no absolute paths, file contents, or environment/header
|
|
45
|
+
values. URLs are reduced to their origin; commands to an executable name.
|
|
46
|
+
Context estimates are heuristics (~4 characters per token, marked with ~);
|
|
47
|
+
\`claude plugin details\` is the authoritative source.
|
|
48
|
+
|
|
49
|
+
Examples:
|
|
50
|
+
npx claudepluginhub doctor
|
|
51
|
+
npx claudepluginhub doctor --json | jq '.summary'
|
|
52
|
+
npx claudepluginhub doctor --strict --scope project
|
|
53
|
+
`;
|
|
54
|
+
export function parseDoctorFlags(argv) {
|
|
55
|
+
if (argv.includes('--help') || argv.includes('-h'))
|
|
56
|
+
return { kind: 'help' };
|
|
57
|
+
let json = false;
|
|
58
|
+
let strict = false;
|
|
59
|
+
let allProjects = false;
|
|
60
|
+
let scope = null;
|
|
61
|
+
const seen = new Set();
|
|
62
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
63
|
+
const arg = argv[i];
|
|
64
|
+
if (arg === '--json' || arg === '--strict' || arg === '--all-projects') {
|
|
65
|
+
if (seen.has(arg))
|
|
66
|
+
return { kind: 'error', message: `Duplicate flag: ${arg}` };
|
|
67
|
+
seen.add(arg);
|
|
68
|
+
if (arg === '--json')
|
|
69
|
+
json = true;
|
|
70
|
+
else if (arg === '--strict')
|
|
71
|
+
strict = true;
|
|
72
|
+
else
|
|
73
|
+
allProjects = true;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (arg === '--scope') {
|
|
77
|
+
if (seen.has(arg))
|
|
78
|
+
return { kind: 'error', message: 'Duplicate flag: --scope' };
|
|
79
|
+
seen.add(arg);
|
|
80
|
+
const value = argv[i + 1];
|
|
81
|
+
if (!value || value.startsWith('-')) {
|
|
82
|
+
return { kind: 'error', message: 'Missing value for --scope. Must be: user, project, local, or all' };
|
|
83
|
+
}
|
|
84
|
+
if (!VALID_SCOPES.includes(value)) {
|
|
85
|
+
return { kind: 'error', message: `Invalid scope "${value}". Must be: user, project, local, or all` };
|
|
86
|
+
}
|
|
87
|
+
scope = value;
|
|
88
|
+
i += 1;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
return { kind: 'error', message: `Unknown argument for doctor: ${arg}` };
|
|
92
|
+
}
|
|
93
|
+
const resolvedScope = scope ?? 'all';
|
|
94
|
+
if (allProjects && resolvedScope === 'user') {
|
|
95
|
+
return {
|
|
96
|
+
kind: 'error',
|
|
97
|
+
message: '--all-projects only widens project-bound scopes and cannot be combined with --scope user',
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return { kind: 'run', flags: { json, strict, scope: resolvedScope, allProjects } };
|
|
101
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { InstallationRecord } from './report.js';
|
|
2
|
+
/**
|
|
3
|
+
* Probe layer over the Claude CLI. `claude plugin list --json` is the ONLY
|
|
4
|
+
* installed-plugin source of truth; its exact shape is undocumented, so
|
|
5
|
+
* records are validated individually — a malformed element is dropped (and
|
|
6
|
+
* counted) without failing the run, while a top-level failure (claude not
|
|
7
|
+
* spawnable, non-zero exit, output not a JSON array) is an operational
|
|
8
|
+
* failure the caller maps to exit 2.
|
|
9
|
+
*/
|
|
10
|
+
export interface ClaudeExecResult {
|
|
11
|
+
ok: boolean;
|
|
12
|
+
stdout: string;
|
|
13
|
+
stderr: string;
|
|
14
|
+
}
|
|
15
|
+
export type ClaudeExec = (args: string[]) => ClaudeExecResult;
|
|
16
|
+
export interface ProbeSuccess {
|
|
17
|
+
ok: true;
|
|
18
|
+
claudeVersion: string | null;
|
|
19
|
+
records: InstallationRecord[];
|
|
20
|
+
droppedRecords: number;
|
|
21
|
+
}
|
|
22
|
+
export interface ProbeFailure {
|
|
23
|
+
ok: false;
|
|
24
|
+
reason: string;
|
|
25
|
+
}
|
|
26
|
+
export type ProbeResult = ProbeSuccess | ProbeFailure;
|
|
27
|
+
export declare function probeClaude(exec?: ClaudeExec): ProbeResult;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { boundEvidenceString } from './report.js';
|
|
3
|
+
import { canonicalize } from './paths.js';
|
|
4
|
+
import { sanitizeNativeErrors } from './sanitize.js';
|
|
5
|
+
const KNOWN_SCOPES = new Set(['user', 'project', 'local', 'managed']);
|
|
6
|
+
function defaultExec(args) {
|
|
7
|
+
try {
|
|
8
|
+
const stdout = execFileSync('claude', args, {
|
|
9
|
+
encoding: 'utf-8',
|
|
10
|
+
timeout: 60_000,
|
|
11
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
12
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
13
|
+
});
|
|
14
|
+
return { ok: true, stdout, stderr: '' };
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
const error = err;
|
|
18
|
+
return {
|
|
19
|
+
ok: false,
|
|
20
|
+
stdout: error.stdout ?? '',
|
|
21
|
+
stderr: error.stderr ?? error.message ?? 'Unknown error',
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function parseVersion(output) {
|
|
26
|
+
const match = output.trim().match(/^(\d+\.\d+\.\d+\S*)/);
|
|
27
|
+
return match ? match[1] : null;
|
|
28
|
+
}
|
|
29
|
+
function splitId(id) {
|
|
30
|
+
const at = id.lastIndexOf('@');
|
|
31
|
+
if (at <= 0)
|
|
32
|
+
return { name: id, marketplace: '' };
|
|
33
|
+
return { name: id.slice(0, at), marketplace: id.slice(at + 1) };
|
|
34
|
+
}
|
|
35
|
+
function parseRecord(element) {
|
|
36
|
+
if (!element || typeof element !== 'object' || Array.isArray(element))
|
|
37
|
+
return null;
|
|
38
|
+
const raw = element;
|
|
39
|
+
if (typeof raw.id !== 'string' || raw.id.length === 0)
|
|
40
|
+
return null;
|
|
41
|
+
if (typeof raw.scope !== 'string' || raw.scope.length === 0)
|
|
42
|
+
return null;
|
|
43
|
+
if (typeof raw.enabled !== 'boolean')
|
|
44
|
+
return null;
|
|
45
|
+
if (typeof raw.installPath !== 'string' || raw.installPath.length === 0)
|
|
46
|
+
return null;
|
|
47
|
+
if (raw.version !== undefined && typeof raw.version !== 'string')
|
|
48
|
+
return null;
|
|
49
|
+
if (raw.projectPath !== undefined && typeof raw.projectPath !== 'string')
|
|
50
|
+
return null;
|
|
51
|
+
// Bound externally sourced identifiers — id/version/scope strings come
|
|
52
|
+
// from another program's output and must not inflate the report.
|
|
53
|
+
const id = boundEvidenceString(raw.id);
|
|
54
|
+
const { name, marketplace } = splitId(id);
|
|
55
|
+
const rawScope = boundEvidenceString(raw.scope);
|
|
56
|
+
const scope = KNOWN_SCOPES.has(rawScope) ? rawScope : 'unknown';
|
|
57
|
+
return {
|
|
58
|
+
id,
|
|
59
|
+
name,
|
|
60
|
+
marketplace,
|
|
61
|
+
version: boundEvidenceString(raw.version ?? 'unknown'),
|
|
62
|
+
scope,
|
|
63
|
+
rawScope,
|
|
64
|
+
enabled: raw.enabled,
|
|
65
|
+
installPath: raw.installPath,
|
|
66
|
+
installPathCanonical: canonicalize(raw.installPath),
|
|
67
|
+
projectPathCanonical: typeof raw.projectPath === 'string' ? canonicalize(raw.projectPath) : null,
|
|
68
|
+
errors: sanitizeNativeErrors(raw.errors),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export function probeClaude(exec = defaultExec) {
|
|
72
|
+
const versionResult = exec(['--version']);
|
|
73
|
+
if (!versionResult.ok) {
|
|
74
|
+
return {
|
|
75
|
+
ok: false,
|
|
76
|
+
reason: 'Claude CLI not found or not runnable. Doctor needs `claude plugin list --json` for its inventory. ' +
|
|
77
|
+
'Install Claude Code first: https://code.claude.com/docs',
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const claudeVersion = parseVersion(versionResult.stdout);
|
|
81
|
+
const listResult = exec(['plugin', 'list', '--json']);
|
|
82
|
+
if (!listResult.ok) {
|
|
83
|
+
const detail = listResult.stderr.trim().slice(0, 200);
|
|
84
|
+
return {
|
|
85
|
+
ok: false,
|
|
86
|
+
reason: `\`claude plugin list --json\` failed${detail ? `: ${detail}` : ''}. This Claude version may be too old for Doctor.`,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
let parsed;
|
|
90
|
+
try {
|
|
91
|
+
parsed = JSON.parse(listResult.stdout);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return {
|
|
95
|
+
ok: false,
|
|
96
|
+
reason: '`claude plugin list --json` did not return valid JSON. This Claude version may be too old for Doctor.',
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (!Array.isArray(parsed)) {
|
|
100
|
+
return {
|
|
101
|
+
ok: false,
|
|
102
|
+
reason: '`claude plugin list --json` did not return a JSON array. This Claude version may be too old for Doctor.',
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const records = [];
|
|
106
|
+
let droppedRecords = 0;
|
|
107
|
+
for (const element of parsed) {
|
|
108
|
+
const record = parseRecord(element);
|
|
109
|
+
if (record)
|
|
110
|
+
records.push(record);
|
|
111
|
+
else
|
|
112
|
+
droppedRecords += 1;
|
|
113
|
+
}
|
|
114
|
+
return { ok: true, claudeVersion, records, droppedRecords };
|
|
115
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ScanResult } from './report.js';
|
|
2
|
+
/**
|
|
3
|
+
* THE context-estimate heuristic — centralized here, documented once.
|
|
4
|
+
*
|
|
5
|
+
* Rule: tokens ≈ ceil(characters / 4), computed from local file contents.
|
|
6
|
+
* - Always-on = the plugin's listing text: each skill/command/agent's
|
|
7
|
+
* frontmatter name + description (mirrors the documented semantics of
|
|
8
|
+
* `claude plugin details`, which counts "listing text ... added to every
|
|
9
|
+
* session"). Hooks/MCP/LSP are NOT estimated.
|
|
10
|
+
* - On-invoke = a component's full body, paid when it fires.
|
|
11
|
+
*
|
|
12
|
+
* All values are estimates: render with a `~` prefix and say so. Components
|
|
13
|
+
* whose frontmatter the bounded reader could not understand are excluded and
|
|
14
|
+
* the plugin is flagged `estimated: false` (unestimated ≠ invalid).
|
|
15
|
+
* `claude plugin details` is the authoritative source; Doctor never parses
|
|
16
|
+
* its human output.
|
|
17
|
+
*/
|
|
18
|
+
export declare const CHARS_PER_TOKEN = 4;
|
|
19
|
+
export declare function estimateTokens(chars: number): number;
|
|
20
|
+
export interface PluginEstimate {
|
|
21
|
+
alwaysOnTokens: number;
|
|
22
|
+
/** True when every skill/command/agent in the plugin was estimable. */
|
|
23
|
+
estimated: boolean;
|
|
24
|
+
largestOnInvoke: {
|
|
25
|
+
path: string;
|
|
26
|
+
tokens: number;
|
|
27
|
+
}[];
|
|
28
|
+
}
|
|
29
|
+
export declare function estimatePlugin(scan: ScanResult): PluginEstimate;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { compareBytes } from './report.js';
|
|
2
|
+
/**
|
|
3
|
+
* THE context-estimate heuristic — centralized here, documented once.
|
|
4
|
+
*
|
|
5
|
+
* Rule: tokens ≈ ceil(characters / 4), computed from local file contents.
|
|
6
|
+
* - Always-on = the plugin's listing text: each skill/command/agent's
|
|
7
|
+
* frontmatter name + description (mirrors the documented semantics of
|
|
8
|
+
* `claude plugin details`, which counts "listing text ... added to every
|
|
9
|
+
* session"). Hooks/MCP/LSP are NOT estimated.
|
|
10
|
+
* - On-invoke = a component's full body, paid when it fires.
|
|
11
|
+
*
|
|
12
|
+
* All values are estimates: render with a `~` prefix and say so. Components
|
|
13
|
+
* whose frontmatter the bounded reader could not understand are excluded and
|
|
14
|
+
* the plugin is flagged `estimated: false` (unestimated ≠ invalid).
|
|
15
|
+
* `claude plugin details` is the authoritative source; Doctor never parses
|
|
16
|
+
* its human output.
|
|
17
|
+
*/
|
|
18
|
+
export const CHARS_PER_TOKEN = 4;
|
|
19
|
+
export function estimateTokens(chars) {
|
|
20
|
+
return Math.ceil(chars / CHARS_PER_TOKEN);
|
|
21
|
+
}
|
|
22
|
+
export function estimatePlugin(scan) {
|
|
23
|
+
const relevant = scan.components.filter((c) => c.type === 'skill' || c.type === 'command' || c.type === 'agent');
|
|
24
|
+
const estimable = relevant.filter((c) => c.estimable);
|
|
25
|
+
const alwaysOnTokens = estimable.reduce((sum, c) => sum + estimateTokens(c.nameDescChars), 0);
|
|
26
|
+
const largestOnInvoke = estimable
|
|
27
|
+
.map((c) => ({ path: c.relPath, tokens: estimateTokens(c.bodyChars) }))
|
|
28
|
+
.sort((a, b) => b.tokens - a.tokens || compareBytes(a.path, b.path))
|
|
29
|
+
.slice(0, 3);
|
|
30
|
+
return {
|
|
31
|
+
alwaysOnTokens,
|
|
32
|
+
estimated: estimable.length === relevant.length && !scan.incomplete,
|
|
33
|
+
largestOnInvoke,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ScanResult } from './report.js';
|
|
2
|
+
/**
|
|
3
|
+
* Bounded, deterministic, read-only inventory of one plugin install root.
|
|
4
|
+
*
|
|
5
|
+
* Treats every plugin file as untrusted input: size-checked before reading,
|
|
6
|
+
* JSON parsed in try/catch, frontmatter read by a bounded line scanner (NOT a
|
|
7
|
+
* YAML parser — files it cannot understand become "unestimated", never
|
|
8
|
+
* "invalid"). Nothing from a plugin is ever executed, required, or imported.
|
|
9
|
+
*
|
|
10
|
+
* These are LIMITED STRUCTURAL CHECKS, not full plugin validation — the
|
|
11
|
+
* authoritative validator is `claude plugin validate <path>`.
|
|
12
|
+
*
|
|
13
|
+
* Symlinks: the root is canonicalized first; entries are lstat'ed; symlinks
|
|
14
|
+
* are followed only when their realpath stays within the canonical root
|
|
15
|
+
* (legitimate dev setups), guarded by a visited-realpath set (cycles) and the
|
|
16
|
+
* depth/file/byte budgets. Escaping or unresolvable links are reported and
|
|
17
|
+
* mark the inventory incomplete rather than being silently ignored.
|
|
18
|
+
*
|
|
19
|
+
* Scans are memoized globally by canonical root: the same directory is never
|
|
20
|
+
* rescanned no matter how many records or project contexts point at it.
|
|
21
|
+
*/
|
|
22
|
+
export interface ScanLimits {
|
|
23
|
+
/** Distinct plugin roots scanned per run. */
|
|
24
|
+
maxPlugins: number;
|
|
25
|
+
/** Files encountered per plugin before the walk stops. */
|
|
26
|
+
maxFilesPerPlugin: number;
|
|
27
|
+
/** Per-file read cap — larger files are counted but not read. */
|
|
28
|
+
maxFileBytes: number;
|
|
29
|
+
/** Total bytes read per plugin. */
|
|
30
|
+
maxPluginBytes: number;
|
|
31
|
+
/** Total bytes read per run. */
|
|
32
|
+
maxTotalBytes: number;
|
|
33
|
+
/** Directory depth below the plugin root. */
|
|
34
|
+
maxDepth: number;
|
|
35
|
+
}
|
|
36
|
+
export declare const DEFAULT_LIMITS: ScanLimits;
|
|
37
|
+
/** Documented tool-matched hook events (hooks reference). */
|
|
38
|
+
export declare const TOOL_MATCHED_EVENTS: Set<string>;
|
|
39
|
+
/**
|
|
40
|
+
* Aggregate cap on hook/MCP/LSP/monitor facts per plugin. Parse helpers stop
|
|
41
|
+
* producing at MAX_FACTS_PER_TYPE + 1 so the scanner can DETECT the overflow
|
|
42
|
+
* and flag it ('max-facts' → scan_incomplete) instead of capping silently.
|
|
43
|
+
*/
|
|
44
|
+
export declare const MAX_FACTS_PER_TYPE = 100;
|
|
45
|
+
export interface Scanner {
|
|
46
|
+
scan(installPath: string): ScanResult;
|
|
47
|
+
stats(): {
|
|
48
|
+
pluginsScanned: number;
|
|
49
|
+
filesScanned: number;
|
|
50
|
+
bytesRead: number;
|
|
51
|
+
truncated: boolean;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export declare function createScanner(overrides?: Partial<ScanLimits>): Scanner;
|
|
55
|
+
interface ParsedFrontmatter {
|
|
56
|
+
name: string | null;
|
|
57
|
+
description: string | null;
|
|
58
|
+
understood: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Bounded single-line frontmatter reader. Not YAML: block scalars, multi-line
|
|
62
|
+
* values, or an unterminated fence make the file "not understood" — the
|
|
63
|
+
* component is then reported as unestimated rather than invalid.
|
|
64
|
+
*/
|
|
65
|
+
export declare function parseFrontmatter(content: string): ParsedFrontmatter;
|
|
66
|
+
export declare function hashComponentContent(content: string): string;
|
|
67
|
+
/**
|
|
68
|
+
* PATH-style prerequisite lookup. Pure fs — the command is never executed.
|
|
69
|
+
* Returns null when the declaration cannot be resolved statically
|
|
70
|
+
* (env expansion other than ${CLAUDE_PLUGIN_ROOT}, relative paths):
|
|
71
|
+
* "unresolvable" must never be reported as "missing".
|
|
72
|
+
*/
|
|
73
|
+
export declare function commandOnPath(rawCommand: string, args: unknown, rootCanonical: string, env?: NodeJS.ProcessEnv): boolean | null;
|
|
74
|
+
export {};
|