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    /// Planning activated by selecting the `plan` primary agent via Tab/palette.
17    AgentSelection,
18    /// Planning suggested by the active execution agent for a demanding task.
19    AgentSuggestion,
20}
21
22impl PlanningEntrySource {
23    pub const fn should_auto_enter(self) -> bool {
24        matches!(self, Self::CliFlag)
25    }
26
27    pub const fn requires_startup_prompt(self) -> bool {
28        matches!(self, Self::ConfigDefault)
29    }
30}
31
32/// Parameters passed to a [`SessionRuntime`] implementation for executing an interactive session.
33#[derive(Debug)]
34pub struct SessionRuntimeParams<'a, Resume> {
35    pub agent_config: &'a CoreAgentConfig,
36    pub vt_config: Option<VTCodeConfig>,
37    pub skip_confirmations: bool,
38    pub full_auto: bool,
39    pub primary_agent_explicitly_configured: bool,
40    pub planning_entry_source: PlanningEntrySource,
41    pub resume: Option<Resume>,
42    pub steering_receiver: &'a mut Option<tokio::sync::mpsc::UnboundedReceiver<SteeringMessage>>,
43}
44
45impl<'a, Resume> SessionRuntimeParams<'a, Resume> {
46    pub fn new(
47        agent_config: &'a CoreAgentConfig,
48        vt_config: Option<VTCodeConfig>,
49        skip_confirmations: bool,
50        full_auto: bool,
51        primary_agent_explicitly_configured: bool,
52        planning_entry_source: PlanningEntrySource,
53        resume: Option<Resume>,
54        steering_receiver: &'a mut Option<tokio::sync::mpsc::UnboundedReceiver<SteeringMessage>>,
55    ) -> Self {
56        Self {
57            agent_config,
58            vt_config,
59            skip_confirmations,
60            full_auto,
61            primary_agent_explicitly_configured,
62            planning_entry_source,
63            resume,
64            steering_receiver,
65        }
66    }
67}
68
69/// Abstraction over an interactive session runtime used by the CLI and adapters.
70#[async_trait]
71pub trait SessionRuntime<Resume>: Send + Sync {
72    async fn run_session(&self, params: SessionRuntimeParams<'_, Resume>) -> Result<()>;
73}