Files
yvgude--lean-ctx/integrations/hermes-lean-ctx/__init__.py
T
wehub-resource-sync 26382a7ac6
CI / Clippy (push) Failing after 15m13s
CI / Test (ubuntu-latest) (push) Failing after 16m1s
CI / Test (macos-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Build (no embeddings / no ORT) (push) Has been cancelled
CI / Format (push) Has been cancelled
CI / Cookbook (Node) (push) Has been cancelled
CI / Pi Extension (Node) (push) Has been cancelled
CI / Rust SDK (lean-ctx-client) (push) Has been cancelled
CI / Embed SDK (lean-ctx-sdk) (push) Has been cancelled
CI / Python SDK (leanctx) (push) Has been cancelled
CI / Hermes Plugin (Python) (push) Has been cancelled
CI / SDK Conformance Matrix (push) Has been cancelled
CI / Coverage (push) Has been cancelled
CI / cargo-deny (push) Has been cancelled
CI / Adversarial Safety (push) Has been cancelled
CI / Benchmarks (push) Has been cancelled
CI / Output-Quality Gate (eval A/B) (push) Has been cancelled
CI / Documentation (push) Has been cancelled
CI / CI Green (push) Has been cancelled
JetBrains Plugin / Actionlint (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (rust) (push) Has been cancelled
JetBrains Plugin / Validation (push) Has been cancelled
JetBrains Plugin / Build (push) Has been cancelled
JetBrains Plugin / Test (push) Has been cancelled
Security Check / Security Scan (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:35:30 +08:00

75 lines
2.3 KiB
Python

"""hermes-lean-ctx — lean-ctx as Hermes' active context engine.
Replaces the built-in ``ContextCompressor`` with deterministic, prompt-cache
friendly compaction and injects lean-ctx's code-intelligence + cross-session
memory tools natively into the agent.
Activate via ``config.yaml``::
context:
engine: "lean-ctx"
Engine logic lives in the lean-ctx daemon (Single Source of Truth); this plugin
is a thin adapter over the ``/v1`` HTTP API via the ``leanctx`` SDK.
"""
from __future__ import annotations
import logging
import os
__version__ = "0.1.0"
logger = logging.getLogger(__name__)
def _resolve_hermes_home() -> str:
try:
from hermes_cli.config import get_hermes_home # type: ignore
return str(get_hermes_home())
except Exception:
return os.environ.get("HERMES_HOME", os.path.expanduser("~/.hermes"))
def register(ctx) -> None:
"""Plugin entry point — register the lean-ctx context engine.
Native engine tools are exposed through the engine's ``get_tool_schemas`` /
``handle_tool_call`` and dispatched automatically by Hermes, so no separate
tool registration is required.
"""
from .config import LeanCtxConfig
from .engine import LeanCtxEngine
config = LeanCtxConfig.from_env()
engine = LeanCtxEngine(config=config, hermes_home=_resolve_hermes_home())
register_context_engine = getattr(ctx, "register_context_engine", None)
if not callable(register_context_engine):
logger.warning(
"hermes-lean-ctx: host does not support register_context_engine(); "
"is this a compatible Hermes Agent version?"
)
return
register_context_engine(engine)
logger.info(
"hermes-lean-ctx loaded — lean-ctx context engine active (daemon: %s)",
config.base_url,
)
# Exported for directory-discovery installs (plugins/context_engine/lean-ctx/)
# and for tests/benchmarks that import the engine directly.
def __getattr__(name: str):
# Lazy export so simply importing the package metadata never requires the
# Hermes ABC / leanctx SDK to be importable.
if name == "LeanCtxEngine":
from .engine import LeanCtxEngine
return LeanCtxEngine
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
__all__ = ["register", "LeanCtxEngine", "__version__"]