# CLI

> The elefork command.

```sh
pip install elefork
export ELEFORK_URL=https://api.elefork.com ELEFORK_TOKEN=elefork_... ELEFORK_PROJECT=demo
```

Global flags: `--url`, `--token`, `--json` (print JSON instead of tables). Commands that start an operation wait for it to finish.

| Command | What it does |
|---|---|
| `elefork templates` | List templates |
| `elefork project create NAME [--size S] [--template T] [--no-branch]` / `project list` | Projects; a new project gets a running branch `main` (never expires) unless `--no-branch` |
| `elefork sql BRANCH "SQL" [--database D] [--role R] [--max-rows N]` | Run statements through the API (no driver needed; `-` reads them from stdin); prints each result; exits `3` on a SQL error |
| `elefork branch create (--template T \| --checkpoint C \| --parent B [--at-checkpoint C]) [--name N] [--count N] [--ttl SECONDS] [--size S] [--pause idle\|never] [--no-wait]` | Create or fork branches; `--pause never` keeps the branch from being paused when idle |
| `elefork branch set ID --pause idle\|never` | Change a branch's pause policy |
| `elefork branch list` / `branch get ID` | Inspect |
| `elefork branch pause ID` / `branch wake ID` | Pause / wake |
| `elefork branch reset ID --checkpoint C` | Reset to a checkpoint |
| `elefork branch delete ID` | Delete |
| `elefork branch credentials ID [--role R] [--database D] [--ttl S]` | Print a connection URI with a fresh token |
| `elefork branch credentials ID --revoke` | Revoke all tokens for the branch |
| `elefork checkpoint create BRANCH [--name N]` / `checkpoint list BRANCH` | Checkpoints |
| `elefork op get ID [--wait SECONDS]` | Inspect an operation |
| `elefork export BRANCH [-o FILE] [--format custom\|plain] [--schema S]... [--database D] [--snapshot ID]` | `pg_dump` the branch through the gateway (fresh 1-hour credentials; the password is passed in `PGPASSWORD`, never on the command line). `--snapshot` dumps in a snapshot you exported with `pg_export_snapshot()` from a transaction you keep open, e.g. to take row counts in the same snapshot |
| `elefork import BRANCH FILE [--clean] [--database D]` | Restore a dump in **one transaction**: custom format with `pg_restore --no-owner --no-acl`, plain SQL with `psql -v ON_ERROR_STOP=1`; on any error nothing is changed |
| `elefork dataset upload FILE --name N [--format sql\|csv] [--table T]` | Upload a `pg_dump` (plain format) or CSV |
| `elefork dataset build ID --base TEMPLATE [--no-wait]` / `dataset list` / `dataset get ID` | Build an org template from a dataset |
| `elefork task create SPEC.json` / `task list` / `task get ID` | Create a task version (`{"name", "template", "rules", "allow"?, "role"?}`) |
| `elefork episode start TASK [--count N] [--credentials]` | Start episodes; `--credentials` also prints a connection URI per branch |
| `elefork episode seal ID` | Seal and wait for the score; exits `4` unless the episode passed |
| `elefork episode get ID` / `episode list TASK` | Inspect results |

`--project` (or `ELEFORK_PROJECT`) accepts a project id or name.

`export` and `import` need the PostgreSQL 18 client tools (`pg_dump`, `pg_restore`, `psql`): on PATH, in `ELEFORK_PG_BIN`, via `--pg-bin`, or in the usual Homebrew/Debian locations (macOS: `brew install libpq`; Debian/Ubuntu: `apt install postgresql-client-18`). Your data is always yours to take: `export` works on every branch, paused ones are woken.

Exit codes: `0` success, `1` API error, `2` operation failed, `3` timed out, `4` episode did not pass (failed rules, tampered, or not scored).
