✨ feat(guard): one shared Guard judges any repository's pull request from a niyam release

Merged
AT
15d ago
+448-74

Slice: #469

A client's pull request today runs its own copy of the checks that judge it, and only niyam has a Guard (#468). This adds one Guard, shipped from niyam as checks.yml is, that any repository calls. Nothing calls it yet: the client's caller is #470, the owner-step is #471, and niyam moves onto it in #472. guard.yml keeps judging niyam's pull requests from main, this one included.

What changes

  • .github/workflows/shared-guard.yml (workflow_call, no inputs, no secrets): one job, judge. It checks out job.workflow_repository at job.workflow_sha, sparse to scripts/guard.mjs and what installs yaml, with persist-credentials: false, and refuses when GitHub gives no job.workflow_sha. It checks out nothing of the caller's; it reads the pull request through the API with the caller's token. Read-only permissions, a timeout, and a concurrency group of its own (niyam-guard-<number>).
  • scripts/guard.mjs:
    • refuses any event but pull_request_target;
    • reads owners and the repository's own "guard" paths from the default branch's .github/niyam.json through the API; missing, unparsed or no owner refuses;
    • a fixed floor of guard files: .github/, .githooks/, .husky/, lefthook.yml, package.json's scripts, the dvara, gitleaks and trufflehog settings;
    • the onboard exemption's tag is checked on veda-hq/niyam's main;
    • refuses any job that could report niyam-guard / judge unless its workflow runs on pull_request_target alone and the job only calls veda-hq/niyam/.github/workflows/shared-guard.yml@<ref>, with no steps.
  • .github/niyam.json gains "guard": ["scripts/*.mjs"], which moved out of the floor, so niyam guards the same files before and after.
  • .github/CODEOWNERS names Alok for shared-guard.yml; .github/actionlint.yaml knows job.workflow_sha/job.workflow_repository there.
  • README's Guard section and a docs/decisions.md record (2026-11-19, P-74) say so, with the rejected alternatives.

Evidence

  • pnpm check passes on the branch rebased onto main (db534a2): 2084 CLI tests and 95 script tests, 0 failures; guard.mjs 100% lines, 96.17% branches.
  • New script tests cover the floor and own paths, guardPathsIn, workflowOf, isCaller, the caller shape (an added caller and a release move pass; an added pull_request trigger, own steps, a local uses: and a job named niyam-guard / judge are refused), settings read from the default branch, the onboard tag on niyam, and the event refusal with no API calls.
  • The sparse checkout installs: a sparse clone of this branch with exactly those six paths ran pnpm install --frozen-lockfile --ignore-scripts ("Lockfile is up to date", 156 packages) and resolves yaml.
  • actionlint passes on shared-guard.yml.

Still to show: #469 asks this pull request to show how GitHub judges a required check with one failing and one passing run of the same name. That test needs a release and a caller (#470), so it runs on an unmerged test pull request once one exists; the result goes on #469.

Guard files: all named in #469's Guards:. CODEOWNERS holds this for Alok's review.

🤖 Generated with Claude Code


Summary by cubic

Adds one shared Guard, shipped from niyam as checks.yml is, that any repository calls to judge its own pull requests instead of running its own copy.

  • Adds .github/workflows/shared-guard.yml, a reusable workflow that runs scripts/guard.mjs from niyam at job.workflow_sha and reads the pull request through the API with the caller's token, never checking out the caller's code.
  • scripts/guard.mjs now refuses any event but pull_request_target, reads the owners and the repository's own guard paths from the default branch's .github/niyam.json (failing closed when GitHub names no default branch), checks the onboard release tag on veda-hq/niyam, and refuses any job that could report niyam-guard / judge unless it runs on pull_request_target alone and only calls shared-guard.yml at a release tag or full commit sha.
  • Moves niyam's own scripts/*.mjs from the fixed floor into niyam's settings, so niyam guards the same files.
  • Nothing calls the shared Guard yet; the caller, owner step, and niyam's own adoption land in follow-up work.