Device interaction

From CamilleScholtz/swmpc · View interactive version

Device interaction is an AI agent skill from the GitHub repository CamilleScholtz/swmpc. Verify app behavior on device or simulator via screenshots, UI hierarchy, and touch interactions.

How to use this skill

Skill file

Device Interaction

TRIGGER when: user asks to verify/test/check if the app works on device, after implementing a UI-affecting feature that needs device verification, user says "does it work", "test this", "check on device", user reports UI doesn't work as expected, need to debug touch/interaction issues.

DO NOT TRIGGER when: user asks about unit tests only, build-only requests without device testing, code review without device testing, simulator configuration questions, changes that don't affect UI (e.g. comments, refactors, non-UI logic).


For the Main Agent

This is a SUBAGENT skill. Invoke it via the Agent tool when device verification is needed. If there is an open session for that work, provide that session identifier to a subagent for exclusive use by that subagent.

Agent tool:
- subagent_type: "general-purpose"
- description: "Verify login feature works"
- prompt: "Using the device-interaction skill, verify that the login feature works correctly on session <session-identifier>. Launch the app, capture screenshot and UI hierarchy, check that the login button is visible and tappable, and report if the implementation is working correctly."

After implementing a UI-affecting feature, invoke this skill to verify the implementation works on a device.

Session Lifecycle

DeviceInteractionStartWorkspaceSession (workspace-backed; do this early, runs in the background)
  → DeviceInteractionInstallAndRun (after each code change; includes building)
    → DeviceEventSynthesize (interact + observe, repeatable)
  → DeviceInteractionEndSession (when done — keeping sessions open is resource-heavy)

There are two ways to start a session:

DeviceInteraction(Workspace)StartSession tools

Device Discovery

When opening a new device interaction session, pass a device identifier to select a device, or omit it to use the current destination. Pass an empty string to get a list of available targets.

DeviceInteractionInstallAndRun tool

Optional Parameters

Omit both parameters to leave the scheme's arguments and environment unchanged.

Prefer these parameters over editing the scheme directly. They are applied only for that one run and have no lasting effect on the user's configuration.


For the Subagent

ALWAYS report UI issues that might be caused by code: overlapping or unreadable text, unexpectedly cropped image/text, wrong colors etc.

DeviceEventSynthesize tool

This tool allows performing an interaction and observing the state of a device.

Reading Hierarchy Files

The hierarchy files include calculated hitPoint positions for each element:

UIView {{100, 200}, {60, 30}}, hitPoint: {130.0, 215.0}
  UIButton "Login" {{110, 205}, {30, 20}}, hitPoint: {125.0, 215.0}
  UIButton "Login2" {{140, 205}, {20, 20}}, hitPoint: {150.0, 215.0}, activationBundleId: com.your.app

Always prefer the hitPoint coordinates for touch events. Only after tapping a hitPoint and confirming (via recapture) it had no effect may you fall back to a raw screenshot-estimated position.

Warning: Elements marked isRemoteLeafPlaceholder do not report child elements — interacting with them requires falling back to screenshot-estimated coordinates.

Multiple Applications (activationBundleId annotations)

When windows from more than one application overlap on screen, each element line is annotated with a activationBundleId: <bundle-identifier> suffix.

If an element line carries a activationBundleId, any interaction with it requires activating that application first by passing activationBundleId parameter to the DeviceEventSynthesize tool.

Tip: you can pass activationBundleId with no interactionCommand.

Application activation is expensive so use that only if necessary.

Example:
Device orientation: Landscape Right
------------------------
Application bundle identifier: com.some.app
Application UI orientation: Landscape Left
Application, pid: 123, label: ' '
 Window, {{0.0, 0.0}, {1133.0, 744.0}}, hitPoint: {566.5, 372.0}
  Other, {{0.0, 0.0}, {744.0, 1133.0}}, hitPoint: {372.0, 372.0}
...
------------------------
Application bundle identifier: com.some.other.app
Application UI orientation: Landscape Left
Application, pid: 333, label: ' '
 Window, {{0.0, 0.0}, {1133.0, 744.0}}, hitPoint: {566.5, 372.0}
...

Interaction Command Syntax

The interactionCommand parameter accepts a command syntax:

| Command | Description |

|---|---|

| t <x> <y> [duration] | Tap at coordinates with optional hold duration |

| d <x> <y> | Double tap |

| t <x1> <y1> f <x2> <y2> [duration] | Swipe from (x1,y1) to (x2,y2) |

| drag <x1> <y1> <x2> <y2> [holdDuration] [moveDuration] | Drag-and-drop: press-and-hold at (x1,y1) then slowly move to (x2,y2). Use for reordering lists or drag-and-drop targets |

| mt [x1 y1, ...] dur [x1 y1, ...] dur ... | Multi-touch sequence. Each [...] keyframe lists touch positions (x y). The duration after each block is the travel time to the next keyframe; for the last block it is the hold time before lifting. A finger ends when its slot is an empty comma entry (e.g. [, x y]) or when the frame has fewer entries than the finger's index — both are equivalent. A finger that reappears in a later keyframe after lifting starts a new tap. |

| b h/p/u/d [duration] | Hardware button: h=Home, p=Power, u=VolUp, d=VolDown |

| b c/s/a [duration] | watchOS only. c=Digital Crown press, s=side button, a=Action button (some devices only) |

| sender keyboard kbd <text> | Type text; must be the last command in the chain — all content after kbd is taken verbatim (multiple spaces preserved). For special characters use \u{XXXX} Unicode escapes: \u{000A} (return/newline), \u{0009} (tab) |

| w duration | Wait for a duration without any work |

| orientation faceDown/faceUp/landscapeLeft/landscapeRight/portrait/portraitUpsideDown | Set device orientation (iOS only) |

| c <rotations> | watchOS only. Rotate the Digital Crown; sign sets direction, 1.0 = one full revolution |

| r up/down/left/right/select/menu/playpause/home | tvOS only. Press a Siri Remote button to move focus, select, or go to the Home screen |

Examples:

Standard Subagent Workflow

Before any interaction, always capture and read the hierarchy (and screenshot). After any interaction, capture again and verify the result. For complex components (like toggles or switches), look at nested elements (like Switch or Slider) — nearby elements might correspond to the actual control. When done, report findings to the main agent.

tvOS (Apple TV)

tvOS is focus-based: there is no touchscreen, so coordinate taps/swipes do not apply. Exactly one element is focused at a time, and you can only activate whatever currently has focus. Drive it with the Siri Remote instead:

Timing and Retries

Judging Success vs Failure

When verifying, distinguish between these categories:

Error Handling

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.