11 Commits
Author SHA1 Message Date
johannes 437f8ec501 Merge pull request 'fix: orchestrated runs honour yolo/auto and work inside the sandbox' (#194) from fix/acp-sandbox-permissions into main
build / version (push) Successful in 11s
build / build (aarch64-apple-darwin) (push) Successful in 6m9s
build / build (x86_64-unknown-linux-musl) (push) Successful in 5m56s
build / release (push) Successful in 36s
Reviewed-on: #194
2026-11-17 15:48:37 +00:00
Johannes KresnerandClaude Opus 5.5 b1ca582d6b fix: orchestrated runs honour yolo/auto and work inside the sandbox
- serve --acp applies --yolo / --auto (or `permissions` in config.toml)
  like the TUI; before, every edit and command went to the orchestrator.
- claude no longer asks to run outside the sandbox. With the sandbox on it
  stays confined; only a stored `claude:unsandboxed` rule or
  --no-claude-sandbox lets it out, and yolo never does.
- The sandbox reads the files the global git config includes and may stat
  $HOME and the directories above allowed paths and includeIf gitdir
  paths (metadata only). git died on both before.
- hx mcp-serve logs a failed start to $TMPDIR/hx-mcp-serve.log; claude
  hides its stderr and only reports "mcp__hx__approve not found".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 16:43:41 +01:00
gitea-actions 37ebf96108 ci: bin.json v0.2.2 2026-11-17 15:16:06 +00:00
johannes 47e184738a Merge pull request 'fix: sandboxed claude can read its macOS login from the keychain' (#193) from fix/claude-sandbox-keychain into main
build / version (push) Successful in 14s
build / build (aarch64-apple-darwin) (push) Successful in 6m18s
build / build (x86_64-unknown-linux-musl) (push) Successful in 5m40s
build / release (push) Successful in 33s
Reviewed-on: #193
2026-11-17 14:53:04 +00:00
Johannes KresnerandClaude Opus 5.5 800bae97d7 fix: sandboxed claude can read its macOS login from the keychain
The seatbelt profile hides $HOME, and claude_extra did not bring back
~/Library/Keychains. On macOS claude keeps its OAuth login there, so a
sandboxed claude failed with "Not logged in" and the only way out was
to let it run unconfined.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 15:47:25 +01:00
gitea-actions 1f4f8aa081 ci: bin.json v0.2.1 2026-11-15 15:35:31 +00:00
johannes 061649cb07 chore: add depencencies to readme and flake
build / version (push) Successful in 11s
build / build (aarch64-apple-darwin) (push) Successful in 6m14s
build / build (x86_64-unknown-linux-musl) (push) Successful in 5m37s
build / release (push) Successful in 26s
2026-11-15 16:13:16 +01:00
gitea-actions 9d8b7dfbd8 ci: bin.json v0.1.16 2026-11-15 11:24:30 +00:00
hermes 179e5cddc7 Merge pull request 'Configurable session storage path' (#192) from sessions-dir into main
build / version (push) Successful in 11s
build / build (aarch64-apple-darwin) (push) Successful in 6m25s
build / build (x86_64-unknown-linux-musl) (push) Successful in 5m27s
build / release (push) Successful in 26s
2026-11-15 11:12:02 +00:00
hermes 05165d7b8f Configurable session storage path (sessions_dir, HX_SESSIONS_DIR, optional sessions_host) 2026-11-15 11:09:09 +00:00
gitea-actions c06381117b ci: bin.json v0.1.15 2026-11-14 13:32:19 +00:00
9 changed files with 295 additions and 95 deletions

No files matched your search

+8
View File
@@ -15,6 +15,12 @@ hx -r # pick a session to resume
hx -r parser # resume the session whose title best matches "parser"
```
## Dependencies
- Rust toolchain (to build from source; `cmake` and `perl` may be needed for the TLS stack).
- `git`.
- Linux: [`bubblewrap`](https://github.com/containers/bubblewrap) (`bwrap`) on `PATH` (`apt install bubblewrap`, `pacman -S bubblewrap`, `dnf install bubblewrap`). The Nix package wraps `hx` so it is provided automatically.
TUI: `enter` send, `shift-enter`/`alt-enter`/`ctrl-j` newline (or end a line with `\` and press enter), `esc` abort, `ctrl-o` expand tool output.
Shift-enter needs a terminal that reports it; hx turns on the kitty keyboard protocol when the terminal answers the probe. Works in ghostty, kitty, WezTerm (`enable_kitty_keyboard = true`), iTerm2, foot, Alacritty 0.13+, Windows Terminal (map shift-enter to `\u001b[13;2u`) and zellij 0.41+. tmux 3.2+ needs `set -g extended-keys on` and `set -g extended-keys-format csi-u`. Elsewhere use `alt-enter`, `ctrl-j` or a trailing `\`. `/keys` prints every key as hx receives it, to see what a terminal or multiplexer (e.g. herdr) passes through. Long input lines wrap; the box grows up to 10 rows.
@@ -44,6 +50,8 @@ Lens findings and affected-test results appear after each turn as a `┄ lens
Config: `~/.hx/config.toml`, overridden per project by `.hx/config.toml`. `hx config init [--project] [--force]` writes a fully commented sample with every key. Example:
**Session storage:** `sessions_dir` in config (or `HX_SESSIONS_DIR`, wins) moves sessions off `~/.hx/sessions`, e.g. to a synced or mounted cloud folder (rclone, Nextcloud, Syncthing). `~` expands; an unwritable path is an error, no silent fallback. `sessions_host = true` prefixes project folders with the host name so machines sharing one folder stay apart. Sessions are append-only JSONL: one hx per session file.
```toml
provider = "claude" # or "codex"
# claude_model = "claude-sonnet-5-5" # default: the account's latest Sonnet
+3 -3
View File
@@ -1,7 +1,7 @@
{
"version": "0.1.14",
"version": "0.2.2",
"sha256": {
"aarch64-apple-darwin": "53a023dc0e8d915cbb62a8c41cb0e8132be68bc1e5b4584b098bbdeb92a6e750",
"x86_64-unknown-linux-musl": "d50e6dcd6af38dc9670b358c9e806d2e000538dd193a2987d4bec7884c9b2d78"
"aarch64-apple-darwin": "84b1789847d5e3b94f903ef5f9cf67336b7b5a2d8801fe9fde68656e5a9167cc",
"x86_64-unknown-linux-musl": "ccff5a974df795a044853a66594424e3176eb9c4a8ef2315176ef2ab3ed95dfc"
}
}
+2
View File
@@ -11,6 +11,8 @@
# compact_at = 900000 # auto-compact at this many tokens; default: 90% of the context window
# max_tokens = 16384
# permissions = "ask" # ask | auto (refuse dangerous calls, run safe ones) | yolo (nothing asks)
# sessions_dir = "~/Nextcloud/hx-sessions" # default ~/.hx/sessions; point at a synced/mounted cloud folder (env HX_SESSIONS_DIR wins)
# sessions_host = false # true: prefix project folders with the host name (machines sharing one sessions_dir)
# mouse = true # wheel scrolling; false keeps terminal text selection
# codemode = false # `codemode` tool: JS scripts that call other tools in a sandbox
# system_prompt = "..." # replaces the built-in prompt; AGENTS.md is still appended
+136 -81
View File
@@ -169,6 +169,10 @@ struct Config {
codemode: Option<bool>,
/// Capture the mouse for wheel scrolling (default true; false = terminal selection works without shift).
mouse: Option<bool>,
/// Where sessions live (default `~/.hx/sessions`); `~` expands. Point at a synced/mounted cloud folder. `HX_SESSIONS_DIR` wins.
sessions_dir: Option<String>,
/// Prefix session folders with the host name, so machines sharing `sessions_dir` stay apart (default false).
sessions_host: Option<bool>,
/// Reuse the last model chosen with /model or /provider (default true).
remember_model: Option<bool>,
/// `/model auto`: tier pins (`fast`, `balanced`, `deep` = model ids) and `down_after`.
@@ -244,6 +248,8 @@ impl Config {
subagents: o.subagents.or(c.subagents),
codemode: o.codemode.or(c.codemode),
mouse: o.mouse.or(c.mouse),
sessions_dir: o.sessions_dir.or(c.sessions_dir),
sessions_host: o.sessions_host.or(c.sessions_host),
remember_model: o.remember_model.or(c.remember_model),
auto: o.auto.or(c.auto),
permissions: o.permissions.or(c.permissions),
@@ -258,44 +264,91 @@ impl Config {
}
}
/// Tool context for the claude sandbox question (set once the agent exists).
/// Tool context of the agent, for the stored "run claude outside the sandbox" rule.
static CLAUDE_CX: std::sync::OnceLock<ToolCtx> = std::sync::OnceLock::new();
/// Answer to "run claude outside the sandbox?" for this process.
static CLAUDE_OUTSIDE: std::sync::Mutex<Option<bool>> = std::sync::Mutex::new(None);
const OUTSIDE_RULE: &str = "claude:unsandboxed";
/// Allowed to leave the sandbox? A stored rule says yes; else the TUI asks (once per run, "always"
/// is stored in `.hx/allow.json`); without a prompt hook (`-p`) the answer is no.
async fn claude_outside() -> bool {
if let Some(v) = *CLAUDE_OUTSIDE.lock().unwrap_or_else(|e| e.into_inner()) {
return v;
}
let ok = match CLAUDE_CX.get() {
Some(cx) if cx.state.permit.get().is_some() => {
hx_core::tool::gate(
cx,
hx_core::permit::Request {
tool: "claude".into(),
detail: "run claude outside the sandbox (its tools then run unconfined)".into(),
rule: OUTSIDE_RULE.into(),
},
)
.await
}
Some(cx) => cx
.state
/// Leave the sandbox only on an explicit, stored rule (`claude:unsandboxed` in `.hx/allow.json`). Never
/// asked and never implied by yolo: yolo is only safe because claude's tools stay confined.
fn claude_outside() -> bool {
CLAUDE_CX.get().is_some_and(|cx| {
cx.state
.allow
.lock()
.unwrap_or_else(|e| e.into_inner())
.allows(&hx_core::permit::Request {
tool: "claude".into(),
detail: String::new(),
rule: OUTSIDE_RULE.into(),
}),
None => false,
.has_rule(OUTSIDE_RULE)
})
}
/// `hx mcp-serve`: lens/LSP, hx's MCP servers and (with a permission socket) `approve` for claude.
async fn mcp_serve() -> Result<()> {
let cwd = std::env::current_dir()?;
let mgr = Arc::new(hx_lens::manager::Manager::new(
cwd.clone(),
hx_lens::manager::default_servers(),
));
let mut reg = hx_core::tool::Registry::default();
reg.add(hx_lens::LspTool::new(mgr.clone()));
let cx = ToolCtx {
cwd: cwd.clone(),
state: Default::default(),
};
*CLAUDE_OUTSIDE.lock().unwrap_or_else(|e| e.into_inner()) = Some(ok);
ok
let sock = std::env::var_os(hx_core::approve::ENV);
if let Some(p) = &sock {
reg.add(hx_core::approve::Approve(p.into()));
// tools run by codemode ask hx for permission like any other
let _ = cx
.state
.permit
.set(hx_core::approve::remote_permit(p.into()));
}
// claude keeps its own tools; hx's MCP servers are added directly, or only through `codemode`
let cfg = Config::load(&cwd)?;
let mut servers =
hx_mcp::config::load(&context::hx_home(), &cwd).map_err(anyhow::Error::msg)?;
// a server entry that is hx itself would spawn mcp-serve recursively
servers.retain(|_, s| !s.args.iter().any(|a| a == "mcp-serve"));
let hub = Arc::new(hx_mcp::Hub::start(servers).await);
if std::env::var_os("HX_CODEMODE").is_some() {
let mut all = hx_tools::registry();
hx_tools::web::register(&mut all, web_search(&cfg));
hub.register(&mut all);
all.add(hx_lens::LspTool::new(mgr.clone()));
reg.add(hx_tools::codemode::Codemode::new(&all));
} else {
hub.register(&mut reg);
}
hx_mcp::serve::serve(
reg,
cx,
tokio::io::BufReader::new(tokio::io::stdin()),
tokio::io::stdout(),
)
.await?;
mgr.shutdown().await;
Ok(())
}
/// Appends a line to `$TMPDIR/hx-mcp-serve.log` (writable inside the sandbox too); best effort.
fn mcp_serve_log(line: &str) {
use std::io::Write;
let p = std::env::temp_dir().join("hx-mcp-serve.log");
if let Ok(mut f) = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open(p)
{
let cwd = std::env::current_dir().unwrap_or_default();
let t = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map_or(0, |d| d.as_secs());
let _ = writeln!(
f,
"{t} pid {} cwd {}: {line}",
std::process::id(),
cwd.display()
);
}
}
/// What `claude` (and its `hx mcp-serve` child) need inside the sandbox: its binary and config,
@@ -327,6 +380,8 @@ fn claude_extra(bin: &str) -> hx_core::sandbox::Extra {
home.join(".claude"),
home.join(".claude.json"),
home.join(".config/claude"),
// macOS keeps claude's login in the login keychain; without it claude says "Not logged in"
home.join("Library/Keychains"),
hx_core::approve::sock_path(),
],
network: true,
@@ -346,11 +401,11 @@ fn claude_extra(bin: &str) -> hx_core::sandbox::Extra {
}
}
/// The `claude` command: sandboxed when the sandbox is on, unless the user let it out.
/// The `claude` command: sandboxed when the sandbox is on, unless claude's sandbox is off or a rule lets it out.
async fn claude_command(bin: String) -> tokio::process::Command {
if hx_core::sandbox::active().is_none()
|| !hx_core::sandbox::claude_sandboxed()
|| claude_outside().await
|| claude_outside()
{
return tokio::process::Command::new(bin);
}
@@ -591,8 +646,33 @@ impl<H: Hook> Hook for ArcHook<H> {
}
}
fn session_dir(cwd: &std::path::Path) -> std::path::PathBuf {
hx_core::session::dir(&context::hx_home(), cwd)
fn session_dir(cwd: &std::path::Path, cfg: &Config) -> Result<std::path::PathBuf> {
let home = context::hx_home();
let root = match std::env::var("HX_SESSIONS_DIR")
.ok()
.or(cfg.sessions_dir.clone())
{
Some(s) if !s.is_empty() => match s.strip_prefix('~') {
Some(r) => std::env::var_os("HOME")
.map(std::path::PathBuf::from)
.unwrap_or_default()
.join(r.trim_start_matches('/')),
None => s.into(),
},
_ => home.join("sessions"),
};
let host = cfg.sessions_host.unwrap_or(false).then(|| {
["HOSTNAME", "HOST", "COMPUTERNAME"]
.iter()
.find_map(|k| std::env::var(k).ok())
.or_else(|| std::fs::read_to_string("/etc/hostname").ok())
.map_or("host".into(), |h| h.trim().to_string())
});
let dir = hx_core::session::dir(&root, cwd, host.as_deref());
// fail loud: a silent fallback would leave sessions off the cloud folder
std::fs::create_dir_all(&dir)
.map_err(|e| anyhow::anyhow!("sessions dir {}: {e}", dir.display()))?;
Ok(dir)
}
#[tokio::main]
@@ -784,51 +864,13 @@ async fn main() -> Result<()> {
return Ok(());
}
Some(Cmd::McpServe) => {
let cwd = std::env::current_dir()?;
let mgr = Arc::new(hx_lens::manager::Manager::new(
cwd.clone(),
hx_lens::manager::default_servers(),
));
let mut reg = hx_core::tool::Registry::default();
reg.add(hx_lens::LspTool::new(mgr.clone()));
let cx = ToolCtx {
cwd: cwd.clone(),
state: Default::default(),
};
let sock = std::env::var_os(hx_core::approve::ENV);
if let Some(p) = &sock {
reg.add(hx_core::approve::Approve(p.into()));
// tools run by codemode ask hx for permission like any other
let _ = cx
.state
.permit
.set(hx_core::approve::remote_permit(p.into()));
// claude starts this and hides its stderr: a failed start shows up only as
// "mcp__hx__approve not found", so the reason goes to a log file as well
let r = mcp_serve().await;
if let Err(e) = &r {
mcp_serve_log(&format!("mcp-serve failed: {e:#}"));
}
// claude keeps its own tools; hx's MCP servers are added directly, or only through `codemode`
let cfg = Config::load(&cwd)?;
let mut servers =
hx_mcp::config::load(&context::hx_home(), &cwd).map_err(anyhow::Error::msg)?;
// a server entry that is hx itself would spawn mcp-serve recursively
servers.retain(|_, s| !s.args.iter().any(|a| a == "mcp-serve"));
let hub = Arc::new(hx_mcp::Hub::start(servers).await);
if std::env::var_os("HX_CODEMODE").is_some() {
let mut all = hx_tools::registry();
hx_tools::web::register(&mut all, web_search(&cfg));
hub.register(&mut all);
all.add(hx_lens::LspTool::new(mgr.clone()));
reg.add(hx_tools::codemode::Codemode::new(&all));
} else {
hub.register(&mut reg);
}
hx_mcp::serve::serve(
reg,
cx,
tokio::io::BufReader::new(tokio::io::stdin()),
tokio::io::stdout(),
)
.await?;
mgr.shutdown().await;
return Ok(());
return r;
}
None => {}
}
@@ -912,7 +954,7 @@ async fn main() -> Result<()> {
}
.unwrap_or_else(|| hx_ai::models::default_for(kind, &models))
});
let dir = session_dir(&cwd);
let dir = session_dir(&cwd, &cfg)?;
let query = cli.resume.as_deref().filter(|q| !q.is_empty());
let path = match (cli.session, cli.r#continue, query) {
_ if acp_id.is_some() => dir.join(format!(
@@ -1152,7 +1194,20 @@ async fn main() -> Result<()> {
});
}
if let Some(id) = acp_id {
// no TUI, no prompts: every permission question goes to the orchestrator
// no TUI, no prompts: every permission question goes to the orchestrator, except what
// --yolo / --auto (or `permissions` in config.toml) settle here, the same as in the TUI
{
let yolo = cli.yolo || cfg.permissions.as_deref() == Some("yolo");
let auto = cli.auto || cfg.permissions.as_deref() == Some("auto");
let mut a = agent
.cx
.state
.allow
.lock()
.unwrap_or_else(|e| e.into_inner());
a.set_yolo(yolo);
a.set_auto(auto && !yolo);
}
let opts = acp::Opts {
session: id,
cwd: cwd.clone(),
+10
View File
@@ -397,6 +397,16 @@ impl Allow {
self.yolo
}
/// Allow everything (not persisted).
pub fn set_yolo(&mut self, on: bool) {
self.yolo = on;
}
/// A stored rule (`.hx/allow.json` or "always" this session), ignoring yolo and edit grants.
pub fn has_rule(&self, rule: &str) -> bool {
self.rules.contains(rule)
}
/// Toggle: allow everything (not persisted); returns the new state.
pub fn toggle_yolo(&mut self) -> bool {
self.yolo = !self.yolo;
+113
View File
@@ -91,6 +91,60 @@ impl Default for Cfg {
}
}
/// Paths named by `path =` in `[include]` / `[includeIf ...]` sections of the global git config, followed
/// into the included files (a few levels), and the `gitdir:` directories of `includeIf` (git resolves
/// them on every start). `~/` expands; relative paths are relative to the including file.
fn git_includes(home: &Path) -> (Vec<PathBuf>, Vec<PathBuf>) {
let mut todo = vec![home.join(".gitconfig"), home.join(".config/git/config")];
let mut found: Vec<PathBuf> = vec![];
let mut dirs: Vec<PathBuf> = vec![];
let mut depth = 0;
while !todo.is_empty() && depth < 5 {
depth += 1;
let mut next = vec![];
for f in todo {
let Ok(text) = std::fs::read_to_string(&f) else {
continue;
};
let mut include = false;
for line in text.lines().map(str::trim) {
if let Some(sec) = line.strip_prefix('[') {
let sec = sec.trim_start();
include = sec.to_ascii_lowercase().starts_with("include");
// [includeIf "gitdir:~/w/"] or "gitdir/i:..."
if let Some(d) = sec
.split_once('"')
.and_then(|(_, r)| r.split_once(':'))
.filter(|(k, _)| k.starts_with("gitdir"))
.and_then(|(_, v)| v.split('"').next())
.and_then(|v| v.strip_prefix("~/"))
{
dirs.push(home.join(d.trim_end_matches("**").trim_end_matches('/')));
}
continue;
}
let Some((k, v)) = line.split_once('=') else {
continue;
};
if !include || !k.trim().eq_ignore_ascii_case("path") {
continue;
}
let v = v.trim().trim_matches('"');
let p = match v.strip_prefix("~/") {
Some(r) => home.join(r),
None => f.parent().unwrap_or(Path::new("/")).join(v),
};
if !found.contains(&p) {
found.push(p.clone());
next.push(p);
}
}
}
todo = next;
}
(found, dirs)
}
#[derive(Debug, Clone)]
pub struct Sandbox {
backend: Backend,
@@ -99,6 +153,8 @@ pub struct Sandbox {
cwd: PathBuf,
rw: Vec<PathBuf>,
ro: Vec<PathBuf>,
/// paths under `$HOME` whose metadata (not content) may be read, e.g. `includeIf "gitdir:~/w"`
meta: Vec<PathBuf>,
env_allow: Vec<String>,
}
@@ -273,6 +329,9 @@ impl Sandbox {
.collect()
};
let mut ro = paths(&cfg.ro);
// files the global git config includes (`[include] path = ...`): without them git fails to start
let (inc, meta) = git_includes(&home);
ro.extend(inc.into_iter().filter(|p| p.exists()).map(|p| canon(&p)));
let skills = crate::context::hx_home().join("skills");
if skills.exists() {
ro.push(canon(&skills));
@@ -284,6 +343,7 @@ impl Sandbox {
cwd: canon(cwd),
rw: paths(&cfg.rw),
ro,
meta,
env_allow: cfg.env_allow.clone(),
})
}
@@ -442,6 +502,28 @@ impl Sandbox {
let w = self.writable();
let readable: Vec<PathBuf> = w.iter().chain(self.ro.iter()).cloned().collect();
p += &format!("(allow file-read* {})\n", list(&readable));
// stat of $HOME and the directories above each allowed path (git resolves paths component by
// component and dies on EPERM); `literal` = these directories only, not what is inside
let mut dirs: Vec<&Path> = readable
.iter()
.chain(&self.meta)
.flat_map(|p| p.ancestors())
.filter(|a| a.starts_with(&self.home))
.collect();
dirs.sort();
dirs.dedup();
let lit = |p: &Path| {
format!(
"(literal \"{}\")",
p.to_string_lossy()
.replace('\\', "\\\\")
.replace('"', "\\\"")
)
};
p += &format!(
"(allow file-read-metadata {})\n",
dirs.iter().map(|d| lit(d)).collect::<Vec<_>>().join(" ")
);
p += &format!("(allow file-write* {})\n", list(&w));
p += "(allow file-write* (literal \"/dev/null\") (literal \"/dev/tty\"))\n";
if self.network {
@@ -455,6 +537,33 @@ impl Sandbox {
mod tests {
use super::*;
#[test]
fn git_includes_follow_include_sections() {
let home = std::env::temp_dir().join(format!("hx-gitinc-{}", std::process::id()));
std::fs::create_dir_all(home.join(".config/delta")).unwrap();
std::fs::write(
home.join(".gitconfig"),
"[user]\n path = /not/an/include\n[include]\n path = ~/.config/delta/theme.gitconfig\n[includeIf \"gitdir:~/w/\"]\n path = \"work.gitconfig\"\n",
)
.unwrap();
std::fs::write(
home.join(".config/delta/theme.gitconfig"),
"[include]\npath = nested\n",
)
.unwrap();
let (got, dirs) = git_includes(&home);
let _ = std::fs::remove_dir_all(&home);
assert_eq!(dirs, [home.join("w")]);
assert_eq!(
got,
[
home.join(".config/delta/theme.gitconfig"),
home.join("work.gitconfig"),
home.join(".config/delta/nested"),
]
);
}
fn sb(backend: Backend, network: bool) -> Sandbox {
Sandbox {
backend,
@@ -463,6 +572,7 @@ mod tests {
cwd: "/home/u/proj".into(),
rw: vec!["/home/u/.cargo/registry".into()],
ro: vec!["/home/u/.cargo".into()],
meta: vec!["/home/u/w/x".into()],
env_allow: vec!["PATH".into(), "LC_*".into()],
}
}
@@ -495,6 +605,9 @@ mod tests {
.unwrap()
);
assert!(p.contains("(allow file-write* (subpath \"/home/u/proj\")"));
assert!(p.contains(
"(allow file-read-metadata (literal \"/home/u\") (literal \"/home/u/.cargo\") (literal \"/home/u/.cargo/registry\") (literal \"/home/u/proj\") (literal \"/home/u/w\") (literal \"/home/u/w/x\"))"
));
assert!(
sb(Backend::Seatbelt, true)
.seatbelt_profile()
+16 -8
View File
@@ -173,14 +173,18 @@ impl Session {
}
}
/// `<hx home>/sessions/<slug of cwd>`.
pub fn dir(home: &Path, cwd: &Path) -> PathBuf {
let slug: String = cwd
.to_string_lossy()
/// `<root>/<slug of cwd>`, with `<host>-` in front when `host` is set (shared roots).
pub fn dir(root: &Path, cwd: &Path, host: Option<&str>) -> PathBuf {
let cwd = cwd.to_string_lossy();
let slug: String = host
.into_iter()
.chain([cwd.trim_matches('/')])
.collect::<Vec<_>>()
.join("/")
.chars()
.map(|c| if c.is_ascii_alphanumeric() { c } else { '-' })
.collect();
home.join("sessions").join(slug.trim_matches('-'))
root.join(slug.trim_matches('-'))
}
/// A fresh, not yet created session file in `dir` (created on first append).
@@ -279,7 +283,7 @@ pub fn list(dir: &Path) -> Vec<Meta> {
v
}
/// Sessions of every project under `<hx home>/sessions`, newest first.
/// Sessions of every project under the sessions root, newest first.
pub fn list_all(root: &Path) -> Vec<Meta> {
let mut v: Vec<Meta> = std::fs::read_dir(root)
.into_iter()
@@ -370,8 +374,12 @@ mod tests {
.collect();
assert_eq!(t, [("newer", "other"), ("fix parser", "proj")]);
assert_eq!(
dir(Path::new("/h"), Path::new("/a/b c")),
Path::new("/h/sessions/a-b-c")
dir(Path::new("/h"), Path::new("/a/b c"), None),
Path::new("/h/a-b-c")
);
assert_eq!(
dir(Path::new("/h"), Path::new("/a/b"), Some("box")),
Path::new("/h/box-a-b")
);
let n = new_path(&proj);
assert!(n.starts_with(&proj) && !n.exists());
+1 -1
View File
@@ -11,7 +11,7 @@
packages = [
pkgs.git
pkgs.stdenv.cc
];
] ++ lib.optional pkgs.stdenv.hostPlatform.isLinux pkgs.bubblewrap;
languages.rust.enable = true;
}
+6 -2
View File
@@ -31,8 +31,12 @@
# ponytail: tests skipped (need git/network); enable when hermetic.
doCheck = false;
# rustls may build aws-lc-sys (cmake) depending on feature set.
nativeBuildInputs = [ pkgs.cmake pkgs.perl ];
nativeBuildInputs = [ pkgs.cmake pkgs.perl ] ++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [ pkgs.makeWrapper ];
dontUseCmakeConfigure = true;
# bubblewrap sandbox runtime dependency (Linux only).
postInstall = pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''
wrapProgram $out/bin/hx --suffix PATH : ${pkgs.lib.makeBinPath [ pkgs.bubblewrap ]}
'';
meta = {
description = "Minimal Rust coding agent using existing subscriptions";
license = pkgs.lib.licenses.unlicense;
@@ -67,7 +71,7 @@
devShells = forAll (pkgs: {
default = pkgs.mkShell {
packages = with pkgs; [ cargo rustc clippy rustfmt rust-analyzer git ];
packages = with pkgs; [ cargo rustc clippy rustfmt rust-analyzer git ] ++ pkgs.lib.optional pkgs.stdenv.hostPlatform.isLinux pkgs.bubblewrap;
};
});
};