Merge main into chat-close: combine the shared chat room with the server-side close
The item adds chat_close/chat_reopen to the brokered chat protocol and the operator-session registry's closed state. main replaced the per-session claim model with shared chat rooms (chat_subscribe, a prompt queue, one broker stream fanned out to every watcher). This merges the two. Resolved conflicts: - internal/protocol/chat.go, internal/protocol/message.go: kept both additions - ChatClose/ChatReopen and main's ChatSubscribe/ChatQueued. - internal/server/chat_sessions.go: kept the closed fields on a listed session; dropped the `Busy` assignment, because main no longer marks a session Busy (any number of clients may watch and write one). - internal/server/chat_claims.go: main deleted the claim model, so the file goes; close's "is a turn running" check is now `chatHub.turnInFlight` in internal/server/chat_room.go, reading the room's `running` flag. That is the same question the old claim answered, against main's model. - internal/server/chat_close.go: calls turnInFlight instead of the removed `active`. - android AppViewModel.kt, ChatFormat.kt, ChatListPane.kt, Message.kt: kept both sides - main's search state, queued-prompt handling, `Busy`-free status label and row/menu shape, plus the item's close/reopen actions, closed chip and section, close confirmation and "Hide on this device" rename. Also in this merge: main's new convention (AGENTS.md) that an item does not edit a shared document; the item's stale-document record for this change lives in docs/notes/chat-close.md, and docs/cli.md, android/README.md and internal/author/skill/references/operations.md are left to the docs-fold writer. Checks after resolving: gofmt clean, go build ./... and go vet ./... clean, the Go module passes, and the app's :app:assembleDebug and :app:testDebugUnitTest pass (--offline --no-daemon).
This commit is contained in:
+50
-15
@@ -33,9 +33,17 @@ const (
|
||||
// operator-session registry. ChatReopen clears the closed state again, so a
|
||||
// finished chat can be resumed. Both take a ChatQuery (the session id) and
|
||||
// echo the updated session like chat_create/chat_adopt. Neither ever touches
|
||||
// the pipeline-owned run sessions.
|
||||
// the pipeline-owned run sessions, and a closed session stays watchable: close
|
||||
// only records the finished state, it never detaches a client.
|
||||
ChatClose = "chat_close"
|
||||
ChatReopen = "chat_reopen"
|
||||
// ChatSubscribe attaches a connection to one session's shared live stream so
|
||||
// it receives every frame any client's turn produces (its own and the other
|
||||
// devices'), not only the frames of a turn it prompted itself. Any number of
|
||||
// clients may watch one session; the session is never read-only. The request
|
||||
// body is a ChatQuery naming the session and the response echoes the request
|
||||
// id once the subscription is attached.
|
||||
ChatSubscribe = "chat_subscribe"
|
||||
// ChatDirectories is the request/response type for the operator's directory
|
||||
// choices: the home directory plus the directories of previous operator
|
||||
// sessions, most recently used first, deduplicated and bounded. It is a
|
||||
@@ -59,13 +67,16 @@ const (
|
||||
)
|
||||
|
||||
// ChatEvent.Kind values pushed on the chat_event stream. Step and usage carry
|
||||
// no ChatPart; they report turn progress and the turn's totals.
|
||||
// no ChatPart; they report turn progress and the turn's totals. User carries the
|
||||
// text of a prompt another client sent, so a transcript can show it live; it is
|
||||
// never sent back to the client that sent the prompt.
|
||||
const (
|
||||
ChatEventText = ChatPartText
|
||||
ChatEventReasoning = ChatPartReasoning
|
||||
ChatEventTool = ChatPartTool
|
||||
ChatEventStep = "step"
|
||||
ChatEventUsage = "usage"
|
||||
ChatEventUser = "user"
|
||||
)
|
||||
|
||||
// ChatStep.Status values, mirroring the OpenCode session.step events.
|
||||
@@ -121,10 +132,11 @@ type ChatSession struct {
|
||||
Tag string `json:"tag,omitempty"`
|
||||
CreatedAt int64 `json:"created_at,omitempty"`
|
||||
UpdatedAt int64 `json:"updated_at,omitempty"`
|
||||
// Busy marks a session another client currently holds (or one the server
|
||||
// itself owns as an active run), so the phone can show it read-only instead
|
||||
// of letting two clients silently write the same conversation. It is
|
||||
// additive and optional: older peers ignore it.
|
||||
// Busy is retained for wire compatibility only: it is never set by this
|
||||
// server. A session is never read-only, any number of clients may watch and
|
||||
// write it, and only a turn is serialised (a waiting prompt is acknowledged
|
||||
// as queued on its own client instead of marking the session Busy). Older
|
||||
// peers still parse the field; newer ones ignore it.
|
||||
Busy bool `json:"busy,omitempty"`
|
||||
// Closed records that the operator finished with this session: the server
|
||||
// keeps the session, its transcript and its history, but the closed state is
|
||||
@@ -171,26 +183,34 @@ type ChatQuery struct {
|
||||
|
||||
// ChatPromptRequest is the chat_prompt request body: the text to send, with an
|
||||
// optional model/agent override and attached file URIs. The matching response is
|
||||
// the inbox envelope, which the server folds into a ChatMessage.
|
||||
// the inbox envelope, which the server folds into a ChatMessage. Client is the
|
||||
// sending device's human-readable label so every other client can attribute the
|
||||
// message; the server sanitises it and falls back to a generic label when it is
|
||||
// blank.
|
||||
type ChatPromptRequest struct {
|
||||
SessionID string `json:"session_id"`
|
||||
Text string `json:"text"`
|
||||
Model string `json:"model,omitempty"`
|
||||
Agent string `json:"agent,omitempty"`
|
||||
Files []string `json:"files,omitempty"`
|
||||
Client string `json:"client,omitempty"`
|
||||
}
|
||||
|
||||
// ChatMessage is one stored turn returned by chat_messages. A user turn is a
|
||||
// single text part; an assistant turn holds the text, reasoning and tool parts
|
||||
// the phone renders. Parts corresponds to the OpenCode content array.
|
||||
type ChatMessage struct {
|
||||
ID string `json:"id"`
|
||||
SessionID string `json:"session_id"`
|
||||
Role string `json:"role"`
|
||||
Model string `json:"model,omitempty"`
|
||||
Agent string `json:"agent,omitempty"`
|
||||
CreatedAt int64 `json:"created_at,omitempty"`
|
||||
Parts []ChatPart `json:"parts"`
|
||||
ID string `json:"id"`
|
||||
SessionID string `json:"session_id"`
|
||||
Role string `json:"role"`
|
||||
Model string `json:"model,omitempty"`
|
||||
Agent string `json:"agent,omitempty"`
|
||||
CreatedAt int64 `json:"created_at,omitempty"`
|
||||
// Client is the sending device's label on a user turn the server echoed, so a
|
||||
// resumed transcript still says who sent the message. It is empty on an
|
||||
// assistant turn.
|
||||
Client string `json:"client,omitempty"`
|
||||
Parts []ChatPart `json:"parts"`
|
||||
}
|
||||
|
||||
// ChatPart is one element of a ChatMessage. Type selects the meaning: text and
|
||||
@@ -252,6 +272,9 @@ type ChatEventFrame struct {
|
||||
Part *ChatPart `json:"part,omitempty"`
|
||||
Step *ChatStep `json:"step,omitempty"`
|
||||
Usage *ChatUsage `json:"usage,omitempty"`
|
||||
// Client is the sending device's label on a user frame (ChatEventUser), so a
|
||||
// transcript can say who sent the message. It is empty on assistant frames.
|
||||
Client string `json:"client,omitempty"`
|
||||
}
|
||||
|
||||
// ChatStep is a progress marker for the current step of a turn.
|
||||
@@ -285,6 +308,15 @@ type ChatPermissionFrame struct {
|
||||
Metadata map[string]any `json:"metadata,omitempty"`
|
||||
Source *ChatPermissionSource `json:"source,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
// Resolved, Decision and ResolvedBy report the shared, exactly-once outcome
|
||||
// of a request any client may answer: once the first answer is recorded the
|
||||
// server pushes the same frame back to every watching client with Resolved
|
||||
// set, the Decision it recorded and the label of the client that gave it, so
|
||||
// their cards clear and show the outcome instead of offering a stale choice.
|
||||
// They are empty on a still-pending request.
|
||||
Resolved bool `json:"resolved,omitempty"`
|
||||
Decision string `json:"decision,omitempty"`
|
||||
ResolvedBy string `json:"resolved_by,omitempty"`
|
||||
}
|
||||
|
||||
// ChatPermissionSource identifies what raised a permission request, matching the
|
||||
@@ -298,10 +330,13 @@ type ChatPermissionSource struct {
|
||||
|
||||
// ChatReplyRequest is the chat_reply request body: the phone's decision on a
|
||||
// pending permission request, mirroring
|
||||
// POST /api/session/{id}/permission/{requestID}/reply.
|
||||
// POST /api/session/{id}/permission/{requestID}/reply. Client is the answering
|
||||
// device's label, recorded with the resolution so every other client can see
|
||||
// which device answered.
|
||||
type ChatReplyRequest struct {
|
||||
SessionID string `json:"session_id"`
|
||||
RequestID string `json:"request_id"`
|
||||
Decision string `json:"decision"`
|
||||
Message string `json:"message,omitempty"`
|
||||
Client string `json:"client,omitempty"`
|
||||
}
|
||||
|
||||
@@ -27,7 +27,13 @@ func chatSamples() []struct {
|
||||
{"create", ChatCreateRequest{Title: "demo", Directory: "/work"}},
|
||||
{"adopt", ChatAdoptRequest{SessionID: "ses_1"}},
|
||||
{"query", ChatQuery{SessionID: "ses_1", Limit: 50}},
|
||||
{"prompt", ChatPromptRequest{SessionID: "ses_1", Text: "hello", Model: "m", Agent: "build", Files: []string{"file:///tmp/a.png"}}},
|
||||
{"prompt", ChatPromptRequest{SessionID: "ses_1", Text: "hello", Model: "m", Agent: "build", Files: []string{"file:///tmp/a.png"}, Client: "Pixel 9 Pro XL"}},
|
||||
{"prompt_queued_ack", Message{Type: ChatPrompt, ID: "a1", ChatQueued: true}},
|
||||
{"subscribe", ChatQuery{SessionID: "ses_1"}},
|
||||
{"event_user", ChatEventFrame{
|
||||
SessionID: "ses_1", MessageID: "usr_1", Kind: ChatEventUser, Client: "Pixel 10 Pro Fold",
|
||||
Part: &ChatPart{Type: ChatPartText, ID: "usr", Text: "from the fold"},
|
||||
}},
|
||||
{"message", ChatMessage{
|
||||
ID: "msg_1", SessionID: "ses_1", Role: ChatRoleAssistant, Model: "m", Agent: "build", CreatedAt: 1792112366711,
|
||||
Parts: []ChatPart{
|
||||
@@ -66,7 +72,11 @@ func chatSamples() []struct {
|
||||
Source: &ChatPermissionSource{Type: "tool", MessageID: "msg_1", ID: "call_1"},
|
||||
Message: "wants to run a command",
|
||||
}},
|
||||
{"reply", ChatReplyRequest{SessionID: "ses_1", RequestID: "req_1", Decision: ChatDecisionOnce, Message: "ok"}},
|
||||
{"permission_resolved", ChatPermissionFrame{
|
||||
SessionID: "ses_1", RequestID: "per_1", Action: "bash",
|
||||
Resolved: true, Decision: ChatDecisionOnce, ResolvedBy: "Pixel 9 Pro XL",
|
||||
}},
|
||||
{"reply", ChatReplyRequest{SessionID: "ses_1", RequestID: "req_1", Decision: ChatDecisionOnce, Message: "ok", Client: "Pixel 9 Pro XL"}},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -170,6 +170,12 @@ type Message struct {
|
||||
// requests themselves ride on ChatQuery (the session id), matching
|
||||
// chat_messages/chat_interrupt.
|
||||
ChatClose *ChatCloseResult `json:"chat_close,omitempty"`
|
||||
// ChatSubscribe attaches this connection to one session's shared stream; the
|
||||
// body names the session like ChatQuery. A chat_prompt response sets
|
||||
// ChatQueued when the prompt had to wait for an in-flight turn and was
|
||||
// accepted into the session's queue instead of being sent immediately.
|
||||
ChatSubscribe *ChatQuery `json:"chat_subscribe,omitempty"`
|
||||
ChatQueued bool `json:"chat_queued,omitempty"`
|
||||
// ChatDirectories carries the operator's directory choices on a
|
||||
// chat_directories response (home first, then recent operator-session
|
||||
// directories, deduplicated and bounded). Additive/omitempty so older peers
|
||||
|
||||
Reference in New Issue
Block a user