feat(mobile): give agents a fold tool for foldable devices (ENG-1494)

Merged
KA
1d ago
+117-8

What

foldTools(...engines) from @e2e-dev/mobile/tools gives an agent a fold tool. It puts a foldable device (the iPhone Duo simulator or a foldable Android emulator) in the closed, half-open, or open pose:

import { foldTools, mobileTools } from '@e2e-dev/mobile/tools';

const iphoneDuo = mobile({ platform: 'ios', device: 'iPhone Duo' });

agents: { default: { model, tools: { ...mobileTools(iphoneDuo), ...foldTools(iphoneDuo) } } },

With it in the agent's tools, agent.act, e2e explore, and the MCP server's call {tool: "fold"} can fold and unfold the device.

Why

A test can fold an iPhone Duo with device.fold(pose), but no agent tool wraps it. On an app built for a foldable, e2e explore and agent.act could not reach the inner display at all. The MCP server's catalog had no fold either: on 0.24.0, run_code refuses device (main's run_code from #1998 reaches it, unreleased).

How it works

  1. foldTools (packages/mobile/src/tools.ts:217) is a pack of its own, built like tvTools: the same pack() helper, mutates: true, scoped to the platforms of the engines it gets. It is not in mobileTools, so a config with no foldable never offers the model a hinge it would fail on. Like tv_remote, it is offered by platform, not by device: a config with an iPhone 16 and an iPhone Duo puts the pack on a named agent the foldable tests select, which the docs say.
  2. The fold tool calls AgentDeviceSurface.fold (packages/mobile/src/surface.ts:1903), the call device.fold makes. It carries the worker's device selection and maps a device without a hinge to UNSUPPORTED_CAPABILITY. The answer names the display the app is on now.
  3. Nothing in e2e changes. Explore runs with the agent entry's tools (packages/e2e/src/explore/executor.ts:69), and the MCP catalog serves the agent's project tools under their own names (packages/e2e/src/session-tools/catalog.ts:122), so both get fold from the config.
  4. Docs: the foldables accordion in docs/mobile.mdx, the agent tools section and the export list in docs/reference/mobile.mdx, the project tools line in docs/reference/mcp.mdx, and skills/e2e/references/mcp.md (synced to the plugin). Both mobile pages say a pose the agent leaves carries over to the next test, so the afterEach fold-back still applies.

Engines cannot add agent tools on their own (the engine manifest refuses a tools key), so the user opts in through the config, the way tvTools works.

Issue

ENG-1494

Verified

Ran it locally: yes

A copy of a teleprompter app's e2e project for the iPhone Duo, with @e2e-dev/core, e2e, and @e2e-dev/mobile linked to this branch's builds and tools: { ...mobileTools(iphoneDuo), ...foldTools(iphoneDuo) }, on an iPhone Duo simulator.

MCP server, driven by a stdio client: tools {tool: "fold"}, then call {tool: "fold"} in each pose. Screenshots show the outer display when closed and the inner split view when open. The video is the same session recorded with start_recording.

=== tools {"tool":"fold"}
fold
Fold or unfold a foldable device. closed puts the app on the outer (cover) display, open lays the inner display flat, and half-open bends it like a book. ...
=== call {"tool":"fold","args":{"pose":"open"}} (1713 ms)
Unfolded the device flat; the app is on the inner display.
=== call {"tool":"fold","args":{"pose":"half-open"}} (3430 ms)
Folded the device half-open; the app is on the inner display.
=== call {"tool":"fold","args":{"pose":"closed"}} (4441 ms)
Folded the device closed; the app is on the outer display.
closedopen
closedopen

e2e explore --max-steps 4 --ai-trace "Check that the reading position survives folding: ... unfold the device flat, fold it half-open, and fold it closed again ..." with openai/gpt-6-luna-fast:

   ✓ 1  Set reading position 9.39s · 3 actions
   ✓ 2  Reading position across folds 25.34s · 3 actions
   ✓ 3  Reopen prompter position 7.22s · 2 actions
   ✓ 4  Near-end folding position 35.53s · 7 actions
 Assessment
   The goal passed: the Script reading position remained unchanged after
   skipping forward and checking the prompter flat, half-open, and closed.

npx unbox-ai tools .e2e/ai-trace.json: the explorer called fold 6 times, none failed.

tool           calls  failed
tap            9      -
fold           6      -
screenshot     6      -
complete_step  4      -

Without foldTools on 0.24.0, the same MCP session has no fold in its catalog, and run_code with await device.fold("open") fails with INVALID_ARGUMENT: run_code: "device" at 1:7 is a fixture of this target's engine, which run_code does not run.

Not checked on a foldable Android emulator: the tool makes the call device.fold makes, which engine.test.ts covers on both platforms.

https://github.com/user-attachments/assets/45b40f62-b354-41ca-8655-d3dade84da27