---
title: "The implementation loop"
description: "In an app made by exact new, run its own exact.mjs from the app's directory."
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.

# The implementation loop

<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/learn/contract-for-agents/the-implementation-loop: <what was wrong or missing>"`

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

</AgentInstructions>

In an app made by `exact new`, run its own `exact.mjs` from the app's directory.
`bun exact.mjs update` regenerates that file, so the app's own verbs go in
`app.json`'s `commands` (`"seed": ["bun", "seed.mjs"]` is `bun exact.mjs seed
web`, run in the app's directory), which it reads and update leaves alone.
A command that prepares files a build reads but the app's repository does not
hold, such as a script that fetches photos into a folder Git ignores, goes in
`app.json`'s `before_build` (`["bun", "scripts/fetch.mjs"]`, where `bun` is
the Bun that runs `exact.mjs`, so it runs on every host): each verb that
builds, runs, compiles or checks the app runs it first in the app's
directory, and stops if it fails. Make it finish at once when the files are there.
`exact.mjs`'s `contract` verb is Exact's compiler, with paths relative to where you run it:

```sh
bun exact.mjs contract types app.contract -o app.contract.d.ts   # what app.ts imports
bun exact.mjs contract build app.contract --json
bun exact.mjs contract symbols app.contract
bun exact.mjs contract fmt --stdout app.contract
bun exact.mjs contract vocab padding                              # is it accepted, and how
bun exact.mjs web
```

Inside the Exact checkout, for its own apps, the same commands are
`cargo run -q -p contract -- <command> apps/<name>/app.contract …` and
`bun host/web/dev.mjs --app <name>`. Run `bun install --frozen-lockfile` there once.

To preview a component declared in your app's root, add a frame such as
`frames/card.contract` inside the app. Its first component is the preview's
root. It can pass props to the app's components and use the app's data handlers.

```text
use Inspector from "../app.contract"
component Frame
  view
    Inspector(title="Card")
```

Run `bun exact.mjs web` from the app directory and open
`/__dev/frames/card/` on the dev server. Each `frames/<name>.contract` has
its own URL. Editing a frame refreshes the pages whose compiled content
changes. An error appears in the affected frame, which keeps its last good
view while you edit. The server builds up to half the available CPU count in
parallel (at least one frame), with open pages first. The app builds
independently. On a shared 12-core M4 Pro, opening 20 frames with six builders
took 6–13 s and peaked at 1.5–1.7 GiB. An unbounded run took 8.9 s and
peaked at 3.3 GiB. The limit can delay the last frame on a busy machine. A change
to an input with unknown readers rebuilds every active frame. Frame URLs
serve the app’s public `assets/` and `deck/` files on request. A changed
public asset refreshes the frames that name or requested it. A file whose
bytes enter the compiled output rebuilds its readers.

To supply sample data, place a TypeScript module named `card.fixture.mts`
beside `card.contract`. Export an object keyed by the app's TypeScript
source names. Each handler receives the same arguments as its handler in
`app.ts`. This frame gives `frameData(title)` a fixed size.

```ts
import type { TypeScriptSources } from '../app.contract.d.ts';

export default {
  frameData: ([title]) => ({ title, width: 320, height: 200 }),
} satisfies Partial<TypeScriptSources>;
```

The frame calls the fixture for `frameData` and the app for every other
source. A fixture can return an empty list or throw to exercise an error
state. Editing or removing the fixture updates its frame. The app's release
build and other frames use their own handlers.

From the Exact checkout, build the frame with
`bun host/web-js/build.mjs /path/to/app --frame frames/card.contract --out /path/to/app/target/card`
and serve the output directory. The app supplies the design, theme and declared
data sources. A frame that needs navigation declares its own routes.

Use `build --json` before and after the edit. It returns one JSON array with all
independent diagnostics it can collect, capped at 20; success is `[]`. It is the
whole output: stderr stays empty (but for a note while the compiler first
builds), and `bun exact.mjs contract build`
appends `app.ts`'s type errors (`typescript-TS2322`, …) to the same array. Keep the
exit status: 0 success, 1 compilation/I/O failure, 2 invalid invocation. Read all
diagnostics, including related locations, before making the next repair. Each has
a `severity`: `"error"` refuses the build; `"warning"` (after the errors, also on a
success) builds and runs but is not what you meant, such as a header node the iOS
bar hides (`lower-header-unplaced`: beside the heading in its own box), a route's `header` a box below the route,
which iOS leaves in the page (`lower-header-nested`), a heading header at the head of
an app with no navigation route (`lower-header-routeless`: a lone `navigationKey`
is only a root; add a navigation root holding
a separately keyed screen whose first child is the header, or give the header
`appearance="none"` to keep it drawn as written on iOS), a content heading that says the bar's title
again (`lower-title-twice`), a tab bar of one tab (`lower-single-tab`), a
`button` with no words and no `aria-label` (`lower-button-unlabelled`), a dialog's
role on a box (`lower-dialog-role`), an `aria-level` with no `role="heading"`
(`lower-level-without-heading`), a content-box `width="100%"` with padding, wider than
its parent by the padding (`lower-width-padding`), a positive written border width without
a written line style (`lower-border-unstyled`), a box whose fixed width ceiling cannot grow
with its text at accessibility sizes (`lower-text-px-width`; use `rem` for the width and its bounds), a bare
`line-height=28`, which is 28 times the font size, not 28 points (`lower-line-height-multiplier`),
screens swapped by an `if` over a state, at the top of the view or inside a route (`lower-screen-by-state`), a count before a plural noun, `${n} cards`
(`lower-count-plural`), a row of the app's records that searches another table of them,
`users.filter(u => u.id == p.userId)` in `for p in posts` (`lower-row-lookup`), a
row that walks its own list, `tokens.slice(0, i)` in `for t, i in tokens`
(`lower-row-own-list`), a
symbol by an alias, not its role (`lower-symbol-alias`), a
`performanceNow()` time sent to a source (`type-performance-now-persisted`), the
launch's `time.epochAtZero` or `time.seed` as a resource's identifying argument, or a
value equal to one at launch (`time.epochAtZero + tick * 60000` while `tick` starts at
0), which keeps its kept answer from ever showing at launch: pass it after `with`
(`lower-resource-launch-identity`), a
state read after its own action assigned it (`analyze-read-after-assign`), a
literal colour that stays the same in dark mode (`lower-colour-one-scheme`: a build's
text says several in one line, its first three sites; `--json` names each), a `list` holding a `section` with no `appearance`, which is neither
a grouped list nor a list of cells (`lower-list-section`), and a
name or key a host would refuse or ignore at run time: a
swipe row's `swipeTrailing` naming a button outside its `scroll` (`lower-swipe-wiring`),
a navigation root's `navigationKey` that never meets its routes' (`lower-navigation-key`),
a literal `navigationSplit` no host reads, such as `"none"` on a box that is no route (`lower-navigation-split`; under
the same id the build fails for a computed one on such a box, which could be a placeholder the compiler cannot place,
and for a `"placeholder"` that is no plain box, outside every route, not its route's own child, repeated by a `for`
inside the route, a popover or with a `portal` other than the literal `portal=""`; which route is a stack's first, whose placeholder shows, is known
at run time), an `image` source
that is a bare word, neither a symbol nor a file (`lower-image-source`), an `image`, `video` or `audio`
file outside `assets/`, which the app would ship without (`lower-asset-path`), and a literal `RoundButton`
label of more than the 7 characters its circle holds (`lower-round-button-label`); each names its repair, and fixing it is part of the edit.

Formatting is explicit. `fmt --stdout` previews, `fmt --check` checks, and plain
`fmt` writes. Formatting changes spacing and breaks only: a result that would
parse to a different program is refused (`fmt-tree-change`) and nothing is
written. Avoid formatting unrelated files. `symbols` reports definitions
and references, with component interfaces and inferred action effects. Search
by exact name with `symbols file.contract --name name`.

After compiling, build and drive the actual app. From an `exact new` app:

```sh
bun exact.mjs test web                          # the app's *.test.contract; builds a stale web app first
bun exact.mjs agent web tree "tap add" state logs "screenshot out.png"
bun exact.mjs agent web --size 390x844 "screenshot phone.png"   # a phone-sized viewport
```

On macOS and the iOS simulator, `agent` and `test` check the native build once
at startup and use it for every launch, including an authored test's `reload`
(LLP 1012.001.000 D1). Edits made during the run are checked by the next run.

The web carrier opens at 420×900; `--size <w>x<h>` (before the operations) opens
another viewport, and a test's first step `size <w>x<h>` does the same for that test.
`resize <w>x<h>`, an operation and a test step, resizes it mid-drive as a person
dragging the window's edge would: the browser's viewport, a macOS window, the
Linux presenter (the driver's op also takes `resize <w> <h>`; a test step takes only
`<w>x<h>`). iOS refuses a mid-drive `resize`; a size given at launch (`--size`, a
test's `size` line) is laid out at that viewport, scaled to fit inside the device's safe
area, so no safe-area inset, layout region or route's clearance is the device's, only
what UIKit's bars cover. The hinge is read where it crosses the viewport.
`close`, an operation and a test step, presses the window's close button as ⌘W
or the red button would (the agent's window is never key, so a typed ⌘W reaches
nothing): the window asks its `beforeunload` first, and the reply says
`closed: true`, or `closed: false` for a window a handler kept (the web's
"Leave site?" is answered "Stay"). macOS and the web; iOS and Linux refuse it.
`--storage <name>` gives a drive a named scratch store, kept between drives on
macOS, iOS and Linux until one passes `--reset-storage`, and on web Chrome when the
next drive passes `--keep-storage` (a browser profile served on one port per
name; a Firefox or WebKit drive starts fresh each time, so a name there lasts
for the drive, including its `reload`). A native drive that names none uses the
store `default`, kept the same way, as the app keeps its files from launch to
launch. A drive that compares with a reference (`screenshot … compare`) starts
empty on every host unless it passes `--keep-storage`, so a plain drive after
one can show what an earlier plain drive stored. A web drive without one has no
app storage: an `app:/` file read finds an empty store (code `ENOENT`, as a
fresh install's first launch does), and a write or SQLite request is refused (`storage
is unavailable in agent mode unless the drive names a scratch store (--storage
<name>)`), so an app that keeps its data there does nothing on a write; a chosen document (`doc:/`)
still opens under its grant. That store, and an authored test's own store, includes
a data module's `secret.keep`: files in the named scratch tree on Apple and Linux,
and the page's `localStorage` on the web ([web sessions](https://exact.expo.dev/recipes/web-sessions.md)).
Apple native modules use that store's data, cache and temporary roots too; a fresh
drive clears them, and only picked temporary documents are cleared on each launch.
A nameless drive keeps no secrets.
To show what survives a restart on any host, use an authored test's `reload` step (below).

The driver prints each reply in a short text form. A `tap` or `type` is one line
(`tapped #15 "add" · delivery platform · epoch 2 · clock 0 ms`); a failed one starts
with `ERROR`. `state` prints one line a section (`slots {"count":1}`) and leaves out
the empty ones (null, `[]`, `{}`); one over 8 KB prints its size, its small sections,
the others' sizes, and how to read one (`state resources`, `state feed.0`) or all of it
(`state --full`). `state <name>` reads a state, derive, resource or section of the
record, even where a view carries the same name. Every other reply is one line too
(`clock 600 ms · settled · epoch 5`, `screenshot out.png · 420×900 · …`).
`--json` prints every field of every reply, one JSON object a line.
`--scale <n>` shrinks each screenshot to n pixels a point: an iPhone's are
1206×2622 at its own 3, 402×874 with `--scale 1`, one pixel a point as on the
web, at about a ninth of the pixels. An app's `bun exact.mjs agent ios|macos`
takes `--scale 1` unless told otherwise; ask for more only to check fine pixels.
On a physical iPhone (`agent ios --device`), a still screenshot takes the display
through Xcode (`pixels="display"`), including video, system bars and the visible
software keyboard. Its dimensions are in screen points (`captureSpace="screen"`)
when the app can confirm them. Otherwise the driver keeps the original PNG at
its native pixel size and reports those dimensions with `scale: null`.
A still taken during a held contact also uses the display and skips the motion wait.
The driver checks app focus before and after capture. If focus changes or it
cannot confirm focus, the reply notes that the display may show another app
or a system overlay. Scaling a display still keeps its embedded RGB colour profile.
`check` uses the same display source on a phone. If the capture cannot be
matched to the app's observation, `check` retries once and reports an
incomplete check if the retry fails.
`window app` and timed films take the app's drawing (`pixels="app"`).
On a simulator, `screenshot <png> display` takes the full screen and reports the
same screen geometry and keyboard fields. A display reply names authored header
nodes UIKit's navigation bar omits under `unshown`.
On a simulator a `window` screenshot's pixels are the display's (`pixels="display"`):
glass, blur and the keyboard as the device draws them. So are a plain one's where glass
or a blur lies in the page; where the display cannot be read (the app not in front, an
overlay) the reply says its materials are approximate, and why.

Inside the Exact checkout, for Caltrain:

```sh
bun host/web/build.mjs caltrain-web
bun scripts/agent.mjs web tree "tap change-station" "type station-search Palo" state logs
bun scripts/agent.mjs web --test apps/caltrain/app.test.contract
```

For an external app driven from the Exact root, set `EXACT_APP_DIR` on both build
and drive. A stale
artifact is a failed verification; rebuild what the driver names. A successful
Cargo rlib build does not prove a native app launches or behaves correctly.

tvOS uses the iOS presenter and plan: `bun host/apple/build.mjs --tvos
caltrain-apple --run` builds and launches on an Apple TV simulator. TypeScript
apps provision lean Hermes for `tvos-simulator` once per machine. On a container,
`focusGuide="auto"` makes an entering remote move return to its last focused
descendant, or its first focusable descendant. Other hosts ignore it, including
when the value is bound. The agent driver has no tvOS target yet.

A script drives the same session in JavaScript: `const s = await open({ host:
'web', app, epoch, timeZone, storage, size: [390, 844] })` from `scripts/agent.mjs`
(`size` is `[width, height]`, or the CLI's `'390x844'`), then
`s.tap(target, opts)`, `s.type(target, text | { key })`, `s.clock(arg)`,
`s.tree()`, `s.state()`, `s.logs()`, `s.layout()`, `s.screenshot(path)`,
`s.resize(width, height)`, `s.prefer({ … })`, `s.perf(target)` and `s.close()` — the
CLI's operations by the same names. Their replies are the CLI's `--json` output: `s.tree()`
is `{ roots, nodes: [{ id, type, depth, props: { testId, text, value, … }, children }] }`,
every node in one preorder list (`depth` and `children` give the nesting),
with `generation`, `epoch`, `incarnation` and `clock` on replies. `generation` advances
once per committed replacement or carried reboot; `epoch` continues across it, while
a new kernel can repeat `incarnation`. `state.replacement` names root slots dropped
because they are gone (`no place`) or their type changed (`type changed`).
`s.state()` is `{ slots, derives, resources,
pending, … }`. `app` is the app's name; an app outside the Exact
checkout is found through `EXACT_APP_DIR` (its directory), as its own `exact.mjs agent`
sets it, so a script run with plain `bun` sets it to the app's directory too
(`EXACT_APP_DIR=/path/to/app bun verify.mjs`; a script that `app.ts` never imports
is no build input); the working directory alone does
not select the app, and `webDist` alone does not select an app. `s.op(request)` is the
host's wire beneath them: it addresses views by numeric `id`, and it refuses a
request it would answer by doing nothing (a `target`, an unknown op, a web
`tap` with no browser input behind it). A reload or a raw browser step goes
through `s.carrier` (`reset({keep: true})` reloads the current browser history
entry with its store and agent launch facts, keeping Back and Forward entries;
`evaluate`, and on Chrome `call`, drive raw browser steps;
`evaluate` takes an expression string or a function of no arguments, which runs in the page,
so it sees none of the script's variables).

Use the existing six repository checks for repository changes. Do not add a
new global check or fixture framework for an ordinary app edit. For documentation,
compile complete examples, parse authored tests, and check local links.
