✨ feat(state): niyam state files a State under a slice, and the work rules name it
Slice: #584
Part of #394 (spec v1, lesson closed-slice-needs-state).
What it does
niyam state <slice> --title "…"(src/work.ts,fileState):- It files an issue of type State, with the body
Part of #N.. - It attaches the State under the slice with
POST /repos/{owner}/{repo}/issues/{slice}/sub_issuesand{sub_issue_id: <the State's numeric id>}, not its number. - Then it prints
State: #M, the line to put under the pull request'sSlice:line. - It refuses an issue that is not a Slice, and files nothing for it.
- Under an open slice it files the State too, and says the slice's pull request needs no State while the slice stays open.
- A State that is filed but not attached exits 1, printing the
gh apicall that attaches it.
- It files an issue of type State, with the body
- The work rules' refusal of a fix that names no open State (
stateProblems) now names the command. niyam pre-pushwarns, and does not refuse, when the slice a push builds is closed and the branch's own open pull request names no open State under it:
⚠️ #N is closed, so its next pull request is a fix and needs a State: niyam state N --title "…"src/run.tsregisters the command (stateArgs, USAGE). README: a new paragraph, "Filing a State".
One change from the slice's text. The slice quotes the command as niyam state #N. niyam prints niyam state N, the bare number, because pasted into bash an unquoted #N starts a comment and drops the rest of the command. The command accepts 12 or a quoted '#12'. Given nothing, it says so, naming the quoting.
Tests
src/work.test.ts:- "fileState": a closed slice, the POST bodies, and the attach by id (9031, not 31); an open slice; not a Slice, not an issue, and a pull request, each filing nothing; a refused filing; a refused attach; no token.
- "a push for a slice closed already": the warning; no warning once the branch's own pull request names an open State; still a warning for a State that is delivered or not under the slice, or for a fork's pull request; no warning for an open slice; the warning comes before a refusal.
- The refusal text test is updated.
src/run.test.ts:stateArgsand its usage errors, including the bareniyam statethat bash leaves ofniyam state #12 ….- One existing test now expects the warning: the board test's push for a closed slice.
Evidence: a run against https://github.com/veda-hq/niyam-sandbox (2026-11-25, as AthyaBot, CLAUDECODE=1, with this pull request's head d677846 built and run as the sandbox's pre-push hook). The push is a dry run of an empty commit naming closed Slice #25, so nothing was sent. #2 is an open Slice, and #1 is a Work item.
== git push --dry-run origin HEAD:refs/heads/evidence-584-closed-slice
⚠️ #25 is closed, so its next pull request is a fix and needs a State: niyam state 25 --title "…"
To https://github.com/veda-hq/niyam-sandbox.git
* [new branch] HEAD -> evidence-584-closed-slice
exit: 0
== niyam state 25 --title '…' (the warning's command, as printed)
✓ #41, https://github.com/veda-hq/niyam-sandbox/issues/41: a State under #25
Put this line under the pull request's "Slice: #25" line:
State: #41 (indented here so Work rules doesn't read it as this pull request's own line)
exit: 0
== niyam state '#2' --title '…'
✓ #42, https://github.com/veda-hq/niyam-sandbox/issues/42: a State under #2
#2 is open, so its pull request needs no State while it stays open; once it closes, the pull request that fixes it names this one under its "Slice: #2" line:
State: #42
exit: 0
== niyam state 1 --title x
✗ #1 is not a Slice (its type is Work item); a State is filed under the slice it is part of
exit: 1
== gh api repos/veda-hq/niyam-sandbox/issues/25/sub_issues (the newest sub-issue)
{"id":6602620722,"number":41,"state":"open","title":"Evidence for niyam#584: a State under a closed slice","type":"State"}
== gh api repos/veda-hq/niyam-sandbox/issues/2/sub_issues (the newest sub-issue)
{"id":6602621757,"number":42,"state":"open","title":"Evidence for niyam#584: a State under an open slice","type":"State"}
So the warning fires at the push and its command runs as printed. Each State is attached under its slice as type State, by its numeric id. A Work item is refused, and nothing is filed for it.
The full gate passed locally on this commit: pnpm check (provenance, typecheck, lint, test, test:scripts, pins, pariksha, hooks:check, build, smoke).
Cost: a new command and one more README section.
Alok approved the slice with "Decision: approve spec v1 #583 … #590" on https://github.com/veda-hq/niyam/issues/394 (2026-11-24).
🤖 Generated with Claude Code