/automate:drive-automation-sessionfrom automate
Drives a reserved Kobiton device via natural-language intent using an Appium automation session. Runs an observe-decide-act loop, pauses when stuck, and returns a session id consumable by saveTestCase.
Ships in automate. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Drive a Kobiton device from a natural-language intent. The caller provides:
kobiton-store:vXXXXX) or a browser name for web sessions.The skill opens an automation-type Appium session (with appium:newCommandTimeout: 1800 so the session survives pauses while the model asks for guidance), runs an observe-decide-act loop, and returns the session id. The returned session is consumable by the Kobiton MCP tools getSession, getSessionArtifacts, and saveTestCase exactly like any other automation session.
Tool naming. This doc refers to Kobiton MCP tools by their bare names (
getSession,reserveDevice,terminateSession, …). The exact registered name depends on how the host loaded the MCP server (e.g. Claude Code as a plugin exposesmcp__plugin_automate_kobiton__getSession; a repo-local.mcp.jsonorclaude mcp addexposesmcp__kobiton__getSession; other hosts differ). Models fuzzy-match on the bare name, so use it and let the host resolve the prefix.
userIntent. Optional: pass one sentence on why when the tool name and arguments show what the call does but not why (e.g.terminateSession,deleteTestCase); omit it when the reason is obvious from the call (e.g.listDevices,getSession).
This skill complements — and does NOT replace — run-interactive-session. They serve different session types:
| Skill | Session type | Best for |
|---|---|---|
run-interactive-session | CLI session (~/.kobiton/bin/kobiton) | Human-driven exploration, ad-hoc inspection |
drive-automation-session | Automation session (direct Appium HTTP) | AI-driven flows, saveable as a test case |
Runs on any OS, but needs two things from the host: a persistent local filesystem — the observe-decide-act loop passes state between turns through the timestamped artifact files under .kobiton/sessions/<session-id>/, so that file handoff is the loop — and ~/.kobiton/.credentials, which scripts/appium.js reads directly (see below). A host with a filesystem but no way to run /automate:setup still can't finish; route those users to create-test-run. Node.js 18+; no native binary (scripts/appium.js uses node:https). See the Skill compatibility matrix in CLAUDE.md.
scripts/appium.js reads ~/.kobiton/.credentials (written by /automate:setup) directly on every invocation and stops with no-credentials if it's missing — this file is required, not a fallback, and the script never calls the MCP getCredential tool. Reading it directly is deliberate: credentials never pass through argv, env, or the host transcript.kobiton-store:vXXXXX, an .apk / .ipa to upload, or a browser name (for web testing). The skill helps locate or upload it in Step 0.Before reserving anything, the skill clarifies what the user wants. Do NOT auto-pick a device unless the user's intent unambiguously implies a platform AND the user did not constrain the choice.
If the user didn't specify a device in their intent:
listDevices with the relevant platform filter and present the top 3-5 options with name + OS version + availability.getDeviceStatus before reserving.reserveDevice. Capture the UDID, deviceName, platformVersion, automationName for Step 2's caps render.If the user's intent strongly implies a platform (e.g., "test the iOS App Store flow", "open Chrome on Android"), it's OK to auto-pick — but state which device you're picking and why in one line before reserving, so the user can redirect.
For an app testing session:
@build.apk, "the latest staging build", kobiton-store:vXXXXX), use it. Verify the store reference exists via listApps if uncertain..apk/.ipa, an existing kobiton-store:vXXXXX reference, or none if the intent is browser-only)."uploadAppToStore → confirmAppUpload → poll getAppParsingStatus until the state is terminal (OK = ready; stop on a FAILURE_* value). confirmAppUpload only kicks off async parsing on the backend — it does NOT guarantee the app is ready, so the session can fail to install if you skip the poll.For a web testing session, skip the app step — --testingType web --browserName chrome|safari is enough.
If the user didn't say how they want to observe the session, ask before creating it:
"Open the device live view to watch the agent drive (foreground), or run the session in the background?"
Two options:
<portal>/devices/launch?id=<deviceId>&view=device-only (same shape as run-automation-suite Step 5; the <deviceId> is the one captured during Step 0 reservation) and launch it via the chromeless launcher chain (see Step 3b for the chromeless-vs-default-browser branching). The URL is also surfaced as text so the user can click manually if the launcher can't open Chrome and no default-browser fallback applies.Remember the choice; act on it in Step 3 right after the session is created. Do NOT auto-open without asking — some users prefer silent runs, especially on shared screens.
| Input | Required | Notes |
|---|---|---|
intent | yes | One to a few sentences describing what the user wants done on the device |
udid | yes | The device the caller has reserved |
platformName | yes | Android or iOS (look up via getDeviceStatus if unknown) |
platformVersion | yes | from getDeviceStatus |
deviceName | yes | from getDeviceStatus |
automationName | recommended | UiAutomator2 (Android) or XCUITest (iOS) |
app OR browserName | yes | kobiton-store:vXXXXX for app testing, browser name for web testing |
testingType | no | app (default) or web |
appium.js reads ~/.kobiton/.credentials directly on every invocation. If the file is missing, tell the user to run /automate:setup and stop:
if [ ! -s ~/.kobiton/.credentials ]; then
echo "Credentials not found. Run /automate:setup first." >&2
exit 1
fi
Reuse run-automation-suite's renderer. The --newCommandTimeout 1800 flag is the key piece for this skill.
SKILL_DIR=$(dirname "$0") # this skill's directory
RENDER=$(realpath "$SKILL_DIR/../run-automation-suite/scripts/render-capabilities.js")
# Unique temp file — two concurrent sessions (two terminals / conversations)
# must not clobber each other's rendered caps before Step 3 reads them.
CAPS_TMP=$(mktemp "${TMPDIR:-/tmp}/drive-automation-session-caps.XXXXXX.json")
node "$RENDER" \
--platformName "$PLATFORM_NAME" \
--udid "$UDID" \
--deviceName "$DEVICE_NAME" \
--platformVersion "$PLATFORM_VERSION" \
--automationName "$AUTOMATION_NAME" \
--app "$APP" \
--testingType "${TESTING_TYPE:-app}" \
--newCommandTimeout 1800 \
--scriptlessCapture \
> "$CAPS_TMP"
appium.js reads ~/.kobiton/.credentials on each invocation. No flags, no env vars.
SESSION_ID=$(node "$SKILL_DIR/scripts/appium.js" \
--method POST --url /session \
--req-body "@$CAPS_TMP" \
| jq -r '.value.sessionId // .sessionId')
SESSION_DIR=".kobiton/sessions/$SESSION_ID"
mkdir -p "$SESSION_DIR"
mv "$CAPS_TMP" "$SESSION_DIR/caps.json"
printf '%s session=%s started intent=%q\n' "$(date -u +%FT%TZ)" "$SESSION_ID" "$INTENT" > "$SESSION_DIR/session.log"
trap 'cleanup' EXIT INT TERM
cleanup() {
[ -z "$SESSION_ID" ] && return 0
# DELETE /wd/hub/session/<id> ends the WebDriver session cleanly; Kobiton
# records state=COMPLETE. appium.js already treats 404 as idempotent success
# (the session was already gone). appium.js always exits 0 by policy, so we
# check stderr instead of $? to detect a real failure.
delete_err=$(node "$SKILL_DIR/scripts/appium.js" \
--method DELETE --url "/session/$SESSION_ID" 2>&1 >/dev/null)
if [ -z "$delete_err" ]; then
printf '%s session=%s end-via-trap status=COMPLETE\n' "$(date -u +%FT%TZ)" "$SESSION_ID" >> "$SESSION_DIR/session.log"
else
printf '%s session=%s end-via-trap delete-failed (session will time out per appium:newCommandTimeout) err=%s\n' "$(date -u +%FT%TZ)" "$SESSION_ID" "$delete_err" >> "$SESSION_DIR/session.log"
fi
}
Build the device-only URL from the device id captured during Step 0 reservation and the portal base URL (e.g., https://portal.kobiton.com) — the AI host has the portal value from earlier MCP responses in the conversation context. Same URL shape as run-automation-suite Step 5.
LIVE_VIEW_URL="<portal>/devices/launch?id=<deviceId>&view=device-only"
printf 'Live view: %s\n' "$LIVE_VIEW_URL"
(The post-run replay URL is <portal>/sessions/<kobiton-session-id>/explorer — a different page, NOT the live view. Surface that one only after the session completes if the user wants to review the recording.)
If the user chose background in Step 0, stop here — the URL is logged and the loop proceeds. They can paste it into a browser later if they get curious.
If the user chose foreground, reuse run-automation-suite's launcher chain instead of re-implementing it. The pattern (chromeless Chrome for users who haven't expressed a preference or prefer Chrome; default-browser fallback otherwise) is identical to run-automation-suite Step 5.
Launch via the chromeless helper (default — gated on saved browser preference). Check auto memory for a saved browser preference:
Pick width and height from the reserved device's form factor (the device name from Step 0):
| Device class | Detect by name (case-insensitive) | Portrait W × H | Landscape W × H |
|---|---|---|---|
| Tablet | iPad, Galaxy Tab, Pixel Tablet, Surface, MatePad, or any model with Tab / Pad | 780 × 920 | 920 × 780 |
| Fold (unfolded) | Fold, Z Fold, Pixel Fold | 880 × 920 | 920 × 880 |
| Phone (default) | none of the above | 540 × 920 | 920 × 540 |
Swap width and height if getSession / rendered caps report orientation=LANDSCAPE — default is portrait.
Invoke per host OS. Run in the background (Claude Code: Bash tool with run_in_background: true; other hosts: append & and disown) so the resize-polling loop doesn't block the first turn. The launcher's stdout/stderr will surface later when it completes; the URL printed above is the user's fallback if the launcher silently fails.
| OS | Command |
|---|---|
| macOS | bash $SKILL_DIR/../run-automation-suite/scripts/chromeless-launcher.sh --url "$LIVE_VIEW_URL" --width <W> --height <H> |
| Windows | pwsh $SKILL_DIR/../run-automation-suite/scripts/chromeless-launcher-windows.ps1 -Url "$LIVE_VIEW_URL" -Width <W> -Height <H> |
| Linux | bash $SKILL_DIR/../run-automation-suite/scripts/chromeless-launcher.sh --url "$LIVE_VIEW_URL" --width <W> --height <H> (launch-only on Linux — no auto-resize) |
Launcher exit codes (surface in the background-task completion event):
0 — Chrome was launched (resize may or may not have succeeded; the warning is informational).2 — Chrome / Chromium is not installed. The user already has $LIVE_VIEW_URL from the printf above; they can paste it into their default browser, or you can offer the default-browser fallback table below as a follow-up.64 — usage error in the launcher invocation. Surface to the user.Default-browser fallback (when the saved preference is Safari/Firefox/Default, or chromeless exited 2). Ask the user once which browser to use (save to auto memory):
| Choice | Command |
|---|---|
| Google Chrome | open -na "Google Chrome" --args --new-window "$LIVE_VIEW_URL" |
| Safari | open -a "Safari" "$LIVE_VIEW_URL" |
| Firefox | open -a "Firefox" "$LIVE_VIEW_URL" |
| Default browser | open "$LIVE_VIEW_URL" |
On Linux, fall back to xdg-open "$LIVE_VIEW_URL" (browser selection isn't supported).
If neither path is available, the URL is already on stdout from the printf above — the user can copy-paste it.
There is no Bash while. The skill is turn-based: each turn, you (the AI host) pick exactly one of three branches:
| Branch | Command | When to pick |
|---|---|---|
| screen | node appium.js screen --session-id $SID --session-dir $DIR | The screen state has likely changed (after a successful act, or at session start, or to verify mid-flow). |
| act | node appium.js <argv> --session-dir $DIR | You know what to do based on the most recent source-<ts>.xml you observed. |
| control | node appium.js control --done|--blocked --reason "..." --session-dir $DIR | Goal reached, or you're genuinely stuck. Ends the cycle. |
Each call names everything it writes with one timestamp <ts> (epoch seconds; the next free second when two calls share one), the same <kind>-<ts>.<ext> scheme run-interactive-session uses.
The script always exits 0; a call failed when it printed to stderr (it also wrote error-<ts>.json).
# Pick ONE of the three. Credentials come from ~/.kobiton/.credentials (Step 1).
# Branch A: observe — by default writes source-<ts>.xml (the lean view: only
# the elements you can target, with their bounds), source-<ts>.full.xml (the
# raw /source) and screenshot-<ts>.png. Read source-<ts>.xml; open the full
# source or the screenshot only as references/webdriver.md § Observe says.
# --xml-only captures the source but no screenshot; --png-only captures the
# screenshot but no source (no XML files); --full writes the unfiltered
# tree to source-<ts>.xml (stripped webview DOM, raw native tree).
node "$SKILL_DIR/scripts/appium.js" screen \
--session-id "$SESSION_ID" --session-dir "$SESSION_DIR"
# Stdout: {"ts":T,"source":"source-T.xml","fullSource":"source-T.full.xml",
# "screenshot":"screenshot-T.png","hash":"<sha256>","mode":"lean",
# "xmlBytes":N,"fullXmlBytes":F,"pngBytes":M,"turns":K}
# plus "warning":"<text>" on a turn-warning call (below).
# The names are relative to $SESSION_DIR. Track the hash across turns in your
# conversation context — repetition is a signal, never a forced stop. See
# references/loop-discipline.md "Stuck patterns".
# Branch B: act — execute an Appium call. On success stdout is the raw
# WebDriver response body (pipe it to jq, e.g. for an element id); on any
# failure stdout is empty and stderr carries the raw Appium body, or
# {error, message} for usage errors. The same content is saved as
# request-<ts>.json + response-<ts>.json or error-<ts>.json.
node "$SKILL_DIR/scripts/appium.js" <YOUR-ARGV> --session-dir "$SESSION_DIR"
# Examples of <YOUR-ARGV>:
# --method POST --url /session/$SESSION_ID/element --req-body '{"using":"xpath","value":"//Button"}'
# actions --session-id $SESSION_ID --type swipe --from-x 540 --from-y 1800 --to-x 540 --to-y 600
# touch-perform --session-id $SESSION_ID --steps @/tmp/steps.json
# --method POST --url /session/$SESSION_ID/element/$EL_ID/clear --req-body '{}'
# Branch C: end the cycle. Writes control-<ts>.json; stdout {"ts":T,"control":"DONE","reason":"..."}.
node "$SKILL_DIR/scripts/appium.js" control \
--done --reason "Settings reached and Bluetooth toggled" \
--session-dir "$SESSION_DIR"
# OR --blocked --reason "Two modals stacked; cannot dismiss"
screen also reports turns (the screen and act calls so far, this one included) and, from 100 turns and every 25 after, a warning to re-check the flow against the stuck patterns and end with control --blocked if it is not progressing — a prompt, not a stop (references/loop-discipline.md § Turn warning).
appium.js logs each failed call (ts=<ts> error), each warning (ts=<ts> turns=<n> warning) and each execute / execute/sync call, which the saved test case won't contain (ts=<ts> capture-warning=…), to session.log.
What to pick next turn depends on what just happened:
screen (the screen probably changed).screen just ran → next turn act (you have a fresh observation).act returned no such element / invalid selector / bad-input → next turn act again with a corrected call. The screen didn't change (the action didn't fire), so the most recent source-<ts>.xml is still valid; re-read it from disk if you need to, but don't burn a turn on a fresh screen.act returned stale element reference → next turn screen (the element id is from a prior state; you need a fresh observation to get current element ids).act returned HTTP 5xx / network timeout → next turn act again with the same call (retry). If it fails twice, control --blocked.control --done.loop-discipline.md "Stuck patterns") → control --blocked.The host is responsible for tracking which source-<ts>.xml represents the current screen state — screen prints its name. After a successful act, the previous source-<ts>.xml is stale until the next screen. After a failed act, it is still current.
When the chosen branch is act, build the call from the most recent source-<ts>.xml.
references/webdriver.md — shared with run-interactive-session — holds every operation's <path> and body, the selector rules, the find-then-act workflow, the coordinates fallback, what to observe and the response and error shapes.
The full loop discipline (artifact paths, error feedback, termination conditions) lives in references/loop-discipline.md. How appium.js sends a call, its helpers and which endpoints the scriptless capture records live in references/endpoint-reference.md.
The Bash trap (set up in Step 3) issues DELETE /wd/hub/session/$SESSION_ID on exit (loop end, error, user stop). That's the clean way to end the session — Kobiton records the session state as COMPLETE, which is what saveTestCase and analytics expect.
Do NOT call the terminateSession MCP tool here. It ends the session via Kobiton's platform-side kill path, which marks the session state as TERMINATED — distinct from COMPLETE and treated as an abnormal exit by the recording pipeline. Reserve terminateSession for the genuinely-stuck case where the WebDriver DELETE is unreachable (network down, Appium hub unresponsive) AND the user explicitly asks to force-kill the session.
If the DELETE somehow fails silently, the session will time out on the Kobiton side per appium:newCommandTimeout (30 min, set in Step 2). Better to wait for that timeout than to mark the session TERMINATED.
Emit the session id back to the caller. The session is now consumable by:
getSession({sessionId}) — session metadata, device info, results.getSessionArtifacts({sessionId}) — video, logs, screenshots, reports.saveTestCase({sessionId}) — persist as a re-runnable test case (sibling feature, out of scope here).See references/webdriver.md for the operations catalog (<path> and body for each) and references/endpoint-reference.md for what is allowlisted (capturable by saveTestCase) vs not, and the helpers (actions, touch-perform) vs generic mode.
The script does not enforce blocker thresholds. The AI host tracks the hash from screen across turns in its conversation context and decides when to emit control --blocked. See references/loop-discipline.md "Stuck patterns" for concrete examples — same-call repetition, screen oscillation (A→B→A→B), credentials prompt, CAPTCHA, lazy load (use a no-op observe to wait), network spinner.
The script stops nothing: the turn warning from screen is a prompt to re-check, and the platform's session-duration cap and appium:newCommandTimeout are the hard limits.
| Symptom | Likely cause | Fix |
|---|---|---|
No credentials available... | No ~/.kobiton/.credentials (an authenticated MCP connection does not substitute — appium.js only reads the file) | Run /automate:setup, which uses the MCP connection to fetch and write the file |
Session create prints {"status":401} on stderr | Credentials stale | Re-run /automate:setup to refresh ~/.kobiton/.credentials; check the portal URL |
| Session create prints a platform-cap message on stderr | newCommandTimeout: 1800 rejected by Kobiton | Lower the timeout in references/capabilities.md |
stderr / error-<ts>.json body has value.error: "no such element" | Selector matched nothing | Re-plan next turn with a different strategy / selector; after two misses in a row, open the latest source-<ts>.full.xml (references/webdriver.md § Observe) |
stderr / error-<ts>.json body has value.error: "invalid session id" | Kobiton platform-side session ended | Emit control --blocked; trap cleans up |
kobiton:aiToolName capability is auto-detected by render-capabilities.js (Claude / Codex / Copilot / Gemini). No flag needed..kobiton/sessions/<session-id>/ — workspace-relative, not /tmp (consistent with run-interactive-session).tools/*.yaml and does not add any MCP tool. It only consumes existing MCP tools (reserveDevice, getSession, terminateSession, etc.).references/capabilities.md (opens in a new tab)references/endpoint-reference.md (opens in a new tab)references/loop-discipline.md (opens in a new tab)references/webdriver.md (opens in a new tab)scripts/__fixtures__/uiautomator2-settings.xml (opens in a new tab)scripts/__fixtures__/webview-mobile-sample.xml (opens in a new tab)scripts/__fixtures__/xcuitest-settings.xml (opens in a new tab)scripts/appium.js (opens in a new tab)scripts/appium.test.js (opens in a new tab)scripts/strip-webview-dom.js (opens in a new tab)scripts/strip-webview-dom.test.js (opens in a new tab)scripts/ui-tree.js (opens in a new tab)scripts/ui-tree.test.js (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
6 skills in this plugin
/create-test-runCreate a Kobiton test run from a test case or suite, then offer to monitor it. When the user gives only partial details (or just a test case id), fill the rest with sensible defaults that match the createTestRun schema, show a summary of what will run, and ask to proceed or customize before creating. After the run is created, offer monitoring in a single prompt — monitor + auto-open live remediation (only when the org's live-remediation flag is ON), monitor only, or don't monitor — and hand off to the monitor-test-run skill if chosen. Use when the user asks to "create / kick off / start / run a test run", "run test case X on N devices", or similar. Wraps the createTestRun MCP tool (and getOrgSettings / listDevices for defaults); delegates the watch to monitor-test-run. Not for running a compiled UIAutomator/XCUITest bundle - that is the CLI's `test run` command in run-interactive-session./debug-device-over-vusbDebug the user's app on a real Kobiton device attached to this machine over virtualUSB, driven by natural language. Installs the pinned virtualUSB client on first use (macOS: cached bundle; Windows: verified installer handed to the user), finds vUSB-ready private devices with listDevices({virtualUsb: true}), connects the chosen device with the virtualUSB CLI so it shows up in adb / Xcode locally, runs the debug loop (install build, reproduce, capture logcat / device logs, screenshots), and always disconnects. Use when the user wants to "debug on a real device", "see the device in adb / Xcode", "plug the Kobiton device into my machine", or says "virtualUSB" / "vusb". Not for exploratory testing through the Kobiton session CLI - that is run-interactive-session.npx claudepluginhub kobiton/automate --plugin automateOther plugins' skills for the same job