Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.
Rust
fix(libsy): read tool signals from codex exec_command traffic (#569)
ryan-lempka1cd08bd5920e
diff --git a/crates/libsy/src/algorithms/util/tool_signals.rs b/crates/libsy/src/algorithms/util/tool_signals.rsindex 9996ff3a9..fc367e55b 100644--- a/crates/libsy/src/algorithms/util/tool_signals.rs+++ b/crates/libsy/src/algorithms/util/tool_signals.rs@@ -126,6 +126,10 @@ static BASH_WRITE_PATTERNS: &[&str] = &["<< eof",];+/// Python file-write expressions, which only indicate a write when an+/// interpreter is running them rather than a search looking for them.+static PYTHON_WRITE_PATTERNS: &[&str] = &["write_text(", "writelines(", ".write("];+static BASH_EDIT_PATTERNS: &[&str] = &["sed -i","sed --in-place",@@ -161,6 +165,7 @@ static BASH_TOOL_NAMES: &[&str] = &["shell","local_shell_call","terminal",+ "exec_command", // codex];// Prefer false negatives: tests_passed routes the picker to EFFICIENT, so a false@@ -321,6 +326,9 @@ fn classify_tool_call(name: &str, command: Option<&str>) -> ToolCategory {if BASH_WRITE_PATTERNS.iter().any(|p| cmd.contains(p)) {return ToolCategory::Write;}+ if cmd.contains("python") && PYTHON_WRITE_PATTERNS.iter().any(|p| cmd.contains(p)) {+ return ToolCategory::Write;+ }if BASH_EDIT_PATTERNS.iter().any(|p| cmd.contains(p)) {return ToolCategory::Edit;}@@ -389,10 +397,32 @@ const COMPACTION_MARKER: &str = "session is being continued";/// The shell command a tool call carries, when it has one. Harnesses name the/// field `command`; anything else is a tool whose category comes from its name.fn command_of(arguments: &Value) -> Option<String> {- arguments- .get("command")- .and_then(Value::as_str)- .map(str::to_lowercase)+ // the Responses wire format sends arguments as a JSON string, not an object+ let decoded = arguments+ .as_str()+ .and_then(|raw| serde_json::from_str::<Value>(raw).ok());+ let object = decoded.as_ref().unwrap_or(arguments);++ ["command", "cmd", "input"]+ .iter()+ .filter_map(|key| object.get(*key))+ .find_map(command_text)+}++/// A command field as lowercase text, from a string or an argv array.+fn command_text(value: &Value) -> Option<String> {+ match value {+ Value::String(text) => Some(text.to_lowercase()),+ Value::Array(parts) => {+ let joined = parts+ .iter()+ .filter_map(Value::as_str)+ .collect::<Vec<_>>()+ .join(" ");+ (!joined.is_empty()).then(|| joined.to_lowercase())+ }+ _ => None,+ }}/// Text carried by a content block, ignoring the non-textual kinds.@@ -806,6 +836,49 @@ mod tests {assert_eq!(sig.recent_edit_count, 1);}+ fn exec_command(cmd: Value) -> Message {+ Message {+ role: Role::Assistant,+ content: vec![ContentBlock::ToolCall(ToolCall {+ id: String::new(),+ name: "exec_command".to_string(),+ arguments: cmd,+ })],+ }+ }++ #[test]+ fn codex_exec_command_is_classified() {+ // arguments arrive as a JSON string, with the command under `cmd`+ let args = json!(r#"{"cmd":"sed -i s/a/b/ src/lib.rs","workdir":"/x"}"#);+ let request = with_messages(vec![exec_command(args), tr("ok")]);+ assert_eq!(+ ToolSignals::from_request(&request, None).recent_edit_count,+ 1+ );+ }++ #[test]+ fn python_write_expressions_need_a_python_command() {+ let write = with_messages(vec![+ exec_command(json!({"cmd": "python3 - <<'PY'\np.write_text(s)\nPY"})),+ tr("ok"),+ ]);+ assert_eq!(+ ToolSignals::from_request(&write, None).recent_write_count,+ 1+ );++ let search = with_messages(vec![+ exec_command(json!({"cmd": "grep -R '.write(' src"})),+ tr("ok"),+ ]);+ assert_eq!(+ ToolSignals::from_request(&search, None).recent_write_count,+ 0+ );+ }+#[test]fn recent_window_size_is_caller_overridable() {// Same six tool calls (1 edit at the end, 5 writes before).