Files
pipelines/app/lib/features/runs/ui/runs_list.dart
T
alan e72bee3faa First run: empty states with a next step, harness setup instead of errors
- One shared EmptyState (icon on a tonal disc, title, one line, primary
  action) that follows the design tokens; used by Runs (Start your first
  run), Pipelines (Browse templates), Schedules and the chat list (Start a
  chat).
- Chat on a server without an agent harness showed "Bad state: No saved
  machine is connected.": the federated list now keeps the server's own
  refusal, treats an omitted empty list as no chats, and the list shows a
  "Set up an agent" state with the harness setup command and Refresh. New
  chat shows the same step instead of a form that can only be refused.
- A run that fails because no harness CLI exists names the setup command
  beside the raw reason; error advice gains a noHarness kind.
- Templates opened before the app connected stayed on "Not connected";
  it now reads again when the connection arrives. The Pipelines empty state
  links to Templates, which had no entry point in the UI.
- The first-launch walkthrough waits briefly for the connection, so a
  connected web app is no longer told to connect; the empty-server check
  treats omitted lists and no chat harness as empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 23:29:23 +00:00

394 lines
13 KiB
Dart

import '../../../ui/motion/motion.dart';
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../../ui/adaptive/floating_bar_layout.dart';
import '../../../ui/layout/memo_subtree.dart';
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 '../domain/run_models.dart';
import '../domain/run_tab_counts.dart';
import '../../../shell/shell_bar.dart';
import '../../../shell/shell_list_shortcuts.dart';
import 'run_list_row.dart';
import 'runs_controller.dart';
import 'runs_filter_options.dart';
import 'runs_selection_bar.dart';
import 'runs_stats_page.dart';
import 'runs_filters.dart';
import '../../../ui/status/empty_state.dart';
import '../../../ui/status/error_notice.dart';
export 'run_list_row.dart';
/// The state a server with no runs at all shows.
const runsEmptyKey = ValueKey<String>('runs-empty');
class RunsList extends StatelessWidget {
const RunsList({
super.key,
required this.controller,
required this.onSelected,
this.syncToken = 0,
this.attentionStore = const SharedPreferencesAttentionStore(),
this.attentionNow,
this.notifications,
this.attention,
this.active = true,
this.onOpenInChat,
this.onRunAgain,
this.onNewRun,
});
/// Starts a new run; the empty list offers it as its next step.
final VoidCallback? onNewRun;
/// False while a run detail covers the list; the bar is then the run's.
final bool active;
final Future<void> Function(BuildContext, JsonMap)? onOpenInChat;
/// Opens the New run form pre-filled from a finished run.
final ValueChanged<JsonMap>? onRunAgain;
final RunsController controller;
final ValueChanged<num> onSelected;
/// Advances when the shared socket is replaced, so the attention detector
/// rebaselines instead of replaying a transition from before the gap.
final int syncToken;
/// Test and fixture seam for the persisted attention dismissals.
final AttentionStore attentionStore;
/// Deterministic local-day clock for the attention window.
final DateTime Function()? attentionNow;
/// App-level notification delivery; absent in list-only fixtures.
final NotificationController? notifications;
/// The app's shared attention controller; absent in list-only fixtures.
final AttentionController? attention;
@override
Widget build(BuildContext context) {
// Select mode replaces the bar: `N selected` and its size, Delete, Done.
if (controller.selection.active) {
final bar = runsSelectionBar(context, controller);
if (!ShellBar.available(context)) {
return _ownBar(context, [
Expanded(
child: Text(
[bar.title, ?bar.subtitle].join(' · '),
key: runsSelectionCountKey,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
...bar.actions,
]);
}
return ShellBar(
active: active,
title: bar.title,
subtitle: bar.subtitle,
actions: bar.actions,
child: _shortcutList(context),
);
}
final actions = [
// The Needs-you bell sits with the other actions, freeing the row.
NeedsYouRunsHeading(
rows: controller.runs,
frames: controller.repository.gateway.frames,
onOpen: (entry) => onSelected(entry.runId),
syncToken: syncToken,
store: attentionStore,
now: attentionNow,
notifications: notifications,
attention: attention,
),
...RunsBarActions(
controller,
).build(context, onStats: () => openRunsStats(context, controller)),
if (controller.runs.isNotEmpty) runsSelectAction(context, controller),
];
// Outside the app shell (the list on its own) the actions head the list.
if (!ShellBar.available(context)) {
return _ownBar(context, [const Spacer(), ...actions]);
}
return ShellBar(
active: active,
actions: actions,
// The Runs tab counts runs still executing.
child: ShellBadge(
kind: ShellBadgeKind.running,
count: runningRunCount(controller.runs),
child: _shortcutList(context),
),
);
}
/// The list under the shell's Ctrl+1…Ctrl+9, which open the Nth run shown
/// (filtered and sorted as on screen). Select mode keeps keys for itself.
Widget _shortcutList(BuildContext context) => ShellListShortcut(
onOpenIndex: (index) {
if (controller.selection.active) return false;
final runs = controller.visibleRuns;
if (index >= runs.length) return false;
final id = runs[index]['id'];
if (id is! num) return false;
onSelected(id);
return true;
},
child: _list(context),
);
Widget _ownBar(BuildContext context, List<Widget> bar) => Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 8, 0),
child: Row(children: bar),
),
Expanded(child: _list(context)),
],
);
Widget _list(BuildContext context) {
if (controller.loading && controller.runs.isEmpty) {
return _state(
context,
icon: const CircularProgressIndicator(),
title: 'Loading runs…',
);
}
if (controller.error != null && controller.runs.isEmpty) {
return _emptyError(context);
}
// The notice and the applied filters lead the list, so they scroll
// behind the top bar with the runs and start below it at rest.
final header = [
if (controller.error != null) _inlineError(context),
if (controller.selection.report != null)
RunsDeleteReport(controller: controller),
RunsFilters(controller: controller),
];
// Filtered and sorted once per build: the getter recomputes every read.
final visible = controller.visibleRuns;
if (visible.isNotEmpty) return _groupedRuns(context, header, visible);
// A server with no runs at all is not a filter problem: say what the list
// is for and where its first run comes from. A free-text query counts as
// a filter too, so a search on an empty server reads as "nothing found".
final noRunsAtAll =
controller.runs.isEmpty &&
controller.activeFilterCount == 0 &&
controller.query.trim().isEmpty;
return BelowTopBar(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
...header,
Expanded(
child: noRunsAtAll
? EmptyState(
key: runsEmptyKey,
dense: true,
icon: Icons.play_circle_outline,
title: 'No runs yet',
message:
'A run is a pipeline working on one task. Start one '
'and follow its progress and results here.',
action: onNewRun == null
? null
: emptyStateAction(
'Start your first run',
onNewRun!,
icon: Icons.add,
),
)
: _state(
context,
icon: const Icon(Icons.inbox_outlined),
title: 'No runs found.',
subtitle: 'Try changing or clearing the filters.',
),
),
],
),
);
}
Widget _groupedRuns(
BuildContext context,
List<Widget> header,
List<JsonMap> visible,
) {
final entries = <_Entry>[];
if (flatRunSorts.contains(controller.sort)) {
// An order by size is one flat list: day headings would split it.
entries.addAll(visible.map((run) => (day: null, run: run)));
} else {
final groups = groupRunsByDay(visible, DateTime.now());
for (final group in groups) {
entries.add((day: group, run: null));
entries.addAll(group.runs.map((run) => (day: null, run: run)));
}
}
// Runs that start while the list is open enter with a short fade.
return ArrivalScope(
ids: [for (final run in visible) '${run['id']}'],
child: _entriesList(entries, header),
);
}
Widget _entriesList(List<_Entry> entries, List<Widget> header) {
// The default padding is the media padding: the first row starts below
// the top bar and the last clears the floating tab bar.
return ListView.builder(
itemCount: header.length + entries.length,
itemBuilder: (context, index) {
if (index < header.length) return header[index];
final entry = entries[index - header.length];
if (entry.day case final day?) {
// A day heading reads as a divider between groups of runs.
return RunsDayHeading(
label: day.label,
runs: day.runs,
controller: controller,
);
}
// The last run of a day (before the next heading) has no divider.
final next = index - header.length + 1;
final last = next >= entries.length || entries[next].run == null;
return Arrival(
id: '${entry.run!['id']}',
child: _runTile(
context,
entry.run!,
divider: !last,
timeOfDay: !flatRunSorts.contains(controller.sort),
),
);
},
);
}
Widget _emptyError(BuildContext context) => Center(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.error_outline),
const SizedBox(height: 8),
ErrorNotice(error: controller.error!, textAlign: TextAlign.center),
const SizedBox(height: 8),
FilledButton(onPressed: controller.load, child: const Text('Retry')),
],
),
),
);
Widget _state(
BuildContext context, {
required Widget icon,
required String title,
String? subtitle,
}) => Center(
// A short pane (a list beside a detail, or the keyboard up) scrolls the
// state instead of overflowing it.
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
icon,
const SizedBox(height: 12),
Text(title, textAlign: TextAlign.center),
if (subtitle != null) ...[
const SizedBox(height: 4),
Text(
subtitle,
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
],
),
),
);
Widget _inlineError(BuildContext context) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
children: [
Expanded(child: ErrorNotice(error: controller.error!)),
TextButton(onPressed: controller.load, child: const Text('Retry')),
],
),
);
Widget _runTile(
BuildContext context,
JsonMap run, {
bool divider = true,
bool timeOfDay = false,
}) {
final id = run['id'];
final selection = controller.selection;
final now = DateTime.now();
// A run event for one run rebuilds only that run's row: the others keep
// their built subtree (their menu, ripple and tooltip included).
return MemoSubtree(
memo: (
MemoMap(run),
divider,
timeOfDay,
selection.active,
selection.contains(id),
id == controller.selectedRunId,
controller,
onSelected,
// An executing run's duration ticks inside the row, not from here.
),
builder: (context) =>
_runRow(run, id, now, divider: divider, timeOfDay: timeOfDay),
);
}
Widget _runRow(
JsonMap run,
Object? id,
DateTime now, {
bool divider = true,
bool timeOfDay = false,
}) {
final selection = controller.selection;
return RunListRow(
selecting: selection.active,
checked: selection.contains(id),
onToggle: () => selection.toggle(run),
// A long-press enters select mode with this run selected.
onLongPress: () => selection.enter(run),
onDeleted: controller.applyDeletion,
run: run,
divider: divider,
timeOfDay: timeOfDay,
selected: id == controller.selectedRunId,
now: now,
onTap: id is num ? () => onSelected(id) : null,
gateway: controller.repository.gateway,
onRunChanged: controller.acceptRunDetail,
onRunOpened: onSelected,
onOpenInChat: onOpenInChat,
onRunAgain: onRunAgain,
);
}
}
typedef _Entry = ({({String label, List<JsonMap> runs})? day, JsonMap? run});