(
settings_path: &Path,
)
| 50 | } |
| 51 | |
| 52 | pub(crate) fn read_settings( |
| 53 | settings_path: &Path, |
| 54 | ) -> AgentResult<(serde_json::Map<String, serde_json::Value>, ClaudeHooks)> { |
| 55 | let data = match std::fs::read(settings_path) { |
| 56 | Ok(data) => data, |
| 57 | Err(e) if e.kind() == std::io::ErrorKind::NotFound => { |
| 58 | return Ok((serde_json::Map::new(), ClaudeHooks::default())); |
| 59 | } |
| 60 | Err(e) => { |
| 61 | return Err(AgentError::ConfigError { |
| 62 | operation: "read".to_string(), |
| 63 | path: settings_path.to_path_buf(), |
| 64 | reason: e.to_string(), |
| 65 | }); |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | let raw: serde_json::Map<String, serde_json::Value> = |
| 70 | serde_json::from_slice(&data).map_err(|e| AgentError::ConfigError { |
| 71 | operation: "parse".to_string(), |
| 72 | path: settings_path.to_path_buf(), |
| 73 | reason: e.to_string(), |
| 74 | })?; |
| 75 | |
| 76 | let hooks = if let Some(hooks_val) = raw.get("hooks") { |
| 77 | serde_json::from_value(hooks_val.clone()).map_err(|e| AgentError::ConfigError { |
| 78 | operation: "parse hooks".to_string(), |
| 79 | path: settings_path.to_path_buf(), |
| 80 | reason: e.to_string(), |
| 81 | })? |
| 82 | } else { |
| 83 | ClaudeHooks::default() |
| 84 | }; |
| 85 | |
| 86 | Ok((raw, hooks)) |
| 87 | } |
| 88 | |
| 89 | pub(crate) fn write_settings( |
| 90 | settings_path: &Path, |
no test coverage detected