Give every outcome its own colour and reach stage visits from the Timeline
- GraphPalette: a curated fixed palette plus a deterministic outcome-to-index mapping (no hashCode() % n); every colour is measured at >= 4.5:1 against the dark surface. Node fills differ by kind, and selection inverts the fill. - Run detail: the Steps tab becomes Timeline, one compact line per recorded visit. The stage detail sheet takes the ordered visits plus an initialVisitIndex and shows a visit 1..N tab row only when there is more than one visit; the timeline opens the tapped visit, the graph the most recent. - List pane: pipelines and runs share one ListRow (flat surface, thin divider, leading element, title plus secondary line) with a tonal selected row, and the wide list pane collapses to a 56dp strip. - Navigation: the bottom bar becomes a floating three-icon destination pill at the bottom right with Role.Tab selected semantics, used on both window widths, with 88dp reserved so nothing scrolls under it. - Icons come from the already-declared material-icons-extended; no new dependency. Implemented by pipeline run 55 (pipeline 9 v6). Its ui_reviewer stage failed on a malformed model result rather than on this work, so the change was verified by hand: assembleDebug plus 93 unit tests pass, and the run's captures were reviewed (graph colours per outcome, Timeline entries, visit tabs, selected list row, floating pill).
This commit is contained in:
@@ -358,3 +358,88 @@ device: that Gradle task therefore also (re)installed the debug APK on the
|
||||
attached Pixel 10 Pro Fold; all device-driving commands targeted the emulator
|
||||
serial (`adb -s emulator-5554`) explicitly. The emulator was stopped with
|
||||
`adb emu kill` plus `kill -9` of the surviving `qemu-system-aarch64-headless`.
|
||||
|
||||
## Distinct graph colours, Timeline + visit tabs, real list pane, floating pill
|
||||
|
||||
Four UI changes were 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`. Nothing in the Pipelines server, its Go source,
|
||||
Docker/compose files or the installer was touched, no run was started from the
|
||||
app, and the attached Pixel 10 Pro Fold was never driven (the debug APK was
|
||||
installed with `adb -s emulator-5554 install -r`, not `:app:installDebug`, so the
|
||||
physical device was not re-installed by this pass either).
|
||||
|
||||
- **Graph colours.** `GraphPalette` is a curated, fixed palette plus a pure
|
||||
deterministic outcome→index mapping (no `hashCode() % 4`). `error` stays the
|
||||
theme error role and `success` the theme tertiary (positive); every other
|
||||
outcome uses one palette colour for both its edge stroke and its label text.
|
||||
Node fills differ by kind (`GraphNodeKind`: terminal success, terminal failure,
|
||||
model, ntfy, other/custom); a selected stage inverts (light fill / dark text)
|
||||
plus a 4px border, and executed-vs-dimmed alpha still applies on top. WCAG
|
||||
contrast is *measured*: `GraphPaletteTest` checks the helper against known
|
||||
reference ratios (white/black 21, `#777`/white 4.48) and asserts every palette
|
||||
colour is ≥ 4.5:1 against `DarkSurface 0xFF0E1513` (measured values range from
|
||||
8.63:1, `approved`, to 13.78:1, `fast`; `success` 11.73:1 and `error` 10.89:1 as
|
||||
the dark scheme supplies them).
|
||||
- **Timeline + visit tabs.** The run-detail `Steps` tab is renamed `Timeline`
|
||||
(key kept `steps`); it renders one compact line per recorded visit (stage,
|
||||
visit number, outcome chip, duration and a brief diagnostic/target description)
|
||||
and nothing else — the heavy evidence moved entirely into the shared
|
||||
`StageDetailSheet`. The sheet now takes a stage's ordered `runSteps` plus an
|
||||
`initialVisitIndex` and shows a `visit 1..N` tab row only when there is more
|
||||
than one visit; the timeline opens on the tapped visit and the graph on the
|
||||
most recent. `runStepFields` gained the step Input/Output blocks, so the sheet
|
||||
still carries status, outcome, duration, visit/max/limit, model target, target,
|
||||
session, agent, diagnostic, transcript, input, output, file changes,
|
||||
notifications and the stage definition.
|
||||
- **Real list pane.** Pipelines and runs now share one `ListRow` (a single flat
|
||||
`Surface`, thin `HorizontalDivider`, leading element + title + secondary line,
|
||||
no per-row elevation) instead of a card per item. The selected row uses the
|
||||
same tonal `secondaryContainer`/`onSecondaryContainer` treatment as the tab
|
||||
rail and destinations, exposed as `selectable` selected state; opening a row
|
||||
selects it and Back clears it. The wide list pane collapses to a 56dp strip
|
||||
(`rememberSaveable`), with the freed width going to the detail.
|
||||
- **Floating destination pill.** The bottom `NavigationBar` is replaced by a
|
||||
floating rounded `Surface` at the bottom right holding the three destinations
|
||||
as 48dp icon targets, inset by the Scaffold's system-bar padding plus 16dp;
|
||||
selected state is a tonal circle plus `Role.Tab` selected semantics (not colour
|
||||
alone). The same pill is used on **both** window widths (no compact strip);
|
||||
the app reserves 88dp at the bottom so no scrollable content is hidden behind
|
||||
it.
|
||||
- **Icons.** Icons are taken from `material-icons-extended` (already declared in
|
||||
`app/build.gradle.kts`/`libs.versions.toml`, BOM-managed — no new dependency
|
||||
and no non-offline Gradle invocation was needed; the artifact was already in
|
||||
the cache). Mapping: Pipelines → `AccountTree`, Runs → `History`, Settings →
|
||||
`Settings`; Graph tab → `Hub`, Timeline → `AutoMirrored.List`, Input →
|
||||
`AutoMirrored.Input`, Output → `AutoMirrored.Send`, Evidence →
|
||||
`AutoMirrored.FactCheck`, Source → `Code`; run statuses → Running
|
||||
`AutoMirrored.DirectionsRun`, Queued `Schedule`, Succeeded `CheckCircle`,
|
||||
Failed `Error`, Canceled `Cancel`, Interrupted `PauseCircle`, Active `Bolt`,
|
||||
Unknown `AutoMirrored.HelpOutline`. The debug APK is ~17 MB; note that
|
||||
`app/build.gradle.kts` sets `release { isMinifyEnabled = false }`, so R8 does
|
||||
**not** strip unused extended icons in the current release config (that
|
||||
stripping only applies to a minified build).
|
||||
- `:app:testDebugUnitTest` reported **93 tests, 0 failures** (new
|
||||
`GraphPaletteTest`, `TimelineTest`, `PipelinesNavTest`; extended
|
||||
`StageDetailSheetTest` and `DetailTabsTest`; `StepMetaTest` was removed with the
|
||||
inline metadata grid it covered). `:app:assembleDebug` succeeded.
|
||||
- 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/nav_timeline_pass/` (git-ignored):
|
||||
`01_launch`, `02_runs_narrow` (narrow lists + pill), `04_timeline` (the concise
|
||||
Timeline tab), `05_sheet_from_timeline_visits` (sheet from the timeline opening
|
||||
on the tapped visit 1, with visit tabs), `05b_sheet_single_visit_no_tabs` (a
|
||||
single-visit stage shows no tab row), `06_sheet_run_section` (Input/Output in
|
||||
the sheet), `07_run_graph` (executed route highlighted), `08_sheet_from_graph`
|
||||
(same stage opened from the graph, on the most recent visit 2),
|
||||
`09_pipeline_4stage_graph` + `_2x`, `10_pipeline_1stage_graph` + `_2x`,
|
||||
`11_wide_pane_expanded`, `12_wide_pane_selected`, `13_wide_pane_collapsed`,
|
||||
`14_wide_runs_pane`, `15_wide_run_detail`, and the icon close crops
|
||||
`16_pill_wide_2x`, `17_tabs_wide_2x`, `18_runstatus_icons_2x`,
|
||||
`18b_failed_status_2x`, `19_pill_narrow_2x`.
|
||||
- `adb -s emulator-5554 logcat -d` contained 0 `FATAL EXCEPTION` lines and no
|
||||
Compose runtime exception. The wide layout was exercised with
|
||||
`adb shell wm size 2000x3400` (≈820dp at density 390); the emulator was stopped
|
||||
with `adb emu kill` plus `kill -9` of any surviving
|
||||
`qemu-system-aarch64-headless`.
|
||||
|
||||
|
||||
@@ -1,21 +1,29 @@
|
||||
package net.awan.pipelines.ui
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.selection.selectable
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.List
|
||||
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowLeft
|
||||
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
|
||||
import androidx.compose.material.icons.filled.AccountTree
|
||||
import androidx.compose.material.icons.filled.History
|
||||
import androidx.compose.material.icons.filled.Settings
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.NavigationBar
|
||||
import androidx.compose.material3.NavigationBarItem
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.VerticalDivider
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -24,9 +32,13 @@ import androidx.compose.runtime.mutableLongStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
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.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.navigation.NavType
|
||||
@@ -46,11 +58,21 @@ import net.awan.pipelines.ui.screens.SettingsScreen
|
||||
private data class TopDestination(val route: String, val label: String, val icon: ImageVector)
|
||||
|
||||
private val destinations = listOf(
|
||||
TopDestination("pipelines", "Pipelines", Icons.AutoMirrored.Filled.List),
|
||||
TopDestination("pipelines", "Pipelines", Icons.Default.AccountTree),
|
||||
TopDestination("runs", "Runs", Icons.Default.History),
|
||||
TopDestination("settings", "Settings", Icons.Default.Settings),
|
||||
)
|
||||
|
||||
/**
|
||||
* Whether [route]'s destination is the current one. A detail route
|
||||
* (`pipeline/…`/`run/…`) belongs to its list destination, so the floating pill
|
||||
* keeps the right destination selected while a detail is open.
|
||||
*/
|
||||
internal fun destinationSelected(currentRoute: String?, route: String): Boolean =
|
||||
currentRoute == route ||
|
||||
(route == "pipelines" && currentRoute?.startsWith("pipeline/") == true) ||
|
||||
(route == "runs" && currentRoute?.startsWith("run/") == true)
|
||||
|
||||
@Composable
|
||||
fun PipelinesApp(vm: AppViewModel) {
|
||||
val navController = rememberNavController()
|
||||
@@ -62,88 +84,151 @@ fun PipelinesApp(vm: AppViewModel) {
|
||||
// display stays single-pane, its wide inner display shows list + detail.
|
||||
val wide = isWideLayout(LocalConfiguration.current.screenWidthDp)
|
||||
|
||||
Scaffold(
|
||||
bottomBar = {
|
||||
NavigationBar {
|
||||
destinations.forEach { destination ->
|
||||
val selected = currentRoute == destination.route ||
|
||||
(destination.route == "pipelines" && currentRoute?.startsWith("pipeline/") == true) ||
|
||||
(destination.route == "runs" && currentRoute?.startsWith("run/") == true)
|
||||
NavigationBarItem(
|
||||
selected = selected,
|
||||
onClick = {
|
||||
if (currentRoute != destination.route) {
|
||||
navController.navigate(destination.route) {
|
||||
popUpTo("pipelines") { inclusive = destination.route == "pipelines" }
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
},
|
||||
icon = { Icon(destination.icon, contentDescription = destination.label) },
|
||||
label = { Text(destination.label) },
|
||||
)
|
||||
}
|
||||
val onNavigate: (TopDestination) -> Unit = { destination ->
|
||||
if (currentRoute != destination.route) {
|
||||
navController.navigate(destination.route) {
|
||||
popUpTo("pipelines") { inclusive = destination.route == "pipelines" }
|
||||
launchSingleTop = true
|
||||
}
|
||||
},
|
||||
) { padding ->
|
||||
Column(Modifier.padding(padding)) {
|
||||
ConnectionBanner(
|
||||
state = connectionState,
|
||||
configuredUrl = configuredUrl,
|
||||
onReconnect = vm::reconnect,
|
||||
)
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = "pipelines",
|
||||
modifier = Modifier.weight(1f),
|
||||
) {
|
||||
composable("pipelines") {
|
||||
if (wide) {
|
||||
WidePipelinePane(
|
||||
}
|
||||
}
|
||||
|
||||
// No bottomBar: the destinations float over the content as a pill (below).
|
||||
// Scaffold still applies the system-bar insets to [padding], so the pill
|
||||
// clears the navigation bar/gesture area; the Column reserves
|
||||
// DESTINATION_PILL_RESERVE at the bottom so no scrollable content is
|
||||
// permanently hidden behind it. The same pill is used on both window widths.
|
||||
Scaffold { padding ->
|
||||
Box(Modifier.fillMaxSize().padding(padding)) {
|
||||
Column(Modifier.fillMaxSize().padding(bottom = DESTINATION_PILL_RESERVE)) {
|
||||
ConnectionBanner(
|
||||
state = connectionState,
|
||||
configuredUrl = configuredUrl,
|
||||
onReconnect = vm::reconnect,
|
||||
)
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = "pipelines",
|
||||
modifier = Modifier.weight(1f),
|
||||
) {
|
||||
composable("pipelines") {
|
||||
if (wide) {
|
||||
WidePipelinePane(
|
||||
vm = vm,
|
||||
onOpenRun = { runId -> navController.navigate("run/$runId") },
|
||||
)
|
||||
} else {
|
||||
PipelineListScreen(vm, onOpen = { id, version ->
|
||||
navController.navigate("pipeline/$id/$version")
|
||||
})
|
||||
}
|
||||
}
|
||||
composable(
|
||||
route = "pipeline/{id}/{version}",
|
||||
arguments = listOf(
|
||||
navArgument("id") { type = NavType.LongType },
|
||||
navArgument("version") { type = NavType.IntType },
|
||||
),
|
||||
) { entry ->
|
||||
PipelineDetailScreen(
|
||||
vm = vm,
|
||||
pipelineId = entry.arguments?.getLong("id") ?: 0L,
|
||||
version = entry.arguments?.getInt("version") ?: 0,
|
||||
onBack = { navController.popBackStack() },
|
||||
onOpenRun = { runId -> navController.navigate("run/$runId") },
|
||||
)
|
||||
} else {
|
||||
PipelineListScreen(vm, onOpen = { id, version ->
|
||||
navController.navigate("pipeline/$id/$version")
|
||||
})
|
||||
}
|
||||
composable("runs") {
|
||||
if (wide) {
|
||||
WideRunPane(vm)
|
||||
} else {
|
||||
RunHistoryScreen(vm, onOpenRun = { runId -> navController.navigate("run/$runId") })
|
||||
}
|
||||
}
|
||||
composable(
|
||||
route = "run/{id}",
|
||||
arguments = listOf(navArgument("id") { type = NavType.LongType }),
|
||||
) { entry ->
|
||||
RunDetailScreen(
|
||||
vm = vm,
|
||||
runId = entry.arguments?.getLong("id") ?: 0L,
|
||||
onBack = { navController.popBackStack() },
|
||||
)
|
||||
}
|
||||
composable("settings") {
|
||||
SettingsScreen(vm)
|
||||
}
|
||||
}
|
||||
composable(
|
||||
route = "pipeline/{id}/{version}",
|
||||
arguments = listOf(
|
||||
navArgument("id") { type = NavType.LongType },
|
||||
navArgument("version") { type = NavType.IntType },
|
||||
),
|
||||
) { entry ->
|
||||
PipelineDetailScreen(
|
||||
vm = vm,
|
||||
pipelineId = entry.arguments?.getLong("id") ?: 0L,
|
||||
version = entry.arguments?.getInt("version") ?: 0,
|
||||
onBack = { navController.popBackStack() },
|
||||
onOpenRun = { runId -> navController.navigate("run/$runId") },
|
||||
}
|
||||
DestinationPill(
|
||||
destinations = destinations,
|
||||
currentRoute = currentRoute,
|
||||
onSelect = onNavigate,
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomEnd)
|
||||
.padding(end = 16.dp, bottom = 16.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The Pipelines/Runs/Settings destinations as a floating rounded pill at the
|
||||
* bottom right: the three destinations as icons, inset from the bottom/right
|
||||
* edges (the Scaffold padding applies the system-bar insets), each a 48dp touch
|
||||
* target. Selection is a tonal container plus the `Role.Tab` selected
|
||||
* accessibility state — never colour alone — and tapping switches destination
|
||||
* through the caller's existing navigate/popUpTo logic.
|
||||
*/
|
||||
@Composable
|
||||
private fun DestinationPill(
|
||||
destinations: List<TopDestination>,
|
||||
currentRoute: String?,
|
||||
onSelect: (TopDestination) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
Surface(
|
||||
modifier = modifier,
|
||||
shape = RoundedCornerShape(50),
|
||||
color = MaterialTheme.colorScheme.surfaceContainerHigh,
|
||||
tonalElevation = 3.dp,
|
||||
shadowElevation = 6.dp,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.padding(4.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
destinations.forEach { destination ->
|
||||
val selected = destinationSelected(currentRoute, destination.route)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(48.dp)
|
||||
.clip(CircleShape)
|
||||
.background(
|
||||
if (selected) {
|
||||
MaterialTheme.colorScheme.secondaryContainer
|
||||
} else {
|
||||
Color.Transparent
|
||||
},
|
||||
)
|
||||
.selectable(
|
||||
selected = selected,
|
||||
role = Role.Tab,
|
||||
onClick = { onSelect(destination) },
|
||||
),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Icon(
|
||||
imageVector = destination.icon,
|
||||
contentDescription = destination.label,
|
||||
tint = if (selected) {
|
||||
MaterialTheme.colorScheme.onSecondaryContainer
|
||||
} else {
|
||||
MaterialTheme.colorScheme.onSurfaceVariant
|
||||
},
|
||||
)
|
||||
}
|
||||
composable("runs") {
|
||||
if (wide) {
|
||||
WideRunPane(vm)
|
||||
} else {
|
||||
RunHistoryScreen(vm, onOpenRun = { runId -> navController.navigate("run/$runId") })
|
||||
}
|
||||
}
|
||||
composable(
|
||||
route = "run/{id}",
|
||||
arguments = listOf(navArgument("id") { type = NavType.LongType }),
|
||||
) { entry ->
|
||||
RunDetailScreen(
|
||||
vm = vm,
|
||||
runId = entry.arguments?.getLong("id") ?: 0L,
|
||||
onBack = { navController.popBackStack() },
|
||||
)
|
||||
}
|
||||
composable("settings") {
|
||||
SettingsScreen(vm)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,23 +237,33 @@ fun PipelinesApp(vm: AppViewModel) {
|
||||
/**
|
||||
* Wide Pipelines destination: the pipeline list beside the selected pipeline's
|
||||
* tabs. The selection is remembered across config changes and Back inside the
|
||||
* detail clears it (rather than popping a route that is not on the stack).
|
||||
* detail clears it (rather than popping a route that is not on the stack). The
|
||||
* list pane collapses to a narrow strip (remembered/saved across configuration
|
||||
* changes); the freed width goes to the detail.
|
||||
*/
|
||||
@Composable
|
||||
private fun WidePipelinePane(vm: AppViewModel, onOpenRun: (Long) -> Unit) {
|
||||
var selectedId by rememberSaveable { mutableStateOf<Long?>(null) }
|
||||
var selectedVersion by rememberSaveable { mutableIntStateOf(0) }
|
||||
var paneExpanded by rememberSaveable { mutableStateOf(true) }
|
||||
Row(Modifier.fillMaxSize()) {
|
||||
Box(Modifier.width(LIST_PANE_WIDTH).fillMaxHeight()) {
|
||||
PipelineListScreen(
|
||||
vm,
|
||||
onOpen = { id, version ->
|
||||
selectedId = id
|
||||
selectedVersion = version
|
||||
},
|
||||
)
|
||||
if (paneExpanded) {
|
||||
Box(Modifier.width(LIST_PANE_WIDTH).fillMaxHeight()) {
|
||||
PipelineListScreen(
|
||||
vm,
|
||||
onOpen = { id, version ->
|
||||
selectedId = id
|
||||
selectedVersion = version
|
||||
},
|
||||
selectedId = selectedId,
|
||||
onTogglePane = { paneExpanded = false },
|
||||
)
|
||||
}
|
||||
VerticalDivider()
|
||||
} else {
|
||||
CollapsedListPane(paneExpanded = false, onToggle = { paneExpanded = true })
|
||||
VerticalDivider()
|
||||
}
|
||||
VerticalDivider()
|
||||
Box(Modifier.weight(1f).fillMaxHeight()) {
|
||||
val id = selectedId
|
||||
if (id == null) {
|
||||
@@ -190,19 +285,31 @@ private fun WidePipelinePane(vm: AppViewModel, onOpenRun: (Long) -> Unit) {
|
||||
/**
|
||||
* Wide Runs destination: the run list beside the selected run's tabs. The
|
||||
* selection is remembered across config changes and Back inside the detail clears
|
||||
* it instead of popping.
|
||||
* it instead of popping. The list pane collapses to a narrow strip exactly like
|
||||
* the pipelines pane.
|
||||
*/
|
||||
@Composable
|
||||
private fun WideRunPane(vm: AppViewModel) {
|
||||
var selectedRunId by rememberSaveable { mutableLongStateOf(0L) }
|
||||
var paneExpanded by rememberSaveable { mutableStateOf(true) }
|
||||
Row(Modifier.fillMaxSize()) {
|
||||
Box(Modifier.width(LIST_PANE_WIDTH).fillMaxHeight()) {
|
||||
RunHistoryScreen(vm, onOpenRun = { selectedRunId = it })
|
||||
if (paneExpanded) {
|
||||
Box(Modifier.width(LIST_PANE_WIDTH).fillMaxHeight()) {
|
||||
RunHistoryScreen(
|
||||
vm,
|
||||
onOpenRun = { selectedRunId = it },
|
||||
selectedRunId = selectedRunId,
|
||||
onTogglePane = { paneExpanded = false },
|
||||
)
|
||||
}
|
||||
VerticalDivider()
|
||||
} else {
|
||||
CollapsedListPane(paneExpanded = false, onToggle = { paneExpanded = true })
|
||||
VerticalDivider()
|
||||
}
|
||||
VerticalDivider()
|
||||
Box(Modifier.weight(1f).fillMaxHeight()) {
|
||||
if (selectedRunId == 0L) {
|
||||
EmptyState("Select a run to see its Summary, Graph, Input, Output, Evidence and Steps.")
|
||||
EmptyState("Select a run to see its Summary, Graph, Input, Output, Evidence and Timeline.")
|
||||
} else {
|
||||
RunDetailScreen(
|
||||
vm = vm,
|
||||
@@ -215,5 +322,36 @@ private fun WideRunPane(vm: AppViewModel) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The collapsed list pane: a narrow strip holding only the control that restores
|
||||
* the pane, with an accurate accessibility label. Reuses the tab rail's
|
||||
* chevron-toggle idiom.
|
||||
*/
|
||||
@Composable
|
||||
private fun CollapsedListPane(paneExpanded: Boolean, onToggle: () -> Unit) {
|
||||
Column(
|
||||
modifier = Modifier.width(COLLAPSED_LIST_PANE_WIDTH).fillMaxHeight(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
IconButton(onClick = onToggle, modifier = Modifier.padding(top = 8.dp)) {
|
||||
Icon(
|
||||
imageVector = if (paneExpanded) {
|
||||
Icons.AutoMirrored.Filled.KeyboardArrowLeft
|
||||
} else {
|
||||
Icons.AutoMirrored.Filled.KeyboardArrowRight
|
||||
},
|
||||
contentDescription = if (paneExpanded) "Collapse list pane" else "Expand list pane",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Width of the master list pane in the wide two-pane layout. */
|
||||
private val LIST_PANE_WIDTH = 360.dp
|
||||
|
||||
/** Width of the collapsed master list pane (its restore control only). */
|
||||
private val COLLAPSED_LIST_PANE_WIDTH = 56.dp
|
||||
|
||||
/** Bottom space reserved for the floating destination pill, so content is never
|
||||
* permanently hidden behind it (pill height + its margins + a small gap). */
|
||||
private val DESTINATION_PILL_RESERVE = 88.dp
|
||||
|
||||
@@ -15,15 +15,15 @@ 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.FactCheck
|
||||
import androidx.compose.material.icons.automirrored.filled.Input
|
||||
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.Code
|
||||
import androidx.compose.material.icons.filled.Hub
|
||||
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
|
||||
@@ -59,18 +59,18 @@ 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", Icons.Default.Info),
|
||||
DetailTab("graph", "Graph", Icons.Default.Share),
|
||||
DetailTab("input", "Input", Icons.Default.Create),
|
||||
DetailTab("graph", "Graph", Icons.Default.Hub),
|
||||
DetailTab("input", "Input", Icons.AutoMirrored.Filled.Input),
|
||||
DetailTab("output", "Output", Icons.AutoMirrored.Filled.Send),
|
||||
DetailTab("evidence", "Evidence", Icons.Default.MailOutline),
|
||||
DetailTab("steps", "Steps", Icons.AutoMirrored.Filled.List),
|
||||
DetailTab("evidence", "Evidence", Icons.AutoMirrored.Filled.FactCheck),
|
||||
DetailTab("steps", "Timeline", Icons.AutoMirrored.Filled.List),
|
||||
)
|
||||
|
||||
/** Pipeline-detail tabs, Summary first (the version list lives inside it). */
|
||||
val pipelineDetailTabs: List<DetailTab> = listOf(
|
||||
DetailTab("summary", "Summary", Icons.Default.Info),
|
||||
DetailTab("graph", "Graph", Icons.Default.Share),
|
||||
DetailTab("source", "Source", Icons.Default.Email),
|
||||
DetailTab("graph", "Graph", Icons.Default.Hub),
|
||||
DetailTab("source", "Source", Icons.Default.Code),
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package net.awan.pipelines.ui.components
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.selection.selectable
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
/**
|
||||
* One row of the shared real list used by the wide pipelines/runs panes (and the
|
||||
* narrow list, so both stay identical).
|
||||
*
|
||||
* It is a single flat [Surface] — no per-row card or elevation — with a leading
|
||||
* element, a title/secondary content column and a thin divider closing the row,
|
||||
* so a stack of rows reads as one continuous list rather than a grid of tiles.
|
||||
*
|
||||
* The selected row uses the same tonal selected container as the wide rail and
|
||||
* the bottom destinations ([MaterialTheme.colorScheme.secondaryContainer] with
|
||||
* `onSecondaryContainer` content) and exposes its selection through
|
||||
* `selectable`'s accessibility selected state, so selection is never conveyed by
|
||||
* colour alone.
|
||||
*/
|
||||
@Composable
|
||||
fun ListRow(
|
||||
selected: Boolean,
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
leading: (@Composable () -> Unit)? = null,
|
||||
role: Role = Role.Button,
|
||||
content: @Composable ColumnScope.() -> Unit,
|
||||
) {
|
||||
val scheme = MaterialTheme.colorScheme
|
||||
val container = if (selected) scheme.secondaryContainer else Color.Transparent
|
||||
val contentColor = if (selected) scheme.onSecondaryContainer else LocalContentColor.current
|
||||
Surface(
|
||||
color = container,
|
||||
contentColor = contentColor,
|
||||
tonalElevation = 0.dp,
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.selectable(selected = selected, role = role, onClick = onClick),
|
||||
) {
|
||||
Column {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 10.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
leading?.invoke()
|
||||
Column(
|
||||
modifier = Modifier.weight(1f),
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||
) {
|
||||
content()
|
||||
}
|
||||
}
|
||||
HorizontalDivider(color = scheme.outlineVariant)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,14 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.DirectionsRun
|
||||
import androidx.compose.material.icons.automirrored.filled.HelpOutline
|
||||
import androidx.compose.material.icons.filled.Bolt
|
||||
import androidx.compose.material.icons.filled.Cancel
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Info
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
import androidx.compose.material.icons.filled.Warning
|
||||
import androidx.compose.material.icons.filled.Error
|
||||
import androidx.compose.material.icons.filled.PauseCircle
|
||||
import androidx.compose.material.icons.filled.Schedule
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
@@ -20,11 +23,7 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.SolidColor
|
||||
import androidx.compose.ui.graphics.StrokeCap
|
||||
import androidx.compose.ui.graphics.StrokeJoin
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.graphics.vector.path
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import net.awan.pipelines.ui.theme.pipelinesText
|
||||
@@ -74,22 +73,23 @@ fun runStateColor(state: RunState): Color = when (state) {
|
||||
RunState.Canceled, RunState.Unknown -> MaterialTheme.colorScheme.onSurfaceVariant
|
||||
}
|
||||
|
||||
/** A distinct glyph per state so the state is readable without the words. */
|
||||
/** A distinct glyph per state, all from the standard filled material icon set. */
|
||||
fun runStateIcon(state: RunState): ImageVector = when (state) {
|
||||
RunState.Running -> RunningIcon
|
||||
RunState.Queued -> QueuedIcon
|
||||
RunState.Running -> Icons.AutoMirrored.Filled.DirectionsRun
|
||||
RunState.Queued -> Icons.Default.Schedule
|
||||
RunState.Succeeded -> Icons.Default.CheckCircle
|
||||
RunState.Failed -> Icons.Default.Warning
|
||||
RunState.Canceled -> Icons.Default.Close
|
||||
RunState.Interrupted -> InterruptedIcon
|
||||
RunState.Active -> Icons.Default.PlayArrow
|
||||
RunState.Unknown -> Icons.Default.Info
|
||||
RunState.Failed -> Icons.Default.Error
|
||||
RunState.Canceled -> Icons.Default.Cancel
|
||||
RunState.Interrupted -> Icons.Default.PauseCircle
|
||||
RunState.Active -> Icons.Default.Bolt
|
||||
RunState.Unknown -> Icons.AutoMirrored.Filled.HelpOutline
|
||||
}
|
||||
|
||||
/**
|
||||
* A state glyph with an accurate [contentDescription]. The glyphs come from the
|
||||
* core icon set or the small local [ImageVector]s below; the extended icon pack
|
||||
* is not used, so state is never conveyed by colour alone.
|
||||
* A state glyph with an accurate [contentDescription]. Every glyph comes from the
|
||||
* standard filled material icon set (the extended pack is declared as a
|
||||
* dependency), all the same weight/family, so state is never conveyed by colour
|
||||
* alone.
|
||||
*/
|
||||
@Composable
|
||||
fun RunStatusIcon(
|
||||
@@ -137,66 +137,3 @@ fun StatusChip(
|
||||
fun RunStatusChip(state: RunState, modifier: Modifier = Modifier) {
|
||||
StatusChip(label = state.label, state = state, modifier = modifier)
|
||||
}
|
||||
|
||||
// --- Local glyphs (core set has no equivalent) ---------------------------------
|
||||
|
||||
/** A live "activity" pulse, used for a running run/step. */
|
||||
private val RunningIcon: ImageVector = strokeIcon("Running") {
|
||||
moveTo(3f, 12f)
|
||||
lineTo(7f, 12f)
|
||||
lineTo(9.5f, 6f)
|
||||
lineTo(13f, 18f)
|
||||
lineTo(15.5f, 12f)
|
||||
lineTo(21f, 12f)
|
||||
}
|
||||
|
||||
/** A clock, used for a queued run. */
|
||||
private val QueuedIcon: ImageVector = strokeIcon("Queued") {
|
||||
moveTo(12f, 3f)
|
||||
curveTo(16.97f, 3f, 21f, 7.03f, 21f, 12f)
|
||||
curveTo(21f, 16.97f, 16.97f, 21f, 12f, 21f)
|
||||
curveTo(7.03f, 21f, 3f, 16.97f, 3f, 12f)
|
||||
curveTo(3f, 7.03f, 7.03f, 3f, 12f, 3f)
|
||||
close()
|
||||
moveTo(12f, 7f)
|
||||
lineTo(12f, 12f)
|
||||
lineTo(16f, 14f)
|
||||
}
|
||||
|
||||
/** Pause bars, used for an interrupted run (distinct from the failed warning). */
|
||||
private val InterruptedIcon: ImageVector = ImageVector.Builder(
|
||||
name = "Interrupted",
|
||||
defaultWidth = 24.dp,
|
||||
defaultHeight = 24.dp,
|
||||
viewportWidth = 24f,
|
||||
viewportHeight = 24f,
|
||||
).path(fill = SolidColor(Color.Black)) {
|
||||
moveTo(8f, 5f)
|
||||
lineTo(8f, 19f)
|
||||
lineTo(11f, 19f)
|
||||
lineTo(11f, 5f)
|
||||
close()
|
||||
moveTo(13f, 5f)
|
||||
lineTo(13f, 19f)
|
||||
lineTo(16f, 19f)
|
||||
lineTo(16f, 5f)
|
||||
close()
|
||||
}.build()
|
||||
|
||||
/** Builds a stroke-only 24dp glyph from a path block. */
|
||||
private fun strokeIcon(name: String, block: androidx.compose.ui.graphics.vector.PathBuilder.() -> Unit): ImageVector =
|
||||
ImageVector.Builder(
|
||||
name = name,
|
||||
defaultWidth = 24.dp,
|
||||
defaultHeight = 24.dp,
|
||||
viewportWidth = 24f,
|
||||
viewportHeight = 24f,
|
||||
).path(
|
||||
fill = null,
|
||||
stroke = SolidColor(Color.Black),
|
||||
strokeLineWidth = 1.8f,
|
||||
strokeLineCap = StrokeCap.Round,
|
||||
strokeLineJoin = StrokeJoin.Round,
|
||||
) {
|
||||
this.block()
|
||||
}.build()
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
package net.awan.pipelines.ui.graph
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import net.awan.pipelines.data.protocol.Protocol
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
import kotlin.math.pow
|
||||
|
||||
/**
|
||||
* The curated graph colour palette.
|
||||
*
|
||||
* Every distinct outcome gets its own deliberate entry (no `hashCode() % 4`
|
||||
* collisions): the mapping is pure and deterministic, so a given outcome name is
|
||||
* the same colour across runs and recompositions, and an unknown/new name gets a
|
||||
* stable reserved fallback colour instead of silently borrowing a known one.
|
||||
*
|
||||
* The palette is tuned for the dark Pipelines surface (DarkSurface `0xFF0E1513`,
|
||||
* over which the outcome label is drawn on a ~0.92-alpha chip). Every entry is
|
||||
* bright enough to be legible both as a 3px edge stroke and as the small 11sp
|
||||
* label text: contrast is *measured* by [GraphPaletteTest], not asserted by eye.
|
||||
*
|
||||
* The two terminal outcomes stay theme roles in [GraphColors] (`error`→error,
|
||||
* `success`→tertiary) so their meaning is preserved; everything else uses
|
||||
* [colors].
|
||||
*/
|
||||
internal object GraphPalette {
|
||||
|
||||
/**
|
||||
* The fixed palette. Deliberately fixed (rather than scheme-derived) so an
|
||||
* outcome is the same colour on every device; the two terminal roles above
|
||||
* remain scheme roles.
|
||||
*/
|
||||
val colors: List<Color> = listOf(
|
||||
Color(0xFF8FE0A0), // 0 blocked - green
|
||||
Color(0xFFF5A3A3), // 1 rejected - red
|
||||
Color(0xFF8FB4F5), // 2 skipped - blue
|
||||
Color(0xFFF5B37A), // 3 exhausted - orange
|
||||
Color(0xFF7FD4E8), // 4 retry - cyan
|
||||
Color(0xFFC0A3F5), // 5 approved - violet
|
||||
Color(0xFFF0E07A), // 6 fast - yellow
|
||||
Color(0xFFF5A3D0), // 7 missing - pink
|
||||
Color(0xFFD6B08C), // 8 done - sand
|
||||
// Reserved fallback region for names not in [KNOWN], kept distinct from
|
||||
// the known entries so an unknown outcome never borrows a known colour.
|
||||
Color(0xFFD8C98A), // 9 fallback - khaki
|
||||
Color(0xFF9FD8C0), // 10 fallback - sea
|
||||
Color(0xFFD8A8C0), // 11 fallback - dusty rose
|
||||
)
|
||||
|
||||
/** The known outcome names and their fixed palette index, in display order. */
|
||||
private val KNOWN: Map<String, Int> = linkedMapOf(
|
||||
"blocked" to 0,
|
||||
"rejected" to 1,
|
||||
"skipped" to 2,
|
||||
"exhausted" to 3,
|
||||
"retry" to 4,
|
||||
"approved" to 5,
|
||||
"fast" to 6,
|
||||
"missing" to 7,
|
||||
"done" to 8,
|
||||
)
|
||||
|
||||
/** First palette index reserved for names that are not in [KNOWN]. */
|
||||
private val FALLBACK_START = KNOWN.size
|
||||
|
||||
/**
|
||||
* The palette index for [outcome]. Pure and deterministic for every input
|
||||
* (including blank): known names get their curated slot, everything else a
|
||||
* stable slot inside the reserved fallback region. `success`/`error` resolve
|
||||
* to the theme roles in [outcomeColor] but still return a stable index here.
|
||||
*/
|
||||
fun outcomeColorIndex(outcome: String): Int {
|
||||
KNOWN[outcome]?.let { return it }
|
||||
val fallbackCount = colors.size - FALLBACK_START
|
||||
if (fallbackCount <= 0) return 0
|
||||
return FALLBACK_START + abs(outcome.hashCode()) % fallbackCount
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Which kind of thing a graph node is, used to give the nodes genuinely distinct
|
||||
* fills: terminals versus stages, and a stage's effective type (model / ntfy /
|
||||
* other). Mirrors [effectiveStageType], so a blank type is the model stage.
|
||||
*/
|
||||
internal enum class GraphNodeKind { TerminalSuccess, TerminalFailure, Model, Ntfy, Custom }
|
||||
|
||||
/** The kind of [key], from whether it is a terminal and its declared type. */
|
||||
internal fun graphNodeKind(terminal: Boolean, key: String, type: String?): GraphNodeKind = when {
|
||||
terminal && key == Protocol.FAILURE_END -> GraphNodeKind.TerminalFailure
|
||||
terminal -> GraphNodeKind.TerminalSuccess
|
||||
effectiveStageType(type) == "ntfy" -> GraphNodeKind.Ntfy
|
||||
effectiveStageType(type) == "model" -> GraphNodeKind.Model
|
||||
else -> GraphNodeKind.Custom
|
||||
}
|
||||
|
||||
/**
|
||||
* WCAG relative luminance of [color] (sRGB), the building block of the WCAG
|
||||
* contrast ratio. Pure so the palette's legibility is measured in a unit test
|
||||
* rather than judged by eye.
|
||||
*/
|
||||
internal fun relativeLuminance(color: Color): Double {
|
||||
fun channel(value: Float): Double {
|
||||
val c = value.toDouble()
|
||||
return if (c <= 0.03928) c / 12.92 else ((c + 0.055) / 1.055).pow(2.4)
|
||||
}
|
||||
return 0.2126 * channel(color.red) + 0.7152 * channel(color.green) + 0.0722 * channel(color.blue)
|
||||
}
|
||||
|
||||
/**
|
||||
* WCAG 2.x contrast ratio between two opaque colours, in `[1.0, 21.0]`. The
|
||||
* formula is symmetric, so argument order does not matter.
|
||||
*/
|
||||
internal fun contrastRatio(a: Color, b: Color): Double {
|
||||
val la = relativeLuminance(a)
|
||||
val lb = relativeLuminance(b)
|
||||
val hi = max(la, lb)
|
||||
val lo = min(la, lb)
|
||||
return (hi + 0.05) / (lo + 0.05)
|
||||
}
|
||||
@@ -13,10 +13,16 @@ import androidx.compose.material3.BottomSheetDefaults
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.ModalBottomSheet
|
||||
import androidx.compose.material3.PrimaryScrollableTabRow
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Tab
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.rememberModalBottomSheetState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
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.semantics.heading
|
||||
@@ -32,6 +38,7 @@ 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.displayMap
|
||||
import net.awan.pipelines.ui.fileChangeLine
|
||||
import net.awan.pipelines.ui.fileChangesSummary
|
||||
import net.awan.pipelines.ui.formatDuration
|
||||
@@ -125,8 +132,10 @@ internal fun controlVisitLabel(control: ControlEvidence): String {
|
||||
/**
|
||||
* The pure run view of one [RunStep] for the selected stage: status, outcome,
|
||||
* duration, visit against the control's max_visits, target, session id,
|
||||
* diagnostic, transcript, a file-change summary and notification receipts. Blank
|
||||
* fields are skipped.
|
||||
* diagnostic, transcript, the step's input/output, a file-change summary and
|
||||
* notification receipts. Blank fields are skipped. This is the one place a
|
||||
* step's recorded evidence is turned into rows; the timeline no longer
|
||||
* duplicates it.
|
||||
*/
|
||||
internal fun runStepFields(step: RunStep): List<StageField> {
|
||||
val fields = ArrayList<StageField>()
|
||||
@@ -144,6 +153,12 @@ internal fun runStepFields(step: RunStep): List<StageField> {
|
||||
if (step.agentActive) fields += StageField("Agent", "active")
|
||||
if (step.diagnostic.isNotBlank()) fields += StageField("Diagnostic", step.diagnostic, block = true)
|
||||
if (step.transcript.isNotBlank()) fields += StageField("Transcript", step.transcript, block = true)
|
||||
step.input?.takeIf { it.isNotEmpty() }?.let {
|
||||
fields += StageField("Input", it.displayMap(), block = true)
|
||||
}
|
||||
step.output?.takeIf { it.isNotEmpty() }?.let {
|
||||
fields += StageField("Output", it.displayMap(), block = true)
|
||||
}
|
||||
|
||||
step.fileChanges?.let { changes ->
|
||||
val summary = fileChangesSummary(changes)
|
||||
@@ -189,28 +204,57 @@ private fun configLabel(key: String): String = when (key) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The one reusable stage-detail overlay, opened when a node in [WorkflowGraph] is
|
||||
* tapped. It is a Material 3 [ModalBottomSheet] that opens near full height
|
||||
* (`skipPartiallyExpanded`), is scrollable, and dismisses by swipe, back or
|
||||
* tapping outside. On a wide window it reuses the screens' responsive centring
|
||||
* (the shared [DETAIL_MAX_WIDTH_DP]) instead of stretching one narrow column. It
|
||||
* is an overlay on the current screen; no navigation route is added.
|
||||
* Clamps a requested visit index into `[0, visitCount)`. A stale saved index or a
|
||||
* stage that turns out to have fewer recorded visits can never index out of
|
||||
* bounds; an empty list yields 0.
|
||||
*/
|
||||
internal fun clampVisitIndex(index: Int, visitCount: Int): Int =
|
||||
if (visitCount <= 0) 0 else index.coerceIn(0, visitCount - 1)
|
||||
|
||||
/**
|
||||
* Whether a stage needs a visit tab row: only when it was visited more than
|
||||
* once, so a single-visit stage never shows a pointless one-tab row.
|
||||
*/
|
||||
internal fun showVisitTabs(visitCount: Int): Boolean = visitCount > 1
|
||||
|
||||
/**
|
||||
* The one reusable stage-detail overlay, opened when a node in [WorkflowGraph]
|
||||
* is tapped or a timeline entry is tapped. It is a Material 3
|
||||
* [ModalBottomSheet] that opens near full height (`skipPartiallyExpanded`), is
|
||||
* scrollable, and dismisses by swipe, back or tapping outside. On a wide window
|
||||
* it reuses the screens' responsive centring (the shared [DETAIL_MAX_WIDTH_DP])
|
||||
* instead of stretching one narrow column. It is an overlay on the current
|
||||
* screen; no navigation route is added.
|
||||
*
|
||||
* [runSteps] is every recorded visit of the stage in order; when there is more
|
||||
* than one the sheet shows a visit tab row (visit 1..N) and starts on
|
||||
* [initialVisitIndex] (the tapped timeline entry, or the most recent visit when
|
||||
* opened from the graph). A stage the run never reached has no run section.
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun StageDetailSheet(
|
||||
stageKey: String,
|
||||
graph: Graph,
|
||||
runStep: RunStep?,
|
||||
runSteps: List<RunStep> = emptyList(),
|
||||
initialVisitIndex: Int = 0,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
val text = pipelinesText()
|
||||
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
||||
val stage = graph.stages.firstOrNull { it.key == stageKey }
|
||||
val definition = stage?.let(::stageDefinitionFields) ?: terminalFields(graph, stageKey)
|
||||
val run = runStep?.let(::runStepFields).orEmpty()
|
||||
val typeLabel = if (stage != null) effectiveStageType(stage.type) else "terminal"
|
||||
|
||||
// Reset the selected visit when the stage (but not the user's tap within it)
|
||||
// changes; saved so it survives recomposition/configuration.
|
||||
var visitIndex by rememberSaveable(stageKey) {
|
||||
mutableIntStateOf(clampVisitIndex(initialVisitIndex, runSteps.size))
|
||||
}
|
||||
val clampedVisit = clampVisitIndex(visitIndex, runSteps.size)
|
||||
val selectedStep = runSteps.getOrNull(clampedVisit)
|
||||
val run = selectedStep?.let(::runStepFields).orEmpty()
|
||||
|
||||
ModalBottomSheet(
|
||||
onDismissRequest = onDismiss,
|
||||
sheetState = sheetState,
|
||||
@@ -231,6 +275,21 @@ fun StageDetailSheet(
|
||||
modifier = Modifier.semantics { heading() },
|
||||
)
|
||||
StageTypeChip(typeLabel)
|
||||
if (showVisitTabs(runSteps.size)) {
|
||||
PrimaryScrollableTabRow(
|
||||
selectedTabIndex = clampedVisit,
|
||||
edgePadding = 0.dp,
|
||||
modifier = Modifier.fillMaxWidth().padding(top = 8.dp),
|
||||
) {
|
||||
runSteps.forEachIndexed { index, _ ->
|
||||
Tab(
|
||||
selected = index == clampedVisit,
|
||||
onClick = { visitIndex = index },
|
||||
text = { Text("visit ${index + 1}", maxLines = 1) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (definition.isNotEmpty()) {
|
||||
Text("Definition", style = text.sectionHeader, modifier = Modifier.padding(top = 8.dp))
|
||||
definition.forEach { field -> StageFieldRow(field) }
|
||||
|
||||
@@ -168,23 +168,23 @@ fun WorkflowGraph(
|
||||
val scheme = MaterialTheme.colorScheme
|
||||
val colors = remember(scheme) {
|
||||
GraphColors(
|
||||
// The two terminal roles stay scheme roles so their meaning is kept.
|
||||
success = scheme.tertiary,
|
||||
error = scheme.error,
|
||||
accent = listOf(scheme.primary, scheme.secondary, scheme.primaryContainer, scheme.secondaryContainer),
|
||||
// Labels sit on a surface-coloured chip, so they must not reuse the
|
||||
// container *fill* colours (primaryContainer/secondaryContainer), which
|
||||
// are near-invisible as text on the surface. Draw those outcomes in
|
||||
// their matching "on-container" colour instead; the other accents are
|
||||
// already legible on the surface in both light and dark themes.
|
||||
labelAccent = listOf(
|
||||
scheme.primary,
|
||||
scheme.secondary,
|
||||
scheme.onPrimaryContainer,
|
||||
scheme.onSecondaryContainer,
|
||||
),
|
||||
// Every other outcome uses the one curated, legible palette for both
|
||||
// its stroke and its label text, so a curve and its label always agree.
|
||||
palette = GraphPalette.colors,
|
||||
// Node fills differ by kind (see [GraphNodeKind]): model (neutral),
|
||||
// ntfy (amber), other/custom (green), and the two terminals.
|
||||
nodeFill = scheme.surfaceVariant,
|
||||
nodeFillActive = scheme.primaryContainer,
|
||||
nodeNtfyFill = scheme.tertiaryContainer,
|
||||
nodeCustomFill = scheme.primaryContainer,
|
||||
// A selected node inverts (light fill / dark text) plus a 4px border,
|
||||
// so selection reads in either appearance and never relies on colour.
|
||||
nodeFillActive = scheme.inverseSurface,
|
||||
nodeTextActive = scheme.inverseOnSurface,
|
||||
nodeBorder = scheme.outline,
|
||||
nodeBorderActive = scheme.primary,
|
||||
nodeText = scheme.onSurface,
|
||||
terminalFill = scheme.secondaryContainer,
|
||||
terminalErrorFill = scheme.errorContainer,
|
||||
@@ -192,6 +192,9 @@ fun WorkflowGraph(
|
||||
labelText = scheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
// node key -> stage type, derived once per graph (never per frame) so node
|
||||
// kind/colour and the spoken description share one lookup.
|
||||
val stageTypeByKey = remember(graph) { graph.stages.associate { it.key to it.type } }
|
||||
|
||||
val fitPaddingPx = with(density) { FIT_PADDING.toPx() }
|
||||
val minVisiblePx = with(density) { MIN_VISIBLE.toPx() }
|
||||
@@ -287,7 +290,7 @@ fun WorkflowGraph(
|
||||
// top of a neighbouring edge instead of being crossed by it.
|
||||
drawEdgePaths(layout, colors, runState)
|
||||
drawEdgeLabels(layout, colors, runState, textMeasurer)
|
||||
drawNodes(layout, colors, runState, selectedStage, textMeasurer)
|
||||
drawNodes(layout, colors, runState, selectedStage, stageTypeByKey, textMeasurer)
|
||||
}
|
||||
}
|
||||
// Accessibility overlay: invisible nodes carrying a click action and a
|
||||
@@ -307,7 +310,7 @@ fun WorkflowGraph(
|
||||
),
|
||||
) {
|
||||
layout.nodes.forEach { node ->
|
||||
val nodeType = graph.stages.firstOrNull { it.key == node.key }?.type
|
||||
val nodeType = stageTypeByKey[node.key]
|
||||
Box(
|
||||
Modifier
|
||||
.offset { IntOffset(node.x.roundToInt(), node.y.roundToInt()) }
|
||||
@@ -360,14 +363,17 @@ fun WorkflowGraph(
|
||||
}
|
||||
}
|
||||
|
||||
private class GraphColors(
|
||||
internal class GraphColors(
|
||||
val success: Color,
|
||||
val error: Color,
|
||||
val accent: List<Color>,
|
||||
val labelAccent: List<Color>,
|
||||
val palette: List<Color>,
|
||||
val nodeFill: Color,
|
||||
val nodeNtfyFill: Color,
|
||||
val nodeCustomFill: Color,
|
||||
val nodeFillActive: Color,
|
||||
val nodeTextActive: Color,
|
||||
val nodeBorder: Color,
|
||||
val nodeBorderActive: Color,
|
||||
val nodeText: Color,
|
||||
val terminalFill: Color,
|
||||
val terminalErrorFill: Color,
|
||||
@@ -979,7 +985,7 @@ private fun DrawScope.drawEdgePaths(
|
||||
) {
|
||||
for (edge in layout.edges) {
|
||||
val executed = edge.isExecuted(runState)
|
||||
val color = outcomeColor(edge.edge, colors)
|
||||
val color = outcomeColor(edge.edge.outcome, colors)
|
||||
val alpha = if (executed) 1f else 0.25f
|
||||
// Routing already happened once in layoutGraph; drawing only replays the
|
||||
// stored polyline, so there is no per-frame recompute.
|
||||
@@ -1012,7 +1018,7 @@ private fun DrawScope.drawEdgeLabels(
|
||||
) {
|
||||
for (edge in layout.edges) {
|
||||
val executed = edge.isExecuted(runState)
|
||||
val textColor = if (executed) outcomeLabelColor(edge.edge, colors) else colors.labelText
|
||||
val textColor = if (executed) outcomeColor(edge.edge.outcome, colors) else colors.labelText
|
||||
val measured = textMeasurer.measure(edge.edge.label, TextStyle(fontSize = 11.sp, color = textColor))
|
||||
val labelTopLeft = Offset(
|
||||
x = edge.labelPoint.x - measured.size.width / 2f,
|
||||
@@ -1067,24 +1073,28 @@ private fun DrawScope.drawNodes(
|
||||
colors: GraphColors,
|
||||
runState: RunGraphState?,
|
||||
selectedStage: String?,
|
||||
stageTypeByKey: Map<String, String?>,
|
||||
textMeasurer: TextMeasurer,
|
||||
) {
|
||||
for (node in layout.nodes) {
|
||||
val executed = runState == null || node.key in runState.visitedStages
|
||||
val selected = node.key == selectedStage
|
||||
val alpha = if (executed) 1f else 0.3f
|
||||
val failureTerminal = node.key == Protocol.FAILURE_END
|
||||
val kind = graphNodeKind(node.terminal, node.key, stageTypeByKey[node.key])
|
||||
val fill = when {
|
||||
node.terminal && failureTerminal -> colors.terminalErrorFill
|
||||
node.terminal -> colors.terminalFill
|
||||
kind == GraphNodeKind.TerminalFailure -> colors.terminalErrorFill
|
||||
kind == GraphNodeKind.TerminalSuccess -> colors.terminalFill
|
||||
selected -> colors.nodeFillActive
|
||||
kind == GraphNodeKind.Ntfy -> colors.nodeNtfyFill
|
||||
kind == GraphNodeKind.Custom -> colors.nodeCustomFill
|
||||
else -> colors.nodeFill
|
||||
}.copy(alpha = alpha)
|
||||
val border = when {
|
||||
node.terminal && failureTerminal -> colors.error
|
||||
node.terminal -> colors.success
|
||||
else -> colors.nodeBorder
|
||||
val border = when (kind) {
|
||||
GraphNodeKind.TerminalFailure -> colors.error
|
||||
GraphNodeKind.TerminalSuccess -> colors.success
|
||||
else -> if (selected) colors.nodeBorderActive else colors.nodeBorder
|
||||
}.copy(alpha = alpha)
|
||||
val textColor = if (!node.terminal && selected) colors.nodeTextActive else colors.nodeText
|
||||
val topLeft = Offset(node.x, node.y)
|
||||
drawRoundRect(
|
||||
color = fill,
|
||||
@@ -1097,12 +1107,12 @@ private fun DrawScope.drawNodes(
|
||||
topLeft = topLeft,
|
||||
size = Size(node.width, node.height),
|
||||
cornerRadius = androidx.compose.ui.geometry.CornerRadius(14f, 14f),
|
||||
style = Stroke(width = if (selected) 4f else 2f),
|
||||
style = Stroke(width = if (selected && !node.terminal) 4f else 2f),
|
||||
)
|
||||
val label = "[" + node.label + "]"
|
||||
val measured = textMeasurer.measure(
|
||||
label,
|
||||
TextStyle(fontSize = 13.sp, fontWeight = FontWeight.Medium, color = colors.nodeText.copy(alpha = alpha)),
|
||||
TextStyle(fontSize = 13.sp, fontWeight = FontWeight.Medium, color = textColor.copy(alpha = alpha)),
|
||||
)
|
||||
// Pre-measured layout avoids the scope-relative width constraint crash and
|
||||
// the redundant re-measure of the string overload.
|
||||
@@ -1116,22 +1126,18 @@ private fun DrawScope.drawNodes(
|
||||
}
|
||||
}
|
||||
|
||||
private fun outcomeColor(edge: GraphEdge, colors: GraphColors): Color = when (edge.outcome) {
|
||||
"error" -> colors.error
|
||||
"success" -> colors.success
|
||||
else -> colors.accent[abs(edge.outcome.hashCode()) % colors.accent.size]
|
||||
}
|
||||
|
||||
/**
|
||||
* Legible label colour for an outcome, using [GraphColors.labelAccent] so
|
||||
* container-filled accents are rendered as text in their on-container colour.
|
||||
* Shares the outcome→index mapping with [outcomeColor] so a label always matches
|
||||
* its curve's colour family.
|
||||
* The colour for an outcome: the theme error role for `error`, a clearly
|
||||
* positive theme colour for `success`, and the curated [GraphPalette] entry for
|
||||
* everything else. One colour is used for both the edge stroke and its label
|
||||
* text (the palette is legible on the surface), so a curve and its label always
|
||||
* agree. `success`/`error` are the terminal roles and are never colour-only
|
||||
* signals (their labels name them). Pure and deterministic.
|
||||
*/
|
||||
private fun outcomeLabelColor(edge: GraphEdge, colors: GraphColors): Color = when (edge.outcome) {
|
||||
internal fun outcomeColor(outcome: String, colors: GraphColors): Color = when (outcome) {
|
||||
"error" -> colors.error
|
||||
"success" -> colors.success
|
||||
else -> colors.labelAccent[abs(edge.outcome.hashCode()) % colors.labelAccent.size]
|
||||
else -> colors.palette[GraphPalette.outcomeColorIndex(outcome)]
|
||||
}
|
||||
|
||||
/** True when [runState] is null (definition view) or recorded this edge's route. */
|
||||
|
||||
@@ -231,7 +231,6 @@ private fun PipelineGraphTab(detail: PipelineDetail, modifier: Modifier) {
|
||||
StageDetailSheet(
|
||||
stageKey = key,
|
||||
graph = detail.graph,
|
||||
runStep = null,
|
||||
onDismiss = { selectedStage = null },
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package net.awan.pipelines.ui.screens
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
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.KeyboardArrowLeft
|
||||
import androidx.compose.material.icons.filled.AccountTree
|
||||
import androidx.compose.material.icons.filled.Refresh
|
||||
import androidx.compose.material.icons.filled.Search
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
@@ -27,13 +27,16 @@ import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import net.awan.pipelines.data.protocol.PipelineSummary
|
||||
import net.awan.pipelines.ui.AppViewModel
|
||||
import net.awan.pipelines.ui.components.EmptyState
|
||||
import net.awan.pipelines.ui.components.ErrorState
|
||||
import net.awan.pipelines.ui.components.ListRow
|
||||
import net.awan.pipelines.ui.components.LoadingState
|
||||
import net.awan.pipelines.ui.theme.pipelinesText
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@@ -41,6 +44,8 @@ fun PipelineListScreen(
|
||||
vm: AppViewModel,
|
||||
onOpen: (id: Long, version: Int) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
selectedId: Long? = null,
|
||||
onTogglePane: (() -> Unit)? = null,
|
||||
) {
|
||||
val state by vm.pipelines.collectAsStateWithLifecycle()
|
||||
var query by remember { mutableStateOf("") }
|
||||
@@ -56,6 +61,14 @@ fun PipelineListScreen(
|
||||
IconButton(onClick = vm::refreshPipelines) {
|
||||
Icon(Icons.Default.Refresh, contentDescription = "Refresh pipelines")
|
||||
}
|
||||
if (onTogglePane != null) {
|
||||
IconButton(onClick = onTogglePane) {
|
||||
Icon(
|
||||
Icons.AutoMirrored.Filled.KeyboardArrowLeft,
|
||||
contentDescription = "Collapse list pane",
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
},
|
||||
@@ -83,11 +96,14 @@ fun PipelineListScreen(
|
||||
} else {
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentPadding = androidx.compose.foundation.layout.PaddingValues(16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
contentPadding = PaddingValues(vertical = 8.dp),
|
||||
) {
|
||||
items(items, key = { it.id }) { pipeline ->
|
||||
PipelineRow(pipeline) { onOpen(pipeline.id, pipeline.version) }
|
||||
PipelineRow(
|
||||
pipeline = pipeline,
|
||||
selected = pipeline.id == selectedId,
|
||||
onClick = { onOpen(pipeline.id, pipeline.version) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,15 +120,44 @@ fun PipelineListScreen(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* One pipeline as a row of the shared real list: a leading workflow glyph, the
|
||||
* name as the title and the id/version/stage-count as the secondary line. The
|
||||
* row is selected when its pipeline is the one open in the detail pane.
|
||||
*/
|
||||
@Composable
|
||||
private fun PipelineRow(pipeline: PipelineSummary, onClick: () -> Unit) {
|
||||
Card(modifier = Modifier.fillMaxWidth().clickable(onClick = onClick)) {
|
||||
Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
||||
Text(pipeline.name, style = MaterialTheme.typography.titleMedium)
|
||||
Text("id ${pipeline.id} · v${pipeline.version} · ${pipeline.stages} stages", style = MaterialTheme.typography.bodySmall)
|
||||
if (pipeline.updatedAt.isNotBlank()) {
|
||||
Text("updated ${pipeline.updatedAt}", style = MaterialTheme.typography.bodySmall)
|
||||
}
|
||||
private fun PipelineRow(pipeline: PipelineSummary, selected: Boolean, onClick: () -> Unit) {
|
||||
val text = pipelinesText()
|
||||
ListRow(
|
||||
selected = selected,
|
||||
onClick = onClick,
|
||||
leading = {
|
||||
Icon(
|
||||
imageVector = Icons.Default.AccountTree,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
},
|
||||
) {
|
||||
Text(
|
||||
pipeline.name,
|
||||
style = text.cardTitle,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
Text(
|
||||
"id ${pipeline.id} · v${pipeline.version} · ${pipeline.stages} stages",
|
||||
style = text.meta,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
if (pipeline.updatedAt.isNotBlank()) {
|
||||
Text(
|
||||
"updated ${pipeline.updatedAt}",
|
||||
style = text.meta,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,25 @@
|
||||
package net.awan.pipelines.ui.screens
|
||||
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
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
|
||||
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.itemsIndexed
|
||||
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.Cancel
|
||||
import androidx.compose.material.icons.filled.KeyboardArrowDown
|
||||
import androidx.compose.material.icons.filled.Refresh
|
||||
import androidx.compose.material.icons.filled.Replay
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@@ -46,7 +38,6 @@ 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.draw.rotate
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
@@ -55,7 +46,6 @@ import kotlinx.serialization.json.JsonElement
|
||||
import net.awan.pipelines.data.ErrorMessages
|
||||
import net.awan.pipelines.data.protocol.RunDetail
|
||||
import net.awan.pipelines.data.protocol.RunGraphState
|
||||
import net.awan.pipelines.data.protocol.RunStep
|
||||
import net.awan.pipelines.data.protocol.SessionEvidence
|
||||
import net.awan.pipelines.ui.AppViewModel
|
||||
import net.awan.pipelines.ui.LoadState
|
||||
@@ -70,18 +60,11 @@ import net.awan.pipelines.ui.components.StatusChip
|
||||
import net.awan.pipelines.ui.components.collapsibleSection
|
||||
import net.awan.pipelines.ui.components.rememberSectionExpansion
|
||||
import net.awan.pipelines.ui.components.runDetailTabs
|
||||
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
|
||||
|
||||
@@ -190,7 +173,7 @@ fun RunDetailScreen(
|
||||
wide = wide,
|
||||
modifier = contentModifier,
|
||||
)
|
||||
else -> RunStepsTab(run, wide, contentModifier)
|
||||
else -> RunTimelineTab(run, wide, contentModifier)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -318,6 +301,9 @@ private fun RunSummaryTab(run: RunDetail, wide: Boolean, modifier: Modifier) {
|
||||
private fun RunGraphTab(run: RunDetail, modifier: Modifier) {
|
||||
val text = pipelinesText()
|
||||
val runState = remember(run.id, run.steps) { RunGraphState.from(run) }
|
||||
// Grouped once per step-list change; the sheet opened from the graph starts on
|
||||
// the most recent visit of the tapped stage.
|
||||
val timeline = remember(run.steps) { runTimeline(run.steps) }
|
||||
// The stage whose detail sheet is open; the sheet overlays this screen.
|
||||
var selectedStage by rememberSaveable { mutableStateOf<String?>(null) }
|
||||
LazyColumn(
|
||||
@@ -348,12 +334,13 @@ private fun RunGraphTab(run: RunDetail, modifier: Modifier) {
|
||||
}
|
||||
}
|
||||
selectedStage?.let { key ->
|
||||
val visits = timeline.visitsByStage[key].orEmpty()
|
||||
StageDetailSheet(
|
||||
stageKey = key,
|
||||
graph = run.graph,
|
||||
// This run's latest step for the stage (a stage can be visited more
|
||||
// than once); null when the run never reached it.
|
||||
runStep = run.steps.lastOrNull { it.stage == key },
|
||||
// Every recorded visit for the stage, opening on the most recent one.
|
||||
runSteps = visits,
|
||||
initialVisitIndex = (visits.size - 1).coerceAtLeast(0),
|
||||
onDismiss = { selectedStage = null },
|
||||
)
|
||||
}
|
||||
@@ -482,246 +469,113 @@ private fun RunEvidenceTab(
|
||||
}
|
||||
}
|
||||
|
||||
/** One inner collapsible section per stage group, each listing that stage's steps. */
|
||||
/**
|
||||
* The Timeline tab: one compact line per recorded visit (stage name, visit
|
||||
* number, outcome chip and duration plus a brief description) and nothing else.
|
||||
* The heavy per-step evidence lives only in the [StageDetailSheet] opened by
|
||||
* tapping an entry. The steps are grouped once per step-list change, not per
|
||||
* recomposition, and rendered in this single LazyColumn.
|
||||
*/
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
private fun RunStepsTab(run: RunDetail, wide: Boolean, modifier: Modifier) {
|
||||
private fun RunTimelineTab(run: RunDetail, wide: Boolean, modifier: Modifier) {
|
||||
val text = pipelinesText()
|
||||
// Grouped once per step-list change, not per recomposition.
|
||||
val groups = remember(run.steps) { run.steps.groupBy { it.stage } }
|
||||
val expansion = rememberSectionExpansion(run.steps)
|
||||
val timeline = remember(run.steps) { runTimeline(run.steps) }
|
||||
var sheetStage by rememberSaveable { mutableStateOf<String?>(null) }
|
||||
var sheetVisit by rememberSaveable { mutableIntStateOf(0) }
|
||||
DetailTabBody(wide, modifier) { columnModifier ->
|
||||
LazyColumn(
|
||||
modifier = columnModifier,
|
||||
contentPadding = PaddingValues(vertical = 16.dp),
|
||||
) {
|
||||
if (run.steps.isEmpty()) {
|
||||
item(key = "steps-empty") {
|
||||
if (timeline.entries.isEmpty()) {
|
||||
item(key = "timeline-empty") {
|
||||
Text(
|
||||
"No steps recorded.",
|
||||
"No visits recorded.",
|
||||
style = text.meta,
|
||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
groups.forEach { (stage, steps) ->
|
||||
val sectionKey = "steps-$stage"
|
||||
collapsibleSection(
|
||||
title = stage.ifBlank { "Unnamed stage" },
|
||||
key = sectionKey,
|
||||
expanded = expansion.isExpanded(sectionKey),
|
||||
onToggle = { expansion.toggle(sectionKey) },
|
||||
) {
|
||||
itemsIndexed(
|
||||
steps,
|
||||
key = { _, step -> "step-${step.sequence}-${step.stage}" },
|
||||
) { index, step ->
|
||||
StepCard(
|
||||
step = step,
|
||||
isLast = index == steps.lastIndex,
|
||||
wide = wide,
|
||||
modifier = Modifier.padding(horizontal = 16.dp).animateItem(),
|
||||
)
|
||||
}
|
||||
items(
|
||||
timeline.entries,
|
||||
key = { "timeline-${it.stageKey}-${it.step.sequence}" },
|
||||
) { entry ->
|
||||
TimelineRow(entry) {
|
||||
sheetStage = entry.stageKey
|
||||
sheetVisit = entry.visitIndex
|
||||
}
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outlineVariant)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
sheetStage?.let { key ->
|
||||
StageDetailSheet(
|
||||
stageKey = key,
|
||||
graph = run.graph,
|
||||
runSteps = timeline.visitsByStage[key].orEmpty(),
|
||||
// Open on the exact visit that was tapped.
|
||||
initialVisitIndex = sheetVisit,
|
||||
onDismiss = { sheetStage = null },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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. 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.
|
||||
* One compact timeline line: a leading status glyph, the stage name and visit
|
||||
* number, the outcome chip and duration, then a single-line description. No
|
||||
* inline code block, metadata grid, transcript, file-changes or notifications
|
||||
* evidence is rendered here; that all lives in the stage detail sheet.
|
||||
*/
|
||||
@Composable
|
||||
private fun StepCard(step: RunStep, isLast: Boolean, wide: Boolean, modifier: Modifier = Modifier) {
|
||||
private fun TimelineRow(entry: TimelineEntry, onClick: () -> Unit) {
|
||||
val text = pipelinesText()
|
||||
val state = runStateOf(step.outcome.ifBlank { step.status })
|
||||
val color = runStateColor(state)
|
||||
var detailsExpanded by rememberSaveable { mutableStateOf(false) }
|
||||
val chevron by animateFloatAsState(
|
||||
targetValue = if (detailsExpanded) 0f else -90f,
|
||||
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). Kept as the row's first child
|
||||
// so the glyph stays aligned with the step title.
|
||||
Column(
|
||||
modifier = Modifier.fillMaxHeight().width(STEP_GUTTER_WIDTH).padding(top = 2.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
RunStatusIcon(
|
||||
state = state,
|
||||
contentDescription = "Step ${step.sequence} ${step.stage}: ${state.label}",
|
||||
tint = color,
|
||||
modifier = Modifier.size(20.dp),
|
||||
)
|
||||
if (!isLast) {
|
||||
Box(
|
||||
Modifier
|
||||
.padding(top = 4.dp)
|
||||
.weight(1f)
|
||||
.width(2.dp)
|
||||
.background(color.copy(alpha = 0.5f)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier.weight(1f).padding(start = 8.dp, bottom = STEP_BOTTOM_GAP),
|
||||
verticalArrangement = Arrangement.spacedBy(STEP_CONTENT_GAP),
|
||||
) {
|
||||
val state = runStateOf(entry.step.outcome.ifBlank { entry.step.status })
|
||||
val chipLabel = entry.outcomeLabel.ifBlank { state.label }
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable(onClick = onClick)
|
||||
.padding(horizontal = 16.dp, vertical = 10.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
RunStatusIcon(
|
||||
state = state,
|
||||
contentDescription = "Visit ${entry.visit} ${entry.stageKey}: ${state.label}",
|
||||
modifier = Modifier.size(18.dp),
|
||||
)
|
||||
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
Text(
|
||||
"${step.sequence}. ${step.stage}",
|
||||
"${entry.stageKey} · visit ${entry.visit}",
|
||||
style = text.cardTitle,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
StatusChip(label = chipLabel, state = state)
|
||||
}
|
||||
|
||||
StepMetaGrid(meta, wide)
|
||||
CodeBlock("Diagnostic", step.diagnostic)
|
||||
|
||||
// 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 (entry.duration != null) {
|
||||
Text(entry.duration, style = text.meta, maxLines = 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
if (entry.description.isNotBlank()) {
|
||||
Text(
|
||||
entry.description,
|
||||
style = text.meta,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
CodeBlock("Input", step.input.displayMap(), maxHeight = STEP_CODE_MAX_HEIGHT)
|
||||
CodeBlock("Output", step.output.displayMap(), maxHeight = STEP_CODE_MAX_HEIGHT)
|
||||
step.fileChanges?.let { changes ->
|
||||
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,
|
||||
)
|
||||
}
|
||||
CodeBlock("Transcript", step.transcript, maxHeight = STEP_CODE_MAX_HEIGHT)
|
||||
}
|
||||
|
||||
/** A session-evidence entry's fields plus its data/diagnostic code blocks. */
|
||||
@Composable
|
||||
private fun EvidenceDetails(evidence: SessionEvidence, modifier: Modifier = Modifier) {
|
||||
@@ -736,20 +590,3 @@ 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
|
||||
|
||||
@@ -2,14 +2,12 @@ package net.awan.pipelines.ui.screens
|
||||
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||
import androidx.compose.foundation.layout.FlowRow
|
||||
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
|
||||
@@ -18,6 +16,7 @@ import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowLeft
|
||||
import androidx.compose.material.icons.filled.Refresh
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
@@ -48,7 +47,9 @@ import net.awan.pipelines.data.protocol.UsageStats
|
||||
import net.awan.pipelines.ui.AppViewModel
|
||||
import net.awan.pipelines.ui.components.RunState
|
||||
import net.awan.pipelines.ui.components.RunStatusChip
|
||||
import net.awan.pipelines.ui.components.RunStatusIcon
|
||||
import net.awan.pipelines.ui.components.ErrorState
|
||||
import net.awan.pipelines.ui.components.ListRow
|
||||
import net.awan.pipelines.ui.components.LoadingState
|
||||
import net.awan.pipelines.ui.components.runStateColor
|
||||
import net.awan.pipelines.ui.components.runStateOf
|
||||
@@ -64,6 +65,8 @@ fun RunHistoryScreen(
|
||||
onOpenRun: (Long) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
filterPipelineId: Long? = null,
|
||||
selectedRunId: Long? = null,
|
||||
onTogglePane: (() -> Unit)? = null,
|
||||
) {
|
||||
val state by vm.runs.collectAsStateWithLifecycle()
|
||||
LaunchedEffect(Unit) { vm.refreshRuns() }
|
||||
@@ -77,6 +80,14 @@ fun RunHistoryScreen(
|
||||
IconButton(onClick = vm::refreshRuns) {
|
||||
Icon(Icons.Default.Refresh, contentDescription = "Refresh runs")
|
||||
}
|
||||
if (onTogglePane != null) {
|
||||
IconButton(onClick = onTogglePane) {
|
||||
Icon(
|
||||
Icons.AutoMirrored.Filled.KeyboardArrowLeft,
|
||||
contentDescription = "Collapse list pane",
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
},
|
||||
@@ -92,6 +103,7 @@ fun RunHistoryScreen(
|
||||
usage = state.data?.usage,
|
||||
runs = state.data?.runs.orEmpty(),
|
||||
filterPipelineId = filterPipelineId,
|
||||
selectedRunId = selectedRunId,
|
||||
error = state.error,
|
||||
onOpenRun = onOpenRun,
|
||||
modifier = Modifier.padding(padding),
|
||||
@@ -106,6 +118,7 @@ private fun RunHistoryContent(
|
||||
usage: UsageStats?,
|
||||
runs: List<RunSummary>,
|
||||
filterPipelineId: Long?,
|
||||
selectedRunId: Long?,
|
||||
error: String?,
|
||||
onOpenRun: (Long) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
@@ -125,7 +138,6 @@ private fun RunHistoryContent(
|
||||
LazyColumn(
|
||||
modifier = modifier.fillMaxSize(),
|
||||
contentPadding = PaddingValues(bottom = 16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
if (usage != null) {
|
||||
item(key = "usage") {
|
||||
@@ -147,7 +159,7 @@ private fun RunHistoryContent(
|
||||
items(group.runs, key = { "run-${it.id}" }) { run ->
|
||||
RunRow(
|
||||
run = run,
|
||||
modifier = Modifier.padding(horizontal = 16.dp).animateItem(),
|
||||
selected = run.id == selectedRunId,
|
||||
onClick = { onOpenRun(run.id) },
|
||||
)
|
||||
}
|
||||
@@ -221,49 +233,68 @@ private fun Metric(label: String, value: String, color: Color, text: PipelinesTe
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* One run as a row of the shared real list: a leading status glyph, the run name
|
||||
* as the title with its version chip, and a secondary line carrying the status
|
||||
* chip, progress and id/start/duration. The row is selected when its run is the
|
||||
* one open in the detail pane.
|
||||
*/
|
||||
@Composable
|
||||
private fun RunRow(run: RunSummary, modifier: Modifier = Modifier, onClick: () -> Unit) {
|
||||
private fun RunRow(run: RunSummary, selected: Boolean, onClick: () -> Unit) {
|
||||
val text = pipelinesText()
|
||||
val state = runStateOf(run.status)
|
||||
Card(modifier.fillMaxWidth().clickable(onClick = onClick)) {
|
||||
Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text(
|
||||
run.name,
|
||||
style = text.cardTitle,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
VersionChip("v${run.version}")
|
||||
}
|
||||
ListRow(
|
||||
selected = selected,
|
||||
onClick = onClick,
|
||||
leading = {
|
||||
RunStatusIcon(
|
||||
state = state,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(20.dp),
|
||||
)
|
||||
},
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
Text(
|
||||
run.name,
|
||||
style = text.cardTitle,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
VersionChip("v${run.version}")
|
||||
}
|
||||
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
RunStatusChip(state)
|
||||
if (run.executing) {
|
||||
// The summary carries no total step count, so progress is shown
|
||||
// honestly as an indeterminate indicator plus completed visits.
|
||||
CircularProgressIndicator(modifier = Modifier.size(14.dp), strokeWidth = 2.dp)
|
||||
}
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text(progressText(run), style = text.meta, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
RunStatusChip(state)
|
||||
if (run.executing) {
|
||||
// The summary carries no total step count, so progress is shown
|
||||
// honestly as an indeterminate indicator plus completed visits.
|
||||
CircularProgressIndicator(modifier = Modifier.size(14.dp), strokeWidth = 2.dp)
|
||||
}
|
||||
Text(progressText(run), style = text.meta, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
|
||||
Text(metaText(run), style = text.meta, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
Text(metaText(run), style = text.meta, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
|
||||
if (run.diagnostic.isNotBlank()) {
|
||||
Text(
|
||||
run.diagnostic,
|
||||
style = text.meta,
|
||||
color = if (state == RunState.Failed) {
|
||||
MaterialTheme.colorScheme.error
|
||||
} else {
|
||||
MaterialTheme.colorScheme.onSurfaceVariant
|
||||
},
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
if (run.diagnostic.isNotBlank()) {
|
||||
Text(
|
||||
run.diagnostic,
|
||||
style = text.meta,
|
||||
color = if (state == RunState.Failed) {
|
||||
MaterialTheme.colorScheme.error
|
||||
} else {
|
||||
MaterialTheme.colorScheme.onSurfaceVariant
|
||||
},
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package net.awan.pipelines.ui.screens
|
||||
|
||||
import net.awan.pipelines.data.protocol.GraphSemantics
|
||||
import net.awan.pipelines.data.protocol.RunStep
|
||||
import net.awan.pipelines.ui.formatDuration
|
||||
|
||||
/**
|
||||
* One recorded visit as a compact timeline line. Pure data so the timeline's
|
||||
* derivation is unit-testable without the Compose runtime.
|
||||
*
|
||||
* [visit] is the display visit number (the control's recorded visit when
|
||||
* present, otherwise the position within the stage's visits); [visitIndex] is
|
||||
* the zero-based index into that stage's ordered visits, which the sheet uses as
|
||||
* its initial tab.
|
||||
*/
|
||||
internal data class TimelineEntry(
|
||||
val step: RunStep,
|
||||
val stageKey: String,
|
||||
val visit: Int,
|
||||
val visitIndex: Int,
|
||||
val outcomeLabel: String,
|
||||
val duration: String?,
|
||||
val description: String,
|
||||
)
|
||||
|
||||
/**
|
||||
* The run's timeline plus each stage's ordered visits. Both are derived in one
|
||||
* pass so the timeline composable can `remember(run.steps)` a single value and
|
||||
* never regroup per recomposition.
|
||||
*/
|
||||
internal data class RunTimeline(
|
||||
val entries: List<TimelineEntry>,
|
||||
val visitsByStage: Map<String, List<RunStep>>,
|
||||
)
|
||||
|
||||
/**
|
||||
* Builds the run timeline from the recorded steps. Stages keep first-appearance
|
||||
* order; a stage's visits are ordered by sequence. Pure and deterministic, with
|
||||
* safe handling of an empty list and of steps whose control/outcome are blank.
|
||||
*/
|
||||
internal fun runTimeline(steps: List<RunStep>): RunTimeline {
|
||||
if (steps.isEmpty()) return RunTimeline(emptyList(), emptyMap())
|
||||
|
||||
val visitsByStage = steps.groupBy { it.stage }
|
||||
.mapValues { (_, visits) -> visits.sortedBy { it.sequence } }
|
||||
// stage+sequence -> index within that stage's ordered visits, built once so
|
||||
// the timestamp/visit derivation below is O(n), never O(n²).
|
||||
val indexByStageSequence = HashMap<Pair<String, Int>, Int>()
|
||||
visitsByStage.forEach { (stage, visits) ->
|
||||
visits.forEachIndexed { index, visit -> indexByStageSequence[stage to visit.sequence] = index }
|
||||
}
|
||||
|
||||
val entries = steps.map { step ->
|
||||
val index = indexByStageSequence[step.stage to step.sequence] ?: 0
|
||||
TimelineEntry(
|
||||
step = step,
|
||||
stageKey = step.stage,
|
||||
visit = step.control?.visit?.takeIf { it > 0 } ?: (index + 1),
|
||||
visitIndex = index,
|
||||
outcomeLabel = step.outcome.ifBlank { step.status },
|
||||
duration = formatDuration(step.startedAt, step.finishedAt),
|
||||
description = timelineDescription(step),
|
||||
)
|
||||
}
|
||||
return RunTimeline(entries, visitsByStage)
|
||||
}
|
||||
|
||||
/**
|
||||
* The brief one-line description shown after a visit's name: the first non-blank
|
||||
* diagnostic line, else the resolved target, else nothing (never a fabricated
|
||||
* value).
|
||||
*/
|
||||
internal fun timelineDescription(step: RunStep): String {
|
||||
step.diagnostic.lineSequence().firstOrNull { it.isNotBlank() }?.let { return it.trim() }
|
||||
if (step.target.isNotBlank()) return "→ ${GraphSemantics.nodeLabel(step.target)}"
|
||||
return ""
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.awan.pipelines.ui
|
||||
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class PipelinesNavTest {
|
||||
|
||||
@Test
|
||||
fun listRoutesSelectTheirOwnDestination() {
|
||||
assertTrue(destinationSelected("pipelines", "pipelines"))
|
||||
assertTrue(destinationSelected("runs", "runs"))
|
||||
assertTrue(destinationSelected("settings", "settings"))
|
||||
assertFalse(destinationSelected("runs", "pipelines"))
|
||||
assertFalse(destinationSelected("pipelines", "runs"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun detailRoutesKeepTheirListDestinationSelected() {
|
||||
// A pipeline detail belongs to Pipelines, a run detail to Runs.
|
||||
assertTrue(destinationSelected("pipeline/1/2", "pipelines"))
|
||||
assertFalse(destinationSelected("pipeline/1/2", "runs"))
|
||||
assertTrue(destinationSelected("run/5", "runs"))
|
||||
assertFalse(destinationSelected("run/5", "pipelines"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun noRouteSelectsNothing() {
|
||||
assertFalse(destinationSelected(null, "pipelines"))
|
||||
assertFalse(destinationSelected(null, "runs"))
|
||||
assertFalse(destinationSelected(null, "settings"))
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,10 @@ class DetailTabsTest {
|
||||
listOf("summary", "graph", "input", "output", "evidence", "steps"),
|
||||
runDetailTabs.map { it.key },
|
||||
)
|
||||
assertEquals(listOf("Summary", "Graph", "Input", "Output", "Evidence", "Steps"), runDetailTabs.map { it.title })
|
||||
assertEquals(
|
||||
listOf("Summary", "Graph", "Input", "Output", "Evidence", "Timeline"),
|
||||
runDetailTabs.map { it.title },
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
package net.awan.pipelines.ui.graph
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import net.awan.pipelines.data.protocol.Protocol
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class GraphPaletteTest {
|
||||
|
||||
/** The dark Pipelines surface the outcome label chip is drawn on. */
|
||||
private val darkSurface = Color(0xFF0E1513)
|
||||
|
||||
/** The two terminal roles as the dark scheme supplies them. */
|
||||
private val successRole = Color(0xFFF2C879)
|
||||
private val errorRole = Color(0xFFFFB4AB)
|
||||
|
||||
private fun colors() = GraphColors(
|
||||
success = successRole,
|
||||
error = errorRole,
|
||||
palette = GraphPalette.colors,
|
||||
nodeFill = Color.Black,
|
||||
nodeNtfyFill = Color.Black,
|
||||
nodeCustomFill = Color.Black,
|
||||
nodeFillActive = Color.Black,
|
||||
nodeTextActive = Color.Black,
|
||||
nodeBorder = Color.Black,
|
||||
nodeBorderActive = Color.Black,
|
||||
nodeText = Color.Black,
|
||||
terminalFill = Color.Black,
|
||||
terminalErrorFill = Color.Black,
|
||||
labelBackground = darkSurface,
|
||||
labelText = Color.Black,
|
||||
)
|
||||
|
||||
/** The outcomes a real pipeline realistically uses, terminals included. */
|
||||
private val realisticOutcomes = listOf(
|
||||
"success", "error", "blocked", "rejected", "skipped",
|
||||
"exhausted", "retry", "approved", "fast", "missing", "done",
|
||||
)
|
||||
|
||||
@Test
|
||||
fun everyRealisticOutcomeGetsADistinctColour() {
|
||||
val colors = colors()
|
||||
val mapped = realisticOutcomes.map { outcomeColor(it, colors) }
|
||||
assertEquals(realisticOutcomes.size, mapped.toSet().size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun terminalRolesArePreserved() {
|
||||
val colors = colors()
|
||||
assertEquals(errorRole, outcomeColor("error", colors))
|
||||
assertEquals(successRole, outcomeColor("success", colors))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun mappingIsDeterministicAcrossRepeatedCalls() {
|
||||
val colors = colors()
|
||||
// Same input, same colour, in any order and however many times called.
|
||||
val first = realisticOutcomes.map { outcomeColor(it, colors) }
|
||||
val second = realisticOutcomes.reversed().asReversed().map { outcomeColor(it, colors) }
|
||||
assertEquals(first, second)
|
||||
assertEquals(first, realisticOutcomes.map { colors.let { c -> outcomeColor(it, c) } })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unknownOutcomesGetADeterministicFallbackAndNeverThrow() {
|
||||
val colors = colors()
|
||||
val unknown = outcomeColor("something-brand-new", colors)
|
||||
assertEquals(unknown, outcomeColor("something-brand-new", colors))
|
||||
// A blank name is just another unknown: stable and non-throwing.
|
||||
assertEquals(outcomeColor("", colors), outcomeColor("", colors))
|
||||
// The fallback comes from the reserved region, not a known outcome slot.
|
||||
val knownIndices = realisticOutcomes
|
||||
.filter { it != "success" && it != "error" }
|
||||
.map { GraphPalette.outcomeColorIndex(it) }
|
||||
assertFalse(GraphPalette.outcomeColorIndex("something-brand-new") in knownIndices)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun wcagContrastHelperMatchesKnownReferenceRatios() {
|
||||
assertEquals(21.0, contrastRatio(Color.White, Color.Black), 0.01)
|
||||
assertEquals(1.0, contrastRatio(Color.White, Color.White), 0.01)
|
||||
// Classic reference: #777777 on white is ~4.48:1.
|
||||
assertEquals(4.48, contrastRatio(Color(0xFF777777), Color.White), 0.02)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun everyPaletteColourIsLegibleOnTheDarkSurface() {
|
||||
// The measured ratio for each label colour against DarkSurface 0xFF0E1513.
|
||||
val measured = GraphPalette.colors.associateWith { contrastRatio(it, darkSurface) }
|
||||
measured.forEach { (colour, ratio) ->
|
||||
assertTrue("$colour contrast $ratio < 4.5", ratio >= 4.5)
|
||||
}
|
||||
// The two terminal roles are legible too.
|
||||
assertTrue(contrastRatio(successRole, darkSurface) >= 4.5)
|
||||
assertTrue(contrastRatio(errorRole, darkSurface) >= 4.5)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nodeKindIsDeterministicAndCoversEveryKind() {
|
||||
assertEquals(GraphNodeKind.Model, graphNodeKind(false, "planner", null))
|
||||
assertEquals(GraphNodeKind.Model, graphNodeKind(false, "planner", ""))
|
||||
assertEquals(GraphNodeKind.Model, graphNodeKind(false, "planner", "model"))
|
||||
assertEquals(GraphNodeKind.Ntfy, graphNodeKind(false, "notify", "ntfy"))
|
||||
assertEquals(GraphNodeKind.Custom, graphNodeKind(false, "const", "constant"))
|
||||
assertEquals(GraphNodeKind.TerminalSuccess, graphNodeKind(true, Protocol.SUCCESS_END, null))
|
||||
assertEquals(GraphNodeKind.TerminalFailure, graphNodeKind(true, Protocol.FAILURE_END, null))
|
||||
// The five kinds are distinct, so a type→colour mapping keyed on them is
|
||||
// distinct by construction.
|
||||
assertEquals(5, GraphNodeKind.entries.toSet().size)
|
||||
// Same input, same kind.
|
||||
assertEquals(graphNodeKind(false, "x", "ntfy"), graphNodeKind(false, "x", "ntfy"))
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,14 @@ 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.NotificationReceipt
|
||||
import net.awan.pipelines.data.protocol.RunStep
|
||||
import net.awan.pipelines.data.protocol.Stage
|
||||
import net.awan.pipelines.data.protocol.StageFileChanges
|
||||
import net.awan.pipelines.data.protocol.StageLimits
|
||||
import kotlinx.serialization.json.JsonPrimitive
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
@@ -72,6 +76,47 @@ class StageDetailSheetTest {
|
||||
assertTrue(fields.none { it.value.isBlank() })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runStepFieldsCarryEveryEvidenceKindTheTimelineDropped() {
|
||||
val step = RunStep(
|
||||
status = "succeeded",
|
||||
outcome = "success",
|
||||
diagnostic = "why",
|
||||
transcript = "said something",
|
||||
input = mapOf("prompt" to JsonPrimitive("do it")),
|
||||
output = mapOf("result" to JsonPrimitive("done")),
|
||||
fileChanges = StageFileChanges(status = "success"),
|
||||
notifications = listOf(NotificationReceipt(status = "delivered", destination = "ntfy")),
|
||||
)
|
||||
val labels = runStepFields(step).map { it.label }
|
||||
assertTrue(
|
||||
labels.containsAll(
|
||||
listOf("Status", "Outcome", "Diagnostic", "Transcript", "Input", "Output", "File changes", "Notification"),
|
||||
),
|
||||
)
|
||||
// Input/output are rendered as full blocks, so nothing shown before is lost.
|
||||
assertTrue(runStepFields(step).first { it.label == "Input" }.block)
|
||||
assertTrue(runStepFields(step).first { it.label == "Output" }.block)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun clampVisitIndexKeepsAValidVisitAndHandlesEmpty() {
|
||||
assertEquals(0, clampVisitIndex(0, 3))
|
||||
assertEquals(2, clampVisitIndex(2, 3))
|
||||
assertEquals(2, clampVisitIndex(99, 3))
|
||||
assertEquals(0, clampVisitIndex(-4, 3))
|
||||
// A stage never visited has no visit to index.
|
||||
assertEquals(0, clampVisitIndex(5, 0))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun visitTabsShowOnlyForMoreThanOneVisit() {
|
||||
assertFalse(showVisitTabs(0))
|
||||
assertFalse(showVisitTabs(1))
|
||||
assertTrue(showVisitTabs(2))
|
||||
assertTrue(showVisitTabs(7))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun controlVisitLabelHandlesMissingMaxAndLimit() {
|
||||
assertEquals("2", controlVisitLabel(ControlEvidence(visit = 2)))
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
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()))))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package net.awan.pipelines.ui.screens
|
||||
|
||||
import net.awan.pipelines.data.protocol.ControlEvidence
|
||||
import net.awan.pipelines.data.protocol.RunStep
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class TimelineTest {
|
||||
|
||||
private fun step(
|
||||
sequence: Int,
|
||||
stage: String,
|
||||
outcome: String = "success",
|
||||
visit: Int = 0,
|
||||
target: String = "",
|
||||
diagnostic: String = "",
|
||||
startedAt: String = "",
|
||||
finishedAt: String = "",
|
||||
) = RunStep(
|
||||
sequence = sequence,
|
||||
stage = stage,
|
||||
outcome = outcome,
|
||||
target = target,
|
||||
diagnostic = diagnostic,
|
||||
startedAt = startedAt,
|
||||
finishedAt = finishedAt,
|
||||
control = if (visit > 0) ControlEvidence(visit = visit) else null,
|
||||
)
|
||||
|
||||
@Test
|
||||
fun emptyRunHasNoEntriesAndNoStageVisits() {
|
||||
val timeline = runTimeline(emptyList())
|
||||
assertTrue(timeline.entries.isEmpty())
|
||||
assertTrue(timeline.visitsByStage.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun oneEntryPerRecordedVisitInOrder() {
|
||||
val timeline = runTimeline(
|
||||
listOf(
|
||||
step(1, "planner", outcome = "success"),
|
||||
step(2, "implementer", outcome = "success"),
|
||||
step(3, "reviewer", outcome = "rejected"),
|
||||
),
|
||||
)
|
||||
assertEquals(listOf("planner", "implementer", "reviewer"), timeline.entries.map { it.stageKey })
|
||||
assertEquals(listOf(1, 2, 3), timeline.entries.map { it.step.sequence })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun visitNumberUsesControlVisitAndVisitIndexFollowsSequence() {
|
||||
// Three visits of one stage, delivered out of sequence order.
|
||||
val timeline = runTimeline(
|
||||
listOf(
|
||||
step(5, "reviewer", outcome = "rejected", visit = 2),
|
||||
step(2, "reviewer", outcome = "success", visit = 1),
|
||||
step(9, "reviewer", outcome = "approved", visit = 3),
|
||||
),
|
||||
)
|
||||
assertEquals(listOf("reviewer"), timeline.visitsByStage.keys.toList())
|
||||
// Visits are ordered by sequence: 2, 5, 9.
|
||||
assertEquals(listOf(2, 5, 9), timeline.visitsByStage.getValue("reviewer").map { it.sequence })
|
||||
val bySequence = timeline.entries.associateBy { it.step.sequence }
|
||||
assertEquals(1, bySequence.getValue(2).visit)
|
||||
assertEquals(2, bySequence.getValue(5).visit)
|
||||
assertEquals(3, bySequence.getValue(9).visit)
|
||||
// visitIndex is the position within the stage's ordered visits.
|
||||
assertEquals(0, bySequence.getValue(2).visitIndex)
|
||||
assertEquals(1, bySequence.getValue(5).visitIndex)
|
||||
assertEquals(2, bySequence.getValue(9).visitIndex)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun visitNumberFallsBackToPositionWhenControlIsMissing() {
|
||||
val timeline = runTimeline(
|
||||
listOf(
|
||||
step(1, "reviewer"),
|
||||
step(2, "reviewer"),
|
||||
),
|
||||
)
|
||||
assertEquals(listOf(1, 2), timeline.entries.map { it.visit })
|
||||
assertEquals(listOf(0, 1), timeline.entries.map { it.visitIndex })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun blankOutcomeAndStatusRenderSafely() {
|
||||
val timeline = runTimeline(listOf(RunStep(sequence = 1, stage = "x")))
|
||||
val entry = timeline.entries.single()
|
||||
assertEquals("", entry.outcomeLabel)
|
||||
assertEquals(null, entry.duration)
|
||||
assertEquals("", entry.description)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun descriptionPrefersDiagnosticThenTarget() {
|
||||
assertEquals(
|
||||
"first line",
|
||||
timelineDescription(step(1, "a", diagnostic = "\n first line \nsecond")),
|
||||
)
|
||||
assertEquals("→ SUCCESS", timelineDescription(step(1, "a", target = "#success")))
|
||||
assertEquals("→ FAILURE", timelineDescription(step(1, "a", target = "#failure")))
|
||||
assertEquals("", timelineDescription(step(1, "a")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun durationComesFromTheSharedFormatter() {
|
||||
val timeline = runTimeline(
|
||||
listOf(
|
||||
step(1, "a", startedAt = "2026-10-15T02:00:00Z", finishedAt = "2026-10-15T02:02:05Z"),
|
||||
),
|
||||
)
|
||||
assertEquals("2m 5s", timeline.entries.single().duration)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user