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.
@@ -1,8 +1,12 @@
1
1
  import type { Finding, InstallationRecord, ScanResult } from './report.js';
2
2
  import type { SelectionOutput } from './select.js';
3
3
  /**
4
- * The single source of truth for finding codes and their severities. Rules
5
- * and renderers both key off this table, so severity policy cannot drift.
4
+ * The single source of truth for finding codes, severities, and categories.
5
+ * Rules and renderers both key off this table, so severity and category
6
+ * policy cannot drift.
7
+ *
8
+ * Category controls PRESENTATION tier (which output section a finding
9
+ * appears in). Severity controls exit codes and --strict behaviour.
6
10
  *
7
11
  * Facts vs findings: capability inventory (hooks exist, MCP servers exist,
8
12
  * env key names, monitors, estimates) lives on plugin entries as FIELDS. The
@@ -16,102 +20,132 @@ import type { SelectionOutput } from './select.js';
16
20
  export declare const FINDING_CODES: {
17
21
  readonly record_malformed: {
18
22
  readonly severity: "warning";
23
+ readonly category: "coverage";
19
24
  readonly title: "Malformed plugin list record";
20
25
  };
21
26
  readonly claude_plugin_load_error: {
22
27
  readonly severity: "error";
28
+ readonly category: "confirmed_problem";
23
29
  readonly title: "Claude Code reports a plugin load error";
24
30
  };
25
31
  readonly install_path_missing: {
26
32
  readonly severity: "error";
33
+ readonly category: "confirmed_problem";
27
34
  readonly title: "Install path does not exist";
28
35
  };
29
36
  readonly install_path_unreadable: {
30
37
  readonly severity: "error";
38
+ readonly category: "confirmed_problem";
31
39
  readonly title: "Install path is not readable";
32
40
  };
33
41
  readonly install_path_not_directory: {
34
42
  readonly severity: "error";
43
+ readonly category: "confirmed_problem";
35
44
  readonly title: "Install path is not a directory";
36
45
  };
37
46
  readonly disabled_record_issue: {
38
47
  readonly severity: "info";
48
+ readonly category: "maintenance";
39
49
  readonly title: "Disabled installation has stale or invalid content";
40
50
  };
41
51
  readonly duplicate_record: {
42
52
  readonly severity: "warning";
53
+ readonly category: "maintenance";
43
54
  readonly title: "Duplicate installation record";
44
55
  };
56
+ readonly redundant_enabled_records: {
57
+ readonly severity: "info";
58
+ readonly category: "maintenance";
59
+ readonly title: "Redundant enabled installation records";
60
+ };
45
61
  readonly duplicate_enabled_records: {
46
62
  readonly severity: "warning";
63
+ readonly category: "coverage";
47
64
  readonly title: "Multiple enabled installation records";
48
65
  };
49
66
  readonly effective_selection_ambiguous: {
50
67
  readonly severity: "warning";
68
+ readonly category: "coverage";
51
69
  readonly title: "Effective plugin selection is ambiguous";
52
70
  };
53
71
  readonly scope_unknown: {
54
72
  readonly severity: "info";
73
+ readonly category: "coverage";
55
74
  readonly title: "Unrecognized plugin scope";
56
75
  };
57
76
  readonly manifest_invalid_json: {
58
77
  readonly severity: "error";
78
+ readonly category: "confirmed_problem";
59
79
  readonly title: "Plugin manifest is not valid JSON";
60
80
  };
61
81
  readonly manifest_invalid_name: {
62
82
  readonly severity: "error";
83
+ readonly category: "confirmed_problem";
63
84
  readonly title: "Plugin manifest name is invalid";
64
85
  };
65
86
  readonly manifest_field_invalid: {
66
87
  readonly severity: "error";
88
+ readonly category: "confirmed_problem";
67
89
  readonly title: "Plugin manifest field has an invalid type";
68
90
  };
69
91
  readonly declared_component_missing: {
70
92
  readonly severity: "warning";
93
+ readonly category: "review";
71
94
  readonly title: "Manifest-declared component path is missing";
72
95
  };
73
96
  readonly component_parse_error: {
74
97
  readonly severity: "warning";
98
+ readonly category: "review";
75
99
  readonly title: "Component configuration could not be parsed";
76
100
  };
77
101
  readonly exact_component_overlap: {
78
102
  readonly severity: "warning";
103
+ readonly category: "review";
79
104
  readonly title: "Exact component content overlap";
80
105
  };
81
106
  readonly hook_broad_unconditional: {
82
107
  readonly severity: "warning";
108
+ readonly category: "review";
83
109
  readonly title: "Broad unconditional command hook";
84
110
  };
85
111
  readonly prerequisite_missing: {
86
112
  readonly severity: "warning";
113
+ readonly category: "review";
87
114
  readonly title: "Declared executable not found on PATH";
88
115
  };
89
116
  readonly bin_not_executable: {
90
117
  readonly severity: "warning";
118
+ readonly category: "review";
91
119
  readonly title: "bin/ file is not executable";
92
120
  };
93
121
  readonly dependency_missing: {
94
122
  readonly severity: "warning";
123
+ readonly category: "review";
95
124
  readonly title: "Declared plugin dependency is not installed";
96
125
  };
97
126
  readonly dependency_disabled: {
98
127
  readonly severity: "warning";
128
+ readonly category: "review";
99
129
  readonly title: "Declared plugin dependency is disabled";
100
130
  };
101
131
  readonly dependency_resolution_unknown: {
102
132
  readonly severity: "info";
133
+ readonly category: "coverage";
103
134
  readonly title: "Plugin dependency could not be verified";
104
135
  };
105
136
  readonly lsp_extension_conflict: {
106
137
  readonly severity: "warning";
138
+ readonly category: "review";
107
139
  readonly title: "Multiple LSP servers claim the same extension";
108
140
  };
109
141
  readonly scan_incomplete: {
110
142
  readonly severity: "warning";
143
+ readonly category: "coverage";
111
144
  readonly title: "Plugin scan hit a resource limit";
112
145
  };
113
146
  readonly symlink_skipped: {
114
147
  readonly severity: "warning";
148
+ readonly category: "coverage";
115
149
  readonly title: "Symlinks skipped during scan";
116
150
  };
117
151
  };
@@ -122,6 +156,9 @@ export interface AnalysisInput {
122
156
  /** Scan lookup by record (memoized per canonical root inside the scanner). */
123
157
  scanFor: (record: InstallationRecord) => ScanResult;
124
158
  droppedRecords: number;
159
+ /** Composite keys (id\0rawScope\0projectPath\0version) resolved as scan-equivalent —
160
+ * only the specific duplicate_record group matching that key is suppressed. */
161
+ scanEquivalentKeys: Set<string>;
125
162
  }
126
163
  export interface AnalysisOutput {
127
164
  global: Finding[];
Binary file
@@ -1,15 +1,6 @@
1
1
  import type { Scanner } from './inventory.js';
2
+ import type { BrowserOpener } from './open-browser.js';
2
3
  import type { DoctorFlags, DoctorReport, InstallationRecord } from './report.js';
3
- /**
4
- * Doctor orchestrator. Read-only by construction: the only child process is
5
- * the Claude CLI itself, and the only filesystem access is bounded reads
6
- * inside plugin install roots.
7
- *
8
- * Exit codes: 0 = completed without failing findings; 1 = completed but found
9
- * errors (or warnings under --strict); 2 = could not run / could not perform
10
- * the primary inventory (bad arguments, Claude CLI missing, unusable
11
- * `plugin list --json` output).
12
- */
13
4
  export interface DoctorRunInputs {
14
5
  records: InstallationRecord[];
15
6
  droppedRecords: number;
@@ -18,12 +9,16 @@ export interface DoctorRunInputs {
18
9
  flags: DoctorFlags;
19
10
  scanner: Scanner;
20
11
  }
12
+ export interface DoctorRunDeps {
13
+ opener?: BrowserOpener;
14
+ }
15
+ export interface OpenReportResult {
16
+ path: string;
17
+ opened: boolean;
18
+ }
19
+ /** Write HTML to a file with exclusive-create (EEXIST if path already exists). */
20
+ export declare function writeReportFile(filePath: string, html: string): void;
21
+ export declare function openReport(report: DoctorReport, opener: BrowserOpener): Promise<OpenReportResult>;
21
22
  export declare function buildDoctorReport(inputs: DoctorRunInputs): DoctorReport;
22
23
  export declare function exitCodeFor(report: DoctorReport, strict: boolean): number;
23
- /**
24
- * Exit via process.exitCode, never process.exit(): a forced exit tears the
25
- * process down before a large report piped to a slow consumer has drained,
26
- * truncating stdout mid-document. Setting exitCode lets Node flush stdout
27
- * naturally and then exit on its own.
28
- */
29
- export declare function runDoctor(argv: string[]): Promise<void>;
24
+ export declare function runDoctor(argv: string[], deps?: DoctorRunDeps): Promise<void>;
@@ -1,12 +1,30 @@
1
+ import { mkdtempSync, writeFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { tmpdir } from 'node:os';
1
4
  import { DOCTOR_HELP, parseDoctorFlags } from './args.js';
2
5
  import { probeClaude } from './claude-source.js';
3
6
  import { canonicalize } from './paths.js';
4
7
  import { selectEffective } from './select.js';
8
+ import { resolveEquivalences } from './equivalence.js';
5
9
  import { createScanner } from './inventory.js';
6
10
  import { analyze } from './rules.js';
7
11
  import { estimatePlugin } from './estimate.js';
8
12
  import { renderHuman, renderJson } from './render.js';
9
- import { boundEvidenceString, cappedList, recapList, comparePluginEntries, DOCTOR_SCHEMA_VERSION, MAX_CAPABILITY_ITEMS, MAX_EVIDENCE_ITEMS, MAX_FINDINGS, MAX_PATHS_PER_TYPE, MAX_PLUGINS_PER_CONTEXT, MAX_UNKNOWN_SCOPE_RECORDS, } from './report.js';
13
+ import { renderHtml } from './html-report.js';
14
+ import { defaultOpener } from './open-browser.js';
15
+ import { boundEvidenceString, cappedList, recapList, comparePluginEntries, DOCTOR_SCHEMA_VERSION, MAX_CAPABILITY_ITEMS, MAX_EFFECTIVE_PLUGINS_PER_CONTEXT, MAX_EVIDENCE_ITEMS, MAX_FINDINGS, MAX_PATHS_PER_TYPE, MAX_PLUGINS_PER_CONTEXT, MAX_TOP_CONTRIBUTORS, MAX_UNKNOWN_SCOPE_RECORDS, } from './report.js';
16
+ /** Write HTML to a file with exclusive-create (EEXIST if path already exists). */
17
+ export function writeReportFile(filePath, html) {
18
+ writeFileSync(filePath, html, { flag: 'wx', mode: 0o600 });
19
+ }
20
+ export async function openReport(report, opener) {
21
+ const html = renderHtml(report);
22
+ const tmpDir = mkdtempSync(join(tmpdir(), 'cph-doctor-'));
23
+ const reportPath = join(tmpDir, 'report.html');
24
+ writeReportFile(reportPath, html);
25
+ const opened = await opener.open(reportPath);
26
+ return { path: reportPath, opened };
27
+ }
10
28
  const VERSION_UNKNOWN_NOTE = 'Version "unknown" is documented-legitimate (npm sources or local directories outside a git repository).';
11
29
  function componentSummaries(scan) {
12
30
  const byType = {
@@ -92,6 +110,50 @@ function makeEntry(record, selection, scan) {
92
110
  inventoryIncomplete: scan.incomplete,
93
111
  };
94
112
  }
113
+ function buildEffectivePlugins(contextSelection, scanFor) {
114
+ return contextSelection.instances.map((instance) => {
115
+ const record = instance.record;
116
+ const scan = record ? scanFor(record) : null;
117
+ const scanned = scan && scan.pathIssue === null;
118
+ const estimate = instance.selection === 'sole' && scanned ? estimatePlugin(scan) : null;
119
+ const allScopes = cappedList([...new Set(instance.contenders.map((r) => r.scope))].sort(), MAX_CAPABILITY_ITEMS);
120
+ const allVersions = cappedList([...new Set(instance.contenders.map((r) => r.version))].sort(), MAX_CAPABILITY_ITEMS);
121
+ const isAmbiguous = instance.selection === 'ambiguous';
122
+ return {
123
+ id: instance.id,
124
+ selection: instance.selection,
125
+ reason: instance.reason,
126
+ recordCount: instance.contenders.length,
127
+ scopes: allScopes,
128
+ versions: allVersions,
129
+ estAlwaysOnTokens: estimate ? estimate.alwaysOnTokens : null,
130
+ estimated: estimate ? estimate.estimated : false,
131
+ inventoryIncomplete: isAmbiguous ? false : (scan ? scan.incomplete : false),
132
+ components: scanned ? componentSummaries(scan) : null,
133
+ capabilities: scanned ? capabilities(scan) : null,
134
+ largestOnInvoke: estimate ? estimate.largestOnInvoke : [],
135
+ };
136
+ });
137
+ }
138
+ function buildContributors(effectivePlugins) {
139
+ const sole = effectivePlugins.filter((ep) => ep.selection === 'sole' && ep.estAlwaysOnTokens !== null);
140
+ if (sole.length === 0)
141
+ return null;
142
+ const sorted = [...sole].sort((a, b) => (b.estAlwaysOnTokens ?? 0) - (a.estAlwaysOnTokens ?? 0));
143
+ const top = sorted.slice(0, MAX_TOP_CONTRIBUTORS).map((ep) => ({
144
+ id: ep.id,
145
+ tokens: ep.estAlwaysOnTokens ?? 0,
146
+ }));
147
+ const remaining = sorted.slice(MAX_TOP_CONTRIBUTORS);
148
+ return {
149
+ top,
150
+ remainingCount: remaining.length,
151
+ remainingTokens: remaining.reduce((sum, ep) => sum + (ep.estAlwaysOnTokens ?? 0), 0),
152
+ };
153
+ }
154
+ function countCategory(findings, category) {
155
+ return findings.filter((f) => f.category === category).length;
156
+ }
95
157
  function buildContextReport(contextSelection, findings, scanFor) {
96
158
  const { context, applicable, disabled, instances } = contextSelection;
97
159
  const selectionByRecord = new Map();
@@ -100,8 +162,6 @@ function buildContextReport(contextSelection, findings, scanFor) {
100
162
  selectionByRecord.set(contender, instance.selection);
101
163
  }
102
164
  }
103
- // Sort and cap FIRST, then build entries — a hostile record list must not
104
- // cost one PluginEntry (and one scan lookup) per record beyond the cap.
105
165
  const listedRecords = [...applicable].sort(comparePluginEntries);
106
166
  const keptRecords = listedRecords.slice(0, MAX_PLUGINS_PER_CONTEXT);
107
167
  const plugins = {
@@ -109,9 +169,9 @@ function buildContextReport(contextSelection, findings, scanFor) {
109
169
  total: listedRecords.length,
110
170
  omitted: listedRecords.length - keptRecords.length,
111
171
  };
112
- // Context totals count only unambiguous instances (the ambiguity findings
113
- // say exactly that); the aggregate estimate is honest about coverage — an
114
- // unreachable, incomplete, or unestimable scan makes it a lower bound.
172
+ const allEffective = buildEffectivePlugins(contextSelection, scanFor);
173
+ const effectivePlugins = cappedList(allEffective, MAX_EFFECTIVE_PLUGINS_PER_CONTEXT);
174
+ const contributors = buildContributors(allEffective);
115
175
  const soleInstances = instances.filter((i) => i.selection === 'sole' && i.record !== null);
116
176
  let estimatedAlwaysOnTokens = null;
117
177
  let estimateComplete = true;
@@ -135,6 +195,8 @@ function buildContextReport(contextSelection, findings, scanFor) {
135
195
  label: context.label,
136
196
  isCurrent: context.isCurrent,
137
197
  plugins,
198
+ effectivePlugins,
199
+ contributors,
138
200
  findings: cappedList(findings, MAX_FINDINGS),
139
201
  summary: {
140
202
  activePlugins: soleInstances.length,
@@ -142,12 +204,16 @@ function buildContextReport(contextSelection, findings, scanFor) {
142
204
  disabledRecords: disabled.length,
143
205
  estimatedAlwaysOnTokens,
144
206
  estimateComplete,
207
+ confirmedProblems: countCategory(findings, 'confirmed_problem'),
208
+ reviewItems: countCategory(findings, 'review'),
209
+ coverageGaps: countCategory(findings, 'coverage'),
210
+ maintenanceNotes: countCategory(findings, 'maintenance'),
145
211
  },
146
212
  };
147
213
  }
148
214
  export function buildDoctorReport(inputs) {
149
215
  const { records, droppedRecords, claudeVersion, cwdCanonical, flags, scanner } = inputs;
150
- const selection = selectEffective(records, cwdCanonical, flags);
216
+ const baseSelection = selectEffective(records, cwdCanonical, flags);
151
217
  const scanCache = new Map();
152
218
  const scanFor = (record) => {
153
219
  const cached = scanCache.get(record);
@@ -157,13 +223,18 @@ export function buildDoctorReport(inputs) {
157
223
  scanCache.set(record, scan);
158
224
  return scan;
159
225
  };
160
- const analysis = analyze({ selection, scanFor, droppedRecords });
226
+ const { resolved: selection, scanEquivalentKeys } = resolveEquivalences(baseSelection, scanFor);
227
+ const analysis = analyze({ selection, scanFor, droppedRecords, scanEquivalentKeys });
161
228
  const contexts = selection.contexts.map((contextSelection) => buildContextReport(contextSelection, analysis.byContext.get(contextSelection.context.key) ?? [], scanFor));
162
229
  const allFindings = [...analysis.global, ...[...analysis.byContext.values()].flat()];
163
230
  const summary = {
164
231
  errors: allFindings.filter((f) => f.severity === 'error').length,
165
232
  warnings: allFindings.filter((f) => f.severity === 'warning').length,
166
233
  notes: allFindings.filter((f) => f.severity === 'info').length,
234
+ confirmedProblems: countCategory(allFindings, 'confirmed_problem'),
235
+ reviewItems: countCategory(allFindings, 'review'),
236
+ coverageGaps: countCategory(allFindings, 'coverage'),
237
+ maintenanceNotes: countCategory(allFindings, 'maintenance'),
167
238
  otherProjectRecordsIgnored: selection.otherProjectRecords.length,
168
239
  };
169
240
  const stats = scanner.stats();
@@ -188,13 +259,7 @@ export function exitCodeFor(report, strict) {
188
259
  return 1;
189
260
  return 0;
190
261
  }
191
- /**
192
- * Exit via process.exitCode, never process.exit(): a forced exit tears the
193
- * process down before a large report piped to a slow consumer has drained,
194
- * truncating stdout mid-document. Setting exitCode lets Node flush stdout
195
- * naturally and then exit on its own.
196
- */
197
- export async function runDoctor(argv) {
262
+ export async function runDoctor(argv, deps) {
198
263
  const parsed = parseDoctorFlags(argv);
199
264
  if (parsed.kind === 'error') {
200
265
  process.stderr.write(`Error: ${parsed.message}\nRun \`npx claudepluginhub doctor --help\` for usage.\n`);
@@ -230,6 +295,21 @@ export async function runDoctor(argv) {
230
295
  process.exitCode = 2;
231
296
  return;
232
297
  }
233
- process.stdout.write(flags.json ? renderJson(report) : renderHuman(report));
298
+ if (flags.open) {
299
+ try {
300
+ const opener = deps?.opener ?? defaultOpener();
301
+ const result = await openReport(report, opener);
302
+ if (!result.opened) {
303
+ process.stderr.write(`Could not open a browser. Report saved to: ${result.path}\n`);
304
+ }
305
+ else if (flags.verbose) {
306
+ process.stderr.write(`Report saved to: ${result.path}\n`);
307
+ }
308
+ }
309
+ catch (err) {
310
+ process.stderr.write(`Warning: could not generate local report: ${err.message}\n`);
311
+ }
312
+ }
313
+ process.stdout.write(flags.json ? renderJson(report) : renderHuman(report, flags));
234
314
  process.exitCode = exitCodeFor(report, flags.strict);
235
315
  }
Binary file
@@ -0,0 +1,2 @@
1
+ export declare function terminalWidth(): number;
2
+ export declare function wrapText(text: string, width: number, indent: number, firstIndent?: number): string;
@@ -0,0 +1,84 @@
1
+ export function terminalWidth() {
2
+ const cols = process.stdout.columns;
3
+ if (!cols)
4
+ return 100;
5
+ return Math.max(72, Math.min(120, cols));
6
+ }
7
+ export function wrapText(text, width, indent, firstIndent) {
8
+ const prefix = " ".repeat(indent);
9
+ const firstPrefix = firstIndent != null ? " ".repeat(firstIndent) : "";
10
+ const lines = text.split("\n");
11
+ const result = [];
12
+ for (const line of lines) {
13
+ const words = line.split(" ").filter((w) => w.length > 0);
14
+ if (words.length === 0) {
15
+ result.push("");
16
+ continue;
17
+ }
18
+ let current = "";
19
+ let isFirstLine = true;
20
+ for (const word of words) {
21
+ const pfx = isFirstLine ? firstPrefix : prefix;
22
+ if (current.length === 0) {
23
+ // Hard-wrap tokens longer than available content width
24
+ if (pfx.length + word.length > width) {
25
+ let remaining = word;
26
+ while (remaining.length > 0) {
27
+ const p = current.length === 0 ? pfx : prefix;
28
+ const available = width - p.length;
29
+ if (available <= 0) {
30
+ result.push(p + remaining);
31
+ remaining = "";
32
+ }
33
+ else if (remaining.length <= available) {
34
+ current = p + remaining;
35
+ remaining = "";
36
+ }
37
+ else {
38
+ result.push(p + remaining.slice(0, available));
39
+ remaining = remaining.slice(available);
40
+ isFirstLine = false;
41
+ }
42
+ }
43
+ }
44
+ else {
45
+ current = pfx + word;
46
+ }
47
+ }
48
+ else if (current.length + 1 + word.length <= width) {
49
+ current = current + " " + word;
50
+ }
51
+ else {
52
+ result.push(current);
53
+ isFirstLine = false;
54
+ // The new word might itself be too long for the continuation
55
+ if (prefix.length + word.length > width) {
56
+ let remaining = word;
57
+ current = "";
58
+ while (remaining.length > 0) {
59
+ const available = width - prefix.length;
60
+ if (available <= 0) {
61
+ result.push(prefix + remaining);
62
+ remaining = "";
63
+ }
64
+ else if (remaining.length <= available) {
65
+ current = prefix + remaining;
66
+ remaining = "";
67
+ }
68
+ else {
69
+ result.push(prefix + remaining.slice(0, available));
70
+ remaining = remaining.slice(available);
71
+ }
72
+ }
73
+ }
74
+ else {
75
+ current = prefix + word;
76
+ }
77
+ }
78
+ }
79
+ if (current.length > 0) {
80
+ result.push(current);
81
+ }
82
+ }
83
+ return result.join("\n");
84
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claudepluginhub",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Install Claude Code components from ClaudePluginHub",
5
5
  "bin": {
6
6
  "claudepluginhub": "dist/index.js"