Skip to content

feat(validator): enforce the docs/agents.md persona contract in CI - #610

Closed
ayobamiseun wants to merge 1 commit into
addyosmani:mainfrom
ayobamiseun:feat/validate-agents
Closed

ayobamiseun wants to merge 1 commit into
addyosmani:mainfrom
ayobamiseun:feat/validate-agents

Conversation

@ayobamiseun

Copy link
Copy Markdown
Contributor

Summary

agents/ is the one authored surface in the repo with no validator. Skills, commands, artifact paths, reference links, and manifests each have a script and a CI step; personas have none, even though docs/agents.md states a contract for them and two commands spawn them by name. A persona that drifts from that contract fails at spawn time in a user's session, not in CI.

This adds scripts/validate-agents.js, which enforces the rules docs/agents.md already states:

Rule Source in docs/agents.md
Valid YAML frontmatter, name equals the file stem, description present "Create agents/<role>.md with the same frontmatter format used by existing personas"; the name is the subagent_type
No hooks, mcpServers, or permissionMode frontmatter "Plugin agents do not support … those fields are silently ignored"
The file ends with a ## Composition section "Every persona file ends with a Composition block"
Listed in the persona table in docs/agents.md and the README "Add the persona to the table at the top of this file"
Every persona a command spawns resolves to a file /ship and /webperf pass the name as subagent_type

All four personas pass every rule today, so this is a guard in the #571 sense: it fires on nothing on main and catches the next persona that is added, renamed, or spawned by a command before its file exists. #261, which adds an accessibility-auditor, would be the first PR it checks.

Design notes

  • Reuses parseFrontmatter and frontmatterYamlErrors from scripts/lib/skill-lint.js rather than parsing again, the same way validate-commands.js does.
  • Spawn detection is deliberately narrow. Commands mention skills, files, and slash commands in backticks constantly, so a backticked name alone is not a reference. The four patterns are the phrasings the commands actually use: "Spawn the x subagent", "the x persona", subagent_type: x, and the /ship fan-out list form 1. **x**. All three host surfaces are scanned. A test pins that `code-review-and-quality` and `tasks/plan.md` are not treated as personas.
  • Listing files that do not exist are skipped so the validator runs in a sandbox and in a partial checkout.
  • docs/agents.md gains one paragraph after the authoring steps saying which steps CI enforces and how to run the check locally.

CI

Two steps in the existing command-parity job, and the validator plus its tests added to the macOS/Windows matrix from #590, so the check runs on all three platforms like the others.

Verification

node scripts/validate-agents.js               # 4 personas, 11 spawn references, 4 distinct — 0 errors
node --test scripts/validate-agents-test.js   # 15 pass
node --test scripts/*-test.js scripts/lib/*-test.js   # 122 pass
node scripts/validate-skills.js               # unchanged, 25 skills pass
node scripts/run-evals.js --min-rank1 95      # unchanged, rank-1 100%
git diff --check                              # clean

Tests cover each rule failing on its own (name mismatch, missing description, invalid YAML, each of the three ignored fields, missing Composition, Composition not last), the empty-directory case, a persona missing from each listing, absent listings skipped, every spawn phrasing resolving with the expected count, an unresolved spawn reported with file and line, and non-spawn backticks ignored.

Overlap

#427, #441, and #551 edit agents/code-reviewer.md content; none touch its frontmatter or Composition block, so they pass this validator as written. #600 and #548 add steps to the same workflow file at other positions.

agents/ was the only authored surface with no validator. docs/agents.md
states a contract for personas — same frontmatter format with name as the
subagent_type, no hooks/mcpServers/permissionMode (silently ignored by
plugin agents), a closing Composition block, and a row in the persona
tables — and /ship and /webperf spawn personas by name. Nothing checked
any of it, so a persona that drifted failed at spawn time in a user's
session rather than in CI.

Add scripts/validate-agents.js, reusing the frontmatter helpers from
scripts/lib/skill-lint.js. It lints each persona against the rules above,
checks the docs/agents.md and README tables list every persona, and scans
all three command surfaces for the phrasings that spawn a persona
("Spawn the `x` subagent", "the `x` persona", subagent_type: x, and the
fan-out list form) so an unresolved name fails with file and line. Spawn
detection is deliberately narrow; a bare backticked name is not a spawn.

All four personas pass today: 4 personas, 11 spawn references, 0 errors.
15 tests cover each rule failing alone, listings, and reference
resolution. Wired into the command-parity job and the macOS/Windows
matrix, and docs/agents.md now says which authoring steps CI enforces.
@addyosmani

Copy link
Copy Markdown
Owner

Thanks for the effort here, but I'm going to pass. We have four personas and no history of the contract drifting, and a 457-line standing validator is more than that needs. Testing it also turned up false positives: an agents/README.md index fails, a numbered list item that bolds a skill name reads as spawning a missing persona, subagent_type: agent-skills:code-reviewer gets parsed as "agent-skills", and a fenced heading after Composition trips the must-be-last check. It also requires a README table entry, which docs/agents.md doesn't ask for. If you want to try a much smaller version that checks name, description and the Composition section inside the existing validator, I'd look at that. Closing for now.

@addyosmani addyosmani closed this Sep 26, 2026
addyosmani pushed a commit that referenced this pull request Oct 10, 2026
The smaller version asked for when #610 was closed. docs/agents.md states
three rules for agents/<name>.md — the same frontmatter format as a skill
with name equal to the file stem (the name is the subagent_type commands
spawn) and a description, and a closing Composition block — and no
validator checked them.

Add lintPersonaContent to scripts/lib/skill-lint.js, reusing the existing
frontmatter parsing and YAML-validity rules, and have validate-skills.js
walk agents/*.md after the skills, skipping an index README.md. Headings
are read from fence-stripped content so an example block after
Composition does not count as a later section. No spawn-reference
scanning, no listing-table checks, no new script, no workflow change.

All four personas pass: 25 skills and 4 personas checked, 0 errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants