use rho_protocol::{
AgentRuntime as WireRuntime, ChildInfo, ChildRole, JobKind, JobState, JobSummary,
};
use super::{agent_rail::SubagentAttachTarget, session_picker::short_session_id};
use crate::agent::{agent_display_name, session_agent_runtime, AgentRuntime};
pub(super) fn delegated_run(job: &JobSummary) -> Option<SubagentAttachTarget> {
let child = job.child.as_ref()?;
match child.role {
ChildRole::Delegated => Some(SubagentAttachTarget {
run_id: job.run.clone()?,
agent_id: child.agent.clone().unwrap_or_else(|| "agent".into()),
}),
ChildRole::Started | ChildRole::WorkflowNode | ChildRole::Unknown => None,
_ => None,
}
}
pub(super) fn title(job: &JobSummary) -> String {
let titled = |title: &Option<String>| title.clone().filter(|title| !title.is_empty());
job.live
.as_ref()
.and_then(|live| titled(&live.title))
.or_else(|| job.child.as_ref().and_then(|child| titled(&child.title)))
.unwrap_or_else(|| untitled(job))
}
fn untitled(job: &JobSummary) -> String {
let named = |kind: &str, id: Option<&str>| match id {
Some(id) => format!("{kind} {}", short_session_id(id)),
None => format!("{kind} {}", short_session_id(job.id.as_str())),
};
match job.kind {
JobKind::Session => named("session", job.session.as_ref().map(|id| id.as_str())),
JobKind::Subagent => named("subagent", job.run.as_deref()),
JobKind::Workflow => named("workflow", job.workflow_run.as_deref()),
_ => named("job", None),
}
}
pub(super) fn needs_input(job: &JobSummary) -> bool {
job.state == JobState::WaitingForInput
|| job
.live
.as_ref()
.is_some_and(|live| !live.inputs.is_empty())
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub(super) struct ChildAgent {
id: String,
engine: Option<WireRuntime>,
}
impl ChildAgent {
pub(super) fn of(child: &ChildInfo) -> Option<Self> {
Some(Self {
id: child.agent.clone()?,
engine: child.engine,
})
}
pub(super) fn label(&self) -> Option<String> {
let runtime = match self.engine.map(AgentRuntime::try_from) {
None | Some(Ok(AgentRuntime::Rho)) => None,
Some(Ok(runtime @ (AgentRuntime::ClaudeCli | AgentRuntime::Antigravity))) => {
Some(runtime.display_name())
}
Some(Err(_)) => Some("another runtime"),
};
match runtime {
Some(runtime) if session_agent_runtime(&self.id).is_none() => {
Some(format!("{} ({runtime})", self.id))
}
Some(_) | None => agent_display_name(&self.id).map(str::to_owned),
}
}
}
#[cfg(test)]
#[path = "daemon_job_tests.rs"]
mod tests;