Repository navigation
Description
Part of #1105.
Scope
A user or agent at a shell runs simlock rotate <orientation> [--lease <id>], and an MCP client calls rotate_device, to turn its leased iOS simulator, on a worker or through a gateway. Both call device.rotate from #1107 and spell orientations through the contract's alias parser. The CLI reference, the root usage, simlock instructions and the MCP tool lists describe them.
In short
After this PR, simlock rotate landscape-left turns the holder's only leased iOS simulator and prints Rotated lease <leaseId> to <orientation>, <leaseId> the id in device.rotate's answer (the caller's own, through a gateway too) and <orientation> the canonical name (landscape_left). --lease <id> (before or after the orientation) names one lease when the holder has several. MCP's rotate_device {orientation} does the same for the session's held lease and returns {leaseId, orientation}. A spelling the alias parser does not know is a usage error (CLI) or a BAD_REQUEST tool error (MCP) with Unknown orientation <input>; use portrait, portrait-upside-down, landscape-left or landscape-right.
flowchart LR
U[simlock rotate - new] --> L{lease}
L -->|--lease| O[device.rotate]
L -->|only lease| O
M[MCP rotate_device - new] --> O
Every CLI failure is one JSON line on stderr, as for every command:
$ simlock rotate landscape-left # before
{"error":{"code":"USAGE","message":"Unknown command: rotate<help hint>"}} # src/cli/index.ts:237
$ simlock rotate landscape-left # after
Rotated lease 3f9c to landscape_left
$ simlock rotate sideways # exit 2
{"error":{"code":"USAGE","message":"Unknown orientation sideways; use portrait, portrait-upside-down, landscape-left or landscape-right"}}
$ simlock rotate left # two leases, exit 2
{"error":{"code":"USAGE","message":"agent-7 holds more than one lease (3f9c, 7a2e); pass --lease <id> to name the device you mean"}}
$ simlock rotate left --lease 7a2e # an Android emulator, exit 12
{"error":{"code":"ROTATION_UNSUPPORTED","message":"Lease 7a2e is on an Android emulator; only an iOS simulator can be rotated"}}
Input to simlock rotate |
Today | After |
|---|---|---|
landscape-left, LEFT, left |
unknown command | landscape_left |
upside-down |
unknown command | portrait_upside_down |
auto, landscapeLeft, none |
unknown command | usage error, exit 2 |
If this goes wrong, a user rotates a different lease than the one they meant, or sees a rotation reported that never happened.
Technical spec
Facts
Commit 795733b.
| # | Fact | Source |
|---|---|---|
| F1 | Top-level commands are registered in the CLI tree; simctl and adb load passthrough.js |
src/cli/tree.ts:131-132 |
| F2 | extractLeaseFlag reads --lease <id> / --lease=<id> only before the first other word |
src/cli/commands/passthrough.ts:86-101 |
| F3 | Without --lease, resolveRemoteLeaseId lists leases (filtered to the requester for an admin session) and errors on none or several, with the messages shown above |
src/cli/commands/passthrough.ts:106-127 |
| F4 | commandArgs parses flags anywhere and returns positionals |
src/cli/args.ts:12-18 |
| F5 | Every CLI failure is one JSON line on stderr; a usage error exits 2, a coded error its cliExitCode |
src/cli/AGENTS.md:50-54 |
| F6 | The root usage lists the commands | src/cli/index.ts:17-41 |
| F7 | The CLI may import from core only loadConfig; MCP never imports core |
src/cli/AGENTS.md:6, src/mcp/AGENTS.md:5 |
| F8 | MCP's run_on_device acts on #heldLeaseId and throws McpSessionError("NO_LEASE", "This MCP session holds no lease. Call lease_simulator first.") with none |
src/mcp/session.ts:288-299, src/mcp/session.ts:94-100 |
| F9 | MCP tools are registered with server.registerTool(name, {title, description, inputSchema, outputSchema}, handler); the SDK checks the input schema before the handler |
src/mcp/server.ts:291-297 |
| F10 | Existing tools take their input schema from the contract op (run_on_device = device.exec minus leaseId, requesterId) |
src/mcp/contracts.ts:87-90 |
| F11 | server.test.ts pins each tool's input schema keys |
src/mcp/server.test.ts:81-85 |
| F12 | simlock instructions says MCP "has five tools" |
src/instructions/index.ts:62 |
| F13 | #heldLeaseId appears on 10 lines of the session, written at 206, 347, 464, 505 and 591 |
src/mcp/session.ts:119, src/mcp/session.ts:206 |
| F14 | The CLI reference has one ## simlock <command> section per command and lists MCP's tools under simlock mcp |
website/src/content/docs/docs/reference/cli.mdx:158-210 |
Modules touched
Searches: registerTool(, extractLeaseFlag, resolveRemoteLeaseId, five tools, passthrough.js in src/.
src/cli/—commands/rotate.ts(new),tree.ts,index.tsusage;resolveRemoteLeaseIdmoved to a shared CLI file both commands import.src/mcp/—rotate_deviceinserver.ts,session.ts,contracts.ts(its own schemas).src/instructions/— the MCP tool count and list.website/— CLI reference (simlock rotate, thesimlock mcplist), connect-your-agent.
flowchart LR
cli[cli rotate*] --> client[simlock-client rotate]
mcp[mcp rotate_device*] --> client
cli --> orient[contract orientation.ts]
mcp --> orient
client --> daemon[daemon or gateway: device.rotate]
Contract and event changes
none: uses device.rotate and src/contract/orientation.ts from #1107 as they are (searched src/contract for this task's names: no change).
MCP rotate_device (not a contract shape): input {orientation: string, 1 to 64 characters}; output {leaseId: string, orientation: one of the four names}. The handler parses orientation with the contract's alias parser; an unknown one throws McpSessionError("BAD_REQUEST", <unknown message>) before any call.
Other code on the same state
Searches: #heldLeaseId (10 lines in src/mcp/session.ts, 5 writes), listLeases( in src/cli (3).
- MCP session's held lease:
rotate_devicereads it likerun_on_deviceand never writes it; a release during a rotate makes the rotate answerUNKNOWN_LEASE. simlock simctl/adb: shareresolveRemoteLeaseId; behaviour unchanged (their tests insrc/cli/passthrough.test.tsstay as they are).
Failure modes
| Call | Outcome | What happens | Limit, counted from |
|---|---|---|---|
listLeases |
none / several | usage error, exit 2 (F3) | — |
device.rotate |
ROTATION_UNSUPPORTED |
CLI JSON error, exit 12; MCP tool error with it | — |
device.rotate |
INPUT_UNAVAILABLE |
CLI JSON error, exit 1; MCP tool error | the helper's 10 s, from the call |
| daemon | not reachable | the CLI's usual connection error | as today |
No state is written.
Rules in play
- ADR 0047 §6: "a command can run for minutes, and
lease_statusor a release must not wait behind it" —rotate_deviceis not on#mutate, likerun_on_device. - MCP manual: "Never imports: core" — the parser comes from the contract.
- Documentation rule 9: the CLI reference,
simlock instructionsand the MCP lists change in this PR.
Tests
Seam: the CLI command over a fake client, modelled on src/cli/passthrough.test.ts; MCP on src/mcp/server.test.ts (run_on_device at :847).
- A user runs
simlock rotate <orientation> [--lease <id>]and seesRotated lease <id> to <orientation>, or a usage error; cases: alias accepted; unknown name → exit 2; no lease → error; two leases without--lease→ error naming them;--leasegiven before and after the orientation;ROTATION_UNSUPPORTED→ exit 12; through a gateway. - An MCP client calls
rotate_device {orientation}and the held lease rotates; cases: ok; no held lease →NO_LEASE; alias accepted; unknown name →BAD_REQUESTtool error with the unknown message;ROTATION_UNSUPPORTED→ tool error.
Done when
- The Tests lines pass, with
server.test.ts's schema-key table (F11) holdingrotate_device. simlock rotate --help, the root usage and the CLI reference agree;simlock instructionsand connect-your-agent listrotate_device.
Out of scope
- The agent-device front (The agent-device front answers orientation on an iOS-simulator lease #1109).
- A
--waitthat confirms the screen turned.
Depends on
Written by an agent.
Activity
test: --lease names the lease to rotate before or after the orientati…
feat(cli): simlock rotate --lease names the lease (callstackincubator…
test: simlock rotate takes aliases, refuses unknown names and ambiguo…
test: an MCP client calls rotate_device {orientation} and the held le…
feat(mcp): rotate_device turns the session's held lease (callstackinc…
test: rotate_device answers NO_LEASE, BAD_REQUEST and the daemon's re…
test: simlock instructions lists simlock rotate and rotate_device (ca…
feat(instructions): simlock instructions lists simlock rotate and rot…
test: simlock rotate --help and the root usage name the command (call…
feat(cli): simlock rotate --help, the root usage, the CLI reference a…
fix: the website's MCP summaries say six tools; rotate_device's alias…
test: pin rotate's agent role, client close and the rotate_device inp…
test: drop a leftover debug assertion from the MCP smoke table (calls…
docs(cli): list simlock rotate in the CLI reference's command table (c…
test(cli): prove simlock rotate through a gateway with --gateway (cal…
feat(cli): simlock rotate and MCP rotate_device (callstackincubator#1123