Skip to content

Commit 68d3df5

Browse files
committed
fix(hooks): retarget auto_save toggle at silent-save path after #1021 rebase
1 parent aa3b237 commit 68d3df5

2 files changed

Lines changed: 19 additions & 25 deletions

File tree

mempalace/hooks_cli.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,6 @@ def _ingest_transcript(transcript_path: str):
463463
if not path.is_file() or path.stat().st_size < 100:
464464
return
465465

466-
from .config import MempalaceConfig
467-
468466
try:
469467
MempalaceConfig() # validate config loads
470468
except Exception:
@@ -564,16 +562,9 @@ def hook_stop(data: dict, harness: str):
564562
# (v3.3.0+), so if we can't read config, behave as if it's still on.
565563
silent_guard = True
566564
try:
567-
from .config import MempalaceConfig
568-
except ImportError as exc:
569-
_log(
570-
f"WARNING: could not import MempalaceConfig for stop guard: {exc}; defaulting to silent mode"
571-
)
572-
else:
573-
try:
574-
silent_guard = MempalaceConfig().hook_silent_save
575-
except AttributeError as exc:
576-
_log(f"WARNING: could not read hook_silent_save: {exc}; defaulting to silent mode")
565+
silent_guard = MempalaceConfig().hook_silent_save
566+
except AttributeError as exc:
567+
_log(f"WARNING: could not read hook_silent_save: {exc}; defaulting to silent mode")
577568
if not silent_guard:
578569
_output({})
579570
return
@@ -599,8 +590,6 @@ def hook_stop(data: dict, harness: str):
599590
_log(f"TRIGGERING SAVE at exchange {exchange_count}")
600591

601592
# Read hook settings from config
602-
from .config import MempalaceConfig
603-
604593
try:
605594
config = MempalaceConfig()
606595
silent = config.hook_silent_save

tests/test_hooks_cli.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -906,24 +906,29 @@ def test_stop_hook_disabled_by_config(tmp_path):
906906

907907

908908
def test_stop_hook_enabled_by_default(tmp_path):
909-
"""When config has no hooks section, stop hook blocks normally."""
909+
"""When auto_save is enabled, stop hook saves silently (systemMessage)."""
910910
transcript = tmp_path / "t.jsonl"
911911
_write_transcript(
912912
transcript,
913913
[{"message": {"role": "user", "content": f"msg {i}"}} for i in range(SAVE_INTERVAL)],
914914
)
915+
save_result = {"count": 3, "themes": ["auto-save"]}
915916
with patch("mempalace.hooks_cli.MempalaceConfig") as mock_cfg_cls:
916917
mock_cfg_cls.return_value.hooks_auto_save = True
917-
result = _capture_hook_output(
918-
hook_stop,
919-
{
920-
"session_id": "test",
921-
"stop_hook_active": False,
922-
"transcript_path": str(transcript),
923-
},
924-
state_dir=tmp_path,
925-
)
926-
assert result["decision"] == "block"
918+
mock_cfg_cls.return_value.hook_silent_save = True
919+
mock_cfg_cls.return_value.hook_desktop_toast = False
920+
with patch("mempalace.hooks_cli._save_diary_direct", return_value=save_result):
921+
result = _capture_hook_output(
922+
hook_stop,
923+
{
924+
"session_id": "test",
925+
"stop_hook_active": False,
926+
"transcript_path": str(transcript),
927+
},
928+
state_dir=tmp_path,
929+
)
930+
assert "systemMessage" in result
931+
assert "3 memories" in result["systemMessage"]
927932

928933

929934
def test_precompact_hook_disabled_by_config(tmp_path):

0 commit comments

Comments
 (0)