# Build Management — implementation-time rules (states · cleanups · plan revisions)

**When to read**: in full, BEFORE implementing planned tasks, updating any `⬜/🟡/✅` state, completing a Phase or milestone, or applying a plan revision. **Not needed for pure planning sessions** ([`../SKILL.md`](../SKILL.md) STEP 1–5) — don't load it there.

These rules are what keep the plan documents trustworthy across sessions: the previous session's chat context does not carry over, so anything not written into the docs — in the right doc, at the right moment — is lost.

## Which doc is the working truth

- While a Phase is active, **its Phase doc's checklist is the live record** for that Phase's task states; GDD §6 is the durable mirror, reconciled at the defined moments (soft-gate crossing · reaching a `⏳ user-test boundary` · last-`✅` cleanup · the archive gate). If they disagree at a checkpoint, reconcile **from the Phase doc** then and there — never let the disagreement survive past a checkpoint.

## Executing a Phase

- **Implement by Phase unit (continuous), not task-by-task**: when the user asks to implement a Phase, work through its tasks **in dependency order, end to end** — verify each inline, update its `⬜→🟡→✅` state, and keep going. **Don't stop after one task to ask whether to continue.** Pause only at: the Phase is **done as far as the AI can take it** — either **complete** (every item `✅`) or at a **⏳ user-test boundary** (only AI-unverifiable items left `🟡`); a **genuine blocker** (a decision or resource only the user can give, a user-test that gates the next task, or an unresolved failure); or a **context/output limit** (then do as much as possible, stop at a clean checkpoint, and state exactly what remains). ⚠️ **A `⏳ user-test boundary` is NOT completion**: [Completed-stage cleanup](#completed-stage-cleanup-mandatory) runs only on all-`✅`, so at this boundary the Phase doc **stays in `Docs/`** and is not deleted — mirror the current states into GDD §6, tell the user exactly which items need their test, and reflect their report back into the checklist (`✅`, or back to fixing). Never call it "complete", and never invent a label for it (the same closed-vocabulary rule as the milestone-level `⏳ user-test pending`). At a pause, give **one batched report**, not a per-task check-in. ("Phase unit" means continuous progress to a natural checkpoint — not necessarily one turn; implement everything implementable first and collect visual/feel/on-device user-tests to surface together at the Phase boundary.)
- **Update each task's state immediately as you build it — mandatory, not deferrable.** Per task, in order: write the code → **right away mark that item `🟡 Implemented (untested)` in the Phase doc** (before starting the next task and before verification) → verify → set `✅ Tested` (or send it back to fixing). **Never leave an implemented task at `⬜`** — if its files exist, it is at least `🟡`. **The checklist update comes before any other record**: don't log work into `Archive/As-built.md` (or anywhere else) whose checklist state you haven't updated yet. Don't batch the state updates to the end (that's how a Phase doc ends up all-`⬜` while the workspace is full of code, blocking the next session from knowing what's done). Tracking state only in an in-session/ephemeral tool (e.g. the harness's own TaskCreate/TaskUpdate list) does **not** count — it is discarded at session end; the Phase-doc checklist is the durable record, so mirror every `⬜→🟡→✅` change into it in the same step.
- **Untestable-by-AI items — be honest**: some items can't be verified by the AI alone (on-device feel, visual/audio judgment, real-player multiplayer, store/commerce — anything needing human eyes or a real client). Do NOT silently mark these `✅ Tested`. Tell the user plainly *which* items you couldn't test and *why*, leave them at `🟡 Implemented (untested)`, and ask the user to test; when they report back, reflect it into the checklist (`✅ Tested`, or send it back to fixing if it failed).

## State-mirroring triggers (Phase doc → GDD §6)

- **The all-`✅` check fires on the LAST `✅`, not later**: the moment a state update makes a Phase's items **all `✅ Tested`**, run **Completed-stage cleanup** (below) right then — before the next task, the next Phase, or its detailed plan. The condition has no other checkpoint, so if you skip it here it never runs. An all-`✅` Phase doc still sitting in `Docs/` means the cleanup was missed — run it on sight.
- **Phase gate (soft)**: if the user asks to start the **next Phase** while some items aren't yet `✅ Tested`, first **tell them which items are still untested**, then offer the choice **as a selectable prompt** (see [*Core principles*](../SKILL.md#core-principles-why-it-works-this-way) in SKILL.md): proceed to the next Phase anyway, or finish testing the untested items first. If the user still wants to proceed, **proceed** — it's a heads-up, not a block. **When proceeding, first mirror the leaving Phase's current per-item states (`🟡`/`✅`) into GDD §6**: §6 may lag only for the *active* Phase, never for a Phase you've moved on from (skipping this is how a GDD ends up all-`⬜` while several Phase docs hold the real states — and resume then misreads the milestone).
- **Mirroring is an in-place edit, never an append**: to mirror into GDD §6, update the existing rows (or rewrite that Phase's §6 block wholesale from the Phase doc) so the block ends with **exactly one row per task** and a Phase header that matches the rows. Never add an updated list next to the old one — duplicate rows with conflicting states corrupt the record worse than a lag would. **Self-heal §6 damage on sight**: duplicate task rows, markers outside `⬜/🟡/✅` (e.g. `⏭️`), or a Phase header whose "(k/n ✅)" count contradicts its rows get fixed the moment you notice them, **sourcing truth from that Phase's live doc**. ⚠️ **If the Phase doc is gone, do NOT reconstruct states from anything else** — `Archive/As-built.md` records systems, gotchas and log entries, **not per-task `⬜/🟡/✅`**, so reading states out of it means inventing them. A missing Phase doc means its stage cleanup already ran, which mirrored that Phase into §6 as all-`✅`; so repair is limited to **structural damage** (drop the duplicate row, replace an invented marker with the state its surviving row already carries, recount the header) — never change or fill in a state value that no surviving record evidences. If the structure alone doesn't settle it, state the ambiguity and **ask the user** rather than guessing; corroborating detail (what the As-built log or the workspace shows was actually built) may inform that question, but never silently decides it.

## Deferral & handoff

- **No silent deferral**: every checklist item is required (it wouldn't be in the checklist otherwise), so don't drop one mid-build with a "the prototype doesn't need it" rationale. If an item genuinely turns out non-required, **move it to the milestone roadmap (a future slot or its For later list) via a plan revision** (user confirmation + GDD §9 log) — never leave it parked as "Deferred" inside the checklist or anywhere in the GDD. **Items moved out by a revision (to another Phase, the roadmap, or dropped) are REMOVED from the leaving checklist** — the §9 entry is their record; `⬜`/`🟡`/`✅` are the ONLY states, don't invent markers (`⏭️` etc.) to park them in place.
- **A stub or dead-end in code is a deferral too — it needs a tracked item the moment it's written**: an intentionally blocked code path (a "not supported yet" guard, a bootstrap that skips a case, a button that only shows an info message) defers real scope, so at the moment you write it, that scope must gain a home — a checklist task in the current or a later Phase (BOTH docs, per the revision flow below), or a milestone-roadmap entry when it lands beyond this milestone. A code comment, an in-game message, or a note inside another item's line is **NOT** a tracking location. Corollary — **no `✅` with an untracked "-followup"**: an item may not be marked `✅` while its own notes push part of its scope to a follow-up that exists nowhere; create the follow-up item first (checklist or roadmap), then mark `✅`.
- **Phase-detail handoff**: after finishing a Phase detailed plan, offer the next step **as a selectable choice** (see [*Core principles*](../SKILL.md#core-principles-why-it-works-this-way) in SKILL.md) — **implement this stage** vs **write the next Phase N+1 detailed plan**.

## Completed-stage cleanup (mandatory)

Runs **only when a Phase's items are all `✅ Tested`** — at a `⏳ user-test boundary` (some items still `🟡`) it does **not** run and the Phase doc stays put (see [*Executing a Phase*](#executing-a-phase) above). Once they are all `✅`, in order — (1) **mirror the Phase's final states into the GDD §6 checklist** — mark the Phase done AND set each of its §6 items to `✅` (**only `✅` is written here**: this procedure runs at all-`✅`, so a `🟡` appearing anywhere means you are not at completion — stop and take the `⏳ user-test boundary` path instead), **adding any items the Phase gained through revisions** so §6 lists every task actually run (cross-check against the Phase doc *before* it is deleted — §6 is the surviving record; a GDD whose Stage says complete while §6 reads `⬜` is a self-contradiction the next session inherits); (2) **distill its as-built facts into `Archive/As-built.md`** (update the current-state map + one Phase entry of **≤15 lines** — what/why/gotchas only, no verify dumps or file lists (git keeps those); a **recurring** issue updates its Standing-issues row — Count + last-seen — instead of gaining a new entry, and Count ≥ 3 means propose a root-cause task; see the [As-built log template](gdd-template.md#as-built-log-template) guide); (3) **update the milestone roadmap's active-slot marker** to exactly `🔨 active (Phase k/n done)` (Status cell only — no percentages, no free-text status, and the roadmap's `Last updated` stays date-only); (4) **delete that Phase's detailed-plan md (`Docs/<game>-M<n>-Phase<k>.md`)** — a transient artifact that must not linger. Nothing is lost: the GDD roadmap keeps progress, `Archive/As-built.md` keeps the as-built record. (Always do 1–3 *before* deleting.)

## Milestone-complete cleanup (mandatory)

**Step 0 — vision-coverage check (before ANY completion claim)**: re-read the GDD **§1 one-line concept** and the roadmap's **`M<n>` slot line**, and trace **each capability they claim** to the `✅` checklist item(s) that implement it. All-`✅` alone is NOT completion — a checklist can be fully green while the milestone's stated vision is not built, because **tasks that were never planned leave no `⬜` behind** (the decomposition itself can have holes, e.g. "online PvP" milestones whose phases built infrastructure but no task ever made two humans actually meet). A claim with no implementing item is a **planning hole**: surface it to the user and either add the missing tasks (revision flow — the milestone stays open), or, with the user's explicit agreement, narrow the milestone's stated scope (reword the roadmap slot line + GDD §1, log in §9). Never resolve the mismatch by relabeling "done" with softer words.

Once **every** GDD roadmap item is `✅ Tested` — **verified by READING GDD §6 itself, never from the Phase doc or session memory**; the final Phase's completion does NOT skip its own Completed-stage cleanup — if §6 still shows `⬜`/`🟡` for that Phase, run the stage cleanup (mirror states into §6) first, and only then proceed — finish up: (1) set the GDD's `Stage` to complete; (2) **finalize `Archive/As-built.md`** so its current-state map reflects the whole milestone — and **compact the Log**: compress this milestone's entries into ONE `M<n> complete — summary` entry (≤15 lines) and delete its per-Phase/per-fix entries (git + the archived GDD + regression docs keep the detail), refresh the Standing-issues table, and if the file exceeds ~500 lines / ~30KB compact on sight (it must stay readable in one full Read — resume depends on it); (3) **update the milestone roadmap** — mark `M<n>` `✅ done` (one-line summary; the archived GDD is the full record), promote/re-order the remaining slots, and **review the For later list with the user** (slot, keep, or drop each item); (4) **move** `Docs/<game>-M<n>-GDD.md` into **`Archive/`** (project root, outside RootDesk; create if missing) — archived, not deleted, as this milestone's record. ⚠️ **Never overwrite an existing archived GDD**: if that name already exists in `Archive/` (shouldn't, under the `M<n>` rule), it signals a numbering error — **stop and flag it, don't silently rename**. **Leave `Docs/` in place** (the next milestone reuses it for a new GDD; the roadmap stays there permanently). Phase docs are **deleted by their own stage cleanup — never moved into `Archive/`**; if any still sit in `Docs/` at this point, their cleanup was missed — run it first. **A Phase doc found inside `Archive/` is residue of a missed cleanup too — heal on sight**: verify its final states are mirrored in the (archived) GDD's §6 (mirror them now if not), then delete the doc. Verify all items are truly `✅` first, then tell the user the milestone is complete + where things are. **A later milestone** follows the next-milestone flow in [*On startup*](../SKILL.md#on-startup--check-for-an-existing-gdd-resume--new--blocked) (new GDD promoted from the roadmap's next slot, reconcile first).

## Milestone blocked on user testing (`⏳ user-test pending`)

When everything the AI can do is done but items remain `🟡` awaiting user tests (real-multiplayer flows, on-device feel, commerce — every remaining non-`✅` item carries a "needs user test" note), the milestone is **NOT complete and gets no invented label** — statuses are a **closed set**, so never coin hybrids like "✅ code-complete". Do exactly this instead:
1. Run **Step 0 (vision-coverage check)** above now — user testing can only confirm what was built; it cannot fill a planning hole, so find holes *before* parking the milestone on the user.
2. **Mirror all current states into GDD §6** (in-place), including every Phase you're stepping away from.
3. Update `Archive/As-built.md`, stating **precisely which items await which user tests** — and what was NOT built, if Step 0 narrowed or flagged anything.
4. Set the roadmap's `M<n>` Status cell to exactly **`⏳ user-test pending`**. The GDD `Stage` stays active with a note (e.g. `Phase 3 — awaiting user tests`), the GDD stays in `Docs/`, and Phase docs holding `🟡` items stay in `Docs/` (their cleanup fires only on all-`✅`).
5. Tell the user **exactly which tests to run and what to look for**; when they report back, reflect the results (`✅ Tested`, or back to fixing) and re-enter the normal completion path above.

## Revising the plan mid-development (add / remove / change a rule)

Once the GDD exists and you're building phase by phase, the user may request changes to the plan. Handle the three kinds — **add**, **remove**, **modify** a planned rule/task — without breaking consistency with what's already built.

**First, check the horizon**: if the request adds work **beyond this milestone** ("later", "someday", "in the full version"), it is **not a GDD revision at all** — record it into the **milestone roadmap** right away (a future slot if the timing is known, its For later list if not; adding an item is always allowed, no waiting for a controlled moment), confirm the placement with the user in one line, and stop; no checklist/state impact, **no §9 entry** — the roadmap is that item's record. Only changes to **this milestone's** plan go through the steps below. ⚠️ The dividing line is *this milestone*, not *the future*: work **leaving** the current GDD for the roadmap (a scope cut) **does** get a §9 entry, because it changes this milestone's checklist — the pure-future case above does not.

For any revision:
1. **Classify** it — add a new rule, remove an existing rule, or modify an existing rule.
2. **Locate** what it touches — which GDD section (key decisions / core systems / roadmap / data-driven) and/or which Phase doc + checklist item(s). A GDD prose item (§2/§4/§5/§7) has no state of its own; determine whether it's already built by tracing it to the roadmap/Phase checklist items that implement it, then apply the `🟡`/`✅` impact rules (step 3) to those.
3. **Assess impact honestly *before* applying** — especially when it touches work already built (`🟡`/`✅`):
   - **Add**: the new item enters the checklist as `⬜ Not started`. If it belongs to a Phase already marked done, say so and place it in the current/next Phase rather than silently re-opening the done one.
   - **Modify**: if the target was `🟡`/`✅`, the built work likely needs redo → reset that item to `⬜` (or `🟡` if only re-testing is needed) and tell the user it must be re-implemented/re-verified.
   - **Remove**: if the target was already built, the code must be removed too → flag a removal task for the implementation skill, then drop the item from the plan/checklist.
   - Note any **dependent** rules/tasks the change ripples into.
   - ⚠️ If it touches a **core decision** (key-decisions table — e.g., map type ↔ Body, solo/multi & `@Sync`), warn strongly: it cascades through the whole stack and can invalidate much of what's built. Confirm before proceeding.
4. **Confirm scope when it affects built/tested work or a core decision** — surface the impact (which states reset, what code to remove, which dependents) and get the user's go-ahead. A pure addition to not-yet-started work can proceed directly.
5. **Apply to the docs** — update the relevant GDD section AND the Phase doc **together**: a task added/removed/modified in a Phase changes **BOTH** that Phase doc's checklist **and** the GDD §6 item list — never just one (an item that exists only in the Phase doc **vanishes** when that doc is deleted on completion; a §9 log entry alone does not put it in the checklist). Set the correct states, and **log the change in the GDD's "Plan changes" section** (type / what / why / impact) so the plan's history stays visible.
6. **Hand off code changes** — writing/removing/altering actual code (.mlua/.model etc.) is the implementation skills' job; this skill updates the plan, checklist states, and flags the implementation/cleanup tasks.
