✨ feat(work): agents delete their closed pull requests' branches, and every owner ask carries its link (#557)
Slice: #557
Agents now delete their own closed pull requests' branches, and every niyam text that sends an agent to the owner names the full address to act at. Alok asked in chat for both corrections in code, not agent memory. The proposal: https://github.com/veda-hq/niyam/issues/557#issuecomment-7077719296 (page: https://claude.ai/artifact/UxjVcfmACqbUEeWmPaakG9).
Why. On veda-hq/veda#383 an agent closed veda-hq/veda#382 as superseded and left its branch. The branch held a secret-shaped token, so every pull request's Secret scans check failed. The agent then asked Alok to delete the branch, and to 👍 "comment 7068450411 on #376", with no link.
Rule A: an agent deletes its own superseded or closed branches.
sliceProblems(src/work.ts): the "one slice, one pull request" refusal gives the other pull request'shtml_url. For a branch in this repository it addsIf #M is superseded, close it and delete its branch: git push origin --delete <head ref>, quoting a ref the shell would split. For a fork's branch it says only to close it.- The keep-going Stop hook (
src/keep-going.ts):leftBranchesreads the latest 100 closed pull requests. It keeps those that:- are unmerged;
- come from this repository;
- were opened by an agent the settings name;
- name a slice this branch's own
Slice:trailers name; - are not on the current branch;
- whose branch builds no open pull request and still exists (
git/ref/heads/<ref>answers 200).
- While any such pull request is found, the session is sent back with its URL and the delete command. This happens before the merged and desktop-ready releases, which is the path the veda#383 session stopped through. The subagent, stop-note, running-push and GitHub-unknown releases still come first.
- Anything GitHub or the settings cannot answer gives no pull requests, so the hook fails open. The pull requests are matched by slice, not by author alone, because every session works as the same agent.
- A session's own branch whose pull request was closed unmerged is now told the same delete command, with the pull request's URL.
- niyam's own pre-push lets a delete-only push through: it skips a ref line whose local sha is all zeros.
doctor(src/doctor.ts): in an onboarded clone,✗whendelete_branch_on_mergeis off. A writer's token reads that setting. The fix names the owner andhttps://github.com/<repo>/settings. Nothing is shown when GitHub says nothing about it, and a failed read is a▲. onboard does not turn the setting on, because changing a repository setting is the owner's call.
Rule B: asks carry full URLs. Each of these now names the full address to act at.
- Work rules (
owedProblem,readSlice): the work item, the slice, the dropped State and the Approvals issue. Where an agent proposal exists, it gives the proposal's#issuecomment-URL. propose's comment links the Approvals issue in full.- Guard (
scripts/guard.mjs):how()reads "approve the slice again at https://github.com//issues/";approvedAt's refusals name the work item, the slice, the Approvals issue and the newest agent proposal'shtml_url.
- needs-owner (
src/asks.ts): the "labelled" line and the sweep's "waits on the owner" line name each ask's comment URL, or the issue's when GitHub gives none.
README and docs/decisions.md say so.
Checked: pnpm check, exit 0:
pnpm test: tests 2161, pass 2161, fail 0
keep-going.ts 99.63 lines / 99.01 branches; work.ts 99.44 / 97.32; doctor.ts 100 / 98.66; asks.ts 100 / 96.72
pnpm test:scripts: tests 133, pass 133, fail 0
guard.mjs 100.00 lines / 97.11 branches
typecheck, lint, pins, pariksha, sarathi, build, smoke: pass
New tests:
- the refusal with URL and delete command, for a fork's branch, with GitHub's own
html_url, and with a quoted ref; - the Stop hook holding a session that is merged, desktop-ready or open while a branch is left, listing several branches, and still letting it go at a stop note, a running push or GitHub-unknown;
leftBranchespassing over pull requests that are merged, deleted, from a fork, from no repository, by the owner, by no one, for another slice, with no body, on this branch, malformed, or that an open pull request builds; naming a branch once; and failing open with no slice, no settings, a refused or offline list, a refused branch read, or an unknown pull request;- doctor with the setting on, off, unsaid, refused, outside a clone, and unreachable;
- the Guard texts, including the proposal's
html_url, and the case where none is given; - needs-owner with a comment's own
html_urlin both the event and the sweep.
Guards: scripts/guard.mjs, scripts/guard.test.mjs. scripts/guard.mjs is code-owned by Alok, so this waits for his review.
After merge: veda, athya_mono and other clients get this only after a niyam release and a pin bump in each. veda-hq/veda has delete_branch_on_merge off today. An admin turns it on at https://github.com/veda-hq/veda/settings.
🤖 Generated with Claude Code
Summary by cubic
Agents now delete their own closed pull requests' branches, and every ask that sends the agent to the owner carries the full link to act at. Previously an agent closed a superseded PR, left its branch holding a secret-shaped token that broke Secret scans, then asked the owner to delete it and react to a bare issue number.
Bug Fixes
- The keep-going Stop hook holds the session while an agent's closed, unmerged pull request for its slice still has its branch on origin, even when the session's own PR merged or is ready on the desktop; it asks after at most five branches a stop, checks every candidate's branch newest first within 30 reads so already-deleted branches hide none, treats only a 404 as a deleted branch and stops at any other GitHub answer, asks open pull requests by each head, and fails open on anything GitHub or settings cannot say.
- The "one slice, one pull request" refusal gives the other pull request's URL and, for a branch in this repository, the
git push origin --deletecommand; a branch starting-or+is namedrefs/heads/…so git reads it neither as an option nor as a forced push. doctorflags repositories withdelete_branch_on_mergeoff, names the settings page, reads the repository fromCLAUDE_PROJECT_DIRwherever it runs, and checks through the cloud proxy; onboarding leaves the setting to the owner.- Work rules, Guard,
propose, and needs-owner texts name fullhttps://github.com/…addresses, preferring the proposal comment's own#issuecomment-link.
Migration
- Clients receive this only after a niyam release and a pin bump;
delete_branch_on_mergestays off in veda until an admin enables it.