Chat: fold activity-only rows between messages into one summary line

Tool-only turns, thinking-only turns and background-task notices that sit
between two content rows become one collapsible activity_group row, e.g.
"Ran 7 commands · used 9 tools · 8 background tasks finished · 1 failed",
the failure count in the error colour and never ellipsized. Expanding it
shows the folded rows as they render on their own. A run's task notices
fold into one chip at the newest notice; a notice whose id recurs later is
counted only at its latest position.

Grouping is a pure domain step (groupChatActivity) applied last in the
thread view's row pipeline; group rows list every member id so ChatRowKeys
keeps their identity, unchanged runs return the identical group object, and
the transcript anchor accepts a group's agent-turn ids. The scroll fixture
gains ?bgwork=1 for the shape.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 10:58:25 +00:00
parent 33874005c4
commit 22866ec0ce
10 changed files with 963 additions and 13 deletions
+63
View File
@@ -12,6 +12,9 @@
// new reply, one every 60 ms;
// `?tasks=N` the history ends with N consecutive background-task notices
// in the server's wording (every third one failed);
// `?bgwork=1` the history ends with an agent's background work between two
// answers: tool-only turns ("Used 9 tools", "Ran 1 command",
// one with a failed command) split by background-task notices;
// `?links=1` answers and operator turns carry a markdown link, an
// autolink, a bare URL and URLs inside code (never linkified).
import 'dart:async';
@@ -31,6 +34,65 @@ bool get _links => _params['links'] == '1';
bool get _older => _params['older'] == '1';
int get _live => int.tryParse(_params['live'] ?? '') ?? 0;
int get _tasks => int.tryParse(_params['tasks'] ?? '') ?? 0;
bool get _bgwork => _params['bgwork'] == '1';
/// `?bgwork=1`: a reply, then tool-only turns split by task notices, then a
/// closing reply, the shape a long background session records.
List<JsonMap> _backgroundWork(String chat) {
var minute = 0;
int at() => DateTime.utc(2026, 11, 5, 10, minute++).millisecondsSinceEpoch;
JsonMap tool(String id, String name, {bool failed = false}) => {
'type': 'tool',
'id': id,
'name': name,
'state': {'status': failed ? 'error' : 'completed', 'title': name},
};
JsonMap turn(String id, List<JsonMap> parts) => {
'id': '$chat-bg-$id',
'role': 'assistant',
'created_at': at(),
'parts': parts,
};
JsonMap notice(String id, String summary) => {
..._taskNotice(chat, 0),
'id': '$chat-bg-task-$id',
'created_at': at(),
'parts': [
{'type': 'text', 'text': 'Background task finished: $summary'},
],
};
return [
{
'id': '$chat-bg-q',
'role': 'user',
'created_at': at(),
'parts': [
{'type': 'text', 'text': 'Run the checks in the background.'},
],
},
turn('a0', [
{'type': 'text', 'text': 'Starting the checks in the background.'},
]),
notice('1', 'Background command "Unit tests" completed (exit code 0)'),
turn('t1', [for (var i = 0; i < 9; i++) tool('t1-$i', 'read')]),
notice('2', 'Agent "Review part 1" finished'),
notice('3', 'Agent "Review part 2" finished'),
turn('t2', [tool('t2-0', 'bash')]),
notice('4', 'Background command "Lint" completed (exit code 0)'),
turn('t3', [tool('t3-0', 'bash')]),
notice('5', 'Background command "Build" completed (exit code 0)'),
notice('6', 'Background command "Docs" completed (exit code 0)'),
turn('t4', [
for (var i = 0; i < 4; i++) tool('t4-$i', 'bash', failed: i == 2),
]),
notice('7', 'Background command "Format" completed (exit code 0)'),
turn('t5', [tool('t5-0', 'bash')]),
notice('8', 'Background command "Smoke test" completed (exit code 0)'),
turn('a1', [
{'type': 'text', 'text': 'All the background checks are done.'},
]),
];
}
/// Background task [i]'s notice, as the server records a Claude Code task
/// notification.
@@ -168,6 +230,7 @@ JsonMap chatScrollHistory(String sessionId, int index, String cursor) {
return {
'messages': [
for (var i = 0; i < count; i++) _message(sessionId, i),
if (_bgwork) ..._backgroundWork(sessionId),
for (var i = 0; i < _tasks; i++) _taskNotice(sessionId, i),
],
'next_cursor': _older ? 'older' : '',