From bee35eb501972ea8aa52d809b53bec07fbd88569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 17 Nov 2026 15:20:19 +0100 Subject: [PATCH 01/10] agent-device 0.21.39: read typed refusals, and press the dismiss control back names 0.21.39 no longer says "in-app back control is not available" or "Unable to dismiss the iOS keyboard", so the fallbacks Explore keyed on those messages would never run. They now read error.details.reason: - back: on iOS, agent-device presses the navigation bar back button, else swipes from the left edge, and refuses with back_swipe_no_change when nothing changed. It lists the screen's dismiss controls (Close, Cancel, Back) in details.dismissControls without pressing them. Explore presses the one it names when its label is safe by Explore's destructive and external rules, requires the destination to change, and otherwise swipes a sheet down as before. - keyboard dismiss refuses with keyboard_dismiss_unavailable; the return-key fallback keys on it. - the remote /health refusal is remote_daemon_unavailable with dispatched "no", which is what Explore inferred from the message before resending. The other controller's bridge gives the same reasons. Co-Authored-By: Claude Opus 5.5 --- docs/quickstart-ci.md | 2 +- package-lock.json | 8 +-- package.json | 2 +- src/binary/run.ts | 16 +++-- src/capture/argent-driver.ts | 12 ++-- src/capture/controller.ts | 42 +++++++++++-- src/capture/route-capture.ts | 18 ++++-- src/shared/agent-device-version.ts | 2 +- src/shared/controller-cache.ts | 2 +- test/node/argent-driver.test.mjs | 7 ++- test/node/ci-map.test.mjs | 65 +++++++++++++++++++-- test/node/public-comment.test.mjs | 6 +- test/node/public-review-validation.test.mjs | 2 +- 13 files changed, 143 insertions(+), 41 deletions(-) diff --git a/docs/quickstart-ci.md b/docs/quickstart-ci.md index fe4ffaf5..0dc2fd7f 100644 --- a/docs/quickstart-ci.md +++ b/docs/quickstart-ci.md @@ -289,7 +289,7 @@ The provider selects the runtime that owns the navigation loop: | `anthropic` | Claude Code through `@anthropic-ai/claude-agent-sdk` 0.3.285 and its platform-native package | `ANTHROPIC_API_KEY` | | `openai` | Codex app-server from `@openai/codex` 0.159.2 and its platform-native package | `OPENAI_API_KEY` | -Both runtimes use Explore's device tools to operate the existing Expo Simulators session through official `agent-device` 0.21.29-nightly.20261018.74. The runtime and native binaries come from the pinned tools installation. CI does not use the development-only `node_modules/.bin/claude` executable or an interactive subscription login. +Both runtimes use Explore's device tools to operate the existing Expo Simulators session through official `agent-device` 0.21.39. The runtime and native binaries come from the pinned tools installation. CI does not use the development-only `node_modules/.bin/claude` executable or an interactive subscription login. Create and commit the nonempty English prose file named by `agent.instructions`. The shared setup skill authors it from source and asks for missing test data or environment inputs. Describe how to reach the app's screens, necessary prerequisites, the representative state to use on both revisions, readiness signals, and actions to avoid. This file guides the runtime agent; it is not a list of mandatory YAML steps or a second screen inventory. diff --git a/package-lock.json b/package-lock.json index 03f648eb..dba9f69e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,7 +29,7 @@ "@types/react-dom": "^19.2.4", "@vitejs/plugin-react": "^4.7.0", "@xyflow/react": "^12.11.3", - "agent-device": "0.21.29-nightly.20261018.74", + "agent-device": "0.21.39", "babel-plugin-react-compiler": "^1.0.0", "eslint": "^10.12.0", "eslint-plugin-react-hooks": "^7.1.1", @@ -4593,9 +4593,9 @@ } }, "node_modules/agent-device": { - "version": "0.21.29-nightly.20261018.74", - "resolved": "https://registry.npmjs.org/agent-device/-/agent-device-0.21.29-nightly.20261018.74.tgz", - "integrity": "sha512-7+ajWLr0J+8iLZ9q11ERbj6U14mC20umBK5BQQdw5aERA79yeXc3Ze6KmtvnILnWjEtoVkYQsXQasL8RL6Uatw==", + "version": "0.21.39", + "resolved": "https://registry.npmjs.org/agent-device/-/agent-device-0.21.39.tgz", + "integrity": "sha512-flgrilleoUU9WNd9BlU8h5KMt8zv0nKWBkqJbzk/bb2NBRA+7H1FGja+RIAuapb7HXdsjK4EPnYFP37N9S8nMA==", "dev": true, "license": "MIT", "bin": { diff --git a/package.json b/package.json index ad3629a9..b6e36d3b 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "@types/react-dom": "^19.2.4", "@vitejs/plugin-react": "^4.7.0", "@xyflow/react": "^12.11.3", - "agent-device": "0.21.29-nightly.20261018.74", + "agent-device": "0.21.39", "babel-plugin-react-compiler": "^1.0.0", "eslint": "^10.12.0", "eslint-plugin-react-hooks": "^7.1.1", diff --git a/src/binary/run.ts b/src/binary/run.ts index c51e38ce..afd15b78 100644 --- a/src/binary/run.ts +++ b/src/binary/run.ts @@ -7,7 +7,7 @@ import { createLocalCiAgentSession } from "../capture/agent/session-local.js"; import type { CiAgentProviderName } from "../capture/agent/provider.js"; import { assertReplayFits, createReplaySession, parseReplayPlan, replaySetup, type ReplayPlan } from "./replay.js"; import { CONTROLLER_SESSION, baseEnvironment, isRecord } from "../capture/common.js"; -import { controllerData, defaultRunner, openedSimulatorDevice } from "../capture/controller.js"; +import { controllerData, controllerFailureReason, defaultRunner, loneBackDismissControl, openedSimulatorDevice } from "../capture/controller.js"; import type { CommandRequest, CommandResult } from "../capture/run.js"; import { executeCaptureSetup } from "../capture/setup-actions.js"; import { SIMULATOR_DOTENV_FILE_NAME, SIMULATOR_DOTENV_HEADER, assertSimulatorSessionIdentity, assertSimulatorStopped, readSimulatorDotenvHandoff, @@ -29,7 +29,7 @@ import { packageBin } from "../shared/package-paths.js"; import { assertDecodedPng, solidColour } from "../shared/png-evidence.js"; import { CONTRACT, type ExploreMap, type Platform } from "../types.js"; import { assertEmulatorCompatible, extractIosBundle, inspectArchive, type ArchiveKind, type InspectedArchive, readArchiveIcon } from "./archive.js"; -import { runBlackBoxExploration, type BlackBoxExplorerResult, type BlackBoxFrame, SYSTEM_DIALOG_PACKAGES } from "./explorer.js"; +import { riskOf, runBlackBoxExploration, type BlackBoxExplorerResult, type BlackBoxFrame, SYSTEM_DIALOG_PACKAGES } from "./explorer.js"; export const DEFAULT_IOS_DEVICE = "iPhone 17 Pro"; export const DEFAULT_BINARY_PROJECT = "expo-explore"; @@ -502,11 +502,15 @@ export async function exploreConnectedSession(ctx: ConnectedSessionExploration): const bounds = frameBounds(frame.nodes); controller(["press", String(Math.round(action.x * bounds.width)), String(Math.round(action.y * bounds.height)), "--level", "full", "--json"], 120_000); } else if (action.action === "back") { - // Onboarding steps, tabs and sheets have no back control; the platform gesture (iOS edge swipe, Android back) still works. + // On iOS agent-device's in-app back already falls back to the edge swipe, and names a modal's one dismiss + // control when that changed nothing. The Argent bridge sends nothing without a back control; Android's + // system back still works there. try { controller(["back", "--in-app", "--level", "full", "--json"], 120_000); } catch (error) { - if (!(error instanceof Error) || !/in-app back control is not available/.test(error.message)) throw error; - controller(["back", "--system", "--level", "full", "--json"], 120_000); + const control = loneBackDismissControl(error); + if (control && riskOf(control.label, allowDestructive ?? []) === "safe") controller(["press", "--level", "full", "--json", "--", control.selector], 120_000); + else if (controllerFailureReason(error) === "back_swipe_not_dispatched") controller(["back", "--system", "--level", "full", "--json"], 120_000); + else throw error; } } else if (action.action === "dismiss-keyboard") await dismissKeyboard(); @@ -516,7 +520,7 @@ export async function exploreConnectedSession(ctx: ConnectedSessionExploration): }; const dismissKeyboard = async () => { try { controller(["keyboard", "dismiss", "--level", "full", "--json"], 120_000); return; } - catch (error) { if (!(error instanceof Error) || !/Unable to dismiss the iOS keyboard/.test(error.message)) throw error; } + catch (error) { if (controllerFailureReason(error) !== "keyboard_dismiss_unavailable") throw error; } // The iOS keyboard has no dismiss key and agent-device never taps the background; its return key (next/done/go) closes it without touching the app. const nodes = (await observe(false)).nodes; // In a multi-line editor the return key inserts a newline instead of ending editing. diff --git a/src/capture/argent-driver.ts b/src/capture/argent-driver.ts index ccc8d48c..e3096e59 100644 --- a/src/capture/argent-driver.ts +++ b/src/capture/argent-driver.ts @@ -76,7 +76,7 @@ const failure = (code: string, message: string, details?: Record failure("COMMAND_FAILED", "Remote daemon is unavailable"); +const remoteUnavailable = () => failure("COMMAND_FAILED", "Remote daemon is unavailable", { reason: "remote_daemon_unavailable", dispatched: "no" }); /** Flags agent-device takes after a command; the bridge needs the platform only from its own context. */ const VALUE_FLAGS = new Set(["--session", "--device", "--platform", "--level", "--udid", "--scope", "--bundle-id", "--serial", "--timeout"]); @@ -613,17 +613,17 @@ export async function runBridgeCommand(argv: readonly string[], context: ArgentB await beforeAction(); if (platform === "android") await call("button", { button: "back" }); else { - // agent-device taps the keyboard's own dismiss control, and fails with this message when there is none, which + // agent-device taps the keyboard's own dismiss control, and refuses with this reason when there is none, which // callers answer with the return key. Only a key in the keyboard's area counts: an app's "Done" above it is not one. const key = flatten(current).find(node => KEYBOARD_DISMISS_LABELS.includes(node.label ?? "") && node.frame && node.frame.y >= KEYBOARD_TOP); - if (!key) return failure("COMMAND_FAILED", "Unable to dismiss the iOS keyboard: the keyboard exposes no dismiss control."); + if (!key) return failure("UNSUPPORTED_OPERATION", "Unable to dismiss the keyboard: it exposes no dismiss key.", { reason: "keyboard_dismiss_unavailable", dispatched: "no" }); const size = current.screen ?? await screen(); await tap(...Object.values(centre({ x: key.frame!.x * size.width, y: key.frame!.y * size.height, width: key.frame!.width * size.width, height: key.frame!.height * size.height }, size)) as [number, number]); } await context.sleep(500); const visible = (await tree()).keyboardVisible === true; - if (visible && platform === "ios") return failure("COMMAND_FAILED", "Unable to dismiss the iOS keyboard: it is still showing after its dismiss key was pressed."); + if (visible && platform === "ios") return failure("COMMAND_FAILED", "Unable to dismiss the keyboard: it is still showing after its dismiss key was pressed.", { reason: "keyboard_dismiss_unavailable" }); return success({ platform, action: "dismiss", wasVisible: true, dismissed: !visible, visible }); } case "scroll": { @@ -666,7 +666,7 @@ export async function runBridgeCommand(argv: readonly string[], context: ArgentB await tap(button.frame.x + button.frame.width / 2, button.frame.y + button.frame.height / 2); return success({ action: "back", mode: "in-app" }); } - if (flags["in-app"] === true || platform === "ios") return failure("COMMAND_FAILED", "in-app back control is not available"); + if (flags["in-app"] === true || platform === "ios") return failure("COMMAND_FAILED", "in-app back control is not available", { reason: "back_swipe_not_dispatched", dispatched: "no" }); await call("button", { button: "back" }); return success({ action: "back", mode: "system" }); } @@ -776,7 +776,7 @@ export async function runBridgeCommand(argv: readonly string[], context: ArgentB if (error instanceof BridgeFailure) return failure(error.code, error.message); if (error instanceof ArgentCallError) { // Never "Remote daemon is unavailable" here: the request may have run, so Explore must not resend it. - return failure(error.sent ? "ARGENT_TOOL_FAILED" : "COMMAND_FAILED", error.sent ? error.message : "Remote daemon is unavailable"); + return error.sent ? failure("ARGENT_TOOL_FAILED", error.message) : remoteUnavailable(); } return failure("ARGENT_BRIDGE_FAILED", error instanceof Error ? error.message : String(error)); } diff --git a/src/capture/controller.ts b/src/capture/controller.ts index 4ed312ed..cca03ccb 100644 --- a/src/capture/controller.ts +++ b/src/capture/controller.ts @@ -106,6 +106,36 @@ export function controllerCommandFailure(stdout: string, command: string): CiErr return failure; } +/** agent-device's typed refusal reason (`error.details.reason`), when the failure carries one. */ +export function controllerFailureReason(error: unknown): string | undefined { + if (!(error instanceof CiError)) return undefined; + const details = nativeControllerFailures.get(error)?.details; + return isRecord(details) && typeof details.reason === "string" ? details.reason : undefined; +} + +/** + * A back that left the screen as it was: agent-device swiped from the left edge and nothing changed + * (`back_swipe_no_change`), or sent nothing (`back_swipe_not_dispatched`, also the Argent bridge's answer + * when the screen has no back control). + */ +export function backLeftScreenUnchanged(error: unknown): boolean { + const reason = controllerFailureReason(error); + return reason === "back_swipe_no_change" || reason === "back_swipe_not_dispatched"; +} + +/** + * The one dismiss control (Close, Cancel, Back) agent-device saw in the screen's top bar when its back changed + * nothing (`details.dismissControls`). agent-device never presses it: on iOS back only pops the navigation stack. + * Undefined when it listed none or several. + */ +export function loneBackDismissControl(error: unknown): { selector: string; label: string } | undefined { + if (controllerFailureReason(error) !== "back_swipe_no_change") return undefined; + const controls = (nativeControllerFailures.get(error as CiError)?.details as Record | undefined)?.dismissControls; + if (!Array.isArray(controls) || controls.length !== 1 || !isRecord(controls[0])) return undefined; + const { selector, label } = controls[0]; + return typeof selector === "string" && selector.trim() && typeof label === "string" ? { selector, label } : undefined; +} + function busyControllerReadFailure(error: unknown): boolean { if (!(error instanceof CiError)) return false; const native = nativeControllerFailures.get(error); @@ -158,14 +188,14 @@ function responsiveAccessibilityRead(args: readonly string[], result: CommandRes } /** - * agent-device checks the remote daemon's /health, with a 3 s timeout, before it sends a command, - * and fails with this error when the check gets no answer or a 5xx. The command itself was never - * sent, so sending it again cannot repeat anything, even a UI action. + * agent-device checks the remote daemon's /health before it sends a command, and refuses with + * `remote_daemon_unavailable` and `dispatched: "no"` when the check gets no answer or a 5xx. The + * command itself was never sent, so sending it again cannot repeat anything, even a UI action. */ export function remoteDaemonUnavailable(error: unknown): boolean { - if (!(error instanceof CiError)) return false; - const native = nativeControllerFailures.get(error); - return !!native && native.code === "COMMAND_FAILED" && native.message === "Remote daemon is unavailable"; + if (controllerFailureReason(error) !== "remote_daemon_unavailable") return false; + const details = nativeControllerFailures.get(error as CiError)?.details; + return isRecord(details) && details.dispatched === "no"; } /** diff --git a/src/capture/route-capture.ts b/src/capture/route-capture.ts index 108600e9..204c9698 100644 --- a/src/capture/route-capture.ts +++ b/src/capture/route-capture.ts @@ -23,7 +23,8 @@ import { CAPTURE_OBSERVER_IDENTIFIER, captureObserverMarkers, parseCaptureDestin import { type CiAgentRuntimeOptions, runCiAgentNavigation, assertAgentCaptureContext } from "./agent/runtime.js"; import { createExplorationInputs } from "../config/exploration-inputs.js"; import { isRecord, captureError, CONTROLLER_SESSION, parseJson } from "./common.js"; -import { MAX_ACCESSIBILITY_EVIDENCE_BYTES, adbDeviceOffline, remoteDaemonUnavailable, controllerData, defaultRunner, type ControllerReadRecovery, type RemoteDaemonRetry, runControllerRead, controllerCommandFailure, runControllerReadAsync, runAgentControllerCommand, wedgedControllerReadFailure, openedSimulatorDevice, alertWatchdogFailure } from "./controller.js"; +import { MAX_ACCESSIBILITY_EVIDENCE_BYTES, adbDeviceOffline, remoteDaemonUnavailable, controllerData, defaultRunner, type ControllerReadRecovery, type RemoteDaemonRetry, runControllerRead, controllerCommandFailure, runControllerReadAsync, runAgentControllerCommand, wedgedControllerReadFailure, openedSimulatorDevice, alertWatchdogFailure, backLeftScreenUnchanged, loneBackDismissControl } from "./controller.js"; +import { riskOf } from "../binary/explorer.js"; import type { ActiveSimulatorRuntime, SimulatorConnection } from "./simulator.js"; import { androidTools } from "./local-simulator.js"; import type { CiMapOptions, CommandResult } from "./run.js"; @@ -771,14 +772,23 @@ export async function capturePlannedRoutes(options: { const toLogical = (space: { width: number; height: number; transposed: boolean }, x: number, y: number): [number, number] => space.transposed ? [y * space.width, (1 - x) * space.height] : [x * space.width, y * space.height]; /** - * agent-device's in-app back taps a navigation control and cannot leave a sheet without one. - * Swipe such a sheet down, then require the observed destination to change. + * agent-device's back presses the navigation bar back button, else swipes from the left edge, which + * cannot leave a modal or a sheet. Press the modal's one dismiss control that agent-device names, or swipe + * a sheet down, then require the observed destination to change. */ const back = async (signal: AbortSignal): Promise<{ via: string } | undefined> => { try { await command(["back", "--level", "full", "--json"], signal); return; } catch (error) { - if (!(error instanceof CiError) || !/in-app back control is not available/.test(error.message)) throw error; + if (!backLeftScreenUnchanged(error)) throw error; const before = (await readSnapshot(signal)).snapshot.nodes; + const control = loneBackDismissControl(error); + if (control && riskOf(control.label, []) === "safe") { + await command(["press", control.selector, "--level", "full", "--json"], signal); + for (let attempt = 0; attempt < 4; attempt++) { + await sleep(500, undefined, { signal: liveSignal(signal) }); + if (observerIdentity((await readSnapshot(signal)).snapshot.nodes) !== observerIdentity(before)) return { via: "dismiss-control" }; + } + } let gesture = sheetDismissGesture(before); if (!gesture) throw error; const gestures: [number, number, number, number][] = []; diff --git a/src/shared/agent-device-version.ts b/src/shared/agent-device-version.ts index aaadb8d6..f95536eb 100644 --- a/src/shared/agent-device-version.ts +++ b/src/shared/agent-device-version.ts @@ -3,4 +3,4 @@ * controller (`--package-version`), the daemon health check, and the screenshot diff tool must * all be this version; each caller checks it by exact equality. */ -export const AGENT_DEVICE_VERSION = "0.21.29-nightly.20261018.74"; +export const AGENT_DEVICE_VERSION = "0.21.39"; diff --git a/src/shared/controller-cache.ts b/src/shared/controller-cache.ts index 2db6e352..0b0abd33 100644 --- a/src/shared/controller-cache.ts +++ b/src/shared/controller-cache.ts @@ -21,7 +21,7 @@ export type ControllerName = "agent-device" | "argent"; /** Each controller's npm release, the file Explore runs from it, and the integrity npm publishes for it. */ export const CONTROLLER_PACKAGES: Record = { "agent-device": { name: "agent-device", version: AGENT_DEVICE_VERSION, bin: "bin/agent-device.mjs", - integrity: "sha512-7+ajWLr0J+8iLZ9q11ERbj6U14mC20umBK5BQQdw5aERA79yeXc3Ze6KmtvnILnWjEtoVkYQsXQasL8RL6Uatw==" }, + integrity: "sha512-flgrilleoUU9WNd9BlU8h5KMt8zv0nKWBkqJbzk/bb2NBRA+7H1FGja+RIAuapb7HXdsjK4EPnYFP37N9S8nMA==" }, argent: { name: "@swmansion/argent", version: ARGENT_VERSION, bin: "dist/cli.js", integrity: "sha512-XXWlWZJlHKqnAvNx3RDhuiVFQOPqh5EDB76+mFAyqC2mutC6irzw03+M/6S/WQ+Dzz2IYOkEfOzQnOOdhrGgJg==" }, }; diff --git a/test/node/argent-driver.test.mjs b/test/node/argent-driver.test.mjs index 290115c7..f0a45f75 100644 --- a/test/node/argent-driver.test.mjs +++ b/test/node/argent-driver.test.mjs @@ -222,11 +222,11 @@ test("keyboard dismiss matches agent-device: Android presses back; iOS taps a di assert.deepEqual(dismissed.json.data, { platform: "android", action: "dismiss", wasVisible: true, dismissed: true, visible: false }); assert.deepEqual(android.calls.find(call => call.tool === "button").args, { udid: "emulator-5554", button: "back" }); - // agent-device fails with this message when the keyboard has no dismiss key, and callers fall back to the return key. + // agent-device refuses with this reason when the keyboard has no dismiss key, and callers fall back to the return key. const noKey = harness("ios", { "list-devices": IOS_DEVICES, "ui-tree": { ...IOS_HOME, keyboardVisible: true } }); const failed = await noKey.run(["keyboard", "dismiss", ...flags("ios")]); assert.equal(failed.exitCode, 1); - assert.match(failed.json.error.message, /^Unable to dismiss the iOS keyboard/); + assert.equal(failed.json.error.details.reason, "keyboard_dismiss_unavailable"); const hidden = harness("ios", { "list-devices": IOS_DEVICES, "ui-tree": IOS_HOME }); assert.equal((await hidden.run(["keyboard", "dismiss", ...flags("ios")])).json.data.wasVisible, false); @@ -237,6 +237,7 @@ test("iOS back with no navigation bar back control fails with agent-device's mes const back = await run(["back", ...flags("ios")]); assert.equal(back.exitCode, 1); assert.equal(back.json.error.message, "in-app back control is not available"); + assert.equal(back.json.error.details.reason, "back_swipe_not_dispatched"); }); test("alerts read and answer in each platform's agent-device shape", async () => { @@ -298,7 +299,7 @@ test("a tool-server that is still starting is waited for before the action is se test("an unreachable tool-server before a UI action is the retryable 'Remote daemon is unavailable'", async () => { const { run, calls } = harness("ios", { "list-devices": IOS_DEVICES, "ui-tree": IOS_HOME, "gesture-tap": {} }, { reachable: false }); const pressed = await run(["press", "10", "10", ...flags("ios")]); - assert.deepEqual(pressed.json.error, { code: "COMMAND_FAILED", message: "Remote daemon is unavailable" }); + assert.deepEqual(pressed.json.error, { code: "COMMAND_FAILED", message: "Remote daemon is unavailable", details: { reason: "remote_daemon_unavailable", dispatched: "no" } }); assert.ok(!calls.some(call => call.tool === "gesture-tap")); }); diff --git a/test/node/ci-map.test.mjs b/test/node/ci-map.test.mjs index 5f43faa4..53ce6fd6 100644 --- a/test/node/ci-map.test.mjs +++ b/test/node/ci-map.test.mjs @@ -58,9 +58,9 @@ const recoveredSnapshot = result => { const value = JSON.parse(result.stdout); return { ...result, stdout: JSON.stringify({ ...value, data: { ...value.data, snapshotQuality: { state: 'recovered', backend: 'tree' } } }) }; }; -// agent-device 0.21.15 raises this before sending a command when the remote daemon's /health check fails. +// agent-device 0.21.39 raises this before sending a command when the remote daemon's /health check fails. const daemonUnavailable = () => json({ success: false, error: { code: 'COMMAND_FAILED', message: 'Remote daemon is unavailable', - details: { daemonBaseUrl: 'https://daemon.example.invalid', hint: 'Verify AGENT_DEVICE_DAEMON_BASE_URL points to a reachable daemon.' } } }); + details: { reason: 'remote_daemon_unavailable', dispatched: 'no', daemonBaseUrl: 'https://daemon.example.invalid', attempts: 1 } } }); const value = (request, name) => request.args[request.args.indexOf(name) + 1]; // agent-device 0.21.15 while its XCTest snapshot tiers are deferred and iOS shows the Save Password // prompt, which com.apple.SafariViewService hosts. @@ -3706,7 +3706,8 @@ function sheetRunner(f, { dismissible = true, sheetOrigin = 72 } = {}) { if (request.command === 'fake-controller') { const [command] = request.args; if (command === 'open' && request.args[2]?.startsWith('sample://')) { path = '/' + request.args[2].slice('sample://'.length); sheet = path === '/settings'; } - if (command === 'back' && sheet) return json({ success: false, error: { code: 'COMMAND_FAILED', message: 'in-app back control is not available' } }); + // agent-device 0.21.39 swipes from the left edge when there is no navigation back button; a sheet stays. + if (command === 'back' && sheet) return json({ success: false, error: { code: 'COMMAND_FAILED', message: 'The back swipe changed nothing.', details: { reason: 'back_swipe_no_change', runnerErrorCode: 'BACK_SWIPE_NO_CHANGE', dispatched: 'unknown' } } }); if (command === 'swipe') { swipes.push(request.args.slice(1, 5)); if (dismissible) { sheet = false; path = '/home'; } return ok({}); } } const response = f.options.runner(request); @@ -3780,10 +3781,66 @@ test('agent back reports a sheet that stays open, and never swipes without sheet const plainTrace = (await readFile(join(plain.options.outputDirectory, 'capture-diagnostics/agent-navigation.jsonl'), 'utf8')).trim().split('\n').map(JSON.parse); const unavailable = plainTrace.find(event => event.action === 'back'); assert.equal(unavailable.result.error.code, 'COMMAND_FAILED'); - assert.match(unavailable.result.error.message, /in-app back control is not available/); + assert.match(unavailable.result.error.message, /The back swipe changed nothing/); assert.equal(screen.swipes.length, 0); }); +/** A full-screen modal whose only exit is a header control agent-device names when its back changes nothing. */ +function modalRunner(f, { label = 'Close' } = {}) { + let path = '/', modal = false; + const presses = []; + const selector = `role=button label="${label}"`; + const runner = request => { + if (request.command === 'fake-controller') { + const [command] = request.args; + if (command === 'open' && request.args[2]?.startsWith('sample://')) { path = '/' + request.args[2].slice('sample://'.length); modal = path === '/settings'; } + if (command === 'back' && modal) return json({ success: false, error: { code: 'COMMAND_FAILED', message: 'The back swipe changed nothing.', + details: { reason: 'back_swipe_no_change', runnerErrorCode: 'BACK_SWIPE_NO_CHANGE', dispatched: 'unknown', dismissControls: [{ selector, label }] } } }); + if (command === 'press' && request.args[1] === selector) { presses.push(request.args[1]); modal = false; path = '/home'; return ok({}); } + } + const response = f.options.runner(request); + if (request.command === 'fake-controller' && request.args[0] === 'snapshot') { + const value = JSON.parse(response.stdout); + for (const node of value.data.nodes) if (node.identifier === CAPTURE_OBSERVER_IDENTIFIER) { + node.label = JSON.stringify({ provider: 'expo-router', pathname: path, segments: path.split('/').filter(Boolean), parameters: {} }); + node.rect = { x: 0, y: 0, width: 1, height: 1 }; + } + value.data.nodes.unshift({ type: 'Application', rect: { x: 0, y: 0, width: 402, height: 874 }, visible: true }); + return { ...response, stdout: JSON.stringify(value) }; + } + return response; + }; + return { runner, presses }; +} + +const modalBackAgent = f => agentFixture([ + { action: 'capture', targetId: f.ids.home, description: 'Loaded home.', requiredLabels: ['screen-title'] }, + { action: 'open', url: 'sample://settings' }, + { action: 'capture', targetId: f.ids.settings, description: 'Settings modal.', requiredLabels: ['screen-title'] }, + { action: 'back' }, + { action: 'done' }, +]); + +test('agent back presses the one dismiss control agent-device names when its back changes nothing', async t => { + const f = await fixture(t); + const modal = modalRunner(f); + await runCiMap({ ...f.options, runner: modal.runner, agent: modalBackAgent(f), setup: [{ action: 'open', url: 'sample://home' }] }); + assert.deepEqual(modal.presses, ['role=button label="Close"']); + const trace = (await readFile(join(f.options.outputDirectory, 'capture-diagnostics/agent-navigation.jsonl'), 'utf8')).trim().split('\n').map(JSON.parse); + const back = trace.find(event => event.action === 'back'); + assert.equal(back.result.performed, 'back'); + assert.equal(back.result.via, 'dismiss-control'); +}); + +test('agent back never presses a named dismiss control that reads as destructive', async t => { + const f = await fixture(t); + const modal = modalRunner(f, { label: 'Cancel subscription' }); + await runCiMap({ ...f.options, runner: modal.runner, agent: modalBackAgent(f), setup: [{ action: 'open', url: 'sample://home' }] }); + assert.deepEqual(modal.presses, []); + const trace = (await readFile(join(f.options.outputDirectory, 'capture-diagnostics/agent-navigation.jsonl'), 'utf8')).trim().split('\n').map(JSON.parse); + assert.equal(trace.find(event => event.action === 'back').result.error.code, 'COMMAND_FAILED'); +}); + test('agent back swipes again when the first drag moves a sheet without closing it', async t => { const f = await fixture(t); const sheet = sheetRunner(f, { dismissible: false }); diff --git a/test/node/public-comment.test.mjs b/test/node/public-comment.test.mjs index e7f42319..74ca121d 100644 --- a/test/node/public-comment.test.mjs +++ b/test/node/public-comment.test.mjs @@ -746,10 +746,10 @@ const footnote = 'Added text “Changes apply live while playing. Base resolutio const footnoteText = 'Added text “Changes apply live while playing\\. Base resolution sets the step grid for lanes you add next\\.”'; function euxyReview(target, options = {}) { const own = { sourceImpact: ['own'], sourceScope: 'screen' }; - const matched = { verdict: 'unchanged', reason: 'matched', mismatchPercentage: 0, threshold: 0.1, tool: 'agent-device@0.21.29' }; + const matched = { verdict: 'unchanged', reason: 'matched', mismatchPercentage: 0, threshold: 0.1, tool: 'agent-device@0.21.39' }; const changed = (description, mismatchPercentage) => ({ ...own, review: { status: 'modified', description, facts: [{ category: 'element', templateId: 'element.added', bullet: description }] }, - visual: { verdict: 'modified', reason: 'repeated-cross-build-delta', mismatchPercentage, threshold: 0.1, tool: 'agent-device@0.21.29' } }); + visual: { verdict: 'modified', reason: 'repeated-cross-build-delta', mismatchPercentage, threshold: 0.1, tool: 'agent-device@0.21.39' } }); const inTreeOnly = { ...changed(footnote, 0), visual: matched }; if (options.offScreen !== false) inTreeOnly.review.offScreen = true; if (options.diffFailed) inTreeOnly.visual = { ...matched, reason: 'diff-failed' }; @@ -799,7 +799,7 @@ test('a change one platform has and another lacks keeps "only" and "not on"', as const iosOnly = target => { const reviewed = euxyReview(target); if (target === 'android') for (const entry of reviewed.surfaces) Object.assign(entry, { review: { status: 'unchanged', description: 'No visible change' }, - visual: { verdict: 'unchanged', reason: 'matched', mismatchPercentage: 0, threshold: 0.1, tool: 'agent-device@0.21.29' } }); + visual: { verdict: 'unchanged', reason: 'matched', mismatchPercentage: 0, threshold: 0.1, tool: 'agent-device@0.21.39' } }); return reviewed; }; const { rows } = await euxyRows(iosOnly); diff --git a/test/node/public-review-validation.test.mjs b/test/node/public-review-validation.test.mjs index 932ab537..26774434 100644 --- a/test/node/public-review-validation.test.mjs +++ b/test/node/public-review-validation.test.mjs @@ -325,7 +325,7 @@ test("a review says its change is off-screen only on a modified verdict whose sc const offScreen = (status, verdict) => { const input = review(); input.surfaces[0].review = { status, description: status === "modified" ? "Added text “lanes you add next”." : "No visible change", offScreen: true }; - input.surfaces[0].visual = { verdict, reason: verdict === "unchanged" ? "matched" : "repeated-cross-build-delta", mismatchPercentage: verdict === "unchanged" ? 0 : 3, threshold: 0.1, tool: "agent-device@0.21.29" }; + input.surfaces[0].visual = { verdict, reason: verdict === "unchanged" ? "matched" : "repeated-cross-build-delta", mismatchPercentage: verdict === "unchanged" ? 0 : 3, threshold: 0.1, tool: "agent-device@0.21.39" }; return input; }; assert.doesNotThrow(() => assertPublicReview(offScreen("modified", "unchanged"))); From 745c4aa97f4b6d77637896056658405115ccc7a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 17 Nov 2026 15:40:18 +0100 Subject: [PATCH 02/10] Binary back counts a dismiss-control press only when the screen changed As in source-driven capture, explore:binary compares the screen before and after it presses the dismiss control agent-device named, and fails the back with agent-device's refusal when nothing changed. Co-Authored-By: Claude Opus 5.5 --- src/binary/run.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/binary/run.ts b/src/binary/run.ts index afd15b78..044db8bb 100644 --- a/src/binary/run.ts +++ b/src/binary/run.ts @@ -29,7 +29,7 @@ import { packageBin } from "../shared/package-paths.js"; import { assertDecodedPng, solidColour } from "../shared/png-evidence.js"; import { CONTRACT, type ExploreMap, type Platform } from "../types.js"; import { assertEmulatorCompatible, extractIosBundle, inspectArchive, type ArchiveKind, type InspectedArchive, readArchiveIcon } from "./archive.js"; -import { riskOf, runBlackBoxExploration, type BlackBoxExplorerResult, type BlackBoxFrame, SYSTEM_DIALOG_PACKAGES } from "./explorer.js"; +import { riskOf, runBlackBoxExploration, screenEvidenceKey, type BlackBoxExplorerResult, type BlackBoxFrame, SYSTEM_DIALOG_PACKAGES } from "./explorer.js"; export const DEFAULT_IOS_DEVICE = "iPhone 17 Pro"; export const DEFAULT_BINARY_PROJECT = "expo-explore"; @@ -508,7 +508,13 @@ export async function exploreConnectedSession(ctx: ConnectedSessionExploration): try { controller(["back", "--in-app", "--level", "full", "--json"], 120_000); } catch (error) { const control = loneBackDismissControl(error); - if (control && riskOf(control.label, allowDestructive ?? []) === "safe") controller(["press", "--level", "full", "--json", "--", control.selector], 120_000); + if (control && riskOf(control.label, allowDestructive ?? []) === "safe") { + // As in source-driven capture, the press counts as back only when the screen changed. + const before = screenEvidenceKey((await observe(false)).nodes); + controller(["press", "--level", "full", "--json", "--", control.selector], 120_000); + await settled(); + if (screenEvidenceKey((await observe(false)).nodes) === before) throw error; + } else if (controllerFailureReason(error) === "back_swipe_not_dispatched") controller(["back", "--system", "--level", "full", "--json"], 120_000); else throw error; } From d18339df4f441170c0291e34a3d5ffe80b33712f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 17 Nov 2026 16:23:03 +0100 Subject: [PATCH 03/10] Back accepts a modal that closes without a route change, and never swipes after a press A modal kept in a screen's own state keeps the route when its Close control dismisses it, so the destination check alone read that as a failure and fell through to the sheet swipe-down with the geometry read before the press. A press now counts when the route changes or the pressed control is gone. If neither happens, back fails with AGENT_DISMISS_CONTROL_FAILED instead of swiping. Co-Authored-By: Claude Opus 5.5 --- src/capture/route-capture.ts | 12 +++++++++++- test/node/ci-map.test.mjs | 29 +++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/capture/route-capture.ts b/src/capture/route-capture.ts index 204c9698..0d14d93e 100644 --- a/src/capture/route-capture.ts +++ b/src/capture/route-capture.ts @@ -783,11 +783,21 @@ export async function capturePlannedRoutes(options: { const before = (await readSnapshot(signal)).snapshot.nodes; const control = loneBackDismissControl(error); if (control && riskOf(control.label, []) === "safe") { + // A modal kept in a screen's own state closes without a route change, so the control leaving counts too. + const controlShown = (nodes: readonly Record[]) => nodes.some(node => + node.label === control.label && /button/i.test(String(node.type ?? "")) && node.visible !== false); await command(["press", control.selector, "--level", "full", "--json"], signal); + let after = before; for (let attempt = 0; attempt < 4; attempt++) { await sleep(500, undefined, { signal: liveSignal(signal) }); - if (observerIdentity((await readSnapshot(signal)).snapshot.nodes) !== observerIdentity(before)) return { via: "dismiss-control" }; + after = (await readSnapshot(signal)).snapshot.nodes; + if (observerIdentity(after) !== observerIdentity(before) || !controlShown(after)) return { via: "dismiss-control" }; } + // The press ran, so a sheet swipe from the geometry read before it could land on whatever is there now. + throw new CiError({ code: "AGENT_DISMISS_CONTROL_FAILED", stage: "capture", + message: `Pressed "${control.label}", the control agent-device named for leaving this screen, but the screen did not change.`, + nextAction: "Inspect the returned accessibility: a confirmation may have appeared. Use an observed control rather than repeating back.", + details: { back: serializeCiError(error, { secrets }), control: control.label, destinationBefore: observerIdentity(before), destinationAfter: observerIdentity(after) } }); } let gesture = sheetDismissGesture(before); if (!gesture) throw error; diff --git a/test/node/ci-map.test.mjs b/test/node/ci-map.test.mjs index 53ce6fd6..957de2be 100644 --- a/test/node/ci-map.test.mjs +++ b/test/node/ci-map.test.mjs @@ -3786,9 +3786,9 @@ test('agent back reports a sheet that stays open, and never swipes without sheet }); /** A full-screen modal whose only exit is a header control agent-device names when its back changes nothing. */ -function modalRunner(f, { label = 'Close' } = {}) { +function modalRunner(f, { label = 'Close', sameRoute = false, closes = true } = {}) { let path = '/', modal = false; - const presses = []; + const presses = [], swipes = []; const selector = `role=button label="${label}"`; const runner = request => { if (request.command === 'fake-controller') { @@ -3796,7 +3796,8 @@ function modalRunner(f, { label = 'Close' } = {}) { if (command === 'open' && request.args[2]?.startsWith('sample://')) { path = '/' + request.args[2].slice('sample://'.length); modal = path === '/settings'; } if (command === 'back' && modal) return json({ success: false, error: { code: 'COMMAND_FAILED', message: 'The back swipe changed nothing.', details: { reason: 'back_swipe_no_change', runnerErrorCode: 'BACK_SWIPE_NO_CHANGE', dispatched: 'unknown', dismissControls: [{ selector, label }] } } }); - if (command === 'press' && request.args[1] === selector) { presses.push(request.args[1]); modal = false; path = '/home'; return ok({}); } + if (command === 'press' && request.args[1] === selector) { presses.push(request.args[1]); if (closes) { modal = false; if (!sameRoute) path = '/home'; } return ok({}); } + if (command === 'swipe') swipes.push(request.args.slice(1, 5)); } const response = f.options.runner(request); if (request.command === 'fake-controller' && request.args[0] === 'snapshot') { @@ -3806,11 +3807,12 @@ function modalRunner(f, { label = 'Close' } = {}) { node.rect = { x: 0, y: 0, width: 1, height: 1 }; } value.data.nodes.unshift({ type: 'Application', rect: { x: 0, y: 0, width: 402, height: 874 }, visible: true }); + if (modal) value.data.nodes.push({ type: 'Button', label, rect: { x: 340, y: 60, width: 44, height: 44 }, visible: true }); return { ...response, stdout: JSON.stringify(value) }; } return response; }; - return { runner, presses }; + return { runner, presses, swipes }; } const modalBackAgent = f => agentFixture([ @@ -3832,6 +3834,25 @@ test('agent back presses the one dismiss control agent-device names when its bac assert.equal(back.result.via, 'dismiss-control'); }); +test('a dismiss control that closes a modal without changing the route counts once the control is gone', async t => { + const f = await fixture(t); + const modal = modalRunner(f, { sameRoute: true }); + await runCiMap({ ...f.options, runner: modal.runner, agent: modalBackAgent(f), setup: [{ action: 'open', url: 'sample://home' }] }); + assert.deepEqual(modal.presses, ['role=button label="Close"']); + const trace = (await readFile(join(f.options.outputDirectory, 'capture-diagnostics/agent-navigation.jsonl'), 'utf8')).trim().split('\n').map(JSON.parse); + assert.equal(trace.find(event => event.action === 'back').result.via, 'dismiss-control'); +}); + +test('a dismiss control press that changes nothing is reported, and no sheet swipe follows it', async t => { + const f = await fixture(t); + const modal = modalRunner(f, { closes: false }); + await runCiMap({ ...f.options, runner: modal.runner, agent: modalBackAgent(f), setup: [{ action: 'open', url: 'sample://home' }] }); + assert.deepEqual(modal.presses, ['role=button label="Close"']); + assert.deepEqual(modal.swipes, []); + const trace = (await readFile(join(f.options.outputDirectory, 'capture-diagnostics/agent-navigation.jsonl'), 'utf8')).trim().split('\n').map(JSON.parse); + assert.equal(trace.find(event => event.action === 'back').result.error.code, 'AGENT_DISMISS_CONTROL_FAILED'); +}); + test('agent back never presses a named dismiss control that reads as destructive', async t => { const f = await fixture(t); const modal = modalRunner(f, { label: 'Cancel subscription' }); From 01f4877ee094fbe4161c3fd11396cb7a2f845224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 17 Nov 2026 16:28:45 +0100 Subject: [PATCH 04/10] A pressed dismiss control that brings up an alert does not count as leaving the screen The pressed control disappearing counted as back, but a confirmation such as "Discard changes?" also hides it while the screen stays. The control leaving now counts only when no alert took its place; otherwise back fails with AGENT_DISMISS_CONTROL_FAILED. Co-Authored-By: Claude Opus 5.5 --- src/capture/route-capture.ts | 6 ++++-- test/node/ci-map.test.mjs | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/capture/route-capture.ts b/src/capture/route-capture.ts index 0d14d93e..723abc45 100644 --- a/src/capture/route-capture.ts +++ b/src/capture/route-capture.ts @@ -783,15 +783,17 @@ export async function capturePlannedRoutes(options: { const before = (await readSnapshot(signal)).snapshot.nodes; const control = loneBackDismissControl(error); if (control && riskOf(control.label, []) === "safe") { - // A modal kept in a screen's own state closes without a route change, so the control leaving counts too. + // A modal kept in a screen's own state closes without a route change, so the control leaving counts too, + // unless an alert took its place (a "Discard changes?" confirmation): that screen is not dismissed. const controlShown = (nodes: readonly Record[]) => nodes.some(node => node.label === control.label && /button/i.test(String(node.type ?? "")) && node.visible !== false); + const alertShown = (nodes: readonly Record[]) => nodes.some(node => node.type === "Alert"); await command(["press", control.selector, "--level", "full", "--json"], signal); let after = before; for (let attempt = 0; attempt < 4; attempt++) { await sleep(500, undefined, { signal: liveSignal(signal) }); after = (await readSnapshot(signal)).snapshot.nodes; - if (observerIdentity(after) !== observerIdentity(before) || !controlShown(after)) return { via: "dismiss-control" }; + if (observerIdentity(after) !== observerIdentity(before) || !controlShown(after) && !alertShown(after)) return { via: "dismiss-control" }; } // The press ran, so a sheet swipe from the geometry read before it could land on whatever is there now. throw new CiError({ code: "AGENT_DISMISS_CONTROL_FAILED", stage: "capture", diff --git a/test/node/ci-map.test.mjs b/test/node/ci-map.test.mjs index 957de2be..836edc7a 100644 --- a/test/node/ci-map.test.mjs +++ b/test/node/ci-map.test.mjs @@ -3786,8 +3786,8 @@ test('agent back reports a sheet that stays open, and never swipes without sheet }); /** A full-screen modal whose only exit is a header control agent-device names when its back changes nothing. */ -function modalRunner(f, { label = 'Close', sameRoute = false, closes = true } = {}) { - let path = '/', modal = false; +function modalRunner(f, { label = 'Close', sameRoute = false, closes = true, confirms = false } = {}) { + let path = '/', modal = false, confirming = false; const presses = [], swipes = []; const selector = `role=button label="${label}"`; const runner = request => { @@ -3796,7 +3796,7 @@ function modalRunner(f, { label = 'Close', sameRoute = false, closes = true } = if (command === 'open' && request.args[2]?.startsWith('sample://')) { path = '/' + request.args[2].slice('sample://'.length); modal = path === '/settings'; } if (command === 'back' && modal) return json({ success: false, error: { code: 'COMMAND_FAILED', message: 'The back swipe changed nothing.', details: { reason: 'back_swipe_no_change', runnerErrorCode: 'BACK_SWIPE_NO_CHANGE', dispatched: 'unknown', dismissControls: [{ selector, label }] } } }); - if (command === 'press' && request.args[1] === selector) { presses.push(request.args[1]); if (closes) { modal = false; if (!sameRoute) path = '/home'; } return ok({}); } + if (command === 'press' && request.args[1] === selector) { presses.push(request.args[1]); if (confirms) confirming = true; else if (closes) { modal = false; if (!sameRoute) path = '/home'; } return ok({}); } if (command === 'swipe') swipes.push(request.args.slice(1, 5)); } const response = f.options.runner(request); @@ -3807,7 +3807,8 @@ function modalRunner(f, { label = 'Close', sameRoute = false, closes = true } = node.rect = { x: 0, y: 0, width: 1, height: 1 }; } value.data.nodes.unshift({ type: 'Application', rect: { x: 0, y: 0, width: 402, height: 874 }, visible: true }); - if (modal) value.data.nodes.push({ type: 'Button', label, rect: { x: 340, y: 60, width: 44, height: 44 }, visible: true }); + if (confirming) value.data.nodes.push({ type: 'Alert', label: 'Discard changes?', rect: { x: 50, y: 300, width: 300, height: 200 }, visible: true }); + else if (modal) value.data.nodes.push({ type: 'Button', label, rect: { x: 340, y: 60, width: 44, height: 44 }, visible: true }); return { ...response, stdout: JSON.stringify(value) }; } return response; @@ -3853,6 +3854,15 @@ test('a dismiss control press that changes nothing is reported, and no sheet swi assert.equal(trace.find(event => event.action === 'back').result.error.code, 'AGENT_DISMISS_CONTROL_FAILED'); }); +test('a dismiss control press that brings up a confirmation is not reported as leaving the screen', async t => { + const f = await fixture(t); + const modal = modalRunner(f, { sameRoute: true, confirms: true }); + await runCiMap({ ...f.options, runner: modal.runner, agent: modalBackAgent(f), setup: [{ action: 'open', url: 'sample://home' }] }); + assert.deepEqual(modal.swipes, []); + const trace = (await readFile(join(f.options.outputDirectory, 'capture-diagnostics/agent-navigation.jsonl'), 'utf8')).trim().split('\n').map(JSON.parse); + assert.equal(trace.find(event => event.action === 'back').result.error.code, 'AGENT_DISMISS_CONTROL_FAILED'); +}); + test('agent back never presses a named dismiss control that reads as destructive', async t => { const f = await fixture(t); const modal = modalRunner(f, { label: 'Cancel subscription' }); From add2d04a753d9e92448c867a0dd12cd69f3132f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 17 Nov 2026 17:39:46 +0100 Subject: [PATCH 05/10] A dismiss-control press never counts as back while an alert is showing A "Discard changes?" confirmation after the press changes the screen, and can hide the route observer, so either signal alone read it as having left. Both code paths now require that no alert is showing before a press counts as back. Co-Authored-By: Claude Opus 5.5 --- src/binary/run.ts | 4 +++- src/capture/route-capture.ts | 2 +- test/node/ci-map.test.mjs | 14 +++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/binary/run.ts b/src/binary/run.ts index 044db8bb..95686455 100644 --- a/src/binary/run.ts +++ b/src/binary/run.ts @@ -513,7 +513,9 @@ export async function exploreConnectedSession(ctx: ConnectedSessionExploration): const before = screenEvidenceKey((await observe(false)).nodes); controller(["press", "--level", "full", "--json", "--", control.selector], 120_000); await settled(); - if (screenEvidenceKey((await observe(false)).nodes) === before) throw error; + // A "Discard changes?" confirmation changes the screen too, but leaves it in place. + const after = (await observe(false)).nodes; + if (screenEvidenceKey(after) === before || after.some(node => node.type === "Alert")) throw error; } else if (controllerFailureReason(error) === "back_swipe_not_dispatched") controller(["back", "--system", "--level", "full", "--json"], 120_000); else throw error; diff --git a/src/capture/route-capture.ts b/src/capture/route-capture.ts index 723abc45..017e4f8c 100644 --- a/src/capture/route-capture.ts +++ b/src/capture/route-capture.ts @@ -793,7 +793,7 @@ export async function capturePlannedRoutes(options: { for (let attempt = 0; attempt < 4; attempt++) { await sleep(500, undefined, { signal: liveSignal(signal) }); after = (await readSnapshot(signal)).snapshot.nodes; - if (observerIdentity(after) !== observerIdentity(before) || !controlShown(after) && !alertShown(after)) return { via: "dismiss-control" }; + if (!alertShown(after) && (observerIdentity(after) !== observerIdentity(before) || !controlShown(after))) return { via: "dismiss-control" }; } // The press ran, so a sheet swipe from the geometry read before it could land on whatever is there now. throw new CiError({ code: "AGENT_DISMISS_CONTROL_FAILED", stage: "capture", diff --git a/test/node/ci-map.test.mjs b/test/node/ci-map.test.mjs index 836edc7a..1415e310 100644 --- a/test/node/ci-map.test.mjs +++ b/test/node/ci-map.test.mjs @@ -3786,7 +3786,7 @@ test('agent back reports a sheet that stays open, and never swipes without sheet }); /** A full-screen modal whose only exit is a header control agent-device names when its back changes nothing. */ -function modalRunner(f, { label = 'Close', sameRoute = false, closes = true, confirms = false } = {}) { +function modalRunner(f, { label = 'Close', sameRoute = false, closes = true, confirms = false, hidesObserver = false } = {}) { let path = '/', modal = false, confirming = false; const presses = [], swipes = []; const selector = `role=button label="${label}"`; @@ -3807,6 +3807,7 @@ function modalRunner(f, { label = 'Close', sameRoute = false, closes = true, con node.rect = { x: 0, y: 0, width: 1, height: 1 }; } value.data.nodes.unshift({ type: 'Application', rect: { x: 0, y: 0, width: 402, height: 874 }, visible: true }); + if (confirming && hidesObserver) value.data.nodes = value.data.nodes.filter(node => node.identifier !== CAPTURE_OBSERVER_IDENTIFIER); if (confirming) value.data.nodes.push({ type: 'Alert', label: 'Discard changes?', rect: { x: 50, y: 300, width: 300, height: 200 }, visible: true }); else if (modal) value.data.nodes.push({ type: 'Button', label, rect: { x: 340, y: 60, width: 44, height: 44 }, visible: true }); return { ...response, stdout: JSON.stringify(value) }; @@ -3863,6 +3864,17 @@ test('a dismiss control press that brings up a confirmation is not reported as l assert.equal(trace.find(event => event.action === 'back').result.error.code, 'AGENT_DISMISS_CONTROL_FAILED'); }); +test('a confirmation that hides the route observer is not reported as leaving the screen', async t => { + const f = await fixture(t); + const modal = modalRunner(f, { sameRoute: true, confirms: true, hidesObserver: true }); + await runCiMap({ ...f.options, runner: modal.runner, agent: modalBackAgent(f), setup: [{ action: 'open', url: 'sample://home' }] }); + assert.deepEqual(modal.swipes, []); + const trace = (await readFile(join(f.options.outputDirectory, 'capture-diagnostics/agent-navigation.jsonl'), 'utf8')).trim().split('\n').map(JSON.parse); + const back = trace.find(event => event.action === 'back'); + assert.notEqual(back.result.via, 'dismiss-control'); + assert.ok(back.result.error, 'back must fail while the confirmation is showing'); +}); + test('agent back never presses a named dismiss control that reads as destructive', async t => { const f = await fixture(t); const modal = modalRunner(f, { label: 'Cancel subscription' }); From 74378c1e00be6a7e10250b724813d06fc2c1d52a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 19 Nov 2026 16:27:49 +0100 Subject: [PATCH 06/10] Match an unlabeled dismiss control by the identifier agent-device names agent-device names a dismiss control by its identifier when it has one, and its label may then be empty. The press check matched only the label, so a button with no label was never seen and the press counted as leaving even when the modal stayed. It now matches the control the way agent-device named it, and the control leaving counts only when it was on screen before the press. Co-Authored-By: Claude Opus 5.5 --- src/capture/controller.ts | 10 ++++++---- src/capture/route-capture.ts | 14 +++++++++----- test/node/ci-map.test.mjs | 27 +++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/capture/controller.ts b/src/capture/controller.ts index cca03ccb..e7837f49 100644 --- a/src/capture/controller.ts +++ b/src/capture/controller.ts @@ -126,14 +126,16 @@ export function backLeftScreenUnchanged(error: unknown): boolean { /** * The one dismiss control (Close, Cancel, Back) agent-device saw in the screen's top bar when its back changed * nothing (`details.dismissControls`). agent-device never presses it: on iOS back only pops the navigation stack. - * Undefined when it listed none or several. + * Undefined when it listed none or several. `identifier` is set when agent-device names the control by it; the + * label may then be empty. */ -export function loneBackDismissControl(error: unknown): { selector: string; label: string } | undefined { +export function loneBackDismissControl(error: unknown): { selector: string; label: string; identifier?: string } | undefined { if (controllerFailureReason(error) !== "back_swipe_no_change") return undefined; const controls = (nativeControllerFailures.get(error as CiError)?.details as Record | undefined)?.dismissControls; if (!Array.isArray(controls) || controls.length !== 1 || !isRecord(controls[0])) return undefined; - const { selector, label } = controls[0]; - return typeof selector === "string" && selector.trim() && typeof label === "string" ? { selector, label } : undefined; + const { selector, label, identifier } = controls[0]; + if (typeof selector !== "string" || !selector.trim() || typeof label !== "string") return undefined; + return typeof identifier === "string" && identifier ? { selector, label, identifier } : { selector, label }; } function busyControllerReadFailure(error: unknown): boolean { diff --git a/src/capture/route-capture.ts b/src/capture/route-capture.ts index 017e4f8c..17888c83 100644 --- a/src/capture/route-capture.ts +++ b/src/capture/route-capture.ts @@ -782,24 +782,28 @@ export async function capturePlannedRoutes(options: { if (!backLeftScreenUnchanged(error)) throw error; const before = (await readSnapshot(signal)).snapshot.nodes; const control = loneBackDismissControl(error); - if (control && riskOf(control.label, []) === "safe") { + const controlName = control && (control.label || control.identifier); + if (control && controlName && riskOf(controlName, []) === "safe") { // A modal kept in a screen's own state closes without a route change, so the control leaving counts too, // unless an alert took its place (a "Discard changes?" confirmation): that screen is not dismissed. + // The control is matched the way agent-device named it: by identifier when it has one, else by label. const controlShown = (nodes: readonly Record[]) => nodes.some(node => - node.label === control.label && /button/i.test(String(node.type ?? "")) && node.visible !== false); + (control.identifier ? node.identifier === control.identifier : node.label === control.label) + && /button/i.test(String(node.type ?? "")) && node.visible !== false); + const controlWasShown = controlShown(before); const alertShown = (nodes: readonly Record[]) => nodes.some(node => node.type === "Alert"); await command(["press", control.selector, "--level", "full", "--json"], signal); let after = before; for (let attempt = 0; attempt < 4; attempt++) { await sleep(500, undefined, { signal: liveSignal(signal) }); after = (await readSnapshot(signal)).snapshot.nodes; - if (!alertShown(after) && (observerIdentity(after) !== observerIdentity(before) || !controlShown(after))) return { via: "dismiss-control" }; + if (!alertShown(after) && (observerIdentity(after) !== observerIdentity(before) || (controlWasShown && !controlShown(after)))) return { via: "dismiss-control" }; } // The press ran, so a sheet swipe from the geometry read before it could land on whatever is there now. throw new CiError({ code: "AGENT_DISMISS_CONTROL_FAILED", stage: "capture", - message: `Pressed "${control.label}", the control agent-device named for leaving this screen, but the screen did not change.`, + message: `Pressed "${controlName}", the control agent-device named for leaving this screen, but the screen did not change.`, nextAction: "Inspect the returned accessibility: a confirmation may have appeared. Use an observed control rather than repeating back.", - details: { back: serializeCiError(error, { secrets }), control: control.label, destinationBefore: observerIdentity(before), destinationAfter: observerIdentity(after) } }); + details: { back: serializeCiError(error, { secrets }), control: controlName, destinationBefore: observerIdentity(before), destinationAfter: observerIdentity(after) } }); } let gesture = sheetDismissGesture(before); if (!gesture) throw error; diff --git a/test/node/ci-map.test.mjs b/test/node/ci-map.test.mjs index 1415e310..90679289 100644 --- a/test/node/ci-map.test.mjs +++ b/test/node/ci-map.test.mjs @@ -3786,16 +3786,18 @@ test('agent back reports a sheet that stays open, and never swipes without sheet }); /** A full-screen modal whose only exit is a header control agent-device names when its back changes nothing. */ -function modalRunner(f, { label = 'Close', sameRoute = false, closes = true, confirms = false, hidesObserver = false } = {}) { +function modalRunner(f, { label = 'Close', identifier, sameRoute = false, closes = true, confirms = false, hidesObserver = false } = {}) { let path = '/', modal = false, confirming = false; const presses = [], swipes = []; - const selector = `role=button label="${label}"`; + // agent-device names a control by identifier when it has one no other button shares; its label may then be empty. + const selector = identifier ? `role=button id="${identifier}"` : `role=button label="${label}"`; + const named = identifier ? { selector, label, identifier } : { selector, label }; const runner = request => { if (request.command === 'fake-controller') { const [command] = request.args; if (command === 'open' && request.args[2]?.startsWith('sample://')) { path = '/' + request.args[2].slice('sample://'.length); modal = path === '/settings'; } if (command === 'back' && modal) return json({ success: false, error: { code: 'COMMAND_FAILED', message: 'The back swipe changed nothing.', - details: { reason: 'back_swipe_no_change', runnerErrorCode: 'BACK_SWIPE_NO_CHANGE', dispatched: 'unknown', dismissControls: [{ selector, label }] } } }); + details: { reason: 'back_swipe_no_change', runnerErrorCode: 'BACK_SWIPE_NO_CHANGE', dispatched: 'unknown', dismissControls: [named] } } }); if (command === 'press' && request.args[1] === selector) { presses.push(request.args[1]); if (confirms) confirming = true; else if (closes) { modal = false; if (!sameRoute) path = '/home'; } return ok({}); } if (command === 'swipe') swipes.push(request.args.slice(1, 5)); } @@ -3809,7 +3811,7 @@ function modalRunner(f, { label = 'Close', sameRoute = false, closes = true, con value.data.nodes.unshift({ type: 'Application', rect: { x: 0, y: 0, width: 402, height: 874 }, visible: true }); if (confirming && hidesObserver) value.data.nodes = value.data.nodes.filter(node => node.identifier !== CAPTURE_OBSERVER_IDENTIFIER); if (confirming) value.data.nodes.push({ type: 'Alert', label: 'Discard changes?', rect: { x: 50, y: 300, width: 300, height: 200 }, visible: true }); - else if (modal) value.data.nodes.push({ type: 'Button', label, rect: { x: 340, y: 60, width: 44, height: 44 }, visible: true }); + else if (modal) value.data.nodes.push({ type: 'Button', ...(label ? { label } : {}), ...(identifier ? { identifier } : {}), rect: { x: 340, y: 60, width: 44, height: 44 }, visible: true }); return { ...response, stdout: JSON.stringify(value) }; } return response; @@ -3875,6 +3877,23 @@ test('a confirmation that hides the route observer is not reported as leaving th assert.ok(back.result.error, 'back must fail while the confirmation is showing'); }); +test('an unlabeled dismiss control named by identifier counts only once that control is gone', async t => { + const closes = await fixture(t); + const closing = modalRunner(closes, { label: '', identifier: 'modal-close', sameRoute: true }); + await runCiMap({ ...closes.options, runner: closing.runner, agent: modalBackAgent(closes), setup: [{ action: 'open', url: 'sample://home' }] }); + assert.deepEqual(closing.presses, ['role=button id="modal-close"']); + const closed = (await readFile(join(closes.options.outputDirectory, 'capture-diagnostics/agent-navigation.jsonl'), 'utf8')).trim().split('\n').map(JSON.parse); + assert.equal(closed.find(event => event.action === 'back').result.via, 'dismiss-control'); + + const stays = await fixture(t); + const staying = modalRunner(stays, { label: '', identifier: 'modal-close', sameRoute: true, closes: false }); + await runCiMap({ ...stays.options, runner: staying.runner, agent: modalBackAgent(stays), setup: [{ action: 'open', url: 'sample://home' }] }); + assert.deepEqual(staying.presses, ['role=button id="modal-close"']); + assert.deepEqual(staying.swipes, []); + const stayed = (await readFile(join(stays.options.outputDirectory, 'capture-diagnostics/agent-navigation.jsonl'), 'utf8')).trim().split('\n').map(JSON.parse); + assert.equal(stayed.find(event => event.action === 'back').result.error.code, 'AGENT_DISMISS_CONTROL_FAILED'); +}); + test('agent back never presses a named dismiss control that reads as destructive', async t => { const f = await fixture(t); const modal = modalRunner(f, { label: 'Cancel subscription' }); From b36e438f73b188a96c4486a1b297c6345780eac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 19 Nov 2026 16:14:39 +0100 Subject: [PATCH 07/10] Pin agent-device 0.21.40 0.21.40 adds the keyboard fix found while testing this bump: keyboard dismiss no longer presses the return key, so on a field whose return key is Done it refuses with keyboard_dismiss_unavailable instead of submitting the form. The typed reasons Explore reads are unchanged. Co-Authored-By: Claude Opus 5.5 --- docs/quickstart-ci.md | 2 +- package-lock.json | 8 ++++---- package.json | 2 +- src/shared/agent-device-version.ts | 2 +- src/shared/controller-cache.ts | 2 +- test/node/ci-map.test.mjs | 4 ++-- test/node/public-comment.test.mjs | 6 +++--- test/node/public-review-validation.test.mjs | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/quickstart-ci.md b/docs/quickstart-ci.md index 0dc2fd7f..7ce2876e 100644 --- a/docs/quickstart-ci.md +++ b/docs/quickstart-ci.md @@ -289,7 +289,7 @@ The provider selects the runtime that owns the navigation loop: | `anthropic` | Claude Code through `@anthropic-ai/claude-agent-sdk` 0.3.285 and its platform-native package | `ANTHROPIC_API_KEY` | | `openai` | Codex app-server from `@openai/codex` 0.159.2 and its platform-native package | `OPENAI_API_KEY` | -Both runtimes use Explore's device tools to operate the existing Expo Simulators session through official `agent-device` 0.21.39. The runtime and native binaries come from the pinned tools installation. CI does not use the development-only `node_modules/.bin/claude` executable or an interactive subscription login. +Both runtimes use Explore's device tools to operate the existing Expo Simulators session through official `agent-device` 0.21.40. The runtime and native binaries come from the pinned tools installation. CI does not use the development-only `node_modules/.bin/claude` executable or an interactive subscription login. Create and commit the nonempty English prose file named by `agent.instructions`. The shared setup skill authors it from source and asks for missing test data or environment inputs. Describe how to reach the app's screens, necessary prerequisites, the representative state to use on both revisions, readiness signals, and actions to avoid. This file guides the runtime agent; it is not a list of mandatory YAML steps or a second screen inventory. diff --git a/package-lock.json b/package-lock.json index dba9f69e..7b79ae92 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,7 +29,7 @@ "@types/react-dom": "^19.2.4", "@vitejs/plugin-react": "^4.7.0", "@xyflow/react": "^12.11.3", - "agent-device": "0.21.39", + "agent-device": "0.21.40", "babel-plugin-react-compiler": "^1.0.0", "eslint": "^10.12.0", "eslint-plugin-react-hooks": "^7.1.1", @@ -4593,9 +4593,9 @@ } }, "node_modules/agent-device": { - "version": "0.21.39", - "resolved": "https://registry.npmjs.org/agent-device/-/agent-device-0.21.39.tgz", - "integrity": "sha512-flgrilleoUU9WNd9BlU8h5KMt8zv0nKWBkqJbzk/bb2NBRA+7H1FGja+RIAuapb7HXdsjK4EPnYFP37N9S8nMA==", + "version": "0.21.40", + "resolved": "https://registry.npmjs.org/agent-device/-/agent-device-0.21.40.tgz", + "integrity": "sha512-7UlxZ2L6kBAwhmPWdyHP5iM+810YenMMcVQgmsai8GJSF5QgacMflJ+2nXfEwgvRxbbw3H1BiUHzuDDMQxQePg==", "dev": true, "license": "MIT", "bin": { diff --git a/package.json b/package.json index b6e36d3b..19b59663 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "@types/react-dom": "^19.2.4", "@vitejs/plugin-react": "^4.7.0", "@xyflow/react": "^12.11.3", - "agent-device": "0.21.39", + "agent-device": "0.21.40", "babel-plugin-react-compiler": "^1.0.0", "eslint": "^10.12.0", "eslint-plugin-react-hooks": "^7.1.1", diff --git a/src/shared/agent-device-version.ts b/src/shared/agent-device-version.ts index f95536eb..0c08cad9 100644 --- a/src/shared/agent-device-version.ts +++ b/src/shared/agent-device-version.ts @@ -3,4 +3,4 @@ * controller (`--package-version`), the daemon health check, and the screenshot diff tool must * all be this version; each caller checks it by exact equality. */ -export const AGENT_DEVICE_VERSION = "0.21.39"; +export const AGENT_DEVICE_VERSION = "0.21.40"; diff --git a/src/shared/controller-cache.ts b/src/shared/controller-cache.ts index 0b0abd33..f03ddcd5 100644 --- a/src/shared/controller-cache.ts +++ b/src/shared/controller-cache.ts @@ -21,7 +21,7 @@ export type ControllerName = "agent-device" | "argent"; /** Each controller's npm release, the file Explore runs from it, and the integrity npm publishes for it. */ export const CONTROLLER_PACKAGES: Record = { "agent-device": { name: "agent-device", version: AGENT_DEVICE_VERSION, bin: "bin/agent-device.mjs", - integrity: "sha512-flgrilleoUU9WNd9BlU8h5KMt8zv0nKWBkqJbzk/bb2NBRA+7H1FGja+RIAuapb7HXdsjK4EPnYFP37N9S8nMA==" }, + integrity: "sha512-7UlxZ2L6kBAwhmPWdyHP5iM+810YenMMcVQgmsai8GJSF5QgacMflJ+2nXfEwgvRxbbw3H1BiUHzuDDMQxQePg==" }, argent: { name: "@swmansion/argent", version: ARGENT_VERSION, bin: "dist/cli.js", integrity: "sha512-XXWlWZJlHKqnAvNx3RDhuiVFQOPqh5EDB76+mFAyqC2mutC6irzw03+M/6S/WQ+Dzz2IYOkEfOzQnOOdhrGgJg==" }, }; diff --git a/test/node/ci-map.test.mjs b/test/node/ci-map.test.mjs index 90679289..3ef4993d 100644 --- a/test/node/ci-map.test.mjs +++ b/test/node/ci-map.test.mjs @@ -58,7 +58,7 @@ const recoveredSnapshot = result => { const value = JSON.parse(result.stdout); return { ...result, stdout: JSON.stringify({ ...value, data: { ...value.data, snapshotQuality: { state: 'recovered', backend: 'tree' } } }) }; }; -// agent-device 0.21.39 raises this before sending a command when the remote daemon's /health check fails. +// agent-device 0.21.40 raises this before sending a command when the remote daemon's /health check fails. const daemonUnavailable = () => json({ success: false, error: { code: 'COMMAND_FAILED', message: 'Remote daemon is unavailable', details: { reason: 'remote_daemon_unavailable', dispatched: 'no', daemonBaseUrl: 'https://daemon.example.invalid', attempts: 1 } } }); const value = (request, name) => request.args[request.args.indexOf(name) + 1]; @@ -3706,7 +3706,7 @@ function sheetRunner(f, { dismissible = true, sheetOrigin = 72 } = {}) { if (request.command === 'fake-controller') { const [command] = request.args; if (command === 'open' && request.args[2]?.startsWith('sample://')) { path = '/' + request.args[2].slice('sample://'.length); sheet = path === '/settings'; } - // agent-device 0.21.39 swipes from the left edge when there is no navigation back button; a sheet stays. + // agent-device 0.21.40 swipes from the left edge when there is no navigation back button; a sheet stays. if (command === 'back' && sheet) return json({ success: false, error: { code: 'COMMAND_FAILED', message: 'The back swipe changed nothing.', details: { reason: 'back_swipe_no_change', runnerErrorCode: 'BACK_SWIPE_NO_CHANGE', dispatched: 'unknown' } } }); if (command === 'swipe') { swipes.push(request.args.slice(1, 5)); if (dismissible) { sheet = false; path = '/home'; } return ok({}); } } diff --git a/test/node/public-comment.test.mjs b/test/node/public-comment.test.mjs index 74ca121d..7197c493 100644 --- a/test/node/public-comment.test.mjs +++ b/test/node/public-comment.test.mjs @@ -746,10 +746,10 @@ const footnote = 'Added text “Changes apply live while playing. Base resolutio const footnoteText = 'Added text “Changes apply live while playing\\. Base resolution sets the step grid for lanes you add next\\.”'; function euxyReview(target, options = {}) { const own = { sourceImpact: ['own'], sourceScope: 'screen' }; - const matched = { verdict: 'unchanged', reason: 'matched', mismatchPercentage: 0, threshold: 0.1, tool: 'agent-device@0.21.39' }; + const matched = { verdict: 'unchanged', reason: 'matched', mismatchPercentage: 0, threshold: 0.1, tool: 'agent-device@0.21.40' }; const changed = (description, mismatchPercentage) => ({ ...own, review: { status: 'modified', description, facts: [{ category: 'element', templateId: 'element.added', bullet: description }] }, - visual: { verdict: 'modified', reason: 'repeated-cross-build-delta', mismatchPercentage, threshold: 0.1, tool: 'agent-device@0.21.39' } }); + visual: { verdict: 'modified', reason: 'repeated-cross-build-delta', mismatchPercentage, threshold: 0.1, tool: 'agent-device@0.21.40' } }); const inTreeOnly = { ...changed(footnote, 0), visual: matched }; if (options.offScreen !== false) inTreeOnly.review.offScreen = true; if (options.diffFailed) inTreeOnly.visual = { ...matched, reason: 'diff-failed' }; @@ -799,7 +799,7 @@ test('a change one platform has and another lacks keeps "only" and "not on"', as const iosOnly = target => { const reviewed = euxyReview(target); if (target === 'android') for (const entry of reviewed.surfaces) Object.assign(entry, { review: { status: 'unchanged', description: 'No visible change' }, - visual: { verdict: 'unchanged', reason: 'matched', mismatchPercentage: 0, threshold: 0.1, tool: 'agent-device@0.21.39' } }); + visual: { verdict: 'unchanged', reason: 'matched', mismatchPercentage: 0, threshold: 0.1, tool: 'agent-device@0.21.40' } }); return reviewed; }; const { rows } = await euxyRows(iosOnly); diff --git a/test/node/public-review-validation.test.mjs b/test/node/public-review-validation.test.mjs index 26774434..24453366 100644 --- a/test/node/public-review-validation.test.mjs +++ b/test/node/public-review-validation.test.mjs @@ -325,7 +325,7 @@ test("a review says its change is off-screen only on a modified verdict whose sc const offScreen = (status, verdict) => { const input = review(); input.surfaces[0].review = { status, description: status === "modified" ? "Added text “lanes you add next”." : "No visible change", offScreen: true }; - input.surfaces[0].visual = { verdict, reason: verdict === "unchanged" ? "matched" : "repeated-cross-build-delta", mismatchPercentage: verdict === "unchanged" ? 0 : 3, threshold: 0.1, tool: "agent-device@0.21.39" }; + input.surfaces[0].visual = { verdict, reason: verdict === "unchanged" ? "matched" : "repeated-cross-build-delta", mismatchPercentage: verdict === "unchanged" ? 0 : 3, threshold: 0.1, tool: "agent-device@0.21.40" }; return input; }; assert.doesNotThrow(() => assertPublicReview(offScreen("modified", "unchanged"))); From 20cc5fcf95d5eea04868aa6f07277ce098e7d914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 17 Nov 2026 16:23:25 +0100 Subject: [PATCH 08/10] Binary dismiss-keyboard never presses the return key When agent-device reports keyboard_dismiss_unavailable, the fallback tapped the keyboard's return key by coordinates. That key never only closes the keyboard: next moves focus to the following field, and done or go submits the form (expo/explore#88). The step now fails with KEYBOARD_DISMISS_UNAVAILABLE and names the app's own controls as the next action. This also removes the multi-line editor guard and the return-key label pattern, which only served the coordinate tap. Co-Authored-By: Claude Opus 5.5 --- src/binary/run.ts | 12 ++---------- test/helpers/binary-controller.ts | 4 ++++ test/node/binary-local.test.mjs | 27 ++++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 test/helpers/binary-controller.ts diff --git a/src/binary/run.ts b/src/binary/run.ts index 95686455..7244e9be 100644 --- a/src/binary/run.ts +++ b/src/binary/run.ts @@ -529,14 +529,8 @@ export async function exploreConnectedSession(ctx: ConnectedSessionExploration): const dismissKeyboard = async () => { try { controller(["keyboard", "dismiss", "--level", "full", "--json"], 120_000); return; } catch (error) { if (controllerFailureReason(error) !== "keyboard_dismiss_unavailable") throw error; } - // The iOS keyboard has no dismiss key and agent-device never taps the background; its return key (next/done/go) closes it without touching the app. - const nodes = (await observe(false)).nodes; - // In a multi-line editor the return key inserts a newline instead of ending editing. - const multiline = nodes.some(node => /text-?view/i.test(String(node.type ?? ""))); - const key = multiline ? undefined : nodes.find(node => /key$/i.test(String(node.type ?? "")) && KEYBOARD_RETURN_KEY.test(String(node.label ?? ""))); - const rect = key?.rect as { x: number; y: number; width: number; height: number } | undefined; - if (!rect) throw binaryError("KEYBOARD_DISMISS_UNAVAILABLE", multiline ? "The keyboard cannot be dismissed from a multi-line editor: its return key inserts a newline." : "The keyboard cannot be dismissed: it has neither a dismiss nor a return key.", "Tap one of the app's own controls that is not behind the keyboard (Cancel, Done, Close), or go back."); - controller(["press", String(Math.round(rect.x + rect.width / 2)), String(Math.round(rect.y + rect.height / 2)), "--level", "full", "--json"], 120_000); + // The return key never only closes the keyboard: next moves focus to the following field, and done or go submits the form. + throw binaryError("KEYBOARD_DISMISS_UNAVAILABLE", "The keyboard cannot be dismissed: it has no dismiss key, and its return key would move focus or submit the form.", "Tap one of the app's own controls that is not behind the keyboard (Cancel, Done, Close), or go back."); }; try { try { await perform(); } @@ -933,8 +927,6 @@ export function guardPositionals(args: readonly string[]): string[] { return [positionals[0]!, ...flags, "--", ...positionals.slice(1)]; } -const KEYBOARD_RETURN_KEY = /^(return|next|done|go|continue|join)$/i; - /** * How a frame's screenshot is stored. An opened (or half-open) iPhone Duo lights its inner panel, whose native axes are * portrait, and shows a landscape UI on it: the tree and taps stay on the portrait axes (a 669×951 pt root, the transpose diff --git a/test/helpers/binary-controller.ts b/test/helpers/binary-controller.ts new file mode 100644 index 00000000..aef1d905 --- /dev/null +++ b/test/helpers/binary-controller.ts @@ -0,0 +1,4 @@ +// One module graph for Explore's binary run and the controller's failure parser: a typed refusal is recognised by the same +// parser instance that produced it, so a fake agent-device that fails with a reason must build its failure here. +export { runBinaryExploration } from "../../src/binary/run.js"; +export { commandOutcome } from "../../src/capture/controller.js"; diff --git a/test/node/binary-local.test.mjs b/test/node/binary-local.test.mjs index 2a935f8f..936f6d48 100644 --- a/test/node/binary-local.test.mjs +++ b/test/node/binary-local.test.mjs @@ -6,7 +6,7 @@ import { join } from "node:path"; import test from "node:test"; import { tsImport } from "tsx/esm/api"; -const { runBinaryExploration } = await tsImport("../../src/binary/run.ts", import.meta.url); +const { runBinaryExploration, commandOutcome } = await tsImport("../helpers/binary-controller.ts", import.meta.url); const { controllerVersion } = await tsImport("../../src/capture/simulator.ts", import.meta.url); const { CONTROLLER_SESSION } = await tsImport("../../src/capture/common.ts", import.meta.url); @@ -116,3 +116,28 @@ test("an opened iPhone Duo's screenshots are stored upright, and the run records assert.equal(map.run.environment.orientation, "landscape"); assert.equal(result.runtime.orientation, "landscape"); }); + +test("a keyboard with no dismiss key stays up: the return key is never pressed, whatever it reads", async t => { + const root = await mkdtemp(join(tmpdir(), "explore-binary-keyboard-")); + t.after(() => rm(root, { recursive: true, force: true })); + const field = { type: "TextField", label: "Password", rect: { x: 20, y: 100, width: 300, height: 44 } }; + const doneKey = { type: "Key", label: "done", rect: { x: 280, y: 700, width: 80, height: 44 } }; + const { requests, runner: base } = localRunner(undefined, { nodes: [field, { type: "Keyboard", rect: { x: 0, y: 600, width: 393, height: 250 } }, doneKey], png: PNG }); + const runner = request => request.args[0] === "keyboard" && request.args[1] === "dismiss" + ? (requests.push(request), commandOutcome(request, { status: 1, stderr: "", stdout: JSON.stringify({ success: false, error: { code: "UNSUPPORTED_OPERATION", + message: "Unable to dismiss the keyboard: it exposes no dismiss key.", details: { reason: "keyboard_dismiss_unavailable", dispatched: "no" } } }) })) + : base(request); + let outcome; + const session = { provider: "anthropic", model: "test", async preflight() {}, async run(request) { + await request.callTool("observe", { includeImage: false }, request.signal); + outcome = await request.callTool("act", { action: "dismiss-keyboard" }, request.signal); + return { stopReason: "done" }; + } }; + await runBinaryExploration({ archive: await simulatorApp(root), output: join(root, "out"), simulator: "local", provider: "anthropic", runner, + createSession: () => session, environment: { PATH: process.env.PATH, HOME: root, ANTHROPIC_API_KEY: "key" } }); + + const controller = requests.filter(request => request.command !== "xcrun").map(request => request.args.filter(arg => !arg.startsWith("--")).slice(0, 2).join(" ")); + assert.ok(controller.includes("keyboard dismiss"), "agent-device is asked to dismiss the keyboard"); + assert.equal(controller.some(command => /^(press \d|keyboard (return|enter))/.test(command)), false, "and nothing taps the done key or the keyboard's return"); + assert.match(outcome.content[0].text, /cannot be dismissed/); +}); From 3813b5a9f632229b16ae86dd1a21308db6f1a946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 19 Nov 2026 17:49:22 +0100 Subject: [PATCH 09/10] Show the model agent-device's hint when an action fails The model read only an error's message, so agent-device's next step never reached it: how to leave a modal back cannot close, or that a visible iOS keyboard needs its Hide Keyboard key or an app control that ends editing. A failed action now reads the message followed by that hint. dismiss-keyboard passes agent-device's refusal through as it is, instead of rewording it. Co-Authored-By: Claude Opus 5.5 --- src/binary/explorer.ts | 17 ++++++++++++++--- src/binary/run.ts | 9 +++------ test/node/binary-local.test.mjs | 8 +++++--- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/binary/explorer.ts b/src/binary/explorer.ts index 7f85b9cf..e102a84a 100644 --- a/src/binary/explorer.ts +++ b/src/binary/explorer.ts @@ -827,17 +827,17 @@ export async function runBlackBoxExploration(options: BlackBoxExplorerOptions): let error: string | undefined; try { await options.act(byCleanLabel(disambiguate(typed, matched, fromScreenId)), signal); } catch (caught) { - error = caught instanceof Error ? caught.message.slice(0, 500) : String(caught).slice(0, 500); + error = actionFailure(caught); // agent-device names the label it would have accepted (a typographic apostrophe the model typed straight). const similar = SIMILAR.exec(error)?.[1]; if (similar && action.action === "tap" && "label" in action && similar !== action.label) { try { await options.act({ action: "tap", label: similar }, signal); error = undefined; } - catch (again) { error = again instanceof Error ? again.message.slice(0, 500) : String(again).slice(0, 500); } + catch (again) { error = actionFailure(again); } } const centre = error && COVERED.test(error) ? byCentre(action, matched, named) : undefined; if (centre) { try { await options.act(centre, signal); error = undefined; } - catch (again) { error = again instanceof Error ? again.message.slice(0, 500) : String(again).slice(0, 500); } + catch (again) { error = actionFailure(again); } } } let view: Awaited> | undefined; @@ -921,3 +921,14 @@ function frameExtent(nodes: readonly Record[]): { width: number } return width > 0 && height > 0 ? { width, height } : undefined; } + +/** + * What the model reads about a failed action: the message, then the controller's own next step. agent-device's hint + * says how to proceed (press a named dismiss control, an app control that ends editing), and the model has no other way + * to learn it. + */ +function actionFailure(caught: unknown): string { + if (!(caught instanceof Error)) return String(caught).slice(0, 500); + const next = caught instanceof CiError && caught.nextAction ? ` Next: ${caught.nextAction.slice(0, 400)}` : ""; + return `${caught.message.slice(0, 500)}${next}`; +} diff --git a/src/binary/run.ts b/src/binary/run.ts index 7244e9be..d6de2168 100644 --- a/src/binary/run.ts +++ b/src/binary/run.ts @@ -526,12 +526,9 @@ export async function exploreConnectedSession(ctx: ConnectedSessionExploration): else await executeCaptureSetup([action], setupOptions); if (action.action !== "wait") await settled(); }; - const dismissKeyboard = async () => { - try { controller(["keyboard", "dismiss", "--level", "full", "--json"], 120_000); return; } - catch (error) { if (controllerFailureReason(error) !== "keyboard_dismiss_unavailable") throw error; } - // The return key never only closes the keyboard: next moves focus to the following field, and done or go submits the form. - throw binaryError("KEYBOARD_DISMISS_UNAVAILABLE", "The keyboard cannot be dismissed: it has no dismiss key, and its return key would move focus or submit the form.", "Tap one of the app's own controls that is not behind the keyboard (Cancel, Done, Close), or go back."); - }; + // A refusal reaches the model with agent-device's own hint. The return key is never a fallback: next moves focus to + // the following field, and done or go submits the form. + const dismissKeyboard = async () => { controller(["keyboard", "dismiss", "--level", "full", "--json"], 120_000); }; try { try { await perform(); } catch (error) { diff --git a/test/node/binary-local.test.mjs b/test/node/binary-local.test.mjs index 936f6d48..e107ae7c 100644 --- a/test/node/binary-local.test.mjs +++ b/test/node/binary-local.test.mjs @@ -117,7 +117,7 @@ test("an opened iPhone Duo's screenshots are stored upright, and the run records assert.equal(result.runtime.orientation, "landscape"); }); -test("a keyboard with no dismiss key stays up: the return key is never pressed, whatever it reads", async t => { +test("a refused keyboard dismiss stays refused: the return key is never pressed, whatever it reads", async t => { const root = await mkdtemp(join(tmpdir(), "explore-binary-keyboard-")); t.after(() => rm(root, { recursive: true, force: true })); const field = { type: "TextField", label: "Password", rect: { x: 20, y: 100, width: 300, height: 44 } }; @@ -125,7 +125,8 @@ test("a keyboard with no dismiss key stays up: the return key is never pressed, const { requests, runner: base } = localRunner(undefined, { nodes: [field, { type: "Keyboard", rect: { x: 0, y: 600, width: 393, height: 250 } }, doneKey], png: PNG }); const runner = request => request.args[0] === "keyboard" && request.args[1] === "dismiss" ? (requests.push(request), commandOutcome(request, { status: 1, stderr: "", stdout: JSON.stringify({ success: false, error: { code: "UNSUPPORTED_OPERATION", - message: "Unable to dismiss the keyboard: it exposes no dismiss key.", details: { reason: "keyboard_dismiss_unavailable", dispatched: "no" } } }) })) + message: "The Apple runner cannot dismiss this keyboard automatically", details: { reason: "keyboard_dismiss_unavailable", dispatched: "no", + hint: "Press the visible Hide Keyboard key or an app control that ends editing." } } }) })) : base(request); let outcome; const session = { provider: "anthropic", model: "test", async preflight() {}, async run(request) { @@ -139,5 +140,6 @@ test("a keyboard with no dismiss key stays up: the return key is never pressed, const controller = requests.filter(request => request.command !== "xcrun").map(request => request.args.filter(arg => !arg.startsWith("--")).slice(0, 2).join(" ")); assert.ok(controller.includes("keyboard dismiss"), "agent-device is asked to dismiss the keyboard"); assert.equal(controller.some(command => /^(press \d|keyboard (return|enter))/.test(command)), false, "and nothing taps the done key or the keyboard's return"); - assert.match(outcome.content[0].text, /cannot be dismissed/); + assert.match(outcome.content[0].text, /cannot dismiss this keyboard/); + assert.match(outcome.content[0].text, /Hide Keyboard key or an app control/, "the model gets agent-device's hint"); }); From 68d2d18206594a3c92d9738a353b089c6647a426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 19 Nov 2026 17:58:49 +0100 Subject: [PATCH 10/10] The bridge's keyboard refusal carries agent-device's hint The other controller's bridge refused keyboard dismiss without a hint, so the model got generic advice there. Its refusals now give the same next step as agent-device's. Co-Authored-By: Claude Opus 5.5 --- src/capture/argent-driver.ts | 10 ++++++---- test/node/argent-driver.test.mjs | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/capture/argent-driver.ts b/src/capture/argent-driver.ts index e3096e59..8eb8ff68 100644 --- a/src/capture/argent-driver.ts +++ b/src/capture/argent-driver.ts @@ -247,6 +247,8 @@ export function iosRuntimeVersion(runtime: unknown): string | undefined { const DEEP_LINK_PROMPT_CONFIRM = { dxPoints: 74, dyPoints: 37 }; const KEYBOARD_DISMISS_LABELS = ["Hide keyboard", "Dismiss keyboard", "Done"]; +/** What the model reads when the keyboard cannot be dismissed: the same next step agent-device's refusal gives. */ +const KEYBOARD_DISMISS_HINT = "Press the visible Hide Keyboard key or an app control that ends editing."; // A keyboard covers the lower part of the screen; its keys start below this share of the height. const KEYBOARD_TOP = 0.4; const ALERT_PREFERRED_BUTTONS = ["Open", "OK", "Allow", "Allow While Using App", "Continue"]; @@ -613,17 +615,17 @@ export async function runBridgeCommand(argv: readonly string[], context: ArgentB await beforeAction(); if (platform === "android") await call("button", { button: "back" }); else { - // agent-device taps the keyboard's own dismiss control, and refuses with this reason when there is none, which - // callers answer with the return key. Only a key in the keyboard's area counts: an app's "Done" above it is not one. + // Refuses with agent-device's reason when the keyboard has no dismiss key, and with a hint like agent-device's, which + // the model reads. Only a key in the keyboard's area counts: an app's "Done" above it is not one. const key = flatten(current).find(node => KEYBOARD_DISMISS_LABELS.includes(node.label ?? "") && node.frame && node.frame.y >= KEYBOARD_TOP); - if (!key) return failure("UNSUPPORTED_OPERATION", "Unable to dismiss the keyboard: it exposes no dismiss key.", { reason: "keyboard_dismiss_unavailable", dispatched: "no" }); + if (!key) return failure("UNSUPPORTED_OPERATION", "Unable to dismiss the keyboard: it exposes no dismiss key.", { reason: "keyboard_dismiss_unavailable", dispatched: "no", hint: KEYBOARD_DISMISS_HINT }); const size = current.screen ?? await screen(); await tap(...Object.values(centre({ x: key.frame!.x * size.width, y: key.frame!.y * size.height, width: key.frame!.width * size.width, height: key.frame!.height * size.height }, size)) as [number, number]); } await context.sleep(500); const visible = (await tree()).keyboardVisible === true; - if (visible && platform === "ios") return failure("COMMAND_FAILED", "Unable to dismiss the keyboard: it is still showing after its dismiss key was pressed.", { reason: "keyboard_dismiss_unavailable" }); + if (visible && platform === "ios") return failure("COMMAND_FAILED", "Unable to dismiss the keyboard: it is still showing after its dismiss key was pressed.", { reason: "keyboard_dismiss_unavailable", hint: KEYBOARD_DISMISS_HINT }); return success({ platform, action: "dismiss", wasVisible: true, dismissed: !visible, visible }); } case "scroll": { diff --git a/test/node/argent-driver.test.mjs b/test/node/argent-driver.test.mjs index f0a45f75..7d951f2b 100644 --- a/test/node/argent-driver.test.mjs +++ b/test/node/argent-driver.test.mjs @@ -222,11 +222,12 @@ test("keyboard dismiss matches agent-device: Android presses back; iOS taps a di assert.deepEqual(dismissed.json.data, { platform: "android", action: "dismiss", wasVisible: true, dismissed: true, visible: false }); assert.deepEqual(android.calls.find(call => call.tool === "button").args, { udid: "emulator-5554", button: "back" }); - // agent-device refuses with this reason when the keyboard has no dismiss key, and callers fall back to the return key. + // agent-device refuses with this reason when the keyboard has no dismiss key; its hint tells the model what to press. const noKey = harness("ios", { "list-devices": IOS_DEVICES, "ui-tree": { ...IOS_HOME, keyboardVisible: true } }); const failed = await noKey.run(["keyboard", "dismiss", ...flags("ios")]); assert.equal(failed.exitCode, 1); assert.equal(failed.json.error.details.reason, "keyboard_dismiss_unavailable"); + assert.match(failed.json.error.details.hint, /Hide Keyboard key or an app control/); const hidden = harness("ios", { "list-devices": IOS_DEVICES, "ui-tree": IOS_HOME }); assert.equal((await hidden.run(["keyboard", "dismiss", ...flags("ios")])).json.data.wasVisible, false);