-
Notifications
You must be signed in to change notification settings - Fork 971
fix(tui): reclaim transcript entries when turns fold #2603
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
Open
he-yufeng
wants to merge
1
commit into
MoonshotAI:main
Choose a base branch
from
he-yufeng:fix/tui-fold-entry-reclaim
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
111 changes: 111 additions & 0 deletions
111
apps/kimi-code/test/tui/transcript-fold-reclaim.test.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,111 @@ | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| import { KimiTUI, type KimiTUIStartupInput } from '#/tui/kimi-tui'; | ||
| import { StepSummaryComponent } from '#/tui/components/messages/step-summary'; | ||
|
|
||
| function makeHarness() { | ||
| return { | ||
| getConfig: vi.fn(async () => ({ | ||
| models: { | ||
| k2: { model: 'moonshot-v1', maxContextSize: 100 }, | ||
| }, | ||
| })), | ||
| createSession: vi.fn(async () => ({ id: 'ses-1', model: 'k2' })), | ||
| resumeSession: vi.fn(async () => ({ id: 'ses-1', model: 'k2' })), | ||
| listSessions: vi.fn(async () => []), | ||
| close: vi.fn(async () => {}), | ||
| track: vi.fn(), | ||
| setTelemetryContext: vi.fn(), | ||
| getExperimentalFeatures: vi.fn(async () => []), | ||
| supportsAtomicSectionReplace: vi.fn(() => false), | ||
| auth: { | ||
| status: vi.fn(async () => ({ providers: [] })), | ||
| login: vi.fn(async () => {}), | ||
| logout: vi.fn(), | ||
| getManagedUsage: vi.fn(), | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| function makeStartupInput(): KimiTUIStartupInput { | ||
| return { | ||
| cliOptions: { | ||
| session: undefined, | ||
| continue: false, | ||
| yolo: false, | ||
| auto: false, | ||
| plan: false, | ||
| model: undefined, | ||
| outputFormat: undefined, | ||
| prompt: undefined, | ||
| skillsDirs: [], | ||
| agent: undefined, | ||
| agentFiles: [], | ||
| }, | ||
| tuiConfig: { | ||
| theme: 'dark', | ||
| disablePasteBurst: false, | ||
| editorCommand: null, | ||
| notifications: { enabled: true, condition: 'unfocused' }, | ||
| upgrade: { autoInstall: true }, | ||
| statusLine: { items: null, command: null }, | ||
| }, | ||
| version: '0.0.0-test', | ||
| workDir: '/tmp/proj-a', | ||
| }; | ||
| } | ||
|
|
||
| function makeDriver() { | ||
| const driver = new KimiTUI(makeHarness() as never, makeStartupInput()); | ||
| vi.spyOn(driver.state.ui, 'requestRender').mockImplementation(() => {}); | ||
| vi.spyOn(driver.state.terminal, 'setProgress').mockImplementation(() => {}); | ||
| return driver; | ||
| } | ||
|
|
||
| describe('transcript fold entry reclaim', () => { | ||
| it('drops the folded assistant entries when a completed turn folds', () => { | ||
| const driver = makeDriver(); | ||
| driver.appendTranscriptEntry({ id: 'u1', kind: 'user', renderMode: 'plain', content: 'hello' }); | ||
| for (const id of ['a0', 'a1', 'a2', 'a3']) { | ||
| driver.appendTranscriptEntry({ | ||
| id, | ||
| kind: 'assistant', | ||
| turnId: 't1', | ||
| renderMode: 'markdown', | ||
| content: `message ${id}`, | ||
| modelText: true, | ||
| }); | ||
| } | ||
| expect(driver.state.transcriptEntries).toHaveLength(5); | ||
|
|
||
| const folded = driver.mergeCompletedTurnAssistants(); | ||
|
|
||
| expect(folded).toBe(true); | ||
| // the two oldest assistants merged into the summary; the tail stays | ||
| expect(driver.state.transcriptEntries.map((entry) => entry.id)).toEqual(['u1', 'a2', 'a3']); | ||
| const summaryCount = driver.state.transcriptContainer.children.filter( | ||
| (child) => child instanceof StepSummaryComponent, | ||
| ).length; | ||
| expect(summaryCount).toBe(1); | ||
| }); | ||
|
|
||
| it('keeps every entry when nothing exceeds the fold caps', () => { | ||
| const driver = makeDriver(); | ||
| driver.appendTranscriptEntry({ id: 'u1', kind: 'user', renderMode: 'plain', content: 'hello' }); | ||
| for (const id of ['a0', 'a1']) { | ||
| driver.appendTranscriptEntry({ | ||
| id, | ||
| kind: 'assistant', | ||
| turnId: 't1', | ||
| renderMode: 'markdown', | ||
| content: `message ${id}`, | ||
| modelText: true, | ||
| }); | ||
| } | ||
|
|
||
| const folded = driver.mergeCompletedTurnAssistants(); | ||
|
|
||
| expect(folded).toBe(false); | ||
| expect(driver.state.transcriptEntries.map((entry) => entry.id)).toEqual(['u1', 'a0', 'a1']); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When assistant blocks are created through the normal live or replay path,
StreamingUIController.onStreamingTextStart()pushes the entry and component separately without callingmarkTranscriptComponent(streaming-ui.ts:593-608), so this lookup returnsundefinedfor the assistant components being folded. Once a turn exceeds the assistant cap, the components disappear but their potentially large text entries remain intranscriptEntries; the new test misses this because it usesappendTranscriptEntry(), which does establish the mapping. Associate the entry when the streaming controller creates the component, or reclaim it through another reliable association.AGENTS.md reference: apps/kimi-code/AGENTS.md:L38-L39
Useful? React with 👍 / 👎.