# Unattended analysis (`<tracker-ref> autopilot`)

> The derivation contract for `/multi-agent:analysis <ref> autopilot`, the mode
> `phases.json` declares as `analysis-autopilot`. One row per question the
> attended chain asks: what an unattended run answers instead, and from which
> evidence. A question no row can settle parks the run. Nothing here is a
> default taken because nobody answered - that is the thing this file exists to
> keep out of the analysis document.

<!-- toc -->
- [When it applies](#when-it-applies)
- [The rule](#the-rule)
- [The derivation table](#the-derivation-table)
- [Running it](#running-it)
- [Parking](#parking)
- [After intake](#after-intake)
- [What it never does](#what-it-never-does)
<!-- /toc -->

## When it applies

The command was invoked as `<tracker-ref> autopilot`: a Jira key or
`owner/repo#N` followed by the modifier. `MULTI_AGENT_UNATTENDED=1` without the
modifier is a different contract - the background shape in
`$HOME/.claude/multi-agent-refs/picker-contract.md`, which parks on every
picker the launch request did not answer and derives nothing.

Phase 0 records the mode before anything else: `mode: "analysis"`,
`autopilot: true`, `status: "in_progress"`, `currentPhase: 0` and `sessionId`
from `MULTI_AGENT_SESSION_ID`, through `write-state.mjs`. A run with no
argument at all refuses at the entry gate (`_entry-picker.md`,
`refuse-unattended`) and never reaches a question.

## The rule

Three outcomes per question, and only three:

| Outcome | When | Recorded as |
|---|---|---|
| **Derived** | evidence the run already holds settles it | one `decisions[]` entry with the evidence as its `why` (`features/autopilot-decisions.md`) |
| **Empty answer** | the evidence says there is nothing, and nothing is a real answer | the same, with the emptiness as the `why` |
| **Parked** | the answer would change what the document IS, and no evidence settles it | `status: awaiting_input`, the reason, and the queue lists the item as awaiting |

A fourth outcome - taking the first option because nobody is there - is not
available. An analysis document is read as a decision record, so a question
answered by option order produces a document nobody agreed to, which is worse
than no document.

## The derivation table

Rows follow the attended chain's own order (`analysis/intake.md`), so a park
names the question the person would have been asked first.

| Step | Question | Unattended answer | Evidence |
|---|---|---|---|
| 1 | Analysis name | the item's summary, verbatim | the queued item (Jira `summary`, GitHub issue title) |
| 1b | Profile | the one profile `prefs.global.analysisProfiles` offers | the preference; **parks** when it offers more than one |
| 1b | Custom outline | the configured outline path | **parks** when the single profile is `custom` and no outline is configured |
| 2 | Account | the account whose tracker returned the item | the item's own source; it is the credential that fetched it |
| 3 | Platforms | the distinct stack tags of the repos below | the repo scan, which is what the attended step derives from before it offers to ask |
| 3 | No platform at all | a real answer, not a gap (Locked 34) | an untagged repo; the development layer and Pass B drop and Section 20 records that they await a repo |
| 4 | Repos | the repo the item was queued for | the queue entry carries exactly one repo, so there is nothing to pick between |
| 5 | Figma, Confluence, Document, Jira, Swagger | the links the item's own text carries, typed by `context-link-extractor.sh` | the item; no link is an answer, and Phase 3.3 still searches the repo before anything is called open |
| 5 | Standards | `Auto-detect from repo`, the picker's own second option | a repo is present; `none` when none is |
| 5 | Firebase | `Auto-detect from repo`, the picker's own second option | a repo is present; `none` when none is |
| 5a | UI tests | `No UI tests` | the lighter side of an opt-in: a section nobody asked for is added by re-running analysis |
| 5a | A11y depth | `Basic checklist` | the same |
| 5a | Redesign | `New work` | the same; a redesign run also reads the v1 behaviour, which is a larger run than the queue was asked for |
| 3.5 | Output destination | the local file only, written into the run's own directory | an unattended run publishes nothing outside the machine (`features/unattended-security.md`, Phase 5 and channels) |
| 3.5 | Confluence parent, Jira issue, Jira write target | not asked and not taken: no Confluence page and no Jira write happens | the same |

The two parking rows are the whole of the park surface, and both are about the
same thing: the profile selects the template the entire document is rendered
against (Locked 31). Everything else is either in the item, in the repo, in the
preferences, or legitimately empty.

## Running it

Collect the evidence into one document and let the rules answer it:

```bash
node "$HOME/.claude/scripts/analysis-unattended.mjs" derive \
  --evidence "$RUN_DIR/analysis-evidence.json" --state "$STATE_FILE" --json
```

The evidence document is `{ref, source, title, profiles[], outline?, repos[],
links[], outputDir}`: the queued item, `prefs.global.analysisProfiles`, the
repo and its stack tag, the typed links from the item's text, and the directory
the run may write. Exit 0 prints the resolved intake (written to
`state.analysisSpec.*`) and the `decisions[]` entries it already recorded; exit
2 means the evidence document itself is unusable; exit 4 is a park.

## Parking

On exit 4 the verdict names the question, the reason and the fix. Park on it and
stop - never re-ask, never fall through to an option:

```bash
node "$HOME/.claude/scripts/gate-ledger.mjs" park --outcome awaiting-answer \
  --waiting-for question --question-file "$Q_FILE" --state "$STATE_FILE"
```

`$Q_FILE` carries the question in the shape a client answers (`id`, `stepId`,
`text` in `outputLanguage`, `kind`, `options[]` of `{id, label}`) - for the
profile park, one option per profile the preference offers. A park whose
question has no option set (the analysis name) is written with
`--waiting-for analysis-name --reason "<the verdict's reason>"` and no question
file; a person re-enters it with `/multi-agent:resume <task-id>`.

The queue lists a parked item as awaiting and never re-runs it on its own, so a
park costs one scan, not a retry loop.

## After intake

- **Phase 3.3** is unchanged and already written for this case: bucket A still
  runs its searches, and a bucket B gap is moved to C stamped
  `autopilot: could not ask` (`analysis/render.md`). A search needs no person;
  a judgement does.
- **Phase 4** publishes the local file and nothing else. Locked 6 still forbids
  `git add` and `git commit`, so the document is delivered where it was written.
- **Phase 5** runs with `--file-only`: the report lands under the run's log
  root and no channel is posted.
- The run ends at Phase 5 with `status: complete`, which is what the queue
  records as `doc-delivered` - the analysis equivalent of a pull request.

## What it never does

- Ask. There is nobody to answer, and a question that waits is a run that
  produced nothing.
- Take an option because it was first. Every answer above names its evidence.
- Create a branch, a worktree, a commit or a pull request - the side-effect
  contract of the analysis command is unchanged by the modifier.
- Post a Confluence page, write a Jira description or comment, or send a
  channel report.
- Fetch a design source outside Phase 1 (Locked 29).
