Skip to content

The agent that grows with you

fix(tui): keep troubleshooting flags scoped to the launching session

David Dudok de Wit0a223726c37e
diff --git a/hermes_cli/gateway_runtime_start.py b/hermes_cli/gateway_runtime_start.py
index 5fb901a8fe1..0d9c222e735 100644
--- a/hermes_cli/gateway_runtime_start.py
+++ b/hermes_cli/gateway_runtime_start.py
@@ -33,11 +33,13 @@ def spawn_unmanaged_gateway(profile_home: Path, *, deadline: float) -> subproces
env[_WINDOWS_GATEWAY_BREAKAWAY_ENV] = "1"
env.update(HERMES_HOME=str(home), HERMES_GATEWAY_DETACHED="1", PYTHONIOENCODING="utf-8")
# Profile selection is the explicit home, not the invoking client's display
- # name. Runtime policy comes from that profile, never a launcher's --yolo/--ignore-rules
- # (those ride the launching session's frozen policy, not every later session's daemon).
+ # name. Launch-only approval/context/config flags ride the launching session's frozen
+ # policy, not the shared daemon or every later session.
env.pop("HERMES_PROFILE", None)
env.pop("HERMES_YOLO_MODE", None)
env.pop("HERMES_IGNORE_RULES", None)
+ env.pop("HERMES_SAFE_MODE", None)
+ env.pop("HERMES_IGNORE_USER_CONFIG", None)
remaining(deadline)
logs = home / "logs"
logs.mkdir(parents=True, exist_ok=True)
diff --git a/hermes_cli/main.py b/hermes_cli/main.py
index 50b59f51789..c74ae5a1486 100644
--- a/hermes_cli/main.py
+++ b/hermes_cli/main.py
@@ -2884,7 +2884,7 @@ def _is_tui_chat_launch(args) -> bool:
def _bypass_chat_launch(args) -> bool:
"""--safe-mode / --ignore-user-config chat: the gateway owner freezes code defaults and runs
the turn out of process, so the profile's display.interface must not pick a surface and the
- client performs no discovery. Explicit --tui is refused later by the TUI's own option gate."""
+ client performs no discovery. Explicit --tui forwards the flags in its session.create policy."""
return bool(getattr(args, "safe_mode", False) or getattr(args, "ignore_user_config", False)) \
and not getattr(args, "tui", False)
diff --git a/tests/hermes_cli/test_gateway_runtime_ensure.py b/tests/hermes_cli/test_gateway_runtime_ensure.py
index 8c41d070fba..dc144cf58ea 100644
--- a/tests/hermes_cli/test_gateway_runtime_ensure.py
+++ b/tests/hermes_cli/test_gateway_runtime_ensure.py
@@ -9,6 +9,28 @@ import time
import pytest
+def test_unmanaged_runtime_drops_session_config_bypass_flags(tmp_path, monkeypatch):
+ from types import SimpleNamespace
+ from hermes_cli import gateway_runtime_start as start
+ from hermes_cli import gateway_windows
+
+ flags = ('HERMES_SAFE_MODE', 'HERMES_IGNORE_USER_CONFIG')
+ for key in flags:
+ monkeypatch.setenv(key, '1')
+ monkeypatch.setenv('RUNTIME_TEST_SENTINEL', 'retained')
+ monkeypatch.setattr(gateway_windows, 'windowless_gateway_restart_spec',
+ lambda command: (command, None, {'RUNTIME_TEST_OVERLAY': '1'}))
+ captured = {}
+ child = SimpleNamespace(pid=123)
+ def spawn(command, **kwargs):
+ captured.update(kwargs)
+ return child
+ monkeypatch.setattr(start.subprocess, 'Popen', spawn)
+ assert start.spawn_unmanaged_gateway(tmp_path, deadline=time.monotonic() + 5) is child
+ assert all(key not in captured['env'] for key in flags)
+ assert captured['env']['RUNTIME_TEST_SENTINEL'] == 'retained'
+ assert all(os.environ[key] == '1' for key in flags)
+
@pytest.mark.platforms("linux")
def test_ensure_waits_for_real_control_owner_without_claiming_pending_is_ready(tmp_path):
@@ -385,4 +407,3 @@ def test_cold_start_target_follows_boot_multiplex_policy(tmp_path, monkeypatch,
runtime.ensure_gateway_runtime(home, timeout=0.3)
assert spawned == [{"root": root, "home": home}[owner].resolve()]
-
diff --git a/ui-tui/src/__tests__/canonicalGateway.test.ts b/ui-tui/src/__tests__/canonicalGateway.test.ts
index d5d5e70947e..b2fcf7c19db 100644
--- a/ui-tui/src/__tests__/canonicalGateway.test.ts
+++ b/ui-tui/src/__tests__/canonicalGateway.test.ts
@@ -2,6 +2,15 @@ import { expect, it } from 'vitest'
import { canonicalRequest, canonicalResult, localCreationOptions, sharedControlParams } from '../canonicalGateway.js'
+it.each(['HERMES_SAFE_MODE', 'HERMES_IGNORE_USER_CONFIG'])('carries %s on the launching session policy', flag => {
+ const field = flag === 'HERMES_SAFE_MODE' ? 'safe_mode' : 'ignore_user_config'
+ const options = localCreationOptions({ [flag]: '1' } as NodeJS.ProcessEnv)
+ expect(options[field]).toBe(true)
+ expect(localCreationOptions({ [flag]: '0' } as NodeJS.ProcessEnv)).not.toHaveProperty(field)
+ const contract = { sources: ['tui'], parameters: ['source', 'request_id', field] }
+ expect(canonicalRequest('session.create', { ...options, request_id: 'owned' }, contract).params[field]).toBe(true)
+})
+
it('retains prepared identity and rejects unsupported TUI launch policy instead of impersonating CLI', () => {
const contract = { sources: ['tui'], parameters: ['request_id', 'source', 'model', 'cwd', 'toolsets'] }
expect(canonicalRequest('session.create', { request_id: 'fresh', model: 'local-model', cwd: '/tmp/project' }, contract)).toEqual({ method: 'session.create', params: { request_id: 'fresh', source: 'tui', model: 'local-model', cwd: '/tmp/project' } })
diff --git a/ui-tui/src/canonicalGateway.ts b/ui-tui/src/canonicalGateway.ts
index 287e365cd4a..75e703fdfb9 100644
--- a/ui-tui/src/canonicalGateway.ts
+++ b/ui-tui/src/canonicalGateway.ts
@@ -99,9 +99,12 @@ export function localCreationOptions(env = process.env): Record<string, unknown>
// session prompts anyway / still loads rules, SOUL, memory and skills.auto_load.
const truthy = (value?: string) => ['1', 'true', 'yes', 'on'].includes((value ?? '').trim().toLowerCase())
- if (truthy(env.HERMES_YOLO_MODE)) { options.yolo = true }
-
- if (truthy(env.HERMES_IGNORE_RULES)) { options.ignore_rules = true }
+ for (const [field, value] of [
+ ['yolo', env.HERMES_YOLO_MODE], ['ignore_rules', env.HERMES_IGNORE_RULES],
+ ['safe_mode', env.HERMES_SAFE_MODE], ['ignore_user_config', env.HERMES_IGNORE_USER_CONFIG]
+ ] as const) {
+ if (truthy(value)) { options[field] = true }
+ }
return options
}