pub fn validate_hook_config(
config: &HookConfig,
script_path: &Path,
) -> Result<()>Expand description
Validate a hook configuration for correctness and safety.
Performs comprehensive validation of a hook configuration including:
- Event list validation (must have at least one event)
- Regex pattern syntax validation for the matcher
- Hook type validation (only “command” type is supported)
- Script existence validation for AGPM-managed scripts
§Arguments
config- The hook configuration to validatescript_path- Path to the hook file (used to resolve relative script paths)
§Returns
Returns Ok(()) if the configuration is valid.
§Errors
Returns an error if:
- No events are specified
- The matcher regex pattern is invalid
- Unsupported hook type is used (only “command” is supported)
- Referenced script file doesn’t exist (for AGPM-managed scripts)
§Examples
use agpm_cli::hooks::{validate_hook_config, HookConfig, HookEvent};
use std::path::Path;
let config = HookConfig {
events: vec![HookEvent::PreToolUse],
matcher: Some("Bash|Write".to_string()),
hook_type: "command".to_string(),
command: "echo 'validation'".to_string(),
timeout: Some(5000),
description: None,
};
let hook_file = Path::new(".claude/hooks/test.json");
validate_hook_config(&config, hook_file)?;
println!("Hook configuration is valid!");