diff --git a/docs/safety.md b/docs/safety.md index 349c32e..62767c8 100644 --- a/docs/safety.md +++ b/docs/safety.md @@ -13,6 +13,7 @@ env = ["GITEA_*"] # orch env vars hx may see (default: PATH HOME # TMPDIR CARGO_* RUST* NIX_*, plus HX_HOME only when `home` is unset) sandbox = true # hx --sandbox (bwrap/seatbelt). Default: on when available (macOS, Linux with bwrap), # together with --yolo (yolo = false opts out). Unsandboxed hx runs with --auto. + # Interactive sessions (TUI, orch up) with yolo = false get --sandbox --auto. ``` ## Allowlist (`allow`) diff --git a/src/acp.rs b/src/acp.rs index 0151b9b..3e0075f 100644 --- a/src/acp.rs +++ b/src/acp.rs @@ -64,13 +64,7 @@ impl Acp { let mut parts = p.hx.split_whitespace(); let mut cmd = Command::new(parts.next().context("empty hx command")?); // sandbox and permission flags are options of the root command, so they go before `serve` - // the TUI answers permission requests itself, so yolo only when the profile asks for it explicitly - let flags = p.hx_flags(); - cmd.args(parts).args( - flags - .iter() - .filter(|f| **f != "--yolo" || p.yolo == Some(true)), - ); + cmd.args(parts).args(p.acp_flags()); cmd.args(["serve", "--acp", "--cwd"]) .arg(worktree) .args(["--session", id]); diff --git a/src/profile.rs b/src/profile.rs index 80007ef..520e765 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -178,6 +178,16 @@ impl Profile { f } + /// Flags for an interactive (ACP) session: like `hx_flags` (sandbox brings yolo, no sandbox falls back to + /// `--auto`), but a sandbox with `yolo = false` gets `--auto` too, so not every edit asks. + pub fn acp_flags(&self) -> Vec<&'static str> { + let mut f = self.hx_flags(); + if f == ["--sandbox"] { + f.push("--auto"); + } + f + } + /// A profile file named by its path (an issue session's profile in its worktree). pub fn load_path(path: &std::path::Path) -> Result { let s = @@ -277,6 +287,15 @@ mod tests { assert_eq!(f("sandbox=false"), ["--auto"]); } + #[test] + fn acp_flags_yolo_with_sandbox_else_auto() { + let f = |s| Profile::parse(s).unwrap().acp_flags(); + assert_eq!(f("sandbox=true"), ["--sandbox", "--yolo"]); + assert_eq!(f("sandbox=true\nyolo=true"), ["--sandbox", "--yolo"]); + assert_eq!(f("sandbox=true\nyolo=false"), ["--sandbox", "--auto"]); + assert_eq!(f("sandbox=false"), ["--auto"]); + } + #[test] fn bwrap_lookup_scans_path() { let dir = std::env::temp_dir().join(format!("orch-bwrap-{}", std::process::id()));