Skip to content

feat(kimi-code): re-baseline pi-tui on upstream v0.84.1 and add fullscreen tui_mode - #2830

Merged
liruifengv merged 18 commits into
mainfrom
feat/pi-tui-0.84-fullscreen
Aug 12, 2026
Merged

feat(kimi-code): re-baseline pi-tui on upstream v0.84.1 and add fullscreen tui_mode#2830
liruifengv merged 18 commits into
mainfrom
feat/pi-tui-0.84-fullscreen

Conversation

@liruifengv

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem is explained in the next section.

Problem

Our vendored @moonshot-ai/pi-tui fork was snapshotted from upstream @earendil-works/pi-tui 0.80.2 (2026-06-23). Upstream has since shipped v0.84.1 plus further main-branch work that we want:

  • Fixes: paste-registry corruption on delete/undo, Windows keyboard input latency, Windows Shift+Enter detection, narrow-terminal crashes, Kitty image layout glitches, OSC 8 hyperlinks left unterminated by truncation, tab normalization.
  • A new architecture: the renderer splits into main-screen and alternate-screen implementations behind a TUI interface; the alternate screen brings an application-owned scrollable viewport, a layout engine (VStack/HStack/ScrollView), mouse text selection, scrollbars, and transcript search.

Separately, kimi-code's inline viewport cannot offer wheel scrolling, drag selection, or in-transcript search without leaving the native-scrollback model.

What changed

pi-tui re-baseline (packages/pi-tui)

  • Re-baselined the fork on upstream v0.84.1 + main through 40a3d85 (2026-08-11) via a three-way merge against the pristine 0.80.2 fork point. All local patches retained: narrow-terminal hardening, processed-line render caching (re-implemented into the split TuiMainScreen), editor history hooks, the paste-burst fallback, and multi-root @ completion.
  • Fork additions on top of upstream:
    • Editor.setText(text, { preservePasteRegistry }) — upstream resets the paste registry on every setText, which would orphan our paste-marker expansion (Ctrl-V on a paste marker).
    • ScrollView.canScroll, TuiAltScreen.getLayoutRoot(), and viewport navigation keys now fall through to the focused component when the primary scroll view cannot scroll (so full-screen viewers keep their own PageUp/PageDown/Home/End handling).
  • The version line now tracks the upstream baseline it forks from (0.84.1).

Fullscreen mode (apps/kimi-code)

  • New tui_mode preference in tui.toml: regular (default, unchanged behavior) or fullscreen. Fullscreen mounts TuiAltScreen: the transcript lives in a primary ScrollView (follow-end, transient scrollbar), the chrome docks at the bottom, mouse selection/copy comes from the renderer, and Ctrl-Shift-F opens transcript search.
  • Full-screen viewers (tasks browser, task output, agent activity, approval preview) now swap the layout root through a mode-aware screen-takeover helper; the previous root-children snapshot trick is never painted in fullscreen.
  • The external editor (Ctrl-G) stops with preserveScreen in fullscreen so the transcript is not replayed into the main screen on exit/entry.
  • Upstream's Markdown LaTeX rendering is opt-out disabled on our side (renderLatex: false) to keep current rendering behavior.
  • The fullscreen dock mirrors pi's sizing contract (transcript ScrollView starts from basis: 0, editor minSize: 3, footer minSize: 1) so a tall transcript cannot crush the dock and clip the editor's bottom border.

Docs: tui_mode added to the tui.toml reference in docs/en and docs/zh.

Verification

  • packages/pi-tui: 959/959 tests, tsc clean (fork adapted to the repo's strict flags).
  • apps/kimi-code: 2726/2726 tests, typecheck and oxlint clean. New coverage: renderer/layout selection, tui_mode config parsing, screen-takeover (regular/fullscreen/nested), paste-registry preservation, alt-screen key gating, and a VirtualTerminal-level regression test replaying a full streaming cycle in fullscreen.
  • Frame benchmark (30k-line transcript, one-line change per frame): 559 hz → 655 hz, no regression.
  • End-to-end PTY runs of the dev CLI in both modes: startup, repeated streaming/spinner cycles, and viewer takeovers all render correctly.
  • Not automatable: real-terminal behavior across the matrix (Windows Terminal/conhost, tmux, iTerm2/Kitty, narrow widths). A manual verification checklist was used during development and is available on request.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

…creen tui_mode

Re-baseline the vendored pi-tui fork on upstream @earendil-works/pi-tui
v0.84.1, keeping all local patches: narrow-terminal hardening,
processed-line render caching (re-implemented into TuiMainScreen), editor
history hooks, the paste-burst fallback, and multi-root @ completion.

Upstream highlights absorbed: the renderer splits into TuiMainScreen and
TuiAltScreen behind a TUI interface, the Markdown component gains opt-out
LaTeX rendering (disabled on the kimi-code side), paste-registry repair
on delete/undo, Windows input-latency and Shift+Enter fixes, and Kitty
image layout fixes. Editor.setText gains a preservePasteRegistry option
so paste-marker expansion survives wholesale text replacement.

New tui_mode = "fullscreen" preference mounts TuiAltScreen: the
transcript lives in a primary ScrollView with follow-end, the chrome
docks at the bottom, mouse selection and scrollbar come from the
renderer, and full-screen viewers (tasks browser, output viewer, approval
preview) swap the layout root via screen-takeover. Viewport navigation
keys fall through to the focused component when the primary scroll view
cannot scroll.
Bring in upstream's merged-but-unreleased changes on top of the v0.84.1
re-baseline:

- Fullscreen transcript search (ctrl+shift+f, next/previous navigation)
- Alternate-screen render-churn reduction (9-18x less per-frame
  allocation by painting full-width rows as direct line references)
- Unbound single-line scroll actions (tui.altScreen.lineUp/lineDown),
  wired into the fork's canScroll gating like the other viewport keys
- SSH-aware escape-timeout default and PI_TUI_ESC_TIMEOUT override
- Search snapping and SGR-mouse fragmentation fixes; LaTeX newline
  argument fix

Conflicts resolved by union: upstream's search/line scroll bindings stay
ungated, fork's primaryScrollable guard applies to all scroll actions.
The fullscreen layout gave the transcript ScrollView its intrinsic
content height as basis and let the dock participate in shrink
distribution with no minSize. Once the transcript exceeded the screen,
the VStack shrink pass crushed the dock to a couple of rows, and the
editor (3 rows: top border / input / bottom border) lost its bottom
border row to clipping.

Adopt pi's sizing contract: the ScrollView starts from basis 0 and
grows, the dock keeps its intrinsic height, the editor never shrinks
below 3 rows, and the footer below 1. Adds a VirtualTerminal-level
regression test that replays a full streaming cycle in fullscreen.
@pkg-pr-new

pkg-pr-new Bot commented Aug 11, 2026

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

commit: d69db9a

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

ℹ️ 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 packages/pi-tui/src/tui-alt-screen.ts Outdated
TuiAltScreen's viewport input listener consumed FOCUS_IN/FOCUS_OUT
reports. Since the renderer installs that listener at construction —
before any app-level listeners — terminal focus tracking and
clipboard-image hints never saw focus transitions in fullscreen mode
(notification_condition = "unfocused" went blind, refocus clipboard
hints stopped). Keep the selection cleanup but stop consuming, matching
the main-screen fan-out. Addresses Codex review on PR #2830.
@changeset-bot

changeset-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d69db9a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/kimi-code Minor
@moonshot-ai/pi-tui 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

Mouse capture in the alternate screen intercepts the terminal's native
link activation, leaving OSC 8 hyperlinks (like the footer's PR link)
unclickable in fullscreen. Route renderer link clicks to the app's
openUrl, and on Windows feed right-clicks to the focused component as a
bracketed paste read from the clipboard.
…resync

- Mark user/assistant transcript messages with OSC 133 zones (start /
  end / final) so the fullscreen renderer's Ctrl-Shift-Up/Down prompt
  jumps work; GutterContainer keeps the markers at byte 0 when prefixing
  its gutter, and message render caches store already-marked lines.
- On exit from fullscreen, preserve the frame and replay the transcript
  through a fresh main-screen renderer so native scrollback gets the
  regular inline layout (pi's "transcript" exit form).
- Re-sync the OSC 9;4 progress indicator after a stop/start cycle:
  terminal.stop() clears it, and the cached progressActive flag used to
  suppress the re-send when returning from the external editor mid-turn.
…opt-out

Align with the upstream pi-tui default: LaTeX math in Markdown messages
renders as Unicode text. The explicit renderLatex:false we set during
the re-baseline becomes a shared Markdown options helper fed by a new
tui.toml preference (render_latex, default true), wired at startup and
refreshed on /reload.
Drop the public tui_mode preference from tui.toml before release; the
fullscreen UI is experimental, so enable it with the
KIMI_CODE_TUI_FULL_SCREEN=1 env var instead. Docs move from the
config-file reference to the env-vars page.
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex

@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: 2146c00e1f

ℹ️ 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/commands/reload.ts Outdated
Codex review on PR #2830: applyReloadedTuiConfig set the shared LaTeX
toggle after applyTheme(), but theme application invalidates transcript
components and their rebuilt Markdown children copy the options at
construction — so a /reload that only flipped render_latex kept the old
value until some later invalidation. Move the setter before applyTheme
and pin the ordering with a test.
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex

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

ℹ️ 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
Comment thread apps/kimi-code/src/tui/tui-state.ts
Codex review on PR #2830: currentTuiConfig omitted renderLatex, so
saving an unrelated preference (theme/editor/upgrade/cache-hint)
serialized render_latex as the default true and silently reset a user's
opt-out. Carry the appState value through the shared save payload.
Tag startup_perf and exit events with the active renderer mode
(regular/fullscreen) so fullscreen adoption is measurable while it is
gated behind KIMI_CODE_TUI_FULL_SCREEN.
@liruifengv
liruifengv merged commit ec84a6f into main Aug 12, 2026
14 checks passed
@liruifengv
liruifengv deleted the feat/pi-tui-0.84-fullscreen branch August 12, 2026 10:23
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