Insert (or reconcile) the tracedecay-owned matcher group for `event`. Drops any pre-existing group that already contains our `subcommand` handler (so refinements to matcher/timeout reach old configs) while preserving every foreign group. Idempotent: exactly one tracedecay group per event.
(
hooks: &mut serde_json::Value,
event: &str,
tracedecay_bin: &str,
subcommand: &str,
timeout: u64,
matcher: Option<&str>,
)
| 1068 | /// (so refinements to matcher/timeout reach old configs) while preserving every |
| 1069 | /// foreign group. Idempotent: exactly one tracedecay group per event. |
| 1070 | fn install_codex_hook_event( |
| 1071 | hooks: &mut serde_json::Value, |
| 1072 | event: &str, |
| 1073 | tracedecay_bin: &str, |
| 1074 | subcommand: &str, |
| 1075 | timeout: u64, |
| 1076 | matcher: Option<&str>, |
| 1077 | ) { |
| 1078 | let existing = hooks["hooks"][event] |
| 1079 | .as_array() |
| 1080 | .cloned() |
| 1081 | .unwrap_or_default(); |
| 1082 | let mut groups: Vec<serde_json::Value> = existing |
| 1083 | .into_iter() |
| 1084 | .filter(|group| !group_has_subcommand(group, subcommand)) |
| 1085 | .collect(); |
| 1086 | |
| 1087 | let handler = json!({ |
| 1088 | "type": "command", |
| 1089 | "command": super::hook_command(tracedecay_bin, subcommand), |
| 1090 | "timeout": timeout, |
| 1091 | }); |
| 1092 | let mut group = json!({ "hooks": [handler] }); |
| 1093 | if let Some(matcher) = matcher { |
| 1094 | group["matcher"] = json!(matcher); |
| 1095 | } |
| 1096 | groups.push(group); |
| 1097 | |
| 1098 | hooks["hooks"][event] = serde_json::Value::Array(groups); |
| 1099 | } |
| 1100 | |
| 1101 | /// True when any handler command in `group` contains `subcommand`. |
| 1102 | fn group_has_subcommand(group: &serde_json::Value, subcommand: &str) -> bool { |
no test coverage detected