1+ #! /bin/bash
2+
3+ # Read JSON input from stdin
4+ json_input=$( cat)
5+
6+ # Extract the prompt field from JSON
7+ prompt=$( echo " $json_input " | jq -r ' .prompt // empty' )
8+
9+ # If no prompt field, exit without output
10+ if [ -z " $prompt " ]; then
11+ exit 0
12+ fi
13+
14+ # Get the project root (current working directory)
15+ PROJECT_ROOT=" $( pwd) "
16+
17+ # Get the acronyms config path
18+ acronyms_file=" ${PROJECT_ROOT} /.memento/acronyms.json"
19+
20+ # Check if acronyms config exists
21+ if [ ! -f " $acronyms_file " ]; then
22+ # No acronyms file - don't output anything
23+ exit 0
24+ fi
25+
26+ # Read acronyms config
27+ acronyms_json=$( cat " $acronyms_file " 2> /dev/null || echo ' {}' )
28+
29+ # Extract settings
30+ case_sensitive=$( echo " $acronyms_json " | jq -r ' .settings.caseSensitive // false' )
31+ whole_word=$( echo " $acronyms_json " | jq -r ' .settings.wholeWordOnly // true' )
32+
33+ # Get all acronyms
34+ acronyms=$( echo " $acronyms_json " | jq -r ' .acronyms // {} | to_entries | .[] | "\(.key)|\(.value)"' )
35+
36+ # Track detected acronyms
37+ detected_acronyms=" "
38+
39+ # Check each acronym
40+ while IFS=' |' read -r acronym expansion; do
41+ if [ -z " $acronym " ]; then
42+ continue
43+ fi
44+
45+ # Build the search pattern
46+ if [ " $whole_word " = " true" ]; then
47+ pattern=" \\ b${acronym} \\ b"
48+ else
49+ pattern=" $acronym "
50+ fi
51+
52+ # Check if acronym exists in prompt
53+ if [ " $case_sensitive " = " true" ]; then
54+ if echo " $prompt " | grep -q " $pattern " ; then
55+ detected_acronyms=" ${detected_acronyms} - **${acronym} **: ${expansion} \n"
56+ fi
57+ else
58+ if echo " $prompt " | grep -qi " $pattern " ; then
59+ # For case-insensitive, show the uppercase version
60+ display_acronym=$( echo " $acronym " | tr ' [:lower:]' ' [:upper:]' )
61+ detected_acronyms=" ${detected_acronyms} - **${display_acronym} **: ${expansion} \n"
62+ fi
63+ fi
64+ done <<< " $acronyms"
65+
66+ # If any acronyms were detected, output ONLY the glossary
67+ # Claude Code will append the original prompt
68+ if [ -n " $detected_acronyms " ]; then
69+ echo -e " ## Acronym Glossary\n${detected_acronyms} \n---\n"
70+ fi
0 commit comments