The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: -z keeps the oneshot auto-approve over the daemon; operator-mode homes reach the control socket
teknium1a858451b5f61
diff --git a/gateway/control_socket.py b/gateway/control_socket.pyindex e33f0772462..21e3bfdea0e 100644--- a/gateway/control_socket.py+++ b/gateway/control_socket.py@@ -279,10 +279,11 @@ class GatewayControlServer:if os.name == "nt":return Nonetry:+ from hermes_cli.gateway_runtime_discovery import HOME_UNSAFE_BITShome = self._homeinfo = home.lstat()if (home.absolute() != home.resolve() or not stat.S_ISDIR(info.st_mode)- or info.st_uid != os.getuid() or info.st_mode & 0o077): # windows-footgun: ok — POSIX-only helper+ or info.st_uid != os.getuid() or info.st_mode & HOME_UNSAFE_BITS): # windows-footgun: ok — POSIX-only helperreturn Nonesock = writer.get_extra_info("socket")if hasattr(socket, "SO_PEERCRED"):diff --git a/gateway/session_authority.py b/gateway/session_authority.pyindex 08844d08d1b..274b8df78f7 100644--- a/gateway/session_authority.py+++ b/gateway/session_authority.py@@ -286,7 +286,7 @@ class SessionAuthority:self.authorize(actor, request.ref, 'session:submit')self._require_admission_open()if (request.intent != 'queue' or not {'text'} <= set(request.payload) <= {- 'text', 'attachments', 'finite', 'surface', 'voice_context', 'interrupted'}+ 'text', 'attachments', 'finite', 'unattended', 'surface', 'voice_context', 'interrupted'}or not isinstance(request.payload['text'], str)):raise RuntimeStoreError('invalid_params')from gateway.session_ingress_media import admit_attachmentsdiff --git a/gateway/session_controls.py b/gateway/session_controls.pyindex 8d7c06a4a09..12216f466fd 100644--- a/gateway/session_controls.py+++ b/gateway/session_controls.py@@ -366,7 +366,7 @@ class AuthorityConnection:async def submit(self, ref, params):if ref.session_id not in self.subscriptions:raise RuntimeStoreError('permission_denied')- forbidden = set(params) - {'session_id', 'text', 'submission_id', 'input_id', 'queued', 'attachments', 'finite',+ forbidden = set(params) - {'session_id', 'text', 'submission_id', 'input_id', 'queued', 'attachments', 'finite', 'unattended','surface', 'voice_context', 'interrupted'}if forbidden:raise RuntimeStoreError('invalid_params')diff --git a/gateway/session_finite.py b/gateway/session_finite.pyindex 4ae16340bef..280bb8b8d3c 100644--- a/gateway/session_finite.py+++ b/gateway/session_finite.py@@ -5,6 +5,7 @@ from contextvars import ContextVarfrom hermes_state_runtime import RuntimeStoreError_finite_turn = ContextVar('finite_turn', default=None)+_unattended_turn = ContextVar('unattended_turn', default=False)def finite_turn_required():@@ -13,26 +14,37 @@ def finite_turn_required():return _finite_turn.get()+def unattended_turn():+ # `hermes -z`: nobody can answer a prompt, so the classic one-shot contract auto-approves+ # (legacy oneshot.py set HERMES_YOLO_MODE). `-q` stays single-query (approvals.single_query_mode).+ return _unattended_turn.get()++@contextmanager-def finite_turn_scope(finite):+def finite_turn_scope(finite, unattended=False):token = _finite_turn.set(finite)+ unattended_token = _unattended_turn.set(bool(finite and unattended))try:yieldfinally:+ _unattended_turn.reset(unattended_token)_finite_turn.reset(token)def admit_finite(params):+ if 'unattended' in params and (type(params['unattended']) is not bool+ or (params['unattended'] and params.get('finite') is not True)):+ raise RuntimeStoreError('invalid_params')if 'finite' not in params:return {}if type(params['finite']) is not bool:raise RuntimeStoreError('invalid_params')- return {'finite': params['finite']}+ return {'finite': params['finite'], **({'unattended': True} if params.get('unattended') else {})}async def execute_finite_admission(authority, ref, row):from gateway.session_ingress import execute_admissionfrom gateway.session_surface import surface_turn_scope- with finite_turn_scope(row['payload'].get('finite', False)), \+ with finite_turn_scope(row['payload'].get('finite', False), row['payload'].get('unattended') is True), \surface_turn_scope(row['payload'].get('surface_v1')):return await execute_admission(authority, ref, row)diff --git a/gateway/session_operator.py b/gateway/session_operator.pyindex da5c43d43a1..890773008c7 100644--- a/gateway/session_operator.py+++ b/gateway/session_operator.py@@ -10,7 +10,7 @@ from hermes_state_runtime import RuntimeStoreErrordef check_local_input(authority, ref, row):payload = row['payload']- allowed = {'text', 'attachments_v1', 'finite', 'surface_v1'}+ allowed = {'text', 'attachments_v1', 'finite', 'unattended', 'surface_v1'}if 'local_operator_v1' in payload:allowed.add('local_operator_v1')if payload['local_operator_v1'] != {diff --git a/hermes_cli/gateway_chat.py b/hermes_cli/gateway_chat.pyindex d69c09da0b6..b4de2b5c688 100644--- a/hermes_cli/gateway_chat.py+++ b/hermes_cli/gateway_chat.py@@ -133,6 +133,7 @@ async def run_gateway_chat(args, emitter=None):(query and not (sys.stdin.isatty() and sys.stdout.isatty())))view = GatewayChatView(client, snapshot, quiet=quiet, emitter=emitter,usage_file=getattr(args, "usage_file", None))+ view.unattended = isinstance(oneshot_prompt, str)if (getattr(args, "resume", None) or title) and not quiet:for row in snapshot.get("messages", []):if row.get("role") in {"user", "assistant"} and isinstance(row.get("content"), str):diff --git a/hermes_cli/gateway_chat_view.py b/hermes_cli/gateway_chat_view.pyindex 16d85a11d61..8c87838084e 100644--- a/hermes_cli/gateway_chat_view.py+++ b/hermes_cli/gateway_chat_view.py@@ -20,6 +20,7 @@ class GatewayChatView:self.emitter = emitterself.quiet = quiet or emitter is not Noneself.finite = False+ self.unattended = False # `-z`: the classic one-shot auto-approves; `-q` stays single-queryself.streams = {}self.completions = {}self.changed = asyncio.Event()@@ -134,7 +135,8 @@ class GatewayChatView:async def submit(self, text):return await self.client.rpc("prompt.submit", session_id=self.session_id,input_id=uuid.uuid4().hex, text=text,- **({"finite": True} if self.finite else {}))+ **({"finite": True} if self.finite else {}),+ **({"unattended": True} if self.finite and self.unattended else {}))async def command(self, text):command, _, rest = text.partition(" ")diff --git a/hermes_cli/gateway_runtime_discovery.py b/hermes_cli/gateway_runtime_discovery.pyindex 756822617f3..d2275cba37b 100644--- a/hermes_cli/gateway_runtime_discovery.py+++ b/hermes_cli/gateway_runtime_discovery.py@@ -17,18 +17,24 @@ class DiscoveryError(ValueError):self.reason = reason-def _private_node(path: Path, *, kind: str) -> os.stat_result:+# The profile home keeps the operator's mode (main's home policy: symlinked homes, HERMES_HOME_MODE+# 0701/0750, shared setups). Only group/other WRITE lets another user swap the socket; read/search+# bits grant nothing against our 0600 socket. Everything we create ourselves stays owner-only.+HOME_UNSAFE_BITS = 0o022+++def _private_node(path: Path, *, kind: str, unsafe_bits: int = 0o077) -> os.stat_result:node = path.lstat()predicates = {"socket": stat.S_ISSOCK, "file": stat.S_ISREG, "directory": stat.S_ISDIR}if not predicates[kind](node.st_mode) or node.st_uid != os.getuid(): # windows-footgun: ok — POSIX socket path onlyraise DiscoveryError("unsafe_control_path")- if stat.S_IMODE(node.st_mode) & 0o077:+ if stat.S_IMODE(node.st_mode) & unsafe_bits:raise DiscoveryError("unsafe_control_permissions")return nodedef _socket_path(home: Path) -> Path:- _private_node(home, kind="directory")+ _private_node(home, kind="directory", unsafe_bits=HOME_UNSAFE_BITS)direct = home / "gateway.sock"if os.path.lexists(direct):_private_node(direct, kind="socket")diff --git a/tests/gateway/test_runtime_ownership.py b/tests/gateway/test_runtime_ownership.pyindex ed12a208055..26501939764 100644--- a/tests/gateway/test_runtime_ownership.py+++ b/tests/gateway/test_runtime_ownership.py@@ -78,15 +78,16 @@ async def test_reserved_home_is_eligible_for_same_user_bootstrap(tmp_path):await server.stop()owner.close()- # Pre-existing readable homes are refused, not silently chmodded.- existing = tmp_path / 'existing-readable-home'- existing.mkdir(mode=0o755)- existing.chmod(0o755)+ # Pre-existing group/other-writable homes are refused, not silently chmodded (a readable+ # operator-chosen mode is fine: only write lets another user swap the socket).+ existing = tmp_path / 'existing-writable-home'+ existing.mkdir(mode=0o775)+ existing.chmod(0o775)owner.reserve([existing])try:observed = await asyncio.to_thread(discover_gateway_endpoint, existing)assert (observed.state, observed.reason_code) == ('inaccessible', 'unsafe_control_permissions')- assert existing.stat().st_mode & 0o777 == 0o755+ assert existing.stat().st_mode & 0o777 == 0o775finally:owner.close()diff --git a/tests/tools/test_approval.py b/tests/tools/test_approval.pyindex 2688b701b50..4244542283d 100644--- a/tests/tools/test_approval.py+++ b/tests/tools/test_approval.py@@ -1995,6 +1995,11 @@ class TestApprovalPromptRedaction:allowlist keys off pattern_key, not the command text."""+ @pytest.fixture(autouse=True)+ def _redaction_on(self, monkeypatch):+ # The switch is a launch snapshot; an earlier file in the same process may have imported it off.+ monkeypatch.setattr("agent.redact._REDACT_ENABLED", True)+SECRET_CMD = ('curl -H "Authorization: Bearer sk-proj-abc123xyz4567890abcdef" '"https://api.openai.com/v1/models"diff --git a/tests/tools/test_single_query_approval_mode.py b/tests/tools/test_single_query_approval_mode.pyindex d5a003c636b..88ba227f6b1 100644--- a/tests/tools/test_single_query_approval_mode.py+++ b/tests/tools/test_single_query_approval_mode.py@@ -333,3 +333,29 @@ class TestSingleQueryModeInteractions:with mock_patch("tools.approval_context._get_single_query_approval_mode", return_value="approve"):result = check_all_command_guards("rm -rf /", "local")assert not result["approved"]+++class TestDaemonOneshotTurns:+ """Over the daemon, `-q` and `-z` are both finite, but only `-z` keeps the legacy+ oneshot auto-approve (oneshot.py set HERMES_YOLO_MODE: nobody can answer a prompt)."""++ def test_unattended_finite_turn_approves_execute_code_but_plain_finite_stays_single_query(self, monkeypatch):+ from unittest.mock import patch as mock_patch+ from gateway.session_finite import admit_finite, finite_turn_scope+ from hermes_state_runtime import RuntimeStoreError++ for key in ("HERMES_SINGLE_QUERY_SESSION", "HERMES_GATEWAY_SESSION", "HERMES_EXEC_ASK", "HERMES_YOLO_MODE"):+ monkeypatch.delenv(key, raising=False)+ assert admit_finite({"finite": True, "unattended": True}) == {"finite": True, "unattended": True}+ assert admit_finite({"finite": True, "unattended": False}) == {"finite": True}+ for bad in ({"unattended": True}, {"finite": False, "unattended": True}, {"finite": True, "unattended": 1}):+ with pytest.raises(RuntimeStoreError):+ admit_finite(bad)+ with mock_patch("tools.approval_context._get_single_query_approval_mode", return_value="deny"):+ with finite_turn_scope(True, unattended=True):+ assert approval_module.check_execute_code_guard("import os", "local")["approved"]+ with finite_turn_scope(True):+ assert approval_module.check_execute_code_guard("import os", "local")["outcome"] == "blocked"+ with finite_turn_scope(False, unattended=True):+ assert approval_module.check_execute_code_guard("import os", "local")["approved"] # headless default+ assert not approval_module._yolo_active()diff --git a/tools/approval.py b/tools/approval.pyindex cff8d0d8d77..ec8662593a1 100644--- a/tools/approval.py+++ b/tools/approval.py@@ -322,7 +322,10 @@ def is_current_session_yolo_enabled() -> bool:def _yolo_active() -> bool:"""CLI ``--yolo`` (process-scoped, frozen at import) or gateway ``/yolo``(session-scoped). Hardline / deny-rule floors run BEFORE this everywhere."""- return _YOLO_MODE_FROZEN or is_current_session_yolo_enabled()+ if _YOLO_MODE_FROZEN or is_current_session_yolo_enabled():+ return True+ from gateway.session_finite import unattended_turn+ return unattended_turn()def _permanent_set() -> set: