Merge lane-chat2: keep the lane's reviewed work

This commit is contained in:
2026-10-17 12:46:18 +01:00
7 changed files with 613 additions and 51 deletions
+123
View File
@@ -5415,3 +5415,126 @@ open in a chosen directory — the brief keeps implementation verification to th
build and the unit tests, and visual review owns the device. The chip, menu and
dialog are Compose UI, which this module has no unit harness for; they are
covered by compilation only.
## A conversation opens at the newest message, and follows it (17 Oct 2026)
Opening a conversation used to start at the top of the transcript, so the first
thing the operator did was scroll down past everything already said to find the
current turn. This item is the scroll and follow behaviour plus a jump-to-latest
affordance; the transcript rendering, streaming, tool chips, diff cards and
approval cards are unchanged. `android/` only; nothing in the Pipelines server,
its Go source, the installer or the Docker files was touched, no dependency was
added beyond the already-declared material-icons-extended, and no run is started
from the app.
- **Opening at the newest message.** The transcript's list state is now created
the moment the conversation first has content, with its first visible item set
by `chatFirstScroll` (`ui/chat/ChatScroll.kt`): a conversation the operator has a
position of their own in is restored, and every other conversation — i.e. every
freshly opened chat — starts at its newest message. "A position of their own" is
explicit now: `ChatThread.scroll` is nullable, null meaning the operator has
never left a position here, so a chat they deliberately left at the very top
(`ChatScrollPosition(0, 0)`) is restored rather than mistaken for "new". The
restore/clamp rule is the app's existing shared one (`restoredScrollAnchor`,
`ui/components/ListScroll.kt`): the saved index is clamped to the messages that
still exist and the offset is kept only when the saved message survived, so a
conversation that shrank underneath neither throws nor draws part-way down an
unrelated message. Placement happens on the list's *first* measure — it waits
for the viewport to be measured — so opening a chat never shows the top first,
and it goes through the same `scrollToEnd(itemCount, animated = false)` the
follow uses, never animated: a fresh conversation is placed at its newest item
(and a last message taller than the viewport has the part still below the fold
closed in the same settling), and a position the operator left is restored.
Because placement and follow share the one path, they cannot disagree about what
the newest item is — the earlier split (placement closed the gap directly) left a
conversation that grew between state creation and first measure showing the older
anchor with the newest item below the fold. Leaving a chat still persists its
position (a list state that never held content saves nothing), so returning to it
restores where the operator was. The placement flag and the follow state are
`rememberSaveable` too, so a rotation or process death while the operator is
reading history does not re-place the transcript and yank them back to the
bottom.
- **One scroll path, changed deliberately.** The existing follow scroll, the app
bar's approval jump and the new jump-to-latest all go through one helper:
`LazyListState.scrollToEnd(itemCount, animated)`. When the newest item sits
entirely below the fold — an item appended exactly at the viewport edge, with no
pixel on screen, so the distance to the end cannot be measured — it is brought
into view first (`animateScrollToItem`/`scrollToItem`); any part of it still
below the fold (a message taller than the viewport) is then closed by exactly
that distance (`closeBottomGap`). An item that is already partly visible is only
gap-closed, never moved up first, so following a growing stream never bounces.
There is no second scroll mechanism beside it. The distance is measured against
the transcript's *content* count (`bottomDistancePx(itemCount)`), not the count
the layout has measured: the follow effect is dispatched ahead of the measure
that appends the new item, so on that frame the layout still describes the
previous items and its own last visible item reads as the end — a stale
`totalItemsCount` makes an appended item look like the already-visible end, no
gap is detected and the item is never brought in. Reconciling the two counts is
what makes an arriving message, the local prompt plus running indicator appended
together, or an approval card actually arrive in view.
- **Follow while reading the newest part.** Following is the operator's position,
not only their intent: only their own drag changes it (a `DragInteraction.Start`
stops it, and a `Stop`/`Cancel` resumes it when the scroll settles at — or
within `CHAT_FOLLOW_THRESHOLD_DP` of — the bottom, `chatFollowsAt`), and it is
settled at placement from the live distance so a position restored away from the
bottom does not follow. While it holds, an arriving message (including one that
lands entirely below the fold), a streamed delta, a tool chip, a freshly arrived
approval card, a grown composer or the appearing keyboard re-follows smoothly;
the whole viewport height is an input to the follow effect, so the newest
message is never left hidden behind the composer or the IME. Programmatic
scrolls never touch the list's `interactionSource`, so they cannot un-stick the
view. The item count the decisions measure against is read at use time
(`rememberUpdatedState`): the drag collector and the affordance's derived state
outlive a recomposition, so a captured count would go stale as messages arrive
and the follow would measure against how many items there used to be.
- **Threshold.** `CHAT_FOLLOW_THRESHOLD_DP` (`ui/theme/Dimens.kt`) is **32dp**:
about one comfortable line of text, so the operator can be slightly off the
exact bottom (the list's own bottom gutter included) and still be pulled along,
while a deliberate scroll up stops the view moving under them.
- **Jump to latest.** A small Material 3 `SmallFloatingActionButton` (the
already-declared `KeyboardArrowDown` icon, at the transcript's bottom-end on the
shared gutter token) is offered while the view is *not* following and there is
genuinely something below the fold (`chatShowJumpToLatest`), and hidden at the
bottom or for an empty transcript. Tapping it re-engages the follow and returns
to the newest message. A pending permission/approval is still brought into view
the way the existing code did — it is the transcript's last item, so the follow
brings it in when the operator is reading the newest part, and the app bar's
approval action still jumps straight to it on demand.
- **Tests.** `ChatScrollTest` (11 cases) pins the pure decisions: the distance to
the end (overflow past the viewport, 0 once in view, null when a whole item is
below the fold — the case an item appended at the viewport edge creates, which
the follow must bring into view rather than only gap-close — or the list is
unmeasured), the same distance reconciled against the content count while the
layout still lags it by one item (the stale frame the follow runs on: read
against the layout's own count it is 0 and nothing moves; read against the
content count it is unknown and the item is brought in), the follow resuming
at/within the threshold but not beyond it, the jump-to-latest visibility (offered
only while away from the bottom, hidden at the bottom and for an empty
transcript), and the first placement (a fresh conversation — no position of its
own — at its newest message, a left position restored and clamped, a position at
the very top kept distinct from "new", and nothing to place when empty).
Evidence (this run's implementer pass, macOS, Kotlin `jvmTarget` 17, Gradle 9.7.1
launcher on JVM 25.0.4.1, `ANDROID_HOME=/Users/alan/Library/Android/sdk`,
cached/offline): `gradle --no-daemon --offline :app:testDebugUnitTest
:app:assembleDebug` → `BUILD SUCCESSFUL`, and `:app:testDebugUnitTest
--rerun-tasks` re-executed every test: the JUnit XMLs total **50 suites / 458
tests / 0 failures / 0 errors / 0 skipped**, including the new `ChatScrollTest`
(11 cases) and the existing chat suites (`ChatStreamTest`, `ChatApprovalTest`,
`MultiChatStateTest`, `ChatSessionManagementTest`, `ChatDirectoriesTest`,
`ChatFormatTest`, `ChatProtocolTest`) green. The APK was published to this run's
artifacts directory as `pipelines-debug-wip-311a015.apk` (18,601,229 bytes, sha256
`a3b45c3518e524f53719de243916fe4fcf120a82fad7c2de09b634bff717b1b6`; `311a015` is
`git rev-parse --short HEAD`, the tree being uncommitted WIP on top of it) and is
served at
`http://10.0.0.75:8080/artifacts/247/1/pipelines-debug-wip-311a015.apk`
(`HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
`Content-Length: 18601229`).
Not verified in this pass: the follow/affordance behaviour on a device and every
claim about first-display smoothness — the brief keeps implementation
verification to the build and the unit tests, and visual review owns the device.
The composable's frame timing (placing the list before its first draw, the
instant correction for a last message taller than the viewport, and the fallback
that brings an item appended below the fold into view) is argued from the pinned
Compose BOM (2024.10.00) and the pure decisions it delegates to, not observed.