session_reset_retirement.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """Point configs that still declare an idle/daily ``session_reset`` at the plugin that restores it.
  2. Core stopped rotating gateway conversations on timers (1d5d059410) and reads nothing under
  3. ``session_reset``. A household that relied on it silently gets conversations that never end and
  4. a bill that grows with them, so gateway startup and ``hermes doctor`` say so. The
  5. ``hermes-session-reset-policy`` catalog plugin reads the top-level block unchanged, which is why
  6. this module reports and never rewrites or drops the key.
  7. """
  8. from __future__ import annotations
  9. from typing import Any, Optional, Tuple
  10. PLUGIN_NAME = "hermes-session-reset-policy"
  11. _TIMED_MODES = frozenset({"idle", "daily", "both"})
  12. def retired_reset_policy(config: Any) -> Optional[tuple[str, str]]:
  13. """``(config_path, mode)`` for a timed ``session_reset`` the config still declares, else None.
  14. Looks at the top-level block and the ``gateway:`` form the pre-removal loader also accepted.
  15. """
  16. if not isinstance(config, dict):
  17. return None
  18. gateway = config.get("gateway")
  19. for path, block in (
  20. ("session_reset", config.get("session_reset")),
  21. ("gateway.session_reset", gateway.get("session_reset") if isinstance(gateway, dict) else None),
  22. ):
  23. if isinstance(block, dict):
  24. mode = str(block.get("mode") or "").strip().lower()
  25. if mode in _TIMED_MODES:
  26. return path, mode
  27. return None
  28. def reset_plugin_enabled() -> bool:
  29. """Whether the restoring plugin is installed and enabled in this process's plugin set."""
  30. from hermes_cli.plugins import discover_plugins, get_plugin_manager
  31. discover_plugins()
  32. return any(p["name"] == PLUGIN_NAME and p["enabled"] for p in get_plugin_manager().list_plugins())
  33. def format_notice(path: str, mode: str) -> str:
  34. move = "" if path == "session_reset" else " (move the block to top-level session_reset first)"
  35. return (
  36. f"{path}.mode: {mode} is no longer applied: gateway conversations reset only on /new or "
  37. f"/reset. To keep idle/daily resets, run `hermes plugins install {PLUGIN_NAME}`{move}."
  38. )