Skip to content

feat(app): add request level app - #8294

Merged
sid-bruno merged 4 commits into
usebruno:mainfrom
naman-bruno:feat/bruno-apps
Jun 22, 2026
Merged

sid-bruno merged 4 commits into
usebruno:mainfrom
naman-bruno:feat/bruno-apps

Conversation

@naman-bruno

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

Copy link
Copy Markdown
Collaborator

Description

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
    • Introduced request App mode with an embedded webview that runs custom JavaScript via an exposed ctx API (theme, logging, requests, and runtime variables).
    • Added App tab + status indicator for app-code presence, plus Request/App/File view switching and Exit to editor.
    • Added app code persistence and expanded BRU/YAML import/export and schema support for app metadata.
  • Bug Fixes
    • Updated autosave to treat app-code edits as dirty.
  • Tests
    • Added Playwright/Electron UI and webview integration coverage for ctx, switching, and persistence.

@coderabbitai

coderabbitai Bot commented Jun 17, 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: 6f1c30eb-51c1-412f-8f7f-2b0481703984

📥 Commits

Reviewing files that changed from the base of the PR and between 9f6b844 and ab11954.

📒 Files selected for processing (3)
  • packages/bruno-app/src/components/RequestTabs/CollectionHeader/StyledWrapper.js
  • packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/bruno-app/src/components/RequestTabs/CollectionHeader/StyledWrapper.js
  • packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js

Walkthrough

Adds a per-request "App mode" that embeds user JavaScript inside an Electron <webview>. A sentinel-based host/guest messaging bridge exposes a window.ctx API for theme, response, variables, sendRequest, and setRuntimeVariable. Backing changes extend the .bru/YAML file formats, Redux state, schema types, request pane UI, collection header toolbar, and Playwright integration tests.

Changes

App Mode: Per-Request Webview with ctx API

Layer / File(s) Summary
App data contracts, schema validation, and file format support
packages/bruno-schema-types/src/collection/item.ts, packages/bruno-schema/src/collections/index.js, packages/bruno-filestore/src/formats/yml/common/app.ts, packages/bruno-lang/v2/src/bruToJson.js, packages/bruno-lang/v2/src/jsonToBru.js, packages/bruno-filestore/src/formats/bru/index.ts, packages/bruno-filestore/src/formats/yml/items/parseHttpRequest.ts, packages/bruno-filestore/src/formats/yml/items/stringifyHttpRequest.ts
Introduces the App interface and item.app field in schema-types and yup validation. Adds OpenCollectionApp converters (toBrunoApp, toOpenCollectionApp). Extends the Bru grammar and bruToJson/jsonToBru for app { code } blocks. Wires app through BRU and YAML parse/stringify paths.
Redux slice: app state reducers, persistence, and autosave
packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js, packages/bruno-app/src/utils/collections/index.js, packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js
Adds updateAppCode, toggleAppMode, and appSetRuntimeVariable reducers. Extends saveRequest to copy draft.app into item.app. Wires app data into collectionAddFileEvent and collectionChangeFileEvent preserving runtime-only enabled. Includes app in filesystem serialization and autosave interception.
AppView: webview component and host/guest ctx bridge
packages/bruno-app/src/components/AppView/index.js, packages/bruno-app/src/components/AppView/StyledWrapper.js
Full AppView component: sentinel console-message channel, window.ctx bootstrap injection, HTML generation, timeline/response/variable helpers, memoized derived state, sendRequest execution path (UID, Redux dispatch, sendNetworkRequest), webview lifecycle wiring, host-to-guest state sync effects, and Exit control.
App tab in HttpRequestPane and AppCodeEditor
packages/bruno-app/src/components/RequestPane/AppCodeEditor/index.js, packages/bruno-app/src/components/RequestPane/AppCodeEditor/StyledWrapper.js, packages/bruno-app/src/components/RequestPane/HttpRequestPane/index.js
Introduces AppCodeEditor (toggle + CodeEditor wired to Redux actions). Registers the App tab in TAB_CONFIG/TAB_PANELS and adds an App status-dot indicator to the request pane.
RequestTabPanel app mode gate and CollectionHeader view-mode toggle
packages/bruno-app/src/components/RequestTabPanel/index.js, packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js, packages/bruno-app/src/components/RequestTabs/CollectionHeader/StyledWrapper.js
RequestTabPanel short-circuits to render AppView when app.enabled is set. CollectionHeader adds appEnabled detection, handleToggleAppMode, conditional overflow menu suppression, and a three-button Request/App/File view-mode toggle with coordinated Redux dispatches.
Integration and UI tests
tests/apps/apps-ui.spec.ts, tests/apps/apps-ctx-api.spec.ts, tests/utils/page/actions.ts
Adds setAppCode, enableApp, exitApp, selectViewMode, getAppWebviewHtml test helpers. UI tests cover App mode visibility, status-dot, view-mode toggle, and persistence. ctx API tests cover window.ctx surface, theme, ctx.log, ctx.sendRequest overrides, setRuntimeVariable persistence, and generated HTML inspection.

Sequence Diagram(s)

sequenceDiagram
  rect rgba(100, 149, 237, 0.5)
    Note over AppView,Redux: App Mode Activation
    AppView->>Redux: dispatch(toggleAppMode, enabled=true)
    Redux-->>RequestTabPanel: item.app.enabled = true
    RequestTabPanel->>AppView: render AppView(item, collection, code)
  end
  rect rgba(144, 238, 144, 0.5)
    Note over AppView,Guest: Webview Bootstrap
    AppView->>Webview: set src (data: URL with ctx bootstrap + user code)
    Webview-->>AppView: dom-ready event
    AppView->>Guest: pushMessage(state, theme, response, results, variables)
    Guest-->>AppView: sentinel console-message(ready)
  end
  rect rgba(255, 165, 0, 0.5)
    Note over Guest,sendNetworkRequest: sendRequest Flow
    Guest->>AppView: sentinel console-message(sendRequest, overrides)
    AppView->>Redux: dispatch(requestSentEvent)
    AppView->>sendNetworkRequest: execute(request, mergedVariables)
    sendNetworkRequest-->>AppView: response / error
    AppView->>Redux: dispatch(responseReceived)
    AppView->>Guest: pushMessage(responseUpdate)
  end
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related PRs

  • usebruno/bruno#6363: Refactors the request pane tab system (TAB_CONFIG/TAB_PANELS) that the main PR extends to add the new "App" tab.
  • usebruno/bruno#7566: Both PRs modify RequestTabPanel/index.js; the retrieved PR adds collapse/expand indicators while the main PR adds app-mode early-return rendering.
  • usebruno/bruno#8258: Modifies the same RequestTabPanel conditional rendering flow and file-mode wiring that the main PR's app-mode integration extends.

Suggested reviewers

  • lohit-bruno
  • bijin-bruno
  • vijayh-bruno

Poem

🪟 A webview awakens, a ctx in hand,
The guest reads its theme and does what is planned.
A sentinel whispers through console's disguise,
The host hears the request and promptly replies.
Redux keeps the state, the grammar learns app,
Three buttons now govern Request, File, and App. 🎛️

🚥 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 clearly and concisely describes the main feature addition: request-level app support. It directly reflects the primary change across all modified files.
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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.44.0)
packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js

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: 6

Caution

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

⚠️ Outside diff range comments (1)
packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js (1)

2747-2764: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Sync app when reusing an existing item in add-file rename flow.

Line 2747-2764 updates currentItem from file.data but skips currentItem.app, while the new-item path at Line 2774 sets it. In add-before-unlink rename ordering, this leaves stale app state in memory.

Suggested minimal fix
           if (currentItem) {
             currentItem.name = file.data.name;
             currentItem.type = file.data.type;
             currentItem.seq = file.data.seq;
             currentItem.tags = file.data.tags;
             currentItem.request = mergeRequestWithPreservedUids(currentItem.request, file.data.request);
+            const currentEnabled = currentItem.draft?.app?.enabled ?? currentItem.app?.enabled ?? false;
+            if (file.data.app) {
+              currentItem.app = { ...file.data.app, enabled: currentEnabled };
+            } else if (currentEnabled) {
+              currentItem.app = { code: null, enabled: true };
+            } else {
+              currentItem.app = null;
+            }
             currentItem.filename = file.meta.name;
             currentItem.pathname = file.meta.pathname;
             currentItem.raw = file.data.raw;
             currentItem.settings = file.data.settings;
             currentItem.examples = file.data.examples;

Also applies to: 2774-2774

🤖 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/providers/ReduxStore/slices/collections/index.js`
around lines 2747 - 2764, The currentItem update block starting at line 2747 is
missing the assignment of the app property from file.data.app, while the
new-item path at line 2774 correctly includes it. This causes stale app state to
remain in memory. Add the assignment currentItem.app = file.data.app to the
currentItem update block alongside the other property assignments like
currentItem.name, currentItem.type, and currentItem.request to ensure the app
property is properly synced when reusing an existing item.
🧹 Nitpick comments (3)
tests/apps/apps-ctx-api.spec.ts (1)

179-183: ⚡ Quick win

Replace the fixed 700ms sleep with a state-driven wait.

Line 181 uses a magic timeout for Redux/AppView propagation; this is brittle in CI. Poll the guest-visible state (ctx.variables.q) before sending.

Suggested change
-    // allow the redux update + AppView re-render to settle before the send reads runtimeVariables
-    await page.waitForTimeout(700);
+    // Wait for runtime variable propagation into guest ctx before sending.
+    await expect.poll(
+      () => guestEval(electronApp, "window.ctx?.variables?.q"),
+      { timeout: 15000 }
+    ).toBe('viaSet');
     await guestEval(electronApp, 'void window.__send()');
     await expect.poll(() => guestResult(electronApp), { timeout: 15000 }).toBe('viaSet');
🤖 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 `@tests/apps/apps-ctx-api.spec.ts` around lines 179 - 183, Replace the
hardcoded 700ms timeout using `page.waitForTimeout(700)` with a state-driven
polling approach that checks the guest-visible state before sending. Use the
`expect.poll()` pattern (already used for the final assertion) to poll
`ctx.variables.q` and wait until it equals 'viaSet' before calling
`window.__send()`, which ensures the Redux/AppView updates have propagated in a
reliable way rather than relying on a fixed delay that may be too short or too
long in different CI environments.

Source: Coding guidelines

packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js (1)

617-653: ⚡ Quick win

Expose view-mode buttons as an accessible toggle group.

The new icon-only buttons should include aria-label and aria-pressed so active mode is announced reliably.

Proposed fix
                   <button
                     type="button"
+                    aria-label="Request view"
+                    aria-pressed={!appEnabled && !collection.fileMode}
                     data-testid="view-mode-request"
@@
                   <button
                     type="button"
+                    aria-label="App view"
+                    aria-pressed={appEnabled && !collection.fileMode}
                     data-testid="view-mode-app"
@@
                   <button
                     type="button"
+                    aria-label="File view"
+                    aria-pressed={collection.fileMode}
                     data-testid="view-mode-file"
🤖 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/RequestTabs/CollectionHeader/index.js`
around lines 617 - 653, Add accessibility attributes to the three view-mode
toggle buttons (view-mode-request, view-mode-app, and view-mode-file). For each
button, add an aria-label attribute with a descriptive name for the mode
(Request, App, and File respectively) and add an aria-pressed attribute that
reflects the button's active state. For the Request button, aria-pressed should
match the condition when it is active (when appEnabled is false and
collection.fileMode is false), for the App button it should match when
appEnabled is true and collection.fileMode is false, and for the File button it
should match when collection.fileMode is true.
packages/bruno-filestore/src/formats/yml/items/stringifyHttpRequest.ts (1)

11-11: Consider using a type-only import for OpenCollectionApp.

OpenCollectionApp is used only as a type annotation (line 217) and is not referenced at runtime. Using import type clarifies intent and is a best practice.

Suggested change
-import { toOpenCollectionApp, OpenCollectionApp } from '../common/app';
+import { toOpenCollectionApp } from '../common/app';
+import type { OpenCollectionApp } from '../common/app';
🤖 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-filestore/src/formats/yml/items/stringifyHttpRequest.ts` at
line 11, The import statement for OpenCollectionApp mixes runtime imports with
type-only imports. Since OpenCollectionApp is used only as a type annotation and
not at runtime, refactor the import statement to use import type syntax for
OpenCollectionApp while keeping the toOpenCollectionApp function as a regular
import from '../common/app'. This clarifies that OpenCollectionApp is purely a
type import and improves code clarity.
🤖 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/AppView/index.js`:
- Around line 258-279: The `sendNetworkRequest` function can resolve with an
error object rather than throwing an exception, but the current code does not
check for this error condition before dispatching the success state. After the
`const result = await sendNetworkRequest(...)` line, add a check to determine if
the result object contains an error payload. If an error is detected in the
result, dispatch an appropriate error action or handle it in the catch block
path instead of proceeding with the `responseReceived` dispatch. This ensures
that error responses from `sendNetworkRequest` are properly handled according to
the host/guest error contract rather than being treated as successful responses.

In `@packages/bruno-app/src/components/AppView/StyledWrapper.js`:
- Around line 34-42: Replace the hardcoded background color `#ffffff` in the
`.app-webview-container` styled component with a theme token by using the theme
prop. Access the appropriate background color from the theme object (similar to
how `props.theme.border.border1` is being used for the border property) to
ensure the webview container respects dark and custom theme settings and
complies with the styled-components color guidelines.

In `@packages/bruno-app/src/components/RequestPane/HttpRequestPane/index.js`:
- Line 113: The StatusDot component rendered in the conditional expression for
the app status indicator on line 113 is missing a test identifier. Add a stable
dataTestId prop to the StatusDot component with the value 'app' to match the
existing pattern used throughout the codebase, ensuring Playwright selectors
remain robust and consistent with the coding guidelines for testable React
elements.

In `@packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js`:
- Around line 26-27: The activeItem lookup for the view-mode toggle is missing a
pathname-based fallback mechanism, causing it to miss valid request tabs and
making the toggle disappear. Modify the code that resolves activeItem (likely
using the findItemInCollection function or the lodash find function) to include
a fallback that matches items by pathname when the primary lookup fails. Apply
this fix at all locations where activeItem is resolved for the view-mode toggle
functionality, including the locations referenced in lines 62-64.

In `@packages/bruno-lang/v2/src/jsonToBru.js`:
- Around line 760-763: The app code indentation in the jsonToBru function is
using only 2 spaces via indentString(app.code, 2), but the BRU parser's
multiline handler strips 4 characters per line during parsing, causing the code
to be truncated on reload. Change the indentString call to use 4 spaces instead
of 2 spaces so that when the parser strips 4 characters, the original code
indentation is preserved correctly during round-trip serialization and
deserialization.

In `@tests/apps/apps-ctx-api.spec.ts`:
- Around line 18-29: The guestEval function uses a generic find() condition on
getAllWebContents() that will match the first webview encountered, but fails to
discriminate when multiple webviews coexist (such as AppView and HTML Preview).
Add a discriminator to the find condition to filter webviews by a stable
identifier such as URL pattern or a specific context selector, ensuring the
function consistently selects the correct guest webview for evaluation rather
than whichever webview happens to be found first.

---

Outside diff comments:
In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js`:
- Around line 2747-2764: The currentItem update block starting at line 2747 is
missing the assignment of the app property from file.data.app, while the
new-item path at line 2774 correctly includes it. This causes stale app state to
remain in memory. Add the assignment currentItem.app = file.data.app to the
currentItem update block alongside the other property assignments like
currentItem.name, currentItem.type, and currentItem.request to ensure the app
property is properly synced when reusing an existing item.

---

Nitpick comments:
In `@packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js`:
- Around line 617-653: Add accessibility attributes to the three view-mode
toggle buttons (view-mode-request, view-mode-app, and view-mode-file). For each
button, add an aria-label attribute with a descriptive name for the mode
(Request, App, and File respectively) and add an aria-pressed attribute that
reflects the button's active state. For the Request button, aria-pressed should
match the condition when it is active (when appEnabled is false and
collection.fileMode is false), for the App button it should match when
appEnabled is true and collection.fileMode is false, and for the File button it
should match when collection.fileMode is true.

In `@packages/bruno-filestore/src/formats/yml/items/stringifyHttpRequest.ts`:
- Line 11: The import statement for OpenCollectionApp mixes runtime imports with
type-only imports. Since OpenCollectionApp is used only as a type annotation and
not at runtime, refactor the import statement to use import type syntax for
OpenCollectionApp while keeping the toOpenCollectionApp function as a regular
import from '../common/app'. This clarifies that OpenCollectionApp is purely a
type import and improves code clarity.

In `@tests/apps/apps-ctx-api.spec.ts`:
- Around line 179-183: Replace the hardcoded 700ms timeout using
`page.waitForTimeout(700)` with a state-driven polling approach that checks the
guest-visible state before sending. Use the `expect.poll()` pattern (already
used for the final assertion) to poll `ctx.variables.q` and wait until it equals
'viaSet' before calling `window.__send()`, which ensures the Redux/AppView
updates have propagated in a reliable way rather than relying on a fixed delay
that may be too short or too long in different CI environments.
🪄 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: 0fe7a1fe-4a94-4658-a8b8-3895ac5cb623

📥 Commits

Reviewing files that changed from the base of the PR and between fab18d9 and aa0d6e8.

📒 Files selected for processing (22)
  • packages/bruno-app/src/components/AppView/StyledWrapper.js
  • packages/bruno-app/src/components/AppView/index.js
  • packages/bruno-app/src/components/RequestPane/AppCodeEditor/StyledWrapper.js
  • packages/bruno-app/src/components/RequestPane/AppCodeEditor/index.js
  • packages/bruno-app/src/components/RequestPane/HttpRequestPane/index.js
  • packages/bruno-app/src/components/RequestTabPanel/index.js
  • packages/bruno-app/src/components/RequestTabs/CollectionHeader/StyledWrapper.js
  • packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js
  • packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js
  • packages/bruno-app/src/utils/collections/index.js
  • packages/bruno-filestore/src/formats/bru/index.ts
  • packages/bruno-filestore/src/formats/yml/common/app.ts
  • packages/bruno-filestore/src/formats/yml/items/parseHttpRequest.ts
  • packages/bruno-filestore/src/formats/yml/items/stringifyHttpRequest.ts
  • packages/bruno-lang/v2/src/bruToJson.js
  • packages/bruno-lang/v2/src/jsonToBru.js
  • packages/bruno-schema-types/src/collection/item.ts
  • packages/bruno-schema/src/collections/index.js
  • tests/apps/apps-ctx-api.spec.ts
  • tests/apps/apps-ui.spec.ts
  • tests/utils/page/actions.ts

Comment thread packages/bruno-lang/v2/src/jsonToBru.js Resolved
Comment thread tests/apps/apps-ctx-api.spec.ts Resolved
utkarsh-bruno
utkarsh-bruno previously approved these changes Jun 18, 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.

If this isn't going to cause a problem : https://github.com/usebruno/bruno/pull/8294/changes#r3430801787 , then it's fine. We could probably implement a stricter CSP but it might also restrict the user a lot. Rest looks good.

# Conflicts:
#	packages/bruno-app/src/components/RequestTabs/CollectionHeader/index.js
#	tests/utils/page/actions.ts
sid-bruno
sid-bruno previously approved these changes Jun 22, 2026
@sid-bruno
sid-bruno merged commit d2de2d5 into usebruno:main Jun 22, 2026
19 of 20 checks passed
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