use std::collections::HashMap;
use std::sync::OnceLock;
use crate::agent::types::Config;
pub struct ActionContext {
pub workflow_id: String,
pub vars: serde_json::Value,
}
impl ActionContext {
pub fn new(workflow_id: &str) -> Self {
Self {
workflow_id: workflow_id.to_string(),
vars: serde_json::json!({}),
}
}
}
pub type ActionFn = fn(&Config, &mut ActionContext) -> Result<(), String>;
static REGISTRY: OnceLock<HashMap<&'static str, ActionFn>> = OnceLock::new();
fn action_registry() -> &'static HashMap<&'static str, ActionFn> {
REGISTRY.get_or_init(|| {
let mut m: HashMap<&'static str, ActionFn> = HashMap::new();
m.insert("code_review", super::shell::action_code_review);
m.insert(
"security_code_review",
super::shell::action_security_code_review,
);
m.insert("refresh_agents", super::shell::action_refresh_agents);
m.insert("refresh_docs", super::shell::action_refresh_docs);
m.insert("auto_merge", super::shell::action_auto_merge);
m
})
}
pub fn lookup_action(name: &str) -> Option<&'static ActionFn> {
action_registry().get(name)
}