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
Merge main; prepare hn 0.1.6
Tim5041d1a499b7
diff --cc tui/Cargo.lockindex b641c8c6a,2d473d91a..15a6a2e3f--- a/tui/Cargo.lock+++ b/tui/Cargo.lock@@@ -653,7 -619,7 +653,7 @@@ dependencies =[[package]]name = "harness-tui"- version = "0.1.4"-version = "0.1.5"++version = "0.1.6"dependencies = ["alacritty_terminal","crossterm",diff --cc tui/Cargo.tomlindex 3f33937d1,33c1f74b1..97f69cf1d--- a/tui/Cargo.toml+++ b/tui/Cargo.toml@@@ -1,6 -1,6 +1,6 @@@[package]name = "harness-tui"- version = "0.1.4"-version = "0.1.5"++version = "0.1.6"edition = "2024"[dependencies]diff --cc tui/src/daemon.rsindex 994a7b06a,d162f0d54..77802ac6d--- a/tui/src/daemon.rs+++ b/tui/src/daemon.rs@@@ -245,15 -267,13 +267,19 @@@ impl Link// ── REST on the same port (machines, desk, status) ──────────────────────────────pub async fn http_json(port: u16, method: &str, path: &str, body: Option<&Value>) -> Result<Value, RpcError> {- http_json_at(port, &socket_path(port), method, path, body).await+ http_json_for(port, method, path, body, Duration::from_secs(15)).await}-async fn http_json_at(port: u16, socket: &Path, method: &str, path: &str, body: Option<&Value>) -> Result<Value, RpcError> {+/// [http_json] with its own wait: a long poll (`POST /api/pair` holds the request for as long as a+/// phone's handshake runs) needs more than the usual 15 s.+pub async fn http_json_for(port: u16, method: &str, path: &str, body: Option<&Value>, wait: Duration) -> Result<Value, RpcError> {++ http_json_at(port, &socket_path(port), method, path, body, wait).await++}++++async fn http_json_at(port: u16, socket: &Path, method: &str, path: &str, body: Option<&Value>, wait: Duration) -> Result<Value, RpcError> {use tokio::io::{AsyncReadExt, AsyncWriteExt};let work = async {- let mut stream = tokio::net::TcpStream::connect(("127.0.0.1", port)).await.map_err(|e| RpcError::new("DAEMON_UNREACHABLE", e.to_string()))?;+ let mut stream = connect_owned(socket).await.map_err(|e| RpcError::new("DAEMON_UNREACHABLE", e.to_string()))?;let body = body.map(|b| b.to_string()).unwrap_or_default();let request = format!("{method} {path} HTTP/1.1\r\nHost: 127.0.0.1:{port}\r\nConnection: close\r\nAccept: application/json\r\nx-adapter-local: 1\r\nContent-Type: application/json\r\nContent-Length: {}\r\n\r\n{body}",@@@ -294,6 -314,50 +320,50 @@@ fn dechunk(body: &[u8]) -> Vec<u8>#[cfg(test)]mod recovery_tests {use super::*;+ use std::os::unix::fs::PermissionsExt;++ struct TestSocket(PathBuf);+ impl Drop for TestSocket { fn drop(&mut self) { let _ = std::fs::remove_file(&self.0); } }+ fn listener() -> (tokio::net::UnixListener, TestSocket) {+ let path = PathBuf::from(format!("/tmp/hn-daemon-{}.sock", uuid::Uuid::new_v4().simple()));+ let listener = tokio::net::UnixListener::bind(&path).unwrap();+ std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o600)).unwrap();+ (listener, TestSocket(path))+ }++ #[tokio::test]+ async fn rest_uses_only_the_users_private_socket_and_never_the_tcp_listener() {+ use tokio::io::{AsyncReadExt, AsyncWriteExt};+ let foreign = tokio::net::TcpListener::bind(("127.0.0.1", 0)).await.unwrap();+ let port = foreign.local_addr().unwrap().port();+ let (owned, socket) = listener();+ let server = tokio::spawn(async move {+ let (mut peer, _) = owned.accept().await.unwrap();+ let mut bytes = [0u8; 4096];+ let n = peer.read(&mut bytes).await.unwrap();+ assert!(String::from_utf8_lossy(&bytes[..n]).starts_with("GET /api/desk "));+ let body = r#"{"owner":"this-user","tabs":[]}"#;+ peer.write_all(format!("HTTP/1.1 200 OK\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}", body.len()).as_bytes()).await.unwrap();+ });- let desk = http_json_at(port, &socket.0, "GET", "/api/desk", None).await.unwrap();++ let desk = http_json_at(port, &socket.0, "GET", "/api/desk", None, Duration::from_secs(15)).await.unwrap();+ assert_eq!(desk["owner"], "this-user");+ server.await.unwrap();+ std::fs::remove_file(&socket.0).unwrap();- assert!(http_json_at(port, &socket.0, "GET", "/api/desk", None).await.is_err());++ assert!(http_json_at(port, &socket.0, "GET", "/api/desk", None, Duration::from_secs(15)).await.is_err());+ assert!(tokio::time::timeout(Duration::from_millis(50), foreign.accept()).await.is_err());+ }++ #[tokio::test]+ async fn rejects_public_sockets_and_symlinks_before_sending_any_request() {+ let (owned, socket) = listener();+ std::fs::set_permissions(&socket.0, std::fs::Permissions::from_mode(0o666)).unwrap();+ assert_eq!(connect_owned(&socket.0).await.unwrap_err().kind(), std::io::ErrorKind::PermissionDenied);+ std::fs::set_permissions(&socket.0, std::fs::Permissions::from_mode(0o600)).unwrap();+ let alias = TestSocket(socket.0.with_extension("link"));+ std::os::unix::fs::symlink(&socket.0, &alias.0).unwrap();+ assert_eq!(connect_owned(&alias.0).await.unwrap_err().kind(), std::io::ErrorKind::PermissionDenied);+ assert!(tokio::time::timeout(Duration::from_millis(50), owned.accept()).await.is_err());+ }#[tokio::test]async fn cancel_closes_socket_and_releases_rpc_clones() {