Skip to content

feat(native-chat): edit a reply's code block and add the edit to the next message - #33522

Open
YangNuoCheng wants to merge 11 commits into
stablyai:mainfrom
YangNuoCheng:feat/native-chat-edit-code-block
Open

YangNuoCheng wants to merge 11 commits into
stablyai:mainfrom
YangNuoCheng:feat/native-chat-edit-code-block

Conversation

@YangNuoCheng

@YangNuoCheng YangNuoCheng commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

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.

  • Edit turns the block into a text field in place, at the code block's font and size, growing with its content.
  • Add to message appends the edit to this chat's composer draft as a fenced block in the block's language (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.
  • Cancel or Escape closes the editor and leaves the composer unchanged. The reply itself is never modified.

Mechanism (renderer only):

  • NativeChatCodeBlock reads the chat it belongs to from the existing NativeChatVisualOwnerContext and appends through appendNativeChatDraftCacheManual(structuredAgentSessionDraftScopeKey(sessionId), …). This manual append preserves the existing draft text and structured document, updates the mounted composer, and does not journal the appended block.
  • Without that context (code blocks outside a structured chat) or on dimmed rows, no Edit button is shown.
  • 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.

Before: code block with wrap and copy

After: an Edit button sits before Wrap and Copy.

After: code block with edit, wrap and copy

After, editing (dark and light):

Editing a code block, dark

Editing a code block, light

Screenshots are from the new native-chat/NativeChatCodeBlock component 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 writes latex\nWe propose Y.\n to 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 NativeChatCodeBlock tests still pass (15 total across the four files).

  • pnpm lint (including the localization coverage check) and pnpm tc pass.

  • 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

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 useState per code block; the editor mounts only while open.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
Walkthrough

NativeChatCodeBlock now allows in-place editing of eligible code blocks when a visual owner exists and visual editing is allowed. Users can cancel an edit or add the edited code to the scoped chat draft as a fenced block. The change adds fence formatting, tests, fixtures, and translations in seven locales. User-message code blocks have editing disabled.

Merge Risk: Moderate · previous review f3692

Adding an edited block can silently omit a selected skill from the next message. Fix that draft loss before merging; keyboard focus also needs restoration when the editor closes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title clearly identifies the main change: editing code blocks in native chat replies and adding the edited content to the next message.
Linked Issues check Passed Directly linked issue #33521 requests: (1) an Edit action on code blocks in structured chat replies; (2) in-place editing in a text field; (3) Cancel and Escape close the editor; (4) Add to message ap…
Out of Scope Changes check Passed Changed areas and their link to #33521:
- native-chat-code-block-edit.ts: pure fence helper used by Add to message. Supports requirement 4.
- NativeChatCodeBlock.tsx: Edit button, editor, Cancel and E…
Description check Passed The description follows the required structure and clearly explains the user impact, implementation, linked issue, visual proof, testing, AI disclosure, scope, and compatibility considerations. The Ri…
Full details: Linked Issues check

Explanation

Directly linked issue #33521 requests: (1) an Edit action on code blocks in structured chat replies; (2) in-place editing in a text field; (3) Cancel and Escape close the editor; (4) Add to message appends a same-language fenced block to this chat's composer, after existing draft text; (5) no change to the agent, protocol, or stored transcript; (6) dimmed rows and code blocks outside a chat stay read-only.

Evidence at head, read from NativeChatCodeBlock.tsx and native-chat-draft-cache.ts:

  • Requirement 1 and 6: draftScopeKey is set only when owner (visual owner context) exists, useNativeChatVisualEditingAllowed() is true, editable is true, and plain is false. Only then does NativeChatCodeEditButton render.
  • Requirement 2: NativeChatCodeEditor renders a Textarea with autoFocus, labeled by the 'Edited code' string.
  • Requirement 3: the container onKeyDown handles Escape from any focused control. Cancel calls onCancel, which sets editText to null. The reply children are not changed.
  • Requirement 4: onAddToMessage calls appendNativeChatDraftCacheManual(draftScopeKey, fenceEditedCodeBlock(editText, language)). That function appends after existing text with a two-newline separator, and the fence helper is in native-chat-code-block-edit.ts.
  • Requirement 5: the write goes only to the composer draft store. No IPC, protocol, or transcript write appears in the head source for these files. The text reaches the agent only on the user's next Send.

Discrepancy noted, not a requirement failure: the PR description says the append uses appendNativeChatDraftCache and is journaled. The head code uses appendNativeChatDraftCacheManual, which is documented as not journaled. The issue does not require journaling. The code is the basis for this assessment.

Unresolved uncertainty: the whole-PR text diff was not read in full. Test results were not run in this review. The assessment relies on the head source and the reported test coverage.

Full details: Out of Scope Changes check

Explanation

Changed areas and their link to #33521:

  • native-chat-code-block-edit.ts: pure fence helper used by Add to message. Supports requirement 4.
  • NativeChatCodeBlock.tsx: Edit button, editor, Cancel and Escape handling, and Add to message. Core feature.
  • native-chat-draft-cache.ts: appendNativeChatDraftCacheManual. This is the append path for Add to message. It deliberately skips duplicate detection and lone /clear or /compact replacement, so the user's fenced block lands as written. This supports requirement 4. It writes only the composer draft, not the agent or transcript.
  • native-chat-visual-owner.tsx and NativeChatView.tsx: pass isFocusedGroup, so dimmed split-group panes stay read-only. Supports requirement 6.
  • NativeChatUserMessageRow.tsx: editable={false}, so user-message code blocks stay read-only. Supports requirement 6.
  • Test and fixture files (NativeChatCodeBlock.edit.test.tsx, native-chat-code-block-edit.test.ts, NativeChatCodeBlock.fixture.tsx): cover the new behavior.
  • Seven locale files: add the new UI strings only.

No change to the agent, IPC, protocol, stored transcript, or automatic send appears in the head source. The PR description's journaling claim does not match the code. This is a documentation mismatch and does not add unrelated scope.

Full details: Description check

Explanation

The description follows the required structure and clearly explains the user impact, implementation, linked issue, visual proof, testing, AI disclosure, scope, and compatibility considerations. The Risk section does not provide an explicit level or rollback plan, and manual testing and full build validation were not completed, but the description is otherwise sufficiently complete.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Commits

Reviewing files that changed from the base of the PR and between ced9a3d and fbb8090.

Files selected for processing: 12
  • src/renderer/src/components/native-chat/NativeChatCodeBlock.edit.test.tsx
  • src/renderer/src/components/native-chat/NativeChatCodeBlock.fixture.tsx
  • src/renderer/src/components/native-chat/NativeChatCodeBlock.tsx
  • src/renderer/src/components/native-chat/native-chat-code-block-edit.test.ts
  • src/renderer/src/components/native-chat/native-chat-code-block-edit.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/fr.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/pt.json
  • src/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.

@YangNuoCheng

Copy link
Copy Markdown
Contributor Author

Thanks @coderabbitai[bot] — all four points are addressed in bd67dfe94c (pushed):

  • Backtick-run spread: fenceEditedCodeBlock now computes the longest backtick run in a loop instead of spreading into Math.max, so a very large block can no longer throw before the draft is updated.
  • Backtick in the language label: a label containing a backtick now drops to an unlabeled fence (covered by a new unit test: fenceEditedCodeBlock("x", "jsx")returns an unlabeled fence aroundx`).
  • Dimmed split groups: editing is now gated on a new NativeChatVisualEditingContext fed from isFocusedGroup, separate from the visual owner, so a dimmed pane's code blocks stay read-only (new test: no Edit button when editing is disallowed).
  • Escape with button focus: the Escape handler moved from the textarea to the editor container, so Escape closes the editor after tabbing to Cancel or Add to message (new test covers Cancel-focused Escape).

I also merged origin/main in to clear the merge conflict. Affected tests, pnpm lint, and pnpm tc all pass locally.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, NativeChatCodeBlock cannot expose Edit even if the dimmed-group gate is removed. Wrap the block with inChat inside the false editing 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
Commits

Reviewing files that changed from the base of the PR and between fbb8090 and bd67dfe.

Files selected for processing: 13
  • src/renderer/src/components/native-chat/NativeChatCodeBlock.edit.test.tsx
  • src/renderer/src/components/native-chat/NativeChatCodeBlock.tsx
  • src/renderer/src/components/native-chat/NativeChatView.tsx
  • src/renderer/src/components/native-chat/native-chat-code-block-edit.test.ts
  • src/renderer/src/components/native-chat/native-chat-code-block-edit.ts
  • src/renderer/src/components/native-chat/native-chat-visual-owner.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/fr.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/pt.json
  • src/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.

@YangNuoCheng

Copy link
Copy Markdown
Contributor Author

Thanks @coderabbitai — all four points are addressed on the branch (head bd67dfe):

  1. Backtick-run spread — fenceEditedCodeBlock now computes the longest backtick run in a loop instead of spreading into Math.max, so a large block with many runs can no longer throw before the draft is updated.
  2. Backtick in the language label — a label containing a backtick is dropped and the block is emitted unlabeled, so the appended text is always a valid backtick-fenced block. Ordinary labels (latex, js, md, …) pass through unchanged.
  3. Editing gated on the focused group — a NativeChatVisualEditingContext now carries focused-group editability alongside the visual owner, and draftScopeKey is only set when both the owner exists and editing is allowed. Dimmed split-group panes keep a read-only block; the visual owner itself stays available to other features.
  4. Escape anywhere in the editor — the Escape handler moved from the textarea to the editor container, so tabbing to Cancel or Add to message and pressing Escape still closes the editor.

Covered by native-chat-code-block-edit.test.ts and NativeChatCodeBlock.edit.test.tsx (9 tests passing), plus full lint and typecheck on the merged head.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
git rev-parse --short HEAD
for name in native-chat-code-block-edit.ts native-chat-code-block-edit.test.ts NativeChatCodeBlock.tsx NativeChatCodeBlock.edit.test.tsx native-chat-visual-owner.tsx; do
  while IFS= read -r file; do
    printf '\n--- %s outline ---\n' "$file"
    ast-grep outline "$file" || true
    printf '\n--- %s source ---\n' "$file"
    sed -n '1,320p' "$file"
  done < <(fd --type f --fixed-strings "$name" src/renderer/src/components/native-chat)
done
rg -n -C 5 'NativeChatVisualOwnerProvider|isFocusedGroup=' src/renderer/src/components/native-chat/NativeChatView.tsx

Length of output: 21099


@YangNuoCheng Thanks for the update. I inspected bd67dfe9 and confirmed that all four implementation changes are present.

One test needs a correction. In NativeChatCodeBlock.edit.test.tsx, “offers no edit in a dimmed split group” does not provide a visual owner. The Edit button therefore stays hidden even if the component ignores NativeChatVisualEditingContext.

Wrap that test’s code block with the existing inChat helper:

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.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
git rev-parse --short HEAD
for name in NativeChatCodeBlock.edit.test.tsx native-chat-code-block-edit.ts; do
  while IFS= read -r file; do
    printf '\n--- %s outline ---\n' "$file"
    ast-grep outline "$file"
    printf '\n--- %s source ---\n' "$file"
    sed -n '1,200p' "$file"
  done < <(fd --type f --fixed-strings "$name" src/renderer/src/components/native-chat)
done

Length of output: 5970


@YangNuoCheng Thanks for the fixes. I checked bd67dfe9. The fence helper uses a loop and drops language labels that contain a backtick.

The dimmed-group test still needs the earlier correction. In src/renderer/src/components/native-chat/NativeChatCodeBlock.edit.test.tsx, “offers no edit in a dimmed split group” does not provide a visual owner. It can therefore pass without testing the editability gate.

Wrap the provider with the existing inChat helper:

render(
  inChat(
    <NativeChatVisualEditingContext.Provider value={false}>
      <NativeChatCodeBlock language="text">
        <code>{'a\n'}</code>
      </NativeChatCodeBlock>
    </NativeChatVisualEditingContext.Provider>
  )
)

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.

@YangNuoCheng

Copy link
Copy Markdown
Contributor Author

Fixed in 6a64cfb.

Dimmed split-group test: the code block is now wrapped with the existing inChat helper, so the test has a valid visual owner and actually exercises the editability gate. Focused tests rerun: 5 passed. pnpm lint and pnpm tc also pass.

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 fenceEditedCodeBlock). The loop itself is also deliberate: spreading a large block's backtick runs into Math.max could exceed the function-argument limit and throw before the draft is saved.

Happy to add a test covering the backtick-in-label fallback if that would help.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (2)

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 win

Disable Edit for user-message code blocks.

NativeChatUserMessageRow passes NativeChatCodeBlock directly to NativeChatMarkdown. 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 false for 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 win

Use manual append semantics for Add to message.

Add to message sends the fenced block through appendNativeChatDraftCache, which is the returned-text replay path. If the user adds the same block again, appendReturnedDraftText detects the existing suffix and silently skips it. If the draft is /clear or /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. Keep appendReturnedDraftText unchanged because appendToNativeChatComposerDraft and 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
Commits

Reviewing files that changed from the base of the PR and between bd67dfe and 6a64cfb.

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.
@YangNuoCheng

Copy link
Copy Markdown
Contributor Author

Thanks @coderabbitai — both points fixed in 0a551c9:

  • User-message code blocks are now read-only: NativeChatCodeBlock gains an editable prop (default true), and NativeChatUserMessageRow passes editable={false}.
  • Add to message now uses a new appendNativeChatDraftCacheManual path that always appends the fenced block (duplicates included) and preserves a lone /clear / /compact. It bypasses appendReturnedDraftText dedupe/command replacement and is not journaled, so returned-text crash replay cannot duplicate it. appendReturnedDraftText and the existing hand-back pipeline are unchanged.

Tests, lint, and typecheck pass locally (the vitest teardown rpc warning also reproduces on the parent commit, so it is unrelated).

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Commits

Reviewing files that changed from the base of the PR and between 6a64cfb and 0a551c9.

Files selected for processing: 4
  • src/renderer/src/components/native-chat/NativeChatCodeBlock.edit.test.tsx
  • src/renderer/src/components/native-chat/NativeChatCodeBlock.tsx
  • src/renderer/src/components/native-chat/NativeChatUserMessageRow.tsx
  • 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.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
git rev-parse --short HEAD
for file in \
src/renderer/src/components/native-chat/NativeChatCodeBlock.tsx \
src/renderer/src/components/native-chat/NativeChatUserMessageRow.tsx \
src/renderer/src/components/native-chat/native-chat-draft-cache.ts \
src/renderer/src/components/native-chat/NativeChatCodeBlock.edit.test.tsx; do
  printf '\n--- %s outline ---\n' "$file"
  ast-grep outline "$file"
done
printf '\n--- code-block editing ---\n'
rg -n -C 7 'editable|draftScopeKey|appendNativeChatDraftCacheManual' src/renderer/src/components/native-chat/NativeChatCodeBlock.tsx
printf '\n--- user-message rendering ---\n'
rg -n -C 6 'NativeChatCodeBlock' src/renderer/src/components/native-chat/NativeChatUserMessageRow.tsx
printf '\n--- manual and returned append paths ---\n'
rg -n -A 65 -B 8 '^export function appendNativeChatDraftCache' src/renderer/src/components/native-chat/native-chat-draft-cache.ts
printf '\n--- focused regression tests ---\n'
sed -n '1,230p' src/renderer/src/components/native-chat/NativeChatCodeBlock.edit.test.tsx

Length of output: 17506


@YangNuoCheng I couldn't produce a complete response to this request. Please try again.


📝 I couldn't check this conversation for new learnings, so no new learning was saved.

You are interacting with an AI system.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

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 win

Preserve the structured document when manually appending text.

When a draft contains a selected skill, appendNativeChatDraftCacheManual clears its document. The cached text keeps the skill token but not its path. 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
Commits

Reviewing files that changed from the base of the PR and between 0a551c9 and f36928d.

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.

@YangNuoCheng

Copy link
Copy Markdown
Contributor Author

Addressed the remaining review points in two commits:

  • efa9d7e: appending an edited block by hand now keeps the structured composer document instead of clearing it, so a selected skill still reaches the request on send (appendPromptDocumentText grows the existing document alongside the text).
  • 64c9afa: after Cancel or Escape, the remounted Edit button regains focus via a ref flag set only on explicit exits, so initial mounts and blurs never steal focus.

Tests for both are in NativeChatCodeBlock.edit.test.tsx and native-chat-draft-cache.test.ts.

…-code-block

# Conflicts:
#	src/renderer/src/components/native-chat/NativeChatUserMessageRow.tsx
#	src/renderer/src/components/native-chat/native-chat-draft-cache.ts
@YangNuoCheng

Copy link
Copy Markdown
Contributor Author

Thanks. I am leaving the docstring-coverage warning unchanged: AGENTS.md asks contributors to avoid comments unless the code needs explanation. Adding docstrings solely to reach the bot's 80% threshold would conflict with that guidance.

@YangNuoCheng

Copy link
Copy Markdown
Contributor Author

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.
@YangNuoCheng

Copy link
Copy Markdown
Contributor Author

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:

  • The edit files live in markdown/code/.
  • appendNativeChatDraftCacheManual moved into drafts/native-chat-draft-views.ts, with its test beside it, because native-chat-draft-cache.ts was removed on main.
  • The four new copy keys are listed in protected-copy-keys.json, because the code block is now a @protected-copy file.

Behavior is unchanged. On a fresh Linux checkout, the affected tests (10 files, 29 tests), the protected-copy key check and typecheck:web pass. Ready for review when you have time.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Edit a code block in a chat reply and continue from your version

1 participant