gen-agent-note-index.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * Regenerate `.agents/notes/INDEX.md` — the fully generated Agent Note index — from the
  3. * Agent Note tree (see [agent-note-index.ts](./agent-note-index.ts) for the layout contract and
  4. * rendering rules). The whole file is generated state; the curated prose lives
  5. * in `.agents/notes/README.md`. Freshness is asserted by
  6. * `verify-agent-note-classification.ts` (a `doc-sync` member), so a stale committed
  7. * index fails CI.
  8. *
  9. * Run: `pnpm run gen-agent-note-index`.
  10. */
  11. import { readFileSync, writeFileSync } from 'node:fs'
  12. import { resolve } from 'node:path'
  13. import { agentNoteRoot, renderIndex, walkAgentNoteTree } from './agent-note-index.ts'
  14. const { notes, errors } = walkAgentNoteTree()
  15. if (errors.length > 0) {
  16. console.error('gen-agent-note-index: refusing to generate from a structurally invalid tree:')
  17. for (const e of errors) console.error(` ${e}`)
  18. process.exit(1)
  19. }
  20. const indexPath = resolve(agentNoteRoot, 'INDEX.md')
  21. const next = renderIndex(notes)
  22. let current: string | undefined
  23. try {
  24. current = readFileSync(indexPath, 'utf8')
  25. } catch {
  26. // Missing INDEX.md is the fresh-generation case, not an error: fall through and write it.
  27. }
  28. if (next === current) {
  29. console.log(`gen-agent-note-index: .agents/notes/INDEX.md is up to date (${notes.length} Agent Notes).`)
  30. } else {
  31. writeFileSync(indexPath, next)
  32. console.log(`gen-agent-note-index: .agents/notes/INDEX.md regenerated (${notes.length} Agent Notes).`)
  33. }