fix(mcp): say headed for an engine that shows its app itself

OK
40m ago
+129-13

What

open_session in e2e mcp says headed for a target whose engine shows its app through an option of its own, such as desktop({ headed: true }). It said headless.

An engine declares it with a new optional contract field:

defineEngine({ name: 'kiosk', version: '1.0.0', spiVersion: 1, alwaysHeaded: true, /* ... */ });

Why

A desktop target with desktop({ headed: true }) opened over e2e mcp as Session ... (platform macos, engine desktop ...), headless; while the engine brought the app forward and used the real pointer and keyboard. The line printed only the run's flag (open_session {headed} or --headed), and the engine had no way to say its option overrides it.

How it works

  1. Engine.alwaysHeaded is a new optional boolean: an option of the engine shows its surface on every run, whatever the run asks (packages/core/src/engine/index.ts:868). It is not named headed, because EngineInitInfo.headed, EnginePrepareInfo.headed and EngineDoctorInfo.headed mean "the run asked". defineEngine checks and copies it like the other boolean flags (packages/core/src/engine/manifest.ts:319).
  2. The flag crosses the engine protocol with the manifest, so a served engine can declare it too: EngineManifest.alwaysHeaded (packages/core/src/engine/protocol/protocol.ts:129), describeEngine and the manifest comparison (packages/core/src/engine/protocol/manifest.ts:35), the client handle, engine-manifest-v1.schema.json, and both fixtures.
  3. desktop() declares it when its headed option is on (packages/desktop/src/engine.ts:55). Its peer floor on @e2e-dev/core and e2e goes to >=0.25.1: an older core refuses the unknown key at config load.
  4. One helper holds the rule: showsSurface(engine, requested) is requested || engine.alwaysHeaded (packages/core/src/engine/manifest.ts:17). A standalone session uses it for the opening line and the usage report once the target is resolved (packages/e2e/src/mcp/session.ts:453), and a session attached to a held test uses it for the usage report (packages/e2e/src/run/worker/held-test-tools.ts:201). The engine is still handed what was asked, so EngineInitInfo.headed keeps its meaning.
  5. Docs: the field in docs/reference/engine.mdx (under init, beside info.headed; it is not a capability) and docs/reference/engine-protocol.mdx, and one clause on open_session's headed in docs/reference/mcp.mdx and the tool's own description.

Dropped alternative: returning the state from init. It would change a required method's return type and the lifecycle/init wire reply for one line of text; the desktop option is known when the engine is created.

Not changed:

  • A session attached to a held test (open_session {attach}) prints no headed word. Its usage report follows the same rule as a standalone session.
  • alwaysHeaded is not the general answer to "is this session visible". @e2e-dev/mobile never reads the run's headed, and a hosted browser cannot honor it, so open_session {headed: true} on those still says headed. That needs a separate decision.
  • The word headless for a native app in the background is unchanged.

Verified

Ran it locally: yes

  • Headed case, scripted engine (a live desktop({ headed: true }) run takes the shared screen, pointer and keyboard on this machine, so it was not run): packages/e2e/tests/integration/mcp-server.test.ts opens a session over the built CLI's stdio on an engine that declares alwaysHeaded: true, with nothing asking for headed, and reads ), headed;. mcp-session-host.test.ts asserts the engine's init still got headed: false and the usage summary says true. mcp-step-attachment.test.ts holds a test on such an engine in a run without --headed, attaches, and reads headed: true in the opening; with the helper call reverted it reads false. On main defineEngine refuses the alwaysHeaded key, so all three fail there.
  • Default case, live: desktop testbed (apps/desktop-testbed, native driver built from this branch), a real e2e mcp stdio session in background mode:
initialized: {"name":"e2e","title":"e2e","version":"0.25.0"}
--- open_session {} (449 ms)
Session 01a21d33-... open on target "macos" (platform macos, engine desktop 0.0.1), headless; config .../apps/desktop-testbed/e2e.config.ts, read with the e2e mcp server's environment, not your shell's.
--- close_session {} (107 ms)
Session 01a21d33-... closed (closed by the agent); 0 tool calls ran.
mainthis PR
engine with its own headed option, nothing askedheadlessheaded
desktop(), nothing askedheadlessheadless
any engine, open_session {headed: true} or --headedheadedheaded

No terminal recording or video: the change is one word in an MCP reply.