mirror of
https://github.com/openai/codex.git
synced 2026-05-29 15:30:22 +00:00
## Why `codex-tools` is meant to hold reusable tool primitives, but `ToolsConfig` had become a second copy of core runtime decisions instead of a small shared contract. It carried provider capabilities, auth/model gates, permission and environment state, web/search/image feature gates, multi-agent settings, and goal availability from core into `codex-tools` ([definition](22dd9ad392/codex-rs/tools/src/tool_config.rs (L97)), [stored on each `TurnContext`](22dd9ad392/codex-rs/core/src/session/turn_context.rs (L87))). Every session/context variant then had to build and mutate that snapshot before assembling tools. This PR removes that master object instead of renaming it. Tool planning now reads the live `TurnContext`, where `codex-core` already owns those decisions, while `codex-tools` keeps only reusable primitives and a generic `ToolSetBuilder`/`ToolSet` accumulator. ## What Changed - Removed `ToolsConfig` / `ToolsConfigParams` from `codex-tools`; the crate keeps the shared helpers that still belong there, including request-user-input mode selection, shell backend/type resolution, `UnifiedExecShellMode`, and `ToolEnvironmentMode`. - Replaced config-snapshot planning with `ToolRouter::from_turn_context` and a `spec_plan` pipeline over `CoreToolPlanContext`, deriving provider capabilities, auth gates, model support, feature gates, environment count, goal support, multi-agent options, web search, and image generation from the authoritative turn state. - Added generic `codex_tools::ToolSetBuilder` / `ToolSet`, plus the small core adapter needed to accumulate `CoreToolRuntime` values and hosted model specs. - Added the `tool_family::shell` registration module and moved shell/unified-exec/memory accounting call sites to read the narrow per-turn fields directly. - Narrowed `TurnContext` to the remaining explicit per-turn fields needed by planning: `available_models`, `unified_exec_shell_mode`, and `goal_tools_supported`. - Reworked MCP exposure and tool-search setup so deferred/direct MCP behavior is driven by the current turn rather than a precomputed config snapshot. - Replaced the large expected-spec fixture tests with focused behavior-level coverage for shell tools, environments, goal and agent-job gates, MCP direct/deferred exposure, tool search, request-plugin-install, code mode, multi-agent mode, hosted tools, and extension executor dispatch. ## Verification - `cargo check -p codex-tools` - `cargo check -p codex-core --lib` - `cargo test -p codex-tools` - `cargo test -p codex-core spec_plan --lib` - `cargo test -p codex-core router --lib`
87 lines
2.3 KiB
Rust
87 lines
2.3 KiB
Rust
use std::collections::HashSet;
|
|
|
|
use codex_features::Feature;
|
|
use codex_mcp::CODEX_APPS_MCP_SERVER_NAME;
|
|
use codex_mcp::ToolInfo as McpToolInfo;
|
|
|
|
use crate::config::Config;
|
|
use crate::connectors;
|
|
|
|
pub(crate) const DIRECT_MCP_TOOL_EXPOSURE_THRESHOLD: usize = 100;
|
|
|
|
pub(crate) struct McpToolExposure {
|
|
pub(crate) direct_tools: Vec<McpToolInfo>,
|
|
pub(crate) deferred_tools: Option<Vec<McpToolInfo>>,
|
|
}
|
|
|
|
pub(crate) fn build_mcp_tool_exposure(
|
|
all_mcp_tools: &[McpToolInfo],
|
|
connectors: Option<&[connectors::AppInfo]>,
|
|
config: &Config,
|
|
search_tool_enabled: bool,
|
|
) -> McpToolExposure {
|
|
let mut deferred_tools = filter_non_codex_apps_mcp_tools_only(all_mcp_tools);
|
|
if let Some(connectors) = connectors {
|
|
deferred_tools.extend(filter_codex_apps_mcp_tools(
|
|
all_mcp_tools,
|
|
connectors,
|
|
config,
|
|
));
|
|
}
|
|
|
|
let should_defer = search_tool_enabled
|
|
&& (config
|
|
.features
|
|
.enabled(Feature::ToolSearchAlwaysDeferMcpTools)
|
|
|| deferred_tools.len() >= DIRECT_MCP_TOOL_EXPOSURE_THRESHOLD);
|
|
|
|
if !should_defer {
|
|
return McpToolExposure {
|
|
direct_tools: deferred_tools,
|
|
deferred_tools: None,
|
|
};
|
|
}
|
|
|
|
McpToolExposure {
|
|
direct_tools: Vec::new(),
|
|
deferred_tools: (!deferred_tools.is_empty()).then_some(deferred_tools),
|
|
}
|
|
}
|
|
|
|
fn filter_non_codex_apps_mcp_tools_only(mcp_tools: &[McpToolInfo]) -> Vec<McpToolInfo> {
|
|
mcp_tools
|
|
.iter()
|
|
.filter(|tool| tool.server_name != CODEX_APPS_MCP_SERVER_NAME)
|
|
.cloned()
|
|
.collect()
|
|
}
|
|
|
|
fn filter_codex_apps_mcp_tools(
|
|
mcp_tools: &[McpToolInfo],
|
|
connectors: &[connectors::AppInfo],
|
|
config: &Config,
|
|
) -> Vec<McpToolInfo> {
|
|
let allowed: HashSet<&str> = connectors
|
|
.iter()
|
|
.map(|connector| connector.id.as_str())
|
|
.collect();
|
|
|
|
mcp_tools
|
|
.iter()
|
|
.filter(|tool| {
|
|
if tool.server_name != CODEX_APPS_MCP_SERVER_NAME {
|
|
return false;
|
|
}
|
|
let Some(connector_id) = tool.connector_id.as_deref() else {
|
|
return false;
|
|
};
|
|
allowed.contains(connector_id) && connectors::codex_app_tool_is_enabled(config, tool)
|
|
})
|
|
.cloned()
|
|
.collect()
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "mcp_tool_exposure_test.rs"]
|
|
mod tests;
|