An engine server answers the engine protocol
outside the runner’s process: in a child process, on another machine, or on
a device, written in any language. connectEngine turns a server into an
engine handle, and the runner drives it like any other engine.
Connect to a server
Set a connectEngine handle as the target’s engine. The manifest says what
the server answers; the runner needs it at config load, before any server
starts.
- The server’s manifest from
initializemust match the declared one. When it differs, the first connection fails withENGINE_FAILUREand names each field. - With
resolveLocators, the client resolves locators over each observation, so a server only has to produce a tree. spawnTransportstarts a server per connection.socketTransportreaches one that already listens on a port.
A server receives what an engine in the runner’s process would: the run’s
environment, model keys and E2E_SECRET_* values included, and secrets in
plaintext. Connect only to a server you trust, over a channel you trust.
socketTransport doesn’t encrypt.
Keep host work on the client
Some members hold functions, or need the machine the runner is on. Pass
them to connectEngine; they run in the runner’s process:
Serve a TypeScript engine
serveEngine answers the protocol with a defineEngine engine, over stdin
and stdout by default. Run it as the command of a spawnTransport, and
declare its manifest with describeEngine.
Keep the server’s own logging on stderr: stdout carries the protocol.
Write a server in another language
A server reads and writes JSON-RPC 2.0 messages, each after a
Content-Length header, as a language server does. It answers:
initialize, with{ protocolVersion: 1, manifest }. Refuse any other protocol version.- Each method its manifest lists, such as
engine/observe. Its params are the member’s arguments by name. shutdown, then theexitnotification, after which the server stops.
Ignore notifications you don’t know. Report a failure as error -32000
with the e2e error in data, so the runner classifies it as a local
engine’s. The messages reference
lists every params and result shape. The manifest’s JSON Schema ships as
schema/engine-manifest-v1.schema.json in the e2e package.
Write a transport
Write a transport when a server needs setup first, such as an app installed
on a device and a port forwarded to it. open receives the target’s app,
because a server elsewhere can’t read the project’s files.