Files
雷电芽衣 bc6983a62e chore(oss): audit the server package and resync the SDK mirrors
Split the 657-line operation service into eor, submit, and verify
modules, add the AGENT_REVOKED and KEY_RETIRED codes the Backend already
emits, and condense every multi-line comment. Mirror Node, Python, and
Go at 2.1.0 with the deep-health 503, non-idempotent retry, rotation
grace, and path-encoding fixes. Document which routes and response
fields the self-hosted server does not provide.

Claude-Session: https://claude.ai/code/session_01Agoc9bRVE9KL7mmWtey9Vq
2026-09-03 20:48:20 -04:00

79 lines
2.8 KiB
Python

"""Letta Code 0.28 native global hook integration."""
from __future__ import annotations
from typing import Dict
from ._runtime import RuntimePaths
from .base import AgentPlugin, InstallConfig, PluginStatus
from .letta_config import render_letta_document
from .letta_contract import (
AGENT_KEY,
JsonObject,
build_letta_group,
letta_runtime_contracts,
)
from .letta_installation import (
commit_letta_installation,
commit_letta_uninstall,
preflight_letta_installation,
prepare_letta_installation,
prepare_letta_uninstall,
)
from .letta_io import letta_runtime_files_exist
from .letta_sources import read_letta_sources
def _installed_groups(paths: RuntimePaths) -> Dict[str, JsonObject]:
return {
"PreToolUse": build_letta_group(paths.guard_path),
"PostToolUse": build_letta_group(paths.audit_path),
"PostToolUseFailure": build_letta_group(paths.audit_path),
}
class LettaPlugin(AgentPlugin):
"""Install Elydora into Letta Code's native global settings."""
manages_guard_runtime = True
def preflight_install(self, config: InstallConfig) -> None:
sources = read_letta_sources()
preflight_letta_installation(config, sources)
def install(self, config: InstallConfig) -> None:
sources = read_letta_sources()
paths = preflight_letta_installation(config, sources)
rendered = render_letta_document(
sources.global_settings,
None,
_installed_groups(paths),
)
changes = prepare_letta_installation(config, paths, rendered)
commit_letta_installation(changes, sources)
print(f"Letta Code hooks installed at {sources.global_settings.file_path}")
print("Letta Code verification: run /hooks and restart active sessions.")
def uninstall(self, agent_id: str = "") -> None:
sources = read_letta_sources()
rendered = render_letta_document(
sources.global_settings, agent_id or None, {}
)
commit_letta_uninstall(prepare_letta_uninstall(rendered), sources)
def status(self) -> PluginStatus:
sources = read_letta_sources()
contracts = letta_runtime_contracts(sources.global_settings.hooks)
configured = not sources.disable_control.disabled and bool(contracts)
installed = configured and letta_runtime_files_exist(contracts)
file_path = sources.global_settings.file_path
if installed:
details = f"Config: {file_path}"
elif contracts and sources.disable_control.disabled:
details = f"Configured hooks are disabled: {file_path}"
elif contracts:
details = f"Configured at {file_path}; managed contract incomplete"
else:
details = "Not installed"
return PluginStatus(installed=installed, agent=AGENT_KEY, details=details)