Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

New Harness: the first task says when an agent cannot take one, and how long it may be

deehwde033f959f71
diff --git a/desktop/lib/core/first_task.dart b/desktop/lib/core/first_task.dart
new file mode 100644
index 000000000..1b4706f9b
--- /dev/null
+++ b/desktop/lib/core/first_task.dart
@@ -0,0 +1,16 @@
+// What a machine accepts as a harness's first task (`prompt` on
+// `agent_create`), so New Harness can say so before Create rather than after.
+
+/// The engines that can be opened with a first message: the non-null entries of
+/// the CLI's `FIRST_PROMPT_ARGS` (cli/src/lib/engineLaunch.ts). A machine refuses
+/// a first message for any other engine (`PROMPT_UNSUPPORTED`).
+/// test/first_task_test.dart holds the two lists to the same answer.
+const kFirstTaskEngines = {'claude', 'codex', 'opencode'};
+
+/// Whether a harness on [engine] — its base engine, for a Store harness — can
+/// start on a first task.
+bool takesFirstTask(String engine) => kFirstTaskEngines.contains(engine);
+
+/// The longest first task a machine accepts, counted after trimming: the CLI's
+/// `MAX_FIRST_PROMPT_CHARS`. Longer is refused (`PROMPT_TOO_LONG`), never cut.
+const kFirstTaskMaxLength = 2000;
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index ebf38eab6..433db5a8e 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -4836,6 +4836,8 @@ class AppNotifier extends ChangeNotifier {
'${detail ?? 'Install it there, then try again.'}',
'PROMPT_UNSUPPORTED' =>
'This engine cannot be opened with a first message on $machine.',
+ 'PROMPT_TOO_LONG' =>
+ 'This first task is too long for $machine. Shorten it and try again.',
'AGENT_UNSUPPORTED' =>
'This engine cannot be opened as a named agent on $machine.',
_ => 'Create harness failed: ${detail ?? code}',
@@ -4953,6 +4955,8 @@ class AppNotifier extends ChangeNotifier {
'INVALID_CODEX_HOME',
'INVALID_DSH',
'PROMPT_UNSUPPORTED',
+ 'PROMPT_TOO_LONG',
+ 'INVALID_PROMPT',
'AGENT_UNSUPPORTED',
'TMUX_UNAVAILABLE',
'TMUX_TOO_OLD_FOR_GRID',
diff --git a/desktop/lib/widgets/new_agent_dialog.dart b/desktop/lib/widgets/new_agent_dialog.dart
index 40ee51f15..175b10d0d 100644
--- a/desktop/lib/widgets/new_agent_dialog.dart
+++ b/desktop/lib/widgets/new_agent_dialog.dart
@@ -11,6 +11,7 @@ import '../state/pane_arrangement.dart';
import '../core/engine_availability.dart';
import '../core/codex_profiles.dart';
import '../core/dsh_catalog.dart';
+import '../core/first_task.dart';
import '../core/permission_modes.dart';
import '../core/project_folder.dart';
import '../core/repository_clone.dart';
@@ -127,7 +128,24 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
);
String? get _firstPrompt {
final task = _task.text.trim();
- return task.isEmpty ? null : task;
+ return task.isEmpty || !_takesTask || _taskTooLong ? null : task;
+ }
+
+ /// Whether the chosen agent can start on a task at all: only some engines
+ /// can be opened with a first message, and a machine refuses one for the
+ /// rest. The field says so and keeps what was typed, unsent.
+ bool get _takesTask => takesFirstTask(_baseEngine(_engine));
+
+ /// Longer than a machine accepts: Create waits until it is shortened, rather
+ /// than sending something the machine refuses or cutting it.
+ bool get _taskTooLong =>
+ _takesTask && _task.text.trim().length > kFirstTaskMaxLength;
+ late bool _taskWasTooLong = _taskTooLong;
+
+ /// Rebuilds the dialog, not just the field, when Create's answer changes.
+ void _onTaskChanged() {
+ if (_taskTooLong == _taskWasTooLong) return;
+ setState(() => _taskWasTooLong = _taskTooLong);
}
final _folderFocus = FocusNode(debugLabel: 'Working folder');
@@ -189,6 +207,7 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
@override
void initState() {
super.initState();
+ _task.addListener(_onTaskChanged);
final remembered = widget.notifier.agentPreference.value;
final asked = widget.initialEngine;
if (asked != null &&
@@ -623,6 +642,7 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
: _projectFolder != null)) &&
!_picking &&
!_submitting &&
+ (_confirmationPending || !_taskTooLong) &&
(_confirmationPending || !_waitingForCodexProfile);
return CallbackShortcuts(
@@ -714,7 +734,10 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
SizedBox(height: compactHeight ? 24 : 32),
_sectionHeader(
'First task',
- 'What should your agent work on? (Optional)',
+ _takesTask
+ ? 'What should your agent work on? (Optional)'
+ : '${_labelOf(_engine)} starts without one. '
+ 'Tell it once it opens.',
null,
compactHeight: compactHeight,
),
@@ -1190,9 +1213,20 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
final radius = BorderRadius.circular(grid.AppControl.radius);
final line = MediaQuery.textScalerOf(context).scale(16) * 1.45;
final padding = ((minHeight - line) / 2).clamp(12.0, double.infinity);
+ final tooLong = _taskTooLong;
+ final errorBorder = OutlineInputBorder(
+ borderRadius: radius,
+ borderSide: BorderSide(
+ color: Theme.of(context).colorScheme.error,
+ width: 1.5,
+ ),
+ );
return TextField(
key: const Key('new-agent-task'),
controller: _task,
+ // Kept, not cleared, for an agent that cannot take it: choosing one
+ // that can sends it after all.
+ enabled: _takesTask,
minLines: 1,
maxLines: 6,
keyboardType: TextInputType.multiline,
@@ -1212,6 +1246,13 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
),
// One line, so an empty box is exactly a tile tall at any width.
hintMaxLines: 1,
+ errorText: tooLong
+ ? 'A first task can be up to $kFirstTaskMaxLength characters. '
+ 'This one is ${_task.text.trim().length}.'
+ : null,
+ errorMaxLines: 2,
+ errorBorder: errorBorder,
+ focusedErrorBorder: errorBorder,
filled: true,
fillColor: grid.AppSurface.recess,
isDense: true,
@@ -1227,6 +1268,10 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
borderRadius: radius,
borderSide: BorderSide.none,
),
+ disabledBorder: OutlineInputBorder(
+ borderRadius: radius,
+ borderSide: BorderSide.none,
+ ),
focusedBorder: OutlineInputBorder(
borderRadius: radius,
borderSide: BorderSide(
@@ -1234,7 +1279,8 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
width: 1.5,
),
),
- suffixIcon: _task.text.isEmpty
+ // A disabled field takes no clicks, so it offers none.
+ suffixIcon: _task.text.isEmpty || !_takesTask
? null
: Padding(
padding: const EdgeInsets.only(right: 8),
diff --git a/desktop/test/first_task_test.dart b/desktop/test/first_task_test.dart
new file mode 100644
index 000000000..808cfbfdc
--- /dev/null
+++ b/desktop/test/first_task_test.dart
@@ -0,0 +1,49 @@
+// What a machine accepts as a first task, as this app knows it: the engines
+// that take one and how long it may be. Both are the CLI's to decide, so both
+// are read back from its source here — a CLI that learns a new engine's first
+// message, or a new limit, fails this test until the app says the same.
+import 'dart:io';
+
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/core/first_task.dart';
+import 'package:harness/widgets/engine_identity.dart';
+
+void main() {
+ final source = File('../cli/src/lib/engineLaunch.ts').readAsStringSync();
+
+ test('the engines that take a first task are the CLI\'s', () {
+ final table = RegExp(
+ r'export const FIRST_PROMPT_ARGS[^=]*=\s*\{(.*?)\n\}',
+ dotAll: true,
+ ).firstMatch(source);
+ expect(
+ table,
+ isNotNull,
+ reason: 'FIRST_PROMPT_ARGS moved or changed shape',
+ );
+ final entries = {
+ for (final m in RegExp(
+ r'^\s*([a-z]+):\s*(null|\[)',
+ multiLine: true,
+ ).allMatches(table!.group(1)!))
+ m.group(1)!: m.group(2) != 'null',
+ };
+ expect(entries, isNotEmpty);
+ expect({
+ for (final e in entries.entries)
+ if (e.value) e.key,
+ }, kFirstTaskEngines);
+ // Every engine this app offers is in the CLI's table, one way or the other.
+ for (final engine in allEngines) {
+ expect(entries.keys, contains(engine.id), reason: engine.id);
+ expect(takesFirstTask(engine.id), entries[engine.id], reason: engine.id);
+ }
+ });
+
+ test('the longest first task is the CLI\'s', () {
+ final limit = RegExp(r'export const MAX_FIRST_PROMPT_CHARS = (\d+)')
+ .firstMatch(source);
+ expect(limit, isNotNull);
+ expect(kFirstTaskMaxLength, int.parse(limit!.group(1)!));
+ });
+}
diff --git a/desktop/test/new_agent_rows_and_task_test.dart b/desktop/test/new_agent_rows_and_task_test.dart
new file mode 100644
index 000000000..aeaf24908
--- /dev/null
+++ b/desktop/test/new_agent_rows_and_task_test.dart
@@ -0,0 +1,522 @@
+// New Harness, as a person reads and uses it: each agent row names the agent,
+// whose it is and what it is in its own words — whichever of the machine's
+// catalog and this build knows it — the search finds an agent by any of those,
+// and the first task is sent exactly as typed, or not at all.
+import 'dart:async';
+
+import 'package:file_selector_platform_interface/file_selector_platform_interface.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/auth/auth_session.dart';
+import 'package:harness/core/config.dart';
+import 'package:harness/core/dsh_catalog.dart';
+import 'package:harness/core/engine_availability.dart';
+import 'package:harness/core/models.dart';
+import 'package:harness/core/project_folder.dart';
+import 'package:harness/shared/widgets/app_icon_button.dart';
+import 'package:harness/state/app_state.dart';
+import 'package:harness/state/pane_arrangement.dart';
+import 'package:harness/widgets/new_agent_dialog.dart';
+import 'package:harness/widgets/search_result_text.dart';
+
+import 'support/agent_picker.dart';
+
+class _Folders extends FileSelectorPlatform {
+ @override
+ Future<String?> getDirectoryPath({
+ String? initialDirectory,
+ String? confirmButtonText,
+ }) async => '/work/lamp';
+}
+
+/// The machine's catalog as a daemon that forwards taglines sends it, with
+/// each way a row can fall back.
+const _catalog = [
+ // An older daemon: no tagline and no author, so this build's words.
+ DshEntry(
+ id: 'autonomous/mujoco',
+ name: 'MuJoCo',
+ engine: 'claude',
+ category: 'Simulation',
+ installed: true,
+ ),
+ // The catalog's words win over this build's, trimmed.
+ DshEntry(
+ id: 'autonomous/typst',
+ name: 'Typst',
+ engine: 'claude',
+ category: 'Documents',
+ author: 'Typst GmbH',
+ tagline: ' Typesetting, as the catalog says it ',
+ installed: true,
+ ),
+ // A blank tagline and no face in this build: its domain.
+ DshEntry(
+ id: 'someone/earth',
+ name: 'Google Earth Engine',
+ engine: 'codex',
+ category: 'Robotics',
+ author: 'Earth Team',
+ tagline: ' ',
+ installed: true,
+ ),
+ // No tagline and no domain: its description. No author: no byline.
+ DshEntry(
+ id: 'someone/maps',
+ name: 'Maps',
+ engine: 'codex',
+ description: 'Works with Google Maps.',
+ installed: true,
+ ),
+ // Nothing to say at all.
+ DshEntry(id: 'someone/bare', name: 'Bare', engine: 'codex', installed: true),
+ // Not installed, with a name long enough to test the busy label.
+ DshEntry(
+ id: 'someone/long',
+ name: 'An Extraordinarily Long Harness Name That Keeps Going Well Past The Button',
+ engine: 'codex',
+ ),
+];
+
+class _App extends AppNotifier {
+ _App()
+ : super(
+ config: AppConfig.dev,
+ authSession: AuthSession(),
+ configStore: null,
+ );
+
+ final prompts = <String?>[];
+
+ /// When set, a create waits for it: the dialog stays mid-create.
+ Completer<String?>? pendingCreate;
+
+ /// When set, an install waits for it.
+ Completer<String?>? pendingInstall;
+
+ @override
+ Future<void> probeEngines(String machineId, {bool force = false}) async {}
+
+ @override
+ Future<void> probeDsh(String machineId, {bool force = false}) async {}
+
+ @override
+ Future<Map<String, dynamic>> listCodexProfiles(
+ String machineId, {
+ Set<String> observedPaths = const {},
+ }) async => {'profiles': <dynamic>[]};
+
+ @override
+ Future<String?> installDsh(String machineId, String id) =>
+ pendingInstall?.future ?? Future.value(null);
+
+ @override
+ Future<String?> createAgent(
+ String machineId, {
+ required String engine,
+ required String folder,
+ bool bypassPermission = false,
+ String? permissionMode,
+ String? codexHome,
+ String? dsh,
+ String? prompt,
+ String? name,
+ String? agent,
+ ProjectFolderRequest? projectFolder,
+ String? swarmId,
+ PaneSplitRequest? split,
+ AgentCreationAttempt? attempt,
+ }) async {
+ prompts.add(prompt);
+ return pendingCreate?.future ?? 'Test launch refused.';
+ }
+}
+
+final _task = find.byKey(const ValueKey('new-agent-task'));
+final _clear = find.byKey(const ValueKey('new-agent-task-clear'));
+final _submit = find.byKey(const ValueKey('create-agent-submit'));
+
+Future<_App> _open(
+ WidgetTester tester, {
+ bool catalogLoaded = true,
+ Size size = const Size(1400, 1000),
+ String? initialPrompt,
+}) async {
+ FileSelectorPlatform.instance = _Folders();
+ tester.view.devicePixelRatio = 1;
+ tester.view.physicalSize = size;
+ addTearDown(tester.view.reset);
+ final app = _App();
+ addTearDown(app.dispose);
+ const machine = Machine(
+ machineId: 'machine-1',
+ authMode: MachineAuthMode.remote,
+ name: 'studio',
+ );
+ final state = MachineState(machine)..localOnly = true;
+ state.engines.replace(const [
+ EngineAvailability(engine: 'claude', installed: true),
+ EngineAvailability(engine: 'codex', installed: true),
+ EngineAvailability(engine: 'cursor', installed: true),
+ ]);
+ if (catalogLoaded) state.dsh.replace(_catalog);
+ app.machineStates['machine-1'] = state;
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Builder(
+ builder: (context) => Scaffold(
+ body: TextButton(
+ onPressed: () => showNewAgentDialog(
+ context,
+ app,
+ 'machine-1',
+ source: 'test',
+ initialPrompt: initialPrompt,
+ ),
+ child: const Text('open'),
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.tap(find.text('open'));
+ await tester.pumpAndSettle();
+ return app;
+}
+
+Future<void> _search(WidgetTester tester, String query) async {
+ if (agentSearch.evaluate().isEmpty) await openAgentSearch(tester);
+ await tester.enterText(agentSearch, query);
+ await tester.pump();
+}
+
+Future<void> _pickFolder(WidgetTester tester) async {
+ final newProject = find.byKey(const ValueKey('new-agent-folder-newProject'));
+ await tester.ensureVisible(newProject);
+ await tester.tap(newProject);
+ await tester.pumpAndSettle();
+}
+
+Future<void> _create(WidgetTester tester) async {
+ await tester.ensureVisible(_submit);
+ await tester.tap(_submit);
+ await tester.pump();
+}
+
+Finder _row(String id) => find.byKey(ValueKey('new-agent-agent-row-$id'));
+
+/// The row's byline and the line under its name, as drawn.
+({String? by, String? line}) _read(WidgetTester tester, String id) {
+ final by = find.byKey(ValueKey('new-agent-agent-row-by-$id'));
+ final subtitle = tester.widget<ListTile>(_row(id)).subtitle;
+ return (
+ by: by.evaluate().isEmpty ? null : tester.widget<Text>(by).data,
+ line: subtitle is SearchResultText ? subtitle.text : null,
+ );
+}
+
+void main() {
+ group('agent rows: the name, whose it is, and what it is', () {
+ testWidgets('the catalog first, then this build, then domain, then '
+ 'description', (tester) async {
+ await _open(tester);
+
+ await _search(tester, 'mujoco');
+ expect(_read(tester, 'autonomous/mujoco'), (
+ by: 'by Google DeepMind',
+ line: 'Advanced physics simulation',
+ ), reason: 'an older daemon sends neither: this build knows both');
+
+ await _search(tester, 'typst');
+ expect(_read(tester, 'autonomous/typst'), (
+ by: 'by Typst GmbH',
+ line: 'Typesetting, as the catalog says it',
+ ), reason: 'the catalog wins over this build, trimmed');
+
+ await _search(tester, 'earth');
+ expect(_read(tester, 'someone/earth'), (
+ by: 'by Earth Team',
+ line: 'Robotics',
+ ), reason: 'a blank tagline is no tagline: the domain says it');
+
+ await _search(tester, 'maps');
+ expect(
+ _read(tester, 'someone/maps'),
+ (by: null, line: 'Works with Google Maps.'),
+ reason:
+ 'nothing else: the description, and no byline without an author',
+ );
+
+ await _search(tester, 'bare');
+ expect(_read(tester, 'someone/bare'), (by: null, line: null));
+
+ await _search(tester, 'claude');
+ expect(_read(tester, 'claude'), (
+ by: 'by Anthropic',
+ line: 'Work with Claude directly in your codebase',
+ ), reason: 'the engines read the same way');
+ expect(tester.takeException(), isNull);
+ });
+
+ testWidgets('before the machine answers, the harnesses read in this '
+ "build's words", (tester) async {
+ await _open(tester, catalogLoaded: false);
+ await _search(tester, 'yosys');
+ expect(_read(tester, 'autonomous/yosys'), (
+ by: 'by YosysHQ',
+ line: 'Framework for Verilog RTL synthesis',
+ ));
+ await _search(tester, 'godogen');
+ expect(
+ find.byKey(const ValueKey('new-agent-agent-row-autonomous/godogen')),
+ findsNothing,
+ reason: 'a harness this build has no face for waits for the machine',
+ );
+ });
+
+ testWidgets('the search finds an agent by whose it is, its Store shelf '
+ 'and its domain, name matches first', (tester) async {
+ await _open(tester);
+
+ // A name, then an author, then the line under a name.
+ // Among equals a harness before an engine: MuJoCo, then Antigravity,
+ // both by Google.
+ await _search(tester, 'google');
+ expect(agentRows(tester), [
+ 'someone/earth',
+ 'autonomous/mujoco',
+ 'agy',
+ 'someone/maps',
+ ]);
+
+ // The Store's shelf: Simulation is on Science.
+ await _search(tester, 'science');
+ expect(agentRows(tester), contains('autonomous/mujoco'));
+ // The domain itself, where no line under a name says it.
+ await _search(tester, 'documents');
+ expect(agentRows(tester), ['autonomous/typst']);
+ // An unknown domain is on the Store's Other shelf.
+ await _search(tester, 'other');
+ expect(agentRows(tester), contains('someone/earth'));
+ // An author the row draws.
+ await _search(tester, 'gmbh');
+ expect(agentRows(tester), ['autonomous/typst']);
+ });
+
+ testWidgets('the preview names whose it is and what it is', (tester) async {
+ await _open(tester);
+ await _search(tester, 'deepmind');
+ expect(agentRows(tester), ['autonomous/mujoco']);
+ final preview = find.byKey(const ValueKey('new-agent-agent-preview'));
+ expect(preview, findsOneWidget);
+ expect(
+ find.descendant(
+ of: preview,
+ matching: find.textContaining('by Google DeepMind'),
+ ),
+ findsOneWidget,
+ );
+ expect(
+ find.descendant(
+ of: preview,
+ matching: find.text('Advanced physics simulation'),
+ ),
+ findsOneWidget,
+ );
+
+ // A harness with no author shows its name alone.
+ await _search(tester, 'bare');
+ expect(
+ find.descendant(of: preview, matching: find.textContaining('by ')),
+ findsNothing,
+ );
+ });
+ });
+
+ group('the first task', () {
+ testWidgets('opens empty, with its hint and nothing to clear', (
+ tester,
+ ) async {
+ await _open(tester);
+ expect(tester.widget<TextField>(_task).controller!.text, isEmpty);
+ expect(find.text('Tell your agent what to do first.'), findsOneWidget);
+ expect(_clear, findsNothing);
+ expect(
+ find.text('First task. What should your agent work on? (Optional)'),
+ findsOneWidget,
+ );
+ });
+
+ testWidgets('is sent as typed, trimmed at its ends', (tester) async {
+ final app = await _open(tester);
+ await _pickFolder(tester);
+ await tester.ensureVisible(_task);
+ await tester.enterText(
+ _task,
+ ' Fix the failing tests.\n\n Then push. \n',
+ );
+ await tester.pump();
+ expect(_clear, findsOneWidget);
+ await _create(tester);
+ expect(app.prompts, ['Fix the failing tests.\n\n Then push.']);
+ });
+
+ testWidgets('only spaces and new lines sends nothing', (tester) async {
+ final app = await _open(tester);
+ await _pickFolder(tester);
+ await tester.ensureVisible(_task);
+ await tester.enterText(_task, ' \n\t \n ');
+ await tester.pump();
+ await _create(tester);
+ expect(app.prompts, [null]);
+ });
+
+ testWidgets('a prompt of only spaces opens an empty task', (tester) async {
+ final app = await _open(tester, initialPrompt: ' \n ');
+ expect(tester.widget<TextField>(_task).controller!.text, isEmpty);
+ expect(_clear, findsNothing);
+ await _pickFolder(tester);
+ await _create(tester);
+ expect(app.prompts, [null]);
+ });
+
+ testWidgets('an agent that cannot take one says so, keeps what was typed '
+ 'and sends nothing', (tester) async {
+ final app = await _open(tester, initialPrompt: 'Draw a desk lamp');
+ await _pickFolder(tester);
+ await chooseAgent(tester, 'cursor');
+ await tester.pumpAndSettle();
+ expect(
+ find.text(
+ 'First task. Cursor starts without one. Tell it once it opens.',
+ ),
+ findsOneWidget,
+ );
+ final field = tester.widget<TextField>(_task);
+ expect(field.enabled, isFalse);
+ expect(field.controller!.text, 'Draw a desk lamp');
+ expect(_clear, findsNothing, reason: 'a disabled field offers no clicks');
+ await _create(tester);
+ expect(app.prompts, [null]);
+
+ // Back on an agent that takes one: the same words, sent.
+ await tester.pumpAndSettle();
+ await chooseAgent(tester, 'claude');
+ await tester.pumpAndSettle();
+ expect(
+ find.text('First task. What should your agent work on? (Optional)'),
+ findsOneWidget,
+ );
+ expect(tester.widget<TextField>(_task).enabled, isTrue);
+ await _create(tester);
+ expect(app.prompts, [null, 'Draw a desk lamp']);
+ });
+
+ testWidgets('longer than a machine takes holds Create and says by how '
+ 'much, counted as the machine counts', (tester) async {
+ final app = await _open(tester);
+ await _pickFolder(tester);
+ await chooseAgent(tester, 'claude');
+ await tester.pumpAndSettle();
+ bool createEnabled() =>
+ tester.widget<ButtonStyleButton>(_submit).onPressed != null;
+ expect(createEnabled(), isTrue);
+
+ await tester.ensureVisible(_task);
+ await tester.enterText(_task, 'x' * 2001);
+ await tester.pump();
+ expect(
+ find.text(
+ 'A first task can be up to 2000 characters. This one is 2001.',
+ ),
+ findsOneWidget,
+ );
+ expect(createEnabled(), isFalse);
+ // Neither the button nor the keyboard creates.
+ await tester.tap(_task);
+ await tester.sendKeyDownEvent(LogicalKeyboardKey.metaLeft);
+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);
+ await tester.sendKeyUpEvent(LogicalKeyboardKey.metaLeft);
+ await tester.pump();
+ expect(app.prompts, isEmpty);
+
+ // The machine counts after trimming, and so does this.
+ await tester.enterText(_task, ' ${'x' * 2000}\n ');
+ await tester.pump();
+ expect(find.textContaining('A first task can be up to'), findsNothing);
+ expect(createEnabled(), isTrue);
+ await _create(tester);
+ expect(app.prompts, ['x' * 2000]);
+ await tester.pumpAndSettle();
+
+ // On an agent that cannot take a task at all, its length holds nothing.
+ await tester.enterText(_task, 'x' * 2500);
+ await tester.pump();
+ expect(createEnabled(), isFalse);
+ await chooseAgent(tester, 'cursor');
+ await tester.pumpAndSettle();
+ expect(find.textContaining('A first task can be up to'), findsNothing);
+ expect(createEnabled(), isTrue);
+ await _create(tester);
+ expect(app.prompts, ['x' * 2000, null]);
+ expect(tester.takeException(), isNull);
+ });
+
+ testWidgets('is locked while the harness is being created, and '
+ 'unlocked when that fails', (tester) async {
+ final app = await _open(tester, initialPrompt: 'Draw a desk lamp');
+ app.pendingCreate = Completer<String?>();
+ await _pickFolder(tester);
+ await _create(tester);
+ expect(app.prompts, ['Draw a desk lamp']);
+
+ bool excluded() => tester
+ .widgetList<ExcludeFocus>(
+ find.ancestor(of: _task, matching: find.byType(ExcludeFocus)),
+ )
+ .any((exclude) => exclude.excluding);
+ bool absorbed() => tester
+ .widgetList<AbsorbPointer>(
+ find.ancestor(of: _task, matching: find.byType(AbsorbPointer)),
+ )
+ .any((absorb) => absorb.absorbing);
+ AppIconButton clearButton() => tester.widget<AppIconButton>(_clear);
+
+ expect(excluded(), isTrue, reason: 'Tab cannot reach it mid-create');
+ expect(absorbed(), isTrue, reason: 'a click cannot reach it either');
+ expect(clearButton().onPressed, isNull);
+
+ app.pendingCreate!.complete('The machine refused.');
+ await tester.pumpAndSettle();
+ expect(excluded(), isFalse);
+ expect(absorbed(), isFalse);
+ expect(clearButton().onPressed, isNotNull);
+ await tester.tap(_clear);
+ await tester.pump();
+ expect(tester.widget<TextField>(_task).controller!.text, isEmpty);
+ });
+ });
+
+ testWidgets('the busy label ends in an ellipsis at 900 wide rather than '
+ 'pushing the button out of the footer', (tester) async {
+ final app = await _open(tester, size: const Size(900, 720));
+ app.pendingInstall = Completer<String?>();
+ await chooseAgent(tester, 'someone/long');
+ await _pickFolder(tester);
+ await _create(tester);
+ await tester.pump();
+ final label = find.descendant(
+ of: _submit,
+ matching: find.textContaining('Installing An Extraordinarily Long'),
+ );
+ expect(label, findsOneWidget);
+ expect(tester.widget<Text>(label).overflow, TextOverflow.ellipsis);
+ expect(tester.widget<Text>(label).maxLines, 1);
+ expect(tester.takeException(), isNull, reason: 'no overflow');
+ final dialog = tester.getRect(find.byType(Dialog));
+ expect(tester.getRect(_submit).right, lessThanOrEqualTo(dialog.right));
+ app.pendingInstall!.complete('Install refused.');
+ await tester.pumpAndSettle();
+ });
+}
diff --git a/desktop/test/swarm_async_test.dart b/desktop/test/swarm_async_test.dart
index 236128a6e..8327b7a4d 100644
--- a/desktop/test/swarm_async_test.dart
+++ b/desktop/test/swarm_async_test.dart
@@ -27,6 +27,7 @@ class _PendingConnection extends WsConn {
);
final reply = Completer<Map<String, dynamic>>();
final calls = <String>[];
+ final payloads = <Map<String, dynamic>>[];
@override
Future<Map<String, dynamic>> request(
String type, {
@@ -34,6 +35,7 @@ class _PendingConnection extends WsConn {
Duration timeout = const Duration(seconds: 20),
}) {
calls.add(type);
+ payloads.add(payload);
return reply.future;
}
@@ -100,6 +102,23 @@ void main() {
null,
'Update the harness CLI on this machine to create a harness',
),
+ // Refused at the wire before any pane exists: a definite no, never
+ // "check status".
+ (
+ 'PROMPT_TOO_LONG',
+ 'prompt is longer than 2000 characters',
+ 'This first task is too long for Test host. Shorten it and try again.',
+ ),
+ (
+ 'INVALID_PROMPT',
+ 'prompt must be a string',
+ 'Create harness failed: prompt must be a string',
+ ),
+ (
+ 'PROMPT_UNSUPPORTED',
+ null,
+ 'This engine cannot be opened with a first message on Test host.',
+ ),
(
'SPAWN_FAILED',
'The machine could not allocate an agent process.',
@@ -131,6 +150,44 @@ void main() {
);
}
+ test('a first task travels on agent_create as given, and no task sends no '
+ 'field', () async {
+ final connection = _PendingConnection();
+ final app = createApp(connectionForTest: (_) => connection);
+ addTearDown(app.dispose);
+ final withTask = app.createAgent(
+ 'm',
+ engine: 'claude',
+ folder: '/work',
+ prompt: 'Fix the failing tests.\nThen push.',
+ );
+ await Future<void>.delayed(Duration.zero);
+ expect(connection.calls, ['agent_create']);
+ expect(
+ connection.payloads.single['prompt'],
+ 'Fix the failing tests.\nThen push.',
+ );
+ connection.complete();
+ await withTask;
+
+ final bare = _PendingConnection();
+ final plain = createApp(connectionForTest: (_) => bare);
+ addTearDown(plain.dispose);
+ final withoutTask = plain.createAgent(
+ 'm',
+ engine: 'codex',
+ folder: '/work',
+ );
+ await Future<void>.delayed(Duration.zero);
+ expect(
+ bare.payloads.single.containsKey('prompt'),
+ isFalse,
+ reason: 'a machine that knows the field refuses it for some engines',
+ );
+ bare.complete();
+ await withoutTask;
+ });
+
test(
'an unconfirmed creation is not presented as a definite failure',
() async {