Skip to main content

ag_runtime/
provider.rs

1use std::path::Path;
2
3use ag_contracts::AgentError;
4use ag_session::{AgentAvailabilityProbe, AgentCliInfo, AgentKind};
5
6/// Machine-scoped provider discovery through the concrete adapter registry.
7pub struct RealAgentAvailabilityProbe;
8
9impl AgentAvailabilityProbe for RealAgentAvailabilityProbe {
10    fn available_agent_kinds(&self) -> Vec<AgentKind> {
11        ag_agent::RealAgentAvailabilityProbe.available_agent_kinds()
12    }
13
14    fn available_agent_clis(&self) -> Vec<AgentCliInfo> {
15        ag_agent::RealAgentAvailabilityProbe.available_agent_clis()
16    }
17}
18
19/// Initializes provider resources in a session workspace.
20///
21/// # Errors
22/// Returns a normalized adapter setup failure.
23pub fn setup_backend(kind: AgentKind, folder: &Path) -> Result<(), AgentError> {
24    ag_agent::create_backend(kind)
25        .setup(folder)
26        .map_err(Into::into)
27}
28
29/// Whether the selected provider retains a process between turns.
30pub fn uses_persistent_session(kind: AgentKind) -> bool {
31    ag_agent::transport_mode(kind).uses_app_server()
32}
33
34/// Reclaims adapter-owned resources during workspace deletion.
35///
36/// # Errors
37/// Returns the runtime artifact cleanup failure.
38pub fn cleanup_session_worktree_artifacts(folder: &Path) -> Result<(), AgentError> {
39    ag_agent::cleanup_session_worktree_artifacts(folder).map_err(Into::into)
40}