@@ -26,6 +26,7 @@ import androidx.compose.foundation.layout.Row
26import androidx.compose.foundation.layout.Spacer
26import androidx.compose.foundation.layout.Spacer
27import androidx.compose.foundation.layout.fillMaxSize
27import androidx.compose.foundation.layout.fillMaxSize
28import androidx.compose.foundation.layout.fillMaxWidth
28import androidx.compose.foundation.layout.fillMaxWidth
29+import androidx.compose.foundation.layout.heightIn
29import androidx.compose.foundation.layout.PaddingValues
30import androidx.compose.foundation.layout.PaddingValues
30import androidx.compose.foundation.layout.WindowInsets
31import androidx.compose.foundation.layout.WindowInsets
31import androidx.compose.foundation.layout.ime
32import androidx.compose.foundation.layout.ime
@@ -45,6 +46,7 @@ import androidx.compose.material.icons.automirrored.filled.Send
45import androidx.compose.material.icons.filled.ChatBubbleOutline
46import androidx.compose.material.icons.filled.ChatBubbleOutline
46import androidx.compose.material.icons.filled.Close
47import androidx.compose.material.icons.filled.Close
47import androidx.compose.material.icons.filled.KeyboardArrowDown
48import androidx.compose.material.icons.filled.KeyboardArrowDown
49+import androidx.compose.material.icons.filled.KeyboardArrowUp
48import androidx.compose.material.icons.filled.Stop
50import androidx.compose.material.icons.filled.Stop
49import androidx.compose.material3.CircularProgressIndicator
51import androidx.compose.material3.CircularProgressIndicator
50import androidx.compose.material3.ExperimentalMaterial3Api
52import androidx.compose.material3.ExperimentalMaterial3Api
@@ -111,6 +113,12 @@ fun ChatScreen(state: UiState, dispatch: (Event) -> Unit) {
116+ // Offer a jump-to-top shortcut once the conversation is long and the user has
117+ // scrolled a few messages down — saves flick-scrolling back through history.
118+ val showScrollTop by remember {
119+ derivedStateOf { state.messages.size > 10 && listState.firstVisibleItemIndex > 3 }
114 // Track how many messages the user has "seen" (i.e. was at the bottom for). While
122 // Track how many messages the user has "seen" (i.e. was at the bottom for). While
115 // they're scrolled up, any messages beyond that count are unseen — flag the FAB.
123 // they're scrolled up, any messages beyond that count are unseen — flag the FAB.
116 var lastSeenCount by remember { mutableStateOf(0) }
124 var lastSeenCount by remember { mutableStateOf(0) }
@@ -261,6 +269,14 @@ fun ChatScreen(state: UiState, dispatch: (Event) -> Unit) {
273+ visible = showScrollTop,
275+ coroutineScope.launch {
276+ listState.animateScrollToItem(0)
@@ -300,6 +316,30 @@ private fun BoxScope.ScrollToBottomButton(visible: Boolean, showBadge: Boolean,
319+// Mirror of ScrollToBottomButton, pinned to the top-start corner. Same BoxScope
320+// extension trick so the top-level AnimatedVisibility overload resolves cleanly.
322+private fun BoxScope.ScrollToTopButton(visible: Boolean, onClick: () -> Unit) {
325+ modifier = Modifier.align(Alignment.TopStart),
326+ enter = scaleIn() + fadeIn(),
327+ exit = scaleOut() + fadeOut(),
329+ Box(Modifier.padding(16.dp)) {
330+ FloatingActionButton(
332+ modifier = Modifier.size(44.dp),
335+ Icons.Filled.KeyboardArrowUp,
336+ contentDescription = "Scroll to top",
303private fun copyToClipboard(context: Context, text: String) {
343private fun copyToClipboard(context: Context, text: String) {
304 val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
344 val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
305 clipboard.setPrimaryClip(ClipData.newPlainText("session", text))
345 clipboard.setPrimaryClip(ClipData.newPlainText("session", text))
@@ -470,7 +510,7 @@ private fun ChatInputBar(
470 OutlinedTextField(
510 OutlinedTextField(
471 value = draft,
511 value = draft,
472 onValueChange = onDraftChange,
512 onValueChange = onDraftChange,
473− modifier = Modifier.weight(1f),
513+ modifier = Modifier.weight(1f).heightIn(min = 48.dp),
474 enabled = !loading,
514 enabled = !loading,
475 placeholder = { Text("Message opencode…") },
515 placeholder = { Text("Message opencode…") },
476 maxLines = 5,
516 maxLines = 5,