use crate::prompt::notice::notice;
use crate::prompt::{Deps, Error, WORKER_ROLE};
use crate::workspace;
use std::path::Path;
pub(in crate::prompt) enum ConfigSource<'a> {
Fork(&'a str),
Agent(&'a str),
}
pub(super) fn agent_role(
workspace: &Path,
source: &ConfigSource<'_>,
deps: &Deps<'_>,
) -> Result<String, Error> {
match source {
ConfigSource::Fork(_) => Ok(WORKER_ROLE.to_string()),
ConfigSource::Agent(agent_id) => Ok(crate::prompt::role::derive(
&workspace::repo_git(workspace),
&workspace::agent_ref(agent_id),
agent_id,
deps.git,
)?
.unwrap_or_else(|| WORKER_ROLE.to_string())),
}
}
pub(super) fn config_commit(
workspace: &Path,
source: &ConfigSource<'_>,
deps: &Deps<'_>,
) -> Result<String, Error> {
let rev = match source {
ConfigSource::Fork(fork_point) => (*fork_point).to_owned(),
ConfigSource::Agent(agent_id) => workspace::agent_ref(agent_id),
};
let resolved =
workspace::current_config::current_config(workspace, &rev, deps.git).map_err(|source| {
Error::Git {
op: "followed config",
source,
}
})?;
if let Some(tips) = resolved.held() {
notice!(
"{tips} diverged config lineages reach [{rev}] — control resolves its fork \
commit until `litany retarget` settles the lineage (ARCH §2.2)",
);
}
Ok(resolved.commit().to_string())
}