The data, replication, agent, and view packages wired into one application. It runs entirely
in-process — an in-memory SQLite database and a durable journal, no server and
no browser — so the transcript is deterministic and needs nothing running.
For URL and browser-storage mirroring, see
examples/todo-app.
- Follow
Projectfrom its SQL binding in stack.ts to theReady Apolloread in demo.ts. This is server-owned data; the client's Remote cache can be rebuilt. - Follow
notesthrough the Sync contract and journal. These are client-authored operations; losing a pending outbox entry loses intent. - Follow one agent capability back to the same application Message. The
agent is bound to
Agent.headless, the application's ownupdate, Commands and Subscriptions run with no view (Remote's read of the Board among them), so the runtime owns the Model and the agent only sends Messages. The protocol adapters change how it is called, not who owns the transition.
requested_create_note completes on the note's state (Agent.when), not on a fact
Message. The caller names the id and update adds the note in the same
transition, so no later Message says "created", and only a call naming this
id can make the state hold. Waiting for the id alone would lie: update
drops a create over a taken id (a durable operation can be replayed), so a
second create for n1 would read as done while the old body stayed.
The predicate checks the body too, and a dropped create ends at its
one-second timeout (test/completion.test.ts). Dispatched by constructor,
the outcome is typed as a state reached, with no Message on it. Where the
application mints the id, only a fact can say which record is the call's:
examples/todo completes on SubmittedTodo with correlate.
Start with Remote or Sync if the first two paths are unfamiliar. The kitchen sink is a composition example, not a minimal template that every application needs to copy.
pnpm install && pnpm build # from the repository root
pnpm --filter foldkit-example-kitchen-sink demopnpm demo at the repository root runs it with the other examples. Read
src/stack.ts first — it is the one application every package below hangs off —
then src/demo.ts, which drives it.
plan: Project:p1 [id,name,status,owner]
before fetch: Initial
after fetch (Drizzle SQLite): Ready Apollo
nested selection (one read): owner Ada
mutation (remote-1): MutationSucceeded -> Ready Apollo II
live (published by the mutation): EntityPatched id,name,status=Apollo II
query page: p2, p1
optimistic insert: p3, p2, p1
confirmed insert: p3, p2, p1
inspect: 4 entities cached
retained with the page: Project:p1, User:u1, Project:p2, Project:p3
retained by the Board alone: Project:p1, User:u1
hydrated: Ready Apollo II, plan empty
replicated (durable journal): First note
headless board (read by its Subscription): Ready Apollo II
capabilities: requested_create_note, rename_note, selected_note, complete_task
agent context: {"notes":[{"id":"n1","body":"First note"}],"selectedNoteId":null}
agent create: completed
notes after agent: First note, From the agent
webmcp tools: requested_create_note, rename_note, selected_note, complete_task
webmcp call: Completed: RequestedCreateNote reached its declared state
mcp tools: requested_create_note, rename_note, selected_note, complete_task
a2a card: Kitchen Sink (4 skills)
notes after A2A: First note, From the agent, From WebMCP, From A2A
native actions: requested_create_note, rename_note, selected_note, complete_task
rendered classes: board
mixins-ui button classes: save
test/demo.test.ts pins the lines that carry the claims, so the example cannot
quietly stop demonstrating them.
| Layer | Package | In this example |
|---|---|---|
| Observation | foldkit-surface |
One Surface.application embeds the Remote submodel beside the client-owned notes slice; BoardSurface projects both. test/module.test.ts validates the whole set of contracts. |
| Server-derived state | foldkit-remote |
The normalized cache submodel: Data.prefetch, live(Data, …), Data.mutate with an optimistic ConnectionChange, Data.query, Data.inspect, Remote.retain, and RemotePersistence.dehydrate/hydrate. |
| Server | foldkit-remote-server |
RemoteServer sources compiled to RemoteServer.handlers, served in-process through Remote.clientLayer over the database layer; a liveHub given to the handlers publishes what each mutation answers, which feeds the live subscription. |
| Server SQL | foldkit-remote-drizzle |
Project and User are Drizzle bindings over in-memory SQLite tables; the nested owner selection, the reads, and the query compile to SQL. |
| Client-owned state | foldkit-durable |
A Journal.make over the Sync contract orders the notes operations. |
| Replication | foldkit-sync |
A replica, an in-memory Storage, and replica.start exchanging through a TransportClient. |
| Agent | foldkit-agent |
One contract projected from the same Model and Messages, bound to a headless runtime of the application. |
| Agent browser | foldkit-agent-webmcp |
The contract registered into a document.modelContext stand-in. |
| Agent external | foldkit-agent-mcp |
The transport-free MCP handler answers initialize and tools/list. |
| Agent A2A | foldkit-agent-a2a |
An Agent Card and a message/send task. |
| Agent Native | foldkit-agent-native |
The contract compiled to package actions. |
| View | foldkit-mixins |
A Slots contract and a Style attached to it. |
| View + Surface | foldkit-mixins-surface |
SurfaceView.define binds BoardSurface's projected Model to the slots. |
| View + UI | foldkit-mixins-ui |
A @foldkit/ui Button customised through Button.resolve without copying it. |