Skip to content

Commit 4dc4f39

Browse files
Claudeclaude
authored andcommitted
feat: add knowledge-retrieval detection to auto-retrieve hook
Routes institutional-memory queries ("what's our process for X", "recall how we handle Y") through GitMem search instead of passive scar injection. Fixes UserPromptSubmit missing from init wizard's buildClaudeHooks(). Updates stale EXPECTED_TOOL_COUNTS (free 21→22, pro 26→27, dev 30→31). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8b07d69 commit 4dc4f39

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

bin/init-wizard.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,17 @@ function buildClaudeHooks() {
253253
],
254254
},
255255
],
256+
UserPromptSubmit: [
257+
{
258+
hooks: [
259+
{
260+
type: "command",
261+
command: `bash ${relScripts}/auto-retrieve-hook.sh`,
262+
timeout: 3000,
263+
},
264+
],
265+
},
266+
],
256267
PreToolUse: [
257268
{
258269
matcher: "Bash",

hooks/scripts/auto-retrieve-hook.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,37 @@ PROMPT_LEN=${#PROMPT}
6565

6666
RETRIEVAL_LEVEL=""
6767

68+
# Priority 0: Knowledge-retrieval queries — route through gitmem, don't inject scars
69+
# These are queries where the user wants to ACCESS institutional memory, not just
70+
# have scars passively injected. Output a routing instruction instead of scars.
71+
IS_KNOWLEDGE_QUERY=false
72+
73+
# Explicit recall/remember commands
74+
if echo "$PROMPT_LOWER" | grep -qE '\b(recall|remember)\b.*(doc|process|tree|structure|how|what|where|our)'; then
75+
IS_KNOWLEDGE_QUERY=true
76+
# Process/documentation queries ("what's our process for X", "how do we usually Y")
77+
elif echo "$PROMPT_LOWER" | grep -qE "(what('s| is) our (process|approach|pattern|method)|how do we (usually|typically|normally)|remind me (how|what|about)|what('s| is) the (process|protocol|procedure) for)"; then
78+
IS_KNOWLEDGE_QUERY=true
79+
# Documentation discovery ("show me the docs", "where are the scars")
80+
elif echo "$PROMPT_LOWER" | grep -qE '\b(show me|find|where (is|are|do)).*(doc(s|umentation)?|process(es)?|pattern(s)?|decision(s)?|scar(s)?|learning(s)?)\b'; then
81+
IS_KNOWLEDGE_QUERY=true
82+
# Institutional knowledge queries ("what did we decide about", "what scars exist")
83+
elif echo "$PROMPT_LOWER" | grep -qE '\b(what did we (decide|learn|document)|what scars|what learnings|past decisions about|institutional (memory|knowledge))\b'; then
84+
IS_KNOWLEDGE_QUERY=true
85+
# Direct "recall" as a verb/command at start of prompt
86+
elif echo "$PROMPT_LOWER" | grep -qE '^\s*recall\b'; then
87+
IS_KNOWLEDGE_QUERY=true
88+
fi
89+
90+
if [ "$IS_KNOWLEDGE_QUERY" = "true" ]; then
91+
cat <<HOOKJSON
92+
{
93+
"additionalContext": "KNOWLEDGE RETRIEVAL DETECTED. Route through GitMem FIRST:\n\n1. gitmem search (query relevant to the question) OR gitmem recall (if action-oriented)\n2. gitmem log (if browsing recent learnings)\n3. ONLY THEN fall back to filesystem reads if gitmem doesn't have the answer\n\nDo NOT start with Read/Glob/Grep on local files. Institutional memory exists precisely so we don't re-explore the filesystem every time."
94+
}
95+
HOOKJSON
96+
exit 0
97+
fi
98+
6899
# Priority 1: Trivial — skip retrieval entirely
69100
if echo "$PROMPT_LOWER" | grep -qE '^(yes|no|ok|k|y|n|sure|thanks|thank you|continue|go ahead|proceed|correct|right|exactly|got it|sounds good|lgtm|looks good|done|nope|yep|yup|agreed)$'; then
70101
exit 0

tests/e2e/mcp-client.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,13 @@ export const DEV_TOOLS = [
272272
*
273273
* free = 73 - 6 - 3 - 2 - 4 - 3 = 55
274274
* pro = 73 - 2 - 4 = 67
275-
* dev = 27
275+
* dev = 31
276276
*
277277
* If these numbers change, a tool was added/removed from definitions.ts.
278278
* Note: Aliases are hidden by default. Set GITMEM_FULL_ALIASES=1 to show all.
279279
*/
280280
export const EXPECTED_TOOL_COUNTS = {
281-
free: 21,
282-
pro: 26,
283-
dev: 30,
281+
free: 22,
282+
pro: 27,
283+
dev: 31,
284284
} as const;

0 commit comments

Comments
 (0)