Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(tui): a composed command starts a harness on a computer shared with you (#1559)

lingrdfb13d1c4e66c
diff --git a/tui/Cargo.lock b/tui/Cargo.lock
index fe988c021..37fd9de42 100644
--- a/tui/Cargo.lock
+++ b/tui/Cargo.lock
@@ -661,7 +661,7 @@ dependencies = [
[[package]]
name = "harness-tui"
-version = "0.1.40"
+version = "0.1.41"
dependencies = [
"alacritty_terminal",
"base64",
diff --git a/tui/Cargo.toml b/tui/Cargo.toml
index 98babe35c..8dc7024bd 100644
--- a/tui/Cargo.toml
+++ b/tui/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "harness-tui"
-version = "0.1.40"
+version = "0.1.41"
edition = "2024"
[dependencies]
diff --git a/tui/src/shell_context/composition.rs b/tui/src/shell_context/composition.rs
index 9e8813fc0..ae85c1429 100644
--- a/tui/src/shell_context/composition.rs
+++ b/tui/src/shell_context/composition.rs
@@ -568,6 +568,47 @@ pub(super) fn launch(app: &mut App, request: Request) {
} else {
path
};
+ // A computer shared with this account (guest sharing): its owner's daemon answers a guest only what
+ // cli core/guestPolicy.ts lists, which is not fs_list_dir, shell_capabilities or the terminal that runs
+ // shell-launch, so a composed command there was refused GUEST_NOT_ALLOWED. Start it as New Harness does there,
+ // and Desktop: Claude Code or Codex in that folder, on the owner's plans (a model route stays behind).
+ if app.fleet.shares.contains_key(&machine) {
+ if launch.model.is_some() {
+ return reply(app, &request, 1, "On a computer shared with you, the harness runs on its owner's plans: leave the model out.");
+ }
+ if !guest_folder(&path, app.homes.get(&machine).map(String::as_str), app.guest_folders.get(&machine)) {
+ return reply(app, &request, 1, "On a computer shared with you, start in your workspace (~) or a folder its owner shares.");
+ }
+ let mode = guest_mode(&launch.engine, app.options.get("@hn-permission-mode", "", None));
+ let payload = match guest_launch(&launch.engine, &path, &args, &mode) {
+ Ok(p) => p,
+ Err(e) => return reply(app, &request, 1, &e),
+ };
+ app.shell_context.pending = Some(request.clone());
+ let epoch = app.account_epoch;
+ let source_cwd = Some(launch.cwd.clone());
+ let creation = payload["creationId"].clone();
+ app.spawn(async move {
+ // A lost answer is not a launch that failed: the receipt says whether it started (as shell_open_status
+ // does for the remote shell), and `started` closes one this command no longer waits for.
+ match link.rpc("agent_create", payload, Duration::from_secs(180)).await {
+ Err(error) => match link.rpc("agent_create_status", json!({"creationId":creation}), Duration::from_secs(15)).await {
+ Ok(reply) if reply["state"] == "created" => Ok(reply),
+ _ => Err(error),
+ },
+ other => other,
+ }
+ }, move |app, result| {
+ if app.account_epoch != epoch { return }
+ // A refusal recorded on the receipt is `failure`, as New Harness reads it.
+ let result = result.and_then(|v| match v["failure"]["code"].as_str() {
+ Some(code) => Err(crate::daemon::RpcError::new(code, v["failure"]["detail"].as_str().unwrap_or(""))),
+ None => Ok(v),
+ });
+ started(app, request, machine, source, source_cwd, result);
+ });
+ return;
+ }
app.shell_context.pending = Some(request.clone());
let epoch = app.account_epoch;
let local = machine == source.0;
@@ -600,25 +641,61 @@ pub(super) fn launch(app: &mut App, request: Request) {
open_shell(&link2, payload).await
},move |app,result| {
if app.account_epoch!=epoch {return}
- let current=app.shell_context.pending.as_ref().is_some_and(|r|r.id==request.id);
- match result {
- Ok(v)=>if let Some(id)=v.pointer("/agent/id").and_then(Value::as_str) {
- app.fleet.agents.insert((machine.clone(),id.into()),crate::fleet::agent_from(&machine,&v["agent"],None));
- if !current {if let Some(link)=app.link(&machine){link.send("agent_delete",json!({"agentId":id}));}return}
- app.shell_context.pending=None;
- if app.focused()!=Some(request.pane) {
- reply_data(app,&request,0,"",Some(json!({"attached":true,"message":"Agent started. Open it with Ctrl+B s."})));return
- }
- reply_data(app,&request,0,"",Some(json!({"attached":true})));
- let shell=app.shells.remove(&source);app.open_agent(&machine,id,Placement::Replace);if shell{app.shells.insert(source.clone());}
- visiting_shell_launch(app,&source,source_cwd,&machine,id);app.save_sessions();
- }else{finish(app,1,"The computer did not create the agent.")},
- Err(e)=>finish(app,1,&format!("Could not start: {e}")),
- }
+ started(app, request, machine, source, source_cwd, result);
});
});
}
+/// A composed command's agent, created on [machine]: it replaces the shell's view, which it returns to on exit.
+fn started(app: &mut App, request: Request, machine: String, source: (String, String), source_cwd: Option<String>,
+ result: Result<Value, crate::daemon::RpcError>) {
+ let current=app.shell_context.pending.as_ref().is_some_and(|r|r.id==request.id);
+ match result {
+ Ok(v)=>if let Some(id)=v.pointer("/agent/id").and_then(Value::as_str) {
+ app.fleet.agents.insert((machine.clone(),id.into()),crate::fleet::agent_from(&machine,&v["agent"],None));
+ if !current {if let Some(link)=app.link(&machine){link.send("agent_delete",json!({"agentId":id}));}return}
+ app.shell_context.pending=None;
+ if app.focused()!=Some(request.pane) {
+ reply_data(app,&request,0,"",Some(json!({"attached":true,"message":"Agent started. Open it with Ctrl+B s."})));return
+ }
+ reply_data(app,&request,0,"",Some(json!({"attached":true})));
+ let shell=app.shells.remove(&source);app.open_agent(&machine,id,Placement::Replace);if shell{app.shells.insert(source.clone());}
+ visiting_shell_launch(app,&source,source_cwd,&machine,id);app.save_sessions();
+ }else{finish(app,1,"The computer did not create the agent.")},
+ Err(e)=>finish(app,1,&format!("Could not start: {e}")),
+ }
+}
+
+/// The permission mode a guest's harness asks: @hn-permission-mode when [engine] has it (as New Harness reads it), or
+/// auto. One setting serves every engine, and the owner's daemon refuses a mode the engine lacks.
+fn guest_mode(engine: &str, option: Option<String>) -> String {
+ option.filter(|m| crate::new_harness::data::modes(engine).iter().any(|(id, _)| id == m)).unwrap_or_else(|| "auto".into())
+}
+
+/// Whether a guest may start in [path]: its workspace ([home]) or a folder the owner shares, or below one. The owner's
+/// daemon starts anything else in the workspace without saying so. Not loaded yet ([shared] none): its daemon decides.
+fn guest_folder(path: &str, home: Option<&str>, shared: Option<&Vec<(String, bool)>>) -> bool {
+ let Some(shared) = shared else { return true };
+ if path.split('/').any(|part| part == "..") { return false }
+ let under = |root: &str| { let root = root.trim_end_matches('/'); path == root || path.starts_with(&format!("{root}/")) };
+ home.is_some_and(under) || shared.iter().any(|(folder, _)| under(folder))
+}
+
+/// What a composed command starts on a computer shared with this account: Claude Code or Codex in [cwd], on its
+/// owner's plans, as New Harness starts it there. A task typed after the command is its first message; the
+/// engine's own options are not for a guest's harness (cli core/agents/guestCreate.ts builds its command).
+fn guest_launch(engine: &str, cwd: &str, args: &[String], permission_mode: &str) -> Result<Value, String> {
+ if !["claude", "codex"].contains(&engine) { return Err("On a computer shared with you, start Claude Code or Codex.".into()) }
+ if args.iter().any(|a| a.starts_with('-')) {
+ return Err("On a computer shared with you, start it without options: it runs on its owner's plans.".into())
+ }
+ let mut payload = json!({ "engine": engine, "cwd": cwd, "creationId": uuid::Uuid::new_v4().to_string(),
+ "bypassPermission": true, "permissionMode": permission_mode });
+ let task = args.join(" ");
+ if !task.trim().is_empty() { payload["prompt"] = json!(task.trim()) }
+ Ok(payload)
+}
+
/// The composer's `@ computer` rows.
fn host_rows(app: &App) -> Vec<Row> {
// "This computer" stands in for this computer only until it has its own name: once the
@@ -656,6 +733,42 @@ fn host_rows(app: &App) -> Vec<Row> {
mod tests {
use super::*;
+ #[test]
+ fn a_composed_command_on_a_computer_shared_with_you_starts_claude_code_or_codex_as_new_harness_does() {
+ // `claude @<shared computer> :<shared folder>`: one agent_create a guest may send, never shell-launch.
+ let p = guest_launch("claude", "/Users/dee/projects/app", &[], "auto").unwrap();
+ assert_eq!(p["engine"], "claude");
+ assert_eq!(p["cwd"], "/Users/dee/projects/app");
+ assert_eq!(p["permissionMode"], "auto");
+ assert!(uuid::Uuid::parse_str(p["creationId"].as_str().unwrap()).is_ok());
+ for key in ["argv", "grid", "model", "apiConnection", "dsh", "agent"] { assert!(p.get(key).is_none(), "{key} is not for a guest") }
+ // A task typed after it is its first message.
+ assert_eq!(guest_launch("codex", "/w", &["fix the login test".into()], "auto").unwrap()["prompt"], "fix the login test");
+ // Its own options, and other agents, are refused with why.
+ assert!(guest_launch("claude", "/w", &["--model".into(), "opus".into()], "auto").unwrap_err().contains("without options"));
+ assert!(guest_launch("gemini", "/w", &[], "auto").unwrap_err().contains("Claude Code or Codex"));
+ }
+
+ #[test]
+ fn a_guest_launch_asks_only_what_its_engine_has_in_a_folder_it_may_use() {
+ // @hn-permission-mode is one setting for every engine; the daemon refuses a mode its engine lacks.
+ assert_eq!(guest_mode("codex", Some("plan".into())), "auto");
+ assert_eq!(guest_mode("claude", Some("plan".into())), "plan");
+ assert_eq!(guest_mode("claude", None), "auto");
+ // Its workspace or a folder the owner shares (and below them); the owner's daemon would start anything
+ // else in the workspace without saying so.
+ let shared = vec![("/Users/dee/code/app".to_string(), true)];
+ let home = Some("/Users/Shared/HarnessGuests/hg_1/work");
+ for ok in ["/Users/Shared/HarnessGuests/hg_1/work", "/Users/Shared/HarnessGuests/hg_1/work/sub", "/Users/dee/code/app", "/Users/dee/code/app/src"] {
+ assert!(guest_folder(ok, home, Some(&shared)), "{ok}");
+ }
+ for no in ["/Users/dee", "/Users/dee/code/application", "/Users/dee/code/app/../secret", "/etc"] {
+ assert!(!guest_folder(no, home, Some(&shared)), "{no}");
+ }
+ // Not loaded yet: the owner's daemon decides.
+ assert!(guest_folder("/Users/dee", home, None));
+ }
+
#[test]
fn offline_computers_are_listed_dim_after_the_connected_ones_never_disabled() {
let (sink, _) = tokio::sync::mpsc::unbounded_channel();