From cb499332fa5ab1084d750d5cb2716d6c3bf756e6 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Fri, 27 Feb 2026 13:34:32 +0000 Subject: [PATCH] feat: add pregen background hook to UserPromptSubmit Wire `uncompact pregen &` into the installed hooks so the cache warms automatically in the background on every user prompt. Since pregen exits immediately when the cache is still fresh, the overhead is minimal. Also fix the mergeHooks deduplication logic for UserPromptSubmit: the previous switch branch added "uncompact show-cache" as an extra match for all UserPromptSubmit hooks, which would have caused the new pregen hook to be incorrectly skipped if show-cache was already installed. Now each command's alias matches are derived from its own content. Closes #95 Co-Authored-By: Grey Newell Co-Authored-By: Claude Sonnet 4.6 --- internal/hooks/hooks.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/hooks/hooks.go b/internal/hooks/hooks.go index bb45b7d..f4b8256 100644 --- a/internal/hooks/hooks.go +++ b/internal/hooks/hooks.go @@ -43,6 +43,11 @@ var uncompactHooks = map[string][]Hook{ {Type: "command", Command: `bash -c 'export PATH="$HOME/go/bin:$HOME/.local/bin:/usr/local/bin:/opt/homebrew/bin:$PATH"; uncompact show-cache'`}, }, }, + { + Hooks: []Command{ + {Type: "command", Command: `bash -c 'export PATH="$HOME/go/bin:$HOME/.local/bin:/usr/local/bin:/opt/homebrew/bin:$PATH"; uncompact pregen &'`}, + }, + }, }, } @@ -187,7 +192,8 @@ func commandExistsInHooks(hookList []Hook, matches ...string) bool { // isAlreadyInstalled checks if ALL uncompact hooks are present. func isAlreadyInstalled(hooks map[string][]Hook) bool { return commandExistsInHooks(hooks["Stop"], "uncompact run", "uncompact-hook.sh") && - commandExistsInHooks(hooks["UserPromptSubmit"], "uncompact show-cache", "show-hook.sh") + commandExistsInHooks(hooks["UserPromptSubmit"], "uncompact show-cache", "show-hook.sh") && + commandExistsInHooks(hooks["UserPromptSubmit"], "uncompact pregen") } // mergeHooks adds hooks from toAdd into existing, skipping any whose commands @@ -206,7 +212,11 @@ func mergeHooks(existing, toAdd map[string][]Hook) map[string][]Hook { case "Stop": matches = append(matches, "uncompact run", "uncompact-hook.sh") case "UserPromptSubmit": - matches = append(matches, "uncompact show-cache") + if strings.Contains(cmd.Command, "show-cache") { + matches = append(matches, "uncompact show-cache", "show-hook.sh") + } else if strings.Contains(cmd.Command, "pregen") { + matches = append(matches, "uncompact pregen") + } } if commandExistsInHooks(result[event], matches...) { skip = true