Skip to content

feat(tui): default to fullscreen mode when experimental flag is set - #4771

Merged
Grapedge merged 5 commits into
mainfrom
fullscreen-default
Nov 10, 2026
Merged

Grapedge merged 5 commits into
mainfrom
fullscreen-default

Conversation

@Grapedge

@Grapedge Grapedge commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

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

  1. 删除 ~/.kimi-code/tui.toml 后启动 kimi,或在未配置 tui_mode 的 tui.toml 下执行 /theme dark 修改任意无关偏好。
  2. 查看 ~/.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 的用户行为保持不变(命中终端不兼容回退时除外)。

概念

概念 回答什么问题 本 PR 之后
TuiConfig.tuiMode 用户在 tui.toml 里是否显式写了 tui_mode 'regular' | 'fullscreen' | undefined;undefined 时渲染为 # tui_mode = "regular" 注释行,修改其他设置不再落盘 tui_mode
TuiModeResolution 当前进程最终用哪种布局启动,以及是否发生了终端回退 { 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]
Loading

因为终端兼容性问题(iTerm2 的 tmux -CC 控制模式、Android Termux 触屏滚动、TERM=dumb 哑终端)取决于当前连接的宿主终端而非主目录配置文件,所以自动回退置于 tui.toml 之后、KIMI_CODE_TUI_FULL_SCREEN 强制覆盖之下;当用户确需在受限终端尝试全屏时,仍可用 KIMI_CODE_TUI_FULL_SCREEN=1 绕过回退且不污染配置文件。

关键决策

决策 选择 没选 理由
环境解析的调用位置 在 CLI 启动入口 runShell 与 /reload-tui 显式调用 resolveTuiMode,把 resolvedTuiMode 传给 KimiTUI 在 createTUIState 内部直接读 process.env 非交互测试运行器默认 TERM=dumb,开发机常设 KIMI_CODE_EXPERIMENTAL_FLAG=1;在入口解析能让直接构造 createTUIState 的组件单测保持纯确定性,不受宿主 shell 环境干扰
KIMI_CODE_TUI_FULL_SCREEN 语义 改为按进程生效的最高优先级布尔覆盖(支持真假值),不写回 tui.toml 保留一次性把 fullscreen 写入 tui.toml 的旧迁移逻辑 与仓库其他 KIMI_CODE_* 环境变量覆盖语义对齐,同时提供不改写配置文件的单次切回 regular 或强制 fullscreen 退路

阅读指南

  1. apps/kimi-code/src/tui/config.ts:看 TuiConfig.tuiMode 的缺省语义、renderTuiConfig 的注释行输出,以及 detectTuiModeFallback 和 resolveTuiMode 的完整优先级。
  2. apps/kimi-code/src/cli/run-shell.ts:看启动期如何计算 tuiModeResolution,并将 tui_mode_config 与 tui_mode_fallback 注入 startup_perf 和 exit 遥测事件。
  3. 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 透传、用例覆盖与文档同步,可略读。

具体变化大纲

 loadTuiConfig(filePath)
   if !existsSync(filePath)
-    save DEFAULT_TUI_CONFIG (writes live tui_mode = "regular" or migrates KIMI_CODE_TUI_FULL_SCREEN=1)
+    save DEFAULT_TUI_CONFIG (writes commented `# tui_mode = "regular"`)
   else
     parse & normalize (tuiMode stays undefined unless tui_mode is set in TOML)
-    if tui_mode absent && KIMI_CODE_TUI_FULL_SCREEN === '1' -> rewrite tui.toml

 resolveTuiMode(configuredMode, env)
+  if KIMI_CODE_TUI_FULL_SCREEN is truthy/falsy -> return fullscreen/regular (no disk write)
+  preferred = configuredMode ?? (KIMI_CODE_EXPERIMENTAL_FLAG ? 'fullscreen' : 'regular')
+  if preferred === 'fullscreen' && detectTuiModeFallback(env) -> return regular + fallback reason
+  return preferred

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=0
首次创建 tui.toml 或在 TUI 内修改无关偏好(/theme、/editor、复制与折叠设置等)时的 tui_mode 落盘行为 将未注释的 tui_mode = "regular" 写入 tui.toml tui_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.toml 曾依赖单次运行 KIMI_CODE_TUI_FULL_SCREEN=1 把偏好永久写入 tui.toml 的 TUI 用户(已落盘的老配置不受影响) 在 /settings -> TUI mode 选择 Fullscreen 或在 tui.toml 写入 tui_mode = "fullscreen"
在 iTerm2 tmux -CC 控制模式、Android Termux(TERMUX_VERSION)或 TERM=dumb 终端下请求 fullscreen 仍进入 \x1b[?1049h 备用屏 自动回退至 regular 主屏模式 在上述终端中仍希望强制使用备用屏的 TUI 交互用户 设置 KIMI_CODE_TUI_FULL_SCREEN=1 强制启用 fullscreen
CLI 遥测字段(startup_perf、exit、tui_mode_switch) startup_perf 与 exit 仅上报 tui_mode startup_perf 与 exit 新增 tui_mode_config 与 tui_mode_fallback;设置切换新增 tui_mode_switch 无外部消费契约变化(KIMI_DISABLE_TELEMETRY 与 telemetry = false 同样生效) N/A

受影响模块与测试覆盖:

  • 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 以及重载时不误报重启提示。
  • 端到端验证:在真实 PTY 伪终端中启动构建产物 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 passed
  • pnpm exec vitest run apps/kimi-code/test/tui/kimi-tui-message-flow.test.ts:499 passed
  • 真实 PTY 验证(6 个场景驱动 apps/kimi-code/dist/main.mjs 检查 ?1049h 计数与 tui.toml 落盘内容):全部通过

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 9, 2026 16:30
@changeset-bot

changeset-bot Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2d7bc1a

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 Patch

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 9, 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-10T03:24:08.191380Z 2d7bc1a 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 9, 2026 •

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

commit: 2d7bc1a

@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: 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".

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

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

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

Grapedge commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@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: 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".

Comment thread apps/kimi-code/src/tui/config.ts Resolved
Comment thread apps/kimi-code/src/tui/config.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: 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".

Comment thread docs/en/configuration/config-files.md Resolved
@Grapedge
Grapedge merged commit c01a04a into main Nov 10, 2026
16 checks passed
@Grapedge
Grapedge deleted the fullscreen-default branch November 10, 2026 05:39
@github-actions github-actions Bot mentioned this pull request Nov 10, 2026
This was referenced Nov 11, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 11, 2026
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.
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