Merge branch 'main' into remove-run-evidence-tab

This commit is contained in:
2026-10-18 23:12:23 +01:00
48 changed files with 2274 additions and 877 deletions
@@ -13,6 +13,8 @@ import net.awan.pipelines.data.protocol.ChatPromptRequest
import net.awan.pipelines.data.protocol.ChatProtocol
import net.awan.pipelines.data.protocol.ChatQuery
import net.awan.pipelines.data.protocol.ChatSession
import net.awan.pipelines.data.protocol.ChatShellOutputPage
import net.awan.pipelines.data.protocol.ChatShell
import net.awan.pipelines.data.protocol.Message
import net.awan.pipelines.data.protocol.Graph
import net.awan.pipelines.data.protocol.PipelineDetail
@@ -312,6 +314,22 @@ class PipelinesRepository(
return response.chatHistory ?: ChatHistoryPage(messages = response.chatMessages ?: emptyList())
}
/** Reads one bounded page from a verified, currently observable shell. */
suspend fun chatShellOutput(sessionId: String, shellId: String, cursor: Long = 0, limit: Int = ChatProtocol.SHELL_OUTPUT_LIMIT): ChatShellOutputPage {
if (sessionId.isBlank() || shellId.isBlank()) throw ProtocolException("Select a shell first.")
if (cursor < 0 || limit <= 0 || limit > ChatProtocol.SHELL_OUTPUT_LIMIT) {
throw ProtocolException("Shell output bounds are invalid.")
}
return client.call(ChatProtocol.shellOutputRequest(sessionId, shellId, cursor, limit)).chatShellOutput
?: throw ProtocolException("The server returned no shell output page.")
}
/** Lists currently observed shells owned by this operator chat session. */
suspend fun chatShells(sessionId: String): List<ChatShell> {
if (sessionId.isBlank()) throw ProtocolException("Select a chat session first.")
return client.call(ChatProtocol.shellsRequest(sessionId)).chatShells ?: emptyList()
}
/**
* Attaches this connection to [sessionId]'s shared live stream, so it sees
* every frame any client's turn produces — the other devices' prompts and the
@@ -201,6 +201,24 @@ data class ChatShell(
val exit: Int? = null,
)
@Serializable
data class ChatShellOutputQuery(
@SerialName("session_id") val sessionId: String = "",
@SerialName("shell_id") val shellId: String = "",
val cursor: Long = 0,
val limit: Int = ChatProtocol.SHELL_OUTPUT_LIMIT,
)
@Serializable
data class ChatShellOutputPage(
val shell: ChatShell = ChatShell(),
val output: String = "",
val cursor: Long = 0,
val size: Long = 0,
val truncated: Boolean = false,
val unavailable: Boolean = false,
)
@Serializable
data class ChatStep(
val status: String = "",
@@ -282,6 +300,7 @@ object ChatProtocol {
const val SHELL_RUNNING = "running"
const val SHELL_EXITED = "exited"
const val SHELL_OUTPUT_LIMIT = 64 * 1024
/**
* A prompt another client sent, echoed live to this client so it appears in
@@ -359,6 +378,15 @@ object ChatProtocol {
fun interruptRequest(sessionId: String): Message =
Message(type = Protocol.CHAT_INTERRUPT, chatQuery = ChatQuery(sessionId = sessionId))
fun shellOutputRequest(sessionId: String, shellId: String, cursor: Long = 0, limit: Int = SHELL_OUTPUT_LIMIT): Message =
Message(
type = Protocol.CHAT_SHELL_OUTPUT,
chatShellOutputQuery = ChatShellOutputQuery(sessionId, shellId, cursor, limit),
)
fun shellsRequest(sessionId: String): Message =
Message(type = Protocol.CHAT_SHELLS, chatQuery = ChatQuery(sessionId = sessionId))
/**
* The `chat_close` frame that finishes [sessionId]: the server stops any
* running turn (through the same interrupt) and records the session closed on
@@ -79,6 +79,8 @@ object Protocol {
// The operator's directory choices for a new chat (home first, then the
// directories of previous operator sessions, most recently used first).
const val CHAT_DIRECTORIES = "chat_directories"
const val CHAT_SHELLS = "chat_shells"
const val CHAT_SHELL_OUTPUT = "chat_shell_output"
// Server-pushed frames with no matching request.
const val CHAT_EVENT = "chat_event"
const val CHAT_PERMISSION = "chat_permission"
@@ -712,4 +714,7 @@ data class Message(
// close/reopen requests themselves ride on chat_query like chat_interrupt.
@SerialName("chat_close") val chatClose: ChatCloseResult? = null,
@SerialName("chat_directories") val chatDirectories: List<String>? = null,
@SerialName("chat_shell_output_query") val chatShellOutputQuery: ChatShellOutputQuery? = null,
@SerialName("chat_shells") val chatShells: List<ChatShell>? = null,
@SerialName("chat_shell_output") val chatShellOutput: ChatShellOutputPage? = null,
)
@@ -89,6 +89,13 @@ internal val destinations = listOf(
TopDestination("settings", "Settings", Icons.Default.Settings),
)
/** The home route remains beneath top-level navigation, so Back returns to Runs. */
internal const val HOME_ROUTE = "runs"
/** Returning to home clears the accumulated top-level stack; other destinations keep it. */
internal fun topLevelPopUpToHomeInclusive(destination: String): Boolean =
destination == HOME_ROUTE
/**
* Whether [route] is the current destination. Detail panes are no longer
* separate routes (they are saved state inside a destination), so this is a
@@ -210,14 +217,14 @@ fun PipelinesApp(
is SearchTarget.Pipeline -> {
pipelineSelection = PaneSelection(MasterPane.Detail, target.pipelineId, target.version)
navController.navigate("pipelines") {
popUpTo("pipelines") { inclusive = false }
popUpTo(HOME_ROUTE) { inclusive = false }
launchSingleTop = true
}
}
is SearchTarget.Run -> {
runSelection = PaneSelection(MasterPane.Detail, target.runId)
runSearchNav = target.takeIf { it.sequence > 0 }
navController.navigate("runs") { launchSingleTop = true }
navController.navigate(HOME_ROUTE) { launchSingleTop = true }
}
null -> Unit
}
@@ -231,7 +238,7 @@ fun PipelinesApp(
val openRunFromAttention: (Long) -> Unit = { runId ->
vm.arrivedAtRun(runId)
runSelection = PaneSelection(pane = MasterPane.Detail, itemId = runId)
navController.navigate("runs") { launchSingleTop = true }
navController.navigate(HOME_ROUTE) { launchSingleTop = true }
}
// A deep link (or the notification's click action) opens its run once. The
@@ -274,7 +281,9 @@ fun PipelinesApp(
val onNavigate: (TopDestination) -> Unit = { destination ->
if (currentRoute != destination.route) {
navController.navigate(destination.route) {
popUpTo("pipelines") { inclusive = destination.route == "pipelines" }
popUpTo(HOME_ROUTE) {
inclusive = topLevelPopUpToHomeInclusive(destination.route)
}
launchSingleTop = true
}
}
@@ -317,7 +326,7 @@ fun PipelinesApp(
)
NavHost(
navController = navController,
startDestination = "pipelines",
startDestination = HOME_ROUTE,
// While the banner is visible it owns the status-bar inset, so
// the inner app bars below must not apply it a second time.
modifier = Modifier
@@ -344,11 +353,11 @@ fun PipelinesApp(
pane = MasterPane.Detail,
itemId = runId,
)
navController.navigate("runs") { launchSingleTop = true }
navController.navigate(HOME_ROUTE) { launchSingleTop = true }
},
)
}
composable("runs") {
composable(HOME_ROUTE) {
RunsDestination(
vm = vm,
wide = wide,
@@ -405,6 +405,36 @@ class ChatProtocolTest {
assertEquals(1792112367999L, decodedReply.chatClose!!.closedAt)
}
@Test
fun shellOutputRequestAndPageUseBoundedWireNames() {
val request = ChatProtocol.shellOutputRequest("ses_1", "sh_1", 7, 128)
val decoded = PipelinesJson.decodeFromString(Message.serializer(), PipelinesJson.encodeToString(Message.serializer(), request))
assertEquals(Protocol.CHAT_SHELL_OUTPUT, decoded.type)
assertEquals("ses_1", decoded.chatShellOutputQuery!!.sessionId)
assertEquals("sh_1", decoded.chatShellOutputQuery!!.shellId)
assertEquals(7L, decoded.chatShellOutputQuery!!.cursor)
assertEquals(128, decoded.chatShellOutputQuery!!.limit)
val page = PipelinesJson.decodeFromString(Message.serializer(), """
{"type":"chat_shell_output","chat_shell_output":{"shell":{"id":"sh_1","status":"running"},"output":"marker","cursor":13,"size":20,"truncated":true}}
""".trimIndent())
assertEquals("marker", page.chatShellOutput!!.output)
assertTrue(page.chatShellOutput!!.truncated)
}
@Test
fun shellsRequestUsesSessionQueryAndPreservesListWireName() {
val request = ChatProtocol.shellsRequest("ses_1")
val decoded = PipelinesJson.decodeFromString(Message.serializer(), PipelinesJson.encodeToString(Message.serializer(), request))
assertEquals(Protocol.CHAT_SHELLS, decoded.type)
assertEquals("ses_1", decoded.chatQuery!!.sessionId)
val reply = PipelinesJson.decodeFromString(Message.serializer(), """
{"type":"chat_shells","chat_shells":[{"id":"sh_1","status":"running","command":"printf marker"}]}
""".trimIndent())
assertEquals("sh_1", reply.chatShells!!.single().id)
assertEquals(ChatProtocol.SHELL_RUNNING, reply.chatShells.single().status)
}
private fun toolDuration(part: ChatPart): Long? {
val time = part.time ?: return null
return time.completed - time.ran
@@ -13,6 +13,19 @@ import org.junit.Test
class PipelinesNavTest {
@Test
fun runsIsTheHomeRouteForColdLaunchAndTopLevelBack() {
assertEquals("runs", HOME_ROUTE)
}
@Test
fun returningToHomeIsTheOnlyTopLevelNavigationThatClearsHome() {
assertTrue(topLevelPopUpToHomeInclusive(HOME_ROUTE))
assertFalse(topLevelPopUpToHomeInclusive("pipelines"))
assertFalse(topLevelPopUpToHomeInclusive("chat"))
assertFalse(topLevelPopUpToHomeInclusive("settings"))
}
@Test
fun thePillDoesNotHoldTemplates() {
// Templates is configuration and moved to the Settings page; the pill keeps