Open stage sections as their own pane instead of expanding inline

Expanding a stage section drew its rows stacked at the section's origin:
CollapsibleSectionBody passed the section's several field composables straight
into AnimatedVisibility, which lays out a single child, so the rows overlapped at
the top of the section and only the last was visible. The shared body now wraps
its content in one full-width Column, so any multi-row section stacks its rows
under its header.

Every stage section now opens as its own pane rather than growing the stage
screen inline:

- PaneState: add the Section pane level (MAX_PANE_DEPTH = 3) and a saved
  sectionKey primitive, with backStep/popTo/encode/decode handling so one Back or
  peek pops exactly one level and the open section survives rotation and process
  death.
- StageDetailPane: the stage screen keeps a compact collapsed list of its
  sections (Artifacts, Output, Input, This run, Stage definition); opening one
  shows it as a full-window surface over the stage on a narrow window, or a panel
  to the right of the stage pane on a wide one, with its own Scaffold/TopAppBar
  title, its own scroll and its own top spacing.
- SectionHeader: a navigation mode for those rows - a static forward chevron
  (mirrored for RTL) and an "Open <section>" action instead of a rotating
  disclosure chevron and "Expand/Collapse", so assistive tech is not told the row
  expands in place. The detail screens' disclosure rows are unchanged.
- DetailTabs: drop the rememberSectionExpansion initiallyExpanded seed, whose
  last caller was the inline stage definition.
- Tests: cover the Section level's backStep, popTo, encode/decode and depth, and
  the shared stageSectionSpecs order and blank-section cases.

Sections still start collapsed, the operator's choices still persist, and each
section's content is unchanged. android/ only; no dependency was added.

Also in this diff, from the covered-identity statistics work: PipelinesApp passes
compactStats = true on its two stacks (SlidingPaneStack's statistics flag).
This commit is contained in:
2026-10-17 01:08:29 +01:00
parent dcd58b8a3d
commit 0df0c278b0
8 changed files with 741 additions and 264 deletions
+82
View File
@@ -3840,3 +3840,85 @@ wrapping is asserted against an injected measurer, not rendered pixels; the
whole-word guarantee therefore rests on `TextMeasurer` and the drawn `Text` whole-word guarantee therefore rests on `TextMeasurer` and the drawn `Text`
using the same role and width, which is why both read `text.cardTitle` and the using the same role and width, which is why both read `text.cardTitle` and the
identity's own `SPACING_S` padding. identity's own `SPACING_S` padding.
## Stage sections open as their own pane, not inline (17 Oct 2026)
The reported stage-screen defect is reproducible and this pass fixes it by
opening every stage section as its own pane and by laying a collapsible body out
in one column. `android/` only; nothing in the Pipelines server, its Go source,
the Docker/compose files or the installer was touched, no dependency was added
and no run was started from the app.
- **The defect and its cause.** Expanding a stage section drew its rows stacked
at the top of the section: the section's content lambda emits one composable
per field (`fields.forEach { StageFieldRow(it) }`) straight into
`CollapsibleSectionBody`'s `AnimatedVisibility`. `AnimatedVisibility` lays out
a *single* child, so several siblings were placed on top of each other at the
section's origin instead of one below the next; the body took the height of its
tallest single row and showed only the last one, so the content did not sit
cleanly under — or under all of — its header.
- **Sections are panes.** The stage screen now keeps a **compact list** of its
section rows (`Artifacts`, `Output`, `Input`, `This run`, `Stage definition`)
and tapping one opens that section as the next pane of the stack — a
full-window screen over the stage on a narrow window, a panel to the stage
pane's right on a wide one — with its own `Scaffold`/`TopAppBar` named for the
section, its own scroll and its own top spacing. Back (the app bar, the gesture
or a peek) returns exactly one level, to the stage screen. `MasterPane` gained
the `Section` level (`MAX_PANE_DEPTH = 3`) and `PaneSelection.sectionKey` (a
primitive saved with the pane selection), so the open section survives rotation
and process death.
- **No trivial inline exceptions.** None of the five sections is kept inline:
each can hold an arbitrarily long value (the definition's prompt/output
contract, the input/output maps, the run evidence, the artifacts gallery), so
an inline body would both risk the layout with many rows and push the run
context off screen; one uniform rule keeps the screen predictable.
- **Rows read as navigation, not as disclosures.** The stage screen's section
rows go through the shared `SectionHeader` with `navigation = true`: the
chevron becomes the static forward arrow (`Icons.AutoMirrored.Filled
.KeyboardArrowRight`, mirrored for RTL) instead of a rotating disclosure
chevron, and the row announces as `Artifacts` with an `Open Artifacts` action
instead of `Artifacts, collapsed` / `Expand Artifacts`. Assistive tech is
therefore never told the row expands in place after it started opening a pane.
The disclosure rows (the run/pipeline detail lists) are unchanged. The
`rememberSectionExpansion` seed that existed only to start the stage pane's
definition expanded (`initiallyExpanded`) is gone with its last caller, so the
shared component no longer carries docs or a parameter for the removed inline
stage behaviour.
- **The shared body fix.** `CollapsibleSectionBody` now lays its content out in a
single full-width `Column`, so *any* collapsible section with more than one row
(it also backs the run/pipeline detail `collapsibleSection` lists) stacks its
rows under the header instead of overlapping them.
- **Semantics kept.** Sections start collapsed; the operator's choice — which
section is open, and the visit — is saved with the pane selection; and each
section's content is derived from the same pure `stageSectionSpecs`
(`stageDefinitionFields`/`runStepFields`/`evidenceFields`), so nothing shown
before is lost. The artifacts section keeps the shared
`ArtifactSelectionScaffold`.
Verification (macOS, JDK 17 from Homebrew `openjdk@17`,
`ANDROID_HOME=/Users/alan/Library/Android/sdk`, cached Gradle 8.11.1,
`--no-daemon --offline`):
- `gradle :app:testDebugUnitTest :app:assembleDebug --no-daemon --offline` →
`BUILD SUCCESSFUL` (`compileDebugKotlin` and `compileDebugUnitTestKotlin`
executed on the edited sources); the test-result XMLs aggregate to **303 tests,
0 failures, 0 errors, 0 skipped** across 34 classes (`PaneStateTest` gained the
Section-level backStep, popTo, encode/decode and depth cases;
`StageDetailSheetTest` replaced the definition-expansion seed with the
`stageSectionSpecs` order/blank-section cases). The `navigation` affordance is
Compose UI semantics, which this module has no unit harness for, so it is
covered by compilation only, not by a test.
- `app/build/outputs/apk/debug/app-debug.apk` is 18,272,941 bytes, sha256
`dccce3ca1a3c5acc724dec376709f694e11a29b68ffd85eae4d5114c4f8989a1`; it was
copied to
`~/.local/share/pipelines/data/artifacts/216/1/pipelines-debug-wip-dcd58b8.apk`
(`dcd58b8` = `git rev-parse --short HEAD`; the tree is uncommitted WIP on top
of it). `curl -sSI
http://10.0.0.249:8080/artifacts/216/1/pipelines-debug-wip-dcd58b8.apk`
returned `HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
`Content-Length: 18272941`, matching the local file's size.
Not verified in this pass: the on-device narrow/wide renders (a section opening
over the stage and returning, and the wide panel beside the stage pane) and any
screenshot of the former inline case — the brief keeps implementation
verification to the build and the unit tests, and visual review owns the device.
@@ -4,26 +4,26 @@ import androidx.compose.runtime.saveable.Saver
/** /**
* Which pane of the sliding stack is showing: the list (level 0), the selected * Which pane of the sliding stack is showing: the list (level 0), the selected
* item's detail (level 1) and, when a stage/node is open, the stage pane * item's detail (level 1), the stage/node pane (level 2) and, when a stage
* (level 2). On a wide window the panes stack left to right and share a fixed * section is opened, that section's pane (level 3). On a wide window the panes
* peek budget; on a narrow window only the topmost pane is visible and it fills * stack left to right and share a fixed peek budget; on a narrow window only the
* the window. * topmost pane is visible and it fills the window.
*/ */
enum class MasterPane { List, Detail, Stage } enum class MasterPane { List, Detail, Stage, Section }
/** /**
* The declared bound on the stack: list (0), detail (1), stage (2). The stack can * The declared bound on the stack: list (0), detail (1), stage (2), section (3).
* never grow deeper than this; selecting a different stage or list item replaces * The stack can never grow deeper than this; selecting a different stage, list
* the rightmost pane instead of pushing a new level. * item or section replaces the rightmost pane instead of pushing a new level.
*/ */
const val MAX_PANE_DEPTH = 2 const val MAX_PANE_DEPTH = 3
/** /**
* The saved pane-stack selection: which pane is rightmost, which item (0 = none), * The saved pane-stack selection: which pane is rightmost, which item (0 = none),
* its pipeline/run version, which detail section (page) is showing, and which * its pipeline/run version, which detail section (page) is showing, which
* stage/visit the stage pane is on. Every field is a primitive, so the state * stage/visit the stage pane is on and, when a stage section is open, its key.
* round-trips through a Bundle cheaply and survives rotation, configuration * Every field is a primitive, so the state round-trips through a Bundle cheaply
* change and process death. * and survives rotation, configuration change and process death.
* *
* Geometry (peek width, insets, measured pane widths) is deliberately *not* part * Geometry (peek width, insets, measured pane widths) is deliberately *not* part
* of this model; it is derived from layout so nothing is hardcoded here. * of this model; it is derived from layout so nothing is hardcoded here.
@@ -35,13 +35,15 @@ data class PaneSelection(
val sectionIndex: Int = 0, val sectionIndex: Int = 0,
val stageKey: String? = null, val stageKey: String? = null,
val stageVisit: Int = 0, val stageVisit: Int = 0,
val sectionKey: String? = null,
) { ) {
/** How many panes are stacked: 0 list, 1 detail, 2 stage. */ /** How many panes are stacked: 0 list, 1 detail, 2 stage, 3 section. */
val depth: Int val depth: Int
get() = when (pane) { get() = when (pane) {
MasterPane.List -> 0 MasterPane.List -> 0
MasterPane.Detail -> 1 MasterPane.Detail -> 1
MasterPane.Stage -> 2 MasterPane.Stage -> 2
MasterPane.Section -> 3
} }
} }
@@ -55,29 +57,39 @@ sealed interface BackResult {
} }
/** /**
* Exactly one pane level of Back. Inside the stage pane it steps back to the * Exactly one pane level of Back. Inside a stage section it steps back to the
* detail; inside the detail it steps back to the list; at the list it leaves the * stage pane; inside the stage pane it steps back to the detail; inside the
* app. Sections are navigated only by their own tab row/pager, never by Back, so * detail it steps back to the list; at the list it leaves the app. The peek tap
* the peek tap and the Back button/gesture always pop the same single level. * and the Back button/gesture therefore always pop the same single level.
*/ */
fun backStep(selection: PaneSelection): BackResult = when (selection.pane) { fun backStep(selection: PaneSelection): BackResult = when (selection.pane) {
MasterPane.List -> BackResult.Exit MasterPane.List -> BackResult.Exit
MasterPane.Detail -> BackResult.Show(PaneSelection(pane = MasterPane.List)) MasterPane.Detail -> BackResult.Show(PaneSelection(pane = MasterPane.List))
MasterPane.Stage -> BackResult.Show( MasterPane.Stage -> BackResult.Show(
selection.copy(pane = MasterPane.Detail, stageKey = null, stageVisit = 0), selection.copy(pane = MasterPane.Detail, stageKey = null, stageVisit = 0, sectionKey = null),
)
MasterPane.Section -> BackResult.Show(
selection.copy(pane = MasterPane.Stage, sectionKey = null),
) )
} }
/** /**
* The selection after tapping the peek of the pane at [level]: every pane to its * The selection after tapping the peek of the pane at [level]: every pane to its
* right is closed. Level 0 (the list) shows a bare list; level 1 shows the same * right is closed. Level 0 (the list) shows a bare list; level 1 shows the same
* item's detail with no stage; a [level] at or beyond the current depth is a * item's detail with no stage; level 2 shows the same item's stage with no
* no-op (there is nothing to its right). Peeks exist only on a wide window; * section; a [level] at or beyond the current depth is a no-op (there is nothing
* narrow windows use Back/gesture for the same one-level step. * to its right). Peeks exist only on a wide window; narrow windows use
* Back/gesture for the same one-level step.
*/ */
fun popTo(selection: PaneSelection, level: Int): PaneSelection = when { fun popTo(selection: PaneSelection, level: Int): PaneSelection = when {
level <= 0 -> PaneSelection() level <= 0 -> PaneSelection()
level == 1 -> selection.copy(pane = MasterPane.Detail, stageKey = null, stageVisit = 0) level == 1 -> selection.copy(
pane = MasterPane.Detail,
stageKey = null,
stageVisit = 0,
sectionKey = null,
)
level == 2 -> selection.copy(pane = MasterPane.Stage, sectionKey = null)
else -> selection else -> selection
} }
@@ -92,6 +104,7 @@ internal fun encodePaneSelection(selection: PaneSelection): List<Any> = listOf(
selection.sectionIndex, selection.sectionIndex,
selection.stageKey ?: "", selection.stageKey ?: "",
selection.stageVisit, selection.stageVisit,
selection.sectionKey ?: "",
) )
/** Restores a [PaneSelection] encoded by [encodePaneSelection]. */ /** Restores a [PaneSelection] encoded by [encodePaneSelection]. */
@@ -102,6 +115,7 @@ internal fun decodePaneSelection(encoded: List<Any>): PaneSelection = PaneSelect
sectionIndex = encoded[3] as Int, sectionIndex = encoded[3] as Int,
stageKey = (encoded[4] as String).takeIf { it.isNotEmpty() }, stageKey = (encoded[4] as String).takeIf { it.isNotEmpty() },
stageVisit = encoded[5] as Int, stageVisit = encoded[5] as Int,
sectionKey = (encoded[6] as String).takeIf { it.isNotEmpty() },
) )
/** /**
@@ -237,7 +237,17 @@ private fun PipelineDestination(
onPopTo = { level -> selection = popTo(selection, level) }, onPopTo = { level -> selection = popTo(selection, level) },
compactLabel = "Pipelines", compactLabel = "Pipelines",
compactIcon = Icons.Filled.AccountTree, compactIcon = Icons.Filled.AccountTree,
backContentDescription = { level -> if (level == 0) "Back to pipelines" else "Back to pipeline" }, // Every covered pane in this stack (the list, or a pipeline's detail) carries
// a statistics block, so the region is sized for it and a single covered
// pane can show the last-run and average lines rather than only counts.
compactStats = true,
backContentDescription = { level ->
when (level) {
0 -> "Back to pipelines"
1 -> "Back to pipeline"
else -> "Back to stage"
}
},
pane = { level, covered, paneModifier -> pane = { level, covered, paneModifier ->
when (level) { when (level) {
0 -> PipelineListScreen( 0 -> PipelineListScreen(
@@ -281,6 +291,33 @@ private fun PipelineDestination(
pipelineId = itemId, pipelineId = itemId,
version = version, version = version,
stageKey = key, stageKey = key,
openSection = null,
onOpenSection = { sectionKey ->
selection = selection.copy(
pane = MasterPane.Section,
sectionKey = sectionKey,
)
},
onBack = onBack,
wide = wide,
modifier = paneModifier,
covered = covered,
)
}
3 -> rememberPaneContent(
selection.sectionKey?.let {
Triple(selection.itemId, it, selection.stageKey)
},
)?.let { (itemId, sectionKey, key) ->
// A closing section pane keeps the identity that opened it, so
// it renders its content until it is fully off-screen.
PipelineStagePane(
vm = vm,
pipelineId = itemId,
version = selection.itemVersion,
stageKey = key.orEmpty(),
openSection = sectionKey,
onOpenSection = {},
onBack = onBack, onBack = onBack,
wide = wide, wide = wide,
modifier = paneModifier, modifier = paneModifier,
@@ -319,7 +356,18 @@ private fun RunsDestination(
onPopTo = { level -> onSelectionChange(popTo(selection, level)) }, onPopTo = { level -> onSelectionChange(popTo(selection, level)) },
compactLabel = "Runs", compactLabel = "Runs",
compactIcon = Icons.Filled.History, compactIcon = Icons.Filled.History,
backContentDescription = { level -> if (level == 0) "Back to runs" else "Back to run" }, // Every covered pane in this stack (the runs list, or a run's detail) carries
// a statistics block, so the region is sized for it and the runs list's
// counts and most-recent run are actually shown rather than dropped by the
// title-only tier.
compactStats = true,
backContentDescription = { level ->
when (level) {
0 -> "Back to runs"
1 -> "Back to run"
else -> "Back to stage"
}
},
pane = { level, covered, paneModifier -> pane = { level, covered, paneModifier ->
when (level) { when (level) {
0 -> RunHistoryScreen( 0 -> RunHistoryScreen(
@@ -359,6 +407,34 @@ private fun RunsDestination(
runId = itemId, runId = itemId,
stageKey = key, stageKey = key,
visitIndex = visit, visitIndex = visit,
openSection = null,
onOpenSection = { sectionKey ->
onSelectionChange(
selection.copy(pane = MasterPane.Section, sectionKey = sectionKey),
)
},
onVisitChange = { onSelectionChange(selection.copy(stageVisit = it)) },
onBack = onBack,
wide = wide,
modifier = paneModifier,
covered = covered,
)
}
3 -> rememberPaneContent(
selection.sectionKey?.let {
Triple(selection.itemId, it, selection.stageKey)
},
)?.let { (itemId, sectionKey, key) ->
// A closing section pane keeps the identity that opened it, so
// it renders its content until it is fully off-screen.
RunStagePane(
vm = vm,
runId = itemId,
stageKey = key.orEmpty(),
visitIndex = selection.stageVisit,
openSection = sectionKey,
onOpenSection = {},
onVisitChange = { onSelectionChange(selection.copy(stageVisit = it)) },
onBack = onBack, onBack = onBack,
wide = wide, wide = wide,
modifier = paneModifier, modifier = paneModifier,
@@ -245,13 +245,9 @@ fun DetailTabBody(
/** /**
* Remembers which inner sections are expanded, keyed by their stable section * Remembers which inner sections are expanded, keyed by their stable section
* key and saved across configuration changes. Sections start collapsed unless * key and saved across configuration changes. Sections start collapsed; the
* [initiallyExpanded] names some, which only a screen whose sections would
* otherwise read as empty does (see the pipeline stage pane's definition); the
* operator's own expand/collapse choices are then persisted (as an [ArrayList] * operator's own expand/collapse choices are then persisted (as an [ArrayList]
* a Bundle can hold). [initiallyExpanded] participates in the save key, so a pane * a Bundle can hold).
* switching between run and definition contexts reseeds rather than inheriting
* the other context's choices.
*/ */
@Stable @Stable
class SectionExpansionState internal constructor( class SectionExpansionState internal constructor(
@@ -270,12 +266,9 @@ private val expandedKeysSaver: Saver<Set<String>, ArrayList<String>> = Saver(
) )
@Composable @Composable
fun rememberSectionExpansion( fun rememberSectionExpansion(vararg inputs: Any?): SectionExpansionState {
vararg inputs: Any?, val expanded = rememberSaveable(*inputs, stateSaver = expandedKeysSaver) {
initiallyExpanded: Set<String> = emptySet(), mutableStateOf(emptySet())
): SectionExpansionState {
val expanded = rememberSaveable(*inputs, initiallyExpanded, stateSaver = expandedKeysSaver) {
mutableStateOf(initiallyExpanded)
} }
return remember(expanded) { SectionExpansionState(expanded) } return remember(expanded) { SectionExpansionState(expanded) }
} }
@@ -16,6 +16,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
import androidx.compose.material.icons.filled.KeyboardArrowDown import androidx.compose.material.icons.filled.KeyboardArrowDown
import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
@@ -38,20 +39,25 @@ import net.awan.pipelines.ui.theme.SPACING_S
import net.awan.pipelines.ui.theme.pipelinesText import net.awan.pipelines.ui.theme.pipelinesText
/** /**
* The one collapsible section header shared by both detail screens: the section * The one section header shared by both detail screens and the stage screen's
* title in the theme's section-header style, a trailing chevron that rotates * compact section list: the section title in the theme's section-header style, a
* with the state (animated, no jump cut), an opaque background so content * trailing chevron, an opaque background so content passing underneath a stuck
* passing underneath a stuck header stays readable, and a subtle divider. * header stays readable, and a subtle divider.
*
* [navigation] distinguishes the two behaviours the same row shape carries. A
* disclosure row (the default) toggles [expanded], its chevron rotates with the
* state (animated, no jump cut) and it reads as e.g. "Steps, expanded" with an
* "Expand Steps"/"Collapse Steps" action. A navigation row ([navigation] true)
* opens the section as its own pane instead: [expanded] is ignored, the chevron
* is the static forward arrow (mirrored for RTL) and it reads as "Steps" with an
* "Open Steps" action, so assistive tech is never told the row expands in place
* when it actually opens a surface of its own.
* *
* [containerColor] is the opaque colour the header covers with. It defaults to * [containerColor] is the opaque colour the header covers with. It defaults to
* the screen background so a stuck header on an ordinary page hides the content * the screen background so a stuck header on an ordinary page hides the content
* scrolling under it; a caller whose surface is a different container (the stage * scrolling under it; a caller whose surface is a different container (the stage
* pane) passes that same colour so the header never reads as a differently toned * pane) passes that same colour so the header never reads as a differently toned
* band across its pane. * band across its pane.
*
* Accessibility is exposed without relying on the chevron: the header is a
* single button node described as e.g. "Steps, expanded" and carries the
* `expanded`/`collapsed` state.
*/ */
@Composable @Composable
fun SectionHeader( fun SectionHeader(
@@ -60,12 +66,19 @@ fun SectionHeader(
onToggle: () -> Unit, onToggle: () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
containerColor: Color = MaterialTheme.colorScheme.background, containerColor: Color = MaterialTheme.colorScheme.background,
navigation: Boolean = false,
) { ) {
val rotation = animateFloatAsState( // Only a disclosure row animates its chevron; a navigation row shows the
targetValue = if (expanded) 0f else -90f, // static forward arrow, so no animator is composed for it.
animationSpec = MotionQuick.spec(), val rotation = if (navigation) {
label = "section-chevron", null
) } else {
animateFloatAsState(
targetValue = if (expanded) 0f else -90f,
animationSpec = MotionQuick.spec(),
label = "section-chevron",
)
}
Column( Column(
modifier = modifier modifier = modifier
.fillMaxWidth() .fillMaxWidth()
@@ -73,11 +86,20 @@ fun SectionHeader(
.background(containerColor) .background(containerColor)
.clickable(role = Role.Button, onClick = onToggle) .clickable(role = Role.Button, onClick = onToggle)
.clearAndSetSemantics { .clearAndSetSemantics {
contentDescription = "$title, ${if (expanded) "expanded" else "collapsed"}" if (navigation) {
role = Role.Button contentDescription = title
onClick(label = if (expanded) "Collapse $title" else "Expand $title") { role = Role.Button
onToggle() onClick(label = "Open $title") {
true onToggle()
true
}
} else {
contentDescription = "$title, ${if (expanded) "expanded" else "collapsed"}"
role = Role.Button
onClick(label = if (expanded) "Collapse $title" else "Expand $title") {
onToggle()
true
}
} }
}, },
) { ) {
@@ -96,11 +118,19 @@ fun SectionHeader(
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),
) )
Icon( Icon(
imageVector = Icons.Default.KeyboardArrowDown, imageVector = if (navigation) {
Icons.AutoMirrored.Filled.KeyboardArrowRight
} else {
Icons.Default.KeyboardArrowDown
},
contentDescription = null, contentDescription = null,
// Read the animating angle inside the layer so the chevron turns // Read the animating angle inside the layer so the chevron turns
// without recomposing the header on every frame. // without recomposing the header on every frame.
modifier = Modifier.graphicsLayer { rotationZ = rotation.value }, modifier = if (rotation != null) {
Modifier.graphicsLayer { rotationZ = rotation.value }
} else {
Modifier
},
) )
} }
HorizontalDivider(color = MaterialTheme.colorScheme.outlineVariant) HorizontalDivider(color = MaterialTheme.colorScheme.outlineVariant)
@@ -115,6 +145,13 @@ fun SectionHeader(
* section does no work and the resting layout is the collapsed header alone. * section does no work and the resting layout is the collapsed header alone.
* With animations disabled Compose maps the platform animator duration scale * With animations disabled Compose maps the platform animator duration scale
* onto the specs, so the body is at its final state at once. * onto the specs, so the body is at its final state at once.
*
* [content] is laid out in a single full-width [Column]: [AnimatedVisibility]
* measures *one* child, so several composables emitted straight into the body
* would be stacked on top of each other at the section's top instead of under
* their header (the "renders oddly at the top of the section" defect). The
* wrapper gives the transition exactly one child and lets a section hold any
* number of rows.
*/ */
@Composable @Composable
fun CollapsibleSectionBody( fun CollapsibleSectionBody(
@@ -130,7 +167,7 @@ fun CollapsibleSectionBody(
fadeOut(animationSpec = MotionQuick.spec()), fadeOut(animationSpec = MotionQuick.spec()),
modifier = modifier, modifier = modifier,
) { ) {
content() Column(Modifier.fillMaxWidth()) { content() }
} }
} }
@@ -18,6 +18,7 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.PrimaryScrollableTabRow import androidx.compose.material3.PrimaryScrollableTabRow
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.Tab import androidx.compose.material3.Tab
import androidx.compose.material3.Text import androidx.compose.material3.Text
@@ -25,10 +26,7 @@ import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.heading import androidx.compose.ui.semantics.heading
import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.semantics
@@ -43,14 +41,11 @@ import net.awan.pipelines.data.protocol.Stage
import net.awan.pipelines.data.protocol.edges import net.awan.pipelines.data.protocol.edges
import net.awan.pipelines.ui.AppViewModel import net.awan.pipelines.ui.AppViewModel
import net.awan.pipelines.ui.components.CodeBlock import net.awan.pipelines.ui.components.CodeBlock
import net.awan.pipelines.ui.components.CollapsibleSectionBody
import net.awan.pipelines.ui.components.DetailTabBody import net.awan.pipelines.ui.components.DetailTabBody
import net.awan.pipelines.ui.components.KeyValueRow import net.awan.pipelines.ui.components.KeyValueRow
import net.awan.pipelines.ui.components.PaneIdentity import net.awan.pipelines.ui.components.PaneIdentity
import net.awan.pipelines.ui.components.SectionExpansionState
import net.awan.pipelines.ui.components.SectionHeader import net.awan.pipelines.ui.components.SectionHeader
import net.awan.pipelines.ui.components.paneSafeArea import net.awan.pipelines.ui.components.paneSafeArea
import net.awan.pipelines.ui.components.rememberSectionExpansion
import net.awan.pipelines.ui.displayMap import net.awan.pipelines.ui.displayMap
import net.awan.pipelines.ui.fileChangeLine import net.awan.pipelines.ui.fileChangeLine
import net.awan.pipelines.ui.fileChangesSummary import net.awan.pipelines.ui.fileChangesSummary
@@ -169,7 +164,7 @@ internal fun headlineFields(fields: List<StageField>): List<StageField> =
internal fun evidenceFields(fields: List<StageField>): List<StageField> = internal fun evidenceFields(fields: List<StageField>): List<StageField> =
fields.filter { it.label !in STAGE_HEADLINE_LABELS && it.label != "Input" && it.label != "Output" } fields.filter { it.label !in STAGE_HEADLINE_LABELS && it.label != "Input" && it.label != "Output" }
/** The section key of the one stage-definition section (expansion is saved on it). */ /** The section key of the one stage-definition section, addressable by the pane selection. */
internal const val STAGE_DEFINITION_KEY = "definition" internal const val STAGE_DEFINITION_KEY = "definition"
/** The stage-definition section's title, naming clearly what it holds. */ /** The stage-definition section's title, naming clearly what it holds. */
@@ -185,24 +180,16 @@ internal const val STAGE_DEFINITION_TITLE = "Stage definition"
@Composable @Composable
internal fun paneContainerColor() = MaterialTheme.colorScheme.surfaceContainer internal fun paneContainerColor() = MaterialTheme.colorScheme.surfaceContainer
/**
* Whether the stage-definition section starts expanded. It is the only content of
* a pane opened without a run context (a pipeline's own stage definition, see
* [PipelineStagePane]), and starts collapsed in a run pane, where the run's
* results lead and the definition sits at the bottom. An operator's own
* expand/collapse choice is still remembered on top of this default.
*/
internal fun definitionStartsExpanded(runContext: Boolean): Boolean = !runContext
/** /**
* One run-side result section of the stage pane. The order is the operator's * One run-side result section of the stage pane. The order is the operator's
* stated preference: the artifacts gallery first, then the output the stage * stated preference: the artifacts gallery first, then the output the stage
* produced for that visit, then the input it received. * produced for that visit, then the input it received. [title] is the section's
* own visible name (its pane's title and its row on the stage screen).
*/ */
internal enum class StageResultSection(val key: String) { internal enum class StageResultSection(val key: String, val title: String) {
Artifacts("artifacts"), Artifacts("artifacts", "Artifacts"),
Output("output"), Output("output", "Output"),
Input("input"), Input("input", "Input"),
} }
/** The run-side result sections, in display order (the artifacts gallery first). */ /** The run-side result sections, in display order (the artifacts gallery first). */
@@ -212,6 +199,74 @@ internal val STAGE_RESULT_SECTIONS: List<StageResultSection> = listOf(
StageResultSection.Input, StageResultSection.Input,
) )
/** The evidence section key/title ("This run" holds the remaining run evidence). */
internal const val STAGE_EVIDENCE_KEY = "run"
internal const val STAGE_EVIDENCE_TITLE = "This run"
/**
* One section of the stage screen: its stable [key] (what the pane selection and
* the section pane address it by), its own [title], the [fields] it shows when it
* is a plain field section, and [artifacts] when it is the per-visit gallery
* (which renders the shared [ArtifactsSection] instead of [fields]).
*/
internal data class StageSectionSpec(
val key: String,
val title: String,
val fields: List<StageField> = emptyList(),
val artifacts: Boolean = false,
)
/**
* The ordered sections of the stage screen for one stage and visit: a run pane
* leads with the visit's Artifacts gallery, then Output, Input and the remaining
* evidence (`This run`); the stage's own definition is the last section in both
* contexts and the only section when there is no run. Blank field sections are
* skipped; the artifacts section always shows for a reached visit, even when the
* visit recorded none, so the operator always finds the gallery. Pure, so the
* compact stage screen's list and the section pane's content are derived from
* exactly the same spec.
*/
internal fun stageSectionSpecs(
stageKey: String,
graph: Graph,
runSteps: List<RunStep>,
visitIndex: Int,
runContext: Boolean,
): List<StageSectionSpec> {
val specs = ArrayList<StageSectionSpec>()
val stage = graph.stages.firstOrNull { it.key == stageKey }
val definition = stage?.let(::stageDefinitionFields) ?: terminalFields(graph, stageKey)
val selectedStep = runSteps.getOrNull(clampVisitIndex(visitIndex, runSteps.size))
if (runContext && selectedStep != null) {
val runFields = runStepFields(selectedStep)
STAGE_RESULT_SECTIONS.forEach { section ->
when (section) {
StageResultSection.Artifacts -> specs += StageSectionSpec(
key = section.key,
title = section.title,
artifacts = true,
)
StageResultSection.Output -> {
val fields = runFields.filter { it.label == "Output" }
if (fields.isNotEmpty()) specs += StageSectionSpec(section.key, section.title, fields)
}
StageResultSection.Input -> {
val fields = runFields.filter { it.label == "Input" }
if (fields.isNotEmpty()) specs += StageSectionSpec(section.key, section.title, fields)
}
}
}
val evidence = evidenceFields(runFields)
if (evidence.isNotEmpty()) {
specs += StageSectionSpec(STAGE_EVIDENCE_KEY, STAGE_EVIDENCE_TITLE, evidence)
}
}
if (definition.isNotEmpty()) {
specs += StageSectionSpec(STAGE_DEFINITION_KEY, STAGE_DEFINITION_TITLE, definition)
}
return specs
}
/** /**
* The pure run view of one [RunStep] for the selected stage: status, outcome, * The pure run view of one [RunStep] for the selected stage: status, outcome,
* duration, visit against the control's max_visits, target, session id, * duration, visit against the control's max_visits, target, session id,
@@ -301,17 +356,19 @@ internal fun clampVisitIndex(index: Int, visitCount: Int): Int =
internal fun showVisitTabs(visitCount: Int): Boolean = visitCount > 1 internal fun showVisitTabs(visitCount: Int): Boolean = visitCount > 1
/** /**
* The stage pane's content: opened as the rightmost level of the sliding stack * The stage screen: the pane shown when no section is open. It carries its own
* from a timeline entry or a graph node, exactly like the list and detail panes, * Scaffold/[TopAppBar] with a back arrow that pops one level (the same step as
* so there is no popup anywhere. It carries its own Scaffold/[TopAppBar] with a * the peek tap and system Back), leads with the run-side headline, and keeps a
* back arrow that pops one level (the same step as the peek tap and system Back). * **compact list of the stage's sections**: tapping a section opens it as its own
* pane ([StageSectionPane]) rather than growing this screen inline.
* *
* [runSteps] is every recorded visit of the stage in order; when there is more * [runSteps] is every recorded visit of the stage in order; when there is more
* than one the pane shows a visit tab row (visit 1..N) and starts on * than one the pane shows a visit tab row (visit 1..N) and reports the chosen
* [initialVisitIndex] (the tapped timeline entry, or the most recent visit when * visit through [onVisitIndexChange]. The selection is owned by the caller (part
* opened from the graph). A stage the run never reached has no run section; the * of the saved pane selection), so this screen and the section pane always agree
* identity heading and type always show, so a freshly opened pane never reads as * and it survives rotation. A stage the run never reached lists only its
* empty. * definition; the identity heading and type always show, so a freshly opened
* pane never reads as empty.
*/ */
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
@@ -319,9 +376,9 @@ fun StageDetailPane(
stageKey: String, stageKey: String,
graph: Graph, graph: Graph,
runSteps: List<RunStep> = emptyList(), runSteps: List<RunStep> = emptyList(),
initialVisitIndex: Int = 0, visitIndex: Int = 0,
configuredServerUrl: String = "", onVisitIndexChange: (Int) -> Unit = {},
fetchArtifactBytes: suspend (String) -> ByteArray? = { null }, onOpenSection: (String) -> Unit = {},
onBack: () -> Unit, onBack: () -> Unit,
wide: Boolean = false, wide: Boolean = false,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
@@ -340,32 +397,10 @@ fun StageDetailPane(
) )
return return
} }
Scaffold(
// The selected visit is owned here so the selection's copy/share actions in
// the top bar and the body's per-visit artifacts section read the same step.
// Reset when the stage changes; saved across configuration.
var visitIndex by rememberSaveable(stageKey) {
mutableIntStateOf(clampVisitIndex(initialVisitIndex, runSteps.size))
}
val clampedVisit = clampVisitIndex(visitIndex, runSteps.size)
val selectedStep = runSteps.getOrNull(clampedVisit)
val visitArtifacts = remember(selectedStep) { selectedStep?.artifacts.orEmpty() }
// The artifact selection for this visit: a long-press enters it, a tap
// toggles. Keyed on the visit, so switching visits leaves selection mode; it
// restores fully (or not at all) after rotation.
val selectionState = rememberArtifactSelection(stageKey, clampedVisit)
// The shared selection host owns the selection, the contextual bar, the bulk
// copy/share actions and Back-leaves-selection-first; the two artifact
// surfaces go through it so they can never drift.
ArtifactSelectionScaffold(
selectionState = selectionState,
candidates = visitArtifacts,
configuredServerUrl = configuredServerUrl,
fetchArtifactBytes = fetchArtifactBytes,
modifier = modifier, modifier = modifier,
containerColor = paneContainerColor(), containerColor = paneContainerColor(),
contentWindowInsets = paneSafeArea(),
topBar = { topBar = {
TopAppBar( TopAppBar(
title = { Text(GraphSemantics.nodeLabel(stageKey)) }, title = { Text(GraphSemantics.nodeLabel(stageKey)) },
@@ -378,68 +413,47 @@ fun StageDetailPane(
colors = TopAppBarDefaults.topAppBarColors(containerColor = paneContainerColor()), colors = TopAppBarDefaults.topAppBarColors(containerColor = paneContainerColor()),
) )
}, },
) { selection, onSelectionChange, padding -> ) { padding ->
StageDetailBody( StageDetailBody(
stageKey = stageKey, stageKey = stageKey,
graph = graph, graph = graph,
runSteps = runSteps, runSteps = runSteps,
selectedStep = selectedStep, visitIndex = visitIndex,
visitIndex = clampedVisit, onVisitIndexChange = onVisitIndexChange,
onVisitIndexChange = { visitIndex = it }, onOpenSection = onOpenSection,
configuredServerUrl = configuredServerUrl,
fetchArtifactBytes = fetchArtifactBytes,
wide = wide, wide = wide,
runContext = runContext, runContext = runContext,
selection = selection,
onSelectionChange = onSelectionChange,
modifier = Modifier.padding(padding), modifier = Modifier.padding(padding),
) )
} }
} }
/** The stage detail's content, wrapped by [StageDetailPane]. */ /** The stage screen's content, wrapped by [StageDetailPane]. */
@OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
private fun StageDetailBody( private fun StageDetailBody(
stageKey: String, stageKey: String,
graph: Graph, graph: Graph,
runSteps: List<RunStep>, runSteps: List<RunStep>,
selectedStep: RunStep?,
visitIndex: Int, visitIndex: Int,
onVisitIndexChange: (Int) -> Unit, onVisitIndexChange: (Int) -> Unit,
configuredServerUrl: String, onOpenSection: (String) -> Unit,
fetchArtifactBytes: suspend (String) -> ByteArray?,
wide: Boolean, wide: Boolean,
runContext: Boolean, runContext: Boolean,
selection: ArtifactSelection,
onSelectionChange: (ArtifactSelection) -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
val text = pipelinesText() val text = pipelinesText()
val stage = graph.stages.firstOrNull { it.key == stageKey } val stage = graph.stages.firstOrNull { it.key == stageKey }
val definition = remember(stage, graph, stageKey) {
stage?.let(::stageDefinitionFields) ?: terminalFields(graph, stageKey)
}
val typeLabel = if (stage != null) effectiveStageType(stage.type) else "terminal" val typeLabel = if (stage != null) effectiveStageType(stage.type) else "terminal"
val clampedVisit = clampVisitIndex(visitIndex, runSteps.size) val clampedVisit = clampVisitIndex(visitIndex, runSteps.size)
// Derived once per selected step, not per recomposition. Only the run-side val selectedStep = runSteps.getOrNull(clampedVisit)
// facts lead the pane; the stage's own configs stay in the definition section. // The run-side headline: always visible, never behind a section, so a freshly
// opened screen never reads as empty.
val runFields = remember(selectedStep) { selectedStep?.let(::runStepFields).orEmpty() } val runFields = remember(selectedStep) { selectedStep?.let(::runStepFields).orEmpty() }
val headline = headlineFields(runFields) val headline = headlineFields(runFields)
val inputFields = remember(runFields) { runFields.filter { it.label == "Input" } } val sections = remember(stageKey, graph, runSteps, clampedVisit, runContext) {
val outputFields = remember(runFields) { runFields.filter { it.label == "Output" } } stageSectionSpecs(stageKey, graph, runSteps, clampedVisit, runContext)
val evidence = evidenceFields(runFields) }
// The stage definition is the only content of a pane without a run context,
// so it starts expanded there and collapsed at the bottom of a run pane.
val expansion = rememberSectionExpansion(
stageKey,
initiallyExpanded = if (definitionStartsExpanded(runContext)) {
setOf(STAGE_DEFINITION_KEY)
} else {
emptySet()
},
)
DetailTabBody(wide, modifier) { columnModifier -> DetailTabBody(wide, modifier) { columnModifier ->
Column( Column(
@@ -454,106 +468,237 @@ private fun StageDetailBody(
modifier = Modifier.semantics { heading() }, modifier = Modifier.semantics { heading() },
) )
StageTypeChip(typeLabel) StageTypeChip(typeLabel)
if (showVisitTabs(runSteps.size)) { StageVisitTabs(runSteps.size, clampedVisit, onVisitIndexChange)
PrimaryScrollableTabRow(
selectedTabIndex = clampedVisit,
edgePadding = 0.dp,
containerColor = paneContainerColor(),
modifier = Modifier.fillMaxWidth().padding(top = SPACING_S),
) {
runSteps.forEachIndexed { index, _ ->
Tab(
selected = index == clampedVisit,
onClick = { onVisitIndexChange(index) },
text = { Text("visit ${index + 1}", maxLines = 1) },
)
}
}
}
// Identity and result: always visible, never behind a collapse, so a
// freshly opened pane never reads as empty.
headline.forEach { field -> StageFieldRow(field) } headline.forEach { field -> StageFieldRow(field) }
if (headline.isEmpty() && selectedStep == null && stage == null && definition.isEmpty()) { if (headline.isEmpty() && selectedStep == null && stage == null && sections.isEmpty()) {
Text("No details recorded for this node.", style = text.meta) Text("No details recorded for this node.", style = text.meta)
} }
// A run pane leads with the run's results: the artifacts gallery // The compact list of sections: each row opens that section as its own
// first, then the output and the input, then the remaining evidence. // pane instead of growing this screen inline (which stacked a section's
if (runContext && selectedStep != null) { // several rows at the top of its header). The row is a navigation row,
STAGE_RESULT_SECTIONS.forEach { section -> // so it reads as "Open Artifacts" with a forward chevron rather than an
when (section) { // in-place "Expand Artifacts"/collapsed disclosure.
StageResultSection.Artifacts -> StageSection(expansion, section.key) { sections.forEach { section ->
ArtifactsSection( SectionHeader(
step = selectedStep, title = section.title,
configuredServerUrl = configuredServerUrl, expanded = false,
fetchArtifactBytes = fetchArtifactBytes, onToggle = { onOpenSection(section.key) },
selection = selection, containerColor = paneContainerColor(),
onSelectionChange = onSelectionChange, navigation = true,
) )
}
StageResultSection.Output -> if (outputFields.isNotEmpty()) {
StageSection(expansion, section.key) {
outputFields.forEach { StageFieldRow(it) }
}
}
StageResultSection.Input -> if (inputFields.isNotEmpty()) {
StageSection(expansion, section.key) {
inputFields.forEach { StageFieldRow(it) }
}
}
}
}
if (evidence.isNotEmpty()) {
StageSection(expansion, "run", "This run") {
evidence.forEach { field -> StageFieldRow(field) }
}
}
}
// The stage's own definition sits in one clearly named section: it is
// the pane's only content without a run context (so it starts
// expanded) and the collapsed last section of a run pane.
if (definition.isNotEmpty()) {
StageSection(expansion, STAGE_DEFINITION_KEY, STAGE_DEFINITION_TITLE) {
definition.forEach { field -> StageFieldRow(field) }
}
} }
} }
} }
} }
/** /**
* One collapsible section of the stage pane: its header toggles [expansion] * The shared visit tab row: rendered only when [visitCount] is more than one, so
* under [key] and its body animates open/closed with the shared * a single-visit stage never shows a pointless one-tab row. Both the stage screen
* [CollapsibleSectionBody], so the content and the chevron move together. The * and a run-section pane use it, so a visit always reads the same way.
* title defaults to the capitalised key (e.g. `artifacts` → `Artifacts`), so the
* pane names every section the same way.
*/ */
@OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
private fun StageSection( internal fun StageVisitTabs(
expansion: SectionExpansionState, visitCount: Int,
key: String, selectedIndex: Int,
title: String = key.capitalized(), onSelect: (Int) -> Unit,
content: @Composable () -> Unit, modifier: Modifier = Modifier,
) { ) {
val expanded = expansion.isExpanded(key) if (!showVisitTabs(visitCount)) return
SectionHeader( PrimaryScrollableTabRow(
title, selectedTabIndex = selectedIndex,
expanded, edgePadding = 0.dp,
{ expansion.toggle(key) },
containerColor = paneContainerColor(), containerColor = paneContainerColor(),
) modifier = modifier.fillMaxWidth().padding(top = SPACING_S),
CollapsibleSectionBody(expanded) { content() } ) {
repeat(visitCount) { index ->
Tab(
selected = index == selectedIndex,
onClick = { onSelect(index) },
text = { Text("visit ${index + 1}", maxLines = 1) },
)
}
}
} }
/** The stage pane hosted directly by the run destination, reading the run detail. */ /**
* One stage section opened as its own pane: its own Scaffold/[TopAppBar] titled
* with the section's own name, its own scroll and its own top spacing, so the
* content always sits cleanly under its header. It is the section level of the
* sliding stack (a full-window screen over the stage on a narrow window, a panel
* to the stage pane's right on a wide one); Back — the app bar, system Back or
* the peek — pops exactly one level, back to the stage.
*
* The artifacts section keeps the shared [ArtifactSelectionScaffold], so its
* gallery retains long-press selection, the contextual bar and
* Back-leaves-selection-first; every other section is plain fields. The visited
* section is derived from the same [stageSectionSpecs] the stage screen lists, so
* the two can never disagree.
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun StageSectionPane(
stageKey: String,
sectionKey: String,
graph: Graph,
runSteps: List<RunStep> = emptyList(),
visitIndex: Int = 0,
onVisitIndexChange: (Int) -> Unit = {},
configuredServerUrl: String = "",
fetchArtifactBytes: suspend (String) -> ByteArray? = { null },
onBack: () -> Unit,
wide: Boolean = false,
modifier: Modifier = Modifier,
covered: Boolean = false,
runContext: Boolean = false,
) {
val clampedVisit = clampVisitIndex(visitIndex, runSteps.size)
val selectedStep = runSteps.getOrNull(clampedVisit)
val spec = remember(stageKey, graph, runSteps, clampedVisit, runContext, sectionKey) {
stageSectionSpecs(stageKey, graph, runSteps, clampedVisit, runContext)
.firstOrNull { it.key == sectionKey }
}
val title = spec?.title ?: sectionKey
if (covered) {
PaneIdentity(
title = title,
subtitle = GraphSemantics.nodeLabel(stageKey),
modifier = modifier.fillMaxSize(),
)
return
}
val bar: @Composable () -> Unit = {
TopAppBar(
title = { Text(title) },
navigationIcon = {
IconButton(onClick = onBack) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back")
}
},
windowInsets = paneSafeArea().only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal),
colors = TopAppBarDefaults.topAppBarColors(containerColor = paneContainerColor()),
)
}
if (spec?.artifacts == true) {
// The gallery keeps the one selection host (long-press selection, the
// contextual bar and Back-leaves-selection-first) it had inline.
val selectionState = rememberArtifactSelection(stageKey, clampedVisit)
ArtifactSelectionScaffold(
selectionState = selectionState,
candidates = selectedStep?.artifacts.orEmpty(),
configuredServerUrl = configuredServerUrl,
fetchArtifactBytes = fetchArtifactBytes,
modifier = modifier,
containerColor = paneContainerColor(),
topBar = bar,
) { selection, onSelectionChange, padding ->
StageSectionBody(
stageKey = stageKey,
spec = spec,
step = selectedStep,
runSteps = runSteps,
visitIndex = clampedVisit,
onVisitIndexChange = onVisitIndexChange,
configuredServerUrl = configuredServerUrl,
fetchArtifactBytes = fetchArtifactBytes,
selection = selection,
onSelectionChange = onSelectionChange,
wide = wide,
modifier = Modifier.padding(padding),
)
}
} else {
Scaffold(
modifier = modifier,
containerColor = paneContainerColor(),
contentWindowInsets = paneSafeArea(),
topBar = bar,
) { padding ->
StageSectionBody(
stageKey = stageKey,
spec = spec,
step = selectedStep,
runSteps = runSteps,
visitIndex = clampedVisit,
onVisitIndexChange = onVisitIndexChange,
configuredServerUrl = configuredServerUrl,
fetchArtifactBytes = fetchArtifactBytes,
selection = ArtifactSelection(),
onSelectionChange = {},
wide = wide,
modifier = Modifier.padding(padding),
)
}
}
}
/**
* One section's content: its own single scroll, a context line naming the stage,
* its own top spacing, and — for a visit's result section — the visit tab row,
* so the operator can switch visits in place. The stage definition skips the tab
* row (it does not change per visit). Plain sections render their rows; the
* artifacts section renders the shared [ArtifactsSection] gallery.
*/
@Composable
private fun StageSectionBody(
stageKey: String,
spec: StageSectionSpec?,
step: RunStep?,
runSteps: List<RunStep>,
visitIndex: Int,
onVisitIndexChange: (Int) -> Unit,
configuredServerUrl: String,
fetchArtifactBytes: suspend (String) -> ByteArray?,
selection: ArtifactSelection,
onSelectionChange: (ArtifactSelection) -> Unit,
wide: Boolean,
modifier: Modifier = Modifier,
) {
val text = pipelinesText()
DetailTabBody(wide, modifier) { columnModifier ->
Column(
modifier = columnModifier
.verticalScroll(rememberScrollState())
.padding(horizontal = SPACING_L, vertical = SPACING_L),
verticalArrangement = Arrangement.spacedBy(SPACING_XS),
) {
Text(GraphSemantics.nodeLabel(stageKey), style = text.meta)
if (spec != null && spec.key != STAGE_DEFINITION_KEY) {
StageVisitTabs(runSteps.size, visitIndex, onVisitIndexChange)
}
when {
spec == null -> Text("This section is not recorded for this stage.", style = text.meta)
spec.artifacts -> if (step != null) {
ArtifactsSection(
step = step,
configuredServerUrl = configuredServerUrl,
fetchArtifactBytes = fetchArtifactBytes,
selection = selection,
onSelectionChange = onSelectionChange,
)
}
else -> spec.fields.forEach { field -> StageFieldRow(field) }
}
}
}
}
/**
* The run-side stage level: with no [openSection] it is the compact stage screen
* ([StageDetailPane]); with one it is that section's pane ([StageSectionPane]).
* Both read the same run detail and derive the stage's visits the same way, so
* the two levels can never disagree and no state is read twice.
*/
@Composable @Composable
fun RunStagePane( fun RunStagePane(
vm: AppViewModel, vm: AppViewModel,
runId: Long, runId: Long,
stageKey: String, stageKey: String,
visitIndex: Int, visitIndex: Int,
openSection: String?,
onOpenSection: (String) -> Unit,
onVisitChange: (Int) -> Unit,
onBack: () -> Unit, onBack: () -> Unit,
wide: Boolean, wide: Boolean,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
@@ -565,28 +710,55 @@ fun RunStagePane(
val steps = run?.steps.orEmpty() val steps = run?.steps.orEmpty()
// One aggregation per step-list change; the stage's visits are read from it. // One aggregation per step-list change; the stage's visits are read from it.
val timeline = remember(steps) { runTimeline(steps) } val timeline = remember(steps) { runTimeline(steps) }
StageDetailPane( val runSteps = remember(timeline, stageKey) { timeline.visitsByStage[stageKey].orEmpty() }
stageKey = stageKey, val graph = run?.graph ?: Graph()
graph = run?.graph ?: Graph(), if (openSection == null) {
runSteps = timeline.visitsByStage[stageKey].orEmpty(), StageDetailPane(
initialVisitIndex = visitIndex, stageKey = stageKey,
configuredServerUrl = configuredServerUrl, graph = graph,
fetchArtifactBytes = vm::fetchArtifactBytes, runSteps = runSteps,
onBack = onBack, visitIndex = visitIndex,
wide = wide, onVisitIndexChange = onVisitChange,
modifier = modifier, onOpenSection = onOpenSection,
covered = covered, onBack = onBack,
runContext = true, wide = wide,
) modifier = modifier,
covered = covered,
runContext = true,
)
} else {
StageSectionPane(
stageKey = stageKey,
sectionKey = openSection,
graph = graph,
runSteps = runSteps,
visitIndex = visitIndex,
onVisitIndexChange = onVisitChange,
configuredServerUrl = configuredServerUrl,
fetchArtifactBytes = vm::fetchArtifactBytes,
onBack = onBack,
wide = wide,
modifier = modifier,
covered = covered,
runContext = true,
)
}
} }
/** The stage pane hosted by the pipeline destination; a definition has no run. */ /**
* The pipeline-side stage level: with no [openSection] it is the stage screen
* (a definition has no run, so it lists just that section); with one it is the
* definition section's pane. The two share the stage screen and the section pane
* with the run side.
*/
@Composable @Composable
fun PipelineStagePane( fun PipelineStagePane(
vm: AppViewModel, vm: AppViewModel,
pipelineId: Long, pipelineId: Long,
version: Int, version: Int,
stageKey: String, stageKey: String,
openSection: String?,
onOpenSection: (String) -> Unit,
onBack: () -> Unit, onBack: () -> Unit,
wide: Boolean, wide: Boolean,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
@@ -594,14 +766,28 @@ fun PipelineStagePane(
) { ) {
val state by vm.pipelineDetail.collectAsStateWithLifecycle() val state by vm.pipelineDetail.collectAsStateWithLifecycle()
val detail = state.data?.takeIf { it.id == pipelineId && it.version == version } val detail = state.data?.takeIf { it.id == pipelineId && it.version == version }
StageDetailPane( val graph = detail?.graph ?: Graph()
stageKey = stageKey, if (openSection == null) {
graph = detail?.graph ?: Graph(), StageDetailPane(
onBack = onBack, stageKey = stageKey,
wide = wide, graph = graph,
modifier = modifier, onOpenSection = onOpenSection,
covered = covered, onBack = onBack,
) wide = wide,
modifier = modifier,
covered = covered,
)
} else {
StageSectionPane(
stageKey = stageKey,
sectionKey = openSection,
graph = graph,
onBack = onBack,
wide = wide,
modifier = modifier,
covered = covered,
)
}
} }
/** One field as either the shared code card (blocks) or a key/value row. */ /** One field as either the shared code card (blocks) or a key/value row. */
@@ -629,7 +815,3 @@ internal fun StageTypeChip(label: String) {
) )
} }
} }
/** A section key as its visible title ("definition" → "Definition"). */
private fun String.capitalized(): String =
replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }
@@ -44,11 +44,38 @@ class PaneStateTest {
assertEquals(1, result.selection.depth) assertEquals(1, result.selection.depth)
} }
@Test
fun backInsideSectionReturnsToTheStageKeepingTheStage() {
val section = PaneSelection(
pane = MasterPane.Section,
itemId = 7L,
itemVersion = 3,
sectionIndex = 1,
stageKey = "planner",
stageVisit = 2,
sectionKey = "artifacts",
)
val result = backStep(section) as BackResult.Show
// Exactly one level: section -> stage, keeping the stage and its visit,
// clearing only the open section.
assertEquals(MasterPane.Stage, result.selection.pane)
assertEquals(7L, result.selection.itemId)
assertEquals(3, result.selection.itemVersion)
assertEquals("planner", result.selection.stageKey)
assertEquals(2, result.selection.stageVisit)
assertEquals(null, result.selection.sectionKey)
assertEquals(2, result.selection.depth)
}
@Test @Test
fun depthIsBoundedByTheDeclaredMaximum() { fun depthIsBoundedByTheDeclaredMaximum() {
assertEquals(0, PaneSelection(MasterPane.List).depth) assertEquals(0, PaneSelection(MasterPane.List).depth)
assertEquals(1, PaneSelection(MasterPane.Detail, itemId = 1L).depth) assertEquals(1, PaneSelection(MasterPane.Detail, itemId = 1L).depth)
assertEquals(2, PaneSelection(MasterPane.Stage, itemId = 1L, stageKey = "s").depth) assertEquals(2, PaneSelection(MasterPane.Stage, itemId = 1L, stageKey = "s").depth)
assertEquals(
3,
PaneSelection(MasterPane.Section, itemId = 1L, stageKey = "s", sectionKey = "artifacts").depth,
)
// Every pane's depth is within the bound; the stack can never grow deeper. // Every pane's depth is within the bound; the stack can never grow deeper.
MasterPane.entries.forEach { pane -> MasterPane.entries.forEach { pane ->
assertTrue(PaneSelection(pane = pane).depth <= MAX_PANE_DEPTH) assertTrue(PaneSelection(pane = pane).depth <= MAX_PANE_DEPTH)
@@ -65,18 +92,26 @@ class PaneStateTest {
stageKey = "s", stageKey = "s",
stageVisit = 3, stageVisit = 3,
) )
val section = stage.copy(pane = MasterPane.Section, sectionKey = "artifacts")
// Level 0 (list): everything closes. // Level 0 (list): everything closes.
assertEquals(PaneSelection(), popTo(stage, 0)) assertEquals(PaneSelection(), popTo(section, 0))
// Level 1 (detail): only the stage closes, the item is kept. // Level 1 (detail): the stage and its section close, the item is kept.
val detail = popTo(stage, 1) val detail = popTo(section, 1)
assertEquals(MasterPane.Detail, detail.pane) assertEquals(MasterPane.Detail, detail.pane)
assertEquals(9L, detail.itemId) assertEquals(9L, detail.itemId)
assertEquals(2, detail.itemVersion) assertEquals(2, detail.itemVersion)
assertEquals(1, detail.sectionIndex) assertEquals(1, detail.sectionIndex)
assertEquals(null, detail.stageKey) assertEquals(null, detail.stageKey)
assertEquals(null, detail.sectionKey)
// Level 2 (stage): only the section closes, the stage is kept.
val stageAgain = popTo(section, 2)
assertEquals(MasterPane.Stage, stageAgain.pane)
assertEquals("s", stageAgain.stageKey)
assertEquals(null, stageAgain.sectionKey)
// A level at or beyond the current depth is a no-op. // A level at or beyond the current depth is a no-op.
assertEquals(stage, popTo(stage, 2)) assertEquals(stage, popTo(stage, 2))
assertEquals(stage, popTo(stage, 5)) assertEquals(section, popTo(section, 3))
assertEquals(section, popTo(section, 5))
assertEquals(PaneSelection(MasterPane.Detail, 4L), popTo(PaneSelection(MasterPane.Detail, 4L), 3)) assertEquals(PaneSelection(MasterPane.Detail, 4L), popTo(PaneSelection(MasterPane.Detail, 4L), 3))
} }
@@ -95,6 +130,15 @@ class PaneStateTest {
stageKey = "planner", stageKey = "planner",
stageVisit = 3, stageVisit = 3,
), ),
PaneSelection(
pane = MasterPane.Section,
itemId = 8L,
itemVersion = 2,
sectionIndex = 4,
stageKey = "planner",
stageVisit = 3,
sectionKey = "artifacts",
),
) )
cases.forEach { selection -> cases.forEach { selection ->
val saved = with(PaneSelectionSaver) { scope.save(selection) } val saved = with(PaneSelectionSaver) { scope.save(selection) }
@@ -105,7 +149,7 @@ class PaneStateTest {
@Test @Test
fun encodedPayloadIsPrimitivesOnly() { fun encodedPayloadIsPrimitivesOnly() {
// Process-death restoration stays small: only Strings, ints and a long, // Process-death restoration stays small: only Strings, ints and a long,
// with a null stage key encoded as an empty string. // with a null stage or section key encoded as an empty string.
val encoded = encodePaneSelection( val encoded = encodePaneSelection(
PaneSelection( PaneSelection(
pane = MasterPane.Stage, pane = MasterPane.Stage,
@@ -116,14 +160,25 @@ class PaneStateTest {
stageVisit = 4, stageVisit = 4,
), ),
) )
assertEquals(listOf("Stage", 9L, 2, 1, "planner", 4), encoded) assertEquals(listOf("Stage", 9L, 2, 1, "planner", 4, ""), encoded)
assertEquals( assertEquals(
PaneSelection(MasterPane.Stage, 9L, 2, 1, "planner", 4), PaneSelection(MasterPane.Stage, 9L, 2, 1, "planner", 4),
decodePaneSelection(encoded), decodePaneSelection(encoded),
) )
assertEquals( assertEquals(
listOf("Detail", 9L, 2, 1, "", 0), listOf("Detail", 9L, 2, 1, "", 0, ""),
encodePaneSelection(PaneSelection(MasterPane.Detail, 9L, 2, 1)), encodePaneSelection(PaneSelection(MasterPane.Detail, 9L, 2, 1)),
) )
val section = PaneSelection(
pane = MasterPane.Section,
itemId = 9L,
itemVersion = 2,
sectionIndex = 1,
stageKey = "planner",
stageVisit = 4,
sectionKey = "artifacts",
)
assertEquals(listOf("Section", 9L, 2, 1, "planner", 4, "artifacts"), encodePaneSelection(section))
assertEquals(section, decodePaneSelection(encodePaneSelection(section)))
} }
} }
@@ -195,11 +195,49 @@ class StageDetailSheetTest {
} }
@Test @Test
fun theDefinitionStartsExpandedOnlyWithoutARunContext() { fun theStageScreenListsItsSectionsInOrderAndTheDefinitionLast() {
// A pipeline's stage definition is the pane's only content, so it starts val stage = Stage(key = "implementer", type = "model", prompt = "do", output = "done")
// expanded; a run pane leads with results and collapses the definition. val graph = Graph(stages = listOf(stage))
assertTrue(definitionStartsExpanded(runContext = false)) val step = RunStep(
assertFalse(definitionStartsExpanded(runContext = true)) status = "succeeded",
outcome = "success",
target = "reviewer",
input = mapOf("prompt" to JsonPrimitive("do it")),
output = mapOf("result" to JsonPrimitive("done")),
diagnostic = "why",
)
val specs = stageSectionSpecs("implementer", graph, listOf(step), visitIndex = 0, runContext = true)
// The run's results lead (artifacts first) and the stage's own definition
// is the last section, named with its own visible title.
assertEquals(listOf("artifacts", "output", "input", "run", "definition"), specs.map { it.key })
assertEquals(
listOf("Artifacts", "Output", "Input", "This run", "Stage definition"),
specs.map { it.title },
)
// The artifacts section is the gallery (no fields); the definition keeps
// the stage's own fields.
assertTrue(specs.first().artifacts)
assertTrue(specs.first().fields.isEmpty())
assertTrue(specs.first { it.key == "definition" }.fields.isNotEmpty())
}
@Test
fun aDefinitionOnlyStageListsJustItsDefinition() {
val graph = Graph(stages = listOf(Stage(key = "planner", type = "model", prompt = "do")))
// No run context (a pipeline stage): only the definition section.
val specs = stageSectionSpecs("planner", graph, emptyList(), visitIndex = 0, runContext = false)
assertEquals(listOf("definition"), specs.map { it.key })
}
@Test
fun aVisitThatRecordedNoOutputOrInputListsArtifactsAndTheDefinition() {
val graph = Graph(stages = listOf(Stage(key = "s", type = "model")))
val step = RunStep(status = "succeeded")
val specs = stageSectionSpecs("s", graph, listOf(step), visitIndex = 0, runContext = true)
// The artifacts gallery always shows for a reached visit; empty
// output/input/evidence sections are omitted rather than listed blank.
assertEquals(listOf("artifacts", "definition"), specs.map { it.key })
assertTrue(specs.none { !it.artifacts && it.fields.isEmpty() })
} }
@Test @Test