Merge branch 'main' into worktree-agent-aab11f4f1fe3dff6b

# Conflicts:
#	app/test/features/runs/ui/run_list_row_test.dart
This commit is contained in:
2026-10-31 12:36:49 +00:00
29 changed files with 266 additions and 225 deletions
@@ -152,7 +152,8 @@ String fileChangesSummary(ChangeCapture capture) {
var text = capture.status;
if (capture.files.isNotEmpty) {
if (text.isNotEmpty) text += ' ';
text += '(${capture.files.length} files)';
final count = capture.files.length;
text += '($count ${count == 1 ? 'file' : 'files'})';
}
if (capture.skipped > 0) {
if (text.isNotEmpty) text += ', ';
@@ -45,7 +45,6 @@ class StageCaptureSection extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(stage.stage, style: Theme.of(context).textTheme.titleMedium),
Text(meta, style: Theme.of(context).textTheme.bodySmall),
if (capture != null) ...[
Text(
@@ -1,4 +1,5 @@
import '../../../../core/api_gateway.dart';
import '../../../../ui/text/relative_time.dart';
import '../../domain/chat_sessions.dart';
/// Titles shared by more than one visible session, so row action labels can
@@ -20,24 +21,15 @@ String sessionActionsLabel(JsonMap session, Set<String> duplicateTitles) {
: 'Chat actions for $title';
}
/// The web row's relative recency: `just now`, `N min ago`, `N hr ago`,
/// `N days ago`, then a short date (`22 Oct`). A row without a usable
/// `updated_at` reports nothing rather than inventing a time.
/// The shared list-row recency, or nothing for an unusable `updated_at`.
String relativeChatSessionTime(Object? updatedAt, {DateTime? now}) {
final millis = chatSessionMillis(updatedAt);
if (millis <= 0) return '';
final then = DateTime.fromMillisecondsSinceEpoch(millis);
var elapsed = (now ?? DateTime.now()).difference(then);
if (elapsed.isNegative) elapsed = Duration.zero;
final seconds = elapsed.inSeconds;
if (seconds < 45) return 'just now';
final minutes = seconds ~/ 60 < 1 ? 1 : seconds ~/ 60;
if (minutes < 60) return '$minutes min ago';
final hours = minutes ~/ 60;
if (hours < 24) return '$hours hr ago';
final days = hours ~/ 24;
if (days < 7) return days == 1 ? '1 day ago' : '$days days ago';
return '${then.day} ${_shortMonths[then.month - 1]}';
return formatRelativeTime(
DateTime.fromMillisecondsSinceEpoch(millis),
now: now,
) ??
'';
}
/// The row's one muted line: the recorded model and the folder (home as `~`).
@@ -60,20 +52,3 @@ String? chatSessionRowStatus(JsonMap session, {required bool unseen}) {
}
return unseen ? 'New' : null;
}
const _shortMonths = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
// `Intl.DateTimeFormat('en-GB', { month: 'short' })`, which the web row
// uses, abbreviates September as `Sept`, not `Sep`.
'Sept',
'Oct',
'Nov',
'Dec',
];
@@ -38,12 +38,13 @@ String? formatLocalTimestamp(String? text) {
return '${local.day} ${_monthNames[local.month - 1]} $hour:$minute';
}
/// `45s`, `2m 5s`, `1h 2m`. Negative values clamp to `0s`.
/// `45s`, `2m 5s`, `1h 2m`, `9d 16h`. Negative values clamp to `0s`.
String formatDuration(int totalSeconds) {
final seconds = totalSeconds < 0 ? 0 : totalSeconds;
if (seconds < 60) return '${seconds}s';
if (seconds < 3600) return '${seconds ~/ 60}m ${seconds % 60}s';
return '${seconds ~/ 3600}h ${(seconds % 3600) ~/ 60}m';
if (seconds < 86400) return '${seconds ~/ 3600}h ${(seconds % 3600) ~/ 60}m';
return '${seconds ~/ 86400}d ${(seconds % 86400) ~/ 3600}h';
}
/// Whole non-negative seconds between two timestamps, or null when either is
@@ -56,18 +57,6 @@ int? durationSeconds(String? start, String? end) {
return seconds >= 0 ? seconds : null;
}
/// `just now`, `Nm ago`, `Nh ago`, `Nd ago`; a future timestamp reads as
/// `just now`, never a negative age.
String? formatRanAgo(String? createdAt, DateTime now) {
final start = parseInstant(createdAt);
if (start == null) return null;
final seconds = now.difference(start).inSeconds;
if (seconds < 60) return 'just now';
if (seconds < 3600) return '${seconds ~/ 60}m ago';
if (seconds < 86400) return '${seconds ~/ 3600}h ago';
return '${seconds ~/ 86400}d ago';
}
/// `1 stage` / `n stages`.
String stageCountText(int count) => '$count ${count == 1 ? 'stage' : 'stages'}';
@@ -1,4 +1,5 @@
import 'pipeline_format.dart';
import '../../ui/text/relative_time.dart';
import 'pipeline_models.dart';
export 'pipeline_filter.dart';
@@ -27,7 +28,7 @@ class RunBadge {
final String? ranAgo;
final String? duration;
/// `2h ago · 1m 5s · run 42`; missing fragments are omitted.
/// `2h · 1m 5s · run 42`; missing fragments are omitted.
String get metaLine => [
ranAgo,
duration,
@@ -42,7 +43,7 @@ RunBadge runBadge(PipelineRun run, DateTime now) {
return RunBadge(
runId: run.id,
state: runStateOf(run.status),
ranAgo: formatRanAgo(run.createdAt, now),
ranAgo: formatRelativeTimestamp(run.createdAt, now: now),
duration: duration,
);
}
@@ -16,6 +16,7 @@ typedef DetailMetric = ({String label, String value});
typedef DetailVisit = ({
String stage,
int? sequence,
int visit,
String title,
String subtitle,
String status,
@@ -114,22 +115,42 @@ List<DetailMetric> detailUsageMetrics(dynamic raw) {
/// Every recorded visit with its server sequence, in recorded order.
List<DetailVisit> detailTimeline(dynamic steps) {
if (steps is! List) return const [];
final records = steps.whereType<Map>().toList(growable: false);
final ordered = List<int>.generate(records.length, (index) => index)
..sort((a, b) {
final bySequence = (_int(records[a]['sequence']) ?? 0).compareTo(
_int(records[b]['sequence']) ?? 0,
);
return bySequence != 0 ? bySequence : a.compareTo(b);
});
final positions = <String, int>{};
final visits = <int, int>{};
for (final index in ordered) {
final stage = '${records[index]['stage'] ?? ''}'.trim();
final position = (positions[stage] ?? 0) + 1;
positions[stage] = position;
visits[index] = _displayVisit(records[index], position);
}
return [
for (final step in steps.whereType<Map>())
(
stage: '${step['stage'] ?? ''}'.trim(),
sequence: step['sequence'] is num
? (step['sequence'] as num).toInt()
: null,
title:
'${_text(step['stage'], 'Stage unavailable')} · visit '
'${step['sequence'] is num ? (step['sequence'] as num).toInt() : 'unavailable'}',
subtitle: _visitSubtitle(step),
status: '${step['status'] ?? ''}'.trim(),
outcome: '${step['outcome'] ?? ''}'.trim(),
target: '${step['target'] ?? ''}'.trim(),
duration: _visitDuration(step),
),
for (var index = 0; index < records.length; index += 1)
() {
final step = records[index];
final stage = '${step['stage'] ?? ''}'.trim();
final visit = visits[index]!;
return (
stage: stage,
sequence: step['sequence'] is num
? (step['sequence'] as num).toInt()
: null,
visit: visit,
title: '${_text(step['stage'], 'Stage unavailable')} · Visit $visit',
subtitle: _visitSubtitle(step),
status: '${step['status'] ?? ''}'.trim(),
outcome: '${step['outcome'] ?? ''}'.trim(),
target: '${step['target'] ?? ''}'.trim(),
duration: _visitDuration(step),
);
}(),
];
}
@@ -166,6 +187,15 @@ String _visitSubtitle(Map step) {
].join(' · ');
}
/// The stage's own recorded visit number, falling back to its position among
/// visits to that stage rather than the run-wide step sequence.
int _displayVisit(Map step, int position) {
final control = step['control'];
final recorded = control is Map ? control['visit'] : null;
if (recorded is num && recorded > 0) return recorded.toInt();
return position;
}
/// The web's `stepDuration`: finished minus started, when both are recorded.
String? _visitDuration(Map step) {
final started = DateTime.tryParse('${step['started_at'] ?? ''}');
@@ -90,13 +90,13 @@ class _RunVisitPaneState extends State<RunVisitPane> {
}
}
/// The page bar's subtitle for a recorded visit: its sequence, then the run
/// The page bar's subtitle for a recorded visit: its per-stage visit, then the run
/// it belongs to (`Visit 2 · Run 7 · Nightly report`).
String runVisitSubtitle(JsonMap run, DetailVisit visit) {
final runId = '${run['id'] ?? ''}'.trim();
final title = detailTitle(run);
return [
if (visit.sequence != null) 'Visit ${visit.sequence}',
'Visit ${visit.visit}',
if (runId.isNotEmpty) 'Run $runId',
if (title.isNotEmpty && title != 'Run $runId') title,
].join(' · ');
+2 -2
View File
@@ -13,7 +13,7 @@ import '../../attention/notify/notification_controller.dart';
import '../../attention/runtime/attention_controller.dart';
import '../../attention/runtime/attention_store.dart';
import '../../attention/ui/needs_you_runs_heading.dart';
import '../../pipelines/pipeline_format.dart' show formatRanAgo;
import '../../../ui/text/relative_time.dart';
import '../domain/run_models.dart';
import '../../../shell/shell_bar.dart';
import 'run_more_menu.dart';
@@ -354,7 +354,7 @@ class RunListRow extends StatelessWidget {
child: RunStatusIcon(state: state, label: runStatusLabel(run)),
),
title: Text(title),
time: formatRanAgo('${run['created_at'] ?? ''}', now),
time: formatRelativeTimestamp('${run['created_at'] ?? ''}', now: now),
subtitle: Text(subtitle),
compactSubtitle: Text(compactSubtitle),
// A narrow list pane beside the open run leaves the row no room for a
@@ -1,4 +1,5 @@
import '../../domain/saved_schedule.dart';
import '../../../../ui/text/relative_time.dart';
/// User-facing values for one saved schedule row.
///
@@ -91,31 +92,12 @@ String scheduleCountLabel(int visible, int total) {
return total == 1 ? '1 schedule' : '$total schedules';
}
/// A row's short next-run word for its title line: `Paused`, `Not
/// scheduled`, `Next time unavailable`, or the local time as `22 Oct 09:00`.
String scheduleNextDueShort(SavedSchedule schedule) {
/// A row's compact next-run label, using the shared relative-time vocabulary.
String scheduleNextDueShort(SavedSchedule schedule, {DateTime? now}) {
if (!schedule.enabled) return 'Paused';
final value = schedule.nextDue;
if (value.isEmpty) return 'Not scheduled';
final date = DateTime.tryParse(value);
if (date == null) return 'Next time unavailable';
final local = date.toLocal();
String two(int part) => part.toString().padLeft(2, '0');
return '${local.day} ${_shortMonths[local.month - 1]} '
'${two(local.hour)}:${two(local.minute)}';
return formatRelativeTime(date, now: now) ?? 'Next time unavailable';
}
const _shortMonths = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec',
];
+8 -14
View File
@@ -1,4 +1,5 @@
import '../../../core/api_gateway.dart';
import '../../../ui/text/relative_time.dart';
import 'search_format.dart';
export 'search_format.dart' show humanBytes, formatSearchTimestamp;
@@ -47,7 +48,7 @@ SearchRowView searchRowView(JsonMap hit, String query) {
final field = _map(hit['field']);
final artifact = _map(hit['artifact']);
final recency = formatSearchTimestamp('${hit['recency'] ?? ''}');
final recency = formatRelativeTimestamp('${hit['recency'] ?? ''}');
final target = _serverTarget(hit);
if (pipeline != null) {
@@ -68,10 +69,7 @@ SearchRowView searchRowView(JsonMap hit, String query) {
title:
'pipeline ${_num(version['pipeline_id'])}'
' · v${_num(version['version'])}',
secondary: _join([
hash == null ? null : 'content $hash',
formatSearchTimestamp('${version['created_at'] ?? ''}'),
]),
secondary: hash == null ? '' : 'content $hash',
kindLabel: 'Pipeline version',
snippetSpans: const [],
recency: recency,
@@ -81,12 +79,8 @@ SearchRowView searchRowView(JsonMap hit, String query) {
if (run != null) {
final name = _nonBlank(run['pipeline_name']);
return SearchRowView(
title: 'run #${_num(run['id'])}${name == null ? '' : ' · $name'}',
secondary: _join([
_nonBlank(run['status']),
_nonBlank(run['workspace']),
formatSearchTimestamp('${run['created_at'] ?? ''}'),
]),
title: 'Run ${_num(run['id'])}${name == null ? '' : ' · $name'}',
secondary: _join([_nonBlank(run['status']), _nonBlank(run['workspace'])]),
kindLabel: 'Run',
snippetSpans: const [],
recency: recency,
@@ -97,7 +91,7 @@ SearchRowView searchRowView(JsonMap hit, String query) {
final stage = _nonBlank(step['stage']) ?? 'step';
return SearchRowView(
title:
'run #${_num(step['run_id'])} · $stage'
'Run ${_num(step['run_id'])} · $stage'
' visit ${_num(step['visit'])}',
secondary: _stepSecondary(step),
kindLabel: 'Step',
@@ -110,7 +104,7 @@ SearchRowView searchRowView(JsonMap hit, String query) {
final snippet = '${field['snippet'] ?? ''}';
return SearchRowView(
title:
'run #${_num(field['run_id'])} · step ${_num(field['sequence'])}'
'Run ${_num(field['run_id'])} · step ${_num(field['sequence'])}'
' · ${_nonBlank(field['field']) ?? 'field'}',
secondary: snippet,
kindLabel: 'Field',
@@ -124,7 +118,7 @@ SearchRowView searchRowView(JsonMap hit, String query) {
return SearchRowView(
title: _nonBlank(artifact['name']) ?? 'artifact',
secondary: _join([
'run #${_num(artifact['run_id'])}',
'Run ${_num(artifact['run_id'])}',
'step ${_num(artifact['sequence'])}',
_nonBlank(artifact['content_type']),
humanBytes(_num(artifact['size_bytes'])),
+40
View File
@@ -0,0 +1,40 @@
const _monthNames = <String>[
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec',
];
/// A compact local recency label for list rows.
///
/// Past instants use `just now`, `Nm`, `Nh`, or `Nd` for their first week,
/// then a short local date. Future instants use the same compact units with an
/// `in` prefix, which keeps scheduled rows truthful.
String? formatRelativeTime(DateTime? instant, {DateTime? now}) {
if (instant == null) return null;
final current = now ?? DateTime.now();
final seconds = instant.difference(current).inSeconds;
final future = seconds > 0;
final age = seconds.abs();
if (age < 60) return 'just now';
final prefix = future ? 'in ' : '';
if (age < 3600) return '$prefix${age ~/ 60}m';
if (age < 86400) return '$prefix${age ~/ 3600}h';
if (age < 7 * 86400) return '$prefix${age ~/ 86400}d';
final local = instant.toLocal();
return '${local.day} ${_monthNames[local.month - 1]}';
}
/// Parses [text] as an RFC3339 timestamp before formatting it for a list row.
String? formatRelativeTimestamp(String? text, {DateTime? now}) {
final value = text?.trim() ?? '';
return formatRelativeTime(DateTime.tryParse(value), now: now);
}