Skip to content

feat: integrate AIAssist for script editing - #8220

Merged
sid-bruno merged 3 commits into
usebruno:mainfrom
naman-bruno:feat/script-gen
Jun 10, 2026
Merged

sid-bruno merged 3 commits into
usebruno:mainfrom
naman-bruno:feat/script-gen

Conversation

@naman-bruno

@naman-bruno naman-bruno commented Jun 10, 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
    • AI-assisted script generation UI added to pre-request, post-response, and tests editors with suggestion chips, keyboard shortcut (⌘/Ctrl+Enter), preview, and apply flow.
  • Utilities
    • Renderer/electron-side AI generation support with prompt assembly, request-context handling, model selection, and error reporting.
  • Styling
    • New styling for AI assist trigger, popup, input, suggestion chips, preview panel, buttons, and loading states.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

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: 86d6a42d-4302-4231-8a07-bbcd97fff2cf

📥 Commits

Reviewing files that changed from the base of the PR and between 65b6b41 and 86b7c48.

📒 Files selected for processing (1)
  • packages/bruno-app/src/components/AIAssist/index.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/bruno-app/src/components/AIAssist/index.js

Walkthrough

Adds AI-assisted script generation: backend prompt templates and IPC handler, renderer IPC wrapper and request-context helper, a styled AIAssist React popup component, and integrations placing the assistant beside script/tests editors across collection, folder, and request panes.

Changes

AI Script Generation Feature

Layer / File(s) Summary
Prompt templates and helpers (backend)
packages/bruno-electron/src/ipc/ai/script-prompts.js
Defines BRUNO_API_REFERENCE, COMMON_OUTPUT_RULES, phase-specific SCRIPT_PROMPTS, formatRequestContext, buildScriptUserPrompt, and stripCodeFences, and exports prompt templates and helpers.
IPC handler & model selection
packages/bruno-electron/src/ipc/ai/index.js
Imports prompt utilities, adds pickDefaultModelId() and the renderer:ai-generate-script IPC endpoint that validates input, selects/resolves a model, calls generateText, and returns cleaned content or structured errors.
Renderer IPC wrapper & request-context
packages/bruno-app/src/utils/ai/index.js
Adds aiGenerateScript(params) that forwards to renderer:ai-generate-script and buildRequestContextFromItem(item) to normalize an item's request (url, method, headers, params, body) for prompts.
AIAssist styling (StyledWrapper)
packages/bruno-app/src/components/AIAssist/StyledWrapper.js
Styled-component with CSS for the assist trigger, popup container/header/body, input, suggestion chips, loading spinner animation, primary/secondary buttons, and generated-preview layout.
AIAssist component
packages/bruno-app/src/components/AIAssist/index.js
Reusable React component managing open/close, suggestions, keyboard shortcut (⌘/Ctrl+Enter), outside/ESC close, calls aiGenerateScript, shows loading/error, previews generated script, and applies it via onApply.
Collection & Folder settings integrations
packages/bruno-app/src/components/CollectionSettings/..., packages/bruno-app/src/components/FolderSettings/...
Places AIAssist beside CodeEditor in pre-request, post-response, and tests editors; wraps editors in relative containers and wires scriptType, currentScript, and onApply to existing update handlers.
RequestPane integrations with request context
packages/bruno-app/src/components/RequestPane/...
Adds AIAssist to request-level editors, memoizes requestContext from item via buildRequestContextFromItem, and passes it to AIAssist while preserving CodeEditor and Redux wiring.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • usebruno/bruno#8178: Both PRs wire up shared AI preferences/state and provider/model plumbing that this PR relies on for enablement and default model selection.
  • usebruno/bruno#8048: Introduces foundational AI infrastructure (providers, models, API key management) connected to the IPC/model selection logic used here.

Suggested reviewers

  • helloanoop
  • bijin-bruno
  • lohit-bruno

Poem

✨ A small popup hums, suggestions in a line,
Prompt and context woven, trimmed of codefence fine,
From pre-request to tests the helper learns your need,
A gentle Back, an Apply — your scripts now take seed,
Spinner spins, then scripts appear — a tiny coding vine. 🌱

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: integrate AIAssist for script editing' directly summarizes the main change—adding AI-assisted editing across multiple script components.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 and usage tips.

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

Looks good

@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

🧹 Nitpick comments (3)
packages/bruno-app/src/components/AIAssist/index.js (2)

48-49: 💤 Low value

Remove unnecessary memoization.

Lines 48–49 use useMemo for simple object lookups (SUGGESTIONS[scriptType], TITLES[scriptType]). These are O(1) operations—not expensive enough to justify memoization. Per coding guidelines ("Memoize only when necessary"), inline them:

- const suggestions = useMemo(() => SUGGESTIONS[scriptType] || [], [scriptType]);
- const title = TITLES[scriptType] || 'Generate with AI';
+ const suggestions = SUGGESTIONS[scriptType] || [];
+ const title = TITLES[scriptType] || 'Generate with AI';
🤖 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/AIAssist/index.js` around lines 48 - 49,
Remove the unnecessary useMemo wrappers around simple lookups: replace the
memoized expressions that compute suggestions and title (the useMemo calls
referencing SUGGESTIONS[scriptType] and TITLES[scriptType]) with direct
assignments so suggestions = SUGGESTIONS[scriptType] || [] and title =
TITLES[scriptType] || 'Generate with AI'; remove the import/use of useMemo if it
becomes unused.

225-226: 💤 Low value

Extract inline style to StyledWrapper.

The inline style object at line 225 ({ display: 'inline-flex', alignItems: 'center', gap: 4 }) could be extracted to StyledWrapper as a .back-button-content class for consistency with the rest of the component's styling approach.

🤖 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/AIAssist/index.js` around lines 225 - 226,
The inline style used for the back button content (display: 'inline-flex',
alignItems: 'center', gap: 4) should be moved into the component's StyledWrapper
as a CSS class named .back-button-content; update StyledWrapper to include rules
for .back-button-content (display: inline-flex; align-items: center; gap: 4px)
and replace the inline style on the element that currently renders <span
style={{ display: 'inline-flex', alignItems: 'center', gap: 4 }}> (in
AIAssist/index.js) with className="back-button-content" so styling is consistent
with the rest of the component.
packages/bruno-app/src/components/FolderSettings/Tests/index.js (1)

37-54: 💤 Low value

Optional: Consider adding data-testid for E2E testing.

The new wrapper divs could include data-testid attributes (e.g., data-testid="folder-tests-ai-assist-wrapper") to facilitate Playwright E2E testing of the AIAssist feature. This would align with the coding guidelines' emphasis on adding testable identifiers.

🧪 Example enhancement
-      <div className="relative h-full">
+      <div className="relative h-full" data-testid="folder-tests-ai-assist-wrapper">

Apply similar changes to all 4 integration files (collection/folder × script/tests).

🤖 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/FolderSettings/Tests/index.js` around lines
37 - 54, Add a data-testid to the new wrapper div around the CodeEditor and
AIAssist so E2E tests can target the AI assist area; locate the JSX containing
CodeEditor (ref testsEditorRef, props value={tests || ''}, onEdit,
onSave={handleSave}, initialScroll={testsScroll}, onScroll={setTestsScroll}) and
AIAssist (scriptType="tests", currentScript={tests || ''}, onApply={onEdit}) and
add a descriptive attribute such as data-testid="folder-tests-ai-assist-wrapper"
(repeat analogous additions for the other three integration files:
collection/folder × script/tests).
🤖 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/AIAssist/index.js`:
- Around line 134-143: In the AIAssist component add Playwright data-testid
attributes to the interactive elements: add data-testid="ai-assist-trigger" to
the trigger button (the element using buttonRef and className
`ai-assist-trigger`), add data-testid="ai-assist-popup" to the popup container
element that shows when isOpen is true, add data-testid="ai-assist-input" to the
textarea/input used for user prompts, add data-testid="ai-assist-generate" to
the Generate button, add data-testid="ai-assist-back" to the Back button, add
data-testid="ai-assist-apply" to the Apply button, and add
data-testid={`ai-assist-suggestion-${s.label}`} to each suggestion chip where
chips are rendered (reference the variable s.label in the suggestion mapping) so
tests can reliably target these elements.

In `@packages/bruno-electron/src/ipc/ai/index.js`:
- Around line 147-181: The generateText call in the ipcMain handler for
'renderer:ai-generate-script' doesn't set temperature, making outputs
non-deterministic; update the generateText invocation inside the
'renderer:ai-generate-script' handler to pass a temperature value (use the
requested temperature if provided or default to 0.3 like the
'renderer:ai-generate-text' handler) so the call to generateText({ model,
system: SCRIPT_PROMPTS[scriptType], prompt: buildScriptUserPrompt(...),
maxOutputTokens: 2048 }) becomes generateText(..., temperature:
temperatureOrDefault) ensuring consistent code generation while keeping other
parameters (model, system, prompt, maxOutputTokens) unchanged.

In `@packages/bruno-electron/src/ipc/ai/script-prompts.js`:
- Around line 84-108: Update the "tests" prompt block so the anti-side-effect
rule is softened: replace the absolute prohibition text around bru.setEnvVar
with guidance to prefer pure assertions but allow bru.setEnvVar when necessary
to capture response data for follow-up requests; locate the string literal keyed
'tests' in script-prompts.js (the prompt content that currently says "Do NOT use
`bru.setEnvVar` or other side-effecting calls inside tests — keep tests pure
assertions.") and change it to something like "Prefer pure assertions; avoid
side effects unless you need to extract response data for subsequent requests —
use `bru.setEnvVar` only for that purpose." Ensure the rest of the tests
instructions and COMMON_OUTPUT_RULES references remain unchanged.
- Around line 148-177: formatRequestContext currently extracts only the GraphQL
query (body.graphql?.query) and omits GraphQL variables; update
formatRequestContext so that when body.mode === 'graphql' it also includes
body.graphql?.variables (serialized as JSON) alongside the query (truncate
combined text to the existing 2000-char slice logic) so the returned context
contains both the query and variables for AI consumption.

---

Nitpick comments:
In `@packages/bruno-app/src/components/AIAssist/index.js`:
- Around line 48-49: Remove the unnecessary useMemo wrappers around simple
lookups: replace the memoized expressions that compute suggestions and title
(the useMemo calls referencing SUGGESTIONS[scriptType] and TITLES[scriptType])
with direct assignments so suggestions = SUGGESTIONS[scriptType] || [] and title
= TITLES[scriptType] || 'Generate with AI'; remove the import/use of useMemo if
it becomes unused.
- Around line 225-226: The inline style used for the back button content
(display: 'inline-flex', alignItems: 'center', gap: 4) should be moved into the
component's StyledWrapper as a CSS class named .back-button-content; update
StyledWrapper to include rules for .back-button-content (display: inline-flex;
align-items: center; gap: 4px) and replace the inline style on the element that
currently renders <span style={{ display: 'inline-flex', alignItems: 'center',
gap: 4 }}> (in AIAssist/index.js) with className="back-button-content" so
styling is consistent with the rest of the component.

In `@packages/bruno-app/src/components/FolderSettings/Tests/index.js`:
- Around line 37-54: Add a data-testid to the new wrapper div around the
CodeEditor and AIAssist so E2E tests can target the AI assist area; locate the
JSX containing CodeEditor (ref testsEditorRef, props value={tests || ''},
onEdit, onSave={handleSave}, initialScroll={testsScroll},
onScroll={setTestsScroll}) and AIAssist (scriptType="tests",
currentScript={tests || ''}, onApply={onEdit}) and add a descriptive attribute
such as data-testid="folder-tests-ai-assist-wrapper" (repeat analogous additions
for the other three integration files: collection/folder × script/tests).
🪄 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: 83e14acf-e719-451c-8d4b-4c9ee06c47b0

📥 Commits

Reviewing files that changed from the base of the PR and between ed5f5c2 and 638a7c3.

📒 Files selected for processing (11)
  • packages/bruno-app/src/components/AIAssist/StyledWrapper.js
  • packages/bruno-app/src/components/AIAssist/index.js
  • packages/bruno-app/src/components/CollectionSettings/Script/index.js
  • packages/bruno-app/src/components/CollectionSettings/Tests/index.js
  • packages/bruno-app/src/components/FolderSettings/Script/index.js
  • packages/bruno-app/src/components/FolderSettings/Tests/index.js
  • packages/bruno-app/src/components/RequestPane/Script/index.js
  • packages/bruno-app/src/components/RequestPane/Tests/index.js
  • packages/bruno-app/src/utils/ai/index.js
  • packages/bruno-electron/src/ipc/ai/index.js
  • packages/bruno-electron/src/ipc/ai/script-prompts.js

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

LGTM other than the useEffect dependency

@sid-bruno
sid-bruno merged commit 6791e0a into usebruno:main Jun 10, 2026
18 of 19 checks passed
rajashreehj-bruno pushed a commit to rajashreehj-bruno/bruno that referenced this pull request Jun 10, 2026
abhishekp-bruno pushed a commit to abhishekp-bruno/bruno that referenced this pull request Jun 17, 2026
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.

3 participants