Skip to content

The agent that grows with you

fix(profiles): hermes update never copies the default .env into a profile

Tekniumf92db3b007be
diff --git a/hermes_cli/profiles.py b/hermes_cli/profiles.py
index db27a63cf70..229c9995650 100644
--- a/hermes_cli/profiles.py
+++ b/hermes_cli/profiles.py
@@ -1479,26 +1479,17 @@ def seed_profile_skills(profile_dir: Path, quiet: bool = False) -> Optional[dict
def backfill_profile_envs(quiet: bool = False) -> list[str]:
- """Give every named profile lacking a ``.env`` one; never overwrites an existing one.
-
- Pre-#44792 profiles read the root ``.env`` through the process environment, so on update each
- gets a copy of the default's (else the placeholder header) to keep its model/tool credentials.
- Messaging-channel keys are stripped like ``--clone``: one bot credential can't be consumed twice.
+ """Seed the placeholder ``.env`` header into every named profile lacking one; never
+ overwrites an existing file. It never copies the default's ``.env``: secrets are
+ profile-scoped, and a copied bot token makes two adapters fight over one bot.
"""
- from hermes_cli.profile_channels import ChannelKeyIndex, strip_channel_env_file
backfilled: list[str] = []
- default_home = _get_default_hermes_home()
- default_env, index = default_home / ".env", None
for entry in _iter_named_profile_dirs():
env_path = entry / ".env"
if env_path.exists():
continue
try:
- if default_env.is_file():
- shutil.copy2(default_env, env_path)
- strip_channel_env_file(env_path, index := index or ChannelKeyIndex(default_home))
- else:
- env_path.write_text(_PLACEHOLDER_ENV, encoding="utf-8")
+ env_path.write_text(_PLACEHOLDER_ENV, encoding="utf-8")
os.chmod(str(env_path), 0o600)
backfilled.append(entry.name)
except OSError as e:
diff --git a/hermes_cli/update_cmd_maint.py b/hermes_cli/update_cmd_maint.py
index 8d4830ea37a..bfbd2afb41f 100644
--- a/hermes_cli/update_cmd_maint.py
+++ b/hermes_cli/update_cmd_maint.py
@@ -846,15 +846,14 @@ def _sync_profiles_after_update() -> None:
except Exception as pe:
print(f" {p.name}: error ({pe})")
- # Backfill .env for profiles created before .env seeding (copy the default's) so they
- # keep the credentials they were effectively using.
+ # Seed the placeholder .env into any named profile lacking one (never a copy of the default's).
with suppress(Exception):
# See #44792.
from hermes_cli.profiles import backfill_profile_envs
backfilled = backfill_profile_envs(quiet=True)
if backfilled:
print()
- print(f"→ Seeded .env for {len(backfilled)} profile(s) (copied from default): {', '.join(backfilled)}")
+ print(f"→ Seeded .env for {len(backfilled)} profile(s) (empty placeholder): {', '.join(backfilled)}")
with suppress(Exception):
from plugins.memory import import_provider_module
diff --git a/tests/hermes_cli/test_profiles.py b/tests/hermes_cli/test_profiles.py
index 1d019e84503..4e0924c0393 100644
--- a/tests/hermes_cli/test_profiles.py
+++ b/tests/hermes_cli/test_profiles.py
@@ -514,9 +514,9 @@ class TestNoSkillsOptOut:
class TestBackfillProfileEnvs:
"""Tests for backfill_profile_envs() — the `hermes update` pass that
gives pre-#44792 profiles (created before .env seeding) their own
- .env, copied from the default install so credentials don't break."""
+ .env: the placeholder header, never a copy of the default's secrets."""
- def test_copies_default_env_into_envless_profiles(self, profile_env):
+ def test_seeds_placeholder_never_the_default_env(self, profile_env):
import stat
tmp_path = profile_env
(tmp_path / ".hermes" / ".env").write_text("OPENROUTER_API_KEY=root-key\n", encoding="utf-8")
@@ -530,7 +530,7 @@ class TestBackfillProfileEnvs:
assert sorted(backfilled) == ["old1", "old2"]
for p in (p1, p2):
- assert (p / ".env").read_text(encoding="utf-8-sig") == "OPENROUTER_API_KEY=root-key\n"
+ assert "root-key" not in (p / ".env").read_text(encoding="utf-8-sig")
assert stat.S_IMODE((p / ".env").stat().st_mode) == 0o600
diff --git a/tests/hermes_cli/test_profiles_backfill_channels.py b/tests/hermes_cli/test_profiles_backfill_channels.py
index b2e9b01707a..9cccc460f24 100644
--- a/tests/hermes_cli/test_profiles_backfill_channels.py
+++ b/tests/hermes_cli/test_profiles_backfill_channels.py
@@ -1,7 +1,7 @@
-"""``hermes update``'s .env backfill must not hand a profile the default's bot credentials.
+"""``hermes update``'s .env backfill must never copy the default's secrets into a profile.
-One bot token can't be consumed twice: a copied TELEGRAM_BOT_TOKEN only ever surfaces as a
-``duplicate_credential`` fatal next to the default's live adapter (Desktop: "Backend telegram down").
+Secrets are profile-scoped, and one bot token can't be consumed twice: a copied TELEGRAM_BOT_TOKEN only
+ever surfaces as a ``duplicate_credential`` fatal next to the default's live adapter.
"""
from __future__ import annotations
@@ -22,14 +22,13 @@ def profile_env(tmp_path, monkeypatch):
return tmp_path
-def test_backfill_keeps_model_keys_and_drops_messaging_channels(profile_env):
+def test_backfill_never_copies_default_credentials(profile_env):
(profile_env / ".hermes" / ".env").write_text(
- "OPENROUTER_API_KEY=root-key\nTELEGRAM_BOT_TOKEN=123:abc\nTELEGRAM_ALLOWED_USERS=42\n"
- "DISCORD_BOT_TOKEN=d1\nDISCORD_HOME_CHANNEL=9\nFAL_KEY=f\n",
- encoding="utf-8",
+ "OPENROUTER_API_KEY=root-key\nTELEGRAM_BOT_TOKEN=123:abc\nDISCORD_BOT_TOKEN=d1\n", encoding="utf-8"
)
p = create_profile("legacy", no_alias=True, no_skills=True)
(p / ".env").unlink()
assert backfill_profile_envs(quiet=True) == ["legacy"]
- assert (p / ".env").read_text(encoding="utf-8-sig") == "OPENROUTER_API_KEY=root-key\nFAL_KEY=f\n"
+ assert all(line.startswith("#") or not line.strip()
+ for line in (p / ".env").read_text(encoding="utf-8-sig").splitlines())