# task-016

status: done

## goal
Add a when branch for ClientMessage.ChatInput in handleClientMessage() that dispatches to module.routerFacade and sends RouterResponseMessage back over WebSocket.

## target artifact
apps/server/src/main/kotlin/com/correx/apps/server/ws/SessionStreamHandler.kt

## execution steps
1. Add `routerFacade: RouterFacade` property to `ServerModule` data class.
2. In `Main.kt`, wire `DefaultRouterFacade` into `ServerModule` (requires constructing RouterRepository, RouterContextBuilder, and RouterConfig alongside the existing InferenceRouter and EventStore).
3. In `SessionStreamHandler.kt`:
   - Add import: `com.correx.core.router.RouterFacade`
   - Add import: `com.correx.apps.server.protocol.ServerMessage.RouterResponseMessage`
   - Replace the `is ClientMessage.ChatInput` branch (currently only logs a warning) with:
     ```kotlin
     is ClientMessage.ChatInput -> {
         runCatching {
             module.routerFacade.handleChat(
                 sessionId = msg.sessionId,
                 text = msg.text,
                 mode = msg.mode,
             )
         }.onSuccess { response ->
             session.send(Frame.Text(
                 ProtocolSerializer.encodeServerMessage(
                     RouterResponseMessage(
                         sessionId = msg.sessionId,
                         content = response.content,
                         steeringEmitted = response.steeringEmitted,
                     )
                 )
             ))
         }.onFailure {
             log.error("routerFacade.handleChat failed for session={}: {}", msg.sessionId.value, it.message, it)
             val error = ServerMessage.ProtocolError("Router error: ${it.message}")
             session.send(Frame.Text(ProtocolSerializer.encodeServerMessage(error)))
         }
     }
     ```
4. Run `./gradlew :apps:server:compileKotlin` to verify compilation.

## changed artifacts
- `apps/server/src/main/kotlin/com/correx/apps/server/ServerModule.kt` — add `routerFacade: RouterFacade` property
- `apps/server/src/main/kotlin/com/correx/apps/server/Main.kt` — wire DefaultRouterFacade into ServerModule
- `apps/server/src/main/kotlin/com/correx/apps/server/ws/SessionStreamHandler.kt` — replace ChatInput no-op with router dispatch

## blockers
- Resolved: user approved proceeding against non-goal for infrastructure wiring.

## notes
- `RouterResponseMessage` already exists in `ServerMessage.kt` (task-015) — no new protocol types needed.
- `ChatInput` already exists in `ClientMessage.kt` (task-014) with `ChatMode` enum.
- `core:router` is already a dependency of `apps:server` — no new module dependency needed.
- `RouterConfig` import is `com.correx.core.router.model.RouterConfig`, not `com.correx.core.router.RouterConfig`.
- `inferenceRouter` was extracted into a separate variable so it could be reused in both `engines` and `routerFacade` constructions.
- kover coverage check fails (12.55% vs 70% threshold) — expected for new code without tests. Not in scope for this task.
- The `DefaultRouterReducer() as RouterReducer` cast was unnecessary and removed — Kotlin's type inference handles it correctly.
- `printStartupBanner` compilation error was from a prior abandoned change — reverted by user. No actual blocker.
