@techsavvyash/threads is the headless core, built on Effect 4. It has no dependency on Pi, Claude Code or any UI. The CLI, plugins and visualiser all go through these exports.
npm install @techsavvyash/threads effect @effect/platform-node-sharedEverything that touches the outside world is an Effect. To run one you provide:
ThreadStore: the store, from one of its two layers.FileSystem: for reading logs and transcripts.ChildProcessSpawner: needed only to launch harnesses.
Failures are typed. Each error has a _tag and a readable message.
End to end
import { NodeChildProcessSpawner, NodeFileSystem, NodePath } from "@effect/platform-node-shared";
import { Effect, Layer } from "effect";
import { ThreadStore, claude, commitCut, importTranscript, launchChild, planCut, storePath } from "@techsavvyash/threads";
const Node = NodeChildProcessSpawner.layer.pipe(
Layer.provideMerge(Layer.mergeAll(NodeFileSystem.layer, NodePath.layer))
);
const program = Effect.gen(function* () {
// 1. Import a Claude Code session as a root.
const file = yield* claude.locate("3f1c…");
const { thread: root } = yield* importTranscript(claude, file!);
// 2. Preview a handoff from event #42, carrying #12 and #40-#42.
const input = { thread: root.id, task: "Implement the store", intent: "handoff", at: "#42", select: "#12,#40-#42" };
const preview = yield* planCut(input);
// 3. Commit exactly what was previewed (a PreviewMismatch if the cut changed meanwhile).
yield* commitCut(input, preview.thread.id);
// 4. Launch it in a fresh Claude Code session and capture the transcript.
return yield* launchChild(claude, preview.thread.id, { cwd: process.cwd() });
});
await Effect.runPromise(
program.pipe(
Effect.provide(ThreadStore.layerPerOperation(storePath())),
Effect.provide(Node)
)
);Store
ThreadStore is a service with two layers:
| Layer | Use it when |
|---|---|
ThreadStore.layer(file) | One process owns the log for a while. It’s opened once and closed when the scope ends. |
ThreadStore.layerPerOperation(file) | Several processes share the log (CLI, plugins, visualiser). Each call opens it, writes and closes it. |
| Member | Does |
|---|---|
view | An Effect giving a StoreView: thread, threads, events, seed, runs, session and history(cutoff) |
createRoot({projectId, title, id?}) | New root thread |
appendEvent({threadId, role, text, id?}) | Append an event; idempotent on id |
previewChild(input) / commitChild(plan) | Build a child and seed without saving / save them atomically |
startRun, finishRun, abandonRun, attachSession | Run lifecycle. abandonRun is a launcher giving up without an outcome (the transcript was not found), so the run reads as unknown, not running. |
batch(f) | Run several operations against one open of the log. Imports use it, so a long transcript is one read, not one per message. |
Records are decoded with Schema when the log is loaded. A torn last line from a crash is dropped. A thread or event that appears twice (two writers working from stale copies) keeps its first record. Any other unreadable record fails with a StoreError that gives the line number. The record schemas (LogRecord, Thread, Seed, Run, …) are exported too.
renderSeed(child, seed) renders the first prompt a child receives.
Operations
These are shared by every front end, so a cut means the same thing everywhere.
| Function | Does |
|---|---|
planCut(CutInput) | Resolve the cutoff and selection, and return a ChildPlan with a deterministic child id |
commitCut(input, expect?) | Plan and commit; fails with PreviewMismatch if the id ≠ expect |
previewText, describePlan, approvalHint | Human- and agent-facing renderings of a plan (pure, over a StoreView) |
selectEvents(view, thread, cutoff, spec) | Evaluate a selection spec |
eventAt(view, thread, at), resolveThread(view, ref) | last, #n or an id; an exact id or unique prefix |
captureSession(adapter, file, sessionId) | Live capture: append to the attached thread, or import a new root |
formatTree, formatEvents, status | Text renderings used by the CLI and agent tools |
CutInput is { thread, task, at?, select?, intent?, trigger?, title? }. Defaults: at: "last", select: "last:6", intent: "branch", trigger: "manual".
Harnesses
| Export | Does |
|---|---|
pi, claude, codex, adapters, adapterFor(name) | The built-in adapters |
importTranscript(adapter, file, {projectId?, threadId?}) | Copy a native transcript into a new root, or into threadId |
launchChild(adapter, threadId, {cwd, args?, model?}) | Record the run, launch, capture the session; see concepts > Runs: launching a child |
syncThread(threadId) | Append new messages from the thread’s native session |
Errors
_tag | When |
|---|---|
StoreError | The log can’t be read or written, or holds an invalid record |
NotFound | An unknown thread, event, run or harness |
Conflict | A retry with different content, or an excerpt that doesn’t match history |
InvalidInput | A bad intent or selection spec, an empty task, an ambiguous prefix, an event not visible at the cutoff |
PreviewMismatch | A commit whose cut no longer matches the approved preview |
LaunchBlocked | Launching a thread that is running, already has a session, or whose last launch has an unknown outcome |
LaunchFailed | The harness couldn’t start a session (the run is recorded as failed) |
TranscriptError | A file that isn’t a transcript of that harness |
TranscriptMissing | The session started but its transcript can’t be found; reconcile it |
Read API
These are plain records for any renderer. The library decides what the forest means; renderers decide how to lay it out.
forest(view)returns{ projects: [{id, roots}], threads: Record<id, ThreadSummary> }. EachThreadSummaryhas:origin, with the cutoff’sindexin the parent- seed size and strategy
- event count and status
- the native session
- child ids
threadDetail(view, id, {offset?, limit?})returns:- one page of events, each with its
n total- the runs
- for a child, the seed plus its rendered
prompt
- one page of events, each with its
The visualiser server lives in @techsavvyash/dough-cli, as a Viewer layer and a scoped startViewer.