Repository navigation
feat(ai): add AI chat sidebar with code block and diff view components - #8358
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:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughAdds 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. ChangesAI Chat Sidebar Feature
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 12
🧹 Nitpick comments (1)
packages/bruno-app/src/components/AiChatSidebar/index.js (1)
655-738: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd stable
data-testidhooks 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-testidto 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
📒 Files selected for processing (17)
packages/bruno-app/package.jsonpackages/bruno-app/src/components/AiChatSidebar/AssistantCodeBlock.jspackages/bruno-app/src/components/AiChatSidebar/DiffView/StyledWrapper.jspackages/bruno-app/src/components/AiChatSidebar/DiffView/index.jspackages/bruno-app/src/components/AiChatSidebar/StyledWrapper.jspackages/bruno-app/src/components/AiChatSidebar/constants.jspackages/bruno-app/src/components/AiChatSidebar/index.jspackages/bruno-app/src/components/AiChatSidebar/utils.jspackages/bruno-app/src/components/RequestTabPanel/index.jspackages/bruno-app/src/components/RequestTabs/CollectionHeader/index.jspackages/bruno-app/src/pages/Bruno/index.jspackages/bruno-app/src/providers/ReduxStore/index.jspackages/bruno-app/src/providers/ReduxStore/slices/chat.jspackages/bruno-app/src/utils/ai/chat-store.jspackages/bruno-electron/src/ipc/ai/chat-prompts.jspackages/bruno-electron/src/ipc/ai/chat.jspackages/bruno-electron/src/ipc/ai/index.js
There was a problem hiding this comment.
♻️ Duplicate comments (1)
packages/bruno-app/src/components/RequestTabPanel/index.js (1)
320-323: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winNarrow-container clamp is still neutralized by render-time min width.
This can set a smaller
leftPaneWidth, but Line 618 re-clamps it withMath.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
📒 Files selected for processing (8)
packages/bruno-app/src/components/AiChatSidebar/DiffView/index.jspackages/bruno-app/src/components/AiChatSidebar/index.jspackages/bruno-app/src/components/AiChatSidebar/utils.jspackages/bruno-app/src/components/RequestTabPanel/index.jspackages/bruno-app/src/components/RequestTabs/CollectionHeader/index.jspackages/bruno-app/src/pages/Bruno/index.jspackages/bruno-app/src/providers/ReduxStore/slices/chat.jspackages/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
left a comment
There was a problem hiding this comment.
I see a few coderabbit comments flagged as major. Other than that, it looks good.
Description
JIRA
Contribution Checklist:
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