# Live viewer, annotations & test healing

Source: https://olef.dev/docs/guides/live-viewer

**Outcome:** collaborate visually with your coding agent on a live Android screen, pointing at exact UI issues, recording flows by hand, auditing selector stability, and repairing broken tests without weakening assertions.

## Visual collaboration loop

> **Diagram:** Live viewer workflow: Human circles an element in Annotate mode, Olef maps it to selector and Compose file:line plus cropped PNG, Agent applies fix in ~1.5s, and test run verifies.
>
> Instead of describing "the second small icon near the top right," circle it once and let Olef hand your agent the exact selector and Compose source file:line.

## 1. Open the live device viewer

The Claude Code and Codex plugins (`olef init`) embed the interactive viewer directly alongside your conversation. You can also launch the loopback viewer standalone from any terminal:

```bash
olef pane
```

For cloud emulators and remote leased phones, use `ocloud emulator viewer <name>` or `ocloud devices view <spec>` to get a hosted browser viewer link.

## 2. Circle a bug with Annotate mode

In the viewer, switch to **Annotate**, outline one or more elements on screen, and leave a short note on each (for example, *"Padding clips on small screens"* or *"Button stays disabled after filling email"*).

Your agent then reads every note in one structured call:

```bash
olef pane annotations
```

For each note, Olef returns:
- Your comment text
- The matched UI element and a stable selector for it
- The composables that drew it with **`file:line`** source locations (when project source mapping is configured)
- An overview PNG with every note outlined and numbered, plus close-up crops for small targets

Reading annotations clears them from the viewer so they are not reprocessed; pass `--keep` to retain them.

## 3. Audit selectors & generate Screen Objects

Before writing or recording tests, check which interactive elements on the current screen lack stable selectors (`resource-id` or Compose `testTag`), or audit accessibility issues:

```bash
olef ui audit
olef ui audit --a11y
```

To scaffold typed test helpers from a real screen, generate a starting-point Kotlin Screen Object with stable selectors filled in and untagged elements marked as `TODO`:

```bash
olef ui gen
```

## 4. Heal broken regression tests safely

When an intentional UI refactor changes a label or resource ID and a saved test fails, ask Olef to inspect the failure artifacts and propose a minimal patch:

```bash
olef test heal <failed-run-dir>
```

`test heal` matches the failed step against the closest candidate selectors captured at failure time (or highlights a changed expectation for you to confirm). It **never edits the script automatically** and never weakens assertions silently.

See [`olef pane`](https://olef.dev/docs/reference/cli/pane), [`olef ui`](https://olef.dev/docs/reference/cli/ui), and [`olef test`](https://olef.dev/docs/reference/cli/test).
