group consecutive same-file edits into one collapsed card (T-296)

A run of 2+ consecutive edits to the same file now folds into one ClideHolderCard
labelled '# edits' (coalesceEditRuns, run after groupConversation) instead of a
stack of cards; a different file or an interleaving step splits the run. Every
edit stays reachable on expand.

The holder gained an optional aggregate status. New owned primitives: ClideSpinner
(the logo mark, monochrome, 3D Y-axis rotation, reduced-motion-aware) and
ClideStatusIndicator (running→spinner / success→check / error→cross, with an
AnimatedSwitcher seam for a richer transition later — kept self-contained, not
built on ConversationCard's mark). The activity card shares the same indicator.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-09 18:34:27 +02:00
co-authored by Claude Opus 4.8
parent 6efb3b5d2b
commit 407ed25ab0
10 changed files with 447 additions and 6 deletions
@@ -50,9 +50,58 @@ final class FoldedCluster extends RenderGroup {
final List<ConversationItem> items;
}
/// A run of 2+ consecutive edits to the SAME file, bundled into one collapsed
/// "# edits" card (T-296). Holds the edit tool-use items (their success results
/// fold into each child card as usual). Always length >= 2.
final class EditRun extends RenderGroup {
const EditRun(this.edits, this.filePath);
final List<ConversationItem> edits;
final String filePath;
}
/// Tools whose result is a diff the user wants to keep first-class at L1/L2.
bool isDiffTool(String name) => const {'Edit', 'Write', 'MultiEdit', 'NotebookEdit', 'Update'}.contains(name);
/// The file an edit tool-use targets, or null if [it] isn't a same-file edit
/// (used to group consecutive edits, T-296).
String? editFilePath(ConversationItem it) {
if (it is! AssistantToolUse || !isDiffTool(it.name)) return null;
final p = it.input['file_path'] ?? it.input['path'] ?? it.input['notebook_path'];
return p is String && p.isNotEmpty ? p : null;
}
/// Coalesce maximal runs of consecutive same-file edit [StickyItem]s into one
/// [EditRun] (T-296). A different file, or any non-edit group, breaks the run;
/// a lone edit stays a [StickyItem]. Run this after [groupConversation], on its
/// output, so it composes with the existing meta-folding (a folded Read cluster
/// between two edit runs splits them — matching the worked example).
List<RenderGroup> coalesceEditRuns(List<RenderGroup> groups) {
final out = <RenderGroup>[];
var run = <ConversationItem>[];
String? runPath;
void flush() {
if (run.isEmpty) return;
out.add(run.length >= 2 ? EditRun(List.unmodifiable(run), runPath!) : StickyItem(run.single));
run = [];
runPath = null;
}
for (final g in groups) {
final path = g is StickyItem ? editFilePath(g.item) : null;
if (path != null) {
if (runPath != null && path != runPath) flush(); // different file → new run
runPath = path;
run.add((g as StickyItem).item);
} else {
flush();
out.add(g);
}
}
flush();
return out;
}
/// Group [items] into render units per [level]. Pairs tool results to their
/// originating tool-use (by `toolUseId`) so a result can be classified by its
/// tool name (diffs stay first-class at L1/L2).
+75 -2
View File
@@ -270,8 +270,9 @@ class _ConversationViewState extends State<ConversationView> {
};
// Fold runs of meta items into collapsible activity cards (T-230); sticky
// items (user/prose/surfaced errors) render first-class as before.
final groups = groupConversation(items, widget.foldLevel);
// items (user/prose/surfaced errors) render first-class as before. Then
// bundle consecutive same-file edits into one "# edits" card (T-296).
final groups = coalesceEditRuns(groupConversation(items, widget.foldLevel));
final list = ClideScrollbar(
controller: _scroll,
child: ListView.builder(
@@ -304,6 +305,16 @@ class _ConversationViewState extends State<ConversationView> {
promptsByToolUseId: fold.promptsByToolUseId,
runByToolUseId: fold.runByToolUseId,
),
EditRun(:final edits) => _EditRunCard(
key: ValueKey('edits.${edits.first.uuid}'),
edits: edits,
tokens: tokens,
toolUseOutcomes: widget.toolUseOutcomes,
toolUseById: widget.controller.toolUseById,
resultByToolUseId: resultByToolUseId,
promptsByToolUseId: fold.promptsByToolUseId,
runByToolUseId: fold.runByToolUseId,
),
};
},
),
@@ -724,6 +735,7 @@ class _ActivityCard extends StatelessWidget {
return ClideHolderCard(
collapsedSummary: _summarizeActivity(items.last),
stepLabel: count == 1 ? '1 step' : '$count steps',
status: _runStatus(items, resultByToolUseId),
children: [
for (final item in items)
_ConversationTurn(
@@ -741,6 +753,67 @@ class _ActivityCard extends StatelessWidget {
}
}
/// Aggregate live status for a run's header tick (T-296): error if any tool in
/// the run failed, else running while its last tool awaits a result, else
/// success. Null (no tools) shows no indicator.
ClideRunStatus? _runStatus(List<ConversationItem> items, Map<String, ToolResultMessage> results) {
final tools = items.whereType<AssistantToolUse>().toList();
if (tools.isEmpty) return null;
for (final t in tools) {
final r = results[t.toolUseId];
if (r != null && r.isError) return ClideRunStatus.error;
}
return results[tools.last.toolUseId] == null ? ClideRunStatus.running : ClideRunStatus.success;
}
/// A run of consecutive same-file edits, bundled into one collapsible "# edits"
/// card (T-296) through the shared [ClideHolderCard]. Each edit keeps its own
/// merged tool card when expanded; the header carries the aggregate live tick.
class _EditRunCard extends StatelessWidget {
const _EditRunCard({
super.key,
required this.edits,
required this.tokens,
required this.toolUseOutcomes,
required this.toolUseById,
required this.resultByToolUseId,
required this.promptsByToolUseId,
required this.runByToolUseId,
});
final List<ConversationItem> edits;
final SurfaceTokens tokens;
final Map<String, bool> toolUseOutcomes;
final Map<String, AssistantToolUse> toolUseById;
final Map<String, ToolResultMessage> resultByToolUseId;
final Map<String, List<UserMessage>> promptsByToolUseId;
final Map<String, List<ConversationItem>> runByToolUseId;
@override
Widget build(BuildContext context) {
final count = edits.length;
return ClideHolderCard(
title: 'Edits',
collapsedSummary: _summarizeActivity(edits.last),
stepLabel: count == 1 ? '1 edit' : '$count edits',
status: _runStatus(edits, resultByToolUseId),
children: [
for (final item in edits)
_ConversationTurn(
key: ValueKey('edit.${item.uuid}'),
item: item,
tokens: tokens,
toolUseOutcomes: toolUseOutcomes,
toolUseById: toolUseById,
resultByToolUseId: resultByToolUseId,
promptsByToolUseId: promptsByToolUseId,
runByToolUseId: runByToolUseId,
),
],
);
}
}
/// One-line summary of a folded item for the collapsed ticker.
String _summarizeActivity(ConversationItem item) {
switch (item) {
+13
View File
@@ -30,6 +30,7 @@ class ClideHolderCard extends StatefulWidget {
required this.children,
this.title = 'Activity',
this.initiallyExpanded = false,
this.status,
});
/// One-line gist of the latest step, shown in the collapsed ticker.
@@ -47,6 +48,10 @@ class ClideHolderCard extends StatefulWidget {
final bool initiallyExpanded;
/// Optional aggregate run status (spinner / check / cross) shown at the head
/// of the ticker + header — the run's live state (T-296). Null shows nothing.
final ClideRunStatus? status;
@override
State<ClideHolderCard> createState() => _ClideHolderCardState();
}
@@ -108,6 +113,10 @@ class _ClideHolderCardState extends State<ClideHolderCard> {
),
),
const SizedBox(width: 8),
if (widget.status != null) ...[
ClideStatusIndicator(status: widget.status!, size: 12),
const SizedBox(width: 8),
],
ClideText(widget.stepLabel, fontSize: clideFontCaption, color: tokens.globalTextMuted),
],
),
@@ -186,6 +195,10 @@ class _ClideHolderCardState extends State<ClideHolderCard> {
child: ClideText(widget.title, fontSize: clideFontCaption, fontFamily: clideMonoFamily, color: tokens.globalTextMuted),
),
const SizedBox(width: 8),
if (widget.status != null) ...[
ClideStatusIndicator(status: widget.status!, size: 12),
const SizedBox(width: 8),
],
ClideText(widget.stepLabel, fontSize: clideFontCaption, color: tokens.globalTextMuted),
],
),