From 4e119a3b38e4a4decfccb003acecabc4614142b6 Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Sat, 28 Mar 2026 16:33:58 -0700 Subject: [PATCH] codex-tools: extract local host tool specs (#16138) ## Why `core/src/tools/spec.rs` still bundled a set of pure local-host tool builders with the orchestration that actually decides when those tools are exposed and which handlers back them. That made `codex-core` responsible for JSON/tool-shape construction that does not depend on session state, and it kept the `codex-tools` migration from taking a meaningfully larger bite out of `spec.rs`. This PR moves that reusable spec-building layer into `codex-tools` while leaving feature gating, handler registration, and runtime-coupled descriptions in `codex-core`. ## What changed - added `codex-rs/tools/src/local_tool.rs` for the pure builders for `exec_command`, `write_stdin`, `shell`, `shell_command`, and `request_permissions` - added `codex-rs/tools/src/view_image.rs` for the `view_image` tool spec and output schema so the extracted modules stay right-sized - rewired `codex-rs/core/src/tools/spec.rs` to call those extracted builders instead of constructing these specs inline - kept the `request_permissions` description source in `codex-core`, with `codex-tools` taking the description as input so the crate boundary does not grow a dependency on handler/runtime code - moved the direct constructor coverage for this slice from `codex-rs/core/src/tools/spec_tests.rs` into `codex-rs/tools/src/local_tool_tests.rs` and `codex-rs/tools/src/view_image_tests.rs` - updated `codex-rs/tools/README.md` to reflect that `codex-tools` now owns this local-host spec layer ## Test plan - `CARGO_TARGET_DIR=/tmp/codex-tools-local-host cargo test -p codex-tools` - `CARGO_TARGET_DIR=/tmp/codex-core-local-tools cargo test -p codex-core --lib tools::spec::` - `just argument-comment-lint` ## References - #15923 - #15928 - #15944 - #15953 - #16031 - #16047 - #16129 - #16132 --- codex-rs/core/src/tools/spec.rs | 544 +------------------------ codex-rs/core/src/tools/spec_tests.rs | 197 +-------- codex-rs/tools/README.md | 1 + codex-rs/tools/src/lib.rs | 11 + codex-rs/tools/src/local_tool.rs | 463 +++++++++++++++++++++ codex-rs/tools/src/local_tool_tests.rs | 442 ++++++++++++++++++++ codex-rs/tools/src/view_image.rs | 67 +++ codex-rs/tools/src/view_image_tests.rs | 67 +++ 8 files changed, 1089 insertions(+), 703 deletions(-) create mode 100644 codex-rs/tools/src/local_tool.rs create mode 100644 codex-rs/tools/src/local_tool_tests.rs create mode 100644 codex-rs/tools/src/view_image.rs create mode 100644 codex-rs/tools/src/view_image_tests.rs diff --git a/codex-rs/core/src/tools/spec.rs b/codex-rs/core/src/tools/spec.rs index e478c55e4..2e0dcf084 100644 --- a/codex-rs/core/src/tools/spec.rs +++ b/codex-rs/core/src/tools/spec.rs @@ -32,7 +32,6 @@ use codex_protocol::config_types::WebSearchConfig; use codex_protocol::config_types::WebSearchMode; use codex_protocol::config_types::WindowsSandboxLevel; use codex_protocol::dynamic_tools::DynamicToolSpec; -use codex_protocol::models::VIEW_IMAGE_TOOL_NAME; use codex_protocol::openai_models::ApplyPatchToolType; use codex_protocol::openai_models::ConfigShellToolType; use codex_protocol::openai_models::InputModality; @@ -42,10 +41,19 @@ use codex_protocol::openai_models::WebSearchToolType; use codex_protocol::protocol::SandboxPolicy; use codex_protocol::protocol::SessionSource; use codex_protocol::protocol::SubAgentSource; +use codex_tools::CommandToolOptions; use codex_tools::FreeformTool; use codex_tools::FreeformToolFormat; use codex_tools::ResponsesApiTool; +use codex_tools::ShellToolOptions; +use codex_tools::ViewImageToolOptions; use codex_tools::augment_tool_spec_for_code_mode; +use codex_tools::create_exec_command_tool; +use codex_tools::create_request_permissions_tool; +use codex_tools::create_shell_command_tool; +use codex_tools::create_shell_tool; +use codex_tools::create_view_image_tool; +use codex_tools::create_write_stdin_tool; use codex_tools::dynamic_tool_to_responses_api_tool; use codex_tools::mcp_tool_to_responses_api_tool; use codex_tools::tool_spec_to_code_mode_tool_definition; @@ -81,40 +89,6 @@ static TOOL_SUGGEST_DESCRIPTION_TEMPLATE: LazyLock