use super::fixture::Fixture;
use super::git::run_git;
use std::fs;
impl Fixture {
pub(crate) fn build_agent(&self, conv_id: &str, user_message: &str) {
let wt = self.path.join("agents").join(conv_id);
let wt_str = wt.to_string_lossy().to_string();
let branch = format!("agents/{conv_id}");
run_git(
&self.repo,
&[
"worktree",
"add",
"-q",
"-b",
branch.as_str(),
wt_str.as_str(),
"config/default",
],
);
fs::write(wt.join("goal.md"), user_message).unwrap();
fs::write(wt.join("soul.md"), "you are a tester\n").unwrap();
run_git(&wt, &["rm", "-q", "--ignore-unmatch", "version"]);
run_git(&wt, &["add", "goal.md", "soul.md"]);
run_git(
&wt,
&["commit", "-q", "-m", &format!("dispatch [{conv_id}]")],
);
let cmp_id = format!("{conv_id}-c");
let cmp_branch = format!("agents/{cmp_id}");
let cmp_wt = self.path.join("agents").join(&cmp_id);
let cmp_str = cmp_wt.to_string_lossy().to_string();
run_git(
&self.repo,
&[
"worktree",
"add",
"-q",
"-b",
cmp_branch.as_str(),
cmp_str.as_str(),
branch.as_str(),
],
);
fs::create_dir_all(cmp_wt.join("summary")).unwrap();
fs::write(
cmp_wt.join("summary/001.md"),
format!("conversation {conv_id}: pong\n"),
)
.unwrap();
run_git(&cmp_wt, &["add", "summary/001.md"]);
run_git(
&cmp_wt,
&[
"commit",
"-q",
"-m",
&format!("compaction: terminal summary [{conv_id}]"),
],
);
run_git(&wt, &["merge", "--no-ff", "-q", "--no-edit", &cmp_branch]);
run_git(&self.repo, &["worktree", "remove", cmp_str.as_str()]);
run_git(&self.repo, &["branch", "-q", "-D", &cmp_branch]);
self.write_step_record(conv_id, user_message);
}
pub(crate) fn name_agent(&self, conv_id: &str, name: &str) {
let wt = self.path.join("agents").join(conv_id);
if !wt.exists() {
let wt_str = wt.to_string_lossy().to_string();
run_git(
&self.repo,
&[
"worktree",
"add",
"-q",
&wt_str,
&format!("agents/{conv_id}"),
],
);
}
fs::write(wt.join("name"), format!("{name}\n")).unwrap();
run_git(&wt, &["add", "name"]);
run_git(&wt, &["commit", "-q", "--allow-empty", "-m", "settle name"]);
}
pub(crate) fn mark_ref(&self, refname: &str) {
run_git(&self.repo, &["update-ref", refname, "config/default"]);
}
pub(crate) fn hold_ref(&self, agent_id: &str, value: &str) {
let staged = self.path.join(".hold-mark");
fs::write(&staged, value).unwrap();
let oid = super::git::git_out(
&self.repo,
&["hash-object", "-w", "--", &staged.to_string_lossy()],
);
run_git(
&self.repo,
&["update-ref", &format!("refs/litany/held/{agent_id}"), &oid],
);
}
pub(crate) fn build_child(&self, parent_id: &str, child_id: &str) {
let wt = self.path.join("agents").join(child_id);
let wt_str = wt.to_string_lossy().to_string();
let branch = format!("agents/{child_id}");
run_git(
&self.repo,
&[
"worktree",
"add",
"-q",
"-b",
branch.as_str(),
wt_str.as_str(),
&format!("agents/{parent_id}"),
],
);
let file = format!("{child_id}.md");
fs::write(wt.join(&file), "child work\n").unwrap();
run_git(&wt, &["add", file.as_str()]);
run_git(
&wt,
&["commit", "-q", "-m", &format!("dispatch [{child_id}]")],
);
run_git(&self.repo, &["worktree", "remove", wt_str.as_str()]);
}
}