feat(ios): appstate reads the session app's XCUIApplication state through the runner

Merged
OK
2mo ago
+554-29

Summary

iOS appstate answered from the session record alone, so after home it still named the app as if in front. The session app's own state is a fact a live runner has.

A new appState runner command reads XCUIApplication(bundleIdentifier:).state and names it (runningForeground, runningBackground, runningBackgroundSuspended, notRunning, unknown), declared once in the kernel as APPLE_APPLICATION_STATES. A lifecycle read like status, it skips the activation preflight.

The Apple runtime binds the read (bindAppleAppStateRuntime) and never starts a runner for it: with no live runner session it answers nothing and the handler keeps source: session with no state, so appState stays on the simulator host in the runner-demand table. With a live runner the handler adds state and source: runner. A cancelled request stays cancelled. The MCP output schema carries both source values and the state enum. The CLI's Apple lines read Session app:. Which app took the screen is still not read.

Validation

Tested at the pushed head, rebased onto 6428c5485. pnpm check:xctest-selection, pnpm check:packaged-runner-swift, and pnpm check:affected --run --base 6428c5485 passed (916 test files, 7,280 tests). The appState request is pinned in runner-requests.json; its XCTests pass on the booted simulator.

Live on an iPhone 17 Pro simulator, runner warm from open:

appstate            State: runningForeground            Source: runner
home; appstate      State: runningBackgroundSuspended   Source: runner
snapshot; appstate  State: runningForeground            (the capture re-activated it)

Handler tests cover the runner answer, no live runner, and a runner that throws; a binder test proves no interactor is resolved without a live session.

Risk: source on the iOS result gains the value runner.