返回 CodeWhale
WORKROOM_ARCHITECTURE.md
根目录 / docs / WORKROOM_ARCHITECTURE.md
1 # Workroom Architecture
2
3 ## Purpose
4
5 Workrooms are CodeWhale's chat-native abstraction for durable, addressable
6 threads of agent work. They sit between the Runtime API's transient thread
7 model and the user-facing surfaces (TUI, mobile, chat bridges).
8
9 This is a draft v0.9 architecture note. In v0.8.62, only the protocol data
10 types and link parser are present. Runtime endpoints, persistent state, mobile
11 rendering, and model-visible link resolution are planned follow-ups.
12
13 ## Component map
14
15 ```
16 ┌─────────────────────────────────────────────────────┐
17 │ User surfaces │
18 │ ┌──────┐ ┌─────────┐ ┌──────────┐ │
19 │ │ TUI │ │ Mobile │ │ Bridges │ │
20 │ └──┬───┘ └────┬────┘ └────┬─────┘ │
21 │ │ │ │ │
22 │ └───────────┼────────────┘ │
23 │ │ future HTTP + workroom links │
24 ├─────────────────┼───────────────────────────────────┤
25 │ Runtime API │ │
26 │ ┌──────────────┴──────────────┐ │
27 │ │ Planned workroom endpoints │ │
28 │ │ GET /workrooms │ │
29 │ │ GET /workroom/:id/threads │ │
30 │ │ GET /workroom/resolve │ │
31 │ └──────────────┬─────────────┘ │
32 │ │ │
33 │ ┌──────────────┴─────────────┐ │
34 │ │ Existing endpoints │ │
35 │ │ /thread /app /prompt ... │ │
36 │ └────────────────────────────┘ │
37 └─────────────────────────────────────────────────────┘
38 ```
39
40 ## Data flow
41
42 1. **Creation.** A future workroom is created when a thread is started with a
43 workroom context (title, workspace, external refs). The workroom id
44 is stable and can be shared as a `codewhale://workroom/...` link.
45
46 2. **Event publication.** Each agent action (tool call, approval, failure)
47 is recorded as a `WorkroomEvent` in the workroom's event log. Events
48 carry `AgentAttribution` metadata tracing which provider, model, and
49 agent produced them.
50
51 3. **Link resolution.** When a `codewhale://workroom/...` link appears in
52 a chat surface, a future `resolve_workroom_link` tool (or API endpoint)
53 parses it and returns scoped context: thread metadata, external refs,
54 and recent event summaries. The calling model can then decide whether
55 to read the full thread transcript.
56
57 4. **Listing.** A future `/workrooms` endpoint returns a summary of all visible
58 workrooms (id, title, updated_at, active thread count). Surfaces
59 consume this for inbox/recent-activity views.
60
61 ## State store
62
63 Persisted workroom state should live alongside existing CodeWhale state:
64
65 ```
66 ~/.codewhale/
67 ├── workrooms/
68 │ ├── wr_abc123.json # Workroom metadata + event log
69 │ └── wr_def456.json
70 ├── threads/ # Existing thread state (unchanged)
71 ├── checkpoints/
72 ├── config.toml
73 └── ...
74 ```
75
76 Each `.json` file would contain the workroom metadata (`Workroom` struct),
77 a list of `WorkroomThread` descriptors, and a bounded set of recent
78 `WorkroomEvent` records. This state store is not implemented yet.
79
80 ## Crate responsibilities
81
82 | Crate | Responsibility |
83 |---|---|
84 | `codewhale-protocol` | Types: `Workroom`, `WorkroomId`, `WorkroomThread`, `WorkroomEvent`, `WorkroomLink`, `ExternalThreadRef`, `AgentAttribution` |
85 | `codewhale-app-server` | Future endpoints: `GET /workrooms`, `GET /workroom/:id/threads`, `GET /workroom/resolve` |
86 | `codewhale-tui` | Future model-facing link resolution and optional sidebar inbox |
87 | `codewhale-state` | Future: persistent workroom store (Phase 2) |
88
89 ## Phase status
90
91 | Phase | Feature | Status |
92 |---|---|---|
93 | 1 | RFC design doc | ✅ Complete |
94 | 1 | Protocol data types | ✅ Complete (with tests) |
95 | 1 | App-server workroom endpoints | ⏳ Not started |
96 | 1 | `resolve_workroom_link` tool | ⏳ Not started |
97 | 1 | Security model docs | ✅ Complete |
98 | 1 | Architecture docs | ✅ Complete |
99 | 2 | Persistent workroom state store | ⏳ Not started |
100 | 2 | Mobile page workroom inbox | ⏳ Not started |
101 | 2 | Chat bridge event integration | ⏳ Not started |
102 | 2 | TUI sidebar inbox | ⏳ Not started |
103
103 lines MARKDOWN