Make a command a thing the app knows, and hold it until it can run
Typing "/" now suggests what this app understands -- `/compact` and `/rename <name>` -- with a line each about what they do, and anything else beginning with a slash is passed to whatever runs the session, because a dialect's own vocabulary grows without this list. None of them are messages, and that is the substance of the change. A line written into a running turn is read by the *model*, so a command sent mid-turn either does nothing or arrives as text somebody has to puzzle over. They now wait for the turn to end. The waiting is done once for every provider, in the pump that already watches every event for the boundary, rather than in each driver where a new provider could get it wrong by leaving it out. Waiting is a state, so it is on screen: the command sits at the reader's end of the conversation in blue, with a spinner and "waiting for this turn to end", and becomes an ordinary blue row when it goes. Blue because these are about the session rather than about the task -- the same blue a compaction already used, which is now one colour with one name rather than two. Renaming from the settings screen sends exactly this, so it waits and draws the same way. The name itself is not held: it is this server's own datum, so the list and the header change at once and only telling the session waits. Echo grew the same split, which is where the bug in it showed: its commands are its messages, so running one announced a `MessageTaken` as well, and the same line drew twice -- once blue, once purple. A command owes no announcement; the manager has already recorded that it was sent. Watched rather than reasoned about: `/compact` during a 25 second turn held with its bubble up, went out when the turn ended, and the compaction that followed reported what it recovered.
This commit is contained in:
1 parent
bebaae7a94
commit
749b2db287
13 files changed
+678
-93
No files matched your search
@@ -143,6 +143,14 @@ sealed class TranscriptItem {
|
||||
data class PeerNote(override val seq: Long, val from: String, val text: String) :
|
||||
TranscriptItem()
|
||||
|
||||
/**
|
||||
* A command the session ran on itself -- `/compact`, `/rename`.
|
||||
*
|
||||
* Kept in the transcript rather than only shown while it waits, because it explains what
|
||||
* follows: a conversation that suddenly has half the context, or a session with a new name.
|
||||
*/
|
||||
data class CommandRow(override val seq: Long, val text: String) : TranscriptItem()
|
||||
|
||||
/** Placeholder row for events this build can't render (newer kinds). */
|
||||
data class Note(override val seq: Long, val text: String) : TranscriptItem()
|
||||
|
||||
@@ -250,7 +258,9 @@ fun foldEvent(items: List<TranscriptItem>, entry: SeqEvent): List<TranscriptItem
|
||||
}
|
||||
is SessionEvent.PeerMessage ->
|
||||
items + TranscriptItem.PeerNote(entry.seq, event.from, event.text)
|
||||
is SessionEvent.CommandSent -> items + TranscriptItem.CommandRow(entry.seq, event.text)
|
||||
// Screen-level state, not transcript rows -- see SessionScreen.
|
||||
is SessionEvent.CommandQueued -> items
|
||||
is SessionEvent.Settings -> items
|
||||
is SessionEvent.Status -> items
|
||||
is SessionEvent.Error -> items + TranscriptItem.ErrorMsg(entry.seq, event.message)
|
||||
@@ -320,6 +330,11 @@ fun SessionScreen(
|
||||
var pendingAttachments by remember { mutableStateOf(listOf<String>()) }
|
||||
// What this session is set to now, seeded from the row that opened it and
|
||||
// then owned here, because changing either is something this screen does.
|
||||
// The name shown at the top. Held here rather than read from the row that opened this
|
||||
// screen, because renaming is something this screen can do -- through the settings below it,
|
||||
// or by typing the command -- and a header still showing the old name reads as a rename that
|
||||
// did not take.
|
||||
var title by remember(summary.id) { mutableStateOf(summary.title) }
|
||||
var model by remember { mutableStateOf(summary.model) }
|
||||
var permissionMode by remember { mutableStateOf(summary.permissionMode ?: "auto") }
|
||||
// The models this provider actually offers, asked of the server rather
|
||||
@@ -344,6 +359,10 @@ fun SessionScreen(
|
||||
// reading of events: after everything taken in, not yet taken in
|
||||
// itself.
|
||||
var queued by remember { mutableStateOf(listOf<String>()) }
|
||||
// Commands the session has been asked to run and cannot yet, by the id that will resolve
|
||||
// them. From the server rather than from this screen, so a rename sent from the settings
|
||||
// screen -- or from another device -- is drawn waiting here too.
|
||||
var waitingCommands by remember { mutableStateOf(listOf<Pair<String, String>>()) }
|
||||
val running = status == "running" || status == "compacting"
|
||||
var moreHistory by remember { mutableStateOf(true) }
|
||||
var loadingHistory by remember { mutableStateOf(false) }
|
||||
@@ -393,6 +412,14 @@ fun SessionScreen(
|
||||
// earlier one -- and only the first match, so two
|
||||
// identical messages wait twice.
|
||||
if (event is SessionEvent.UserMessage) queued = queued - event.text
|
||||
// Waiting, then gone: a command leaves this list when the session takes it,
|
||||
// and the row it becomes is added by `foldEvent` in the same pass.
|
||||
if (event is SessionEvent.CommandQueued) {
|
||||
waitingCommands = waitingCommands + (event.id to event.text)
|
||||
}
|
||||
if (event is SessionEvent.CommandSent) {
|
||||
waitingCommands = waitingCommands.filterNot { it.first == event.id }
|
||||
}
|
||||
// Kept as well as folded. Folding is one-way -- a tool's
|
||||
// start and end become one row -- so a page arriving in
|
||||
// front of what is already here cannot be stitched on
|
||||
@@ -624,6 +651,25 @@ fun SessionScreen(
|
||||
val text = input.trim()
|
||||
val attachments = pendingAttachments
|
||||
if (text.isEmpty() && attachments.isEmpty()) return
|
||||
// A command is not a message: it is an instruction to the session about itself, and one
|
||||
// written into a running turn is read by the model instead. The server holds it until the
|
||||
// turn ends and says so, which is where its waiting bubble comes from -- so nothing is
|
||||
// held here, and there is no local guess to correct when the answer arrives.
|
||||
if (text.startsWith("/") && attachments.isEmpty()) {
|
||||
input = ""
|
||||
// The one command with a visible effect outside the transcript, applied when the
|
||||
// server has accepted it rather than when it was typed: the name is this app's own
|
||||
// datum and changes at once, and only telling the session waits for a boundary.
|
||||
val renamed =
|
||||
text.removePrefix("/rename ").trim().takeIf {
|
||||
text.startsWith("/rename ") && it.isNotEmpty()
|
||||
}
|
||||
act {
|
||||
runCommand(settings, summary.id, text)
|
||||
renamed?.let { title = it }
|
||||
}
|
||||
return
|
||||
}
|
||||
input = ""
|
||||
pendingAttachments = emptyList()
|
||||
if (running && text.isNotEmpty()) queued = queued + text
|
||||
@@ -672,7 +718,7 @@ fun SessionScreen(
|
||||
) {
|
||||
TextButton(onClick = onBack) { Text("Back") }
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text(summary.title, style = MaterialTheme.typography.titleMedium)
|
||||
Text(title, style = MaterialTheme.typography.titleMedium)
|
||||
Text(
|
||||
listOfNotNull(
|
||||
summary.provider,
|
||||
@@ -739,9 +785,12 @@ fun SessionScreen(
|
||||
// Below the working indicator, because that is where they
|
||||
// are in the session's reading of events: after everything
|
||||
// it has taken in, and not yet taken in themselves.
|
||||
if (queued.isNotEmpty()) {
|
||||
if (queued.isNotEmpty() || waitingCommands.isNotEmpty()) {
|
||||
item(key = "queued") {
|
||||
Column(horizontalAlignment = Alignment.End) {
|
||||
waitingCommands.forEach { (_, text) ->
|
||||
CommandBubble(text, waiting = true)
|
||||
}
|
||||
queued.forEach { text -> UserBubble(text, pending = true) }
|
||||
}
|
||||
}
|
||||
@@ -867,6 +916,7 @@ fun SessionScreen(
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
is TranscriptItem.CommandRow -> CommandBubble(item.text)
|
||||
is TranscriptItem.CompactedNote -> CompactedRow(item)
|
||||
is TranscriptItem.PeerNote ->
|
||||
PeerMessageRow(
|
||||
@@ -913,6 +963,13 @@ fun SessionScreen(
|
||||
}
|
||||
}
|
||||
|
||||
// Between the transcript and the box: above what is being typed, so the list does not
|
||||
// cover the thing the command is about, and below everything that explains it.
|
||||
CommandSuggestions(
|
||||
commands = suggestedCommands(input),
|
||||
onPick = { command -> input = command.typed() },
|
||||
)
|
||||
|
||||
// Always enabled -- a send while the session is running becomes a
|
||||
// steering message injected at the next tool boundary, which is
|
||||
// the point of the whole app.
|
||||
|
||||
Reference in new issue
Block a user