Show injected Claude input as agent reports and notices, not operator bubbles

Claude Code records subagent/peer reports, task notifications, reminders and
skill bodies as user-role entries. Classify them server-side (history and live
stream) by origin/isMeta/queued_command mode: reports become kind agent_report,
task notifications kind notice, harness meta is hidden, and the mid-turn
wrapper is unwrapped to the operator's text. The app draws a collapsed Agent
report card and a one-line system notice on the agent's side.
This commit is contained in:
2026-11-02 16:44:07 +00:00
parent d78cbe3f66
commit 07d4740d0c
15 changed files with 1208 additions and 16 deletions
+10 -3
View File
@@ -79,8 +79,11 @@ type chatMessage struct {
role string
client string
operationID string
order []string
parts map[string]*chatPart
// kind is the ChatMessage.Kind of harness-injected content (an agent
// report or a notice); empty for an ordinary turn.
kind string
order []string
parts map[string]*chatPart
}
type chatTurn struct {
@@ -232,6 +235,9 @@ func (h *chatHub) applyLocked(frame protocol.ChatEventFrame) {
if message.operationID == "" && frame.Kind == protocol.ChatEventUser {
message.operationID = frame.OperationID
}
if message.kind == "" && frame.MessageKind != "" && frame.Kind != protocol.ChatEventUser {
message.kind = frame.MessageKind
}
switch frame.Kind {
case protocol.ChatEventUser:
if frame.Part == nil || frame.Part.ID == "" || frame.Part.Text == "" || turn.overflow {
@@ -260,7 +266,7 @@ func (h *chatHub) applyLocked(frame protocol.ChatEventFrame) {
}
part, ok := message.parts[id]
if !ok {
part = &chatPart{part: protocol.ChatPart{Type: frame.Kind, ID: id}}
part = &chatPart{part: protocol.ChatPart{Type: frame.Kind, ID: id, Name: frame.Part.Name}}
message.order = append(message.order, id)
message.parts[id] = part
}
@@ -553,6 +559,7 @@ func (h *chatHub) snapshot(sessionID string) []protocol.ChatMessage {
}
out.Client = message.client
out.OperationID = message.operationID
out.Kind = message.kind
for _, partID := range message.order {
if part, ok := message.parts[partID]; ok {
piece := part.part
+29
View File
@@ -0,0 +1,29 @@
package server
import (
"testing"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
// A live agent report keeps its kind and sender across a resume snapshot, and
// is never mistaken for the agent's final reply.
func TestHubKeepsInjectedMessageKind(t *testing.T) {
h := newChatHub()
h.apply(protocol.ChatEventFrame{SessionID: "s", MessageID: "msg_1", Kind: protocol.ChatEventText, Delta: "The answer", Part: &protocol.ChatPart{ID: "msg_1#text#0"}})
h.apply(protocol.ChatEventFrame{
SessionID: "s", MessageID: "agent-report-x", MessageKind: protocol.ChatMessageKindAgentReport, Kind: protocol.ChatEventText,
Delta: "## Report", Part: &protocol.ChatPart{ID: "agent-report-x#text#0", Name: "general-purpose"},
})
messages := h.snapshot("s")
if len(messages) != 2 || messages[0].Kind != "" || messages[1].Kind != protocol.ChatMessageKindAgentReport ||
messages[1].Role != protocol.ChatRoleAssistant || messages[1].Parts[0].Name != "general-purpose" || messages[1].Parts[0].Text != "## Report" {
t.Fatalf("snapshot: %+v", messages)
}
h.mu.Lock()
reply := h.finalReplyTextLocked("s")
h.mu.Unlock()
if reply != "The answer" {
t.Fatalf("final reply must skip the report, got %q", reply)
}
}
+4
View File
@@ -62,6 +62,10 @@ func (h *chatHub) finalReplyTextLocked(sessionID string) string {
if message.role == protocol.ChatRoleUser {
return ""
}
if message.kind != "" {
// An agent report or notice the harness delivered is not the reply.
continue
}
var text strings.Builder
for _, id := range message.order {
part := message.parts[id]