Skip to content

feat(ai-assist): add docs generation with folder and collection context - #8246

Merged
naman-bruno merged 1 commit into
usebruno:mainfrom
utkarsh-bruno:feat/BRU-3428-ai-docs
Jun 22, 2026
Merged

naman-bruno merged 1 commit into
usebruno:mainfrom
utkarsh-bruno:feat/BRU-3428-ai-docs

Conversation

@utkarsh-bruno

@utkarsh-bruno utkarsh-bruno commented Jun 12, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Added AI assist for Docs on folder and collection level.

image image image

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.

Summary by CodeRabbit

Release Notes

New Features

  • AI Assist now generates documentation for collections, folders, and requests, providing contextual suggestions based on your API structure and request configurations

Tests

  • Added comprehensive test coverage for AI-assisted documentation generation and supporting utilities

@coderabbitai

coderabbitai Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR extends AI-assisted script generation to support documentation editing across collection, folder, and request contexts. It adds docs-specific UI/prompts to AIAssist, creates context builders to summarize collection structure for the LLM, integrates AIAssist into three documentation editors, and updates backend prompts to handle docs generation with formatted metadata.

Changes

AI-assisted documentation generation

Layer / File(s) Summary
AIAssist component docs support
packages/bruno-app/src/components/AIAssist/index.js
AIAssist now accepts docsContext prop, recognizes scriptType="docs" with docs-specific suggestions and titles, and uses per-type preview labels instead of static text.
AIAssist comprehensive testing
packages/bruno-app/src/components/AIAssist/index.spec.js
Adds 356-line test suite covering conditional rendering, popup interactions, prompt/suggestion behavior, generation flow with docs context, error handling, and preview/apply logic for both script and docs types.
Docs context builders
packages/bruno-app/src/utils/ai/index.js
New utility functions summarize collection and folder structure into formatted AI context: buildDocsContextFromCollection and buildDocsContextFromFolder walk sidebar-ordered items, skip transient entries, and aggregate folder/request metadata.
Docs context builder tests
packages/bruno-app/src/utils/ai/index.spec.js
Tests verify context generation for collections and folders with nested items, null handling for missing inputs, and request context normalization.
Documentation component integration
packages/bruno-app/src/components/CollectionSettings/Docs/index.js, packages/bruno-app/src/components/Documentation/index.js, packages/bruno-app/src/components/FolderSettings/Documentation/index.js
Collection, Folder, and Request documentation editors now compute memoized docs/request context and render AIAssist alongside CodeEditor, wiring generated content through existing onEdit handlers.
Backend prompt and IPC support
packages/bruno-electron/src/ipc/ai/index.js, packages/bruno-electron/src/ipc/ai/script-prompts.js
IPC handler reads docsContext from params and passes it to buildScriptUserPrompt. New SCRIPT_PROMPTS['docs'] instructs model to generate raw Markdown, and formatDocsContext helper formats collection/folder/request metadata with child counts for prompt context.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • usebruno/bruno#8220: Directly builds on the same AIAssist script-editing integration by extending scriptType to "docs" and plumbing docsContext through the entire flow.
  • usebruno/bruno#8213: The new buildDocsContextFromCollection/buildDocsContextFromFolder functions depend on sortItemsBySidebarOrder helpers from that PR.

Suggested labels

size/XXL

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • bijin-bruno
  • sid-bruno
  • naman-bruno

Poem

📚 AI scribes now draft your docs,
From collections through to locks,
Context flows through every tier,
Markdown magic, fresh and clear.
Bruno's brain now helps you write.

🚥 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(ai-assist): add docs generation with folder and collection context' clearly and accurately summarizes the main change: adding AI-assisted documentation generation with contextual information from folders and collections.
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.

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

Caution

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

⚠️ Outside diff range comments (2)
packages/bruno-app/src/components/AIAssist/index.js (2)

169-174: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Make the shortcut hint platform-aware.

The handler accepts both Cmd+Enter and Ctrl+Enter, but the footer always tells users ⌘ + Enter to generate. On Windows/Linux that teaches the wrong shortcut. Render the hint from the current platform so it matches actual behavior.

As per coding guidelines, Bruno must remain OS-agnostic across macOS, Windows, and Linux.

Also applies to: 199-206

🤖 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 169 - 174,
The footer shortcut string is hardcoded to "⌘ + Enter" while the onKeyDown
handler accepts both Cmd and Ctrl; make the hint platform-aware by computing a
shortcutLabel (e.g., isMac ? '⌘ + Enter' : 'Ctrl + Enter') using a runtime
platform check (navigator.platform or navigator.userAgentData.platform fallback)
and render that label wherever the footer currently shows the hardcoded string
(refer to the onKeyDown handler and handleGenerate and the footer text around
the blocks at the shown ranges, also update the other occurrence around lines
199-206). Ensure the computed label is used in both footer locations so the
displayed hint matches the actual keyboard behavior across macOS/Windows/Linux.

Source: Coding guidelines


138-178: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add stable data-testids to the new AI assist controls.

This new modal flow is now part of the docs authoring UI, but the trigger/dialog/input/action controls still rely on titles, placeholders, and visible text for targeting. Please add stable data-testid hooks to the trigger, dialog, textarea, generate button, back button, and apply button so Playwright coverage does not depend on copy changes.

As per coding guidelines, "Add data-testid to testable elements for Playwright in React components."

Also applies to: 208-235

🤖 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 138 - 178,
Add stable data-testid attributes to the AI assist UI elements: add
data-testid="ai-assist-trigger" on the trigger button (the element using
buttonRef and toggling isOpen), data-testid="ai-assist-dialog" on the popup
container (the element using attachPopup and role="dialog"),
data-testid="ai-assist-textarea" on the textarea (the element using focusOnMount
and onChange/setPrompt), and data-testid attributes for the action buttons:
data-testid="ai-assist-generate" on the control that calls handleGenerate,
data-testid="ai-assist-back" on the back control, and
data-testid="ai-assist-apply" on the apply control (and also add the same
attributes in the alternate block around lines 208-235 referenced by the review)
so Playwright selectors don’t depend on visible copy.

Source: Coding guidelines

🧹 Nitpick comments (1)
packages/bruno-app/src/utils/ai/index.spec.js (1)

46-103: ⚡ Quick win

Cover the new ordering and transient-item branches explicitly.

buildDocsContextFromCollection() / buildDocsContextFromFolder() now depend on sortItemsBySidebarOrder() and isTransient filtering, but the new fixtures only exercise already ordered, non-transient data. Add one unsorted case and one transient-child case so the new behavior is pinned down.

As per coding guidelines, "Add tests for any new functionality or meaningful changes."

🤖 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/utils/ai/index.spec.js` around lines 46 - 103, Add
tests that exercise the new ordering and transient-item branches: in the
describe blocks for buildDocsContextFromCollection and
buildDocsContextFromFolder, add one test each that supplies an unsorted
collection/folder (items out of sidebar order) to verify sortItemsBySidebarOrder
is applied, and one test that includes a child item with isTransient: true to
verify transient children are filtered out; reference the existing test
helpers/fixtures used by the file and assert the expected reordered output and
that transient items are omitted when calling
buildDocsContextFromCollection(collection) and
buildDocsContextFromFolder(collection, folder).

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/AIAssist/index.spec.js`:
- Around line 173-179: Update the failing test assertions in AIAssist's spec so
they match the new component contract that always forwards docsContext: for the
aiGenerateScript calls; locate the assertions that call aiGenerateScript (e.g.,
the expect(aiGenerateScript).toHaveBeenCalledWith(...) blocks) and either add
docsContext: undefined to the expected argument objects or change the assertions
to use expect.objectContaining({...}) so docsContext presence is ignored—apply
the same change to the other similar assertions referenced (around the blocks
asserting calls at the later positions).

In `@packages/bruno-electron/src/ipc/ai/index.js`:
- Around line 170-176: The code currently always calls stripCodeFences(text)
before returning generated content, which removes valid fenced Markdown examples
for scriptType === 'docs'; change the return to conditionally skip
stripCodeFences when scriptType is 'docs' (e.g. compute finalContent =
scriptType === 'docs' ? text : stripCodeFences(text')) and return { content:
finalContent, modelId } so generateText, SCRIPT_PROMPTS, buildScriptUserPrompt
and stripCodeFences are left intact but docs-mode preserves legitimate fences.

In `@packages/bruno-electron/src/ipc/ai/script-prompts.js`:
- Around line 252-255: The current code in the sections.push for currentScript
(when scriptType === 'docs') wraps the document in a fixed triple-backtick fence
which will break if currentScript already contains fenced code; change the
wrapper to compute a safe fence delimiter dynamically: inspect currentScript to
find the longest run of backticks and then use a fence of one backtick longer
(e.g., '`'.repeat(maxRun + 1)) when building the fenced block in the
sections.push call; update the logic that sets fenceLang/existingLabel and the
sections.push construction (referencing currentScript, scriptType, fenceLang,
existingLabel) so the outer fence cannot be closed by content inside the
document.

---

Outside diff comments:
In `@packages/bruno-app/src/components/AIAssist/index.js`:
- Around line 169-174: The footer shortcut string is hardcoded to "⌘ + Enter"
while the onKeyDown handler accepts both Cmd and Ctrl; make the hint
platform-aware by computing a shortcutLabel (e.g., isMac ? '⌘ + Enter' : 'Ctrl +
Enter') using a runtime platform check (navigator.platform or
navigator.userAgentData.platform fallback) and render that label wherever the
footer currently shows the hardcoded string (refer to the onKeyDown handler and
handleGenerate and the footer text around the blocks at the shown ranges, also
update the other occurrence around lines 199-206). Ensure the computed label is
used in both footer locations so the displayed hint matches the actual keyboard
behavior across macOS/Windows/Linux.
- Around line 138-178: Add stable data-testid attributes to the AI assist UI
elements: add data-testid="ai-assist-trigger" on the trigger button (the element
using buttonRef and toggling isOpen), data-testid="ai-assist-dialog" on the
popup container (the element using attachPopup and role="dialog"),
data-testid="ai-assist-textarea" on the textarea (the element using focusOnMount
and onChange/setPrompt), and data-testid attributes for the action buttons:
data-testid="ai-assist-generate" on the control that calls handleGenerate,
data-testid="ai-assist-back" on the back control, and
data-testid="ai-assist-apply" on the apply control (and also add the same
attributes in the alternate block around lines 208-235 referenced by the review)
so Playwright selectors don’t depend on visible copy.

---

Nitpick comments:
In `@packages/bruno-app/src/utils/ai/index.spec.js`:
- Around line 46-103: Add tests that exercise the new ordering and
transient-item branches: in the describe blocks for
buildDocsContextFromCollection and buildDocsContextFromFolder, add one test each
that supplies an unsorted collection/folder (items out of sidebar order) to
verify sortItemsBySidebarOrder is applied, and one test that includes a child
item with isTransient: true to verify transient children are filtered out;
reference the existing test helpers/fixtures used by the file and assert the
expected reordered output and that transient items are omitted when calling
buildDocsContextFromCollection(collection) and
buildDocsContextFromFolder(collection, folder).
🪄 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: 818a0a3d-f7fa-4301-8dfc-1994abbe0a0f

📥 Commits

Reviewing files that changed from the base of the PR and between 1d3a412 and dd1bb27.

📒 Files selected for processing (9)
  • packages/bruno-app/src/components/AIAssist/index.js
  • packages/bruno-app/src/components/AIAssist/index.spec.js
  • packages/bruno-app/src/components/CollectionSettings/Docs/index.js
  • packages/bruno-app/src/components/Documentation/index.js
  • packages/bruno-app/src/components/FolderSettings/Documentation/index.js
  • packages/bruno-app/src/utils/ai/index.js
  • packages/bruno-app/src/utils/ai/index.spec.js
  • packages/bruno-electron/src/ipc/ai/index.js
  • packages/bruno-electron/src/ipc/ai/script-prompts.js

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