List a session's background tasks above its subagents
The count beside the status said how much work was going and never what,
so "3 bg tasks" was a number with no way to find out what it was about.
Drivers now report the tasks themselves rather than a size:
`Driver::background_tasks` returns `Vec<BackgroundTask>` -- id, the
provider's own description, and a kind -- served by
`GET /sessions/{id}/background`. It is runtime state, never persisted,
and `null` is "nobody has said", which is what a session with no process
answers and what the panel says in words rather than drawing as an empty
list. `description` is optional because Codex names a background terminal
by a process id, and a number drawn as a name is worse than admitting
there is none.
Claude's `background_tasks_changed` entries turn out to be objects
carrying `task_id`, `task_type` and `description`, so each is read rather
than counted -- and an `ambient` one is now dropped from the list and the
count alike, on the CLI's own instruction: a live-update watcher is not
activity, and counting one left a session reading `waiting` with nothing
to wait for.
The phone draws them in the right-hand panel above the subagents,
collapsed to "2 bg tasks running" and pushing the subagents down when
opened. Both lists are items of one lazy column, so neither can run off
the panel, and the section is refetched whenever the live count moves --
a card for work that has finished is exactly the stale measurement the
count exists not to be.
Verified against the real Claude CLI (2.1.261): a backgrounded `sleep 120`
came back as `{"id":"br16327wr","description":"Sleep for 120 seconds",
"kind":"command"}`, and on the emulator against the echo rig the section
appeared, expanded, and dropped a card as its task finished.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c8bfc958ad
commit
942edd6b31
17 files changed
+620
-115
No files matched your search
@@ -39,16 +39,26 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/**
|
||||
* A session's subagents, listed in the panel [SidePanels] slides over it from the right.
|
||||
* What a session has running beside the turn you are reading: its background tasks, then its
|
||||
* subagents, in the panel [SidePanels] slides over it from the right.
|
||||
*
|
||||
* [active] is whether the panel is being looked at: the list is fetched then rather than on
|
||||
* [active] is whether the panel is being looked at: the lists are fetched then rather than on
|
||||
* composition, since the panel is composed for every session whether or not anybody opens it.
|
||||
*
|
||||
* [backgroundTasks] is the live count from the session's own event stream, and is what the
|
||||
* background list is refetched against: a card for work that has since finished is a stale
|
||||
* measurement drawn as a current one, which is the one thing a list of what is running now must not
|
||||
* do.
|
||||
*
|
||||
* Both lists are items of one lazy column rather than two stacked scrollers, so expanding the
|
||||
* background section pushes the subagents down without either being able to run off the panel.
|
||||
*/
|
||||
@Composable
|
||||
fun SubagentPanel(
|
||||
settings: ServerSettings,
|
||||
summary: SessionSummary,
|
||||
active: Boolean,
|
||||
backgroundTasks: Int,
|
||||
onClose: () -> Unit,
|
||||
onOpenSubagent: (SubagentSummary) -> Unit,
|
||||
) {
|
||||
@@ -62,6 +72,11 @@ fun SubagentPanel(
|
||||
var deleteError by remember(summary.id) { mutableStateOf<String?>(null) }
|
||||
var confirming by remember(summary.id) { mutableStateOf<List<SubagentSummary>?>(null) }
|
||||
var refreshToken by remember(summary.id) { mutableIntStateOf(0) }
|
||||
var background by
|
||||
remember(summary.id) {
|
||||
mutableStateOf<LoadState<List<BackgroundTaskSummary>?>>(LoadState.Loading)
|
||||
}
|
||||
var backgroundExpanded by remember(summary.id) { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(active, refreshToken) {
|
||||
if (!active) return@LaunchedEffect
|
||||
@@ -76,49 +91,71 @@ fun SubagentPanel(
|
||||
}
|
||||
}
|
||||
|
||||
// No reset to Loading on a refetch: the spinner belongs to the first fetch, and one flashed
|
||||
// over the list at every start and end would blink precisely when something happened.
|
||||
LaunchedEffect(active, backgroundTasks, refreshToken) {
|
||||
if (!active || backgroundTasks == 0) return@LaunchedEffect
|
||||
background =
|
||||
try {
|
||||
LoadState.Loaded(
|
||||
withContext(Dispatchers.IO) { fetchBackgroundTasks(settings, summary.id) }
|
||||
)
|
||||
} catch (e: ApiException) {
|
||||
LoadState.failed(e)
|
||||
}
|
||||
}
|
||||
|
||||
BackHandler(enabled = selected.isNotEmpty()) { selected = emptySet() }
|
||||
|
||||
val ordered = (rows as? LoadState.Loaded)?.value?.let(::subagentOrder)
|
||||
|
||||
Column(Modifier.fillMaxSize()) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.End,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp),
|
||||
) {
|
||||
Text(
|
||||
"Subagents",
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
MarkButton("Close subagents", onClose) { Chevron(Pointing.Right) }
|
||||
MarkButton("Close panel", onClose) { Chevron(Pointing.Right) }
|
||||
}
|
||||
|
||||
when (val state = rows) {
|
||||
is LoadState.Loading ->
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.padding(16.dp).width(24.dp).height(24.dp)
|
||||
)
|
||||
is LoadState.Error ->
|
||||
Column(Modifier.padding(16.dp)) {
|
||||
Text(
|
||||
state.message,
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
)
|
||||
TextButton(onClick = { refreshToken++ }) { Text("Try again") }
|
||||
}
|
||||
is LoadState.Loaded -> {
|
||||
val ordered = subagentOrder(state.value)
|
||||
if (ordered.isEmpty()) {
|
||||
Text(
|
||||
"No subagents in this session.",
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
modifier = Modifier.padding(16.dp),
|
||||
)
|
||||
} else {
|
||||
LazyColumn(
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = Modifier.weight(1f).padding(horizontal = 16.dp),
|
||||
) {
|
||||
LazyColumn(
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = Modifier.weight(1f).padding(horizontal = 16.dp),
|
||||
) {
|
||||
backgroundTaskSection(
|
||||
count = backgroundTasks,
|
||||
tasks = background,
|
||||
expanded = backgroundExpanded,
|
||||
onToggle = { backgroundExpanded = !backgroundExpanded },
|
||||
onRetry = { refreshToken++ },
|
||||
)
|
||||
item(key = "subagents-heading") { PanelSectionHeading("Subagents") }
|
||||
when (val state = rows) {
|
||||
is LoadState.Loading ->
|
||||
item(key = "subagents-loading") {
|
||||
CircularProgressIndicator(modifier = Modifier.width(24.dp).height(24.dp))
|
||||
}
|
||||
is LoadState.Error ->
|
||||
item(key = "subagents-error") {
|
||||
Column {
|
||||
Text(
|
||||
state.message,
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
)
|
||||
TextButton(onClick = { refreshToken++ }) { Text("Try again") }
|
||||
}
|
||||
}
|
||||
is LoadState.Loaded ->
|
||||
if (ordered.isNullOrEmpty()) {
|
||||
item(key = "subagents-empty") {
|
||||
Text(
|
||||
"No subagents in this session.",
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
uniqueItems(ordered, key = { it.id }) { subagent ->
|
||||
SubagentCard(
|
||||
subagent = subagent,
|
||||
@@ -134,25 +171,25 @@ fun SubagentPanel(
|
||||
)
|
||||
}
|
||||
}
|
||||
if (selected.isNotEmpty()) {
|
||||
val picked = ordered.filter { it.id in selected }
|
||||
SubagentSelectionBar(
|
||||
picked = picked,
|
||||
onDelete = { confirming = picked },
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
deleteError?.let {
|
||||
Text(
|
||||
it,
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (selected.isNotEmpty()) {
|
||||
val picked = ordered.orEmpty().filter { it.id in selected }
|
||||
SubagentSelectionBar(
|
||||
picked = picked,
|
||||
onDelete = { confirming = picked },
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
)
|
||||
}
|
||||
deleteError?.let {
|
||||
Text(
|
||||
it,
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
confirming?.let { picked ->
|
||||
|
||||
Reference in new issue
Block a user