Skip to content

Commit 565d920

Browse files
milla-jovovichclaude
authored andcommitted
feat: add MEMPAL_VERBOSE toggle — developers see diaries in chat (MemPalace#871)
export MEMPAL_VERBOSE=true → hook blocks, agent writes diary in chat export MEMPAL_VERBOSE=false → silent background save (default) Developers need to see code and diaries being written. Regular users want zero chat clutter. Now both work. TDD: tests written first, failed, code fixed, tests pass. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1485060 commit 565d920

2 files changed

Lines changed: 58 additions & 6 deletions

File tree

hooks/mempal_save_hook.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,25 @@ if [ "$SINCE_LAST" -ge "$SAVE_INTERVAL" ] && [ "$EXCHANGE_COUNT" -gt 0 ]; then
156156
"$PYTHON" -m mempalace mine "$MINE_DIR" >> "$STATE_DIR/hook.log" 2>&1 &
157157
fi
158158

159-
# Notify the AI that a checkpoint happened — but do NOT ask it to write
160-
# anything in chat. All filing happens in the background via the pipeline.
161-
# The old version asked the agent to write diary entries, add drawers, and
162-
# add KG triples in the chat window — that cost ~$1/session in retransmitted
163-
# tokens and cluttered the conversation.
164-
cat << 'HOOKJSON'
159+
# MEMPAL_VERBOSE toggle:
160+
# true = developer mode — block and show diaries/code in chat
161+
# false = silent mode (default) — save in background, no chat clutter
162+
# Set via: export MEMPAL_VERBOSE=true
163+
if [ "$MEMPAL_VERBOSE" = "true" ] || [ "$MEMPAL_VERBOSE" = "1" ]; then
164+
cat << 'HOOKJSON'
165+
{
166+
"decision": "block",
167+
"reason": "MemPalace save checkpoint. Write a brief session diary entry covering key topics, decisions, and code changes since the last save. Use verbatim quotes where possible. Continue after saving."
168+
}
169+
HOOKJSON
170+
else
171+
cat << 'HOOKJSON'
165172
{
166173
"decision": "allow",
167174
"reason": "MemPalace auto-save checkpoint. Your conversation is being saved verbatim in the background — no action needed from you. Continue working."
168175
}
169176
HOOKJSON
177+
fi
170178
else
171179
# Not time yet — let the AI stop normally
172180
echo "{}"

tests/test_save_hook_verbose.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""TDD: save hook must support verbose mode for developers.
2+
3+
Developers want to see diaries and code in chat.
4+
Regular users want silent background saves.
5+
The hook should check a config flag.
6+
"""
7+
8+
import os
9+
10+
11+
class TestSaveHookVerboseMode:
12+
"""Save hook must have a verbose/silent toggle."""
13+
14+
def test_hook_checks_verbose_flag(self):
15+
"""Hook must read a MEMPAL_VERBOSE or similar flag."""
16+
hook_path = os.path.join(
17+
os.path.dirname(os.path.dirname(__file__)),
18+
"hooks",
19+
"mempal_save_hook.sh",
20+
)
21+
src = open(hook_path).read()
22+
has_verbose = "VERBOSE" in src or "verbose" in src or "SILENT" in src or "silent" in src
23+
assert has_verbose, (
24+
"Save hook has no verbose/silent toggle. "
25+
"Developers need to see diaries and code in chat. "
26+
"Add MEMPAL_VERBOSE flag: when true, hook blocks and asks "
27+
"agent to write; when false, saves silently."
28+
)
29+
30+
def test_verbose_mode_blocks(self):
31+
"""When verbose, hook should use decision: block so agent writes in chat."""
32+
hook_path = os.path.join(
33+
os.path.dirname(os.path.dirname(__file__)),
34+
"hooks",
35+
"mempal_save_hook.sh",
36+
)
37+
src = open(hook_path).read()
38+
# There should be TWO decision paths: block (verbose) and allow (silent)
39+
has_block = '"decision": "block"' in src or "'decision': 'block'" in src
40+
has_allow = '"decision": "allow"' in src or "'decision': 'allow'" in src
41+
assert has_block and has_allow, (
42+
"Hook needs both 'block' (verbose/developer) and 'allow' (silent) paths. "
43+
f"Has block: {has_block}, has allow: {has_allow}"
44+
)

0 commit comments

Comments
 (0)