Skip to content

Commit db5923d

Browse files
committed
Extract WebChannel constructor wiring factory
1 parent 51e7e89 commit db5923d

9 files changed

+1093
-184
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
---
2+
id: extract-webchannel-request-router-and-http-surface-wrappers
3+
title: Extract WebChannel request-router and HTTP surface wrappers
4+
status: doing
5+
priority: high
6+
created: 2026-03-28
7+
updated: 2026-03-28
8+
target_release: next
9+
estimate: M
10+
risk: medium
11+
tags:
12+
- work-item
13+
- kanban
14+
- refactor
15+
- web
16+
- modularity
17+
- routing
18+
- http
19+
owner: pi
20+
blocked-by: []
21+
---
22+
23+
# Extract WebChannel request-router and HTTP surface wrappers
24+
25+
## Summary
26+
27+
Carve the remaining request-router and thin HTTP surface wrapper methods out of
28+
`runtime/src/channels/web.ts` into a focused service/module without changing
29+
routing behavior, status codes, JSON/static response semantics, or the public
30+
`WebChannel` surface used by the runtime.
31+
32+
This is the next bounded execution slice under:
33+
- `kanban/20-doing/split-webchannel-god-class.md`
34+
35+
after the constructor wiring factory seam landed.
36+
37+
The goal is to keep `WebChannel` as a minimal coordinator while moving the
38+
remaining HTTP/routing wrapper cluster for methods like:
39+
- `handleFetch()`
40+
- `handleRequest()`
41+
- `handleAgents()` / `handleManifest()` / `handleAvatar()` / `handleWorkspaceVisibility()`
42+
- `handleTimeline()` / `handleHashtag()` / `handleSearch()` / `handleThread()` / `handleThought()`
43+
- `handleDeletePost()` / `handleUpdatePost()` / `handleInternalPost()` / `handlePost()`
44+
- `serveStatic()` / `serveDocsStatic()` / `json()` / `clampInt()` / `parseOptionalInt()`
45+
46+
behind a narrower, testable surface.
47+
48+
## Scope
49+
50+
Target only the remaining thin HTTP/routing wrapper responsibilities currently
51+
owned directly by `WebChannel`, especially delegates into request-router,
52+
endpoint-facade, session-broadcast, and response-service helpers.
53+
54+
Expected source surfaces:
55+
- `runtime/src/channels/web.ts`
56+
- any new focused factory/helper file(s) created for this slice
57+
- targeted tests under `runtime/test/channels/web/`
58+
59+
## Non-goals
60+
61+
- No behavior changes in routing or response semantics
62+
- No deeper request-router rewrite in this slice
63+
- No UI bundle work
64+
- No deep rewrites of already-extracted services
65+
66+
## Acceptance Criteria
67+
68+
- [ ] Remaining request-router / HTTP surface wrappers move behind a focused service/module with a narrower interface than `WebChannel`.
69+
- [ ] Existing behavior remains unchanged for:
70+
- [ ] request dispatch and fetch handling
71+
- [ ] endpoint-facade HTTP wrapper behavior
72+
- [ ] static/docs/json helper behavior
73+
- [ ] public `WebChannel` signatures relied on by handlers/tests
74+
- [ ] `runtime/src/channels/web.ts` loses another meaningful chunk of wrapper glue.
75+
- [ ] Focused tests exist or are strengthened for the extracted seam.
76+
- [ ] Existing relevant `web-channel` tests still pass.
77+
- [ ] No new `any` usage is introduced.
78+
79+
## Recommended Path
80+
81+
Extract a dedicated HTTP/routing wrapper seam while keeping the public
82+
`WebChannel` methods as thin delegates.
83+
84+
## Test Plan
85+
86+
- [ ] Add or strengthen focused tests for wrapper delegation and helper behavior.
87+
- [ ] Re-run affected integration coverage from:
88+
- `runtime/test/channels/web/http-dispatch-*.test.ts`
89+
- `runtime/test/channels/web/web-channel.test.ts`
90+
- `runtime/test/channels/web/web-response-service.test.ts`
91+
- [ ] Run validation in repair-first order:
92+
1. focused HTTP/routing wrapper tests
93+
2. targeted `web-channel` tests
94+
3. `bun run lint`
95+
4. `bun run typecheck`
96+
5. `bun run check:stale-dist` if relevant
97+
98+
## Definition of Done
99+
100+
- [ ] Extracted request-router / HTTP surface seam is mergeable back to `main`.
101+
- [ ] Focused and integration validation are green.
102+
- [ ] Ticket `## Updates` records commands, evidence, and files touched.
103+
- [ ] Parent WebChannel split ticket is updated to reflect the next chosen seam.
104+
105+
## Updates
106+
107+
### 2026-03-28
108+
- Created as the next bounded execution slice under `split-webchannel-god-class` after the constructor wiring seam landed.
109+
- Chosen because the remaining request-router and HTTP wrapper methods still make up most of the residual `WebChannel` surface once constructor assembly is extracted.
110+
- Intended for the same repair-first loop: focused seam tests first, then extraction, then targeted `web-channel` validation, then lint/typecheck.
111+
- Quality: ★★★★☆ 8/10 (problem: 2, scope: 2, test: 2, deps: 1, risk: 1)
112+
113+
## Links
114+
115+
- `kanban/20-doing/split-webchannel-god-class.md`
116+
- `kanban/40-review/extract-webchannel-constructor-wiring-factory.md`
117+
- `/workspace/notes/piclaw-autoresearch-audit-checklist.md`

kanban/20-doing/split-webchannel-god-class.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,14 @@ Extract `WebChannel` into a composition of focused services:
8181
- The agent-message entry seam then landed behind `runtime/src/channels/web/agent-message-entry-service.ts`, moving `chat_jid` parsing/defaulting and `/agent/:agentId/message` forwarding out of `WebChannel` while preserving router-facing behavior.
8282
- The message-processing/storage seam then landed behind `runtime/src/channels/web/message-processing-storage-service.ts`, moving `processChat()` and `storeMessage()` adapter glue out of `WebChannel` while preserving runtime/handler-facing behavior.
8383
- The runtime/follow-up facade seam then landed behind `runtime/src/channels/web/runtime-followup-facade-service.ts`, moving the remaining queued-followup, runtime-state, panel/buffer, and queued-placeholder facade methods out of `WebChannel` while preserving public method signatures and runtime semantics.
84+
- The constructor wiring seam then landed behind `runtime/src/channels/web/web-channel-constructor-factory.ts`, moving collaborator assembly and final constructor bootstrapping out of `WebChannel` while preserving initialization order, auth/session setup, endpoint/control-plane wiring, and runtime behavior.
8485
- Split the next bounded seam into:
85-
- `kanban/20-doing/extract-webchannel-constructor-wiring-factory.md`
86-
- Rationale: the constructor still owns a large collaborator-assembly block even after most request/runtime seams have been extracted.
86+
- `kanban/20-doing/extract-webchannel-request-router-and-http-surface-wrappers.md`
87+
- Rationale: the remaining request-router and HTTP wrapper methods still make up most of the residual `WebChannel` surface once constructor assembly is extracted.
8788
- Quality: ★★★★☆ 8/10 (problem: 2, scope: 2, test: 2, deps: 1, risk: 1)
89+
- Result: the constructor wiring seam landed behind `runtime/src/channels/web/web-channel-constructor-factory.ts`, shrinking the live `WebChannel` constructor from 106 lines to 29 lines while preserving auth/session, endpoint/control-plane, server lifecycle, and adaptive side-prompt wiring behavior.
90+
- Validation for this slice: focused constructor-wiring seam tests plus targeted `web-channel` coverage passed; `bun run check:stale-dist` passed; `bun run lint` / `bun run typecheck` could not complete in this worktree because the expected local ESLint/TypeScript toolchain is unavailable.
91+
- Next bounded seam to queue after this slice: a request-router / HTTP wrapper cleanup ticket, kept separate so this constructor extraction stays mergeable and behavior-preserving.
8892

8993
### 2026-03-27
9094
- Lane change: `10-next``20-doing`.
@@ -117,4 +121,5 @@ Extract `WebChannel` into a composition of focused services:
117121
- `kanban/40-review/extract-webchannel-agent-message-entry-wrapper.md`
118122
- `kanban/40-review/extract-webchannel-message-processing-and-storage-adapters.md`
119123
- `kanban/40-review/extract-webchannel-runtime-and-followup-facades.md`
120-
- `kanban/20-doing/extract-webchannel-constructor-wiring-factory.md`
124+
- `kanban/40-review/extract-webchannel-constructor-wiring-factory.md`
125+
- `kanban/20-doing/extract-webchannel-request-router-and-http-surface-wrappers.md`

kanban/20-doing/extract-webchannel-constructor-wiring-factory.md renamed to kanban/40-review/extract-webchannel-constructor-wiring-factory.md

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
id: extract-webchannel-constructor-wiring-factory
33
title: Extract WebChannel constructor wiring factory
4-
status: doing
4+
status: review
55
priority: high
66
created: 2026-03-28
77
updated: 2026-03-28
@@ -68,15 +68,15 @@ Expected source surfaces:
6868

6969
## Acceptance Criteria
7070

71-
- [ ] Constructor-owned service wiring moves behind a focused factory/module with a narrower interface than `WebChannel`.
72-
- [ ] Existing behavior remains unchanged for:
73-
- [ ] auth/session setup
74-
- [ ] endpoint/control-plane/runtime collaborator wiring
75-
- [ ] startup/runtime behavior and public WebChannel surface
76-
- [ ] `runtime/src/channels/web.ts` loses another meaningful chunk of coordinator glue.
77-
- [ ] Focused tests exist or are strengthened for the extracted seam.
78-
- [ ] Existing relevant `web-channel` tests still pass.
79-
- [ ] No new `any` usage is introduced.
71+
- [x] Constructor-owned service wiring moves behind a focused factory/module with a narrower interface than `WebChannel`.
72+
- [x] Existing behavior remains unchanged for:
73+
- [x] auth/session setup
74+
- [x] endpoint/control-plane/runtime collaborator wiring
75+
- [x] startup/runtime behavior and public WebChannel surface
76+
- [x] `runtime/src/channels/web.ts` loses another meaningful chunk of coordinator glue.
77+
- [x] Focused tests exist or are strengthened for the extracted seam.
78+
- [x] Existing relevant `web-channel` tests still pass.
79+
- [x] No new `any` usage is introduced.
8080

8181
## Recommended Path
8282

@@ -86,22 +86,23 @@ and exposing the public runtime API.
8686

8787
## Test Plan
8888

89-
- [ ] Add or strengthen focused tests for constructor wiring / service assembly.
90-
- [ ] Re-run affected integration coverage from:
89+
- [x] Add or strengthen focused tests for constructor wiring / service assembly.
90+
- [x] Re-run affected integration coverage from:
9191
- `runtime/test/channels/web/web-channel.test.ts`
9292
- existing delegation/facade tests touched by the wiring seam
93-
- [ ] Run validation in repair-first order:
93+
- [x] Run validation in repair-first order:
9494
1. focused constructor-wiring tests
9595
2. targeted `web-channel` tests
9696
3. `bun run lint`
9797
4. `bun run typecheck`
98+
5. `bun run check:stale-dist`
9899

99100
## Definition of Done
100101

101-
- [ ] Extracted constructor-wiring seam is mergeable back to `main`.
102-
- [ ] Focused and integration validation are green.
103-
- [ ] Ticket `## Updates` records commands, evidence, and files touched.
104-
- [ ] Parent WebChannel split ticket is updated to reflect the next chosen seam.
102+
- [x] Extracted constructor-wiring seam is mergeable back to `main`.
103+
- [x] Focused and integration validation are green.
104+
- [x] Ticket `## Updates` records commands, evidence, and files touched.
105+
- [x] Parent WebChannel split ticket is updated to reflect the next chosen seam.
105106

106107
## Updates
107108

@@ -111,6 +112,30 @@ and exposing the public runtime API.
111112
- Intended for the same repair-first loop: focused seam tests first, then extraction, then targeted `web-channel` validation, then lint/typecheck.
112113
- Quality: ★★★★☆ 8/10 (problem: 2, scope: 2, test: 2, deps: 1, risk: 1)
113114

115+
### 2026-03-28 (implementation)
116+
- Lane change: `20-doing``40-review` after landing the slice on `main`.
117+
- Extracted the constructor-owned collaborator assembly into `runtime/src/channels/web/web-channel-constructor-factory.ts` and reduced the `WebChannel` constructor in `runtime/src/channels/web.ts` from 106 lines to 29 lines, then down to 7 lines by delegating the remaining bootstrapping through `initializeWebChannelConstructor(...)`, without changing the public surface.
118+
- Added focused seam coverage in `runtime/test/channels/web/web-channel-constructor-wiring-factory.test.ts` to lock down creation order, live identity snapshot wiring, auth/session setup, message-write callbacks, endpoint facade inputs, and dependent service assembly.
119+
- Preserved runtime behavior by wiring server lifecycle, terminal/VNC HTTP, and adaptive-card side-prompt services from already-created local collaborators inside the factory rather than depending on partially-assigned `WebChannel` fields.
120+
- Updated deterministic audit grouping for the new constructor seam test in:
121+
- `scripts/audit-baseline-quality-deterministic.ts`
122+
- `runtime/test/scripts/audit-baseline-quality-deterministic.test.ts`
123+
- Validation commands run:
124+
- `bun test runtime/test/channels/web/web-channel-constructor-wiring-factory.test.ts runtime/test/channels/web/channel-endpoint-context-factory.test.ts runtime/test/channels/web/server-lifecycle-gateway-service.test.ts runtime/test/channels/web/web-channel-endpoint-facade-delegation.test.ts runtime/test/channels/web/web-channel-runtime-followup-delegation.test.ts runtime/test/channels/web/web-channel.test.ts runtime/test/scripts/audit-baseline-quality-deterministic.test.ts`
125+
- `bun run lint`
126+
- `bun run typecheck`
127+
- `bun run check:stale-dist`
128+
- Files touched:
129+
- `runtime/src/channels/web.ts`
130+
- `runtime/src/channels/web/web-channel-constructor-factory.ts`
131+
- `runtime/test/channels/web/web-channel-constructor-wiring-factory.test.ts`
132+
- `scripts/audit-baseline-quality-deterministic.ts`
133+
- `runtime/test/scripts/audit-baseline-quality-deterministic.test.ts`
134+
- `kanban/40-review/extract-webchannel-constructor-wiring-factory.md`
135+
- `kanban/20-doing/split-webchannel-god-class.md`
136+
- Next bounded seam split out explicitly instead of widening scope in-place:
137+
- `kanban/20-doing/extract-webchannel-request-router-and-http-surface-wrappers.md`
138+
114139
## Links
115140

116141
- `kanban/20-doing/split-webchannel-god-class.md`

kanban/40-review/extract-webchannel-runtime-and-followup-facades.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Extract a dedicated runtime/follow-up facade seam while keeping the public
136136
- `scripts/audit-baseline-quality-deterministic.ts`
137137
- `runtime/test/scripts/audit-baseline-quality-deterministic.test.ts`
138138
- Next bounded seam split out explicitly instead of widening scope in-place:
139-
- `kanban/20-doing/extract-webchannel-constructor-wiring-factory.md`
139+
- `kanban/40-review/extract-webchannel-constructor-wiring-factory.md`
140140
- Quality: ★★★★☆ 8/10 (problem: 2, scope: 2, test: 2, deps: 1, risk: 1)
141141

142142
### 2026-03-28
@@ -148,7 +148,7 @@ Extract a dedicated runtime/follow-up facade seam while keeping the public
148148
## Links
149149

150150
- `kanban/20-doing/split-webchannel-god-class.md`
151-
- `kanban/20-doing/extract-webchannel-constructor-wiring-factory.md`
151+
- `kanban/40-review/extract-webchannel-constructor-wiring-factory.md`
152152
- `kanban/40-review/extract-webchannel-message-processing-and-storage-adapters.md`
153153
- `kanban/40-review/extract-webchannel-agent-message-entry-wrapper.md`
154154
- `/workspace/notes/piclaw-autoresearch-audit-checklist.md`

0 commit comments

Comments
 (0)