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

# bijection check

> Check the app tree's types and label flow, analyze its guards and keep bijection.lock current.

`bijection check` analyzes the app tree that `bijection/app.ts`
exports, without installing anything or running a handler. Run it before
every commit and as a required CI step.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection check
bijection check --write-lock
bijection check --format json
```

It does four things:

1. **Types.** It type-checks the backend with the CLI's pinned TypeScript
   compiler. The SDK's types check shapes: addresses, indexes, verbs, spec
   keys and value types. They do not check label flow.
2. **Label flow.** It infers each function's commit label and checks every
   read, write, open, call and disclosure against it. Flow is checked here
   and enforced again by the host; it is never a TypeScript error.
3. **Guards.** It lists every `forbid` guard with its tier, its `under` and
   the facts it reads, and analyzes the analyzable ones.
4. **The lock file.** It derives the app's authority and refuses when the
   committed [`bijection.lock`](https://docs.bijection.com/development/cli/lock) differs
   (`AuthorityLockStale`). It compiles every warehouse statement and pipeline
   program through the semantics guest, offline, and refuses a committed file
   under [`bijection.statements/`](https://docs.bijection.com/development/cli/lock#committed-statements)
   that differs (`StatementStale`). `--write-lock` rewrites both for review.

`PathRepeats` flags paths such as `orders.orders`. `SnakeCaseField` flags
fact fields such as `order_total` and suggests camelCase. Both are warnings
that allow the check to continue.

## The lexicon

`bijection check` enforces the SDK's written lexicon: one word for each
meaning. It refuses an app identifier that uses a word the lexicon retires or
a synonym it refuses, and the sentence names the lexicon's word:

| Code | Where |
| - | - |
| `LexiconAbsent` | An SDK import, a declaration's option key or an exported name that is a retired word (`v`, `useQuery`, `fail`, `keep`), or an exported name holding a refused noun (`renameOutcome`). |
| `LexiconSynonym` | A `ctx` member that names a verb by a synonym (`ctx.fail` for `ctx.refuse`, `ctx.update` for `ctx.replace`), or a declaration option named by a synonym (`errors` for `refuses`, `timeout` for `within`). |

```text theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection/orders.ts:8:3 LexiconSynonym: mutation() takes no option errors, a synonym the lexicon refuses; the option is refuses
```

Field names (a table's fields, a function's `args`) are your own and are not
checked.

## Flow sentences

Each flow refusal is one sentence at `path:line:col`. It names the code, what
went wrong and the fix.

A helper in your app that a function hands its `ctx` to (`audit(ctx, fact)`)
is checked under that function's `under`, at the helper's own lines. The
types never check label flow: a helper's `QueryCtx` or `MutationCtx` takes
every function's context.

```text theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection/orders.ts:12:61 ReadAbove: ctx.get reads finance data (access.ledger), above this function's under (tenant); add finance to under, or read it in a function whose under clears it
```

| Code | Meaning |
| - | - |
| `ReadAbove` | A read (`get`, `has`, `list`, `page`, `count`) or a strict write's assumption reads above the function's `under`. |
| `WriteBelow` | A write would carry data into a table labelled below the function's `under`. |
| `OpenAbove` | A plain `ctx.open` opens a sealed value whose label is above the function's `under`. |
| `QueryWrites` | A query attempts to use `ctx.open(sealed, { release })`, which requires a mutation. |
| `CallAbove` | A query's label does not flow to its `ctx.call` caller, or a mutation's label does not flow to its `ctx.call` or `ctx.try` caller. |
| `InvalidSubmit` | The known run label differs from the mutation's fixed `under`. Set the submit's `under` to that label and use a release if the request label does not flow to it. |
| `DiscloseWrongRelease`, `DiscloseAbove` | `ctx.open(sealed, { release })` names a release whose `from` does not cover the sealed value or whose audience is above the frame. |
| `AllowBelowLabel` | A role in `allow` does not clear the function's `under`. The class roles `role.anyone` and `role.signedIn` are skipped. |

```ts bijection/ledger.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { label, mutation, role, t, table } from "@bijectionhq/bijection";

export const tenant = label();
export const finance = label();
export const clerk = role({ clear: [tenant] });
export const ledger = table({ account: t.string, balance: t.decimal }, { key: ["account"], label: finance });

// ReadAbove: the clerk's function runs under tenant, and the ledger is finance data.
export const peek = mutation({ allow: [clerk], under: tenant }, (ctx) => ctx.get(ledger("a")));
```

## Guards

For each guard, `check` prints its path, its tier, its `under` and the
tables its condition reads:

```text theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
Guard inputs:
  bijection/guards.ts:8:3 guards.closing (when, under desk) reads quarterClose
```

A `where:` guard is written with the declarative predicate builder, so it is
analyzable. With `cvc5` or `z3` on `PATH`, `check` warns about `where:`
guards that can never match, and reports the policy diff against the
committed lock: the acts the change newly forbids or newly allows, with an
example of each, or that the guards mean the same as before. Without a
solver it says `analysis unavailable`. A `when:` guard is a TypeScript
function: it is tested, not proved, and the lock marks it `tested`.

`--prove <query>` asks whether any act matching a query can be allowed by
the guards. The query is a scope and an optional predicate in the guard IR.
It prints an allowed example and fails when one exists:

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection check --prove '{"scope": {"kind": "patch", "table": "orders.orders", "fields": ["total"]}}'
```

The proof covers the guards only: positive authority (`allow`, grants and
clearance) is not modelled, so an allowed example is an act no guard refuses.

## Pending lowerings

A timed lowering is an ordinary scheduled task that changes a fact's label
field through a release you declare, built with `labelSwitch` from
`@bijectionhq/library-label-switch` (see
[Eventual labels and timed lowering](https://docs.bijection.com/access/labels.md#eventual-labels-and-timed-lowering)).
`check` reports it like any other code: the functions that schedule it carry
a submit, and its release is listed with the others in the lock. The
lowerings still pending at run time are tasks in `sys.tasks`.

## Exposure

`check` ends with what the lock states: the app contract, every exposed
function with its `allow`, `under` and guards, the internal functions, and
the paths that carry grave acts.

```text theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
Contract 7c1e…: 3 exposed, 1 internal functions.
Exposed (callable from outside):
  notes.list (query) allow sys:anyone
  notes.add (mutation, under tenant) allow team.member; guards guards.noSpam
Internal: notes.purge
```

## Options

| Option | Effect |
| - | - |
| `--write-lock` | Write the derived authority to `bijection.lock` beside `app.ts`, instead of refusing a stale one. Review and commit the diff. |
| `--prove <query>` | Prove that no act matching the JSON query `{ "scope", "where" }` is allowed. |
| `--installation <project>:<name>` | Also check the target bindings on this deployment. |
| `--format <pretty\|json>` | Output format. JSON lists `lowerings` and `guardInputs`. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.