@garygentry/feature-forge 0.2.10 → 0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/adapters/claude/.feature-forge-bundle.json +1 -1
  2. package/adapters/claude/references/shared-conventions.md +44 -8
  3. package/adapters/claude/scripts/forge-session.py +134 -1
  4. package/adapters/claude/skills/forge/SKILL.md +2 -0
  5. package/adapters/claude/skills/forge-0-epic/SKILL.md +2 -0
  6. package/adapters/claude/skills/forge-1-prd/SKILL.md +21 -3
  7. package/adapters/claude/skills/forge-2-tech/SKILL.md +2 -0
  8. package/adapters/claude/skills/forge-3-specs/SKILL.md +3 -1
  9. package/adapters/claude/skills/forge-4-backlog/SKILL.md +4 -0
  10. package/adapters/codex/.feature-forge-bundle.json +1 -1
  11. package/adapters/codex/references/shared-conventions.md +44 -8
  12. package/adapters/codex/scripts/forge-session.py +134 -1
  13. package/adapters/codex/skills/forge/SKILL.md +2 -0
  14. package/adapters/codex/skills/forge-0-epic/SKILL.md +2 -0
  15. package/adapters/codex/skills/forge-1-prd/SKILL.md +20 -2
  16. package/adapters/codex/skills/forge-2-tech/SKILL.md +2 -0
  17. package/adapters/codex/skills/forge-3-specs/SKILL.md +3 -1
  18. package/adapters/codex/skills/forge-4-backlog/SKILL.md +4 -0
  19. package/adapters/copilot/.feature-forge-bundle.json +1 -1
  20. package/adapters/copilot/references/shared-conventions.md +44 -8
  21. package/adapters/copilot/scripts/forge-session.py +134 -1
  22. package/adapters/copilot/skills/forge/forge.md +2 -0
  23. package/adapters/copilot/skills/forge-0-epic/forge-0-epic.md +2 -0
  24. package/adapters/copilot/skills/forge-1-prd/forge-1-prd.md +20 -2
  25. package/adapters/copilot/skills/forge-2-tech/forge-2-tech.md +2 -0
  26. package/adapters/copilot/skills/forge-3-specs/forge-3-specs.md +3 -1
  27. package/adapters/copilot/skills/forge-4-backlog/forge-4-backlog.md +4 -0
  28. package/adapters/cursor/.feature-forge-bundle.json +1 -1
  29. package/adapters/cursor/references/shared-conventions.md +44 -8
  30. package/adapters/cursor/scripts/forge-session.py +134 -1
  31. package/adapters/cursor/skills/forge/forge.mdc +2 -0
  32. package/adapters/cursor/skills/forge-0-epic/forge-0-epic.mdc +2 -0
  33. package/adapters/cursor/skills/forge-1-prd/forge-1-prd.mdc +20 -2
  34. package/adapters/cursor/skills/forge-2-tech/forge-2-tech.mdc +2 -0
  35. package/adapters/cursor/skills/forge-3-specs/forge-3-specs.mdc +3 -1
  36. package/adapters/cursor/skills/forge-4-backlog/forge-4-backlog.mdc +4 -0
  37. package/adapters/gemini/.feature-forge-bundle.json +1 -1
  38. package/adapters/gemini/gemini-extension.json +1 -1
  39. package/adapters/gemini/references/shared-conventions.md +44 -8
  40. package/adapters/gemini/scripts/forge-session.py +134 -1
  41. package/adapters/gemini/skills/forge/forge.md +2 -0
  42. package/adapters/gemini/skills/forge-0-epic/forge-0-epic.md +2 -0
  43. package/adapters/gemini/skills/forge-1-prd/forge-1-prd.md +20 -2
  44. package/adapters/gemini/skills/forge-2-tech/forge-2-tech.md +2 -0
  45. package/adapters/gemini/skills/forge-3-specs/forge-3-specs.md +3 -1
  46. package/adapters/gemini/skills/forge-4-backlog/forge-4-backlog.md +4 -0
  47. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feature-forge",
3
- "version": "0.12.5",
3
+ "version": "0.12.7",
4
4
  "agent": "claude",
5
5
  "generatedBy": "python3 scripts/build-adapters.py"
6
6
  }
@@ -159,6 +159,28 @@ python3 "$R/scripts/epic-manifest.py" \
159
159
 
160
160
  If `render-status` fails, proceed with **only** EPIC.md + charter (a corrupt manifest must not silently inject stale dep specs — REQ-ROBUST-02): on **exit 1**, parse the `{findings[]}` JSON from stdout and surface each; on **exit 2**, surface the plain `Error:` line from stderr verbatim. Do not attempt to parse findings JSON on an exit-2 failure (stdout is empty).
161
161
 
162
+ **After injecting context, invoke the Epic-Member Base Guard block below** (it self-gates to a no-op for standalone features and features that do not resolve as a nested member).
163
+
164
+ ## Epic-Member Base Guard
165
+
166
+ Defense-in-depth for the split-brain-epic failure (Issue #125). Invoke this block in the authoring stages (`forge-1-prd`..`forge-4-backlog`) once the feature has resolved — right after **Epic Context Injection** for the stages that run it (`forge-1-prd`..`forge-3-specs`), and right after **Feature Directory Resolution** for `forge-4-backlog`. It confirms that a **resolved nested epic member** actually sits on a branch that contains the epic's manifest. Without this, a member reached from a branch cut *before* the epic-manifest commit (or that otherwise lacks it) would author specs against an epic decomposition that is not present — the exact drift that produces a disjoint, split-brain member. **Skip if not a git repo or `branchPerFeature` is false.**
167
+
168
+ ```bash
169
+ R="$(bash -c 'for d in "${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')"
170
+ [ -n "$R" ] || { echo "feature-forge: cannot locate plugin root" >&2; exit 1; }
171
+ python3 "$R/scripts/forge-session.py" check-epic-base --feature "{feature}" --specs-dir "{specsDir}" --json
172
+ ```
173
+
174
+ Act on the emitted `action`:
175
+ - **`none`** — a standalone feature (no epic to check) or the manifest is present on the current branch. Proceed silently. This is the no-op path for standalone features (REQ-COMPAT-01), so standalone behavior is unchanged.
176
+ - **`not-resolved`** — the feature does not resolve on the current branch. Proceed silently (the caller's own resolution already handled that case).
177
+ - **`warn-detached-base`** — a nested member resolves here but the epic's `epic-manifest.json` is **absent on this branch**. **STOP** unless `--force` was passed, and surface verbatim (filling `{epic}` and `{homeBranch}` from the payload's `epic` and `homeBranch`):
178
+ > `{feature}` is a member of epic `{epic}`, but this branch does not contain the epic manifest (`{specsDir}/{epic}/epic-manifest.json`). This base predates or lacks the epic. Switch to the epic's home branch `{homeBranch}` and re-run, or pass `--force` to author against a detached base anyway.
179
+
180
+ With `--force`, log a one-line warning ("Authoring `{feature}` against a detached epic base — manifest not on this branch") and proceed, consistent with the other guards.
181
+
182
+ If the helper is unavailable (a non-Claude host without the resolver), skip this block — it is best-effort defense in depth, not a hard prerequisite.
183
+
162
184
  ## Pipeline State Protocol
163
185
 
164
186
  Write pipeline state conforming to `references/pipeline-state-schema.json`. Always update `updatedAt` when modifying pipeline state.
@@ -226,17 +248,31 @@ When `gitCommitAfterStage` is true, follow this exact order to avoid state incon
226
248
  - **Nothing to commit:** If all artifacts were already committed, this is fine — mark the stage `complete`, leave `commitHash` at its existing value (or `null` if there was never an artifact commit), and skip Commit 2. There is no new artifact commit to record.
227
249
  5. **Never** use `git add -A`, `--amend`, `--no-verify`, or `--force` flags
228
250
 
229
- ## Crash Recovery
251
+ ## Stage-Entry Guard
252
+
253
+ Invoke this block at the **start of an authoring stage** (`forge-1-prd`..`forge-4-backlog`), **after** Feature Directory Resolution and **before** any interview or (re-)authoring. It prevents a re-entered stage — an injected skill body or a re-invoked `Skill` — from blindly re-running the interview over an in-progress or already-complete draft. `{stage}` is the invoking skill's id (e.g. `forge-2-tech`).
254
+
255
+ **Read, then classify** this stage's entry in `{resolvedFeatureDir}/.pipeline-state.json` (`stages.{stage}.status`):
256
+
257
+ 1. **Fresh** — no state file yet, or `stages.{stage}` is absent/`pending`. First run of this stage. Proceed to the **Entry Stamp** below, then author normally. No prompt.
258
+
259
+ 2. **Interrupted** (`status: "in-progress"`) — a previous run of THIS stage was interrupted before it committed (the exit commit is what flips it to `complete`, so `in-progress` on entry always means a crash/abandon). Do **not** silently re-author. Instead:
260
+ - **Inventory on-disk artifacts:** list the files this stage produces that already exist in `{resolvedFeatureDir}/` (e.g. `PRD.md`; `tech-spec.md`; the `##-*.md` suite + `TRACEABILITY.md`; `backlog.json`), and cross-check against the `stages.{stage}.artifacts` array (written incrementally during the previous run).
261
+ - **Gate via `AskUserQuestion`** (Decision Support protocol): present the inventory as text, then ask "This {stage} run was interrupted — {N} artifact(s) from the previous run are on disk: {list}. Resume the in-progress draft, or start a new version from scratch?" Options: **Resume (recommended)** — continue from the first artifact not yet written/complete, reusing the existing files; do **not** re-stamp or bump the version. · **Start a new version** — treat it as a fresh authoring pass (proceed to the Entry Stamp; the version increments at exit).
262
+ - Skip artifact regeneration for files that already exist and are complete (non-empty, properly structured); continue from the next unwritten artifact.
263
+
264
+ 3. **Re-authoring** (`status: "complete"` or `"stale"`) — a finished draft exists. Warn via `AskUserQuestion` before overwriting: "A completed {stage} artifact already exists for '{feature}' (v{n}{, marked stale}). Continuing will create a new version. Proceed?" On confirm, proceed to the Entry Stamp and author a new version (the version increments at exit, per that stage's Update-Pipeline-State step).
265
+
266
+ **Entry Stamp** (fresh, restart, and re-author paths — NOT the resume path). Before authoring, write to `{resolvedFeatureDir}/.pipeline-state.json` and update `updatedAt`:
267
+ - `stages.{stage}.status` → `"in-progress"`
268
+ - `stages.{stage}.startedAt` → current ISO-8601 UTC timestamp
269
+ - top-level `currentStage` → `"{stage}"` (where the pipeline IS, per O1)
230
270
 
231
- When a skill detects that `currentStage` matches itself and the stage status is `in-progress`, a previous run was interrupted. Follow this recovery protocol:
271
+ This write is **left uncommitted**: it is staged and committed as part of this stage's existing exit commit (Git Commit Protocol), so no extra commit is needed at entry. If the run is interrupted after the stamp but before the exit commit, the marker survives on disk (uncommitted) and the next entry classifies as **Interrupted** — which is exactly the intent.
232
272
 
233
- 1. **Inventory existing artifacts:** List all files on disk in `{specsDir}/{feature}/` that this stage would produce
234
- 2. **Compare against state:** Check the `artifacts` array in the pipeline state for this stage — it tracks files written incrementally during the previous run
235
- 3. **Present options to user:** "This stage was interrupted. Found {N} artifacts from the previous run: {list}. Would you like to resume from where it left off, or restart the stage from scratch?"
236
- 4. **If resume:** Skip artifact generation for files that already exist and appear complete (non-empty, properly structured). Continue from the next unwritten artifact.
237
- 5. **If restart:** Proceed normally. The version number will increment.
273
+ **Force Mode.** When `--force` is passed, skip the interactive gate: do not prompt for resume-vs-restart or the re-author warning. Treat entry as a fresh restart — apply the Entry Stamp and author. (`--force` already skips prerequisite checks; here it likewise bypasses the self-stage gate. Existing on-disk artifacts are still loaded per Force Mode.)
238
274
 
239
- **Incremental artifact tracking:** When a stage writes multiple files (e.g., forge-3-specs writing a suite of spec documents), update the `artifacts` array in `.pipeline-state.json` after writing each file — not just at stage completion. This ensures crash recovery knows exactly which files were successfully written.
275
+ **Incremental artifact tracking:** When a stage writes multiple files (e.g. forge-3-specs writing a suite of spec documents), update the `stages.{stage}.artifacts` array in `.pipeline-state.json` after writing each file — not just at stage completion. This is what makes the Interrupted inventory above precise about which files were successfully written.
240
276
 
241
277
  ## Force Mode
242
278
 
@@ -11,6 +11,8 @@ root navigator:
11
11
  python3 forge-session.py discover-feature [NAME | --all] [--specs-dir DIR] [--json]
12
12
  python3 forge-session.py reconcile-branch --feature F [--specs-dir DIR] \
13
13
  [--config FILE] [--epic E] [--json]
14
+ python3 forge-session.py check-epic-base --feature F [--specs-dir DIR] \
15
+ [--config FILE] [--epic E] [--json]
14
16
  python3 forge-session.py stage-exit --feature F --stage S [--specs-dir DIR] \
15
17
  [--config FILE] [--epic E] [--next-feature N] [--host claude|generic] [--json]
16
18
 
@@ -45,7 +47,17 @@ concluding it was never started. When nothing is found locally it also asks
45
47
  `git ls-remote --heads origin` about branches a single-branch clone never
46
48
  fetched, and emits the exact `git fetch`/`git switch` commands a caller could
47
49
  run. It is strictly read-only — it never checks anything out itself — and
48
- like `doctor` it always exits 0 and degrades to data.
50
+ like `doctor` it always exits 0 and degrades to data. Each candidate also
51
+ carries `epic`/`isEpicMember`, so a caller minting a new standalone feature can
52
+ refuse when the name is a known epic member discoverable on another branch
53
+ (the split-brain-epic guard, Issue #125).
54
+
55
+ `check-epic-base` is the defense-in-depth companion: given a feature that
56
+ resolves to a nested epic member on the current branch, it confirms the epic's
57
+ `epic-manifest.json` is actually present on HEAD. When it is absent, the member
58
+ was reached from a branch that predates or lacks the manifest commit (a detached
59
+ base) and the command emits `warn-detached-base` with the member's recorded home
60
+ branch. Read-only; always exits 0.
49
61
 
50
62
  `stage-exit` computes everything an authoring stage's closing used to derive
51
63
  in prose (the Scripted Stage Exit, `references/stage-exit-protocol.md`):
@@ -848,6 +860,26 @@ def _read_state_at_ref(ref: str, path: str) -> dict:
848
860
  return parsed if isinstance(parsed, dict) else {}
849
861
 
850
862
 
863
+ def _epic_membership(path: str, specs_rel: str, state: dict) -> tuple[str | None, bool]:
864
+ """Derive ``(epic, isEpicMember)`` for a discovered candidate.
865
+
866
+ A candidate is an epic member when its state carries an ``epic`` back-pointer
867
+ **or** its path is nested (``{specsDir}/{epic}/{name}/.pipeline-state.json``).
868
+ Nested-ness is structurally authoritative; the ``epic`` field is the recorded
869
+ back-pointer. When the state lacks the field, the nested directory name is used
870
+ so the signal is never "member of epic None".
871
+ """
872
+ prefix = specs_rel + "/"
873
+ nested_epic: str | None = None
874
+ if path.startswith(prefix):
875
+ segments = path[len(prefix):].split("/")
876
+ if len(segments) == 3: # [epic, name, state-file]
877
+ nested_epic = segments[0]
878
+ epic = state.get("epic")
879
+ epic = epic if isinstance(epic, str) and epic else nested_epic
880
+ return epic, bool(nested_epic) or bool(epic)
881
+
882
+
851
883
  def _list_refs(pattern: str) -> list[tuple[str, str]]:
852
884
  """Return ``(short_ref, committer_date)`` pairs under a ref namespace."""
853
885
  raw = _git_output([
@@ -908,6 +940,7 @@ def discover_feature(name: str, specs_dir: str) -> dict:
908
940
  state_branch = state.get("branch")
909
941
  state_branch = state_branch if isinstance(state_branch, str) else None
910
942
  updated = state.get("updatedAt")
943
+ epic, is_epic_member = _epic_membership(path, specs_rel, state)
911
944
  matched_branches.add(branch)
912
945
  candidates.append({
913
946
  "branch": branch,
@@ -918,6 +951,8 @@ def discover_feature(name: str, specs_dir: str) -> dict:
918
951
  "stateBranchMatches": state_branch == branch,
919
952
  "currentStage": state.get("currentStage"),
920
953
  "pipelineStatus": state.get("pipelineStatus", "active"),
954
+ "epic": epic,
955
+ "isEpicMember": is_epic_member,
921
956
  "updatedAt": updated if isinstance(updated, str) else None,
922
957
  "commitDate": commit_date or None,
923
958
  "isCurrentBranch": branch == current_branch,
@@ -988,6 +1023,8 @@ def _print_discover(payload: dict) -> None:
988
1023
  marks.append("remote-tracking")
989
1024
  if not cand["stateBranchMatches"] and cand["stateBranch"]:
990
1025
  marks.append(f"state records branch {cand['stateBranch']}")
1026
+ if cand.get("isEpicMember"):
1027
+ marks.append(f"member of epic {cand.get('epic') or '?'}")
991
1028
  suffix = f" ({'; '.join(marks)})" if marks else ""
992
1029
  print(
993
1030
  f" {cand['branch']}: stage={cand['currentStage'] or '?'} "
@@ -1054,6 +1091,7 @@ def discover_all(specs_dir: str) -> dict:
1054
1091
  state = _read_state_at_ref(ref, path)
1055
1092
  state_branch = state.get("branch")
1056
1093
  state_branch = state_branch if isinstance(state_branch, str) else None
1094
+ epic, is_epic_member = _epic_membership(path, specs_rel, state)
1057
1095
  seen.append({
1058
1096
  "branch": branch,
1059
1097
  "remoteTracking": is_remote,
@@ -1062,6 +1100,8 @@ def discover_all(specs_dir: str) -> dict:
1062
1100
  "stateBranchMatches": state_branch == branch,
1063
1101
  "currentStage": state.get("currentStage"),
1064
1102
  "pipelineStatus": state.get("pipelineStatus", "active"),
1103
+ "epic": epic,
1104
+ "isEpicMember": is_epic_member,
1065
1105
  "commitDate": commit_date or None,
1066
1106
  "isCurrentBranch": branch == current_branch,
1067
1107
  "switchCommand": f"git switch {branch}",
@@ -1097,6 +1137,8 @@ def _print_discover_all(payload: dict) -> None:
1097
1137
  marks.append("remote-tracking")
1098
1138
  if not cand["stateBranchMatches"] and cand["stateBranch"]:
1099
1139
  marks.append(f"state records branch {cand['stateBranch']}")
1140
+ if cand.get("isEpicMember"):
1141
+ marks.append(f"member of epic {cand.get('epic') or '?'}")
1100
1142
  suffix = f" ({'; '.join(marks)})" if marks else ""
1101
1143
  print(f" {cand['branch']}: stage={cand['currentStage'] or '?'} "
1102
1144
  f"status={cand['pipelineStatus']}{suffix}")
@@ -1191,6 +1233,77 @@ def _print_reconcile(payload: dict) -> None:
1191
1233
  print(f" → write state branch := {payload['newBranch']} ({payload['statePath']})")
1192
1234
 
1193
1235
 
1236
+ # --------------------------------------------------------------------------- #
1237
+ # Epic-member base guard (Issue #125) — detached-base detection
1238
+ # --------------------------------------------------------------------------- #
1239
+
1240
+
1241
+ def check_epic_base(
1242
+ name: str, specs_dir: Path, config_path: Path, epic: str | None = None
1243
+ ) -> dict:
1244
+ """Verify the current HEAD actually contains the epic manifest for a nested member.
1245
+
1246
+ Defense-in-depth for the split-brain-epic failure (Issue #125): when a feature
1247
+ resolves to a nested epic-member directory but the epic's ``epic-manifest.json``
1248
+ is absent from the current checkout, the member stub was reached from a branch
1249
+ that predates (or otherwise lacks) the manifest commit — a detached base. This
1250
+ is read-only: it emits a decision; the caller stops or warns.
1251
+
1252
+ Actions:
1253
+ - ``none`` — not a git repo, a standalone feature (no epic to check), or the
1254
+ manifest is present on HEAD. Nothing to do.
1255
+ - ``not-resolved`` — the feature does not resolve on the current branch.
1256
+ - ``warn-detached-base`` — nested member resolves here but the manifest is
1257
+ missing on HEAD; ``homeBranch`` is the member stub's recorded ``branch``.
1258
+ """
1259
+ base = {
1260
+ "feature": name,
1261
+ "gitRepo": True,
1262
+ "epic": epic,
1263
+ "isEpicMember": False,
1264
+ "manifestOnHead": None,
1265
+ "homeBranch": None,
1266
+ }
1267
+ if _git_output(["rev-parse", "--git-dir"]) is None:
1268
+ return {**base, "gitRepo": False, "action": "none",
1269
+ "reason": "not a git repository"}
1270
+ config = _load_config(config_path)
1271
+ row = next(
1272
+ (r for r in build_rows(specs_dir, config)
1273
+ if r["name"] == name and (epic is None or r["epic"] == epic)),
1274
+ None,
1275
+ )
1276
+ if row is None:
1277
+ return {**base, "action": "not-resolved",
1278
+ "reason": "feature state does not resolve on the current branch — "
1279
+ "use discover-feature to locate it"}
1280
+ member_epic = row["epic"]
1281
+ if not member_epic:
1282
+ return {**base, "action": "none",
1283
+ "reason": "standalone feature — no epic base to check"}
1284
+ base = {**base, "epic": member_epic, "isEpicMember": True,
1285
+ "homeBranch": row["branch"]}
1286
+ manifest = specs_dir / member_epic / MANIFEST_FILENAME
1287
+ if manifest.is_file():
1288
+ return {**base, "manifestOnHead": True, "action": "none",
1289
+ "reason": f"epic manifest present on the current branch "
1290
+ f"({member_epic}/{MANIFEST_FILENAME})"}
1291
+ return {**base, "manifestOnHead": False, "action": "warn-detached-base",
1292
+ "reason": f"member of epic {member_epic!r} resolves here, but "
1293
+ f"{member_epic}/{MANIFEST_FILENAME} is absent on the current "
1294
+ f"branch — this base predates or lacks the epic manifest"}
1295
+
1296
+
1297
+ def _print_check_epic_base(payload: dict) -> None:
1298
+ """Human-readable check-epic-base report."""
1299
+ if not payload["gitRepo"]:
1300
+ print(f"check-epic-base {payload['feature']}: not a git repository")
1301
+ return
1302
+ print(f"check-epic-base {payload['feature']}: {payload['action']} — {payload['reason']}")
1303
+ if payload["action"] == "warn-detached-base":
1304
+ print(f" → switch to the epic's home branch: {payload['homeBranch'] or '(unknown)'}")
1305
+
1306
+
1194
1307
  # --------------------------------------------------------------------------- #
1195
1308
  # Scripted Stage Exit
1196
1309
  # --------------------------------------------------------------------------- #
@@ -1587,6 +1700,16 @@ def main() -> int:
1587
1700
  p_recon.add_argument("--epic", default=None, help="Epic name for a nested member")
1588
1701
  p_recon.add_argument("--json", action="store_true", dest="json_output")
1589
1702
 
1703
+ p_base = sub.add_parser(
1704
+ "check-epic-base",
1705
+ help="Verify HEAD contains the epic manifest for a resolved nested member",
1706
+ )
1707
+ p_base.add_argument("--feature", required=True, help="Feature name")
1708
+ p_base.add_argument("--specs-dir", default="./specs", help="Specs directory")
1709
+ p_base.add_argument("--config", default="./forge.config.json", help="forge.config.json path")
1710
+ p_base.add_argument("--epic", default=None, help="Epic name for a nested member")
1711
+ p_base.add_argument("--json", action="store_true", dest="json_output")
1712
+
1590
1713
  p_exit = sub.add_parser(
1591
1714
  "stage-exit", help="Emit the Scripted Stage Exit directives + NEXT-STEPS block"
1592
1715
  )
@@ -1667,6 +1790,16 @@ def main() -> int:
1667
1790
  _print_reconcile(payload)
1668
1791
  return 0
1669
1792
 
1793
+ if args.cmd == "check-epic-base":
1794
+ payload = check_epic_base(
1795
+ args.feature, Path(args.specs_dir), Path(args.config), args.epic
1796
+ )
1797
+ if args.json_output:
1798
+ print(json.dumps(payload, indent=2, ensure_ascii=False))
1799
+ else:
1800
+ _print_check_epic_base(payload)
1801
+ return 0
1802
+
1670
1803
  if args.cmd == "stage-exit":
1671
1804
  payload = stage_exit(
1672
1805
  args.feature,
@@ -91,6 +91,8 @@ After rendering a **per-feature** dashboard for an **active** pipeline (skip thi
91
91
 
92
92
  **1. Read the next step.** From the `rank-features --json` output (above), find this feature's row and read its `nextStage`, `nextCommand`, `verifyPending`, `verifyCommand`, `verifyStage`, `verifyState`, `autoVerify`, `autoFix`, and `verifyGate` (the resolved gate: `none` → no verify action; `auto` → the §2b catch-up; `standard` → the §3 gate). If the feature is not in the `active` list (paused/abandoned), or `nextStage` is `null` (every production stage complete), skip the drive prompt — instead congratulate the user and, if `forge-6-docs` has not run, offer it; otherwise note the pipeline is complete. If the payload has a non-empty `invalidAutoVerifyKeys`, print a one-line warning first (e.g. "⚠️ forge.config.json `autoVerifyStages` has unknown keys: … — they are ignored; fix the typo").
93
93
 
94
+ **Detached-epic hint (completion of a *standalone* feature, Issue #125).** When `nextStage` is `null` for a feature whose row has no `epic` (a standalone completion), run `discover-feature "{feature}" --json` (via the standard prelude) *before* congratulating. If any candidate has `isEpicMember: true` on another branch, add an **additive, non-blocking** hint — it does not change the completion, only flags a likely split-brain: "⚠️ Heads-up: `{feature}` matches a member of epic `{epic}` on branch `{stateBranch}`. This standalone pipeline may have been forged detached from that epic. To reconcile, see `docs/recovery-detached-epic-member.md` (or continue — this is only a heads-up)." Skip the hint for epic-member rows (their `epic` is non-null) and when discovery surfaces no epic-member candidate.
95
+
94
96
  **2. Check the context window.** Run the context-usage helper so you can advise whether to continue here or start the next stage in a fresh session:
95
97
  ```bash
96
98
  R="$(bash -c 'for d in "${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')"
@@ -69,6 +69,8 @@ Resolve the epic subtree path `{specsDir}/{epic}/` and decide which branch to ru
69
69
  - **NEW** (no `epic-manifest.json`) → **Creation branch** (Step C1 onward).
70
70
  - **EXISTS** → **Edit branch** (§ Edit Mode below).
71
71
 
72
+ This manifest-existence dispatch **is** forge-0-epic's stage-entry guard: a re-entry on an existing epic lands in Edit Mode (helper-mutated, re-validated) rather than re-running the creation interview, so the **Stage-Entry Guard** block used by `forge-1-prd`..`forge-4-backlog` does not apply here (an epic has no self `.pipeline-state.json` to stamp — it writes member states).
73
+
72
74
  3. **Pre-flight epic-name uniqueness (creation only).** Before composing anything for a NEW
73
75
  epic, confirm the epic name itself does not collide with any existing feature or epic:
74
76
 
@@ -2,7 +2,7 @@
2
2
  # GENERATED — DO NOT EDIT. Source: skills/forge-1-prd/SKILL.md. Regenerate: python3 scripts/build-adapters.py
3
3
  name: forge-1-prd
4
4
  description: Create a requirements PRD for a feature through structured interview. Use when user runs /feature-forge:forge-1-prd or explicitly asks to start the forge pipeline for a new feature. Do NOT trigger for general requirements discussions, project scoping outside forge, or PRD questions unrelated to the forge pipeline.
5
- argument-hint: <feature-name>
5
+ argument-hint: <feature-name> [--force-standalone]
6
6
  ---
7
7
 
8
8
  # forge-1-prd — Requirements Interviewer
@@ -13,14 +13,32 @@ Create a thorough, requirements-only PRD through relentless structured interview
13
13
 
14
14
  Read and follow `references/shared-conventions.md` for feature name validation, configuration reading, and force mode handling before proceeding.
15
15
 
16
+ **`--force-standalone` (forge-1-prd only).** A distinct flag from `--force`: it bypasses only the **Mint Guard** in Step 1 (letting you intentionally fork a name that is a known epic member into a detached standalone feature). It does **not** imply `--force` — prerequisite checks and the Stage-Entry Guard still run. Use it only when you genuinely mean to create a standalone feature that shares a name with an epic member on another branch.
17
+
16
18
  ## Step 1: Read Configuration and Check State
17
19
 
18
20
  ### Branch Setup (if using git)
19
21
  Invoke the **Branch Setup** block in `references/shared-conventions.md` with `{label}` = `{feature}` and `{scope}` = `feature`. It self-gates (skips when not a git repo, when `branchPerFeature` is false, or for an epic member that inherits the epic's branch), detects whether you're on the default branch, and strongly recommends — still optionally — creating `{branchPrefix}{feature}` when you are. Do this before directory resolution.
20
22
 
21
- Set the working directory by invoking the **Feature Directory Resolution** block in `references/shared-conventions.md`, which yields `{resolvedFeatureDir}`. Note one PRD-specific caveat: at PRD time a brand-new standalone feature may have NO directory yet, so resolution is expected to fail `not-found` for a never-started standalone feature — in that case forge-1 creates `{specsDir}/{feature}/` as today. For an epic member the directory already exists (created empty by forge-0-epic with an `epic` back-pointer), so resolution succeeds and yields the nested path.
23
+ Set the working directory by invoking the **Feature Directory Resolution** block in `references/shared-conventions.md`, which yields `{resolvedFeatureDir}`. Note one PRD-specific caveat: at PRD time a brand-new standalone feature may have NO directory yet, so resolution is expected to fail for a never-started standalone feature — as `not-found` (exit 1) when `{specsDir}/` already exists (other features present), or as `specs dir not found` (exit 2) when `{specsDir}/` itself does not exist yet (the very first feature, or a branch that never had a specs tree). In **both** of those "about to create a brand-new standalone" cases forge-1 creates `{specsDir}/{feature}/` as today. (The *other* exit-2 errors — `unsafe-name`, a path-containment escape — are genuine STOPs, never a mint.) For an epic member the directory already exists (created empty by forge-0-epic with an `epic` back-pointer), so resolution succeeds and yields the nested path.
24
+
25
+ ### Mint Guard: refuse to fork a known epic member into a detached standalone (Issue #125)
26
+
27
+ Run this sub-step **whenever forge-1 is about to mint a brand-new flat standalone `{specsDir}/{feature}/`** — that is, when Feature Directory Resolution returned either `not-found` (exit 1) **or** `specs dir not found` (the exit-2 missing-specs-dir flavor, e.g. a clean default branch that has never had a specs tree). The exit-2 case is the *cleanest* split-brain trigger: on a branch that predates the epic, `{specsDir}/` may not exist at all, yet cross-branch discovery still sees the member on the epic branch. It prevents the split-brain-epic failure where a member of an epic (whose manifest lives on a *different, unmerged* branch) is silently forged as a disjoint standalone feature carrying no `epic` back-pointer. Skip it entirely when resolution succeeded (an epic member's directory already exists — resolution yields the nested path, so this never fires), on the other exit-2 errors (`unsafe-name` / path-containment — those STOP, they never mint), and when `--force-standalone` was passed (see below).
22
28
 
23
- If `.pipeline-state.json` exists for this feature and `forge-1-prd` is already marked complete, use `AskUserQuestion` to warn: "A PRD already exists for '{feature}'. Continuing will create a new version. Proceed?"
29
+ 1. Run cross-branch discovery for this exact name (branch-agnostic — it scans all refs regardless of current HEAD):
30
+ ```bash
31
+ R="$(bash -c 'for d in "${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')"
32
+ [ -n "$R" ] || { echo "feature-forge: cannot locate plugin root" >&2; exit 1; }
33
+ python3 "$R/scripts/forge-session.py" discover-feature "{feature}" --specs-dir "{specsDir}" --json
34
+ ```
35
+ 2. **If any candidate has `isEpicMember: true` → HARD STOP.** This is not the soft switch/fetch/treat-as-new menu from the Feature Directory Resolution block — do **not** create any directory and do **not** fall through to the interview. Emit verbatim (filling `{epic}` and `{stateBranch}` from that candidate's `epic` and `stateBranch`):
36
+ > `{feature}` is a member of epic `{epic}` (recorded on branch `{stateBranch}`). You appear to be on a branch that does not contain that epic. Switch to `{stateBranch}` and run `/feature-forge:forge-1-prd {feature}` there, or pass `--force-standalone` to intentionally fork a detached standalone feature.
37
+ 3. **If candidates exist but none are epic members** → keep today's soft behavior: this is the ordinary cross-branch-discovery case already handled by the Feature Directory Resolution block's **Candidates found** menu (switch / fetch+switch / treat-as-new / stop). Defer to it.
38
+ 4. **If nothing was found** (no candidates) → proceed to mint the flat standalone feature as today.
39
+ 5. **If `--force-standalone` was passed** → skip this guard entirely, log a one-line warning ("Forking `{feature}` as a detached standalone despite epic membership on `{stateBranch}`"), and proceed to create the flat feature. `--force-standalone` is distinct from `--force` and does **not** imply it (see the Force Mode note below).
40
+
41
+ After resolution, invoke the **Stage-Entry Guard** block in `references/shared-conventions.md` with `{stage}` = `forge-1-prd`. It classifies re-entry (fresh / interrupted / re-authoring), runs the resume-vs-restart gate and the "create a new version?" warning as applicable, and applies the entry stamp on the authoring paths. For a brand-new standalone feature there is no state file yet, so the guard's **fresh** arm applies with nothing to prompt; the entry stamp lands when the state file is first created in Step 6.
24
42
 
25
43
  ## Step 2: Examine Existing Context
26
44
 
@@ -19,6 +19,8 @@ Read and follow `references/shared-conventions.md` for feature name validation,
19
19
 
20
20
  **Prerequisite check:** Read `{resolvedFeatureDir}/.pipeline-state.json`. If not in force mode and `forge-1-prd` is not `complete`, STOP and tell the user: "The PRD for '{feature}' isn't complete yet. Run `/feature-forge:forge-1-prd {feature}` first."
21
21
 
22
+ After the prerequisite check, invoke the **Stage-Entry Guard** block in `references/shared-conventions.md` with `{stage}` = `forge-2-tech` — it detects an interrupted or already-complete tech-spec, runs the resume/restart or new-version gate, and stamps `status: "in-progress"` + `startedAt` + `currentStage` before the research and interview.
23
+
22
24
  Read `{resolvedFeatureDir}/PRD.md` into context. This is your foundation — every technology decision must trace back to a PRD requirement.
23
25
 
24
26
  After reading the PRD, invoke the **Epic Context Injection** block in `references/shared-conventions.md`. It self-gates on the resolved feature's `epic` back-pointer: for a standalone feature it is a no-op; for an epic member it loads EPIC.md, this feature's charter, and the completed direct dependencies' specs into context before the research and interview.
@@ -21,6 +21,8 @@ Read and follow `references/shared-conventions.md` for feature name validation,
21
21
 
22
22
  **Prerequisite check:** Read `{resolvedFeatureDir}/.pipeline-state.json`. If not in force mode, both `forge-1-prd` and `forge-2-tech` must be `complete`. If not, STOP and tell the user which prerequisites are missing.
23
23
 
24
+ After the prerequisite check, invoke the **Stage-Entry Guard** block in `references/shared-conventions.md` with `{stage}` = `forge-3-specs`. Because this stage writes a suite incrementally, the guard's **interrupted** arm uses the `stages.forge-3-specs.artifacts` array (already updated after each spec file — Step 3) to resume from the first unwritten document rather than regenerating the whole suite.
25
+
24
26
  Read both `{resolvedFeatureDir}/PRD.md` and `{resolvedFeatureDir}/tech-spec.md` into context.
25
27
 
26
28
  After reading the PRD and tech spec, invoke the **Epic Context Injection** block in `references/shared-conventions.md`. It self-gates on the resolved feature's `epic` back-pointer: for a standalone feature it is a no-op; for an epic member it loads EPIC.md, this feature's charter, and the completed direct dependencies' specs into context before the spec suite is planned.
@@ -56,7 +58,7 @@ Feature-specific:
56
58
 
57
59
  **Then call `AskUserQuestion`** following the **Decision Support** protocol in `references/shared-conventions.md`: recommend this plan as the default (it's your evidence-backed read of the feature's complexity) and name the trade-off so the user can push back knowingly — more documents means finer separation of concerns but more to keep in sync; fewer means tighter docs but risks one document carrying multiple concerns. Lead with: "I recommend this plan. Add or remove any documents?" Note the guidance below — resist splitting a concern into a sub-50-line document.
58
60
 
59
- **Incremental artifact tracking:** After each spec document is written (by you or a writer subagent), immediately update the `artifacts` array in `.pipeline-state.json` with the new file path. This enables crash recovery if the session is interrupted mid-suite (see shared-conventions.md "Crash Recovery").
61
+ **Incremental artifact tracking:** After each spec document is written (by you or a writer subagent), immediately update the `artifacts` array in `.pipeline-state.json` with the new file path. This enables crash recovery if the session is interrupted mid-suite (see shared-conventions.md "Stage-Entry Guard").
60
62
 
61
63
  ## Step 4: Write the Spec Suite
62
64
 
@@ -39,6 +39,10 @@ Resolve the **loop runner** from the `loopRunner` block in `forge.config.json`,
39
39
 
40
40
  **Prerequisite check:** Read `{resolvedFeatureDir}/.pipeline-state.json`. If not in force mode, stages `forge-1-prd`, `forge-2-tech`, and `forge-3-specs` must all be `complete`. If not, STOP and tell the user which prerequisites are missing.
41
41
 
42
+ After the prerequisite check, invoke the **Stage-Entry Guard** block in `references/shared-conventions.md` with `{stage}` = `forge-4-backlog` — it detects an interrupted or complete `backlog.json`, runs the resume/restart or new-version gate, and stamps entry before Step 2 loads the specs. (The backlog is a single artifact, so "resume" means: reuse the existing `backlog.json` if the previous run wrote it, rather than re-authoring from scratch.)
43
+
44
+ Then invoke the **Epic-Member Base Guard** block in `references/shared-conventions.md` (this stage does not run Epic Context Injection, so invoke it explicitly here). It self-gates to a no-op for standalone features; for a nested epic member on a branch that lacks the epic manifest it stops with a home-branch pointer (Issue #125).
45
+
42
46
  **Verification check.** Check whether the specs have been verified. If not, use `AskUserQuestion` to warn with the cost of skipping: "Specs haven't been verified yet. Recommended: run `/feature-forge:forge-verify {feature}` first — unverified specs can carry gaps or contradictions that get baked into backlog items and only surface mid-loop, where they're far more expensive to fix. Continue anyway?" Offer **Verify first (recommended)** · **Continue without verifying**.
43
47
 
44
48
  ## Step 2: Load All Specs
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feature-forge",
3
- "version": "0.12.5",
3
+ "version": "0.12.7",
4
4
  "agent": "codex",
5
5
  "generatedBy": "python3 scripts/build-adapters.py"
6
6
  }
@@ -159,6 +159,28 @@ python3 "$R/scripts/epic-manifest.py" \
159
159
 
160
160
  If `render-status` fails, proceed with **only** EPIC.md + charter (a corrupt manifest must not silently inject stale dep specs — REQ-ROBUST-02): on **exit 1**, parse the `{findings[]}` JSON from stdout and surface each; on **exit 2**, surface the plain `Error:` line from stderr verbatim. Do not attempt to parse findings JSON on an exit-2 failure (stdout is empty).
161
161
 
162
+ **After injecting context, invoke the Epic-Member Base Guard block below** (it self-gates to a no-op for standalone features and features that do not resolve as a nested member).
163
+
164
+ ## Epic-Member Base Guard
165
+
166
+ Defense-in-depth for the split-brain-epic failure (Issue #125). Invoke this block in the authoring stages (`forge-1-prd`..`forge-4-backlog`) once the feature has resolved — right after **Epic Context Injection** for the stages that run it (`forge-1-prd`..`forge-3-specs`), and right after **Feature Directory Resolution** for `forge-4-backlog`. It confirms that a **resolved nested epic member** actually sits on a branch that contains the epic's manifest. Without this, a member reached from a branch cut *before* the epic-manifest commit (or that otherwise lacks it) would author specs against an epic decomposition that is not present — the exact drift that produces a disjoint, split-brain member. **Skip if not a git repo or `branchPerFeature` is false.**
167
+
168
+ ```bash
169
+ R="$(bash -c 'for d in "${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')"
170
+ [ -n "$R" ] || { echo "feature-forge: cannot locate plugin root" >&2; exit 1; }
171
+ python3 "$R/scripts/forge-session.py" check-epic-base --feature "{feature}" --specs-dir "{specsDir}" --json
172
+ ```
173
+
174
+ Act on the emitted `action`:
175
+ - **`none`** — a standalone feature (no epic to check) or the manifest is present on the current branch. Proceed silently. This is the no-op path for standalone features (REQ-COMPAT-01), so standalone behavior is unchanged.
176
+ - **`not-resolved`** — the feature does not resolve on the current branch. Proceed silently (the caller's own resolution already handled that case).
177
+ - **`warn-detached-base`** — a nested member resolves here but the epic's `epic-manifest.json` is **absent on this branch**. **STOP** unless `--force` was passed, and surface verbatim (filling `{epic}` and `{homeBranch}` from the payload's `epic` and `homeBranch`):
178
+ > `{feature}` is a member of epic `{epic}`, but this branch does not contain the epic manifest (`{specsDir}/{epic}/epic-manifest.json`). This base predates or lacks the epic. Switch to the epic's home branch `{homeBranch}` and re-run, or pass `--force` to author against a detached base anyway.
179
+
180
+ With `--force`, log a one-line warning ("Authoring `{feature}` against a detached epic base — manifest not on this branch") and proceed, consistent with the other guards.
181
+
182
+ If the helper is unavailable (a non-Claude host without the resolver), skip this block — it is best-effort defense in depth, not a hard prerequisite.
183
+
162
184
  ## Pipeline State Protocol
163
185
 
164
186
  Write pipeline state conforming to `references/pipeline-state-schema.json`. Always update `updatedAt` when modifying pipeline state.
@@ -226,17 +248,31 @@ When `gitCommitAfterStage` is true, follow this exact order to avoid state incon
226
248
  - **Nothing to commit:** If all artifacts were already committed, this is fine — mark the stage `complete`, leave `commitHash` at its existing value (or `null` if there was never an artifact commit), and skip Commit 2. There is no new artifact commit to record.
227
249
  5. **Never** use `git add -A`, `--amend`, `--no-verify`, or `--force` flags
228
250
 
229
- ## Crash Recovery
251
+ ## Stage-Entry Guard
252
+
253
+ Invoke this block at the **start of an authoring stage** (`forge-1-prd`..`forge-4-backlog`), **after** Feature Directory Resolution and **before** any interview or (re-)authoring. It prevents a re-entered stage — an injected skill body or a re-invoked `Skill` — from blindly re-running the interview over an in-progress or already-complete draft. `{stage}` is the invoking skill's id (e.g. `forge-2-tech`).
254
+
255
+ **Read, then classify** this stage's entry in `{resolvedFeatureDir}/.pipeline-state.json` (`stages.{stage}.status`):
256
+
257
+ 1. **Fresh** — no state file yet, or `stages.{stage}` is absent/`pending`. First run of this stage. Proceed to the **Entry Stamp** below, then author normally. No prompt.
258
+
259
+ 2. **Interrupted** (`status: "in-progress"`) — a previous run of THIS stage was interrupted before it committed (the exit commit is what flips it to `complete`, so `in-progress` on entry always means a crash/abandon). Do **not** silently re-author. Instead:
260
+ - **Inventory on-disk artifacts:** list the files this stage produces that already exist in `{resolvedFeatureDir}/` (e.g. `PRD.md`; `tech-spec.md`; the `##-*.md` suite + `TRACEABILITY.md`; `backlog.json`), and cross-check against the `stages.{stage}.artifacts` array (written incrementally during the previous run).
261
+ - **Gate via `AskUserQuestion`** (Decision Support protocol): present the inventory as text, then ask "This {stage} run was interrupted — {N} artifact(s) from the previous run are on disk: {list}. Resume the in-progress draft, or start a new version from scratch?" Options: **Resume (recommended)** — continue from the first artifact not yet written/complete, reusing the existing files; do **not** re-stamp or bump the version. · **Start a new version** — treat it as a fresh authoring pass (proceed to the Entry Stamp; the version increments at exit).
262
+ - Skip artifact regeneration for files that already exist and are complete (non-empty, properly structured); continue from the next unwritten artifact.
263
+
264
+ 3. **Re-authoring** (`status: "complete"` or `"stale"`) — a finished draft exists. Warn via `AskUserQuestion` before overwriting: "A completed {stage} artifact already exists for '{feature}' (v{n}{, marked stale}). Continuing will create a new version. Proceed?" On confirm, proceed to the Entry Stamp and author a new version (the version increments at exit, per that stage's Update-Pipeline-State step).
265
+
266
+ **Entry Stamp** (fresh, restart, and re-author paths — NOT the resume path). Before authoring, write to `{resolvedFeatureDir}/.pipeline-state.json` and update `updatedAt`:
267
+ - `stages.{stage}.status` → `"in-progress"`
268
+ - `stages.{stage}.startedAt` → current ISO-8601 UTC timestamp
269
+ - top-level `currentStage` → `"{stage}"` (where the pipeline IS, per O1)
230
270
 
231
- When a skill detects that `currentStage` matches itself and the stage status is `in-progress`, a previous run was interrupted. Follow this recovery protocol:
271
+ This write is **left uncommitted**: it is staged and committed as part of this stage's existing exit commit (Git Commit Protocol), so no extra commit is needed at entry. If the run is interrupted after the stamp but before the exit commit, the marker survives on disk (uncommitted) and the next entry classifies as **Interrupted** — which is exactly the intent.
232
272
 
233
- 1. **Inventory existing artifacts:** List all files on disk in `{specsDir}/{feature}/` that this stage would produce
234
- 2. **Compare against state:** Check the `artifacts` array in the pipeline state for this stage — it tracks files written incrementally during the previous run
235
- 3. **Present options to user:** "This stage was interrupted. Found {N} artifacts from the previous run: {list}. Would you like to resume from where it left off, or restart the stage from scratch?"
236
- 4. **If resume:** Skip artifact generation for files that already exist and appear complete (non-empty, properly structured). Continue from the next unwritten artifact.
237
- 5. **If restart:** Proceed normally. The version number will increment.
273
+ **Force Mode.** When `--force` is passed, skip the interactive gate: do not prompt for resume-vs-restart or the re-author warning. Treat entry as a fresh restart — apply the Entry Stamp and author. (`--force` already skips prerequisite checks; here it likewise bypasses the self-stage gate. Existing on-disk artifacts are still loaded per Force Mode.)
238
274
 
239
- **Incremental artifact tracking:** When a stage writes multiple files (e.g., forge-3-specs writing a suite of spec documents), update the `artifacts` array in `.pipeline-state.json` after writing each file — not just at stage completion. This ensures crash recovery knows exactly which files were successfully written.
275
+ **Incremental artifact tracking:** When a stage writes multiple files (e.g. forge-3-specs writing a suite of spec documents), update the `stages.{stage}.artifacts` array in `.pipeline-state.json` after writing each file — not just at stage completion. This is what makes the Interrupted inventory above precise about which files were successfully written.
240
276
 
241
277
  ## Force Mode
242
278