add a default archetype, preselected by the clients
This commit is contained in:
parent
a74d23d313
commit
8f7c45d40f
1 changed files with 253 additions and 47 deletions
|
|
@ -590,6 +590,22 @@ struct AgentCreateArgs {
|
|||
/// hive roster and names the known hives if it misses.
|
||||
#[arg(long, value_name = "HIVE")]
|
||||
hive: String,
|
||||
/// Archetype of the `hyperhive` source to build the agent from.
|
||||
///
|
||||
/// `default` is the default config with no config repo; turn the agent
|
||||
/// into a custom one later when it needs a repo. The hive's `hyperhive`
|
||||
/// input must know the archetype, or the agent's build fails.
|
||||
#[arg(
|
||||
long,
|
||||
value_name = "NAME",
|
||||
default_value = "default",
|
||||
conflicts_with = "custom"
|
||||
)]
|
||||
archetype: String,
|
||||
/// Create a custom agent: it gets an `agent-configs/<name>` repo and no
|
||||
/// archetype.
|
||||
#[arg(long)]
|
||||
custom: bool,
|
||||
/// A text file the agent's `AGENTS.md` starts with.
|
||||
///
|
||||
/// The agent writes it on its first start, and only when it has no
|
||||
|
|
@ -606,6 +622,13 @@ struct AgentCreateArgs {
|
|||
controller_socket: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl AgentCreateArgs {
|
||||
/// The archetype to send: `--archetype`, or none for `--custom`.
|
||||
fn requested_archetype(&self) -> Option<&str> {
|
||||
(!self.custom).then_some(self.archetype.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
struct AgentMintForgeTokenArgs {
|
||||
/// Name of an agent that already exists.
|
||||
|
|
@ -838,8 +861,15 @@ fn main() -> Result<()> {
|
|||
Verb::Agent {
|
||||
command: AgentVerb::Create(args),
|
||||
} => {
|
||||
let archetype = args.requested_archetype().map(str::to_owned);
|
||||
let target = remote.target(args.controller_socket)?;
|
||||
agent::create(&target, &args.name, &args.hive, args.agents_md.as_deref())
|
||||
agent::create(
|
||||
&target,
|
||||
&args.name,
|
||||
&args.hive,
|
||||
archetype.as_deref(),
|
||||
args.agents_md.as_deref(),
|
||||
)
|
||||
}
|
||||
// Same socket-resolution reasoning as `Create` above.
|
||||
Verb::Agent {
|
||||
|
|
@ -1729,6 +1759,30 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn agent_create_defaults_to_the_default_archetype_and_custom_sends_none() {
|
||||
let args = |extra: &[&str]| {
|
||||
let base = ["swarmctl", "agent", "create", "scribe", "--hive", "alpha"];
|
||||
Cli::try_parse_from(base.iter().chain(extra))
|
||||
};
|
||||
let archetype_of = |cli: Cli| {
|
||||
let Verb::Agent {
|
||||
command: AgentVerb::Create(args),
|
||||
} = cli.command
|
||||
else {
|
||||
panic!("expected `agent create`");
|
||||
};
|
||||
args.requested_archetype().map(str::to_owned)
|
||||
};
|
||||
assert_eq!(archetype_of(args(&[]).unwrap()).as_deref(), Some("default"));
|
||||
assert_eq!(
|
||||
archetype_of(args(&["--archetype", "reviewer"]).unwrap()).as_deref(),
|
||||
Some("reviewer")
|
||||
);
|
||||
assert_eq!(archetype_of(args(&["--custom"]).unwrap()), None);
|
||||
assert!(args(&["--custom", "--archetype", "reviewer"]).is_err());
|
||||
}
|
||||
|
||||
/// The socket is optional on the command line because the nix wrapper
|
||||
/// sets `SWARM_CONTROLLER_SOCKET`; `path_from` is what turns an absent
|
||||
/// pair into an error rather than a guess.
|
||||
|
|
|
|||
Loading…
Reference in a new issue