Reading versions needs a publishable (
pk_) or secret (sk_) key with
worlds:read. Snapshotting, checking out, renaming, and pruning need a secret
key with worlds:write. Never ship a secret key to a browser.How the tree works
- A version is a full snapshot of a world’s graph at a point in time, plus
metadata:
id,parentVersionId,source,title, andcreatedAt. - HEAD is the version your working graph currently descends from.
- Snapshotting onto the current HEAD advances HEAD: a linear “save”. Snapshotting off an older parent forks a branch and leaves HEAD alone.
sourcerecords how a version was made:save,branch,manual,ai(an agent edit), orimport.- Pruning a version deletes only that node and re-roots its children onto its parent, so the tree never fragments. You can’t prune the version HEAD currently points at. Check out another version first.
Snapshot a version
Capture the world’s current graph as a new version. OmitparentVersionId to
snapshot onto the current HEAD.
List the tree
GET /v1/worlds/{id}/versions returns every node oldest-first. Rebuild the tree
from each node’s parentVersionId.
GET /v1/worlds/{id}/versions/{versionId}. It returns the version metadata plus
the complete snapshot world.
Check out a version
Checking out sets the working graph to a version’s snapshot and moves HEAD onto it, atomically. A later snapshot then branches off the checked-out version. The response carries the restoredworld and the new rev (also the ETag).
Like every world write, checkout honors If-Match / expectedRev and returns
409 if a concurrent edit advanced the rev, so a checkout never silently
clobbers an in-flight edit.
Diff two versions
GET /v1/worlds/{id}/versions/{a}/diff/{b} returns a pure structural diff
between version a (base) and version b (target). States are keyed by their
record key, events by their unique name. changed means present in both but not
byte-identical.
Rename a version
PATCH /v1/worlds/{id}/versions/{versionId} changes a version’s title and
nothing else: it never touches the snapshot, the parent pointer, or HEAD.
title is required. Send an empty or missing one and the call comes back 400.
The response echoes the versionId and the trimmed title.
Prune a version
DELETE /v1/worlds/{id}/versions/{versionId} removes a single version node. Any
children it had are re-rooted onto the pruned node’s parent, so the tree
stays connected. You never orphan a branch by deleting a node in the middle of
it. The response returns { ok: true, deleted } with the id you removed.

