# CLI
English · [中文](CLI.zh-CN.md)
A dependency-light HTTP client for a running MiroShark backend.
## Install
```bash
# From a checkout with the backend installed:
pip install -e backend/
miroshark-cli ask "Will the EU AI Act survive trilogue?"
# Or run directly — no install, no third-party deps:
python backend/cli.py --help
```
Set `MIROSHARK_API_URL` to point at a remote deployment.
## Commands
| Command | What it does |
|---|---|
| `ask ""` | Synthesize a seed briefing from a question |
| `list` | List simulations / projects |
| `status ` | Runner status + round/total |
| `wait [--interval N] [--timeout N]` | Block until the run finishes, then exit 0/1 |
| `stop ` | Cancel a running simulation |
| `frame ` | Compact per-round snapshot |
| `publish [--unpublish]` | Toggle the embed public flag |
| `report ` | Render the analytical report |
| `cost ` | Estimated USD cost + token/call totals (the "$1" claim, per run) |
| `trending` | Pull RSS/Atom trending items |
| `health` | Ping `/health` |
All commands accept `--json` for scripting.
## Wait
`wait ` polls `/api/simulation//run-status` until the run reaches a
terminal state, so a script can block on a running simulation and then act on the
result without hand-rolling a polling loop:
```bash
# sim_id comes from `list` (or the web UI)
SIM=$(python backend/cli.py --json list | jq -r '.[0].simulation_id')
python backend/cli.py wait "$SIM" && python backend/cli.py report "$SIM"
```
Progress lines (`[running] round 12/144`) print to **stderr**, so stdout stays clean
for `--json` piping. Exit codes: `0` when the run **completes**, `1` when it **fails**
or is **stopped**, `2` on **timeout**. Tune the loop with `--interval` (seconds
between polls, default `5`) and `--timeout` (max seconds to wait, default `600`).
Add `--json` to print the final run-status payload on exit.
## Stop
`stop ` POSTs to `/api/simulation/stop` to cancel a running simulation —
the escape hatch `wait` was missing. `wait` blocks until a run reaches a terminal
state, but had no way to *end* one that hangs, overruns its timeout, or is simply no
longer needed. Pair them to bound a run and clean up on overrun:
```bash
# Wait up to 10 min; if it times out (or fails), stop it.
python backend/cli.py wait "$SIM" --timeout 600 || python backend/cli.py stop "$SIM"
```
On success it prints ` stopped` and exits `0`; on error (unknown id, server
failure) it exits `1`. `--json` is a global flag, so place it before the subcommand (`python backend/cli.py --json stop "$SIM"`) for the raw `/stop` payload.
## Cost
`cost ` surfaces the per-run cost estimate (the `/api/simulation//cost.json`
endpoint) at the command line, so the "$1 to simulate anything" claim is verifiable
from a script:
```bash
$ python backend/cli.py cost sim_abc123
~$0.9213 (1,284,902 tokens, 871 LLM calls)
graph_build ~$0.1204
simulation ~$0.7100
report ~$0.0909
```
The `~` prefix marks the figure as a lower-bound estimate — calls on models absent
from the price table count as `$0`. The simulation must be published (`publish `).
Exit codes: `0` on success, `1` on private/server error, `2` when cost is not yet
available (the run has logged no LLM calls). Add `--json` for the full breakdown.