> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rua.hud.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# CLI

> Reference for rua's command-line entry points: the sim programs python -m rua.sim.bridge and python -m rua.sim.gym, and their port announcement.

rua installs no console script. Its command-line surface is two **sim programs**, run with `python -m`, which
serve a bridge until SIGTERM or Ctrl-C. `RobotEndpoint` and `attach_gym` run them for you; you run them by hand
to host a sim on another machine or to debug one.

Both print one line once the control channel is bound, which a spawning `RobotEndpoint` reads from stdout:

```text theme={"dark"}
HUD_SIM_PORT=<control port>
```

Everything else on stdout is the sim's own logging.

## `python -m rua.sim.bridge`

Serve a `RobotBridge` subclass.

```bash theme={"dark"}
python -m rua.sim.bridge path/to/sim.py:ClassName [--init JSON]
```

| Argument | Description |
| - | - |
| `path/to/sim.py:ClassName` | The bridge class, loaded from the file by path. |
| `--init JSON` | Constructor keyword arguments as a JSON object. The reserved key `__hud_state__` carries `contract`, `metadata` and `num_envs`, set on the instance after construction. |

The control channel binds an ephemeral port on `127.0.0.1`.

```bash theme={"dark"}
$ python -m rua.sim.bridge sim.py:PointArm
[env] robot listening on ws://127.0.0.1:38679
HUD_SIM_PORT=35269
```

## `python -m rua.sim.gym`

Serve a gym-style env with `GymBridge`.

```bash theme={"dark"}
python -m rua.sim.gym TARGET [--fps N] [--contract PATH] [--bridge FILE:CLASS] \
    [--host HOST] [--port PORT] [--num-envs N] [--KEY VALUE ...]
```

| Argument | Default | Description |
| - | - | - |
| `TARGET` | required | `path/to/module.py:factory`, a gymnasium registry id, or an `EnvSpec` as JSON. |
| `--fps` | none | Control-rate override. |
| `--contract` | none | Contract file to load, or write when missing. Without it, the contract is derived in memory. |
| `--bridge` | `GymBridge` | `path/to/module.py:Class`, a `GymBridge` subclass to serve instead. |
| `--host` | `127.0.0.1` | Control-channel interface. |
| `--port` | `0` | Control-channel port; `0` is ephemeral. |
| `--num-envs` | none | Vectorized slot count. |
| `--KEY VALUE` | | Any other pair becomes a task-arg default named `KEY` with dashes as underscores. `VALUE` is parsed as JSON when it can be, else kept as a string. |

```bash theme={"dark"}
$ python -m rua.sim.gym CartPole-v1 --contract cartpole.json
[env] no contract found; building env to probe observation/action structure
[env] wrote cartpole.json (edit names to relabel plots)
[env] robot listening on ws://127.0.0.1:33243
HUD_SIM_PORT=46803
```

> [!NOTE]
>
> `attach_gym` passes `--contract contract.json` by default, while the command line's own default is no file.
> `--host` and `--port` set the control channel only; the robot WebSocket always binds an ephemeral port on
> `127.0.0.1`.

Both programs print a `RuntimeWarning` from `runpy` at startup, because `rua.sim` imports its `bridge`
and `gym` submodules before `python -m` runs them. It is harmless.

`rua.sim.gym.gym_command(target, *, fps=None, contract="contract.json", bridge=None, **defaults)` returns
the argv `attach_gym` spawns, if you want to run it yourself.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.