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

Function add_direct_handler

atomic-agent/src/hooks/agy.rs:1151–1172  ·  view source on GitHub ↗

Add a handler to a direct handler list (`PreInvocation`, `Stop`, ...). Returns `true` if the handler was added (i.e., no Atomic handler with the same command was already present).

(group: &mut Value, event: &str, command: &str)

Source from the content-addressed store, hash-verified

1149/// Returns `true` if the handler was added (i.e., no Atomic handler with the
1150/// same command was already present).
1151fn add_direct_handler(group: &mut Value, event: &str, command: &str) -> bool {
1152 let Some(obj) = group.as_object_mut() else {
1153 return false;
1154 };
1155
1156 let entry = obj
1157 .entry(event.to_string())
1158 .or_insert_with(|| Value::Array(Vec::new()));
1159 let Some(list) = entry.as_array_mut() else {
1160 return false;
1161 };
1162
1163 if event_list_has_atomic(list) {
1164 return false;
1165 }
1166
1167 let mut handler = Map::new();
1168 handler.insert("type".to_string(), Value::String("command".to_string()));
1169 handler.insert("command".to_string(), Value::String(command.to_string()));
1170 list.push(Value::Object(handler));
1171 true
1172}
1173
1174/// Add a handler inside a matcher group (`PreToolUse`, `PostToolUse`).
1175///

Callers 1

install_toMethod · 0.85

Calls 3

event_list_has_atomicFunction · 0.85
insertMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected