From f58f57c271b14b9d6808255d1b8af9ccdb7f8fb7 Mon Sep 17 00:00:00 2001 From: "lusendong.6789" Date: Mon, 2 Nov 2026 21:34:45 +0800 Subject: [PATCH] refactor(chat): colocate internal server helpers Signed-off-by: lusendong.6789 Co-authored-by: TRAE CLI --- .../completed_todos.py} | 14 +++++++------- .../goal_subagent_api.py} | 10 +++++----- loopx/chat_server.py | 4 ++-- loopx/chat_status_api.py | 2 +- loopx/control_plane/status/goal_source.py | 2 +- tests/architecture/top_level_module_budget.json | 2 +- .../test_codex_subagent_host_capacity.py | 2 +- .../test_subagent_model_configuration.py | 2 +- tests/test_chat_completed_todos.py | 4 ++-- tests/test_managed_research_team.py | 2 +- 10 files changed, 22 insertions(+), 22 deletions(-) rename loopx/{chat_completed_todos.py => chat/completed_todos.py} (95%) rename loopx/{chat_goal_subagent_api.py => chat/goal_subagent_api.py} (97%) diff --git a/loopx/chat_completed_todos.py b/loopx/chat/completed_todos.py similarity index 95% rename from loopx/chat_completed_todos.py rename to loopx/chat/completed_todos.py index 25cf787297..bdba52074e 100644 --- a/loopx/chat_completed_todos.py +++ b/loopx/chat/completed_todos.py @@ -10,14 +10,14 @@ from time import monotonic from urllib.parse import parse_qs, urlparse -from .paths import resolve_runtime_root -from .capabilities.native_chat.project_context import coordination_runtime_root -from .status_server import is_loopback_host +from ..paths import resolve_runtime_root +from ..capabilities.native_chat.project_context import coordination_runtime_root +from ..status_server import is_loopback_host def _goal_result_candidates(*, runtime_root, goal_id): """Snapshot bounded metadata; exact acceptance is checked per requested page.""" - from .control_plane.coordination.local_authority import read_canonical_todos_if_promoted + from ..control_plane.coordination.local_authority import read_canonical_todos_if_promoted payload = read_canonical_todos_if_promoted(runtime_root=runtime_root, goal_id=goal_id) if payload is None: @@ -42,7 +42,7 @@ def _goal_result_candidates(*, runtime_root, goal_id): def _verify_goal_result_page(*, page, registry_path, runtime_root, goal_id): - from .control_plane.todos.completion_result import read_completion_result + from ..control_plane.todos.completion_result import read_completion_result rows = [] unavailable_todo_ids = [] @@ -159,7 +159,7 @@ def _goal_results(self) -> None: self._send_error("Goal results could not be loaded.", status=503) def _goal_result(self, todo_id: str) -> None: - from .control_plane.todos.completion_result import read_completion_result + from ..control_plane.todos.completion_result import read_completion_result goal_id = parse_qs(urlparse(self.path).query).get("goal_id", [""])[0] try: @@ -182,7 +182,7 @@ def _goal_result(self, todo_id: str) -> None: def _completed_todos(self) -> None: # This loopback-only workspace read preserves task text and evidence. # Select display fields without returning the authority's internal metadata. - from .control_plane.todos.list_readback import list_goal_todos + from ..control_plane.todos.list_readback import list_goal_todos if not self._require_loopback_origin(): return diff --git a/loopx/chat_goal_subagent_api.py b/loopx/chat/goal_subagent_api.py similarity index 97% rename from loopx/chat_goal_subagent_api.py rename to loopx/chat/goal_subagent_api.py index e8d01aeb65..1e380eee22 100644 --- a/loopx/chat_goal_subagent_api.py +++ b/loopx/chat/goal_subagent_api.py @@ -4,15 +4,15 @@ from typing import Any -from .control_plane.goals.configure_goal_service import configure_goal_with_global_sync -from .capabilities.multi_subagent import ( +from ..control_plane.goals.configure_goal_service import configure_goal_with_global_sync +from ..capabilities.multi_subagent import ( apply_codex_subagent_capacity, plan_codex_subagent_capacity, public_codex_host_capacity, ) -from .control_plane.todos.contract import normalize_todo_task_domain -from .status_server import configure_goal_preview_id -from .orchestration import subagent_model_configuration_options +from ..control_plane.todos.contract import normalize_todo_task_domain +from ..status_server import configure_goal_preview_id +from ..orchestration import subagent_model_configuration_options CHAT_GOAL_SUBAGENT_DRY_RUN_PATH = "/api/chat/goal-subagents/dry-run" diff --git a/loopx/chat_server.py b/loopx/chat_server.py index 97ef446c53..12e1e4544b 100644 --- a/loopx/chat_server.py +++ b/loopx/chat_server.py @@ -36,7 +36,7 @@ ) from .chat_actions import ChatActionService, ProtectedActionGate, goal_workspace_labels, goal_workspace_ref from .chat_action_store import ACTION_KINDS, ActionConflictError, ChatActionStore -from .chat_goal_subagent_api import ( +from .chat.goal_subagent_api import ( GoalSubagentConfigurationRequestMixin, add_goal_subagent_capability, add_goal_subagent_routes, @@ -101,7 +101,7 @@ default_extension_state_file, resolve_extension_activation, ) -from .chat_completed_todos import CompletedTodoPages, CompletedTodoRequestMixin +from .chat.completed_todos import CompletedTodoPages, CompletedTodoRequestMixin from .presentation.explore_results_api import ExploreResultsRequestMixin from .presentation.research_analysis_api import RESEARCH_ANALYSIS_PATH, ResearchAnalysisRequestMixin from .presentation.goal_source_routing import GOAL_SOURCE_LINKS_PATH, GoalSourceRequestMixin diff --git a/loopx/chat_status_api.py b/loopx/chat_status_api.py index f0e978462c..0e1bbb96bc 100644 --- a/loopx/chat_status_api.py +++ b/loopx/chat_status_api.py @@ -10,7 +10,7 @@ from urllib.parse import parse_qs, urlparse from .chat import redact_local_paths -from .chat_goal_subagent_api import goal_subagent_configuration_enabled +from .chat.goal_subagent_api import goal_subagent_configuration_enabled from .chat.workspace_directory import workspace_goal_directory from .codex_app_thread_activity import ( codex_delivery_expectations, diff --git a/loopx/control_plane/status/goal_source.py b/loopx/control_plane/status/goal_source.py index f133ea243a..10bc3ceed5 100644 --- a/loopx/control_plane/status/goal_source.py +++ b/loopx/control_plane/status/goal_source.py @@ -24,7 +24,7 @@ from urllib.request import HTTPRedirectHandler, Request, build_opener from ..content_digest import BARE_SHA256_PATTERN -from ...chat_completed_todos import CompletedTodoPages +from ...chat.completed_todos import CompletedTodoPages from ...status_server import is_loopback_host from .ssh_host_catalog import configured_ssh_host_aliases diff --git a/tests/architecture/top_level_module_budget.json b/tests/architecture/top_level_module_budget.json index 62b7c57a22..ac1a498748 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": 132, + "max_top_level_modules": 130, "allowlist": ["__init__.py", "entrypoint.py", "cli.py"] } diff --git a/tests/capabilities/test_codex_subagent_host_capacity.py b/tests/capabilities/test_codex_subagent_host_capacity.py index cd77e79287..652a1ce9f6 100644 --- a/tests/capabilities/test_codex_subagent_host_capacity.py +++ b/tests/capabilities/test_codex_subagent_host_capacity.py @@ -11,7 +11,7 @@ from loopx.control_plane.goals.configure_goal_service import ( configure_goal_with_global_sync, ) -from loopx.chat_goal_subagent_api import GoalSubagentConfigurationRequestMixin +from loopx.chat.goal_subagent_api import GoalSubagentConfigurationRequestMixin from loopx.file_lock import exclusive_cross_runtime_file_lock from loopx.paths import global_registry_path diff --git a/tests/control_plane/test_subagent_model_configuration.py b/tests/control_plane/test_subagent_model_configuration.py index 69f6045f07..c7606bdccf 100644 --- a/tests/control_plane/test_subagent_model_configuration.py +++ b/tests/control_plane/test_subagent_model_configuration.py @@ -274,7 +274,7 @@ def test_capability_model_rejects_non_string_inputs(config: dict) -> None: def test_goal_drawer_preview_binding_and_model_roundtrip(registry: Path) -> None: from types import SimpleNamespace - from loopx.chat_goal_subagent_api import GoalSubagentConfigurationRequestMixin + from loopx.chat.goal_subagent_api import GoalSubagentConfigurationRequestMixin class Handler(GoalSubagentConfigurationRequestMixin): def __init__(self) -> None: diff --git a/tests/test_chat_completed_todos.py b/tests/test_chat_completed_todos.py index feee0dda13..a55e477995 100644 --- a/tests/test_chat_completed_todos.py +++ b/tests/test_chat_completed_todos.py @@ -7,7 +7,7 @@ import pytest -from loopx.chat_completed_todos import CompletedTodoPages, _verify_goal_result_page +from loopx.chat.completed_todos import CompletedTodoPages, _verify_goal_result_page from loopx.chat_server import ChatHTTPServer, ChatRequestHandler from loopx.control_plane.todos.contract import encode_metadata_value @@ -127,7 +127,7 @@ def test_snapshot_expiry_starts_when_loading_finishes(monkeypatch): pages = CompletedTodoPages() pages.ttl_seconds = 1 clock = [0] - monkeypatch.setattr("loopx.chat_completed_todos.monotonic", lambda: clock[0]) + monkeypatch.setattr("loopx.chat.completed_todos.monotonic", lambda: clock[0]) rows = [{"todo_id": f"todo_{index}"} for index in range(41)] def load(): diff --git a/tests/test_managed_research_team.py b/tests/test_managed_research_team.py index 3df964c134..4d78f925bf 100644 --- a/tests/test_managed_research_team.py +++ b/tests/test_managed_research_team.py @@ -19,7 +19,7 @@ from loopx.control_plane.goals.acceptance import ( # noqa: E402 configure_goal_acceptance, inspect_goal_acceptance, verify_goal_acceptance, ) -from loopx.chat_completed_todos import ( # noqa: E402 +from loopx.chat.completed_todos import ( # noqa: E402 CompletedTodoPages, _goal_result_candidates, _verify_goal_result_page, ) from loopx.chat_server import ChatHTTPServer, ChatRequestHandler # noqa: E402