[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M75GZWJ9QDFV4BT01RM12T85":3,"skill-same:01M75GZWJ9QDFV4BT01RM12T85":82},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":23,"commitSha":24,"skillDirectory":25,"forksCount":13,"repositoryHtmlUrl":26,"repositoryHomepageUrl":27,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":29,"install":30,"resources":43},"01M75GZWJ9QDFV4BT01RM12T85","forge-5-loop",null,"Execute the autonomous coding loop (rauf by default) against a forge feature's backlog. Use when user runs forge-5-loop or forge-5-rauf-loop, or asks to run rauf \u002F run the loop \u002F implement a forge feature after the backlog is created and verified. Do NOT trigger for general rauf usage, standalone loop runs, or implementation tasks outside the forge pipeline.","garygentry\u002Ffeature-forge","garygentry","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F12444042?v=4","01M75GWTRXHQMKFWDVG9N8ENNS","01M75GWTSZ5NV3MYKFWVCZJKW4",0,"MIT","https:\u002F\u002Fgithub.com\u002Fgarygentry\u002Ffeature-forge\u002Fblob\u002Fmain\u002Fadapters\u002Fcodex\u002Fskills\u002Fforge-5-loop\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\n# GENERATED — DO NOT EDIT. Source: skills\u002Fforge-5-loop\u002FSKILL.md. Regenerate: python3 scripts\u002Fbuild-adapters.py\nname: forge-5-loop\ndescription: Execute the autonomous coding loop (rauf by default) against a forge feature's backlog. Use when user runs forge-5-loop or forge-5-rauf-loop, or asks to run rauf \u002F run the loop \u002F implement a forge feature after the backlog is created and verified. Do NOT trigger for general rauf usage, standalone loop runs, or implementation tasks outside the forge pipeline.\n---\n\n# forge-5-loop — Autonomous Loop Executor\n\nThe loop spawns a fresh agent session per backlog item, implementing each task with full verification.\n\nThe loop **runner** is configured, not hardcoded. feature-forge talks to it through the `loopRunner` block in `forge.config.json`; rauf is the default and reference implementation (see `references\u002Fralph-loop-contract.md`). Every command below is rendered from `loopRunner` with token substitution — no hardcoded `rauf …` commands; even the human log filename is tokenized (`{loopRunner.logFile}`).\n\n## Resolve the loop runner\n\nResolve the effective `loopRunner` with the command below — it merges this project's `loopRunner` block over the schema defaults deterministically, so do not read the config schema for defaults. **If `forge.config.json` has no `loopRunner` block at all, state plainly: \"No loopRunner configured — defaulting to the rauf loop runner.\"** then proceed with the full default block, which is exactly what the call returns. If the call exits 2, surface the plain `Error:` line from stderr verbatim and fall back to the documented rauf defaults.\n\n```bash\nR=\"$(bash -c '[ -z \"${FEATURE_FORGE_ROOT:-}\" ] || [ -x \"$FEATURE_FORGE_ROOT\u002Fscripts\u002Fforge-root.sh\" ] || { echo \"feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts\u002Fforge-root.sh\" >&2; exit 2; }; for d in \"${FEATURE_FORGE_ROOT:-}\" \"${CLAUDE_PLUGIN_ROOT:-}\" \"$HOME\"\u002F.claude\u002Fskills\u002Ffeature-forge \"$HOME\"\u002F.claude\u002Fplugins\u002Fcache\u002F*\u002Ffeature-forge\u002F* \"$HOME\"\u002F.claude\u002Fplugins\u002F*\u002Ffeature-forge \"$HOME\"\u002F.agents\u002Fskills\u002Ffeature-forge .\u002F.agents\u002Fskills\u002Ffeature-forge; do [ -x \"$d\u002Fscripts\u002Fforge-root.sh\" ] && exec \"$d\u002Fscripts\u002Fforge-root.sh\"; done')\"\n[ -n \"$R\" ] || { echo \"feature-forge: cannot locate plugin root\" >&2; exit 1; }\npython3 \"$R\u002Fscripts\u002Fforge-session.py\" effective-config --config .\u002Fforge.config.json --json\n```\n\nToken substitution applies to every `*Command` string. Substitute:\n\n- `{bin}` → `loopRunner.bin` (default `rauf`)\n- `{backlogDir}` → the resolved backlog directory (Step 1d \u002F 2b), relative to project root\n- `{specsDir}` → `specsDir` from config\n- `{iterations}` → the computed iteration count (Step 2a)\n\nWhenever this skill says \"run the **run command**\" \u002F \"**status command**\" \u002F etc., it means the corresponding substituted `loopRunner.*Command`.\n\n**Turn structure reminder:** Text first, then host's question mechanism for all questions — never embed one in your text (it stalls). At rung 2\u002F3, see the Interaction Capability Ladder.\n\n## Step 1: Validate Prerequisites\n\nRead and follow `references\u002Fshared-conventions.md` for feature name validation, configuration reading, and force mode handling.\n\n### 1a. Pipeline State Check\n\n**Resolve the feature directory first.** Invoke the **Feature Directory Resolution** block in `references\u002Fshared-conventions.md` to turn the bare feature name into `{resolvedFeatureDir}` (exit 0 → stdout is the absolute dir; exit ≥ 1 → STOP and surface the finding verbatim). Read state from `{resolvedFeatureDir}\u002F` everywhere this skill previously wrote `{specsDir}\u002F{feature}\u002F` (the 1e backlog path and the Step 3a \u002F Step 5 state writes). Standalone features resolve to their flat path exactly as today.\n\nRead `{resolvedFeatureDir}\u002F.pipeline-state.json`. If not in force mode, `stages.forge-4-backlog` must be `complete`. If not, STOP and tell the user: \"Backlog hasn't been created yet. Run `forge-4-backlog {feature}` first.\"\n\nIf the state's `notes` is non-empty, surface it before proceeding and treat it as run input — often backlog-time constraints; it never overrides specs or config (raise any conflict).\n\n### 1b. Verification Check\n\nDerive whether the upstream backlog has been verified from the settled on-disk record, never by eyeballing conversational state. Run `verify-state --for-stage forge-4-backlog` — it reads the served stage's `forge-verify-backlog` entry and returns `{case, verified, stale, message, nextCommand}`. Add `--epic \"{epic}\"` when this feature is an epic member (nested layout). The full case enum and its rationale live in `references\u002Fverify-state.md`.\n\n```bash\nR=\"$(bash -c '[ -z \"${FEATURE_FORGE_ROOT:-}\" ] || [ -x \"$FEATURE_FORGE_ROOT\u002Fscripts\u002Fforge-root.sh\" ] || { echo \"feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts\u002Fforge-root.sh\" >&2; exit 2; }; for d in \"${FEATURE_FORGE_ROOT:-}\" \"${CLAUDE_PLUGIN_ROOT:-}\" \"$HOME\"\u002F.claude\u002Fskills\u002Ffeature-forge \"$HOME\"\u002F.claude\u002Fplugins\u002Fcache\u002F*\u002Ffeature-forge\u002F* \"$HOME\"\u002F.claude\u002Fplugins\u002F*\u002Ffeature-forge \"$HOME\"\u002F.agents\u002Fskills\u002Ffeature-forge .\u002F.agents\u002Fskills\u002Ffeature-forge; do [ -x \"$d\u002Fscripts\u002Fforge-root.sh\" ] && exec \"$d\u002Fscripts\u002Fforge-root.sh\"; done')\"\n[ -n \"$R\" ] || { echo \"feature-forge: cannot locate plugin root\" >&2; exit 1; }\npython3 \"$R\u002Fscripts\u002Fforge-session.py\" verify-state --feature \"{feature}\" --for-stage forge-4-backlog --specs-dir \"{specsDir}\" --json\n```\n\nIf `verified` is true, proceed with no prompt. Otherwise print the returned `message`, then use host's question mechanism to warn with the cost of skipping — the loop implements items autonomously and commits as it goes, so a bad item is far cheaper to catch now than after commits build on it — and offer **Verify first (recommended)** (run the returned `nextCommand`) · **Continue without verifying**. This is a pre-stage read of the upstream artifact, so the proceed-anyway path writes **nothing** — in particular a `stale` result (fixes applied, re-verify still owed) must not be demoted to `skipped`: `state-verify` refuses that write (#203) and the recorded status already says re-verification is outstanding.\n\n### 1b-epic. Epic Dependency Gate\n\nRead the resolved feature's `.pipeline-state.json`. **If it has no `epic` key, skip this sub-step entirely** (standalone feature — REQ-COMPAT-01; standalone runs are unchanged). Otherwise:\n\n1. Run `render-status \"{epic}\" --specs-dir \"{specsDir}\" --json` via the helper:\n\n   ```bash\nR=\"$(bash -c '[ -z \"${FEATURE_FORGE_ROOT:-}\" ] || [ -x \"$FEATURE_FORGE_ROOT\u002Fscripts\u002Fforge-root.sh\" ] || { echo \"feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts\u002Fforge-root.sh\" >&2; exit 2; }; for d in \"${FEATURE_FORGE_ROOT:-}\" \"${CLAUDE_PLUGIN_ROOT:-}\" \"$HOME\"\u002F.claude\u002Fskills\u002Ffeature-forge \"$HOME\"\u002F.claude\u002Fplugins\u002Fcache\u002F*\u002Ffeature-forge\u002F* \"$HOME\"\u002F.claude\u002Fplugins\u002F*\u002Ffeature-forge \"$HOME\"\u002F.agents\u002Fskills\u002Ffeature-forge .\u002F.agents\u002Fskills\u002Ffeature-forge; do [ -x \"$d\u002Fscripts\u002Fforge-root.sh\" ] && exec \"$d\u002Fscripts\u002Fforge-root.sh\"; done')\"\n[ -n \"$R\" ] || { echo \"feature-forge: cannot locate plugin root\" >&2; exit 1; }\npython3 \"$R\u002Fscripts\u002Fepic-manifest.py\" \\\n  render-status \"{epic}\" --specs-dir \"{specsDir}\" --json\n   ```\n\n2. Find this feature's entry; read its `unmetDeps` (the direct `dependsOn` not yet complete-for-orchestration per `00-core-definitions.md §7`).\n3. **If `unmetDeps` is empty**, proceed to 1c with no prompt.\n4. **If `unmetDeps` is non-empty**, use host's question mechanism (do NOT inline the question as prose) to warn that the feature depends on the unmet dependencies, which are not yet complete, and that running the loop now means implementing against contracts that may still change:\n\n   > \"{feature} depends on {unmetDeps joined}, which are not yet complete. Running the loop now means implementing against contracts that may still change. Proceed anyway, or stop and finish the dependencies first?\"\n\n   Require an **explicit \"Proceed anyway\"** choice to continue (REQ-ORCH-04). \"Stop\" aborts before any runner setup. `--force` (shared-conventions Force Mode) also bypasses this gate with the standard force warning.\n5. If `render-status` fails, **STOP** — do not silently run a loop whose dependency state is unverifiable (REQ-ROBUST-02). Surface per the exit-1\u002Fexit-2 split in the **Feature Directory Resolution** block of `references\u002Fshared-conventions.md` (exit 1 → parse `{findings[]}` from stdout; exit 2 → surface the plain `Error:` stderr line verbatim — no findings JSON to parse).\n\nThis gate runs **before** the runner version\u002Fsetup gates (1c\u002F1d) so a blocked feature stops early, before any runner side-effects.\n\n### 1c. Runner Version Gate\n\n### 1d. Runner Setup Check (precondition file)\n\nThese gate on the loop runner being installed, current, and wired **before** touching it — enforced by `doctor`'s `runner-*` checks, never ad-hoc parsing. Run:\n\n```bash\nR=\"$(bash -c '[ -z \"${FEATURE_FORGE_ROOT:-}\" ] || [ -x \"$FEATURE_FORGE_ROOT\u002Fscripts\u002Fforge-root.sh\" ] || { echo \"feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts\u002Fforge-root.sh\" >&2; exit 2; }; for d in \"${FEATURE_FORGE_ROOT:-}\" \"${CLAUDE_PLUGIN_ROOT:-}\" \"$HOME\"\u002F.claude\u002Fskills\u002Ffeature-forge \"$HOME\"\u002F.claude\u002Fplugins\u002Fcache\u002F*\u002Ffeature-forge\u002F* \"$HOME\"\u002F.claude\u002Fplugins\u002F*\u002Ffeature-forge \"$HOME\"\u002F.agents\u002Fskills\u002Ffeature-forge .\u002F.agents\u002Fskills\u002Ffeature-forge; do [ -x \"$d\u002Fscripts\u002Fforge-root.sh\" ] && exec \"$d\u002Fscripts\u002Fforge-root.sh\"; done')\"\n[ -n \"$R\" ] || { echo \"feature-forge: cannot locate plugin root\" >&2; exit 1; }\npython3 \"$R\u002Fscripts\u002Fforge-session.py\" doctor --json --specs-dir \"{specsDir}\" --check runner-binary --check runner-version --check runner-wired --check runner-legacy-layout\n```\n\nAll four `ok`\u002F`na` → proceed silently. Otherwise follow `references\u002Fpreflight-and-self-heal.md`: `runner-binary`\u002F`runner-version` not `ok` → **HARD GATE FAILURE**, STOP with the check's own `remedy.description` (never a hardcoded `installHint` — a customized `bin` gets its own config-fix remedy, G4). `runner-legacy-layout` warn → STOP: \"This project is still on the legacy **Ralph** layout. Run {`remedy.command`, e.g. `{bin} migrate .`} first, then re-run `forge-5-loop {feature}`.\" `runner-wired` warn → STOP with `loopRunner.setupHint`. A STOP lifts only once a permitted `local-write` remedy ran **and** the identical re-run shows `ok`; `forge-guide --doctor` walks it.\n\n> `installHint` points at the runner **CLI**; `setupHint` (1d) installs its per-project artifacts.\n\n### 1e. Backlog File Check\n\nResolve the backlog file path (matching forge-4-backlog's composition rule, item 015 \u002F §6.2):\n- If `backlogDir` is set in `forge.config.json`: use `{backlogDir}\u002F{feature}\u002Fbacklog.json` (the per-feature subpath, so each epic member's backlog stays independent — the `{feature}` segment prevents collisions across a multi-feature epic)\n- Otherwise: use `{resolvedFeatureDir}\u002Fbacklog.json`\n\nVerify the file exists on disk. If not, STOP and tell the user: \"No backlog.json found at {path}. Run `forge-4-backlog {feature}` to generate it.\"\n\n### 1f. Branch Pre-flight (if using git)\n\nThe runner commits each item onto the current branch. Skip if not a git repo or `branchPerFeature` is false. Otherwise run the **Branch Reconciliation** block in `references\u002Fshared-conventions.md` (it runs `reconcile-branch` and, on `warn-drift` — you are on the default branch — strongly recommends creating `{branchPrefix}{feature}` via host's question mechanism before the loop commits; on `adopt-current` it updates the recorded branch to the current one, never pushing you back to a stale\u002Fimposed branch). Never hard-stop.\n\n### 1g. Stranded-Work Pre-flight (if using git)\n\nRun `git status --porcelain`. If it reports changes **and** `{backlogDir}\u002F{loopRunner.stateDir}\u002Fstate.json` exists from a previous run, **STOP**: name that run (its `startedAt`, `currentItem`, and `blockedItems` from `state.json`) and point the user at the **Post-Run Tree Reconciliation** section of `references\u002Frecovery-procedure.md` to commit \u002F stash \u002F discard the stranded work before relaunch — never auto-pass `--force`. If the tree is dirty with **no** prior-run `state.json`, keep today's behavior (surface it; let the user commit\u002Fstash or pass `--force`). A clean tree is silent.\n\n## Step 2: Construct the Loop Command\n\n### 2a. Analyze Backlog\n\nRun the **list command** (`loopRunner.listCommand`, default `rauf backlog list . --backlog {backlogDir} --json`) and count items by status: `pending`, `in_progress`, `done`, `blocked`. Pipe that same list-command JSON into `backlog-topology --items-stdin --json` (a `forge-session.py` verb — invoke it via Step 3a's `$R` fence) and read `maxChainDepth` to report alongside the iteration count — advisory only: no prompt, no operator decision.\n\nCalculate the iteration count: `ceil((pending + in_progress) * loopIterationMultiplier)` where `loopIterationMultiplier` comes from `forge.config.json` (default: 1.5, headroom for retries).\n\nThen, **whatever the counts**, run the **status-json command**: `reviewPending: true` (optional field) means a prior review pass failed or was interrupted — follow **Pending review** in `references\u002Frunner-contract.md` before any fresh run (which would drop it). Otherwise, with no pending or in_progress items: a reported `loopState` that is not a clean finish → follow **Unfinished runner** in that file; else STOP and tell the user: \"All backlog items are already done or blocked. Nothing to run.\"\n\nIf there are `blocked` items, note them — the user may want `--retry-blocked`.\n\n### 2b. Resolve Backlog Directory\n\n`{backlogDir}` is a **directory path** (not a file path), relative to the project root.\n\n- If `backlogDir` is set in config: use the per-feature subpath `{backlogDir}\u002F{feature}` (matching the 1e composition rule and forge-4-backlog §6.2).\n- Otherwise: use `{resolvedFeatureDir}` (the directory containing `backlog.json`).\n\n### 2c. Build Command\n\nRender the **run command** (`loopRunner.runCommand`) with token substitution, e.g. the rauf default becomes:\n\n```\nrauf loop run . --backlog specs\u002Fauth --iterations 15\n```\n\n### 2d. Confirm with User\n\nUse host's question mechanism to present the rendered run command and options. The following block is the content for host's question mechanism — do NOT output it as text:\n\n```\nReady to run the loop for {feature}:\n\n  {rendered runCommand}   # + \" --review\" when the recommended Run-mode option (below) is picked\n\nBacklog summary:\n  - Pending: {pending}\n  - In progress: {in_progress}\n  - Done: {done}\n  - Blocked: {blocked}\n  - Iterations: {iterationCount} ({activeItems} items x {loopIterationMultiplier} multiplier)\n  - Max chain depth: {maxChainDepth} — depth bounds achievable progress regardless of iteration budget\n\nFor the model-selection precedence (item.model > --model\u002Foptions > project default >\nprovider default), read references\u002Frunner-contract.md.\n```\n\n**Run mode and full loop-runner contract:** follow `## Run mode (Step 2d, rauf)` and the remaining sections in `references\u002Frunner-contract.md` verbatim; `loopRunner.reviewMode` (`\"always\"`\u002F`\"never\"`) suppresses the Run-mode question — semantics live there.\n\n#### Agent selection (gated on `loopRunner.agentArgument`)\n\n**Capability gate.** Everything below applies **only when** the effective `loopRunner.agentArgument` is present and non-empty. **When it is absent or empty, Step 2d is exactly the confirmation above — no probe, no agent question, no availability listing, no `Agent:` line — byte-identical to today** (REQ-PLUG-02, REQ-COMPAT-01). The full algorithm, precedence, and verbatim message shapes are in `## Agent selection` of `references\u002Fagent-selection.md`; read it. When the gate is on, augment Step 2d in order:\n\n- **(a) Probe once.** Before confirming, run `loopRunner.agentsProbeCommand` (default `{bin} agents --json`) **exactly once** (no retries, no second probe); it exits 0 with `{ agents: [...] }`. Parse `agents[]`; build the advertised set `{ row.id }` — this one parsed array drives (b)–(d).\n- **(b) Agent question.** Add an **\"agent\"** question to the same host's question mechanism surface: **one option per advertised row** labelled `\"{displayName} ({id}) — available\u002Fnot found\"`, **plus an explicit `\"default (claude-cli)\"` choice mapping to `run_selection = None`**. Resolve the pick (run > project, empty\u002Fwhitespace unset, an explicit runner-default pick collapses to the default path) into `{resolved.agent, resolved.source}`. Precedence: `item.provider > --agent > project defaultAgent > runner default` (forge never reads a backlog item's provider). Under `loopRunner.agentMode: \"auto\"`, skip this question (`run_selection = None`); (a)\u002F(c)\u002F(d)\u002F(d-model) still run — see `references\u002Fagent-selection.md`.\n- **(c) Availability listing.** From the **same** parsed `agents[]` (no second probe), list `id` \u002F `displayName` \u002F available (`yes`\u002F`no`, `detail` on unavailable rows).\n- **(d) Verdict** — only for a **non-default** resolved agent (default path `None`\u002F`claude-cli` → no probe, byte-identical to today). Classify by **membership** then `available` (never by exit code): **UNKNOWN** (`∉` set) → **hard-reject BEFORE any loop side-effect**, error lists the **sorted** valid ids, **NO proceed-anyway**; **UNAVAILABLE** (member, `available False`) → warn with `detail`, host's question mechanism offering **proceed-anyway OR choose-another** (re-presents the same `agents[]`), never silent; **AVAILABLE** → proceed, the validated id fills `{agent}`; **probe failure** (non-zero exit \u002F unparseable \u002F missing or empty `agents[]` \u002F row lacking `id`) → surface it, offer **choose-another OR abort**, **never launch the non-default agent unvalidated** and never silently fall back to the default.\n- **(d-model) Claude-only model-alias guard.** Runs **only** when the resolved agent is **non-default** (not the default \u002F `claude-cli` path). Read the backlog.json (Step 1e path); collect items whose `model` is a **Claude-specific alias** (tier `opus`\u002F`sonnet`\u002F`haiku` or a `claude-*` id). **If none, skip silently.** Otherwise warn before launch via host's question mechanism (NOT prose): `item.model` outranks `--agent`, so the alias is forwarded verbatim to `{agent}`, which will likely reject it (e.g. codex 400 *\"The 'sonnet' model is not supported…\"*) — every spawn exits 1 and rauf circuit-breaks (*\"3 consecutive infra failures — halting\"*) with no hint of the cause. Offer: **(1) Strip `model` for this run (recommended)** — rewrite backlog.json removing the `model` key from each affected item (persistent edit; re-run forge-4-backlog to restore), then proceed; **(2) Proceed as-is** — only safe if `{agent}` understands the pinned ids. forge touches only `model`, never `provider`. Full rationale: `references\u002Fagent-selection.md`.\n- **(e) Optional-flags line.** Augment the confirmation block's closing flags\u002Fprecedence pointer to list `--agent \u003Cid>` first plus the agent precedence pointer (`item.provider > --agent > project defaultAgent > runner default`) alongside the model precedence; the full catalog is `## Optional flags catalog (Step 2d, rauf)` in `references\u002Fagent-selection.md`.\n- **(f) Resolved-agent line.** Add to the confirmation block: `Agent: {resolved.agent or claude-cli} (source: {sourceLabel})` — `sourceLabel`: `RUN` → `\"per-run selection\"`, `PROJECT` → `\"project default (loopRunner.defaultAgent)\"`, `DEFAULT` → `\"runner default — claude-cli\"`.\n\n## Step 3: Execute the Loop\n\n### 3a. Update Pipeline State\n\nBefore launching, record the pre-launch marker by running `state-enter` — one atomic write that sets `stages.forge-5-loop.status` to `in-progress`, `stages.forge-5-loop.startedAt` to the current ISO timestamp, `currentStage` to `forge-5-loop`, and refreshes `updatedAt`. Add `--epic \"{epic}\"` when this feature is an epic member — required, per the Pipeline State Protocol in `references\u002Fshared-conventions.md`:\n\n```bash\nR=\"$(bash -c '[ -z \"${FEATURE_FORGE_ROOT:-}\" ] || [ -x \"$FEATURE_FORGE_ROOT\u002Fscripts\u002Fforge-root.sh\" ] || { echo \"feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts\u002Fforge-root.sh\" >&2; exit 2; }; for d in \"${FEATURE_FORGE_ROOT:-}\" \"${CLAUDE_PLUGIN_ROOT:-}\" \"$HOME\"\u002F.claude\u002Fskills\u002Ffeature-forge \"$HOME\"\u002F.claude\u002Fplugins\u002Fcache\u002F*\u002Ffeature-forge\u002F* \"$HOME\"\u002F.claude\u002Fplugins\u002F*\u002Ffeature-forge \"$HOME\"\u002F.agents\u002Fskills\u002Ffeature-forge .\u002F.agents\u002Fskills\u002Ffeature-forge; do [ -x \"$d\u002Fscripts\u002Fforge-root.sh\" ] && exec \"$d\u002Fscripts\u002Fforge-root.sh\"; done')\"\n[ -n \"$R\" ] || { echo \"feature-forge: cannot locate plugin root\" >&2; exit 1; }\npython3 \"$R\u002Fscripts\u002Fforge-session.py\" state-enter --feature \"{feature}\" --stage forge-5-loop --specs-dir \"{specsDir}\"\n```\n\nThen commit this state write before launching (mandatory — the runner refuses a dirty tree, and this marker is itself a change) via the shared-conventions **Git Commit Protocol** (epic members: stage `{specsDir}\u002F{epic}\u002F`): `{commitPrefix}({feature}): forge-5-loop in-progress`, regardless of `gitCommitAfterStage`. Unrelated leftover changes still trip the refusal; surface it, never auto-pass `--force`.\n\n### 3b. Launch Background Process\n\nLaunch the loop so it survives session end and **never blocks this session** — never run the run command in the foreground. Use the launch for this host in **Launch detail (Step 3b)** of `references\u002Frunner-contract.md`: the exact command, the `mkdir -p` state-dir and root→`IS_SANDBOX` guards, and why the runner's own `{stateDir}\u002Fevents.ndjson` is never redirected into.\n\n### 3c. Inform User\n\nFollow the **Inform-user output template (Step 3c)** section of `references\u002Frunner-contract.md` — it carries this step's instruction, the always-shown **verification-coverage** scan of the backlog's active items (contextualizing a benign runner warning like rauf's \"No verification commands detected\"), and the verbatim \"Loop started…\" template.\n\n### 3d. Supervise the run, and react to events\n\nSupervise the run exactly as **Supervise the run (Step 3d)** in `references\u002Frunner-contract.md` says for this host — coverage-complete, so every terminal and exception state reaches you (silence is not success) — and react per **React to events as they land (Step 3e)**: report each completed item's one-line card, surface exceptions now. Decide from the status JSON command, never from an event line alone.\n\n### 3f. Reach completion\n\nStep 4 is reached when the run has ended; Step 3d of `references\u002Frunner-contract.md` names this host's terminal signal. Never end your turn while the loop runs unless your host wakes you when it ends.\n\n## Step 4: Check Results\n\nWhen the run has ended (Step 3f):\n\n### 4a. Get Final Backlog State\n\nRun the **status-json command** (`loopRunner.statusJsonCommand`) and read\n`backlogSummary` for the authoritative counts — it separates the three non-done\noutcomes: genuine `blocked`, `needsHuman`, and runner-`deferred` (\"false blocks\").\nFall back to the **list command** (`loopRunner.listCommand`) if `statusJsonCommand`\nis not configured. Also read the optional `loopState`, `reviewPending`, `lock` fields (absent on older runners = unset); **Runner terminal states** in `references\u002Fresult-reporting.md` maps them. **`reviewPending: true` is never complete, whatever the counts** — offer the resume per **Pending review** in `references\u002Frunner-contract.md` before 4b. If the run used a review flag (e.g. rauf's `--review`), also read any `review_completed` event (event stream, or `{loopRunner.stateDir}\u002Fevents.ndjson`) for its `itemsCreated`\u002F`summary` to surface in 4b — see `references\u002Fresult-reporting.md`.\n\n### 4b. Report Results\n\nPresent a summary to the user. Pick **every** branch that applies (a run can be both\nblocked and needs-human) and render its report. The five verbatim result-report output templates — **all-done**, **needs-human**, **blocked**, **deferred**, and **pending** (with a conditional cause) — are in `references\u002Fresult-reporting.md`, together with the Step 7 `LoopOutcome` ladder these same counts feed. The reports are descriptive only: they carry no next command, and the run does not end here. If the authoritative counts cannot be obtained at all (4a failed or its output does not parse), follow **Operational failure before the counts are known** in that same file: surface the failure and its recovery, and close nothing — no outcome, no stage exit, no terminal block.\n\n### 4c. Post-Run Recovery Pass (unconditional)\n\nRun the **Post-Run Recovery Procedure** (`references\u002Frecovery-procedure.md`) now — on **every** run close, before Step 5 writes state, so the tree it inspects is exactly what the run left. The live `needs_human` handler (3d) is **not** the entry condition: a run that emitted no event still enters here, so blocked-only runs reach the unblock. With nothing to decide, its step 1 skips to the §4 tree reconciliation — silent on a clean tree — which also reconciles work a run stranded uncommitted with no signal (1g is only the next-launch backstop). Its step-7 gate feeds Step 7's `resolved` rung; the stage still closes exactly once, in Step 7.\n\n## Step 5: Update Pipeline State\n\nRecord completion by running `state-complete` (below). Evaluate \"all backlog items are `done`\" yourself and pass the result as `--status`: `complete` only when Step 7's ladder selects `complete` (every item `done`, `total > 0`, no pending review, a clean runner finish per `references\u002Fresult-reporting.md`), else `in-progress`. The verb records `completedAt`, the version, `basedOnVersions` and `artifacts`, and refreshes `updatedAt`. Add `--epic \"{epic}\"` when this feature is an epic member — required, per the Pipeline State Protocol.\n\n```bash\nR=\"$(bash -c '[ -z \"${FEATURE_FORGE_ROOT:-}\" ] || [ -x \"$FEATURE_FORGE_ROOT\u002Fscripts\u002Fforge-root.sh\" ] || { echo \"feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts\u002Fforge-root.sh\" >&2; exit 2; }; for d in \"${FEATURE_FORGE_ROOT:-}\" \"${CLAUDE_PLUGIN_ROOT:-}\" \"$HOME\"\u002F.claude\u002Fskills\u002Ffeature-forge \"$HOME\"\u002F.claude\u002Fplugins\u002Fcache\u002F*\u002Ffeature-forge\u002F* \"$HOME\"\u002F.claude\u002Fplugins\u002F*\u002Ffeature-forge \"$HOME\"\u002F.agents\u002Fskills\u002Ffeature-forge .\u002F.agents\u002Fskills\u002Ffeature-forge; do [ -x \"$d\u002Fscripts\u002Fforge-root.sh\" ] && exec \"$d\u002Fscripts\u002Fforge-root.sh\"; done')\"\n[ -n \"$R\" ] || { echo \"feature-forge: cannot locate plugin root\" >&2; exit 1; }\npython3 \"$R\u002Fscripts\u002Fforge-session.py\" state-complete --feature \"{feature}\" --stage forge-5-loop --version {n} --status \"\u003Ccomplete|in-progress>\" --based-on \"forge-4-backlog=\u003Ccurrent version from pipeline state>\" --artifact \"{backlogDir}\u002F{loopRunner.stateDir}\u002Fstate.json\" --specs-dir \"{specsDir}\"\n```\n\n**No git commit is needed** — the loop runner commits implementation code atomically per completed item during the run. (Step 6's commit, epic members only, is of pipeline state \u002F manifest — a distinct artifact.)\n\n## Step 5b: Offer Impl-Verify (standalone path)\n\n**Gate:** run only if (a) the feature's `.pipeline-state.json` has **no** `epic` key **and** (b) Step 5 set `stages.forge-5-loop.status` to `complete`. Otherwise **skip** straight to Step 7 — a non-complete run has nothing to verify yet, and epic members get the equivalent offer in Step 6.1 (do **not** prompt twice). This standalone counterpart to Step 6.1 nudges verification interactively. Use host's question mechanism (NOT inline prose) to offer: *\"{feature}'s loop is complete. Recommended: run `forge-verify {feature} impl` to audit the implementation before generating docs. Run it now, or skip to forge-6-docs?\"* On **run**, invoke `feature-forge:forge-verify {feature} impl` with the literal `owner: nested` token in the dispatching prompt — this dispatch happens inside the loop stage, so **you** remain the sole terminal owner and the branch skill returns its structured result and prints no terminal block of its own (see \"Branch ownership\" and \"Caller-side resumption\" in `references\u002Fstage-exit-protocol.md`; a delegate-and-resume site — on return, control resumes here). A verifier return without its report structure is a dropped digest, not a result (issue #183) — apply \"Truncated Verifier Returns\" in forge-verify's `findings-template.md` reference (resume or re-dispatch) before recording anything. On **skip**, persist the skip through `state-verify` using the fence below (mirrors `forge-4-backlog`'s skip handling) — the forge-6-docs backstop re-surfaces the skip. Either way, do **not** name a next command here: Step 7 routes, and it routes differently depending on what this step recorded.\n\n**The skip is written by `state-verify`, never by hand — and never over a resolved entry** (`passed`\u002F`findings-applied`: the verb refuses that demotion, #203 — skip the fence and continue). Add `--epic \"{epic}\"` when this feature is an epic member — required, per the Pipeline State Protocol in `references\u002Fshared-conventions.md`. On exit 2, surface the plain `Error:` line verbatim and stop: the skip is not persisted, so Step 7 would route on state that is not on disk.\n\n```bash\nR=\"$(bash -c '[ -z \"${FEATURE_FORGE_ROOT:-}\" ] || [ -x \"$FEATURE_FORGE_ROOT\u002Fscripts\u002Fforge-root.sh\" ] || { echo \"feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts\u002Fforge-root.sh\" >&2; exit 2; }; for d in \"${FEATURE_FORGE_ROOT:-}\" \"${CLAUDE_PLUGIN_ROOT:-}\" \"$HOME\"\u002F.claude\u002Fskills\u002Ffeature-forge \"$HOME\"\u002F.claude\u002Fplugins\u002Fcache\u002F*\u002Ffeature-forge\u002F* \"$HOME\"\u002F.claude\u002Fplugins\u002F*\u002Ffeature-forge \"$HOME\"\u002F.agents\u002Fskills\u002Ffeature-forge .\u002F.agents\u002Fskills\u002Ffeature-forge; do [ -x \"$d\u002Fscripts\u002Fforge-root.sh\" ] && exec \"$d\u002Fscripts\u002Fforge-root.sh\"; done')\"\n[ -n \"$R\" ] || { echo \"feature-forge: cannot locate plugin root\" >&2; exit 1; }\npython3 \"$R\u002Fscripts\u002Fforge-session.py\" state-verify --feature \"{feature}\" --stage forge-5-loop --status skipped --specs-dir \"{specsDir}\"\n```\n\n## Step 6: Epic Handoff\n\n**Gate:** only run this step if (a) the resolved feature's `.pipeline-state.json` has an `epic` key **and** (b) Step 5 set `stages.forge-5-loop.status` to `complete` (all backlog items done). If either is false, **skip** straight to Step 7 — standalone completed features are handled by Step 5b, and a non-complete run has no handoff to make (REQ-COMPAT-01).\n\n1. **Offer impl-verify first (recommended, skippable).** Per the completion rule (`00-core-definitions.md §7`), a feature whose `forge-verify-impl.status == findings-reported` does **not** unblock dependents. Use host's question mechanism (NOT inline prose) to offer: *\"{feature}'s loop is done. Recommended: run `forge-verify {feature} impl` before unblocking dependents. Run it now, or skip and continue the handoff?\"* On **run**, dispatch exactly as Step 5b does — the same literal `owner: nested` token in the dispatching prompt (you remain the sole terminal owner), the same truncated-return guard before recording anything, and the same declared resume (control returns here; the handoff continues at 2). On **skip**, persist the skip through `state-verify --status skipped` using Step 5b's fence (add `--epic \"{epic}\"` — required for members) so the Step 7 exit reads a recorded decision instead of re-asking the question the user just answered; completion is then judged on the §7 rule with impl-verify explicitly skipped.\n2. **Recompute and announce.** Run `render-status \"{epic}\" --specs-dir \"{specsDir}\" --json`. Announce the feature's completion and the epic rollup (e.g. \"2\u002F4 features complete\") — derived live from disk, never re-computed in prose.\n3. **Announce what is actionable — do not route.** Read `render-status`'s `actionable` set (every dependency now complete, not itself complete) and say plainly which members can start now, or which are still blocked and on which dependencies. This is context for the user, not a handoff: the Step 7 exit consumes the same live payload and fences the one authoritative next command itself, so do **not** present a next-feature picker, offer to author a member's PRD, or repeat a member's `nextCommand` here. Two competing actions is exactly the ambiguity the scripted exit removes.\n4. **Commit (REQ-OBS-01).** When `gitCommitAfterStage` is true, commit the Step 5 completion write (and any manifest `updatedAt` bump) via the shared-conventions **Git Commit Protocol**, staging the epic subtree so the member state change commits atomically: `git add {specsDir}\u002F{epic}\u002F` then `{commitPrefix}({feature}): complete loop`. If `gitCommitAfterStage` is false, skip the commit. Then fall through to Step 7 — the epic handoff closes there, once, like every other path.\n\n## Step 7: Close the Stage\n\nEvery loop run ends here, and ends here **exactly once** — standalone or epic member, complete or not.\n\nFirst select the single `LoopOutcome` with the ladder in `references\u002Fresult-reporting.md` (`resolved` → unfinished-runner `partial` → `needs-human` → `blocked` → `deferred` → `partial` → `complete`, first match wins, plus any `--cause` it names), reading it from Step 4a's authoritative counts and never from the runner's process exit code. If those counts were never obtained, follow that file's operational-failure rule instead: report the failure and its recovery and run no exit at all.\n\n**Close this stage with the Scripted Stage Exit** (contract: `references\u002Fstage-exit-protocol.md`; do not improvise a \"Next steps\" list). Run:\n\n```bash\nR=\"$(bash -c '[ -z \"${FEATURE_FORGE_ROOT:-}\" ] || [ -x \"$FEATURE_FORGE_ROOT\u002Fscripts\u002Fforge-root.sh\" ] || { echo \"feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts\u002Fforge-root.sh\" >&2; exit 2; }; for d in \"${FEATURE_FORGE_ROOT:-}\" \"${CLAUDE_PLUGIN_ROOT:-}\" \"$HOME\"\u002F.claude\u002Fskills\u002Ffeature-forge \"$HOME\"\u002F.claude\u002Fplugins\u002Fcache\u002F*\u002Ffeature-forge\u002F* \"$HOME\"\u002F.claude\u002Fplugins\u002F*\u002Ffeature-forge \"$HOME\"\u002F.agents\u002Fskills\u002Ffeature-forge .\u002F.agents\u002Fskills\u002Ffeature-forge; do [ -x \"$d\u002Fscripts\u002Fforge-root.sh\" ] && exec \"$d\u002Fscripts\u002Fforge-root.sh\"; done')\"\n[ -n \"$R\" ] || { echo \"feature-forge: cannot locate plugin root\" >&2; exit 1; }\npython3 \"$R\u002Fscripts\u002Fforge-session.py\" stage-exit --feature \"{feature}\" --stage forge-5-loop --outcome \"{LoopOutcome}\" --specs-dir \"{specsDir}\" --host generic --verify-capability \"{verify-capability}\"\n```\n\nObey the DIRECTIVES it prints, in the consumption order this protocol fixes: surface `invalidAutoVerifyKeys` and every `warnings` entry first; `runInStageVerify: true` → run the in-stage clean-room verify chain now (honoring `autoFixEligible`, and asking through the Standard Verify Gate first when you may not dispatch unsolicited); `verifyGate: \"standard\"` → present the Standard Verify Gate; `verifyGate: \"manual-print\"` → print the `verifyCommand` for the user and do **not** dispatch inline. Then, and only when `terminalOwnedBy` is `\"self\"`, **print the NEXT-STEPS block verbatim as your absolute last output — nothing after its sentinel line.** A `terminalOwnedBy: \"outer\"` payload carries `nextSteps: null`: return your structured result to the caller and print no terminal block at all.\n\nAdd `--epic \"{epic}\"` when this feature is an epic member — required, per the Pipeline State Protocol in `references\u002Fshared-conventions.md`. Determine `{verify-capability}` per the **Host and capability determination** section of `references\u002Fstage-exit-protocol.md`: `interactive` needs both a question mechanism and *permission* to dispatch the clean-room `forge-verifier`, and a session that merely needs consent first is still `interactive`. The script owns the routing for every outcome — the loop resume, the navigator recovery, the docs handoff, and the epic's live next member — so append nothing to its block: no retry line, no rollup restated, no \"continue to docs\". A non-`complete` outcome deliberately fences no downstream work, and re-adding one here would claim readiness the backlog does not support.\n\n## Gotchas\n\n- **Plugin-root discovery (1b-epic helper) covers installed paths, not workspace-dev checkouts.** The `forge-root.sh` search probes the locations of an **installed** plugin only, so a feature-forge **source checkout** (e.g. `~\u002Fworkspace\u002Ffeature-forge`) exits \"cannot locate plugin root\" unless `FEATURE_FORGE_ROOT` points at it (#323). Expected in a dev environment; run the epic-manifest script from the checkout directly (`python3 \u003Ccheckout>\u002Fscripts\u002Fepic-manifest.py …`).\n- `{backlogDir}` is a **directory path**, not a file path. Pass `specs\u002Fauth`, not `specs\u002Fauth\u002Fbacklog.json`.\n- rauf resolves `RAUF.md` with fallback (`{backlogDir}\u002F.rauf\u002FRAUF.md` first, then the project's `.rauf\u002FRAUF.md`). State files (state.json, {loopRunner.logFile}, etc.) land at `{backlogDir}\u002F{loopRunner.stateDir}\u002F`, isolated per backlog dir, so concurrent features don't collide.\n- If the session disconnects mid-loop, the runner process continues independently — check results later with the status \u002F list commands. A crashed run's stale lock (`PAUSED` + `lock.stale`) is cleared by rauf's `resume`, not `--force` (see `references\u002Fresult-reporting.md`).\n- Never run the run command in the foreground — it blocks for the whole run and hits the shell tool's timeout for any non-trivial backlog. \"Don't block the foreground\" is NOT \"stay silent\": supervise per 3d. A `needs_human`\u002F`blocked`\u002F`review` signal does **not** pause the loop — the runner sets the item aside and keeps going; surface it live but don't tell the user the loop is waiting.\n- The version gate (1c) uses the `--json` form on purpose; never parse `rauf version`'s human output.\n- **Implementation artifacts must not cite specs.** The loop should **read** specs and `backlog.json` freely — they are the source of truth, and the backlog rightly cites specs for provenance. But artifacts the loop **writes into the target repo** (source code, generated `SKILL.md`\u002Fagent files, configs, code comments) must be **self-contained**: no references to feature-forge spec files (no `See specs\u002F{feature}\u002FNN-*.md`, no \"source spec\" provenance notes) — specs are pre-implementation inputs that may be archived or deleted once the feature ships. This applies only to shipped implementation output, never to the backlog or spec documents, which keep citing specs.\n\n---\n\n## Host execution notes (Codex)\n\nThis skill was authored Claude-first; the body above refers to \"the host's question mechanism\", \"the host's subagent mechanism\", and \"the host's background-execution mechanism\". On Codex:\n\n- **User input:** Codex has no structured question tool. Which rung you are on is **not** observable from inside the session — a `codex exec` run looks exactly like an interactive one — so read it from the Interaction Capability Ladder's `interaction-mode` record instead of judging it. Interactive session — ask the question directly and wait for the reply; never assume an answer. Non-interactive — don't wait: take the Interaction Capability Ladder's declared conservative default, state it in your output, and use `no-default: abort — \u003Cquestion> requires a human answer` for an interview question with no sane default (`references\u002Fshared-conventions.md`).\n- **Subagents:** spawn a Codex subagent using the named custom agent under `.codex\u002Fagents\u002F\u003Cname>.toml`. Codex spawns a subagent only when explicitly asked; if the custom agent is unavailable, run that step inline yourself.\n- **Background \u002F monitoring (forge-5-loop):** Codex cannot wake you when a background process prints or exits, so **never end your turn while the loop runs**. Launch it detached and supervise it from inside the turn with the `rauf loop wait` loop — one bounded wait per shell call, print each card, decide from the status JSON — exactly as `references\u002Frunner-contract.md` (Steps 3b\u002F3d) says for this host. The optional rauf Stop hook (`rauf hook codex-stop`; wire it with `npx @garygentry\u002Ffeature-forge install -a codex --codex-stop-hook`) holds the session open if it tries to end its turn while the loop still runs. Other long-lived commands: run them in your shell session and report progress as it arrives.\n","# forge-5-loop — Autonomous Loop Executor\n\nThe loop spawns a fresh agent session per backlog item, implementing each task with full verification.\n\nThe loop **runner** is configured, not hardcoded. feature-forge talks to it through the `loopRunner` block in `forge.config.json`; rauf is the default and reference implementation (see `references\u002Fralph-loop-contract.md`). Every command below is rendered from `loopRunner` with token substitution — no hardcoded `rauf …` commands; even the human log filename is tokenized (`{loopRunner.logFile}`).\n\n## Resolve the loop runner\n\nResolve the effective `loopRunner` with the command below — it merges this project's `loopRunner` block over the schema defaults deterministically, so do not read the config schema for defaults. **If `forge.config.json` has no `loopRunner` block at all, state plainly: \"No loopRunner configured — defaulting to the rauf loop runner.\"** then proceed with the full default block, which is exactly what the call returns. If the call exits 2, surface the plain `Error:` line from stderr verbatim and fall back to the documented rauf defaults.\n\n```bash\nR=\"$(bash -c '[ -z \"${FEATURE_FORGE_ROOT:-}\" ] || [ -x \"$FEATURE_FORGE_ROOT\u002Fscripts\u002Fforge-root.sh\" ] || { echo \"feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts\u002Fforge-root.sh\" >&2; exit 2; }; for d in \"${FEATURE_FORGE_ROOT:-}\" \"${CLAUDE_PLUGIN_ROOT:-}\" \"$HOME\"\u002F.claude\u002Fskills\u002Ffeature-forge \"$HOME\"\u002F.claude\u002Fplugins\u002Fcache\u002F*\u002Ffeature-forge\u002F* \"$HOME\"\u002F.claude\u002Fplugins\u002F*\u002Ffeature-forge \"$HOME\"\u002F.agents\u002Fskills\u002Ffeature-forge .\u002F.agents\u002Fskills\u002Ffeature-forge; do [ -x \"$d\u002Fscripts\u002Fforge-root.sh\" ] && exec \"$d\u002Fscripts\u002Fforge-root.sh\"; done')\"\n[ -n \"$R\" ] || { echo \"feature-forge: cannot locate plugin root\" >&2; exit 1; }\npython3 \"$R\u002Fscripts\u002Fforge-session.py\" effective-config --config .\u002Fforge.config.json --json\n```\n\nToken substitution applies to every `*Command` string. Substitute:\n\n- `{bin}` → `loopRunner.bin` (default `rauf`)\n- `{backlogDir}` → the resolved backlog directory (Step 1d \u002F 2b), relative to project root\n- `{specsDir}` → `specsDir` from config\n- `{iterations}` → the computed iteration count (Step 2a)\n\nWhenever this skill says \"run the **run command**\" \u002F \"**status command**\" \u002F etc., it means the corresponding substituted `loopRunner.*Command`.\n\n**Turn structure reminder:** Text first, then host's question mechanism for all questions — never embed one in your text (it stalls). At rung 2\u002F3, see the Interaction Capability Ladder.\n\n## Step 1: Validate Prerequisites\n\nRead and follow `references\u002Fshared-conventions.md` for feature name validation, configuration reading, and force mode handling.\n\n### 1a. Pipeline State Check\n\n**Resolve the feature directory first.** Invoke the **Feature Directory Resolution** block in `references\u002Fshared-conventions.md` to turn the bare feature name into `{resolvedFeatureDir}` (exit 0 → stdout is the absolute dir; exit ≥ 1 → STOP and surface the finding verbatim). Read state from `{resolvedFeatureDir}\u002F` everywhere this skill previously wrote `{specsDir}\u002F{feature}\u002F` (the 1e backlog path and the Step 3a \u002F Step 5 state writes). Standalone features resolve to their flat path exactly as today.\n\nRead `{resolvedFeatureDir}\u002F.pipeline-state.json`. If not in force mode, `stages.forge-4-backlog` must be `complete`. If not, STOP and tell the user: \"Backlog hasn't been created yet. Run `forge-4-backlog {feature}` first.\"\n\nIf the state's `notes` is non-empty, surface it before proceeding and treat it as run input — often backlog-time constraints; it never overrides specs or config (raise any conflict).\n\n### 1b. Verification Check\n\nDerive whether the upstream backlog has been verified from the settled on-disk record, never by eyeballing conversational state. Run `verify-state --for-stage forge-4-backlog` — it reads the served stage's `forge-verify-backlog` entry and returns `{case, verified, stale, message, nextCommand}`. Add `--epic \"{epic}\"` when this feature is an epic member (nested layout). The full case enum and its rationale live in `references\u002Fverify-state.md`.\n\n```bash\nR=\"$(bash -c '[ -z \"${FEATURE_FORGE_ROOT:-}\" ] || [ -x \"$FEATURE_FORGE_ROOT\u002Fscripts\u002Fforge-root.sh\" ] || { echo \"feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts\u002Fforge-root.sh\" >&2; exit 2; }; for d in \"${FEATURE_FORGE_ROOT:-}\" \"${CLAUDE_PLUGIN_ROOT:-}\" \"$HOME\"\u002F.claude\u002Fskills\u002Ffeature-forge \"$HOME\"\u002F.claude\u002Fplugins\u002Fcache\u002F*\u002Ffeature-forge\u002F* \"$HOME\"\u002F.claude\u002Fplugins\u002F*\u002Ffeature-forge \"$HOME\"\u002F.agents\u002Fskills\u002Ffeature-forge .\u002F.agents\u002Fskills\u002Ffeature-forge; do [ -x \"$d\u002Fscripts\u002Fforge-root.sh\" ] && exec \"$d\u002Fscripts\u002Fforge-root.sh\"; done')\"\n[ -n \"$R\" ] || { echo \"feature-forge: cannot locate plugin root\" >&2; exit 1; }\npython3 \"$R\u002Fscripts\u002Fforge-session.py\" verify-state --feature \"{feature}\" --for-stage forge-4-backlog --specs-dir \"{specsDir}\" --json\n```\n\nIf `verified` is true, proceed with no prompt. Otherwise print the returned `message`, then use host's question mechanism to warn with the cost of skipping — the loop implements items autonomously and commits as it goes, so a bad item is far cheaper to catch now than after commits build on it — and offer **Verify first (recommended)** (run the returned `nextCommand`) · **Continue without verifying**. This is a pre-stage read of the upstream artifact, so the proceed-anyway path writes **nothing** — in particular a `stale` result (fixes applied, re-verify still owed) must not be demoted to `skipped`: `state-verify` refuses that write (#203) and the recorded status already says re-verification is outstanding.\n\n### 1b-epic. Epic Dependency Gate\n\nRead the resolved feature's `.pipeline-state.json`. **If it has no `epic` key, skip this sub-step entirely** (standalone feature — REQ-COMPAT-01; standalone runs are unchanged). Otherwise:\n\n1. Run `render-status \"{epic}\" --specs-dir \"{specsDir}\" --json` via the helper:\n\n   ```bash\nR=\"$(bash -c '[ -z \"${FEATURE_FORGE_ROOT:-}\" ] || [ -x \"$FEATURE_FORGE_ROOT\u002Fscripts\u002Fforge-root.sh\" ] || { echo \"feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts\u002Fforge-root.sh\" >&2; exit 2; }; for d in \"${FEATURE_FORGE_ROOT:-}\" \"${CLAUDE_PLUGIN_ROOT:-}\" \"$HOME\"\u002F.claude\u002Fskills\u002Ffeature-forge \"$HOME\"\u002F.claude\u002Fplugins\u002Fcache\u002F*\u002Ffeature-forge\u002F* \"$HOME\"\u002F.claude\u002Fplugins\u002F*\u002Ffeature-forge \"$HOME\"\u002F.agents\u002Fskills\u002Ffeature-forge .\u002F.agents\u002Fskills\u002Ffeature-forge; do [ -x \"$d\u002Fscripts\u002Fforge-root.sh\" ] && exec \"$d\u002Fscripts\u002Fforge-root.sh\"; done')\"\n[ -n \"$R\" ] || { echo \"feature-forge: cannot locate plugin root\" >&2; exit 1; }\npython3 \"$R\u002Fscripts\u002Fepic-manifest.py\" \\\n  render-status \"{epic}\" --specs-dir \"{specsDir}\" --json\n   ```\n\n2. Find this feature's entry; read its `unmetDeps` (the direct `dependsOn` not yet complete-for-orchestration per `00-core-definitions.md §7`).\n3. **If `unmetDeps` is empty**, proceed to 1c with no prompt.\n4. **If `unmetDeps` is non-empty**, use host's question mechanism (do NOT inline the question as prose) to warn that the feature depends on the unmet dependencies, which are not yet complete, and that running the loop now means implementing against contracts that may still change:\n\n   > \"{feature} depends on {unmetDeps joined}, which are not yet complete. Running the loop now means implementing against contracts that may still change. Proceed anyway, or stop and finish the dependencies first?\"\n\n   Require an **explicit \"Proceed anyway\"** choice to continue (REQ-ORCH-04). \"Stop\" aborts before any runner setup. `--force` (shared-conventions Force Mode) also bypasses this gate with the standard force warning.\n5. If `render-status` fails, **STOP** — do not silently run a loop whose dependency state is unverifiable (REQ-ROBUST-02). Surface per the exit-1\u002Fexit-2 split in the **Feature Directory Resolution** block of `references\u002Fshared-conventions.md` (exit 1 → parse `{findings[]}` from stdout; exit 2 → surface the plain `Error:` stderr line verbatim — no findings JSON to parse).\n\nThis gate runs **before** the runner version\u002Fsetup gates (1c\u002F1d) so a blocked feature stops early, before any runner side-effects.\n\n### 1c. Runner Version Gate\n\n### 1d. Runner Setup Check (precondition file)\n\nThese gate on the loop runner being installed, current, and wired **before** touching it — enforced by `doctor`'s `runner-*` checks, never ad-hoc parsing. Run:\n\n```bash\nR=\"$(bash -c '[ -z \"${FEATURE_FORGE_ROOT:-}\" ] || [ -x \"$FEATURE_FORGE_ROOT\u002Fscripts\u002Fforge-root.sh\" ] || { echo \"feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts\u002Fforge-root.sh\" >&2; exit 2; }; for d in \"${FEATURE_FORGE_ROOT:-}\" \"${CLAUDE_PLUGIN_ROOT:-}\" \"$HOME\"\u002F.claude\u002Fskills\u002Ffeature-forge \"$HOME\"\u002F.claude\u002Fplugins\u002Fcache\u002F*\u002Ffeature-forge\u002F* \"$HOME\"\u002F.claude\u002Fplugins\u002F*\u002Ffeature-forge \"$HOME\"\u002F.agents\u002Fskills\u002Ffeature-forge .\u002F.agents\u002Fskills\u002Ffeature-forge; do [ -x \"$d\u002Fscripts\u002Fforge-root.sh\" ] && exec \"$d\u002Fscripts\u002Fforge-root.sh\"; done')\"\n[ -n \"$R\" ] || { echo \"feature-forge: cannot locate plugin root\" >&2; exit 1; }\npython3 \"$R\u002Fscripts\u002Fforge-session.py\" doctor --json --specs-dir \"{specsDir}\" --check runner-binary --check runner-version --check runner-wired --check runner-legacy-layout\n```\n\nAll four `ok`\u002F`na` → proceed silently. Otherwise follow `references\u002Fpreflight-and-self-heal.md`: `runner-binary`\u002F`runner-version` not `ok` → **HARD GATE FAILURE**, STOP with the check's own `remedy.description` (never a hardcoded `installHint` — a customized `bin` gets its own config-fix remedy, G4). `runner-legacy-layout` warn → STOP: \"This project is still on the legacy **Ralph** layout. Run {`remedy.command`, e.g. `{bin} migrate .`} first, then re-run `forge-5-loop {feature}`.\" `runner-wired` warn → STOP with `loopRunner.setupHint`. A STOP lifts only once a permitted `local-write` remedy ran **and** the identical re-run shows `ok`; `forge-guide --doctor` walks it.\n\n> `installHint` points at the runner **CLI**; `setupHint` (1d) installs its per-project artifacts.\n\n### 1e. Backlog File Check\n\nResolve the backlog file path (matching forge-4-backlog's composition rule, item 015 \u002F §6.2):\n- If `backlogDir` is set in `forge.config.json`: use `{backlogDir}\u002F{feature}\u002Fbacklog.json` (the per-feature subpath, so each epic member's backlog stays independent — the `{feature}` segment prevents collisions across a multi-feature epic)\n- Otherwise: use `{resolvedFeatureDir}\u002Fbacklog.json`\n\nVerify the file exists on disk. If not, STOP and tell the user: \"No backlog.json found at {path}. Run `forge-4-backlog {feature}` to generate it.\"\n\n### 1f. Branch Pre-flight (if using git)\n\nThe runner commits each item onto the current branch. Skip if not a git repo or `branchPerFeature` is false. Otherwise run the **Branch Reconciliation** block in `references\u002Fshared-conventions.md` (it runs `reconcile-branch` and, on `warn-drift` — you are on the default branch — strongly recommends creating `{branchPrefix}{feature}` via host's question mechanism before the loop commits; on `adopt-current` it updates the recorded branch to the current one, never pushing you back to a stale\u002Fimposed branch). Never hard-stop.\n\n### 1g. Stranded-Work Pre-flight (if using git)\n\nRun `git status --porcelain`. If it reports changes **and** `{backlogDir}\u002F{loopRunner.stateDir}\u002Fstate.json` exists from a previous run, **STOP**: name that run (its `startedAt`, `currentItem`, and `blockedItems` from `state.json`) and point the user at the **Post-Run Tree Reconciliation** section of `references\u002Frecovery-procedure.md` to commit \u002F stash \u002F discard the stranded work before relaunch — never auto-pass `--force`. If the tree is dirty with **no** prior-run `state.json`, keep today's behavior (surface it; let the user commit\u002Fstash or pass `--force`). A clean tree is silent.\n\n## Step 2: Construct the Loop Command\n\n### 2a. Analyze Backlog\n\nRun the **list command** (`loopRunner.listCommand`, default `rauf backlog list . --backlog {backlogDir} --json`) and count items by status: `pending`, `in_progress`, `done`, `blocked`. Pipe that same list-command JSON into `backlog-topology --items-stdin --json` (a `forge-session.py` verb — invoke it via Step 3a's `$R` fence) and read `maxChainDepth` to report alongside the iteration count — advisory only: no prompt, no operator decision.\n\nCalculate the iteration count: `ceil((pending + in_progress) * loopIterationMultiplier)` where `loopIterationMultiplier` comes from `forge.config.json` (default: 1.5, headroom for retries).\n\nThen, **whatever the counts**, run the **status-json command**: `reviewPending: true` (optional field) means a prior review pass failed or was interrupted — follow **Pending review** in `references\u002Frunner-contract.md` before any fresh run (which would drop it). Otherwise, with no pending or in_progress items: a reported `loopState` that is not a clean finish → follow **Unfinished runner** in that file; else STOP and tell the user: \"All backlog items are already done or blocked. Nothing to run.\"\n\nIf there are `blocked` items, note them — the user may want `--retry-blocked`.\n\n### 2b. Resolve Backlog Directory\n\n`{backlogDir}` is a **directory path** (not a file path), relative to the project root.\n\n- If `backlogDir` is set in config: use the per-feature subpath `{backlogDir}\u002F{feature}` (matching the 1e composition rule and forge-4-backlog §6.2).\n- Otherwise: use `{resolvedFeatureDir}` (the directory containing `backlog.json`).\n\n### 2c. Build Command\n\nRender the **run command** (`loopRunner.runCommand`) with token substitution, e.g. the rauf default becomes:\n\n```\nrauf loop run . --backlog specs\u002Fauth --iterations 15\n```\n\n### 2d. Confirm with User\n\nUse host's question mechanism to present the rendered run command and options. The following block is the content for host's question mechanism — do NOT output it as text:\n\n```\nReady to run the loop for {feature}:\n\n  {rendered runCommand}   # + \" --review\" when the recommended Run-mode option (below) is picked\n\nBacklog summary:\n  - Pending: {pending}\n  - In progress: {in_progress}\n  - Done: {done}\n  - Blocked: {blocked}\n  - Iterations: {iterationCount} ({activeItems} items x {loopIterationMultiplier} multiplier)\n  - Max chain depth: {maxChainDepth} — depth bounds achievable progress regardless of iteration budget\n\nFor the model-selection precedence (item.model > --model\u002Foptions > project default >\nprovider default), read references\u002Frunner-contract.md.\n```\n\n**Run mode and full loop-runner contract:** follow `## Run mode (Step 2d, rauf)` and the remaining sections in `references\u002Frunner-contract.md` verbatim; `loopRunner.reviewMode` (`\"always\"`\u002F`\"never\"`) suppresses the Run-mode question — semantics live there.\n\n#### Agent selection (gated on `loopRunner.agentArgument`)\n\n**Capability gate.** Everything below applies **only when** the effective `loopRunner.agentArgument` is present and non-empty. **When it is absent or empty, Step 2d is exactly the confirmation above — no probe, no agent question, no availability listing, no `Agent:` line — byte-identical to today** (REQ-PLUG-02, REQ-COMPAT-01). The full algorithm, precedence, and verbatim message shapes are in `## Agent selection` of `references\u002Fagent-selection.md`; read it. When the gate is on, augment Step 2d in order:\n\n- **(a) Probe once.** Before confirming, run `loopRunner.agentsProbeCommand` (default `{bin} agents --json`) **exactly once** (no retries, no second probe); it exits 0 with `{ agents: [...] }`. Parse `agents[]`; build the advertised set `{ row.id }` — this one parsed array drives (b)–(d).\n- **(b) Agent question.** Add an **\"agent\"** question to the same host's question mechanism surface: **one option per advertised row** labelled `\"{displayName} ({id}) — available\u002Fnot found\"`, **plus an explicit `\"default (claude-cli)\"` choice mapping to `run_selection = None`**. Resolve the pick (run > project, empty\u002Fwhitespace unset, an explicit runner-default pick collapses to the default path) into `{resolved.agent, resolved.source}`. Precedence: `item.provider > --agent > project defaultAgent > runner default` (forge never reads a backlog item's provider). Under `loopRunner.agentMode: \"auto\"`, skip this question (`run_selection = None`); (a)\u002F(c)\u002F(d)\u002F(d-model) still run — see `references\u002Fagent-selection.md`.\n- **(c) Availability listing.** From the **same** parsed `agents[]` (no second probe), list `id` \u002F `displayName` \u002F available (`yes`\u002F`no`, `detail` on unavailable rows).\n- **(d) Verdict** — only for a **non-default** resolved agent (default path `None`\u002F`claude-cli` → no probe, byte-identical to today). Classify by **membership** then `available` (never by exit code): **UNKNOWN** (`∉` set) → **hard-reject BEFORE any loop side-effect**, error lists the **sorted** valid ids, **NO proceed-anyway**; **UNAVAILABLE** (member, `available False`) → warn with `detail`, host's question mechanism offering **proceed-anyway OR choose-another** (re-presents the same `agents[]`), never silent; **AVAILABLE** → proceed, the validated id fills `{agent}`; **probe failure** (non-zero exit \u002F unparseable \u002F missing or empty `agents[]` \u002F row lacking `id`) → surface it, offer **choose-another OR abort**, **never launch the non-default agent unvalidated** and never silently fall back to the default.\n- **(d-model) Claude-only model-alias guard.** Runs **only** when the resolved agent is **non-default** (not the default \u002F `claude-cli` path). Read the backlog.json (Step 1e path); collect items whose `model` is a **Claude-specific alias** (tier `opus`\u002F`sonnet`\u002F`haiku` or a `claude-*` id). **If none, skip silently.** Otherwise warn before launch via host's question mechanism (NOT prose): `item.model` outranks `--agent`, so the alias is forwarded verbatim to `{agent}`, which will likely reject it (e.g. codex 400 *\"The 'sonnet' model is not supported…\"*) — every spawn exits 1 and rauf circuit-breaks (*\"3 consecutive infra failures — halting\"*) with no hint of the cause. Offer: **(1) Strip `model` for this run (recommended)** — rewrite backlog.json removing the `model` key from each affected item (persistent edit; re-run forge-4-backlog to restore), then proceed; **(2) Proceed as-is** — only safe if `{agent}` understands the pinned ids. forge touches only `model`, never `provider`. Full rationale: `references\u002Fagent-selection.md`.\n- **(e) Optional-flags line.** Augment the confirmation block's closing flags\u002Fprecedence pointer to list `--agent \u003Cid>` first plus the agent precedence pointer (`item.provider > --agent > project defaultAgent > runner default`) alongside the model precedence; the full catalog is `## Optional flags catalog (Step 2d, rauf)` in `references\u002Fagent-selection.md`.\n- **(f) Resolved-agent line.** Add to the confirmation block: `Agent: {resolved.agent or claude-cli} (source: {sourceLabel})` — `sourceLabel`: `RUN` → `\"per-run selection\"`, `PROJECT` → `\"project default (loopRunner.defaultAgent)\"`, `DEFAULT` → `\"runner default — claude-cli\"`.\n\n## Step 3: Execute the Loop\n\n### 3a. Update Pipeline State\n\nBefore launching, record the pre-launch marker by running `state-enter` — one atomic write that sets `stages.forge-5-loop.status` to `in-progress`, `stages.forge-5-loop.startedAt` to the current ISO timestamp, `currentStage` to `forge-5-loop`, and refreshes `updatedAt`. Add `--epic \"{epic}\"` when this feature is an epic member — required, per the Pipeline State Protocol in `references\u002Fshared-conventions.md`:\n\n```bash\nR=\"$(bash -c '[ -z \"${FEATURE_FORGE_ROOT:-}\" ] || [ -x \"$FEATURE_FORGE_ROOT\u002Fscripts\u002Fforge-root.sh\" ] || { echo \"feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts\u002Fforge-root.sh\" >&2; exit 2; }; for d in \"${FEATURE_FORGE_ROOT:-}\" \"${CLAUDE_PLUGIN_ROOT:-}\" \"$HOME\"\u002F.claude\u002Fskills\u002Ffeature-forge \"$HOME\"\u002F.claude\u002Fplugins\u002Fcache\u002F*\u002Ffeature-forge\u002F* \"$HOME\"\u002F.claude\u002Fplugins\u002F*\u002Ffeature-forge \"$HOME\"\u002F.agents\u002Fskills\u002Ffeature-forge .\u002F.agents\u002Fskills\u002Ffeature-forge; do [ -x \"$d\u002Fscripts\u002Fforge-root.sh\" ] && exec \"$d\u002Fscripts\u002Fforge-root.sh\"; done')\"\n[ -n \"$R\" ] || { echo \"feature-forge: cannot locate plugin root\" >&2; exit 1; }\npython3 \"$R\u002Fscripts\u002Fforge-session.py\" state-enter --feature \"{feature}\" --stage forge-5-loop --specs-dir \"{specsDir}\"\n```\n\nThen commit this state write before launching (mandatory — the runner refuses a dirty tree, and this marker is itself a change) via the shared-conventions **Git Commit Protocol** (epic members: stage `{specsDir}\u002F{epic}\u002F`): `{commitPrefix}({feature}): forge-5-loop in-progress`, regardless of `gitCommitAfterStage`. Unrelated leftover changes still trip the refusal; surface it, never auto-pass `--force`.\n\n### 3b. Launch Background Process\n\nLaunch the loop so it survives session end and **never blocks this session** — never run the run command in the foreground. Use the launch for this host in **Launch detail (Step 3b)** of `references\u002Frunner-contract.md`: the exact command, the `mkdir -p` state-dir and root→`IS_SANDBOX` guards, and why the runner's own `{stateDir}\u002Fevents.ndjson` is never redirected into.\n\n### 3c. Inform User\n\nFollow the **Inform-user output template (Step 3c)** section of `references\u002Frunner-contract.md` — it carries this step's instruction, the always-shown **verification-coverage** scan of the backlog's active items (contextualizing a benign runner warning like rauf's \"No verification commands detected\"), and the verbatim \"Loop started…\" template.\n\n### 3d. Supervise the run, and react to events\n\nSupervise the run exactly as **Supervise the run (Step 3d)** in `references\u002Frunner-contract.md` says for this host — coverage-complete, so every terminal and exception state reaches you (silence is not success) — and react per **React to events as they land (Step 3e)**: report each completed item's one-line card, surface exceptions now. Decide from the status JSON command, never from an event line alone.\n\n### 3f. Reach completion\n\nStep 4 is reached when the run has ended; Step 3d of `references\u002Frunner-contract.md` names this host's terminal signal. Never end your turn while the loop runs unless your host wakes you when it ends.\n\n## Step 4: Check Results\n\nWhen the run has ended (Step 3f):\n\n### 4a. Get Final Backlog State\n\nRun the **status-json command** (`loopRunner.statusJsonCommand`) and read\n`backlogSummary` for the authoritative counts — it separates the three non-done\noutcomes: genuine `blocked`, `needsHuman`, and runner-`deferred` (\"false blocks\").\nFall back to the **list command** (`loopRunner.listCommand`) if `statusJsonCommand`\nis not configured. Also read the optional `loopState`, `reviewPending`, `lock` fields (absent on older runners = unset); **Runner terminal states** in `references\u002Fresult-reporting.md` maps them. **`reviewPending: true` is never complete, whatever the counts** — offer the resume per **Pending review** in `references\u002Frunner-contract.md` before 4b. If the run used a review flag (e.g. rauf's `--review`), also read any `review_completed` event (event stream, or `{loopRunner.stateDir}\u002Fevents.ndjson`) for its `itemsCreated`\u002F`summary` to surface in 4b — see `references\u002Fresult-reporting.md`.\n\n### 4b. Report Results\n\nPresent a summary to the user. Pick **every** branch that applies (a run can be both\nblocked and needs-human) and render its report. The five verbatim result-report output templates — **all-done**, **needs-human**, **blocked**, **deferred**, and **pending** (with a conditional cause) — are in `references\u002Fresult-reporting.md`, together with the Step 7 `LoopOutcome` ladder these same counts feed. The reports are descriptive only: they carry no next command, and the run does not end here. If the authoritative counts cannot be obtained at all (4a failed or its output does not parse), follow **Operational failure before the counts are known** in that same file: surface the failure and its recovery, and close nothing — no outcome, no stage exit, no terminal block.\n\n### 4c. Post-Run Recovery Pass (unconditional)\n\nRun the **Post-Run Recovery Procedure** (`references\u002Frecovery-procedure.md`) now — on **every** run close, before Step 5 writes state, so the tree it inspects is exactly what the run left. The live `needs_human` handler (3d) is **not** the entry condition: a run that emitted no event still enters here, so blocked-only runs reach the unblock. With nothing to decide, its step 1 skips to the §4 tree reconciliation — silent on a clean tree — which also reconciles work a run stranded uncommitted with no signal (1g is only the next-launch backstop). Its step-7 gate feeds Step 7's `resolved` rung; the stage still closes exactly once, in Step 7.\n\n## Step 5: Update Pipeline State\n\nRecord completion by running `state-complete` (below). Evaluate \"all backlog items are `done`\" yourself and pass the result as `--status`: `complete` only when Step 7's ladder selects `complete` (every item `done`, `total > 0`, no pending review, a clean runner finish per `references\u002Fresult-reporting.md`), else `in-progress`. The verb records `completedAt`, the version, `basedOnVersions` and `artifacts`, and refreshes `updatedAt`. Add `--epic \"{epic}\"` when this feature is an epic member — required, per the Pipeline State Protocol.\n\n```bash\nR=\"$(bash -c '[ -z \"${FEATURE_FORGE_ROOT:-}\" ] || [ -x \"$FEATURE_FORGE_ROOT\u002Fscripts\u002Fforge-root.sh\" ] || { echo \"feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts\u002Fforge-root.sh\" >&2; exit 2; }; for d in \"${FEATURE_FORGE_ROOT:-}\" \"${CLAUDE_PLUGIN_ROOT:-}\" \"$HOME\"\u002F.claude\u002Fskills\u002Ffeature-forge \"$HOME\"\u002F.claude\u002Fplugins\u002Fcache\u002F*\u002Ffeature-forge\u002F* \"$HOME\"\u002F.claude\u002Fplugins\u002F*\u002Ffeature-forge \"$HOME\"\u002F.agents\u002Fskills\u002Ffeature-forge .\u002F.agents\u002Fskills\u002Ffeature-forge; do [ -x \"$d\u002Fscripts\u002Fforge-root.sh\" ] && exec \"$d\u002Fscripts\u002Fforge-root.sh\"; done')\"\n[ -n \"$R\" ] || { echo \"feature-forge: cannot locate plugin root\" >&2; exit 1; }\npython3 \"$R\u002Fscripts\u002Fforge-session.py\" state-complete --feature \"{feature}\" --stage forge-5-loop --version {n} --status \"\u003Ccomplete|in-progress>\" --based-on \"forge-4-backlog=\u003Ccurrent version from pipeline state>\" --artifact \"{backlogDir}\u002F{loopRunner.stateDir}\u002Fstate.json\" --specs-dir \"{specsDir}\"\n```\n\n**No git commit is needed** — the loop runner commits implementation code atomically per completed item during the run. (Step 6's commit, epic members only, is of pipeline state \u002F manifest — a distinct artifact.)\n\n## Step 5b: Offer Impl-Verify (standalone path)\n\n**Gate:** run only if (a) the feature's `.pipeline-state.json` has **no** `epic` key **and** (b) Step 5 set `stages.forge-5-loop.status` to `complete`. Otherwise **skip** straight to Step 7 — a non-complete run has nothing to verify yet, and epic members get the equivalent offer in Step 6.1 (do **not** prompt twice). This standalone counterpart to Step 6.1 nudges verification interactively. Use host's question mechanism (NOT inline prose) to offer: *\"{feature}'s loop is complete. Recommended: run `forge-verify {feature} impl` to audit the implementation before generating docs. Run it now, or skip to forge-6-docs?\"* On **run**, invoke `feature-forge:forge-verify {feature} impl` with the literal `owner: nested` token in the dispatching prompt — this dispatch happens inside the loop stage, so **you** remain the sole terminal owner and the branch skill returns its structured result and prints no terminal block of its own (see \"Branch ownership\" and \"Caller-side resumption\" in `references\u002Fstage-exit-protocol.md`; a delegate-and-resume site — on return, control resumes here). A verifier return without its report structure is a dropped digest, not a result (issue #183) — apply \"Truncated Verifier Returns\" in forge-verify's `findings-template.md` reference (resume or re-dispatch) before recording anything. On **skip**, persist the skip through `state-verify` using the fence below (mirrors `forge-4-backlog`'s skip handling) — the forge-6-docs backstop re-surfaces the skip. Either way, do **not** name a next command here: Step 7 routes, and it routes differently depending on what this step recorded.\n\n**The skip is written by `state-verify`, never by hand — and never over a resolved entry** (`passed`\u002F`findings-applied`: the verb refuses that demotion, #203 — skip the fence and continue). Add `--epic \"{epic}\"` when this feature is an epic member — required, per the Pipeline State Protocol in `references\u002Fshared-conventions.md`. On exit 2, surface the plain `Error:` line verbatim and stop: the skip is not persisted, so Step 7 would route on state that is not on disk.\n\n```bash\nR=\"$(bash -c '[ -z \"${FEATURE_FORGE_ROOT:-}\" ] || [ -x \"$FEATURE_FORGE_ROOT\u002Fscripts\u002Fforge-root.sh\" ] || { echo \"feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts\u002Fforge-root.sh\" >&2; exit 2; }; for d in \"${FEATURE_FORGE_ROOT:-}\" \"${CLAUDE_PLUGIN_ROOT:-}\" \"$HOME\"\u002F.claude\u002Fskills\u002Ffeature-forge \"$HOME\"\u002F.claude\u002Fplugins\u002Fcache\u002F*\u002Ffeature-forge\u002F* \"$HOME\"\u002F.claude\u002Fplugins\u002F*\u002Ffeature-forge \"$HOME\"\u002F.agents\u002Fskills\u002Ffeature-forge .\u002F.agents\u002Fskills\u002Ffeature-forge; do [ -x \"$d\u002Fscripts\u002Fforge-root.sh\" ] && exec \"$d\u002Fscripts\u002Fforge-root.sh\"; done')\"\n[ -n \"$R\" ] || { echo \"feature-forge: cannot locate plugin root\" >&2; exit 1; }\npython3 \"$R\u002Fscripts\u002Fforge-session.py\" state-verify --feature \"{feature}\" --stage forge-5-loop --status skipped --specs-dir \"{specsDir}\"\n```\n\n## Step 6: Epic Handoff\n\n**Gate:** only run this step if (a) the resolved feature's `.pipeline-state.json` has an `epic` key **and** (b) Step 5 set `stages.forge-5-loop.status` to `complete` (all backlog items done). If either is false, **skip** straight to Step 7 — standalone completed features are handled by Step 5b, and a non-complete run has no handoff to make (REQ-COMPAT-01).\n\n1. **Offer impl-verify first (recommended, skippable).** Per the completion rule (`00-core-definitions.md §7`), a feature whose `forge-verify-impl.status == findings-reported` does **not** unblock dependents. Use host's question mechanism (NOT inline prose) to offer: *\"{feature}'s loop is done. Recommended: run `forge-verify {feature} impl` before unblocking dependents. Run it now, or skip and continue the handoff?\"* On **run**, dispatch exactly as Step 5b does — the same literal `owner: nested` token in the dispatching prompt (you remain the sole terminal owner), the same truncated-return guard before recording anything, and the same declared resume (control returns here; the handoff continues at 2). On **skip**, persist the skip through `state-verify --status skipped` using Step 5b's fence (add `--epic \"{epic}\"` — required for members) so the Step 7 exit reads a recorded decision instead of re-asking the question the user just answered; completion is then judged on the §7 rule with impl-verify explicitly skipped.\n2. **Recompute and announce.** Run `render-status \"{epic}\" --specs-dir \"{specsDir}\" --json`. Announce the feature's completion and the epic rollup (e.g. \"2\u002F4 features complete\") — derived live from disk, never re-computed in prose.\n3. **Announce what is actionable — do not route.** Read `render-status`'s `actionable` set (every dependency now complete, not itself complete) and say plainly which members can start now, or which are still blocked and on which dependencies. This is context for the user, not a handoff: the Step 7 exit consumes the same live payload and fences the one authoritative next command itself, so do **not** present a next-feature picker, offer to author a member's PRD, or repeat a member's `nextCommand` here. Two competing actions is exactly the ambiguity the scripted exit removes.\n4. **Commit (REQ-OBS-01).** When `gitCommitAfterStage` is true, commit the Step 5 completion write (and any manifest `updatedAt` bump) via the shared-conventions **Git Commit Protocol**, staging the epic subtree so the member state change commits atomically: `git add {specsDir}\u002F{epic}\u002F` then `{commitPrefix}({feature}): complete loop`. If `gitCommitAfterStage` is false, skip the commit. Then fall through to Step 7 — the epic handoff closes there, once, like every other path.\n\n## Step 7: Close the Stage\n\nEvery loop run ends here, and ends here **exactly once** — standalone or epic member, complete or not.\n\nFirst select the single `LoopOutcome` with the ladder in `references\u002Fresult-reporting.md` (`resolved` → unfinished-runner `partial` → `needs-human` → `blocked` → `deferred` → `partial` → `complete`, first match wins, plus any `--cause` it names), reading it from Step 4a's authoritative counts and never from the runner's process exit code. If those counts were never obtained, follow that file's operational-failure rule instead: report the failure and its recovery and run no exit at all.\n\n**Close this stage with the Scripted Stage Exit** (contract: `references\u002Fstage-exit-protocol.md`; do not improvise a \"Next steps\" list). Run:\n\n```bash\nR=\"$(bash -c '[ -z \"${FEATURE_FORGE_ROOT:-}\" ] || [ -x \"$FEATURE_FORGE_ROOT\u002Fscripts\u002Fforge-root.sh\" ] || { echo \"feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts\u002Fforge-root.sh\" >&2; exit 2; }; for d in \"${FEATURE_FORGE_ROOT:-}\" \"${CLAUDE_PLUGIN_ROOT:-}\" \"$HOME\"\u002F.claude\u002Fskills\u002Ffeature-forge \"$HOME\"\u002F.claude\u002Fplugins\u002Fcache\u002F*\u002Ffeature-forge\u002F* \"$HOME\"\u002F.claude\u002Fplugins\u002F*\u002Ffeature-forge \"$HOME\"\u002F.agents\u002Fskills\u002Ffeature-forge .\u002F.agents\u002Fskills\u002Ffeature-forge; do [ -x \"$d\u002Fscripts\u002Fforge-root.sh\" ] && exec \"$d\u002Fscripts\u002Fforge-root.sh\"; done')\"\n[ -n \"$R\" ] || { echo \"feature-forge: cannot locate plugin root\" >&2; exit 1; }\npython3 \"$R\u002Fscripts\u002Fforge-session.py\" stage-exit --feature \"{feature}\" --stage forge-5-loop --outcome \"{LoopOutcome}\" --specs-dir \"{specsDir}\" --host generic --verify-capability \"{verify-capability}\"\n```\n\nObey the DIRECTIVES it prints, in the consumption order this protocol fixes: surface `invalidAutoVerifyKeys` and every `warnings` entry first; `runInStageVerify: true` → run the in-stage clean-room verify chain now (honoring `autoFixEligible`, and asking through the Standard Verify Gate first when you may not dispatch unsolicited); `verifyGate: \"standard\"` → present the Standard Verify Gate; `verifyGate: \"manual-print\"` → print the `verifyCommand` for the user and do **not** dispatch inline. Then, and only when `terminalOwnedBy` is `\"self\"`, **print the NEXT-STEPS block verbatim as your absolute last output — nothing after its sentinel line.** A `terminalOwnedBy: \"outer\"` payload carries `nextSteps: null`: return your structured result to the caller and print no terminal block at all.\n\nAdd `--epic \"{epic}\"` when this feature is an epic member — required, per the Pipeline State Protocol in `references\u002Fshared-conventions.md`. Determine `{verify-capability}` per the **Host and capability determination** section of `references\u002Fstage-exit-protocol.md`: `interactive` needs both a question mechanism and *permission* to dispatch the clean-room `forge-verifier`, and a session that merely needs consent first is still `interactive`. The script owns the routing for every outcome — the loop resume, the navigator recovery, the docs handoff, and the epic's live next member — so append nothing to its block: no retry line, no rollup restated, no \"continue to docs\". A non-`complete` outcome deliberately fences no downstream work, and re-adding one here would claim readiness the backlog does not support.\n\n## Gotchas\n\n- **Plugin-root discovery (1b-epic helper) covers installed paths, not workspace-dev checkouts.** The `forge-root.sh` search probes the locations of an **installed** plugin only, so a feature-forge **source checkout** (e.g. `~\u002Fworkspace\u002Ffeature-forge`) exits \"cannot locate plugin root\" unless `FEATURE_FORGE_ROOT` points at it (#323). Expected in a dev environment; run the epic-manifest script from the checkout directly (`python3 \u003Ccheckout>\u002Fscripts\u002Fepic-manifest.py …`).\n- `{backlogDir}` is a **directory path**, not a file path. Pass `specs\u002Fauth`, not `specs\u002Fauth\u002Fbacklog.json`.\n- rauf resolves `RAUF.md` with fallback (`{backlogDir}\u002F.rauf\u002FRAUF.md` first, then the project's `.rauf\u002FRAUF.md`). State files (state.json, {loopRunner.logFile}, etc.) land at `{backlogDir}\u002F{loopRunner.stateDir}\u002F`, isolated per backlog dir, so concurrent features don't collide.\n- If the session disconnects mid-loop, the runner process continues independently — check results later with the status \u002F list commands. A crashed run's stale lock (`PAUSED` + `lock.stale`) is cleared by rauf's `resume`, not `--force` (see `references\u002Fresult-reporting.md`).\n- Never run the run command in the foreground — it blocks for the whole run and hits the shell tool's timeout for any non-trivial backlog. \"Don't block the foreground\" is NOT \"stay silent\": supervise per 3d. A `needs_human`\u002F`blocked`\u002F`review` signal does **not** pause the loop — the runner sets the item aside and keeps going; surface it live but don't tell the user the loop is waiting.\n- The version gate (1c) uses the `--json` form on purpose; never parse `rauf version`'s human output.\n- **Implementation artifacts must not cite specs.** The loop should **read** specs and `backlog.json` freely — they are the source of truth, and the backlog rightly cites specs for provenance. But artifacts the loop **writes into the target repo** (source code, generated `SKILL.md`\u002Fagent files, configs, code comments) must be **self-contained**: no references to feature-forge spec files (no `See specs\u002F{feature}\u002FNN-*.md`, no \"source spec\" provenance notes) — specs are pre-implementation inputs that may be archived or deleted once the feature ships. This applies only to shipped implementation output, never to the backlog or spec documents, which keep citing specs.\n\n---\n\n## Host execution notes (Codex)\n\nThis skill was authored Claude-first; the body above refers to \"the host's question mechanism\", \"the host's subagent mechanism\", and \"the host's background-execution mechanism\". On Codex:\n\n- **User input:** Codex has no structured question tool. Which rung you are on is **not** observable from inside the session — a `codex exec` run looks exactly like an interactive one — so read it from the Interaction Capability Ladder's `interaction-mode` record instead of judging it. Interactive session — ask the question directly and wait for the reply; never assume an answer. Non-interactive — don't wait: take the Interaction Capability Ladder's declared conservative default, state it in your output, and use `no-default: abort — \u003Cquestion> requires a human answer` for an interview question with no sane default (`references\u002Fshared-conventions.md`).\n- **Subagents:** spawn a Codex subagent using the named custom agent under `.codex\u002Fagents\u002F\u003Cname>.toml`. Codex spawns a subagent only when explicitly asked; if the custom agent is unavailable, run that step inline yourself.\n- **Background \u002F monitoring (forge-5-loop):** Codex cannot wake you when a background process prints or exits, so **never end your turn while the loop runs**. Launch it detached and supervise it from inside the turn with the `rauf loop wait` loop — one bounded wait per shell call, print each card, decide from the status JSON — exactly as `references\u002Frunner-contract.md` (Steps 3b\u002F3d) says for this host. The optional rauf Stop hook (`rauf hook codex-stop`; wire it with `npx @garygentry\u002Ffeature-forge install -a codex --codex-stop-hook`) holds the session open if it tries to end its turn while the loop still runs. Other long-lived commands: run them in your shell session and report progress as it arrives.\n",{"name":5,"description":7},"main","ce0d6d40bba1d87039b0397041d15cb56c934037","adapters\u002Fcodex\u002Fskills\u002Fforge-5-loop","https:\u002F\u002Fgithub.com\u002Fgarygentry\u002Ffeature-forge","https:\u002F\u002Fgarygentry.github.io\u002Ffeature-forge\u002F","https:\u002F\u002Fgithub.com\u002Fgarygentry","2026-10-15 10:14:13",{"source":8,"skillName":5,"commands":31,"prompt":41,"zipAvailable":42},[32,35,38],{"tool":33,"command":34},"npx","npx skills add garygentry\u002Ffeature-forge --skill forge-5-loop",{"tool":36,"command":37},"bunx","bunx skills add garygentry\u002Ffeature-forge --skill forge-5-loop",{"tool":39,"command":40},"pnpm","pnpm dlx skills add garygentry\u002Ffeature-forge --skill forge-5-loop","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fgarygentry\u002Ffeature-forge\u002Fblob\u002Fmain\u002Fadapters\u002Fcodex\u002Fskills\u002Fforge-5-loop\u002FSKILL.md",true,[44,50,54,58,62,66,70,74,78],{"path":45,"resourceType":46,"resourceTypeDesc":47,"sizeBytes":48,"sourceHtmlUrl":49},"references\u002Fagent-selection.md","REFERENCE","参考文档",8451,"https:\u002F\u002Fgithub.com\u002Fgarygentry\u002Ffeature-forge\u002Fblob\u002Fmain\u002Fadapters\u002Fcodex\u002Fskills\u002Fforge-5-loop\u002Freferences\u002Fagent-selection.md",{"path":51,"resourceType":46,"resourceTypeDesc":47,"sizeBytes":52,"sourceHtmlUrl":53},"references\u002Fpreflight-and-self-heal.md",12075,"https:\u002F\u002Fgithub.com\u002Fgarygentry\u002Ffeature-forge\u002Fblob\u002Fmain\u002Fadapters\u002Fcodex\u002Fskills\u002Fforge-5-loop\u002Freferences\u002Fpreflight-and-self-heal.md",{"path":55,"resourceType":46,"resourceTypeDesc":47,"sizeBytes":56,"sourceHtmlUrl":57},"references\u002Fralph-loop-contract.md",13123,"https:\u002F\u002Fgithub.com\u002Fgarygentry\u002Ffeature-forge\u002Fblob\u002Fmain\u002Fadapters\u002Fcodex\u002Fskills\u002Fforge-5-loop\u002Freferences\u002Fralph-loop-contract.md",{"path":59,"resourceType":46,"resourceTypeDesc":47,"sizeBytes":60,"sourceHtmlUrl":61},"references\u002Frecovery-procedure.md",22902,"https:\u002F\u002Fgithub.com\u002Fgarygentry\u002Ffeature-forge\u002Fblob\u002Fmain\u002Fadapters\u002Fcodex\u002Fskills\u002Fforge-5-loop\u002Freferences\u002Frecovery-procedure.md",{"path":63,"resourceType":46,"resourceTypeDesc":47,"sizeBytes":64,"sourceHtmlUrl":65},"references\u002Fresult-reporting.md",12973,"https:\u002F\u002Fgithub.com\u002Fgarygentry\u002Ffeature-forge\u002Fblob\u002Fmain\u002Fadapters\u002Fcodex\u002Fskills\u002Fforge-5-loop\u002Freferences\u002Fresult-reporting.md",{"path":67,"resourceType":46,"resourceTypeDesc":47,"sizeBytes":68,"sourceHtmlUrl":69},"references\u002Frunner-contract.md",25831,"https:\u002F\u002Fgithub.com\u002Fgarygentry\u002Ffeature-forge\u002Fblob\u002Fmain\u002Fadapters\u002Fcodex\u002Fskills\u002Fforge-5-loop\u002Freferences\u002Frunner-contract.md",{"path":71,"resourceType":46,"resourceTypeDesc":47,"sizeBytes":72,"sourceHtmlUrl":73},"references\u002Fshared-conventions.md",74084,"https:\u002F\u002Fgithub.com\u002Fgarygentry\u002Ffeature-forge\u002Fblob\u002Fmain\u002Fadapters\u002Fcodex\u002Fskills\u002Fforge-5-loop\u002Freferences\u002Fshared-conventions.md",{"path":75,"resourceType":46,"resourceTypeDesc":47,"sizeBytes":76,"sourceHtmlUrl":77},"references\u002Fstage-exit-protocol.md",35669,"https:\u002F\u002Fgithub.com\u002Fgarygentry\u002Ffeature-forge\u002Fblob\u002Fmain\u002Fadapters\u002Fcodex\u002Fskills\u002Fforge-5-loop\u002Freferences\u002Fstage-exit-protocol.md",{"path":79,"resourceType":46,"resourceTypeDesc":47,"sizeBytes":80,"sourceHtmlUrl":81},"references\u002Fverify-state.md",4988,"https:\u002F\u002Fgithub.com\u002Fgarygentry\u002Ffeature-forge\u002Fblob\u002Fmain\u002Fadapters\u002Fcodex\u002Fskills\u002Fforge-5-loop\u002Freferences\u002Fverify-state.md",[83,90,95,101,106,112],{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":18},"01M75H8RTWSJ2HYCPPKA3FRG42","alpha","A valid skill description.","https:\u002F\u002Fgithub.com\u002Fgarygentry\u002Ffeature-forge\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Freader-nested-metadata\u002Fskills\u002Falpha\u002FSKILL.md",[],[],{"skillNo":91,"name":85,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":18},"01M75H8QXKFS116EF1009KB3CY","https:\u002F\u002Fgithub.com\u002Fgarygentry\u002Ffeature-forge\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Freader-malformed\u002Fskills\u002Falpha\u002FSKILL.md",[],[],{"skillNo":96,"name":85,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":18},"01M75H8PKNSV4WEREK6D91G9T4","This is a folded scalar description.","https:\u002F\u002Fgithub.com\u002Fgarygentry\u002Ffeature-forge\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Freader-folded-scalar\u002Fskills\u002Falpha\u002FSKILL.md",[],[],{"skillNo":102,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":103,"categories":104,"keywords":105,"publishedAt":18},"01M75H8MAV261C8QJ4S8CGRHV5","https:\u002F\u002Fgithub.com\u002Fgarygentry\u002Ffeature-forge\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Freader-crlf\u002Fskills\u002Falpha\u002FSKILL.md",[],[],{"skillNo":107,"name":85,"nameZh":6,"description":108,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":109,"categories":110,"keywords":111,"publishedAt":18},"01M75H8KDW98YF0PBHPD5V1GKR","foo: bar","https:\u002F\u002Fgithub.com\u002Fgarygentry\u002Ffeature-forge\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Freader-colon-value\u002Fskills\u002Falpha\u002FSKILL.md",[],[],{"skillNo":113,"name":85,"nameZh":6,"description":114,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":115,"categories":116,"keywords":117,"publishedAt":18},"01M75H8JFYFCGYNRCRTS4PMKKX","A valid description.","https:\u002F\u002Fgithub.com\u002Fgarygentry\u002Ffeature-forge\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Freader-blank-lines\u002Fskills\u002Falpha\u002FSKILL.md",[],[]]