Show loudly in the chat list when a chat is waiting on the operator
The server's chat activity now counts each session's unanswered approvals and questions (awaiting_operator) and pushes it to every connection when it changes. A waiting chat's list row pulses in the error colour with a solid bar on its leading edge, its avatar wears a ringing bell in place of the spinner, and its state line leads with a bold "Waiting for you". Reduced motion holds the pulse and the bell still. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,9 +6,10 @@ import (
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
// Chat list activity: every listed chat shows whether its turn is running and
|
||||
// Chat list activity: every listed chat shows whether its turn is running,
|
||||
// whether background tasks (shells, background commands, subagents) are still
|
||||
// running after the turn. Room frames reach only the connections that opened
|
||||
// running after the turn, and whether the agent is waiting on the operator (an
|
||||
// unanswered approval or question). Room frames reach only the connections that opened
|
||||
// that chat, so the hub keeps a small per-session summary and pushes each
|
||||
// change to every connection as chat_activity, and chat_sessions carries the
|
||||
// current summary on each row.
|
||||
@@ -33,6 +34,7 @@ func (h *chatHub) chatActivityLocked(sessionID string) protocol.ChatActivity {
|
||||
}
|
||||
activity.TurnRunning = room.running || room.observedTurn
|
||||
activity.BackgroundTasks = h.backgroundTasksLocked(sessionID)
|
||||
activity.AwaitingOperator = len(room.pending) + len(room.forms)
|
||||
return activity
|
||||
}
|
||||
|
||||
@@ -56,7 +58,9 @@ func (h *chatHub) noteActivityLocked(sessionID string) {
|
||||
h.rememberLiveLocked(sessionID)
|
||||
next := h.chatActivityLocked(sessionID)
|
||||
previous := h.activity[sessionID]
|
||||
if previous.TurnRunning == next.TurnRunning && previous.BackgroundTasks == next.BackgroundTasks {
|
||||
if previous.TurnRunning == next.TurnRunning &&
|
||||
previous.BackgroundTasks == next.BackgroundTasks &&
|
||||
previous.AwaitingOperator == next.AwaitingOperator {
|
||||
return
|
||||
}
|
||||
if h.activity == nil {
|
||||
|
||||
@@ -185,3 +185,43 @@ func TestChatBackgroundTasksKeepUnattendedRoom(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// An unanswered approval or question is the operator's to act on: the list
|
||||
// activity counts it, and answering it clears the count.
|
||||
func TestChatActivityCountsWhatAwaitsTheOperator(t *testing.T) {
|
||||
h := newChatHub()
|
||||
defer func() {
|
||||
h.mu.Lock()
|
||||
for _, room := range h.rooms {
|
||||
room.cancel()
|
||||
}
|
||||
h.mu.Unlock()
|
||||
}()
|
||||
const id = "ses_wait"
|
||||
awaiting := func() int {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
return h.activity[id].AwaitingOperator
|
||||
}
|
||||
h.mu.Lock()
|
||||
h.roomLocked(id)
|
||||
h.mu.Unlock()
|
||||
|
||||
h.pushPermission(id, protocol.ChatPermissionFrame{SessionID: id, RequestID: "perm_1"})
|
||||
if got := awaiting(); got != 1 {
|
||||
t.Fatalf("a pending approval: awaiting=%d", got)
|
||||
}
|
||||
h.mu.Lock()
|
||||
h.applyLocked(protocol.ChatEventFrame{SessionID: id, Kind: protocol.ChatEventForm, Form: &protocol.ChatForm{ID: "q_1"}})
|
||||
h.mu.Unlock()
|
||||
if got := awaiting(); got != 2 {
|
||||
t.Fatalf("an approval and a question: awaiting=%d", got)
|
||||
}
|
||||
h.confirmPermission(id, "perm_1", "c", "allow")
|
||||
h.mu.Lock()
|
||||
h.applyLocked(protocol.ChatEventFrame{SessionID: id, Kind: protocol.ChatEventForm, Form: &protocol.ChatForm{ID: "q_1", Resolved: true}})
|
||||
h.mu.Unlock()
|
||||
if got := awaiting(); got != 0 {
|
||||
t.Fatalf("both answered: awaiting=%d", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,6 +245,7 @@ func (h *chatHub) applyLocked(frame protocol.ChatEventFrame) {
|
||||
room.forms = append(room.forms, *frame.Form)
|
||||
}
|
||||
h.rememberLiveLocked(frame.SessionID)
|
||||
h.noteActivityLocked(frame.SessionID)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ func (h *chatHub) confirmPermission(sessionID, requestID, client, decision strin
|
||||
break
|
||||
}
|
||||
}
|
||||
h.noteActivityLocked(sessionID)
|
||||
for _, sub := range room.subs {
|
||||
targets = append(targets, sub)
|
||||
}
|
||||
|
||||
@@ -718,6 +718,7 @@ func (h *chatHub) pushPermission(sessionID string, frame protocol.ChatPermission
|
||||
if len(room.pending) > chatRoomPendingLimit {
|
||||
room.pending = room.pending[len(room.pending)-chatRoomPendingLimit:]
|
||||
}
|
||||
h.noteActivityLocked(sessionID)
|
||||
for _, sub := range room.subs {
|
||||
targets = append(targets, sub)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user