diff --git a/apps/server/src/main/kotlin/com/correx/apps/server/bridge/SessionEventBridge.kt b/apps/server/src/main/kotlin/com/correx/apps/server/bridge/SessionEventBridge.kt index 44333661..4fd047c4 100644 --- a/apps/server/src/main/kotlin/com/correx/apps/server/bridge/SessionEventBridge.kt +++ b/apps/server/src/main/kotlin/com/correx/apps/server/bridge/SessionEventBridge.kt @@ -35,20 +35,8 @@ class SessionEventBridge( ?.map { ApprovalDto(requestId = it.id.value, tier = it.tier.name) } ?: emptyList() - val pendingRequest = approvalState?.requests?.values - ?.firstOrNull { req -> approvalState.decisions.values.none { it.requestId == req.id } } - send(ServerMessage.SessionSnapshot( sessionId = sessionId, - workflowId = orchState.workflowId, - status = orchState.status.name, - currentStageId = orchState.currentStageId?.value, - pauseReason = orchState.pauseReason, - pendingApproval = orchState.pendingApproval, - approvalRequestId = pendingRequest?.id?.value, - approvalTier = pendingRequest?.tier?.name, - approvalToolName = pendingRequest?.toolName, - approvalPreview = pendingRequest?.preview, state = SessionStateDto( status = orchState.status.name, currentStageId = orchState.currentStageId?.value, diff --git a/apps/server/src/main/kotlin/com/correx/apps/server/protocol/ServerMessage.kt b/apps/server/src/main/kotlin/com/correx/apps/server/protocol/ServerMessage.kt index 80b06214..ba7f94bc 100644 --- a/apps/server/src/main/kotlin/com/correx/apps/server/protocol/ServerMessage.kt +++ b/apps/server/src/main/kotlin/com/correx/apps/server/protocol/ServerMessage.kt @@ -76,15 +76,6 @@ sealed interface ServerMessage { @SerialName("session_snapshot") data class SessionSnapshot( val sessionId: SessionId, - val workflowId: String, - val status: String, - val currentStageId: String?, - val pauseReason: String?, - val pendingApproval: Boolean, - val approvalRequestId: String?, - val approvalTier: String?, - val approvalToolName: String?, - val approvalPreview: String?, val state: SessionStateDto, val pendingApprovals: List, val lastSequence: Long, diff --git a/apps/server/src/test/kotlin/com/correx/apps/server/protocol/ServerMessageSerializationTest.kt b/apps/server/src/test/kotlin/com/correx/apps/server/protocol/ServerMessageSerializationTest.kt index cc3ca40c..96a70763 100644 --- a/apps/server/src/test/kotlin/com/correx/apps/server/protocol/ServerMessageSerializationTest.kt +++ b/apps/server/src/test/kotlin/com/correx/apps/server/protocol/ServerMessageSerializationTest.kt @@ -39,15 +39,6 @@ class ServerMessageSerializationTest { fun `SessionSnapshot encodes lastSequence and lastSessionSequence`() { val msg = ServerMessage.SessionSnapshot( sessionId = SessionId("sess-1"), - workflowId = "wf-1", - status = "running", - currentStageId = "stage-1", - pauseReason = null, - pendingApproval = false, - approvalRequestId = null, - approvalTier = null, - approvalToolName = null, - approvalPreview = null, state = SessionStateDto( status = "running", currentStageId = "stage-1", diff --git a/apps/tui/src/main/kotlin/com/correx/apps/tui/reducer/SessionsReducer.kt b/apps/tui/src/main/kotlin/com/correx/apps/tui/reducer/SessionsReducer.kt index 7d53ffe6..71214e91 100644 --- a/apps/tui/src/main/kotlin/com/correx/apps/tui/reducer/SessionsReducer.kt +++ b/apps/tui/src/main/kotlin/com/correx/apps/tui/reducer/SessionsReducer.kt @@ -117,28 +117,26 @@ object SessionsReducer { sessionState: SessionsState, msg: ServerMessage.SessionSnapshot, ): Pair> { - val approvalRequestId = msg.approvalRequestId - val approvalInfo = if (msg.pendingApproval && approvalRequestId != null) { + val firstPending = msg.pendingApprovals.firstOrNull() + val approvalInfo = firstPending?.let { ApprovalInfo( - requestId = approvalRequestId, + requestId = it.requestId, sessionId = msg.sessionId.value, - tier = msg.approvalTier ?: "T2", + tier = it.tier, riskSummary = "unknown", - toolName = msg.approvalToolName, - preview = msg.approvalPreview, + toolName = null, + preview = null, ) - } else null + } + val status = if (firstPending != null) "PAUSED awaiting approval" else msg.state.status val summary = SessionSummary( id = msg.sessionId.value, - status = when { - msg.pendingApproval -> "PAUSED awaiting approval" - else -> msg.status - }, - workflowId = msg.workflowId, - name = msg.workflowId, + status = status, + workflowId = msg.sessionId.value, + name = msg.sessionId.value, lastEventAt = clock(), - currentStage = msg.currentStageId, - currentStageId = msg.currentStageId, + currentStage = msg.state.currentStageId, + currentStageId = msg.state.currentStageId, pendingApproval = approvalInfo, ) val selected = sessionState.selectedId ?: msg.sessionId.value diff --git a/apps/tui/src/test/kotlin/com/correx/apps/tui/reducer/SessionsReducerTest.kt b/apps/tui/src/test/kotlin/com/correx/apps/tui/reducer/SessionsReducerTest.kt index 37cb538d..2371728a 100644 --- a/apps/tui/src/test/kotlin/com/correx/apps/tui/reducer/SessionsReducerTest.kt +++ b/apps/tui/src/test/kotlin/com/correx/apps/tui/reducer/SessionsReducerTest.kt @@ -290,42 +290,24 @@ class SessionsReducerTest { } @Test - fun `SessionSnapshot with pendingApproval populates pendingApproval on summary`() { + fun `SessionSnapshot with pendingApprovals populates pendingApproval on summary`() { val msg = ServerMessage.SessionSnapshot( sessionId = SessionId("s1"), - workflowId = "wf", - status = "PAUSED", - currentStageId = null, - pauseReason = null, - pendingApproval = true, - approvalRequestId = "r9", - approvalTier = "T2", - approvalToolName = "bash", - approvalPreview = "preview text", state = com.correx.apps.server.protocol.SessionStateDto("PAUSED", null, null), - pendingApprovals = emptyList(), + pendingApprovals = listOf(com.correx.apps.server.protocol.ApprovalDto(requestId = "r9", tier = "T2")), lastSequence = 1L, lastSessionSequence = 1L, ) val (state, _) = reduce(action = Action.ServerEventReceived(msg)) assertEquals("r9", state.sessions[0].pendingApproval?.requestId) - assertEquals("bash", state.sessions[0].pendingApproval?.toolName) + assertEquals("PAUSED awaiting approval", state.sessions[0].status) } @Test - fun `SessionSnapshot without pendingApproval leaves pendingApproval null`() { + fun `SessionSnapshot without pendingApprovals leaves pendingApproval null`() { val msg = ServerMessage.SessionSnapshot( sessionId = SessionId("s1"), - workflowId = "wf", - status = "ACTIVE", - currentStageId = null, - pauseReason = null, - pendingApproval = false, - approvalRequestId = null, - approvalTier = null, - approvalToolName = null, - approvalPreview = null, - state = com.correx.apps.server.protocol.SessionStateDto("PAUSED", null, null), + state = com.correx.apps.server.protocol.SessionStateDto("ACTIVE", null, null), pendingApprovals = emptyList(), lastSequence = 1L, lastSessionSequence = 1L, diff --git a/apps/tui/src/test/kotlin/com/correx/apps/tui/reducer/SnapshotPhaseReducerTest.kt b/apps/tui/src/test/kotlin/com/correx/apps/tui/reducer/SnapshotPhaseReducerTest.kt index 3958d530..469c8f78 100644 --- a/apps/tui/src/test/kotlin/com/correx/apps/tui/reducer/SnapshotPhaseReducerTest.kt +++ b/apps/tui/src/test/kotlin/com/correx/apps/tui/reducer/SnapshotPhaseReducerTest.kt @@ -108,15 +108,6 @@ class SnapshotPhaseReducerTest { val state = TuiState(snapshotPhase = true) val snapshot = ServerMessage.SessionSnapshot( sessionId = SessionId("s1"), - workflowId = "wf", - status = "ACTIVE", - currentStageId = null, - pauseReason = null, - pendingApproval = false, - approvalRequestId = null, - approvalTier = null, - approvalToolName = null, - approvalPreview = null, state = SessionStateDto(status = "ACTIVE", currentStageId = null, pauseReason = null), pendingApprovals = emptyList(), lastSequence = 1L,