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:
@@ -70,6 +70,11 @@ JsonMap refreshCachedChatHistory(
|
||||
/// the latest record and that record's lifecycle state. Several updates of one
|
||||
/// compaction are therefore one line, never one line per update.
|
||||
///
|
||||
/// A message the server marks with a `kind` is content the harness delivered,
|
||||
/// not a turn: an `agent_report` becomes its own `agent_report` row and a
|
||||
/// `notice` its own `system_notice` row, on the agent's side, never folded into
|
||||
/// an answer and never drawn as the operator's bubble (see [chatInjectedKind]).
|
||||
///
|
||||
/// [trailing] rows are conversation cards (permission requests and questions),
|
||||
/// not messages. They keep the server's order after the transcript, the way the
|
||||
/// web renders approvals and forms at the end of the conversation.
|
||||
@@ -124,6 +129,18 @@ List<JsonMap> transcriptRows(
|
||||
}
|
||||
|
||||
for (final message in messages) {
|
||||
final injected = chatInjectedKind(message);
|
||||
if (injected != null) {
|
||||
flush();
|
||||
rows.add({
|
||||
'kind': injected == chatKindAgentReport
|
||||
? 'agent_report'
|
||||
: 'system_notice',
|
||||
'key': message['id'],
|
||||
'message': message,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
if (message['role'] == 'assistant') {
|
||||
final id = '${message['id'] ?? ''}'.trim();
|
||||
key ??= id;
|
||||
@@ -149,10 +166,14 @@ List<JsonMap> transcriptRows(
|
||||
// Prefer the assistant identity that actually streamed: a queued follow-up
|
||||
// can be later in the transcript while this same reply is still arriving.
|
||||
// Before a first delta, do not reopen an older reply behind a new user turn.
|
||||
final answers = [
|
||||
for (final message in messages)
|
||||
if (chatInjectedKind(message) == null) message,
|
||||
];
|
||||
final streamingId =
|
||||
liveMessageId ??
|
||||
(messages.isNotEmpty && messages.last['role'] == 'assistant'
|
||||
? '${messages.last['id'] ?? ''}'
|
||||
(answers.isNotEmpty && answers.last['role'] == 'assistant'
|
||||
? '${answers.last['id'] ?? ''}'
|
||||
: null);
|
||||
var hasStreamingRow = false;
|
||||
if (running && streamingId != null) {
|
||||
@@ -180,6 +201,19 @@ List<JsonMap> transcriptRows(
|
||||
return rows;
|
||||
}
|
||||
|
||||
/// `ChatMessage.Kind` of a report another agent delivered into the session.
|
||||
const String chatKindAgentReport = 'agent_report';
|
||||
|
||||
/// `ChatMessage.Kind` of a one-line harness notice (a background task ended).
|
||||
const String chatKindNotice = 'notice';
|
||||
|
||||
/// The injected-content kind the server recorded on [message], or null for an
|
||||
/// ordinary turn. An unknown future kind keeps the message's own role.
|
||||
String? chatInjectedKind(JsonMap message) {
|
||||
final kind = '${message['kind'] ?? ''}';
|
||||
return kind == chatKindAgentReport || kind == chatKindNotice ? kind : null;
|
||||
}
|
||||
|
||||
/// Whether [part] is a recorded activity record rather than answer content.
|
||||
///
|
||||
/// Both spellings occur: `compaction` is the native lifecycle record and
|
||||
@@ -307,6 +341,9 @@ JsonMap applyChatEvent(JsonMap thread, JsonMap frame) {
|
||||
final incoming = frame['part'];
|
||||
if (incoming is! Map || incoming['id'] == null) return thread;
|
||||
final messageId = frame['message_id'];
|
||||
// An agent report or notice the harness delivered: drawn on its own, and
|
||||
// never evidence that the agent's turn is running.
|
||||
final injected = chatInjectedKind({'kind': frame['message_kind']});
|
||||
var index = messages.indexWhere(
|
||||
(m) => m['id'] == messageId && m['role'] == 'assistant',
|
||||
);
|
||||
@@ -315,6 +352,7 @@ JsonMap applyChatEvent(JsonMap thread, JsonMap frame) {
|
||||
'id': messageId,
|
||||
'session_id': frame['session_id'],
|
||||
'role': 'assistant',
|
||||
'kind': ?injected,
|
||||
'parts': <JsonMap>[],
|
||||
});
|
||||
index = messages.length - 1;
|
||||
@@ -331,7 +369,12 @@ JsonMap applyChatEvent(JsonMap thread, JsonMap frame) {
|
||||
final delta = frame['delta'];
|
||||
if (delta is! String || delta.isEmpty) return thread;
|
||||
if (partIndex < 0) {
|
||||
parts.add({'type': kind, 'id': incoming['id'], 'text': delta});
|
||||
parts.add({
|
||||
'type': kind,
|
||||
'id': incoming['id'],
|
||||
'text': delta,
|
||||
if (incoming['name'] is String) 'name': incoming['name'],
|
||||
});
|
||||
} else {
|
||||
parts[partIndex] = {
|
||||
...parts[partIndex],
|
||||
@@ -354,6 +397,9 @@ JsonMap applyChatEvent(JsonMap thread, JsonMap frame) {
|
||||
parts[partIndex] = merged;
|
||||
}
|
||||
messages[index] = {...message, 'parts': parts};
|
||||
if (chatInjectedKind(message) != null) {
|
||||
return {...thread, 'messages': messages};
|
||||
}
|
||||
return {...thread, 'messages': messages, 'running': true};
|
||||
}
|
||||
if (kind == 'step' && frame['step'] is Map) {
|
||||
|
||||
Reference in New Issue
Block a user