| 433 | } |
| 434 | |
| 435 | fn write_hooks_file(path: &Path, config: &CodexHooksFile) -> AgentResult<()> { |
| 436 | if let Some(parent) = path.parent() { |
| 437 | std::fs::create_dir_all(parent).map_err(|e| AgentError::ConfigError { |
| 438 | operation: "create directory".to_string(), |
| 439 | path: parent.to_path_buf(), |
| 440 | reason: e.to_string(), |
| 441 | })?; |
| 442 | } |
| 443 | let content = serde_json::to_string_pretty(config).map_err(|e| AgentError::ConfigError { |
| 444 | operation: "serialize".to_string(), |
| 445 | path: path.to_path_buf(), |
| 446 | reason: e.to_string(), |
| 447 | })?; |
| 448 | std::fs::write(path, content).map_err(|e| AgentError::ConfigError { |
| 449 | operation: "write".to_string(), |
| 450 | path: path.to_path_buf(), |
| 451 | reason: e.to_string(), |
| 452 | }) |
| 453 | } |
| 454 | |
| 455 | fn hooks_file_has_current_atomic_hooks(path: &Path) -> bool { |
| 456 | let Ok(config) = read_hooks_file(path) else { |