use super::command::{TrustyCommand, help_text};
use super::http_client::DaemonClient;
use super::result::CommandResult;
mod health;
mod managed;
mod pairing;
mod sessions;
#[cfg(test)]
mod tests;
#[cfg(test)]
pub(crate) use sessions::{MAX_OUTPUT_CHARS, decide_answer, resolve_session, truncate_output};
pub struct CommandExecutor {
client: DaemonClient,
}
impl CommandExecutor {
pub fn new(daemon_url: impl Into<String>) -> Self {
Self {
client: DaemonClient::new(daemon_url),
}
}
pub fn with_client(client: reqwest::Client, daemon_url: impl Into<String>) -> Self {
Self {
client: DaemonClient::with_client(client, daemon_url),
}
}
pub fn from_daemon_client(client: DaemonClient) -> Self {
Self { client }
}
pub fn client(&self) -> &DaemonClient {
&self.client
}
pub async fn execute(&self, cmd: TrustyCommand) -> CommandResult {
match cmd {
TrustyCommand::Help => CommandResult::Help(help_text().to_string()),
TrustyCommand::Alerts => CommandResult::AlertSubscriptions(vec![
"Categories: Permission, Agent".to_string(),
"Memory alerts: enabled".to_string(),
]),
TrustyCommand::Sessions => self.sessions().await,
TrustyCommand::Status { session_id } => self.status(&session_id).await,
TrustyCommand::Approve { session_id } => self.decide(&session_id, true).await,
TrustyCommand::Deny { session_id } => self.decide(&session_id, false).await,
TrustyCommand::Overseer => self.overseer().await,
TrustyCommand::Tmux => self.tmux().await,
TrustyCommand::Projects => self.projects().await,
TrustyCommand::Discover => self.discover().await,
TrustyCommand::Adopt { session } => self.adopt(&session).await,
TrustyCommand::Config { project } => self.config(&project).await,
TrustyCommand::Snapshot { session } => self.snapshot(&session).await,
TrustyCommand::Kill { session_id } => self.kill(&session_id).await,
TrustyCommand::Send { session, prompt } => self.send(&session, &prompt).await,
TrustyCommand::Launch { project, .. } => self.launch(&project).await,
TrustyCommand::Connect { project, .. } => self.connect(&project).await,
TrustyCommand::Doctor => self.doctor().await,
TrustyCommand::Health => self.health().await,
TrustyCommand::CoordinatorChat { message } => self.coordinator_chat(&message).await,
TrustyCommand::ManagedNew {
repo_url,
git_ref,
task,
name_hint,
runtime,
inject_task,
deliverable_id,
force_new,
} => {
self.managed_new(
repo_url,
git_ref,
task,
name_hint,
runtime,
inject_task,
deliverable_id,
force_new,
)
.await
}
TrustyCommand::ManagedList => self.managed_list().await,
TrustyCommand::ManagedFleet => self.managed_fleet().await,
TrustyCommand::ManagedGet { target } => self.managed_get(&target).await,
TrustyCommand::ManagedSend { target, text } => self.managed_send(&target, &text).await,
TrustyCommand::ManagedAnswer { target, answer } => {
self.managed_answer(&target, &answer).await
}
TrustyCommand::ManagedActivity { target } => self.managed_activity(&target).await,
TrustyCommand::ManagedAttachCmd { target } => self.managed_attach_cmd(&target).await,
TrustyCommand::ManagedRuntimeStop { target } => {
self.managed_runtime_stop(&target).await
}
TrustyCommand::ManagedResume { target } => self.managed_resume(&target).await,
TrustyCommand::ManagedDecommission { target } => {
self.managed_decommission(&target).await
}
TrustyCommand::ManagedAdopt {
tmux_name,
cwd,
task,
runtime,
} => self.managed_adopt(tmux_name, cwd, task, runtime).await,
TrustyCommand::Start | TrustyCommand::Pair { code: None } => self.pair_state().await,
TrustyCommand::Pair { code: Some(_) } => {
self.pair_state().await
}
}
}
}