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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
feat(mobile): Intern 3 setup — iOS join retries, Wi-Fi check, Settings fallback, saved Wi-Fi passwords, failed-setup notice (#2789)
Bubu-Dudu-52hz6368bf6b0220
diff --git a/mobile/android/app/src/main/kotlin/ai/autonomous/harness/android/MainActivity.kt b/mobile/android/app/src/main/kotlin/ai/autonomous/harness/android/MainActivity.ktindex 631ff775e..61ac4b95c 100644--- a/mobile/android/app/src/main/kotlin/ai/autonomous/harness/android/MainActivity.kt+++ b/mobile/android/app/src/main/kotlin/ai/autonomous/harness/android/MainActivity.kt@@ -15,6 +15,7 @@ import android.net.Networkimport android.net.NetworkCapabilitiesimport android.net.NetworkRequestimport android.net.Uri+import android.net.wifi.WifiManagerimport android.net.wifi.WifiNetworkSpecifierimport android.os.PatternMatcherimport android.os.Build@@ -125,7 +126,7 @@ class MainActivity : FlutterActivity() {// `Harness-…`; Android shows its own sheet listing those nearby and the person picks one.// The app's traffic is then bound to that Wi-Fi — it has no Internet, and Android would// otherwise send 10.42.0.1 over mobile data. `leave` drops it, and the phone- // returns to its own Wi-Fi by itself.+ // returns to its own Wi-Fi by itself. `wifiOn`: whether the phone's Wi-Fi is on.MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "harness/setup_wifi").setMethodCallHandler { call, result ->when (call.method) {@@ -134,6 +135,7 @@ class MainActivity : FlutterActivity() {joinSetupWifi(prefix, result)}"leave" -> { leaveSetupWifi(); result.success(true) }+ "wifiOn" -> result.success(wifiManager().isWifiEnabled)else -> result.notImplemented()}}@@ -215,6 +217,8 @@ class MainActivity : FlutterActivity() {try { connectivity.unregisterNetworkCallback(callback) } catch (e: IllegalArgumentException) {}}+ private fun wifiManager() = applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager+/** Plays the Flutter asset [asset] once, as a sonification — the system's own sounds' stream —* and only while the ringer is on: muted means silent, and the haptic Dart plays beside it is* felt either way. False when it did not play. The player lets itself go when it finishes. */diff --git a/mobile/ios/Runner/AppDelegate.swift b/mobile/ios/Runner/AppDelegate.swiftindex 41b23018b..a6fa75788 100644--- a/mobile/ios/Runner/AppDelegate.swift+++ b/mobile/ios/Runner/AppDelegate.swift@@ -2,6 +2,7 @@ import AVFoundationimport AudioToolboximport AuthenticationServicesimport Flutter+import Networkimport NetworkExtensionimport Speechimport UIKit@@ -40,10 +41,16 @@ import UserNotifications/// no longer goes to Settings ▸ Wi-Fi. It answers `joined` with the address the hotspot gave this phone,/// or `unavailable` (cancelled, not found, or iOS stayed on its own Wi-Fi). `leave` forgets the hotspot,/// and iOS goes back to the phone's own Wi-Fi by itself.+///+/// `wifiOn`: whether the phone is on a Wi-Fi network — with Wi-Fi off, iOS never answers a join at all.enum SetupWifiChannel {/// The hotspot's network (os/setup.py ADDRESS 10.42.0.1): this phone's address there is 10.42.0.x.private static let subnet = "10.42.0."+ /// Joins tried before giving up: iOS often answers "not found" first while the hotspot is up+ /// (ecm-sds-mobile, the lamp's setup, saw the same).+ private static let attempts = 3+static func register(with registry: FlutterPluginRegistry) {guard let messenger = registry.registrar(forPlugin: "HarnessSetupWifi")?.messenger() else { return }let channel = FlutterMethodChannel(name: "harness/setup_wifi", binaryMessenger: messenger)@@ -52,38 +59,78 @@ enum SetupWifiChannel {case "join":let prefix = (call.arguments as? [String: Any])?["prefix"] as? String ?? ""guard !prefix.isEmpty else { result(["state": "unavailable"]); return }- join(prefix: prefix, result: result)+ join(prefix: prefix, attempt: 1, result: result)case "leave":leave { result(true) }+ case "wifiOn":+ wifiOn { result($0) }default:result(FlutterMethodNotImplemented)}}}- private static func join(prefix: String, result: @escaping FlutterResult) {- // Open: os/setup.py hosts the hotspot with no password. Once: iOS forgets it when the app leaves the- // front, so a phone is never left on a network with no Internet.- let configuration = NEHotspotConfiguration(ssidPrefix: prefix)- configuration.joinOnce = true- NEHotspotConfigurationManager.shared.apply(configuration) { error in- if let error = error as NSError?, error.code != NEHotspotConfigurationError.alreadyAssociated.rawValue {- NSLog("[setup_wifi] join \(prefix): \(error.domain) \(error.code) \(error.localizedDescription)")- result(["state": "unavailable"])+ private static func join(prefix: String, attempt: Int, result: @escaping FlutterResult) {+ apply(prefix: prefix) { error in+ if let error {+ NSLog("[setup_wifi] join \(prefix) #\(attempt): \(error.domain) \(error.code) \(error.localizedDescription)")+ // Cancelled by the person: asked again, they would only see the same question.+ if error.code == NEHotspotConfigurationError.userDenied.rawValue || attempt >= attempts {+ result(["state": "unavailable"])+ return+ }+ DispatchQueue.main.asyncAfter(deadline: .now() + 2) { join(prefix: prefix, attempt: attempt + 1, result: result) }return}// A join iOS reports is not yet one the phone is on: it can stay on its own Wi-Fi, which has the- // Internet the hotspot lacks, and DHCP takes a moment. Only an address on the hotspot's network counts.- awaitAddress(deadline: Date().addingTimeInterval(10)) { address in+ // Internet the hotspot lacks, and DHCP takes a moment. Only an address on the hotspot's network+ // counts; still none after a few seconds, the join is asked for again.+ awaitAddress(prefix: prefix, start: Date()) { address inresult(address == nil ? ["state": "unavailable"] : ["state": "joined", "address": address!])}}}- private static func awaitAddress(deadline: Date, done: @escaping (String?) -> Void) {+ /// Open: os/setup.py hosts the hotspot with no password. Once: iOS forgets it when the app leaves the+ /// front, so a phone is never left on a network with no Internet. Already on it is no error.+ private static func apply(prefix: String, done: @escaping (NSError?) -> Void) {+ let configuration = NEHotspotConfiguration(ssidPrefix: prefix)+ configuration.joinOnce = true+ NEHotspotConfigurationManager.shared.apply(configuration) { error in+ let error = error as NSError?+ done(error?.code == NEHotspotConfigurationError.alreadyAssociated.rawValue ? nil : error)+ }+ }++ /// Up to 10 s for an address on the hotspot, asking for the join again at 3 s and 6 s.+ private static func awaitAddress(prefix: String, start: Date, asked: Int = 0, done: @escaping (String?) -> Void) {if let address = hotspotAddress() { done(address); return }- if Date() > deadline { done(nil); return }- DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { awaitAddress(deadline: deadline, done: done) }+ let waited = Date().timeIntervalSince(start)+ if waited > 10 { done(nil); return }+ if asked < 2 && waited > Double(3 * (asked + 1)) {+ NSLog("[setup_wifi] no hotspot address after \(Int(waited)) s: joining \(prefix) again")+ apply(prefix: prefix) { _ in awaitAddress(prefix: prefix, start: start, asked: asked + 1, done: done) }+ return+ }+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {+ awaitAddress(prefix: prefix, start: start, asked: asked, done: done)+ }+ }++ /// Whether the phone is on a Wi-Fi network, as its network path says. iOS does not tell an app+ /// whether the Wi-Fi itself is on, so on but joined to nothing reads off too: both are put right in+ /// Settings ▸ Wi-Fi.+ private static func wifiOn(done: @escaping (Bool) -> Void) {+ let monitor = NWPathMonitor(requiredInterfaceType: .wifi)+ let queue = DispatchQueue(label: "harness.setup_wifi.path")+ var answered = false+ monitor.pathUpdateHandler = { path in+ if answered { return }+ answered = true+ monitor.cancel()+ DispatchQueue.main.async { done(path.status == .satisfied) }+ }+ monitor.start(queue: queue)}/// This phone's IPv4 address on the hotspot's network, if it has one.diff --git a/mobile/lib/phone/add_device/add_device_page.dart b/mobile/lib/phone/add_device/add_device_page.dartindex a8ceeee0f..a66aae046 100644--- a/mobile/lib/phone/add_device/add_device_page.dart+++ b/mobile/lib/phone/add_device/add_device_page.dart@@ -1,4 +1,5 @@import 'dart:async';+import 'dart:io';import 'package:flutter/material.dart';import 'package:lucide_icons_flutter/lucide_icons.dart';@@ -13,6 +14,7 @@ import '../phone_navigation.dart' show phoneRoute;import '../settings_row.dart';import '../tty.dart';import '../tty_controls.dart';+import 'saved_wifi.dart';import 'setup_hotspot.dart';/// Settings ▸ Set up Intern 3: a Harness with no screen (a box, a mini PC) put on the person's@@ -185,7 +187,18 @@ class _Line extends StatelessWidget {class _AddDevicePageState extends State<AddDevicePage> {late final SetupHotspot _hotspot = widget.hotspot ?? SetupHotspot();+ final _saved = const SavedWifi();final _ssid = TextEditingController();++ /// The Wi-Fi password was filled in from the last setup on that Wi-Fi ([SavedWifi]).+ bool _filled = false;++ /// iOS's own join did not work, and the person joins the hotspot in Settings instead: the app only+ /// waits to reach the device, as on a phone that never joins by itself.+ bool _manual = false;++ /// The app joins the hotspot itself, rather than the person in Settings.+ bool get _auto => SetupHotspot.joinsByItself && !_manual;final _password = TextEditingController();final _name = TextEditingController();@@ -286,6 +299,7 @@ class _AddDevicePageState extends State<AddDevicePage> {void dispose() {_poll?.cancel();_tick?.cancel();+ _again?.cancel();_backWatch?.cancel();unawaited(_hotspot.leave());_ssid.dispose();@@ -383,7 +397,19 @@ class _AddDevicePageState extends State<AddDevicePage> {// that failed), so a new one now, while this phone is on its own Wi-Fi again. Sent again, the old// one came back "This ticket was already used or has expired".if (_ticketSent && !await _freshTicket()) return;- if (SetupHotspot.joinsByItself) {+ if (_auto) {+ // With the phone's Wi-Fi off, iOS never answers the join: the spinner would turn for ever.+ if (!await _hotspot.wifiOn()) {+ if (!mounted) return;+ _show(+ _Step.join,+ error: Platform.isIOS+ ? 'This phone is not on Wi-Fi. Turn Wi-Fi on in Settings ▸ Wi-Fi, then tap Try again.'+ : 'This phone\'s Wi-Fi is off. Turn it on, then tap Try again.',+ );+ return;+ }+ if (!mounted) return;// Back for a device that did not come online: as long as Android looks for its hotspot.if (_retrying) _countdown(_hotspotSearch);// The same device again once it has started: only its own name in Android's list.@@ -409,12 +435,33 @@ class _AddDevicePageState extends State<AddDevicePage> {? 'Intern 3 did not come online${ssid.isEmpty ? '' : ' on "$ssid"'}, and its Wi-Fi ''"Harness-…" did not come back. It may be on the Wi-Fi without being signed in: ''check its screen, then tap Try again.'+ : Platform.isIOS+ ? 'This phone could not join Intern 3. Check it is plugged in and nearby: its '+ 'Wi-Fi is named "Harness-…". Or join it in Settings instead.': 'Intern 3 was not chosen. Check it is plugged in and nearby: its Wi-Fi is named "Harness-…".',);return;}}- // Joined by Android, or by the person in Settings: wait for the page to answer.+ _awaitPage();+ }++ /// iOS's own join did not work: the person picks `Harness-…` in Settings ▸ Wi-Fi and comes back,+ /// and the app waits to reach the device. Not on Android: a hotspot joined in Settings, with no+ /// Internet, is soon left again for a Wi-Fi that has it, and the app's own join is the way there.+ void _joinInSettings() {+ _manual = true;+ _show(_Step.join);+ setState(() {+ _busy = true;+ _progress = _Progress.choosing;+ _address = null;+ });+ _awaitPage();+ }++ /// Joined by the phone, or by the person in Settings: wait for the device's page to answer.+ void _awaitPage() {_poll?.cancel();_poll = Timer.periodic(const Duration(seconds: 2),@@ -657,18 +704,26 @@ class _AddDevicePageState extends State<AddDevicePage> {// -- 3. the person's Wi-Fi --- void _choose(SetupNetwork? network) {+ Future<void> _choose(SetupNetwork? network) async {_chosen = network;_ssid.text = network?.ssid ?? '';_password.clear();+ _filled = false;// The same Wi-Fi again after it failed: why, over the password being typed again.final failed = _failed;- _show(- _Step.password,- error: failed != null && network != null && failed.ssid == network.ssid- ? failed.why- : '',- );+ final again =+ failed != null && network != null && failed.ssid == network.ssid;+ _show(_Step.password, error: again ? failed.why : '');+ // The password a device came online with last time on this Wi-Fi. Not after it just failed+ // there: the Wi-Fi's password may have changed since.+ if (network == null || !network.secure || again) return;+ final saved = await _saved.password(network.ssid);+ if (!mounted || saved == null || _chosen != network) return;+ if (_password.text.isNotEmpty) return;+ setState(() {+ _password.text = saved;+ _filled = true;+ });}Future<void> _send() async {@@ -815,6 +870,10 @@ class _AddDevicePageState extends State<AddDevicePage> {: online;if (settled) {_poll?.cancel();+ // Online with it: the password is right, and the next setup on this Wi-Fi fills it in.+ if (ssid.isNotEmpty && _password.text.isNotEmpty) {+ unawaited(_saved.remember(ssid, _password.text));+ }// Named after its Wi-Fi, `Harness-XXXX`, the name the person just picked it by; a device// that was here already keeps its own.final machine = _machine;@@ -828,9 +887,18 @@ class _AddDevicePageState extends State<AddDevicePage> {_poll?.cancel();// Not online by now: the Wi-Fi most likely failed and the device is back on its hotspot with// the reason. Android goes back to it by itself; elsewhere the person rejoins it.- if (SetupHotspot.joinsByItself) {- _retrying = true;- unawaited(_join());+ // Said first, as an end (owner, 2026-11-04): the bar ran out and the page went back to+ // step 2 with no word, as if nothing had been tried. A few seconds, then the setup again.+ if (_auto) {+ _show(+ _Step.waiting,+ error:+ 'The setup did not finish: Intern 3 did not come online on "$ssid". '+ 'Most often its Wi-Fi password was not right.',+ );+ setState(() => _againSoon = true);+ _again?.cancel();+ _again = Timer(const Duration(seconds: 5), _setUpAgain);return;}_show(@@ -843,6 +911,18 @@ class _AddDevicePageState extends State<AddDevicePage> {});}+ /// After a setup that did not finish: back to the device's hotspot, which shows why it failed.+ bool _againSoon = false;+ Timer? _again;++ void _setUpAgain() {+ _again?.cancel();+ if (!mounted || !_againSoon) return;+ _againSoon = false;+ _retrying = true;+ unawaited(_join());+ }+// -- the page --@override@@ -918,7 +998,7 @@ class _AddDevicePageState extends State<AddDevicePage> {];case _Step.join:return [- if (SetupHotspot.joinsByItself)+ if (_auto)say('Choose Intern 3, "Harness-…", from the Wi-Fi list. Then wait here.',)@@ -950,7 +1030,7 @@ class _AddDevicePageState extends State<AddDevicePage> {done: _progress.index > _Progress.choosing.index,text: _progress.index > _Progress.choosing.index? 'Joined Intern 3\'s Wi-Fi${_address == null ? '' : ' · address $_address'}'- : SetupHotspot.joinsByItself+ : _auto? 'Choose "Harness-…" from the list…': 'Waiting for this phone to join "Harness-…"…',),@@ -1016,12 +1096,12 @@ class _AddDevicePageState extends State<AddDevicePage> {title: network.ssid,value: network.secure ? 'Locked' : 'Open',detail: _bars(network.signal),- onTap: () => _choose(network),+ onTap: () => unawaited(_choose(network)),),SettingsRow(key: const Key('add-device-wifi-other'),title: 'Other network…',- onTap: () => _choose(null),+ onTap: () => unawaited(_choose(null)),),],),@@ -1040,7 +1120,11 @@ class _AddDevicePageState extends State<AddDevicePage> {),const SizedBox(height: 12),] else- say('The password for "${_chosen!.ssid}". It is case-sensitive.'),+ say(+ _filled+ ? 'The password for "${_chosen!.ssid}", filled in from your last setup on it.'+ : 'The password for "${_chosen!.ssid}". It is case-sensitive.',+ ),if (_chosen?.secure ?? true) ...[const SizedBox(height: 8),TtyField(@@ -1070,7 +1154,10 @@ class _AddDevicePageState extends State<AddDevicePage> {case _Step.waiting:return [say(- _error.isNotEmpty+ _againSoon+ ? 'Setting it up again: this phone finds Intern 3 in a few seconds, and it says what '+ 'went wrong.'+ : _error.isNotEmpty? '': _ssid.text.trim().isEmpty? '$name is on a cable: it is signing in to your account. '@@ -1120,12 +1207,18 @@ class _AddDevicePageState extends State<AddDevicePage> {];case _Step.join:return [- if (_error.isNotEmpty || !SetupHotspot.joinsByItself)+ if (_error.isNotEmpty || !_auto)TtyPrimaryButton(key: const Key('add-device-retry-join'),- label: SetupHotspot.joinsByItself ? 'Try again' : 'I joined it',- onPressed: () =>- unawaited(SetupHotspot.joinsByItself ? _join() : _reach()),+ label: _auto ? 'Try again' : 'I joined it',+ onPressed: () => unawaited(_auto ? _join() : _reach()),+ ),+ // iOS's own join did not work: Settings ▸ Wi-Fi still does.+ if (Platform.isIOS && _auto && _error.isNotEmpty)+ TtyTextButton(+ key: const Key('add-device-join-in-settings'),+ label: 'Join it in Settings instead',+ onPressed: _joinInSettings,),if (_unlocked)TtyTextButton(@@ -1186,7 +1279,13 @@ class _AddDevicePageState extends State<AddDevicePage> {];case _Step.waiting:return [- if (_error.isNotEmpty)+ if (_againSoon)+ TtyPrimaryButton(+ key: const Key('add-device-again'),+ label: 'Set up again now',+ onPressed: _setUpAgain,+ )+ else if (_error.isNotEmpty)TtyPrimaryButton(key: const Key('add-device-rejoin'),label: 'Join Intern 3 again',diff --git a/mobile/lib/phone/add_device/saved_wifi.dart b/mobile/lib/phone/add_device/saved_wifi.dartnew file mode 100644index 000000000..7fa2ecd91--- /dev/null+++ b/mobile/lib/phone/add_device/saved_wifi.dart@@ -0,0 +1,38 @@+import 'package:flutter/services.dart';+import 'package:flutter_secure_storage/flutter_secure_storage.dart';++/// The Wi-Fi passwords a device was set up with from this phone, by Wi-Fi name: the next setup on the+/// same Wi-Fi fills it in. Kept only once the device came online with it, so a mistyped one is never+/// offered again. In the iOS Keychain (Android: Keystore-backed), never carried to another device or a+/// backup. A store that cannot be read is empty: nothing here is worth an error.+class SavedWifi {+ const SavedWifi();++ static const _storage = FlutterSecureStorage(+ iOptions: IOSOptions(+ accessibility: KeychainAccessibility.first_unlock_this_device,+ ),+ );++ static String _key(String ssid) => 'setup_wifi:$ssid';++ Future<String?> password(String ssid) async {+ try {+ return await _storage.read(key: _key(ssid));+ } on PlatformException {+ return null;+ } on MissingPluginException {+ return null;+ }+ }++ Future<void> remember(String ssid, String password) async {+ try {+ await _storage.write(key: _key(ssid), value: password);+ } on PlatformException {+ // Not kept: typed again next time.+ } on MissingPluginException {+ // Not on this platform.+ }+ }+}diff --git a/mobile/lib/phone/add_device/setup_hotspot.dart b/mobile/lib/phone/add_device/setup_hotspot.dartindex 55849f856..3b04a4d36 100644--- a/mobile/lib/phone/add_device/setup_hotspot.dart+++ b/mobile/lib/phone/add_device/setup_hotspot.dart@@ -54,6 +54,19 @@ class SetupHotspot {}}+ /// Whether the phone's Wi-Fi is on (iOS: whether it is on a Wi-Fi network). Asked before a join:+ /// with it off, iOS never answers the join. True when it cannot be told: no setup waits on a guess.+ Future<bool> wifiOn() async {+ if (!joinsByItself) return true;+ try {+ return await _channel.invokeMethod<bool>('wifiOn') ?? true;+ } on PlatformException {+ return true;+ } on MissingPluginException {+ return true;+ }+ }+/// Back to the phone's own Wi-Fi and the Internet.Future<void> leave() async {if (!joinsByItself) return;