# task-009

status: done

## goal
Implement `RouterReducer` — reduces `RouterState` from `SteeringNoteAddedEvent` and workflow lifecycle events (started, completed, failed, paused, resumed, stage completed, stage failed).

## target artifact
core/router/src/main/kotlin/com/correx/core/router/RouterReducer.kt

## execution steps
- Create `RouterReducer` interface in `core/router` module matching the convention (`reduce(state: RouterState, event: StoredEvent): RouterState`)
- Implement `DefaultRouterReducer` class implementing `RouterReducer`
- Handle `SteeringNoteAddedEvent` — append a USER-role `RouterTurn` to `conversationHistory`
- Handle `WorkflowStartedEvent` — set `workflowStatus = RUNNING`, set `currentStageId` from `startStageId`
- Handle `WorkflowCompletedEvent` — set `workflowStatus = COMPLETED`, clear `currentStageId`
- Handle `WorkflowFailedEvent` — set `workflowStatus = FAILED`, clear `currentStageId`
- Handle `OrchestrationPausedEvent` — set `workflowStatus = PAUSED`
- Handle `OrchestrationResumedEvent` — set `workflowStatus = RUNNING`
- Handle `StageCompletedEvent` — append a `RouterL2Entry` with `StageOutcomeKind.SUCCESS` to `l2Memory`
- Handle `StageFailedEvent` — append a `RouterL2Entry` with `StageOutcomeKind.FAILURE` to `l2Memory`, clear `currentStageId`
- Return unchanged `state` for any unknown event types (catch-all `else` branch)

## changed artifacts
- `core/router/src/main/kotlin/com/correx/core/router/RouterReducer.kt` — new file

## blockers
- none

## notes
- Handler methods that don't need payload data (`handleWorkflowCompleted`, `handleWorkflowFailed`, `handleOrchestrationPaused`, `handleOrchestrationResumed`) take only `state` parameter to avoid detekt `UnusedParameter` warnings
- All state mutations use `state.copy(...)` per core architecture pattern — state is never mutated in place
- Timestamps come from `event.metadata.timestamp` to preserve the original event ordering
