# Verdicts, Receipts & CLI Reference

Plumb reports a disposition for each claim, comparison, and open scope entry.

## Complete Table of Dispositions & `expect` Syntax

You can assert the expected disposition right inside a `claim` or `compare` with `expect ...` (checked automatically by `plumb validate`):

| Disposition / Outcome | `expect` syntax | Meaning |
| --- | --- | --- |
| `Evaluated(Compared)` | `expect compared` | Empirical comparison succeeded and stayed within the acceptance budget. |
| `Evaluated(ConditionalResult)` | `expect conditional_result` | Theoretical or mathematical `claim` certified under its declared assumptions. |
| `Evaluated(Conflict)` | `expect conflict exact_witness`<br>`expect conflict certified_enclosure`<br>`expect conflict declared_budget_exceeded` | Proven contradiction (exact point witness, certified enclosure across the full domain/box, or fixed-point budget exceeded). |
| `Evaluated(NonIdentifiable)` | `expect non_identifiable` | Exact structural degeneracy / unbounded direction along a nonzero response. |
| `Evaluated(SystematicsLimited)` | `expect systematics_limited [from <id>, ...]` | Deterministic bounded systematic box straddles the acceptance budget. |
| `Evaluated(Unresolved)` | `expect unresolved bound_too_loose`<br>`expect unresolved optimizer_inconclusive` | Checker could not certify pass or conflict within its precision/node budget. |
| `Blocked` | `expect blocked <reason> [from <id>]` | Scientific prerequisite failed (see refusal reasons below). |
| `OutOfScope` | `expect out_of_scope out_of_claimed_scope`<br>`expect out_of_scope regime_not_applicable` | Reserved for explicit scope exclusions. Current checks do not emit this disposition. |
| `Unassessed` | `expect unassessed no_catalogue_entry`<br>`expect unassessed no_applicable_checker` | Declared `open` or no applicable checker exists. |

The receipt format also reserves `unresolved timeout` and `unresolved insufficient_power` for future checkers.

### `RefusalReason` Values (for `expect blocked <reason>`)

| Reason | When Plumb emits it |
| --- | --- |
| `missing_bridge` | No prediction of the theory (own or inherited) targets an observed role and no chain of at most six rules reaches it, or the named prediction does not target the role. |
| `ambiguous_bridge` | Two predictions of the same theory target an observed role, or two rules both reach it. Name one prediction as the model, or remove the duplicate route. |
| `missing_asset` | Referenced artifact is missing bytes or not pinned in the lockfile. |
| `missing_assumption` | Required statistical/calibration premise is absent. |
| `backend_unavailable` | A Lean obligation was reached on a host without a capable Lean/Lake backend (or with `PLUMB_LEAN_DISABLE=1`). |
| `domain_violation` | Expression undefined on domain (e.g. division by zero, `log` of non-positive), empty quantifier box, or `valid when` premise failed / could not be certified. |
| `incompatible_conditioning` | Observable's `conditioned on ... requires ...` assumption is not granted by the theory or by a prediction or rule the comparison evaluates (an inherited prediction stops granting once the child theory replaces something it reads). |
| `unknown_dataset_dependence` | Two combined observables share a data leaf (same file SHA-256 + column or shared posterior origin), share a hidden `includes` covariance nuisance, or multiple alternative models share one observation (`joint(...)`). |
| `unspecified_uncertainty` | A measurement or inference supplies a numerical value to a statistical comparison without a declared uncertainty model. The finding names the source. |
| `axis_mismatch` | Row labels, row order, lengths, physical dimensions, or axis manifest digests do not match. |
| `non_positive_definite_covariance` | Covariance matrix fails exact $LDL^T$ SPD check or has non-positive $\sigma$. |
| `unconsumed_bias` | Outcome truncation (`select truncate observed`), outcome-dependent covariate mask, unconsumed bounded systematic under `gaussian_ldlt`, or post-selected Bell bound below Larsson threshold. |
| `blocked_by_upstream` | An upstream check referenced via `scope ... after` or `derived from` did not pass. |
| `circular_calibration` | The model side reads a data leaf that is also measured on the observed side. |

## Receipt Format (`plumb.receipt/v1`)

Run `plumb check target.plumb --out runs/attempt-1` to write `receipt.json` and `report.md` in the attempt directory.

- The `envelope` records the attempt ID, optional `predecessor_attempt_id`, time, Plumb version, target, execution state, and evidence digests. Passing `--parent <receipt.json>` on `plumb check` or `plumb audit` verifies the parent receipt's digests, completed execution state, and matching scope before linking `predecessor_attempt_id` (exiting `2` if tampered, missing, incomplete, or from a different scope). When `--parent` is passed with `--json` (even without `--out`), stdout emits the full `Receipt` JSON so the attempt chain stays intact.
- The `body` records coverage counts, findings, expectation checks, and (for audits) `audit_summary`. Each finding gives its disposition, assumptions, active biases, checker and relevant measures. The `bridge_id` field identifies the prediction or rule chain when applicable.

## Auditing a candidate theory

`plumb audit candidate.plumb --theory my_theory --scope std.cosmology.expansion` runs the frozen scope checks against the candidate's parameter boxes. The scope supplies observations, budgets, and policies (`baseline`, `limit`, `alpha`, `allow`). The candidate supplies assumptions (`*.cand.*`), theories, predictions and claims. An audit records candidate assertions in the assumption ledger. A conditioned observation needs a referee premise granted by the trusted theory, by an explicitly `allow`ed candidate grant, by a library `MathematicalPremise` discharged by a passing library claim, or by the predictions and rules that produce its own rows. Declare `audit my_theory against std.cosmology.expansion` in the module to run the same scope with `plumb check`.

Every audit receipt and Markdown report includes a machine-readable `audit_summary`:
- `status` — closed-enum overall audit verdict: `contradicted`, `vacuous`, `uncovered`, `unresolved`, `systematics_limited`, `accommodation`, or `not_contradicted`.
- `next_action` — closed-enum next step for automated loops: `retire`, `reduce_freedom`, `provide_bridge`, `escalate_tier`, `supply_witness`, `tighten_or_justify`, or `hold_for_promotion`.
- `complexity` — `{ free_parameters, numeric_literals, candidate_assumptions, dropped_assumptions, price }`:
  - `free_parameters` counts non-degenerate parameter boxes added beyond `baseline` (when the candidate extends `baseline`), or all free parameters otherwise; physical box endpoints are not double-charged as literals, while degenerate point-pinned boxes `[v, v]` are priced once.
  - `numeric_literals` evaluates pure candidate constant subexpressions (including arithmetic chains, unit ratios such as `1 Mpc / 1 km`, non-zero dimensionful literals, and 0-argument candidate `def`s) and charges every value outside the structural dimensionless set `{0, ±1, ±2, ±1/2}` (and exact `0` in any unit).
  - `dropped_assumptions` counts baseline grants absent from the candidate; `price = free_parameters + numeric_literals + dropped_assumptions`.
- `exceeded_limits` — any `limit price <= N` or `limit free_parameters <= M` policies breached by the candidate (classifying the audit as `vacuous` / `reduce_freedom`).
- `unused_parameters` — candidate-added free parameters that vanish after algebraic simplification across the planned scope blocks (catching cancelled knobs such as `0 * fudge` or `fudge - fudge`). An added parameter absent from this scope can be measured by another frozen scope that the audit loads. Inherited reference parameters are excluded. When all blocks are covered, unused parameters classify the audit as `vacuous` / `reduce_freedom`; when blocks are `Blocked`, `uncovered` (`provide_bridge` / `escalate_tier`) takes precedence.
- `unsatisfied_conditioning` — conditioning requirements that still block a scope block after tier routing (below). They classify the audit as `uncovered` / `escalate_tier`.
- `accommodation` — the predictive-surplus gate. When the scope declares a `baseline` and the candidate would otherwise be `not_contradicted`, Plumb evaluates the baseline against the same blocks and collects the observations of every certified conflict core. A parameter the candidate adds beyond the baseline that only conflict-core observations read (after algebraic simplification) explains nothing outside the conflict it absorbs. The audit is then classified `accommodation` / `reduce_freedom`, and `accommodation` lists the offending `parameters`, the baseline `conflict_core` and the `relabeled_assumptions` of the core observations the parameters act on. A parameter that also moves an observation outside the core keeps `not_contradicted`. Without a baseline, or when the baseline does not conflict, the gate does not apply.

### Tier routing with `supersedes_for`

A candidate that drops an observation's conditioning premise is never excused from that observation. If the referee library declares a deeper-tier observation that supersedes it, the scope block faces that observation instead:

<!-- plumb:check -->
```plumb
assumption ontology.lcdm_early : PhysicalOntology
role cosmo.rd : Dimensionless
role cosmo.theta : Dimensionless

inference rd_planck : cosmo.rd = 147 +- 1 {
  conditioned on lcdm_fit requires ontology.lcdm_early
}

measurement cmb_early : cosmo.theta = 1.0411 +- 0.0003 {
  supersedes_for rd_planck when not ontology.lcdm_early
}
```

When a candidate that does not grant `ontology.lcdm_early` reaches a block checking `rd_planck`, the block is evaluated against `cmb_early`. The candidate then needs a prediction for `cosmo.theta`, and it can pass or conflict there. The finding records the substitution in its `supersession` measure, for example `rd_planck -> cmb_early when not ontology.lcdm_early`, and the global joint uses the substituted observations. Only observations in the modules the scope's own module imports, directly or transitively, can supersede. A candidate cannot declare observations (`P0342`), so it cannot choose its own deeper tier. When no observation supersedes the summary, the block stays `blocked incompatible_conditioning`, and the audit is `uncovered` / `escalate_tier` with the requirement in `unsatisfied_conditioning`.

The `global_joint` finding tests the covered blocks at one shared parameter assignment and retains each block's cuts. Its `joint.blocks` measure identifies the included blocks. If some blocks share a data source, `joint.excluded` explains each exclusion (and keeps `audit_summary.status` at `uncovered` / `escalate_tier` rather than claiming full joint coverage). If every pair overlaps, the joint finding reports the dependence. A successful check reports `param.<name>.lo`, `param.<name>.hi`, and `param.<name>.unit` in the parameter's declared unit.

Use `--witness point.json` to propose a point such as `{"H0":"70.02 km/s/Mpc","Omega_m":"0.285"}`. Supply all free parameters used by the tested blocks. The receipt records the outcome for each block, including missing predictions, missing conditioning grants and explicitly open phenomena.

## External MCMC & Fitter Parity (`plumb parity`)

Before launching an external MCMC sampler (Cobaya, emcee, NumPyro, Stan) or numerical optimizer, export Plumb's exact per-block $\chi^2$ and Gaussian log-likelihood (`-0.5 * chi2`, excluding the normalization constant) at a few fixed parameter points (including an off-optimum point with nonzero shared nuisance response):

```sh
plumb parity candidate.plumb --theory my_theory --scope std.cosmology.expansion --points points.json --json
```

`points.json` accepts either a single JSON parameter map (`{"H0": "70 km/s/Mpc", "Omega_m": "0.3"}`) or an array of maps. Every point must specify all declared parameters of the theory as quoted quantity strings and stay inside each parameter's declared `[lo, hi]` box (missing or out-of-box parameters are refused with exit code `2`). Unlike `plumb audit --witness`, `plumb parity` evaluates **strictly at each fixed point** without searching parameter boxes, so external scripts can confirm zero unit, sign, axis-order, or shared-nuisance drift before running chains.

## Comparing Two Receipts (`plumb compare`)

`plumb compare left/receipt.json right/receipt.json` checks the union of all check IDs across both receipts (exiting `0` with per-check `COMPARABLE` or `REFUSED` lines, or structured JSON with `--json`). A check is `Comparable` when both receipts evaluated it to `Compared` on the exact same dataset (matching `axis_sha256`, `observation_sha256`, `covariance_sha256`, `conditioning`, `metric`, `unit`, and `active_biases`), while allowing candidate predictions (`prediction_sha256`) to differ.

Typical 2-model pattern:
1. Put shared artifacts and observables in `data_module.plumb`.
2. Create `model_a.plumb` and `model_b.plumb`, each doing `import data_module` and declaring `compare main_fit: my_obs ~ ...` with the same check name `main_fit`.
3. Run `plumb check model_a.plumb --out runs/a`, `plumb check model_b.plumb --out runs/b`, and `plumb compare runs/a/receipt.json runs/b/receipt.json`.

## CLI Reference & Exit Codes

All commands support `--json` for machine-readable output.

| Command | Purpose |
| --- | --- |
| `plumb check <file.plumb> [--out <dir>] [--parent <receipt.json>] [--std <dir>]` | Check a `.plumb` module, optionally chain to a verified parent receipt, and write an atomic receipt + report. |
| `plumb audit <file.plumb> --theory <name> --scope <name> [--witness <file.json>] [--parent <receipt.json>] [--out <dir>] [--std <dir>]` | Test a theory against a frozen library scope and emit `audit_summary` (`status`, `next_action`, `complexity`). |
| `plumb parity <file.plumb> --theory <name> --scope <name> --points <file.json> [--std <dir>]` | Export exact per-block $\chi^2$ and Gaussian log-likelihood at fixed parameter points for external MCMC/fitter parity checks. |
| `plumb fmt <file.plumb>... [--check]` | Format one or more `.plumb` modules into canonical layout. |
| `plumb lock [path] [--check]` | Generate or verify `plumb.lock` (or `std/lock.json` for `std`), automatically pinning referenced `.lean` proofs and local Lake inputs. |
| `plumb validate [path]` | Verify lockfiles, strict JSON schemas, every module, and every `expect`. |
| `plumb trace <receipt.json> [check]` | Print the full transitive assumption, bias, and discharged-premise/Lean-axiom chain for a receipt. |
| `plumb compare <left.json> <right.json>` | Run the comparability gate across two receipts. |
| `plumb show <receipt.json \| checker \| std.<module>>` | Summarize a receipt, describe a checker, or print a `std` module verbatim. |
| `plumb list checkers` | List all 19 built-in `by <method>` verification checkers. |
| `plumb explain <CODE>` | Explain a diagnostic code (e.g., `plumb explain P0315`). |
| `plumb lean goal <file.plumb> [--claim <name>]` | Print the Plumb-generated Lean 4 theorem target for the selected claim. |
| `plumb lean init <file.plumb> --claim <name> [--force]` | Scaffold a sidecar `.lean` proof file for a `by lean "..."` claim. |
| `plumb doctor [--lean]` | Show Plumb’s version. Use `--lean` for backend and cache diagnostics. The JSON report includes those diagnostics with either spelling. |
| `plumb doc [topic \| std.<module> \| --all \| --search <q> \| --llms]` | Read, search, or export this built-in user guide or any `std` module. |

### Exit Codes

- **`0`** — Completed cleanly. Note that scientific `Conflict`, `Blocked`, `NonIdentifiable`, `SystematicsLimited`, and `Unresolved` dispositions are valid audit outcomes and exit **`0`**!
- **`2`** — Preflight or input error: bad CLI usage, syntax/type/cycle diagnostic, malformed JSON or duplicate JSON key, lockfile or SHA-256 mismatch, missing file, failed `expect` during `validate`, or refusing to overwrite an existing `--out` attempt directory.
- **`3`** — Internal or I/O execution error.

Dense covariance checks can reuse an authenticated positive-definiteness certificate in your private cache. The attempt envelope lists reused certificate keys in `certificate_memo_hits`. The checker recomputes residuals and test statistics on every attempt. Use `--no-cache` with `check`, `audit`, or `parity` to reproduce a cold check. Set `PLUMB_CACHE_DIR` to choose an owner-only cache directory outside the workspace.

A successful linear fit writes its emitted views under `body.emitted`. Each
view includes named axes with roles and units, certified mean and statistical
covariance intervals, input digests, assumptions, and the minimum chi-square
of the upstream fit. A comparison uses one joint view when it needs multiple
coordinates from the same fit. Two separate projections share the fit's data
identity and would count the same evidence twice.

A factor produced using a pin also carries the upstream data identity and
assumption ledger. Its downstream chi-square measures the agreement of the
new data with the pinned estimates.
