From cb4366f0100f99caab9a20bd2d5ee6a382f6ef23 Mon Sep 17 00:00:00 2001 From: Joan Leon Date: Sun, 20 Sep 2026 23:24:42 +0200 Subject: [PATCH 1/6] fix(validator): check references/ links inside a skill's own references/ files (#585) A file under skills//references/ sits one directory deeper than SKILL.md, so a link to a shared checklist needs ../../../references/ from there. The validator only read SKILL.md, which left that off-by-a-level mistake unguarded in the one place it can now happen (hardening-patterns.md on main, optimization-patterns.md in #580). The rule is unchanged: only references/*.md links, fenced blocks exempt, paths that do not exist yet ignored. The file set grows to include the markdown files directly inside each skill's references/ directory, and every link resolves from the file that contains it. The failure hint names the three-level prefix when the violation is in a reference file. --- scripts/validate-reference-links-test.js | 87 ++++++++++++++++++++++++ scripts/validate-reference-links.js | 68 +++++++++++++----- 2 files changed, 137 insertions(+), 18 deletions(-) diff --git a/scripts/validate-reference-links-test.js b/scripts/validate-reference-links-test.js index a720fec2bd..e9ded5ef51 100644 --- a/scripts/validate-reference-links-test.js +++ b/scripts/validate-reference-links-test.js @@ -103,6 +103,93 @@ test('passes when a skill colocates its own references directory', () => { assert.match(result.stdout, /1 skills checked — 0 error\(s\) — PASSED/); }); +test('passes when a skill reference file reaches the shared checklist three levels up', () => { + // A file under skills//references/ sits one directory deeper than + // SKILL.md, so the shared checklists are three levels up from it, not two. + const root = makeSandbox(); + writeFile(root, 'references/security-checklist.md', '# Security\n'); + writeFile(root, 'skills/hardening/SKILL.md', 'See [patterns](references/patterns.md).\n'); + writeFile( + root, + 'skills/hardening/references/patterns.md', + 'Shared checklists live in `../../../references/security-checklist.md`.\n' + ); + + const result = run(root); + + assert.equal(result.status, 0, result.stdout + result.stderr); + assert.match(result.stdout, /✓ {2}skills\/hardening\/references\/patterns\.md/); + assert.match(result.stdout, /1 skills checked — 0 error\(s\) — PASSED/); +}); + +test('fails when a skill reference file links the shared checklist with the SKILL.md prefix', () => { + // The same off-by-a-level mistake this validator exists to catch, made from + // inside the skill's references/ directory: the link is resolved from the + // file that contains it, so `../../` stops at skills/. + const root = makeSandbox(); + writeFile(root, 'references/security-checklist.md', '# Security\n'); + writeFile(root, 'skills/hardening/SKILL.md', 'See [patterns](references/patterns.md).\n'); + writeFile( + root, + 'skills/hardening/references/patterns.md', + ['# Patterns', '', 'See `../../references/security-checklist.md`.', ''].join('\n') + ); + + const result = run(root); + + assert.equal(result.status, 1, result.stdout + result.stderr); + assert.match(result.stdout, /✓ {2}skills\/hardening\/SKILL\.md/); + assert.match(result.stdout, /✗ {2}skills\/hardening\/references\/patterns\.md/); + assert.match( + result.stdout, + /L3: \.\.\/\.\.\/references\/security-checklist\.md — resolves to skills\/references\/security-checklist\.md/ + ); + assert.match(result.stdout, /1 skills checked — 1 error\(s\) — FAILED/); + assert.match(result.stdout, /use `\.\.\/\.\.\/\.\.\/references\/\.md`/); +}); + +test('keeps the same narrow rule inside a skill reference file', () => { + // Same exemptions as SKILL.md: fenced examples, sibling files named without + // a references/ prefix, and artifacts that do not exist yet. + const root = makeSandbox(); + writeFile(root, 'references/security-checklist.md', '# Security\n'); + writeFile(root, 'skills/hardening/SKILL.md', 'See [patterns](references/patterns.md).\n'); + writeFile( + root, + 'skills/hardening/references/patterns.md', + [ + 'Record findings in `SECURITY.md` or `docs/threat-model.md`. See also `other-patterns.md`.', + '', + '```markdown', + '[wrong on purpose](../../references/security-checklist.md)', + '```', + '', + ].join('\n') + ); + + const result = run(root); + + assert.equal(result.status, 0, result.stdout + result.stderr); + assert.match(result.stdout, /1 skills checked — 0 error\(s\) — PASSED/); +}); + +test('counts errors from SKILL.md and its reference files together', () => { + const root = makeSandbox(); + writeFile(root, 'references/security-checklist.md', '# Security\n'); + writeFile(root, 'skills/hardening/SKILL.md', 'See `references/security-checklist.md`.\n'); + writeFile(root, 'skills/hardening/references/a.md', 'See `../../references/security-checklist.md`.\n'); + writeFile(root, 'skills/hardening/references/b.md', 'See `../../../references/security-checklist.md`.\n'); + writeFile(root, 'skills/hardening/references/notes.txt', 'See ../../references/security-checklist.md\n'); + + const result = run(root); + + assert.equal(result.status, 1, result.stdout + result.stderr); + assert.match(result.stdout, /✗ {2}skills\/hardening\/references\/a\.md/); + assert.match(result.stdout, /✓ {2}skills\/hardening\/references\/b\.md/); + assert.doesNotMatch(result.stdout, /notes\.txt/); + assert.match(result.stdout, /1 skills checked — 2 error\(s\) — FAILED/); +}); + test('fails when a link points at a checklist that no longer exists', () => { const root = makeSandbox(); writeFile(root, 'references/definition-of-done.md', '# Definition of Done\n'); diff --git a/scripts/validate-reference-links.js b/scripts/validate-reference-links.js index 3e69a08ef6..870a204acf 100644 --- a/scripts/validate-reference-links.js +++ b/scripts/validate-reference-links.js @@ -20,10 +20,16 @@ * accepts both conventions in CLAUDE.md — shared checklists reached via * `../../references/`, and a skill's own colocated `references/` directory. * + * The markdown files inside a skill's own `references/` directory get the + * same check, with each link resolved from the file that contains it. They + * sit one directory deeper than SKILL.md, so from there the shared checklists + * are `../../../references/`: the same off-by-a-level mistake, one level down. + * * Scope is deliberately narrow: only `references/*.md` links, only SKILL.md - * files. It is not a general markdown path linter — skills legitimately - * mention paths that do not exist yet (`tasks/todo.md`, `PERF.md`, - * `docs/ideas/[idea-name].md`), and those must not fail the build. + * and `skills//references/*.md` files. It is not a general markdown + * path linter — skills legitimately mention paths that do not exist yet + * (`tasks/todo.md`, `PERF.md`, `docs/ideas/[idea-name].md`), and those must + * not fail the build. * * Fenced code blocks are exempt for the same reason. Text inside a fence is * an example, not a link an agent will follow — and this rule in particular @@ -48,16 +54,19 @@ const SKILLS_DIR = path.join(ROOT, 'skills'); // non-path character so `myreferences/x.md` does not match. const REFERENCE_LINK_RE = /(? { for (const match of line.matchAll(REFERENCE_LINK_RE)) { const link = match[1]; - if (!fs.existsSync(path.resolve(skillDir, link))) { - violations.push({ line: i + 1, link }); + const target = path.resolve(baseDir, link); + if (!fs.existsSync(target)) { + violations.push({ line: i + 1, link, target }); } } }); @@ -65,6 +74,21 @@ function findViolations(skillDir, skillFile) { return violations; } +// The markdown files directly inside a skill's own references/ directory. +function skillReferenceFiles(skillDir) { + const dir = path.join(skillDir, 'references'); + if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) return []; + return fs.readdirSync(dir) + .filter((name) => name.endsWith('.md')) + .sort() + .map((name) => path.join(dir, name)) + .filter((file) => fs.statSync(file).isFile()); +} + +function toPosix(file) { + return path.relative(ROOT, file).split(path.sep).join('/'); +} + function main() { console.log('Checking references/ links in skills...\n'); @@ -75,6 +99,7 @@ function main() { let checked = 0; let errors = 0; + let referenceFileErrors = 0; const skillNames = fs.readdirSync(SKILLS_DIR).sort(); for (const name of skillNames) { @@ -83,16 +108,19 @@ function main() { if (!fs.statSync(skillDir).isDirectory() || !fs.existsSync(skillFile)) continue; checked++; - const violations = findViolations(skillDir, skillFile); - - if (violations.length === 0) { - console.log(` ✓ skills/${name}/SKILL.md`); - } else { - console.log(` ✗ skills/${name}/SKILL.md`); - for (const { line, link } of violations) { - const resolved = path.relative(ROOT, path.resolve(skillDir, link)).split(path.sep).join('/'); - console.log(` L${line}: ${link} — resolves to ${resolved}, which does not exist`); + for (const file of [skillFile, ...skillReferenceFiles(skillDir)]) { + const violations = findViolations(file); + + if (violations.length === 0) { + console.log(` ✓ ${toPosix(file)}`); + continue; + } + + console.log(` ✗ ${toPosix(file)}`); + for (const { line, link, target } of violations) { + console.log(` L${line}: ${link} — resolves to ${toPosix(target)}, which does not exist`); errors++; + if (file !== skillFile) referenceFileErrors++; } } } @@ -101,9 +129,13 @@ function main() { console.log(`\n${checked} skills checked — ${errors} error(s) — ${status}`); if (errors > 0) { - console.log('\nLinks to references/ are resolved from the skill\'s own directory.'); - console.log('Shared checklists live in the repo-root references/, two levels up:'); + console.log('\nLinks to references/ are resolved from the directory of the file that contains them.'); + console.log('Shared checklists live in the repo-root references/, two levels up from a SKILL.md:'); console.log('use `../../references/.md`, not `references/.md`.'); + if (referenceFileErrors > 0) { + console.log('From a file inside skills//references/ they are three levels up:'); + console.log('use `../../../references/.md`.'); + } process.exit(1); } } From d1463fd0d6675c6e145d9c57802d70faf84d1f51 Mon Sep 17 00:00:00 2001 From: Joan Leon Date: Sun, 20 Sep 2026 23:36:05 +0200 Subject: [PATCH 2/6] fix(security-and-hardening): restore rules the condensed text dropped in #579 #579 moved the code patterns verbatim, but three prose sections (supply chain, privacy, LLM) and the cookie bullet were rewritten rather than moved, and some rules ended up in none of SKILL.md, the reference, or the shared checklist. Restores them inline: the sameSite value and its CSRF reason, why forced audit fixes are dangerous, the audit signatures commands and "not automatic proof of compromise", the retention TTL, auditable consent, the (2025) on the OWASP LLM list, and "the full system prompt" plus "validate every tool argument" in the LLM rule. Red Flags already audits the system-prompt item, so the rule and its audit agree again. Same 216 lines, +55 words. --- skills/security-and-hardening/SKILL.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/skills/security-and-hardening/SKILL.md b/skills/security-and-hardening/SKILL.md index a59ca0daeb..e80e1e9a4f 100644 --- a/skills/security-and-hardening/SKILL.md +++ b/skills/security-and-hardening/SKILL.md @@ -87,7 +87,7 @@ Patterns: [Injection](references/hardening-patterns.md#injection), [XSS](referen ### Authentication and sessions - Hash passwords with bcrypt (≥12 rounds), scrypt, or argon2. The session secret comes from the environment, never from code. -- Session cookies are `httpOnly`, `secure`, `sameSite`, with a bounded `maxAge`. +- Session cookies are `httpOnly`, `secure`, and `sameSite: 'lax'` or `'strict'` (the CSRF defense; `'none'` sends the cookie on cross-site requests), with a bounded `maxAge`. Pattern: [Authentication](references/hardening-patterns.md#broken-authentication). @@ -134,8 +134,8 @@ Pattern: [Secrets management](references/hardening-patterns.md#secrets-managemen 1. **Find the installation boundary and manager.** Use the workspace root that owns the lockfile, or an independent nested project only when it is outside that workspace. Corroborate `packageManager` (when present), the lockfile, and CI; stop on disagreement or competing lockfiles. Pin the manager version. 2. **Block dependency scripts before first execution.** Bootstrap with scripts disabled or a documented fail-closed policy, inspect the pending script source, approve only the minimum, commit the policy, then verify with a clean frozen/immutable install. Never blanket-approve. -3. **Run the native audit against the committed lockfile before every release.** Triage critical/high by **reachability** (runtime, build, test, deploy paths) and fix availability. Never apply forced remediation (`npm audit fix --force` or equivalent) automatically; preview, read changelogs, test each upgrade. Document every deferral with a reason and a review date. -4. **Audits only match known advisories.** They do not catch a newly malicious or typosquatted package (`cross-env` vs `crossenv`). Review new dependencies, lockfile diffs, and script-policy changes together: ownership, maintenance, release age, provenance, transitive graph. Verify registry signatures where supported and treat their absence as a signal to investigate (A06, LLM03). +3. **Run the native audit against the committed lockfile before every release.** Triage critical/high by **reachability** (runtime, build, test, deploy paths) and fix availability. Never apply forced remediation (`npm audit fix --force` or equivalent) automatically, since forced fixes may cross declared dependency ranges; preview, read changelogs, test each upgrade. Document every deferral with a reason and a review date. +4. **Audits only match known advisories.** They do not catch a newly malicious or typosquatted package (`cross-env` vs `crossenv`). Review new dependencies, lockfile diffs, and script-policy changes together: ownership, maintenance, release age, provenance, transitive graph. Verify registry signatures where supported (`npm audit signatures`, `pnpm audit signatures`) and treat their absence as a signal to investigate, not automatic proof of compromise (A06, LLM03). Triage decision tree: [Dependency audit triage](references/hardening-patterns.md#dependency-audit-triage). Manager matrix and install-script gate: `../../references/security-checklist.md`. @@ -145,19 +145,19 @@ Hardening asks "can an attacker read it?" Privacy asks "should *we* hold it at a - **Classify fields as you add them** (non-personal, PII, sensitive) and handle each class accordingly. You cannot protect, or honor a deletion request for, data you cannot find. - **Collect only against a stated purpose.** "Might be useful later" is latent breach scope, not a purpose. Keep PII out of telemetry (the `observability-and-instrumentation` skill makes the same point from the ops side). -- **Set retention up front, then actually delete** — including backups, caches, search indexes, and analytics copies. +- **Set retention up front, then actually delete.** Every personal-data store needs a TTL and a working deletion path, including backups, caches, search indexes, and analytics copies. - **Support the data-subject rights your jurisdiction requires** (GDPR, CCPA, and kin): export, correct, delete. Design the schema so a user's data is findable and erasable, not smeared irreversibly across systems. -- **Consent gates collection and third-party sharing.** Sending PII to an analytics, ad, or LLM vendor is sharing; the vendor needs a data-processing agreement. Make region a configurable policy, not a hardcoded assumption. +- **Consent gates collection and third-party sharing, and is auditable.** Sending PII to an analytics, ad, or LLM vendor is sharing; the vendor needs a data-processing agreement. Make region a configurable policy, not a hardcoded assumption. Classification table: [Data classification](references/hardening-patterns.md#data-classification). A privacy incident starts the breach-notification clock; run the postmortem with the `debugging-and-error-recovery` skill. ### AI / LLM features -Calling an LLM — chatbots, summarizers, agents, RAG — adds a new attack surface; map it to the [OWASP Top 10 for LLM Applications](https://genai.owasp.org/llm-top-10/): +Calling an LLM — chatbots, summarizers, agents, RAG — adds a new attack surface; map it to the [OWASP Top 10 for LLM Applications (2025)](https://genai.owasp.org/llm-top-10/): - **Model output is untrusted input** (LLM05). Never into `eval`, SQL, a shell, `innerHTML`, or a file path; parse defensively, validate against a schema, then encode. - **Prompts can be hijacked** (LLM01). Untrusted text in the context — a user message, a fetched page, a PDF — can carry instructions. The system prompt is not a security boundary; enforce permissions in code. -- **Keep secrets and other tenants' data out of the context window** (LLM02, LLM07); scope tool permissions and confirm destructive actions (LLM06); cap tokens, request rate, and recursion depth (LLM10); partition RAG embeddings per tenant and validate documents before indexing (LLM08). +- **Keep secrets, other tenants' data, and the full system prompt out of the context window** (LLM02, LLM07); scope tool permissions, validate every tool argument, and confirm destructive actions (LLM06); cap tokens, request rate, and recursion depth (LLM10); partition RAG embeddings per tenant and validate documents before indexing (LLM08). Pattern: [LLM output handling](references/hardening-patterns.md#llm-output-handling). From 95801ad7c63fa2db9e259c74b9c1631e3c32f023 Mon Sep 17 00:00:00 2001 From: ayobamiseun Date: Sun, 20 Sep 2026 23:05:16 +0100 Subject: [PATCH 3/6] ci: validate tooling on macOS and Windows Add platform coverage for all six Node test suites, validators, and routing checks while preserving existing Ubuntu check names. Require both matrix jobs before plugin validation and retain failures from each platform. --- .github/workflows/test-plugin-install.yml | 48 ++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-plugin-install.yml b/.github/workflows/test-plugin-install.yml index 82054e0546..9d1c6756be 100644 --- a/.github/workflows/test-plugin-install.yml +++ b/.github/workflows/test-plugin-install.yml @@ -69,6 +69,52 @@ jobs: - name: Test artifact-path validator run: node --test scripts/validate-artifact-paths-test.js + # Ubuntu coverage stays in the existing jobs above, preserving their check names. + validate-platforms: + name: Validate tooling (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-latest, windows-latest] + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: Set up Node.js + uses: actions/setup-node@v6 + with: + node-version: '24' + + - name: Test validators and eval runner + run: >- + node --test + scripts/lib/skill-lint-test.js + scripts/validate-versions-test.js + scripts/run-evals-test.js + scripts/validate-reference-links-test.js + scripts/validate-commands-test.js + scripts/validate-artifact-paths-test.js + + - name: Validate all skills + run: node scripts/validate-skills.js + + - name: Validate manifest versions + run: node scripts/validate-versions.js + + - name: Validate references/ links in skills + run: node scripts/validate-reference-links.js + + - name: Validate commands across all tool directories + run: node scripts/validate-commands.js + + - name: Validate spec/plan/todo artifact paths + run: node scripts/validate-artifact-paths.js + + - name: Run skill evals (trigger + routing) + run: node scripts/run-evals.js --min-rank1 95 + test-hooks: name: Hook regression tests runs-on: ubuntu-latest @@ -83,7 +129,7 @@ jobs: validate: name: Validate plugin structure - needs: [validate-skills, validate-commands] + needs: [validate-skills, validate-commands, validate-platforms] runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 From 6fa76fa090baab4f3c877c84cb00dc923336c1e7 Mon Sep 17 00:00:00 2001 From: Abhishek Sharma Date: Mon, 21 Sep 2026 11:17:42 -0700 Subject: [PATCH 4/6] fix(validator): reject frontmatter that is not valid YAML MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `parseFrontmatter` splits each line on its first colon. That is enough to read `name` and `description`, and it is forgiving by design — but it means a SKILL.md whose frontmatter is not valid YAML passes every check in the linter. The hosts that consume these skills do not share that forgiveness. Per Cursor staff in #494, attaching a skill to a message parses its frontmatter as YAML, and a parse failure fails the request with a generic server error and takes the rest of the chat's context with it. So the repo could ship frontmatter that breaks a host while CI stayed green. Three shapes pass the current linter and are rejected by a strict parser (confirmed against ruby's psych, each isolated by mutating only the frontmatter of a real SKILL.md that otherwise lints clean): description: Use this: when X colon-space: YAML reads a nested mapping \tkey: value tab indentation is invalid YAML whitespace description: "unterminated an unclosed quote All three now fail with the line number and the fix. Deliberate boundaries: a colon with no trailing space is untouched, so `https://example.com/a:b` still passes, and a duplicate key is NOT reported because `safe_load` accepts one — the rule tracks the parser, not taste. This was verified once by hand against all 25 skills in the #494 thread. This makes it a check instead of a memory. Narrow on purpose: the repo has no package.json and therefore no YAML parser to depend on, so this is a small set of rules aimed at the classes actually observed to break a host, not a YAML implementation. No current frontmatter uses block scalars or multi-line values and the check says so. All 25 skills still pass with 0 errors, every validator exits 0, and the six script suites are green (35 pass in skill-lint-test). Mutation-tested 4/4: removing the call, widening the colon rule to any colon, and dropping either the tab or the unterminated-quote rule each fail the new tests. Refs #494 --- scripts/lib/skill-lint-test.js | 88 ++++++++++++++++++++++++++++++++++ scripts/lib/skill-lint.js | 84 ++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+) diff --git a/scripts/lib/skill-lint-test.js b/scripts/lib/skill-lint-test.js index a9a1f253a6..d2ebf93645 100644 --- a/scripts/lib/skill-lint-test.js +++ b/scripts/lib/skill-lint-test.js @@ -249,3 +249,91 @@ test('CRLF line endings are handled', () => { const result = lintSkillContent('fenced', content, FENCE_KNOWN); assert.equal(overviewMissing(result), true); }); + +// ── Frontmatter must be valid YAML, not merely splittable ──────────────────── +// `parseFrontmatter` splits each line on its first colon, which is forgiving by +// design. The hosts that read these skills are not: Cursor parses the +// frontmatter as YAML when a skill is attached to a message, and a parse +// failure fails the whole request and takes the chat's context with it (#494). +// Each shape below was confirmed rejected by a strict parser (ruby psych) while +// passing every other check in this linter. + +/** Frontmatter that is otherwise complete, so only YAML validity varies. */ +function fmLines(...lines) { + return withAllSections(['---', 'name: alpha', ...lines, '---'].join('\n')); +} + +const yamlErrors = result => result.errors.filter(e => e.startsWith('Frontmatter line ')); + +test('a valid frontmatter reports no YAML error', () => { + const result = lintSkillContent('alpha', fmLines('description: Use when you need alpha'), KNOWN); + assert.deepEqual(yamlErrors(result), []); +}); + +test('an unquoted value containing a colon is rejected', () => { + // YAML reads `Use when: X` as a nested mapping and errors; the split-on-first + // -colon parser reads it as a plain string and never notices. + const result = lintSkillContent( + 'alpha', + fmLines('description: Use when you need alpha: auth, secrets and review'), + KNOWN, + ); + assert.equal(yamlErrors(result).length, 1); + assert.match(yamlErrors(result)[0], /unquoted value containing/); +}); + +test('quoting the same value makes it valid again', () => { + const result = lintSkillContent( + 'alpha', + fmLines('description: "Use when you need alpha: auth, secrets and review"'), + KNOWN, + ); + assert.deepEqual(yamlErrors(result), []); +}); + +test('a colon with no trailing space is left alone', () => { + // `https://example.com` is a perfectly good YAML scalar. The rule keys on + // colon-space, not on colons, so ordinary URLs do not trip it. + const result = lintSkillContent( + 'alpha', + fmLines('description: Use when you need alpha', 'docs: https://example.com/a:b'), + KNOWN, + ); + assert.deepEqual(yamlErrors(result), []); +}); + +test('a tab used for indentation is rejected', () => { + const result = lintSkillContent( + 'alpha', + fmLines('description: Use when you need alpha', 'meta:', '\tlevel: core'), + KNOWN, + ); + assert.equal(yamlErrors(result).length, 1); + assert.match(yamlErrors(result)[0], /indents with a tab/); +}); + +test('an unterminated quote is rejected', () => { + const result = lintSkillContent('alpha', fmLines('description: "Use when you need alpha'), KNOWN); + assert.equal(yamlErrors(result).length, 1); + assert.match(yamlErrors(result)[0], /never closes/); +}); + +test('a duplicate key is not reported, because YAML accepts it', () => { + // Deliberate boundary: `safe_load` accepts duplicate keys, so flagging them + // here would fail files no host rejects. The rule tracks the parser, not taste. + const result = lintSkillContent( + 'alpha', + fmLines('description: Use when you need alpha', 'description: Use when you need alpha'), + KNOWN, + ); + assert.deepEqual(yamlErrors(result), []); +}); + +test('the error names the line so the fix is obvious', () => { + const result = lintSkillContent( + 'alpha', + fmLines('description: Use when you need alpha', 'owner: team: platform'), + KNOWN, + ); + assert.match(yamlErrors(result)[0], /^Frontmatter line 4 /); +}); diff --git a/scripts/lib/skill-lint.js b/scripts/lib/skill-lint.js index fa2aad582d..be4a455d86 100644 --- a/scripts/lib/skill-lint.js +++ b/scripts/lib/skill-lint.js @@ -146,6 +146,85 @@ function parseFrontmatter(content) { return result; } +/** + * Report frontmatter that this file's own parser accepts but a real YAML + * parser rejects. + * + * `parseFrontmatter` above splits each line on its first colon. That is enough + * to read `name` and `description`, and it is deliberately forgiving — but it + * means a SKILL.md whose frontmatter is not valid YAML passes every check here. + * The hosts that consume these skills do not share that forgiveness: Cursor + * parses the frontmatter as YAML when a skill is attached to a message, and a + * parse failure there fails the whole request with a generic server error and + * takes the rest of the chat's context with it (#494). + * + * So the repo could ship frontmatter that breaks a host while CI stayed green. + * That was verified once by hand, against all 25 skills, in the #494 thread; + * this makes it a check instead of a memory. + * + * Scope is deliberately narrow — the three shapes a strict parser rejects and + * the split-on-first-colon parser does not, confirmed against ruby's psych: + * + * description: Use this: when X unquoted value with a colon-space: YAML + * reads a nested mapping and errors + * \tkey: value tab indentation: invalid YAML whitespace + * description: "unterminated an unclosed quote + * + * It is not a YAML implementation. This repo has no package.json and therefore + * no parser to depend on, so the check stays a small set of rules aimed at the + * classes actually observed to break a host. No current frontmatter uses block + * scalars or multi-line values, and the check assumes that stays true; add a + * rule here rather than loosening one if it changes. + */ +function frontmatterYamlErrors(content) { + const match = content.match(/^---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*\r?\n/); + if (!match) return []; + + const errors = []; + const lines = match[1].split(/\r?\n/); + lines.forEach((line, i) => { + const lineNo = i + 2; // the opening `---` is line 1 + if (!line.trim()) return; + + if (/^[ ]*\t/.test(line)) { + errors.push( + `Frontmatter line ${lineNo} indents with a tab — YAML forbids tabs in indentation, ` + + `so a host that parses this frontmatter rejects the whole file` + ); + return; + } + + const colonIdx = line.indexOf(':'); + if (colonIdx === -1) return; + const value = line.slice(colonIdx + 1).trim(); + if (!value) return; + + const quote = value[0] === '"' || value[0] === "'" ? value[0] : null; + if (quote) { + // An opening quote must close. `endsWith` is enough here because a + // trailing comment after a quoted scalar does not appear in this repo. + if (value.length < 2 || !value.endsWith(quote)) { + errors.push( + `Frontmatter line ${lineNo} opens a ${quote === '"' ? 'double' : 'single'} quote that never closes — ` + + `a host parsing this frontmatter as YAML rejects the whole file` + ); + } + return; + } + + // Unquoted scalar. A colon followed by a space (or ending the line) makes + // YAML read a nested mapping where a plain string was meant. + if (/:(\s|$)/.test(value)) { + errors.push( + `Frontmatter line ${lineNo} has an unquoted value containing ': ' — YAML reads that as a ` + + `nested mapping and rejects the file; wrap the value in quotes` + ); + } + }); + + return errors; +} + /** * Collect all explicit skill cross-references from content. * Only matches against the SKILL_REF_PATTERNS list to avoid @@ -183,6 +262,10 @@ function lintSkillContent(dirName, content, knownSkills) { return { errors, warnings, exempt }; } + // The parser above is forgiving by design; the hosts that read this + // frontmatter are not (#494). + errors.push(...frontmatterYamlErrors(content)); + if (!fm.name) { errors.push("Frontmatter missing required field: 'name'"); } else if (fm.name !== dirName) { @@ -311,6 +394,7 @@ function lintSkill(dirName, skillsDir, knownSkills) { module.exports = { stripFencedCodeBlocks, parseFrontmatter, + frontmatterYamlErrors, extractSkillReferences, lintSkillContent, lintSkill, From 4af909b7c5a0b7104a8fe29f35fe5e255ad6478d Mon Sep 17 00:00:00 2001 From: Abhishek Sharma Date: Mon, 21 Sep 2026 12:19:04 -0700 Subject: [PATCH 5/6] feat(validator): hold commands to the same frontmatter rules as skills MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `descriptionFromMd` in validate-commands.js splits each frontmatter line on its first colon — the same forgiving read the skill linter used before the strict rules landed. So a command whose frontmatter is not valid YAML passes every check here, and Claude Code parses that frontmatter when the command is loaded. Same class of gap as the SKILL.md one, on the other set of files: the #494 thread verified all 25 SKILL.md files *and* the command files by hand. This makes the second half a check too, sharing the rules rather than restating them. All nine current commands already pass — confirmed independently against ruby's psych before writing this — so it is a guard, not a repair. That is the same shape the skills half had, and the same reason: the manual verification was real, it just could not stay true on its own. Scoped to `.claude/commands/*.md`. The `.gemini/` and `commands/` directories are TOML and already go through a real TOML parser, so a malformed one surfaces as a missing description in the existing check. A test pins that the YAML rules are NOT applied to them, since a TOML description legitimately carries a colon and running these rules over it would fail nearly every command. The test sandbox copies the validator into a temp tree, so it now copies scripts/lib/skill-lint.js beside it. Without that every existing test fails with a module-not-found, which is how I found it. Five new tests. Mutation-tested 2/2: skipping the check, and reporting its errors without counting them, each fail two. Every validator exits 0 and all six script suites pass. Refs #494 --- scripts/validate-commands-test.js | 66 +++++++++++++++++++++++++++++++ scripts/validate-commands.js | 35 ++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/scripts/validate-commands-test.js b/scripts/validate-commands-test.js index 1bcf77c4b1..8c65c8672b 100644 --- a/scripts/validate-commands-test.js +++ b/scripts/validate-commands-test.js @@ -10,6 +10,9 @@ const { spawnSync } = require('node:child_process'); const { afterEach, test } = require('node:test'); const VALIDATOR = path.join(__dirname, 'validate-commands.js'); +// The validator shares the frontmatter-validity rules with validate-skills, so +// the sandbox needs the lib alongside it, not just the script. +const SKILL_LINT = path.join(__dirname, 'lib', 'skill-lint.js'); const sandboxes = []; function makeSandbox() { @@ -17,6 +20,8 @@ function makeSandbox() { const scriptsDir = path.join(root, 'scripts'); fs.mkdirSync(scriptsDir, { recursive: true }); fs.copyFileSync(VALIDATOR, path.join(scriptsDir, 'validate-commands.js')); + fs.mkdirSync(path.join(scriptsDir, 'lib'), { recursive: true }); + fs.copyFileSync(SKILL_LINT, path.join(scriptsDir, 'lib', 'skill-lint.js')); sandboxes.push(root); return root; } @@ -148,3 +153,64 @@ test('parses escaped quotes in double-quoted TOML descriptions', () => { assert.equal(result.status, 0, result.stdout + result.stderr); assert.match(result.stdout, /1 commands checked — 0 error\(s\) — PASSED/); }); + +// Claude parses a command's frontmatter as YAML when the command is loaded, and +// `descriptionFromMd` splits each line on its first colon — so a command whose +// frontmatter is not valid YAML passed every check here. Same class as the +// SKILL.md gap, on the other set of files the #494 thread checked by hand. + +test('a command whose frontmatter is valid YAML passes', () => { + const root = makeSandbox(); + writeMatchingCommands(root, 'build', 'Build the thing'); + const result = run(root); + assert.equal(result.status, 0, result.stdout); + assert.match(result.stdout, /Checking Claude command frontmatter/); +}); + +test('an unquoted colon in a command description is rejected', () => { + const root = makeSandbox(); + // Valid to the splitter, rejected by a real YAML parser: it reads a nested + // mapping. The TOML siblings keep the same text so only the .md is at fault. + writeClaudeCommand(root, 'build', 'description: Build the thing: quickly'); + writeTomlCommand(root, path.join('.gemini', 'commands'), 'build', 'description = "Build the thing: quickly"'); + writeTomlCommand(root, 'commands', 'build', 'description = "Build the thing: quickly"'); + + const result = run(root); + assert.equal(result.status, 1, result.stdout); + assert.match(result.stdout, /unquoted value containing/); +}); + +test('quoting the same description makes it pass', () => { + const root = makeSandbox(); + writeClaudeCommand(root, 'build', 'description: "Build the thing: quickly"'); + writeTomlCommand(root, path.join('.gemini', 'commands'), 'build', 'description = "Build the thing: quickly"'); + writeTomlCommand(root, 'commands', 'build', 'description = "Build the thing: quickly"'); + + const result = run(root); + assert.equal(result.status, 0, result.stdout); +}); + +test('a tab-indented command frontmatter is rejected', () => { + const root = makeSandbox(); + writeFile( + root, + path.join('.claude', 'commands', 'build.md'), + '---\ndescription: Build the thing\nmeta:\n\tlevel: core\n---\n\n# Command\n', + ); + writeTomlCommand(root, path.join('.gemini', 'commands'), 'build', 'description = "Build the thing"'); + writeTomlCommand(root, 'commands', 'build', 'description = "Build the thing"'); + + const result = run(root); + assert.equal(result.status, 1, result.stdout); + assert.match(result.stdout, /indents with a tab/); +}); + +test('the TOML directories are not put through the YAML rules', () => { + const root = makeSandbox(); + // A TOML description legitimately carries a colon. Running the YAML rules over + // these files would fail every command that has one. + writeMatchingCommands(root, 'build', 'Build the thing quickly'); + const result = run(root); + assert.equal(result.status, 0, result.stdout); + assert.doesNotMatch(result.stdout, /\.gemini.*unquoted value/); +}); diff --git a/scripts/validate-commands.js b/scripts/validate-commands.js index a9ff439924..f26736bb32 100644 --- a/scripts/validate-commands.js +++ b/scripts/validate-commands.js @@ -10,6 +10,7 @@ * Checks (errors block CI): * - Every command present in one directory exists in all three * - The 'description' field is identical across all three equivalents + * - Claude command frontmatter is valid YAML, not merely splittable * * What this does NOT check: * Prompt body differences are intentional — each tool has its own @@ -23,6 +24,14 @@ const fs = require('fs'); const path = require('path'); +// The same frontmatter-validity rules validate-skills applies to SKILL.md. +// `descriptionFromMd` below splits each line on its first colon, exactly as the +// skill reader used to, so a command whose frontmatter is not valid YAML passes +// every check here — and Claude Code parses that frontmatter when the command is +// loaded. The #494 thread verified all 25 SKILL.md files AND the command files by +// hand; this makes the second half a check too. +const { frontmatterYamlErrors } = require(path.join(__dirname, 'lib', 'skill-lint.js')); + // ─── Config ─────────────────────────────────────────────────────────────────── const ROOT = path.resolve(__dirname, '..'); @@ -136,6 +145,32 @@ function main() { } } + // ── Claude frontmatter validity ───────────────────────────────────────────── + // Only the .md directory: the TOML dirs are parsed by a real TOML parser + // already, so a malformed one surfaces as a missing description above. + console.log('\nChecking Claude command frontmatter...'); + + for (const stem of claudeStems) { + const full = path.join(DIRS.claude.dir, `${stem}${DIRS.claude.ext}`); + let yamlErrors = []; + try { + yamlErrors = frontmatterYamlErrors(fs.readFileSync(full, 'utf8')); + } catch (e) { + console.log(` ✗ ${stem} — cannot read file: ${e.message}`); + errors++; + continue; + } + if (yamlErrors.length === 0) { + console.log(` ✓ ${stem}`); + continue; + } + console.log(` ✗ ${stem}`); + for (const message of yamlErrors) { + console.log(` ${message}`); + errors++; + } + } + // ── Description sync check ────────────────────────────────────────────────── console.log('\nChecking description sync...'); From be49649df7fc2a5a3083aabc853e10a0eadf2ff3 Mon Sep 17 00:00:00 2001 From: Federico Bartoli Date: Tue, 22 Sep 2026 06:18:18 +0200 Subject: [PATCH 6/6] test(evals): add a claude plugin eval pilot for code-review-and-quality --- evals/README.md | 15 +++++++++ .../code-review-fires/graders/off-by-one.md | 7 +++++ .../graders/severity-labels.md | 4 +++ .../code-review-fires/graders/skill-fired.md | 5 +++ evals/plugin/code-review-fires/prompt.md | 31 +++++++++++++++++++ .../graders/not-fired.md | 8 +++++ .../graders/tdd-fired.md | 6 ++++ .../plugin/code-review-stays-quiet/prompt.md | 8 +++++ 8 files changed, 84 insertions(+) create mode 100644 evals/plugin/code-review-fires/graders/off-by-one.md create mode 100644 evals/plugin/code-review-fires/graders/severity-labels.md create mode 100644 evals/plugin/code-review-fires/graders/skill-fired.md create mode 100644 evals/plugin/code-review-fires/prompt.md create mode 100644 evals/plugin/code-review-stays-quiet/graders/not-fired.md create mode 100644 evals/plugin/code-review-stays-quiet/graders/tdd-fired.md create mode 100644 evals/plugin/code-review-stays-quiet/prompt.md diff --git a/evals/README.md b/evals/README.md index e571aac810..4a6e332fd0 100644 --- a/evals/README.md +++ b/evals/README.md @@ -37,6 +37,21 @@ Tier 3 supports two behavioral artifact kinds. `execution` is the default: each The executor runs with an explicit permission mode (`--permission-mode acceptEdits` plus a pre-approved tool list) so execution evals can genuinely edit files, run commands, inspect diffs, and make commits rather than being denied and narrating instead. Traces are fenced as untrusted data in the grader prompt and piped to the grader over stdin (they can be megabytes; argv would hit the OS argument-size limit), executor and grader calls carry timeouts, and grader output is validated as JSON before being written to `evals/results/` (gitignored) in skill-creator's `grading.json` shape. Discipline skills also include pressure cases for time pressure, sunk cost, and authority pressure; these verify that the workflow still holds when the prompt argues for skipping it. +## Plugin evals (Claude Code) + +`claude plugin eval` (Claude Code 2.1.269 or later) loads the whole plugin, every skill at once, runs the cases under `evals/plugin/`, and scores each case with and without the plugin. It complements Tier 2 rather than replacing it: Tier 2 checks that a description carries the vocabulary users say; this checks that Claude Code's own router picks the skill on a natural prompt, and what the skill adds to the reply (the `Δ` column). + +```bash +claude plugin eval . --no-publish # every case, both arms, 3 runs each +claude plugin eval . --case code-review-fires --runs 1 --ablation none # one cheap iteration on one case +``` + +A case is a directory holding `prompt.md` (frontmatter: turn and tool limits; body: the prompt, sent verbatim) and one grader per file under `graders/`. Reports land in `evals/results//`, already gitignored. Every run and every `llm` grader is a real model call on your account, so this runs on demand and never in CI, like Tier 3. + +Two rules keep it honest. The command scans all of `evals/` for `prompt.md` or `case.yaml`, so never give a fixture file either name. And a `tool_used: Skill` grader only says whether the skill fired; in a two-arm run it is excluded from the score, so pair it with a grader on the reply itself. `code-review-fires` shows the pattern: the fired indicator, a free `regex` grader that looks for the skill's severity taxonomy (Critical, Required, Nit, Optional, Consider, FYI) used as a heading or as a label, and one `llm` judge on the planted off-by-one. `code-review-stays-quiet` is the precision check: the review skill must not fire on a test-first request, and its `Δ` is expected to be 0; a second, unscored indicator records whether test-driven-development fires instead. + +What the first runs taught (Claude Code 2.1.278, claude-opus-5). Skill invocation is stochastic: the review skill fired in 5 of 7 runs on the phrasing the case uses, and test-driven-development fired in 2 of 7 runs on the test-first prompt, so read `Δ` and the report rather than the exit code, or pass `--threshold 0.8` as the CI example in the docs does. In one run the review skill did not fire and the reply still used its severity taxonomy as headings, which no baseline run did in nine; the loaded skill descriptions may shape the reply even without an invocation. Phrasing matters: "Review this diff before I merge it", "Can you do a proper code review of this change before I merge it?" and "Review this pull request for me before it goes into main" never fired the skill in six runs; the model reviewed the diff on its own, competently but without the verdict, the severity tiers or the five-axis pass. Naming the axes ("across correctness, readability, security and performance") is what fires it, so the case uses that; the plainer phrasings are the open finding, and the fix, if any, belongs in the skill's description, not in the prompt. The model may also reach a skill through its slash command (`agent-skills:review`, then `code-review-and-quality`), which costs two turns, so give a case a turn budget of 10 or more. + ## Eval case format One file per skill: `evals/cases/.json`. diff --git a/evals/plugin/code-review-fires/graders/off-by-one.md b/evals/plugin/code-review-fires/graders/off-by-one.md new file mode 100644 index 0000000000..1db921b7bc --- /dev/null +++ b/evals/plugin/code-review-fires/graders/off-by-one.md @@ -0,0 +1,7 @@ +--- +type: llm +--- + +PASS if the review points out that `rows.slice(start, start + size - 1)` returns one row fewer than `size` on every page (the end index of slice is exclusive) and treats it as something that must be fixed before merge, for example by labelling it Critical or leaving it unprefixed as a required change. + +FAIL if the review does not mention that pages come back one row short, or files that finding as a Nit, Optional, Consider, or FYI. diff --git a/evals/plugin/code-review-fires/graders/severity-labels.md b/evals/plugin/code-review-fires/graders/severity-labels.md new file mode 100644 index 0000000000..fd981329f4 --- /dev/null +++ b/evals/plugin/code-review-fires/graders/severity-labels.md @@ -0,0 +1,4 @@ +--- +type: regex +pattern: '(^|\n)#{1,6} *(Critical|Required|Nit|Optional|Consider|FYI)\b|\b(Critical|Required|Nit|Optional|Consider|FYI):' +--- diff --git a/evals/plugin/code-review-fires/graders/skill-fired.md b/evals/plugin/code-review-fires/graders/skill-fired.md new file mode 100644 index 0000000000..b3d99df074 --- /dev/null +++ b/evals/plugin/code-review-fires/graders/skill-fired.md @@ -0,0 +1,5 @@ +--- +type: tool_used +tool: Skill +input_match: '"skill"\s*:\s*"(?:[\w-]+:)?code-review-and-quality"' +--- diff --git a/evals/plugin/code-review-fires/prompt.md b/evals/plugin/code-review-fires/prompt.md new file mode 100644 index 0000000000..de08726239 --- /dev/null +++ b/evals/plugin/code-review-fires/prompt.md @@ -0,0 +1,31 @@ +--- +description: A review request that names the axes, with a small diff inline. The skill should fire (through the review command or directly) and the reply should carry its severity labels. +expected_outcome: A structured review with a verdict, findings labelled with the skill's severity taxonomy, and the off-by-one in pageOrders treated as a required change. +max_turns: 12 +allowed_tools: [Read, Glob, Grep, Skill] +--- + +I want a code review of this diff across correctness, readability, security and performance before merging. It adds paging to the orders endpoint. + +```diff +diff --git a/src/orders.js b/src/orders.js +--- a/src/orders.js ++++ b/src/orders.js +@@ -12,3 +12,15 @@ function listOrders(db) { + return db.query('SELECT * FROM orders ORDER BY created_at DESC'); + } +-module.exports = { listOrders }; ++function pageOrders(db, page, size) { ++ const rows = db.query('SELECT * FROM orders ORDER BY created_at DESC'); ++ const start = (page - 1) * size; ++ return rows.slice(start, start + size - 1); ++} ++ ++app.get('/orders', (req, res) => { ++ const page = Number(req.query.page) || 1; ++ const size = Number(req.query.size) || 20; ++ res.json(pageOrders(db, page, size)); ++}); ++ ++module.exports = { listOrders, pageOrders }; +``` diff --git a/evals/plugin/code-review-stays-quiet/graders/not-fired.md b/evals/plugin/code-review-stays-quiet/graders/not-fired.md new file mode 100644 index 0000000000..c27388ab6b --- /dev/null +++ b/evals/plugin/code-review-stays-quiet/graders/not-fired.md @@ -0,0 +1,8 @@ +--- +type: tool_used +tool: Skill +input_match: '"skill"\s*:\s*"(?:[\w-]+:)?code-review-and-quality"' +min: 0 +max: 0 +arm: both +--- diff --git a/evals/plugin/code-review-stays-quiet/graders/tdd-fired.md b/evals/plugin/code-review-stays-quiet/graders/tdd-fired.md new file mode 100644 index 0000000000..b4a413948f --- /dev/null +++ b/evals/plugin/code-review-stays-quiet/graders/tdd-fired.md @@ -0,0 +1,6 @@ +--- +type: tool_used +tool: Skill +input_match: '"skill"\s*:\s*"(?:[\w-]+:)?test-driven-development"' +arm: with-only +--- diff --git a/evals/plugin/code-review-stays-quiet/prompt.md b/evals/plugin/code-review-stays-quiet/prompt.md new file mode 100644 index 0000000000..721882ecbe --- /dev/null +++ b/evals/plugin/code-review-stays-quiet/prompt.md @@ -0,0 +1,8 @@ +--- +description: A test-first request that belongs to test-driven-development. The review skill must not fire. +expected_outcome: The reply proposes a failing test first; code-review-and-quality is never invoked. +max_turns: 12 +allowed_tools: [Read, Glob, Grep, Skill] +--- + +Write a failing test for this bug before we fix it: splitCents(100, 3) returns [33, 33, 33] and a cent goes missing.