refuse allow with claude_cli instead of forcing the direct provider

This commit is contained in:
hermes committed 2026-11-13 19:14:31 +00:00
1 parent 2ff8abe7a3
commit 2751bcf27b
7 files changed
+60 -34

No files matched your search

+3 -6
View File
@@ -8,8 +8,8 @@
//! must stay inside the worktree or `read_roots`. Hard rules apply to every allowed call: no `git push`
//! (publishing is the sink's job), no secret-looking paths, file tools stay in the worktree (reads may also
//! use `read_roots`), writes never touch `.git` or `.hx` (guard config).
//! With `allow` set orch writes `claude_cli = false` into the generated worktree config: the `claude_cli`
//! provider executes tools inside the `claude` binary, invisible to hx' event bus, so it cannot be guarded.
//! Not enforceable with hx' `claude_cli` provider: the `claude` binary runs its own tools, invisible to hx' event
//! bus. `run::execute` refuses such a run up front (see `report::provider_mode`) instead of running it unguarded.
//! ponytail: plain `bash` is not confined (a shell cannot be parsed reliably); use `sandbox = true` for that.
use anyhow::{Result, bail};
@@ -294,10 +294,7 @@ pub fn install(run: &str, wt: &Path, allow: &[String], read_roots: &[PathBuf]) -
}
std::fs::create_dir_all(cfg.parent().unwrap())?;
let exe = std::env::current_exe()?.to_string_lossy().into_owned();
// `claude_cli = false`: with the claude_cli provider the `claude` binary runs its own tools and hx emits no
// tool_call events, so neither the guard nor the stream check would see anything. The project config beats
// ~/.hx/config.toml, so this holds even when the profile's home enables claude_cli.
let ext = toml::to_string(&json!({"claude_cli": false, "extensions": [{
let ext = toml::to_string(&json!({"extensions": [{
"command": [exe, "guard", pp.to_string_lossy()], "timeout_secs": 10}]}))?;
std::fs::write(cfg, format!("{MARK}\n{ext}"))?;
Ok(pol)
+3 -6
View File
@@ -47,17 +47,14 @@ fn unknown() -> String {
"unknown".into()
}
/// The mode hx will use for this profile and worktree, derived the way hx decides it: `allow` forces direct (see
/// policy.rs); else `claude_cli` in the worktree/home config; else auto = on when the claude binary starts and no
/// HX_BASE_URL is set. ponytail: ignores hx' remembered last provider (`last.json`), so a profile without
/// The mode hx will use for this profile and worktree, derived the way hx decides it: `provider = "codex"`; else
/// `claude_cli` in the worktree/home config; else auto = on when the claude binary starts and no HX_BASE_URL is
/// set (HX_BASE_URL only counts when the profile passes it on, like hx sees it). ponytail: ignores hx' remembered last provider (`last.json`), so a profile without
/// `provider` that hx routes to codex is still labelled claude_cli; set `provider` in profiles you compare.
pub fn provider_mode(p: &Profile, wt: &Path) -> String {
if p.provider.as_deref() == Some("codex") {
return "codex".into();
}
if p.allow.is_some() {
return "direct".into();
}
let home = p.home.clone().map(|h| h.join(".hx"));
let explicit = [
Some(wt.join(".hx")),
+10
View File
@@ -112,6 +112,8 @@ fn usage_total(u: &Value) -> u64 {
.sum()
}
const REFUSE_CLAUDE_CLI: &str = "`allow` cannot be enforced with hx' claude_cli provider (the claude binary runs its own tools, hx sees no tool calls). Remove `allow` and use `sandbox = true`, or set `claude_cli = false` in the profile's hx config to use the direct provider.";
/// hx surfaces provider rejections as `api 429: ...`; also match the usual wording.
fn is_rate_limit(reason: &str) -> bool {
let r = reason.to_lowercase();
@@ -169,6 +171,14 @@ pub fn execute(r: &mut Run, p: &Profile, task: &Task) -> Result<()> {
return Ok(());
}
let mut log = std::fs::File::create(log_path(&r.id))?;
if p.allow.is_some() && crate::report::provider_mode(p, &r.worktree) == "claude_cli" {
// never run "guarded" without a guard: the claude binary's tools are invisible to hx and orch
writeln!(log, "{REFUSE_CLAUDE_CLI}")?;
r.status = Status::NeedsHuman;
r.reason = Some(format!("policy: {REFUSE_CLAUDE_CLI}"));
r.ended = Some(now());
return r.save();
}
let mut prompt = body.clone();
let mut session: Option<String> = None;
loop {