matter.work
Building Apps / Foundations

One-page apps

The quickest app: one HTML page an agent writes, with saved state and a builder thread, and no project, build or key.

The quickest Matter app is one HTML page, with its scripts and styles inline: a calculator, a chart, a checklist, a prototype. An agent writes the page and gives it to Matter, and the app opens at once. There is no folder, no build, and no signing key.

Start here. Move to a project when the app needs its own tables, more than one page, routines, a worker or tools.

Making One#

Ask for it in any thread, or click New App on the Apps page (⌘7). Either way an agent makes it with the manage_apps tool:

Action What it does
create Makes the app from a name, with html for its page. Without html the app starts empty.
read Returns the page and the app’s saved state.
update Changes the page: html replaces all of it, and edits change parts. Each edit replaces old_text, which must occur exactly once, with new_text. Edits apply in order, all or nothing. state sets keys in the saved state.

Every change to the page is a new version, and it becomes current at once. Versions in the app’s menu lists them and rolls back. A page holds up to 1 MB of HTML.

The app starts private to whoever asked for it. They share it with Access and Published in its menu, as with any app.

Saved State#

What people enter in the page belongs in the app’s state: a small JSON object that Matter saves, syncs to their other devices, and shares with everyone who uses the app. It is on window.matter.state before the page’s first script runs:

A list that remembers its items
<ul id="list"></ul>
<script>
  const { state } = window.matter
  const draw = ({ items = [] }) => {
    document.getElementById('list').innerHTML = items.map((item) => `<li>${item}</li>`).join('')
  }
  draw(state.get())
  state.onChange(draw)

  function add(item) {
    state.patch({ items: [...(state.get().items ?? []), item] })
  }
</script>
  • get() returns the state now, with no request.
  • patch({ key: value }) sets the keys given, each whole; null removes one. The page sees it at once, and it saves from there, waiting if the device is offline.
  • onChange(fn) hears every change, made here or anywhere else, and returns a function that stops it.

Matter merges changes a key at a time, so two people changing different keys both land. Two changes to the same key don’t merge: the later one wins, so give things that change apart their own keys. State holds up to 64 KB; past that, use a table. Agents read it with read and set keys with update.

A project’s pages have the same object as matter.state in @matter.work/app-sdk, since Matter 0.5.31.

The Builder Thread#

Each member has one builder thread per app: the conversation where they build it. It docks at the right edge of the app’s page, and Open Builder in the app’s menu brings it back.

  • Each of its turns is told the app as it is: the page (when it’s small enough to send whole), its saved state, and what the member has on screen. So “make this bigger” needs no read first.
  • A turn that makes a version ends with Undo and Redo, which make the version before or after it current.
  • An agent makes a conversation an app’s builder thread with manage_threads attach (app_id), or sends work into one with start.

Projects have a builder thread too. There the agent changes the project’s files and deploys with matter app deploy.

Look#

Style the page with Matter’s --matter-* variables, which every app page has, so it fits light and dark. To compare designs, show them in one page with a switcher rather than as separate apps.

What It Can’t Do#

Nobody signs a one-page app’s versions, so it only ever has its page: no worker, no tools, no routines and no connections. It opens for everyone it’s shared with on the first click, and for anyone but the member whose agent made it, its page is limited.