Watch
0
0
Fork
You've already forked hyperhive
0

controller: turn an archetype agent into a custom one

This commit is contained in:
atlas 2026-11-01 12:02:38 +01:00 • committed by mara
commit 0737798d78

View file

@ -807,22 +807,38 @@ impl Client {
tracing::debug!(%repo, "swarm forge: config already seeded");
return Ok(());
}
let files = vec![
ChangeFileOperation {
content: Some(base64_encode(&initial_agent_nix(agent))),
self.create_config_files(
repo,
&[
("agent.nix", initial_agent_nix(agent)),
("flake.nix", initial_flake_nix().to_owned()),
],
"swarm-controller: seed agent config",
)
.await?;
tracing::info!(%repo, %agent, "swarm forge: seeded agent.nix + flake.nix");
Ok(())
}
/// Commit `files` (path, content) to `repo`'s default branch in one
/// `repo_change_files` call, creating each path. No presence check: a
/// path that already exists makes the forge refuse the whole commit.
pub(crate) async fn create_config_files(
&self,
repo: &str,
files: &[(&str, String)],
message: &str,
) -> Result<()> {
let files: Vec<ChangeFileOperation> = files
.iter()
.map(|(path, content)| ChangeFileOperation {
content: Some(base64_encode(content)),
from_path: None,
operation: ChangeFileOperationOperation::Create,
path: "agent.nix".to_owned(),
path: (*path).to_owned(),
sha: None,
},
ChangeFileOperation {
content: Some(base64_encode(initial_flake_nix())),
from_path: None,
operation: ChangeFileOperationOperation::Create,
path: "flake.nix".to_owned(),
sha: None,
},
];
})
.collect();
self.api
.call(|api| {
api.repo_change_files(
@ -835,7 +851,7 @@ impl Client {
dates: None,
files: files.clone(),
force_overwrite_new_branch: None,
message: Some("swarm-controller: seed agent config".to_owned()),
message: Some(message.to_owned()),
new_branch: None,
signoff: None,
},
@ -843,8 +859,7 @@ impl Client {
.into_future()
})
.await
.with_context(|| format!("seed config files in {CONFIG_ORG}/{repo}"))?;
tracing::info!(%repo, %agent, "swarm forge: seeded agent.nix + flake.nix");
.with_context(|| format!("commit config files to {CONFIG_ORG}/{repo}"))?;
Ok(())
}