Repository navigation
feat(native-chat): edit a reply's code block and add the edit to the next message - #33522
YangNuoCheng wants to merge 11 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
Actionable comments posted: 4

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
d23ccecf-62ba-4fe8-8320-33965b1ef97d
Files selected for processing: 12-
src/renderer/src/components/native-chat/NativeChatCodeBlock.edit.test.tsxsrc/renderer/src/components/native-chat/NativeChatCodeBlock.fixture.tsxsrc/renderer/src/components/native-chat/NativeChatCodeBlock.tsxsrc/renderer/src/components/native-chat/native-chat-code-block-edit.test.tssrc/renderer/src/components/native-chat/native-chat-code-block-edit.tssrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/fr.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/pt.jsonsrc/renderer/src/i18n/locales/zh.json
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
|
Thanks @coderabbitai[bot] — all four points are addressed in
I also merged |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments: 1
src/renderer/src/components/native-chat/NativeChatCodeBlock.edit.test.tsx: 1
94-95:Trivial · Maintainability & Code Quality · Quick win Give the dimmed-group test a visual owner.
Without
NativeChatVisualOwnerContext,NativeChatCodeBlockcannot expose Edit even if the dimmed-group gate is removed. Wrap the block withinChatinside thefalseediting provider.Suggested fix
<NativeChatVisualEditingContext.Provider value={false}> - <NativeChatCodeBlock language="text"> - <code>{'a\n'}</code> - </NativeChatCodeBlock> + {inChat( + <NativeChatCodeBlock language="text"> + <code>{'a\n'}</code> + </NativeChatCodeBlock> + )} </NativeChatVisualEditingContext.Provider>

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
48d68f39-147c-454b-af78-209963e4985b
Files selected for processing: 13-
src/renderer/src/components/native-chat/NativeChatCodeBlock.edit.test.tsxsrc/renderer/src/components/native-chat/NativeChatCodeBlock.tsxsrc/renderer/src/components/native-chat/NativeChatView.tsxsrc/renderer/src/components/native-chat/native-chat-code-block-edit.test.tssrc/renderer/src/components/native-chat/native-chat-code-block-edit.tssrc/renderer/src/components/native-chat/native-chat-visual-owner.tsxsrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/fr.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/pt.jsonsrc/renderer/src/i18n/locales/zh.json
Files skipped from review as they are similar to previous changes: 7-
- src/renderer/src/i18n/locales/en.json
- src/renderer/src/i18n/locales/pt.json
- src/renderer/src/i18n/locales/zh.json
- src/renderer/src/i18n/locales/ko.json
- src/renderer/src/i18n/locales/ja.json
- src/renderer/src/i18n/locales/fr.json
- src/renderer/src/i18n/locales/es.json
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
|
Thanks @coderabbitai — all four points are addressed on the branch (head bd67dfe):
Covered by |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain
One test needs a correction. In Wrap that test’s code block with the existing render(
inChat(
<NativeChatVisualEditingContext.Provider value={false}>
<NativeChatCodeBlock language="text">
<code>{'a\n'}</code>
</NativeChatCodeBlock>
</NativeChatVisualEditingContext.Provider>
)
)This isolates the editability gate while keeping a valid visual owner. Please rerun the focused tests after this change. I verified the source, but I did not run tests, lint, or typecheck. If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! You are interacting with an AI system. |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain
The dimmed-group test still needs the earlier correction. In Wrap the provider with the existing Please rerun the focused tests after this change. I inspected the source but did not run tests, lint, or typecheck. You are interacting with an AI system. |
|
Fixed in 6a64cfb. Dimmed split-group test: the code block is now wrapped with the existing Fence helper: dropping a language label that contains a backtick is intentional. CommonMark does not allow a backtick fence's info string to contain a backtick, so such a label cannot round-trip; the helper emits an unlabeled fence instead (see the comment in Happy to add a test covering the backtick-in-label fallback if that would help. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

Minor · Disable Edit for user-message code blocks. · NativeChatCodeBlock.tsx:41-55
src/renderer/src/components/native-chat/NativeChatCodeBlock.tsx:41-55
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winDisable Edit for user-message code blocks.
NativeChatUserMessageRowpassesNativeChatCodeBlockdirectly toNativeChatMarkdown. The component enables Edit when the owner, focused editing context, and non-plain conditions pass. It does not check the message role.A user-message code block in a focused structured chat can therefore expose Edit and append its contents to the composer. Add an explicit editability prop and set it to
falsefor user messages. Keep the existing owner and focus checks unchanged.Suggested fix
export function NativeChatCodeBlock({ children, language, sourceLine, - plain = false + plain = false, + editable = true }: { children?: React.ReactNode language?: string sourceLine?: number plain?: boolean + editable?: boolean }): React.JSX.Element { @@ - owner && editingAllowed && !plain ? structuredAgentSessionDraftScopeKey(owner.sessionId) : null + owner && editingAllowed && editable && !plain + ? structuredAgentSessionDraftScopeKey(owner.sessionId) + : null- renderCodeBlock={NativeChatCodeBlock} + renderCodeBlock={(props) => ( + <NativeChatCodeBlock {...props} editable={false} /> + )}

Minor · Use manual append semantics for Add to message. · NativeChatCodeBlock.tsx:79-87
src/renderer/src/components/native-chat/NativeChatCodeBlock.tsx:79-87
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winUse manual append semantics for Add to message.
Add to messagesends the fenced block throughappendNativeChatDraftCache, which is the returned-text replay path. If the user adds the same block again,appendReturnedDraftTextdetects the existing suffix and silently skips it. If the draft is/clearor/compact, the helper replaces that command instead of preserving it before the block.Add a producer-specific append operation for
NativeChatCodeBlock. It must always append the fenced block, including for duplicate text and lone conversation commands. KeepappendReturnedDraftTextunchanged becauseappendToNativeChatComposerDraftand its journal callback implement the hand-back and crash-replay contract.

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
72b4d2a1-2ab5-46f9-9a84-3b95d5b2ad31
Files selected for processing: 1-
src/renderer/src/components/native-chat/NativeChatCodeBlock.edit.test.tsx
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
…dded blocks User messages no longer offer Edit on their code blocks, and Add to message appends the fenced block verbatim instead of going through returned-text dedupe, so duplicates land and a lone /clear is preserved.
|
Thanks @coderabbitai — both points fixed in 0a551c9:
Tests, lint, and typecheck pass locally (the vitest teardown rpc warning also reproduces on the parent commit, so it is unrelated). |
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
85cd2a25-3fce-4113-be80-13485285cc65
Files selected for processing: 4-
src/renderer/src/components/native-chat/NativeChatCodeBlock.edit.test.tsxsrc/renderer/src/components/native-chat/NativeChatCodeBlock.tsxsrc/renderer/src/components/native-chat/NativeChatUserMessageRow.tsxsrc/renderer/src/components/native-chat/native-chat-draft-cache.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
-
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain
You are interacting with an AI system. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

Minor · Preserve the structured document when manually appending text. · native-chat-draft-cache.ts:61-72
src/renderer/src/components/native-chat/native-chat-draft-cache.ts:61-72
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick winPreserve the structured document when manually appending text.
When a draft contains a selected skill,
appendNativeChatDraftCacheManualclears its document. The cached text keeps the skill token but not itspath. On Send,promptSkillRefs(submitted.document)then returns no skill reference, so the selected skill is omitted from the request.Suggested fix
+import { appendPromptDocumentText } from './native-chat-prompt-document-text' ... - const previous = readNativeChatDraftCache(scopeKey) + const current = readNativeChatComposerDraft(scopeKey) + const previous = current.text const appended = previous === '' ? text : `${previous}\n\n${text}` - updateNativeChatComposerDraft(scopeKey, { text: appended, document: undefined }, 'immediate') + updateNativeChatComposerDraft( + scopeKey, + { + text: appended, + document: appendPromptDocumentText(current.document, previous, appended) + }, + 'immediate' + )

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
e50bf643-f07c-41a2-82f6-bf91a864c4e6
Files selected for processing: 1-
src/renderer/src/components/native-chat/native-chat-draft-cache.ts
Files skipped from review as they are similar to previous changes: 1-
- src/renderer/src/components/native-chat/native-chat-draft-cache.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
-
|
Addressed the remaining review points in two commits:
Tests for both are in |
…-code-block # Conflicts: # src/renderer/src/components/native-chat/NativeChatUserMessageRow.tsx # src/renderer/src/components/native-chat/native-chat-draft-cache.ts
… main's link-placement test
|
Thanks. I am leaving the docstring-coverage warning unchanged: |
|
Cross-linking #37407 — an umbrella issue for super-agent workflows; this PR covers the low-attention human step, editing a suggested block inline instead of re-typing context. |
…-code-block Move the code-block edit files into main's native-chat folders (markdown/code, drafts) and list the edit's copy keys as protected, since the code block is now a @protected-copy file.
|
Updated onto current main with a merge commit (61f34d8, no force-push), so the PR no longer conflicts with main. Main had moved native-chat into subfolders, so this PR now follows that layout:
Behavior is unchanged. On a fresh Linux checkout, the affected tests (10 files, 29 tests), the protected-copy key check and |
ELI5
An agent's answer in a chat often has text in a code block that you want to tweak before continuing: a rewritten paragraph, a commit message, a config. Now you can click Edit on the block, change it in place, and click Add to message. Your version lands in the message box, and you write your next instruction under it.
What Changed
Before: a code block in a chat reply had Wrap and Copy only. To change it, the user copied it, pasted it into the composer, re-typed the fence, and edited it there.
After: a code block in a structured chat reply also has Edit.
latex` …), then closes the editor. The fence is longer than any backtick run inside the text, so a block that itself holds a fence stays one block.Mechanism (renderer only):
NativeChatCodeBlockreads the chat it belongs to from the existingNativeChatVisualOwnerContextand appends throughappendNativeChatDraftCacheManual(structuredAgentSessionDraftScopeKey(sessionId), …). This manual append preserves the existing draft text and structured document, updates the mounted composer, and does not journal the appended block.fenceEditedCodeBlock(new, pure) builds the fence. New strings are added in all seven locales.Why
Editing an agent's text and continuing from your own version is a frequent step when working with agents on writing or config, and today it takes several manual steps. Reusing the existing composer draft store keeps the change small: no new IPC, no protocol change, nothing sent without the user pressing Send.
Linked Issue
Fixes #33521
Visual Proof
Before (main): a chat code block offers Wrap and Copy.
After: an Edit button sits before Wrap and Copy.
After, editing (dark and light):
Screenshots are from the new
native-chat/NativeChatCodeBlockcomponent fixture (pnpm fixtures:shot 'native-chat/NativeChatCodeBlock:*' --theme both).Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
NativeChatCodeBlock.edit.test.tsx(3 tests): Edit → change → Add to message writeslatex\nWe propose Y.\nto the chat's composer draft and closes the editor while the reply keeps its text; Escape leaves the draft empty; no Edit button outside a chat or on a dimmed row.native-chat-code-block-edit.test.ts(3 tests): language, trailing newline, and a fence longer than one inside the text.Existing
NativeChatCodeBlocktests still pass (15 total across the four files).pnpm lint(including the localization coverage check) andpnpm tcpass.Not run inside a full dev build of the desktop app; the component fixture above renders the real component with the app's styles in both themes. macOS only; the change is renderer-only and platform-neutral.
AI Disclosure
Implemented with an AI coding agent (Claude, claude-opus-5-5) under my direction; I reviewed the change.
Review
Agent skill upstream boundary
Notes
Security: the editor is a plain textarea; its text only reaches the composer draft, and nothing is sent until the user presses Send. Backwards compatibility: no stored data or protocol changes. Performance: one
useStateper code block; the editor mounts only while open.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)