Run card mini-map and stage strip; graph edge hover highlight

The show_run card carries the run's graph and per-stage progress (bounded by
the graph, not the run length) and draws a still mini-map with the run graph
plus a stage strip with status, visits and time. Hovering or tapping an edge
in the pipeline and run graphs highlights it, its label and endpoints, with a
tooltip naming from -> to, the outcome and, for runs, how often it was taken.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 12:56:51 +00:00
parent c4de1de27b
commit 7872e57d40
17 changed files with 1709 additions and 51 deletions
@@ -1,6 +1,9 @@
import '../../../core/api_gateway.dart';
import '../../pipelines/pipeline_format.dart' show formatDuration;
import '../../runs/domain/run_events.dart' show isTerminalRunStatus;
import 'chat_shown_run_map.dart';
export 'chat_shown_run_map.dart';
/// A `show_run` item's run, as the server records it
/// (`internal/protocol/chat_shown.go` ChatShownRunBody). The server pushes the
@@ -15,6 +18,7 @@ class ChatShownRun {
required this.currentStage,
required this.startedAt,
required this.finishedAt,
this.map,
});
/// The run of a `run` item, or null for any other item or a malformed one.
@@ -32,6 +36,7 @@ class ChatShownRun {
currentStage: _text(body['current_stage']),
startedAt: _millis(body['started_at']),
finishedAt: _millis(body['finished_at']),
map: ChatShownRunMap.of(body['map']),
);
}
@@ -44,6 +49,9 @@ class ChatShownRun {
final int? startedAt;
final int? finishedAt;
/// The graph and stage progress for the card's mini-map, when sent.
final ChatShownRunMap? map;
/// Whether the run has ended (succeeded, failed, canceled, interrupted).
bool get finished => isTerminalRunStatus(status);
@@ -0,0 +1,119 @@
import '../../../core/api_gateway.dart';
import '../../pipelines/pipeline_format.dart' show formatDuration;
/// One declared stage of a `show_run` card's map with its progress in the run
/// (`internal/protocol/chat_shown.go` ChatShownRunStage).
class ChatShownRunStage {
const ChatShownRunStage({
required this.key,
required this.type,
required this.visits,
required this.status,
required this.seconds,
required this.runningSince,
});
final String key;
final String type;
/// How many times the run entered the stage; 0 when it never did.
final int visits;
/// The latest visit's recorded status, empty when never visited.
final String status;
/// Seconds spent in the stage's finished visits.
final int seconds;
/// The running visit's start (epoch milliseconds), or null.
final int? runningSince;
bool get visited => visits > 0;
/// Total time in the stage at [now] (epoch milliseconds), counting a running
/// visit; null for a stage that never ran.
String? duration(int now) {
if (!visited) return null;
final since = runningSince;
final live = since == null || now < since ? 0 : (now - since) ~/ 1000;
return formatDuration(seconds + live);
}
}
/// A `show_run` card's map: the run's graph as the graph feature reads it and
/// the compact route evidence as run-detail steps, plus the stage list.
///
/// The server bounds it by the graph's size (ChatShownRunMapStages), not by
/// the run's length.
class ChatShownRunMap {
const ChatShownRunMap({
required this.graph,
required this.steps,
required this.stages,
});
/// The map of a run body, or null when the server sent none.
static ChatShownRunMap? of(Object? raw) {
if (raw is! Map) return null;
final rawStages = raw['stages'];
if (rawStages is! List) return null;
final stages = <ChatShownRunStage>[];
final definitions = <JsonMap>[];
for (final stage in rawStages.whereType<Map>()) {
final key = '${stage['key'] ?? ''}'.trim();
if (key.isEmpty) continue;
final edges = stage['edges'];
definitions.add({
'key': key,
'type': stage['type'],
'edges': edges is Map ? JsonMap.from(edges) : const <String, dynamic>{},
'fallback_error': stage['fallback_error'] == true,
});
stages.add(
ChatShownRunStage(
key: key,
type: '${stage['type'] ?? ''}',
visits: _int(stage['visits']) ?? 0,
status: '${stage['status'] ?? ''}'.trim(),
seconds: _int(stage['seconds']) ?? 0,
runningSince: _positive(stage['running_since']),
),
);
}
if (stages.isEmpty) return null;
final rawVisits = raw['visits'];
final steps = <JsonMap>[
if (rawVisits is List)
for (final visit in rawVisits.whereType<Map>())
{
'sequence': visit['sequence'],
'stage': '${visit['stage'] ?? ''}',
'status': '${visit['status'] ?? ''}',
'outcome': '${visit['outcome'] ?? ''}',
'target': '${visit['target'] ?? ''}',
},
];
return ChatShownRunMap(
graph: {'stages': definitions},
steps: steps,
stages: stages,
);
}
/// The graph definition shape (`stages` with `key`, `edges`).
final JsonMap graph;
/// The route evidence in the run-detail step shape, in sequence order.
final List<JsonMap> steps;
final List<ChatShownRunStage> stages;
/// The run-detail map the graph feature reads its evidence from.
JsonMap runDetail({required String currentStage, required bool executing}) =>
{'steps': steps, 'current_stage': currentStage, 'executing': executing};
}
int? _int(Object? value) => value is num ? value.toInt() : null;
int? _positive(Object? value) =>
value is num && value > 0 ? value.toInt() : null;
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import '../../../../../core/api_gateway.dart';
import '../../../chat_run_opener.dart';
import '../../../domain/chat_shown_run.dart';
import 'chat_shown_run_map_view.dart';
import 'chat_shown_surface.dart';
/// The glyph of a run status.
@@ -134,6 +135,10 @@ class _ChatShownRunCardState extends State<ChatShownRunCard> {
),
],
),
if (run.map case final map?) ...[
const SizedBox(height: 10),
ChatShownRunMapView(run: run, map: map, now: _now),
],
],
),
);
@@ -0,0 +1,175 @@
import 'package:flutter/material.dart';
import '../../../../graph/widgets/run_graph_view.dart';
import '../../../domain/chat_shown_run.dart';
/// The mini-map's height: enough for one row of stages and the ends below it
/// at a glance, small enough to keep the card compact.
const double chatShownRunMapHeight = 136;
/// A `show_run` card's graph: a still mini-map of the run's pipeline drawn by
/// the run graph itself (visited stages with their status, the live stage's
/// halo, the taken path solid and untaken routes dashed), then a strip of every
/// stage with its status, visits and time.
class ChatShownRunMapView extends StatelessWidget {
const ChatShownRunMapView({
super.key,
required this.run,
required this.map,
required this.now,
});
final ChatShownRun run;
final ChatShownRunMap map;
/// The current time in epoch milliseconds, for running stages' durations.
final int now;
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
final current = run.finished ? '' : run.currentStage;
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
DecoratedBox(
decoration: BoxDecoration(
color: colors.surfaceContainerLow,
border: Border.all(color: colors.outlineVariant),
borderRadius: BorderRadius.circular(8),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: SizedBox(
key: const Key('chat-shown-run-map'),
height: chatShownRunMapHeight,
child: Padding(
padding: const EdgeInsets.all(6),
child: RunGraphView(
graph: map.graph,
run: map.runDetail(
currentStage: run.currentStage,
executing: !run.finished,
),
onStageSelected: (_) {},
showHeader: false,
expandable: false,
still: true,
),
),
),
),
),
const SizedBox(height: 8),
Wrap(
key: const Key('chat-shown-run-stages'),
spacing: 6,
runSpacing: 6,
children: [
for (final stage in map.stages)
_StageEntry(
stage: stage,
current: stage.key == current,
duration: stage.duration(now),
),
],
),
],
);
}
}
/// The glyph of a recorded stage status; a stage never entered is a hollow
/// circle.
IconData chatShownStageIcon(String status, {required bool visited}) {
if (!visited) return Icons.radio_button_unchecked;
return switch (status) {
'completed' || 'succeeded' => Icons.check_circle,
'failed' => Icons.error,
'running' => Icons.play_circle,
'waiting' => Icons.front_hand,
'interrupted' => Icons.pause_circle,
'canceled' => Icons.cancel,
_ => Icons.circle,
};
}
Color _stageColor(ColorScheme colors, ChatShownRunStage stage) {
if (!stage.visited) return colors.outline;
return switch (stage.status) {
'completed' || 'succeeded' => colors.primary,
'failed' || 'interrupted' => colors.error,
'running' || 'waiting' => colors.tertiary,
_ => colors.onSurfaceVariant,
};
}
/// One stage of the strip: status glyph, name, `×visits` when it looped and
/// the time spent. The run's current stage is filled and bold.
class _StageEntry extends StatelessWidget {
const _StageEntry({
required this.stage,
required this.current,
required this.duration,
});
final ChatShownRunStage stage;
final bool current;
final String? duration;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final colors = theme.colorScheme;
final base = theme.textTheme.labelMedium ?? const TextStyle();
final name = base.copyWith(
color: stage.visited ? colors.onSurface : colors.onSurfaceVariant,
fontWeight: current ? FontWeight.w700 : null,
);
final meta = base.copyWith(color: colors.onSurfaceVariant);
final status = stage.visited ? stage.status : 'not run';
final facts = [if (stage.visits > 1) '×${stage.visits}', ?duration];
return Semantics(
container: true,
label: [
stage.key,
status,
if (stage.visits > 1) '${stage.visits} visits',
?duration,
if (current) 'current stage',
].join(', '),
child: ExcludeSemantics(
child: DecoratedBox(
key: ValueKey('chat-shown-run-stage:${stage.key}'),
decoration: BoxDecoration(
color: current ? colors.secondaryContainer : null,
border: Border.all(
color: current ? colors.secondary : colors.outlineVariant,
),
borderRadius: BorderRadius.circular(8),
),
child: Padding(
padding: const EdgeInsetsDirectional.fromSTEB(6, 3, 8, 3),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
chatShownStageIcon(stage.status, visited: stage.visited),
size: MediaQuery.textScalerOf(context).scale(14),
color: _stageColor(colors, stage),
),
const SizedBox(width: 4),
Text(stage.key, style: name),
if (facts.isNotEmpty) ...[
const SizedBox(width: 6),
Text(facts.join(' · '), style: meta),
],
],
),
),
),
),
);
}
}