wip: preserve background task viewer
This commit is contained in:
@@ -246,12 +246,9 @@ internal fun ChatConversationPane(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// The background processes still running, shown whether or not a turn
|
// The viewer keeps the bounded exit tail only when this client saw it.
|
||||||
// is: a shell can outlive the turn that started it, so this is a strip
|
if (thread.observedShells.isNotEmpty()) {
|
||||||
// of its own rather than part of the turn indicator, and it clears the
|
BackgroundProcessBar(thread.observedShells)
|
||||||
// moment each shell exits.
|
|
||||||
if (thread.runningShells.isNotEmpty()) {
|
|
||||||
BackgroundProcessBar(thread.runningShells)
|
|
||||||
}
|
}
|
||||||
if (thread.error != null && thread.loaded) {
|
if (thread.error != null && thread.loaded) {
|
||||||
Text(
|
Text(
|
||||||
|
|||||||
@@ -115,12 +115,11 @@ data class ChatThread(
|
|||||||
*/
|
*/
|
||||||
val lastDeltaAt: Long = 0,
|
val lastDeltaAt: Long = 0,
|
||||||
/**
|
/**
|
||||||
* The agent's shell commands still running for this session, keyed by the
|
* Verified shell commands observed for this session, keyed by their server
|
||||||
* shell id the server reported and in the order they started. A background
|
* id and in observation order. Running shells come from the authoritative
|
||||||
* process can outlive the tool call (and the turn) that started it, so this is
|
* snapshot/event stream. A small exited tail is retained only after this
|
||||||
* thread state of its own rather than part of the turn: it keeps showing after
|
* client observed its exit, so a selected task can settle honestly without
|
||||||
* the turn's indicator has gone, and a shell leaves the map the moment its
|
* claiming historical shell discovery.
|
||||||
* exited frame arrives. Kept on the thread so it survives a chat switch.
|
|
||||||
*/
|
*/
|
||||||
val shells: Map<String, ChatShell> = emptyMap(),
|
val shells: Map<String, ChatShell> = emptyMap(),
|
||||||
/** The unsent composer text for this chat. */
|
/** The unsent composer text for this chat. */
|
||||||
@@ -201,11 +200,14 @@ data class ChatThread(
|
|||||||
runningToolElapsedMillis(part, toolStartedAt[part.id] ?: 0L, nowMillis)
|
runningToolElapsedMillis(part, toolStartedAt[part.id] ?: 0L, nowMillis)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The background processes this session is still running, in start order, so
|
* The background processes currently running for this session, in start
|
||||||
* a conversation shows what is running even when no turn is.
|
* order, so a conversation shows what is running even when no turn is.
|
||||||
*/
|
*/
|
||||||
val runningShells: List<ChatShell> get() = runningBackgroundShells(shells)
|
val runningShells: List<ChatShell> get() = runningBackgroundShells(shells)
|
||||||
|
|
||||||
|
/** Bounded observed tasks, including a recently observed exit when present. */
|
||||||
|
val observedShells: List<ChatShell> get() = shells.values.toList()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* What the in-flight turn is doing at [nowMillis] (see [turnPhase]): its
|
* What the in-flight turn is doing at [nowMillis] (see [turnPhase]): its
|
||||||
* running tool calls, and how long ago the last delta arrived. Pure, so the
|
* running tool calls, and how long ago the last delta arrived. Pure, so the
|
||||||
@@ -1049,10 +1051,15 @@ class ChatStore(
|
|||||||
val shell = frame.shell ?: return
|
val shell = frame.shell ?: return
|
||||||
if (shell.id.isBlank()) return
|
if (shell.id.isBlank()) return
|
||||||
update(frame.sessionId) { thread ->
|
update(frame.sessionId) { thread ->
|
||||||
val shells = if (shell.status == ChatProtocol.SHELL_EXITED) {
|
val prior = thread.shells[shell.id]
|
||||||
thread.shells - shell.id
|
val merged = if (shell.status == ChatProtocol.SHELL_EXITED) {
|
||||||
|
shell.copy(command = shell.command.ifBlank { prior?.command.orEmpty() })
|
||||||
} else {
|
} else {
|
||||||
thread.shells + (shell.id to shell)
|
shell.copy(command = shell.command.ifBlank { prior?.command.orEmpty() })
|
||||||
|
}
|
||||||
|
val shells = (thread.shells + (shell.id to merged)).let { observed ->
|
||||||
|
if (observed.size <= OBSERVED_SHELL_LIMIT) observed
|
||||||
|
else observed.entries.toList().takeLast(OBSERVED_SHELL_LIMIT).associate { it.toPair() }
|
||||||
}
|
}
|
||||||
if (shells == thread.shells) thread else thread.copy(shells = shells)
|
if (shells == thread.shells) thread else thread.copy(shells = shells)
|
||||||
}
|
}
|
||||||
@@ -1203,5 +1210,7 @@ class ChatStore(
|
|||||||
companion object {
|
companion object {
|
||||||
const val LOCAL_MESSAGE_PREFIX = "local-"
|
const val LOCAL_MESSAGE_PREFIX = "local-"
|
||||||
const val NOTICE_PREFIX = "notice-"
|
const val NOTICE_PREFIX = "notice-"
|
||||||
|
/** Per-session in-memory observation bound; this is not task history. */
|
||||||
|
const val OBSERVED_SHELL_LIMIT = 16
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -386,35 +386,48 @@ private fun RunningToolLine(part: ChatPart, elapsedMillis: Long) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** A read-only, expandable task viewer for verified shells this chat observed. */
|
||||||
* The always-visible indicator that the agent has a background process running —
|
|
||||||
* a dev server, a watching build, a sleep whose tool call has already returned.
|
|
||||||
* It is deliberately separate from the turn's spinner: a background process can
|
|
||||||
* outlive the turn, so this is shown whenever a shell is running, whether or not
|
|
||||||
* a turn is, and each line names the command the way the running-tool line names
|
|
||||||
* a call. It clears the moment the shell exits, because the exited frame removes
|
|
||||||
* it from the thread's shells. It survives a chat switch like the other live
|
|
||||||
* state, since it is read from the thread rather than held here.
|
|
||||||
*/
|
|
||||||
@Composable
|
@Composable
|
||||||
internal fun BackgroundProcessBar(shells: List<ChatShell>, modifier: Modifier = Modifier) {
|
internal fun BackgroundProcessBar(shells: List<ChatShell>, modifier: Modifier = Modifier) {
|
||||||
|
var selectedID by rememberSaveable { mutableStateOf<String?>(null) }
|
||||||
|
val selected = shells.firstOrNull { it.id == selectedID }
|
||||||
Column(
|
Column(
|
||||||
verticalArrangement = Arrangement.spacedBy(SPACING_XS),
|
verticalArrangement = Arrangement.spacedBy(SPACING_XS),
|
||||||
modifier = modifier.fillMaxWidth().padding(horizontal = CHAT_GUTTER, vertical = 4.dp),
|
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 ->
|
shells.forEach { shell ->
|
||||||
key(shell.id) { BackgroundProcessLine(shell) }
|
key(shell.id) {
|
||||||
|
BackgroundProcessLine(shell, selectedID == shell.id) {
|
||||||
|
selectedID = if (selectedID == shell.id) null else shell.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (selected != null) {
|
||||||
|
BackgroundProcessDetail(selected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** One background process: a distinct glyph, a `Background process` label and its command. */
|
/** One verified shell task; selection reveals its read-only detail. */
|
||||||
@Composable
|
@Composable
|
||||||
private fun BackgroundProcessLine(shell: ChatShell) {
|
private fun BackgroundProcessLine(shell: ChatShell, selected: Boolean, onSelect: () -> Unit) {
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.spacedBy(CHAT_ITEM_GAP),
|
horizontalArrangement = Arrangement.spacedBy(CHAT_ITEM_GAP),
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.minimumInteractiveComponentSize()
|
||||||
|
.clickable(role = Role.Button, onClick = onSelect),
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.PlayArrow,
|
Icons.Default.PlayArrow,
|
||||||
@@ -423,7 +436,7 @@ private fun BackgroundProcessLine(shell: ChatShell) {
|
|||||||
modifier = Modifier.size(ICON_STATUS_DP),
|
modifier = Modifier.size(ICON_STATUS_DP),
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = "Background process",
|
text = if (shell.status == ChatProtocol.SHELL_EXITED) "Exited" else "Running",
|
||||||
style = MaterialTheme.typography.labelMedium,
|
style = MaterialTheme.typography.labelMedium,
|
||||||
color = MaterialTheme.colorScheme.tertiary,
|
color = MaterialTheme.colorScheme.tertiary,
|
||||||
)
|
)
|
||||||
@@ -435,6 +448,44 @@ private fun BackgroundProcessLine(shell: ChatShell) {
|
|||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
)
|
)
|
||||||
|
if (selected) {
|
||||||
|
Text(
|
||||||
|
text = "Details",
|
||||||
|
style = MaterialTheme.typography.labelSmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Detail intentionally exposes only state known from verified lifecycle frames. */
|
||||||
|
@Composable
|
||||||
|
private fun BackgroundProcessDetail(shell: ChatShell) {
|
||||||
|
Surface(
|
||||||
|
color = MaterialTheme.colorScheme.surfaceContainer,
|
||||||
|
shape = RoundedCornerShape(CHAT_GUTTER),
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
) {
|
||||||
|
SelectionContainer {
|
||||||
|
Column(
|
||||||
|
verticalArrangement = Arrangement.spacedBy(SPACING_XS),
|
||||||
|
modifier = Modifier.padding(CHAT_GUTTER),
|
||||||
|
) {
|
||||||
|
Text("Command", style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||||
|
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("Output is unavailable until the server provides verified readback.", style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
# Background tasks viewer limits
|
||||||
|
|
||||||
|
The chat background-task surface now 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.
|
||||||
|
|
||||||
|
The upstream shell list is RUNNING-only. Tasks which ended before observation are
|
||||||
|
not enumerated or backfilled. The current installed chat protocol has no verified
|
||||||
|
shell-output readback, so the detail explicitly reports output as unavailable
|
||||||
|
rather than inventing it.
|
||||||
|
|
||||||
|
This changes the chat UI. The packaged OpenCode skill references and chat topic
|
||||||
|
documentation should describe the running-only, bounded-observation behavior and
|
||||||
|
the lack of durable history when the manual `docs-fold` pipeline next updates
|
||||||
|
shared documentation.
|
||||||
Reference in New Issue
Block a user