---
description: "Mobile UI Bug Hunter  -  iOS Simulator (simctl) + Android Emulator (adb)  -  auto-detects platform"
allowed-tools: Agent, Bash, Read, Write, Edit, TaskCreate, TaskUpdate, TaskList, TaskGet, mcp__multi-agent__ios_list_devices, mcp__multi-agent__ios_boot_device, mcp__multi-agent__ios_screenshot, mcp__multi-agent__ios_tap, mcp__multi-agent__ios_swipe, mcp__multi-agent__ios_type_text, mcp__multi-agent__ios_launch_app, mcp__multi-agent__ios_terminate_app, mcp__multi-agent__ios_list_apps, mcp__multi-agent__ios_go_home, mcp__multi-agent__ios_set_appearance, mcp__multi-agent__ios_set_content_size, mcp__multi-agent__ios_set_locale, mcp__multi-agent__ios_open_url, mcp__multi-agent__ios_status_bar, mcp__multi-agent__ios_push_notification, mcp__multi-agent__ios_grant_permission, mcp__multi-agent__ios_revoke_permission, mcp__multi-agent__ios_reset_permissions, mcp__multi-agent__ios_set_location, mcp__multi-agent__ios_clear_location, mcp__multi-agent__ios_set_increase_contrast, mcp__multi-agent__ios_record_video, mcp__multi-agent__ios_add_media, mcp__multi-agent__ios_keychain_reset, mcp__multi-agent__ios_get_app_container, mcp__multi-agent__ios_erase_device, mcp__multi-agent__ios_get_ui_tree, mcp__multi-agent__ios_accessibility_audit, mcp__multi-agent__ios_accessibility_audit_deep, mcp__multi-agent__ios_list_crashes, mcp__multi-agent__agent_run_steps, mcp__multi-agent__android_list_devices, mcp__multi-agent__android_screenshot, mcp__multi-agent__android_tap, mcp__multi-agent__android_swipe, mcp__multi-agent__android_type_text, mcp__multi-agent__android_key_event, mcp__multi-agent__android_launch_app, mcp__multi-agent__android_stop_app, mcp__multi-agent__android_list_packages, mcp__multi-agent__android_go_home, mcp__multi-agent__android_go_back, mcp__multi-agent__android_get_ui_tree, mcp__multi-agent__android_set_dark_mode, mcp__multi-agent__android_set_font_scale, mcp__multi-agent__android_set_locale, mcp__multi-agent__android_set_location, mcp__multi-agent__android_grant_permission, mcp__multi-agent__android_revoke_permission, mcp__multi-agent__android_record_screen, mcp__multi-agent__android_install_apk, mcp__multi-agent__android_uninstall_app, mcp__multi-agent__android_logcat, mcp__multi-agent__android_get_screen_size, mcp__multi-agent__android_open_url, mcp__multi-agent__android_clear_app_data, mcp__multi-agent__android_accessibility_audit, mcp__multi-agent__android_list_crashes, mcp__multi-agent__ios_visual_diff, mcp__multi-agent__design_contrast_check, mcp__multi-agent__ui_locate, mcp__multi-agent__ios_tap_element, mcp__multi-agent__android_tap_element, mcp__multi-agent__ui_hit_test, mcp__multi-agent__ui_target_check, mcp__multi-agent__ui_region_changed, mcp__multi-agent__media_frames
---

# Mobile UI Bug Hunter

Auto-detects platform: iOS (simctl) or Android (adb). No external apps needed.

- **iOS**: Xcode + Simulator
- **Android**: Android SDK + Emulator (or physical device via USB)

> **Note**: Tool names above assume MCP server is registered as `multi-agent`. If you used a different name in your settings.json, update the `allowed-tools` list accordingly.

## Platform Detection

```
1. Check cwd for .xcodeproj / Package.swift -> iOS
2. Check cwd for build.gradle / build.gradle.kts -> Android
3. Check running devices: simctl list booted / adb devices
4. If both available -> ask user which platform
5. If argument contains "android" or "ios" -> use that
```

For iOS: use `mcp__multi-agent__ios_*` tools
For Android: use `mcp__multi-agent__android_*` tools

**Android extras**: `get_ui_tree` returns XML with bounds/text/resource-id (uiautomator dump), `logcat` for live output, `list_crashes` for the crash buffer, `go_back` button.

## Activation

```
/multi-agent test                      -> full app test
/multi-agent test "dark mode"          -> dark mode bug test
/multi-agent test "accessibility"      -> accessibility audit (visual + MCP audit tool)
/multi-agent test "dynamic type"       -> large text test
/multi-agent test "screenshot tr"      -> locale screenshots
/multi-agent test "store-ready"        -> hands off to /multi-agent:store-ready (package validation)
/sim-test                              -> standalone (same thing)
```

Not offered, deliberately  -  `"biometric"` and `"performance"` were listed here with
no implementation section, so reaching one fell through to the general sweep and got
reported as the scenario asked for. Neither can be implemented symmetrically today:
biometric has an iOS tool (`ios_biometric`) and no Android counterpart, and launch
timing has `android_launch_time` and no iOS counterpart. Platform is auto-detected,
so either one would work on one platform and silently do nothing on the other. They
come back when the missing side exists, not before  -  do not re-add the rows to make
the list look complete.

Four scenarios also have a fixed-scenario command that pins the tag, so it does not
have to be typed or quoted. They arrive here with the scenario already resolved  -
treat them as identical to the quoted form:

```
/multi-agent:test-dark-mode            -> scenario "dark mode"
/multi-agent:test-accessibility        -> scenario "accessibility"
/multi-agent:test-dynamic-type         -> scenario "dynamic type"
/multi-agent:test-screenshots [locale] -> scenario "screenshot <locale>", locale defaults to tr
```

`store-ready` is not one of them, and does not belong to this file at all: it
validates a built package on either platform and lives at
`/multi-agent:store-ready`. The `"store-ready"` tag is kept as a hand-off so an
existing invocation still lands somewhere correct. `/multi-agent:testflight-validation`
is the iOS-pinned alias of that same command.

## Flow

Every run follows the exploratory-testing contract: findings shape, budget,
stop rules, and blocked steps kept apart from product failures. Read it once
before Step 1:

```
$HOME/.claude/multi-agent-refs/features/exploratory-testing.md
```

### Step 0  -  Budget and run file

Open the run file at `$HOME/.claude/logs/sim-test/{bundle_id}/{timestamp}/run.json`
with the goal (the scenario, or "full sweep"), the platform and the budget
(defaults 8 steps, 10 minutes, 150000 tokens; the user may name others). Append
each step and each finding as it happens. Before every new step:

```bash
node "$HOME/.claude/scripts/explore-findings.mjs" check --run "<run.json>"
```

`stop: true` ends exploration with that reason (`step-limit`, `time`, `tokens`,
or `stuck` after three consecutive blocked steps that reported nothing) and
goes straight to the crash sweep and Step 6. A failed step does not stop the run.

### Step 1  -  Device & App Discovery

```
Call: ios_list_devices (or android_list_devices)
-> If no booted simulator: ask user which to boot, call ios_boot_device
-> If booted: auto-select

Call: ios_list_apps
-> Auto-detect bundle_id from cwd project (xcodebuild -showBuildSettings | PRODUCT_BUNDLE_IDENTIFIER)
-> Or ask user to pick from installed apps

Call: ios_launch_app (bundle_id)
-> Wait 2 seconds for app to load
```

### Step 2  -  Clean Status Bar (for screenshots)

```
Call: ios_status_bar (time: "09:41", battery_level: 100)
```

### Step 3  -  Systematic Screen Exploration

For each screen in the app, read before you look, and batch what you can.

**Locators before coordinates.** With `@mmerterden/multi-agent-mcp` ≥
v3.19.0, resolve elements with `ui_locate` (accessibility id, then role plus
label, then visible text) and tap with `ios_tap_element` / `android_tap_element`;
assert exact outcomes with `expect_text` / `expect_element` / `expect_url` steps
inside `agent_run_steps`; type credentials with `secret_ref`, never the value.
`LOCATOR_NOT_FOUND` / `LOCATOR_AMBIGUOUS` block the step as automation, not
product. On an older toolkit, the frame-centre taps below are the fallback; say
which one ran in the report.

When a coordinate tap is unavoidable, check it instead of trusting it:
`ui_hit_test` (`platform`, `x`, `y`) names what the point would hit and its
`interactive_hit`; `ui_target_check` (`platform`, `target`) before re-tapping an
element seen on an earlier tree says whether it is still there, shifted (tap
the healed `point`), covered or gone; and `ui_region_changed` (`before`, `after`,
`x`, `y`: two screenshot paths) says whether anything near the tap changed. A
tap whose target was covered or gone is an automation miss, not a "button did
not respond" bug.

A defect that only shows in motion (a flicker, a jump during a transition, an
animation that stalls) is recorded with `ios_record_video` /
`android_record_screen`, then `media_frames` (`path`, optional `out_dir`,
`max_frames`) extracts the distinct key frames; cite those PNGs as the bug's
evidence rather than one still that cannot show it. `media_frames` needs
`ffmpeg` on PATH; without it, say so and attach the recording path.

```
Call: ios_get_ui_tree            (text: labels, frames, traits; ~0.1 s, no image)
-> pick tap targets from element frames, never by guessing pixels from a picture

Call: agent_run_steps            (one round trip for a scripted sequence)
  steps: [ {tool: "ios_tap", args: {x, y}}, {wait_ms: 400},
           {tool: "ios_screenshot", args: {path: "<dir>/<screen>.png"}},
           {tool: "ios_get_ui_tree", args: {}} ]

Call: ios_screenshot             (inline, only when a visual judgment is needed)
-> Claude analyzes the image for bugs (see Bug Detection below)
```

Every inline `ios_screenshot` / `android_screenshot` is an 800 px JPEG (about 60 KB) by
default; pass `format: "png"` or a larger `max_width` only when a pixel-level look is the
point. Bulk captures (dark mode, dynamic type, locale sweeps) always go through `path`,
so a run of 100 screens does not push 100 images through the model: look at the ones
whose tree or diff changed. A screen whose tree is unchanged after a tap is the
"button did not respond" finding without a second image.

**Navigation strategy:**

1. Tree of the initial screen -> tab bar items are the elements with a tab-bar trait or the bottom row of buttons; use their frames
2. Tap each tab (batched via `agent_run_steps`) -> tree + file capture each
3. On each screen: tap interactive elements from the tree -> tree after; inline screenshot only where the tree cannot tell (layout, contrast, clipping)
4. Scroll: `ios_swipe(200, 600, 200, 200)` to scroll down -> tree, capture when new content appeared
5. Type in text fields: `ios_type_text("test input")`

### Step 4  -  Variant Testing (based on input argument)

**"dark mode":**

```
Call: ios_set_appearance("dark")
-> Re-navigate all screens, screenshot each
Call: ios_set_appearance("light")  // reset
```

Write both captures of a screen to files (`path`), then compare them with
`ios_visual_diff` (`baseline`: light PNG, `current`: dark PNG, `mode: "layout"`,
works for Android captures too). Layout mode ignores colour, so a score under
`min_score` (default 90) or any `regions` entry is content the theme moved or
hid: report it as a Layout bug on that screen with the region boxes. Contrast in
dark mode is measured as in the accessibility scenario below, with
`themes: ["dark"]`.

**"dynamic type":**

```
Call: ios_set_content_size("extra-extra-extra-large")
-> Re-navigate, screenshot
Call: ios_set_content_size("accessibility-extra-large")
-> Re-navigate, screenshot
Call: ios_set_content_size("medium")  // reset
```

**"accessibility":**

Two halves per screen, and the report keeps them apart: what the tool measured and what the screenshot suggests.

```
On each screen, after ios_screenshot:
Call: ios_accessibility_audit            (Android: android_accessibility_audit)
-> findings[]: missing labels / contentDescription, controls a screen reader cannot
   name, tap targets under 44pt (iOS) / 48dp (Android), missing identifiers,
   reading order that does not follow the layout. Each finding becomes a BUG task
   with the element identifier from the tree, not a guess from the pixels.
-> measurable:false (with a reason) means the tree could not be read (on iOS,
   Simulator.app itself must be running, a booted device is not enough). Record
   the screen as "not audited: <reason>" in the report. Never read it as clean.
-> Pass `scope: "<prefix>"` to narrow to one screen's identifiers when the tree is large.
```

The screenshot pass still runs on every screen for what the tree cannot see: poor contrast, text readability at default + large sizes, and visual crowding. Report those as screenshot findings, separately from the audit findings.

Contrast is measured, not judged by eye. When the project keeps colour tokens (a tokens JSON, or asset-catalog colour sets read into `{light, dark}` values), run `design_contrast_check` once with `tokens` (object or JSON path) and, when roles cannot be derived from the names, explicit `pairs`; every pair below AA becomes a finding with its ratio and theme. A contrast suspicion from a screenshot gets the pair's hex values from the code and goes through the same tool as `fg`, `bg`, `size` (`normal`, `large` or `ui`). A suspicion with no resolvable colour stays a screenshot finding marked "not measured".

Optional deep pass (iOS only, minutes rather than seconds): when the project has an XCUITest target whose test calls `performAccessibilityAudit()`, run `ios_accessibility_audit_deep` (`scheme`, `project` or `workspace`, optional `test_identifier`) once at the end. It reaches contrast, Dynamic Type, clipped text, traits and hit regions that a tree dump cannot. The result says whether the named test ran; a test that never called the audit reports as "did not run", never as clean. Skip it, and say so in the report, when no such test exists.

**"screenshot <lang>":**

```
Call: ios_set_locale(language: "<lang>", bundle_id: "...")
-> Navigate all screens, screenshot each
-> Great for App Store screenshot generation
```

For a right-to-left language (`ar`, `he`, `fa`, `ur`), keep a left-to-right
capture of each screen, flip it with `sips --flip horizontal <ltr.png> --out
<ltr-flipped.png>` and compare it with the RTL capture through `ios_visual_diff`
(`mode: "layout"`). The `regions` it returns are the parts that did not mirror;
check each against the screenshot before filing, since translated text changes
edges too.

**"store-ready":**

Not implemented here. `store-ready` validates a built **package**, which is a
different job from driving a running app, and it is owned by one command on both
platforms:

```
$HOME/.claude/commands/multi-agent/store-ready/SKILL.md
```

Read that file and follow it. Pass through any artifact path given after
`store-ready` as its `--archive=` / `--ipa=` / `--aab=` / `--apk=` input.

Its Step A is the visual + accessibility sweep in this file  -  it calls back here
for the running-app half, then runs three gates per platform that nothing in this
file can do: the static package audit, the store's own validator, and a policy
review against repo source. It merges both halves into one severity-grouped report
and offers the `/multi-agent:channels` follow-up.

The archive-compliance audit is NOT repeated here. Invoking `ios_app_store_audit`
with the arguments the store-ready command's Gate 1 already uses would put two
copies of one call in the tree, which is how a second door opens with no Gate 2,
no Gate 3 and no Android parity behind it.

**No argument (full test):**

- Run light mode -> all screens
- Run dark mode -> all screens
- Run large text -> all screens
- Crash sweep, after the last screen and before the report:

```
Call: ios_list_crashes (app: <process name>, since_min: <minutes since Step 1 launch>, limit: 20)
      Android: android_list_crashes (lines: 200)
-> Every report / stack newer than the launch becomes a BUG task with severity Critical,
   the crashed process and the top frame in the description.
-> Empty result -> "Crashes: none during this run" in the report. Only the bounded window
   counts; older reports on the host are not this run's.
```

- Compile complete report

### Step 5  -  Bug Detection (on EVERY screenshot)

Exact claims (a total, a label, a route, an element present) are checked with an
expect step or the UI tree. A visual or semantic claim that becomes a finding,
or decides a step, goes to a fresh judge subagent that sees only the assertion
and the current screenshot / UI tree, never this run's history:

```
$HOME/.claude/multi-agent-refs/features/assertion-judge.md
```

`inconclusive` never passes. The checked verdict goes on the finding as `judge`.

When analyzing each screenshot, check for:

| Category         | What to Look For                                                                     |
| ---------------- | ------------------------------------------------------------------------------------ |
| **Layout**       | Overlapping elements, truncated text, off-screen content, broken alignment           |
| **Visual**       | Wrong colors, missing images, placeholder text ("Lorem ipsum"), inconsistent spacing |
| **Dark Mode**    | Text invisible on dark background, hardcoded white/black, wrong tint colors          |
| **Typography**   | Text overflow at large sizes, unreadable small text, line height issues              |
| **Navigation**   | Missing back button, dead-end screens, broken tab bar                                |
| **State**        | Empty state without message, loading spinner stuck, error state visible              |
| **Localization** | Untranslated strings, text clipping in long translations                             |
| **Interaction**  | Button didn't respond (before/after screenshots identical after tap)                 |

### Step 6  -  Report

Render the findings block from the run file first; its verdict, issues,
warnings and blocked section are the source for everything below:

```bash
node "$HOME/.claude/scripts/explore-findings.mjs" report --run "<run.json>"
```

Every bug below is a finding from the run file: `expected`, `observed`, `repro`,
`severity` 1-5 (5 critical, 4 high, 3 medium, 2 low, 1 trivial), `kind`
`issue` or `warning`, and `evidence`. A finding the script listed under
"failed the contract" is fixed or dropped, never reported as a bug.

Create tasks for each bug found:

```
TaskCreate("BUG: [severity] title", "Screen: X, Category: Y, Steps: ...", activeForm: "Found bug...")
```

Then output full report:

```markdown
# Simulator UI Test Report

**App**: {bundle_id}
**Device**: {device_name} (iOS {version})
**Date**: {timestamp}
**Mode**: {full / dark mode / accessibility / screenshot}

## Bugs Found ({N} total)

### BUG-1: [{severity word} {issue|warning}] {title}

- **Screen**: {which screen}
- **Category**: Layout / Dark Mode / Typography / Navigation
- **Repro**: 1. Open app -> 2. Tap {X} -> 3. Observe {issue}
- **Expected**: {correct behavior}
- **Observed**: {what's wrong}
- **Judge**: {passed / failed ASSERTION_FAILED / failed ASSERTION_INCONCLUSIVE, when a judge decided it}
- **Spec**: "<quoted acceptance criterion from the analysis doc Section 15 / 20, or: no spec, model expectation>" (<source>)
- **Evidence**: before=<png path> after=<png path>

### BUG-2: ...

## Blocked ({N})  -  not product failures

| Step | Cause | Code | Detail |
| ---- | ----- | ---- | ------ |
| 4    | credentials | CREDENTIAL_MISSING | no test account for checkout |

## Screens Visited ({N})

| #   | Screen   | Light | Dark  | Large Text | Bugs | Evidence |
| --- | -------- | ----- | ----- | ---------- | ---- | -------- |
| 1   | Home     | ok    | BUG-1 | ok         | 1    | 3        |
| 2   | Login    | ok    | ok    | BUG-2      | 1    | 4        |
| 3   | Settings | ok    | ok    | ok         | 0    | 2        |

## Summary

- Screens tested: {N}
- Clean: {N}
- With bugs: {N}
- Verdict: {passed / failed / blocked} · ended: {finished / step-limit / time / tokens / stuck}
- Budget used: {steps}/{max} steps · {min}/{max} min · {tokens}/{max} tokens
- Critical: {N} | High: {N} | Medium: {N} | Low: {N} | Trivial: {N}
- Blocked steps: {N} (environment {N} · credentials {N} · seed data {N} · automation {N})
- Accessibility audit (accessibility scenario): {N} audited, {N} not audited (reason per screen), deep pass: {ran / skipped: reason}
- Crashes (full scenario): {N} during this run
- Production readiness: FAILED | NEEDS WORK | READY
```

`Evidence` in a bug block is the captures already written to files in Step 4: a tap-driven finding needs both `before` and `after`, a static finding (layout, contrast, dark mode, large text) needs `after` only. The `Evidence` column in Screens Visited is the count of screenshot files written for that screen. Production readiness defaults to FAILED; it is NEEDS WORK when only low / trivial findings remain, and READY only when there are no findings of severity 3 or above and every planned screen was visited. A blocked run is never READY: the screens it could not reach were not tested.

Save to: `$HOME/.claude/logs/sim-test/{bundle_id}/{timestamp}.md`

### Step 7  -  Fix Offer

After report is complete, if bugs were found:

```
{N} bug(s) found. Want me to fix them?
  y -> Create fix tasks, start fixing (reads source code, applies changes)
  n -> Report saved, you can review and fix manually
  pick -> Show bug list, user picks which to fix
```

If user says yes:

1. For each bug, locate the relevant View file
2. Analyze the screenshot + bug description
3. Apply the fix (color, padding, font, constraint, etc.)
4. Re-run screenshot on that screen to verify fix
5. Show before/after comparison

### Step 8  -  Cleanup

```
Call: ios_set_appearance("light")
Call: ios_set_content_size("medium")
Call: ios_status_bar (clear override)
```
