附录
A · 源码索引
按问题而不是目录查找 T3 Code 的入口、核心实现与测试。
这份索引用于从文档结论跳回源码。链接指向上游 main,本地分析基线为 0.0.33 快照;上游路径若变化,
可用表中的文件名在仓库内搜索。
启动与组合
| 问题 | 实现 | 配套证据 |
|---|---|---|
| CLI 参数怎样进入 Server | apps/server/src/bin.ts | apps/server/src/cli/* |
| Layer/服务如何装配 | apps/server/src/server.ts | 各 Layers/* |
| WebSocket RPC 怎样挂载 | apps/server/src/ws.ts | auth/RPC tests |
| 数据迁移怎样汇总 | Migrations.ts | Migrations/001..040 |
Contracts 与 RPC
| 问题 | 实现 |
|---|---|
| RPC 方法、输入输出和 stream | packages/contracts/src/rpc.ts |
| Shared Schema / 领域类型 | packages/contracts/src |
| 方法到 scope 映射 | RpcAuthorization.ts |
| WebSocket upgrade 认证 | EnvironmentAuth.ts |
| HTTP auth / ticket | auth/http.ts |
| DPoP proof | auth/dpop.ts |
编排核心
| 问题 | 实现 | 重点测试 |
|---|---|---|
| command queue、事务、receipt、publish | OrchestrationEngine.ts | OrchestrationEngine.test.ts |
| command 如何决定 events | decider.ts | decider.*.test.ts |
| events 如何形成 read model | projector.ts | projector*.test.ts |
| 意图如何调用 Provider | ProviderCommandReactor.ts | 同名 test |
| Provider event 如何回流 | ProviderRuntimeIngestion.ts | base/activity/approval tests |
| checkpoint 如何挂在 turn 上 | CheckpointReactor.ts | 同名 test |
| 可 drain 后台 worker | DrainableWorker.ts | DrainableWorker.test.ts |
持久化
| 主题 | 迁移/目录 |
|---|---|
| 事件日志 | 001_OrchestrationEvents.ts |
| 幂等回执 | 002_OrchestrationCommandReceipts.ts |
| Checkpoint diff blob | 003_CheckpointDiffBlobs.ts |
| Provider session runtime | 004_ProviderSessionRuntime.ts |
| 初始关系投影 | 005_Projections.ts |
| 全部 Schema 演化 | Migrations/ |
Provider 通用层
| 问题 | 实现 |
|---|---|
| Adapter 统一接口 | Services/ProviderAdapter.ts |
| Driver 工厂契约 | ProviderDriver.ts |
| Built-in 顺序 | builtInDrivers.ts |
| Provider catalog | builtInProviderCatalog.ts |
| 实例 hydration/live registry | ProviderInstanceRegistryHydration.ts, ProviderInstanceRegistryLive.ts |
| Adapter registry | ProviderAdapterRegistry.ts |
| Session directory/reaper | ProviderSessionDirectory.ts, ProviderSessionReaper.ts |
| Instance env 隔离 | ProviderInstanceEnvironment.ts |
各 Provider
| Provider | Driver | Adapter/Runtime | 底层协议包 |
|---|---|---|---|
| Codex | CodexDriver.ts | CodexAdapter.ts, CodexSessionRuntime.ts | effect-codex-app-server |
| Claude | ClaudeDriver.ts | ClaudeAdapter.ts, ClaudeProvider.ts | Claude Agent SDK |
| Cursor | CursorDriver.ts | CursorAdapter.ts, provider/acp/*Cursor* | effect-acp |
| Grok | GrokDriver.ts | GrokAdapter.ts, provider/acp/*Grok/XAi* | effect-acp |
| OpenCode | OpenCodeDriver.ts | OpenCodeAdapter.ts, opencodeRuntime.ts | OpenCode SDK |
Git、终端、预览、遥测
| 能力 | 实现 |
|---|---|
| Checkpoint 业务抽象 | CheckpointStore.ts |
| Git checkpoint/diff/restore | GitVcsDriver.ts |
| Git process/core | GitVcsDriverCore.ts |
| Terminal manager | terminal/Manager.ts |
| Node/Bun PTY | NodePtyAdapter.ts, BunPtyAdapter.ts |
| Port discovery/preview | PortScanner.ts, preview/Manager.ts |
| Resource telemetry | resourceTelemetry/ |
| Rust monitor | native/resource-monitor |
Client Runtime
| 问题 | 实现 |
|---|---|
| 环境 catalog | connection/catalog.ts |
| endpoint 解析 | connection/resolver.ts |
| 环境 scope/lease | connection/registry.ts |
| 重试状态机 | connection/supervisor.ts |
| 单次 RPC session | rpc/session.ts |
| Snapshot/reducer/atoms | state/ |
| Remote authorization | authorization/ |
| Relay discovery | relay/ |
Web、Desktop、Mobile
| 端 | 入口 | 关键目录 |
|---|---|---|
| Web | apps/web/src/main.tsx | routes/, components/, connection/, rpc/ |
| Desktop | apps/desktop/src/main.ts | app/, backend/, ipc/, ssh/, wsl/, updates/, preview/ |
| Mobile | apps/mobile/src/App.tsx | features/, state/, native iOS/Android modules |
Remote / Relay
| 问题 | 实现 |
|---|---|
| Server cloud boot/managed endpoint | apps/server/src/cloud |
| Relay Worker entry | infra/relay/src/worker.ts |
| Relay HTTP API | infra/relay/src/http/Api.ts |
| Environment link/connector/endpoint | infra/relay/src/environments |
| Relay token/DPoP | infra/relay/src/auth |
| Mobile activity/APNs | infra/relay/src/agentActivity |
推荐的源码追踪顺序
遇到一个产品动作时,不要从 UI 沿 imports 漫游,按下面顺序定位:
contracts RPC/schema
→ ws handler / client operation
→ orchestration command + decider
→ committed event + projector
→ reactor / adapter side effect
→ runtime ingestion result
→ client reducer + view
→ tests at each boundary这条顺序能始终回答“当前读到的是意图、事实、外部副作用还是展示派生”。