| 384 | } |
| 385 | |
| 386 | fn write_hooks_file(path: &Path, config: &CodexHooksFile) -> AgentResult<()> { |
| 387 | if let Some(parent) = path.parent() { |
| 388 | std::fs::create_dir_all(parent).map_err(|e| AgentError::ConfigError { |
| 389 | operation: "create directory".to_string(), |
| 390 | path: parent.to_path_buf(), |
| 391 | reason: e.to_string(), |
| 392 | })?; |
| 393 | } |
| 394 | let content = serde_json::to_string_pretty(config).map_err(|e| AgentError::ConfigError { |
| 395 | operation: "serialize".to_string(), |
| 396 | path: path.to_path_buf(), |
| 397 | reason: e.to_string(), |
| 398 | })?; |
| 399 | std::fs::write(path, content).map_err(|e| AgentError::ConfigError { |
| 400 | operation: "write".to_string(), |
| 401 | path: path.to_path_buf(), |
| 402 | reason: e.to_string(), |
| 403 | }) |
| 404 | } |
| 405 | |
| 406 | fn hooks_file_has_atomic_hooks(path: &Path) -> bool { |
| 407 | std::fs::read_to_string(path) |