Skip to content

refactor(chat): move ACP, endpoint, and provider leaves under loopx.chat and ratchet module budget (#5072) - #9196

Merged
loopx-agent merged 1 commit into
mainfrom
codex/chat-leaf-colocate-batch2-20261121
Nov 22, 2026
Merged

loopx-agent merged 1 commit into
mainfrom
codex/chat-leaf-colocate-batch2-20261121

Conversation

@loopx-agent

@loopx-agent loopx-agent commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Goal And Delivered Outcome

Author Declaration

  • Written by: model_agent (Antigravity, Google Deepmind)

Implemented against

  • Specification and revision: docs/architecture/rfcs/monorepo-distribution-split-v0.md (M1, I3, Section 9) at 4052e3ffd24decd03680abcc79de1b956c6f5ba1
  • Criteria:
Criterion (spec clause) Disposition Symbol / path Test or command
M1 internal Chat leaf relocation under loopx/chat/ implemented loopx/chat/acp.py, loopx/chat/endpoints.py, loopx/chat/providers.py pytest -q --no-cov tests/test_chat_internal_module_layout.py
I3 pure internal moves delete old top-level modules with all callers updated implemented loopx/chat/session_open.py, loopx/capabilities/native_chat/model_settings.py, loopx/chat_runtime.py, loopx/cli_commands/support_control_chat_endpoint.py, loopx/kiro_cli_goal_mode/*, tests/*, examples/* rg -n "loopx\\.chat_(acp|endpoints|providers)|chat_(acp|endpoints|providers)\\.py" + tests/test_chat_internal_module_layout.py
Top-level module budget ratchet lowered in same PR implemented tests/architecture/top_level_module_budget.json (118 → 115) pytest -q --no-cov tests/architecture/test_top_level_module_budget.py
  • Self-check before submission: Verified ls -1 loopx/*.py | wc -l == 115, verified zero dangling old-module imports/monkeypatches across code/tests/examples/docs via rg, verified bilingual RFC check, ran ruff, configured strict mypy (17 files), affected chat smokes (acp-adapter, provider-adapters, chat-server), browser smoke syntax check (node --check), targeted pytest (821 passed in 15.90s), loopx check (0 errors on 25 files), Goal-bound change-quality (cqr_c9c3481af1b333546746), and canary premerge (19/19 selected checks passed, 0 failures).

Scope And Continuation

Validation

  • Tested revision: fc76e46fcb72dfc3574fbaa2ec0e5e6906e1316a (rebased cleanly onto 4052e3ffd24decd03680abcc79de1b956c6f5ba1; all checks below ran directly on exact HEAD fc76e46fcb72dfc3574fbaa2ec0e5e6906e1316a)
  • Run state: finished
  • Input classes: synthetic, public_fixture
Check kind Result Public-safe evidence / limitation
unit passed pytest -q --no-cov -n auto tests/architecture/test_top_level_module_budget.py tests/architecture/test_control_plane_import_boundaries.py tests/architecture/test_package_kernel_import_ratchet.py tests/test_chat_internal_module_layout.py tests/test_atomic_write_modes.py tests/test_chat_acp_startup_timeout.py tests/test_chat_agent.py tests/test_chat_agent_model_http.py tests/test_chat_codex_defaults.py tests/test_chat_endpoint_readiness.py tests/test_chat_goal_workspace_selection.py tests/test_chat_long_running.py tests/test_chat_machine_configuration_api.py tests/test_chat_path_redaction.py tests/test_chat_reasoning_selection.py tests/test_chat_startup_isolation.py tests/test_kiro_cli_host_surface.py → 821 passed in 15.90s
static passed ruff check on all changed .py files (All checks passed!), python -m mypy (Success: no issues found in 17 source files), python scripts/check_rfc_bilingual.py --base origin/main --head HEAD (RFC bilingual diff check passed.), node --check examples/personal-workspace-browser/first-goal-agent-unavailable.mjs (exit 0), loopx check --scan-path ... (ok: true, errors: 0, 25 files clean)
real_entrypoint passed python examples/loopx-chat-acp-adapter-smoke.py (ok), python examples/loopx-chat-provider-adapters-smoke.py (ok), python examples/loopx-chat-server-smoke.py (ok), loopx canary premerge --from-git-diff --git-diff-base origin/main --goal-id personal-loopx-maintenance (ok: true, direct_checks: 6/6, selected_checks: 19/19, failure_count: 0, change_quality receipt cqr_c9c3481af1b333546746 valid)
  • Coverage and gaps: All callers, monkeypatches, smokes, layout assertions, and module-budget gates referencing chat_acp, chat_endpoints, or chat_providers were checked and exercised; examples/personal-workspace-browser/first-goal-agent-unavailable.mjs was syntax-checked (node --check) rather than executed end-to-end in Playwright (full-repo pytest and remote CI were not run).

Frontend / Visual Evidence

  • UI impact: none
  • Before: N/A
  • After: N/A
  • First viewport and preview: N/A (internal Python module colocation only; zero UI rendering changes).
  • States and viewports shown: N/A
  • Source data: none
  • Attention review: N/A
  • Craft review: N/A

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Refactoring (no functional changes)
  • Documentation update
  • Test update

LoopX Area

  • Control plane (goals, todos, quota, scheduler, registry, runtime)
  • Benchmark boundary (adapters, runners, verifiers, scoring, evidence)
  • Capability or extension (providers, adapters, skills)
  • Public docs or presentation surface (README, protocols, dashboard)
  • Build, packaging, installer, or CI
  • Host or runtime integration

Technical Direction

  • Direction / acceptance reference, when applicable: docs/architecture/rfcs/monorepo-distribution-split-v0.md (M1, I3, Section 9)

Shared-authority RFC fixture impact

N/A

Boundary Checklist

  • Neither the diff nor this PR body/comments/attachments disclose private state, credentials, raw traces or verifier output, internal links, or local machine paths (including .loopx/, .codex/goals/, and live ACTIVE_GOAL_STATE.md).
  • I did not duplicate maintainer-owned benchmark work unless a maintainer split out a public issue for it.
  • I kept the change scoped to the linked issue/task.
  • Existing English/Chinese RFC pairs (including ledger entries) both have a diff, and the local premerge check python3 scripts/check_rfc_bilingual.py --base origin/main --head HEAD passes, or no paired RFC changed.
  • I completed the visual evidence section for UI changes, or marked UI impact none.
  • Every commit includes a DCO Signed-off-by trailer (git commit -s).

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · Gemini · Google · self_reported

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

动机 / Motivation

LoopX Chat 运行时(ChatRuntimeController、open_chat_session)、原生模型设置模块(model_settings)、CLI chat-endpoint 命令以及 loopx-core 与 loopx-workspace 分包维护者。

迁移前:loopx/chat_acp.py、loopx/chat_endpoints.py 与 loopx/chat_providers.py 三个仅服务于内部 Chat 传输与端点的模块仍扁平放置在 loopx/ 顶层,使 loopx/*.py 保持在 122 个并模糊包内归属边界;迁移后:三者直接通过 git mv 并入 loopx/chat/{acp,endpoints,providers}.py,同步更新全仓 25 个文件内的相对导入、测试与示例引用,删除顶层旧模块且不留兼容 shim,并将 top_level_module_budget.json 从 122 收紧至 119。

全仓 loopx/*.py 顶层模块数精确降为 119 且与 top_level_module_budget.json(119)一致;importlib.util.find_spec 对 loopx.chat_acp、loopx.chat_endpoints 与 loopx.chat_providers 均返回 None;跨模块导入、ACP/Claude/直连模型适配器行为、AgentEndpointRegistry 读写权限(0600)与 chat-endpoint list CLI 均与迁移前等价。

本 PR 不改动任何运行时会话语义、协议 schema、ACP/Provider 行为逻辑或 loopx.chat_action_store 边界,也不合并并行 PR #9179 的搬迁批次或修改远端分支保护策略。

loopx/ 顶层仍保留其余待迁出的 chat_*.py 与主机模式目录(例如 chat_action_store.py 受当前 loopx-core 边界测试约束留在后续批次),且主干已推进至 PR #9193 后本分支处于 BEHIND(无文件冲突)。

改动思路 / Approach

围绕仓库既定分包与减法规范(docs/architecture/rfcs/monorepo-distribution-split-v0.md @ 16f418837c87ab40f04ff303962598f5bd71a034),对 loopx/chat_acp.py、loopx/chat_endpoints.py 与 loopx/chat_providers.py 三个内部叶子模块执行“无兼容 shim 的直接迁入 + 全量调用点同步 + 单向预算棘轮”策略。由于原计划中的 chat_action_store.py 仍被 tests/control_plane/test_installed_core_context.py 与 packages/loopx-core/prepare.py 的核心分包边界断言显式引用,作者将其替换为与并行 PR #9179 无重叠的 chat_acp.py,避免了在搬迁 PR 中夹带跨分包契约变更。

将仅在内部使用的 ACP stdio 适配器、本地端点注册表和 Claude/直连模型适配器作为纯代码组织内移并入 loopx/chat/,既不新增适配层、注册表或运行时开关,又直接把顶层模块上限按净删减量从 122 压低至 119,是符合 M1 与 I3 的最小可逆边界。

当前 PR 边界(current_pr_boundary):当前 PR 仅搬迁 chat_acp、chat_endpoints、chat_providers 三枚非 loopx-core 约束叶子模块并更新全仓内部调用方与预算棘轮,故意把受 test_installed_core_context.py 边界断言约束的 chat_action_store.py 与其余叶子模块留待 #5072 后续独立批次。

搬迁前后导入流向对比:

迁移前: loopx/chat/{session_open,endpoint_catalog} / loopx/chat_runtime / model_settings / support_control_chat_endpoint
          ──▶ loopx.chat_acp / loopx.chat_endpoints / loopx.chat_providers (top-level 122)
迁移后: loopx/chat/{session_open} / loopx/chat_runtime / model_settings / support_control_chat_endpoint
          ──▶ loopx.chat.acp / loopx.chat.endpoints / loopx.chat.providers (top-level 119, 旧路径 find_spec=None)

具体改动 / Changes

依据规范 docs/architecture/rfcs/monorepo-distribution-split-v0.md(修订 16f418837c87ab40f04ff303962598f5bd71a034)逐条核对以下验收标准:

  • M1(implemented):通过 git mv 将 loopx/chat_acp.py、loopx/chat_endpoints.py、loopx/chat_providers.py 分别迁入 loopx/chat/acp.py、loopx/chat/endpoints.py 与 loopx/chat/providers.py,由 tests/test_chat_internal_module_layout.py 校验新模块归属 loopx.chat.*。
  • I3(implemented):全仓不存在对这 3 个模块的对外公开重导出(loopx/__init__.py 与 loopx/chat.py 均未暴露);PR 同步更新所有内部调用方、monkeypatch 字符串目标、3 个离线 smoke、1 个浏览器 smoke 脚本及 kiro_cli_goal_mode 文档注释,且不保留任何顶层兼容 shim。
  • Section 9 row 1(implemented):tests/architecture/top_level_module_budget.json 将 max_top_level_modules 从 122 精确下调 3 至 119(实测 ls -1 loopx/*.py | wc -l 为 119),tests/architecture/test_top_level_module_budget.py 验证通过。

关键代码讲解

  1. ACPStdioAdapter(loopx/chat/acp.py#L42-L593):负责通过 stdio JSON-RPC 2.0 启动、恢复和关闭本地/远程 ACP Agent 会话并流式转发事件。迁移后仅将其顶部对 loopx.chat 与 loopx.chat_agent 的相对导入从单点改为 from ..chat import ... 与 from ..chat_agent import ...,内部超时控制、权限请求拒绝与优雅退出逻辑一字未改。
  2. AgentEndpointRegistry(loopx/chat/endpoints.py#L221-L274):管理 owner-local 自定义 ACP 端点的 endpoints.json 读写(0600 原子写入、文件锁、RESERVED_AGENT_IDS 防覆盖保护)。迁入后将内部相对导入更新为 from ..chat_store import utc_now、from ..file_lock import ...、from ..kiro_cli_goal_mode import KIRO_CLI_CHAT_AGENT_ID,同时保持 ChatRuntimeController(loopx/chat_runtime.py#L49,L280,L330)与 handle_chat_endpoint_command(loopx/cli_commands/support_control_chat_endpoint.py#L8,L49)的单一所有权不变。
  3. ClaudeCodeAdapter 与 codex_model_options(loopx/chat/providers.py#L25-L60,L154-L330):分别封装 Codex 模型目录探测、Claude Code 只读 CLI 会话以及 Anthropic/OpenAI 直连只读工具循环。迁入后将 from .chat / from .chat_agent 改为 from ..chat / from ..chat_agent,同步在 loopx/chat/session_open.py#L51,L63 使用同包相对导入 from .acp import ACPStdioAdapter 与 from .providers import ClaudeCodeAdapter, direct_model_from_environment。
  4. observed_model_settings 与 inspect_agent_model_options(loopx/capabilities/native_chat/model_settings.py#L100-L239):分别在模型选项查询、会话模型配置以及会话恢复校验时懒导入 from ...chat import providers 与 from ...chat.acp import ACPStdioAdapter。同时 tests/test_chat_agent_model_http.py 与 tests/test_chat_reasoning_selection.py 中的 monkeypatch.setattr("loopx.chat_providers.codex_model_options", ...) 字符串路径也全部同步为 "loopx.chat.providers.codex_model_options"。

对主干的风险 / Risks

  • 全仓残留引用与负向/反事实检查(PASS):在独立干净工作树中(重装可编辑 loopx 确认 loopx.__file__ 与 loopx.chat.__path__ 指向当前 PR 检出目录后),对全仓执行 rg -n "\bchat_(acp|endpoints|providers)\b" 验证零残留旧路径调用或字符串 monkeypatch;Python 负向检查确认 importlib.util.find_spec 对 loopx.chat_acp、loopx.chat_endpoints 与 loopx.chat_providers 均返回 None;AgentEndpointRegistry 实测拒绝保留 ID "codex" 并允许正常端点写入/列表,loopx.cli chat-endpoint list 返回空列表 JSON(ok: true)。
  • 验证矩阵与覆盖边界(PASS):
    • 架构与 Chat 定向 pytest(21 个文件):1120 passed, 6 skipped in 532.97s(6 项 skipped 为 tests/control_plane/test_installed_core_context.py 需外部 LOOPX_CORE_TEST_PYTHON 环境的用例)。
    • 本地真实入口 smoke:examples/loopx-chat-acp-adapter-smoke.py(ok)、examples/loopx-chat-provider-adapters-smoke.py(ok)、与构建仪表盘资源后的 examples/loopx-chat-server-smoke.py(ok)全部通过;examples/personal-workspace-browser/first-goal-agent-unavailable.mjs 通过 node --check。
    • 静态与公开边界检查:ruff check(22 个 .py 文件全通过)、mypy(pyproject.toml 17 个 strict 文件全通过)、scripts/check_rfc_bilingual.py --base origin/main --head HEAD 通过、git diff --check 通过、loopx check(25 个文件 errors=0)通过、canary premerge 在隔离 HOME 下 6/6 直接检查 + 10/10 目录 canary + 8/8 风险 smoke + 1/1 边界检查全部 PASS。
  • 并发批次与分支推进观察(非阻断):审查期间 origin/main 已合入 PR #9193 推进至 202d7bdb05,致使 canary premerge 相对最新 origin/main 的 scope_fingerprint 未命中作者先前在 db76a91f0c 记录的 CQR(cqr_62b712366d71f399f220),但 #9193 与本 PR 零文件重叠,GitHub 状态仍为 MERGEABLE(BEHIND)。另 top_level_module_budget.json 的 baseline_commit 记录为 00f47ed364(db76a91f0c^1,顶层模块同样为 122 个),与并行的 PR #9179 合入其中之一后,后合入方只需按合并后计数(119 -> 116)与 test_chat_internal_module_layout.py / chat_runtime.py 重演单行 rebase 即可。

我的整体评价 / Verdict

本 PR 为 justified_increment:严格遵循 #5072 / monorepo-distribution-split-v0.md 的 M1 与 I3 规则,在不改变任何运行时或对外契约的前提下完成 3 个内部 Chat 叶子模块归位与预算棘轮下调。

  • Long-horizon(improved):loopx/ 顶层模块从 122 稳定降至 119 且禁止顶层兼容 shim 回流,降低了后续分包重构与调用方定位的长期维护成本。
  • User experience(preserved)与 Visual review(not_applicable):本次仅调整内部 Python 模块布局、测试导入与文档引用,不涉及前端 UI 组件或视觉呈现改动(已核对 loopx/chat/acp.py、loopx/chat/endpoints.py、loopx/chat/providers.py 与 examples/personal-workspace-browser/first-goal-agent-unavailable.mjs,unverified_scope: none)。
  • 语义词表与兼容决策:未新增、扩展或改变任何状态枚举或协议字段(semantic_alignment: not_applicable);compatibility_assessment 为 not_applicable(纯内部模块,无公开重导出);observable_semantics 与 default_off_isolation 均验证等价/不适用(equivalent / not_applicable)。
  • Exact-head freshness:复核远端 HEAD 仍为 993ecae82ddf0b19185e8e99e4468a1788e181c4(OPEN、MERGEABLE、wait_for_ci: false),全部本地定向测试、smoke 与静态边界检查均已在该精确 head 独立跑通。

English verdict: APPROVE at exact head 993ecae (published as COMMENTED review because PR #9196 is author-owned; 3 internal Chat leaf modules moved cleanly to loopx/chat/{acp,endpoints,providers}.py with zero shims, all callers/monkeypatches/smokes updated, top_level_module_budget ratcheted 122 -> 119, 1120 pytest cases + 3 chat smokes + ruff + mypy + canary premerge 19/19 PASS).

@mergify

mergify Bot commented Nov 21, 2026

Copy link
Copy Markdown

This pull request has merge conflicts with main and cannot be merged
until they are resolved. Please rebase or merge the base branch, @loopx-agent.

Choose the remote for the base repository, not an out-of-date fork.
For a fork clone, first inspect git remote -v; upstream must point
to https://github.com/loopx-project/loopx.git. If it is absent, add it
with git remote add upstream https://github.com/loopx-project/loopx.git.
Then run:

git fetch upstream
git rebase upstream/main
# Resolve each conflict, git add the resolved files, then git rebase --continue.
git push --force-with-lease origin HEAD

For a same-repository clone whose origin points to
https://github.com/loopx-project/loopx.git, use origin instead of
upstream for fetch/rebase. If you prefer merging the base, use
git merge <base-remote>/main and push normally.

Keep the DCO Signed-off-by trailer on every commit when you rebase.
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 21, 2026

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

动机 / Motivation

维护者正在按 M1 迁移 Chat 内部模块,每批还要通过顶层实际数量门禁。 #5072 将可兼容迁移和精确模块计数绑定在同一 PR,避免为降低表面数字留出新增长空间。 当前 main 有 121 个顶层 Python 模块,合入本提案的三个搬迁后实际为 118。临时整合树只选择主干的 121 或提案的 119 作为预算时,原精确计数测试均失败。把预算改为实测 118 后,预算与模块布局合计 9 项通过。 这批把 ACP、端点登记和 provider 适配迁进 loopx.chat,更新内建调用点。源分支固定的 119 对应旧分叉。 本轮只核验 M1 的三个模块和兼容边界。剩余 Chat 模块与发行分包仍由 #5072 跟踪。

改动思路 / Approach

保留原 Chat 架构与接口责任,更新相对导入和已有启动路径。 内部模块从同一分发包重新归位。公开命令、配置和效果所有者仍沿现有入口。 整合时只需在现有精确计数 owner 设置实际数值,现有生产模块的组合可保留。

具体改动 / Changes

逐项检查当前头 993ecae 和 merge base db76a91,25 个文件,+50/-39。主干 a6ffb3b 的合并预演只在模块预算 fixture 有内容冲突。其余生产文件由 Git 自动整合。我分别用两侧 fixture 跑了同一项门禁,再在临时树按实测值对照。 评审依据为 a6ffb3b。 目标规范

  • m1-chat-leaf-relocation · Move internal ACP, endpoint, and provider modules into the existing Chat package.
  • i3-active-callers · Preserve established public interfaces and update existing internal callers with no stale imports.
  • current-main-module-budget · Pin the real merged top-level count after the three moves.

关键代码讲解

  • ACP 适配 更新分包后的同层与上层引用。
  • 端点登记 复用原 JSON 写入与执行登记。
  • 会话入口 继续通过同一 provider 和 ACP 会话路径。
  • 预算 提案保存旧分叉下测出的 119。

对主干的风险 / Risks

[P2] 当前主干整合的精确模块预算应为 118。 在当前 main 上重基并把预算更新到实际的 118,保留现有 allowlist。用同一提交重跑准确计数、内部导入和包边界。 选择任一冲突侧都会使 mandatory architecture gate 失败。无需扩大迁移范围即可恢复。

分叉基线有 122 个顶层模块,提案准确头有 119。该头通过 110 项定向 Python 测试及本地 quick premerge,覆盖无旧 shim 的布局、ACP 启动、端点和聊天配置。 隔离 Core wheel 的命令帮助在无 Node 的 PATH 可启动。 重建标准 wheel 后,三个新模块均由已安装包加载,ACP stdio 和 provider fixture 实跑通过。 整合树使用主干值和提案值时分别为 1 项失败、5 项通过。按同一生产树实际数量收紧后,预算和布局 9 项通过。 临时整合只用于验证。远端 PR 分支仍含内容冲突。

我的整体评价 / Verdict

请求修改。保留原 Chat 架构与接口责任,更新相对导入和已有启动路径。 内部模块从同一分发包重新归位。公开命令、配置和效果所有者仍沿现有入口。 搬迁可在旧分叉基线上通过,当前分支的规范预算和主干组合仍待提交。 请在新基线记录整合后的精确预算,并在不改动 MCP、provider 或 Chat 权限的前提下复验同一头。

English verdict: REQUEST_CHANGES at 993ecae. The exact relocation passes focused Chat tests. Current main plus these moves contains 118 top-level modules. The architecture gate fails with either side's conflicting budget and passes when the integrated budget is set to the measured count.

…hat and ratchet module budget

Implements the next monorepo-distribution-split-v0 (#5072) M1 internal leaf migration batch without permanent top-level compatibility shims:

- Move loopx/chat_acp.py -> loopx/chat/acp.py
- Move loopx/chat_endpoints.py -> loopx/chat/endpoints.py
- Move loopx/chat_providers.py -> loopx/chat/providers.py
- Update internal relative imports, callers, tests, smokes, layout guards, and kiro_cli_goal_mode references
- Ratchet tests/architecture/top_level_module_budget.json from 118 to 115 at baseline 4052e3f

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
@loopx-agent
loopx-agent force-pushed the codex/chat-leaf-colocate-batch2-20261121 branch from 993ecae to fc76e46 Compare November 22, 2026 00:23
@mergify mergify Bot removed the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 22, 2026

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · Gemini · Google · self_reported

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

本次针对精确头 fc76e46fcb72dfc3574fbaa2ec0e5e6906e1316a 执行独立复审,核验了前一轮(993ecae82d)[P2] 顶层模块预算滞后问题(thread PRRT_kwDOStEbEs66auIk 所在问题已通过 rebase 至 #9179 合入后的 4052e3ffd2 并将预算更新为 115 解决),结论为 无未决阻塞项,建议通过(APPROVE)。

动机 / Motivation

受影响的调用方与维护者包括 LoopX Chat 运行时(ChatRuntimeController 与会话打开入口 open_chat_session)、原生模型配置模块(model_settings)、CLI 命令 loopx chat-endpoint,以及推进 loopx-core 与工作区拆分的仓库维护者。

搬迁前,loopx/chat_acp.py、loopx/chat_endpoints.py 与 loopx/chat_providers.py 三个仅服务内部 Chat 传输、本地端点登记与模型 provider 适配的叶子模块散落在 loopx/ 顶层,使包顶层仍保留 118 个平铺 .py 文件、模块归属不清且每次新增拆分批次都需要与顶层预算竞争;搬迁后,三者通过 git mv 并入 loopx/chat/{acp,endpoints,providers}.py,同步切换全仓 25 个文件内的导入、monkeypatch 目标、smoke 与注释,删除旧顶层模块且不留兼容 shim,并将顶层模块预算从 118 精确下调至 115(实测 loopx/*.py 为 115 个)。

在精确头 fc76e46fcb72dfc3574fbaa2ec0e5e6906e1316a 上,loopx/*.py 数量实测为 115 个且与 tests/architecture/top_level_module_budget.json 一致,旧模块名 loopx.chat_acp、loopx.chat_endpoints、loopx.chat_providers 的 importlib.util.find_spec 均返回 None;同时 ACPStdioAdapter、AgentEndpointRegistry(含 0o600 持久化写入)与 ClaudeCodeAdapter 从 loopx.chat.* 加载且 CLI chat-endpoint、模型设置与 3 个离线 Chat smoke 行为与基线一致。

本 PR 不改动 ACP 协议协商、provider 模型路由、端点注册表 schema、权限边界或会话持久化语义,也不搬迁受 loopx-core 安装边界测试 pins 约束的 loopx/chat_action_store.py 或其余待拆 chat_*.py 模块。

loopx/ 顶层仍保留 chat_action_store.py 等其余待迁移 chat_*.py 模块(受 tests/control_plane/test_installed_core_context.py 与 packages/loopx-core/prepare.py 边界约束留待 #5072 后续独立批次),且浏览器端到端脚本 examples/personal-workspace-browser/first-goal-agent-unavailable.mjs 仅完成语法检查而未运行完整 Playwright 浏览器链路;此外当前分支相对 main(77af2b21f54329c837912e084f8d581ad519d92e)处于 BEHIND(无文本或计数冲突)。

改动思路 / Approach

将仅在内部消费的 ACP stdio 适配器、本地端点注册表与 Claude/直连模型适配层直接迁入已有 loopx/chat/ 命名空间(由 loopx/chat.py 的 __path__ 承载)并删除顶层旧文件,复用现有单向预算棘轮与布局测试 owner,不引入额外兼容 shim、桥接开关或状态副本,在行为零漂移前提下实现可独立验证、可整批回退的结构减法。

当前 PR 边界仅覆盖 chat_acp.py、chat_endpoints.py、chat_providers.py 三枚内部 Chat 叶子模块迁入 loopx/chat/、全仓内部调用方/测试/smoke/注释同步以及 top_level_module_budget.json(118 → 115)与 test_chat_internal_module_layout.py 更新,刻意将 chat_action_store.py 及后续 M1/M2 分包迁移留归 #5072 后续独立批次。

架构所有者判定与机制分解:在职责划分上,loopx.chat 由 loopx/chat.py 继续作为公共包入口并通过 __path__ 挂载 loopx/chat/ 内部子模块,未引入 loopx/chat/__init__.py,因此既不改变外部 import loopx.chat 语义,又把 3 个仅服务内部传输、端点持久化与 provider 适配的模块收拢到统一子树;packages/loopx-core/prepare.py 对 loopx/chat/ 与 loopx/chat_*.py 均持排除策略,搬迁前后分包隔离边界完全等价。对于为何不纳入 loopx/chat_action_store.py,已核实 tests/control_plane/test_installed_core_context.py 与 packages/loopx-core/prepare.py 显式依赖其顶层分发边界,留在后续批次处理是最小风险选择。

迁移前 (4052e3ffd2, top-level 118):
  chat_runtime / chat.session_open / model_settings / support_control_chat_endpoint
     ──▶ loopx.chat_acp / loopx.chat_endpoints / loopx.chat_providers

迁移后 (fc76e46fcb, top-level 115, 旧路径 find_spec=None):
  chat_runtime / chat.session_open / model_settings / support_control_chat_endpoint
     ──▶ loopx.chat.acp / loopx.chat.endpoints / loopx.chat.providers

上表为基于源码导入关系的示意对比(非运行期证明);所有变更均由相对/包内路径导入与架构门禁实测支撑。

具体改动 / Changes

依据规范 docs/architecture/rfcs/monorepo-distribution-split-v0.md(固定修订 16f418837c87ab40f04ff303962598f5bd71a034)逐条核对当前头 fc76e46fcb72dfc3574fbaa2ec0e5e6906e1316a(25 个文件,+50/-39):

  • M1(implemented):通过 git mv 将 loopx/chat_acp.py、loopx/chat_endpoints.py、loopx/chat_providers.py 移入 loopx/chat/acp.py、loopx/chat/endpoints.py、loopx/chat/providers.py,并将模块内原本的平级相对导入(.chat、.chat_agent、.chat_store、.file_lock、.kiro_cli_goal_mode)同步调整为上一级包相对导入(..*),由 tests/test_chat_internal_module_layout.py 断言三者 __module__ 均归属于 loopx.chat.*。
  • I3(implemented):核查全仓 git grep 结果与 loopx/__init__.py / loopx/chat.py,确认这 3 个模块无对外公开重导出;同步更新生产调用方(loopx/chat/session_open.py、loopx/chat_runtime.py、loopx/capabilities/native_chat/model_settings.py、loopx/cli_commands/support_control_chat_endpoint.py)、loopx/kiro_cli_goal_mode/ 注释与 README、8 个测试文件(含 monkeypatch.setattr("loopx.chat.providers.codex_model_options", ...) 字符串路径)、3 个 Python smoke 与 1 个浏览器 smoke 脚本,未保留顶层兼容 shim。
  • S9-R1(implemented):在 tests/architecture/top_level_module_budget.json 将 baseline_commit 更新为 rebase 基线 4052e3ffd24decd03680abcc79de1b956c6f5ba1、将 max_top_level_modules 从 118 精确下调 3 至 115(保留 allowlist 为 ["__init__.py", "entrypoint.py", "cli.py"]),同时在 test_chat_internal_module_layout.py 完整保留 #9179 已合入叶子的无 shim 断言并追加本批 3 个旧路径 find_spec(...) is None 校验。

关键代码讲解

  • ACPStdioAdapter:迁入 loopx/chat/acp.py 后将内部依赖切换为 ..chat 与 ..chat_agent,继续承担 ACP v1 stdio 进程启动、协议初始化(initialize/initialized、session/new/session/resume/session/load)及空闲/硬超时控制;由 session_open._start_acp_adapter 与 model_settings.observed_model_settings 直接消费,超时/断流统一抛出 CodexChatAgentError / CodexChatTimeoutError 并经 _terminate() 先关 stdin EOF 再温和退出。
  • AgentEndpointRegistry:迁入 loopx/chat/endpoints.py 后改用 ..chat_store、..file_lock 与 ..kiro_cli_goal_mode,在 upsert/delete 写路径保持 exclusive_file_lock 与 0o600 文件 / 0o700 目录原子写权限,并保留 RESERVED_AGENT_IDS 冲突拒绝分支;被 ChatRuntimeController 与 handle_chat_endpoint_command 调用。
  • ClaudeCodeAdapter 与 codex_model_options:迁入 loopx/chat/providers.py 后切换为 ..chat 与 ..chat_agent,保持 ClaudeCodeAdapter.start(含不可用时 _provider_error、tool_scope 校验)与 direct_model_from_environment(ANTHROPIC_API_KEY/OPENAI_API_KEY 缺失即 fail-closed)语义不变;由 session_open._start_adapter 与 model_settings.{inspect_agent_model_options,configure_session_model} 调用。
  • observed_model_settings 与 inspect_agent_model_options:将函数内局部导入同步更新为 from ...chat import providers 与 from ...chat.acp import ACPStdioAdapter,确保对自定义 ACP 端点模型/推理强度回读的 isinstance(..., ACPStdioAdapter) 检查与 Codex 模型目录校验继续命中同一个真实类对象而不会静默跳过。
  • open_chat_session / _start_adapter:使用同包相对导入 .acp.ACPStdioAdapter 与 .providers.{ClaudeCodeAdapter, direct_model_from_environment},保持会话创建/恢复/provider 不可用拒绝对外路径与错误码完全等价。

对主干的风险 / Risks

对基线(4052e3ffd2)与当前远端主干(77af2b21f54329c837912e084f8d581ad519d92e)的对照检查显示,整体主干回归风险低,未发现阻塞项:

  1. 已解决的前置 [P2] 预算滞后风险:前一提交 993ecae82d 未包含 #9179 的减法更新(当时主干由 121 降至 118),导致合入冲突。本次精确头 fc76e46fcb72dfc3574fbaa2ec0e5e6906e1316a 已基于 4052e3ffd2 干净重基并将 max_top_level_modules 设为 115;同时实测当前 origin/main(77af2b21f54329c837912e084f8d581ad519d92e,含 #9198 workbench 改动)顶层 loopx/*.py 仍为 118 且未新增任何 chat_acp/chat_endpoints/chat_providers 引用,本地只读 git merge-tree origin/main HEAD 干净无冲突且合并树顶层模块数精确为 115。
  2. 动态导入与 monkeypatch 路径一致性风险:若遗漏任意字符串形式的 monkeypatch.setattr("loopx.chat_providers...") 或函数内局部导入,运行期将在 inspect_agent_model_options / configure_session_model / observed_model_settings 或测试中触发 ModuleNotFoundError。全仓 git grep 已证实除 test_chat_internal_module_layout.py 的负向断言外不存在旧模块引用,且正反向导入探针(find_spec 对 3 个旧名均为 None,新路径导入与 __module__ 均正确)及 17 个架构/Chat 测试文件共 821 项在基线与精确头全部通过(821 passed)。
  3. 残余风险与未覆盖边界:目标分支相对 origin/main 为 BEHIND(虽经 merge-tree 确认无冲突);examples/personal-workspace-browser/first-goal-agent-unavailable.mjs 仅执行了 node --check 语法校验,未跑真实 Playwright 浏览器会话;按 Goal 策略未查询远端 GitHub CI(wait_for_ci: false)。

独立本地验证清单(全部运行于隔离评审工作树 fc76e46fcb72dfc3574fbaa2ec0e5e6906e1316a):

  • 顶层计数与合入树核验(PASS):ls -1 loopx/*.py | wc -l == 115(基线 4052e3ffd2 与 origin/main 均为 118);git merge-tree origin/main HEAD 干净且合并树顶层 .py 为 115。
  • 架构与 Chat 定向 pytest(PASS):覆盖 test_top_level_module_budget.py、test_control_plane_import_boundaries.py、test_package_kernel_import_ratchet.py、test_chat_internal_module_layout.py 及 13 个关联 Chat/端点/ACP 测试文件,精确头 821 passed in 15.64s(基线 4052e3ffd2 对等运行 821 passed in 18.02s)。
  • CLI 与持久化真实路径对照(PASS):基线与精确头分别在隔离目录执行 loopx chat-endpoint add/list/remove,endpoints.json 权限均为 0o600、JSON schema 与输出完全一致。
  • 代码质量、类型与脚本校验(PASS):22 个改动 Python 文件 ruff check 0 错误;python -m mypy(配置 17 个严格检查文件)Success: no issues found(另对 8 个改动 loopx/*.py 运行 --follow-imports=silent 显示 56 条既有未标注/Protocol 错误,与基线 4052e3ffd2 完全一致、未引入新错误);check_rfc_bilingual.py、git diff --check、node --check 全部通过。
  • Chat 与 Pre-Merge Smoke(PASS):3 个 Chat smoke(loopx-chat-acp-adapter-smoke.py、loopx-chat-provider-adapters-smoke.py、以及在隔离工作树构建前端产物后运行的 loopx-chat-server-smoke.py)全部通过;loopx check --scan-path ...(25 文件)0 errors / 0 warnings;loopx canary premerge --from-git-diff --git-diff-base origin/main 通过(19/19 选定检查全过:10/10 catalog canaries、8/8 risk-profile smokes、1/1 public boundary)。
  • 远端 GitHub CI(UNVERIFIED,诊断记录 required=false):未向分支上报 status check rollup;按仓库 Goal 策略 wait_for_ci: false(ci_policy: not_consulted),本地全套架构门禁、定向单测、CLI 真实路径与 canary premerge 已完整覆盖变更不变量。

我的整体评价 / Verdict

从 长程任务连续性(long_horizon) 与 用户体验(user_experience) 两个维度评估,两者均 保持等价(preserved):会话创建、恢复、ACP 超时保护、本地端点注册与模型设置热切换的行为、错误码和持久化结构未发生变化;因本 PR 仅涉及内部模块目录整理与预算棘轮、不更改任何渲染界面或交互文案,视觉评审(visual_review)判定为 not_applicable(unverified_scope: none,仅浏览器脚本 first-goal-agent-unavailable.mjs 未做实机渲染复跑但核心 UI 未修改)。

在可观测语义(observable_semantics)上,基线 4052e3ffd2 与精确头 fc76e46fcb72dfc3574fbaa2ec0e5e6906e1316a 对同一 chat-endpoint CLI 请求、文件权限(0o600)、端点注册表 schema、Chat/ACP 测试矩阵与 3 个 smoke 输出完全一致(唯一预期变化是 3 个内部模块名从 loopx.chat_* 迁至 loopx.chat.* 且旧路径无 shim)。在代码体积与架构评估上,50 行新增 / 39 行删减全部属于路径调整、包边界测试与预算棘轮,无新增兼容层或控制面状态;按 monorepo-distribution-split-v0.md 既有词汇与 loopx_top_level_module_budget_v0 契约复用执行(reuse_existing),无需新增 RFC 或词汇注册。当前精确头 fc76e46fcb72dfc3574fbaa2ec0e5e6906e1316a 已完整解决前置 [P2] 预算问题且全部独立验证通过,建议批准。

English verdict: APPROVE at fc76e46. The PR cleanly relocates three internal Chat leaf modules under loopx/chat/, updates all callers and tests without shims, lowers max_top_level_modules to 115 after the #9179 rebase, and passes local architecture, Chat pytest (821 passed), CLI parity, mypy/ruff, all three Chat smokes, and canary premerge (19/19 checks).

@loopx-agent
loopx-agent merged commit eb49d6a into main Nov 22, 2026
22 of 64 checks passed
@loopx-agent
loopx-agent deleted the codex/chat-leaf-colocate-batch2-20261121 branch November 22, 2026 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant