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.
@@ -0,0 +1,385 @@
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 { formatApproxTokens } from './estimate.js';
8
+ // ---------------------------------------------------------------------------
9
+ // Escaping
10
+ // ---------------------------------------------------------------------------
11
+ export function escapeHtml(s) {
12
+ return s
13
+ .replace(/&/g, '&amp;')
14
+ .replace(/</g, '&lt;')
15
+ .replace(/>/g, '&gt;')
16
+ .replace(/"/g, '&quot;')
17
+ .replace(/'/g, '&#39;');
18
+ }
19
+ // ---------------------------------------------------------------------------
20
+ // Helpers
21
+ // ---------------------------------------------------------------------------
22
+ function severityBadge(s) {
23
+ const cls = s === 'error' ? 'badge-error' : s === 'warning' ? 'badge-warning' : 'badge-info';
24
+ const label = s === 'error' ? 'ERROR' : s === 'warning' ? 'WARN' : 'INFO';
25
+ return `<span class="badge ${escapeHtml(cls)}">${label}</span>`;
26
+ }
27
+ function cappedNote(list) {
28
+ return list.omitted > 0 ? `<span class="dim"> (+${list.omitted} more)</span>` : '';
29
+ }
30
+ function renderFinding(f) {
31
+ const pluginList = f.pluginIds.items.length > 0
32
+ ? `<div class="finding-plugins">Affects: ${f.pluginIds.items
33
+ .map((id) => `<code>${escapeHtml(id)}</code>`)
34
+ .join(', ')}${cappedNote(f.pluginIds)}</div>`
35
+ : '';
36
+ const remediation = f.remediation
37
+ ? `<div class="finding-remediation"><strong>Remediation:</strong> ${escapeHtml(f.remediation)}</div>`
38
+ : '';
39
+ return `<div class="finding-card">
40
+ <div class="finding-header">${severityBadge(f.severity)} <span class="finding-title">${escapeHtml(f.title)}</span> <code class="finding-code">${escapeHtml(f.code)}</code></div>
41
+ <div class="finding-message">${escapeHtml(f.message)}</div>
42
+ ${pluginList}${remediation}
43
+ </div>`;
44
+ }
45
+ function capsSummary(caps) {
46
+ const parts = [];
47
+ if (caps.hooks.total > 0)
48
+ parts.push(`hooks: ${caps.hooks.total}`);
49
+ if (caps.mcp.total > 0)
50
+ parts.push(`mcp: ${caps.mcp.total}`);
51
+ if (caps.lsp.total > 0)
52
+ parts.push(`lsp: ${caps.lsp.total}`);
53
+ if (caps.monitors.total > 0)
54
+ parts.push(`monitors: ${caps.monitors.total}`);
55
+ if (caps.binCount > 0)
56
+ parts.push(`bin: ${caps.binCount}`);
57
+ return parts.length > 0 ? parts.join(', ') : 'none';
58
+ }
59
+ function renderEffectivePlugin(ep) {
60
+ const tokenStr = ep.estAlwaysOnTokens != null ? formatApproxTokens(ep.estAlwaysOnTokens) + ' tok' : 'n/a';
61
+ const estimateNote = !ep.estimated ? ' <span class="dim">(incomplete estimate)</span>' : '';
62
+ const incompleteNote = ep.selection === 'ambiguous'
63
+ ? ' <span class="dim">(active copy unresolved)</span>'
64
+ : ep.inventoryIncomplete
65
+ ? ' <span class="dim">(scan incomplete)</span>'
66
+ : '';
67
+ const compRows = ep.components
68
+ ? Object.entries(ep.components)
69
+ .filter(([, v]) => v.count > 0)
70
+ .map(([type, v]) => `<li><strong>${escapeHtml(type)}</strong>: ${v.count}${v.paths.items.length > 0 ? ` (${v.paths.items.map((p) => `<code>${escapeHtml(p)}</code>`).join(', ')}${cappedNote(v.paths)})` : ''}</li>`)
71
+ .join('\n')
72
+ : '';
73
+ const capsRow = ep.capabilities
74
+ ? `<li><strong>Capabilities:</strong> ${escapeHtml(capsSummary(ep.capabilities))}</li>`
75
+ : '';
76
+ const invokeRows = ep.largestOnInvoke.length > 0
77
+ ? `<li><strong>Largest on-invoke:</strong> ${ep.largestOnInvoke.map((l) => `<code>${escapeHtml(l.path)}</code> ${formatApproxTokens(l.tokens)} tok`).join(', ')}</li>`
78
+ : '';
79
+ return `<details class="plugin-detail">
80
+ <summary><code class="plugin-id">${escapeHtml(ep.id)}</code> <span class="dim">${escapeHtml(tokenStr)}${estimateNote}${incompleteNote}</span></summary>
81
+ <ul class="plugin-facts">
82
+ <li><strong>Status:</strong> ${ep.selection === 'ambiguous' ? 'active copy unresolved' : escapeHtml(ep.reason === 'scan_equivalent' ? 'active (equivalent records)' : 'active')}</li>
83
+ <li><strong>Records:</strong> ${ep.recordCount} &mdash; scopes: ${ep.scopes.items.map((s) => escapeHtml(s)).join(', ')}${ep.scopes.omitted > 0 ? ` (+${ep.scopes.omitted} more)` : ''} &mdash; versions: ${ep.versions.items.map((v) => `<code>${escapeHtml(v)}</code>`).join(', ')}${ep.versions.omitted > 0 ? ` (+${ep.versions.omitted} more)` : ''}</li>
84
+ ${compRows}${capsRow}${invokeRows}
85
+ </ul>
86
+ </details>`;
87
+ }
88
+ function renderContextFootprint(ctx, multiContext) {
89
+ const heading = multiContext
90
+ ? `${escapeHtml(ctx.key)} &middot; ${escapeHtml(ctx.label)}`
91
+ : escapeHtml(ctx.label);
92
+ const label = heading + (ctx.isCurrent ? ' <span class="badge badge-info">current</span>' : '');
93
+ const totalTok = ctx.summary.estimatedAlwaysOnTokens != null
94
+ ? formatApproxTokens(ctx.summary.estimatedAlwaysOnTokens) + ' tok always-on'
95
+ : 'estimate unavailable';
96
+ const completeNote = !ctx.summary.estimateComplete ? ' (incomplete)' : '';
97
+ let barChart = '';
98
+ if (ctx.contributors && ctx.contributors.top.length > 0) {
99
+ const maxTok = ctx.contributors.top[0]?.tokens ?? 1;
100
+ const bars = ctx.contributors.top
101
+ .map((c) => {
102
+ const pct = maxTok > 0 ? Math.max(2, Math.round((c.tokens / maxTok) * 100)) : 2;
103
+ return `<div class="bar-row"><code class="bar-label">${escapeHtml(c.id)}</code><div class="bar-track"><div class="bar-fill" style="width:${pct}%"></div></div><span class="bar-value">${formatApproxTokens(c.tokens)}</span></div>`;
104
+ })
105
+ .join('\n');
106
+ const remainder = ctx.contributors.remainingCount > 0
107
+ ? `<div class="dim bar-remainder">+${ctx.contributors.remainingCount} more with ${formatApproxTokens(ctx.contributors.remainingTokens)} tok combined</div>`
108
+ : '';
109
+ barChart = `<div class="bar-chart">${bars}${remainder}</div>`;
110
+ }
111
+ return `<div class="context-block">
112
+ <h3>${label}</h3>
113
+ <p>${escapeHtml(totalTok)}${escapeHtml(completeNote)} &mdash; ${ctx.summary.activePlugins} active plugin${ctx.summary.activePlugins !== 1 ? 's' : ''}</p>
114
+ ${barChart}
115
+ </div>`;
116
+ }
117
+ function renderOmissions(report) {
118
+ const parts = [];
119
+ const multiContext = report.contexts.length > 1;
120
+ const findingsOmitted = report.findings.omitted +
121
+ report.contexts.reduce((sum, c) => sum + c.findings.omitted, 0);
122
+ if (findingsOmitted > 0) {
123
+ parts.push(`<p class="dim">${findingsOmitted} additional finding(s) not shown (report capped).</p>`);
124
+ }
125
+ if (report.contextsOmitted > 0) {
126
+ parts.push(`<p class="dim">${report.contextsOmitted} additional project context(s) were not analyzed.</p>`);
127
+ }
128
+ for (const ctx of report.contexts) {
129
+ const ctxName = multiContext
130
+ ? `${escapeHtml(ctx.key)} &middot; ${escapeHtml(ctx.label)}`
131
+ : escapeHtml(ctx.label);
132
+ if (ctx.effectivePlugins.omitted > 0) {
133
+ parts.push(`<p class="dim">${ctx.effectivePlugins.omitted} additional plugin(s) in ${ctxName} not shown.</p>`);
134
+ }
135
+ if (ctx.plugins.omitted > 0) {
136
+ parts.push(`<p class="dim">${ctx.plugins.omitted} inventory record(s) in ${ctxName} not shown.</p>`);
137
+ }
138
+ }
139
+ return parts.length > 0 ? `<div class="omissions">${parts.join('\n')}</div>` : '';
140
+ }
141
+ // ---------------------------------------------------------------------------
142
+ // Verdict
143
+ // ---------------------------------------------------------------------------
144
+ function renderVerdict(report) {
145
+ const { confirmedProblems, reviewItems, coverageGaps } = report.summary;
146
+ const actionableCount = confirmedProblems + reviewItems;
147
+ if (actionableCount > 0) {
148
+ const cls = confirmedProblems > 0 ? 'verdict-fail' : 'verdict-warn';
149
+ const parts = [];
150
+ if (confirmedProblems > 0)
151
+ parts.push(`${confirmedProblems} confirmed problem${confirmedProblems !== 1 ? 's' : ''}`);
152
+ if (reviewItems > 0)
153
+ parts.push(`${reviewItems} review item${reviewItems !== 1 ? 's' : ''}`);
154
+ return `<div class="verdict ${cls}">${parts.join(', ')}</div>`;
155
+ }
156
+ if (coverageGaps > 0) {
157
+ return `<div class="verdict verdict-warn">Doctor could not fully verify ${coverageGaps} item${coverageGaps !== 1 ? 's' : ''}.</div>`;
158
+ }
159
+ return `<div class="verdict verdict-pass">No broken plugins found.</div>`;
160
+ }
161
+ // ---------------------------------------------------------------------------
162
+ // CSS
163
+ // ---------------------------------------------------------------------------
164
+ const CSS = `
165
+ :root {
166
+ --bg: #fff; --fg: #1a1a1a; --muted: #666; --border: #e0e0e0;
167
+ --card-bg: #fafafa; --code-bg: #f0f0f0;
168
+ --green: #16a34a; --red: #dc2626; --amber: #d97706; --blue: #2563eb;
169
+ --bar-fill: #6366f1;
170
+ }
171
+ @media (prefers-color-scheme: dark) {
172
+ :root {
173
+ --bg: #111; --fg: #e5e5e5; --muted: #999; --border: #333;
174
+ --card-bg: #1a1a1a; --code-bg: #252525;
175
+ --green: #4ade80; --red: #f87171; --amber: #fbbf24; --blue: #60a5fa;
176
+ --bar-fill: #818cf8;
177
+ }
178
+ }
179
+ *, *::before, *::after { box-sizing: border-box; }
180
+ body { margin: 0; padding: 2rem 1rem; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--fg); line-height: 1.6; overflow-wrap: break-word; word-break: break-word; }
181
+ .container { max-width: 52rem; margin: 0 auto; }
182
+ h1 { font-size: 1.5rem; margin: 0 0 0.25rem; }
183
+ h2 { font-size: 1.2rem; margin: 2rem 0 0.75rem; border-bottom: 1px solid var(--border); padding-bottom: 0.25rem; }
184
+ h3 { font-size: 1rem; margin: 0.5rem 0 0.25rem; }
185
+ code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.875em; background: var(--code-bg); padding: 0.1em 0.35em; border-radius: 3px; }
186
+ .dim { color: var(--muted); }
187
+ .header-meta { color: var(--muted); font-size: 0.875rem; margin-bottom: 1.5rem; }
188
+
189
+ .verdict { padding: 0.75rem 1rem; border-radius: 6px; font-weight: 600; margin-bottom: 1.5rem; }
190
+ .verdict-pass { background: color-mix(in srgb, var(--green) 12%, transparent); color: var(--green); }
191
+ .verdict-fail { background: color-mix(in srgb, var(--red) 12%, transparent); color: var(--red); }
192
+ .verdict-warn { background: color-mix(in srgb, var(--amber) 12%, transparent); color: var(--amber); }
193
+
194
+ .badge { display: inline-block; font-size: 0.7rem; font-weight: 700; padding: 0.1em 0.5em; border-radius: 3px; text-transform: uppercase; vertical-align: middle; }
195
+ .badge-error { background: var(--red); color: #fff; }
196
+ .badge-warning { background: var(--amber); color: #000; }
197
+ .badge-info { background: var(--blue); color: #fff; }
198
+
199
+ .finding-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 6px; padding: 0.75rem 1rem; margin-bottom: 0.75rem; }
200
+ .finding-header { margin-bottom: 0.35rem; }
201
+ .finding-title { font-weight: 600; }
202
+ .finding-code { font-size: 0.75rem; color: var(--muted); margin-left: 0.5rem; }
203
+ .finding-message { margin-bottom: 0.35rem; }
204
+ .finding-plugins { font-size: 0.875rem; margin-bottom: 0.25rem; }
205
+ .finding-remediation { font-size: 0.875rem; color: var(--muted); }
206
+
207
+ .context-block { margin-bottom: 1.25rem; }
208
+ .bar-chart { margin: 0.5rem 0; }
209
+ .bar-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.3rem; }
210
+ .bar-label { flex: 0 0 auto; max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.8rem; }
211
+ .bar-track { flex: 1 1 auto; height: 0.6rem; background: var(--border); border-radius: 3px; overflow: hidden; }
212
+ .bar-fill { height: 100%; background: var(--bar-fill); border-radius: 3px; min-width: 2%; }
213
+ .bar-value { flex: 0 0 auto; font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
214
+ .bar-remainder { font-size: 0.8rem; margin-top: 0.15rem; }
215
+
216
+ details.plugin-detail { margin-bottom: 0.5rem; }
217
+ details.plugin-detail > summary { cursor: pointer; padding: 0.35rem 0; }
218
+ details.plugin-detail > summary:hover { color: var(--blue); }
219
+ .plugin-id { font-weight: 600; }
220
+ .plugin-facts { margin: 0.25rem 0 0.5rem 1.25rem; font-size: 0.875rem; }
221
+ .plugin-facts li { margin-bottom: 0.2rem; }
222
+
223
+ .footer { margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--border); font-size: 0.8rem; color: var(--muted); }
224
+
225
+ @media print {
226
+ details > *:not(summary) { display: block !important; }
227
+ .verdict { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
228
+ .badge { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
229
+ }
230
+
231
+ @media (max-width: 600px) {
232
+ body { padding: 1rem 0.5rem; }
233
+ .bar-label { max-width: 8rem; }
234
+ }
235
+ `;
236
+ // ---------------------------------------------------------------------------
237
+ // Main renderer
238
+ // ---------------------------------------------------------------------------
239
+ export function renderHtml(report) {
240
+ const version = report.claude.version ? `v${escapeHtml(report.claude.version)}` : 'unknown';
241
+ const scopeLabel = escapeHtml(report.options.scope);
242
+ const opts = [
243
+ `scope: ${scopeLabel}`,
244
+ report.options.allProjects ? 'all-projects' : null,
245
+ report.options.strict ? 'strict' : null,
246
+ ]
247
+ .filter(Boolean)
248
+ .join(' | ');
249
+ // --- Issues (confirmed_problem + review) --------------------------------
250
+ const globalIssues = report.findings.items.filter((f) => f.category === 'confirmed_problem' || f.category === 'review');
251
+ const globalCoverage = report.findings.items.filter((f) => f.category === 'coverage');
252
+ const multiContext = report.contexts.length > 1;
253
+ let issuesHtml = '';
254
+ if (multiContext) {
255
+ const parts = [];
256
+ if (globalIssues.length > 0) {
257
+ parts.push(`<h3>Installation-wide</h3>\n${globalIssues.map(renderFinding).join('\n')}`);
258
+ }
259
+ for (const ctx of report.contexts) {
260
+ const ctxIssues = ctx.findings.items.filter((f) => f.category === 'confirmed_problem' || f.category === 'review');
261
+ if (ctxIssues.length > 0) {
262
+ parts.push(`<h3>${escapeHtml(ctx.key)} &middot; ${escapeHtml(ctx.label)}${ctx.isCurrent ? ' <span class="badge badge-info">current</span>' : ''}</h3>\n${ctxIssues.map(renderFinding).join('\n')}`);
263
+ }
264
+ }
265
+ if (parts.length > 0) {
266
+ issuesHtml = `<h2>Issues</h2>\n${parts.join('\n')}`;
267
+ }
268
+ }
269
+ else {
270
+ const allIssues = [
271
+ ...globalIssues,
272
+ ...report.contexts.flatMap((c) => c.findings.items.filter((f) => f.category === 'confirmed_problem' || f.category === 'review')),
273
+ ];
274
+ issuesHtml = allIssues.length > 0
275
+ ? `<h2>Issues</h2>\n${allIssues.map(renderFinding).join('\n')}`
276
+ : '';
277
+ }
278
+ // --- Context footprint ---------------------------------------------------
279
+ const sorted = [...report.contexts].sort((a, b) => a.isCurrent === b.isCurrent ? 0 : a.isCurrent ? -1 : 1);
280
+ const contextHtml = sorted.length > 0
281
+ ? `<h2>Context Footprint</h2>\n${sorted.map((c) => renderContextFootprint(c, multiContext)).join('\n')}`
282
+ : '';
283
+ // --- Coverage notes ------------------------------------------------------
284
+ let coverageHtml = '';
285
+ if (multiContext) {
286
+ const parts = [];
287
+ if (globalCoverage.length > 0) {
288
+ parts.push(`<h3>Installation-wide</h3>\n${globalCoverage.map(renderFinding).join('\n')}`);
289
+ }
290
+ for (const ctx of report.contexts) {
291
+ const ctxCoverage = ctx.findings.items.filter((f) => f.category === 'coverage');
292
+ if (ctxCoverage.length > 0) {
293
+ parts.push(`<h3>${escapeHtml(ctx.key)} &middot; ${escapeHtml(ctx.label)}${ctx.isCurrent ? ' <span class="badge badge-info">current</span>' : ''}</h3>\n${ctxCoverage.map(renderFinding).join('\n')}`);
294
+ }
295
+ }
296
+ if (parts.length > 0) {
297
+ coverageHtml = `<h2>Coverage Notes</h2>\n${parts.join('\n')}`;
298
+ }
299
+ }
300
+ else {
301
+ const allCoverage = [
302
+ ...globalCoverage,
303
+ ...report.contexts.flatMap((c) => c.findings.items.filter((f) => f.category === 'coverage')),
304
+ ];
305
+ coverageHtml = allCoverage.length > 0
306
+ ? `<h2>Coverage Notes</h2>\n${allCoverage.map(renderFinding).join('\n')}`
307
+ : '';
308
+ }
309
+ // --- Per-plugin details --------------------------------------------------
310
+ let pluginDetailsHtml = '';
311
+ if (multiContext) {
312
+ const parts = [];
313
+ for (const ctx of report.contexts) {
314
+ if (ctx.effectivePlugins.items.length > 0) {
315
+ parts.push(`<h3>${escapeHtml(ctx.key)} &middot; ${escapeHtml(ctx.label)}${ctx.isCurrent ? ' <span class="badge badge-info">current</span>' : ''}</h3>\n${ctx.effectivePlugins.items.map(renderEffectivePlugin).join('\n')}`);
316
+ }
317
+ }
318
+ if (parts.length > 0) {
319
+ pluginDetailsHtml = `<h2>Plugin Details</h2>\n${parts.join('\n')}`;
320
+ }
321
+ }
322
+ else {
323
+ const effectivePlugins = report.contexts.flatMap((c) => c.effectivePlugins.items);
324
+ pluginDetailsHtml = effectivePlugins.length > 0
325
+ ? `<h2>Plugin Details</h2>\n${effectivePlugins.map(renderEffectivePlugin).join('\n')}`
326
+ : '';
327
+ }
328
+ // --- Maintenance (collapsed) ---------------------------------------------
329
+ const globalMaintenance = report.findings.items.filter((f) => f.category === 'maintenance');
330
+ let maintenanceHtml = '';
331
+ if (multiContext) {
332
+ const parts = [];
333
+ if (globalMaintenance.length > 0) {
334
+ parts.push(`<h3>Installation-wide</h3>\n${globalMaintenance.map(renderFinding).join('\n')}`);
335
+ }
336
+ for (const ctx of report.contexts) {
337
+ const ctxMaintenance = ctx.findings.items.filter((f) => f.category === 'maintenance');
338
+ if (ctxMaintenance.length > 0) {
339
+ parts.push(`<h3>${escapeHtml(ctx.key)} &middot; ${escapeHtml(ctx.label)}${ctx.isCurrent ? ' <span class="badge badge-info">current</span>' : ''}</h3>\n${ctxMaintenance.map(renderFinding).join('\n')}`);
340
+ }
341
+ }
342
+ if (parts.length > 0) {
343
+ const totalMaintenance = globalMaintenance.length +
344
+ report.contexts.reduce((sum, c) => sum + c.findings.items.filter((f) => f.category === 'maintenance').length, 0);
345
+ maintenanceHtml = `<h2>Maintenance</h2>\n<details><summary>${totalMaintenance} maintenance note${totalMaintenance !== 1 ? 's' : ''}</summary>\n${parts.join('\n')}\n</details>`;
346
+ }
347
+ }
348
+ else {
349
+ const allMaintenance = [
350
+ ...globalMaintenance,
351
+ ...report.contexts.flatMap((c) => c.findings.items.filter((f) => f.category === 'maintenance')),
352
+ ];
353
+ maintenanceHtml =
354
+ allMaintenance.length > 0
355
+ ? `<h2>Maintenance</h2>\n<details><summary>${allMaintenance.length} maintenance note${allMaintenance.length !== 1 ? 's' : ''}</summary>\n${allMaintenance.map(renderFinding).join('\n')}\n</details>`
356
+ : '';
357
+ }
358
+ return `<!DOCTYPE html>
359
+ <html lang="en">
360
+ <head>
361
+ <meta charset="utf-8">
362
+ <meta name="viewport" content="width=device-width, initial-scale=1">
363
+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; img-src data:; object-src 'none'; base-uri 'none'; form-action 'none'">
364
+ <title>ClaudePluginHub Doctor Report</title>
365
+ <style>${CSS}</style>
366
+ </head>
367
+ <body>
368
+ <div class="container">
369
+ <h1>ClaudePluginHub Doctor</h1>
370
+ <div class="header-meta">Claude ${version} &mdash; ${escapeHtml(opts)}</div>
371
+ ${renderVerdict(report)}
372
+ ${issuesHtml}
373
+ ${contextHtml}
374
+ ${coverageHtml}
375
+ ${pluginDetailsHtml}
376
+ ${maintenanceHtml}
377
+ ${renderOmissions(report)}
378
+ <div class="footer">
379
+ <p>Generated locally by ClaudePluginHub Doctor. No report data was uploaded.</p>
380
+ <p>Token estimates are approximations (~chars/4). Run <code>claude plugin details</code> for authoritative values.</p>
381
+ </div>
382
+ </div>
383
+ </body>
384
+ </html>`;
385
+ }
@@ -57,11 +57,6 @@ interface ParsedFrontmatter {
57
57
  description: string | null;
58
58
  understood: boolean;
59
59
  }
60
- /**
61
- * Bounded single-line frontmatter reader. Not YAML: block scalars, multi-line
62
- * values, or an unterminated fence make the file "not understood" — the
63
- * component is then reported as unestimated rather than invalid.
64
- */
65
60
  export declare function parseFrontmatter(content: string): ParsedFrontmatter;
66
61
  export declare function hashComponentContent(content: string): string;
67
62
  /**
@@ -388,11 +388,132 @@ function stringPaths(value) {
388
388
  }
389
389
  return [];
390
390
  }
391
- /**
392
- * Bounded single-line frontmatter reader. Not YAML: block scalars, multi-line
393
- * values, or an unterminated fence make the file "not understood" — the
394
- * component is then reported as unestimated rather than invalid.
395
- */
391
+ const BLOCK_SCALAR_RE = /^([|>])([+-]?)$/;
392
+ /** Detects explicit indent indicators like |2, >2, |+2, >-2, |2+, >2- that we don't handle. */
393
+ const BLOCK_SCALAR_EXPLICIT_INDENT_RE = /^[|>][+-]?\d|^[|>]\d[+-]?/;
394
+ function readBlockScalar(lines, startIndex, limit, indicator, chomping) {
395
+ let indent = -1;
396
+ const bodyLines = [];
397
+ let i = startIndex;
398
+ for (; i < limit; i++) {
399
+ const line = lines[i];
400
+ if (line.trim() === '') {
401
+ bodyLines.push('');
402
+ continue;
403
+ }
404
+ const leadingSpaces = line.match(/^( *)/)?.[1].length ?? 0;
405
+ if (indent === -1) {
406
+ indent = leadingSpaces;
407
+ if (indent === 0) {
408
+ if (/^---\s*$/.test(line))
409
+ break;
410
+ break;
411
+ }
412
+ }
413
+ if (leadingSpaces < indent)
414
+ break;
415
+ bodyLines.push(line.slice(indent));
416
+ }
417
+ if (i >= limit && lines.length > limit) {
418
+ return { value: '', nextIndex: i, truncated: true };
419
+ }
420
+ let raw;
421
+ if (indicator === '|') {
422
+ raw = bodyLines.join('\n');
423
+ }
424
+ else {
425
+ // Folded mode: fold adjacent normal-indented lines into one, but preserve
426
+ // literal newlines around blank lines (paragraph breaks) and more-indented
427
+ // lines (lines with extra indentation beyond the block indent).
428
+ //
429
+ // YAML spec folding: N consecutive blank lines between content produce
430
+ // exactly N newlines in output (1 blank = paragraph separator = single \n
431
+ // between paragraphs; 2 blanks = \n\n; 3 blanks = \n\n\n; etc.).
432
+ // More-indented lines always get a literal newline before/after them
433
+ // (they are never folded into surrounding content).
434
+ const stripped = [...bodyLines];
435
+ while (stripped.length > 0 && stripped[stripped.length - 1] === '')
436
+ stripped.pop();
437
+ let output = '';
438
+ let currentRun = [];
439
+ // Track whether we just emitted blank-line newlines; if so, the next
440
+ // content should NOT add its own \n separator — the blanks already did.
441
+ let afterBlanks = false;
442
+ // Track whether the last emitted content was a more-indented line (which
443
+ // is NOT newline-terminated in the output). Blank lines following a
444
+ // more-indented line must add an extra \n to terminate it first.
445
+ let afterMoreIndented = false;
446
+ const flushRun = () => {
447
+ if (currentRun.length > 0) {
448
+ output += currentRun.join(' ');
449
+ currentRun = [];
450
+ }
451
+ };
452
+ let idx = 0;
453
+ while (idx < stripped.length) {
454
+ const bl = stripped[idx];
455
+ if (bl === '') {
456
+ // Count consecutive blank lines
457
+ flushRun();
458
+ let blankCount = 0;
459
+ while (idx < stripped.length && stripped[idx] === '') {
460
+ blankCount++;
461
+ idx++;
462
+ }
463
+ // If the preceding content was a more-indented line, it didn't end
464
+ // with a newline — add one to terminate it before the blank separation.
465
+ if (afterMoreIndented) {
466
+ output += '\n';
467
+ afterMoreIndented = false;
468
+ }
469
+ // N blank lines → N newlines in output
470
+ output += '\n'.repeat(blankCount);
471
+ afterBlanks = true;
472
+ }
473
+ else if (bl.startsWith(' ') || bl.startsWith('\t')) {
474
+ // More-indented line: not folded with adjacent lines
475
+ flushRun();
476
+ output += '\n';
477
+ output += bl;
478
+ afterBlanks = false;
479
+ afterMoreIndented = true;
480
+ idx++;
481
+ }
482
+ else {
483
+ // Normal line: fold with adjacent normal lines
484
+ if (currentRun.length === 0 && output.length > 0 && !afterBlanks) {
485
+ // Separator between adjacent content (no intervening blank lines)
486
+ output += '\n';
487
+ }
488
+ currentRun.push(bl);
489
+ afterBlanks = false;
490
+ afterMoreIndented = false;
491
+ idx++;
492
+ }
493
+ }
494
+ flushRun();
495
+ const folded = output;
496
+ let trailingCount = bodyLines.length - stripped.length;
497
+ // When folded content is blank-only, trailing newlines ARE the value —
498
+ // subtract one so the keep-chomping branch's unconditional +'\n' doesn't
499
+ // produce an off-by-one (there is no "final content line break" to add).
500
+ if (folded === '' && trailingCount > 0)
501
+ trailingCount -= 1;
502
+ raw = folded + '\n'.repeat(trailingCount);
503
+ }
504
+ let value;
505
+ if (chomping === '-') {
506
+ value = raw.replace(/\n+$/, '');
507
+ }
508
+ else if (chomping === '+') {
509
+ value = raw.length > 0 || bodyLines.length > 0 ? raw + '\n' : '';
510
+ }
511
+ else {
512
+ const stripped = raw.replace(/\n+$/, '');
513
+ value = stripped.length > 0 || bodyLines.length > 0 ? stripped + '\n' : '';
514
+ }
515
+ return { value, nextIndex: i, truncated: false };
516
+ }
396
517
  export function parseFrontmatter(content) {
397
518
  if (!content.startsWith('---'))
398
519
  return { name: null, description: null, understood: true };
@@ -401,10 +522,10 @@ export function parseFrontmatter(content) {
401
522
  let name = null;
402
523
  let description = null;
403
524
  let closed = false;
404
- let blockScalar = false;
405
- for (let i = 1; i < Math.min(lines.length, FRONTMATTER_MAX_LINES); i += 1) {
525
+ const lineLimit = Math.min(lines.length, FRONTMATTER_MAX_LINES);
526
+ for (let i = 1; i < lineLimit; i += 1) {
406
527
  const line = lines[i];
407
- if (line.trim() === '---') {
528
+ if (/^---\s*$/.test(line) && !line.startsWith(' ') && !line.startsWith('\t')) {
408
529
  closed = true;
409
530
  break;
410
531
  }
@@ -412,17 +533,35 @@ export function parseFrontmatter(content) {
412
533
  if (!match)
413
534
  continue;
414
535
  const value = match[2].trim();
415
- if (value === '' || value === '|' || value === '>' || value.startsWith('|') || value.startsWith('>')) {
416
- blockScalar = true;
536
+ // Explicit indent indicators (|2, >2, >+1, etc.) are uncommon and complex —
537
+ // mark as not understood rather than risk a wrong parse.
538
+ if (BLOCK_SCALAR_EXPLICIT_INDENT_RE.test(value)) {
539
+ return { name, description, understood: false };
540
+ }
541
+ const blockMatch = value.match(BLOCK_SCALAR_RE);
542
+ if (blockMatch) {
543
+ const indicator = blockMatch[1];
544
+ const chomping = blockMatch[2];
545
+ const result = readBlockScalar(lines, i + 1, lineLimit, indicator, chomping);
546
+ if (result.truncated) {
547
+ return { name, description, understood: false };
548
+ }
549
+ i = result.nextIndex - 1;
550
+ if (match[1] === 'name')
551
+ name = result.value;
552
+ else
553
+ description = result.value;
417
554
  continue;
418
555
  }
556
+ if (value === '')
557
+ continue;
419
558
  const unquoted = value.replace(/^["']/, '').replace(/["']$/, '');
420
559
  if (match[1] === 'name')
421
560
  name = unquoted;
422
561
  else
423
562
  description = unquoted;
424
563
  }
425
- return { name, description, understood: closed && !blockScalar };
564
+ return { name, description, understood: closed };
426
565
  }
427
566
  function normalizeForHash(content) {
428
567
  return content.replace(/\r\n/g, '\n').replace(/\s+$/, '');
@@ -0,0 +1,11 @@
1
+ import { type ExecFileException } from 'node:child_process';
2
+ export interface BrowserOpener {
3
+ open(filePath: string): Promise<boolean>;
4
+ }
5
+ type ExecFileFn = (file: string, args: string[], callback: (error: ExecFileException | null) => void) => void;
6
+ export declare function createOpener(deps: {
7
+ platform: string;
8
+ execFile: ExecFileFn;
9
+ }): BrowserOpener;
10
+ export declare function defaultOpener(): BrowserOpener;
11
+ export {};
@@ -0,0 +1,38 @@
1
+ import { execFile as nodeExecFile } from 'node:child_process';
2
+ export function createOpener(deps) {
3
+ return {
4
+ open(filePath) {
5
+ let cmd;
6
+ let args;
7
+ switch (deps.platform) {
8
+ case 'darwin':
9
+ cmd = 'open';
10
+ args = [filePath];
11
+ break;
12
+ case 'linux':
13
+ cmd = 'xdg-open';
14
+ args = [filePath];
15
+ break;
16
+ case 'win32':
17
+ cmd = 'cmd.exe';
18
+ args = ['/c', 'start', '', filePath];
19
+ break;
20
+ default:
21
+ return Promise.resolve(false);
22
+ }
23
+ return new Promise((resolve) => {
24
+ deps.execFile(cmd, args, (error) => {
25
+ resolve(!error);
26
+ });
27
+ });
28
+ },
29
+ };
30
+ }
31
+ export function defaultOpener() {
32
+ return createOpener({
33
+ platform: process.platform,
34
+ execFile: (file, args, callback) => {
35
+ nodeExecFile(file, args, callback);
36
+ },
37
+ });
38
+ }
@@ -1,9 +1,3 @@
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
- */
1
+ import type { DoctorReport, DoctorFlags } from './report.js';
8
2
  export declare function renderJson(report: DoctorReport): string;
9
- export declare function renderHuman(report: DoctorReport): string;
3
+ export declare function renderHuman(report: DoctorReport, flags: DoctorFlags): string;