MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / json_hooks_active

Function json_hooks_active

atomic-agent/src/hooks/live.rs:11–135  ·  view source on GitHub ↗

Inspect an already parsed settings document. Unsupported formats and malformed hook structures return an error rather than implying absence. # Errors Returns a static, content-free explanation when the configuration cannot be interpreted reliably.

(
    agent: &str,
    root: &Value,
    hooks_key: &str,
    prefix: &str,
)

Source from the content-addressed store, hash-verified

9/// Returns a static, content-free explanation when the configuration cannot be
10/// interpreted reliably.
11pub fn json_hooks_active(
12 agent: &str,
13 root: &Value,
14 hooks_key: &str,
15 prefix: &str,
16) -> Result<bool, &'static str> {
17 let events: &[&str] = match agent {
18 "claude-code" | "codex" => &[
19 "SessionStart",
20 "SessionEnd",
21 "Stop",
22 "UserPromptSubmit",
23 "PreToolUse",
24 "PostToolUse",
25 ],
26 "gemini-cli" => &[
27 "SessionStart",
28 "SessionEnd",
29 "BeforeAgent",
30 "AfterAgent",
31 "BeforeTool",
32 "AfterTool",
33 ],
34 _ => return Err("agent hook format is not supported for inspection"),
35 };
36 if hooks_key != "hooks" || prefix != format!("atomic agent hooks {agent}") {
37 return Err("unsupported hook key or command prefix");
38 }
39 let root = root.as_object().ok_or("settings root is not an object")?;
40 if agent == "gemini-cli" {
41 for key in ["hooksConfig", "tools"] {
42 if root.get(key).is_some_and(|value| !value.is_object()) {
43 return Err("hook settings are not an object");
44 }
45 }
46 if let Some(disabled) = root.get("hooksConfig").and_then(|v| v.get("disabled")) {
47 if !disabled
48 .as_array()
49 .is_some_and(|names| names.iter().all(Value::is_string))
50 {
51 return Err("disabled hook names are not an array of strings");
52 }
53 }
54 }
55 let flags = match agent {
56 "claude-code" => [root.get("disableAllHooks"), None],
57 "gemini-cli" => [
58 root.get("hooksConfig").and_then(|v| v.get("enabled")),
59 root.get("tools").and_then(|v| v.get("enableHooks")),
60 ],
61 _ => [None, None],
62 };
63 for flag in flags.into_iter().flatten() {
64 if !flag.is_boolean() {
65 return Err("hook enablement flag is not a boolean");
66 }
67 }
68 if globally_disabled(agent, root) {

Callers 2

settings_hooksFunction · 0.85
is_installedMethod · 0.85

Calls 9

globally_disabledFunction · 0.85
disabledFunction · 0.85
is_invocationFunction · 0.85
getMethod · 0.65
allMethod · 0.45
iterMethod · 0.45
into_iterMethod · 0.45
containsMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected