claudepluginhub 0.10.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.
@@ -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
+ }
@@ -0,0 +1,30 @@
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 declare function formatApproxTokens(n: number): string;
21
+ export interface PluginEstimate {
22
+ alwaysOnTokens: number;
23
+ /** True when every skill/command/agent in the plugin was estimable. */
24
+ estimated: boolean;
25
+ largestOnInvoke: {
26
+ path: string;
27
+ tokens: number;
28
+ }[];
29
+ }
30
+ export declare function estimatePlugin(scan: ScanResult): PluginEstimate;
@@ -0,0 +1,47 @@
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 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
+ }
34
+ export function estimatePlugin(scan) {
35
+ const relevant = scan.components.filter((c) => c.type === 'skill' || c.type === 'command' || c.type === 'agent');
36
+ const estimable = relevant.filter((c) => c.estimable);
37
+ const alwaysOnTokens = estimable.reduce((sum, c) => sum + estimateTokens(c.nameDescChars), 0);
38
+ const largestOnInvoke = estimable
39
+ .map((c) => ({ path: c.relPath, tokens: estimateTokens(c.bodyChars) }))
40
+ .sort((a, b) => b.tokens - a.tokens || compareBytes(a.path, b.path))
41
+ .slice(0, 3);
42
+ return {
43
+ alwaysOnTokens,
44
+ estimated: estimable.length === relevant.length && !scan.incomplete,
45
+ largestOnInvoke,
46
+ };
47
+ }
@@ -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;