Classify a turn based on tool names and Bash command content. `tool_names`: names of all `tool_use` blocks in the turn (e.g. "Edit", "Bash"). `bash_commands`: content of Bash tool inputs (the `command` field).
(tool_names: &[&str], bash_commands: &[&str])
| 62 | /// `tool_names`: names of all `tool_use` blocks in the turn (e.g. "Edit", "Bash"). |
| 63 | /// `bash_commands`: content of Bash tool inputs (the `command` field). |
| 64 | pub fn classify(tool_names: &[&str], bash_commands: &[&str]) -> TaskCategory { |
| 65 | if tool_names.is_empty() { |
| 66 | return TaskCategory::Conversation; |
| 67 | } |
| 68 | |
| 69 | // Agent tool → delegation |
| 70 | if tool_names.contains(&"Agent") { |
| 71 | return TaskCategory::Delegation; |
| 72 | } |
| 73 | |
| 74 | // Planning tools |
| 75 | if tool_names.contains(&"EnterPlanMode") || tool_names.contains(&"TaskCreate") { |
| 76 | return TaskCategory::Planning; |
| 77 | } |
| 78 | |
| 79 | let has_edit = tool_names.contains(&"Edit") || tool_names.contains(&"Write"); |
| 80 | let has_read_only = tool_names.contains(&"Read") |
| 81 | || tool_names.contains(&"Grep") |
| 82 | || tool_names.contains(&"Glob") |
| 83 | || tool_names.contains(&"WebSearch"); |
| 84 | |
| 85 | // Check Bash commands for specific patterns |
| 86 | let any_bash = |patterns: &[&str]| -> bool { |
| 87 | bash_commands.iter().any(|cmd| { |
| 88 | let lower = cmd.to_ascii_lowercase(); |
| 89 | patterns.iter().any(|p| lower.contains(p)) |
| 90 | }) |
| 91 | }; |
| 92 | |
| 93 | // Git operations |
| 94 | if any_bash(&["git "]) { |
| 95 | return TaskCategory::GitOps; |
| 96 | } |
| 97 | |
| 98 | // Testing: test runner commands |
| 99 | if any_bash(&[ |
| 100 | "cargo test", |
| 101 | "cargo nextest", |
| 102 | "pytest", |
| 103 | "vitest", |
| 104 | "jest ", |
| 105 | "mocha ", |
| 106 | "npm test", |
| 107 | "npm run test", |
| 108 | "pnpm test", |
| 109 | "pnpm run test", |
| 110 | "go test", |
| 111 | "dotnet test", |
| 112 | "flutter test", |
| 113 | ]) { |
| 114 | return TaskCategory::Testing; |
| 115 | } |
| 116 | |
| 117 | // Build/deploy |
| 118 | if any_bash(&[ |
| 119 | "cargo build", |
| 120 | "cargo check", |
| 121 | "npm run build", |
no test coverage detected