fix: PAUSED resume after server restart, diff viewer only shows last tool

This commit is contained in:
2026-05-26 22:26:56 +04:00
parent 1af42befca
commit 92bea6c2c4
3 changed files with 56 additions and 14 deletions
@@ -163,9 +163,9 @@ private fun renderIdleLayout(frame: Frame, state: TuiState) {
private fun renderInSessionLayout(frame: Frame, state: TuiState) {
val area = frame.area()
val selectedSession = state.sessions.sessions.firstOrNull { it.id == state.sessions.selectedId }
val hasDiff = selectedSession?.tools?.any {
it.status == ToolDisplayStatus.COMPLETED && it.diff != null
} == true
val hasDiff = selectedSession?.tools
?.lastOrNull { it.status == ToolDisplayStatus.COMPLETED }
?.diff != null
val constraints = mutableListOf(
Constraint.length(STATUS_HEIGHT),
@@ -197,12 +197,20 @@ private fun renderInSessionLayout(frame: Frame, state: TuiState) {
private fun renderApprovalLayout(frame: Frame, state: TuiState) {
val area = frame.area()
val selectedSession = state.sessions.sessions.firstOrNull { it.id == state.sessions.selectedId }
val hasDiff = selectedSession?.tools
?.lastOrNull { it.status == ToolDisplayStatus.COMPLETED }
?.diff != null
val constraints = mutableListOf(
Constraint.length(STATUS_HEIGHT),
)
if (state.eventStripVisible) {
constraints.add(Constraint.length(EVENT_STRIP_HEIGHT))
}
if (hasDiff) {
constraints.add(Constraint.length(DIFF_HEIGHT))
}
constraints.add(Constraint.fill())
constraints.add(Constraint.length(INPUT_HEIGHT))
@@ -215,6 +223,9 @@ private fun renderApprovalLayout(frame: Frame, state: TuiState) {
if (state.eventStripVisible) {
frame.renderWidget(eventHistoryStripWidget(state), vertRects[rectIdx++])
}
if (hasDiff) {
frame.renderWidget(diffViewerWidget(state), vertRects[rectIdx++])
}
frame.renderWidget(approvalSurfaceWidget(state), vertRects[rectIdx++])
frame.renderWidget(inputBarWidget(state, DisplayState.APPROVAL), vertRects[rectIdx])
}
@@ -23,8 +23,11 @@ private val yellowStyle = Style.create().yellow()
fun diffViewerWidget(state: TuiState): Paragraph {
val selectedSession = state.sessions.sessions.firstOrNull { it.id == state.sessions.selectedId }
// Only show the diff for the most recently completed tool. If the last tool has no diff
// (e.g. a shell command), the viewer is hidden — stale diffs from earlier tools are noise.
val toolWithDiff = selectedSession?.tools
?.lastOrNull { it.status == ToolDisplayStatus.COMPLETED && it.diff != null }
?.lastOrNull { it.status == ToolDisplayStatus.COMPLETED }
?.takeIf { it.diff != null }
val diffText = toolWithDiff?.diff ?: return Paragraph.builder().build()