Open History to see the last commit
1# Architecture
2
3T3 Code keeps execution in the environment that owns the workspace. Web, desktop, and mobile
4clients control it over authenticated RPC. A remote client must never substitute its own filesystem,
5provider credentials, or machine state for the environment's. The desktop app bundles a server,
6but its renderer follows the same boundary.
7
8## Ownership boundaries
9
10Provider processes, terminals, Git, and project files belong to the server. Shared connection and
11domain state belongs in `packages/client-runtime`; clients supply platform services and UI.
12Keeping that logic shared prevents reconnect and multi-environment behavior from diverging between
13web and mobile. See [connection runtime](./connection-runtime.md) and
14[remote environments](./remote.md).
15
16The [RPC contract](../../packages/contracts/src/rpc.ts) is the boundary between independently
17versioned clients and servers. Subscriptions send the state a client needs, so a client viewing one
18thread does not pay for every thread's history. Authentication of a socket does not authorize every
19method on it. See [environment auth](./environment-auth.md).
20
21### Pull request linking compatibility
22
23Web, desktop, mobile, and environments upgrade independently. Negotiate linking through the
24environment descriptor, never through a client version or an assumed coordinated release:
25
26| Environment capability | Client behavior |
27| ------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
28| `threadPullRequests: true` | Use persisted `pullRequests[]`, multi-link commands, stack UI, and reverse thread lookup. |
29| Only `threadPullRequestLinking: true` | Use `linkedPullRequest` and the existing `thread.meta.update` single-link operation. Do not call multi-link RPCs. |
30| Neither flag | Hide linking actions; existing branch-discovered PR display remains available. |
31
32New environments continue advertising the legacy flag, accepting legacy metadata commands, and
33emitting the derived `linkedPullRequest` field for older clients. That hostless field includes only
34links in the thread project's own repository; cross-host and cross-repository links require the
35multi-link protocol. New clients accept snapshots that
36omit `pullRequests`. Retain the legacy wire fields, projection column, and replay support; this feature
37does not schedule their removal. Missing new capabilities must also override cached multi-link data
38after an environment downgrade.
39
40Provider-specific behavior belongs behind an adapter. Orchestration works with normalized commands
41and events, so adding a provider should not require branches throughout the domain or clients.
42See [provider constraints](./providers.md).
43
44## Settings ownership
45
46Client preferences stay in the current client; environment defaults and project overrides stay
47on their owning server. The web and desktop settings target is URL state, resolved against current
48connections and project membership. An unavailable target must not fall back to another environment.
49**All environments** is an explicit bulk edit of connected, loaded servers, not a durable global
50default or a promise to synchronize offline or future environments. Project-group targets similarly
51select known environment-local checkouts; the group itself does not store inherited defaults.
52
53## Durable intent and side effects
54
55The event log is the source of truth for orchestration state. The
56[engine](../../apps/server/src/orchestration/Layers/OrchestrationEngine.ts) serializes commands;
57the [decider](../../apps/server/src/orchestration/decider.ts) produces events without performing
58provider or filesystem work. Events, persisted projections, and the accepted command receipt commit
59in one database transaction. The in-memory state changes and subscribers receive events after that
60commit. This keeps command retries idempotent and prevents a persisted projection from getting
61ahead of the event log.
62
63Reactors perform side effects after intent has been recorded, then feed results back through
64commands. A command acknowledgement therefore means the intent committed, not that the provider,
65checkpoint, or other follow-up work finished. Keep external I/O out of the decider and the database
66transaction.
67
68Persisted events must remain decodable on replay. Changing a schema affects old environments at
69startup as well as live RPC traffic. Compatibility work must account for stored history, not just
70what the newest client sends.
71
72## Turn completion and checkpoints
73
74A turn ending and its follow-up work settling are separate milestones. The
75[projector](../../apps/server/src/orchestration/projector.ts) settles the turn from its session
76status. A late checkpoint or diff must not extend the recorded turn duration or keep the client
77showing provider work as active.
78
79[Checkpoints](../../apps/server/src/checkpointing/CheckpointStore.ts) use hidden Git refs to
80capture workspace state without adding commits to the user's branch. A revert must coordinate
81workspace state with the provider conversation. A provider that cannot roll back its conversation
82must reject that operation before changing the filesystem.
83
84## Waiting for asynchronous work
85
86Tests use [drainable workers](../../packages/shared/src/DrainableWorker.ts) to wait until both the
87queue and its current item have finished. An empty queue alone does not prove the worker is idle.
88
89Runtime receipts mark specific test milestones. Their
90[production layer](../../apps/server/src/orchestration/Layers/RuntimeReceiptBus.ts) is a no-op;
91production behavior must use persisted state and events. These test signals are separate from the
92durable command receipts that make dispatch idempotent.
93
94The Electron shell acquires `DesktopPreReadyPlatform.layer` synchronously before asynchronous
95services. On Linux this sets the desktop-entry identity and global-shortcut portal flags before
96Chromium initializes its portal connection. Setting the identity later in `DesktopAppIdentity`
97is too late: Chromium caches the first registration, including failures. The identity must match
98the installed entry managed by `DesktopLinuxUrlHandler`. Pre-ready setup also refreshes that entry's
99`Exec` path before portal registration: AppImage updates can remove the previous executable, which
100makes the old entry invalid even though its filename is correct. The later URL handler avoids
101rewriting an identical entry while the portal may be reading it. On Wayland, Electron's synchronous
102shortcut-registration result only confirms submission; it does not confirm desktop consent or
103an active binding.
104
105Native modules never load in the Electron main process on the startup path, and the two the
106snapshot feature keeps are isolated: `@crowecawcaw/xa11y` runs only in forked Node-mode children
107(`SnapShotAccessibilityWorker`, `RegionSnapShotWorker`) and a worker thread, and `ffi-rs` loads
108lazily inside `WindowsForeground.ts` for a handful of Win32 calls. macOS window lookup shells out
109to `osascript` instead of a native addon. A crash or stall in any of these must not take the app
110down, so new native capability goes in a child with a deadline, not an `import` in main.
111
112See the [glossary](./glossary.md) for shared terms and the
113[development runbook](../operations/development.md) for setup and checks.