feat(#2): split harness-internal state from agent-visible state
This commit is contained in:
parent
ce875646a5
commit
ae6d23594d
9 changed files with 113 additions and 23 deletions
|
|
@ -47,6 +47,13 @@ pub async fn run(coord: &Arc<Coordinator>) -> Result<()> {
|
|||
let names = enumerate_agents().await;
|
||||
tracing::info!(count = names.len(), "migration: scanning");
|
||||
|
||||
// Phase 0: move harness-owned files out of state/ into harness/.
|
||||
// Idempotent — rename is a no-op if the source doesn't exist and
|
||||
// the destination already does.
|
||||
for name in &names {
|
||||
migrate_harness_files(name);
|
||||
}
|
||||
|
||||
// Phase 1 + 2: per-agent applied + proposed.
|
||||
for name in &names {
|
||||
if let Err(e) = migrate_applied_repo(name).await {
|
||||
|
|
@ -104,6 +111,35 @@ pub async fn run(coord: &Arc<Coordinator>) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Move harness-owned sqlite/config files out of the agent-visible state dir
|
||||
/// and into the sibling harness dir. Best-effort: logs warnings but never
|
||||
/// fails. Idempotent — each file is only moved if present at the old path
|
||||
/// and absent at the new path.
|
||||
fn migrate_harness_files(name: &str) {
|
||||
const HARNESS_FILES: &[&str] = &[
|
||||
"hyperhive-events.sqlite",
|
||||
"hyperhive-turn-stats.sqlite",
|
||||
"hyperhive-model",
|
||||
];
|
||||
let state_dir = Coordinator::agent_notes_dir(name);
|
||||
let harness_dir = Coordinator::agent_harness_dir(name);
|
||||
if let Err(e) = std::fs::create_dir_all(&harness_dir) {
|
||||
tracing::warn!(%name, error = ?e, "migration: create harness dir failed");
|
||||
return;
|
||||
}
|
||||
for file in HARNESS_FILES {
|
||||
let src = state_dir.join(file);
|
||||
let dst = harness_dir.join(file);
|
||||
if !src.exists() || dst.exists() {
|
||||
continue;
|
||||
}
|
||||
match std::fs::rename(&src, &dst) {
|
||||
Ok(()) => tracing::info!(%name, %file, "migration: moved to harness dir"),
|
||||
Err(e) => tracing::warn!(%name, %file, error = ?e, "migration: move to harness dir failed"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn enumerate_agents() -> Vec<String> {
|
||||
let containers = lifecycle::list().await.unwrap_or_default();
|
||||
containers
|
||||
|
|
|
|||
Loading…
Reference in a new issue