| 419 | } |
| 420 | |
| 421 | fn write_hooks_file(path: &Path, config: &CodexHooksFile) -> AgentResult<()> { |
| 422 | if let Some(parent) = path.parent() { |
| 423 | std::fs::create_dir_all(parent).map_err(|e| AgentError::ConfigError { |
| 424 | operation: "create directory".to_string(), |
| 425 | path: parent.to_path_buf(), |
| 426 | reason: e.to_string(), |
| 427 | })?; |
| 428 | } |
| 429 | let content = serde_json::to_string_pretty(config).map_err(|e| AgentError::ConfigError { |
| 430 | operation: "serialize".to_string(), |
| 431 | path: path.to_path_buf(), |
| 432 | reason: e.to_string(), |
| 433 | })?; |
| 434 | std::fs::write(path, content).map_err(|e| AgentError::ConfigError { |
| 435 | operation: "write".to_string(), |
| 436 | path: path.to_path_buf(), |
| 437 | reason: e.to_string(), |
| 438 | }) |
| 439 | } |
| 440 | |
| 441 | fn hooks_file_has_current_atomic_hooks(path: &Path) -> bool { |
| 442 | let Ok(config) = read_hooks_file(path) else { |