Merge main into slash-commands: combine the composer's slash commands with the

server-side chat close

What was combined:

- main brought the server-side close (chat_close/chat_reopen over the protocol,
  PipelinesRepository.chatClose/chatReopen, ChatStore.sessionClosed/sessionReopened
  and active/closed session projections, the list's Close chat… confirmation and
  the Closed chip), plus the destinations-pill overlay and the omni-search and
  status-label work from the lanes that landed beside this one.
- this branch brought the composer's slash commands: parsing, the filtered offer
  list with Enter/tap/D-pad, the shared prompt path, /new in the current
  directory, the local /rename, /stop, /help and the unknown-command offer, with
  local command lines rendered outside the model's conversation.

Resolution (the one place the two sides disagreed):

The branch's /close reported that no real session close existed, because none did
when it was written. main now has one, so /close delegates to it instead:
AppViewModel.SessionChatCommandHost.finishSession calls closeChatSession, which
uses the server's own chat_close (a running turn is stopped, the session is marked
closed for every client, the history is kept), and then chatStore.close returns the
operator to the list. A failure is reported on the list, where the list's own close
reports it. The now-false "this build has no real session close yet" line and its
CHAT_CLOSE_UNAVAILABLE constant are removed, /close's offer summary says it
finishes the session for every client, and its test now drives the real store
close (sessionClosed + close) and asserts the row is closed, kept as history and
off the pane.

Checks run after resolving, on the merged tree (HEAD = this merge):
`--offline --no-daemon :app:assembleDebug` BUILD SUCCESSFUL, and
`:app:testDebugUnitTest` BUILD SUCCESSFUL with 646 tests, 0 failures (including
ChatCommandsTest.closeDelegatesToTheRealServerCloseAndReturnsToTheList). DimensTest
still holds: no raw dimension was added outside the token files. The packaged
templates and packaged authoring skill references are unaffected — this is an
Android-app-only change with no protocol, server, installer or Docker change — so
none of them needed updating.

Documentation now stale (not edited here; one writer folds shared docs):
android/README.md's chat section describes the composer and the session list
without the slash commands (vocabulary, offer list, unknown-command guard) and
without the composer's /close path to the server close.
This commit is contained in:
2026-10-18 00:24:41 +01:00
46 changed files with 2111 additions and 265 deletions
@@ -333,6 +333,26 @@ class PipelinesRepository(
client.call(ChatProtocol.interruptRequest(sessionId))
}
/**
* Finishes a chat on the server: any running turn is stopped and the session
* is recorded closed, so every client sees it. Nothing is deleted. The
* server returns the closed session, which the caller folds into its list.
*/
suspend fun chatClose(sessionId: String): ChatSession {
if (sessionId.isBlank()) throw ProtocolException("Select a chat session first.")
val response = client.call(ChatProtocol.closeRequest(sessionId))
return response.chatSession
?: throw ProtocolException("The server did not return the closed chat session.")
}
/** Clears a closed chat's state so it returns to the active list. */
suspend fun chatReopen(sessionId: String): ChatSession {
if (sessionId.isBlank()) throw ProtocolException("Select a chat session first.")
val response = client.call(ChatProtocol.reopenRequest(sessionId))
return response.chatSession
?: throw ProtocolException("The server did not return the reopened chat session.")
}
suspend fun chatReply(sessionId: String, requestId: String, decision: String, message: String = "") {
if (sessionId.isBlank() || requestId.isBlank()) {
throw ProtocolException("A pending permission request is required.")
@@ -33,6 +33,26 @@ data class ChatSession(
// run. Kept for wire compatibility; the server no longer sets it, and a
// session is never read-only for a client.
val busy: Boolean = false,
// The operator finished with this session: the server recorded it as closed,
// so every client sees the same state. The session, its transcript and its
// history are kept and the closed chat stays in the list (grouped as history),
// where it can be reopened. [closedAt] is the epoch-millisecond close time, 0
// while open. Additive/optional, so an older server simply never sets them.
val closed: Boolean = false,
@SerialName("closed_at") val closedAt: Long = 0,
)
/**
* The outcome of a `chat_close`, mirroring `internal/protocol/chat.go`
* ChatCloseResult: the closed session's id, the epoch-millisecond close time and
* whether an in-flight turn was interrupted to stop it. It is the record that a
* running turn was stopped.
*/
@Serializable
data class ChatCloseResult(
@SerialName("session_id") val sessionId: String = "",
@SerialName("closed_at") val closedAt: Long = 0,
val interrupted: Boolean = false,
)
@Serializable
@@ -288,6 +308,24 @@ object ChatProtocol {
fun interruptRequest(sessionId: String): Message =
Message(type = Protocol.CHAT_INTERRUPT, 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
* the server, sharing the state with every client. Nothing is deleted. Built
* here (not inline in the repository) so production and its unit test share
* the one wire shape.
*/
fun closeRequest(sessionId: String): Message =
Message(type = Protocol.CHAT_CLOSE, chatQuery = ChatQuery(sessionId = sessionId))
/**
* The `chat_reopen` frame that clears a closed session's state so it returns
* to the active list; the inverse of [closeRequest]. Built here so production
* and its unit test share the one wire shape.
*/
fun reopenRequest(sessionId: String): Message =
Message(type = Protocol.CHAT_REOPEN, chatQuery = ChatQuery(sessionId = sessionId))
/**
* The `chat_reply` frame that answers one permission request: [decision] is
* one of [DECISION_ONCE]/[DECISION_ALWAYS]/[DECISION_REJECT]. Built here (not
@@ -68,6 +68,11 @@ object Protocol {
const val CHAT_MESSAGES = "chat_messages"
const val CHAT_INTERRUPT = "chat_interrupt"
const val CHAT_REPLY = "chat_reply"
// Close/reopen an operator session on the server (its closed state is
// recorded so every client sees it). Both ride on chat_query like
// chat_interrupt; chat_close also carries a ChatCloseResult on the response.
const val CHAT_CLOSE = "chat_close"
const val CHAT_REOPEN = "chat_reopen"
// Attaches this connection to one session's shared live stream, so every
// client watching a session receives every frame any client's turn produces.
const val CHAT_SUBSCRIBE = "chat_subscribe"
@@ -688,5 +693,8 @@ data class Message(
@SerialName("chat_event") val chatEvent: ChatEventFrame? = null,
@SerialName("chat_permission") val chatPermission: ChatPermissionFrame? = null,
@SerialName("chat_reply") val chatReply: ChatReplyRequest? = null,
// The outcome of a chat_close (session id, closed_at, interrupted); the
// 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,
)
@@ -41,7 +41,6 @@ import net.awan.pipelines.data.transport.ServerUrl
import net.awan.pipelines.notify.NoRunAlerts
import net.awan.pipelines.notify.RunAlertSink
import net.awan.pipelines.notify.runAlerts
import net.awan.pipelines.ui.chat.CHAT_CLOSE_UNAVAILABLE
import net.awan.pipelines.ui.chat.ChatAttachment
import net.awan.pipelines.ui.chat.ChatCommandHost
import net.awan.pipelines.ui.chat.ChatSessionOverrides
@@ -1157,6 +1156,9 @@ class AppViewModel(
// is one waiting behind an in-flight turn, and the composer says so
// instead of blocking input.
chatStore.setQueued(sessionId, queued)
// Prompting a closed session reopens it on the server; clear the
// closed mark locally too so the list agrees without a re-fetch.
chatStore.sessionReopened(sessionId)
} catch (t: Throwable) {
if (t is CancellationException) throw t
val message = ErrorMessages.describe(t)
@@ -1202,8 +1204,8 @@ class AppViewModel(
* The real effects behind a slash command. `/new` creates in the current
* session's directory and switches to it (the old one stays open, listed, with
* its history); `/rename` uses the device's own rename; `/stop` interrupts;
* `/close` reports that this build has no real close instead of hiding the
* session. Nothing here is ever a prompt.
* `/close` finishes the session for every client through the server's own
* close and returns to the list. Nothing here is ever a prompt.
*/
private inner class SessionChatCommandHost(private val sessionId: String) : ChatCommandHost {
override fun startSession(directory: String) {
@@ -1228,9 +1230,13 @@ class AppViewModel(
}
override fun finishSession() {
// No session close exists in this revision: the honest answer, never
// the local hide dressed up as one.
chatStore.notice(sessionId, CHAT_CLOSE_UNAVAILABLE, failed = true)
// The server's own close: any running turn is stopped and the session
// is marked closed for every client, with its history kept. Then the
// conversation leaves the pane, so the operator is back at the list,
// where the closed chat sits as history. A failure is reported on the
// list — the same place the list's own close reports it.
closeChatSession(sessionId)
chatStore.close(sessionId)
}
override fun renameSession(title: String) {
@@ -1284,6 +1290,44 @@ class AppViewModel(
}
}
/**
* Finishes a chat on the server: any running turn is stopped (the server
* reuses its interrupt) and the session is recorded closed, so every client
* sees the same state. Nothing is deleted — the session and its history stay —
* and the chat is kept in the list as closed history. Errors are reported on
* the list, which is where the action lives.
*/
fun closeChatSession(sessionId: String) {
if (sessionId.isBlank()) return
viewModelScope.launch {
try {
val closed = repository.chatClose(sessionId)
chatStore.sessionClosed(sessionId, closed.closedAt)
} catch (t: Throwable) {
if (t is CancellationException) throw t
chatStore.sessionsFailed(ErrorMessages.describe(t))
}
}
}
/**
* Reopens a closed chat so it returns to the active list. Sending another
* message also reopens it (the server clears the closed state on prompt), so
* this is the explicit path beside that one.
*/
fun reopenChatSession(sessionId: String) {
if (sessionId.isBlank()) return
viewModelScope.launch {
try {
repository.chatReopen(sessionId)
chatStore.sessionReopened(sessionId)
} catch (t: Throwable) {
if (t is CancellationException) throw t
chatStore.sessionsFailed(ErrorMessages.describe(t))
}
}
}
private fun <T> load(target: MutableStateFlow<LoadState<T>>, block: suspend () -> T) {
viewModelScope.launch {
target.value = target.value.copy(loading = true, error = null)
@@ -32,6 +32,7 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@@ -60,19 +61,27 @@ import net.awan.pipelines.ui.chat.ChatScreen
import net.awan.pipelines.ui.components.AttentionIndicator
import net.awan.pipelines.ui.components.AttentionSheet
import net.awan.pipelines.ui.components.ConnectionBanner
import net.awan.pipelines.ui.components.LocalPillBottomInset
import net.awan.pipelines.ui.components.MotionStandard
import net.awan.pipelines.ui.components.paneSafeArea
import net.awan.pipelines.ui.components.spec
import net.awan.pipelines.ui.screens.SettingsScreen
import net.awan.pipelines.ui.theme.ATTENTION_CHIP_RESERVE
import net.awan.pipelines.ui.theme.DESTINATION_PILL_RESERVE
import net.awan.pipelines.ui.theme.SPACING_L
import net.awan.pipelines.ui.theme.SPACING_S
/** One destination the floating pill holds: its nav [route], the accessible [label] and its glyph. */
internal data class TopDestination(val route: String, val label: String, val icon: ImageVector)
private val destinations = listOf(
/**
* The pill's destinations, in display order. Templates is deliberately absent: it
* is configuration, reached from the Settings page instead, so the pill holds only
* the surfaces a person moves between constantly. The pill's width derives from
* this list (its icon row), never a fixed value, so removing a destination only
* narrows it.
*/
internal val destinations = listOf(
TopDestination("pipelines", "Pipelines", Icons.Default.AccountTree),
TopDestination("templates", "Templates", TemplatesIcon),
TopDestination("runs", "Runs", Icons.Default.History),
TopDestination("chat", "Chat", Icons.AutoMirrored.Filled.Chat),
TopDestination("settings", "Settings", Icons.Default.Settings),
@@ -272,74 +281,78 @@ fun PipelinesApp(
// screens' app bars (a Material 3 TopAppBar applies the top safe-area inset),
// which removed the duplicate top band. The bottom is owned by each screen's
// Scaffold, and the floating pill explicitly clears the safe area (system
// bars, cutout, gesture area and IME) via windowInsetsPadding. The Column
// reserves DESTINATION_PILL_RESERVE at the bottom so no scrollable content is
// permanently hidden behind the pill; while the pill is hidden (an open
// conversation, see [destinationPillVisible]) that reservation is dropped too,
// so the composer sits at the true bottom instead of over an empty band.
// bars, cutout, gesture area and IME) via windowInsetsPadding.
//
// The pill is a true overlay: it is drawn in its own bottom-anchored layer over
// the content and never takes layout space, so the content keeps its full
// height. Nothing is positioned by the pill; its bottom clearance
// ([pillScrollInset], published through [LocalPillBottomInset]) is applied
// inside each scrollable screen's own scroll content, so scrolling to the end
// still reveals the last row clear of the pill, and while the pill is hidden
// (an open conversation, see [destinationPillVisible]) that clearance is zero
// so a hidden pill leaves no empty band. See [contentPillPadding].
val bannerVisible = connectionState !is ConnectionState.Connected
Scaffold(contentWindowInsets = WindowInsets(0, 0, 0, 0)) { padding ->
Box(Modifier.fillMaxSize().padding(padding)) {
Column(Modifier.fillMaxSize().padding(bottom = destinationPillReserve(pillVisible) + ATTENTION_CHIP_RESERVE)) {
ConnectionBanner(
state = connectionState,
configuredUrl = configuredUrl,
onReconnect = vm::reconnect,
)
NavHost(
navController = navController,
startDestination = "pipelines",
// 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
.weight(1f)
.then(
if (bannerVisible) {
Modifier.consumeWindowInsets(
paneSafeArea().only(WindowInsetsSides.Top),
)
} else {
Modifier
},
),
) {
composable("pipelines") {
PipelineDestination(
vm = vm,
wide = wide,
selection = pipelineSelection,
onSelectionChange = { pipelineSelection = it },
listState = pipelineListState,
onOpenRun = { runId ->
runSelection = PaneSelection(
pane = MasterPane.Detail,
itemId = runId,
)
navController.navigate("runs") { launchSingleTop = true }
},
)
}
composable("runs") {
RunsDestination(
vm = vm,
wide = wide,
selection = runSelection,
onSelectionChange = { runSelection = it },
pendingNav = runSearchNav,
onPendingNavResolved = { runSearchNav = null },
listState = runListState,
decisionRequest = decisionRequest,
onDecisionRequestHandled = { decisionRequest = null },
)
}
composable("chat") {
ChatScreen(vm = vm, wide = wide)
}
composable("templates") {
TemplatesDestination(vm = vm, wide = wide, listState = templateListState)
}
composable("settings") {
SettingsScreen(vm, wide = wide)
CompositionLocalProvider(LocalPillBottomInset provides pillScrollInset(pillVisible)) {
Column(Modifier.fillMaxSize().padding(bottom = contentPillPadding(pillVisible))) {
ConnectionBanner(
state = connectionState,
configuredUrl = configuredUrl,
onReconnect = vm::reconnect,
)
NavHost(
navController = navController,
startDestination = "pipelines",
// 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
.weight(1f)
.then(
if (bannerVisible) {
Modifier.consumeWindowInsets(
paneSafeArea().only(WindowInsetsSides.Top),
)
} else {
Modifier
},
),
) {
composable("pipelines") {
PipelineDestination(
vm = vm,
wide = wide,
selection = pipelineSelection,
onSelectionChange = { pipelineSelection = it },
listState = pipelineListState,
onOpenRun = { runId ->
runSelection = PaneSelection(
pane = MasterPane.Detail,
itemId = runId,
)
navController.navigate("runs") { launchSingleTop = true }
},
)
}
composable("runs") {
RunsDestination(
vm = vm,
wide = wide,
selection = runSelection,
onSelectionChange = { runSelection = it },
pendingNav = runSearchNav,
onPendingNavResolved = { runSearchNav = null },
listState = runListState,
decisionRequest = decisionRequest,
onDecisionRequestHandled = { decisionRequest = null },
)
}
composable("chat") {
ChatScreen(vm = vm, wide = wide)
}
composable("settings") {
SettingsDestination(vm = vm, wide = wide, listState = templateListState)
}
}
}
}
@@ -362,21 +375,29 @@ fun PipelinesApp(
// Composed after the NavHost, so while the field is open Back (button
// or gesture) dismisses the morph before any pane's own Back handler.
BackHandler(enabled = searchState.open) { dismissSearch() }
// The results panel and the destination bar share one bottom-anchored,
// inset-clearing column. `paneSafeArea` (WindowInsets.safeDrawing) is
// applied once here: the panel then takes exactly the height the IME and
// navigation bar leave (weight, `fill = false` so a short panel wraps)
// and scrolls inside it, and the input always sits directly below the
// panel and above the keyboard. The activity declares `adjustResize`
// and the app is edge-to-edge, so the Compose window inset is the only
// source of the IME geometry and it is applied once, here.
// The results panel, the attention chip and the destination bar share
// one bottom-anchored, inset-clearing column — the overlay layer, drawn
// above the content and never part of its layout. `paneSafeArea`
// (WindowInsets.safeDrawing) is applied once here, so the pill clears the
// system bars, cutout, gesture area and IME: the panel then takes exactly
// the height the IME and navigation bar leave (weight, `fill = false` so
// a short panel wraps) and scrolls inside it, and the input always sits
// directly below the panel and above the keyboard. The activity declares
// `adjustResize` and the app is edge-to-edge, so the Compose window inset
// is the only source of the IME geometry and it is applied once, here.
//
// The overlay's resting place is the window width's in [destinationPillAlignment]:
// horizontally centred on a narrow window, anchored to the bottom-right
// corner on a wide one. Its margin comes from the named [SPACING_L], so the
// corner placement adds no new number. That rule positions the pill; the
// attention chip above it keeps its own bottom-right place at every width.
Column(
modifier = Modifier
.fillMaxSize()
.windowInsetsPadding(paneSafeArea())
.padding(end = 16.dp, bottom = 16.dp),
.padding(end = if (wide) SPACING_L else 0.dp, bottom = SPACING_L),
verticalArrangement = Arrangement.Bottom,
horizontalAlignment = Alignment.End,
horizontalAlignment = destinationPillAlignment(wide),
) {
if (searchState.open) {
SearchResultsPanel(
@@ -389,13 +410,17 @@ fun PipelinesApp(
modifier = Modifier
.fillMaxWidth()
.weight(1f, fill = false)
.padding(bottom = 16.dp),
.padding(bottom = SPACING_L),
)
}
// The attention chip is not part of the pill's placement rule: it
// keeps its own bottom-right resting place at every width (as it
// had before the pill became width-dependent), so only the pill
// follows [destinationPillAlignment].
AttentionIndicator(
entries = attention,
onClick = { attentionOpen = true },
modifier = Modifier.padding(bottom = SPACING_S),
modifier = Modifier.align(Alignment.End).padding(bottom = SPACING_S),
)
// The pill stands down while a conversation is open; the search
// field it morphs into is unreachable there anyway (the field opens
@@ -469,14 +494,40 @@ internal fun destinationPillVisible(currentRoute: String?, conversationOpen: Boo
!(currentRoute == CHAT_ROUTE && conversationOpen)
/**
* The bottom space the content reserves for the pill: the named
* [DESTINATION_PILL_RESERVE] while the pill is drawn, and none while it is
* hidden, so a hidden pill leaves no empty band at the end of scrollable content
* and the composer sits at the true bottom. Derived from [pillVisible] alone, so
* the reservation and the drawn pill can never disagree into a frame with a
* drawn pill over content it does not clear, or a reserved gap behind a hidden
* one — which is what keeps the content from jumping as the pill appears and
* disappears.
* Where the bottom overlay — the destination pill and the attention chip above it
* — rests in the window: horizontally centred on a **narrow** window and anchored
* to the bottom-right **corner** on a **wide** one. The overlay is drawn above the
* content and never takes layout space either way, so this is purely where it
* sits. A pure function of the window width, so the one arrangement rule is
* unit-testable and no screen hardcodes a width.
*/
internal fun destinationPillReserve(pillVisible: Boolean): Dp =
if (pillVisible) DESTINATION_PILL_RESERVE else 0.dp
internal fun destinationPillAlignment(wide: Boolean): Alignment.Horizontal =
if (wide) Alignment.End else Alignment.CenterHorizontally
/**
* The bottom padding the app's content column applies for the pill: none, whether
* the pill is [pillVisible] or not. The pill is an overlay drawn above the
* content, so it must never size or offset it — the content keeps its own full
* height and the pill's clearance lives in each scrollable's own scroll content
* (see [pillScrollInset]). The value is a function of the drawn state (both of
* which the unit test pins at zero) rather than left implicit in an absent
* modifier, so a later change that reintroduces a reserved band here fails the
* test.
*/
internal fun contentPillPadding(pillVisible: Boolean): Dp = 0.dp
/**
* The trailing bottom space a scrollable screen keeps so its last row scrolls clear
* of the floating bottom stack — the destination pill and the attention chip above
* it — built from the named [DESTINATION_PILL_RESERVE] and [ATTENTION_CHIP_RESERVE]
* while the pill is drawn, and none while it is hidden (an open conversation, see
* [destinationPillVisible]) so a hidden pill leaves no empty band at the end of a
* list. Published to the content through `LocalPillBottomInset` and applied inside
* each scrollable's own scroll content, never as layout padding on the content. It
* is derived from [pillVisible] alone, so the clearance and the drawn pill can
* never disagree into a frame with a drawn pill over content it does not clear, or
* a reserved gap behind a hidden one — which is what keeps a list from jumping as
* the pill appears and disappears.
*/
internal fun pillScrollInset(pillVisible: Boolean): Dp =
if (pillVisible) DESTINATION_PILL_RESERVE + ATTENTION_CHIP_RESERVE else 0.dp
@@ -0,0 +1,89 @@
package net.awan.pipelines.ui
import androidx.activity.compose.PredictiveBackHandler
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Settings
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import kotlinx.coroutines.flow.collect
import net.awan.pipelines.ui.components.SlidingPaneStack
import net.awan.pipelines.ui.components.rememberPaneContent
import net.awan.pipelines.ui.screens.SettingsScreen
import net.awan.pipelines.ui.screens.TemplateDetailScreen
import net.awan.pipelines.ui.screens.TemplateGalleryScreen
/**
* The Settings destination: the same shared pane stack the other destinations
* use, with the settings page as pane 0 and the templates gallery it opens from
* its Templates row as pane 1 and the selected template's detail as pane 2.
* Templates is configuration, so it is one of the settings destinations rather
* than a floating-pill entry; the gallery is the existing [TemplateGalleryScreen]
* (and its detail the existing [TemplateDetailScreen]), so no second templates
* surface is built. Its selection is saved state, so it survives rotation,
* configuration change and process death; the covered-pane strip, the back gesture
* and the pane's own back control all step exactly one level via [settingsBack].
* Nothing here starts a run.
*/
@Composable
internal fun SettingsDestination(
vm: AppViewModel,
wide: Boolean,
listState: LazyListState,
) {
var selection by rememberSaveable(stateSaver = SettingsSelectionSaver) {
mutableStateOf(SettingsSelection())
}
val depth = selection.depth
val onBack: () -> Unit = { selection = settingsBack(selection) }
PredictiveBackHandler(enabled = depth >= 1) { progress ->
// Consume the gesture; on completion perform exactly one Back step.
progress.collect { }
onBack()
}
SlidingPaneStack(
depth = depth,
wide = wide,
onPopTo = { level -> selection = settingsPopTo(selection, level) },
compactLabel = "Settings",
compactIcon = Icons.Filled.Settings,
backContentDescription = { level ->
if (level == 0) "Back to settings" else "Back to templates"
},
pane = { level, covered, paneModifier ->
when (level) {
0 -> SettingsScreen(
vm = vm,
onOpenTemplates = { selection = openTemplatesGallery(selection) },
wide = wide,
modifier = paneModifier,
covered = covered,
)
1 -> TemplateGalleryScreen(
vm = vm,
wide = wide,
onOpen = { key -> selection = openTemplateDetail(selection, key) },
listState = listState,
modifier = paneModifier,
covered = covered,
)
2 -> rememberPaneContent(selection.templateKey)?.let { key ->
TemplateDetailScreen(
vm = vm,
templateKey = key,
onBack = onBack,
wide = wide,
modifier = paneModifier,
covered = covered,
)
}
}
},
)
}
@@ -0,0 +1,86 @@
package net.awan.pipelines.ui
import androidx.compose.runtime.saveable.Saver
/**
* Which pane of the Settings destination's sliding stack is rightmost: the
* settings page itself (level 0), the templates gallery opened from its Templates
* row (level 1) or the selected template's detail (level 2). Templates is
* configuration, so it is one of the settings destinations reached from the
* Settings page rather than an entry in the floating destination pill; modelling
* the stack here is what gives the gallery the same covered-pane strip and
* one-level Back step the other destinations use.
*/
internal enum class SettingsPane(val level: Int) {
Settings(0),
Gallery(1),
Template(2),
}
/**
* The Settings destination's saved pane selection. The only state beyond the
* rightmost pane is the open template's key, so the whole selection is
* Bundle-able primitives and survives rotation, configuration change and process
* death. Geometry (peek widths, insets) is deliberately not part of the model; it
* is derived from layout by the shared stack.
*/
internal data class SettingsSelection(
val pane: SettingsPane = SettingsPane.Settings,
val templateKey: String? = null,
) {
/** How many panes are stacked: 0 settings, 1 gallery, 2 template detail. */
val depth: Int
get() = pane.level
}
/** The Settings page's Templates row opens the gallery as its own pane. */
internal fun openTemplatesGallery(selection: SettingsSelection): SettingsSelection =
selection.copy(pane = SettingsPane.Gallery, templateKey = null)
/** A gallery card opens the selected template's detail as the next pane. */
internal fun openTemplateDetail(selection: SettingsSelection, key: String): SettingsSelection =
selection.copy(pane = SettingsPane.Template, templateKey = key)
/**
* Exactly one pane level of Back, so the back gesture, the covered strip's tap and
* the detail's own back control all step the same single level: detail → gallery →
* settings. At settings there is nothing to close and the selection is unchanged,
* so the caller lets Back leave the destination.
*/
internal fun settingsBack(selection: SettingsSelection): SettingsSelection = when (selection.pane) {
SettingsPane.Settings -> selection
SettingsPane.Gallery -> selection.copy(pane = SettingsPane.Settings, templateKey = null)
SettingsPane.Template -> selection.copy(pane = SettingsPane.Gallery, templateKey = null)
}
/**
* The selection after tapping a covered pane's strip at [level]: every pane to its
* right is closed. Level 0 closes back to the settings page, level 1 closes the
* template detail back to the gallery, and a [level] at or beyond the current
* depth is a no-op. Peeks exist only on a wide window; narrow windows use
* Back/gesture for the same one-level step.
*/
internal fun settingsPopTo(selection: SettingsSelection, level: Int): SettingsSelection = when {
level <= 0 -> SettingsSelection()
level == 1 -> selection.copy(pane = SettingsPane.Gallery, templateKey = null)
else -> selection
}
/**
* Encodes a [SettingsSelection] as Bundle-able primitives. Paired with
* [decodeSettingsSelection].
*/
internal fun encodeSettingsSelection(selection: SettingsSelection): List<Any> =
listOf(selection.pane.name, selection.templateKey ?: "")
/** Restores a [SettingsSelection] encoded by [encodeSettingsSelection]. */
internal fun decodeSettingsSelection(encoded: List<Any>): SettingsSelection = SettingsSelection(
pane = SettingsPane.valueOf(encoded[0] as String),
templateKey = (encoded[1] as String).takeIf { it.isNotEmpty() },
)
/** Saves/restores a [SettingsSelection] across configuration change and process death. */
internal val SettingsSelectionSaver: Saver<SettingsSelection, List<Any>> = Saver(
save = { encodeSettingsSelection(it) },
restore = { decodeSettingsSelection(it) },
)
@@ -1,70 +0,0 @@
package net.awan.pipelines.ui
import androidx.activity.compose.PredictiveBackHandler
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import kotlinx.coroutines.flow.collect
import net.awan.pipelines.ui.components.SlidingPaneStack
import net.awan.pipelines.ui.components.rememberPaneContent
import net.awan.pipelines.ui.screens.TemplateDetailScreen
import net.awan.pipelines.ui.screens.TemplateGalleryScreen
/**
* The Templates destination: the same shared pane stack, with the template
* gallery as pane 0 and the selected template's detail as pane 1. The selected
* template key is the saved state, so it survives rotation, configuration change
* and process death; Back/the peek pop one level. Nothing here starts a run.
*/
@Composable
internal fun TemplatesDestination(
vm: AppViewModel,
wide: Boolean,
listState: LazyListState,
) {
var selectedKey by rememberSaveable { mutableStateOf<String?>(null) }
val depth = if (selectedKey == null) 0 else 1
val onBack: () -> Unit = { selectedKey = null }
PredictiveBackHandler(enabled = depth >= 1) { progress ->
progress.collect { }
onBack()
}
SlidingPaneStack(
depth = depth,
wide = wide,
onPopTo = { level -> if (level <= 0) selectedKey = null },
compactLabel = "Templates",
compactIcon = TemplatesIcon,
backContentDescription = { level ->
if (level == 0) "Back to templates" else "Back to template"
},
pane = { level, covered, paneModifier ->
when (level) {
0 -> TemplateGalleryScreen(
vm = vm,
wide = wide,
onOpen = { key -> selectedKey = key },
listState = listState,
modifier = paneModifier,
covered = covered,
)
1 -> rememberPaneContent(selectedKey)?.let { key ->
TemplateDetailScreen(
vm = vm,
templateKey = key,
onBack = onBack,
wide = wide,
modifier = paneModifier,
covered = covered,
)
}
}
},
)
}
@@ -25,15 +25,15 @@ internal const val CHAT_COMMAND_HELP = "help"
* terminal's own vocabulary is the model here (`:status`, `:logs`, …): a command
* acts on the chat surface itself and is never sent to the agent.
*
* `/close` is shown as unavailable in this revision: the server has no request
* that finishes a session for every client yet, and the app will not pretend the
* local "remove from list" is that close.
* `/close` is the server's own close (`chat_close`, shared by every client), not
* the local "remove from list": the chat is finished for every device, its
* history is kept, and it can be reopened.
*/
internal val CHAT_COMMANDS: List<ChatCommand> = listOf(
ChatCommand(CHAT_COMMAND_NEW, "Start a fresh session in this directory", "/new"),
ChatCommand(
CHAT_COMMAND_CLOSE,
"Finish this session for every client (not available in this build)",
"Finish this session for every client, keeping its history",
"/close",
),
ChatCommand(CHAT_COMMAND_RENAME, "Rename this session on this device", "/rename <title>", takesArgument = true),
@@ -211,8 +211,3 @@ internal fun runChatSlashCommand(text: String, thread: ChatThread, host: ChatCom
is ChatCommandEffect.Report -> host.notify(effect.text, failed = true, offer = effect.offer)
}
}
/** What `/close` says in this revision, where no real session close exists. */
internal const val CHAT_CLOSE_UNAVAILABLE =
"Can't finish this session: this build has no real session close yet, so nothing was " +
"changed. The session stays open and listed; no local hide was used instead."
@@ -3,6 +3,7 @@ package net.awan.pipelines.ui.chat
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
@@ -33,6 +34,7 @@ import net.awan.pipelines.ui.AppViewModel
import net.awan.pipelines.ui.components.ErrorState
import net.awan.pipelines.ui.components.ListRow
import net.awan.pipelines.ui.components.LoadingState
import net.awan.pipelines.ui.components.pillContentPadding
import net.awan.pipelines.ui.theme.ICON_INLINE_DP
import net.awan.pipelines.ui.theme.pipelinesText
@@ -85,7 +87,10 @@ internal fun NewChatPane(
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(horizontal = CHAT_GUTTER, vertical = CHAT_ITEM_GAP),
)
LazyColumn(Modifier.weight(1f).fillMaxWidth()) {
LazyColumn(
modifier = Modifier.weight(1f).fillMaxWidth(),
contentPadding = pillContentPadding(PaddingValues()),
) {
items(choices, key = { it.createDirectory }) { choice ->
DirectoryRow(
choice = choice,
@@ -252,11 +252,20 @@ private const val OPERATOR_TAG_LABEL = "Operator"
* prompt from any client, so the session stays writable everywhere.
*/
internal fun sessionStatusLabel(session: ChatSession, runningLocally: Boolean): String =
sessionStatusLabel(runningLocally)
sessionStatusLabel(runningLocally, session.closed)
/** The status of a conversation from its own running flag (see [sessionStatusLabel]). */
internal fun sessionStatusLabel(runningLocally: Boolean): String =
if (runningLocally) "Running" else "Idle"
/**
* The status of a conversation from its own flags (see [sessionStatusLabel]).
* A closed session reads `Closed` first: it is finished, whatever a stale local
* running mark says. A session is never reported `Busy` or read-only because
* another client is watching it — the server fans the stream out and accepts a
* prompt from any client, so the session stays writable everywhere.
*/
internal fun sessionStatusLabel(runningLocally: Boolean, closed: Boolean = false): String = when {
closed -> "Closed"
runningLocally -> "Running"
else -> "Idle"
}
/**
* The activity a session row signals beyond its open/tag/directory state. An
@@ -298,7 +307,7 @@ internal data class ConversationHeader(
internal fun conversationHeader(thread: ChatThread): ConversationHeader = ConversationHeader(
title = sessionTitle(ChatSession(id = thread.sessionId, title = thread.title)),
kind = sessionTagLabel(thread.tag),
activity = sessionStatusLabel(thread.running),
activity = sessionStatusLabel(thread.running, thread.closed),
directory = thread.directory,
model = thread.model,
)
@@ -388,6 +397,19 @@ internal fun reasoningLabel(count: Int, streaming: Boolean): String = when {
else -> REASONING_SETTLED_LABEL
}
/**
* The close confirmation's body: it says exactly what closing does — stops a
* running turn, marks the chat closed on every device — and what it does not do:
* nothing is deleted, the chat and its history are kept and can be reopened. Kept
* pure so the confirmation wording and its unit test share one string instead of
* the copy drifting from the promise.
*/
internal fun closeChatConfirmation(title: String): String =
"Closes \"$title\" and marks it closed on every device. " +
"A turn that is running is stopped first. " +
"Nothing is deleted — the chat and its history are kept, " +
"and you can reopen it from the list."
/**
* The elapsed time the server's own timing gives a settled turn: from the
* earliest start to the latest completion across the parts that carry a timing
@@ -4,6 +4,7 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
@@ -55,6 +56,7 @@ import net.awan.pipelines.ui.components.LabelChip
import net.awan.pipelines.ui.components.ListRow
import net.awan.pipelines.ui.components.LoadingState
import net.awan.pipelines.ui.components.PaneIdentity
import net.awan.pipelines.ui.components.pillContentPadding
import net.awan.pipelines.ui.theme.ICON_BUTTON_SMALL_DP
import net.awan.pipelines.ui.theme.ICON_INLINE_DP
import net.awan.pipelines.ui.theme.SPACING_M
@@ -94,10 +96,12 @@ internal 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. 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.
// its order. Active sessions are grouped by directory when there is more than
// one; the closed ones the operator finished with sit below them as history.
val sessions = state.filteredSessions
val groups = groupChatSessionsByDirectory(sessions)
val active = state.activeSessions
val closed = state.closedSessions
val groups = groupChatSessionsByDirectory(active)
val query = state.sessionQuery
// A removal is reported for what it is: a local, undoable change, never a
@@ -115,6 +119,7 @@ internal fun ChatListPane(
}
}
var renaming by remember { mutableStateOf<ChatSession?>(null) }
var closing by remember { mutableStateOf<ChatSession?>(null) }
Scaffold(
modifier = modifier,
@@ -169,7 +174,10 @@ internal fun ChatListPane(
// drift hundreds of pixels from its title, the same constraint the
// other lists and detail bodies use; narrow windows fill as before.
else -> DetailTabBody(wide, Modifier.fillMaxSize()) { listModifier ->
LazyColumn(listModifier) {
LazyColumn(
modifier = listModifier,
contentPadding = pillContentPadding(PaddingValues()),
) {
if (groups.size > 1) {
// More than one directory: one section per repository so
// same-directory chats sit together, each keeping the
@@ -177,12 +185,21 @@ internal fun ChatListPane(
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 })
SessionListItem(state, session, vm, onRename = { renaming = it }, onClose = { closing = it })
}
}
} else {
items(sessions, key = { it.id }) { session ->
SessionListItem(state, session, vm, onRename = { renaming = it })
items(active, key = { it.id }) { session ->
SessionListItem(state, session, vm, onRename = { renaming = it }, onClose = { closing = it })
}
}
if (closed.isNotEmpty()) {
// Finished chats stay reachable as history: a clearly
// labelled section, in the same recency order, from which
// each one can be reopened.
item(key = "closed-header") { DirectoryHeader(CLOSED_SECTION_LABEL) }
items(closed, key = { it.id }) { session ->
SessionListItem(state, session, vm, onRename = { renaming = it }, onClose = { closing = it })
}
}
if (state.sessionsError != null) {
@@ -211,6 +228,16 @@ internal fun ChatListPane(
},
)
}
closing?.let { session ->
CloseChatDialog(
session = session,
onDismiss = { closing = null },
onConfirm = {
vm.closeChatSession(session.id)
closing = null
},
)
}
}
/**
@@ -251,17 +278,20 @@ private fun SessionListItem(
session: ChatSession,
vm: AppViewModel,
onRename: (ChatSession) -> Unit,
onClose: (ChatSession) -> Unit,
) {
val thread = state.thread(session.id)
SessionRow(
session = session,
thread = thread,
open = thread != null,
unseen = state.isUnseen(session),
unseen = !session.closed && state.isUnseen(session),
active = state.activeId == session.id,
onClick = { vm.openChatSession(session) },
onRename = { onRename(session) },
onRemove = { vm.removeChat(session.id) },
onClose = { onClose(session) },
onReopen = { vm.reopenChatSession(session.id) },
onHide = { vm.removeChat(session.id) },
)
}
@@ -295,7 +325,9 @@ private fun SessionRow(
active: Boolean,
onClick: () -> Unit,
onRename: () -> Unit,
onRemove: () -> Unit,
onClose: () -> Unit,
onReopen: () -> Unit,
onHide: () -> Unit,
) {
val texts = pipelinesText()
val running = thread?.running == true
@@ -316,10 +348,20 @@ private fun SessionRow(
// The kind chip names the session kind the server reported, so an
// operator chat is tellable from anything run-related at a glance.
sessionTagLabel(session)?.let { LabelChip(it, SPACING_S, SPACING_XXS) }
// A closed chat is named as such on the row itself, so it is never
// confused with a hide (which only affects this device) or with a
// still-open chat.
if (session.closed) LabelChip(CLOSED_CHIP_LABEL, SPACING_S, SPACING_XXS)
// The activity badge is the new-activity signal; the tag and the
// directory below are unchanged beside it.
SessionActivityBadge(activity, open)
SessionMenu(onRename = onRename, onRemove = onRemove)
SessionMenu(
closed = session.closed,
onRename = onRename,
onClose = onClose,
onReopen = onReopen,
onHide = onHide,
)
}
val meta = buildList {
add(sessionWorkLabel(session.busy, thread))
@@ -330,9 +372,19 @@ private fun SessionRow(
}
}
/** A session row's management actions: rename and remove from this device's list. */
/**
* A session row's management actions. Closing is the real, server-side finish
* (shared by every device); hiding only affects this device and is named so the
* two cannot be confused. A closed chat offers Reopen instead of Close.
*/
@Composable
private fun SessionMenu(onRename: () -> Unit, onRemove: () -> Unit) {
private fun SessionMenu(
closed: Boolean,
onRename: () -> Unit,
onClose: () -> Unit,
onReopen: () -> Unit,
onHide: () -> Unit,
) {
var expanded by remember { mutableStateOf(false) }
Box {
IconButton(onClick = { expanded = true }, modifier = Modifier.size(ICON_BUTTON_SMALL_DP)) {
@@ -350,17 +402,52 @@ private fun SessionMenu(onRename: () -> Unit, onRemove: () -> Unit) {
onRename()
},
)
if (closed) {
DropdownMenuItem(
text = { Text("Reopen") },
onClick = {
expanded = false
onReopen()
},
)
} else {
DropdownMenuItem(
text = { Text("Close chat…") },
onClick = {
expanded = false
onClose()
},
)
}
DropdownMenuItem(
text = { Text("Remove from list") },
text = { Text("Hide on this device") },
onClick = {
expanded = false
onRemove()
onHide()
},
)
}
}
}
/**
* The close confirmation. It says exactly what closing does and does not do:
* stops any running turn, keeps the whole history, and marks the chat closed for
* every device — never a delete, and distinct from the local hide.
*/
@Composable
private fun CloseChatDialog(session: ChatSession, onDismiss: () -> Unit, onConfirm: () -> Unit) {
AlertDialog(
onDismissRequest = onDismiss,
title = { Text("Close chat?") },
text = {
Text(closeChatConfirmation(sessionTitle(session)))
},
confirmButton = { TextButton(onClick = onConfirm) { Text("Close chat") } },
dismissButton = { TextButton(onClick = onDismiss) { Text("Cancel") } },
)
}
/**
* The rename dialog. The brokered protocol has no rename for a chat session, so
* the dialog says plainly that the name is kept on this device rather than
@@ -396,7 +483,13 @@ private fun RenameChatDialog(session: ChatSession, onDismiss: () -> Unit, onConf
}
/** The removal report: what happened and how to undo it. */
private const val CHAT_REMOVED_MESSAGE = "Removed from this list; the chat stays on the server."
private const val CHAT_REMOVED_MESSAGE = "Hidden on this device; the chat stays on the server."
/** The row chip and section heading for a chat the operator finished with. */
private const val CLOSED_CHIP_LABEL = "Closed"
/** The heading of the section that keeps closed chats reachable as history. */
private const val CLOSED_SECTION_LABEL = "Closed"
/** A running/busy/open indicator: a coloured dot plus a word, never colour alone. */
@Composable
@@ -5,16 +5,17 @@ import net.awan.pipelines.data.protocol.PipelinesJson
/**
* The operator's own changes to the session list, which the server has no
* request for: a chat cannot be renamed or deleted through the brokered
* protocol (there is no chat_rename/chat_delete type, and the OpenCode session
* endpoint is not exposed), so both are kept here, on the device, and applied
* over whatever the server lists.
* request for: a chat cannot be renamed through the brokered protocol (there is
* no chat_rename type), so it is kept here, on the device, and applied over
* whatever the server lists. Closing a chat and reopening it are *not* here: they
* are server-side (`chat_close`/`chat_reopen`) so every device sees them.
*
* - [titles] are local renames, keyed by session id; a renamed chat shows its
* local title and the server's title is left untouched.
* - [hidden] are sessions the operator removed from the list. Nothing is deleted
* on the server, so the removal is honest and reversible ([remove] can be
* undone with [restore]).
* - [hidden] are sessions the operator hid on this device. Nothing is deleted on
* the server, and no other device is affected, so the hide is honest and
* reversible ([remove] can be undone with [restore]). It is distinct from a
* server-side close, which marks the chat closed for every client.
*
* Kept as a serializable value so it survives a restart as one preference,
* exactly like the app's other stored settings.
@@ -71,6 +71,12 @@ data class ChatThread(
val updatedAt: Long = 0,
/** The server reports another client (or an active run) holds this session. */
val busy: Boolean = false,
/**
* The server reports this session closed: the operator finished with it. The
* conversation and its history are kept; the chat can be reopened, and sending
* another message reopens it too.
*/
val closed: Boolean = false,
val messages: List<ChatMessage> = emptyList(),
val loading: Boolean = false,
val loaded: Boolean = false,
@@ -274,6 +280,21 @@ data class ChatState(
*/
val filteredSessions: List<ChatSession>
get() = filterChatSessions(visibleSessions, sessionQuery)
/**
* The sessions still in play: [filteredSessions] without the closed ones, in
* the same recency order. The list shows these as the active conversations.
*/
val activeSessions: List<ChatSession>
get() = filteredSessions.filterNot { it.closed }
/**
* The finished sessions: [filteredSessions] the server reports as closed, in
* the same order. They are shown as history — nothing was deleted — and can be
* reopened from the list.
*/
val closedSessions: List<ChatSession>
get() = filteredSessions.filter { it.closed }
}
/**
@@ -356,6 +377,7 @@ class ChatStore(
agent = session.agent.ifBlank { thread.agent },
tag = session.tag.ifBlank { thread.tag },
busy = session.busy,
closed = session.closed,
)
}
// Fold the read state in: the active conversation is on screen, so its
@@ -457,9 +479,11 @@ class ChatStore(
}
/**
* Removes a session from the device's list and closes its conversation, if
* open. Nothing is deleted on the server — the session still exists there — so
* the removal is honest and reversible through [undoRemove].
* Hides a session on this device only and closes its conversation, if open.
* Nothing is deleted on the server — the session still exists there — and no
* other device is affected, so the hide is honest and reversible through
* [undoRemove]. It is deliberately not a "close": the server-side close (see
* [sessionClosed]) is shared by every client.
*/
fun remove(sessionId: String) {
if (sessionId.isBlank()) return
@@ -481,6 +505,44 @@ class ChatStore(
)
}
// ---- Closing and reopening (server-side, shared by every client) ---------
/**
* Records that the server closed [sessionId]: the row is marked closed with
* the server's [closedAt] and any in-flight turn is settled, because the
* server stopped it. The session is not removed from [ChatState.sessions] —
* closed chats stay listed as history.
*/
fun sessionClosed(sessionId: String, closedAt: Long) {
if (sessionId.isBlank()) return
val at = if (closedAt > 0) closedAt else now()
_state.value = _state.value.copy(
sessions = _state.value.sessions.map {
if (it.id == sessionId) it.copy(closed = true, closedAt = at) else it
},
open = _state.value.open.map {
if (it.sessionId == sessionId) setRunning(it.copy(closed = true), false) else it
},
)
}
/**
* Clears the closed state of [sessionId] — an explicit reopen, or a prompt
* that the server treated as reopening it — so the chat returns to the active
* list without a re-fetch.
*/
fun sessionReopened(sessionId: String) {
if (sessionId.isBlank()) return
_state.value = _state.value.copy(
sessions = _state.value.sessions.map {
if (it.id == sessionId) it.copy(closed = false, closedAt = 0) else it
},
open = _state.value.open.map {
if (it.sessionId == sessionId) it.copy(closed = false) else it
},
)
}
// ---- Opening / switching -------------------------------------------------
/**
@@ -506,6 +568,7 @@ class ChatStore(
agent = session.agent,
updatedAt = session.updatedAt,
busy = session.busy,
closed = session.closed,
)
_state.value = _state.value.copy(open = _state.value.open + thread, activeId = session.id, seen = seen)
return true
@@ -517,6 +580,7 @@ class ChatStore(
agent = session.agent.ifBlank { existing.agent },
tag = session.tag.ifBlank { existing.tag },
busy = session.busy,
closed = session.closed,
)
_state.value = _state.value.copy(
open = _state.value.open.map { if (it.sessionId == session.id) merged else it },
@@ -868,6 +932,7 @@ class ChatStore(
agent = session?.agent ?: "",
tag = session?.tag ?: "",
busy = session?.busy ?: false,
closed = session?.closed ?: false,
)
_state.value = _state.value.copy(open = _state.value.open + placeholder)
}
@@ -0,0 +1,53 @@
package net.awan.pipelines.ui.components
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
/**
* The floating destination pill's clearance at the bottom of the content, as the
* app shell computes it for the current window and route (see
* `pillScrollInset`). It is published around the content so a scrollable screen
* can add it to its own scroll content's bottom padding and let its last row
* scroll clear of the pill, without the pill ever taking or positioning layout
* space. Defaults to zero, so a screen composed outside the app shell (a preview,
* a test) keeps exactly its own padding.
*/
internal val LocalPillBottomInset = compositionLocalOf { 0.dp }
/**
* [base] with the floating pill's clearance added at the bottom, for a scroll
* container's `contentPadding`. It adds the clearance **inside** the scroll
* content, so the container keeps its full height and its last row can still be
* scrolled into view above the pill; it is deliberately not a layout padding on
* the container, which would shrink the viewport and hide the row behind the pill
* instead. Returns [base] unchanged when no pill is drawn.
*/
@Composable
internal fun pillContentPadding(base: PaddingValues): PaddingValues {
val inset = LocalPillBottomInset.current
if (inset == 0.dp) return base
val direction = LocalLayoutDirection.current
return PaddingValues(
start = base.calculateLeftPadding(direction),
top = base.calculateTopPadding(),
end = base.calculateRightPadding(direction),
bottom = base.calculateBottomPadding() + inset,
)
}
/**
* Adds the floating pill's clearance as bottom padding on a scrollable's **own
* content** (a `Column` inside `verticalScroll`, or any content whose end must
* clear the pill), for the cases a `LazyColumn`'s `contentPadding` cannot reach.
* Like [pillContentPadding] it is content padding, not a layout inset, so the
* container keeps its full height and only its last content scrolls clear of the
* pill. A no-op when no pill is drawn.
*/
@Composable
internal fun Modifier.pillBottomPadding(): Modifier = padding(bottom = LocalPillBottomInset.current)
@@ -32,6 +32,7 @@ import net.awan.pipelines.data.protocol.Graph
import net.awan.pipelines.ui.components.CodeBlock
import net.awan.pipelines.ui.components.collapsibleSection
import net.awan.pipelines.ui.components.copyText
import net.awan.pipelines.ui.components.pillContentPadding
import net.awan.pipelines.ui.components.rememberSectionExpansion
import net.awan.pipelines.ui.theme.ICON_INLINE_DP
import net.awan.pipelines.ui.theme.SPACING_L
@@ -71,7 +72,7 @@ internal fun PipelineSourceView(
LazyColumn(
modifier = modifier.fillMaxSize(),
contentPadding = PaddingValues(vertical = SPACING_L),
contentPadding = pillContentPadding(PaddingValues(vertical = SPACING_L)),
) {
item(key = "source-actions") {
Row(
@@ -48,6 +48,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.components.pillBottomPadding
import net.awan.pipelines.ui.STAGE_RUN_LABEL_LINES
import net.awan.pipelines.ui.displayMap
import net.awan.pipelines.ui.fileChangeLine
@@ -520,7 +521,8 @@ private fun StageDetailBody(
Column(
modifier = columnModifier
.verticalScroll(rememberScrollState())
.padding(horizontal = SPACING_L, vertical = SPACING_S),
.padding(horizontal = SPACING_L, vertical = SPACING_S)
.pillBottomPadding(),
verticalArrangement = Arrangement.spacedBy(SPACING_XS),
) {
// A run parked on this stage surfaces its decision here, at the top of
@@ -755,7 +757,8 @@ private fun StageSectionBody(
Column(
modifier = columnModifier
.verticalScroll(rememberScrollState())
.padding(horizontal = SPACING_L, vertical = SPACING_L),
.padding(horizontal = SPACING_L, vertical = SPACING_L)
.pillBottomPadding(),
verticalArrangement = Arrangement.spacedBy(SPACING_XS),
) {
KeyValueRow("Stage", GraphSemantics.nodeLabel(stageKey))
@@ -52,6 +52,7 @@ import net.awan.pipelines.ui.components.StateCrossfade
import net.awan.pipelines.ui.components.collapsibleSection
import net.awan.pipelines.ui.components.detailLoadPhase
import net.awan.pipelines.ui.components.paneSafeArea
import net.awan.pipelines.ui.components.pillContentPadding
import net.awan.pipelines.ui.components.pipelineDetailTabs
import net.awan.pipelines.ui.components.rememberPaneContent
import net.awan.pipelines.ui.formatLocalTimestamp
@@ -200,7 +201,7 @@ private fun PipelineSummaryTab(detail: PipelineDetail, wide: Boolean, modifier:
DetailTabBody(wide, modifier) { columnModifier ->
LazyColumn(
modifier = columnModifier,
contentPadding = PaddingValues(vertical = SPACING_L),
contentPadding = pillContentPadding(PaddingValues(vertical = SPACING_L)),
) {
item(key = "pipeline-summary") {
Column(
@@ -256,7 +257,7 @@ private fun PipelineGraphTab(
val text = pipelinesText()
LazyColumn(
modifier = modifier,
contentPadding = PaddingValues(vertical = SPACING_L),
contentPadding = pillContentPadding(PaddingValues(vertical = SPACING_L)),
) {
item(key = "pipeline-graph") {
Column(
@@ -55,6 +55,7 @@ import net.awan.pipelines.ui.components.StateCrossfade
import net.awan.pipelines.ui.components.animateListItem
import net.awan.pipelines.ui.components.listLoadPhase
import net.awan.pipelines.ui.components.paneSafeArea
import net.awan.pipelines.ui.components.pillContentPadding
import net.awan.pipelines.ui.components.rememberLiveNowMillis
import net.awan.pipelines.ui.formatLocalTimestamp
import net.awan.pipelines.ui.stageCountText
@@ -227,7 +228,7 @@ fun PipelineListScreen(
LazyColumn(
state = listState,
modifier = listModifier,
contentPadding = PaddingValues(vertical = SPACING_S),
contentPadding = pillContentPadding(PaddingValues(vertical = SPACING_S)),
) {
items(items, key = { it.id }) { pipeline ->
PipelineRow(
@@ -20,6 +20,7 @@ import net.awan.pipelines.ui.LoadState
import net.awan.pipelines.ui.components.CodeBlock
import net.awan.pipelines.ui.components.DetailTabBody
import net.awan.pipelines.ui.components.collapsibleSection
import net.awan.pipelines.ui.components.pillContentPadding
import net.awan.pipelines.ui.components.rememberSectionExpansion
import net.awan.pipelines.ui.theme.SPACING_L
import net.awan.pipelines.ui.theme.SPACING_S
@@ -45,7 +46,7 @@ internal fun RunEvidenceTab(
DetailTabBody(wide, modifier) { columnModifier ->
LazyColumn(
modifier = columnModifier,
contentPadding = PaddingValues(vertical = SPACING_L),
contentPadding = pillContentPadding(PaddingValues(vertical = SPACING_L)),
) {
item(key = "evidence-reload") {
Row(
@@ -10,6 +10,7 @@ import kotlinx.serialization.json.JsonElement
import net.awan.pipelines.ui.components.CodeBlock
import net.awan.pipelines.ui.components.DetailTabBody
import net.awan.pipelines.ui.components.collapsibleSection
import net.awan.pipelines.ui.components.pillContentPadding
import net.awan.pipelines.ui.components.rememberSectionExpansion
import net.awan.pipelines.ui.displayText
import net.awan.pipelines.ui.theme.SPACING_L
@@ -35,7 +36,7 @@ internal fun RunFieldSectionsTab(
DetailTabBody(wide, modifier) { columnModifier ->
LazyColumn(
modifier = columnModifier,
contentPadding = PaddingValues(vertical = SPACING_L),
contentPadding = pillContentPadding(PaddingValues(vertical = SPACING_L)),
) {
if (entries.isEmpty()) {
item(key = "$keyPrefix-empty") {
@@ -12,6 +12,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import net.awan.pipelines.data.protocol.RunDetail
import net.awan.pipelines.data.protocol.RunGraphState
import net.awan.pipelines.ui.components.pillContentPadding
import net.awan.pipelines.ui.graph.WorkflowGraph
import net.awan.pipelines.ui.theme.SPACING_L
import net.awan.pipelines.ui.theme.SPACING_S
@@ -39,7 +40,7 @@ internal fun RunGraphTab(
val timeline = remember(run.steps) { runTimeline(run.steps) }
LazyColumn(
modifier = modifier,
contentPadding = PaddingValues(vertical = SPACING_L),
contentPadding = pillContentPadding(PaddingValues(vertical = SPACING_L)),
) {
item(key = "run-graph") {
Column(
@@ -68,6 +68,7 @@ import net.awan.pipelines.ui.components.StateCrossfade
import net.awan.pipelines.ui.components.animateListItem
import net.awan.pipelines.ui.components.listLoadPhase
import net.awan.pipelines.ui.components.paneSafeArea
import net.awan.pipelines.ui.components.pillContentPadding
import net.awan.pipelines.ui.components.rememberLiveNowMillis
import net.awan.pipelines.ui.components.runStateColor
import net.awan.pipelines.ui.components.runStateOf
@@ -330,7 +331,7 @@ private fun RunHistoryContent(
LazyColumn(
state = listState,
modifier = listModifier,
contentPadding = PaddingValues(bottom = SPACING_L),
contentPadding = pillContentPadding(PaddingValues(bottom = SPACING_L)),
) {
entries.forEach { entry ->
when (entry) {
@@ -20,6 +20,7 @@ import net.awan.pipelines.ui.RUN_VIEW_TITLE_LINES
import net.awan.pipelines.ui.components.CodeBlock
import net.awan.pipelines.ui.components.DetailTabBody
import net.awan.pipelines.ui.components.KeyValueRow
import net.awan.pipelines.ui.components.pillContentPadding
import net.awan.pipelines.ui.components.StatusChip
import net.awan.pipelines.ui.components.collapsibleSection
import net.awan.pipelines.ui.components.rememberLiveNowMillis
@@ -68,7 +69,7 @@ internal fun RunSummaryTab(
DetailTabBody(wide, modifier) { columnModifier ->
LazyColumn(
modifier = columnModifier,
contentPadding = PaddingValues(vertical = SPACING_L),
contentPadding = pillContentPadding(PaddingValues(vertical = SPACING_L)),
) {
// The artifacts gallery still leads the summary, but inside one
// collapsed section: its header alone carries the run's capture
@@ -27,6 +27,7 @@ import net.awan.pipelines.data.protocol.RunDetail
import net.awan.pipelines.ui.components.ColoredChip
import net.awan.pipelines.ui.components.DetailTabBody
import net.awan.pipelines.ui.components.RunStatusIcon
import net.awan.pipelines.ui.components.pillContentPadding
import net.awan.pipelines.ui.components.runStateIcon
import net.awan.pipelines.ui.components.runStateOf
import net.awan.pipelines.ui.graph.graphColors
@@ -60,7 +61,7 @@ internal fun RunTimelineTab(
DetailTabBody(wide, modifier) { columnModifier ->
LazyColumn(
modifier = columnModifier,
contentPadding = PaddingValues(vertical = SPACING_L),
contentPadding = pillContentPadding(PaddingValues(vertical = SPACING_L)),
) {
if (timeline.entries.isEmpty()) {
item(key = "timeline-empty") {
@@ -1,9 +1,11 @@
package net.awan.pipelines.ui.screens
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
@@ -11,6 +13,8 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.filled.WarningAmber
import androidx.compose.material3.Button
import androidx.compose.material3.Card
@@ -26,18 +30,32 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import net.awan.pipelines.data.transport.ConnectionState
import net.awan.pipelines.ui.AppViewModel
import net.awan.pipelines.ui.TemplatesIcon
import net.awan.pipelines.ui.components.DetailTabBody
import net.awan.pipelines.ui.components.PaneIdentity
import net.awan.pipelines.ui.components.paneSafeArea
import net.awan.pipelines.ui.components.pillBottomPadding
import net.awan.pipelines.ui.theme.SPACING_L
import net.awan.pipelines.ui.theme.SPACING_M
import net.awan.pipelines.ui.theme.SPACING_XS
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SettingsScreen(vm: AppViewModel, modifier: Modifier = Modifier, wide: Boolean = false) {
fun SettingsScreen(
vm: AppViewModel,
onOpenTemplates: () -> Unit,
modifier: Modifier = Modifier,
wide: Boolean = false,
covered: Boolean = false,
) {
val serverUrl by vm.serverUrlDraft.collectAsStateWithLifecycle()
val workspace by vm.workspaceDraft.collectAsStateWithLifecycle()
val urlError by vm.urlError.collectAsStateWithLifecycle()
@@ -47,6 +65,17 @@ fun SettingsScreen(vm: AppViewModel, modifier: Modifier = Modifier, wide: Boolea
val configuredWorkspace by vm.configuredWorkspace.collectAsStateWithLifecycle()
val workspaceError by vm.workspaceError.collectAsStateWithLifecycle()
if (covered) {
// A covered pane shows only its compact identity, never its fields
// squeezed into the peek strip (the same rule as the other destinations).
PaneIdentity(
title = "Settings",
icon = Icons.Filled.Settings,
modifier = modifier.fillMaxSize(),
)
return
}
Scaffold(
modifier = modifier,
contentWindowInsets = paneSafeArea(),
@@ -75,6 +104,7 @@ fun SettingsScreen(vm: AppViewModel, modifier: Modifier = Modifier, wide: Boolea
onDisconnect = vm::disconnect,
onReconnect = vm::reconnect,
onSaveWorkspace = vm::saveWorkspace,
onOpenTemplates = onOpenTemplates,
)
}
}
@@ -98,15 +128,19 @@ private fun SettingsContent(
onDisconnect: () -> Unit,
onReconnect: () -> Unit,
onSaveWorkspace: () -> Unit,
onOpenTemplates: () -> Unit,
) {
// The settings body keeps the app's comfortable reading width on a wide
// window (centred) instead of letting a helper line run the whole 2000px.
// The floating pill is an overlay, so the scrolled body adds its clearance to
// its own scroll content and its last control scrolls clear of the pill.
DetailTabBody(wide, padding) { columnModifier ->
Column(
modifier = columnModifier
.verticalScroll(rememberScrollState())
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(12.dp),
.padding(SPACING_L)
.pillBottomPadding(),
verticalArrangement = Arrangement.spacedBy(SPACING_M),
) {
Text("Connection", style = MaterialTheme.typography.titleMedium)
@@ -163,6 +197,51 @@ private fun SettingsContent(
)
Button(onClick = onSaveWorkspace, enabled = workspaceError == null) { Text("Save workspace") }
Text("Saved workspace: ${configuredWorkspace.ifBlank { "(none)" }}")
Text("Templates", style = MaterialTheme.typography.titleMedium)
// The templates gallery is configuration, so it lives here rather than in
// the floating pill. The row is the settings page's idiom: a section
// label followed by a card, with a leading glyph and a forward chevron.
Card(
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.surfaceContainerHigh,
),
modifier = Modifier
.fillMaxWidth()
.clickable(
role = Role.Button,
onClickLabel = "Open templates",
onClick = onOpenTemplates,
),
) {
Row(
modifier = Modifier.fillMaxWidth().padding(SPACING_L),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(SPACING_M),
) {
Icon(
imageVector = TemplatesIcon,
contentDescription = null,
tint = MaterialTheme.colorScheme.onSurfaceVariant,
)
Column(
modifier = Modifier.weight(1f),
verticalArrangement = Arrangement.spacedBy(SPACING_XS),
) {
Text("Browse templates", style = MaterialTheme.typography.bodyLarge)
Text(
text = "Reusable pipeline definitions offered by the server.",
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
Icon(
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight,
contentDescription = null,
)
}
}
}
}
}
@@ -50,6 +50,7 @@ import net.awan.pipelines.ui.components.StateCrossfade
import net.awan.pipelines.ui.components.clampTabIndex
import net.awan.pipelines.ui.components.detailLoadPhase
import net.awan.pipelines.ui.components.paneSafeArea
import net.awan.pipelines.ui.components.pillContentPadding
import net.awan.pipelines.ui.components.pipelineDetailTabs
import net.awan.pipelines.ui.graph.PipelineSourceView
import net.awan.pipelines.ui.graph.WorkflowGraph
@@ -161,7 +162,7 @@ private fun TemplateSummaryTab(entry: TemplateEntry, wide: Boolean, modifier: Mo
DetailTabBody(wide, modifier) { columnModifier ->
LazyColumn(
modifier = columnModifier,
contentPadding = PaddingValues(vertical = SPACING_L),
contentPadding = pillContentPadding(PaddingValues(vertical = SPACING_L)),
) {
item(key = "template-summary") {
Column(
@@ -232,7 +233,7 @@ private fun TemplateGraphTab(entry: TemplateEntry, modifier: Modifier) {
}
LazyColumn(
modifier = modifier,
contentPadding = PaddingValues(vertical = SPACING_L),
contentPadding = pillContentPadding(PaddingValues(vertical = SPACING_L)),
) {
item(key = "template-graph") {
Column(
@@ -49,6 +49,7 @@ import net.awan.pipelines.ui.components.StateCrossfade
import net.awan.pipelines.ui.components.animateListItem
import net.awan.pipelines.ui.components.listLoadPhase
import net.awan.pipelines.ui.components.paneSafeArea
import net.awan.pipelines.ui.components.pillContentPadding
import net.awan.pipelines.ui.templateCard
import net.awan.pipelines.ui.templateGridColumns
import net.awan.pipelines.ui.templateStageCountLabel
@@ -151,7 +152,7 @@ private fun TemplateGrid(
LazyColumn(
state = listState,
modifier = Modifier.fillMaxSize(),
contentPadding = PaddingValues(SPACING_L),
contentPadding = pillContentPadding(PaddingValues(SPACING_L)),
verticalArrangement = Arrangement.spacedBy(SPACING_S),
) {
items(rows, key = { it.first().key }) { row ->
@@ -76,17 +76,21 @@ internal val MIN_COVERED_PANE_WIDTH_DP = 112.dp
// ---- Destination pill (ui/PipelinesApp.kt) ---------------------------------
/**
* Bottom space reserved by the floating destination pill, so content is never
* permanently hidden behind it (pill height + its margins + a small gap).
* The trailing bottom space a scrollable screen keeps at the end of its own scroll
* content so its last row is never permanently hidden behind the floating
* destination pill (pill height + its margins + a small gap). The pill itself is
* an overlay and takes no layout space; this is clearance inside the scroll
* content, applied through `LocalPillBottomInset`.
*/
internal val DESTINATION_PILL_RESERVE = 88.dp
/**
* Bottom space the floating attention chip occupies above the destination pill:
* the chip's own height (its single label line plus its vertical padding) plus the
* gap below it. Reserved at the bottom of the content whether or not a chip is
* present, so the chip can never be laid out over a row, a field or a button and
* the content does not jump as it appears and clears.
* gap below it. Added to a scrollable's trailing space alongside
* [DESTINATION_PILL_RESERVE] while the pill is drawn, so the chip can never be laid
* out over a row, a field or a button and the content does not jump as it appears
* and clears.
*/
internal val ATTENTION_CHIP_RESERVE = SPACING_XXL + SPACING_M