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
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ScanResult } from './report.js';
|
|
2
|
+
/**
|
|
3
|
+
* Exact duplicate detection for primary component content (skills, commands,
|
|
4
|
+
* agents) across the enabled, unambiguous effective instances of ONE project
|
|
5
|
+
* context. "Exact" means byte-identical after normalizing line endings
|
|
6
|
+
* (CRLF→LF) and trailing end-of-file whitespace — nothing else. This is never
|
|
7
|
+
* a semantic-similarity claim, and a duplicate is not proof that either
|
|
8
|
+
* plugin is defective.
|
|
9
|
+
*/
|
|
10
|
+
export interface OverlapEntry {
|
|
11
|
+
pluginId: string;
|
|
12
|
+
type: string;
|
|
13
|
+
relPath: string;
|
|
14
|
+
}
|
|
15
|
+
export interface OverlapGroup {
|
|
16
|
+
hash: string;
|
|
17
|
+
entries: OverlapEntry[];
|
|
18
|
+
}
|
|
19
|
+
export declare function findOverlaps(plugins: {
|
|
20
|
+
pluginId: string;
|
|
21
|
+
scan: ScanResult;
|
|
22
|
+
}[]): OverlapGroup[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { compareBytes } from './report.js';
|
|
2
|
+
export function findOverlaps(plugins) {
|
|
3
|
+
const byHash = new Map();
|
|
4
|
+
for (const { pluginId, scan } of plugins) {
|
|
5
|
+
for (const component of scan.components) {
|
|
6
|
+
if (component.hash === null)
|
|
7
|
+
continue;
|
|
8
|
+
const entries = byHash.get(component.hash) ?? [];
|
|
9
|
+
entries.push({ pluginId, type: component.type, relPath: component.relPath });
|
|
10
|
+
byHash.set(component.hash, entries);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const groups = [];
|
|
14
|
+
for (const [hash, entries] of byHash.entries()) {
|
|
15
|
+
const distinctPlugins = new Set(entries.map((e) => e.pluginId));
|
|
16
|
+
if (distinctPlugins.size < 2)
|
|
17
|
+
continue; // within-plugin repetition is not cross-plugin overlap
|
|
18
|
+
entries.sort((a, b) => compareBytes(a.pluginId, b.pluginId) || compareBytes(a.relPath, b.relPath));
|
|
19
|
+
groups.push({ hash, entries });
|
|
20
|
+
}
|
|
21
|
+
groups.sort((a, b) => compareBytes(a.hash, b.hash));
|
|
22
|
+
return groups;
|
|
23
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonicalize a path for identity comparisons: realpath when the target
|
|
3
|
+
* exists (resolves macOS /tmp → /private/tmp aliasing and other symlinks),
|
|
4
|
+
* plain resolve+normalize when it does not (a stale projectPath from Claude
|
|
5
|
+
* must never throw — it simply won't match anything that exists).
|
|
6
|
+
*/
|
|
7
|
+
export declare function canonicalize(path: string): string;
|
|
8
|
+
/** True when childCanonical is rootCanonical or lies underneath it. */
|
|
9
|
+
export declare function isWithin(rootCanonical: string, childCanonical: string): boolean;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { realpathSync } from 'node:fs';
|
|
2
|
+
import { resolve, sep } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Canonicalize a path for identity comparisons: realpath when the target
|
|
5
|
+
* exists (resolves macOS /tmp → /private/tmp aliasing and other symlinks),
|
|
6
|
+
* plain resolve+normalize when it does not (a stale projectPath from Claude
|
|
7
|
+
* must never throw — it simply won't match anything that exists).
|
|
8
|
+
*/
|
|
9
|
+
export function canonicalize(path) {
|
|
10
|
+
try {
|
|
11
|
+
return realpathSync(path);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return resolve(path);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** True when childCanonical is rootCanonical or lies underneath it. */
|
|
18
|
+
export function isWithin(rootCanonical, childCanonical) {
|
|
19
|
+
if (childCanonical === rootCanonical)
|
|
20
|
+
return true;
|
|
21
|
+
const root = rootCanonical.endsWith(sep) ? rootCanonical : rootCanonical + sep;
|
|
22
|
+
return childCanonical.startsWith(root);
|
|
23
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DoctorReport } from './report.js';
|
|
2
|
+
/**
|
|
3
|
+
* Renderers over one shared DoctorReport. JSON mode emits exactly one JSON
|
|
4
|
+
* document (no ANSI, no banners); human mode uses the CLI's existing color
|
|
5
|
+
* palette. Capability inventory renders as per-plugin facts; the findings
|
|
6
|
+
* list stays reserved for actionable conditions.
|
|
7
|
+
*/
|
|
8
|
+
export declare function renderJson(report: DoctorReport): string;
|
|
9
|
+
export declare function renderHuman(report: DoctorReport): string;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { BOLD, CYAN, DIM, RED, RESET, YELLOW } from '../output.js';
|
|
2
|
+
/**
|
|
3
|
+
* Renderers over one shared DoctorReport. JSON mode emits exactly one JSON
|
|
4
|
+
* document (no ANSI, no banners); human mode uses the CLI's existing color
|
|
5
|
+
* palette. Capability inventory renders as per-plugin facts; the findings
|
|
6
|
+
* list stays reserved for actionable conditions.
|
|
7
|
+
*/
|
|
8
|
+
export function renderJson(report) {
|
|
9
|
+
return `${JSON.stringify(report, null, 2)}\n`;
|
|
10
|
+
}
|
|
11
|
+
function formatTokens(n) {
|
|
12
|
+
return n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
13
|
+
}
|
|
14
|
+
const SEVERITY_TAG = {
|
|
15
|
+
error: `${RED}${BOLD}ERROR${RESET}`,
|
|
16
|
+
warning: `${YELLOW}WARN ${RESET}`,
|
|
17
|
+
info: `${DIM}INFO ${RESET}`,
|
|
18
|
+
};
|
|
19
|
+
function pluginChips(entry) {
|
|
20
|
+
const chips = [];
|
|
21
|
+
if (entry.components) {
|
|
22
|
+
for (const [type, summary] of Object.entries(entry.components)) {
|
|
23
|
+
if (summary.count > 0)
|
|
24
|
+
chips.push(`${type} ${summary.count}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (entry.capabilities) {
|
|
28
|
+
const caps = entry.capabilities;
|
|
29
|
+
if (caps.hooks.total > 0)
|
|
30
|
+
chips.push(`hooks ${caps.hooks.total}`);
|
|
31
|
+
if (caps.mcp.total > 0)
|
|
32
|
+
chips.push(`mcp ${caps.mcp.total}`);
|
|
33
|
+
if (caps.lsp.total > 0)
|
|
34
|
+
chips.push(`lsp ${caps.lsp.total}`);
|
|
35
|
+
if (caps.monitors.total > 0)
|
|
36
|
+
chips.push(`monitors ${caps.monitors.total}`);
|
|
37
|
+
if (caps.binCount > 0)
|
|
38
|
+
chips.push(`bin ${caps.binCount}`);
|
|
39
|
+
}
|
|
40
|
+
return chips.length > 0 ? ` ${DIM}[${chips.join(' · ')}]${RESET}` : '';
|
|
41
|
+
}
|
|
42
|
+
function pluginLine(entry) {
|
|
43
|
+
const state = entry.selection === 'disabled'
|
|
44
|
+
? `${DIM}disabled${RESET}`
|
|
45
|
+
: entry.selection === 'ambiguous'
|
|
46
|
+
? `${YELLOW}ambiguous${RESET}`
|
|
47
|
+
: 'active';
|
|
48
|
+
const tokens = entry.estAlwaysOnTokens !== null ? ` ${DIM}~${formatTokens(entry.estAlwaysOnTokens)} tok${RESET}` : '';
|
|
49
|
+
const native = entry.nativeErrors.length > 0 ? ` ${RED}load-error${RESET}` : '';
|
|
50
|
+
return ` ${BOLD}${entry.id}${RESET} ${DIM}v${entry.version} (${entry.scope})${RESET} ${state}${native}${tokens}${pluginChips(entry)}`;
|
|
51
|
+
}
|
|
52
|
+
function findingBlock(finding) {
|
|
53
|
+
const lines = [`${SEVERITY_TAG[finding.severity]} ${BOLD}${finding.title}${RESET}`];
|
|
54
|
+
lines.push(` ${finding.message}`);
|
|
55
|
+
if (finding.pluginIds.items.length > 0) {
|
|
56
|
+
const more = finding.pluginIds.omitted > 0 ? ` (+${finding.pluginIds.omitted} more)` : '';
|
|
57
|
+
lines.push(` ${DIM}plugins: ${finding.pluginIds.items.join(', ')}${more}${RESET}`);
|
|
58
|
+
}
|
|
59
|
+
if (finding.remediation) {
|
|
60
|
+
lines.push(` ${DIM}fix: ${finding.remediation}${RESET}`);
|
|
61
|
+
}
|
|
62
|
+
return lines;
|
|
63
|
+
}
|
|
64
|
+
function contextSummaryLine(context) {
|
|
65
|
+
const incomplete = context.summary.estimateComplete ? '' : ' (incomplete — lower bound)';
|
|
66
|
+
const est = context.summary.estimatedAlwaysOnTokens !== null
|
|
67
|
+
? ` · est. always-on ${CYAN}~${formatTokens(context.summary.estimatedAlwaysOnTokens)} tokens${RESET}${incomplete}`
|
|
68
|
+
: '';
|
|
69
|
+
return `${DIM}Active: ${context.summary.activePlugins} · Disabled: ${context.summary.disabledRecords} · Ambiguous: ${context.summary.ambiguousPlugins}${est}${RESET}`;
|
|
70
|
+
}
|
|
71
|
+
function pluginLines(context) {
|
|
72
|
+
const lines = context.plugins.items.map(pluginLine);
|
|
73
|
+
if (context.plugins.omitted > 0) {
|
|
74
|
+
lines.push(` ${DIM}… +${context.plugins.omitted} more plugin record(s) not shown${RESET}`);
|
|
75
|
+
}
|
|
76
|
+
return lines;
|
|
77
|
+
}
|
|
78
|
+
function findingLines(findings) {
|
|
79
|
+
const lines = findings.items.flatMap(findingBlock);
|
|
80
|
+
if (findings.omitted > 0) {
|
|
81
|
+
lines.push(`${DIM}… +${findings.omitted} more finding(s) not shown${RESET}`);
|
|
82
|
+
}
|
|
83
|
+
return lines;
|
|
84
|
+
}
|
|
85
|
+
export function renderHuman(report) {
|
|
86
|
+
const lines = [];
|
|
87
|
+
lines.push('');
|
|
88
|
+
lines.push(`${CYAN}${BOLD}ClaudePluginHub Doctor${RESET}`);
|
|
89
|
+
lines.push('');
|
|
90
|
+
lines.push(`Claude Code ${report.claude.version ?? '(version unknown)'}`);
|
|
91
|
+
const current = report.contexts.find((c) => c.isCurrent) ?? report.contexts[0];
|
|
92
|
+
const multiContext = report.contexts.length > 1;
|
|
93
|
+
if (current && !multiContext) {
|
|
94
|
+
lines.push(`Project: ${current.label}`);
|
|
95
|
+
lines.push(contextSummaryLine(current));
|
|
96
|
+
}
|
|
97
|
+
const { errors, warnings, notes } = report.summary;
|
|
98
|
+
lines.push('');
|
|
99
|
+
lines.push(`${errors > 0 ? RED : ''}${errors} error${errors === 1 ? '' : 's'}${errors > 0 ? RESET : ''} · ` +
|
|
100
|
+
`${warnings > 0 ? YELLOW : ''}${warnings} warning${warnings === 1 ? '' : 's'}${warnings > 0 ? RESET : ''} · ` +
|
|
101
|
+
`${notes} note${notes === 1 ? '' : 's'}`);
|
|
102
|
+
if (multiContext) {
|
|
103
|
+
// Global (installation-level) findings once, then one section per project.
|
|
104
|
+
if (report.findings.items.length > 0) {
|
|
105
|
+
lines.push('');
|
|
106
|
+
lines.push(...findingLines(report.findings));
|
|
107
|
+
}
|
|
108
|
+
for (const context of report.contexts) {
|
|
109
|
+
lines.push('');
|
|
110
|
+
lines.push(`${BOLD}— ${context.key} · ${context.label}${context.isCurrent ? ' (current)' : ''}${RESET}`);
|
|
111
|
+
lines.push(contextSummaryLine(context));
|
|
112
|
+
lines.push(...pluginLines(context));
|
|
113
|
+
lines.push(...findingLines(context.findings));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else if (current) {
|
|
117
|
+
if (current.plugins.items.length > 0) {
|
|
118
|
+
lines.push('');
|
|
119
|
+
lines.push(...pluginLines(current));
|
|
120
|
+
}
|
|
121
|
+
if (report.findings.items.length + current.findings.items.length > 0) {
|
|
122
|
+
lines.push('');
|
|
123
|
+
lines.push(...findingLines(report.findings));
|
|
124
|
+
lines.push(...findingLines(current.findings));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (report.unknownScopeRecords.total > 0) {
|
|
128
|
+
lines.push('');
|
|
129
|
+
lines.push(`${DIM}${report.unknownScopeRecords.total} record(s) with unrecognized scope were preserved but not analyzed.${RESET}`);
|
|
130
|
+
}
|
|
131
|
+
if (report.contextsOmitted > 0) {
|
|
132
|
+
lines.push('');
|
|
133
|
+
lines.push(`${DIM}${report.contextsOmitted} additional project(s) exceeded the context limit and were not analyzed.${RESET}`);
|
|
134
|
+
}
|
|
135
|
+
lines.push('');
|
|
136
|
+
lines.push(`${DIM}~ values are heuristic estimates (≈4 characters/token); \`claude plugin details\` is authoritative.${RESET}`);
|
|
137
|
+
if (report.summary.otherProjectRecordsIgnored > 0) {
|
|
138
|
+
lines.push(report.options.allProjects
|
|
139
|
+
? `${DIM}${report.summary.otherProjectRecordsIgnored} record(s) could not be attributed to an analyzable project and were ignored.${RESET}`
|
|
140
|
+
: `${DIM}${report.summary.otherProjectRecordsIgnored} record(s) belonging to other projects were ignored — use --all-projects to analyze them.${RESET}`);
|
|
141
|
+
}
|
|
142
|
+
if (report.scan.truncated) {
|
|
143
|
+
lines.push(`${DIM}Some scans hit resource limits — see scan_incomplete findings.${RESET}`);
|
|
144
|
+
}
|
|
145
|
+
lines.push('');
|
|
146
|
+
return lines.join('\n');
|
|
147
|
+
}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared report model for `claudepluginhub doctor`.
|
|
3
|
+
*
|
|
4
|
+
* schemaVersion 1. Every list that grows with plugin count passes through
|
|
5
|
+
* cappedList() so the JSON stays bounded at hundreds of plugins; ordering is
|
|
6
|
+
* deterministic (byte-order comparators, fixed severity/scope ranks) so two
|
|
7
|
+
* runs over identical state produce byte-identical output. The model never
|
|
8
|
+
* carries absolute paths, file contents, env/header values, URL paths, or
|
|
9
|
+
* command strings — see sanitize.ts.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DOCTOR_SCHEMA_VERSION = 1;
|
|
12
|
+
export type Severity = 'error' | 'warning' | 'info';
|
|
13
|
+
export type ScopeFilter = 'user' | 'project' | 'local' | 'all';
|
|
14
|
+
export type KnownScope = 'user' | 'project' | 'local' | 'managed';
|
|
15
|
+
export type RecordScope = KnownScope | 'unknown';
|
|
16
|
+
export interface DoctorFlags {
|
|
17
|
+
json: boolean;
|
|
18
|
+
strict: boolean;
|
|
19
|
+
scope: ScopeFilter;
|
|
20
|
+
allProjects: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Sanitized native error from a record's optional `errors` field.
|
|
24
|
+
* Observed shape (spike 2026-07-18, Claude Code 2.1.212): array of
|
|
25
|
+
* human-readable strings; a record can stay enabled:true with an unsatisfied
|
|
26
|
+
* dependency. Object-with-`code` elements are tolerated as an alternate/future
|
|
27
|
+
* shape. Raw messages are never stored.
|
|
28
|
+
*/
|
|
29
|
+
export interface NativePluginError {
|
|
30
|
+
/** 'dependency-missing', a validated code token, or 'unknown'. */
|
|
31
|
+
kind: string;
|
|
32
|
+
recognized: boolean;
|
|
33
|
+
/** Our canonical text — never the raw native message. */
|
|
34
|
+
summary: string;
|
|
35
|
+
/** Present only when extracted AND strictly validated as a plugin id. */
|
|
36
|
+
dependencyId?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface InstallationRecord {
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
marketplace: string;
|
|
42
|
+
version: string;
|
|
43
|
+
scope: RecordScope;
|
|
44
|
+
rawScope: string;
|
|
45
|
+
enabled: boolean;
|
|
46
|
+
installPath: string;
|
|
47
|
+
installPathCanonical: string | null;
|
|
48
|
+
/** Internal only — never serialized into the report. */
|
|
49
|
+
projectPathCanonical: string | null;
|
|
50
|
+
errors: NativePluginError[];
|
|
51
|
+
}
|
|
52
|
+
export interface ProjectContext {
|
|
53
|
+
key: string;
|
|
54
|
+
/** Basename — display only, never identity (basenames can collide). */
|
|
55
|
+
label: string;
|
|
56
|
+
isCurrent: boolean;
|
|
57
|
+
/** Internal only — never serialized into the report. */
|
|
58
|
+
canonicalPath: string;
|
|
59
|
+
}
|
|
60
|
+
export type Selection = 'sole' | 'ambiguous';
|
|
61
|
+
export interface EffectiveInstance {
|
|
62
|
+
contextKey: string;
|
|
63
|
+
id: string;
|
|
64
|
+
selection: Selection;
|
|
65
|
+
/** The selected record; null when ambiguous. */
|
|
66
|
+
record: InstallationRecord | null;
|
|
67
|
+
contenders: InstallationRecord[];
|
|
68
|
+
}
|
|
69
|
+
export type MdComponentType = 'skill' | 'command' | 'agent' | 'outputStyle';
|
|
70
|
+
export interface ComponentInfo {
|
|
71
|
+
type: MdComponentType;
|
|
72
|
+
relPath: string;
|
|
73
|
+
name: string | null;
|
|
74
|
+
description: string | null;
|
|
75
|
+
/** False when the bounded frontmatter reader could not understand the file. */
|
|
76
|
+
estimable: boolean;
|
|
77
|
+
nameDescChars: number;
|
|
78
|
+
bodyChars: number;
|
|
79
|
+
/** Normalized content hash — only for skill/command/agent. */
|
|
80
|
+
hash: string | null;
|
|
81
|
+
}
|
|
82
|
+
export type CommandForm = 'shell' | 'exec';
|
|
83
|
+
export interface CommandFact {
|
|
84
|
+
form: CommandForm;
|
|
85
|
+
/** Sanitized executable basename — see sanitize.ts. */
|
|
86
|
+
executable: string;
|
|
87
|
+
}
|
|
88
|
+
export interface HookFact {
|
|
89
|
+
event: string;
|
|
90
|
+
/** True only for the documented tool-matched events. */
|
|
91
|
+
toolMatched: boolean;
|
|
92
|
+
/** Matcher omitted / "" / "*" on a tool-matched event. */
|
|
93
|
+
broad: boolean;
|
|
94
|
+
/** Handler (or its entry) declares an `if` filter. */
|
|
95
|
+
conditional: boolean;
|
|
96
|
+
type: string;
|
|
97
|
+
command: CommandFact | null;
|
|
98
|
+
/** Origin-only URL for http hooks. */
|
|
99
|
+
targetOrigin: string | null;
|
|
100
|
+
}
|
|
101
|
+
export interface McpFact {
|
|
102
|
+
name: string;
|
|
103
|
+
kind: 'stdio' | 'remote' | 'unknown';
|
|
104
|
+
command: CommandFact | null;
|
|
105
|
+
targetOrigin: string | null;
|
|
106
|
+
/** Bounded at parse time; total/omitted describe the ORIGINAL key set. */
|
|
107
|
+
envKeys: CappedList<string>;
|
|
108
|
+
headerKeys: CappedList<string>;
|
|
109
|
+
/** null = prerequisite not checkable (env expansion / unresolvable form). */
|
|
110
|
+
commandFound: boolean | null;
|
|
111
|
+
}
|
|
112
|
+
export interface LspFact {
|
|
113
|
+
name: string;
|
|
114
|
+
command: CommandFact | null;
|
|
115
|
+
/** Bounded at parse time; total/omitted describe the ORIGINAL declaration. */
|
|
116
|
+
extensions: CappedList<string>;
|
|
117
|
+
languages: CappedList<string>;
|
|
118
|
+
commandFound: boolean | null;
|
|
119
|
+
}
|
|
120
|
+
export interface MonitorFact {
|
|
121
|
+
name: string | null;
|
|
122
|
+
when: string | null;
|
|
123
|
+
command: CommandFact | null;
|
|
124
|
+
}
|
|
125
|
+
export interface DependencyDecl {
|
|
126
|
+
name: string | null;
|
|
127
|
+
versionRange: string | null;
|
|
128
|
+
marketplace: string | null;
|
|
129
|
+
parseable: boolean;
|
|
130
|
+
}
|
|
131
|
+
export interface ManifestState {
|
|
132
|
+
present: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* True only when the manifest's content was actually read (and a parse was
|
|
135
|
+
* attempted). A manifest refused for containment or resource-limit reasons
|
|
136
|
+
* is present but NOT inspected — no content-derived claim (invalid JSON,
|
|
137
|
+
* invalid name, invalid fields, declared-missing) may be made about it.
|
|
138
|
+
*/
|
|
139
|
+
inspected: boolean;
|
|
140
|
+
parseError: boolean;
|
|
141
|
+
name: string | null;
|
|
142
|
+
nameInvalid: boolean;
|
|
143
|
+
/** Recognized fields carrying load-blocking wrong types. */
|
|
144
|
+
invalidFields: string[];
|
|
145
|
+
/** Explicitly declared paths that do not exist under the plugin root. */
|
|
146
|
+
declaredMissing: string[];
|
|
147
|
+
dependencies: DependencyDecl[];
|
|
148
|
+
}
|
|
149
|
+
export type PathIssue = 'missing' | 'unreadable' | 'not-directory';
|
|
150
|
+
export interface ScanResult {
|
|
151
|
+
pathIssue: PathIssue | null;
|
|
152
|
+
manifest: ManifestState;
|
|
153
|
+
components: ComponentInfo[];
|
|
154
|
+
themeFiles: string[];
|
|
155
|
+
hooks: HookFact[];
|
|
156
|
+
mcp: McpFact[];
|
|
157
|
+
lsp: LspFact[];
|
|
158
|
+
monitors: MonitorFact[];
|
|
159
|
+
bin: {
|
|
160
|
+
relPath: string;
|
|
161
|
+
executable: boolean;
|
|
162
|
+
}[];
|
|
163
|
+
/** Plugin-relative paths of JSON configs that could not be parsed. */
|
|
164
|
+
parseErrors: string[];
|
|
165
|
+
/** Plugin-relative paths of symlinks skipped (escape/cycle/unresolvable). */
|
|
166
|
+
symlinksSkipped: string[];
|
|
167
|
+
filesScanned: number;
|
|
168
|
+
bytesRead: number;
|
|
169
|
+
limitsHit: string[];
|
|
170
|
+
incomplete: boolean;
|
|
171
|
+
}
|
|
172
|
+
export interface CappedList<T> {
|
|
173
|
+
items: T[];
|
|
174
|
+
total: number;
|
|
175
|
+
omitted: number;
|
|
176
|
+
}
|
|
177
|
+
export interface Finding {
|
|
178
|
+
code: string;
|
|
179
|
+
severity: Severity;
|
|
180
|
+
title: string;
|
|
181
|
+
message: string;
|
|
182
|
+
pluginIds: CappedList<string>;
|
|
183
|
+
evidence?: Record<string, unknown>;
|
|
184
|
+
remediation?: string;
|
|
185
|
+
}
|
|
186
|
+
export interface ComponentTypeSummary {
|
|
187
|
+
count: number;
|
|
188
|
+
paths: CappedList<string>;
|
|
189
|
+
}
|
|
190
|
+
export interface PluginCapabilities {
|
|
191
|
+
hooks: {
|
|
192
|
+
total: number;
|
|
193
|
+
byEvent: CappedList<{
|
|
194
|
+
event: string;
|
|
195
|
+
count: number;
|
|
196
|
+
broad: number;
|
|
197
|
+
conditional: number;
|
|
198
|
+
}>;
|
|
199
|
+
};
|
|
200
|
+
mcp: CappedList<{
|
|
201
|
+
name: string;
|
|
202
|
+
kind: string;
|
|
203
|
+
executable: string | null;
|
|
204
|
+
targetOrigin: string | null;
|
|
205
|
+
envKeys: CappedList<string>;
|
|
206
|
+
headerKeys: CappedList<string>;
|
|
207
|
+
}>;
|
|
208
|
+
lsp: CappedList<{
|
|
209
|
+
name: string;
|
|
210
|
+
extensions: CappedList<string>;
|
|
211
|
+
languages: CappedList<string>;
|
|
212
|
+
}>;
|
|
213
|
+
monitors: CappedList<{
|
|
214
|
+
name: string | null;
|
|
215
|
+
when: string | null;
|
|
216
|
+
executable: string | null;
|
|
217
|
+
}>;
|
|
218
|
+
binCount: number;
|
|
219
|
+
}
|
|
220
|
+
export interface PluginEntry {
|
|
221
|
+
id: string;
|
|
222
|
+
version: string;
|
|
223
|
+
versionNote: string | null;
|
|
224
|
+
scope: RecordScope;
|
|
225
|
+
enabled: boolean;
|
|
226
|
+
selection: Selection | 'disabled';
|
|
227
|
+
nativeErrors: NativePluginError[];
|
|
228
|
+
components: Record<string, ComponentTypeSummary> | null;
|
|
229
|
+
capabilities: PluginCapabilities | null;
|
|
230
|
+
estAlwaysOnTokens: number | null;
|
|
231
|
+
estimated: boolean;
|
|
232
|
+
largestOnInvoke: {
|
|
233
|
+
path: string;
|
|
234
|
+
tokens: number;
|
|
235
|
+
}[];
|
|
236
|
+
inventoryIncomplete: boolean;
|
|
237
|
+
}
|
|
238
|
+
export interface ContextReport {
|
|
239
|
+
key: string;
|
|
240
|
+
label: string;
|
|
241
|
+
isCurrent: boolean;
|
|
242
|
+
plugins: CappedList<PluginEntry>;
|
|
243
|
+
findings: CappedList<Finding>;
|
|
244
|
+
summary: {
|
|
245
|
+
/** Unambiguous ('sole') effective instances only — ambiguous plugins are
|
|
246
|
+
* excluded from context totals and counted separately. */
|
|
247
|
+
activePlugins: number;
|
|
248
|
+
ambiguousPlugins: number;
|
|
249
|
+
disabledRecords: number;
|
|
250
|
+
estimatedAlwaysOnTokens: number | null;
|
|
251
|
+
/** False when any counted plugin's scan was incomplete, unestimable, or
|
|
252
|
+
* unreachable — the token total is then a lower bound, not a full sum. */
|
|
253
|
+
estimateComplete: boolean;
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
export interface DoctorReport {
|
|
257
|
+
schemaVersion: typeof DOCTOR_SCHEMA_VERSION;
|
|
258
|
+
claude: {
|
|
259
|
+
version: string | null;
|
|
260
|
+
};
|
|
261
|
+
options: {
|
|
262
|
+
scope: ScopeFilter;
|
|
263
|
+
allProjects: boolean;
|
|
264
|
+
strict: boolean;
|
|
265
|
+
};
|
|
266
|
+
contexts: ContextReport[];
|
|
267
|
+
/** Distinct project paths beyond MAX_CONTEXTS that were not analyzed. */
|
|
268
|
+
contextsOmitted: number;
|
|
269
|
+
findings: CappedList<Finding>;
|
|
270
|
+
unknownScopeRecords: CappedList<{
|
|
271
|
+
id: string;
|
|
272
|
+
rawScope: string;
|
|
273
|
+
enabled: boolean;
|
|
274
|
+
}>;
|
|
275
|
+
summary: {
|
|
276
|
+
errors: number;
|
|
277
|
+
warnings: number;
|
|
278
|
+
notes: number;
|
|
279
|
+
otherProjectRecordsIgnored: number;
|
|
280
|
+
};
|
|
281
|
+
scan: {
|
|
282
|
+
pluginsScanned: number;
|
|
283
|
+
filesScanned: number;
|
|
284
|
+
bytesRead: number;
|
|
285
|
+
truncated: boolean;
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
export declare const MAX_FINDINGS = 500;
|
|
289
|
+
export declare const MAX_PATHS_PER_TYPE = 50;
|
|
290
|
+
export declare const MAX_PLUGIN_IDS_PER_FINDING = 20;
|
|
291
|
+
export declare const MAX_EVIDENCE_ITEMS = 10;
|
|
292
|
+
export declare const MAX_EVIDENCE_STRING = 200;
|
|
293
|
+
export declare const MAX_MESSAGE_CHARS = 500;
|
|
294
|
+
export declare const MAX_CONTEXTS = 50;
|
|
295
|
+
export declare const MAX_PLUGINS_PER_CONTEXT = 200;
|
|
296
|
+
export declare const MAX_UNKNOWN_SCOPE_RECORDS = 50;
|
|
297
|
+
export declare const MAX_CAPABILITY_ITEMS = 25;
|
|
298
|
+
export declare function cappedList<T>(items: T[], cap: number): CappedList<T>;
|
|
299
|
+
/**
|
|
300
|
+
* Re-cap an already-capped list to a smaller display cap while PRESERVING the
|
|
301
|
+
* original collection's total — never re-derive total from the retained items.
|
|
302
|
+
*/
|
|
303
|
+
export declare function recapList<T>(list: CappedList<T>, cap: number): CappedList<T>;
|
|
304
|
+
export declare function boundEvidenceString(value: string): string;
|
|
305
|
+
export declare function boundMessage(value: string): string;
|
|
306
|
+
export declare function compareBytes(a: string, b: string): number;
|
|
307
|
+
export declare function compareFindings(a: Finding, b: Finding): number;
|
|
308
|
+
export declare function comparePluginEntries(a: Pick<PluginEntry, 'id' | 'scope' | 'version'>, b: Pick<PluginEntry, 'id' | 'scope' | 'version'>): number;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared report model for `claudepluginhub doctor`.
|
|
3
|
+
*
|
|
4
|
+
* schemaVersion 1. Every list that grows with plugin count passes through
|
|
5
|
+
* cappedList() so the JSON stays bounded at hundreds of plugins; ordering is
|
|
6
|
+
* deterministic (byte-order comparators, fixed severity/scope ranks) so two
|
|
7
|
+
* runs over identical state produce byte-identical output. The model never
|
|
8
|
+
* carries absolute paths, file contents, env/header values, URL paths, or
|
|
9
|
+
* command strings — see sanitize.ts.
|
|
10
|
+
*/
|
|
11
|
+
export const DOCTOR_SCHEMA_VERSION = 1;
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// Bounds & ordering
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
export const MAX_FINDINGS = 500;
|
|
16
|
+
export const MAX_PATHS_PER_TYPE = 50;
|
|
17
|
+
export const MAX_PLUGIN_IDS_PER_FINDING = 20;
|
|
18
|
+
export const MAX_EVIDENCE_ITEMS = 10;
|
|
19
|
+
export const MAX_EVIDENCE_STRING = 200;
|
|
20
|
+
export const MAX_MESSAGE_CHARS = 500;
|
|
21
|
+
export const MAX_CONTEXTS = 50;
|
|
22
|
+
export const MAX_PLUGINS_PER_CONTEXT = 200;
|
|
23
|
+
export const MAX_UNKNOWN_SCOPE_RECORDS = 50;
|
|
24
|
+
export const MAX_CAPABILITY_ITEMS = 25;
|
|
25
|
+
export function cappedList(items, cap) {
|
|
26
|
+
const total = items.length;
|
|
27
|
+
const kept = items.slice(0, cap);
|
|
28
|
+
return { items: kept, total, omitted: total - kept.length };
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Re-cap an already-capped list to a smaller display cap while PRESERVING the
|
|
32
|
+
* original collection's total — never re-derive total from the retained items.
|
|
33
|
+
*/
|
|
34
|
+
export function recapList(list, cap) {
|
|
35
|
+
const kept = list.items.slice(0, cap);
|
|
36
|
+
return { items: kept, total: list.total, omitted: list.total - kept.length };
|
|
37
|
+
}
|
|
38
|
+
function boundString(value, max) {
|
|
39
|
+
return value.length > max ? `${value.slice(0, max - 1)}…` : value;
|
|
40
|
+
}
|
|
41
|
+
export function boundEvidenceString(value) {
|
|
42
|
+
return boundString(value, MAX_EVIDENCE_STRING);
|
|
43
|
+
}
|
|
44
|
+
export function boundMessage(value) {
|
|
45
|
+
return boundString(value, MAX_MESSAGE_CHARS);
|
|
46
|
+
}
|
|
47
|
+
const SEVERITY_RANK = { error: 0, warning: 1, info: 2 };
|
|
48
|
+
const SCOPE_RANK = {
|
|
49
|
+
user: 0,
|
|
50
|
+
project: 1,
|
|
51
|
+
local: 2,
|
|
52
|
+
managed: 3,
|
|
53
|
+
unknown: 4,
|
|
54
|
+
};
|
|
55
|
+
export function compareBytes(a, b) {
|
|
56
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
57
|
+
}
|
|
58
|
+
export function compareFindings(a, b) {
|
|
59
|
+
return (SEVERITY_RANK[a.severity] - SEVERITY_RANK[b.severity] ||
|
|
60
|
+
compareBytes(a.code, b.code) ||
|
|
61
|
+
compareBytes(a.pluginIds.items[0] ?? '', b.pluginIds.items[0] ?? '') ||
|
|
62
|
+
compareBytes(a.message, b.message));
|
|
63
|
+
}
|
|
64
|
+
export function comparePluginEntries(a, b) {
|
|
65
|
+
return (compareBytes(a.id, b.id) ||
|
|
66
|
+
SCOPE_RANK[a.scope] - SCOPE_RANK[b.scope] ||
|
|
67
|
+
compareBytes(a.version, b.version));
|
|
68
|
+
}
|