Lead a run's stage pane with the run's results
A stage opened from a run (Timeline, run graph or run stage list) now leads with the run-side result instead of the stage's own definition: status, outcome, duration, visit and target, then the visit's results in the order Artifacts (gallery first), Output, Input, then the remaining run evidence under This run. The stage's full definition (type, prompt, output contract, outcomes, model, provider, configs, tools, limits, memory, notify) moves into one collapsed "Stage definition" section at the bottom. StageDetailPane gains a runContext flag: RunStagePane passes true and gets the collapsed-definition default, while PipelineStagePane passes false and keeps the definition expanded, since it is then the pane's only content. rememberSectionExpansion gains an initiallyExpanded set (part of the save key) so the seed respects an operator's own expand/collapse choices without inheriting them across contexts. Nothing visible before is removed - the previous Model/Provider headline promotion is reverted and those facts remain reachable inside the expanded definition. The visit tabs and the collapsed-by-default behaviour of the other sections are unchanged. android/ only; no dependency added. Updates android/README.md and StageDetailSheetTest.kt accordingly.
This commit is contained in:
@@ -239,9 +239,13 @@ fun DetailTabBody(
|
||||
|
||||
/**
|
||||
* Remembers which inner sections are expanded, keyed by their stable section
|
||||
* key and saved across configuration changes. Every section starts collapsed the
|
||||
* first time a screen is opened (the initial set is empty); the operator's own
|
||||
* expand/collapse choices are persisted (as an [ArrayList] a Bundle can hold).
|
||||
* key and saved across configuration changes. Sections start collapsed unless
|
||||
* [initiallyExpanded] names some, which only a screen whose sections would
|
||||
* otherwise read as empty does (see the pipeline stage pane's definition); the
|
||||
* operator's own expand/collapse choices are then persisted (as an [ArrayList]
|
||||
* a Bundle can hold). [initiallyExpanded] participates in the save key, so a pane
|
||||
* switching between run and definition contexts reseeds rather than inheriting
|
||||
* the other context's choices.
|
||||
*/
|
||||
@Stable
|
||||
class SectionExpansionState internal constructor(
|
||||
@@ -260,9 +264,12 @@ private val expandedKeysSaver: Saver<Set<String>, ArrayList<String>> = Saver(
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun rememberSectionExpansion(vararg inputs: Any?): SectionExpansionState {
|
||||
val expanded = rememberSaveable(*inputs, stateSaver = expandedKeysSaver) {
|
||||
mutableStateOf(emptySet())
|
||||
fun rememberSectionExpansion(
|
||||
vararg inputs: Any?,
|
||||
initiallyExpanded: Set<String> = emptySet(),
|
||||
): SectionExpansionState {
|
||||
val expanded = rememberSaveable(*inputs, initiallyExpanded, stateSaver = expandedKeysSaver) {
|
||||
mutableStateOf(initiallyExpanded)
|
||||
}
|
||||
return remember(expanded) { SectionExpansionState(expanded) }
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import net.awan.pipelines.ui.components.CodeBlock
|
||||
import net.awan.pipelines.ui.components.DetailTabBody
|
||||
import net.awan.pipelines.ui.components.KeyValueRow
|
||||
import net.awan.pipelines.ui.components.PaneIdentity
|
||||
import net.awan.pipelines.ui.components.SectionExpansionState
|
||||
import net.awan.pipelines.ui.components.SectionHeader
|
||||
import net.awan.pipelines.ui.components.rememberSectionExpansion
|
||||
import net.awan.pipelines.ui.displayMap
|
||||
@@ -138,45 +139,59 @@ internal fun controlVisitLabel(control: ControlEvidence): String {
|
||||
}
|
||||
|
||||
/**
|
||||
* The identity/result labels that must be visible the moment the stage pane is
|
||||
* opened, before anything is expanded: the stage's status and outcome, its
|
||||
* target, duration, visit and model target. Everything else lives in a
|
||||
* collapsible section.
|
||||
* The run-side identity/result labels that must be visible the moment a run's
|
||||
* stage pane is opened, before anything is expanded: the stage's status and
|
||||
* outcome, its target, duration, visit and the model it targeted. The stage's
|
||||
* own definition (including its model and provider configs) is deliberately not
|
||||
* part of these; it lives in the collapsed stage-definition section below.
|
||||
*/
|
||||
internal val STAGE_HEADLINE_LABELS: Set<String> =
|
||||
setOf("Status", "Outcome", "Target", "Duration", "Visit", "Model target")
|
||||
|
||||
/** The always-visible identity/result fields of a step's recorded evidence. */
|
||||
/** The always-visible run-side identity/result fields of a step's evidence. */
|
||||
internal fun headlineFields(fields: List<StageField>): List<StageField> =
|
||||
fields.filter { it.label in STAGE_HEADLINE_LABELS }
|
||||
|
||||
/**
|
||||
* The remaining run evidence (diagnostic, transcript, session/agent, file
|
||||
* changes, notifications) that belongs in a collapsible section: the headline
|
||||
* facts and the input/output blocks are surfaced elsewhere.
|
||||
* facts and the input/output result blocks are surfaced elsewhere.
|
||||
*/
|
||||
internal fun evidenceFields(fields: List<StageField>): List<StageField> =
|
||||
fields.filter { it.label !in STAGE_HEADLINE_LABELS && it.label != "Input" && it.label != "Output" }
|
||||
|
||||
/**
|
||||
* The definition configs promoted to the always-visible headline so the operator
|
||||
* sees the recorded model and provider without expanding Definition. Only these
|
||||
* two labels are promoted; the rest of the definition stays collapsible. Pure,
|
||||
* so the promotion is unit-tested without the Compose runtime.
|
||||
*/
|
||||
internal val STAGE_CONFIG_HEADLINE_LABELS: Set<String> = setOf("Model", "Provider")
|
||||
/** The section key of the one stage-definition section (expansion is saved on it). */
|
||||
internal const val STAGE_DEFINITION_KEY = "definition"
|
||||
|
||||
/** The non-blank Model/Provider config rows of [definition], in definition order. */
|
||||
internal fun stageConfigHeadlineFields(definition: List<StageField>): List<StageField> =
|
||||
definition.filter { it.label in STAGE_CONFIG_HEADLINE_LABELS }
|
||||
/** The stage-definition section's title, naming clearly what it holds. */
|
||||
internal const val STAGE_DEFINITION_TITLE = "Stage definition"
|
||||
|
||||
/**
|
||||
* The definition rows that stay in the collapsed Definition section: everything
|
||||
* except the configs [stageConfigHeadlineFields] already promoted to the
|
||||
* headline, so a promoted fact is never rendered twice.
|
||||
* Whether the stage-definition section starts expanded. It is the only content of
|
||||
* a pane opened without a run context (a pipeline's own stage definition, see
|
||||
* [PipelineStagePane]), and starts collapsed in a run pane, where the run's
|
||||
* results lead and the definition sits at the bottom. An operator's own
|
||||
* expand/collapse choice is still remembered on top of this default.
|
||||
*/
|
||||
internal fun remainingDefinitionFields(definition: List<StageField>): List<StageField> =
|
||||
definition.filter { it.label !in STAGE_CONFIG_HEADLINE_LABELS }
|
||||
internal fun definitionStartsExpanded(runContext: Boolean): Boolean = !runContext
|
||||
|
||||
/**
|
||||
* One run-side result section of the stage pane. The order is the operator's
|
||||
* stated preference: the artifacts gallery first, then the output the stage
|
||||
* produced for that visit, then the input it received.
|
||||
*/
|
||||
internal enum class StageResultSection(val key: String) {
|
||||
Artifacts("artifacts"),
|
||||
Output("output"),
|
||||
Input("input"),
|
||||
}
|
||||
|
||||
/** The run-side result sections, in display order (the artifacts gallery first). */
|
||||
internal val STAGE_RESULT_SECTIONS: List<StageResultSection> = listOf(
|
||||
StageResultSection.Artifacts,
|
||||
StageResultSection.Output,
|
||||
StageResultSection.Input,
|
||||
)
|
||||
|
||||
/**
|
||||
* The pure run view of one [RunStep] for the selected stage: status, outcome,
|
||||
@@ -292,6 +307,7 @@ fun StageDetailPane(
|
||||
wide: Boolean = false,
|
||||
modifier: Modifier = Modifier,
|
||||
covered: Boolean = false,
|
||||
runContext: Boolean = false,
|
||||
) {
|
||||
// A covered pane shows its compact identity only; the visit tab row and the
|
||||
// stage body must never be drawn squeezed into the peek strip.
|
||||
@@ -325,6 +341,7 @@ fun StageDetailPane(
|
||||
configuredServerUrl = configuredServerUrl,
|
||||
fetchArtifactBytes = fetchArtifactBytes,
|
||||
wide = wide,
|
||||
runContext = runContext,
|
||||
modifier = Modifier.padding(padding),
|
||||
)
|
||||
}
|
||||
@@ -341,6 +358,7 @@ private fun StageDetailBody(
|
||||
configuredServerUrl: String,
|
||||
fetchArtifactBytes: suspend (String) -> ByteArray?,
|
||||
wide: Boolean,
|
||||
runContext: Boolean,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val text = pipelinesText()
|
||||
@@ -357,15 +375,23 @@ private fun StageDetailBody(
|
||||
}
|
||||
val clampedVisit = clampVisitIndex(visitIndex, runSteps.size)
|
||||
val selectedStep = runSteps.getOrNull(clampedVisit)
|
||||
// Derived once per selected step, not per recomposition.
|
||||
// Derived once per selected step, not per recomposition. Only the run-side
|
||||
// facts lead the pane; the stage's own configs stay in the definition section.
|
||||
val runFields = remember(selectedStep) { selectedStep?.let(::runStepFields).orEmpty() }
|
||||
// The identity/result facts, plus the stage's recorded Model/Provider, are
|
||||
// visible without expanding anything; nothing is derived per frame.
|
||||
val configHeadline = remember(definition) { stageConfigHeadlineFields(definition) }
|
||||
val headline = headlineFields(runFields) + configHeadline
|
||||
val headline = headlineFields(runFields)
|
||||
val inputFields = remember(runFields) { runFields.filter { it.label == "Input" } }
|
||||
val outputFields = remember(runFields) { runFields.filter { it.label == "Output" } }
|
||||
val evidence = evidenceFields(runFields)
|
||||
val definitionRows = remember(definition) { remainingDefinitionFields(definition) }
|
||||
val expansion = rememberSectionExpansion(stageKey)
|
||||
// The stage definition is the only content of a pane without a run context,
|
||||
// so it starts expanded there and collapsed at the bottom of a run pane.
|
||||
val expansion = rememberSectionExpansion(
|
||||
stageKey,
|
||||
initiallyExpanded = if (definitionStartsExpanded(runContext)) {
|
||||
setOf(STAGE_DEFINITION_KEY)
|
||||
} else {
|
||||
emptySet()
|
||||
},
|
||||
)
|
||||
|
||||
DetailTabBody(wide, modifier) { columnModifier ->
|
||||
Column(
|
||||
@@ -403,56 +429,66 @@ private fun StageDetailBody(
|
||||
Text("No details recorded for this node.", style = text.meta)
|
||||
}
|
||||
|
||||
if (definitionRows.isNotEmpty()) {
|
||||
val key = "definition"
|
||||
SectionHeader(key.capitalized(), expansion.isExpanded(key), { expansion.toggle(key) })
|
||||
if (expansion.isExpanded(key)) {
|
||||
definitionRows.forEach { field -> StageFieldRow(field) }
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedStep != null) {
|
||||
val inputFields = runFields.filter { it.label == "Input" }
|
||||
val outputFields = runFields.filter { it.label == "Output" }
|
||||
if (inputFields.isNotEmpty()) {
|
||||
val key = "input"
|
||||
SectionHeader(key.capitalized(), expansion.isExpanded(key), { expansion.toggle(key) })
|
||||
if (expansion.isExpanded(key)) inputFields.forEach { StageFieldRow(it) }
|
||||
}
|
||||
if (outputFields.isNotEmpty()) {
|
||||
val key = "output"
|
||||
SectionHeader(key.capitalized(), expansion.isExpanded(key), { expansion.toggle(key) })
|
||||
if (expansion.isExpanded(key)) outputFields.forEach { StageFieldRow(it) }
|
||||
}
|
||||
val artifactsKey = "artifacts"
|
||||
SectionHeader(
|
||||
artifactsKey.capitalized(),
|
||||
expansion.isExpanded(artifactsKey),
|
||||
{ expansion.toggle(artifactsKey) },
|
||||
)
|
||||
if (expansion.isExpanded(artifactsKey)) {
|
||||
ArtifactsSection(
|
||||
step = selectedStep,
|
||||
configuredServerUrl = configuredServerUrl,
|
||||
fetchArtifactBytes = fetchArtifactBytes,
|
||||
)
|
||||
// A run pane leads with the run's results: the artifacts gallery
|
||||
// first, then the output and the input, then the remaining evidence.
|
||||
if (runContext && selectedStep != null) {
|
||||
STAGE_RESULT_SECTIONS.forEach { section ->
|
||||
when (section) {
|
||||
StageResultSection.Artifacts -> StageSection(expansion, section.key) {
|
||||
ArtifactsSection(
|
||||
step = selectedStep,
|
||||
configuredServerUrl = configuredServerUrl,
|
||||
fetchArtifactBytes = fetchArtifactBytes,
|
||||
)
|
||||
}
|
||||
StageResultSection.Output -> if (outputFields.isNotEmpty()) {
|
||||
StageSection(expansion, section.key) {
|
||||
outputFields.forEach { StageFieldRow(it) }
|
||||
}
|
||||
}
|
||||
StageResultSection.Input -> if (inputFields.isNotEmpty()) {
|
||||
StageSection(expansion, section.key) {
|
||||
inputFields.forEach { StageFieldRow(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (evidence.isNotEmpty()) {
|
||||
val key = "run"
|
||||
SectionHeader(
|
||||
"This run",
|
||||
expansion.isExpanded(key),
|
||||
{ expansion.toggle(key) },
|
||||
)
|
||||
if (expansion.isExpanded(key)) {
|
||||
StageSection(expansion, "run", "This run") {
|
||||
evidence.forEach { field -> StageFieldRow(field) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The stage's own definition sits in one clearly named section: it is
|
||||
// the pane's only content without a run context (so it starts
|
||||
// expanded) and the collapsed last section of a run pane.
|
||||
if (definition.isNotEmpty()) {
|
||||
StageSection(expansion, STAGE_DEFINITION_KEY, STAGE_DEFINITION_TITLE) {
|
||||
definition.forEach { field -> StageFieldRow(field) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* One collapsible section of the stage pane: its header toggles [expansion]
|
||||
* under [key] and, while it is expanded, [content] is rendered. The title
|
||||
* defaults to the capitalised key (e.g. `artifacts` → `Artifacts`), so the pane
|
||||
* names every section the same way.
|
||||
*/
|
||||
@Composable
|
||||
private fun StageSection(
|
||||
expansion: SectionExpansionState,
|
||||
key: String,
|
||||
title: String = key.capitalized(),
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
SectionHeader(title, expansion.isExpanded(key), { expansion.toggle(key) })
|
||||
if (expansion.isExpanded(key)) content()
|
||||
}
|
||||
|
||||
/** The stage pane hosted directly by the run destination, reading the run detail. */
|
||||
@Composable
|
||||
fun RunStagePane(
|
||||
@@ -482,6 +518,7 @@ fun RunStagePane(
|
||||
wide = wide,
|
||||
modifier = modifier,
|
||||
covered = covered,
|
||||
runContext = true,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ class StageDetailSheetTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun definitionModelAndProviderArePromotedToTheHeadlineWithoutDuplication() {
|
||||
fun theRunHeadlineIsRunSideOnlyAndTheDefinitionKeepsModelAndProvider() {
|
||||
val stage = Stage(
|
||||
key = "implementer",
|
||||
type = "model",
|
||||
@@ -177,31 +177,36 @@ class StageDetailSheetTest {
|
||||
),
|
||||
)
|
||||
val definition = stageDefinitionFields(stage)
|
||||
val promoted = stageConfigHeadlineFields(definition).map { it.label }
|
||||
assertEquals(listOf("Model", "Provider"), promoted)
|
||||
// The promoted facts stay in the always-visible headline...
|
||||
// Nothing is removed: the definition section still carries model/provider.
|
||||
val labels = definition.map { it.label }
|
||||
assertTrue(labels.containsAll(listOf("Type", "Prompt", "Model", "Provider", "Retries")))
|
||||
assertEquals("deepseek-v4.1-flash", definition.first { it.label == "Model" }.value)
|
||||
assertEquals("opencode-go", definition.first { it.label == "Provider" }.value)
|
||||
// The always-visible headline is the run-side result only.
|
||||
val step = RunStep(
|
||||
status = "completed",
|
||||
outcome = "success",
|
||||
target = "reviewer",
|
||||
control = ControlEvidence(visit = 1, maxVisits = 5, modelTarget = "deepseek-v4.1-flash"),
|
||||
)
|
||||
val headline = headlineFields(runStepFields(step)) + stageConfigHeadlineFields(definition)
|
||||
val labels = headline.map { it.label }
|
||||
assertEquals(listOf("Status", "Outcome", "Visit", "Model target", "Target", "Model", "Provider"), labels)
|
||||
assertEquals("deepseek-v4.1-flash", headline.first { it.label == "Model" }.value)
|
||||
assertEquals("opencode-go", headline.first { it.label == "Provider" }.value)
|
||||
// ...and are never rendered a second time in the collapsed Definition.
|
||||
val remaining = remainingDefinitionFields(definition).map { it.label }
|
||||
assertTrue(remaining.none { it == "Model" || it == "Provider" })
|
||||
// The rest of the definition is untouched and still needs no expansion to exist.
|
||||
assertTrue(remaining.containsAll(listOf("Type", "Prompt", "Retries")))
|
||||
val headline = headlineFields(runStepFields(step)).map { it.label }
|
||||
assertEquals(listOf("Status", "Outcome", "Visit", "Model target", "Target"), headline)
|
||||
assertTrue(headline.none { it == "Model" || it == "Provider" })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aDefinitionWithNoConfigsPromotesNothing() {
|
||||
val fields = stageDefinitionFields(Stage(key = "planner"))
|
||||
assertTrue(stageConfigHeadlineFields(fields).isEmpty())
|
||||
assertEquals(fields, remainingDefinitionFields(fields))
|
||||
fun theDefinitionStartsExpandedOnlyWithoutARunContext() {
|
||||
// A pipeline's stage definition is the pane's only content, so it starts
|
||||
// expanded; a run pane leads with results and collapses the definition.
|
||||
assertTrue(definitionStartsExpanded(runContext = false))
|
||||
assertFalse(definitionStartsExpanded(runContext = true))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theRunResultSectionsLeadWithTheArtifactsGallery() {
|
||||
assertEquals(
|
||||
listOf("artifacts", "output", "input"),
|
||||
STAGE_RESULT_SECTIONS.map { it.key },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user