Skip to content
10 changes: 0 additions & 10 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

118 changes: 0 additions & 118 deletions codex-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 18 additions & 16 deletions codex-rs/codex-mcp/src/connection_manager_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ fn model_tool_names(tools: &[ToolInfo]) -> HashSet<ToolName> {
.collect::<HashSet<_>>()
}

fn model_tool_name_len(name: &ToolName) -> usize {
name.namespace.as_deref().map_or(0, str::len) + name.name.len()
}

fn is_code_mode_compatible_tool_name(name: &ToolName) -> bool {
name.namespace
.as_deref()
.into_iter()
.chain(std::iter::once(name.name.as_str()))
.flat_map(str::chars)
.all(|c| c.is_ascii_alphanumeric() || c == '_')
}
#[test]
fn declared_openai_file_fields_treat_names_literally() {
let meta = serde_json::json!({
Expand Down Expand Up @@ -334,17 +346,14 @@ fn test_normalize_tools_long_names_same_server() {

let names = model_tool_names(&model_tools);

assert!(names.iter().all(|name| name.display().len() == 64));
assert!(names.iter().all(|name| model_tool_name_len(name) == 64));
assert!(
names
.iter()
.all(|name| name.namespace.as_deref() == Some("mcp__my_server__"))
);
assert!(
names.iter().all(|name| name
.display()
.chars()
.all(|c| c.is_ascii_alphanumeric() || c == '_')),
names.iter().all(is_code_mode_compatible_tool_name),
"model-visible names must be code-mode compatible: {names:?}"
);
}
Expand All @@ -363,10 +372,9 @@ fn test_normalize_tools_sanitizes_invalid_characters() {
ToolName::namespaced("mcp__server_one__", "tool_two_three")
);
assert_eq!(
format!("{}{}", tool.callable_namespace, tool.callable_name),
model_name.display()
ToolName::namespaced(tool.callable_namespace.clone(), tool.callable_name.clone()),
model_name
);

// The callable parts are sanitized for model-visible tool calls, but the raw
// MCP name is preserved for the actual MCP call.
assert_eq!(tool.server_name, "server.one");
Expand All @@ -375,10 +383,7 @@ fn test_normalize_tools_sanitizes_invalid_characters() {
assert_eq!(tool.tool.name, "tool.two-three");

assert!(
model_name
.display()
.chars()
.all(|c| c.is_ascii_alphanumeric() || c == '_'),
is_code_mode_compatible_tool_name(&model_name),
"model-visible name must be code-mode compatible: {model_name:?}"
);
}
Expand Down Expand Up @@ -425,10 +430,7 @@ fn test_normalize_tools_disambiguates_sanitized_namespace_collisions() {
assert_eq!(raw_servers, HashSet::from(["basic-server", "basic_server"]));
let model_names = model_tool_names(&model_tools);
assert!(
model_names.iter().all(|name| name
.display()
.chars()
.all(|c| c.is_ascii_alphanumeric() || c == '_')),
model_names.iter().all(is_code_mode_compatible_tool_name),
"model-visible names must be code-mode compatible: {model_names:?}"
);
}
Expand Down
5 changes: 3 additions & 2 deletions codex-rs/core/src/memory_usage.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::tools::context::ToolInvocation;
use crate::tools::context::ToolPayload;
use crate::tools::flat_tool_name;
use crate::tools::handlers::unified_exec::ExecCommandArgs;
use codex_memories_read::usage::MEMORIES_USAGE_METRIC;
use codex_memories_read::usage::memories_usage_kinds_from_command;
Expand All @@ -17,14 +18,14 @@ pub(crate) async fn emit_metric_for_tool_read(invocation: &ToolInvocation, succe
}

let success = if success { "true" } else { "false" };
let tool_name = invocation.tool_name.display();
let tool_name = flat_tool_name(&invocation.tool_name);
for kind in kinds {
invocation.turn.session_telemetry.counter(
MEMORIES_USAGE_METRIC,
/*inc*/ 1,
&[
("kind", kind.as_tag()),
("tool", &tool_name),
("tool", tool_name.as_ref()),
("success", success),
],
);
Expand Down
2 changes: 1 addition & 1 deletion codex-rs/core/src/session/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ async fn danger_full_access_tool_attempts_do_not_enforce_managed_network() -> an
session: Arc::clone(&session),
turn: Arc::clone(&turn),
call_id: "probe-call".to_string(),
tool_name: "probe".to_string(),
tool_name: codex_tools::ToolName::plain("probe"),
};

orchestrator
Expand Down
2 changes: 1 addition & 1 deletion codex-rs/core/src/stream_events_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ pub(crate) async fn handle_output_item_done(
tracing::info!(
thread_id = %ctx.sess.conversation_id,
"ToolCall: {} {}",
call.tool_name.display(),
call.tool_name,
payload_preview
);

Expand Down
4 changes: 2 additions & 2 deletions codex-rs/core/src/tools/handlers/apply_patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ impl ToolHandler for ApplyPatchHandler {
session: session.clone(),
turn: turn.clone(),
call_id: call_id.clone(),
tool_name: tool_name.display(),
tool_name: tool_name.clone(),
};
let out = orchestrator
.run(
Expand Down Expand Up @@ -566,7 +566,7 @@ pub(crate) async fn intercept_apply_patch(
session: session.clone(),
turn: turn.clone(),
call_id: call_id.to_string(),
tool_name: tool_name.to_string(),
tool_name: ToolName::plain(tool_name),
};
let out = orchestrator
.run(
Expand Down
10 changes: 7 additions & 3 deletions codex-rs/core/src/tools/handlers/mcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::tools::context::McpToolOutput;
use crate::tools::context::ToolInvocation;
use crate::tools::context::ToolOutput;
use crate::tools::context::ToolPayload;
use crate::tools::flat_tool_name;
use crate::tools::hook_names::HookToolName;
use crate::tools::registry::PostToolUsePayload;
use crate::tools::registry::PreToolUsePayload;
Expand Down Expand Up @@ -42,8 +43,9 @@ impl ToolHandler for McpHandler {
return None;
};

let tool_name = &self.tool_name;
Some(PreToolUsePayload {
tool_name: HookToolName::new(self.tool_name.display()),
tool_name: HookToolName::new(flat_tool_name(tool_name).into_owned()),
tool_input: mcp_hook_tool_input(raw_arguments),
})
}
Expand All @@ -59,8 +61,9 @@ impl ToolHandler for McpHandler {

let tool_response =
result.post_tool_use_response(&invocation.call_id, &invocation.payload)?;
let tool_name = &self.tool_name;
Some(PostToolUsePayload {
tool_name: HookToolName::new(self.tool_name.display()),
tool_name: HookToolName::new(flat_tool_name(tool_name).into_owned()),
tool_use_id: invocation.call_id.clone(),
tool_input: result.tool_input.clone(),
tool_response,
Expand Down Expand Up @@ -93,13 +96,14 @@ impl ToolHandler for McpHandler {
let arguments_str = raw_arguments;

let started = Instant::now();
let hook_tool_name = flat_tool_name(&self.tool_name);
let result = handle_mcp_tool_call(
Arc::clone(&session),
&turn,
call_id.clone(),
server,
tool,
self.tool_name.display(),
hook_tool_name.into_owned(),
arguments_str,
)
.await;
Expand Down
5 changes: 3 additions & 2 deletions codex-rs/core/src/tools/handlers/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::tools::runtimes::shell::ShellRuntimeBackend;
use crate::tools::sandboxing::ToolCtx;
use codex_protocol::models::AdditionalPermissionProfile;
use codex_protocol::protocol::ExecCommandSource;
use codex_tools::ToolName;

mod container_exec;
mod local_shell;
Expand Down Expand Up @@ -72,7 +73,7 @@ fn shell_command_payload_command(payload: &ToolPayload) -> Option<String> {
}

struct RunExecLikeArgs {
tool_name: String,
tool_name: ToolName,
exec_params: ExecParams,
hook_command: String,
additional_permissions: Option<AdditionalPermissionProfile>,
Expand Down Expand Up @@ -201,7 +202,7 @@ async fn run_exec_like(args: RunExecLikeArgs) -> Result<FunctionToolOutput, Func
turn.clone(),
Some(&tracker),
&call_id,
tool_name.as_str(),
tool_name.name.as_str(),
)
.await?
{
Expand Down
Loading
Loading