Skip to content

fix(tui): fold previews only when collapsing saves rows - #4248

Merged
Grapedge merged 4 commits into
MoonshotAI:mainfrom
kimi-agent-bot:fix/tui-fold-only-when-saving-rows
Oct 16, 2026
Merged

Grapedge merged 4 commits into
MoonshotAI:mainfrom
kimi-agent-bot:fix/tui-fold-only-when-saving-rows

Conversation

@kimi-agent-bot

@kimi-agent-bot kimi-agent-bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

修复 TUI 折叠的一个 off-by-one:恰好只多出一行时,折叠提示行(… (1 more lines, ctrl+o to expand))1:1 顶替被藏的那行,行数零节省,内容却被藏到 ctrl+o 后面(内部用户反馈,TUI p2)。

Bug Reproduction Steps

  1. thinking 块最终恰好 3 行(THINKING_PREVIEW_LINES=2,藏 1 行):折叠后 = 1 空行 + 2 预览行 + 1 提示行 = 4 行,与不折叠一样高,第 3 行却被藏起。
  2. 失败命令的输出恰好 4 行(PREVIEW_LINES=3,藏 1 行):折叠后 = 3 行 + 提示行 = 4 行,与不折叠一样高。
  3. Write 恰好 11 行的文件(COMMAND_PREVIEW_LINES=10,藏 1 行):cap 后 = 10 行 + 提示行 = 11 行,与不 cap 一样高。

Root Cause

三处折叠判断都是「藏 ≥1 行就折」(length > maxLines / remaining > 0),没有扣除提示行自身占的 1 行:折叠净收益 = 隐藏行数 − 1,隐藏 1 行时收益为 0,纯损失一次 ctrl+o。根本修复(阈值修正),非绕过。

Code Changes

  • tool-renderers/truncated.ts:TruncatedOutputComponent 折叠条件改为 contentLines.length > maxLines + 1(净省 ≥1 行才折);truncatedAtLastRender 同步改,否则 ctrl+o 会在无内容可展时仍被广告(它经 wasTruncated() 喂 hasHiddenContent());tail 分支共用同一条件,随之覆盖。
  • thinking.ts:finalized 折叠分支与 previewHidesLines 改为 contentLines.length > THINKING_PREVIEW_LINES + 1;live 流式滚动窗口(无提示行、机制不同)不动。
  • tool-call.ts:Write 预览 cap 改为 allLines.length > COMMAND_PREVIEW_LINES + 1;callPreviewHidesContent 的 Write 镜像规则同步 +1,保持两处一致。
  • 测试:truncated / thinking / tool-call 各补两个边界用例(藏 1 行不折、藏 2 行照折)。

录屏

真实 TUI(PR 分支 dev 构建)逐 case 录制,脚本带屏幕断言:每段都是「藏 1 行全显 → 藏 2 行折叠 → ctrl+o 展开 → 再折回」,右下角有按键回显。

thinking 块(3 行 / 4 行):

fold-case-think

失败命令输出(共 4 行 / 共 5 行):

fold-case-fail

Write 预览(11 行 / 12 行):

fold-case-write

已知同构、本 PR 不动(弹窗摘要场景、非 transcript 折叠,如需要可后续单独提):approval-panel.ts file_content 摘要(ctrl+e 预览)、question-dialog.ts body 截断(无展开路径)。renderDiffLinesClustered 按 cluster 边界截断、按 change 计数,数学不同,不在本 PR。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
thinking 块恰好藏 1 行 折成 2 预览行 + 提示行,第 3 行藏 ctrl+o 后 3 行全显示,无提示行,ctrl+o 不再广告 无人(高度相同,旧行为纯损失) 无
通用输出组件恰好藏 1 行(失败命令输出、! shell 卡片、通用工具错误结果) 折成 maxLines 行 + 提示行 maxLines+1 行全显示 无人 无
Write 预览恰好 11 行 cap 成 10 行 + 提示行 11 行全显示 无人 无
藏 ≥2 行的一切场景 折叠 + 提示行 不变 — —

受影响模块:TUI transcript 渲染(thinking.ts、tool-renderers/truncated.ts 及其复用方 tool-call/shell-run/shell-execution、tool-call.ts Write 预览)。仅 TUI 客户端;print 模式、desktop/web/VS Code 不经此路径。测试覆盖:三个组件各新增「藏 1 行 / 藏 2 行」边界用例;messages 目录相关套件 266 条全绿;tsc --noEmit、oxlint --type-aware、check-no-comments 通过。真实 TUI 逐 case 录屏验证(thinking 3 行/4 行、失败命令 4 行/5 行、Write 11 行/12 行)见群话题。

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.

Collapsing swaps the hidden rows for a one-line expand hint, so folding
a single hidden row rendered at the same height as the full preview
while hiding content behind ctrl+o. Thinking blocks, the generic
truncated-output component, and the Write call preview now only fold
when at least two rows are hidden.
@changeset-bot

changeset-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6d18567

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

@pkg-pr-new

pkg-pr-new Bot commented Oct 15, 2026 •

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

commit: 6d18567

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

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T16:10:28.245328Z 6d18567 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.

@kimi-agent-bot

Copy link
Copy Markdown
Collaborator Author

CI test (4) 的 failure 与本 PR 无关:失败的是 packages/remote-control 的 tunnel 测试 registers, forwards HTTP and WS with local auth, then reconnects the pair(30s 超时)。本 PR diff 只触及 apps/kimi-code 的 TUI 折叠组件及其测试(7 个文件:3 源码 + 3 测试 + changeset),packages/remote-control 零改动。该测试在同一代码上表现不稳定:main(ef727e5) 的 CI 通过,本地对同一 commit 连跑两次分别失败 2 个和 3 个不等(tunnel/WS 时序敏感)。麻烦有权限的同学帮忙 re-run 一下这个 job。

The error-result branch of ToolCallComponent.computeHiddenContent and
ShellRunComponent.hasHiddenContent still advertised ctrl+o when the
preview hid exactly one row, which the preview now shows in full. Give
both mirrors the same maxLines+1 threshold, and count Write rows in the
expand predicate exactly like the renderer (highlightLines keeps a
trailing empty entry that computeWriteStats strips), so a trailing
newline no longer leaves the cap hint up while refusing expansion.

@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: 418d845f18

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

The error branch of computeHiddenContent counted non-empty lines, but
the preview folds all rendered rows including interior blanks, so an
error output of four non-empty rows plus a blank read as
not-expandable while collapsing would still save a row. Count with the
same trim-trailing-empty rule as the preview.

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

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

Bash's error preview renders sanitized output, so a trailing row that
only carries an escape sequence disappears there but still counted
toward hidden content, advertising ctrl+o for a card that cannot
change. Count the same sanitized rows the preview folds.
@Grapedge
Grapedge merged commit 8fcd332 into MoonshotAI:main Oct 16, 2026
16 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 20, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Oct 22, 2026
)

Ported from MoonshotAI/kimi-code 2.3.0 (8fcd332).

Kept our cached finalLines count in shell-run's hasHiddenContent instead of
re-splitting finalOutput per probe, applying upstream's +1 fold threshold to it.
Kept our import ordering in tool-call and moved the new shell-output import into
the #/ group, and dropped the now-unused computeWriteStats import.
Shifted our shell-run line-count caching test to the new boundary (12 rows, not
11, now fold) because a single hidden row no longer gains anything.
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.

2 participants