Metadata-Version: 2.4
Name: trugs-runner
Version: 0.1.2
Summary: The TRUGS runner offers and records actions against a fixed graph.
License: Apache-2.0
Project-URL: Homepage, https://trugs.ai
Project-URL: Source, https://github.com/TRUGS-LLC/TRUGS-RUNNER
Project-URL: Issues, https://github.com/TRUGS-LLC/TRUGS-RUNNER/issues
Project-URL: Specification, https://github.com/TRUGS-LLC/TRUGS
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: jsonschema<5,>=4.19
Requires-Dist: trugs-tools<3.0.0,>=2.2.0
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: ruff==0.16.5; extra == "dev"
Requires-Dist: trugs-tools==2.2.0; extra == "dev"
Dynamic: license-file

# TRUGS runner

[![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/LICENSE)
[![check](https://github.com/TRUGS-LLC/TRUGS-RUNNER/actions/workflows/check.yml/badge.svg)](https://github.com/TRUGS-LLC/TRUGS-RUNNER/actions/workflows/check.yml)
[![run](https://github.com/TRUGS-LLC/TRUGS-RUNNER/actions/workflows/run.yml/badge.svg)](https://github.com/TRUGS-LLC/TRUGS-RUNNER/actions/workflows/run.yml)

TRUGS runner is a Python library and command-line tool for running an agent along a path that a person has written down in advance. Here an agent means an AI model, or an ordinary program, doing work on someone's behalf. The path is a graph called a rail. It lists every step the agent may take, which programs each step may use, and what evidence must exist before the run moves on. The runner refuses anything the rail does not allow and keeps a record of every step. A rail can end with a deterministic check, called the oracle, which decides whether the conditions stated at the start now hold.

It is meant for developers who hand work to AI agents or to scripts and need more than the agent's own word that the work was done. The runner gives them three things: a fixed path that can be reviewed before the run, a record of what actually happened, and an exact check at the end.

An agent can go wrong in two ways. First, it can leave the path: it can invent a step, skip one, call something it was not given, or simply claim to be finished. The runner prevents this by refusing every action the rail does not permit. Second, it can take a permitted step that is simply wrong. The runner cannot prevent that. The walkthrough shows how an oracle can catch it at the end. After each step, a gate checks that the required evidence exists, because a statement that something was done is not evidence that it was. The runner validates and captures the rail once, when a run starts, and nothing in the run can change it.

Each special term is explained in plain words under [Words used here](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/README.md#words-used-here).

## Status

This is version 0.1.2, published on PyPI as `trugs-runner`. It needs Python 3.11 or later.

The project's automated checks run inside pinned Linux containers (linux/amd64) on Python 3.11, 3.13 and 3.14. They check formatting, lint, tests, shipped graphs and compliance. The "run" workflow checks the walkthrough on Python 3.11 with both the correct and the wrong worker.

The runner uses Unix file locking and the gateway uses Unix sockets. The project's checks cover Linux. Windows is not supported; these checks do not establish macOS support.

Questions and bug reports go to the [issue tracker](https://github.com/TRUGS-LLC/TRUGS-RUNNER/issues). No response time is promised.

## Where this fits in TRUGS

The [TRUGS specification](https://github.com/TRUGS-LLC/TRUGS) defines the graph format used by rails. [TRUGS-TOOLS](https://github.com/TRUGS-LLC/TRUGS-TOOLS) provides the `trug` command for graph validation and TRL, the specification's controlled English. It is published as `trugs-tools`. Installing the runner installs it too. The runner uses its digest functions to identify snapshots and record entries.

This repository runs a TRUG as a fixed rail. Use it when you want a graph to govern a run and record its steps.

## Words used here

- **Agent.** An AI model, or any program, doing work on someone's behalf.
- **TRUG.** A graph stored as a JSON file in the format that the TRUGS specification defines. It has a list of nodes, which stand for things such as people, programs and steps. It also has a list of edges, which are named relations between nodes, such as `MAY` ("may use") or `ROUTES` ("leads to").
- **Rail.** A TRUG that a person writes and approves in advance to govern a run. It declares the steps, which programs each step may use, who may use them, and the evidence needed to move on. The documents also call a rail an *executable TRUG*.
- **Actor.** The party a rail serves, named as the `actor` of the graph's root node. The runner checks every request to run a program against what the rail allows that actor.
- **Permission edges.** Edges named `SHALL`, `MAY` and `SHALL_NOT`, which say what an actor must, may or must not do. The rail refuses its actor any program that no `SHALL` or `MAY` edge grants.
- **Capability.** A program the rail names by its path, which the runner may start at a step.
- **Worker.** A program or AI agent asked to do work at a step. In the walkthrough, it proposes a choice and the runner runs the program that choice names.
- **Receipt.** In the walkthrough, a small file written by the program a choice named, recording what it did. Its gates and oracle read these files as evidence.
- **Gate.** A check after a step that decides whether the required evidence exists and which route the run takes next.
- **Oracle.** A deterministic program, run at the end, that checks conditions written down in advance and returns a verdict. "Deterministic" means it gives the same answer every time for the same evidence. It uses no judgment and no AI model.
- **Pin.** To record a fingerprint (a SHA-256 digest) of each file a rail names, inside the rail itself. If a file changes afterwards, the rail is refused until someone pins it again.
- **Snapshot.** The copy of a rail and its pinned files that the runner takes when a run starts. The run uses only this copy.
- **Record and head.** Each run keeps a record in its run directory. The record is a chain of entries, each linked to the one before it by its digest. The head is a small JSON object that names the latest entry by its run id, record version, sequence number and digest. To continue a run you must present its current head, and the runner refuses an out-of-date head.
- **Cursor.** The node the run is currently at.
- **Person pause.** A point at which the rail stops and waits for a person's answer, given as a JSON file.

## Install

You need Python 3.11 or later. The project's own checks run on Linux.

To use the runner as a library, install the published package:

```bash
python3 -m pip install trugs-runner
```

The package installs two Python modules: `executable_trug`, the engine and its command line, which you run as
`python3 -m executable_trug`, and `trugs_runner`, the library for building rails in Python. It also installs
`jsonschema` and `trugs-tools`.

The walkthrough below uses the examples in this repository, which are not part of the package. To follow it, clone
the repository and install it into a new virtual environment:

```bash
git clone https://github.com/TRUGS-LLC/TRUGS-RUNNER.git
cd TRUGS-RUNNER
python3 -m venv .venv
. .venv/bin/activate
python3 -m pip install -e .
python3 -m executable_trug --help
```

The last command prints the command's help, beginning `usage: executable-trug`.

For development, use `python3 -m pip install -e ".[dev]"` to add pytest and the pinned checking tools. The runner requires `trugs-tools>=2.2.0,<3.0.0`; the development extra pins it to 2.2.0.

## Run it

The first example classifies the letters of a word. Its rail is [letter-classification.trug.json](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/examples/letter-classification/letter-classification.trug.json). From the root of your clone, run:

```sh
export PYTHONPATH=src
G=examples/letter-classification/letter-classification.trug.json
W="$PWD/examples/letter-classification/workers/deterministic_worker.py"

python3 -m executable_trug pin $G                      # record what each program is
python3 examples/letter-classification/driver.py --worker-command "python3 $W" \
  --run-dir /tmp/run --word Strawberry --head-file letter-head.json
```

The first line tells Python to use the code in this checkout. After an editable install it changes nothing, but it does no harm. `pin` writes the fingerprint of every file the rail names into the rail. In a fresh clone the fingerprints already match, so the file does not change.

The driver is a small example program. It calls the runner's Python interface to start the run, and then passes each returned head forward until the run stops. It runs the rail over the word "Strawberry", with one worker call per character. The worker here is a small Python script that stands in for an AI agent. It compares each character with "r" and answers `record_r` or `record_not_r`.

**What you should see.** The driver prints one long line of JSON describing where the run ended, and exits with status 0 (check this with `echo $?`). In that line, `"cursor": "passed"` means the run reached the rail's success stage, and `"phase": "terminal"` means the run has finished.

The run writes several things:

- its record, in `/tmp/run`;
- its latest head, in `letter-head.json` in the current directory;
- a snapshot of the rail, in `~/.local/share/executable-trug/snapshots`, or in `$XDG_DATA_HOME/executable-trug/snapshots` when that variable is set to an absolute path.

A run directory can be used only once. If you run the same command again, it stops with `run_already_exists` and exit status 2, so choose a new path for a new run. Snapshots are kept until you remove them; [COMMANDS.md](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/COMMANDS.md#local-records-and-snapshots) explains how to remove them safely.

The worker path must be absolute, because the runner starts programs from inside its captured snapshot and not from your current directory. You pass the worker command to the driver separately; it is not one of the files the rail pins. The worker needs no tools and no file access. It reads its prompt on standard input and answers with one line, such as `CHOICE: record_r`.

You can supply a different worker the same way, with `--worker-command`. Without a worker, nothing can be classified. The dispatch fails, and the run pauses at the rail's `decide_recovery` step for a person to decide. To answer, continue the run with its exact saved head and pass `--person-input-file`. The file contains `{"source":"person","value":"retry"}` or `{"source":"person","value":"give_up"}`.

### What just happened

For each character, the rail ran this cycle:

1. a capability read the next character;
2. the worker was asked for one choice, `record_r` or `record_not_r`;
3. the runner ran the program that choice named, and that program wrote a receipt;
4. a gate confirmed that the receipt existed;
5. the index advanced, and the cycle repeated.

When the word ran out, the oracle checked every receipt against the rule the task stated: an "r" in either case must be recorded as `record_r`, and every other character as `record_not_r`. It then decided whether the run had met that rule.

The worker never wrote a receipt itself. It only stated a choice, and the rail performed the act. The evidence was therefore written by a program that the worker was never given a path to.

## The part that matters

Now run the example again with a worker that always answers `record_r`, whatever the character:

```sh
python3 examples/letter-classification/driver.py --worker-command "python3 $W --always-record-r" \
  --run-dir /tmp/wrong --word Strawberry
```

The run takes the same number of steps. Every receipt is written and every gate passes. But the driver exits with status 21, and its JSON line shows `"cursor": "failed"`: the oracle caught the mistake.

The oracle reports two findings separately. The first is integrity: there must be exactly one well-formed receipt per character, belonging to this run and this graph. Integrity passes here. The second is correctness: each receipt must name the program that its character called for. Correctness fails here for every character that is not an "r".

That split is the design. The gate after each step asks only whether the required thing happened, and that is cheap enough to check at every step. Whether the conditions the task stated now hold is a separate question. Something exact answers it once, at the end.

The oracle is never asked whether the work was *good*. Correctness in that sense is a judgment about intent, and anything that forms judgments is an opinion rather than an instrument. The oracle checks *completion* instead: whether conditions written down in advance now hold.

It also only checks conditions it can decide **without running what the agent produced**. Suppose the oracle had to run code the agent wrote. That code would then control every input to the verdict, and so it could decide its own result. This oracle reads receipts and executes nothing the agent wrote. [CONCEPTS.md](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/CONCEPTS.md) explains the reasoning.

## Examples and pattern rails

The [examples index](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/examples/README.md) lists four examples and four pattern rails. Each one has its own README that opens by saying what it shows.

The examples are complete scenarios with their own driver programs:

- [Letter classification](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/examples/letter-classification/) is the walkthrough above.
- [FAQ answer](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/examples/faq-answer/) has a worker choose an answer from a separate, pinned FAQ graph. The rail refuses a choice that is not in the FAQ, and the oracle fails an answer that is permitted but wrong.
- [Development orchestration](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/examples/development-orchestration/) takes seven software-development roles: discussion, recommendation, proposal, feasibility, specification, code and audit. Each role is a TRUG you can run on its own, and the example composes all seven into one lifecycle. Even when the audit role accepts the work, the lifecycle ends with a person's decision rather than accepting automatically. The example is not tied to any model provider: it uses prepared fixture responses and calls no AI model.
- [Development ladder](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/examples/development-ladder/) runs up to six rounds. In each round a prepared code candidate is checked against 18 fixed tests for a small two-player game called ThreeToe. After three rejections a feasibility step runs, and after six a person decides.

The pattern rails are small, general-purpose rails built with the authoring library:

- [Approve and record](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/patterns/approve-and-record/) is for work where a person must approve before anything is recorded. A person's exact acceptance governs the recording step, and a refusal withholds it. It also shows a custom node next to library nodes.
- [Router](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/patterns/router/) has a program worker propose a route. The runner checks the route against a captured list of choices before running the declared tool.
- [Bounded tool loop](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/patterns/bounded-tool-loop/) alternates between a program worker and a tool, up to a declared number of returns, and then asks a person to choose.
- [Evaluator-optimizer](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/patterns/evaluator-optimizer/) has an AI model write a draft for a person to review. The person's recorded feedback goes into the next draft, and at the round limit the run reaches a summary and a person pause.

The pattern scripts import the authoring library. Run them from an environment where the package is installed, or from the repository root with `PYTHONPATH=src`.

## Make your own

To build a rail in Python from library nodes and your own custom nodes, see [Author a rail](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/src/trugs_runner/README.md). The `create` subcommand also makes a small starting rail; see the [Reference](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/README.md#reference) section.

To write a rail by hand, use [the letter-classification example](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/examples/letter-classification/README.md) as a guide to the file layout. In short:

1. Write the graph using the node types and edge relations of the TRUGS vocabulary (its nouns and prepositions).
2. Give every node the complete list of outcomes it can produce.
3. Name the actor that drives the run as the `actor` of the graph's root node, and give it a `MAY` edge to each capability it may invoke.
4. Install the programs the graph names, and `pin` them.
5. Write an oracle.

Then check the rail with `python3 -m executable_trug check` and `trug validate`.

If you cannot write a deterministic oracle for a step, the task has not yet been stated precisely enough. That is a fact about the specification, not about the step. If you can only write an oracle by running what the agent produced, read [CONCEPTS.md](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/CONCEPTS.md) before you rely on its verdict.

## Scope

This release runs rails that stay fixed for the whole run. It does not include self-modifying TRUGS, meaning graphs that change their own structure while they run. It is also not a sandbox; the next section explains what it does and does not protect against.

## Honest limits

The TRUGS runner offers and records; it does not confine. It decides which programs may run and keeps a record of what happened, but it does not isolate the programs it starts. When the pattern and authoring documents call it "the open runner", this is what they mean.

- **It is not a security boundary, and it does not contain the worker.** A capability starts the worker as an ordinary process under the same user account as the runner. The worker is kept away from the oracle, the receipts and the result programs only because it is never told where they are; nothing isolates them. A worker that goes looking can find them. Anything a worker does before it states its choice has already happened, even if the rail then refuses the choice. If you run a worker you do not trust, contain it yourself, for example in a virtual machine. A fully locked-down system is a separate layer from this one. A rail is a step up from instructions that a model may ignore, but it is not a sandbox.
- **It measures no model.** The bundled worker decides by comparison, not by judgment. Nothing measured with it says anything about an AI model.
- **The graph never rewrites itself.** A rail stays fixed for the whole run; see [Scope](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/README.md#scope).
- **The run directory is trusted.** Someone who can rewrite the files in a run directory, and the head you kept, can rewrite the run's history consistently. The record also does not prove who acted, so keep run directories in storage you trust. Full verification reads check the whole chain, while the ordinary reads during a run check less. [How much a read verifies](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/README.md#how-much-a-read-verifies) gives the detail.
- **The actor is declared, not authenticated.** The rail checks every request against the actor named in the graph's root, but it cannot tell which process is actually calling. Permission edges that name any other actor are not checked while the run is going, because no other actor ever makes requests of the rail. That includes the worker's `SHALL_NOT` edges.
- **Definitions are captured at start.** When a run starts, the runner validates the rail and captures it together with its pinned files. Before each step, it compares the captured files with their recorded fingerprints and stops with a report if they differ. Editing the installed files affects only new runs. The snapshot store is trusted local storage, not a way to confine workers.
- **A refusal never chooses a route.** When a permission is refused, the run stays where it was. Other ordinary refusals during execution halt the run for a person. Editing installed files cannot change the definitions a run is using.
- **A stopped run keeps its reason, its position and any unresolved action.** When recovery is offered, `continue` accepts an explicit choice to retry or abandon. That choice must come with the retained head and your confirmation that the old processes have stopped.
- **The authoring `run` command stops at a person pause.** It passes each returned head along through start and continue, and then reports the pause. The person's answer has to be submitted explicitly.
- **In this release, text from a model can move a run forward in only three ways.** It can go to a person inside the rail's declared discussion form. It can pass an exact check of the whole result against input bound independently of the model. Otherwise it is marked `unverified`.
- **The pattern rails stay inside that boundary.** The router and the bounded tool loop use program workers, and in the evaluator-optimizer a person reviews the model's drafts. None of them shows a model evaluating another model, tool calls through the model gateway, child rails (rails that start other rails) or fan-out (several at once).
- **Compliance uses the pinned checker.** `make check` includes `trug compliance`, which compares the repository against the stored baseline in `.github/compliance-baseline.json`. To compare results, use the pinned checking environment described under [Verify](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/README.md#verify).

## What the rail refuses, and what it does not control

The rail controls what *the rail* does with an actor's request and a worker's choice. It does not control what a worker *program* does while it runs.

Each time the runner starts a program, it works in two phases. First it records an *intent*, which names the step, the program and the attempt number. Then the program runs, and afterwards the runner records an *observation* of its result.

Some requests are refused **before anything is started**, so nothing runs:

- A request the graph does not permit the run's actor, either because a `SHALL_NOT` edge forbids it or because no `SHALL` or `MAY` edge allows it. The runner records the refusal, and the run's position does not change.
- A request for which the step budget has no room left. The run halts.

Some results are refused **after the program has run, but before an observation is recorded**. This happens to a result that breaks the step protocol or fails the state checks, for example by setting a state key the rail does not declare. Nothing from that result is committed, neither a state change nor an observation, and the cursor does not move. The intent and the evidence of the refusal remain, and the run halts at that node.

A **route-gate halt** happens later, after the observation and the accepted state have been committed. If the gate cannot select a permitted route, the run keeps the observation and the state and records a halt, without moving the cursor.

In both of the last two cases, the program and any worker it started have already acted. Effects outside the rail are not undone. See [Actions §12](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/SPEC/SPEC-261005-actions-gates-and-step-protocol.md).

Refusals during execution report a reason and the retained head. Recorded refusals are appended to the run's `record/entries/` folder. Errors in the command or its keywords are reported before any work starts. State changes refused before an observation, and refused cursor moves, are never committed. The diagnostics and refusal evidence they refer to stay available in the run's private `content/objects/` folder.

If a run stops between an intent and its observation, nobody knows whether the program acted. The rail therefore never starts that program again on its own, and `continue` reports the unresolved invocation for a person. Actions marked as safe to repeat reuse the request already recorded. For anything else, retrying or abandoning is an explicit choice made when continuing.

Admission is the set of checks the runner applies before it accepts a rail. Admission also refuses two further things. It refuses a capability or data path that is absolute, or that leads outside the install folder through `..` or a symbolic link. It also refuses a graph in which one actor holds conflicting permissions toward the same capability, such as both `SHALL_NOT` and `MAY`.

## Choosing from a second TRUG

A rail can name another TRUG as pinned data, such as a set of FAQ entries, and require a worker's choice to be one of that TRUG's nodes. The rail declares this with two parts:

- a `DATA` node, which gives the data TRUG's `path` and `digest`;
- a `SUBJECT_TO` edge, which names the state key it constrains and says what counts as an acceptable node. That is the property the node must carry (`requires`) and, optionally, its node type.

A value proposed for that state key must be the id of such a node in the data TRUG. Otherwise the rail refuses the value, commits none of it and halts the run. If the data TRUG changes, the rail is refused until it is pinned again. [The FAQ example](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/examples/faq-answer/) shows one such choice: a question answered from an FAQ TRUG.

These gates fail closed. Admission refuses a malformed gate, or any other kind of edge to a `DATA` node, rather than ignoring it.

## When a run is interrupted

A run that stops part way, because the driver was killed or the machine restarted, keeps everything it had already committed to its record. The driver saves the head file only when it returns, so after an interruption `letter-head.json` may be missing or out of date. You recover in two steps: first make sure nothing from the old run is still running, then recover the current head from the record and continue from it.

First, stop and wait for the old driver and for **every capability and worker process it started, including their child processes**. Killing the driver alone does not mean they have stopped. After a restart, confirm that none of them survived or was restarted. Keep other drivers, and anything else that writes to the run, stopped while you recover. The `--processes-stopped` option declares that you have confirmed this; it does not stop anything for you.

Then recover the current head by verifying the record without running any action, and continue with exactly that head. These commands use `$W` from the first block:

```sh
python3 examples/letter-classification/driver.py --run-dir /tmp/run --recover-head --processes-stopped --head-file letter-head.json
python3 examples/letter-classification/driver.py --worker-command "python3 $W" --run-dir /tmp/run --expected-head letter-head.json --head-file letter-head.json --processes-stopped
```

Recovery needs both `--head-file` and `--processes-stopped`, and cannot be combined with `--expected-head` or with person input. The driver refuses a record or content that fails verification. `continue` still refuses an out-of-date head; it never refreshes the head you supply.

When the run continues, an action whose observation was already committed is routed onward without being started again. Some actions are not safe to repeat. If such an action has a committed intent but no accepted observation, the runner reports `invocation_unresolved` (exit status 2) and keeps the action's effects and the run's state rather than repeating it. Recover the newly recorded halt head with the first command again; continuing from that head returns the same halt (exit status 21). Choosing to retry or abandon the action is then a separate, explicit decision. The letter driver has no option for that choice. The Python `rail.continue_run` interface accepts `operator_choice="retry"` or `operator_choice="abandon"`, together with the retained head, `processes_stopped=True` and the driver's worker command in `adapter_values`. The engine's `continue` command also accepts `--resolution retry|abandon`, but it has no option to supply this example's worker command. Use the Python interface when retrying this example needs that worker.

## Verify

These checks run the project's full test suite in pinned containers, as continuous integration does. They need Docker on a linux/amd64 machine. The `prepare` step downloads the locked base image and the dependency files listed in `tests/container/`, so it needs network access. The `build` and `run` steps work offline.

```sh
scripts/test-container prepare --python 3.11
scripts/test-container build --python 3.11
scripts/test-container run --python 3.11 -- make check
scripts/test-container prepare --python 3.14
scripts/test-container build --python 3.14
scripts/test-container run --python 3.14 -- make check
```

Inside the prepared container, `make check` runs formatting, lint, the tests, validation of the shipped graphs, and the compliance check. It uses the same pinned tools as CI. The examples use that environment with `PYTHONPATH=src`. Continuous integration also runs Python 3.13 the same way; use `--python 3.13` in the three commands to do the same.

## Reference

[COMMANDS.md](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/COMMANDS.md) covers authoring, the model gateway, records and maintenance in more depth. The command blocks below are working examples, and the project's tests check them.

### The subcommands

`python3 -m executable_trug` has seven subcommands. New runs use version 2 of the step protocol.

- `create DIRECTORY` makes a new draft rail directory containing a small working example. The draft has a pinned program, a person step, explicit gates, sample expectations, and `BINDS` edges, which say which input each step receives. The subcommand refuses a directory that already exists.
- `pin GRAPH` writes the fingerprint of each file the graph names into the graph. It changes only the installed source; the definitions captured by existing runs never change.
- `check GRAPH` captures and validates the definitions without publishing a snapshot or starting work.
- `test GRAPH --samples FILE` runs each sample in a fresh temporary record and snapshot store. It checks the exact sequence of routes, the final cursor and the stop reason, and then removes the temporary files. A mismatch exits with status 21.
- `run GRAPH --input-file FILE --run-dir DIR` starts a run and drives it until a person pause, a halt or the end. A person pause exits with status 0, and the output includes `pending_person`. `run` never submits a choice.
- `start GRAPH --input-file FILE --run-dir DIR` creates a run and performs no action.
- `continue --run-dir DIR --expected-head FILE` advances an existing run from the head in that file and returns the next head. The file must contain the complete head JSON object exactly as it was returned. A whole response will not do, and neither will a head refreshed some other way. The options include `--person-input-file`, `--resolution retry|abandon`, `--processes-stopped` and `--operator-note-file`.

An input file holds any JSON value, and the rail's `BINDS` edges select what each step receives. A person input file holds exactly one submission of the form `{"source":"person","value":...}`, where the value is any exact JSON value, including `null`.

**Exit statuses.** The commands use three exit statuses:

- **0** means success, including a person pause reached by `run`.
- **21** means the run is at a halted or failed position, or a `test` expectation did not match.
- **2** means an error or a refusal. Examples are a missing or out-of-date head, malformed JSON or a malformed submission, invalid declarations, an existing draft directory, an unsupported verb, or a structured execution refusal.

When a model call or a gate halts a run, `run` returns the halted view with status 21, while `continue` returns a structured error with status 2. The older verbs `execute`, `transition`, `surface` and `resume`, and the `--outcome` option, have been removed, and the command line refuses them.

### Authoring and execution reference

The block below creates a draft rail, then pins, checks and tests it. It runs the rail once until it reaches its person pause. It then goes through a second run one operation at a time, with `start` and `continue`.

The `python3 -c` lines copy the `head` field from each response into `head.json`, because each `continue` needs the latest head. The last `continue` submits the draft's `accept.json` as the person's answer.

Run the block from an empty working directory, either with the engine installed or with an absolute `PYTHONPATH` pointing to this checkout's `src`. Every command in it exits with status 0.

<!-- authoring commands -->
```bash
python3 -m executable_trug create draft
python3 -m executable_trug pin draft/rail.json
python3 -m executable_trug check draft/rail.json
python3 -m executable_trug test draft/rail.json --samples draft/samples.json > tests.json
python3 -m executable_trug run draft/rail.json --input-file draft/input.json --run-dir auto-run --snapshot-store "$PWD/snapshots" > pause.json
python3 -m executable_trug start draft/rail.json --input-file draft/input.json --run-dir run --snapshot-store "$PWD/snapshots" > start.json
python3 -c 'import json; json.dump(json.load(open("start.json"))["head"], open("head.json", "w"))'
python3 -m executable_trug continue --run-dir run --expected-head head.json > work.json
python3 -c 'import json; json.dump(json.load(open("work.json"))["head"], open("head.json", "w"))'
python3 -m executable_trug continue --run-dir run --expected-head head.json > person.json
python3 -c 'import json; json.dump(json.load(open("person.json"))["head"], open("head.json", "w"))'
python3 -m executable_trug continue --run-dir run --expected-head head.json --person-input-file draft/accept.json > terminal.json
```

### Model gateway reference

A rail that calls an AI model reaches it through a gateway. The gateway is a separate process that you start yourself, and it holds the model configuration and any login. The runner talks to the gateway over a Unix socket that you name on each command. Provider configuration and login data stay with the gateway; the run records safe provider identities and references to content.

The gateway supports two providers. `local-vllm` sends a request to a vLLM server on the same machine. `sol` runs a configured external model command once per call, using a login already set up on that machine. COMMANDS.md describes the gateway's configuration file.

Set `GATEWAY_CONFIG` to the absolute path of the configuration file. Start the gateway in a separate terminal and wait for its `ready` event; press Ctrl-C there to stop it.

<!-- gateway daemon -->
```bash
python3 -m executable_trug.gateway --config "$GATEWAY_CONFIG"
```

For a model rail, set these variables:

- `GRAPH`, `INPUT` and `SAMPLES` to the rail's graph, JSON input and samples;
- `SNAPSHOTS` to its snapshot store;
- `GATEWAY_SOCKET` to the configured control socket.

The three commands below are alternatives, not a sequence. The first creates a fresh run, the second tests the samples, and the third continues an existing `run` from its complete retained head in `head.json`.

<!-- gateway operator commands -->
```bash
python3 -m executable_trug run "$GRAPH" --input-file "$INPUT" --run-dir gateway-run --snapshot-store "$SNAPSHOTS" --gateway-socket "$GATEWAY_SOCKET" > gateway-result.json
python3 -m executable_trug test "$GRAPH" --samples "$SAMPLES" --gateway-socket "$GATEWAY_SOCKET" > gateway-tests.json
python3 -m executable_trug continue --run-dir run --expected-head head.json --gateway-socket "$GATEWAY_SOCKET" > gateway-step.json
```

### Gateway checker reference

The gateway checker examines recorded model-gateway evidence. Run it from the root of a clone of this repository. It uses helpers from the `tests/` folder, which is not in the published package.

The offline commands read cases that were already recorded. Replace the uppercase placeholders with your case and output paths, and use new output and log paths each time.

<!-- gateway checker offline -->
```bash
python3 scripts/check-model-gateway.py verify OUTPUT/ordinary --expectations OUTPUT/ordinary/expectations.json
python3 scripts/check-model-gateway.py replay OUTPUT
python3 scripts/check-model-gateway.py capture CASE
python3 scripts/check-model-gateway.py bundle OUTPUT > OFFLINE.log
python3 scripts/check-model-gateway.py extract --log OFFLINE.log --output EXTRACTED
```

Live checks call a real provider, so they are kept apart from offline verification. They need the explicit `live` command and a gateway that you have started separately. Replace the socket, model and output placeholders with your own configuration; `/operator/runtime/control.sock` is only an example socket path.

<!-- gateway checker live -->
```bash
python3 scripts/check-model-gateway.py live --provider sol --gateway-socket /operator/runtime/control.sock --model MODEL --output OUTPUT
python3 scripts/check-model-gateway.py live --provider local-vllm --gateway-socket /operator/runtime/control.sock --model MODEL --output OUTPUT
```

### Local maintenance reference

Maintenance uses the Python interface rather than the command line. The first line below inspects the paused `auto-run` from the authoring example, and the second erases its content. Erasing requires explicit confirmations that the run's processes and any outside writers have stopped. The confirmation arguments only declare that these processes have stopped; they do not stop them. Erasure keeps the record itself, shared snapshots and independent development sub-runs.

<!-- maintenance commands -->
```bash
python3 -c 'import json; from executable_trug.maintenance import inspect_record; json.dump(inspect_record("auto-run"), open("inspection.json", "w"))'
python3 -c 'import json; from executable_trug.maintenance import erase; head = json.load(open("pause.json"))["head"]; json.dump(erase("auto-run", head, processes_stopped=True, external_writers_stopped=True), open("erased.json", "w"))'
```

### How much a read verifies

Three reads do full verification: `record.read_record()` with its default settings, `rail.read_state()`, and `cli.inspect()`. They check the complete chain of record entries and the content those entries refer to. Inspection reports any lost content separately. If you supply an earlier head that you kept, full verification anchors the verified part of the chain at that head's sequence number. `read_record(verify_payloads=False)` checks the chain only.

The ordinary reads made during `start` and `continue` do less. They work out the position, input, state, pending links and gate values that the current operation needs. They also:

- check that the record format is supported and that the supplied head is the latest;
- validate the current protocol, state and gates;
- validate new entries before publishing them.

They do not re-hash earlier entries or content, and they report `chain_integrity: null`. On this path, a retained head shows that it agrees with the latest head stored in the record. It does not show that the earlier history is intact.

So someone who can replace every byte in a run directory, and the head the caller kept, can still rewrite the history consistently. The chain also does not prove who acted. See [Record §5](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/SPEC/SPEC-261003-run-record.md#5-covering-digest-sdk-verification-and-limits).

## More reading

- [CONCEPTS.md](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/CONCEPTS.md) explains what makes a graph an executable TRUG, the two kinds of failure it addresses, and why the oracle is deterministic. Read it after the walkthrough.
- [COMMANDS.md](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/COMMANDS.md) gives more detail on authoring, the model gateway, local records, snapshots and maintenance.
- The [design record](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/SPEC/README.md) lists the eleven specifications behind the runner. It is a record of design decisions, not a user manual, and some passages predate this release.
- To learn about TRUGs themselves, start with the specification's [GETTING_STARTED.md](https://github.com/TRUGS-LLC/TRUGS/blob/main/GETTING_STARTED.md). The [TRUGS language](https://github.com/TRUGS-LLC/TRUGS/tree/main/TRUGS_LANGUAGE) folder describes TRL, which CONCEPTS.md calls TRUG/L.

## Contributing

[CONTRIBUTING.md](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/CONTRIBUTING.md) explains how to propose a change. A small fix can go straight to a pull request. For anything bigger, open an issue first and describe the change and how it can be checked. Changes in behavior need tests, and `make check` should pass in the pinned checking environment. Only people merge into `main`, though automated agents may open pull requests for review. Contributions are licensed under the Apache License 2.0.

## Reporting security problems

See [SECURITY.md](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/SECURITY.md) for private vulnerability reporting. Do not report security problems in the public issue tracker.

## License

Apache 2.0. Copyright 2026 TRUGS LLC. See [LICENSE](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/LICENSE) and [NOTICE](https://github.com/TRUGS-LLC/TRUGS-RUNNER/blob/main/NOTICE).
