Repository navigation
feat: 新增 AssistantRender hook 事件,支持 LLM 输出显示层重渲染 #1358
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
viggo-pod
wants to merge
1
commit into
claude-code-best:main
Choose a base branch
from
viggo-pod:feat/assistant-render-event
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.
+672
−3
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { describe, expect, test } from 'bun:test'; | ||
| import { randomUUID } from 'crypto'; | ||
| import type { RenderableMessage } from 'src/types/message.js'; | ||
| import { areMessageRowPropsEqual } from 'src/components/MessageRow.js'; | ||
| import { clearRenderCache, getRenderCacheVersion, setMessageRenderCache } from 'src/utils/hooks/renderCache.js'; | ||
|
|
||
| function assistantMessage(text: string): RenderableMessage { | ||
| return { | ||
| type: 'assistant', | ||
| uuid: randomUUID(), | ||
| message: { | ||
| role: 'assistant', | ||
| content: [{ type: 'text', text }], | ||
| }, | ||
| } as unknown as RenderableMessage; | ||
| } | ||
|
|
||
| // 最小 Props:比较器只消费其中少数字段,其余以空值填充 | ||
| function makeProps(message: RenderableMessage, renderCacheVersion = 0) { | ||
| return { | ||
| message, | ||
| isUserContinuation: false, | ||
| hasContentAfter: false, | ||
| tools: [], | ||
| commands: [], | ||
| verbose: false, | ||
| inProgressToolUseIDs: new Set<string>(), | ||
| streamingToolUseIDs: new Set<string>(), | ||
| screen: 'main', | ||
| canAnimate: false, | ||
| lastThinkingBlockId: null, | ||
| latestBashOutputUUID: null, | ||
| renderCacheVersion, | ||
| columns: 80, | ||
| isLoading: false, | ||
| lookups: { resolvedToolUseIDs: new Set<string>() }, | ||
| } as unknown as Parameters<typeof areMessageRowPropsEqual>[0]; | ||
| } | ||
|
|
||
| describe('areMessageRowPropsEqual (AssistantRender cache version)', () => { | ||
| test('renderCacheVersion bump forces re-render', () => { | ||
| clearRenderCache(); | ||
| const message = assistantMessage('render-target'); | ||
| const prev = makeProps(message, getRenderCacheVersion()); | ||
| expect(areMessageRowPropsEqual(prev, prev)).toBe(true); | ||
| setMessageRenderCache('render-target', 'ASCII'); | ||
| const next = makeProps(message, getRenderCacheVersion()); | ||
| expect(areMessageRowPropsEqual(prev, next)).toBe(false); | ||
| }); | ||
|
|
||
| test('same renderCacheVersion with static message bails out', () => { | ||
| clearRenderCache(); | ||
| setMessageRenderCache('stable', 'ASCII'); | ||
| const version = getRenderCacheVersion(); | ||
| const message = assistantMessage('stable'); | ||
| const prev = makeProps(message, version); | ||
| const next = makeProps(message, version); | ||
| expect(areMessageRowPropsEqual(prev, next)).toBe(true); | ||
| }); | ||
| }); |
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
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.
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.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🤖 get_repo_knowledge executed:
get_repo_knowledge claude-code-best/claude-code /tmp/coderabbit-repo-knowledge/claude-code-best-claude-code-3b145301Length of output: 2804
🏁 Script executed:
Repository: claude-code-best/claude-code
Length of output: 17812
🏁 Script executed:
Repository: claude-code-best/claude-code
Length of output: 17743
🏁 Script executed:
Repository: claude-code-best/claude-code
Length of output: 15076
🌐 Web query:
github claude-code src/entrypoints/sdk/coreSchemas.ts AssistantRender text_blocks message_id💡 Result:
The file src/entrypoints/sdk/coreSchemas.ts in the Claude Code codebase defines Zod schemas for SDK-related messages [1][2][3]. It does not contain an AssistantRender or text_blocks definition directly related to message_id in the way a component or renderer might [1][4]. Instead, logic involving message IDs and text content is handled in utilities such as src/utils/messages.ts [5]. Specifically, the function appendMessageTagToUserMessage in that file appends a [id:...] tag to the last text block of a user message to allow Claude to reference message IDs [5]. This utility identifies the last text block by iterating through the message content blocks and checking for a block with type: 'text' [5]. The schemas in src/entrypoints/sdk/coreSchemas.ts primarily define the structure of assistant, streamlined_text, and stream_event messages for the SDK, using lazy schema definitions [1][2][4]. These schemas ensure that fields such as uuid and session_id are present, but the specific rendering logic for text blocks and message IDs is managed in the message handling utilities [1][5].
Citations:
🏁 Script executed:
Repository: claude-code-best/claude-code
Length of output: 25844
🏁 Script executed:
Repository: claude-code-best/claude-code
Length of output: 1510
🏁 Script executed:
Repository: claude-code-best/claude-code
Length of output: 5428
Enforce the AssistantRenderHookInputSchema contract.
The producer passes only non-whitespace text blocks and always includes
message_id, but the exported schema accepts missing identifiers, empty arrays, whitespace-only text, and negative indexes. Apply the same constraints at the schema boundary.Proposed schema fix
📝 Committable suggestion
🤖 Prompt for AI Agents