Lightweight coding agent that runs in your terminal
Rust
Tag shell tool telemetry by command category (#32887)
jifbb947e8e362e
diff --git a/codex-rs/core/src/memory_usage.rs b/codex-rs/core/src/memory_usage.rsindex 4655b63931..17851b3aba 100644--- a/codex-rs/core/src/memory_usage.rs+++ b/codex-rs/core/src/memory_usage.rs@@ -26,7 +26,7 @@ pub(crate) fn emit_metric_for_tool_read(invocation: &ToolInvocation, success: bo}}-fn shell_script_for_invocation(invocation: &ToolInvocation) -> Option<String> {+pub(crate) fn shell_script_for_invocation(invocation: &ToolInvocation) -> Option<String> {let ToolPayload::Function { arguments } = &invocation.payload else {return None;};diff --git a/codex-rs/core/src/tools/registry.rs b/codex-rs/core/src/tools/registry.rsindex 2220d4244a..928f43db56 100644--- a/codex-rs/core/src/tools/registry.rs+++ b/codex-rs/core/src/tools/registry.rs@@ -10,6 +10,7 @@ use crate::hook_runtime::record_additional_contexts;use crate::hook_runtime::run_post_tool_use_hooks;use crate::hook_runtime::run_pre_tool_use_hooks;use crate::memory_usage::emit_metric_for_tool_read;+use crate::memory_usage::shell_script_for_invocation;use crate::sandbox_tags::permission_profile_policy_tag;use crate::sandbox_tags::permission_profile_sandbox_tag;use crate::session::turn_context::TurnContext;@@ -27,8 +28,10 @@ use crate::util::error_or_panic;use codex_extension_api::ToolCallOutcome;use codex_protocol::models::FunctionCallOutputPayload;use codex_protocol::models::ResponseInputItem;+use codex_protocol::parse_command::ParsedCommand;use codex_protocol::protocol::EventMsg;use codex_rollout::state_db;+use codex_shell_command::parse_command::parse_shell_script;use codex_tools::ToolName;use codex_tools::ToolSearchInfo;use codex_tools::ToolSpec;@@ -462,7 +465,7 @@ impl ToolRegistry {let telemetry_tags = tool.telemetry_tags(&invocation).await;let mut tool_result_tags =- Vec::with_capacity(base_tool_result_tags.len() + telemetry_tags.len());+ Vec::with_capacity(base_tool_result_tags.len() + telemetry_tags.len() + 1);let mut extra_trace_fields = Vec::new();tool_result_tags.extend_from_slice(&base_tool_result_tags);for (key, value) in &telemetry_tags {@@ -538,6 +541,22 @@ impl ToolRegistry {}}+ if let Some(command) = shell_script_for_invocation(&invocation) {+ let parsed = parse_shell_script(&command);+ let mut categories = parsed.iter().map(|command| match command {+ ParsedCommand::Read { .. } => "read",+ ParsedCommand::ListFiles { .. } => "list_files",+ ParsedCommand::Search { .. } => "search",+ ParsedCommand::Unknown { .. } => "unknown",+ });+ let category = match categories.next() {+ Some(first) if categories.all(|category| category == first) => first,+ Some(_) => "mixed",+ None => "unknown",+ };+ tool_result_tags.push(("command_category", category));+ }+let response_cell = tokio::sync::Mutex::new(None);let invocation_for_tool = invocation.clone();let log_payload = invocation.payload.log_payload();