# Ledger and provenance

See which parts of a change were mechanical and which were written by hand, prove a refactor is only renames, catch contract breaks, and verify a signed record of how every merge was made.

A diff shows what changed. It does not show how. A thousand-line rename an agent ran through a language server looks the same as a thousand lines typed by hand, so a reviewer has to read all of it. Sailfork records how each change was made, so a reviewer reads only the part that needs a person.

```sh
sailfork pr ledger 12          # how pull request #12 was made
sailfork commit ledger 4f2a9c  # how one commit was made
sailfork commit attestation 4f2a9c   # the signed record of the merge that landed it
```

The pull request page shows the ledger beside the diff, and the pull request and commit pages show the merge's provenance.

## The ledger

A ledger has four parts:

- **Operations**: the typed edits a caisson ran, an LSP rename (`caisson_lsp_rename`) or an ast-grep rewrite (`caisson_ast_rewrite`), each with a one-line summary such as `rename chargeCard to captureCharge in 4 files`, what it was asked, its commit and the files it wrote.
- **Residue**: the hand edits no operation explains, file by file, as unified diffs in the order they were made. `whole` marks a file no operation touched.
- **Checks**: the commands a caisson ran on exactly the code a commit holds, with exit code, duration and commit.
- **Intent**: the issues the change is for, read from its caissons' `issue/<n>-...` branches, and the caissons that made it.

Review the residue; the operations are mechanical. An operation is `verified` when every file it wrote reached the end of the change with no hand edit after it.

A commit made outside a caisson has no recorded operations, so Sailfork looks for a rename in its diff: if replacing one word with another across every changed file gives the commit's files exactly, the ledger lists it as an `inferred` rename. An inferred rename is never verified and never counts toward proof, and its files still show their residue.

Large changes are bounded. `omitted` lists changed files whose residue was left out (past the file cap, binary or too large to diff), and `uninferred` counts commits that were not searched for renames.

## Proof

Every ledger carries a `proof` with a state and the reasons for it.

| State | When |
| --- | --- |
| `verified` | Every changed file was written by a verified rename, no residue remains, and a check ran clean on the last commit's code. |
| `none` | Anything less. `reasons` says what is missing. |

A rename counts as verified when the server saw each edit replace one name with the new one. The check runs in the author's own sandbox, so proof tells a reviewer what the evidence is. It does not claim nobody could forge it.

### Lighter review for verified refactors

A verified change is only renames that pass a check, so it rarely needs the same review as new logic. Set `refactorApprovals` in a repository's or organization's [merge rules](https://sailfork.com/docs/branches#merge-rules), and a pull request whose ledger is verified, with a required CI check passing on its head, needs that many approvals instead of the usual count. It is 0 or more and below `approvals`; `null` keeps the usual count.

```sh
sailfork api /api/repos/fenil/ocean-landing/merge-rules --method PUT --input - <<'EOF'
{"approvals": 2, "dismissStale": true, "upToDate": false, "threadsResolved": true, "selfReview": false, "refactorApprovals": 1}
EOF
```

A verified change also takes 40 points off its [risk score](https://sailfork.com/docs/inflight#risk-score).

## Contract breaks

The ledger lists what a change breaks for the code and people that depend on it, under `contract`:

| Kind | Found when |
| --- | --- |
| `route` | An API route is gone from the route list in `client/src/contract.ts`. |
| `migration` | A migration is removed, edited after it shipped, or drops, renames, retypes or deletes something. |
| `export` | A `pub` Rust item is removed, narrowed or no longer re-exported. Up to 20 files of the target branch that still use it are listed in `consumers`. |

Each break is one line, such as `removed GET /api/x`, `not additive: alter table a drop column b` or `removed pub function Cache::load`, with its file. An item counts as exported by its `pub` declaration, so one in a private module is listed too. Only the repository's own files are searched for consumers.

The check has a 5 second deadline. An empty `contract` means nothing was found only when `contractChecked` is `true`. `contractTruncated` says a cap cut the list short.

## Attestations

When a pull request merges, Sailfork records how it was made as a signed statement under the commit the merge landed:

- a [DSSE](https://github.com/secure-systems-lab/dsse) envelope with payload type `application/vnd.in-toto+json`,
- holding an [in-toto](https://in-toto.io) statement (`https://in-toto.io/Statement/v1`) whose subject is the repository and the merge commit,
- with a [SLSA provenance](https://slsa.dev/provenance/v1) predicate of build type `https://sailfork.com/attestations/caisson-change/v1`,
- signed with Ed25519 by the server's commit signing key.

The predicate records:

| Field | What it holds |
| --- | --- |
| `externalParameters.pullRequest` | Number, branch, base and who merged it |
| `externalParameters.issues` | The issues the change was for |
| `externalParameters.agents` | Each caisson that made it, its branch and who opened it |
| `externalParameters.operations` | Each rename and rewrite, its files, and whether it was verified or inferred |
| `internalParameters.proof` | The proof state and its reasons |
| `internalParameters.checks` | The checks that ran on exact commits |
| `internalParameters.contract` | Contract breaks, and whether the check finished |
| `internalParameters.handEditedFiles` | How many files carry residue |
| `internalParameters.risk` | The risk score, when one was seen while the pull request was open |
| `resolvedDependencies` | The base and head commits that were merged |

The risk score is best effort: it is the highest score the server saw while the pull request was open, and is left out when none was kept. A merge made before attestations existed is attested the first time someone asks for it.

### Read one

```sh
sailfork commit attestation 4f2a9c
curl https://sailfork.com/api/repos/fenil/ocean-landing/commits/4f2a9c/attestation
```

The MCP tool is `commit_attestation`. A reader who may not see some paths gets a copy with them left out, `redacted` set to `true` and no signature, since the signature no longer covers it.

### Verify one

The public key is an OpenSSH line at `https://sailfork.com/.well-known/sailfork/commit-signing-key`, the same key that signs caisson commits (see [Commit signatures](https://sailfork.com/docs/commit-signatures)). The signature is over the DSSE pre-authentication encoding of the payload type and the decoded payload.

```python
# uv run --with cryptography verify.py attestation.json
import base64, json, sys, urllib.request
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey

envelope = json.load(open(sys.argv[1]))
line = urllib.request.urlopen("https://sailfork.com/.well-known/sailfork/commit-signing-key").read().split()
key = Ed25519PublicKey.from_public_bytes(base64.b64decode(line[1])[-32:])

kind = envelope["payloadType"].encode()
payload = base64.b64decode(envelope["payload"])
signed = b"DSSEv1 %d %s %d " % (len(kind), kind, len(payload)) + payload
key.verify(base64.b64decode(envelope["signatures"][0]["sig"]), signed)
print(json.dumps(json.loads(payload)["predicate"], indent=2))
```

`verify` raises on a bad signature. Each signature's `keyid` is the key's fingerprint. The key is derived from the server's secret, so after a rotation, older attestations name a key that is no longer published.

## Reference

| CLI | MCP | Route |
| --- | --- | --- |
| `pr ledger N` | `pull_ledger` | `GET /api/repos/{owner}/{repo}/pulls/{number}/ledger` |
| `commit ledger SHA` | `commit_ledger` | `GET /api/repos/{owner}/{repo}/commit/{sha}/ledger` |
| `commit attestation SHA` | `commit_attestation` | `GET /api/repos/{owner}/{repo}/commits/{sha}/attestation` |

Each needs `repo:read` and works signed out on a public repository. Fields are in [Pull request API](https://sailfork.com/docs/api-pulls).

---

Every docs page: https://sailfork.com/llms.txt
