Repository navigation
chore(agents): add skills for recurring agent work #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
scottlovegrove
merged 3 commits into
scottlovegrove/agents-2-verify
from
scottlovegrove/agents-3-skills
Nov 5, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| // Instructions that name files or commands that don't exist send agents in circles. This checks | ||
| // every path, link and `npm run` script named in the agent-facing docs, and the skills' shape. | ||
|
|
||
| import { existsSync, lstatSync, readdirSync, readFileSync, readlinkSync } from 'node:fs' | ||
| import { basename, dirname, join, relative, resolve } from 'node:path' | ||
| import { describe, expect, it } from 'vitest' | ||
| import { git } from './lib/git.ts' | ||
| import { REPO_ROOT } from './lib/test-repo.ts' | ||
| import { AGENT_DOCS } from './lib/tree.ts' | ||
|
|
||
| const SKILLS_DIR = join(REPO_ROOT, '.agents/skills') | ||
| const skills = readdirSync(SKILLS_DIR).filter((name) => !name.startsWith('.')) | ||
|
|
||
| function markdownFiles(dir: string): string[] { | ||
| return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => { | ||
| const path = join(dir, entry.name) | ||
| if (entry.isDirectory()) return markdownFiles(path) | ||
| return entry.name.endsWith('.md') ? [path] : [] | ||
| }) | ||
| } | ||
|
|
||
| // The same list that makes verify treat these docs as code, so a doc checked here can't be | ||
| // skipped there as docs-only. | ||
| const DOCS = [ | ||
| ...[...AGENT_DOCS].map((path) => join(REPO_ROOT, path)), | ||
| ...markdownFiles(join(REPO_ROOT, '.agents')), | ||
| ] | ||
|
|
||
| const tracked = git(REPO_ROOT, ['ls-files', '--cached', '--others', '--exclude-standard']) | ||
| .stdout.split('\n') | ||
| .filter(Boolean) | ||
| const scripts = Object.keys( | ||
| ( | ||
| JSON.parse(readFileSync(join(REPO_ROOT, 'package.json'), 'utf8')) as { | ||
| scripts: Record<string, string> | ||
| } | ||
| ).scripts, | ||
| ) | ||
|
|
||
| const ROOTED = /^(src|scripts|docs|\.agents|\.github|\.claude|\.codex|\.cursor)\// | ||
| const FILE_NAME = /^[\w.-]+\.(md|json|ts|tsx|js|cjs|mjs|sh|yml|yaml)$/ | ||
| // A path relative to the document, like `references/test-rules.md` in a skill. | ||
| const RELATIVE_FILE = /^[\w.-]+(\/[\w.-]+)+\.(md|json|ts|sh)$/ | ||
| // Output and state that exist only after a build or run. | ||
| const GENERATED = /^(\.tmp|tmp|dist|node_modules)(\/|$)/ | ||
|
|
||
| type Reference = { path: string; line?: number } | ||
|
|
||
| /** Paths named in backticks, with an optional `:line`. Placeholders (`<tool>`, `*`) are skipped. */ | ||
| function namedPaths(text: string): Reference[] { | ||
| return [...text.matchAll(/`([^`\s]+)`/g)] | ||
| .map((match) => match[1] ?? '') | ||
| .filter((value) => !/[<>*{}]/.test(value) && !GENERATED.test(value)) | ||
| .map((value) => { | ||
| const [, path = value, line] = value.match(/^(.*?):(\d+)$/) ?? [] | ||
| return { path, line: line ? Number(line) : undefined } | ||
| }) | ||
| .filter(({ path }) => ROOTED.test(path) || FILE_NAME.test(path) || RELATIVE_FILE.test(path)) | ||
| } | ||
|
|
||
| // CODEBASE.md names files relative to the folder its section describes (`lib/refs.ts`, | ||
| // `users.ts` in the src/lib/ catalog), so short paths resolve against these too. | ||
| const BASES = ['', 'src/', 'src/lib/', 'src/commands/'] | ||
|
|
||
| /** The repository path a reference names, or why it doesn't resolve. */ | ||
| function resolveReference(path: string, doc: string): string | { problem: string } { | ||
| if (!ROOTED.test(path) && path.includes('/')) { | ||
| const local = relative(REPO_ROOT, resolve(dirname(doc), path)) | ||
| if (existsSync(join(REPO_ROOT, local))) return local | ||
| } | ||
| if (ROOTED.test(path)) { | ||
| return existsSync(join(REPO_ROOT, path)) ? path : { problem: 'does not exist' } | ||
| } | ||
| const based = BASES.map((base) => `${base}${path}`).find((candidate) => | ||
| existsSync(join(REPO_ROOT, candidate)), | ||
| ) | ||
| if (based) return based | ||
| if (path.includes('/')) return { problem: 'does not exist' } | ||
| const matches = tracked.filter((candidate) => basename(candidate) === path) | ||
| if (matches.length === 1) return matches[0] ?? path | ||
| return { | ||
| problem: matches.length === 0 ? 'does not exist' : `is ambiguous: ${matches.join(', ')}`, | ||
| } | ||
| } | ||
|
|
||
| function brokenReferences(text: string, doc: string): string[] { | ||
| return namedPaths(text).flatMap(({ path, line }) => { | ||
| const resolved = resolveReference(path, doc) | ||
| if (typeof resolved !== 'string') return [`${path} ${resolved.problem}`] | ||
| if (line === undefined) return [] | ||
| const full = join(REPO_ROOT, resolved) | ||
| if (lstatSync(full).isDirectory()) return [`${path}:${line} names a line in a folder`] | ||
| const lines = readFileSync(full, 'utf8').split('\n').length | ||
| return line > lines ? [`${path}:${line} is past the end (${lines} lines)`] : [] | ||
| }) | ||
| } | ||
|
|
||
| /** Backticked names in the bullet list under a heading. */ | ||
| function listedUnder(text: string, heading: string): string[] { | ||
| const section = text.split(heading)[1]?.split(/\n#{1,3} /)[0] ?? '' | ||
| return [...section.matchAll(/^- `([\w-]+)`/gm)].map((match) => match[1] ?? '') | ||
| } | ||
|
|
||
| describe.each(DOCS.map((path) => [relative(REPO_ROOT, path), path]))('%s', (_name, path) => { | ||
| const text = readFileSync(path, 'utf8') | ||
|
|
||
| it('names only files and lines that exist', () => { | ||
| expect(brokenReferences(text, path)).toEqual([]) | ||
| }) | ||
|
|
||
| it('links only to files that exist', () => { | ||
| const links = [...text.matchAll(/\]\(([^)#\s]+)(#[^)]*)?\)/g)] | ||
| .map((match) => match[1] ?? '') | ||
| .filter((link) => !/^[a-z]+:/.test(link)) | ||
| expect(links.filter((link) => !existsSync(resolve(dirname(path), link)))).toEqual([]) | ||
| }) | ||
|
|
||
| it('names only npm scripts that exist', () => { | ||
| const named = [...text.matchAll(/npm run (?:--silent )?([\w:-]+)/g)].map((m) => m[1] ?? '') | ||
| expect(named.filter((script) => !scripts.includes(script))).toEqual([]) | ||
| }) | ||
| }) | ||
|
|
||
| describe.each(skills)('skill %s', (skill) => { | ||
| const file = join(SKILLS_DIR, skill, 'SKILL.md') | ||
| const text = readFileSync(file, 'utf8') | ||
| const frontmatter = text.match(/^---\n([\s\S]*?)\n---\n/)?.[1] ?? '' | ||
|
|
||
| it('has a name matching its folder and a description that says when to use it', () => { | ||
| expect(frontmatter).toMatch(new RegExp(`^name: ${skill}$`, 'm')) | ||
| const description = frontmatter.match(/^description: (.+)$/m)?.[1] ?? '' | ||
| expect(description).toContain('Use when') | ||
| expect(description.length).toBeLessThan(400) | ||
| }) | ||
|
|
||
| it('is linked for Claude Code', () => { | ||
| const link = join(REPO_ROOT, '.claude/skills', skill) | ||
| expect(lstatSync(link).isSymbolicLink()).toBe(true) | ||
| expect(resolve(dirname(link), readlinkSync(link))).toBe(join(SKILLS_DIR, skill)) | ||
| }) | ||
| }) | ||
|
|
||
| it('lists every skill in AGENTS.md, and only those', () => { | ||
| const text = readFileSync(join(REPO_ROOT, 'AGENTS.md'), 'utf8') | ||
| expect(listedUnder(text, '## Skills').toSorted()).toEqual(skills.toSorted()) | ||
| }) | ||
|
|
||
| it('names only test helpers that the fixtures, global-args or @doist/cli-core/testing export', async () => { | ||
| const skill = readFileSync(join(SKILLS_DIR, 'write-tests/SKILL.md'), 'utf8') | ||
| const section = skill.split('## Helpers')[1]?.split('\n## ')[0] ?? '' | ||
| const named = [...section.matchAll(/`(\w+)`/g)].map((match) => match[1] ?? '') | ||
| const fixtures = join(REPO_ROOT, 'src/lib/__fixtures__') | ||
| const sources = [ | ||
| ...readdirSync(fixtures).map((file) => join(fixtures, file)), | ||
| join(REPO_ROOT, 'src/lib/global-args.ts'), | ||
| ] | ||
| const local = sources.flatMap((file) => | ||
| [ | ||
| ...readFileSync(file, 'utf8').matchAll( | ||
| /^export (?:async )?(?:function|const|type) (\w+)/gm, | ||
| ), | ||
| ].map((match) => match[1]), | ||
| ) | ||
| const shared = Object.keys(await import('@doist/cli-core/testing')) | ||
| expect(named.length).toBeGreaterThan(5) | ||
| expect(named.filter((name) => !local.includes(name) && !shared.includes(name))).toEqual([]) | ||
| }) | ||
|
|
||
| it('has no Claude Code skill link without a skill behind it', () => { | ||
| const links = readdirSync(join(REPO_ROOT, '.claude/skills')) | ||
| expect(links.toSorted()).toEqual(skills.toSorted()) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.