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
+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 {