MoonshotAI / MoonshotAI/kimi-code

终端流式输出时偶尔自动滚动到顶部(pi-tui fullRender 触发清屏)

Open
#981 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.5k
Forks
1.2k
Avg merge
11h 53m
Merged PRs (30d)
350

Description

What version of Kimi Code is running?

kimi, version 0.16.0

Which open platform/subscription were you using?

Kimi Code

Which model were you using?

K2.7 Code

What platform is your computer?

Windows 11, Git Bash (MINGW64)

What issue are you seeing?

流式输出过程中,终端偶尔会自动跳到最顶部,导致无法看到正在输出的内容,需要手动滚回底部。

What steps can reproduce the bug?
  1. 启动 kimi-code,进行一个会产生较长输出的对话(超过终端视口高度)
  2. 当模型先 thinking 再输出 assistant 文本时,thinking 阶段结束切换渲染模式时,终端会跳到顶部
  3. 或者在长对话中,任何发生在视口上方的组件渲染变化都可能触发
What is the expected behavior?

流式输出时终端应保持在底部,跟随最新输出内容,不跳回顶部。

Additional information

根因分析

问题出在底层 TUI 渲染库 @earendil-works/pi-tuidoRender() 方法中。当前版本(0.16.0)依赖的 pi-tui 版本为 ^0.74.0,经确认最新发布的 0.18.0、0.19.0 也使用相同的 pi-tui 版本,因此该问题在最新版本中同样存在。

tui.js 第 909 行:

if (firstChanged < prevViewportTop) {
    fullRender(true);  // 发出清屏序列
    return;
}

当第一条变更行在视口上方时,diff 渲染器认为无法通过增量更新到达,触发全屏重绘。fullRender(true) 会发出清屏序列,导致终端从顶部开始重新渲染。

典型触发场景:thinking 阶段结束时,ThinkingComponent 从 live 模式(带动画 spinner)切换到 finalized 模式(静态文本),渲染输出发生变化。此时 transcript 已超过终端高度,视口在底部(prevViewportTop > 0),而 thinking 组件位于 transcript 靠前位置,firstChanged < prevViewportTop 条件成立。

上游修复情况

pi-tui 最新版本是 0.79.10(当前使用 0.74.0),相关修复:

  • 0.51.1:修复了 prevViewportTop 计算使用 stale maxLinesRendered 导致不必要的 full redraw
  • 0.63.0:修复了内容收缩后 viewport 跟踪错误

建议

  1. 短期:升级 @earendil-works/pi-tui 到 >= 0.79.10,利用已有的 viewport 跟踪修复减少误触发
  2. 根本修复:在 pi-tui 上游修复 firstChanged < prevViewportTop 分支的降级策略

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported doRender() branch in pi-tui's tui.js around line 909, especially the firstChanged < prevViewportTop check and fullRender(true) call. Reproduce the issue with a long streaming conversation and inspect the project's @earendil-works/pi-tui dependency version. Done means the dependency upgrade or upstream fix prevents the terminal from jumping to the top during viewport-above changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.