thcThought Control

Decisions

The choices that shaped thc, written as a log. Each says what was chosen, why, and what it costs, because every one of them rules something out.

Each decision carries a stamp. Held means it stands as made. Revised means it changed, and the entry says from what. Open means it’s decided for now, with a known next step. The costs are real: they’re the reasons someone could reasonably have chosen otherwise.

Decision
D-01The log is the truth, not Markdown filesrevised
D-02Plain JSONL, not a CRDT frameworkheld
D-03One log directory per deviceheld
D-04A hybrid logical clock and per-field last-writer-winsheld
D-05Concurrent text edits keep both versionsheld
D-06Clocks, randomness and recurrence belong to the writerheld
D-07One primitive: the nodeheld
D-08Parse capture syntax once, at the edgesheld
D-09SQLite is a cache, and the CLI reads it directlyheld
D-10The daemon is optionalheld
D-11Who writes: the process itself, or the daemonrevised
D-12Random 60-bit ids, keyed ids where devices must agreeheld
D-13Fractional order keysheld
D-14Rust, one binary, macOS and Linuxheld
D-15The TUI is one serializable stateheld
D-16The editor engine is its own projectheld
D-17Agents are users; only people acceptheld
D-18Policy lives on the device, not in the vaultheld
D-19The terminal first; the menu bar app pausedrevised
D-20The CLI is the agent interface; MCP lateropen

The data

D-01

The log is the truth, not Markdown files

revised

The first version (v0.1) kept Markdown files as the truth and inline - [ ] lines as tasks. v0.2 replaced that: every change is one JSON line in log/<device>/YYYY-MM.jsonl, and everything else is derived.

why
Markdown as the source of truth needs a parse-and-rewrite layer that has to keep IDs, types and history in text. An append-only event log gives stable IDs, typed fields, transactions and history directly. The SQLite store is a view of it and Markdown is an export.
cost
Your notes aren't files you edit in place. You get them back as plain text through thc edit, drop/ and a continuously regenerated, read-only export/ that Obsidian can open.
D-02

Plain JSONL, not a CRDT framework

held

The log format is a versioned contract (docs/FORMAT.md). Readers skip ops they don’t know, so an older binary reads a newer log without damage; new op types need a format version bump.

why
A JSONL log can be read with grep and jq, or rebuilt from in fifty lines of any language. The merge rules fit on one page of FORMAT.md. Boring, proven tools add less than they remove.
cost
Text merges whole fields, not characters. Two devices editing the same note's text offline produce a conflict to resolve (D-05), where a sequence CRDT would interleave them.
D-03

One log directory per device

held

log/<device>/ is written by exactly one device. Readers ignore a trailing partial line until its newline arrives, and ignore file names with a space (sync-tool artefacts).

why
Dropbox, iCloud and Syncthing all misbehave when two machines write one file: they make "conflicted copy" files. If each device appends only to its own directory, a sync tool only ever copies files, never merges them.
cost
Reading means taking the union of every device's files and ordering it. An event that arrives late and sorts before applied ones forces a rebuild from scratch, which is fine at personal scale and wouldn't be at a team's.
D-04

A hybrid logical clock and per-field last-writer-wins

held

Fields are position (parent and order together), text, each property, deleted, and each edge. crates/thc-core/tests/convergence.rs simulates devices editing and syncing at random points and must always converge to identical state.

why
Every device must build the same state from the same lines without talking to each other. A total order on (hlc.ms, hlc.counter, dev, eid) and one rule, the latest event wins per field, does that deterministically.
cost
Concurrent changes to the same field resolve silently: the later one wins and the earlier is only in history. Per-field granularity keeps that rare (a due date and a title don't collide), but it's a choice.
D-05

Concurrent text edits keep both versions

held

Each node.text carries base, the event id of the text it started from. An edit made from the current text resolves open conflicts on that node.

why
Text is what people actually write; losing a paragraph silently is the one failure a notebook can't have. Two edits from the same base are concurrent: the later one shows, the other is stored as a conflict, and every device shows the same ≠.
cost
A person has to resolve it. Agents are told not to (thc text on a node with an open text conflict exits 4).
D-06

Clocks, randomness and recurrence belong to the writer

held

Replay (Store::apply) is a pure function of the events. TxBuilder is where every clock-, random- or timezone-dependent decision lives.

why
If replay read the replaying device's clock or timezone, two devices could build different states from the same log. So the writer resolves fri, mints ids, and computes a repeating task's next dates into the node.complete event itself.
cost
The writer carries more logic, and a stored date can't be re-derived later under different rules. Whether an alert has fired is per-device local state, never an event, because firing is a side effect of one device's clock.
D-07

One primitive: the node

held

Built-in properties (status, scheduled, due, priority, repeat…) are indexed columns; anything else is a typed custom property.

why
A page, a journal day, a task, a tag and a saved view are all nodes used in a particular way. "Task" is a status any node can have; "reminder" is an alert attached to one. Fewer kinds means fewer edge cases for people and agents.
cost
Kinds are conventions, so code that cares must ask (a status, a journal date, a system prop). Hidden system nodes, like ¶ Views and attachment nodes, need every listing to skip them.
D-08

Parse capture syntax once, at the edges

held

The edges are thc add/todo/remind, the capture box, the editor, $EDITOR’s round trip and drop/. Everything past them deals in fields.

why
Call dentist due:fri #health !high is fast to type and ambiguous to store. Parsing it once into typed fields means stored text is never re-read to learn what something is.
cost
Quoting rules: text inside quotes or backticks is never parsed, so writing about the syntax needs care. The editor's idle save stores text raw, so a half-typed due:fr isn't read as a date until you leave the line.

The processes

D-09

SQLite is a cache, and the CLI reads it directly

held

The store lives in the local cache directory, never in the synced vault: WAL mode, STRICT tables, partial indexes on open tasks, FTS5 for search.

why
Measured: opening SQLite and running an indexed query over 20k rows takes about 2.3 ms in a native process, most of it the OS starting the process. Routing reads through the daemon would save about 0.5 ms and add a dependency.
cost
Every device builds and keeps its own store, and an upgrade that reads more of the log re-materializes it. Deleting it is always safe: thc rebuild replays the log.
D-10

The daemon is optional

held

thc daemon watches the log, replays other devices’ lines, pushes changed to subscribers within about 120 ms, fires alerts and keeps the export fresh.

why
A background process is one more thing to install, update and debug. Everything it does, the CLI and TUI can do on demand. It's a cache warmer, an event bus and an alarm clock, not a server.
cost
Two paths for some things: the TUI watches the log itself when no daemon runs, and alerts only fire on time while one does. A daemon left on a replaced binary has to be detected (exe_id) and restarted.
D-11

Who writes: the process itself, or the daemon

revised

The socket’s write methods also serve clients without file access, such as the menu bar app.

why
The spec first had clients send writes through the daemon. As built, the CLI and the TUI write directly under the device write lock (a flock plus BEGIN IMMEDIATE), so neither depends on the daemon. For a while the TUI's document saves went through the daemon's blocks.apply when it was live, on a writer thread; that second route, with its queue of saves in flight, was removed: one save path, inline, daemon or not.
cost
A very large save (1,000 lines pasted into a 5,000-line page, about a second) holds the keyboard while it writes. Everyday saves take milliseconds.
D-12

Random 60-bit ids, keyed ids where devices must agree

held

Replay keeps the first node.create of an id, which is what makes keyed creates idempotent.

why
Sequential numbers collide when devices and agents work in parallel, and names drift. Sixty random bits as 12 Crockford base32 characters never need coordinating. Things every device would create the same way (a journal day, a tag, a page made by title, an agent's --key) get an id hashed from a key, so two offline creates make one node.
cost
Ids carry no meaning, so people use short prefixes and titles. A keyed id already taken (a renamed page, a deleted tag) falls back to a random one. Logs from before keyed ids could hold two roots for one day; thc doctor --fix merges them.
D-13

Fractional order keys

held

crates/thc-core/src/ord.rs is about a hundred lines and never panics.

why
Base-62 keys sort lexically, and a key between two others always exists, so moving or inserting a note never renumbers its siblings: one event per move, not one per sibling.
cost
Two devices appending offline can pick the same key. Siblings sort by (order, id) so every reader agrees, and a later insert between equal keys goes just after them.
D-14

Rust, one binary, macOS and Linux

held

The budgets are in docs/SPEC.md §8. They’re targets, not merge gates; CI guards catch order-of-magnitude regressions.

why
A query should take about as long as the OS needs to start a process, so agents can call it in loops. Rust has no runtime to start, like C. One binary holds the CLI, the TUI and the daemon, so there's one thing to install and update. Unix sockets, launchd and systemd cover both platforms.
cost
No Windows. Release builds (fat LTO, one codegen unit) are slow to compile. The daemon's login item exists twice: a launchd agent and a systemd --user unit.

The interfaces

D-15

The TUI is one serializable state

held
why
If a presentation choice isn't in the state, it can't be replayed, patched by an agent, rendered headless or tested. So the TUI is a UiState, messages through one door, a pure update returning effects, and a view a test forbids from reading the store, a clock, the environment or a file.
cost
Everything has to be modelled, including time (ticks) and ids (minted by the runtime). The migration isn't finished: write actions and the document's key path still run as runtime code, recorded so traces stay exact.
D-16

The editor engine is its own project

held
why
A text editor with exact caret motion is a project of its own, with its own tests (golden caret examples, property tests over random documents). As a separate crate it has a clear boundary: text and cursors only. Tasks, vaults and saving stay in thc, on the engine's extension points.
cost
Two repositories. An engine bug found in thc is fixed in caretline first, then released or pinned by git revision, then pulled in; never patched here. thc pins exact versions, so every upgrade is deliberate.
D-17

Agents are users; only people accept

held

Review verdicts are the only ops added in format v2 (tx.review, tx.unreview).

why
Agents get what makes them reliable: --json, stable exit codes, --dry-run, idempotency keys, preconditions (--if-match, --expect), and attribution on every event. A person keeps the last word: an agent's transactions wait in thc review, and replay ignores an agent's accepted verdict.
cost
A review queue to tend. Reverting has to keep later edits by others, so a revert is computed per field, not a blind undo.
D-18

Policy lives on the device, not in the vault

held

Checked on every write, in order: read-only mode, the tier’s deny, the tier’s confirm, hooks, the write.

why
Which verbs an actor may run (allowed, needs confirmation, refused) is a property of a machine. If it lived in the synced vault, one device could change what another allows.
cost
Each machine is configured on its own. And it's a guard against mistakes, not a security boundary: anything that can run thc can set THC_ACTOR or edit the config.
D-19

The terminal first; the menu bar app paused

revised

The daemon’s socket protocol stays versioned for clients like it.

why
The terminal is the interface: the CLI is where behaviour lives, the TUI drives it, and GUIs tend to grow features only they can reach. A macOS menu bar app (ThoughtBar) shipped as a thin client of the daemon's socket, with no file access and no editing UI.
cost
No native window. Development of the menu bar app is paused and it isn't part of this repository; install and update now work without it. Its protocol (thc schema --proto) is still generated from the binary.
D-20

The CLI is the agent interface; MCP later

open

thc schema gives every command’s JSON Schema, generated from the clap definitions.

why
An agent that can run a shell can use thc exactly as a person does, with the guide built into the binary (thc instructions) so it can't drift. One interface means one set of tests and one behaviour.
cost
Agents without a shell can't use it yet. A stdio MCP server on the same core is planned, with tools annotated as read-only, destructive or idempotent.