✨ feat(work): Slice done closes a Work item when its last slice closes

Merged
AT
3d ago
+521-9

Slice done now closes a Work item once the merge leaves it done (spec v1 of https://github.com/veda-hq/niyam/issues/655, approved 2026-11-26, D1 (a)).

After it closes the Slices and States a merged pull request names, the merged job reads the Work item above each slice once. It closes it as completed, after a comment naming its sub-issues and the pull request, when all of these hold:

  • it is open, and an owner's approved label is on it;
  • its body has a line **Slices:** all filed;
  • every sub-issue is closed, and so is every State under each Slice;
  • at least one Slice closed as completed;
  • no needs-owner label is on it;
  • it was not reopened after its last sub-issue closed.

Otherwise the run prints one line saying why it stays open, for example - #10 stays open: its body has no "**Slices:** all filed" line, so it may have slices still to file. A Work item in another repository is left to that repository's jobs. One whose sub-issues GitHub lists short of sub_issues_summary.total stays open.

The rule lives in the new src/work-done.ts (workItemDone, closeIfDone), which the hourly sweep in https://github.com/veda-hq/niyam/issues/657 reuses. README: the Slice done paragraph.

Evidence

  • pnpm check passes: 2910 src tests and 138 scripts tests, work-done.ts at 100% lines, branches and functions.
  • pnpm exec agnipariksha --lane src --files src/work-done.ts --no-reuse: 266 killed of 266, 0 blocking. Equivalent mutants were designed out (String(body) for a null body, label reads without a ?? [] default), not disabled.
  • I did not finish a local Stryker run on src/work.ts (the new closeWorkItems and its call). Other sessions' sweep runs held .git/agnipariksha.lock, and both tries gave up waiting. CI's Mutation check covers it.
  • New tests:
    • src/work-done.test.ts: each condition above, the line's exact form, pagination, read failures, and one comment per Work item.
    • src/work.test.ts, "the Work item above it":
      • the last slice closes it;
      • the last State closes it;
      • two slices are judged once;
      • a Work item in another repository and an orphan slice are left alone;
      • a failed parent read fails the run.
    • The existing prMerged tests now also expect the "stays open" line.

Slice: #656

🤖 Generated with Claude Code


Summary by cubic

Slice done now closes a Work item once a merged pull request leaves it done, after closing the Slices and States the pull request names. The rule lives in the new src/work-done.ts, which the hourly sweep (#657) reuses.

A Work item is closed as completed, with a comment naming its sub-issues and the pull request, when its body says **Slices:** all filed, it is open with an owner's approved label, it has no needs-owner label, every sub-issue and every State under its Slices is closed, at least one Slice closed as completed, and it was not reopened after its last sub-issue closed. Otherwise the run prints one line saying why it stays open. A Work item in another repository is left to that repository's own jobs, and one whose sub-issues GitHub does not list to the token stays open.