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

Function remove_atomic_commands

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

Remove all Atomic hook commands from every event list in a group, dropping emptied matcher groups and empty event lists.

(group: &mut Value)

Source from the content-addressed store, hash-verified

1218/// Remove all Atomic hook commands from every event list in a group,
1219/// dropping emptied matcher groups and empty event lists.
1220fn remove_atomic_commands(group: &mut Value) {
1221 let Some(obj) = group.as_object_mut() else {
1222 return;
1223 };
1224
1225 let events: Vec<String> = obj.keys().cloned().collect();
1226 for event in events {
1227 let Some(list) = obj.get_mut(&event).and_then(Value::as_array_mut) else {
1228 continue;
1229 };
1230
1231 // Matcher-wrapped lists: clean each group's hooks.
1232 for item in list.iter_mut() {
1233 if let Some(hooks) = item.get_mut("hooks").and_then(Value::as_array_mut) {
1234 hooks.retain(|handler| {
1235 !handler
1236 .get("command")
1237 .and_then(Value::as_str)
1238 .is_some_and(is_atomic_command)
1239 });
1240 }
1241 }
1242 // Drop emptied matcher groups.
1243 list.retain(|item| match item.get("hooks").and_then(Value::as_array) {
1244 Some(hooks) => !hooks.is_empty(),
1245 None => true,
1246 });
1247 // Direct handler lists: drop Atomic handlers.
1248 list.retain(|handler| {
1249 // Keep matcher groups (handled above) and non-Atomic handlers.
1250 if handler.get("hooks").is_some() {
1251 return true;
1252 }
1253 !handler
1254 .get("command")
1255 .and_then(Value::as_str)
1256 .is_some_and(is_atomic_command)
1257 });
1258
1259 if list.is_empty() {
1260 obj.remove(&event);
1261 }
1262 }
1263}
1264
1265/// Returns `true` if the group has no remaining handlers and no keys other
1266/// than `enabled` (a bare `enabled` flag on an empty group is meaningless).

Callers 3

install_toMethod · 0.85
uninstall_fromMethod · 0.85

Calls 5

get_mutMethod · 0.80
iter_mutMethod · 0.80
getMethod · 0.65
removeMethod · 0.65
is_emptyMethod · 0.45

Tested by

no test coverage detected