Repository navigation
Conversation
Introduce a stable TUI proxy reference backed by a replaceable TuiMainScreen/TuiAltScreen instance, preserving main-screen render state, animation frames, input and color-scheme listeners, and non-capturing overlays across runtime mode switches.
…e switches Allow DockSection, NotifyPanelComponent, and FooterComponent to update their fullscreen layout state in place without losing panel state, and track active screen takeovers per TUI instance so mode switches can guard against active takeover views.
Unify startup, runtime switching, and fullscreen exit under TuiLayoutShell and KimiTUI.switchTuiMode so changing TUI mode in /settings or reloading tui.toml applies immediately without restarting, while preserving terminal focus reporting, OSC progress state, and environment/fallback safeguards.
🦋 Changeset detectedLatest commit: 8390517 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: |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Screenshots / Recordings
在真实终端里以
regular模式启动后,通过/settings切换到fullscreen立即生效(无重启提示),再次打开/settings即可看到全屏专属选项;修改tui.toml后执行/reload-tui立即切回regular并隐藏全屏选项。切换前(
regular模式/settings):切换后(
/settings实时切到fullscreen后立即重开/settings):Requirement or Bug
此前在
/settings中切换 TUI mode(regular主屏模式与fullscreen备用屏全屏模式),或通过/reload、/reload-tui重载tui.toml中的tui_mode时,都只能写入或读取配置并提示重启 Kimi Code 才能生效。本 PR 支持在运行中实时切换 TUI mode,无需重启进程,同时保留当前会话对话记录、输入框草稿、待发队列、通知历史以及主屏原有的滚动位置。
Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路
整体沿用上游 Pi Coding Agent 的运行时替换渲染器思路,直接复用
packages/pi-tui已有的TuiMainScreen.captureRenderState()、restoreRenderState()与stop({ preserveScreen: true }),不改动底层库。我们把活跃的TuiMainScreen/TuiAltScreen收拢进新增的TuiRendererSession,对外只暴露一个引用恒定的TUI代理对象,并在宿主侧统一管理主屏与全屏的布局壳、模式相关组件刷新以及跨渲染器持久状态,让启动、运行中切换和全屏退出共用同一条路径。flowchart LR Cmd["命令入口(/settings, /reload, /reload-tui)"] --> Host["KimiTUI.switchTuiMode"] Host --> Guard["安全窗口守卫(关闭/重入/外部编辑器/接管视图/弹窗)"] Guard --> Session["TuiRendererSession"] Session --> Proxy["稳定 TUI 代理(动态原型 + 方法转发)"] Session --> State["跨渲染器持久层(rAF 桥接 / 有序监听 / 非捕获浮层 / 主屏快照)"] Session --> Shell["TuiLayoutShell(主屏平铺 / 全屏视口与停靠区)"] Shell --> Chrome["DockSection / NotifyPanel / Footer / Transcript"]这样把“底层渲染器替换与状态迁移”和“业务组件”隔离开来,现有十余类持有
ui引用的组件无需改写构造签名,也能减少与并行 UI 改动的冲突面。关键决策
TuiRendererSession内透明桥接requestAnimationFrame、输入/配色监听与nonCapturing浮层KimiTUI维护人工重绑清单,或修改packages/pi-tuiClipboardImageHint先于消费焦点事件的TerminalFocus、避免流式动画卡死与新旧 rAF 句柄碰撞,并防止KIMI_TUI_INPUT_LATENCY=1误拦切屏notifyPanelContainer/queueContainer包装方式VStack,主屏外层套GutterContainer,DockSection支持原地setLayout()NotifyPanelComponent或替换容器对象onReturnFocus回调,且最小化对独立组件的改动{ status: 'blocked', reason }并提示先关闭当前视图再/reload-tui或重启ScreenTakeover快照ENABLE_TERMINAL_FOCUS_REPORTING(\x1b[?1004h)、重置并重刷 OSC 9;4 进度条;拦截requestRender(true)保存强制重绘前的主屏快照TuiMainScreen.start()自动恢复或重跑终端主题追踪TuiAltScreen.stop()会下发\x1b[?1004l且ProcessTerminal.stop()清空进度条;/reload中的applyTheme()会先触发requestRender(true)将previousWidth置-1,提前保留有效主屏快照可避免回切/退出时误发\x1b[3J清空终端历史阅读指南
按以下顺序阅读核心文件即可掌握全貌:
apps/kimi-code/src/tui/tui-renderer.ts:TuiRendererSession、createInteractiveTui、动态原型Proxy、rAF 桥接、监听注册表与只读非捕获浮层栈追踪。apps/kimi-code/src/tui/tui-state.ts:TuiLayoutShell如何统一主屏/全屏布局挂载、footerMounted阶段守卫与addLayoutEffect清理。apps/kimi-code/src/tui/kimi-tui.ts:switchTuiMode()安全守卫、布局重挂载、DECSET 1004/ OSC 9;4 恢复与stopUiForExit()复用。apps/kimi-code/src/tui/commands/config.ts与reload.ts:/settings、/reload、/reload-tui接入实时切换与环境覆盖/回退提示。其余改动为 3 个 chrome 组件的原地模式刷新(
dock-section.ts、notify-panel.ts、footer.ts)、screen-takeover.ts的WeakMap活跃追踪、editor-keyboard.ts选区复制监听改为动态判断,以及单元测试与oxlint-ratchet.json基线下调,可按需略读。代码变更的可视化大纲
applyTuiModeChoice (commands/config.ts) resolveTuiMode -> saveTuiConfig -> setAppState if env override / terminal fallback showStatus + showNotice(overrideNotice) - else if resolved.mode !== ui.mode - showNotice(TUI_MODE_RESTART_NOTICE) + else + switch (host.switchTuiMode(resolved.mode)) + switched -> showStatus (live switch complete) + unchanged -> showStatus + blocked -> showStatus + showNotice(TUI_MODE_SWITCH_BLOCKED_NOTICE) applyReloadedTuiConfig (commands/reload.ts) renderLatex/mermaid -> applyTheme -> refreshTerminalThemeTracking -> setAppState + if env override / terminal fallback + applyTranscriptPresentation + setCopyOnSelect + showNotice(reload overrideNotice) + else + switchResult = host.switchTuiMode(resolution.mode) + if switchResult !== switched -> applyTranscriptPresentation + setCopyOnSelect + if switchResult === blocked -> showNotice(TUI_MODE_SWITCH_BLOCKED_NOTICE)Behavior Changes and Affected Users
/settings中切换 TUI mode(常规终端且未设置覆盖环境变量)tui.toml,显示重启后生效提示,界面停留在旧模式tui.toml并立即切换渲染模式,不再显示重启提示,/settings中的全屏专属选项立即同步显隐KIMI_CODE_TUI_FULL_SCREEN=0或1锁定当前会话模式,或在下次启动前再改回原值/reload或/reload-tui且tui.toml的tui_mode与当前运行模式不同tui.toml但仅想重载主题/其他选项而不改变当前会话模式的tui.toml自定义用户KIMI_CODE_TUI_FULL_SCREEN=0或1锁定当前进程模式/tasks/ 审批预览接管视图、编辑器替换面板或外部编辑器/reload-tui或重启,已保存配置不受影响/reload-tui,或重启 CLIregular→fullscreen→ 退出)TuiMainScreen直接重绘全部容器exitToMainScreen恢复离开主屏前保存的渲染状态并重挂主屏布局后再输出,避免重复打印历史记录并展开常规布局受影响模块:
apps/kimi-code/src/tui/(渲染器会话、布局壳、停靠面板与页脚、屏幕接管、键盘控制器、/settings与/reload命令)。验证结论:
\x1b[3J]、通知历史与队列保留、冷启动选区复制、DECSET 1004与 OSC 9;4 恢复、阻塞守卫与环境/终端回退),共 174 个 TUI 测试文件(3860 条用例)与 39 个 CLI 测试文件(742 条用例)全部通过。regular→/settings切fullscreen→ 验证全屏选项即时出现 →/reload-tui切回regular→ 二次切fullscreen→/exit无重复输出,以及冷启动fullscreen→/settings切regular→/exit)。SUCCESS、9 项SKIPPED);Windows 测试与可选 TUI E2E 在当前 CI 配置中处于跳过状态,本 PR 未在 Windows 平台实测。完整验证命令与结果
最终提交后本地运行:
pnpm exec tsc -p apps/kimi-code/tsconfig.json --noEmit:0 errorspnpm exec vitest run --reporter=agent apps/kimi-code/test/tui/:174 passed (174), 3860 passed (3860)pnpm lint:0 warnings, 0 errors(check-comments、oxlint及全部 guards/ratchet 通过)pnpm run check:duplication cb8a623c22aff737082f9fbfc74eafa9cd4b6701:0 new clonesregular→/settingsfullscreen→/reload-tuiregular→fullscreen→/exit):通过此前本地运行(最新提交由 Linux CI 全量测试覆盖):
pnpm exec vitest run --reporter=agent apps/kimi-code/test/cli/:39 passed (39), 742 passed (742)fullscreen→/settingsregular→/exit):通过Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.