Apps and publishing

An app is a folder of web files in the workspace. When it needs structured data, it binds to approved operations on one or more transactional Collections through app.publish.json and calls them over the dohc-app-channel MessagePort.

app.publish.json format

Place app.publish.json inside the app folder. Modern manifests omit inputs, packageMap, revision, and revisionSha256, and reference operations by name:

{
  "version": 1,
  "entryPath": "src/App.tsx",
  "dataset": {
    "kind": "dataset",
    "datasetPath": "tracker/dataset.json",
    "operations": ["listExpenses", "createExpense"]
  }
}

Rules:

Built-in app kit and TypeScript/JSX

The closed app compiler bundles .ts, .tsx, .js, .jsx, and .css with extensionless relative imports and ships a built-in kit without needing node_modules:

Other packages, including lucide-react, need their files in the app folder and a packageMap entry.

Choosing styles

New apps from dohc_create_app start with plain React and src/styles.css, without importing dohc/ui.

Calling Collection operations (dohc-app-channel)

The host delivers one MessagePort to the app window on load. Wait for { kind: "dohc-app-channel", version: 1 } and send backend.invoke messages on that port:

let channelPort;
const pending = new Map();
const queue = [];

function send(message) {
  return new Promise((resolve, reject) => {
    const id = crypto.randomUUID();
    const frame = { id, ...message };
    pending.set(id, { resolve, reject });
    if (channelPort) channelPort.postMessage(frame);
    else queue.push(frame);
  });
}

window.addEventListener("message", (event) => {
  if (
    channelPort ||
    event.source !== window.parent ||
    event.data?.kind !== "dohc-app-channel" ||
    event.data?.version !== 1 ||
    event.ports.length !== 1
  ) {
    return;
  }
  channelPort = event.ports[0];
  channelPort.onmessage = ({ data }) => {
    const req = pending.get(data?.id);
    if (!req) return;
    pending.delete(data.id);
    if (data.ok) req.resolve(data.value);
    else req.reject(new Error(data.error?.message ?? `Request failed (${data.status})`));
  };
  channelPort.start();
  while (queue.length) channelPort.postMessage(queue.shift());
});

// Single-Collection call (add `dataset: "<alias>"` for multi-Collection apps):
// const { result } = await send({
//   op: "backend.invoke",
//   operation: "listExpenses",
//   input: {},
//   idempotencyKey: crypto.randomUUID(),
// });

Other channel operations: backend.upload (name, contentType, bytes as a transferred ArrayBuffer up to 20 MiB, idempotencyKey), backend.file (fileId, operation, input; replies { file, bytes } with bytes as a transferred ArrayBuffer), backend.attempt (operation, request), host.copy (text, up to 65,536 UTF-8 bytes, user-activated), host.print (optional height, 1 to 50,000 CSS pixels, user-activated), and for document-Collection share-link apps: collection.list and collection.create.

Sandbox constraints (window.origin === "null")

Every app runs in a sandboxed srcdoc iframe with an opaque origin (window.origin === "null"), without allow-same-origin or allow-modals:

Verifying an app frontend (dohc_publish_app verifyFrontend)

verifyFrontend works only in a workspace you own; in a workspace you joined, check a Personal app's source with checkLocal and its appRoot from personalFolder. Before publishing or handing an app to a user, verify its compiled frontend inside dohc's real sandboxed document, CSP, and dohc-app-channel broker with { action: "verifyFrontend", workspaceId, appRoot } (candidate source) or { action: "verifyFrontend", workspaceId, publicationId } (active local publication, or a workspace-audience app's served bundle; add memberId to run as one member's actions). Specify exactly one of appRoot or publicationId.

{
  "request": {
    "action": "verifyFrontend",
    "workspaceId": "<workspaceId>",
    "appRoot": "apps/booking",
    "steps": [
      { "kind": "fill", "selector": "#name", "value": "Ada" },
      { "kind": "fill", "selector": "#seats", "value": "5" },
      {
        "kind": "click",
        "selector": "#submit",
        "expectBackend": { "op": "backend.invoke", "operation": "createBooking", "status": 200 }
      },
      { "kind": "waitFor", "selector": "#status", "textIncludes": "Booked" }
    ]
  }
}

Local approval, staging, and launch (dohc_publish_app)

Pass { request: { action, ... } } to dohc_publish_app:

createLink, prepare, and approve need a workspace that syncs with a server. Without one, they fail with "Sync this workspace before sharing." Check live sync with dohc_workspace_status or dohc workspace status (role, synced, sync.state, sync.caughtUp, sync.pendingChangeCount, sync.lastSyncedAtMs, syncFailure). The synced field in .dohc/sync-history.json does not show whether the workspace syncs now. For regular file and note writes, sync.state and sync.pendingChangeCount cover edits the engine has already recorded, so also verify that sync.lastSyncedAtMs is later than the write and pendingShare is empty. After approve, link holders' reads and writes run on that server, so the app works while the owner's computer is off.

  1. Create link: { action: "createLink", workspaceId, appRoot, operationId: "<fresh UUID>" } -> returns shareId, grantId, and one-time bearer url. Reuse the same operationId on retry.
  2. Prepare: { action: "prepare", workspaceId, appRoot, shareId, grantId } -> returns approvalId, candidateDigest.
  3. Approve: { action: "approve", workspaceId, approvalId, candidateDigest } -> returns publicationId and appQuery (?app=<publicationId>).
  4. Append appQuery before the # fragment of the share link URL. Keep the share link secret out of workspace files and dohc requests.

A share link URL is a bearer credential at its stated access level: anyone holding it can use it. An app for members returns no appQuery. Rotating a link stays in the desktop. agentLabel values are what the agent declares, shown as provenance.

Personal apps (only in a workspace you joined)

"Personal app" means a private local app inside a workspace someone else owns (role: "joined" in dohc_workspace_status or dohc workspace status). It does not apply to a workspace you own (role: "owner"), even if that workspace is named "Personal".

In a workspace you joined, you can open workspace apps published by the owner (dohc_list_member_apps) and build private Personal apps on this computer. personalFolder returns your Personal app folder on this computer. prepareLocal, listLocal, and checkLocal take one of its subfolders as appRoot, and approve, cancel, launchLocal, and withdraw work as they do in a workspace you own. A Personal app stays on this computer, never syncs, and runs only the Collection actions your own access allows.

Opening an app on another device and publishing to workspace members (dohc_publish_app)

Apps reach other devices in three distinct ways:

Re-approving apps after a standalone Collection migration

  1. Inspect boundApps returned by prepareSchemaChange, prepareMigration, prepareRelationChoices, prepareHistoryRestore, or dataset permissions.
  2. Each entry reports scope ("local", "link", "workspace", or "owner"), appRoot, shareId/grantId (for share links), status ("compatible", "needs-refresh", or "incompatible"), and plain-English reasons when incompatible. If boundAppsIncomplete is true, check dataset permissions after applying the change.
  3. For "incompatible" apps, update the app's source or app.publish.json to match the changed actions or fields first.
  4. For older apps whose app.publish.json still pins revision and revisionSha256, remove those two fields once.
  5. Re-approve each affected local app with prepareLocal + approve (or stage + approveStaged), and each affected share-link app with prepare + approve using its shareId and grantId. Re-publishing a share-link app returns a new appQuery (?app=<newPublicationId>); withdraw the previous publicationId explicitly when ready.