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
@@ -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