Show only running background tasks in a compact chat bar
The chat background-task bar now lists only tasks that are still running, so an exited task no longer lingers and the bar disappears when the last one ends. The one-line 'running now and recently observed exits' subtitle is replaced by a compact 'Background tasks · N running' header, and the list is capped at three touch-sized rows and scrolls beyond that instead of pushing the composer down the screen. Unit-tested (running-only set and the row cap) and the stale note updated.
This commit is contained in:
@@ -246,10 +246,11 @@ internal fun ChatConversationPane(
|
||||
)
|
||||
}
|
||||
}
|
||||
// The viewer keeps the bounded exit tail only when this client saw it.
|
||||
if (thread.observedShells.isNotEmpty()) {
|
||||
// Only tasks still running are shown; the bar goes away when the last
|
||||
// one ends rather than keeping a list of finished tasks on screen.
|
||||
if (thread.runningShells.isNotEmpty()) {
|
||||
BackgroundProcessBar(
|
||||
shells = thread.observedShells,
|
||||
shells = thread.runningShells,
|
||||
selectedID = thread.selectedShellId,
|
||||
output = thread.shellOutput,
|
||||
onSelect = { vm.selectChatShell(thread.sessionId, it) },
|
||||
|
||||
@@ -11,14 +11,17 @@ import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.selection.SelectionContainer
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Build
|
||||
import androidx.compose.material.icons.filled.KeyboardArrowDown
|
||||
@@ -27,6 +30,7 @@ import androidx.compose.material.icons.filled.PlayArrow
|
||||
import androidx.compose.material.icons.filled.Psychology
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.LocalMinimumInteractiveComponentSize
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.SmallFloatingActionButton
|
||||
import androidx.compose.material3.Surface
|
||||
@@ -50,6 +54,7 @@ import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.collect
|
||||
@@ -386,7 +391,28 @@ private fun RunningToolLine(part: ChatPart, elapsedMillis: Long) {
|
||||
}
|
||||
}
|
||||
|
||||
/** A read-only, expandable task viewer for verified shells this chat observed. */
|
||||
/**
|
||||
* How many running background tasks are visible at once in the chat bar. Beyond
|
||||
* this the list scrolls instead of growing taller, so a burst of tasks cannot
|
||||
* push the composer down the screen.
|
||||
*/
|
||||
internal const val BACKGROUND_TASK_VISIBLE_ROWS = 3
|
||||
|
||||
/**
|
||||
* The tallest the running-task list is drawn: [BACKGROUND_TASK_VISIBLE_ROWS]
|
||||
* entries at the platform minimum touch target plus the gaps between them. Past
|
||||
* that the list scrolls rather than growing.
|
||||
*/
|
||||
internal fun backgroundTaskListMaxHeight(minTouch: Dp): Dp =
|
||||
(minTouch + SPACING_XS) * BACKGROUND_TASK_VISIBLE_ROWS
|
||||
|
||||
/**
|
||||
* The read-only task viewer for the background shells this chat still has
|
||||
* running. A task that has exited is not a background task any more and is never
|
||||
* listed, so the bar exists only while something is actually running and goes
|
||||
* away when the last task ends. The list is capped at
|
||||
* [BACKGROUND_TASK_VISIBLE_ROWS] rows and scrolls beyond that.
|
||||
*/
|
||||
@Composable
|
||||
internal fun BackgroundProcessBar(
|
||||
shells: List<ChatShell>,
|
||||
@@ -396,25 +422,40 @@ internal fun BackgroundProcessBar(
|
||||
onRefresh: (String) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
if (shells.isEmpty()) return
|
||||
val selected = shells.firstOrNull { it.id == selectedID }
|
||||
val minTouch = LocalMinimumInteractiveComponentSize.current
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(SPACING_XS),
|
||||
modifier = modifier.fillMaxWidth().padding(horizontal = CHAT_GUTTER, vertical = 4.dp),
|
||||
) {
|
||||
Text(
|
||||
text = "Background tasks",
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
)
|
||||
Text(
|
||||
text = "Running now and recently observed exits; not complete task history.",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
shells.forEach { shell ->
|
||||
key(shell.id) {
|
||||
BackgroundProcessLine(shell, selectedID == shell.id) {
|
||||
onSelect(if (selectedID == shell.id) null else shell.id)
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(SPACING_XS),
|
||||
) {
|
||||
Text(
|
||||
text = "Background tasks",
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
)
|
||||
Text(
|
||||
text = "${shells.size} running",
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(SPACING_XS),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(max = backgroundTaskListMaxHeight(minTouch))
|
||||
.verticalScroll(rememberScrollState()),
|
||||
) {
|
||||
shells.forEach { shell ->
|
||||
key(shell.id) {
|
||||
BackgroundProcessLine(shell, selectedID == shell.id) {
|
||||
onSelect(if (selectedID == shell.id) null else shell.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -424,7 +465,7 @@ internal fun BackgroundProcessBar(
|
||||
}
|
||||
}
|
||||
|
||||
/** One verified shell task; selection reveals its read-only detail. */
|
||||
/** One running shell task; selection reveals its read-only detail. */
|
||||
@Composable
|
||||
private fun BackgroundProcessLine(shell: ChatShell, selected: Boolean, onSelect: () -> Unit) {
|
||||
Row(
|
||||
@@ -442,7 +483,7 @@ private fun BackgroundProcessLine(shell: ChatShell, selected: Boolean, onSelect:
|
||||
modifier = Modifier.size(ICON_STATUS_DP),
|
||||
)
|
||||
Text(
|
||||
text = if (shell.status == ChatProtocol.SHELL_EXITED) "Exited" else "Running",
|
||||
text = "Running",
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
color = MaterialTheme.colorScheme.tertiary,
|
||||
)
|
||||
@@ -481,14 +522,7 @@ private fun BackgroundProcessDetail(shell: ChatShell, output: ChatShellOutputSta
|
||||
Text(shell.command.ifBlank { "Unavailable" }, style = MaterialTheme.typography.bodyMedium)
|
||||
Text("Task identity", style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
Text(shell.id, style = MaterialTheme.typography.bodySmall, fontFamily = FontFamily.Monospace)
|
||||
Text(
|
||||
text = if (shell.status == ChatProtocol.SHELL_EXITED) {
|
||||
"Status: exited" + (shell.exit?.let { " (exit $it)" } ?: "; exit status unavailable")
|
||||
} else {
|
||||
"Status: running"
|
||||
},
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
)
|
||||
Text("Status: running", style = MaterialTheme.typography.bodySmall)
|
||||
when {
|
||||
output?.loading == true -> CircularProgressIndicator(modifier = Modifier.size(ICON_STATUS_DP))
|
||||
output?.error != null -> Row(horizontalArrangement = Arrangement.spacedBy(SPACING_XS)) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.awan.pipelines.ui.chat
|
||||
|
||||
import androidx.compose.ui.unit.dp
|
||||
import net.awan.pipelines.data.protocol.ChatEventFrame
|
||||
import net.awan.pipelines.data.protocol.ChatPart
|
||||
import net.awan.pipelines.data.protocol.ChatProtocol
|
||||
@@ -8,6 +9,7 @@ import net.awan.pipelines.data.protocol.ChatShell
|
||||
import net.awan.pipelines.data.protocol.ChatShellOutputPage
|
||||
import net.awan.pipelines.data.protocol.ChatStep
|
||||
import net.awan.pipelines.data.protocol.ChatToolState
|
||||
import net.awan.pipelines.ui.theme.SPACING_XS
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
@@ -133,6 +135,18 @@ class ChatInFlightStateTest {
|
||||
assertEquals(listOf("sh_1"), runningBackgroundShells(shells).map { it.id })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theRunningTaskListIsCappedAtAThumbSizedHandful() {
|
||||
// Two or three rows at most: past that the bar scrolls instead of growing
|
||||
// taller, and every visible row keeps the platform minimum touch target.
|
||||
assertTrue(BACKGROUND_TASK_VISIBLE_ROWS in 2..3)
|
||||
val row = 48.dp
|
||||
assertEquals(
|
||||
(row + SPACING_XS) * BACKGROUND_TASK_VISIBLE_ROWS,
|
||||
backgroundTaskListMaxHeight(row),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aCommandIsCollapsedElidedAndNeverBlank() {
|
||||
assertEquals("npm run dev", shellCommandSummary(" npm run \n dev "))
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
# Background tasks viewer limits
|
||||
|
||||
The chat background-task surface now shows only shell identities verified for the
|
||||
The chat background-task bar shows only shell identities verified for the
|
||||
selected chat session by the current-running snapshot and lifecycle events. It
|
||||
keeps a bounded in-memory tail of exits observed by this client so a selected task
|
||||
can settle with an observed exit code; it is not durable task history.
|
||||
lists **only tasks that are still running**: a task that exits leaves the bar, and
|
||||
the bar disappears entirely once the last one ends, so the bar's height tracks the
|
||||
running work rather than accumulating finished tasks. The bar shows at most three
|
||||
rows (`BACKGROUND_TASK_VISIBLE_ROWS`) and scrolls beyond that.
|
||||
|
||||
The store still keeps a bounded in-memory tail of exits observed by this client, so
|
||||
a task's exit code can settle internally; it is not durable task history and is no
|
||||
longer rendered by the bar.
|
||||
|
||||
The upstream shell list is RUNNING-only. Tasks which ended before observation are
|
||||
not enumerated or backfilled. Verified output is read lazily for the selected task
|
||||
through one bounded 64 KiB page; refresh rereads that page from cursor zero rather
|
||||
than accumulating client history. A task that exits after observation remains
|
||||
visible and reports the server's output or an explicit unavailable/empty state.
|
||||
than accumulating client history. Selecting a running task reports the server's
|
||||
output or an explicit unavailable/empty state; because the bar lists only running
|
||||
tasks, a task's output is not readable from the bar after it exits.
|
||||
|
||||
This changes the chat UI. The packaged OpenCode skill references and chat topic
|
||||
documentation should describe the running-only, bounded-observation behavior and
|
||||
|
||||
Reference in New Issue
Block a user