verify-rfc-classification.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * Doc-sync gate: enforce the RFC classification scheme
  3. * ([the classification RFC](../docs/rfc/implemented/process/2026-06-20-rfc-classification.md))
  4. * and the freshness of the generated index tables
  5. * ([the index-generation RFC](../docs/rfc/implemented/process/2026-07-04-generate-rfc-index-tables.md)).
  6. * Every RFC is filed at `docs/rfc/{lifecycle}/{class}/yyyy-mm-dd-topic.md`; the
  7. * folder IS the label. This gate is the machine source of truth for the closed
  8. * class set and keeps the README index honest.
  9. *
  10. * Two checks (both against [rfc-index.ts](./rfc-index.ts), the shared walker
  11. * and renderer):
  12. *
  13. * 1. STRUCTURE — every `.md` under a lifecycle folder lives in a class folder
  14. * from CLASSES, is named `yyyy-mm-dd-*.md`, and opens with a parseable H1.
  15. * A loose `.md` directly under a lifecycle root (other than the
  16. * README/AGENTS allowlist) fails; an unknown class folder fails; a stray
  17. * file at an unexpected depth fails. This is what makes the set CLOSED: a
  18. * new class folder can't appear without amending CLASSES (and the README's
  19. * Classification section, per the RFC).
  20. *
  21. * 2. FRESHNESS — the marker-delimited index regions in `docs/rfc/README.md`
  22. * byte-match a fresh render from the tree, so every RFC is listed exactly
  23. * once, under the heading matching its path, with its H1 title and filename
  24. * date. The fix for a stale index is `pnpm run gen-rfc-index`, never a hand
  25. * edit. This is checker, not fixer: it reports and never rewrites.
  26. *
  27. * Run: `tsx scripts/verify-rfc-classification.ts`.
  28. */
  29. import { readFileSync } from 'node:fs'
  30. import { resolve } from 'node:path'
  31. import { rfcRoot, spliceReadme, walkRfcTree } from './rfc-index.ts'
  32. const { rfcs, errors } = walkRfcTree()
  33. const readmePath = resolve(rfcRoot, 'README.md')
  34. const readme = readFileSync(readmePath, 'utf8')
  35. if (errors.length === 0) {
  36. try {
  37. if (spliceReadme(readme, rfcs) !== readme) {
  38. errors.push('index: docs/rfc/README.md is stale — run `pnpm run gen-rfc-index` and commit the result')
  39. }
  40. } catch (error) {
  41. errors.push(`index: ${error instanceof Error ? error.message : String(error)}`)
  42. }
  43. }
  44. if (errors.length === 0) {
  45. console.log(`verify-rfc-classification: ${rfcs.length} RFC(s) checked, structure and index consistent.`)
  46. process.exit(0)
  47. }
  48. console.error('verify-rfc-classification: violations found:')
  49. for (const e of errors) console.error(` ${e}`)
  50. process.exit(1)