diff --git a/docs/architecture/rfcs/monorepo-distribution-split-v0.md b/docs/architecture/rfcs/monorepo-distribution-split-v0.md index 6e5521ac0a..dd29d868f2 100644 --- a/docs/architecture/rfcs/monorepo-distribution-split-v0.md +++ b/docs/architecture/rfcs/monorepo-distribution-split-v0.md @@ -671,23 +671,18 @@ diaries in this RFC. #### 3. Concrete retirement backlog and ratchet rules -1. **Pre-Turn pilot CLI subcommands and top-level modules.** Retire the `15` - superseded pre-Turn `codex-cli-*` pilot/proof subcommands replaced by - `loopx turn` (`turn_driver/codex_cli.py`), `start-goal`, and `codex_app` - heartbeat (`14` with zero non-pilot callers plus `codex-cli-session-probe` - referenced only as a hint in `loopx/project_prompt.py`), along with the `4` - top-level `loopx/codex_cli_*.py` modules (`3,767` LOC) and `6` - `loopx/cli_commands/starter_*.py` wrappers (`859` LOC). Keep live - `codex-cli-bootstrap-message` and `turn_driver/codex_cli.py`. -2. **Remaining top-level `chat_*` and `*_goal_mode` migrations with strict - downward ratchet.** Complete M1/M2 by migrating the remaining `20` top-level - `loopx/chat_*.py` modules (`20,562` LOC) into `loopx/chat/` and the `9` - `loopx/*_goal_mode/` directories (`59` files / `17,655` lines; `33` `.py` / - `7,062` LOC) into `loopx/hosts/`. Every PR deleting or moving top-level - modules must ratchet `max_top_level_modules` in - [`top_level_module_budget.json`](../../../tests/architecture/top_level_module_budget.json) - (currently `127`) strictly downward; keeping permanent top-level shim files - that freeze the count does not clear M1/M2. +1. **Pre-Turn pilot CLI retirement.** [#8884](https://github.com/loopx-project/loopx/pull/8884) + retired 15 superseded pilot commands and four flat `loopx/codex_cli_*.py` + modules, and lowered the top-level budget from 127 to 124. The live + `codex-cli-bootstrap-message` and `turn_driver/codex_cli.py` still have callers. +2. **Remaining top-level `chat_*` and `*_goal_mode` migrations.** M1 places + the internal action normalization and Goal lifecycle action modules under + `loopx/chat/`. This removes two flat names and lowers the budget from 124 + to 122. M1 still needs to migrate the remaining Chat modules under I3. + M2 still moves host mode packages under `loopx/hosts/`. Each net removal + lowers [`top_level_module_budget.json`](../../../tests/architecture/top_level_module_budget.json) + by the same count in that PR. The Core wheel already excludes both Chat + paths, so this move reduces the source directory count. 3. **Unreferenced `examples/` scripts and source-text-pinning smokes.** Prune unreferenced scripts under `examples/` (`200` unreferenced `.py` scripts / `45,504` LOC; `209` scripts / `47,325` LOC across `.py/.sh/.mjs/.js/.ts` on diff --git a/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md b/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md index 2303929af4..dfdb523659 100644 --- a/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md +++ b/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md @@ -488,17 +488,14 @@ R0 可以先于目录移动交付,但不代表内核合格。R3/R4 可选, #### 3. 具名退役清单与棘轮规则 -1. **退役 Turn 前置 pilot CLI 子命令与顶层模块。** 删除已被 `loopx turn`(`turn_driver/codex_cli.py`)、 - `start-goal` 与 `codex_app` heartbeat 替代的 `15` 个 `codex-cli-*` pilot/证明子命令(其中 - `14` 个在非 pilot 生产调用方中为零引用,另有 `codex-cli-session-probe` 仅作为提示出现在 - `loopx/project_prompt.py`),以及 `4` 个顶层 `loopx/codex_cli_*.py`(`3,767` 行)和 `6` 个 - `loopx/cli_commands/starter_*.py` 包装(`859` 行);保留现役 `codex-cli-bootstrap-message` 与 - `turn_driver/codex_cli.py`。 -2. **迁完剩余顶层 `chat_*` 与 `*_goal_mode` 并严格单向下调棘轮。** 完成 M1/M2:将剩余 `20` 个顶层 - `loopx/chat_*.py`(`20,562` 行)迁入 `loopx/chat/`,将 `9` 个 `loopx/*_goal_mode/` 目录 - (`59` 文件 / `17,655` 行;其中 `33` 个 `.py` / `7,062` 行)迁入 `loopx/hosts/`。任何删除或迁出 - 顶层模块的 PR 都必须在同一 PR 内同步调低 [`top_level_module_budget.json`](../../../tests/architecture/top_level_module_budget.json) - 中的 `max_top_level_modules`(当前 `127`);靠保留永久顶层 shim 维持计数不变不构成 M1/M2 完成。 +1. **退役 Turn 前置 pilot CLI。** [#8884](https://github.com/loopx-project/loopx/pull/8884) + 已退役 15 个被替代的试验命令和四个顶层 `loopx/codex_cli_*.py` 模块,顶层预算从 127 降至 124。 + `codex-cli-bootstrap-message` 与 `turn_driver/codex_cli.py` 仍有现役调用方。 +2. **迁移剩余顶层 `chat_*` 和 `*_goal_mode`。** M1 将动作规范化和 Goal 生命周期动作两个内部模块 + 放入 `loopx/chat/`,移除两个顶层名字,预算由 124 降至 122。M1 剩余 Chat 模块仍按 I3 迁移, + M2 继续把宿主模式包迁入 `loopx/hosts/`。每次净减少都在同一 PR 中等量调低 + [`top_level_module_budget.json`](../../../tests/architecture/top_level_module_budget.json)。 + Core wheel 原已排除这两类 Chat 路径,这次减少的是源码顶层模块数量。 3. **清理无引用 `examples/` 与源码文本绑定式 smoke。** 清理 `examples/` 中无引用脚本(`main@f15ebdd16b` 实测 `200` 个无引用 `.py` / `45,504` 行;按 `.py/.sh/.mjs/.js/.ts` 计为 `209` 个 / `47,325` 行), 并依 [good-smokes](../../development/good-smokes.md) 退役 `14` 个绑定内部 Python 符号而非已交付 diff --git a/loopx/chat_action_normalization.py b/loopx/chat/action_normalization.py similarity index 97% rename from loopx/chat_action_normalization.py rename to loopx/chat/action_normalization.py index d8b0f730bb..b134927417 100644 --- a/loopx/chat_action_normalization.py +++ b/loopx/chat/action_normalization.py @@ -6,11 +6,11 @@ import re from typing import Any, Mapping -from .agent_registry import registered_agent_ids_for_goal -from .control_plane.content_digest import BARE_SHA256_PATTERN -from .control_plane.runtime.time import now_utc, parse_timestamp, utc_isoformat -from .control_plane.todos.contract import require_supported_todo_resume_when -from .registry import registry_goals +from ..agent_registry import registered_agent_ids_for_goal +from ..control_plane.content_digest import BARE_SHA256_PATTERN +from ..control_plane.runtime.time import now_utc, parse_timestamp, utc_isoformat +from ..control_plane.todos.contract import require_supported_todo_resume_when +from ..registry import registry_goals _AUTHORITY_PRINCIPAL = re.compile(r"^[a-z][a-z0-9._-]{0,30}:[A-Za-z0-9._:-]{1,200}$") @@ -33,7 +33,7 @@ def _normalize( ) -> dict[str, Any]: # Imported lazily to retain the compatibility helpers in chat_actions # without introducing a module initialization cycle. - from .chat_actions import ( + from ..chat_actions import ( ProtectedActionGate, _digest, _normalize_cadence, @@ -174,15 +174,15 @@ def _normalize( "agent_session", "managed_turn", }: - from .control_plane.collaboration.goal_instance_scope import ( + from ..control_plane.collaboration.goal_instance_scope import ( collaboration_goal_scope, ) - from .control_plane.effect_runtime import ( + from ..control_plane.effect_runtime import ( EffectRuntimeRejected, effect_runtime_result, ) - from .control_plane.goals.activation import goal_is_stopped - from .thread_agent_binding import resolve_registry_thread_agent_binding + from ..control_plane.goals.activation import goal_is_stopped + from ..thread_agent_binding import resolve_registry_thread_agent_binding try: executor = dict( @@ -227,7 +227,7 @@ def _normalize( raise ValueError("agent operation Goal is stopped") origin_goal_ref = scope.current_goal_ref if executor["kind"] == "managed_turn": - from .control_plane.collaboration.operation_handoff import ( + from ..control_plane.collaboration.operation_handoff import ( managed_operation_binding_current, ) @@ -260,8 +260,8 @@ def _normalize( raise ValueError("source route selection requires a managed executor") source_route = None if managed_source: - from .control_plane.effect_runtime import effect_runtime_result - from .thread_agent_binding import ( + from ..control_plane.effect_runtime import effect_runtime_result + from ..thread_agent_binding import ( collect_accepted_bindings, resolve_thread_agent_binding, ) @@ -583,7 +583,7 @@ def _normalize( if values.get(field): result[field] = _text(values[field], field=field, limit=1000) if "permission" in values or "start_execution" in values: - from .control_plane.effect_runtime import effect_runtime_result + from ..control_plane.effect_runtime import effect_runtime_result result.update(effect_runtime_result("goal.creation.execution.normalize", values)) if result.get("open_session") is False and result.get("start_execution"): # start_execution queues the original task as the first Turn of the Session the @@ -721,10 +721,10 @@ def _normalize( raise ValueError("heartbeat edit requires a configuration change") return result if action_kind == "team.plan": - from .control_plane.todos.contract import ( + from ..control_plane.todos.contract import ( TODO_ACTION_KIND_ADVANCEMENT_VALUES, ) - from .control_plane.work_items.governed_transition_proposal import ( + from ..control_plane.work_items.governed_transition_proposal import ( validate_steward_team_plan_preview, ) diff --git a/loopx/chat_goal_lifecycle_actions.py b/loopx/chat/goal_lifecycle_actions.py similarity index 96% rename from loopx/chat_goal_lifecycle_actions.py rename to loopx/chat/goal_lifecycle_actions.py index 318dcb9e4a..5580c55a64 100644 --- a/loopx/chat_goal_lifecycle_actions.py +++ b/loopx/chat/goal_lifecycle_actions.py @@ -4,9 +4,9 @@ from typing import Any -from .control_plane.goals.activation import GoalActivationState, goal_activation_state -from .control_plane.goals.activation_service import set_goal_activation_state -from .control_plane.goals.deletion_service import delete_stopped_goal +from ..control_plane.goals.activation import GoalActivationState, goal_activation_state +from ..control_plane.goals.activation_service import set_goal_activation_state +from ..control_plane.goals.deletion_service import delete_stopped_goal GOAL_LIFECYCLE_SOURCE_BASIS_SCHEMA_VERSION = "loopx_goal_lifecycle_source_basis_v1" @@ -75,7 +75,7 @@ def _goal_lifecycle_preview( def _normalize_goal_lifecycle( self, parameters: dict[str, Any] ) -> dict[str, Any]: - from .chat_actions import _opaque, _text + from ..chat_actions import _opaque, _text values = self._allowed_parameters( parameters, @@ -100,7 +100,7 @@ def _apply_goal_delete( goal_id: str, current_fingerprint: str, ) -> dict[str, Any]: - from .chat_actions import _digest + from ..chat_actions import _digest expected_fingerprint = str(proposal.get("expected_state_fingerprint") or "") if current_fingerprint != expected_fingerprint: @@ -175,7 +175,7 @@ def _goal_delete_failed( def _apply_goal_lifecycle( self, proposal_id: str, proposal: dict[str, Any], parameters: dict[str, Any] ) -> dict[str, Any]: - from .chat_actions import _digest + from ..chat_actions import _digest goal_id = str(parameters["goal_id"]) operation = str(parameters["operation"]) diff --git a/loopx/chat_actions.py b/loopx/chat_actions.py index 6f6065eb1b..834a4000ec 100644 --- a/loopx/chat_actions.py +++ b/loopx/chat_actions.py @@ -12,13 +12,13 @@ from .control_plane.projects.identity import GoalCreationConflictError from .control_plane.coordination.new_goal_storage_transport import initialize_goal_storage_target from .chat import apply_todo_review_preview, build_todo_review_preview -from .chat_action_normalization import ChatActionNormalizationMixin +from .chat.action_normalization import ChatActionNormalizationMixin from .chat_action_store import ( ACTION_KINDS as SUPPORTED_ACTION_KINDS, ActionConflictError, ChatActionStore, ) -from .chat_goal_lifecycle_actions import ChatGoalLifecycleActionMixin +from .chat.goal_lifecycle_actions import ChatGoalLifecycleActionMixin from .chat.monitor_actions import ChatMonitorActionMixin from .chat_store import ChatSessionStore, TERMINAL_TURN_STATES from .chat.todo_actions import ChatTodoActionMixin diff --git a/tests/architecture/test_content_digest_single_owner.py b/tests/architecture/test_content_digest_single_owner.py index 24cfd06eaf..ef01cb9d43 100644 --- a/tests/architecture/test_content_digest_single_owner.py +++ b/tests/architecture/test_content_digest_single_owner.py @@ -181,7 +181,7 @@ "loopx.capabilities.periodic_report.review", "loopx.capabilities.progress_review.receipt", "loopx.chat.result_files_api", - "loopx.chat_action_normalization", + "loopx.chat.action_normalization", "loopx.capabilities.manager_context.chat_history", "loopx.cli_commands.quota_context_reader", "loopx.cli_commands.update_artifact", diff --git a/tests/architecture/top_level_module_budget.json b/tests/architecture/top_level_module_budget.json index 5eb69d838b..7a507492e8 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": "0514512ee7fbdf5548c88d07763a41dbfc5df931", - "max_top_level_modules": 124, + "baseline_commit": "41ea75e89892ed88d0ae543e97e31aad0a181c47", + "max_top_level_modules": 122, "allowlist": ["__init__.py", "entrypoint.py", "cli.py"] } diff --git a/tests/control_plane/test_compact_identifier_shape_owner.py b/tests/control_plane/test_compact_identifier_shape_owner.py index 6bdf6c0892..5d1e90adab 100644 --- a/tests/control_plane/test_compact_identifier_shape_owner.py +++ b/tests/control_plane/test_compact_identifier_shape_owner.py @@ -6,7 +6,8 @@ import pytest -from loopx import chat_action_normalization, chat_actions, chat_action_store, domain_state +from loopx import chat_actions, chat_action_store, domain_state +from loopx.chat import action_normalization from loopx.capabilities.benchmark_toolkit import integrity from loopx.capabilities.context_providers import service_ownership from loopx.capabilities.decision_context import packets, profile, sources @@ -254,10 +255,10 @@ def test_a_principal_reference_is_a_different_question_and_stays_separate() -> N # ``^[a-z][a-z0-9._-]{0,30}:$`` embeds the same body behind a required # family prefix. Merging them would either widen the opaque id to accept a # prefix it never allowed or narrow a principal to a bare id. - principal = chat_action_normalization._AUTHORITY_PRINCIPAL + principal = action_normalization._AUTHORITY_PRINCIPAL assert principal.fullmatch("codex:thread-1") assert not principal.fullmatch("thread-1") assert PUBLIC_OPAQUE_ID.fullmatch("thread-1") assert OPAQUE_SHAPE not in ( - REPOSITORY_ROOT / "loopx/chat_action_normalization.py" + REPOSITORY_ROOT / "loopx/chat/action_normalization.py" ).read_text(encoding="utf-8") diff --git a/tests/control_plane/test_goal_activation.py b/tests/control_plane/test_goal_activation.py index 7db05f5a32..fe80eee20f 100644 --- a/tests/control_plane/test_goal_activation.py +++ b/tests/control_plane/test_goal_activation.py @@ -10,7 +10,7 @@ import pytest -from loopx import chat_goal_lifecycle_actions +from loopx.chat import goal_lifecycle_actions from loopx.chat_action_store import ChatActionStore from loopx.chat_actions import ChatActionService from loopx.cli_commands import registry_admin @@ -879,7 +879,7 @@ def test_owner_confirmed_lifecycle_action_rechecks_source_inside_write_lock( "idempotency_key": "stop-goal-one-before-lock-race", } ) - original = chat_goal_lifecycle_actions.set_goal_activation_state + original = goal_lifecycle_actions.set_goal_activation_state source_changed = False def change_source_before_execute(**kwargs: object) -> dict[str, object]: @@ -894,7 +894,7 @@ def change_source_before_execute(**kwargs: object) -> dict[str, object]: return original(**kwargs) monkeypatch.setattr( - chat_goal_lifecycle_actions, + goal_lifecycle_actions, "set_goal_activation_state", change_source_before_execute, ) @@ -939,7 +939,7 @@ def test_owner_confirmed_lifecycle_action_rechecks_route_before_execute( "idempotency_key": "stop-goal-one-before-execute-route-race", } ) - original = chat_goal_lifecycle_actions.set_goal_activation_state + original = goal_lifecycle_actions.set_goal_activation_state switched_global_bytes: bytes | None = None def change_route_before_execute(**kwargs: object) -> dict[str, object]: @@ -952,7 +952,7 @@ def change_route_before_execute(**kwargs: object) -> dict[str, object]: return original(**kwargs) monkeypatch.setattr( - chat_goal_lifecycle_actions, + goal_lifecycle_actions, "set_goal_activation_state", change_route_before_execute, ) @@ -1656,7 +1656,7 @@ def test_owner_confirmed_typed_action_recovers_concurrent_same_operation_delete( action_store=tmp_path / "actions", idempotency_key="delete-goal-one-concurrently", ) - original_delete = chat_goal_lifecycle_actions.delete_stopped_goal + original_delete = goal_lifecycle_actions.delete_stopped_goal delete_calls = 0 def delete_between_preflight_and_execute(**kwargs: object) -> dict[str, object]: @@ -1675,7 +1675,7 @@ def delete_between_preflight_and_execute(**kwargs: object) -> dict[str, object]: return current monkeypatch.setattr( - chat_goal_lifecycle_actions, + goal_lifecycle_actions, "delete_stopped_goal", delete_between_preflight_and_execute, ) @@ -1746,7 +1746,7 @@ def test_owner_confirmed_typed_action_records_delete_failures( action_store=tmp_path / "actions", idempotency_key=f"delete-goal-one-lock-failure-{failure_call}", ) - original_delete = chat_goal_lifecycle_actions.delete_stopped_goal + original_delete = goal_lifecycle_actions.delete_stopped_goal delete_calls = 0 def fail_delete(**kwargs: object) -> dict[str, object]: @@ -1757,7 +1757,7 @@ def fail_delete(**kwargs: object) -> dict[str, object]: return original_delete(**kwargs) monkeypatch.setattr( - chat_goal_lifecycle_actions, + goal_lifecycle_actions, "delete_stopped_goal", fail_delete, ) diff --git a/tests/extensions/test_finance_transaction_approval_consumer.py b/tests/extensions/test_finance_transaction_approval_consumer.py index 3ea4406b1f..d0316323d1 100644 --- a/tests/extensions/test_finance_transaction_approval_consumer.py +++ b/tests/extensions/test_finance_transaction_approval_consumer.py @@ -9,7 +9,7 @@ import pytest -import loopx.chat_action_normalization as chat_action_normalization +from loopx.chat import action_normalization from loopx.chat_action_store import ChatActionStore from loopx.chat_actions import ChatActionService from loopx.extensions.lark.goal_channel_operation import ( @@ -113,7 +113,7 @@ def test_builder_feeds_one_canonical_core_dashboard_and_lark_projection( ) -> None: module = _module() now = datetime(2026, 9, 14, 1, 0, tzinfo=UTC) - monkeypatch.setattr(chat_action_normalization, "now_utc", lambda: now) + monkeypatch.setattr(action_normalization, "now_utc", lambda: now) packet = module.build_finance_transaction_approval_packet(_input(now=now), now=now) assert packet["boundary"] == {