kimi-code/docs/zh/reference/keyboard.md
liruifengv 2db5fc20ec
feat: add shell mode (!) to the CLI (#1079)
* feat: add shell mode (`!`) to the CLI

Add shell mode, letting users run shell commands directly from the prompt
with `!`. Output streams live into the transcript, supports backgrounding
(ctrl+b), cancellation (Esc / Ctrl+C), input queuing while running, and
enters the conversation context with resume support.

* feat(kimi-code): show shell mode label on editor border and add tip

Render a "! shell mode" label on the top-left of the editor border while the editor is in `!` bash mode, so the active mode is visible at a glance. Also add a rotating toolbar tip (`! to run a shell command`) to surface the feature.

* feat(kimi-code): refine shell mode queue, history, and display

- Keep `!` commands out of input history so they never resurface as bare text stripped of their `!`.

- Make `!` commands non-steerable: Ctrl-S skips them (they stay queued to run after the current task) and the steer hint is only shown when something is actually steerable.

- Render queued `!` commands with a `$` prompt and the shell-mode hue so they read as commands, not as text to send to the model.

- Echo executed shell commands with a `$` prompt instead of `!`.

* fix(kimi-code): sanitize shell output and harden rendering

Captured shell command output can contain terminal control sequences (colours, cursor moves, alternate-screen switches, OSC hyperlinks, carriage-return spinners, bells). pi-tui's Text passes strings straight to the terminal, so any unhandled sequence was executed by the terminal and fought with pi-tui's own cursor control, producing the blank-screen-plus-leftover-characters mess after running commands like pnpm dev or a nested TUI.

- Sanitize CSI (incl. private modes), OSC, single-char ESC and C0 control chars (keeping newline and tab) in both the finished/resume view (previously unsanitized) and the running tail.

- Make the sanitize, format, and ShellRunComponent render paths never-throw, and cap the live running buffer, so a misbehaving command cannot crash the TUI.

- Dispose transcript children on clear so ShellRunComponent's timer is released on /clear or session switch.

* fix(kimi-code): render shell command echo with $ instead of sparkles

The shell command echo is a 'user' transcript entry, so UserMessageComponent prefixed it with the USER_MESSAGE_BULLET (sparkles), producing 'sparkles $ command'.

Add an optional bullet override to UserMessageComponent / TranscriptEntry and set it to an empty string for the shell echo (both live and resume), so the '$ command' content sits at the leading column where the sparkles marker used to be. Normal user messages keep the sparkles bullet.

* fix(kimi-code): enter shell mode when pasting a !-prefixed command

The bash-mode trigger only handled the single ! keystroke, so a pasted !cmd was inserted as literal text in prompt mode and submitted as a normal message.

After pi-tui inserts pasted content, detect an empty-prompt buffer that now starts with !, switch to bash mode, and strip the leading ! so the buffer holds only the command, matching the typed ! path.

* fix(kimi-code): restore shell mode when recalling a queued command

recallLastQueued() dropped the queued item's mode, and the Up-arrow recall only restored the text. A queued ! command (queued while another command runs, which resets the editor to prompt mode) therefore came back as a normal prompt and was submitted as a message instead of a shell command.

Return the full QueuedMessage from recallLastQueued() and restore editor.inputMode (plus the onInputModeChange sync) from the recalled item's mode.

* feat(kimi-code): use violet as the shell mode color

Replace the claude-code-style magenta/rose shellMode token with a violet that is distinct from plan-mode blue, the user role amber, success green, error red, and the teal accent.

Custom themes that omit the token fall back to this new default via the base+overrides merge, so existing custom themes keep working unchanged.

* chore: refine the shell mode changeset

* docs: document shell mode

Add a Shell mode section to the interaction guide and list the ! and Ctrl+B shortcuts in the keyboard reference, in both English and Chinese.

* test(protocol): include shell events in volatile classification check

shell.output and shell.started were added as volatile event types for shell mode; update the snapshot test's volatile-type list and count accordingly.

* fix(agent-core): surface shell command failure reason with no output

When a ! shell command fails without producing stdout/stderr (non-zero exit with no output, timeout, spawn failure), the failure reason lived only in the tool result's output and the TUI showed '(no output)'. Fold it into stderr so the live view and replay show what went wrong.

* fix(kimi-code): decode CSI-u ! to enter shell mode

In terminals with the Kitty keyboard protocol (VSCode integrated terminal, Kitty), pressing ! arrives as a CSI-u sequence, so the raw normalized === '!' comparison never matched and shell mode could not be entered by typing !. Decode with printableChar before comparing, matching every other printable-key check in the TUI.

* fix(kimi-code): do not steer while a shell command is running

Ctrl-S steers queued input into the running turn, but a shell command is not an agent turn, so steering during streamingPhase === 'shell' would launch a turn before the command output is recorded. Keep Ctrl-S a no-op during shell runs; queued messages stay queued.

* fix(agent-core): escape bash tag delimiters in shell output

Shell command output is arbitrary text; if it contains a bash tag delimiter such as </bash-stdout>, the recorded pseudo-XML wrapper breaks and replay extracts the wrong slice. Escape the content when wrapping it in agent-core and unescape when extracting during replay, so output survives round-trip intact.

* docs: document the shellMode theme token

The shellMode color token was added to the palette but not propagated to its mirrors. Add it to the custom-theme docs token table, the theme JSON schema, and the custom-theme skill token list.

* feat(agent-core): reset background task deadline on detach

Add a resettable deadline timer to BackgroundManager and let tasks register a detach timeout; when a foreground task is moved to the background, its deadline resets to the background default counted from the detach moment.

Wire this into shell mode so ! commands run with a 3-minute foreground timeout and get 10 minutes once detached to the background, instead of staying bounded by the original 60-second foreground deadline.

* feat(agent-core): lower shell mode foreground timeout to 2 minutes
2026-06-25 21:24:53 +08:00

4.3 KiB
Raw Blame History

键盘快捷键

Kimi Code CLI 的 TUI 交互模式支持一套键盘快捷键。键位按使用场景分为五组:通用输入、模式切换、流式输出期间、工具输出控制、审批面板,以及弹窗浏览。在 TUI 中输入 /help 可随时打开内置快捷键清单。

通用快捷键

以下键位在输入框中始终可用:

快捷键 功能
Enter 提交当前输入
Shift-Enter / Ctrl-J 在输入中插入换行
/ 浏览输入历史
Esc 关闭弹窗 / 取消补全 / 中断流式输出或上下文压缩
Ctrl-C 中断当前流式输出,或清空输入框
Ctrl-D 在输入框为空时退出 Kimi Code CLI
Ctrl-T 待办列表被截断时,展开或折叠完整列表

流式输出期间Ctrl-C 会立即取消,无需二次确认。

退出程序(输入框为空时按 Ctrl-C,或按 Ctrl-D)使用「双击确认」机制:第一次按下后状态栏会出现提示,再按一次相同的键才真正退出。中途按其他键会清除确认状态。

模式切换

快捷键 功能
Shift-Tab 切换 Plan 模式
! 在空输入框中进入 Shell 模式

Shift-Tab 可开启或关闭 Plan 模式。开启后Agent 会优先使用只读工具进行研究和规划,并可写入当前计划文件;Bash 按当前权限模式和普通规则处理,不会因 Plan 模式额外发起独立审批。单纯切换模式不会创建空计划文件。再次按 Shift-Tab 退出 Plan 模式。

在空输入框中键入 ! 进入 Shell 模式,可直接运行终端命令;命令运行期间按 Ctrl+B 可将其转为后台任务。详见交互与输入

输入与编辑

快捷键 功能
Ctrl-G 在外部编辑器中编辑当前输入
Ctrl-V 粘贴剪贴板中的图片或视频Unix / macOS
Alt-V 粘贴剪贴板中的图片或视频Windows
Ctrl-- 撤销Undo

Ctrl-G 会打开外部编辑器,编辑器按以下优先级选择:

  1. /editor 命令配置的编辑器
  2. $VISUAL 环境变量
  3. $EDITOR 环境变量

保存并退出后,编辑内容替换输入框;不保存退出则保持原样。

粘贴图片或视频时输入框中显示占位符实际媒体数据在提交时一并发送给模型。优先从系统剪贴板读取Linux 上会尝试 Wayland 与 X11WSL 下还会通过 PowerShell 兜底读取 Windows 剪贴板。

流式输出期间

流式输出streaming期间输入框依然可以接收输入并支持以下额外操作

快捷键 功能
Ctrl-S Steer将当前输入立即注入正在运行的轮次
Esc 中断当前流式输出
Ctrl-C 中断当前流式输出

Ctrl-S 时,模型会在下一个可中断的时机立刻看到你的消息,无需等待当前轮次结束。

工具输出

快捷键 功能
Ctrl-O 展开或折叠工具输出

历史中存在折叠的工具调用结果时,按 Ctrl-O 可在折叠和展开之间切换。

审批面板

当 Agent 发起需要确认的工具调用时TUI 会弹出审批面板。详细审批流程见交互与输入,面板内可用键位如下:

快捷键 功能
/ 在候选选项之间移动光标
Enter 确认当前选中的选项
1 ~ 9 直接选择对应序号的选项
Esc / Ctrl-C / Ctrl-D 拒绝当前请求
Ctrl-E 面板包含 diff 或文件内容预览时,展开或折叠完整内容
Ctrl-O 切换其他工具输出的折叠状态

需要附带反馈的选项如「Reject」「Revise」会在确认后切换到反馈输入态直接输入反馈文本Enter 提交;按 Esc 退出反馈输入并回到候选列表。

弹窗模式

输入 /help 打开帮助面板后,可使用以下键位浏览和关闭面板:

快捷键 功能
/ 单行滚动
PageUp / PageDown 每次滚动 10 行
Esc / Enter / q / Q 关闭面板

下一步