| 1 | # RFC: Codewhale Workrooms — Chat-native Threaded Agent Work |
| 2 | |
| 3 | **Issue:** #3209 |
| 4 | **Status:** Future RFC — the Workroom wire shape and link parser are defined |
| 5 | once, outside this repository: `cwc_core::workroom` and |
| 6 | `packages/contracts/src/workroom.js` in codewhale-contracts (authority: |
| 7 | codewhale-platform `crates/cwc-core`), which a Project's room serves. The |
| 8 | earlier copy in `crates/protocol/src/workroom.rs` had no consumers and was |
| 9 | removed. Phase 2 (store, app-server endpoints, `resolve_workroom_link` tool, |
| 10 | TUI inbox) not started |
| 11 | **Date:** 2026-06-17 (status refreshed 2026-07-15) |
| 12 | **Target:** post-v0.9.0; the release label is a maintainer decision, not part |
| 13 | of this design |
| 14 | |
| 15 | This document is design scaffolding. This tree carries none of it: the |
| 16 | protocol types and link parser live in codewhale-contracts (see Status), and |
| 17 | runtime endpoints, mobile UI integration, persistent state, and model-visible |
| 18 | tools remain follow-up work. |
| 19 | |
| 20 | ## 1. Problem |
| 21 | |
| 22 | Codewhale agent work currently lives in transient TUI sessions, local Runtime API |
| 23 | threads, Fleet runs, and chat-bridge message loops — each with its own lifecycle, |
| 24 | state representation, and context boundary. There is no first-class abstraction |
| 25 | that: |
| 26 | |
| 27 | - lets a user start work on one surface (TUI) and resume it on another (mobile) |
| 28 | - gives a stable, shareable link to a thread of agent work |
| 29 | - attaches GitHub issues/PRs/commits as context without copying transcripts |
| 30 | - records which agent/model produced each event for multi-agent workflows |
| 31 | - provides a unified inbox of mentions, approvals, failures, and completions |
| 32 | |
| 33 | ## 2. Proposed Abstraction: `Workroom` |
| 34 | |
| 35 | A `Workroom` is a durable, addressable container for a threaded conversation |
| 36 | involving one or more agents, models, and human participants. It maps onto |
| 37 | the existing Runtime API thread infrastructure and extends it with: |
| 38 | |
| 39 | ### 2.1 Core Types |
| 40 | |
| 41 | ```rust |
| 42 | /// Unique identifier for a workroom, stable across restarts. |
| 43 | pub struct WorkroomId(pub String); // e.g. "wr_abc123def456" |
| 44 | |
| 45 | /// A workroom aggregates threads, members, and metadata. |
| 46 | pub struct Workroom { |
| 47 | pub id: WorkroomId, |
| 48 | pub title: String, |
| 49 | pub workspace: Option<String>, // repo root or project path |
| 50 | pub repo_identity: Option<RepoRef>, // GitHub repo identity (owner/name) |
| 51 | pub owner: String, // local user or identity handle |
| 52 | pub created_at: DateTime<Utc>, |
| 53 | pub updated_at: DateTime<Utc>, |
| 54 | pub visibility: WorkroomVisibility, |
| 55 | } |
| 56 | |
| 57 | pub enum WorkroomVisibility { |
| 58 | Private, |
| 59 | Shared { allowed_tokens: Vec<String> }, |
| 60 | } |
| 61 | |
| 62 | /// A thread within a workroom — can be a channel, DM, or linked external ref. |
| 63 | pub struct WorkroomThread { |
| 64 | pub id: String, |
| 65 | pub workroom_id: WorkroomId, |
| 66 | pub title: String, |
| 67 | pub kind: WorkroomThreadKind, |
| 68 | pub external_ref: Option<ExternalThreadRef>, |
| 69 | pub created_at: DateTime<Utc>, |
| 70 | } |
| 71 | |
| 72 | pub enum WorkroomThreadKind { |
| 73 | Channel, |
| 74 | DirectMessage, |
| 75 | AgentTask, // spawned by an agent for sub-work |
| 76 | ApprovalQueue, // pending human approvals |
| 77 | ReceiptLog, // completed agent receipts |
| 78 | } |
| 79 | |
| 80 | /// An external reference that can be attached to a workroom thread. |
| 81 | pub enum ExternalThreadRef { |
| 82 | GitHubIssue { |
| 83 | owner: String, |
| 84 | repo: String, |
| 85 | number: u64, |
| 86 | }, |
| 87 | GitHubPullRequest { |
| 88 | owner: String, |
| 89 | repo: String, |
| 90 | number: u64, |
| 91 | }, |
| 92 | GitHubCommit { |
| 93 | owner: String, |
| 94 | repo: String, |
| 95 | sha: String, |
| 96 | }, |
| 97 | GitHubCheck { |
| 98 | owner: String, |
| 99 | repo: String, |
| 100 | check_run_id: u64, |
| 101 | }, |
| 102 | } |
| 103 | |
| 104 | /// An event within a workroom thread, attributed to an agent/model. |
| 105 | pub struct WorkroomEvent { |
| 106 | pub id: String, |
| 107 | pub thread_id: String, |
| 108 | pub workroom_id: WorkroomId, |
| 109 | pub timestamp: DateTime<Utc>, |
| 110 | pub kind: WorkroomEventKind, |
| 111 | pub agent: Option<AgentAttribution>, |
| 112 | } |
| 113 | |
| 114 | pub enum WorkroomEventKind { |
| 115 | Message { content: String }, |
| 116 | Mention { mentioned_user: String }, |
| 117 | ToolCall { tool_name: String, summary: String }, |
| 118 | ToolResult { tool_name: String, success: bool }, |
| 119 | ApprovalRequest { tool_name: String }, |
| 120 | ArtifactLinked { path: String, kind: String }, |
| 121 | Receipt { summary: String }, |
| 122 | Failure { error: String }, |
| 123 | NeedsHuman { reason: String }, |
| 124 | Resumed, |
| 125 | } |
| 126 | |
| 127 | pub struct AgentAttribution { |
| 128 | pub provider: String, // e.g. "deepseek" |
| 129 | pub model: String, // e.g. "deepseek-v4-pro" |
| 130 | pub agent_id: String, // sub-agent or fleet worker id |
| 131 | } |
| 132 | |
| 133 | /// A link that can be pasted into any surface and resolved back to a workroom. |
| 134 | pub struct WorkroomLink { |
| 135 | pub workroom_id: WorkroomId, |
| 136 | pub thread_id: Option<String>, |
| 137 | pub event_id: Option<String>, |
| 138 | } |
| 139 | ``` |
| 140 | |
| 141 | ### 2.2 Link Format |
| 142 | |
| 143 | ``` |
| 144 | codewhale://workroom/wr_abc123def456 |
| 145 | codewhale://workroom/wr_abc123def456/thread/thr_xyz |
| 146 | codewhale://workroom/wr_abc123def456/event/evt_789 |
| 147 | ``` |
| 148 | |
| 149 | ### 2.3 Mapping to Existing Infrastructure |
| 150 | |
| 151 | | Workroom concept | Existing mapping | |
| 152 | |---|---| |
| 153 | | `Workroom` | New abstraction; future persisted state alongside Runtime API threads | |
| 154 | | `WorkroomThread` | Maps to a `ThreadId` in the Runtime API | |
| 155 | | `WorkroomEvent` | Wraps existing thread/fleet events with agent attribution | |
| 156 | | `WorkroomLink` | New URL scheme resolvable by the Runtime API | |
| 157 | | `ExternalThreadRef` | New; metadata-only, no secret/token storage | |
| 158 | | `AgentAttribution` | Extracted from sub-agent metadata and fleet worker identity | |
| 159 | |
| 160 | ## 3. Planned Runtime API Endpoints |
| 161 | |
| 162 | ### 3.1 `GET /workrooms` |
| 163 | |
| 164 | List all workrooms visible to the authenticated caller. |
| 165 | |
| 166 | Response: |
| 167 | ```json |
| 168 | { |
| 169 | "workrooms": [ |
| 170 | { |
| 171 | "id": "wr_abc123", |
| 172 | "title": "PR #3231 — DeepInfra support", |
| 173 | "updated_at": "2026-06-15T12:00:00Z", |
| 174 | "active_threads": 3 |
| 175 | } |
| 176 | ] |
| 177 | } |
| 178 | ``` |
| 179 | |
| 180 | ### 3.2 `GET /workroom/:id/threads` |
| 181 | |
| 182 | List active threads within a workroom. |
| 183 | |
| 184 | ### 3.3 `GET /workroom/resolve?link=codewhale://workroom/wr_abc/thread/thr_x` |
| 185 | |
| 186 | Resolve a workroom link to scoped context (thread metadata, recent events) |
| 187 | without replaying the full transcript. |
| 188 | |
| 189 | ### 3.4 Planned tool: `resolve_workroom_link` |
| 190 | |
| 191 | A model-visible tool that takes a `codewhale://workroom/...` URL and returns |
| 192 | the scoped context (thread title, recent event summaries, external refs). This |
| 193 | should not be registered until the backing runtime resolution behavior exists. |
| 194 | |
| 195 | ## 4. Security Model |
| 196 | |
| 197 | - **Local-first by default.** Persisted workroom state should live under the |
| 198 | Codewhale home directory alongside existing state. No cloud service is |
| 199 | assumed. |
| 200 | - **Runtime API auth required.** Planned workroom endpoints must use the same |
| 201 | `Authorization: Bearer <token>` protection as other runtime surfaces. |
| 202 | - **No secrets in links.** Workroom links contain only opaque IDs, never API |
| 203 | keys or tokens. Resolution requires local Runtime API access. |
| 204 | - **No secrets in events.** Event payloads must not contain API keys, auth |
| 205 | tokens, or plaintext credentials. The `ArtifactLinked` event kind references |
| 206 | paths, not contents. |
| 207 | - **Share semantics.** `WorkroomVisibility::Shared` lists allowed bearer tokens, |
| 208 | not usernames. The operator controls which tokens can access a workroom. |
| 209 | - **No public links.** There is no unauthenticated read path for workrooms. |
| 210 | |
| 211 | ## 5. Integration Points |
| 212 | |
| 213 | ### 5.1 Mobile Control Page |
| 214 | |
| 215 | The mobile page at `/mobile` already lists active threads. Replace its |
| 216 | ad-hoc thread listing with the `/workrooms` projection so it renders the |
| 217 | same inbox that the TUI and chat bridges see. |
| 218 | |
| 219 | ### 5.2 Chat Bridges (Telegram, Feishu) |
| 220 | |
| 221 | Chat bridges currently maintain their own message loops. Each bridge should |
| 222 | publish bridge-originated messages as `WorkroomEvent::Message` into a |
| 223 | designated workroom thread, and consume `WorkroomEvent::Mention` events |
| 224 | as bridge notifications. |
| 225 | |
| 226 | ### 5.3 TUI |
| 227 | |
| 228 | The TUI should surface workroom inbox events (mentions, approvals) in the |
| 229 | sidebar, and allow pasting `codewhale://` links into the composer for |
| 230 | context resolution. |
| 231 | |
| 232 | ## 6. Implementation Plan |
| 233 | |
| 234 | ### Phase 1: Foundation (this PR) |
| 235 | - [x] RFC design doc |
| 236 | - [x] `WorkroomId`, `Workroom`, `WorkroomThread`, `WorkroomEvent`, `WorkroomLink` types |
| 237 | - [x] `ExternalThreadRef` (GitHub refs as workroom context) |
| 238 | - [x] `AgentAttribution` (multi-agent/model event attribution) |
| 239 | - [x] Security model documentation |
| 240 | - [x] Architecture docs |
| 241 | |
| 242 | ### Phase 2: Integration (follow-up) |
| 243 | - [ ] Persistent workroom state store |
| 244 | - [ ] Runtime API endpoints: `GET /workrooms`, `GET /workroom/:id/threads` |
| 245 | - [ ] `resolve_workroom_link` tool for link resolution |
| 246 | - [ ] Mobile page consumes workroom projection |
| 247 | - [ ] Chat bridges publish/consume workroom events |
| 248 | - [ ] TUI inbox sidebar |
| 249 | - [ ] Workroom link paste resolution in composer |
| 250 | |
| 251 | ## 7. Non-goals for Phase 1 |
| 252 | |
| 253 | - No hosted public Codewhale cloud service |
| 254 | - No default-on Slack/Discord/Feishu/Telegram/GitHub App integration |
| 255 | - No arbitrary public share links without explicit auth story |
| 256 | - No model-specific workroom format |
| 257 | - No migration of existing threads (new workrooms only) |
| 258 |