use serde_json::Value;
pub const CANONICAL_ACTION_ALIASES: &[(&str, &str, &str)] = &[
("bash", "run", "exec_shell"),
("bash", "wait", "exec_shell_wait"),
("bash", "interact", "exec_shell_interact"),
("bash", "cancel", "exec_shell_cancel"),
("Bash", "run", "exec_shell"),
("Bash", "wait", "exec_shell_wait"),
("Bash", "interact", "exec_shell_interact"),
("Bash", "cancel", "exec_shell_cancel"),
("File", "read", "read_file"),
("File", "list", "list_dir"),
("File", "search_name", "file_search"),
("File", "search_content", "grep_files"),
("File", "write", "write_file"),
("File", "edit", "edit_file"),
("File", "patch", "apply_patch"),
("Git", "status", "git_status"),
("Git", "diff", "git_diff"),
("Git", "log", "git_log"),
("Git", "show", "git_show"),
("Git", "blame", "git_blame"),
("Git", "commit_plan", "git_commit_plan"),
("Git", "fetch", "git_fetch"),
("Git", "merge_tree", "git_merge_tree"),
("Git", "review_scope", "git_review_scope"),
("Run", "tests", "run_tests"),
("Run", "verifiers", "run_verifiers"),
("Web", "search", "web_search"),
("Web", "fetch", "fetch_url"),
("Web", "wait", "wait_for_dev_server"),
("rlm", "session_objects", "rlm_session_objects"),
("rlm", "open", "rlm_open"),
("rlm", "eval", "rlm_eval"),
("rlm", "configure", "rlm_configure"),
("rlm", "close", "rlm_close"),
("tasks", "create", "task_create"),
("tasks", "list", "task_list"),
("tasks", "read", "task_read"),
("tasks", "cancel", "task_cancel"),
("tasks", "gate_run", "task_gate_run"),
("tasks", "pr_attempt_record", "pr_attempt_record"),
("tasks", "pr_attempt_list", "pr_attempt_list"),
("tasks", "pr_attempt_read", "pr_attempt_read"),
("tasks", "pr_attempt_preflight", "pr_attempt_preflight"),
("automation", "create", "automation_create"),
("automation", "list", "automation_list"),
("automation", "read", "automation_read"),
("automation", "update", "automation_update"),
("automation", "pause", "automation_pause"),
("automation", "resume", "automation_resume"),
("automation", "adopt", "automation_adopt"),
("automation", "delete", "automation_delete"),
("automation", "run", "automation_run"),
("github", "issue_context", "github_issue_context"),
("github", "pr_context", "github_pr_context"),
("github", "comment", "github_comment"),
("github", "close_issue", "github_close_issue"),
("github", "close_pr", "github_close_pr"),
("github", "report_draft", "github_report_draft"),
("github", "report_read", "github_report_read"),
];
#[must_use]
pub fn action_family_default(tool_name: &str) -> Option<Option<&'static str>> {
match tool_name {
"bash" | "Bash" => Some(Some("run")),
"File" => Some(Some("read")),
"Git" => Some(Some("status")),
"Run" => Some(Some("tests")),
"Web" => Some(Some("search")),
"rlm" | "tasks" | "automation" | "github" => Some(None),
_ => None,
}
}
#[must_use]
pub fn is_action_family(tool_name: &str) -> bool {
action_family_default(tool_name).is_some()
}
#[must_use]
pub fn canonical_action_alias<'a>(tool_name: &'a str, input: &Value) -> &'a str {
match tool_name {
"read" => return "read_file",
"write" => return "write_file",
"edit" => return "edit_file",
_ => {}
}
let Some(default_action) = action_family_default(tool_name) else {
return tool_name;
};
let Some(action) = input
.get("action")
.and_then(Value::as_str)
.or(default_action)
else {
return tool_name;
};
CANONICAL_ACTION_ALIASES
.iter()
.find_map(|(family, candidate_action, alias)| {
(*family == tool_name && *candidate_action == action).then_some(*alias)
})
.unwrap_or(tool_name)
}