chat: search the session list and group it by directory

With a day's sessions the list was a flat, unsearchable wall in recency
order, so the chat the operator wanted was the one that could not be
found, and sessions of one repository were scattered through it.

Narrow the list as the operator types and keep same-repository chats
together, using the control and empty-state patterns the other lists
already use:

- ChatListFilter.kt adds the one pure derivation: sessionMatchesQuery /
  filterChatSessions match a case-insensitive substring over a session's
  title and directory, a blank query narrows nothing, and the survivors
  keep their incoming (recency) order. groupChatSessionsByDirectory groups
  the narrowed list by directory, each group keeping that order and the
  groups ordered by their first (most recent) session, so the top still
  leads with the newest activity.
- ChatState.sessionQuery (set through ChatStore.searchSessions /
  AppViewModel.setChatSessionQuery) is a display narrowing only: the
  server's list, open conversations and the activity marks are untouched.
  filteredSessions is visibleSessions narrowed by the query.
- ChatListPane renders the existing FilterMenu with one OutlinedTextField
  and a Clear search reset (the pipelines/runs filter pattern), shows a
  directory heading per group only when more than one directory is
  present, and renders the shared EmptyState ("No chats match ...") with
  a Clear search action when nothing matches. The trailing New chat
  action is never hidden while the list is narrowed, and every row still
  shows its directory.

Tests (ChatListFilterTest, 9 cases): the match rule over title and
directory, that a narrowing preserves the recency order, grouping by
directory (order by the first session, order kept inside a group, a
single directory yields one group, a blank directory groups too), and
through the store that searching narrows filteredSessions, clearing
restores the full list, the server's list is untouched and a filtered
session still reports its activity mark.

Checked before commit: android/README.md was updated in this change with
the behaviour, tests and evidence. The packaged authoring skill references
(internal/author/skill/references/) document the Pipelines server, its
chat_* protocol surface and authoring, none of which changed - this is a
client-side narrowing over the already-listed sessions - so none needed
updating, and the internal/author/install.go managed reference inventory
is unchanged. No repository template or root/topic doc describes the
Android session list, so none was stale.

android/ only; no dependency added beyond the already-declared
material-icons-extended; no run is started from the app.
This commit is contained in:
2026-10-17 14:50:30 +01:00
parent bb486acc11
commit 355fe4e908
6 changed files with 387 additions and 16 deletions
+69
View File
@@ -5714,3 +5714,72 @@ active carries no wall-clock stamp on its pushed frames, so its exact recency is
only learned from the server's history/`updated_at` on a later read; if the app is
killed before that, a restart can conservatively re-flag that chat until it is
opened again. Opening always clears the mark.
## Finding a session among many: search and directory grouping (17 Oct 2026)
The chat list is the operator's own sessions in recency order, but as a day's work
accumulates it is a flat, unsearchable wall and the session that is wanted is the
one that cannot be found. The list can now be narrowed by typing over each chat's
title and directory, sessions of one repository are grouped together, and a
narrowing that matches nothing says so and offers to clear it.
`android/` only; no dependency was added beyond the already-declared
material-icons-extended, nothing in the Pipelines server, its Go source, the
installer or the Docker files was touched, and no run is started from the app.
- **The search control reuses the list-filter pattern.**
`ChatListSearchControl` is the shared `FilterMenu` (the same top-bar icon with
an active-count badge used by the pipelines and runs lists), carrying one
`OutlinedTextField` and a `Clear search` reset. It is not a new control: the
field narrows the list as the operator types and the menu stays open behind it,
exactly like the pipelines name filter.
- **The match rule is one pure derivation.** `ui/chat/ChatListFilter.kt`
adds `sessionMatchesQuery` / `filterChatSessions`: a case-insensitive substring
over the session's title (the local rename included, since it is applied to the
visible list first) and its directory. A blank or whitespace query narrows
nothing, and the survivors keep their incoming order — so the search composes
with the recency order rather than re-sorting it.
- **Same repository, together.** `groupChatSessionsByDirectory` groups the
narrowed sessions by directory, each group keeping the recency order inside it
and the groups ordered by their first (most recent) session, so the top of the
list still leads with the newest activity. The list pane renders a directory
heading per group only when there is more than one directory; a single directory
(or none) stays the flat list, which is already together. Every row still shows
its directory as before.
- **Empty result and the create path.** A narrowing that matches nothing renders
the shared `EmptyState` — `No chats match "<query>".` with a `Clear search`
action — the same empty-state pattern the other lists use. The trailing
`New chat` action is never hidden while the list is narrowed, so creating stays
one tap away.
- **State and marks untouched.** `ChatState.sessionQuery` (set through
`ChatStore.searchSessions` / `AppViewModel.setChatSessionQuery`) is a display
narrowing only: it never touches the server's list or an open conversation, and
the activity marks derive from the same session ids as before.
Tests (`ChatListFilterTest`, 9 cases): the match rule over title and directory
(case-insensitive, blank matches all, a miss is empty), that filtering preserves
the recency order, grouping by directory (order by the first session, order kept
inside a group, a single directory yields one group, a blank directory groups
too), and — through the store — that searching narrows `filteredSessions`,
clearing restores the full list, the server's list is untouched, and a filtered
session still reports its activity mark.
Evidence (this run's implementer pass, macOS, Gradle 8.11.1 at
`~/.gradle/wrapper/dists/gradle-8.11.1-bin/bpt9gzteqjrbo1mjrsomdt32c/gradle-8.11.1/bin/gradle`
with `JAVA_HOME="/Applications/Android Studio.app/Contents/jbr/Contents/Home"`
(JDK 17) and `ANDROID_HOME=/Users/alan/Library/Android/sdk`):
`gradle --offline --no-daemon :app:testDebugUnitTest` → `BUILD SUCCESSFUL`; the
JUnit XMLs total **55 suites / 501 tests / 0 failures / 0 errors / 0 skipped** (9
new in `ChatListFilterTest`). `gradle --offline --no-daemon :app:assembleDebug` →
`BUILD SUCCESSFUL`; the APK was published to this run's artifacts directory as
`pipelines-debug-wip-bb486ac.apk` (18,486,624 bytes, sha256
`d276f7be66501c7becdd83628e3407f955ec982552a87a6a5146d4f44cb5598d`; `bb486ac` is
`git rev-parse --short HEAD`, the tree being uncommitted WIP on top of it) and is
served at
`http://10.0.0.75:8080/artifacts/271/1/pipelines-debug-wip-bb486ac.apk`
(`HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
`Content-Length: 18486624`).
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.
@@ -839,6 +839,14 @@ class AppViewModel(
/** Shows the session list again while keeping every open conversation. */
fun showChatList() = chatStore.showList()
/**
* Narrows the session list to what matches [query] over each chat's title and
* directory, as the operator types. It is a display narrowing only, so no
* request is made and open conversations are untouched; a blank query clears
* it.
*/
fun setChatSessionQuery(query: String) = chatStore.searchSessions(query)
fun closeChat(sessionId: String) = chatStore.close(sessionId)
fun updateChatDraft(sessionId: String, text: String) = chatStore.draft(sessionId, text)
@@ -0,0 +1,53 @@
package net.awan.pipelines.ui.chat
import net.awan.pipelines.data.protocol.ChatSession
/**
* The session-list narrowing: a case-insensitive substring the operator types to
* find a chat by what it is called or where it lives. Blank narrows nothing, and
* the list's own recency order is never touched — filtering keeps the order the
* server returned (and the operator's local overrides applied on top).
*
* Kept pure (no Compose, no transport) like the other chat formatting, so the
* match rule and its unit test share one derivation.
*/
internal fun sessionMatchesQuery(session: ChatSession, query: String): Boolean {
val needle = query.trim()
if (needle.isEmpty()) return true
return sessionTitle(session).contains(needle, ignoreCase = true) ||
session.directory.contains(needle, ignoreCase = true)
}
/**
* Narrows [sessions] to those matching [query] over their title and directory. A
* blank query changes nothing, and the surviving sessions keep their original
* relative order, so a narrowing composes with the recency order rather than
* re-sorting it.
*/
internal fun filterChatSessions(sessions: List<ChatSession>, query: String): List<ChatSession> =
if (query.isBlank()) sessions else sessions.filter { sessionMatchesQuery(it, query) }
/**
* One run of sessions sharing one directory, so sessions of the same repository
* can be placed together while each keeps its recency position inside the run.
*/
data class ChatSessionGroup(val directory: String, val sessions: List<ChatSession>)
/**
* Groups [sessions] by directory, so sessions in the same repository sit together.
* The sessions keep their incoming recency order (within each group), and the
* groups themselves are ordered by the first — most recent — session they contain,
* so the top of the list still leads with the newest activity. A blank directory is
* a group of its own, labelled by the row as usual.
*
* The caller renders the groups as sections only when there is more than one;
* with a single directory the flat list is already "together".
*/
internal fun groupChatSessionsByDirectory(sessions: List<ChatSession>): List<ChatSessionGroup> {
if (sessions.isEmpty()) return emptyList()
val order = LinkedHashMap<String, MutableList<ChatSession>>()
for (session in sessions) {
order.getOrPut(session.directory) { mutableListOf() }.add(session)
}
return order.map { (directory, grouped) -> ChatSessionGroup(directory, grouped) }
}
@@ -119,6 +119,8 @@ import net.awan.pipelines.ui.components.CODE_BLOCK_MAX_HEIGHT
import net.awan.pipelines.ui.components.CodeBlock
import net.awan.pipelines.ui.components.EmptyState
import net.awan.pipelines.ui.components.ErrorState
import net.awan.pipelines.ui.components.FilterMenu
import net.awan.pipelines.ui.components.FilterSectionHeader
import net.awan.pipelines.ui.components.LabelChip
import net.awan.pipelines.ui.components.ListRow
import net.awan.pipelines.ui.components.LoadingState
@@ -136,6 +138,7 @@ import net.awan.pipelines.ui.theme.ICON_INLINE_DP
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_XXS
import net.awan.pipelines.ui.theme.TOOL_PANEL_MAX_WIDTH_DP
import net.awan.pipelines.ui.theme.pipelinesText
@@ -256,8 +259,12 @@ private fun ChatListPane(
// The server returns operator sessions only, with the operator's own local
// renames and removals applied on top; the app never guesses which session
// belongs to a run.
val sessions = state.visibleSessions
// belongs to a run. The operator's search narrows that list without touching
// its order, and the survivors are grouped by directory when there is more
// than one so sessions in the same repository sit together.
val sessions = state.filteredSessions
val groups = groupChatSessionsByDirectory(sessions)
val query = state.sessionQuery
// A removal is reported for what it is: a local, undoable change, never a
// pretend delete — the server is not asked to remove anything.
@@ -282,9 +289,12 @@ private fun ChatListPane(
TopAppBar(
title = { Text("Chat") },
actions = {
ChatListSearchControl(query = query, onQuery = vm::setChatSessionQuery)
IconButton(onClick = vm::refreshChatSessions) {
Icon(Icons.Default.Refresh, contentDescription = "Refresh chats")
}
// The create path stays one tap away while the list is
// narrowed: it is the same trailing action, never hidden.
IconButton(onClick = vm::startNewChat) {
Icon(Icons.Default.Add, contentDescription = "New chat")
}
@@ -304,28 +314,37 @@ private fun ChatListPane(
NotConnectedNotice()
}
when {
state.sessionsLoading && sessions.isEmpty() -> LoadingState("Loading chats…")
state.sessionsError != null && sessions.isEmpty() -> {
state.sessionsLoading && state.sessions.isEmpty() -> LoadingState("Loading chats…")
state.sessionsError != null && state.sessions.isEmpty() -> {
ErrorState(state.sessionsError, onRetry = vm::refreshChatSessions)
}
sessions.isEmpty() && query.isNotBlank() -> EmptyState(
// A narrowing that matches nothing says so plainly and offers
// to clear it, the same empty-state pattern the other lists use.
message = "No chats match \"${query.trim()}\".",
actionLabel = "Clear search",
onAction = { vm.setChatSessionQuery("") },
)
sessions.isEmpty() -> EmptyState(
message = "No chat sessions on this server yet.",
actionLabel = "New chat",
onAction = vm::startNewChat,
)
else -> LazyColumn(Modifier.fillMaxSize()) {
items(sessions, key = { it.id }) { session ->
val thread = state.thread(session.id)
SessionRow(
session = session,
open = thread != null,
running = thread?.running == true,
unseen = state.isUnseen(session),
active = state.activeId == session.id,
onClick = { vm.openChatSession(session) },
onRename = { renaming = session },
onRemove = { vm.removeChat(session.id) },
)
if (groups.size > 1) {
// More than one directory: one section per repository so
// same-directory chats sit together, each keeping the
// recency order inside it.
groups.forEach { group ->
item(key = "dir-" + group.directory) { DirectoryHeader(group.directory) }
items(group.sessions, key = { it.id }) { session ->
SessionListItem(state, session, vm, onRename = { renaming = it })
}
}
} else {
items(sessions, key = { it.id }) { session ->
SessionListItem(state, session, vm, onRename = { renaming = it })
}
}
if (state.sessionsError != null) {
item("error") {
@@ -354,6 +373,79 @@ private fun ChatListPane(
}
}
/**
* The session-list search control: the same top-bar filter-menu pattern the other
* lists use, with one free-text field that narrows the list by title and directory
* as the operator types. The active-count badge and the reset action report and
* clear the narrowing, and the create action beside it is never hidden.
*/
@Composable
private fun ChatListSearchControl(query: String, onQuery: (String) -> Unit) {
FilterMenu(
activeCount = if (query.isBlank()) 0 else 1,
contentDescription = "Search chats",
resetLabel = "Clear search",
onReset = { onQuery("") },
) {
FilterSectionHeader("Search")
OutlinedTextField(
value = query,
onValueChange = onQuery,
label = { Text("Title or directory contains") },
singleLine = true,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = SPACING_M, vertical = SPACING_S),
)
}
}
/**
* One session of the list, whether it is rendered flat or inside a directory
* section: [SessionRow] fed from the live [state], so the activity marks, the open
* flag and the rename/remove actions are identical in both layouts.
*/
@Composable
private fun SessionListItem(
state: ChatState,
session: ChatSession,
vm: AppViewModel,
onRename: (ChatSession) -> Unit,
) {
val thread = state.thread(session.id)
SessionRow(
session = session,
open = thread != null,
running = thread?.running == true,
unseen = state.isUnseen(session),
active = state.activeId == session.id,
onClick = { vm.openChatSession(session) },
onRename = { onRename(session) },
onRemove = { vm.removeChat(session.id) },
)
}
/**
* The heading of one directory section. The directory is shown here as well as on
* every row, so the grouping is legible even after a row scrolls out of view.
*/
@Composable
private fun DirectoryHeader(directory: String) {
Text(
text = directory.ifBlank { NO_DIRECTORY_LABEL },
style = MaterialTheme.typography.labelLarge,
color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = CHAT_GUTTER, vertical = CHAT_ITEM_GAP),
)
}
/** The section heading for sessions the server reported without a directory. */
private const val NO_DIRECTORY_LABEL = "No directory"
@Composable
private fun SessionRow(
session: ChatSession,
@@ -159,6 +159,12 @@ data class ChatState(
val lastRemoved: String? = null,
/** What the operator has read of the list (see [ChatSeenState]). */
val seen: ChatSeenState = ChatSeenState(),
/**
* The operator's search over the list: free text matched against each
* session's title and directory (see [sessionMatchesQuery]). Blank narrows
* nothing, so the default list is the server's order unchanged.
*/
val sessionQuery: String = "",
) {
val active: ChatThread? get() = open.firstOrNull { it.sessionId == activeId }
@@ -208,6 +214,15 @@ data class ChatState(
val hiddenIds = overrides.hiddenIds
sessions.count { it.id !in hiddenIds }
}
/**
* The sessions the list shows after the operator's own changes and their
* search: [visibleSessions] narrowed by [sessionQuery], in the same order, so
* the search composes with the recency order instead of re-sorting it. The
* list pane groups the result by directory (see [groupChatSessionsByDirectory]).
*/
val filteredSessions: List<ChatSession>
get() = filterChatSessions(visibleSessions, sessionQuery)
}
/**
@@ -258,6 +273,16 @@ class ChatStore(
_state.value = _state.value.copy(sessionsLoading = false, sessionsError = message)
}
/**
* Narrows the list by the operator's search text. It is a display narrowing
* only: the server's list and every open conversation are untouched, and a
* blank [query] restores the full, recency-ordered list.
*/
fun searchSessions(query: String) {
if (query == _state.value.sessionQuery) return
_state.value = _state.value.copy(sessionQuery = query)
}
/**
* Replaces the server's session list and folds its title/busy flags into any
* already-open thread, so a status change is reflected without dropping the
@@ -0,0 +1,124 @@
package net.awan.pipelines.ui.chat
import net.awan.pipelines.data.protocol.ChatEventFrame
import net.awan.pipelines.data.protocol.ChatPart
import net.awan.pipelines.data.protocol.ChatProtocol
import net.awan.pipelines.data.protocol.ChatSession
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
/**
* The session-list narrowing and grouping: the match rule over a chat's title and
* directory, that a narrowing keeps the recency order, and that sessions of one
* directory group together. Pure, so it needs no device, server or Compose.
*/
class ChatListFilterTest {
private fun session(
id: String,
title: String = id,
directory: String = "",
updatedAt: Long = 0,
) = ChatSession(id = id, title = title, directory = directory, updatedAt = updatedAt)
private fun delta(sessionId: String) = ChatEventFrame(
sessionId = sessionId,
messageId = "m1",
kind = ChatProtocol.PART_TEXT,
delta = "hello",
part = ChatPart(type = ChatProtocol.PART_TEXT, id = "m1#0"),
)
private val deploy = session("a", title = "Deploy API", directory = "/repos/api")
private val webBug = session("b", title = "Fix login", directory = "/repos/web")
private val webDocs = session("c", title = "Write docs", directory = "/repos/web")
// --- the match rule: title and directory ------------------------------------
@Test
fun aBlankQueryMatchesEverySession() {
assertTrue(sessionMatchesQuery(deploy, ""))
assertTrue(sessionMatchesQuery(deploy, " "))
assertEquals(listOf(deploy, webBug, webDocs), filterChatSessions(listOf(deploy, webBug, webDocs), ""))
}
@Test
fun theQueryMatchesTheTitleOrTheDirectoryIgnoringCase() {
// Title, case-insensitively.
assertTrue(sessionMatchesQuery(deploy, "deploy"))
assertTrue(sessionMatchesQuery(deploy, "API"))
// Directory, case-insensitively.
assertTrue(sessionMatchesQuery(webBug, "REPOS/WEB"))
assertEquals(listOf(webBug, webDocs), filterChatSessions(listOf(deploy, webBug, webDocs), "web"))
}
@Test
fun aQueryThatMatchesNothingYieldsAnEmptyList() {
assertTrue(filterChatSessions(listOf(deploy, webBug), "no-such-chat").isEmpty())
}
// --- narrowing preserves the underlying order --------------------------------
@Test
fun filteringKeepsTheRecencyOrderOfTheSurvivors() {
val ordered = listOf(deploy, webBug, webDocs)
// Both web chats are kept in the order they were given, not re-sorted.
assertEquals(listOf("b", "c"), filterChatSessions(ordered, "web").map { it.id })
// A single hit is still just that hit.
assertEquals(listOf("a"), filterChatSessions(ordered, "deploy").map { it.id })
}
// --- grouping by directory --------------------------------------------------
@Test
fun sessionsOfTheSameDirectoryGroupTogetherKeepingTheirOrder() {
val groups = groupChatSessionsByDirectory(listOf(deploy, webBug, webDocs))
// The first group is the one whose most recent session comes first.
assertEquals(listOf("/repos/api", "/repos/web"), groups.map { it.directory })
assertEquals(listOf("b", "c"), groups[1].sessions.map { it.id })
}
@Test
fun aSingleDirectoryYieldsOneGroupSoTheFlatListIsAlreadyTogether() {
assertEquals(1, groupChatSessionsByDirectory(listOf(webBug, webDocs)).size)
assertTrue(groupChatSessionsByDirectory(emptyList()).isEmpty())
}
@Test
fun sessionsWithoutADirectoryGroupTogetherToo() {
val groups = groupChatSessionsByDirectory(listOf(session("a"), session("b", directory = "/repos/x")))
assertEquals(listOf("", "/repos/x"), groups.map { it.directory })
}
// --- through the store ------------------------------------------------------
@Test
fun searchNarrowsTheStoreListAndClearingRestoresIt() {
val store = ChatStore()
store.sessionsLoaded(listOf(deploy, webBug, webDocs))
assertEquals(listOf("a", "b", "c"), store.value.filteredSessions.map { it.id })
store.searchSessions("web")
// The list is narrowed but the order is untouched.
assertEquals(listOf("b", "c"), store.value.filteredSessions.map { it.id })
// The server's list itself is untouched.
assertEquals(3, store.value.sessions.size)
store.searchSessions("")
assertEquals(listOf("a", "b", "c"), store.value.filteredSessions.map { it.id })
}
@Test
fun theActivityMarkIsReportedForAFilteredSession() {
val store = ChatStore()
store.sessionsLoaded(listOf(deploy, webBug, webDocs))
// A pushed frame for a background chat marks it, whether or not it matches.
store.event(delta("b"))
store.searchSessions("web")
assertTrue(store.value.isUnseen(webBug))
val groups = groupChatSessionsByDirectory(store.value.filteredSessions)
assertEquals(1, groups.size)
assertEquals(listOf("b", "c"), groups.single().sessions.map { it.id })
}
}