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
Harness OS: the welcome asks hn again until it knows its pane
bubu-dudu78b06f53b8e4
diff --git a/os/onboarding.py b/os/onboarding.pyindex 69ca0a39a..1cfd3db14 100644--- a/os/onboarding.py+++ b/os/onboarding.py@@ -4,9 +4,12 @@ import osfrom pathlib import Pathimport subprocessimport sys+import time# Written by setup.py when a phone signed this computer in (os/setup.py FROM_PHONE).FROM_PHONE = Path('/var/lib/harness-os/set-up-from-phone')+# How long the welcome keeps asking hn to lay out the first workspace.+READY_FOR = 10def prepare():@@ -30,14 +33,22 @@ def welcome():# Set up from a phone (setup.py): OpenCode alone, without the two starter terminals; nobody# was at this screen to start with three panes.bare = ['bare'] if FROM_PHONE.is_file() else []- try:- result = subprocess.run(['hn', 'os-action', 'ready', pane, *bare], check=False, timeout=15)+ # Asked again for a while: this pane can start before hn knows it by its tmux id ("That pane is+ # not the welcome on this computer"), and one early refusal lost the two starter terminals.+ deadline = time.monotonic() + READY_FOR+ while True:+ try:+ result = subprocess.run(['hn', 'os-action', 'ready', pane, *bare], check=False, timeout=15)+ except (OSError, subprocess.TimeoutExpired):+ breakif result.returncode == 0:state = Path.home() / '.local/state/harness-os'state.mkdir(parents=True, exist_ok=True)(state / 'onboarded').touch()- except (OSError, subprocess.TimeoutExpired):- pass+ break+ if time.monotonic() >= deadline:+ break+ time.sleep(.5)os.execv('/usr/bin/hn-os', ['hn-os', 'try'])diff --git a/os/tests/test_onboarding.py b/os/tests/test_onboarding.pyindex 494a454a1..1a0dc0a15 100644--- a/os/tests/test_onboarding.py+++ b/os/tests/test_onboarding.py@@ -53,6 +53,33 @@ class Onboarding(unittest.TestCase):command.assert_not_called()execute.assert_called_once_with('/usr/lib/harness-os/open-install', ['open-install'])+ def test_the_welcome_asks_again_until_hn_knows_its_pane(self):+ # hn can refuse at first ("That pane is not the welcome on this computer") while it does not+ # know the pane by its tmux id yet; one refusal used to cost the two starter terminals.+ with tempfile.TemporaryDirectory() as temp, patch.object(onboarding.Path, 'is_file', return_value=False), \+ patch.object(onboarding.Path, 'home', return_value=Path(temp)), \+ patch.object(onboarding.subprocess, 'run', side_effect=[result(1), result(1), result()]) as command, \+ patch.object(onboarding.time, 'sleep'), \+ patch.object(onboarding.os, 'execv') as execute, \+ patch.dict(os.environ, {'TMUX_PANE': '%4'}):+ onboarding.welcome()+ self.assertEqual(command.call_count, 3)+ self.assertTrue((Path(temp) / '.local/state/harness-os/onboarded').exists())+ execute.assert_called_once_with('/usr/bin/hn-os', ['hn-os', 'try'])++ def test_a_welcome_hn_never_knows_gives_up_after_a_while(self):+ clock = iter(range(0, 1000, 3))+ with tempfile.TemporaryDirectory() as temp, patch.object(onboarding.Path, 'is_file', return_value=False), \+ patch.object(onboarding.Path, 'home', return_value=Path(temp)), \+ patch.object(onboarding.subprocess, 'run', return_value=result(1)) as command, \+ patch.object(onboarding.time, 'monotonic', side_effect=lambda: next(clock)), \+ patch.object(onboarding.time, 'sleep'), \+ patch.object(onboarding.os, 'execv') as execute:+ onboarding.welcome()+ self.assertLess(command.call_count, 10)+ self.assertFalse((Path(temp) / '.local/state/harness-os/onboarded').exists())+ execute.assert_called_once()+def test_failed_layout_request_does_not_mark_first_use_complete(self):with tempfile.TemporaryDirectory() as temp, patch.object(onboarding.Path, 'is_file', return_value=False), \patch.object(onboarding.Path, 'home', return_value=Path(temp)), \