✨ feat(onboard): onboard writes the shared Guard's caller, and doctor checks it

Merged
AT
13d ago
+762-35

Slice: #470

Each client gets a thin caller for the shared Guard (#469): niyam onboard writes it, moves it with every other pin, and niyam doctor checks it.

What changes

  • src/guard-caller.ts (new), shared by onboard and doctor: guardCaller(branch, version) renders the caller; callerAt(text) reads the release and branch of a file YAML-equal to that render (comments and layout aside); callerIsOnboards(text) says a file is onboard's (that, or onboard's header); callerWanted(on) is the one condition for writing it.
  • The caller, for a default branch trunk at v0.7.4:
    on:
      pull_request_target:
        types: [opened, edited, synchronize, reopened]
        branches: ["trunk"]
    permissions: { contents: read, pull-requests: read, issues: read }   # block form, at the top and on the job
    jobs:
      niyam-guard:
        name: niyam-guard
        uses: veda-hq/niyam/.github/workflows/shared-guard.yml@v0.7.4
    
    so its check is niyam-guard / judge. Its header names no release, so a run that moves the pin changes the uses: line alone, which Guard's onboard exemption takes as a version move.
  • onboard:
    • writes it with work-rules on, on pull requests to the repository's default branch (from GitHub, as for niyam.yml), not main (#470's comment);
    • a run again moves its pin and branch; a caller of its own edited by hand is written again; a niyam-guard.yml it did not write is refused before any plan, naming the file, changing nothing;
    • the plan shows guard caller, and the pull request says what the file holds;
    • in a public repository (private: false or visibility: public from the GET /repos/{slug} onboard already makes), "By hand" and the pull request's "Left to do by hand" add one step: allow pull_request_target for the caller under Settings → Actions → Policies. A private one gets none.
  • doctor, under "This repo", in a repository with work-rules on and a niyam.yml: ✓ when the caller is as onboard writes it at niyam.yml's release and push branch; ✗ when missing, at another release or branch, or of another shape (fix: niyam onboard again, or rename or delete it first when onboard did not write it).
  • ONBOARD_FILES includes the caller, so pr-work-rules' onboard exemption covers it.
  • README (onboard, doctor, The shared Guard) and a docs/decisions.md record (2026-11-19).

Assumption to check: the caller is written only with work-rules on. Guard refuses any guard-file change that no approved Work item's slice names, and only work-rules repositories have Work items, so a caller elsewhere would block every .github/ change. It is one function, callerWanted, to change.

Evidence

  • pnpm check passes: 2103 CLI tests and 96 script tests, 0 failures; guard-caller.ts 100% lines and branches, doctor.ts 100% lines, onboard.ts 99.57% lines (its uncovered lines predate this).
  • New tests: first write; a pin move changing only uses:; a default branch trunk and a branch change; rewrite after a comment edit and after hand edits (with:, sha pin, added trigger); three files onboard did not write refused with nothing changed; work-rules off writes none; public by private: false or visibility: public gets the step, private does not; doctor's ✓ and 16 ✗ shapes, files onboard did not write, other release and branch; the rendered caller meets the Guard's isCaller conditions.

After release: every work-rules client, niyam included, gets doctor ✗ until it runs onboard again. The first onboard pull request that adds the caller adds a guard file, which a version move does not cover, so in niyam it needs #472's slice.

🤖 Generated with Claude Code


Summary by cubic

niyam onboard now writes the shared Guard's caller, .github/workflows/niyam-guard.yml, in work-rules repositories, and niyam doctor checks it under "This repo".

  • The caller runs on pull requests to the repository's default branch and calls the shared Guard at the release niyam.yml pins, so its check is niyam-guard / judge.
  • A run again moves its pin and branch; a caller onboard wrote is rewritten even if hand-edited, and a niyam-guard.yml onboard did not write is refused before any plan.
  • The caller's pin counts in the downgrade guard, in the checkout and on GitHub, so an older CLI cannot move it back.
  • Public repositories get a one-time by-hand step to allow pull_request_target under Settings → Actions → Policies.
  • doctor marks the caller ✓ when it matches onboard's write, and ✗ when missing, at another release or branch, of another shape, or unreadable.

Release

  • After release, every work-rules client, niyam included, shows doctor ✗ until it runs onboard again.
  • In niyam, the first onboard pull request that adds the caller needs slice #472, as adding a guard file is not covered by a version move.