Take subagent reports out of the main transcript, and separate turns with a rule
A row per finished background task is a screenful of dividers about work the reader was not asking after, and one of them turned out to be a whole shell command drawn as centred prose, because its words came from somewhere with no reason to keep them short. `Event::TaskNote` is gone entirely, along with the row that drew it. A subagent's closing report is recorded as that subagent's own transcript's closing text and is read in the subcard, which is where it was already going; what the parent gets a row for is a message a subagent genuinely sends it, which arrives by the peer path and has had one all along. What remains is the actual defect and the smallest thing that fixes it. The fold still refuses to grow a settled reply, so a turn boundary is always a message boundary, and where two replies then abut it puts a `TurnBreak` between them: a hairline, no words, no colour. Made by the fold rather than sent by the server, because it is not something that happened -- it is the boundary between two things that did. `joinPages` puts one in at a page seam, which the fold never gets to see. The task notification is still what closes a task in `Status::Waiting`'s bookkeeping, and the registry lookup that recognises one this translator never saw start is what makes that work for a session adopted across a restart. Verified on the emulator: three replies, three rules, and nothing about the helpers anywhere in the parent. 170 server tests, 85 JVM tests, ktfmt, clippy, rustfmt and Android lint clean. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ef1aad8776
commit
1bbb642973
13 files changed
+171
-407
No files matched your search
@@ -26,18 +26,9 @@ import java.time.format.FormatStyle
|
||||
* two it was is said by the words and the colour.
|
||||
*
|
||||
* The rules take [color] too, so the whole divider reads as one mark of one kind.
|
||||
*
|
||||
* [trailing] is drawn inside the rules, beside the words -- the one divider that opens onto
|
||||
* something needs its chevron there, and giving it its own copy of this layout is how the two would
|
||||
* come to sit at different heights.
|
||||
*/
|
||||
@Composable
|
||||
fun TranscriptDivider(
|
||||
text: String,
|
||||
color: Color,
|
||||
modifier: Modifier = Modifier,
|
||||
trailing: (@Composable () -> Unit)? = null,
|
||||
) {
|
||||
fun TranscriptDivider(text: String, color: Color, modifier: Modifier = Modifier) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
@@ -45,11 +36,32 @@ fun TranscriptDivider(
|
||||
) {
|
||||
HorizontalDivider(Modifier.weight(1f), color = color)
|
||||
Text(text, style = MaterialTheme.typography.bodySmall, color = color)
|
||||
trailing?.invoke()
|
||||
HorizontalDivider(Modifier.weight(1f), color = color)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The rule between two replies that met with nothing said in between -- see
|
||||
* [TranscriptItem.TurnBreak].
|
||||
*
|
||||
* No words and no colour. Every other divider here reports something that happened and is worth
|
||||
* finding by scanning; this one only says "these are two", and it appears once per turn that
|
||||
* started without anybody typing. Saying more was a screenful of announcements about background
|
||||
* work the reader was not asking after -- one of them a whole shell command, drawn as centred prose
|
||||
* because the words came from somewhere that had no reason to keep them short.
|
||||
*
|
||||
* The outline colour is the scheme's one for structure rather than for meaning, which is what this
|
||||
* is. Inset from both edges so it reads as a separator between two rows rather than as the top edge
|
||||
* of the one under it.
|
||||
*/
|
||||
@Composable
|
||||
fun TurnBreakRow(modifier: Modifier = Modifier) {
|
||||
HorizontalDivider(
|
||||
modifier.fillMaxWidth().padding(horizontal = 48.dp, vertical = 6.dp),
|
||||
color = MaterialTheme.colorScheme.outlineVariant,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The mark a clear leaves.
|
||||
*
|
||||
|
||||
@@ -108,28 +108,6 @@ sealed class SessionEvent {
|
||||
val turnStart: Long? = null,
|
||||
) : SessionEvent()
|
||||
|
||||
/**
|
||||
* A task the session started in the background reporting back: a subagent that has finished, or
|
||||
* a backgrounded command.
|
||||
*
|
||||
* It is a message the session *received*, and the turn it wakes up and runs follows it. Without
|
||||
* a row for it, that turn's reply met the previous one with nothing in between and the two were
|
||||
* folded into a single message -- one answer running straight into the next mid-sentence.
|
||||
*/
|
||||
data class TaskNote(
|
||||
/** The tool call it belongs to; a subagent is named by that id. */
|
||||
val about: String,
|
||||
/**
|
||||
* What the reader knows the task as -- a subagent's title. Null for a backgrounded command,
|
||||
* which its own summary names; the row says so rather than inventing a title.
|
||||
*/
|
||||
val title: String?,
|
||||
/** How it ended, in the CLI's word: "completed", "failed", "cancelled". */
|
||||
val status: String,
|
||||
/** What it said on the way out, where it said anything. */
|
||||
val summary: String?,
|
||||
) : SessionEvent()
|
||||
|
||||
/**
|
||||
* A command the session was asked to run on itself and cannot run yet. Resolved by
|
||||
* [CommandSent] with the same id; a command that ran straight away has only that one.
|
||||
@@ -274,13 +252,6 @@ fun parseSeqEvent(json: String): SeqEvent {
|
||||
body.getString("text"),
|
||||
if (body.has("turnStart")) body.getLong("turnStart") else null,
|
||||
)
|
||||
"taskNote" ->
|
||||
SessionEvent.TaskNote(
|
||||
about = body.getString("about"),
|
||||
title = body.optString("title").ifEmpty { null },
|
||||
status = body.getString("status"),
|
||||
summary = body.optString("summary").ifEmpty { null },
|
||||
)
|
||||
"commandQueued" ->
|
||||
SessionEvent.CommandQueued(body.getString("id"), body.getString("text"))
|
||||
"commandSent" -> SessionEvent.CommandSent(body.getString("id"), body.getString("text"))
|
||||
|
||||
@@ -288,10 +288,6 @@ fun SessionScreen(
|
||||
// Which messages from other agents are open, by the seq that identifies their row. Closed by
|
||||
// default, which is the rule for anything new in this transcript.
|
||||
var expandedNotes by remember { mutableStateOf(setOf<Long>()) }
|
||||
// Which task reports are open, by the seq that identifies their row. Closed by default, which
|
||||
// is the rule for anything new in this transcript -- and doubly so here, since what one opens
|
||||
// onto is already in the subagent's own transcript.
|
||||
var expandedTaskNotes by remember { mutableStateOf(setOf<Long>()) }
|
||||
// Which memory notes are open, by the note's own text. Held here rather than in the card so a
|
||||
// note opened and scrolled past is still open on the way back.
|
||||
var openMemories by remember { mutableStateOf(setOf<String>()) }
|
||||
@@ -1607,25 +1603,7 @@ fun SessionScreen(
|
||||
is TranscriptItem.CompactedNote ->
|
||||
CompactedRow(item)
|
||||
is TranscriptItem.LimitNote -> LimitRow(item)
|
||||
is TranscriptItem.TaskNote ->
|
||||
TaskNoteRow(
|
||||
item,
|
||||
open = item.seq in expandedTaskNotes,
|
||||
// Anchored, so the edge the reader pressed
|
||||
// stays where it was.
|
||||
onToggle = {
|
||||
toggleAnchored(row) {
|
||||
expandedTaskNotes =
|
||||
if (
|
||||
item.seq in
|
||||
expandedTaskNotes
|
||||
)
|
||||
expandedTaskNotes - item.seq
|
||||
else
|
||||
expandedTaskNotes + item.seq
|
||||
}
|
||||
},
|
||||
)
|
||||
is TranscriptItem.TurnBreak -> TurnBreakRow()
|
||||
// Never reached: a peer message is flattened into
|
||||
// its own units. Here because a `when` over the
|
||||
// item kinds has to stay exhaustive.
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
package com.example.aiapp
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
/**
|
||||
* The mark a background task reporting back leaves: a subagent that finished, or a backgrounded
|
||||
* command.
|
||||
*
|
||||
* A divider, drawn like a clear or a compaction, because what it marks is a *boundary*. The turn
|
||||
* below it is the session answering something that arrived, and without a row there the reply that
|
||||
* ended the previous turn and the reply that answers this one met with nothing between them -- the
|
||||
* fold grew the older message and drew two answers as one paragraph, running together mid-sentence.
|
||||
*
|
||||
* **Closed, and the subagent's words are not what it says.** A subagent's closing report is
|
||||
* recorded as its own transcript's closing text, which is where somebody who wants it looks;
|
||||
* putting it in the parent by default is the same paragraph in two places for a reader who did not
|
||||
* ask for it. Opened, this shows it anyway, because having to leave the conversation to read one
|
||||
* line is its own cost -- and because a backgrounded *command* has no transcript of its own, so
|
||||
* here is the only place its report exists at all.
|
||||
*/
|
||||
@Composable
|
||||
fun TaskNoteRow(
|
||||
item: TranscriptItem.TaskNote,
|
||||
open: Boolean,
|
||||
onToggle: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
// Blue is the session's own background work -- the same thing `waiting` means in the status
|
||||
// row, so "this is the session getting on with something it started" is learned once. Red only
|
||||
// where something actually went wrong; a cancelled task is a choice somebody made.
|
||||
val colour = if (item.status == "failed") failedColor else waitingColor
|
||||
val line = taskNoteSummary(item.title, item.status, item.summary)
|
||||
// Nothing behind the line: a task that ended without a word, or one whose report *is* the line
|
||||
// already. A control that opens onto nothing, or onto a copy of what is above it, teaches the
|
||||
// reader that the control means nothing.
|
||||
val expandable = item.summary != null && item.summary != line
|
||||
Column(
|
||||
modifier
|
||||
.fillMaxWidth()
|
||||
.then(if (expandable) Modifier.clickable(onClick = onToggle) else Modifier)
|
||||
) {
|
||||
TranscriptDivider(
|
||||
line,
|
||||
colour,
|
||||
trailing =
|
||||
if (!expandable) null
|
||||
else {
|
||||
{
|
||||
Chevron(
|
||||
if (open) Pointing.Up else Pointing.Down,
|
||||
colour = colour,
|
||||
// The row is the control and the chevron is all of its marking, so the
|
||||
// name belongs here: it is the only thing a screen reader has to read.
|
||||
modifier =
|
||||
Modifier.semantics {
|
||||
contentDescription =
|
||||
if (open) "Hide the report" else "Show the report"
|
||||
},
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
if (open && expandable) {
|
||||
// Not the divider's colour: this is what the task said rather than a mark we drew, and
|
||||
// colouring a quotation as if it were part of the rule around it makes the rule look
|
||||
// like it is carrying some of the meaning.
|
||||
Text(
|
||||
item.summary.orEmpty(),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(bottom = 8.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* What the divider says: what reported, and how it went.
|
||||
*
|
||||
* Its own function so the wording is testable without a screen, and because the case that decides
|
||||
* whether this is any good is the one nobody builds a screen for -- a task that failed or was
|
||||
* killed. "Reported back" is the right phrase for exactly one of the endings; using it for all of
|
||||
* them would announce a task that died as one that had something to say.
|
||||
*
|
||||
* A status word this build has never seen is said as itself rather than mapped onto the nearest
|
||||
* one, since the nearest one would read as a fact somebody established.
|
||||
*/
|
||||
fun taskNoteSummary(title: String?, status: String, summary: String?): String {
|
||||
// A backgrounded command has no title of its own and its summary is already a whole sentence --
|
||||
// `Background command "..." completed (exit code 0)`. Naming it from that beats "a background
|
||||
// task", which says nothing, and there is nothing left behind the line to open.
|
||||
if (title == null && summary != null && status == "completed") return summary
|
||||
val who = title ?: "A background task"
|
||||
return when (status) {
|
||||
"completed" -> "$who reported back"
|
||||
"failed" -> "$who failed"
|
||||
"cancelled" -> "$who was cancelled"
|
||||
else -> "$who: $status"
|
||||
}
|
||||
}
|
||||
@@ -144,24 +144,27 @@ sealed class TranscriptItem {
|
||||
}
|
||||
|
||||
/**
|
||||
* A task the session started in the background reporting back: a subagent that finished, or a
|
||||
* backgrounded command.
|
||||
* Where one turn ended and the next began with nothing said in between.
|
||||
*
|
||||
* Its own row rather than an update to the Task call's, which is wherever the call was made --
|
||||
* above everything the session has said since, where a reader at the bottom would never see it
|
||||
* change. Here it is where it arrived, in front of the turn it caused.
|
||||
* A rule and no words. Two replies meet like this whenever a turn starts without anybody typing
|
||||
* -- a subagent reporting back, a session the CLI picked up by itself -- and drawn with only
|
||||
* the ordinary gap between them they read as one answer with a paragraph break through the
|
||||
* middle of it. What the reader needs is to see that these are two; what started the turn is
|
||||
* somebody else's transcript's business, and a row per background task is a screenful of
|
||||
* dividers about work nobody was asking after.
|
||||
*
|
||||
* Made by the fold rather than sent by the server, because it is not something that happened:
|
||||
* it is the boundary between two things that did. See [foldEvent].
|
||||
*/
|
||||
data class TaskNote(
|
||||
override val seq: Long,
|
||||
/** The tool call it belongs to; a subagent is named by that id. */
|
||||
val about: String,
|
||||
data class TurnBreak(override val seq: Long) : TranscriptItem() {
|
||||
/**
|
||||
* The subagent's title, or null for a backgrounded command -- see [SessionEvent.TaskNote].
|
||||
* Its own key, because it shares a [seq] with the reply it sits above -- that reply's first
|
||||
* delta is the event this was made at, and a keyed list refuses two items with one key by
|
||||
* taking the app down.
|
||||
*/
|
||||
val title: String?,
|
||||
val status: String,
|
||||
val summary: String?,
|
||||
) : TranscriptItem()
|
||||
override val key: Any
|
||||
get() = "break$seq"
|
||||
}
|
||||
|
||||
/**
|
||||
* A command the session ran on itself -- `/compact`, `/rename`. Kept in the transcript rather
|
||||
@@ -302,7 +305,9 @@ private fun healSplitMessage(
|
||||
// A settled reply is a whole turn, so the two are two answers that happen to meet at the
|
||||
// boundary rather than one cut in half -- the same distinction the fold makes, and joining them
|
||||
// here would put back exactly the run-together paragraph it stops.
|
||||
if (head.settled) return earlier to later
|
||||
// The rule between them is put in here too, since the fold that would have made it never saw
|
||||
// these two side by side.
|
||||
if (head.settled) return earlier to (listOf(TranscriptItem.TurnBreak(tail.seq)) + later)
|
||||
return earlier.dropLast(1) to (listOf(tail.copy(text = head.text + tail.text)) + later.drop(1))
|
||||
}
|
||||
|
||||
@@ -397,7 +402,13 @@ fun foldEvent(items: List<TranscriptItem>, entry: SeqEvent): List<TranscriptItem
|
||||
if (last is TranscriptItem.AssistantMsg && !last.settled) {
|
||||
items.dropLast(1) + last.copy(text = last.text + event.delta)
|
||||
} else {
|
||||
items + TranscriptItem.AssistantMsg(entry.seq, event.delta)
|
||||
// A rule between the two, and only where they actually meet: anything that draws a
|
||||
// row of its own -- a message, a command, a peer note -- is already the boundary.
|
||||
val between =
|
||||
if (last is TranscriptItem.AssistantMsg)
|
||||
listOf(TranscriptItem.TurnBreak(entry.seq))
|
||||
else emptyList()
|
||||
items + between + TranscriptItem.AssistantMsg(entry.seq, event.delta)
|
||||
}
|
||||
}
|
||||
is SessionEvent.ToolStart ->
|
||||
@@ -475,15 +486,6 @@ fun foldEvent(items: List<TranscriptItem>, entry: SeqEvent): List<TranscriptItem
|
||||
}
|
||||
}
|
||||
is SessionEvent.PeerMessage -> placePeerNote(items, entry.seq, event)
|
||||
is SessionEvent.TaskNote ->
|
||||
items +
|
||||
TranscriptItem.TaskNote(
|
||||
entry.seq,
|
||||
event.about,
|
||||
event.title,
|
||||
event.status,
|
||||
event.summary,
|
||||
)
|
||||
is SessionEvent.CommandSent -> items + TranscriptItem.CommandRow(entry.seq, event.text)
|
||||
// Screen-level state, not transcript rows -- see SessionScreen.
|
||||
is SessionEvent.CommandQueued -> items
|
||||
|
||||
@@ -47,18 +47,40 @@ class TranscriptItemsTest {
|
||||
assertEquals(listOf("Still running its tests."), texts(items))
|
||||
}
|
||||
|
||||
/**
|
||||
* The rule that replaced the wall of reports. A turn that starts with nothing recorded in front
|
||||
* of it -- a subagent finishing, the CLI picking a conversation back up -- leaves two replies
|
||||
* abutting, and only the break says they are two.
|
||||
*/
|
||||
@Test
|
||||
fun a_task_reporting_back_is_a_row_between_the_two_turns() {
|
||||
fun two_replies_that_meet_are_separated_by_a_rule_and_nothing_else() {
|
||||
val items =
|
||||
fold(
|
||||
SessionEvent.AssistantText("Launched it."),
|
||||
SessionEvent.Status("waiting"),
|
||||
SessionEvent.TaskNote("toolu_1", "the Dev Updater agent", "completed", "pushed"),
|
||||
SessionEvent.AssistantText("Noted."),
|
||||
)
|
||||
assertEquals(3, items.size, "$items")
|
||||
assertTrue(items[1] is TranscriptItem.TaskNote, "$items")
|
||||
assertTrue(items[1] is TranscriptItem.TurnBreak, "$items")
|
||||
assertEquals(listOf("Launched it.", "Noted."), texts(items))
|
||||
// Distinct keys: the break shares the reply's seq, and two items with one key take the
|
||||
// app down.
|
||||
assertEquals(3, items.map { it.key }.toSet().size, "$items")
|
||||
}
|
||||
|
||||
/**
|
||||
* A reply after anything that draws a row of its own needs no rule: that row is the boundary.
|
||||
*/
|
||||
@Test
|
||||
fun a_reply_after_a_row_of_its_own_gets_no_rule() {
|
||||
val items =
|
||||
fold(
|
||||
SessionEvent.AssistantText("Launched it."),
|
||||
SessionEvent.Status("idle"),
|
||||
SessionEvent.UserMessage("carry on", null, emptyList()),
|
||||
SessionEvent.AssistantText("Noted."),
|
||||
)
|
||||
assertTrue(items.none { it is TranscriptItem.TurnBreak }, "$items")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,23 +103,7 @@ class TranscriptItemsTest {
|
||||
listOf(TranscriptItem.AssistantMsg(2, "The next.", settled = true)),
|
||||
)
|
||||
assertEquals(listOf("One turn.", "The next."), texts(whole))
|
||||
}
|
||||
|
||||
/** The endings nobody builds a screen for -- see [taskNoteSummary]. */
|
||||
@Test
|
||||
fun a_task_note_says_which_ending_it_was() {
|
||||
val said = "it said hello"
|
||||
// A subagent is named, and its own words stay in its own transcript rather than being
|
||||
// repeated here.
|
||||
assertEquals("helper 1 reported back", taskNoteSummary("helper 1", "completed", said))
|
||||
assertEquals("helper 1 failed", taskNoteSummary("helper 1", "failed", null))
|
||||
assertEquals("helper 1 was cancelled", taskNoteSummary("helper 1", "cancelled", said))
|
||||
// A word this build has never seen is said as itself, not mapped onto the nearest one.
|
||||
assertEquals("helper 1: evicted", taskNoteSummary("helper 1", "evicted", said))
|
||||
// A backgrounded command has no title and no transcript of its own, so its summary is the
|
||||
// only record of it there is -- and it is already a sentence.
|
||||
val command = """Background command "build the kernel" completed (exit code 0)"""
|
||||
assertEquals(command, taskNoteSummary(null, "completed", command))
|
||||
assertEquals("A background task failed", taskNoteSummary(null, "failed", null))
|
||||
// And the rule between them, which the fold that would have made it never got to see.
|
||||
assertTrue(whole.any { it is TranscriptItem.TurnBreak }, "$whole")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user