Projects, threads and the forest
A thread is one conversation. Threads belong to a project, which defaults to the name of the directory the session ran in.
- Root: a fresh conversation. Usually it was imported or captured from a harness.
- Child: every other thread. It has exactly one origin in the same project.
Threads with their origins form a forest: one tree per root. One cutoff can have any number of children, for example two branches and a handoff from the same message.
Events
An event is one recorded message, with a role of user, assistant, tool or system. Events are only ever appended; they’re never edited.
Commands refer to events by their 1-based position in the thread’s own events (#1, #2, …) or by event id. Imported events get stable ids of the form <harness>:<session>:<native-id>, so importing again never duplicates anything.
Origins: where a cut comes from
An origin records three things.
source: the parent thread and the event the cut is made at. The cutoff is inclusive and never changes.intent: why the child exists.continue: the same work in fresh context, for example when context is running out.branch: parallel work. This is the default.handoff: a scoped task given to another agent.
trigger: what prompted the cut.manualcontext_limit: the session was near the end of its context window.
intent and trigger are separate on purpose. A context-limit cut is usually a continue, but it doesn’t have to be.
Seeds: what the child receives
A seed is the exact context a child starts with:
- the task
- the selected events, copied verbatim with references to their source events
- the name and version of the strategy that produced it
- a token estimate
The first strategy is selected-events@1, which copies the events you select. Summaries will be a separate kind of item, so a seed never blurs what was quoted and what was written.
The seed is rendered into one harness-neutral first prompt (dough thread seed <thread> prints it). Every adapter delivers exactly that text, so the same cut gives the same input whichever harness launches it.
Selecting events
You choose the carried events with a comma-separated selection spec:
| Token | Selects |
|---|---|
all | everything visible at the cutoff, including ancestors’ context |
none | nothing; the child gets only the task |
user | every user message visible at the cutoff |
last:N | the last N visible events (default last:6) |
#n | event n of the cut thread |
#a-#b | events a through b of the cut thread |
<event-id> | one event by id |
“Visible at the cutoff” means the ancestors’ events through each origin, followed by this thread’s own events through the cutoff. The seed is always ordered by history, whatever order the spec lists events in.
Preview, approve, commit
A cut has two steps.
- Preview: planning a cut builds the child and its seed without saving anything.
- Commit: saving writes the child and its seed as one record.
The child’s id is a hash of its inputs: source, intent, trigger, title, task and selected events. So:
- Retries are safe: committing the same plan twice returns the existing child.
- Previews are pinned: an agent flow previews first, then commits with
expect: "<child id>". If anything changed in between, such as a new message moving the latest cutoff, the ids differ and the commit is refused. What gets committed is always what you saw.
Runs: launching a child
A run is one attempt to attach a native session to a thread. A run moves through these states:
started: recorded before the harness starts.succeeded: the harness gave back a session id, and its transcript was found.failed: the harness exited with an error.
A launch records its launcher’s process id. While that process is alive, the thread shows as running (▶ pi running since 21:30) and can’t be launched again. If the launcher dies before recording an outcome, the run stays started and the outcome is unknown. Any further launch of that thread is refused until you reconcile it (dough thread reconcile): either attach the session that was created, or mark the run failed. This prevents two live sessions for one thread. A child that already has a session can’t be launched again; reopen it with dough thread open.
The store
The store is one append-only JSONL log for every project, ~/.threads/log.jsonl by default. Each thread records its project, so the tree groups threads by project.
- Records: each line is one record (a root, an event, a child with its seed, or a run), and each is fsynced as it’s written.
- Loading: the in-memory indexes are rebuilt from the log on open.
- Crash safety: a half-written final line from a crash is cut off on the next open.
Harnesses keep their own native logs. The store holds only the normalized copy plus lineage.
One writer at a time
Every front end opens the store for a single operation and closes it straight away; an import opens it once for all its writes. That keeps writes short, but it isn’t a lock. Two processes importing the same session at once may both write the same records; loading the store keeps the first copy of each.