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.

fix(mobile): small New form fixes

tonyb6a8be70bfc9
diff --git a/mobile/lib/core/first_task.dart b/mobile/lib/core/first_task.dart
index 4ff3e22f5..3356645ee 100644
--- a/mobile/lib/core/first_task.dart
+++ b/mobile/lib/core/first_task.dart
@@ -3,8 +3,9 @@
/// 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`).
-const kFirstTaskEngines = {'claude', 'codex', 'opencode'};
+/// other engine (`PROMPT_UNSUPPORTED`). test/first_task_test.dart holds the two lists to the same
+/// answer: one missing here is an engine whose first task New drops without a word.
+const kFirstTaskEngines = {'claude', 'codex', 'opencode', 'hermes'};
/// Whether a harness on [engine] can start on a first task.
bool takesFirstTask(String engine) => kFirstTaskEngines.contains(engine);
@@ -12,3 +13,15 @@ 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;
+
+/// What New says to a first task longer than [kFirstTaskMaxLength], in the desktop's words, or
+/// null while it fits. Counted after trimming, as the machine counts.
+///
+/// ⚠️ Said, never fixed by cutting: a task cut to fit is not the one that was written, and the
+/// person is the one to choose what goes.
+String? firstTaskLengthError(String task) {
+ final length = task.trim().length;
+ if (length <= kFirstTaskMaxLength) return null;
+ return 'A first message can be $kFirstTaskMaxLength characters; '
+ 'this is $length.';
+}
diff --git a/mobile/lib/phone/new_agent_chooser.dart b/mobile/lib/phone/new_agent_chooser.dart
index 7c24ead57..41de839e6 100644
--- a/mobile/lib/phone/new_agent_chooser.dart
+++ b/mobile/lib/phone/new_agent_chooser.dart
@@ -47,7 +47,11 @@ class ChooserItem<T> {
/// current value, and the `+` actions ending it. A tap picks and closes.
///
/// Long lists scroll in full. [autofocusSearch] always shows the search field and opens its keyboard.
-Future<T?> showNewAgentChooser<T>(
+///
+/// ⚠️ **Null is the sheet put away, so no row's value may be null** — hence `T extends Object`. The
+/// Profile chooser's Default row once was, and a pull down came back as "Default", resetting the
+/// profile it was meant to leave alone. A choice of "none" travels inside a value of its own.
+Future<T?> showNewAgentChooser<T extends Object>(
BuildContext context, {
required String hint,
required List<ChooserItem<T>> items,
diff --git a/mobile/lib/phone/new_agent_page.dart b/mobile/lib/phone/new_agent_page.dart
index 865f9ee26..652a940ff 100644
--- a/mobile/lib/phone/new_agent_page.dart
+++ b/mobile/lib/phone/new_agent_page.dart
@@ -199,8 +199,23 @@ class _NewAgentPageState extends State<NewAgentPage> {
}
/// The first task — `prompt` on `agent_create`. Optional: empty starts the harness idle.
+ ///
+ /// ⚠️ **No length limit on the field.** One cut whatever was typed or pasted past
+ /// [kFirstTaskMaxLength] without a word, and what the mic added went past it unchecked. Start
+ /// says so instead, and sends nothing — see [_lengthError].
final _task = TextEditingController();
+ /// What Start said about the task's length, while it is the line under the task. Editing the
+ /// task keeps it true: the count follows the words, and the line goes once they fit.
+ String? _lengthError;
+
+ /// The task changed — typed, pasted or said.
+ void _taskEdited(String text) => setState(() {
+ if (_lengthError != null && _error == _lengthError) {
+ _error = _lengthError = firstTaskLengthError(text);
+ }
+ });
+
/// Made on the first tap of the mic, not before: a recorder opens a platform channel, and a
/// form nobody talks to should not.
VoiceInputController? _ownVoice;
@@ -226,7 +241,7 @@ class _NewAgentPageState extends State<NewAgentPage> {
text: next,
selection: TextSelection.collapsed(offset: next.length),
);
- setState(() {});
+ _taskEdited(next);
return true;
}),
);
@@ -702,6 +717,18 @@ class _NewAgentPageState extends State<NewAgentPage> {
// Taken after the wait, not before it: the answer can move the form to the folder's own
// repository (a worktree's main checkout), and Start goes where the form says now.
final folder = _folder, project = _project;
+ // The first task as it is sent, read after the wait too: the field stays open through it. An
+ // engine that cannot take one is sent none.
+ final task = takesFirstTask(engine) ? _task.text.trim() : '';
+ // Shortened by the person, never cut here: a machine refuses a longer one, and a task cut to
+ // fit is not the one that was written. The desktop's check, in its words.
+ if (firstTaskLengthError(task) case final tooLong?) {
+ setState(() {
+ _creating = false;
+ _error = _lengthError = tooLong;
+ });
+ return;
+ }
// Held so the id of what it starts comes back here — see
// [AgentCreationAttempt.agentId] — and kept as [_creation] for as long as
// its answer is outstanding.
@@ -712,11 +739,7 @@ class _NewAgentPageState extends State<NewAgentPage> {
// that is not a repository, or one this form never read, falls through to
// the plain path — and `New project` / `Git…` keep the request they made.
// A New folder is named after the first task when there is one to send — the phone has no name
- // field, and five `codex-2026-…` folders told nobody which was which (openharness#94). The agent
- // takes the same words until its engine titles the session.
- final task = engine == 'terminal' || !takesFirstTask(engine)
- ? ''
- : _task.text;
+ // field, and five `codex-2026-…` folders told nobody which was which (openharness#94).
final namedByTask =
project != null &&
project.repository == null &&
@@ -750,8 +773,12 @@ class _NewAgentPageState extends State<NewAgentPage> {
codexHome: _showsCodexProfile ? _codexProfile?.path : null,
model: _model,
attempt: creation,
- prompt: _engine != null && takesFirstTask(_engine!) ? _task.text : null,
- name: namedByTask ? taskProjectTitle(task) : null,
+ prompt: task.isEmpty ? null : task,
+ // Whenever a first task is sent, the harness is called by its words until the engine titles
+ // the session — in any project, the desktop's rule. Named only for a New folder, a second
+ // harness in an existing one read "Untitled Pane" until then. Nothing to say leaves the name
+ // to the machine.
+ name: task.isEmpty ? null : taskProjectTitle(task),
);
_answered(creation, engine, error);
}
@@ -1151,9 +1178,8 @@ class _NewAgentPageState extends State<NewAgentPage> {
controller: _task,
hint: 'What should it do?',
lines: 6,
- maxLength: kFirstTaskMaxLength,
action: TextInputAction.newline,
- onChanged: (_) => setState(() {}),
+ onChanged: _taskEdited,
trailing: [
Align(
alignment: Alignment.bottomRight,
@@ -1549,13 +1575,13 @@ class _NewAgentPageState extends State<NewAgentPage> {
}
Future<void> _chooseProfile() async {
- final picked = await showNewAgentChooser<LocalCodexProfile?>(
+ final picked = await showNewAgentChooser<_ProfileChoice>(
context,
title: 'Profile',
hint: 'Search profiles',
items: [
ChooserItem(
- value: null,
+ value: const _ProfileChoice(null),
title: 'Default',
subtitle: _codexProfilesLoaded ? null : 'Looking for others…',
icon: LucideIcons.user300,
@@ -1563,7 +1589,7 @@ class _NewAgentPageState extends State<NewAgentPage> {
),
for (final profile in _codexProfiles)
ChooserItem(
- value: profile,
+ value: _ProfileChoice(profile),
title: profile.label,
subtitle: profile.path,
icon: LucideIcons.user300,
@@ -1571,8 +1597,9 @@ class _NewAgentPageState extends State<NewAgentPage> {
),
],
);
- if (!mounted) return;
- setState(() => _codexProfile = picked);
+ // Put away without a pick: the profile stays what it was. Default is a pick, of no profile.
+ if (picked == null || !mounted) return;
+ setState(() => _codexProfile = picked.profile);
}
/// The branch row: the picker, and the name dialog behind its first entry.
@@ -1779,6 +1806,15 @@ class _ProjectChoice {
final String? folder;
}
+/// What the Profile chooser hands back: a profile, or none for Default. Wrapped because the sheet
+/// answers null when it is put away, and Default read that way reset a profile nobody unchose — the
+/// model sheet's [NewAgentModelChoice] for the same reason.
+class _ProfileChoice {
+ const _ProfileChoice(this.profile);
+
+ final LocalCodexProfile? profile;
+}
+
/// A computer's project choice, held while the form is on another computer — see
/// `_projectsByMachine`.
typedef _KeptProject = ({
diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dart
index 147c22fd3..07f73d8e2 100644
--- a/mobile/lib/state/app_state.dart
+++ b/mobile/lib/state/app_state.dart
@@ -5748,8 +5748,8 @@ class AppNotifier extends ChangeNotifier {
final task = prompt?.trim();
final choices = <String, dynamic>{
'engine': engine,
- // The harness's first task — the machine types it into the agent once it is up. Only
- // claude, codex and opencode take one (see `kFirstTaskEngines`); an empty one is left out.
+ // The harness's first task — the machine types it into the agent once it is up. Only the
+ // engines in `kFirstTaskEngines` take one; an empty one is left out.
if (task != null && task.isNotEmpty) 'prompt': task,
// What the agent is called until its engine titles the session. Absent, the machine names it
// after the engine and the time ("Codex harness 9-17 15:26").
diff --git a/mobile/test/first_task_test.dart b/mobile/test/first_task_test.dart
new file mode 100644
index 000000000..8d2774d6c
--- /dev/null
+++ b/mobile/test/first_task_test.dart
@@ -0,0 +1,82 @@
+// What a machine accepts as a first task, as the phone 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 — the
+// desktop's `test/first_task_test.dart`, for the phone's copy. Hermes takes a first task there and
+// was missing here, so New dropped its task without a word.
+import 'dart:io';
+
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness_mobile/core/first_task.dart';
+import 'package:harness_mobile/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',
+ };
+ // Engines whose launch moved into an engine contract (cli/src/engines/<id>/launch.ts) are
+ // spread into the table from there; read them where they are declared.
+ if (table.group(1)!.contains("...launchField('firstPromptArgs')")) {
+ final launches = RegExp(
+ r'export const engineLaunches = \{([^}]*)\}',
+ ).firstMatch(File('../cli/src/engines/launches.ts').readAsStringSync());
+ expect(
+ launches,
+ isNotNull,
+ reason: 'engineLaunches moved or changed shape',
+ );
+ for (final id in launches!.group(1)!.split(',').map((s) => s.trim())) {
+ if (id.isEmpty) continue;
+ final contract = RegExp(r'firstPromptArgs:\s*(null|\[)').firstMatch(
+ File('../cli/src/engines/$id/launch.ts').readAsStringSync(),
+ );
+ expect(contract, isNotNull, reason: '$id has no firstPromptArgs');
+ entries.putIfAbsent(id, () => contract!.group(1) != 'null');
+ }
+ }
+ expect(entries, isNotEmpty);
+ expect({
+ for (final e in entries.entries)
+ if (e.value) e.key,
+ }, kFirstTaskEngines);
+ expect(takesFirstTask('hermes'), isTrue);
+ // Every engine the phone 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)!));
+ });
+
+ test('one over the limit is refused in the desktop\'s words, counted after '
+ 'trimming', () {
+ expect(firstTaskLengthError('x' * kFirstTaskMaxLength), isNull);
+ // Space around it is not the task, and not counted — the machine trims before it counts.
+ expect(firstTaskLengthError(' ${'x' * kFirstTaskMaxLength}\n\n'), isNull);
+ expect(firstTaskLengthError(''), isNull);
+ expect(
+ firstTaskLengthError('x' * (kFirstTaskMaxLength + 1)),
+ 'A first message can be 2000 characters; this is 2001.',
+ );
+ });
+}
diff --git a/mobile/test/phone_edge/new_behavior_test.dart b/mobile/test/phone_edge/new_behavior_test.dart
index 83ab8a8fc..7077b43e7 100644
--- a/mobile/test/phone_edge/new_behavior_test.dart
+++ b/mobile/test/phone_edge/new_behavior_test.dart
@@ -654,6 +654,195 @@ void main() {
await close(tester, app);
});
+ for (final pickDefault in [false, true]) {
+ testWidgets('the Profile sheet put away keeps the profile'
+ '${pickDefault ? '; Default clears it' : ''}', (tester) async {
+ final (:app, :conn) = await openNew(tester);
+ await choose(tester, 'agent', 'Codex');
+ await tapInView(tester, find.text('options'));
+ await frames(tester);
+ await choose(tester, 'profile', 'work');
+ expect(formRow(tester, 'profile').value, 'work');
+
+ // A tap above the sheet: nothing was picked, so nothing changes. It once came back as
+ // Default, whose value is no profile.
+ await tapInView(tester, find.text('profile'));
+ await frames(tester);
+ expect(find.text('Profile'), findsOneWidget);
+ await tester.tapAt(tester.getCenter(find.byType(ModalBarrier).last));
+ await frames(tester);
+ expect(find.text('Profile'), findsNothing);
+ expect(formRow(tester, 'profile').value, 'work');
+
+ if (pickDefault) {
+ await choose(tester, 'profile', 'Default');
+ expect(formRow(tester, 'profile').value, 'Default');
+ }
+ await tapInView(tester, find.text('Start'));
+ await frames(tester, count: 20);
+ final created = conn.payloads['agent_create']!.single;
+ expect(created['engine'], 'codex');
+ if (pickDefault) {
+ expect(created.containsKey('codexHome'), isFalse);
+ } else {
+ expect(created['codexHome'], '/home/ada/.codex-work');
+ }
+ await close(tester, app);
+ });
+ }
+
+ group('the first task', () {
+ /// The task as the field holds it.
+ String task(WidgetTester tester) =>
+ tester.widget<TextField>(find.byType(TextField)).controller!.text;
+
+ /// Picks [engine] in the agent chooser by searching for it: the list is longer than a screen.
+ Future<void> chooseAgent(WidgetTester tester, String engine) async {
+ await tapInView(tester, find.text('agent'));
+ await frames(tester);
+ await tester.enterText(find.byType(TextField).last, engine);
+ await frames(tester);
+ await tester.tap(find.text(engine, findRichText: true).last);
+ await frames(tester);
+ }
+
+ testWidgets('Hermes starts on its first task', (tester) async {
+ final (:app, :conn) = await openNew(tester);
+ await chooseAgent(tester, 'Hermes');
+ expect(formRow(tester, 'agent').value, 'Hermes');
+ await tester.enterText(
+ find.byType(TextField),
+ 'summarise the open issues',
+ );
+ await tapInView(tester, find.text('Start'));
+ await frames(tester, count: 20);
+ final created = conn.payloads['agent_create']!.single;
+ expect(created['engine'], 'hermes');
+ expect(created['prompt'], 'summarise the open issues');
+ await close(tester, app);
+ });
+
+ testWidgets('typed or pasted past the limit: kept whole; Start says so and '
+ 'sends nothing, and starts once it fits', (tester) async {
+ final (:app, :conn) = await openNew(tester);
+ await tester.enterText(find.byType(TextField), 'x' * 2001);
+ await tester.pump();
+ expect(task(tester), hasLength(2001));
+ expect(find.text('2001/2000'), findsOneWidget);
+
+ await tapInView(tester, find.text('Start'));
+ await frames(tester, count: 20);
+ expect(conn.payloads['agent_create'], isNull);
+ expect(find.byType(NewAgentPage), findsOneWidget);
+ expect(
+ find.text('✗ A first message can be 2000 characters; this is 2001.'),
+ findsOneWidget,
+ );
+ expect(task(tester), hasLength(2001));
+
+ // The line follows the words: still over, it says how far; once they fit, it goes.
+ await tester.enterText(find.byType(TextField), 'x' * 2005);
+ await tester.pump();
+ expect(
+ find.text('✗ A first message can be 2000 characters; this is 2005.'),
+ findsOneWidget,
+ );
+ // The space around a task is not counted, as the machine does not count it.
+ await tester.enterText(find.byType(TextField), ' ${'x' * 2000}\n');
+ await tester.pump();
+ expect(find.textContaining('A first message can be'), findsNothing);
+
+ await tapInView(tester, find.text('Start'));
+ await frames(tester, count: 20);
+ expect(conn.payloads['agent_create']!.single['prompt'], 'x' * 2000);
+ await close(tester, app);
+ });
+
+ testWidgets('said past the limit: kept whole; Start says so and sends '
+ 'nothing', (tester) async {
+ setPhone(tester, largePhone);
+ final conn = EdgeConn(answers, startsAgents);
+ final app = edgeApp(conn: conn);
+ final voice = edgeVoice();
+ voice.stt.replies.add('y' * 20);
+ await tester.pumpWidget(
+ phoneApp(
+ NewAgentPage(notifier: app, machineId: 'm', voice: voice.voice),
+ ),
+ );
+ await frames(tester);
+ await tester.enterText(find.byType(TextField), 'x' * 1990);
+ await tester.tap(find.byType(TtyFieldMic));
+ await frames(tester);
+ await tester.tap(find.byType(TtyFieldMic));
+ await frames(tester);
+ expect(task(tester), '${'x' * 1990} ${'y' * 20}');
+
+ await tapInView(tester, find.text('Start'));
+ await frames(tester, count: 20);
+ expect(conn.payloads['agent_create'], isNull);
+ expect(
+ find.text('✗ A first message can be 2000 characters; this is 2011.'),
+ findsOneWidget,
+ );
+ expect(task(tester), hasLength(2011));
+ await close(tester, app);
+ });
+
+ testWidgets('a task in a folder that exists names the harness after it', (
+ tester,
+ ) async {
+ final (:app, :conn) = await openNew(tester);
+ expect(formRow(tester, 'project').value, 'web');
+ await tester.enterText(
+ find.byType(TextField),
+ 'Fix the login redirect loop on Safari\nand say what changed',
+ );
+ await tapInView(tester, find.text('Start'));
+ await frames(tester, count: 20);
+ final created = conn.payloads['agent_create']!.single;
+ expect(
+ created['prompt'],
+ 'Fix the login redirect loop on Safari\nand say what changed',
+ );
+ expect(created['name'], 'Fix the login redirect loop on');
+ // The folder is the one chosen: only a New folder is named by the task.
+ expect(created['gitSource'], '/code/web');
+ expect(created.containsKey('projectName'), isFalse);
+ await close(tester, app);
+ });
+
+ testWidgets('no task: no name and no task sent', (tester) async {
+ final (:app, :conn) = await openNew(tester);
+ await tester.enterText(find.byType(TextField), ' \n ');
+ await tapInView(tester, find.text('Start'));
+ await frames(tester, count: 20);
+ final created = conn.payloads['agent_create']!.single;
+ expect(created.containsKey('prompt'), isFalse);
+ expect(created.containsKey('name'), isFalse);
+ await close(tester, app);
+ });
+
+ testWidgets('a New folder is named after its task, and the harness too', (
+ tester,
+ ) async {
+ final (:app, :conn) = await openNew(tester);
+ await choose(tester, 'project', '+ New Folder');
+ await tester.enterText(
+ find.byType(TextField),
+ 'Robot nói chuyện với Gemini',
+ );
+ await tapInView(tester, find.text('Start'));
+ await frames(tester, count: 20);
+ final created = conn.payloads['agent_create']!.single;
+ expect(created['projectSource'], 'new');
+ expect(created['projectName'], 'robot-noi-chuyen-voi-gemini');
+ expect(created['name'], 'Robot nói chuyện với Gemini');
+ expect(created['prompt'], 'Robot nói chuyện với Gemini');
+ await close(tester, app);
+ });
+ });
+
group('the computer row', () {
testWidgets('a row of its own, between agent and project; the project row '
'names only the project', (tester) async {