Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8539e0308d | ||
|
|
ef53278466 | ||
|
|
8ecbd504a2 | ||
|
|
3f396b112a |
No files matched your search
@@ -1,4 +1,7 @@
|
|||||||
{
|
{
|
||||||
"version": "0.0.0",
|
"version": "0.1.1",
|
||||||
"sha256": {}
|
"sha256": {
|
||||||
|
"aarch64-apple-darwin": "f7859070acf2b34527a14fa031e0deff8a07540e61a32138b1a5f1b19c4025e4",
|
||||||
|
"x86_64-unknown-linux-musl": "202c05f892e29f16e5446b4e6b51ec24f8fd55ee73fc1359b202fe7bfa8cc28f"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+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
|
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_*
|
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)
|
# 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`)
|
## Allowlist (`allow`)
|
||||||
|
|||||||
@@ -4,8 +4,9 @@
|
|||||||
hx = "hx"
|
hx = "hx"
|
||||||
# home = "/home/me/.hx-work" # own HOME, so the profile keeps its own ~/.hx/auth.json
|
# home = "/home/me/.hx-work" # own HOME, so the profile keeps its own ~/.hx/auth.json
|
||||||
# provider = "anthropic"
|
# provider = "anthropic"
|
||||||
sandbox = false
|
# Default: --sandbox --yolo when the platform has a sandbox (macOS, Linux with bwrap), else --auto.
|
||||||
# yolo = true # only together with sandbox = true
|
# 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.
|
# Shell command run in the worktree after hx; exit 0 = pass.
|
||||||
# gate = "cargo test"
|
# gate = "cargo test"
|
||||||
|
|||||||
@@ -67,6 +67,13 @@ impl Acp {
|
|||||||
.args(["serve", "--acp", "--cwd"])
|
.args(["serve", "--acp", "--cwd"])
|
||||||
.arg(worktree)
|
.arg(worktree)
|
||||||
.args(["--session", id]);
|
.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
|
// same cleared environment as the batch runner: orch's secrets never reach the agent
|
||||||
cmd.env_clear().envs(hx_env(std::env::vars(), p));
|
cmd.env_clear().envs(hx_env(std::env::vars(), p));
|
||||||
if let Some(h) = &p.home {
|
if let Some(h) = &p.home {
|
||||||
|
|||||||
+2
-2
@@ -454,7 +454,7 @@ fn process(
|
|||||||
telemetry: &Path,
|
telemetry: &Path,
|
||||||
) -> Result<state::Run> {
|
) -> Result<state::Run> {
|
||||||
let mut r = run::new_run(t, repo, profile)?;
|
let mut r = run::new_run(t, repo, profile)?;
|
||||||
if p.allow.is_none() && !p.sandbox {
|
if p.allow.is_none() && !p.sandboxed() {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"warning: profile {profile} has no `allow` list and no sandbox: hx may use every tool"
|
"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);
|
let audit = |ev: &str, d: serde_json::Value| policy::audit(&policy::audit_path(), &id, ev, d);
|
||||||
audit(
|
audit(
|
||||||
"run_start",
|
"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)?;
|
run::execute(&mut r, p, t)?;
|
||||||
audit(
|
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 anyhow::{Context, Result, bail};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::path::PathBuf;
|
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.
|
/// [`Profile::add_allow`] on a file.
|
||||||
fn add_allow_at(path: &std::path::Path, entry: &str) -> Result<bool> {
|
fn add_allow_at(path: &std::path::Path, entry: &str) -> Result<bool> {
|
||||||
crate::policy::check_entry(entry)?;
|
crate::policy::check_entry(entry)?;
|
||||||
@@ -33,6 +43,18 @@ fn add_allow_at(path: &std::path::Path, entry: &str) -> Result<bool> {
|
|||||||
Ok(true)
|
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)]
|
#[derive(Deserialize, Debug, Default, Clone)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct Budget {
|
pub struct Budget {
|
||||||
@@ -61,11 +83,11 @@ pub struct Profile {
|
|||||||
/// HOME for hx, so each profile keeps its own `~/.hx/auth.json`.
|
/// HOME for hx, so each profile keeps its own `~/.hx/auth.json`.
|
||||||
pub home: Option<PathBuf>,
|
pub home: Option<PathBuf>,
|
||||||
pub provider: Option<String>,
|
pub provider: Option<String>,
|
||||||
#[serde(default)]
|
/// Passes `--sandbox`. Unset: on when the platform has a sandbox (macOS, Linux with bwrap).
|
||||||
pub sandbox: bool,
|
pub sandbox: Option<bool>,
|
||||||
/// Passes `--yolo`. Only allowed together with `sandbox = true`.
|
/// Passes `--yolo`. Only allowed together with a sandbox. Unset: on whenever the sandbox is on.
|
||||||
#[serde(default)]
|
/// With neither set and no sandbox available hx runs with `--auto`.
|
||||||
pub yolo: bool,
|
pub yolo: Option<bool>,
|
||||||
/// Shell command run in the worktree after hx; exit 0 = pass. None = no gate.
|
/// Shell command run in the worktree after hx; exit 0 = pass. None = no gate.
|
||||||
pub gate: Option<String>,
|
pub gate: Option<String>,
|
||||||
/// Extra hx attempts after a red gate (default 2). 0 = fail straight to needs-human.
|
/// 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) {
|
if p.workers == 0 || p.max_concurrent == Some(0) {
|
||||||
bail!("workers and max_concurrent must be >= 1");
|
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");
|
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)
|
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> {
|
pub fn load(name: &str) -> Result<Self> {
|
||||||
if name.is_empty() || name.contains(['/', '.']) {
|
if name.is_empty() || name.contains(['/', '.']) {
|
||||||
bail!("bad profile name {name:?}");
|
bail!("bad profile name {name:?}");
|
||||||
}
|
}
|
||||||
let path = crate::config_dir()
|
let path = profile_path(name);
|
||||||
.join("profiles")
|
|
||||||
.join(format!("{name}.toml"));
|
|
||||||
let s = match std::fs::read_to_string(&path) {
|
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
|
// 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 => {
|
Err(e) if name == "default" && e.kind() == std::io::ErrorKind::NotFound => {
|
||||||
@@ -153,10 +200,7 @@ impl Profile {
|
|||||||
if name.is_empty() || name.contains(['/', '.']) {
|
if name.is_empty() || name.contains(['/', '.']) {
|
||||||
bail!("bad profile name {name:?}");
|
bail!("bad profile name {name:?}");
|
||||||
}
|
}
|
||||||
let path = crate::config_dir()
|
add_allow_at(&profile_path(name), entry)
|
||||||
.join("profiles")
|
|
||||||
.join(format!("{name}.toml"));
|
|
||||||
add_allow_at(&path, entry)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn account<'a>(&'a self, profile: &'a str) -> &'a str {
|
pub fn account<'a>(&'a self, profile: &'a str) -> &'a str {
|
||||||
@@ -214,10 +258,28 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rejects_yolo_without_sandbox_and_unknown_keys() {
|
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());
|
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]
|
#[test]
|
||||||
fn rejects_path_like_names() {
|
fn rejects_path_like_names() {
|
||||||
assert!(Profile::load("../x").is_err());
|
assert!(Profile::load("../x").is_err());
|
||||||
|
|||||||
+1
-6
@@ -275,12 +275,7 @@ fn run_hx(
|
|||||||
if let Some(s) = session {
|
if let Some(s) = session {
|
||||||
cmd.args(["--session", s]);
|
cmd.args(["--session", s]);
|
||||||
}
|
}
|
||||||
if p.sandbox {
|
cmd.args(p.hx_flags());
|
||||||
cmd.arg("--sandbox");
|
|
||||||
}
|
|
||||||
if p.yolo {
|
|
||||||
cmd.arg("--yolo");
|
|
||||||
}
|
|
||||||
if let Some(prov) = &p.provider {
|
if let Some(prov) = &p.provider {
|
||||||
cmd.args(["--provider", prov]);
|
cmd.args(["--provider", prov]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user