> ## Documentation Index
> Fetch the complete documentation index at: https://developers.haia.finance/llms.txt
> Use this file to discover all available pages before exploring further.

# build

> Assemble one receipt per operation from a run's events.

```sh theme={null}
haia-trace build [file] [options]
```

The core command. Read a run's events and produce **one Receipt per operation**.

Events are grouped into operations by their `context_id`; each group is folded
through the assembler independently. Every assembled receipt is written to
`.trace/receipts/<context_id>.json`.

## Usage

```sh theme={null}
haia-trace build                          # build the latest run in .trace/events/
haia-trace build ./run.ndjson             # build a specific run file
haia-trace build --template x402-seller   # apply a specific template
haia-trace build --json                   # machine-readable output for agents
```

## Arguments and options

| Argument / option | Meaning                                                                 |
| ----------------- | ----------------------------------------------------------------------- |
| `[file]`          | NDJSON run file to build from. Default: the latest in `.trace/events/`. |
| `--template <id>` | Operation template applied to every operation. Default: `x402-buyer`.   |
| `--json`          | Emit `{ receipts, unassigned }` as JSON instead of a terminal summary.  |

Run-level events that carry no `context_id` (chain confirmations, capture
attestations) belong to no single operation, so they're reported separately as
`unassigned` rather than attributed or dropped.

## JSON output for agents

`--json` prints the full [Receipt](/concepts/operation-receipt) objects — the
machine-readable basis an agent reads (`completeness`, `missing`) to decide
whether to continue a chain of spending.

## Producing a run file

`build` needs a `.trace/events/*.ndjson` run file. Today you can point it at any
NDJSON file whose lines match the [Event
Contract](/sdk/core) — the CLI ships a working example fixture.

<Note>
  For automatic capture from a live x402 app, point
  [`@usehaia/trace-x402`](/sdk/x402) at `.trace/events` — `trace(...)` then feeds
  `build` directly. Pick the template matching the side you traced: `x402-buyer`
  (the default) for a client capture, `--template x402-seller` for a resource
  server or facilitator capture.
</Note>
