MoonshotAI / MoonshotAI/kimi-cli

Uncaught Pi TUI exception due to screen width

Open Beginner friendly
#2,450 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
11.4k
Forks
1.3k
Avg merge
9h 47m
Merged PRs (30d)
2

Description

What version of Kimi Code CLI is running?

Kimi Code v0.12.0

Which open platform/subscription were you using?

moonshot.ai or whatever the token/api one is

Which model were you using?

k2.6

What platform is your computer?

debian

What issue are you seeing?

file:///home/lonelyllm/.kimi-code/node_modules/.pnpm/@earendil-works+pi-tui@0.74.0/node_modules/@earendil-works/pi-tui/dist/tui.js:974
throw new Error(errorMsg);
^

Error: Rendered line 90 exceeds terminal width (40 > 23).

This is likely caused by a custom TUI component not truncating its output.
Use visibleWidth() to measure and truncateToWidth() to truncate lines.

Debug log written to: /home/lonelyllm/.pi/agent/pi-crash.log
at TUI.doRender (file:///home/lonelyllm/.kimi-code/node_modules/.pnpm/@earendil-works+pi-tui@0.74.0/node_modules/@earendil-works/pi-tui/dist/tui.js:974:23)
at Timeout._onTimeout (file:///home/lonelyllm/.kimi-code/node_modules/.pnpm/@earendil-works+pi-tui@0.74.0/node_modules/@earendil-works/pi-tui/dist/tui.js:372:18)
at listOnTimeout (node:internal/timers:605:17)
at process.processTimers (node:internal/timers:541:7)


What steps can reproduce the bug?

No idea.

What is the expected behavior?

Not throwing an error.

Additional information

Kimi patched my local install, here's the patch it applied in case it helps you fix the issue:

From: lonelyllm
Subject: [PATCH] Fix TUI crash when truncation hint exceeds terminal width

When the terminal is very narrow (e.g. 23 columns), two components render
a ... (N more lines, ctrl+o to expand) hint without ensuring it fits.
Pi-tui correctly detects the overflow and throws:

Error: Rendered line 90 exceeds terminal width (40 > 23).

This patch applies truncateToWidth() to both hint lines so they are safely
clipped in narrow terminals instead of crashing the session.


apps/kimi-code/src/tui/components/messages/thinking.ts | 7 +++++--
apps/kimi-code/src/tui/components/messages/tool-renderers/truncated.ts | 4 ++--
2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/apps/kimi-code/src/tui/components/messages/thinking.ts b/apps/kimi-code/src/tui/components/messages/thinking.ts
index 0fee366..199c71f 100644
--- a/apps/kimi-code/src/tui/components/messages/thinking.ts
+++ b/apps/kimi-code/src/tui/components/messages/thinking.ts
@@ -6,7 +6,7 @@
*/

import type { Component, TUI } from '@earendil-works/pi-tui';
-import { Text } from '@earendil-works/pi-tui';
+import { Text, truncateToWidth } from '@earendil-works/pi-tui';
import chalk from 'chalk';

import {
@@ -112,7 +112,10 @@ export class ThinkingComponent implements Component {
const truncated = rendered.slice(0, 1 + THINKING_PREVIEW_LINES);
const remaining = contentLines.length - THINKING_PREVIEW_LINES;
truncated.push(

  •  MESSAGE_INDENT + chalk.dim(`... (${String(remaining)} more lines, ctrl+o to expand)`),
    
  •  truncateToWidth(
    
  •    MESSAGE_INDENT + chalk.dim(`... (${String(remaining)} more lines, ctrl+o to expand)`),
    
  •    width,
    
  •  ),
    
    );
    return truncated;
    }
    diff --git a/apps/kimi-code/src/tui/components/messages/tool-renderers/truncated.ts b/apps/kimi-code/src/tui/components/messages/tool-renderers/truncated.ts
    index 54706fc..908ebb2 100644
    --- a/apps/kimi-code/src/tui/components/messages/tool-renderers/truncated.ts
    +++ b/apps/kimi-code/src/tui/components/messages/tool-renderers/truncated.ts
    @@ -1,5 +1,5 @@
    import type { Component } from '@earendil-works/pi-tui';
    -import { Text } from '@earendil-works/pi-tui';
    +import { Text, truncateToWidth } from '@earendil-works/pi-tui';
    import chalk from 'chalk';

import type { ColorPalette } from '#/tui/theme/colors';
@@ -70,7 +70,7 @@ export class TruncatedOutputComponent implements Component {
const hint = this.expandHint
? ... (${String(remaining)} more lines, ctrl+o to expand)
: ... (${String(remaining)} more lines);

  • return [...shown, ' '.repeat(this.indent) + chalk.dim(hint)];
  • return [...shown, truncateToWidth(' '.repeat(this.indent) + chalk.dim(hint), width)];
    }
    }

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 by reading apps/kimi-code/src/tui/components/messages/thinking.ts and apps/kimi-code/src/tui/components/messages/tool-renderers/truncated.ts, focusing on the narrow-terminal rendering paths and their expand hints. Reproduce or inspect the supplied 23-column failure, then verify that both hint lines stay within the terminal width without throwing.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.