Skip to content

refactor(bootstrap): extract renderers, deduplicate CLI builders, and retire 2000-line ceiling - #8891

Open
loopx-agent wants to merge 1 commit into
mainfrom
codex/bootstrap-command-pack-slim-20261117
Open

loopx-agent wants to merge 1 commit into
mainfrom
codex/bootstrap-command-pack-slim-20261117

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Summary

Refactors and slims loopx/bootstrap_command_pack.py from 2,137 lines down to 1,792 lines (-345 lines, removing its lines: 2240 baseline waiver and tightening any_count from 32 to 26 in loopx/canary/module_metric_baseline.json), with a net-negative repository diff (-72 lines overall: 453 insertions(+), 525 deletions(-)):

  1. Extract pure presentation renderers to loopx/presentation/renderers/start_goal_markdown.py (215 -> 489 lines):
    • Moved render_loopx_bootstrap_command_pack_message and render_loopx_bootstrap_command_pack_markdown alongside render_start_goal_guided_markdown, consolidating repeated isinstance(..., dict) extraction via _dict_field.
    • Re-exported all moved symbols and CANONICAL_SLASH_COMMAND in loopx/bootstrap_command_pack.py so existing imports remain intact.
  2. Deduplicate CLI builders & contract templates in loopx/bootstrap_command_pack.py:
    • Consolidated _start_goal_detail_command, rerun_command_for, detail_command, rerun_command, and canonical_cli_command onto shared _start_goal_common_tail + _start_goal_command.
    • Extracted shared _SLASH_FORMS, _PRESERVE_TODOS_POLICY, and explicitly typed _guided_safety_contract.
  3. Retire oversized module ceiling in loopx/canary/module_metric_baseline.json:
    • Deleted the "lines": 2240 exemption for loopx/bootstrap_command_pack.py (now 1,792 lines, under the default 2,000-line limit) and lowered its "any_count" ceiling from 32 to 26.

Verification (run from worktree at commit fd3e470153)

Check Command Outcome
Python lint uv run --extra test ruff check loopx/bootstrap_command_pack.py loopx/presentation/renderers/start_goal_markdown.py tests loopx/canary loopx/control_plane loopx/domain_packs loopx/presentation All checks passed!
Maintainability ratchet uv run --extra test python examples/control_plane/control-plane-maintainability-ratchet-smoke.py Passed (unreviewed: 0, magnitude_regressions: 0)
Semantic vocabulary drift uv run --extra test python examples/semantic-vocabulary-drift-smoke.py Passed (semantic-vocabulary-drift-smoke: ok)
Canary planner smoke uv run --extra test python examples/canary/catalog-planner-smoke.py catalog-canary-planner-smoke ok
Targeted pytest (12 suites) uv run --extra test python -m pytest -q --no-cov tests/canary/test_maintainability_ratchet.py tests/control_plane/test_m6_quality_gates.py tests/architecture/test_progress_scope_owner.py tests/architecture/test_top_level_module_budget.py tests/control_plane/test_start_goal_compact_projection.py tests/control_plane/test_start_goal_orphaned_goal_state.py tests/test_bootstrap_command_pack_platform.py tests/test_host_loop_activation.py tests/control_plane/test_effect_program_ordered_steps.py tests/control_plane/test_fine_grained_turn_mode.py tests/control_plane/test_quota_settlement_cli.py tests/control_plane/test_goal_objective_projection.py 469 passed, 1 skipped
Public boundary scan uv run --extra test loopx check --scan-path ... Passed (ok: true, errors: 0, public boundary scan clean: 3 files)

… retire 2000-line ceiling

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
@loopx-agent
loopx-agent force-pushed the codex/bootstrap-command-pack-slim-20261117 branch from fd3e470 to a34b81b Compare November 17, 2026 05:19

@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)

已针对 PR #8891 远端实际 exact head a34b81b8683d9e01cc0cd1fd76e61ce60735c797 完成完整源码逐行核对与本地实跑验证(审查结论:APPROVE,无 P0/P1/P2 阻断问题)。

动机 / Motivation

受影响调用方与维护者:调用 /loopx 引导与命令包生成路径的所有 CLI 与宿主接入方(loopx/cli_commands/start_goal.py、loopx/cli_commands/starter_bootstrap.py、loopx/bootstrap_command_pack.py 与 loopx/presentation/renderers/start_goal_markdown.py),以及 loopx/canary/ 可维护性棘轮维护者。

修改前(d210e4cc1d):loopx/bootstrap_command_pack.py 达 2,137 行(32 处 Any、lines: 2240 棘轮豁免),将 render_loopx_bootstrap_command_pack_message、render_loopx_bootstrap_command_pack_markdown 与 CANONICAL_SLASH_COMMAND 混置于包构建逻辑中,并在多处引导包构造器内重复拼接 start-goal --guided 参数串与 slash_forms、preserve_todos_policy、safety_contract 模板。修改后(a34b81b868):纯 Markdown 渲染器迁入既有的 loopx/presentation/renderers/start_goal_markdown.py(215 -> 489 行,any_count=9)并复用 _dict_field,loopx/bootstrap_command_pack.py 降至 1,792 行(-345 行,any_count 降至 26)并退役 2,240 行棘轮豁免,全仓 3 个修改文件净减 72 行(+453/-525)。

可观测结果:module_metrics 实测 loopx/bootstrap_command_pack.py 为 {'lines': 1792, 'any_count': 26, 'dict_any_count': 0}、loopx/presentation/renderers/start_goal_markdown.py 为 {'lines': 489, 'any_count': 9, 'dict_any_count': 0};Python 运行时身份断言确认全部 4 个重导出符号与 start_goal_markdown.py 原对象同一(is);12 个非重叠 pytest 套件共 475 passed, 1 skipped(其中唯一 skip 为非 Windows 平台条件跳过 test_bootstrap_command_pack_platform.py:163);未对齐 #8867 的 examples/bootstrap-command-pack-smoke.py:357 在基线 d210e4cc1d 与本 PR a34b81b868 上均以完全相同的兼容性断言失败(对齐 #8867 规则后全脚本通过并输出 bootstrap command pack smoke passed);ruff、mypy(17 文件)、control-plane-maintainability-ratchet、catalog-planner-smoke、canary premerge --tier quick 与 loopx check 均全绿通过。

非目标边界:本 PR 仅将既有 bootstrap Markdown 渲染器迁入 loopx/presentation/renderers/start_goal_markdown.py、合并本地 CLI 命令串与策略字典构造并退役 2,240 行棘轮豁免,通过 loopx/bootstrap_command_pack.py 显式重导出保留全部调用方导入兼容,不改变任何 JSON Schema、Markdown 文案、CLI 标志或引导事务规则,亦不顺带合入主干在基线之后才合入的 #8867 smoke 兼容调整或 #8910 TS 消费者清单更新,也不授予自动合入权限。

改动思路 / Approach

本次重构直接复用既有表现层所有者 loopx/presentation/renderers/start_goal_markdown.py 收口全部 start-goal 与 bootstrap Markdown 渲染器(通过 _dict_field 消除重复字典校验样板),并在 loopx/bootstrap_command_pack.py 保留显式重导出以零改动兼容 starter_bootstrap.py 与全部调用方;CLI 命令串与策略模板则收口到模块内 _start_goal_common_tail、_start_goal_command、_slash_forms、_PRESERVE_TODOS_POLICY 与 _guided_safety_contract,避免新建平行模块或改变任何外部行为。

当前 PR 边界:改动严格收敛于 loopx/bootstrap_command_pack.py、loopx/presentation/renderers/start_goal_markdown.py 与 loopx/canary/module_metric_baseline.json 3 个文件;d210e4cc1d 基线之后合入主干的 #8867 smoke 兼容断言调整与 #8910 TS 消费者清单更新保持独立合并刷新边界。

  • 渲染器统一归位与字段提取收敛(loopx/presentation/renderers/start_goal_markdown.py:14-489):将 CANONICAL_SLASH_COMMAND、render_loopx_bootstrap_command_pack_message 与 render_loopx_bootstrap_command_pack_markdown 迁至 render_start_goal_guided_markdown 同模块,使用 _dict_field 统一替代原先散落的 isinstance(..., dict) 样板,保留全部 Markdown 模板文本、分支顺序与 ORPHANED_GOAL_STATE_CONNECTION 围栏路由一字不变。
  • 显式重导出与 CLI 构造去重(loopx/bootstrap_command_pack.py:36-41,224-321,423-478,1006-1020,1192-1206,1342-1356,1715-1730):在 bootstrap_command_pack.py 保留 4 个符号的显式 as 重导出,删去 _start_goal_detail_command、rerun_command_for、detail_command 与多目标 rerun_command 重复拼接逻辑,由 _start_goal_common_tail 与 _start_goal_command 精确覆盖 include_format_json、host_surface=None、display_name 与 include_command_pack_detail 各可选标志组合,并用 _slash_forms()、_PRESERVE_TODOS_POLICY 与 _guided_safety_contract 保证每次返回独立字典副本。
  • 棘轮豁免退役(loopx/canary/module_metric_baseline.json:7-11):移除 loopx/bootstrap_command_pack.py 的 "lines": 2240 豁免并将其 "any_count" 上限自 32 收紧至 26;迁移后的 start_goal_markdown.py 实测 489 行、any_count=9,远低于默认 2,000 行与 300 Any 上限。

具体改动 / Changes

本次完整 diff 覆盖 3 个文件(453 insertions(+), 525 deletions(-),整体净减 72 行):

  1. loopx/presentation/renderers/start_goal_markdown.py(+303 / -29,215 -> 489 行,any_count=9):新增 _dict_field 辅助并迁入 CANONICAL_SLASH_COMMAND、render_loopx_bootstrap_command_pack_message 与 render_loopx_bootstrap_command_pack_markdown。
  2. loopx/bootstrap_command_pack.py(+148 / -493,2,137 -> 1,792 行,32 Any -> 26):保留渲染器显式重导出、清理无用导入,抽离 _SLASH_FORMS/_slash_forms、_PRESERVE_TODOS_POLICY、_guided_safety_contract、_start_goal_common_tail 与增强版 _start_goal_command。
  3. loopx/canary/module_metric_baseline.json(+2 / -3,L7-11):删除 loopx/bootstrap_command_pack.py 的 "lines": 2240 豁免并下调 "any_count": 26。

对主干的风险 / Risks

  • 调用方导入与主干合并兼容性:全仓检索并实测 loopx.cli_commands.start_goal、loopx.cli_commands.starter_bootstrap 与相关单测套件均正常解析;git merge-tree --write-tree 确认与当前 origin/main(6844005820)无任何冲突,且 bootstrap_command_pack.py 在 d210e4cc1d..6844005820 间未受其他 PR 改动。
  • 基线滞后导致的诊断性差异归因:PR 基线 d210e4cc1d 早于主干已合入的 #8867(377bd86c9b)与 #8910(0514512ee7),因此在基线 d210e4cc1d 与本 PR 上未修改的 examples/bootstrap-command-pack-smoke.py:357 均会以完全相同的 compact_projection_default 断言失败(对齐 #8867 规则后全脚本通过),远端 typescript-core (2/3) 与本地 node --test tests/control_plane_ts/content_digest_single_owner.test.ts:908 亦复现基线既有 + 'control_plane/quota/settlement_readback.ts' 消费者清单差异,均与本 PR Python 重构无关。
  • 本地完整验证结果(exact head a34b81b8683d9e01cc0cd1fd76e61ce60735c797):
    • module_metrics: loopx/bootstrap_command_pack.py (lines=1792, any_count=26, dict_any_count=0), loopx/presentation/renderers/start_goal_markdown.py (lines=489, any_count=9, dict_any_count=0)
    • uv run --extra test ruff check ...(改动与关联 CLI/测试文件): All checks passed!;uv run --extra test mypy: Success: no issues found in 17 source files
    • pytest(12 个非重叠套件共 475 passed, 1 skipped):test_maintainability_ratchet.py + test_top_level_module_budget.py + test_progress_scope_owner.py 29 passed in 11.23s;9 个 bootstrap/start-goal/effect-program/quota/m6 套件 446 passed, 1 skipped in 514.79s(唯一 skip 为 test_bootstrap_command_pack_platform.py:163 Windows PowerShell 7 平台跳过)
    • examples/control_plane/control-plane-maintainability-ratchet-smoke.py: control-plane-maintainability-ratchet: ok(unreviewed=0, stale_exceptions=0, magnitude_regressions=0)
    • examples/canary/catalog-planner-smoke.py: catalog-canary-planner-smoke ok
    • uv run --extra test loopx canary premerge --tier quick --from-git-diff --git-diff-base d210e4cc1d002f92498b2811c565b9430e79f4c1: passed(ok=true, selected=3, failures=0, manual_holds=0)
    • uv run --extra test loopx check --scan-path ...: ok=True (errors=0, warnings=0)

我的整体评价 / Verdict

  • Long-horizon 影响:improved — 彻底退役 bootstrap_command_pack.py 的 2,240 行豁免并收紧 any_count 至 26,将全部 start-goal/bootstrap Markdown 渲染器与 CLI 构造器统一到单一规范路径。
  • User-experience 影响:preserved — 保留全部 JSON 字段、Markdown 文案、CLI 标志与模块重导出契约;visual_review 为 not_applicable(无前端 UI 改动)。
  • 可观测语义 / 复用 / 词表:observable_semantics 与 decision_text_assessment 均为 equivalent,repository_reuse 为 reused,authority_semantics 与 semantic_alignment 均为 aligned(candidate_decision="reuse_existing")。

改动干净收敛、12 个相关 pytest 套件 475 passed 与 premerge quick 等全部通过、无 P0/P1/P2 阻断项。本 PR 为作者自有且触及 loopx/** 核心模块,正式合入前需刷新基线 CI 并取得维护者授权。

English verdict: APPROVE exact head a34b81b (author-owned COMMENTED approval review); relocates bootstrap Markdown renderers into start_goal_markdown.py with preserved re-exports, deduplicates CLI/template builders to shrink bootstrap_command_pack.py from 2137 to 1792 lines (retiring its 2240-line waiver, any_count 32 -> 26), and passes 475/475 executed pytest cases (1 Windows skip), ruff, mypy, maintainability ratchet, catalog planner smoke, and quick premerge canary.

This branch has not been deployed

No deployments
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