aboutsummaryrefslogtreecommitdiff
path: root/src/integration/targets.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/integration/targets.rs')
-rw-r--r--src/integration/targets.rs84
1 files changed, 78 insertions, 6 deletions
diff --git a/src/integration/targets.rs b/src/integration/targets.rs
index 488b7032..87000eae 100644
--- a/src/integration/targets.rs
+++ b/src/integration/targets.rs
@@ -13,7 +13,7 @@ use super::config_edit::{
remove_hook_commands, remove_kimi_config_block, remove_simple_command_hook,
};
use super::env::{
- claude_dir, codex_dir, copilot_dir, cursor_dir, devin_dir, droid_dir, hermes_dir,
+ claude_dir, codex_dir, copilot_dir, cursor_dir, devin_dir, droid_dir, grok_dir, hermes_dir,
hermes_plugin_dir, kilo_dir, kimi_dir, mastracode_dir, omp_extension_dir, opencode_dir,
pi_extension_dir, qodercli_dir,
};
@@ -24,10 +24,11 @@ use super::types::{
ClaudeInstallPaths, ClaudeUninstallResult, CodexInstallPaths, CodexUninstallResult,
CopilotInstallPaths, CopilotUninstallResult, CursorInstallPaths, CursorUninstallResult,
DevinInstallPaths, DevinUninstallResult, DroidInstallPaths, DroidUninstallResult,
- HermesInstallPaths, HermesUninstallResult, KiloInstallPaths, KiloUninstallResult,
- KimiInstallPaths, KimiUninstallResult, MastracodeInstallPaths, MastracodeUninstallResult,
- OmpInstallPaths, OmpUninstallResult, OpenCodeInstallPaths, OpenCodeUninstallResult,
- PiUninstallResult, QodercliInstallPaths, QodercliUninstallResult,
+ GrokInstallPaths, GrokUninstallResult, HermesInstallPaths, HermesUninstallResult,
+ KiloInstallPaths, KiloUninstallResult, KimiInstallPaths, KimiUninstallResult,
+ MastracodeInstallPaths, MastracodeUninstallResult, OmpInstallPaths, OmpUninstallResult,
+ OpenCodeInstallPaths, OpenCodeUninstallResult, PiUninstallResult, QodercliInstallPaths,
+ QodercliUninstallResult,
};
use super::{
CLAUDE_HOOK_ASSET, CLAUDE_HOOK_INSTALL_NAME, CODEX_HOOK_ASSET, CODEX_HOOK_INSTALL_NAME,
@@ -35,7 +36,8 @@ use super::{
COPILOT_REMOVED_LIFECYCLE_HOOK_EVENTS, CURSOR_HOOK_ASSET, CURSOR_HOOK_INSTALL_NAME,
DEVIN_HOOK_ASSET, DEVIN_HOOK_EVENTS, DEVIN_HOOK_INSTALL_NAME,
DEVIN_REMOVED_LIFECYCLE_HOOK_EVENTS, DROID_HOOK_ASSET, DROID_HOOK_EVENTS,
- DROID_HOOK_INSTALL_NAME, DROID_REMOVED_LIFECYCLE_HOOK_EVENTS, HERMES_PLUGIN_INIT_ASSET,
+ DROID_HOOK_INSTALL_NAME, DROID_REMOVED_LIFECYCLE_HOOK_EVENTS, GROK_HOOK_ASSET,
+ GROK_HOOK_CONFIG_INSTALL_NAME, GROK_HOOK_INSTALL_NAME, HERMES_PLUGIN_INIT_ASSET,
HERMES_PLUGIN_INIT_INSTALL_NAME, HERMES_PLUGIN_MANIFEST_ASSET,
HERMES_PLUGIN_MANIFEST_INSTALL_NAME, KILO_PLUGIN_ASSET, KILO_PLUGIN_INSTALL_NAME,
KIMI_HOOK_ASSET, KIMI_HOOK_INSTALL_NAME, MASTRACODE_HOOK_ASSET, MASTRACODE_HOOK_EVENTS,
@@ -1200,3 +1202,73 @@ pub(crate) fn uninstall_mastracode() -> io::Result<MastracodeUninstallResult> {
updated_hooks,
})
}
+
+/// The complete Herdr-owned Grok hook config. Installation and status share
+/// this value so any config drift is reported as outdated.
+pub(crate) fn grok_hook_config(hook_path: &Path) -> Value {
+ let quoted_hook_path = shell_single_quote(&hook_path.display().to_string());
+ let session_command = format!("sh {quoted_hook_path} session");
+ json!({
+ "hooks": {
+ "SessionStart": [
+ {
+ "hooks": [
+ {
+ "type": "command",
+ "command": session_command,
+ "timeout": 10,
+ }
+ ]
+ }
+ ]
+ }
+ })
+}
+
+pub(crate) fn install_grok() -> io::Result<GrokInstallPaths> {
+ let dir = grok_dir()?;
+ if !dir.is_dir() {
+ return Err(io::Error::other(format!(
+ "grok config directory not found at {}. install grok cli first",
+ dir.display()
+ )));
+ }
+
+ // Grok merges every `~/.grok/hooks/*.json`, so herdr owns a dedicated
+ // config file and never edits the user's other hooks. The hook script and
+ // its config live side by side under `hooks/`.
+ let hooks_dir = dir.join("hooks");
+ fs::create_dir_all(&hooks_dir)?;
+
+ let hook_path = hooks_dir.join(GROK_HOOK_INSTALL_NAME);
+ fs::write(&hook_path, GROK_HOOK_ASSET)?;
+ make_executable(&hook_path)?;
+
+ let config_path = hooks_dir.join(GROK_HOOK_CONFIG_INSTALL_NAME);
+ fs::write(
+ &config_path,
+ serde_json::to_string_pretty(&grok_hook_config(&hook_path))?,
+ )?;
+
+ Ok(GrokInstallPaths {
+ hook_path,
+ config_path,
+ })
+}
+
+pub(crate) fn uninstall_grok() -> io::Result<GrokUninstallResult> {
+ let hooks_dir = grok_dir()?.join("hooks");
+ let hook_path = hooks_dir.join(GROK_HOOK_INSTALL_NAME);
+ let config_path = hooks_dir.join(GROK_HOOK_CONFIG_INSTALL_NAME);
+
+ // herdr owns both files outright, so removal is a straight delete.
+ let removed_config_file = remove_file_if_exists(&config_path)?;
+ let removed_hook_file = remove_file_if_exists(&hook_path)?;
+
+ Ok(GrokUninstallResult {
+ hook_path,
+ config_path,
+ removed_hook_file,
+ removed_config_file,
+ })
+}