feat(#2): split harness-internal state from agent-visible state

This commit is contained in:
damocles 2026-06-01 12:52:22 +02:00 committed by mara
commit ae6d23594d
9 changed files with 113 additions and 23 deletions

View file

@ -755,12 +755,21 @@ pub fn ensure_claude_dir(claude_dir: &Path) -> Result<()> {
}
/// Public for the `InitConfig` approval path in `actions.rs` which seeds
/// dirs without calling the full `spawn`.
/// dirs without calling the full `spawn`. Also creates the sibling `harness/`
/// dir so the first harness startup can write its sqlite files immediately.
pub fn ensure_state_dir(notes_dir: &Path) -> Result<()> {
if !notes_dir.exists() {
std::fs::create_dir_all(notes_dir)
.with_context(|| format!("create {}", notes_dir.display()))?;
}
// Harness dir is a sibling of the agent-visible state dir.
if let Some(parent) = notes_dir.parent() {
let harness_dir = parent.join("harness");
if !harness_dir.exists() {
std::fs::create_dir_all(&harness_dir)
.with_context(|| format!("create {}", harness_dir.display()))?;
}
}
Ok(())
}
@ -1086,15 +1095,30 @@ fn set_nspawn_flags(
shared = HOST_SHARED_ROOT,
);
// Per-agent state at `/agents/<container>/state`. Skipped for
// the manager — the `/agents` bind below already exposes its
// own state (along with every sub-agent's).
// Per-agent state + harness dirs. Skipped for the manager —
// the `/agents` bind below already exposes both (along with
// every sub-agent's). For regular agents the harness dir is
// the sibling of notes_dir (same parent, "harness" subdir).
if container != MANAGER_NAME {
let _ = write!(
binds,
" --bind={notes}:/agents/{agent_name}/state",
notes = notes_dir.display(),
);
// Harness dir: sibling of notes_dir under the agent state root.
// systemd-nspawn refuses to start when the bind source is missing;
// ensure_state_dir already creates it, but be defensive here.
if let Some(parent) = notes_dir.parent() {
let harness_dir = parent.join("harness");
if !harness_dir.exists() {
let _ = std::fs::create_dir_all(&harness_dir);
}
let _ = write!(
binds,
" --bind={harness}:/agents/{agent_name}/harness",
harness = harness_dir.display(),
);
}
}
if container == MANAGER_NAME {
// systemd-nspawn refuses to start a container whose bind