a57decbf4eec35e4e1ba2eac0a2f3c725de447ae
5 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
e9d902213e |
Preserve background shell visibility across readback races
Reconcile authoritative shell snapshots with bounded lifecycle journals so concurrent exits and creates cannot be overwritten, coalesce observation setup, and retain verified ownership across reconnects. Add deterministic reconciliation and cancellation regressions plus stable limited-visibility handling.\n\nChecked packaged templates and authoring skill references: none need updating. The task-owned docs note records the stale shared chat documentation for docs-fold; shared documentation was not edited. |
||
|
|
7d9490bba1 |
chat: name the in-flight state, and surface background processes
Two gaps in the chat's in-flight feedback. The turn indicator no longer reads a bare `Working…` for every state. A new pure derivation (TurnPhase/turnPhase/turnPhaseLabel in ui/chat/ChatFormat.kt) labels the headline from evidence already on the wire: `Thinking…` while text or reasoning deltas are still arriving (within TURN_THINKING_WINDOW_MILLIS), `Running a tool…` while calls are in flight, `Waiting…` otherwise. No percentage, ETA or invented progress. The agent's shell commands are now surfaced end to end as their own frame kind, so a background process (a dev server, a watching build) that outlives its tool call is visible and clears when it exits. Server: - protocol/chat.go adds ChatEventShell, ChatShell (id, status, command, *int exit — a pointer so exit 0 is not "absent") and ChatEventFrame.shell. - opencode/chat.go maps shell.created/shell.exited through a new exported ChatStreamState, attributing created via info.metadata.sessionID and exit via the ids the stream already surfaced; another session's or an unattributed shell is ignored, an id-less shell fails the stream. No cwd/file/credential is carried. - server/chat_hub.go retains still-running shells (chatShellLimit plus the shared byte cap) and drops them on exit; chat_stream.go replays them on chat_subscribe, the shell half of the resume (a shell is not a turn, so the message snapshot cannot carry it). App: - data/protocol/Chat.kt adds ChatShell, ChatEventFrame.shell, EVENT_SHELL, SHELL_RUNNING/SHELL_EXITED. - ui/chat/ChatStore.kt stamps ChatThread.lastDeltaAt on each delta (cleared when the turn settles) and keeps ChatThread.shells across a chat switch; a shell never marks the thread running. streamResumed drops shells so the subscribe replay re-syncs the still-running ones. - ui/chat/ChatTranscript.kt: RunningIndicator prints the phase label; a new always-visible BackgroundProcessBar names each running shell. - ui/chat/ChatConversationPane.kt shows the bar whenever a shell is running, whether or not a turn is. Tests extend the server's event mapping (opencode/chat_v2_test.go, server/chat_test.go) and the app's pure folds (new ui/chat/ChatInFlightStateTest.kt, 15 tests), pinning the shell mapping, the other-session rejection and the "background process outlives the turn" state. Checked and intentionally unchanged: - No packaged OpenCode skill reference documents either surface. internal/author/skill/references/operations.md describes the brokered chat_* protocol in prose without naming frame kinds or the app indicator, so it stays correct as-is; no reference was added, so install.go's managed inventory needs no change. - This repository has no packaged templates directory. - Shared docs are not edited here per the map: docs/notes/chat-shell-background -process.md records what is now stale in docs/cli.md and android/README.md for the docs-fold writer. Verification (this session): gofmt -l clean, go build ./... and go vet ./... OK. Android unit suite and the on-device capture were run in the preceding review stage; see the note for the live-verification limitation. |
||
|
|
798e958cb7 |
chat: fold an agent turn into one reply, split reasoning from answer, keep tool name/input
The phone's chat transcript rendered one agent reply as ~36 bubbles, each with its own thinking block, and a finished tool call lost its name and its input. - Turn fold (android): ChatFormat.kt gains the pure ChatTurn / TranscriptRow / transcriptRows fold - each run of consecutive assistant messages between two of the operator's messages is one agent turn - and ChatTranscript renders one bubble per turn: the turn's single collapsible thinking block (all its reasoning, in order, growing live while it streams), then its tool-call chips, then one answer block of just the turn's text parts. AssistantParts/MessagePart are replaced by AgentTurnItem/UserMessageItem; ChatConversationPane counts the folded rows. - Delta part ids (server + client): internal/protocol/chat.go adds ChatDeltaPartID(messageID, kind, ordinal), mirrored as ChatProtocol.deltaPartId in data/protocol/Chat.kt, and NormalizeChatEvent keys a text or reasoning delta on it. OpenCode numbers a message's text and reasoning parts independently from 0, so the old "%s#%d" gave the first text delta and first reasoning part the same id: the answer was appended into the thinking block, and the server's retained state (chat_hub.go) re-collided on resume. ChatStore's upsert now routes a delta through the kind-aware deltaPartId fold, so it stays robust even against a peer that still shares one id. - Tool fields (server + client): NormalizeChatEvent takes a call's arguments from session.tool.input.ended's text as well as session.tool.called's input object (toolInput), and chat_hub.go's new mergeChatToolPart folds each tool frame onto the retained part so the progress/success frames that omit name and input never blank them. ChatFormat.kt's mergeToolPart mirrors that on the client, so the chip and panel header keep the real tool name and the panel shows INPUT beside OUTPUT. Tests: chat_v2_test.go and chat_test.go add the text/reasoning id-collision and the tool name+input retention cases; ChatReasoningTurnTest, ChatTranscriptTest and ChatRunningWorkTest cover the turn fold, the collision and the tool lifecycle. Checks: Go build, vet, gofmt and the package tests pass (go build ./... && go vet ./...; gofmt -l . empty; go test ./internal/server ./internal/opencode ./internal/protocol ./internal/stage ./internal/pipeline; go test ./...). Android passes offline with --no-daemon (assembleDebug and the full testDebugUnitTest suite, 660 tests). The on-phone observation was not performed: the device lock was held by another run and adb was not available here. Documentation inventory checked: no packaged OpenCode skill reference in internal/author/skill/references/ and no packaged template documents the app's chat transcript, this delta part-id derivation or the tool-field retention, and no internal/author/ managed file inventory entry names any touched file, so none of them needs updating. The shared android/README.md behaviour statements are made stale by this change and are recorded instead in docs/notes/chat-transcript-turn-fold.md for the docs-fold writer, per the repo rule that an item never edits a shared document itself. |
||
|
|
6cb61578de |
Fan a chat session out to every client and share approvals exactly-once
A session was owned by one connection: the claim map in chat_claims.go let the
first client hold it, every other client saw the session Busy and read-only, and
a second client's prompt was rejected. Replace the claim with a per-session
"room" so the operator's phone, tablet and terminal all watch and write the same
conversation, and a pending approval is a shared, exactly-once object.
Server (internal/server, internal/protocol):
- New chat_room.go: one room per session holding the session's single broker
stream, its one bounded prompt queue (8) and the fan-out to every attached
client. A chat_subscribe frame attaches a connection to a session's shared
stream and replays the still-unresolved approval requests the room holds.
- chat_stream.go: handleChatPrompt accepts a prompt from any client. It attaches
the sender, either starts a turn or queues the prompt behind the in-flight turn
and acknowledges it with chat_queued:true ("queued" is the chosen behaviour,
stated on the wire and in docs/cli.md), and echoes the user turn to every other
client attributed to the sender's label. The prompt handler no longer owns the
stream; one turn runner per room drains the queue, so two turns never
interleave. Per-connection write serialisation is unchanged (each chatSub has
its own writer goroutine and bounded buffer).
- chat_permissions.go / chat_commands.go: an approval is reserved by the first
answer and confirmed once delivered; the first answer wins, is recorded with
the answering client's label, and the resolution is pushed to every watching
client as chat_permission with resolved/decision/resolved_by so their cards
clear. A later answer is refused with an error naming the client that answered,
and never reaches the agent twice; a reservation whose reply failed is
released.
- chat_hub.go / chat_sessions.go / chat.go: the hub now owns rooms and the
user-turn id sequence; the resulting user turns are retained (role and client
carried) so a reconnect re-syncs who said what. chat_sessions no longer marks a
session Busy and its clientID parameter is gone; the protocol keeps the Busy
field for wire compatibility only. websocket.go detaches a connection's chat
subscriptions when the read loop ends.
- chat_claims.go is removed, not left vestigial: the only exclusive thing left is
a turn, and the room's queue is that.
App (android):
- PipelinesRepository carries a stable per-device client label (Build.MODEL, with
a fallback) on prompts and replies, and adds chatSubscribe; AppViewModel
subscribes on opening a chat (best-effort, an older server's error frame does
not stop history loading) and records the queued ack.
- ChatStore folds a user frame from another client into the transcript once,
attributed by the sender's label, and never receives its own prompt back, so
the sender's own message is never duplicated. ChatThread.readOnly is gone:
canSend no longer depends on another client, the composer says "Queued - it
will send when the current turn finishes." instead of disabling input, and the
status label is Running/Idle only. Scroll/follow behaviour is untouched.
- Tests: ChatProtocolTest round-trips the new wire fields, ChatFormatTest asserts
the stale Busy flag cannot produce a read-only label, MultiChatStateTest asserts
a session another client watches stays writable.
Reflected where it belongs: no packaged template changes (no bundled starter
embeds the chat protocol). Checked the packaged authoring skill references: none
of them describes the chat wire beyond operations.md, and
internal/author/skill/references/operations.md is now stale - its "Brokered
OpenCode chat" section still says chat_sessions marks "busy" when another client
holds the session and that a second client's chat_prompt is rejected, and it does
not mention chat_subscribe, the per-session prompt queue/chat_queued, the
per-client label or the shared exactly-once approval (it also still describes the
per-subscription permission poller, which the room's single poller replaced). The
supported semantics are the ones in docs/cli.md, updated in this commit; the
operations.md section needs a rewrite to match. No README or other shared
document was edited here.
Checks run on the committed tree: gofmt -l internal cmd examples (nothing), go
build ./..., go vet ./internal/... ./cmd/..., go test ./internal/server
./internal/protocol ./internal/stage ./internal/pipeline.
|
||
|
|
c1652e2bc6 |
Split chat/model/run files by concern (pure move)
Pure move: split the three multi-feature server files into per-concern files, with no behaviour change - same package, same exported and unexported identifiers, same call graph, same tests. - internal/server/chat.go -> chat.go (broker seam, client token, dispatcher), chat_hub.go, chat_claims.go, chat_permissions.go, chat_sessions.go, chat_stream.go, chat_commands.go - internal/stage/model.go -> model.go, model_run.go, model_failure.go, model_validation.go - internal/pipeline/runs.go -> runs.go (read side), runs_schema.go, runs_create.go, runs_mutate.go, runs_sessions.go Checked before committing: - Packaged templates and internal/author/skill/references: neither refers to internal/server/chat.go, internal/stage/model.go or internal/pipeline/runs.go, so nothing there needed updating (the change is a move with no behaviour change). - gofmt -l on the three packages: clean. go build ./..., go vet ./... and go test ./... pass. go.mod/go.sum unchanged. - No test, docs, android/, install or Docker files touched. Known stale path pointers deliberately left to the single docs writer (shared docs) and out of scope (android/): docs/chat-verification.md and android/README.md name the old file paths. |