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:
@@ -42,7 +42,15 @@ type transcriptEntry struct {
|
||||
Type string `json:"type"`
|
||||
Prompt json.RawMessage `json:"prompt"`
|
||||
CommandMode string `json:"commandMode"`
|
||||
IsMeta bool `json:"isMeta"`
|
||||
Origin json.RawMessage `json:"origin"`
|
||||
} `json:"attachment"`
|
||||
// IsMeta marks a user entry the CLI wrote itself (a skill body, an image
|
||||
// placeholder, a reminder). Origin says where injected input came from: a
|
||||
// peer or subagent report, or a task notification. An operator prompt has
|
||||
// neither.
|
||||
IsMeta bool `json:"isMeta"`
|
||||
Origin json.RawMessage `json:"origin"`
|
||||
}
|
||||
|
||||
func readTranscript(path string) ([]transcriptEntry, error) {
|
||||
@@ -174,6 +182,15 @@ func (s *session) transcriptMessages(limit int, cursor string) (protocol.ChatHis
|
||||
parts = append(parts, files...)
|
||||
messages = append(messages, protocol.ChatMessage{ID: id, SessionID: s.id, Role: protocol.ChatRoleUser, CreatedAt: created, Parts: parts})
|
||||
}
|
||||
injectedSeen := map[string]bool{}
|
||||
addInjected := func(entry transcriptEntry, item injected) {
|
||||
if item.id == "" || injectedSeen[item.id] {
|
||||
return
|
||||
}
|
||||
injectedSeen[item.id] = true
|
||||
created, _ := transcriptTime(entry.Timestamp)
|
||||
messages = append(messages, item.message(s.id, created))
|
||||
}
|
||||
for _, entry := range entries {
|
||||
if entry.IsSidechain {
|
||||
continue
|
||||
@@ -232,9 +249,17 @@ func (s *session) transcriptMessages(limit int, cursor string) (protocol.ChatHis
|
||||
}
|
||||
}
|
||||
case "user":
|
||||
origin := decodeOrigin(entry.Origin)
|
||||
if len(entry.Message.Content) > 0 && entry.Message.Content[0] == '"' {
|
||||
// A string user entry is harness feedback (local command output or
|
||||
// a tool protocol message), never a turn the operator sent.
|
||||
// A string user entry is harness input (local command output, a
|
||||
// reminder, a task notification or an agent's report), never a
|
||||
// turn the operator sent. Reports and notices are shown as such.
|
||||
var raw string
|
||||
if json.Unmarshal(entry.Message.Content, &raw) == nil {
|
||||
if item := classifyInjected(raw, origin, entry.IsMeta); item.class == classAgentReport || item.class == classNotice {
|
||||
addInjected(entry, item)
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
blocks := decodeBlocks(entry.Message.Content)
|
||||
@@ -263,14 +288,32 @@ func (s *session) transcriptMessages(limit int, cursor string) (protocol.ChatHis
|
||||
if hasResult || (text == "" && len(files) == 0) {
|
||||
continue
|
||||
}
|
||||
if text != "" {
|
||||
switch item := classifyInjected(text, origin, entry.IsMeta); item.class {
|
||||
case classAgentReport, classNotice:
|
||||
addInjected(entry, item)
|
||||
continue
|
||||
case classHidden:
|
||||
continue
|
||||
default:
|
||||
text = item.text
|
||||
}
|
||||
} else if entry.IsMeta {
|
||||
continue
|
||||
}
|
||||
addUser(entry, text, files)
|
||||
case "attachment":
|
||||
// A message the operator sent while the turn was running is recorded
|
||||
// as a queued_command attachment where the CLI surfaced it to the
|
||||
// model, so it is the user's turn at that point of the transcript.
|
||||
// Other queued commands (task notifications, agent messages) are
|
||||
// harness input, not the operator's.
|
||||
if entry.Attachment.Type != "queued_command" || entry.Attachment.CommandMode != "prompt" {
|
||||
// Other queued commands (task notifications, and agent reports the
|
||||
// CLI also queues as "prompt" with an origin) are harness input:
|
||||
// they are shown as notices and report cards, never as the operator's.
|
||||
if entry.Attachment.Type != "queued_command" {
|
||||
continue
|
||||
}
|
||||
mode := entry.Attachment.CommandMode
|
||||
if mode != "prompt" && mode != "task-notification" {
|
||||
continue
|
||||
}
|
||||
var text string
|
||||
@@ -285,6 +328,19 @@ func (s *session) transcriptMessages(limit int, cursor string) (protocol.ChatHis
|
||||
if strings.TrimSpace(text) == "" {
|
||||
continue
|
||||
}
|
||||
origin := decodeOrigin(entry.Attachment.Origin)
|
||||
if mode == "task-notification" && origin.Kind == "" {
|
||||
origin.Kind = "task-notification"
|
||||
}
|
||||
switch item := classifyInjected(text, origin, entry.Attachment.IsMeta); item.class {
|
||||
case classAgentReport, classNotice:
|
||||
addInjected(entry, item)
|
||||
continue
|
||||
case classHidden:
|
||||
continue
|
||||
default:
|
||||
text = item.text
|
||||
}
|
||||
addUser(entry, text, []protocol.ChatPart{})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user