feat: T2 freeze src/types.ts (shared contracts)

- All ARCHITECTURE §3 interfaces as pure types; dependency-free (no ws/node/DOM)
  so both backend and frontend can import it
- Refinements vs §3 (documented): EnvLike (not NodeJS.ProcessEnv), WebSocketLike +
  WS_OPEN (not ws.WebSocket), added Config.wsPath (invariant 8)
- ARCHITECTURE §3.1/§3.4 reconciled to match (anti-drift)
- tsc --noEmit passes

T2 of docs/PLAN.md
This commit is contained in:
Yaojia Wang
2026-06-16 07:58:52 +02:00
parent 409b208928
commit 0e10dc21c3
3 changed files with 203 additions and 8 deletions

View File

@@ -24,10 +24,11 @@
> 新会话读到的第一块。保持准确,只描述"此刻"。
- **Wave**: W0(T1 ✓)→ 下一步 **T2**(冻结 `src/types.ts`)
- **任务**: T2 — 共享类型契约,完成后 W0 全部 commit,即可放开 W1 并行
- **下一步**: 派 `module-builder`(sonnet)执行 T2,或主会话直接做;依据 ARCHITECTURE §3
- **阻塞**: 无。(前端打包待决项**已解决**:选 esbuild,已装好并接好 `build:web`/`dev:web`,约定写入 PLAN §1。)
- **Wave**: W0(T1 ✓ T2 ✓)→ **W1 可放开并行** + T3
- **任务**: 下一步派 **W1 批次**(单批 ~35 个,worktree 隔离):T3 mock + T4 config + T5 protocol +
T6 ring-buffer + T7 origin(再一批 T8T11 前端)。dispatch prompt 见 DISPATCH.md。
- **下一步**: `git commit` 本次(T2)后,按 DISPATCH 派第一批 W1 builder;每批返回后 orchestrator 写 LOG。
- **阻塞**: 无。`src/types.ts` 已冻结,所有 W1 任务可只读 import。
- **最后更新**: 2026-06-16
---
@@ -40,7 +41,7 @@
| 任务 | Wave | 模块 | 状态 | Steps (完成/总) | 完成日期 |
|------|------|------|------|------------------|----------|
| T1 | W0 | 脚手架 + 装齐依赖 | `[x]` | 5/5 | 2026-06-16 |
| T2 | W0 | `src/types.ts` 共享契约(冻结源) | `[ ]` | 0/8 | |
| T2 | W0 | `src/types.ts` 共享契约(冻结源) | `[x]` | 8/8 | 2026-06-16 |
| T3 | W0 | mock IPty 测试替身 | `[ ]` | 0/2 | — |
| T4 | W1 | `config.ts` | `[ ]` | 0/5 | — |
| T5 | W1 | `protocol.ts` | `[ ]` | 0/4 | — |
@@ -118,6 +119,23 @@
- **遗留 / 待办**: 无(原前端打包待决项已解决,见下补记)。
- **commit**: `b126cf0`
### 2026-06-16 · T2 冻结共享类型契约 src/types.ts
- **状态**: `[x]` DONE
- **改动**: 新建 `src/types.ts`(纯类型,无实现);删 `src/.gitkeep`。含 Config、ClientMessage/ServerMessage/
ParseResult、Dims、IPty(子集)+ IDisposable/PtyEvent、RingBuffer、WebSocketLike + WS_OPEN、SessionMeta/Session
(lastOutputAt/exitedAt/exitCode)、SessionManager、MountKeybar;各模块工厂函数签名以注释列为 import 锚点。
同步更新 ARCHITECTURE §3.1/§3.4(加 wsPath、EnvLike、WebSocketLike 注记,防漂移)。
- **验证**: `npx tsc -p tsconfig.json --noEmit` PASS;grep 确认无 `ws`/`NodeJS`/DOM 外部类型依赖(仅注释提及)。
- **决策 / 偏离 ARCHITECTURE §3**(为"前后端共享 → 必须无外部类型依赖"):
1. `loadConfig(env: EnvLike)` 替代 `NodeJS.ProcessEnv`(`EnvLike = Readonly<Record<string,string|undefined>>`,process.env 可赋值)。
2. `Session.attachedWs: WebSocketLike` 替代 `ws``WebSocket`(真实 ws 结构兼容);导出 `WS_OPEN=1` 供 M5 守卫。
3. **新增 `Config.wsPath`**(默认 '/term'):不变量 8 要求 WS 路径入 config,§3.1 原 Config 漏列,已补;T4 需从 env `WS_PATH` 读、T14 用 `cfg.wsPath`
三处均已回写 ARCHITECTURE,types.ts 为权威冻结源。
- **遗留 / 待办**: 无。W1 全部任务现可只读 import `src/types.ts`。**注意**:IPty/WebSocketLike 是结构子集,
实现方(T12/T14)可把真实 node-pty IPty / ws.WebSocket 直接赋值(结构兼容)。
- **commit**: (见下次提交)
### 2026-06-16 · T1 补记 — 前端打包定为 esbuild
- **状态**: `[x]` DONE