@@ -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
@@ -42,8 +43,10 @@ import androidx.compose.foundation.text.KeyboardOptions
42import androidx.compose.material.icons.Icons
43import androidx.compose.material.icons.Icons
43import androidx.compose.material.icons.automirrored.filled.ArrowBack
44import androidx.compose.material.icons.automirrored.filled.ArrowBack
44import androidx.compose.material.icons.automirrored.filled.Send
45import androidx.compose.material.icons.automirrored.filled.Send
46+import androidx.compose.material.icons.filled.ChatBubbleOutline
45import androidx.compose.material.icons.filled.Close
47import androidx.compose.material.icons.filled.Close
46import androidx.compose.material.icons.filled.KeyboardArrowDown
48import androidx.compose.material.icons.filled.KeyboardArrowDown
49+import androidx.compose.material.icons.filled.KeyboardArrowUp
47import androidx.compose.material.icons.filled.Stop
50import androidx.compose.material.icons.filled.Stop
48import androidx.compose.material3.CircularProgressIndicator
51import androidx.compose.material3.CircularProgressIndicator
49import androidx.compose.material3.ExperimentalMaterial3Api
52import androidx.compose.material3.ExperimentalMaterial3Api
@@ -58,6 +61,7 @@ import androidx.compose.material3.OutlinedTextField
58import androidx.compose.material3.Scaffold
61import androidx.compose.material3.Scaffold
59import androidx.compose.material3.Surface
62import androidx.compose.material3.Surface
60import androidx.compose.material3.Text
63import androidx.compose.material3.Text
64+import androidx.compose.material3.TextButton
61import androidx.compose.material3.TopAppBar
65import androidx.compose.material3.TopAppBar
62import androidx.compose.runtime.Composable
66import androidx.compose.runtime.Composable
63import androidx.compose.runtime.LaunchedEffect
67import androidx.compose.runtime.LaunchedEffect
@@ -71,6 +75,7 @@ import androidx.compose.ui.Alignment
71import androidx.compose.ui.Modifier
75import androidx.compose.ui.Modifier
72import androidx.compose.ui.draw.clip
76import androidx.compose.ui.draw.clip
73import androidx.compose.ui.hapticfeedback.HapticFeedbackType
77import androidx.compose.ui.hapticfeedback.HapticFeedbackType
78+import androidx.compose.ui.platform.LocalClipboardManager
74import androidx.compose.ui.platform.LocalContext
79import androidx.compose.ui.platform.LocalContext
75import androidx.compose.ui.platform.LocalDensity
80import androidx.compose.ui.platform.LocalDensity
76import androidx.compose.ui.platform.LocalHapticFeedback
81import androidx.compose.ui.platform.LocalHapticFeedback
@@ -108,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 }
111 // 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
112 // 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.
113 var lastSeenCount by remember { mutableStateOf(0) }
124 var lastSeenCount by remember { mutableStateOf(0) }
@@ -194,12 +205,24 @@ fun ChatScreen(state: UiState, dispatch: (Event) -> Unit) {
195 Box(Modifier.fillMaxWidth().weight(1f)) {
206 Box(Modifier.fillMaxWidth().weight(1f)) {
196 if (state.messages.isEmpty() && !state.loading) {
207 if (state.messages.isEmpty() && !state.loading) {
198− text = "Send a message to start the conversation.",
199− style = MaterialTheme.typography.bodyMedium,
200− color = MaterialTheme.colorScheme.onSurfaceVariant,
201 modifier = Modifier.align(Alignment.Center).padding(32.dp),
209 modifier = Modifier.align(Alignment.Center).padding(32.dp),
210+ horizontalAlignment = Alignment.CenterHorizontally,
213+ Icons.Filled.ChatBubbleOutline,
214+ contentDescription = null,
215+ modifier = Modifier.size(48.dp),
216+ tint = MaterialTheme.colorScheme.primary.copy(alpha = 0.5f),
218+ Spacer(Modifier.size(16.dp))
220+ text = "Send a message to start the conversation.",
221+ style = MaterialTheme.typography.bodyMedium,
222+ color = MaterialTheme.colorScheme.onSurfaceVariant,
223+ textAlign = TextAlign.Center,
204 LazyColumn(
227 LazyColumn(
205 state = listState,
228 state = listState,
@@ -246,6 +269,14 @@ fun ChatScreen(state: UiState, dispatch: (Event) -> Unit) {
273+ visible = showScrollTop,
275+ coroutineScope.launch {
276+ listState.animateScrollToItem(0)
@@ -285,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",
288private fun copyToClipboard(context: Context, text: String) {
343private fun copyToClipboard(context: Context, text: String) {
289 val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
344 val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
290 clipboard.setPrimaryClip(ClipData.newPlainText("session", text))
345 clipboard.setPrimaryClip(ClipData.newPlainText("session", text))
@@ -442,19 +497,41 @@ private fun ChatInputBar(
442 onStop: () -> Unit,
497 onStop: () -> Unit,
444 val haptic = LocalHapticFeedback.current
499 val haptic = LocalHapticFeedback.current
500+ val clipboardManager = LocalClipboardManager.current
445 Surface(tonalElevation = 3.dp) {
501 Surface(tonalElevation = 3.dp) {
447 modifier = Modifier.fillMaxWidth().imePadding().padding(horizontal = 12.dp, vertical = 8.dp),
503 modifier = Modifier.fillMaxWidth().imePadding().padding(horizontal = 12.dp, vertical = 8.dp),
506+ modifier = Modifier.fillMaxWidth(),
448 verticalAlignment = Alignment.Bottom,
507 verticalAlignment = Alignment.Bottom,
449 horizontalArrangement = Arrangement.spacedBy(8.dp),
508 horizontalArrangement = Arrangement.spacedBy(8.dp),
451 OutlinedTextField(
510 OutlinedTextField(
452 value = draft,
511 value = draft,
453 onValueChange = onDraftChange,
512 onValueChange = onDraftChange,
454− modifier = Modifier.weight(1f),
513+ modifier = Modifier.weight(1f).heightIn(min = 48.dp),
455 enabled = !loading,
514 enabled = !loading,
456 placeholder = { Text("Message opencode…") },
515 placeholder = { Text("Message opencode…") },
457 maxLines = 5,
516 maxLines = 5,
517+ // Offer a quick way to wipe the draft once there's something to clear
518+ // and we're not mid-generation (where the field is a poor place to fuss).
519+ trailingIcon = if (draft.isNotEmpty() && !generating) {
522+ onClick = { onDraftChange("") },
523+ modifier = Modifier.size(20.dp),
527+ contentDescription = "Clear draft",
528+ modifier = Modifier.size(16.dp),
458 // Surface a running count once the draft gets long, so the user has a
535 // Surface a running count once the draft gets long, so the user has a
459 // sense of scale before sending a wall of text.
536 // sense of scale before sending a wall of text.
460 supportingText = if (draft.length > 500) {
537 supportingText = if (draft.length > 500) {
@@ -497,5 +574,17 @@ private fun ChatInputBar(
577+ // With nothing typed yet, offer a one-tap way to drop in clipboard contents.
578+ if (draft.isEmpty() && !generating && !loading) {
581+ clipboardManager.getText()?.text?.let { onDraftChange(it) }
583+ contentPadding = PaddingValues(0.dp),