šŸ› fix(board): board-audit reads as the agent from the keychain when GH_TOKEN is unset (#548)

Merged
AT
4d ago
+187-14

Slice: #408
State: #548

With no GH_TOKEN, as in the owner's terminal, niyam board-audit now reads the board with the agent's token. niyam machine keeps that token in this Mac's keychain. Its error no longer tells the owner to run GH_TOKEN="$(gh auth token)" niyam board-audit, which needs the gh sign-in machine removes.

Why. On 2026-11-22 Alok ran niyam board-audit athya-hq/athya-rules in his terminal, right after niyam machine had signed him out of gh, as doctor asks. It refused:

niyam board-audit: board-audit needs GH_TOKEN, with read access to the Project: run it in an agent session, or GH_TOKEN="$(gh auth token)" niyam board-audit

The audit only reads. The agent's classic token has project and read:org (README, niyam machine), so it can read the board. This is a fix under #408, which made board-audit, so the slice's approval carries it.

Shape. auditToken in src/board-audit.ts:

  • GH_TOKEN comes first, where it is set, as in an agent session.
  • Otherwise it reads the agent's token from this Mac's keychain (readToken). The agent is:
    • in a clone, the one its settings name that sessions here work as (agentHere);
    • outside a clone, the one machine set up on this Mac (agentsSetUp).
  • No stored token, none set up, or several and none named: it says so, names niyam machine, and reads nothing. Never a guess.
  • Rejected: the owner's one-time browser sign-in, as owner-step uses. It costs a device code for a read the agent can do.

README ("Checking the board") and a Record in docs/decisions.md say so.

Tests (src/board-audit.test.ts; the old "needs GH_TOKEN" case is replaced):

  • With no GH_TOKEN, in the clone: every request carries the agent's keychain token.
  • With no GH_TOKEN, outside a clone, with one agent set up: the same.
  • Each of these reads nothing and never runs gh, and its error names niyam machine:
    • no stored token;
    • no agent set up;
    • two agents set up and none named;
    • in a clone whose settings name two agents, with neither set up.
  • In a clone whose settings name two agents, with one set up: it reads as that one.
  • The help line (src/run.ts) says the same.

Evidence:

  • pnpm exec node --test src/board-audit.test.ts: 15 pass, 0 fail.
  • pnpm check: exit 0.
    • 2132 pass, 0 fail; coverage 99.57% lines, 97.26% branches. src/board-audit.ts has 100% lines and 99.28% branches.
    • test:scripts: 133 pass, 0 fail.
    • Typecheck, lint, pins, pariksha, sarathi, build and smoke all passed.
  • Not run against GitHub from a real terminal: this session's hook allows only niyam review-thread. The tests use the fake keychain. The proof is the owner's first niyam board-audit athya-hq/athya-rules after upgrading.

After merge: a release. Then the owner runs niyam board-audit athya-hq/athya-rules in their own terminal, with no gh sign-in.

šŸ¤– Generated with Claude Code


Summary by cubic

niyam board-audit now reads the board with the agent's keychain token when GH_TOKEN is unset, so it works in the owner's terminal after niyam machine signs them out of gh. Previously it failed and told the owner to run GH_TOKEN="$(gh auth token)" niyam board-audit, which needs that sign-in back.

  • GH_TOKEN still takes priority when set, but a locked session's placeholder counts as no token: it reads nothing, never the keychain's instead, and says to run niyam doctor.
  • Without GH_TOKEN, the agent is resolved from the clone's settings, or the single agent machine set up on the Mac; the keychain is read under the login as machine spelled it.
  • On a platform with no token store, it says GH_TOKEN is needed there instead of naming niyam machine.
  • With no token, no agent set up, or several agents and none named, it says so, names the fix, and reads nothing. It never falls back to the owner's one-time browser sign-in.
  • README, docs/decisions.md, and the niyam board-audit help line document the new behavior.