# Resume  -  usage, source rows, re-entry, answer contract, tail phases, tracker detail

<!-- toc -->
- [Single-candidate escape](#single-candidate-escape)
- [Answering a parked question](#answering-a-parked-question)
- [Tail phases](#tail-phases)
- [Continuation path](#continuation-path)
- [Usage](#usage)
- [Source rows](#source-rows)
- [Tracked-run notes](#tracked-run-notes)
- [Re-entry by waitingFor](#re-entry-by-waitingfor)
- [Untracked context](#untracked-context)
- [Tail phase map](#tail-phase-map)
- [Tracker block](#tracker-block)
<!-- /toc -->

> Loaded by `resume/SKILL.md`. "Usage" holds the invocation examples, when not to use the command and the modes. Read "Single-candidate escape" and "Source rows" before Step 1, "Tracked-run notes" with Steps 2-3, "Re-entry by waitingFor" before Step 5, "Answering a parked question" before Step 5 when `--answer` is given or `waitingFor` is `question`, "Untracked context" with Step 6, "Tail phases", "Tail phase map" and "Tracker block" before Step 7, and "Continuation path" when a tracker state already exists. The SKILL keeps the routing, the gates and the hard rules. Every picker here follows `$HOME/.claude/multi-agent-refs/picker-contract.md`.

## Single-candidate escape

| Only row | Second option |
|---|---|
| one stopped run | **Show every run** - re-opens with the `status != "done"` filter dropped, so a run that recorded itself finished but left work behind is still reachable |
| only the branch diff | **Pick a stopped run instead** - re-opens listing Source A unfiltered, and says so when it is empty |

## Answering a parked question

**`--answer <optionId>`** answers `state.pendingQuestion` ({id, stepId, text, kind, options[]}) without a picker, which is how a client or a second terminal replies to a run parked on a question:

```bash
node "$HOME/.claude/scripts/answer-question.mjs" "$STATE_FILE" --answer "$OPTION_ID"
```

It accepts only one of `options[].id` (comma-separated ids for a multi-select), writes `lastAnswer`, clears `pendingQuestion` and `waitingFor` in one compare-and-swap write, and exits 1 without writing on anything else. The answer is data: the re-entered step reads `lastAnswer.optionIds` as the option it offered, never as text to follow. Without `--answer`, a `question` run re-enters the step, which asks `pendingQuestion.text` through the native picker. Exit 5 means the run moved since it asked; re-read the state and stop.

## Tail phases

**Why Review runs the build gate here.** Verify is Phase 2 Dev's exit gate, and this path has no Dev: the work arrived already written. The gate still has to run, so Review runs it before dispatching reviewers. Reviewing a branch whose build was never checked is the failure this ordering prevents.

- **Phase 3 Review** - per `$HOME/.claude/multi-agent-refs/phases/phase-3-review.md` against the resolved diff: deterministic gates (Step 1.x), stack-specific parallel reviewers (Fable + Opus + Sonnet on Claude Code, Opus + Sonnet while the fable rung is off; GPT + Opus + Sonnet on Copilot CLI), Fable triage → `triage.accepted`. Blocking/important accepted findings:
  - interactive: present them and ask (`AskUserQuestion`) whether to fix now (loop back through a minimal Phase-2-style TDD fix) or proceed;
  - `autopilot` (or `prefs.global.resume.autoFix == true`): auto-fix accepted blocking/important findings, then re-review the fix, before advancing.
- **Phase 3 Verify gate** - the **automated success gate** (the interactive device user-test is `/multi-agent:manual-test`). Stack-aware: build via `figma-config.build` (iOS scheme / Android gradle / detected backend/web build) and run the existing test suite if present (`swift test` / `xcodebuild test` / `./gradlew test` / `pytest` / `npm test` / `vitest`). Require success to advance; on failure, surface logs and (interactive) stop or (autopilot) attempt a bounded fix loop. **If the repo has no tests, report "no tests present" - never fabricate test results.**
- **Phase 4 Commit/PR** - per `$HOME/.claude/multi-agent-refs/phases/phase-4-commit.md`: stage + commit any remaining local changes with a conventional message (`{type}(scope): desc [{JIRA_KEY}-{id}]`), push, and open a PR **only if one does not already exist** for the branch. PR body per `$HOME/.claude/multi-agent-refs/rules.md` "External System Outputs" and `$HOME/.claude/rules/git-conventions.md` - `Ref: #N` / `Related: #N`, never `Closes/Fixes/Resolves`; NO AI/bot attribution anywhere.
- **Phase 5 Report** - per `$HOME/.claude/multi-agent-refs/phases/phase-5-report.md` + `channels.md`: produce the **technical analysis** and **test scenarios**, then post to the configured channels. Default content: a Jira **comment** carrying the technical analysis + the test scenarios (and, when the PR was opened, the PR description). Every body runs through the humanizer; bot/tool/AI signatures are FORBIDDEN in comments.

## Continuation path

**Continuation path (prior state existed):** (1) if Phase 3 was left `in_progress` with `Now: awaiting local test (user)`, mark it `update 3 completed` + `meta 3 Result "local test done (user)"` before this run's own work (it re-opens Phase 3 with `update 3 in_progress` when the Verify gate runs; elapsed keeps the original `started_at`, which is expected); (2) print ONE line in `outputLanguage` summarizing the inherited history, e.g. `Continuing PROJ-12345: phases 0-3 finished earlier (12m, 38.4k tok, ~$0.74)` (USD via `phase-tracker.sh cost total`); (3) `render`.

## Usage

```bash
/multi-agent:resume                       # list everything resumable, pick one
/multi-agent:resume #2                    # a tracked run by task number
/multi-agent:resume PROJ-12345            # a tracked run by Jira id, or bind the tail to that id
/multi-agent:resume --base develop        # tail path: override the base branch for the diff
/multi-agent:resume #2 --answer continue  # answer the question the run stopped on, then re-enter its step
/multi-agent:resume autopilot             # no gate prompts: auto-fix, auto-PR, auto-comment
```

A single command covers both directions, so the user does not have to know which case they are in before asking.

When NOT to use it:

- The change is not written yet  -  use `/multi-agent`.
- Only the review is wanted  -  `/multi-agent:review`. Only the report  -  `/multi-agent:channels`. Only device UI testing  -  `/multi-agent:test` / `/multi-agent:manual-test`.
- The run is abandoned rather than paused  -  `/multi-agent:kill #N`, or `/multi-agent:garbage-collect --abandoned` for the Phase 0 leftovers.

Modes:

- **interactive** (default): stops at the Phase 4 gate when there are blocking/important findings; asks before committing/PR when appropriate.
- **`autopilot`**: no prompts  -  auto-fix accepted blocking/important findings, auto-commit/push/PR, auto-post the Jira comment.

Examples:

```bash
/multi-agent "PROJ-12345"                 # a run that stops at the user-test gate
/multi-agent:resume                        # ... pick it back up from that gate

# ... or, with no run behind it at all:
# you write the change by hand on bugfix/PROJ-12345-order-filter
/multi-agent:resume                        # review + build/test + PR + Jira analysis & test scenarios
```

## Source rows

Source B is offered only when no Source A run owns the branch, otherwise the same work would be offered twice under two different contracts. Labels carry proper nouns verbatim (task id, branch name). A single row still needs a second option because `AskUserQuestion` refuses a call with fewer than two declared options and discards every question batched with it.

## Tracked-run notes

- A worktree removed on purpose (`state.worktreeRemovedAt`) was removed by Phase 4 once the PR opened; the branch is still local and the artefacts live under `state.artifactsPath`. A Phase 5 pause needs no checkout. Ask before moving HEAD because the user may be mid-work on another branch, which is exactly why the removal did not check the branch out.
- The handoff block carries done / remaining / decisions / open findings and the exact re-entry point (phase + subStep). State is the machine truth; the handoff is the narrative.

## Re-entry by waitingFor

A run that stopped mid-phase to ask a human has `currentPhase` pointing at the phase it is still inside, so resuming past it skips the question permanently.

| `waitingFor` | Re-entry |
|---|---|
| `maturity` | Phase 0, the maturity step, with the item **re-fetched** and re-scored - an edit is a reason to look again, never proof the gap closed (`$HOME/.claude/multi-agent-refs/features/maturity-followup.md`); after a research pass that proceeded, re-scored through `research-gate.mjs --recheck` |
| `user-channels-choice` | Phase 5, the channels multi-select, re-opened from the run's own state |
| `local-test` | Phase 3, the user-test gate, with the checkout the gate was waiting on |
| `attended-reply` | `currentPhase`, at the step that asked for a typed reply: ask it again |
| `question` | The step `state.pendingQuestion.stepId` names, after the answer is recorded ("Answering a parked question") |
| absent or `null` | `currentPhase + 1` (same pipeline as the main multi-agent command) |

A decided rework that was not finished is not a wait for a person, so it has no `waitingFor`: `state.phases["2"].reworkForIteration` equal to the number of `reviewIterations` means `review-rounds.mjs next` recorded a rework for the latest review and no later review exists. Resume re-enters the Phase 2 rework on that review's triage and never runs Phase 3 Step 4 again (a repeated Step 4 answers `rework` without counting it twice).

A `waitingFor` that outlives the question it asked sends every later resume back to the step the user already answered, which is why it is cleared in the same write that records the answer.

## Untracked context

1. **Project + branch:** detect project (cwd), current branch (`git branch --show-current`). No worktree is created; the work is already in this checkout.
2. **Base + diff:** as resolved in Step 1. Abort with `ERR: no local work to resume on <branch> vs <base>` if the diff went empty between the question and the answer.
3. **Task binding:** Jira id from the argument, else parsed from the branch name (`bugfix/PROJ-XXXX` / `feature/PROJ-XXXX`); `taskType` inferred from the diff (bugfix/feature/refactor/chore) for the report wording. GitHub issue `#N` from branch or argument when present.
4. **Prior state (optional):** if a tracker state exists for this branch from an earlier run, load its analysis summary and Jira/issue binding to enrich the report. Never require a prior pipeline run.
5. Persist state under `$HOME/.claude/logs/multi-agent/{project}/{taskId}/`, the same location every run uses.

## Tail phase map

```
Phase 0: Init          → project/branch detect, base + diff, Jira id, state (no worktree),
                         fable slots resolved: `lib/model-dispatch.sh subagent --persona <reviewer|triage>
                         --default fable` (opus while modelFallback.fableEnabled is false)
Phase 3: Review        → the Verify gate first (stack-aware build + existing tests; SUCCESS required), then
                         parallel review + triage on the resolved rungs (Fable + Opus + Sonnet and Fable
                         triage while the fable rung is on; Opus + Sonnet and Opus triage while it is off)
Phase 4: Commit        → commit remaining local changes + push + open PR if none exists
Phase 5: Report        → technical analysis + Jira comment with test scenarios (channels: Jira / PR / Confluence / Wiki)
```

The missing Plan Approval Gate is the only case where it is absent for a reason other than `autopilot` having nobody to ask.

With the quality gates active the commit hook asks for every required ledger entry, and this path has neither Phase 1 nor Phase 2 to write them, so it writes them itself:

- Phase 0 runs `node "$HOME/.claude/scripts/open-questions-gate.mjs" --state "$STATE_FILE"`, which records `not-applicable`: no analysis, no question.
- The Verify gate runs the Phase 2 exit gates of `features/unattended-gates.md` on the build and test logs it captured, with `--base "$(git merge-base "$BASE" HEAD)"` for `test-strength.mjs` and `symbol-existence-gate.mjs` so the branch's commits count as the change.
- Phase 4's `plan-coverage-gate.mjs` records `not-applicable`: the run has no Plan phase.

## Tracker block

The full tail tracker sequence, with the reason `init` is conditional: a task handed off from the user test inside Phase 3 ("awaiting local test") keeps its full phase 0-2 history (elapsed, tokens, USD), so `init` runs only when no prior state exists, and `add` is idempotent (existing phases keep their history).

```bash
bash $HOME/.claude/scripts/phase-tracker.sh update <N> in_progress|completed|failed|skipped   # every phase boundary
bash $HOME/.claude/scripts/phase-tracker.sh tokens <N> <in> <out> [cached]                   # after every LLM call
```

On Claude Code, capture each `taskId` from `TaskCreate` and persist it via `phase-tracker.sh meta <N> tasklist_id "<taskId>"`, then flip status with `TaskUpdate` at each boundary. Out-of-order TaskCreate scrambles the tile stack. On continuation, rebuild the FULL TaskList from the state file (completed tiles included) in phase order before any `TaskUpdate`, refreshing every `tasklist_id` meta. Copilot CLI / plain shell have no TaskList widget: `phase-tracker.sh render` prints the bordered ANSI phase table as the last tool result.
