claudepluginhub 0.11.0 → 0.12.1

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.
@@ -23,6 +23,10 @@ export const TOOL_MATCHED_EVENTS = new Set([
23
23
  const FRONTMATTER_MAX_LINES = 100;
24
24
  const FRONTMATTER_MAX_BYTES = 16 * 1024;
25
25
  const MAX_KEYS = 50;
26
+ /** Default cap on combined description + when_to_use listing text (chars).
27
+ * Configurable listing caps/budgets may cause Doctor to differ from Claude's
28
+ * effective post-budget context. */
29
+ const LISTING_DESC_CAP = 1536;
26
30
  /**
27
31
  * Aggregate cap on hook/MCP/LSP/monitor facts per plugin. Parse helpers stop
28
32
  * producing at MAX_FACTS_PER_TYPE + 1 so the scanner can DETECT the overflow
@@ -388,41 +392,223 @@ function stringPaths(value) {
388
392
  }
389
393
  return [];
390
394
  }
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
- */
395
+ const BLOCK_SCALAR_RE = /^([|>])([+-]?)$/;
396
+ /** Detects explicit indent indicators like |2, >2, |+2, >-2, |2+, >2- that we don't handle. */
397
+ const BLOCK_SCALAR_EXPLICIT_INDENT_RE = /^[|>][+-]?\d|^[|>]\d[+-]?/;
398
+ function readBlockScalar(lines, startIndex, limit, indicator, chomping) {
399
+ let indent = -1;
400
+ const bodyLines = [];
401
+ let i = startIndex;
402
+ for (; i < limit; i++) {
403
+ const line = lines[i];
404
+ if (line.trim() === '') {
405
+ bodyLines.push('');
406
+ continue;
407
+ }
408
+ const leadingSpaces = line.match(/^( *)/)?.[1].length ?? 0;
409
+ if (indent === -1) {
410
+ indent = leadingSpaces;
411
+ if (indent === 0) {
412
+ if (/^---\s*$/.test(line))
413
+ break;
414
+ break;
415
+ }
416
+ }
417
+ if (leadingSpaces < indent)
418
+ break;
419
+ bodyLines.push(line.slice(indent));
420
+ }
421
+ if (i >= limit && lines.length > limit) {
422
+ return { value: '', nextIndex: i, truncated: true };
423
+ }
424
+ let raw;
425
+ if (indicator === '|') {
426
+ raw = bodyLines.join('\n');
427
+ }
428
+ else {
429
+ // Folded mode: fold adjacent normal-indented lines into one, but preserve
430
+ // literal newlines around blank lines (paragraph breaks) and more-indented
431
+ // lines (lines with extra indentation beyond the block indent).
432
+ //
433
+ // YAML spec folding: N consecutive blank lines between content produce
434
+ // exactly N newlines in output (1 blank = paragraph separator = single \n
435
+ // between paragraphs; 2 blanks = \n\n; 3 blanks = \n\n\n; etc.).
436
+ // More-indented lines always get a literal newline before/after them
437
+ // (they are never folded into surrounding content).
438
+ const stripped = [...bodyLines];
439
+ while (stripped.length > 0 && stripped[stripped.length - 1] === '')
440
+ stripped.pop();
441
+ let output = '';
442
+ let currentRun = [];
443
+ // Track whether we just emitted blank-line newlines; if so, the next
444
+ // content should NOT add its own \n separator — the blanks already did.
445
+ let afterBlanks = false;
446
+ // Track whether the last emitted content was a more-indented line (which
447
+ // is NOT newline-terminated in the output). Blank lines following a
448
+ // more-indented line must add an extra \n to terminate it first.
449
+ let afterMoreIndented = false;
450
+ const flushRun = () => {
451
+ if (currentRun.length > 0) {
452
+ output += currentRun.join(' ');
453
+ currentRun = [];
454
+ }
455
+ };
456
+ let idx = 0;
457
+ while (idx < stripped.length) {
458
+ const bl = stripped[idx];
459
+ if (bl === '') {
460
+ // Count consecutive blank lines
461
+ flushRun();
462
+ let blankCount = 0;
463
+ while (idx < stripped.length && stripped[idx] === '') {
464
+ blankCount++;
465
+ idx++;
466
+ }
467
+ // If the preceding content was a more-indented line, it didn't end
468
+ // with a newline — add one to terminate it before the blank separation.
469
+ if (afterMoreIndented) {
470
+ output += '\n';
471
+ afterMoreIndented = false;
472
+ }
473
+ // N blank lines → N newlines in output
474
+ output += '\n'.repeat(blankCount);
475
+ afterBlanks = true;
476
+ }
477
+ else if (bl.startsWith(' ') || bl.startsWith('\t')) {
478
+ // More-indented line: not folded with adjacent lines
479
+ flushRun();
480
+ output += '\n';
481
+ output += bl;
482
+ afterBlanks = false;
483
+ afterMoreIndented = true;
484
+ idx++;
485
+ }
486
+ else {
487
+ // Normal line: fold with adjacent normal lines
488
+ if (currentRun.length === 0 && output.length > 0 && !afterBlanks) {
489
+ // Separator between adjacent content (no intervening blank lines)
490
+ output += '\n';
491
+ }
492
+ currentRun.push(bl);
493
+ afterBlanks = false;
494
+ afterMoreIndented = false;
495
+ idx++;
496
+ }
497
+ }
498
+ flushRun();
499
+ const folded = output;
500
+ let trailingCount = bodyLines.length - stripped.length;
501
+ // When folded content is blank-only, trailing newlines ARE the value —
502
+ // subtract one so the keep-chomping branch's unconditional +'\n' doesn't
503
+ // produce an off-by-one (there is no "final content line break" to add).
504
+ if (folded === '' && trailingCount > 0)
505
+ trailingCount -= 1;
506
+ raw = folded + '\n'.repeat(trailingCount);
507
+ }
508
+ let value;
509
+ if (chomping === '-') {
510
+ value = raw.replace(/\n+$/, '');
511
+ }
512
+ else if (chomping === '+') {
513
+ value = raw.length > 0 || bodyLines.length > 0 ? raw + '\n' : '';
514
+ }
515
+ else {
516
+ const stripped = raw.replace(/\n+$/, '');
517
+ value = stripped.length > 0 || bodyLines.length > 0 ? stripped + '\n' : '';
518
+ }
519
+ return { value, nextIndex: i, truncated: false };
520
+ }
396
521
  export function parseFrontmatter(content) {
522
+ const empty = {
523
+ name: null, description: null, whenToUse: null,
524
+ understood: true, bodyStartOffset: 0, disableModelInvocation: false,
525
+ };
397
526
  if (!content.startsWith('---'))
398
- return { name: null, description: null, understood: true };
527
+ return empty;
399
528
  const slice = content.slice(0, FRONTMATTER_MAX_BYTES);
400
529
  const lines = slice.split('\n');
401
530
  let name = null;
402
531
  let description = null;
532
+ let whenToUse = null;
403
533
  let closed = false;
404
- let blockScalar = false;
405
- for (let i = 1; i < Math.min(lines.length, FRONTMATTER_MAX_LINES); i += 1) {
534
+ let disableModelInvocation = false;
535
+ const lineLimit = Math.min(lines.length, FRONTMATTER_MAX_LINES);
536
+ let offset = lines[0].length + 1; // skip opening '---\n'
537
+ for (let i = 1; i < lineLimit; i += 1) {
406
538
  const line = lines[i];
407
- if (line.trim() === '---') {
539
+ if (/^---\s*$/.test(line) && !line.startsWith(' ') && !line.startsWith('\t')) {
408
540
  closed = true;
541
+ offset += line.length + 1;
409
542
  break;
410
543
  }
411
- const match = line.match(/^(name|description)\s*:\s*(.*)$/);
412
- if (!match)
544
+ const dmiMatch = line.match(/^disable-model-invocation\s*:\s*(.*)$/);
545
+ if (dmiMatch) {
546
+ // Only unquoted YAML boolean `true` disables. Quoted "true", 'true',
547
+ // yes, 1, and malformed values must NOT silently disable.
548
+ disableModelInvocation = dmiMatch[1].trim() === 'true';
549
+ offset += line.length + 1;
413
550
  continue;
551
+ }
552
+ // Only the documented `when_to_use` spelling is recognized.
553
+ // `when-to-use` (hyphen) has no official compatibility contract and must
554
+ // not silently change estimates.
555
+ const match = line.match(/^(name|description|when_to_use)\s*:\s*(.*)$/);
556
+ if (!match) {
557
+ offset += line.length + 1;
558
+ continue;
559
+ }
560
+ const key = match[1];
414
561
  const value = match[2].trim();
415
- if (value === '' || value === '|' || value === '>' || value.startsWith('|') || value.startsWith('>')) {
416
- blockScalar = true;
562
+ // Explicit indent indicators (|2, >2, >+1, etc.) are uncommon and complex —
563
+ // mark as not understood rather than risk a wrong parse.
564
+ if (BLOCK_SCALAR_EXPLICIT_INDENT_RE.test(value)) {
565
+ return {
566
+ name, description, whenToUse,
567
+ understood: false, bodyStartOffset: content.length, disableModelInvocation,
568
+ };
569
+ }
570
+ const blockMatch = value.match(BLOCK_SCALAR_RE);
571
+ if (blockMatch) {
572
+ const indicator = blockMatch[1];
573
+ const chomping = blockMatch[2];
574
+ const result = readBlockScalar(lines, i + 1, lineLimit, indicator, chomping);
575
+ if (result.truncated) {
576
+ return {
577
+ name, description, whenToUse,
578
+ understood: false, bodyStartOffset: content.length, disableModelInvocation,
579
+ };
580
+ }
581
+ // Advance offset for the key line and all block-scalar lines consumed
582
+ for (let j = i; j < result.nextIndex; j++) {
583
+ offset += lines[j].length + 1;
584
+ }
585
+ i = result.nextIndex - 1;
586
+ if (key === 'name')
587
+ name = result.value;
588
+ else if (key === 'description')
589
+ description = result.value;
590
+ else
591
+ whenToUse = result.value;
592
+ continue;
593
+ }
594
+ if (value === '') {
595
+ offset += line.length + 1;
417
596
  continue;
418
597
  }
419
598
  const unquoted = value.replace(/^["']/, '').replace(/["']$/, '');
420
- if (match[1] === 'name')
599
+ if (key === 'name')
421
600
  name = unquoted;
422
- else
601
+ else if (key === 'description')
423
602
  description = unquoted;
603
+ else
604
+ whenToUse = unquoted;
605
+ offset += line.length + 1;
424
606
  }
425
- return { name, description, understood: closed && !blockScalar };
607
+ const bodyStartOffset = closed ? Math.min(offset, content.length) : content.length;
608
+ return {
609
+ name, description, whenToUse,
610
+ understood: closed, bodyStartOffset, disableModelInvocation,
611
+ };
426
612
  }
427
613
  function normalizeForHash(content) {
428
614
  return content.replace(/\r\n/g, '\n').replace(/\s+$/, '');
@@ -443,7 +629,9 @@ function buildComponent(type, relPath, content) {
443
629
  name: type === 'skill' ? basename(relPath) : fileStem(relPath),
444
630
  description: null,
445
631
  estimable: false,
446
- nameDescChars: 0,
632
+ disableModelInvocation: false,
633
+ listingChars: 0,
634
+ listingComplete: true,
447
635
  bodyChars: 0,
448
636
  hash: null,
449
637
  };
@@ -451,14 +639,32 @@ function buildComponent(type, relPath, content) {
451
639
  const frontmatter = parseFrontmatter(content);
452
640
  const fallbackName = type === 'skill' ? basename(relPath.replace(/\/SKILL\.md$/, '')) : fileStem(relPath);
453
641
  const name = frontmatter.name ?? (fallbackName === 'SKILL.md' ? 'skill' : fallbackName);
642
+ // Skills and legacy commands list name + description + whenToUse (capped at
643
+ // 1,536 chars for description+whenToUse combined); agents list name + description.
644
+ // The component name is outside that cap.
645
+ const isSkillOrCommand = type === 'skill' || type === 'command';
646
+ const descLen = frontmatter.description?.length ?? 0;
647
+ const wtuLen = isSkillOrCommand ? (frontmatter.whenToUse?.length ?? 0) : 0;
648
+ const cappedDescWtu = isSkillOrCommand
649
+ ? Math.min(descLen + wtuLen, LISTING_DESC_CAP)
650
+ : descLen;
651
+ const listingChars = name.length + cappedDescWtu;
652
+ // Skills/commands without a description may use a first-body-paragraph
653
+ // fallback that the bounded parser cannot safely determine — mark listing
654
+ // incomplete. Agents use only name+description semantics.
655
+ const listingComplete = isSkillOrCommand
656
+ ? frontmatter.description !== null
657
+ : true;
454
658
  return {
455
659
  type,
456
660
  relPath,
457
661
  name,
458
662
  description: frontmatter.description,
459
663
  estimable: frontmatter.understood,
460
- nameDescChars: name.length + (frontmatter.description?.length ?? 0),
461
- bodyChars: content.length,
664
+ disableModelInvocation: frontmatter.disableModelInvocation,
665
+ listingChars,
666
+ listingComplete,
667
+ bodyChars: content.length - frontmatter.bodyStartOffset,
462
668
  hash: type === 'outputStyle' ? null : hashComponentContent(content),
463
669
  };
464
670
  }
@@ -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;