Skip to content

Commit 0de2a6e

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

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
@@ -435,8 +435,6 @@ def _ingest_transcript(transcript_path: str):
435435
if not path.is_file() or path.stat().st_size < 100:
436436
return
437437

438-
from .config import MempalaceConfig
439-
440438
try:
441439
MempalaceConfig() # validate config loads
442440
except Exception:
@@ -536,16 +534,9 @@ def hook_stop(data: dict, harness: str):
536534
# (v3.3.0+), so if we can't read config, behave as if it's still on.
537535
silent_guard = True
538536
try:
539-
from .config import MempalaceConfig
540-
except ImportError as exc:
541-
_log(
542-
f"WARNING: could not import MempalaceConfig for stop guard: {exc}; defaulting to silent mode"
543-
)
544-
else:
545-
try:
546-
silent_guard = MempalaceConfig().hook_silent_save
547-
except AttributeError as exc:
548-
_log(f"WARNING: could not read hook_silent_save: {exc}; defaulting to silent mode")
537+
silent_guard = MempalaceConfig().hook_silent_save
538+
except AttributeError as exc:
539+
_log(f"WARNING: could not read hook_silent_save: {exc}; defaulting to silent mode")
549540
if not silent_guard:
550541
_output({})
551542
return
@@ -571,8 +562,6 @@ def hook_stop(data: dict, harness: str):
571562
_log(f"TRIGGERING SAVE at exchange {exchange_count}")
572563

573564
# Read hook settings from config
574-
from .config import MempalaceConfig
575-
576565
try:
577566
config = MempalaceConfig()
578567
silent = config.hook_silent_save

tests/test_hooks_cli.py

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

769769

770770
def test_stop_hook_enabled_by_default(tmp_path):
771-
"""When config has no hooks section, stop hook blocks normally."""
771+
"""When auto_save is enabled, stop hook saves silently (systemMessage)."""
772772
transcript = tmp_path / "t.jsonl"
773773
_write_transcript(
774774
transcript,
775775
[{"message": {"role": "user", "content": f"msg {i}"}} for i in range(SAVE_INTERVAL)],
776776
)
777+
save_result = {"count": 3, "themes": ["auto-save"]}
777778
with patch("mempalace.hooks_cli.MempalaceConfig") as mock_cfg_cls:
778779
mock_cfg_cls.return_value.hooks_auto_save = True
779-
result = _capture_hook_output(
780-
hook_stop,
781-
{
782-
"session_id": "test",
783-
"stop_hook_active": False,
784-
"transcript_path": str(transcript),
785-
},
786-
state_dir=tmp_path,
787-
)
788-
assert result["decision"] == "block"
780+
mock_cfg_cls.return_value.hook_silent_save = True
781+
mock_cfg_cls.return_value.hook_desktop_toast = False
782+
with patch("mempalace.hooks_cli._save_diary_direct", return_value=save_result):
783+
result = _capture_hook_output(
784+
hook_stop,
785+
{
786+
"session_id": "test",
787+
"stop_hook_active": False,
788+
"transcript_path": str(transcript),
789+
},
790+
state_dir=tmp_path,
791+
)
792+
assert "systemMessage" in result
793+
assert "3 memories" in result["systemMessage"]
789794

790795

791796
def test_precompact_hook_disabled_by_config(tmp_path):

0 commit comments

Comments
 (0)