From 8d720feb698341c9a1599253d5e903cd99c603cb Mon Sep 17 00:00:00 2001 From: jif-oai Date: Tue, 2 Jun 2026 00:24:41 +0200 Subject: [PATCH 1/5] Move tool search metadata onto ToolExecutor (#25684) Deferred tools need to be searchable even when they are not implemented inside `codex-core`. Extension-provided tools can be registered for later discovery, but the search metadata path was still owned by core-specific runtime hooks, which meant the shared `ToolExecutor` abstraction could not describe how a deferred extension tool should appear in `tool_search`. ## Changes - Move `ToolSearchEntry` and `ToolSearchInfo` into `codex-tools` and re-export them from the shared tools crate. - Add a default `ToolExecutor::search_info` implementation that derives loadable tool-search metadata from function and namespace specs. - Forward search metadata through extension adapters and exposure overrides while keeping custom search text/source metadata for dynamic, MCP, and multi-agent tools. - Remove the old core-local `tool_search_entry` module now that search metadata lives with the shared executor APIs. ## Testing - Added `deferred_extension_tools_are_discoverable_with_tool_search` coverage in `core/src/tools/spec_plan_tests.rs`. --- codex-rs/core/src/tools/handlers/dynamic.rs | 26 ++-- .../src/tools/handlers/extension_tools.rs | 5 + codex-rs/core/src/tools/handlers/mcp.rs | 54 +++---- .../core/src/tools/handlers/multi_agents.rs | 2 +- .../handlers/multi_agents/close_agent.rs | 14 +- .../handlers/multi_agents/resume_agent.rs | 14 +- .../tools/handlers/multi_agents/send_input.rs | 14 +- .../src/tools/handlers/multi_agents/spawn.rs | 14 +- .../src/tools/handlers/multi_agents/wait.rs | 14 +- .../core/src/tools/handlers/tool_search.rs | 4 +- codex-rs/core/src/tools/mod.rs | 1 - codex-rs/core/src/tools/registry.rs | 14 +- codex-rs/core/src/tools/spec_plan.rs | 9 +- codex-rs/core/src/tools/spec_plan_tests.rs | 57 +++++++ codex-rs/core/src/tools/tool_search_entry.rs | 56 ------- codex-rs/tools/src/lib.rs | 4 + codex-rs/tools/src/tool_executor.rs | 10 +- codex-rs/tools/src/tool_search.rs | 139 ++++++++++++++++++ 18 files changed, 302 insertions(+), 149 deletions(-) delete mode 100644 codex-rs/core/src/tools/tool_search_entry.rs create mode 100644 codex-rs/tools/src/tool_search.rs diff --git a/codex-rs/core/src/tools/handlers/dynamic.rs b/codex-rs/core/src/tools/handlers/dynamic.rs index e5e0d10534..a74f44fd6d 100644 --- a/codex-rs/core/src/tools/handlers/dynamic.rs +++ b/codex-rs/core/src/tools/handlers/dynamic.rs @@ -9,7 +9,6 @@ use crate::tools::handlers::parse_arguments; use crate::tools::registry::CoreToolRuntime; use crate::tools::registry::ToolExecutor; use crate::tools::registry::ToolExposure; -use crate::tools::tool_search_entry::ToolSearchInfo; use crate::turn_timing::now_unix_timestamp_ms; use codex_protocol::dynamic_tools::DynamicToolCallRequest; use codex_protocol::dynamic_tools::DynamicToolResponse; @@ -20,6 +19,7 @@ use codex_protocol::protocol::EventMsg; use codex_tools::ResponsesApiNamespace; use codex_tools::ResponsesApiNamespaceTool; use codex_tools::ToolName; +use codex_tools::ToolSearchInfo; use codex_tools::ToolSearchSourceInfo; use codex_tools::ToolSpec; use codex_tools::default_namespace_description; @@ -75,6 +75,17 @@ impl ToolExecutor for DynamicToolHandler { self.exposure } + fn search_info(&self) -> Option { + ToolSearchInfo::from_spec( + self.search_text.clone(), + self.spec(), + Some(ToolSearchSourceInfo { + name: "Dynamic tools".to_string(), + description: Some("Tools provided by the current Codex thread.".to_string()), + }), + ) + } + async fn handle( &self, invocation: ToolInvocation, @@ -126,18 +137,7 @@ impl ToolExecutor for DynamicToolHandler { } } -impl CoreToolRuntime for DynamicToolHandler { - fn search_info(&self) -> Option { - ToolSearchInfo::from_spec( - self.search_text.clone(), - self.spec(), - Some(ToolSearchSourceInfo { - name: "Dynamic tools".to_string(), - description: Some("Tools provided by the current Codex thread.".to_string()), - }), - ) - } -} +impl CoreToolRuntime for DynamicToolHandler {} #[expect( clippy::await_holding_invalid_type, diff --git a/codex-rs/core/src/tools/handlers/extension_tools.rs b/codex-rs/core/src/tools/handlers/extension_tools.rs index 95b272bbf6..4ad88ac5bb 100644 --- a/codex-rs/core/src/tools/handlers/extension_tools.rs +++ b/codex-rs/core/src/tools/handlers/extension_tools.rs @@ -7,6 +7,7 @@ use codex_tools::ExtensionTurnItem; use codex_tools::ImageGenerationCompletionFuture; use codex_tools::ToolCall as ExtensionToolCall; use codex_tools::ToolName; +use codex_tools::ToolSearchInfo; use codex_tools::ToolSpec; use codex_tools::TurnItemEmissionFuture; use codex_tools::TurnItemEmitter; @@ -49,6 +50,10 @@ impl ToolExecutor for ExtensionToolAdapter { self.0.supports_parallel_tool_calls() } + fn search_info(&self) -> Option { + self.0.search_info() + } + async fn handle( &self, invocation: ToolInvocation, diff --git a/codex-rs/core/src/tools/handlers/mcp.rs b/codex-rs/core/src/tools/handlers/mcp.rs index 8f18d5b55e..77ff3c14a3 100644 --- a/codex-rs/core/src/tools/handlers/mcp.rs +++ b/codex-rs/core/src/tools/handlers/mcp.rs @@ -15,11 +15,11 @@ use crate::tools::registry::PostToolUsePayload; use crate::tools::registry::PreToolUsePayload; use crate::tools::registry::ToolExecutor; use crate::tools::registry::ToolTelemetryTags; -use crate::tools::tool_search_entry::ToolSearchInfo; use codex_mcp::ToolInfo; use codex_tools::ResponsesApiNamespace; use codex_tools::ResponsesApiNamespaceTool; use codex_tools::ToolName; +use codex_tools::ToolSearchInfo; use codex_tools::ToolSearchSourceInfo; use codex_tools::ToolSpec; use codex_tools::mcp_tool_to_responses_api_tool; @@ -87,6 +87,32 @@ impl ToolExecutor for McpHandler { .unwrap_or(false) } + fn search_info(&self) -> Option { + let source_name = self + .tool_info + .connector_name + .as_deref() + .map(str::trim) + .filter(|connector_name| !connector_name.is_empty()) + .unwrap_or_else(|| self.tool_info.server_name.trim()); + let source_info = (!source_name.is_empty()).then(|| ToolSearchSourceInfo { + name: source_name.to_string(), + description: self + .tool_info + .namespace_description + .as_deref() + .map(str::trim) + .filter(|description| !description.is_empty()) + .map(str::to_string), + }); + + ToolSearchInfo::from_spec( + build_mcp_search_text(&self.tool_info), + self.spec(), + source_info, + ) + } + async fn handle( &self, invocation: ToolInvocation, @@ -131,32 +157,6 @@ impl ToolExecutor for McpHandler { } impl CoreToolRuntime for McpHandler { - fn search_info(&self) -> Option { - let source_name = self - .tool_info - .connector_name - .as_deref() - .map(str::trim) - .filter(|connector_name| !connector_name.is_empty()) - .unwrap_or_else(|| self.tool_info.server_name.trim()); - let source_info = (!source_name.is_empty()).then(|| ToolSearchSourceInfo { - name: source_name.to_string(), - description: self - .tool_info - .namespace_description - .as_deref() - .map(str::trim) - .filter(|description| !description.is_empty()) - .map(str::to_string), - }); - - ToolSearchInfo::from_spec( - build_mcp_search_text(&self.tool_info), - self.spec(), - source_info, - ) - } - fn telemetry_tags<'a>( &'a self, _invocation: &'a ToolInvocation, diff --git a/codex-rs/core/src/tools/handlers/multi_agents.rs b/codex-rs/core/src/tools/handlers/multi_agents.rs index 00176572e0..8bc96d19c2 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents.rs @@ -19,7 +19,6 @@ use crate::tools::handlers::multi_agents_spec::MULTI_AGENT_V1_NAMESPACE; use crate::tools::handlers::parse_arguments; use crate::tools::registry::CoreToolRuntime; use crate::tools::registry::ToolExecutor; -use crate::tools::tool_search_entry::ToolSearchInfo; use codex_protocol::ThreadId; use codex_protocol::models::ResponseInputItem; use codex_protocol::openai_models::ReasoningEffort; @@ -36,6 +35,7 @@ use codex_protocol::protocol::CollabWaitingBeginEvent; use codex_protocol::protocol::CollabWaitingEndEvent; use codex_protocol::user_input::UserInput; use codex_tools::ToolName; +use codex_tools::ToolSearchInfo; use codex_tools::ToolSearchSourceInfo; use serde::Deserialize; use serde::Serialize; diff --git a/codex-rs/core/src/tools/handlers/multi_agents/close_agent.rs b/codex-rs/core/src/tools/handlers/multi_agents/close_agent.rs index bcfa5231b9..2007e3df7d 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents/close_agent.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents/close_agent.rs @@ -16,6 +16,13 @@ impl ToolExecutor for Handler { create_close_agent_tool_v1() } + fn search_info(&self) -> Option { + multi_agent_tool_search_info( + "close_agent close shutdown stop agent subagent thread status target", + self.spec(), + ) + } + async fn handle( &self, invocation: ToolInvocation, @@ -109,13 +116,6 @@ async fn handle_close_agent( } impl CoreToolRuntime for Handler { - fn search_info(&self) -> Option { - multi_agent_tool_search_info( - "close_agent close shutdown stop agent subagent thread status target", - self.spec(), - ) - } - fn matches_kind(&self, payload: &ToolPayload) -> bool { matches!(payload, ToolPayload::Function { .. }) } diff --git a/codex-rs/core/src/tools/handlers/multi_agents/resume_agent.rs b/codex-rs/core/src/tools/handlers/multi_agents/resume_agent.rs index a536c8d704..ebe3678eb9 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents/resume_agent.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents/resume_agent.rs @@ -17,6 +17,13 @@ impl ToolExecutor for Handler { create_resume_agent_tool() } + fn search_info(&self) -> Option { + multi_agent_tool_search_info( + "resume_agent resume reopen closed agent subagent thread id target", + self.spec(), + ) + } + async fn handle( &self, invocation: ToolInvocation, @@ -135,13 +142,6 @@ async fn handle_resume_agent( } impl CoreToolRuntime for Handler { - fn search_info(&self) -> Option { - multi_agent_tool_search_info( - "resume_agent resume reopen closed agent subagent thread id target", - self.spec(), - ) - } - fn matches_kind(&self, payload: &ToolPayload) -> bool { matches!(payload, ToolPayload::Function { .. }) } diff --git a/codex-rs/core/src/tools/handlers/multi_agents/send_input.rs b/codex-rs/core/src/tools/handlers/multi_agents/send_input.rs index 8499bac52c..d7f316ba3e 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents/send_input.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents/send_input.rs @@ -16,6 +16,13 @@ impl ToolExecutor for Handler { create_send_input_tool_v1() } + fn search_info(&self) -> Option { + multi_agent_tool_search_info( + "send_input send message existing agent subagent follow up interrupt redirect queue target", + self.spec(), + ) + } + async fn handle( &self, invocation: ToolInvocation, @@ -91,13 +98,6 @@ impl ToolExecutor for Handler { } impl CoreToolRuntime for Handler { - fn search_info(&self) -> Option { - multi_agent_tool_search_info( - "send_input send message existing agent subagent follow up interrupt redirect queue target", - self.spec(), - ) - } - fn matches_kind(&self, payload: &ToolPayload) -> bool { matches!(payload, ToolPayload::Function { .. }) } diff --git a/codex-rs/core/src/tools/handlers/multi_agents/spawn.rs b/codex-rs/core/src/tools/handlers/multi_agents/spawn.rs index c4120dd5af..56707fb0ca 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents/spawn.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents/spawn.rs @@ -32,6 +32,13 @@ impl ToolExecutor for Handler { create_spawn_agent_tool_v1(self.options.clone()) } + fn search_info(&self) -> Option { + multi_agent_tool_search_info( + "spawn_agent spawn agent subagent sub-agent delegate delegation parallel work worker explorer no-apps fork model reasoning", + self.spec(), + ) + } + async fn handle( &self, invocation: ToolInvocation, @@ -204,13 +211,6 @@ async fn handle_spawn_agent( } impl CoreToolRuntime for Handler { - fn search_info(&self) -> Option { - multi_agent_tool_search_info( - "spawn_agent spawn agent subagent sub-agent delegate delegation parallel work worker explorer no-apps fork model reasoning", - self.spec(), - ) - } - fn matches_kind(&self, payload: &ToolPayload) -> bool { matches!(payload, ToolPayload::Function { .. }) } diff --git a/codex-rs/core/src/tools/handlers/multi_agents/wait.rs b/codex-rs/core/src/tools/handlers/multi_agents/wait.rs index 2e4fb6100a..063b064578 100644 --- a/codex-rs/core/src/tools/handlers/multi_agents/wait.rs +++ b/codex-rs/core/src/tools/handlers/multi_agents/wait.rs @@ -37,6 +37,13 @@ impl ToolExecutor for Handler { create_wait_agent_tool_v1(self.options) } + fn search_info(&self) -> Option { + multi_agent_tool_search_info( + "wait_agent wait agent subagent status final result complete timeout targets", + self.spec(), + ) + } + async fn handle( &self, invocation: ToolInvocation, @@ -203,13 +210,6 @@ impl ToolExecutor for Handler { } impl CoreToolRuntime for Handler { - fn search_info(&self) -> Option { - multi_agent_tool_search_info( - "wait_agent wait agent subagent status final result complete timeout targets", - self.spec(), - ) - } - fn matches_kind(&self, payload: &ToolPayload) -> bool { matches!(payload, ToolPayload::Function { .. }) } diff --git a/codex-rs/core/src/tools/handlers/tool_search.rs b/codex-rs/core/src/tools/handlers/tool_search.rs index 442d77ce8d..2de1e20dd4 100644 --- a/codex-rs/core/src/tools/handlers/tool_search.rs +++ b/codex-rs/core/src/tools/handlers/tool_search.rs @@ -6,8 +6,6 @@ use crate::tools::context::boxed_tool_output; use crate::tools::handlers::tool_search_spec::create_tool_search_tool; use crate::tools::registry::CoreToolRuntime; use crate::tools::registry::ToolExecutor; -use crate::tools::tool_search_entry::ToolSearchEntry; -use crate::tools::tool_search_entry::ToolSearchInfo; use bm25::Document; use bm25::Language; use bm25::SearchEngine; @@ -16,6 +14,8 @@ use codex_tools::LoadableToolSpec; use codex_tools::TOOL_SEARCH_DEFAULT_LIMIT; use codex_tools::TOOL_SEARCH_TOOL_NAME; use codex_tools::ToolName; +use codex_tools::ToolSearchEntry; +use codex_tools::ToolSearchInfo; use codex_tools::ToolSearchSourceInfo; use codex_tools::ToolSpec; use codex_tools::coalesce_loadable_tool_specs; diff --git a/codex-rs/core/src/tools/mod.rs b/codex-rs/core/src/tools/mod.rs index 5b7a17f428..cd10d246db 100644 --- a/codex-rs/core/src/tools/mod.rs +++ b/codex-rs/core/src/tools/mod.rs @@ -14,7 +14,6 @@ pub(crate) mod runtimes; pub(crate) mod sandboxing; pub(crate) mod spec_plan; pub(crate) mod tool_dispatch_trace; -pub(crate) mod tool_search_entry; use std::borrow::Cow; diff --git a/codex-rs/core/src/tools/registry.rs b/codex-rs/core/src/tools/registry.rs index f0fdf424a9..b2a0b7704a 100644 --- a/codex-rs/core/src/tools/registry.rs +++ b/codex-rs/core/src/tools/registry.rs @@ -24,13 +24,13 @@ use crate::tools::hook_names::HookToolName; use crate::tools::lifecycle::notify_tool_finish; use crate::tools::lifecycle::notify_tool_start; use crate::tools::tool_dispatch_trace::ToolDispatchTrace; -use crate::tools::tool_search_entry::ToolSearchInfo; use crate::util::error_or_panic; use codex_extension_api::ToolCallOutcome; use codex_protocol::models::FunctionCallOutputPayload; use codex_protocol::models::ResponseInputItem; use codex_protocol::protocol::EventMsg; use codex_tools::ToolName; +use codex_tools::ToolSearchInfo; use codex_tools::ToolSpec; use futures::future::BoxFuture; use serde_json::Value; @@ -46,10 +46,6 @@ pub use codex_tools::ToolExposure; /// Implementers provide the shared `ToolExecutor` behavior plus optional /// core-owned metadata for hooks, telemetry, tool search, and argument diffs. pub(crate) trait CoreToolRuntime: ToolExecutor { - fn search_info(&self) -> Option { - None - } - fn matches_kind(&self, payload: &ToolPayload) -> bool { matches!( payload, @@ -273,6 +269,10 @@ impl ToolExecutor for ExposureOverride { self.exposure != ToolExposure::Hidden && self.handler.supports_parallel_tool_calls() } + fn search_info(&self) -> Option { + self.handler.search_info() + } + async fn handle( &self, invocation: ToolInvocation, @@ -282,10 +282,6 @@ impl ToolExecutor for ExposureOverride { } impl CoreToolRuntime for ExposureOverride { - fn search_info(&self) -> Option { - self.handler.search_info() - } - fn matches_kind(&self, payload: &ToolPayload) -> bool { self.handler.matches_kind(payload) } diff --git a/codex-rs/core/src/tools/spec_plan.rs b/codex-rs/core/src/tools/spec_plan.rs index c7d9ae5aeb..56d3714074 100644 --- a/codex-rs/core/src/tools/spec_plan.rs +++ b/codex-rs/core/src/tools/spec_plan.rs @@ -72,6 +72,7 @@ use codex_tools::ToolEnvironmentMode; use codex_tools::ToolExecutor; use codex_tools::ToolName; use codex_tools::ToolOutput; +use codex_tools::ToolSearchInfo; use codex_tools::ToolSpec; use codex_tools::UnifiedExecShellMode; use codex_tools::can_request_original_image_detail; @@ -937,6 +938,10 @@ impl ToolExecutor for MultiAgentV2NamespaceOverride { self.handler.supports_parallel_tool_calls() } + fn search_info(&self) -> Option { + self.handler.search_info() + } + async fn handle( &self, invocation: ToolInvocation, @@ -950,10 +955,6 @@ impl CoreToolRuntime for MultiAgentV2NamespaceOverride { self.handler.matches_kind(payload) } - fn search_info(&self) -> Option { - self.handler.search_info() - } - fn create_diff_consumer( &self, ) -> Option> { diff --git a/codex-rs/core/src/tools/spec_plan_tests.rs b/codex-rs/core/src/tools/spec_plan_tests.rs index e129e4ddaa..b75e6d2ed2 100644 --- a/codex-rs/core/src/tools/spec_plan_tests.rs +++ b/codex-rs/core/src/tools/spec_plan_tests.rs @@ -313,6 +313,44 @@ impl ToolExecutor for WebRunExtensionTool { } } +struct DeferredExtensionTool; + +#[async_trait::async_trait] +impl ToolExecutor for DeferredExtensionTool { + fn tool_name(&self) -> ToolName { + ToolName::plain("extension_echo") + } + + fn spec(&self) -> ToolSpec { + ToolSpec::Function(ResponsesApiTool { + name: "extension_echo".to_string(), + description: "Echoes arguments through an extension tool.".to_string(), + strict: true, + defer_loading: None, + parameters: codex_tools::JsonSchema::object( + BTreeMap::from([( + "message".to_string(), + codex_tools::JsonSchema::string(/*description*/ None), + )]), + Some(vec!["message".to_string()]), + Some(false.into()), + ), + output_schema: None, + }) + } + + fn exposure(&self) -> ToolExposure { + ToolExposure::Deferred + } + + async fn handle( + &self, + _call: ExtensionToolCall, + ) -> Result, codex_tools::FunctionCallError> { + panic!("spec planning should not execute extension tools") + } +} + fn duplicate_primary_environment(turn: &mut TurnContext) { let mut second_environment = turn.environments.turn_environments[0].clone(); second_environment.environment_id = "secondary".to_string(); @@ -702,6 +740,25 @@ async fn mcp_and_tool_search_follow_direct_and_deferred_tool_exposure() { ]); } +#[tokio::test] +async fn deferred_extension_tools_are_discoverable_with_tool_search() { + let plan = probe_with( + |turn| { + turn.model_info.supports_search_tool = true; + }, + ToolPlanInputs { + extension_tool_executors: vec![Arc::new(DeferredExtensionTool)], + ..ToolPlanInputs::default() + }, + ) + .await; + + plan.assert_visible_contains(&["tool_search"]); + plan.assert_visible_lacks(&["extension_echo"]); + plan.assert_registered_contains(&["extension_echo"]); + assert_eq!(plan.exposure("extension_echo"), ToolExposure::Deferred); +} + #[tokio::test] async fn invalid_mcp_tools_are_not_registered() { let plan = probe_with( diff --git a/codex-rs/core/src/tools/tool_search_entry.rs b/codex-rs/core/src/tools/tool_search_entry.rs deleted file mode 100644 index 8e37cdcfff..0000000000 --- a/codex-rs/core/src/tools/tool_search_entry.rs +++ /dev/null @@ -1,56 +0,0 @@ -use codex_tools::LoadableToolSpec; -use codex_tools::ResponsesApiNamespaceTool; -use codex_tools::ToolSearchSourceInfo; -use codex_tools::ToolSpec; -use codex_tools::default_namespace_description; - -#[derive(Clone)] -pub(crate) struct ToolSearchEntry { - pub(crate) search_text: String, - pub(crate) output: LoadableToolSpec, -} - -#[derive(Clone)] -pub(crate) struct ToolSearchInfo { - pub(crate) entry: ToolSearchEntry, - pub(crate) source_info: Option, -} - -impl ToolSearchInfo { - pub(crate) fn from_spec( - search_text: String, - spec: ToolSpec, - source_info: Option, - ) -> Option { - let output = match spec { - ToolSpec::Function(mut tool) => { - tool.defer_loading = Some(true); - tool.output_schema = None; - LoadableToolSpec::Function(tool) - } - ToolSpec::Namespace(mut namespace) => { - if namespace.description.trim().is_empty() { - namespace.description = default_namespace_description(&namespace.name); - } - for tool in &mut namespace.tools { - let ResponsesApiNamespaceTool::Function(tool) = tool; - tool.defer_loading = Some(true); - tool.output_schema = None; - } - LoadableToolSpec::Namespace(namespace) - } - ToolSpec::ToolSearch { .. } - | ToolSpec::ImageGeneration { .. } - | ToolSpec::WebSearch { .. } - | ToolSpec::Freeform(_) => return None, - }; - - Some(Self { - entry: ToolSearchEntry { - search_text, - output, - }, - source_info, - }) - } -} diff --git a/codex-rs/tools/src/lib.rs b/codex-rs/tools/src/lib.rs index 3adae5923a..28c4f93bba 100644 --- a/codex-rs/tools/src/lib.rs +++ b/codex-rs/tools/src/lib.rs @@ -17,6 +17,7 @@ mod tool_discovery; mod tool_executor; mod tool_output; mod tool_payload; +mod tool_search; mod tool_spec; pub use code_mode::augment_tool_spec_for_code_mode; @@ -97,6 +98,9 @@ pub use tool_executor::ToolExposure; pub use tool_output::JsonToolOutput; pub use tool_output::ToolOutput; pub use tool_payload::ToolPayload; +pub use tool_search::ToolSearchEntry; +pub use tool_search::ToolSearchInfo; +pub use tool_search::default_tool_search_text; pub use tool_spec::ResponsesApiWebSearchFilters; pub use tool_spec::ResponsesApiWebSearchUserLocation; pub use tool_spec::ToolSpec; diff --git a/codex-rs/tools/src/tool_executor.rs b/codex-rs/tools/src/tool_executor.rs index 1e5a94ee48..541d2443e0 100644 --- a/codex-rs/tools/src/tool_executor.rs +++ b/codex-rs/tools/src/tool_executor.rs @@ -1,6 +1,7 @@ use crate::FunctionCallError; use crate::ToolName; use crate::ToolOutput; +use crate::ToolSearchInfo; use crate::ToolSpec; /// Controls where a tool is exposed to the model. @@ -13,7 +14,9 @@ pub enum ToolExposure { Direct, /// Register this tool for later discovery, but omit it from the initial - /// model-visible tool list. + /// model-visible tool list. Deferred tools must provide search metadata via + /// [`ToolExecutor::search_info`]. The default implementation derives + /// metadata from function and namespace specs. Deferred, /// Include this tool in the initial model-visible tool list only. @@ -48,6 +51,11 @@ pub trait ToolExecutor: Send + Sync { ToolExposure::Direct } + fn search_info(&self) -> Option { + let spec = self.spec(); + ToolSearchInfo::from_tool_spec(&self.tool_name(), spec, /*source_info*/ None) + } + fn supports_parallel_tool_calls(&self) -> bool { false } diff --git a/codex-rs/tools/src/tool_search.rs b/codex-rs/tools/src/tool_search.rs new file mode 100644 index 0000000000..ecb5504d4f --- /dev/null +++ b/codex-rs/tools/src/tool_search.rs @@ -0,0 +1,139 @@ +use crate::JsonSchema; +use crate::LoadableToolSpec; +use crate::ResponsesApiNamespaceTool; +use crate::ResponsesApiTool; +use crate::ToolName; +use crate::ToolSearchSourceInfo; +use crate::ToolSpec; +use crate::default_namespace_description; + +#[derive(Clone)] +pub struct ToolSearchEntry { + pub search_text: String, + pub output: LoadableToolSpec, +} + +#[derive(Clone)] +pub struct ToolSearchInfo { + pub entry: ToolSearchEntry, + pub source_info: Option, +} + +impl ToolSearchInfo { + pub fn from_tool_spec( + tool_name: &ToolName, + spec: ToolSpec, + source_info: Option, + ) -> Option { + let search_text = default_tool_search_text(tool_name, &spec); + Self::from_spec(search_text, spec, source_info) + } + + pub fn from_spec( + search_text: String, + spec: ToolSpec, + source_info: Option, + ) -> Option { + let output = match spec { + ToolSpec::Function(mut tool) => { + tool.defer_loading = Some(true); + tool.output_schema = None; + LoadableToolSpec::Function(tool) + } + ToolSpec::Namespace(mut namespace) => { + if namespace.description.trim().is_empty() { + namespace.description = default_namespace_description(&namespace.name); + } + for tool in &mut namespace.tools { + let ResponsesApiNamespaceTool::Function(tool) = tool; + tool.defer_loading = Some(true); + tool.output_schema = None; + } + LoadableToolSpec::Namespace(namespace) + } + ToolSpec::ToolSearch { .. } + | ToolSpec::ImageGeneration { .. } + | ToolSpec::WebSearch { .. } + | ToolSpec::Freeform(_) => return None, + }; + + Some(Self { + entry: ToolSearchEntry { + search_text, + output, + }, + source_info, + }) + } +} + +pub fn default_tool_search_text(tool_name: &ToolName, spec: &ToolSpec) -> String { + let mut parts = Vec::new(); + push_search_part(&mut parts, tool_name.to_string()); + push_search_part(&mut parts, tool_name.name.replace('_', " ")); + if let Some(namespace) = &tool_name.namespace { + push_search_part(&mut parts, namespace.clone()); + } + + match spec { + ToolSpec::Function(tool) => append_function_search_text(tool, &mut parts), + ToolSpec::Namespace(namespace) => { + push_search_part(&mut parts, namespace.name.clone()); + push_search_part(&mut parts, namespace.description.clone()); + for tool in &namespace.tools { + let ResponsesApiNamespaceTool::Function(tool) = tool; + append_function_search_text(tool, &mut parts); + } + } + ToolSpec::ToolSearch { description, .. } => { + push_search_part(&mut parts, description.clone()); + } + ToolSpec::ImageGeneration { .. } => { + push_search_part(&mut parts, "image generation".to_string()); + } + ToolSpec::WebSearch { .. } => { + push_search_part(&mut parts, "web search".to_string()); + } + ToolSpec::Freeform(tool) => { + push_search_part(&mut parts, tool.name.clone()); + push_search_part(&mut parts, tool.description.clone()); + push_search_part(&mut parts, tool.format.syntax.clone()); + } + } + + parts.join(" ") +} + +fn append_function_search_text(tool: &ResponsesApiTool, parts: &mut Vec) { + push_search_part(parts, tool.name.clone()); + push_search_part(parts, tool.name.replace('_', " ")); + push_search_part(parts, tool.description.clone()); + append_schema_search_text(&tool.parameters, parts); +} + +fn append_schema_search_text(schema: &JsonSchema, parts: &mut Vec) { + if let Some(description) = &schema.description { + push_search_part(parts, description.clone()); + } + if let Some(properties) = &schema.properties { + for (name, schema) in properties { + push_search_part(parts, name.clone()); + append_schema_search_text(schema, parts); + } + } + if let Some(items) = &schema.items { + append_schema_search_text(items, parts); + } + if let Some(variants) = &schema.any_of { + for variant in variants { + append_schema_search_text(variant, parts); + } + } +} + +fn push_search_part(parts: &mut Vec, part: String) { + let part = part.trim(); + if !part.is_empty() { + parts.push(part.to_string()); + } +} From 4e540b107690989ea20832f85cd7f121492f5b74 Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Mon, 1 Jun 2026 19:41:22 -0300 Subject: [PATCH 2/5] fix(tui): clarify footer shortcut overlay hints (#25625) ## Why The TUI shortcut overlay used static labels for `Tab` and `Ctrl+C`, even though both keys change behavior while a task is running. That made the visible help misleading: idle `Tab` submits rather than queues, and active-turn `Ctrl+C` interrupts rather than exits. Closes #25531. Closes #25564. ## What Changed - Pass task-running state into the shortcut overlay renderer. - Render `Tab` as `submit message` while idle and `queue message` while work is running. - Render `Ctrl+C` as `exit` while idle and `interrupt` while work is running. - Add snapshot coverage for the active-work shortcut overlay and update idle overlay snapshots. ## How to Test 1. Start Codex and open the shortcut overlay with `?` while no task is running. 2. Confirm the overlay shows `tab to submit message` and `ctrl + c to exit`. 3. Start a task, then open or keep the shortcut overlay visible while work is running. 4. Confirm the overlay shows `tab to queue message` and `ctrl + c to interrupt`. 5. Type a follow-up prompt during active work and press `Tab`; confirm it queues rather than submitting immediately. Targeted tests: - `just test -p codex-tui footer_snapshots` - `just test -p codex-tui footer_mode_snapshots` ## Validation Notes `just test -p codex-tui` currently has two unrelated guardian feature-flag test failures on this base: - `app::tests::update_feature_flags_disabling_guardian_clears_manual_review_policy_without_history` - `app::tests::update_feature_flags_disabling_guardian_clears_review_policy_and_restores_default` `just argument-comment-lint codex-rs/tui/src/bottom_pane/footer.rs` could not run locally because the prebuilt wrapper requires `dotslash`; the touched Rust diff was manually inspected for opaque positional literals. --- codex-rs/tui/src/bottom_pane/chat_composer.rs | 11 ++++ codex-rs/tui/src/bottom_pane/footer.rs | 61 +++++++++++++++++++ ...__tests__footer_mode_shortcut_overlay.snap | 2 +- ...de_shortcut_overlay_queue_submissions.snap | 21 +++++++ ...shortcuts_collaboration_modes_enabled.snap | 2 +- ...oter__tests__footer_shortcuts_running.snap | 13 ++++ ...tests__footer_shortcuts_shift_and_esc.snap | 2 +- 7 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__footer_mode_shortcut_overlay_queue_submissions.snap create mode 100644 codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__footer__tests__footer_shortcuts_running.snap diff --git a/codex-rs/tui/src/bottom_pane/chat_composer.rs b/codex-rs/tui/src/bottom_pane/chat_composer.rs index ec3284866d..5a39b53aa9 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer.rs @@ -3410,6 +3410,7 @@ impl ChatComposer { esc_backtrack_hint: self.footer.esc_backtrack_hint, use_shift_enter_hint: self.footer.use_shift_enter_hint, is_task_running: self.is_task_running, + queue_submissions: self.queue_submissions, quit_shortcut_key: self.footer.quit_shortcut_key, collaboration_modes_enabled: self.collaboration_modes_enabled, is_wsl, @@ -4691,6 +4692,16 @@ mod tests { }, ); + snapshot_composer_state( + "footer_mode_shortcut_overlay_queue_submissions", + /*enhanced_keys_supported*/ true, + |composer| { + composer.set_queue_submissions(/*queue_submissions*/ true); + let _ = composer + .handle_key_event(KeyEvent::new(KeyCode::Char('?'), KeyModifiers::NONE)); + }, + ); + snapshot_composer_state( "footer_mode_ctrl_c_quit", /*enhanced_keys_supported*/ true, diff --git a/codex-rs/tui/src/bottom_pane/footer.rs b/codex-rs/tui/src/bottom_pane/footer.rs index 8035881e8e..e11534ac82 100644 --- a/codex-rs/tui/src/bottom_pane/footer.rs +++ b/codex-rs/tui/src/bottom_pane/footer.rs @@ -68,6 +68,7 @@ pub(crate) struct FooterProps { pub(crate) esc_backtrack_hint: bool, pub(crate) use_shift_enter_hint: bool, pub(crate) is_task_running: bool, + pub(crate) queue_submissions: bool, pub(crate) collaboration_modes_enabled: bool, pub(crate) is_wsl: bool, /// Which key the user must press again to quit. @@ -742,6 +743,8 @@ fn footer_from_props_lines( let state = ShortcutsState { use_shift_enter_hint: props.use_shift_enter_hint, esc_backtrack_hint: props.esc_backtrack_hint, + is_task_running: props.is_task_running, + queue_submissions: props.queue_submissions, is_wsl: props.is_wsl, collaboration_modes_enabled: props.collaboration_modes_enabled, key_hints, @@ -864,6 +867,8 @@ fn footer_hint_items_line(items: &[(String, String)]) -> Line<'static> { struct ShortcutsState { use_shift_enter_hint: bool, esc_backtrack_hint: bool, + is_task_running: bool, + queue_submissions: bool, is_wsl: bool, collaboration_modes_enabled: bool, key_hints: FooterKeyHints, @@ -1096,6 +1101,13 @@ impl ShortcutDescriptor { }?; let mut line = Line::from(vec![self.prefix.into(), key.into()]); match self.id { + ShortcutId::QueueMessageTab => { + if state.is_task_running || state.queue_submissions { + line.push_span(" to queue message"); + } else { + line.push_span(" to submit message"); + } + } ShortcutId::EditPrevious => { if state.esc_backtrack_hint { line.push_span(" again to edit previous message"); @@ -1107,6 +1119,13 @@ impl ShortcutDescriptor { ]); } } + ShortcutId::Quit => { + if state.is_task_running { + line.push_span(" to interrupt"); + } else { + line.push_span(" to exit"); + } + } _ => line.push_span(self.label), }; Some(line) @@ -1542,6 +1561,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: false, + queue_submissions: false, collaboration_modes_enabled: false, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1559,6 +1579,7 @@ mod tests { esc_backtrack_hint: true, use_shift_enter_hint: true, is_task_running: false, + queue_submissions: false, collaboration_modes_enabled: false, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1579,6 +1600,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: false, + queue_submissions: false, collaboration_modes_enabled: true, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1589,6 +1611,24 @@ mod tests { }, ); + snapshot_footer( + "footer_shortcuts_running", + FooterProps { + mode: FooterMode::ShortcutOverlay, + esc_backtrack_hint: false, + use_shift_enter_hint: false, + is_task_running: true, + queue_submissions: false, + collaboration_modes_enabled: false, + is_wsl: false, + quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), + status_line_value: None, + status_line_enabled: false, + key_hints: FooterKeyHints::default_bindings(), + active_agent_label: None, + }, + ); + snapshot_footer( "footer_ctrl_c_quit_idle", FooterProps { @@ -1596,6 +1636,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: false, + queue_submissions: false, collaboration_modes_enabled: false, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1613,6 +1654,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: true, + queue_submissions: false, collaboration_modes_enabled: false, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1630,6 +1672,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: false, + queue_submissions: false, collaboration_modes_enabled: false, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1647,6 +1690,7 @@ mod tests { esc_backtrack_hint: true, use_shift_enter_hint: false, is_task_running: false, + queue_submissions: false, collaboration_modes_enabled: false, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1664,6 +1708,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: true, + queue_submissions: false, collaboration_modes_enabled: false, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1683,6 +1728,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: false, + queue_submissions: false, collaboration_modes_enabled: false, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1702,6 +1748,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: true, + queue_submissions: false, collaboration_modes_enabled: false, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1717,6 +1764,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: false, + queue_submissions: false, collaboration_modes_enabled: true, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1745,6 +1793,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: true, + queue_submissions: false, collaboration_modes_enabled: true, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1766,6 +1815,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: false, + queue_submissions: false, collaboration_modes_enabled: false, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1782,6 +1832,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: true, + queue_submissions: false, collaboration_modes_enabled: false, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1798,6 +1849,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: false, + queue_submissions: false, collaboration_modes_enabled: false, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1814,6 +1866,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: false, + queue_submissions: false, collaboration_modes_enabled: true, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1844,6 +1897,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: false, + queue_submissions: false, collaboration_modes_enabled: true, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1866,6 +1920,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: false, + queue_submissions: false, collaboration_modes_enabled: false, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1889,6 +1944,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: false, + queue_submissions: false, collaboration_modes_enabled: true, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1913,6 +1969,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: false, + queue_submissions: false, collaboration_modes_enabled: false, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1929,6 +1986,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: false, + queue_submissions: false, collaboration_modes_enabled: false, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -1948,6 +2006,7 @@ mod tests { esc_backtrack_hint: false, use_shift_enter_hint: false, is_task_running: false, + queue_submissions: false, collaboration_modes_enabled: true, is_wsl: false, quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), @@ -2009,6 +2068,8 @@ mod tests { .binding_for(ShortcutsState { use_shift_enter_hint: false, esc_backtrack_hint: false, + is_task_running: false, + queue_submissions: false, is_wsl, collaboration_modes_enabled: false, key_hints: FooterKeyHints::default_bindings(), diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__footer_mode_shortcut_overlay.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__footer_mode_shortcut_overlay.snap index b5508114fe..5239a34bd2 100644 --- a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__footer_mode_shortcut_overlay.snap +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__footer_mode_shortcut_overlay.snap @@ -11,7 +11,7 @@ expression: terminal.backend() " " " " " / for commands ! for shell commands " -" shift + enter for newline tab to queue message " +" shift + enter for newline tab to submit message " " @ for file paths ctrl + v to paste images " " ctrl + g to edit in external editor esc again to edit previous message " " ctrl + r search history ctrl + c to exit " diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__footer_mode_shortcut_overlay_queue_submissions.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__footer_mode_shortcut_overlay_queue_submissions.snap new file mode 100644 index 0000000000..582724eea7 --- /dev/null +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__footer_mode_shortcut_overlay_queue_submissions.snap @@ -0,0 +1,21 @@ +--- +source: tui/src/bottom_pane/chat_composer.rs +expression: terminal.backend() +--- +" " +"› Ask Codex to do anything " +" " +" " +" " +" " +" " +" " +" / for commands ! for shell commands " +" shift + enter for newline tab to queue message " +" @ for file paths ctrl + v to paste images " +" ctrl + g to edit in external editor esc esc to edit previous message " +" ctrl + r search history ctrl + c to exit " +" ⌥ + , reasoning down ⌥ + . reasoning up " +" ctrl + t to view transcript " +" " +" customize shortcuts with /keymap " diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__footer__tests__footer_shortcuts_collaboration_modes_enabled.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__footer__tests__footer_shortcuts_collaboration_modes_enabled.snap index dc2f896096..3b67a90683 100644 --- a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__footer__tests__footer_shortcuts_collaboration_modes_enabled.snap +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__footer__tests__footer_shortcuts_collaboration_modes_enabled.snap @@ -3,7 +3,7 @@ source: tui/src/bottom_pane/footer.rs expression: terminal.backend() --- " / for commands ! for shell commands " -" ctrl + j for newline tab to queue message " +" ctrl + j for newline tab to submit message " " @ for file paths ctrl + v to paste images " " ctrl + g to edit in external editor esc esc to edit previous message " " ctrl + r search history ctrl + c to exit " diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__footer__tests__footer_shortcuts_running.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__footer__tests__footer_shortcuts_running.snap new file mode 100644 index 0000000000..7c733bd13b --- /dev/null +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__footer__tests__footer_shortcuts_running.snap @@ -0,0 +1,13 @@ +--- +source: tui/src/bottom_pane/footer.rs +expression: terminal.backend() +--- +" / for commands ! for shell commands " +" ctrl + j for newline tab to queue message " +" @ for file paths ctrl + v to paste images " +" ctrl + g to edit in external editor esc esc to edit previous message " +" ctrl + r search history ctrl + c to interrupt " +" ⌥ + , reasoning down ⌥ + . reasoning up " +" ctrl + t to view transcript " +" " +" customize shortcuts with /keymap " diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__footer__tests__footer_shortcuts_shift_and_esc.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__footer__tests__footer_shortcuts_shift_and_esc.snap index 52c26826e9..07e9706283 100644 --- a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__footer__tests__footer_shortcuts_shift_and_esc.snap +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__footer__tests__footer_shortcuts_shift_and_esc.snap @@ -3,7 +3,7 @@ source: tui/src/bottom_pane/footer.rs expression: terminal.backend() --- " / for commands ! for shell commands " -" shift + enter for newline tab to queue message " +" shift + enter for newline tab to submit message " " @ for file paths ctrl + v to paste images " " ctrl + g to edit in external editor esc again to edit previous message " " ctrl + r search history ctrl + c to exit " From 75a08def9808ed5b77b458d09c2fe99f2b52c433 Mon Sep 17 00:00:00 2001 From: Jeremy Rose <172423086+nornagon-openai@users.noreply.github.com> Date: Mon, 1 Jun 2026 15:49:54 -0700 Subject: [PATCH 3/5] [codex] Publish release symbol artifacts (#25649) ## Why Production Codex binaries are stripped for distribution, which leaves crashes and samples from released builds without the symbols needed for useful stack traces. Publish symbols as separate release assets so production artifacts stay small while released builds remain symbolicateable. ## What changed - Add `.github/scripts/archive-release-symbols-and-strip-binaries.sh` to package platform-native symbols into `codex-symbols-.tar.gz` assets while stripping the corresponding Unix binaries before signing. - Build release binaries with full debug information before producing distribution artifacts. - Publish macOS `.dSYM` bundles, Linux `.debug` files with `.gnu_debuglink`, and Windows `.pdb` files. - Strip Linux `bwrap` before computing its packaged-resource digest, but intentionally omit `bwrap` from symbol archives. - Preserve symbols artifacts in the unsigned macOS promotion flow. ## Verification - Ran `shellcheck` and `bash -n` on `.github/scripts/archive-release-symbols-and-strip-binaries.sh`. - Parsed the modified workflow YAML files and ran `git diff --check`. - Built a macOS release smoke binary and verified that the archived `.dSYM` contains DWARF application source information and has the same UUID as the stripped production binary. - Built Linux smoke binaries and verified that the symbol archive contains `codex.debug`, excludes `bwrap.debug`, leaves the expected `.gnu_debuglink` in `codex`, and does not mutate the separately stripped `bwrap` digest. - Staged a Windows smoke archive and verified that it contains the expected `.pdb` file. --- ...hive-release-symbols-and-strip-binaries.sh | 119 ++++++++++++++++++ .github/workflows/rust-release-windows.yml | 20 +++ .github/workflows/rust-release.yml | 41 +++++- 3 files changed, 179 insertions(+), 1 deletion(-) create mode 100755 .github/scripts/archive-release-symbols-and-strip-binaries.sh diff --git a/.github/scripts/archive-release-symbols-and-strip-binaries.sh b/.github/scripts/archive-release-symbols-and-strip-binaries.sh new file mode 100755 index 0000000000..3e5894bb99 --- /dev/null +++ b/.github/scripts/archive-release-symbols-and-strip-binaries.sh @@ -0,0 +1,119 @@ +#!/usr/bin/env bash +set -euo pipefail + +usage() { + cat <<'EOF' +Usage: archive-release-symbols-and-strip-binaries.sh \ + --target \ + --artifact-name \ + --release-dir \ + --archive-dir \ + --binaries "" +EOF +} + +target="" +artifact_name="" +release_dir="" +archive_dir="" +binaries="" + +while [[ $# -gt 0 ]]; do + case "$1" in + --target) + target="${2:?--target requires a value}" + shift 2 + ;; + --artifact-name) + artifact_name="${2:?--artifact-name requires a value}" + shift 2 + ;; + --release-dir) + release_dir="${2:?--release-dir requires a value}" + shift 2 + ;; + --archive-dir) + archive_dir="${2:?--archive-dir requires a value}" + shift 2 + ;; + --binaries) + binaries="${2:?--binaries requires a value}" + shift 2 + ;; + -h|--help) + usage + exit 0 + ;; + *) + echo "Unexpected argument: $1" >&2 + usage >&2 + exit 1 + ;; + esac +done + +if [[ -z "$target" || -z "$artifact_name" || -z "$release_dir" || -z "$archive_dir" || -z "$binaries" ]]; then + usage >&2 + exit 1 +fi + +symbols_root="${RUNNER_TEMP:-/tmp}/codex-symbols-${artifact_name}" +symbols_dir="${symbols_root}/codex-symbols-${artifact_name}" +archive_path="${archive_dir%/}/codex-symbols-${artifact_name}.tar.gz" +rm -rf "$symbols_root" +mkdir -p "$symbols_dir" "$archive_dir" +read -r -a binary_names <<< "$binaries" + +case "$target" in + *apple-darwin) + for binary in "${binary_names[@]}"; do + binary_path="${release_dir%/}/${binary}" + dsym_path="${binary_path}.dSYM" + if [[ ! -f "$binary_path" ]]; then + echo "Binary $binary_path not found" >&2 + exit 1 + fi + if [[ ! -d "$dsym_path" ]]; then + echo "dSYM $dsym_path not found" >&2 + exit 1 + fi + + cp -RL "$dsym_path" "${symbols_dir}/${binary}.dSYM" + strip -S -x "$binary_path" + done + ;; + *linux*) + objcopy_bin="${OBJCOPY:-objcopy}" + strip_bin="${STRIP:-strip}" + for binary in "${binary_names[@]}"; do + binary_path="${release_dir%/}/${binary}" + debug_path="${symbols_dir}/${binary}.debug" + if [[ ! -f "$binary_path" ]]; then + echo "Binary $binary_path not found" >&2 + exit 1 + fi + + "$objcopy_bin" --only-keep-debug "$binary_path" "$debug_path" + "$strip_bin" --strip-debug --strip-unneeded "$binary_path" + "$objcopy_bin" --add-gnu-debuglink="$debug_path" "$binary_path" + done + ;; + *windows*) + for binary in "${binary_names[@]}"; do + pdb_path="${release_dir%/}/${binary}.pdb" + if [[ ! -f "$pdb_path" ]]; then + echo "PDB $pdb_path not found" >&2 + exit 1 + fi + + cp "$pdb_path" "${symbols_dir}/${binary}.pdb" + done + ;; + *) + echo "No symbols packaging support for target: $target" >&2 + exit 1 + ;; +esac + +rm -f "$archive_path" +tar -C "$symbols_root" -czf "$archive_path" "codex-symbols-${artifact_name}" diff --git a/.github/workflows/rust-release-windows.yml b/.github/workflows/rust-release-windows.yml index 3b4d3cfebf..91887cbe0b 100644 --- a/.github/workflows/rust-release-windows.yml +++ b/.github/workflows/rust-release-windows.yml @@ -34,6 +34,8 @@ jobs: working-directory: codex-rs env: CARGO_PROFILE_RELEASE_LTO: ${{ inputs.release-lto }} + CARGO_PROFILE_RELEASE_DEBUG: full + CARGO_PROFILE_RELEASE_STRIP: "false" strategy: fail-fast: false @@ -131,6 +133,7 @@ jobs: mkdir -p "$output_dir" for binary in ${{ matrix.binaries }}; do cp "target/${{ matrix.target }}/release/${binary}.exe" "$output_dir/${binary}.exe" + cp "target/${{ matrix.target }}/release/${binary}.pdb" "$output_dir/${binary}.pdb" done - name: Upload Windows binaries @@ -213,6 +216,23 @@ jobs: account-name: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }} certificate-profile-name: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME }} + - name: Build symbols archive + shell: bash + run: | + bash "${GITHUB_WORKSPACE}/.github/scripts/archive-release-symbols-and-strip-binaries.sh" \ + --target "${{ matrix.target }}" \ + --artifact-name "${{ matrix.target }}" \ + --release-dir "target/${{ matrix.target }}/release" \ + --archive-dir "symbols-dist/${{ matrix.target }}" \ + --binaries "${WINDOWS_BINARIES}" + + - name: Upload symbols archive + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 + with: + name: ${{ matrix.target }}-symbols + path: codex-rs/symbols-dist/${{ matrix.target }}/* + if-no-files-found: error + - name: Stage artifacts shell: bash run: | diff --git a/.github/workflows/rust-release.yml b/.github/workflows/rust-release.yml index db72ab830f..364fe78902 100644 --- a/.github/workflows/rust-release.yml +++ b/.github/workflows/rust-release.yml @@ -149,6 +149,9 @@ jobs: # 2026-03-04: temporarily change releases to use thin LTO because # Ubuntu ARM is timing out at 60 minutes. CARGO_PROFILE_RELEASE_LTO: ${{ contains(github.ref_name, '-alpha') && 'thin' || 'thin' }} + CARGO_PROFILE_RELEASE_DEBUG: full + CARGO_PROFILE_RELEASE_SPLIT_DEBUGINFO: ${{ contains(matrix.target, 'apple-darwin') && 'packed' || 'off' }} + CARGO_PROFILE_RELEASE_STRIP: "false" # Use the git CLI instead of Cargo's libgit2 path for git dependencies. # macOS release runners have intermittently failed to fetch nested # submodules through SecureTransport/libgit2, especially libwebrtc's @@ -249,7 +252,7 @@ jobs: run: | set -euo pipefail sudo apt-get update -y - sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends pkg-config libcap-dev + sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends binutils pkg-config libcap-dev - uses: dtolnay/rust-toolchain@e081816240890017053eacbb1bdf337761dc5582 # 1.95.0 with: targets: ${{ matrix.target }} @@ -308,6 +311,10 @@ jobs: exit 1 fi + # Codex embeds this digest at build time and verifies the bundled + # bwrap resource before use. Strip bwrap before hashing so the digest + # covers the exact bytes that the release packages. + strip --strip-debug --strip-unneeded "$bwrap_path" digest="$(sha256sum "$bwrap_path" | awk '{print $1}')" echo "CODEX_BWRAP_SHA256=${digest}" >> "$GITHUB_ENV" echo "Built bwrap ${bwrap_path} with sha256:${digest}" @@ -321,6 +328,11 @@ jobs: fi build_args=() for binary in ${{ matrix.binaries }}; do + # bwrap was built, finalized, and hashed before this build so + # Codex can embed the digest of the bytes that will be packaged. + if [[ "$binary" == "bwrap" ]]; then + continue + fi build_args+=(--bin "$binary") done echo "CARGO_PROFILE_RELEASE_LTO: ${CARGO_PROFILE_RELEASE_LTO}" @@ -333,6 +345,32 @@ jobs: path: codex-rs/target/**/cargo-timings/cargo-timing.html if-no-files-found: warn + - name: Build symbols archive and strip binaries + shell: bash + run: | + binaries=() + for binary in ${{ matrix.binaries }}; do + # bwrap is already stripped before hashing. Its symbols are not + # useful enough to justify a separate pre-Codex symbols pass. + if [[ "$binary" == "bwrap" ]]; then + continue + fi + binaries+=("$binary") + done + bash "${GITHUB_WORKSPACE}/.github/scripts/archive-release-symbols-and-strip-binaries.sh" \ + --target "${{ matrix.target }}" \ + --artifact-name "${{ matrix.artifact_name }}" \ + --release-dir "target/${{ matrix.target }}/release" \ + --archive-dir "symbols-dist/${{ matrix.artifact_name }}" \ + --binaries "${binaries[*]}" + + - name: Upload symbols archive + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 + with: + name: ${{ matrix.artifact_name }}-symbols + path: codex-rs/symbols-dist/${{ matrix.artifact_name }}/* + if-no-files-found: error + - if: ${{ runner.os == 'macOS' && env.SIGN_MACOS != 'true' }} name: Stage unsigned macOS artifacts shell: bash @@ -1031,6 +1069,7 @@ jobs: run: | find dist -mindepth 1 -maxdepth 1 -type d \ ! -name '*-apple-darwin*-unsigned' \ + ! -name '*-symbols' \ ! -name 'aarch64-unknown-linux-musl' \ ! -name 'aarch64-unknown-linux-musl-app-server' \ ! -name 'x86_64-unknown-linux-musl' \ From b89bf1ef47240cff4d646caca6f8f9ca223c5ca4 Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Mon, 1 Jun 2026 16:02:06 -0700 Subject: [PATCH 4/5] Reject directory rollout paths for pathless side chats (#25661) ## Why Fixes openai/codex#20944. Desktop side chats are intentionally ephemeral and pathless. They can still accept live turns while loaded, but after a reload there is no persisted rollout to resume. In the reported failure mode, Desktop could send `$CODEX_HOME` as the resume/fork path for one of these pathless side chats. `thread/resume` and `thread/fork` prefer an explicit `path` over `threadId`, and rollout path lookup only checked that a candidate existed. That let `$CODEX_HOME` pass as a rollout path, so the later rollout reader tried to open a directory and surfaced the low-level `Is a directory` error. ## What Changed - Reject explicit rollout paths that resolve to a directory or other non-file before attempting to read rollout history. - Make `codex_rollout::existing_rollout_path` return only plain or compressed rollout candidates that are actual files. - Add an app-server regression test that creates an ephemeral fork, runs a turn while the side thread is loaded, simulates reload, then verifies both `thread/resume` and `thread/fork` reject `$CODEX_HOME` with `path is a directory` instead of the OS-level directory-read error. - Rebase over the `TestAppServer` rename and update the remaining stale test harness call sites to use `TestAppServer` with `app_server` local variables. Relevant code: - `thread-store/src/local/read_thread.rs` validates explicit rollout paths before rollout reading: https://github.com/openai/codex/blob/25b47c8f425d351aaba4baa955a8092064a1707b/codex-rs/thread-store/src/local/read_thread.rs#L146-L165 - `rollout/src/compression.rs` now requires file metadata for plain and compressed rollout candidates: https://github.com/openai/codex/blob/25b47c8f425d351aaba4baa955a8092064a1707b/codex-rs/rollout/src/compression.rs#L940-L950 - The repro test covers the pathless ephemeral side-chat reload case: https://github.com/openai/codex/blob/25b47c8f425d351aaba4baa955a8092064a1707b/codex-rs/app-server/tests/suite/v2/thread_fork.rs#L774-L886 ## Verification - `just test -p codex-app-server pathless_ephemeral_thread_rejects_codex_home_path_after_reload` --- .../app-server/tests/suite/v2/thread_fork.rs | 115 ++++++++++++++++++ codex-rs/rollout/src/compression.rs | 8 +- .../thread-store/src/local/read_thread.rs | 19 +++ 3 files changed, 136 insertions(+), 6 deletions(-) diff --git a/codex-rs/app-server/tests/suite/v2/thread_fork.rs b/codex-rs/app-server/tests/suite/v2/thread_fork.rs index 57a24fc9e7..f89c9ec5e2 100644 --- a/codex-rs/app-server/tests/suite/v2/thread_fork.rs +++ b/codex-rs/app-server/tests/suite/v2/thread_fork.rs @@ -17,6 +17,7 @@ use codex_app_server_protocol::ThreadForkResponse; use codex_app_server_protocol::ThreadItem; use codex_app_server_protocol::ThreadListParams; use codex_app_server_protocol::ThreadListResponse; +use codex_app_server_protocol::ThreadResumeParams; use codex_app_server_protocol::ThreadSource; use codex_app_server_protocol::ThreadStartParams; use codex_app_server_protocol::ThreadStartResponse; @@ -770,6 +771,120 @@ async fn thread_fork_ephemeral_remains_pathless_and_omits_listing() -> Result<() Ok(()) } +#[tokio::test] +async fn pathless_ephemeral_thread_rejects_codex_home_path_after_reload() -> Result<()> { + let server = create_mock_responses_server_repeating_assistant("Done").await; + let codex_home = TempDir::new()?; + create_config_toml(codex_home.path(), &server.uri())?; + + let parent_thread_id = create_fake_rollout( + codex_home.path(), + "2025-01-05T12-00-00", + "2025-01-05T12:00:00Z", + "Parent message", + Some("mock_provider"), + /*git_info*/ None, + )?; + + let side_thread_id = { + let mut app_server = TestAppServer::new(codex_home.path()).await?; + timeout(DEFAULT_READ_TIMEOUT, app_server.initialize()).await??; + + let fork_id = app_server + .send_thread_fork_request(ThreadForkParams { + thread_id: parent_thread_id, + ephemeral: true, + ..Default::default() + }) + .await?; + let fork_resp: JSONRPCResponse = timeout( + DEFAULT_READ_TIMEOUT, + app_server.read_stream_until_response_message(RequestId::Integer(fork_id)), + ) + .await??; + let ThreadForkResponse { thread, .. } = to_response::(fork_resp)?; + assert!(thread.ephemeral); + assert_eq!(thread.path, None); + + let turn_id = app_server + .send_turn_start_request(TurnStartParams { + thread_id: thread.id.clone(), + client_user_message_id: None, + input: vec![UserInput::Text { + text: "continue".to_string(), + text_elements: Vec::new(), + }], + ..Default::default() + }) + .await?; + let turn_resp: JSONRPCResponse = timeout( + DEFAULT_READ_TIMEOUT, + app_server.read_stream_until_response_message(RequestId::Integer(turn_id)), + ) + .await??; + let _: TurnStartResponse = to_response::(turn_resp)?; + timeout( + DEFAULT_READ_TIMEOUT, + app_server.read_stream_until_notification_message("turn/completed"), + ) + .await??; + + thread.id + }; + + let mut app_server = TestAppServer::new(codex_home.path()).await?; + timeout(DEFAULT_READ_TIMEOUT, app_server.initialize()).await??; + let codex_home_path = codex_home.path().to_path_buf(); + + let resume_id = app_server + .send_thread_resume_request(ThreadResumeParams { + thread_id: side_thread_id.clone(), + path: Some(codex_home_path.clone()), + ..Default::default() + }) + .await?; + let resume_err: JSONRPCError = timeout( + DEFAULT_READ_TIMEOUT, + app_server.read_stream_until_error_message(RequestId::Integer(resume_id)), + ) + .await??; + assert!( + resume_err.error.message.contains("path is a directory"), + "unexpected resume error: {}", + resume_err.error.message + ); + assert!( + !resume_err.error.message.contains("Is a directory"), + "resume should reject the directory before rollout reading: {}", + resume_err.error.message + ); + + let fork_id = app_server + .send_thread_fork_request(ThreadForkParams { + thread_id: side_thread_id, + path: Some(codex_home_path), + ..Default::default() + }) + .await?; + let fork_err: JSONRPCError = timeout( + DEFAULT_READ_TIMEOUT, + app_server.read_stream_until_error_message(RequestId::Integer(fork_id)), + ) + .await??; + assert!( + fork_err.error.message.contains("path is a directory"), + "unexpected fork error: {}", + fork_err.error.message + ); + assert!( + !fork_err.error.message.contains("Is a directory"), + "fork should reject the directory before rollout reading: {}", + fork_err.error.message + ); + + Ok(()) +} + // Helper to create a config.toml pointing at the mock model server. fn create_config_toml(codex_home: &Path, server_uri: &str) -> std::io::Result<()> { let config_toml = codex_home.join("config.toml"); diff --git a/codex-rs/rollout/src/compression.rs b/codex-rs/rollout/src/compression.rs index 9fafc749d2..5f0023432c 100644 --- a/codex-rs/rollout/src/compression.rs +++ b/codex-rs/rollout/src/compression.rs @@ -939,16 +939,12 @@ mod path { pub(super) async fn existing_rollout_path(path: &Path) -> Option { let plain_path = plain_rollout_path(path); - if tokio::fs::try_exists(plain_path.as_path()) - .await - .unwrap_or(false) + if matches!(tokio::fs::metadata(plain_path.as_path()).await, Ok(metadata) if metadata.is_file()) { return Some(plain_path); } let compressed_path = compressed_rollout_path(plain_path.as_path()); - if tokio::fs::try_exists(compressed_path.as_path()) - .await - .unwrap_or(false) + if matches!(tokio::fs::metadata(compressed_path.as_path()).await, Ok(metadata) if metadata.is_file()) { return Some(compressed_path); } diff --git a/codex-rs/thread-store/src/local/read_thread.rs b/codex-rs/thread-store/src/local/read_thread.rs index e960bbd626..52c8eb7a38 100644 --- a/codex-rs/thread-store/src/local/read_thread.rs +++ b/codex-rs/thread-store/src/local/read_thread.rs @@ -143,6 +143,25 @@ async fn resolve_requested_rollout_path( } else { rollout_path }; + match tokio::fs::metadata(path.as_path()).await { + Ok(metadata) if metadata.is_dir() => { + return Err(ThreadStoreError::InvalidRequest { + message: format!( + "failed to resolve rollout path `{}`: path is a directory", + path.display() + ), + }); + } + Ok(metadata) if !metadata.is_file() => { + return Err(ThreadStoreError::InvalidRequest { + message: format!( + "failed to resolve rollout path `{}`: path is not a file", + path.display() + ), + }); + } + _ => {} + } let Some(path) = codex_rollout::existing_rollout_path(path.as_path()).await else { return Err(ThreadStoreError::InvalidRequest { message: format!( From 9c3af9af8ddabe00977600c07c60784453cfc410 Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Mon, 1 Jun 2026 18:05:53 -0700 Subject: [PATCH 5/5] core: merge built-in permission profiles as TOML --- codex-rs/core/src/config/config_tests.rs | 32 ++++++++- codex-rs/core/src/config/permissions.rs | 91 +++++++++++++++--------- 2 files changed, 87 insertions(+), 36 deletions(-) diff --git a/codex-rs/core/src/config/config_tests.rs b/codex-rs/core/src/config/config_tests.rs index 70719843ba..eecb784093 100644 --- a/codex-rs/core/src/config/config_tests.rs +++ b/codex-rs/core/src/config/config_tests.rs @@ -2356,7 +2356,13 @@ async fn default_permissions_profile_can_extend_builtin_workspace() -> std::io:: description: None, extends: Some(BUILT_IN_PERMISSION_PROFILE_WORKSPACE.to_string()), workspace_roots: None, - filesystem: None, + filesystem: Some(FilesystemPermissionsToml { + glob_scan_max_depth: None, + entries: BTreeMap::from([( + ":tmpdir".to_string(), + FilesystemPermissionToml::Access(FileSystemAccessMode::Read), + )]), + }), network: Some(NetworkToml { enabled: Some(true), ..Default::default() @@ -2383,6 +2389,30 @@ async fn default_permissions_profile_can_extend_builtin_workspace() -> std::io:: !policy.can_write_path_with_cwd(&cwd.path().join(".git"), cwd.path()), "expected profile extending :workspace to keep metadata carveouts, policy: {policy:?}" ); + assert!( + policy.entries.iter().any(|entry| matches!( + entry, + FileSystemSandboxEntry { + path: FileSystemPath::Special { + value: FileSystemSpecialPath::Tmpdir, + }, + access: FileSystemAccessMode::Read, + } + )), + "expected child :tmpdir read entry to replace the inherited write entry, policy: {policy:?}" + ); + assert!( + !policy.entries.iter().any(|entry| matches!( + entry, + FileSystemSandboxEntry { + path: FileSystemPath::Special { + value: FileSystemSpecialPath::Tmpdir, + }, + access: FileSystemAccessMode::Write, + } + )), + "expected inherited :tmpdir write entry to be removed, policy: {policy:?}" + ); assert_eq!( config.permissions.network_sandbox_policy(), NetworkSandboxPolicy::Enabled diff --git a/codex-rs/core/src/config/permissions.rs b/codex-rs/core/src/config/permissions.rs index a8546858f1..12aebf16d9 100644 --- a/codex-rs/core/src/config/permissions.rs +++ b/codex-rs/core/src/config/permissions.rs @@ -1,4 +1,5 @@ use std::borrow::Cow; +use std::collections::BTreeMap; use std::io; use std::path::Component; use std::path::Path; @@ -196,25 +197,59 @@ pub(crate) fn resolve_permission_profile( profile_name: &str, ) -> io::Result { permissions - .resolve_profile(profile_name, extensible_builtin_parent_profile_marker) + .resolve_profile(profile_name, extensible_builtin_parent_profile) .map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err.to_string())) } -/// Built-in parents provide their runtime permissions below. Resolution only -/// needs an empty profile marker so inheritance can terminate while preserving -/// the built-in parent id in `inherited_profile_names`. -fn extensible_builtin_parent_profile_marker(profile_name: &str) -> Option { - matches!( - profile_name, - BUILT_IN_READ_ONLY_PROFILE | BUILT_IN_WORKSPACE_PROFILE - ) - .then_some(PermissionProfileToml { - description: None, - extends: None, - workspace_roots: None, - filesystem: None, - network: None, - }) +fn extensible_builtin_parent_profile(profile_name: &str) -> Option { + match profile_name { + BUILT_IN_READ_ONLY_PROFILE => Some(PermissionProfileToml { + description: None, + extends: None, + workspace_roots: None, + filesystem: Some(FilesystemPermissionsToml { + glob_scan_max_depth: None, + entries: BTreeMap::from([( + ":root".to_string(), + FilesystemPermissionToml::Access(FileSystemAccessMode::Read), + )]), + }), + network: None, + }), + BUILT_IN_WORKSPACE_PROFILE => Some(PermissionProfileToml { + description: None, + extends: None, + workspace_roots: None, + filesystem: Some(FilesystemPermissionsToml { + glob_scan_max_depth: None, + entries: BTreeMap::from([ + ( + ":root".to_string(), + FilesystemPermissionToml::Access(FileSystemAccessMode::Read), + ), + ( + ":workspace_roots".to_string(), + FilesystemPermissionToml::Scoped(BTreeMap::from([ + (".".to_string(), FileSystemAccessMode::Write), + (".git".to_string(), FileSystemAccessMode::Read), + (".agents".to_string(), FileSystemAccessMode::Read), + (".codex".to_string(), FileSystemAccessMode::Read), + ])), + ), + ( + ":slash_tmp".to_string(), + FilesystemPermissionToml::Access(FileSystemAccessMode::Write), + ), + ( + ":tmpdir".to_string(), + FilesystemPermissionToml::Access(FileSystemAccessMode::Write), + ), + ]), + }), + network: None, + }), + _ => None, + } } pub(crate) fn network_proxy_config_for_profile_selection( @@ -244,25 +279,10 @@ pub(crate) fn compile_permission_profile( policy_cwd: &Path, startup_warnings: &mut Vec, ) -> io::Result<(FileSystemSandboxPolicy, NetworkSandboxPolicy)> { - let ResolvedPermissionProfileToml { - profile, - inherited_profile_names, - } = resolve_permission_profile(permissions, profile_name)?; - let base_permissions = inherited_profile_names.iter().find_map(|name| { - match name.as_str() { - BUILT_IN_READ_ONLY_PROFILE => Some(PermissionProfile::read_only()), - BUILT_IN_WORKSPACE_PROFILE => Some(PermissionProfile::workspace_write()), - _ => None, - } - .map(|profile| profile.to_runtime_permissions()) - }); - let (mut file_system_sandbox_policy, base_network_sandbox_policy) = base_permissions - .unwrap_or_else(|| { - ( - FileSystemSandboxPolicy::restricted(Vec::new()), - NetworkSandboxPolicy::Restricted, - ) - }); + let ResolvedPermissionProfileToml { profile, .. } = + resolve_permission_profile(permissions, profile_name)?; + let mut file_system_sandbox_policy = FileSystemSandboxPolicy::restricted(Vec::new()); + let base_network_sandbox_policy = NetworkSandboxPolicy::Restricted; if let Some(filesystem) = profile.filesystem.as_ref() { if filesystem.is_empty() && file_system_sandbox_policy.entries.is_empty() { push_warning( @@ -693,6 +713,7 @@ fn parse_special_path(path: &str) -> Option { ":minimal" => Some(FileSystemSpecialPath::Minimal), ":workspace_roots" => Some(FileSystemSpecialPath::project_roots(/*subpath*/ None)), ":tmpdir" => Some(FileSystemSpecialPath::Tmpdir), + ":slash_tmp" => Some(FileSystemSpecialPath::SlashTmp), _ if path.starts_with(':') => { Some(FileSystemSpecialPath::unknown(path, /*subpath*/ None)) }