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(os): a Harness OS computer as a machine: its own name, gh, a sound when an agent is done, C-b D diff (#1805)
Bubu-Dudu-52hzab3a198816f1
diff --git a/os/packages.x86_64 b/os/packages.x86_64index 669d839d0..77d8914b0 100644--- a/os/packages.x86_64+++ b/os/packages.x86_64@@ -52,11 +52,15 @@ brightnessctlttf-dejavuttf-nerd-fonts-symbols-mononoto-fonts-emoji+# The sound the terminal's bell plays (foot.ini [bell]).+sound-theme-freedesktop# Harness and the package tools needed to bootstrap agent engines.nodejs-lts-jodnpmtmuxgit+# gh: an agent pushes and opens pull requests, and a Swarm checks a project's out, with the person's GitHub.+github-clicurljqripgrepdiff --git a/os/root/usr/lib/harness-os/diff b/os/root/usr/lib/harness-os/diffnew file mode 100755index 000000000..b1902d13a--- /dev/null+++ b/os/root/usr/lib/harness-os/diff@@ -0,0 +1,22 @@+#!/bin/sh+# What the harness in this folder changed and has not committed: the files, then the lines, in a+# pager. C-b D splits it beside the harness (tmux.conf), in the harness's own folder; q closes it.+cd "${1:-.}" 2>/dev/null || { printf 'No folder %s\n' "$1"; read -r _; exit 1; }+if ! git rev-parse --git-dir >/dev/null 2>&1; then+ printf '%s is not a git repository: there is no diff to show.\n\nPress Enter to close.' "$PWD"+ read -r _+ exit 0+fi+if [ -z "$(git status --porcelain)" ]; then+ printf 'Nothing changed in %s since its last commit.\n\n' "$PWD"+ git --no-pager log --oneline -5+ printf '\nPress Enter to close.'+ read -r _+ exit 0+fi+{+ printf '%s\n\n' "$PWD"+ git -c color.status=always status --short+ printf '\n'+ git -c color.ui=always diff HEAD+} | LESS= less -Rdiff --git a/os/root/usr/share/harness-os/foot.ini b/os/root/usr/share/harness-os/foot.iniindex 5a616e542..6440a11cd 100644--- a/os/root/usr/share/harness-os/foot.ini+++ b/os/root/usr/share/harness-os/foot.ini@@ -16,5 +16,11 @@ lines=0[mouse]hide-when-typing=yes+[bell]+# hn rings it when a harness out of sight is done or waits on you (tui/src/app.rs): a short sound,+# though hn is always the focused window here.+command=pw-play /usr/share/sounds/freedesktop/stereo/complete.oga+command-focused=yes+[key-bindings]spawn-terminal=nonediff --git a/os/root/usr/share/harness-os/tmux.conf b/os/root/usr/share/harness-os/tmux.confindex c00b7cc43..a1cd37103 100644--- a/os/root/usr/share/harness-os/tmux.conf+++ b/os/root/usr/share/harness-os/tmux.conf@@ -4,6 +4,8 @@ unbind Dunbind C-zbind W os-action wifibind U new-window -n Updates '/usr/bin/harness updates'+# What the harness in front changed, beside it, in its folder.+bind D split-window -h -c '#{pane_current_path}' '/usr/lib/harness-os/diff'# Keep hn's normal installed status bar. A new tab is immediately a terminal.set -g @hn-new-window shell# Only the tab in front (*) is bold. Unread output (#) and a bell (!) keep their markers butdiff --git a/os/setup.py b/os/setup.pyindex a34fc9a42..28d5d1274 100644--- a/os/setup.py+++ b/os/setup.py@@ -66,6 +66,10 @@ HOME = Path('/home') / USERSESSION = HOME / '.harness/auth/session.json'COMPUTER_ID = HOME / '.harness/computer-id'HOTSPOT = 'harness-setup'+HOSTNAME = Path('/etc/hostname')+HOSTS = Path('/etc/hosts')+# What the installer calls every computer (installer.py), until name_computer gives it its hotspot's name.+INSTALLED_NAME = 'harness'ADDRESS = '10.42.0.1'PORT = 80PROTOCOL = 1@@ -159,6 +163,32 @@ def hotspot_name(device=None):return 'Harness-' + (tail or 'Setup')+def name_computer(device=None):+ """Call the computer what its hotspot is called (`Harness-BD19`) instead of the installer's+ `harness`: every Harness OS was `harness`, so two in one account, on one router or in one Swarm+ could not be told apart. Once, and only over that name: one somebody chose stays."""+ try:+ if HOSTNAME.read_text().strip() != INSTALLED_NAME:+ return+ except OSError:+ return+ name = hotspot_name(device)+ try:+ renamed = subprocess.run(['hostnamectl', 'set-hostname', name], capture_output=True, text=True, timeout=30)+ except (OSError, subprocess.TimeoutExpired) as error:+ log(f'could not name the computer {name}: {error}')+ return+ if renamed.returncode:+ log(f'could not name the computer {name}: {renamed.stderr.strip()}')+ return+ try:+ hosts = HOSTS.read_text()+ HOSTS.write_text(re.sub(rf'^(127\.0\.1\.1\s+){INSTALLED_NAME}$', rf'\g<1>{name}', hosts, flags=re.M))+ except OSError:+ pass+ log(f'named the computer {name}')++def signed_in():return SESSION.is_file()@@ -721,9 +751,15 @@ def set_up_as_unlocked():def watch():- started, waiting_since = time.monotonic(), None+ started, waiting_since, named = time.monotonic(), None, Falsewhile True:now = time.monotonic()+ if not named:+ # By the Wi-Fi card, as the hotspot is: once it is there, or once it would have been.+ device = wifi_device()+ if device or now - started >= DEVICE_WAIT:+ name_computer(device)+ named = Trueforced = asked_now()wait = 0 if forced else hotspot_wait(now, started)if wait is None:diff --git a/os/tests/test_setup.py b/os/tests/test_setup.pyindex c219565df..516743280 100644--- a/os/tests/test_setup.py+++ b/os/tests/test_setup.py@@ -458,6 +458,30 @@ class Ssh(unittest.TestCase):'addresses': [{'interface': 'wlo1', 'address': '172.168.21.13'}]})+class Name(unittest.TestCase):+ def name(self, hostname):+ with tempfile.TemporaryDirectory() as folder:+ etc = Path(folder)+ (etc / 'hostname').write_text(hostname + '\n')+ (etc / 'hosts').write_text(f'127.0.0.1 localhost\n::1 localhost\n127.0.1.1 {hostname}\n')+ calls = []+ with patch.object(setup, 'HOSTNAME', etc / 'hostname'), patch.object(setup, 'HOSTS', etc / 'hosts'), \+ patch.object(setup, 'hotspot_name', return_value='Harness-BD19'), \+ patch.object(setup.subprocess, 'run', side_effect=lambda command, **_: calls.append(command) or result()):+ setup.name_computer('wlan0')+ return calls, (etc / 'hosts').read_text()++ def test_the_installers_name_becomes_the_hotspots(self):+ calls, hosts = self.name('harness')+ self.assertEqual(calls, [['hostnamectl', 'set-hostname', 'Harness-BD19']])+ self.assertIn('127.0.1.1 Harness-BD19\n', hosts)++ def test_a_name_somebody_chose_stays(self):+ calls, hosts = self.name('studio')+ self.assertEqual(calls, [])+ self.assertIn('127.0.1.1 studio\n', hosts)++class Server:def shutdown(self): passdef server_close(self): passdiff --git a/os/tools/build-package.py b/os/tools/build-package.pyindex c8b1936d7..32f78df03 100644--- a/os/tools/build-package.py+++ b/os/tools/build-package.py@@ -14,7 +14,9 @@ import tempfile# dnsmasq: NetworkManager's shared mode hands the setup hotspot's phone an address with it.-DEPENDENCIES = ('nodejs-lts-jod', 'tmux', 'foot', 'gtklock', 'grim', 'slurp', 'dnsmasq')+# github-cli (gh) and sound-theme-freedesktop (foot.ini's bell): for a computer installed before they were+# in the image (packages.x86_64) to get them with an update.+DEPENDENCIES = ('nodejs-lts-jod', 'tmux', 'foot', 'gtklock', 'grim', 'slurp', 'dnsmasq', 'github-cli', 'sound-theme-freedesktop')def package_info(version, timestamp, size, compositor_dependencies=()):diff --git a/tui/src/app.rs b/tui/src/app.rsindex 46a84c1f5..5cfd73dc0 100644--- a/tui/src/app.rs+++ b/tui/src/app.rs@@ -1777,6 +1777,12 @@ impl App {let flag = |k: &str| payload.get(k).and_then(Value::as_bool).unwrap_or(false);let (replay, subagent) = (flag("replay"), flag("subagent"));let aborted = payload.get("aborted").and_then(Value::as_bool).unwrap_or(false);+ // Harness OS: hn is the screen and always focused, so no notification reaches anyone.+ // Its bell, which the OS's terminal plays as a sound (foot.ini [bell]), says a harness+ // out of sight is done — rung as a window's is: not with bell-action none, nor visual-bell on.+ let ring = self.os_session+ && self.options.get("bell-action", "", None).as_deref() != Some("none")+ && self.options.get("visual-bell", "", None).as_deref() != Some("on");if let Some(agent) = self.fleet.event_agent(machine_id, &payload) {agent.working = false; agent.activity.unknown = false; agent.activity.until = None;if !subagent { agent.subagents.clear() }@@ -1805,6 +1811,7 @@ impl App {if mine && failed && !visible.contains(&key) { self.say(what.clone(), theme::DANGER) }} else if looking.as_ref() == Some(&key) { self.mark_seen_key(key) }if mine && !self.terminal_focused && !replay && !subagent { crate::notify("Harness", &what) }+ if ring && mine && !replay && !subagent && !aborted && !visible.contains(&hook_key) { crate::bell() }if !replay && !subagent && !failed { crate::commands::notify_harness(self, "harness-done", &hook_key) }}}