The workspace store and its command journal#
Status: accepted · Date: 2026-10-11
Context#
The workspace is an immutable plain value, the view, changed only by the four
commands add, set, remove and style through the pure apply(view, command). The editor needs undo and redo, needs to know who changed what and
when, and needs a file that people and agents can read, diff and edit with
ordinary tools. No dependency is involved: this decision records how core
holds history and writes the file, so that later changes know what they
must keep.
Considered options#
A journal in the file. Every accepted command is kept as an entry
{command, author, time}in the workspace file beside the snapshot{meta, settings, blocks}. The journal is the undo stack.Undo in memory only. The file holds the snapshot; undo history is lost when the editor closes and authorship is not recorded.
Inverse commands. Each command computes its inverse for undo. Every command kind then needs a second, separately tested reducer, and the inverse of a whole-manifest
setis a whole manifest anyway.
Decision#
Keep the journal in the file. createStore(workspace, {author, clock, minter}) stamps each accepted command with its author ("Gerhardt" until
setAuthor) and clock().toISOString(), ISO 8601 UTC with milliseconds, and
appends the command as parseCommand normalized it, with the IDs of every
element it created (below). undo moves the last
entry to an in-memory redo stack and restores the previous view; a new
command clears the redo stack. The views of the session are kept, sharing
every unchanged block, so undo and redo within a session return the very
same objects. Undo past the session’s first entry replays the journal once
from the empty workspace (createView(), default settings) and keeps every
view of that replay.
The journal is the authority: replaying the whole journal from the empty
workspace reproduces the snapshot’s settings and blocks exactly. It holds
because apply is pure and deterministic and the journal carries every ID a
command created; the property tests prove it over every manifest fixture with
generated command sequences.
The journal carries the minted IDs. An element a command creates
without an ID of its own (a named timestamp, an elision, a named MatchStamp
with its anchors and new match timestamps, a new root’s default timestamps, a
segment line’s first segment, a group, region, conversion map, flow-control
element, FlowMap or virtual timeline added without id) is given a random
ID, its type prefix, _ and 13 base-36 characters (TimeToShare’s README,
“Identity”). The reducer never mints: it takes each ID, in the order it
creates the elements, from the command’s ids list, and refuses a command
whose list is too short, or, once applied, longer than what it created
(invalid_command). dispatch applies the command with the store’s minter
behind the IDs the command carries (an agent may write its own), so the
minter fills what the list lacks, and journals the command with every ID it
took as its ids. A replay reads them from the journal and mints nothing, so
it reproduces the view whatever minter the replaying store holds. The minter
(createIdMinter, workspace/ids.ts) is seeded with 64 random bits per
store, or with a seed a test gives; from one seed it mints exactly the IDs
timetoalign’s minter mints, since both pass the minted-ID vectors that
TimeToShare ships (fixtures/ids/minted_ids.json). store.minter() hands
out a copy of the store’s minter at its count, which mints what the next
dispatch mints without advancing the store’s; the canvas previews a gesture
with it, so a preview shows the IDs its release stores. Nothing is renamed: an ID a manifest already holds, given or
minted, is refused when the manifest is checked. A block or session ID is
ten random base-36 characters, carried in the command or the entry as before.
The workspace file’s version is 8 since its journal carries the IDs. A
journal written before (version 7 and earlier) holds commands whose IDs a
replay would have to mint again, which a random minter cannot do, so such a
file is refused for its version alone: “workspace version 7 was written
before IDs were journaled and must be imported again: import its manifests
into a new workspace”. There is no migration and no second minter that
would reproduce the old numbering. Amended
2026-10-19: createStore verifies it for every workspace it is given. It
replays the journal to its end, compares the result’s settings and blocks
with the snapshot, and throws JournalMismatchError {entry, path} naming the
first differing path when they differ, so a file whose journal was edited by
hand to disagree with its snapshot is refused (journal_mismatch) as any
unreadable file is, rather than opened with a history that undo would not
follow. readWorkspace keeps its cost and does not replay: reading and
verifying are two steps, both run when a file is opened.
writeWorkspace is TimeToShare’s dumps of {meta, settings, blocks, journal, sessions}; readWorkspace reads with TimeToShare’s lossless parseJson
(its parse validates one manifest and does not apply to the workspace),
refuses another format or version, any unknown or missing member and any
invalid manifest, and reads every block’s manifest through core’s one
manifest reader, normalizeManifest. Writing what was read gives the same bytes.
Superseded in part (2026-10-18). Undo and redo now move by steps. A change is one command at any depth, owned by the innermost editor session whose own entries hold it. A change the level in view owns itself, a command of the open editor’s session or, with no editor open, of the main journal, is one step; a maximal run of consecutive changes owned by one closed session is one step, so undo reaches into a closed session run by run. Redo re-applies the earliest undone step, so it mirrors undo step for step. The store keeps a count of applied changes per level instead of a redo stack, a new command discards the undone changes, and an undo past the views the store holds applies the changes from the latest view it holds, or from the empty workspace at the start of a loaded journal. The replay invariant holds as stated.
Amended (2026-11-26): a session states its kind where its target does
not. A fourth editor, the flow editor of a root’s FlowMaps, targets the
root’s address, which alone opens the root’s timeline editor. A session
closed in it is written {target, kind: "flow", entries}; every other
session stays {target, entries}, its kind the one its target opens, so
every file written before reads as it did, and the version stays 8. A
reader refuses any other kind (invalid_value, “a session states only
the kind flow”). A session reopens, unfolded, and an earlier session is
listed, only where both target and kind match.
Consequences#
Undo reaches back across sessions, and the file says who changed what and
when. The file grows with its history: every add of a block carries the
whole manifest, so a workspace’s text is roughly its snapshot twice.
Compaction (dropping or squashing old entries) is a later decision.
Budgets measured on an Intel Core i7-8750H, Node 22.23.2, each the median of
9 runs after a warm-up, with the core test suite running alone
(TILIE_MEASURE=<file>, tests/budget.test.ts): a workspace of the 23 manifest
fixtures in turn, with a journal of the block additions followed by moves.
Workspace |
Text |
|
|
one |
|---|---|---|---|---|
300 blocks, 1,000 entries |
2.6 MB |
175 ms |
94 ms |
0.28 ms |
10,000 blocks, 10,000 entries |
81.1 MB |
4,394 ms |
2,834 ms |
8.3 ms |
The budgets were first set at 50 ms to open (validation included) and to
save 300 blocks with 1,000 entries, and 1 ms for a command. The command
budget holds. Opening and saving did not: of the opening time,
TimeToShare’s parseJson takes about 88 ms on the 2.6 MB text and the
manifests’ validation about 30 ms; of the saving time, dumps takes about
60 ms. A command copies the map of blocks once, so its time grows with the
number of blocks: 8.3 ms at 10,000.
Given these measurements, the budgets were revised on 2026-10-11 rather than
the file format or the reader changed: opening and saving 300 blocks with
1,000 entries each take at most 250 ms; a command at most 1 ms. No speedup
work is planned; tests/budget.test.ts holds these limits, and a figure
beyond them fails the test. The test times each operation as the minimum of
5 runs after a warm-up, so it measures the code rather than the load of the
machine: inside the parallel suite a median reached 273 ms for opening while
the same code takes 175 ms alone, and even the minimum exceeded the limit
when other work loaded the machine. The budget test therefore runs on its
own: the default pnpm test excludes it, and pnpm test:budget runs it
with the other budgets in one run, one file at a time; each limit is
checked softly, so every figure beyond its limit is reported.
On 2026-11-21 the opening budget was raised to 300 ms, saving and a command unchanged. Schema 0.2.0’s manifests gained resources, named MatchStamps, provenance beliefs and a JSON-LD context of 35 terms, which every manifest of the budget’s workspace carries and every validation reads: opening the same workspace went from about 235 ms to about 260 ms, with TiLiE’s own code measured unchanged between the two schema versions. The limit is that figure with the margin of about 15 % the MatchClaim anchor index’s budget keeps (decision 0029); a limit is raised only where the cost is inherent, never to hide an accidental one.
Opening and verifying the 300-block workspace with 1,000 entries,
readWorkspace followed by createStore, measured 497 to 501 ms on
2026-10-19 (the same machine, minimum of 5 runs after a warm-up, while other
work loaded it); the budget test prints this figure and sets no limit on it,
since the replay is the price of trusting the journal.
Exit cost: the journal is one array in the file and one module in core;
dropping it leaves the snapshot readable as it is. Dropping the ids of its
commands would make the journal a description no replay can follow.
Review date#
2027-04-10, or when a workspace file’s size makes compaction necessary.