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>
This commit is contained in:
2026-12-03 23:29:23 +00:00
parent 9436067bf2
commit e72bee3faa
30 changed files with 696 additions and 111 deletions
+1
View File
@@ -1215,6 +1215,7 @@ class _PipelinesAppState extends State<PipelinesApp>
onViewPipelineRuns: (id) =>
_delegate.goTo(AppRoute.runsForPipeline(id)),
onOpenSchedules: _delegate.openSchedules,
onOpenTemplates: _delegate.openTemplates,
onOpenSettings: () => _delegate.goTo(AppRoute.settings),
onOpenInChat: (context, detail, run) =>
_openPipelineInChat(context, detail, run),
@@ -24,6 +24,7 @@ class PipelinesDestination extends StatelessWidget {
this.onRunStarted,
this.onViewPipelineRuns,
this.onOpenSchedules,
this.onOpenTemplates,
this.onOpenSettings,
this.onSelectionChanged,
this.initialPipelineId,
@@ -50,6 +51,9 @@ class PipelinesDestination extends StatelessWidget {
final ValueChanged<int>? onViewPipelineRuns;
final VoidCallback? onOpenSchedules;
/// Opens the Templates gallery, offered by an empty pipeline list.
final VoidCallback? onOpenTemplates;
/// Opens Settings as a page from the Pipelines bar's gear.
final VoidCallback? onOpenSettings;
final ValueChanged<int?>? onSelectionChanged;
@@ -96,6 +100,7 @@ class PipelinesDestination extends StatelessWidget {
onRunStarted: onRunStarted,
onViewPipelineRuns: onViewPipelineRuns,
onOpenSchedules: onOpenSchedules,
onOpenTemplates: onOpenTemplates,
onOpenSettings: onOpenSettings,
onSelectionChanged: onSelectionChanged,
onOpenInChat: onOpenInChat,
@@ -119,6 +119,7 @@ class _TemplatesDestinationState extends State<TemplatesDestination> {
embedded: true,
onCreated: widget.onCreated,
initialKey: widget.initialKey,
reloadToken: session.connectionEpoch,
),
);
}
+26 -1
View File
@@ -4,7 +4,16 @@ import 'error_reason.dart';
import 'transport/connection_state.dart';
/// The common kinds of failure an operator can act on.
enum ErrorAdviceKind { notConnected, serverTooOld, permission, timeout }
enum ErrorAdviceKind {
notConnected,
serverTooOld,
permission,
timeout,
/// The server has no agent harness to run a chat or a stage with: a setup
/// step on the server, not a failure of this app.
noHarness,
}
/// What to do about a failure, as one sentence, and the raw detail it came
/// from (kept available behind the sentence, never replaced by it).
@@ -29,6 +38,7 @@ ErrorAdviceKind? errorAdviceKind(Object error) {
return ErrorAdviceKind.permission;
}
final text = '$error'.toLowerCase();
if (needsHarnessSetup(text)) return ErrorAdviceKind.noHarness;
if (_tooOld.hasMatch(text)) return ErrorAdviceKind.serverTooOld;
if (_permission.hasMatch(text)) return ErrorAdviceKind.permission;
if (_timeout.hasMatch(text)) return ErrorAdviceKind.timeout;
@@ -49,8 +59,23 @@ String errorAdviceSentence(ErrorAdviceKind kind) => switch (kind) {
ErrorAdviceKind.timeout =>
'The server did not answer in time. Check the connection, then try '
'again.',
ErrorAdviceKind.noHarness =>
'No agent harness is set up on the server yet. In a terminal on the '
'server, run `pipelines harness setup <agent>` (claude, codex, '
'opencode or pi), then try again.',
};
/// Whether [error] says the server has no usable agent harness: chat is not
/// configured, or a stage could not start its harness's CLI. Such a server is
/// new, not broken, so callers show the setup step instead of an error.
bool needsHarnessSetup(Object? error) =>
error != null && _noHarness.hasMatch('$error'.toLowerCase());
final _noHarness = RegExp(
r'chat is not configured|harness unreachable|'
r'cannot run the selected \w+ cli',
);
final _tooOld = RegExp(
r'unknown (command|message|request)|unsupported (command|message|request)',
);
@@ -91,11 +91,18 @@ class FederatedChatGateway implements ApiGateway {
if (type == 'chat_sessions') {
final current = Map.of(sources());
_cached.removeWhere((id, _) => !serverIds.contains(id));
// The first machine's own refusal, kept so a list that no machine
// could read says why (chat not set up there, say) instead of
// claiming that nothing is connected.
Object? firstFailure;
final results = await Future.wait(
current.entries.map((entry) async {
try {
final reply = await entry.value.call(type, fields);
final list = reply['chat_sessions'];
// A server with no chats leaves the empty list out of its reply.
final list =
reply['chat_sessions'] ??
(reply['type'] == 'chat_sessions' ? const <Object?>[] : null);
if (list is! List) {
throw StateError(
'Invalid chat list from ${entry.value.server.name}.',
@@ -110,13 +117,15 @@ class FederatedChatGateway implements ApiGateway {
.map((v) => Map<String, dynamic>.from(v))
.toList();
return true;
} catch (_) {
} catch (error) {
firstFailure ??= error;
return false;
}
}),
);
_cached.removeWhere((id, _) => !serverIds.contains(id));
if (!results.contains(true) && _cached.isEmpty) {
if (firstFailure case final failure?) throw failure;
throw StateError('No saved machine is connected.');
}
return {
@@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
import '../../../../ui/status/empty_state.dart';
import '../../../walkthrough/walkthrough_harness_command.dart';
/// The chat list's state on a server without an agent harness: chat is not
/// configured there yet, which is a setup step rather than an error. It names
/// the step (the setup command for the agent the operator picks, ready to
/// copy) and offers Refresh for after the command has run.
const chatHarnessSetupKey = ValueKey<String>('chat-harness-setup');
class ChatHarnessSetupState extends StatelessWidget {
const ChatHarnessSetupState({super.key, this.onRefresh});
/// Reads the chat list again once the harness is set up.
final VoidCallback? onRefresh;
@override
Widget build(BuildContext context) {
final refresh = onRefresh;
return EmptyState(
key: chatHarnessSetupKey,
dense: true,
icon: Icons.build_circle_outlined,
title: 'Set up an agent to start chatting',
message:
'Chats run on a coding agent on your server, and none is set up '
'yet. Run the setup command for the agent you use in a terminal on '
'the server, then refresh.',
action: refresh == null
? null
: emptyStateAction('Refresh', refresh, icon: Icons.refresh),
child: const WalkthroughHarnessCommand(),
);
}
}
@@ -1,12 +1,18 @@
import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import '../../../../core/error_advice.dart';
import '../../../../ui/status/empty_state.dart';
import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart';
import 'chat_harness_setup_state.dart';
import 'session_list_material.dart';
import 'session_pane_menu.dart';
import 'session_row_style.dart';
/// The chat list's state when the server has no chats yet.
const chatListEmptyKey = ValueKey<String>('chat-list-empty');
typedef ChatSessionSection = ({String title, List<JsonMap> sessions});
/// Which list sections are folded away, kept by the list's screen so the
@@ -52,8 +58,16 @@ class ChatSessionsBody extends StatelessWidget {
this.onDismissError,
this.selectionOnly = false,
this.emptyMessageOverride,
this.onNewChat,
this.onRefresh,
});
/// Starts a chat; an empty list offers it as its next step.
final VoidCallback? onNewChat;
/// Reads the list again; the harness setup state offers it.
final VoidCallback? onRefresh;
/// Reuse list presentation for a picker without mutation menus or gestures.
final bool selectionOnly;
final String? emptyMessageOverride;
@@ -94,6 +108,35 @@ class ChatSessionsBody extends StatelessWidget {
: 'No chats match "${query.trim()}".');
if (loading && sessions.isEmpty) return const ChatLoadingIndicator();
// The list's own first-run states. A picker (selectionOnly or an
// override) keeps its one-line message.
final firstRun =
!selectionOnly &&
emptyMessageOverride == null &&
sessions.isEmpty &&
query.trim().isEmpty;
if (firstRun && needsHarnessSetup(error)) {
return ChatHarnessSetupState(onRefresh: onRefresh);
}
if (firstRun && error == null) {
final start = onNewChat;
return EmptyState(
key: chatListEmptyKey,
dense: true,
icon: Icons.forum_outlined,
title: 'No chats yet',
message:
'Talk with a coding agent on your server. Each chat works in a '
'folder you choose and keeps its history here.',
action: start == null
? null
: emptyStateAction(
'Start a chat',
start,
icon: Icons.add_comment_outlined,
),
);
}
final clearSearch = query.trim().isEmpty ? null : onClearSearch;
final duplicateTitles = duplicateChatTitles(visible);
return MaterialSessionList(
@@ -9,6 +9,7 @@ import 'package:flutter/material.dart';
import '../../../../ui/layout/content_width.dart';
import '../../../../core/api_gateway.dart';
import '../../../../core/error_advice.dart';
import '../../../../shell/shell_bar.dart';
import '../../../../shell/shell_list_shortcuts.dart';
import '../../../terminal/terminal_open_action.dart';
@@ -16,7 +17,9 @@ import '../../data/chat_repository.dart';
import '../../domain/chat_colors.dart';
import '../../domain/chat_cycle.dart';
import '../../domain/chat_sessions.dart';
import '../../../../ui/adaptive/app_popups.dart';
import 'chat_adaptive.dart';
import 'chat_harness_setup_state.dart';
import 'chat_color_picker.dart';
import 'chat_session_local.dart';
import 'chat_sessions_body.dart';
@@ -194,6 +197,20 @@ class ChatSessionsScreenState extends State<ChatSessionsScreen> {
}
Future<void> _newChat({bool chooseMachine = true}) async {
// Without an agent harness the create form could only be refused: show
// the setup step instead, with Refresh to read the list once it is done.
if (needsHarnessSetup(_controller.error)) {
await showAppDetails<void>(
context,
builder: (sheet) => ChatHarnessSetupState(
onRefresh: () {
Navigator.of(sheet).pop();
unawaited(_controller.refresh());
},
),
);
return;
}
final scope = ServerContext.maybeOf(context);
var repository = _controller.repository;
if (chooseMachine && scope != null) {
@@ -241,6 +258,13 @@ class ChatSessionsScreenState extends State<ChatSessionsScreen> {
if (session != null && mounted) widget.onOpen(session);
}
/// The list failure shown above the list. A server without an agent
/// harness is not a failure: the list itself shows that setup step.
String? get _listError {
final error = _controller.error;
return error == null || needsHarnessSetup(error) ? null : error;
}
/// Starts the same machine picker and create dialog used by the list action.
Future<void> newChat() => _newChat();
@@ -316,20 +340,20 @@ class ChatSessionsScreenState extends State<ChatSessionsScreen> {
children: [
// A notice above the list starts below the floating bar; the list
// under it then needs no inset of its own.
if (_controller.error != null)
if (_listError != null)
Padding(
padding: EdgeInsets.only(
top: MediaQuery.paddingOf(context).top,
),
child: ChatErrorNotice(
message: _controller.error!,
message: _listError!,
onRetry: _controller.refresh,
),
),
Expanded(
child: MediaQuery.removePadding(
context: context,
removeTop: _controller.error != null,
removeTop: _listError != null,
child: Stack(
children: [
ContentWidth(
@@ -340,6 +364,8 @@ class ChatSessionsScreenState extends State<ChatSessionsScreen> {
query: _search.text,
loading: _controller.loading,
error: _controller.error,
onNewChat: _newChat,
onRefresh: _controller.refresh,
onOpen: _open,
onOpenBeside: widget.onOpenBeside == null
? null
@@ -157,8 +157,11 @@ PipelineEmptyState? pipelineListEmptyState(
if (items.isNotEmpty) return null;
if (all.isEmpty) {
return const PipelineEmptyState(
'No pipelines yet.',
detail: 'Create one from a template in Templates.',
'No pipelines yet',
detail:
'A pipeline is a workflow you define once and run on many tasks. '
'Start from a template, or create one with `pipelines new` on the '
'server.',
);
}
final name = filters.name;
+6
View File
@@ -40,6 +40,7 @@ class PipelinesScreen extends StatefulWidget {
this.onViewPipelineRuns,
this.onSelectionChanged,
this.onOpenSchedules,
this.onOpenTemplates,
this.onOpenSettings,
this.initialPipelineId,
this.initialVersion = 0,
@@ -77,6 +78,9 @@ class PipelinesScreen extends StatefulWidget {
/// Opens every schedule; shown in the bar while the list is visible.
final VoidCallback? onOpenSchedules;
/// Opens the Templates gallery from the empty list.
final VoidCallback? onOpenTemplates;
/// Opens Settings as a page; a gear in the bar while the list is visible.
final VoidCallback? onOpenSettings;
@@ -278,6 +282,7 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
controller: _controller,
onOpenInChat: widget.onOpenPipelineInChat,
onRun: _runFromList,
onOpenTemplates: widget.onOpenTemplates,
),
);
}
@@ -287,6 +292,7 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
controller: _controller,
onOpenInChat: widget.onOpenPipelineInChat,
onRun: _runFromList,
onOpenTemplates: widget.onOpenTemplates,
),
),
detailIdentity: _controller.selectedId,
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import '../../../shell/shell_list_shortcuts.dart';
import '../../../ui/adaptive/floating_bar_layout.dart';
import '../../../ui/adaptive/segmented_bar_overflow.dart';
import '../../../ui/status/empty_state.dart';
import '../../../ui/status/run_status_icon.dart';
import '../pipeline_format.dart';
import '../pipeline_models.dart';
@@ -22,14 +23,21 @@ import 'pipeline_row_actions.dart';
const double kPipelineListInset = 12;
/// The left/top pane: filter and sort controls, then the truthful list states.
/// The state a server without any pipeline shows.
const pipelinesEmptyKey = ValueKey<String>('pipelines-empty');
class PipelineListPanel extends StatelessWidget {
const PipelineListPanel({
super.key,
required this.controller,
this.onOpenInChat,
this.onRun,
this.onOpenTemplates,
});
/// Opens the Templates gallery; an empty server offers it as the next step.
final VoidCallback? onOpenTemplates;
final PipelinesController controller;
final Future<void> Function(BuildContext, PipelineSummary, PipelineRun?)?
onOpenInChat;
@@ -194,34 +202,31 @@ class PipelineListPanel extends StatelessWidget {
}
Widget _empty(BuildContext context, PipelineEmptyState empty) {
return Center(
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
empty.message,
textAlign: TextAlign.center,
style: _mutedStyle(context),
// A filter that hides every row is not an empty server: name it and
// offer the way back.
if (empty.clearAction case final clear?) {
return EmptyState(
dense: true,
icon: Icons.filter_alt_off_outlined,
title: empty.message,
message: empty.detail,
action: emptyStateAction(clear, controller.clearFilters),
);
}
final templates = onOpenTemplates;
return EmptyState(
key: pipelinesEmptyKey,
dense: true,
icon: Icons.account_tree_outlined,
title: empty.message,
message: empty.detail,
action: templates == null
? null
: emptyStateAction(
'Browse templates',
templates,
icon: Icons.library_add_outlined,
),
if (empty.detail != null)
Padding(
padding: const EdgeInsets.only(top: 4),
child: Text(
empty.detail!,
textAlign: TextAlign.center,
style: _mutedStyle(context),
),
),
if (empty.clearAction != null)
PipelineTextButton(
label: empty.clearAction!,
onPressed: controller.clearFilters,
),
],
),
),
);
}
@@ -339,13 +344,6 @@ class PipelineListPanel extends StatelessWidget {
].join(' · ');
}
TextStyle? _mutedStyle(BuildContext context) {
final theme = Theme.of(context);
return theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
);
}
/// The pipeline's initial on a tint picked from its id, so neighbouring
/// pipelines are told apart at a glance.
Widget _pipelineIdentityIcon(BuildContext context, PipelineSummary pipeline) {
+1
View File
@@ -377,6 +377,7 @@ class _RunsScreenState extends State<RunsScreen> {
attention: widget.attention,
onOpenInChat: widget.onOpenInChat,
onRunAgain: _runAgain,
onNewRun: _startNewRun,
),
),
);
@@ -1,9 +1,13 @@
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../../core/error_advice.dart';
import '../domain/run_outcome_line.dart';
import '../../../ui/theme/app_design_tokens.dart';
/// The setup step a run that failed for want of an agent harness shows.
const runFailureHarnessHintKey = ValueKey<String>('run-failure-harness-hint');
/// The run Summary's prominent "Why it failed" note: a failed run's recorded
/// failure reason (else its diagnostic), selectable, at the top of the
/// Summary so the reason is read before the facts. Nothing for other runs.
@@ -61,6 +65,19 @@ class RunFailureBanner extends StatelessWidget {
color: scheme.onErrorContainer,
),
),
// A server without an agent harness is a setup step:
// say which, beside the raw reason.
if (needsHarnessSetup(outcome.full)) ...[
const SizedBox(height: 8),
Text(
errorAdviceSentence(ErrorAdviceKind.noHarness),
key: runFailureHarnessHintKey,
style: theme.textTheme.bodyMedium?.copyWith(
color: scheme.onErrorContainer,
fontWeight: FontWeight.w600,
),
),
],
if (actions case final actions?) ...[
const SizedBox(height: 8),
actions,
+23 -6
View File
@@ -18,10 +18,14 @@ 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,
@@ -35,8 +39,12 @@ class RunsList extends StatelessWidget {
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;
@@ -184,12 +192,21 @@ class RunsList extends StatelessWidget {
...header,
Expanded(
child: noRunsAtAll
? _state(
context,
icon: const Icon(Icons.inbox_outlined),
title: 'No runs yet.',
subtitle:
'Start one from Pipelines and its runs appear here.',
? 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,
@@ -7,9 +7,13 @@ import '../../domain/saved_schedule.dart';
import 'schedule_list_controller.dart';
import 'schedule_list_row.dart';
import 'schedule_list_toolbar.dart';
import '../../../../ui/status/empty_state.dart';
import '../../../../ui/status/error_notice.dart';
const scheduleListKey = ValueKey<String>('schedule-list');
/// The state a server without any saved schedule shows.
const schedulesEmptyKey = ValueKey<String>('schedules-empty');
const scheduleRetryKey = ValueKey<String>('schedule-retry');
const scheduleToolbarKey = ValueKey<String>('schedule-toolbar');
@@ -75,9 +79,13 @@ class SchedulesListView extends StatelessWidget {
}
if (controller.schedules.isEmpty) {
return BelowTopBar(
child: _emptyState(
'No schedules yet.',
detail: 'Saved run configurations, not pipeline definitions.',
child: const EmptyState(
key: schedulesEmptyKey,
icon: Icons.event_repeat_outlined,
title: 'No schedules yet',
message:
'A schedule runs a pipeline for you on a timetable. Open a '
"pipeline's Run form and choose Schedule… to add one.",
),
);
}
@@ -140,29 +148,8 @@ class SchedulesListView extends StatelessWidget {
);
}
Widget _emptyState(String message, {String? detail}) {
return Center(
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(message, textAlign: TextAlign.center),
if (detail != null)
Builder(
builder: (context) => Text(
detail,
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
),
],
),
),
);
}
Widget _emptyState(String message) =>
EmptyState(icon: Icons.search_off_outlined, title: message, dense: true);
Widget _failureState(BuildContext context, ScheduleListFailure failure) {
return Center(
+13 -1
View File
@@ -52,9 +52,15 @@ class TemplatesScreen extends StatefulWidget {
this.embedded = false,
this.onCreated,
this.initialKey,
this.reloadToken = 0,
});
final ApiGateway gateway;
/// Advances when the shared connection is (re)established. A gallery that
/// could not be read (opened before the app had connected, or while it was
/// offline) reads again then, instead of keeping the failure until Retry.
final int reloadToken;
final bool embedded;
final ValueChanged<JsonMap>? onCreated;
@@ -88,7 +94,13 @@ class _TemplatesScreenState extends State<TemplatesScreen> {
if (oldWidget.initialKey != widget.initialKey) {
_selectedKey = widget.initialKey;
}
if (oldWidget.gateway == widget.gateway) return;
if (oldWidget.gateway == widget.gateway) {
if (oldWidget.reloadToken != widget.reloadToken &&
(_error != null || !_loaded)) {
unawaited(_load());
}
return;
}
// A different gateway is a different server: never keep this one's rows or
// selection while the replacement is read.
_repository = TemplateRepository(widget.gateway);
@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flutter/widgets.dart';
import '../../core/api_gateway.dart';
import '../../core/error_advice.dart';
import 'first_run_walkthrough.dart';
import 'walkthrough_store.dart';
@@ -11,19 +12,31 @@ import 'walkthrough_store.dart';
/// triggers the walkthrough.
Future<bool?> serverHasNoWorkYet(ApiGateway? gateway) async {
if (gateway == null) return null;
// A server leaves an empty list out of its reply.
Future<List<Object?>?> list(String type, String key, [JsonMap? fields]) =>
gateway.call(type, fields ?? const {}).then((reply) {
final value = reply[key] ?? const <Object?>[];
return value is List ? List<Object?>.from(value) : null;
});
Future<List<Object?>?> chats() async {
try {
return await list('chat_sessions', 'chat_sessions');
} catch (error) {
// A server without a chat harness has no chats yet; that is the newest
// server of all, not an unreadable one.
if (needsHarnessSetup(error)) return const <Object?>[];
rethrow;
}
}
try {
final replies = await Future.wait(<Future<JsonMap>>[
gateway.call('list_pipelines', {'include_archived': true}),
gateway.call('list_runs'),
gateway.call('chat_sessions'),
final lists = await Future.wait(<Future<List<Object?>?>>[
list('list_pipelines', 'pipelines', {'include_archived': true}),
list('list_runs', 'runs'),
chats(),
]);
final lists = <Object?>[
replies[0]['pipelines'],
replies[1]['runs'],
replies[2]['chat_sessions'],
];
if (lists.any((list) => list is! List)) return null;
return lists.every((list) => (list as List).isEmpty);
if (lists.any((list) => list == null)) return null;
return lists.every((list) => list!.isEmpty);
} catch (_) {
return null;
}
@@ -55,8 +68,13 @@ class FirstRunWalkthroughGate extends StatefulWidget {
required this.connected,
this.gateway,
this.onOpenConnection,
this.connectWait = const Duration(seconds: 3),
});
/// How long the first offer waits for a connection before it shows the
/// walkthrough with its connect page.
final Duration connectWait;
/// Opens Settings' Connection from the walkthrough's connect page.
final VoidCallback? onOpenConnection;
@@ -115,6 +133,7 @@ class _FirstRunWalkthroughGateState extends State<FirstRunWalkthroughGate> {
@override
void dispose() {
_endConnectionWait();
widget.connection.removeListener(_onConnectionChanged);
super.dispose();
}
@@ -170,6 +189,10 @@ class _FirstRunWalkthroughGateState extends State<FirstRunWalkthroughGate> {
if (!_active) return;
if (!seen) {
_decided = true;
// The app usually connects within a moment of its first frame (always
// on the web, which is served by the server). Wait briefly so a
// connected app is not told to connect.
if (!widget.connected()) await _connection(widget.connectWait);
await _showIfActive();
return;
}
@@ -190,6 +213,31 @@ class _FirstRunWalkthroughGateState extends State<FirstRunWalkthroughGate> {
await _showIfActive();
}
/// The first offer's wait for a connection; ended early by [dispose].
Timer? _connectTimer;
Completer<void>? _connectWaiting;
/// Completes when the session connects or after [limit], whichever is
/// first, or as soon as the gate is disposed.
Future<void> _connection(Duration limit) {
final done = _connectWaiting = Completer<void>();
void check() {
if (widget.connected()) _endConnectionWait();
}
final listenable = widget.connection..addListener(check);
_connectTimer = Timer(limit, _endConnectionWait);
return done.future.whenComplete(() => listenable.removeListener(check));
}
void _endConnectionWait() {
_connectTimer?.cancel();
_connectTimer = null;
final waiting = _connectWaiting;
_connectWaiting = null;
if (waiting != null && !waiting.isCompleted) waiting.complete();
}
Future<void> _showIfActive() async {
if (!_active) return;
await _show();
+143
View File
@@ -0,0 +1,143 @@
import 'package:flutter/material.dart';
import '../theme/app_design_tokens.dart';
/// One button of an [EmptyState]: a label, an optional icon and its action.
typedef EmptyStateAction = ({
String label,
IconData? icon,
VoidCallback onPressed,
});
/// Builds an [EmptyStateAction]; a named constructor reads better at call
/// sites than a record literal.
EmptyStateAction emptyStateAction(
String label,
VoidCallback onPressed, {
IconData? icon,
}) => (label: label, icon: icon, onPressed: onPressed);
/// What a list shows when it has nothing yet: never an error, always a next
/// step. One look on every screen: a large icon on a tonal disc, a short
/// title, one muted line of explanation and up to two actions (the primary
/// one filled). [child] adds content under the message, such as a command to
/// copy. The whole state scrolls in a short pane instead of overflowing.
///
/// Shapes follow the active design: the disc takes the design's corner
/// radius (square under Terminal, round under Classic and Paper).
class EmptyState extends StatelessWidget {
const EmptyState({
super.key,
required this.icon,
required this.title,
this.message,
this.action,
this.secondaryAction,
this.child,
this.dense = false,
});
final IconData icon;
final String title;
final String? message;
final EmptyStateAction? action;
final EmptyStateAction? secondaryAction;
final Widget? child;
/// A smaller icon and tighter spacing, for narrow list panes.
final bool dense;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final scheme = theme.colorScheme;
final tokens = AppDesignTokens.of(context);
final disc = dense ? 56.0 : 72.0;
final primary = action;
final secondary = secondaryAction;
return Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 420),
child: Semantics(
container: true,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
DecoratedBox(
decoration: BoxDecoration(
color: scheme.secondaryContainer,
borderRadius: tokens.corners(
BorderRadius.circular(disc / 2),
),
),
child: SizedBox.square(
dimension: disc,
child: Icon(
icon,
size: disc / 2,
color: scheme.onSecondaryContainer,
),
),
),
SizedBox(height: dense ? 12 : 16),
Text(
title,
textAlign: TextAlign.center,
style: theme.textTheme.titleMedium,
),
if (message case final message?) ...[
const SizedBox(height: 6),
Text(
message,
textAlign: TextAlign.center,
style: theme.textTheme.bodyMedium?.copyWith(
color: scheme.onSurfaceVariant,
),
),
],
if (child case final child?) ...[
const SizedBox(height: 16),
child,
],
if (primary != null || secondary != null) ...[
SizedBox(height: dense ? 16 : 20),
Wrap(
alignment: WrapAlignment.center,
spacing: 8,
runSpacing: 8,
children: [
if (primary != null)
primary.icon == null
? FilledButton(
onPressed: primary.onPressed,
child: Text(primary.label),
)
: FilledButton.icon(
onPressed: primary.onPressed,
icon: Icon(primary.icon),
label: Text(primary.label),
),
if (secondary != null)
secondary.icon == null
? TextButton(
onPressed: secondary.onPressed,
child: Text(secondary.label),
)
: TextButton.icon(
onPressed: secondary.onPressed,
icon: Icon(secondary.icon),
label: Text(secondary.label),
),
],
),
],
],
),
),
),
),
);
}
}
@@ -5,6 +5,7 @@ import 'package:pipelines_app/core/servers/chat/chat_identity.dart';
import 'package:pipelines_app/core/servers/chat/chat_server_gateway.dart';
import 'package:pipelines_app/core/servers/chat/federated_chat_gateway.dart';
import 'package:pipelines_app/core/servers/server_catalog.dart';
import 'package:pipelines_app/core/transport/connection_state.dart';
import 'package:pipelines_app/core/transport/server_url.dart';
import 'package:pipelines_app/features/chat/files/files_urls.dart';
@@ -12,6 +13,8 @@ class Machine implements ApiGateway {
final events = StreamController<JsonMap>.broadcast();
final calls = <(String, JsonMap)>[];
bool fail = false;
Object? failure;
JsonMap? sessionsReply;
Completer<JsonMap>? pendingSessions;
@override
Stream<JsonMap> get frames => events.stream;
@@ -19,6 +22,8 @@ class Machine implements ApiGateway {
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
calls.add((type, fields));
if (fail) throw StateError('offline');
if (failure case final failure?) throw failure;
if (type == 'chat_sessions' && sessionsReply != null) return sessionsReply!;
if (type == 'chat_sessions') {
if (pendingSessions != null) return pendingSessions!.future;
return {
@@ -57,6 +62,40 @@ SavedServer server(String id) => SavedServer.validated(
endpoints: ['ws://$id.test/connect'],
);
void main() {
group('a server with no chats or no chat harness', () {
FederatedChatGateway federated(Machine machine) {
final sources = {'a': ChatServerGateway(server('a'), machine)};
return FederatedChatGateway(
() => sources,
() => 'a',
const Stream.empty(),
);
}
test('an omitted empty list reads as no chats, not a failure', () async {
final machine = Machine()..sessionsReply = {'type': 'chat_sessions'};
final reply = await federated(machine).call('chat_sessions');
expect(reply['chat_sessions'], isEmpty);
});
test('the server\'s own refusal is kept when no machine answers', () {
final machine = Machine()
..failure = const ProtocolError(
'chat is not configured on this server',
);
expect(
federated(machine).call('chat_sessions'),
throwsA(
isA<ProtocolError>().having(
(error) => error.message,
'message',
'chat is not configured on this server',
),
),
);
});
});
test(
'colliding native IDs remain distinct, mutations and replies stay on source',
() async {
@@ -17,7 +17,7 @@ void main() {
expect(find.byType(Scaffold), findsWidgets);
const message = 'No chats yet. Use New chat to start one.';
const message = 'No chats yet';
expect(find.text(message), findsOneWidget);
expectNormalTextStyle(tester, message);
});
@@ -39,7 +39,7 @@ void main() {
'for this operator';
expect(find.text(message), findsOneWidget);
expectNormalTextStyle(tester, message);
expect(find.text('No chats yet. Use New chat to start one.'), findsNothing);
expect(find.text('No chats yet'), findsNothing);
expect(
find.ancestor(
of: find.text('Retry'),
@@ -3,6 +3,8 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/core/transport/connection_state.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_harness_setup_state.dart';
import 'chat_test_harness.dart';
import 'fake_chat_gateway.dart';
@@ -91,13 +93,29 @@ void main() {
) async {
final gateway = FakeChatGateway();
await pumpMaterialChat(tester, gateway);
expect(
find.text('No chats yet. Use New chat to start one.'),
findsOneWidget,
);
expect(find.text('No chats yet'), findsOneWidget);
expect(find.text('Start a chat'), findsOneWidget);
expect(find.textContaining('No chats match'), findsNothing);
});
testWidgets('a server without a chat harness shows the setup step', (
tester,
) async {
usePhoneSurface(tester);
final gateway = FakeChatGateway()
..sessionsHandler = () => Future.error(
const ProtocolError('chat is not configured on this server'),
);
await pumpMaterialChat(tester, gateway);
expect(find.byKey(chatHarnessSetupKey), findsOneWidget);
expect(find.text('pipelines harness setup claude'), findsOneWidget);
// Not a failure: no error notice, no raw server text.
expect(find.textContaining('not configured'), findsNothing);
expect(find.text('No chats yet'), findsNothing);
expect(find.text('Refresh'), findsWidgets);
});
testWidgets('load failure wraps the reason and hides the empty message', (
tester,
) async {
@@ -114,7 +132,7 @@ void main() {
'Bad state: server unavailable while listing chat sessions '
'for this operator';
expect(find.text(message), findsOneWidget);
expect(find.text('No chats yet. Use New chat to start one.'), findsNothing);
expect(find.text('No chats yet'), findsNothing);
final messageBox = tester.renderObject<RenderBox>(find.text(message));
expect(
messageBox.size.height,
@@ -132,7 +132,7 @@ void main() {
const [],
const PipelineFilters(),
)?.message,
'No pipelines yet.',
'No pipelines yet',
);
expect(pipelineListEmptyState(all, all, const PipelineFilters()), isNull);
});
@@ -1,6 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/pipelines/screen.dart';
import 'package:pipelines_app/features/pipelines/widgets/pipeline_list_panel.dart';
import 'fixtures.dart';
import 'test_helpers.dart';
@@ -20,11 +23,8 @@ void main() {
(tester) async {
await pumpWide(tester, emptyServerGateway());
expect(find.text('No pipelines yet.'), findsOneWidget);
expect(
find.text('Create one from a template in Templates.'),
findsOneWidget,
);
expect(find.text('No pipelines yet'), findsOneWidget);
expect(find.textContaining('Start from a template'), findsOneWidget);
expect(find.text('Loading pipelines…'), findsNothing);
expect(find.byKey(const Key('pipeline-list')), findsNothing);
expect(find.textContaining('not defined'), findsNothing);
@@ -33,6 +33,28 @@ void main() {
},
);
testWidgets('the empty state opens Templates as its next step', (
tester,
) async {
tester.view.physicalSize = const Size(1100, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
var opened = 0;
await tester.pumpWidget(
MaterialApp(
home: PipelinesScreen(
gateway: emptyServerGateway(),
onOpenTemplates: () => opened++,
),
),
);
await tester.pumpAndSettle();
expect(find.byKey(pipelinesEmptyKey), findsOneWidget);
await tester.tap(find.text('Browse templates'));
expect(opened, 1);
});
testWidgets(
'a failed list stays an error and never reads as an empty server',
(tester) async {
@@ -42,7 +64,7 @@ void main() {
);
expect(find.textContaining('server offline'), findsOneWidget);
expect(find.text('No pipelines yet.'), findsNothing);
expect(find.text('No pipelines yet'), findsNothing);
expect(find.text('Loading pipelines…'), findsNothing);
expect(tester.takeException(), isNull);
},
@@ -104,11 +104,8 @@ void main() {
MaterialApp(home: PipelinesScreen(gateway: emptyGateway)),
);
await tester.pumpAndSettle();
expect(find.text('No pipelines yet.'), findsOneWidget);
expect(
find.text('Create one from a template in Templates.'),
findsOneWidget,
);
expect(find.text('No pipelines yet'), findsOneWidget);
expect(find.textContaining('Start from a template'), findsOneWidget);
});
testWidgets('a detail refusal keeps the selection and offers retry', (
@@ -146,4 +146,34 @@ void main() {
);
expect(find.text('Why it failed'), findsNothing);
});
testWidgets('a run that found no agent harness names the setup step', (
tester,
) async {
const reason =
'environment problem: model stage research: HARNESS TRANSPORT: '
'harness unreachable: cannot run the selected OpenCode CLI: exec: '
'"opencode": executable file not found in \$PATH';
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: RunFailureBanner(
run: _run('failed', {'failure_reason': reason}),
),
),
),
);
expect(find.byKey(runFailureHarnessHintKey), findsOneWidget);
expect(find.textContaining('pipelines harness setup'), findsOneWidget);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: RunFailureBanner(
run: _run('failed', {'diagnostic': 'exit status 2'}),
),
),
),
);
expect(find.byKey(runFailureHarnessHintKey), findsNothing);
});
}
@@ -9,6 +9,7 @@ import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
import 'package:pipelines_app/features/runs/ui/runs_filters.dart';
import 'package:pipelines_app/ui/status/run_status_icon.dart';
import 'package:pipelines_app/features/runs/ui/runs_list.dart';
import 'package:pipelines_app/ui/status/error_notice.dart';
class _Gateway implements ApiGateway {
final framesController = StreamController<JsonMap>.broadcast();
@@ -162,8 +163,10 @@ void main() {
gateway.reply = {'runs': []};
await controller.load();
await tester.pumpAndSettle();
expect(find.text('No runs yet.'), findsOneWidget);
expect(find.textContaining('Start one from Pipelines'), findsOneWidget);
expect(find.text('No runs yet'), findsOneWidget);
expect(find.textContaining('A run is a pipeline'), findsOneWidget);
// No New run seam in this fixture: the state offers no dead button.
expect(find.text('Start your first run'), findsNothing);
expect(find.text('No runs found.'), findsNothing);
expect(find.textContaining('offline'), findsNothing);
expect(tester.takeException(), isNull);
@@ -173,7 +176,7 @@ void main() {
controller.setStatus('failed');
await tester.pumpAndSettle();
expect(find.text('No runs found.'), findsOneWidget);
expect(find.text('No runs yet.'), findsNothing);
expect(find.text('No runs yet'), findsNothing);
expect(
find.text('Try changing or clearing the filters.'),
findsOneWidget,
@@ -183,6 +186,32 @@ void main() {
variant: TargetPlatformVariant.only(TargetPlatform.android),
);
testWidgets('an empty server offers the first run as the next step', (
tester,
) async {
gateway.failure = null;
gateway.gate = null;
gateway.reply = {'runs': []};
await controller.load();
var started = 0;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: RunsList(
controller: controller,
onSelected: (_) {},
onNewRun: () => started++,
),
),
),
);
await tester.pumpAndSettle();
expect(find.byKey(runsEmptyKey), findsOneWidget);
expect(find.byType(ErrorNotice), findsNothing);
await tester.tap(find.text('Start your first run'));
expect(started, 1);
});
testWidgets(
'an empty server with a search query reads as no match, not no runs',
(tester) async {
@@ -200,7 +229,7 @@ void main() {
);
await tester.pumpAndSettle();
expect(find.text('No runs found.'), findsOneWidget);
expect(find.text('No runs yet.'), findsNothing);
expect(find.text('No runs yet'), findsNothing);
expect(
find.text('Try changing or clearing the filters.'),
findsOneWidget,
@@ -88,7 +88,7 @@ void main() {
(type, fields) async => {'type': 'schedules'},
);
await pumpSchedules(tester, gateway: empty);
expect(find.text('No schedules yet.'), findsOneWidget);
expect(find.text('No schedules yet'), findsOneWidget);
expect(find.byKey(scheduleRetryKey), findsNothing);
final unsupported = FakeSchedulesGateway(
@@ -100,7 +100,7 @@ void main() {
findsOneWidget,
);
expect(find.byKey(scheduleRetryKey), findsOneWidget);
expect(find.text('No schedules yet.'), findsNothing);
expect(find.text('No schedules yet'), findsNothing);
final failed = FakeSchedulesGateway(
(type, fields) async => throw StateError('socket closed'),
@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/core/transport/connection_state.dart';
import 'package:pipelines_app/features/templates/screen.dart';
import 'package:pipelines_app/features/templates/ui/template_detail.dart';
import 'package:pipelines_app/features/templates/ui/template_gallery.dart'
@@ -122,6 +123,29 @@ void main() {
expect(find.text('Release workflow'), findsOneWidget);
});
testWidgets('a gallery opened before the connection reads again on connect', (
tester,
) async {
var connected = false;
final gateway = GalleryGateway((type, fields) async {
if (!connected) throw const NotConnectedError();
if (type == 'list_templates') return templatesReply(galleryTemplates);
throw StateError('unexpected $type');
});
Widget screen(int token) => MaterialApp(
home: TemplatesScreen(gateway: gateway, reloadToken: token),
);
await tester.pumpWidget(screen(0));
await tester.pumpAndSettle();
expect(find.byKey(templatesErrorKey), findsOneWidget);
connected = true;
await tester.pumpWidget(screen(1));
await tester.pumpAndSettle();
expect(find.byKey(templatesErrorKey), findsNothing);
expect(find.text('Release workflow'), findsOneWidget);
});
testWidgets('refresh re-reads the catalogue and keeps the selection', (
tester,
) async {
@@ -108,6 +108,37 @@ Future<void> _finishWalkthrough(WidgetTester tester) async {
}
void main() {
testWidgets(
'first launch waits briefly for the connection before welcoming',
(tester) async {
final store = MemoryWalkthroughStore();
final link = ValueNotifier<bool>(false);
await tester.pumpWidget(_host(store: store, link: link));
await tester.pump();
expect(find.text(_welcome), findsNothing);
// The app connects a moment later: the welcome is the connected one,
// with no connect directions.
link.value = true;
await tester.pumpAndSettle();
expect(find.text(_welcome), findsOneWidget);
expect(find.textContaining('start by connecting'), findsNothing);
},
);
testWidgets(
'first launch without a connection still offers the connect page',
(tester) async {
final store = MemoryWalkthroughStore();
final link = ValueNotifier<bool>(false);
await tester.pumpWidget(_host(store: store, link: link));
await tester.pump(const Duration(seconds: 3));
await tester.pumpAndSettle();
expect(find.text(_welcome), findsOneWidget);
expect(find.textContaining('start by connecting'), findsOneWidget);
},
);
testWidgets('first launch shows the walkthrough once per device', (
tester,
) async {
+17
View File
@@ -35,6 +35,23 @@ void main() {
errorAdviceKind(TimeoutException('request timed out after 30000ms')),
ErrorAdviceKind.timeout,
);
expect(
errorAdviceKind(
const ProtocolError('chat is not configured on this server'),
),
ErrorAdviceKind.noHarness,
);
expect(
errorAdviceKind(
'HARNESS TRANSPORT: harness unreachable: cannot run the selected '
'OpenCode CLI',
),
ErrorAdviceKind.noHarness,
);
expect(
errorAdviceSentence(ErrorAdviceKind.noHarness),
contains('pipelines harness setup'),
);
expect(errorAdviceKind('pipeline 4 has no stage review'), isNull);
final advice = errorAdvice(StateError('Connection closed'));
expect(advice?.detail, 'Connection closed');