Merge branch 'main' into codex/permission-request-hooks-base

# Conflicts:
#	codex-rs/core/src/codex.rs
This commit is contained in:
Abhinav Vedmala
2026-04-14 17:42:00 -07:00
511 changed files with 20987 additions and 6539 deletions
+11 -8
View File
@@ -6,6 +6,7 @@ use crate::permissions::NetworkSandboxPolicy;
use crate::protocol::FileChange;
use crate::protocol::ReviewDecision;
use crate::protocol::SandboxPolicy;
use codex_utils_absolute_path::AbsolutePathBuf;
use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;
@@ -129,17 +130,17 @@ pub enum GuardianAssessmentAction {
Command {
source: GuardianCommandSource,
command: String,
cwd: PathBuf,
cwd: AbsolutePathBuf,
},
Execve {
source: GuardianCommandSource,
program: String,
argv: Vec<String>,
cwd: PathBuf,
cwd: AbsolutePathBuf,
},
ApplyPatch {
cwd: PathBuf,
files: Vec<PathBuf>,
cwd: AbsolutePathBuf,
files: Vec<AbsolutePathBuf>,
},
NetworkAccess {
target: String,
@@ -213,7 +214,7 @@ pub struct ExecApprovalRequestEvent {
/// The command to be executed.
pub command: Vec<String>,
/// The command's working directory.
pub cwd: PathBuf,
pub cwd: AbsolutePathBuf,
/// Optional human-readable reason for the approval (e.g. retry without sandbox).
#[serde(skip_serializing_if = "Option::is_none")]
pub reason: Option<String>,
@@ -369,6 +370,8 @@ pub struct ApplyPatchApprovalRequestEvent {
#[cfg(test)]
mod tests {
use super::*;
use codex_utils_absolute_path::test_support::PathBufExt;
use codex_utils_absolute_path::test_support::test_path_buf;
use pretty_assertions::assert_eq;
#[test]
@@ -377,7 +380,7 @@ mod tests {
"type": "command",
"source": "shell",
"command": "rm -rf /tmp/guardian",
"cwd": "/tmp",
"cwd": test_path_buf("/tmp"),
}))
.expect("guardian action");
@@ -386,7 +389,7 @@ mod tests {
GuardianAssessmentAction::Command {
source: GuardianCommandSource::Shell,
command: "rm -rf /tmp/guardian".to_string(),
cwd: PathBuf::from("/tmp"),
cwd: test_path_buf("/tmp").abs(),
}
);
}
@@ -419,7 +422,7 @@ mod tests {
"-f".to_string(),
"/tmp/file.sqlite".to_string(),
],
cwd: PathBuf::from("/tmp"),
cwd: test_path_buf("/tmp").abs(),
}
);
}
+2 -1
View File
@@ -14,6 +14,7 @@ use crate::protocol::WebSearchEndEvent;
use crate::user_input::ByteRange;
use crate::user_input::TextElement;
use crate::user_input::UserInput;
use codex_utils_absolute_path::AbsolutePathBuf;
use quick_xml::de::from_str as from_xml_str;
use quick_xml::se::to_string as to_xml_string;
use schemars::JsonSchema;
@@ -123,7 +124,7 @@ pub struct ImageGenerationItem {
pub result: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub saved_path: Option<String>,
pub saved_path: Option<AbsolutePathBuf>,
}
#[derive(Debug, Clone, Deserialize, Serialize, TS, JsonSchema)]
+97 -17
View File
@@ -134,6 +134,8 @@ pub struct McpServerRefreshConfig {
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, JsonSchema, TS)]
pub struct ConversationStartParams {
/// Selects whether the realtime session should produce text or audio output.
pub output_modality: RealtimeOutputModality,
#[serde(
default,
deserialize_with = "conversation_start_prompt_serde::deserialize",
@@ -157,6 +159,13 @@ pub enum ConversationStartTransport {
Webrtc { sdp: String },
}
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "snake_case")]
pub enum RealtimeOutputModality {
Text,
Audio,
}
mod conversation_start_prompt_serde {
use serde::Deserializer;
use serde::Serializer;
@@ -290,6 +299,11 @@ pub struct RealtimeTranscriptDelta {
pub delta: String,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)]
pub struct RealtimeTranscriptDone {
pub text: String,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, JsonSchema, TS)]
pub struct RealtimeTranscriptEntry {
pub role: String,
@@ -332,7 +346,9 @@ pub enum RealtimeEvent {
},
InputAudioSpeechStarted(RealtimeInputAudioSpeechStarted),
InputTranscriptDelta(RealtimeTranscriptDelta),
InputTranscriptDone(RealtimeTranscriptDone),
OutputTranscriptDelta(RealtimeTranscriptDelta),
OutputTranscriptDone(RealtimeTranscriptDone),
AudioOut(RealtimeAudioFrame),
ResponseCreated(RealtimeResponseCreated),
ResponseCancelled(RealtimeResponseCancelled),
@@ -636,6 +652,12 @@ pub enum Op {
/// involve the model.
SetThreadName { name: String },
/// Set whether the thread remains eligible for memory generation.
///
/// This persists thread-level memory mode metadata without involving the
/// model.
SetThreadMemoryMode { mode: ThreadMemoryMode },
/// Request Codex to undo a turn (turn are stacked so it is the same effect as CMD + Z).
Undo,
@@ -665,6 +687,13 @@ pub enum Op {
ListModels,
}
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "lowercase")]
pub enum ThreadMemoryMode {
Enabled,
Disabled,
}
impl From<Vec<UserInput>> for Op {
fn from(value: Vec<UserInput>) -> Self {
Op::UserInput {
@@ -755,6 +784,7 @@ impl Op {
Self::DropMemories => "drop_memories",
Self::UpdateMemories => "update_memories",
Self::SetThreadName { .. } => "set_thread_name",
Self::SetThreadMemoryMode { .. } => "set_thread_memory_mode",
Self::Undo => "undo",
Self::ThreadRollback { .. } => "thread_rollback",
Self::Review { .. } => "review",
@@ -1637,7 +1667,7 @@ pub struct HookRunSummary {
pub handler_type: HookHandlerType,
pub execution_mode: HookExecutionMode,
pub scope: HookScope,
pub source_path: PathBuf,
pub source_path: AbsolutePathBuf,
pub display_order: i64,
pub status: HookRunStatus,
pub status_message: Option<String>,
@@ -2403,7 +2433,7 @@ pub struct ImageGenerationEndEvent {
pub result: String,
#[serde(skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub saved_path: Option<String>,
pub saved_path: Option<AbsolutePathBuf>,
}
// Conversation kept for backward compatibility.
@@ -2431,6 +2461,14 @@ pub enum InitialHistory {
}
impl InitialHistory {
pub fn scan_rollout_items(&self, mut predicate: impl FnMut(&RolloutItem) -> bool) -> bool {
match self {
InitialHistory::New | InitialHistory::Cleared => false,
InitialHistory::Resumed(resumed) => resumed.history.iter().any(&mut predicate),
InitialHistory::Forked(items) => items.iter().any(predicate),
}
}
pub fn forked_from_id(&self) -> Option<ThreadId> {
match self {
InitialHistory::New | InitialHistory::Cleared => None,
@@ -2596,6 +2634,15 @@ impl SessionSource {
})
}
/// Low cardinality thread source label for analytics.
pub fn thread_source_name(&self) -> Option<&'static str> {
match self {
SessionSource::Cli | SessionSource::VSCode | SessionSource::Exec => Some("user"),
SessionSource::SubAgent(_) => Some("subagent"),
SessionSource::Mcp | SessionSource::Custom(_) | SessionSource::Unknown => None,
}
}
pub fn get_nickname(&self) -> Option<String> {
match self {
SessionSource::SubAgent(SubAgentSource::ThreadSpawn { agent_nickname, .. }) => {
@@ -3000,7 +3047,7 @@ pub struct ExecCommandBeginEvent {
/// The command to be executed.
pub command: Vec<String>,
/// The command's working directory if not the default cwd for the agent.
pub cwd: PathBuf,
pub cwd: AbsolutePathBuf,
pub parsed_cmd: Vec<ParsedCommand>,
/// Where the command originated. Defaults to Agent for backward compatibility.
#[serde(default)]
@@ -3024,7 +3071,7 @@ pub struct ExecCommandEndEvent {
/// The command that was executed.
pub command: Vec<String>,
/// The command's working directory if not the default cwd for the agent.
pub cwd: PathBuf,
pub cwd: AbsolutePathBuf,
pub parsed_cmd: Vec<ParsedCommand>,
/// Where the command originated. Defaults to Agent for backward compatibility.
#[serde(default)]
@@ -3057,7 +3104,7 @@ pub struct ViewImageToolCallEvent {
/// Identifier for the originating tool call.
pub call_id: String,
/// Local filesystem path provided to the tool.
pub path: PathBuf,
pub path: AbsolutePathBuf,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, JsonSchema, TS)]
@@ -3333,7 +3380,7 @@ pub struct SkillMetadata {
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub dependencies: Option<SkillDependencies>,
pub path: PathBuf,
pub path: AbsolutePathBuf,
pub scope: SkillScope,
pub enabled: bool,
}
@@ -3345,9 +3392,9 @@ pub struct SkillInterface {
#[ts(optional)]
pub short_description: Option<String>,
#[ts(optional)]
pub icon_small: Option<PathBuf>,
pub icon_small: Option<AbsolutePathBuf>,
#[ts(optional)]
pub icon_large: Option<PathBuf>,
pub icon_large: Option<AbsolutePathBuf>,
#[ts(optional)]
pub brand_color: Option<String>,
#[ts(optional)]
@@ -3431,7 +3478,7 @@ pub struct SessionConfiguredEvent {
/// Working directory that should be treated as the *root* of the
/// session.
pub cwd: PathBuf,
pub cwd: AbsolutePathBuf,
/// The effort the model is putting into reasoning about the user's request.
#[serde(skip_serializing_if = "Option::is_none")]
@@ -3772,6 +3819,8 @@ mod tests {
use crate::permissions::NetworkSandboxPolicy;
use anyhow::Result;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_absolute_path::test_support::PathBufExt;
use codex_utils_absolute_path::test_support::test_path_buf;
use pretty_assertions::assert_eq;
use serde_json::json;
use std::path::PathBuf;
@@ -3845,6 +3894,24 @@ mod tests {
);
}
#[test]
fn session_source_thread_source_name_classifies_user_and_subagent_sources() {
for (source, expected) in [
(SessionSource::Cli, Some("user")),
(SessionSource::VSCode, Some("user")),
(SessionSource::Exec, Some("user")),
(
SessionSource::SubAgent(SubAgentSource::Review),
Some("subagent"),
),
(SessionSource::Mcp, None),
(SessionSource::Custom("atlas".to_string()), None),
(SessionSource::Unknown, None),
] {
assert_eq!(source.thread_source_name(), expected);
}
}
#[test]
fn session_source_restriction_product_defaults_non_subagent_sources_to_codex() {
assert_eq!(
@@ -4514,7 +4581,7 @@ mod tests {
status: "completed".into(),
revised_prompt: Some("A tiny blue square".into()),
result: "Zm9v".into(),
saved_path: Some("/tmp/ig-1.png".into()),
saved_path: Some(test_path_buf("/tmp/ig-1.png").abs()),
}),
};
@@ -4526,7 +4593,10 @@ mod tests {
assert_eq!(event.status, "completed");
assert_eq!(event.revised_prompt.as_deref(), Some("A tiny blue square"));
assert_eq!(event.result, "Zm9v");
assert_eq!(event.saved_path.as_deref(), Some("/tmp/ig-1.png"));
assert_eq!(
event.saved_path.as_ref().map(AbsolutePathBuf::as_path),
Some(test_path_buf("/tmp/ig-1.png").as_path())
);
}
_ => panic!("expected ImageGenerationEnd event"),
}
@@ -4573,12 +4643,14 @@ mod tests {
},
});
let start = Op::RealtimeConversationStart(ConversationStartParams {
output_modality: RealtimeOutputModality::Audio,
prompt: Some(Some("be helpful".to_string())),
session_id: Some("conv_1".to_string()),
transport: None,
voice: None,
});
let webrtc_start = Op::RealtimeConversationStart(ConversationStartParams {
output_modality: RealtimeOutputModality::Audio,
prompt: Some(Some("be helpful".to_string())),
session_id: Some("conv_1".to_string()),
transport: Some(ConversationStartTransport::Webrtc {
@@ -4591,12 +4663,14 @@ mod tests {
});
let close = Op::RealtimeConversationClose;
let default_prompt_start = Op::RealtimeConversationStart(ConversationStartParams {
output_modality: RealtimeOutputModality::Audio,
prompt: None,
session_id: None,
transport: None,
voice: None,
});
let null_prompt_start = Op::RealtimeConversationStart(ConversationStartParams {
output_modality: RealtimeOutputModality::Audio,
prompt: Some(None),
session_id: None,
transport: None,
@@ -4608,6 +4682,7 @@ mod tests {
serde_json::to_value(&start).unwrap(),
json!({
"type": "realtime_conversation_start",
"output_modality": "audio",
"prompt": "be helpful",
"session_id": "conv_1"
})
@@ -4615,19 +4690,22 @@ mod tests {
assert_eq!(
serde_json::to_value(&default_prompt_start).unwrap(),
json!({
"type": "realtime_conversation_start"
"type": "realtime_conversation_start",
"output_modality": "audio"
})
);
assert_eq!(
serde_json::to_value(&null_prompt_start).unwrap(),
json!({
"type": "realtime_conversation_start",
"output_modality": "audio",
"prompt": null
})
);
assert_eq!(
serde_json::from_value::<Op>(json!({
"type": "realtime_conversation_start"
"type": "realtime_conversation_start",
"output_modality": "audio"
}))
.unwrap(),
default_prompt_start
@@ -4635,6 +4713,7 @@ mod tests {
assert_eq!(
serde_json::from_value::<Op>(json!({
"type": "realtime_conversation_start",
"output_modality": "audio",
"prompt": null
}))
.unwrap(),
@@ -4680,6 +4759,7 @@ mod tests {
serde_json::to_value(&webrtc_start).unwrap(),
json!({
"type": "realtime_conversation_start",
"output_modality": "audio",
"prompt": "be helpful",
"session_id": "conv_1",
"transport": {
@@ -4876,7 +4956,7 @@ mod tests {
#[test]
fn turn_context_item_deserializes_without_network() -> Result<()> {
let item: TurnContextItem = serde_json::from_value(json!({
"cwd": "/tmp",
"cwd": test_path_buf("/tmp"),
"approval_policy": "never",
"sandbox_policy": { "type": "danger-full-access" },
"model": "gpt-5",
@@ -4893,7 +4973,7 @@ mod tests {
let item = TurnContextItem {
turn_id: None,
trace_id: None,
cwd: PathBuf::from("/tmp"),
cwd: test_path_buf("/tmp"),
current_date: None,
timezone: None,
approval_policy: AskForApproval::Never,
@@ -4943,7 +5023,7 @@ mod tests {
approval_policy: AskForApproval::Never,
approvals_reviewer: ApprovalsReviewer::User,
sandbox_policy: SandboxPolicy::new_read_only_policy(),
cwd: PathBuf::from("/home/user/project"),
cwd: test_path_buf("/home/user/project").abs(),
reasoning_effort: Some(ReasoningEffortConfig::default()),
history_log_id: 0,
history_entry_count: 0,
@@ -4965,7 +5045,7 @@ mod tests {
"sandbox_policy": {
"type": "read-only"
},
"cwd": "/home/user/project",
"cwd": test_path_buf("/home/user/project"),
"reasoning_effort": "medium",
"history_log_id": 0,
"history_entry_count": 0,