vtcode-core 0.182.4

Core library for VT Code - a Rust-based terminal coding agent
Documentation
use serde::{Deserialize, Serialize};
use std::fmt;
use uuid::Uuid;

/// Maximum number of follow-up intents held by a runtime before new intents
/// park in the overflow buffer. The overflow buffer keeps rapid influx from
/// silently dropping user messages; once both buffers are full the caller
/// receives `FollowUpQueueFull` so back-pressure stays visible.
pub const MAX_QUEUED_FOLLOW_UP_INTENTS: usize = 64;
/// Overflow park capacity after the primary FIFO is full. Combined with the
/// primary cap this bounds total retained follow-ups while still absorbing
/// a burst instead of discarding it.
pub const MAX_OVERFLOW_FOLLOW_UP_INTENTS: usize = 64;
/// Total follow-up slots: primary plus overflow plus the one reserved
/// recovery slot. The memory envelope retains the same count oldest-first
/// per snapshot.
pub const MAX_PENDING_FOLLOW_UP_INTENTS: usize = MAX_QUEUED_FOLLOW_UP_INTENTS + MAX_OVERFLOW_FOLLOW_UP_INTENTS + 1;
/// Maximum number of applied follow-up IDs retained for restart recovery.
pub const MAX_APPLIED_FOLLOW_UP_INTENT_IDS: usize = 64;

/// Origin of a queued follow-up, preserved when it is applied to conversation history.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum FollowUpProvenance {
    /// Input supplied by a user through the steering interface.
    #[default]
    UserInput,
    /// A harness-generated continuation or recovery instruction.
    Synthetic,
}

/// A follow-up instruction with a stable identity for recovery and
/// de-duplication.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct QueuedFollowUpIntent {
    id: String,
    text: String,
    /// Defaults to user input for envelopes written before provenance existed.
    #[serde(default)]
    provenance: FollowUpProvenance,
}

impl QueuedFollowUpIntent {
    /// Create a new intent with a UUIDv4 identity.
    #[must_use]
    pub fn new(text: String) -> Self {
        Self::new_with_provenance(text, FollowUpProvenance::UserInput)
    }

    /// Create a new intent with an explicit source and UUIDv4 identity.
    #[must_use]
    pub fn new_with_provenance(text: String, provenance: FollowUpProvenance) -> Self {
        Self { id: Uuid::new_v4().to_string(), text, provenance }
    }

    /// Reconstruct an intent recovered from durable state.
    pub fn from_parts(id: impl Into<String>, text: impl Into<String>) -> Self {
        Self::from_parts_with_provenance(id, text, FollowUpProvenance::UserInput)
    }

    /// Reconstruct an intent recovered from durable state with its source.
    pub fn from_parts_with_provenance(
        id: impl Into<String>,
        text: impl Into<String>,
        provenance: FollowUpProvenance,
    ) -> Self {
        Self { id: id.into(), text: text.into(), provenance }
    }

    #[must_use]
    pub fn id(&self) -> &str {
        &self.id
    }

    #[must_use]
    pub fn text(&self) -> &str {
        &self.text
    }

    #[must_use]
    pub const fn provenance(&self) -> FollowUpProvenance {
        self.provenance
    }

    /// Consume the intent and return its user-visible text.
    #[must_use]
    pub fn into_parts(self) -> (String, String) {
        (self.id, self.text)
    }

    /// Consume the intent and return its identity, text, and source.
    #[must_use]
    pub fn into_parts_with_provenance(self) -> (String, String, FollowUpProvenance) {
        (self.id, self.text, self.provenance)
    }
}

/// Error returned when a runtime cannot accept another follow-up intent.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FollowUpQueueFull {
    pub capacity: usize,
}

impl fmt::Display for FollowUpQueueFull {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "follow-up intent queue is full (capacity {})", self.capacity)
    }
}

impl std::error::Error for FollowUpQueueFull {}

/// Messages used to steer the agent's execution loop from an external source.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum SteeringMessage {
    /// Stop the agent's execution loop immediately (Steering).
    SteerStop,
    /// Pause the agent's execution loop.
    Pause,
    /// Resume the agent's execution loop.
    Resume,
    /// Inject input as a follow-up user message. The turn loop applies it to
    /// live history at the next iteration boundary (mid-turn steering) or, if
    /// the turn ends first, delivers it at the next turn boundary.
    FollowUpInput(String),
}