# Release slice: preview deploys

Status: 2026-11-11, revision 2. Drafted by Claude (Opus 5.5) on
`release-preview` from main 2096af3. This slice of
`2026-11-11-equipo-release.md` runs ahead of the others, at Paul's
request: "Can we unblock it from being able to get me mockups and deploy
them / the app?"

Revision 1 (3bc1909) drew NOT READY from Astra in its one round. The
findings are in `CODEX-FINDINGS-RELEASE-PREVIEW.md`; revision 2 takes
every one, marked **(astra N)**, mostly by cutting scope.

The main cut is that v1 builds nothing. A preview is the committed files
of one output directory, read from git objects. Running a build command
moves to v2, with the release plan's prefetch.

## 0. Why, and the finish line

Engineering can build clickable mockups on a task branch, but Paul has
no way to see them. A preview is a Carloku **temporary static site**: a
public `tmp-<name>.<region>.oncarlos.com` that moves to the Trash after 7
days. It gets the platform host only, and an account holds at most 20
(carlos/platform `docs/superpowers/specs/2026-09-25-temporary-static-sites-design.md`).

**Finish line:**
- An approved candidate whose `release/preview.json` names an output
  directory is published to `tmp-<task id>`.
- The task card says "Preview: <link> (expires in 7 days)".
- A newer approved candidate replaces the preview in place.
- Demo: the barber mockups task (`tk5fen4uajpn`, paulca/threatmin) once
  Paul retries it.

A preview is never called shipped, deployed or live.

## 1. Rules

1. **Approved candidates only.** Equipo schedules a preview once per
   candidate, only after Review approves it, and only when Review's
   report says the candidate has `release/preview.json`
   (`has_preview`).
   - `has_preview` is scheduling evidence, not authority **(astra 3)**:
     the preview step reads the config again from the candidate.
   - **Why approval, not "Paul asked":** a preview is published to the
     open internet under Paul's account. Approval means a second model
     has read the change and its config first.
   - The coordinator cannot trigger a preview.
   - A person's Preview button for an unapproved candidate is v2 (§6).
2. **Config.** `release/preview.json` holds `{"output": "<dir>"}`. It is
   read from git objects, at most 4 KiB, decoded strictly.
   - `output` is a clean relative path that is not `.git`, and none of
     its parts start with `.`.
   - Any other field, `build` included, refuses the preview in v1
     **(astra 4, cut)**.
3. **Export from git objects, never the working tree (astra 4).**
   - The runner fetches the candidate into a private git directory, as
     checks do, and lists `git ls-tree -r -l <candidate> -- <output>`.
   - Only regular blobs (modes 100644 and 100755) are taken. A symlink
     (120000), a submodule, any path with a part starting with `.`
     (`.carlos/` included) and the reserved `equipo-preview.json` all
     refuse the preview.
   - Caps: at most 2,000 files, 10 MiB each and 50 MiB in total, all
     checked against the listing before any read.
   - Each blob is written with `git cat-file blob`, its size checked
     while copying, to a fresh file in a new 0700 staging directory
     under the runner's state, outside every workspace and namespace.
     No repository code runs.
   - The digest is the SHA-256 of the sorted lines `<path> <sha256>`.
     The marker `equipo-preview.json` (task, full candidate, step,
     attempt, digest) is written after it and is not part of it.
   - Every `carlos` command runs with its working directory in a fresh,
     empty directory.
4. **Steps and authority (astra 3, 8).** The preview step runs on the
   primary.
   - **Start:** the start authorization (`LeaseCheck`) for a preview step
     holds only for the current attempt, not withdrawn, of a task not
     cancelled, whose newest candidate is the step's, approved, and
     whose creator is still an owner.
   - **Built:** after export the runner reports `preview{phase: built,
     digest, files, bytes}` and the instance records the digest. This
     report must arrive before publishing: the publish check below
     requires the recorded digest.
   - **Publish:** before each mutation, the runner sends a `LeaseCheck`
     with purpose `preview_publish` and the digest (a new field). The
     instance's `authorizePreview` repeats the start conditions, and
     requires the digest to equal the recorded one. It writes an audit
     row.
   - Below protocol 9 the runner never sends a preview check, so it is
     never downgraded into an ordinary lease. The instance places
     previews only on a primary at 9.
   - **The commitment point is the promote.** A refusal before it ends
     the step `cancelled`, and nothing of this candidate is served. A
     refusal after it cannot unpublish, and the step says so.
5. **Mutations: one at a time, fixed templates (astra 1, 2, 6).** Every
   command runs with `CARLOS_SERVICE_TOKEN` in the environment and the
   account and console from the credential file. Each mutation is
   preceded by its own publish check, and its intent is written to the
   runner's step state first.

   | Phase | Command |
   |---|---|
   | read state | `carlos apps list`: the `tmp-<task>` line is missing, live with an expiry, live with no expiry (kept), or trashed. Anything unparseable is unknown and ends the step |
   | create (missing) | `carlos deploy --temporary --ttl 7d --app <task> --kind static --version p0-<step7> --no-prompt <placeholder dir>`. It creates the app, mints its host and serves a runner-written placeholder page, never repository content. Its watch probes only that page, which has no `_redirects` |
   | renew (live) | `carlos apps ttl --app tmp-<task> 7d`, before any content changes. The platform's printed expiry is recorded |
   | ship | `carlos ship --app tmp-<task> --kind static --version p-<step7>-<attempt> --no-prompt <staging dir>`. Serves nothing |
   | promote | `carlos promote --app tmp-<task> --no-prompt p-<step7>-<attempt> <channel>`. The channel is read from `carlos channels` |

   - **Refused states:** kept, trashed or unknown. Trashed ends
     `preview_expired`, and the step does not invent another name.
   - **Refusals and their reasons:** a create refused at the cap is
     `preview_cap`. Carloku's create budget is 50 attempts per principal,
     counted in memory **(astra 9)**. A refused create is reported, never
     retried.
   - **Never run:** delete, keep, domains, gate, assets, env and secrets.
   - **Never on another app:** no command touches any app but
     `tmp-<task>`.
   - **Versions:** each includes the preview step's id, and the record
     keeps the full candidate **(astra 7)**.
6. **Verified, without following anything (astra 2).** After the promote,
   the runner fetches `https://tmp-<task>.<domain>/equipo-preview.json`.
   - The request refuses redirects, sends no credential, is capped at
     64 KiB and retries for at most 2 minutes.
   - It needs HTTP 200, the task, the full candidate, the step, the
     attempt and the digest.
   - Then the step is done (`deployed`), with the URL and the platform's
     expiry.
   - Otherwise it is done with the outcome `unconfirmed` **(astra 5)**,
     and it is never retried.
7. **Restarts (astra 5).**
   - A preview step that stopped before its first mutation fails
     `runner_restarted`, as today.
   - One stopped after a mutation intent was written runs again in a
     reconcile phase. That phase rebuilds nothing and sends nothing: it
     fetches the marker (rule 6), and ends `deployed` or
     `unconfirmed`.
   - **Rolling a runner back below 8:** the instance stops placing
     previews, every preview step settles, and the outbox drains first.
8. **Ancillary (astra 7).** Preview steps never drive a task: the
   progress Equipo computes skips them. A failed preview leaves the task
   where it was, with no Needs you.
9. **Audit and spend.**
   - Audit rows for every check (`preview.authorize`, allowed or
     refused) and outcome (`preview.deployed`, `preview.unconfirmed`,
     `preview.failed`), with the task, step, candidate, app and digest,
     and no credential.
   - A preview runs no model, so it spends no tokens. The step records
     its wall time and bytes. A first preview uses one of the
     principal's temporary create attempts.

10. **Round 2 fixes** (Astra round 2 on 5885855, findings in
    `CODEX-FINDINGS-RELEASE-PREVIEW-R2.md`).
    - **No replacement after a start.** A preview attempt that started is
      never replaced. Withdrawn, or its runner removed, it ends done and
      "could not be confirmed" once its export was recorded as built
      (it may have published), and cancelled before that.
    - **A withdrawn attempt keeps its report.** A withdrawn attempt's
      own done report is kept as it says.
    - **Cancelled previews reconcile.** After a restart, a preview that
      may have published reconciles from the marker even when cancelled.
    - **The credential file is refused unless all of these hold:**
      - it is a regular file, not a link (lstat, then `O_NOFOLLOW`);
      - its mode is exactly 0600 and the runner's user owns it;
      - it is outside every directory a sandbox mounts (the workspace,
        scratch, step git directories, the Go root and the module
        cache);
      - its JSON decodes as expected.

      Every error is a fixed sentence, never content or keys. The path
      is one of the protected paths.
    - **An empty account is a listing.** `carlos apps list` printing "no
      apps in this account" counts as an empty list.

## 2. States and the card

- **The timeline:** "Prepared 12 files (340 KiB)." once built, then
  "Preview ready" with the link. An unconfirmed outcome reads "Preview
  could not be confirmed". A failure reads as any stopped step does, with its reason.
- **The task card:** the newest `deployed` preview whose expiry is still
  ahead gives "Preview: <link> (expires in 7 days)".

## 3. Wire

**Protocol 9,** `wire.ProtocolPreview`, adds (8 went to the empty-repository merge, `wire.ProtocolEmptyMerge`, on main first):
- `StepReport.has_preview` (Review);
- `StepReport.preview` (`{phase, app, url, version, digest, files,
  bytes, expires_at, outcome}`);
- `LeaseCheck.digest`;
- the `preview` specialist and the `preview_publish` purpose.

**Downgrade:**
- `Encode` drops the fields below 8.
- A preview dispatch is never encoded below 8: `Encode` refuses it with
  `ErrProtocol`.
- **The fence (astra 8):** when a primary connects below 8, its queued
  and running preview steps settle `cancelled` with `runner_outdated`
  (`fenceOldRunner`'s pattern), and their pending dispatch commands are
  retired.

## 4. Permissions

| What | Who holds it | Paul's action |
|---|---|---|
| A Carloku credential that can create, update and ttl temporary apps | the primary runner, from a 0600 file (`EQUIPO_PREVIEW_CREDENTIAL_PATH`) never mounted into a namespace | **C6, carlos/platform#935**, asks for a `temporary` role. Until then, see below |
| The runner setting | Paul | one `EQUIPO_PREVIEW_CREDENTIAL_PATH` line in the staging runner's `service.env` |

**Until C6:**
- **The account:** a Carloku account used only for previews.
- **The credential:** `carlos services create --role publish --account
  <previews account> equipo-previews`.
- **The file:** the token, console, account and the account's platform
  domain (for example `bds.oncarlos.com`).

This credential is broad: it could also create permanent apps or keep
one **(astra 1)**. The executor's templates are the only limit, and the
dedicated account bounds what it can reach. A `deploy` credential cannot
create apps (`authcli.go:598`), so it cannot serve here.

## 5. Tests, failing first

- **wire:** the downgrade below 8, strict at 7, and a preview dispatch
  refused below 8.
- **runner:**
  - **config:** strict decoding, unknown fields, bad paths;
  - **export:** symlink, submodule and dot paths, the reserved name, the
    caps, the digest, and the marker kept out of it;
  - **executor:** the exact argv of each phase, the token only in the
    environment, the working directory, each state of `apps list`, a
    publish check refused before each mutation;
  - **verification:** a match, a mismatch, and a redirect refused;
  - **reconcile:** after a restart.
- **thintest:**
  - an approval with `has_preview` schedules one preview, and only one
    per candidate; without either, none;
  - a newer approved candidate schedules another;
  - each start and publish condition, one at a time;
  - the digest is bound;
  - a preview never sets Needs you or moves the stage;
  - the card line and the timeline;
  - the audit rows;
  - the fence for a protocol 7 primary.
- **Mutations:** each authority condition, each export guard, the
  allowlist, the verification checks and the ancillary rule are broken
  once, and each test is seen to fail.

## 6. Out of scope, v2

- Build commands, which need the release plan's prefetch and contained
  build.
- A person's Preview button.
- A second name after an expired preview.
- Deleting a preview when its task ends; it expires on its own.

## 7. Copy (Astra's delegated verdicts applied, two passes)

| Key | Text |
|---|---|
| `work.specialist.preview` | Preview |
| `work.tl.preview_built` | Prepared %d files (%s). |
| `work.tl.preview_ready` | Preview ready |
| `work.tl.preview_unconfirmed` | Preview could not be confirmed |
| `work.card.preview` | Preview: %s (expires in %s) |
| `work.reason.preview_cap` | the account already has 20 previews |
| `work.reason.preview_expired` | this task's preview expired and its name is still taken |
| `work.reason.preview_config` | this version cannot use release/preview.json |
| `work.reason.preview_too_large` | the preview exceeds 2,000 files, 10 MiB per file or 50 MiB in total |
| `work.reason.preview_state` | Equipo could not read the preview's state |
| `work.reason.runner_outdated` | the runner needs an update for previews |
| `work.card.preview_open` | Preview: %s |
| `work.preview.in_days` / `in_day` / `today` | %d days / 1 day / less than a day |
| `work.reason.preview_failed` | a Carloku command for the preview failed |
