config-audit/scanners/skill-listing-scanner.mjs
Kjell Tore Guttormsen 7bb254780a feat(skill-listing): add SKL scanner for the skill-listing token budget
Fase 4 Items 2+3 (CC 2.1.114→181 gap-review). New orchestrated scanner
`skill-listing-scanner.mjs` (prefix SKL) flags every active skill whose
description exceeds the verified 1,536-char listing cap (CC 2.1.105, changelog
L1502). Past the cap, Claude Code silently truncates the description the model
reads to route skill invocation — dropping the trigger phrases at the tail.
HOME-scoped over all user + plugin skills via enumerateSkills (COL is the model).

- CA-SKL-001 (medium): description > 1,536 chars. Remediation folds in Item
  2(b) — recommends disableBundledSkills + skillOverrides + trimming
  (designvalg A: no standalone GAP-check, which would fire for nearly everyone).
- Designvalg B: v1 ships the verified cap ONLY. The aggregate 2%-of-context
  listing budget is deferred — it needs a context-window assumption that would
  turn a verified fact into a guess (would carry a CALIBRATION_NOTE if added).
- Choice C: recognize the skillOverrides settings key (CC 2.1.129) in
  KNOWN_KEYS. Left OUT of TYPE_CHECKS — the value is a per-skill object
  (off/user-invocable-only/name-only), not a string; a 'string' check (as the
  plan sketched) would create a NEW false positive. Verify-first deviation.

Registration: scan-orchestrator (13th scanner), humanizer (SKL → 'Wasted
tokens' + static/_default translations), scoring SCANNER_AREA_MAP (→ Token
Efficiency; no 11th area), README badge 12→13, CLAUDE.md (finding-id +
test-count), docs/scanner-internals.md, gap-matrix + plan status notes.

Snapshots reseeded hermetically (SEED_SNAPSHOT/UPDATE_SNAPSHOT): SKL entry with
0 findings in empty HOME, scanners_ok 11→12, claudeMdEstimatedTokens bump from
the CLAUDE.md edits flowing through the cascade. Contamination grep clean.

Suite 868/868 (856 baseline + 11 SKL + 1 skillOverrides). RED→GREEN logged
per cycle.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ter3E2JSi1Khgmuf2kady8
2026-06-18 17:36:28 +02:00

94 lines
4.1 KiB
JavaScript

/**
* SKL Scanner — Skill-listing token budget
*
* Claude Code shows the model a listing of every active skill's `description`
* so it can decide which skill to invoke. That listing is budgeted: each
* description is capped, and anything past the cap is silently truncated
* (Claude Code raised the per-description cap 250 → 1,536 chars in v2.1.105,
* changelog L1502, and added a startup/`/doctor` notice when truncation
* happens). A description past the cap loses its tail from what the model
* actually sees — the very trigger phrases meant to route invocation.
*
* Detection (v1, high confidence — no estimation):
* CA-SKL-001 active skill description > 1,536 chars → truncated (medium)
*
* The aggregate listing budget (skill descriptions sum vs ~2% of the context
* window, v2.1.32 L2860) is deliberately NOT scanned in v1: it requires
* assuming the user's context-window size, which would turn a verified fact
* into a guess. Lead with the cap; the aggregate check is a possible later
* addition (would carry a CALIBRATION_NOTE).
*
* Two-lens note vs TOK pattern F: TOK pattern F flags *project-local* skills
* with descriptions > 500 chars as a structural per-turn "bloat" heuristic.
* SKL is a different lens — it scans ALL active skills (user + plugin) against
* the *verified* 1,536-char hard truncation cap, not a bloat heuristic. The
* two are intentionally distinct, not duplicates.
*
* Zero external dependencies.
*/
import { finding, scannerResult } from './lib/output.mjs';
import { SEVERITY } from './lib/severity.mjs';
import { enumeratePlugins, enumerateSkills } from './lib/active-config-reader.mjs';
import { readTextFile } from './lib/file-discovery.mjs';
import { parseFrontmatter } from './lib/yaml-parser.mjs';
const SCANNER = 'SKL';
// Verified per-description skill-listing cap (CC 2.1.105, changelog L1502).
// Descriptions longer than this are truncated in the listing the model sees.
const DESCRIPTION_CAP = 1536;
/**
* Main scanner entry point.
*
* @param {string} _targetPath unused (skill listing is HOME-scoped)
* @param {object} _discovery unused (ignores project discovery)
*/
export async function scan(_targetPath, _discovery) {
const start = Date.now();
const findings = [];
const plugins = await enumeratePlugins();
const allSkills = await enumerateSkills(plugins);
let scanned = 0;
for (const skill of allSkills) {
if (!skill || typeof skill.path !== 'string') continue;
const content = await readTextFile(skill.path);
if (!content) continue;
scanned++;
const fm = parseFrontmatter(content)?.frontmatter || null;
const desc = (fm && typeof fm.description === 'string') ? fm.description : '';
if (desc.length <= DESCRIPTION_CAP) continue;
const sourceLabel = skill.source === 'plugin'
? `plugin:${skill.pluginName}`
: 'user';
findings.push(finding({
scanner: SCANNER,
severity: SEVERITY.medium,
title: 'Skill description exceeds the listing cap (Claude Code truncates it)',
description:
`Skill "${skill.name}" (${sourceLabel}) has a description of ${desc.length} ` +
`characters (>${DESCRIPTION_CAP}). Claude Code caps each skill description in ` +
'the listing the model reads to choose a skill, so everything past ' +
`${DESCRIPTION_CAP} characters is silently dropped — including any trigger ` +
'phrases at the tail meant to route invocation.',
file: skill.path,
evidence:
`description_chars=${desc.length}; cap=${DESCRIPTION_CAP}; ` +
`skill="${skill.name}"; source=${sourceLabel}`,
recommendation:
`Trim the description below ${DESCRIPTION_CAP} characters, leading with the ` +
'trigger phrases. To reclaim listing budget more broadly: set ' +
'`disableBundledSkills: true` to drop bundled skills you do not use from the ' +
'listing entirely, or use `skillOverrides` (`name-only` collapses a ' +
'description, `off` removes a skill) on the heaviest entries.',
category: 'token-efficiency',
}));
}
return scannerResult(SCANNER, 'ok', findings, scanned, Date.now() - start);
}