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
chore(stage): count text-editor view as observation (#835)
Graham King699c7c0a0d9a
diff --git a/crates/libsy/src/algorithms/plan_execute.rs b/crates/libsy/src/algorithms/plan_execute.rsindex ecb76054f..74e4063a2 100644--- a/crates/libsy/src/algorithms/plan_execute.rs+++ b/crates/libsy/src/algorithms/plan_execute.rs@@ -365,6 +365,22 @@ mod tests {assert!(routed.llm_request.instructions.is_empty());}+ #[tokio::test]+ async fn editor_view_keeps_planning() {+ let messages = vec![tool_call(+ "str_replace_based_edit_tool",+ json!({"command": "view", "path": "/app/main.py"}),+ )];++ let (selected, _) = route_and_capture(+ algorithm(PlanExecuteConfig::default()),+ request(messages, None),+ )+ .await;++ assert_eq!(selected, CAPABLE);+ }+#[test]fn rejects_blank_prompts() {for config in [diff --git a/crates/libsy/src/algorithms/util/tool_signals.rs b/crates/libsy/src/algorithms/util/tool_signals.rsindex 59d6afc15..76f7e49da 100644--- a/crates/libsy/src/algorithms/util/tool_signals.rs+++ b/crates/libsy/src/algorithms/util/tool_signals.rs@@ -107,6 +107,9 @@ static EDIT_TOOL_NAMES: &[&str] = &["patch", // hermes's str_replace-style edit tool];+/// Editor tools whose `command` argument picks the action. `view` only reads.+static EDITOR_TOOL_NAMES: &[&str] = &["str_replace_based_edit_tool", "text_editor"];+static WRITE_TOOL_NAMES: &[&str] = &["write", "create_file", "new_file", "write_file"];// Bash subcommand patterns. Lowercased; callers must lowercase the command@@ -492,6 +495,9 @@ fn classify_tool_call_with_semantics(if WRITE_TOOL_NAMES.contains(&lower.as_str()) {return ToolSemantic::Mutate(MutationKind::Write);}+ if EDITOR_TOOL_NAMES.contains(&lower.as_str()) && command == Some("view") {+ return ToolSemantic::Observe;+ }if EDIT_TOOL_NAMES.contains(&lower.as_str()) {return ToolSemantic::Mutate(MutationKind::Edit);}@@ -2051,6 +2057,49 @@ mod tests {);}+ #[test]+ fn text_editor_view_is_a_read() {+ for name in ["str_replace_based_edit_tool", "text_editor"] {+ assert_eq!(+ classify_tool_call(name, Some("view")),+ ToolSemantic::Observe+ );+ for command in [+ Some("create"),+ Some("insert"),+ Some("str_replace"),+ Some("undo_edit"),+ None,+ ] {+ assert_eq!(+ classify_tool_call(name, command),+ ToolSemantic::Mutate(MutationKind::Edit),+ );+ }+ }++ let arguments = [+ json!({"command": "view", "path": "/app/main.py"}),+ // the Responses wire format sends arguments as a JSON string+ json!(r#"{"command":"view","path":"/app/main.py"}"#),+ ];+ for arguments in arguments {+ let call = Message {+ role: Role::Assistant,+ content: vec![ContentBlock::ToolCall(ToolCall {+ id: String::new(),+ name: "str_replace_based_edit_tool".to_string(),+ arguments,+ })],+ };+ let request = with_messages(vec![call, tr("print('hi')")]);+ let sig = ToolSignals::from_request(&request, None);+ assert_eq!(sig.read_count, 1);+ assert_eq!(sig.recent_read_count, 1);+ assert_eq!(sig.edit_count, 0);+ }+ }+#[test]fn read_tool_classifies_as_read() {assert_eq!(classify_tool_call("Read", None), ToolSemantic::Observe);