# Sell and purchase an invoice repair

This complete Python client project runs against the Chio single-operator venue.
The included `invoice.bundle` is a Git repository with two branches: `baseline`
ignores line quantities and produces 850; `repaired` includes quantities and
produces 2400. Both contain the same standard-library check. The example supplies
a repair; it does not generate one autonomously.

Extract `repair-market` beside your `chio-source` checkout at public revision
`5b8bec41d32f3838b880576fe6123c983ecebf8d`:
https://github.com/backbay-labs/chio/tree/5b8bec41d32f3838b880576fe6123c983ecebf8d

Use a source-built `chio` on PATH, Python 3.11 or newer, and uv. The operator
requires Linux, Git, Bubblewrap, prlimit, and delegated cgroup v2 or an available
systemd user manager. The sandbox must be allowed to create user and network
namespaces. The capture used Ubuntu 24.04 arm64 with systemd user scopes and a
scoped AppArmor permission for its dedicated bwrap executable. It did not disable
the system-wide restriction on unprivileged user namespaces. A container with
cgroup files present but no usable delegation is insufficient.

In terminal 1:

```bash
cd repair-market
git clone invoice.bundle invoices
chio finding operator init --directory ./venue --repository-root "$PWD/invoices" --listen 127.0.0.1:7143
chio finding operator serve --profile ./venue/operator-profile.json
```

In terminal 2, enter the same `repair-market` directory:

```bash
uv run --locked seller.py --credential venue/seller-client.json --repository "$PWD/invoices" --base origin/baseline --candidate origin/repaired --test 'python3 check.py' --topic coding/invoice-total > offered.json
uv run --locked buyer.py --credential venue/buyer-client.json --chio "$(command -v chio)" --offer offered.json --patch purchased.patch --max-price 300
```

The scoped seller submits the revisions and check. The operator replays the
failure and repair before admitting its offer. The buyer invokes the Rust proof
and purchase-terminal verifiers and writes `purchased.patch` and the complete
`purchase.json`. The local venue captures 300 USD minor units; this is local credit
accounting, not an external payment. No client file contains the operator service
token; protect the generated venue credentials and state directory.

Apply the delivery to a separate baseline checkout:

```bash
git clone --branch baseline invoice.bundle customer-copy
git -C customer-copy apply --check "$PWD/purchased.patch"
git -C customer-copy apply "$PWD/purchased.patch"
python3 customer-copy/check.py
python3 customer-copy/invoice.py customer-copy/items.json
chio finding operator tick --profile ./venue/operator-profile.json
```

The check reports `invoice total: 2400; check passed`. The purchase itself never
changes a source workspace. To use your own project, submit its repository,
base/candidate revisions and offline test command; keep it inside the operator's
configured repository root. Tests run without network access and need their
build dependencies available inside that repository.

A 200-unit bid for the 300-unit offer is refused before purchase state advances in
the capture. The current API returns HTTP 500 `purchase_executor_failed`; the
operator log explains `bid ceiling is below the quoted price`. This is a diagnostic
limitation, not a useful client-facing denial format. Inspect the specific
operator error before retrying a failed purchase.

The archive includes five source/configuration files and the Git bundle. It
contains no generated venue, credentials, signing seeds, database, purchase or
virtual environment. Stop the foreground operator with Ctrl-C when finished.
