Skip to content

The agent that grows with you

refactor(gateway): skip the workspace probe outside focus and drop redundant posture plumbing

kshitijk4poor1d39fab8b9c9
diff --git a/agent/coding_context.py b/agent/coding_context.py
index 4b344f2e10d..bdc62b52b53 100644
--- a/agent/coding_context.py
+++ b/agent/coding_context.py
@@ -399,6 +399,8 @@ def is_coding_context(*, platform: Optional[str] = None, cwd: Optional[str | Pat
def coding_selection(*, platform: Optional[str] = None, cwd: Optional[str | Path] = None, config: Optional[dict[str, Any]] = None) -> Optional[list[str]]:
"""Toolset selection for the coding posture (``None`` unless ``focus`` and active)."""
+ if _coding_mode(config) != "focus": # only focus swaps toolsets: skip the workspace probe
+ return None
return resolve_runtime_mode(platform=platform, cwd=cwd, config=config).toolset_selection(config)
diff --git a/cli.py b/cli.py
index 0de1eafdbd9..e0f9be91bb5 100644
--- a/cli.py
+++ b/cli.py
@@ -1499,7 +1499,6 @@ class HermesCLI(CLIInitMixin, CLITuiRuntimeMixin, CLIProcessNotificationsMixin,
def _build_cli_from_args(model, toolsets, provider, reasoning, api_key, base_url, max_turns, run_budget, verbose, compact, resume, checkpoints, pass_session_id, ignore_rules, skills):
"""Resolve the toolset list (explicit / coding posture / platform default), construct HermesCLI, and start the background skills preload."""
toolsets_list = None
- profile_default = False
if isinstance(toolsets, str) and toolsets:
toolsets_list = [t.strip() for t in toolsets.split(",")]
elif isinstance(toolsets, (list, tuple)) and toolsets:
@@ -1510,7 +1509,6 @@ def _build_cli_from_args(model, toolsets, provider, reasoning, api_key, base_url
elif not toolsets:
# Coding posture inside a code workspace, else the shared platform resolver. Neither is a
# pick: the gateway resolves both from the session's cwd, so this list only feeds the display.
- profile_default = True
try:
from agent.coding_context import coding_selection
toolsets_list = coding_selection(platform="cli", config=CLI_CONFIG)
@@ -1546,7 +1544,7 @@ def _build_cli_from_args(model, toolsets, provider, reasoning, api_key, base_url
if emit_partial_update_hint(e):
sys.exit(1)
raise
- if profile_default:
+ if not toolsets:
cli._explicit_toolsets = False # the gateway resolves the default and coding posture itself
# Only a typed -t is checked against a resumed session's frozen toolsets.
cli._typed_toolsets = toolsets_list if toolsets else None
diff --git a/gateway/session_policy.py b/gateway/session_policy.py
index eee7ac9e8a7..8bfa6ddf6b8 100644
--- a/gateway/session_policy.py
+++ b/gateway/session_policy.py
@@ -137,12 +137,9 @@ class LocalSessionPolicy:
return self.toolsets
# The workspace decision is the creation-time one: a project file the agent writes mid-session must
# not switch this conversation's toolsets (prompt cache). Only a profile change (``focus`` off) does.
- posture = None
- if self.coding_posture:
- from agent.coding_context import focus_toolsets
- posture = focus_toolsets(config)
- return tuple(sorted(_resolve_toolsets({}, config, self.source, self.safe_mode,
- None if posture is None else set(posture))))
+ from agent.coding_context import focus_toolsets
+ posture = focus_toolsets(config) if self.coding_posture else None
+ return tuple(sorted(_resolve_toolsets({}, config, self.source, self.safe_mode, posture)))
def current_reasoning_config(self, runner, session_key=None):
"""The next turn's reasoning: a typed session /reasoning (the messaging handler's override), else
@@ -296,7 +293,8 @@ def build_policy(params, config, *, private_secrets=None, profile_terminal=True,
config.setdefault('model', {})['selection_profile'] = list(profile_target(config))
_apply_launch_overrides(params, config)
# Only a folder the client named is a workspace: the daemon's own directory (the fallback above, used by
- # hosted rooms) must not switch a session into the coding posture, nor may a caller that opts out.
+ # hosted rooms) must not switch a session into the coding posture, nor may a caller that opts out
+ # (Kanban workers, legacy-row adoption).
# ``tool`` is a third-party integration, not a person's workspace.
named = workspace_posture and source != 'tool' and 'cwd' in params and 'toolsets' not in params
posture = _coding_posture(config, source, cwd) if named else None
@@ -400,8 +398,8 @@ def _apply_launch_overrides(params, config):
def _resolve_toolsets(params, config, source, safe_mode, posture=None):
"""Validate explicit toolsets and return the session's enabled toolset set. Without a pick, the
- coding *posture* (``_coding_posture``) replaces the profile default on every interactive surface;
- the gateway decides it, never the client."""
+ coding *posture* (``_coding_posture``) replaces the profile default; the gateway decides it, never
+ the client."""
from hermes_cli.tools_config import _get_platform_tools
from toolsets import validate_toolset
explicit = params.get('toolsets')
@@ -418,7 +416,7 @@ def _resolve_toolsets(params, config, source, safe_mode, posture=None):
if not requested <= effective:
raise RuntimeStoreError('invalid_params')
elif posture is not None:
- enabled = posture
+ enabled = set(posture)
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
@@ -445,7 +443,7 @@ def _coding_posture(config, source, cwd):
except Exception:
logger.debug('coding posture detection failed for %s; keeping the profile default', cwd, exc_info=True)
return None
- return None if selection is None else set(selection)
+ return selection
def _extract_config_secrets(value, private, path=()):