Skip to main content

vtcode_core/core/interfaces/
session.rs

1use anyhow::Result;
2use async_trait::async_trait;
3
4use crate::config::loader::VTCodeConfig;
5use crate::config::types::AgentConfig as CoreAgentConfig;
6use crate::core::agent::steering::SteeringMessage;
7
8/// Source that triggered planning workflow entry.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
10pub enum PlanningEntrySource {
11    #[default]
12    None,
13    CliFlag,
14    ConfigDefault,
15    UserRequest,
16}
17
18impl PlanningEntrySource {
19    pub const fn should_auto_enter(self) -> bool {
20        matches!(self, Self::CliFlag)
21    }
22
23    pub const fn requires_startup_prompt(self) -> bool {
24        matches!(self, Self::ConfigDefault)
25    }
26}
27
28/// Parameters passed to a [`SessionRuntime`] implementation for executing an interactive session.
29#[derive(Debug)]
30pub struct SessionRuntimeParams<'a, Resume> {
31    pub agent_config: &'a CoreAgentConfig,
32    pub vt_config: Option<VTCodeConfig>,
33    pub skip_confirmations: bool,
34    pub full_auto: bool,
35    pub primary_agent_explicitly_configured: bool,
36    pub planning_entry_source: PlanningEntrySource,
37    pub resume: Option<Resume>,
38    pub steering_receiver: &'a mut Option<tokio::sync::mpsc::UnboundedReceiver<SteeringMessage>>,
39}
40
41impl<'a, Resume> SessionRuntimeParams<'a, Resume> {
42    #[expect(clippy::too_many_arguments)]
43    pub fn new(
44        agent_config: &'a CoreAgentConfig,
45        vt_config: Option<VTCodeConfig>,
46        skip_confirmations: bool,
47        full_auto: bool,
48        primary_agent_explicitly_configured: bool,
49        planning_entry_source: PlanningEntrySource,
50        resume: Option<Resume>,
51        steering_receiver: &'a mut Option<tokio::sync::mpsc::UnboundedReceiver<SteeringMessage>>,
52    ) -> Self {
53        Self {
54            agent_config,
55            vt_config,
56            skip_confirmations,
57            full_auto,
58            primary_agent_explicitly_configured,
59            planning_entry_source,
60            resume,
61            steering_receiver,
62        }
63    }
64}
65
66/// Abstraction over an interactive session runtime used by the CLI and adapters.
67#[async_trait]
68pub trait SessionRuntime<Resume>: Send + Sync {
69    async fn run_session(&self, params: SessionRuntimeParams<'_, Resume>) -> Result<()>;
70}