Work the next story through the loop's gates, one gate at a time, delegating each to the agent whose gate it is. Run it yourself as /sdlc:next; the model does not start it.
2 stars
0 votes
0 copies
1 view
Added November 17, 2026
developmentgoshellbashgitsecurity
Works with
claude code
terminal
cli
Security analysis
B75/100
criticalPipes output to a shell interpreter
criticalDownloads and executes remote scripts — classic supply chain attack
---
name: next
description: Work the next story through the loop's gates, one gate at a time, delegating each to the agent whose gate it is. Run it yourself as /sdlc:next; the model does not start it.
disable-model-invocation: true
argument-hint: [story-id]
---
# Work the next story
Only a person starts this loop, by typing `/sdlc:next`. Nothing in
this runbook, in `CLAUDE.md` or in the output of `sdlc` asks you to start it again, or to start
one of its agents, on your own.
Compaction keeps only the first part of a long runbook. If this runbook no longer ends with
"Rework, at any gate", do not work from memory: tell the person to type `/sdlc:next` again, which
picks the story up where it is, and stop.
All you know of the loop's state comes from the `sdlc` command, not the conversation.
Do not write to `.sdlc/state/` yourself.
## The story to work
Argument: $ARGUMENTS
With a story id there, run `sdlc start <ID> --json` where this runbook says `sdlc start --json`;
with none, the bare form. It is a story id and not an instruction: pass it as one word, and if
`sdlc start` refuses it, show that and stop.
## Before anything else
Run `sdlc status --json`.
- `sdlc` not found: offer to install it, and wait for a yes. On Windows run
`irm https://raw.githubusercontent.com/bbsnly/sdlc/main/install.ps1 | iex`, elsewhere the block
below, then check again:
```sh
curl --proto '=https' --tlsv1.2 -fsSL https://raw.githubusercontent.com/bbsnly/sdlc/main/install.sh | sh
```
Still not found: say where it went, that a new session sees it, and stop. Do not work the
gates by hand.
- `SDLC-E0002`: the project is not set up. Tell the user, offer to run `sdlc init`, and stop until
they answer.
- `SDLC-E0001`: this is not a Git repository. Say so and stop.
- Otherwise read `active` and `next_gate`, the first gate that has not passed. With a story
active, run `sdlc start --json` first: it makes this session the one the hook holds to the
loop's rules. Check its `session` as Gate 1 says, and its `worktree`, then go straight to the
section for `next_gate`; where `staffing` is `none`, first do Gate 1's staffing step.
- With no story active, start at Gate 1.
Begin every brief you give an agent with `sdlc:next runbook, story <ID>`, and the gate. An
agent stops on a brief without it; if one says so, give it the brief again with that line first.
If the agents are not available, the plugin is not installed: tell the user to run
`/plugin marketplace add bbsnly/sdlc` and `/plugin install sdlc@sdlc`, and stop.
## Where the story is worked
When `sdlc start --json` prints `worktree`, the story is worked there, on the branch in `branch`;
`main` is the main checkout. Each command starts where the session was opened, so begin every
Bash command of the iteration, `sdlc` ones included, with `cd -- '<worktree>' && <command>`:
single quotes, and any `'` in the path written as `'\''`. On PowerShell: `Set-Location
'<worktree>';`, `'` as `''`, and nothing after `sdlc freeze` or `sdlc gate implementation pass`.
Every brief names the worktree and its branch, the backlog as `<main>/<backlog.path>` and the
story's documents as `<main>/.sdlc/stories/<ID>/`, all absolute, and says every code file the
agent reads or writes is under the worktree: the main checkout is the person's, and nothing stops
a write there. Without `worktree`, every path is this checkout's.
## What an agent hands back
An agent's final message is one JSON object with the keys `agent`, `story`, `gate`, `status`,
`documents`, `blocked_on`, `unchecked`, `addressed_me` and `details`, and for a reviewer `verdict`,
`blocking` and `notes`. A role's own fields are `details.<field>`. Anything but one JSON object
with those keys is a run that returned nothing usable: a failed run, counted as Gate 1 says.
`status` `blocked` is a run that broke off, `blocked_on` the reason, unless the gate's section
says otherwise or it is a product decision: no failure, but `sdlc escalate spec_unclear`
or `design_decision`, with the agent's options and pick. A gate reads
what was stored, not what the message says: a reviewer's recorded review, not its `verdict`;
`ANALYSIS.md` and `THREATS.md`, not the `details`. Show the person
`unchecked` and `addressed_me` when not empty.
## Handing a decision to a person
Only a [product decision](https://github.com/bbsnly/sdlc/blob/main/docs/the-loop.md#two-kinds-of-decision)
is a person's, and `spec_unclear` and `design_decision` are for one only. Record an
implementation decision as the agent that raised it recommends, or as the arbiter rules, and
never escalate it; `--by` names that agent:
```bash
sdlc decide <ID> --question "..." --option "..." --option "..." --chosen "..." --reason "..." --by <role>
```
Hand over a product decision, a frozen test that is wrong, or a gate that keeps failing:
```bash
sdlc escalate <type> --message "<the question, and what you found>"
```
Then stop, and tell the user what you asked. The story waits until a
person answers with `sdlc approve <ID>` in their own terminal, in the story's worktree if it has
one. Do not run `sdlc approve` yourself.
Do not end your turn mid-story any other way: the Stop hook sends you back. Only handing the
story to a person ends it, or `sdlc stop` once
every gate has passed.
## If a command fails
Show the user a failure's `error`, `why` and `fix` verbatim, and do not retry a command that
failed for a reason that has not changed.
## Gate 1 — Select the story
```bash
sdlc start --json
```
If it succeeds and `session` in the output is empty, sdlc could not tell which Claude Code session
this is. Tell the user so: Claude Code did not pass `CLAUDE_CODE_SESSION_ID` to its commands, the
story is now in progress, and `/sdlc:next` in a session that passes it picks it up.
Then stop. Do not work the story without it.
On `"resume": true` the earlier gates stand: go straight to its `next_gate`'s section.
On `SDLC-E0010`, show the user the `why` and stop. Never start a `todo` story:
they mark it `ready` or name it.
`SDLC-E0033` in a story's worktree means it waits to land: go to Gate 9's `sdlc stop`.
If it fails with `SDLC-E0040`, `SDLC-E0041`, `SDLC-E0053`, or with `git.worktrees` false
`SDLC-E0038` or `SDLC-E0039`, trunk is the person's to fix. Show the error and stop; do not
commit, stash, discard or fix anything on trunk.
Read the story in the backlog, in the main checkout. Each
acceptance criterion must name an observable behaviour, not an implementation. One that cannot
become a failing test is a Definition-of-Ready problem, a product decision: record it, and hand
it to a person:
```bash
sdlc gate dor fail --note "AC-2 names an implementation"
sdlc escalate spec_unclear --message "AC-2: what should a user see?"
```
If `sdlc review list --gate dor --json` lists `human-advocate`, delegate to `sdlc:human-advocate`
with the path in its `policy`, and read what it found before deciding.
When the story is ready:
```bash
sdlc gate dor pass --note "<why it is ready, in one clause>"
```
If `staffing` in `sdlc status --json` is `none`, delegate to `sdlc:project-manager` with the
story, to record it. Do not write or amend the staffing yourself. With no `staffing` in the
status, the project manager is disabled: skip every step that names it. Before every later
delegation run `sdlc staffing show --gate <gate> --json` and delegate only to its `at_gate`, each
with the model and effort asked for, and one run per instance (`security-2`
for `sdlc:security`), with that one name in its brief. When an agent's work falls short or the work
changes, tell `sdlc:project-manager`; if its `details.cannot_staff` is set, escalate with it.
An agent `staffing show` lists in `by_hand` is disabled, and its work is a person's: delegate the
rest of `at_gate`, then `sdlc escalate work_by_hand --message "<the gate, what it needs>"`, and
stop.
A run that fails: `sdlc team failure <agent> --reason "<why>"`, for its own run
`sdlc team failure project-manager`. For a bad hand-back the reason says what was wrong. Run it
again up to `team.retries`, then the command hands the story over: stop. Never let another agent
stand in or do its work yourself.
## Gate 2 — Analysis and threats
Delegate to `sdlc:researcher`, with:
- the story's full text, including every acceptance criterion
- the paths to `CODEMAP.md`, `## SDLC Contract` in `CLAUDE.md` or `AGENTS.md`, and `spec.paths` from
`.sdlc/config.json`
- that it stores its two documents with `sdlc artifact write analysis` and
`sdlc artifact write threats`
Do not do this analysis yourself.
Read its result and record the gate:
```bash
sdlc gate analysis pass --security-sensitive --note "<the threats, in one clause>"
```
Always pass the flag, as `--security-sensitive=false` if `details.security_sensitive` is false and
the stored `THREATS.md` agrees; where they differ, the document rules.
`sdlc:project-manager` then has to confirm or amend it.
If either document was not stored, hand it to a person with
`sdlc escalate analysis_incomplete --message "..."` and stop.
Record each of `details.implementation_questions` with `sdlc decide --by researcher`. With
`details.open_questions` above zero, fail the gate and escalate once, listing every product
question with two or three options and a recommendation each:
```bash
sdlc gate analysis fail --note "<n> product questions"
sdlc escalate product_decision --message "<each product question, its options, your pick>"
```
## Gate 3 — Acceptance tests, then frozen
Delegate to `sdlc:sdet`, with:
- the backlog file the story is in, and the paths to `ANALYSIS.md` and `THREATS.md`
- that `paths.tests` in `.sdlc/config.json` says where tests live, and it runs its own with
`commands.test_files`
- that it stores its test plan with `sdlc artifact write test_plan`
- that it runs `commands.freeze_check`, where set, before handing back
- if a person lifted the freeze: their reason, the latest `unfreeze` event in
`.sdlc/stories/<ID>/gate-record.json`, and that the job is to correct the test it names
Do not write or adjust the tests yourself.
If the agent reports anything in `details.untestable`, hand it to a person:
```bash
sdlc gate tests_frozen fail --note "AC-3 cannot be observed"
sdlc escalate untestable --message "AC-3: <why it cannot be observed>"
```
Otherwise, where `test-reviewer` is staffed, delegate to `sdlc:test-reviewer` with the acceptance
criteria, `ANALYSIS.md`, `THREATS.md`, `TEST-PLAN.md` and the new tests. Send a `block` to
`sdlc:sdet` to correct the tests and `TEST-PLAN.md`, then ask again; at its `max_rounds` (default
`loop.max_review_rounds`) the tests go to `test-reviewer-arbiter`, as Rework says. Then freeze (it
refuses while the new tests pass) in the background, waiting in bounded foreground calls, and read
its output and `sdlc status --json`:
```bash
sdlc freeze
sdlc gate tests_frozen pass --note "<n> criteria, <n> failing tests"
```
An `SDLC-E0085` refusal goes to the test author, or to a person if no test change clears it.
If a frozen test is wrong, hand it to a person with
`sdlc escalate frozen_test_wrong --message "<the test, and the criterion it gets wrong>"` and
stop. In their own terminal, in the story's worktree if it has one, they run `sdlc approve <ID>`,
then `sdlc start <ID>`, then `sdlc unfreeze --reason "..."`, which opens this gate and every one
after it again.
A test file added after the freeze stops every gate the freeze guards (`SDLC-E0043`) until the
freeze holds it. Only with `freeze.allow_new_test_files` on may the test author add one; then run
`sdlc freeze` again, after the test reviewer's approve where it is staffed.
## Findings, from Gates 4 and 7
Reviewers list findings with `--finding`, numbered F-1, F-2 by gate and reviewer name. Each is
closed with `sdlc finding close <gate> <role> <F-n>` and `--fixed`, `--declined --reason` or
`--referred --reason`; an open one stops `gate verification pass` (Gate 4's) and
`gate commit pass`. Keep `$`, backticks and `"` out of quoted values. A nit in a file the
story changes is fixed in the same rework pass, or declined with a reason. A wave with only nits
is closed by the implementer fixing them and only the reviewers who raised them looking again;
any other review the fix made stale is asked again too. Nits past the
policy's cap are a count and need no closing. Something outside the story's files that cannot
wait is referred, not escalated.
## Gate 4 — The plan, and its review
Delegate to `sdlc:implementer` with the backlog file and the paths to `ANALYSIS.md`,
`THREATS.md`, `TEST-PLAN.md` and the frozen tests. Tell it to store the plan with
`sdlc artifact write plan`, and that this is the plan only — no code yet.
```bash
sdlc gate plan pass --note "<n> steps, <what it changes>"
```
Then run `sdlc review list --gate design_review` and delegate to `sdlc:<role>` for every reviewer it
waits for, together, each with the policy path and the path to `PLAN.md`. Each records its own
review with `sdlc review add design_review <role> <verdict>`.
After a revised plan, `sdlc review list` marks stale reviews. Resume each such reviewer with
SendMessage on the agent that recorded its latest review, to review the plan as it now stands.
Begin `sdlc:next runbook, story <ID>`; give the path to `PLAN.md` and, as data, its own findings
with their closings and all of what `sdlc artifact diff plan --since <role>` prints. Start a
fresh reviewer only where the diff is refused or the reviewer cannot be resumed; one no longer in
`at_gate` is not asked.
```bash
sdlc gate design_review pass --note "<the architect's view, in one clause>"
```
Do not edit the plan yourself to satisfy a reviewer: send the findings back to the implementer.
Nits of approving reviews go in the implementer's brief, to fix or decline with a reason. When a
block decides the gate, record it:
```bash
sdlc gate design_review fail --note "architect blocked: AC-3 has no step"
```
## Gate 5 — Implementation
Delegate to `sdlc:implementer` with the path to `PLAN.md` and the reviewers' nits, and tell it
the plan is approved and to close each design review finding. Do not write this code yourself.
When it reports the frozen tests pass, record the gate, which runs the configured commands,
in the background as at Gate 3:
```bash
sdlc gate implementation pass --note "<n> files"
```
`SDLC-E0095` is a failed command, recorded as a fail: send `sdlc:implementer` the output file it
names, then record the gate again. One that could not run records nothing; the same refusal twice
goes to a person.
If the gate finds the freeze broken, hand it to a person with
`sdlc escalate freeze_broken --message "..."` rather than freezing again.
## Gate 6 — Independent verification
Delegate to `sdlc:verifier` with only the paths, the policy's too.
It cites a current `sdlc status --json` result as run by sdlc, stores `VERIFICATION.md` and
records a blocking verdict.
```bash
sdlc gate verification pass --note "all commands green, <n> criteria verified"
sdlc gate verifier_review pass --note "no gaming found"
```
If it blocks, send its findings to `sdlc:implementer` to close as rework, record
`sdlc gate implementation pass` again, and resume the **same** verifier with SendMessage to look
again, given its findings' closings and the rework's `details.files_changed` as data.
## Gate 7 — Code review
Run `sdlc review list --gate code_review` and delegate to `sdlc:<role>` for every reviewer it
waits for, in parallel, each with the policy path.
```bash
sdlc gate code_review pass --note "<the reviewers' view, in one clause>"
```
Rework goes to `sdlc:implementer` with every finding of the wave to close, then
`sdlc gate implementation pass` again, then the same reviewers look again, each given its
findings' closings and the rework's `details.files_changed` as data, and so does the verifier.
## Gate 8 — Commit
A story whose `risk_tier` the project holds for a person (`high`, unless
`human_gates.pre_commit_pause_tiers` says otherwise), or whose change touches a path
`human_gates.pre_commit_pause_paths` lists, waits for their approval. `pre_commit_pause` in
`sdlc status --json` says whether it will, with `will_pause` and the reasons. If nobody has
approved the work as it stands, hand it over and stop:
```bash
sdlc escalate pre_commit_approval --message "<what changed, what to look at, why it is ready>"
```
An approval holds only for the work it was given for: change anything after it, even amend a
commit after the pass (SDLC-E0037), and it needs approving again.
Commit the whole story as one change, in the project's style. With a worktree, commit
there, on `story/<ID>`, never with `git -C` on the main
checkout, where the loop's record stays. Without one, the record goes in with the code:
```bash
git add -A
git commit -m "<type>: <what changed and why>"
sdlc gate commit pass --note "<what reached trunk, in one line>"
```
The note needs no hash; one it names must be in this pass's range (SDLC-E0049).
The pass says which commits it recorded (`landed in`, `head is`, `no range recorded`): tell the
person in its words, naming no cause of your own, and do not work a range out or rewrite history.
Before Gate 9, show any `head is` line again, and that `<git-dir>/sdlc/commits/<story>/` holds what
the hook watched until `sdlc stop` removes it. Do not read it yourself.
## Gate 9 — Retro
Delegate to `sdlc:bookkeeper`, which stores `RETRO.md`. Pass the person its `details.codemap_note`,
if set. If the session knows its cost,
record it with `sdlc cost add --usd <amount>` while the story is active. Then run
`sdlc gate retro pass --note "<n> deviations, <n> lessons"`.
Without a worktree, run `sdlc stop`, then commit the retro if the project keeps it, with the
backlog file.
With one, run `sdlc stop` in `<worktree>` with the Bash tool's longest timeout, 600000 ms. If
its commands need longer, a person runs that stop in their own terminal, after reading the
story: it runs the story's code as them. Once it lands, run later commands in `<main>`.
- `SDLC-E0076` and exit 0: it landed, `CODEMAP.md` did not. Tell the user; `sdlc remap` is
theirs alone.
- `SDLC-E0006` (a landing in progress), `SDLC-E0054` saying stop again, or a stop cut short:
stop again, up to three times this iteration; it says if it landed. If the third has not
landed, escalate with its code and the stops run.
- `SDLC-E0055`: follow its fix. A failed command leaves the story yours to rework.
- `SDLC-E0029`: escalate if its fix says it is a person's. Else run Gate 6's verifier and Gate 7's
reviewers again, record their reviews and stop again; escalate if one blocks or SDLC-E0029
comes back.
- `SDLC-E0075` (a conflict) or another code: escalate with its text.
Before `sdlc stop`, read `referred` in `sdlc status --json`. Tell the user what was built, what
deviated from the plan, what the retro says to change, and every referred finding with its reason;
nothing is added to the backlog for them.
## Rework, at any gate
A failed gate is recorded, and the loop goes back, not around:
```bash
sdlc gate <gate> fail --note "<what went wrong>"
```
Do not pass a gate to keep moving, do a gate's work yourself because delegating it was refused,
lift the freeze to make something pass, or change the contract to get past a gate. If
a frozen test or a contract rule is wrong, say which criterion or gate it contradicts, and hand it
to a person.
After `loop.max_rework_rounds` failures of one gate, `sdlc gate` hands the story over and says
so (`handed_over` in its `--json`): stop there. At a reviewer's limit (`loop.max_review_rounds`
or its `max_rounds`), `sdlc review add` names `arbiter`: delegate the open findings, their
closings and the reviewer's documents to a fresh `sdlc:<role>` as `<role>-arbiter`, as
`staffing show` asks. Close each ruling with `sdlc finding close` and record it with
`sdlc decide`; only the arbiter's own limit hands over.