Show chat tool calls as expandable INPUT/OUTPUT chips
Render each assistant turn's tool calls the way the reference jarvis chat does: one compact chip per call showing the tool name, its duration and a spinner while it runs, with consecutive calls of a turn grouped into one wrapping row so the transcript stays scannable (ChatScreen AssistantParts / ToolCalls). Tapping a chip opens a floating panel over the transcript with INPUT as pretty-printed JSON and OUTPUT as monospace, plus copy actions. The panel is dismissible by tapping outside or its Close action and is positioned by ToolPanelPositionProvider so it never moves the conversation (the transcript scroll position is untouched while the overlay is open). A failed call is shown as failed and renders both its diff (when present) and an ERROR block. ERROR text now comes from the new toolErrorText, which prefers the server's error message over any partial output, while toolOutputText is the OUTPUT derivation again; toolFailed identifies the error state. While a turn streams, the transcript follows the newest content with a hard jump unless the operator has dragged away, driven by listState.interactionSource.interactions (DragInteraction.Start/Stop/Cancel) rather than programmatic scrolls. The running indicator and its live elapsed time derive from the turn's own start (ChatThread.elapsedMillis, an injectable clock in ChatStore) so they survive a chat switch. A reconnecting socket now settles every open chat and re-fetches its history (ChatStore.streamResumed, AppViewModel.observeConnection), and a server-pushed stream error with no session id settles the sole/active running turn with the server's message instead of leaving the indicator spinning. Tests: ChatFormatTest covers toolErrorText; new ChatStreamTest covers the streaming/elapsed/reconnect/stream-error guarantees against an injected clock; new ToolPanelPositionProviderTest covers the panel's below/flip/margin placement. README's chat section documents the follow-the-stream mechanism.
This commit is contained in:
@@ -2420,3 +2420,247 @@ Not verified: the live brokered server (separate lane), streaming against real
|
||||
OpenCode, and attachments — unchanged from the passes above. The markdown subset
|
||||
is intentionally smaller than full CommonMark (no HTML, no reference links, no
|
||||
nested lists, no strikethrough).
|
||||
|
||||
## Streaming replies (16 Oct 2026)
|
||||
|
||||
The live delta/streaming pass promised by the first slice. `android/` only; no new
|
||||
dependency (still just the declared `material-icons-extended`), no Pipelines
|
||||
server/Go/installer/Docker file touched, no run started from the app, and
|
||||
`emulator-5556` only (lane A's `emulator-5554` was never addressed).
|
||||
|
||||
- **Turn lifecycle in the model.** `ChatStore` now owns `ChatThread.runningSince`
|
||||
and one private `setRunning` transition, so a turn that begins is stamped with
|
||||
the wall clock and settling clears it; `ChatThread.elapsedMillis(now)` is the one
|
||||
pure derivation the indicator and its test share. `event` already appended
|
||||
`text`/`reasoning` deltas to the target part and upserted tool parts, wherever the
|
||||
frame's chat sits in the open order.
|
||||
- **Running indicator.** The transcript's indicator shows the spinner, `Working…`
|
||||
and the live elapsed time (ticked once a second, never per frame, through the
|
||||
shared `formatDuration`). Its tick loop is keyed on the turn's start and stops the
|
||||
moment the turn settles, and the elapsed value keeps counting across a chat
|
||||
switch because it lives on the thread, not the composable.
|
||||
- **Follow the stream.** The transcript hard-jumps to the newest item while a turn
|
||||
runs — a fast-growing reply outruns an animation — unless the operator has
|
||||
scrolled up to read; returning to the end resumes following. Consuming the list
|
||||
state's `interactionSource.interactions` (`DragInteraction.Start`/`Stop`/`Cancel`)
|
||||
distinguishes a user drag from the programmatic jump, so the jump never un-sticks
|
||||
the view.
|
||||
- **Reconnect resync.** `AppViewModel.observeConnection` re-fetches every open
|
||||
chat's history whenever the socket transitions to `Connected`, after
|
||||
`ChatStore.streamResumed()` settles each running thread (a still-live stream
|
||||
re-asserts `running` on its next frame, so no stale `Working…` sticks). The
|
||||
resync *replaces* the conversation wholesale, so a gap can neither duplicate nor
|
||||
drop text.
|
||||
- **Failure settle.** A server-pushed `error` frame carries no session id (the
|
||||
brokered protocol cannot attribute it), so `ChatStore.streamError` settles the
|
||||
sole running chat — or the active one when several are in flight — and keeps the
|
||||
server's text; with nothing running it is ignored. The prompt-call failure path
|
||||
already settled the turn and is unchanged.
|
||||
- **Non-blocking.** Unsolicited frames reach the UI through the client's bounded
|
||||
`SharedFlow` (`tryEmit` from the socket thread, `DROP_OLDEST` capacity 256), so a
|
||||
slow collector never blocks the read loop; each mutation touches only its chat and
|
||||
the `LazyColumn` keys limit recomposition to the changed item.
|
||||
|
||||
Evidence (macOS, JDK 17 target, Gradle 9.7.1,
|
||||
`ANDROID_HOME=/Users/alan/Library/Android/sdk`):
|
||||
|
||||
- `gradle :app:assembleDebug :app:testDebugUnitTest` → `BUILD SUCCESSFUL`; the JUnit
|
||||
XML totals **248 tests, 0 failures, 0 errors, 0 skipped** (new `ChatStreamTest`:
|
||||
a delta sequence grows the rendered text and toggles the running indicator, the
|
||||
elapsed time comes from the turn's own start and a repeated start keeps it,
|
||||
`streamResumed` settles every open chat and returns them for re-fetch,
|
||||
`streamError` settles the running turn with the server's text and is ignored with
|
||||
nothing running).
|
||||
- The debug APK was installed on `emulator-5556` only and driven with
|
||||
`uiautomator dump`/`input tap` against `.stream_check/stream_stub.py` (a stdlib
|
||||
`/connect` WebSocket double that streams `chat_event` frames; test scaffolding,
|
||||
not the app — the deployed server still predates chat). Captures were validated
|
||||
with `android/scripts/capture_png.sh -s emulator-5556`: a mid-stream reply with
|
||||
the growing transcript and the indicator at `Working… · 1s`
|
||||
(`chat_stream_01_early`) and `Working… · 4s` with the list followed to the newest
|
||||
line (`chat_stream_02_mid`); the settled turn with the completed `bash 340ms`
|
||||
tool chip, no indicator and the send control restored (`chat_stream_03_settled`);
|
||||
and, after a mid-stream drag up, the transcript **staying** where the operator
|
||||
left it while the turn still ran (`chat_stream_04_scrolled_up`). `adb -s
|
||||
emulator-5556 logcat -d` held 0 `FATAL EXCEPTION` and 0 `E AndroidRuntime`
|
||||
during the sweep.
|
||||
- **APK publish.** `app-debug.apk` (18,262,465 bytes, sha256
|
||||
`ef435b662e6f7e7467b5ae25b69fb24f8904334af204224aad00bfd76879a84e`) copied to
|
||||
`~/.local/share/pipelines/data/artifacts/126/1/pipelines-debug-wip-d7f6500.apk`;
|
||||
`curl -I http://10.0.0.249:8080/artifacts/126/1/pipelines-debug-wip-d7f6500.apk`
|
||||
returned `HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
|
||||
`Content-Length: 18262465`, and a streamed `GET | shasum -a 256` matched.
|
||||
|
||||
Not verified in this pass: the live brokered server (separate lane), streaming
|
||||
against real OpenCode, and attachments — unchanged. `:app:lintDebug` could not run
|
||||
in this environment: the Gradle JVM reports `25.0.4.1`, a version string the AGP
|
||||
8.7.2 lint (IntelliJ `JavaVersion`) rejects, so lint fails before analysing the
|
||||
tree; this is environmental and unrelated to the change.
|
||||
|
||||
## Tool-call chips and the expandable panel (16 Oct 2026)
|
||||
|
||||
The tool-call surface now matches the reference chat's `_ToolCalls`/`_ToolChip`
|
||||
and `_buildPanel` (research §1.3) more closely. `android/` only; no new
|
||||
dependency (still just the declared `material-icons-extended`), no Pipelines
|
||||
server/Go/installer/Docker file touched, no run started from the app, and
|
||||
`emulator-5556` only (lane A's `emulator-5554` was never addressed).
|
||||
|
||||
- **Grouped chips.** A run of consecutive `tool` parts in one assistant turn is
|
||||
now one `FlowRow` of compact chips (`ToolCalls`/`ToolChip`), so the turn's calls
|
||||
sit together and wrap instead of each taking a full-width row. Each chip keeps
|
||||
its kind icon, label (the edited file for an `edit`), `+N -M` diff stat,
|
||||
duration and running spinner.
|
||||
- **Overlay panel, scroll preserved.** Tapping a chip opens its INPUT/OUTPUT
|
||||
panel as a `Popup` anchored to that chip, not as inline content. The former
|
||||
inline panel re-flowed the transcript (a short chat visibly jumped); the popup
|
||||
is outside the list layout, so opening, failing or dismissing it never moves the
|
||||
conversation's scroll anchor. `ToolPanelPositionProvider` places it below the
|
||||
chip, flips it above when there is no room, and keeps it inside the window
|
||||
margins. The panel is dismissible by its own X or by tapping outside, and its
|
||||
INPUT and OUTPUT blocks carry the shared `CodeBlock` copy action.
|
||||
- **Visible failure.** An `error` tool call is now unmistakable: an
|
||||
error-tinted chip with an `ErrorOutline` icon (`toolFailed`), and its panel
|
||||
shows an ERROR block with the tool's error text (`ChatFormat.toolFailed`).
|
||||
- **Diff cards preserved.** An `edit`-family chip still expands to the synthesised
|
||||
green/red diff (`toolEditDiff`/`DiffView`), unchanged.
|
||||
|
||||
Evidence (macOS, Gradle 9.7.1 `--offline`, `ANDROID_HOME=/Users/alan/Library/Android/sdk`):
|
||||
|
||||
- `gradle :app:assembleDebug :app:testDebugUnitTest --offline` → `BUILD
|
||||
SUCCESSFUL`; the JUnit XML totals **252 tests, 0 failures, 0 errors, 0
|
||||
skipped** (new `toolFailedOnlyForTheErrorStatus`, and
|
||||
`ToolPanelPositionProviderTest`: below-the-chip, flip-above and margin-clamp
|
||||
placement).
|
||||
- The debug APK was installed on `emulator-5556` only and driven against
|
||||
`.tool_calls_check/chat_stub_tools.py` (a stdlib `/connect` WebSocket double
|
||||
serving the documented `internal/protocol/chat.go` JSON; test scaffolding, not
|
||||
the app). Captures were validated with `android/scripts/capture_png.sh -s
|
||||
emulator-5556`: `01_tools_collapsed.png` (the completed `bash 340ms` and
|
||||
`src/layout.kt +2 -2 300ms` chips grouped), `02_tools_expanded.png` (the bash
|
||||
chip expanded to INPUT pretty JSON + OUTPUT monospace with the transcript behind
|
||||
it unmoved — the chips keep the same on-screen position), and
|
||||
`03_error_chip_collapsed.png`/`04_error_chip_expanded.png` (the failed `shell`
|
||||
chip in the error container and its panel INPUT + ERROR text). Tapping outside
|
||||
the panel dismissed it with the chips still in place. `adb -s emulator-5556
|
||||
logcat -d` held 0 `FATAL EXCEPTION` and 0 `E AndroidRuntime` during the sweep.
|
||||
- **APK publish.** `app-debug.apk` (18,262,465 bytes, sha256
|
||||
`160f10ea8a2dc80364bb7f38596d50d08557ccce01f99705b93a8b9bc9216c27`) copied to
|
||||
`~/.local/share/pipelines/data/artifacts/129/1/pipelines-debug-wip-d7f6500.apk`;
|
||||
`curl -I http://10.0.0.249:8080/artifacts/129/1/pipelines-debug-wip-d7f6500.apk`
|
||||
returned `HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
|
||||
`Content-Length: 18262465`, and a streamed `GET | shasum -a 256` matched.
|
||||
|
||||
Not verified in this pass: the live brokered server (separate lane), streaming
|
||||
against real OpenCode, and attachments — unchanged from the passes above.
|
||||
|
||||
## Tool-call review fixes (16 Oct 2026)
|
||||
|
||||
Two findings from the tool-call slice review, both in `android/`, under the same
|
||||
constraints as above (no new dependency beyond the declared
|
||||
`material-icons-extended`, no Pipelines server/Go/installer/Docker file touched,
|
||||
no run started from the app, `emulator-5556` only).
|
||||
|
||||
- **One elapsed derivation.** `ChatScreen.rememberElapsedMillis` re-derived the
|
||||
running turn's elapsed time by subtracting the start itself, duplicating the
|
||||
tested `ChatThread.elapsedMillis` and contradicting the two KDocs that claimed
|
||||
the indicator shared the model's derivation. The composable now ticks a
|
||||
`rememberElapsedNow(runningSince)` wall clock (once a second, and only while
|
||||
the turn lives) and reads `thread.elapsedMillis(now)`, so the model and the UI
|
||||
cannot drift.
|
||||
- **No per-frame allocation.** `ToolCalls` keyed its open-panel `remember` on
|
||||
`parts.map { it.id }`, allocating a list on every streaming recomposition. The
|
||||
key is unnecessary — an id no longer among the calls simply matches nothing —
|
||||
so `openId` is plain remembered state and a streaming rebuild no longer
|
||||
allocates a key list.
|
||||
|
||||
Evidence (macOS, Gradle 9.7.1 `--offline`,
|
||||
`ANDROID_HOME=/Users/alan/Library/Android/sdk`):
|
||||
|
||||
- `gradle :app:assembleDebug :app:testDebugUnitTest --offline` → `BUILD
|
||||
SUCCESSFUL`; the JUnit XML totals **252 tests, 0 failures, 0 errors, 0
|
||||
skipped**.
|
||||
- The rebuilt debug APK was installed on `emulator-5556` only and driven against
|
||||
`.tool_calls_check/chat_stub_tools.py` and `chat_stub_error.py` (stdlib
|
||||
`/connect` WebSocket doubles serving the documented `internal/protocol/chat.go`
|
||||
JSON; test scaffolding, not the app). Captures were validated with
|
||||
`android/scripts/capture_png.sh -s emulator-5556` into `.tool_calls_fix/`:
|
||||
`01_tools_collapsed.png` (the completed `bash 340ms` and `src/layout.kt +2 -2
|
||||
300ms` chips grouped), `02_tools_expanded.png` (the bash chip's INPUT pretty
|
||||
JSON + OUTPUT monospace), `04_diff_card.png` (the edit chip's synthesised
|
||||
green/red diff card), `03_dismissed_outside.png` (tapping outside dismissed the
|
||||
panel with both chips at the same on-screen bounds), and
|
||||
`05_error_chip_collapsed.png`/`06_error_chip_expanded.png` (the failed `shell`
|
||||
chip in the error container, with a `Failed tool call` description, and its
|
||||
panel INPUT + ERROR text). `adb -s emulator-5556 logcat -d` held 0 `FATAL
|
||||
EXCEPTION` and 0 `E AndroidRuntime` during the sweep.
|
||||
- **APK publish.** `app-debug.apk` (18,219,766 bytes, sha256
|
||||
`b607a879ce2f2ac324fe6fa254918a456337c678abc1781bb79a05d88d539984`) copied to
|
||||
`~/.local/share/pipelines/data/artifacts/129/3/pipelines-debug-wip-d7f6500.apk`;
|
||||
`curl -I http://10.0.0.75:8080/artifacts/129/3/pipelines-debug-wip-d7f6500.apk`
|
||||
returned `HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
|
||||
`Content-Length: 18219766`, and a streamed `GET | shasum -a 256` matched. This
|
||||
supersedes the `129/1` publish above: it is built from the current source, so
|
||||
the change is in the served artifact (a fresh rebuild can still differ in
|
||||
`classes5.dex` — the reproducibility caveat recorded in review stands).
|
||||
|
||||
Not verified in this pass: the live brokered server (separate lane), streaming
|
||||
against real OpenCode, and attachments — unchanged from the passes above.
|
||||
`:app:lintDebug` still cannot run here (the Gradle JVM's `25.0.4.1` version
|
||||
string is rejected by AGP 8.7.2 lint), unchanged from the slice above.
|
||||
|
||||
## Tool-call review fixes, second pass (16 Oct 2026)
|
||||
|
||||
Three findings from the tool-call slice's second review, all in `android/` under
|
||||
the same constraints (no new dependency beyond the declared
|
||||
`material-icons-extended`, no Pipelines server/Go/installer/Docker file touched, no
|
||||
run started from the app, `emulator-5556` only).
|
||||
|
||||
- **A failed edit call shows its error.** The panel only rendered the diff for an
|
||||
`edit`-family call, because the `diff != null` branch sat above the `failed`
|
||||
check, so a *failed* edit showed no error text. The ERROR block is now emitted
|
||||
whenever `toolFailed`, alongside the diff when one exists; a failed non-edit call
|
||||
keeps INPUT + ERROR, and a successful edit still shows the diff alone.
|
||||
- **The error message, not the partial output.** `ChatFormat.toolOutputText`
|
||||
returned non-blank `state.content` before it considered `state.error`, and that
|
||||
text fed the ERROR block, so a failed call carrying both showed its partial
|
||||
output under the ERROR heading. The failed call's text now comes from the new
|
||||
`toolErrorText`, which prefers the server's message and falls back to the output
|
||||
text only when the failure carries none; `toolOutputText` is the OUTPUT
|
||||
derivation again.
|
||||
- **README mechanism corrected.** The follow-the-stream bullet claimed a
|
||||
`snapshotFlow` on the list's scroll state; the code consumes
|
||||
`listState.interactionSource.interactions` (`DragInteraction.Start`/`Stop`/`Cancel`),
|
||||
as the bullet now says.
|
||||
|
||||
Evidence (macOS, Gradle 9.7.1, `ANDROID_HOME=/Users/alan/Library/Android/sdk`):
|
||||
|
||||
- `gradle :app:testDebugUnitTest :app:assembleDebug` → `BUILD SUCCESSFUL`; the
|
||||
JUnit XML totals **253 tests, 0 failures, 0 errors, 0 skipped** (the failed-text
|
||||
helper split into `toolOutputFallsBackToNoOutput` and
|
||||
`toolErrorPrefersTheMessageOverPartialOutput`, which asserts the message wins over
|
||||
a failed call's partial output).
|
||||
- The rebuilt debug APK was installed on `emulator-5556` only and driven against
|
||||
`.tool_calls_fix2/chat_stub_failed_edit.py` (the review tool stub plus a failed
|
||||
`edit` call with `oldString`/`newString` and a failed `bash` call carrying both
|
||||
partial output and an error; stdlib `/connect` WebSocket double, test
|
||||
scaffolding, not the app). Captures were validated with
|
||||
`android/scripts/capture_png.sh -s emulator-5556` into `.tool_calls_fix2/`:
|
||||
`04_failed_edit_expanded.png` shows the failed edit chip's diff *and* its ERROR
|
||||
block (`oldString not found in src/layout.kt`), and
|
||||
`06_failed_bash_expanded.png` shows the failed bash call's INPUT + ERROR
|
||||
(`exit status 2: src/nope.kt: No such file`), the error text — not the partial
|
||||
output — under the ERROR heading. `uiautomator dump` confirms the same nodes;
|
||||
`adb -s emulator-5556 logcat -d` held 0 `FATAL EXCEPTION` and 0 `E
|
||||
AndroidRuntime` during the sweep.
|
||||
- **APK publish.** `app-debug.apk` (18,219,360 bytes, sha256
|
||||
`4522aa62c8a3a59033aa2cca8b7fba65267dbdde473284585eaae47f03aeda2f`) copied to
|
||||
`~/.local/share/pipelines/data/artifacts/129/5/pipelines-debug-wip-d7f6500.apk`;
|
||||
`curl -I http://10.0.0.249:8080/artifacts/129/5/pipelines-debug-wip-d7f6500.apk`
|
||||
returned `HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
|
||||
`Content-Length: 18219360`, and a streamed `GET | shasum -a 256` matched. This
|
||||
supersedes the `129/3` publish above: it is rebuilt from the current source, so
|
||||
the fix is in the served artifact (the `classes5.dex` reproducibility caveat
|
||||
recorded in review stands).
|
||||
|
||||
Not verified in this pass: the live brokered server (separate lane), streaming
|
||||
against real OpenCode, and attachments — unchanged from the passes above.
|
||||
|
||||
Reference in New Issue
Block a user