From 2bc00a2a9437f8f304eeb64c84a68ea098afa5c5 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sat, 17 Oct 2026 15:14:52 +0100 Subject: [PATCH 1/2] =?UTF-8?q?android:=20make=20the=20conversation=20read?= =?UTF-8?q?able=20=E2=80=94=20markdown,=20collapsed=20reasoning,=20one=20i?= =?UTF-8?q?dentity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix the three reading problems in the chat conversation view. Android only; no new dependency (the declared material-icons-extended only); no server, Go, installer or Docker file touched and no run started from the app. - Markdown reaches the transcript. Assistant text already went through MarkdownText inside a private composable; name the decision as the pure ChatFormat.partRendering(part) (MARKDOWN/REASONING/PLAIN/HIDDEN) and have MessagePart consume it. Text outside the renderer's documented subset and unknown part kinds still render as their own text (PLAIN); blank parts render nothing (HIDDEN). - Reasoning collapsed by default. ReasoningBlock is now one compact, muted line per part (icon, label, chevron) that expands on tap to the muted text. Expansion is hoisted to the conversation pane as the pure ReasoningExpansion set keyed per stable part key, so a part keeps its state across scroll/disposal and every part starts collapsed in a newly opened chat. A running turn's streaming reasoning stays collapsed under a live "Thinking…" label, signalling progress without competing with the answer. - One identity in the header. ChatFormat.conversationHeader(thread) builds the app-bar title plus only context (labelled kind chip from the server tag, activity, directory, model); the app bar and the context line read the same value. openChatsBeside drops the active chat from the open-chat strip so its title is shown once; every other open chat stays one tap away and the session list is unchanged. Tests: new ChatTranscriptTest (7 cases) plus the existing ChatFormatTest — the markdown subset reaches the renderer from a ChatPart, text outside the subset and an unknown kind still render, reasoning starts collapsed and toggles per part, the header names the session once, and the strip offers only the other open chats. Checked, and none needs an update: the packaged templates carry no Android chat surface; the repository guidelines (README, docs/) document the server and CLI, whose behaviour is unchanged — docs/cli.md's note that Android rendering of the tag is out of scope for the server change still holds; and the packaged authoring skill references (internal/author/skill/references/) describe delivery/verification generally, none of which this UI change alters. android/README.md records the new behaviour. Verified: `gradle :app:testDebugUnitTest :app:assembleDebug --no-daemon --offline --rerun-tasks` → BUILD SUCCESSFUL; JUnit XMLs total 508 tests, 0 failures, 0 errors, 0 skipped. app-debug.apk sha256 0df6899429a8f5632ec568340dddb63a5617b1a04af19f52c6ebb793470a0b23. --- android/README.md | 65 ++++++ .../net/awan/pipelines/ui/chat/ChatFormat.kt | 88 ++++++- .../net/awan/pipelines/ui/chat/ChatScreen.kt | 217 +++++++++++++++--- .../net/awan/pipelines/ui/chat/ChatStore.kt | 9 + .../pipelines/ui/chat/ChatTranscriptTest.kt | 152 ++++++++++++ 5 files changed, 492 insertions(+), 39 deletions(-) create mode 100644 android/app/src/test/java/net/awan/pipelines/ui/chat/ChatTranscriptTest.kt diff --git a/android/README.md b/android/README.md index 44a598b7..0f2c3a10 100644 --- a/android/README.md +++ b/android/README.md @@ -5783,3 +5783,68 @@ Not verified in this pass: the search field, the directory sections and the empty state on a device, and the narrow/wide layouts — the brief keeps implementation verification to the build and the unit tests, and visual review owns the operator's Pixel 9 Pro XL. + +## Conversation reading: markdown, collapsed reasoning, one identity (17 Oct 2026) + +Making the conversation readable on a phone. `android/` only; no new dependency +(the declared `material-icons-extended` only), no Pipelines server/Go/installer/ +Docker file touched and no run started from the app. + +- **Markdown reaches the transcript (tested).** The assistant `text` part was + already rendered through `MarkdownText`, but the transcript's decision was + buried in a private composable. `ChatFormat.partRendering(part)` now names the + one decision the transcript makes (`MARKDOWN` / `REASONING` / `PLAIN` / + `HIDDEN`), `MessagePart` consumes it, and `ChatTranscriptTest` drives a sample + covering the whole documented subset (headings, paragraph, bullet and ordered + lists, quote, table, fenced code, rule, inline code/bold/italic/link) from a + `ChatPart` into `parseMarkdown`/`parseInline`. Text outside the subset (raw + HTML, `~~strike~~`) still parses to a paragraph and renders verbatim; an + unknown part kind still renders its text, never drops it. +- **Reasoning collapsed by default.** `ReasoningBlock` is now one compact, + muted line per part — a `Psychology` icon, a label (`Thinking…` while the + newest turn streams, `Reasoning` once settled) and a chevron — that expands on + tap to the full, still-muted text. Expansion is a pure + `ReasoningExpansion` set hoisted to the conversation pane (not the lazy + transcript), so a part keeps its state while the operator scrolls and its item + is disposed, and every part starts collapsed in a freshly opened chat. The + choice for a running turn: its streaming reasoning stays collapsed and keeps + following the stream under the live `Thinking…` label, so it signals progress + without competing with the answer. +- **One identity in the header.** `ChatFormat.conversationHeader(thread)` builds + the app-bar title plus the only extra context — the labelled kind chip + (`Operator`) from the server's own tag, the activity (`Running` / + `Busy · read-only` / `Idle`), the directory and the model — and the app bar and + context line read the same value. The conversation's active chip is omitted + from the open-chat strip (`openChatsBeside`), so the session's title is shown + once; every *other* open chat is still one tap away, and the session list is + unchanged. + +Tests (`ChatTranscriptTest`, 7 cases, plus the existing `ChatFormatTest`): the +markdown subset reaches the renderer from a `ChatPart`; text outside the subset +and an unknown part kind still render; reasoning starts collapsed, toggles per +part and never expands on a blank key; the header names the session once with +only kind/activity/directory/model beside it; and the conversation strip offers +only the other open chats. + +Evidence (macOS, JDK 17, Gradle 9.7.1 `--offline`, `--no-daemon`, +`ANDROID_HOME=/Users/alan/Library/Android/sdk`): + +- `gradle :app:assembleDebug --no-daemon --offline --rerun-tasks` → `BUILD + SUCCESSFUL` (35 tasks executed). +- `gradle :app:testDebugUnitTest --no-daemon --offline --rerun-tasks` → + `BUILD SUCCESSFUL`; the JUnit XMLs total **508 tests, 0 failures, 0 errors, 0 + skipped** (7 new in `ChatTranscriptTest`). +- **APK publish.** `app-debug.apk` copied to this run's artifacts directory as + `pipelines-debug-wip-5ac196c.apk` (18,486,624 bytes, sha256 + `0df6899429a8f5632ec568340dddb63a5617b1a04af19f52c6ebb793470a0b23`; `5ac196c` + is `git rev-parse --short HEAD`, the tree being uncommitted WIP on top of it). + It is served at + `http://10.0.0.75:8080/artifacts/274/1/pipelines-debug-wip-5ac196c.apk` + (`HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`, + `Content-Length: 18486624`). + +Not verified in this pass: the conversation, the collapsed/expanded reasoning +and the header on a device — the brief keeps implementation verification to the +build and the unit tests, and visual review owns the operator's Pixel 9 Pro XL +(captures: headings/list/fenced code/table, reasoning collapsed then expanded, +and the header). diff --git a/android/app/src/main/java/net/awan/pipelines/ui/chat/ChatFormat.kt b/android/app/src/main/java/net/awan/pipelines/ui/chat/ChatFormat.kt index 56836c07..3f28436a 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/chat/ChatFormat.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/chat/ChatFormat.kt @@ -93,10 +93,15 @@ internal fun sessionTitle(session: ChatSession): String = * session shows no chip. This only *labels*; the app never filters on the tag, * because the server already lists operator sessions only. */ -internal fun sessionTagLabel(session: ChatSession): String? = when { - session.tag.isBlank() -> null - session.tag == ChatProtocol.TAG_OPERATOR -> OPERATOR_TAG_LABEL - else -> session.tag +internal fun sessionTagLabel(session: ChatSession): String? = tagLabel(session.tag) + +/** The kind chip for a conversation's own tag (see [sessionTagLabel]). */ +internal fun sessionTagLabel(tag: String): String? = tagLabel(tag) + +private fun tagLabel(tag: String): String? = when { + tag.isBlank() -> null + tag == ChatProtocol.TAG_OPERATOR -> OPERATOR_TAG_LABEL + else -> tag } private const val OPERATOR_TAG_LABEL = "Operator" @@ -110,9 +115,13 @@ private const val OPERATOR_TAG_LABEL = "Operator" * `Running` and writable, never the read-only the server's own `busy` flag alone * would imply. */ -internal fun sessionStatusLabel(session: ChatSession, runningLocally: Boolean): String = when { +internal fun sessionStatusLabel(session: ChatSession, runningLocally: Boolean): String = + sessionStatusLabel(session.busy, runningLocally) + +/** The status of a conversation from its own model flags (see [sessionStatusLabel]). */ +internal fun sessionStatusLabel(busy: Boolean, runningLocally: Boolean): String = when { runningLocally -> "Running" - session.busy -> "Busy · read-only" + busy -> "Busy · read-only" else -> "Idle" } @@ -135,6 +144,73 @@ internal fun sessionActivity(running: Boolean, unseen: Boolean): SessionActivity else -> SessionActivity.IDLE } +/** + * The one identity a conversation header shows: the title is the session's + * name, and everything else is context that cannot be mistaken for a second + * name — the server's kind tag, the live activity and the directory/model. + * Kept pure so the header and its unit test agree that the title appears once. + */ +internal data class ConversationHeader( + val title: String, + val kind: String?, + val activity: String, + val directory: String, + val model: String, +) { + /** The extra identity context, in reading order, with blank fields omitted. */ + val context: List = listOf(directory, model).filter { it.isNotBlank() } +} + +/** Builds the conversation header from the open thread's copied session fields. */ +internal fun conversationHeader(thread: ChatThread): ConversationHeader = ConversationHeader( + title = sessionTitle(ChatSession(id = thread.sessionId, title = thread.title)), + kind = sessionTagLabel(thread.tag), + activity = sessionStatusLabel(thread.busy, thread.running), + directory = thread.directory, + model = thread.model, +) + +/** + * The open chats a conversation still offers to switch to: every other open + * chat, never the active one, so its title is not repeated beside its own + * header. The session list keeps showing all open chats. + */ +internal fun openChatsBeside(open: List, activeSessionId: String): List = + open.filterNot { it.sessionId == activeSessionId } + +/** + * How the transcript renders one part. The decision is pure so the markdown + * route out of the transcript can be tested without Compose: assistant text is + * markdown, reasoning is its own collapsed presentation, any other part with + * text is plain, and an empty part renders nothing. + */ +internal enum class PartRendering { MARKDOWN, REASONING, PLAIN, HIDDEN } + +internal fun partRendering(part: ChatPart): PartRendering = when { + part.type == ChatProtocol.PART_TEXT && part.text.isNotBlank() -> PartRendering.MARKDOWN + part.type == ChatProtocol.PART_REASONING && part.text.isNotBlank() -> PartRendering.REASONING + part.text.isNotBlank() -> PartRendering.PLAIN + else -> PartRendering.HIDDEN +} + +/** + * Which reasoning parts the operator has opened. A set keyed by the stable + * per-part key, so a streaming part keeps its state as deltas arrive and every + * part starts collapsed in a freshly opened conversation. + */ +internal data class ReasoningExpansion(private val expanded: Set = emptySet()) { + fun isExpanded(partKey: String): Boolean = partKey in expanded + + fun toggled(partKey: String): ReasoningExpansion { + if (partKey.isBlank()) return this + return copy(expanded = if (partKey in expanded) expanded - partKey else expanded + partKey) + } +} + +/** The stable key for one reasoning part, even when the server omitted its id. */ +internal fun reasoningKey(messageId: String, part: ChatPart, index: Int): String = + messageId + ":" + part.id.ifBlank { index.toString() } + /** Which action the composer's single primary control offers for a chat. */ enum class ComposerAction { Send, Stop } diff --git a/android/app/src/main/java/net/awan/pipelines/ui/chat/ChatScreen.kt b/android/app/src/main/java/net/awan/pipelines/ui/chat/ChatScreen.kt index 189ecb1a..e392f8a4 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/chat/ChatScreen.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/chat/ChatScreen.kt @@ -70,6 +70,7 @@ import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.material3.TopAppBar +import androidx.compose.material3.minimumInteractiveComponentSize import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect @@ -139,6 +140,7 @@ import net.awan.pipelines.ui.theme.ICON_LIST_DP import net.awan.pipelines.ui.theme.ICON_STATUS_DP import net.awan.pipelines.ui.theme.SPACING_S import net.awan.pipelines.ui.theme.SPACING_M +import net.awan.pipelines.ui.theme.SPACING_XS import net.awan.pipelines.ui.theme.SPACING_XXS import net.awan.pipelines.ui.theme.TOOL_PANEL_MAX_WIDTH_DP import net.awan.pipelines.ui.theme.pipelinesText @@ -726,17 +728,26 @@ private fun NotConnectedNotice() { } /** - * The open-conversation switcher: one chip per conversation the operator has - * open, so several chats can be kept at once and switched between in one tap. - * A running chat carries a `Running` badge; the X closes that chat (optional - * close is provided). + * The open-conversation switcher: one chip per open conversation, so several + * chats can be kept at once and switched between in one tap. A running chat + * carries its live dot, a chat waiting on an approval carries its hand, and the + * X closes that chat (optional close is provided). [excludeSessionId] omits one + * chat — the conversation pane omits its own active one, whose title already + * stands in the app bar, while the session list shows every open chat. */ @Composable private fun OpenChatStrip( state: ChatState, onSelect: (String) -> Unit, onClose: (String) -> Unit, + excludeSessionId: String? = null, ) { + val threads = if (excludeSessionId == null) { + state.open + } else { + openChatsBeside(state.open, excludeSessionId) + } + if (threads.isEmpty()) return Row( modifier = Modifier .fillMaxWidth() @@ -744,7 +755,7 @@ private fun OpenChatStrip( .padding(horizontal = CHAT_GUTTER, vertical = CHAT_ITEM_GAP), horizontalArrangement = Arrangement.spacedBy(CHAT_ITEM_GAP), ) { - state.open.forEach { thread -> + threads.forEach { thread -> val selected = state.activeId == thread.sessionId Surface( shape = RoundedCornerShape(50), @@ -800,6 +811,41 @@ private fun OpenChatStrip( // ---- Pane 1: the active conversation ----------------------------------------- +/** + * The conversation's identity context, directly below the app bar that carries + * its title: the session kind (labelled, never a bare name), its activity and, + * when the server knows them, the directory and model. The title is not repeated + * here — this block adds only what the title cannot say. + */ +@Composable +private fun ConversationHeader(header: ConversationHeader) { + val texts = pipelinesText() + Column( + modifier = Modifier.fillMaxWidth().padding(horizontal = CHAT_GUTTER, vertical = CHAT_ITEM_GAP), + verticalArrangement = Arrangement.spacedBy(SPACING_XS), + ) { + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(CHAT_ITEM_GAP), + ) { + header.kind?.let { LabelChip(it, SPACING_S, SPACING_XXS) } + Text( + text = header.activity, + style = texts.label, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + } + if (header.context.isNotEmpty()) { + Text( + text = header.context.joinToString(" · "), + style = texts.meta, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + } + } +} + @OptIn(ExperimentalMaterial3Api::class) @Composable private fun ChatConversationPane( @@ -810,6 +856,15 @@ private fun ChatConversationPane( ) { val approval = approvalCard(thread.permission, thread.permissionAnswer) val awaiting = approval?.actionable == true + // The header's one identity: the title, with the kind, activity, directory and + // model as context below it. It is built once so the app bar and the context + // line cannot disagree about the session's name. + val header = conversationHeader(thread) + // Reasoning expansion is hoisted here, not into the lazy transcript: a + // reasoning part keeps its open/closed state while the operator scrolls (and + // the item is disposed), and the state is per conversation, so a newly opened + // chat starts with every reasoning part collapsed. + var reasoning by remember(thread.sessionId) { mutableStateOf(ReasoningExpansion()) } // A turn blocked on an approval is not generating, so the running indicator // (and its ticking clock) stands down while the card is unanswered. val showRunning = thread.running && !awaiting @@ -852,7 +907,7 @@ private fun ChatConversationPane( TopAppBar( title = { Text( - text = thread.title.ifBlank { sessionTitle(ChatSession(id = thread.sessionId)) }, + text = header.title, maxLines = 1, overflow = TextOverflow.Ellipsis, ) @@ -889,7 +944,15 @@ private fun ChatConversationPane( }, ) { padding -> Column(Modifier.fillMaxSize().padding(padding).imePadding()) { - OpenChatStrip(state = state, onSelect = vm::activateChat, onClose = vm::closeChat) + ConversationHeader(header) + // Every *other* open chat is still one tap away; the active one is + // already named by the app bar, so it is not repeated here. + OpenChatStrip( + state = state, + onSelect = vm::activateChat, + onClose = vm::closeChat, + excludeSessionId = thread.sessionId, + ) Box(Modifier.weight(1f).fillMaxWidth()) { when { thread.loading && !thread.loaded -> LoadingState("Loading conversation…") @@ -911,6 +974,8 @@ private fun ChatConversationPane( itemCount = itemCount, approval = approval, showRunning = showRunning, + reasoning = reasoning, + onToggleReasoning = { reasoning = reasoning.toggled(it) }, onDecision = { decision -> approval?.let { vm.replyChatPermission(thread.sessionId, it.requestId, decision) } }, @@ -961,6 +1026,8 @@ private fun ChatTranscript( itemCount: Int, approval: ApprovalCard?, showRunning: Boolean, + reasoning: ReasoningExpansion, + onToggleReasoning: (String) -> Unit, onDecision: (String) -> Unit, ) { val scope = rememberCoroutineScope() @@ -1043,6 +1110,9 @@ private fun ChatTranscript( if (following) listState.scrollToEnd(itemCount, animated = true) } Box(Modifier.fillMaxSize()) { + // Only the newest turn can be streaming, so its reasoning wears the live + // label; a settled turn's reasoning is labelled as settled. + val streamingMessageId = thread.messages.lastOrNull()?.id?.takeIf { thread.running } LazyColumn( state = listState, modifier = Modifier.fillMaxSize(), @@ -1050,7 +1120,12 @@ private fun ChatTranscript( verticalArrangement = Arrangement.spacedBy(CHAT_ITEM_GAP, Alignment.Bottom), ) { items(thread.messages, key = { it.id }) { message -> - MessageItem(message) + MessageItem( + message = message, + reasoning = reasoning, + streaming = message.id == streamingMessageId, + onToggleReasoning = onToggleReasoning, + ) } if (showRunning) { item(key = "pending") { RunningIndicator(thread) } @@ -1181,7 +1256,12 @@ private fun rememberElapsedNow(runningSince: Long): Long { } @Composable -private fun MessageItem(message: ChatMessage) { +private fun MessageItem( + message: ChatMessage, + reasoning: ReasoningExpansion, + streaming: Boolean, + onToggleReasoning: (String) -> Unit, +) { val isUser = message.role == ChatProtocol.ROLE_USER Row( modifier = Modifier.fillMaxWidth(), @@ -1201,7 +1281,13 @@ private fun MessageItem(message: ChatMessage) { if (isUser) { UserParts(message.parts) } else { - AssistantParts(message.parts) + AssistantParts( + messageId = message.id, + parts = message.parts, + reasoning = reasoning, + streaming = streaming, + onToggleReasoning = onToggleReasoning, + ) } } } @@ -1234,7 +1320,13 @@ private fun UserParts(parts: List) { * as they fit, instead of each taking a row, so the transcript stays scannable. */ @Composable -private fun AssistantParts(parts: List) { +private fun AssistantParts( + messageId: String, + parts: List, + reasoning: ReasoningExpansion, + streaming: Boolean, + onToggleReasoning: (String) -> Unit, +) { var index = 0 while (index < parts.size) { if (parts[index].type == ChatProtocol.PART_TOOL) { @@ -1243,42 +1335,101 @@ private fun AssistantParts(parts: List) { ToolCalls(parts.subList(index, end)) index = end } else { - MessagePart(parts[index]) + val part = parts[index] + MessagePart( + part = part, + reasoningKey = reasoningKey(messageId, part, index), + reasoning = reasoning, + streaming = streaming, + onToggleReasoning = onToggleReasoning, + ) index++ } } } @Composable -private fun MessagePart(part: ChatPart) { - when (part.type) { - ChatProtocol.PART_TEXT -> if (part.text.isNotBlank()) { - MarkdownText(part.text) - } - ChatProtocol.PART_REASONING -> ReasoningBlock(part.text) - else -> if (part.text.isNotBlank()) Text(part.text, style = MaterialTheme.typography.bodyMedium) +private fun MessagePart( + part: ChatPart, + reasoningKey: String, + reasoning: ReasoningExpansion, + streaming: Boolean, + onToggleReasoning: (String) -> Unit, +) { + when (partRendering(part)) { + PartRendering.MARKDOWN -> MarkdownText(part.text) + PartRendering.REASONING -> ReasoningBlock( + text = part.text, + expanded = reasoning.isExpanded(reasoningKey), + streaming = streaming, + onToggle = { onToggleReasoning(reasoningKey) }, + ) + PartRendering.PLAIN -> Text(part.text, style = MaterialTheme.typography.bodyMedium) + PartRendering.HIDDEN -> Unit } } -/** Reasoning is visually secondary: a muted, bordered block, never body weight. */ +/** + * Reasoning is visually secondary and collapsed by default: one compact, muted + * line per part (its spinner-free label names the state; the live label is + * `Thinking…`) that expands on tap to the full, still-muted text. The expansion + * state lives on the conversation, so it survives the transcript disposing the + * item while the operator scrolls and a streaming part keeps its state as + * deltas arrive. + */ @Composable -private fun ReasoningBlock(text: String) { +private fun ReasoningBlock( + text: String, + expanded: Boolean, + streaming: Boolean, + onToggle: () -> Unit, +) { if (text.isBlank()) return - Row(horizontalArrangement = Arrangement.spacedBy(CHAT_ITEM_GAP), modifier = Modifier.padding(vertical = 4.dp)) { - Icon( - Icons.Default.Psychology, - contentDescription = null, - tint = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = Modifier.size(16.dp), - ) - Text( - text = text, - style = MaterialTheme.typography.bodySmall.copy(fontFamily = FontFamily.Default), - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) + val label = if (streaming) REASONING_STREAMING_LABEL else REASONING_SETTLED_LABEL + Column(Modifier.fillMaxWidth()) { + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(CHAT_ITEM_GAP), + modifier = Modifier + .fillMaxWidth() + .minimumInteractiveComponentSize() + .clickable(role = Role.Button, onClick = onToggle) + .padding(vertical = SPACING_XS), + ) { + Icon( + Icons.Default.Psychology, + contentDescription = null, + tint = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier.size(ICON_INLINE_DP), + ) + Text( + text = label, + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier.weight(1f), + ) + Icon( + imageVector = if (expanded) Icons.Default.KeyboardArrowUp else Icons.Default.KeyboardArrowDown, + contentDescription = if (expanded) "Hide reasoning" else "Show reasoning", + tint = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier.size(ICON_INLINE_DP), + ) + } + if (expanded) { + Text( + text = text, + style = MaterialTheme.typography.bodySmall.copy(fontFamily = FontFamily.Default), + color = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier.padding(start = ICON_INLINE_DP + CHAT_ITEM_GAP, bottom = CHAT_ITEM_GAP), + ) + } } } +/** The live and settled labels of a reasoning part's one collapsed line. */ +private const val REASONING_STREAMING_LABEL = "Thinking…" +private const val REASONING_SETTLED_LABEL = "Reasoning" + /** * One turn's tool calls as a single group of compact chips, mirroring the * reference transcript's `_ToolCalls`/`_ToolChip` (research §1.3): each call diff --git a/android/app/src/main/java/net/awan/pipelines/ui/chat/ChatStore.kt b/android/app/src/main/java/net/awan/pipelines/ui/chat/ChatStore.kt index 4a094e28..cdeb965b 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/chat/ChatStore.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/chat/ChatStore.kt @@ -51,6 +51,8 @@ data class ChatThread( val title: String = "", val directory: String = "", val model: String = "", + /** The server's stored session kind, copied so the conversation header can label it. */ + val tag: String = "", val agent: String = "", val updatedAt: Long = 0, /** The server reports another client (or an active run) holds this session. */ @@ -298,6 +300,8 @@ class ChatStore( thread.copy( title = renamed[thread.sessionId] ?: session.title.ifBlank { thread.title }, directory = session.directory.ifBlank { thread.directory }, + model = session.model.ifBlank { thread.model }, + tag = session.tag.ifBlank { thread.tag }, busy = session.busy, ) } @@ -445,6 +449,7 @@ class ChatStore( title = title, directory = session.directory, model = session.model, + tag = session.tag, agent = session.agent, updatedAt = session.updatedAt, busy = session.busy, @@ -455,6 +460,8 @@ class ChatStore( val merged = existing.copy( title = title.ifBlank { existing.title }, directory = session.directory.ifBlank { existing.directory }, + model = session.model.ifBlank { existing.model }, + tag = session.tag.ifBlank { existing.tag }, busy = session.busy, ) _state.value = _state.value.copy( @@ -720,6 +727,8 @@ class ChatStore( sessionId = sessionId, title = _state.value.overrides.titles[sessionId] ?: session?.title ?: "", directory = session?.directory ?: "", + model = session?.model ?: "", + tag = session?.tag ?: "", busy = session?.busy ?: false, ) _state.value = _state.value.copy(open = _state.value.open + placeholder) diff --git a/android/app/src/test/java/net/awan/pipelines/ui/chat/ChatTranscriptTest.kt b/android/app/src/test/java/net/awan/pipelines/ui/chat/ChatTranscriptTest.kt new file mode 100644 index 00000000..43712b85 --- /dev/null +++ b/android/app/src/test/java/net/awan/pipelines/ui/chat/ChatTranscriptTest.kt @@ -0,0 +1,152 @@ +package net.awan.pipelines.ui.chat + +import net.awan.pipelines.data.protocol.ChatPart +import net.awan.pipelines.data.protocol.ChatProtocol +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue +import org.junit.Test + +/** + * The conversation's reading decisions, all pure so they need no device: the + * markdown route out of the transcript, reasoning collapsed and remembering its + * expansion, and a header that names the session once with only context beside + * and below it. + */ +class ChatTranscriptTest { + + @Test + fun assistantTextReachesTheMarkdownRendererWithTheDocumentedSubset() { + val sample = """ + # Release notes + + Intro with **bold**, *italic*, `inline code` and a [link](https://example.com/x). + + - first + - second + + 1. one + 2. two + + > quoted line + + | Name | Value | + | --- | --- | + | a | 1 | + + ```kotlin + val gap = 8.dp + ``` + + --- + """.trimIndent() + val part = ChatPart(type = ChatProtocol.PART_TEXT, id = "p1", text = sample) + + // The transcript's own decision routes assistant text through markdown... + assertEquals(PartRendering.MARKDOWN, partRendering(part)) + // ...and the whole documented subset parses into the renderer's blocks. + val blocks = parseMarkdown(part.text) + assertTrue(blocks.any { it is MdHeading }) + assertTrue(blocks.any { it is MdParagraph }) + assertTrue(blocks.any { it is MdListBlock }) + assertTrue(blocks.any { it is MdQuote }) + assertTrue(blocks.any { it is MdTableBlock }) + assertTrue(blocks.any { it is MdCodeBlock }) + assertTrue(blocks.contains(MdRule)) + val spans = parseInline("**bold** *italic* `code` [link](https://example.com/x)") + assertTrue(spans.any { it is MdStrong }) + assertTrue(spans.any { it is MdEmphasis }) + assertTrue(spans.any { it is MdCodeSpan }) + assertTrue(spans.any { it is MdLinkSpan }) + } + + @Test + fun textOutsideTheMarkdownSubsetStillRendersAsItsOwnText() { + val text = "~~struck~~ and raw html; \$_unclosed" + val part = ChatPart(type = ChatProtocol.PART_TEXT, id = "p1", text = text) + assertEquals(PartRendering.MARKDOWN, partRendering(part)) + // Nothing in the subset matches, so the paragraph keeps the source verbatim. + assertEquals(listOf(MdParagraph(text)), parseMarkdown(text)) + + // A part kind the renderer does not know still shows its text, never drops it. + val unknown = ChatPart(type = "status", id = "p2", text = "connection restored") + assertEquals(PartRendering.PLAIN, partRendering(unknown)) + assertEquals(PartRendering.HIDDEN, partRendering(ChatPart(type = ChatProtocol.PART_TEXT, id = "p3"))) + } + + @Test + fun reasoningStartsCollapsedAndKeepsItsExpansionPerPart() { + var reasoning = ReasoningExpansion() + assertFalse(reasoning.isExpanded("m:r1")) + assertFalse(reasoning.isExpanded("m:r2")) + + reasoning = reasoning.toggled("m:r1") + assertTrue(reasoning.isExpanded("m:r1")) + assertFalse(reasoning.isExpanded("m:r2")) + + // Expanding a second part does not disturb the first. + reasoning = reasoning.toggled("m:r2") + assertTrue(reasoning.isExpanded("m:r1")) + assertTrue(reasoning.isExpanded("m:r2")) + + // Collapsing brings only that part back. + reasoning = reasoning.toggled("m:r1") + assertFalse(reasoning.isExpanded("m:r1")) + assertTrue(reasoning.isExpanded("m:r2")) + + // A blank key is never a key: it can never expand every id-less part at once. + val untouched = ReasoningExpansion().toggled("") + assertFalse(untouched.isExpanded("")) + } + + @Test + fun reasoningKeyIsStableForAServerPartAndFallsBackToTheIndex() { + assertEquals("m:r1", reasoningKey("m", ChatPart(id = "r1"), 0)) + assertEquals("m:2", reasoningKey("m", ChatPart(id = ""), 2)) + } + + @Test + fun theHeaderNamesTheSessionOnceAndOnlyAddsContext() { + val header = conversationHeader( + ChatThread( + sessionId = "ses_1", + title = "Fix the parser", + directory = "/Users/alan/repos/pipelines", + model = "openai/gpt-5", + tag = ChatProtocol.TAG_OPERATOR, + running = true, + ), + ) + assertEquals("Fix the parser", header.title) + assertEquals("Operator", header.kind) + assertEquals("Running", header.activity) + assertEquals(listOf("/Users/alan/repos/pipelines", "openai/gpt-5"), header.context) + + // The title is the only identity: the context never repeats it. + assertFalse(header.context.contains(header.title)) + assertFalse(header.kind == header.title) + assertFalse(header.activity == header.title) + } + + @Test + fun theHeaderFallsBackToTheIdAndOmitsUnknownContext() { + val header = conversationHeader(ChatThread(sessionId = "ses_untitled", running = false)) + assertEquals("ses_untitled", header.title) + assertNull(header.kind) + assertEquals("Idle", header.activity) + assertEquals(emptyList(), header.context) + } + + @Test + fun theConversationOffersOnlyTheOtherOpenChatsToSwitchTo() { + val a = ChatThread(sessionId = "a", title = "Alpha") + val b = ChatThread(sessionId = "b", title = "Beta") + val open = listOf(a, b) + + // The active chat is never repeated beside its own header... + assertEquals(listOf(b), openChatsBeside(open, "a")) + // ...and a single open chat leaves nothing to switch to. + assertEquals(emptyList(), openChatsBeside(listOf(a), "a")) + } +} From d13f359e7ba2e79eac4c35d996bd6957d18deffb Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sat, 17 Oct 2026 15:49:55 +0100 Subject: [PATCH 2/2] android: show the run title whole in the run view, two lines in the list A run's title is derived from its prompt, so it is often long. Give it the room it needs where the operator reads the run, and a deliberate clamp where it is one of many. Android only; no new dependency (the declared material-icons-extended only), no Pipelines server/Go/installer/Docker file touched, and no run started from the app. - Run view shows the whole title. The run-summary title line states its intent with RUN_VIEW_TITLE_LINES (Int.MAX_VALUE) and TextOverflow.Clip, so it wraps over as many lines as it needs and is never ellipsised; the fixed-height M3 app-bar copy stays a compact one-line label. - Runs-list rows grow, then clamp. RunRow's title went from maxLines = 1 to RUN_ROW_TITLE_LINES (2): a longer title takes a second line before it ellipsises, with the glyph, status chip and meta line still aligned and the selection highlight and tap target unchanged. - Stage-pane context line. StageDetailPane's run-label line went from maxLines = 1 to STAGE_RUN_LABEL_LINES (2); the pane is compact context, not where the whole title lives. - Named budgets. ui/RunIdentity.kt holds the three budgets so the choice is deliberate at each call site. RunTitlesTest (4 cases) pins them and asserts a clamping place is never more generous than the run view; RunIdentityTest gained a case that runLabel/runIdentity never shorten a long title. Checked for stale copies: android/README.md gained a dated section for this change (its existing "Run title beside the pipeline name" section still holds, it just did not describe line budgets). The top-level README and docs/ do not document the app's run-title rendering, and the packaged templates and internal/author/skill/references/ packaged skill describe Pipelines authoring and Android APK delivery, not this UI, so none of them needed updating. Evidence (JDK 17, Gradle 9.7.1 --offline --no-daemon): :app:testDebugUnitTest BUILD SUCCESSFUL, 57 classes / 513 tests / 0 failures / 0 errors / 0 skipped (RunTitlesTest 4/0, RunIdentityTest 6/0); :app:assembleDebug BUILD SUCCESSFUL, app-debug.apk 18,486,624 bytes sha256 2b23762b54f0..., published as this run's pipelines-debug-wip-2bc00a2.apk and served at http://10.0.0.75:8080/artifacts/278/4/pipelines-debug-wip-2bc00a2.apk. --- android/README.md | 50 +++++++++++++++++++ .../java/net/awan/pipelines/ui/RunIdentity.kt | 19 +++++++ .../pipelines/ui/graph/StageDetailPane.kt | 6 ++- .../pipelines/ui/screens/RunDetailScreen.kt | 19 ++++++- .../pipelines/ui/screens/RunHistoryScreen.kt | 3 +- .../net/awan/pipelines/ui/RunIdentityTest.kt | 12 +++++ .../net/awan/pipelines/ui/RunTitlesTest.kt | 38 ++++++++++++++ 7 files changed, 143 insertions(+), 4 deletions(-) create mode 100644 android/app/src/test/java/net/awan/pipelines/ui/RunTitlesTest.kt diff --git a/android/README.md b/android/README.md index 0f2c3a10..5ae414ff 100644 --- a/android/README.md +++ b/android/README.md @@ -5848,3 +5848,53 @@ and the header on a device — the brief keeps implementation verification to th build and the unit tests, and visual review owns the operator's Pixel 9 Pro XL (captures: headings/list/fenced code/table, reasoning collapsed then expanded, and the header). + +## Run title readability: whole in the run view, two lines in the list (17 Oct 2026) + +A run's title is derived from its prompt, so it is often long. The run view now +guarantees the operator can read it whole, while the places that are one of many +clamp deliberately. `android/` only; no new dependency, no Pipelines +server/Go/installer/Docker file touched and no run started from the app; the build +and unit tests only, no device command run. + +- **Run view shows the whole title.** The run-summary title line rendered + `runLabel(run.title, run.name)` with the Compose default; it now states the + intent with `RUN_VIEW_TITLE_LINES` (`Int.MAX_VALUE`) and `TextOverflow.Clip`, so + it wraps over as many lines as it needs and is never ellipsised. The fixed-height + M3 app-bar copy stays a compact one-line label; the summary's scrollable title is + the complete one. +- **Runs-list rows grow, then clamp.** `RunHistoryScreen.RunRow`'s title went from + `maxLines = 1` to `RUN_ROW_TITLE_LINES` (2), so a longer title takes a second + line before it ellipsises; the row's glyph, status chip and meta line keep their + alignment and the selection highlight and tap target are unchanged. +- **Stage-pane context line.** `StageDetailPane`'s run-label line went from + `maxLines = 1` to `STAGE_RUN_LABEL_LINES` (2) — the pane is compact context, not + the place the whole title lives. +- **One named budget.** `ui/RunIdentity.kt` holds the three named line budgets so + the choice is deliberate at each call site. `RunTitlesTest` (4 cases) pins them + and asserts a clamping place is never more generous than the run view; + `RunIdentityTest` gained a case that `runLabel`/`runIdentity` never shorten a + long title, so re-introducing a truncating helper here fails. + +Tests: the 57 result XMLs aggregate to **513 tests, 0 failures, 0 errors, 0 +skipped** (`RunTitlesTest` 4/0, `RunIdentityTest` 6/0). + +Evidence (macOS, JDK 17 from Homebrew `openjdk@17`, Gradle 9.7.1 `--offline`, +`--no-daemon`, `ANDROID_HOME=/Users/alan/Library/Android/sdk`): + +- `gradle :app:testDebugUnitTest --no-daemon --offline --rerun` → `BUILD + SUCCESSFUL`. +- `gradle :app:assembleDebug --no-daemon --offline` → `BUILD SUCCESSFUL`; + `app-debug.apk` 18,486,624 bytes, sha256 + `2b23762b54f011bbec680804a232f32bd43c244fb52c465a0f4b2c2c9a0148cb`. +- **APK publish.** Copied to this run's artifacts directory as + `pipelines-debug-wip-2bc00a2.apk` (`2bc00a2` = `git rev-parse --short HEAD`, the + tree being uncommitted WIP on top of it), served at + `http://10.0.0.75:8080/artifacts/278/4/pipelines-debug-wip-2bc00a2.apk` + (`HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`; the + downloaded bytes hash to the same sha256). + +Not verified in this pass: how the wrapping summary title, the two-line list row +and the two-line stage header actually render — that needs the device, which this +build-and-unit-test pass did not use; visual review owns the operator's Pixel 9 +Pro XL. diff --git a/android/app/src/main/java/net/awan/pipelines/ui/RunIdentity.kt b/android/app/src/main/java/net/awan/pipelines/ui/RunIdentity.kt index 79e9c079..38ebeaf2 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/RunIdentity.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/RunIdentity.kt @@ -24,3 +24,22 @@ fun runIdentity(title: String?, name: String): RunIdentity { val stored = title?.trim().orEmpty() return if (stored.isEmpty()) RunIdentity(name, null) else RunIdentity(stored, name) } + +/** + * The line budget for a run's title in each place the app shows it. A title is + * derived from the run's prompt, so it is often long, and the places it appears + * have different jobs: the run view exists to let the operator read the run, so + * its own title is complete, while a runs-list row (one of many) and the stage + * pane's compact run-context line may clamp because the run view still carries + * the whole title. Kept here, named, so the budgets are a deliberate choice the + * tests pin rather than a bare `maxLines` literal at each call site. + */ + +/** The run view's own title never elides: it wraps over as many lines as it needs. */ +internal const val RUN_VIEW_TITLE_LINES: Int = Int.MAX_VALUE + +/** A runs-list row's title grows to two lines for a longer title, then ellipsises. */ +internal const val RUN_ROW_TITLE_LINES: Int = 2 + +/** The stage pane's compact run-context line shows at most two lines, then ellipsises. */ +internal const val STAGE_RUN_LABEL_LINES: Int = 2 diff --git a/android/app/src/main/java/net/awan/pipelines/ui/graph/StageDetailPane.kt b/android/app/src/main/java/net/awan/pipelines/ui/graph/StageDetailPane.kt index 6af92d25..29fbc172 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/graph/StageDetailPane.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/graph/StageDetailPane.kt @@ -47,6 +47,7 @@ import net.awan.pipelines.ui.components.KeyValueRow import net.awan.pipelines.ui.components.PaneIdentity import net.awan.pipelines.ui.components.SectionHeader import net.awan.pipelines.ui.components.paneSafeArea +import net.awan.pipelines.ui.STAGE_RUN_LABEL_LINES import net.awan.pipelines.ui.displayMap import net.awan.pipelines.ui.fileChangeLine import net.awan.pipelines.ui.fileChangesSummary @@ -422,7 +423,10 @@ fun StageDetailPane( Text( label, style = pipelinesText().meta, - maxLines = 1, + // The run's own complete title lives in the run + // view; here it is a compact context line, so it may + // take a second line but not run away with the pane. + maxLines = STAGE_RUN_LABEL_LINES, overflow = TextOverflow.Ellipsis, ) } diff --git a/android/app/src/main/java/net/awan/pipelines/ui/screens/RunDetailScreen.kt b/android/app/src/main/java/net/awan/pipelines/ui/screens/RunDetailScreen.kt index c98f40ca..c768dca4 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/screens/RunDetailScreen.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/screens/RunDetailScreen.kt @@ -89,6 +89,7 @@ import net.awan.pipelines.ui.runArtifactGroups import net.awan.pipelines.ui.runArtifactsHeader import net.awan.pipelines.ui.runIdentity import net.awan.pipelines.ui.runLabel +import net.awan.pipelines.ui.RUN_VIEW_TITLE_LINES import net.awan.pipelines.ui.theme.ICON_INLINE_DP import net.awan.pipelines.ui.theme.ICON_STATUS_DP import net.awan.pipelines.ui.theme.SPACING_L @@ -193,7 +194,11 @@ fun RunDetailScreen( // The header names the run by its title and keeps the pipeline // it belongs to on a second line, so a stage pane opened from // here carries the same context. Without a title the pipeline - // name is the single identity, never a blank first line. + // name is the single identity, never a blank first line. This + // app-bar copy is a compact one-line label (the M3 app bar is a + // fixed height, so it cannot grow); the run's own complete, + // wrapping title is the summary's title line below, which is + // never elided. val identity = run?.let { runIdentity(it.title, it.name) } Column { Text( @@ -429,7 +434,17 @@ private fun RunSummaryTab( modifier = Modifier.fillMaxWidth().padding(horizontal = SPACING_L), verticalArrangement = Arrangement.spacedBy(SPACING_XS), ) { - Text(runLabel(run.title, run.name), style = text.screenTitle) + // The run view's own copy of the title: the operator must be + // able to read what the run is called, so it is never elided - + // it wraps over as many lines as it needs. The compact app-bar + // copy above stays a one-line label for context while this + // scrollable, complete one is what the operator reads. + Text( + runLabel(run.title, run.name), + style = text.screenTitle, + maxLines = RUN_VIEW_TITLE_LINES, + overflow = TextOverflow.Clip, + ) Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(SPACING_S), diff --git a/android/app/src/main/java/net/awan/pipelines/ui/screens/RunHistoryScreen.kt b/android/app/src/main/java/net/awan/pipelines/ui/screens/RunHistoryScreen.kt index 4cd57055..40b39c62 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/screens/RunHistoryScreen.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/screens/RunHistoryScreen.kt @@ -70,6 +70,7 @@ import net.awan.pipelines.ui.components.paneSafeArea import net.awan.pipelines.ui.components.rememberLiveNowMillis import net.awan.pipelines.ui.components.runStateColor import net.awan.pipelines.ui.components.runStateOf +import net.awan.pipelines.ui.RUN_ROW_TITLE_LINES import net.awan.pipelines.ui.formatDuration import net.awan.pipelines.ui.runDurationText import net.awan.pipelines.ui.runIdentity @@ -529,7 +530,7 @@ private fun RunRow( Text( identity.label, style = text.cardTitle, - maxLines = 1, + maxLines = RUN_ROW_TITLE_LINES, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f), ) diff --git a/android/app/src/test/java/net/awan/pipelines/ui/RunIdentityTest.kt b/android/app/src/test/java/net/awan/pipelines/ui/RunIdentityTest.kt index cfd1e135..53fcfba9 100644 --- a/android/app/src/test/java/net/awan/pipelines/ui/RunIdentityTest.kt +++ b/android/app/src/test/java/net/awan/pipelines/ui/RunIdentityTest.kt @@ -47,4 +47,16 @@ class RunIdentityTest { assertEquals("android-app", runLabel(null, "android-app")) assertEquals("android-app", runLabel(" ", "android-app")) } + + @Test + fun aVeryLongTitleIsKeptWholeAtTheDataLevel() { + // The run view's own title is rendered from this value with no line limit, + // so the identity itself must never silently shorten it: a prompt-derived + // title stays complete and the view, not this function, decides the + // layout. Guards against re-introducing a truncating helper here. + val long = "Implement the whole thing carefully, then review it ".repeat(40).trim() + assertEquals(long, runLabel(long, "android-app")) + assertEquals(long, runIdentity(long, "android-app").label) + assertEquals("android-app", runIdentity(long, "android-app").pipeline) + } } diff --git a/android/app/src/test/java/net/awan/pipelines/ui/RunTitlesTest.kt b/android/app/src/test/java/net/awan/pipelines/ui/RunTitlesTest.kt new file mode 100644 index 00000000..f49f18b9 --- /dev/null +++ b/android/app/src/test/java/net/awan/pipelines/ui/RunTitlesTest.kt @@ -0,0 +1,38 @@ +package net.awan.pipelines.ui + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Test + +/** + * The run title's line budget in each place it is shown. A title is derived from + * the run's prompt and is often long, so the run view - the place whose whole job + * is to let the operator read the run - must show it complete, while the places + * that are one of many (a runs-list row) or a compact label (the stage pane's + * run-context line) clamp. The budgets are pinned here so a change to one is a + * deliberate, reviewed decision and the run view can never become the most + * generous place by accident. + */ +class RunTitlesTest { + + @Test + fun theRunViewShowsTheWholeTitleNeverEliding() { + assertEquals(Int.MAX_VALUE, RUN_VIEW_TITLE_LINES) + } + + @Test + fun aRunsListRowGrowsForALongTitleThenClampsAtTwoLines() { + assertEquals(2, RUN_ROW_TITLE_LINES) + } + + @Test + fun theStagePaneRunContextTakesASecondLineThenClamps() { + assertEquals(2, STAGE_RUN_LABEL_LINES) + } + + @Test + fun aClampingPlaceIsNeverMoreGenerousThanTheCompleteOne() { + assertTrue("a list row may not outlive the run view", RUN_ROW_TITLE_LINES < RUN_VIEW_TITLE_LINES) + assertTrue("a stage context line may not outlive the run view", STAGE_RUN_LABEL_LINES < RUN_VIEW_TITLE_LINES) + } +}