# Deploy and review

# Deploy and review

**Run** compiles the open file against this device, compares it with what runs
now, and deploys it. A change that leaves safety as it was lands at once; a
change to what protects the system lands only after you read the review.

## Before it can run

- The file compiles with no errors. Its unit tests run on every compile; the
  review shows how they did.
- Every input and output is wired ([Wiring](https://phloem.ai/docs/trellis/channels/)).
- No run is waiting on a change it cannot carry (below).

## The review

The review leads with one verdict line — *2 looser · 1 new command · 3 tighter*
— then lists each change, riskiest first:

| Kind | Means |
|---|---|
| **Looser** | a limit or hold time moved the permissive way |
| **Removed** | an alert, condition or output is gone |
| **New command** | the system can command something it could not before |
| **Safe state** | an output's `safe=` value changed |
| **Changed** | a difference with no clear direction, for you to read |
| **Tighter** | a limit or hold time moved the protective way |
| **Added** | a new alert or condition |

The first four are marked; **Tighter** and **Added** fold into one line,
**Changes that only make it safer**. **Wired differently** lists each channel
that moved. A raised or removed `rate_limit=` is looser, a lowered one tighter;
a change to who an alert tells (`notify=`) is a change to read; every script
the sequences run is listed by its contents. The review counts changes you did not write, too: turning a
shutdown alert into a warning also makes its input's silence warn, and both are
listed. A first deploy says so, and starts once every input has reported.

| Change | What happens |
|---|---|
| only a sequence | stored and runnable at once; the system is not redeployed |
| limits, alerts, conditions — during a run | the run carries on under the new program, its state kept |
| channels, a calculated channel's filter, what shutdown does, the running sequence or the wiring — during a run | refused until the run ends, saying what changed |

Deploying is compare-and-set against the program you reviewed: if someone else
deployed in between, yours is refused rather than overwriting theirs.

## Stop, reset, approve

| Act | Where | Does |
|---|---|---|
| **Stop** | a run's control, a dashboard's Stop, Shift+Esc anywhere | every output to its `safe=` value, the run ended, latched until a reset. A controlled stop, not an emergency stop |
| **Reset** | the header | re-arms after a shutdown or Stop. Refused while a trigger still holds, an input it reads is unknown, or an output is not confirmed safe |
| **Confirm safe and release** | the state panel | releases outputs no connector can confirm, after you check them. Never clears a latch |
| **Approve** | the state panel | accepts a system held after a restart onto a different program, with the review between the two |

Every restart comes back stopped: a machine never resumes on its own when power
returns. If what would run changed — an update recompiled it differently — the
system is held until someone approves the review.

## Undeploy, history, restore

- **Undeploy…** (from the state in the header) removes what runs, through the
  same rule as Reset.
- **Runs › Deployments** lists what this device deployed of the system, newest
  first: when, from which device, and what it replaced. **Restore** puts an
  earlier one back through the same review, as if you had edited the file.
- Every save of a file is a version; **History** opens them.

From a terminal:

```bash
phloem trellis compile proof_test.phl          # compile against this device, run its tests
phloem trellis deploy proof_test.phl           # prints the review; lands only if safety is unchanged
phloem trellis deploy proof_test.phl --yes     # apply a review that changes protection
phloem trellis status
phloem trellis stop --reason "fixture loose"
phloem trellis reset
phloem trellis deployments proof_test
phloem trellis restore 7be0d44 --yes
phloem trellis undeploy
```

- [Runs and records](https://phloem.ai/docs/trellis/runs/): Start a sequence on the deployed system
- [Test without hardware](https://phloem.ai/docs/trellis/testing/): The tests the review reports
