---
title: "Inspect and format Contract"
description: "contract migrate <file.contract> rewrites retired spellings in place."
modificationDate: "2026-11-30"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Inspect and format Contract

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/reference/developer/inspect-and-format-contract: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

```sh
cargo run -q -p contract -- build apps/messages/app.contract --json
cargo run -q -p contract -- build apps/messages/app.contract -o /tmp/messages.plan --map
cargo run -q -p contract -- symbols apps/messages/app.contract
cargo run -q -p contract -- symbols apps/messages/app.contract --name select
cargo run -q -p contract -- fmt --stdout apps/messages/app.contract
cargo run -q -p contract -- fmt --check apps/messages/app.contract
```

`contract migrate <file.contract>` rewrites retired spellings in place. It moves
`-exact-press-background-color` and `-exact-press-color` into the owner's
`:active` block, merging with an existing block and retaining expressions and
comments. It refuses conflicting active rows, directly nested inline text and
explicit `appearance="auto"` controls other than buttons before writing.
Classes and component uses are checked at compile time. Compile the result with
`contract build`; use `contract fmt` to format it. Arbitrary strings and
transition targets are unchanged.

`symbols` prints JSON with `definitions` and `references`. Each reference's
`to` is an index into `definitions`; locations include the original file,
1-based line and UTF-8 byte column, and an exclusive `end_col`. Component interfaces,
local bindings, parameters, typed shape fields, font families and literal IDs are navigable.
Shared shape/function/style/font files can be queried directly. The query uses the
compiler's import and type rules and writes no files. Repeated literal IDs have
an edge to each matching declaration; dynamic IDs have no static target.
An action's definition carries `writes`: the states and mutations its body
assigns or sends, inferred (an action declares none), in slot order: router
state, states, then mutations, each as declared.

`symbols --editor` adds what an editor integration reads
(`editors/content-mapper`, LLP 1035.005.003); nothing else asks for it, and without the flag none
of it is computed. A definition the type checker types carries `type`, its type in TypeScript as
`contract types` writes it in `app.d.ts`'s summary: a state, derive, prop,
inject, resource, mutation (`T | null`), local or parameter by its value, a shape
by its fields, a field by its value, an action or `fn` as a function of its
parameters. An enum is the union of its strings, `"a" | "b"`. A shape inside a type is written by its name,
and `shapes` lists each shape used so, its `name` and its fields as `type`,
`{ id: string }`. A shape TypeScript cannot name, one with a hyphen (`A-B`) or
named as a reserved word (`class`), is written in a type by an alias no shape
has (`A_B`, `class_`), which its row in `shapes` gives as `as`. When loading stopped and each file was read on its own, a
shape also has the `file` it was read in: two files may declare different
shapes of one name. A bare `action` prop or inject has no `type`: its arity is
what it is called with.
A route, component, source, style, task or ID has no `type`. When the type
check refused, only what is declared keeps one: shapes, fields, and `fn`s and
their parameters.
`elements` lists each view element as written, for an editor's hover and
completion: its `tag` (the compiler's name for it; an `h2` is a `text`), its
place and `component`, and `attrs`, each attribute written on it with the place
of its name and, for a string literal value, `string` with the value and its
place, quotes included. A button's one argument, which becomes its `text` child, is no element
of its own. A `--name` query has no `elements`.

Add an element filter to `symbols --editor` to return just the matching
`elements` across the source graph. `--component` matches the declared name,
and `--tag` accepts the authored or compiler tag. Repeat `--has <attr>` and
`--where 'attr=expression'` to require written attributes and exact source
values. Use `--has` for a bare attribute such as `multiple`. Repeat
`--match <text>` to look up several
case-sensitive substrings in one pass. A match can occur in the tag, a written
attribute name or value, or a positional text expression such as an option
label or a button's direct text child. Use `--or` to start an independent filter
group. An element that satisfies any group appears once, in source order
within its file.

```sh
contract symbols app.contract --editor --component Editor --tag button --match 'Save draft' \
  --or --component Preview --tag button --match Cancel
```

Filtered elements include `binding` on attributes with other written values,
`text` for text expressions, and `context` for enclosing `if` and `for` headers,
outermost first. An `if` reports which branch contains the element. Each entry
includes its authored `source` and range in the element's file. An `end_line`
appears when the range crosses a line. Element filters can be used with
`--stdin` and are separate from `--name` queries.

When the program is refused, `symbols` still prints what it found, adds an
`errors` array of the refusals in `build --json`'s form, writes them to stderr
and exits 1. A declaration or member the syntax refused is absent, and so is
every reference in its scope spelled as its name; a reference to a name
declared twice in one namespace (a component's members, or the program's
shapes and functions) has no edge. When the type check refused, a
reference that needs an inferred type (a field read through a value, an
action value called) has no edge, nor does one to a shape or function the
check refused. When loading stops (a `use` or `members` line that names no
file, a cycle, a missing name), every file it can still reach and parse is
read on its own, with no edge from one file to another. A file whose
declarations cannot be told apart (a line that does not lex, or a first
component whose view is refused) has no symbols; when that file is the root,
`definitions` and `references` are empty. A refused program's actions carry
no `writes`.

`--name <exact-name>` returns all matching definitions across scopes and their
references, with `to` indices into that response's smaller `definitions` array.
Names are exact and case-sensitive, not patterns; no match returns empty arrays.
The complete source graph is still checked. `symbols --help` shows the syntax.

`build --json` writes one diagnostics array to stdout: every independent
diagnostic the compiler can collect, at most 20, each with a stable `id`, a
`severity`, `message`, original `file`, `line`, `col`, `end_col`, and `related`
array. An `"error"` refuses the build (exit 1); a `"warning"` builds (exit 0) and
is printed on a success too, so `[]` means a success with nothing to say. Action-interface
mismatches link the invocation, declaration and caller binding, each with its
own source file, including forwarded props and injected actions. Locations use the same byte columns as symbols; zero
means no source range, and a null file means no file is associated. No prose is
mixed into JSON, including argument and output-write failures, and nothing is
written to stderr: advice the human form prints there (a resource fed by a live
clock, a game's stale surface arguments) is among the warnings. `bun exact.mjs
contract build app.contract --json` appends `app.ts`'s type-check errors to the
same array, one per TypeScript diagnostic (`id` `typescript-TS<n>`). Exit codes are
0 for success, 1 for compilation/I/O failure, and 2 for invalid arguments.
`-o <file.plan>` writes the same plan bytes in either output mode.

`--stdin` gives `build` and `symbols` the named file's text on stdin, an
editor's unsaved buffer, in place of what is saved there:

```sh
contract build app.contract --json --stdin < buffer
contract symbols app.contract --stdin < buffer
```

The text is read as if it were saved at that path: its `use` and `members`
lines resolve beside it, every other file is read from disk, and the output
on both streams and the exit code are those the same text saved there gives,
diagnostics' `file` and ranges and the text form's quoted lines included.
Only the named file's text is replaced. Unsaved text writes no file but
`-o`'s: `build` leaves an existing `<file>.d.ts` as it is (so it never says
it regenerated it), and `bun exact.mjs contract build app.contract --stdin`
neither refreshes the types `app.ts` imports nor type-checks `app.ts`.
`--stdin` takes no `--entry`.

`build --stdin-as <used.contract>` reads stdin as the text of a file the named
one uses, for the unsaved buffer of a file that is built with its app:

```sh
contract build app.contract --json --errors-only --stdin-as lib/row.contract < buffer
```

It is `--stdin` in every other way, and the two are not given together.

`build --map -o <file.plan>` also writes `<file.plan>.map.json`, keyed by
SHA-256 of the plan bytes. Each plan node has its original file and range,
component call-site chain, and one binding per style row: its base value's
origin (`own`, `class:<Name>`, or `tag`) and, where an author wrote it, `at`
and `attr`; and `states`, one `{state, origin, at}` per state part that
writes the row: `:active`'s (on the press paint row it lowers to), `:hover`'s
and `:focus-visible`'s (LLP 1121 D8, LLP 1122); a conditional class's
(`class=(c ? A : B)`) says no `at`, as its base row says none; a row a
`:disabled` or `:checked` part folds over its base says the base's attribute
as its base and each folded part in `states`. A row only a state part
writes, a press row among them, has no base fields. Each source is listed
with its digest, and a Contract source with its `home`, as its components'
identities name it (a param's full name is `<home>#<component>.<param>`). Slots, derives, resources and actions retain their declarations,
including state and actions lifted from child components. Maps are separate
files; ordinary compilation collects neither instantiation provenance nor lowering sites. The compiler API's
`compile_path_mapped` and `compile_path_source_mapped` return the map alongside
the plan; `SourceMap::bake_error` resolves measured layout refusals, and
`SourceMap::json` takes the final encoded bytes after baking. A consumer must
verify the map's digest against the plan actually accepted by its session.
The resident Contract, TypeScript and portable Rust producers emit maps after
baking. Temporary source captures retain the original app filenames. The dev
server keeps the matching map at the generation's `app.plan.map.json` URL,
declared under `dev.sourceMap`; it is never an asset or module payload. Static
builds and production publication omit it. `agent.mjs ... "layout <target>"`
reads the map beside `--plan` or from the development `--url`/`EXACT_DEV_PLAN`
envelope. It shows the declaration, component callers and winning authored style
origins only when the same node reply carries the matching plan digest. The
runner computes that digest lazily once per accepted plan; ordinary inspection
does no hashing. Missing, invalid or stale maps leave geometry available with a
source-unavailable explanation. The driver retains four recent map digests for
sessions that keep an older plan after a refused reload. A fresh driver may lack
that older map and refuses the join. “Compatible source map” means the compiled
plan matches: formatting-only edits can change source locations without changing
the plan, so this is not an original-source revision guarantee.

`fmt --stdout` previews source-preserving formatting; `--check` prints a diff
and exits nonzero when formatting differs. Plain `fmt <file>` writes the result
explicitly. `fmt --stdin <file>` formats stdin's text to stdout, an editor's
unsaved buffer: the file names the text and is not read. Formatting never runs
automatically on save.
