claudepluginhub 0.11.0 → 0.12.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 +15 -4
- package/dist/doctor/args.d.ts +1 -1
- package/dist/doctor/args.js +18 -8
- package/dist/doctor/color.d.ts +11 -0
- package/dist/doctor/color.js +23 -0
- package/dist/doctor/equivalence.d.ts +9 -0
- package/dist/doctor/equivalence.js +263 -0
- package/dist/doctor/estimate.d.ts +1 -0
- package/dist/doctor/estimate.js +12 -0
- package/dist/doctor/html-report.d.ts +9 -0
- package/dist/doctor/html-report.js +385 -0
- package/dist/doctor/inventory.d.ts +0 -5
- package/dist/doctor/inventory.js +150 -11
- package/dist/doctor/open-browser.d.ts +11 -0
- package/dist/doctor/open-browser.js +38 -0
- package/dist/doctor/render.d.ts +2 -8
- package/dist/doctor/render.js +323 -117
- package/dist/doctor/report.d.ts +43 -4
- package/dist/doctor/report.js +2 -0
- package/dist/doctor/rules.d.ts +39 -2
- package/dist/doctor/rules.js +0 -0
- package/dist/doctor/run.d.ts +12 -17
- package/dist/doctor/run.js +96 -16
- package/dist/doctor/select.js +0 -0
- package/dist/doctor/wrap.d.ts +2 -0
- package/dist/doctor/wrap.js +84 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,7 +88,9 @@ dependencies, LSP extension conflicts, non-executable `bin/` files, and
|
|
|
88
88
|
heuristic context-size estimates. No account or network needed.
|
|
89
89
|
|
|
90
90
|
```bash
|
|
91
|
-
npx claudepluginhub doctor #
|
|
91
|
+
npx claudepluginhub doctor # verdict-first report for the current project
|
|
92
|
+
npx claudepluginhub doctor --open # detailed HTML report opened in your browser
|
|
93
|
+
npx claudepluginhub doctor --verbose # include maintenance details and full inventory
|
|
92
94
|
npx claudepluginhub doctor --json # machine-readable (schemaVersion 1)
|
|
93
95
|
npx claudepluginhub doctor --strict # warnings also fail (CI)
|
|
94
96
|
npx claudepluginhub doctor --scope user # restrict to one scope (user|project|local|all)
|
|
@@ -96,6 +98,13 @@ npx claudepluginhub doctor --all-projects # analyze other projects' records too
|
|
|
96
98
|
npx claudepluginhub doctor --help # full reference
|
|
97
99
|
```
|
|
98
100
|
|
|
101
|
+
**Default output** leads with a verdict ("No broken plugins found" or "N
|
|
102
|
+
issues need attention"), followed by actionable findings, top context
|
|
103
|
+
contributors, and coverage notes. Maintenance details (disabled stale caches,
|
|
104
|
+
redundant records) are hidden by default — use `--verbose` to see them. Use
|
|
105
|
+
`--open` to generate a detailed self-contained HTML report and open it in your
|
|
106
|
+
browser (writes a temporary file — the only non-read-only action, opt-in).
|
|
107
|
+
|
|
99
108
|
**Default scope behavior.** Doctor diagnoses the current directory: user-scope
|
|
100
109
|
(and managed) plugins plus project/local plugins whose recorded project path
|
|
101
110
|
matches the current directory after resolving symlinks (macOS `/private/...`
|
|
@@ -104,9 +113,9 @@ analyzed unless `--all-projects` is passed — and then each project is analyzed
|
|
|
104
113
|
as its own context; plugins that merely coexist in different projects are
|
|
105
114
|
never reported as conflicting. Disabled plugins are inventoried but never
|
|
106
115
|
count toward active context totals, overlap, or runtime-risk findings. When
|
|
107
|
-
several enabled records exist for one plugin and
|
|
108
|
-
|
|
109
|
-
guessing.
|
|
116
|
+
several enabled records exist for one plugin and their scans are equivalent
|
|
117
|
+
for Doctor's checks, they are treated as one effective plugin; otherwise
|
|
118
|
+
Doctor reports the ambiguity instead of guessing.
|
|
110
119
|
|
|
111
120
|
**Severities and exit codes.** `ERROR` = breaks or blocks plugin loading;
|
|
112
121
|
`WARN` = likely problem or notable risk signal; `INFO` = context. Exit `0` =
|
|
@@ -154,6 +163,8 @@ npx claudepluginhub vercel/next.js --plugin cache-components
|
|
|
154
163
|
| `--limit <n>` | `recommend` only: picks per detected stack (1-50, default 4) |
|
|
155
164
|
| `--json` | `recommend` / `doctor`: raw JSON output |
|
|
156
165
|
| `--strict` | `doctor` only: warnings also fail the run (exit 1) |
|
|
166
|
+
| `--verbose` | `doctor` only: show maintenance details and full plugin inventory |
|
|
167
|
+
| `--open` | `doctor` only: generate a detailed HTML report and open in browser |
|
|
157
168
|
| `--all-projects` | `doctor` only: analyze other projects' records, each per project |
|
|
158
169
|
| `-h, --help` | Show help (`doctor --help` for the doctor reference) |
|
|
159
170
|
|
package/dist/doctor/args.d.ts
CHANGED
|
@@ -8,5 +8,5 @@ export type ParsedDoctorArgs = {
|
|
|
8
8
|
kind: 'error';
|
|
9
9
|
message: string;
|
|
10
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";
|
|
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 --verbose Show maintenance findings, full plugin inventory, and\n technical details hidden from the default output\n --open Generate a detailed HTML report and open it in the browser;\n writes a temporary file (explicit opt-in \u2014 the default\n command is read-only)\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 --open\n npx claudepluginhub doctor --verbose\n npx claudepluginhub doctor --json | jq '.summary'\n npx claudepluginhub doctor --strict --scope project\n";
|
|
12
12
|
export declare function parseDoctorFlags(argv: string[]): ParsedDoctorArgs;
|
package/dist/doctor/args.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
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
1
|
const VALID_SCOPES = ['user', 'project', 'local', 'all'];
|
|
8
2
|
export const DOCTOR_HELP = `ClaudePluginHub Doctor — diagnose the Claude Code plugin setup for this project.
|
|
9
3
|
|
|
@@ -17,6 +11,11 @@ Options:
|
|
|
17
11
|
--json Machine-readable report (schemaVersion 1) on stdout;
|
|
18
12
|
operational errors go to stderr
|
|
19
13
|
--strict Warnings also fail the run (exit 1) — for CI use
|
|
14
|
+
--verbose Show maintenance findings, full plugin inventory, and
|
|
15
|
+
technical details hidden from the default output
|
|
16
|
+
--open Generate a detailed HTML report and open it in the browser;
|
|
17
|
+
writes a temporary file (explicit opt-in — the default
|
|
18
|
+
command is read-only)
|
|
20
19
|
--scope <scope> Restrict to one scope: user | project | local | all
|
|
21
20
|
(default: all)
|
|
22
21
|
--all-projects Also analyze project/local records belonging to other
|
|
@@ -48,6 +47,8 @@ Privacy:
|
|
|
48
47
|
|
|
49
48
|
Examples:
|
|
50
49
|
npx claudepluginhub doctor
|
|
50
|
+
npx claudepluginhub doctor --open
|
|
51
|
+
npx claudepluginhub doctor --verbose
|
|
51
52
|
npx claudepluginhub doctor --json | jq '.summary'
|
|
52
53
|
npx claudepluginhub doctor --strict --scope project
|
|
53
54
|
`;
|
|
@@ -56,12 +57,14 @@ export function parseDoctorFlags(argv) {
|
|
|
56
57
|
return { kind: 'help' };
|
|
57
58
|
let json = false;
|
|
58
59
|
let strict = false;
|
|
60
|
+
let verbose = false;
|
|
61
|
+
let open = false;
|
|
59
62
|
let allProjects = false;
|
|
60
63
|
let scope = null;
|
|
61
64
|
const seen = new Set();
|
|
62
65
|
for (let i = 0; i < argv.length; i += 1) {
|
|
63
66
|
const arg = argv[i];
|
|
64
|
-
if (arg === '--json' || arg === '--strict' || arg === '--all-projects') {
|
|
67
|
+
if (arg === '--json' || arg === '--strict' || arg === '--all-projects' || arg === '--verbose' || arg === '--open') {
|
|
65
68
|
if (seen.has(arg))
|
|
66
69
|
return { kind: 'error', message: `Duplicate flag: ${arg}` };
|
|
67
70
|
seen.add(arg);
|
|
@@ -69,6 +72,10 @@ export function parseDoctorFlags(argv) {
|
|
|
69
72
|
json = true;
|
|
70
73
|
else if (arg === '--strict')
|
|
71
74
|
strict = true;
|
|
75
|
+
else if (arg === '--verbose')
|
|
76
|
+
verbose = true;
|
|
77
|
+
else if (arg === '--open')
|
|
78
|
+
open = true;
|
|
72
79
|
else
|
|
73
80
|
allProjects = true;
|
|
74
81
|
continue;
|
|
@@ -90,6 +97,9 @@ export function parseDoctorFlags(argv) {
|
|
|
90
97
|
}
|
|
91
98
|
return { kind: 'error', message: `Unknown argument for doctor: ${arg}` };
|
|
92
99
|
}
|
|
100
|
+
if (open && json) {
|
|
101
|
+
return { kind: 'error', message: '--open and --json are incompatible' };
|
|
102
|
+
}
|
|
93
103
|
const resolvedScope = scope ?? 'all';
|
|
94
104
|
if (allProjects && resolvedScope === 'user') {
|
|
95
105
|
return {
|
|
@@ -97,5 +107,5 @@ export function parseDoctorFlags(argv) {
|
|
|
97
107
|
message: '--all-projects only widens project-bound scopes and cannot be combined with --scope user',
|
|
98
108
|
};
|
|
99
109
|
}
|
|
100
|
-
return { kind: 'run', flags: { json, strict, scope: resolvedScope, allProjects } };
|
|
110
|
+
return { kind: 'run', flags: { json, strict, verbose, open, scope: resolvedScope, allProjects } };
|
|
101
111
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Zero-dependency ANSI color utilities for CLI output. */
|
|
2
|
+
export declare function shouldColorize(): boolean;
|
|
3
|
+
export interface Theme {
|
|
4
|
+
bold(s: string): string;
|
|
5
|
+
dim(s: string): string;
|
|
6
|
+
red(s: string): string;
|
|
7
|
+
green(s: string): string;
|
|
8
|
+
yellow(s: string): string;
|
|
9
|
+
cyan(s: string): string;
|
|
10
|
+
}
|
|
11
|
+
export declare function makeTheme(color: boolean): Theme;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Zero-dependency ANSI color utilities for CLI output. */
|
|
2
|
+
export function shouldColorize() {
|
|
3
|
+
if ('NO_COLOR' in process.env)
|
|
4
|
+
return false;
|
|
5
|
+
if (process.env.FORCE_COLOR !== undefined)
|
|
6
|
+
return true;
|
|
7
|
+
return process.stdout.isTTY === true;
|
|
8
|
+
}
|
|
9
|
+
const identity = (s) => s;
|
|
10
|
+
const wrap = (open, close) => (s) => `${open}${s}${close}`;
|
|
11
|
+
export function makeTheme(color) {
|
|
12
|
+
if (!color) {
|
|
13
|
+
return { bold: identity, dim: identity, red: identity, green: identity, yellow: identity, cyan: identity };
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
bold: wrap('\x1b[1m', '\x1b[22m'),
|
|
17
|
+
dim: wrap('\x1b[2m', '\x1b[22m'),
|
|
18
|
+
red: wrap('\x1b[31m', '\x1b[39m'),
|
|
19
|
+
green: wrap('\x1b[32m', '\x1b[39m'),
|
|
20
|
+
yellow: wrap('\x1b[33m', '\x1b[39m'),
|
|
21
|
+
cyan: wrap('\x1b[36m', '\x1b[39m'),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { InstallationRecord, ScanResult } from './report.js';
|
|
2
|
+
import type { SelectionOutput } from './select.js';
|
|
3
|
+
export declare function scanEquivalent(aRecord: InstallationRecord, aScan: ScanResult, bRecord: InstallationRecord, bScan: ScanResult): boolean;
|
|
4
|
+
/** Build the composite key used by `ruleDuplicateRecord` for grouping. */
|
|
5
|
+
export declare function duplicateRecordKey(record: InstallationRecord): string;
|
|
6
|
+
export declare function resolveEquivalences(base: SelectionOutput, scanFor: (record: InstallationRecord) => ScanResult): {
|
|
7
|
+
resolved: SelectionOutput;
|
|
8
|
+
scanEquivalentKeys: Set<string>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { compareBytes } from './report.js';
|
|
2
|
+
function cmp(a, b) {
|
|
3
|
+
const sa = a ?? '';
|
|
4
|
+
const sb = b ?? '';
|
|
5
|
+
return sa < sb ? -1 : sa > sb ? 1 : 0;
|
|
6
|
+
}
|
|
7
|
+
function cmpBool(a, b) {
|
|
8
|
+
return (a ? 1 : 0) - (b ? 1 : 0);
|
|
9
|
+
}
|
|
10
|
+
function cmpNum(a, b) {
|
|
11
|
+
return a - b;
|
|
12
|
+
}
|
|
13
|
+
function sortedStrings(arr) {
|
|
14
|
+
return [...arr].sort(compareBytes);
|
|
15
|
+
}
|
|
16
|
+
function cappedListEqual(a, b) {
|
|
17
|
+
if (a.total !== b.total || a.omitted !== b.omitted)
|
|
18
|
+
return false;
|
|
19
|
+
const sa = sortedStrings(a.items);
|
|
20
|
+
const sb = sortedStrings(b.items);
|
|
21
|
+
if (sa.length !== sb.length)
|
|
22
|
+
return false;
|
|
23
|
+
for (let i = 0; i < sa.length; i++) {
|
|
24
|
+
if (sa[i] !== sb[i])
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
function commandEqual(a, b) {
|
|
30
|
+
if (a === null && b === null)
|
|
31
|
+
return true;
|
|
32
|
+
if (a === null || b === null)
|
|
33
|
+
return false;
|
|
34
|
+
return a.form === b.form && a.executable === b.executable;
|
|
35
|
+
}
|
|
36
|
+
function canonicalErrors(errors) {
|
|
37
|
+
return errors
|
|
38
|
+
.map((e) => `${e.kind}\0${e.summary}\0${e.recognized}\0${e.dependencyId ?? ''}`)
|
|
39
|
+
.sort()
|
|
40
|
+
.join('\n');
|
|
41
|
+
}
|
|
42
|
+
function canonicalDeps(deps) {
|
|
43
|
+
return deps
|
|
44
|
+
.map((d) => `${d.name ?? ''}\0${d.marketplace ?? ''}\0${d.versionRange ?? ''}\0${d.parseable}`)
|
|
45
|
+
.sort()
|
|
46
|
+
.join('\n');
|
|
47
|
+
}
|
|
48
|
+
function manifestEqual(a, b) {
|
|
49
|
+
return (a.present === b.present &&
|
|
50
|
+
a.inspected === b.inspected &&
|
|
51
|
+
a.parseError === b.parseError &&
|
|
52
|
+
a.name === b.name &&
|
|
53
|
+
a.nameInvalid === b.nameInvalid &&
|
|
54
|
+
sortedStrings(a.invalidFields).join('\0') === sortedStrings(b.invalidFields).join('\0') &&
|
|
55
|
+
sortedStrings(a.declaredMissing).join('\0') === sortedStrings(b.declaredMissing).join('\0') &&
|
|
56
|
+
canonicalDeps(a.dependencies) === canonicalDeps(b.dependencies));
|
|
57
|
+
}
|
|
58
|
+
function cmpComponent(a, b) {
|
|
59
|
+
return cmp(a.type, b.type) || compareBytes(a.relPath, b.relPath);
|
|
60
|
+
}
|
|
61
|
+
function componentsEqual(a, b) {
|
|
62
|
+
if (a.length !== b.length)
|
|
63
|
+
return false;
|
|
64
|
+
const sa = [...a].sort(cmpComponent);
|
|
65
|
+
const sb = [...b].sort(cmpComponent);
|
|
66
|
+
for (let i = 0; i < sa.length; i++) {
|
|
67
|
+
const x = sa[i];
|
|
68
|
+
const y = sb[i];
|
|
69
|
+
if (x.type !== y.type ||
|
|
70
|
+
x.relPath !== y.relPath ||
|
|
71
|
+
x.name !== y.name ||
|
|
72
|
+
x.description !== y.description ||
|
|
73
|
+
x.estimable !== y.estimable ||
|
|
74
|
+
x.nameDescChars !== y.nameDescChars ||
|
|
75
|
+
x.bodyChars !== y.bodyChars ||
|
|
76
|
+
x.hash !== y.hash)
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
function cmpHook(a, b) {
|
|
82
|
+
return (cmp(a.event, b.event) ||
|
|
83
|
+
cmp(a.type, b.type) ||
|
|
84
|
+
cmpBool(a.broad, b.broad) ||
|
|
85
|
+
cmpBool(a.conditional, b.conditional) ||
|
|
86
|
+
cmpBool(a.toolMatched, b.toolMatched) ||
|
|
87
|
+
cmp(a.command?.form, b.command?.form) ||
|
|
88
|
+
cmp(a.command?.executable, b.command?.executable) ||
|
|
89
|
+
cmp(a.targetOrigin, b.targetOrigin));
|
|
90
|
+
}
|
|
91
|
+
function hooksEqual(a, b) {
|
|
92
|
+
if (a.length !== b.length)
|
|
93
|
+
return false;
|
|
94
|
+
const sa = [...a].sort(cmpHook);
|
|
95
|
+
const sb = [...b].sort(cmpHook);
|
|
96
|
+
for (let i = 0; i < sa.length; i++) {
|
|
97
|
+
const x = sa[i];
|
|
98
|
+
const y = sb[i];
|
|
99
|
+
if (x.event !== y.event ||
|
|
100
|
+
x.type !== y.type ||
|
|
101
|
+
x.broad !== y.broad ||
|
|
102
|
+
x.conditional !== y.conditional ||
|
|
103
|
+
x.toolMatched !== y.toolMatched ||
|
|
104
|
+
x.targetOrigin !== y.targetOrigin ||
|
|
105
|
+
!commandEqual(x.command, y.command))
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
function cmpMcp(a, b) {
|
|
111
|
+
return cmp(a.name, b.name);
|
|
112
|
+
}
|
|
113
|
+
function mcpEqual(a, b) {
|
|
114
|
+
if (a.length !== b.length)
|
|
115
|
+
return false;
|
|
116
|
+
const sa = [...a].sort(cmpMcp);
|
|
117
|
+
const sb = [...b].sort(cmpMcp);
|
|
118
|
+
for (let i = 0; i < sa.length; i++) {
|
|
119
|
+
const x = sa[i];
|
|
120
|
+
const y = sb[i];
|
|
121
|
+
if (x.name !== y.name ||
|
|
122
|
+
x.kind !== y.kind ||
|
|
123
|
+
x.commandFound !== y.commandFound ||
|
|
124
|
+
x.targetOrigin !== y.targetOrigin ||
|
|
125
|
+
!commandEqual(x.command, y.command) ||
|
|
126
|
+
!cappedListEqual(x.envKeys, y.envKeys) ||
|
|
127
|
+
!cappedListEqual(x.headerKeys, y.headerKeys))
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
function cmpLsp(a, b) {
|
|
133
|
+
return cmp(a.name, b.name);
|
|
134
|
+
}
|
|
135
|
+
function lspEqual(a, b) {
|
|
136
|
+
if (a.length !== b.length)
|
|
137
|
+
return false;
|
|
138
|
+
const sa = [...a].sort(cmpLsp);
|
|
139
|
+
const sb = [...b].sort(cmpLsp);
|
|
140
|
+
for (let i = 0; i < sa.length; i++) {
|
|
141
|
+
const x = sa[i];
|
|
142
|
+
const y = sb[i];
|
|
143
|
+
if (x.name !== y.name ||
|
|
144
|
+
x.commandFound !== y.commandFound ||
|
|
145
|
+
!commandEqual(x.command, y.command) ||
|
|
146
|
+
!cappedListEqual(x.extensions, y.extensions) ||
|
|
147
|
+
!cappedListEqual(x.languages, y.languages))
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
function cmpMonitor(a, b) {
|
|
153
|
+
return (cmp(a.name, b.name) ||
|
|
154
|
+
cmp(a.when, b.when) ||
|
|
155
|
+
cmp(a.command?.form, b.command?.form) ||
|
|
156
|
+
cmp(a.command?.executable, b.command?.executable));
|
|
157
|
+
}
|
|
158
|
+
function monitorsEqual(a, b) {
|
|
159
|
+
if (a.length !== b.length)
|
|
160
|
+
return false;
|
|
161
|
+
const sa = [...a].sort(cmpMonitor);
|
|
162
|
+
const sb = [...b].sort(cmpMonitor);
|
|
163
|
+
for (let i = 0; i < sa.length; i++) {
|
|
164
|
+
const x = sa[i];
|
|
165
|
+
const y = sb[i];
|
|
166
|
+
if (x.name !== y.name || x.when !== y.when || !commandEqual(x.command, y.command))
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
function binEqual(a, b) {
|
|
172
|
+
if (a.length !== b.length)
|
|
173
|
+
return false;
|
|
174
|
+
const sa = [...a].sort((x, y) => compareBytes(x.relPath, y.relPath));
|
|
175
|
+
const sb = [...b].sort((x, y) => compareBytes(x.relPath, y.relPath));
|
|
176
|
+
for (let i = 0; i < sa.length; i++) {
|
|
177
|
+
if (sa[i].relPath !== sb[i].relPath || sa[i].executable !== sb[i].executable)
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
export function scanEquivalent(aRecord, aScan, bRecord, bScan) {
|
|
183
|
+
if (aScan.pathIssue !== null || bScan.pathIssue !== null)
|
|
184
|
+
return false;
|
|
185
|
+
if (aScan.incomplete || bScan.incomplete)
|
|
186
|
+
return false;
|
|
187
|
+
if (canonicalErrors(aRecord.errors) !== canonicalErrors(bRecord.errors))
|
|
188
|
+
return false;
|
|
189
|
+
if (!manifestEqual(aScan.manifest, bScan.manifest))
|
|
190
|
+
return false;
|
|
191
|
+
if (!componentsEqual(aScan.components, bScan.components))
|
|
192
|
+
return false;
|
|
193
|
+
if (!hooksEqual(aScan.hooks, bScan.hooks))
|
|
194
|
+
return false;
|
|
195
|
+
if (!mcpEqual(aScan.mcp, bScan.mcp))
|
|
196
|
+
return false;
|
|
197
|
+
if (!lspEqual(aScan.lsp, bScan.lsp))
|
|
198
|
+
return false;
|
|
199
|
+
if (!monitorsEqual(aScan.monitors, bScan.monitors))
|
|
200
|
+
return false;
|
|
201
|
+
if (!binEqual(aScan.bin, bScan.bin))
|
|
202
|
+
return false;
|
|
203
|
+
if (sortedStrings(aScan.themeFiles).join('\0') !== sortedStrings(bScan.themeFiles).join('\0'))
|
|
204
|
+
return false;
|
|
205
|
+
if (sortedStrings(aScan.parseErrors).join('\0') !== sortedStrings(bScan.parseErrors).join('\0'))
|
|
206
|
+
return false;
|
|
207
|
+
if (sortedStrings(aScan.symlinksSkipped).join('\0') !== sortedStrings(bScan.symlinksSkipped).join('\0'))
|
|
208
|
+
return false;
|
|
209
|
+
if (sortedStrings(aScan.limitsHit).join('\0') !== sortedStrings(bScan.limitsHit).join('\0'))
|
|
210
|
+
return false;
|
|
211
|
+
// filesScanned and bytesRead are operational counters that do not affect
|
|
212
|
+
// findings, estimates, or any diagnostic result — deliberately excluded.
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
const SCOPE_RANK_VALUES = {
|
|
216
|
+
user: 0,
|
|
217
|
+
project: 1,
|
|
218
|
+
local: 2,
|
|
219
|
+
managed: 3,
|
|
220
|
+
unknown: 4,
|
|
221
|
+
};
|
|
222
|
+
function cmpRecord(a, b) {
|
|
223
|
+
return (cmpNum(SCOPE_RANK_VALUES[a.scope] ?? 99, SCOPE_RANK_VALUES[b.scope] ?? 99) ||
|
|
224
|
+
compareBytes(a.installPath, b.installPath) ||
|
|
225
|
+
compareBytes(a.version, b.version));
|
|
226
|
+
}
|
|
227
|
+
/** Build the composite key used by `ruleDuplicateRecord` for grouping. */
|
|
228
|
+
export function duplicateRecordKey(record) {
|
|
229
|
+
return [record.id, record.rawScope, record.projectPathCanonical ?? '', record.version].join('\0');
|
|
230
|
+
}
|
|
231
|
+
export function resolveEquivalences(base, scanFor) {
|
|
232
|
+
const scanEquivalentKeys = new Set();
|
|
233
|
+
const contexts = base.contexts.map((ctx) => {
|
|
234
|
+
const resolvedInstances = ctx.instances.map((instance) => {
|
|
235
|
+
if (instance.reason !== 'unresolved')
|
|
236
|
+
return instance;
|
|
237
|
+
const contenders = instance.contenders;
|
|
238
|
+
const scanned = contenders.map((r) => ({ record: r, scan: scanFor(r) }));
|
|
239
|
+
const first = scanned[0];
|
|
240
|
+
const allEquiv = scanned.every((s, i) => i === 0 || scanEquivalent(first.record, first.scan, s.record, s.scan));
|
|
241
|
+
if (!allEquiv)
|
|
242
|
+
return instance;
|
|
243
|
+
// Add composite keys for the specific record groups that were resolved
|
|
244
|
+
for (const r of contenders) {
|
|
245
|
+
scanEquivalentKeys.add(duplicateRecordKey(r));
|
|
246
|
+
}
|
|
247
|
+
const sorted = [...contenders].sort(cmpRecord);
|
|
248
|
+
return {
|
|
249
|
+
contextKey: instance.contextKey,
|
|
250
|
+
id: instance.id,
|
|
251
|
+
selection: 'sole',
|
|
252
|
+
reason: 'scan_equivalent',
|
|
253
|
+
record: sorted[0],
|
|
254
|
+
contenders,
|
|
255
|
+
};
|
|
256
|
+
});
|
|
257
|
+
return { ...ctx, instances: resolvedInstances };
|
|
258
|
+
});
|
|
259
|
+
return {
|
|
260
|
+
resolved: { ...base, contexts },
|
|
261
|
+
scanEquivalentKeys,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
@@ -17,6 +17,7 @@ import type { ScanResult } from './report.js';
|
|
|
17
17
|
*/
|
|
18
18
|
export declare const CHARS_PER_TOKEN = 4;
|
|
19
19
|
export declare function estimateTokens(chars: number): number;
|
|
20
|
+
export declare function formatApproxTokens(n: number): string;
|
|
20
21
|
export interface PluginEstimate {
|
|
21
22
|
alwaysOnTokens: number;
|
|
22
23
|
/** True when every skill/command/agent in the plugin was estimable. */
|
package/dist/doctor/estimate.js
CHANGED
|
@@ -19,6 +19,18 @@ export const CHARS_PER_TOKEN = 4;
|
|
|
19
19
|
export function estimateTokens(chars) {
|
|
20
20
|
return Math.ceil(chars / CHARS_PER_TOKEN);
|
|
21
21
|
}
|
|
22
|
+
export function formatApproxTokens(n) {
|
|
23
|
+
if (n < 100)
|
|
24
|
+
return `~${n}`;
|
|
25
|
+
if (n < 1000)
|
|
26
|
+
return `~${Math.round(n / 10) * 10}`;
|
|
27
|
+
if (n < 10000) {
|
|
28
|
+
const k = n / 1000;
|
|
29
|
+
const rounded = Math.round(k * 10) / 10;
|
|
30
|
+
return `~${rounded % 1 === 0 ? rounded.toFixed(0) : rounded.toFixed(1)}k`;
|
|
31
|
+
}
|
|
32
|
+
return `~${Math.round(n / 1000)}k`;
|
|
33
|
+
}
|
|
22
34
|
export function estimatePlugin(scan) {
|
|
23
35
|
const relevant = scan.components.filter((c) => c.type === 'skill' || c.type === 'command' || c.type === 'agent');
|
|
24
36
|
const estimable = relevant.filter((c) => c.estimable);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-contained HTML report renderer for `claudepluginhub doctor --open`.
|
|
3
|
+
*
|
|
4
|
+
* Produces a complete <!DOCTYPE html> document with inlined CSS, no scripts,
|
|
5
|
+
* no external resources. Light/dark theme via prefers-color-scheme.
|
|
6
|
+
*/
|
|
7
|
+
import type { DoctorReport } from './report.js';
|
|
8
|
+
export declare function escapeHtml(s: string): string;
|
|
9
|
+
export declare function renderHtml(report: DoctorReport): string;
|