# Publishing & the CLI

The gateway serves snapshots from the published store. The thermite CLI creates them: draft for review, publish for production. Both commands validate manifests, tag definitions, and transaction/query files before changing the target slot. Verify the resulting application on the gateway.

## Snapshot source into draft or production.

Edits in `projects/` do not replace production screen files. Drafts have separate snapshots and sessions but share gateway device connections; draft writes can affect connected equipment. Publish snapshots the current source again. Keep it at the reviewed revision to publish reviewed content. Slot mounts and supported project changes apply live; alarm-definition and notification changes require a gateway restart.

```sh
# stage for review
$ thermite project draft press-line wip
Published press-line → draft 'wip' (snap-01a1d097bba372efaa8af557dc922b19) — serves at /draft/press-line/wip/

# publish the current project source to production
$ thermite project publish press-line
Published press-line → production (snap-01a1d097bbd674859e2966fd5c5dd513)
Surviving drafts:
  wip    (published 2026-11-12T16:29:27.331313+00:00)
    teardown: thermite project destroy-draft press-line wip

# clean up the draft slot
$ thermite project destroy-draft press-line wip
Destroyed draft 'wip' of 'press-line'.
```

## The command set.

Global flag: `--site <path>` (defaults to walking up from the current directory). The slug `.` means "the project containing the current directory." Nothing prompts; every failure exits non-zero — safe to script.

| Command | Effect |
| --- | --- |
| `thermite project init <slug>` | Create `projects/<slug>/` with a fresh manifest. Refuses if the directory exists. |
| `thermite project draft <slug> <name>` | Validate the workspace project and snapshot it into the `drafts/<name>` slot, served at `/draft/<slug>/<name>/`. Re-running swaps that draft's snapshot. |
| `thermite project drafts <slug>` | List a project's published draft slots. |
| `thermite project publish <slug>` | Validate and snapshot into the production slot, served at `/p/<slug>/`. |
| `thermite project publish --all` | Publish every workspace project — provisioning and demo bootstrap. |
| `thermite project unpublish <slug>` | Remove the production slot. Drafts and the workspace are untouched; publish restores the app. |
| `thermite project destroy-draft <slug> <name>` | Remove a draft slot. Draft-only verb — production can't be destroyed here. |
| `thermite project list` | Store-wide listing of every published slot. |

## The published store.

Snapshots are immutable folders; a one-line `current` pointer names the live one. Manage the store through the CLI; the server reads the published snapshots.

```
published/
├── .lock                          # store-wide advisory lock
└── press-line/
    ├── production/
    │   ├── current                # contains: snap-01a1d097bbd6…
    │   └── snap-01a1d097bbd6…/
    │       ├── snapshot.toml      # provenance — below
    │       ├── project.toml
    │       ├── users.toml
    │       ├── tags/  screens/  transactions/  queries/
    │       └── …
    └── drafts/
        └── wip/
            ├── current
            └── snap-01a1d097bba3…/
```

```toml
# snapshot.toml — written by the CLI at publish time
format_version = 1
project_id = "01979000-0000-7000-8000-000000e14400"
slug = "press-line"
kind = "production"
created_at = "2026-07-03T17:15:03.091683400+00:00"
cli_version = "0.1.0"
source_git_commit = "18e72427e58fc5149510b8f1cd1a3c87bbb37834"
source_git_branch = "main"
```

The git fields are best-effort: present when the workspace is a git repo, absent otherwise — and a snapshot of a dirty workspace contains the uncommitted content, whatever the recorded commit says. Publish from clean, committed source and retain any private inputs separately for recovery.

## Review project changes before publishing.

### `01 · Branch`

Keep reviewed project source and configuration templates in Git; keep credentials and live gateway configuration in secured recovery backups. Branch and edit the source.

### `02 · Draft`

thermite project draft `<slug>` `<name>` snapshots the current project source at `/draft/<slug>/<name>/`. Review it with the project's configured access policy.

### `03 · Review`

The PR diff is the change — tags, screens, manifests are plain text. CI can run any linting you like; the publish step itself validates.

### `04 · Publish`

After merge, run thermite project publish on the gateway (by hand or from your pipeline over SSH) from the clean merged checkout — the snapshot then records the merge commit.

Check out the intended revision in the site's `projects/<slug>/` folder, then run `thermite project draft <slug> <name>`. The draft name selects the destination slot at `/draft/<slug>/<name>/` — see [Projects](https://thermitescada.com/docs/project-structure.md).

## Restore earlier source and publish again.

Publishing retains the immediately-prior snapshot; the CLI prints what it replaced. Roll back by checking out and republishing the earlier project source, creating a new snapshot. For a clean committed publish, `source_git_commit` identifies that source revision; it does not describe uncommitted or ignored files included in a snapshot.
