verify-agent-note-classification.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * Enforce Agent Note lifecycle/class paths, dated filenames, and titles; verify the
  3. * generated index and reject index rows in the curated README. Structural rules
  4. * and rendering are shared with `agent-note-index.ts`; the closed classification
  5. * contract lives in `.agents/notes/README.md`.
  6. */
  7. import { existsSync, readFileSync } from 'node:fs'
  8. import { resolve } from 'node:path'
  9. import { agentNoteRoot, INDEX_ROW, renderIndex, walkAgentNoteTree } from './agent-note-index.ts'
  10. const { notes, errors } = walkAgentNoteTree()
  11. // Keep the former homes unavailable so new notes cannot silently escape this tree.
  12. for (const legacyRoot of ['docs/rfc', 'docs/rfcs']) {
  13. if (existsSync(resolve(import.meta.dirname, '..', legacyRoot))) {
  14. errors.push(`legacy-path: ${legacyRoot}/ is forbidden — put Agent Notes under .agents/notes/`)
  15. }
  16. }
  17. if (errors.length === 0) {
  18. let index: string | undefined
  19. try {
  20. index = readFileSync(resolve(agentNoteRoot, 'INDEX.md'), 'utf8')
  21. } catch {
  22. // A missing INDEX.md is reported below as staleness, exactly like a drifted one.
  23. }
  24. if (renderIndex(notes) !== index) {
  25. errors.push('index: .agents/notes/INDEX.md is stale or missing — run `pnpm run gen-agent-note-index` and commit the result')
  26. }
  27. const readme = readFileSync(resolve(agentNoteRoot, 'README.md'), 'utf8')
  28. for (const line of readme.split('\n')) {
  29. if (INDEX_ROW.test(line)) {
  30. errors.push(`readme: index-shaped row in the curated README (the list lives in INDEX.md): ${JSON.stringify(line.slice(0, 80))}`)
  31. }
  32. }
  33. }
  34. if (errors.length === 0) {
  35. console.log(`verify-agent-note-classification: ${notes.length} Agent Note(s) checked, structure and index consistent.`)
  36. process.exit(0)
  37. }
  38. console.error('verify-agent-note-classification: violations found:')
  39. for (const e of errors) console.error(` ${e}`)
  40. process.exit(1)