Repository navigation
feat(tui): add sticky user messages in fullscreen mode #4031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@moonshot-ai/kimi-code": minor | ||
| --- | ||
|
|
||
| Add sticky user message summaries in fullscreen mode; click a summary to jump to the original message. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@moonshot-ai/kimi-code": patch | ||
| --- | ||
|
|
||
| Replace the user message bullet ✨ with ❯. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@moonshot-ai/pi-tui": minor | ||
| --- | ||
|
|
||
| Add fullscreen layout effects that settle render requests before terminal output. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
apps/kimi-code/src/tui/components/messages/sticky-user-message.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { | ||
| truncateToWidth, | ||
| type Component, | ||
| type TuiMouseEvent, | ||
| type TuiMouseEventResult, | ||
| } from '@moonshot-ai/pi-tui'; | ||
|
|
||
| import { TRUNCATION_ELLIPSIS } from '#/tui/constant/rendering'; | ||
| import { USER_MESSAGE_BULLET } from '#/tui/constant/symbols'; | ||
| import { currentTheme } from '#/tui/theme'; | ||
| import type { StickyUserMessageJudgment } from '#/tui/utils/sticky-user-message'; | ||
|
|
||
| export class StickyUserMessageComponent implements Component { | ||
| private judgment: StickyUserMessageJudgment | null = null; | ||
|
|
||
| constructor(private readonly scrollTo: (y: number) => void) {} | ||
|
|
||
| setJudgment(judgment: StickyUserMessageJudgment | null): boolean { | ||
| if ( | ||
| this.judgment?.component === judgment?.component && | ||
| this.judgment?.summary === judgment?.summary && | ||
| this.judgment?.targetY === judgment?.targetY | ||
| ) { | ||
| return false; | ||
| } | ||
| this.judgment = judgment; | ||
| return true; | ||
| } | ||
|
|
||
| invalidate(): void {} | ||
|
|
||
| render(width: number): string[] { | ||
| const safeWidth = Math.max(0, width); | ||
| if (this.judgment === null || safeWidth <= 0) return []; | ||
|
|
||
| const line = truncateToWidth( | ||
| USER_MESSAGE_BULLET + this.judgment.summary, | ||
| safeWidth, | ||
| TRUNCATION_ELLIPSIS, | ||
| ); | ||
| return [currentTheme.boldFg('roleUser', line)]; | ||
| } | ||
|
|
||
| handleMouse(event: TuiMouseEvent): TuiMouseEventResult | undefined { | ||
| if (event.type === 'click' && event.button === 'left' && this.judgment !== null) { | ||
| this.scrollTo(this.judgment.targetY); | ||
| return { handled: true }; | ||
| } | ||
| return undefined; | ||
| } | ||
| } |
71 changes: 71 additions & 0 deletions
71
apps/kimi-code/src/tui/components/messages/transcript-view.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { ScrollView, VStack, type Component, type TuiMouseEvent } from '@moonshot-ai/pi-tui'; | ||
|
|
||
| import { GutterContainer } from '#/tui/components/chrome/gutter-container'; | ||
| import { StickyUserMessageComponent } from '#/tui/components/messages/sticky-user-message'; | ||
| import { CHROME_GUTTER } from '#/tui/constant/rendering'; | ||
| import { StickyUserMessageIndex } from '#/tui/utils/sticky-user-message'; | ||
|
|
||
| export class TranscriptView extends VStack { | ||
| private readonly scrollView: ScrollView; | ||
| private readonly pill: StickyUserMessageComponent; | ||
| private readonly messages = new StickyUserMessageIndex(); | ||
| private paddingTop = 1; | ||
|
|
||
| constructor(private readonly transcript: GutterContainer) { | ||
| super(); | ||
| let cachedBody: string[] | undefined; | ||
| let paddedBody: string[] | undefined; | ||
| const content = { | ||
| children: [transcript], | ||
| render: (width: number) => { | ||
| const lines = transcript.render(width); | ||
| if (cachedBody !== lines) { | ||
| cachedBody = lines; | ||
| paddedBody = undefined; | ||
| } | ||
| if (this.paddingTop === 0) return lines; | ||
| return (paddedBody ??= ['', ...lines]); | ||
| }, | ||
| invalidate: () => { | ||
| transcript.invalidate(); | ||
| }, | ||
| handleMouse: (event: TuiMouseEvent) => { | ||
| if (event.y < this.paddingTop) return undefined; | ||
| return transcript.handleMouse({ | ||
| ...event, | ||
| y: event.y - this.paddingTop, | ||
| height: event.height - this.paddingTop, | ||
| }); | ||
| }, | ||
| } satisfies Component & { children: Component[] }; | ||
| this.scrollView = new ScrollView(content, { | ||
| follow: 'end', | ||
| primary: true, | ||
| overscroll: 'chain', | ||
| scrollbar: 'auto', | ||
| }); | ||
| this.pill = new StickyUserMessageComponent((y) => { | ||
| this.scrollView.scrollTo(y); | ||
| }); | ||
| const pillContainer = new GutterContainer(CHROME_GUTTER, CHROME_GUTTER); | ||
| pillContainer.addChild(this.pill); | ||
| this.addChild(pillContainer, { shrink: 0, minSize: 0 }); | ||
| this.addChild(this.scrollView, { basis: 0, grow: 1, shrink: 1, minSize: 0 }); | ||
| } | ||
|
|
||
| updateStickyMessage(): boolean { | ||
| const layout = this.transcript.getRenderedLayout(); | ||
| if (!layout) return false; | ||
| const height = this.scrollView.viewportHeight + (this.paddingTop === 0 ? 1 : 0); | ||
| const judgment = | ||
| height < 2 | ||
| ? null | ||
| : this.messages.getJudgment( | ||
| layout, | ||
| this.scrollView.scrollTop, | ||
| this.scrollView.isFollowingEnd, | ||
| ); | ||
| this.paddingTop = judgment === null ? 1 : 0; | ||
| return this.pill.setJudgment(judgment); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.