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
@@ -32,6 +32,8 @@ import '../ui/transcript/chat_transcript_selection.dart';
import '../ui/transcript/chat_injected_rows.dart';
import '../ui/transcript/shown/chat_shown_card.dart';
import '../ui/transcript/chat_task_notices_group.dart';
import '../ui/transcript/chat_activity_group_view.dart';
import '../domain/chat_activity_groups.dart';
import '../ui/transcript/chat_turn_diff_chip.dart';
import '../../artifacts/actions/artifact_file_bridge.dart';
import '../domain/chat_session_handoff.dart';
@@ -1183,12 +1185,17 @@ class _ChatThreadViewState extends State<ChatThreadView> {
final compactionNotice = _noticeOf(notices, ChatNoticeKind.compaction);
// The operator's own shell commands sit among the turns by start time;
// dismissed ones fold into a chip under the answer that followed them.
final rows = attachChatShellHistory(
withChatShellRunRows([
for (final row in allRows)
if (!_hiddenRunningCompaction(row)) row,
], _shellRuns.runs),
_shellRuns.dismissedRuns,
// A run of activity-only rows (tool turns, background-task notices)
// between two messages folds into one summary line last, once every
// chip has found its row.
final rows = groupChatActivity(
attachChatShellHistory(
withChatShellRunRows([
for (final row in allRows)
if (!_hiddenRunningCompaction(row)) row,
], _shellRuns.runs),
_shellRuns.dismissedRuns,
),
);
// Older pages prepend messages and a live frame can append one, so a
// folded assistant turn's first message id is not a stable identity.
@@ -1728,6 +1735,14 @@ class _ChatThreadViewState extends State<ChatThreadView> {
);
}
if (kind == 'task_notices') return ChatTaskNoticesGroup(row: row);
if (kind == chatActivityGroupKind) {
// Each folded row is built (and memoised) as it would be on its own.
return ChatActivityGroupView(
row: row,
memberBuilder: (member) =>
_transcriptRow(member, '$key/${member['key'] ?? ''}'),
);
}
if (kind == 'questions') return ChatQuestionsRow(row: row);
if (kind == 'permission' || kind == 'question') {
return ChatTranscriptCard(
@@ -1,4 +1,5 @@
import '../../../core/api_gateway.dart';
import '../domain/chat_activity_groups.dart';
/// Where an opened transcript is split into its older and newer halves.
///
@@ -49,10 +50,17 @@ int chatTranscriptAnchorIndex(List<JsonMap> rows, String? anchor) {
return -1;
}
/// The stored message ids of one user or assistant row. Cards, activity lines
/// and the pending-response shell carry none and can never be an anchor.
/// The stored message ids of one user or assistant row, or of the agent turns
/// an activity group folds. Cards, notices, activity lines and the
/// pending-response shell carry none and can never be an anchor.
List<String> _messageIds(JsonMap row) {
final kind = row['kind'];
if (kind == chatActivityGroupKind) {
return [
for (final id in chatActivityGroupTurnIds(row))
if (id.trim().isNotEmpty) id.trim(),
];
}
if (kind == 'assistant') {
final listed = row['messageIds'];
if (listed is! List) return const [];