controller: turn an archetype agent into a custom one
This commit is contained in:
parent
8a7f254c74
commit
0737798d78
1 changed files with 1008 additions and 44 deletions
|
|
@ -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(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue