Skip to content

feat(tui): migrate screen-takeover viewers to ScrollView with mouse support - #5469

Open
Grapedge wants to merge 3 commits into
feat/fullscreen-mouse-corefrom
feat/fullscreen-mouse-viewers
Open

Grapedge wants to merge 3 commits into
feat/fullscreen-mouse-corefrom
feat/fullscreen-mouse-viewers

Conversation

@Grapedge

@Grapedge Grapedge commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Screenshots / Recordings

在真实 PTY(120×36,macOS)全屏模式下,/tasks 由 ScreenTakeoverView + FramedScrollPane 渲染完整三栏布局,点击顶栏 filter=ALL 与底栏 Tab filter / Q/Esc cancel 直接生效,缩至 44×12 时平滑降级并可在恢复尺寸后还原三栏。

实机终端文本快照(全屏模式 `/tasks` 与 44×12 窄屏降级)
 1| TASK BROWSER  filter=ALL  0 total
 2|╭─ Tasks [all] ──────────────────────╮╭─ Detail ───────────────────────────────────────────────────────────────────────╮
 3|│No tasks in this session.           ││Select a task from the list.                                                    │
16|│                                    │╰────────────────────────────────────────────────────────────────────────────────╯
17|│                                    │╭─ Preview Output ───────────────────────────────────────────────────────────────╮
35|╰────────────────────────────────────╯╰────────────────────────────────────────────────────────────────────────────────╯
36| ↑↓ select  Enter/O output  R refresh  Tab filter  Q/Esc cancel
 1|Terminal too small (need ≥ 48 × 10)

Requirement or Bug

4 个全屏接管查看器(TasksBrowserApp、TaskOutputViewer、AgentActivityViewer、ApprovalPreviewViewer)此前各自手写 scrollTop/followTail 状态机和边框拼接,不支持鼠标滚轮、滚动条拖拽或点击操作。本 PR 作为 3 层堆叠 PR 的第 2 层(基于 PR 1),将 4 个查看器统一迁移到 pi-tui 的 ScrollView + VStack/HStack 布局树,同时确保常规模式(TuiMainScreen)与直接调用 render(width) 的单元测试完全无损。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

新增 ScreenTakeoverView 与 FramedScrollPane 两个基座组件,让 4 个查看器在全屏和常规模式下走同一棵 pi-tui 布局树并删除全部手写滚动与画框代码。

flowchart TD
    A["ScreenTakeoverView extends VStack<br/>全屏走 TuiAltScreen 布局树 · 常规/单测走 renderLayoutFrame"] --> B["FramedScrollPane extends VStack<br/>topBorder + HStack(leftRail, ScrollView, rightRail) + bottomBorder"]
    B --> C["单框查看器 (padX: 1, OverflowScrollView)<br/>TaskOutputViewer · AgentActivityViewer · ApprovalPreviewViewer"]
    B --> D["三栏查看器 (padX: 0, ScrollView)<br/>TasksBrowserApp (SplitHStack + right VStack)"]
    E["screen-takeover.ts"] -->|"仅 TuiAltScreen 激活/退出时切换"| A
Loading

因为单框查看器通过 mountSinglePane 共用同一套头部、滚动框、页脚位置和键盘滚屏逻辑,三者均实现代码净删减;滚动条默认处于隐藏态,仅在 beginScreenTakeover 检测到 TuiAltScreen 时开启、在嵌套接管或 endScreenTakeover 时关闭并清理定时器,彻底消除常规模式与假时钟测试中的幽灵滚动条和残留定时器。

关键决策

决策 选择 没选 理由
双模式渲染策略 ScreenTakeoverView extends VStack,全屏走原生布局管线,常规/单测覆写 render(width) 调 renderLayoutFrame 保留手写 renderFrame 做常规分支 单一滚动与布局事实来源,避免双实现漂移与重复代码
TasksBrowserApp 列表悬停与预览交互 列表 move 不触发 onSelect,单击选中、双击打开完整输出;Preview Output 不拦截左键按压 列表 move 切选中或 Preview Output 吞掉按压做双击 防止鼠标滑过触发异步拉取任务输出 RPC 风暴,同时保留 Preview Output 拖选复制与超链接能力
TasksBrowserApp 左右分栏宽度 SplitHStack 在 visible(viewport) 中计算 clamp(floor(w * 0.32), 28, 44) 作为左栏 basis 静态 grow: 32 / 68 权重 stack.ts 余量分配在宽度 100/120 时会偏移 1–3 列;显式 basis 在 48–160 宽度下与原布局像素一致
TasksBrowserApp 主滚动视图归属 将 previewPane.scrollView 设为 primary: true 留给首个 listPane 解锁 Preview Output 的 PageUp/PageDown、Ctrl+Shift+F 搜索与回底提示,且不与任务列表选中态脱节

阅读指南

  1. apps/kimi-code/src/tui/components/chrome/screen-takeover-view.ts 与 apps/kimi-code/src/tui/utils/screen-takeover.ts:双模式接管基类、带框滚动窗格、滚动条与定时器生命周期。
  2. apps/kimi-code/src/tui/components/dialogs/{task-output-viewer,agent-activity-viewer,approval-preview}.ts:3 个单框查看器的薄迁移。
  3. apps/kimi-code/src/tui/components/dialogs/tasks-browser.ts:三栏任务浏览器布局、列表单/双击与防误触止损确认。

可略读部分:changeset、ratchet 基线降低与 5 个测试文件的新增用例。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
4 个全屏接管查看器的鼠标交互 不支持鼠标滚轮、滚动条与点击操作 全屏模式支持独立窗格滚轮(不串滚)、滚动条拖拽、文本拖选复制,以及底栏/顶栏操作点击与任务列表单击选中、双击打开 TUI 全屏模式交互用户 全部原有键盘快捷键保持一致
单框查看器在全屏模式下的 PageUp / PageDown 由组件 handleInput 按 viewportHeight - 1 翻页 因唯一 ScrollView 为 primary,全屏下由 TuiAltScreen 按 viewportHeight - 4 驱动同一 ScrollView(同时解锁 Ctrl+Shift+F 与回底提示);常规模式仍按 viewportHeight - 1 TUI 交互用户 关闭全屏模式(KIMI_CODE_TUI_FULL_SCREEN=0)保持原翻页步长
ApprovalPreviewViewer 键盘快捷键 支持 j/k/↑/↓/PageUp/PageDown/Space/g/G/Ctrl+B/Ctrl+F 额外兼容 Ctrl+U/Ctrl+D/b 翻页,原有键位全部保留 TUI 交互用户 无(纯增量兼容)
常规模式(TuiMainScreen)下的 4 个查看器 按 terminal.rows 渲染固定高度纯框线界面,无滚动条 视觉输出、精确行数、分栏宽度与零滚动条完全保持一致 TUI 常规模式交互用户 无变化

验证结论

  • 平台与核对方式:在 macOS 真实 PTY(120×36 与 44×12 实时缩放)验证全屏与常规模式下的 /tasks 三栏布局、顶栏/底栏点击、窄屏降级及恢复后焦点还原;其余 3 个查看器通过 TuiAltScreen + VirtualTerminal 与直接 render(width) 单测覆盖双模式;Linux 由 CI 跑测验证。
  • 未验证项:Windows 终端未在本地实机运行。
自动化检查与测试结果
  • pnpm exec vitest run --reporter=agent(tasks-browser、task-output-viewer、agent-activity-viewer、approval-preview、screen-takeover 及全部引用测):6 files, 145 passed(修复评审后 5 个核心单测 108/108 passed)
  • pnpm exec tsc -p apps/kimi-code/tsconfig.json --noEmit:0 errors
  • pnpm lint:0 warnings, 0 errors
  • pnpm run check:duplication:0 new clones

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.

@Grapedge
Grapedge added this pull request to stack #5471 November 25, 2026 21:46
@changeset-bot

changeset-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 52ac0be

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 25, 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-25T22:11:09.267658Z 52ac0be 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 25, 2026 •

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

commit: 52ac0be

@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: e29e49445b

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

@Grapedge
Grapedge force-pushed the feat/fullscreen-mouse-viewers branch from e29e494 to 3e2c529 Compare November 25, 2026 22:01

@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: 3e2c52988e

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

This branch has not been deployed

No deployments
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.

1 participant