Repository: openai/codex
File: codex-rs/app-server-protocol/src/protocol/v2.rs (Rust)

Code before:
pub enum CommandAction {
    Read {
        command: String,
        name: String,
        path: PathBuf,
    },
    ListFiles {
        command: String,
        path: Option<String>,
    },
    Search {
        command: String,
        query: Option<String>,
        path: Option<String>,
    },
    Unknown {
        command: String,
    },
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(rename_all = "camelCase", export_to = "v2/")]
pub enum SubAgentSource {
    Review,
    Compact,
    CollabSpawn { parent_thread_id: String },
    Other(String),
}

impl From<CoreSubAgentSource> for SubAgentSource {
    fn from(value: CoreSubAgentSource) -> Self {
        match value {
            CoreSubAgentSource::Review => SubAgentSource::Review,
            CoreSubAgentSource::Compact => SubAgentSource::Compact,
            CoreSubAgentSource::ThreadSpawn { parent_thread_id } => SubAgentSource::CollabSpawn {
                parent_thread_id: parent_thread_id.to_string(),
            },
            CoreSubAgentSource::Other(label) => SubAgentSource::Other(label),
        }
    }
}

impl From<SubAgentSource> for CoreSubAgentSource {
    fn from(value: SubAgentSource) -> Self {
        match value {
            SubAgentSource::Review => CoreSubAgentSource::Review,
            SubAgentSource::Compact => CoreSubAgentSource::Compact,
            SubAgentSource::CollabSpawn { parent_thread_id } => {
                match ThreadId::from_string(&parent_thread_id) {
                    Ok(parent_thread_id) => CoreSubAgentSource::ThreadSpawn { parent_thread_id },

Review comment (suggestion):
from an API perspective, shouldn't the compaction operation always be behind the scenes? Does a `compact` thread ever exist in practice? Would be nice to be avoid exposing this if possible

Code after:
#[ts(export_to = "v2/")]
pub enum CommandAction {
    Read {
        command: String,
        name: String,
        path: PathBuf,
    },
    ListFiles {
        command: String,
        path: Option<String>,
    },
    Search {
        command: String,
        query: Option<String>,
        path: Option<String>,
    },
    Unknown {
        command: String,
    },
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(rename_all = "camelCase", export_to = "v2/")]
#[derive(Default)]
pub enum SessionSource {
    Cli,
    #[serde(rename = "vscode")]
    #[ts(rename = "vscode")]
    #[default]
    VsCode,
    Exec,
    AppServer,
    SubAgent(CoreSubAgentSource),
    #[serde(other)]
    Unknown,
}

impl From<CoreSessionSource> for SessionSource {
    fn from(value: CoreSessionSource) -> Self {
        match value {
            CoreSessionSource::Cli => SessionSource::Cli,
            CoreSessionSource::VSCode => SessionSource::VsCode,
            CoreSessionSource::Exec => SessionSource::Exec,
            CoreSessionSource::Mcp => SessionSource::AppServer,
            CoreSessionSource::SubAgent(sub) => SessionSource::SubAgent(sub),
            CoreSessionSource::Unknown => SessionSource::Unknown,
        }
    }
}