thcThought Control

The event log

The one thing thc never throws away. Every change is a JSON line appended to this device's own file, and everything else, the database included, is rebuilt from those lines.

The log is the on-disk contract. The SQLite store, the Markdown export, every screen and every --json answer are derived from it, and docs/FORMAT.md is its specification. It changes only with a version bump, and it is deliberately boring: JSON Lines you can grep, jq, or rebuild from in fifty lines of any language.

17op types, from node.create to tx.unreview
v2the format version; additive over v1
12characters per id: 60 random bits
1writer per file, ever

The vault on disk

The vault on diskA vault folder holds thc-vault.toml, a log directory with one subdirectory per device and one JSONL file per month, plus files, drop and export. Each device appends only to its own directory.~/Dropbox/thought/├─ thc-vault.tomlformat = 2 · id · name · created├─ log/│ ├─ mbp-7f3a/│ │ ├─ 2026-09.jsonl│ │ └─ 2026-10.jsonl│ └─ mini-2c1d/│ └─ 2026-10.jsonl├─ files/2026/10/attachments · <hash>-<name>, written once├─ drop/any .md or .txt here becomes inbox items└─ export/generated Markdown · never read backone directory per devicethis Mac appends only to mbp-7f3a/,the mini only to mini-2c1d/. A sync toolsees one writer per file, so it nevermakes a "conflicted copy".a file's month is the UTC month of its clocks · a name with a space is a sync artefact, ignored
fig. 1A vault is a plain folder. Only log/ is the truth; files/ holds attachments the log refers to, and drop/ and export/ are edges where plain text comes in and goes out.
  • thc-vault.toml marks the folder as a vault and holds its synced identity: format, an id written once and never changed, a name and a created date. None of it is in the log.
  • log/<device>/<YYYY-MM>.jsonl is the log. A device’s id is its short host name plus four random characters (mbp-7f3a), kept in the local cache so it survives restarts. The month in a file name is the UTC month of the event’s clock.
  • files/ holds attachments, named by a hash of their bytes, written once and never edited. A note refers to one with an ordinary Markdown image in its text.
  • drop/ is an inbox for files: any .md or .txt dropped there becomes inbox items.
  • export/ is generated Markdown that Obsidian can open. thc never reads it back.

The store is not here. It lives in the device’s cache directory, because it is a cache: two devices with the same log build the same store, so there’s nothing to sync.

One line, field by field

Every change is one JSON object on one line: an envelope with the operation’s fields flattened into it.

Anatomy of one log lineA node.create event as written to the log, with each envelope field labelled: v, eid, hlc, dev, actor, via, tx and op, followed by the op's own fields.one line of log/mbp-7f3a/2026-10.jsonl, wrapped for reading{"v":1, "eid":"01M4FR3YGC1CZJV7…", "hlc":[1791529974284,1], "dev":"mbp-7f3a", "actor":{"kind":"agent","name":"claude"}, "via":"cli", "tx":"01M4FR3YGC4MVN4E…", "op":"node.create", "id":"md78p9t6g9c7","parent":"nshgnw2hmhc7", "order":"V","text":"Call the dentist #health", "props":{"status":"todo","due":"2026-10-09"}}vthe lowest format version that reads iteidevent id · a ULID, unique everywherehlchybrid logical clock · [ms, counter]devthe device · also its log directoryactorwho · human, or an agent by nameviawhich surface · cli, tui, bar, edit, droptxtransaction · the unit of undo and reviewopthe operation, its fields flattened inthe op's own fields: node.create's id, parent,order, text, props
fig. 2A real event, from thc todo run by an agent. The envelope says when, where, who, through what and as part of which transaction; the op says what.
FieldMeaning
vThe lowest format version that understands this event: 1, or 2 for the tx.* ops. A v2 writer still stamps v1 ops "v":1, so older readers keep reading them
eidThe event id, a ULID, unique across every device
hlcA hybrid logical clock, [unix_ms, counter]. See Replay and merge
devThe device, which is also the directory the line lives in
actor{"kind":"human"} or {"kind":"agent","name":"claude"}, from THC_ACTOR
viaThe surface: cli, tui, bar, edit, drop, …
txThe transaction. Every event from one command shares it; undo and review work per transaction
opThe operation’s name. Its own fields sit beside it

A transaction, as written

One command is one transaction. This is the whole of what THC_ACTOR=claude thc todo "Call the dentist due:fri #health !high" appended, on the first write of the day (ids shortened):

{"v":1,"eid":"01M4FR3YGCNH…","hlc":[1791529974284,0],"dev":"mbp-7f3a","actor":{"kind":"agent","name":"claude"},"via":"cli","tx":"01M4FR3YGC4M…","op":"node.create","id":"nshgnw2hmhc7","parent":null,"order":"V","text":"","props":{"journal":"2026-10-09"}}
{"v":1,"eid":"01M4FR3YGC1C…","hlc":[1791529974284,1],…,"op":"node.create","id":"md78p9t6g9c7","parent":"nshgnw2hmhc7","order":"V","text":"Call the dentist #health","props":{"status":"todo","due":"2026-10-09","priority":"high"}}
{"v":1,"eid":"01M4FR3YGCV8…","hlc":[1791529974284,2],…,"op":"node.create","id":"2tbj6654hfp8","parent":null,"order":"k","text":"","title":"health","props":{"tag":true}}
{"v":1,"eid":"01M4FR3YGCN4…","hlc":[1791529974284,3],…,"op":"edge.add","src":"md78p9t6g9c7","rel":"tag","dst":"2tbj6654hfp8"}

Four lines: today’s journal day (it didn’t exist yet), the task under it with its fields already typed, the health tag, and the edge between them. All four share one tx and one millisecond; the clock’s counter orders them. due:fri arrives as a date, never as text to parse again later.

The operations

opFieldsNotes
node.createid, parent, order, text, title?, props?order is a base-62 fractional index. Replay keeps the first create of an id
node.textid, text, base?base is the eid of the text this edit started from
node.setid, propsA null value unsets. Built-ins: title status scheduled due priority repeat done_at journal tag style gap
node.moveid, parent, orderRejected, and recorded as a conflict, if it would make a cycle
node.completeid, at, occurrence?, next?With next, the node repeats: its dates advance and its status stays todo
node.skipid, occurrence, nextSkip one occurrence of a repeating node
node.delete / node.restoreidSoft delete; history is never lost
edge.add / edge.removesrc, rel, dstrel is tag, mention, embed, blocks, relates, …
alert.addid, node, triggerAn absolute at, or an offset from the node’s due or scheduled
alert.ack / alert.remove / alert.snoozeid, until for snoozeAcked or snoozed on one device stops the others once it syncs
prop.definekey, typenumber, bool, date or text. The first definition wins
tx.reviewtxs[], verdictv2. accepted or reverted, on other transactions. Changes no node
tx.unreviewtxs[]v2. Withdraws a verdict, putting the transactions back in the queue

There’s no “task” op and no “page” op. A task is a node with a status; a page is a root node with a title; a journal day is a root with a journal date; a tag is a root with tag: true. A line’s form (bullet, paragraph, heading, quote, code) is either a style prop or lives in the text itself (# , > , three backticks), so every reader sees it the same way.

Ids

A node id is 60 random bits written as 12 characters of Crockford base32: 0-9a-z without i l o u, so it reads aloud and survives being typed. Any unique prefix of 4 or more characters works on the CLI, and input is forgiving (I and L read as 1, O as 0). Random ids need no coordination: two devices, or two agents in parallel, never collide.

Keyed ids are for nodes every device would create the same way. The id is FNV-1a 64 over thc-key:<key>, folded to 60 bits (id::from_key), so two devices that create the same day offline produce the same node.create, and replay keeps one:

NodeKey
A journal dayjournal:2026-10-09
A tagtag:health
A page made by title or by a [[link]]page:offsite
The saved-views page and built-in viewsfixed keys in views.rs
An attachmentfile: plus its path in the vault
An agent’s --keywhatever the agent passes

The writer uses a keyed id only while it’s free. A page renamed away from a title keeps its id, so a new page with the old title gets a random one instead of reviving the renamed page; a deleted day isn’t brought back by a new create either.

That same rule makes agent retries safe. The second run below finds the keyed id taken and writes nothing:

$ thc todo "Book venue" --key offsite-venue --json
{"ok":true,"tx":"01M4FR4JVEWJ…","events":1,"nodes":[{"id":"z8pbwpmhk414",…}]}
$ thc todo "Book venue" --key offsite-venue --json
{"ok":true,"tx":null,"events":0,"nodes":[{"id":"z8pbwpmhk414",…}]}

Order keys

Siblings are ordered by a fractional index: a base-62 string that sorts lexically, with key_between(a, b) always able to find a key strictly between two others. Moving a line never renumbers its siblings, so a move is one node.move event, not a rewrite of the list.

Two devices appending offline can pick the same key after the same last sibling. Siblings then sort by (order, id), so every reader agrees, and a later insert between the twins goes just after them rather than failing. Nothing fits between equal keys; nothing has to.

Readers are forgiving

The log is written by many binaries over many years, through sync tools that deliver files whole, in pieces, or twice. Readers stay calm about all of it:

  • A trailing partial line is left alone and read once its newline arrives.
  • A file name with a space (2026-10 (conflicted copy).jsonl) is a sync tool’s artefact and is ignored.
  • An unknown op, or a v above the reader’s version, is from a newer writer, not damage. It is skipped silently. The store records which reader built it, and after an upgrade it replays once from scratch, so ops it used to skip are applied.
  • A malformed line is reported (thc doctor), never guessed at.

Changing the format

The rules are short. Additions that older readers can safely ignore (a new prop such as gap, attachment nodes, a reserved form) need no bump. A new op type needs a format version bump, and the event carries the lowest version that understands it. Replay must stay a pure function of the events: anything that depends on a clock, randomness or a timezone is computed by the writer and stored in the event.

Next: Replay and merge, how every device turns these lines into the same state.