Files
hermes-agent/storage_limits.py
yoniebans e50375c995 feat(storage): neutral helpers and the store-handle seams callers share
The top-level helpers the switched callers share (session keys, process identity, storage limits, lineage adoption, session rescue) and the store-handle seams that open persistence beside the legacy store, with the test fixtures and fakes the caller tests use.
2026-11-17 17:50:50 +01:00

25 lines
939 B
Python

"""The transcript size limits callers pass to the resume and export verbs."""
_MAX_SAFE_MESSAGES = 20_000 # resume/export guard default
def _configured_transcript_limit(key: str, fallback: int = _MAX_SAFE_MESSAGES) -> int:
"""``sessions.<key>`` from config.yaml (lazy import: circular at load), else *fallback*; 0 disables."""
try:
from hermes_cli.config import load_config_readonly
value = (load_config_readonly().get("sessions") or {}).get(key)
if value is None:
return fallback
limit = int(value)
return limit if limit >= 0 else fallback
except Exception: # health: allow BLE001 -- an unreadable config means the default limit
return fallback
def resolved_max_resume_messages() -> int:
return _configured_transcript_limit("max_resume_messages")
def resolved_max_export_messages() -> int:
return _configured_transcript_limit("max_export_messages")