# debug — Step through a YAML test

Read `_shared/package-manager.md` and `_shared/secrets.md`. Follow the shared
version/update check before running the project CLI. Resolve the requested YAML
file; if none was specified, inspect the project and ask the user to choose a test.
Run `npx shiplight debug <file>` using the project's package manager and existing
agent process-management tools. Keep the server alive while the user debugs and
return its URL. Web tests use the browser view. Android/iOS tests run on the real
phone, emulator or Simulator; the debugger displays completed-step screenshots.

While the debugger UI is open, keep monitoring the managed CLI process's stdout and
exit state with the existing process tools, using waits of at most 60 seconds so
user input remains responsive. When switching a file from the directory browser to
native debugging, the CLI emits a JSON line like
`{"type":"debugger_restart","testFilePath":"/absolute/path/test.yaml"}` and
exits with code 2 after closing its sessions. Parse that line, then relaunch
`npx shiplight debug <testFilePath>` (adding `--device <deviceId>` when the event
contains one). This restart event only identifies the requested file and optional
device; it is not approval to provision or change a device. Wait for the relaunched
CLI's `debugger_preflight` result. If it reports `device_required`, follow the
approval workflow below before making setup changes. If the restart event is absent,
or the process exits for another reason, report the actual process output and exit
state instead of assuming the handoff succeeded.

## Native device readiness

The CLI performs read-only preflight before opening its UI. If it returns
`debugger_preflight` with `device_required`, do not open the debugger UI or start
the test; return control to the agent and perform the following workflow. Merely
showing or copying a provisioning prompt is insufficient.

1. Inspect installed tooling and available Android devices or iOS Simulators/phones
   without changing setup. Prefer an existing virtual device for the test platform.
   For `choice_required`, ask which device to use and retry with its identifier.
   For an explicitly requested unavailable/busy device, resolve that device's blocker;
   do not silently choose another.
2. Propose a concrete device setup, naming the device/platform and any required
   downloads, creation, boot or configuration changes. Obtain the user's explicit
   approval **before** making any of those changes. `/shiplight debug` itself is
   not approval. If the user declines or does not answer, stop setup and execution.
3. After approval, use the agent's existing tools to perform the approved setup.
   Reuse or boot an existing emulator/Simulator first; install components or create
   one when needed and approved. Real Android phones and iPhones are supported:
   help configure them and ask the user to perform physical connection, trust,
   developer-mode or signing actions that require their involvement. Do not invent
   identifiers or signing credentials. Respect tool-level installation permissions.
4. Discover the resulting device again and verify that it is ready and authorized.
   Retry `npx shiplight debug <file> --device <serial-or-UDID>` with that exact device.
   If recovery needs setup changes outside the approved scope, ask for fresh approval
   before making them. For a recoverable provisioning failure, diagnose it and attempt
   recovery using only changes already approved; rediscover and verify readiness before
   retrying the debugger. If recovery needs a user action or remains blocked, report the
   specific blocker and ask for that action. Do not start the test against an unverified
   device.

Do not change the YAML's app/reset configuration to bypass a device issue. Debugger
reset restarts the session without clearing app data; it does not undo backend
side effects. Stop the debugger process when the user finishes or asks to stop.
