# People's gates

# People's gates

A gate is a line where a run waits for a person: a confirmation, a reading, an
inspection, a hold point or a signature. The system's alerts keep running while
it waits, and a shutdown ends the run and cancels the question.

```python
def receive():
    torque = ask("bolt torque", N * m, decimals=1, min=0 * N * m, max=60 * N * m)
    check("bolt torque", torque, between(22 * N * m, 26 * N * m))

    inspect("weld", views={"top": ["bead continuous", "no porosity"], "side": []},
            reference={"top": "weld-top"}, photos=1)

    step("leak check", optional=True)
    pause("Swap the fixture")
    confirm("Unit accepted", sign=True)
```

| Line | Asks | If the answer is no |
|---|---|---|
| `confirm(prompt)` | **Confirm** or **Decline** | declining aborts the run; `at_end` runs |
| `x = ask(name, what)` | a value — see below | judged by a `check` |
| `inspect(name)` | **Pass** or **Fail**, view by view when it has views | a failed inspection fails the run |
| `pause(label)` | **Resume** | nothing to decline; stopping is **Abort** |
| `confirm(prompt, sign=True)` | **Sign**: a confirmation that attests | as `confirm` |

Every gate takes `photos=N` (photos required with the answer, from a file or a
live camera) and `timeout=` (unanswered in time fails the run). Without a
timeout the run waits as long as it takes.

## What `ask` takes

```python
torque  = ask("bolt torque", N * m, decimals=1, example="24.0")
bore    = ask("bore diameter", mm, labels=["top", "middle", "bottom"], show_limits=False)
serial  = ask("serial on the label", str, pattern="[A-Z]{2}[0-9]{4}")
finish  = ask("surface finish", ["matte", "satin", "gloss"])
legible = ask("label legible", bool)
due     = ask("calibration due", date)

check("bore", bore, between(9.9 * mm, 10.1 * mm))
check("bore round", spread(bore) < 0.05 * mm)
check("finish", finish in ["matte", "satin"])
check("legible", legible)
check("calibrated for a month", due >= today(days=30))
```

| Second argument | The person enters | Entry options |
|---|---|---|
| a unit | a reading | `decimals=`, `min=`, `max=`; `count=N` for N readings, or `labels=[…]` to name each |
| `str` | text | `pattern=`: a regular expression the whole text must match |
| a list | one of the choices | — |
| `bool` | yes or no | — |
| `date` | a day, `YYYY-MM-DD` | — |

**What can be entered is not what passes.** Entry options refuse a slip — a
third decimal, a value past `max=` — and say what to fix. What passes is the
`check`'s limit. A check on counted readings passes only if every reading
does; `average(bore)`, `highest(bore)`, `lowest(bore)` and `spread(bore)`
(highest less lowest) reduce them instead. Text, a choice, yes/no and a date
compare with `==`, `!=`, `in`, `not in`, `not`, and (a date) `<`, `>=` —
against a day, or `today(days=)`: the day the run started, plus or minus days.

| Option | Shows the person |
|---|---|
| `example="24.0"` | a placeholder in the box: one value it accepts |
| `labels=["top", "middle", "bottom"]` | a name for each reading; sets the count, and the record keeps them |
| `show_limits=False` | nothing of the limits the checks will judge, so a reading is not nudged toward them. The check and the record still state them |

**Couldn't measure.** A person may answer an `ask` with **Couldn't measure** or
an `inspect` with **Can't inspect**, and a reason. It is never a pass: a check
on it records *not measured*, and a run with nothing else wrong ends
**incomplete** — the unit is neither passed nor rejected. `cannot=False`
removes the choice.

## Inspections

| Written | Shows |
|---|---|
| `inspect("seal")` | one **Pass** / **Fail** |
| `inspect("label", checks=["legible", "not torn"])` | checks to tick; it passes only with every one ticked |
| `inspect("weld", views={"top": [...], "side": []})` | one answer per view, each with its own checks and photos |
| `reference="label-ok"` or `reference={"top": "weld-top"}` | a reference picture, by name, from the project's `trellis/references/` folder (`.jpg`, `.png` or `.webp`) |
| `fail_reasons=["porosity", "undercut", "crack"]` | what a person picks from when it fails: a fail names at least one, a pass none. Reports and defect counts read them |

A missing reference picture shows as missing; it never holds the run.

Any answer — a confirmation, a reading, an inspection, resuming a pause — can
carry a note of up to 500 characters, kept beside it in the record.

## Skipping a step

A step written `step("leak check", optional=True)` offers **Skip step**, with a
note saying why (**Why it is skipped**). The record keeps the skip and the note;
the step's checks record *skipped*.

## Where an answer came from

Every answer, skip, reset and Stop records its **source**: the device and the
surface it came through (`rig-02 · Computer`, `rig-02 · CLI`, the console), with
the time. A typed name is never taken as identity. A signature is accepted only
from a person's surface — Computer, the CLI or the console — never from the
assistant or a paired device.

> **Warning:** Asking a question while an output this sequence set is away from
> its `safe=` value is a warning when the file compiles: the person may walk up
> to live hardware. Make the hardware safe first, then ask.

- [Checks](https://phloem.ai/docs/trellis/checks/): Judge an answer against a limit
- [Runs and records](https://phloem.ai/docs/trellis/runs/): Answer from the CLI; read the record
