Let the detail tabs collapse and rebuild the step and source layouts
DetailTabs: give every tab a meaningful ImageVector from the core Material icon set and turn the wide rail into a collapsible one. A rememberSaveable railExpanded flag plus an accessibility-labelled "Collapse tabs"/"Expand tabs" control shrink the rail to a narrow icon-only strip and back; the collapsed tile still names its tab via the icon's content description and still marks the selected tab by container colour and tab semantics, and the content box reclaims the rail width. Narrow windows keep the top PrimaryScrollableTabRow. railWidthDp is a pure, unit-tested predicate. RunDetailScreen: render a step's metadata as aligned label/value rows (KeyValueRow) instead of a ragged stack of lines, paired into two columns on wide windows (status/outcome, duration/visit, target/session, agent/model target) and a single column on narrow ones. Evidence (input, output, transcript, file changes, notifications, control diagnostics) fills its card in full-width monospace with a shared padding/line height, and the vertical rhythm is one bottom gap per step with no doubled gap for a step without expandable detail. The timeline glyph and connector stay aligned with the step title. All previously shown fields are retained. PipelineDetailScreen/CodeBlock: the Source tab now fills the whole tab area with the tab's single LazyColumn owning all scrolling (CodeBlock gains an optional maxHeight = null that renders unbounded; the default bounded behaviour is unchanged for other callers). It renders the parsed definition as one collapsible section per stage (key, type) built from the same stageDefinitionFields/StageFieldRow the stage detail sheet uses, covering prompt, output, tools, configs, edges (outcomes with resolved targets and #success/#failure terminals), memory, limits and notify policy while skipping absent fields. A Raw toggle reveals the exact markdown and a copy action copies the whole definition. Extract shared formatting helpers (fileChangeLine, notificationLine, fileChangesSummary, controlVisitLabel) into Format.kt and expose StageFieldRow/StageTypeChip/stageDefinitionFields so the sheet and the Source tab agree. Add StageDetailSheetTest and StepMetaTest, extend DetailTabsTest (icon distinctness, rail width) and FormatTest, and record the build, unit-test and emulator-screenshot verification in android/README.md; the captures stay in the git-ignored android/captures/space_pass/. Assisted-by: DeepSeek V4.1 Flash
This commit is contained in:
+70
-9
@@ -113,14 +113,27 @@ stops it.
|
||||
existing back/refresh/start/cancel/retry bars on the detail screens).
|
||||
- Both detail screens are tabbed via one shared `ui/components/DetailTabs.kt`:
|
||||
run detail exposes Summary, Graph, Input, Output, Evidence and Steps, pipeline
|
||||
detail Summary, Graph and Source, with Summary first and the default. The run's
|
||||
six tabs scroll horizontally on a narrow window; on a wide window the same tabs
|
||||
render as a vertical selectable rail. Selection is `rememberSaveable` (survives
|
||||
detail Summary, Graph and Source, with Summary first and the default. Every tab
|
||||
carries a meaningful icon alongside its label. The run's six tabs scroll
|
||||
horizontally on a narrow window; on a wide window the same tabs render as a
|
||||
vertical selectable rail that **collapses to a narrow icon-only strip** and
|
||||
expands back via an accessibility-labelled "Collapse tabs"/"Expand tabs"
|
||||
control, so the content reclaims the rail's width; the collapsed strip keeps
|
||||
each icon's accurate content description and still marks the selected tab. Both
|
||||
the selection and the collapsed/expanded state are `rememberSaveable` (survive
|
||||
recomposition and configuration changes) and the tabs carry real tab semantics
|
||||
(`Role.Tab` + selected state), so selection is never conveyed by colour alone.
|
||||
Only the selected tab's body composes (`when`), each tab is a single
|
||||
`LazyColumn`, and the Graph tab keeps the full-height `WorkflowGraph` panel
|
||||
with its Fit and expand controls.
|
||||
- The Source tab fills the whole tab area and renders the parsed definition
|
||||
instead of dumping the raw markdown: one collapsible section per stage (name ·
|
||||
type) holding labelled blocks for prompt, output, tools, configs, edges
|
||||
(outcomes with their resolved targets, `#success`/`#failure` named as
|
||||
terminals), memory, limits and notification policy, skipping what a stage does
|
||||
not have. The rows come from the same `stageDefinitionFields`/`StageFieldRow`
|
||||
the stage detail sheet uses, so the two views cannot diverge. The exact source
|
||||
stays available behind a "Raw" toggle and a whole-definition copy action.
|
||||
- The Summary tab carries what each page header carried: for a run the
|
||||
status/outcome/executing chip row, recorded + completed visits, pipeline
|
||||
id/version, stage, workspace, content hash, start/finish/duration and the
|
||||
@@ -131,8 +144,10 @@ stops it.
|
||||
CodeBlock.kt` card: `surfaceContainer` role, default rounded shape, a small
|
||||
label header, a whole-block copy action (`LocalClipboardManager`) and monospace
|
||||
at the shared size/line height, with a bounded height that scrolls internally
|
||||
instead of pushing the page. Blank content renders nothing, and no raw bordered
|
||||
monospace box remains.
|
||||
instead of pushing the page. `maxHeight = null` renders a block unbounded so the
|
||||
surrounding page scrolls as a whole (the Source tab uses this); the default
|
||||
bounded behaviour is unchanged for every other caller. Blank content renders
|
||||
nothing, and no raw bordered monospace box remains.
|
||||
- Inside each tab the existing `LazyListScope.collapsibleSection` (`SectionHeader`)
|
||||
provides inner sections where content naturally breaks down: Output per result
|
||||
field, Input per labelled part, Steps per stage group and Evidence per entry.
|
||||
@@ -155,10 +170,16 @@ stops it.
|
||||
per screen, defaulting to expanded. Real lists (versions, steps, session
|
||||
evidence) are items of the one outer list, so nothing nests a scrollable.
|
||||
- Steps render as a timeline in run detail: a leading status glyph connected to
|
||||
the next step by an outcome-coloured line, the stage with its sequence/visit
|
||||
number, an outcome chip and the duration, with every retained piece of evidence
|
||||
(input, output, transcript, file changes, notifications, control evidence)
|
||||
behind a collapsible, collapsed-by-default detail in monospace.
|
||||
the next step by an outcome-coloured line (kept aligned with the step title),
|
||||
the stage with its sequence and an outcome chip. A step's metadata is a set of
|
||||
aligned label/value rows (`KeyValueRow`) — paired side by side in two columns on
|
||||
a wide window and stacked in one column on a narrow one — with a single
|
||||
consistent vertical rhythm (one bottom gap per step, no doubled gap when a step
|
||||
has no expandable detail) and full-width monospace evidence cards. Every
|
||||
retained field stays: status, outcome, duration, visit/maxVisits/limitReached/
|
||||
model target, target, session id, agent active, diagnostic and, behind the
|
||||
collapsed-by-default detail, input, output, transcript, file changes (including
|
||||
binary/truncated and skipped) and notification receipts.
|
||||
- The runs list is grouped by day (`Today`/`Yesterday`/date, newest first) under
|
||||
sticky headers, with the usage aggregates as a metrics block (total, average
|
||||
via `formatDuration`, and colour-coded succeeded/failed/canceled/interrupted/
|
||||
@@ -288,6 +309,46 @@ with the run detail open; the selected tab stayed selected
|
||||
(`18_before_config`, `18_after_config`). `adb logcat` for the app package
|
||||
contained no `FATAL EXCEPTION` and no Compose/other runtime exception.
|
||||
|
||||
The space-usage pass (collapsible icon rail, roomier Steps, rendered Source tab)
|
||||
was verified on the same `Pixel_Fold_API_36` emulator (dark mode after
|
||||
`adb shell cmd uimode night yes`) against the live server at
|
||||
`ws://10.0.2.2:8080/connect`:
|
||||
|
||||
- `:app:testDebugUnitTest` reported **76 tests, 0 failures** (up from 60:
|
||||
new `StageDetailSheetTest` for the stage/step field derivation and
|
||||
`StepMetaTest` for the step metadata pairing + details predicate, plus the
|
||||
icon/rail-width assertions in `DetailTabsTest` and the file-change/notification
|
||||
formatting in `FormatTest`). `:app:assembleDebug` and `:app:installDebug`
|
||||
succeeded; the install reported `Installed on 1 device` (the emulator — no
|
||||
physical device was attached at install time).
|
||||
- Captures were written with `adb -s emulator-5554 shell screencap -p
|
||||
/sdcard/shot.png` followed by `adb -s emulator-5554 pull` (never
|
||||
`exec-out … >`), to `captures/space_pass/` (git-ignored):
|
||||
`narrow_pipeline_top_tabs` (narrow window, tabs across the top),
|
||||
`source_tab_narrow` (rendered definition) and `source_tab_raw_narrow` (the
|
||||
`Raw` toggle revealing the exact markdown), `wide_source_rail_expanded`
|
||||
(icon+label rail, Source tab) and `wide_source_rail_collapsed` (icon-only rail,
|
||||
content visibly wider), `wide_run_steps_expanded` and
|
||||
`wide_run_steps_expanded_rail_collapsed` (a step with the two-column metadata
|
||||
grid — Status/Outcome, Duration/Visit, Target/Session — and full-width Input/
|
||||
Output/File-changes/Transcript cards), plus `wide_graph_stage_sheet` (tapping a
|
||||
stage on the Graph tab still opens the refactored `StageDetailSheet`). No
|
||||
clipping, even step spacing and a height-filling Source tab were confirmed by
|
||||
eye.
|
||||
- Rail-collapse persistence across a configuration change was exercised by
|
||||
collapsing the rail on a detail screen and switching `wm density` 390→401: the
|
||||
activity recreated and the collapsed strip stayed collapsed (`Expand tabs` was
|
||||
still the control's description after the change; capture
|
||||
`wide_detail_rail_collapsed_config_change`). The saved tab index is clamped by
|
||||
`clampTabIndex` (unit-tested), so a stale index never indexes out of bounds.
|
||||
- The wide layout was exercised by resizing the emulated display
|
||||
(`adb shell wm size 2000x3400`, ≈820dp at density 390) and reset afterwards
|
||||
(`wm size reset`); the attached Pixel 10 Pro Fold was never used and no run was
|
||||
started from the app.
|
||||
- `adb -s emulator-5554 logcat -d` contained 0 `FATAL EXCEPTION` lines and 0
|
||||
`E AndroidRuntime` lines. The emulator was stopped with `adb emu kill`; no
|
||||
`qemu-system-aarch64-headless` process survived.
|
||||
|
||||
Because `adb` cannot physically fold the phone, the wide two-pane/rail layout was
|
||||
exercised on the emulator by resizing the emulated display (`adb shell wm size
|
||||
2000x3400`, ≈820dp at density 390) and the narrow single-pane layout at the
|
||||
|
||||
@@ -6,6 +6,9 @@ import kotlinx.serialization.json.JsonArray
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.JsonPrimitive
|
||||
import net.awan.pipelines.data.protocol.FileChange
|
||||
import net.awan.pipelines.data.protocol.NotificationReceipt
|
||||
import net.awan.pipelines.data.protocol.StageFileChanges
|
||||
|
||||
/** Human duration between two RFC3339 timestamps, or null when unavailable. */
|
||||
fun formatDuration(start: String, end: String): String? {
|
||||
@@ -51,3 +54,34 @@ fun Map<String, JsonElement>?.displayMap(): String =
|
||||
*/
|
||||
fun visitCount(count: Int, adjective: String): String =
|
||||
"$count $adjective ${if (count == 1) "visit" else "visits"}"
|
||||
|
||||
/**
|
||||
* One changed-file line, e.g. `modified src/a.kt (binary) (truncated)`. The
|
||||
* single spelling used by the stage detail sheet and the run steps timeline.
|
||||
*/
|
||||
fun fileChangeLine(file: FileChange): String =
|
||||
"${file.kind} ${file.path}" +
|
||||
(if (file.binary) " (binary)" else "") +
|
||||
(if (file.truncated) " (truncated)" else "")
|
||||
|
||||
/** One notification receipt, e.g. `delivered → ntfy · ok`, skipping a blank diagnostic. */
|
||||
fun notificationLine(receipt: NotificationReceipt): String =
|
||||
"${receipt.status} → ${receipt.destination}" +
|
||||
(receipt.diagnostic?.takeIf { it.isNotBlank() }?.let { " · $it" } ?: "")
|
||||
|
||||
/**
|
||||
* A compact file-change summary, e.g. `success (3 files), 1 skipped`. Blank parts
|
||||
* (missing status, no files, nothing skipped) are omitted so no dangling label is
|
||||
* ever emitted; an entirely blank change set renders as "".
|
||||
*/
|
||||
fun fileChangesSummary(changes: StageFileChanges): String = buildString {
|
||||
if (changes.status.isNotBlank()) append(changes.status)
|
||||
if (changes.files.isNotEmpty()) {
|
||||
if (isNotEmpty()) append(" ")
|
||||
append("(${changes.files.size} files)")
|
||||
}
|
||||
if (changes.skipped > 0) {
|
||||
if (isNotEmpty()) append(", ")
|
||||
append("${changes.skipped} skipped")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,11 @@ import net.awan.pipelines.ui.theme.pipelinesText
|
||||
* pushing the page down. The internal scroll is finite-height, so it is safe
|
||||
* inside the tab's single LazyColumn (never an unbounded same-direction nest).
|
||||
*
|
||||
* Pass `maxHeight = null` to render the whole block unbounded and let the
|
||||
* surrounding page scroll as a whole (used by the Source tab, whose single
|
||||
* LazyColumn owns all scrolling). The default bounded behaviour is unchanged for
|
||||
* every other caller.
|
||||
*
|
||||
* Blank content renders nothing, so callers never leave an empty block.
|
||||
*/
|
||||
@Composable
|
||||
@@ -45,7 +50,7 @@ fun CodeBlock(
|
||||
label: String,
|
||||
text: String,
|
||||
modifier: Modifier = Modifier,
|
||||
maxHeight: Dp = CODE_BLOCK_MAX_HEIGHT,
|
||||
maxHeight: Dp? = CODE_BLOCK_MAX_HEIGHT,
|
||||
) {
|
||||
if (text.isBlank()) return
|
||||
val styles = pipelinesText()
|
||||
@@ -78,14 +83,18 @@ fun CodeBlock(
|
||||
)
|
||||
}
|
||||
}
|
||||
Text(
|
||||
text = text,
|
||||
style = styles.mono,
|
||||
modifier = Modifier
|
||||
val body = if (maxHeight != null) {
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(max = maxHeight)
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(start = 16.dp, end = 16.dp, bottom = 16.dp),
|
||||
} else {
|
||||
Modifier.fillMaxWidth()
|
||||
}
|
||||
Text(
|
||||
text = text,
|
||||
style = styles.mono,
|
||||
modifier = body.padding(start = 16.dp, end = 16.dp, bottom = 16.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,24 @@ import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.selection.selectable
|
||||
import androidx.compose.foundation.selection.selectableGroup
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowLeft
|
||||
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
|
||||
import androidx.compose.material.icons.automirrored.filled.List
|
||||
import androidx.compose.material.icons.automirrored.filled.Send
|
||||
import androidx.compose.material.icons.filled.Create
|
||||
import androidx.compose.material.icons.filled.Email
|
||||
import androidx.compose.material.icons.filled.Info
|
||||
import androidx.compose.material.icons.filled.MailOutline
|
||||
import androidx.compose.material.icons.filled.Share
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.PrimaryScrollableTabRow
|
||||
import androidx.compose.material3.Tab
|
||||
@@ -21,36 +34,43 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.VerticalDivider
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.Saver
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import net.awan.pipelines.ui.theme.pipelinesText
|
||||
|
||||
/** A named detail page tab: [key] is stable for `when` dispatch, [title] is shown. */
|
||||
data class DetailTab(val key: String, val title: String)
|
||||
/**
|
||||
* A named detail page tab: [key] is stable for `when` dispatch, [title] is shown,
|
||||
* and [icon] is the tab's glyph (used on the wide rail, always alongside the
|
||||
* label when expanded and alone when it is collapsed).
|
||||
*/
|
||||
data class DetailTab(val key: String, val title: String, val icon: ImageVector)
|
||||
|
||||
/** Run-detail tabs, Summary first so it is the default selection. */
|
||||
val runDetailTabs: List<DetailTab> = listOf(
|
||||
DetailTab("summary", "Summary"),
|
||||
DetailTab("graph", "Graph"),
|
||||
DetailTab("input", "Input"),
|
||||
DetailTab("output", "Output"),
|
||||
DetailTab("evidence", "Evidence"),
|
||||
DetailTab("steps", "Steps"),
|
||||
DetailTab("summary", "Summary", Icons.Default.Info),
|
||||
DetailTab("graph", "Graph", Icons.Default.Share),
|
||||
DetailTab("input", "Input", Icons.Default.Create),
|
||||
DetailTab("output", "Output", Icons.AutoMirrored.Filled.Send),
|
||||
DetailTab("evidence", "Evidence", Icons.Default.MailOutline),
|
||||
DetailTab("steps", "Steps", Icons.AutoMirrored.Filled.List),
|
||||
)
|
||||
|
||||
/** Pipeline-detail tabs, Summary first (the version list lives inside it). */
|
||||
val pipelineDetailTabs: List<DetailTab> = listOf(
|
||||
DetailTab("summary", "Summary"),
|
||||
DetailTab("graph", "Graph"),
|
||||
DetailTab("source", "Source"),
|
||||
DetailTab("summary", "Summary", Icons.Default.Info),
|
||||
DetailTab("graph", "Graph", Icons.Default.Share),
|
||||
DetailTab("source", "Source", Icons.Default.Email),
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -66,8 +86,10 @@ fun clampTabIndex(index: Int, tabCount: Int): Int =
|
||||
*
|
||||
* Narrow windows get a horizontally scrolling Material 3 [PrimaryScrollableTabRow]
|
||||
* (the run detail's six tabs scroll on a cover display); wide windows get a
|
||||
* vertical selectable rail. Both carry real tab semantics (`Role.Tab` + selected
|
||||
* state), so selection is never conveyed by colour alone.
|
||||
* vertical selectable rail that collapses to a narrow icon-only strip and expands
|
||||
* back to icons with labels, remembered across configuration changes. Both carry
|
||||
* real tab semantics (`Role.Tab` + selected state), so selection is never
|
||||
* conveyed by colour alone.
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@@ -83,17 +105,33 @@ fun DetailTabs(
|
||||
if (tabs.isEmpty()) return
|
||||
|
||||
if (wide) {
|
||||
// Remembered/saved so the collapsed or expanded rail survives
|
||||
// recomposition and configuration changes.
|
||||
var railExpanded by rememberSaveable { mutableStateOf(true) }
|
||||
Row(modifier.fillMaxSize()) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.width(WIDE_RAIL_WIDTH)
|
||||
.width(railWidthDp(railExpanded).dp)
|
||||
.fillMaxHeight()
|
||||
.selectableGroup()
|
||||
.padding(vertical = 8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
tabs.forEachIndexed { index, tab ->
|
||||
RailTab(tab = tab, selected = index == selected) { onSelect(index) }
|
||||
RailToggle(expanded = railExpanded, onToggle = { railExpanded = !railExpanded })
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.fillMaxWidth()
|
||||
.selectableGroup()
|
||||
.padding(top = 4.dp, bottom = 8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
tabs.forEachIndexed { index, tab ->
|
||||
RailTab(
|
||||
tab = tab,
|
||||
selected = index == selected,
|
||||
expanded = railExpanded,
|
||||
onClick = { onSelect(index) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
VerticalDivider()
|
||||
@@ -119,9 +157,40 @@ fun DetailTabs(
|
||||
}
|
||||
}
|
||||
|
||||
/** The accessibility-labelled control that collapses/expands the wide rail. */
|
||||
@Composable
|
||||
private fun RailTab(tab: DetailTab, selected: Boolean, onClick: () -> Unit) {
|
||||
private fun RailToggle(expanded: Boolean, onToggle: () -> Unit) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 4.dp),
|
||||
horizontalArrangement = if (expanded) Arrangement.End else Arrangement.Center,
|
||||
) {
|
||||
IconButton(onClick = onToggle) {
|
||||
Icon(
|
||||
imageVector = if (expanded) {
|
||||
Icons.AutoMirrored.Filled.KeyboardArrowLeft
|
||||
} else {
|
||||
Icons.AutoMirrored.Filled.KeyboardArrowRight
|
||||
},
|
||||
contentDescription = if (expanded) "Collapse tabs" else "Expand tabs",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* One wide-rail tab. Expanded it is an icon+label row; collapsed it is an
|
||||
* icon-only tile whose icon carries the [DetailTab.title] as its content
|
||||
* description. Selection is conveyed by the tab semantics (Role.Tab + selected)
|
||||
* and the container colour, not colour alone.
|
||||
*/
|
||||
@Composable
|
||||
private fun RailTab(tab: DetailTab, selected: Boolean, expanded: Boolean, onClick: () -> Unit) {
|
||||
val text = pipelinesText()
|
||||
val contentColor = if (selected) {
|
||||
MaterialTheme.colorScheme.onSecondaryContainer
|
||||
} else {
|
||||
MaterialTheme.colorScheme.onSurfaceVariant
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -129,20 +198,31 @@ private fun RailTab(tab: DetailTab, selected: Boolean, onClick: () -> Unit) {
|
||||
.background(
|
||||
if (selected) MaterialTheme.colorScheme.secondaryContainer else Color.Transparent,
|
||||
)
|
||||
.padding(horizontal = 16.dp, vertical = 12.dp),
|
||||
.padding(horizontal = if (expanded) 16.dp else 0.dp, vertical = 12.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = if (expanded) {
|
||||
Arrangement.spacedBy(12.dp)
|
||||
} else {
|
||||
Arrangement.Center
|
||||
},
|
||||
) {
|
||||
Text(
|
||||
text = tab.title,
|
||||
style = text.cardTitle,
|
||||
color = if (selected) {
|
||||
MaterialTheme.colorScheme.onSecondaryContainer
|
||||
} else {
|
||||
MaterialTheme.colorScheme.onSurfaceVariant
|
||||
},
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
Icon(
|
||||
imageVector = tab.icon,
|
||||
// When expanded the label names the tab, so the glyph is decorative;
|
||||
// collapsed the glyph is the only visible affordance and names it.
|
||||
contentDescription = if (expanded) null else tab.title,
|
||||
tint = contentColor,
|
||||
modifier = Modifier.size(24.dp),
|
||||
)
|
||||
if (expanded) {
|
||||
Text(
|
||||
text = tab.title,
|
||||
style = text.cardTitle,
|
||||
color = contentColor,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +280,12 @@ fun rememberSectionExpansion(vararg inputs: Any?): SectionExpansionState {
|
||||
return remember(collapsed) { SectionExpansionState(collapsed) }
|
||||
}
|
||||
|
||||
private val WIDE_RAIL_WIDTH = 200.dp
|
||||
private const val WIDE_RAIL_WIDTH_DP = 200
|
||||
private const val COLLAPSED_RAIL_WIDTH_DP = 64
|
||||
|
||||
/** Rail width in dp: icons with labels when expanded, icon-only when collapsed. */
|
||||
internal fun railWidthDp(expanded: Boolean): Int =
|
||||
if (expanded) WIDE_RAIL_WIDTH_DP else COLLAPSED_RAIL_WIDTH_DP
|
||||
|
||||
/** Comfortable max text width for a tab body on a wide window. */
|
||||
const val DETAIL_MAX_WIDTH_DP = 840
|
||||
|
||||
@@ -22,6 +22,7 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.semantics.heading
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.unit.dp
|
||||
import net.awan.pipelines.data.protocol.ControlEvidence
|
||||
import net.awan.pipelines.data.protocol.Graph
|
||||
import net.awan.pipelines.data.protocol.GraphSemantics
|
||||
import net.awan.pipelines.data.protocol.Protocol
|
||||
@@ -31,7 +32,10 @@ import net.awan.pipelines.data.protocol.edges
|
||||
import net.awan.pipelines.ui.components.CodeBlock
|
||||
import net.awan.pipelines.ui.components.DETAIL_MAX_WIDTH_DP
|
||||
import net.awan.pipelines.ui.components.KeyValueRow
|
||||
import net.awan.pipelines.ui.fileChangeLine
|
||||
import net.awan.pipelines.ui.fileChangesSummary
|
||||
import net.awan.pipelines.ui.formatDuration
|
||||
import net.awan.pipelines.ui.notificationLine
|
||||
import net.awan.pipelines.ui.theme.pipelinesText
|
||||
|
||||
/**
|
||||
@@ -104,6 +108,20 @@ internal fun stageDefinitionFields(stage: Stage): List<StageField> {
|
||||
return fields
|
||||
}
|
||||
|
||||
/**
|
||||
* The shared visit label for a step's control evidence, e.g. `3 / 5 (limit
|
||||
* reached)` (or just `3` when no max is recorded). Used by the sheet and the run
|
||||
* steps timeline so the two never spell a visit differently.
|
||||
*/
|
||||
internal fun controlVisitLabel(control: ControlEvidence): String {
|
||||
val base = if (control.maxVisits > 0) {
|
||||
"${control.visit} / ${control.maxVisits}"
|
||||
} else {
|
||||
control.visit.toString()
|
||||
}
|
||||
return base + if (control.limitReached) " (limit reached)" else ""
|
||||
}
|
||||
|
||||
/**
|
||||
* The pure run view of one [RunStep] for the selected stage: status, outcome,
|
||||
* duration, visit against the control's max_visits, target, session id,
|
||||
@@ -116,10 +134,8 @@ internal fun runStepFields(step: RunStep): List<StageField> {
|
||||
if (step.outcome.isNotBlank()) fields += StageField("Outcome", step.outcome)
|
||||
formatDuration(step.startedAt, step.finishedAt)?.let { fields += StageField("Duration", it) }
|
||||
step.control?.let { control ->
|
||||
val suffix = if (control.limitReached) " (limit reached)" else ""
|
||||
when {
|
||||
control.maxVisits > 0 -> fields += StageField("Visit", "${control.visit} / ${control.maxVisits}$suffix")
|
||||
control.visit > 0 -> fields += StageField("Visit", control.visit.toString())
|
||||
if (control.maxVisits > 0 || control.visit > 0) {
|
||||
fields += StageField("Visit", controlVisitLabel(control))
|
||||
}
|
||||
control.modelTarget?.takeIf { it.isNotBlank() }?.let { fields += StageField("Model target", it) }
|
||||
}
|
||||
@@ -130,20 +146,12 @@ internal fun runStepFields(step: RunStep): List<StageField> {
|
||||
if (step.transcript.isNotBlank()) fields += StageField("Transcript", step.transcript, block = true)
|
||||
|
||||
step.fileChanges?.let { changes ->
|
||||
val summary = buildString {
|
||||
append(changes.status)
|
||||
if (changes.files.isNotEmpty()) append(" (${changes.files.size} files)")
|
||||
if (changes.skipped > 0) append(", ${changes.skipped} skipped")
|
||||
}.trim().trimStart(',')
|
||||
val summary = fileChangesSummary(changes)
|
||||
if (summary.isNotBlank()) fields += StageField("File changes", summary)
|
||||
if (changes.files.isNotEmpty()) {
|
||||
fields += StageField(
|
||||
"Changed files",
|
||||
changes.files.joinToString("\n") { file ->
|
||||
"${file.kind} ${file.path}" +
|
||||
(if (file.binary) " (binary)" else "") +
|
||||
(if (file.truncated) " (truncated)" else "")
|
||||
},
|
||||
changes.files.joinToString("\n") { fileChangeLine(it) },
|
||||
block = true,
|
||||
)
|
||||
}
|
||||
@@ -151,11 +159,7 @@ internal fun runStepFields(step: RunStep): List<StageField> {
|
||||
|
||||
step.notifications.orEmpty().forEach { receipt ->
|
||||
if (receipt.status.isNotBlank() || receipt.destination.isNotBlank()) {
|
||||
fields += StageField(
|
||||
"Notification",
|
||||
"${receipt.status} → ${receipt.destination}" +
|
||||
(receipt.diagnostic?.takeIf { it.isNotBlank() }?.let { " · $it" } ?: ""),
|
||||
)
|
||||
fields += StageField("Notification", notificationLine(receipt))
|
||||
}
|
||||
}
|
||||
return fields
|
||||
@@ -226,14 +230,14 @@ fun StageDetailSheet(
|
||||
style = text.screenTitle,
|
||||
modifier = Modifier.semantics { heading() },
|
||||
)
|
||||
TypeChip(typeLabel)
|
||||
StageTypeChip(typeLabel)
|
||||
if (definition.isNotEmpty()) {
|
||||
Text("Definition", style = text.sectionHeader, modifier = Modifier.padding(top = 8.dp))
|
||||
definition.forEach { field -> FieldRow(field) }
|
||||
definition.forEach { field -> StageFieldRow(field) }
|
||||
}
|
||||
if (run.isNotEmpty()) {
|
||||
Text("This run", style = text.sectionHeader, modifier = Modifier.padding(top = 8.dp))
|
||||
run.forEach { field -> FieldRow(field) }
|
||||
run.forEach { field -> StageFieldRow(field) }
|
||||
}
|
||||
if (definition.isEmpty() && run.isEmpty()) {
|
||||
Text("No details recorded for this node.", style = text.meta)
|
||||
@@ -245,7 +249,7 @@ fun StageDetailSheet(
|
||||
|
||||
/** One field as either the shared code card (blocks) or a key/value row. */
|
||||
@Composable
|
||||
private fun FieldRow(field: StageField) {
|
||||
internal fun StageFieldRow(field: StageField) {
|
||||
if (field.block) {
|
||||
CodeBlock(field.label, field.value)
|
||||
} else {
|
||||
@@ -255,7 +259,7 @@ private fun FieldRow(field: StageField) {
|
||||
|
||||
/** A small rounded chip naming the stage type (model / ntfy / …). */
|
||||
@Composable
|
||||
private fun TypeChip(label: String) {
|
||||
internal fun StageTypeChip(label: String) {
|
||||
Surface(
|
||||
shape = RoundedCornerShape(50),
|
||||
color = MaterialTheme.colorScheme.secondaryContainer,
|
||||
|
||||
@@ -4,12 +4,17 @@ import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.ContentCopy
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
import androidx.compose.material.icons.filled.Refresh
|
||||
import androidx.compose.material3.AlertDialog
|
||||
@@ -19,6 +24,7 @@ import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
@@ -32,7 +38,10 @@ import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import net.awan.pipelines.data.ErrorMessages
|
||||
@@ -47,8 +56,12 @@ import net.awan.pipelines.ui.components.KeyValueRow
|
||||
import net.awan.pipelines.ui.components.LoadingState
|
||||
import net.awan.pipelines.ui.components.collapsibleSection
|
||||
import net.awan.pipelines.ui.components.pipelineDetailTabs
|
||||
import net.awan.pipelines.ui.components.rememberSectionExpansion
|
||||
import net.awan.pipelines.ui.graph.StageDetailSheet
|
||||
import net.awan.pipelines.ui.graph.StageFieldRow
|
||||
import net.awan.pipelines.ui.graph.WorkflowGraph
|
||||
import net.awan.pipelines.ui.graph.effectiveStageType
|
||||
import net.awan.pipelines.ui.graph.stageDefinitionFields
|
||||
import net.awan.pipelines.ui.theme.pipelinesText
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@@ -110,7 +123,7 @@ fun PipelineDetailScreen(
|
||||
when (tab.key) {
|
||||
"summary" -> PipelineSummaryTab(detail, wide, contentModifier)
|
||||
"graph" -> PipelineGraphTab(detail, contentModifier)
|
||||
else -> PipelineSourceTab(detail.source, wide, contentModifier)
|
||||
else -> PipelineSourceTab(detail, contentModifier)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -224,15 +237,89 @@ private fun PipelineGraphTab(detail: PipelineDetail, modifier: Modifier) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The Source tab fills the whole tab area (page-level scrolling, no cramped
|
||||
* inner box) and renders the parsed definition: one collapsible section per
|
||||
* stage (name · type) holding labelled blocks built from the same
|
||||
* [stageDefinitionFields] the stage detail sheet uses, so the two cannot
|
||||
* diverge. Absent fields are skipped. The exact markdown is one tap away behind
|
||||
* the Raw toggle and a copy-whole-definition action.
|
||||
*/
|
||||
@Composable
|
||||
private fun PipelineSourceTab(source: String, wide: Boolean, modifier: Modifier) {
|
||||
DetailTabBody(wide, modifier) { columnModifier ->
|
||||
LazyColumn(
|
||||
modifier = columnModifier,
|
||||
contentPadding = PaddingValues(vertical = 16.dp),
|
||||
) {
|
||||
item(key = "pipeline-source") {
|
||||
CodeBlock("Source", source, Modifier.padding(horizontal = 16.dp))
|
||||
private fun PipelineSourceTab(detail: PipelineDetail, modifier: Modifier) {
|
||||
val text = pipelinesText()
|
||||
val clipboard = LocalClipboardManager.current
|
||||
var showRaw by rememberSaveable { mutableStateOf(false) }
|
||||
val stages = detail.graph.stages
|
||||
// Derived once per definition change, not per recomposition.
|
||||
val sections = remember(stages) {
|
||||
stages.map { stage ->
|
||||
// The heading already names the type, so drop the redundant row.
|
||||
stage to stageDefinitionFields(stage).filterNot { it.label == "Type" }
|
||||
}
|
||||
}
|
||||
val expansion = rememberSectionExpansion(stages)
|
||||
|
||||
LazyColumn(
|
||||
modifier = modifier.fillMaxSize(),
|
||||
contentPadding = PaddingValues(vertical = 16.dp),
|
||||
) {
|
||||
item(key = "source-actions") {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
OutlinedButton(onClick = { showRaw = !showRaw }) {
|
||||
Text(if (showRaw) "Rendered" else "Raw")
|
||||
}
|
||||
OutlinedButton(onClick = { clipboard.setText(AnnotatedString(detail.source)) }) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.ContentCopy,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(18.dp),
|
||||
)
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Text("Copy definition")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
when {
|
||||
showRaw -> item(key = "source-raw") {
|
||||
CodeBlock(
|
||||
"Definition source",
|
||||
detail.source,
|
||||
Modifier.padding(horizontal = 16.dp, vertical = 4.dp),
|
||||
maxHeight = null,
|
||||
)
|
||||
}
|
||||
stages.isEmpty() -> item(key = "source-empty") {
|
||||
Text(
|
||||
"This definition has no stages.",
|
||||
style = text.meta,
|
||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
)
|
||||
}
|
||||
else -> sections.forEach { (stage, fields) ->
|
||||
val sectionKey = "source-${stage.key}"
|
||||
collapsibleSection(
|
||||
title = "${stage.key} · ${effectiveStageType(stage.type)}",
|
||||
key = sectionKey,
|
||||
expanded = expansion.isExpanded(sectionKey),
|
||||
onToggle = { expansion.toggle(sectionKey) },
|
||||
) {
|
||||
item(key = "$sectionKey-body") {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
fields.forEach { field -> StageFieldRow(field) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.IntrinsicSize
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
@@ -52,8 +53,6 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
import net.awan.pipelines.data.ErrorMessages
|
||||
import net.awan.pipelines.data.protocol.FileChange
|
||||
import net.awan.pipelines.data.protocol.NotificationReceipt
|
||||
import net.awan.pipelines.data.protocol.RunDetail
|
||||
import net.awan.pipelines.data.protocol.RunGraphState
|
||||
import net.awan.pipelines.data.protocol.RunStep
|
||||
@@ -75,9 +74,14 @@ import net.awan.pipelines.ui.components.runStateColor
|
||||
import net.awan.pipelines.ui.components.runStateOf
|
||||
import net.awan.pipelines.ui.displayMap
|
||||
import net.awan.pipelines.ui.displayText
|
||||
import net.awan.pipelines.ui.fileChangeLine
|
||||
import net.awan.pipelines.ui.fileChangesSummary
|
||||
import net.awan.pipelines.ui.formatDuration
|
||||
import net.awan.pipelines.ui.graph.StageDetailSheet
|
||||
import net.awan.pipelines.ui.graph.StageField
|
||||
import net.awan.pipelines.ui.graph.WorkflowGraph
|
||||
import net.awan.pipelines.ui.graph.controlVisitLabel
|
||||
import net.awan.pipelines.ui.notificationLine
|
||||
import net.awan.pipelines.ui.theme.pipelinesText
|
||||
import net.awan.pipelines.ui.visitCount
|
||||
|
||||
@@ -515,6 +519,7 @@ private fun RunStepsTab(run: RunDetail, wide: Boolean, modifier: Modifier) {
|
||||
StepCard(
|
||||
step = step,
|
||||
isLast = index == steps.lastIndex,
|
||||
wide = wide,
|
||||
modifier = Modifier.padding(horizontal = 16.dp).animateItem(),
|
||||
)
|
||||
}
|
||||
@@ -528,11 +533,13 @@ private fun RunStepsTab(run: RunDetail, wide: Boolean, modifier: Modifier) {
|
||||
/**
|
||||
* One step as a timeline entry: a leading status glyph in a gutter connected to
|
||||
* the next entry by a line coloured by this step's outcome, the stage name with
|
||||
* its sequence and visit number, an outcome chip and the duration. Every retained
|
||||
* piece of evidence lives behind a collapsible detail, collapsed by default.
|
||||
* its sequence and visit number, an outcome chip and the duration. The step's
|
||||
* metadata is a set of aligned label/value rows (two columns on a wide window,
|
||||
* one on a narrow one) and every retained piece of evidence lives behind a
|
||||
* collapsible detail, collapsed by default.
|
||||
*/
|
||||
@Composable
|
||||
private fun StepCard(step: RunStep, isLast: Boolean, modifier: Modifier = Modifier) {
|
||||
private fun StepCard(step: RunStep, isLast: Boolean, wide: Boolean, modifier: Modifier = Modifier) {
|
||||
val text = pipelinesText()
|
||||
val state = runStateOf(step.outcome.ifBlank { step.status })
|
||||
val color = runStateColor(state)
|
||||
@@ -542,12 +549,16 @@ private fun StepCard(step: RunStep, isLast: Boolean, modifier: Modifier = Modifi
|
||||
label = "step-chevron",
|
||||
)
|
||||
val chipLabel = step.outcome.ifBlank { step.status }.ifBlank { state.label }
|
||||
// Derived once per step change, not per recomposition.
|
||||
val meta = remember(step) { stepMetaFields(step) }
|
||||
val hasDetails = remember(step) { stepHasDetails(step) }
|
||||
|
||||
Row(modifier = modifier.fillMaxWidth().height(IntrinsicSize.Min)) {
|
||||
// Timeline gutter: the status glyph, then a connector line to the next
|
||||
// step (coloured by this step's outcome).
|
||||
// step (coloured by this step's outcome). Kept as the row's first child
|
||||
// so the glyph stays aligned with the step title.
|
||||
Column(
|
||||
modifier = Modifier.fillMaxHeight().width(36.dp).padding(top = 2.dp),
|
||||
modifier = Modifier.fillMaxHeight().width(STEP_GUTTER_WIDTH).padding(top = 2.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
RunStatusIcon(
|
||||
@@ -568,8 +579,8 @@ private fun StepCard(step: RunStep, isLast: Boolean, modifier: Modifier = Modifi
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier.weight(1f).padding(start = 8.dp, bottom = 12.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
modifier = Modifier.weight(1f).padding(start = 8.dp, bottom = STEP_BOTTOM_GAP),
|
||||
verticalArrangement = Arrangement.spacedBy(STEP_CONTENT_GAP),
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
@@ -585,84 +596,132 @@ private fun StepCard(step: RunStep, isLast: Boolean, modifier: Modifier = Modifi
|
||||
StatusChip(label = chipLabel, state = state)
|
||||
}
|
||||
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
Text(step.status, style = text.meta)
|
||||
val duration = formatDuration(step.startedAt, step.finishedAt)
|
||||
if (duration != null) Text("took $duration", style = text.meta)
|
||||
if (step.agentActive) Text("agent active", style = text.meta)
|
||||
}
|
||||
step.control?.let { control ->
|
||||
Text(
|
||||
"visit ${control.visit}/${control.maxVisits}" +
|
||||
(if (control.limitReached) " · limit reached" else "") +
|
||||
(control.modelTarget?.let { " · model $it" } ?: ""),
|
||||
style = text.meta,
|
||||
)
|
||||
}
|
||||
if (step.target.isNotBlank()) Text("target ${step.target}", style = text.meta)
|
||||
if (step.sessionId.isNotBlank()) Text("session ${step.sessionId}", style = text.mono)
|
||||
CodeBlock("Diagnostic", step.diagnostic, Modifier.padding(top = 4.dp))
|
||||
StepMetaGrid(meta, wide)
|
||||
CodeBlock("Diagnostic", step.diagnostic)
|
||||
|
||||
// Evidence is collapsed by default so the timeline stays scannable.
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.clickable { detailsExpanded = !detailsExpanded }
|
||||
.padding(vertical = 4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.KeyboardArrowDown,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(16.dp).rotate(chevron),
|
||||
)
|
||||
Text(if (detailsExpanded) "Hide details" else "Show details", style = text.meta)
|
||||
}
|
||||
// Evidence is collapsed by default so the timeline stays scannable;
|
||||
// a step with nothing to expand shows no toggle (no doubled gap).
|
||||
if (hasDetails) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.clickable { detailsExpanded = !detailsExpanded }
|
||||
.padding(vertical = 4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.KeyboardArrowDown,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(16.dp).rotate(chevron),
|
||||
)
|
||||
Text(if (detailsExpanded) "Hide details" else "Show details", style = text.meta)
|
||||
}
|
||||
|
||||
if (detailsExpanded) {
|
||||
StepEvidence(step)
|
||||
if (detailsExpanded) {
|
||||
StepEvidence(step)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The step's metadata as aligned key/value rows: the fields that naturally pair
|
||||
* sit side by side in two columns on a wide window and stack in one column on a
|
||||
* narrow one. Blank values are skipped, so no empty row is left behind.
|
||||
*/
|
||||
@Composable
|
||||
private fun StepMetaGrid(fields: List<StageField>, wide: Boolean) {
|
||||
val shown = remember(fields) { fields.filter { it.value.isNotBlank() } }
|
||||
if (shown.isEmpty()) return
|
||||
if (wide) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(STEP_META_ROW_GAP)) {
|
||||
shown.chunked(2).forEach { row ->
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(STEP_META_COLUMN_GAP)) {
|
||||
row.forEach { field ->
|
||||
KeyValueRow(
|
||||
label = field.label,
|
||||
value = field.value,
|
||||
modifier = Modifier.weight(1f),
|
||||
monospace = field.mono,
|
||||
)
|
||||
}
|
||||
// Keep a lone trailing field in the first column so paired
|
||||
// fields stay aligned across rows.
|
||||
if (row.size == 1) Spacer(Modifier.weight(1f))
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Column {
|
||||
shown.forEach { field ->
|
||||
KeyValueRow(label = field.label, value = field.value, monospace = field.mono)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The step's always-visible metadata in the intended pairing order (status and
|
||||
* outcome, duration and visit, target and session, agent and model target), with
|
||||
* blanks dropped so [StepMetaGrid] never renders an empty row.
|
||||
*/
|
||||
internal fun stepMetaFields(step: RunStep): List<StageField> = buildList {
|
||||
add(StageField("Status", step.status))
|
||||
add(StageField("Outcome", step.outcome))
|
||||
formatDuration(step.startedAt, step.finishedAt)?.let { add(StageField("Duration", it)) }
|
||||
step.control?.let { control ->
|
||||
if (control.maxVisits > 0 || control.visit > 0) {
|
||||
add(StageField("Visit", controlVisitLabel(control)))
|
||||
}
|
||||
}
|
||||
add(StageField("Target", step.target))
|
||||
add(StageField("Session", step.sessionId, mono = true))
|
||||
if (step.agentActive) add(StageField("Agent", "active"))
|
||||
step.control?.modelTarget?.takeIf { it.isNotBlank() }?.let { add(StageField("Model target", it)) }
|
||||
}.filter { it.value.isNotBlank() }
|
||||
|
||||
/** True when a step has any evidence worth expanding (no toggle otherwise). */
|
||||
internal fun stepHasDetails(step: RunStep): Boolean {
|
||||
if (step.input?.isNotEmpty() == true) return true
|
||||
if (step.output?.isNotEmpty() == true) return true
|
||||
step.fileChanges?.let { changes ->
|
||||
if (changes.status.isNotBlank() || changes.files.isNotEmpty() || changes.skipped > 0) return true
|
||||
}
|
||||
if (step.notifications.orEmpty().any { it.status.isNotBlank() || it.destination.isNotBlank() }) return true
|
||||
return step.transcript.isNotBlank()
|
||||
}
|
||||
|
||||
/**
|
||||
* The expandable evidence: every block is the shared full-width [CodeBlock] with
|
||||
* the same bounded height, so the monospace input, output, file changes,
|
||||
* notifications and transcript line up inside the step's card.
|
||||
*/
|
||||
@Composable
|
||||
private fun StepEvidence(step: RunStep) {
|
||||
val text = pipelinesText()
|
||||
CodeBlock("Input", step.input.displayMap(), maxHeight = STEP_CODE_MAX_HEIGHT)
|
||||
CodeBlock("Output", step.output.displayMap(), maxHeight = STEP_CODE_MAX_HEIGHT)
|
||||
step.fileChanges?.let { changes ->
|
||||
Text(
|
||||
"file changes: ${changes.status}" +
|
||||
(if (changes.files.isNotEmpty()) " (${changes.files.size})" else "") +
|
||||
(if (changes.skipped > 0) " · ${changes.skipped} skipped" else ""),
|
||||
style = text.label,
|
||||
val summary = fileChangesSummary(changes)
|
||||
val files = changes.files.take(MAX_LISTED_FILES).joinToString("\n") { fileChangeLine(it) }
|
||||
CodeBlock(
|
||||
"File changes",
|
||||
listOf(summary, files).filter { it.isNotBlank() }.joinToString("\n"),
|
||||
maxHeight = STEP_CODE_MAX_HEIGHT,
|
||||
)
|
||||
}
|
||||
val notifications = step.notifications.orEmpty()
|
||||
.filter { it.status.isNotBlank() || it.destination.isNotBlank() }
|
||||
if (notifications.isNotEmpty()) {
|
||||
CodeBlock(
|
||||
"Notifications",
|
||||
notifications.joinToString("\n") { notificationLine(it) },
|
||||
maxHeight = STEP_CODE_MAX_HEIGHT,
|
||||
)
|
||||
changes.files.take(MAX_LISTED_FILES).forEach { file -> FileChangeRow(file, text) }
|
||||
}
|
||||
step.notifications.orEmpty().forEach { notification -> NotificationRow(notification, text) }
|
||||
CodeBlock("Transcript", step.transcript, maxHeight = STEP_CODE_MAX_HEIGHT)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun FileChangeRow(file: FileChange, text: net.awan.pipelines.ui.theme.PipelinesTextStyles) {
|
||||
Text(
|
||||
"· ${file.kind} ${file.path}" +
|
||||
(if (file.binary) " (binary)" else "") +
|
||||
(if (file.truncated) " (truncated)" else ""),
|
||||
style = text.mono,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun NotificationRow(receipt: NotificationReceipt, text: net.awan.pipelines.ui.theme.PipelinesTextStyles) {
|
||||
Text(
|
||||
"notification ${receipt.status} → ${receipt.destination}" +
|
||||
(receipt.diagnostic?.let { " · $it" } ?: ""),
|
||||
style = text.mono,
|
||||
)
|
||||
}
|
||||
|
||||
/** A session-evidence entry's fields plus its data/diagnostic code blocks. */
|
||||
@Composable
|
||||
private fun EvidenceDetails(evidence: SessionEvidence, modifier: Modifier = Modifier) {
|
||||
@@ -679,5 +738,18 @@ private fun EvidenceDetails(evidence: SessionEvidence, modifier: Modifier = Modi
|
||||
private const val POLL_INTERVAL_MILLIS = 1_000L
|
||||
private const val MAX_LISTED_FILES = 20
|
||||
|
||||
/** One bottom gap per step (the connector line spans it to the next step). */
|
||||
private val STEP_BOTTOM_GAP = 12.dp
|
||||
|
||||
/** Vertical gap between a step's title, meta grid, diagnostic and evidence. */
|
||||
private val STEP_CONTENT_GAP = 6.dp
|
||||
|
||||
/** Gaps inside the two-column metadata grid (row gap, then column gap). */
|
||||
private val STEP_META_ROW_GAP = 2.dp
|
||||
private val STEP_META_COLUMN_GAP = 12.dp
|
||||
|
||||
/** The timeline gutter holding the status glyph and the connector line. */
|
||||
private val STEP_GUTTER_WIDTH = 36.dp
|
||||
|
||||
/** Step evidence blocks are shorter than a full-page block (they sit in a timeline). */
|
||||
private val STEP_CODE_MAX_HEIGHT = 240.dp
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package net.awan.pipelines.ui
|
||||
|
||||
import net.awan.pipelines.data.protocol.FileChange
|
||||
import net.awan.pipelines.data.protocol.NotificationReceipt
|
||||
import net.awan.pipelines.data.protocol.StageFileChanges
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
@@ -25,4 +28,32 @@ class FormatTest {
|
||||
assertNull(formatDuration("2026-10-15T02:00:00Z", ""))
|
||||
assertNull(formatDuration("2026-10-15T02:05:00Z", "2026-10-15T02:00:00Z"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fileChangesSummaryOmitsBlankParts() {
|
||||
assertEquals("", fileChangesSummary(StageFileChanges()))
|
||||
assertEquals(
|
||||
"success (3 files)",
|
||||
fileChangesSummary(StageFileChanges(status = "success", files = List(3) { FileChange() })),
|
||||
)
|
||||
assertEquals("1 skipped", fileChangesSummary(StageFileChanges(skipped = 1)))
|
||||
assertEquals("success, 1 skipped", fileChangesSummary(StageFileChanges(status = "success", skipped = 1)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fileChangeAndNotificationLinesCarryTheirFlags() {
|
||||
assertEquals(
|
||||
"modified a.kt (binary) (truncated)",
|
||||
fileChangeLine(FileChange(kind = "modified", path = "a.kt", binary = true, truncated = true)),
|
||||
)
|
||||
assertEquals(
|
||||
"delivered → ntfy · ok",
|
||||
notificationLine(NotificationReceipt(status = "delivered", destination = "ntfy", diagnostic = "ok")),
|
||||
)
|
||||
// A blank diagnostic leaves no trailing separator.
|
||||
assertEquals(
|
||||
"delivered → ntfy",
|
||||
notificationLine(NotificationReceipt(status = "delivered", destination = "ntfy")),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.awan.pipelines.ui.components
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class DetailTabsTest {
|
||||
@@ -23,6 +24,19 @@ class DetailTabsTest {
|
||||
assertEquals(false, pipelineDetailTabs.any { it.key == "versions" })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun everyTabCarriesADistinctMeaningfulIcon() {
|
||||
// Every tab has an icon and no two tabs of the same rail share one.
|
||||
listOf(runDetailTabs, pipelineDetailTabs).forEach { tabs ->
|
||||
assertEquals(tabs.size, tabs.map { it.icon.name }.toSet().size)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun collapsedRailIsNarrowerThanExpanded() {
|
||||
assertTrue(railWidthDp(false) < railWidthDp(true))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun clampTabIndexKeepsAValidSelection() {
|
||||
assertEquals(0, clampTabIndex(0, 6))
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
package net.awan.pipelines.ui.graph
|
||||
|
||||
import net.awan.pipelines.data.protocol.ControlEvidence
|
||||
import net.awan.pipelines.data.protocol.Graph
|
||||
import net.awan.pipelines.data.protocol.NotificationPolicy
|
||||
import net.awan.pipelines.data.protocol.RunStep
|
||||
import net.awan.pipelines.data.protocol.Stage
|
||||
import net.awan.pipelines.data.protocol.StageLimits
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class StageDetailSheetTest {
|
||||
|
||||
@Test
|
||||
fun blankStageEmitsOnlyItsType() {
|
||||
val fields = stageDefinitionFields(Stage(key = "planner"))
|
||||
assertEquals(listOf("Type"), fields.map { it.label })
|
||||
assertEquals("model", fields.single().value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun stageDefinitionFieldsSkipBlanksAndLabelEverySection() {
|
||||
val stage = Stage(
|
||||
key = "planner",
|
||||
type = "model",
|
||||
prompt = "do the thing",
|
||||
output = "plan",
|
||||
configs = mapOf("model" to "gpt", "provider" to ""),
|
||||
edges = mapOf("success" to "#", "error" to "cleanup"),
|
||||
blocks = mapOf("tools" to "read_file\nwrite_file"),
|
||||
limits = StageLimits(maxVisits = 3, on = listOf("exceeded")),
|
||||
memory = mapOf("notes" to "notes.md"),
|
||||
notify = NotificationPolicy(
|
||||
on = listOf("failure"),
|
||||
destination = "ntfy",
|
||||
artifacts = listOf("log"),
|
||||
),
|
||||
)
|
||||
val fields = stageDefinitionFields(stage)
|
||||
val labels = fields.map { it.label }
|
||||
assertTrue(
|
||||
labels.containsAll(
|
||||
listOf(
|
||||
"Type", "Prompt", "Output", "Outcomes", "Model", "Tools",
|
||||
"Max visits", "Limit on", "Memory", "Notify on",
|
||||
"Notify destination", "Notify artifacts",
|
||||
),
|
||||
),
|
||||
)
|
||||
// A blank config value is skipped, never rendered as an empty row.
|
||||
assertTrue(fields.none { it.value.isBlank() })
|
||||
val outcomes = fields.first { it.label == "Outcomes" }.value
|
||||
assertTrue(outcomes.contains("success → SUCCESS (terminal)"))
|
||||
assertTrue(outcomes.contains("error → cleanup"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runStepFieldsSkipBlanksAndIncludeTheVisitFormat() {
|
||||
assertEquals(emptyList<StageField>(), runStepFields(RunStep()))
|
||||
val step = RunStep(
|
||||
status = "succeeded",
|
||||
outcome = "success",
|
||||
target = "#success",
|
||||
sessionId = "sess-1",
|
||||
agentActive = true,
|
||||
control = ControlEvidence(visit = 3, maxVisits = 5, limitReached = true, modelTarget = "gpt"),
|
||||
)
|
||||
val fields = runStepFields(step)
|
||||
assertEquals("3 / 5 (limit reached)", fields.first { it.label == "Visit" }.value)
|
||||
assertEquals("active", fields.first { it.label == "Agent" }.value)
|
||||
assertTrue(fields.none { it.value.isBlank() })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun controlVisitLabelHandlesMissingMaxAndLimit() {
|
||||
assertEquals("2", controlVisitLabel(ControlEvidence(visit = 2)))
|
||||
assertEquals("2 / 4", controlVisitLabel(ControlEvidence(visit = 2, maxVisits = 4)))
|
||||
assertEquals(
|
||||
"2 / 4 (limit reached)",
|
||||
controlVisitLabel(ControlEvidence(visit = 2, maxVisits = 4, limitReached = true)),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun terminalFieldsListIncomingRoutesOnly() {
|
||||
val graph = Graph(stages = listOf(Stage(key = "a", edges = mapOf("success" to "#success"))))
|
||||
assertTrue(terminalFields(graph, "a").isEmpty())
|
||||
val incoming = terminalFields(graph, "#success")
|
||||
assertEquals(listOf("Incoming routes"), incoming.map { it.label })
|
||||
assertTrue(incoming.single().value.contains("a · success → SUCCESS"))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package net.awan.pipelines.ui.screens
|
||||
|
||||
import kotlinx.serialization.json.JsonPrimitive
|
||||
import net.awan.pipelines.data.protocol.ControlEvidence
|
||||
import net.awan.pipelines.data.protocol.FileChange
|
||||
import net.awan.pipelines.data.protocol.NotificationReceipt
|
||||
import net.awan.pipelines.data.protocol.RunStep
|
||||
import net.awan.pipelines.data.protocol.StageFileChanges
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class StepMetaTest {
|
||||
|
||||
@Test
|
||||
fun blankStepHasNoMetaRowsAndNoDetails() {
|
||||
assertEquals(emptyList<String>(), stepMetaFields(RunStep()).map { it.label })
|
||||
assertFalse(stepHasDetails(RunStep()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun metaRowsFollowTheIntendedWideWindowPairing() {
|
||||
val step = RunStep(
|
||||
status = "succeeded",
|
||||
outcome = "success",
|
||||
startedAt = "2026-10-15T02:00:00Z",
|
||||
finishedAt = "2026-10-15T02:00:05Z",
|
||||
target = "#success",
|
||||
sessionId = "sess-1",
|
||||
agentActive = true,
|
||||
control = ControlEvidence(visit = 1, maxVisits = 2, modelTarget = "gpt"),
|
||||
)
|
||||
assertEquals(
|
||||
listOf("Status", "Outcome", "Duration", "Visit", "Target", "Session", "Agent", "Model target"),
|
||||
stepMetaFields(step).map { it.label },
|
||||
)
|
||||
// Chunking the rows by two yields the intended wide-window column pairs.
|
||||
val pairs = stepMetaFields(step).chunked(2).map { row -> row.map { it.label } }
|
||||
assertEquals(listOf("Status", "Outcome"), pairs[0])
|
||||
assertEquals(listOf("Duration", "Visit"), pairs[1])
|
||||
assertEquals(listOf("Target", "Session"), pairs[2])
|
||||
assertEquals(listOf("Agent", "Model target"), pairs[3])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun detailsPredicateTracksEveryEvidenceKind() {
|
||||
assertTrue(stepHasDetails(RunStep(input = mapOf("prompt" to JsonPrimitive("x")))))
|
||||
assertTrue(stepHasDetails(RunStep(transcript = "hi")))
|
||||
assertTrue(
|
||||
stepHasDetails(
|
||||
RunStep(fileChanges = StageFileChanges(files = listOf(FileChange(path = "a", kind = "modified")))),
|
||||
),
|
||||
)
|
||||
assertTrue(
|
||||
stepHasDetails(
|
||||
RunStep(notifications = listOf(NotificationReceipt(status = "delivered", destination = "ntfy"))),
|
||||
),
|
||||
)
|
||||
// A blank change set / receipt list is not expandable detail.
|
||||
assertFalse(stepHasDetails(RunStep(fileChanges = StageFileChanges())))
|
||||
assertFalse(stepHasDetails(RunStep(notifications = listOf(NotificationReceipt()))))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user