Skip to content

fix: feed back ExitPlanMode approval so CLI doesn't loop the plan#65

Merged
quick-sort merged 1 commit into
mainfrom
fix/exit-plan-mode-approval
Jun 19, 2026
Merged

fix: feed back ExitPlanMode approval so CLI doesn't loop the plan#65
quick-sort merged 1 commit into
mainfrom
fix/exit-plan-mode-approval

Conversation

@hilr

@hilr hilr commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • ExitPlanMode 是 requiresUserInteraction() 工具,CLI 阻塞等审批的 tool_result。PR fix: surface plan content to IM channel on ExitPlanMode #59 只 surface 了计划,没 feed back 审批,所以用户回复后 CLI 还卡着,计划被反复 emit
  • 复用 AskUserQuestion 的 _pending_ask 机制:ExitPlanMode 触发时 surface 计划 + Yes/No 提示,设置 kind=exit_plan_mode 的 pending state,return
  • 下一次 run() 按前缀解析 Yes/No(中英文都支持,longest-match 让 "不要用" 命中 "不要"),把对应 tool_result 发回去让 CLI 继续
  • No 后面的文字作为修改意见发回 LLM;没匹配上 Yes 的回复默认拒绝 + feedback,避免计划没明确批准就跑

Test Plan

  • test_exit_plan_mode_surfaces_plan_with_hint — 计划 + 提示一起发,pending state 正确
  • test_exit_plan_mode_without_plan_still_intercepts / test_exit_plan_mode_empty_plan_still_intercepts — 空 plan 也走拦截分支
  • test_exit_plan_mode_resume_yes_approves — Yes 回复发送批准 tool_result
  • test_exit_plan_mode_resume_no_with_feedback — No + 后续文字作为 feedback
  • test_exit_plan_mode_resume_chinese_yes / test_exit_plan_mode_resume_chinese_no_with_feedback — 中文 好的/不要 也工作
  • test_build_plan_approval_* — 单元测试覆盖 Yes/No/中文/ambiguous 各种回复
  • 全套 183 个测试通过

Closes #64

ExitPlanMode is a requiresUserInteraction() tool — the CLI blocks
waiting for an approval tool_result. The previous fix (PR #59) only
surfaced the plan to the IM channel but never fed back an approval,
so the next user reply re-entered the blocked CLI and the plan got
re-emitted in a loop.

Mirror the AskUserQuestion _pending_ask mechanism: when ExitPlanMode
fires, surface plan + a Yes/No hint, set pending state with
kind=exit_plan_mode, and return. On the next run(), parse the reply
(yes/no prefix, CN + EN) and send the matching tool_result so the
CLI can continue. Anything that doesn't match an approval word
defaults to rejection with the reply as feedback, so a plan never
runs without explicit approval.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@quick-sort quick-sort merged commit 2b09579 into main Jun 19, 2026
1 check passed
@quick-sort quick-sort deleted the fix/exit-plan-mode-approval branch June 19, 2026 02:00
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.

ExitPlanMode 后计划被反复发送到 channel

2 participants