chat: name the session's model in the conversation header

The conversation header showed only the thread title, so inside a chat there
was nothing saying which model was answering. It now renders a second line
from server-reported values only.

- ChatFormat.kt: add chatHeaderMeta(thread), joining the reported model, the
  session's kind tag and the directory with " · "; blank parts are omitted so
  no model is ever claimed when the server did not report one. Refactor
  sessionTagLabel to a tag-value overload so the list row and the header share
  one tag mapping.
- ChatStore.kt: ChatThread gains the tag field; sessionsLoaded and open fold
  the server's model/agent/tag into already-open threads, and ensureThread
  seeds them, so the header never shows a stale or missing model.
- ChatScreen.kt: the conversation top bar title becomes a two-line column with
  the meta line in the shared pipelinesText().meta role; the create flow states
  plainly that this server has no request for choosing a chat's model.
- No model chooser is shipped. The server forwards no model/agent on
  chat_prompt and exposes no model/agent catalogue, so shipping a picker would
  be a control that does nothing; android/README.md records the exact server
  change it would need.
- Tests: ChatFormatTest covers chatHeaderMeta (reported model/tag/directory,
  and never claiming an unreported model) and the shared tag mapping;
  ChatSessionManagementTest covers the open thread carrying the reported
  model/agent/tag and a list refresh folding a new model in.

Checked before committing:
- Packaged templates: none exist (the author package embeds only skill/SKILL.md
  and references/*.md; no *.tmpl/*.template in the tree) - nothing to update.
- Repository guidelines: android/README.md updated with the change and its
  evidence; the root README and docs/ describe the server and CLI, not the
  Android chat surface - no update needed.
- Packaged authoring skill references (internal/author/skill/references/): none
  describes the Android chat surface - no update needed.

android/ only, no new dependency beyond the declared material-icons-extended.
This commit is contained in:
2026-10-17 15:03:00 +01:00
parent 8e6cb39284
commit 9b67e55d70
6 changed files with 195 additions and 9 deletions
@@ -93,12 +93,33 @@ 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? = sessionTagLabel(session.tag)
/**
* The kind chip label for a session's own tag value (see [sessionTagLabel]).
* Kept as the single mapping so a session and the conversation it opens cannot
* label the same tag differently.
*/
internal fun sessionTagLabel(tag: String): String? = when {
tag.isBlank() -> null
tag == ChatProtocol.TAG_OPERATOR -> OPERATOR_TAG_LABEL
else -> tag
}
/**
* The one-line meta under a conversation's own title: the model the server
* reports is answering, the session's kind tag and its directory. Every part is
* a value the server reported (a model id, the wire tag, the directory), so
* nothing is guessed and no catalogue is invented; a blank part is omitted, so a
* session the server reported without a model (or an older server that omits the
* field) shows no model claim at all.
*/
internal fun chatHeaderMeta(thread: ChatThread): String = listOfNotNull(
thread.model.takeIf { it.isNotBlank() },
sessionTagLabel(thread.tag),
thread.directory.takeIf { it.isNotBlank() },
).joinToString(" · ")
private const val OPERATOR_TAG_LABEL = "Operator"
/**
@@ -628,6 +628,19 @@ private fun NewChatPane(
modifier = Modifier.padding(horizontal = CHAT_GUTTER, vertical = CHAT_ITEM_GAP),
)
}
// The brokered server exposes no request for choosing a
// session's model: chat_prompt carries model/agent fields but
// the server does not forward them, and there is no catalogue
// request to offer a choice from. So the flow says so plainly
// rather than shipping a picker that would do nothing. The
// conversation header then shows whatever model the server
// reports for the created session.
Text(
text = "This server has no request for choosing a chat's model, so a new chat uses the server's default.",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(horizontal = CHAT_GUTTER, vertical = CHAT_ITEM_GAP),
)
NewChatActions(
directory = selected?.createDirectory ?: create.directory,
creating = create.creating,
@@ -851,11 +864,28 @@ private fun ChatConversationPane(
topBar = {
TopAppBar(
title = {
Text(
text = thread.title.ifBlank { sessionTitle(ChatSession(id = thread.sessionId)) },
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
Column {
Text(
text = thread.title.ifBlank { sessionTitle(ChatSession(id = thread.sessionId)) },
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
// The model the server reports is answering this session,
// beside the session's kind tag and its directory, so what
// is replying is always visible without leaving the
// conversation. Every part is server-reported; a blank one
// is simply omitted.
val meta = chatHeaderMeta(thread)
if (meta.isNotBlank()) {
Text(
text = meta,
style = pipelinesText().meta,
color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
}
},
navigationIcon = {
IconButton(onClick = vm::showChatList) {
@@ -52,6 +52,8 @@ data class ChatThread(
val directory: String = "",
val model: String = "",
val agent: String = "",
/** The session's kind tag the server reported (see [ChatSession.tag]). */
val tag: String = "",
val updatedAt: Long = 0,
/** The server reports another client (or an active run) holds this session. */
val busy: Boolean = false,
@@ -298,6 +300,9 @@ 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 },
agent = session.agent.ifBlank { thread.agent },
tag = session.tag.ifBlank { thread.tag },
busy = session.busy,
)
}
@@ -446,6 +451,7 @@ class ChatStore(
directory = session.directory,
model = session.model,
agent = session.agent,
tag = session.tag,
updatedAt = session.updatedAt,
busy = session.busy,
)
@@ -455,6 +461,9 @@ class ChatStore(
val merged = existing.copy(
title = title.ifBlank { existing.title },
directory = session.directory.ifBlank { existing.directory },
model = session.model.ifBlank { existing.model },
agent = session.agent.ifBlank { existing.agent },
tag = session.tag.ifBlank { existing.tag },
busy = session.busy,
)
_state.value = _state.value.copy(
@@ -720,6 +729,9 @@ class ChatStore(
sessionId = sessionId,
title = _state.value.overrides.titles[sessionId] ?: session?.title ?: "",
directory = session?.directory ?: "",
model = session?.model ?: "",
agent = session?.agent ?: "",
tag = session?.tag ?: "",
busy = session?.busy ?: false,
)
_state.value = _state.value.copy(open = _state.value.open + placeholder)
@@ -152,4 +152,32 @@ class ChatFormatTest {
assertEquals("Named", sessionTitle(ChatSession(id = "ses_1", title = "Named")))
assertEquals("ses_abcdefghijklmn", sessionTitle(ChatSession(id = "ses_abcdefghijklmnop")))
}
@Test
fun chatHeaderMetaShowsTheReportedModelTagAndDirectory() {
// The conversation header names what is answering beside the session's
// kind tag and its directory, every part the server's own value.
val thread = ChatThread(
sessionId = "ses_1",
model = "deepseek-v4.1-flash",
tag = ChatProtocol.TAG_OPERATOR,
directory = "/home/op/work",
)
assertEquals("deepseek-v4.1-flash · Operator · /home/op/work", chatHeaderMeta(thread))
}
@Test
fun chatHeaderMetaNeverClaimsAModelTheServerDidNotReport() {
// A session the server reported without a model (or an older server that
// omits the field) shows no model claim, never a guess or a catalogue.
assertEquals("", chatHeaderMeta(ChatThread(sessionId = "ses_1")))
assertEquals("Operator", chatHeaderMeta(ChatThread(sessionId = "ses_1", tag = ChatProtocol.TAG_OPERATOR)))
}
@Test
fun aSessionTagAndAThreadTagLabelTheSame() {
assertEquals(sessionTagLabel(ChatSession(tag = ChatProtocol.TAG_OPERATOR)), sessionTagLabel(ChatProtocol.TAG_OPERATOR))
assertEquals("scratch", sessionTagLabel("scratch"))
assertNull(sessionTagLabel(""))
}
}
@@ -143,6 +143,23 @@ class ChatSessionManagementTest {
assertTrue(store.value.visibleSessions == listed)
}
@Test
fun anOpenConversationCarriesTheModelAndTagTheServerReports() {
val store = ChatStore()
store.sessionsLoaded(listOf(session("a").copy(model = "deepseek-v4.1-flash", agent = "build")))
store.open(store.value.sessions.single())
// The header reads the server's own values, so opening a session shows
// what is answering without a second request.
assertEquals("deepseek-v4.1-flash", store.value.thread("a")!!.model)
assertEquals("build", store.value.thread("a")!!.agent)
assertEquals(ChatProtocol.TAG_OPERATOR, store.value.thread("a")!!.tag)
// A later list refresh folds the server's reported model into the open
// conversation too, so the header never shows a stale model id.
store.sessionsLoaded(listOf(session("a").copy(model = "gpt-x", agent = "build")))
assertEquals("gpt-x", store.value.thread("a")!!.model)
}
@Test
fun theCoveredPaneCountMatchesTheVisibleList() {
val store = ChatStore()