use std::{
num::NonZeroUsize,
path::{Path, PathBuf},
};
use rho_sdk::{SessionId, SessionOptions};
use super::{
agent_binding::{AgentInvocation, AgentRole, BoundAgent},
session_assembly::{
assemble_session, ApprovalInputs, BuiltSession, HookStart, ModelOwner, SessionApproval,
SessionAssemblyOptions, SignIn,
},
tools_prompt::{ToolSourceAttach, ToolSourceLoad},
};
use crate::{
added_dirs::AddedDirs,
agent::{read_only_tools, AgentCapabilities},
diagnostics::RuntimeDiagnostics,
permission::PermissionMode,
session_environment::SessionEnvironment,
tools::mcp::{config::McpConfig, McpAuthorizationMode, McpElicitationSupport},
};
pub(super) struct ReadOnlySession<'a> {
pub(super) agent: &'a BoundAgent,
pub(super) config_path: PathBuf,
pub(super) cwd: &'a Path,
pub(super) added_dirs: &'a AddedDirs,
pub(super) environment: SessionEnvironment,
pub(super) max_steps: NonZeroUsize,
pub(super) usage_purpose: &'static str,
pub(super) parent: SessionId,
}
pub(super) fn invocation() -> AgentInvocation {
AgentInvocation {
role: AgentRole::Delegated,
available_tools: AgentCapabilities::new(read_only_tools()),
}
}
pub(super) async fn assemble(session: ReadOnlySession<'_>) -> anyhow::Result<BuiltSession> {
let ReadOnlySession {
agent,
config_path,
cwd,
added_dirs,
environment,
max_steps,
usage_purpose,
parent,
} = session;
let mut config = agent
.rho_config()
.ok_or_else(|| anyhow::anyhow!("agent {} does not run on rho", agent.id()))?
.clone();
config.mcp = McpConfig::default();
config.permission_mode = PermissionMode::Plan;
let diagnostics = RuntimeDiagnostics::new(&config);
let assembled = assemble_session(SessionAssemblyOptions {
config: &config,
config_path,
cwd,
no_system_prompt: false,
no_tools: false,
no_subagents: true,
questionnaire_enabled: false,
surfaces: None,
pull_requests: None,
mcp_elicitation: McpElicitationSupport::Unavailable,
tool_source_attach: ToolSourceAttach::None,
tool_source_load: ToolSourceLoad::Inline,
hook_start: HookStart::Gate,
sign_in: SignIn::Required,
model_owner: ModelOwner::InternalAgent,
mcp_authorization: McpAuthorizationMode::NonInteractive,
diagnostics: &diagnostics,
agent,
max_steps: Some(max_steps),
usage_purpose,
usage_parent_session_id: Some(parent),
hook_host_labels: rho_sdk::hooks::HookHostLabels::new(),
added_dirs,
environment,
subagent_pool: crate::app::subagent_pool::SubagentPool::Own,
process_keep_warm: crate::tools::process::KeepWarmOffer::Hidden,
extend_tools: std::convert::identity,
system_prompt_suffix: None,
approval: |_: ApprovalInputs| {
Ok(SessionApproval {
session: None,
receiver: None,
})
},
session_options: move |_| Ok(SessionOptions::new().id(SessionId::new())),
})
.await?;
Ok(assembled.built)
}