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

Function remove_stale_atomic_hooks_for_event

atomic-agent/src/hooks/codex.rs:580–607  ·  view source on GitHub ↗

Remove only obsolete Atomic hooks for one event, preserving custom hooks and the exact current Atomic definition. This lets a normal `enable` migrate older installations without requiring users to discover `--force`.

(
    hooks: &mut Map<String, Value>,
    event: &str,
    command: &str,
    status_message: Option<&str>,
    timeout_sec: Option<u64>,
)

Source from the content-addressed store, hash-verified

578/// and the exact current Atomic definition. This lets a normal `enable`
579/// migrate older installations without requiring users to discover `--force`.
580fn remove_stale_atomic_hooks_for_event(
581 hooks: &mut Map<String, Value>,
582 event: &str,
583 command: &str,
584 status_message: Option<&str>,
585 timeout_sec: Option<u64>,
586) {
587 let Some(groups) = hooks.get_mut(event).and_then(Value::as_array_mut) else {
588 return;
589 };
590
591 groups.retain_mut(|group| {
592 let Some(group_obj) = group.as_object_mut() else {
593 return true;
594 };
595 let Some(group_hooks) = group_obj.get_mut("hooks").and_then(Value::as_array_mut) else {
596 return true;
597 };
598 group_hooks.retain(|hook| {
599 let is_atomic = hook
600 .get("command")
601 .and_then(Value::as_str)
602 .is_some_and(is_atomic_hook);
603 !is_atomic || hook_matches_spec(hook, command, status_message, timeout_sec)
604 });
605 !group_hooks.is_empty()
606 });
607}
608
609fn remove_atomic_hooks(hooks: &mut Map<String, Value>) {
610 for value in hooks.values_mut() {

Callers 1

install_hooks_atFunction · 0.85

Calls 4

hook_matches_specFunction · 0.85
get_mutMethod · 0.80
getMethod · 0.65
is_emptyMethod · 0.45

Tested by

no test coverage detected