refactor: per-agent state paths (/agents/{label}/state), centralize in paths.rs

This commit is contained in:
damocles 2026-05-16 14:16:25 +02:00
parent a82009cf8c
commit a6d1464071
10 changed files with 86 additions and 56 deletions

View file

@ -743,25 +743,18 @@ fn set_nspawn_flags(
let path = format!("/etc/nixos-containers/{container}.conf");
let original = std::fs::read_to_string(&path).with_context(|| format!("read {path}"))?;
// Compute mount points: for sub-agents, bind /agents/<name>/ with state+claude inside.
// For manager, use the old structure with /root/.claude and /state.
let agent_mount_base = if container == MANAGER_NAME {
None // Manager has no agent-specific mount
// Compute the in-container state mount point. Sub-agents get
// /agents/<name>/state; the manager keeps the legacy /state path.
// Claude credentials always land at /root/.claude for all agents so
// the `claude` CLI (which reads $HOME/.claude) finds them without any
// HOME override.
let notes_mount = if container == MANAGER_NAME {
CONTAINER_NOTES_MOUNT.to_owned()
} else {
// Strip the "h-" prefix from container name to get agent name
let agent_name = container.strip_prefix(AGENT_PREFIX).unwrap_or(container);
Some(format!("/agents/{agent_name}"))
};
// For sub-agents: bind /agents/<name>/ containing state and claude
// For manager: use old /state and /root/.claude mounts
let (notes_mount, claude_mount) = if let Some(ref mount_base) = agent_mount_base {
// Sub-agent: state at /agents/<name>/state, claude at /agents/<name>/claude
(format!("{mount_base}/state"), format!("{mount_base}/claude"))
} else {
// Manager: keep current structure
(CONTAINER_NOTES_MOUNT.to_owned(), CONTAINER_CLAUDE_MOUNT.to_owned())
format!("/agents/{agent_name}/state")
};
let claude_mount = CONTAINER_CLAUDE_MOUNT;
let mut binds = format!(
"--bind={runtime}:{CONTAINER_RUNTIME_MOUNT} --bind={claude}:{claude_mount} --bind={notes}:{notes_mount} --bind={shared}:{CONTAINER_SHARED_MOUNT}",