# CLI

> The sysnee CLI deploys sites, follows builds and creates databases from a terminal, CI or a coding agent, with JSON output and stable exit codes.

## Install

Needs Node.js 20 or newer.

```bash
npm install -g @sysnee/cli@1.0.0
sysnee --version
```

Without installing: `npx @sysnee/cli@1.0.0 <command>`. The package is published to npm from Sysnee's repository with provenance (`npm audit signatures` checks it).

## Sign in

```bash
sysnee login
```

1. The terminal shows a code and opens `https://cloud.sysnee.com/oauth/device`.
2. Check that the code matches, review the permissions and approve. Write permissions ask for your second factor.
3. The CLI keeps the session in the system keychain (macOS Keychain, Windows Credential Manager, Secret Service on Linux). Without a keychain it uses a file only your user can read (`~/.config/sysnee/credentials.json`, mode 0600), and says so.

By default the login asks for read access to everything, site deploys, and creating, stopping and starting databases. **No delete scope.** To ask for others:

```bash
sysnee login --scopes "account:read sites:read sites:deploy sites:delete"
```

The session lasts 30 days without use and renews itself. `sysnee logout` deletes the local credentials and revokes the session on the server. You can also revoke it in **Console → Security → Authorized apps**.

On a machine without a browser, use `sysnee login --no-browser` and open the link on another device.

### CI and scripts

Create a [personal token](https://docs.sysnee.com/en/tokens.md) in **Console → Security → Tokens** with only the scopes and projects you need, and pass it as an environment variable:

```bash
SYSNEE_TOKEN=sysnee_pat_... sysnee deploy dist --site my-site
```

`sysnee login --token sysnee_pat_...` stores the token like a session. In CI, prefer the variable: the token stays in the CI's secret store, not on disk.

## Commands

| Command | What it does |
|---|---|
| `sysnee whoami` | Who is signed in, with which scopes and projects |
| `sysnee projects` | List projects |
| `sysnee link [--project <id>] [--site <name>]` | Tie the folder to a project and site (`.sysnee/project.json`) |
| `sysnee usage` | This month's usage and cost so far |
| `sysnee deploy [dir] [--site <name>] [--no-wait]` | Zip the folder, upload it and follow the build |
| `sysnee sites list` | List sites |
| `sysnee sites create <name> [--spa]` | Create a site at `<name>.sysnee.app` |
| `sysnee sites info [site]` | Details and deployments |
| `sysnee sites update <site> [--spa\|--no-spa] [--analytics\|--no-analytics]` | Turn SPA mode or visitor analytics on or off |
| `sysnee sites logs [site] [deployment] [--follow]` | Build log |
| `sysnee sites rollback <site> <deployment>` | Serve an earlier deployment again |
| `sysnee sites delete <site> [--request]` | Delete the site (see [Deletions](#deletions)) |
| `sysnee domains list <site>` | The site's domains and their status |
| `sysnee domains add <site> <hostname>` | Add a domain and show the DNS records |
| `sysnee domains verify <site> <domain-id>` | Check the DNS now |
| `sysnee domains remove <site> <hostname> [--request]` | Remove a domain (see [Deletions](#deletions)) |
| `sysnee db list` | List databases |
| `sysnee db info <database>` | Host, port, user and state |
| `sysnee db create <name> --dotenv .env` | Create a database (see below) |
| `sysnee db stop <database>` / `start <database>` | Stop or start the database |
| `sysnee db delete <database>` | Always confirmed by a person in the console |
| `sysnee schema` | Every command and option as JSON |

Global options: `--json`, `--dry-run`, `--api-url <url>` (or `SYSNEE_API_URL`). `sysnee <command> --help` shows each command's options.

`<site>` and `<database>` take the name or the id. Without `--project`, the CLI uses the folder's linked project and, failing that, the organization's default project.

### Deploy

```bash
sysnee deploy dist
```

- The folder is the build output (with `index.html` at its root), not the source code. Run the build first.
- Left out: `.git`, `node_modules`, `.sysnee` and any `.env*`.
- Limits: 100 MB compressed, 500 MB uncompressed, 10,000 files. See [Sites](https://docs.sysnee.com/en/sites.md).
- Without `--no-wait`, the command follows the log and ends with the final status (`ready` or `failed`).

### A database without exposing the password

```bash
sysnee db create my-db --dotenv .env
```

- The CLI generates a strong password on your machine, creates the database and writes `DATABASE_URL=postgresql://...` to `.env`. A new file is created with mode 0600.
- The password is not in the output, not even with `--json`. That is why coding agents should use this command.
- If `.env` is not in `.gitignore`, the CLI warns you.
- `--env-key` changes the variable name. `--yes` replaces an existing variable.
- Other options: `--size low|medium|high`, `--storage <gb>`, `--purpose development|staging|production`, `--pg-version 16|17|18`, `--allow <cidr>`.
- `--show-password` prints the password. Don't use it when an agent runs the command.

### Deletions

- **`sysnee sites delete`** in a terminal asks you to type the site's name, then deletes it. Outside a terminal (CI, agents) or with `--request`, it creates a deletion request and exits with code 2. Nothing is deleted until a person confirms at the console link.
- **`sysnee domains remove`** works like `sites delete`: in a terminal you type the hostname; elsewhere, or with `--request`, a request confirmed in the console and exit code 2.
- **`sysnee db delete`** always creates the request and exits with 2, even in a terminal.
- They need the matching delete scope (`sites:delete`, `databases:delete`), which the default login does not ask for.

## For scripts and agents

- **JSON:** the output is JSON when it is not a terminal, or with `--json`. Errors too: `{"error": "<code>", "message": "..."}`.
- **`--dry-run`:** shows the method, URL and body that would be sent, without sending them. Passwords are masked.
- **`sysnee schema`:** describes every command, argument and option as JSON.

### Exit codes

| Code | Meaning |
|---|---|
| `0` | Success |
| `1` | Error (validation, limit, not found, network) |
| `2` | A person must confirm; nothing was done. The output has `confirm_url` |
| `3` | Sign-in needed: run `sysnee login` or set `SYSNEE_TOKEN` |

### Environment variables

| Variable | Use |
|---|---|
| `SYSNEE_TOKEN` | Access token; takes precedence over the saved session |
| `SYSNEE_API_URL` | Another API origin (staging) |
| `SYSNEE_CONFIG_DIR` | Where to keep the configuration (default: `~/.config/sysnee`) |
| `SYSNEE_NO_KEYCHAIN=1` | Don't use the system keychain |
