diff options
| author | Ward Peeters <ward@coding-tech.com> | 2026-07-04 00:29:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-07-04 01:29:42 +0300 |
| commit | d0e333451bd794a419e96f28db925772950ea156 (patch) | |
| tree | 1a6e5d3bd6ac40f8ef454058f069d30202327002 /src/integration/config_edit.rs | |
| parent | d5521e3d250498df4af552fff83fce3d5ef33810 (diff) | |
feat: add mastracode integration (#788)
* feat: add mastracode integration
refs #337
Co-authored-by: Mastra Code (openai/gpt-5.5) <noreply@mastra.ai>
Co-authored-by: Ogulcan Celik <ogulcancelik@gmail.com>
Diffstat (limited to 'src/integration/config_edit.rs')
| -rw-r--r-- | src/integration/config_edit.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/integration/config_edit.rs b/src/integration/config_edit.rs index a1653395..63c18845 100644 --- a/src/integration/config_edit.rs +++ b/src/integration/config_edit.rs @@ -110,6 +110,34 @@ pub(crate) fn ensure_command_hook( // { "type": "command", "matcher": "...", "bash": "...", ... } // Keep the helpers separate so install/uninstall preserves unrelated hooks in // each agent's native format instead of normalizing user configuration. +pub(crate) fn ensure_flat_command_hook( + hooks: &mut Map<String, Value>, + event: &str, + command: String, + timeout_ms: u64, +) -> io::Result<()> { + let entries = hooks + .entry(event.to_string()) + .or_insert_with(|| Value::Array(Vec::new())) + .as_array_mut() + .ok_or_else(|| io::Error::other(format!("hook entries for {event} must be an array")))?; + + if entries.iter().any(|entry| { + entry.get("type").and_then(Value::as_str) == Some("command") + && entry.get("command").and_then(Value::as_str) == Some(command.as_str()) + }) { + return Ok(()); + } + + entries.push(json!({ + "type": "command", + "command": command, + "timeout": timeout_ms, + "description": "Report MastraCode agent state to Herdr", + })); + Ok(()) +} + pub(crate) fn ensure_direct_command_hook( hooks: &mut Map<String, Value>, event: &str, @@ -214,6 +242,31 @@ pub(crate) fn remove_command_hook( Ok(removed) } +pub(crate) fn remove_flat_command_hook( + hooks: &mut Map<String, Value>, + event: &str, + command: &str, +) -> io::Result<bool> { + let Some(entries_value) = hooks.get_mut(event) else { + return Ok(false); + }; + + let entries = entries_value + .as_array_mut() + .ok_or_else(|| io::Error::other(format!("hook entries for {event} must be an array")))?; + + let before = entries.len(); + entries.retain(|entry| { + !(entry.get("type").and_then(Value::as_str) == Some("command") + && entry.get("command").and_then(Value::as_str) == Some(command)) + }); + let removed = entries.len() != before; + if entries.is_empty() { + hooks.remove(event); + } + Ok(removed) +} + pub(crate) fn remove_direct_command_hook( hooks: &mut Map<String, Value>, event: &str, |
