From 55cda8585091a33d9cd7203cc56da3c195396cb5 Mon Sep 17 00:00:00 2001 From: "lusendong.6789" Date: Mon, 2 Nov 2026 19:13:05 +0800 Subject: [PATCH] refactor(chat): move server entry helpers Signed-off-by: lusendong.6789 Co-authored-by: TRAE CLI --- loopx/{chat_session_open.py => chat/session_open.py} | 2 +- loopx/{chat_ssh_source_api.py => chat/ssh_source_api.py} | 6 +++--- loopx/chat_server.py | 4 ++-- tests/architecture/top_level_module_budget.json | 2 +- tests/test_chat_internal_module_layout.py | 6 ++++++ tests/test_native_steward_turn_host.py | 2 +- tests/test_ssh_tunnel_source.py | 8 ++++---- 7 files changed, 18 insertions(+), 12 deletions(-) rename loopx/{chat_session_open.py => chat/session_open.py} (98%) rename loopx/{chat_ssh_source_api.py => chat/ssh_source_api.py} (94%) diff --git a/loopx/chat_session_open.py b/loopx/chat/session_open.py similarity index 98% rename from loopx/chat_session_open.py rename to loopx/chat/session_open.py index 21ebd12d63..e140d3fb4d 100644 --- a/loopx/chat_session_open.py +++ b/loopx/chat/session_open.py @@ -22,7 +22,7 @@ from pathlib import Path from typing import Any -from .chat_manager import open_manager_session +from ..chat_manager import open_manager_session # The executor a Goal-scoped session runs on when the caller makes no explicit # pick. The steward channel does not use this: it resolves its own default. diff --git a/loopx/chat_ssh_source_api.py b/loopx/chat/ssh_source_api.py similarity index 94% rename from loopx/chat_ssh_source_api.py rename to loopx/chat/ssh_source_api.py index 821fa13a7c..5c74b02300 100644 --- a/loopx/chat_ssh_source_api.py +++ b/loopx/chat/ssh_source_api.py @@ -5,11 +5,11 @@ from collections.abc import Callable from typing import Any -from .control_plane.goals.ssh_lifecycle_transport import ( +from ..control_plane.goals.ssh_lifecycle_transport import ( apply_ssh_goal_lifecycle, ) -from .control_plane.status.ssh_tunnel import ensure_ssh_source -from .status_server import is_loopback_host +from ..control_plane.status.ssh_tunnel import ensure_ssh_source +from ..status_server import is_loopback_host SSH_SOURCE_ENSURE_PATH = "/api/ssh-source/ensure" diff --git a/loopx/chat_server.py b/loopx/chat_server.py index bc9fa940c8..97ef446c53 100644 --- a/loopx/chat_server.py +++ b/loopx/chat_server.py @@ -53,8 +53,8 @@ MANAGER_AGENT_GOAL_ID, MANAGER_AGENT_OBJECTIVE, is_manager_channel, manager_capabilities_projection, manager_workspace, ) -from .chat_session_open import open_chat_session -from .chat_ssh_source_api import SshSourceRequestMixin +from .chat.session_open import open_chat_session +from .chat.ssh_source_api import SshSourceRequestMixin from .chat_store import ChatSessionStore, TERMINAL_TURN_STATES from .capabilities.native_chat.model_settings import normalize_agent_reasoning_effort, normalize_agent_model_id from .extensions.lark.private_conversation_api import PrivateConversationRequestMixin, PRIVATE_CONVERSATIONS_PATH diff --git a/tests/architecture/top_level_module_budget.json b/tests/architecture/top_level_module_budget.json index 2f596b7889..c5ee836e21 100644 --- a/tests/architecture/top_level_module_budget.json +++ b/tests/architecture/top_level_module_budget.json @@ -1,6 +1,6 @@ { "schema": "loopx_top_level_module_budget_v0", "baseline_commit": "a4483aaece5bc74ec3f969fd067229487022401b", - "max_top_level_modules": 136, + "max_top_level_modules": 134, "allowlist": ["__init__.py", "entrypoint.py", "cli.py"] } diff --git a/tests/test_chat_internal_module_layout.py b/tests/test_chat_internal_module_layout.py index 6a4132ba82..ef0478b0a9 100644 --- a/tests/test_chat_internal_module_layout.py +++ b/tests/test_chat_internal_module_layout.py @@ -11,6 +11,8 @@ from loopx.chat.goal_configuration_api import GoalConfigurationRequestMixin from loopx.chat.machine_configuration_api import MachineConfigurationRequestMixin from loopx.chat.monitor_actions import ChatMonitorActionMixin +from loopx.chat.session_open import open_chat_session +from loopx.chat.ssh_source_api import SshSourceRequestMixin from loopx.chat.todo_actions import ChatTodoActionMixin from loopx.chat.todo_detail import TodoDetailRequestMixin from loopx.chat.usage_statistics_api import UsageStatisticsRequestMixin @@ -31,6 +33,8 @@ def test_chat_internal_helpers_load_below_the_public_chat_namespace() -> None: == "loopx.chat.machine_configuration_api" ) assert ChatMonitorActionMixin.__module__ == "loopx.chat.monitor_actions" + assert open_chat_session.__module__ == "loopx.chat.session_open" + assert SshSourceRequestMixin.__module__ == "loopx.chat.ssh_source_api" assert ChatTodoActionMixin.__module__ == "loopx.chat.todo_actions" assert TodoDetailRequestMixin.__module__ == "loopx.chat.todo_detail" assert UsageStatisticsRequestMixin.__module__ == "loopx.chat.usage_statistics_api" @@ -44,6 +48,8 @@ def test_chat_internal_helpers_have_no_top_level_compatibility_shims() -> None: "loopx.chat_goal_configuration_api", "loopx.chat_machine_configuration_api", "loopx.chat_monitor_actions", + "loopx.chat_session_open", + "loopx.chat_ssh_source_api", "loopx.chat_todo_actions", "loopx.chat_todo_detail", "loopx.chat_usage_statistics_api", diff --git a/tests/test_native_steward_turn_host.py b/tests/test_native_steward_turn_host.py index 458036e1b7..c69b3c8f54 100644 --- a/tests/test_native_steward_turn_host.py +++ b/tests/test_native_steward_turn_host.py @@ -59,7 +59,7 @@ def managed_fixture(steward, tmp_path, monkeypatch, provider="file", *, validato def test_registered_agents_have_distinct_durable_sessions_without_adopting_legacy_history(steward, tmp_path, monkeypatch, provider): service, first, actor, _, _, capture = managed_fixture(steward, tmp_path, monkeypatch, provider) store, runtime, *_ = steward - from loopx.chat_session_open import open_chat_session + from loopx.chat.session_open import open_chat_session from loopx.agent_registry import load_goal_from_registry cli(runtime, "configure-goal", "--goal-id", actor["goal_id"], "--registered-agent", actor["agent_id"], "--registered-agent", "peer", "--execute") diff --git a/tests/test_ssh_tunnel_source.py b/tests/test_ssh_tunnel_source.py index f12307fc00..b2b764633e 100644 --- a/tests/test_ssh_tunnel_source.py +++ b/tests/test_ssh_tunnel_source.py @@ -11,7 +11,7 @@ import pytest -from loopx.chat_ssh_source_api import SshSourceRequestMixin +from loopx.chat.ssh_source_api import SshSourceRequestMixin from loopx.control_plane.goals.ssh_lifecycle_transport import ( apply_ssh_goal_lifecycle, ) @@ -135,7 +135,7 @@ def test_ssh_source_request_mixin_delegates_validated_loopback_request() -> None receipt = {"ok": True, "status_url": "http://127.0.0.1:8877/status.json"} with mock.patch( - "loopx.chat_ssh_source_api.ensure_ssh_source", return_value=receipt + "loopx.chat.ssh_source_api.ensure_ssh_source", return_value=receipt ) as ensure: handler._ssh_source_ensure() @@ -149,7 +149,7 @@ def test_ssh_source_request_mixin_delegates_validated_loopback_request() -> None def test_ssh_source_request_mixin_rejects_non_loopback_server() -> None: handler = _SshSourceHandler(host="0.0.0.0") - with mock.patch("loopx.chat_ssh_source_api.ensure_ssh_source") as ensure: + with mock.patch("loopx.chat.ssh_source_api.ensure_ssh_source") as ensure: handler._ssh_source_ensure() ensure.assert_not_called() @@ -337,7 +337,7 @@ def test_ssh_goal_lifecycle_handler_returns_verified_remote_receipt() -> None: "projection_verified": True, } with mock.patch( - "loopx.chat_ssh_source_api.apply_ssh_goal_lifecycle", + "loopx.chat.ssh_source_api.apply_ssh_goal_lifecycle", return_value=receipt, ) as apply: handler._ssh_goal_lifecycle()