Skip to content

refactor(hosts): consolidate claude, kunluncode, and zcode packages under loopx/hosts - #9505

Open
loopx-agent wants to merge 5 commits into
mainfrom
codex/consolidate-goal-mode-into-hosts-batch2-20261127
Open

loopx-agent wants to merge 5 commits into
mainfrom
codex/consolidate-goal-mode-into-hosts-batch2-20261127

Conversation

@loopx-agent

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

Copy link
Copy Markdown
Collaborator

Goal and delivered outcome

Consolidate the second batch of host goal-mode runtime packages into loopx/hosts/ without adding legacy compatibility shims:

  • loopx/claude_goal_mode/ -> loopx/hosts/claude/ (14 files)
  • loopx/kunluncode_goal_mode/ -> loopx/hosts/kunluncode/ (9 files)
  • loopx/zcode_goal_mode/ -> loopx/hosts/zcode/ (13 files, including images/native-{error-mobile,quota-desktop}.png moved intact as exact R100 renames)

Updated all Python, TypeScript (dashboard zcode-goal data/UI + packages/dsh-loopx-plugin/src/managed-runtime.ts), package/packaging (pyproject.toml, tsconfig.control-plane.json, loopx/presentation/chat_bundle.py, loopx/semantics/goal_instance_binding_inventory_v1.json, scripts/ci/test_impact_plan.py), smoke/probe scripts, bilingual docs/RFCs, and affected tests, plus added tests/test_hosts_goal_mode_batch2_consolidation.py and updated tests/test_slash_command_install_equivalence.py. Top-level loopx/*.py remains 112.

Upgrade, CI, & Shell Migration Fixes

  1. Claude upgrade migration (bfd1e3bb52, PRRT_kwDOStEbEs68h5jk resolved): Default loopx slash-commands --install (when claude-code / all is selected, never --surface codex or --uninstall) inspects user and project Claude directories and migrates provably LoopX-owned retired loopx/claude_goal_mode/ entries in commands/loopx.md, settings.json, and project .mcp.json to loopx/hosts/claude/, leaving user permissions, env, model, custom hooks/statuslines, and unreadable files intact.
  2. KunlunCode & CI impact-plan parity (bfd1e3bb52): _is_managed_server recognizes both new and legacy server.py paths; scripts/ci/test_impact_plan.py restores the mixed loopx/web/chat/index.html + full-risk assertion.
  3. Wrapper preservation & registry codec discovery (b1b3f51f71, PRRT_kwDOStEbEs68iw4f resolved): Preserves wrapper prefixes, quotes, nested sh -c, PowerShell &, and trailing flags; _projects_from_registry_file uses registry_codec.read_activation_upgrade_registry.
  4. Unquoted shell operators & command-position matching (bd711a7df7, PRRT_kwDOStEbEs68j7z5 & PRRT_kwDOStEbEs68j7z6 resolved): Splits unquoted shell operators via _ShellToken(NamedTuple) (preserving spec_from_file_location imports without sys.modules) and inspects command execution position per segment rather than rewriting data args (printf, echo, redirections, python3 -c, command -v).
  5. Here-documents, compound clauses & fail-closed manual diagnostics (c5b6f14bb1, PRRT_kwDOStEbEs68kxW0 & PRRT_kwDOStEbEs68kxW3 resolved):
    • _consume_heredoc_bodies skips pending <<EOF / <<'EOF' / <<-EOF bodies and closing delimiters verbatim after header newlines while migrating real launchers on header lines or after closing delimiters.
    • _advance_command_wrappers and _split_command_segments handle unquoted POSIX compound clauses (if, elif, then, else, while, until, do, { ...; }, (...), case ... in pat) ...;; esac) while leaving for lists, case patterns, and quoted keyword tokens intact.
    • Dynamic/unparseable constructs (eval, env -S, unterminated quotes/heredocs, unsupported flags) stay untouched and emit manual_migration_required with explicit --scope ... --harden recovery notes through install_slash_commands.

Verification of the current head (c5b6f14bb1b74a58246f3cc33423cfd2a269d684)

Surface Observed result
Isolated dual-wheel 10-case upgrade matrix Built clean full loopx-2.4.1 wheels from baseline (9467da4187) and candidate (c5b6f14bb1) in isolated venv site-packages; verified pre-migration exit 2, ran loopx slash-commands --install from outside project roots, and verified all 9 runnable statusLine configs (ordinary, spaced env wrapper, adjacent &&, printf print-only, print-then-launch adjacent & spaced &&, quoted heredoc-only, heredoc-then-launch, if [ ... ]; then <launcher>; fi) plus /loopx status exit 0 matching baseline stdout (print_only & heredoc_only untouched verbatim; eval project cleanly surfaced manual_migration_required == 1 untouched).
Host, Claude, KunlunCode, DSH & Architecture pytest pytest -q -n 4 across test_slash_command_install.py, test_hosts_goal_mode_batch2_consolidation.py, test_claude_goal_mode_{stdio_utf8,hook_fail_closed}.py, test_claude_goal_release_qualification.py, test_kunluncode_goal_mode.py, test_dsh_goal_mode_stdio_utf8.py, test_slash_command_install_equivalence.py, and tests/architecture/: 2,102 passed (0 failed, 0 skipped); scripts/ci unittest: Ran 24 tests OK.
TypeScript & DSH plugin suites npm run typecheck:control-plane (0 errors); node --experimental-strip-types --test (zcode_* + content_digest_single_owner): 69 passed, 0 failed; packages/dsh-loopx-plugin tsc --noEmit (0) and vitest run: 16 files / 405 passed.
Lint, typing, RFC, vocab & premerge ruff check (0), mypy --follow-imports=silent --strict (install.py 0), mypy --follow-imports=silent (slash_command_install.py 0), scripts/check_rfc_bilingual.py --base origin/main --head HEAD passed, semantic-vocabulary-drift-smoke.py ok (34/34), maintainability ratchet ok=true (unreviewed_count=0), git merge-tree --write-tree origin/main HEAD clean (0 conflicts), 5/5 commits DCO-signed, top-level loopx/*.py == 112. Goal canary premerge --tier standard: 6/6 direct checks, 10/10 catalog canaries, 1/1 boundary (loopx check across 103 files), 5/8 risk-profile smokes (3 misses strictly dsh-loopx-plugin-validation.py on absent host pnpm; DSH tsc + 16/16 Vitest verified directly above), manual_hold_count=2 (R100 PNG assets).

Author declaration

Written with AI assistance (DCO sign-off preserved).

…nder loopx/hosts

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>

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

[P2] 保住既有 Claude 配置的升级路径。同一个隔离项目中,基线实际 /loopx status 和状态栏都退出 0。换装候选并运行默认更新后,项目配置还指向已移除的脚本,两条实际命令都退出 2。显式重装后均恢复退出 0。 保留兼容 launcher,或在正常更新中仅迁移可证明归属的已托管旧入口,保留用户设置。 源码

动机 / Motivation

把 Claude Code、KunlunCode 和 ZCode 的运行实现收拢到 loopx/hosts,同时保住已选择安装的宿主入口。 基线 Claude 的项目适配器把包内脚本绝对地址写到 /loopx 命令和可选状态栏。wheel 更新与项目的持久配置彼此独立。 既有 Claude Code 项目适配器用户,以及从 Python/Node、面板或命令入口使用 KunlunCode 和 ZCode 的用户。

旧地址退出后,既有项目不能查看状态,且使用可选状态栏的项目收到启动失败,直到显式重新配置。 两个完整 wheel 各自生成 Chat bundle。基线项目命令与状态栏实际退出 0。候选的新位置脚本经显式项目重装重新工作,两条退出 0,用户已有设置条目保持。 精确候选 145 项 Python 和 69 项 TypeScript 定向用例通过。配对 wheel 复验了已安装配置在普通更新的失败及显式重装恢复。 测试覆盖项目 scope、完整 wheel 与执行配置中的真实脚本。Claude 宿主 UI、宿主内 MCP 注册、KunlunCode/ZCode 本机宿主和远端 CI 未核验。 验收契约

改动思路 / Approach

该改动沿用 旧 wheel 项目安装器 → .claude 命令和设置 → 发行版升级默认 CLI → 真实状态命令及状态栏入口。这批变更迁移三种宿主资源和入口,继续用原配置写入器。Python 更新器的默认 facade 安装与 Claude 项目级 opt-in 安装各自运行。 wheel 去掉旧包后,默认 facade 刷新不刷新项目命令和状态栏。显式运行新安装器则把持久地址改到新目录。 保留现有包内稳定 launcher,或仅在所有权可证明时定向更新旧地址,复用原 scoped installer 的配置保留逻辑。

具体改动 / Changes

精确提交 581d7d1,本次对照目标 379b9ea。100 个文件,+268/−173。大部分是三种运行包、面板消费方、资源和文档路径迁移。

关键代码讲解

  • REPO_ROOT。脚本在新包路径下导入正确的共享依赖。原安装输出持久记录旧绝对路径。 源码

  • command_md。把当前包内的绝对脚本路径写入项目 /loopx 命令。 源码

  • hardening_block。显式 opt-in 时把当前包的状态栏入口记录进项目设置。 源码

  • install_slash_commands。默认更新后的 Claude facade 走主技能目录,既有项目级命令及状态栏由另一入口拥有。 源码

  • ZCode native CLI。迁移后的 ZCode 与 KunlunCode 宿主调用继续接入现有 native owners。 源码

  • persisted-claude-project-entrypoint(not_met)。既有项目显式安装的 /loopx 命令与可选状态栏在常规升级后继续启动,在保留用户配置的前提下迁移脚本地址。

对主干的风险 / Risks

在同一个隔离 venv 原位换装精确候选 wheel,按 Python 发行更新器路径执行真实默认 slash-commands --install。已安装的 Claude /loopx status 与可选状态栏命令保留旧绝对路径,实际启动均退出 2。 受影响的已安装项目显示无状态且命令不可启动。只验证新装无法覆盖持久旧地址。 在普通升级保持已安装 launcher 可执行,或准确识别并迁移已托管旧入口;保留用户设置。

语义与 CI 对齐

在同一个隔离 venv 原位换装精确候选 wheel,按 Python 发行更新器路径执行真实默认 slash-commands --install。已安装的 Claude /loopx status 与可选状态栏命令保留旧绝对路径,实际启动均退出 2。 在普通升级保持已安装 launcher 可执行,或准确识别并迁移已托管旧入口;保留用户设置。

我的整体评价 / Verdict

REQUEST_CHANGES。 请先恢复持久 Claude 配置的普通升级路径。候选显式重装的成功结果界定了修复范围。 让已安装的 Claude 会话在运行包重构后维持状态读取能力。

English verdict: REQUEST_CHANGES at 581d7d1. Request changes. The default wheel upgrade leaves existing Claude /loopx status and status-line commands pointing to removed scripts. Reinstalling the scoped adapter restores both.

Comment thread loopx/hosts/claude/scripts/install.py Resolved
…CI assertion

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>

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

[P2] 迁移旧脚本时保留自定义 Claude hook 的调用方式。给已安装的 Claude PreToolUse 新增一个合法的项目级自定义调用。它使用 env 包装旧 LoopX 脚本,并设置独立 timeout。默认升级把脚本移到新路径,完整重建 command,丢掉 env 包装而保留 timeout。在两份真实 wheel 的同一项目中复现。 按已知生成结构匹配托管条目,保留用户自定义调用。可无歧义定位其旧脚本参数时仅更换对应路径,保留包装程序、环境和其他参数。补一条已安装配置的更新回归。 源码

动机 / Motivation

合并 Claude、KunlunCode、ZCode 默认宿主包位置,跨原位更新保留已安装的命令和用户自定义。 此前默认更新后项目 Claude 命令仍指向被移除旧脚本。当前增加现存配置的自动迁移。 既有 Claude Code 项目适配器用户,以及从 Python/Node、面板或命令入口使用 KunlunCode 和 ZCode 的用户。

默认升级静默改变项目 hook 的执行上下文。用户以独立配置指定的环境仍影响后续动作。 实际用精确 base/head wheel 在同一 venv 原位升级。从注册项目之外运行默认 slash-commands --install,原项目 /loopx status 与状态栏均退出 0。dry-run 保持文件字节,重复更新幂等,env 和权限键保留。 原位双 wheel、注册项目外的真实更新、dry-run 和再次安装。定向 Python 119、Node 69 通过。安装路径上的用户 wrapper 已复现被覆盖。 安装行为在 macOS 临时 venv、临时 home 和测试项目内验证,默认更新由真实 CLI 执行。Node 69、定向 Python 119 项通过。Windows quoting、真实宿主会话和托管 CI 未核验。 验收契约

改动思路 / Approach

该改动沿用 旧 wheel 项目安装器 → .claude 命令和设置 → 发行版升级默认 CLI → 真实状态命令及状态栏入口。复用默认 slash install 入口与原子文件更新。在迁移 owner 保留现有配置写入边界。 发现注册项目的配置后,按旧脚本路径片段筛选 PreToolUse 与 statusLine,再整体重建 command。引用旧脚本不充分证明整个调用是工具生成。 按已知生成结构匹配托管条目,保留用户自定义调用。可无歧义定位其旧脚本参数时仅更换对应路径,保留包装程序、环境和其他参数。补一条已安装配置的更新回归。

具体改动 / Changes

精确提交 bfd1e3b,本次对照目标 379b9ea。102 文件 +1017/−173。重构包括移动三个宿主包及两幅原样 UI 资源,以及路径消费者、双语文档和回归。相较上一受评头,增量集中在 Claude 迁移、KunlunCode 旧命令识别和相应测试。

关键代码讲解

  • _migrated_settings_payload。命中旧脚本路径片段即重建 command,丢弃用户的包装程序。 源码

  • _discover_claude_migration_targets。由现有配置和注册项目查找历史安装。 源码

  • _is_managed_server。同时识别旧的 managed server 与新发行路径。 源码

  • managed-migration-preserves-custom-hook-invocation(not_met)。默认更新恢复旧安装入口,同时保持所有非托管配置的执行形式与设置。

对主干的风险 / Risks

给已安装的 Claude PreToolUse 新增一个合法的项目级自定义调用。它使用 env 包装旧 LoopX 脚本,并设置独立 timeout。默认升级把脚本移到新路径,完整重建 command,丢掉 env 包装而保留 timeout。在两份真实 wheel 的同一项目中复现。 一般旧项目可以继续使用,含旧脚本路径的自定义 hook 会被改写为标准调用。 按已知生成结构匹配托管条目,保留用户自定义调用。可无歧义定位其旧脚本参数时仅更换对应路径,保留包装程序、环境和其他参数。补一条已安装配置的更新回归。

我的整体评价 / Verdict

REQUEST_CHANGES。 上一轮标准命令和状态栏的升级缺口已关闭。仍需要限定自动迁移的识别与更新范围。 宿主移位后的首次正常升级需要同时保全运行入口和用户已经配置的行为。

English verdict: REQUEST_CHANGES at bfd1e3b. The default wheel upgrade now restores ordinary Claude command and statusline execution. It still rewrites a user-defined PreToolUse command and drops its environment wrapper. Migrate only proven managed entries or preserve the custom invocation.

Comment thread loopx/hosts/claude/scripts/install.py Resolved
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>

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

[P2] 旧脚本路径紧邻 shell 运算符时漏迁。

[P2] 迁移把普通输出参数当作 LoopX 启动命令。

动机 / Motivation

已有 Claude Code LoopX 安装、升级 wheel 后重装 slash commands 的用户。 旧包脚本移到新目录后,已有 statusLine 需要换到新路径,同时保留用户的命令结构与输出。 迁移实际执行的旧 LoopX 脚本,保留 shell 链接符、参数与用户自有的 statusLine 内容。 对照契约

使用实际 Wheel 连续安装旧版和当前提交,运行公开安装 CLI,再按保存的配置执行状态栏及 slash 命令。 紧邻 && 的旧启动命令和先打印路径再启动的组合均退出 2。只打印路径的用户脚本退出 0,但显示内容变化。

已实装 macOS/POSIX wheel 并运行保存的命令。交互式 Claude Code、PowerShell 和托管 CI 未验证。

  • S1 脚本搬家后普通命令和空格分隔的包装仍可用。 通过。
  • S2 紧邻 shell 运算符的实际 launcher 能迁移。 当前反例成立。
  • S3 仅出现在值参数中的旧路径保留原样。 当前反例成立。

改动思路 / Approach

迁移入口读取用户拥有的设置,写回只覆盖已确认归属的 LoopX 命令。 现有迁移入口仍适用。执行位置与值参数由同一 parser 分辨,保留现有命令范围及用户输出。 旧 wheel 自带原路径,五种合成配置全部可执行,状态栏输出和原 slash 命令均正常。 按实际入口执行并读回结果。

具体改动 / Changes

精确提交 b1b3f51f71c64c65bc1ce90bca3b23d5efc9eb6d,102 个文件 +1331/−173。变更集中于 Claude Code、KunlunCode、ZCode host 布局、Wheel 安装兼容与配套 CI 测试。

  • migrate_legacy_claude_dir。真实安装器迁移旧版 settings 文件。 代码
  • _migrated_settings_payload。对旧 statusLine 和 PreToolUse 调用相同的命令迁移入口。 代码
  • _tokenize_shell_spans。从原命令提取位置,未把不带空格的 shell operator 识别成边界。 代码
  • _rewrite_legacy_claude_command。当前按首个匹配路径后缀选中替换位置。 代码
  • installed legacy Claude command test。既有验证执行迁移后的普通 statusLine 命令。 代码

实际双 Wheel 的普通及带空格包装对照保留了显示,五种 slash 命令均成功,dry-run 保留原设置字节。Python 232 项及 Node 52 项通过。 定向回归测试

对主干的风险 / Risks

标准本地预检 19 项执行检查通过。 针对 PR 基线和复核时主干的只读 merge-tree 及签署检查通过。标准预检从干净提交运行。状态栏错误独立从真实 Wheel 安装复现。

语义与 CI 对齐

已有测试覆盖普通和空格分隔的包装。新增两个真实失败用例分别压缩 shell operator 周围空格,并把匹配路径放在用户命令的值参数位置。

我的整体评价 / Verdict

REQUEST_CHANGES。 普通和空格包装的升级已核验。请让迁移按实际执行位置匹配脚本,保留运算符和用户的普通参数。两个退出 2 的用例及打印内容漂移均可稳定复现。

English verdict: REQUEST_CHANGES at b1b3f51. A real wheel upgrade leaves valid no-space shell operator chains on the removed launcher and rewrites a matching path used only as a printf argument. Verify that the matched span is an executed LoopX script and preserve shell boundaries and literal data.

Comment thread loopx/hosts/claude/scripts/install.py Resolved
Comment thread loopx/hosts/claude/scripts/install.py Resolved
…ion Claude launchers

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>

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

[P2] 引用 here-document 的输出被当成启动命令改写。 现有 statusLine 用引用 here-document 打印一行旧启动命令,随后执行一次相同的实际 launcher。 真实 wheel 升级后实际 launcher 可执行,但打印出来的文本也变成新路径,第一行 stdout 与旧包不相同。 区分 here-document 重定向与普通文件重定向,跳过数据正文和终止行,只迁移其后的确实执行的命令。 实装后比较原输出字节,断言引用的正文 unchanged 且后续 launcher 确实从新路径执行。 源码

[P2] 条件分支里的旧状态栏 launcher 未迁移。 既有状态栏通过合法的 POSIX if 条件,随后在 then 分支执行旧脚本。 当前安装报告成功,实际 statusLine 却因引用移除的旧版脚本,从退出 0 变成 2。slash 命令仍成功,容易漏掉状态栏故障。 识别已证明安全的复合命令位置,或把无法认证的旧 launcher 报为需手工迁移,提供恢复路径。 从实际旧 wheel 升级,在真实 /bin/sh 下执行原配置并验证状态栏结果和迁移诊断。 源码

动机 / Motivation

已有 Claude Code LoopX 安装、升级 wheel 后重装 slash commands 的用户。 旧包脚本搬家后,状态栏需要换到新路径,同时保留用户已有 shell 包装和输出。 只迁移实际执行的旧 LoopX 脚本,保留用户的打印文本和未覆盖的配置。 对照契约

在隔离 Python 环境先实际安装旧版 wheel,然后安装当前 wheel,再由公开安装 CLI 改写配置。由 POSIX shell 执行保存的状态栏并对照基线输出。 引用 here-document 将旧命令作为纯文本输出时,安装器也改写了数据行,首行输出变化但仍退出 0。条件分支 then 之后的真实 launcher 未迁移,状态栏从退出 0 变成 2。

验证覆盖本地 macOS POSIX 与实际 wheel 安装。未运行交互式 Claude Code、PowerShell 或托管 CI。

  • 原失败回归 无空格链接符和用户路径值保留原效果。 通过。
  • 引用数据字节 here-document 的用户输出保持原字节。 当前反例成立。
  • 条件包装 可执行的条件分支 launcher 完成迁移或提供明确诊断。 当前反例成立。

改动思路 / Approach

显式安装时更新项目或用户已授权的 LoopX 路径。用户自有的文本和非 LoopX 命令不在替换权限内。 复用现有原位迁移和设置归属。把 shell 数据、命令和未知语法先区分,再决定是否替换。 实际旧版 wheel 仍提供原启动路径,七种合成配置和七次 slash 命令均退出 0。 按实际入口执行并读回结果。

具体改动 / Changes

精确提交 bd711a7df78b3804d9afd08d571d5f6e342d65cf,PR 对照目标 379b9ea3e9dab2b5671129bdd0c52b3e47479ed0。102 个文件 +1818/−174。范围是 Claude Code、KunlunCode、ZCode host 打包路径,真实安装迁移,及配套类型、CI 和测试。相比上一审仅两处文件改变。

  • migrate_legacy_claude_dir。实际迁移入口读取既有 Claude 配置并写回可归属项。 代码
  • _migrated_settings_payload。提取 statusLine 或 PreToolUse 命令且保留已有用户配置。 代码
  • _split_command_segments。分隔命令及重定向。现有 here-document 状态没有跨行保留。 代码
  • _advance_command_wrappers。定位分段内的 wrapper 和命令,未跳过 then 保留字。 代码
  • test_claude_legacy_migration_command_position_and_operator_boundaries。已有定向矩阵保护无空格运算符、普通数据和常见 wrapper。 代码

两份实际打包程序的七组升级测试确保原 slash 命令正常,七次 dry-run 保留设置字节。独立 Python 258 项通过、3 跳过,TypeScript 定向 69 项通过,源类型检查、Chat 构建及两张 ZCode PNG 逐字节对照通过。 定向回归测试

对主干的风险 / Risks

标准本地预检 6 项直接检查和 19 项执行检查均通过。另有 2 项人工图像验收,仍保留预检状态。 相对当前主干 6915df6 的只读 merge-tree 成功,四个提交均有 DCO 签署。两个失败都来自真实 wheel 安装;迁移依然报告成功。已检查两张原有 ZCode 首屏资产,窄屏原生错误和桌面额度门均与基线逐字节相同。

语义与 CI 对齐

当前测试验证常见 shell 链。真实升级反例另对照引用文本和控制流程,确认前者 stdout 漂移,后者退出 2。

我的整体评价 / Verdict

REQUEST_CHANGES。 上一轮三类已复现的旧问题均已关闭。当前还需要保持 here-document 的数据原文,并可靠处理或诊断条件分支中的真实 launcher。

English verdict: REQUEST_CHANGES at bd711a7. The installed upgrade fixes the earlier five cases. It still rewrites displayed text inside a quoted here-document and leaves an executed launcher after then pointing to the removed file, causing statusLine to exit 2. The slash command continues to work in both cases.

Comment thread loopx/hosts/claude/scripts/install.py Resolved
Comment thread loopx/hosts/claude/scripts/install.py Resolved
… control clauses

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>

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

This exact-head review (c5b6f14bb1b74a58246f3cc33423cfd2a269d684) confirms zero blocking defects across the Batch 2 host consolidation (claude, kunluncode, zcode moved under loopx/hosts/), including heredoc body preservation, POSIX compound clause migration, and fail-closed manual_migration_required reporting. Submitted as a COMMENTED review because GitHub blocks formal self-approval on author-owned PRs.

动机 / Motivation

  • Who & trigger: Operators upgrading an existing LoopX installation (loopx slash-commands --install) or invoking CLI and dashboard integrations for Claude Code, KunlunCode, and ZCode (loopx-kunluncode, loopx zcode-goal, dashboard chat bundle, and loopx/hosts/*), alongside maintainers consolidating top-level loopx/*_goal_mode/ packages under loopx/hosts/.
  • Before & after scenario: Before: consolidating loopx/claude_goal_mode/ into loopx/hosts/claude/ deletes the old script paths inside newly built wheels, so existing projects whose .claude/settings.json hooks, statusLine, .mcp.json, or /loopx command still point at claude_goal_mode fail with exit status 2; meanwhile, naive substring or flat command rewrites corrupt quoted heredoc bodies and printf operands, miss adjacent && chains or if ...; then ...; fi branches, drop custom env wrappers/timeouts, or silently skip dynamic eval commands. After: default loopx slash-commands --install discovers current and registered projects, skips here-document bodies verbatim, rewrites only executable legacy launcher positions across compound POSIX clauses and shell chains while preserving literal operands/wrappers/timeouts, flags unparseable dynamic eval/option references with manual_migration_required recovery notes, and preserves KunlunCode and ZCode behavior.
  • Observable outcome: All three adapters (claude, kunluncode, zcode) operate from loopx/hosts/{claude,kunluncode,zcode} across Python, TypeScript, dashboard, and wheel builds, KunlunCode legacy MCP detection (_MANAGED_MCP_SCRIPT_SUFFIXES) and loopx-kunluncode stay intact, existing Claude setups upgrade idempotently across simple, heredoc, and compound control commands without modifying --surface codex, --uninstall, print_only, or heredoc-only setups, and dynamic eval legacy commands emit actionable manual_migration_required diagnostics.
  • Non-goals: Compatibility stub packages under deleted loopx.*_goal_mode import paths are intentionally omitted once repository callers cut over, dynamic shells such as eval or env -S are never guessed/rewritten automatically, and loopx-kunluncode keeps its console-script alias until downstream caller cutover completes.
  • Remaining gap: Six remaining loopx/*_goal_mode/ packages (agy_goal_mode, dsh_goal_mode, kiro_cli_goal_mode, opencode2_goal_mode, opencode_goal_mode, pi_goal_mode) stay deferred to subsequent M2 batches.

改动思路 / Approach

  • Entry point & authoritative state: Packaging and runtime cutover flows directly through pyproject.toml, tsconfig.control-plane.json, loopx/presentation/chat_bundle.py, apps/presentation/dashboard, loopx/hosts/{claude,kunluncode,zcode}, and loopx/slash_command_install.py. During non-uninstall loopx slash-commands --install when "claude-code" is active, _discover_claude_migration_targets enumerates CLAUDE_HOME, CLAUDE_CONFIG_DIR, cwd/ancestor roots, and active project registries via read_activation_upgrade_registry, then invokes migrate_legacy_claude_dir per discovered .claude or .mcp.json directory.
  • Architecture assessment (retain) & boundary: Separating pure shell-span and heredoc parsing (_consume_heredoc_bodies -> _tokenize_shell_spans -> _split_command_segments -> _advance_command_wrappers -> _segment_edits) from fail-closed diagnostic reporting (_inspect_legacy_claude_command), target discovery (_discover_claude_migration_targets), and atomic JSON writes (migrate_legacy_claude_dir) keeps invariants, policies, and provider IO distinct without maintaining duplicate loopx/*_goal_mode stub packages. Scoped to Batch 2 consolidation (claude, kunluncode, zcode), repository caller/packaging/dashboard/doc cutovers, KunlunCode legacy MCP tolerance, and segment/heredoc/clause-aware Claude upgrade migration with fail-closed manual diagnostics; excludes the remaining 6 host packages.
Component / Path Legacy Baseline (9467da4187) Batch 2 Consolidated (c5b6f14bb1) Migration / Compatibility Behavior
Claude adapter loopx/claude_goal_mode/* loopx/hosts/claude/* Span/heredoc/compound-clause migration via loopx slash-commands --install (--surface claude-code)
KunlunCode adapter loopx/kunluncode_goal_mode/* loopx/hosts/kunluncode/* Keeps loopx-kunluncode alias; _is_managed_server recognizes old + new server.py suffixes
ZCode native Goal loopx/zcode_goal_mode/* loopx/hosts/zcode/* Updates TS/Python/dashboard/chat-bundle contracts (loopx/hosts/zcode/contract.{ts,json})
Heredoc / compound / dynamic shells Flat/substring edge gaps _consume_heredoc_bodies, _CLAUSE_STARTERS, _inspect_legacy_claude_command Skips heredocs verbatim; migrates if/then/elif/else/while/do/{}/(); flags eval/env -S as manual_migration_required

Note: Table derived from inspected source at c5b6f14bb1b74a58246f3cc33423cfd2a269d684; runtime behavior independently verified via live dual-wheel execution probes.

具体改动 / Changes

Across -M20% diff classification (102 files, +2271 / -174):

  • Production (21 files, +1056/-32): Core additions live in loopx/hosts/claude/scripts/install.py (+867/-9 total across the branch) and loopx/slash_command_install.py, plus loopx/cli_commands/slash_commands.py, loopx/hosts/kunluncode/{cli,runtime,server}.py, loopx/hosts/zcode/{api,bridge,cli,runtime}, loopx/presentation/chat_bundle.py, apps/presentation/dashboard/src/{data/zcode-goal.ts,features/personal-workspace/zcode-goal-control.tsx}, packages/dsh-loopx-plugin/src/managed-runtime.ts, pyproject.toml, tsconfig.control-plane.json, and CI/install scripts.
  • Tests & Smokes (32 files, +1124/-60): Regression suites in tests/test_slash_command_install.py (including heredocs, POSIX compound clauses, case patterns, for lists, and eval manual diagnostics), tests/test_kunluncode_goal_mode.py, tests/test_hosts_goal_mode_batch2_consolidation.py, and updated imports across TS/Py suites.
  • Docs (14 files, +37/-37) & Mechanical Moves (35 files, +54/-45): Bilingual roadmap sync (docs/architecture/rfcs/loopx-overall-roadmap-v0{,.zh-CN}.md), companion docs, and git mv relocation of claude, kunluncode, and zcode.

关键代码讲解

  1. loopx/hosts/claude/scripts/install.py:640 — _tokenize_shell_spans & _consume_heredoc_bodies:618: Queues POSIX << / <<- delimiters (preserving here-string <<< order), consumes queued heredoc bodies and closing delimiters verbatim after (with tab stripping for <<-), fails closed (None) on unterminated heredocs/quotes, and still tokenizes executed commands before (on header lines) and after closing delimiters.
  2. loopx/hosts/claude/scripts/install.py:756 — _split_command_segments & _advance_command_wrappers:829: Tracks case ... in pattern) ...;; esac arms without matching case patterns, steps over unquoted _CLAUSE_STARTERS (if, elif, then, else, while, until, do, {) while holding _CLAUSE_HEADERS_NON_COMMAND (for, select, case) non-executable so for s in <old>; do <old_launcher>; done and if [ ... ]; then <old_launcher>; fi rewrite only real execution slots, and flags eval / env -S / unsupported flags only when legacy suffixes remain.
  3. loopx/hosts/claude/scripts/install.py:1284 — migrate_legacy_claude_dir & loopx/slash_command_install.py:687 (_discover_claude_migration_targets, install_slash_commands:967): Upgrades .claude/commands/loopx.md, .claude/settings.json, and .mcp.json atomically across registry/home targets, emitting manual_migration_required rows and --scope ... --harden recovery notes in installed + Markdown notes when dynamic commands cannot be auto-rewritten.
  4. loopx/hosts/kunluncode/cli.py:153 — _is_managed_server & pyproject.toml:71: Retains loopx-kunluncode = "loopx.hosts.kunluncode.cli:main", updates _source_root() (parents[3]), and accepts both /loopx/hosts/kunluncode/server.py and /loopx/kunluncode_goal_mode/server.py in _MANAGED_MCP_SCRIPT_SUFFIXES.
  5. loopx/hosts/zcode/bridge.py:212 — zcode_goal_operation & loopx/presentation/chat_bundle.py:22: Switches -m loopx.hosts.zcode.bridge --validate-binding, relative imports, SOURCE_FILES (loopx/hosts/zcode/contract.{ts,json}), and dashboard imports (zcode-goal.ts, zcode-goal-control.tsx) cleanly without behavioral drift.

Specification mapping (docs/architecture/rfcs/loopx-overall-roadmap-v0.md @ 9467da418740ac483d0f09499f2f08ff1ad559d6):

  • roadmap-m2-batch2-move (hosts/claude, hosts/kunluncode, hosts/zcode migrated cleanly, old dirs removed): implemented
  • roadmap-m2-caller-and-packaging-cutover (all internal imports, TS configs, pyproject.toml, chat_bundle.py, dashboard, CI/docs updated): implemented
  • roadmap-m2-claude-and-kunluncode-upgrade-preservation (legacy Claude .claude/.mcp.json heredoc/compound-safe migration + manual_migration_required + KunlunCode legacy MCP detection + loopx-kunluncode alias preserved): implemented
  • roadmap-m2-remaining-6-packages (consolidation of agy, dsh, kiro_cli, opencode, opencode2, pi under loopx/hosts/): deferred

对主干的风险 / Risks

  • Findings: No blocking findings on exact head c5b6f14bb1b74a58246f3cc33423cfd2a269d684. All 6 review threads (including Round-4 PRRT_kwDOStEbEs68kxW0 and PRRT_kwDOStEbEs68kxW3) are verified resolved (6/6) and covered by live dual-wheel and regression verification.
  • Failure analysis & negative walkthroughs: Verified print_only (printf), heredoc_only (cat <<'EOF'), heredoc_then_launch (cat <<-'EOF' tab-stripped body + post-EOF launcher), for_literal_and_do (for s in <old>; do <launcher>; done), if_then_compound (if [ -n "$HOME" ]; then <launcher>; fi), eval_dynamic (manual_migration_required == 1 with untouched command and actionable recovery guidance), --surface codex, --uninstall, and corrupt JSON handling. Zero false-positive warnings were emitted on benign print/heredoc/for-list setups.
  • Scope fit, isolation & authority (default_off_isolation = isolated, authority_semantics = aligned): Active callers are wired in CLI/packaging/dashboard; Claude hooks continue gating on .claude/loop.md / LOOPX_GOAL_FORCE=1, KunlunCode keeps its loopx-kunluncode entry point, and ZCode retains its session-scoped controller boundary.
  • Validation ledger (ci_policy: not_consulted, wait_for_ci: false):
    • Dual-wheel live 11-case upgrade counterfactual (9467da4187 -> c5b6f14bb1): Built full 2.4.1 wheels (build:chat + dashboard tsc --noEmit + setup.py verify_frontend()), installed baseline in an isolated venv, ran loopx slash-commands --install from outside project dirs after upgrade: 10/10 runnable setups (ordinary, spaced_env, adjacent_and, print_only, print_then_launch_adjacent, print_then_launch_spaced, heredoc_only, heredoc_then_launch, if_then_compound, for_literal_and_do) + env PreToolUse (timeout=12) + .mcp.json + /loopx status + loopx-kunluncode --help passed exit 0 matching baseline (print_only & heredoc_only byte-identical); eval_dynamic remained untouched and emitted manual_migration_required == 1; --surface codex and --uninstall left all 11 untouched; repeat install had zero "updated" rows.
    • Pytest (3166 passed, 3 skipped): tests/test_slash_command_install*.py, tests/test_claude_*.py, tests/test_hosts_goal_mode_batch2_consolidation.py, tests/test_kunluncode_goal_mode.py, tests/test_dsh_*.py, tests/test_zcode_*.py, tests/test_host_*.py, tests/test_atomic_write_modes.py, tests/test_runtime_subprocess_utf8.py, tests/presentation/test_chat_bundle.py, tests/cli_commands/test_source_session_lifetime.py, tests/control_plane/, tests/canary/test_maintainability_ratchet.py, and tests/architecture/ passed in 145.44s (3 Windows-only skips in test_claude_goal_install_python_launcher.py).
    • TypeScript / DSH / CI / Static: npm run typecheck:control-plane 0; Node TS tests 85/85 passed; packages/dsh-loopx-plugin tsc (3 tsconfigs) 0 + Vitest 16/16 (405/405 passed); scripts/ci unittest discover 24/24 passed; check_rfc_bilingual.py passed; ruff check 0; mypy --strict --follow-imports=silent 0/22 (17 [tool.mypy] kernel files + install.py + slash_command_install.py + kunluncode/server.py + zcode/{api,bridge}.py); loopx check (98 scanned files) errors=0, warnings=1 (non-literal cli.ts:87 credential token).
    • Canary premerge (--tier standard): Direct 6/6 passed, catalog_run 10/10 passed, boundary_run 1/1 passed, risk_profile_run 5/8 passed (3 failures strictly in examples/canary/dsh-loopx-plugin-validation.py --phase {quality,package,runtime}, exit 2: pnpm is required for DSH plugin validation).
  • Residual risk & strongest unverified gap: On this macOS host without pnpm, the pnpm pack / DSH CLI plugin pack lifecycle (dsh-loopx-plugin-validation.py --phase package,runtime) and the 3 Windows-only shell tests (Git Bash / powershell.exe live execution beyond unit tests in test_slash_command_install.py) were not executed live.

我的整体评价 / Verdict

  • Outcome impact (long_horizon: improved; user_experience: preserved): Advances M2 loopx/hosts/ consolidation (3 of 9 packages migrated, zero stray *_goal_mode cross-imports) while safely upgrading Claude setups (including heredocs and compound POSIX control clauses) and flagging non-rewritable dynamic commands without silent breakage. visual_review: not_applicable — apps/presentation/dashboard/src/data/zcode-goal.ts and zcode-goal-control.tsx modify only the contract.js import path with no rendered DOM/CSS changes, verified via tsc --noEmit and Vite chat bundle build (unverified_scope: none).
  • Assessment decisions: observable_semantics = equivalent, code_volume = necessary (compatibility_assessment: retain), change_proportionality = proportionate (architecture_assessment: retain), default_off_isolation = isolated, authority_semantics = aligned, semantic_alignment = aligned (reuses existing claude_goal_mode legacy suffixes, ZCode contract schema, and registered registry codecs). Separating pure shell-span and heredoc parsing (_consume_heredoc_bodies -> _tokenize_shell_spans -> _split_command_segments -> _advance_command_wrappers -> _segment_edits) from fail-closed diagnostic reporting (_inspect_legacy_claude_command), target discovery (_discover_claude_migration_targets), and atomic JSON writes (migrate_legacy_claude_dir) keeps invariants, policies, and provider IO distinct without maintaining duplicate loopx/*_goal_mode stub packages. Scoped to Batch 2 consolidation (claude, kunluncode, zcode), repository caller/packaging/dashboard/doc cutovers, KunlunCode legacy MCP tolerance, and segment/heredoc/clause-aware Claude upgrade migration with fail-closed manual diagnostics; excludes the remaining 6 host packages.
  • Freshness & Conclusion: Verified at exact head c5b6f14bb1b74a58246f3cc33423cfd2a269d684 (6/6 threads resolved, wait_for_ci: false, PR left OPEN), published as COMMENTED review due to GitHub author-owned restriction.

English Verdict: APPROVE

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

[P2] then 后的 POSIX 续行让状态栏静默失效。 现有 statusLine 为了换行排版,在 then 后使用反斜杠换行,再缩进实际 LoopX launcher。 POSIX shell 删除反斜杠换行。迁移器却把换行放入独立 token,遗漏后续 launcher。实际升级报告成功且没有手工迁移提示,statusLine 从退出 0 变成 2。 扫描时消除 POSIX 词法续行的值,同时保留源偏移,确保随后明确的命令仍在命令位置。 用两个实际 wheel 升级含续行的有效 if 配置,断言迁移后原 stdout、退出 0 和续行格式。 源码

[P3] 行末注释的普通撇号被当作未闭合引号。 现有 POSIX statusLine 在真实 launcher 后附加行末注释,其中包含一个普通撇号。 shell 忽略该注释。迁移器把注释中的撇号视为引号起点,错误要求手工迁移并保留旧脚本路径。实际升级后状态栏退出 2。 识别词起始位置的未引用注释标记,跳到换行并保留注释内容。引用中的井号和字面词仍应按原义处理。 用实际升级覆盖 launcher 后的撇号注释和含井号的普通数据,校验命令迁移、原注释保留和无误报。 源码

动机 / Motivation

已有 Claude Code LoopX 安装、升级 wheel 后重装 slash commands 的用户。 旧包脚本搬家后,显式安装需要迁移真实启动路径,同时保留自定义状态栏的 shell 结构和用户设置。 迁移有效命令中的旧 LoopX 脚本,保持状态栏可运行并保留用户文本。无法可靠迁移时给出准确诊断。 对照契约

在隔离环境分别安装实际旧 wheel 和新 wheel,由公开安装 CLI 执行升级,再通过 /bin/sh 执行保存的 statusLine 并对照退出码与 stdout。 then 分支的 shell 续行和行末含撇号的注释都会保留已移除的旧路径,使 statusLine 退出 2。续行没有手工迁移提示,注释被误报为未闭合引号或 here-document。两种情况下 slash 命令均退出 0。

覆盖本地 POSIX shell 和真实 wheel 安装。交互式 Claude Code、PowerShell、托管 CI 和正式部署未验证。

  • 既有启动与数据显示 普通命令、引用 here-document、行内条件分支和 case 分支保留原输出。 通过。
  • POSIX 续行 then 分支中带续行的有效命令应迁移并正常执行。 当前反例成立。
  • POSIX 行末注释 包含普通撇号的 Shell 注释应保留原文且不阻断有效 launcher 的迁移。 当前反例成立。

改动思路 / Approach

仅在显式安装 Claude Code slash commands 时迁移可归属的 LoopX 引用。原有设置及 shell 用户文本保持原义。 复用现有原位迁移和设置归属。由同一词法扫描维护执行位置和原字符串偏移。 实际旧 wheel 保留原脚本,十种 statusLine 和十次 slash 命令均退出 0。 按实际入口执行并读回结果。

具体改动 / Changes

精确提交 c5b6f14bb1b74a58246f3cc33423cfd2a269d684,PR 对照目标 379b9ea3e9dab2b5671129bdd0c52b3e47479ed0。103 个文件 +2792/−695。此次涉及 Claude Code、KunlunCode、ZCode 迁包及其打包、CI、文档和验证。相对上一审的三文件增量集中在 shell 判定、诊断透出及回归测试。

  • migrate_legacy_claude_dir。配置迁移入口写回可归属的旧路径并透出手工迁移诊断。 代码
  • _inspect_settings_migration。提取 statusLine 和 hook 命令,保留其他设置字段。 代码
  • _consume_heredoc_bodies。按声明跳过 here-document 正文,引用正文经实装对照一致。 代码
  • _tokenize_shell_spans。保留词和运算符偏移。当前把续行写入词值,并在注释中识别引号。 代码
  • _split_command_segments。区分命令段和重定向,普通 case 分支中的 launcher 实装成功。 代码
  • test_claude_legacy_migration_heredocs_compound_clauses_and_manual_diagnostics。定向矩阵保护普通复合命令、here-document 和部分手工迁移诊断。 代码

上一轮的引用 here-document 和行内 then 两项已修复,普通 case 额外通过。十个项目的 slash 命令及 dry-run 保留设置字节均通过,非归属权限字段保留。另有 Python 259 项通过和 3 项跳过,TypeScript 69 项通过,控制平面类型检查与 Chat bundle 构建通过。 定向回归测试

对主干的风险 / Risks

标准本地预检 6 项直接检查和 19 项执行检查均通过。另有 2 项人工图像验收,仍保留预检状态。 相对当前主干 6915df6 的只读 merge-tree 成功,五个提交均有 DCO 签署。两张 ZCode 画面均检查过,与基线逐字节一致。两个新增 shell 反例在隔离 wheel 实装中成立。

语义与 CI 对齐

定向矩阵覆盖普通复合语句和 here-document。续行和注释是独立的 POSIX 词法边界,在真实安装路径分别导致漏报和误报。

我的整体评价 / Verdict

REQUEST_CHANGES。 上一轮两项问题已通过原路径复验。请修复续行导致的静默失效及注释误报,并在下一提交复跑两条实装升级样本。

English verdict: REQUEST_CHANGES at c5b6f14. The quoted here-document and inline then regressions are fixed. In an installed-wheel upgrade, a valid POSIX line continuation before the launcher leaves statusLine broken without a diagnostic. An apostrophe in a trailing comment also blocks migration with a false unterminated-quote diagnostic. Both statusLine commands exit 2 while slash commands still work.

):
if awaiting_heredoc is not None and raw_command[i + 1] == "\n":
return None
i += 1

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.

[P2] then 后的 POSIX 续行让状态栏静默失效。 现有 statusLine 为了换行排版,在 then 后使用反斜杠换行,再缩进实际 LoopX launcher。 POSIX shell 删除反斜杠换行。迁移器却把换行放入独立 token,遗漏后续 launcher。实际升级报告成功且没有手工迁移提示,statusLine 从退出 0 变成 2。 扫描时消除 POSIX 词法续行的值,同时保留源偏移,确保随后明确的命令仍在命令位置。 用两个实际 wheel 升级含续行的有效 if 配置,断言迁移后原 stdout、退出 0 和续行格式。

break
buf.append(raw_command[i])
i += 1
if not closed:

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.

[P3] 行末注释的普通撇号被当作未闭合引号。 现有 POSIX statusLine 在真实 launcher 后附加行末注释,其中包含一个普通撇号。 shell 忽略该注释。迁移器把注释中的撇号视为引号起点,错误要求手工迁移并保留旧脚本路径。实际升级后状态栏退出 2。 识别词起始位置的未引用注释标记,跳到换行并保留注释内容。引用中的井号和字面词仍应按原义处理。 用实际升级覆盖 launcher 后的撇号注释和含井号的普通数据,校验命令迁移、原注释保留和无误报。

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