Repository navigation
feat(tui): default to fullscreen mode when experimental flag is set - #4771
Conversation
🦋 Changeset detectedLatest commit: 2d7bc1a 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 Summary: ✅ CompletedThis 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: 1aa9aec6f4
ℹ️ 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
Explicit Fullscreen selections can fail to persist, and restart guidance is misleading when environment overrides or terminal fallbacks prevent the saved preference from taking effect.
3 open issues
What changed in this PR
本 PR 将 TUI 的磁盘显式偏好与运行时模式分开,避免首次启动或修改无关设置时自动保存 regular,并在实验开关开启且未配置模式时默认使用全屏布局。
Changes:
- 集中解析模式优先级,支持进程级环境变量覆盖和不兼容终端自动回退。
- 启动、设置与重载流程接入模式解析,并补充模式相关遥测。
- 更新回归测试、中英文配置文档和发布说明。
| File | Description |
|---|---|
docs/zh/configuration/env-vars.md |
说明模式覆盖变量和终端检测变量。 |
docs/zh/configuration/config-files.md |
更新默认模式说明及注释配置示例。 |
docs/en/configuration/env-vars.md |
同步英文环境变量说明。 |
docs/en/configuration/config-files.md |
同步英文配置说明及示例。 |
apps/kimi-code/test/tui/create-tui-state.test.ts |
验证运行时模式不改写显式偏好。 |
apps/kimi-code/test/tui/config.test.ts |
覆盖配置持久化、模式优先级和终端回退。 |
apps/kimi-code/test/tui/commands/tui-mode-preferences.test.ts |
覆盖模式保存、切换遥测及无关偏好保存。 |
apps/kimi-code/test/tui/commands/reload.test.ts |
覆盖实验默认全屏下的重载提示。 |
apps/kimi-code/test/cli/run-shell.test.ts |
覆盖启动模式解析与遥测字段。 |
apps/kimi-code/src/tui/types.ts |
增加运行时模式选项。 |
apps/kimi-code/src/tui/tui-state.ts |
根据已解析模式选择渲染器。 |
apps/kimi-code/src/tui/kimi-tui.ts |
透传运行时模式。 |
apps/kimi-code/src/tui/config.ts |
分离显式偏好与模式解析,保留未配置状态。 |
apps/kimi-code/src/tui/commands/reload.ts |
按解析后的模式判断重启提示。 |
apps/kimi-code/src/tui/commands/config.ts |
调整模式选择判断并记录切换事件。 |
apps/kimi-code/src/cli/run-shell.ts |
接入模式解析及启动、退出遥测。 |
.changeset/fullscreen-experimental-default.md |
添加实验开关下默认全屏的发布说明。 |
Review effort: Balanced
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8e6ffab68d
ℹ️ 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: 29fe852e63
ℹ️ 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 upstream MoonshotAI#4771. Resolve the effective TUI mode from the configured preference, the experimental flag, and terminal fallbacks (tmux control mode, Termux, dumb terminals), with KIMI_CODE_TUI_FULL_SCREEN as an env override. Stop persisting tui_mode unless explicitly chosen, thread the resolved mode through startup and telemetry, and surface env-override / fallback notices when picking a mode.


Requirement or Bug
之前首次启动生成
~/.kimi-code/tui.toml,或在/settings修改主题、编辑器等无关偏好时,都会把未注释的tui_mode = "regular"写入磁盘,导致用户未曾主动选择界面模式也被锁定在regular主屏模式。本 PR 停止持久化未显式配置的tui_mode,在开启KIMI_CODE_EXPERIMENTAL_FLAG且未配置tui_mode时默认启用fullscreen备用屏模式,并为不兼容备用屏的终端环境补充自动回退与模式分布遥测。Bug Reproduction Steps
~/.kimi-code/tui.toml后启动kimi,或在未配置tui_mode的tui.toml下执行/theme dark修改任意无关偏好。~/.kimi-code/tui.toml,文件中被写入未注释的tui_mode = "regular"。Root Cause
DEFAULT_TUI_CONFIG与normalizeTuiConfig将缺省的tui_mode统一填充为'regular',导致TuiConfig.tuiMode无法区分「用户在tui.toml显式配置了regular」与「未配置」。由于saveTuiConfig每次保存都会通过renderTuiConfig重写整份文件,缺省值随之落盘。本次为根本修复,将磁盘显式偏好(TuiMode | undefined)与运行时解析结果(TuiModeResolution)拆开建模。Code Changes
核心思路
将
TuiConfig.tuiMode限定为仅表达tui.toml中的显式配置(未设置时保持undefined,渲染为注释行# tui_mode = "regular"),新增纯函数resolveTuiMode统一根据环境变量覆盖、tui.toml配置、实验开关与终端环境计算实际生效模式,并在startup_perf、exit与tui_mode_switch中上报配置来源与回退原因。现有显式配置了tui_mode的用户行为保持不变(命中终端不兼容回退时除外)。概念
TuiConfig.tuiModetui.toml里是否显式写了tui_mode'regular' | 'fullscreen' | undefined;undefined时渲染为# tui_mode = "regular"注释行,修改其他设置不再落盘tui_modeTuiModeResolution{ mode, config, fallback },由resolveTuiMode(configuredMode, env)在启动与重载入口计算结构与判定流程
flowchart TD S([CLI 启动 runShell / 重载 reload]) --> L[loadTuiConfig 读取 tui.toml<br/>未设置时 tuiMode 保持 undefined] L --> E{KIMI_CODE_TUI_FULL_SCREEN<br/>是否设置布尔值?} E -- 真值 1/true/yes/on --> F1[mode = fullscreen<br/>跳过终端回退, 不改写 tui.toml] E -- 假值 0/false/no/off --> R1[mode = regular<br/>不改写 tui.toml] E -- 未设置 --> P{偏好模式判定:<br/>tui.toml 显式值 ??<br/>KIMI_CODE_EXPERIMENTAL_FLAG} P -- regular --> R2[mode = regular] P -- fullscreen --> FB{检测终端回退:<br/>tmux -CC / TERMUX_VERSION / TERM=dumb} FB -- 命中 --> R3[mode = regular<br/>记录 fallback 原因] FB -- 未命中 --> F2[mode = fullscreen]因为终端兼容性问题(iTerm2 的
tmux -CC控制模式、Android Termux 触屏滚动、TERM=dumb哑终端)取决于当前连接的宿主终端而非主目录配置文件,所以自动回退置于tui.toml之后、KIMI_CODE_TUI_FULL_SCREEN强制覆盖之下;当用户确需在受限终端尝试全屏时,仍可用KIMI_CODE_TUI_FULL_SCREEN=1绕过回退且不污染配置文件。关键决策
runShell与/reload-tui显式调用resolveTuiMode,把resolvedTuiMode传给KimiTUIcreateTUIState内部直接读process.envTERM=dumb,开发机常设KIMI_CODE_EXPERIMENTAL_FLAG=1;在入口解析能让直接构造createTUIState的组件单测保持纯确定性,不受宿主 shell 环境干扰KIMI_CODE_TUI_FULL_SCREEN语义tui.tomlfullscreen写入tui.toml的旧迁移逻辑KIMI_CODE_*环境变量覆盖语义对齐,同时提供不改写配置文件的单次切回regular或强制fullscreen退路阅读指南
apps/kimi-code/src/tui/config.ts:看TuiConfig.tuiMode的缺省语义、renderTuiConfig的注释行输出,以及detectTuiModeFallback和resolveTuiMode的完整优先级。apps/kimi-code/src/cli/run-shell.ts:看启动期如何计算tuiModeResolution,并将tui_mode_config与tui_mode_fallback注入startup_perf和exit遥测事件。apps/kimi-code/src/tui/commands/config.ts与apps/kimi-code/src/tui/commands/reload.ts:看设置选择器如何基于有效模式判断变更与重启提示,并上报tui_mode_switch。其余文件(
kimi-tui.ts、tui-state.ts、types.ts、测试与中英文配置文档)为resolvedTuiMode透传、用例覆盖与文档同步,可略读。具体变化大纲
Behavior Changes and Affected Users
tui.toml未设置tui_mode且开启KIMI_CODE_EXPERIMENTAL_FLAG(1/true/yes/on)时的默认界面模式regular主屏模式fullscreen备用屏模式(命中终端回退时回退regular)KIMI_CODE_EXPERIMENTAL_FLAG但希望留在主屏模式的 TUI 交互用户~/.kimi-code/tui.toml设置tui_mode = "regular",或设置环境变量KIMI_CODE_TUI_FULL_SCREEN=0tui.toml或在 TUI 内修改无关偏好(/theme、/editor、复制与折叠设置等)时的tui_mode落盘行为tui_mode = "regular"写入tui.tomltui_mode未显式设置时保持注释行# tui_mode = "regular",不自动落盘regular/settings -> TUI mode选择或已在tui.toml显式配置的值仍原样保留)tui.toml取消注释tui_mode = "regular"或在/settings -> TUI mode中显式选择KIMI_CODE_TUI_FULL_SCREEN环境变量行为'1',且在tui.toml未设置tui_mode时把tui_mode = "fullscreen"持久写入磁盘1/true/yes/on强制fullscreen且跳过终端回退;假值0/false/no/off强制regular),不再改写tui.tomlKIMI_CODE_TUI_FULL_SCREEN=1把偏好永久写入tui.toml的 TUI 用户(已落盘的老配置不受影响)/settings -> TUI mode选择Fullscreen或在tui.toml写入tui_mode = "fullscreen"tmux -CC控制模式、Android Termux(TERMUX_VERSION)或TERM=dumb终端下请求fullscreen\x1b[?1049h备用屏regular主屏模式KIMI_CODE_TUI_FULL_SCREEN=1强制启用fullscreenstartup_perf、exit、tui_mode_switch)startup_perf与exit仅上报tui_modestartup_perf与exit新增tui_mode_config与tui_mode_fallback;设置切换新增tui_mode_switchKIMI_DISABLE_TELEMETRY与telemetry = false同样生效)受影响模块与测试覆盖:
apps/kimi-code/src/tui/config.ts:apps/kimi-code/test/tui/config.test.ts覆盖默认注释输出、修改无关配置不落盘tui_mode、显式regular/fullscreen往返保留(钉住显式regular在KIMI_CODE_EXPERIMENTAL_FLAG=1下仍保持regular的旧行为)、三种终端自动回退及KIMI_CODE_TUI_FULL_SCREEN覆盖优先级。apps/kimi-code/src/cli/run-shell.ts:apps/kimi-code/test/cli/run-shell.test.ts覆盖实验开关默认fullscreen、显式regular优先、终端回退tui_mode_fallback及startup_perf/exit遥测字段。apps/kimi-code/src/tui/commands/config.ts、reload.ts、tui-state.ts:tui-mode-preferences.test.ts、reload.test.ts与create-tui-state.test.ts覆盖设置切换持久化、tui_mode_switch埋点、修改无关偏好保持tuiMode: undefined以及重载时不误报重启提示。apps/kimi-code/dist/main.mjs,实测验证首次启动不落盘、执行/theme dark修改配置不误写tui_mode、KIMI_CODE_EXPERIMENTAL_FLAG=1进入?1049h、tmux -CC自动回退、KIMI_CODE_TUI_FULL_SCREEN=1强制覆盖与显式regular保持主屏共 6 个场景。未在真机 Android Termux 与 Windows SSH 环境实测,这两条路径基于环境变量纯函数单测覆盖。验证命令与测试结果
pnpm --filter @moonshot-ai/kimi-code run typecheck:通过pnpm run lint(check-no-comments+oxlint --type-aware):0 error 通过pnpm --filter @moonshot-ai/kimi-code run build:通过pnpm exec vitest run apps/kimi-code/test/tui/config.test.ts apps/kimi-code/test/tui/commands/tui-mode-preferences.test.ts apps/kimi-code/test/tui/commands/reload.test.ts apps/kimi-code/test/cli/run-shell.test.ts apps/kimi-code/test/tui/create-tui-state.test.ts:5 files, 108 passedpnpm exec vitest run apps/kimi-code/test/tui/kimi-tui-message-flow.test.ts:499 passedapps/kimi-code/dist/main.mjs检查?1049h计数与tui.toml落盘内容):全部通过Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.