Repository navigation
feat(ai-assist): add docs generation with folder and collection context - #8246
Conversation
WalkthroughThis 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. ChangesAI-assisted documentation generation
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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: 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 winMake the shortcut hint platform-aware.
The handler accepts both
Cmd+EnterandCtrl+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 winAdd 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-testidhooks 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-testidto 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 winCover the new ordering and transient-item branches explicitly.
buildDocsContextFromCollection()/buildDocsContextFromFolder()now depend onsortItemsBySidebarOrder()andisTransientfiltering, 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
📒 Files selected for processing (9)
packages/bruno-app/src/components/AIAssist/index.jspackages/bruno-app/src/components/AIAssist/index.spec.jspackages/bruno-app/src/components/CollectionSettings/Docs/index.jspackages/bruno-app/src/components/Documentation/index.jspackages/bruno-app/src/components/FolderSettings/Documentation/index.jspackages/bruno-app/src/utils/ai/index.jspackages/bruno-app/src/utils/ai/index.spec.jspackages/bruno-electron/src/ipc/ai/index.jspackages/bruno-electron/src/ipc/ai/script-prompts.js
Description
Added AI assist for Docs on folder and collection level.
Contribution Checklist:
Summary by CodeRabbit
Release Notes
New Features
Tests