The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(profiles): hoist the profile-id grammar into hermes_constants.PROFILE_ID_RE
teknium1348568ddaf79
diff --git a/hermes_cli/profiles.py b/hermes_cli/profiles.pyindex 3f42e7be318..8dd3146654b 100644--- a/hermes_cli/profiles.py+++ b/hermes_cli/profiles.py@@ -18,13 +18,13 @@ from typing import Dict, List, Optional, Tuplefrom hermes_cli.archive_safe import archive_root_dirs, make_targz, normalize_archive_parts, safe_extract_targzfrom hermes_constants import (- LOCAL_RUNTIME_ROOT_DIRS, clear_named_profile_deleted, mark_named_profile_deleted, named_profile_has_identity,- named_profile_is_deleted, named_profile_is_live,+ LOCAL_RUNTIME_ROOT_DIRS, PROFILE_ID_RE, clear_named_profile_deleted, mark_named_profile_deleted,+ named_profile_has_identity, named_profile_is_deleted, named_profile_is_live,)logger = logging.getLogger(__name__)-_PROFILE_ID_RE = re.compile(r"^[a-z0-9][a-z0-9_-]{0,63}$")+_PROFILE_ID_RE = PROFILE_ID_RE # legacy alias; hermes_constants.PROFILE_ID_RE is canonical# Directories bootstrapped inside every new profile. ``home`` is the back-compat/Docker# HOME for tool subprocesses (host subprocesses keep the real HOME so CLI credentialsdiff --git a/hermes_cli/update_restart_recovery.py b/hermes_cli/update_restart_recovery.pyindex 7add7fe0f07..f49b41cf36d 100644--- a/hermes_cli/update_restart_recovery.py+++ b/hermes_cli/update_restart_recovery.py@@ -60,7 +60,8 @@ _RECOVERY_ENV = "HERMES_UPDATE_RESTART_RECOVERY"_GATEWAY_MARKERS = ("_HERMES_GATEWAY", "HERMES_GATEWAY", "HERMES_GATEWAY_MODE")_PROFILE_RESTART_TIMEOUT = 90_VERIFY_TIMEOUT = 15-_PROFILE_ID_RE = re.compile(r"^[a-z0-9][a-z0-9_-]{0,63}$")+from hermes_constants import PROFILE_ID_RE as _PROFILE_ID_RE+_SUPERVISOR_RE = re.compile(r"^[a-z0-9][a-z0-9_-]{0,31}$")_UNIT_RE = re.compile(r"^hermes-serve(-[a-z0-9][a-z0-9_-]{0,63})?\.service$")_SERVE_UNIT_PATTERN = "hermes-serve*"diff --git a/hermes_constants.py b/hermes_constants.pyindex cae64930023..89ee7f8d773 100644--- a/hermes_constants.py+++ b/hermes_constants.py@@ -277,6 +277,8 @@ def named_profile_is_deleted(profile_home: str | Path) -> bool:# none of these; a pre-tombstone ghost shell or a stray infrastructure dir must never be# listed, served, ticked, or seeded with the default install's credentials._PROFILE_IDENTITY_MARKERS = ("config.yaml", ".env", "SOUL.md", "profile.yaml", "auth.json", "state.db")+# Canonical named-profile id grammar; every profile-directory gate imports this one object.+PROFILE_ID_RE = re.compile(r"^[a-z0-9][a-z0-9_-]{0,63}$")def named_profile_has_identity(profile_home: str | Path) -> bool:diff --git a/tests/tools/test_bot_mode_probe.py b/tests/tools/test_bot_mode_probe.pyindex 5097060cd89..7405b3f8531 100644--- a/tests/tools/test_bot_mode_probe.py+++ b/tests/tools/test_bot_mode_probe.py@@ -71,36 +71,6 @@ def test_roster_excludes_dirs_failing_the_profile_id_regex(tmp_path):assert not any(f"`@{s}`" in section for s in ("_backup_removed_20260920", ".staging-area"))-def test_profile_id_regex_mirror_stays_in_sync_with_canonical():- """The roster's mirrored profile-id predicate must accept and reject exactly what the- canonical ``hermes_cli.profiles._PROFILE_ID_RE`` accepts and rejects — the #116905 bug- class was precisely these two predicates drifting apart (review follow-up)."""- from hermes_cli.profiles import _PROFILE_ID_RE as canonical-- samples = [- "researcher",- "content-creator",- "trade-ops2",- "a",- "0",- "a" * 64,- "a" * 65,- "_backup_removed",- ".staging-area",- "has space",- "UPPER",- "default",- "-leading-dash",- "trailing-dash-",- "sla/sh",- "emoji-\U0001f916",- ]- for sample in samples:- assert bool(bot_mode_probe._PROFILE_ID_RE.match(sample)) == bool(- canonical.match(sample)- ), sample--def test_silent_when_no_profile_is_bot_managed(tmp_path):home = tmp_path / ".hermes"home.mkdir()diff --git a/tools/bot_mode_probe.py b/tools/bot_mode_probe.pyindex 3f9f63d56c7..eb1b20084d5 100644--- a/tools/bot_mode_probe.py+++ b/tools/bot_mode_probe.py@@ -20,10 +20,6 @@ from pathlib import Path_PROTOCOL_HEADING = "## Messaging other agents"# The legacy section through the next H2 heading (or EOF), plus the blank lines before it._LEGACY_PROTOCOL_RE = re.compile(r"\n*" + re.escape(_PROTOCOL_HEADING) + r"[ \t]*\n.*?(?=\n## |\Z)", re.S)-# Mirrors hermes_cli.profiles._PROFILE_ID_RE (not imported: this module must stay-# import-light on the system-prompt path, and hermes_cli.profiles drags in the full-# profile machinery — archive/tar, subprocess, threading — for one regex).-_PROFILE_ID_RE = re.compile(r"^[a-z0-9][a-z0-9_-]{0,63}$")def strip_legacy_protocol(text: str) -> str:@@ -78,14 +74,14 @@ def _roster(root: Path) -> list[tuple[str, Path]]:predicate as ``profile list``: infra dirs (``sessions/``, ``logs/``) and tombstones are notteammates (#99392), and neither is a marker-carrying dir whose name is not a profile id —a parked backup or staging dir must never become a ``message_agent`` target (#116905)."""- from hermes_constants import named_profile_is_live+ from hermes_constants import PROFILE_ID_RE, named_profile_is_liveprofiles = root / "profiles"named = _swallow(lambda: [(c.name, c)for c in sorted(profiles.iterdir())- if c.name != "default" and _PROFILE_ID_RE.match(c.name) and named_profile_is_live(c)+ if c.name != "default" and PROFILE_ID_RE.match(c.name) and named_profile_is_live(c)]if profiles.is_dir()else [],