| 973 | } |
| 974 | |
| 975 | fn settings_hooks(agent: &str, path: &Path, hooks_key: &str, command_prefix: &str) -> HookPresence { |
| 976 | match std::fs::read_to_string(path) { |
| 977 | Ok(text) => match serde_json::from_str::<serde_json::Value>(&text) { |
| 978 | Ok(root) => match atomic_agent::hooks::live::json_hooks_active( |
| 979 | agent, |
| 980 | &root, |
| 981 | hooks_key, |
| 982 | command_prefix, |
| 983 | ) { |
| 984 | Ok(active) => { |
| 985 | // Named Gemini exclusions can also mask a hook declared in |
| 986 | // another settings scope, so don't infer the merged state. |
| 987 | let restricted = root.get("hooks").is_some_and(has_disabled_entry) |
| 988 | || (agent == "gemini-cli" |
| 989 | && root |
| 990 | .get("hooksConfig") |
| 991 | .and_then(|v| v.get("disabled")) |
| 992 | .and_then(serde_json::Value::as_array) |
| 993 | .is_some_and(|names| !names.is_empty())); |
| 994 | let disabled = root.as_object().is_some_and(|object| { |
| 995 | atomic_agent::hooks::live::globally_disabled(agent, object) |
| 996 | }); |
| 997 | match (active, restricted || disabled) { |
| 998 | (true, true) => HookPresence::Restricted, |
| 999 | (true, false) => HookPresence::Present, |
| 1000 | (false, true) => HookPresence::Disabled, |
| 1001 | (false, false) => HookPresence::Absent, |
| 1002 | } |
| 1003 | } |
| 1004 | Err(reason) => HookPresence::Unreadable(HookError::Invalid(reason)), |
| 1005 | }, |
| 1006 | Err(_) => HookPresence::Unreadable(HookError::Invalid("settings could not be parsed")), |
| 1007 | }, |
| 1008 | Err(error) if error.kind() == ErrorKind::NotFound && demonstrably_missing(path) => { |
| 1009 | HookPresence::Absent |
| 1010 | } |
| 1011 | Err(error) => HookPresence::Unreadable(HookError::Read(error.kind())), |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | fn has_disabled_entry(value: &serde_json::Value) -> bool { |
| 1016 | match value { |