# moonrockz/moon-lander-plugins/worker

The serve loop of a worker program. A worker program serves one plugin of any kind to its
host on standard input and output, and the host starts it with
[`WorkerPlugin`](../process/README.mbt.md). This package builds for native only.

```moonbit notest
    Some("moonbit") => @plugins_worker.serve(@conformance.heartbeat())
    Some("wasm") =>
      @plugins_worker.serve(
        @plugins_wasm.WasmPlugin::new(@wasm_guests.heartbeat_module()),
      )
    Some("native") => @plugins_worker.serve(@native_fixtures.heartbeat())
```

This is the worker program of the worker scenarios: its first argument selects a MoonBit,
a wasm or a linked native heartbeat plugin.

`serve` first makes the process ignore SIGINT and SIGTERM, and on Windows the console
events Ctrl-C and Ctrl-Break, so the host decides when the worker ends. It then serves calls
until the host closes standard input, and returns. The plugin gets the largest call limit,
because the host enforces its own limit.

- Do not write to standard output in a worker: it holds only the frames. Write diagnostics
  to standard error, which the host logs.
- `frame_limit` must be the same as the limit that the host gives to `WorkerPlugin::new`.

The frames are in [the design of the change](https://github.com/moonrockz/moon-lander/blob/main/openspec/changes/archive/2026-12-05-add-service-plugins/design.html)
(WRK-2), and their constants are also in `abi.zig`, so a worker in another language can use
them.
