Name a run of tool calls once, instead of after whichever call is first
A group of adjacent tool calls was identified by its first call, and the list is keyed by that identity. But a run can gain members at *either* end -- a new call arriving beside it, or a page of history arriving in front of it -- so its first member is not a name, it is a description that changes. Every time it changed, the row was a different row as far as the list was concerned: the anchor went with it, and the transcript stepped under whoever was reading. Each call now carries the run it belongs to, decided once when it is folded in and never recomputed, and the row keys on that. A lone call that gains a neighbour becomes a group *without* changing identity, which the old key got wrong in the other direction too -- one row was replaced by another rather than updated. `joinPages` hands the arriving older calls the name of the run they are joining, rather than renaming that run after them. The obvious way round is the wrong one: the newer half is the part already on screen, so naming the joined run after the older half renames the row the reader is looking at, which is the whole failure this is meant to remove. Checked against the same twelve-`/tools 8` rig, whose page boundary falls inside the second group: every group still reads eight, so the grouping is unchanged -- what changed is that none of their identities move. Toward the standing rule for this screen, which is that it may only move when the reader is at the newest end and something new arrives.
This commit is contained in:
1 parent
2264723ee3
commit
50670863f4
2 files changed
+73
-15
No files matched your search
@@ -32,26 +32,34 @@ import androidx.compose.ui.unit.dp
|
||||
*/
|
||||
sealed class TranscriptRow {
|
||||
/**
|
||||
* This row's identity in the list, taken from the first transcript event behind it.
|
||||
* This row's identity in the list, which must survive everything that can happen to the row.
|
||||
*
|
||||
* See [TranscriptItem.seq]: the list is keyed by this so that inserting a new message at one
|
||||
* end, or a page of history at the other, moves the rows and not the reader.
|
||||
* The list is keyed by this so that inserting a new message at one end, or a page of history at
|
||||
* the other, moves the rows and not the reader. That makes it the load-bearing value on this
|
||||
* screen: when a key changes, the list loses its anchor and the transcript steps under whoever
|
||||
* is reading it.
|
||||
*
|
||||
* A tool row therefore keys on [TranscriptItem.ToolRun.runId] rather than on a sequence number,
|
||||
* and it is the *same* value whether the run is drawn as one card or as a group. A lone call
|
||||
* that gains a neighbour becomes a group without changing identity, which is the case a
|
||||
* seq-based key got wrong: the row the reader was looking at was replaced rather than updated.
|
||||
* Everything else keys on the seq of the event behind it, which never moves.
|
||||
*/
|
||||
abstract val seq: Long
|
||||
abstract val key: Any
|
||||
|
||||
data class Single(val item: TranscriptItem) : TranscriptRow() {
|
||||
override val seq: Long
|
||||
get() = item.seq
|
||||
override val key: Any
|
||||
get() = (item as? TranscriptItem.ToolRun)?.runId ?: item.seq
|
||||
}
|
||||
|
||||
/** Two or more calls with nothing between them; drawn as one collapsed card. */
|
||||
data class Tools(val calls: List<TranscriptItem.ToolRun>) : TranscriptRow() {
|
||||
/** Stable across reloads because it is the first call's own id. */
|
||||
/** The run's own name, which every call in it already carries. */
|
||||
val id: String
|
||||
get() = calls.first().id
|
||||
get() = calls.first().runId
|
||||
|
||||
override val seq: Long
|
||||
get() = calls.first().seq
|
||||
override val key: Any
|
||||
get() = id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,10 +83,16 @@ fun groupToolRuns(items: List<TranscriptItem>): List<TranscriptRow> {
|
||||
}
|
||||
|
||||
items.forEach { item ->
|
||||
if (item is TranscriptItem.ToolRun) run += item
|
||||
else {
|
||||
// Grouped by the run each call says it belongs to, not by adjacency worked out here.
|
||||
// Adjacency is the same answer most of the time and a worse one at the edges: a call
|
||||
// arriving next to an existing run, or a page of history arriving in front of one, both
|
||||
// change which call is *first*, and a group named after its first member is a different
|
||||
// group every time that happens.
|
||||
if (item is TranscriptItem.ToolRun && (run.isEmpty() || run.first().runId == item.runId)) {
|
||||
run += item
|
||||
} else {
|
||||
flush()
|
||||
rows += TranscriptRow.Single(item)
|
||||
if (item is TranscriptItem.ToolRun) run += item else rows += TranscriptRow.Single(item)
|
||||
}
|
||||
}
|
||||
flush()
|
||||
|
||||
Reference in new issue
Block a user