Files
hermes-agent/hermes_cli/models_profile_cache.py
alt-glitch 074383f218 refactor(approval): the approval gate, detection and human prompts move from tools/ to approval/
tools/ holds model tools. These 36 files register none: they decide whether
a command or a write may run, detect dangerous commands, and ask a person
(approval prompts, gateway clarify, slash confirmations). They move to a new
root package, approval/, with command detection in approval/detection/.
tools/approval.py becomes approval/gate.py and tools/approval_detection.py
becomes approval/detection/patterns.py; the other files drop the approval_
prefix or keep their stem. 79 tests whose subject is a moved file move to
tests/approval/, whose conftest.py imports the autouse fixtures of
tests/tools/conftest.py they ran under.

Function bodies are unchanged and every import stays where it was. Loggers
follow their modules: the five module loggers that logged as tools.approval
now log as approval.gate, and approval joins the tools entry of
hermes_logging.COMPONENT_PREFIXES, so `hermes logs --component tools` shows
the same lines. approval also joins packages.find, FIRST_PARTY_MODULE_ROOTS,
_KNOWN_LOGGER_ROOTS, the plugin isolation audit, six check scripts, the P33
profile-scope pattern and the test fixtures that list root packages.

Ten old names keep a file at the old path, each a MOVES key, a
REQUIRED_NAMES row and a file written by scripts/move/generate_shims.py:
tools.approval and tools.clarify_gateway are on the published plugin API,
and all ten are imported inside functions on every turn, message, tool call
or human prompt by a process started on a release up to v0.23.5, which
keeps running its old code after an update swaps the checkout. Five more
modules that pinned catalog plugins import keep their old name through a
MOVES key with no file, listed in the plugin guide.

Both new packages call rebind_loaded_modules from their __init__, so a
session that outlives the update keeps the one gate it already holds: a
notifier registered before the update still reaches a background child's
approval request.
2026-12-01 17:49:22 +05:30

33 lines
1.4 KiB
Python

"""Per-profile view of ``hermes_cli.models``' module-level catalog slots.
Several caches on the facade (curated OpenRouter list, reasoning-capability catalogs and their
once-per-process guards) hold values derived from ONE profile's config, ``.env`` and ``<home>/cache``
files. In a multiplexed gateway every turn runs under a HERMES_HOME override, so a single module slot
would hand the launch profile's value to every other profile. Under an override the slot is read and
written per home key (routed profiles start cold, never from the launch profile's warmed value);
without one the module attribute stays the slot, so single-profile behaviour and the tests that reset
``models._X = None`` are untouched. Same shape as ``approval.gate._permanent_set``.
"""
from __future__ import annotations
from typing import Any
from hermes_constants import get_hermes_home_override, hermes_home_key
_SLOTS_BY_HOME: dict[tuple[str, str], Any] = {}
def profile_slot_get(module: Any, attr: str, default: Any = None) -> Any:
"""``module.<attr>`` for the active profile; ``default`` is a routed profile's cold value."""
if get_hermes_home_override() is None:
return getattr(module, attr)
return _SLOTS_BY_HOME.get((hermes_home_key(), attr), default)
def profile_slot_set(module: Any, attr: str, value: Any) -> None:
if get_hermes_home_override() is None:
setattr(module, attr, value)
else:
_SLOTS_BY_HOME[(hermes_home_key(), attr)] = value