Commit 2063cca
authored
refactor(10/12): rewire CLI, daemon, and MCP server boundaries (#328)
## Summary
This is **PR 10 of 12** in a stacked PR series that decouples the rendering pipeline from MCP transport. Depends on PR 9 (all tool migrations complete). This PR connects the dots -- it rewires the three output boundaries (CLI, daemon, MCP server) to use the render session from PR 3 with the event-based handlers from PRs 5-9.
### Architecture: three boundaries, one rendering engine
The rendering pipeline has three consumers, each using the same render session differently:
**CLI direct** (`src/cli/register-tool-commands.ts`): Creates a render session with the user's chosen strategy (text or JSON). Wraps `emit` to write incrementally to stdout as events arrive (streaming output during builds). After the handler completes, calls `finalize()` to flush any buffered content (grouped diagnostics). Sets exit code from `session.isError()`.
**MCP server** (`src/utils/tool-registry.ts`): Creates a render session with text strategy. After the handler completes, calls `finalize()` to get the complete rendered string, wraps it in a `ToolResponse` (the MCP protocol type). `ToolResponse` construction happens here and only here -- it is not exported or used anywhere else in the codebase.
**Daemon** (`src/daemon/daemon-server.ts`): Creates a render session in record-only mode. Sends raw events over the wire to the CLI client. The CLI client re-renders locally using its own session, giving the same output as CLI direct mode.
### CLI changes
- `output.ts`: Deleted `printToolResponse()`, `extractRenderedNextSteps()`, and all `_meta` coordination logic. These were the main sources of complexity in the old rendering pipeline. Kept `formatToolList()` for `--list` output.
- `register-tool-commands.ts`: Now creates and manages the render session directly. Streaming output is handled by a thin wrapper around `session.emit()`.
- `daemon-client.ts`: Updated to receive events from daemon and render locally.
### Daemon protocol
- Protocol version bumped to v2. Wire payload is now `{ events, attachments?, isError? }` instead of pre-rendered content.
- Old CLI + new daemon (or vice versa) gets a clear version mismatch error with restart instructions.
### MCP resources
All MCP resource handlers updated to use the simplified context pattern (10 files). These are simpler than tool handlers since resources don't emit pipeline events.
### Other changes
- `src/integrations/xcode-tools-bridge/`: Updated to work with the new handler context. Added `bridge-tool-result.ts` for structured bridge tool results.
- `src/visibility/exposure.ts`: Updated exposure predicates for new handler signatures.
- `src/smoke-tests/`: Updated test harness for new tool invocation pattern.
- Various utility files updated for signature changes: `CommandExecutor`, `FileSystemExecutor`, `execution/`, `xcode-state-reader`, `xcode-state-watcher`, `video-capture`, `log_capture`.
## Stack navigation
- PR 1-9/12: Foundation, utilities, contract, tool migrations
- **PR 10/12** (this PR): CLI, daemon, MCP server boundaries
- PR 11/12: Manifests, config, docs, examples
- PR 12/12: Snapshot test fixtures and benchmarks
## Test plan
- [ ] `npx vitest run` passes -- boundary tests updated
- [ ] CLI text output matches expected formatting (manual spot check)
- [ ] CLI JSON output produces valid JSONL
- [ ] MCP server returns correctly structured `ToolResponse` content
- [ ] Daemon protocol v2 correctly transmits events over wire
- [ ] Smoke tests pass with new tool invocation pattern1 parent e4d3934 commit 2063cca
File tree
59 files changed
+1092
-1236
lines changed- src
- cli
- __tests__
- core
- __tests__
- daemon
- __tests__
- integrations/xcode-tools-bridge
- mcp/resources
- __tests__
- server
- smoke-tests
- __tests__
- test-utils
- utils
- __tests__
- execution
- log-capture
- video-capture
- visibility
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
59 files changed
+1092
-1236
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 26 | + | |
30 | 27 | | |
31 | 28 | | |
32 | 29 | | |
| |||
97 | 94 | | |
98 | 95 | | |
99 | 96 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
104 | 100 | | |
105 | 101 | | |
106 | 102 | | |
| |||
126 | 122 | | |
127 | 123 | | |
128 | 124 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
133 | 128 | | |
134 | 129 | | |
135 | 130 | | |
| |||
159 | 154 | | |
160 | 155 | | |
161 | 156 | | |
| 157 | + | |
| 158 | + | |
162 | 159 | | |
163 | 160 | | |
164 | 161 | | |
| |||
167 | 164 | | |
168 | 165 | | |
169 | 166 | | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
| 167 | + | |
176 | 168 | | |
177 | | - | |
178 | | - | |
| 169 | + | |
| 170 | + | |
179 | 171 | | |
180 | 172 | | |
181 | 173 | | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
186 | 177 | | |
187 | 178 | | |
188 | 179 | | |
| |||
202 | 193 | | |
203 | 194 | | |
204 | 195 | | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
209 | 199 | | |
210 | 200 | | |
211 | 201 | | |
| |||
253 | 243 | | |
254 | 244 | | |
255 | 245 | | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
260 | 249 | | |
261 | 250 | | |
262 | 251 | | |
| |||
281 | 270 | | |
282 | 271 | | |
283 | 272 | | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
284 | 353 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
55 | | - | |
| 57 | + | |
| 58 | + | |
56 | 59 | | |
57 | 60 | | |
58 | 61 | | |
59 | | - | |
60 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
61 | 79 | | |
62 | 80 | | |
63 | 81 | | |
| |||
83 | 101 | | |
84 | 102 | | |
85 | 103 | | |
86 | | - | |
87 | | - | |
| 104 | + | |
| 105 | + | |
88 | 106 | | |
89 | 107 | | |
90 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | | - | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
22 | 29 | | |
23 | 30 | | |
24 | 31 | | |
| |||
81 | 88 | | |
82 | 89 | | |
83 | 90 | | |
84 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
85 | 99 | | |
86 | 100 | | |
87 | 101 | | |
| |||
124 | 138 | | |
125 | 139 | | |
126 | 140 | | |
127 | | - | |
| 141 | + | |
128 | 142 | | |
129 | 143 | | |
130 | 144 | | |
131 | 145 | | |
132 | | - | |
| 146 | + | |
133 | 147 | | |
134 | 148 | | |
135 | 149 | | |
| |||
146 | 160 | | |
147 | 161 | | |
148 | 162 | | |
149 | | - | |
| 163 | + | |
150 | 164 | | |
151 | 165 | | |
152 | 166 | | |
153 | 167 | | |
154 | | - | |
| 168 | + | |
155 | 169 | | |
156 | 170 | | |
157 | 171 | | |
| |||
0 commit comments