Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4df9c3b01 | ||
|
|
5611ad7e6a | ||
|
|
8539e0308d | ||
|
|
ef53278466 | ||
|
|
8ecbd504a2 | ||
|
|
3f396b112a |
No files matched your search
@@ -54,7 +54,7 @@ command = "python3 /work/adapters/gitea.py"
|
||||
## State-machine sessions and the TUI
|
||||
|
||||
`orch` without a subcommand opens the TUI: sessions overview (`enter` on a row opens the session detail, `esc` goes
|
||||
back; `t` full test output, `d` diff, `l` event transcript, `o` open the worktree in hx). It reads `.hx/orch.db` of the
|
||||
back; `t` full test output, `d` diff, `l` event transcript, `o` open the session in hx, `hx --session sN` in its worktree). It reads `.hx/orch.db` of the
|
||||
current directory. `orch session --repo . --machine task --name NAME [--profile P]` creates a session and runs it.
|
||||
`orch session --repo . --resume s1` continues an unfinished session (for example after a crash or a closed terminal)
|
||||
from its saved state; `--machine`, `--name` and `--after` are not allowed with it. Machines are TOML files in
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
{
|
||||
"version": "0.0.0",
|
||||
"sha256": {}
|
||||
"version": "0.1.2",
|
||||
"sha256": {
|
||||
"aarch64-apple-darwin": "90d260baec2247624a9f718fc5c66a6dfd87e11981a2660ec0caddac4b7aa066",
|
||||
"x86_64-unknown-linux-musl": "6dd90621ba50e40a6efff5ecbd5f870c36ca579ec00030b0e76c4022151871e8"
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -11,7 +11,8 @@ allow = ["read", "write", "edit", "bash:cargo *", "bash:git status"]
|
||||
read_roots = ["/work/shared-docs"] # extra readable dirs besides the worktree
|
||||
env = ["GITEA_*"] # orch env vars hx may see (default: PATH HOME USER LOGNAME SHELL TERM LANG LC_*
|
||||
# TMPDIR CARGO_* RUST* NIX_*, plus HX_HOME only when `home` is unset)
|
||||
sandbox = true # hx --sandbox (bwrap); required for yolo = true
|
||||
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.
|
||||
```
|
||||
|
||||
## Allowlist (`allow`)
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
hx = "hx"
|
||||
# home = "/home/me/.hx-work" # own HOME, so the profile keeps its own ~/.hx/auth.json
|
||||
# provider = "anthropic"
|
||||
sandbox = false
|
||||
# yolo = true # only together with sandbox = true
|
||||
# Default: --sandbox --yolo when the platform has a sandbox (macOS, Linux with bwrap), else --auto.
|
||||
# sandbox = false # force unsandboxed (hx runs with --auto)
|
||||
# yolo = false # sandbox without --yolo; yolo = true needs a sandbox
|
||||
|
||||
# Shell command run in the worktree after hx; exit 0 = pass.
|
||||
# gate = "cargo test"
|
||||
|
||||
@@ -67,6 +67,13 @@ impl Acp {
|
||||
.args(["serve", "--acp", "--cwd"])
|
||||
.arg(worktree)
|
||||
.args(["--session", id]);
|
||||
// the TUI answers permission requests itself, so yolo only when the profile asks for it explicitly
|
||||
let flags = p.hx_flags();
|
||||
cmd.args(
|
||||
flags
|
||||
.iter()
|
||||
.filter(|f| **f != "--yolo" || p.yolo == Some(true)),
|
||||
);
|
||||
// same cleared environment as the batch runner: orch's secrets never reach the agent
|
||||
cmd.env_clear().envs(hx_env(std::env::vars(), p));
|
||||
if let Some(h) = &p.home {
|
||||
|
||||
+2
-2
@@ -454,7 +454,7 @@ fn process(
|
||||
telemetry: &Path,
|
||||
) -> Result<state::Run> {
|
||||
let mut r = run::new_run(t, repo, profile)?;
|
||||
if p.allow.is_none() && !p.sandbox {
|
||||
if p.allow.is_none() && !p.sandboxed() {
|
||||
eprintln!(
|
||||
"warning: profile {profile} has no `allow` list and no sandbox: hx may use every tool"
|
||||
);
|
||||
@@ -463,7 +463,7 @@ fn process(
|
||||
let audit = |ev: &str, d: serde_json::Value| policy::audit(&policy::audit_path(), &id, ev, d);
|
||||
audit(
|
||||
"run_start",
|
||||
serde_json::json!({"profile": profile, "repo": repo, "allow": p.allow, "sandbox": p.sandbox, "yolo": p.yolo, "task": t.id}),
|
||||
serde_json::json!({"profile": profile, "repo": repo, "allow": p.allow, "sandbox": p.sandboxed(), "yolo": p.yolo_on(), "task": t.id}),
|
||||
);
|
||||
run::execute(&mut r, p, t)?;
|
||||
audit(
|
||||
|
||||
+77
-15
@@ -1,9 +1,19 @@
|
||||
//! Profile: `<config>/profiles/NAME.toml`. One profile = one identity (own HOME/auth), budget and gate.
|
||||
//! Profile: `./.hx/profiles/NAME.toml` (repo-local, checked first), else `<config>/profiles/NAME.toml`. One profile = one identity (own HOME/auth), budget and gate.
|
||||
|
||||
use anyhow::{Context, Result, bail};
|
||||
use serde::Deserialize;
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// `./.hx/profiles/NAME.toml` when it exists (repo-local wins), else `<config>/profiles/NAME.toml`.
|
||||
fn profile_path(name: &str) -> PathBuf {
|
||||
let file = format!("{name}.toml");
|
||||
let local = PathBuf::from(".hx/profiles").join(&file);
|
||||
if local.is_file() {
|
||||
return local;
|
||||
}
|
||||
crate::config_dir().join("profiles").join(file)
|
||||
}
|
||||
|
||||
/// [`Profile::add_allow`] on a file.
|
||||
fn add_allow_at(path: &std::path::Path, entry: &str) -> Result<bool> {
|
||||
crate::policy::check_entry(entry)?;
|
||||
@@ -33,6 +43,18 @@ fn add_allow_at(path: &std::path::Path, entry: &str) -> Result<bool> {
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// macOS ships a sandbox (seatbelt); Linux needs `bwrap` on PATH; elsewhere none.
|
||||
pub fn sandbox_available() -> bool {
|
||||
if cfg!(target_os = "macos") {
|
||||
return true;
|
||||
}
|
||||
cfg!(target_os = "linux") && has_bwrap(&std::env::var("PATH").unwrap_or_default())
|
||||
}
|
||||
|
||||
fn has_bwrap(path: &str) -> bool {
|
||||
std::env::split_paths(path).any(|d| d.join("bwrap").is_file())
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Default, Clone)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Budget {
|
||||
@@ -61,11 +83,11 @@ pub struct Profile {
|
||||
/// HOME for hx, so each profile keeps its own `~/.hx/auth.json`.
|
||||
pub home: Option<PathBuf>,
|
||||
pub provider: Option<String>,
|
||||
#[serde(default)]
|
||||
pub sandbox: bool,
|
||||
/// Passes `--yolo`. Only allowed together with `sandbox = true`.
|
||||
#[serde(default)]
|
||||
pub yolo: bool,
|
||||
/// Passes `--sandbox`. Unset: on when the platform has a sandbox (macOS, Linux with bwrap).
|
||||
pub sandbox: Option<bool>,
|
||||
/// Passes `--yolo`. Only allowed together with a sandbox. Unset: on whenever the sandbox is on.
|
||||
/// With neither set and no sandbox available hx runs with `--auto`.
|
||||
pub yolo: Option<bool>,
|
||||
/// Shell command run in the worktree after hx; exit 0 = pass. None = no gate.
|
||||
pub gate: Option<String>,
|
||||
/// Extra hx attempts after a red gate (default 2). 0 = fail straight to needs-human.
|
||||
@@ -123,19 +145,44 @@ impl Profile {
|
||||
if p.workers == 0 || p.max_concurrent == Some(0) {
|
||||
bail!("workers and max_concurrent must be >= 1");
|
||||
}
|
||||
if p.yolo && !p.sandbox {
|
||||
if p.yolo == Some(true) && p.sandbox == Some(false) {
|
||||
bail!("yolo = true requires sandbox = true");
|
||||
}
|
||||
if p.yolo == Some(true) && p.sandbox.is_none() && !sandbox_available() {
|
||||
bail!("yolo = true requires a sandbox, and none is available (Linux needs bwrap)");
|
||||
}
|
||||
Ok(p)
|
||||
}
|
||||
|
||||
/// Whether hx runs sandboxed: explicit setting, else whatever the platform offers.
|
||||
pub fn sandboxed(&self) -> bool {
|
||||
self.sandbox.unwrap_or_else(sandbox_available)
|
||||
}
|
||||
|
||||
/// Whether hx gets `--yolo`: explicit setting, else on with the sandbox.
|
||||
pub fn yolo_on(&self) -> bool {
|
||||
self.yolo.unwrap_or(self.sandboxed()) && self.sandboxed()
|
||||
}
|
||||
|
||||
/// Permission flags for hx: `--sandbox [--yolo]`, or `--auto` when unsandboxed.
|
||||
pub fn hx_flags(&self) -> Vec<&'static str> {
|
||||
let mut f = Vec::new();
|
||||
if self.sandboxed() {
|
||||
f.push("--sandbox");
|
||||
if self.yolo_on() {
|
||||
f.push("--yolo");
|
||||
}
|
||||
} else {
|
||||
f.push("--auto");
|
||||
}
|
||||
f
|
||||
}
|
||||
|
||||
pub fn load(name: &str) -> Result<Self> {
|
||||
if name.is_empty() || name.contains(['/', '.']) {
|
||||
bail!("bad profile name {name:?}");
|
||||
}
|
||||
let path = crate::config_dir()
|
||||
.join("profiles")
|
||||
.join(format!("{name}.toml"));
|
||||
let path = profile_path(name);
|
||||
let s = match std::fs::read_to_string(&path) {
|
||||
// only the implicit profile may be missing; a typo in any other name must still fail
|
||||
Err(e) if name == "default" && e.kind() == std::io::ErrorKind::NotFound => {
|
||||
@@ -153,10 +200,7 @@ impl Profile {
|
||||
if name.is_empty() || name.contains(['/', '.']) {
|
||||
bail!("bad profile name {name:?}");
|
||||
}
|
||||
let path = crate::config_dir()
|
||||
.join("profiles")
|
||||
.join(format!("{name}.toml"));
|
||||
add_allow_at(&path, entry)
|
||||
add_allow_at(&profile_path(name), entry)
|
||||
}
|
||||
|
||||
pub fn account<'a>(&'a self, profile: &'a str) -> &'a str {
|
||||
@@ -214,10 +258,28 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn rejects_yolo_without_sandbox_and_unknown_keys() {
|
||||
assert!(Profile::parse("yolo=true").is_err());
|
||||
assert!(Profile::parse("sandbox=false\nyolo=true").is_err());
|
||||
assert!(Profile::parse("bogus=1").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flags_follow_sandbox_setting() {
|
||||
let f = |s| Profile::parse(s).unwrap().hx_flags();
|
||||
assert_eq!(f("sandbox=true"), ["--sandbox", "--yolo"]);
|
||||
assert_eq!(f("sandbox=true\nyolo=false"), ["--sandbox"]);
|
||||
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()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
assert!(!has_bwrap(dir.to_str().unwrap()));
|
||||
std::fs::write(dir.join("bwrap"), "").unwrap();
|
||||
assert!(has_bwrap(&format!("/nonexistent:{}", dir.display())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_path_like_names() {
|
||||
assert!(Profile::load("../x").is_err());
|
||||
|
||||
+1
-6
@@ -275,12 +275,7 @@ fn run_hx(
|
||||
if let Some(s) = session {
|
||||
cmd.args(["--session", s]);
|
||||
}
|
||||
if p.sandbox {
|
||||
cmd.arg("--sandbox");
|
||||
}
|
||||
if p.yolo {
|
||||
cmd.arg("--yolo");
|
||||
}
|
||||
cmd.args(p.hx_flags());
|
||||
if let Some(prov) = &p.provider {
|
||||
cmd.args(["--provider", prov]);
|
||||
}
|
||||
|
||||
+10
-4
@@ -768,12 +768,18 @@ fn transcript(app: &App, id: &str) -> Pager {
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens hx in the worktree: the TUI steps aside for the time hx runs.
|
||||
fn open_in_hx(term: &mut ratatui::DefaultTerminal, worktree: &str) -> Option<String> {
|
||||
/// Opens hx on the session's conversation in the worktree: the TUI steps aside for the time hx runs.
|
||||
fn open_in_hx(
|
||||
term: &mut ratatui::DefaultTerminal,
|
||||
worktree: &str,
|
||||
session: &str,
|
||||
) -> Option<String> {
|
||||
let hx = crate::profile::Profile::load("default").map_or_else(|_| "hx".into(), |p| p.hx);
|
||||
let mut parts = hx.split_whitespace();
|
||||
let mut cmd = std::process::Command::new(parts.next()?);
|
||||
cmd.args(parts).current_dir(worktree);
|
||||
cmd.args(parts)
|
||||
.args(["--session", session])
|
||||
.current_dir(worktree);
|
||||
ratatui::restore();
|
||||
let res = cmd.status();
|
||||
*term = ratatui::init();
|
||||
@@ -1002,7 +1008,7 @@ fn on_key(
|
||||
}
|
||||
KeyCode::Char('o') => {
|
||||
if let Some(d) = &app.detail
|
||||
&& let Some(err) = open_in_hx(term, &d.worktree.clone())
|
||||
&& let Some(err) = open_in_hx(term, &d.worktree.clone(), &d.id.clone())
|
||||
{
|
||||
app.pager = Some(Pager {
|
||||
title: "open worktree".into(),
|
||||
|
||||
Reference in new issue
Block a user