The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): the gateway applies the coding posture when no toolsets were picked
unsupportedpastelsaee5a705b23e
diff --git a/gateway/session_policy.py b/gateway/session_policy.pyindex e2433c40b92..87549235721 100644--- a/gateway/session_policy.py+++ b/gateway/session_policy.py@@ -1,5 +1,5 @@"""Frozen, explicit local-client launch policy for the existing TurnRunner."""-from contextlib import contextmanager+from contextlib import contextmanager, suppressfrom contextvars import ContextVarfrom dataclasses import dataclassimport json@@ -129,7 +129,7 @@ class LocalSessionPolicy:if (not self.follows_profile or self.source not in SURFACES or self.editor_mcp_json is not Noneor 'toolsets' in json.loads(self.request_json)):return self.toolsets- return tuple(sorted(_resolve_toolsets({}, config, self.source, self.safe_mode)))+ return tuple(sorted(_resolve_toolsets({}, config, self.source, self.safe_mode, self.cwd)))def current_reasoning_config(self, runner, session_key=None):"""The next turn's reasoning: a typed session /reasoning (the messaging handler's override), else@@ -282,7 +282,7 @@ def build_policy(params, config, *, private_secrets=None, profile_terminal=True)# still targets this, and a later profile edit supersedes it.config.setdefault('model', {})['selection_profile'] = list(profile_target(config))_apply_launch_overrides(params, config)- enabled = _resolve_toolsets(params, config, source, safe_mode)+ enabled = _resolve_toolsets(params, config, source, safe_mode, cwd)terminal = build_profile_terminal_scope(get_hermes_home()) if profile_terminal else default_terminal_scope()# The client's launch folder is a path on THIS host: a remote or container backend keeps its own# configured cwd unless the user picked this folder for the session.@@ -379,8 +379,10 @@ def _apply_launch_overrides(params, config):config['agent'].pop('reasoning_overrides', None)-def _resolve_toolsets(params, config, source, safe_mode):- """Validate explicit toolsets and return the session's enabled toolset set."""+def _resolve_toolsets(params, config, source, safe_mode, cwd=None):+ """Validate explicit toolsets and return the session's enabled toolset set. Without a pick, the+ coding posture for *cwd* (``agent.coding_context: focus`` in a code workspace) replaces the+ profile default on every interactive surface; the gateway decides it, never the client."""from hermes_cli.tools_config import _get_platform_toolsfrom toolsets import validate_toolsetexplicit = params.get('toolsets')@@ -396,7 +398,16 @@ def _resolve_toolsets(params, config, source, safe_mode):effective = {t for name in enabled for t in resolve_toolset(name)}if not requested <= effective:raise RuntimeStoreError('invalid_params')- elif source in {'tui', 'gui'}:+ else:+ selection = None+ if cwd is not None:+ # A detection failure keeps the profile default rather than refusing the session.+ with suppress(Exception):+ from agent.coding_context import coding_selection+ selection = coding_selection(platform=SURFACES[source], cwd=cwd, config=config)+ if selection is not None:+ enabled = set(selection)+ if explicit is None and source in {'tui', 'gui'}:# Same surface toolsets as the native TUI factory, without its env inference.# The fold-in lands after _get_platform_tools subtracted agent.disabled_toolsets, so# subtract again or `disabled_toolsets: [project]` is a no-op here (#54433).diff --git a/tests/gateway/test_session_policy_coding_posture.py b/tests/gateway/test_session_policy_coding_posture.pynew file mode 100644index 00000000000..fcf5d359d6a--- /dev/null+++ b/tests/gateway/test_session_policy_coding_posture.py@@ -0,0 +1,47 @@+"""The gateway, not the client, applies the coding posture to a session that did not pick toolsets."""+import pytest++FOCUS = {'agent': {'coding_context': 'focus'}, 'platform_toolsets': {'cli': ['terminal'], 'acp': ['terminal']}}+++def project(tmp_path):+ root = tmp_path / 'project'+ root.mkdir()+ (root / 'pyproject.toml').write_text('[project]\nname = "demo"\n')+ return root++[email protected]('source', ['cli', 'tui', 'gui', 'acp', 'oneshot'])+def test_focus_in_a_code_workspace_selects_the_coding_posture(project, source):+ from gateway.session_policy import build_policy+ policy = build_policy({'source': source, 'cwd': str(project)}, FOCUS)+ assert 'coding' in policy.toolsets and 'terminal' not in policy.toolsets+++def test_surface_toolsets_still_fold_in_over_the_posture(project):+ from gateway.session_policy import build_policy+ assert 'project' in build_policy({'source': 'tui', 'cwd': str(project)}, FOCUS).toolsets+ gui = build_policy({'source': 'gui', 'cwd': str(project)}, FOCUS).toolsets+ assert {'coding', 'desktop_ui', 'catalog'} <= set(gui)+++def test_profile_default_outside_a_workspace_or_without_focus(project, tmp_path):+ from gateway.session_policy import build_policy+ plain = tmp_path / 'notes'+ plain.mkdir()+ assert build_policy({'source': 'cli', 'cwd': str(plain)}, FOCUS).toolsets == ('terminal',)+ auto = {**FOCUS, 'agent': {'coding_context': 'auto'}}+ assert build_policy({'source': 'cli', 'cwd': str(project)}, auto).toolsets == ('terminal',)+++def test_an_explicit_pick_wins_over_the_posture(project):+ from gateway.session_policy import build_policy+ policy = build_policy({'source': 'cli', 'cwd': str(project), 'toolsets': ['terminal']}, FOCUS)+ assert policy.toolsets == ('terminal',)+++def test_a_following_session_keeps_the_posture_for_its_own_cwd(project):+ from gateway.session_policy import build_policy+ policy = build_policy({'source': 'cli', 'cwd': str(project), 'follow_profile_config': True}, FOCUS)+ assert 'coding' in policy.current_toolsets(FOCUS)diff --git a/website/docs/developer-guide/gateway-local-sessions.md b/website/docs/developer-guide/gateway-local-sessions.mdindex 173ed3e5c41..737539d3454 100644--- a/website/docs/developer-guide/gateway-local-sessions.md+++ b/website/docs/developer-guide/gateway-local-sessions.md@@ -72,7 +72,10 @@ OpenAI API-to-local session affinity; those remain separate integration paths.The native local routing identity remains server-owned `Platform.LOCAL`; source nevergrants messaging/native trust. Default TUI selection folds in `project`; GUI folds inthe client-surface toolsets (`project`, `desktop_ui`, `catalog`). GUI policy is- independent of `HERMES_DESKTOP` and of the attaching viewer's identity.+ independent of `HERMES_DESKTOP` and of the attaching viewer's identity. Without explicit+ `toolsets`, the gateway applies the coding posture (`agent.coding_context: focus` in a+ code workspace, `agent/coding_context.py`) from the session's `cwd` on every interactive+ surface; clients never send it as a pick.- Optional flat creation fields: `cwd` (existing absolute gateway-local directory),`model` (nonempty model identifier on the daemon's configured provider), and `toolsets`(explicit array of established toolset names, including an empty array). Unknown or