git.delta.rocks / fleet / refs/commits / 087938500f2e

difftreelog

refactor join with remowt monorepo

zqoyktorYaroslav Bolyukin2026-06-18parent: #32d9799.patch.diff

57 files changed

modifiedCargo.lockdiffbeforeafterboth
before · Cargo.lock
576 packageslockfile v4
after · Cargo.lock
722 packageslockfile v4
modifiedCargo.tomldiffbeforeafterboth
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,9 +1,10 @@
 [workspace]
-members = ["crates/*", "cmds/*"]
-resolver = "2"
-package.version = "0.1.0"
+members = ["crates/*", "cmds/*", "remowt/crates/*", "remowt/cmds/*"]
+resolver = "3"
+package.version = "0.1.9"
 package.edition = "2024"
-package.rust-version = "1.89.0"
+package.rust-version = "1.95.0"
+package.license = "MIT"
 
 [workspace.dependencies]
 fleet-base = { path = "./crates/fleet-base" }
@@ -13,42 +14,56 @@
 opentelemetry-exporter-env = { path = "./crates/opentelemetry-exporter-env" }
 remowt-fleet = { path = "./crates/remowt-fleet" }
 
-remowt-client = "0.1.3"
-remowt-endpoints = "0.1.3"
-remowt-link-shared = "0.1.3"
-remowt-plugin = "0.1.3"
-remowt-ui-prompt = "0.1.3"
+remowt-client = { version = "0.1.9", path = "remowt/crates/remowt-client" }
+remowt-polkit-shared = { version = "0.1.9", path = "remowt/crates/polkit-shared" }
+remowt-link-shared = { version = "0.1.9", path = "remowt/crates/remowt-link-shared" }
+remowt-plugin = { version = "0.1.9", path = "remowt/crates/remowt-plugin" }
+remowt-ui-prompt = { version = "0.1.9", path = "remowt/crates/remowt-ui-prompt" }
+remowt-endpoints = { version = "0.1.9", path = "remowt/crates/remowt-endpoints" }
 
-bifrostlink = "0.2.3"
+bifrostlink = "0.2.0"
+bifrostlink-macros = "0.2.0"
+bifrostlink-ports = "0.2.0"
 
-uuid = { version = "1", features = ["v4"] }
+iroh = { version = "1.0.0", features = ["unstable-custom-transports"] }
+iroh-base = "1.0.0"
+noq-udp = { version = "1.0.0", default-features = false }
+n0-watcher = "1.0.0"
 
+uuid = { version = "1", features = ["v4"] }
+russh = { version = "0.61.2", default-features = false, features = [
+        "ring",
+        "flate2",
+        "rsa",
+] }
+russh-config = "0.58.0"
 age = { version = "0.11", features = ["plugin", "ssh"] }
 anyhow = "1.0"
 base64 = "0.22.1"
 bindgen = "0.72.0"
+bytes = "1.11.0"
 camino = "1.2.2"
 chrono = { version = "0.4.41", features = ["serde"] }
 clap = { version = "4.5", features = ["derive", "env", "unicode", "wrap_help"] }
 clap_complete = "4.5"
 cxx = "1.0.168"
 cxx-build = "1.0.168"
-ed25519-dalek = "2.1"
+ed25519-dalek = "3.0.0-rc.0"
 futures = "0.3.31"
 hex = "0.4.3"
-hmac = "0.12"
+hmac = "0.13.0"
 hostname = "0.4.1"
 human-repr = "1.1"
 indicatif = "0.18"
 indoc = "2.0.6"
-itertools = "0.14.0"
+itertools = "0.15.0"
 linked-hash-map = "0.5.6"
 nix = { version = "0.31.2", features = ["fs", "user"] }
 nom = "8.0.0"
-opentelemetry = "0.31.0"
-opentelemetry-appender-tracing = "0.31.1"
-opentelemetry-otlp = { version = "0.31.0", features = ["grpc-tonic", "gzip-tonic", "http-json", "reqwest-rustls"] }
-opentelemetry_sdk = "0.31.0"
+opentelemetry = "0.32.0"
+opentelemetry-appender-tracing = "0.32.0"
+opentelemetry-otlp = { version = "0.32.0", features = ["grpc-tonic", "gzip-tonic", "http-json", "reqwest-rustls"] }
+opentelemetry_sdk = "0.32.0"
 pbkdf2 = "0.12"
 peg = "0.8.5"
 pkg-config = "0.3.30"
@@ -56,8 +71,8 @@
 serde = { version = "1.0", features = ["derive"] }
 serde_json = "1.0"
 sha2 = "0.10"
-shlex = "1.3"
-tabled = "0.20.0"
+shlex = "2.0.1"
+tabled = "0.21.0"
 tempfile = "3.20"
 test-log = { version = "0.2.19", features = ["trace"] }
 thiserror = "2.0.12"
@@ -65,12 +80,16 @@
 tokio = { version = "1.45.1", features = ["fs", "macros", "rt", "rt-multi-thread", "sync", "time"] }
 tracing = "0.1"
 tracing-indicatif = "0.3.13"
-tracing-opentelemetry = "0.32.1"
+tracing-opentelemetry = "0.33.0"
 # For fixed coloring needs to be updated to https://github.com/tokio-rs/tracing/pull/3484
 tracing-subscriber = { version = "0.3.19", features = ["env-filter", "fmt"] }
 unicode_categories = "0.1.1"
 vte = { version = "0.15.0", features = ["ansi"] }
 x25519-dalek = { version = "2.0.1", features = ["getrandom"] }
+zbus = "5.16.0"
+zbus_polkit = "5.0.0"
+tokio-util = "0.7.11"
+pam-client = "0.5.0"
 
 [profile.dev]
 panic = "abort"
modifiedcmds/remowt-plugin-fleet/src/main.rsdiffbeforeafterboth
--- a/cmds/remowt-plugin-fleet/src/main.rs
+++ b/cmds/remowt-plugin-fleet/src/main.rs
@@ -1,4 +1,4 @@
-use remowt_fleet::{Nix, init_libraries};
+use remowt_fleet::{init_libraries, Nix};
 
 fn main() -> anyhow::Result<()> {
 	remowt_plugin::run(|rpc| {
modifiedcrates/fleet-base/src/host.rsdiffbeforeafterboth
--- a/crates/fleet-base/src/host.rs
+++ b/crates/fleet-base/src/host.rs
@@ -425,9 +425,9 @@
 			warn!("failed to sign store paths: {e}");
 		}
 		let store = self.nix_store().await?;
+		let eval_store = eval_store();
 		{
 			let path = path.clone();
-			let eval_store = eval_store();
 			spawn_blocking(move || eval_store.copy_to(&store, path.as_ref()))
 				.await
 				.expect("copy_to panicked")
modifiedcrates/nix-eval/src/lib.rsdiffbeforeafterboth
--- a/crates/nix-eval/src/lib.rs
+++ b/crates/nix-eval/src/lib.rs
@@ -565,7 +565,7 @@
 	#[instrument(skip(self, dst))]
 	pub fn copy_to(&self, dst: &Store, path: &Utf8Path) -> Result<()> {
 		let sp = self
-			.parse_path(&path)
+			.parse_path(path)
 			.context("failed to parse store path")?;
 		let rc = with_default_context(|c, _| unsafe {
 			store_copy_closure(c, self.as_ptr(), dst.0, sp.as_ptr())
addedremowt/README.adocdiffbeforeafterboth
--- /dev/null
+++ b/remowt/README.adoc
@@ -0,0 +1,3 @@
+= Remowt
+
+A framework for executing code on remote machines.
addedremowt/cmds/polkit-dbus-helper/Cargo.tomldiffbeforeafterboth
--- /dev/null
+++ b/remowt/cmds/polkit-dbus-helper/Cargo.toml
@@ -0,0 +1,19 @@
+[package]
+name = "polkit-backend"
+description = "polkit/PAM D-Bus authentication backend for remowt"
+version.workspace = true
+edition = "2021"
+license.workspace = true
+
+[dependencies]
+anyhow.workspace = true
+clap = { workspace = true, features = ["derive"] }
+nix.workspace = true
+pam-client.workspace = true
+remowt-polkit-shared.workspace = true
+tokio = { workspace = true, features = ["macros", "rt", "rt-multi-thread"] }
+tracing.workspace = true
+tracing-subscriber.workspace = true
+remowt-ui-prompt.workspace = true
+zbus = { workspace = true, features = ["tokio"] }
+zbus_polkit = { workspace = true, features = ["tokio"] }
addedremowt/cmds/polkit-dbus-helper/README.adocdiffbeforeafterboth
--- /dev/null
+++ b/remowt/cmds/polkit-dbus-helper/README.adoc
@@ -0,0 +1,8 @@
+== What is it?
+
+Usually, there is a `polkit-agent-helper-1` suid binary installed on the system with polkit package.
+
+This, however, an alternative to that approach, a system daemon listening for dbus requests, which works
+without using suid binaries.
+
+In future it will provide some additional features.
addedremowt/cmds/polkit-dbus-helper/etc/systemd/system/remowt-polkit-helper.servicediffbeforeafterboth
--- /dev/null
+++ b/remowt/cmds/polkit-dbus-helper/etc/systemd/system/remowt-polkit-helper.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Remowt polkit helper service
+
+[Service]
+Type=dbus
+BusName=lach.polkit.helper1
+ExecStart=@libexecdir@/polkit-backend
+# TODO: Hardening
+
+[Install]
+WantedBy=multi-user.target
+Alias=dbus-lach.polkit.helper1.service
addedremowt/cmds/polkit-dbus-helper/share/dbus-1/system-services/lach.polkit.helper1.confdiffbeforeafterboth
--- /dev/null
+++ b/remowt/cmds/polkit-dbus-helper/share/dbus-1/system-services/lach.polkit.helper1.conf
@@ -0,0 +1,5 @@
+[D-BUS Service]
+Name=lach.polkit.helper1
+Exec=/bin/false
+User=root
+SystemdService=dbus-lach.polkit.helper1.service
addedremowt/cmds/polkit-dbus-helper/share/dbus-1/system.d/lach.polkit.helper1.confdiffbeforeafterboth
--- /dev/null
+++ b/remowt/cmds/polkit-dbus-helper/share/dbus-1/system.d/lach.polkit.helper1.conf
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" "https://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+	<policy user="root">
+		<allow own = "lach.polkit.helper1"/>
+		<allow send_interface="lach.PolkitInputHandler"/>
+	</policy>
+	<policy context="default">
+		<allow send_destination="lach.polkit.helper1"/>
+		<deny send_interface="lach.PolkitInputHandler"/>
+	</policy>
+</busconfig>
addedremowt/cmds/polkit-dbus-helper/src/main.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/cmds/polkit-dbus-helper/src/main.rs
@@ -0,0 +1,236 @@
+use std::collections::{HashMap, HashSet};
+use std::ffi::{CStr, CString};
+use std::future::pending;
+use std::sync::LazyLock;
+
+use anyhow::Context as _;
+use clap::Parser;
+use nix::unistd::{setuid, Uid, User};
+use pam_client::{Context, ConversationHandler, ErrorCode, Flag};
+use remowt_polkit_shared::BackendRequest;
+use remowt_ui_prompt::dbus::DbusPrompterProxyBlocking;
+use remowt_ui_prompt::BlockingPrompter;
+use tokio::task::{block_in_place, spawn_blocking};
+use tracing::trace;
+use zbus::fdo;
+use zbus::message::Header;
+use zbus::zvariant::OwnedValue;
+use zbus::{blocking, interface, proxy, Connection};
+
+struct Helper {
+	connection: Connection,
+	blocking_connection: blocking::Connection,
+}
+
+static ALLOWED_ENVIRONMENT: LazyLock<HashSet<&str>> = LazyLock::new(|| {
+	[
+		// pam ssh agent auth
+		"SSH_AUTH_SOCK",
+		// ssh itself provides this when running PAM
+		"SSH_AUTH_INFO_0",
+		// contains user which ran sudo
+		"SUDO_USER",
+	]
+	.into_iter()
+	.collect()
+});
+
+struct Conversation<P>(P);
+impl<P: BlockingPrompter> Conversation<P> {
+	fn prompt_inner(&self, echo: bool, prompt: &CStr) -> Result<CString, ErrorCode> {
+		trace!("do prompt");
+		let out = self
+			.0
+			.prompt_text(echo, &prompt.to_string_lossy(), "PAM prompt request", &[])
+			.map_err(|e| {
+				trace!("prompt error: {e}");
+				ErrorCode::CONV_ERR
+			})?;
+		CString::new(out).map_err(|_| ErrorCode::CONV_AGAIN)
+	}
+	fn text_inner(&self, error: bool, msg: &CStr) {
+		trace!("do text");
+		let msg = msg.to_string_lossy();
+		let _ = self.0.display_text(error, &msg, &[]);
+	}
+}
+impl<P: BlockingPrompter> ConversationHandler for Conversation<P> {
+	fn prompt_echo_on(&mut self, prompt: &CStr) -> Result<CString, ErrorCode> {
+		self.prompt_inner(true, prompt)
+	}
+
+	fn prompt_echo_off(&mut self, prompt: &CStr) -> Result<CString, ErrorCode> {
+		self.prompt_inner(false, prompt)
+	}
+
+	fn text_info(&mut self, msg: &CStr) {
+		self.text_inner(false, msg)
+	}
+
+	fn error_msg(&mut self, msg: &CStr) {
+		self.text_inner(true, msg)
+	}
+
+	fn radio_prompt(&mut self, prompt: &CStr) -> Result<bool, ErrorCode> {
+		let prompt = prompt.to_string_lossy();
+		let result = self
+			.0
+			.prompt_radio(&prompt, "PAM prompt request", &[])
+			.map_err(|_| ErrorCode::CONV_ERR)?;
+		Ok(result)
+	}
+}
+
+#[proxy(
+	default_service = "org.freedesktop.DBus",
+	default_path = "/org/freedesktop/DBus"
+)]
+trait DBus {
+	fn get_connection_credentials(&self, body: &str) -> zbus::Result<HashMap<String, OwnedValue>>;
+}
+
+#[interface(name = "lach.PolkitHelper")]
+impl Helper {
+	async fn init_conversation(
+		&self,
+		request: BackendRequest,
+		#[zbus(header)] hdr: Header<'_>,
+	) -> fdo::Result<()> {
+		let Some(sender) = hdr.sender().map(|v| v.to_owned()) else {
+			trace!("missing sender");
+			return Err(fdo::Error::AuthFailed("missing sender".to_owned()));
+		};
+
+		let dbus = DBusProxy::new(&self.connection).await?;
+
+		// TOCTOU: sender might be already disconnected, and there might be another
+		// user with different user id here, but does it matters?
+		let reply = dbus.get_connection_credentials(&sender).await?;
+		let connection_uid: u32 = (&reply["UnixUserID"]).try_into().unwrap();
+
+		let identity = request.identity.clone();
+		let blocking_connection = self.blocking_connection.clone();
+		let thread_result: fdo::Result<()> = block_in_place(move || {
+			trace!("find user");
+			let Some(identity_uid) = identity.uid() else {
+				return Err(fdo::Error::AuthFailed("can't process identity".to_owned()));
+			};
+			let user = User::from_uid(identity_uid)
+				.map_err(|_| fdo::Error::AuthFailed("error querying user".to_owned()))?
+				.ok_or_else(|| fdo::Error::AuthFailed("uid not found".to_owned()))?;
+
+			let responder = DbusPrompterProxyBlocking::new(
+				&blocking_connection,
+				sender,
+				request.prompter_path,
+			)?;
+			let conversation = Conversation(responder);
+			trace!("run context for {}", &user.name);
+			let mut ctx = Context::new(
+				// TODO: Should another scope be used?
+				"login",
+				Some(&user.name),
+				conversation,
+			)
+			.map_err(|_| fdo::Error::Failed("pam context init failed".to_owned()))?;
+
+			trace!("fill env");
+			for (k, v) in request.environment {
+				if k.contains('=') || !ALLOWED_ENVIRONMENT.contains(k.as_str()) {
+					continue;
+				}
+				let _ = ctx.putenv(format!("{k}={v}"));
+			}
+
+			trace!("authenticate");
+			ctx.authenticate(Flag::NONE)
+				.map_err(|_| fdo::Error::AuthFailed("pam authentication failed".to_owned()))?;
+
+			trace!("acct mgmt");
+			ctx.acct_mgmt(Flag::NONE)
+				.map_err(|_| fdo::Error::AuthFailed("pam acct mgmt failed".to_owned()))?;
+
+			Ok(())
+		});
+
+		thread_result?;
+
+		trace!("respond");
+		let proxy = zbus_polkit::policykit1::AuthorityProxy::new(&self.connection).await?;
+
+		let identity_details = request
+			.identity
+			.details
+			.iter()
+			.map(|(k, v)| (k.as_str(), (**v).try_clone().expect("success")))
+			.collect::<HashMap<_, _>>();
+		proxy
+			.authentication_agent_response2(
+				connection_uid,
+				&request.cookie,
+				&zbus_polkit::policykit1::Identity {
+					identity_kind: &request.identity.kind,
+					identity_details: &identity_details,
+				},
+			)
+			.await?;
+		Ok(())
+	}
+}
+
+const OBJ_PATH: &str = "/lach/PolkitHelper";
+
+#[derive(Parser)]
+struct Opts {
+	/// Not recommended: start as a session connection, then use escalation
+	/// to respond to polkit requests.
+	#[arg(long)]
+	session: bool,
+}
+
+#[tokio::main]
+async fn main() -> anyhow::Result<()> {
+	tracing_subscriber::fmt::init();
+	let opts = Opts::parse();
+	let connection = if opts.session {
+		Connection::session().await
+	} else {
+		Connection::system().await
+	}
+	.context("failed to open connection")?;
+
+	let session = opts.session;
+	let blocking_connection: anyhow::Result<blocking::Connection> = spawn_blocking(move || {
+		Ok(if session {
+			blocking::Connection::session()?
+		} else {
+			blocking::Connection::system()?
+		})
+	})
+	.await?;
+	let blocking_connection = blocking_connection.context("failed to open blocking connection")?;
+
+	if opts.session {
+		setuid(Uid::from_raw(0))
+			.context("polkit-backend needs to be suid if run in session mode")?;
+	}
+
+	connection
+		.object_server()
+		.at(
+			OBJ_PATH,
+			Helper {
+				connection: connection.clone(),
+				blocking_connection,
+			},
+		)
+		.await
+		.context("failed listen path")?;
+
+	connection
+		.request_name("lach.polkit.helper1")
+		.await
+		.context("failed to request name")?;
+
+	pending().await
+}
addedremowt/cmds/remowt-agent/Cargo.tomldiffbeforeafterboth
--- /dev/null
+++ b/remowt/cmds/remowt-agent/Cargo.toml
@@ -0,0 +1,35 @@
+[package]
+name = "remowt-agent"
+description = "remowt on-host agent serving fs/pty/systemd endpoints over bifrostlink"
+version.workspace = true
+edition = "2021"
+license.workspace = true
+
+[dependencies]
+anyhow.workspace = true
+bifrostlink.workspace = true
+bifrostlink-ports.workspace = true
+clap = { workspace = true, features = ["derive"] }
+futures.workspace = true
+nix.workspace = true
+remowt-polkit-shared.workspace = true
+remowt-link-shared.workspace = true
+remowt-plugin.workspace = true
+tempfile.workspace = true
+tokio = { workspace = true, features = [
+	"rt",
+	"fs",
+	"macros",
+	"net",
+	"io-util",
+	"time",
+	"process",
+] }
+tokio-util = { workspace = true, features = ["codec"] }
+tracing.workspace = true
+tracing-subscriber.workspace = true
+remowt-ui-prompt.workspace = true
+uuid = { workspace = true, features = ["v4"] }
+zbus = { workspace = true, features = ["tokio"] }
+zbus_polkit = { workspace = true, features = ["tokio"] }
+remowt-endpoints.workspace = true
addedremowt/cmds/remowt-agent/src/askpass.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/cmds/remowt-agent/src/askpass.rs
@@ -0,0 +1,51 @@
+use std::borrow::Cow;
+use std::io::Write as _;
+
+use anyhow::Context as _;
+use remowt_ui_prompt::dbus::{DbusPrompterInterface, DbusPrompterProxy, BUS_NAME, PROMPTER_PATH};
+use remowt_ui_prompt::{Prompter, Source};
+use tracing::debug;
+use zbus::Connection;
+
+pub async fn serve<P>(conn: &Connection, prompter: P) -> anyhow::Result<()>
+where
+	P: Prompter + 'static,
+{
+	conn.object_server()
+		.at(PROMPTER_PATH, DbusPrompterInterface(prompter))
+		.await?;
+	match conn.request_name(BUS_NAME).await {
+		Ok(()) => {}
+		Err(zbus::Error::NameTaken) => {
+			debug!("{BUS_NAME} already owned, chaining to upstream");
+		}
+		Err(e) => return Err(e.into()),
+	}
+	Ok(())
+}
+
+pub async fn ask(prompt: &str, description: String) -> anyhow::Result<()> {
+	let conn = Connection::session()
+		.await
+		.context("connecting to the session bus (DBUS_SESSION_BUS_ADDRESS)")?;
+	let proxy = DbusPrompterProxy::builder(&conn)
+		.destination(BUS_NAME)?
+		.path(PROMPTER_PATH)?
+		.build()
+		.await?;
+
+	let password = proxy
+		.prompt_text(
+			false,
+			prompt,
+			&description,
+			&[Source(Cow::Borrowed("remowt-askpass"))],
+		)
+		.await?;
+
+	let mut out = std::io::stdout().lock();
+	out.write_all(password.as_bytes())?;
+	out.write_all(b"\n")?;
+	out.flush()?;
+	Ok(())
+}
addedremowt/cmds/remowt-agent/src/bus.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/cmds/remowt-agent/src/bus.rs
@@ -0,0 +1,40 @@
+use std::process::Stdio;
+
+use anyhow::Context as _;
+use futures::StreamExt as _;
+use tokio::process::{Child, Command};
+use tokio_util::codec::{FramedRead, LinesCodec};
+use zbus::Connection;
+
+pub struct PrivateBus {
+	pub address: String,
+	pub conn: Connection,
+	_child: Child,
+}
+
+pub async fn spawn() -> anyhow::Result<PrivateBus> {
+	let mut child = Command::new("dbus-daemon")
+		.args(["--session", "--nofork", "--print-address"])
+		.stdout(Stdio::piped())
+		.kill_on_drop(true)
+		.spawn()
+		.context("spawning dbus-daemon for the private bus")?;
+
+	let stdout = child.stdout.take().expect("piped");
+	let address = FramedRead::new(stdout, LinesCodec::new())
+		.next()
+		.await
+		.context("dbus-daemon exited before printing its address")?
+		.context("reading dbus-daemon address")?;
+
+	let conn = zbus::connection::Builder::address(address.as_str())?
+		.build()
+		.await
+		.context("connecting to the private bus")?;
+
+	Ok(PrivateBus {
+		address,
+		conn,
+		_child: child,
+	})
+}
addedremowt/cmds/remowt-agent/src/editor.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/cmds/remowt-agent/src/editor.rs
@@ -0,0 +1,158 @@
+use std::env::{current_dir, temp_dir};
+use std::path::Path;
+use std::time::Duration;
+use std::{fs, io};
+
+use anyhow::{bail, Context as _};
+use nix::libc;
+use remowt_link_shared::editor::EditorEndpointsClient;
+use tokio::process::Command;
+use zbus::{fdo, interface, proxy, Connection};
+
+use remowt_link_shared::BifConfig;
+
+const BUS_NAME: &str = "lach.RemowtEditor";
+const SERVICE_PATH: &str = "/lach/Editor";
+
+pub struct EditorService {
+	editor: EditorEndpointsClient<BifConfig>,
+}
+
+#[interface(name = "lach.RemowtEditor")]
+impl EditorService {
+	/// Attach the User's GUI to the nvim server at `socket_path` (on the remote),
+	/// blocking until the user is done.
+	async fn edit(&self, socket_path: String) -> fdo::Result<()> {
+		self.editor
+			.open_editor(socket_path)
+			.await
+			.map_err(|e| fdo::Error::Failed(format!("requesting editor on the User: {e}")))?
+			.map_err(|e| fdo::Error::Failed(format!("editor failed: {e}")))?;
+		Ok(())
+	}
+
+	async fn forward_tcp(&self, addr: String) -> fdo::Result<u16> {
+		let local = self
+			.editor
+			.expose_tcp(addr)
+			.await
+			.map_err(|e| fdo::Error::Failed(format!("requesting tcp forward on the User: {e}")))?
+			.map_err(|e| fdo::Error::Failed(format!("tcp forward failed: {e}")))?;
+		Ok(local)
+	}
+
+	async fn forward_udp(&self, addr: String) -> fdo::Result<u16> {
+		let local = self
+			.editor
+			.expose_udp(addr)
+			.await
+			.map_err(|e| fdo::Error::Failed(format!("requesting udp forward on the User: {e}")))?
+			.map_err(|e| fdo::Error::Failed(format!("udp forward failed: {e}")))?;
+		Ok(local)
+	}
+}
+
+pub async fn serve(
+	conn: &Connection,
+	editor: EditorEndpointsClient<BifConfig>,
+) -> anyhow::Result<()> {
+	conn.object_server()
+		.at(SERVICE_PATH, EditorService { editor })
+		.await?;
+	conn.request_name(BUS_NAME).await?;
+	Ok(())
+}
+
+#[proxy(interface = "lach.RemowtEditor")]
+trait RemowtEditor {
+	async fn edit(&self, socket_path: &str) -> fdo::Result<()>;
+	async fn forward_tcp(&self, addr: &str) -> fdo::Result<u16>;
+	async fn forward_udp(&self, addr: &str) -> fdo::Result<u16>;
+}
+
+pub async fn forward(udp: bool, addr: String) -> anyhow::Result<()> {
+	let conn = Connection::session()
+		.await
+		.context("connecting to the session bus (DBUS_SESSION_BUS_ADDRESS)")?;
+	let proxy = RemowtEditorProxy::builder(&conn)
+		.destination(BUS_NAME)?
+		.path(SERVICE_PATH)?
+		.build()
+		.await?;
+	let local = if udp {
+		proxy.forward_udp(&addr).await?
+	} else {
+		proxy.forward_tcp(&addr).await?
+	};
+	println!("{local}");
+	Ok(())
+}
+
+pub async fn edit(path: String) -> anyhow::Result<()> {
+	let path = Path::new(&path);
+	let abs = if path.is_absolute() {
+		path.to_path_buf()
+	} else {
+		current_dir()?.join(path)
+	};
+
+	let sock = temp_dir().join(format!("remowt-nvim-{}.sock", uuid::Uuid::new_v4()));
+	let sock_str = sock
+		.to_str()
+		.context("temp socket path is not utf-8")?
+		.to_owned();
+
+	let mut child = Command::new("nvim");
+	child
+		.arg("--headless")
+		.arg("--listen")
+		.arg(&sock)
+		.arg("--")
+		.arg(&abs)
+		.kill_on_drop(true);
+	// SAFETY: only an async-signal-safe `prctl` call.
+	unsafe {
+		child.pre_exec(|| {
+			if libc::prctl(libc::PR_SET_PDEATHSIG, libc::SIGKILL as libc::c_ulong) != 0 {
+				return Err(io::Error::last_os_error());
+			}
+			Ok(())
+		});
+	}
+	let mut child = child.spawn().context("spawning nvim")?;
+
+	wait_for_socket(&sock)
+		.await
+		.context("nvim did not start its server")?;
+
+	let conn = Connection::session()
+		.await
+		.context("connecting to the session bus (DBUS_SESSION_BUS_ADDRESS)")?;
+	let proxy = RemowtEditorProxy::builder(&conn)
+		.destination(BUS_NAME)?
+		.path(SERVICE_PATH)?
+		.build()
+		.await?;
+	let result = proxy.edit(&sock_str).await;
+
+	if tokio::time::timeout(Duration::from_secs(2), child.wait())
+		.await
+		.is_err()
+	{
+		let _ = child.kill().await;
+	}
+	let _ = fs::remove_file(&sock);
+
+	result?;
+	Ok(())
+}
+
+async fn wait_for_socket(path: &Path) -> anyhow::Result<()> {
+	for _ in 0..200 {
+		if tokio::fs::try_exists(path).await.unwrap_or(false) {
+			return Ok(());
+		}
+		tokio::time::sleep(Duration::from_millis(50)).await;
+	}
+	bail!("timed out waiting for {}", path.display())
+}
addedremowt/cmds/remowt-agent/src/helper/dbus.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/cmds/remowt-agent/src/helper/dbus.rs
@@ -0,0 +1,81 @@
+use std::collections::HashMap;
+use std::marker::PhantomData;
+
+use remowt_polkit_shared::{BackendRequest, Identity};
+use remowt_ui_prompt::dbus::DbusPrompterInterface;
+use remowt_ui_prompt::Prompter;
+use zbus::Connection;
+
+use crate::PolkitHelperProxy;
+
+use super::Helper;
+
+struct TemporaryPrompterInterface<P: Prompter + 'static> {
+	connection: Connection,
+	path: String,
+	_marker: PhantomData<P>,
+}
+impl<P: Prompter + 'static> TemporaryPrompterInterface<P> {
+	async fn new(connection: Connection, prompter: P) -> Self {
+		let path = format!(
+			"/remowt/prompters/{}",
+			uuid::Uuid::new_v4().to_string().replace("-", "_")
+		);
+		let _ = connection
+			.object_server()
+			.at(path.clone(), DbusPrompterInterface(prompter))
+			.await;
+		Self {
+			connection,
+			path,
+			_marker: PhantomData,
+		}
+	}
+}
+impl<P: Prompter + Send + Sync + 'static> Drop for TemporaryPrompterInterface<P> {
+	fn drop(&mut self) {
+		// Removal is async because of async RwLock used inside...
+		// We should not care about its reuse
+		let connection = self.connection.clone();
+		let path = std::mem::take(&mut self.path);
+		tokio::spawn(async move {
+			let _ = connection
+				.object_server()
+				.remove::<DbusPrompterInterface<P>, String>(path)
+				.await;
+		});
+	}
+}
+
+#[derive(Clone)]
+pub struct DbusHelper {
+	connection: Connection,
+	helper: PolkitHelperProxy<'static>,
+}
+impl DbusHelper {
+	pub async fn new(connection: Connection) -> zbus::Result<Self> {
+		let helper = PolkitHelperProxy::new(&connection).await?;
+		Ok(Self { connection, helper })
+	}
+}
+impl Helper for DbusHelper {
+	async fn help_me<P: Prompter + Send + Sync + 'static>(
+		&self,
+		cookie: &str,
+		prompter: P,
+		identity: Identity,
+	) -> anyhow::Result<()> {
+		let prompter = TemporaryPrompterInterface::new(self.connection.clone(), prompter).await;
+		self.helper
+			.init_conversation(
+				BackendRequest {
+					cookie: cookie.to_owned(),
+					environment: HashMap::new(),
+					prompter_path: prompter.path.clone(),
+					identity,
+				}, // cookie.to_owned(), HashMap::new(), prompter.path.clone()
+			)
+			.await?;
+		Ok(())
+	}
+}
addedremowt/cmds/remowt-agent/src/helper/mod.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/cmds/remowt-agent/src/helper/mod.rs
@@ -0,0 +1,21 @@
+use futures::Future;
+use remowt_polkit_shared::Identity;
+use remowt_ui_prompt::Prompter;
+
+mod dbus;
+mod protocol;
+mod socket;
+mod suid;
+
+pub use dbus::DbusHelper;
+pub use socket::SocketHelper;
+pub use suid::SuidHelper;
+
+pub trait Helper {
+	fn help_me<P: Prompter + Send + Sync + 'static>(
+		&self,
+		cookie: &str,
+		prompt: P,
+		identity: Identity,
+	) -> impl Future<Output = anyhow::Result<()>> + Send;
+}
addedremowt/cmds/remowt-agent/src/helper/protocol.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/cmds/remowt-agent/src/helper/protocol.rs
@@ -0,0 +1,50 @@
+use std::pin::pin;
+
+use anyhow::bail;
+use futures::stream::Peekable;
+use futures::StreamExt as _;
+use remowt_ui_prompt::Prompter;
+use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt as _};
+use tokio::select;
+use tokio_util::codec::{FramedRead, LinesCodec};
+
+pub async fn run_conversation<R, W, P>(reader: R, mut writer: W, prompt: P) -> anyhow::Result<()>
+where
+	R: AsyncRead,
+	W: AsyncWrite + Unpin,
+	P: Prompter,
+{
+	let mut lines = pin!(FramedRead::new(reader, LinesCodec::new()).peekable());
+
+	while let Some(line) = lines.next().await {
+		let line = line?;
+		let res = if let Some(prompt_text) = line.strip_prefix("PAM_PROMPT_ECHO_OFF ") {
+			prompt.prompt_text(false, prompt_text, "", &[]).await?
+		} else if let Some(prompt_text) = line.strip_prefix("PAM_PROMPT_ECHO_ON ") {
+			prompt.prompt_text(true, prompt_text, "", &[]).await?
+		} else if let Some(msg_text) = line.strip_prefix("PAM_ERROR_MSG ") {
+			prompt.display_text(true, msg_text, &[]).await?;
+			String::new()
+		} else if let Some(msg_text) = line.strip_prefix("PAM_TEXT_INFO ") {
+			select! {
+				_ = Peekable::peek(lines.as_mut()) => {},
+				r = prompt.display_text(false, msg_text, &[]) => {r?}
+			}
+			String::new()
+		} else if line == "SUCCESS" {
+			return Ok(());
+		} else if line == "FAILURE" {
+			bail!("helper reported failure")
+		} else {
+			bail!("unknown agent request: {line}")
+		};
+
+		if res.contains('\n') {
+			bail!("response should not include newline")
+		}
+
+		writer.write_all(res.as_bytes()).await?;
+		writer.write_all(b"\n").await?;
+	}
+	bail!("agent finished unexpectedly")
+}
addedremowt/cmds/remowt-agent/src/helper/socket.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/cmds/remowt-agent/src/helper/socket.rs
@@ -0,0 +1,53 @@
+use anyhow::{anyhow, bail};
+use nix::unistd::User;
+use remowt_polkit_shared::Identity;
+use remowt_ui_prompt::Prompter;
+use tokio::io::AsyncWriteExt as _;
+use tokio::net::UnixStream;
+use tracing::debug;
+
+use super::protocol::run_conversation;
+use super::Helper;
+
+/// Polkit 127 introduced an alternative backend similar to `lach.PolkitHelper`
+const SOCKET_PATH: &str = "/run/polkit/agent-helper.socket";
+
+#[derive(Clone)]
+pub struct SocketHelper<F> {
+	pub fallback: F,
+}
+
+impl<F: Helper + Sync> Helper for SocketHelper<F> {
+	async fn help_me<P: Prompter + Send + Sync + 'static>(
+		&self,
+		cookie: &str,
+		prompt: P,
+		identity: Identity,
+	) -> anyhow::Result<()> {
+		let Some(uid) = identity.uid() else {
+			bail!("can't process identity");
+		};
+
+		let stream = match UnixStream::connect(SOCKET_PATH).await {
+			Ok(stream) => stream,
+			Err(e) => {
+				debug!("agent-helper.socket unavailable ({e}), using fallback helper");
+				return self.fallback.help_me(cookie, prompt, identity).await;
+			}
+		};
+
+		let user = User::from_uid(uid)
+			.map_err(|e| anyhow!("error querying user: {e}"))?
+			.ok_or_else(|| anyhow!("user not found"))?;
+
+		assert!(!cookie.contains('\n'));
+		let (reader, mut writer) = stream.into_split();
+
+		writer.write_all(user.name.as_bytes()).await?;
+		writer.write_all(b"\n").await?;
+		writer.write_all(cookie.as_bytes()).await?;
+		writer.write_all(b"\n").await?;
+
+		run_conversation(reader, writer, prompt).await
+	}
+}
addedremowt/cmds/remowt-agent/src/helper/suid.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/cmds/remowt-agent/src/helper/suid.rs
@@ -0,0 +1,46 @@
+use std::process::Stdio;
+
+use anyhow::{anyhow, bail};
+use nix::unistd::User;
+use remowt_polkit_shared::Identity;
+use remowt_ui_prompt::Prompter;
+use tokio::io::AsyncWriteExt as _;
+use tokio::process::Command;
+
+use super::protocol::run_conversation;
+use super::Helper;
+
+#[derive(Clone)]
+pub struct SuidHelper;
+impl Helper for SuidHelper {
+	async fn help_me<P: Prompter + 'static>(
+		&self,
+		cookie: &str,
+		prompt: P,
+		identity: Identity,
+	) -> anyhow::Result<()> {
+		let Some(uid) = identity.uid() else {
+			bail!("can't process identity");
+		};
+		let user = User::from_uid(uid)
+			.map_err(|e| anyhow!("error querying user: {e}"))?
+			.ok_or_else(|| anyhow!("user not found"))?;
+
+		let mut cmd = Command::new("polkit-agent-helper-1");
+		cmd.arg(user.name);
+		cmd.stdin(Stdio::piped());
+		cmd.stdout(Stdio::piped());
+		cmd.kill_on_drop(true);
+		let mut child = cmd.spawn()?;
+		let mut stdin = child.stdin.take().expect("piped");
+		let stdout = child.stdout.take().expect("piped");
+
+		assert!(!cookie.contains('\n'));
+		stdin.write_all(cookie.as_bytes()).await?;
+		stdin.write_all(b"\n").await?;
+
+		let res = run_conversation(stdout, stdin, prompt).await;
+		drop(child);
+		res
+	}
+}
addedremowt/cmds/remowt-agent/src/main.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/cmds/remowt-agent/src/main.rs
@@ -0,0 +1,437 @@
+use std::borrow::Cow;
+use std::collections::{BTreeMap, HashMap};
+use std::fs::Permissions;
+use std::future::pending;
+use std::io;
+use std::os::unix::fs::PermissionsExt as _;
+use std::path::PathBuf;
+use std::sync::{Arc, Mutex, OnceLock};
+
+use bifrostlink::declarative::RemoteEndpoints;
+use bifrostlink::Rpc;
+use bifrostlink_ports::stdio::from_stdio;
+use bifrostlink_ports::unix_socket::from_socket;
+use clap::Parser;
+use remowt_endpoints::{
+	forward::Forward, fs::Fs, iroh_tunnel::IrohTunnel, nix_daemon::NixDaemon, pty::Pty,
+	subprocess::Subprocess, systemd::Systemd,
+};
+use remowt_link_shared::iroh_tunnel::TunnelDialer;
+use remowt_link_shared::{editor::EditorEndpointsClient, Address, BifConfig};
+use remowt_polkit_shared::{emphasize, BackendRequest, Identity, PidDisplay};
+use remowt_ui_prompt::bifrost::PromptEndpointsClient;
+use remowt_ui_prompt::rofi::RofiPrompter;
+use remowt_ui_prompt::{PrependSourcePrompter, Prompter, Source};
+use tokio::fs;
+use tokio::net::UnixStream;
+use tokio::runtime::Builder;
+use tokio::task::AbortHandle;
+use tracing::{debug, trace};
+use zbus::fdo;
+use zbus::zvariant::{OwnedValue, Str};
+use zbus::{interface, proxy, Connection};
+use zbus_polkit::policykit1::Subject;
+
+use self::helper::{Helper, SocketHelper, SuidHelper};
+
+pub mod askpass;
+pub mod bus;
+pub mod editor;
+pub mod helper;
+
+struct CancelTaskOnDrop {
+	tasks: Arc<Mutex<HashMap<String, AbortHandle>>>,
+	handle: String,
+}
+impl Drop for CancelTaskOnDrop {
+	fn drop(&mut self) {
+		debug!("cancel on drop");
+		if let Some(task) = self
+			.tasks
+			.lock()
+			.expect("not poisoned")
+			.remove(&self.handle)
+		{
+			task.abort();
+		}
+	}
+}
+
+struct Agent<H, P> {
+	tasks: Arc<Mutex<HashMap<String, AbortHandle>>>,
+	helper: H,
+	prompter: P,
+}
+impl<H, P> Agent<H, P> {
+	fn new(helper: H, prompter: P) -> Self {
+		Agent {
+			tasks: Arc::new(Mutex::new(HashMap::new())),
+			helper,
+			prompter,
+		}
+	}
+}
+
+#[interface(name = "org.freedesktop.PolicyKit1.AuthenticationAgent")]
+impl<H, P> Agent<H, P>
+where
+	H: Helper + Clone + Send + Sync + 'static,
+	P: Prompter + Clone + Send + Sync + 'static,
+{
+	/// BeginAuthentication method
+	#[allow(clippy::too_many_arguments)]
+	async fn begin_authentication(
+		&self,
+		action_id: String,
+		message: String,
+		_icon_name: String,
+		mut details: BTreeMap<String, String>,
+		cookie: String,
+		identities: Vec<Identity>,
+	) -> zbus::fdo::Result<()> {
+		use std::fmt::Write;
+		debug!("begin auth");
+		let _cancel_guard = Arc::new(OnceLock::new());
+		let task = {
+			let helper = self.helper.clone();
+			let prompter = self.prompter.clone();
+			let cookie = cookie.clone();
+			let _cancel_guard = _cancel_guard.clone();
+			tokio::task::spawn(async move {
+				let _cancel_guard = _cancel_guard.clone();
+				trace!("conversation task");
+				let mut description = format!("{message}\n\n<b>Action id:</b> {action_id}",);
+				if let Some(subject) = details.remove("polkit.caller-pid") {
+					let _ = write!(description, "\n<b>Caller:</b> ");
+					if let Ok(pid) = subject.parse::<u32>() {
+						let _ = write!(description, "{}", PidDisplay(pid));
+					} else {
+						let _ = write!(description, "{}", emphasize("invalid pid"));
+					}
+				}
+				if let Some(subject) = details.remove("polkit.subject-pid") {
+					let _ = write!(description, "\n<b>Subject:</b> ");
+					if let Ok(pid) = subject.parse::<u32>() {
+						let _ = write!(description, "{}", PidDisplay(pid));
+					} else {
+						let _ = write!(description, "{}", emphasize("invalid pid"));
+					}
+				}
+				let mut prompter = PrependSourcePrompter {
+					source: vec![Source(Cow::Borrowed("polkit agent"))],
+					description: description.clone(),
+					prompter,
+				};
+
+				let identity_displays: Vec<String> =
+					identities.iter().map(|v| v.to_string()).collect();
+				let identity_displays: Vec<&str> =
+					identity_displays.iter().map(|v| v.as_str()).collect();
+				debug!("choose identity");
+				let choosen_identity = match identity_displays.len() {
+					0 => {
+						return Err(fdo::Error::AuthFailed(
+							"no identity to authenticate as".to_owned(),
+						))
+					}
+					1 => 0,
+					_ => {
+						prompter
+							.prompt_enum(
+								"Identity",
+								"Select identity to use for polkit authorization",
+								&identity_displays,
+								&[],
+							)
+							.await?
+					}
+				};
+				debug!("identity chosen");
+
+				let _ = write!(
+					description,
+					"\n<b>Identity:</b> {}",
+					identities[choosen_identity as usize]
+				);
+				prompter.description = description;
+
+				prompter.source.push(Source(Cow::Borrowed("polkit daemon")));
+
+				helper
+					.help_me(
+						&cookie,
+						prompter,
+						identities[choosen_identity as usize].clone(),
+					)
+					.await
+					.map_err(|e| fdo::Error::Failed(e.to_string()))?;
+				// let connection = Connection::system().await?;
+				// let helper = PolkitHelperProxy::new(&connection).await?;
+
+				Ok(())
+			})
+		};
+		self.tasks
+			.lock()
+			.unwrap()
+			.insert(cookie.clone(), task.abort_handle());
+		debug!("abort handle stored");
+		let _ = _cancel_guard.set(CancelTaskOnDrop {
+			tasks: self.tasks.clone(),
+			handle: cookie.clone(),
+		});
+
+		let _ = task.await;
+
+		Ok(())
+	}
+
+	/// CancelAuthentication method
+	async fn cancel_authentication(&self, cookie: &str) -> zbus::fdo::Result<()> {
+		debug!("auth cancelled");
+		if let Some(abort) = self.tasks.lock().unwrap().remove(cookie) {
+			debug!("abort handle found");
+			abort.abort();
+		}
+		// debug!("Authentication cancled ! {cookie}");
+		Ok(())
+	}
+}
+
+const OBJ_PATH: &str = "/org/freedesktop/PolicyKit1/AuthenticationAgent";
+
+#[proxy(
+	interface = "lach.PolkitHelper",
+	default_service = "lach.polkit.helper1",
+	default_path = "/lach/PolkitHelper"
+)]
+trait PolkitHelper {
+	fn init_conversation(&self, request: BackendRequest) -> zbus::Result<()>;
+}
+
+#[derive(Parser)]
+enum Opts {
+	AskPass {
+		prompt: String,
+		description: String,
+	},
+	Editor {
+		/// Argument to nvim
+		path: String,
+	},
+	/// Expose a remote TCP/UDP address on the local (User) machine, printing the local port.
+	Forward {
+		/// Protocol: `tcp` (ssh or iroh) or `udp` (iroh-only).
+		proto: ForwardProto,
+		/// Remote socket address to expose locally, e.g. `127.0.0.1:8080`.
+		addr: String,
+	},
+	RealAgent {
+		#[arg(long)]
+		path: Option<PathBuf>,
+		/// Expect own address to be AgentPrivileged, skip installing polkit agent
+		#[arg(long)]
+		privileged: bool,
+		#[arg(long)]
+		local: bool,
+	},
+	LocalAgent,
+}
+
+#[derive(Clone, Copy, clap::ValueEnum)]
+enum ForwardProto {
+	Tcp,
+	Udp,
+}
+
+fn main() -> anyhow::Result<()> {
+	tracing_subscriber::fmt()
+		.with_writer(io::stderr)
+		.without_time()
+		.init();
+	let opts = Opts::parse();
+
+	let runtime = Builder::new_current_thread().enable_all().build()?;
+
+	match opts {
+		Opts::AskPass {
+			prompt,
+			description,
+		} => runtime.block_on(askpass::ask(&prompt, description)),
+		Opts::LocalAgent => runtime.block_on(main_real()),
+		Opts::Editor { path } => runtime.block_on(editor::edit(path)),
+		Opts::Forward { proto, addr } => {
+			runtime.block_on(editor::forward(matches!(proto, ForwardProto::Udp), addr))
+		}
+		Opts::RealAgent {
+			path,
+			privileged,
+			local,
+		} => runtime.block_on(main_real_agent(path, privileged, local)),
+	}
+}
+async fn main_real() -> anyhow::Result<()> {
+	let system_conn = Connection::system().await?;
+	let helper = SocketHelper {
+		fallback: SuidHelper,
+	};
+	register_auth_agent(&system_conn, Agent::new(helper, RofiPrompter)).await?;
+
+	let session_conn = Connection::session().await?;
+	askpass::serve(&session_conn, RofiPrompter).await?;
+
+	let _keep_alive = (system_conn, session_conn);
+	pending().await
+}
+async fn main_real_agent(
+	path: Option<PathBuf>,
+	privileged: bool,
+	local: bool,
+) -> anyhow::Result<()> {
+	let address = if privileged {
+		Address::AgentPrivileged
+	} else {
+		Address::Agent
+	};
+	let mut rpc = Rpc::<BifConfig>::new(address);
+
+	let dialer = Arc::new(TunnelDialer::new());
+	Fs::new().register_endpoints(&mut rpc);
+	Systemd.register_endpoints(&mut rpc);
+	Pty::new(dialer.clone()).register_endpoints(&mut rpc);
+	Subprocess::new(dialer.clone()).register_endpoints(&mut rpc);
+	NixDaemon::new(dialer.clone()).register_endpoints(&mut rpc);
+	IrohTunnel::new(dialer.clone()).register_endpoints(&mut rpc);
+	Forward::new(dialer.clone()).register_endpoints(&mut rpc);
+
+	remowt_plugin::host::serve(&mut rpc);
+
+	let user_prompter = PromptEndpointsClient::wrap(rpc.remote(Address::User));
+	let editor_client = EditorEndpointsClient::wrap(rpc.remote(Address::User));
+
+	let bus = bus::spawn().await?;
+	askpass::serve(&bus.conn, user_prompter.clone()).await?;
+	editor::serve(&bus.conn, editor_client).await?;
+
+	let helpers = tempfile::Builder::new().prefix("remowt-path.").tempdir()?;
+	let exe = std::env::current_exe()?;
+	let askpass_helper = helpers.path().join("remowt-askpass");
+	let editor_helper = helpers.path().join("remowt-editor");
+	let forward_helper = helpers.path().join("remowt-forward");
+	{
+		let script = format!(
+			"#!/bin/sh\nexec {} ask-pass \"password\" \"$1\"\n",
+			sh_quote(&exe.to_string_lossy())
+		);
+		fs::write(&askpass_helper, script).await?;
+		fs::set_permissions(&askpass_helper, Permissions::from_mode(0o755)).await?;
+	}
+	{
+		let script = format!(
+			"#!/bin/sh\nexec {} editor \"$1\"\n",
+			sh_quote(&exe.to_string_lossy())
+		);
+		fs::write(&editor_helper, script).await?;
+		fs::set_permissions(&editor_helper, Permissions::from_mode(0o755)).await?;
+	}
+	{
+		let script = format!(
+			"#!/bin/sh\nexec {} forward \"$@\"\n",
+			sh_quote(&exe.to_string_lossy())
+		);
+		fs::write(&forward_helper, script).await?;
+		fs::set_permissions(&forward_helper, Permissions::from_mode(0o755)).await?;
+	}
+
+	// Safety: Hoping tokio own threads won't read any of those...
+	unsafe {
+		prepend_path(helpers.path());
+		std::env::set_var("SUDO_ASKPASS", &askpass_helper);
+		std::env::set_var("SSH_ASKPASS", &askpass_helper);
+		std::env::set_var("SSH_ASKPASS_REQUIRE", "force");
+		std::env::set_var("EDITOR", &editor_helper);
+		std::env::set_var("VISUAL", &editor_helper);
+		std::env::set_var("DBUS_SESSION_BUS_ADDRESS", &bus.address);
+	}
+
+	let port = match path {
+		Some(path) => from_socket(UnixStream::connect(path).await?),
+		None => from_stdio(),
+	};
+	rpc.add_direct(Address::User, port, bifrostlink::Rtt(0));
+
+	let polkit_conn = if !privileged && !local {
+		// The unprivileged agent doubles as a polkit authentication agent so
+		// `run0` (e.g. our own elevation) routes its prompt to the User over
+		// bifrost instead of failing on a tty-less session.
+		let conn = Connection::system().await?;
+		let helper = SocketHelper {
+			fallback: SuidHelper,
+		};
+		register_auth_agent(&conn, Agent::new(helper, user_prompter)).await?;
+		Some(conn)
+	} else {
+		None
+	};
+
+	let _keep_alive = (bus, helpers, polkit_conn);
+	pending().await
+}
+
+async fn register_auth_agent<H, P>(conn: &Connection, agent: Agent<H, P>) -> anyhow::Result<()>
+where
+	H: Helper + Clone + Send + Sync + 'static,
+	P: Prompter + Clone + Send + Sync + 'static,
+{
+	let proxy = zbus_polkit::policykit1::AuthorityProxy::new(conn).await?;
+	conn.object_server().at(OBJ_PATH, agent).await?;
+
+	let subject = auth_agent_subject()?;
+	proxy
+		.register_authentication_agent(&subject, "C", OBJ_PATH)
+		.await?;
+	debug!(kind = subject.subject_kind, "registered polkit agent");
+	Ok(())
+}
+
+fn auth_agent_subject() -> anyhow::Result<Subject> {
+	let mut details = HashMap::new();
+	if let Ok(session_id) = std::env::var("XDG_SESSION_ID") {
+		let val: OwnedValue = Str::from(session_id).into();
+		details.insert("session-id".to_string(), val);
+		return Ok(Subject {
+			subject_kind: "unix-session".to_string(),
+			subject_details: details,
+		});
+	}
+
+	details.insert("pid".to_string(), OwnedValue::from(std::process::id()));
+	Ok(Subject {
+		subject_kind: "unix-process".to_string(),
+		subject_details: details,
+	})
+}
+
+fn sh_quote(s: &str) -> String {
+	format!("'{}'", s.replace('\'', "'\\''"))
+}
+
+/// Prepend `dir` to the process `PATH`.
+///
+/// # SAFETY
+///
+/// Same as `set_var`
+unsafe fn prepend_path(dir: &std::path::Path) {
+	let value = match std::env::var_os("PATH") {
+		Some(existing) => {
+			let mut v = dir.as_os_str().to_owned();
+			v.push(":");
+			v.push(existing);
+			v
+		}
+		None => dir.as_os_str().to_owned(),
+	};
+	unsafe {
+		std::env::set_var("PATH", value);
+	}
+}
addedremowt/cmds/remowt-ssh/Cargo.tomldiffbeforeafterboth
--- /dev/null
+++ b/remowt/cmds/remowt-ssh/Cargo.toml
@@ -0,0 +1,24 @@
+[package]
+name = "remowt-ssh"
+description = "SSH transport client for connecting to a remowt agent"
+version.workspace = true
+edition = "2021"
+license.workspace = true
+
+[dependencies]
+clap = { workspace = true, features = ["derive"] }
+tracing-subscriber.workspace = true
+remowt-link-shared.workspace = true
+remowt-client.workspace = true
+tokio = { workspace = true, features = [
+	"macros",
+	"fs",
+	"net",
+	"io-util",
+	"rt",
+	"signal",
+] }
+nix = { workspace = true, features = ["term"] }
+anyhow.workspace = true
+tracing.workspace = true
+remowt-ui-prompt.workspace = true
addedremowt/cmds/remowt-ssh/src/main.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/cmds/remowt-ssh/src/main.rs
@@ -0,0 +1,230 @@
+use std::borrow::Cow;
+use std::env::VarError;
+use std::io;
+use std::os::fd::{AsRawFd, RawFd};
+use std::path::PathBuf;
+use std::pin::Pin;
+use std::task::{Context, Poll};
+
+use anyhow::anyhow;
+use clap::Parser;
+use nix::libc;
+use nix::sys::termios::{self, SetArg, Termios};
+use remowt_client::editor::SshEditor;
+use remowt_client::{AgentBundle, Remowt};
+use remowt_link_shared::editor::serve_editor;
+use remowt_ui_prompt::auto::AutoPrompter;
+use remowt_ui_prompt::bifrost::serve_prompts;
+use remowt_ui_prompt::{PrependSourcePrompter, Source};
+use tokio::io::unix::AsyncFd;
+use tokio::io::{AsyncRead, ReadBuf};
+use tokio::signal::unix::{signal, SignalKind};
+use tracing::debug;
+
+#[derive(Parser)]
+enum Opts {
+	/// Connect to remote host with remowt agent.
+	Ssh {
+		host: String,
+		#[arg(long)]
+		escalate: bool,
+	},
+	/// Connect to local host for testing the connectivity.
+	Local {
+		#[arg(long)]
+		escalate: bool,
+	},
+}
+
+fn agents_dir() -> anyhow::Result<PathBuf> {
+	std::env::var_os("REMOWT_AGENTS_DIR")
+		.map(PathBuf::from)
+		.or_else(|| option_env!("REMOWT_AGENTS_DIR").map(PathBuf::from))
+		.ok_or_else(|| anyhow!("no remowt-agents bundle"))
+}
+
+#[tokio::main(flavor = "current_thread")]
+async fn main() -> anyhow::Result<()> {
+	tracing_subscriber::fmt()
+		.with_writer(std::io::stderr)
+		.without_time()
+		.init();
+	let opts = Opts::parse();
+
+	let bundle = AgentBundle::from_dir(agents_dir()?)?;
+	let (conn, escalate) = match &opts {
+		Opts::Ssh { host, escalate } => (
+			Remowt::connect(host, &bundle, "remowt-ssh".to_owned()).await?,
+			*escalate,
+		),
+		Opts::Local { escalate } => (
+			Remowt::connect_local(&bundle, "remowt-ssh".to_owned()).await?,
+			*escalate,
+		),
+	};
+	let mut rpc = conn.rpc();
+
+	serve_prompts(
+		&mut rpc,
+		PrependSourcePrompter {
+			prompter: AutoPrompter::new().await,
+			source: match opts {
+				Opts::Ssh { host, .. } => vec![Source(Cow::Owned(format!("ssh host: {}", host)))],
+				Opts::Local { .. } => vec![],
+			},
+			description: "".to_owned(),
+		},
+	);
+	if let Some(sess) = conn.ssh() {
+		serve_editor(
+			&mut rpc,
+			SshEditor {
+				sess,
+				conn: conn.clone(),
+			},
+		);
+	}
+
+	debug!("entering shell");
+	run_shell(&conn, escalate).await?;
+	debug!("shell ended");
+
+	Ok(())
+}
+
+async fn run_shell(conn: &Remowt, escalate: bool) -> anyhow::Result<()> {
+	let term = match std::env::var("TERM") {
+		Ok(v) => v,
+		Err(VarError::NotPresent) => "xterm-256color".to_owned(),
+		Err(e) => return Err(e.into()),
+	};
+	let (cols, rows) = term_size().unwrap_or((80, 24));
+
+	let shell = conn.open_shell(&term, cols, rows, escalate).await?;
+	let resizer = shell.resizer();
+	let stream = shell.stream;
+
+	let _raw = RawMode::enable();
+
+	if let Ok(mut winch) = signal(SignalKind::window_change()) {
+		tokio::spawn(async move {
+			while winch.recv().await.is_some() {
+				if let Some((cols, rows)) = term_size() {
+					let _ = resizer.resize(cols, rows).await;
+				}
+			}
+		});
+	}
+
+	let (mut from_remote, mut to_remote) = tokio::io::split(stream);
+	let mut stdin = AsyncStdin::new()?;
+	let mut stdout = tokio::io::stdout();
+
+	tokio::select! {
+		r = tokio::io::copy(&mut from_remote, &mut stdout) => { r?; }
+		_ = tokio::io::copy(&mut stdin, &mut to_remote) => {}
+	}
+
+	Ok(())
+}
+
+struct AsyncStdin {
+	fd: AsyncFd<RawFd>,
+	original_flags: i32,
+}
+
+impl AsyncStdin {
+	fn new() -> io::Result<Self> {
+		let raw = libc::STDIN_FILENO;
+		// SAFETY: F_GETFL/F_SETFL round-trip on a valid fd.
+		let original_flags = unsafe { libc::fcntl(raw, libc::F_GETFL) };
+		if original_flags < 0 {
+			return Err(io::Error::last_os_error());
+		}
+		if unsafe { libc::fcntl(raw, libc::F_SETFL, original_flags | libc::O_NONBLOCK) } < 0 {
+			return Err(io::Error::last_os_error());
+		}
+		Ok(Self {
+			fd: AsyncFd::new(raw)?,
+			original_flags,
+		})
+	}
+}
+
+impl Drop for AsyncStdin {
+	fn drop(&mut self) {
+		// SAFETY: restoring the flags we saved on a valid fd.
+		unsafe { libc::fcntl(libc::STDIN_FILENO, libc::F_SETFL, self.original_flags) };
+	}
+}
+
+impl AsyncRead for AsyncStdin {
+	fn poll_read(
+		self: Pin<&mut Self>,
+		cx: &mut Context<'_>,
+		buf: &mut ReadBuf<'_>,
+	) -> Poll<io::Result<()>> {
+		let this = self.get_mut();
+		loop {
+			let mut guard = match this.fd.poll_read_ready(cx) {
+				Poll::Ready(Ok(g)) => g,
+				Poll::Ready(Err(e)) => return Poll::Ready(Err(e)),
+				Poll::Pending => return Poll::Pending,
+			};
+			let unfilled = buf.initialize_unfilled();
+			let res = guard.try_io(|inner| {
+				let fd = *inner.get_ref();
+				// SAFETY: writing into `unfilled`'s own backing storage.
+				let n = unsafe { libc::read(fd, unfilled.as_mut_ptr().cast(), unfilled.len()) };
+				if n < 0 {
+					Err(io::Error::last_os_error())
+				} else {
+					Ok(n as usize)
+				}
+			});
+			match res {
+				Ok(Ok(n)) => {
+					buf.advance(n);
+					return Poll::Ready(Ok(()));
+				}
+				Ok(Err(e)) => return Poll::Ready(Err(e)),
+				Err(_would_block) => continue,
+			}
+		}
+	}
+}
+
+fn term_size() -> Option<(u16, u16)> {
+	let mut ws: libc::winsize = unsafe { std::mem::zeroed() };
+	let rc = unsafe { libc::ioctl(libc::STDIN_FILENO, libc::TIOCGWINSZ, &mut ws) };
+	if rc != 0 || ws.ws_col == 0 {
+		None
+	} else {
+		Some((ws.ws_col, ws.ws_row))
+	}
+}
+
+struct RawMode {
+	original: Termios,
+}
+
+impl RawMode {
+	fn enable() -> Option<Self> {
+		let stdin = std::io::stdin();
+		// SAFETY: trivial libc call on a borrowed fd.
+		if unsafe { libc::isatty(stdin.as_raw_fd()) } != 1 {
+			return None;
+		}
+		let original = termios::tcgetattr(&stdin).ok()?;
+		let mut raw = original.clone();
+		termios::cfmakeraw(&mut raw);
+		termios::tcsetattr(&stdin, SetArg::TCSANOW, &raw).ok()?;
+		Some(Self { original })
+	}
+}
+
+impl Drop for RawMode {
+	fn drop(&mut self) {
+		let _ = termios::tcsetattr(std::io::stdin(), SetArg::TCSANOW, &self.original);
+	}
+}
addedremowt/crates/polkit-shared/Cargo.tomldiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/polkit-shared/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "remowt-polkit-shared"
+description = "Shared polkit/PAM types for remowt"
+version.workspace = true
+edition = "2021"
+license.workspace = true
+
+[dependencies]
+nix = { workspace = true, features = ["user"] }
+serde = { workspace = true, features = ["derive"] }
+zbus.workspace = true
addedremowt/crates/polkit-shared/src/lib.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/polkit-shared/src/lib.rs
@@ -0,0 +1,113 @@
+use std::collections::HashMap;
+use std::{fmt, fs};
+
+use nix::unistd::{Uid, User};
+use serde::{Deserialize, Serialize};
+use zbus::zvariant::{OwnedValue, Type, Value};
+
+pub fn emphasize(s: impl AsRef<str>) -> String {
+	format!("<span style=\"italic\">&lt;{}&gt;</span>", escape(s),)
+}
+fn command(s: impl AsRef<str>) -> String {
+	format!("<u><tt>{}</tt></u>", s.as_ref())
+}
+fn escape(s: impl AsRef<str>) -> String {
+	s.as_ref()
+		.replace("&", "&quot;")
+		.replace("<", "&lt;")
+		.replace(">", "&gt;")
+}
+
+pub struct PidDisplay(pub u32);
+impl fmt::Display for PidDisplay {
+	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+		if self.0 == 1 {
+			emphasize("init").fmt(f)
+		} else if let Ok(proc) = fs::read_to_string(format!("/proc/{}/cmdline", self.0)) {
+			write!(
+				f,
+				"command: {}",
+				command(
+					proc.replace("\0", " ")
+						.strip_suffix(" ")
+						.expect("cmdline should end with NUL")
+				)
+			)
+		} else if let Ok(proc) = fs::read_to_string(format!("/proc/{}/comm", self.0)) {
+			write!(f, "process: {}", command(proc.replace("\0", " ")))
+		} else {
+			emphasize("unknown process").fmt(f)
+		}
+	}
+}
+
+#[derive(Serialize, Deserialize, Type, PartialEq, Debug)]
+pub struct Identity {
+	pub kind: String,
+	pub details: HashMap<String, OwnedValue>,
+}
+
+impl Identity {
+	pub fn uid(&self) -> Option<Uid> {
+		if self.kind != "unix-user" {
+			return None;
+		}
+		let uid = self.details.get("uid")?;
+		let Value::U32(uid) = &**uid else {
+			return None;
+		};
+		Some(Uid::from_raw(*uid))
+	}
+}
+
+impl fmt::Display for Identity {
+	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+		match self.kind.as_str() {
+			"unix-user" => match self.details.get("uid").map(|v| &**v) {
+				Some(Value::U32(uid)) => match User::from_uid(Uid::from_raw(*uid)) {
+					Ok(Some(u)) => write!(
+						f,
+						"user: {} {} {}",
+						u.name,
+						u.uid,
+						if u.gecos.is_empty() {
+							"".to_owned()
+						} else {
+							format!(": {}", escape(u.gecos.to_string_lossy()))
+						}
+					),
+					Ok(None) => emphasize("not found").fmt(f),
+					Err(e) => {
+						let user = format!("could not get user: {e}");
+						emphasize(&user).fmt(f)?;
+						Ok(())
+					}
+				},
+
+				_ => emphasize("unknown uid").fmt(f),
+			},
+			_ => emphasize(format!("identity of unknown kind: {}", self.kind)).fmt(f),
+		}
+	}
+}
+
+impl Clone for Identity {
+	fn clone(&self) -> Self {
+		Self {
+			kind: self.kind.clone(),
+			details: self
+				.details
+				.iter()
+				.map(|(k, v)| (k.clone(), v.try_clone().expect("no fds are expected")))
+				.collect(),
+		}
+	}
+}
+
+#[derive(Serialize, Deserialize, Type, PartialEq, Debug)]
+pub struct BackendRequest {
+	pub cookie: String,
+	pub environment: HashMap<String, String>,
+	pub prompter_path: String,
+	pub identity: Identity,
+}
addedremowt/crates/remowt-client/Cargo.tomldiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-client/Cargo.toml
@@ -0,0 +1,32 @@
+[package]
+name = "remowt-client"
+description = "russh-based client connection to a remowt agent"
+version.workspace = true
+edition = "2021"
+license.workspace = true
+
+[dependencies]
+anyhow.workspace = true
+bifrostlink.workspace = true
+bytes.workspace = true
+camino.workspace = true
+serde.workspace = true
+serde_json.workspace = true
+remowt-link-shared.workspace = true
+russh.workspace = true
+russh-config.workspace = true
+tempfile.workspace = true
+tokio = { workspace = true, features = [
+	"net",
+	"io-util",
+	"rt",
+	"sync",
+	"macros",
+	"process",
+] }
+tracing.workspace = true
+uuid = { workspace = true, features = ["v4"] }
+remowt-endpoints.workspace = true
+tokio-util = { workspace = true, features = ["codec"] }
+futures.workspace = true
+iroh.workspace = true
addedremowt/crates/remowt-client/src/editor.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-client/src/editor.rs
@@ -0,0 +1,183 @@
+use std::collections::HashMap;
+use std::net::SocketAddr;
+use std::sync::atomic::{AtomicU64, Ordering};
+use std::sync::{Arc, Mutex};
+
+use remowt_endpoints::forward::ForwardClient;
+use remowt_link_shared::editor::{EditorBackend, Error};
+use remowt_link_shared::BifConfig;
+use russh::client::Handle;
+use tokio::net::{TcpListener, UdpSocket, UnixListener};
+use tracing::error;
+
+use crate::{Remowt, SshHandler};
+
+pub struct SshEditor {
+	pub sess: Arc<Handle<SshHandler>>,
+	pub conn: Remowt,
+}
+impl EditorBackend for SshEditor {
+	async fn open_editor(&self, socket_path: String) -> Result<(), Error> {
+		let local = std::env::temp_dir().join(format!("remowt-nvim-{}.sock", uuid::Uuid::new_v4()));
+		let _ = std::fs::remove_file(&local);
+		let listener = UnixListener::bind(&local).map_err(|e| Error::Failed(e.to_string()))?;
+
+		let sess = self.sess.clone();
+		let forward = tokio::spawn(async move {
+			loop {
+				let Ok((mut stream, _)) = listener.accept().await else {
+					break;
+				};
+				let sess = sess.clone();
+				let remote = socket_path.clone();
+				tokio::spawn(async move {
+					match sess.channel_open_direct_streamlocal(remote).await {
+						Ok(ch) => {
+							let mut remote = ch.into_stream();
+							let _ = tokio::io::copy_bidirectional(&mut stream, &mut remote).await;
+						}
+						Err(e) => error!("opening direct-streamlocal to nvim failed: {e}"),
+					}
+				});
+			}
+		});
+
+		let status = tokio::process::Command::new("neovide")
+			.arg("--no-fork")
+			.arg("--server")
+			.arg(&local)
+			.status()
+			.await
+			.map_err(|e| Error::Failed(format!("spawning neovide: {e}")));
+
+		forward.abort();
+		let _ = std::fs::remove_file(&local);
+
+		match status? {
+			s if s.success() => Ok(()),
+			s => Err(Error::Failed(format!("neovide exited with {s}"))),
+		}
+	}
+
+	async fn expose_tcp(&self, addr: String) -> Result<u16, Error> {
+		let listener = TcpListener::bind(("127.0.0.1", 0))
+			.await
+			.map_err(|e| Error::Failed(e.to_string()))?;
+		let local = listener
+			.local_addr()
+			.map_err(|e| Error::Failed(e.to_string()))?
+			.port();
+
+		let conn = self.conn.clone();
+		tokio::spawn(async move {
+			loop {
+				let Ok((mut tcp, _)) = listener.accept().await else {
+					break;
+				};
+				let conn = conn.clone();
+				let addr = addr.clone();
+				tokio::spawn(async move {
+					let (forwarded, tunnel) = match conn.bind_fast_tunnel("forward", false).await {
+						Ok(v) => v,
+						Err(e) => {
+							error!("forward: bind tunnel failed: {e}");
+							return;
+						}
+					};
+					let fclient: ForwardClient<BifConfig> = conn.endpoints();
+					match fclient.connect_tcp(tunnel, addr).await {
+						Ok(Ok(())) => {}
+						Ok(Err(e)) => {
+							error!("forward: agent connect_tcp failed: {e}");
+							return;
+						}
+						Err(e) => {
+							error!("forward: connect_tcp rpc failed: {e}");
+							return;
+						}
+					}
+					match forwarded.accept().await {
+						Ok(mut stream) => {
+							let _ = tokio::io::copy_bidirectional(&mut tcp, &mut stream).await;
+						}
+						Err(e) => error!("forward: accept tunnel failed: {e}"),
+					}
+				});
+			}
+		});
+
+		Ok(local)
+	}
+
+	async fn expose_udp(&self, addr: String) -> Result<u16, Error> {
+		let router = self.conn.datagram_router().ok_or_else(|| {
+			Error::Failed(
+				"udp forward requires the iroh fast path, which is not established".into(),
+			)
+		})?;
+
+		let fclient: ForwardClient<BifConfig> = self.conn.endpoints();
+		let session = fclient
+			.open_udp(addr)
+			.await
+			.map_err(|e| Error::Failed(format!("open_udp rpc: {e}")))?
+			.map_err(|e| Error::Failed(format!("agent open_udp: {e}")))?;
+
+		let sock = Arc::new(
+			UdpSocket::bind(("127.0.0.1", 0))
+				.await
+				.map_err(|e| Error::Failed(e.to_string()))?,
+		);
+		let local = sock
+			.local_addr()
+			.map_err(|e| Error::Failed(e.to_string()))?
+			.port();
+
+		let sub_for_source: Arc<Mutex<HashMap<SocketAddr, u64>>> =
+			Arc::new(Mutex::new(HashMap::new()));
+		let source_for_sub: Arc<Mutex<HashMap<u64, SocketAddr>>> =
+			Arc::new(Mutex::new(HashMap::new()));
+		let next_sub = Arc::new(AtomicU64::new(0));
+		let mut rx = router.register(session);
+
+		let up_sock = sock.clone();
+		let up_router = router.clone();
+		let down_source_for_sub = source_for_sub.clone();
+		tokio::spawn(async move {
+			let mut buf = vec![0u8; 65535];
+			loop {
+				let (n, src) = match up_sock.recv_from(&mut buf).await {
+					Ok(v) => v,
+					Err(_) => break,
+				};
+				let sub = {
+					let mut by_src = sub_for_source.lock().expect("lock");
+					if let Some(&sub) = by_src.get(&src) {
+						sub
+					} else {
+						let sub = next_sub.fetch_add(1, Ordering::Relaxed);
+						by_src.insert(src, sub);
+						source_for_sub.lock().expect("lock").insert(sub, src);
+						sub
+					}
+				};
+				if up_router.send(session, sub, &buf[..n]).is_err() {
+					break;
+				}
+			}
+			up_router.unregister(session);
+		});
+
+		let down_sock = sock.clone();
+		tokio::spawn(async move {
+			while let Some((sub, payload)) = rx.recv().await {
+				let dst = down_source_for_sub.lock().expect("lock").get(&sub).copied();
+				if let Some(dst) = dst {
+					let _ = down_sock.send_to(&payload, dst).await;
+				}
+			}
+		});
+
+		Ok(local)
+	}
+}
addedremowt/crates/remowt-client/src/forwarded.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-client/src/forwarded.rs
@@ -0,0 +1,89 @@
+use std::io;
+use std::pin::Pin;
+use std::task::{Context, Poll};
+
+use anyhow::{anyhow, Result};
+use camino::Utf8PathBuf;
+use remowt_link_shared::iroh_tunnel::IrohBiStream;
+use russh::client::Msg;
+use russh::{Channel, ChannelStream};
+use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
+use tokio::net::{UnixListener, UnixStream};
+use tokio::sync::oneshot;
+
+pub enum RemowtListener {
+	Ssh(oneshot::Receiver<Channel<Msg>>),
+	Local(UnixListener, Utf8PathBuf),
+	Iroh(oneshot::Receiver<RemowtStream>),
+}
+
+impl RemowtListener {
+	pub async fn accept(self) -> Result<RemowtStream> {
+		match self {
+			RemowtListener::Ssh(rx) => {
+				let ch = rx
+					.await
+					.map_err(|_| anyhow!("agent never connected the forwarded socket"))?;
+				Ok(RemowtStream::Ssh(ch.into_stream()))
+			}
+			RemowtListener::Local(listener, path) => {
+				let (stream, _) = listener.accept().await?;
+				let _ = std::fs::remove_file(&path);
+				Ok(RemowtStream::Local(stream))
+			}
+			RemowtListener::Iroh(rx) => rx
+				.await
+				.map_err(|_| anyhow!("agent never opened the iroh tunnel")),
+		}
+	}
+}
+
+pub enum RemowtStream {
+	Ssh(ChannelStream<Msg>),
+	Local(UnixStream),
+	Iroh(IrohBiStream),
+}
+
+impl AsyncRead for RemowtStream {
+	fn poll_read(
+		self: Pin<&mut Self>,
+		cx: &mut Context<'_>,
+		buf: &mut ReadBuf<'_>,
+	) -> Poll<io::Result<()>> {
+		match self.get_mut() {
+			RemowtStream::Ssh(s) => Pin::new(s).poll_read(cx, buf),
+			RemowtStream::Local(s) => Pin::new(s).poll_read(cx, buf),
+			RemowtStream::Iroh(s) => Pin::new(s).poll_read(cx, buf),
+		}
+	}
+}
+
+impl AsyncWrite for RemowtStream {
+	fn poll_write(
+		self: Pin<&mut Self>,
+		cx: &mut Context<'_>,
+		buf: &[u8],
+	) -> Poll<io::Result<usize>> {
+		match self.get_mut() {
+			RemowtStream::Ssh(s) => Pin::new(s).poll_write(cx, buf),
+			RemowtStream::Local(s) => Pin::new(s).poll_write(cx, buf),
+			RemowtStream::Iroh(s) => Pin::new(s).poll_write(cx, buf),
+		}
+	}
+
+	fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
+		match self.get_mut() {
+			RemowtStream::Ssh(s) => Pin::new(s).poll_flush(cx),
+			RemowtStream::Local(s) => Pin::new(s).poll_flush(cx),
+			RemowtStream::Iroh(s) => Pin::new(s).poll_flush(cx),
+		}
+	}
+
+	fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
+		match self.get_mut() {
+			RemowtStream::Ssh(s) => Pin::new(s).poll_shutdown(cx),
+			RemowtStream::Local(s) => Pin::new(s).poll_shutdown(cx),
+			RemowtStream::Iroh(s) => Pin::new(s).poll_shutdown(cx),
+		}
+	}
+}
addedremowt/crates/remowt-client/src/lib.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-client/src/lib.rs
@@ -0,0 +1,714 @@
+use std::collections::HashMap;
+use std::env;
+use std::path::PathBuf;
+use std::sync::atomic::AtomicU64;
+use std::sync::{Arc, Mutex};
+
+use anyhow::{anyhow, bail, ensure, Context as _, Result};
+use bifrostlink::declarative::RemoteEndpoints;
+use bifrostlink::{Remote, Rpc, Rtt};
+use camino::{Utf8Path, Utf8PathBuf};
+use remowt_link_shared::iroh_tunnel::{DatagramRouter, IrohBiStream, TunnelAddr};
+use remowt_link_shared::plugin::PluginEndpointsClient;
+use remowt_link_shared::port::child_port;
+use remowt_link_shared::{Address, BifConfig};
+use russh::client::{connect, Config, Handle, Handler, Msg, Session};
+use russh::keys::agent::client::AgentClient;
+use russh::keys::agent::AgentIdentity;
+use russh::keys::check_known_hosts;
+use russh::keys::ssh_key::PublicKey;
+use russh::Channel;
+use tempfile::TempDir;
+use tokio::io::AsyncRead;
+use tokio::net::UnixListener;
+use tokio::sync::oneshot;
+use tokio::task::JoinHandle;
+use tokio::{
+	fs,
+	io::{AsyncBufReadExt as _, AsyncReadExt as _, AsyncWriteExt as _, BufReader},
+};
+use tracing::{debug, info, warn};
+use uuid::Uuid;
+
+pub mod editor;
+mod forwarded;
+mod shell;
+mod ssh_exec;
+mod subprocess;
+
+use self::ssh_exec::SshExecChild;
+pub use self::subprocess::{RemowtChild, SpawnOptions, StderrMode, StdioMode};
+pub use forwarded::{RemowtListener, RemowtStream};
+pub use shell::{RemowtShell, RemowtShellResizer};
+
+type Subs = Arc<Mutex<HashMap<Utf8PathBuf, oneshot::Sender<Channel<Msg>>>>>;
+
+fn sh_quote(s: impl AsRef<str>) -> String {
+	format!("'{}'", s.as_ref().replace('\'', "'\\''"))
+}
+
+const ESCALATORS: [(&str, &[&str]); 2] = [("run0", &["--background=", "--pipe"]), ("sudo", &[])];
+
+pub struct AgentBundle {
+	dir: PathBuf,
+	hashes: HashMap<String, String>,
+}
+
+impl AgentBundle {
+	pub fn from_dir(dir: impl Into<PathBuf>) -> Result<Self> {
+		let dir = dir.into();
+		let hashes_path = dir.join("hashes");
+		let raw = std::fs::read_to_string(&hashes_path)
+			.with_context(|| format!("reading agent hashes at {}", hashes_path.display()))?;
+		let mut hashes = HashMap::new();
+		for line in raw.lines() {
+			let line = line.trim();
+			if line.is_empty() {
+				continue;
+			}
+			let (arch, hash) = line
+				.split_once(char::is_whitespace)
+				.ok_or_else(|| anyhow!("malformed hashes line: {line:?}"))?;
+			hashes.insert(arch.to_owned(), hash.trim().to_owned());
+		}
+		ensure!(
+			!hashes.is_empty(),
+			"agent bundle {} has no hashes",
+			dir.display()
+		);
+		Ok(Self { dir, hashes })
+	}
+
+	fn binary(&self, arch: &str) -> PathBuf {
+		self.dir.join(format!("remowt-agent-{arch}"))
+	}
+
+	fn local_binary(&self) -> Result<PathBuf> {
+		let arch = env::consts::ARCH;
+		let path = self.binary(arch);
+		ensure!(
+			path.is_file(),
+			"no local remowt-agent build for arch {arch} in bundle {}",
+			self.dir.display()
+		);
+		Ok(path)
+	}
+}
+
+async fn run(sess: &Handle<SshHandler>, cmd: &str) -> Result<(Option<u32>, Vec<u8>)> {
+	let ch = sess.channel_open_session().await?;
+	ch.exec(true, cmd).await?;
+
+	let mut child = SshExecChild::from_exec(ch);
+	drop(child.stdin);
+	drain_to_tracing(child.stderr, cmd.to_owned(), true);
+
+	let mut out = Vec::new();
+	child.stdout.read_to_end(&mut out).await?;
+	let code = child.exit.await.ok().flatten();
+	Ok((code, out))
+}
+
+async fn run_string_ok(sess: &Handle<SshHandler>, cmd: &str) -> Result<String> {
+	let (code, mut out) = run(sess, cmd).await?;
+	ensure!(
+		code == Some(0),
+		"remote command failed (exit {code:?}): {cmd}"
+	);
+	if !out.is_empty() {
+		ensure!(
+			out.ends_with(b"\n"),
+			"remote command was not newline-terminated: {cmd}: {out:?}"
+		);
+		out.pop();
+	}
+	String::from_utf8(out).context("expected utf8 output for command")
+}
+
+async fn deploy_agent(sess: &Handle<SshHandler>, bundle: &AgentBundle) -> Result<Utf8PathBuf> {
+	debug!("uname -a");
+	let arch = run_string_ok(sess, "uname -m").await?;
+	let hash = bundle
+		.hashes
+		.get(&arch)
+		.ok_or_else(|| anyhow!("no remowt-agent build for remote arch {arch:?}"))?;
+
+	debug!("get dir");
+	let cache = run_string_ok(sess, "echo \"$XDG_CACHE_HOME\"").await?;
+	let dir = if cache.is_empty() {
+		let home = run_string_ok(sess, "echo \"$HOME\"").await?;
+		ensure!(
+			!home.is_empty(),
+			"remote $HOME and $XDG_CACHE_HOME both empty"
+		);
+		Utf8PathBuf::from(home).join(".cache/remowt")
+	} else {
+		Utf8PathBuf::from(cache).join("remowt")
+	};
+	let path = dir.join(hash);
+
+	debug!("presence");
+	let (present, _) = run(sess, &format!("test -x {}", sh_quote(&path))).await?;
+	if present != Some(0) {
+		let bin = bundle.binary(&arch);
+		debug!("read");
+		let bytes = fs::read(&bin)
+			.await
+			.with_context(|| format!("reading agent binary {}", bin.display()))?;
+		debug!("upload");
+		upload_agent(sess, &dir, &path, bytes).await?;
+	}
+	Ok(path)
+}
+
+async fn upload_agent(
+	sess: &Handle<SshHandler>,
+	dir: &Utf8Path,
+	path: &Utf8Path,
+	bytes: Vec<u8>,
+) -> Result<()> {
+	debug!("mkdirp");
+	run_string_ok(sess, &format!("mkdir -p {}", sh_quote(dir))).await?;
+
+	let tmp = dir.join(format!("tmp.{}", Uuid::new_v4()));
+	let ch = sess.channel_open_session().await?;
+	debug!("cat");
+	ch.exec(true, format!("cat > {}", sh_quote(&tmp))).await?;
+
+	let mut child = SshExecChild::from_exec(ch);
+	child
+		.stdin
+		.write_all(&bytes)
+		.await
+		.context("sending agent binary")?;
+	child
+		.stdin
+		.shutdown()
+		.await
+		.context("sending agent binary")?;
+	let code = child.wait().await;
+	ensure!(code == Some(0), "agent upload failed (exit {code:?})");
+
+	debug!("chmod");
+	run_string_ok(sess, &format!("chmod 0755 {}", sh_quote(&tmp))).await?;
+	run_string_ok(
+		sess,
+		&format!("mv -f {} {}", sh_quote(&tmp), sh_quote(path)),
+	)
+	.await?;
+	Ok(())
+}
+
+pub struct SshHandler {
+	host: String,
+	port: u16,
+	subs: Subs,
+}
+impl Handler for SshHandler {
+	type Error = russh::Error;
+	async fn check_server_key(
+		&mut self,
+		server_public_key: &PublicKey,
+	) -> Result<bool, Self::Error> {
+		Ok(check_known_hosts(&self.host, self.port, server_public_key)?)
+	}
+	async fn server_channel_open_forwarded_streamlocal(
+		&mut self,
+		channel: Channel<Msg>,
+		socket_path: &str,
+		_session: &mut Session,
+	) -> Result<(), Self::Error> {
+		let Some(ch) = self
+			.subs
+			.lock()
+			.expect("lock")
+			.remove(&Utf8PathBuf::from(socket_path))
+		else {
+			return Err(russh::Error::WrongChannel);
+		};
+		let _ = ch.send(channel);
+		Ok(())
+	}
+}
+
+enum Transport {
+	Ssh {
+		sess: Arc<Handle<SshHandler>>,
+		subs: Subs,
+		runtime_dir: Utf8PathBuf,
+		agent_path: Utf8PathBuf,
+	},
+	Local {
+		agent_path: PathBuf,
+		runtime_dir: Utf8PathBuf,
+	},
+}
+
+struct RemowtInner {
+	transport: Transport,
+	rpc: Rpc<BifConfig>,
+	elevated: tokio::sync::OnceCell<()>,
+	#[allow(dead_code)]
+	children: Mutex<Vec<tokio::process::Child>>,
+	_runtime_tmp: Option<TempDir>,
+	user: String,
+	iroh: IrohState,
+}
+
+#[derive(Default)]
+struct IrohState {
+	conn: tokio::sync::OnceCell<iroh::endpoint::Connection>,
+	#[allow(dead_code)]
+	endpoint: Mutex<Option<iroh::Endpoint>>,
+	subs: Arc<Mutex<HashMap<u64, oneshot::Sender<RemowtStream>>>>,
+	next_token: AtomicU64,
+	router: Mutex<Option<Arc<DatagramRouter>>>,
+}
+
+#[derive(Clone)]
+pub struct Remowt(Arc<RemowtInner>);
+
+pub type RemowtRemote = Remote<BifConfig>;
+
+impl Remowt {
+	/// Connect to the remote host over ssh, detect the architecture and deploy the required
+	/// agent binary.
+	pub async fn connect(host: &str, bundle: &AgentBundle, remowt_user: String) -> Result<Self> {
+		let conf = russh_config::parse_home(host)?;
+		let port = conf.host_config.port.or(conf.port).unwrap_or(22);
+		let hostname = conf
+			.host_config
+			.hostname
+			.clone()
+			.unwrap_or_else(|| conf.host_name.clone());
+		let user = conf
+			.user
+			.clone()
+			.unwrap_or_else(|| env::var("USER").unwrap_or_else(|_| "root".to_owned()));
+
+		let subs: Subs = Arc::new(Mutex::new(HashMap::new()));
+		let mut sess = connect(
+			Arc::new(Config::default()),
+			(hostname.clone(), port),
+			SshHandler {
+				host: hostname,
+				port,
+				subs: subs.clone(),
+			},
+		)
+		.await?;
+
+		let mut agent = AgentClient::connect_env().await?;
+		let rsa_hash = sess.best_supported_rsa_hash().await?.flatten();
+		let mut authenticated = false;
+		for ident in agent.request_identities().await? {
+			let AgentIdentity::PublicKey { key, .. } = ident else {
+				continue;
+			};
+			if sess
+				.authenticate_publickey_with(user.clone(), key, rsa_hash, &mut agent)
+				.await?
+				.success()
+			{
+				authenticated = true;
+				break;
+			}
+		}
+		ensure!(authenticated, "ssh authentication failed");
+
+		let sess = Arc::new(sess);
+
+		debug!("deploying agent");
+		let agent_path = deploy_agent(&sess, bundle).await?;
+
+		debug!("runtime dir");
+		let runtime_dir = remote_runtime_dir(&sess).await?;
+
+		let rpc = Rpc::<BifConfig>::new(Address::User);
+
+		let cmd_chan = sess.channel_open_session().await?;
+		debug!("starting agent");
+		cmd_chan
+			.exec(true, format!("{} real-agent", sh_quote(&agent_path)))
+			.await?;
+
+		let child = SshExecChild::from_exec(cmd_chan);
+		drain_to_tracing(child.stderr, "agent".to_owned(), true);
+		rpc.add_direct(
+			Address::Agent,
+			child_port(child.stdout, child.stdin),
+			Rtt(0),
+		);
+
+		let remowt = Self(Arc::new(RemowtInner {
+			transport: Transport::Ssh {
+				sess,
+				subs,
+				runtime_dir,
+				agent_path,
+			},
+			rpc,
+			elevated: tokio::sync::OnceCell::new(),
+			children: Mutex::new(Vec::new()),
+			_runtime_tmp: None,
+			user: remowt_user,
+			iroh: IrohState::default(),
+		}));
+		remowt.setup_iroh().await;
+		Ok(remowt)
+	}
+
+	/// "Connect" to the local machine's agent, by starting the agent binary locally.
+	pub async fn connect_local(bundle: &AgentBundle, user: String) -> Result<Self> {
+		let agent_path = bundle.local_binary()?;
+		let mut child = tokio::process::Command::new(&agent_path)
+			.arg("real-agent")
+			.arg("--local")
+			.stdin(std::process::Stdio::piped())
+			.stdout(std::process::Stdio::piped())
+			.kill_on_drop(true)
+			.spawn()
+			.with_context(|| format!("spawning agent binary {}", agent_path.display()))?;
+		let stdin = child.stdin.take().expect("stdin piped");
+		let stdout = child.stdout.take().expect("stdout piped");
+
+		let rpc = Rpc::<BifConfig>::new(Address::User);
+		rpc.add_direct(Address::Agent, child_port(stdout, stdin), Rtt(0));
+
+		let (runtime_dir, runtime_tmp) = local_runtime_dir()?;
+
+		Ok(Self(Arc::new(RemowtInner {
+			transport: Transport::Local {
+				agent_path,
+				runtime_dir,
+			},
+			rpc,
+			elevated: tokio::sync::OnceCell::new(),
+			children: Mutex::new(vec![child]),
+			_runtime_tmp: runtime_tmp,
+			user,
+			iroh: IrohState::default(),
+		})))
+	}
+
+	/// Get the handle to the underlying russh session handle.
+	pub fn ssh(&self) -> Option<Arc<Handle<SshHandler>>> {
+		match &self.0.transport {
+			Transport::Ssh { sess, .. } => Some(sess.clone()),
+			Transport::Local { .. } => None,
+		}
+	}
+
+	pub fn rpc(&self) -> Rpc<BifConfig> {
+		self.0.rpc.clone()
+	}
+
+	pub async fn load_plugin(&self, id: u16, name: &str) -> Result<()> {
+		let client: PluginEndpointsClient<BifConfig> = self.endpoints();
+		client
+			.load_plugin(id, name.to_owned())
+			.await?
+			.map_err(|e| anyhow!("agent failed to load plugin: {e}"))
+	}
+	pub async fn run0_load_plugin_path(&self, id: u16, path: &str) -> Result<()> {
+		self.ensure_escalated().await?;
+		let client: PluginEndpointsClient<BifConfig> =
+			PluginEndpointsClient::wrap(self.0.rpc.remote(Address::AgentPrivileged));
+		client
+			.load_plugin_path(id, path.to_owned())
+			.await?
+			.map_err(|e| anyhow!("privileged agent failed to load plugin: {e}"))
+	}
+	pub fn plugin_endpoints<R: RemoteEndpoints<BifConfig>>(&self, id: u16) -> R {
+		R::wrap(self.0.rpc.remote(Address::Plugin(id)))
+	}
+
+	pub fn endpoints<R: RemoteEndpoints<BifConfig>>(&self) -> R {
+		R::wrap(self.0.rpc.remote(Address::Agent))
+	}
+	pub async fn run0_endpoints<R: RemoteEndpoints<BifConfig>>(&self) -> Result<R> {
+		self.ensure_escalated().await?;
+		Ok(R::wrap(self.0.rpc.remote(Address::AgentPrivileged)))
+	}
+
+	async fn ensure_escalated(&self) -> Result<()> {
+		self.0
+			.elevated
+			.get_or_try_init(|| async {
+				let (agent_path, local) = match &self.0.transport {
+					Transport::Ssh { agent_path, .. } => (agent_path.as_str().to_owned(), false),
+					Transport::Local { agent_path, .. } => (
+						agent_path
+							.to_str()
+							.ok_or_else(|| anyhow!("local agent path is not utf-8"))?
+							.to_owned(),
+						true,
+					),
+				};
+
+				let (tool, flags) = self.detect_escalation().await?;
+				let mut args: Vec<String> = Vec::new();
+				args.push("-w".to_owned());
+				args.push(tool.to_owned());
+				args.extend(flags.iter().copied().map(str::to_owned));
+				if tool == "run0" {
+					args.push(format!(
+						"--unit={}-{}.service",
+						self.0.user,
+						Uuid::new_v4().simple()
+					));
+				}
+				args.push(agent_path);
+				args.push("real-agent".to_owned());
+				args.push("--privileged".to_owned());
+				if local {
+					args.push("--local".to_owned());
+				}
+
+				let child = self
+					.spawn(SpawnOptions {
+						program: "setsid".to_owned(),
+						args,
+						stdin: StdioMode::Pipe,
+						stdout: StdioMode::Pipe,
+						stderr: StderrMode::Inherit,
+						..Default::default()
+					})
+					.await
+					.context("spawning privileged agent")?;
+
+				let stdin = child
+					.stdin
+					.ok_or_else(|| anyhow!("privileged agent stdin missing"))?;
+				let stdout = child
+					.stdout
+					.ok_or_else(|| anyhow!("privileged agent stdout missing"))?;
+
+				let port = child_port(stdout, stdin);
+				self.0
+					.rpc
+					.add_direct(Address::AgentPrivileged, port, Rtt(0));
+				anyhow::Ok(())
+			})
+			.await?;
+		Ok(())
+	}
+
+	async fn detect_escalation(&self) -> Result<(&'static str, &'static [&'static str])> {
+		for (tool, flags) in ESCALATORS {
+			let probe = self
+				.spawn(SpawnOptions {
+					program: (*tool).to_owned(),
+					args: vec!["--version".to_owned()],
+					stdout: StdioMode::Null,
+					stderr: StderrMode::Null,
+					..Default::default()
+				})
+				.await;
+			if let Ok(child) = probe {
+				let _ = child.wait().await;
+				return Ok((tool, flags));
+			}
+		}
+		bail!("no escalation tool found")
+	}
+
+	/// XDG_RUNTIME_DIR on the remote machine.
+	pub fn runtime_dir(&self) -> Utf8PathBuf {
+		match &self.0.transport {
+			Transport::Ssh { runtime_dir, .. } => runtime_dir.clone(),
+			Transport::Local { runtime_dir, .. } => runtime_dir.clone(),
+		}
+	}
+
+	/// Bind unix listener socket on the remote machine with auto-generated path, returning the path.
+	pub async fn bind_runtime_unix(&self, hint: &str) -> Result<(RemowtListener, Utf8PathBuf)> {
+		let sock = self
+			.runtime_dir()
+			.join(format!("remowt-{hint}-{}.sock", Uuid::new_v4()));
+		let listener = self.bind_unix(&sock).await?;
+		Ok((listener, sock))
+	}
+
+	/// Bind unix listener socket on the remote machine on the specified path.
+	pub async fn bind_unix(&self, path: &Utf8Path) -> Result<RemowtListener> {
+		match &self.0.transport {
+			Transport::Ssh { sess, subs, .. } => {
+				let (tx, rx) = oneshot::channel();
+				subs.lock().expect("lock").insert(path.to_owned(), tx);
+				sess.streamlocal_forward(path.to_owned()).await?;
+				Ok(RemowtListener::Ssh(rx))
+			}
+			Transport::Local { .. } => {
+				let _ = std::fs::remove_file(path);
+				Ok(RemowtListener::Local(
+					UnixListener::bind(path)?,
+					path.to_owned(),
+				))
+			}
+		}
+	}
+
+	/// Bind a data tunnel, preferring the iroh fast path when it is up. Escalated tunnels
+	/// (the privileged agent, a separate process with no iroh connection of its own) and the
+	/// local transport always use the ssh/unix path.
+	pub async fn bind_fast_tunnel(
+		&self,
+		hint: &str,
+		escalated: bool,
+	) -> Result<(RemowtListener, TunnelAddr)> {
+		if !escalated && self.0.iroh.conn.get().is_some() {
+			let token = self
+				.0
+				.iroh
+				.next_token
+				.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
+			let (tx, rx) = oneshot::channel();
+			self.0.iroh.subs.lock().expect("lock").insert(token, tx);
+			return Ok((RemowtListener::Iroh(rx), TunnelAddr::Iroh { token }));
+		}
+		let (listener, path) = self.bind_runtime_unix(hint).await?;
+		Ok((listener, TunnelAddr::Unix(path)))
+	}
+
+	async fn setup_iroh(&self) {
+		if std::env::var_os("REMOWT_NO_IROH").is_some() {
+			debug!("REMOWT_NO_IROH set, skipping iroh fast tunnel");
+			return;
+		}
+		if !matches!(self.0.transport, Transport::Ssh { .. }) {
+			return;
+		}
+		if let Err(e) = self.try_setup_iroh().await {
+			warn!("iroh fast tunnel unavailable, using ssh: {e}");
+		}
+	}
+
+	async fn try_setup_iroh(&self) -> Result<()> {
+		use remowt_endpoints::iroh_tunnel::IrohTunnelClient;
+		use remowt_link_shared::iroh_tunnel::{build_endpoint, ssh_custom_addr, REMOWT_ALPN};
+
+		let (listener, sock) = self.bind_runtime_unix("iroh-xport").await?;
+		let secret = iroh::SecretKey::generate();
+		let client_id = secret.public();
+
+		let client: IrohTunnelClient<BifConfig> =
+			IrohTunnelClient::wrap(self.0.rpc.remote(Address::Agent));
+		let (accepted, agent_id) = tokio::join!(listener.accept(), client.setup(client_id, sock));
+		let stream = accepted?;
+		let agent_id = agent_id?.map_err(|e| anyhow!("agent iroh setup failed: {e}"))?;
+
+		let ep = build_endpoint(secret, stream, agent_id, false).await?;
+		let addr = iroh::EndpointAddr::from_parts(
+			agent_id,
+			[iroh::TransportAddr::Custom(ssh_custom_addr(agent_id))],
+		);
+		let conn = ep.connect(addr, REMOWT_ALPN).await?;
+		ensure!(conn.remote_id() == agent_id, "iroh peer identity mismatch");
+		info!("iroh fast tunnel established");
+
+		let subs = self.0.iroh.subs.clone();
+		let accept_conn = conn.clone();
+		tokio::spawn(async move {
+			loop {
+				match accept_conn.accept_bi().await {
+					Ok((send, mut recv)) => {
+						let subs = subs.clone();
+						tokio::spawn(async move {
+							let mut buf = [0u8; 8];
+							if tokio::io::AsyncReadExt::read_exact(&mut recv, &mut buf)
+								.await
+								.is_err()
+							{
+								return;
+							}
+							let token = u64::from_be_bytes(buf);
+							let tx = subs.lock().expect("lock").remove(&token);
+							if let Some(tx) = tx {
+								let _ = tx.send(RemowtStream::Iroh(IrohBiStream::new(send, recv)));
+							}
+						});
+					}
+					Err(e) => {
+						debug!("iroh accept loop ended: {e}");
+						break;
+					}
+				}
+			}
+		});
+
+		let log_conn = conn.clone();
+		tokio::spawn(async move {
+			tokio::time::sleep(std::time::Duration::from_secs(2)).await;
+			for p in log_conn.paths().iter() {
+				if p.is_selected() {
+					info!(rtt = ?p.rtt(), "iroh selected path: {}", p.remote_addr());
+				}
+			}
+		});
+
+		*self.0.iroh.router.lock().expect("lock") = Some(DatagramRouter::spawn(conn.clone()));
+		*self.0.iroh.endpoint.lock().expect("lock") = Some(ep);
+		let _ = self.0.iroh.conn.set(conn);
+		Ok(())
+	}
+
+	pub fn datagram_router(&self) -> Option<Arc<DatagramRouter>> {
+		self.0.iroh.router.lock().expect("lock").clone()
+	}
+}
+
+pub(crate) fn drain_to_tracing(
+	stream: impl AsyncRead + Unpin + 'static + Send,
+	context: String,
+	stderr: bool,
+) -> JoinHandle<()> {
+	tokio::spawn(async move {
+		let mut reader = BufReader::new(stream);
+		let mut buf = Vec::with_capacity(4096);
+		loop {
+			buf.clear();
+			match reader.read_until(b'\n', &mut buf).await {
+				Ok(0) => break,
+				Ok(_) => {
+					let line = String::from_utf8_lossy(buf.strip_suffix(b"\n").unwrap_or(&buf));
+					if stderr {
+						warn!(context = %context, "{line}");
+					} else {
+						info!(context = %context, "{line}");
+					}
+				}
+				Err(e) => {
+					warn!(context = %context, "child stdio read failed: {e}");
+					break;
+				}
+			}
+		}
+	})
+}
+
+fn local_runtime_dir() -> Result<(Utf8PathBuf, Option<TempDir>)> {
+	if let Ok(dir) = env::var("XDG_RUNTIME_DIR") {
+		if !dir.is_empty() {
+			return Ok((Utf8PathBuf::from(dir), None));
+		}
+	}
+	let tmp = tempfile::Builder::new()
+		.prefix("remowt.")
+		.rand_bytes(12)
+		.tempdir()?;
+	let dir = Utf8PathBuf::from_path_buf(tmp.path().to_owned())
+		.map_err(|p| anyhow!("temp dir {} is not utf-8", p.display()))?;
+	Ok((dir, Some(tmp)))
+}
+
+async fn remote_runtime_dir(sess: &Handle<SshHandler>) -> Result<Utf8PathBuf> {
+	let dir = run_string_ok(sess, "echo \"$XDG_RUNTIME_DIR\"").await?;
+	let dir = dir.trim();
+	if dir.is_empty() {
+		let tmp = run_string_ok(sess, "mktemp -d remowt.XXXXXXXXXXXX --tmpdir").await?;
+		Ok(Utf8PathBuf::from(tmp))
+	} else {
+		Ok(Utf8PathBuf::from(dir))
+	}
+}
addedremowt/crates/remowt-client/src/shell.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-client/src/shell.rs
@@ -0,0 +1,65 @@
+use anyhow::{anyhow, Result};
+use bifrostlink::declarative::RemoteEndpoints as _;
+use bifrostlink::Remote;
+use remowt_endpoints::pty::{PtyClient, ShellId};
+use remowt_link_shared::{Address, BifConfig};
+
+use crate::forwarded::RemowtStream;
+use crate::Remowt;
+
+pub struct RemowtShell {
+	pub id: ShellId,
+	pub stream: RemowtStream,
+	remote: Remote<BifConfig>,
+}
+impl RemowtShell {
+	pub fn resizer(&self) -> RemowtShellResizer {
+		RemowtShellResizer {
+			remote: self.remote.clone(),
+			id: self.id,
+		}
+	}
+}
+
+#[derive(Clone)]
+pub struct RemowtShellResizer {
+	remote: Remote<BifConfig>,
+	id: ShellId,
+}
+
+impl RemowtShellResizer {
+	pub async fn resize(&self, cols: u16, rows: u16) -> Result<()> {
+		PtyClient::wrap(self.remote.clone())
+			.resize(self.id, cols, rows)
+			.await?
+			.map_err(|e| anyhow!("failed to resize remote shell: {e}"))
+	}
+}
+
+impl Remowt {
+	pub async fn open_shell(
+		&self,
+		term: &str,
+		cols: u16,
+		rows: u16,
+		escalate: bool,
+	) -> Result<RemowtShell> {
+		let (forwarded, tunnel) = self.bind_fast_tunnel("shell", escalate).await?;
+		let client: PtyClient<BifConfig> = if escalate {
+			self.run0_endpoints().await?
+		} else {
+			self.endpoints()
+		};
+		let id = client
+			.open_shell(tunnel, term.to_owned(), cols, rows)
+			.await?
+			.map_err(|e| anyhow!("agent failed to open shell: {e}"))?;
+		let stream = forwarded.accept().await?;
+
+		Ok(RemowtShell {
+			id,
+			stream,
+			remote: self.0.rpc.remote(Address::Agent),
+		})
+	}
+}
addedremowt/crates/remowt-client/src/ssh_exec.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-client/src/ssh_exec.rs
@@ -0,0 +1,82 @@
+use bytes::Bytes;
+use russh::client::Msg;
+use russh::{Channel, ChannelMsg};
+use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _, DuplexStream};
+use tokio::sync::oneshot;
+
+const BUF: usize = 64 * 1024;
+
+pub(crate) struct SshExecChild {
+	pub stdin: DuplexStream,
+	pub stdout: DuplexStream,
+	pub stderr: DuplexStream,
+	pub exit: oneshot::Receiver<Option<u32>>,
+}
+
+impl SshExecChild {
+	/// Manage channel returned by russh exec().
+	pub(crate) fn from_exec(ch: Channel<Msg>) -> Self {
+		let (stdin, mut stdin_r) = tokio::io::duplex(BUF);
+		let (mut out_w, stdout) = tokio::io::duplex(BUF);
+		let (mut err_w, stderr) = tokio::io::duplex(BUF);
+		let (exit_tx, exit) = oneshot::channel();
+
+		tokio::spawn(async move {
+			let (mut read, write) = ch.split();
+
+			let stdin_pump = tokio::spawn(async move {
+				let mut buf = vec![0u8; BUF];
+				loop {
+					match stdin_r.read(&mut buf).await {
+						Ok(0) | Err(_) => break,
+						Ok(n) => {
+							if write
+								.data_bytes(Bytes::copy_from_slice(&buf[..n]))
+								.await
+								.is_err()
+							{
+								return;
+							}
+						}
+					}
+				}
+				let _ = write.eof().await;
+			});
+
+			let mut code = None;
+			while let Some(msg) = read.wait().await {
+				match msg {
+					ChannelMsg::Data { data } => {
+						if out_w.write_all(&data).await.is_err() {
+							break;
+						}
+					}
+					ChannelMsg::ExtendedData { data, .. } => {
+						if err_w.write_all(&data).await.is_err() {
+							break;
+						}
+					}
+					ChannelMsg::ExitStatus { exit_status } => code = Some(exit_status),
+					_ => {}
+				}
+			}
+
+			stdin_pump.abort();
+			let _ = out_w.shutdown().await;
+			let _ = err_w.shutdown().await;
+			let _ = exit_tx.send(code);
+		});
+
+		SshExecChild {
+			stdin,
+			stdout,
+			stderr,
+			exit,
+		}
+	}
+
+	/// Wait for the process to finish, returning its exit status.
+	pub(crate) async fn wait(self) -> Option<u32> {
+		self.exit.await.ok().flatten()
+	}
+}
addedremowt/crates/remowt-client/src/subprocess.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-client/src/subprocess.rs
@@ -0,0 +1,439 @@
+use std::pin::pin;
+
+use anyhow::{anyhow, bail, Result};
+use camino::Utf8PathBuf;
+use futures::StreamExt as _;
+use remowt_endpoints::subprocess::{ProcId, SpawnSpec, StderrSpec, StdioSpec, SubprocessClient};
+use remowt_link_shared::iroh_tunnel::TunnelAddr;
+use remowt_link_shared::BifConfig;
+use serde::de::DeserializeOwned;
+use tokio::io::AsyncWriteExt as _;
+use tokio::select;
+use tokio_util::codec::{BytesCodec, FramedRead, LinesCodec};
+use tracing::{debug, info, warn};
+
+use crate::forwarded::{RemowtListener, RemowtStream};
+use crate::{drain_to_tracing, Remowt};
+
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
+pub enum StdioMode {
+	#[default]
+	Null,
+	Pipe,
+	Inherit,
+}
+
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
+pub enum StderrMode {
+	#[default]
+	Null,
+	Pipe,
+	Inherit,
+	MergeWithStdout,
+}
+
+#[derive(Default)]
+pub struct SpawnOptions {
+	pub program: String,
+	pub args: Vec<String>,
+	pub env: Vec<(String, String)>,
+	pub env_clear: bool,
+	pub cwd: Option<Utf8PathBuf>,
+	pub escalated: bool,
+	pub stdin: StdioMode,
+	pub stdout: StdioMode,
+	pub stderr: StderrMode,
+}
+
+pub struct RemowtChild {
+	pub stdin: Option<RemowtStream>,
+	pub stdout: Option<RemowtStream>,
+	pub stderr: Option<RemowtStream>,
+	id: ProcId,
+	client: SubprocessClient<BifConfig>,
+}
+
+impl RemowtChild {
+	pub async fn wait(self) -> Result<Option<i32>> {
+		let RemowtChild {
+			stdin,
+			stdout,
+			stderr,
+			id,
+			client,
+		} = self;
+		drop(stdin);
+		let drain_out = async move {
+			if let Some(s) = stdout {
+				let _ = drain_to_tracing(s, "<child stdout>".to_owned(), false).await;
+			}
+		};
+		let drain_err = async move {
+			if let Some(s) = stderr {
+				let _ = drain_to_tracing(s, "<child stderr>".to_owned(), true).await;
+			}
+		};
+		let wait = async move {
+			client
+				.wait(id)
+				.await?
+				.map_err(|e| anyhow!("agent wait failed: {e}"))
+		};
+		let (code, _, _) = tokio::join!(wait, drain_out, drain_err);
+		code
+	}
+
+	pub async fn kill(&self, signal: i32) -> Result<()> {
+		self.client
+			.kill(self.id, signal)
+			.await?
+			.map_err(|e| anyhow!("agent kill failed: {e}"))
+	}
+}
+
+fn needs_socket(m: StdioMode) -> bool {
+	matches!(m, StdioMode::Pipe | StdioMode::Inherit)
+}
+
+fn stderr_needs_socket(m: StderrMode) -> bool {
+	matches!(m, StderrMode::Pipe | StderrMode::Inherit)
+}
+
+impl Remowt {
+	pub async fn spawn(&self, opts: SpawnOptions) -> Result<RemowtChild> {
+		let SpawnOptions {
+			program,
+			args,
+			env,
+			env_clear,
+			cwd,
+			escalated,
+			stdin,
+			stdout,
+			stderr,
+		} = opts;
+
+		if matches!(stderr, StderrMode::MergeWithStdout) && !needs_socket(stdout) {
+			bail!("stderr=MergeWithStdout requires stdout=Pipe or Inherit");
+		}
+
+		let stdin_bound = if needs_socket(stdin) {
+			Some(self.bind_fast_tunnel("proc-stdin", escalated).await?)
+		} else {
+			None
+		};
+		let stdout_bound = if needs_socket(stdout) {
+			Some(self.bind_fast_tunnel("proc-stdout", escalated).await?)
+		} else {
+			None
+		};
+		let stderr_bound = if stderr_needs_socket(stderr) {
+			Some(self.bind_fast_tunnel("proc-stderr", escalated).await?)
+		} else {
+			None
+		};
+
+		let stdin_spec = match &stdin_bound {
+			Some((_, t)) => StdioSpec::Tunnel(t.clone()),
+			None => StdioSpec::Null,
+		};
+		let stdout_spec = match &stdout_bound {
+			Some((_, t)) => StdioSpec::Tunnel(t.clone()),
+			None => StdioSpec::Null,
+		};
+		let stderr_spec = match (&stderr, &stderr_bound) {
+			(StderrMode::Pipe | StderrMode::Inherit, Some((_, t))) => StderrSpec::Tunnel(t.clone()),
+			(StderrMode::MergeWithStdout, _) => StderrSpec::MergeWithStdout,
+			_ => StderrSpec::Null,
+		};
+
+		let client: SubprocessClient<BifConfig> = if escalated {
+			// Boxed to break the async-fn type cycle
+			Box::pin(self.run0_endpoints::<SubprocessClient<BifConfig>>()).await?
+		} else {
+			self.endpoints()
+		};
+
+		let spec = SpawnSpec {
+			program: program.clone(),
+			args,
+			env,
+			env_clear,
+			cwd,
+			stdin: stdin_spec,
+			stdout: stdout_spec,
+			stderr: stderr_spec,
+		};
+		let id = client
+			.spawn(spec)
+			.await?
+			.map_err(|e| anyhow!("agent spawn failed: {e}"))?;
+
+		let (stdin_res, stdout_res, stderr_res) = tokio::join!(
+			accept(stdin_bound),
+			accept(stdout_bound),
+			accept(stderr_bound),
+		);
+
+		let stdin_stream = handle_stdin(stdin, stdin_res?, &program);
+		let stdout_stream = handle_output(stdout, stdout_res?, &program);
+		let stderr_stream = handle_output_err(stderr, stderr_res?, &program);
+
+		Ok(RemowtChild {
+			stdin: stdin_stream,
+			stdout: stdout_stream,
+			stderr: stderr_stream,
+			id,
+			client,
+		})
+	}
+
+	pub fn cmd(&self, program: impl AsRef<str>) -> RemowtCommand {
+		let program = program.as_ref().to_owned();
+		RemowtCommand {
+			program,
+			args: vec![],
+			env: vec![],
+			remowt: self.clone(),
+			escalated: false,
+		}
+	}
+}
+
+async fn accept(b: Option<(RemowtListener, TunnelAddr)>) -> Result<Option<RemowtStream>> {
+	match b {
+		Some((l, _)) => Ok(Some(l.accept().await?)),
+		None => Ok(None),
+	}
+}
+
+fn handle_stdin(mode: StdioMode, s: Option<RemowtStream>, program: &str) -> Option<RemowtStream> {
+	match mode {
+		StdioMode::Pipe => s,
+		StdioMode::Inherit => {
+			if let Some(s) = s {
+				let program = program.to_owned();
+				tokio::spawn(async move {
+					let mut stdin = tokio::io::stdin();
+					let mut s = s;
+					if let Err(e) = tokio::io::copy(&mut stdin, &mut s).await {
+						warn!(program, "stdin forward ended: {e}");
+					}
+					let _ = s.shutdown().await;
+				});
+			}
+			None
+		}
+		StdioMode::Null => None,
+	}
+}
+
+fn handle_output(mode: StdioMode, s: Option<RemowtStream>, program: &str) -> Option<RemowtStream> {
+	match mode {
+		StdioMode::Pipe => s,
+		StdioMode::Inherit => {
+			if let Some(s) = s {
+				let program = program.to_owned();
+				tokio::spawn(drain_to_tracing(s, program, false));
+			}
+			None
+		}
+		StdioMode::Null => None,
+	}
+}
+
+fn handle_output_err(
+	mode: StderrMode,
+	s: Option<RemowtStream>,
+	program: &str,
+) -> Option<RemowtStream> {
+	match mode {
+		StderrMode::Pipe => s,
+		StderrMode::Inherit => {
+			if let Some(s) = s {
+				let program = program.to_owned();
+				tokio::spawn(drain_to_tracing(s, program, true));
+			}
+			None
+		}
+		StderrMode::MergeWithStdout | StderrMode::Null => None,
+	}
+}
+
+fn escape_bash(input: &str, out: &mut String) {
+	const TO_ESCAPE: &str = "$ !\"#&'()*,;<>?[\\]^`{|}";
+	if input.chars().all(|c| !TO_ESCAPE.contains(c)) {
+		out.push_str(input);
+		return;
+	}
+	out.push('\'');
+	for (i, v) in input.split('\'').enumerate() {
+		if i != 0 {
+			out.push_str("'\"'\"'");
+		}
+		out.push_str(v);
+	}
+	out.push('\'');
+}
+
+#[derive(Clone)]
+pub struct RemowtCommand {
+	program: String,
+	args: Vec<String>,
+	env: Vec<(String, String)>,
+	remowt: Remowt,
+	escalated: bool,
+}
+
+impl RemowtCommand {
+	pub fn arg(&mut self, arg: impl AsRef<str>) -> &mut Self {
+		self.args.push(arg.as_ref().to_owned());
+		self
+	}
+	pub fn args<V: AsRef<str>>(&mut self, args: impl IntoIterator<Item = V>) -> &mut Self {
+		for arg in args {
+			self.args.push(arg.as_ref().to_owned());
+		}
+		self
+	}
+	pub fn eqarg(&mut self, key: impl AsRef<str>, value: impl AsRef<str>) -> &mut Self {
+		self.args
+			.push(format!("{}={}", key.as_ref(), value.as_ref()));
+		self
+	}
+	pub fn comparg(&mut self, key: impl AsRef<str>, value: impl AsRef<str>) -> &mut Self {
+		self.args.push(key.as_ref().to_owned());
+		self.args.push(value.as_ref().to_owned());
+		self
+	}
+	pub fn env(&mut self, name: impl AsRef<str>, value: impl AsRef<str>) -> &mut Self {
+		self.env
+			.push((name.as_ref().to_owned(), value.as_ref().to_owned()));
+		self
+	}
+
+	pub fn sudo(mut self) -> Self {
+		self.escalated = true;
+		self
+	}
+
+	/// Only for display.
+	fn shell_line(&self) -> String {
+		let mut out = String::new();
+		if self.escalated {
+			out.push_str("run0 ");
+		}
+		if !self.env.is_empty() {
+			out.push_str("env");
+			for (k, v) in &self.env {
+				out.push(' ');
+				assert!(!k.contains('='));
+				escape_bash(k, &mut out);
+				out.push('=');
+				escape_bash(v, &mut out);
+			}
+			out.push(' ');
+		}
+		escape_bash(&self.program, &mut out);
+		for arg in &self.args {
+			out.push(' ');
+			escape_bash(arg, &mut out);
+		}
+		out
+	}
+
+	fn into_spawn_options(self) -> (Remowt, SpawnOptions, String) {
+		let line = self.shell_line();
+		let opts = SpawnOptions {
+			program: self.program,
+			args: self.args,
+			env: self.env,
+			env_clear: false,
+			cwd: None,
+			escalated: self.escalated,
+			stdin: StdioMode::Null,
+			stdout: StdioMode::Pipe,
+			stderr: StderrMode::Pipe,
+		};
+		(self.remowt, opts, line)
+	}
+
+	pub async fn run(self) -> Result<()> {
+		run_inner(self, false).await.map(|_| ())
+	}
+	pub async fn run_string(self) -> Result<String> {
+		let bytes = run_inner(self, true).await?.expect("want_stdout");
+		Ok(String::from_utf8(bytes)?)
+	}
+	pub async fn run_value<T: DeserializeOwned>(self) -> Result<T> {
+		let s = self.run_string().await?;
+		Ok(serde_json::from_str(&s)?)
+	}
+}
+
+async fn run_inner(cmd: RemowtCommand, want_stdout: bool) -> Result<Option<Vec<u8>>> {
+	let (remowt, opts, line) = cmd.into_spawn_options();
+	debug!("running command {line:?} over remowt");
+	let program = opts.program.clone();
+	let mut child = remowt.spawn(opts).await?;
+	let stderr = child.stderr.take().expect("stderr=Pipe");
+	let stdout = child.stdout.take().expect("stdout=Pipe");
+
+	let mut err = FramedRead::new(stderr, LinesCodec::new());
+	let (mut out_bytes, mut out_lines) = if want_stdout {
+		(Some(FramedRead::new(stdout, BytesCodec::new())), None)
+	} else {
+		(None, Some(FramedRead::new(stdout, LinesCodec::new())))
+	};
+
+	let mut buf = if want_stdout { Some(Vec::new()) } else { None };
+
+	let mut wait = pin!(child.wait());
+	let exit = loop {
+		select! {
+			biased;
+
+			Some(e) = err.next() => {
+				let e = e?;
+				warn!(program = %program, "{e}");
+			}
+			Some(o) = async { out_bytes.as_mut()?.next().await }, if want_stdout => {
+				buf.as_mut().expect("want_stdout").extend_from_slice(&o?);
+			}
+			Some(o) = async { out_lines.as_mut()?.next().await }, if !want_stdout => {
+				let o = o?;
+				info!(program = %program, "{o}");
+			}
+			res = &mut wait => {
+				break res?;
+			}
+		}
+	};
+
+	while let Some(e) = err.next().await {
+		if let Ok(line) = e {
+			warn!(program = %program, "{line}");
+		}
+	}
+	if want_stdout {
+		if let Some(out_bytes) = out_bytes.as_mut() {
+			while let Some(o) = out_bytes.next().await {
+				if let Ok(chunk) = o {
+					buf.as_mut().expect("want_stdout").extend_from_slice(&chunk);
+				}
+			}
+		}
+	} else if let Some(out_lines) = out_lines.as_mut() {
+		while let Some(o) = out_lines.next().await {
+			if let Ok(line) = o {
+				info!(program = %program, "{line}");
+			}
+		}
+	}
+
+	match exit {
+		Some(0) => Ok(buf),
+		Some(c) => bail!("command '{line}' failed with status {c}"),
+		None => Err(anyhow!("command '{line}' ended without an exit status")),
+	}
+}
addedremowt/crates/remowt-endpoints/Cargo.tomldiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-endpoints/Cargo.toml
@@ -0,0 +1,25 @@
+[package]
+name = "remowt-endpoints"
+description = "Nix daemon proxy"
+version.workspace = true
+edition = "2021"
+license.workspace = true
+
+[dependencies]
+bifrostlink.workspace = true
+camino.workspace = true
+serde = { workspace = true }
+tempfile.workspace = true
+thiserror.workspace = true
+tokio = { workspace = true, features = [
+	"net",
+	"io-util",
+	"rt",
+	"process",
+	"io-std",
+] }
+tracing.workspace = true
+nix = { workspace = true, features = ["process", "signal", "term"] }
+zbus.workspace = true
+remowt-link-shared.workspace = true
+iroh.workspace = true
addedremowt/crates/remowt-endpoints/src/forward.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-endpoints/src/forward.rs
@@ -0,0 +1,117 @@
+use std::collections::HashMap;
+use std::net::SocketAddr;
+use std::sync::atomic::{AtomicU64, Ordering};
+use std::sync::{Arc, Mutex};
+
+use bifrostlink::declarative::endpoints;
+use bifrostlink::Config;
+use remowt_link_shared::iroh_tunnel::{TunnelAddr, TunnelDialer};
+use serde::{Deserialize, Serialize};
+use std::result::Result;
+use tokio::net::{TcpStream, UdpSocket};
+use tracing::warn;
+
+#[derive(Serialize, Deserialize, Debug, thiserror::Error)]
+pub enum Error {
+	#[error("tunnel unavailable: {0}")]
+	Tunnel(String),
+	#[error("connect to {0} failed: {1}")]
+	Connect(String, String),
+	#[error("invalid target address {0:?}")]
+	BadAddr(String),
+	#[error("udp forward requires the iroh fast path, which is not established")]
+	NoIroh,
+}
+
+#[derive(Clone)]
+pub struct Forward {
+	dialer: Arc<TunnelDialer>,
+	next_session: Arc<AtomicU64>,
+}
+
+impl Forward {
+	pub fn new(dialer: Arc<TunnelDialer>) -> Self {
+		Self {
+			dialer,
+			next_session: Arc::new(AtomicU64::new(0)),
+		}
+	}
+}
+
+#[endpoints(ns = 12)]
+impl Forward {
+	#[endpoints(id = 1)]
+	async fn connect_tcp(&self, tunnel: TunnelAddr, addr: String) -> Result<(), Error> {
+		let stream = self
+			.dialer
+			.connect_tunnel(&tunnel)
+			.await
+			.map_err(|e| Error::Tunnel(e.to_string()))?;
+		let tcp = TcpStream::connect(&addr)
+			.await
+			.map_err(|e| Error::Connect(addr, e.to_string()))?;
+		tokio::spawn(async move {
+			let mut stream = stream;
+			let mut tcp = tcp;
+			let _ = tokio::io::copy_bidirectional(&mut stream, &mut tcp).await;
+		});
+		Ok(())
+	}
+
+	#[endpoints(id = 2)]
+	async fn open_udp(&self, addr: String) -> Result<u64, Error> {
+		let target: SocketAddr = addr.parse().map_err(|_| Error::BadAddr(addr.clone()))?;
+		let router = self.dialer.router().ok_or(Error::NoIroh)?;
+		let session = self.next_session.fetch_add(1, Ordering::Relaxed);
+		let mut rx = router.register(session);
+
+		let sockets: Arc<Mutex<HashMap<u64, Arc<UdpSocket>>>> =
+			Arc::new(Mutex::new(HashMap::new()));
+		tokio::spawn(async move {
+			while let Some((sub, payload)) = rx.recv().await {
+				let existing = sockets.lock().expect("lock").get(&sub).cloned();
+				let sock = match existing {
+					Some(s) => s,
+					None => {
+						let sock = match UdpSocket::bind(unspecified_for(&target)).await {
+							Ok(s) => s,
+							Err(e) => {
+								warn!("udp forward: bind failed: {e}");
+								continue;
+							}
+						};
+						if let Err(e) = sock.connect(target).await {
+							warn!("udp forward: connect {target} failed: {e}");
+							continue;
+						}
+						let sock = Arc::new(sock);
+						sockets.lock().expect("lock").insert(sub, sock.clone());
+						// Reply reader: datagrams from the target go back on (session, sub).
+						let router = router.clone();
+						let reply_sock = sock.clone();
+						tokio::spawn(async move {
+							let mut buf = vec![0u8; 65535];
+							while let Ok(n) = reply_sock.recv(&mut buf).await {
+								if router.send(session, sub, &buf[..n]).is_err() {
+									break;
+								}
+							}
+						});
+						sock
+					}
+				};
+				let _ = sock.send(&payload).await;
+			}
+			router.unregister(session);
+		});
+
+		Ok(session)
+	}
+}
+
+fn unspecified_for(target: &SocketAddr) -> SocketAddr {
+	match target {
+		SocketAddr::V4(_) => SocketAddr::from(([0, 0, 0, 0], 0)),
+		SocketAddr::V6(_) => SocketAddr::from(([0u16; 8], 0)),
+	}
+}
addedremowt/crates/remowt-endpoints/src/fs.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-endpoints/src/fs.rs
@@ -0,0 +1,105 @@
+use std::io::ErrorKind;
+use std::str::FromStr;
+use std::sync::Mutex;
+
+use bifrostlink::declarative::endpoints;
+use bifrostlink::Config;
+use camino::Utf8PathBuf;
+use serde::{Deserialize, Serialize};
+use tempfile::TempDir;
+
+#[derive(Default)]
+pub struct Fs {
+	tempdirs: Mutex<Vec<TempDir>>,
+}
+
+impl Fs {
+	pub fn new() -> Self {
+		Self::default()
+	}
+}
+
+#[derive(Serialize, Deserialize, Debug, thiserror::Error)]
+pub enum Error {
+	#[error("file not found")]
+	NotFound,
+	#[error("file name/contents is not utf8")]
+	InvalidUtf8,
+	#[error("unknown fs error")]
+	Unknown,
+}
+
+#[endpoints(ns = 1)]
+impl Fs {
+	#[endpoints(id = 1)]
+	async fn read_file_tiny(&self, path: Utf8PathBuf) -> Result<Vec<u8>, Error> {
+		match tokio::fs::read(path).await {
+			Ok(v) => Ok(v),
+			Err(e) if e.kind() == ErrorKind::NotFound => Err(Error::NotFound),
+			_ => Err(Error::Unknown),
+		}
+	}
+	#[endpoints(id = 2)]
+	async fn file_exists(&self, path: Utf8PathBuf) -> bool {
+		tokio::fs::try_exists(path).await.unwrap_or(false)
+	}
+	#[endpoints(id = 3)]
+	async fn read_dir_raw(&self, path: Utf8PathBuf) -> Result<Vec<Utf8PathBuf>, Error> {
+		let mut dir = match tokio::fs::read_dir(path).await {
+			Ok(dir) => dir,
+			Err(e) if e.kind() == ErrorKind::NotFound => return Err(Error::NotFound),
+			Err(_) => return Err(Error::Unknown),
+		};
+		let mut out = Vec::new();
+		while let Ok(Some(entry)) = dir.next_entry().await {
+			let name = Utf8PathBuf::try_from(entry.file_name()).map_err(|_| Error::InvalidUtf8)?;
+			out.push(name);
+		}
+		Ok(out)
+	}
+	#[endpoints(id = 4)]
+	async fn mktemp_dir_raw(&self) -> Result<Utf8PathBuf, Error> {
+		let dir = tempfile::Builder::new()
+			.prefix("remowt.")
+			.tempdir()
+			.map_err(|_| Error::Unknown)?;
+		let mut tempdirs = self.tempdirs.lock().expect("not poisoned");
+		let path = Utf8PathBuf::try_from(dir.path().to_owned()).map_err(|_| Error::InvalidUtf8);
+		tempdirs.push(dir);
+		path
+	}
+	#[endpoints(id = 5)]
+	async fn rm_file(&self, path: Utf8PathBuf) -> Result<(), Error> {
+		match tokio::fs::remove_file(path).await {
+			Ok(()) => Ok(()),
+			Err(e) if e.kind() == ErrorKind::NotFound => Ok(()),
+			Err(_) => Err(Error::Unknown),
+		}
+	}
+}
+
+impl<C: Config> FsClient<C> {
+	pub async fn read_file_text(&self, path: impl Into<Utf8PathBuf>) -> Result<String, Error> {
+		let v = self
+			.read_file_tiny(path.into())
+			.await
+			.map_err(|_| Error::Unknown)?;
+		let v = v?;
+		String::from_utf8(v).map_err(|_| Error::InvalidUtf8)
+	}
+	pub async fn read_file_value<T: FromStr>(
+		&self,
+		path: impl Into<Utf8PathBuf>,
+	) -> Result<Result<T, T::Err>, Error> {
+		let text = self.read_file_text(path).await?;
+		Ok(T::from_str(&text))
+	}
+	pub async fn mktemp_dir(&self) -> Result<Utf8PathBuf, Error> {
+		self.mktemp_dir_raw().await.map_err(|_| Error::Unknown)?
+	}
+	pub async fn read_dir(&self, path: impl Into<Utf8PathBuf>) -> Result<Vec<Utf8PathBuf>, Error> {
+		self.read_dir_raw(path.into())
+			.await
+			.map_err(|_| Error::Unknown)?
+	}
+}
addedremowt/crates/remowt-endpoints/src/iroh_tunnel.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-endpoints/src/iroh_tunnel.rs
@@ -0,0 +1,85 @@
+use std::sync::{Arc, Mutex};
+
+use bifrostlink::declarative::endpoints;
+use bifrostlink::Config;
+use camino::Utf8PathBuf;
+use iroh::{Endpoint, EndpointId, SecretKey};
+use remowt_link_shared::iroh_tunnel::{build_endpoint, TunnelDialer};
+use serde::{Deserialize, Serialize};
+use std::result::Result;
+use tokio::net::UnixStream;
+use tracing::{debug, warn};
+
+#[derive(Serialize, Deserialize, Debug, thiserror::Error)]
+pub enum Error {
+	#[error("iroh transport pipe unavailable: {0}")]
+	Pipe(String),
+	#[error("iroh endpoint failed: {0}")]
+	Iroh(String),
+}
+
+#[derive(Clone)]
+pub struct IrohTunnel {
+	dialer: Arc<TunnelDialer>,
+	endpoint: Arc<Mutex<Option<Endpoint>>>,
+}
+
+impl IrohTunnel {
+	pub fn new(dialer: Arc<TunnelDialer>) -> Self {
+		Self {
+			dialer,
+			endpoint: Arc::new(Mutex::new(None)),
+		}
+	}
+}
+
+#[endpoints(ns = 11)]
+impl IrohTunnel {
+	#[endpoints(id = 1)]
+	async fn setup(
+		&self,
+		client_id: EndpointId,
+		xport_socket: Utf8PathBuf,
+	) -> Result<EndpointId, Error> {
+		let stream = UnixStream::connect(&xport_socket)
+			.await
+			.map_err(|e| Error::Pipe(e.to_string()))?;
+
+		let secret = SecretKey::generate();
+		let agent_id = secret.public();
+		let ep = build_endpoint(secret, stream, client_id, true)
+			.await
+			.map_err(|e| Error::Iroh(e.to_string()))?;
+
+		let dialer = self.dialer.clone();
+		let accept_ep = ep.clone();
+		tokio::spawn(async move {
+			while let Some(incoming) = accept_ep.accept().await {
+				let dialer = dialer.clone();
+				match incoming.accept() {
+					Ok(accepting) => {
+						tokio::spawn(async move {
+							match accepting.await {
+								Ok(conn) => {
+									if conn.remote_id() != client_id {
+										warn!("iroh: rejecting connection from unexpected peer");
+										conn.close(0u32.into(), b"unexpected peer");
+										return;
+									}
+									debug!("iroh tunnel connection accepted");
+									dialer.set_conn(conn);
+								}
+								Err(e) => warn!("iroh accept failed: {e}"),
+							}
+						});
+					}
+					Err(e) => warn!("iroh incoming rejected: {e}"),
+				}
+			}
+		});
+
+		*self.endpoint.lock().expect("not poisoned") = Some(ep);
+
+		Ok(agent_id)
+	}
+}
addedremowt/crates/remowt-endpoints/src/lib.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-endpoints/src/lib.rs
@@ -0,0 +1,7 @@
+pub mod forward;
+pub mod fs;
+pub mod iroh_tunnel;
+pub mod nix_daemon;
+pub mod pty;
+pub mod subprocess;
+pub mod systemd;
addedremowt/crates/remowt-endpoints/src/nix_daemon.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-endpoints/src/nix_daemon.rs
@@ -0,0 +1,59 @@
+use std::process::Stdio;
+use std::sync::Arc;
+
+use bifrostlink::declarative::endpoints;
+use bifrostlink::Config;
+use remowt_link_shared::iroh_tunnel::{TunnelAddr, TunnelDialer};
+use serde::{Deserialize, Serialize};
+use std::result::Result;
+use tokio::process::Command;
+
+#[derive(Clone)]
+pub struct NixDaemon {
+	dialer: Arc<TunnelDialer>,
+}
+
+impl NixDaemon {
+	pub fn new(dialer: Arc<TunnelDialer>) -> Self {
+		Self { dialer }
+	}
+}
+
+#[derive(Serialize, Deserialize, Debug, thiserror::Error)]
+pub enum Error {
+	#[error("nix daemon unavailable: {0}")]
+	DaemonUnavailable(String),
+	#[error("tunnel socket unavailable: {0}")]
+	Tunnel(String),
+}
+
+#[endpoints(ns = 4)]
+impl NixDaemon {
+	#[endpoints(id = 2)]
+	async fn serve_store(&self, store: String, tunnel: TunnelAddr) -> Result<(), Error> {
+		let mut child = Command::new("nix-daemon")
+			.arg("--stdio")
+			.arg("--store")
+			.arg(&store)
+			.stdin(Stdio::piped())
+			.stdout(Stdio::piped())
+			.spawn()
+			.map_err(|e| Error::DaemonUnavailable(e.to_string()))?;
+		let tunnel = self
+			.dialer
+			.connect_tunnel(&tunnel)
+			.await
+			.map_err(|e| Error::Tunnel(e.to_string()))?;
+		let mut stdin = child.stdin.take().expect("piped");
+		let mut stdout = child.stdout.take().expect("piped");
+		tokio::spawn(async move {
+			let (mut tr, mut tw) = tokio::io::split(tunnel);
+			let _ = tokio::join!(
+				tokio::io::copy(&mut tr, &mut stdin),
+				tokio::io::copy(&mut stdout, &mut tw),
+			);
+			let _ = child.wait().await;
+		});
+		Ok(())
+	}
+}
addedremowt/crates/remowt-endpoints/src/pty.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-endpoints/src/pty.rs
@@ -0,0 +1,260 @@
+use std::collections::HashMap;
+use std::io;
+use std::os::fd::{AsRawFd, OwnedFd};
+use std::pin::Pin;
+use std::process::Stdio;
+use std::sync::atomic::{AtomicU64, Ordering};
+use std::sync::{Arc, Mutex};
+use std::task::{Context, Poll};
+
+use bifrostlink::declarative::endpoints;
+use bifrostlink::Config;
+use nix::libc;
+use nix::pty::{openpty, OpenptyResult, Winsize};
+use remowt_link_shared::iroh_tunnel::{TunnelAddr, TunnelDialer};
+use serde::{Deserialize, Serialize};
+use tokio::io::unix::AsyncFd;
+use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
+use tracing::{debug, info, warn};
+
+pub type ShellId = u64;
+
+#[derive(Serialize, Deserialize, Debug, thiserror::Error)]
+pub enum Error {
+	#[error("openpty failed: {0}")]
+	Open(String),
+	#[error("failed to spawn shell: {0}")]
+	Spawn(String),
+	#[error("failed to connect to forwarded socket: {0}")]
+	Connect(String),
+	#[error("no shell with that id")]
+	NoSuchShell,
+	#[error("resize failed: {0}")]
+	Resize(String),
+	#[error("io error: {0}")]
+	Io(String),
+}
+
+impl From<io::Error> for Error {
+	fn from(e: io::Error) -> Self {
+		Error::Io(e.to_string())
+	}
+}
+
+#[derive(Clone)]
+pub struct Pty {
+	shells: Arc<Mutex<HashMap<ShellId, OwnedFd>>>,
+	next_id: Arc<AtomicU64>,
+	dialer: Arc<TunnelDialer>,
+}
+
+impl Pty {
+	pub fn new(dialer: Arc<TunnelDialer>) -> Self {
+		Self {
+			shells: Default::default(),
+			next_id: Default::default(),
+			dialer,
+		}
+	}
+}
+
+#[endpoints(ns = 7)]
+impl Pty {
+	#[endpoints(id = 1)]
+	async fn open_shell(
+		&self,
+		tunnel: TunnelAddr,
+		term: String,
+		cols: u16,
+		rows: u16,
+	) -> Result<ShellId, Error> {
+		let ws = Winsize {
+			ws_row: rows,
+			ws_col: cols,
+			ws_xpixel: 0,
+			ws_ypixel: 0,
+		};
+		let OpenptyResult { master, slave } =
+			openpty(Some(&ws), None).map_err(|e| Error::Open(e.to_string()))?;
+
+		let shell = std::env::var("SHELL").unwrap_or_else(|_| "/bin/sh".to_owned());
+
+		let slave_in = slave.try_clone()?;
+		let slave_out = slave.try_clone()?;
+		let slave_err = slave;
+
+		let mut cmd = tokio::process::Command::new(&shell);
+		cmd.env("TERM", &term);
+		if let Ok(home) = std::env::var("HOME") {
+			cmd.current_dir(home);
+		}
+		cmd.stdin(Stdio::from(slave_in));
+		cmd.stdout(Stdio::from(slave_out));
+		cmd.stderr(Stdio::from(slave_err));
+		// SAFETY: only async-signal-safe calls (setsid, ioctl) before exec.
+		unsafe {
+			cmd.pre_exec(|| {
+				nix::unistd::setsid().map_err(|e| io::Error::from_raw_os_error(e as i32))?;
+				if libc::ioctl(0, libc::TIOCSCTTY as _, 0) < 0 {
+					return Err(io::Error::last_os_error());
+				}
+				Ok(())
+			});
+		}
+
+		let mut child = cmd.spawn().map_err(|e| Error::Spawn(e.to_string()))?;
+
+		let resize_fd = master.try_clone()?;
+		let id = self.next_id.fetch_add(1, Ordering::Relaxed);
+		self.shells
+			.lock()
+			.expect("not poisoned")
+			.insert(id, resize_fd);
+
+		let sock = match self.dialer.connect_tunnel(&tunnel).await {
+			Ok(s) => s,
+			Err(e) => {
+				self.shells.lock().expect("not poisoned").remove(&id);
+				let _ = child.kill().await;
+				return Err(Error::Connect(e.to_string()));
+			}
+		};
+		let pty = AsyncPty::new(master)?;
+
+		debug!(id, shell, "shell opened");
+		let shells = self.shells.clone();
+		tokio::spawn(async move {
+			let mut pty = pty;
+			let mut sock = sock;
+			if let Err(e) = tokio::io::copy_bidirectional(&mut pty, &mut sock).await {
+				warn!(id, "shell pump ended: {e}");
+			}
+			let _ = child.kill().await;
+			shells.lock().expect("not poisoned").remove(&id);
+			info!(id, "shell closed");
+		});
+
+		Ok(id)
+	}
+
+	#[endpoints(id = 2)]
+	async fn resize(&self, id: ShellId, cols: u16, rows: u16) -> Result<(), Error> {
+		let ws = libc::winsize {
+			ws_row: rows,
+			ws_col: cols,
+			ws_xpixel: 0,
+			ws_ypixel: 0,
+		};
+		let shells = self.shells.lock().expect("not poisoned");
+		let fd = shells.get(&id).ok_or(Error::NoSuchShell)?;
+		// SAFETY: `fd` is a live PTY master
+		let rc = unsafe { libc::ioctl(fd.as_raw_fd(), libc::TIOCSWINSZ as _, &ws) };
+		if rc < 0 {
+			return Err(Error::Resize(io::Error::last_os_error().to_string()));
+		}
+		Ok(())
+	}
+}
+
+struct AsyncPty {
+	fd: AsyncFd<OwnedFd>,
+}
+
+impl AsyncPty {
+	fn new(fd: OwnedFd) -> io::Result<Self> {
+		let raw = fd.as_raw_fd();
+		// SAFETY: standard F_GETFL/F_SETFL round-trip on a valid fd.
+		unsafe {
+			let flags = libc::fcntl(raw, libc::F_GETFL);
+			if flags < 0 {
+				return Err(io::Error::last_os_error());
+			}
+			if libc::fcntl(raw, libc::F_SETFL, flags | libc::O_NONBLOCK) < 0 {
+				return Err(io::Error::last_os_error());
+			}
+		}
+		Ok(Self {
+			fd: AsyncFd::new(fd)?,
+		})
+	}
+}
+
+impl AsyncRead for AsyncPty {
+	fn poll_read(
+		self: Pin<&mut Self>,
+		cx: &mut Context<'_>,
+		buf: &mut ReadBuf<'_>,
+	) -> Poll<io::Result<()>> {
+		let this = self.get_mut();
+		loop {
+			let mut guard = match this.fd.poll_read_ready(cx) {
+				Poll::Ready(Ok(g)) => g,
+				Poll::Ready(Err(e)) => return Poll::Ready(Err(e)),
+				Poll::Pending => return Poll::Pending,
+			};
+			let unfilled = buf.initialize_unfilled();
+			let res = guard.try_io(|inner| {
+				let fd = inner.get_ref().as_raw_fd();
+				// SAFETY: writing into `unfilled`'s own backing storage.
+				let n = unsafe { libc::read(fd, unfilled.as_mut_ptr().cast(), unfilled.len()) };
+				if n < 0 {
+					let err = io::Error::last_os_error();
+					if err.raw_os_error() == Some(libc::EIO) {
+						Ok(0)
+					} else {
+						Err(err)
+					}
+				} else {
+					Ok(n as usize)
+				}
+			});
+			match res {
+				Ok(Ok(n)) => {
+					buf.advance(n);
+					return Poll::Ready(Ok(()));
+				}
+				Ok(Err(e)) => return Poll::Ready(Err(e)),
+				Err(_would_block) => continue,
+			}
+		}
+	}
+}
+
+impl AsyncWrite for AsyncPty {
+	fn poll_write(
+		self: Pin<&mut Self>,
+		cx: &mut Context<'_>,
+		buf: &[u8],
+	) -> Poll<io::Result<usize>> {
+		let this = self.get_mut();
+		loop {
+			let mut guard = match this.fd.poll_write_ready(cx) {
+				Poll::Ready(Ok(g)) => g,
+				Poll::Ready(Err(e)) => return Poll::Ready(Err(e)),
+				Poll::Pending => return Poll::Pending,
+			};
+			let res = guard.try_io(|inner| {
+				let fd = inner.get_ref().as_raw_fd();
+				// SAFETY: reading from `buf` for `buf.len()` bytes.
+				let n = unsafe { libc::write(fd, buf.as_ptr().cast(), buf.len()) };
+				if n < 0 {
+					Err(io::Error::last_os_error())
+				} else {
+					Ok(n as usize)
+				}
+			});
+			match res {
+				Ok(r) => return Poll::Ready(r),
+				Err(_would_block) => continue,
+			}
+		}
+	}
+
+	fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
+		Poll::Ready(Ok(()))
+	}
+
+	fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
+		Poll::Ready(Ok(()))
+	}
+}
addedremowt/crates/remowt-endpoints/src/subprocess.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-endpoints/src/subprocess.rs
@@ -0,0 +1,293 @@
+use std::collections::HashMap;
+use std::io;
+use std::process::Stdio;
+use std::sync::atomic::{AtomicU64, Ordering};
+use std::sync::{Arc, Mutex};
+
+use bifrostlink::declarative::endpoints;
+use bifrostlink::Config;
+use camino::Utf8PathBuf;
+use nix::sys::signal::{self, Signal};
+use nix::unistd::Pid;
+use remowt_link_shared::iroh_tunnel::{TunnelAddr, TunnelDialer, TunnelStream};
+use serde::{Deserialize, Serialize};
+use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _};
+use tokio::process::{ChildStderr, ChildStdout, Command};
+use tokio::sync::{mpsc, watch};
+use tracing::{debug, warn};
+
+pub type ProcId = u64;
+
+#[derive(Serialize, Deserialize, Debug)]
+pub enum StdioSpec {
+	Null,
+	Tunnel(TunnelAddr),
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub enum StderrSpec {
+	Null,
+	Tunnel(TunnelAddr),
+	MergeWithStdout,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct SpawnSpec {
+	pub program: String,
+	pub args: Vec<String>,
+	pub env: Vec<(String, String)>,
+	pub env_clear: bool,
+	pub cwd: Option<Utf8PathBuf>,
+	pub stdin: StdioSpec,
+	pub stdout: StdioSpec,
+	pub stderr: StderrSpec,
+}
+
+#[derive(Serialize, Deserialize, Debug, thiserror::Error)]
+pub enum Error {
+	#[error("spawn failed: {0}")]
+	Spawn(String),
+	#[error("connect to forwarded socket failed: {0}")]
+	Connect(String),
+	#[error("no process with that id")]
+	NoSuchProcess,
+	#[error("MergeWithStdout requires stdout=Socket")]
+	BadMerge,
+	#[error("invalid signal: {0}")]
+	BadSignal(i32),
+	#[error("kill failed: {0}")]
+	Kill(String),
+	#[error("io error: {0}")]
+	Io(String),
+}
+
+impl From<io::Error> for Error {
+	fn from(e: io::Error) -> Self {
+		Error::Io(e.to_string())
+	}
+}
+
+struct ChildState {
+	pid: u32,
+	exit_rx: watch::Receiver<Option<Option<i32>>>,
+}
+
+#[derive(Clone)]
+pub struct Subprocess {
+	children: Arc<Mutex<HashMap<ProcId, ChildState>>>,
+	next_id: Arc<AtomicU64>,
+	dialer: Arc<TunnelDialer>,
+}
+
+impl Subprocess {
+	pub fn new(dialer: Arc<TunnelDialer>) -> Self {
+		Self {
+			children: Default::default(),
+			next_id: Default::default(),
+			dialer,
+		}
+	}
+}
+
+#[endpoints(ns = 10)]
+impl Subprocess {
+	#[endpoints(id = 1)]
+	async fn spawn(&self, spec: SpawnSpec) -> Result<ProcId, Error> {
+		let SpawnSpec {
+			program,
+			args,
+			env,
+			env_clear,
+			cwd,
+			stdin,
+			stdout,
+			stderr,
+		} = spec;
+
+		if matches!(stderr, StderrSpec::MergeWithStdout) && !matches!(stdout, StdioSpec::Tunnel(_))
+		{
+			return Err(Error::BadMerge);
+		}
+
+		let mut cmd = Command::new(&program);
+		cmd.args(&args);
+		if env_clear {
+			cmd.env_clear();
+		}
+		for (k, v) in &env {
+			cmd.env(k, v);
+		}
+		if let Some(cwd) = &cwd {
+			cmd.current_dir(cwd);
+		}
+		cmd.stdin(match &stdin {
+			StdioSpec::Tunnel(_) => Stdio::piped(),
+			StdioSpec::Null => Stdio::null(),
+		});
+		cmd.stdout(match &stdout {
+			StdioSpec::Tunnel(_) => Stdio::piped(),
+			StdioSpec::Null => Stdio::null(),
+		});
+		cmd.stderr(match &stderr {
+			StderrSpec::Tunnel(_) | StderrSpec::MergeWithStdout => Stdio::piped(),
+			StderrSpec::Null => Stdio::null(),
+		});
+		cmd.kill_on_drop(false);
+
+		let mut child = cmd.spawn().map_err(|e| Error::Spawn(e.to_string()))?;
+		let pid = child
+			.id()
+			.ok_or_else(|| Error::Spawn("child exited before pid available".to_owned()))?;
+
+		if let StdioSpec::Tunnel(addr) = &stdin {
+			let sock = self
+				.dialer
+				.connect_tunnel(addr)
+				.await
+				.map_err(|e| Error::Connect(e.to_string()))?;
+			let mut stdin_w = child.stdin.take().expect("piped");
+			tokio::spawn(async move {
+				let (mut sr, _) = tokio::io::split(sock);
+				let _ = tokio::io::copy(&mut sr, &mut stdin_w).await;
+				let _ = stdin_w.shutdown().await;
+			});
+		}
+
+		let stdout_handle = child.stdout.take();
+		let stderr_handle = child.stderr.take();
+
+		match (&stdout, &stderr, stdout_handle, stderr_handle) {
+			(StdioSpec::Tunnel(out_addr), StderrSpec::MergeWithStdout, Some(out), Some(err)) => {
+				let sock = self
+					.dialer
+					.connect_tunnel(out_addr)
+					.await
+					.map_err(|e| Error::Connect(e.to_string()))?;
+				tokio::spawn(merge_to_sock(out, err, sock));
+			}
+			(StdioSpec::Tunnel(out_addr), _, Some(out), err_opt) => {
+				let sock = self
+					.dialer
+					.connect_tunnel(out_addr)
+					.await
+					.map_err(|e| Error::Connect(e.to_string()))?;
+				tokio::spawn(pump_to_sock(out, sock));
+				if let (StderrSpec::Tunnel(err_addr), Some(err)) = (&stderr, err_opt) {
+					let err_sock = self
+						.dialer
+						.connect_tunnel(err_addr)
+						.await
+						.map_err(|e| Error::Connect(e.to_string()))?;
+					tokio::spawn(pump_to_sock(err, err_sock));
+				}
+			}
+			(StdioSpec::Null, StderrSpec::Tunnel(err_addr), _, Some(err)) => {
+				let sock = self
+					.dialer
+					.connect_tunnel(err_addr)
+					.await
+					.map_err(|e| Error::Connect(e.to_string()))?;
+				tokio::spawn(pump_to_sock(err, sock));
+			}
+			_ => {}
+		}
+
+		let (exit_tx, exit_rx) = watch::channel(None);
+		let id = self.next_id.fetch_add(1, Ordering::Relaxed);
+		self.children
+			.lock()
+			.expect("not poisoned")
+			.insert(id, ChildState { pid, exit_rx });
+
+		debug!(id, pid, program, "subprocess spawned");
+		tokio::spawn(async move {
+			let result = child.wait().await;
+			let code = match result {
+				Ok(status) => status.code(),
+				Err(e) => {
+					warn!(id, "child.wait failed: {e}");
+					None
+				}
+			};
+			let _ = exit_tx.send(Some(code));
+		});
+
+		Ok(id)
+	}
+
+	#[endpoints(id = 2)]
+	async fn wait(&self, id: ProcId) -> Result<Option<i32>, Error> {
+		let mut rx = {
+			let map = self.children.lock().expect("not poisoned");
+			let entry = map.get(&id).ok_or(Error::NoSuchProcess)?;
+			entry.exit_rx.clone()
+		};
+		rx.wait_for(|v| v.is_some())
+			.await
+			.map_err(|_| Error::Io("exit channel closed".to_owned()))?;
+		let code = rx.borrow().flatten();
+		self.children.lock().expect("not poisoned").remove(&id);
+		Ok(code)
+	}
+
+	#[endpoints(id = 3)]
+	async fn kill(&self, id: ProcId, signal: i32) -> Result<(), Error> {
+		let pid = {
+			let map = self.children.lock().expect("not poisoned");
+			let entry = map.get(&id).ok_or(Error::NoSuchProcess)?;
+			entry.pid
+		};
+		let sig = Signal::try_from(signal).map_err(|_| Error::BadSignal(signal))?;
+		signal::kill(Pid::from_raw(pid as i32), sig).map_err(|e| Error::Kill(e.to_string()))?;
+		Ok(())
+	}
+}
+
+async fn pump_to_sock<R>(mut from: R, sock: TunnelStream)
+where
+	R: tokio::io::AsyncRead + Unpin,
+{
+	let (_, mut sw) = tokio::io::split(sock);
+	let _ = tokio::io::copy(&mut from, &mut sw).await;
+	let _ = sw.shutdown().await;
+}
+
+async fn merge_to_sock(mut stdout: ChildStdout, mut stderr: ChildStderr, sock: TunnelStream) {
+	let (_, mut sw) = tokio::io::split(sock);
+	let (tx, mut rx) = mpsc::channel::<Vec<u8>>(64);
+	let tx_out = tx.clone();
+	let out_pump = tokio::spawn(async move {
+		let mut buf = vec![0u8; 4096];
+		loop {
+			match stdout.read(&mut buf).await {
+				Ok(0) | Err(_) => break,
+				Ok(n) => {
+					if tx_out.send(buf[..n].to_vec()).await.is_err() {
+						break;
+					}
+				}
+			}
+		}
+	});
+	let err_pump = tokio::spawn(async move {
+		let mut buf = vec![0u8; 4096];
+		loop {
+			match stderr.read(&mut buf).await {
+				Ok(0) | Err(_) => break,
+				Ok(n) => {
+					if tx.send(buf[..n].to_vec()).await.is_err() {
+						break;
+					}
+				}
+			}
+		}
+	});
+	while let Some(chunk) = rx.recv().await {
+		if sw.write_all(&chunk).await.is_err() {
+			break;
+		}
+	}
+	let _ = out_pump.await;
+	let _ = err_pump.await;
+	let _ = sw.shutdown().await;
+}
addedremowt/crates/remowt-endpoints/src/systemd.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-endpoints/src/systemd.rs
@@ -0,0 +1,54 @@
+use bifrostlink::declarative::endpoints;
+use bifrostlink::Config;
+use serde::{Deserialize, Serialize};
+use zbus::proxy;
+use zbus::zvariant::OwnedObjectPath;
+
+pub struct Systemd;
+
+#[derive(Serialize, Deserialize, Debug, thiserror::Error)]
+pub enum Error {
+	#[error("systemd request failed: {0}")]
+	Failed(String),
+}
+
+#[proxy(
+	interface = "org.freedesktop.systemd1.Manager",
+	default_service = "org.freedesktop.systemd1",
+	default_path = "/org/freedesktop/systemd1"
+)]
+trait Manager {
+	fn start_unit(&self, name: &str, mode: &str) -> zbus::Result<OwnedObjectPath>;
+	fn stop_unit(&self, name: &str, mode: &str) -> zbus::Result<OwnedObjectPath>;
+}
+
+async fn manager() -> Result<ManagerProxy<'static>, Error> {
+	let conn = zbus::Connection::system()
+		.await
+		.map_err(|e| Error::Failed(e.to_string()))?;
+	ManagerProxy::new(&conn)
+		.await
+		.map_err(|e| Error::Failed(e.to_string()))
+}
+
+#[endpoints(ns = 5)]
+impl Systemd {
+	#[endpoints(id = 1)]
+	async fn start(&self, unit: String) -> Result<(), Error> {
+		manager()
+			.await?
+			.start_unit(&unit, "replace")
+			.await
+			.map_err(|e| Error::Failed(e.to_string()))?;
+		Ok(())
+	}
+	#[endpoints(id = 2)]
+	async fn stop(&self, unit: String) -> Result<(), Error> {
+		manager()
+			.await?
+			.stop_unit(&unit, "replace")
+			.await
+			.map_err(|e| Error::Failed(e.to_string()))?;
+		Ok(())
+	}
+}
addedremowt/crates/remowt-link-shared/Cargo.tomldiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-link-shared/Cargo.toml
@@ -0,0 +1,25 @@
+[package]
+name = "remowt-link-shared"
+description = "Shared bifrostlink endpoint wiring for remowt"
+version.workspace = true
+edition = "2021"
+license.workspace = true
+
+[dependencies]
+anyhow.workspace = true
+bifrostlink.workspace = true
+bytes.workspace = true
+camino = { workspace = true }
+serde = { workspace = true, features = ["derive"] }
+serde_json.workspace = true
+thiserror.workspace = true
+tokio = { workspace = true, features = ["fs", "io-util", "macros", "net", "sync", "rt"] }
+tokio-util = { workspace = true, features = ["codec"] }
+tracing.workspace = true
+remowt-ui-prompt.workspace = true
+
+iroh.workspace = true
+iroh-base.workspace = true
+noq-udp.workspace = true
+n0-watcher.workspace = true
+futures.workspace = true
addedremowt/crates/remowt-link-shared/src/editor.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-link-shared/src/editor.rs
@@ -0,0 +1,45 @@
+use std::future::Future;
+
+use bifrostlink::declarative::endpoints;
+use bifrostlink::{Config, Rpc};
+use serde::{Deserialize, Serialize};
+
+#[derive(Serialize, Deserialize, Debug, thiserror::Error)]
+pub enum Error {
+	#[error("editor failed: {0}")]
+	Failed(String),
+}
+
+pub trait EditorBackend: Send + Sync {
+	fn open_editor(&self, socket_path: String) -> impl Future<Output = Result<(), Error>> + Send;
+	fn expose_tcp(&self, addr: String) -> impl Future<Output = Result<u16, Error>> + Send;
+	fn expose_udp(&self, addr: String) -> impl Future<Output = Result<u16, Error>> + Send;
+}
+
+pub struct EditorEndpoints<E>(pub E);
+
+#[endpoints(ns = 8)]
+impl<E: EditorBackend + 'static> EditorEndpoints<E> {
+	#[endpoints(id = 1)]
+	async fn open_editor(&self, socket_path: String) -> Result<(), Error> {
+		self.0.open_editor(socket_path).await
+	}
+
+	#[endpoints(id = 2)]
+	async fn expose_tcp(&self, addr: String) -> Result<u16, Error> {
+		self.0.expose_tcp(addr).await
+	}
+
+	#[endpoints(id = 3)]
+	async fn expose_udp(&self, addr: String) -> Result<u16, Error> {
+		self.0.expose_udp(addr).await
+	}
+}
+
+pub fn serve_editor<E, C>(rpc: &mut Rpc<C>, editor: E)
+where
+	E: EditorBackend + Send + Sync + 'static,
+	C: Config,
+{
+	EditorEndpoints(editor).register_endpoints(rpc);
+}
addedremowt/crates/remowt-link-shared/src/iroh_tunnel.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-link-shared/src/iroh_tunnel.rs
@@ -0,0 +1,536 @@
+use std::collections::HashMap;
+use std::pin::Pin;
+use std::sync::{Arc, Mutex};
+use std::task::{Context, Poll};
+use std::time::Duration;
+use std::{fmt, io};
+
+use anyhow::Result;
+use bytes::{Bytes, BytesMut};
+use camino::Utf8PathBuf;
+use futures::{SinkExt as _, Stream};
+use iroh::endpoint::transports::{
+	CustomEndpoint, CustomSender, CustomTransport, RecvInfo, Transmit,
+};
+use iroh::endpoint::{presets, Connection, RecvStream, SendStream};
+use iroh::{Endpoint, EndpointId, SecretKey};
+use iroh_base::CustomAddr;
+use serde::{Deserialize, Serialize};
+use tokio::io::{AsyncRead, AsyncWrite, ReadBuf, ReadHalf, WriteHalf};
+use tokio::net::UnixStream;
+use tokio::sync::{mpsc, watch};
+use tokio_util::codec::{FramedRead, FramedWrite, LengthDelimitedCodec};
+use tracing::{debug, warn};
+
+// "rmwtssh"
+pub const REMOWT_SSH_TRANSPORT_ID: u64 = 0x_72_6d_77_74_73_73_68;
+
+pub const REMOWT_ALPN: &[u8] = b"remowt/tunnel/0";
+
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub enum TunnelAddr {
+	Unix(Utf8PathBuf),
+	Iroh { token: u64 },
+}
+
+pub fn ssh_custom_addr(id: EndpointId) -> CustomAddr {
+	CustomAddr::from((REMOWT_SSH_TRANSPORT_ID, &id.as_bytes()[..]))
+}
+
+pub async fn build_endpoint<S>(
+	secret: SecretKey,
+	stream: S,
+	remote: EndpointId,
+	accept: bool,
+) -> Result<Endpoint>
+where
+	S: AsyncRead + AsyncWrite + Unpin + Send + Sync + 'static,
+{
+	let local = secret.public();
+	let transport = Arc::new(SshTransport::new(stream, local, remote));
+	let mut builder = Endpoint::builder(presets::N0)
+		.secret_key(secret)
+		.add_custom_transport(transport);
+	if accept {
+		builder = builder.alpns(vec![REMOWT_ALPN.to_vec()]);
+	}
+	Ok(builder.bind().await?)
+}
+
+struct SshTransport {
+	local: CustomAddr,
+	remote: CustomAddr,
+	addrs: n0_watcher::Watchable<Vec<CustomAddr>>,
+	endpoint: Mutex<Option<SshEndpointParts>>,
+	sender: Arc<SshSender>,
+}
+
+struct SshEndpointParts {
+	reader: Pin<Box<dyn FramedDatagrams>>,
+}
+
+trait FramedDatagrams: Stream<Item = io::Result<BytesMut>> + Send + Sync {}
+impl<T: Stream<Item = io::Result<BytesMut>> + Send + Sync> FramedDatagrams for T {}
+
+impl fmt::Debug for SshTransport {
+	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+		f.debug_struct("SshTransport").finish_non_exhaustive()
+	}
+}
+
+impl SshTransport {
+	fn new<S>(stream: S, local: EndpointId, remote: EndpointId) -> Self
+	where
+		S: AsyncRead + AsyncWrite + Unpin + Send + Sync + 'static,
+	{
+		let (read, write): (ReadHalf<S>, WriteHalf<S>) = tokio::io::split(stream);
+		let reader = FramedRead::new(read, LengthDelimitedCodec::new());
+
+		let (tx, rx) = mpsc::unbounded_channel::<Bytes>();
+		tokio::spawn(writer_task(rx, write));
+
+		let local = ssh_custom_addr(local);
+		Self {
+			addrs: n0_watcher::Watchable::new(vec![local.clone()]),
+			local,
+			remote: ssh_custom_addr(remote),
+			endpoint: Mutex::new(Some(SshEndpointParts {
+				reader: Box::pin(reader),
+			})),
+			sender: Arc::new(SshSender { tx }),
+		}
+	}
+}
+
+async fn writer_task<W: AsyncWrite + Unpin>(mut rx: mpsc::UnboundedReceiver<Bytes>, write: W) {
+	let mut framed = FramedWrite::new(write, LengthDelimitedCodec::new());
+	while let Some(datagram) = rx.recv().await {
+		if let Err(e) = framed.send(datagram).await {
+			debug!("ssh transport writer ended: {e}");
+			break;
+		}
+	}
+}
+
+impl CustomTransport for SshTransport {
+	fn bind(&self) -> io::Result<Box<dyn CustomEndpoint>> {
+		let parts = self
+			.endpoint
+			.lock()
+			.expect("not poisoned")
+			.take()
+			.ok_or_else(|| io::Error::other("ssh transport already bound"))?;
+		Ok(Box::new(SshEndpoint {
+			local: self.local.clone(),
+			remote: self.remote.clone(),
+			addrs: self.addrs.clone(),
+			sender: self.sender.clone(),
+			reader: parts.reader,
+		}))
+	}
+}
+
+struct SshEndpoint {
+	local: CustomAddr,
+	remote: CustomAddr,
+	addrs: n0_watcher::Watchable<Vec<CustomAddr>>,
+	sender: Arc<SshSender>,
+	reader: Pin<Box<dyn FramedDatagrams>>,
+}
+
+impl fmt::Debug for SshEndpoint {
+	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+		f.debug_struct("SshEndpoint").finish_non_exhaustive()
+	}
+}
+
+impl CustomEndpoint for SshEndpoint {
+	fn watch_local_addrs(&self) -> n0_watcher::Direct<Vec<CustomAddr>> {
+		self.addrs.watch()
+	}
+
+	fn create_sender(&self) -> Arc<dyn CustomSender> {
+		self.sender.clone()
+	}
+
+	fn poll_recv(
+		&mut self,
+		cx: &mut Context,
+		bufs: &mut [io::IoSliceMut<'_>],
+		metas: &mut [noq_udp::RecvMeta],
+		recv_infos: &mut [RecvInfo],
+	) -> Poll<io::Result<usize>> {
+		assert_eq!(bufs.len(), metas.len());
+		assert_eq!(bufs.len(), recv_infos.len());
+		if bufs.is_empty() {
+			return Poll::Ready(Ok(0));
+		}
+		let mut count = 0;
+		while count < bufs.len() {
+			match self.reader.as_mut().poll_next(cx) {
+				Poll::Ready(Some(Ok(frame))) => {
+					let buf = &mut bufs[count];
+					if buf.len() < frame.len() {
+						warn!("ssh transport datagram {} > buf {}", frame.len(), buf.len());
+						if count > 0 {
+							break;
+						}
+						return Poll::Ready(Err(io::Error::other("datagram exceeds recv buffer")));
+					}
+					buf[..frame.len()].copy_from_slice(&frame);
+					metas[count].len = frame.len();
+					metas[count].stride = frame.len();
+					recv_infos[count] =
+						RecvInfo::new(self.remote.clone(), Some(self.local.clone()));
+					count += 1;
+				}
+				Poll::Ready(Some(Err(e))) => {
+					if count > 0 {
+						break;
+					}
+					return Poll::Ready(Err(e));
+				}
+				Poll::Ready(None) => {
+					if count > 0 {
+						break;
+					}
+					return Poll::Ready(Err(io::Error::other("ssh transport closed")));
+				}
+				Poll::Pending => {
+					if count > 0 {
+						break;
+					}
+					return Poll::Pending;
+				}
+			}
+		}
+		Poll::Ready(Ok(count))
+	}
+}
+
+#[derive(Debug)]
+struct SshSender {
+	tx: mpsc::UnboundedSender<Bytes>,
+}
+
+impl CustomSender for SshSender {
+	fn is_valid_send_addr(&self, addr: &CustomAddr) -> bool {
+		addr.id() == REMOWT_SSH_TRANSPORT_ID
+	}
+
+	fn poll_send(
+		&self,
+		_cx: &mut Context,
+		_dst: &CustomAddr,
+		_src: Option<&CustomAddr>,
+		transmit: &Transmit<'_>,
+	) -> Poll<io::Result<()>> {
+		let segment = transmit.segment_size.unwrap_or(transmit.contents.len());
+		if segment == 0 || transmit.contents.is_empty() {
+			return Poll::Ready(Ok(()));
+		}
+		for chunk in transmit.contents.chunks(segment) {
+			if self.tx.send(Bytes::copy_from_slice(chunk)).is_err() {
+				return Poll::Ready(Err(io::Error::other("ssh transport writer gone")));
+			}
+		}
+		Poll::Ready(Ok(()))
+	}
+}
+
+pub struct IrohBiStream {
+	send: SendStream,
+	recv: RecvStream,
+}
+
+impl IrohBiStream {
+	pub fn new(send: SendStream, recv: RecvStream) -> Self {
+		Self { send, recv }
+	}
+}
+
+impl AsyncRead for IrohBiStream {
+	fn poll_read(
+		self: Pin<&mut Self>,
+		cx: &mut Context<'_>,
+		buf: &mut ReadBuf<'_>,
+	) -> Poll<io::Result<()>> {
+		AsyncRead::poll_read(Pin::new(&mut self.get_mut().recv), cx, buf)
+	}
+}
+
+impl AsyncWrite for IrohBiStream {
+	fn poll_write(
+		self: Pin<&mut Self>,
+		cx: &mut Context<'_>,
+		buf: &[u8],
+	) -> Poll<io::Result<usize>> {
+		AsyncWrite::poll_write(Pin::new(&mut self.get_mut().send), cx, buf)
+	}
+	fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
+		AsyncWrite::poll_flush(Pin::new(&mut self.get_mut().send), cx)
+	}
+	fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
+		AsyncWrite::poll_shutdown(Pin::new(&mut self.get_mut().send), cx)
+	}
+}
+
+pub enum TunnelStream {
+	Unix(UnixStream),
+	Iroh(IrohBiStream),
+}
+
+impl AsyncRead for TunnelStream {
+	fn poll_read(
+		self: Pin<&mut Self>,
+		cx: &mut Context<'_>,
+		buf: &mut ReadBuf<'_>,
+	) -> Poll<io::Result<()>> {
+		match self.get_mut() {
+			TunnelStream::Unix(s) => Pin::new(s).poll_read(cx, buf),
+			TunnelStream::Iroh(s) => Pin::new(s).poll_read(cx, buf),
+		}
+	}
+}
+
+impl AsyncWrite for TunnelStream {
+	fn poll_write(
+		self: Pin<&mut Self>,
+		cx: &mut Context<'_>,
+		buf: &[u8],
+	) -> Poll<io::Result<usize>> {
+		match self.get_mut() {
+			TunnelStream::Unix(s) => Pin::new(s).poll_write(cx, buf),
+			TunnelStream::Iroh(s) => Pin::new(s).poll_write(cx, buf),
+		}
+	}
+	fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
+		match self.get_mut() {
+			TunnelStream::Unix(s) => Pin::new(s).poll_flush(cx),
+			TunnelStream::Iroh(s) => Pin::new(s).poll_flush(cx),
+		}
+	}
+	fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
+		match self.get_mut() {
+			TunnelStream::Unix(s) => Pin::new(s).poll_shutdown(cx),
+			TunnelStream::Iroh(s) => Pin::new(s).poll_shutdown(cx),
+		}
+	}
+}
+
+#[derive(Clone)]
+pub struct TunnelDialer {
+	conn: watch::Sender<Option<Connection>>,
+	router: Arc<Mutex<Option<Arc<DatagramRouter>>>>,
+}
+
+impl Default for TunnelDialer {
+	fn default() -> Self {
+		Self::new()
+	}
+}
+
+impl TunnelDialer {
+	pub fn new() -> Self {
+		let (conn, _) = watch::channel(None);
+		Self {
+			conn,
+			router: Arc::new(Mutex::new(None)),
+		}
+	}
+
+	pub fn set_conn(&self, conn: Connection) {
+		*self.router.lock().expect("lock") = Some(DatagramRouter::spawn(conn.clone()));
+		self.conn.send_replace(Some(conn));
+	}
+
+	pub fn router(&self) -> Option<Arc<DatagramRouter>> {
+		self.router.lock().expect("lock").clone()
+	}
+
+	pub async fn connect_tunnel(&self, addr: &TunnelAddr) -> io::Result<TunnelStream> {
+		match addr {
+			TunnelAddr::Unix(path) => Ok(TunnelStream::Unix(UnixStream::connect(path).await?)),
+			TunnelAddr::Iroh { token } => {
+				let mut rx = self.conn.subscribe();
+				let conn =
+					tokio::time::timeout(Duration::from_secs(5), rx.wait_for(|c| c.is_some()))
+						.await
+						.map_err(|_| io::Error::other("timed out waiting for iroh connection"))?
+						.map_err(|_| io::Error::other("iroh connection channel closed"))?
+						.clone()
+						.expect("is_some");
+				let (mut send, recv) = conn.open_bi().await.map_err(io::Error::other)?;
+				send.write_all(&token.to_be_bytes())
+					.await
+					.map_err(io::Error::other)?;
+				Ok(TunnelStream::Iroh(IrohBiStream::new(send, recv)))
+			}
+		}
+	}
+}
+
+const DGRAM_HEADER: usize = 16;
+
+type DatagramRoutes = Arc<Mutex<HashMap<u64, mpsc::UnboundedSender<(u64, Bytes)>>>>;
+
+pub struct DatagramRouter {
+	conn: Connection,
+	routes: DatagramRoutes,
+}
+
+impl DatagramRouter {
+	pub fn spawn(conn: Connection) -> Arc<Self> {
+		let routes: DatagramRoutes = Arc::new(Mutex::new(HashMap::new()));
+		let read_routes = routes.clone();
+		let read_conn = conn.clone();
+		tokio::spawn(async move {
+			loop {
+				match read_conn.read_datagram().await {
+					Ok(dg) if dg.len() >= DGRAM_HEADER => {
+						let session = u64::from_be_bytes(dg[0..8].try_into().expect("8 bytes"));
+						let sub = u64::from_be_bytes(dg[8..16].try_into().expect("8 bytes"));
+						let payload = dg.slice(DGRAM_HEADER..);
+						let tx = read_routes.lock().expect("lock").get(&session).cloned();
+						if let Some(tx) = tx {
+							let _ = tx.send((sub, payload));
+						}
+					}
+					Ok(_) => {}
+					Err(e) => {
+						debug!("datagram read loop ended: {e}");
+						break;
+					}
+				}
+			}
+		});
+		Arc::new(Self { conn, routes })
+	}
+
+	pub fn register(&self, session: u64) -> mpsc::UnboundedReceiver<(u64, Bytes)> {
+		let (tx, rx) = mpsc::unbounded_channel();
+		self.routes.lock().expect("lock").insert(session, tx);
+		rx
+	}
+
+	pub fn unregister(&self, session: u64) {
+		self.routes.lock().expect("lock").remove(&session);
+	}
+
+	pub fn send(&self, session: u64, sub: u64, payload: &[u8]) -> io::Result<()> {
+		let mut buf = BytesMut::with_capacity(DGRAM_HEADER + payload.len());
+		buf.extend_from_slice(&session.to_be_bytes());
+		buf.extend_from_slice(&sub.to_be_bytes());
+		buf.extend_from_slice(payload);
+		self.conn
+			.send_datagram(buf.freeze())
+			.map_err(io::Error::other)
+	}
+}
+
+#[cfg(test)]
+mod tests {
+	use super::*;
+	use iroh::endpoint::presets;
+	use iroh::{EndpointAddr, RelayMode, TransportAddr};
+
+	async fn endpoint<S>(secret: SecretKey, stream: S, remote: EndpointId, accept: bool) -> Endpoint
+	where
+		S: AsyncRead + AsyncWrite + Unpin + Send + Sync + 'static,
+	{
+		let local = secret.public();
+		let transport = Arc::new(SshTransport::new(stream, local, remote));
+		let mut builder = Endpoint::builder(presets::N0)
+			.secret_key(secret)
+			.relay_mode(RelayMode::Disabled)
+			.clear_ip_transports()
+			.add_custom_transport(transport);
+		if accept {
+			builder = builder.alpns(vec![REMOWT_ALPN.to_vec()]);
+		}
+		builder.bind().await.expect("bind")
+	}
+
+	#[tokio::test]
+	async fn echo_over_ssh_transport() {
+		let (client_pipe, agent_pipe) = tokio::io::duplex(256 * 1024);
+		let client_secret = SecretKey::generate();
+		let agent_secret = SecretKey::generate();
+		let client_id = client_secret.public();
+		let agent_id = agent_secret.public();
+
+		let client = endpoint(client_secret, client_pipe, agent_id, false).await;
+		let agent = endpoint(agent_secret, agent_pipe, client_id, true).await;
+
+		let server = tokio::spawn(async move {
+			let incoming = agent.accept().await.expect("incoming");
+			let conn = incoming
+				.accept()
+				.expect("accept")
+				.await
+				.expect("connecting");
+			assert_eq!(conn.remote_id(), client_id);
+			let (mut send, mut recv) = conn.accept_bi().await.expect("accept_bi");
+			let mut buf = [0u8; 5];
+			recv.read_exact(&mut buf).await.expect("read");
+			send.write_all(&buf).await.expect("write");
+			send.finish().expect("finish");
+			conn.closed().await;
+		});
+
+		let addr =
+			EndpointAddr::from_parts(agent_id, [TransportAddr::Custom(ssh_custom_addr(agent_id))]);
+		let conn = client.connect(addr, REMOWT_ALPN).await.expect("connect");
+		assert_eq!(conn.remote_id(), agent_id);
+		let (mut send, mut recv) = conn.open_bi().await.expect("open_bi");
+		send.write_all(b"hello").await.expect("write");
+		send.finish().expect("finish");
+		let mut buf = [0u8; 5];
+		recv.read_exact(&mut buf).await.expect("read");
+		assert_eq!(&buf, b"hello");
+
+		conn.close(0u32.into(), b"done");
+		let _ = server.await;
+	}
+
+	#[tokio::test]
+	async fn dgram_round_trip() {
+		let (client_pipe, agent_pipe) = tokio::io::duplex(256 * 1024);
+		let client_secret = SecretKey::generate();
+		let agent_secret = SecretKey::generate();
+		let client_id = client_secret.public();
+		let agent_id = agent_secret.public();
+
+		let client = endpoint(client_secret, client_pipe, agent_id, false).await;
+		let agent = endpoint(agent_secret, agent_pipe, client_id, true).await;
+
+		let server = tokio::spawn(async move {
+			let incoming = agent.accept().await.expect("incoming");
+			let conn = incoming
+				.accept()
+				.expect("accept")
+				.await
+				.expect("connecting");
+			let router = DatagramRouter::spawn(conn);
+			let mut rx = router.register(7);
+			if let Some((sub, payload)) = rx.recv().await {
+				router.send(7, sub, &payload).expect("send reply");
+			}
+			tokio::time::sleep(Duration::from_millis(200)).await;
+		});
+
+		let addr =
+			EndpointAddr::from_parts(agent_id, [TransportAddr::Custom(ssh_custom_addr(agent_id))]);
+		let conn = client.connect(addr, REMOWT_ALPN).await.expect("connect");
+		let router = DatagramRouter::spawn(conn);
+		let mut rx = router.register(7);
+		router.send(7, 42, b"ping").expect("send");
+		let (sub, payload) = tokio::time::timeout(Duration::from_secs(5), rx.recv())
+			.await
+			.expect("datagram timed out")
+			.expect("router closed");
+		assert_eq!(sub, 42);
+		assert_eq!(&payload[..], b"ping");
+		let _ = server.await;
+	}
+}
addedremowt/crates/remowt-link-shared/src/lib.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-link-shared/src/lib.rs
@@ -0,0 +1,89 @@
+use bifrostlink::error::{ErrorT, ListenerForYourRequestHasBeenDeadError, ResponseError};
+use bifrostlink::notification;
+use bifrostlink::packet::OpaquePacketWrapper;
+use bifrostlink::AddressT;
+use bytes::Bytes;
+use serde::de::DeserializeOwned;
+use serde::{Deserialize, Serialize};
+
+pub mod editor;
+pub mod iroh_tunnel;
+pub mod port;
+
+#[derive(Clone, Serialize, Hash, Eq, Debug, PartialEq, Deserialize)]
+pub enum Address {
+	User,
+	Agent,
+	AgentPrivileged,
+	Plugin(u16),
+}
+impl AddressT for Address {}
+
+pub mod plugin;
+
+#[derive(thiserror::Error, Debug)]
+pub enum Error {
+	#[error("listener is dead")]
+	ListenerDead,
+	#[error("response: {0}")]
+	Response(String),
+
+	#[error(transparent)]
+	Ui(#[from] remowt_ui_prompt::Error),
+}
+
+impl From<ListenerForYourRequestHasBeenDeadError> for Error {
+	fn from(_value: ListenerForYourRequestHasBeenDeadError) -> Self {
+		Self::ListenerDead
+	}
+}
+impl From<serde_json::Error> for Error {
+	fn from(_value: serde_json::Error) -> Self {
+		Self::ListenerDead
+	}
+}
+impl From<Error> for ResponseError {
+	fn from(val: Error) -> Self {
+		ResponseError(val.to_string())
+	}
+}
+impl From<ResponseError> for Error {
+	fn from(value: ResponseError) -> Self {
+		Self::Response(value.0)
+	}
+}
+impl ErrorT for Error {}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct TestNotification {
+	pub value: u32,
+}
+notification!((0x0100) TestNotification);
+
+pub struct BifConfig;
+impl bifrostlink::Config for BifConfig {
+	type Address = Address;
+
+	type Error = Error;
+
+	type EncodedData = Vec<u8>;
+
+	fn decode_headers(
+		data_with_headers: Bytes,
+	) -> Result<(OpaquePacketWrapper<Self::Address>, Self::EncodedData), Self::Error> {
+		let (header, data): (OpaquePacketWrapper<Self::Address>, Vec<u8>) =
+			serde_json::from_slice(&data_with_headers)?;
+		Ok((header, data))
+	}
+
+	fn decode_data<T: DeserializeOwned>(data: Self::EncodedData) -> Result<T, Self::Error> {
+		let v: T = serde_json::from_slice(&data)?;
+		Ok(v)
+	}
+
+	fn encode_data<T: Serialize>(headers: OpaquePacketWrapper<Self::Address>, data: T) -> Bytes {
+		let data = serde_json::to_vec(&data).expect("serialization shouldn't fail");
+		let o = serde_json::to_vec(&(headers, data)).expect("serialization shouldn't fail");
+		o.into()
+	}
+}
addedremowt/crates/remowt-link-shared/src/plugin.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-link-shared/src/plugin.rs
@@ -0,0 +1,39 @@
+use std::future::Future;
+
+use bifrostlink::declarative::endpoints;
+use bifrostlink::Config;
+use serde::{Deserialize, Serialize};
+
+#[derive(Serialize, Deserialize, Debug, thiserror::Error)]
+pub enum Error {
+	#[error("plugin name must be a bare file name")]
+	BadName,
+	#[error("spawning plugin failed: {0}")]
+	Spawn(String),
+	#[error("agent is shutting down")]
+	Gone,
+}
+
+pub trait PluginHost: Send + Sync {
+	fn load_plugin(&self, id: u16, name: String) -> impl Future<Output = Result<(), Error>> + Send;
+
+	fn load_plugin_path(
+		&self,
+		id: u16,
+		path: String,
+	) -> impl Future<Output = Result<(), Error>> + Send;
+}
+
+pub struct PluginEndpoints<H>(pub H);
+
+#[endpoints(ns = 9)]
+impl<H: PluginHost + 'static> PluginEndpoints<H> {
+	#[endpoints(id = 1)]
+	async fn load_plugin(&self, id: u16, name: String) -> Result<(), Error> {
+		self.0.load_plugin(id, name).await
+	}
+	#[endpoints(id = 2)]
+	async fn load_plugin_path(&self, id: u16, path: String) -> Result<(), Error> {
+		self.0.load_plugin_path(id, path).await
+	}
+}
addedremowt/crates/remowt-link-shared/src/port.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-link-shared/src/port.rs
@@ -0,0 +1,82 @@
+use std::io;
+
+use bifrostlink::Port;
+use bytes::{Bytes, BytesMut};
+use tokio::io::{AsyncRead, AsyncReadExt as _, AsyncWrite, AsyncWriteExt as _};
+use tokio::select;
+
+pub fn child_port<R, W>(mut reader: R, mut writer: W) -> Port
+where
+	R: AsyncRead + Unpin + Send + 'static,
+	W: AsyncWrite + Unpin + Send + 'static,
+{
+	Port::new(|mut rx, tx| async move {
+		let read_task = async move {
+			loop {
+				let len = match reader.read_u32().await {
+					Ok(len) => len,
+					Err(e) => {
+						log_read_end(&e);
+						break;
+					}
+				};
+				let mut buf = BytesMut::zeroed(len as usize);
+				if let Err(e) = reader.read_exact(&mut buf).await {
+					log_read_end(&e);
+					break;
+				}
+				if tx.send(buf.freeze()).is_err() {
+					break;
+				}
+			}
+		};
+		let write_task = async move {
+			while let Some(msg) = rx.recv().await {
+				if let Err(e) = write_frame(&mut writer, msg).await {
+					log_write_end(&e);
+					break;
+				}
+			}
+		};
+		select! {
+			_ = read_task => {},
+			_ = write_task => {},
+		}
+	})
+}
+
+fn log_read_end(e: &io::Error) {
+	if matches!(
+		e.kind(),
+		io::ErrorKind::UnexpectedEof
+			| io::ErrorKind::BrokenPipe
+			| io::ErrorKind::ConnectionReset
+			| io::ErrorKind::ConnectionAborted
+	) {
+		tracing::debug!("child read ended: {e}");
+	} else {
+		tracing::error!("child read failed: {e}");
+	}
+}
+
+fn log_write_end(e: &io::Error) {
+	if matches!(
+		e.kind(),
+		io::ErrorKind::BrokenPipe
+			| io::ErrorKind::ConnectionReset
+			| io::ErrorKind::ConnectionAborted
+	) {
+		tracing::debug!("child write ended: {e}");
+	} else {
+		tracing::error!("child write failed: {e}");
+	}
+}
+
+async fn write_frame<W: AsyncWrite + Unpin>(writer: &mut W, msg: Bytes) -> io::Result<()> {
+	let len = u32::try_from(msg.len())
+		.map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "message larger than 4GB"))?;
+	writer.write_u32(len).await?;
+	writer.write_all(&msg).await?;
+	writer.flush().await?;
+	Ok(())
+}
addedremowt/crates/remowt-plugin/Cargo.tomldiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-plugin/Cargo.toml
@@ -0,0 +1,23 @@
+[package]
+name = "remowt-plugin"
+description = "Plugin host and protocol for remowt agents"
+version.workspace = true
+edition = "2021"
+license.workspace = true
+
+[dependencies]
+anyhow.workspace = true
+bifrostlink.workspace = true
+bifrostlink-ports.workspace = true
+remowt-link-shared.workspace = true
+serde_json.workspace = true
+tokio = { workspace = true, features = [
+	"rt",
+	"net",
+	"io-std",
+	"io-util",
+	"macros",
+	"time",
+	"process",
+] }
+tracing-subscriber.workspace = true
addedremowt/crates/remowt-plugin/src/host.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-plugin/src/host.rs
@@ -0,0 +1,70 @@
+use std::ffi::OsStr;
+use std::process::Stdio;
+use std::sync::Mutex;
+
+use bifrostlink::{Rpc, Rtt, WeakRpc};
+use tokio::process::{Child, Command};
+
+use remowt_link_shared::plugin::{Error, PluginEndpoints, PluginHost};
+use remowt_link_shared::port::child_port;
+use remowt_link_shared::{Address, BifConfig};
+
+pub fn serve(rpc: &mut Rpc<BifConfig>) {
+	let host = Host {
+		me: rpc.me(),
+		rpc: rpc.clone().downgrade(),
+		children: Mutex::new(Vec::new()),
+	};
+	PluginEndpoints(host).register_endpoints(rpc);
+}
+
+struct Host {
+	me: Address,
+	rpc: WeakRpc<BifConfig>,
+	children: Mutex<Vec<Child>>,
+}
+
+impl Host {
+	fn spawn(&self, id: u16, path: impl AsRef<OsStr>) -> Result<(), Error> {
+		let rpc = self.rpc.clone().upgrade().ok_or(Error::Gone)?;
+
+		let mut child = Command::new(path)
+			.arg(id.to_string())
+			.arg(serde_json::to_string(&self.me).expect("address serializes"))
+			.stdin(Stdio::piped())
+			.stdout(Stdio::piped())
+			.kill_on_drop(true)
+			.spawn()
+			.map_err(|e| Error::Spawn(e.to_string()))?;
+		let stdin = child.stdin.take().expect("stdin piped");
+		let stdout = child.stdout.take().expect("stdout piped");
+
+		let addr = Address::Plugin(id);
+		rpc.add_direct(addr, child_port(stdout, stdin), Rtt(0));
+		self.children.lock().expect("not poisoned").push(child);
+		Ok(())
+	}
+}
+
+impl PluginHost for Host {
+	async fn load_plugin(&self, id: u16, name: String) -> Result<(), Error> {
+		// TODO: Right now loads plugin next to the binary...
+		// But with our CA addressed schema, the plugins should be located in content-addressed subdir...
+		// Maybe it should just be scrapped in favor of load_plugin_path.
+		if name.is_empty() || name == "." || name == ".." || name.contains(['/', '\0']) {
+			return Err(Error::BadName);
+		}
+		let exe = std::env::current_exe().map_err(|e| Error::Spawn(e.to_string()))?;
+		let dir = exe
+			.parent()
+			.ok_or_else(|| Error::Spawn("primary agent has no parent directory".to_owned()))?;
+		self.spawn(id, dir.join(&name))
+	}
+
+	async fn load_plugin_path(&self, id: u16, path: String) -> Result<(), Error> {
+		if path.is_empty() || path.contains('\0') {
+			return Err(Error::BadName);
+		}
+		self.spawn(id, path)
+	}
+}
addedremowt/crates/remowt-plugin/src/lib.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-plugin/src/lib.rs
@@ -0,0 +1,46 @@
+use std::future::pending;
+
+use anyhow::Result;
+use bifrostlink::{Rpc, Rtt};
+use bifrostlink_ports::stdio::from_stdio;
+use tokio::runtime::Builder;
+
+pub mod host;
+
+pub use bifrostlink;
+pub use remowt_link_shared::{self, Address, BifConfig};
+
+pub fn plugin_index() -> Result<u16> {
+	let arg = std::env::args()
+		.nth(1)
+		.ok_or_else(|| anyhow::anyhow!("missing plugin index argument"))?;
+	arg.parse()
+		.map_err(|e| anyhow::anyhow!("invalid plugin index {arg:?}: {e}"))
+}
+
+pub fn host_address() -> Result<Address> {
+	let arg = std::env::args()
+		.nth(2)
+		.ok_or_else(|| anyhow::anyhow!("missing host address argument"))?;
+	serde_json::from_str(&arg).map_err(|e| anyhow::anyhow!("invalid host address {arg:?}: {e}"))
+}
+
+pub fn run<F>(register: F) -> Result<()>
+where
+	F: FnOnce(&mut Rpc<BifConfig>),
+{
+	tracing_subscriber::fmt()
+		.with_writer(std::io::stderr)
+		.init();
+
+	let index = plugin_index()?;
+	let host = host_address()?;
+	let runtime = Builder::new_current_thread().enable_all().build()?;
+	runtime.block_on(async move {
+		let mut rpc = Rpc::<BifConfig>::new(Address::Plugin(index));
+		rpc.add_direct(host, from_stdio(), Rtt(0));
+		register(&mut rpc);
+		let _rpc = rpc;
+		pending::<Result<()>>().await
+	})
+}
addedremowt/crates/remowt-ui-prompt/Cargo.tomldiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-ui-prompt/Cargo.toml
@@ -0,0 +1,20 @@
+[package]
+name = "remowt-ui-prompt"
+description = "Interactive UI prompt endpoint for remowt (D-Bus)"
+version.workspace = true
+edition = "2021"
+license.workspace = true
+
+[dependencies]
+anyhow.workspace = true
+bifrostlink.workspace = true
+bifrostlink-macros.workspace = true
+serde.workspace = true
+thiserror.workspace = true
+tokio = { workspace = true, features = ["io-util", "macros", "process", "rt"] }
+tracing.workspace = true
+zbus = { workspace = true, optional = true }
+
+[features]
+default = ["dbus"]
+dbus = ["dep:zbus"]
addedremowt/crates/remowt-ui-prompt/src/auto.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-ui-prompt/src/auto.rs
@@ -0,0 +1,83 @@
+use anyhow::bail;
+use tracing::debug;
+use zbus::fdo::DBusProxy;
+use zbus::names::BusName;
+
+use crate::dbus::{DbusPrompterProxy, BUS_NAME, PROMPTER_PATH};
+use crate::rofi::RofiPrompter;
+use crate::{Prompter, Result, Source};
+
+pub struct AutoPrompter {
+	dbus: Option<DbusPrompterProxy<'static>>,
+	fallback: RofiPrompter,
+}
+
+impl AutoPrompter {
+	pub async fn new() -> Self {
+		let dbus = match Self::try_dbus().await {
+			Ok(p) => Some(p),
+			Err(e) => {
+				debug!("dbus prompter unavailable, falling back to rofi: {e}");
+				None
+			}
+		};
+		Self {
+			dbus,
+			fallback: RofiPrompter,
+		}
+	}
+
+	async fn try_dbus() -> anyhow::Result<DbusPrompterProxy<'static>> {
+		let conn = zbus::Connection::session().await?;
+		let dbus = DBusProxy::new(&conn).await?;
+		let name = BusName::try_from(BUS_NAME)?;
+		if !dbus.name_has_owner(name).await? {
+			bail!("{BUS_NAME} not registered on session bus");
+		}
+		let proxy = DbusPrompterProxy::builder(&conn)
+			.destination(BUS_NAME)?
+			.path(PROMPTER_PATH)?
+			.build()
+			.await?;
+		Ok(proxy)
+	}
+}
+
+impl Prompter for AutoPrompter {
+	async fn prompt_enum(
+		&self,
+		prompt: &str,
+		description: &str,
+		variants: &[&str],
+		source: &[Source],
+	) -> Result<u32> {
+		if let Some(dbus) = &self.dbus {
+			return Prompter::prompt_enum(dbus, prompt, description, variants, source).await;
+		}
+		self.fallback
+			.prompt_enum(prompt, description, variants, source)
+			.await
+	}
+
+	async fn prompt_text(
+		&self,
+		echo: bool,
+		prompt: &str,
+		description: &str,
+		source: &[Source],
+	) -> Result<String> {
+		if let Some(dbus) = &self.dbus {
+			return Prompter::prompt_text(dbus, echo, prompt, description, source).await;
+		}
+		self.fallback
+			.prompt_text(echo, prompt, description, source)
+			.await
+	}
+
+	async fn display_text(&self, error: bool, description: &str, source: &[Source]) -> Result<()> {
+		if let Some(dbus) = &self.dbus {
+			return Prompter::display_text(dbus, error, description, source).await;
+		}
+		self.fallback.display_text(error, description, source).await
+	}
+}
addedremowt/crates/remowt-ui-prompt/src/bifrost.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-ui-prompt/src/bifrost.rs
@@ -0,0 +1,109 @@
+use bifrostlink::{Config, Rpc};
+use bifrostlink_macros::endpoints;
+use serde::{Deserialize, Serialize};
+
+use crate::{Error, Prompter, Source};
+
+pub struct PromptEndpoints<P>(pub P);
+
+#[endpoints(ns = 2)]
+impl<P> PromptEndpoints<P>
+where
+	P: Prompter + Send + Sync + 'static,
+{
+	#[endpoints(id = 1, cancel)]
+	async fn prompt_enum(
+		&self,
+		prompt: String,
+		description: String,
+		variants: Vec<String>,
+		source: Vec<Source>,
+	) -> Result<u32, Error> {
+		let variants: Vec<&str> = variants.iter().map(|v| v.as_str()).collect();
+		self.0
+			.prompt_enum(&prompt, &description, &variants, &source)
+			.await
+	}
+
+	#[endpoints(id = 2, cancel)]
+	async fn prompt_text(
+		&self,
+		echo: bool,
+		prompt: String,
+		description: String,
+		source: Vec<Source>,
+	) -> Result<String, Error> {
+		self.0
+			.prompt_text(echo, &prompt, &description, &source)
+			.await
+	}
+
+	#[endpoints(id = 3, cancel)]
+	async fn display_text(
+		&self,
+		error: bool,
+		description: String,
+		source: Vec<Source>,
+	) -> Result<(), Error> {
+		self.0.display_text(error, &description, &source).await
+	}
+}
+
+impl<C: Config> Prompter for PromptEndpointsClient<C>
+where
+	Error: ToString,
+{
+	async fn prompt_enum(
+		&self,
+		prompt: &str,
+		description: &str,
+		variants: &[&str],
+		source: &[Source],
+	) -> crate::Result<u32> {
+		self.prompt_enum(
+			prompt.to_owned(),
+			description.to_owned(),
+			variants.iter().map(|v| (*v).to_owned()).collect(),
+			source.to_vec(),
+		)
+		.await
+		.map_err(|e| Error::Remote(e.to_string()))?
+	}
+
+	async fn prompt_text(
+		&self,
+		echo: bool,
+		prompt: &str,
+		description: &str,
+		source: &[Source],
+	) -> crate::Result<String> {
+		self.prompt_text(
+			echo,
+			prompt.to_owned(),
+			description.to_owned(),
+			source.to_vec(),
+		)
+		.await
+		.map_err(|e| Error::Remote(e.to_string()))?
+	}
+
+	async fn display_text(
+		&self,
+		error: bool,
+		description: &str,
+		source: &[Source],
+	) -> crate::Result<()> {
+		self.display_text(error, description.to_owned(), source.to_vec())
+			.await
+			.map_err(|e| Error::Remote(e.to_string()))?
+	}
+}
+
+pub fn serve_prompts<P, C>(rpc: &mut Rpc<C>, prompt: P)
+where
+	P: Prompter + Send + Sync + 'static,
+	C: Config,
+	C::Error: From<Error>,
+{
+	PromptEndpoints(prompt).register_endpoints(rpc);
+}
addedremowt/crates/remowt-ui-prompt/src/dbus.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-ui-prompt/src/dbus.rs
@@ -0,0 +1,143 @@
+use zbus::interface;
+use zbus::{fdo, proxy};
+
+use crate::Source;
+use crate::{BlockingPrompter, Result};
+use crate::{Error, Prompter};
+
+pub const BUS_NAME: &str = "lach.RemowtAskpass";
+pub const PROMPTER_PATH: &str = "/lach/Askpass";
+
+pub struct DbusPrompterInterface<P>(pub P);
+
+#[interface(name = "lach.PolkitInputHandler")]
+impl<P: Prompter + Send + Sync + 'static> DbusPrompterInterface<P> {
+	async fn prompt_enum(
+		&self,
+		prompt: &str,
+		description: &str,
+		variants: Vec<String>,
+		source: Vec<Source>,
+	) -> fdo::Result<u32> {
+		let variants: Vec<&str> = variants.iter().map(|v| v.as_str()).collect();
+		Ok(self
+			.0
+			.prompt_enum(prompt, description, &variants, &source)
+			.await?)
+	}
+	async fn prompt_text(
+		&self,
+		echo: bool,
+		prompt: &str,
+		description: &str,
+		source: Vec<Source>,
+	) -> fdo::Result<String> {
+		Ok(self
+			.0
+			.prompt_text(echo, prompt, description, &source)
+			.await?)
+	}
+	async fn display_text(
+		&self,
+		error: bool,
+		description: &str,
+		source: Vec<Source>,
+	) -> fdo::Result<()> {
+		Ok(self.0.display_text(error, description, &source).await?)
+	}
+}
+
+#[proxy(interface = "lach.PolkitInputHandler")]
+pub trait DbusPrompter {
+	async fn prompt_enum(
+		&self,
+		prompt: &str,
+		description: &str,
+		variants: &[&str],
+		source: &[Source],
+	) -> fdo::Result<u32>;
+	async fn prompt_text(
+		&self,
+		echo: bool,
+		prompt: &str,
+		description: &str,
+		source: &[Source],
+	) -> fdo::Result<String>;
+	async fn display_text(
+		&self,
+		error: bool,
+		description: &str,
+		source: &[Source],
+	) -> fdo::Result<()>;
+}
+
+impl Prompter for DbusPrompterProxy<'_> {
+	async fn prompt_enum(
+		&self,
+		prompt: &str,
+		description: &str,
+		variants: &[&str],
+		source: &[Source],
+	) -> Result<u32> {
+		Ok(self
+			.prompt_enum(prompt, description, variants, source)
+			.await?)
+	}
+
+	async fn prompt_text(
+		&self,
+		echo: bool,
+		prompt: &str,
+		description: &str,
+		source: &[Source],
+	) -> Result<String> {
+		Ok(self.prompt_text(echo, prompt, description, source).await?)
+	}
+
+	async fn display_text(&self, error: bool, description: &str, source: &[Source]) -> Result<()> {
+		Ok(self.display_text(error, description, source).await?)
+	}
+}
+impl BlockingPrompter for DbusPrompterProxyBlocking<'_> {
+	fn prompt_enum(
+		&self,
+		prompt: &str,
+		description: &str,
+		variants: &[&str],
+		source: &[Source],
+	) -> Result<u32> {
+		Ok(self.prompt_enum(prompt, description, variants, source)?)
+	}
+
+	fn prompt_text(
+		&self,
+		echo: bool,
+		prompt: &str,
+		description: &str,
+		source: &[Source],
+	) -> Result<String> {
+		Ok(self.prompt_text(echo, prompt, description, source)?)
+	}
+
+	fn display_text(&self, error: bool, description: &str, source: &[Source]) -> Result<()> {
+		Ok(self.display_text(error, description, source)?)
+	}
+}
+
+impl From<fdo::Error> for Error {
+	fn from(value: fdo::Error) -> Self {
+		if matches!(value, fdo::Error::NoReply(_)) {
+			return Self::Cancel;
+		}
+		Self::InputError(format!("{value}"))
+	}
+}
+impl From<Error> for fdo::Error {
+	fn from(value: Error) -> Self {
+		match value {
+			Error::Cancel => fdo::Error::NoReply("input was cancelled".to_owned()),
+			Error::Remote(e) => fdo::Error::NoReply(format!("remote error occured: {e}")),
+			Error::InputError(e) => fdo::Error::Failed(e),
+		}
+	}
+}
addedremowt/crates/remowt-ui-prompt/src/lib.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-ui-prompt/src/lib.rs
@@ -0,0 +1,202 @@
+use core::fmt;
+use std::borrow::Cow;
+use std::future::Future;
+use std::result;
+
+pub mod auto;
+pub mod bifrost;
+pub mod dbus;
+pub mod rofi;
+
+#[derive(thiserror::Error, Debug, serde::Serialize, serde::Deserialize)]
+pub enum Error {
+	#[error("user has cancelled input")]
+	Cancel,
+	#[error("input error: {0}")]
+	InputError(String),
+	#[error("unknown remote error: {0}")]
+	Remote(String),
+}
+
+pub type Result<T, E = Error> = result::Result<T, E>;
+
+#[cfg_attr(feature = "dbus", derive(zbus::zvariant::Type))]
+#[derive(serde::Serialize, serde::Deserialize, Clone)]
+pub struct Source(pub Cow<'static, str>);
+impl fmt::Display for Source {
+	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+		write!(f, "<u>{}</u>", self.0)
+	}
+}
+
+pub trait Prompter: Send + Sync {
+	fn prompt_radio(
+		&self,
+		prompt: &str,
+		description: &str,
+		source: &[Source],
+	) -> impl Future<Output = Result<bool>> + Send {
+		let fut = self.prompt_enum(prompt, description, &["No", "Yes"], source);
+		async { fut.await.map(|v| v == 1) }
+	}
+	fn prompt_enum(
+		&self,
+		prompt: &str,
+		description: &str,
+		variants: &[&str],
+		source: &[Source],
+	) -> impl Future<Output = Result<u32>> + Send;
+	fn prompt_text(
+		&self,
+		echo: bool,
+		prompt: &str,
+		description: &str,
+		source: &[Source],
+	) -> impl Future<Output = Result<String>> + Send;
+	fn display_text(
+		&self,
+		error: bool,
+		description: &str,
+		source: &[Source],
+	) -> impl Future<Output = Result<()>> + Send;
+}
+pub trait BlockingPrompter {
+	fn prompt_radio(&self, prompt: &str, description: &str, source: &[Source]) -> Result<bool> {
+		self.prompt_enum(prompt, description, &["No", "Yes"], source)
+			.map(|v| v == 1)
+	}
+	fn prompt_enum(
+		&self,
+		prompt: &str,
+		description: &str,
+		variants: &[&str],
+		source: &[Source],
+	) -> Result<u32>;
+	fn prompt_text(
+		&self,
+		echo: bool,
+		prompt: &str,
+		description: &str,
+		source: &[Source],
+	) -> Result<String>;
+	fn display_text(&self, error: bool, description: &str, source: &[Source]) -> Result<()>;
+}
+impl<P> Prompter for &P
+where
+	P: Prompter,
+{
+	fn prompt_radio(
+		&self,
+		prompt: &str,
+		description: &str,
+		source: &[Source],
+	) -> impl Future<Output = Result<bool>> + Send {
+		(*self).prompt_radio(prompt, description, source)
+	}
+
+	fn prompt_enum(
+		&self,
+		prompt: &str,
+		description: &str,
+		variants: &[&str],
+		source: &[Source],
+	) -> impl Future<Output = Result<u32>> + Send {
+		(*self).prompt_enum(prompt, description, variants, source)
+	}
+
+	fn prompt_text(
+		&self,
+		echo: bool,
+		prompt: &str,
+		description: &str,
+		source: &[Source],
+	) -> impl Future<Output = Result<String>> + Send {
+		(*self).prompt_text(echo, prompt, description, source)
+	}
+
+	fn display_text(
+		&self,
+		error: bool,
+		description: &str,
+		source: &[Source],
+	) -> impl Future<Output = Result<()>> + Send {
+		(*self).display_text(error, description, source)
+	}
+}
+
+pub struct PrependSourcePrompter<P> {
+	pub prompter: P,
+	pub source: Vec<Source>,
+	pub description: String,
+}
+impl<P> PrependSourcePrompter<P> {
+	fn source(&self, input: &[Source]) -> Vec<Source> {
+		let mut out = self.source.clone();
+		out.extend(input.iter().cloned());
+		out
+	}
+	fn description(&self, input: &str) -> String {
+		if self.description.is_empty() {
+			input.to_owned()
+		} else if input.is_empty() {
+			self.description.to_owned()
+		} else {
+			format!("{input}\n\n{}", self.description)
+		}
+	}
+}
+impl<P> Prompter for PrependSourcePrompter<P>
+where
+	P: Prompter + Sync,
+{
+	async fn prompt_radio(
+		&self,
+		prompt: &str,
+		description: &str,
+		source: &[Source],
+	) -> Result<bool> {
+		self.prompter
+			.prompt_radio(prompt, &self.description(description), &self.source(source))
+			.await
+	}
+
+	async fn prompt_enum(
+		&self,
+		prompt: &str,
+		description: &str,
+		variants: &[&str],
+		source: &[Source],
+	) -> Result<u32> {
+		self.prompter
+			.prompt_enum(
+				prompt,
+				&self.description(description),
+				variants,
+				&self.source(source),
+			)
+			.await
+	}
+
+	async fn prompt_text(
+		&self,
+		echo: bool,
+		prompt: &str,
+		description: &str,
+		source: &[Source],
+	) -> Result<String> {
+		self.prompter
+			.prompt_text(
+				echo,
+				prompt,
+				&self.description(description),
+				&self.source(source),
+			)
+			.await
+	}
+
+	async fn display_text(&self, error: bool, description: &str, source: &[Source]) -> Result<()> {
+		self.prompter
+			.display_text(error, &self.description(description), &self.source(source))
+			.await
+	}
+}
addedremowt/crates/remowt-ui-prompt/src/rofi.rsdiffbeforeafterboth
--- /dev/null
+++ b/remowt/crates/remowt-ui-prompt/src/rofi.rs
@@ -0,0 +1,226 @@
+use std::process::Stdio;
+
+use tokio::io::AsyncWriteExt;
+use tokio::process::Command;
+use tracing::trace;
+
+use crate::{Error, Prompter, Result, Source};
+
+#[derive(Clone)]
+pub struct RofiPrompter;
+
+fn fixup_prompt(prompt: &str) -> &str {
+	// Rofi always appends such suffix
+	prompt.strip_suffix(": ").unwrap_or(prompt)
+}
+
+fn rofi_command() -> Command {
+	Command::new(option_env!("ROFI").unwrap_or("rofi"))
+}
+
+impl Prompter for RofiPrompter {
+	async fn prompt_enum(
+		&self,
+		prompt: &str,
+		description: &str,
+		variants: &[&str],
+		source: &[Source],
+	) -> Result<u32> {
+		trace!("rofi radio");
+		let mut cmd = rofi_command();
+		let mesg = if source.is_empty() {
+			description.to_owned()
+		} else {
+			let mut out = format!("{description}\n\n<b>Requested on ",);
+			for (i, s) in source.iter().enumerate() {
+				if i != 0 {
+					out.push_str(" -> ");
+				}
+				out.push_str(&s.to_string());
+			}
+			out.push_str("</b>");
+			out
+		};
+		cmd.args([
+			"-dmenu",
+			"-mesg",
+			&mesg,
+			"-sync",
+			"-no-custom",
+			"-p",
+			fixup_prompt(prompt),
+			"-format",
+			"i",
+			"-markup-rows",
+		]);
+		cmd.stdin(Stdio::piped());
+		cmd.stdout(Stdio::piped());
+		cmd.kill_on_drop(true);
+		let mut child = cmd
+			.spawn()
+			.map_err(|e| Error::InputError(format!("failed to spawn rofi: {e}")))?;
+
+		let mut stdin = child.stdin.take().expect("stdin is piped");
+		for var in variants {
+			stdin
+				.write_all(var.replace('\n', " ").as_bytes())
+				.await
+				.map_err(|e| Error::InputError(format!("failed to write rofi variants: {e}")))?;
+			stdin
+				.write_all(b"\n")
+				.await
+				.map_err(|e| Error::InputError(format!("failed to write rofi variants: {e}")))?;
+		}
+		// write_all already flushes, just to be sure.
+		let _ = stdin.flush().await;
+		drop(stdin);
+
+		let out = child
+			.wait_with_output()
+			.await
+			.map_err(|e| Error::InputError(format!("failed to wait for rofi: {e}")))?;
+		match out.status.code() {
+			Some(0) => {}
+			Some(1) => return Err(Error::Cancel),
+			other => {
+				return Err(Error::InputError(format!(
+					"rofi exited with status {other:?}"
+				)));
+			}
+		}
+		let stdout = out
+			.stdout
+			.strip_suffix(b"\n")
+			.unwrap_or(&out.stdout)
+			.to_owned();
+
+		let id: u32 = String::from_utf8(stdout)
+			.map_err(|e| Error::InputError(format!("rofi produced invalid output: {e}")))?
+			.parse()
+			.map_err(|e| Error::InputError(format!("rofi produced invalid output: {e}")))?;
+		if id as usize >= variants.len() {
+			return Err(Error::InputError("invalid rofi response".to_owned()));
+		}
+
+		Ok(id)
+	}
+
+	async fn prompt_text(
+		&self,
+		echo: bool,
+		prompt: &str,
+		description: &str,
+		source: &[Source],
+	) -> Result<String> {
+		trace!("rofi text");
+		let mut cmd = rofi_command();
+		let mesg = if source.is_empty() {
+			description.to_owned()
+		} else {
+			let mut out = format!("{description}\n\n<b>Requested on ",);
+			for (i, s) in source.iter().enumerate() {
+				if i != 0 {
+					out.push_str(" -> ");
+				}
+				out.push_str(&s.to_string());
+			}
+			out.push_str("</b>");
+			out
+		};
+		cmd.args(["-dmenu", "-mesg", &mesg, "-p", fixup_prompt(prompt)]);
+		if !echo {
+			cmd.arg("-password");
+		}
+		cmd.stdin(Stdio::null());
+		cmd.stdout(Stdio::piped());
+		cmd.kill_on_drop(true);
+		let child = cmd
+			.spawn()
+			.map_err(|e| Error::InputError(format!("failed to spawn rofi: {e}")))?;
+
+		let out = child
+			.wait_with_output()
+			.await
+			.map_err(|e| Error::InputError(format!("failed to wait for rofi: {e}")))?;
+		match out.status.code() {
+			Some(0) => {}
+			Some(1) => return Err(Error::Cancel),
+			other => {
+				return Err(Error::InputError(format!(
+					"rofi exited with status {other:?}"
+				)));
+			}
+		}
+		let stdout = out
+			.stdout
+			.strip_suffix(b"\n")
+			.unwrap_or(&out.stdout)
+			.to_owned();
+
+		Ok(String::from_utf8_lossy(&stdout).to_string())
+	}
+
+	async fn display_text(&self, error: bool, description: &str, source: &[Source]) -> Result<()> {
+		trace!("rofi display");
+		let mut cmd = rofi_command();
+		let mut mesg = if source.is_empty() {
+			description.to_owned()
+		} else {
+			let mut out = format!("{description}\n\n<b>Coming from ",);
+			for s in source.iter() {
+				out.push_str(&s.to_string());
+			}
+			out.push_str("</b>");
+			out
+		};
+		if error {
+			mesg.insert_str(0, "<span color=\"red\">");
+			mesg.push_str("</span>");
+		}
+		cmd.args(["-e", &mesg, "-markup"]);
+		cmd.stdin(Stdio::null());
+		cmd.stdout(Stdio::null());
+		cmd.kill_on_drop(true);
+		let mut child = cmd
+			.spawn()
+			.map_err(|e| Error::InputError(format!("failed to spawn rofi: {e}")))?;
+
+		child
+			.wait()
+			.await
+			.map_err(|e| Error::InputError(format!("failed to wait for rofi: {e}")))?;
+
+		Ok(())
+	}
+}
+
+#[cfg(test)]
+mod tests {
+	use std::borrow::Cow;
+
+	use crate::rofi::RofiPrompter;
+	use crate::{PrependSourcePrompter, Prompter as _, Source};
+
+	// #[tokio::test]
+	#[tokio::test]
+	#[ignore = "interactive"]
+	async fn test() {
+		let prompter = PrependSourcePrompter {
+			prompter: RofiPrompter,
+			description: "test".to_owned(),
+			source: vec![Source(Cow::Borrowed("ssh"))],
+		};
+		prompter
+			.prompt_radio("Enable", "Polkit needs access", &[])
+			.await
+			.expect("rofi");
+		prompter
+			.prompt_text(false, "Password", "Polkit needs access", &[])
+			.await
+			.expect("rofi");
+		prompter
+			.display_text(true, "Polkit needs access", &[])
+			.await
+			.expect("rofi");
+	}
+}