Repository navigation
feat(tui): allow /model and /effort while the agent is busy - #4621
Conversation
🦋 Changeset detectedLatest commit: 0dc8a26 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 12e1c850b2
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
🟡 Changes recommended
A dispatch race lets Ctrl-S or Tower auto-steering send subsequent messages before a pending model or thinking-setting change finishes, so they may run with stale settings.
1 open issue
What changed in this PR
本 PR 允许 TUI 在 Agent 忙碌时切换模型和思考强度,并通过队列协调“先压缩、后切换”的执行顺序。
Changes:
/model、/effort忙时可用,提示新设置从下一轮生效。- 新增模型切换队列项,支持压缩去重、主 Agent 事件过滤及转向屏障。
- 补充命令、消息流和面板测试,更新中英文文档与 changeset。
| File | Description |
|---|---|
docs/zh/reference/slash-commands.md |
说明忙时切换的生效时机。 |
docs/en/reference/slash-commands.md |
同步英文命令说明。 |
apps/kimi-code/test/tui/kimi-tui-message-flow.test.ts |
覆盖切换队列顺序、失败处理和撤回。 |
apps/kimi-code/test/tui/components/panes/queue-pane.test.ts |
验证切换项展示与转向提示。 |
apps/kimi-code/test/tui/commands/model-switch-confirm.test.ts |
覆盖忙时确认、状态提示和压缩事件过滤。 |
apps/kimi-code/src/tui/utils/model-switch.ts |
移除忙时拦截,增加下一轮生效提示。 |
apps/kimi-code/src/tui/types.ts |
将队列项改为联合类型,新增切换项。 |
apps/kimi-code/src/tui/kimi-tui.ts |
接入切换项入队、分派和转向屏障。 |
apps/kimi-code/src/tui/controllers/staging-leases.ts |
限定仅从提示消息释放媒体资源。 |
apps/kimi-code/src/tui/controllers/session-event-handler.ts |
记录压缩次数,并在队列占用时暂停出队。 |
apps/kimi-code/src/tui/components/panes/queue-pane.ts |
展示目标模型、思考强度及排队提示。 |
apps/kimi-code/src/tui/commands/dispatch.ts |
扩展命令宿主的队列控制接口。 |
apps/kimi-code/src/tui/commands/config.ts |
实现忙时确认及持有队列的压缩后切换流程。 |
.changeset/busy-model-switches.md |
记录用户可见功能变化。 |
Review effort: Balanced
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 25a9bde5a2
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 12502230d8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0dc8a26693
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Port of upstream MoonshotAI/kimi-code 1b13934 (MoonshotAI#4621). A model or effort switch no longer errors out while a turn runs. A turn that has already sent its first request keeps the model it was launched with, and the switch applies from the next turn; before that first request the switch lands immediately. Choosing Compact and continue while busy queues the whole action: the queued item is a FIFO barrier like a queued /compact, so prompts behind it wait, the compaction runs when the queue drains, and it is skipped when another compaction completed in the meantime. A child agent's compaction no longer completes the wait. Local-form adaptations, because this fork's queue diverged from upstream's: - The queued item type is a five-variant union here (prompt / bash / skill / compact / model-switch); upstream has four. Steering narrows to QueuedPromptMessage | QueuedSkillActivation so the fork's slash-skill queueing keeps working, and the two dispatcher copies (KimiTUI and MessageDispatchController) both handle the new mode instead of sending the item's /model text as a prompt. - New user-facing copy goes through t() with en/zh keys (4 keys) instead of upstream's literal strings, and the queue row names the model and effort. - compactForModelSwitch detects compaction.unable by error code rather than isKimiError: the SDK normalizes RPC failures across the boundary, so the rejection is not an Error2 instance and the type guard never matched. - The fork's runModelSwitchAction keeps its extra 'new' action; only the 'compact' arm gained the busy branch. - QueuePaneComponent is a Container with its own row budget here rather than upstream's DockSection, so the model-switch row renders inline. Also adds the missing wire.version_too_low error copy (en/zh) that MoonshotAI#4638 left behind; check:t-coverage failed on it. Verified: app typecheck clean; kimi-tui-message-flow 408 tests (407 pass, 1 skipped), model-switch-confirm 21, queue-pane 12, session-event-handler compaction/goal-queue + program-status + create-tui-state 40, editor-keyboard + staging-leases 73; check:locale-keys, check:locale-placeholders, check:t-coverage, check:no-hardcoded-prose and check:no-comments green; oxlint --type-aware 0 errors on the touched files. Reverse checks: dropping model-switch from the barrier predicate reddens the Ctrl-S and queue-pane cases, forcing busy=false reddens the queued-compact case, and removing the next-turn suffix reddens two notice cases.
Ports the docs half of upstream MoonshotAI/kimi-code 8b6a003 (MoonshotAI#4673): the 2.5.0 section from the upstream release notes lands in both changelogs, en and zh, word for word. Every feature the section names is in this tree - busy /model and /effort (MoonshotAI#4621), merged project-level skills (MoonshotAI#4520), remote sessions in SSH, Docker and custom-command environments (MoonshotAI#4062), [workspace] require_trust (MoonshotAI#4517), web search off by default (MoonshotAI#4516), and the subagent model pool (MoonshotAI#4418) - so the notes describe what the fork actually does. Deliberately not touched: apps/kimi-code/CHANGELOG.md still tops out at 2.4.1 and package.json still says 2.4.1. That file is generated by `changeset version`, this tree has 377 pending changesets, and AGENTS.md forbids running version or publish from this repository, so the entry is written on the docs side only. Whoever next cuts a release here should reconcile this section with what changeset version generates rather than re-deriving it by hand.

Requirement or Bug
agent 忙时(模型回复中、压缩中、
!命令运行中)输入/model或/effort,会先弹出选择器,选完才报Cannot switch models while streaming — press Esc or Ctrl-C first.,用户白选一次。这个 PR 之后,忙时可以直接切换,从下一轮开始生效。Kimi 官方模型的切换确认框忙时也照常弹出;选 Compact and continue 会排进消息队列,等当前这一轮结束后先用旧模型压缩,再切到新模型。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路
引擎在每一轮第一次请求时固定模型和思考强度,所以 TUI 不再拦截忙时切换:设置立即写入,当前这一轮剩下的请求仍用旧设置,下一轮用新设置。Compact and continue 不一样:压缩请求不属于任何一轮,读的是当时的模型,所以必须先压缩、后切换。忙时选它,就往消息队列里放一个“先压缩再切换”的条目,和普通消息、
!命令、排队的/compact一起先进先出。关键决策
mode区分的联合类型/compact的字段混用走一遍
sequenceDiagram participant User participant TUI participant Engine User->>TUI: 忙时选 Compact and continue TUI->>TUI: 队列加入“先压缩再切换” Engine-->>TUI: 当前这一轮结束 TUI->>Engine: 用旧模型压缩 Engine-->>TUI: 主 agent 压缩完成 TUI->>Engine: 切换模型和思考强度 TUI->>Engine: 发出队列里的下一条切换完成之前,队列保持占用,压缩完成事件不会提前发出下一条消息,所以下一条一定用新模型。
阅读指南
apps/kimi-code/src/tui/commands/config.ts:确认框忙时不再被跳过;Compact and continue 忙时入队、空闲时直接执行;出队执行和队列占用都在这里。apps/kimi-code/src/tui/utils/model-switch.ts:删掉忙时拦截,忙时切换成功的提示追加Takes effect from the next turn.。apps/kimi-code/src/tui/types.ts:队列条目改成联合类型,新增模型切换条目。apps/kimi-code/src/tui/kimi-tui.ts、controllers/session-event-handler.ts、components/panes/queue-pane.ts:入队、出队分派、Ctrl-S 屏障、压缩计数和面板显示。可以略读:
staging-leases.ts和kimi-tui.ts里按联合类型收窄的接线。Screenshots / Recordings
忙时切换,改动前:
改动后,普通模型直接切换:
改动后,命中云端规则时,忙时照常弹出确认框(规则说明由云端下发,这里是本地测试配置):
选 Compact and continue 后,队列面板显示模型切换项:
Behavior Changes and Affected Users
/model、/effort、/settings的 Model 项Takes effect from the next turn./compact是屏障/compact的排队与跳过已知、这次不处理的行为:
受影响模块与测试:
model-switch-confirm.test.ts覆盖忙时确认框、直接切换的提示、入队和只认主 agent 的压缩事件;kimi-tui-message-flow.test.ts覆盖出队顺序、切换完成前新输入继续排队、压缩失败或取消后继续处理队列、跳过压缩的提示、Ctrl-S 屏障、↑ 撤回和/new清空;queue-pane.test.ts覆盖面板显示和 Ctrl-S 提示。验证
pnpm --filter @moonshot-ai/kimi-code typecheck通过。/model和/effort,请求日志显示当前这一轮仍用旧模型和旧强度,下一轮用新的。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.