Skip to content

The agent that grows with you

feat(desktop): gate preview scripts behind a declared capability and per-origin consent

Teknium4ff28461102f
diff --git a/apps/desktop/src/app/capabilities/plugins/plugin-page-access.test.tsx b/apps/desktop/src/app/capabilities/plugins/plugin-page-access.test.tsx
new file mode 100644
index 00000000000..585dc69c187
--- /dev/null
+++ b/apps/desktop/src/app/capabilities/plugins/plugin-page-access.test.tsx
@@ -0,0 +1,47 @@
+// @vitest-environment jsdom
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { afterEach, beforeEach, describe, expect, it } from 'vitest'
+
+import { $previewScriptGrants, ensurePreviewScriptConsent, grantPreviewScript } from '@/store/plugin-preview-grants'
+
+import { PluginPageAccess } from './plugin-page-access'
+
+beforeEach(() => $previewScriptGrants.set({}))
+afterEach(cleanup)
+
+describe('PluginPageAccess', () => {
+ it('stays hidden for a plugin that did not declare preview scripts', () => {
+ grantPreviewScript('quiet', 'https://mail.example.com')
+ const { container } = render(<PluginPageAccess plugin={{ capabilities: [], id: 'quiet' }} pluginName="Quiet" />)
+
+ expect(container.textContent).toBe('')
+ })
+
+ it('lists granted origins and revoking one makes the next call ask again', async () => {
+ grantPreviewScript('page-reader', 'https://mail.example.com')
+ grantPreviewScript('page-reader', 'https://docs.example.com')
+ render(
+ <PluginPageAccess
+ plugin={{ capabilities: ['preview.executeJavaScript'], id: 'page-reader' }}
+ pluginName="Page Reader"
+ />
+ )
+
+ expect(screen.getByText('https://mail.example.com')).toBeTruthy()
+ fireEvent.click(screen.getByRole('button', { name: 'Revoke access to https://mail.example.com' }))
+
+ expect($previewScriptGrants.get()['page-reader']).toEqual(['https://docs.example.com'])
+ expect(screen.queryByText('https://mail.example.com')).toBeNull()
+
+ let settled = false
+ void ensurePreviewScriptConsent('page-reader', 'Page Reader', 'https://mail.example.com').then(() => (settled = true))
+ await Promise.resolve()
+ expect(settled).toBe(false)
+ })
+
+ it('says it will ask when the plugin declared the door but holds no grant', () => {
+ render(<PluginPageAccess plugin={{ capabilities: ['preview.executeJavaScript'], id: 'fresh' }} pluginName="Fresh" />)
+
+ expect(screen.getByText('Asks before running scripts on a page')).toBeTruthy()
+ })
+})
diff --git a/apps/desktop/src/app/capabilities/plugins/plugin-page-access.tsx b/apps/desktop/src/app/capabilities/plugins/plugin-page-access.tsx
new file mode 100644
index 00000000000..267222a827f
--- /dev/null
+++ b/apps/desktop/src/app/capabilities/plugins/plugin-page-access.tsx
@@ -0,0 +1,65 @@
+import { useStore } from '@nanostores/react'
+
+import { Codicon } from '@/components/ui/codicon'
+import { PREVIEW_SCRIPT_CAPABILITY } from '@/contrib/plugin-preview'
+import type { PluginRecord } from '@/contrib/plugins-store'
+import { useI18n } from '@/i18n'
+import { notify } from '@/store/notifications'
+import { $previewScriptGrants, revokePreviewScript } from '@/store/plugin-preview-grants'
+
+import { Pill } from '../../settings/primitives'
+
+interface PluginPageAccessProps {
+ /** The Desktop half of the package; absent for agent-only packages. */
+ plugin?: Pick<PluginRecord, 'capabilities' | 'id'>
+ pluginName: string
+}
+
+/**
+ * The revocation side of `ctx.preview.executeJavaScript` consent, shown on a
+ * Desktop plugin's row: every page origin the user allowed it to script, each
+ * with its own revoke. A revoked origin asks again on the plugin's next call.
+ * Rendered only for plugins that declared the capability.
+ */
+export function PluginPageAccess({ plugin, pluginName }: PluginPageAccessProps) {
+ const { t } = useI18n()
+ const copy = t.skills.plugins
+ const grants = useStore($previewScriptGrants)
+
+ if (!plugin?.capabilities?.includes(PREVIEW_SCRIPT_CAPABILITY)) {
+ return null
+ }
+
+ const pluginId = plugin.id
+ const origins = grants[pluginId] ?? []
+
+ return (
+ <div
+ className="mt-1 flex flex-wrap items-center gap-1.5 text-[length:var(--conversation-caption-font-size)] text-(--ui-text-tertiary)"
+ data-testid={`plugin-page-access-${pluginId}`}
+ >
+ <span className="font-medium text-(--ui-text-secondary)">{copy.previewScriptAccessLabel}</span>
+ {origins.length === 0 ? (
+ <span>{copy.previewScriptAccessNone}</span>
+ ) : (
+ origins.map(origin => (
+ <Pill className="gap-1 pr-0.5" key={origin}>
+ <span>{origin}</span>
+ <button
+ aria-label={copy.previewScriptRevoke(origin)}
+ className="inline-flex size-4 items-center justify-center rounded-sm hover:bg-(--ui-control-hover-background) hover:text-foreground"
+ onClick={() => {
+ revokePreviewScript(pluginId, origin)
+ notify({ kind: 'info', message: copy.previewScriptRevoked(pluginName, origin) })
+ }}
+ title={copy.previewScriptRevoke(origin)}
+ type="button"
+ >
+ <Codicon name="close" size="0.7rem" />
+ </button>
+ </Pill>
+ ))
+ )}
+ </div>
+ )
+}
diff --git a/apps/desktop/src/app/capabilities/plugins/plugins-tab.tsx b/apps/desktop/src/app/capabilities/plugins/plugins-tab.tsx
index 3d3d92bb937..6c68ffde46a 100644
--- a/apps/desktop/src/app/capabilities/plugins/plugins-tab.tsx
+++ b/apps/desktop/src/app/capabilities/plugins/plugins-tab.tsx
@@ -46,6 +46,7 @@ import { CatalogSwitch } from '../catalog/catalog-switch'
import { TOOLSETS_QUERY_KEY } from '../toolsets/toolsets-data'
import { mergePluginPackages, type PackageKind, type PluginPackage } from './plugin-packages'
+import { PluginPageAccess } from './plugin-page-access'
import { runPluginUpdate } from './plugin-update'
/** Deep-link anchor for a package row (`/capabilities?tab=plugins&plugin=<key>`).
@@ -400,6 +401,7 @@ function PackageRow({
{desktop?.status === 'error' ? desktop.error : pkg.description}
</div>
)}
+ <PluginPageAccess plugin={desktop} pluginName={pkg.name} />
{unavailableServers.map(server =>
server.sentence ? (
<div
diff --git a/apps/desktop/src/app/contrib/controller.tsx b/apps/desktop/src/app/contrib/controller.tsx
index f2e5260490d..427c81f97c9 100644
--- a/apps/desktop/src/app/contrib/controller.tsx
+++ b/apps/desktop/src/app/contrib/controller.tsx
@@ -121,6 +121,7 @@ import { TermsButterbar } from '../shell/terms-butterbar'
import { BASIC_TREE, DEFAULT_TREE, registerLayoutPresets } from './layout-presets'
import { bindLayoutSides } from './layout-sides'
import { FilesPane, LogsPane, ReviewPaneContent } from './panes'
+import { PluginPreviewConsentDialog } from './plugin-preview-consent-dialog'
import { ContribWiring, WiredPane } from './wiring'
import { WorkspacePageHeaderHostContext } from './workspace-page-header'
@@ -790,6 +791,7 @@ export function ContribController() {
<ContribWiring>
<AppContextMenu />
<HudShell />
+ <PluginPreviewConsentDialog />
</ContribWiring>
)
}
@@ -798,6 +800,7 @@ export function ContribController() {
return (
<ContribWiring>
<BrowserPopoutShell />
+ <PluginPreviewConsentDialog />
</ContribWiring>
)
}
@@ -811,6 +814,9 @@ export function ContribController() {
>
<ContribWiring>
<AppContextMenu />
+ {/* App-owned answer to a plugin's ctx.preview.executeJavaScript. Plugins
+ run in every window kind, so each shell mounts it. */}
+ <PluginPreviewConsentDialog />
<div
className="flex h-screen min-h-0 w-screen flex-col bg-(--ui-bg-chrome) text-(--ui-text-primary)"
// Window-glass hook: this div and the sidebar-wrapper above it are
diff --git a/apps/desktop/src/app/contrib/plugin-preview-consent-dialog.test.tsx b/apps/desktop/src/app/contrib/plugin-preview-consent-dialog.test.tsx
new file mode 100644
index 00000000000..1a9bdf995e5
--- /dev/null
+++ b/apps/desktop/src/app/contrib/plugin-preview-consent-dialog.test.tsx
@@ -0,0 +1,59 @@
+// @vitest-environment jsdom
+import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { afterEach, beforeEach, describe, expect, it } from 'vitest'
+
+import {
+ $previewScriptConsentQueue,
+ $previewScriptGrants,
+ ensurePreviewScriptConsent
+} from '@/store/plugin-preview-grants'
+
+import { PluginPreviewConsentDialog } from './plugin-preview-consent-dialog'
+
+beforeEach(() => {
+ $previewScriptGrants.set({})
+ $previewScriptConsentQueue.set([])
+})
+
+afterEach(cleanup)
+
+describe('PluginPreviewConsentDialog', () => {
+ it('renders nothing while no plugin is asking', () => {
+ render(<PluginPreviewConsentDialog />)
+
+ expect(screen.queryByRole('dialog')).toBeNull()
+ })
+
+ it('names the plugin and the page origin, and Allow persists the grant', async () => {
+ render(<PluginPreviewConsentDialog />)
+
+ let answer!: Promise<boolean>
+ act(() => {
+ answer = ensurePreviewScriptConsent('page-reader', 'Page Reader', 'https://mail.example.com')
+ })
+
+ const dialog = await screen.findByRole('dialog')
+ expect(dialog.textContent).toContain('Page Reader')
+ expect(dialog.textContent).toContain('https://mail.example.com')
+
+ fireEvent.click(screen.getByRole('button', { name: 'Allow on this site' }))
+
+ await expect(answer).resolves.toBe(true)
+ expect($previewScriptGrants.get()['page-reader']).toEqual(['https://mail.example.com'])
+ expect(screen.queryByRole('dialog')).toBeNull()
+ })
+
+ it('treats Escape as a refusal, never as consent', async () => {
+ render(<PluginPreviewConsentDialog />)
+
+ let answer!: Promise<boolean>
+ act(() => {
+ answer = ensurePreviewScriptConsent('page-reader-esc', 'Page Reader', 'https://mail.example.com')
+ })
+
+ fireEvent.keyDown(await screen.findByRole('dialog'), { key: 'Escape' })
+
+ await expect(answer).resolves.toBe(false)
+ expect($previewScriptGrants.get()).toEqual({})
+ })
+})
diff --git a/apps/desktop/src/app/contrib/plugin-preview-consent-dialog.tsx b/apps/desktop/src/app/contrib/plugin-preview-consent-dialog.tsx
new file mode 100644
index 00000000000..71e9c419ef2
--- /dev/null
+++ b/apps/desktop/src/app/contrib/plugin-preview-consent-dialog.tsx
@@ -0,0 +1,66 @@
+import { useStore } from '@nanostores/react'
+
+import { Button } from '@/components/ui/button'
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle
+} from '@/components/ui/dialog'
+import { useI18n } from '@/i18n'
+import { ShieldLock } from '@/lib/icons'
+import { $previewScriptConsentQueue, answerPreviewScriptConsent } from '@/store/plugin-preview-grants'
+
+/**
+ * The app-owned consent prompt for `ctx.preview.executeJavaScript`. A plugin
+ * never renders or answers it: the first call a plugin makes on a page origin
+ * queues a request, this dialog shows the oldest one (plugin name + origin),
+ * and only an explicit "Allow on this site" grants. Every other close path —
+ * "Don't allow", Esc, the backdrop — funnels through `onOpenChange(false)` as
+ * a refusal, so silence is never consent.
+ */
+export function PluginPreviewConsentDialog() {
+ const { t } = useI18n()
+ const copy = t.skills.plugins
+ const request = useStore($previewScriptConsentQueue)[0]
+
+ if (!request) {
+ return null
+ }
+
+ return (
+ <Dialog
+ key={request.id}
+ onOpenChange={open => {
+ if (!open) {
+ answerPreviewScriptConsent(request.id, false)
+ }
+ }}
+ open
+ >
+ <DialogContent className="max-w-md" data-testid="plugin-preview-consent" showCloseButton={false}>
+ <DialogHeader>
+ <DialogTitle icon={ShieldLock}>{copy.previewScriptPromptTitle(request.pluginName)}</DialogTitle>
+ <DialogDescription>{copy.previewScriptPromptBody(request.pluginName, request.origin)}</DialogDescription>
+ </DialogHeader>
+
+ <div className="grid gap-2 text-[length:var(--conversation-caption-font-size)]">
+ <code className="w-fit rounded bg-(--ui-bg-tertiary) px-1.5 py-0.5 text-foreground">{request.origin}</code>
+ <p className="text-(--ui-text-secondary)">{copy.previewScriptPromptRisk}</p>
+ <p className="text-(--ui-text-tertiary)">{copy.previewScriptPromptRevokeHint}</p>
+ </div>
+
+ <DialogFooter>
+ <Button onClick={() => answerPreviewScriptConsent(request.id, false)} type="button" variant="ghost">
+ {copy.previewScriptDeny}
+ </Button>
+ <Button onClick={() => answerPreviewScriptConsent(request.id, true)} type="button">
+ {copy.previewScriptAllow}
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ )
+}
diff --git a/apps/desktop/src/contrib/plugin-preview.test.ts b/apps/desktop/src/contrib/plugin-preview.test.ts
new file mode 100644
index 00000000000..87583ff9138
--- /dev/null
+++ b/apps/desktop/src/contrib/plugin-preview.test.ts
@@ -0,0 +1,175 @@
+import { afterEach, beforeEach, describe, expect, it } from 'vitest'
+
+import { registerPreviewScriptRunner } from '@/app/chat/right-rail/preview-script-runner'
+import { $rightRailActiveTabId } from '@/store/layout'
+import {
+ $previewScriptConsentQueue,
+ $previewScriptGrants,
+ answerPreviewScriptConsent,
+ grantPreviewScript,
+ revokePreviewScript
+} from '@/store/plugin-preview-grants'
+import { closeRightRail, openPreview } from '@/store/preview'
+
+import { createPluginContext } from './plugin'
+import { dropPlugin, publishPlugin } from './plugins-store'
+
+const CAPABILITY = 'preview.executeJavaScript'
+
+// A stand-in guest page: evaluates the injected source the way the webview
+// does (script completion value) against a page whose origin the test moves.
+let pageOrigin = 'https://mail.example.com'
+let afterProbe: (() => void) | null = null
+let ran: string[] = []
+
+async function fakeGuest(code: string): Promise<unknown> {
+ ran.push(code)
+ const page = { document: { title: 'Inbox (3)' }, window: { location: { origin: pageOrigin } } }
+ const result = new Function('window', 'document', `return eval(${JSON.stringify(code)})`)(page.window, page.document)
+
+ if (code === 'window.location.origin' && afterProbe) {
+ afterProbe()
+ afterProbe = null
+ }
+
+ return result
+}
+
+let unbindRunner: (() => void) | undefined
+let pluginSeq = 0
+
+function pluginWith(capabilities: string[]) {
+ const id = `page-reader-${++pluginSeq}`
+
+ publishPlugin({ capabilities, id, kind: 'disk', name: 'Page Reader', status: 'loaded' })
+
+ return { ctx: createPluginContext(id, undefined, capabilities), id }
+}
+
+function openPage() {
+ openPreview({ kind: 'url', label: 'Browser', source: pageOrigin, url: `${pageOrigin}/inbox` })
+ unbindRunner = registerPreviewScriptRunner($rightRailActiveTabId.get()!, fakeGuest)
+}
+
+const userCodeRuns = () => ran.filter(code => code.includes('document.title')).length
+
+beforeEach(() => {
+ closeRightRail()
+ window.localStorage.clear()
+ pageOrigin = 'https://mail.example.com'
+ afterProbe = null
+ ran = []
+ $previewScriptGrants.set({})
+ $previewScriptConsentQueue.set([])
+})
+
+afterEach(() => {
+ unbindRunner?.()
+ unbindRunner = undefined
+
+ for (let n = 1; n <= pluginSeq; n++) {
+ dropPlugin(`page-reader-${n}`)
+ }
+})
+
+describe('ctx.preview.executeJavaScript', () => {
+ it('refuses a plugin that did not declare the capability, without asking or running', async () => {
+ openPage()
+ const { ctx } = pluginWith([])
+
+ expect(ctx.preview.isAvailable()).toBe(false)
+ await expect(ctx.preview.executeJavaScript('document.title')).rejects.toThrow(/did not declare/)
+ expect($previewScriptConsentQueue.get()).toEqual([])
+ expect(ran).toEqual([])
+ })
+
+ it('asks once naming the plugin and origin; Allow runs the script and persists the grant', async () => {
+ openPage()
+ const { ctx, id } = pluginWith([CAPABILITY])
+
+ expect(ctx.preview.isAvailable()).toBe(true)
+ const first = ctx.preview.executeJavaScript('document.title')
+
+ await expect.poll(() => $previewScriptConsentQueue.get().length).toBe(1)
+ const [request] = $previewScriptConsentQueue.get()
+ expect(request).toMatchObject({ origin: 'https://mail.example.com', pluginId: id, pluginName: 'Page Reader' })
+ expect(userCodeRuns()).toBe(0)
+
+ answerPreviewScriptConsent(request.id, true)
+ await expect(first).resolves.toBe('Inbox (3)')
+ expect($previewScriptGrants.get()[id]).toEqual(['https://mail.example.com'])
+
+ await expect(ctx.preview.executeJavaScript('document.title')).resolves.toBe('Inbox (3)')
+ expect($previewScriptConsentQueue.get()).toEqual([])
+ })
+
+ it("Don't allow refuses without running the script and does not re-ask this run", async () => {
+ openPage()
+ const { ctx } = pluginWith([CAPABILITY])
+ const first = ctx.preview.executeJavaScript('document.title')
+
+ await expect.poll(() => $previewScriptConsentQueue.get().length).toBe(1)
+ answerPreviewScriptConsent($previewScriptConsentQueue.get()[0].id, false)
+
+ await expect(first).rejects.toThrow(/not allowed/)
+ await expect(ctx.preview.executeJavaScript('document.title')).rejects.toThrow(/not allowed/)
+ expect($previewScriptConsentQueue.get()).toEqual([])
+ expect(userCodeRuns()).toBe(0)
+ })
+
+ it('asks again after the grant is revoked', async () => {
+ openPage()
+ const { ctx, id } = pluginWith([CAPABILITY])
+
+ grantPreviewScript(id, 'https://mail.example.com')
+ await expect(ctx.preview.executeJavaScript('document.title')).resolves.toBe('Inbox (3)')
+
+ revokePreviewScript(id, 'https://mail.example.com')
+ void ctx.preview.executeJavaScript('document.title').catch(() => {})
+
+ await expect.poll(() => $previewScriptConsentQueue.get().length).toBe(1)
+ expect(userCodeRuns()).toBe(1)
+ })
+
+ it('scopes a grant to its origin', async () => {
+ pageOrigin = 'https://bank.example.com'
+ openPage()
+ const { ctx, id } = pluginWith([CAPABILITY])
+
+ grantPreviewScript(id, 'https://mail.example.com')
+ void ctx.preview.executeJavaScript('document.title').catch(() => {})
+
+ await expect.poll(() => $previewScriptConsentQueue.get().length).toBe(1)
+ expect($previewScriptConsentQueue.get()[0].origin).toBe('https://bank.example.com')
+ expect(userCodeRuns()).toBe(0)
+ })
+
+ it('refuses when the page navigated to another origin between the check and the run', async () => {
+ openPage()
+ const { ctx, id } = pluginWith([CAPABILITY])
+
+ grantPreviewScript(id, 'https://mail.example.com')
+
+ afterProbe = () => {
+ pageOrigin = 'https://bank.example.com'
+ }
+
+ await expect(ctx.preview.executeJavaScript('document.title')).rejects.toThrow(/changed origin/)
+ })
+
+ it('refuses opaque and non-web origins without asking', async () => {
+ pageOrigin = 'null'
+ openPage()
+ const { ctx } = pluginWith([CAPABILITY])
+
+ await expect(ctx.preview.executeJavaScript('document.title')).rejects.toThrow(/web page/)
+ expect($previewScriptConsentQueue.get()).toEqual([])
+ })
+
+ it('rejects when no preview page is open', async () => {
+ const { ctx } = pluginWith([CAPABILITY])
+
+ expect(ctx.preview.isAvailable()).toBe(false)
+ await expect(ctx.preview.executeJavaScript('document.title')).rejects.toThrow('No preview page is open.')
+ })
+})
diff --git a/apps/desktop/src/contrib/plugin-preview.ts b/apps/desktop/src/contrib/plugin-preview.ts
new file mode 100644
index 00000000000..80446112053
--- /dev/null
+++ b/apps/desktop/src/contrib/plugin-preview.ts
@@ -0,0 +1,90 @@
+/**
+ * `ctx.preview` — a plugin's door into the preview Browser's guest page.
+ *
+ * The guest is reached through the same script runner drive_preview and the
+ * preview tour use (`activePreviewScriptRunner`), never a scraped
+ * `<webview>`. Because that page can be one the user is signed in to, the
+ * door is closed by default and the APP arbitrates every call:
+ *
+ * 1. the plugin must declare `capabilities: ['preview.executeJavaScript']`
+ * on its default export (undeclared → refused, nothing asked or run);
+ * 2. the page must be a real web origin (`http(s)://host[:port]`);
+ * 3. the user must have allowed THIS plugin on THIS origin — the first call
+ * raises the app-owned consent dialog (plugin name + origin), "Allow"
+ * persists a grant revocable in Capabilities ▸ Plugins, "Don't allow"
+ * refuses for the rest of the app run;
+ * 4. the script runs behind an in-page origin guard, so a navigation between
+ * the check and the run refuses instead of landing on another site.
+ */
+
+import { activePreviewScriptRunner } from '@/app/chat/right-rail/preview-script-runner'
+import { ensurePreviewScriptConsent, isGrantableOrigin } from '@/store/plugin-preview-grants'
+
+import { $pluginRecords } from './plugins-store'
+
+/** The capability a plugin declares to use `ctx.preview.executeJavaScript`. */
+export const PREVIEW_SCRIPT_CAPABILITY = 'preview.executeJavaScript'
+
+export const PREVIEW_NOTHING_OPEN = 'No preview page is open.'
+
+export interface PluginPreview {
+ /** True when this plugin declared `preview.executeJavaScript` and this
+ * window has a live Browser page for the focused session. Says nothing
+ * about the user's consent — that is asked on the first call. */
+ isAvailable: () => boolean
+ /** Run `code` in the focused session's active preview Browser tab and
+ * resolve its completion value. Always a Promise; rejects when the
+ * capability is undeclared, no page is open, the page is not a web
+ * origin, the user did not allow it, or the page changed origin. */
+ executeJavaScript: (code: string) => Promise<unknown>
+}
+
+const ORIGIN_PROBE = 'window.location.origin'
+
+/** Prepends a statement, so the plugin's script keeps its completion value. */
+function originGuarded(origin: string, code: string): string {
+ const expected = JSON.stringify(origin)
+
+ return `if (window.location.origin !== ${expected}) { throw new Error('The preview page changed origin; script not run.') }\n${code}`
+}
+
+async function runPreviewScript(pluginId: string, declared: boolean, code: unknown): Promise<unknown> {
+ if (typeof code !== 'string') {
+ throw new Error('ctx.preview.executeJavaScript requires a string')
+ }
+
+ if (!declared) {
+ throw new Error(`Plugin "${pluginId}" did not declare the ${PREVIEW_SCRIPT_CAPABILITY} capability.`)
+ }
+
+ // Bound to the tab resolved now: the origin the user is asked about and the
+ // page the script lands on are the same tab even if focus moves meanwhile.
+ const run = activePreviewScriptRunner()
+
+ if (!run) {
+ throw new Error(PREVIEW_NOTHING_OPEN)
+ }
+
+ const origin = await run(ORIGIN_PROBE)
+
+ if (typeof origin !== 'string' || !isGrantableOrigin(origin)) {
+ throw new Error('Preview scripts run only on a web page (http or https).')
+ }
+
+ const name = $pluginRecords.get()[pluginId]?.name ?? pluginId
+
+ if (!(await ensurePreviewScriptConsent(pluginId, name, origin))) {
+ throw new Error(`${name} is not allowed to run scripts on ${origin}.`)
+ }
+
+ return run(originGuarded(origin, code))
+}
+
+export function createPluginPreview(pluginId: string, capabilities: readonly string[] = []): PluginPreview {
+ const declared = capabilities.includes(PREVIEW_SCRIPT_CAPABILITY)
+
+ return {
+ isAvailable: () => declared && Boolean(activePreviewScriptRunner()),
+ executeJavaScript: code => runPreviewScript(pluginId, declared, code)
+ }
+}
diff --git a/apps/desktop/src/contrib/plugin.ts b/apps/desktop/src/contrib/plugin.ts
index d487729ac19..f3ad9848c91 100644
--- a/apps/desktop/src/contrib/plugin.ts
+++ b/apps/desktop/src/contrib/plugin.ts
@@ -29,13 +29,15 @@ import { $petActive } from '@/store/pet'
import { clearPetMessages, type PetSayOptions, sayPetMessage } from '@/store/pet-plugin-messages'
import { type GatewayEventListener, onGatewayEvent } from './events'
+import { createPluginPreview, type PluginPreview } from './plugin-preview'
import { $pluginRecords } from './plugins-store'
import { registry } from './registry'
import { type PluginSettingsPage, settingsPageContribution } from './settings-pages'
-export type { PluginSettingsPage, PluginSettingsSubpage } from './settings-pages'
+export type { PluginPreview } from './plugin-preview'
import type { Contribution } from './types'
+export type { PluginSettingsPage, PluginSettingsSubpage } from './settings-pages'
export type { PluginRestOptions } from '@/hermes'
export type { HermesOpenTarget } from '@/lib/hermes-open-target'
export type { PluginAppActionId, PluginAppActionInfo, PluginRunActionResult } from '@/lib/keybinds/plugin-actions'
@@ -171,6 +173,11 @@ export interface PluginContext {
runAction: (id: PluginAppActionId) => PluginRunActionResult
/** The actions `runAction` accepts, with their localized labels. */
listActions: () => PluginAppActionInfo[]
+ /** Run JavaScript in the preview Browser page. Closed unless the plugin
+ * declares `capabilities: ['preview.executeJavaScript']`, and even then
+ * the app asks the user once per page origin before anything runs.
+ * Feature-detect on older hosts: `ctx.preview?.executeJavaScript`. */
+ preview: PluginPreview
/** Plugin-scoped persistence. */
storage: PluginStorage
/** Plugin-scoped i18n: ship + register locale bundles under this plugin,
@@ -189,6 +196,10 @@ export interface HermesPlugin {
* for opt-in plugins: they inventory in Capabilities ▸ Plugins, off until the
* user flips the switch. */
defaultEnabled?: boolean
+ /** Sensitive doors this plugin uses, declared up front so the app can show
+ * them and gate them. Today: `'preview.executeJavaScript'` (`ctx.preview`).
+ * A door the plugin did not declare refuses every call. */
+ capabilities?: readonly string[]
/** Called once at load; wire contributions through `ctx`. */
register: (ctx: PluginContext) => void
}
@@ -343,9 +354,21 @@ function createPluginLifetime(track: (dispose: () => void) => () => void) {
}
}
+/** The declared capabilities of a plugin export, strings only. */
+export function declaredCapabilities(plugin: Pick<HermesPlugin, 'capabilities'>): string[] {
+ return Array.isArray(plugin.capabilities)
+ ? plugin.capabilities.filter((entry): entry is string => typeof entry === 'string')
+ : []
+}
+
/** Build the scoped context handed to a plugin's `register`. `onDispose`
- * receives every registration's disposer (the loader's unload/reload hook). */
-export function createPluginContext(pluginId: string, onDispose?: (dispose: () => void) => void): PluginContext {
+ * receives every registration's disposer (the loader's unload/reload hook);
+ * `capabilities` is what the plugin declared (`declaredCapabilities`). */
+export function createPluginContext(
+ pluginId: string,
+ onDispose?: (dispose: () => void) => void,
+ capabilities: readonly string[] = []
+): PluginContext {
const source = `plugin:${pluginId}`
const scope = (c: PluginContribution): Contribution => ({ ...c, id: `${pluginId}:${c.id}`, source })
@@ -369,6 +392,7 @@ export function createPluginContext(pluginId: string, onDispose?: (dispose: () =
pet: createPluginPet(pluginId, track),
runAction: id => runPluginAppAction(pluginId, id),
listActions: listPluginAppActions,
+ preview: createPluginPreview(pluginId, capabilities),
storage: createPluginStorage(pluginId),
i18n: createPluginI18n(pluginId, track)
}
diff --git a/apps/desktop/src/contrib/plugins-store.ts b/apps/desktop/src/contrib/plugins-store.ts
index 5de08d3e6d7..c9a95871d7a 100644
--- a/apps/desktop/src/contrib/plugins-store.ts
+++ b/apps/desktop/src/contrib/plugins-store.ts
@@ -20,6 +20,8 @@ export interface PluginRecord {
status: PluginStatus
/** One-liner from the plugin's own metadata (what it adds). */
description?: string
+ /** Sensitive doors the plugin declared (`HermesPlugin.capabilities`). */
+ capabilities?: string[]
/** Load/registration failure message (status 'error'). */
error?: string
/** Absolute plugin.js path (disk plugins) — powers "Reveal in Finder". */
diff --git a/apps/desktop/src/contrib/plugins.ts b/apps/desktop/src/contrib/plugins.ts
index 3708c3b0d0c..540ee894113 100644
--- a/apps/desktop/src/contrib/plugins.ts
+++ b/apps/desktop/src/contrib/plugins.ts
@@ -14,7 +14,7 @@
*/
import { trackGatewayEventDisposers } from './events'
-import { createPluginContext, type HermesPlugin } from './plugin'
+import { createPluginContext, declaredCapabilities, type HermesPlugin } from './plugin'
import { pluginActive, publishPlugin } from './plugins-store'
import { watchRuntimePlugins } from './runtime-loader'
@@ -45,10 +45,13 @@ export function discoverBundledPlugins(): void {
// Same inventory + live-toggle contract as runtime plugins: each bundled
// plugin publishes a record with activate/deactivate handles, and a
// persisted disable survives boots by skipping registration here.
+ const capabilities = declaredCapabilities(plugin)
+
const record = {
id: plugin.id,
name: plugin.name ?? plugin.id,
description: plugin.description,
+ capabilities,
kind: 'bundled' as const
}
@@ -61,7 +64,7 @@ export function discoverBundledPlugins(): void {
try {
trackGatewayEventDisposers(
dispose => disposers.push(dispose),
- () => plugin.register(createPluginContext(plugin.id, dispose => disposers.push(dispose)))
+ () => plugin.register(createPluginContext(plugin.id, dispose => disposers.push(dispose), capabilities))
)
publishPlugin({ ...record, status: 'loaded' })
} catch (error) {
diff --git a/apps/desktop/src/contrib/runtime-loader.test.ts b/apps/desktop/src/contrib/runtime-loader.test.ts
index c177c9c35a7..3d3b3d16fef 100644
--- a/apps/desktop/src/contrib/runtime-loader.test.ts
+++ b/apps/desktop/src/contrib/runtime-loader.test.ts
@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type { HermesReadDirResult } from '@/global'
import type * as HermesModule from '@/hermes'
+import { $previewScriptGrants, grantPreviewScript } from '@/store/plugin-preview-grants'
import { emitGatewayEvent } from './events'
import { $pluginRecords, publishPlugin, setPluginEnabled } from './plugins-store'
@@ -451,8 +452,11 @@ describe('uninstallDiskPlugin (Plugins hub trash button)', () => {
try {
await seedStandalone()
removeDesktopPlugin.mockResolvedValue({ ok: true })
+ grantPreviewScript('gone', 'https://mail.example.com')
expect(await uninstallDiskPlugin('gone')).toEqual({ ok: true })
+ // A later plugin reusing the id asks again instead of inheriting the grant.
+ expect($previewScriptGrants.get().gone).toBeUndefined()
// The folder name, never a path — Electron resolves it under the root.
expect(removeDesktopPlugin).toHaveBeenCalledWith({ name: 'gone-soon' })
diff --git a/apps/desktop/src/contrib/runtime-loader.ts b/apps/desktop/src/contrib/runtime-loader.ts
index f9c4b55025d..4946f0ab7d2 100644
--- a/apps/desktop/src/contrib/runtime-loader.ts
+++ b/apps/desktop/src/contrib/runtime-loader.ts
@@ -37,9 +37,10 @@ import { atom } from 'nanostores'
import { isReadFileErrorResult } from '@/lib/desktop-fs'
import { installPluginSdk, sdkImportMap } from '@/sdk/runtime'
import { notifyError } from '@/store/notifications'
+import { revokePreviewScript } from '@/store/plugin-preview-grants'
import { trackGatewayEventDisposers } from './events'
-import { createPluginContext, type HermesPlugin } from './plugin'
+import { createPluginContext, declaredCapabilities, type HermesPlugin } from './plugin'
import { $pluginRecords, dropPlugin, pluginActive, type PluginKind, publishPlugin } from './plugins-store'
interface LoadOptions {
@@ -456,10 +457,13 @@ export async function loadRuntimePlugin(
throw new Error(`duplicate id "${plugin.id}", already loaded from ${owner.file ?? owner.kind}`)
}
+ const capabilities = declaredCapabilities(plugin)
+
const record = {
id: plugin.id,
name: plugin.name ?? plugin.id,
description: plugin.description,
+ capabilities,
kind: options.kind ?? 'disk',
file: options.file,
packageName: options.packageName,
@@ -493,7 +497,7 @@ export async function loadRuntimePlugin(
try {
result = trackGatewayEventDisposers(
dispose => disposers.push(dispose),
- () => plugin.register(createPluginContext(plugin.id, dispose => disposers.push(dispose)))
+ () => plugin.register(createPluginContext(plugin.id, dispose => disposers.push(dispose), capabilities))
)
} catch (error) {
failRegistration(error)
@@ -1008,6 +1012,11 @@ export async function uninstallDiskPlugin(pluginId: string): Promise<{ ok: boole
retireDiskPlugin(file, record)
+ // A later plugin reusing this id must ask the user again, never inherit.
+ if (record.id) {
+ revokePreviewScript(record.id)
+ }
+
return { ok: true }
}
diff --git a/apps/desktop/src/i18n/ar_capabilities.ts b/apps/desktop/src/i18n/ar_capabilities.ts
index b7b10836e5e..76090b327c7 100644
--- a/apps/desktop/src/i18n/ar_capabilities.ts
+++ b/apps/desktop/src/i18n/ar_capabilities.ts
@@ -1,3 +1,4 @@
+import { arPluginPreviewAccess } from './ar_plugin_preview_access'
import type { TranslationOverrides } from './define-locale'
export const arCapabilities = {
@@ -14,6 +15,7 @@ export const arCapabilities = {
},
skills: {
plugins: {
+ ...arPluginPreviewAccess,
pageBlurb: 'يمكن للإضافة توسيع هذا التطبيق أو الوكيل أو كليهما — ولكل جزء مفتاح تشغيل مستقل.'
},
tabSkills: 'المهارات',
diff --git a/apps/desktop/src/i18n/ar_plugin_preview_access.ts b/apps/desktop/src/i18n/ar_plugin_preview_access.ts
new file mode 100644
index 00000000000..5f680ea1bd0
--- /dev/null
+++ b/apps/desktop/src/i18n/ar_plugin_preview_access.ts
@@ -0,0 +1,16 @@
+import type { PluginPreviewAccessTranslations } from './types_plugin_preview_access'
+
+/** Copy for the preview-script consent prompt and the per-plugin grant list (Capabilities ▸ Plugins). */
+export const arPluginPreviewAccess: PluginPreviewAccessTranslations = {
+ previewScriptPromptTitle: (plugin: string) => `هل تسمح لـ ${plugin} بتشغيل نصوص برمجية على هذه الصفحة؟`,
+ previewScriptPromptBody: (plugin: string, origin: string) =>
+ `يريد ${plugin} تشغيل JavaScript في متصفح المعاينة على ${origin}.`,
+ previewScriptPromptRisk: 'يمكن للنصوص البرمجية قراءة كل شيء على ذلك الموقع وتغييره، بما في ذلك صفحات الحسابات التي سجّلت الدخول إليها هناك.',
+ previewScriptPromptRevokeHint: 'ينطبق على هذا الموقع فقط. يمكنك إلغاؤه من المهارات ▸ الإضافات.',
+ previewScriptAllow: 'السماح على هذا الموقع',
+ previewScriptDeny: 'عدم السماح',
+ previewScriptAccessLabel: 'نصوص الصفحة',
+ previewScriptAccessNone: 'يسأل قبل تشغيل النصوص البرمجية على أي صفحة',
+ previewScriptRevoke: (origin: string) => `إلغاء الوصول إلى ${origin}`,
+ previewScriptRevoked: (plugin: string, origin: string) => `لم يعد بإمكان ${plugin} تشغيل نصوص برمجية على ${origin}.`
+}
diff --git a/apps/desktop/src/i18n/de.ts b/apps/desktop/src/i18n/de.ts
index e2de1bb880f..ac9cdf49c96 100644
--- a/apps/desktop/src/i18n/de.ts
+++ b/apps/desktop/src/i18n/de.ts
@@ -13,6 +13,7 @@ import { deModelSettings } from './de_model_settings'
import { deNotices } from './de_notices'
import { deNotifications } from './de_notifications'
import { deOnboarding } from './de_onboarding'
+import { dePluginPreviewAccess } from './de_plugin_preview_access'
import { dePluginUpdate } from './de_plugin_update'
import { deProjects } from './de_projects'
import { deSharedMetrics } from './de_shared_metrics'
@@ -2495,6 +2496,7 @@ export const deOverrides = {
`An Commit ${sha} gepinnt. Updates werden abgelehnt, bis es mit einem neuen Pin neu installiert wird.`,
pinnedBadge: sha => `gepinnt @ ${sha}`,
...dePluginUpdate,
+ ...dePluginPreviewAccess,
uninstall: 'Deinstallieren',
uninstallTip: (name: string, profile: string) => `${name} aus ${profile} deinstallieren`,
uninstallConfirmTitle: (name: string) => `${name} deinstallieren?`,
diff --git a/apps/desktop/src/i18n/de_plugin_preview_access.ts b/apps/desktop/src/i18n/de_plugin_preview_access.ts
new file mode 100644
index 00000000000..15a480f38cd
--- /dev/null
+++ b/apps/desktop/src/i18n/de_plugin_preview_access.ts
@@ -0,0 +1,16 @@
+import type { PluginPreviewAccessTranslations } from './types_plugin_preview_access'
+
+/** Copy for the preview-script consent prompt and the per-plugin grant list (Capabilities ▸ Plugins). */
+export const dePluginPreviewAccess: PluginPreviewAccessTranslations = {
+ previewScriptPromptTitle: (plugin: string) => `${plugin} Skripte auf dieser Seite ausführen lassen?`,
+ previewScriptPromptBody: (plugin: string, origin: string) =>
+ `${plugin} möchte im Vorschau-Browser JavaScript auf ${origin} ausführen.`,
+ previewScriptPromptRisk: 'Skripte können alles auf dieser Website lesen und ändern, auch Seiten von Konten, bei denen du dort angemeldet bist.',
+ previewScriptPromptRevokeHint: 'Gilt nur für diese Website. Du kannst den Zugriff unter Fähigkeiten ▸ Plugins widerrufen.',
+ previewScriptAllow: 'Auf dieser Website erlauben',
+ previewScriptDeny: 'Nicht erlauben',
+ previewScriptAccessLabel: 'Seitenskripte',
+ previewScriptAccessNone: 'Fragt vor dem Ausführen von Skripten auf einer Seite',
+ previewScriptRevoke: (origin: string) => `Zugriff auf ${origin} widerrufen`,
+ previewScriptRevoked: (plugin: string, origin: string) => `${plugin} kann keine Skripte mehr auf ${origin} ausführen.`
+}
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index 8c546a7ef05..05b28a94559 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -20,6 +20,7 @@ import { enModelSettings } from './en_model_settings'
import { enNotices } from './en_notices'
import { enNotifications } from './en_notifications'
import { enOnboarding } from './en_onboarding'
+import { enPluginPreviewAccess } from './en_plugin_preview_access'
import { enPluginUpdate } from './en_plugin_update'
import { enProjects } from './en_projects'
import { enSharedMetrics } from './en_shared_metrics'
@@ -2135,6 +2136,7 @@ export const en: Translations = {
`Pinned to commit ${sha}. Updates are refused until it is reinstalled with a new pin.`,
pinnedBadge: (sha: string) => `pinned @ ${sha}`,
...enPluginUpdate,
+ ...enPluginPreviewAccess,
uninstall: 'Uninstall',
uninstallTip: (name: string, profile: string) => `Uninstall ${name} from ${profile}`,
uninstallConfirmTitle: (name: string) => `Uninstall ${name}?`,
diff --git a/apps/desktop/src/i18n/en_plugin_preview_access.ts b/apps/desktop/src/i18n/en_plugin_preview_access.ts
new file mode 100644
index 00000000000..087c5eb0f24
--- /dev/null
+++ b/apps/desktop/src/i18n/en_plugin_preview_access.ts
@@ -0,0 +1,16 @@
+import type { PluginPreviewAccessTranslations } from './types_plugin_preview_access'
+
+/** Copy for the preview-script consent prompt and the per-plugin grant list (Capabilities ▸ Plugins). */
+export const enPluginPreviewAccess: PluginPreviewAccessTranslations = {
+ previewScriptPromptTitle: (plugin: string) => `Let ${plugin} run scripts on this page?`,
+ previewScriptPromptBody: (plugin: string, origin: string) =>
+ `${plugin} wants to run JavaScript in the preview Browser on ${origin}.`,
+ previewScriptPromptRisk: 'Scripts can read and change everything on that site, including pages from accounts you are signed in to there.',
+ previewScriptPromptRevokeHint: 'Applies to this site only. You can revoke it in Capabilities ▸ Plugins.',
+ previewScriptAllow: 'Allow on this site',
+ previewScriptDeny: "Don't allow",
+ previewScriptAccessLabel: 'Page scripts',
+ previewScriptAccessNone: 'Asks before running scripts on a page',
+ previewScriptRevoke: (origin: string) => `Revoke access to ${origin}`,
+ previewScriptRevoked: (plugin: string, origin: string) => `${plugin} can no longer run scripts on ${origin}.`
+}
diff --git a/apps/desktop/src/i18n/es.ts b/apps/desktop/src/i18n/es.ts
index 44c0759c722..cd77eb152db 100644
--- a/apps/desktop/src/i18n/es.ts
+++ b/apps/desktop/src/i18n/es.ts
@@ -14,6 +14,7 @@ import { esModelSettings } from './es_model_settings'
import { esNotices } from './es_notices'
import { esNotifications } from './es_notifications'
import { esOnboarding } from './es_onboarding'
+import { esPluginPreviewAccess } from './es_plugin_preview_access'
import { esPluginUpdate } from './es_plugin_update'
import { esProjects } from './es_projects'
import { esSharedMetrics } from './es_shared_metrics'
@@ -2487,6 +2488,7 @@ export const esOverrides = {
`Fijado al commit ${sha}. Las actualizaciones se rechazan hasta que se reinstale con un nuevo commit fijado.`,
pinnedBadge: (sha: string) => `fijado @ ${sha}`,
...esPluginUpdate,
+ ...esPluginPreviewAccess,
uninstall: 'Desinstalar',
uninstallTip: (name: string, profile: string) => `Desinstalar ${name} de ${profile}`,
uninstallConfirmTitle: (name: string) => `¿Desinstalar ${name}?`,
diff --git a/apps/desktop/src/i18n/es_plugin_preview_access.ts b/apps/desktop/src/i18n/es_plugin_preview_access.ts
new file mode 100644
index 00000000000..586fa9ddeb4
--- /dev/null
+++ b/apps/desktop/src/i18n/es_plugin_preview_access.ts
@@ -0,0 +1,16 @@
+import type { PluginPreviewAccessTranslations } from './types_plugin_preview_access'
+
+/** Copy for the preview-script consent prompt and the per-plugin grant list (Capabilities ▸ Plugins). */
+export const esPluginPreviewAccess: PluginPreviewAccessTranslations = {
+ previewScriptPromptTitle: (plugin: string) => `¿Permitir que ${plugin} ejecute scripts en esta página?`,
+ previewScriptPromptBody: (plugin: string, origin: string) =>
+ `${plugin} quiere ejecutar JavaScript en el navegador de vista previa en ${origin}.`,
+ previewScriptPromptRisk: 'Los scripts pueden leer y cambiar todo en ese sitio, incluidas las páginas de cuentas en las que tienes la sesión iniciada.',
+ previewScriptPromptRevokeHint: 'Solo se aplica a este sitio. Puedes revocarlo en Capacidades ▸ Plugins.',
+ previewScriptAllow: 'Permitir en este sitio',
+ previewScriptDeny: 'No permitir',
+ previewScriptAccessLabel: 'Scripts de página',
+ previewScriptAccessNone: 'Pregunta antes de ejecutar scripts en una página',
+ previewScriptRevoke: (origin: string) => `Revocar el acceso a ${origin}`,
+ previewScriptRevoked: (plugin: string, origin: string) => `${plugin} ya no puede ejecutar scripts en ${origin}.`
+}
diff --git a/apps/desktop/src/i18n/fr.ts b/apps/desktop/src/i18n/fr.ts
index 5f251afa1fc..05bfa1f7bb8 100644
--- a/apps/desktop/src/i18n/fr.ts
+++ b/apps/desktop/src/i18n/fr.ts
@@ -14,6 +14,7 @@ import { frModelSettings } from './fr_model_settings'
import { frNotices } from './fr_notices'
import { frNotifications } from './fr_notifications'
import { frOnboarding } from './fr_onboarding'
+import { frPluginPreviewAccess } from './fr_plugin_preview_access'
import { frPluginUpdate } from './fr_plugin_update'
import { frProjects } from './fr_projects'
import { frSharedMetrics } from './fr_shared_metrics'
@@ -2502,6 +2503,7 @@ export const frOverrides = {
`Épinglé au commit ${sha}. Les mises à jour sont refusées tant qu’il n’est pas réinstallé avec un nouvel épinglage.`,
pinnedBadge: (sha: string) => `épinglé @ ${sha}`,
...frPluginUpdate,
+ ...frPluginPreviewAccess,
uninstall: 'Désinstaller',
uninstallTip: (name: string, profile: string) => `Désinstaller ${name} de ${profile}`,
uninstallConfirmTitle: (name: string) => `Désinstaller ${name} ?`,
diff --git a/apps/desktop/src/i18n/fr_plugin_preview_access.ts b/apps/desktop/src/i18n/fr_plugin_preview_access.ts
new file mode 100644
index 00000000000..20f1264c9cc
--- /dev/null
+++ b/apps/desktop/src/i18n/fr_plugin_preview_access.ts
@@ -0,0 +1,16 @@
+import type { PluginPreviewAccessTranslations } from './types_plugin_preview_access'
+
+/** Copy for the preview-script consent prompt and the per-plugin grant list (Capabilities ▸ Plugins). */
+export const frPluginPreviewAccess: PluginPreviewAccessTranslations = {
+ previewScriptPromptTitle: (plugin: string) => `Autoriser ${plugin} à exécuter des scripts sur cette page ?`,
+ previewScriptPromptBody: (plugin: string, origin: string) =>
+ `${plugin} veut exécuter du JavaScript dans le navigateur d’aperçu sur ${origin}.`,
+ previewScriptPromptRisk: 'Les scripts peuvent lire et modifier tout ce qui se trouve sur ce site, y compris les pages des comptes auxquels vous y êtes connecté.',
+ previewScriptPromptRevokeHint: 'S’applique à ce site uniquement. Vous pouvez révoquer l’accès dans Capacités ▸ Plugins.',
+ previewScriptAllow: 'Autoriser sur ce site',
+ previewScriptDeny: 'Ne pas autoriser',
+ previewScriptAccessLabel: 'Scripts de page',
+ previewScriptAccessNone: 'Demande avant d’exécuter des scripts sur une page',
+ previewScriptRevoke: (origin: string) => `Révoquer l’accès à ${origin}`,
+ previewScriptRevoked: (plugin: string, origin: string) => `${plugin} ne peut plus exécuter de scripts sur ${origin}.`
+}
diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.ts
index 3c7f8efc392..9d98bbba3d8 100644
--- a/apps/desktop/src/i18n/ja.ts
+++ b/apps/desktop/src/i18n/ja.ts
@@ -15,6 +15,7 @@ import { jaModelSettings } from './ja_model_settings'
import { jaNotices } from './ja_notices'
import { jaNotifications } from './ja_notifications'
import { jaOnboarding } from './ja_onboarding'
+import { jaPluginPreviewAccess } from './ja_plugin_preview_access'
import { jaPluginSettings } from './ja_plugins'
import { jaProjects } from './ja_projects'
import { jaSharedMetrics } from './ja_shared_metrics'
@@ -1313,6 +1314,7 @@ export const jaOverrides = {
skillDeepLink: jaSkillDeepLink,
skills: {
plugins: {
+ ...jaPluginPreviewAccess,
pageBlurb:
'プラグインはこのアプリ、エージェント、または両方を拡張できます。それぞれに独立したスイッチがあります。'
},
diff --git a/apps/desktop/src/i18n/ja_plugin_preview_access.ts b/apps/desktop/src/i18n/ja_plugin_preview_access.ts
new file mode 100644
index 00000000000..cf712482b55
--- /dev/null
+++ b/apps/desktop/src/i18n/ja_plugin_preview_access.ts
@@ -0,0 +1,16 @@
+import type { PluginPreviewAccessTranslations } from './types_plugin_preview_access'
+
+/** Copy for the preview-script consent prompt and the per-plugin grant list (Capabilities ▸ Plugins). */
+export const jaPluginPreviewAccess: PluginPreviewAccessTranslations = {
+ previewScriptPromptTitle: (plugin: string) => `${plugin} にこのページでスクリプトの実行を許可しますか?`,
+ previewScriptPromptBody: (plugin: string, origin: string) =>
+ `${plugin} がプレビューブラウザーの ${origin} で JavaScript を実行しようとしています。`,
+ previewScriptPromptRisk: 'スクリプトはそのサイトのすべてを読み取り・変更できます。ログイン中のアカウントのページも含まれます。',
+ previewScriptPromptRevokeHint: 'このサイトにのみ適用されます。スキルとツール ▸ プラグインでいつでも取り消せます。',
+ previewScriptAllow: 'このサイトで許可',
+ previewScriptDeny: '許可しない',
+ previewScriptAccessLabel: 'ページスクリプト',
+ previewScriptAccessNone: 'ページでスクリプトを実行する前に確認します',
+ previewScriptRevoke: (origin: string) => `${origin} へのアクセスを取り消す`,
+ previewScriptRevoked: (plugin: string, origin: string) => `${plugin} は ${origin} でスクリプトを実行できなくなりました。`
+}
diff --git a/apps/desktop/src/i18n/ru.ts b/apps/desktop/src/i18n/ru.ts
index e6771bf8f34..396f9ac06fe 100644
--- a/apps/desktop/src/i18n/ru.ts
+++ b/apps/desktop/src/i18n/ru.ts
@@ -13,6 +13,7 @@ import { ruModelSettings } from './ru_model_settings'
import { ruNotices } from './ru_notices'
import { ruNotifications } from './ru_notifications'
import { ruOnboarding } from './ru_onboarding'
+import { ruPluginPreviewAccess } from './ru_plugin_preview_access'
import { ruPluginSettings } from './ru_plugins'
import { ruProjects } from './ru_projects'
import { ruSharedMetrics } from './ru_shared_metrics'
@@ -1437,6 +1438,7 @@ export const ruOverrides = {
skillDeepLink: ruSkillDeepLink,
skills: {
plugins: {
+ ...ruPluginPreviewAccess,
pageBlurb: 'Плагин может расширять приложение, агента или оба сразу — у каждой части свой переключатель.'
},
tabSkills: 'Навыки',
diff --git a/apps/desktop/src/i18n/ru_plugin_preview_access.ts b/apps/desktop/src/i18n/ru_plugin_preview_access.ts
new file mode 100644
index 00000000000..9061f0fb624
--- /dev/null
+++ b/apps/desktop/src/i18n/ru_plugin_preview_access.ts
@@ -0,0 +1,16 @@
+import type { PluginPreviewAccessTranslations } from './types_plugin_preview_access'
+
+/** Copy for the preview-script consent prompt and the per-plugin grant list (Capabilities ▸ Plugins). */
+export const ruPluginPreviewAccess: PluginPreviewAccessTranslations = {
+ previewScriptPromptTitle: (plugin: string) => `Разрешить ${plugin} запускать скрипты на этой странице?`,
+ previewScriptPromptBody: (plugin: string, origin: string) =>
+ `${plugin} хочет выполнить JavaScript во встроенном браузере на ${origin}.`,
+ previewScriptPromptRisk: 'Скрипты могут читать и изменять всё на этом сайте, включая страницы аккаунтов, в которые вы там вошли.',
+ previewScriptPromptRevokeHint: 'Действует только для этого сайта. Отозвать можно в разделе Возможности ▸ Плагины.',
+ previewScriptAllow: 'Разрешить на этом сайте',
+ previewScriptDeny: 'Не разрешать',
+ previewScriptAccessLabel: 'Скрипты страниц',
+ previewScriptAccessNone: 'Спрашивает перед запуском скриптов на странице',
+ previewScriptRevoke: (origin: string) => `Отозвать доступ к ${origin}`,
+ previewScriptRevoked: (plugin: string, origin: string) => `${plugin} больше не может запускать скрипты на ${origin}.`
+}
diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.ts
index 0f2e489af4f..ad53e33323e 100644
--- a/apps/desktop/src/i18n/types.ts
+++ b/apps/desktop/src/i18n/types.ts
@@ -24,6 +24,7 @@ import type { ModelSettingsTranslations } from './types_model_settings'
import type { NoticeTranslations } from './types_notices'
import type { NotificationSettingsTranslations } from './types_notifications'
import type { OnboardingTranslations } from './types_onboarding'
+import type { PluginPreviewAccessTranslations } from './types_plugin_preview_access'
import type { PluginUpdateTranslations } from './types_plugin_update'
import type { SidebarProjectsTranslations } from './types_projects'
import type { SharedMetricsTranslations } from './types_shared_metrics'
@@ -1888,7 +1889,8 @@ catalog: CatalogTranslations
skillArchivedTitle: string
skillArchivedMessage: string
tabPlugins: string
- plugins: PluginUpdateTranslations & {
+ plugins: PluginUpdateTranslations &
+ PluginPreviewAccessTranslations & {
agentTitle: string
agentBlurb: string
pageBlurb: string
diff --git a/apps/desktop/src/i18n/types_plugin_preview_access.ts b/apps/desktop/src/i18n/types_plugin_preview_access.ts
new file mode 100644
index 00000000000..790f3e43846
--- /dev/null
+++ b/apps/desktop/src/i18n/types_plugin_preview_access.ts
@@ -0,0 +1,14 @@
+/** Copy for the `ctx.preview.executeJavaScript` consent: the app-owned prompt a plugin's first
+ * call on a page origin raises, and the per-plugin grant list in Capabilities ▸ Plugins. */
+export interface PluginPreviewAccessTranslations {
+ previewScriptPromptTitle: (plugin: string) => string
+ previewScriptPromptBody: (plugin: string, origin: string) => string
+ previewScriptPromptRisk: string
+ previewScriptPromptRevokeHint: string
+ previewScriptAllow: string
+ previewScriptDeny: string
+ previewScriptAccessLabel: string
+ previewScriptAccessNone: string
+ previewScriptRevoke: (origin: string) => string
+ previewScriptRevoked: (plugin: string, origin: string) => string
+}
diff --git a/apps/desktop/src/i18n/zh-hant_capabilities.ts b/apps/desktop/src/i18n/zh-hant_capabilities.ts
index b4f69ca6a1e..89574c6d613 100644
--- a/apps/desktop/src/i18n/zh-hant_capabilities.ts
+++ b/apps/desktop/src/i18n/zh-hant_capabilities.ts
@@ -1,8 +1,10 @@
import type { TranslationOverrides } from './define-locale'
+import { zhHantPluginPreviewAccess } from './zh-hant_plugin_preview_access'
export const zhHantCapabilities = {
skills: {
plugins: {
+ ...zhHantPluginPreviewAccess,
pageBlurb: '外掛可以擴充本應用程式、代理,或兩者 — 每一部分都有自己的開關。'
},
hub: {
diff --git a/apps/desktop/src/i18n/zh-hant_plugin_preview_access.ts b/apps/desktop/src/i18n/zh-hant_plugin_preview_access.ts
new file mode 100644
index 00000000000..2ae6ce9722c
--- /dev/null
+++ b/apps/desktop/src/i18n/zh-hant_plugin_preview_access.ts
@@ -0,0 +1,16 @@
+import type { PluginPreviewAccessTranslations } from './types_plugin_preview_access'
+
+/** Copy for the preview-script consent prompt and the per-plugin grant list (Capabilities ▸ Plugins). */
+export const zhHantPluginPreviewAccess: PluginPreviewAccessTranslations = {
+ previewScriptPromptTitle: (plugin: string) => `允許 ${plugin} 在此頁面執行指令碼嗎?`,
+ previewScriptPromptBody: (plugin: string, origin: string) =>
+ `${plugin} 想在預覽瀏覽器中的 ${origin} 上執行 JavaScript。`,
+ previewScriptPromptRisk: '指令碼可以讀取並變更該網站上的所有內容,包括你在該網站已登入帳戶的頁面。',
+ previewScriptPromptRevokeHint: '僅適用於此網站。你可以在 技能與工具 ▸ 外掛 中撤銷。',
+ previewScriptAllow: '在此網站允許',
+ previewScriptDeny: '不允許',
+ previewScriptAccessLabel: '頁面指令碼',
+ previewScriptAccessNone: '在頁面上執行指令碼前會先詢問',
+ previewScriptRevoke: (origin: string) => `撤銷對 ${origin} 的存取`,
+ previewScriptRevoked: (plugin: string, origin: string) => `${plugin} 不能再於 ${origin} 上執行指令碼。`
+}
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index 0d5372081c8..f5a1b1dd702 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -14,6 +14,7 @@ import { zhModelSettings } from './zh_model_settings'
import { zhNotices } from './zh_notices'
import { zhNotifications } from './zh_notifications'
import { zhOnboarding } from './zh_onboarding'
+import { zhPluginPreviewAccess } from './zh_plugin_preview_access'
import { zhProjects } from './zh_projects'
import { zhSharedMetrics } from './zh_shared_metrics'
import { zhThemePicker } from './zh_theme_picker'
@@ -2047,6 +2048,7 @@ export const zhOverrides = {
skillArchivedMessage: '可通过 hermes curator restore 恢复。',
tabPlugins: '插件',
plugins: {
+ ...zhPluginPreviewAccess,
agentTitle: 'Agent 插件',
agentBlurb: '为所选配置扩展 agent — 工具、钩子、模型提供方。重启网关后生效。',
pageBlurb: '插件可以扩展本应用、agent,或两者 — 每一半都有自己的开关。',
diff --git a/apps/desktop/src/i18n/zh_plugin_preview_access.ts b/apps/desktop/src/i18n/zh_plugin_preview_access.ts
new file mode 100644
index 00000000000..d1813443a41
--- /dev/null
+++ b/apps/desktop/src/i18n/zh_plugin_preview_access.ts
@@ -0,0 +1,16 @@
+import type { PluginPreviewAccessTranslations } from './types_plugin_preview_access'
+
+/** Copy for the preview-script consent prompt and the per-plugin grant list (Capabilities ▸ Plugins). */
+export const zhPluginPreviewAccess: PluginPreviewAccessTranslations = {
+ previewScriptPromptTitle: (plugin: string) => `允许 ${plugin} 在此页面运行脚本吗?`,
+ previewScriptPromptBody: (plugin: string, origin: string) =>
+ `${plugin} 想在预览浏览器中的 ${origin} 上运行 JavaScript。`,
+ previewScriptPromptRisk: '脚本可以读取并更改该网站上的所有内容,包括你在该网站已登录账户的页面。',
+ previewScriptPromptRevokeHint: '仅适用于此网站。你可以在 技能与工具 ▸ 插件 中撤销。',
+ previewScriptAllow: '在此网站允许',
+ previewScriptDeny: '不允许',
+ previewScriptAccessLabel: '页面脚本',
+ previewScriptAccessNone: '在页面上运行脚本前会先询问',
+ previewScriptRevoke: (origin: string) => `撤销对 ${origin} 的访问`,
+ previewScriptRevoked: (plugin: string, origin: string) => `${plugin} 不能再在 ${origin} 上运行脚本。`
+}
diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.ts
index 672c544f495..1a126f4d201 100644
--- a/apps/desktop/src/sdk/index.ts
+++ b/apps/desktop/src/sdk/index.ts
@@ -111,7 +111,6 @@ import { pluginDecisions, profiles, skills, toolsets } from './bridge'
import { composerHost } from './composer'
import { i18nHost } from './i18n'
import { planPluginOpenSession } from './plugin-open-session-plan'
-import { executePreviewJavaScript, previewIsAvailable } from './preview'
import {
type PluginProfileRequestOptions,
type PluginProfileRoute,
@@ -607,18 +606,6 @@ export const host = {
/** Read, update, and observe the allowlisted Desktop appearance preferences. */
settings: desktopSettings,
- /**
- * Run JavaScript in the focused session's live preview Browser tab — the
- * same guest `executeJavaScript` drive_preview and the tour use. Rejects
- * when this window has no mounted webview (empty rail, a file peek, or a
- * Browser popped out into another window). Always a Promise so a plugin
- * `.catch()` sees a missing page the same way it sees a guest throw.
- */
- preview: {
- executeJavaScript: executePreviewJavaScript,
- isAvailable: previewIsAvailable
- },
-
/** Toast into the app's notification stack. */
notify,
notifyError,
diff --git a/apps/desktop/src/sdk/plugin-contract.ts b/apps/desktop/src/sdk/plugin-contract.ts
index 898b1885a86..5d79ba13def 100644
--- a/apps/desktop/src/sdk/plugin-contract.ts
+++ b/apps/desktop/src/sdk/plugin-contract.ts
@@ -12,6 +12,7 @@ export type {
PluginNotificationAction,
PluginOs,
PluginPet,
+ PluginPreview,
PluginRestOptions,
PluginRunActionResult,
PluginSettingsPage,
diff --git a/apps/desktop/src/sdk/preview.test.ts b/apps/desktop/src/sdk/preview.test.ts
deleted file mode 100644
index d4718ff2bc1..00000000000
--- a/apps/desktop/src/sdk/preview.test.ts
+++ /dev/null
@@ -1,68 +0,0 @@
-import { beforeEach, describe, expect, it } from 'vitest'
-
-import { registerPreviewScriptRunner } from '@/app/chat/right-rail/preview-script-runner'
-import { host } from '@/sdk'
-import { $rightRailActiveTabId } from '@/store/layout'
-import { closeRightRail, openPreview } from '@/store/preview'
-
-function urlTarget(url: string) {
- return { kind: 'url' as const, label: 'Browser', source: url, url }
-}
-
-function fileTarget(path: string) {
- return {
- kind: 'file' as const,
- label: path,
- path,
- previewKind: 'text' as const,
- source: path,
- url: `file://${path}`
- }
-}
-
-describe('host.preview', () => {
- let unbind: (() => void) | undefined
-
- beforeEach(() => {
- unbind?.()
- unbind = undefined
- closeRightRail()
- window.localStorage.clear()
- })
-
- it('rejects when no preview page is open', async () => {
- expect(host.preview.isAvailable()).toBe(false)
- await expect(host.preview.executeJavaScript('1 + 1')).rejects.toThrow('No preview page is open.')
- })
-
- it('is unavailable on a file peek that never registered a guest runner', () => {
- openPreview(fileTarget('/work/notes.txt'))
- expect(host.preview.isAvailable()).toBe(false)
- })
-
- it('runs JS on the active Browser tab and returns the guest value', async () => {
- openPreview(urlTarget('https://example.com'))
- const tabId = $rightRailActiveTabId.get()!
-
- unbind = registerPreviewScriptRunner(tabId, async code => ({ ran: code }))
-
- expect(host.preview.isAvailable()).toBe(true)
- await expect(host.preview.executeJavaScript('document.title')).resolves.toEqual({ ran: 'document.title' })
- })
-
- it('rejects a non-string without throwing synchronously', async () => {
- const pending = host.preview.executeJavaScript(1 as never)
-
- expect(pending).toBeInstanceOf(Promise)
- await expect(pending).rejects.toThrow('host.preview.executeJavaScript requires a string')
- })
-
- it('forwards a guest throw as a rejection', async () => {
- openPreview(urlTarget('https://example.com'))
- unbind = registerPreviewScriptRunner($rightRailActiveTabId.get()!, async () => {
- throw new Error('guest exploded')
- })
-
- await expect(host.preview.executeJavaScript('x')).rejects.toThrow('guest exploded')
- })
-})
diff --git a/apps/desktop/src/sdk/preview.ts b/apps/desktop/src/sdk/preview.ts
deleted file mode 100644
index 2f47813e6e6..00000000000
--- a/apps/desktop/src/sdk/preview.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * Plugin door into the preview Browser's guest page.
- *
- * drive_preview and the preview tour already reach the guest through
- * `activePreviewScriptRunner` (the pane registers webview.executeJavaScript).
- * Plugins had no supported equivalent, so authors scraped `<webview>` out of
- * the app DOM — which the catalog `desktop surface` rule exists to stop.
- * This module is that equivalent: the focused session's live Browser tab, in
- * this window. A file peek, an empty rail, or a Browser popped out into
- * another window have no runner here.
- */
-import { activePreviewScriptRunner } from '@/app/chat/right-rail/preview-script-runner'
-
-export const PREVIEW_NOTHING_OPEN = 'No preview page is open.'
-
-/** True when this window has a live guest page for the focused session. */
-export function previewIsAvailable(): boolean {
- return Boolean(activePreviewScriptRunner())
-}
-
-/**
- * Run `code` in the focused session's active preview Browser tab.
- * Always a Promise: a missing page and a guest throw both reject, so plugin
- * `.catch()` sees them the same way (host doors are async-safe).
- */
-export function executePreviewJavaScript(code: string): Promise<unknown> {
- return (async () => {
- if (typeof code !== 'string') {
- throw new Error('host.preview.executeJavaScript requires a string')
- }
-
- const run = activePreviewScriptRunner()
-
- if (!run) {
- throw new Error(PREVIEW_NOTHING_OPEN)
- }
-
- return run(code)
- })()
-}
diff --git a/apps/desktop/src/store/plugin-preview-grants.ts b/apps/desktop/src/store/plugin-preview-grants.ts
new file mode 100644
index 00000000000..101b7a1a140
--- /dev/null
+++ b/apps/desktop/src/store/plugin-preview-grants.ts
@@ -0,0 +1,164 @@
+import { atom } from 'nanostores'
+
+import { Codecs, persistentAtom } from '@/lib/persisted'
+
+/**
+ * USER GRANTS FOR `ctx.preview.executeJavaScript` — which plugin may run
+ * script in the preview Browser on which page origin.
+ *
+ * The preview pane can hold pages the user is signed in to, so script there
+ * reads session data. A plugin that declared the capability still runs
+ * nothing until the user allows it for that origin; the grant is per plugin
+ * AND per origin, persisted across launches and revocable from Capabilities ▸
+ * Plugins. "Don't allow" holds for this app run only, so a plugin retrying in
+ * a loop cannot stack prompts, and the question comes back next launch.
+ *
+ * Global scope (like the plugin enable decisions): Desktop plugins are
+ * app-level, not per profile.
+ */
+
+/** pluginId -> origins the user allowed. */
+export type PreviewScriptGrants = Record<string, string[]>
+
+function sanitizeGrants(value: unknown): PreviewScriptGrants {
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
+ return {}
+ }
+
+ const grants: PreviewScriptGrants = {}
+
+ for (const [pluginId, origins] of Object.entries(value)) {
+ if (!Array.isArray(origins)) {
+ continue
+ }
+
+ const kept = origins.filter((origin): origin is string => typeof origin === 'string' && isGrantableOrigin(origin))
+
+ if (kept.length > 0) {
+ grants[pluginId] = [...new Set(kept)]
+ }
+ }
+
+ return grants
+}
+
+export const $previewScriptGrants = persistentAtom<PreviewScriptGrants>(
+ 'hermes.desktop.pluginPreviewScriptGrants.v1',
+ {},
+ Codecs.json(sanitizeGrants)
+)
+
+/** "Don't allow" answers for this app run, as `${pluginId}\n${origin}`. */
+const $sessionDenials = atom<ReadonlySet<string>>(new Set())
+
+const pairKey = (pluginId: string, origin: string) => `${pluginId}\n${origin}`
+
+/** A grant names a real web origin: `http(s)://host[:port]`, nothing else.
+ * Opaque origins (`null` for about:blank, data:, sandboxed frames) and
+ * `file://` cannot scope a grant to one site, so they are never offered. */
+export function isGrantableOrigin(origin: string): boolean {
+ try {
+ const url = new URL(origin)
+
+ return (url.protocol === 'http:' || url.protocol === 'https:') && url.origin === origin
+ } catch {
+ return false
+ }
+}
+
+export function hasPreviewScriptGrant(pluginId: string, origin: string): boolean {
+ return $previewScriptGrants.get()[pluginId]?.includes(origin) ?? false
+}
+
+export function grantPreviewScript(pluginId: string, origin: string): void {
+ const grants = $previewScriptGrants.get()
+ const current = grants[pluginId] ?? []
+
+ if (!current.includes(origin)) {
+ $previewScriptGrants.set({ ...grants, [pluginId]: [...current, origin] })
+ }
+}
+
+/** Revoke one origin, or every origin for the plugin when omitted. */
+export function revokePreviewScript(pluginId: string, origin?: string): void {
+ const { [pluginId]: current, ...rest } = $previewScriptGrants.get()
+
+ if (!current) {
+ return
+ }
+
+ const kept = origin === undefined ? [] : current.filter(entry => entry !== origin)
+
+ $previewScriptGrants.set(kept.length > 0 ? { ...rest, [pluginId]: kept } : rest)
+}
+
+export interface PreviewScriptConsentRequest {
+ id: number
+ pluginId: string
+ pluginName: string
+ origin: string
+}
+
+/** Pending prompts, oldest first. The app-owned dialog renders the head. */
+export const $previewScriptConsentQueue = atom<readonly PreviewScriptConsentRequest[]>([])
+
+const pending = new Map<string, { promise: Promise<boolean>; resolve: (allowed: boolean) => void }>()
+let nextRequestId = 1
+
+/**
+ * Resolve whether `pluginId` may run script on `origin`: an existing grant
+ * answers true, a "Don't allow" from this run answers false, otherwise the
+ * user is asked once (concurrent calls for the same pair share the prompt).
+ */
+export function ensurePreviewScriptConsent(pluginId: string, pluginName: string, origin: string): Promise<boolean> {
+ if (hasPreviewScriptGrant(pluginId, origin)) {
+ return Promise.resolve(true)
+ }
+
+ const key = pairKey(pluginId, origin)
+
+ if ($sessionDenials.get().has(key)) {
+ return Promise.resolve(false)
+ }
+
+ const inFlight = pending.get(key)
+
+ if (inFlight) {
+ return inFlight.promise
+ }
+
+ let resolve!: (allowed: boolean) => void
+ const promise = new Promise<boolean>(done => (resolve = done))
+
+ pending.set(key, { promise, resolve })
+ $previewScriptConsentQueue.set([
+ ...$previewScriptConsentQueue.get(),
+ { id: nextRequestId++, origin, pluginId, pluginName }
+ ])
+
+ return promise
+}
+
+/** The dialog's answer for request `id`. Anything but an explicit allow —
+ * Esc, backdrop, the close button — arrives here as `false`. */
+export function answerPreviewScriptConsent(id: number, allowed: boolean): void {
+ const queue = $previewScriptConsentQueue.get()
+ const request = queue.find(entry => entry.id === id)
+
+ if (!request) {
+ return
+ }
+
+ $previewScriptConsentQueue.set(queue.filter(entry => entry.id !== id))
+
+ const key = pairKey(request.pluginId, request.origin)
+
+ if (allowed) {
+ grantPreviewScript(request.pluginId, request.origin)
+ } else {
+ $sessionDenials.set(new Set([...$sessionDenials.get(), key]))
+ }
+
+ pending.get(key)?.resolve(allowed)
+ pending.delete(key)
+}
diff --git a/locales/_keys.desktop.json b/locales/_keys.desktop.json
index ae0fe91d334..bfe18a443ff 100644
--- a/locales/_keys.desktop.json
+++ b/locales/_keys.desktop.json
@@ -4848,6 +4848,16 @@
"skills.plugins.pinnedBadge",
"skills.plugins.pinnedProvenance",
"skills.plugins.portableBadge",
+ "skills.plugins.previewScriptAccessLabel",
+ "skills.plugins.previewScriptAccessNone",
+ "skills.plugins.previewScriptAllow",
+ "skills.plugins.previewScriptDeny",
+ "skills.plugins.previewScriptPromptBody",
+ "skills.plugins.previewScriptPromptRevokeHint",
+ "skills.plugins.previewScriptPromptRisk",
+ "skills.plugins.previewScriptPromptTitle",
+ "skills.plugins.previewScriptRevoke",
+ "skills.plugins.previewScriptRevoked",
"skills.plugins.serverStates.app_not_running",
"skills.plugins.serverStates.connected",
"skills.plugins.serverStates.endpoint_unavailable",