fix(letta): mirror official Python hook integration

This commit is contained in:
ZacharyZhang-NY committed 2026-07-20 18:48:01 -04:00
1 parent 24a9d64978
commit 53476feca7
19 files changed
+2443 -212

No files matched your search

@@ -1,15 +1,39 @@
from __future__ import annotations
from elydora.plugins.letta import _is_elydora_hook as is_letta_hook
from pathlib import Path
import sys
import pytest
from elydora.plugins.letta_command import build_letta_command
from elydora.plugins.letta_contract import managed_letta_removals
def test_hook_detection_handles_only_string_commands() -> None:
assert is_letta_hook({"command": 42}, "") is False
assert is_letta_hook({"hooks": [{"command": None}]}, "") is False
assert is_letta_hook(
{"hooks": [{"command": "run .elydora/agent-1/hook.py"}]}, ""
) is True
assert is_letta_hook(
{"hooks": [{"command": "run .elydora/agent-1/hook.py"}]},
"agent-2",
) is False
def test_letta_hook_detection_requires_exact_owned_commands(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
home = tmp_path / "home"
guard = home / ".elydora" / "agent-1" / "guard.py"
monkeypatch.setenv("HOME", str(home))
monkeypatch.setenv("USERPROFILE", str(home))
hooks = {
"PreToolUse": [{
"matcher": "*",
"hooks": [{
"type": "command",
"command": build_letta_command(str(guard)),
"timeout": 10_000,
}],
}],
}
assert len(managed_letta_removals(hooks)) == 1
hooks["PreToolUse"][0]["hooks"][0]["quiet"] = True
assert managed_letta_removals(hooks) == []
hooks["PreToolUse"][0]["hooks"][0] = {
"type": "command",
"command": f'"{sys.executable}" {guard}',
}
assert len(managed_letta_removals(hooks, "agent-1")) == 1
assert managed_letta_removals(hooks, "agent-2") == []