Open source CapCut alternative.
TypeScript
docs: add the thread record guide
David Le605b6e1c9306
diff --git a/docs/README.md b/docs/README.mdindex 16e79785..ed84d131 100644--- a/docs/README.md+++ b/docs/README.md@@ -18,6 +18,7 @@ Supported product and engineering guides live in `docs/guides/`. This list is th- [Agent Harness](guides/agent-harness.md) — the runtime loop that turns a request into completed work: plan, act, verify, recover, and the safety invariants.- [Harness Deep Dive](guides/harness-deep-dive.md) — subsystem mechanics, one level below the architecture loop.- [Decision System](guides/decision-system.md) — how a turn becomes a conversation, a question, a permission request, or guarded action, and what counts as done.+- [Thread Record](guides/thread-record.md) — the per-task `thread.md` conversation and trace: what gets written, the entry kinds, and the one-writer append-only rules.- [Donkey Vision](guides/donkey-vision.md) — the observation layer that turns on-screen windows into structured UI the agent can reason about.- [Background Input](guides/background-input.md) — driving an app without taking over the cursor or raising it: the foreground/background decision and the delivery lanes.diff --git a/docs/architecture.md b/docs/architecture.mdindex fbf8de07..c7f763e0 100644--- a/docs/architecture.md+++ b/docs/architecture.md@@ -73,7 +73,7 @@ in `guides/agent-harness.md` — it is not repeated here.| Store | Holds ||---|---|-| Thread markdown (`App Support/Donkey/Threads/<id>/thread.md`) | conversation contents and full reasoning/tool trace |+| Thread markdown (`App Support/Donkey/Threads/<id>/thread.md`) | conversation contents and full reasoning/tool trace ([how to write it](guides/thread-record.md)) || Core Data | durable task metadata, events, and assets for per-run coordination || Task and compaction snapshots | execution state, and exactly what context each model decision saw || Agent memory (SQLite, FTS5 + local vectors) | local-item records, negative lookups, runtime task definitions, bounded harness hints |diff --git a/docs/guides/thread-record.md b/docs/guides/thread-record.mdnew file mode 100644index 00000000..0ef9e6a5--- /dev/null+++ b/docs/guides/thread-record.md@@ -0,0 +1,48 @@+# Thread Record++Every session writes a running record of itself to `thread.md` — the real conversation plus the full reasoning and tool trace, one folder per task under Application Support (`Threads/<id>/thread.md`). It is human-readable markdown, appended live, so you can `tail -f` a run as it unfolds, and it is what the in-app conversation view renders back to the user. A compacted `summary.md` sits beside it.++**The one rule:** every session event a user (or a maintainer reading the run) would want to see goes into the thread, through the one transcript writer — never a bare `print`, never a log line that lives only in the console, never state that exists only in memory. If an event matters enough to happen, it matters enough to be in the record.++## How It Works++The thread file is opened once per task and only ever appended to:++```text+begin (writes the header once; no-op if the file exists)+ -> userMessage / planning (the turn opens)+ -> step / model call (each executed step, each model call)+ -> system event / error (lifecycle events; failures outside a tool result)+ -> response (the assistant's answer closes the turn)+ -> summary (regenerates the compacted summary.md)+```++The run loop records itself: the turn-trace manager is the single sink every model call and every executed step report to, so steps and model calls reach the thread without callers thinking about it. Events that happen *outside* a run — pausing, resuming, approving, or denying a task from the notch — are recorded by the overlay model's lifecycle announcer, which writes the same line to the in-app event store and to the thread. **The run loop records the work; the lifecycle announcer records the user's controls.**++## Entry Kinds++Pick the kind that matches what happened; each renders with its own heading and icon.++| Kind | Use it for |+|---|---|+| user message | a request that opens a turn |+| planning | the parsed understanding that anchors a turn: goal, target app, parameters, success criteria, clarification |+| step | one executed step as a single block — the decision (thought, reason, action and its input), then that action's output |+| model call | one call to the model: clipped prompt and reply, finish reason, attempt, duration |+| response | the assistant's answer that closes a turn |+| system event | a lifecycle event — understanding parsed, run finished, task paused, permission granted |+| error | something hit outside a tool result — a planner reply that couldn't be used, a run that aborted before starting |++The step is the only grouped block; everything else is a flat entry. Don't re-narrate a step as a separate system event — the step block already carries its decision and output.++## Rules++1. **One writer, append-only.** Open the thread once and append. The header is written a single time; later turns and events only add to the end. Never truncate or rewrite the file.+2. **Keyed by task id.** Each task owns its thread folder, addressed by task id, so events from one task never bleed into another.+3. **Typed activity, not raw strings.** Lifecycle lines come from the centralized activity vocabulary — one icon and label per kind — so the record stays consistent and the conversation view can render it. Don't invent a one-off status string like "Approved — continuing."+4. **Plain text in the store, markdown in the thread.** The in-app event store keeps plain text — structured data the conversation view reads. The thread keeps the icon-prefixed markdown line. Presentation stays out of the data store.+5. **Bounded and off the main thread.** Clip long prompts, replies, and outputs so a verbose run can't bloat the file, and write off the main thread — recording must never block the UI.++## Where It Lives++The transcript writer lives in the runtime; lifecycle events route through the overlay model's announcer, and the typed lines come from the shared activity vocabulary in the contracts. Start with the transcript writer.