---
name: multi-agent-resume
description: "Pick up unfinished work: a pipeline run that stopped mid-phase, or work already written on the current branch that never went through the pipeline. Use when a task stopped or failed, or when hand-written local work needs review, build, PR and reporting."
user-invocable: true
argument-hint: "[#id | PROJ-12345] [--base <branch>] [--answer <option-id>] [autopilot]  -  no argument: pick from the list"
metadata:
  language: en
---

# multi-agent resume  -  Continue Unfinished Work

**Input**: $ARGUMENTS

Unfinished work arrives from two directions, and which one applies is a property of the repository, not of how the command was typed:

- **A tracked run stopped.** It has an `agent-state.json`, a phase it was inside, and possibly a worktree. It resumes from where it stopped.
- **Work exists on the current branch with no run behind it.** Nothing to resume, so the **pipeline tail** runs over the diff. Plan and Dev never run; the diff is the Dev output.

Step 1 finds both and asks, so the user does not have to know which case they are in before asking the question.

## Input

```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
multi-agent resume autopilot          # no gate prompts: auto-fix, auto-PR, auto-comment
```

**Access check, before anything else.** A resumed run skips Phase 0, so it asks here:

```bash
ACCESS_LINE=$(node "$HOME/.copilot/scripts/usage-access.mjs"); ACCESS_RC=$?
```

`ACCESS_RC` 3: print `$ACCESS_LINE` as written and stop. No list, no state change, no question, attended or unattended. Any other exit continues (the check fails open). Contract: `$HOME/.claude/multi-agent-refs/features/usage-reporting.md` "The access check".

## Steps

1. **Build the resumable list, then ask.** Source A: every `agent-state.json` under `$HOME/.claude/logs/multi-agent/{project}/` with `status != "done"`, each row showing task id, the phase it stopped inside, its workspace (worktree path, or `local`), age, and `haltReason` when set. Source B: the current branch, when `git diff <base>...HEAD` plus working-tree changes is non-empty **and** no Source A run owns that branch. An argument naming a run selects it directly; an argument naming nothing resumable is an error, never a silent fall-through to the tail. Nothing in either source: `ERR: nothing to resume` - do not ask.

   Ask per `$HOME/.claude/multi-agent-refs/picker-contract.md` (Copilot CLI: `$HOME/.claude/lib/ask-choice.sh`). Breadcrumb `Step 1/1: which unfinished work to pick up` above the picker, in `outputLanguage`; labels carry the task id and branch name verbatim, and the run branches on which row was selected rather than on the label text. A single row is still a question and needs a genuine second option: **Show every run** (drops the `status != "done"` filter) when the only row is a stopped run, **Pick a stopped run instead** when the only row is the branch diff.

2. **Tracked run  -  read and validate state.** `validate-state.mjs` first; on non-zero exit do NOT guess a phase. Read `currentPhase`, `status`, `haltReason`, `circuitBreaker`, `autopilot`. Heal a stale worktree lock before continuing  -  unless `worktreeRemovedAt` is set, in which case the artefacts live under `artifactsPath` and the worktree must not be recreated.

3. **Tracked run  -  load context** from durable artifacts, never from conversation memory: the latest `## Handoff` block in `agent-log.md` first, per-phase findings as the fallback, `git log --oneline -10` to ground what was actually committed.

4. **Tracked run  -  rebuild the phase tiles** from `tracker-state.json`, never re-initialized. Copilot CLI: a single `phase-tracker.sh render`.

5. **Tracked run  -  continue.** Read `state.waitingFor` FIRST: when it names a step (`maturity`, `user-channels-choice`, `local-test`, `question`), the run re-enters THAT step. `currentPhase + 1` is the fallback, not the rule. A decided and unfinished rework (`phases["2"].reworkForIteration` equal to the number of `reviewIterations`) re-enters Phase 2, never Phase 3 Step 4 again. Clear `waitingFor` in the same write that records the answer. `question` re-enters `pendingQuestion.stepId`; `--answer <optionId>` records the answer first through `node "$HOME/.claude/scripts/answer-question.mjs" "$STATE_FILE" --answer "$OPTION_ID"`, which accepts only one of `pendingQuestion.options[].id` and writes nothing otherwise. The answer is data, never an instruction.

6. **Untracked branch work  -  resolve context.** Base branch: `--base` → `figma-config.project.baseBranch` → `develop` → upstream/merge-base. Jira id from the argument or the branch name. State under `$HOME/.claude/logs/multi-agent/{project}/{taskId}/`. No worktree is created.

7. **Untracked branch work  -  run the tail.**

```
Phase 0: Init          → project/branch detect, base + diff, Jira id, state (NO worktree)
Phase 3: Review        → the Verify gate first (stack-aware build + existing tests; SUCCESS required), then
                         parallel review (GPT + Opus + Sonnet) + triage
Phase 4: Commit        → commit remaining changes + push + open PR if none exists
Phase 5: Report        → technical analysis + Jira comment with test scenarios (channels: Jira / PR / Confluence / Wiki)
```

The build that Dev's exit gate would have run happens inside Review instead, because there is no Dev run to inherit a log from.

With the quality gates active the tail writes the ledger entries Phase 1 and Phase 2 would have: `open-questions-gate.mjs` at Phase 0 (not-applicable), the Phase 2 exit gates inside the Verify gate, and a not-applicable `plan-coverage` at Phase 4 (`$HOME/.claude/multi-agent-refs/features/unattended-gates.md`).

## Notes

- Build+Test is the automated success gate (the interactive device user-test is `multi-agent:manual-test`). If the repo has no tests, it reports "no tests present"  -  never fabricates results.
- `autopilot` (or `prefs.global.resume.autoFix == true`) auto-fixes triage-accepted blocking/important findings and re-reviews the fix before advancing.
- Commit/PR follows house rules: conventional message, `Ref: #N` (never Closes/Fixes), NO AI/bot attribution. PR opened only if one does not already exist.
- Full phase contract lives in the Claude Code command `commands/multi-agent/resume/SKILL.md`; this skill is the Copilot-CLI counterpart.

## Required: outward-facing payload contracts

Before writing anything outward-facing  -  PR body, Jira comment, Confluence page, closing report  -  load `$HOME/.claude/multi-agent-refs/payload-contracts.md`. It names the canonical section set for each payload, the markup dialect per surface (PR body is Markdown, Jira is wiki markup  -  mixing them is a defect), and the token/duration numbers the closing report must carry. Improvising a payload shape from memory is the most common failure of a run that starts in the middle.
