bmad-module-ultracode-goal 2.0.0 → 2.2.0

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 (43) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/README.md +5 -5
  3. package/docs/404.md +1 -1
  4. package/docs/_internal/STABILITY.md +13 -9
  5. package/docs/architecture.md +17 -12
  6. package/docs/comparison.md +19 -11
  7. package/docs/gate-model.md +24 -0
  8. package/docs/getting-started.md +1 -1
  9. package/docs/how-it-works.md +3 -3
  10. package/docs/index.md +0 -1
  11. package/docs/operating-tips.md +4 -2
  12. package/docs/troubleshooting.md +9 -5
  13. package/docs/why-ultracode-goal.md +1 -1
  14. package/package.json +5 -4
  15. package/skills/ucg-formalize/SKILL.md +136 -39
  16. package/skills/ucg-resolve/SKILL.md +86 -58
  17. package/skills/ucg-status/SKILL.md +64 -30
  18. package/skills/ultracode-goal/SKILL.md +9 -11
  19. package/skills/ultracode-goal/assets/module-help.csv +1 -1
  20. package/skills/ultracode-goal/assets/module.yaml +8 -3
  21. package/skills/ultracode-goal/assets/ucg-awareness/bmad-testarch-test-design.toml +8 -0
  22. package/skills/ultracode-goal/customize.toml +12 -7
  23. package/skills/ultracode-goal/references/define-done.md +3 -3
  24. package/skills/ultracode-goal/references/execute.md +40 -53
  25. package/skills/ultracode-goal/references/finalize.md +12 -12
  26. package/skills/ultracode-goal/references/gate.md +42 -11
  27. package/skills/ultracode-goal/references/health-check.md +7 -4
  28. package/skills/ultracode-goal/references/ingest-and-scope.md +4 -4
  29. package/skills/ultracode-goal/references/preflight.md +10 -9
  30. package/skills/ultracode-goal/scripts/gate_eval.py +684 -39
  31. package/skills/ultracode-goal/scripts/gate_trail.py +131 -32
  32. package/skills/ultracode-goal/scripts/health_check_fp.py +98 -3
  33. package/skills/ultracode-goal/scripts/hooks/guard_pretooluse.py +56 -14
  34. package/skills/ultracode-goal/scripts/mem_observation.py +48 -10
  35. package/skills/ultracode-goal/scripts/mutate_check.py +353 -0
  36. package/skills/ultracode-goal/scripts/preflight_check.py +397 -3
  37. package/skills/ultracode-goal/scripts/status_render.py +20 -2
  38. package/skills/ultracode-goal/scripts/story_sizing.py +193 -0
  39. package/tools/build-docs.js +24 -1
  40. package/tools/validate-docs-links.js +169 -8
  41. package/website/astro.config.mjs +0 -1
  42. package/docs/parallel-mode.md +0 -68
  43. package/skills/ultracode-goal/assets/execute-epic.workflow.js +0 -249
@@ -13,6 +13,16 @@ The gate reads artifacts TEA produces. In **production**, before running the gat
13
13
 
14
14
  `bmad-testarch-nfr` (produces `nfr-assessment.md`) and `bmad-testarch-test-review` are independent — of each other *and* of the automate→trace chain — so run them in any order, or concurrently with it; `gate_eval.py` consumes all three artifacts without caring how they were produced. (`bmad-testarch-test-review` normally runs in Execute per story — run it here only if you lack a current `test-review.md` for the story.) In **`--light`**, skip all of the above and run only `bmad-testarch-trace`, then the gate with `--profile light` (trace gate only — no NFR/review AND).
15
15
 
16
+ ## Measure the commit, not the working tree
17
+
18
+ Stage 5's subject is a COMMIT, but an assessor that runs or times anything by default measures the WORKING TREE — which is where the next remediation, or a sibling assessor's mutation window, happens. A measured run recorded the consequence three times in one story even under a strict no-concurrent-work rule: one assessor's mutation window contaminated a sibling's timing run (discarded and re-run), and two assessors invented their own ad hoc isolation mid-gate because they could not trust the shared tree. Make the isolation structural instead of a discipline each assessor re-derives: create a worktree of the commit under assessment — `git worktree add <tmp-path> <commit>`, with `<tmp-path>` under `{workflow.implementation_artifacts}/.gate-worktree-<story_id>` (the same containment Execute's scratch rule buys; never an improvised repo-root directory) — and point every assessor's reads, runs and measurements THERE. Their OUTPUTS go home: every artifact an assessor writes — trace report, gate decision, NFR assessment, test review, `bmad-testarch-automate`'s backfilled coverage — lands in the MAIN tree's resolved dirs (`{workflow.trace_output_dir}`, `{workflow.implementation_artifacts}`, resolved to absolute paths against `{project-root}` BEFORE any assessor is pointed at the worktree), never under the worktree. The worktree is the measurement surface, the main tree is the record — an artifact written into the worktree is destroyed with it, after which the gate re-reads the PREVIOUS cycle's same-named artifact as current (resolution is by name, with no freshness check), which is a stale PASS advancing a story whose fresh assessment was never read. Once the story's verdict is recorded, remove the worktree with `git worktree remove --force <tmp-path>` — the copied-in untracked inputs below make the unforced form refuse, and a measurement surface holds nothing to preserve — then `git worktree prune`; a resume that finds a dead session's stale `.gate-worktree-<story_id>` removes it the same way before creating its own. A step that only authors an artifact from already-recorded evidence has nothing to measure and needs no worktree; the rule binds every assessor that runs or times anything. Three caveats the setup owes, each a measured failure when skipped:
19
+
20
+ - **Dependency directories do not follow the commit.** A worktree carries tracked files only, so an installed dependency tree (`node_modules` and its kin) is absent there. Symlink each such directory the repo has (root *and* nested) from the main tree into the worktree — and prefer the symlink over resolver environment variables: Node's ESM resolver ignores `NODE_PATH` (it is honoured by the CJS resolver only), so a `NODE_PATH` bridge quietly breaks exactly the modern half of a JS gate set. Where a symlink cannot serve, an offline install from the package manager's shared store is the fallback; measure both once per repo before committing to one.
21
+ - **Untracked inputs the gate set reads.** A scratch browser config, an env file, a generated fixture: enumerate what the declared gate commands actually read that the commit does not carry, and copy those in deliberately — an isolated gate that silently lost its config measures a different harness and reports the result as this one's.
22
+ - **The ordering rule stands.** Isolation removes the contamination, not the sequence: the run still gates story N to a verdict before touching story N+1 (the sequential spine is unchanged), so this section licenses no overlap. What it buys today is that no assessor can contaminate another's measurement and no stray tree state can contaminate a gate mid-read.
23
+
24
+ Record in `.decision-log.md`, once per gated story, whether the gate measured a worktree or the main tree — the same honesty line the sweep's `scope=` carries: an assessment reported as isolated that actually ran on the shared tree is a false claim about the evidence.
25
+
16
26
  ## Non-web stack (web-only TEA chain): author the deterministic trace artifacts
17
27
 
18
28
  When the module's TEA chain is web-only, `bmad-testarch-trace` cannot run on a non-web stack and so cannot emit the binding gate decision. Do **not** reverse-engineer a prior run's leftover artifacts — author the two files to the exact shape `scripts/gate_eval.py` reads; every other field in real TEA output (`target`, `links`/`trace_report_path`, `rationale`, `schema_version`) is decoration the reader never touches. **Name all four for the story** — `trace-<id>.md`, `gate-decision-<id>.json`, and on the production path `nfr-assessment-<id>.md` and `test-review-<id>.md`. The first pair must be per-story because `--story <id>` scoping resolves them by name in a shared `--trace-output` dir. The second pair binds nothing mechanically (the `--nfr` / `--test-review` flags take an explicit path), which is exactly why it needs stating: unnamed, each story's NFR and review overwrite the last one's in that shared directory, and the audit trail keeps only whichever story finished most recently.
@@ -22,10 +32,12 @@ When the module's TEA chain is web-only, `bmad-testarch-trace` cannot run on a n
22
32
  ```yaml
23
33
  ---
24
34
  workflowType: testarch-trace # must be 'testarch-trace' or 'trace', else the report is skipped
25
- gateDecisionFile: gate-decision-<id>.json # the slim file to read; relative to --trace-output (absolute honored)
35
+ gateDecisionFile: gate-decision-<id>.json # the slim file to read; a bare filename in --trace-output
26
36
  ---
27
37
  ```
28
38
 
39
+ **The hint is bounded, and a hint it refuses is not fatal.** `gateDecisionFile` must name a file sitting **directly in `--trace-output`**: a bare filename, never a subdirectory, never a `..` path and never an absolute path (a hint that resolves outside the artifact directory is ignored, because a gate read from outside the directory the run was pointed at is not this run's gate). When the hint carries a story id it must be **this** story's; when it carries none, it is honoured only where no other story's artifact is present. A refused hint does not fail the story on its own: resolution continues to `gate-decision-<story_id>.json` and then to the same fail-closed rule an artifact-less story gets.
40
+
29
41
  **`gate-decision-<id>.json`** — the slim file the hint points at. `gate_eval.py` reads only these four keys; `gate_status` alone drives the `--light` verdict (PASS/WAIVED → advance, CONCERNS → defer, FAIL → reloop, NOT_EVALUATED → escalate), the other three are passed through into the verdict JSON / `.decision-log.md`:
30
42
 
31
43
  ```json
@@ -34,7 +46,19 @@ gateDecisionFile: gate-decision-<id>.json # the slim file to read; relative to -
34
46
 
35
47
  Write a PASS only when the story is demonstrably done to its profile's Definition-of-Done (under `--light`: acceptance criteria satisfied with lint and build green; under production the bar is higher — also un-skipped passing acceptance tests plus test-review/code-review, per the profile note below — see `references/define-done.md`); a non-green story is `reloop`/`escalate`, never a hand-authored PASS (see the INVARIANT in "Route on the verdict"). `p0_status`/`p1_status`/`overall_status` are passthrough-only here — they do not drive the `--light` verdict, so write them to reflect reality, never to dress up a non-green story. If you instead write the always-present `e2e-trace-summary.json`, the reader takes its top-level `gate_status` and the nested `gate_criteria.{p0_status,p1_status,overall_status}` — the same fields one level down.
36
48
 
37
- **Which profile's gate you then run.** The hand-authored trace decision above is the same file for either profile; only what you AND onto it differs. Under **`--light`** it *is* the whole gate — run `gate_eval.py --profile light` (below) and stop. Under **production** — the legitimate case when an operator scopes foundational, non-web packages to the full chain — the production ANDs still apply. TEA's *browser* generators are what a non-web stack cannot run as-is: ATDD in Stage 3 and the automate→trace pair here. So the story's acceptance tests are authored and driven in the stack's own harness (the Vitest case) and reach the production Definition-of-Done un-skipped and passing, and you hand-author the trace decision above in place of automate→trace. **Where ATDD cannot generate the `test.skip()` scaffold, the red phase is established BY HAND, and it must still be established.** Author the acceptance cases with real assertions, RUN them before the first implementation edit, capture that run's raw output to a file under `{workflow.implementation_artifacts}`, and record in the trace report both the red count and a one-line justification for every case that was already green. This section otherwise rules the artifacts thoroughly and the acceptance-test BAR ("un-skipped and passing") while saying nothing about how un-skipped is reached from a red start — so a run that skipped the red phase entirely satisfies every other sentence here. **A case nobody ever saw fail is not evidence**, and a hand-authored PASS resting on one is the same dishonesty the hand-authored-PASS rule above forbids. **Whichever profile you land in, this path is `gate-provenance: hand-authored`** — log it per story exactly as "Run the gate" below requires, because a run that takes this branch on every row produces an Epic whose every verdict rests on a file the run wrote for itself, and nothing else in the artifacts would say so. `bmad-testarch-nfr` and `bmad-testarch-test-review` are independent of that browser pair (see "Backfill the gate evidence" above), so still produce `nfr-assessment.md` and `test-review.md` the normal way and run `gate_eval.py --profile production --story <story_id> --nfr <…/nfr-assessment-<story_id>.md> --test-review <…/test-review-<story_id>.md>`. Pass **both** flags. `gate_eval.py` fail-closes a `--nfr`/`--test-review` path that is given-but-missing **and one you simply omit**: an omitted flag on a per-story production gate is itself a failing signal, with a reason naming the flag. That is deliberate — a forgotten flag used to be skipped in silence, so the AND never ran, the field rendered `null`, and the verdict was computed without it, which bought a *higher* verdict than supplying a failing artifact would have. If a signal genuinely cannot be produced on the stack, that is a CONCERNS/`defer` or a `reloop`, never a dropped flag. The one legitimate omission is the epic roll-up, which declares itself with `--epic-level` (see "Route on the verdict") rather than by leaving the flags off. A stack that cannot meet the production acceptance-test bar at all belongs under `--light` (see the framework fitness caveat in `references/preflight.md`), not a hand-waved production PASS. The honesty bar is unchanged: a PASS requires full AC coverage by passing tests, never to dodge an AND.
49
+ **Which profile's gate you then run.** The hand-authored trace decision above is the same file for either profile; only what you AND onto it differs. Under **`--light`** it *is* the whole gate — run `gate_eval.py --profile light` (below) and stop. Under **production** — the legitimate case when an operator scopes foundational, non-web packages to the full chain — the production ANDs still apply. TEA's *browser* generators are what a non-web stack cannot run as-is: ATDD in Stage 3 and the automate→trace pair here. So the story's acceptance tests are authored and driven in the stack's own harness (the Vitest case) and reach the production Definition-of-Done un-skipped and passing, and you hand-author the trace decision above in place of automate→trace.
50
+
51
+ **A production story on this path owes five deliverables.** (A `--light` story owes two of them — items 1 and 5: the trace decision *is* its whole gate, and provenance is logged whichever profile you land in.) Each is independently checkable and each has been independently dropped by a run that complied with the rest — so they are numbered rather than prosed, and a production story is done with this section only when all five exist:
52
+
53
+ 1. **The hand-authored trace decision** — the two files above, in place of automate→trace.
54
+ 2. **The red phase is established BY HAND, and it must still be established.** Where ATDD cannot generate the `test.skip()` scaffold: author the acceptance cases with real assertions and RUN them before the first implementation edit — the window this rule governs closes in Stage 4, which is why `references/execute.md` step 1 states the same obligation where the first-edit decision is actually made. This section otherwise rules the artifacts thoroughly and the acceptance-test BAR ("un-skipped and passing") while saying nothing about how un-skipped is reached from a red start — so a run that skipped the red phase entirely satisfies every other sentence here. **A case nobody ever saw fail is not evidence**, and a hand-authored PASS resting on one is the same dishonesty the hand-authored-PASS rule above forbids.
55
+ 3. **Capture that run's raw output to a file** under `{workflow.implementation_artifacts}`. An independent deliverable, not a detail of item 2: the capture is what makes the red phase auditable after the fact, and it cannot be honestly re-made once the implementation lands — a run that ran the red phase and read the result but captured nothing holds strictly weaker evidence than this item asks for, and a labelled transcription is the most it can honestly write.
56
+ 4. **The red count recorded in the trace report, with a one-line justification for every case that was already green.** Where a shared acceptance file accumulates already-shipped siblings' cases, those green-by-design cases may be justified as one line naming that class rather than case-by-case — the per-case justification owed is for THIS story's cases that never went red.
57
+ 5. **`gate-provenance: hand-authored`, logged per story** exactly as "Run the gate" below requires — a run that takes this branch on every row produces an Epic whose every verdict rests on a file the run wrote for itself, and nothing else in the artifacts would say so.
58
+
59
+ `bmad-testarch-nfr` and `bmad-testarch-test-review` are independent of that browser pair (see "Backfill the gate evidence" above), so still produce `nfr-assessment.md` and `test-review.md` the normal way and run `gate_eval.py --profile production --story <story_id> --nfr <…/nfr-assessment-<story_id>.md> --test-review <…/test-review-<story_id>.md> --tests-ran {workflow.implementation_artifacts}/.tests-ran-<story_id>`. Pass **both** signal flags (and `--tests-ran`, which every per-story gate carries — the sweep-scope AND binds this path unchanged). `gate_eval.py` fail-closes a `--nfr`/`--test-review` path that is given-but-missing **and one you simply omit**: an omitted flag on a per-story production gate is itself a failing signal, with a reason naming the flag. That is deliberate — a forgotten flag used to be skipped in silence, so the AND never ran, the field rendered `null`, and the verdict was computed without it, which bought a *higher* verdict than supplying a failing artifact would have. If a signal genuinely cannot be produced on the stack, that is a CONCERNS/`defer` or a `reloop`, never a dropped flag. The one legitimate omission is the epic roll-up, which declares itself with `--epic-level` (see "Route on the verdict") rather than by leaving the flags off. A stack that cannot meet the production acceptance-test bar at all belongs under `--light` (see the framework fitness caveat in `references/preflight.md`), not a hand-waved production PASS. The honesty bar is unchanged: a PASS requires full AC coverage by passing tests, never to dodge an AND.
60
+
61
+ **The epic-level roll-up needs no hand-authoring at all where sprint-status is available: run it with `--rollup`** (see "Route on the verdict"), which computes the aggregate from the per-story artifacts this section already had you author — no `trace-<epic>.md` required. Hand-author the epic pair only where the gate cannot be given sprint-status. **In that fallback the roll-up needs the same hand-authoring, named for the EPIC.** Everything above is written per story, and on this stack TEA never runs — so nothing ever writes the epic's own `trace-<epic>.md`, while the omit-`--rollup` form of the gate below presumes it exists: `--story <epic_id>` in a per-story-named directory resolves nothing and fail-closes a completed Epic to `escalate`. When every story is `done`, hand-author the same two files named for the epic id — `trace-<epic>.md`, its frontmatter pointing at `gate-decision-<epic>.json` — with a `gate_status` that honestly summarises the per-story record: a PASS only when every story advanced, never a roll-up dressed over a story that did not. It takes no NFR and no test-review; the roll-up declares that omission with `--epic-level`, per "Route on the verdict" below.
38
62
 
39
63
  **Hand-authored `nfr-assessment.md` and `test-review.md` shapes (production path only).** `gate_eval.py` scans these two files with the *same* parser it uses on real TEA output, so a hand- or agent-authored file must carry the exact fields below — otherwise the scanner reads the signal as *not found* and, under the fail-closed contract, treats it as **failing**, spuriously downgrading an `advance` to `reloop`. (Under `--light` neither file is read, so this whole block is production-only.) Only the named field is parsed; everything else is human prose.
40
64
 
@@ -60,18 +84,18 @@ The score **must** carry the `/100` denominator: a bare `score: 89` matches noth
60
84
  Production:
61
85
 
62
86
  ```
63
- uv run {skill-root}/scripts/gate_eval.py --trace-output {workflow.trace_output_dir} --story <story_id> --profile production --nfr {nfr-assessment.md} --test-review {test-review.md}
87
+ uv run {skill-root}/scripts/gate_eval.py --trace-output {workflow.trace_output_dir} --story <story_id> --profile production --nfr {nfr-assessment.md} --test-review {test-review.md} --tests-ran {workflow.implementation_artifacts}/.tests-ran-<story_id>
64
88
  ```
65
89
 
66
90
  Light:
67
91
 
68
92
  ```
69
- uv run {skill-root}/scripts/gate_eval.py --trace-output {workflow.trace_output_dir} --story <story_id> --profile light
93
+ uv run {skill-root}/scripts/gate_eval.py --trace-output {workflow.trace_output_dir} --story <story_id> --profile light --tests-ran {workflow.implementation_artifacts}/.tests-ran-<story_id>
70
94
  ```
71
95
 
72
96
  Resolve `{nfr-assessment.md}` and `{test-review.md}` to the paths TEA wrote them to (under `{workflow.trace_output_dir}` or the TEA output root); pass the production-only flags only in production. The script reads `gate-decision.json` (resolving its filename from the trace report frontmatter, falling back to the `e2e-trace-summary.json` gate fields when the slim file is absent — that fallback is **not** a failure).
73
97
 
74
- **`--story` in a shared multi-story trace dir.** When every story in a multi-story Epic writes a per-story-named trace report + gate decision (`trace-<id>.md`, `gate-decision-<id>.json`) into the **one** shared `{workflow.trace_output_dir}`, an unscoped read resolves the first/oldest story's gate — a false verdict for every later story. Pass `--story <story_id>` (the id of the story you are gating) so resolution is scoped to that story's artifacts; matching is on id components (`11-6` == `11.6` == `11_6`) anchored to the trailing components, so epic id `1` resolves `trace-1` and never the child story `1-1`'s report. For the **epic-level** gate after the last story, pass the epic's own id the same way (it resolves the epic's `trace-<epic>` report, not any child story). **`--story` fails closed on a genuine no-match — this is a behaviour change.** It used to fall back to the unscoped read whenever nothing matched, which meant a story that wrote *no* artifacts at all silently reported a NEIGHBOURING story's gate as its own: an unevaluated story could read `PASS`/`advance`. Now the fallback depends on how the directory is **named**. If any trace report or gate-decision file there carries a trailing numeric id in its name (`trace-2-1.md`, `gate-decision-4.json` — i.e. the dir is per-story-named), a `--story` that matches nothing means that story is genuinely absent, and the read returns `gate_status: NOT_EVALUATED` -> `escalate`, with a reason naming the story. If instead every candidate is generically named (`trace.md`, `gate-decision.json`), the directory holds one story's artifacts and the documented unscoped fallback still applies, so passing `--story` against a single-story dir resolves exactly as before. `--story` remains optional; omit it only when `{workflow.trace_output_dir}` provably holds a single story's artifacts. If you were relying on the old silent fallback in a per-story-named dir, you will now get an `escalate` instead of a verdict — which is the point: it surfaces a story whose gate was never produced. The experimental `--parallel` workflow (`assets/execute-epic.workflow.js`) shares one `trace_output` across its worktree agents too, so it now passes `--story` per story automatically. If your TEA build does not name artifacts per story, isolate the current story's `trace-*.md` + `gate-decision*.json` into a fresh dir and point `--trace-output` there instead. It returns JSON:
98
+ **`--story` in a shared multi-story trace dir.** When every story in a multi-story Epic writes a per-story-named trace report + gate decision (`trace-<id>.md`, `gate-decision-<id>.json`) into the **one** shared `{workflow.trace_output_dir}`, an unscoped read resolves the first/oldest story's gate — a false verdict for every later story. Pass `--story <story_id>` (the id of the story you are gating) so resolution is scoped to that story's artifacts; matching is on id components (`11-6` == `11.6` == `11_6`) anchored to the trailing components, so epic id `1` resolves `trace-1` and never the child story `1-1`'s report. **`<story_id>` is ONE string, used byte-identically in three places:** the story's `sprint-status.yaml` key, the `<id>` in the artifact filenames above (`trace-<id>.md`, `gate-decision-<id>.json`, and the same `<id>` in the per-story NFR and test-review names the non-web section below pins), and this `--story` argument. Copy the key verbatim, whether it is bare (`4-2`) or carries a kebab title slug (`4-2-<kebab-title>`); do not abbreviate it to its number when invoking, and do not expand it when naming. When TEA authored the files, take the id portion of the stem it actually wrote and pass that. **A mismatch fails in both directions**: `--story 4-2-<kebab-title>` resolves `gate-decision-4-2-<kebab-title>.json` and *not* `gate-decision-4-2.json`, and `--story 4-2` resolves neither. The tolerance is deliberately no wider than this — matching is anchored to the trailing components on purpose, because a prefix match would let epic id `4` resolve `trace-4-2-<kebab-title>.md` and hand the epic roll-up a child story's verdict, which is the fail-open the anchor exists to close. **Recognise the symptom:** a spelling mismatch surfaces as `gate_status: NOT_EVALUATED` -> `escalate`, worded identically to a story that genuinely wrote nothing, so before treating that `escalate` as a real block, list `{workflow.trace_output_dir}` and compare the exact stem. For the **epic-level** gate after the last story, pass the epic's own id the same way (it resolves the epic's `trace-<epic>` report, not any child story). **`--story` fails closed on a genuine no-match — this is a behaviour change.** It used to fall back to the unscoped read whenever nothing matched, which meant a story that wrote *no* artifacts at all silently reported a NEIGHBOURING story's gate as its own: an unevaluated story could read `PASS`/`advance`. Now the fallback depends on how the directory is **named**. If any artifact there is named for a story, a `--story` that matches nothing means that story is genuinely absent, and the read returns `gate_status: NOT_EVALUATED` -> `escalate`, with a reason naming the artifact KIND that made the directory per-story-named (never a neighbour's filename — quoting one in an absent story's verdict is the very fail-open this branch closes). **"Named for a story" is wider than the two gate-bearing files, and the test is not "ends in a number".** Seven prefixes count — `gate-decision`, `e2e-trace-summary`, `nfr-assessment`, `test-review`, `traceability-matrix`, `trace`, `atdd-checklist` — and the rule is that the component **immediately after the prefix starts with a digit**, so `trace-92-0a.md` and `trace-5-8-some-slug.md` both count even though neither ends in a number. Two consequences worth holding: a per-story NFR assessment or test review, alone, flips the directory per-story-named on its own even with no trace or gate file beside it — and those are artifacts the non-web section below orders into this same directory; and an id whose first component is not a digit (`trace-st-5.md`) does not flip it, which is one more reason the isolated-track rule requires a numeric epic prefix. If instead every candidate is generically named (`trace.md`, `gate-decision.json`), the directory holds one story's artifacts and the documented unscoped fallback still applies, so passing `--story` against a single-story dir resolves exactly as before. `--story` remains optional; omit it only when `{workflow.trace_output_dir}` provably holds a single story's artifacts. If you were relying on the old silent fallback in a per-story-named dir, you will now get an `escalate` instead of a verdict — which is the point: it surfaces a story whose gate was never produced. If your TEA build does not name artifacts per story, isolate the current story's `trace-*.md` + `gate-decision*.json` into a fresh dir and point `--trace-output` there instead. It returns JSON:
75
99
 
76
100
  ```json
77
101
  {"verdict": "advance|defer|reloop|escalate",
@@ -82,23 +106,29 @@ Resolve `{nfr-assessment.md}` and `{test-review.md}` to the paths TEA wrote them
82
106
 
83
107
  Do not recompute TEA thresholds or re-judge `gate_status` — read it as given. The script already ANDs the production signals (an `advance` is downgraded to `reloop` if `nfr-assessment.md` overallStatus is FAIL, or `test-review.md` score < 80 or recommendation is Block). Record the full verdict JSON and its `reasons` in `.decision-log.md` for this story.
84
108
 
85
- **Record who authored the artifacts the verdict rests on.** Alongside that JSON, log one line naming the provenance of this story's `trace-<id>.md` / `gate-decision-<id>.json`: **`gate-provenance: tea`** when `bmad-testarch-trace` wrote them, or **`gate-provenance: hand-authored`** when the non-web section above did. This is not bookkeeping. The module's central non-negotiable is that completion is decided by a script reading TEA's artifact rather than by the model's judgment, and on the hand-authored path the model *writes the file the gate then reads* — a defensible substitution the non-web section sanctions, but one that is otherwise **indistinguishable** in the decision log and the run report from a verdict grounded in a TEA-authored gate. An Epic can run to completion entirely on the hand-authored path, story after story, with nothing anywhere recording that it did. Provenance is what keeps "the JSON is the truth" honest about *whose* JSON it was; it changes no verdict and gates nothing.
109
+ **The sweep-scope AND (`--tests-ran`, per-story gates, both profiles).** Pass `--tests-ran {workflow.implementation_artifacts}/.tests-ran-<story_id>` on every per-story gate, exactly as the commands above show. The script reads the marker's `scope=` line (`references/execute.md` steps 2 and 5 write it beside `baseline=`): `scope=full` asserts the green run behind this gate was the full three-axis sweep and passes the verdict through; `scope=scoped` is legitimate mid-loop evidence, so the verdict is **capped at `reloop`** — a story may only advance off a full-scope sweep, and the cap moves `defer` too, because defer's route advances the story. Fail-closed like every other signal: a missing marker, a marker with no `scope=` line, or a value the reader does not recognise all get the same cap, with a reason naming what was wrong. The verdict JSON carries the recognised value as `sweep_scope` so an advance that proved its sweep is distinguishable from one that was never asked. Two boundaries: the epic roll-up gates no sweep of its own, so `--epic-level` refuses the flag outright (an invocation error, exit 2 — the same lane as `--epic-level` with `--nfr`); and *omitting* the flag skips the check rather than failing it, deliberately — making omission failing would change the verdict of documented invocations that predate the flag, the exact 2.0.0 lesson `docs/_internal/STABILITY.md` records — so the always-pass-it rule lives here, in the instruction, and a per-story gate invoked without the flag is a drift to fix, not a laxer mode to use.
110
+
111
+ **The delta cycle profile (`--cycle-profile`, mid-loop gates, production).** A gate whose previous evaluation of this story was `reloop` with findings cleanly attributed to their assessor dimension may re-run as a **delta gate**: re-run in full only the assessor(s) whose dimension produced the failing findings, while the others verify their own prior artifact against the diff from the previous gate's `assessed-commit` line to the commit under assessment (a concerns-only re-check; a previous verdict record without that line means the fallback below — run the full gate) instead of re-deriving the story from zero. Declare it — pass `--cycle-profile delta` — and the script caps the verdict at `reloop`: a delta gate may say "not yet, and here is why", never `advance` or `defer`. ADVANCE requires the full instrument (every assessor, over a `scope=full` sweep), exactly as before, so the oracle's finality is untouched, and a delta cycle whose findings all close costs one extra full gate — the confirming cycle a multi-cycle story pays anyway. The fallback is mechanical, not judgment: when any prior finding lacks a clean dimension attribution (which assessor artifact it came from), run the full gate. Pair it with the sweep split: mid-loop cycles ride `scope=scoped` sweeps and delta gates; the advance-bound cycle runs the full sweep and the full gate. (A measured seven-cycle story paid a flat ~20 minutes of full three-assessor gating per cycle regardless of fix size — a nine-minute confirming fix gated at the same cost as a 77-minute one.) Under `--light` the gate is already a single trace read, so the profile buys nothing there; omit it.
112
+
113
+ **Record who authored the artifacts the verdict rests on.** Alongside that JSON, log one line naming the provenance of this story's `trace-<id>.md` / `gate-decision-<id>.json`: **`gate-provenance: tea`** when `bmad-testarch-trace` wrote them, or **`gate-provenance: hand-authored`** when the non-web section above did. This is not bookkeeping. The module's central non-negotiable is that completion is decided by a script reading TEA's artifact rather than by the model's judgment, and on the hand-authored path the model *writes the file the gate then reads* — a defensible substitution the non-web section sanctions, but one that is otherwise **indistinguishable** in the decision log and the run report from a verdict grounded in a TEA-authored gate. An Epic can run to completion entirely on the hand-authored path, story after story, with nothing anywhere recording that it did. Provenance is what keeps "the JSON is the truth" honest about *whose* JSON it was; it changes no verdict and gates nothing. Beside it, log `assessed-commit: <sha>` — the commit the assessors measured — because the delta cycle profile's re-check computes its diff from the PREVIOUS gate's `assessed-commit` line, and a story whose record lacks one falls back to the full gate.
86
114
 
87
115
  **Attended runs also print the verdict, once.** In an attended run, immediately after `gate_eval.py` returns and alongside the `.decision-log.md` record above, print **exactly one** transcript line for this story — `story 4-2 — gate_status PASS — verdict advance` — carrying the story id, the `gate_status`, and the routing verdict. The line fires at the moment the verdict is formed, not on the heartbeat cadence: **one line per story, per gate evaluation**, so a watching human sees every story's completion decision without opening a file, and a re-looped story prints its own line for its second evaluation rather than restating the first. Skip this print in headless (`-H`): there the artifacts and `run-result.json` are the interface, and transcript prose has no reader. The line is **additive to the `.decision-log.md` record and never a substitute for it** — the recorded JSON is the completion evidence, a transcript line is not, and a reader who treats the line as the record has lost the `reasons`.
88
116
 
89
117
  ## Route on the verdict
90
118
 
91
- - **`advance`** (gate_status PASS or WAIVED) → the story passes. **Sync the story's row in `sprint-status.yaml` to `done` before moving on** — set `development_status[<story_id>]` to `done`, preserving the file's comments and key order, and log the transition in `.decision-log.md`. This write is the run's own, not a sub-skill's: `bmad-dev-story` leaves the row at `review`, and `bmad-code-review` (production only — it does not run under `--light` at all) writes `done` **only** when nothing was left as an action item, so a story that legitimately `defer`s a non-critical finding is left at `in-progress`. Every downstream reader keys on `done` — Stage 1's in-scope rule (`references/ingest-and-scope.md` rule 3), the Epic-level trigger in this very sentence, and `scripts/drive_epic.py`'s progress check — so an advanced story whose row still says `review` is an advanced story the next reader re-drives, and an Epic whose last story advanced without this write never satisfies the Epic-level condition below. Sync it here, at the one place the authoritative verdict is known. Then move to the next story. When **every story of the Epic is `done`**, run the Epic-level **trace** gate: pass the epic's own id via `--story` (scoped per the `--story` note above), **add `--epic-level`**, and read its `gate_status` **only**. TEA produces NFR and test-review **per story, not per epic**, so there is no epic-level aggregate to AND, and every story's own production gate already ANDed its signals before reaching `done`; the epic roll-up is a pure trace read.
119
+ - **`advance`** (gate_status PASS or WAIVED) → the story passes. **Sync the story's row in `sprint-status.yaml` to `done` before moving on** — set `development_status[<story_id>]` to `done`, preserving the file's comments and key order, and log the transition in `.decision-log.md`. This write is the run's own, not a sub-skill's: `bmad-dev-story` leaves the row at `review`, and `bmad-code-review` (production only — it does not run under `--light` at all) writes `done` **only** when nothing was left as an action item, so a story that legitimately `defer`s a non-critical finding is left at `in-progress`. Every downstream reader keys on `done` — Stage 1's in-scope rule (`references/ingest-and-scope.md` rule 3), the Epic-level trigger in this very sentence, and `scripts/drive_epic.py`'s progress check — so an advanced story whose row still says `review` is an advanced story the next reader re-drives, and an Epic whose last story advanced without this write never satisfies the Epic-level condition below. Sync it here, at the one place the authoritative verdict is known. Then move to the next story. When **every story of the Epic is `done`**, run the Epic-level gate: pass the epic's own id via `--story`, **add `--epic-level`**, and read its `gate_status` **only**. TEA produces NFR and test-review **per story, not per epic**, so there is no epic-level aggregate to AND, and every story's own production gate already ANDed its signals before reaching `done`. With `--rollup` the epic id is the sprint-status grouping key and the verdict is a computation over the per-story record; only in the omit-`--rollup` fallback is `--story` resolved against an epic-named artifact (scoped per the `--story` note above) and the roll-up a pure trace read.
92
120
 
93
121
  ```
94
- uv run {skill-root}/scripts/gate_eval.py --trace-output {workflow.trace_output_dir} --story <epic_id> --profile production --epic-level
122
+ uv run {skill-root}/scripts/gate_eval.py --trace-output {workflow.trace_output_dir} --story <epic_id> --profile production --epic-level --rollup --sprint-status {workflow.implementation_artifacts}/sprint-status.yaml
95
123
  ```
96
124
 
97
- **Declare the omission; do not imply it.** `--epic-level` is what makes the skipped ANDs correct rather than the signal-dropping the per-story gate forbids in "Run the gate". The two used to be the same input — leaving the flags off — so a forgotten flag on a story gate was indistinguishable from a legitimate epic roll-up, and the story gate silently advanced on a signal nobody read. Without the flag, `--profile production` now treats an absent `--nfr`/`--test-review` as failing. Passing an epic-level `--test-review`/`--nfr` path that no aggregate writes is the mirror mistake: it gets "test-review file … not found; treated as failing" and spuriously downgrades an epic PASS to `reloop`. Under `--profile light` the flag is a no-op, since that profile runs no ANDs at all. Then proceed to Stage 6 (`references/finalize.md`). **Partial-by-design exception:** if this run delivered only a deliberate *strict subset* of the Epic's stories (in-scope ⊊ Epic — e.g. a conditional / evidence-gated Epic where the operator scoped a subset; this is distinct from ingest-and-scope.md's already-`done`-skipping, which still ends with every story `done`) — do **not** author an Epic-level gate: a PASS would misrepresent an incomplete Epic as complete. Record the per-story advance(s) and proceed to Stage 6 with the Epic left in its partial / conditional state (the `partial-complete` terminal outcome — see `references/finalize.md`).
125
+ **`--rollup` computes the roll-up; it does not read an epic-named artifact.** The story set comes from `sprint-status.yaml` — the authority on what the Epic owes, never a typed list a story could quietly fall off — and the aggregate is the WORST per-story `gate_status`, fail-closed on five refusals, each `NOT_EVALUATED` → `escalate`: an unreadable sprint-status; an epic with no stories in it; any story not `done` (the roll-up's own trigger is every-story-done, so running it early is refused rather than answered); a multi-story epic whose trace dir is not per-story-named (one shared artifact cannot decide N stories); and any `done` story with no resolvable gate artifact of its own — Stage 1's `done-without-gate-artifacts` audit made binding at the one gate that certifies the Epic. The sprint-status key is the resolution identity, byte-identical to the artifact `<id>` exactly as the `--story` rule above pins it — a renamed or slugged mismatch fail-closes, and the remedy is naming, never slug tolerance. Omit `--rollup` and the invocation reads the epic's own `trace-<epic>` artifact exactly as before; prefer `--rollup` wherever sprint-status is available, because the epic summary then rests on a computation over the per-story record instead of on prose nobody re-checks. **The partial-by-design exception below binds `--rollup` unchanged**: a deliberately partial Epic authors no epic-level gate and runs no roll-up — and one run anyway is answered by the not-`done` refusal, never by a PASS over a subset.
126
+
127
+ **Declare the omission; do not imply it.** `--epic-level` is what makes the skipped ANDs correct rather than the signal-dropping the per-story gate forbids in "Run the gate". The two used to be the same input — leaving the flags off — so a forgotten flag on a story gate was indistinguishable from a legitimate epic roll-up, and the story gate silently advanced on a signal nobody read. Without the flag, `--profile production` now treats an absent `--nfr`/`--test-review` as failing. Passing an epic-level `--test-review`/`--nfr` path that no aggregate writes is the mirror mistake, and the script now refuses the combination outright rather than evaluating it: it is an **invocation error, not a gate verdict** — argparse prints a usage line naming `--epic-level` and exits `2`, computing no verdict at all (the same lane a missing `--story` occupies in `references/finalize.md`). So there is no `reloop` to route on and no gate artifact to re-read: fix it by re-issuing the command without the paths. Under `--profile light` the flag is a no-op, since that profile runs no ANDs at all. Then proceed to Stage 6 (`references/finalize.md`). **Partial-by-design exception:** if this run delivered only a deliberate *strict subset* of the Epic's stories (in-scope ⊊ Epic — e.g. a conditional / evidence-gated Epic where the operator scoped a subset; this is distinct from ingest-and-scope.md's already-`done`-skipping, which still ends with every story `done`) — do **not** author an Epic-level gate: a PASS would misrepresent an incomplete Epic as complete. Record the per-story advance(s) and proceed to Stage 6 with the Epic left in its partial / conditional state (the `partial-complete` terminal outcome — see `references/finalize.md`).
98
128
 
99
129
  - **`defer`** (gate_status CONCERNS, or non-critical code-review / NFR findings that did not flip the gate) → append the open items to the ledger at `{workflow.deferred_work_path}` using the schema below, then **advance** anyway. The Epic keeps moving; the parked work is visible.
100
130
 
101
- - **`reloop`** (gate_status FAIL, or a production signal downgraded an advance) → run `bmad-correct-course` to diagnose and adjust, then re-run the story (back through Execute, `references/execute.md`) — **within the remaining turn budget**. Re-run the gate after. If the re-loop would exceed `{workflow.max_turns_per_story}`, treat it as `escalate` instead.
131
+ - **`reloop`** (gate_status FAIL, or a production signal downgraded an advance, or a cap — sweep-scope or delta-profile) → **generalize before fixing.** Before `bmad-correct-course` writes any fix, take the verdict's `reasons` and the review's findings and, for each finding: (1) name, in ONE line, the defect CLASS the finding is an instance of; (2) state whether any earlier review of this story or this Epic already found that class — the previous gate artifacts and `{workflow.implementation_artifacts}/.class-ledger-<epic_id>.md` are the evidence, and they are already on disk, so this is a read, not a judgment call; (3) where the class is a repeat, the fix must close the CLASS — every sibling instance the same seam admits, not the one instance the reviewer demonstrated — and the log records why the class-level fix was not taken when the class was first named. A measured run spent five of six reviews re-finding one class ("an assertion that cannot go red") one seam over each time, with the class-killing move available from day one; the generalize step is what makes cycle N read cycle N-1 instead of re-buying it. Record one `class:` line per finding in this re-loop's `.decision-log.md` entry, and append any class not already present to `.class-ledger-<epic_id>.md` (create on first use; named for the Epic, so a later Epic starts a fresh ledger while this Epic's survives across its own invocations for exactly the resume case; one line per class, `- <class, one line> — first named <story_id>, cycle <n>`; **append-only** — Execute step 1 reads it before every story and re-loop, so a class named once is warned about everywhere after, including across stories, which no per-story artifact can do). **A score that does not move indicts the FIX STRATEGY, not the code:** when two consecutive gate evaluations of this story have moved `review_score` by less than 3 (production — under `--light` no review score exists, so the trigger there is two consecutive re-loops whose findings name any class already in the ledger), the generalize answers above are mandatory *in writing* before any further fix — a re-loop whose findings all name the same class as the previous re-loop's is a re-loop about to be spent badly. **A cap-only re-loop skips the ceremony.** When a cap alone produced the verdict — the `reasons` show only the sweep-scope cap, the delta-profile cap, or both, with no gate FAIL and no failed production signal — there is no finding to generalize and nothing to diagnose: re-run the full three-axis sweep where the sweep cap fired and refresh the marker with `scope=full`, then re-run the gate as the FULL instrument — **dropping `--cycle-profile`**, because the delta cap is lifted by the flag's absence and a re-gate that keeps it caps again forever — writing no `class:` lines, appending nothing to the ledger, and skipping `bmad-correct-course` entirely; such evaluations do not count toward the flat-score tripwire, and a capped CONCERNS keeps its findings for the next gate's own `defer` route — parking them is that gate's job, not this re-loop's. Otherwise, run `bmad-correct-course` to diagnose and adjust, then re-run the story (back through Execute, `references/execute.md`) — **within the remaining turn budget**. Re-run the gate after. If the re-loop would exceed `{workflow.max_turns_per_story}`, treat it as `escalate` instead.
102
132
 
103
133
  - **`escalate`** (gate_status NOT_EVALUATED — the gate could not be read — or budget exhausted on a FAIL) → **stop.** Do not advance, do not defer the failing item. Record the reason and the verdict JSON in `.decision-log.md`, and write the typed escalation sidecar `{workflow.implementation_artifacts}/escalation-<story_id>.json` (shape in `references/execute.md`, under "Escalation sidecar") so the pending decision is readable without the transcript. In an attended run, surface the blocker to the user. In headless, this is a `blocked` outcome — emit the JSON in Stage 6 (`references/finalize.md`).
104
134
 
@@ -120,4 +150,5 @@ Append to `{workflow.deferred_work_path}` (create on first use). One heading per
120
150
 
121
151
  - `source` ∈ `gate` (CONCERNS), `code-review` (non-critical finding), `nfr` (non-FAIL finding), `decision` (parked decision).
122
152
  - `severity` ∈ `low`, `med`, `high`. A `high` that maps to a gate FAIL or a P0/critical finding does **not** belong here — re-loop or escalate it.
123
- - `id` is unique within the Epic heading (append `d2`, `d3`, … ); never rewrite existing rows.
153
+ - `id` is unique within the Epic heading (append `d2`, `d3`, … ). Note that the id is unique only WITHIN its heading, so `d1` under two Epics is two different decisions; a project-wide reader must key them by more than the raw column (`/ucg-resolve` mints an id for exactly this reason).
154
+ - `status` ∈ `open`, `resolved`. **This gate only ever appends rows, and never rewrites one** — but the column is not frozen forever: `/ucg-resolve` flips `open` to `resolved` when an operator closes a parked decision, and that single transition is the one sanctioned edit to an existing row. Everything else about a row is immutable once written: never restate its `id`, `source`, `severity`, `story`, `reason` or `suggested_action`, because the ledger is the durable account of what was parked and rewriting it loses the history the Epic close-out reads.
@@ -126,14 +126,14 @@ uv run {skill-root}/scripts/health_check_fp.py fingerprint \
126
126
  **2. Check the seen-cache via the script:**
127
127
 
128
128
  ```
129
- uv run {skill-root}/scripts/health_check_fp.py seen --fp {fp} --cache {seenCachePath}
129
+ uv run {skill-root}/scripts/health_check_fp.py seen --fp {fp} --cache {seenCachePath} --queue-path {workflow.health_check_queue_path}
130
130
  ```
131
131
 
132
132
  → **`seen` is the suppression verdict, not mere cache presence.** Read `status`:
133
133
 
134
134
  - **`unseen`** (`seen: false`, `record: null`) — proceed.
135
- - **`handled`** (`seen: true`) — this user already handled this fingerprint on this machine. Before suppressing, if `record.issue_url` is non-empty you **must** run the issue-state check below; it can override this verdict to `regression`. Otherwise skip submission silently and log `"fp-xxxxxxx: already handled on {record.date}, {record.issue_url} — skipping"`.
136
- - **`regression`** (`seen: false`, `record` present, `record.action` is `resolved`) — this fingerprint was fixed and closed out, so a fresh sighting is a **regression, not a duplicate**. Do NOT suppress. Proceed, and mark it so it can never be filed as a first sighting: title it `[health-check][{severity}][{fp}] {workflow}: REGRESSION — {short description}` and open the body with `Regression of {record.issue_url} (resolved {record.date}).` When `record.issue_url` is empty (the prior sighting only ever queued, so no issue exists), write `Regression of a previously resolved local finding (resolved {record.date}).` instead — the `{fp}` label still ties the two together server-side.
135
+ - **`handled`** (`seen: true`) — this user already handled this fingerprint on this machine. Before suppressing, if `record.issue_url` is non-empty you **must** run the issue-state check below; it can override this verdict to `regression`. **`handled` suppresses a defect, not a section**: the fingerprint hashes only severity + stage + section slug, so a second, *distinct* defect in an already-reported section computes to the same `fp` — and suppressing it on the fingerprint alone silences a live defect forever. So before suppressing, compare **defects, not wording**, starting from the `prior` object the `seen` call above already returned (the recorded filing's path, title and `defect_slug`, located from the queue dir and its `resolved/` subfolder — read that file for the Finding text). When `prior` is null, retrieve the prior finding another way: the issue at `record.issue_url`, or a manual search of `{workflow.health_check_queue_path}`. Same defect → suppress and log `"fp-xxxxxxx: already handled on {record.date}, {record.issue_url} — skipping"`. A different defect → proceed as an ordinary submission, opening the body with a one-line collision note naming the `fp` and the prior finding it is not, so a maintainer does not merge the two. Prior text unretrievable → proceed rather than suppress: reporting a duplicate is self-healing (the dedup Action closes it); silencing a live defect is not.
136
+ - **`regression`** (`seen: false`, `record` present, `record.action` is `resolved`) — this fingerprint was fixed and closed out, so a fresh sighting is a **regression, not a duplicate**. Do NOT suppress. Proceed, and mark it so it can never be filed as a first sighting: title it `[health-check][{severity}][{fp}] {workflow}: REGRESSION — {short description}` (when `record.defect_slug` is present, name it: `REGRESSION of {defect_slug} — {short description}`, so a colliding fp's regression names WHICH defect regressed) and open the body with `Regression of {record.issue_url} (resolved {record.date}).` When `record.issue_url` is empty (the prior sighting only ever queued, so no issue exists), write `Regression of a previously resolved local finding (resolved {record.date}).` instead — the `{fp}` label still ties the two together server-side.
137
137
  - **`unrecognized`** (`seen: false`, `record` present) — the record carries an action this version does not know, so it cannot be confirmed handled. Proceed as an ordinary submission. Reporting a duplicate is self-healing (the dedup Action closes it); silencing a live defect is not.
138
138
 
139
139
  **The issue-state check (required whenever `handled` carries an `issue_url`).** The cache is machine-local: it records what *this* user did on *this* machine, so a `resolved` written by whoever fixed the defect is invisible to everyone else. An issue's state is shared, so it is the better authority. Bound the call, because this is finalize's terminal step and a hung network must not stall it:
@@ -244,7 +244,7 @@ Even when queuing, **still compute the fingerprint via the script** (so the queu
244
244
 
245
245
  ```
246
246
  uv run {skill-root}/scripts/health_check_fp.py record --fp {fp} --cache {seenCachePath} \
247
- --issue-url "" --action queued --date {YYYY-MM-DD}
247
+ --issue-url "" --action queued --date {YYYY-MM-DD} [--defect-slug {the frontmatter's defect_slug}]
248
248
  ```
249
249
 
250
250
  **Never overwrite a `resolved` record with `queued`.** `record` is a flat overwrite, and this path runs on the documented default (`autosubmit` off, and friction/gap always queue), so a single unattended run between a fix and the next attended report would otherwise downgrade `resolved` back to `queued` and silently re-arm the suppression the fix just removed. Read the cache first (`seen --fp {fp}`) and **skip this record entirely when `status` is `regression`** — the queue file is still written, and the `resolved` record stays intact so the next §5a run still sees the regression. Log the skip: `"fp-xxxxxxx: resolved on {record.date}, leaving the record intact — queued file written"`.
@@ -260,10 +260,13 @@ workflow: ultracode-goal/{stage}
260
260
  step_file: skills/ultracode-goal/references/{stage}.md
261
261
  severity: {bug | friction | gap}
262
262
  fingerprint: {fp-xxxxxxx}
263
+ defect_slug: {optional-short-kebab-name-for-this-defect}
263
264
  date: {ISO date}
264
265
  ---
265
266
  ```
266
267
 
268
+ `defect_slug` is optional and informational: a short kebab-case name for THIS defect (not the section), so a colliding fingerprint's later sightings and regressions can name which defect they mean. It never keys suppression — the handled branch's prior-text comparison stays mandatory.
269
+
267
270
  When `gh auth status` failed, after writing the files display:
268
271
 
269
272
  "{N} finding(s) saved locally:" then each path, then:
@@ -30,10 +30,10 @@ Resolution order:
30
30
 
31
31
  **Numeric-key caveat.** The rollup groups stories by their numeric epic prefix (`^\d+`), so a track whose epic keys are non-numeric — e.g. an isolated `epic-st-5` / `st-5-1` starter track — returns `sprint_status_present: true` with an **empty `epics` array** (not an error; the helper still exits 0). Do not read that empty-but-present result as "the track has no epics" — it is the signal the track was not numerically disambiguated per rule 6. Reading the isolated `sprint-status.yaml` directly recovers Stage-1 scope selection, but treat that as a **diagnostic only**: the same numeric-prefix limit binds Stage 2's `formalize_check.py --epic` reader, so an alpha-keyed track still formalizes to zero in-scope stories downstream. A track meant to run the pipeline must be **re-keyed to a free epic number** (rule 6); do not carry an alpha-keyed track past Stage 1 on the strength of a direct read alone.
32
32
  2. Confirm the Epic has a body (acceptance-bearing stories or an Epic file). A title-only Epic with no stories is not blocking here — Stage 2 generates missing stories/ACs via `bmad-create-story`. Note it so Stage 2 expects remediation.
33
- 3. **In-scope = not-yet-`done`.** The run's in-scope stories are the resolved Epic's stories whose rollup status is not `done`. A partially-done Epic — say stories 1–3 hand-finished before this run was ever invoked — carries only its remaining stories into preflight; log the done ones as `skipped-already-done` so Execute never re-drives them (the resume cursor only covers re-invocations that have a prior run folder; this rule covers the fresh invocation that doesn't). **Operator-scoped subset:** if the operator deliberately names a *strict subset* of the not-`done` stories (a conditional or evidence-gated Epic where only some stories are in play this run), honor it — in-scope ⊊ Epic. Such a run ends in the **`partial-complete`** terminal state with no Epic-level gate authored (gate.md / finalize.md), distinct from the already-done skip above, which still ends with every story `done`. Headless never narrows this way: its in-scope is every not-`done` story, so a successful headless run finishes the Epic **unless the operator bounded the invocation's work with `--max-stories N`** — that flag drives fewer of the in-scope stories without narrowing the set (`references/execute.md`), so the Epic is finished by the *next* invocation's resume rather than by this one. In-scope is the same either way; only how much of it one invocation takes on differs.
33
+ 3. **In-scope = not-yet-`done`.** The run's in-scope stories are the resolved Epic's stories whose rollup status is not `done`. A partially-done Epic — say stories 1–3 hand-finished before this run was ever invoked — carries only its remaining stories into preflight; log the done ones as `skipped-already-done` so Execute never re-drives them (the resume cursor only covers re-invocations that have a prior run folder; this rule covers the fresh invocation that doesn't). **The `done` rows this rule skips are trusted, so audit them cheaply before trusting them**: a row that reached `done` without its gate artifacts — a crash between the sync and the artifacts, an older defect, a hand-edit — is otherwise invisible forever, because resume routing keys on the log and the row, never on artifacts, and the gate trail fails soft over the hole. One directory listing suffices: list `{workflow.trace_output_dir}` once and name in `.decision-log.md` any `done` story of this Epic with no `trace-<id>.md` / `gate-decision-<id>.json` pair, as `done-without-gate-artifacts`. **Judge "no pair" the way `gate_eval.py` resolves, not by stem equality**, or the listing invents holes the gate will not see: id components are tolerated (`11-6` == `11.6` == `11_6`), a gate decision named by the trace report's `gateDecisionFile` frontmatter hint counts as resolved, and so does an `e2e-trace-summary-<id>.json` carrying the gate fields (the fallback `gate.md` calls "**not** a failure"). This is **never a launch blocker and never a re-drive trigger on its own** — but it is not merely operator context either: every row named here **will refuse the Epic-level `--rollup` at Stage 5** (`gate.md`: any `done` story with no resolvable gate artifact of its own → `NOT_EVALUATED` → `escalate`), so a partially hand-finished Epic drives each remaining story to `advance` and then blocks at the one gate that certifies the Epic. Log it with the two ways out: author the missing per-story `trace-<id>.md` / `gate-decision-<id>.json` before launch, or accept that the Epic gate will escalate while the per-story advances stand. **Operator-scoped subset:** if the operator deliberately names a *strict subset* of the not-`done` stories (a conditional or evidence-gated Epic where only some stories are in play this run), honor it — in-scope ⊊ Epic. Such a run ends in the **`partial-complete`** terminal state with no Epic-level gate authored (gate.md / finalize.md), distinct from the already-done skip above, which still ends with every story `done`. Headless never narrows this way: its in-scope is every not-`done` story, so a successful headless run finishes the Epic **unless the operator bounded the invocation's work with `--max-stories N`** — that flag drives fewer of the in-scope stories without narrowing the set (`references/execute.md`), so the Epic is finished by the *next* invocation's resume rather than by this one. In-scope is the same either way; only how much of it one invocation takes on differs.
34
34
  4. **Already-done short-circuit.** If *every* story for the resolved Epic is already `done`, do not carry a no-op Epic into preflight: surface "this Epic is already complete — re-run anyway?" and proceed only on a yes (an explicit yes re-scopes all stories deliberately). Headless: emit the same five-key blocked JSON (`report`/`deferred_work` `null`) with `reason` "epic already complete", built by the `scripts/headless_envelope.py` `build_headless_envelope` adapter with `impl_artifacts={workflow.implementation_artifacts}` — the config resolved by this point, so the adapter also writes the envelope to `{workflow.implementation_artifacts}/run-result.json` (same bytes as stdout) for an automator to read.
35
35
  5. If `sprint-status.yaml` is absent (the rollup says so and emits no Epics) or `{planning_artifacts}` has no PRD/ADR for this Epic, that is not a hard stop at this stage — record the gap; Stage 2 preflight reports it mechanically and the semantic scan judges whether the missing planning artifact is a true RED (undecided product/architecture) or a benign absence.
36
- 6. **Cross-file or colliding-epic initiative.** The resolution chain keys on the epic *number*: the rollup and `formalize_check.py --epic` both read it against one `sprint-status.yaml` inside `{workflow.implementation_artifacts}`, and the Stage-5 gate (`gate_eval.py`) resolves per-story trace artifacts *by id* inside `{workflow.trace_output_dir}`. So an initiative that is **not** tracked in that sprint-status (its epic/stories live in a separate planning file, e.g. a starter-template track brought in alongside the product's own epics) — **or** whose epic number **collides** with an epic already in it — cannot be resolved by number without silently hitting the wrong, unrelated epic. Run it as an **isolated track**: point `--impl-artifacts` (and the matching `{workflow.trace_output_dir}` / test-artifacts root) at a dedicated dir that holds *only* this initiative's own `sprint-status.yaml` and stories, and give its stories **disambiguated ids that keep a numeric epic prefix** — a free, high epic *number* no shared-track epic uses (e.g. `epic-90` with stories `90-1`, `90-2`), never an alpha prefix like `st-5`. Keep the disambiguation numeric because the number-keyed readers named above group by the `^\d+` prefix: an alpha-keyed track (`epic-st-5` / `st-5-1`) silently rolls up to an empty `epics` array and formalizes to zero in-scope stories. Pass that isolated `--impl-artifacts` to the sprint-status readers (`preflight_check.py --rollup`, `formalize_check.py`); scope the gate to the isolated track by pointing `gate_eval.py --trace-output` at that dedicated trace dir with `--story <disambiguated id>` (it keys on the story id against trace-report filenames, never on the epic number against a sprint-status, so it takes no `--impl-artifacts`). Record the isolated `--impl-artifacts` and trace-output paths in `.decision-log.md` so Stage 2 and the gate inherit them verbatim; never let a number-keyed read fall through to the shared `sprint-status.yaml`.
36
+ 6. **Cross-file or colliding-epic initiative.** The resolution chain keys on the epic *number*: the rollup and `formalize_check.py --epic` both read it against one `sprint-status.yaml` inside `{workflow.implementation_artifacts}`, and the Stage-5 gate (`gate_eval.py`) resolves per-story trace artifacts *by id* inside `{workflow.trace_output_dir}`. So an initiative that is **not** tracked in that sprint-status (its epic/stories live in a separate planning file, e.g. a starter-template track brought in alongside the product's own epics) — **or** whose epic number **collides** with an epic already in it — cannot be resolved by number without silently hitting the wrong, unrelated epic. Run it as an **isolated track**: point `--impl-artifacts` (and the matching `{workflow.trace_output_dir}` / test-artifacts root) at a dedicated dir that holds *only* this initiative's own `sprint-status.yaml` and stories, and give its stories **disambiguated ids that keep a numeric epic prefix** — a free, high epic *number* no shared-track epic uses (e.g. `epic-90` with stories `90-1`, `90-2`), never an alpha prefix like `st-5`. Keep the disambiguation numeric because the number-keyed readers named above group by the `^\d+` prefix: an alpha-keyed track (`epic-st-5` / `st-5-1`) silently rolls up to an empty `epics` array and formalizes to zero in-scope stories. Pass that isolated `--impl-artifacts` to the sprint-status readers (`preflight_check.py --rollup`, `formalize_check.py`); scope the gate to the isolated track by pointing `gate_eval.py --trace-output` at that dedicated trace dir with `--story <disambiguated id>` (the per-story gate keys on the story id against trace-report filenames and takes no `--impl-artifacts`; the `--rollup` epic gate DOES read a sprint-status, so pass the isolated track's own file via `--sprint-status`, mirroring the `--impl-artifacts` redirection — never the shared one). Record the isolated `--impl-artifacts` and trace-output paths in `.decision-log.md` so Stage 2 and the gate inherit them verbatim; never let a number-keyed read fall through to the shared `sprint-status.yaml`. **Where the redirection is declared depends on whether this project ALSO runs a shared track.** The scalar is project-wide, so setting it redirects *every* run, not this one: on a project that carries both tracks it would point the shared track's runs at the isolated dir too, and `/ucg-status` (which reads the configured scalar as the shared track's) would then describe the wrong run. So: **only when the isolated track is the project's sole track** — a dedicated checkout, or a project with no shared `sprint-status.yaml` — set `implementation_artifacts` (and `trace_output_dir`) to the dedicated dirs in `{project-root}/_bmad/custom/ultracode-goal.toml` and pass the flags as the pass-through of those resolved scalars. **On a project carrying both, stay flag-only** and take the caveat at the end of this rule seriously, because it is then the normal case rather than the exception. Either way the hazard to know is that a flag reaches only the script you type it on, and three consumers read the **scalar** instead: Stage 2's injected `ULTRACODE_IMPL_ARTIFACTS` (`references/preflight.md`), Stage 6's `run-result.json` write (`references/finalize.md`, `impl_artifacts={workflow.implementation_artifacts}`), and `scripts/drive_epic.py`, whose terminal poll is `--impl-artifacts` exactly. Redirect the flags alone and the run's terminal lands in the shared dir while the driver polls the isolated one, so a story that in fact completed is reported as `no-terminal`. If a track must run flag-only, record that in `.decision-log.md` and do not drive it with `drive_epic.py`.
37
37
 
38
38
  Do not open story or planning files for deep reading here — note their paths so Stage 2 and the TEA stages scan them. Reading them now bloats context ahead of delegation.
39
39
 
@@ -43,7 +43,7 @@ Profile defaults to **production** — the full TEA chain (test-design + atdd +
43
43
 
44
44
  Surface the default with its cost up front, so the choice is made at this cheap stage rather than discovered at the expensive one: "Production (full TEA chain per story — the thorough, slower default) unless you want `--light` (trace gate only — faster and cheaper, with proportionally lighter evidence)." One soft-gate touch — "Anything else on scope before I preflight?" — then move on. **Under `--yes` (and headless), skip that soft-gate and the Operator-notes solicitation entirely**: resolve the profile from the flags and proceed straight to preflight, so the "no conversational stops" contract the expert one-liner advertises actually holds. Don't re-derive the profile later; Stages 3 and 5 read what you lock here.
45
45
 
46
- Also note execution mode for the log: **sequential** `/goal` spine (default) or `--parallel` (experimental worktree fan-out). It does not change scope, but the log should carry it so the run is reconstructable after compaction.
46
+ Also note in the log when the retired `--parallel` flag was passed: it is accepted and ignored (`references/execute.md`, "Retired — `--parallel`"), and the accepted-and-ignored note is what keeps the run reconstructable after compaction.
47
47
 
48
48
  ## Operator notes
49
49
 
@@ -71,7 +71,7 @@ uv run {skill-root}/scripts/mem_recall.py latch --impl-artifacts {workflow.imple
71
71
 
72
72
  **Never synthesize a probe to stand in for a denied call.** An empty `[]` written to the probe file satisfies the capability contract and latches GREEN (`claude_mem: present`, `schema_ok: true`), which claims this run validated a surface it never reached, and then authorizes a Finalize write against it. A denial is a red latch, always.
73
73
 
74
- **Still make the call even when a prior session recorded the same denial.** Skipping the probe on the strength of a previous run's note asserts an unavailability *this* run never measured, which is the anti-fabrication rule applied to the run's own history. It costs one turn. What a prior note earns is not a skipped probe but a louder report: after several consecutive denials, say in the run report that `on` plus headless plus a permission-gated MCP server means recall is **off in practice**, and the operator should either grant the permission once or set `cross_session_recall = "off"` rather than pay the probe every run.
74
+ **Still make the call even when a prior session recorded the same denial.** Skipping the probe on the strength of a previous run's note asserts an unavailability *this* run never measured, which is the anti-fabrication rule applied to the run's own history. It costs one turn, and that cost is deliberate — a recorded denial is a fact about a past session's permission layer, not this one's. What a prior note earns is not a skipped probe but a louder report: **every headless run whose probe was denied writes the remedy into its run report as a REQUIRED line, not an optional nicety** — `on` plus headless plus a permission-gated MCP server means recall is **off in practice**, and the operator's two one-line fixes (grant the permission once, or set `cross_session_recall = "off"`) both live outside the run, so the report line is the only surface where they can act. A run short of turns may drop prose; it may not drop that line (`references/finalize.md`'s run-report list restates this).
75
75
 
76
76
  When `{workflow.cross_session_recall}` is `"on"` **and** the claude-mem MCP tools are present, consult prior runs — exactly one search, one read:
77
77
 
@@ -1,6 +1,6 @@
1
1
  # Stage 2 — Preflight (the autonomy gate)
2
2
 
3
- This is the load-bearing gate. After this stage the run goes **unattended**: a sequential `/goal` spine or an experimental `--parallel` worktree fan-out, neither of which takes mid-run human input. So everything that would otherwise stall or ask a question must be resolved **now**, or the run must refuse to launch. The posture is **hard gate with auto-remediation**: the script reports mechanical blockers, this stage clears the remediable ones, you add the semantic judgment the script cannot, and launch happens only when the post-remediation intervention budget is zero. Converse in `{communication_language}`; produced markers/docs use `{document_output_language}`.
3
+ This is the load-bearing gate. After this stage the run goes **unattended**: a sequential `/goal` spine that takes no mid-run human input. So everything that would otherwise stall or ask a question must be resolved **now**, or the run must refuse to launch. The posture is **hard gate with auto-remediation**: the script reports mechanical blockers, this stage clears the remediable ones, you add the semantic judgment the script cannot, and launch happens only when the post-remediation intervention budget is zero. Converse in `{communication_language}`; produced markers/docs use `{document_output_language}`.
4
4
 
5
5
  ## 1. Run the mechanical check
6
6
 
@@ -50,7 +50,7 @@ Clear each remediable blocker, then **re-run the check** so the budget reflects
50
50
  - **`project-context.md` count != 1** (`project_context_count`) — advisory only: `preflight_check.py` reports it as a **check** and never appends it to `blockers[]`, so a count of `0` or `> 1` never moves `budget` and never blocks launch. Resolve to exactly **one** anyway (generate via `bmad-generate-project-context` if zero; de-dup if multiple): `{workflow.persistent_facts}` globs this file and duplicates poison Auto-Memory grounding — that is why to fix it, not the gate.
51
51
  - **`sprint-status.yaml` absent** (`sprint_status_present: false`): ensure it is present (via `bmad-sprint-planning`). Its presence makes TEA test-design **auto-select Epic-Level** and skip its interactive System/Epic mode prompt — without it, Stage 3 stalls on a question no one is there to answer. **Non-default-track caveat:** `preflight_check.py`'s `sprint_status_present` falls back to a repo-wide `_bmad-output/**` glob, so on a run scoped to a non-default `--impl-artifacts` dir (an isolated track, per ingest-and-scope.md's cross-file/colliding-epic rule) it can read `true` off a *foreign* track's `sprint-status.yaml` while this run's own track has none — this `sprint_status_present: false` trigger then never fires. On any non-default `--impl-artifacts` run, take `formalize_check.py`'s strict per-impl-artifacts read (the §1b `sprint_status_absent` mechanical gap) as the authoritative sprint-status signal and remediate off *that*, not the glob-backed flag.
52
52
  - **TEA mode**: force **Create** mode for every TEA workflow this run. Resume/Validate/Edit are interactive and will halt an unattended run. Set/confirm whatever the TEA config exposes (`tea_execution_mode`) so no workflow resumes a prior session.
53
- - **Secrets / credentials** a story needs (test env keys, API tokens): **interactive** — prompt **once**, now, and capture them out of git. **Headless** — do not prompt; an unresolvable secret becomes a RED blocker (step 4), never a deferred question.
53
+ - **Secrets / credentials — and unresolvable EXTERNAL DEPENDENCIES generally** — that a story needs (test env keys, API tokens, and equally network egress for anything a story's tasks say to *fetch*: a vendored data file, a crate or package not already in the lockfile, a model download): **interactive** — prompt or resolve **once**, now, and capture secrets out of git. **Headless** — do not prompt; an unresolvable secret **or an external fetch the environment refuses** becomes a RED blocker (step 4), never a deferred question. The fetch case sits in this bullet on the same fail-closed terms as credentials because its discovery otherwise happens mid-Execute, after the work around it is done, with the gate as the story's only exit.
54
54
  - **Formalize mechanical gaps** (`formalize_check.py`'s `mechanical_gaps[]` from step 1b): fold these machine-derivable, meaning-preserving fixes into *this same* pass — never a second remediation pass and never a new step heading. The genuinely-new one is the leaked-TEA-artifact **MOVE-and-re-point**: move a TEA artifact that leaked into a source/impl dir out to the `{workflow.trace_output_dir}` / test_artifacts root, then re-point every in-repo reference to the new path (content is only relocated, never rewritten) — the MOVE targets a *genuine* TEA artifact only; the kernel now excludes UCG's own story notes / run sentinels whose filename merely carries a marker token because the story slug does (`formalize_check.py:_is_ucg_impl_artifact`), so they no longer reach this remediation. Should any *other* non-TEA false positive ever surface, **verify identity before moving** and archive it *out of the impl-artifacts scan tree* — never into the trace dir (that misfiles it) and never leave it in place (it stays counted and deadlocks the `budget == 0` gate, since a remediable gap that is never cleared keeps the formalize verdict off `ready`) — recording in `.decision-log.md` what it actually is. The orphaned-index and missing-AC gaps reuse the `bmad-create-story` scaffold this step already runs. Auto-clear **only** a `mechanical_gaps[]` entry whose `remediable == true` (the kernel's human-authored `remediable` literal, never re-decided in this prose); a leaked-artifact finding the kernel emitted as a `judgment_candidates[]` entry or with `remediable: false` is **not** moved here — that residual content-soundness judgment routes to the step-3 scan / step-4 hard gate. These remediations reuse the existing remediate-then-re-run loop below ("run the script from step 1 again"), so the budget re-reflects the formalize fixes on re-run with no extra invocation.
55
55
 
56
56
  **Stale-hook pre-arming (before any remediation commit).** A prior UCG run may have left its PreToolUse guard (`scripts/hooks/guard_pretooluse.py`) and Stop budget hook (`scripts/hooks/budget_stop.py`) armed in `{project-root}/.claude/settings.local.json` — still live *now*, because step 5 has not yet re-armed this run's hooks. That stale guard mis-governs any remediation that commits (the dirty-tree `git_clean: false` clear especially): its marker-gate keys on `.current-story` plus a `.tests-ran-<story_id>` marker in the impl-artifacts, and on a fresh run `.current-story` is either unset — so no marker resolves and the commit is **denied**, dead-ending the remediation — or still points at the prior run's last story, whose persisted marker (Finalize removes only `.mem-state.json`, never the tests-ran markers) it then **rides to a spurious green**, waving the commit through under stale, wrong-run enforcement. Both failure modes are wrong for this run. Do **not** forge a marker and do **not** wait on the gate: **disarm the prior-run hooks first**, then make the remediation commit, and let step 5 re-merge both hooks freshly with *this* run's injected env. **The entries are nested, not top-level.** `settings.local.json` carries them under a top-level `hooks` key as `hooks.PreToolUse[].hooks[]` and `hooks.Stop[].hooks[]`: each outer element is a matcher group (`Stop` groups carry no `matcher` key) holding its own inner `hooks[]` array, and the UCG entry is the inner item whose `command` string names `guard_pretooluse.py` / `budget_stop.py`. Remove those inner items, and the enclosing matcher group only when that leaves its `hooks[]` empty, so a co-resident non-UCG hook survives. A disarm aimed at top-level `PreToolUse` / `Stop` keys matches nothing, changes nothing, and reports success: the stale guard then rides armed through the whole of preflight while the log records a disarm that never happened. So **mirror step 5's assertion** — re-read the **resolved** settings and confirm neither script path appears in any hook `command`, **before** any remediation commit. Assert on the script path rather than on the shape, so the check still holds if the settings schema moves and so an entry armed in another settings layer is not missed. Disarming is exactly as load-bearing as arming, and is the one this stage would otherwise leave unverified. Log the disarm, that assertion, and the step-5 re-arm to `.decision-log.md`.
@@ -118,7 +118,7 @@ Three properties of that override, each load-bearing:
118
118
  - **ultracode** session effort and **Auto Mode** are on (gated to Opus/Sonnet 4.6+; required for unattended xhigh + auto-workflow execution),
119
119
  - the post-remediation formalize_check.py verdict is `ready` — i.e. `mechanical_budget == 0` AND the formalize subagent found no RED — re-using the step-1b kernel's verdict after the step-2 fold-in and step-3 seed (not a fresh gate-time check); this clause holds on verdict `ready` and only `ready`, so any other verdict (`blocked`, an un-cleared `remediable`, or an unreadable / absent / unparseable / missing verdict) FAILS the gate under the "If any fails … STOP" disposition below.
120
120
 
121
- If any fails: write the blockers — mechanical and semantic — to `.decision-log.md` with what each needs to clear, and **STOP**. Do not launch a partially-ready run; a single guessed architecture decision corrupts the whole Epic. In **headless**, instead emit the blocked JSON in the canonical five-key shape (every key always present; `report` and `deferred_work` are `null` because the run blocked before producing them):
121
+ If any fails: write the blockers — mechanical and semantic — to `.decision-log.md` with what each needs to clear, and **STOP**. Name `/ucg-resolve` as the way back in: it walks the recorded REDs and records the operator's answer against the id `scripts/red_ids.py` minted, which is what step 3's override then reads, so an answered RED is not asked again at the next preflight. An operator closing the loop by hand instead has to re-derive that id, which is exactly what step 3 forbids. Do not launch a partially-ready run; a single guessed architecture decision corrupts the whole Epic. In **headless**, instead emit the blocked JSON in the canonical five-key shape (every key always present; `report` and `deferred_work` are `null` because the run blocked before producing them):
122
122
 
123
123
  ```json
124
124
  {"status": "blocked",
@@ -137,13 +137,13 @@ Pass `impl_artifacts={workflow.implementation_artifacts}` to that call: `scripts
137
137
 
138
138
  Do these in order; each must be asserted, not assumed:
139
139
 
140
- - **Epic branch.** Assert you are on `{workflow.epic_branch_prefix}<epic-id>`. When step 1 reported `git_branch`, step 2's remediation already created it, and this is a **re-assertion, not a rebuild** — the same treatment the resume path gives it. Create it here when it does not yet exist — and note that `budget == 0` does **not** by itself put you on it: `git_branch` fires on a protected branch and nothing else, so a run started on some unrelated feature branch clears the gate having never been asked about its branch, and step 2 has no bullet that fires for it. That case lands here, so resolve it here rather than routing back: check out the base this Epic should branch from (a `{workflow.protected_branches}` branch, per execute.md's "off a protected branch" precondition — or the base the operator named in Stage 1) and cut `{workflow.epic_branch_prefix}<epic-id>` from there. Do **not** branch from wherever HEAD happens to sit; an Epic branch cut off an unrelated feature branch carries that branch's uncommitted work into the run's history and makes the branch-deletion rollback destructive. Rollback for this run is git (per-story commits, worktree isolation under `--parallel`) — `/rewind` checkpoints miss Bash-driven changes, so the branch is the real undo. If the tree is dirty (`git_clean: false`), resolve before branching — the last budget re-run was at the end of step 2, and step 3 has since written its scan sidecar and appended to `.decision-log.md`, so `budget == 0` does **not** imply a clean tree by the time you arrive here (`git_clean` counts untracked files).
141
- - **Purge stale run markers.** Delete any `{workflow.implementation_artifacts}/.escalation-*`, `{workflow.implementation_artifacts}/.on-escalation-fired-*` and `{workflow.implementation_artifacts}/.budget-*` an earlier run left behind, before the hooks that write them are armed — a stale escalation marker makes this run look like it already escalated, a stale fired-marker silently swallows this run's first escalation ping, which is the one an absent operator is waiting on, and a stale turn counter is already at or past the ceiling, so the Stop hook escalates on this run's **first** Stop event before it has done a single turn of work. Those three dot-prefixed families only. **On a resume, purge nothing.** A resume re-asserts the environment rather than rebuilding it, and the turn counter is the one piece of that environment a resume must inherit: zeroing `.budget-*` on re-entry would hand an in-flight story a fresh ceiling every time it stopped, so a run could evade the budget indefinitely by resuming. A counter the operator has deliberately cleared is a different thing, and `/ucg-resolve` clears exactly that one when it closes a `budget-overrun` escalation. In particular do **not** delete `escalation-*.json`: the typed sidecar is an operator-facing artifact like `run-status.json` and `run-result.json`, neither of which is purged at arming either, and it is named per story rather than per run, so arming cannot tell a deliberately-pending sidecar from a stale one. A decision the operator chose to leave pending lives in exactly that file, and a prior run's unresolved escalation surfacing at `/ucg-resolve` is correct: it genuinely is still pending. Sidecar staleness is handled at read time instead, by the run-scoped marker scan in `references/execute.md`.
140
+ - **Epic branch.** Assert you are on `{workflow.epic_branch_prefix}<epic-id>`. When step 1 reported `git_branch`, step 2's remediation already created it, and this is a **re-assertion, not a rebuild** — the same treatment the resume path gives it. Create it here when it does not yet exist — and note that `budget == 0` does **not** by itself put you on it: `git_branch` fires on a protected branch and nothing else, so a run started on some unrelated feature branch clears the gate having never been asked about its branch, and step 2 has no bullet that fires for it. That case lands here, so resolve it here rather than routing back: check out the base this Epic should branch from (a `{workflow.protected_branches}` branch, per execute.md's "off a protected branch" precondition — or the base the operator named in Stage 1) and cut `{workflow.epic_branch_prefix}<epic-id>` from there. Do **not** branch from wherever HEAD happens to sit; an Epic branch cut off an unrelated feature branch carries that branch's uncommitted work into the run's history and makes the branch-deletion rollback destructive. Rollback for this run is git (per-story commits) — `/rewind` checkpoints miss Bash-driven changes, so the branch is the real undo. If the tree is dirty (`git_clean: false`), resolve before branching — the last budget re-run was at the end of step 2, and step 3 has since written its scan sidecar and appended to `.decision-log.md`, so `budget == 0` does **not** imply a clean tree by the time you arrive here (`git_clean` counts untracked files).
141
+ - **Purge stale run markers.** Delete any `{workflow.implementation_artifacts}/.escalation-*`, `{workflow.implementation_artifacts}/.on-escalation-fired-*`, `{workflow.implementation_artifacts}/.budget-*`, `{workflow.implementation_artifacts}/.heartbeat-*` and `{workflow.implementation_artifacts}/.stall-*` an earlier run left behind, before the hooks that write them are armed — a stale escalation marker makes this run look like it already escalated, a stale fired-marker silently swallows this run's first escalation ping, which is the one an absent operator is waiting on, and a stale turn counter is already at or past the ceiling, so the Stop hook escalates on this run's **first** Stop event before it has done a single turn of work — and a stale heartbeat's gap since the PRIOR run would fire this run's stall rule on its first resume about an idle nobody had. Those five dot-prefixed families only. **On a resume, purge nothing.** A resume re-asserts the environment rather than rebuilding it, and the turn counter is the one piece of that environment a resume must inherit: zeroing `.budget-*` on re-entry would hand an in-flight story a fresh ceiling every time it stopped, so a run could evade the budget indefinitely by resuming. A counter the operator has deliberately cleared is a different thing, and `/ucg-resolve` clears exactly that one when it closes a `budget-overrun` escalation. In particular do **not** delete `escalation-*.json`: the typed sidecar is an operator-facing artifact like `run-status.json` and `run-result.json`, neither of which is purged at arming either, and it is named per story rather than per run, so arming cannot tell a deliberately-pending sidecar from a stale one. A decision the operator chose to leave pending lives in exactly that file, and a prior run's unresolved escalation surfacing at `/ucg-resolve` is correct: it genuinely is still pending. Sidecar staleness is handled at read time instead, by the run-scoped marker scan in `references/execute.md`.
142
142
  - **Hooks.** Idempotently merge the **PreToolUse** guard (`scripts/hooks/guard_pretooluse.py`) and the **Stop** budget hook (`scripts/hooks/budget_stop.py`) into `{project-root}/.claude/settings.local.json` (gitignored, machine-local, honored after the workspace trust dialog). Re-merge every run — do not assume a prior run left them.
143
143
 
144
144
  **Arm the PreToolUse group with a matcher that covers EVERY tool, not just `Bash`.** Use `"matcher": "*"`, or omit the `matcher` key entirely the way the `Stop` group already does. Five of the guard's six invariants are Bash/git, so `Bash` is the natural choice and it is the choice both known installs made — but the sixth, the Cross-Session Recall latch, exists to gate an **MCP tool call**. Claude Code only invokes a PreToolUse group for tools its matcher selects, so under `Bash` the hook is never run for `mcp__plugin_claude-mem_*__*` at all: the guard would deny that call correctly if it were asked, and it is never asked. The invariant then enforces nothing while every log line says the hooks are armed, which is the worst of both — a control that reports itself active and is not.
145
145
 
146
- Then **assert they are active**: re-read the resolved settings and confirm both script paths appear **and** that the PreToolUse group's matcher is the all-tools form. A presence-only assertion passes on a `Bash`-only arming, which is exactly the state this bullet exists to prevent. Invariants that live only in memory are context, not enforcement, and memory does not block a `git commit`.
146
+ Then **assert they are active**: re-read the resolved settings and confirm both script paths appear **and** that the PreToolUse group's matcher is the all-tools form. A presence-only assertion passes on a `Bash`-only arming, which is exactly the state this bullet exists to prevent. The same assertion is scriptable — `preflight_check.py --assert-armed` performs it (branch, both hooks under their own events, matcher form, injected env) in one read and fail-closes with named reasons. Pass `--epic-branch-prefix {workflow.epic_branch_prefix}` and one `--protected-branch <name>` per entry in `{workflow.protected_branches}`, exactly as step 1 does: omit either and it asserts the branch against its hardcoded defaults (`ultracode/epic-`, `main, master`), silently no-opping those overrides and failing a correctly armed run on a false RED. The resume path leans on it (`references/execute.md`), and it is equally valid here. It reads `.claude/settings.local.json`, the file this bullet's arming writes — an arming that lives in another settings layer fail-closes, which is the correct answer for a control this stage must be able to disarm and re-merge. Invariants that live only in memory are context, not enforcement, and memory does not block a `git commit`.
147
147
  - **Inject the hook env from the resolved scalars.** Both hooks read config from env first ("env wins so the conductor can inject per run") and fall back to hardcoded defaults (`main/master`, `25`, `ultracode/epic-`) otherwise — so a `customize.toml` override of any of these **silently no-ops at the enforcement layer** unless you pass it through. Set these on the hook commands (in the `settings.local.json` hook `command`, e.g. `KEY=value uv run …`) or in the process env the hooks inherit:
148
148
  - `ULTRACODE_PROTECTED_BRANCHES={workflow.protected_branches}` (comma-separated)
149
149
  - `ULTRACODE_IMPL_ARTIFACTS={workflow.implementation_artifacts}`
@@ -152,8 +152,8 @@ Do these in order; each must be asserted, not assumed:
152
152
  - `ULTRACODE_TEST_ARTIFACTS=<the resolved TEA test-artifacts root>` — deliberately **not** a `{workflow.…}` scalar: no such workflow key exists, and a `{workflow.test_artifacts}` placeholder would never be filled by config resolution. Inject the same root TEA config resolution yields (`scripts/preflight_check.py`, `_tea_artifacts_root`): the tea-config `test_artifacts` value with `{project-root}` substituted (a relative value resolves under the project root), defaulting to `{project-root}/_bmad-output/test-artifacts` when tea config names none. This is the directory the guard reads the story's `atdd-checklist-<story-id>.md` from; leave it unset and the un-skip proof below is out of scope and silently enforces nothing.
153
153
  - The same PreToolUse guard now also enforces the Cross-Session Recall latch from `{workflow.implementation_artifacts}/.mem-state.json` — the merged hook reads it automatically, fail-closed; no new env var to inject. **It enforces nothing unless the matcher above covers MCP tools**, because the latch's whole purpose is to gate a claude-mem MCP call and a group matched on `Bash` is never invoked for one. This is the invariant that makes the all-tools matcher load-bearing rather than tidy.
154
154
  - **Un-skip proof (production only).** With `ULTRACODE_TEST_ARTIFACTS` injected, the guard reads the **staged post-image** of every acceptance-test file the story's `atdd-checklist-<story-id>.md` enumerates (`git show :<path>`) and denies the commit while any of them still contains `test.skip(`. It proves the marker is absent from the blob being committed, so it fires on a story's *first* commit too, where there is no prior blob to diff against. Caveat worth stating plainly: **`test.skip(` is a JS/Vitest-specific token** (the Playwright/Vitest form TEA's ATDD generates today, which is web/JS-only) — a pytest (`@pytest.mark.skip`) or Go (`t.Skip()`) stack marks skips differently and this check would not see them. Under `--light` there is no atdd-checklist, so the check stays inert.
155
- - **The commit/push guard anchors on each segment's leading token (`fp-7ac2643`).** The guard splits the command into shell segments and flags one only when `git` is that segment's **leading** token — after leading `VAR=val` assignments, shell keywords and group openers (`if`/`then`/`else`/`fi`, `for`/`while`/`until`/`do`/`done`, `case`/`esac`, `!`, and `(`/`{`, whether spaced or glued to the command name), and known exec wrappers (`env`, `command`, `sudo`, `time`, `nice`, `nohup`, `timeout`, `setsid`, `stdbuf`, `ionice`, `doas`, plus the string payload of a `sh|bash|zsh|dash -c`) are stripped — and the subcommand it would then run is exactly `commit` or `push`. The keyword strip is what keeps a commit inside a compound command (`if true; then git commit …; fi`, `for … do git commit … done`, `( git commit … )`) reachable by the gates: without it a keyword sits in the leading position, the segment classifies as carrying no git write, and the protected-branch, tests-ran, freshness and empty-index gates are all skipped at once. Segment splitting covers `&&`, `||`, `;`, `|`, a newline, **and a lone `&`** (`npm run build & git commit …` is two segments, not one); those separator sets are applied as a **union** rather than merged into one regex, because splitting on `&` or a newline is quote-blind and a lone set would tear `git -c alias.x='a&b' commit` into fragments that each escape detection. So a verb merely *mentioned* inside an `echo`, a log line, or a here-string in a verification command is no longer denied, while a real `FOO=bar git commit`, `sudo git commit` or `timeout 30 git commit` still is: on a `{workflow.protected_branches}` branch both verbs are denied, and on the epic branch, before the story's `.tests-ran-<story_id>` marker exists, a real `git commit` is denied (the marker gate is commit-only — a real `git push` is never marker-gated). Residual, stated rather than hidden: a wrapper **not** on that list (`xargs git commit`, say) leaves a non-`git` leading token and is allowed through, so the tests-ran marker and the remote's branch protection are the nets behind this one. Two shapes still take the older matches-anywhere path and deny on a mention: a segment whose quoting cannot be parsed, and one that hides its command inside a `$(…)` substitution or backticks. **Do not read the anchoring as having eliminated the false-positive class — it narrowed it, and the remainder bites prose about commits in particular.** Markdown prose names identifiers in backticks, and an apostrophe (`don't`) is unbalanced quoting, so a run-log line describing a commit denial routinely hits both fallbacks; a line that *leads* with the verb is a real verb-leading segment and denies on its own. The rule that avoids all of it: **write prose with Write/Edit, never a Bash heredoc.** The PreToolUse guard **evaluates Bash command strings only**, so a decision-log append made with the file tools reaches no matcher of its own and no phrasing of the log can trip a gate. Said that way on purpose, now that the group is armed for every tool: the hook IS invoked for a `Write`, it simply has nothing to evaluate and returns no decision (verified across `Read`/`Write`/`Edit`/`Grep`/`Glob`/`Task`/`WebFetch` and an unrelated MCP call - every one passes through). Reading it as "the guard never sees Write/Edit" and then widening the matcher looks like a contradiction, and the tempting way to resolve a contradiction is to narrow the matcher back to `Bash` - which is precisely the regression the bullet above exists to prevent. Reserve Bash for commands you actually mean to run. (execute.md step 4 covers the narrower marker-written-in-the-same-compound-command trap.)
156
- - **Allowlist.** Pre-populate the tool allowlist with `{workflow.allowlist_commands}` so the unattended run (and any fan-out subagents, which inherit the allowlist) can run tests/lint/build/commit without a permission prompt that no one is there to approve.
155
+ - **The commit/push guard anchors on each segment's leading token (`fp-7ac2643`).** The guard splits the command into shell segments and flags one only when `git` is that segment's **leading** token — after leading `VAR=val` assignments, shell keywords and group openers (`if`/`then`/`else`/`fi`, `for`/`while`/`until`/`do`/`done`, `case`/`esac`, `!`, and `(`/`{`, whether spaced or glued to the command name), and known exec wrappers (`env`, `command`, `sudo`, `time`, `nice`, `nohup`, `timeout`, `setsid`, `stdbuf`, `ionice`, `doas`, plus the string payload of a `sh|bash|zsh|dash` invoked with any `-c`-bearing flag cluster, `-lc` and `-cx` included) are stripped — and the subcommand it would then run is exactly `commit` or `push`. The keyword strip is what keeps a commit inside a compound command (`if true; then git commit …; fi`, `for … do git commit … done`, `( git commit … )`) reachable by the gates: without it a keyword sits in the leading position, the segment classifies as carrying no git write, and the protected-branch, tests-ran, freshness and empty-index gates are all skipped at once. Segment splitting covers `&&`, `||`, `;`, `|`, a newline, **and a lone `&`** (`npm run build & git commit …` is two segments, not one); those separator sets are applied as a **union** rather than merged into one regex, because splitting on `&` or a newline is quote-blind and a lone set would tear `git -c alias.x='a&b' commit` into fragments that each escape detection. So a verb merely *mentioned* inside an `echo`, a log line, or a here-string in a verification command is no longer denied, while a real `FOO=bar git commit`, `sudo git commit` or `timeout 30 git commit` still is: on a `{workflow.protected_branches}` branch both verbs are denied, and on the epic branch, before the story's `.tests-ran-<story_id>` marker exists, a real `git commit` is denied (the marker gate is commit-only — a real `git push` is never marker-gated). Residual, stated rather than hidden: a wrapper **not** on that list (`xargs git commit`, say) leaves a non-`git` leading token and is allowed through, so the tests-ran marker and the remote's branch protection are the nets behind this one. Three shapes still take the older matches-anywhere path and deny on a mention: a segment whose quoting cannot be parsed, one that hides its command inside a `$(…)` substitution or backticks, and — the newest — a **listed** shell wrapper (`sh|bash|zsh|dash`) whose command-string payload cannot be located at all, meaning no `-c`-bearing flag cluster with an operand after it, or nesting deeper than the shell-recursion cap. That third lane exists because locating the payload by the bare token `-c` alone missed every combined form (`bash -lc`, `sh -lc`, `bash -cx`, `zsh -ic`), and a wrapper whose payload went unread classified as carrying no git write and skipped all four commit gates. It is fail-closed in the same direction as the other two, and it has the same cost: `bash <script> "…git commit…"` now denies on the mention, so a verification command's own arguments must not spell a write verb. **Do not read the anchoring as having eliminated the false-positive class — it narrowed it, and the remainder bites prose about commits in particular.** Markdown prose names identifiers in backticks, and an apostrophe (`don't`) is unbalanced quoting, so a run-log line describing a commit denial routinely hits both fallbacks; a line that *leads* with the verb is a real verb-leading segment and denies on its own. The rule that avoids all of it: **write prose with Write/Edit, never a Bash heredoc.** The PreToolUse guard **evaluates Bash command strings only**, so a decision-log append made with the file tools reaches no matcher of its own and no phrasing of the log can trip a gate. Now that the group is armed for every tool, the hook IS invoked for a `Write`; it simply has nothing to evaluate and returns no decision (verified across `Read`/`Write`/`Edit`/`Grep`/`Glob`/`Task`/`WebFetch` and an unrelated MCP call - every one passes through), so do not narrow the matcher back to `Bash` on the strength of this clause. Reserve Bash for commands you actually mean to run. (execute.md step 4 covers the narrower marker-written-in-the-same-compound-command trap.)
156
+ - **Allowlist.** Pre-populate the tool allowlist with `{workflow.allowlist_commands}` so the unattended run can run tests/lint/build/commit without a permission prompt that no one is there to approve.
157
157
 
158
158
  ### Launch briefing (interactive only)
159
159
 
@@ -163,7 +163,8 @@ This is the moment the human leaves the loop. Before the first unattended action
163
163
  - **Worst-case envelope:** up to `story count × {workflow.max_turns_per_story}` turns — a smart default from context already in hand, so a first-timer can calibrate launch-now vs. launch-after-lunch.
164
164
  - **The autonomy line:** state plainly — *"from here I will not ask you anything."*
165
165
  - **Kill switch:** Ctrl-C, or delete the Epic branch — and note that `/rewind` will not help (its checkpoints miss the Bash-driven changes that make up the run, the same reason the branch is the real undo).
166
- - **Where to watch:** the run's `.decision-log.md` (prose account); on the sequential spine, `{workflow.implementation_artifacts}/run-status.json` (the machine-readable heartbeat Execute updates as the spine advances); under `--parallel`, watch the workflow progress view (`/workflows`) and its run log instead — the fan-out's worktree agents do not write `run-status.json`.
166
+ - **Where to watch:** the run's `.decision-log.md` (prose account) and `{workflow.implementation_artifacts}/run-status.json` (the machine-readable heartbeat Execute updates as the spine advances).
167
+ - **The rendered view of those files:** `/ucg-status` reads them back — heartbeat, decision-log tail, deferred-work ledger, escalation sidecars — and shows the run without touching it. The raw paths above stay for a poller; this is the one for a human checking in.
167
168
  - **How the run ends:** the last thing every run does is the workflow health check — a terminal self-audit of the friction the run itself hit, so the workflow improves from having been used. **Attended, it presents every finding and halts** — the run comes back to you at the close, so "unattended" ends there rather than at the last story. **Headless, it queues its findings locally and never blocks the emit.**
168
169
  - **Optional diff viewer:** when `hunk` is detected on PATH, the surfaces that name a commit suggest `hunk show <commit>` to read one story's diff and `hunk diff {workflow.epic_branch_prefix}<epic-id>` to read the whole branch. Absent `hunk`, nothing is printed and behavior is unchanged — it is never installed, never checked for at launch, and its absence is never warned about.
169
170