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.

feat(mobile): New Harness asks what the desktop's own launcher asks

bubu-dudue1da664b1d46
diff --git a/mobile/lib/core/permission_modes.dart b/mobile/lib/core/permission_modes.dart
new file mode 100644
index 000000000..70bd167c0
--- /dev/null
+++ b/mobile/lib/core/permission_modes.dart
@@ -0,0 +1,96 @@
+/// How far a new harness may go without asking — New Harness ▸ Approvals.
+///
+/// Mirrors the CLI's `PERMISSION_MODES` (cli/src/lib/engineLaunch.ts) mode for mode: this is the
+/// menu, the CLI is what turns a mode into flags and refuses one an engine lacks. An engine absent
+/// here offers no choice. Keep both tables in step.
+///
+/// ⚠️ **A copy of `desktop/lib/core/permission_modes.dart`, and it has to stay one.** The two apps
+/// send the same `permissionMode` to the same daemon, so a mode worded differently on a phone is
+/// the same launch described two ways — and a mode present on one side only is a harness a person
+/// cannot make from the other. This file is the phone's half; change neither alone.
+library;
+
+class PermissionMode {
+ const PermissionMode(this.id, this.label, this.detail, {this.risky = false});
+
+ /// What the machine is sent (`agent_create`'s `permissionMode`).
+ final String id;
+ final String label;
+ final String detail;
+
+ /// Turns off the engine's own safety net; worded as such in the menu.
+ final bool risky;
+}
+
+/// The default for every engine that has modes.
+const kDefaultPermissionMode = 'auto';
+
+const _auto = 'auto';
+const _ask = 'ask';
+
+const Map<String, List<PermissionMode>> kEnginePermissionModes = {
+ 'claude': [
+ PermissionMode(
+ _auto,
+ 'Auto-approve',
+ 'Approves routine actions, checks risky ones',
+ ),
+ PermissionMode(
+ 'acceptEdits',
+ 'Accept edits',
+ 'Edits files freely, asks before commands',
+ ),
+ PermissionMode(
+ 'plan',
+ 'Plan first',
+ 'Reads and plans, changes nothing until you agree',
+ ),
+ PermissionMode(
+ _ask,
+ 'Ask first',
+ 'Asks before acting, as Claude Code does',
+ ),
+ PermissionMode(
+ 'full',
+ 'Skip all checks',
+ 'No approvals and no safety checks. Risky',
+ risky: true,
+ ),
+ ],
+ 'codex': [
+ PermissionMode(
+ 'readOnly',
+ 'Read only',
+ 'Reads and suggests, asks before any change',
+ ),
+ PermissionMode(_ask, 'Ask first', 'Asks before acting, as Codex does'),
+ PermissionMode(
+ _auto,
+ 'Auto-approve',
+ 'Approves routine actions in the sandbox',
+ ),
+ PermissionMode(
+ 'full',
+ 'Full access',
+ 'No approvals and no sandbox. Risky',
+ risky: true,
+ ),
+ ],
+ 'cursor': [
+ PermissionMode(_auto, 'Auto-approve', 'Runs commands without asking'),
+ PermissionMode(_ask, 'Ask first', 'Asks before running commands'),
+ ],
+ 'opencode': [
+ PermissionMode(_auto, 'Auto-approve', 'Approves actions on its own'),
+ PermissionMode(_ask, 'Ask first', 'Asks before acting'),
+ ],
+};
+
+/// The modes [engine] offers, or empty when it has none to choose between.
+List<PermissionMode> permissionModesOf(String engine) =>
+ kEnginePermissionModes[engine] ?? const [];
+
+/// Whether [mode] lets the agent act without stopping to ask — the yes/no a daemon that predates
+/// modes understands (`bypassPermission`). Plan and Read only read as no, so an older machine asks
+/// rather than approving on their behalf; Skip all checks reads as yes and gets Auto-approve there.
+bool permissionModeApproves(String mode) => mode == _auto || mode == 'full';
diff --git a/mobile/lib/phone/branch_picker_sheet.dart b/mobile/lib/phone/branch_picker_sheet.dart
index 680bb2991..176fb76aa 100644
--- a/mobile/lib/phone/branch_picker_sheet.dart
+++ b/mobile/lib/phone/branch_picker_sheet.dart
@@ -129,141 +129,161 @@ class _BranchPickerState extends State<_BranchPicker> {
return note == null ? null : SheetRowNote(note);
}
+ /// Puts the keyboard away and takes the caret out of the field — see the note on the project
+ /// picker's own [_dismissKeyboard], which had the same fault: the sheet closed and the keyboard
+ /// stayed, over the form underneath.
+ void _dismissKeyboard() => FocusManager.instance.primaryFocus?.unfocus();
+
@override
Widget build(BuildContext context) {
AppTheme.watch(context);
final matches = _matches;
final typed = widget.typedName;
- return SafeArea(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: [
- Padding(
- padding: const EdgeInsets.fromLTRB(kSheetInset, 0, kSheetInset, 10),
- child: PhoneSearchField(
- controller: _controller,
- focus: _focus,
- // ⚠️ Not autofocused. The list is worth reading first — most
- // repositories have a handful of branches and the answer is on
- // screen already; the keyboard would bury it.
- autofocus: false,
- hintText: 'Search branches',
- onChanged: (value) => setState(() => _query = value),
- onClear: () => setState(() {
- _controller.clear();
- _query = '';
- }),
- ),
- ),
- Flexible(
- child: ListView.builder(
- padding: EdgeInsets.fromLTRB(
+ return GestureDetector(
+ // Any tap that is not a row puts the keyboard away. A row's own detector is nearer the tap
+ // and still wins.
+ behavior: HitTestBehavior.opaque,
+ onTap: _dismissKeyboard,
+ child: SafeArea(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Padding(
+ padding: const EdgeInsets.fromLTRB(
kSheetInset,
0,
kSheetInset,
- MediaQuery.paddingOf(context).bottom + 16,
+ 10,
),
- itemCount: matches.length + 1,
- itemBuilder: (context, index) {
- if (index == 0) {
- // First, because a branch nobody has yet is what most new
- // work starts on and it cannot be found by searching.
+ child: PhoneSearchField(
+ controller: _controller,
+ focus: _focus,
+ // ⚠️ Not autofocused. The list is worth reading first — most
+ // repositories have a handful of branches and the answer is on
+ // screen already; the keyboard would bury it.
+ autofocus: false,
+ hintText: 'Search branches',
+ onChanged: (value) => setState(() => _query = value),
+ onClear: () => setState(() {
+ _controller.clear();
+ _query = '';
+ }),
+ ),
+ ),
+ Flexible(
+ child: ListView.builder(
+ keyboardDismissBehavior:
+ ScrollViewKeyboardDismissBehavior.onDrag,
+ padding: EdgeInsets.fromLTRB(
+ kSheetInset,
+ 0,
+ kSheetInset,
+ MediaQuery.paddingOf(context).bottom + 16,
+ ),
+ itemCount: matches.length + 1,
+ itemBuilder: (context, index) {
+ if (index == 0) {
+ // First, because a branch nobody has yet is what most new
+ // work starts on and it cannot be found by searching.
+ return SheetRow(
+ first: true,
+ last: matches.isEmpty,
+ leading: SheetTile(
+ child: Icon(
+ LucideIcons.plus,
+ size: 18,
+ color: AppPalette.accentOnSurface,
+ ),
+ ),
+ title: Text(
+ typed == null ? 'New branch…' : 'New branch: $typed',
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: sheetRowTitleStyle().copyWith(
+ color: AppPalette.accentOnSurface,
+ ),
+ ),
+ onTap: () {
+ HapticFeedback.selectionClick();
+ _dismissKeyboard();
+ Navigator.of(context).pop(const BranchChoice.name(''));
+ },
+ );
+ }
+ final branch = matches[index - 1];
+ final chosen =
+ widget.typedName == null &&
+ branch.ref == widget.selectedRef;
return SheetRow(
- first: true,
- last: matches.isEmpty,
+ first: false,
+ last: index == matches.length,
leading: SheetTile(
child: Icon(
- LucideIcons.plus,
+ LucideIcons.gitBranch,
size: 18,
- color: AppPalette.accentOnSurface,
+ color: chosen
+ ? AppPalette.accentOnSurface
+ : AppPalette.textSecondary,
),
),
title: Text(
- typed == null ? 'New branch…' : 'New branch: $typed',
+ branch.name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
- style: sheetRowTitleStyle().copyWith(
- color: AppPalette.accentOnSurface,
- ),
+ style: sheetRowTitleStyle(),
+ ),
+ chevron: false,
+ selected: chosen,
+ // The note goes where a status would: `default · current` is
+ // what this branch IS, the same kind of fact.
+ // ⚠️ **The note and the tick sit side by side, and the note
+ // is never given up for it.** They were one slot, so the
+ // branch most likely to carry `default · current` — the one
+ // the form starts on — was also the one wearing the tick,
+ // and the two facts a person needs to tell those words apart
+ // were exactly the ones never shown.
+ trailing: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ ?_noteRow(branch),
+ if (chosen) ...[
+ const SizedBox(width: 8),
+ Icon(
+ LucideIcons.check300,
+ size: 18,
+ color: AppPalette.accent,
+ ),
+ ],
+ ],
),
onTap: () {
HapticFeedback.selectionClick();
- Navigator.of(context).pop(const BranchChoice.name(''));
+ _dismissKeyboard();
+ Navigator.of(context).pop(BranchChoice.ref(branch.ref));
},
);
- }
- final branch = matches[index - 1];
- final chosen =
- widget.typedName == null &&
- branch.ref == widget.selectedRef;
- return SheetRow(
- first: false,
- last: index == matches.length,
- leading: SheetTile(
- child: Icon(
- LucideIcons.gitBranch,
- size: 18,
- color: chosen
- ? AppPalette.accentOnSurface
- : AppPalette.textSecondary,
- ),
- ),
- title: Text(
- branch.name,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: sheetRowTitleStyle(),
- ),
- chevron: false,
- selected: chosen,
- // The note goes where a status would: `default · current` is
- // what this branch IS, the same kind of fact.
- // ⚠️ **The note and the tick sit side by side, and the note
- // is never given up for it.** They were one slot, so the
- // branch most likely to carry `default · current` — the one
- // the form starts on — was also the one wearing the tick,
- // and the two facts a person needs to tell those words apart
- // were exactly the ones never shown.
- trailing: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- ?_noteRow(branch),
- if (chosen) ...[
- const SizedBox(width: 8),
- Icon(
- LucideIcons.check300,
- size: 18,
- color: AppPalette.accent,
- ),
- ],
- ],
- ),
- onTap: () {
- HapticFeedback.selectionClick();
- Navigator.of(context).pop(BranchChoice.ref(branch.ref));
- },
- );
- },
- ),
- ),
- if (matches.isEmpty && _query.trim().isNotEmpty)
- Padding(
- padding: const EdgeInsets.fromLTRB(
- kSheetCaptionInset,
- 0,
- kSheetInset,
- 12,
+ },
),
- child: Text(
- 'No branch matches “${_query.trim()}”. New branch… makes one.',
- style: TextStyle(
- color: AppPalette.textSecondary,
- fontSize: 13.5,
+ ),
+ if (matches.isEmpty && _query.trim().isNotEmpty)
+ Padding(
+ padding: const EdgeInsets.fromLTRB(
+ kSheetCaptionInset,
+ 0,
+ kSheetInset,
+ 12,
+ ),
+ child: Text(
+ 'No branch matches “${_query.trim()}”. New branch… makes one.',
+ style: TextStyle(
+ color: AppPalette.textSecondary,
+ fontSize: 13.5,
+ ),
),
),
- ),
- ],
+ ],
+ ),
),
);
}
diff --git a/mobile/lib/phone/new_agent_draft.dart b/mobile/lib/phone/new_agent_draft.dart
new file mode 100644
index 000000000..a406dd5ec
--- /dev/null
+++ b/mobile/lib/phone/new_agent_draft.dart
@@ -0,0 +1,62 @@
+import 'package:harness_mobile/core/codex_profiles.dart';
+import 'package:harness_mobile/core/git_project.dart';
+import 'package:harness_mobile/core/project_folder.dart';
+
+/// What the New Harness form was left holding, so opening it again comes back to it.
+///
+/// The desktop's `NewHarnessDraft` (`desktop/lib/state/new_harness.dart`), and kept the way the
+/// desktop keeps it: **in memory, for as long as the app runs**. Nothing here is written to disk.
+/// Closing the form is not the same as changing your mind about it — somebody who backed out to
+/// check which branch they meant should not have to name the folder, the engine and the approvals
+/// again — but a choice made yesterday is not an answer to a question asked today.
+///
+/// ⚠️ **Dropped once a harness is actually created, not kept.** The desktop closes its box with
+/// `keepDraft: false` on `onCreated` for the same reason: the draft exists to survive a
+/// cancellation, and a form that reopens pre-filled with the harness you just started is a second
+/// one waiting to be made by accident.
+///
+/// The engine alone outlives this, and always did — `AppNotifier.agentPreference` remembers it
+/// across launches, so a phone that has never opened this form still starts on the right one.
+class NewAgentDraft {
+ const NewAgentDraft({
+ required this.machineId,
+ required this.engine,
+ required this.permissionMode,
+ this.folder,
+ this.project,
+ this.projectLabel,
+ this.worktree,
+ this.branchRef,
+ this.branchName,
+ this.placeholder,
+ this.git,
+ this.gitFolder,
+ this.codexProfile,
+ });
+
+ final String machineId;
+ final String? engine;
+ final String permissionMode;
+
+ /// A folder that exists, or ([project]) one the machine is to make. Exactly one is ever set —
+ /// see the note on `_NewAgentPageState._project`.
+ final String? folder;
+ final ProjectFolderRequest? project;
+ final String? projectLabel;
+
+ final bool? worktree;
+ final String? branchRef, branchName, placeholder;
+
+ /// What the machine last said about [gitFolder], carried so reopening the form does not flash
+ /// an empty Branch section while a round trip to somebody's laptop repeats itself.
+ final GitProjectInfo? git;
+ final String? gitFolder;
+
+ final LocalCodexProfile? codexProfile;
+}
+
+/// The one draft, or null where there is nothing to come back to.
+///
+/// A plain variable rather than a notifier: nothing rebuilds when it changes. It is read once as
+/// the form is built and written once as it goes.
+NewAgentDraft? newAgentDraft;
diff --git a/mobile/lib/phone/new_agent_page.dart b/mobile/lib/phone/new_agent_page.dart
index 608691736..75e7d739b 100644
--- a/mobile/lib/phone/new_agent_page.dart
+++ b/mobile/lib/phone/new_agent_page.dart
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
import 'package:harness_mobile/core/codex_profiles.dart';
+import 'package:harness_mobile/core/permission_modes.dart';
import 'package:harness_mobile/shared/theme/app_theme.dart';
import 'package:harness_mobile/state/app_state.dart';
import 'package:harness_mobile/widgets/engine_identity.dart';
@@ -15,7 +16,9 @@ import 'agent_index.dart';
import 'branch_picker_sheet.dart';
import 'phone_header.dart';
import 'phone_navigation.dart';
+import 'new_agent_draft.dart';
import 'phone_status.dart';
+import 'project_picker_sheet.dart';
import 'settings_row.dart';
/// Starting an agent from the phone: a folder on that machine, and an engine to
@@ -93,11 +96,24 @@ class _NewAgentPageState extends State<NewAgentPage> {
LocalCodexProfile? _codexProfile;
bool _codexProfilesLoaded = false;
- /// Whether the Recent row is folded open.
+ /// How far the harness may go without asking — the desktop's Approvals row.
///
- /// Starts shut every time, and closes again on a pick: what it lists are answers, and once one is
- /// taken the list has nothing left to say.
- bool _recentOpen = false;
+ /// ⚠️ **Per engine, and reset with it.** Claude's "Accept edits" is not a mode Codex has, and a
+ /// mode an engine lacks is refused by the CLI at launch — so switching engine drops back to
+ /// [kDefaultPermissionMode] rather than carrying a choice across. See
+ /// `core/permission_modes.dart`.
+ String _permissionMode = kDefaultPermissionMode;
+
+ /// Whether the approval rows are folded open, like the engine list above them.
+ bool _approvalsOpen = false;
+
+ /// The modes the chosen engine offers, empty for one that has none to choose between — the row
+ /// is then left out rather than drawn dead.
+ List<PermissionMode> get _permissionModes =>
+ _engine == null ? const [] : permissionModesOf(_engine!);
+
+ PermissionMode? get _permissionModeChoice =>
+ _permissionModes.where((mode) => mode.id == _permissionMode).firstOrNull;
/// What the machine said about [_folder]'s repository, and which folder it
/// answered about.
@@ -139,6 +155,7 @@ class _NewAgentPageState extends State<NewAgentPage> {
@override
void initState() {
super.initState();
+ _restoreDraft();
// After the first frame, not during it: `probeEngines` can notify synchronously, and a notify
// while this page is still being mounted marks the listeners above it dirty mid-build — the
// "setState() called during build" assertion.
@@ -154,6 +171,71 @@ class _NewAgentPageState extends State<NewAgentPage> {
);
}
+ @override
+ void dispose() {
+ _keepDraft();
+ super.dispose();
+ }
+
+ /// Takes back what the form was left holding — see [NewAgentDraft].
+ ///
+ /// ⚠️ **The machine comes from the draft, not from the page's argument**, which is what the
+ /// desktop does (`_machineId = draft?.machineId ?? machineId`): the form was opened from a
+ /// terminal or a list that names ONE machine, and a draft that came back on a different one
+ /// would be a folder path belonging to a machine that has never heard of it.
+ ///
+ /// Nothing is restored for a machine the account no longer has. The whole draft goes with it,
+ /// rather than half of it: a folder and a branch are answers about a machine, and re-hanging
+ /// them on another is how a form comes back subtly wrong.
+ void _restoreDraft() {
+ final draft = newAgentDraft;
+ if (draft == null) return;
+ if (widget.notifier.stateOf(draft.machineId) == null) {
+ newAgentDraft = null;
+ return;
+ }
+ _machineId = draft.machineId;
+ _engine = draft.engine;
+ _permissionMode = draft.permissionMode;
+ _folder = draft.folder;
+ _project = draft.project;
+ _projectLabel = draft.projectLabel;
+ _worktree = draft.worktree ?? false;
+ _branchRef = draft.branchRef;
+ _branchName = draft.branchName;
+ _placeholder = draft.placeholder;
+ _git = draft.git;
+ _gitFolder = draft.gitFolder;
+ _codexProfile = draft.codexProfile;
+ }
+
+ /// Leaves the form's answers where the next open will find them. Called from [dispose], so it
+ /// covers every way out — Back, a swipe, the route being replaced — except the one that must
+ /// not be covered: [_create] clears the draft the moment a harness exists.
+ void _keepDraft() {
+ // Nothing chosen and nothing typed is not a draft; it is the form as it opens. Kept, it would
+ // pin the page to whichever machine was last looked at for the rest of the run.
+ if (_folder == null && _project == null && _branchName == null) {
+ newAgentDraft = null;
+ return;
+ }
+ newAgentDraft = NewAgentDraft(
+ machineId: _machineId,
+ engine: _engine,
+ permissionMode: _permissionMode,
+ folder: _folder,
+ project: _project,
+ projectLabel: _projectLabel,
+ worktree: _worktree,
+ branchRef: _branchRef,
+ branchName: _branchName,
+ placeholder: _placeholder,
+ git: _git,
+ gitFolder: _gitFolder,
+ codexProfile: _codexProfile,
+ );
+ }
+
/// What this form needs to hear from [_machineId]: its engines and its Codex profiles.
void _askMachine() {
// Which engines this machine actually has. Best effort: an unanswered probe
@@ -180,7 +262,6 @@ class _NewAgentPageState extends State<NewAgentPage> {
_folder = null;
_project = null;
_projectLabel = null;
- _recentOpen = false;
_git = null;
_gitFolder = null;
_gitLoading = false;
@@ -276,13 +357,20 @@ class _NewAgentPageState extends State<NewAgentPage> {
? 'A fresh folder, made on the machine'
: null);
- String get _engineLabel => _engine == null
- ? 'Choose an agent'
- : allEngines
- .where((identity) => identity.id == _engine)
- .firstOrNull
- ?.label ??
- _engine!;
+ String get _engineLabel =>
+ _engine == null ? 'Choose an agent' : _engineName(_engine!);
+
+ /// What this form calls an engine.
+ ///
+ /// ⚠️ **"Claude Code", not "Claude", and only here.** The desktop's launcher says the same
+ /// (`new_harness.dart`: `id == 'claude' ? 'Claude Code' : engineIdentity(id).label`) while its
+ /// engine table keeps the bare `Claude` for everywhere else — a pane header, a row on the Agents
+ /// list. The launcher is the one screen naming the PROGRAM rather than the harness running it,
+ /// and "Claude" alone reads there as a model.
+ String _engineName(String id) => id == 'claude'
+ ? 'Claude Code'
+ : allEngines.where((identity) => identity.id == id).firstOrNull?.label ??
+ id;
/// What the BRANCH row says is about to happen, in the words of the thing it
/// will do. Null leaves the row showing the branch alone.
@@ -392,12 +480,6 @@ class _NewAgentPageState extends State<NewAgentPage> {
bool get _browsed => _folder != null && !_recent.contains(_folder);
/// The recent folder currently chosen, for the folded row to show, or null.
- String? get _pickedRecent =>
- _folder != null && _recent.contains(_folder) ? _folder : null;
-
- String get _recentCount =>
- _recent.length == 1 ? '1 folder' : '${_recent.length} folders';
-
/// The last segment of a path, for the row's title. No `package:path` here — these are the remote
/// machine's paths, and its separator is not this device's to assume.
String _basename(String path) {
@@ -492,6 +574,27 @@ class _NewAgentPageState extends State<NewAgentPage> {
unawaited(_loadGit(chosen));
}
+ /// The searchable list of folders already worked in — the desktop's project menu, which is the
+ /// same history this page's Recent row lists.
+ ///
+ /// ⚠️ **It folds Recent shut on the way back.** Both are the same list, and leaving one open
+ /// under an answer taken from the other left the folder ticked in two places at once.
+ Future<void> _searchProject() async {
+ final chosen = await showProjectPickerSheet(
+ context,
+ folders: _recent,
+ selected: _folder,
+ );
+ if (chosen == null || !mounted) return;
+ setState(() {
+ _folder = chosen;
+ _project = null;
+ _projectLabel = null;
+ _error = null;
+ });
+ unawaited(_loadGit(chosen));
+ }
+
Future<void> _create() async {
final folder = _folder, engine = _engine, project = _project;
if ((folder == null && project == null) || engine == null || _creating) {
@@ -529,6 +632,9 @@ class _NewAgentPageState extends State<NewAgentPage> {
// this required so the ordinary case cannot be left out by accident.
folder: folder ?? '',
projectFolder: request,
+ // Omitted for an engine with no modes, rather than sent as the default: the CLI refuses a
+ // mode an engine lacks, and "the default" is the machine's to decide there.
+ permissionMode: _permissionModes.isEmpty ? null : _permissionMode,
// Only for Codex, and only when chosen: omitted, the machine launches
// with its own default CODEX_HOME.
codexHome: _showsCodexProfile ? _codexProfile?.path : null,
@@ -536,6 +642,9 @@ class _NewAgentPageState extends State<NewAgentPage> {
);
if (!mounted) return;
if (error == null) {
+ // The harness exists: the draft that described it would be a second one waiting to be made
+ // by accident. See [NewAgentDraft].
+ newAgentDraft = null;
_open(creation.agentId);
return;
}
@@ -670,37 +779,51 @@ class _NewAgentPageState extends State<NewAgentPage> {
setState(() => _projectOpen = !_projectOpen),
),
if (_projectOpen) ...[
+ // ⚠️ **First, and above the three ways of naming a folder the machine
+ // does not know yet** — the desktop's own order, and the right one: on a
+ // machine that has been worked on, the answer is nearly always a folder
+ // that already exists. Absent where there is no history to search; the
+ // Recent row below is absent then too, for the same reason.
+ if (_recent.isNotEmpty)
+ SettingsRow(
+ title: 'Search project',
+ nested: true,
+ detail: 'Find one by name or path',
+ leading: Icon(
+ LucideIcons.search300,
+ size: 18,
+ color: AppPalette.textSecondary,
+ ),
+ trailing: Icon(
+ LucideIcons.chevronRight300,
+ size: 18,
+ color: AppPalette.textFaint,
+ ),
+ onTap: () => unawaited(_searchProject()),
+ ),
SettingsRow(
- title: 'New project',
+ title: 'Clone Repository',
nested: true,
detail:
_projectSourceNote ??
- 'A fresh folder, made on the machine',
+ (_project?.repository == null
+ ? 'Clone a GitHub repository'
+ : _projectLabel),
leading: Icon(
- LucideIcons.folderPlus300,
+ LucideIcons.gitBranch300,
size: 18,
color: AppPalette.textSecondary,
),
- trailing: _check(
- _project != null && _project!.repository == null,
- ),
+ trailing: _check(_project?.repository != null),
onTap: !_canMakeProject
? null
- : () => setState(() {
- _project =
- const ProjectFolderRequest.newProject();
- _projectLabel = 'New project';
- _folder = null;
- _git = null;
- _gitFolder = null;
- _error = null;
- }),
+ : () => unawaited(_pickRepository()),
),
// Shows its path only when the choice is this row's own. A folder picked
// from RECENT below is already named there, and printing it here too would
// put one answer under two ticks.
SettingsRow(
- title: 'Browse…',
+ title: 'Open Folder',
nested: true,
detail: _browsed ? _folder : null,
leading: Icon(
@@ -712,73 +835,31 @@ class _NewAgentPageState extends State<NewAgentPage> {
onTap: () => unawaited(_browse()),
),
SettingsRow(
- title: 'Git…',
+ title: 'New Project',
nested: true,
detail:
_projectSourceNote ??
- (_project?.repository == null
- ? 'Clone a GitHub repository'
- : _projectLabel),
+ 'A fresh folder, made on the machine',
leading: Icon(
- LucideIcons.gitBranch300,
+ LucideIcons.folderPlus300,
size: 18,
color: AppPalette.textSecondary,
),
- trailing: _check(_project?.repository != null),
+ trailing: _check(
+ _project != null && _project!.repository == null,
+ ),
onTap: !_canMakeProject
? null
- : () => unawaited(_pickRepository()),
- ),
- // The fourth source, folded shut. Its entries are answers already given
- // rather than a way of choosing, so they stay out of sight until asked
- // for — a machine used for months would otherwise bury the three rows
- // above under its own history.
- //
- // ⚠️ Absent entirely when there is no history, rather than opening onto
- // nothing. Nobody's first agent has a recent folder.
- if (_recent.isNotEmpty)
- SettingsRow(
- title: 'Recent',
- nested: true,
- detail: _recentOpen
- ? null
- : (_pickedRecent ?? _recentCount),
- leading: Icon(
- LucideIcons.history300,
- size: 18,
- color: AppPalette.textSecondary,
- ),
- trailing: Icon(
- _recentOpen
- ? LucideIcons.chevronUp300
- : LucideIcons.chevronDown300,
- size: 18,
- color: AppPalette.textFaint,
- ),
- onTap: () =>
- setState(() => _recentOpen = !_recentOpen),
- ),
- if (_recentOpen)
- for (final path in _recent)
- SettingsRow(
- title: _basename(path),
- detail: path,
- nested: true,
- // No leading glyph: the indent under an open Recent is what says
- // these belong to it, and a second icon column would put them back
- // level with the sources above.
- trailing: _check(_folder == path),
- onTap: () {
- setState(() {
- _folder = path;
- _project = null;
- _projectLabel = null;
- _recentOpen = false;
+ : () => setState(() {
+ _project =
+ const ProjectFolderRequest.newProject();
+ _projectLabel = 'New project';
+ _folder = null;
+ _git = null;
+ _gitFolder = null;
_error = null;
- });
- unawaited(_loadGit(path));
- },
- ),
+ }),
+ ),
],
],
),
@@ -821,7 +902,7 @@ class _NewAgentPageState extends State<NewAgentPage> {
if (_engineOpen)
for (final identity in _shownEngines) ...[
SettingsRow(
- title: identity.label,
+ title: _engineName(identity.id),
nested: true,
detail: _engineNote(identity.id),
leading: EngineMark(
@@ -831,6 +912,9 @@ class _NewAgentPageState extends State<NewAgentPage> {
trailing: _check(_engine == identity.id),
onTap: () => setState(() {
_engine = identity.id;
+ // See [_permissionMode]: a mode is one engine's
+ // word, and the CLI refuses another's.
+ _permissionMode = kDefaultPermissionMode;
_error = null;
}),
),
@@ -883,6 +967,59 @@ class _NewAgentPageState extends State<NewAgentPage> {
),
],
),
+ // ⚠️ **Its own caption, the way the desktop gives it its own row.** Approvals
+ // is not a detail of which engine was picked — it is the one choice here that
+ // decides what the harness may do to the machine while nobody is watching, and
+ // a phone is exactly where nobody is watching. Folded under AGENT beside the
+ // Codex profile, it read as another engine setting.
+ //
+ // Left out entirely for an engine with nothing to choose between: a row saying
+ // "Not used by this agent" is a row that has to be read to learn it says
+ // nothing.
+ if (_permissionModes.isNotEmpty) ...[
+ const SettingsCaption('APPROVALS'),
+ SettingsGroup(
+ children: [
+ SettingsRow(
+ title:
+ _permissionModeChoice?.label ?? 'Auto-approve',
+ detail: _permissionModeChoice?.detail,
+ leading: Icon(
+ LucideIcons.shieldCheck300,
+ size: 18,
+ color: _permissionModeChoice?.risky == true
+ ? AppPalette.warn
+ : AppPalette.textSecondary,
+ ),
+ trailing: Icon(
+ _approvalsOpen
+ ? LucideIcons.chevronUp300
+ : LucideIcons.chevronDown300,
+ size: 18,
+ color: AppPalette.textFaint,
+ ),
+ onTap: () => setState(
+ () => _approvalsOpen = !_approvalsOpen,
+ ),
+ ),
+ if (_approvalsOpen)
+ for (final mode in _permissionModes)
+ SettingsRow(
+ title: mode.label,
+ detail: mode.detail,
+ nested: true,
+ // The one that turns the engine's own safety net off wears the
+ // danger ink every other row on this phone uses for "this cannot
+ // be taken back". It is a mode like any other to the CLI, and not
+ // to the person reading the list.
+ destructive: mode.risky,
+ trailing: _check(_permissionMode == mode.id),
+ onTap: () =>
+ setState(() => _permissionMode = mode.id),
+ ),
+ ],
+ ),
+ ],
],
),
),
@@ -952,23 +1089,43 @@ class _NewAgentPageState extends State<NewAgentPage> {
/// wrong thing.
List<Widget> _branchSection() {
final info = _repository;
- if (info == null && !_gitLoading && !_gitFailed) return const [];
- if (info == null && _gitFailed) {
+ // ⚠️ **Always drawn, whatever the folder turns out to be** — the desktop keeps Branch and
+ // Worktree on the form and answers both with "Not a Git repository" (`new_harness_form.dart`,
+ // `_blocked`). A section that comes and goes with the folder makes a person wonder what else
+ // they have not been shown, and a missing Branch row is indistinguishable from an app that
+ // cannot do branches. Where there is nothing to choose the rows are inert rather than absent.
+ if (info == null && !_gitLoading) {
+ // A machine that could not answer is not the same as a folder that is not a checkout, and
+ // the difference is worth a sentence: one of them is worth trying again.
+ final reason = _gitFailed
+ ? 'The machine did not answer'
+ : 'Not a Git repository';
return [
const SettingsCaption('BRANCH'),
SettingsGroup(
children: [
SettingsRow(
- title: 'Could not read the repository',
- detail:
- 'The machine did not answer. The harness still starts in '
- 'the folder, on the branch it is on.',
+ title: 'Branch',
+ value: reason,
+ detail: _gitFailed
+ ? 'The harness still starts in the folder, on the branch it '
+ 'is on.'
+ : null,
leading: Icon(
LucideIcons.gitBranch300,
size: 18,
color: AppPalette.textFaint,
),
),
+ SettingsRow(
+ title: 'Worktree',
+ value: reason,
+ leading: Icon(
+ LucideIcons.gitFork300,
+ size: 18,
+ color: AppPalette.textFaint,
+ ),
+ ),
],
),
];
@@ -1003,7 +1160,18 @@ class _NewAgentPageState extends State<NewAgentPage> {
// to the branch, with it on the harness gets a checkout of its own —
// so it has to be readable at the same time as the answer it
// qualifies.
- if (info != null)
+ if (info == null)
+ // Still reading. Drawn without an answer rather than left out, so
+ // the row does not arrive under a thumb already on its way down.
+ SettingsRow(
+ title: 'Worktree',
+ leading: Icon(
+ LucideIcons.gitFork300,
+ size: 18,
+ color: AppPalette.textFaint,
+ ),
+ )
+ else
SettingsRow(
title: 'Worktree',
detail: _worktree
diff --git a/mobile/lib/phone/project_picker_sheet.dart b/mobile/lib/phone/project_picker_sheet.dart
new file mode 100644
index 000000000..6600d8403
--- /dev/null
+++ b/mobile/lib/phone/project_picker_sheet.dart
@@ -0,0 +1,216 @@
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:lucide_icons_flutter/lucide_icons.dart';
+
+import 'package:harness_mobile/shared/theme/app_theme.dart';
+
+import 'phone_search_field.dart';
+import 'sheet_list.dart';
+
+/// The folders a harness has been started in on this machine, searchable.
+///
+/// The desktop's project menu is a filter field over the same history — "Find a project by name or
+/// path" (`state/new_harness.dart`, `NewHarnessField.projectMenu`) — and this is that field on a
+/// phone. The three ways of naming a folder the machine does not know yet (Clone Repository, Open
+/// Folder, New Project) stay on the form itself, where the desktop also keeps them.
+///
+/// ⚠️ **By name AND by path, both.** A phone truncates a path to its last segment or two, so a
+/// query typed against what is on screen finds nothing if only the full path is matched; and a
+/// person who remembers `~/work/api` rather than `api` would find nothing if only the name were.
+/// Returns the folder chosen, or null.
+Future<String?> showProjectPickerSheet(
+ BuildContext context, {
+ required List<String> folders,
+ required String? selected,
+}) => showModalBottomSheet<String>(
+ context: context,
+ useRootNavigator: true,
+ showDragHandle: true,
+ backgroundColor: AppPalette.panelBg,
+ isScrollControlled: true,
+ builder: (_) => _ProjectPicker(folders: folders, selected: selected),
+);
+
+class _ProjectPicker extends StatefulWidget {
+ const _ProjectPicker({required this.folders, required this.selected});
+
+ final List<String> folders;
+ final String? selected;
+
+ @override
+ State<_ProjectPicker> createState() => _ProjectPickerState();
+}
+
+class _ProjectPickerState extends State<_ProjectPicker> {
+ final _controller = TextEditingController();
+ final _focus = FocusNode();
+ String _query = '';
+
+ @override
+ void dispose() {
+ _controller.dispose();
+ _focus.dispose();
+ super.dispose();
+ }
+
+ static String _name(String path) {
+ final parts = path.split('/').where((part) => part.isNotEmpty);
+ return parts.isEmpty ? path : parts.last;
+ }
+
+ List<String> get _matches {
+ final query = _query.trim().toLowerCase();
+ if (query.isEmpty) return widget.folders;
+ return [
+ for (final folder in widget.folders)
+ if (folder.toLowerCase().contains(query)) folder,
+ ];
+ }
+
+ /// Puts the keyboard away and takes the caret out of the field.
+ ///
+ /// ⚠️ **[FocusManager], not `_focus.unfocus()`.** The field is not always what holds the focus
+ /// by the time this runs — the sheet is closing, or the tap landed on the list — and unfocusing
+ /// a node that does not have it does nothing at all, which is exactly the bug: the sheet went
+ /// and the keyboard stayed, standing over the form underneath.
+ void _dismissKeyboard() => FocusManager.instance.primaryFocus?.unfocus();
+
+ @override
+ Widget build(BuildContext context) {
+ AppTheme.watch(context);
+ final matches = _matches;
+ return GestureDetector(
+ // ⚠️ A tap ANYWHERE that is not a row: the empty space under a short list, the sheet's own
+ // margins, the space beside the field. Opaque so those taps land here rather than falling
+ // through to whatever is behind the sheet; a row's own detector is nearer the tap and still
+ // wins, so choosing a folder is unaffected.
+ behavior: HitTestBehavior.opaque,
+ onTap: _dismissKeyboard,
+ child: SafeArea(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Padding(
+ padding: const EdgeInsets.fromLTRB(
+ kSheetInset,
+ 0,
+ kSheetInset,
+ 10,
+ ),
+ child: PhoneSearchField(
+ controller: _controller,
+ focus: _focus,
+ // ⚠️ **The way out, and the sheet had none.** It fills the screen once its list
+ // is longer than a few rows, so the drag-down a short sheet is dismissed by is
+ // nowhere near the thumb — and a person who opened it to look rather than to
+ // choose was stuck until they picked a folder they did not want. The chevron is
+ // where every other search bar on this phone keeps it.
+ onBack: () {
+ _dismissKeyboard();
+ Navigator.of(context).pop();
+ },
+ // ⚠️ Not autofocused, for the reason the branch picker gives: a machine used for a
+ // week has a handful of folders and the answer is already on screen, where a
+ // keyboard would bury it.
+ autofocus: false,
+ hintText: 'Search project',
+ onChanged: (value) => setState(() => _query = value),
+ onClear: () => setState(() {
+ _controller.clear();
+ _query = '';
+ }),
+ ),
+ ),
+ Flexible(
+ child: matches.isEmpty
+ ? Padding(
+ padding: const EdgeInsets.fromLTRB(
+ kSheetInset,
+ 8,
+ kSheetInset,
+ 24,
+ ),
+ child: Text(
+ widget.folders.isEmpty
+ ? 'No folders yet. Open one, clone a repository, or '
+ 'make a new project.'
+ : 'No folder matches “${_query.trim()}”.',
+ style: TextStyle(
+ color: AppPalette.textSecondary,
+ fontSize: 13.5,
+ ),
+ ),
+ )
+ : ListView.builder(
+ // Dragging the list is a way of saying "let me read this",
+ // and iOS puts the keyboard away for it everywhere else.
+ keyboardDismissBehavior:
+ ScrollViewKeyboardDismissBehavior.onDrag,
+ padding: EdgeInsets.fromLTRB(
+ kSheetInset,
+ 0,
+ kSheetInset,
+ MediaQuery.paddingOf(context).bottom + 16,
+ ),
+ itemCount: matches.length,
+ itemBuilder: (context, index) {
+ final folder = matches[index];
+ final chosen = folder == widget.selected;
+ return SheetRow(
+ first: index == 0,
+ last: index == matches.length - 1,
+ leading: SheetTile(
+ child: Icon(
+ LucideIcons.folder300,
+ size: 18,
+ color: chosen
+ ? AppPalette.accentOnSurface
+ : AppPalette.textSecondary,
+ ),
+ ),
+ title: Text(
+ _name(folder),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: sheetRowTitleStyle(),
+ ),
+ // The path under the name, not instead of it: two
+ // machines can hold `api`, and the folder is the only
+ // thing that tells them apart.
+ subtitle: Text(
+ folder,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyle(
+ color: AppPalette.textFaint,
+ fontSize: 12.5,
+ ),
+ ),
+ chevron: false,
+ selected: chosen,
+ trailing: chosen
+ ? Icon(
+ LucideIcons.check300,
+ size: 18,
+ color: AppPalette.accent,
+ )
+ : null,
+ onTap: () {
+ HapticFeedback.selectionClick();
+ // Before the pop, not after: once the route is gone
+ // this State is unmounted and its context can no
+ // longer be asked for anything.
+ _dismissKeyboard();
+ Navigator.of(context).pop(folder);
+ },
+ );
+ },
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/lib/state/app_state.dart b/mobile/lib/state/app_state.dart
index c6f2ec474..8fc464636 100644
--- a/mobile/lib/state/app_state.dart
+++ b/mobile/lib/state/app_state.dart
@@ -23,6 +23,7 @@ import '../core/agent_preference.dart';
import '../core/engine_availability.dart';
import '../core/device_name.dart';
import '../core/local_hostname.dart';
+import '../core/permission_modes.dart';
import '../core/local_git_projects.dart';
import '../core/last_opened_agent.dart';
import '../core/phone_search_history.dart';
@@ -4791,7 +4792,7 @@ class AppNotifier extends ChangeNotifier {
required String engine,
required String folder,
ProjectFolderRequest? projectFolder,
- bool bypassPermission = false,
+ String? permissionMode,
String? codexHome,
String? swarmId,
PaneSplitRequest? split,
@@ -4802,7 +4803,16 @@ class AppNotifier extends ChangeNotifier {
'engine': engine,
if (projectFolder == null) 'cwd': folder,
...?projectFolder?.payload,
- 'bypassPermission': bypassPermission,
+ 'permissionMode': ?permissionMode,
+ // ⚠️ **Both keys, and the older one is not redundant.** `permissionMode`
+ // is the whole menu (`core/permission_modes.dart`); `bypassPermission` is
+ // the yes/no a daemon from before that menu understands, and it is all
+ // such a machine reads. Sent alone, "Plan first" on an old machine would
+ // launch as "approve everything" — so the boolean is derived from the
+ // mode rather than asked for separately. See [permissionModeApproves].
+ 'bypassPermission': permissionMode == null
+ ? false
+ : permissionModeApproves(permissionMode),
'codexHome': ?codexHome,
};
if (creation._choices != null &&
diff --git a/mobile/test/phone_new_agent_opens_test.dart b/mobile/test/phone_new_agent_opens_test.dart
index 13b08c9e3..aeab1cb85 100644
--- a/mobile/test/phone_new_agent_opens_test.dart
+++ b/mobile/test/phone_new_agent_opens_test.dart
@@ -96,13 +96,16 @@ void main() {
await tester.pump();
// PROJECT and ENGINE are folded shut — the page says what is chosen and
- // opens onto the choices. Recent is a second fold inside PROJECT.
+ // opens onto the choices. The folders already worked in are behind Search
+ // project, which is a sheet rather than a second fold.
await tester.tap(find.text('Choose a folder'));
await tester.pump();
- await tester.tap(find.text('Recent'));
+ await tester.tap(find.text('Search project'));
await tester.pump();
+ await tester.pump(const Duration(milliseconds: 400));
await tester.tap(find.text('grid'));
await tester.pump();
+ await tester.pump(const Duration(milliseconds: 400));
// Claude is the engine the form starts on, and the ENGINE row now shows
// it rather than offering it — so there is nothing to tap.
await tester.pump();