@veda-hq/niyam 0.0.0-stage → 0.6.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1448 -2
  3. package/dist/agent.js +445 -0
  4. package/dist/approvals.js +25 -0
  5. package/dist/as-agent.js +315 -0
  6. package/dist/asks.js +475 -0
  7. package/dist/board.js +617 -0
  8. package/dist/brief.js +370 -0
  9. package/dist/cli.js +3 -0
  10. package/dist/cloud.js +213 -0
  11. package/dist/cubic-dismiss.js +284 -0
  12. package/dist/decisions.js +214 -0
  13. package/dist/design.js +207 -0
  14. package/dist/doctor.js +313 -0
  15. package/dist/edits.js +59 -0
  16. package/dist/features.js +142 -0
  17. package/dist/guard.js +108 -0
  18. package/dist/handoff.js +527 -0
  19. package/dist/host.js +18 -0
  20. package/dist/identity.js +171 -0
  21. package/dist/issue-types.js +514 -0
  22. package/dist/jsonedit.js +183 -0
  23. package/dist/keep-going.js +384 -0
  24. package/dist/layout.js +80 -0
  25. package/dist/lockout.js +184 -0
  26. package/dist/machine.js +385 -0
  27. package/dist/main.js +9 -0
  28. package/dist/names.js +19 -0
  29. package/dist/onboard-pull.js +249 -0
  30. package/dist/onboard.js +1501 -0
  31. package/dist/owner-login.js +105 -0
  32. package/dist/owner-step.js +676 -0
  33. package/dist/pages.js +50 -0
  34. package/dist/pr-autocreate.js +866 -0
  35. package/dist/pr-signals.js +407 -0
  36. package/dist/push-identity.js +71 -0
  37. package/dist/review-thread.js +247 -0
  38. package/dist/reviews.js +255 -0
  39. package/dist/run.js +271 -0
  40. package/dist/secrets.js +34 -0
  41. package/dist/session-start.js +257 -0
  42. package/dist/shell.js +329 -0
  43. package/dist/sys.js +291 -0
  44. package/dist/token-store.js +61 -0
  45. package/dist/types.js +1 -0
  46. package/dist/upgrade.js +186 -0
  47. package/dist/version.js +27 -0
  48. package/dist/work.js +847 -0
  49. package/package.json +47 -3
package/README.md CHANGED
@@ -1,3 +1,1449 @@
1
- # Temporary Holding Version
1
+ # niyam
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ niyam (नियम, rule) was named process-rules until 0.6.3. Its repository moved
4
+ from athya-hq/process-rules to veda-hq/niyam, and GitHub forwards the old
5
+ address. Since P-57 no release reads or writes the old names: see
6
+ [Renamed from process-rules](#renamed-from-process-rules).
7
+
8
+ Work rules for a repository that tracks its work in GitHub Issues and a GitHub
9
+ Project, with an owner account that approves and an agent account that builds.
10
+
11
+ Any repository can adopt it. No server, database or dashboard: a CLI, git
12
+ hooks and a shared GitHub Actions workflow.
13
+
14
+ ## Status
15
+
16
+ Early. The CLI runs `machine`, `doctor`, `session-start`, `guard`, `onboard`, `propose`, `upgrade` and `owner-step`. What comes next, and in what
17
+ order: the Slice issues under
18
+ [niyam roadmap v1](https://github.com/veda-hq/niyam/issues/22),
19
+ on the Project [process-rules work](https://github.com/orgs/athya-hq/projects/2) (its title from before the rename);
20
+ [docs/roadmap.md](docs/roadmap.md) keeps version v1 as approved. Decisions:
21
+ [docs/decisions.md](docs/decisions.md). Traps learned while building it:
22
+ [docs/lessons.md](docs/lessons.md).
23
+
24
+ GitHub means github.com: it is the only supported host. GitHub Enterprise
25
+ Server and GitHub Enterprise Cloud with data residency (GHE.com) are not
26
+ supported yet; every GitHub address in the CLI comes from one host constant,
27
+ so a host setting can be added later.
28
+
29
+ Claude Code is the only supported agent runner. The agent identity and the
30
+ GitHub lock reach a session through Claude Code's SessionStart hook and
31
+ `CLAUDE_ENV_FILE`, so an agent run from another tool (Codex, Cursor,
32
+ Copilot's agent, Aider, a plain script) gets neither, and only the pull
33
+ request's PR identity check catches its work, after the push. Other runners
34
+ wait for adoption outside Athya (#50).
35
+
36
+ ## Agent identity on a Mac
37
+
38
+ macOS is the supported platform: the agent's token lives in the macOS
39
+ keychain. On any other platform `machine` and `doctor` refuse, and
40
+ `session-start` keeps GitHub locked out of the session; Claude cloud sessions
41
+ need no keychain and work as before, and `doctor` runs its cloud checks there
42
+ (see Claude cloud sessions below). The token is read and stored through
43
+ one token-store interface (`src/token-store.ts`), so a Linux or Windows store
44
+ can be added there when an adopter needs one.
45
+
46
+ The adopting repo names its accounts in `.github/niyam.json`:
47
+
48
+ ```json
49
+ { "owner": "example-owner", "agent": "ExampleBot" }
50
+ ```
51
+
52
+ Each of `"owner"` and `"agent"` is a login or a non-empty list of logins,
53
+ such as `"owner": ["example-owner", "second-owner"]`; no account may be both.
54
+ Every check accepts anyone in a list: an approval, a 👍 or a `Decision:`
55
+ comment from any owner counts, and proposals, commits, pushes and pull
56
+ requests from any agent count as agent work. A Mac's agent sessions work as
57
+ one agent: the only one listed, or else the one listed that `machine` set up
58
+ on that Mac; with none of them set up there, or more than one, session-start
59
+ keeps GitHub locked out rather than guess. Messages that send someone to fix
60
+ a setup name the first owner. `onboard` writes the one-login form, and on a
61
+ repo whose settings list several it works as the owner named, else the
62
+ one the run's browser sign-in is, which must be listed, and the agent named,
63
+ else the one set up on the Mac; it leaves the lists as they are.
64
+
65
+ `niyam machine ExampleBot`, run once per Mac and agent account (inside
66
+ an adopting repo the name can be left out), needs no client repo. It makes the
67
+ agent's signing key (`~/.ssh/<agent, lowercased>_signing`), opens GitHub's
68
+ classic-token page with the scopes filled in (`repo`, `workflow`, `read:org`,
69
+ `project`, `write:ssh_signing_key`) and reads the token through a hidden prompt
70
+ into the keychain (service `niyam`), refusing a fine-grained token,
71
+ missing scopes or no expiry. It then registers the key as the agent's signing key, writes
72
+ `~/.config/niyam/<agent, lowercased>/session.sh`, and writes the
73
+ launcher `~/.config/niyam/bin/niyam`, which the Claude Code
74
+ hooks and the pre-push git hook run. Releases before P-55 wrote both under
75
+ `~/.config/process-rules/`, which nothing reads since P-57: `machine` removes
76
+ that folder, whole, once it has written the new one, and deletes the keychain
77
+ entry under the service `process-rules` once the `niyam` one holds the same
78
+ token (see Renamed from process-rules). The launcher names the node that ran `machine` by its real path (not a version
79
+ manager's per-shell one, which the Claude app's hooks may not have), so the
80
+ hooks need no node on their `PATH`. Why a classic token: [docs/decisions.md](docs/decisions.md).
81
+
82
+ `machine` first works out what it would change, changing nothing, and shows
83
+ one plan, in the same layout as `onboard`, listing only what changes. Then it
84
+ asks once:
85
+
86
+ ```
87
+ ◆ niyam machine AGENT
88
+ │
89
+ ◇ This Mac
90
+ │ signing key ~/.ssh/agent_signing (new)
91
+ │ token classic, in the keychain (new)
92
+ │ session file new
93
+ │ launcher ~/.config/niyam/bin/niyam
94
+ │
95
+ ◇ GitHub — as AGENT
96
+ │ signing key register
97
+ │
98
+ ◆ Go ahead? ● Yes ○ No
99
+ ```
100
+
101
+ No changes nothing. `--yes` goes ahead without asking, and `--dry-run` shows
102
+ the plan and stops. When nothing would change, it asks nothing and says
103
+ `◇ This Mac is set up for AGENT`, with or without a terminal. Otherwise,
104
+ with no terminal it refuses in one line unless given `--yes` or `--dry-run`.
105
+ A stored token GitHub refuses, or one that ends within 14 days, shows in the
106
+ plan as replaced. After the yes, each step shows as one `◇` line, or `■`
107
+ with why when it fails. The token's step opens GitHub's page, says in a few
108
+ short lines what to do there, and asks for the paste, hidden. A failed key,
109
+ token or key registration stops the run there, and nothing after it changes.
110
+ A failed lockout step stops nothing and goes under "Worth fixing". A run
111
+ that finishes ends with that group of `▲` lines, each with its one-line fix,
112
+ and `└ AGENT is ready on this Mac`. The SessionStart hook sources the
113
+ session file, so nothing is left to do by hand.
114
+
115
+ The trade-off, for adopters: the agent account holds one classic token, and
116
+ its `repo` scope reaches every repository the agent account can access, not
117
+ only the adopting one. Invite a dedicated agent account to the repositories
118
+ it works in and nothing else; the expiry bounds the rest. It is classic for
119
+ now because a fine-grained token waits on an organisation owner's approval
120
+ wherever the organisation requires it, reaches no repository where the agent
121
+ is only an outside collaborator, takes one token per organisation, and
122
+ cannot register the agent's signing key when an organisation owns it. An organisation or
123
+ enterprise that blocks classic tokens cannot adopt niyam yet:
124
+ `onboard` names the block and that an organisation owner can allow classic
125
+ tokens under Settings → Personal access tokens. A fine-grained token or a
126
+ GitHub App waits for adoption outside Athya.
127
+
128
+ A client's `.claude/settings.json` locks GitHub out of every session before
129
+ any hook runs: its `env` holds the lock's variables (a `GH_TOKEN` GitHub
130
+ refuses, no credential helper, GitHub's SSH remotes on HTTPS and every other
131
+ SSH remote refused), so a session whose hook never ran or failed reaches
132
+ GitHub as nobody, never as the owner. In a Claude cloud session the
133
+ SessionStart hook lifts it only once GitHub says the session is the agent
134
+ (see Claude cloud sessions below).
135
+
136
+ In Claude Code, the client's SessionStart hook runs `niyam
137
+ session-start`. It appends a lock to `CLAUDE_ENV_FILE`: a token GitHub refuses,
138
+ no credential helper, nothing inherited that could bring one back (`git -c`
139
+ injection, `GIT_CONFIG`, askpass), GitHub's SSH remotes on HTTPS and every
140
+ other SSH remote refused. Then, when this Mac has the session file `machine`
141
+ wrote for the agent the repo's settings name, exactly as `machine` writes it,
142
+ it appends that file, which replaces the lock with the agent's identity. Any
143
+ other outcome leaves GitHub locked out and says why, so a session never falls
144
+ back to the owner's login. When the CLI is missing or fails, the hook still
145
+ tells the session to stop, with what the CLI printed.
146
+
147
+ The line that tells a local session it works as the agent also tells it to
148
+ turn Auto-fix on for each pull request it opens. The Claude desktop app's
149
+ Auto-fix wakes a session on CI failures, merge conflicts and review comments,
150
+ and the app turns it on for a new pull request by itself only while that
151
+ session is open on screen, so a session started in the background (as a
152
+ coordinator starts its slice sessions) opens its pull request with Auto-fix
153
+ off. So after `gh pr create`, when the app's `ccd_pr` tools are there and
154
+ `get_status` shows `auto_fix` off, the session turns it on with
155
+ `set_monitor`. The app checks that the session opened the pull request and
156
+ that its `gh` login wrote it, which holds for the agent's own pull requests.
157
+ In auto mode the classifier refuses those calls unless the repo's
158
+ `.claude/settings.json` allows them, so `onboard` adds `mcp__ccd_pr__bind_pr`,
159
+ `mcp__ccd_pr__get_status` and `mcp__ccd_pr__set_monitor` to its
160
+ `permissions.allow`, and `doctor` warns under "This repo" (`▲`) about each
161
+ one an onboarded repo's file lacks. They reach the app only, not GitHub.
162
+
163
+ Before each Bash command, the client's PreToolUse hook runs `niyam
164
+ guard`: a command running `gh` or a git command that reaches a remote (push,
165
+ fetch, pull, clone, ls-remote, submodule, and `remote` update, prune, show (not `-n`),
166
+ `add -f`/`--fetch` (unless a later `--no-fetch`) and `set-head -a`/`--auto`;
167
+ not `remote get-url` and the other local `remote` subcommands) is refused,
168
+ with the reason,
169
+ unless session-start gave this session the agent identity. Hooks cannot see
170
+ the variables session-start gives the session's shells, so session-start
171
+ records how it left each session in
172
+ `~/.config/niyam/sessions/<session id>.json` and the guard reads that.
173
+ A command not naming `gh` or `git` as a word goes ahead without starting the CLI;
174
+ when the CLI cannot run, every command naming either is refused.
175
+
176
+ The guard also reads each comment an agent session posts or edits through
177
+ `gh`: `gh issue comment`, `gh pr comment`, and `gh api` on a comments
178
+ endpoint or in a GraphQL comment mutation, its body inline, in a heredoc, in
179
+ `$(cat file)`, or from `--body-file`, `-F body=@file` or `--input`. A
180
+ comment that asks the owner (it opens with `Needs you:` or `Proposal:`, past
181
+ any Markdown emphasis, or names an owner login, with or without `@`) must
182
+ link a published page (`https://claude.ai/artifact/…` or
183
+ `https://claude.ai/code/artifact/…`) and fit 500 characters; otherwise it is
184
+ refused, naming the rule and the fix: publish the page, then post the
185
+ question, the link and how to answer. A body the guard cannot read in full
186
+ (a variable, a command substitution other than `cat`) is judged by what it
187
+ spells out; where that asks the owner, or the body opens with the unknown
188
+ part, it is refused with how to write it so the guard can read it; so is a comment with no body in the command, which gh would take from an editor, a prompt or the browser. Commands inside `$(…)`, backquotes and `sh -c` are read too. `propose`
189
+ posts through GitHub's API, not through `gh`, so this check does not see
190
+ it; `propose` holds its own comments to the same rule before posting them.
191
+
192
+ The session file holds no secret: `GH_TOKEN` is read from the keychain on each
193
+ use, and is a value GitHub refuses when the keychain has none. Git gets a
194
+ credential helper that drops every earlier one and hands the agent's token to
195
+ github.com only, commits as the agent's no-reply address and signs with its
196
+ key.
197
+
198
+ The lock lives in the session's environment, which a session that ignores it
199
+ could change. So `machine` also locks the owner away, as optional hardening
200
+ for a machine that runs agents. Its plan lists signing `gh` out of every
201
+ account other than the agent's, active or not, and removing a git password
202
+ for github.com saved in the macOS keychain. The one yes covers them, and a no
203
+ leaves them in place with everything else. On a laptop you also use for your
204
+ own work, saying yes signs you out of your own GitHub tooling. The stronger
205
+ alternative is a separate macOS user that runs only the agent sessions: none
206
+ of your logins, keychain or SSH keys are in it, and nothing of yours is signed
207
+ out. A sign-out that fails stops nothing; it goes under "Worth fixing". So
208
+ does each SSH key in `~/.ssh` with no passphrase, with
209
+ `ssh-keygen -p -f <key>` to add one; agents' signing keys are left out,
210
+ since sessions sign with them and they have no passphrase on purpose. The owner's SSH access is left alone,
211
+ since it is the owner's own way to GitHub (docs/decisions.md). Agent sessions
212
+ send GitHub over HTTPS and refuse SSH, and the pre-push hook refuses their
213
+ pushes over SSH. `doctor` names the account SSH reaches GitHub as without
214
+ asking (a key in the SSH agent or the keychain), as fine.
215
+
216
+ Releases before 0.5.21 asked about each lockout step on its own, and recorded
217
+ what was declined in
218
+ `~/.config/niyam/<agent, lowercased>/lockout-declined.json` (under
219
+ `~/.config/process-rules/` before P-55, which nothing reads since P-57).
220
+ `doctor` reports a login or password in that record as your choice instead of
221
+ warning, and an account signed in later is still a warning. Once a `machine`
222
+ run locks them away, the record goes.
223
+
224
+ When `machine` signs an account out of `gh`, "Worth fixing" ends with two
225
+ steps only you can take. Restart the Claude desktop app: it keeps the `gh`
226
+ token it read before the move until it restarts, so until then its own
227
+ GitHub actions (Auto-fix, the PR bar) run as you, and Auto-fix refuses the
228
+ agent's pull requests. And revoke the old token on GitHub (Settings →
229
+ Applications → Authorized OAuth Apps → GitHub CLI): `gh auth logout` deletes
230
+ it from the Mac but does not revoke it. `machine` records the move in
231
+ `~/.config/niyam/<agent, lowercased>/gh-moved.json`, and `doctor`
232
+ repeats both steps while the desktop app was started before it. `doctor`
233
+ cannot see whether the token was revoked, so once the app has restarted it
234
+ no longer reminds you to revoke it.
235
+
236
+ The owner is never signed in to `gh`, and needs no sign-in kept anywhere on
237
+ the Mac. When a run of `onboard` (or `onboard --add`) reaches a step that
238
+ acts as the owner (giving the agent access, setting up the board, or
239
+ setting the `FIGMA_LIBRARY` secret from an older setting), it
240
+ asks for one browser approval, which serves the rest of that run; a run
241
+ with no such step asks for none. That approval comes after the plan's yes,
242
+ unless only it can tell what the plan is: which of several owners the
243
+ settings list ran it, or, on a first run with no owner named, whom to
244
+ suggest; the pull request then says so. It runs `gh auth login --web` into a
245
+ fresh temporary `gh` folder, asking for gh's own scopes (`repo`,
246
+ `read:org`, `gist`) plus only those the run's features add (`project` for
247
+ the board, and `admin:org` in an organisation), reads the token from
248
+ there, refuses it unless it is the owner's, and deletes the folder
249
+ whatever happens. Its line names the account to sign in as (each owner the
250
+ settings list, while the run has not chosen one). `onboard` reads `gh`'s
251
+ output rather than showing it: it shows the one-time code and opens the
252
+ link in the browser, drops `gh`'s tips and its notes about setting up that
253
+ temporary folder, and shows any other line, an error included, as `gh`
254
+ wrote it. The
255
+ token lives in the command's memory for that run; the owner's own `gh`
256
+ config and keychain are never read or written, so there is nothing to sign
257
+ out of afterwards.
258
+
259
+ A request to GitHub or Figma that gets no answer at all stops the command
260
+ with which request it was and why, such as `GET
261
+ api.github.com/repos/…/actions/secrets/public-key could not be made:
262
+ ECONNRESET (other side closed)`, never its query or token. A GET, PUT or
263
+ DELETE, which can be repeated safely, is tried once more a second later
264
+ first; a POST or PATCH never is. A call with a time limit keeps it for
265
+ both tries, and one that runs out of time stops with that, not tried
266
+ again.
267
+
268
+ `niyam doctor` only reads. It re-checks the key, the token and its
269
+ scopes, the key's registration, the session file, that the launcher runs,
270
+ that the CLI is the newest release (`▲` when a newer one is out, fixed by
271
+ `niyam upgrade`) and the only `niyam` on `PATH` (`✗`
272
+ otherwise, naming each copy and its version), anything left from before
273
+ niyam (`~/.config/process-rules/`, or a keychain entry under the service
274
+ `process-rules`: `▲`, which `niyam machine` removes), and
275
+ what of the owner's an agent session could reach, any `owner-step` folder
276
+ left behind (`▲`, saying whether it still holds a token; see Owner steps), and, in a repository with
277
+ the board on, the organisation's issue types (see Issue types). It shows them grouped as
278
+ This Mac, GitHub and This repo, one line each: `✓` fine, `▲` worth fixing,
279
+ `✗` broken. Each problem line ends with its fix:
280
+
281
+ ```
282
+ ◆ niyam doctor AGENT
283
+ │
284
+ ◇ This Mac
285
+ ✓ signing key ~/.ssh/agent_signing
286
+ ✓ session file
287
+ ✗ launcher missing, so hooks need node on PATH → niyam machine
288
+ ▲ niyam 0.5.20 runs here; 0.5.30 is out → niyam upgrade
289
+ │
290
+ ◇ GitHub — as AGENT
291
+ ▲ token ends in 11 days → niyam machine
292
+ ✓ signing key registered
293
+ │
294
+ └ 3 to fix
295
+ ```
296
+
297
+ It closes with `└ All good` or `└ N to fix`, and exits 1 when anything is
298
+ `✗`. A token that ends within 14 days is `▲`, and still exits 0. It needs no
299
+ terminal. In a Claude cloud session it runs the cloud checks instead (see
300
+ Claude cloud sessions below).
301
+
302
+ ## Adopting
303
+
304
+ 1. On each Mac that runs agent sessions: `niyam machine <agent>`.
305
+ Only you can run it: it asks for the agent's token and makes its signing
306
+ key. `onboard` refuses on a Mac it has not set up, naming what is missing.
307
+ 2. In the client repository, as its owner: `niyam onboard`. It
308
+ suggests the owner from the run's browser sign-in (below) and the agent from the accounts
309
+ `machine` set up on this Mac, for you to confirm (or name them:
310
+ `niyam onboard <owner> <agent>`). It first works out everything
311
+ it would change, changing nothing, and prints that as one plan, then asks
312
+ once:
313
+
314
+ ```
315
+ ◆ niyam onboard v0.5.17 → v0.5.20
316
+ │ owner/repo · owner OWNER · agent AGENT
317
+ │
318
+ ◇ Pull request
319
+ │ workflow pins → v0.5.20
320
+ │ cloud-setup.sh new, installs v0.5.20
321
+ │ auto-merge when checks pass
322
+ │
323
+ ◇ GitHub — one sign-in as OWNER
324
+ │ board set up or check
325
+ │ issue types org-wide: retype 1, disable 3
326
+ │ example-app#12 Task → Brief
327
+ │ disable Task, Bug, Feature
328
+ │
329
+ ◇ This Mac
330
+ │ pre-push hook new
331
+ │
332
+ ◇ Claude cloud — by hand, once per claude.ai account
333
+ │ claude.ai's GitHub as AGENT
334
+ │
335
+ ◇ Check
336
+ │ one signed test commit by AGENT, deleted after
337
+ │
338
+ ◆ Go ahead? ● Yes ○ No
339
+ ```
340
+
341
+ It shows only what changes, in a few words each; the pull request's
342
+ description holds each change in full. No changes nothing and opens no
343
+ pull request. `--yes` goes ahead without asking, and `--dry-run` prints
344
+ the plan and stops, changing nothing and signing in to nothing, so where
345
+ only a sign-in could tell which of the settings' owners runs it, a dry
346
+ run asks you to name the owner. Without a terminal, `onboard` refuses
347
+ unless given `--yes` or `--dry-run`. After the yes it shows one line per step, a
348
+ spinner while it works, and ends with the pull request and a short "By
349
+ hand:" list of what GitHub's and Claude's APIs cannot do. Each line there
350
+ is one sentence on standard output saying the whole step: how often (now,
351
+ once for the repository, once per claude.ai account), what to do, and its
352
+ link. A first onboarding with the review routine ends:
353
+
354
+ ```
355
+ By hand:
356
+ Once for owner/repo: in Claude Code, run /schedule and create a weekly routine on it, with claude.ai's GitHub connected as AGENT and the prompt below the line in https://github.com/veda-hq/niyam/blob/v0.6.15/routines/review.md.
357
+ Once per claude.ai account: sign in at https://claude.ai/code and connect GitHub as AGENT (or change it at https://claude.ai/customize/connectors); skip it if done.
358
+ ```
359
+
360
+ It writes `.github/niyam.json`, adds to `.claude/settings.json`
361
+ the lock in `env`, a SessionStart hook running `niyam session-start`, a
362
+ PreToolUse hook running `niyam guard` (each through the launcher `machine`
363
+ writes, else `niyam` on PATH; hooks an older release wrote are replaced
364
+ in place, 0.6.10's too), and `permissions.allow` rules
365
+ for `niyam review-thread` (replacing the rule under the old command) and for
366
+ the app's `mcp__ccd_pr__bind_pr`, `mcp__ccd_pr__get_status` and
367
+ `mcp__ccd_pr__set_monitor`, which turn Auto-fix on (a rerun adds only
368
+ the ones missing), and
369
+ writes `.github/workflows/niyam.yml`, which calls this repository's
370
+ shared checks (`.github/workflows/checks.yml`) from two jobs: `niyam`
371
+ on pull requests and pushes, read-only, and `niyam-weekly` on the
372
+ weekly run, the only one that writes to issues. Each job carries a
373
+ `name:` (`niyam`, `niyam-weekly`, …), so its checks read
374
+ `niyam / Work rules`. With identity alone `onboard` writes no workflow. It writes
375
+ `.github/niyam/cloud-setup.sh`, which installs the CLI in Claude
376
+ cloud sessions at the version the workflow pins, and writes it again on
377
+ every run (see Claude cloud sessions below); a cloud session with no
378
+ niyam runs it from the SessionStart hook, so there is nothing to paste,
379
+ and the first time, the plan lists the one connection of claude.ai's
380
+ GitHub as the agent, once per claude.ai account. Where the
381
+ repo still has `.github/process-rules/cloud-setup.sh`, which releases up
382
+ to 0.6.10 wrote beside it, the pull request deletes it, but only where it
383
+ leaves `.github/niyam/cloud-setup.sh` (one the run could not write, as
384
+ when GitHub names no sha256 for the release, keeps the old file too), and
385
+ the description says to delete niyam's part of a Setup script pasted
386
+ before 0.6.10. It checks the agent can
387
+ push. With no access, or read access only (a public repo, or an
388
+ organisation's base permission), the plan gives it write access as you
389
+ and accepts the invitation as the agent; and `onboard` names
390
+ an organisation that
391
+ requires SAML authorisation or blocks classic tokens. As the owner (with
392
+ the `project` scope, and `admin:org` in an organisation), it sets up the
393
+ work board: the organisation's issue types
394
+ (Work item, Slice, State, Decision, Brief; see Issue types below), the repo's labels (`approved`,
395
+ `needs-owner`, `mechanical`, `veto`, `expiring`, `cannot-run-here`), and a
396
+ Project "<repo> work" linked to the repo. It makes that Project by copying
397
+ the product's public [niyam template](https://github.com/orgs/athya-hq/projects/4),
398
+ which holds the fields Step (Frame, Specify, Slice, Build, Done), Decision
399
+ and Review date and the views Needs
400
+ you (`label:needs-owner is:open`), Board (`type:Slice,Brief`, by Status,
401
+ showing linked pull requests), Work items (`type:"Work item"`, grouped by Step), Decisions
402
+ (`type:Decision`, grouped by Decision) and Reviews due (`"Review
403
+ date":<=@today`), with its workflows; so the board needs nothing done by
404
+ hand. What the board lacks is known only once you have signed in, so the
405
+ plan says "set up or check"; issue types are an organisation-wide
406
+ setting, so the plan says "org-wide" and lists what it would change. If
407
+ a copy's workflows arrive off, "By hand:" links where to turn them on. A
408
+ Project of that title made before the template is left as it is: the plan's
409
+ yes does not replace it. When GitHub refuses the copy, or for such an
410
+ older Project, `onboard` adds the fields and makes or updates the views
411
+ itself, and "By hand:" links the Project for the three things GitHub's API
412
+ cannot set: the Type column on Needs you (`+` at the right of the
413
+ headers → Type, then Save), the grouping, and the auto-archive workflow.
414
+ GitHub's API cannot even see a Type column, so `onboard` sends a view's
415
+ columns only when they differ from what it asks for: a rerun keeps Type.
416
+ When it does set Needs you's columns, it says Type may be gone and how to
417
+ add it again. On any Project it
418
+ adds an option a field lacks, such as Step's Done on one made before it,
419
+ sending each option it keeps with its id, so no item loses its value. The Board keeps a
420
+ closed slice or brief in Done until that workflow archives it, with the
421
+ filter `is:closed updated:<@today-7d`: a week. A view's filter cannot do
422
+ this, since GitHub's Project filters join different fields with AND alone
423
+ and have no closed date, and GitHub's API can neither read nor set a
424
+ workflow's filter. Last, it pushes
425
+ one signed test commit as the agent to a throwaway branch, checks GitHub
426
+ shows it Verified by the agent (asking again when the network or GitHub
427
+ fails for a moment), and deletes the branch. The steps that act as you
428
+ (giving the agent access, the board, the `FIGMA_LIBRARY` secret) share one browser approval, for
429
+ that run only. The files git tracks in your checkout are never changed: once every step has run,
430
+ `onboard` commits the files it changes as the agent, signed, on the
431
+ branch `niyam/onboard` from the default branch's tip, in a
432
+ temporary repository it deletes afterwards, pushes it as the agent and
433
+ opens the agent's pull request (or updates the one an earlier run opened),
434
+ titled `chore(niyam): onboard at v<version>`, as Conventional
435
+ Commits reads it, and its commit the same. Where most of the default
436
+ branch's latest 20 commit subjects, merge commits aside, lead with an
437
+ emoji or a gitmoji shortcode, so does the title: the one an earlier
438
+ onboard commit had, else the one the repo puts most on chores, else `🔧`
439
+ (`:wrench:` where shortcodes are the style). Where the default branch's
440
+ Mergify configuration (the first of `.mergify.yml`, `.mergify/config.yml`
441
+ and `.github/mergify.yml`) has a queue rule and queues pull requests by
442
+ itself, through a rule whose actions hold `queue` and whose conditions
443
+ ask for no label, or merge protections' `auto_merge_conditions` set to
444
+ `true` or to conditions that ask for no label, the merge queue merges the pull
445
+ request, and the run ends "<url> the merge queue merges it when checks
446
+ pass". Otherwise it turns on GitHub's
447
+ auto-merge for that pull request as the agent, squashing where the repo
448
+ allows it (else rebasing, else merging), so it merges itself once its
449
+ checks pass, and any review the repo's rules require is given. Where the
450
+ repo does not allow auto-merge, or GitHub refuses it (as it does for a
451
+ pull request already clean to merge), the run still succeeds: it ends
452
+ "Merge <url>", and "By hand:" says why. A run
453
+ that changes no file, or that stops, opens none. A file the default branch has otherwise than your
454
+ checkout is refused, so bring the checkout up to date first. The pre-push
455
+ git hook, which git does not track, is written in place. The work rules
456
+ pass that pull request without a `Slice:` line while it changes only the
457
+ files `onboard` writes. `onboard` leaves the repo's CODEOWNERS as it is:
458
+ when a rule there names you, GitHub asks you to review the agent's pull
459
+ requests that change the files it matches, and the repo's own rules
460
+ decide whether that review is required. An existing `.claude/settings.json`
461
+ keeps its layout: `onboard` adds only its entries, and replaces the hook
462
+ entries an older release wrote where they stand. The repository needs at
463
+ least one commit. The pull request checks read the settings from the base
464
+ branch, so a pull request cannot rename the agent it is checked against.
465
+ The pull request that first commits them, `onboard`'s, passes PR identity, Work rules
466
+ and Design frames, saying the repo is not adopted on its base yet, as for
467
+ a feature that is off; they apply from the next pull request.
468
+
469
+ The shared checks run five jobs. **Settings** validates
470
+ `.github/niyam.json`, and fails when a job's `niyam-ref`
471
+ names another release than the `checks.yml@` line it calls (see Releases and
472
+ upgrading). **PR identity** runs on pull requests: every
473
+ commit that claims the agent (its login or its no-reply address) must be
474
+ Verified as the agent, and agent commits must be pushed by the agent, so agent
475
+ work pushed with the owner's login fails. Who pushed comes only from GitHub's
476
+ record of the pushes to the pull request's branch (the fork's, for a fork),
477
+ never from whoever started the run, so an edit, a reopen or a re-run by anyone
478
+ gives the result the push gave. A push GitHub has not recorded yet is waited
479
+ for about a minute, then fails until a re-run finds it. A merge queue's test runs
480
+ pass with nothing to check, since each queued pull request was checked on its own:
481
+ a `merge_group` run, and a pull request `mergify[bot]` opened from a
482
+ `mergify/merge-queue/` branch of the repository itself (anyone else's pull request
483
+ on such a branch is checked). **Work rules** runs on the agent's
484
+ pull requests: each names exactly one slice, as a line `Slice: #N`, and that
485
+ slice may be built:
486
+
487
+ - it is a Slice issue under a Work item the owner labeled `approved`;
488
+ - if it was added to the work item after the approval, the owner approved
489
+ it: a 👍 on the agent's proposal for it, made after it was added, a
490
+ comment starting `Decision:` naming it, or the owner's own request: a
491
+ comment they wrote on the work item before the slice was last added,
492
+ which the slice's body links (`…/issues/<work item>#issuecomment-<id>`)
493
+ and they have not edited since. Which comment asked for the slice is the
494
+ agent's claim, shown in the slice's body: the comment came first, so it
495
+ cannot name the slice;
496
+ - each of its State sub-issues closed as not planned after the approval
497
+ carries the owner's approval: a 👍 on the agent's proposal for it, or a
498
+ `Decision:` comment;
499
+ - no other open pull request names it;
500
+ - each State it names with a line `State: #N` is a State sub-issue of the
501
+ slice, and when the slice is closed already, so the pull request is a fix,
502
+ it names at least one open State: the one the fix is filed as.
503
+
504
+ **One comment answers a batch.** Settings that name the repository's standing
505
+ Approvals issue (`"approvals": N`) let the owner answer many asks at once:
506
+ an owner's comment there whose first line opens `Decision: approve`, then
507
+ `#N` for each issue it approves (`Decision: approve #31 #12 #40`). Only that
508
+ line approves; the lines under it are reasons, so `Not #44 yet` approves
509
+ nothing. The work rules take it for a slice added after the approval when it
510
+ names the slice and was made after the slice was last added, and for a
511
+ dropped State when it names the State and was made after the State was
512
+ closed. They read the Approvals issue's comments once a check, only when a
513
+ decision is owed. If GitHub cannot find the Approvals issue, it answers
514
+ nothing and the check goes on.
515
+
516
+ A `Decision:` comment, a batch answer included, counts only while it says
517
+ what owners wrote: unedited, or edited by owners alone. Repo writers, agents included, can edit anyone's
518
+ comment, and only GitHub's GraphQL API (`userContentEdits`) names who made
519
+ each edit, so the work rules read it for an owner's edited `Decision:` alone;
520
+ an unedited one is read through REST, as before. Where GraphQL is refused, as
521
+ in a Claude cloud session, an edited `Decision:` does not count, and the
522
+ refusal says why.
523
+
524
+ **The board follows the work.** When an agent session's push names a slice
525
+ the work rules let it build, pre-push moves the board on, as the agent, on
526
+ every open Project of the repository's owner that holds the issues: the
527
+ slice's Status to In Progress; its work item's Step to Build, since its first
528
+ slice has started; and every other Work item of the repository to the Step
529
+ GitHub's facts give it. A closed work item is at Done; an open one is at
530
+ least Frame, where a new one starts, at least Slice once it has sub-issues,
531
+ and at least Build once one of them is closed. Nothing on GitHub marks
532
+ Specify, so the owner sets it by hand and it stays. A Step moves only
533
+ forward, except that a reopened work item leaves Done, and an option the
534
+ owner added to Step is left alone. So once Step has Done, the Work items
535
+ view groups no closed work item under Frame, Specify, Slice or Build, and
536
+ none under "No Step", but for one the owner put at an option of their own. The items it reads
537
+ hold their issues, so this reads no issue on its own. A Project whose Step
538
+ has no Done, made before it, gets one line saying so, and `onboard` adds the
539
+ option, keeping every item's Step. A workflow's `GITHUB_TOKEN` cannot write to a Project, so the
540
+ agent's push does this, with the agent token's `project` scope, with `board`
541
+ on. It uses GitHub's REST API for Projects alone, so it works through a
542
+ Claude cloud session's GitHub proxy, which refuses GraphQL.
543
+ A board it cannot read, or a move GitHub refuses, is said and does not stop
544
+ the push; a push for a closed slice, such as a fix, moves nothing. When a pull request naming a slice merges into the default branch,
545
+ the shared workflow comments on the slice, linking the pull request, and
546
+ closes it, and the Project's Item closed workflow moves it to Done: a
547
+ `Slice: #N` line is not one of GitHub's closing keywords, so GitHub does not
548
+ close it. Each State under that slice the pull request names with a line
549
+ `State: #N` gets the same comment and is closed as completed too; a State
550
+ named only in prose stays open, a State closed as not planned is left as it
551
+ is, and so is one under a slice the pull request does not name. A slice or
552
+ State GitHub closed already, through a closing keyword such as "Closes #N"
553
+ beside it, still gets the comment; one that has it gets no second one. That job alone of a pull request's runs writes to issues. It runs only for
554
+ pull requests from the repository itself: a fork's run gets a read-only token, so
555
+ a slice a fork's pull request builds is closed by hand.
556
+
557
+ **What needs the owner.** A request the owner made on the work item is its
558
+ own approval, linked as above. A fix needs none: it restores what the owner
559
+ approved and changes nothing they would see beyond it, so it is filed as a
560
+ State under the slice it fixes and its pull request names that slice, with
561
+ `Slice: #N`, and the State, with `State: #N`, which closes the State on merge. The
562
+ State needs no approval, though that slice's own approval rules still apply,
563
+ as for any pull request naming it. A request made in chat is filed as a slice quoting the
564
+ owner's words and proposed once. Anything else the agent adds, a fix filed
565
+ as its own slice included, waits for the owner's 👍.
566
+
567
+ **Approving with one tap.** In an agent session, `niyam propose
568
+ <issue> --page <url>` asks the owner for what a slice owes: given the slice, it comments
569
+ on it as the agent, one `Proposal:` comment for its addition after the
570
+ approval and one for each State dropped after it (given a State, for that
571
+ state alone), mentioning the owner, and labels the slice `needs-owner`, so it
572
+ shows in the owner's Needs you view and their GitHub notifications. Each
573
+ proposal is a pointer, as every ask to the owner is: one line naming what it
574
+ proposes, `Page: <url>` and how to answer, in at most 500 characters. The
575
+ page, which the agent publishes first and names with `--page <url>` (one page
576
+ for the whole run), argues it: what changes and why, from the slice's
577
+ `**You will see:**` and `**Why:**` sections (a dropped State's own
578
+ `**Why:**`), what it costs and what happens if the owner declines. Without
579
+ `--page`, a proposal still to be posted is refused, posting nothing, with
580
+ the command to run; a `--page` that is no published page is refused before
581
+ GitHub is asked anything. It also refuses, posting nothing, while a
582
+ body lacks those sections, naming them, and when a comment would break the
583
+ guard's rule (a title so long the comment runs over 500 characters). The owner
584
+ approves a proposal by reacting 👍 to it, from the phone or the web; a typed
585
+ `Decision:` comment still works. A 👍 counts only from the owner, only on the
586
+ agent's comment starting `Proposal:` whose first `#N` is the slice or state
587
+ it approves, and only when made after the proposal's last edit (and, for a
588
+ slice, after it was last added). Run again, `propose` posts nothing twice, and
589
+ once the owner has approved everything it takes `needs-owner` off. Each run
590
+ prints, for each decision still waiting, the link GitHub gives its newest
591
+ proposal, posted now or before: the comment's own `#issuecomment-` address,
592
+ where the owner reacts, never the slice's top or the `needs-owner` list. A
593
+ waiting decision with no proposal yet gets the command that posts one,
594
+ `niyam propose <issue> --page <page url>` with its number. A
595
+ reaction does not re-run a pull request's checks: the agent proposes before
596
+ it starts, and pre-push or a re-run of Work rules sees the 👍.
597
+
598
+ **Many at once.** `propose` takes several issues, `niyam propose 12
599
+ 30 41 --page <url>`, and asks for each in turn, each comment linking that page. Where the settings name an Approvals issue
600
+ (`"approvals": N`), each proposal also says it can be answered in the batch
601
+ on Approvals, and the run ends with that issue's link and the first line of
602
+ the owner's answer there, ready to paste: `Decision: approve #12 #30 #41`,
603
+ one number per proposal still waiting (a slice for its addition, a State for
604
+ its drop). The owner pastes it as a comment on Approvals, deleting any number
605
+ they refuse. The agent hands the line over and never posts it: only the
606
+ owner's own comment approves anything. The Needs you job reads each
607
+ proposal by its own number, so a slice whose only waiting proposal is a
608
+ State's leaves Needs you as soon as the batch names the State.
609
+
610
+ **The Needs you list keeps itself.** With `board` on, the client workflow's
611
+ `niyam-asks` job runs `niyam needs-owner`. An agent's comment
612
+ opening with `Needs you:` or `Proposal:`, on an issue, a pull request or a review thread, labels its issue or pull request
613
+ `needs-owner`, so it shows in the owner's Needs you view. On an issue, the
614
+ owner's `approved` label or `Decision:` comment takes the label off at once;
615
+ on a pull request, where a label approves nothing (approvals are given on
616
+ issues only), the owner answers with a `Decision:` comment, which takes it
617
+ off at once, or a 👍 on the ask, which the hourly sweep counts. The sweep
618
+ reads an issue's or pull request's own comments, not review threads, so an
619
+ ask in a review thread is answered with a `Decision:` reply there. Hourly
620
+ (cron `41 * * * *`), on a run by hand, and at once when the owner posts a
621
+ batch answer on the Approvals issue, a sweep takes it off each open issue
622
+ whose every agent ask the owner has answered. Each `Proposal:` is an ask of
623
+ its own, for the issue its first line names first (a slice for its addition,
624
+ a State for its drop; the issue itself when it names none); a `Needs you:` is
625
+ one when it is the latest agent ask there. An ask is answered by a 👍 on it
626
+ after its last edit, a `Decision:` comment after it on the issue, or a batch
627
+ answer after it on the Approvals issue whose first line names its issue,
628
+ that no one but owners edited. So a batch naming one proposal on a slice
629
+ leaves the slice on Needs you while another there waits. A proposal for the
630
+ slice's own addition counts only answers after the slice was last added to
631
+ its work item, so a slice taken out and added again waits on the owner
632
+ again. The sweep reads that from the slice's own timeline; unlike the work
633
+ rules, it misses an addition GitHub records only on the work item's. An issue labelled
634
+ with no agent ask on it, such as the weekly job's undo issues, is left as it
635
+ is, unless the owner's batch answer names it. Only comments
636
+ that may ask or decide, from the owner, a member or a collaborator, the
637
+ `approved` label and the hourly cron start the job, so other comments, and an
638
+ outsider's, run nothing.
639
+
640
+ **Answering review threads.** In an agent session, `niyam
641
+ review-thread <thread-id> --reply <text> --resolve` replies on a review
642
+ thread (`PRRT_…`), resolves it, or both, as the agent. It refuses unless the
643
+ session's token is the agent's and the thread is on a pull request the agent
644
+ opened in the repository here. `onboard` allows exactly this command in
645
+ `.claude/settings.json` (`Bash(niyam review-thread *)`), so answering
646
+ review findings on its own pull requests needs no prompt, even in Claude
647
+ Code's auto mode, where an allow rule settles a command without the
648
+ classifier. It allows the command, not `gh api`: a rule cannot hold `gh
649
+ api`'s arguments to one endpoint, since its `*` matches anything after it.
650
+
651
+ The reply can come from a file, `--body-file <path>`, since replies hold
652
+ backticks and braces that a shell guard may refuse in an argument. The file
653
+ must be in the repository, such as under `.tmp/`, since the allow rule runs
654
+ the command without a prompt. A reply from a file resolves the thread unless
655
+ `--no-resolve` is given. `--reaction
656
+ +1` or `-1` with `--comment-id <id>` reacts on one of the thread's comments;
657
+ a reaction that fails is a warning, and the thread is still resolved. A
658
+ reply already on the thread, compared without surrounding space, is not
659
+ posted again, so a rerun is safe.
660
+
661
+ On a machine it uses GitHub's GraphQL API, and a thread is named by its node
662
+ id (`PRRT_…`). In a Claude cloud session, whose proxy refuses GraphQL, it uses
663
+ the proxy's own REST routes (`pulls/{n}/ccr/review_threads` and
664
+ `pulls/{n}/ccr/comments/{id}/resolve`), and a thread is named by its first
665
+ comment's number, the one in its `#discussion_r` link. The proxy appends a
666
+ Claude Code footer to what it posts, so a reply there is compared without it.
667
+ An id in the other form is refused before any request.
668
+
669
+ **Reading a pull request's signals.** `niyam pr-signals <pr> [--ci-only]`
670
+ prints one JSON object: the pull request's open review threads, its failing
671
+ checks and the local review's findings, as one list of signals with
672
+ duplicates folded together, and its resolved threads, to tell a new finding
673
+ from one already answered. Each thread's signal carries the ids
674
+ `review-thread` takes there (`thread`, and `comment` for a reaction). A
675
+ failing check run from GitHub Actions brings the error lines of its job's
676
+ log, 40 at most; another check brings its name, conclusion and summary.
677
+ Every page of every list is read to its end, and a page that says more follow
678
+ without a cursor stops the run: a short list never reads as the whole one. A
679
+ pull request that is merged or closed is refused (exit 3 or 4, and
680
+ `"ok": false` on standard output) before anything is read, and again before
681
+ printing, as one can merge while its signals are read. `--ci-only` reads the
682
+ checks alone.
683
+
684
+ A repository with a local review, one that runs before a push and writes its
685
+ findings to a file, names it in `.github/niyam.json`, with the logins of its
686
+ review bots:
687
+
688
+ ```json
689
+ { "signals": { "bots": ["review-bot"], "findings": ".tmp/review/findings.json" } }
690
+ ```
691
+
692
+ The file holds `{"issues": [{"title", "description", "file", "line",
693
+ "priority"}], "metadata": {"status"}}`. A finding citing a file the pull
694
+ request does not change is dropped, as another branch's. A file whose
695
+ `metadata.status` is `failed` is reported as a failed review, never a clean
696
+ one. A bot's thread and the local finding at the same file and line are one
697
+ signal: the same review, posted twice.
698
+
699
+ **The hand-off gate.** A session working on one thing that trips over
700
+ another, not its fault, fixes the other thing worse than a session with no
701
+ stake would: it wants its own work unblocked. No program can see that
702
+ moment, so the gate prices two of its footprints. A push whose branch edits
703
+ the repository's shared plumbing, or whose push history shows one stage
704
+ failing three times across two working trees or more, needs a declaration
705
+ first:
706
+
707
+ ```sh
708
+ niyam handoff --detect # what fires, as JSON
709
+ niyam handoff --record --disposition own-work --reason "the workflow change is this slice"
710
+ niyam handoff --record --disposition handed-off --reason "..." --open-brief .tmp/brief.md
711
+ ```
712
+
713
+ `own-work` is one sentence. `handed-off` names a Brief issue (`--brief #N`,
714
+ or `--open-brief <draft.md>`, which lints the draft and opens it as one, on
715
+ the board `.github/niyam.json`'s `project` names). `carrying` also owes
716
+ `## What I verified` and `## Why I did not hand off`, and may blame a file
717
+ the branch changed. `dismissed` cites where the owner decided (`#123`, a
718
+ link, an id such as `ABC-123`, or a commit). `niyam pre-push` runs the gate
719
+ for an agent session, right after the identity check; `niyam handoff
720
+ --assert-fresh` runs it alone, for a hook of the client's own. It passes
721
+ when nothing fires, and otherwise only when the session's newest
722
+ declaration (`--call-site push-skill`, the default) covers this head, this
723
+ base and every trigger that fired. A blocking
724
+ brief handed off holds the push until a merged pull request saying
725
+ `Fixes #N` closes it and this branch has its merge commit, or it is closed as
726
+ not planned. Declarations and the gate's verdicts are JSON lines in
727
+ `.tmp/push/handoff-log.jsonl`. `niyam brief [--lint] <draft.md>` opens a
728
+ draft, or only checks it.
729
+
730
+ A brief draft has YAML frontmatter (`slug`, `title`, `discovered-on`: this
731
+ branch, `blocking: yes|no`, `status: open`, `blamed-paths`: a list of files,
732
+ none in the branch's own diff) and five sections: `## What happened`, with
733
+ the command and its output in a fence, `## Why this is not caused by the
734
+ originating branch`, `## Hypothesis (UNVERIFIED)`, `## What the receiving
735
+ session must verify first` and `## Sequencing`. The gate is on where the
736
+ repository names its plumbing; a folder ends in `/`, anything else is one
737
+ file by its whole path. The copy of the settings on the remote's default
738
+ branch (or the `--base` asked for) decides when it names one, the settings
739
+ file always counts as plumbing, and the base must be a remote-tracking
740
+ branch, so a branch cannot turn the gate off in the push the gate judges:
741
+
742
+ ```json
743
+ {
744
+ "handoff": {
745
+ "plumbing": [".github/workflows/", ".husky/", "package.json"],
746
+ "history": ".tmp/performance/history.jsonl",
747
+ "ignoreStages": ["checking-incidental-handoff-declarations"],
748
+ "template": "docs/templates/brief.md",
749
+ "base": "origin/main"
750
+ }
751
+ }
752
+ ```
753
+
754
+ `history` is the push history, one JSON line per hook run with its `kind`,
755
+ `exitCode`, `branch`, tree `fingerprint` and `stages` (`name`, `status`);
756
+ without one, only the plumbing trigger fires. A line that is not a whole run
757
+ is skipped, never counted.
758
+
759
+ **Dismissing a Cubic finding.** A wrong finding is the agent's call; a true
760
+ one left unfixed is the owner's. `niyam cubic-dismiss --evidence <proof>
761
+ --title <exact title> --reason <why>` records one the agent proves wrong:
762
+ the proof is a path at HEAD (a `#section` or `:line` may follow), a commit
763
+ HEAD contains by its full 40-hex id, or a title already dismissed, and one
764
+ that does not resolve is refused. `--decision <where the owner chose>`
765
+ records the owner's call; a reason, evidence or context that says
766
+ "pre-existing", "out of scope", "later" or "follow-up" is refused on
767
+ evidence. `--title`/`--reason` pair up in order and repeat, and `--from
768
+ <file.json>`, a file in the repository holding `[{"title", "reason"}]`,
769
+ carries titles a shell cannot. It appends a dated comment and the title to
770
+ the dismiss file, refuses one that already differs from HEAD, and commits
771
+ that file alone (`git commit --only`, every hook run) with a
772
+ `Dismissal-Basis: evidence` trailer, or the owner's word, so
773
+ `git log --grep "Dismissal-Basis: evidence" -p -- .cubic-dismiss` lists every
774
+ call the agent made alone. A failed commit restores the file. The settings:
775
+
776
+ ```json
777
+ { "cubicDismiss": { "file": ".cubic-dismiss", "subject": "chore(review): dismiss {count} Cubic finding{s}", "ownerBasis": "owner" } }
778
+ ```
779
+
780
+ **A pushed branch gets its pull request.** git has no post-push hook, so
781
+ `niyam pr-autocreate` takes a push from three sides. `claude-hook`, Claude
782
+ Code's PostToolUse(Bash) and Stop hook, catches a session's foreground push
783
+ once the tracking ref moved (a background one at Stop), opens the pull
784
+ request, and tells the session once to switch Autofix on: in context after
785
+ the push, or by holding Stop (exit 2); a cloud session, which has no
786
+ Autofix, gets a `systemMessage` instead. `spawn-watchers --root <repo>
787
+ --remote <name>`, run by the pre-push hook with git's ref lines on stdin,
788
+ starts one detached `watch` per pushed branch, which waits for the remote to
789
+ hold the pushed commit, then opens the pull request, retrying GitHub for ten
790
+ minutes. Nothing opens for a protected or merge-queue branch, another remote,
791
+ a branch with no commits ahead of the base, one with a merged pull request
792
+ (it is retired) or a closed one (reopening is a person's call), or in CI.
793
+ `NIYAM_PR_AUTOCREATE=0` on a push opens none for the commit it sent: the
794
+ choice is recorded before git sends the refs, and a push whose choice cannot
795
+ be recorded is refused (exit 3). Every answer is kept in
796
+ `.tmp/pr-autocreate/` (one JSON record per branch, its opt-outs, the watch
797
+ log), so GitHub is asked once per pushed commit. A session's hook reaches
798
+ GitHub as the session's agent, with every check `as-agent` makes, and the
799
+ watcher with the push's own token. Its own errors never fail a push or hold
800
+ a session. The settings:
801
+
802
+ ```json
803
+ { "prAutocreate": { "base": "main", "draft": false, "protected": ["main", "master", "develop", "prod", "production"], "skip": ["mergify/", "gh-readonly-queue/"], "optOut": [], "describe": "`gh pr edit --body-file`" } }
804
+ ```
805
+
806
+ `optOut` names older opt-out variables read beside `NIYAM_PR_AUTOCREATE`;
807
+ `describe` says how the pushing session writes the real description;
808
+ `retired`, a link, explains why a merged pull request retires its branch;
809
+ `footer` ends the placeholder body.
810
+
811
+ **Started work runs to merge.** `niyam keep-going`, Claude Code's Stop hook,
812
+ sends a session back while its branch has commits the base lacks and its
813
+ pull request has not merged at this commit, saying what is left (push, open
814
+ the pull request, mark it ready, carry it to merge) and the count ("1 of
815
+ 5"). It lets the session stop for a subagent; on the base, another trunk or
816
+ a detached HEAD; when another remote branch carries the commits; while a
817
+ background task, `git commit` or `git push` runs (its exit wakes the
818
+ session), except in print mode (`NIYAM_PRINT_MODE=1`), where the task dies
819
+ with the turn; for a desktop session with every commit on a ready pull
820
+ request, which Autofix wakes; when GitHub cannot say; and at a stop note for
821
+ this commit, which `niyam keep-going --stop "<why>"` writes when only the
822
+ owner can unblock the work or it is proven unneeded, and whose reason it
823
+ shows once. At the sixth stop at one commit it writes that note itself. A new
824
+ commit resets the count and voids the note. The pull request is read over
825
+ REST, as the session's agent; a cloud session is held the same way. Its
826
+ records are in `.tmp/keep-going/`. The settings:
827
+
828
+ ```json
829
+ { "keepGoing": { "trunks": [], "printMode": [], "owner": "the owner", "tag": "niyam keep-going" } }
830
+ ```
831
+
832
+ `base`, when set, names the branch work merges into; otherwise it is
833
+ origin's default branch. `printMode` names older print-mode variables read beside `NIYAM_PRINT_MODE`;
834
+ `owner` is who the messages tell a session to tell; `tag` ends each message.
835
+
836
+ **Design frames** is the `figma` feature, an optional extension for clients
837
+ that design in Figma: with it on and two Actions secrets, `FIGMA_LIBRARY`
838
+ (the design library's file key) and `FIGMA_TOKEN`, each State of the slice
839
+ an agent pull request builds, other than one closed as not planned, must link
840
+ a Figma frame (`figma.com/design/...?node-id=...`) that holds at least one
841
+ component published by that library and is not a captured image (an image
842
+ covering half the frame or more). Frames are for Experience work: a slice
843
+ whose parent Work item names any other kind in a `Kind:` line (`**Kind:** Process.`,
844
+ or plain `Kind: Process`) passes without a Figma call; one whose Work item
845
+ names no kind, or whose parent is not a Work item, is checked. Without `FIGMA_TOKEN`, or without a
846
+ library (from `FIGMA_LIBRARY`, or an older committed key, below), the job says
847
+ the check is off and passes. The library key is a secret, not a committed setting,
848
+ so a public repository does not publish its design file, and the workflow
849
+ `onboard` writes passes the Figma secrets only while `figma` is on. Settings
850
+ an older release wrote still work: a `design` feature is read as `figma`, and
851
+ a `"figma": { "library": ... }` setting is read when `FIGMA_LIBRARY` is not
852
+ set, each with a warning; `onboard` renames the feature, takes the key out
853
+ and sets it as the `FIGMA_LIBRARY` secret itself, as you, with the run's one
854
+ browser approval: it seals the key with the repository's Actions public key
855
+ (a libsodium sealed box, as GitHub requires) and stores it through GitHub's
856
+ API, never printing it.
857
+
858
+ **Decisions, weekly** runs on Mondays at 06:17 UTC (and by hand), or on the
859
+ `schedule` the settings set. A Decision issue carries
860
+ its fields one per line: `Kind:` (Override, Risk or Bet), `Review:`,
861
+ `Expires:`, `Check:` (a command in backticks; exit 0 means the decision still
862
+ holds) and `Undo:`. For each open Decision issue, a check that reads laptop
863
+ files (`~/`, `$HOME`, `/Users/`, `/home/`) is labeled `cannot-run-here`; any
864
+ other check runs in the checkout with only `PATH` and `HOME` set, for at most
865
+ two minutes and five more seconds to end it (a check that runs out of time is
866
+ not counted as tripped), and
867
+ when it fails the decision gets a comment and one undo issue labeled
868
+ `needs-owner`. Runs do not overlap, and after 45 minutes of checks the rest
869
+ wait for next week. An Override whose expiry is within 30 days is labeled
870
+ `expiring`; one whose expiry has passed is named in the run's log. A check runs
871
+ only when the owner or the agent wrote the issue and was the last to edit it.
872
+
873
+ The **review routine** is a weekly scheduled agent session in the client
874
+ repository, working as the agent; its prompt is
875
+ [routines/review.md](routines/review.md). It runs `niyam reviews-due`
876
+ for the open decisions whose `Review:` date has come, then for each one either
877
+ keeps it (comment `Kept:` with reasoning and a new review date) or settles it
878
+ (comment `Settled:` with reasoning, and closes it), labeling both `veto` so
879
+ the owner has a week to reverse it. A decision touching secrets, money or
880
+ production is held for the owner with a suggestion and `needs-owner`. The
881
+ weekly job removes `veto` once the week has passed.
882
+
883
+ `reviews-due` lists only a decision the owner or the agent wrote and last
884
+ edited, so no one else's text reaches the routine. It reads only GitHub's REST
885
+ API, which a cloud session's GitHub proxy allows, and REST does not say who
886
+ last edited an issue's body, so the weekly job, whose token reads GraphQL,
887
+ vets the text for it: on each open decision with a `Review:` date that the
888
+ owner or the agent wrote and last edited, it keeps one comment naming the
889
+ text's SHA-256, and updates it after their edits. `reviews-due` lists a
890
+ decision only while its text has the hash in the workflow's latest such
891
+ comment. Any other text is left out, and `reviews-due` says so: a decision
892
+ the owner or the agent wrote or edited since the job last ran comes up after
893
+ its next run.
894
+
895
+ The weekly job also watches the routine: an open decision the routine reviews
896
+ whose `Review:` date is over a week past, with no `Kept:` or `Settled:` from
897
+ the agent since, is labeled `needs-owner` with a comment, so a routine that
898
+ was never created, or has stopped, shows up. Only the agent's comments count
899
+ as verdicts: anyone can write `Kept:`. `reviews-due` still lists a decision
900
+ the job labeled so, until the agent comments on it, and the job takes the
901
+ label off once the agent's verdict follows it; a `needs-owner` the routine or
902
+ the owner added stays. `onboard`, with `review` on, lists the routine under
903
+ "By hand:", and its pull request says how to create it: a weekly Claude routine on the repository (claude.ai/code/routines,
904
+ or `/schedule`), with claude.ai's GitHub connected as the agent, and the
905
+ prompt from `routines/review.md` at the release in use. It cannot create the
906
+ routine itself: Claude's routines API answers only a Claude Code session's own
907
+ sign-in, not a command, and a routine works as claude.ai's GitHub connection,
908
+ which no API names.
909
+
910
+ `onboard` also writes a pre-push git hook running `niyam pre-push`,
911
+ for every adopter. In a local agent session (one session-start set up, or
912
+ any shell Claude Code runs on the Mac, which sets `CLAUDECODE`, so it holds
913
+ where the Claude Code hooks never ran) it is the pre-push identity guard: a
914
+ push over SSH is refused, whatever the host, since it would use this Mac's
915
+ SSH keys, the owner's; over HTTPS to GitHub, git is asked for the
916
+ credentials it would push with (one in the URL included) and GitHub for
917
+ whose they are, and only the agent's push goes ahead; in a Claude cloud
918
+ session, GitHub is asked through its proxy whose account the session is. The
919
+ owner's pushes from their own terminal are not checked. With `work-rules` on, it then applies the same rules before an
920
+ agent session pushes: all the commits
921
+ one push brings, on one branch, name one slice between them as a
922
+ `Slice: #N` trailer. Commits a remote already has are not the push's own,
923
+ and neither are the default branch's commits the clone can find: those its
924
+ tip as GitHub names it reaches, when the clone has that commit, and those
925
+ its remote-tracking ref reaches. Where those are behind, as in a
926
+ single-branch clone that merged the default branch from `FETCH_HEAD`, and the
927
+ push would be refused, GitHub is asked which commits the push's merges
928
+ brought are on the default branch, and those are left out too. So a merge of
929
+ the default branch brings none of the slices its commits name. A push whose
930
+ own commits name no slice, such as a merge or a commit with no trailer, is
931
+ judged by the branch's own commits, those not on the default branch: it
932
+ passes when they name exactly one slice. Where the clone cannot find the
933
+ default branch at all, a push of only merges is judged by the commits the
934
+ merges did not bring, as before. In an agent session, a push is refused when the CLI is
935
+ missing, or, with `work-rules` on, the session has no token. When the repository already has its own
936
+ pre-push hook, or git runs hooks from a folder outside the repository (a
937
+ global `core.hooksPath`), `onboard` leaves it alone and lists the line to add
938
+ under "By hand:": `niyam pre-push "$@"`. The client workflow re-runs the checks when a
939
+ pull request's description is edited. After upgrading niyam, run
940
+ `onboard` again: it upgrades the hook entries in `.claude/settings.json` and
941
+ the workflow. An older release's workflow, one job that let every run write
942
+ to issues, is replaced; a workflow split into `niyam` and
943
+ `niyam-weekly` alone gets the `niyam-merged` job, which
944
+ closes a merged pull request's slice, and runs on closed pull requests; a
945
+ workflow with those three jobs alone gets the `niyam-asks` job, with
946
+ the comment and label triggers and the hourly cron it runs on, and the weekly
947
+ job leaves that cron alone; a 0.5.28 asks job, which any
948
+ commenter's ask started, starts on an owner's, member's or collaborator's alone;
949
+ a 0.6.3 one, which the approved label alone of the issue events started, starts
950
+ on an issue opened or reopened too (see Issue types), unless the client changed
951
+ its `issues:` trigger; a
952
+ workflow already split into its jobs keeps everything but its version pins, which move to the
953
+ new release, the one branch pushes run on, which follows a changed default
954
+ branch, and the one cron the weekly job runs on, which follows a changed
955
+ `schedule` (a schedule with more crons, or a comment on its cron line, is the
956
+ client's own and stays as it is); any other workflow is offered a replacement. Make the checks of the
957
+ features a client has turned on required on its default branch, such as
958
+ `niyam / PR identity` with `pr-identity` and `niyam / Work rules` with
959
+ `work-rules`; a check of a feature that is off still runs and passes, but with
960
+ identity alone there is no workflow at all, so require none.
961
+
962
+ ### One feature at a time
963
+
964
+ A client can turn features on one at a time. `identity` is always on: the
965
+ settings, the session-start hook, the agent's access and its Verified commit.
966
+ The others are `pr-identity`, `board`, `work-rules`, `figma`, `decisions` and
967
+ `review`. The settings list the ones a client has turned on:
968
+
969
+ ```json
970
+ { "owner": "example-owner", "agent": "ExampleBot", "features": ["identity"], "project": "Example work" }
971
+ ```
972
+
973
+ `niyam onboard <owner> <agent> --features identity` sets up identity
974
+ alone; later, `niyam onboard --add board` turns one more on and sets
975
+ it up. Settings with no `features` key keep every feature on, as before;
976
+ `"features": []` means identity alone. The shared checks,
977
+ the weekly job, `reviews-due` and the pre-push hook each pass, saying so, when
978
+ their feature is off; `onboard` writes the workflow only once a check needs it. `project` names the board's
979
+ Project (by default `<repo> work`). `schedule` sets when the weekly job runs,
980
+ as a five-field cron in UTC (by default `"17 6 * * 1"`, Mondays at 06:17);
981
+ `onboard` refuses one that is not a cron, or that is `41 * * * *`, the hourly needs-owner sweep's, and writes it into the workflow, so
982
+ run `onboard` again after changing it. `approvals` names the repository's
983
+ standing Approvals issue, where one owner comment answers a batch of asks
984
+ (see the work rules); without it, there are no batch answers on an
985
+ Approvals issue.
986
+
987
+ GitHub has issue types for organisations only, so on a repository a personal
988
+ account owns, `work-rules`, `decisions` and `figma` cannot run: the work rules
989
+ need a Slice under a Work item, the weekly job and `reviews-due` list
990
+ Decision issues, and the design check reads a slice's State sub-issues.
991
+ `onboard` refuses to turn them on there, with `--features` or `--add`, saying
992
+ why; with no `--features`, it turns on the rest and names the ones it left
993
+ off. Should the settings list them anyway, `pr-work-rules`, `pr-design`, the
994
+ weekly job, `reviews-due` and the pre-push hook's work rules pass, saying the
995
+ feature is off on a personal account's repository and why, rather than
996
+ failing every pull request. They ask GitHub whose the repository is once per
997
+ run.
998
+
999
+ ### Issue types
1000
+
1001
+ The work model has five issue types, Work item, Slice, State, Decision and
1002
+ Brief, and `onboard` makes the organisation's enabled types exactly these.
1003
+ Issue types are an organisation-wide setting, so this reaches every
1004
+ repository in the organisation, onboarded or not, and the plan says
1005
+ "org-wide". `onboard` adds a work model type the organisation lacks and
1006
+ enables one it has disabled. Every other type, GitHub's default Task, Bug
1007
+ and Feature or one of the organisation's own, it disables, after giving each
1008
+ issue that holds one, open or closed, in any of the organisation's
1009
+ repositories, a work model type from GitHub's facts about it:
1010
+
1011
+ - a sub-issue of a Work item becomes a Slice;
1012
+ - a sub-issue of a Slice becomes a State, an experience state of that slice;
1013
+ - an issue with sub-issues becomes a Work item;
1014
+ - any other becomes a Brief.
1015
+
1016
+ Each open issue with no type at all, in any of the organisation's
1017
+ repositories, gets one by the same rule, under the same yes. A repository's
1018
+ Approvals issue, the one its settings (`.github/niyam.json` on its default
1019
+ branch) name as `"approvals": N`, is left with no type, and the plan says so: it is a standing record the
1020
+ owner answers batches on, never closed, which none of the five fits, and the
1021
+ work rules find it by its number, not its type. A closed issue with no type
1022
+ is left as it is, and the plan says that too. No rule reads a title or a
1023
+ label: the CLI writes neither for a Decision, so a Decision is typed by hand.
1024
+
1025
+ An issue whose parent is being retyped is read as the parent's new type, so
1026
+ a Task with Task sub-issues becomes a Work item with Slices. The plan names
1027
+ every issue it types, a run of consecutive ones in a repository that one
1028
+ rule types alike on one row (the question names the first ten), and each
1029
+ type it disables, and the one yes covers them. The agent
1030
+ reads the organisation's types, but only the repositories it can see, so
1031
+ where an enabled type outside the work model exists, or an issue to type, `onboard`
1032
+ signs you in before the
1033
+ plan and reads every repository as you: the plan shows what the yes
1034
+ approves. The run reads again and changes nothing beyond it: an issue found
1035
+ only after the plan keeps its type, or its lack of one, that type stays
1036
+ enabled, and "By hand:" says to run `onboard` again. A dry run signs in to
1037
+ nothing, so it lists what
1038
+ the agent can see. It retypes every issue first and disables a type only then, so no
1039
+ issue is left holding a disabled type: GitHub hides a disabled type on the
1040
+ issues that hold it and shows it again if it is enabled. `onboard` disables
1041
+ rather than deletes, so a type can come back; GitHub does not say what
1042
+ deleting one does to its issues. A rerun cannot check a type that is
1043
+ disabled: GitHub refuses to list issues by one (HTTP 422), for the owner
1044
+ too, so the plan names each such type on a `disabled` row (as `disabled
1045
+ Task, Bug, Feature: GitHub lists no issues by a disabled type, so onboard
1046
+ cannot tell whether any holds one`), never saying none holds it, and the
1047
+ type stays disabled; enabled again, `onboard` retypes what holds it and
1048
+ disables it once more. Any other 422, one for an enabled type included,
1049
+ still fails the read, as does any other refusal but the 410 of a repository
1050
+ with issues turned off.
1051
+ An issue in an archived repository cannot be
1052
+ changed, so it keeps its type, that type stays enabled, and "By hand:" says
1053
+ to unarchive the repository and run `onboard` again. A repository with issues
1054
+ turned off, as a fork usually is, has none to read. A rerun changes
1055
+ nothing when all is in order, and catches a type someone enabled again or a
1056
+ default GitHub adds later. Disabling a type needs an organisation owner
1057
+ (`admin:org`); retyping an issue needs write access to its repository. Both
1058
+ come from the owner's sign-in for the run.
1059
+
1060
+ **New issues get a type as they open.** With `board` on, `onboard` writes
1061
+ the client workflow (for `board` alone too), whose `niyam-asks` job
1062
+ also starts when an issue is opened or reopened, and runs `niyam
1063
+ issue-type`, which gives an issue with no type one by the same rule, read
1064
+ from GitHub when the job runs, so a parent set as the issue was made counts.
1065
+ GitHub starts no run for an issue a workflow's own `GITHUB_TOKEN` opens, such
1066
+ as a monthly reminder a client's workflow files, so the job also runs on the
1067
+ asks job's hourly cron and types every open issue in the repository with
1068
+ none: such an issue has its type within the hour. An issue opened with a
1069
+ type, one closed since, the Approvals issue, and a repository a personal
1070
+ account owns are left alone. A workflow whose `issues:` trigger the client
1071
+ changed keeps it, so there the job starts hourly alone. The job's
1072
+ `issues: write` sets the type: GitHub's `type` on an issue takes write access
1073
+ to issues, as the weekly job's undo issues, opened as Briefs by that token,
1074
+ show. Issue events never come from a fork, and the job reads its settings
1075
+ from the default branch and runs the CLI from the release the workflow pins,
1076
+ so an issue's author, whoever opens it, changes nothing but that issue's
1077
+ type. An issue made as a Brief and only
1078
+ later made a sub-issue keeps Brief: no event starts the job then, so retype
1079
+ it by hand.
1080
+
1081
+ `doctor` on a Mac, in a repository whose settings turn the board on, warns (`▲`)
1082
+ when the organisation has an enabled type outside the work model or lacks
1083
+ one of the work model's, naming the issues in this repository that hold
1084
+ another type, and when an open issue here has no type, but the Approvals
1085
+ issue; the fix is the owner running `onboard` again.
1086
+
1087
+ ### Hooks that call GitHub
1088
+
1089
+ The lock in the settings' `env` reaches every hook, and session-start lifts
1090
+ it only for the session's shells, through `CLAUDE_ENV_FILE`, which Claude
1091
+ Code gives the SessionStart, Setup, CwdChanged and FileChanged hooks alone.
1092
+ So a client's own hook that runs `gh` or git's remote commands, a
1093
+ PreToolUse or Stop hook say, presents the lock's token, and GitHub answers
1094
+ `HTTP 401: Bad credentials`; in a cloud session too. Run each such command
1095
+ through `as-agent`, with the `session_id` Claude Code puts in every hook's
1096
+ JSON input:
1097
+
1098
+ ```sh
1099
+ input=$(cat)
1100
+ sid=$(printf '%s' "$input" | jq -r .session_id)
1101
+ cli="$HOME/.config/niyam/bin/niyam"; [ -x "$cli" ] || cli=niyam
1102
+ printf '%s' "$input" | "$cli" as-agent --session "$sid" -- gh pr view --json state
1103
+ status=$?
1104
+ [ "$status" -eq 77 ] && exit 0 # locked: this session does not work as the agent
1105
+ exit "$status"
1106
+ ```
1107
+
1108
+ `niyam as-agent --session <session_id> -- <command> [args...]` runs
1109
+ the command only when session-start recorded, for that session id, that the
1110
+ session works as one of the agents the settings file names, the
1111
+ record the guard reads. On a Mac the command gets what the session file
1112
+ gives a shell: the agent's identity, the lock's variables removed, and
1113
+ `GH_TOKEN` read from the keychain as it starts. In a cloud session it gets
1114
+ the proxy's placeholder token, which the proxy swaps for the connected
1115
+ account's. Its standard input, output and error are the hook's, and its exit
1116
+ code is `as-agent`'s. Otherwise nothing runs: one line on standard error says
1117
+ why, in the guard's words, and `as-agent` exits **77**, a code
1118
+ `gh`, git and the shell do not use, so a hook can tell "locked" from
1119
+ the command's own failure. A missing `--` or command is bad usage, exit 2. The token is
1120
+ only ever in the command's environment, never on a command line, in output
1121
+ or in a file, and it never falls back to the owner's `gh` logins, git
1122
+ password or SSH. Use the launcher line above, as the hooks `onboard` writes do:
1123
+ the app's hooks may have no node on their `PATH`. `niyam doctor`,
1124
+ run in the client repo, warns under "This repo" about each hook in `.claude/settings.json` or
1125
+ `.claude/settings.local.json` whose command, or the repo script it runs,
1126
+ calls `gh` or git's remote commands outside `as-agent`. A script that
1127
+ imports a Python module tracked in the repo whose code runs `as-agent` (a
1128
+ helper wrapping each `gh` call) counts as routed through it; the hook's
1129
+ command is still judged. Outside a cloud session, a script is read only up
1130
+ to a line, at column 0, that exits there,
1131
+ `[ "${CLAUDE_CODE_REMOTE:-}" = true ] || exit 0` or
1132
+ `[ "$CLAUDE_CODE_REMOTE" != true ] && exit`, when only blank lines, `set`,
1133
+ `export` and the like, `.` or `source`, and assignments come before it: bash
1134
+ runs nothing after it on a Mac. Both are read as text, so a routed script
1135
+ that also calls `gh` on its own is not told apart.
1136
+
1137
+ ### Claude cloud sessions
1138
+
1139
+ A Claude cloud session has no keychain and no session file: it reaches
1140
+ GitHub through Claude's GitHub proxy, as the account connected to claude.ai.
1141
+ So for agent sessions there, that connection is the agent account. Its
1142
+ `session-start` asks GitHub, through the proxy, which account the session
1143
+ is. When it is the agent, it writes the pre-push git hook (a fresh clone
1144
+ has none), lifts the lock and records the session for the guard; `gh` gets
1145
+ the proxy's placeholder token (`proxy-injected`), which the proxy swaps for
1146
+ the connected account's. As anyone else, GitHub stays locked out and the
1147
+ session is told to stop. The pre-push hook asks GitHub the same through
1148
+ the proxy before each push. `session-start` runs only as the SessionStart
1149
+ hook: Claude Code sets `CLAUDE_ENV_FILE` for its hooks, never in the
1150
+ session's shell, so run by hand there it always says STOP, which says
1151
+ nothing about the session.
1152
+ The hook's own line at session start is what counts.
1153
+
1154
+ A cloud session's git commits are authored and committed as Claude's own
1155
+ account, `Claude <noreply@anthropic.com>`, and signed by it (Verified),
1156
+ while the push is the agent's. PR identity checks only commits that claim
1157
+ an agent, so these pass, and GitHub records the agent as having pushed
1158
+ them.
1159
+
1160
+ The proxy refuses GitHub's GraphQL API, so the work rules and `reviews-due`
1161
+ read only its REST API, here and everywhere else. The one exception is who
1162
+ edited an owner's edited `Decision:` comment, which only GraphQL names; here
1163
+ such a comment does not count.
1164
+
1165
+ **Installing niyam there.** Claude Code has no API, CLI or repo file for a
1166
+ cloud environment's Setup script, but a repo's SessionStart hooks run in its
1167
+ cloud sessions. So when `CLAUDE_CODE_REMOTE=true` and the hook finds no
1168
+ niyam CLI, it runs the clone's `.github/niyam/cloud-setup.sh` (from
1169
+ `CLAUDE_PROJECT_DIR`, else the working folder), then `session-start` as
1170
+ usual, and says in one line that it installed niyam. `onboard` writes that
1171
+ file in its pull request at the version `.github/workflows/niyam.yml` pins,
1172
+ and writes it again on every run, so the pin bump that upgrades the checks
1173
+ upgrades cloud sessions too. The file unpacks Node and the CLI under
1174
+ `/opt/niyam`, each once it matches the sha256 the file pins (Node's from
1175
+ this release, the CLI's from GitHub's record of the release archive), and
1176
+ puts `niyam` in `/usr/local/bin`, leaving the image's own Node alone, so it
1177
+ needs root; the environment needs the network to reach nodejs.org and
1178
+ GitHub's release downloads, which the default Limited access allows. The
1179
+ install's own output is dropped. When it fails, the hook's line names its
1180
+ last error line and the user it ran as, and the STOP follows; a clone with
1181
+ no such file says to run `onboard`. On a Mac, or where a CLI is found, the
1182
+ hook does as before.
1183
+
1184
+ What a hook installs is not cached, so each such session downloads about
1185
+ 50 MB first. Claude keeps a snapshot of what a Setup script installs, so
1186
+ `niyam cloud-setup` prints an optional snippet that makes sessions start
1187
+ faster: pasted at the top of the environment's Setup script, it finds the
1188
+ clone and runs the same file, with `NIYAM_SETUP` set. It names no version,
1189
+ so a new release needs no new paste. Its instructions are comment lines at
1190
+ the top of the snippet, on standard output with it, so `niyam cloud-setup
1191
+ | pbcopy` copies them too and nothing is left on standard error. A snippet
1192
+ pasted before 0.6.10 runs `.github/process-rules/cloud-setup.sh` alone,
1193
+ which `onboard` deletes since P-57: delete it, or paste the new snippet
1194
+ over it. The Setup script runs as root from the folder that holds the clone
1195
+ (the VM's home, the clone one folder down), so the snippet looks there and
1196
+ in each home. The Setup field holds one script, so the snippet runs in a
1197
+ shell of its own (`bash <<'NIYAM' … NIYAM`): a failed download, or a clone
1198
+ with no such file, says so on standard error and the commands after it
1199
+ still run. If the repo has its own Setup script, put this first, then the
1200
+ repo's own: a repo's script may end with `exit`, and nothing after that
1201
+ runs.
1202
+
1203
+ Claude keeps a snapshot of the environment once its Setup script has run,
1204
+ and builds it again only when the Setup script changes or after about a
1205
+ week. So after a pin bump, a cloud session's `session-start` finds its CLI
1206
+ is not the release `cloud-setup.sh` installs, runs that file itself, and
1207
+ says so in one line; the session goes on with the new CLI, and the snapshot
1208
+ catches up on its next build. When the repo has no `cloud-setup.sh` while
1209
+ the workflow pins another release, or the file is not at the workflow's
1210
+ pin, the line says to run `onboard` again. When the Setup script still
1211
+ installs a release of its own (an older paste), the line also says to
1212
+ delete niyam's part of it or paste the snippet over it. It only warns: the
1213
+ session works on.
1214
+
1215
+ claude.ai has one GitHub connection per account, so it is the agent's for
1216
+ every cloud session that account starts.
1217
+
1218
+ `niyam doctor` in a cloud session (`CLAUDE_CODE_REMOTE=true`) only
1219
+ reads, in the same layout and with the same exit codes as on a Mac:
1220
+
1221
+ ```
1222
+ ◆ niyam doctor AGENT
1223
+ │
1224
+ ◇ This cloud session
1225
+ ✗ .github/niyam/cloud-setup.sh installs 0.5.24, but .github/workflows/niyam.yml pins v0.5.25 → niyam onboard again
1226
+ ✓ niyam 0.5.24 runs here
1227
+ ✓ the SessionStart hook installs niyam from .github/niyam/cloud-setup.sh when a session has none; the Setup script does not run it, which only makes sessions start slower
1228
+ │
1229
+ ◇ GitHub — as AGENT
1230
+ ✓ the proxy acts as AGENT, an agent the repo's settings name
1231
+ ✓ session-start gave this session AGENT's identity
1232
+ │
1233
+ └ 1 to fix
1234
+ ```
1235
+
1236
+ This cloud session checks that `cloud-setup.sh` opens with the comment
1237
+ `onboard` writes, naming the release it installs, and that this release is
1238
+ the workflow's pin (`✗`, fixed by running `onboard` again; a workflow that pins no one version is `▲`), that the CLI running is that
1239
+ release (`▲`: `session-start` installs it, or `bash
1240
+ .github/niyam/cloud-setup.sh` does), and that the Setup script
1241
+ runs the repo's file, naming the file it ran (the mark
1242
+ `/opt/niyam/from-setup` holds its path), or that the SessionStart hook
1243
+ installs it, since the Setup script does not: both are `✓`. GitHub
1244
+ checks that the account the proxy acts as is one of the settings' agents,
1245
+ and that `session-start` gave the session that identity (`✗` otherwise:
1246
+ `gh` and git stay locked out). This repo lists hooks that reach GitHub
1247
+ outside `as-agent` and the Auto-fix rules missing, as on a Mac. It installs nothing; on Linux outside a
1248
+ cloud session, `doctor` still refuses.
1249
+
1250
+ ### Owner steps
1251
+
1252
+ Some GitHub changes only the owner's account can make: an organisation's
1253
+ issue types, the `approved` and `do-not-merge` labels (the auto-mode
1254
+ classifier keeps agents from changing them), and a ruleset's required checks.
1255
+ An agent that needs one asks the owner to run one command in their own
1256
+ terminal, never a script or a settings page:
1257
+
1258
+ ```bash
1259
+ niyam owner-step issue-types <org>
1260
+ niyam owner-step label <owner/repo> <number> <add|remove> <approved|do-not-merge>
1261
+ niyam owner-step required-checks <owner/repo> <ruleset id or name> [--check <name>]…
1262
+ ```
1263
+
1264
+ - `issue-types` adds the work model's issue types the organisation lacks and
1265
+ enables any that are disabled. It changes no other type and no issue; `onboard`
1266
+ does that.
1267
+ - `label` adds or removes `approved` or `do-not-merge` on an issue or pull
1268
+ request. It refuses a label the repository does not have.
1269
+ - `required-checks` makes the ruleset also require the checks of the features
1270
+ the repository's settings turn on, read from its default branch
1271
+ (`.github/niyam.json`): `niyam / PR identity` for `pr-identity`,
1272
+ `niyam / Work rules` for `work-rules` and `niyam / Design frames` for
1273
+ `figma`. It adds a check only when the repository's
1274
+ `.github/workflows/niyam.yml` has a `niyam` job, named `niyam`, calling
1275
+ shared checks that run that job, at the version it pins. A required check
1276
+ that never reports would hold every pull request, so any other check is a
1277
+ `✗` saying why. It keeps every other check and rule, removes none, and
1278
+ shows the before and after.
1279
+ - `required-checks --check <name>`, repeatable, also requires a check the
1280
+ repository runs itself, such as a job of its own CI. It adds one only
1281
+ when it reported `success` on the head commit of the last pull request
1282
+ merged into the default branch, from one app alone, and requires it from
1283
+ that app. That shows pull requests run it and it passes. One that never
1284
+ ran there, did not pass, or that two apps reported is a `✗`. A check a
1285
+ workflow runs only for some paths can pass there and then never report
1286
+ on a pull request that skips them, holding it: name only checks that run
1287
+ on every pull request.
1288
+
1289
+ It refuses in an agent session (`NIYAM_AGENT` set, or `CLAUDECODE=1`)
1290
+ and without a terminal. It makes a new folder in the user's temporary folder
1291
+ (`niyam-owner-step-…`; on macOS, `getconf DARWIN_USER_TEMP_DIR`) and runs gh
1292
+ with that folder as `GH_CONFIG_DIR`, `GH_PAGER=cat`, no `GH_TOKEN`, and
1293
+ git's global config pointed inside the folder. It then signs in with one
1294
+ browser approval of gh's device code: `gh auth login -h github.com -p https
1295
+ --skip-ssh-key -w -s <scope> --insecure-storage`. The scope is `admin:org`
1296
+ for issue types and `repo` for the others; gh always adds `repo`, `read:org`
1297
+ and `gist`. The token stays in that folder: never in the keychain, the
1298
+ owner's gh config, git's or SSH's settings, a command's arguments or the
1299
+ output. Every call goes through `gh api` there, and none is made unless the
1300
+ folder holds the token, so gh can never fall back to another login.
1301
+
1302
+ It checks that the signed-in login owns the organisation, or the repository
1303
+ (the user who owns it, or an owner of its organisation), and reads what is
1304
+ there. Then it prints exactly what it will change and asks for a yes; the
1305
+ sign-in and the reads change nothing. It makes each change, reads it back,
1306
+ and marks it `✓` or `✗`. Whatever happens, an error or Ctrl-C included, it
1307
+ tries to delete the folder, which holds the token's only copy, and marks that
1308
+ `✗`, with the `rm -rf` to run, when the delete fails. It does not run
1309
+ `gh auth logout`, which deletes gh's keychain entries for the host whatever
1310
+ `GH_CONFIG_DIR` says, and which cannot revoke the token anyway. The token
1311
+ stays valid on GitHub until it is revoked, so the command ends with the link
1312
+ to do that: https://github.com/settings/applications. Exit 0 when every change was made, or none
1313
+ was needed or wanted, and no check was skipped; 1 otherwise, a `required-checks`
1314
+ run that skipped a check included, even after a no; 130 after a Ctrl-C.
1315
+ `doctor` marks `▲` any owner-step folder left behind, which a killed run or a
1316
+ failed delete leaves, and says whether it still holds a token. A run going on
1317
+ now has one too, so delete it only when no owner-step is running. Each step lives here with tests; a new step
1318
+ is a slice the owner approves.
1319
+
1320
+ ### Releases and upgrading
1321
+
1322
+ Each release is a tag `vX.Y.Z` on `main`, matching `package.json`; the
1323
+ Release workflow checks both, runs `pnpm check` and publishes the GitHub
1324
+ release, attaching the CLI package it built and tested. From 0.6.16 the same
1325
+ package is on npm as `@veda-hq/niyam`, with provenance, for a repository that
1326
+ pins it as an exact version. Install the attached package on each machine with
1327
+ pnpm, once; nothing is built on install:
1328
+
1329
+ ```bash
1330
+ pnpm add -g https://github.com/veda-hq/niyam/releases/download/v0.6.17/veda-hq-niyam-0.6.17.tgz
1331
+ ```
1332
+
1333
+ The package puts one command on `PATH`, `niyam`. Since P-57 a release
1334
+ attaches nothing under the name before niyam, so a Mac that still has the
1335
+ package `@athya-hq/process-rules` (0.6.x) takes the line above. Remove the
1336
+ old package first, with `pnpm remove -g @athya-hq/process-rules`, so only
1337
+ one package puts commands on `PATH`.
1338
+
1339
+ After that, update it with one command on each machine:
1340
+
1341
+ ```bash
1342
+ niyam upgrade
1343
+ ```
1344
+
1345
+ `upgrade` asks GitHub's public releases API for the newest release, with no
1346
+ token and no sign-in, and when it is newer than the CLI running, installs it
1347
+ with the same `pnpm add -g`, printing old → new and the version the shell then
1348
+ runs. On the newest release it says so and installs nothing; it never moves
1349
+ back to an older one. When GitHub cannot be reached, or a newer release has no
1350
+ package attached yet, or pnpm fails, it says which and exits 1, checking
1351
+ nothing more. After an install, or when there was nothing to install, it walks
1352
+ `PATH`, as `type -a niyam` does, reading an empty or relative entry
1353
+ against the current folder as the shell does. It exits 0 when exactly one
1354
+ `niyam` is there and it is the newest release. When more than one is
1355
+ there, or the first is not that release, it lists each path and its version,
1356
+ marks pnpm's own copy to keep, names the others to remove, and exits 1, since
1357
+ an older copy the shell finds first is how a Mac keeps running an old release
1358
+ after an upgrade. It works in an agent session on a Mac too; in a Claude cloud
1359
+ session it refuses, because there the repo's `cloud-setup.sh` installs the
1360
+ release the workflow pins. A CLI from before `upgrade` has none: install the
1361
+ newest release with the line above. `onboard`, when the repo pins a newer release than the
1362
+ CLI running, refuses and says to run `niyam upgrade` first.
1363
+
1364
+ `onboard` pins the client's workflow to one version, the release of the CLI
1365
+ that ran it. Each job writes the pin twice, `checks.yml@vX.Y.Z` and, two lines
1366
+ below it under `with:`, `niyam-ref: vX.Y.Z`, the one input `checks.yml`
1367
+ declares; GitHub refuses a caller that passes an input the called workflow
1368
+ does not declare, `process-rules-ref` too since P-57. Every job of
1369
+ `checks.yml` runs the CLI from the commit it was called at (GitHub's
1370
+ `job.workflow_sha`), so the checks and the CLI are always one release; on
1371
+ GitHub Enterprise Server, which has no `job.workflow_sha`, the CLI comes from
1372
+ `niyam-ref`. Settings fails a run whose `niyam-ref` names
1373
+ another release, saying which and how to fix it: Dependabot and Renovate move
1374
+ a job's `uses:` line and nothing else, so their bump of niyam leaves
1375
+ the pair apart, and it also leaves out the cloud setup file's pin and any job a
1376
+ newer release adds. So leave `veda-hq/niyam` out of their updates (a
1377
+ Dependabot `ignore` entry, a Renovate `packageRules` entry with `enabled:
1378
+ false`). Upgrading is two steps: `niyam upgrade`, then `onboard` again,
1379
+ which moves every pin together. Editing the version by hand means changing
1380
+ every line that names it, two per job. A split workflow needs v0.5.4 or later: GitHub refuses a whole run, before
1381
+ any job's `if:`, when the called workflow asks for more than the calling job
1382
+ grants, and before v0.5.4 `checks.yml` asked for `issues: write` itself. The hooks run the
1383
+ launcher `machine` writes, else `niyam` from the `PATH`; without
1384
+ either the session-start hook tells the session to stop, and the guard refuses
1385
+ `gh` and `git`. Run `machine` again after removing the node it names.
1386
+
1387
+ ## Developing
1388
+
1389
+ Node 24 (`.nvmrc`) and pnpm.
1390
+
1391
+ ```bash
1392
+ pnpm install
1393
+ pnpm check
1394
+ ```
1395
+
1396
+ `pnpm check` typechecks, runs the tests with a coverage floor (95% lines and
1397
+ functions, 90% branches), builds `dist/` and runs it. `pnpm scan:secrets` runs
1398
+ Gitleaks and TruffleHog over the working tree; CI runs both over the whole
1399
+ history.
1400
+
1401
+ ## License
1402
+
1403
+ MIT
1404
+
1405
+ ## Renamed from process-rules
1406
+
1407
+ process-rules became niyam in the release after 0.6.3, in steps (docs/decisions.md,
1408
+ P-49, P-50 and P-53 to P-57). P-49 renamed the repository, the package, the command and
1409
+ the messages; P-50 the keychain service and the settings file; P-53 the hooks and
1410
+ the checks; P-54 dropped the `process-rules` command; P-55 moved this Mac's files to
1411
+ `~/.config/niyam/` and the agent variable to `NIYAM_AGENT`; P-56 renamed what
1412
+ `onboard` writes in a repository (the workflow, its job ids, `niyam-ref`, the cloud
1413
+ setup file and the onboard branch). Each of those still read the old names beside
1414
+ the new ones. P-57, for a release cut once every repository and this Mac have
1415
+ moved, ends that: no release uses a `process-rules` name to read settings,
1416
+ tokens, files or checks, or writes one; what is left is in the table below.
1417
+
1418
+ What P-57 removed for good, by hand where it is on a machine:
1419
+
1420
+ - `niyam machine` removes `~/.config/process-rules/`, launcher and all, once the
1421
+ new folder is written, and deletes the keychain entry under the service
1422
+ `process-rules` once it has read back that the `niyam` entry holds the same
1423
+ token; when they differ, or the read fails, it leaves the entry and says why,
1424
+ with the `security delete-generic-password` line to run once nothing needs it.
1425
+ `doctor` marks either one still there ▲.
1426
+ - `niyam onboard` deletes `.github/process-rules/cloud-setup.sh` wherever it
1427
+ leaves `.github/niyam/cloud-setup.sh`, and writes and runs none under that
1428
+ name; a Setup snippet pasted before 0.6.10 needs the new one pasted once, or, since P-60, deleting.
1429
+ - `niyam owner-step required-checks` takes each `process-rules / …` check out of
1430
+ a ruleset: no workflow reports one since P-53, so it would hold every pull
1431
+ request. The `niyam / …` check of the same job takes its place where the
1432
+ workflow runs that job.
1433
+ - Releases no longer attach the bridge archive `athya-hq-process-rules-<version>.tgz`,
1434
+ and `upgrade` asks veda-hq/niyam alone: a Mac still on `@athya-hq/process-rules`
1435
+ installs niyam with the `pnpm add -g` line in Releases and upgrading.
1436
+
1437
+ What still says process-rules, and why:
1438
+
1439
+ | What | Why it stays |
1440
+ | ---- | ------------ |
1441
+ | The reviews' reader for `<!-- process-rules vetted sha256:… -->` marks | data in decisions already vetted: dropping it would un-vet them |
1442
+ | The hook texts of releases before P-57, in `onboard`'s `OLDER_` lists | data compared against, so `onboard` replaces an older hook in place; nothing runs them |
1443
+ | 0.6.10's session file, which `sessionFileIs` still takes as an older one | `session-start` and `as-agent` use it, so a session started before `machine` runs again is not locked out, until `machine` rewrites it; its token read falls back to the keychain service `process-rules`, and it sets `PROCESS_RULES_AGENT`, which `as-agent` keeps from the commands it runs |
1444
+ | `~/.config/process-rules/` and the keychain service `process-rules` | `machine` removes them; `doctor` reports them while they are there |
1445
+ | `.github/process-rules/cloud-setup.sh` | `onboard` deletes it wherever it leaves `.github/niyam/cloud-setup.sh` |
1446
+ | `/usr/local/bin/process-rules` in a cloud environment, a launcher that runs `process-rules`, a required `process-rules / …` check | named only to remove them: the cloud setup file removes the first, `doctor` marks the second ✗ (fixed by `niyam machine`), `owner-step required-checks` takes the third out |
1447
+ | GitHub's redirect from athya-hq/process-rules | GitHub's, not niyam's |
1448
+ | The titles of tokens and signing keys made before P-56 | on GitHub already; nothing reads them (the closed Projects once titled "process-rules work" are now "niyam work (old)") |
1449
+ | The history in docs/decisions.md and docs/roadmap.md | a record of what was decided then |