Skip to content

The agent that grows with you

fix: frozen-policy workers never tokenize the profile .env in skill_view

Teknium3c116048f581
diff --git a/tests/hermes_cli/test_corelane_frozen_worker_skill_env.py b/tests/hermes_cli/test_corelane_frozen_worker_skill_env.py
new file mode 100644
index 00000000000..036fd50be5f
--- /dev/null
+++ b/tests/hermes_cli/test_corelane_frozen_worker_skill_env.py
@@ -0,0 +1,56 @@
+"""A frozen-policy worker never opens the profile's ``.env`` -- including the skill readiness probe.
+
+``hermes_cli.config.load_env`` already returns ``{}`` under ``worker_config_snapshot()``; the
+``skill_view`` readiness snapshot must route through it instead of tokenizing the file itself.
+"""
+import json
+import os
+import subprocess
+import sys
+import textwrap
+from pathlib import Path
+
+import pytest
+
+ROOT = Path(__file__).resolve().parents[2]
+
+
+def _run(tmp_path, mode):
+ home = tmp_path / mode
+ (home / "skills" / "probe").mkdir(parents=True)
+ (home / ".env").write_text("CORELANE_PROBE_KEY=from-profile-dotenv\n", encoding="utf-8")
+ (home / "config.yaml").write_text("agent: {}\n", encoding="utf-8")
+ (home / "skills" / "probe" / "SKILL.md").write_text(
+ "---\nname: probe\ndescription: probe\nrequired_environment_variables:\n"
+ " - name: CORELANE_PROBE_KEY\n prompt: key\n---\nbody\n", encoding="utf-8")
+ script = home / "probe.py"
+ script.write_text(f"import sys; sys.path.insert(0, {str(ROOT)!r})\n" + textwrap.dedent("""
+ import json, os, sys
+ if os.environ["PROBE_MODE"] == "config":
+ from agent.safe_worker_policy import _bind_safe_worker_policy
+ _bind_safe_worker_policy(safe_mode=False, ignore_user_config=True, config={})
+ home = os.environ["HERMES_HOME"]
+ opened = []
+ sys.addaudithook(lambda e, a: opened.append(str(a[0]))
+ if e == "open" and str(a[0]).startswith(home) and str(a[0]).endswith(".env") else None)
+ from tools.skills_tool import skill_view
+ result = json.loads(skill_view("probe"))
+ print(json.dumps({"opened": opened, "missing": result.get("missing_required_environment_variables")}))
+ """), encoding="utf-8")
+ env = {k: os.environ[k] for k in ("PATH", "LANG", "TZ") if k in os.environ}
+ env.update(HOME=str(home), HERMES_HOME=str(home), PROBE_MODE=mode, HERMES_DISABLE_LAZY_INSTALLS="1")
+ proc = subprocess.run([sys.executable, str(script)], cwd=ROOT, env=env, stdin=subprocess.DEVNULL,
+ capture_output=True, text=True, timeout=90)
+ assert proc.returncode == 0, proc.stdout + proc.stderr
+ return json.loads(proc.stdout.strip().splitlines()[-1])
+
+
[email protected]("mode", ["config", "ordinary"])
+def test_skill_readiness_never_reads_profile_dotenv_in_frozen_worker(tmp_path, mode):
+ receipt = _run(tmp_path, mode)
+ if mode == "ordinary":
+ # Positive control: the ordinary loader sees the profile credential.
+ assert receipt["opened"] and receipt["missing"] == [], receipt
+ else:
+ assert receipt["opened"] == [], receipt
+ assert receipt["missing"] == ["CORELANE_PROBE_KEY"], receipt
diff --git a/tools/skills_tool.py b/tools/skills_tool.py
index 2cff3829929..8be98e1b949 100644
--- a/tools/skills_tool.py
+++ b/tools/skills_tool.py
@@ -95,7 +95,12 @@ def _skill_lookup_path_error(name: str) -> Optional[str]:
def load_env() -> Dict[str, str]:
"""Snapshot of HERMES_HOME/.env for the post-skill secret-capture diff (same tokenizer that
- installs the profile scope, so a captured value never differs from the served one)."""
+ installs the profile scope, so a captured value never differs from the served one). A frozen-policy
+ worker never opens the profile ``.env``: ``hermes_cli.config.load_env`` owns that short-circuit."""
+ from agent.safe_worker_policy import worker_config_snapshot
+
+ if worker_config_snapshot() is not None:
+ return {}
from agent.secret_scope import load_env_file
return load_env_file(get_hermes_home() / ".env")