Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion hermes_cli/codex_runtime_plugin_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@
"# end hermes-agent managed section"
)

# Codex starts stdio MCP servers as child processes and only forwards
# explicitly allowlisted parent variables. Keep this list limited to Hermes'
# runtime identity and Kanban scope: provider credentials and endpoint
# overrides must never cross this boundary implicitly.
HERMES_TOOLS_DYNAMIC_ENV_VARS = (
"HERMES_HOME",
"HERMES_PROFILE",
"HERMES_PROFILE_NAME",
"HERMES_KANBAN_TASK",
"HERMES_KANBAN_WORKSPACE",
"HERMES_KANBAN_BRANCH",
"HERMES_KANBAN_RUN_ID",
"HERMES_KANBAN_DB",
"HERMES_KANBAN_WORKSPACES_ROOT",
"HERMES_KANBAN_BOARD",
)


@dataclass
class MigrationReport:
Expand Down Expand Up @@ -562,7 +579,9 @@ def _build_hermes_tools_mcp_entry() -> dict:
The command runs the worktree's Python via the current sys.executable
so a hermes installed under /opt/, /usr/local/, or a venv all work.
HERMES_HOME and PYTHONPATH are passed through so the spawned process
sees the same config + module layout the user is running."""
sees the same config + module layout the user is running. Dynamic worker
and board context is allowlisted separately so every Codex launch sees
the values from its parent rather than values captured at migrate time."""
import sys

env: dict[str, str] = {}
Expand Down Expand Up @@ -596,6 +615,7 @@ def _build_hermes_tools_mcp_entry() -> dict:
out: dict[str, Any] = {
"command": sys.executable,
"args": ["-m", "agent.transports.hermes_tools_mcp_server"],
"env_vars": list(HERMES_TOOLS_DYNAMIC_ENV_VARS),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also allowlist HERMES_KANBAN_CLAIM_LOCK. The dispatcher injects it for each worker, and kanban_heartbeat needs the identical lock to renew the claim; without it the MCP child falls back to its own host:pid and cannot update the dispatcher's claim.

}
if env:
out["env"] = env
Expand Down
31 changes: 31 additions & 0 deletions tests/hermes_cli/test_codex_runtime_plugin_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ def test_expose_hermes_tools_writes_callback_mcp_entry(self, tmp_path):

This is the fix for 'all other tools that codex doesn't provide
should be useable by hermes' — quirk #7."""
from hermes_cli.codex_runtime_plugin_migration import (
HERMES_TOOLS_DYNAMIC_ENV_VARS,
)

report = migrate({}, codex_home=tmp_path,
discover_plugins=False,
default_permission_profile=None,
Expand All @@ -502,9 +506,36 @@ def test_expose_hermes_tools_writes_callback_mcp_entry(self, tmp_path):
# Must include startup + tool timeouts so codex doesn't give up
assert "startup_timeout_sec" in text
assert "tool_timeout_sec" in text
required_worker_context = {
"HERMES_HOME",
"HERMES_KANBAN_TASK",
"HERMES_KANBAN_WORKSPACE",
"HERMES_KANBAN_RUN_ID",
"HERMES_KANBAN_DB",
"HERMES_KANBAN_BOARD",
}
assert required_worker_context <= set(HERMES_TOOLS_DYNAMIC_ENV_VARS)
assert all(name.startswith("HERMES_") for name in HERMES_TOOLS_DYNAMIC_ENV_VARS)
assert not any(
name.endswith(("API_KEY", "AUTH_TOKEN", "BASE_URL"))
for name in HERMES_TOOLS_DYNAMIC_ENV_VARS
)
for name in HERMES_TOOLS_DYNAMIC_ENV_VARS:
assert f'"{name}"' in text
# And the entry is reported
assert "hermes-tools" in report.migrated

# The managed block is replace-on-migrate. The dynamic context
# allowlist must survive every product regeneration, not merely a
# one-off manual edit to config.toml.
migrate({}, codex_home=tmp_path,
discover_plugins=False,
default_permission_profile=None,
expose_hermes_tools=True)
rerendered = (tmp_path / "config.toml").read_text()
assert rerendered.count("env_vars =") == 1
assert all(f'"{name}"' in rerendered for name in HERMES_TOOLS_DYNAMIC_ENV_VARS)

def test_expose_hermes_tools_disabled_skips_entry(self, tmp_path):
"""expose_hermes_tools=False suppresses the callback registration."""
migrate({}, codex_home=tmp_path,
Expand Down