Skip to content

Commit eace0ee

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

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
@@ -429,8 +429,6 @@ def _ingest_transcript(transcript_path: str):
429429
if not path.is_file() or path.stat().st_size < 100:
430430
return
431431

432-
from .config import MempalaceConfig
433-
434432
try:
435433
MempalaceConfig() # validate config loads
436434
except Exception:
@@ -497,16 +495,9 @@ def hook_stop(data: dict, harness: str):
497495
# (v3.3.0+), so if we can't read config, behave as if it's still on.
498496
silent_guard = True
499497
try:
500-
from .config import MempalaceConfig
501-
except ImportError as exc:
502-
_log(
503-
f"WARNING: could not import MempalaceConfig for stop guard: {exc}; defaulting to silent mode"
504-
)
505-
else:
506-
try:
507-
silent_guard = MempalaceConfig().hook_silent_save
508-
except AttributeError as exc:
509-
_log(f"WARNING: could not read hook_silent_save: {exc}; defaulting to silent mode")
498+
silent_guard = MempalaceConfig().hook_silent_save
499+
except AttributeError as exc:
500+
_log(f"WARNING: could not read hook_silent_save: {exc}; defaulting to silent mode")
510501
if not silent_guard:
511502
_output({})
512503
return
@@ -532,8 +523,6 @@ def hook_stop(data: dict, harness: str):
532523
_log(f"TRIGGERING SAVE at exchange {exchange_count}")
533524

534525
# Read hook settings from config
535-
from .config import MempalaceConfig
536-
537526
try:
538527
config = MempalaceConfig()
539528
silent = config.hook_silent_save

tests/test_hooks_cli.py

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

708708

709709
def test_stop_hook_enabled_by_default(tmp_path):
710-
"""When config has no hooks section, stop hook blocks normally."""
710+
"""When auto_save is enabled, stop hook saves silently (systemMessage)."""
711711
transcript = tmp_path / "t.jsonl"
712712
_write_transcript(
713713
transcript,
714714
[{"message": {"role": "user", "content": f"msg {i}"}} for i in range(SAVE_INTERVAL)],
715715
)
716+
save_result = {"count": 3, "themes": ["auto-save"]}
716717
with patch("mempalace.hooks_cli.MempalaceConfig") as mock_cfg_cls:
717718
mock_cfg_cls.return_value.hooks_auto_save = True
718-
result = _capture_hook_output(
719-
hook_stop,
720-
{
721-
"session_id": "test",
722-
"stop_hook_active": False,
723-
"transcript_path": str(transcript),
724-
},
725-
state_dir=tmp_path,
726-
)
727-
assert result["decision"] == "block"
719+
mock_cfg_cls.return_value.hook_silent_save = True
720+
mock_cfg_cls.return_value.hook_desktop_toast = False
721+
with patch("mempalace.hooks_cli._save_diary_direct", return_value=save_result):
722+
result = _capture_hook_output(
723+
hook_stop,
724+
{
725+
"session_id": "test",
726+
"stop_hook_active": False,
727+
"transcript_path": str(transcript),
728+
},
729+
state_dir=tmp_path,
730+
)
731+
assert "systemMessage" in result
732+
assert "3 memories" in result["systemMessage"]
728733

729734

730735
def test_precompact_hook_disabled_by_config(tmp_path):

0 commit comments

Comments
 (0)