diff --git a/android/app/src/main/java/net/awan/pipelines/ui/AppViewModel.kt b/android/app/src/main/java/net/awan/pipelines/ui/AppViewModel.kt index 1309d46b..b36fcdb6 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/AppViewModel.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/AppViewModel.kt @@ -34,7 +34,6 @@ import net.awan.pipelines.data.protocol.Protocol import net.awan.pipelines.data.protocol.RunDetail import net.awan.pipelines.data.protocol.RunEventFrame import net.awan.pipelines.data.protocol.SearchResponse -import net.awan.pipelines.data.protocol.SessionEvidence import net.awan.pipelines.data.protocol.Template import net.awan.pipelines.data.transport.ConnectionState import net.awan.pipelines.data.transport.ServerUrl @@ -119,9 +118,6 @@ class AppViewModel( private val _runDetail = MutableStateFlow(LoadState()) val runDetail: StateFlow> = _runDetail.asStateFlow() - private val _evidence = MutableStateFlow(LoadState>()) - val evidence: StateFlow>> = _evidence.asStateFlow() - /** * Whether the live run stream is delivering pushes. Shown as the small * "live"/"reconnecting" badge in the runs list and the run detail so a view @@ -794,8 +790,6 @@ class AppViewModel( } } - fun loadEvidence(id: Long) = load(_evidence) { repository.getRunEvidence(id) } - /** Fetches an artifact's bytes for an inline image preview; null on failure. */ suspend fun fetchArtifactBytes(url: String): ByteArray? = runCatching { repository.fetchArtifactBytes(url) }.getOrNull() @@ -865,14 +859,6 @@ class AppViewModel( } } - /** - * Drops any previously loaded evidence so a different run never shows the - * previous run's records. Evidence is then fetched on demand, never polled. - */ - fun resetEvidence() { - _evidence.value = LoadState() - } - /** * Loads a run on demand (opening it, or after a manual cancel/retry). * [silent] keeps the current content without a loading flash while it is diff --git a/android/app/src/main/java/net/awan/pipelines/ui/OmniSearchResults.kt b/android/app/src/main/java/net/awan/pipelines/ui/OmniSearchResults.kt index 2bbc9553..fd841a44 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/OmniSearchResults.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/OmniSearchResults.kt @@ -304,7 +304,9 @@ fun searchTarget(hit: SearchResult): SearchTarget? = when { fun searchFieldSection(field: String): Int = when (field) { "input" -> 2 "output" -> 3 - "evidence", "transcript" -> 4 + // Evidence was a retired run-detail tab. Keep old search hits safe by + // opening Summary rather than accidentally selecting Timeline. + "evidence", "transcript" -> 0 else -> 0 } diff --git a/android/app/src/main/java/net/awan/pipelines/ui/PaneState.kt b/android/app/src/main/java/net/awan/pipelines/ui/PaneState.kt index 99ff82d7..696a1c71 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/PaneState.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/PaneState.kt @@ -20,8 +20,9 @@ const val MAX_PANE_DEPTH = 3 /** * The saved pane-stack selection: which pane is rightmost, which item (0 = none), - * its pipeline/run version, which detail section (page) is showing, which - * stage/visit the stage pane is on and, when a stage section is open, its key. + * its pipeline/run version, which detail section (page) is showing and its + * stable tab key, which stage/visit the stage pane is on and, when a stage + * section is open, its key. * Every field is a primitive, so the state round-trips through a Bundle cheaply * and survives rotation, configuration change and process death. * @@ -36,6 +37,7 @@ data class PaneSelection( val stageKey: String? = null, val stageVisit: Int = 0, val sectionKey: String? = null, + val detailTabKey: String? = null, ) { /** How many panes are stacked: 0 list, 1 detail, 2 stage, 3 section. */ val depth: Int @@ -105,6 +107,7 @@ internal fun encodePaneSelection(selection: PaneSelection): List = listOf( selection.stageKey ?: "", selection.stageVisit, selection.sectionKey ?: "", + selection.detailTabKey ?: "", ) /** Restores a [PaneSelection] encoded by [encodePaneSelection]. */ @@ -116,6 +119,7 @@ internal fun decodePaneSelection(encoded: List): PaneSelection = PaneSelect stageKey = (encoded[4] as String).takeIf { it.isNotEmpty() }, stageVisit = encoded[5] as Int, sectionKey = (encoded[6] as String).takeIf { it.isNotEmpty() }, + detailTabKey = encoded.getOrNull(7)?.let { it as String }?.takeIf { it.isNotEmpty() }, ) /** diff --git a/android/app/src/main/java/net/awan/pipelines/ui/RunsDestination.kt b/android/app/src/main/java/net/awan/pipelines/ui/RunsDestination.kt index 0fa97a1b..7942b12a 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/RunsDestination.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/RunsDestination.kt @@ -11,8 +11,8 @@ import androidx.compose.ui.Modifier import androidx.lifecycle.compose.collectAsStateWithLifecycle import kotlinx.coroutines.flow.collect import net.awan.pipelines.ui.components.SlidingPaneStack -import net.awan.pipelines.ui.components.clampTabIndex import net.awan.pipelines.ui.components.rememberPaneContent +import net.awan.pipelines.ui.components.runDetailTabIndex import net.awan.pipelines.ui.components.runDetailTabs import net.awan.pipelines.ui.graph.RunStagePane import net.awan.pipelines.ui.screens.RunDetailScreen @@ -91,8 +91,15 @@ internal fun RunsDestination( vm = vm, runId = itemId, onBack = onBack, - selectedSection = clampTabIndex(sectionIndex, runDetailTabs.size), - onSelectSection = { onSelectionChange(selection.copy(sectionIndex = it)) }, + selectedSection = runDetailTabIndex(selection.detailTabKey, sectionIndex), + onSelectSection = { index -> + onSelectionChange( + selection.copy( + sectionIndex = index, + detailTabKey = runDetailTabs[index].key, + ), + ) + }, modifier = paneModifier, wide = wide, onOpenStage = { key, visit -> diff --git a/android/app/src/main/java/net/awan/pipelines/ui/components/DetailTabs.kt b/android/app/src/main/java/net/awan/pipelines/ui/components/DetailTabs.kt index 7dee2ded..832fa45a 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/components/DetailTabs.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/components/DetailTabs.kt @@ -16,7 +16,6 @@ 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.List import androidx.compose.material.icons.automirrored.filled.Send @@ -63,10 +62,25 @@ val runDetailTabs: List = listOf( DetailTab("graph", "Graph", Icons.Default.Hub), DetailTab("input", "Input", Icons.AutoMirrored.Filled.Input), DetailTab("output", "Output", Icons.AutoMirrored.Filled.Send), - DetailTab("evidence", "Evidence", Icons.AutoMirrored.Filled.FactCheck), DetailTab("steps", "Timeline", Icons.AutoMirrored.Filled.List), ) +/** + * Resolves a run-detail selection from its stable [key], falling back to its + * index when it was produced by this version of the app. Saved selections from + * before Evidence was removed use the old index order: Evidence (4) deliberately + * returns to Summary and Timeline (5) moves to its new last index. + */ +fun runDetailTabIndex(key: String?, index: Int): Int { + val keyedIndex = key?.let { selectedKey -> runDetailTabs.indexOfFirst { it.key == selectedKey } } + if (keyedIndex != null && keyedIndex >= 0) return keyedIndex + return when (index) { + 4 -> 0 + 5 -> runDetailTabs.lastIndex + else -> clampTabIndex(index, runDetailTabs.size) + } +} + /** Pipeline-detail tabs, Summary first (the version list lives inside it). */ val pipelineDetailTabs: List = listOf( DetailTab("summary", "Summary", Icons.Default.Info), diff --git a/android/app/src/main/java/net/awan/pipelines/ui/screens/RunDetailScreen.kt b/android/app/src/main/java/net/awan/pipelines/ui/screens/RunDetailScreen.kt index d817c800..1725c38b 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/screens/RunDetailScreen.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/screens/RunDetailScreen.kt @@ -40,7 +40,6 @@ import net.awan.pipelines.ui.components.LoadPhase import net.awan.pipelines.ui.components.LoadingState import net.awan.pipelines.ui.components.PaneIdentity import net.awan.pipelines.ui.components.StateCrossfade -import net.awan.pipelines.ui.components.clampTabIndex import net.awan.pipelines.ui.components.detailLoadPhase import net.awan.pipelines.ui.components.paneSafeArea import net.awan.pipelines.ui.components.rememberPaneContent @@ -72,7 +71,6 @@ fun RunDetailScreen( ) { val state by vm.runDetail.collectAsStateWithLifecycle() val runsState by vm.runs.collectAsStateWithLifecycle() - val evidenceState by vm.evidence.collectAsStateWithLifecycle() val configuredServerUrl by vm.configuredServerUrl.collectAsStateWithLifecycle() val runStream by vm.runStream.collectAsStateWithLifecycle() var confirmCancel by remember { mutableStateOf(false) } @@ -88,11 +86,7 @@ fun RunDetailScreen( // Reaching a run clears its notification, whichever path opened it (the // notification's own tap, the attention list, the runs list or a search). vm.arrivedAtRun(runId) - // Scope evidence to this run: drop the previous run's records, then fetch - // this run's evidence once (on demand; live pushes carry no evidence). - vm.resetEvidence() vm.loadRun(runId) - vm.loadEvidence(runId) } val run = state.data?.takeIf { it.id == runId } @@ -115,7 +109,7 @@ fun RunDetailScreen( val candidateArtifacts = remember(artifactGroups) { artifactGroups.flatMap { it.artifacts }.distinctBy { it.url } } - val summaryTab = runDetailTabs.getOrNull(clampTabIndex(selectedSection, runDetailTabs.size))?.key + val summaryTab = runDetailTabs.getOrNull(selectedSection)?.key // A covered pane shows its compact identity only; the tab rail, timeline and // graphs must never be drawn squeezed into the peek strip. The run belongs to @@ -268,13 +262,6 @@ fun RunDetailScreen( wide = wide, modifier = contentModifier, ) - "evidence" -> RunEvidenceTab( - evidenceState = evidenceState, - steps = shownRun.steps, - onLoadEvidence = { vm.loadEvidence(runId) }, - wide = wide, - modifier = contentModifier, - ) else -> RunTimelineTab( run = shownRun, wide = wide, diff --git a/android/app/src/main/java/net/awan/pipelines/ui/screens/RunEvidenceTab.kt b/android/app/src/main/java/net/awan/pipelines/ui/screens/RunEvidenceTab.kt deleted file mode 100644 index 130c12eb..00000000 --- a/android/app/src/main/java/net/awan/pipelines/ui/screens/RunEvidenceTab.kt +++ /dev/null @@ -1,136 +0,0 @@ -package net.awan.pipelines.ui.screens - -import androidx.compose.foundation.ExperimentalFoundationApi -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.OutlinedButton -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember -import androidx.compose.ui.Modifier -import net.awan.pipelines.data.protocol.RunStep -import net.awan.pipelines.data.protocol.SessionEvidence -import net.awan.pipelines.ui.LoadState -import net.awan.pipelines.ui.components.CodeBlock -import net.awan.pipelines.ui.components.DetailTabBody -import net.awan.pipelines.ui.components.collapsibleSection -import net.awan.pipelines.ui.components.pillContentPadding -import net.awan.pipelines.ui.components.rememberSectionExpansion -import net.awan.pipelines.ui.theme.SPACING_L -import net.awan.pipelines.ui.theme.SPACING_S -import net.awan.pipelines.ui.theme.SPACING_XS -import net.awan.pipelines.ui.theme.pipelinesText - -/** One inner collapsible section per session-evidence entry (data block inside). */ -@OptIn(ExperimentalFoundationApi::class) -@Composable -internal fun RunEvidenceTab( - evidenceState: LoadState>, - steps: List, - onLoadEvidence: () -> Unit, - wide: Boolean, - modifier: Modifier, -) { - val text = pipelinesText() - val evidence = evidenceState.data.orEmpty() - val expansion = rememberSectionExpansion(evidence) - // Correlate each evidence record with its step once per data change, by the - // protocol's shared sequence, never per recomposition. - val stepBySequence = remember(steps) { steps.associateBy { it.sequence } } - DetailTabBody(wide, modifier) { columnModifier -> - LazyColumn( - modifier = columnModifier, - contentPadding = pillContentPadding(PaddingValues(vertical = SPACING_L)), - ) { - item(key = "evidence-reload") { - Row( - modifier = Modifier.fillMaxWidth().padding(horizontal = SPACING_L), - horizontalArrangement = Arrangement.spacedBy(SPACING_S), - ) { - OutlinedButton(onClick = onLoadEvidence, enabled = !evidenceState.loading) { - Text(if (evidenceState.loading) "Loading…" else "Reload session evidence") - } - } - } - when { - evidenceState.loading && evidenceState.data == null -> item(key = "evidence-loading") { - Text( - "Loading session evidence…", - style = text.meta, - modifier = Modifier.padding(horizontal = SPACING_L, vertical = SPACING_S), - ) - } - evidenceState.error != null -> item(key = "evidence-error") { - Text( - evidenceState.error!!, - color = MaterialTheme.colorScheme.error, - style = text.meta, - modifier = Modifier.padding(horizontal = SPACING_L, vertical = SPACING_S), - ) - } - evidenceState.loaded && evidence.isEmpty() -> item(key = "evidence-empty") { - Text( - "No session evidence recorded.", - style = text.meta, - modifier = Modifier.padding(horizontal = SPACING_L, vertical = SPACING_S), - ) - } - else -> evidence.forEach { record -> - val sectionKey = "evidence-${record.sequence}-${record.sessionId}" - collapsibleSection( - title = evidenceSectionTitle(record, stepBySequence[record.sequence]), - key = sectionKey, - expanded = expansion.isExpanded(sectionKey), - onToggle = { expansion.toggle(sectionKey) }, - ) { - EvidenceDetails(record, Modifier.padding(horizontal = SPACING_L, vertical = SPACING_XS)) - } - } - } - } - } -} - -/** - * A self-describing evidence-section title: the step, and when the matching - * step is known the stage and visit, plus the backend (or, when absent, the - * session id) identity. Never a bare index; falls back gracefully when the - * record cannot be correlated with a step. - */ -internal fun evidenceSectionTitle(record: SessionEvidence, step: RunStep?): String { - val parts = ArrayList() - if (record.sequence > 0) parts += "step ${record.sequence}" - if (step != null) { - val visit = step.control?.visit?.takeIf { it > 0 } - val stage = buildString { - if (step.stage.isNotBlank()) append(step.stage) - if (visit != null) { - if (isNotEmpty()) append(' ') - append("visit $visit") - } - } - if (stage.isNotBlank()) parts += stage - } - val identity = record.backend.ifBlank { record.sessionId } - if (identity.isNotBlank()) parts += identity - return if (parts.isEmpty()) "Evidence" else "Evidence - " + parts.joinToString(", ") -} - -/** A session-evidence entry's fields plus its data/diagnostic code blocks. */ -@Composable -private fun EvidenceDetails(evidence: SessionEvidence, modifier: Modifier = Modifier) { - val text = pipelinesText() - Column(modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(SPACING_XS)) { - if (evidence.sessionId.isNotBlank()) Text("session ${evidence.sessionId}", style = text.mono) - if (evidence.backend.isNotBlank()) Text("backend ${evidence.backend}", style = text.meta) - if (evidence.directory.isNotBlank()) Text("directory ${evidence.directory}", style = text.meta) - CodeBlock("Diagnostic", evidence.diagnostic.orEmpty()) - CodeBlock("Data", evidence.data.orEmpty()) - } -} diff --git a/android/app/src/test/java/net/awan/pipelines/ui/OmniSearchResultsTest.kt b/android/app/src/test/java/net/awan/pipelines/ui/OmniSearchResultsTest.kt index 2bd8b23d..04d919f4 100644 --- a/android/app/src/test/java/net/awan/pipelines/ui/OmniSearchResultsTest.kt +++ b/android/app/src/test/java/net/awan/pipelines/ui/OmniSearchResultsTest.kt @@ -285,8 +285,8 @@ class OmniSearchResultsTest { fun aTextFieldTargetOpensTheRunDetailSectionHoldingIt() { assertEquals(2, searchFieldSection("input")) assertEquals(3, searchFieldSection("output")) - assertEquals(4, searchFieldSection("evidence")) - assertEquals(4, searchFieldSection("transcript")) + assertEquals(0, searchFieldSection("evidence")) + assertEquals(0, searchFieldSection("transcript")) assertEquals(0, searchFieldSection("other")) assertEquals( diff --git a/android/app/src/test/java/net/awan/pipelines/ui/PaneStateTest.kt b/android/app/src/test/java/net/awan/pipelines/ui/PaneStateTest.kt index e9f9d112..329fee3a 100644 --- a/android/app/src/test/java/net/awan/pipelines/ui/PaneStateTest.kt +++ b/android/app/src/test/java/net/awan/pipelines/ui/PaneStateTest.kt @@ -146,6 +146,14 @@ class PaneStateTest { } } + @Test + fun legacySavedSelectionWithoutATabKeyRemainsReadable() { + assertEquals( + PaneSelection(MasterPane.Detail, 9L, 2, 4), + decodePaneSelection(listOf("Detail", 9L, 2, 4, "", 0, "")), + ) + } + @Test fun encodedPayloadIsPrimitivesOnly() { // Process-death restoration stays small: only Strings, ints and a long, @@ -160,13 +168,13 @@ class PaneStateTest { stageVisit = 4, ), ) - assertEquals(listOf("Stage", 9L, 2, 1, "planner", 4, ""), encoded) + assertEquals(listOf("Stage", 9L, 2, 1, "planner", 4, "", ""), encoded) assertEquals( PaneSelection(MasterPane.Stage, 9L, 2, 1, "planner", 4), decodePaneSelection(encoded), ) assertEquals( - listOf("Detail", 9L, 2, 1, "", 0, ""), + listOf("Detail", 9L, 2, 1, "", 0, "", ""), encodePaneSelection(PaneSelection(MasterPane.Detail, 9L, 2, 1)), ) val section = PaneSelection( @@ -178,7 +186,7 @@ class PaneStateTest { stageVisit = 4, sectionKey = "artifacts", ) - assertEquals(listOf("Section", 9L, 2, 1, "planner", 4, "artifacts"), encodePaneSelection(section)) + assertEquals(listOf("Section", 9L, 2, 1, "planner", 4, "artifacts", ""), encodePaneSelection(section)) assertEquals(section, decodePaneSelection(encodePaneSelection(section))) } } diff --git a/android/app/src/test/java/net/awan/pipelines/ui/components/DetailTabsTest.kt b/android/app/src/test/java/net/awan/pipelines/ui/components/DetailTabsTest.kt index ed3c057a..068fb4d1 100644 --- a/android/app/src/test/java/net/awan/pipelines/ui/components/DetailTabsTest.kt +++ b/android/app/src/test/java/net/awan/pipelines/ui/components/DetailTabsTest.kt @@ -12,11 +12,11 @@ class DetailTabsTest { fun runDetailTabsStartWithSummaryAndCoverEverySection() { assertEquals("summary", runDetailTabs.first().key) assertEquals( - listOf("summary", "graph", "input", "output", "evidence", "steps"), + listOf("summary", "graph", "input", "output", "steps"), runDetailTabs.map { it.key }, ) assertEquals( - listOf("Summary", "Graph", "Input", "Output", "Evidence", "Timeline"), + listOf("Summary", "Graph", "Input", "Output", "Timeline"), runDetailTabs.map { it.title }, ) } @@ -39,9 +39,9 @@ class DetailTabsTest { @Test fun clampTabIndexKeepsAValidSelection() { - assertEquals(0, clampTabIndex(0, 6)) - assertEquals(5, clampTabIndex(5, 6)) - assertEquals(3, clampTabIndex(3, 6)) + assertEquals(0, clampTabIndex(0, 5)) + assertEquals(4, clampTabIndex(4, 5)) + assertEquals(3, clampTabIndex(3, 5)) } @Test @@ -52,6 +52,15 @@ class DetailTabsTest { assertEquals(0, clampTabIndex(1, 0)) } + @Test + fun runDetailTabSelectionUsesStableKeysAndSafelyMigratesLegacyEvidence() { + assertEquals(4, runDetailTabIndex("steps", 5)) + assertEquals(0, runDetailTabIndex("evidence", 4)) + assertEquals(0, runDetailTabIndex(null, 4)) + assertEquals(4, runDetailTabIndex(null, 5)) + assertEquals(4, runDetailTabIndex("steps", 4)) + } + @Test fun sectionsStartCollapsedAndToggleIsRemembered() { val state = SectionExpansionState(mutableStateOf>(emptySet())) diff --git a/android/app/src/test/java/net/awan/pipelines/ui/screens/TimelineTest.kt b/android/app/src/test/java/net/awan/pipelines/ui/screens/TimelineTest.kt index bf3a29f1..54f9bf95 100644 --- a/android/app/src/test/java/net/awan/pipelines/ui/screens/TimelineTest.kt +++ b/android/app/src/test/java/net/awan/pipelines/ui/screens/TimelineTest.kt @@ -2,7 +2,6 @@ package net.awan.pipelines.ui.screens import net.awan.pipelines.data.protocol.ControlEvidence import net.awan.pipelines.data.protocol.RunStep -import net.awan.pipelines.data.protocol.SessionEvidence import net.awan.pipelines.data.protocol.StageArtifact import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse @@ -136,23 +135,4 @@ class TimelineTest { assertTrue(fieldSectionTitle("", "input").isNotBlank()) } - @Test - fun evidenceSectionTitleDescribesStepStageVisitAndIdentity() { - val step = RunStep( - sequence = 4, - stage = "ui_reviewer", - control = ControlEvidence(visit = 1), - ) - assertEquals( - "Evidence - step 4, ui_reviewer visit 1, opencode", - evidenceSectionTitle(SessionEvidence(sequence = 4, backend = "opencode"), step), - ) - // Unmatched evidence still names the step and falls back to the session id. - assertEquals( - "Evidence - step 4, sess-9", - evidenceSectionTitle(SessionEvidence(sequence = 4, sessionId = "sess-9"), null), - ) - // Never a bare index and never empty, even with nothing to say. - assertEquals("Evidence", evidenceSectionTitle(SessionEvidence(), null)) - } } diff --git a/docs/notes/remove-run-evidence-tab.md b/docs/notes/remove-run-evidence-tab.md new file mode 100644 index 00000000..fed9ef64 --- /dev/null +++ b/docs/notes/remove-run-evidence-tab.md @@ -0,0 +1,3 @@ +# Remove run Evidence tab + +The Android run-detail UI no longer exposes its redundant Evidence tab or automatically fetches session evidence when a run opens. No shared README, topic document, or packaged OpenCode skill reference currently documents that tab; this note records the UI behavior change for the manual `docs-fold` pass.