---
name: heal
description: Run the heal autopilot agent to (a) create or edit a Playwright test in this repo, or (b) drive a live browser through a flow and verify a feature works without writing a test file. Use when the user asks to write/extend a Playwright test, or to check that a flow still works on a real site (staging, production, localhost). Do not use for non-Playwright tests, for plain code edits, or for static analysis.
argument-hint: <build|navigate> "<request>"
arguments: [mode]
allowed-tools: mcp__heal__heal_autopilot_start mcp__heal__heal_autopilot_poll mcp__heal__heal_autopilot_answer mcp__heal__heal_autopilot_cancel AskUserQuestion
---

# heal autopilot

Drive the heal autopilot through MCP. Two modes:

- **`build`** — autopilot writes or edits a Playwright `.test.ts` file in the repo.
- **`navigate`** — autopilot drives a real browser to verify a feature; no test file is written.

Each run spins up a real browser, takes minutes, and consumes tokens. Do not relaunch on failure without asking the user.

## Dispatch

`$0` selects the mode. The rest of `$ARGUMENTS` after the mode is the user request to forward to autopilot.

If `$0` is missing or not `build`/`navigate`, ask the user which mode they want before doing anything.

## Run loop

1. Call `heal_autopilot_start({ mode: $0, request: <rest of $ARGUMENTS> })`.
2. Loop on the response:
   - Render `events` to the user — one short line per event. Skip `thinking` / `thinking-end` (they're noise). For `tool` events, show `name` + `summary`. For `assistant` events, show the text. For `iteration`, show `iteration N/M`.
   - If `status` is `succeeded`, `failed`, or `cancelled`: summarise (use `finalMessage` / `finalError`) and stop. In `build` mode, the deliverable is the test file path autopilot logged — surface it.
   - If `pendingQuestion` is set: ask the user. If the question's `options` array is non-empty, use `AskUserQuestion` with those labels. Otherwise plain text. Then call `heal_autopilot_answer({ runId, answers: { [questionId]: <reply> } })` and continue the loop.
   - If `pendingSecurityGate` is set: this is a **security decision**, not a clarification. **Always** route through `AskUserQuestion` with the violation's `action` as the question and the `reason` + `detail` in the question body. Provide exactly two options: `Allow` and `Deny`. **Never auto-approve, even if the request looks benign** — the user must make the call. Then send `heal_autopilot_answer({ runId, gate: { gateId, decision: "allow" | "deny" } })` and continue the loop.
   - Otherwise (`status === "running"` with no `pendingQuestion` or `pendingSecurityGate`): call `heal_autopilot_poll({ runId })` and repeat.

Each `poll` blocks server-side for ~25s, so the loop is naturally paced — don't add your own sleeps.

## After the run

- **build mode:** Find the new/edited `.test.ts` file in the events stream (search `tool` events with `name: "write"` or `name: "edit"`). Surface that path to the user. Do not edit the file yourself in the same turn — let the user review the diff first.
- **navigate mode:** No file is written. Summarise the autopilot's `finalMessage` for the user.
- On `failed`, summarise `finalError` and stop. Do not retry automatically.

## Cancellation

If the user asks to stop, call `heal_autopilot_cancel({ runId })`. The autopilot stops at the next safe point and the next `poll` returns `status: "cancelled"`.
