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.

2.7 KB
Raw Blame
import 'package:flutter/widgets.dart';

import 'package:harness_mobile/settings/experimental_features.dart';
import 'package:harness_mobile/state/app_state.dart';
import 'package:harness_mobile/swarm/swarm_page.dart';

import 'agent_index.dart';
import 'agents_list_page.dart';
import 'agents_page.dart' show openNewAgent;
import 'phone_navigation.dart';
import 'phone_search_commands.dart';
import 'phone_status.dart';
import 'settings_page.dart';
import 'welcome/how_it_works.dart';

/// What `>` offers on the phone, and so what `?` lists under its three modes.
///
/// The desktop's `_searchModes` builds its half of this off a keymap and drops
/// any command the workspace cannot currently run. Same rule here, without the
/// keymap: a command is offered only while it would do something — there is no
/// "New agent" while no machine is ready to take one.
///
/// ⚠️ **Re-read on every filter, never cached.** Which commands are available
/// follows the fleet, and a list built once at open would keep offering a
/// machine that has since dropped.
List<PhoneCommand> phoneSearchCommands(
  BuildContext context,
  AppNotifier notifier,
) {
  final ready = [
    for (final machine in filterableMachines(notifier))
      if (phoneMachineStatusOf(machine) == PhoneMachineStatus.ready) machine,
  ];
  return [
    if (ready.isNotEmpty)
      PhoneCommand(
        id: 'agent.new',
        title: 'New Harness',
        detail: ready.length == 1
            ? 'On ${ready.first.machine.displayName}'
            : 'Choose an agent and a project',
        run: () =>
            openNewAgent(context, notifier, ready.first.machine.machineId),
      ),
    PhoneCommand(
      id: 'navigation.agents',
      title: 'All harnesses',
      detail: 'Every harness on the account, by computer',
      run: () =>
          Navigator.of(context)
              .push(phoneRoute((_) => AgentsListPage(notifier: notifier))),
    ),
    // Swarm's way in while it is built: only for a phone that turned it on in Settings ▸
    // Experimental. Read here, on every filter, so turning it off takes it out of the next search.
    if (experimentalFeaturesStore.isOn(PhoneExperiment.swarm))
      PhoneCommand(
        id: 'swarm.open',
        title: 'Swarm',
        detail: 'Experimental · your Swarms',
        run: () => openSwarmHome(context),
      ),
    PhoneCommand(
      id: 'app.settings',
      title: 'Settings',
      detail: 'Appearance · terminal · account',
      run: () => Navigator.of(
        context,
      ).push(phoneRoute((_) => SettingsPage(notifier: notifier, large: false))),
    ),
    PhoneCommand(
      id: 'app.help',
      title: 'Help: how Harness works',
      detail: 'Computers, agents, harnesses, tabs and gestures',
      run: () => openHowItWorks(context),
    ),
  ];
}