Files
pipelines/app/lib/features/runs/ui/run_detail_summary_fields.dart
T
alan fc615c69e7 Merge branch 'main' into worktree-agent-a35ac03e196ffae50
# Conflicts:
#	app/lib/features/runs/ui/run_detail_content.dart
#	app/lib/features/runs/ui/run_list_row.dart
#	app/tool/search_selection_probe_entry.dart
2026-11-04 17:44:29 +00:00

117 lines
4.4 KiB
Dart

import '../../../core/api_gateway.dart';
import '../../pipelines/pipeline_format.dart';
import '../domain/run_deletion.dart' show formatByteSize, runSizeBytes;
import '../domain/run_tokens.dart';
import 'run_detail_visit_facts.dart';
/// One recorded Summary row: the web run summary's key/value shape.
///
/// [monospace] marks a value the web renders as a code identifier (the content
/// hash); [block] marks a multi-line recorded document (the diagnostic) that is
/// drawn as its own block rather than a short row.
typedef DetailSummaryRow = ({
String label,
String value,
bool monospace,
bool block,
});
/// The run Summary's rows: Pipeline, Stage, Workspace, Content hash, Started,
/// Finished, Duration, Size on disk, Tokens, Cost, Retry of and the Diagnostic
/// block.
///
/// Only values the server actually recorded are rows: a blank field is omitted
/// rather than drawn as an empty or invented placeholder, exactly as
/// `summaryRows` in the web client does. A run with no pipeline id shows its
/// recorded pipeline name, and shows no Pipeline row at all when it recorded
/// neither.
///
/// An executing run with no recorded finish shows its elapsed Duration up to
/// [now]; without [now] it has none.
List<DetailSummaryRow> detailSummaryRows(JsonMap run, {DateTime? now}) {
final rows = <DetailSummaryRow>[];
void add(
String label,
String? value, {
bool monospace = false,
bool block = false,
}) {
final text = value?.trim() ?? '';
if (text.isEmpty) return;
rows.add((label: label, value: text, monospace: monospace, block: block));
}
final pipelineId = _number(run['pipeline_id'])?.toInt() ?? 0;
if (pipelineId > 0) {
final version = _number(run['version'])?.toInt() ?? 0;
add('Pipeline', 'id $pipelineId · v$version');
} else {
add('Pipeline', _text(run['name']));
}
add('Stage', _text(run['current_stage']));
add('Workspace', _text(run['workspace']));
add('Content hash', _text(run['content_hash']), monospace: true);
add('Started', formatLocalTimestamp(_text(run['created_at'])));
add('Finished', formatLocalTimestamp(_text(run['finished_at'])));
final since = detailRunningSince(run);
final seconds = since != null
? now?.difference(since).inSeconds
: durationSeconds(_text(run['created_at']), _text(run['finished_at']));
if (seconds != null) add('Duration', formatDuration(seconds));
// What the run occupies on disk and what it spent, as the server measured
// and the harness reported; an unmeasured size or unreported usage has no
// row.
final bytes = runSizeBytes(run);
if (bytes != null) add('Size on disk', formatByteSize(bytes));
final usage = runTokenUsage(run);
if (usage != null) {
add('Tokens', tokenUsageDetail(usage));
add('Cost', tokenUsageCost(usage));
}
final retryOf = _number(run['retry_of'])?.toInt() ?? 0;
if (retryOf > 0) add('Retry of', 'run $retryOf');
// A diagnostic is a recorded document: its own whitespace is preserved, but a
// blank one is not a row.
final diagnostic = '${run['diagnostic'] ?? ''}';
if (diagnostic.trim().isNotEmpty) {
rows.add((
label: 'Diagnostic',
value: diagnostic,
monospace: false,
block: true,
));
}
return rows;
}
/// The run's identity line: `run {id} · {n} recorded visits · {m} completed
/// visits`, the same recorded/completed vocabulary the web summary and the
/// server use.
String detailSummaryIdentity(JsonMap run) {
final recorded = detailRunSteps(run).length;
final completedValue = _number(run['completed_steps'])?.toInt() ?? 0;
final completed = completedValue < 0 ? 0 : completedValue;
String visits(int count, String adjective) =>
'$count $adjective ${count == 1 ? 'visit' : 'visits'}';
return 'run ${run['id'] ?? ''} · ${visits(recorded, 'recorded')} · '
'${visits(completed, 'completed')}';
}
/// When the run started, while it is executing and has no recorded finish;
/// null otherwise, so its Duration is the recorded one (or none).
DateTime? detailRunningSince(JsonMap run) {
if (run['executing'] != true || _text(run['finished_at']) != null) {
return null;
}
return parseInstant(_text(run['created_at']));
}
String? _text(dynamic value) {
if (value == null) return null;
final text = '$value'.trim();
return text.isEmpty ? null : text;
}
num? _number(dynamic value) =>
value is num ? value : num.tryParse('${value ?? ''}'.trim());