Skip to content

feat(ai): add AI chat sidebar with code block and diff view components - #8358

Merged
utkarsh-bruno merged 5 commits into
usebruno:mainfrom
naman-bruno:feat/ai-sidebar
Jun 25, 2026
Merged

utkarsh-bruno merged 5 commits into
usebruno:mainfrom
naman-bruno:feat/ai-sidebar

Conversation

@naman-bruno

@naman-bruno naman-bruno commented Jun 24, 2026 •

Copy link
Copy Markdown
Collaborator

Description

JIRA

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Summary by CodeRabbit

  • New Features
    • Added an AI assistant sidebar with chat history, type-specific suggestions, model selection (including Auto), per-tab conversation persistence, and streaming with stop control.
    • Added AI-generated code diff previews with expandable hunks, accept/reject actions, and improved markdown/code-fence rendering with one-click code copy.
    • Enabled an “AI Assistant” entry point in the collection header when AI is enabled.
  • Bug Fixes
    • Improved layout resizing so the response pane remains visible when the container width shrinks.
  • Chores
    • Added a diff library dependency to support diff generation.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Review 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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 83272ce8-343a-49a2-8419-3c390d2bde34

📥 Commits

Reviewing files that changed from the base of the PR and between d5da538 and f6a158e.

📒 Files selected for processing (2)
  • packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js
  • packages/bruno-electron/src/ipc/ai/index.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/bruno-electron/src/ipc/ai/index.js
  • packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js

Walkthrough

Adds an AI chat sidebar to Bruno with Electron-backed streaming, Redux chat state, IndexedDB conversation storage, and UI for prompts, diffs, history, and code actions.

Changes

AI Chat Sidebar Feature

Layer / File(s) Summary
Electron prompt config and IPC wiring
packages/bruno-electron/src/ipc/ai/chat-prompts.js, packages/bruno-electron/src/ipc/ai/index.js
Defines content-type prompt templates, tool instructions, labels, and IPC registration for chat handling.
Electron streaming handler
packages/bruno-electron/src/ipc/ai/chat.js
Formats request context, redacts response data, defines tool schemas, and streams AI chat events through IPC with fallback code extraction.
IndexedDB chat persistence
packages/bruno-app/package.json, packages/bruno-app/src/utils/ai/chat-store.js
Adds the diff dependency and implements IndexedDB conversation storage helpers for save, list, load, and delete operations.
Redux chat slice and thunks
packages/bruno-app/src/providers/ReduxStore/index.js, packages/bruno-app/src/providers/ReduxStore/slices/chat.js
Registers the chat reducer and adds per-tab chat state, reducers, and thunks for streaming, persistence, history, stop, and code status updates.
Sidebar primitives and diff rendering
packages/bruno-app/src/components/AiChatSidebar/constants.js, packages/bruno-app/src/components/AiChatSidebar/utils.js, packages/bruno-app/src/components/AiChatSidebar/AssistantCodeBlock.js, packages/bruno-app/src/components/AiChatSidebar/DiffView/index.js, packages/bruno-app/src/components/AiChatSidebar/DiffView/StyledWrapper.js
Adds sidebar constants, markdown/segment utilities, the assistant code block, and the diff view with collapsed hunks, actions, and styling.
Sidebar shell and styling
packages/bruno-app/src/components/AiChatSidebar/index.js, packages/bruno-app/src/components/AiChatSidebar/StyledWrapper.js
Implements the sidebar component, message timeline, history UI, model selection, diff wiring, and full layout styling.
App-level wiring and entry points
packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js, packages/bruno-app/src/pages/Bruno/index.js, packages/bruno-app/src/components/RequestTabPanel/index.js
Adds the assistant toggle, mounts the sidebar in the main page, and clamps request pane width on resize.

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Suggested reviewers

  • helloanoop
  • bijin-bruno
  • lohit-bruno
  • sid-bruno
  • utkarsh-bruno

Poem

✨ A sidebar wakes with prompts and light,
Diffs unfold in the dead of night.
Streams hum soft through IPC lanes,
Chats persist with IndexedDB grains.
Click, compare, accept — code sings bright.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding the AI chat sidebar and its code block/diff view components.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@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: 12

🧹 Nitpick comments (1)
packages/bruno-app/src/components/AiChatSidebar/index.js (1)

655-738: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add stable data-testid hooks to the primary sidebar controls.

This new UI is currently testable only through titles, labels, and class names, which will make Playwright coverage brittle as the copy/icons evolve. As per coding guidelines, "Add data-testid to testable elements for Playwright in React components".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-app/src/components/AiChatSidebar/index.js` around lines 655 -
738, The primary AiChatSidebar controls currently lack stable Playwright
selectors, making tests reliant on titles, labels, and class names. Add
data-testid attributes to the key interactive elements in
AiChatSidebar/index.js, especially the new chat, history toggle, history
items/popover actions, close, stop/send, model selector trigger, and any other
primary sidebar controls used in tests. Use the existing component symbols like
handleNewChat, HistoryPopover, handleClose, handleStop, handleSubmit, and
ModelSelectorTrigger to locate and annotate the right elements without changing
behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/bruno-app/src/components/AiChatSidebar/DiffView/index.js`:
- Around line 80-95: The hunk expansion logic in expandUp and expandDown is
updating the opposite state buckets, so the chevrons reveal lines on the wrong
side of the collapsed diff. Swap the setters so expandUp updates expandedFromTop
and expandDown updates expandedFromBottom, and keep the remaining-line
calculation tied to the same side-specific state in DiffView.

In `@packages/bruno-app/src/components/AiChatSidebar/index.js`:
- Around line 377-406: The apply flow in handleApplyCode should not blindly
dispatch generated code when the live editor buffer is stale. Add a guard that
checks the same base-vs-current mismatch already detected in the stale-state
logic around the message rendering path, and if the buffer no longer matches,
prevent apply by disabling the action or forcing a re-read/regeneration instead
of dispatching updateRequestTests, updateRequestScript, updateResponseScript,
updateRequestDocs, or updateAppCode. Keep the accepted status update in
handleApplyCode only for the non-stale path, and use the existing
messageIndex/writeIndex state to route the stale case consistently.

In `@packages/bruno-app/src/components/AiChatSidebar/utils.js`:
- Around line 7-8: The highlight helper is inserting the fenced-code language
directly into the HTML class attribute, which leaves the AiChatSidebar Markdown
rendering path vulnerable. Update highlight in utils.js to sanitize or
allow-list the lang value before building the pre/code wrapper, and make sure
only a safe class name is emitted alongside the already escaped str content.

In `@packages/bruno-app/src/components/RequestTabPanel/index.js`:
- Around line 307-330: The ResizeObserver clamp in RequestTabPanel still leaves
the layout overflowing when the container width is smaller than both pane
minimums. Update the resize handling in the useEffect that watches
mainSectionRef so the fallback in the left-pane width calculation does not
always force MIN_LEFT_PANE_WIDTH when maxLeft is smaller; instead, add a
narrower-container branch that chooses a different fallback (such as temporarily
relaxing the left minimum or collapsing a pane) so the request/response panes
can still fit.

In `@packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js`:
- Around line 753-766: The AI Assistant toggle is currently nested inside the
non-scratch collection branch in CollectionHeader, which prevents scratch
workspace request tabs from ever opening the sidebar. Move the isAiEnabled /
toggleAiSidebar ActionIcon block out of the !isScratchCollection-only path so it
renders for scratch tabs too, while keeping the existing AI sidebar wiring
intact via the CollectionHeader and Bruno/index.js flow.

In `@packages/bruno-app/src/pages/Bruno/index.js`:
- Around line 168-170: The AI sidebar is still rendered from the Bruno page
shell even when the main pane has switched to non-request modes like Manage
Workspace or API Spec. Update the conditional around AiChatSidebar in
Bruno/index.js to use the same page-mode gating as RequestTabs/RequestTabPanel,
so it only appears on request pages when chat.isOpen and a collection is active.

In `@packages/bruno-app/src/providers/ReduxStore/slices/chat.js`:
- Around line 53-60: The chat slice is not preserving createdAt, so later saves
keep rewriting a conversation’s original timestamp. Update the ReduxStore chat
state in ensureChat/startNewConversation and the load/restore paths so createdAt
is initialized once when a conversation is created or loaded, then carried
forward unchanged through persistChat/saveConversation and related state
updates. Use the existing chat state helpers and conversation lifecycle methods
in chat.js to make sure createdAt is stored on the chat object and reused
instead of defaulting to a fresh timestamp.
- Around line 317-324: The error path in handleError leaves behind the streaming
assistant placeholder created earlier in the request flow, so the chat can stay
stuck in a partial-stream state. Update the failure handling in chat.js so that
when the requestId matches, you also clear or finalize the isStreaming assistant
entry associated with tabUid before cleanup/reject, alongside setAiError,
setAiLoading, and setCurrentRequestId. Use the existing handleError and cleanup
flow to locate the right spot and ensure the placeholder is removed on any
failed stream.
- Around line 230-334: The sendAiMessage thunk currently allows a second AI
request to start for the same tab while an existing one is still streaming,
which can interleave updates because currentRequestId and the streaming reducers
are tab-scoped. Add a guard at the start of sendAiMessage (before dispatching
the user/assistant placeholder messages) to reject or no-op when
getState().chat.chats[tabUid] already has an active request, using the existing
currentRequestId and loading state to detect it. Keep the behavior localized to
sendAiMessage and preserve the existing finishLifecycle and handleError cleanup
paths.
- Around line 179-371: Add regression tests for the new chat state machine in
the Redux slice by covering the persistence helpers and IPC stream lifecycle.
Write tests around persistChat, refreshChatHistory, openConversation,
removeConversation, persistCurrentConversation, sendAiMessage, and stopAiStream
to verify save/load/delete history behavior. Include happy-path coverage for
ai-chat-complete and ai-chat-stopped, plus an error-path test for ai-chat-error,
and assert the expected dispatches, cleanup, and persistence calls.

In `@packages/bruno-electron/src/ipc/ai/chat.js`:
- Around line 69-111: The prompt-building logic in the request context formatter
is sending sensitive request data verbatim, so redact secret-bearing fields
before appending them to parts. Update the header/params/body handling in the
chat context builder to mask values for sensitive names and token-like patterns
(for example Authorization, Cookie, API key, password, token) while preserving
non-sensitive metadata. Keep the fix localized to the request-to-prompt flow in
the AI chat IPC path so all enabled headers, query/path params, and body modes
use the same redaction rules.
- Around line 193-195: Validate the payload in renderer:ai-chat-stream before
any use of messages.map or requestId, since the current destructuring in the IPC
handler can throw before the try/catch and bypass main:ai-chat-error. Add an
upfront guard in ipcMain.on('renderer:ai-chat-stream', ...) to ensure requestId
is present and messages is a valid array before constructing allMessages, and if
invalid, emit the same graceful error path used by the existing handler. Apply
the same validation/fallback pattern wherever the ai chat stream payload is
processed again around the later matching block that also builds allMessages.

---

Nitpick comments:
In `@packages/bruno-app/src/components/AiChatSidebar/index.js`:
- Around line 655-738: The primary AiChatSidebar controls currently lack stable
Playwright selectors, making tests reliant on titles, labels, and class names.
Add data-testid attributes to the key interactive elements in
AiChatSidebar/index.js, especially the new chat, history toggle, history
items/popover actions, close, stop/send, model selector trigger, and any other
primary sidebar controls used in tests. Use the existing component symbols like
handleNewChat, HistoryPopover, handleClose, handleStop, handleSubmit, and
ModelSelectorTrigger to locate and annotate the right elements without changing
behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 017f2416-a3ba-41e2-ab48-aa60754328d9

📥 Commits

Reviewing files that changed from the base of the PR and between 42e9c9a and f38bf65.

📒 Files selected for processing (17)
  • packages/bruno-app/package.json
  • packages/bruno-app/src/components/AiChatSidebar/AssistantCodeBlock.js
  • packages/bruno-app/src/components/AiChatSidebar/DiffView/StyledWrapper.js
  • packages/bruno-app/src/components/AiChatSidebar/DiffView/index.js
  • packages/bruno-app/src/components/AiChatSidebar/StyledWrapper.js
  • packages/bruno-app/src/components/AiChatSidebar/constants.js
  • packages/bruno-app/src/components/AiChatSidebar/index.js
  • packages/bruno-app/src/components/AiChatSidebar/utils.js
  • packages/bruno-app/src/components/RequestTabPanel/index.js
  • packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js
  • packages/bruno-app/src/pages/Bruno/index.js
  • packages/bruno-app/src/providers/ReduxStore/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/chat.js
  • packages/bruno-app/src/utils/ai/chat-store.js
  • packages/bruno-electron/src/ipc/ai/chat-prompts.js
  • packages/bruno-electron/src/ipc/ai/chat.js
  • packages/bruno-electron/src/ipc/ai/index.js

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

♻️ Duplicate comments (1)
packages/bruno-app/src/components/RequestTabPanel/index.js (1)

320-323: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Narrow-container clamp is still neutralized by render-time min width.

This can set a smaller leftPaneWidth, but Line 618 re-clamps it with Math.max(leftPaneWidth, MIN_LEFT_PANE_WIDTH), so narrow layouts still overflow and can push the response pane off-screen.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-app/src/components/RequestTabPanel/index.js` around lines 320
- 323, The narrow-layout resize path in RequestTabPanel still gets overridden
later by the render-time minimum width clamp, so small widths can never take
effect. Update the width handling around setLeftPaneWidth in RequestTabPanel so
the resize result is allowed to remain below MIN_LEFT_PANE_WIDTH when the
container is narrow, and remove or gate the later Math.max(leftPaneWidth,
MIN_LEFT_PANE_WIDTH) logic so the left pane can shrink without forcing the
response pane off-screen.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@packages/bruno-app/src/components/RequestTabPanel/index.js`:
- Around line 320-323: The narrow-layout resize path in RequestTabPanel still
gets overridden later by the render-time minimum width clamp, so small widths
can never take effect. Update the width handling around setLeftPaneWidth in
RequestTabPanel so the resize result is allowed to remain below
MIN_LEFT_PANE_WIDTH when the container is narrow, and remove or gate the later
Math.max(leftPaneWidth, MIN_LEFT_PANE_WIDTH) logic so the left pane can shrink
without forcing the response pane off-screen.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 57ed6ff0-9a3b-4ddc-aa97-22bdd89977b8

📥 Commits

Reviewing files that changed from the base of the PR and between f38bf65 and 93ee39c.

📒 Files selected for processing (8)
  • packages/bruno-app/src/components/AiChatSidebar/DiffView/index.js
  • packages/bruno-app/src/components/AiChatSidebar/index.js
  • packages/bruno-app/src/components/AiChatSidebar/utils.js
  • packages/bruno-app/src/components/RequestTabPanel/index.js
  • packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js
  • packages/bruno-app/src/pages/Bruno/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/chat.js
  • packages/bruno-electron/src/ipc/ai/chat.js
🚧 Files skipped from review as they are similar to previous changes (7)
  • packages/bruno-app/src/pages/Bruno/index.js
  • packages/bruno-app/src/components/AiChatSidebar/utils.js
  • packages/bruno-app/src/components/AiChatSidebar/DiffView/index.js
  • packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js
  • packages/bruno-app/src/components/AiChatSidebar/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/chat.js
  • packages/bruno-electron/src/ipc/ai/chat.js

utkarsh-bruno
utkarsh-bruno previously approved these changes Jun 24, 2026

@utkarsh-bruno utkarsh-bruno left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I see a few coderabbit comments flagged as major. Other than that, it looks good.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants