feat: unify agent isolation (--ignore-rules / --safe-mode) across TUI, messaging gateway, and API server - #88360
Draft
YuYigeng wants to merge 10 commits into
Draft
feat: unify agent isolation (--ignore-rules / --safe-mode) across TUI, messaging gateway, and API server#88360YuYigeng wants to merge 10 commits into
YuYigeng wants to merge 10 commits into
Conversation
Single source of truth for --ignore-rules / --safe-mode (and their HERMES_IGNORE_RULES / HERMES_SAFE_MODE env forms) across every agent session entry point. Explicit flags win over env, safe mode implies ignore-rules, default stays False, and both AIAgent skip flags always move together.
TUI sessions previously read only HERMES_IGNORE_RULES for the skip flags; safe mode (--safe-mode / HERMES_SAFE_MODE=1) now resolves to the same skip_context_files + skip_memory contract via the shared resolver.
The messaging gateway only supported an opt-in per-platform skip_context_files config. Isolation now composes with that config (resolver OR platform opt-out for context files, resolver for memory), and skip_memory joins skip_context_files in the agent cache signature so a cached AIAgent is never reused across an isolation change.
API server agents now resolve HERMES_IGNORE_RULES / HERMES_SAFE_MODE and pass skip_context_files + skip_memory to AIAgent, matching CLI, TUI, and messaging gateway behavior.
State that HERMES_IGNORE_RULES and the agent-level effect of HERMES_SAFE_MODE are honored by CLI, TUI, messaging gateway, and API server sessions.
Background gateway tasks constructed AIAgent without the isolation skip flags, so --ignore-rules / --safe-mode applied to foreground turns but not to /background-style work. Extract _resolve_gateway_isolation_skip_flags (shared by foreground and background paths) so both honor HERMES_IGNORE_RULES / HERMES_SAFE_MODE and compose with the per-platform context-file opt-out.
TUI background turns and preview restarts rebuild AIAgent from scratch; the kwargs helpers now carry the parent session's skip_context_files / skip_memory so an isolated session stays isolated in its background work.
CLI background tasks (/background) now resolve HERMES_IGNORE_RULES / HERMES_SAFE_MODE through the shared isolation resolver, matching the foreground chat agent.
ACP (Agent Client Protocol) sessions now pass skip_context_files and skip_memory from the shared isolation resolver, so a daemon started with --ignore-rules / --safe-mode applies the same contract to IDE/editor sessions.
YuYigeng
force-pushed
the
agent/isolation-contract
branch
from
August 18, 2026 12:29
0b99bbb to
cc4fc38
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
--ignore-rules/HERMES_IGNORE_RULESand--safe-mode/HERMES_SAFE_MODEare honored by CLI chat and-zoneshot sessions, but not consistently by the other agent session entry points. On currentmain:HERMES_IGNORE_RULES;HERMES_SAFE_MODEis ignored for the skip flags, and TUI background turns do not inherit the parent session's isolation.gateway.platforms.<platform>.skip_context_filesconfig; both env vars are ignored on foreground turns and background tasks.AIAgentwithout either skip flag and never reads the env vars.AIAgentwithout the skip flags.Root cause
Isolation intent is resolved per entry point instead of once.
--ignore-rulesand--safe-modeare normalized toHERMES_IGNORE_RULES/HERMES_SAFE_MODEat CLI startup, but the other agent construction sites never resolve them, soAIAgentreceives defaultFalseskip flags and injects rules/memory even when isolation was requested.Scope
Included:
agent/isolation.py: one private resolver, precedence = explicit flag > env (HERMES_IGNORE_RULES,HERMES_SAFE_MODE; safe mode implies ignore-rules) > defaultFalse; returns(skip_context_files, skip_memory).tui_gateway/server.py,_make_agent) and TUI background/preview turns (_background_agent_kwargs).gateway/run.py), including the agent cache signature so a cachedAIAgentis never reused across an isolation change.gateway/platforms/api_server.py).hermes_cli/cli_commands_mixin.py).acp_adapter/session.py).Not included (follow-ups):
-zoneshot / Termux wiring (tracked in #72075, kept independent; can be refactored onto the shared resolver after it merges); cron / batch / curator / delegate worker policies (deliberate internal contracts); newconfig.yamlkeys (public config surface, only if maintainers want it).Design
One resolver as the single source of truth. For the gateway, isolation composes with the existing per-platform latency opt-out:
skip_context_files = isolation OR platform config,skip_memory = isolation. Default behavior is unchanged everywhere.Coverage matrix
HERMES_IGNORE_RULESonlytest_make_agent_forwards_isolation_envtest_background_agent_kwargs_inherits_isolationtest_skip_context_files_change_different_signature,test_skip_memory_change_different_signature,test_resolve_gateway_isolation_skip_flagstest_resolve_gateway_isolation_skip_flagstest_create_agent_honors_isolation_envtest_make_agent_forwards_isolation_env,test_make_agent_defaults_isolation_offCompatibility
Falsewhen no flag/env is set).skip_context_fileskey keeps working and composes with isolation.skip_memorynow participates in the gateway agent cache signature, so an isolation toggle rebuilds the agent instead of silently reusing a stale one.Related / competing work
oneshot(-z) has no way to skip built-in memory injection —--ignore-rulesis silently ignored #72064HERMES_IGNORE_RULES(stale base, not updated since 2026-07). This PR covers that gateway path plus safe mode, background tasks, cache invalidation, TUI, CLI background, API server, and ACP via the shared resolver.Validation
scripts/run_tests.sh tests/agent/test_isolation.py tests/gateway/test_isolation_skip_flags.py tests/gateway/test_agent_cache.py tests/acp/test_session.pyscripts/run_tests.sh tests/test_tui_gateway_server.pyscripts/run_tests.sh tests/gateway/test_api_server.pyruff checkon changed filesgit diff --check