diff --git a/.changeset/expand-live-thinking.md b/.changeset/expand-live-thinking.md new file mode 100644 index 00000000000..f07d4622390 --- /dev/null +++ b/.changeset/expand-live-thinking.md @@ -0,0 +1,5 @@ +--- +"@moonshot-ai/kimi-code": minor +--- + +Allow expanding thinking during streaming with Ctrl-O diff --git a/apps/kimi-code/src/tui/components/messages/thinking.ts b/apps/kimi-code/src/tui/components/messages/thinking.ts index f2fcbf2b1ad..75b14f68c61 100644 --- a/apps/kimi-code/src/tui/components/messages/thinking.ts +++ b/apps/kimi-code/src/tui/components/messages/thinking.ts @@ -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. diff --git a/apps/kimi-code/test/tui/kimi-tui-message-flow.test.ts b/apps/kimi-code/test/tui/kimi-tui-message-flow.test.ts index dfa1ab26203..b17007b226a 100644 --- a/apps/kimi-code/test/tui/kimi-tui-message-flow.test.ts +++ b/apps/kimi-code/test/tui/kimi-tui-message-flow.test.ts @@ -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');