feat(tui): allow expanding streaming thinking (#4322)

This commit is contained in:
grapedge 2026-10-22 15:35:30 +08:00 • committed by GitHub
parent 4c5d7d5e27
commit 44cdf8f403
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 9 deletions

View file

@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": minor
---
Allow expanding thinking during streaming with Ctrl-O

View file

@ -111,15 +111,17 @@ export class ThinkingComponent implements Component {
const contentWidth = Math.max(1, width - MESSAGE_INDENT.length);
const contentLines = this.text.length > 0 ? this.textComponent.render(contentWidth) : [''];
// Collapsing swaps the hidden rows for a one-line hint, so a single
// hidden row would render at the same height as the full block.
// Live folding hides every row beyond the tail. Finalized folding swaps
// hidden rows for a one-line hint, so it must save at least one row.
this.previewHidesLines =
this.mode === 'finalized' && contentLines.length > THINKING_PREVIEW_LINES + 1;
this.mode === 'live'
? contentLines.length > THINKING_PREVIEW_LINES
: contentLines.length > THINKING_PREVIEW_LINES + 1;
let rendered: string[];
if (this.mode === 'live') {
const visibleLines =
contentLines.length > THINKING_PREVIEW_LINES
!this.expanded && this.previewHidesLines
? contentLines.slice(contentLines.length - THINKING_PREVIEW_LINES)
: contentLines;
const spinner = currentTheme.fg(
@ -138,7 +140,7 @@ export class ThinkingComponent implements Component {
lines.push(p + contentLines[i]);
}
if (this.expanded || contentLines.length <= THINKING_PREVIEW_LINES + 1) {
if (this.expanded || !this.previewHidesLines) {
rendered = lines;
} else {
// Leading blank + first PREVIEW_LINES content lines + hint line.

View file

@ -11292,6 +11292,12 @@ capabilities = ["image_in", "video_in"]
} as Event,
vi.fn(),
);
driver.streamingUI.flushNow();
const streaming = stripSgr(renderTranscript(driver));
expect(streaming).toContain('t1');
expect(streaming).toContain('t7');
driver.sessionEventHandler.handleEvent(
{
type: 'assistant.delta',
@ -11303,6 +11309,7 @@ capabilities = ["image_in", "video_in"]
);
const transcript = stripSgr(renderTranscript(driver));
expect(transcript).toContain('t1');
expect(transcript).toContain('t7');
expect(transcript).not.toContain('ctrl+o expand');
});
@ -12489,18 +12496,35 @@ describe('transcript fold block clicks', () => {
expect(renderFooterLine1(driver)).toContain('ctrl+o expand');
});
it('toggles a long finalized thinking block without advertising it in the footer', async () => {
it('toggles live and finalized thinking without advertising it in the footer', async () => {
const { driver } = await makeDriver();
const longThinking = ['think-one', 'think-two', 'think-three', 'think-four'].join('\n');
const longThinking = ['think-one', 'think-two', 'think-three'].join('\n');
driver.streamingUI.onThinkingUpdate(longThinking);
const streaming = stripSgr(renderTranscript(driver));
expect(streaming).toContain('think-four');
expect(streaming).toContain('think-three');
expect(streaming).not.toContain('think-one');
clickTranscriptLine(driver, 'think-four');
clickTranscriptLine(driver, 'think-three');
expect(stripSgr(renderTranscript(driver))).toContain('think-one');
clickTranscriptLine(driver, 'think-one');
expect(stripSgr(renderTranscript(driver))).not.toContain('think-one');
clickTranscriptLine(driver, 'think-three');
expect(stripSgr(renderTranscript(driver))).toContain('think-one');
driver.streamingUI.onThinkingUpdate(`${longThinking}\nthink-four`);
const growing = stripSgr(renderTranscript(driver));
expect(growing).toContain('think-one');
expect(growing).toContain('think-four');
driver.streamingUI.onThinkingEnd();
const finalized = stripSgr(renderTranscript(driver));
expect(finalized).toContain('think-one');
expect(finalized).toContain('think-four');
expect(renderFooterLine1(driver)).not.toContain('ctrl+o');
clickTranscriptLine(driver, 'think-four');
const collapsed = stripSgr(renderTranscript(driver));
expect(collapsed).toContain('think-one');