fix(mcp): say headed for an engine that shows its app itself
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
Engine.alwaysHeadedis 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 namedheaded, becauseEngineInitInfo.headed,EnginePrepareInfo.headedandEngineDoctorInfo.headedmean "the run asked".defineEnginechecks and copies it like the other boolean flags (packages/core/src/engine/manifest.ts:319).- 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),describeEngineand the manifest comparison (packages/core/src/engine/protocol/manifest.ts:35), the client handle,engine-manifest-v1.schema.json, and both fixtures. desktop()declares it when itsheadedoption is on (packages/desktop/src/engine.ts:55). Its peer floor on@e2e-dev/coreande2egoes to>=0.25.1: an older core refuses the unknown key at config load.- One helper holds the rule:
showsSurface(engine, requested)isrequested || 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, soEngineInitInfo.headedkeeps its meaning. - Docs: the field in
docs/reference/engine.mdx(underinit, besideinfo.headed; it is not a capability) anddocs/reference/engine-protocol.mdx, and one clause onopen_session'sheadedindocs/reference/mcp.mdxand 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. alwaysHeadedis not the general answer to "is this session visible".@e2e-dev/mobilenever reads the run'sheaded, and a hosted browser cannot honor it, soopen_session {headed: true}on those still saysheaded. That needs a separate decision.- The word
headlessfor 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.tsopens a session over the built CLI's stdio on an engine that declaresalwaysHeaded: true, with nothing asking for headed, and reads), headed;.mcp-session-host.test.tsasserts the engine'sinitstill gotheaded: falseand the usage summary saystrue.mcp-step-attachment.test.tsholds a test on such an engine in a run without--headed, attaches, and readsheaded: truein the opening; with the helper call reverted it readsfalse. On maindefineEnginerefuses thealwaysHeadedkey, so all three fail there. - Default case, live: desktop testbed (
apps/desktop-testbed, native driver built from this branch), a reale2e mcpstdio 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.
| main | this PR | |
|---|---|---|
| engine with its own headed option, nothing asked | headless | headed |
desktop(), nothing asked | headless | headless |
any engine, open_session {headed: true} or --headed | headed | headed |
No terminal recording or video: the change is one word in an MCP reply.