# The CLI

> Every command of npx @sypnia/cases, and its flags.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://cases.docs.sypnia.com/tools/cli/

For agents: Commands: init (create cases/ with map.yaml, navigation.yaml and an example), generate [--check] (typed skeletons src/cases/<area>/<id>.ts for new cases, .sypnia/cases/types.d.ts, and each area's service src/areas/<area>.ts), nav [--from-code] [path <place>] (the navigation tree; propose it from data-sypnia-place/data-sypnia-opens), graph [--from <event>] [--json] (the event graph), deliveries <listener> and dead-letters list|show|replay|drop --event <id> --reason (read the app's database: DATABASE_URL or --database-url), dev [trigger <case>] (every area's service from src/areas on PORT, PORT+1…, against DATABASE_URL, with its background delivery task), check [--contract] [--json] [--ci] [--base <git ref>] [--no-telemetry] (validate, compare with code, commit trailers `Case: <id>`, `// case: <id>` notes, cases/plan.md and production figures from Telemetry; exit 1 on errors), sync --from-code (fill code-owned fields into the case files), login (device flow, Sypnia account, through @sypnia/data), pull [--version N] (the approved map, or a version, into cases/, files as written), push [--title] (local files as a draft proposal), propose --title [--reviewers a,b] (open a proposal with the changes against the approved version), diff [vN..vM] [--base <ref>] [--json] (two versions; the files against the approved version when [cases] project names a Cases project; against a commit with --base or without a Cases project), link <map> [--data <ref>] (writes [cases] project and data in sypnia.toml and, with --data, links the map and the Data project both ways on the Cases server); the Cases server is https://cases.api.sypnia.com, or SYPNIA_CASES_API / [cases] api; credentials SYPNIA_TOKEN or the login session, key <case> (a case key syp_rck_… for SYPNIA_CASE_KEY_<CASE_ID>), Sypnorm's tables (typed tables from Sypnia Data or DATABASE_URL) and map [--upload --project <ref>] [--check] [--json] [--out] [--force] (the code side of the map; --upload --project <x>: 20 lowercase letters is a Data project ref, sent to its «Use cases» and forwarded by the Data control plane to the linked Cases map as a draft proposal; anything else is a Cases map, sent to the Cases server as a draft proposal; SYPNIA_TOKEN or the login session).

### `cases init`\[Engine, Cloud]Creates `cases/` with `map.yaml`, `navigation.yaml` (one root) and one example case, with the schema line for your editor.

### `cases generate`\[Engine, Cloud]Writes a typed skeleton, `src/cases/<area>/<id>.ts`, for every case that has none (it never overwrites code), `.sypnia/cases/types.d.ts` with every input, outcome and failure, and each area's service, `src/areas/<area>.ts`. Run it after each change to the map; `--check` fails when the types are out of date.

### `cases nav`\[Engine, Cloud]Prints the navigation tree with each place's path and cases. `cases nav path <place>` prints one path («Shop › Order for tomorrow»). `--from-code` reads every `data-sypnia-place` and `data-sypnia-opens` in your code and proposes the tree ([The navigation map](https://cases.docs.sypnia.com/map/navigation)).

### `cases graph`\[Engine, Cloud]Prints the event graph: which case starts on which outcome. `--from <event>` follows one chain; `--json` for machines ([Outcomes and events](https://cases.docs.sypnia.com/map/outcomes-and-events#the-event-graph)).

### `cases check`\[Engine, Cloud]Validates the map and compares it with the code, the plan and production ([The check](https://cases.docs.sypnia.com/contract/the-check)). Code is Sypnorm's use cases, `Case: <id>` trailers of the last 2000 commits and `// case: <id>` notes in the sources. `cases/plan.md` gives `unbuilt`; with Telemetry linked (`app.telemetry` in `map.yaml`, or `telemetry` in the `[cases]` table) and a read token in `SYPNIA_TELEMETRY_TOKEN`, it reads the last 30 days of production. Flags: `--contract` (also the landing's promises and milestones that name no case), `--json`, `--ci` (annotations), `--base <git ref>` (the commit to compare outcome payloads with, for `breaking-change`; `HEAD` by default), `--no-telemetry` (skip production). Exit `1` on any error.

### `cases sync --from-code`\[Engine, Cloud]Fills the fields the code owns (data, failure names, allowed actors) from `npx @sypnia/cases map`. It edits the case files; review them as any change to the map, and send them with `cases propose`.

### `cases deliveries <listener>`\[Engine, Cloud]Recent deliveries to one listening case (`deliveries.tell-the-baker`): state, attempts, wait, last error ([Delivery](https://cases.docs.sypnia.com/runtime/delivery)). It reads the app's database: `DATABASE_URL`, or `--database-url`; `--json`, `--limit`.

### `cases dead-letters`\[Engine, Cloud]`list` every listener with dead letters; `show <listener>` its events and errors; `replay <listener> [--event <id>]` sends them again after a fix; `drop <listener> --event <id> --reason "…"` removes one, with the reason kept ([Dead letters](https://cases.docs.sypnia.com/runtime/delivery#dead-letters)). Like `deliveries`, it reads `DATABASE_URL` or `--database-url`.

### `cases dev`\[Engine]Runs every area's service of `src/areas/` on your machine, against your local Postgres (`DATABASE_URL`), each on its own port from `PORT` (3000 by default, or `--port`) up, with events delivered between them and the jobs of `scheduled` cases on a fast clock (`--clock 60x`). TypeScript areas run through `tsx`. `cases dev trigger <case>` queues a run of a case now; its area's service runs it.

### `cases login`\[Cloud]Signs in with your Sypnia account through the device flow of `@sypnia/data` (the same session Data's CLI saves): you approve a code in the browser, and the session stays in `~/.config/sypnia/` (mode 600). Nothing secret is pasted anywhere. The session is bound to a key on this machine; where a command takes a token instead, set `SYPNIA_TOKEN`.

The commands below talk to a Cases server: Sypnia Cloud at `https://cases.api.sypnia.com`, or your own, named in `SYPNIA_CASES_API` or in `api` of the `[cases]` table. They use `SYPNIA_TOKEN` (a Sypnia token or a Cases project token), else the `login` session. The Cases project is `--project <map>`, or `project` of the `[cases]` table.

### `cases pull`\[Engine, Cloud]Writes the approved version of the map into `cases/`, or another version with `--version 3`. A version made from files gives each file back as it was written, byte for byte. Files only on your side are listed, never deleted; `cases/plan.md` stays yours.

### `cases push`\[Engine, Cloud]Sends the files of `cases/` as a **draft proposal** against the approved version (`--title` names it). It never changes an approved version; `cases propose` opens it for review.

### `cases propose`\[Engine, Cloud]Opens a proposal with the local changes against the approved version: each case added, changed or retired. `--title "…"` names it, and `--reviewers ana@la-espiga.co,owner@la-espiga.co` asks those people to review ([Versions, proposals and reviews](https://cases.docs.sypnia.com/contract/versions-and-reviews)).

### `cases diff`\[Engine, Cloud]Shows changes case by case and field by field; `--json` for machines. `cases diff v3..v4` compares two versions of the Cases project. With a Cases project set, `cases diff` compares `cases/` with the approved version; `--base <ref>`, or no Cases project, compares it with a commit (`HEAD` by default).

### `cases link`\[Engine, Cloud]Binds this repository to a Cases project: `cases link <map>` writes it into the `[cases]` table of `sypnia.toml`, so the commands above and `map --upload` know where to go. With `--data <ref>` it also writes the Data project there and links the map with that Data project, both ways ([Data](https://cases.docs.sypnia.com/links/data)).

### `cases key <case>`\[Engine, Cloud]Prints a new case key (`syp_rck_…`) for an `external` case without a signature, once. Keep it in your app's secrets as `SYPNIA_CASE_KEY_<CASE_ID>` (`SYPNIA_CASE_KEY_RAPPI_ORDER`) and give it to the caller ([How a case starts](https://cases.docs.sypnia.com/map/starts#external)).

## Sypnorm's commands

### `cases tables`\[Engine, Cloud]Reads your database schema (a Sypnia Data project, or any Postgres through `DATABASE_URL`) and writes Sypnorm's typed tables ([Tables and queries](https://cases.docs.sypnia.com/sypnorm/tables-and-queries)).

### `cases map`\[Engine, Cloud]Derives the code side of the map from your use cases into `sypnorm.map.json` (`--out` for another file). Flags: `--upload` sends the map to the project `--project` names (by default `project`, then `data`, of the `[cases]` table). Twenty lowercase letters is a Sypnia Data project: the map goes to its «Use cases», and Data forwards it to the Cases map linked with that project, as a draft proposal. Anything else, or any project while `SYPNIA_CASES_API` or `api` of the `[cases]` table names your own server, is a Cases map: the map goes to the Cases server as a draft proposal of what the code changed. A person approves it; a map with errors is not sent unless you add `--force`. It signs in with `SYPNIA_TOKEN`, or the `login` session. `--check` fails when code and file differ; `--json` prints it ([The map from your code](https://cases.docs.sypnia.com/sypnorm/the-map)).
