Skip to content

feat(cli): suggest the closest choice and keep usage errors short - #10012

Open
Duang777 wants to merge 3 commits into
loopx-project:mainfrom
Duang777:codex/cli-typo-suggestions
Open

Duang777 wants to merge 3 commits into
loopx-project:mainfrom
Duang777:codex/cli-typo-suggestions

Conversation

@Duang777

@Duang777 Duang777 commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Goal And Delivered Outcome

  • Outcome basis / optional anchor: observed while walking the getting-started flow on main; related to [Roadmap / Tracking]: LoopX 架构收敛与稳定性重构路线(Architecture Convergence & Stabilization, main@0950cea5) #9852 P1-1 (context/token cost for agent callers). No issue filed.
  • Goal/source and gap: one mistyped word produced a wall of text. A wrong top-level command (loopx stauts) printed all 135 command names twice (usage line plus choose from), ~4.3 KB. A wrong subcommand or option value under a large parser (loopx todo lst, loopx quota --include-detail vison) printed that parser's full usage, 4.3–4.9 KB. No closest-match hint was given. Agents read this into context on every slip.
  • Observable before → after (stderr bytes, exit code 2 unchanged):
Input main this branch New last line
loopx stauts 4257 B 307 B invalid choice: 'stauts' (135 choices; see: loopx --help); did you mean 'status'?
loopx quota-guard 4262 B 310 B ... did you mean 'quota'?
loopx todo lst --goal-id x 4271 B 302 B invalid choice: 'lst' (choose from 'add', 'list', ...); did you mean 'list'?
loopx quota --runtime-profile codex ~4.9 KB 380 B ... did you mean 'codex_cli'?
loopx quota --include-detail vison 4790 B 273 B ... did you mean 'vision'?
loopx --format yaml status 279 B 279 B unchanged (small parser, no close match)
  • Issue/task and intended base: none; base main at dc0505ea3.

Author Declaration

  • Written by: model_agent (Claude Opus, Anthropic), operated by @Duang777

Implemented against

  • Specification and revision: existing LoopXArgumentParser contract in loopx/cli_runtime.py at dc0505ea3 (complete option names; exit 2 on usage errors).
  • Criteria:
Criterion (spec clause) Disposition Symbol / path Test or command
Invalid choice still says invalid choice: '<value>' and exits 2 preserved LoopXArgumentParser._check_value existing invalid choice assertions in tests and smokes
Closest match is named when one exists (difflib, cutoff 0.6) implemented _check_value test_mistyped_choice_names_the_closest_match_without_listing_every_command
Choice sets ≤ 12 keep the full choose from list preserved _INLINE_CHOICE_LIMIT examples/claude-goalmode-lifecycle-smoke.py exact-text check
Top-level usage no longer spells every command implemented add_subparsers(..., metavar="<command>") same test
Usage over 1000 chars (24 of 470 parsers) points to --help in errors only implemented LoopXArgumentParser.error, _ERROR_USAGE_LIMIT same test; --help output unchanged
  • Module launches (python -m loopx.cli / loopx.entrypoint) are named by the runnable <interpreter> -m <module> instead of argparse's pre-3.14 cli.py, so every printed --help hint runs (verified on Python 3.11 and 3.13).
  • Self-check before submission: --help output and successful parses are unchanged. The error label for the top-level positional is now argument <command>: instead of argument command:. The selected-parser path (_SelectedArgumentParser, line ~1492) reuses LoopXArgumentParser.error, so both the selected and full CLI paths get the same output.

Scope And Continuation

  • Completed scope and remaining work: argparse error output only. No new command, option or vocabulary.
  • Slice boundary / successor: complete.

Validation

  • Tested revision: 07e77257e
  • Run state: finished
  • Input classes: synthetic
Check kind Result Public-safe evidence / limitation
unit passed New parametrized test (both loopx.entrypoint and loopx.cli): 6 fail on main, 6 pass here.
unit passed test_cli_argument_diagnostics.py, test_cli_entrypoint.py, test_benchmark_continuation.py, test_replan_context_evidence.py, test_performance_diagnosis_cli.py: 515 passed.
smoke passed claude-goalmode-lifecycle, delivery-batch-scale-enum, delivery-outcome-enum, project/host-mode-plan-cli smokes (all assert on invalid-choice text).
static passed loopx canary premerge --from-git-diff --git-diff-base origin/main: status passed. The maintainability-ratchet canary reports one unreviewed finding for loopx/control_plane/turn_driver/epoch_prefetch.py (2029 lines > 2000), which is already on main after #9947 and not touched here.
  • Coverage and gaps: tests/test_core_distribution.py (installed Core) was not rerun locally for this change; it asserts only invalid choice and usage: substrings, both preserved.

Frontend / Visual Evidence

  • UI impact: none (CLI error text only)

Type of Change

  • New feature
  • Test update

LoopX Area

  • Control plane (goals, todos, quota, scheduler, registry, runtime)

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.
  • 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.
  • 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).

🤖 Generated with Claude Code

@huangruiteng huangruiteng left a comment

Copy link
Copy Markdown
Collaborator

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

[P2] Python 3.11 的帮助提示无法执行。

动机 / Motivation

从 console 或受支持的 Python 模块执行命令,遇到拼写错误后需要查看帮助的用户与 Agent。 console 的三类错误分别消耗 4527、4262 和 4766 字节,退出码为 2。 同输入减至 307、302、273 字节并给出近似命令。Python 3.11 的模块入口却生成命令行上不存在的 cli.py 或 entrypoint.py。 Python 3.11.17 从独立目录通过 python -m loopx.cli 或 python -m loopx.entrypoint 触发根命令、子命令或枚举拼写错误。 保留命令注册与退出语义。缩短 stderr,增加提示,并让终端用户可以按提示打开同一个命令的帮助。

改动思路 / Approach

复用LoopXArgumentParser、原 command registrars 与既有 CLI 调用构造。保留命令注册与退出语义。缩短 stderr,增加提示,并让终端用户可以按提示打开同一个命令的帮助。 重用源 CLI 的可执行 argv 组装和命令路径,避免把 argparse 的显示名当作启动命令。加一组 Python 3.11 执行提示的回归。 Python 3.14 上 console 的显式根与 quota --help 字节长度分别仍为 1968 和 27544。console 六类退出码保持。

具体改动 / Changes

  • error 用短 usage 输出当前命令的帮助地址。3.11 的 argparse 默认程序名来自模块文件名,按输出复制会尝试执行 cli.py。
  • _check_value 保留非法输入与相近词。选项较多时,帮助地址沿用同一个显示名,因此根命令、子命令和枚举均能复现。
  • 根命令占位 缩短错误中的 usage,console 两层显式帮助仍可读。补充的测试应执行提示,而不只校验 stderr 长度。

参考 源 CLI 入口合同 的 dc0505e 版本,核对 使用错误保持拒绝 与 CLI 帮助入口可达。

对主干的风险 / Risks

相同七组输入比较提案基点与精确头、Python 3.11/3.14 的三个入口。Python 3.11 隔离目录逐一执行诊断中的命令,两个模块共六个 command not found,同输入的三个 console 提示均可打开帮助。 本地 quick premerge 6 项直接与 2 项选定检查通过,一项已知维护性 advisory。446 项本地诊断和入口测试通过。 独立验证使用 macOS 上真实源码 console 与模块进程,未复跑安装 wheel 及原生 Windows。 当前主干 ca020c4 的三方组合干净。该结果来自真实执行建议命令,正常 console 的字节缩减可保留。

我的整体评价 / Verdict

要求修改。 重用源 CLI 的可执行 argv 组装和命令路径,避免把 argparse 的显示名当作启动命令。加一组 Python 3.11 执行提示的回归。 保留 console 的紧凑输出,配对确认最高和最低支持解释器的模块错误都能指向其真实入口。

英文简短结论

English verdict: REQUEST_CHANGES at a7bf1b8. On supported Python 3.11, the source-module error points to nonexistent cli.py and entrypoint.py commands. Keep the concise diagnostics and generate a runnable help command for each entrypoint.

Comment thread loopx/cli_runtime.py Resolved
@Duang777
Duang777 force-pushed the codex/cli-typo-suggestions branch from a7bf1b8 to 07e7725 Compare December 4, 2026 04:11
@Duang777

Duang777 commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed in 07e77257e (rebased onto main at 8fca137dc):

  • Root cause: before Python 3.14 argparse names a module launch after its file, so both the usage line and the new hint said cli.py / entrypoint.py. build_cli_parser now sets prog for a LoopX module launch to the command that re-runs this process: <sys.executable> -m <module> (shell-quoted). Console scripts and -c launches keep argparse's name, so loopx stauts still prints see: loopx --help.
  • The hint is now unquoted (see: <command> --help) so a quoted interpreter path stays copyable.
  • New test_module_launch_help_hint_runs (both loopx.entrypoint and loopx.cli × root command, subcommand, choice): runs the typo from a clean directory, extracts the printed hint, executes it with --help and requires exit 0. On Python 3.11.15 it fails 6/6 on a7bf1b866 and passes 6/6 here; also passes on 3.13.

Validation: CLI diagnostics/entrypoint suites 527 passed, 4 invalid-choice smokes pass, premerge passed. test_public_facade_import_only_reexports_match_the_audited_allowlist fails identically on main (quota re-export audit), unrelated.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

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-astra · OpenAI · runtime_reported · high

动机 / Motivation

在终端或自动化中输入无近似匹配的根命令、需要查找合法命令名的用户。 基点对同一无效输入返回 4322 字节 stderr,列出了合法命令 pr-review。 从模块入口运行 zzzzzzzzzz,跟随错误中的 --help,再打开该页推荐的分组命令参考。 当前头的诊断降至 469 字节,提示可运行;其指向的根帮助和该页推荐的 commands 参考都没有 pr-review。 保留默认简明帮助、子命令帮助以及错误退出码。修订范围是根命令的发现路径。

改动思路 / Approach

复用LoopXArgumentParser 与既有的命令注册表。保留默认简明帮助、子命令帮助以及错误退出码。修订范围是根命令的发现路径。 为根命令提供由当前 parser 注册项生成的完整列表入口,并在大选集诊断中指向它;回归应验证列表包含有效但不在简明首页的命令。

具体改动 / Changes

按基点 docs/reference/source-cli-entrypoint.md 的 8fca137 版本核对 紧凑 CLI 错误 和 被省略的有效命令可发现。

对主干的风险 / Risks

以相同的模块入口和无匹配输入比较基点与头,检查指向的帮助全文及 commands 输出,再直接运行 pr-review --help。13 项入口测试通过。 安装仓库锁定的 npm 开发依赖后,精确头的 quick premerge 通过。 本次核对本地模块入口与命令参考,未复跑原生 Windows 安装。

我的整体评价 / Verdict

要求修改。 用户无法从指定的帮助页查到被省略的合法命令,例如 pr-review;直接运行 pr-review --help 成功。 为根命令提供由当前 parser 注册项生成的完整列表入口,并在大选集诊断中指向它;回归应验证列表包含有效但不在简明首页的命令。 安装仓库锁定的 npm 开发依赖后,精确头的 quick premerge 通过。

英文简短结论

English verdict: REQUEST_CHANGES at 07e7725. The root error removes the list of valid commands and points to a help page that omits registered commands such as pr-review. Keep the short diagnostic and link to a complete registry-backed list.

Comment thread loopx/cli_runtime.py Resolved
Duang777 and others added 3 commits December 5, 2026 04:50
A mistyped command or choice printed every top-level command twice and,
for large subcommands, a 4-5 KB usage block. Name the closest match,
replace large choice lists with a pointer to --help, and shorten usage
lines over 1000 characters in error output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: duang777 <duangjl007@gmail.com>
Before Python 3.14, argparse names 'python -m loopx.cli' after the file,
so usage lines and the new '--help' hint said 'cli.py todo --help', which
cannot run. Name a LoopX module launch by the command that re-runs it
('<interpreter> -m <module>'), leave console scripts unchanged, and print
the hint unquoted so a quoted interpreter path survives.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: duang777 <duangjl007@gmail.com>
A shortened root-command error sent people to --help, whose short page
does not list every registered command. commands --registered prints the
names on the current parser, and that diagnostic now points there.
Module and console-script hints stay commands that actually run.

Signed-off-by: duang777 <duangjl007@gmail.com>
@cursor
cursor Bot force-pushed the codex/cli-typo-suggestions branch from 07e7725 to 02e49e2 Compare December 5, 2026 04:54

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

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

动机 / Motivation

本 PR 针对的是在终端或自动化工具中通过 console script 或 python -m loopx.cli / python -m loopx.entrypoint 调用 LoopX CLI 的用户与 Agent。修改前输入 loopx.entrypoint stauts、todo lst --goal-id example-goal 或 quota --include-detail vison 分别在 stderr 输出 4666、6224 与 6611 字节重复命令和参数列表(quota shuld-run 达 6742 字节)且无拼写提示,Python 3.11 模块入口更指向不存在的 cli.py;修改后同输入降至 486、484、455 与 438 字节,并给出 did you mean 建议及可执行的 --help 或 commands --registered 指引。保留退出码 2、invalid choice: 前缀及 12 项以内的 choose from 列表;超过 12 项选择或 1000 字符的 usage 改由可执行的 --help 或 commands --registered 承接,并列出被精简首页省略的 pr-review 等全部 135 个已注册命令。本次边界限定于 Python CLI 解析错误输出、prog 模块名修正与 commands --registered 只读投影,不改动 --help 首页文案、成功命令的 stdout、现有 JSON 业务载荷结构或任何权限与持久化状态。在多轮 Agent 任务中,每一次命令或选项拼写失误原本都会把数千字节噪声压入上下文并增加纠错轮次,因此将诊断压缩到数百字节并指向真实可运行入口具有直接的实用价值。

改动思路 / Approach

本次改动复用既有的 LoopXArgumentParser、_SelectedArgumentParser、build_cli_parser 以及 help_surface 渲染管线,没有引入新的持久化状态或平行策略 owner。两项机制均落在既有 Python CLI 展示与诊断适配器边界内,复用 LoopXArgumentParser 与 commands 命令族,不增加持久状态或平行策略 owner。当前 PR 边界为 argparse 错误文本格式化、pre-3.14 模块启动 prog 修正及 commands --registered 只读列表,不包含 --help 重构或持久化契约变更。

  1. 统一入口与可执行提示:在 build_cli_parser 中,通过 _module_invocation_prog 为 loopx* 模块启动显式设置 prog(<sys.executable> -m <module>),解决 Python 3.14 之前 argparse 将模块名显示为 cli.py / entrypoint.py 导致提示命令无法执行的问题;同时将根命令 subparsers 的 metavar 设为 <command> 并标记 _loopx_root_commands = True,使根级与子级 usage 不再展开 135 个命令名。
  2. 错误精简与近似匹配:在 LoopXArgumentParser.error 中对超过 _ERROR_USAGE_LIMIT(1000 字符)的 usage 折叠为 usage: <prog> [options] (see: <prog> --help);在 LoopXArgumentParser._check_value 中利用 difflib.get_close_matches(..., n=3) 生成 did you mean ...?,选项超过 _INLINE_CHOICE_LIMIT(12 项)时折叠为计数与帮助指针。
  3. 根命令完整列表投影:由于 loopx --help 刻意保持为精简首页(不包含 pr-review 等命令),根命令错误若仅指向 --help 会导致遗漏命令不可发现。PR 新增 commands --registered(仅读当前 parser 已注册命令或 standalone core 可用命令集合并按字母序排序),从根源上消除前序审查指出的“省略命令不可发现”缺口。

具体改动 / Changes

关键代码讲解

  • LoopXArgumentParser.error:当 self.format_usage() 超过 _ERROR_USAGE_LIMIT(1000 字符)时,将多行展开的参数列表替换为单行 usage: {self.prog} [options] (see: {self.prog} --help)\n 并以状态码 2 退出。_SelectedArgumentParser.error 在选定命令分发路径捕获异常后同样经由 LoopXArgumentParser.error(exc.parser, str(exc)) 渲染,保证全量与精选两条路径输出一致。
  • LoopXArgumentParser._check_value:校验失败后按 len(names) > 12 分支。<= 12 时保留原 choose from ... 完整枚举;> 12 时,若动作带有 _loopx_root_commands 标记则指向 {self.prog} commands --registered,否则指向 {self.prog} --help,并在存在 difflib 近似匹配(最多 3 项)时追加 ; did you mean ...?。
  • _module_invocation_prog:检查 sys.modules["__main__"].__spec__.name,仅当以 loopx 开头且 sys.executable 非空时返回 shlex.quote(sys.executable) -m <module>(剥离 .__main__ 后缀),否则返回 None 保留 console_script 或 -c 的默认 prog。
  • _registered_root_command_names 与 render_registered_commands_markdown:在非 standalone-core 模式下通过 build_parser() 实时读取带 _loopx_root_commands 标记的 action.choices(共 135 个顶层命令,含 pr-review);在 standalone-core 模式下回退聚合 _available_selected_commands() 与可选 _WORKSPACE_COMMANDS,不引入 loopx.cli 依赖。在 help_surface.py 注册 --registered 标志,支持 --format json(返回 {"ok": true, "commands": [...]})与 Markdown 列表输出。

规范对齐(docs/reference/source-cli-entrypoint.md @ 65fe0480847c61e1df8af92e827dffd4cf1aabc4)

对照源 CLI 入口规范 docs/reference/source-cli-entrypoint.md(commit 65fe0480847c61e1df8af92e827dffd4cf1aabc4)逐项核对:

  • CLI-ERR-PARITY(源入口与 console 使用错误保持退出码 2 拒绝与统一诊断):implemented —— LoopXArgumentParser 与 build_cli_parser 同时作用于 loopx.entrypoint、loopx.cli 与 console script,实测均返回退出码 2 且无 stdout 污染。
  • CLI-HELP-REACHABLE(诊断中给出的帮助/命令列表入口可实际执行且可发现全部合法命令):implemented —— Python 3.11.17 与 3.14.8 上 loopx.entrypoint 和 loopx.cli 提示的 commands --registered 与 --help 命令均可直接运行返回 0,且 commands --registered 列出 pr-review 等首页省略命令。
  • CLI-JSON-PURE(不改变正常命令 --format json 纯净输出及 standalone-core 隔离):implemented —— commands --format json、commands --registered --format json 与缺失子命令的 handler JSON 错误均保持单行合法 JSON;standalone-core 路径不会导入 loopx.cli。

对主干的风险 / Risks

  • 前序轮次审查收敛情况:两轮前关于 Python 3.11 模块入口显示 cli.py 的问题(a7bf1b866)及上一轮关于根命令提示指向精简 --help 遗漏 pr-review 的问题(07e77257e)均已在当前精确头 02e49e2a4201ab3c12c49ce5a7694c24ab23a96f 修复并由对应测试覆盖。
  • 反例与兼容性边界:
    • 当子命令或选项拥有 > 12 项选择(例如 benchmark 38 个子命令、doctor --agent-type 22 个选项、quota 15 个子命令)时,错误输出指向 <prog> --help,经核对这些命令的 --help 均完整列出对应枚举或子命令;todo 恰好 12 个子命令,仍内联 choose from 并附带 ; did you mean 'list'?。
    • 唯一非字符串枚举 --execution-replan-after-todos(choices=[1, 2, 3, 4, 5])在传入 9 时输出 invalid choice: 9 (choose from '1', '2', '3', '4', '5')(枚举值以字符串形式 repr 展示,而非裸数字 1, 2, ...),语义仍清晰且无现有测试依赖裸数字 repr,属非阻塞细节。
    • mypy --follow-imports=silent loopx/cli_runtime.py 报告 21 处类型检查报错,其中新增代码的 LoopXArgumentParser.error -> None(基类为 Never)与 _registered_root_command_names 中 action.choices 未判空属于非阻塞类型注解问题(运行期 self.exit(2, ...) 永不返回,且 _loopx_root_commands 动作的 choices 恒为字典);loopx/help_surface.py 与 ruff check 均零错误通过。
  • 本地验证矩阵:
    • PASS 定向单元测试:tests/test_cli_entrypoint.py、tests/test_cli_argument_diagnostics.py、tests/control_plane/test_source_cli_entrypoint.py、tests/test_cli_manual_visibility.py、tests/test_cli_stdio_utf8.py、tests/test_core_distribution.py 共 505 passed, 89 skipped(89 项跳过为需要 LOOPX_CORE_TEST_PYTHON 已安装 Core wheel 的环境隔离测试)。
    • PASS 精确头 premerge 门禁:loopx canary premerge --from-git-diff --git-diff-base origin/main(standard tier:3 项 selected/executed canaries 全部通过,含 cli-output-budget-regression-smoke.py、semantic-vocabulary-drift-smoke.py、control-plane-maintainability-ratchet-smoke.py,0 failures)。
    • PASS 静态与边界检查:ruff check 通过;loopx check --scan-path ... 通过(errors=0, warnings=0, public boundary scan clean)。
    • PASS Python 3.11.17 实测:loopx.entrypoint 与 loopx.cli 共 6 组模块启动提示命令提取并执行全部返回 0;Python 3.14.8 基点(07a41a872)vs 精确头(02e49e2a4)对照实测:stauts 4666 B → 486 B、zzzzzzzzzz 4670 B → 466 B、todo lst 6224 B → 484 B、quota --include-detail vison 6611 B → 455 B、quota shuld-run 6742 B → 438 B、--format yaml status 2345 B → 383 B。

我的整体评价 / Verdict

建议批准(APPROVE)。 从长程演进与用户体验看,本 PR(long_horizon: improved、user_experience: improved)在不牺牲任何错误退出语义、JSON 纯净度或命令可发现性的前提下,将常见拼写错误的 stderr 体积压缩了约 83%–93%,并给出了可直接复制执行的 --help / commands --registered 指引与 difflib 拼写建议,显著降低 Agent 与终端用户的上下文开销与排查轮次。改动体量克制(仅 3 个文件 +225/-2,未引入新词汇表或持久化协议),所有必需本地验证均已通过。

关于视觉审查与未验证范围(visual_review):本次仅涉及 CLI stderr/stdout 文本诊断,无 GUI、webview 或前端布局变更(visual_review: not_applicable);unverified_scope 为已安装独立 loopx-core wheel 运行时(89 项 test_core_distribution.py 跳过)及原生 Windows 控制台下 shlex.quote(sys.executable) 在 cmd.exe 中的引号兼容性(可通过进程内 _standalone_core() 模拟及现有 console script 测试部分缓解,建议后续如在 Windows 模块启动路径遇阻再按需改用 subprocess.list2cmdline)。

English verdict: APPROVE at 02e49e2. The change resolves both prior exact-head blockers (runnable module-launch help hints on Python 3.11+ and full root-command discovery via commands --registered), cuts invalid-choice/long-usage stderr by ~83-93% across tested cases while preserving exit code 2 and JSON contracts, and passes 505 targeted pytest cases plus loopx canary premerge (cli-output-budget-regression-smoke.py included).

@songoow songoow left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed exact head 02e49e2a4 (+225/-2 across loopx/cli_runtime.py, loopx/help_surface.py, and tests/test_cli_entrypoint.py). Implementation is sound, well-tested, and ready from a code quality standpoint.

Verification Summary

  • Both prior CHANGES_REQUESTED findings are resolved and covered by executable tests:
    1. @huangruiteng's finding at a7bf1b866 (non-runnable cli.py/entrypoint.py hints on Python 3.11): fixed via _module_invocation_prog() in build_cli_parser, leaving console scripts untouched while emitting runnable <shlex.quote(sys.executable)> -m <module> hints across root, subcommand, and _SelectedArgumentParser paths; verified by test_module_launch_help_hint_runs and test_console_script_help_hint_stays_runnable.
    2. loopx-agent's finding at 07e77257e (concise --help omits valid commands like pr-review): fixed by adding commands --registered (_registered_root_command_names + render_registered_commands_markdown, supporting --format json and Markdown) and routing _loopx_root_commands invalid-choice diagnostics there; verified by test_registered_command_list_includes_command_absent_from_home_page.
  • CI & mergeability: 27/27 CI checks green (kernel-static-checks, kernel-contracts, typescript-core 1–3, typescript-coverage, chat-bundle, checks, merge-gate, Sign-off), cleanly MERGEABLE against current main.

Non-blocking Notes

  • LoopXArgumentParser.error can be annotated -> NoReturn in a future cleanup (self.exit never returns).
  • In _standalone_core() mode, _registered_root_command_names() mirrors the existing commands list (_available_selected_commands() | _WORKSPACE_COMMANDS); after #10048, _CORE_BACKUP_COMMANDS can be included in both places together if desired.
  • For choice sets <= 12, stringifying before repr slightly alters formatting for non-string choices (e.g., integer enums render '1' instead of 1), which is harmless for current contracts.

Merge Gate Note

  • GitHub's reviewDecision still shows CHANGES_REQUESTED from @huangruiteng's outdated review at a7bf1b866 (now addressed) and the branch is BEHIND main; that stale review will need re-review/dismissal (and branch update if required by branch protection) before merge.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

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 / 请求修改

[P2] 让 Windows 用户能直接运行错误提示。在真实 argparse 入口注入 Windows 解释器路径,stderr 给出 'C:\Program Files\Python311\python.exe' -m loopx.cli commands --registered。该行在 PowerShell 的命令位置缺少调用运算符 &,无法运行。现有测试在 shlex.split() 后直接执行 argv,因此绕过了 PowerShell 的解析。前序评审也将原生 Windows 留为未验证。 用现有 render_host_cli_command 渲染模块 argv,增加使用 PowerShell 原样执行 stderr 提示的入口回归,并保留 POSIX 带空格路径用例。 受审位置 PowerShell 调用运算符 · Python shlex 边界

动机 / Motivation

从源码模块、安装入口和脚本运行 LoopX CLI 的用户。 用户拼错根命令、Todo 子命令或 quota 参数后,需要在短诊断中找到可直接运行的帮助。 错误保持退出 2,根诊断给出完整命令清单入口,子层给出对应帮助和接近的候选。 本轮范围是错误恢复与命令发现。原生 Windows 与单独发行的 Core 包仍待执行验证。 Windows 分支通过目标路径注入和官方 shell 规则确认。当前宿主为 macOS,原生 Windows 尚未运行。单独发行的 Core 包本轮未安装。 验收依据

改动思路 / Approach

沿既有 argparse parser 生成近似候选和帮助入口,从同一注册源列举命令。模块启动提示应复用已有的宿主命令渲染。 改动限于 CLI 解析诊断、注册命令参考和对应入口测试。生产执行权限沿原 CLI 解析边界。 前轮提出的问题 · 当前提交既有 Gemini 评审

具体改动 / Changes

  • invalid_status。误输保持退出 2、无 stdout。

  • complete_help。完整清单包括首页省略的已注册命令。

  • host_runnable。帮助提示应能由受支持宿主的 shell 按原样执行。

  • LoopXArgumentParser.error。长 usage 改为普通帮助提示,错误仍退出 2。 受审实现

  • _module_invocation_prog。从当前 Python 模块入口派生解释器和模块名。 受审实现

  • commands --registered。完整清单从构建后的 CLI 注册表取得。 受审实现

  • render_host_cli_command。既有 host renderer 可按目标 shell 渲染 argv。 受审实现

对主干的风险 / Risks

相同的根、Todo 与 quota 误输在两个基线模块打印约 4.3–5.4 KB,仍退出 2。 对照同一 Python 3.11.17 及带空格的解释器路径,两个模块的三种误输保持退出 2 和无 stdout。受审头诊断为 568–667 字节。逐条将提示直接交给 POSIX shell,六条均退出 0。完整清单列出 135 项,包含首页未列出的 pr-review。 非法 --format 仍拒绝且只写 stderr。根诊断只提供查询参考。 本轮再跑 20 项受影响 Python 入口测试,全部通过。git diff --check 通过,当前主干合成无冲突。

我的整体评价 / Verdict

要求修改精确提交 02e49e2。用现有 render_host_cli_command 渲染模块 argv,增加使用 PowerShell 原样执行 stderr 提示的入口回归,并保留 POSIX 带空格路径用例。

English verdict: REQUEST_CHANGES at 02e49e2. The six POSIX recovery hints execute as printed. The Windows interpreter-path diagnostic is POSIX-quoted and cannot be pasted into PowerShell. Reuse the existing host renderer and test the exact printed command in PowerShell.

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.

4 participants