diff options
Diffstat (limited to 'src/integration/registry.rs')
| -rw-r--r-- | src/integration/registry.rs | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/integration/registry.rs b/src/integration/registry.rs index bcd17220..10500df5 100644 --- a/src/integration/registry.rs +++ b/src/integration/registry.rs @@ -22,6 +22,7 @@ pub(crate) fn integration_target_label( crate::api::schema::IntegrationTarget::Qodercli => "qodercli", crate::api::schema::IntegrationTarget::Cursor => "cursor", crate::api::schema::IntegrationTarget::Mastracode => "mastracode", + crate::api::schema::IntegrationTarget::Grok => "grok", } } @@ -49,6 +50,7 @@ pub(crate) fn integration_target_command_names( crate::api::schema::IntegrationTarget::Qodercli => qodercli_command_names(), crate::api::schema::IntegrationTarget::Cursor => cursor_command_names(), crate::api::schema::IntegrationTarget::Mastracode => &["mastracode"], + crate::api::schema::IntegrationTarget::Grok => &["grok"], } } @@ -257,7 +259,7 @@ fn integration_specs() -> [( crate::api::schema::IntegrationTarget, io::Result<PathBuf>, u32, -); 14] { +); 15] { [ ( crate::api::schema::IntegrationTarget::Pi, @@ -332,6 +334,11 @@ fn integration_specs() -> [( mastracode_dir().map(|dir| dir.join("hooks").join(super::MASTRACODE_HOOK_INSTALL_NAME)), super::MASTRACODE_INTEGRATION_VERSION, ), + ( + crate::api::schema::IntegrationTarget::Grok, + grok_dir().map(|dir| dir.join("hooks").join(super::GROK_HOOK_INSTALL_NAME)), + super::GROK_INTEGRATION_VERSION, + ), ] } @@ -372,6 +379,19 @@ pub(crate) fn print_outdated_update_notice() -> bool { true } +/// Whether the Herdr-owned Grok hook config exactly matches the installed +/// integration. JSON formatting and object key order do not affect validity. +fn grok_hook_config_is_valid(hook_path: &Path) -> bool { + let Some(hooks_dir) = hook_path.parent() else { + return false; + }; + let config_path = hooks_dir.join(super::GROK_HOOK_CONFIG_INSTALL_NAME); + fs::read_to_string(config_path) + .ok() + .and_then(|content| serde_json::from_str::<serde_json::Value>(&content).ok()) + .is_some_and(|config| config == super::targets::grok_hook_config(hook_path)) +} + pub(crate) fn integration_status_at( target: crate::api::schema::IntegrationTarget, path: PathBuf, @@ -390,12 +410,23 @@ pub(crate) fn integration_status_at( let installed_version = fs::read_to_string(&path) .ok() .and_then(|content| parse_integration_version(&content)); - let state = if installed_version.is_some_and(|version| version >= expected_version) { + let mut state = if installed_version.is_some_and(|version| version >= expected_version) { super::IntegrationStatusKind::Current } else { super::IntegrationStatusKind::Outdated }; + // Grok only invokes the hook when the herdr-owned `hooks/herdr.json` + // registers it, so a current hook script with a missing or broken config + // is a nonfunctional install: report it as outdated so `herdr integration + // status` flags it and a reinstall rewrites both files. + if target == crate::api::schema::IntegrationTarget::Grok + && state == super::IntegrationStatusKind::Current + && !grok_hook_config_is_valid(&path) + { + state = super::IntegrationStatusKind::Outdated; + } + super::IntegrationStatus { target, path, |
