<!-- https://tinyactors.dev/cli/commands/run/ -->
# tinyactors run

Kind: reference. For: [Workflow developer who tests](https://tinyactors.dev/audiences/workflow-tester.xml), [Agent-platform engineer](https://tinyactors.dev/audiences/agent-platform.xml).
Voice: [Reference](https://tinyactors.dev/voices/reference.xml).

> Serve one host over JSON-RPC 2.0 on standard input and output.

Serve one host over JSON-RPC 2.0 on standard input and output.

<a id="usage"></a>

## Usage

```shell
tinyactors run [options] [INPUT...]
```

Experimental: the protocol may change in any release until a second client uses it. Makes one host with quickjs and adds the inputs' image: charts, a system manifest or an image. Without inputs, the client adds images. Reads JSON-RPC 2.0 messages, one per line, from standard input and answers on standard output. run.* methods are the host's calls (run.spawn, run.send, run.advanceTime, run.turn, run.addImage, ...). Every other method is core's control plane (actor.state, host.stats, ...). What actors do comes back as effect.* notifications. Each is written before the response to the request that caused it. The clock is simulated: it moves only with run.advanceTime. The end of input ends the server. run `--schema` writes the protocol's JSON Schema (`docs/cli.md`, Run).

<a id="options"></a>

## Options

- **`-W, --warnings-as-errors`**: Refuse a chart that compiles with a warning.
- **`-I, --include DIR`**: Search `DIR` for a src that is not beside the file naming it, in the order given. Repeatable.
- **`--config FILE`**: Read the host config from `FILE` as JSON (`docs/host-config.md`), its ioProcessors a map of type to {location}. Default: every key core's.
- **`--system ID`**: Set the config's systemID to ID. Default: tinyactors-run.
- **`--io-processor TYPE[=LOCATION]`**: Add an I/O processor of `TYPE`, at `LOCATION` when given, that the client serves after the config's. Repeatable.
- **`--boot`**: Spawn the boot actors of the inputs' system manifest before the first message.
- **`--wall-start NS`**: Start the wall clock at `NS` nanoseconds since the Unix epoch. Default: 0.
- **`--seed N`**: Seed Math.random with N; 0 takes the engine's own seed, new on every run. Default: 1.
- **`--max-ops N`**: Allow quickjs N interrupt checks per evaluation. Default: quickjs's.
- **`--memory-limit BYTES`**: Limit quickjs's heap to `BYTES`. Default: quickjs's.
- **`--realm REALM`**: Set how the charts share quickjs realms to `REALM`. Values: auto (shared unless globals are declared) or isolated (one per session). Default: auto.
- **`--max-message BYTES`**: Take input lines of at most `BYTES`. Default: 64 MiB.
- **`--schema`**: Write the protocol's JSON Schema and exit.

Configure output formats like `-f json` using the [shared options on the command reference](https://tinyactors.dev/cli/commands/index.md#program-options).

<a id="examples"></a>

## Examples

```shell
tinyactors run order.scxml
```

Serve a host running one chart.

```shell
tinyactors run --config shop.json order.scxml payment.scxml
```

Serve two charts with a host config.

```shell
tinyactors run --io-processor payments --system shop order.scxml < requests.jsonl
```

```text title="output"
{"jsonrpc":"2.0","id":1,"result":{"session":1,"address":"tinyactors://shop/#_scxml_1"}}
{"jsonrpc":"2.0","id":2,"result":{}}
{"jsonrpc":"2.0","id":3,"result":{}}
{"jsonrpc":"2.0","method":"effect.send","params":{"batch":1,"index":0,"session":1,"type":"payments","target":"charges","event":"charge","sendid":"pay","data":{"amount":1200},"traceparent":"00-bba5ad4a1f842e59ffef8375d9ebcaca-94e8a8f3181c87c4-03","waiting":true}}
{"jsonrpc":"2.0","id":4,"result":{"status":"held","runs":1,"fuel":19,"time":0,"nextDeadline":null}}
{"jsonrpc":"2.0","id":5,"result":{}}
{"jsonrpc":"2.0","id":6,"result":{"status":"idle","runs":1,"fuel":14,"time":0,"nextDeadline":null}}
{"jsonrpc":"2.0","id":7,"result":{"value":"paid","history":{}}}
{"jsonrpc":"2.0","id":8,"result":{}}
{"jsonrpc":"2.0","method":"effect.done","params":{"batch":3,"index":0,"session":1,"name":"order-1","final":"shipped","data":{"charge":"ch_81"}}}
{"jsonrpc":"2.0","id":9,"result":{"status":"idle","runs":1,"fuel":6,"time":0,"nextDeadline":null}}
{"jsonrpc":"2.0","id":10,"result":{"session":2,"address":"tinyactors://shop/#_scxml_2"}}
{"jsonrpc":"2.0","id":11,"result":{}}
{"jsonrpc":"2.0","id":12,"result":{}}
{"jsonrpc":"2.0","method":"effect.send","params":{"batch":4,"index":0,"session":2,"type":"payments","target":"charges","event":"charge","sendid":"pay","data":{"amount":450},"traceparent":"00-7efdaa95605dfc9c4bde97c0a78eaab8-63c3721caf3ede87-03","waiting":true}}
{"jsonrpc":"2.0","id":13,"result":{"status":"idle","runs":2,"fuel":22,"time":0,"nextDeadline":30000000000}}
{"jsonrpc":"2.0","id":14,"result":{"time":30000000000,"wallNs":30000000000}}
{"jsonrpc":"2.0","method":"effect.send","params":{"batch":5,"index":0,"session":2,"type":"payments","target":"charges","event":"charge","sendid":"pay","data":{"amount":450},"traceparent":"00-7efdaa95605dfc9c4bde97c0a78eaab8-9f49d57c96da3d8f-03","waiting":true}}
{"jsonrpc":"2.0","id":15,"result":{"status":"idle","runs":2,"fuel":14,"time":30000000000,"nextDeadline":60000000000}}
{"jsonrpc":"2.0","id":16,"result":{"session":2,"segment":0,"chart":"order","parent":null,"mailbox":0,"invocations":0,"timers":[{"sendid":"deadline","event":"payment.timeout","due":60000000000}],"timersPending":1}}
```

Serve system shop with a payments I/O processor, requests from a file.

```shell
tinyactors run --schema > run.schema.json
```

Write the protocol's JSON Schema to a file.

<a id="exit-status"></a>

## Exit status

- **`0`**: Standard input ends, or `--schema` has written the schema.
- **`1`**: An input or the config is refused at startup.
- **`3`**: An input or standard input cannot be read, standard output cannot be written or memory runs out.

<a id="see"></a>

## Related pages

- [JSON-RPC scripting](https://tinyactors.dev/cli/guides/scripting/index.md)
- [The protocol's JSON Schema](https://tinyactors.dev/cli/commands/run.schema.json)

## Commands

- [tinyactors compile](https://tinyactors.dev/cli/commands/compile/)
- [tinyactors check](https://tinyactors.dev/cli/commands/check/)
- [tinyactors inspect](https://tinyactors.dev/cli/commands/inspect/)
- [tinyactors states](https://tinyactors.dev/cli/commands/states/)
- [tinyactors transitions](https://tinyactors.dev/cli/commands/transitions/)
- [tinyactors events](https://tinyactors.dev/cli/commands/events/)
- [tinyactors data](https://tinyactors.dev/cli/commands/data/)
- [tinyactors expressions](https://tinyactors.dev/cli/commands/expressions/)
- [tinyactors disassemble](https://tinyactors.dev/cli/commands/disassemble/)
- [tinyactors graph](https://tinyactors.dev/cli/commands/graph/)
- [tinyactors diff](https://tinyactors.dev/cli/commands/diff/)
- [tinyactors lint](https://tinyactors.dev/cli/commands/lint/)
- [tinyactors path](https://tinyactors.dev/cli/commands/path/)
- [tinyactors fmt](https://tinyactors.dev/cli/commands/fmt/)
- [tinyactors actors](https://tinyactors.dev/cli/commands/actors/)
- [tinyactors run](https://tinyactors.dev/cli/commands/run/)
- [tinyactors help](https://tinyactors.dev/cli/commands/help/)
- [tinyactors version](https://tinyactors.dev/cli/commands/version/)
