The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
Merge remote-tracking branch 'origin/main' into fix/106742-thread-resolution
teknium1bb193b204700
diff --cc plugins/platforms/a2a/adapter.pyindex 1f57cbcd6a4,bdb1b5fb8a5..fd474f35204--- a/plugins/platforms/a2a/adapter.py+++ b/plugins/platforms/a2a/adapter.py@@@ -486,9 -539,13 +511,13 @@@ class A2AAdapter(BasePlatformAdapter)protocol.metrics.inbound_total += 1self._register_inline_push(task_id, params, agent=agent)if not agent.get("local", True):- reply, state = self._forward_to_profile(agent, peer, context_id, framed, input_id=task_id)- self._record_outcome(task_id, context_id, peer, state, reply)- return protocol.build_task(task_id, context_id, state, reply, created_at=rec["created_iso"]), None+ self._activate_task(task_id)+ try:- reply, state = self._forward_to_profile(agent, peer, context_id, framed)++ reply, state = self._forward_to_profile(agent, peer, context_id, framed, input_id=task_id)+ self._record_outcome(task_id, context_id, peer, state, reply)+ return protocol.build_task(task_id, context_id, state, reply, created_at=rec["created_iso"]), None+ finally:+ self._pop_pending(task_id)if self._loop is None or self._message_handler is None:return self._end_task(rec, protocol.STATE_FAILED, "Agent gateway not ready to accept A2A tasks.")fut = self._add_pending(task_id, context_id)diff --cc tests/hermes_cli/test_kanban_worker_spawn_toolsets.pyindex 8042c8e9734,a3c1dce230a..b1f221b3631--- a/tests/hermes_cli/test_kanban_worker_spawn_toolsets.py+++ b/tests/hermes_cli/test_kanban_worker_spawn_toolsets.py@@@ -110,6 -124,96 +110,88 @@@ def test_default_spawn_does_not_pass_mutask.model_override = "gpt-5.6-sol"kbd._default_spawn(task, str(workspace))- parser, _subparsers, _chat_parser = build_top_level_parser()- # Profile selection is attached by the outer CLI bootstrap rather than- # build_top_level_parser(); remove that already-validated prefix and parse- # the worker flags/subcommand through the real shared parser.- assert captured["cmd"][1:3] == ["-p", "elias"]- args = parser.parse_args(captured["cmd"][3:])-- assert args.command == "chat"- assert args.model == "gpt-5.6-sol"- assert args.query == "work kanban task t_spawn_tools"-+ # Mutable model strings are not launch authority; the owner reads the claimed card.+ assert captured["cmd"][-2:] == ["-m", "hermes_cli.kanban_worker_client"]+ assert task.model_override not in captured["cmd"]++ def test_default_spawn_resolves_env_passthrough_under_multiplex(monkeypatch, tmp_path):+ """Under multiplex a worker spawn with ``terminal.env_passthrough`` configured must+ forward the ASSIGNEE profile's own value, never crash on an unscoped read or leak the+ dispatcher's ambient os.environ (#109494).+ """+ root = tmp_path / ".hermes"+ profile = root / "profiles" / "elias"+ profile.mkdir(parents=True)+ root.joinpath("config.yaml").write_text(+ "terminal:\n env_passthrough:\n - MY_PASSTHROUGH_VAR\n", encoding="utf-8")+ profile.joinpath("config.yaml").write_text("{}\n", encoding="utf-8")+ profile.joinpath(".env").write_text("MY_PASSTHROUGH_VAR=elias-value\n", encoding="utf-8")+ monkeypatch.setenv("HERMES_HOME", str(root))+ monkeypatch.setenv("MY_PASSTHROUGH_VAR", "dispatcher-value")++ from agent.secret_scope import set_multiplex_active+ from hermes_cli import kanban_db as kb+ from hermes_cli import kanban_db_dispatch as kbd++ monkeypatch.setattr(kbd, "_resolve_hermes_argv", lambda: ["hermes"])++ captured = {}++ class FakeProc:+ pid = 4243++ def fake_popen(cmd, *args, **kwargs):+ captured["env"] = dict(kwargs.get("env") or {})+ return FakeProc()++ monkeypatch.setattr(subprocess, "Popen", fake_popen)++ workspace = tmp_path / "workspace"+ workspace.mkdir()++ set_multiplex_active(True)+ try:+ pid = kbd._default_spawn(_make_task(kb, assignee="elias"), str(workspace))+ finally:+ set_multiplex_active(False)++ assert pid == 4243+ # The assignee's own scoped value, not the dispatcher's ambient os.environ one.+ assert captured["env"].get("MY_PASSTHROUGH_VAR") == "elias-value"+++ def test_resolve_worker_cli_toolsets_uses_profile_home_not_parent_config(monkeypatch, tmp_path):+ root = tmp_path / ".hermes"+ profile = root / "profiles" / "elias"+ profile.mkdir(parents=True)+ root.joinpath("config.yaml").write_text("platform_toolsets:\n cli:\n - kanban\n", encoding="utf-8")+ profile.joinpath("config.yaml").write_text(+ """+ platform_toolsets:+ cli:+ - terminal+ - web+ toolsets:+ - hermes-cli+ """.lstrip(),+ encoding="utf-8",+ )+ monkeypatch.setenv("HERMES_HOME", str(root))++ from hermes_cli import kanban_db as kb+ from hermes_cli import kanban_db_dispatch as kbd++ resolved = kbd._resolve_worker_cli_toolsets(str(profile))++ assert resolved is not None+ assert "terminal" in resolved+ assert "web" in resolved+ # Opt-in is no longer inferred for ordinary chats. The dispatcher-owned+ # worker gets lifecycle tools at schema assembly, independently of the+ # assignee's saved chat selection.+ monkeypatch.setenv("HERMES_KANBAN_TASK", "t_spawn_tools")+ from model_tools import get_tool_definitions+ names = {t["function"]["name"] for t in get_tool_definitions(resolved, quiet_mode=True, skip_tool_search_assembly=True)}+ assert "kanban_complete" in names+ assert "kanban_list" not in names+ assert resolved != ["kanban"]diff --cc tests/tui_gateway/test_tui_gateway_server.pyindex 60fcdfa780d,b744e3ca6b7..fed974359cf--- a/tests/tui_gateway/test_tui_gateway_server.py+++ b/tests/tui_gateway/test_tui_gateway_server.py@@@ -7243,10 -7233,9 +7243,10 @@@ def test_notification_poller_live_loop_monkeypatch.setattr(server, "_get_db", lambda: None)monkeypatch.setattr(server, "_emit", lambda *args, **_kwargs: emitted.append(args))- def _deliver(_rid, sid, session, text):+ def _deliver(_rid, sid, session, text, **_kw):delivered["a" if sid == "sid-a-live-handoff" else "b"].append(text)session["running"] = False+ return True # the execution gate accepted the turn; None would re-queue for redeliverymonkeypatch.setattr(server, "_run_prompt_submit", _deliver)server._sessions.update(diff --cc tools/terminal_scope.pyindex 2b187784e32,56988ad2a65..abb39d79c39--- a/tools/terminal_scope.py+++ b/tools/terminal_scope.py@@@ -86,40 -86,41 +86,49 @@@ def terminal_env(name: str, default: streturn default if value is None else str(value)+def _apply_terminal_mapping(scope: Dict[str, str], mapping: Dict[str, Any]) -> None:+ from hermes_cli.config import TERMINAL_CONFIG_ENV_MAP, _terminal_env_value++ for cfg_key, value in mapping.items():+ # cwd placeholders are resolved per-surface later; not a policy value.+ if value is None or (cfg_key == "cwd" and str(value).strip() in {".", "auto", "cwd"}):+ continue+ env_var = TERMINAL_CONFIG_ENV_MAP.get(cfg_key)+ if env_var:+ # List/dict config values must be JSON (same contract as+ # apply_terminal_config_to_env). str() yields Python repr, which+ # json.loads in terminal_tool rejects.+ scope[env_var] = _terminal_env_value(value)+++def default_terminal_scope() -> Dict[str, str]:+ """Code-default ``TERMINAL_*`` policy: what a profile-bypassing session freezes instead of+ reading ``.env``/``config.yaml``. Total like the profile projection, minus the profile."""+ from hermes_cli.config_defaults import DEFAULT_CONFIG++ scope: Dict[str, str] = {}+ _apply_terminal_mapping(scope, {**_TOOL_LEVEL_DEFAULTS, **(DEFAULT_CONFIG.get("terminal") or {})})+ return scope++- def build_profile_terminal_scope(hermes_home: "Any") -> Dict[str, str]:+ def build_profile_terminal_scope(+ hermes_home: "Any", *, env_overlay: Optional[Dict[str, str]] = None) -> Dict[str, str]:"""Build the COMPLETE effective ``TERMINAL_*`` policy for a profile home.- Projection: ``DEFAULT_CONFIG['terminal']`` <- profile ``.env`` TERMINAL_* <- profile- ``config.yaml`` ``terminal:``. Total by construction, so a bound scope never widens back to- ambient authority. Raises :class:`TerminalPolicyUnavailable` if a present file is unreadable.+ Projection: ``DEFAULT_CONFIG['terminal']`` <- profile ``.env`` TERMINAL_* <- *env_overlay*+ <- profile ``config.yaml`` ``terminal:``. Total by construction, so a bound scope never+ widens back to ambient authority. Raises :class:`TerminalPolicyUnavailable` if a present+ file is unreadable.++ *env_overlay* is a TRUSTED ``TERMINAL_*`` mapping captured from the launch process before+ multiplexing began (``tui_gateway/launch_terminal_policy.py``): the launch profile's+ env-only policy (``TERMINAL_ENV=ssh`` from systemd, ``op run``, a launcher bridge) has no+ file to rebuild it from, and reading live ``os.environ`` here is the leak this module+ closes. It sits where the process env sits in the standalone bridge — explicit YAML keys+ still win (``apply_terminal_config_to_env``)."""- from hermes_cli.config import TERMINAL_CONFIG_ENV_MAP, _terminal_env_value- from hermes_cli.config_defaults import DEFAULT_CONFIG-home = Path(hermes_home)- scope: Dict[str, str] = {}-- def _apply(mapping: Dict[str, Any]) -> None:- for cfg_key, value in mapping.items():- # cwd placeholders are resolved per-surface later; not a policy value.- if value is None or (cfg_key == "cwd" and str(value).strip() in {".", "auto", "cwd"}):- continue- env_var = TERMINAL_CONFIG_ENV_MAP.get(cfg_key)- if env_var:- # List/dict config values must be JSON (same contract as- # apply_terminal_config_to_env). str() yields Python repr, which- # json.loads in terminal_tool rejects.- scope[env_var] = _terminal_env_value(value)-- _apply({**_TOOL_LEVEL_DEFAULTS, **(DEFAULT_CONFIG.get("terminal") or {})})+ scope = default_terminal_scope()env_path = home / ".env"if env_path.exists():# load_env_file swallows OSError by design (secret scope fails soft); an unreadablediff --cc tui_gateway/session_notifications.pyindex 09689685b95,1e80a97696e..6b6c1b23d5e--- a/tui_gateway/session_notifications.py+++ b/tui_gateway/session_notifications.py@@@ -483,12 -469,9 +485,13 @@@ def _notif_dispatch_completions(sid, se_notif_release_turn(session)try:if text is not None:- _notif_submit(f"__notif__{int(time.time() * 1000)}", sid, session, text,- "completion batch dispatch failed", display_kind=PROCESS_COMPLETE_DISPLAY_KIND,- display_metadata={"display_text": batch.display_text(registry)})+ if not _notif_submit(f"__notif__{int(time.time() * 1000)}", sid, session, text,- "completion batch dispatch failed"):++ "completion batch dispatch failed", display_kind=PROCESS_COMPLETE_DISPLAY_KIND,++ display_metadata={"display_text": batch.display_text(registry)}):+ for event, _text, claim in claimed:+ _notif_defer_event(event, claim,+ deferred.append if deferred is not None else registry.completion_queue.put)+ returnexcept Exception:for event, _text, claim in claimed:release_event_delivery(event, claim)