The Contract language
A practical reference to Contract as Seed Exact uses it: every construct with a real example from the app, the purity rules, the root-only rules and the compiler commands.

Contract is Exact's declarative interface language. A .contract file describes what the app shows and how its state changes. It cannot fetch, read files or run arbitrary code: that is the job of the data module. This page is a lookup table for the constructs the app actually uses. The full language is in Exact's grammar and guide for agents.

Syntax in one paragraph

Indentation with spaces makes blocks. Top-level declarations start in column 1. Tags are HTML element names and attributes are CSS properties or element attributes (padding=16, flex=1, color="-exact-label"). A bare number is pixels, units are quoted ("50%"). Names may contain hyphens, so subtraction needs spaces (a - b). Comments are //. Strings use double quotes, templates use backticks.

Declarations

Construct

Real example

Source

use … from

use Avatar, StatusLine from "./ui.contract" and use EmptyState from "exact:content"

app.contract L4-L17, activity.contract L2

shape

shape Time with epochAtZero: number, utcOffset: number

app.contract L22-L24

fn

fn tid(active: bool, name: string): string = active ? name : ""

read.contract L90

atom

atom agentDocument link="hm:" color="brand", used with atoms= and atompress= on Markdown text

agents.contract L5, L559-L561

routes

routes nav with tab read "/" and doc "/d/:ref"

app.contract L26-L65

component, props, view

component StatusLine with message: string, retry: action

ui.contract L23-L31

inject / provide

The root provides discussions, readNow, readUtc; DocScreen injects them

app.contract L736-L741, read.contract L270-L274

State and data, inside a component

Construct

Real example

Source

state … persist

state server = "https://hyper.media" persist

app.contract L76-L77

typed state

state meServers: string[] = [] persist

app.contract L218

derive

derive activityActive = nav.tab == "activity"

app.contract L132

resource … as shape … else empty()

resource docs = readDocs(server, readRefs, readEpoch) as shape DocPage[] else empty()

app.contract L103

with

resource vaultStatus = vaultRead(meIds) with time.epochAtZero as shape VaultStatus else empty()

app.contract L254

mutation … refreshes … then

mutation discussPosted as shape DiscussReply refreshes discussions, discussThreads then discussAfterPost

app.contract L118

mutation … queue

mutation vaultEdited as shape VaultStatus queue refreshes vaultStatus, meIds

app.contract L257

task … mount

task readClock mount then every(60000, readClockStep)

app.contract L90-L91

task … when with every

task vaultPoll when vaultStatus.connection == "pending" and vaultPage.visibilityState == "visible" then every(2000, vaultPollTick)

app.contract L261-L262

task … when … key with after

task activityWake when activityActive key = … then after(1, activityAsk)

app.contract L141-L142

action

action readOpenDir(uid: string) then nav = push(nav, path("directory", uid))

app.contract L316-L317

send

send discussPosted = discussPost(readContextServer, currentAccount, target, parent, text, time.epochAtZero + performanceNow())

app.contract L340-L343

refresh

refresh docs

app.contract L308-L309

let

let n = back(nav) then nav = push(n, path("doc", r.url))

app.contract L302-L303

match on an option

match first(docs.filter(d => d.ref == readContextRef)) { case some(d) => d.server, case none => server }

app.contract L97

match block in an action

match readSiteOpened with case some(r) and case none arms

app.contract L295-L305

reset a mutation slot

meExported = none

app.contract L600-L604

pending, failure

pending(readSiteOpened); match failure(activityData) { case some(f) => f.message, case none => "" }

app.contract L292, L137

A resource is asked again whenever one of its arguments changes. The app refetches on purpose by changing an argument, see State, refresh and stale-reply patterns. with appends arguments that should not count against a kept answer at boot. A mutation reads as option<T> and starts at none.

Views and built-in calls

Elements, attributes, navigation attributes and built-in calls such as share, haptic and openURL are on their own page: Contract views and built-in calls.

Purity rules

From Exact's start-here guide and README:

    No truthiness. Conditions are bool: write draft.trim() != "".

    Absence is an option, none or some(x), read with match. There is no null.

    Values never change. Build a new one: xs.concat([x]), or a record copy Shape(old, field=value).

    == compares lists and records by value.

    State changes only in actions. "Nothing runs because a value changed: an event runs an action." Writes land when the action ends, so a later line reads the old value. Bind with let when the new value is needed.

    No loops in actions and no await. Lists are a view's keyed for. Computation is a derive or fn. Anything slower lives in a source.

Root-only rules

resource, mutation and task may be declared only in the root component, and routes only in the root file (language inventory). That is why app.contract holds every one of them and passes data and actions down as props. Child components may hold their own state, derive and actions. persist is for root state only.

Compiler commands

Command

What it does

bun exact.mjs contract build app.contract --json --errors-only

Compile, rewrite app.contract.d.ts, and type-check app.ts. [] and exit 0 mean no errors

bun exact.mjs contract fmt <file>

Source-preserving formatter (--check to verify)

bun exact.mjs contract vocab [<name>…]

No name prints the card (docs/card.md). A name prints a keyword, tag, function or recipe

bun exact.mjs contract types app.contract -o app.contract.d.ts

Generate the Sources, Answer and Result types app.ts imports

More verbs are in Commands and verbs.

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime