ARKNET / BUILD 212 PUBLIC DESKTOP RUNTIME EVIDENCE SOURCE: src-tauri/src/main.rs PRIVATE SOURCE SHA-256: a10975ab0da0b5ce0c0bfb53270f35188000b063a06b4ac2f5378537773ed1db PUBLICATION: selected native-shell/runtime-boundary excerpt BOUNDARY: no tokens, provider keys, credentials or private filesystem values are published. WHAT THIS PROVES - Tauri v2 owns the desktop shell and Node sidecar lifecycle. - A free loopback port is reserved dynamically from 127.0.0.1:0. - Per-launch IPC/API tokens are held in native AppState and passed to the sidecar environment. - The sidecar process is spawned by the desktop shell and polled for readiness. - The WebView bridge points API calls at the private loopback address and injects the per-launch token. SOURCE EXCERPT 0001: // ArkNet — native desktop shell (Tauri v2). 0002: // 0003: // Wraps the existing browser app: spawns the zero-dependency Node sidecar on a 0004: // private loopback port, waits for it to listen, then opens that URL in a native 0005: // WebView2 window. The sidecar's lifetime is bound to this process. 0006: // 0007: // Secrets (roadmap 2.1): BYOK API keys live in the OS keychain (never in 0008: // localStorage). The Rust side stores/reads them via the `keyring` crate. Keys are 0009: // injected into the sidecar's env at spawn AND can be updated live by POSTing provider 0010: // config to the sidecar's token-guarded /api/key endpoint — so changing a key never 0011: // restarts the sidecar (which would kill the page the user is on). 0050: /// Shared runtime state: the fixed sidecar port, the per-launch IPC token (shared 0051: /// only with the sidecar), the project root, and the live child. 0052: struct AppState { 0053: port: u16, 0054: ipc_token: String, 0055: api_token: String, 0056: root: PathBuf, 0057: workspaces: PathBuf, 0058: startup_log: Option, 0059: sidecar: Mutex>, 1316: // ---- sidecar ---- 1317: 1318: /// Reserve an unused loopback port, then release it so the sidecar can bind it. 1319: fn free_port() -> u16 { 1320: TcpListener::bind("127.0.0.1:0") 1321: .and_then(|l| l.local_addr()) 1322: .map(|addr| addr.port()) 1323: .expect("could not reserve a local port for the sidecar") 1324: } 1667: fn sidecar_command(state: &AppState, entry: &Path, node: &Path) -> Command { 1668: let mut cmd = Command::new(node); 1669: cmd.arg(entry) 1670: // The sidecar can load the native Windows desktop driver, but that alone grants nothing: 1671: // only a locally paired Telegram owner receives the per-run remote-owner lease. Ordinary 1672: // agent runs remain synthetic/headless by policy in the sidecar. 1673: .env("STARNET_DESKTOP_SHELL", "1") 1674: .env("STARNET_COMPUTER_DRIVER", "1") 1675: // Do NOT pin STARNET_BROWSER_HEADLESS on the whole sidecar. runOnce gives ordinary 1676: // model-driven browsing forceHeadless + syntheticInputOnly directly, while the watched 1677: // browser.login tool is a separately consented, human-driven headed exception. A process- 1678: // wide env pin disables that exception before its consent flow can run and leaves users 1699: .env("STARNET_BUILD_DIRTY", env!("STARNET_BUILD_DIRTY")) 1700: .current_dir(&state.root); 1701: set_sidecar_branded_env(&mut cmd, "SKYNET_PORT", state.port.to_string()); 1702: set_sidecar_branded_env(&mut cmd, "SKYNET_IPC_TOKEN", &state.ipc_token); 1703: set_sidecar_branded_env(&mut cmd, "SKYNET_API_TOKEN", &state.api_token); 1704: set_sidecar_branded_env(&mut cmd, "SKYNET_WORKSPACES", state.workspaces.as_os_str()); 1705: if let Some(key) = read_key() { 1706: set_sidecar_branded_env(&mut cmd, "SKYNET_OPENROUTER_KEY", key); 1707: } 1708: for (provider, env_name) in SIDECAR_PROVIDER_KEY_ENVS { 1709: if let Some(key) = read_key_for(provider) { 1710: set_sidecar_branded_env(&mut cmd, env_name, key); 1711: } 1767: let mut last_error = None; 1768: for attempt in 0..=20 { 1769: match sidecar_command(state, &entry, &node).spawn() { 1770: Ok(child) => { 1771: let pid = child.id(); 1772: if let Ok(mut guard) = state.sidecar.lock() { 1773: *guard = Some(child); 1774: } 1775: let listening = wait_for_port(state.port, Duration::from_secs(25)); 1776: log_startup( 1777: &state.startup_log, 1778: format!( 1779: "spawn_sidecar pid={pid} port={} listening={listening}", 1780: state.port 1781: ), 2427: fn desktop_bridge_init(port: u16, api_token: &str) -> String { 2428: let mut init = format!( 2429: "window.__STARNET_API__='http://127.0.0.1:{port}';window.__STARNET_API_TOKEN__='{api_token}';var _sf=window.fetch;window.fetch=function(u,o){{if(typeof u==='string'&&u.indexOf('/api/')===0)u=window.__STARNET_API__+u;return _sf(u,o)}};" 2430: ); 2431: #[cfg(windows)] 2432: init.push_str("window.__STARNET_CUSTOM_CHROME__=1;"); 2433: init 2434: }