07 Implement
text $ARGUMENTS
# /sp:07-implement — In-Session Implementation Orchestrator
## User Input
```text
$ARGUMENTS
Arguments are optional context. Ralph derives its scope from the current branch automatically, so no epic argument is required.
Purpose
Drain the feature epic's ready queue by running the /ralph skill in the
main session. Ralph runs the prep/verify bookkeeping scripts inline and
dispatches one short-lived ralph-worker subagent per task, returning when the
queue is drained.
Critical: orchestrate in the main conversation
Run all of the following directly in the main conversation. Do NOT delegate
orchestration to a subagent. Ralph works by running its prep/verify scripts
inline and dispatching a ralph-worker Agent per task, and subagents cannot
spawn subagents — if this command handed the whole job to an orchestrator
subagent, that subagent could neither dispatch the worker nor persist prep's
beads writes, and ralph would collapse into one long-running inline context. The
preflight (Step 1) is the only part delegated to a subagent; everything else
— invoking ralph, and the completion handling — happens here, in the
user-visible session that ralph treats as its monitor.
(This mirrors /sp:08-harden, which orchestrates in the main conversation and
only launches leaf work — the reviews and the ralph drain — from there.)
Execution Steps
Step 1 — Preflight (subagent)
Launch the sp-07-implement agent via the Agent tool to gather facts:
Agent(subagent_type="sp-07-implement", description="sp:07 preflight",
prompt="Run preflight for /sp:07-implement and return your block.")
It returns exactly one block. Dispatch on it:
| Block | Action |
|---|---|
PROCEED … |
Store epicId. Display the listed ready tasks. Go to Step 2. |
COMPLETE … |
Store epicId. No ready tasks and the epic is fully closed. Skip Step 2; go to Step 3 to close out + report. |
BLOCKED … |
Report the wait condition (the listed blockers) to the user and stop — nothing is drainable yet. |
NO_TASKS |
Report: "No beads epic/tasks found. Run /sp:05-tasks to create them." and stop. |
Step 2 — Drain the queue (ralph, main session)
Invoke the /ralph skill in this session:
Skill skill=ralph
The current branch (the feature epic branch) drives ralph's scope detection
automatically — no epic argument needed. Ralph announces the chosen scope on
iteration 1 so the user can ^C if it picked wrong, then runs the loop
prep (inline) → worker (subagent) → verify (inline), one task per iteration,
until prep reports QUEUE EMPTY.
There is no daemon to monitor, no lockfile, no .ralph-monitor.json, and no
ScheduleWakeup chain. The session itself runs the loop and the user watches
live.
When ralph returns (queue drained), continue to Step 3.
Step 3 — Completion (main session)
Run directly in the main conversation.
a. Find the implement phase task:
IMPLEMENT_TASK_ID=$(br show <epic-id> --json | jq -r '.[0].dependents[] | select(.title | contains("[sp:07-implement]")) | .id')
b. Retire any finished grouping nodes left behind by an interrupted run
(defensive straggler sweep). A run interrupted mid-tick can leave a US<N>:
grouping parent open even though all its children closed — prep.sh retires
these incrementally, but if the run stopped between a leaf closing and the next
prep tick, the parent lingers open and keeps OPEN_COUNT > 0, so the phase
never closes. Before counting, sweep the implement task's direct dependents and
close any that are themselves DONE grouping nodes (all their parent-child
children closed), reusing prep's classifier:
pc_state() { # LEAF | ACTIVE | DONE
local s; s=$(br show "$1" --json 2>/dev/null | jq -r '
[.[0].dependents[]? | select(.dependency_type=="parent-child")] as $pc
| "\($pc|length) \([$pc[]|select(.status=="closed"|not)]|length)"')
read -r total open <<<"$s"
if [ "${total:-0}" -eq 0 ]; then echo LEAF
elif [ "${open:-0}" -gt 0 ]; then echo ACTIVE
else echo DONE; fi
}
for id in $(br show "$IMPLEMENT_TASK_ID" --json \
| jq -r '.[0].dependents[] | select(.status != "closed") | .id'); do
if [ "$(pc_state "$id")" = "DONE" ]; then
br close "$id" --reason "grouping node complete (all child tasks closed)"
fi
done
c. Count remaining open sub-tasks under it (after the sweep):
OPEN_COUNT=$(br show "$IMPLEMENT_TASK_ID" --json | jq '[.[0].dependents[] | select(.status == "open")] | length')
d. If all sub-tasks are closed, close the implement phase task:
if [ "$OPEN_COUNT" -eq 0 ]; then
br close "$IMPLEMENT_TASK_ID" --reason "All implementation tasks complete"
fi
e. Flush any pending .beads/ state — only when .beads/ is the only dirty
area:
if [ -n "$(git status --porcelain .beads/)" ] \
&& [ -z "$(git status --porcelain | grep -v '^...\.beads/')" ]; then
git add .beads/
git commit -m "chore(beads): sync state"
fi
f. Show the final summary:
br stats --json
br dep tree <epic-id> --direction up
g. If the implement phase closed: report "Implementation complete. Run
/sp:08-harden for the review + remediation cycle."
h. If open tasks remain: report the count and suggest next steps — usually,
inspect the failed tasks' beads comments, fix the underlying issue, then
re-run /sp:07-implement.
Error Recovery
- Authentication failure inside a subagent: surface to the user — they must re-authenticate before re-running.
- Repeated task failures: each failure leaves a
FAILED:comment on the task. Review withbr comments list <id>. - No epic found: verify the
Maintain 07 Implement?
Let people know it's listed here — add the badge (live metrics, light/dark aware) or a plain link to your README or docs.
[07 Implement on getagentictools](https://getagentictools.com/loops/silcam-sp-07-implement-in-session-implementation-orchestrator?ref=badge)