# Quickstart & Everyday Workflow

## Your First `.plumb` File

Save the following as `demo.plumb`. It declares a speed, records its Gaussian uncertainty in one line, and checks two predictions against the same $\chi^2$ budget.

<!-- plumb:check -->
```plumb
assumption stat.gaussian_demo: StatisticalModel "Independent Gaussian measurement error."

role demo.speed: km/s "Speed of the demo carrier."

measurement obs_speed: demo.speed = 300 +- 10 km/s assuming stat.gaussian_demo

theory constant_speed {
  v: km/s
  predict demo.speed = v
}

compare check_consistent: obs_speed ~ constant_speed
  at v = 305 km/s
  accept chi2 <= 4
  expect compared
  by gaussian_ldlt

compare check_conflict: obs_speed ~ constant_speed
  at v = 350 km/s
  accept chi2 <= 4
  expect conflict declared_budget_exceeded
  by gaussian_ldlt
```

Run `plumb check` to see both verdicts.

```sh
plumb check demo.plumb
```

- `check_consistent` evaluates $\chi^2 = ((300 - 305)/10)^2 = 1/4 \le 4$ -> **`compared`**.
- `check_conflict` evaluates $\chi^2 = ((300 - 350)/10)^2 = 25 > 4$ -> **`conflict (declared_budget_exceeded)`**.
- The command exits with code `0`. Both verdicts are completed checks.
- The prediction applies to any measurement of `demo.speed`.

## Everyday CLI Workflow

### 1. Format canonically

```sh
plumb fmt demo.plumb          # rewrite in canonical Plumb style
plumb fmt --check demo.plumb  # fail (exit 2) if not formatted
```

### 2. Lock a workspace (`plumb.lock`)

Whenever your workspace has `.plumb` files and/or external JSON data files (`artifact ... from "..."`), generate or verify `plumb.lock`:

```sh
plumb lock my_project          # creates or updates my_project/plumb.lock
plumb lock --check my_project  # verifies exact-byte SHA-256 of every module & artifact
```

If you edit a `.plumb` module or a data file, `plumb lock --check` fails with exit code `2` until you deliberately re-run `plumb lock` (which bumps the module's revision and records `supersedes`).

### 3. Check and emit an immutable receipt

```sh
plumb check my_project/analysis.plumb --out runs/attempt-1
```

This writes two files atomically inside `runs/attempt-1/`:
- `receipt.json` (`plumb.receipt/v1`) — full machine-readable audit record with digests, verdicts, witnesses, and assumption ledgers.
- `report.md` — human-readable Markdown summary.

Plumb **refuses to overwrite** an existing attempt directory (exit code `2`), preserving append-only audit history.

### 4. Inspect transitive assumptions (`plumb trace`)

```sh
plumb trace runs/attempt-1/receipt.json
plumb trace runs/attempt-1/receipt.json my_compare_name
```

`plumb trace` prints every assumption and active bias stage that contributed to a finding — transitively across all imported modules and `derived from` chains.

### 5. Compare two receipts safely (`plumb compare`)

To compare two candidate models against the exact same dataset, put your shared data and observables in `data_module.plumb`, then create two model modules (`model_a.plumb`, `model_b.plumb`) that `import data_module` and define the same `compare` check name(s) targeting the same observable(s). Importing `data_module` brings in its declarations without re-running its own checks.

```sh
plumb check my_project/model_a.plumb --out runs/model-a
plumb check my_project/model_b.plumb --out runs/model-b
plumb compare runs/model-a/receipt.json runs/model-b/receipt.json
```

`plumb compare` allows the candidate predictions (`prediction_sha256`) to differ while refusing if the two receipts differ in axis order, observation digest, covariance digest, conditioning, metric, units, active bias stack, or check set.

### 6. Validate an entire locked project (`plumb validate`)

```sh
plumb validate .           # validate the locked project in the current directory
plumb validate my_project  # verifies plumb.lock, strict JSON schemas, every module, and every `expect`
```

### 7. Explore docs, `std` modules, checkers, and error codes

```sh
plumb doc                       # built-in user guide topics
plumb doc language              # syntax reference
plumb doc std.astronomy.ladder.cepheids  # inspect any built-in std module source verbatim
plumb doc --search "bias"       # search built-in docs
plumb list checkers             # list all built-in `by <method>` verification checkers
plumb explain P0312             # explain a specific diagnostic code
```
