mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
Remove ToolName display helper (#21465)
## Why `ToolName::display()` made it too easy to flatten tool identity and accidentally compare rendered strings. Tool identity should stay structural until a legacy string boundary actually requires the flattened spelling. ## What - Removes `ToolName::display()` and relies on the existing `Display` impl for messages and errors. - Adds structural ordering for `ToolName` and uses it for sorting/deduping deferred tools. - Carries `ToolName` through tool/sandbox plumbing, flattening only at legacy boundaries such as hook payloads, telemetry tags, and Responses tool names. - Updates MCP normalization tests to assert `ToolName` structure instead of rendered strings. ## Testing - `cargo test -p codex-mcp test_normalize_tools` - `cargo test -p codex-core unavailable_tool` - `just fix -p codex-protocol` - `just fix -p codex-mcp` - `just fix -p codex-core`
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt;
|
||||
|
||||
/// Identifies a callable tool, preserving the namespace split when the model
|
||||
@@ -31,13 +32,6 @@ impl ToolName {
|
||||
namespace: Some(namespace.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn display(&self) -> String {
|
||||
match &self.namespace {
|
||||
Some(namespace) => format!("{namespace}{}", self.name),
|
||||
None => self.name.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ToolName {
|
||||
@@ -49,6 +43,26 @@ impl fmt::Display for ToolName {
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for ToolName {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
let lhs = match &self.namespace {
|
||||
Some(namespace) => (namespace.as_str(), Some(self.name.as_str())),
|
||||
None => (self.name.as_str(), None),
|
||||
};
|
||||
let rhs = match &other.namespace {
|
||||
Some(namespace) => (namespace.as_str(), Some(other.name.as_str())),
|
||||
None => (other.name.as_str(), None),
|
||||
};
|
||||
lhs.cmp(&rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for ToolName {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for ToolName {
|
||||
fn from(name: String) -> Self {
|
||||
Self::plain(name)
|
||||
|
||||
Reference in New Issue
Block a user