✨ feat: doc-number, renumber-doc and work-item-number from athya_mono (W-60)

Merged
AT
19d ago
+3229-3

Athya's doc-number tools move here (athya_mono W-60, athya-hq/athya_mono#3621). Each command is generic, and a repository describes its documents in .github/niyam.json "docNumbers", either inline or as a path to a JSON file.

  • niyam doc-number <kind> [--reserve] [--json] gives the next free number for a numbered document kind.
    • It reads git history on every ref, the working tree of every worktree, the reservation refs, open PRs, the titles of Work item issues and frozen folders.
    • --reserve claims the number for good with an atomic update-ref under the configured prefix, and refuses when any GitHub source could not be read.
    • The number goes to stdout and where it came from goes to stderr.
  • niyam renumber-doc <kind> <from> <to> [--apply] moves a document to a new number and rewrites references and frontmatter relationships everywhere except the configured history paths.
  • niyam work-item-number [--issue N] [--apply] renumbers a Work item issue filed with a taken number: it comments first, then retitles, and refuses if the title changed meanwhile. It also adds the configured label to Work items that lack it.

Evidence

  • Same answers as the old scripts. On athya_mono's own repository, the old and new allocators agree: ADR next 0078 (main 73); RFC next 0169 (main 57, 60 Work items, 80 frozen folders).
  • Tests. pnpm check passes:
    • doc-numbers: 64 tests, including competing processes in linked worktrees getting distinct numbers.
    • renumber-doc: 79 tests, including a seeded property suite checked against the yaml parser.
    • work-item-number: 41 tests, including fault injection on every gh call.

A decision to see

niyam has no schema library. JSON from outside (gh output, .github/niyam.json) therefore goes through validators written here and exposed in the Standard Schema shape (~standard: version 1, vendor niyam). shuddhi's schema-parse-untrusted accepts that shape, so there are no suppressions. The checks themselves are hand-written; adding zod instead would be a new dependency. Object here if the rule should not accept this.

Test-only git hygiene (hermeticGitEnv, maskProcessGitEnv, removeFixtureRoot) lives in src/hermetic-git.ts.

Not in this PR

  • The release (0.6.22).
  • athya_mono's switch to these commands (athya-hq/athya_mono#3621).
  • lint-adrs and lint-rfcs: a 30-day reading proposes deleting them rather than moving them (Proposal). If Alok keeps either one, it comes here in a second PR.

Slice: #398

šŸ¤– Generated with Claude Code


Summary by cubic

Adds three numbered-document commands ported from athya_mono (W-60): doc-number, renumber-doc, and work-item-number. Repositories declare their document kinds in .github/niyam.json under "docNumbers" — inline or as a path to a JSON file — and the commands are generic across kinds. Not included here: the 0.6.22 release, athya_mono's switch to these commands, or lint-adrs/lint-rfcs.

New Features

  • doc-number <kind> [--reserve] allocates the next free number by scanning git history, worktrees, reservation refs, open PRs, and Work item titles; --reserve claims it with an atomic update-ref and refuses when any GitHub source can't be read.
  • renumber-doc <kind> <from> <to> [--apply] moves a document to a new number and rewrites every reference and frontmatter relationship outside configured history paths; dry run by default.
  • work-item-number [--issue N] [--apply] renumbers Work item issues holding taken numbers: comments first, retitles second, refuses if the title changed meanwhile, and labels unlabelled items.

Validation and tests

  • 184 tests total, including competing processes in linked worktrees, a property suite checked against the yaml parser, and fault injection on every gh call; test-only git fixtures live in src/hermetic-git.ts.
  • Untrusted JSON from gh and the settings file is validated by hand-written validators in Standard Schema shape (vendor niyam, version 1) instead of adding zod.