Skip to content

feat(tui): add follow_up_behavior to choose whether Enter queues or steers - #4890

Merged
Grapedge merged 8 commits into
mainfrom
tui-follow-up-behavior
Nov 13, 2026
Merged

Grapedge merged 8 commits into
mainfrom
tui-follow-up-behavior

Conversation

@Grapedge

@Grapedge Grapedge commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

Agent 工作期间按 Enter,消息会排进队列,等当前轮次结束才发出;想立即插话只能按 Ctrl-S,而 Ctrl-S 会把输入框和整个队列一起注入。很多用户更希望忙时按 Enter 就直接插话。这个 PR 新增 tui.toml 偏好 follow_up_behavior(queue | steer,默认 queue),也可以在 /settings → Follow-up behavior 中切换。选 Steer 后,Enter 只把输入框里这一条注入正在运行的轮次。默认值下行为不变。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

核心思路。 每次提交多带一个“投递方式”。编辑器记下是哪个键触发的提交,提交时按当前偏好查一张固定的表,得到 default(今天 Enter 走的路径)、steer-draft(只注入这一条,不碰队列)或 queue(忙时一定排队)。default 走的代码和今天完全相同。steer-draft 在当前无法注入时退回 default。

偏好 Enter Ctrl-Enter / Cmd-Enter Ctrl-Q
queue(默认) 今天的 Enter 只注入这一条 排队
steer 只注入这一条 排队 排队

“今天的 Enter”指:忙时排队(Tower 模式或 WaitFor 期间连同队列一起注入),空闲时直接发送。“排队”指:忙时一定排队,Tower 模式和 WaitFor 期间也一样,空闲时直接发送;这样排进去的消息不会被 Tower / WaitFor 自动注入,Ctrl-S 仍会把它一起注入。Ctrl-S 不变。

flowchart TD
  K[Enter / Ctrl-Enter / Cmd-Enter / Ctrl-Q] --> T{偏好 × 按键}
  T -- default --> D[今天的 Enter 路径]
  T -- queue --> H[忙时排队,等回合结束]
  T -- steer-draft --> C{现在能注入吗}
  C -- 能 --> S[只注入这一条,队列原样保留]
  C -- 不能 --> D
  S -- 注入失败 --> Q[放回队列原位置并报错]
Loading

“不能注入”包括:空闲、! shell 命令在跑、正在压缩、消息被暂缓、上一条注入还没完成、bash 模式输入、内置斜杠命令。这些情况下按键效果和今天的 Enter 一样,不会吞掉消息。

决策 选择 没选 理由
显式排队键 Ctrl-Q Alt-Enter 旧式终端里 Alt-Enter 发 \x1b\r,今天会插入换行,绑定它会破坏现有用法
Ctrl-Enter 的提示 终端确认支持 kitty 键盘协议时,/settings 和 /help 才提到 Ctrl-Enter;文档不写 始终提示 Windows Terminal、macOS Terminal.app 认不出 Ctrl-Enter(Windows Terminal 里它和 Ctrl-J 是同一个字节,会插入换行)。按键绑定在所有终端都保留
已排着 /compact 或模型切换时按 steer 键 照样注入当前回合 排到它后面 steer 键不碰队列,不会让排队的消息插队;被注入的消息属于当前回合,之后的压缩会包含它
未设置时的 tui.toml 写注释行 # follow_up_behavior = "queue" # "queue" | "steer" 写入默认值 只有用户主动选择后才写入真实值
阅读指南
  1. apps/kimi-code/src/tui/config.ts:偏好的解析、渲染,以及“偏好 × 按键 → 投递方式”的表。
  2. components/editor/custom-editor.ts:把 Ctrl-Enter、Cmd-Enter、Ctrl-Q 当作提交,并记下提交键。
  3. controllers/editor-keyboard.ts:提交时查表。
  4. kimi-tui.ts 的 trySteerDraft 和 sendMessage:注入一条草稿,失败时放回队列原位置;queue 投递把消息标成 holdUntilTurnEnds,Tower / WaitFor 的自动注入会跳过它。
  5. commands/config.ts、dialogs/follow-up-behavior-selector.ts、dialogs/help-panel.ts:/settings 入口和帮助面板。

steerMessage 的回调从布尔值改成三态(steered / failed / restored),现有调用方的分支不变。可以略读:dispatch.ts 和各发送方法的参数透传、文档、测试。

Screenshots / Recordings

以下文本快照来自本分支在支持 kitty 键盘协议的终端里的真实运行。终端认不出 Ctrl-Enter 时,选择器的 Queue 只写前半句,Steer 写 Ctrl-Q queues one.,/help 不显示 Ctrl-Enter 这一行。

/settings 第 2 页新增的一项:

   ❯ Editor
     Set the external editor command.
     Follow-up behavior
     Choose whether to queue follow-ups or steer the current turn.

选中后打开的选择器:

  Follow-up behavior
  ↑↓ navigate · Enter select · Esc cancel
   ❯ Queue ← current
     Enter queues follow-ups until Kimi finishes. Ctrl-Enter steers one.
     Steer
     Enter steers follow-ups into the current turn. Ctrl-Enter queues one.

切到 Steer 之后,tui.toml 写入:

follow_up_behavior = "steer" # "queue" | "steer"

/help 中相关的几行(Queue,默认):

     Ctrl-S                Steer — inject a follow-up during streaming
     Enter                 Submit; queues while Kimi is working
     Ctrl-Enter            Submit; steers into the running turn
     Ctrl-Q                Submit; queues while Kimi is working

/help 中相关的几行(Steer):

     Ctrl-S                Steer — inject a follow-up during streaming
     Enter                 Submit; steers into the running turn
     Ctrl-Enter            Submit; queues while Kimi is working
     Ctrl-Q                Submit; queues while Kimi is working

Behavior Changes and Affected Users

行为 改动前 改动后 谁依赖旧行为 退路
未设置或 queue 时的 Enter;任何偏好下的 Ctrl-S — 不变 所有 TUI 用户 不需要
Ctrl-Enter / Cmd-Enter(终端能区分时,如支持 kitty 键盘协议的终端) 无反应 空闲时发送;忙时按上表注入或排队 无(之前无反应) 不需要
Ctrl-Enter(Windows Terminal、Terminal.app 等区分不了的终端) 按终端发出的普通字节处理 不变(只有 kitty 或 modifyOtherKeys 编码才会被认成 Ctrl-Enter) — —
Ctrl-Q 无反应 空闲时发送;忙时排队,Tower 模式和 WaitFor 期间也排队 无 不需要
Tower / WaitFor 期间,队列里有 Ctrl-Q 排的消息时按 Enter — 排队,不再自动注入(和队列里有 shell 命令或 skill 时一致);Ctrl-S 仍可一起注入 Tower 用户 Ctrl-S
tui.toml 被 TUI 重写时 没有这一行 多一行注释;在 /settings 选过之后写真实值 用 dotfile 管理 tui.toml 的用户会看到新行 无害,不需要
tui.toml 写了非法值 — 忽略并告警,按 queue 处理 — 改成合法值
/settings 列表 — 第 2 页 Editor 之后新增一项,其后几项下移一位 靠方向键记忆位置的用户 —
/help 快捷键 Enter 描述为 “Submit” Enter 描述随偏好变化;多一行 Ctrl-Q;终端支持时再多一行 Ctrl-Enter — —

已知限制:引擎要等消息真正注入后才确认 steer(#4630 起如此)。所以在一次很长的工具调用期间,steer 下第一次 Enter 会注入,之后的 Enter 退回排队,直到第一条被 Agent 接收。同一窗口内 Ctrl-S 也不起作用,这是 main 上的现有行为。

测试覆盖:

  • test/tui/config.test.ts:解析、注释行与真实值的渲染、非法值告警。
  • test/tui/commands/follow-up-preferences.test.ts:/settings 保存、未变化时不重写、保存失败、选择器文案随终端能力变化。
  • test/tui/components/editor/custom-editor.test.ts、test/tui/controllers/editor-keyboard.test.ts:三个键都能提交,并保留 Enter 的特殊情况(补全、\ 续行、粘贴中的 Enter)。
  • test/tui/kimi-tui-message-flow.test.ts:只注入草稿、各种退回、失败放回队列、Tower 下不带走已有队列、Tower 下 Ctrl-Q 一定排队、/help 行随偏好和终端能力变化。
  • test/tui/components/panels/help-panel.test.ts、test/tui/commands/reload.test.ts:帮助面板各组合、/reload 读取新值。
验证
  • pnpm exec vitest run test/tui:173 个文件、3785 个测试全部通过;每个 commit 各自单独通过 typecheck 和该 commit 改到的测试。新增的 Tower 排队测试做过反向验证:去掉修复后 5 条变红。
  • 在 macOS 上用支持 kitty 键盘协议的终端跑真实 TUI:queue 下 Enter 排队、Ctrl-Enter 只注入草稿并在同一轮次被读到、Ctrl-Q 排队;/settings 切到 Steer 后写入 follow_up_behavior = "steer" # "queue" | "steer",Enter 只注入这一条,Ctrl-Enter / Ctrl-Q 排队,/help 描述随之变化。这次运行早于 Tower / WaitFor 强制排队的 commit,强制排队只有单测覆盖。
  • 最新 commit 上,删掉 tui.toml 后启动 TUI,重新生成的文件里是注释行 # follow_up_behavior = "queue" # "queue" | "steer";默认设置下 /help 列出 Enter、Ctrl-Enter、Ctrl-Q 三行(见上方快照)。
  • 未验证:Windows(PowerShell、Windows Terminal、VS Code 终端)上的实际按键,以及只支持 modifyOtherKeys 的终端。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Copilot AI balanced review requested due to automatic review settings November 12, 2026 19:06
@changeset-bot

changeset-bot Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7c96859

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Minor

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T19:55:52.530660Z 7c96859 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@7c96859
npx https://pkg.pr.new/@moonshot-ai/kimi-code@7c96859

commit: 7c96859

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The steer-draft submission path bypasses queued compaction and model-switch barriers, allowing messages to enter pre-compaction context or use the old model.

1 open issue
What changed in this PR

此 PR 为 TUI 新增 follow_up_behavior 偏好,让用户选择忙时按 Enter 排队或仅注入当前草稿;默认保持排队行为,并接入现有配置、设置和消息投递流程。

Changes:

  • 支持偏好解析、保存、重载及 /settings 切换。
  • 新增提交键映射和单草稿注入路径,处理不可注入与失败回退。
  • 更新终端能力相关帮助、中英文文档及配置、键盘和消息流测试。
File Description
docs/​zh/​reference/​keyboard.md 补充排队快捷键与 Enter 偏好说明。
docs/​zh/​guides/​interaction.md 说明忙时 Enter 的可选行为。
docs/​zh/​configuration/​config-files.md 记录新配置项及示例。
docs/​en/​reference/​keyboard.md 同步英文快捷键说明。
docs/​en/​guides/​interaction.md 同步英文交互说明。
docs/​en/​configuration/​config-files.md 同步英文配置参考。
apps/​kimi-code/​test/​tui/​kimi-tui-message-flow.test.ts 覆盖草稿注入、失败恢复、回退及按键行为。
apps/​kimi-code/​test/​tui/​fullscreen-layout.test.ts 调整设置列表分页断言。
apps/​kimi-code/​test/​tui/​controllers/​editor-keyboard.test.ts 验证偏好与提交键映射。
apps/​kimi-code/​test/​tui/​config.test.ts 验证解析、告警及配置往返保存。
apps/​kimi-code/​test/​tui/​components/​panels/​help-panel.test.ts 验证不同偏好与终端能力下的帮助内容。
apps/​kimi-code/​test/​tui/​components/​editor/​custom-editor.test.ts 覆盖新增提交键及编辑器特殊输入。
apps/​kimi-code/​test/​tui/​commands/​reload.test.ts 验证重载和移除偏好。
apps/​kimi-code/​test/​tui/​commands/​follow-up-preferences.test.ts 覆盖设置选择、持久化及保存失败。
apps/​kimi-code/​src/​tui/​types.ts 增加偏好状态及注入结果类型。
apps/​kimi-code/​src/​tui/​kimi-tui.ts 实现单草稿注入、恢复及动态帮助接入。
apps/​kimi-code/​src/​tui/​controllers/​editor-keyboard.ts 根据偏好和按键选择投递方式。
apps/​kimi-code/​src/​tui/​config.ts 定义偏好、键位映射及配置读写。
apps/​kimi-code/​src/​tui/​components/​editor/​custom-editor.ts 识别并记录新增提交键。
apps/​kimi-code/​src/​tui/​components/​dialogs/​settings-selector.ts 新增 Follow-up behavior 入口。
apps/​kimi-code/​src/​tui/​components/​dialogs/​help-panel.ts 按偏好和终端能力生成快捷键说明。
apps/​kimi-code/​src/​tui/​components/​dialogs/​follow-up-behavior-selector.ts 提供 Queue / Steer 选择器。
apps/​kimi-code/​src/​tui/​commands/​reload.ts 将重载后的偏好应用到运行状态。
apps/​kimi-code/​src/​tui/​commands/​dispatch.ts 透传消息投递方式。
apps/​kimi-code/​src/​tui/​commands/​config.ts 接入设置选择器并保存偏好。
.changeset/​follow-up-behavior.md 添加用户可见功能的发布说明。

Review effort: Balanced

Comment thread apps/kimi-code/src/tui/kimi-tui.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 956e17fb82

ℹ️ 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".

Comment thread apps/kimi-code/src/tui/config.ts Resolved
Comment thread apps/kimi-code/src/tui/kimi-tui.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed5fd9f359

ℹ️ 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".

Comment thread apps/kimi-code/src/tui/kimi-tui.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7c9685910e

ℹ️ 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".

Comment thread apps/kimi-code/src/tui/config.ts Resolved
@Grapedge
Grapedge merged commit 90d3a66 into main Nov 13, 2026
28 of 29 checks passed
@Grapedge
Grapedge deleted the tui-follow-up-behavior branch November 13, 2026 05:14
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.

3 participants