From 7cfaa82c9b68e9261094f33d5c958254e6640f96 Mon Sep 17 00:00:00 2001 From: Ahmed Alaa <46384841+BenAlaa@users.noreply.github.com> Date: Mon, 24 Aug 2026 13:26:54 +0300 Subject: [PATCH 01/12] docs(book): add front matter and system maps --- src/content/book/00-cover.mdx | 38 ++++++ src/content/book/01-how-to-read.mdx | 70 +++++++++++ src/content/book/02-contents.mdx | 97 ++++++++++++++ src/content/book/03-architecture-map.mdx | 122 ++++++++++++++++++ src/content/book/04-request-trace.mdx | 154 +++++++++++++++++++++++ 5 files changed, 481 insertions(+) create mode 100644 src/content/book/00-cover.mdx create mode 100644 src/content/book/01-how-to-read.mdx create mode 100644 src/content/book/02-contents.mdx create mode 100644 src/content/book/03-architecture-map.mdx create mode 100644 src/content/book/04-request-trace.mdx diff --git a/src/content/book/00-cover.mdx b/src/content/book/00-cover.mdx new file mode 100644 index 0000000..f432c60 --- /dev/null +++ b/src/content/book/00-cover.mdx @@ -0,0 +1,38 @@ +--- +slug: cover +order: 0 +kind: front +part: Start here +partOrder: 0 +title: T3 Code Decoded +shortTitle: Cover +summary: A source-grounded, end-to-end field guide to T3 Code's control plane, provider adapters, clients, remote access, and distribution system. +status: source-checked +gates: [sources] +objectives: [] +keywords: [T3 Code, architecture, agent harness, control plane] +sourceAreas: [apps/server, apps/web, apps/desktop, apps/mobile, packages/contracts] +visuals: [book cover] +updatedAt: 2026-08-24 +--- + +import BookCover from "../../components/BookCover.astro"; +import Callout from "../../components/Callout.astro"; + + + + + This edition is locked to [`pingdotgg/t3code@fa219001d`](https://github.com/pingdotgg/t3code/tree/fa219001dc2f14cfd9c7774c2c03c153359144be). “Shipped,” “supported,” and “implemented” always mean that revision unless a dated release or roadmap note says otherwise. + + +## What this book is trying to make obvious + +T3 Code is easy to mistake for an agent. It is more useful—and more technically +interesting—to see it as a **control surface and execution boundary around several +independent agent runtimes**. Providers own their model loops and native context. +T3 owns durable orchestration history and query projections, coordinates workspace +operations, and gives clients shared semantics with deliberate platform-specific +capabilities. Some delivery and side-effect machinery remains intentionally +ephemeral; the book marks those seams instead of calling all server state durable. + +That division of ownership is the spine of the book. Every later module connects back to it. diff --git a/src/content/book/01-how-to-read.mdx b/src/content/book/01-how-to-read.mdx new file mode 100644 index 0000000..be1994b --- /dev/null +++ b/src/content/book/01-how-to-read.mdx @@ -0,0 +1,70 @@ +--- +slug: how-to-read +order: 1 +kind: front +part: Start here +partOrder: 0 +title: How to read a changing system +shortTitle: Reading guide +summary: The evidence rules, source labels, revision contract, and reading paths used throughout the book. +status: source-checked +gates: [sources] +objectives: + - Distinguish verbatim source, abridged source, diagrams, and interpretation. + - Choose a linear, feature-first, or implementation-first reading path. + - Understand what the pinned revision does and does not promise. +keywords: [evidence, source references, revision, reading path] +sourceAreas: [sources/t3code.lock.json, sources/excerpts.manifest.json] +visuals: [evidence legend] +updatedAt: 2026-08-24 +--- + +import Callout from "../../components/Callout.astro"; +import EvidenceClaim from "../../components/EvidenceClaim.astro"; +import SourceExcerpt from "../../components/SourceExcerpt.astro"; +import SourceSnapshot from "../../components/SourceSnapshot.astro"; + +This is a field guide to a moving codebase. It therefore treats provenance as part of the interface, not a footnote. + + + +## Four evidence labels + +1. **Verified behavior** is backed by executable code, a test, schema, migration, or workflow at the pinned revision. +2. **Documented intent** reports what a maintainer document says without silently upgrading prose into runtime behavior. +3. **Inference** names a design consequence derived from cited evidence. The sources prove the inputs; the book owns the interpretation. +4. **Future / proposed** is explicitly unshipped. A builder capability, community request, or future-work paragraph is never called a supported feature. + +Exact source cards are a separate presentation device. Their code is read directly +from the locked Git object—not the possibly dirty working tree—and shows real line +numbers, a visible checksum prefix, and an immutable GitHub permalink. + + + + + A stable source lock makes an explanation reproducible. It does not make it permanently current; later editions must deliberately refresh and review the evidence. + + +## Three reading paths + +### Linear: follow one task + +Start with **The request trace**, then read the numbered chapters in order. This follows a user action from client state through authenticated RPC, commands, events, provider I/O, checkpoints, and back to every UI. + +### Architecture-first: map then zoom + +Open **The complete system map**, choose a layer, and follow its cross-links. This is useful when you already know event sourcing, provider protocols, or Electron/React Native and want the unfamiliar seams. + +### Transfer-first: design another orchestrator + +Read the ownership model, adapter boundary, domain kernel, connection runtime, and final transfer guide. Those chapters separate reusable patterns from choices that only make sense for T3 Code's bring-your-own-subscription model. + + + The live repository moves quickly. A source link with `fa219001d` is intentionally historical and stable. A link to `main` may be newer, but it cannot prove what this edition read. The book prefers reproducibility over silently chasing HEAD. + + +## Status words + +- **Draft**: structured and cited, but still awaiting a second source pass. +- **Source checked**: claims and diagrams have been reconciled to the pinned checkout. +- **Verified**: source checked, link checked, and reviewed in the end-to-end narrative. diff --git a/src/content/book/02-contents.mdx b/src/content/book/02-contents.mdx new file mode 100644 index 0000000..e56a7a8 --- /dev/null +++ b/src/content/book/02-contents.mdx @@ -0,0 +1,97 @@ +--- +slug: contents +order: 2 +kind: front +part: Start here +partOrder: 0 +title: Contents and learning route +shortTitle: Contents +summary: "The complete ordered reading route: establish ownership, then trace the durable control plane, adapters, work lifecycle, clients, remote paths, shipping system, and architectural synthesis." +status: source-checked +gates: [sources, links, editorial] +objectives: + - See why the order follows runtime causality instead of repository folders. + - Understand the scope of every completed part and its visual explanations. +keywords: [contents, chapters, roadmap, learning path] +sourceAreas: [BOOK_PLAN.md] +visuals: [chapter roadmap] +updatedAt: 2026-08-24 +--- + +import Callout from "../../components/Callout.astro"; + +The old book introduced several keystone concepts long after depending on them. This edition orders the material by **causal distance from one user request**. The repository atlas remains available as reference, but it does not dictate the story. + +## Start here + +- **How to read a changing system** — evidence, revision, and reading paths. +- **The complete system map** — the same architecture in spatial form. +- **One request, every boundary** — a step-through trace before the zoomed chapters. + +## Part I · Boundaries and vocabulary + +1. Control surface, not agent brain +2. Environment · project · thread · turn · session +3. Repository and dependency atlas +4. Runtime topologies and technology choices + +## Part II · Boot and connect + +5. The `npx t3` bootstrap path +6. Server composition and execution boundary +7. Effect RPC, subscriptions, and wire contracts +8. Pairing, scopes, credentials, and WebSocket upgrade + +## Part III · The durable domain kernel + +9. Commands and invariants +10. Events, receipts, and idempotency +11. Projection tables and read models +12. Post-commit reactors: serialized handling without durable delivery +13. SQLite, files, settings, secrets, migrations, and recovery + +## Part IV · Five harnesses, one product model + +14. The `ProviderAdapter` contract +15. Drivers, instances, registries, and multi-instance routing +16. Codex through app-server JSON-RPC +17. Claude through the Agent SDK +18. Cursor and Grok through ACP +19. OpenCode and the normalization matrix +20. Two usage systems: live context telemetry and transcript accounting + +## Part V · The work lifecycle + +21. Project discovery and `t3.json` +22. Current checkout vs isolated worktrees +23. Start, stream, steer, interrupt, settle +24. Permission modes, approvals, and structured input +25. Threads, provider tasks, plans, skills, and subagents +26. Who owns context, compaction, and memory +27. Hidden-ref checkpoints, diffs, and revert +28. Terminals, files, previews, MCP, VCS, and pull requests + +## Part VI · Client architectures: shared semantics, platform edges + +29. The shared client runtime +30. Web routes, state, and rendering performance +31. Composer, work log, review, and sidebar lifecycle +32. Desktop: Electron, IPC, server ownership, browser, SSH +33. Mobile: React Native, persistence, outbox, sharing, notifications + +## Part VII · Reach and ship + +34. Primary, paired bearer, Tailscale endpoints, and SSH access +35. T3 Connect: OAuth, DPoP, relay, and tunnel +36. Reconnect, multi-environment state, notifications, version skew +37. Distribution artifacts: CLI, hosted app, desktop, mobile, marketing, and AUR +38. Release graph, three update systems, and observability/privacy + +## Part VIII · Synthesis + +39. Six complete traces: ownership, convergence, and failure boundaries +40. Decisions, trade-offs, limitations, and an honest roadmap + + + `BOOK_PLAN.md` is the authoring contract for this repository. Product roadmap claims inside the book use a stricter split: shipped code, explicit maintainer future work, and community ideas are three different categories. + diff --git a/src/content/book/03-architecture-map.mdx b/src/content/book/03-architecture-map.mdx new file mode 100644 index 0000000..0d7aee9 --- /dev/null +++ b/src/content/book/03-architecture-map.mdx @@ -0,0 +1,122 @@ +--- +slug: architecture-map +order: 3 +kind: front +part: Start here +partOrder: 0 +title: The complete system map +shortTitle: System map +summary: A spatial map that separates client surfaces, transport, transactional state, hot delivery, side effects, provider routing, and external execution. +status: source-checked +gates: [sources] +objectives: + - Locate every major package at its runtime boundary. + - See which edges carry commands, events, provider-native protocol, or filesystem effects. +keywords: [architecture map, components, packages, boundaries] +sourceAreas: [apps/server, packages/contracts, packages/client-runtime, apps/web, apps/desktop, apps/mobile, apps/marketing, infra/relay] +visuals: [interactive layer map, ownership table] +updatedAt: 2026-08-24 +--- + +import Callout from "../../components/Callout.astro"; +import EvidenceClaim from "../../components/EvidenceClaim.astro"; +import Figure from "../../components/Figure.astro"; +import LayerMap from "../../components/LayerMap.astro"; +import Mermaid from "../../components/Mermaid.astro"; +import SourceList from "../../components/SourceList.astro"; + +For a selected environment, authoritative repository and provider execution occurs +behind that environment's server boundary. A client can supervise several such +environments, while Electron and mobile also own device-local storage, navigation, +notifications, preview, update, and operating-system integrations. + +
+ +
+ +## Two return paths, one write path + +
+ |typed command| W[WebSocket RPC + scope] + W --> Q[Serialized in-memory queue] + Q --> D[Decision: invariants + clock/UUID Effects] + D -->|then enter SQL transaction| S[(Events + SQL projections + accepted receipt)] + S -.->|post-commit publish| B[Hot event PubSub] + B -.->|best effort; not replayed| R[Provider command reactor] + R --> V[ProviderService + instance registry] + V --> A[Provider adapter] + A --> P[Codex · Claude · Cursor · Grok · OpenCode] + P -->|native notifications| A + A -->|canonical runtime events| I[Runtime ingestion] + I -->|internal commands| Q + B -.->|committed live events| L[WebSocket subscription] + L --> C + S --> H[Authenticated HTTP snapshot query] + H --> C`} /> +
+ +The downward path is imperative: “start this turn,” “accept this approval,” “revert +this checkpoint.” The upward path is descriptive: assistant deltas, activities, +plans, usage, session state, and changed-file summaries. The adapter is where each +harness's vocabulary becomes the canonical provider-runtime vocabulary. + + + Event append, SQL projection updates, and an accepted command receipt are atomic. Publication to reactors happens afterwards through memory. A committed intent can therefore survive while its provider or filesystem side effect is lost across a crash. + + +## Three UI families, four execution clients, five delivery shapes + +`apps/web` serves three roles: the browser UI copied into the npm CLI, the hosted +product UI, and the Electron renderer. Electron and React Native add very different +native systems around shared connection/state semantics. The marketing Astro site +is the fifth delivery shape, but it is a publication surface—not an execution +client. + +
+ + + + + + + + + + +
Cross-surface capability comparison for local web, hosted web, Electron, iOS, and Android
CapabilityLocal webHosted webElectroniOSAndroid
Environment serverCLI-ownedremotemanaged local/WSLremoteremote
Terminal rendererGhostty WASMGhostty WASMGhostty WASMnative Ghosttynative Ghostty VT
Offline new-task intentdurable outboxdurable outbox
Environment provisioningprimary/pairpair/relayprimary, WSL, SSHpair/relaypair/relay
Distinctive native edgelocal browsercloud identitypreview, updates, OS IPCAPNs, Live Activities, shareshare, widgets
+
+ + + A phone does not run Codex and the hosted web app does not proxy repository traffic. Each selected environment keeps provider processes, workspace files, Git, PTYs, and authoritative orchestration state behind its own server. A client may merge several environments, and its native shell still owns device-local concerns. + + +## Source trail + + diff --git a/src/content/book/04-request-trace.mdx b/src/content/book/04-request-trace.mdx new file mode 100644 index 0000000..5d71bd2 --- /dev/null +++ b/src/content/book/04-request-trace.mdx @@ -0,0 +1,154 @@ +--- +slug: request-trace +order: 4 +kind: front +part: Start here +partOrder: 0 +title: One request, every boundary +shortTitle: Request trace +summary: Step through a user turn from a client command to an ordered SQL commit, provider-native execution, canonical event ingestion, checkpoint diff, and streamed UI state. +status: source-checked +gates: [sources] +objectives: + - Build a causal mental model before studying individual modules. + - Distinguish the synchronous command acknowledgement from asynchronous provider work. + - Locate durability, side effects, streaming, and checkpoint settlement. +keywords: [turn lifecycle, command, event, provider, checkpoint, stream] +sourceAreas: [packages/contracts/src/orchestration.ts, apps/server/src/orchestration, apps/server/src/provider] +visuals: [interactive request stepper, sequence diagram] +updatedAt: 2026-08-24 +--- + +import Callout from "../../components/Callout.astro"; +import EvidenceClaim from "../../components/EvidenceClaim.astro"; +import Figure from "../../components/Figure.astro"; +import Mermaid from "../../components/Mermaid.astro"; +import SourceExcerpt from "../../components/SourceExcerpt.astro"; +import SourceList from "../../components/SourceList.astro"; +import TraceLab from "../../components/TraceLab.astro"; + +The easiest way to understand T3 Code is to separate **accepting intent** from +**performing work**. This first trace deliberately follows a turn on an existing +thread with no new attachments or worktree bootstrap. That keeps one transactional +write path visible; the multi-step bootstrap branch appears immediately afterwards. + + + +## The command is deliberately rich + + + +## The acknowledgement is not the answer + + + + + + + A successful dispatch returns the committed event sequence, and its accepted command receipt is internal SQLite state in the same transaction. A rejected command returns an error. Only invariant rejection is recorded, and that write is best effort with persistence failure discarded. + + + + `DispatchResult` is the client success value. The orchestration command receipt is internal idempotency state. `RuntimeReceiptBus` exposes short-lived checkpoint milestones to tests and is a no-op broadcaster in production. They solve three different problems. + + +The turn reaches another milestone when its projected provider session is no longer +`running`. Checkpoint state can arrive independently, and capture may be missing, +skipped, or erroneous. A single “complete” boolean cannot faithfully represent all +three phases. + +## The bootstrap fork is not one transaction + +The richer client command can create a thread, create or select a worktree, run +setup, and start the first turn. Those are several operations with compensating +tombstone cleanup on failure. Only the two-to-four-event batch for an already +existing thread—optional lifecycle resets, then message and turn-start—is decided +and committed atomically. + + + Attachment normalization persists decoded bytes before the engine transaction. A command can therefore fail after external filesystem work has begun; Chapter 9 models that branch explicitly. + + +## The full causal loop + +
+ >C: send prompt + C->>RPC: thread.turn.start + RPC->>N: canonicalize external input + N->>E: dispatch existing-thread command + E->>E: decide command → events + E->>DB: events + SQL projections + accepted receipt + DB-->>E: commit sequence + E-->>RPC: DispatchResult { sequence } + RPC-->>C: successful dispatch result + E-->>R: committed turn-start-requested + R->>V: ensure session + send + V->>A: start/resume + sendTurn + A->>P: provider-native request + P-->>A: native notifications + A-->>V: canonical runtime events + V-->>I: canonical runtime events + I->>E: internal commands + E->>DB: commit projected state + E-->>RPC: thread event stream + RPC-->>C: render messages/activity/session + V-->>I: turn.completed + V-->>K: turn.completed + K->>G: attempt hidden-ref capture + diff + K->>E: thread.turn.diff.complete + E->>DB: commit checkpoint event + projection + E-->>RPC: committed checkpoint event`} /> +
+ +The diagram intentionally keeps the checkpoint worker in the reactor lane, but its +last write does **not** bypass the domain kernel. Git capture is a side effect; the +result becomes durable only after a new internal command passes through the engine. + + + Provider intent is consumed from a hot stream. If the server exits after the SQL commit but before the reactor handles that event, restart does not replay the pending provider send. Retrying the same command finds the accepted receipt and does not regenerate the event. + + + From d5487ab1ab9b1bc7753185477c04f33c9e4631b1 Mon Sep 17 00:00:00 2001 From: Ahmed Alaa <46384841+BenAlaa@users.noreply.github.com> Date: Mon, 24 Aug 2026 13:26:58 +0300 Subject: [PATCH 02/12] docs(book): publish part one boundaries --- src/content/book/10-control-surface.mdx | 106 ++++++++++++++++++ src/content/book/20-domain-vocabulary.mdx | 117 ++++++++++++++++++++ src/content/book/30-repository-atlas.mdx | 118 +++++++++++++++++++++ src/content/book/40-runtime-topologies.mdx | 110 +++++++++++++++++++ 4 files changed, 451 insertions(+) create mode 100644 src/content/book/10-control-surface.mdx create mode 100644 src/content/book/20-domain-vocabulary.mdx create mode 100644 src/content/book/30-repository-atlas.mdx create mode 100644 src/content/book/40-runtime-topologies.mdx diff --git a/src/content/book/10-control-surface.mdx b/src/content/book/10-control-surface.mdx new file mode 100644 index 0000000..030f93e --- /dev/null +++ b/src/content/book/10-control-surface.mdx @@ -0,0 +1,106 @@ +--- +slug: control-surface +order: 10 +number: "1" +kind: chapter +part: Part I · Boundaries and vocabulary +partOrder: 1 +title: Control surface, not agent brain +shortTitle: The ownership boundary +summary: For each environment, T3 Code authoritatively coordinates repository and provider execution without replacing a provider's model loop, native context, or authentication. +status: source-checked +gates: [sources] +objectives: + - Draw the ownership boundary between client, T3 server, provider adapter, and provider CLI. + - Explain why multi-harness support is an adapter problem rather than a shared agent implementation. + - Identify the server services that make T3 Code more than a terminal wrapper. +keywords: [control surface, harness, ownership, server, provider adapter] +sourceAreas: [docs/internals/overview.md, apps/server/src/server.ts, apps/server/src/provider/Services/ProviderAdapter.ts] +visuals: [ownership matrix, server capability assembly] +updatedAt: 2026-08-24 +--- + +import Callout from "../../components/Callout.astro"; +import DecisionGrid from "../../components/DecisionGrid.astro"; +import EvidenceClaim from "../../components/EvidenceClaim.astro"; +import SourceExcerpt from "../../components/SourceExcerpt.astro"; +import SourceList from "../../components/SourceList.astro"; + +The product's cleanest architectural sentence is: **each T3 environment is a +server-authoritative control plane around replaceable coding-agent runtimes.** + +Clients are thin with respect to trusted workspace execution—not small programs. +They express intent and render projected state, while Electron and mobile still own +substantial native behavior. For the selected environment, the server owns +repository-facing orchestration. A provider runtime owns its model/tool loop. The +adapter and `ProviderService` divide live protocol behavior from persisted session +binding and recovery state. + + + +## Six ownership layers + +
+ + + + + + + + + + + +
Ownership of durable, runtime, provider-native, client-local, and workspace state
OwnerOwnsDoes not own
T3 domaindurable project/thread history, lifecycle intent, messages, activities, proposed plans, checkpoint metadata, query projectionslive process objects, provider-native memory, every transient UI signal
ProviderService + session directoryinstance routing and persisted binding, cwd, model/runtime payload, continuation cursor, statusnative cursor meaning or provider reasoning
Provider adapterlive process/session object, native protocol, cursor interpretation, approval/input mapping, canonical event translationcross-provider product policy or durable projections
Provider runtimemodel/tool loop, native conversation/context, compaction, provider account authenticationT3's multi-environment UI, checkpoint model, or product lifecycle
Client shellnavigation, presentation, caches, device settings; mobile drafts and durable outbox; Electron OS integrationsauthoritative environment thread history or remote workspace execution
Selected environmentworkspace files, provider processes, Git, PTYs, server SQLite/files/settings/secretsother environments supervised by the same client
+
+ + + “The server is authoritative” applies per environment. The shared client registry can keep several environment descriptors and merge their projected work into one product surface. + + +## A normalized, deliberately bounded seam + + + + + +The contract is not a promise of feature equality. Its lifecycle, interaction, +history, rollback, feedback, and event-stream surface is deliberately bounded, but +not tiny. At this revision, the separate common capability object only describes +session model switching; other semantic differences +are expressed by adapter behavior, errors, and provider presentation. Uniform +orchestration is achieved by **normalizing at the boundary**, not by pretending the +providers are identical. + + + Capability discovery currently advertises only in-session model switching. The actual adapter seam also covers session lifecycle, turns, approvals, structured input, history, rollback, feedback, shutdown, and canonical events. + + +## Why the server is the real product kernel + + + + + + + In this book, **agent** is a provider-owned coding runtime or subagent, **provider adapter** is its T3 integration, **client** is a T3 product surface, and **environment** is one running T3 server plus the machine/state it exposes. Calling all four “the agent” hides the architecture. + + +## Source trail + + diff --git a/src/content/book/20-domain-vocabulary.mdx b/src/content/book/20-domain-vocabulary.mdx new file mode 100644 index 0000000..2864676 --- /dev/null +++ b/src/content/book/20-domain-vocabulary.mdx @@ -0,0 +1,117 @@ +--- +slug: domain-vocabulary +order: 20 +number: "2" +kind: chapter +part: Part I · Boundaries and vocabulary +partOrder: 1 +title: Environment, project, thread, turn, and session +shortTitle: Domain vocabulary +summary: The entities share a UI, but they have different identity, cardinality, ownership, and restart behavior. +status: source-checked +gates: [sources] +objectives: + - Distinguish product work items from provider and transport sessions. + - Understand which entity owns workspace, provider selection, history, and lifecycle. + - Separate durable thread state from ephemeral liveness and live plan progress. +keywords: [environment, project, thread, turn, session, entity model] +sourceAreas: [packages/contracts/src/environment.ts, packages/contracts/src/orchestration.ts, packages/contracts/src/providerRuntime.ts] +visuals: [entity relationship table, lifecycle scenario lab] +updatedAt: 2026-08-24 +--- + +import Callout from "../../components/Callout.astro"; +import EvidenceClaim from "../../components/EvidenceClaim.astro"; +import ScenarioLab from "../../components/ScenarioLab.astro"; +import SourceList from "../../components/SourceList.astro"; + +T3 Code's screens place projects, threads, turns, and provider sessions close +together, but none are synonyms. The clean model starts with an **environment**: +one running T3 server plus the machine and capabilities it exposes. A client can +hold several environment descriptors and merge their work into one view. + +## The entity ladder + +
+ + + + + + + + + + + +
Identity, parent, durable contents, and lifecycle for the main T3 Code entities
EntityParent / cardinalityWhat it carriesImportant boundary
Environmentclient catalog → manyserver identity, label, platform, version, capabilities, authenticated endpointone authority for the execution context it exposes; one physical host may expose several
Projectenvironment → manyworkspace root, repository identity, scripts, presentation metadataa discovered/configured root, not a task
Threadproject → manyworkspace selection, provider instance/model/modes, messages, activities, plans, checkpoints, lifecyclethe durable product work item
Turnthread → ordered manyone user request, provider lifecycle, generated assistant/tool activity, usage, checkpoint ordinala lifecycle episode, not necessarily a provider process
Provider sessionthread → current bindinginstance, cwd, model/runtime payload, continuation state, live adapter object when runningbinding can survive; the live object cannot and may later be created from continuation state
Connection sessionenvironment target → one attempt/leaseauthenticated socket, capabilities, generation, sequence cursortransport lifetime; reconnect replaces it without replacing the thread
+
+ +The thread is where product concepts converge. It identifies a project and +workspace, remembers the chosen provider instance and modes, and projects messages, +activities, proposed plans, checkpoints, and a summary of provider runtime state. +The provider's live session object remains outside that aggregate. + + + Background-agent liveness and live plan progress are convenience folds for the current process. They appear beside durable lifecycle and message state but intentionally disappear on restart. + + +## Similar names, different restart behavior + + + +Startup and lazy recovery are two separate transitions. On boot, projected +`starting` or `running` sessions that have no live adapter entry are settled as an +error. A later routed operation may use the persisted binding and continuation +cursor to create or resume a new adapter session; the old in-memory object itself is +never resurrected. +## A vocabulary rule for the rest of the book + +When the text says **session**, it qualifies the owner: provider session, RPC +session, browser auth session, or desktop backend process. When it says **task**, it +means either the durable product work item—a thread—or explicitly a provider-emitted +task/subagent activity. This avoids importing one harness's internal vocabulary into +the cross-provider domain model. + + + One client can supervise many environments. One environment exposes many projects. One project has many threads. One thread has many turns but only a current provider binding. Reconnect, resume, and restart act on different rungs of that ladder. + + + diff --git a/src/content/book/30-repository-atlas.mdx b/src/content/book/30-repository-atlas.mdx new file mode 100644 index 0000000..1ab04e1 --- /dev/null +++ b/src/content/book/30-repository-atlas.mdx @@ -0,0 +1,118 @@ +--- +slug: repository-atlas +order: 30 +number: "3" +kind: chapter +part: Part I · Boundaries and vocabulary +partOrder: 1 +title: Repository and dependency atlas +shortTitle: Repository atlas +summary: The monorepo is a product graph—five apps, shared contracts and runtime packages, protocol bridges, remote infrastructure, native modules, and release machinery. +status: source-checked +gates: [sources] +objectives: + - Map repository folders to runtime and distribution responsibilities. + - Distinguish dependency edges from process and protocol boundaries. + - Understand how the source inventory is reproduced from the pinned Git object. +keywords: [monorepo, packages, apps, dependencies, build graph, inventory] +sourceAreas: [apps, packages, infra, native, scripts, pnpm-workspace.yaml] +visuals: [monorepo dependency flow, package atlas, reproducible inventory] +updatedAt: 2026-08-24 +--- + +import Callout from "../../components/Callout.astro"; +import EvidenceClaim from "../../components/EvidenceClaim.astro"; +import Figure from "../../components/Figure.astro"; +import FlowLab from "../../components/FlowLab.astro"; +import Mermaid from "../../components/Mermaid.astro"; +import SourceList from "../../components/SourceList.astro"; +import SourceSnapshot from "../../components/SourceSnapshot.astro"; + +The repository is large enough that folder-by-folder reading obscures the design. +Treat it as a directed product graph: contracts define the language, runtime +packages implement reusable algorithms, apps choose a process topology, and +infrastructure/native/build layers complete delivery. + + + +These counts are not hand-maintained marketing numbers. `source:check` enumerates +tracked files at the locked Git commit, applies versioned extension and test-path +rules, and counts lines from Git objects. Assets and the `.repos` reference clones +are excluded; generated protocol source remains part of the implementation surface. + +## The atlas + +
+ + + + + + + + + + + + + + + + + +
Major repository areas and what they build or own
AreaPrimary outputArchitectural role
apps/serverpublished t3 CLI/serverexecution authority, persistence, HTTP/WS, providers, workspace services
apps/webReact browser bundlelocal, hosted, and Electron-renderer product UI
apps/desktopElectron applicationbackend ownership, WSL/SSH, exposure, preview, native IPC, updater
apps/mobileExpo iOS/Android appsremote-native UI, durable outbox/share, native terminal/diff, notifications
apps/marketingAstro/Vercel static sitedownload and publication surface, separate from product web
packages/contractsEffect schemas/typescanonical product, RPC, auth, provider, usage, and relay vocabulary
packages/client-runtimenon-visual client libraryconnection, RPC, snapshot/cursor state, caches, capability logic
packages/effect-*protocol bridgestyped Codex app-server and ACP clients
packages/ssh / tailscalereachability librariesremote launch/forward and endpoint provisioning
infra/relayCloudflare Worker/control planeidentity, tunnel allocation, connection credentials, agent awareness
nativeRust/native artifactsGhostty VT and resource monitoring
scripts / packaging / .githubartifacts and releasesversioning, signing, installers, CI, stores, AUR, hosted aliases
+
+ +## Dependency is not the same as deployment + +
+ S[apps/server] + C --> R[packages/client-runtime] + R --> W[apps/web] + R --> M[apps/mobile] + C --> D[apps/desktop] + W --> S + W --> D + S --> N[npm t3: server + copied web] + S --> D + X[effect-acp / codex bridge] --> S + H[ssh / tailscale / shared] --> S + H --> D + I[infra/relay] -.control plane.-> S`} /> +
+ +The arrow from web to server is a build edge: `apps/server` copies `apps/web/dist` +into its published client directory. At runtime, a browser still communicates with +the server over authenticated HTTP/WebSocket boundaries. Likewise, Electron imports +shared code and bundles a server, but its renderer remains isolated behind preload +IPC. + + + + + Shared schemas and state algorithms reduce semantic drift across products. The cost is coordinated versioning and capability-skew handling; sharing a package does not erase the security or process boundary. + + + + The `.repos` directory contains synchronized reference repositories and is not T3 Code production ownership. Generated protocol source inside first-party packages is included because it ships and constrains runtime behavior. The atlas always states which category a number uses. + + + diff --git a/src/content/book/40-runtime-topologies.mdx b/src/content/book/40-runtime-topologies.mdx new file mode 100644 index 0000000..b6dba6f --- /dev/null +++ b/src/content/book/40-runtime-topologies.mdx @@ -0,0 +1,110 @@ +--- +slug: runtime-topologies +order: 40 +number: "4" +kind: chapter +part: Part I · Boundaries and vocabulary +partOrder: 1 +title: Runtime topologies and technology placement +shortTitle: Runtime topologies +summary: The same contracts appear in several process graphs; local CLI, hosted web, Electron, and mobile move ownership without moving repository execution off the environment server. +status: source-checked +gates: [sources] +objectives: + - Draw the process and trust boundary for every execution client. + - Separate product UI families from delivery and publication shapes. + - Explain technology placement as verified mechanics or explicitly labeled inference. +keywords: [topology, Effect, SQLite, React, Electron, Expo, Astro] +sourceAreas: [apps/server, apps/web, apps/desktop, apps/mobile, apps/marketing] +visuals: [topology switcher, technology placement matrix] +updatedAt: 2026-08-24 +--- + +import Callout from "../../components/Callout.astro"; +import EvidenceClaim from "../../components/EvidenceClaim.astro"; +import ScenarioLab from "../../components/ScenarioLab.astro"; +import SourceList from "../../components/SourceList.astro"; + +There is no single “T3 Code process.” The invariant is an environment server that +owns authoritative repository/provider execution. What changes by product shape is +who launches that server, where the renderer runs, how it reaches the endpoint, and +which device-local systems surround the shared semantics. + + +## Technology placement, not mythology + +
+ + + + + + + + + + + + +
Where major technologies are used and the observable consequence of their placement
TechnologyPlacementVerified consequence
Effect + Schemacontracts, server services/scopes, client runtimeruntime-decoded boundaries, typed failure channels, scoped child resources, composable layers
SQLiteenvironment serverone transactional event/projection/accepted-receipt store plus indexed query models
Reactshared web rendererone UI serves local browser, hosted app, and Electron with runtime-specific composition
Electrondesktop main/preloadOS/backend/update/preview authority stays outside the sandboxed renderer
React Native + ExpoiOS/Androidnative persistence, navigation, modules, stores, and OTA use a separate release domain
GhosttyWASM on web; native modules on mobileterminal semantics are shared conceptually while rendering/input paths remain platform-specific
Astromarketing sitedownload/publication pages build independently of the React product client
+
+ + + The code proves where each technology is used and the boundaries it creates. Unless an upstream decision record says otherwise, explanations of *why*—for example, minimizing remote authority or preserving native scrolling—are architectural inference, not quoted maintainer intent. + + +## Marketing is the fifth delivery shape, not a fifth client + +The independent Astro marketing site discovers stable downloads and links to app +stores. It does not load `client-runtime`, connect to environments, or render thread +state. Counting it clarifies release/distribution ownership; placing it in the +execution topology would confuse publication with control. + + + Server, contracts, web, and desktop release in a lockstep version domain. Mobile's store version/build number and native fingerprint form another. The same architecture can therefore be compatible at the contract level while its packages show different version strings. + + + From 74d4bb5b1dd7c568cdb6ea3e4cdac1488cb1edf4 Mon Sep 17 00:00:00 2001 From: Ahmed Alaa <46384841+BenAlaa@users.noreply.github.com> Date: Mon, 24 Aug 2026 13:27:02 +0300 Subject: [PATCH 03/12] docs(book): publish part two boot and connect --- src/content/book/50-cli-bootstrap.mdx | 185 +++++++++++++ src/content/book/60-server-composition.mdx | 185 +++++++++++++ src/content/book/70-rpc-snapshots-resume.mdx | 200 ++++++++++++++ src/content/book/80-auth-pairing.mdx | 267 +++++++++++++++++++ 4 files changed, 837 insertions(+) create mode 100644 src/content/book/50-cli-bootstrap.mdx create mode 100644 src/content/book/60-server-composition.mdx create mode 100644 src/content/book/70-rpc-snapshots-resume.mdx create mode 100644 src/content/book/80-auth-pairing.mdx diff --git a/src/content/book/50-cli-bootstrap.mdx b/src/content/book/50-cli-bootstrap.mdx new file mode 100644 index 0000000..2adfad4 --- /dev/null +++ b/src/content/book/50-cli-bootstrap.mdx @@ -0,0 +1,185 @@ +--- +slug: cli-bootstrap +order: 50 +number: "5" +kind: chapter +part: Part II · Boot and connect +partOrder: 2 +title: The `npx t3` bootstrap path +shortTitle: CLI bootstrap +summary: The published package resolves commands and configuration, locates its copied web client, and hands one readonly ServerConfig value to the layered runtime. +status: source-checked +gates: [sources] +objectives: + - Trace npm's executable entry through command selection and server launch. + - Apply the real CLI, environment, desktop-bootstrap, and default precedence rules. + - Distinguish bundled JavaScript, copied web assets, and native external dependencies. +keywords: [npx t3, CLI, ServerConfig, bootstrap, static assets, npm package] +sourceAreas: [apps/server/src/bin.ts, apps/server/src/cli, apps/server/scripts/cli.ts, apps/server/vite.config.ts] +visuals: [package exploder, interactive bootstrap stepper, configuration scenario resolver] +updatedAt: 2026-08-24 +--- + +import Callout from "../../components/Callout.astro"; +import EvidenceClaim from "../../components/EvidenceClaim.astro"; +import Figure from "../../components/Figure.astro"; +import FlowLab from "../../components/FlowLab.astro"; +import Mermaid from "../../components/Mermaid.astro"; +import ScenarioLab from "../../components/ScenarioLab.astro"; +import SourceExcerpt from "../../components/SourceExcerpt.astro"; +import SourceList from "../../components/SourceList.astro"; + +`npx t3` looks like one command, but it crosses three distinct systems: npm +selects a published executable, the Effect CLI selects a command and resolves +configuration, and the server runtime acquires the services described in Chapter 6. +Keeping those stages separate makes several otherwise surprising behaviors obvious. + +## What npm actually installs + +The package is named `t3`, exposes `dist/bin.mjs` as the `t3` executable, and +publishes only `dist`. That directory is deliberately more than one JavaScript file. + +
+ + + + + + + + + +
Artifacts inside or beside the published T3 CLI bundle
ArtifactHow it gets thereWhy it remains distinct
dist/bin.mjsbundled from src/bin.tsthe npm executable and command graph
dist/service-launcher.mjssecond bundle entrystandalone managed-update trial and handoff process
dist/client/*copied from the completed web buildstatic web application served by the CLI
selected node_moduleskept external by policynative binaries/loaders must exist on the real filesystem
+
+ +
+ |bundle| CLI[dist/bin.mjs] + L[src/service-launcher.ts] -->|bundle| SL[dist/service-launcher.mjs] + W[apps/web/dist] -->|copy| UI[dist/client] + N[native dependency closure] -->|external| NM[node_modules] + CLI --> P[npm package: t3] + SL --> P + UI --> P + NM -.installed beside.-> P`} /> +
+ + + A local build warns and continues when `apps/web/dist` is absent. The publish path is stricter: it refuses to publish without the copied client entry and service launcher. At runtime the browser still crosses HTTP and WebSocket boundaries. + + +## One entry, several command meanings + + + +Bare `t3` and `t3 start` both call `runServerCommand` with normal browser +presentation. `t3 serve` is not merely an alias for `--no-browser`: it requests +headless presentation and forces cwd auto-bootstrap off so a service can start +without inventing project state. + + + +