AGENT SKILL

forge-5-loop

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 / run the loop / 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.

License 许可
MIT
最近更新
2026-10-15
Stars
★ 0
Forks
0

01 前言 Front Matter

name
forge-5-loop
description
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 / run the loop / 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.

02 资源文件 9

03 SKILL.md 正文

forge-5-loop — Autonomous Loop Executor

The loop spawns a fresh agent session per backlog item, implementing each task with full verification.

The 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/ralph-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}).

Resolve the loop runner

Resolve 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.

R="$(bash -c '[ -z "${FEATURE_FORGE_ROOT:-}" ] || [ -x "$FEATURE_FORGE_ROOT/scripts/forge-root.sh" ] || { echo "feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts/forge-root.sh" >&2; exit 2; }; for d in "${FEATURE_FORGE_ROOT:-}" "${CLAUDE_PLUGIN_ROOT:-}" "$HOME"/.claude/skills/feature-forge "$HOME"/.claude/plugins/cache/*/feature-forge/* "$HOME"/.claude/plugins/*/feature-forge "$HOME"/.agents/skills/feature-forge ./.agents/skills/feature-forge; do [ -x "$d/scripts/forge-root.sh" ] && exec "$d/scripts/forge-root.sh"; done')"
[ -n "$R" ] || { echo "feature-forge: cannot locate plugin root" >&2; exit 1; }
python3 "$R/scripts/forge-session.py" effective-config --config ./forge.config.json --json

Token substitution applies to every *Command string. Substitute:

  • {bin} → loopRunner.bin (default rauf)
  • {backlogDir} → the resolved backlog directory (Step 1d / 2b), relative to project root
  • {specsDir} → specsDir from config
  • {iterations} → the computed iteration count (Step 2a)

Whenever this skill says "run the run command" / "status command" / etc., it means the corresponding substituted loopRunner.*Command.

Turn structure reminder: Text first, then host's question mechanism for all questions — never embed one in your text (it stalls). At rung 2/3, see the Interaction Capability Ladder.

Step 1: Validate Prerequisites

Read and follow references/shared-conventions.md for feature name validation, configuration reading, and force mode handling.

1a. Pipeline State Check

Resolve the feature directory first. Invoke the Feature Directory Resolution block in references/shared-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}/ everywhere this skill previously wrote {specsDir}/{feature}/ (the 1e backlog path and the Step 3a / Step 5 state writes). Standalone features resolve to their flat path exactly as today.

Read {resolvedFeatureDir}/.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."

If 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).

1b. Verification Check

Derive 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/verify-state.md.

R="$(bash -c '[ -z "${FEATURE_FORGE_ROOT:-}" ] || [ -x "$FEATURE_FORGE_ROOT/scripts/forge-root.sh" ] || { echo "feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts/forge-root.sh" >&2; exit 2; }; for d in "${FEATURE_FORGE_ROOT:-}" "${CLAUDE_PLUGIN_ROOT:-}" "$HOME"/.claude/skills/feature-forge "$HOME"/.claude/plugins/cache/*/feature-forge/* "$HOME"/.claude/plugins/*/feature-forge "$HOME"/.agents/skills/feature-forge ./.agents/skills/feature-forge; do [ -x "$d/scripts/forge-root.sh" ] && exec "$d/scripts/forge-root.sh"; done')"
[ -n "$R" ] || { echo "feature-forge: cannot locate plugin root" >&2; exit 1; }
python3 "$R/scripts/forge-session.py" verify-state --feature "{feature}" --for-stage forge-4-backlog --specs-dir "{specsDir}" --json

If 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.

1b-epic. Epic Dependency Gate

Read 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:

  1. Run render-status "{epic}" --specs-dir "{specsDir}" --json via the helper:

R="$(bash -c '[ -z "${FEATURE_FORGE_ROOT:-}" ] || [ -x "$FEATURE_FORGE_ROOT/scripts/forge-root.sh" ] || { echo "feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts/forge-root.sh" >&2; exit 2; }; for d in "${FEATURE_FORGE_ROOT:-}" "${CLAUDE_PLUGIN_ROOT:-}" "$HOME"/.claude/skills/feature-forge "$HOME"/.claude/plugins/cache//feature-forge/ "$HOME"/.claude/plugins/*/feature-forge "$HOME"/.agents/skills/feature-forge ./.agents/skills/feature-forge; do [ -x "$d/scripts/forge-root.sh" ] && exec "$d/scripts/forge-root.sh"; done')" [ -n "$R" ] || { echo "feature-forge: cannot locate plugin root" >&2; exit 1; } python3 "$R/scripts/epic-manifest.py"
render-status "{epic}" --specs-dir "{specsDir}" --json


2. Find this feature's entry; read its `unmetDeps` (the direct `dependsOn` not yet complete-for-orchestration per `00-core-definitions.md §7`).
3. **If `unmetDeps` is empty**, proceed to 1c with no prompt.
4. **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:

> "{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?"

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.
5. If `render-status` fails, **STOP** — do not silently run a loop whose dependency state is unverifiable (REQ-ROBUST-02). Surface per the exit-1/exit-2 split in the **Feature Directory Resolution** block of `references/shared-conventions.md` (exit 1 → parse `{findings[]}` from stdout; exit 2 → surface the plain `Error:` stderr line verbatim — no findings JSON to parse).

This gate runs **before** the runner version/setup gates (1c/1d) so a blocked feature stops early, before any runner side-effects.

### 1c. Runner Version Gate

### 1d. Runner Setup Check (precondition file)

These gate on the loop runner being installed, current, and wired **before** touching it — enforced by `doctor`'s `runner-*` checks, never ad-hoc parsing. Run:

```bash
R="$(bash -c '[ -z "${FEATURE_FORGE_ROOT:-}" ] || [ -x "$FEATURE_FORGE_ROOT/scripts/forge-root.sh" ] || { echo "feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts/forge-root.sh" >&2; exit 2; }; for d in "${FEATURE_FORGE_ROOT:-}" "${CLAUDE_PLUGIN_ROOT:-}" "$HOME"/.claude/skills/feature-forge "$HOME"/.claude/plugins/cache/*/feature-forge/* "$HOME"/.claude/plugins/*/feature-forge "$HOME"/.agents/skills/feature-forge ./.agents/skills/feature-forge; do [ -x "$d/scripts/forge-root.sh" ] && exec "$d/scripts/forge-root.sh"; done')"
[ -n "$R" ] || { echo "feature-forge: cannot locate plugin root" >&2; exit 1; }
python3 "$R/scripts/forge-session.py" doctor --json --specs-dir "{specsDir}" --check runner-binary --check runner-version --check runner-wired --check runner-legacy-layout

All four ok/na → proceed silently. Otherwise follow references/preflight-and-self-heal.md: runner-binary/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.

installHint points at the runner CLI; setupHint (1d) installs its per-project artifacts.

1e. Backlog File Check

Resolve the backlog file path (matching forge-4-backlog's composition rule, item 015 / §6.2):

  • If backlogDir is set in forge.config.json: use {backlogDir}/{feature}/backlog.json (the per-feature subpath, so each epic member's backlog stays independent — the {feature} segment prevents collisions across a multi-feature epic)
  • Otherwise: use {resolvedFeatureDir}/backlog.json

Verify 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."

1f. Branch Pre-flight (if using git)

The 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/shared-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/imposed branch). Never hard-stop.

1g. Stranded-Work Pre-flight (if using git)

Run git status --porcelain. If it reports changes and {backlogDir}/{loopRunner.stateDir}/state.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/recovery-procedure.md to commit / stash / 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/stash or pass --force). A clean tree is silent.

Step 2: Construct the Loop Command

2a. Analyze Backlog

Run 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.

Calculate the iteration count: ceil((pending + in_progress) * loopIterationMultiplier) where loopIterationMultiplier comes from forge.config.json (default: 1.5, headroom for retries).

Then, 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/runner-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."

If there are blocked items, note them — the user may want --retry-blocked.

2b. Resolve Backlog Directory

{backlogDir} is a directory path (not a file path), relative to the project root.

  • If backlogDir is set in config: use the per-feature subpath {backlogDir}/{feature} (matching the 1e composition rule and forge-4-backlog §6.2).
  • Otherwise: use {resolvedFeatureDir} (the directory containing backlog.json).

2c. Build Command

Render the run command (loopRunner.runCommand) with token substitution, e.g. the rauf default becomes:

rauf loop run . --backlog specs/auth --iterations 15

2d. Confirm with User

Use 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:

Ready to run the loop for {feature}:

  {rendered runCommand}   # + " --review" when the recommended Run-mode option (below) is picked

Backlog summary:
  - Pending: {pending}
  - In progress: {in_progress}
  - Done: {done}
  - Blocked: {blocked}
  - Iterations: {iterationCount} ({activeItems} items x {loopIterationMultiplier} multiplier)
  - Max chain depth: {maxChainDepth} — depth bounds achievable progress regardless of iteration budget

For the model-selection precedence (item.model > --model/options > project default >
provider default), read references/runner-contract.md.

Run mode and full loop-runner contract: follow ## Run mode (Step 2d, rauf) and the remaining sections in references/runner-contract.md verbatim; loopRunner.reviewMode ("always"/"never") suppresses the Run-mode question — semantics live there.

Agent selection (gated on loopRunner.agentArgument)

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/agent-selection.md; read it. When the gate is on, augment Step 2d in order:

  • (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).
  • (b) Agent question. Add an "agent" question to the same host's question mechanism surface: one option per advertised row labelled "{displayName} ({id}) — available/not found", plus an explicit "default (claude-cli)" choice mapping to run_selection = None. Resolve the pick (run > project, empty/whitespace 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)/(c)/(d)/(d-model) still run — see references/agent-selection.md.
  • (c) Availability listing. From the same parsed agents[] (no second probe), list id / displayName / available (yes/no, detail on unavailable rows).
  • (d) Verdict — only for a non-default resolved agent (default path None/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 / unparseable / missing or empty agents[] / 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.
  • (d-model) Claude-only model-alias guard. Runs only when the resolved agent is non-default (not the default / claude-cli path). Read the backlog.json (Step 1e path); collect items whose model is a Claude-specific alias (tier opus/sonnet/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/agent-selection.md.
  • (e) Optional-flags line. Augment the confirmation block's closing flags/precedence pointer to list --agent <id> 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/agent-selection.md.
  • (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".

Step 3: Execute the Loop

3a. Update Pipeline State

Before 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/shared-conventions.md:

R="$(bash -c '[ -z "${FEATURE_FORGE_ROOT:-}" ] || [ -x "$FEATURE_FORGE_ROOT/scripts/forge-root.sh" ] || { echo "feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts/forge-root.sh" >&2; exit 2; }; for d in "${FEATURE_FORGE_ROOT:-}" "${CLAUDE_PLUGIN_ROOT:-}" "$HOME"/.claude/skills/feature-forge "$HOME"/.claude/plugins/cache/*/feature-forge/* "$HOME"/.claude/plugins/*/feature-forge "$HOME"/.agents/skills/feature-forge ./.agents/skills/feature-forge; do [ -x "$d/scripts/forge-root.sh" ] && exec "$d/scripts/forge-root.sh"; done')"
[ -n "$R" ] || { echo "feature-forge: cannot locate plugin root" >&2; exit 1; }
python3 "$R/scripts/forge-session.py" state-enter --feature "{feature}" --stage forge-5-loop --specs-dir "{specsDir}"

Then 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}/{epic}/): {commitPrefix}({feature}): forge-5-loop in-progress, regardless of gitCommitAfterStage. Unrelated leftover changes still trip the refusal; surface it, never auto-pass --force.

3b. Launch Background Process

Launch 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/runner-contract.md: the exact command, the mkdir -p state-dir and root→IS_SANDBOX guards, and why the runner's own {stateDir}/events.ndjson is never redirected into.

3c. Inform User

Follow the Inform-user output template (Step 3c) section of references/runner-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.

3d. Supervise the run, and react to events

Supervise the run exactly as Supervise the run (Step 3d) in references/runner-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.

3f. Reach completion

Step 4 is reached when the run has ended; Step 3d of references/runner-contract.md names this host's terminal signal. Never end your turn while the loop runs unless your host wakes you when it ends.

Step 4: Check Results

When the run has ended (Step 3f):

4a. Get Final Backlog State

Run the status-json command (loopRunner.statusJsonCommand) and read backlogSummary for the authoritative counts — it separates the three non-done outcomes: genuine blocked, needsHuman, and runner-deferred ("false blocks"). Fall back to the list command (loopRunner.listCommand) if statusJsonCommand is not configured. Also read the optional loopState, reviewPending, lock fields (absent on older runners = unset); Runner terminal states in references/result-reporting.md maps them. reviewPending: true is never complete, whatever the counts — offer the resume per Pending review in references/runner-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}/events.ndjson) for its itemsCreated/summary to surface in 4b — see references/result-reporting.md.

4b. Report Results

Present a summary to the user. Pick every branch that applies (a run can be both blocked 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/result-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.

4c. Post-Run Recovery Pass (unconditional)

Run the Post-Run Recovery Procedure (references/recovery-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.

Step 5: Update Pipeline State

Record 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/result-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.

R="$(bash -c '[ -z "${FEATURE_FORGE_ROOT:-}" ] || [ -x "$FEATURE_FORGE_ROOT/scripts/forge-root.sh" ] || { echo "feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts/forge-root.sh" >&2; exit 2; }; for d in "${FEATURE_FORGE_ROOT:-}" "${CLAUDE_PLUGIN_ROOT:-}" "$HOME"/.claude/skills/feature-forge "$HOME"/.claude/plugins/cache/*/feature-forge/* "$HOME"/.claude/plugins/*/feature-forge "$HOME"/.agents/skills/feature-forge ./.agents/skills/feature-forge; do [ -x "$d/scripts/forge-root.sh" ] && exec "$d/scripts/forge-root.sh"; done')"
[ -n "$R" ] || { echo "feature-forge: cannot locate plugin root" >&2; exit 1; }
python3 "$R/scripts/forge-session.py" state-complete --feature "{feature}" --stage forge-5-loop --version {n} --status "<complete|in-progress>" --based-on "forge-4-backlog=<current version from pipeline state>" --artifact "{backlogDir}/{loopRunner.stateDir}/state.json" --specs-dir "{specsDir}"

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 / manifest — a distinct artifact.)

Step 5b: Offer Impl-Verify (standalone path)

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/stage-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.

The skip is written by state-verify, never by hand — and never over a resolved entry (passed/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/shared-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.

R="$(bash -c '[ -z "${FEATURE_FORGE_ROOT:-}" ] || [ -x "$FEATURE_FORGE_ROOT/scripts/forge-root.sh" ] || { echo "feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts/forge-root.sh" >&2; exit 2; }; for d in "${FEATURE_FORGE_ROOT:-}" "${CLAUDE_PLUGIN_ROOT:-}" "$HOME"/.claude/skills/feature-forge "$HOME"/.claude/plugins/cache/*/feature-forge/* "$HOME"/.claude/plugins/*/feature-forge "$HOME"/.agents/skills/feature-forge ./.agents/skills/feature-forge; do [ -x "$d/scripts/forge-root.sh" ] && exec "$d/scripts/forge-root.sh"; done')"
[ -n "$R" ] || { echo "feature-forge: cannot locate plugin root" >&2; exit 1; }
python3 "$R/scripts/forge-session.py" state-verify --feature "{feature}" --stage forge-5-loop --status skipped --specs-dir "{specsDir}"

Step 6: Epic Handoff

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).

  1. 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.
  2. Recompute and announce. Run render-status "{epic}" --specs-dir "{specsDir}" --json. Announce the feature's completion and the epic rollup (e.g. "2/4 features complete") — derived live from disk, never re-computed in prose.
  3. 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.
  4. 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}/{epic}/ 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.

Step 7: Close the Stage

Every loop run ends here, and ends here exactly once — standalone or epic member, complete or not.

First select the single LoopOutcome with the ladder in references/result-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.

Close this stage with the Scripted Stage Exit (contract: references/stage-exit-protocol.md; do not improvise a "Next steps" list). Run:

R="$(bash -c '[ -z "${FEATURE_FORGE_ROOT:-}" ] || [ -x "$FEATURE_FORGE_ROOT/scripts/forge-root.sh" ] || { echo "feature-forge: FEATURE_FORGE_ROOT=$FEATURE_FORGE_ROOT has no scripts/forge-root.sh" >&2; exit 2; }; for d in "${FEATURE_FORGE_ROOT:-}" "${CLAUDE_PLUGIN_ROOT:-}" "$HOME"/.claude/skills/feature-forge "$HOME"/.claude/plugins/cache/*/feature-forge/* "$HOME"/.claude/plugins/*/feature-forge "$HOME"/.agents/skills/feature-forge ./.agents/skills/feature-forge; do [ -x "$d/scripts/forge-root.sh" ] && exec "$d/scripts/forge-root.sh"; done')"
[ -n "$R" ] || { echo "feature-forge: cannot locate plugin root" >&2; exit 1; }
python3 "$R/scripts/forge-session.py" stage-exit --feature "{feature}" --stage forge-5-loop --outcome "{LoopOutcome}" --specs-dir "{specsDir}" --host generic --verify-capability "{verify-capability}"

Obey 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.

Add --epic "{epic}" when this feature is an epic member — required, per the Pipeline State Protocol in references/shared-conventions.md. Determine {verify-capability} per the Host and capability determination section of references/stage-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.

Gotchas

  • 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. ~/workspace/feature-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 <checkout>/scripts/epic-manifest.py …).
  • {backlogDir} is a directory path, not a file path. Pass specs/auth, not specs/auth/backlog.json.
  • rauf resolves RAUF.md with fallback ({backlogDir}/.rauf/RAUF.md first, then the project's .rauf/RAUF.md). State files (state.json, {loopRunner.logFile}, etc.) land at {backlogDir}/{loopRunner.stateDir}/, isolated per backlog dir, so concurrent features don't collide.
  • If the session disconnects mid-loop, the runner process continues independently — check results later with the status / list commands. A crashed run's stale lock (PAUSED + lock.stale) is cleared by rauf's resume, not --force (see references/result-reporting.md).
  • 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/blocked/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.
  • The version gate (1c) uses the --json form on purpose; never parse rauf version's human output.
  • 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/agent files, configs, code comments) must be self-contained: no references to feature-forge spec files (no See specs/{feature}/NN-*.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.

Host execution notes (Codex)

This 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:

  • 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 — <question> requires a human answer for an interview question with no sane default (references/shared-conventions.md).
  • Subagents: spawn a Codex subagent using the named custom agent under .codex/agents/<name>.toml. Codex spawns a subagent only when explicitly asked; if the custom agent is unavailable, run that step inline yourself.
  • Background / 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/runner-contract.md (Steps 3b/3d) says for this host. The optional rauf Stop hook (rauf hook codex-stop; wire it with npx @garygentry/feature-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.

04 同仓库更多 Skills