The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): a preview-script revoke storage refuses still binds
Tekniume22d823b548e
diff --git a/apps/desktop/src/app/capabilities/plugins/plugin-page-access.tsx b/apps/desktop/src/app/capabilities/plugins/plugin-page-access.tsxindex c40894de1f9..46285673f9e 100644--- a/apps/desktop/src/app/capabilities/plugins/plugin-page-access.tsx+++ b/apps/desktop/src/app/capabilities/plugins/plugin-page-access.tsx@@ -49,8 +49,11 @@ export function PluginPageAccess({ plugin, pluginName }: PluginPageAccessProps)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) })+ if (revokePreviewScript(pluginId, origin)) {+ notify({ kind: 'info', message: copy.previewScriptRevoked(pluginName, origin) })+ } else {+ notify({ kind: 'error', message: copy.previewScriptRevokeUnsaved(pluginName, origin) })+ }}}type="button">diff --git a/apps/desktop/src/contrib/plugin-preview.test.ts b/apps/desktop/src/contrib/plugin-preview.test.tsindex 8058fd7aeb1..e1c9202aa3a 100644--- a/apps/desktop/src/contrib/plugin-preview.test.ts+++ b/apps/desktop/src/contrib/plugin-preview.test.ts@@ -1,4 +1,4 @@-import { afterEach, beforeEach, describe, expect, it } from 'vitest'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { registerPreviewScriptRunner } from '@/app/chat/right-rail/preview-script-runner'import { $rightRailActiveTabId } from '@/store/layout'@@ -221,6 +221,26 @@ describe('ctx.preview.executeJavaScript', () => {).resolves.toBe(true)})+ it("a revoke that storage refuses to save still binds this window and isn't shown as done", async () => {+ openPage()+ const { ctx, id } = pluginWith([CAPABILITY])++ grantPreviewScript(id, 'https://mail.example.com')++ const setItem = vi.spyOn(window.localStorage, 'setItem').mockImplementation(() => {+ throw new DOMException('quota', 'QuotaExceededError')+ })++ expect(revokePreviewScript(id, 'https://mail.example.com')).toBe(false)+ setItem.mockRestore()++ // The settings list shows what is actually saved, and the call asks again.+ expect($previewScriptGrants.get()[id]).toEqual(['https://mail.example.com'])+ void ctx.preview.executeJavaScript('document.title').catch(() => {})+ await expect.poll(() => $previewScriptConsentQueue.get().length).toBe(1)+ expect(userCodeRuns()).toBe(0)+ })+it('rejects when no preview page is open', async () => {const { ctx } = pluginWith([CAPABILITY])diff --git a/apps/desktop/src/i18n/ar_plugin_preview_access.ts b/apps/desktop/src/i18n/ar_plugin_preview_access.tsindex 5f680ea1bd0..dd8b6a61164 100644--- a/apps/desktop/src/i18n/ar_plugin_preview_access.ts+++ b/apps/desktop/src/i18n/ar_plugin_preview_access.ts@@ -12,5 +12,7 @@ export const arPluginPreviewAccess: PluginPreviewAccessTranslations = {previewScriptAccessLabel: 'نصوص الصفحة',previewScriptAccessNone: 'يسأل قبل تشغيل النصوص البرمجية على أي صفحة',previewScriptRevoke: (origin: string) => `إلغاء الوصول إلى ${origin}`,- previewScriptRevoked: (plugin: string, origin: string) => `لم يعد بإمكان ${plugin} تشغيل نصوص برمجية على ${origin}.`+ previewScriptRevoked: (plugin: string, origin: string) => `لم يعد بإمكان ${plugin} تشغيل نصوص برمجية على ${origin}.`,+ previewScriptRevokeUnsaved: (plugin: string, origin: string) =>+ `تعذّر حفظ هذا التغيير، لذا يسري فقط حتى إعادة تشغيل Hermes. ${plugin} محظور على ${origin} في الوقت الحالي.`}diff --git a/apps/desktop/src/i18n/de_plugin_preview_access.ts b/apps/desktop/src/i18n/de_plugin_preview_access.tsindex 15a480f38cd..4ef8fd40089 100644--- a/apps/desktop/src/i18n/de_plugin_preview_access.ts+++ b/apps/desktop/src/i18n/de_plugin_preview_access.ts@@ -12,5 +12,7 @@ export const dePluginPreviewAccess: PluginPreviewAccessTranslations = {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.`+ previewScriptRevoked: (plugin: string, origin: string) => `${plugin} kann keine Skripte mehr auf ${origin} ausführen.`,+ previewScriptRevokeUnsaved: (plugin: string, origin: string) =>+ `Die Änderung konnte nicht gespeichert werden und gilt nur bis zum Neustart von Hermes. ${plugin} ist auf ${origin} vorerst gesperrt.`}diff --git a/apps/desktop/src/i18n/en_plugin_preview_access.ts b/apps/desktop/src/i18n/en_plugin_preview_access.tsindex 087c5eb0f24..9c34f8f58a4 100644--- a/apps/desktop/src/i18n/en_plugin_preview_access.ts+++ b/apps/desktop/src/i18n/en_plugin_preview_access.ts@@ -12,5 +12,7 @@ export const enPluginPreviewAccess: PluginPreviewAccessTranslations = {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}.`+ previewScriptRevoked: (plugin: string, origin: string) => `${plugin} can no longer run scripts on ${origin}.`,+ previewScriptRevokeUnsaved: (plugin: string, origin: string) =>+ `Couldn't save that change, so it lasts only until Hermes restarts. ${plugin} is blocked on ${origin} for now.`}diff --git a/apps/desktop/src/i18n/es_plugin_preview_access.ts b/apps/desktop/src/i18n/es_plugin_preview_access.tsindex 586fa9ddeb4..0c4b97db21c 100644--- a/apps/desktop/src/i18n/es_plugin_preview_access.ts+++ b/apps/desktop/src/i18n/es_plugin_preview_access.ts@@ -12,5 +12,7 @@ export const esPluginPreviewAccess: PluginPreviewAccessTranslations = {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}.`+ previewScriptRevoked: (plugin: string, origin: string) => `${plugin} ya no puede ejecutar scripts en ${origin}.`,+ previewScriptRevokeUnsaved: (plugin: string, origin: string) =>+ `No se pudo guardar el cambio, así que solo dura hasta que Hermes se reinicie. ${plugin} queda bloqueado en ${origin} por ahora.`}diff --git a/apps/desktop/src/i18n/fr_plugin_preview_access.ts b/apps/desktop/src/i18n/fr_plugin_preview_access.tsindex 20f1264c9cc..1edd204aa6b 100644--- a/apps/desktop/src/i18n/fr_plugin_preview_access.ts+++ b/apps/desktop/src/i18n/fr_plugin_preview_access.ts@@ -12,5 +12,7 @@ export const frPluginPreviewAccess: PluginPreviewAccessTranslations = {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}.`+ previewScriptRevoked: (plugin: string, origin: string) => `${plugin} ne peut plus exécuter de scripts sur ${origin}.`,+ previewScriptRevokeUnsaved: (plugin: string, origin: string) =>+ `Impossible d’enregistrer la modification : elle ne vaut que jusqu’au redémarrage de Hermes. ${plugin} est bloqué sur ${origin} pour l’instant.`}diff --git a/apps/desktop/src/i18n/ja_plugin_preview_access.ts b/apps/desktop/src/i18n/ja_plugin_preview_access.tsindex cf712482b55..196b2552693 100644--- a/apps/desktop/src/i18n/ja_plugin_preview_access.ts+++ b/apps/desktop/src/i18n/ja_plugin_preview_access.ts@@ -12,5 +12,7 @@ export const jaPluginPreviewAccess: PluginPreviewAccessTranslations = {previewScriptAccessLabel: 'ページスクリプト',previewScriptAccessNone: 'ページでスクリプトを実行する前に確認します',previewScriptRevoke: (origin: string) => `${origin} へのアクセスを取り消す`,- previewScriptRevoked: (plugin: string, origin: string) => `${plugin} は ${origin} でスクリプトを実行できなくなりました。`+ previewScriptRevoked: (plugin: string, origin: string) => `${plugin} は ${origin} でスクリプトを実行できなくなりました。`,+ previewScriptRevokeUnsaved: (plugin: string, origin: string) =>+ `変更を保存できなかったため、Hermes を再起動するまでの一時的な設定です。現在 ${plugin} は ${origin} でブロックされています。`}diff --git a/apps/desktop/src/i18n/ru_plugin_preview_access.ts b/apps/desktop/src/i18n/ru_plugin_preview_access.tsindex 9061f0fb624..9e09328d508 100644--- a/apps/desktop/src/i18n/ru_plugin_preview_access.ts+++ b/apps/desktop/src/i18n/ru_plugin_preview_access.ts@@ -12,5 +12,7 @@ export const ruPluginPreviewAccess: PluginPreviewAccessTranslations = {previewScriptAccessLabel: 'Скрипты страниц',previewScriptAccessNone: 'Спрашивает перед запуском скриптов на странице',previewScriptRevoke: (origin: string) => `Отозвать доступ к ${origin}`,- previewScriptRevoked: (plugin: string, origin: string) => `${plugin} больше не может запускать скрипты на ${origin}.`+ previewScriptRevoked: (plugin: string, origin: string) => `${plugin} больше не может запускать скрипты на ${origin}.`,+ previewScriptRevokeUnsaved: (plugin: string, origin: string) =>+ `Не удалось сохранить изменение, поэтому оно действует только до перезапуска Hermes. Пока ${plugin} заблокирован на ${origin}.`}diff --git a/apps/desktop/src/i18n/types_plugin_preview_access.ts b/apps/desktop/src/i18n/types_plugin_preview_access.tsindex 790f3e43846..cfdd6d9e169 100644--- a/apps/desktop/src/i18n/types_plugin_preview_access.ts+++ b/apps/desktop/src/i18n/types_plugin_preview_access.ts@@ -11,4 +11,5 @@ export interface PluginPreviewAccessTranslations {previewScriptAccessNone: stringpreviewScriptRevoke: (origin: string) => stringpreviewScriptRevoked: (plugin: string, origin: string) => string+ previewScriptRevokeUnsaved: (plugin: string, origin: string) => string}diff --git a/apps/desktop/src/i18n/zh-hant_plugin_preview_access.ts b/apps/desktop/src/i18n/zh-hant_plugin_preview_access.tsindex 2ae6ce9722c..7169d8c39e3 100644--- a/apps/desktop/src/i18n/zh-hant_plugin_preview_access.ts+++ b/apps/desktop/src/i18n/zh-hant_plugin_preview_access.ts@@ -12,5 +12,7 @@ export const zhHantPluginPreviewAccess: PluginPreviewAccessTranslations = {previewScriptAccessLabel: '頁面指令碼',previewScriptAccessNone: '在頁面上執行指令碼前會先詢問',previewScriptRevoke: (origin: string) => `撤銷對 ${origin} 的存取`,- previewScriptRevoked: (plugin: string, origin: string) => `${plugin} 不能再於 ${origin} 上執行指令碼。`+ previewScriptRevoked: (plugin: string, origin: string) => `${plugin} 不能再於 ${origin} 上執行指令碼。`,+ previewScriptRevokeUnsaved: (plugin: string, origin: string) =>+ `無法儲存此變更,因此它僅在 Hermes 重新啟動前有效。目前 ${plugin} 在 ${origin} 上被封鎖。`}diff --git a/apps/desktop/src/i18n/zh_plugin_preview_access.ts b/apps/desktop/src/i18n/zh_plugin_preview_access.tsindex d1813443a41..ccb24c50917 100644--- a/apps/desktop/src/i18n/zh_plugin_preview_access.ts+++ b/apps/desktop/src/i18n/zh_plugin_preview_access.ts@@ -12,5 +12,7 @@ export const zhPluginPreviewAccess: PluginPreviewAccessTranslations = {previewScriptAccessLabel: '页面脚本',previewScriptAccessNone: '在页面上运行脚本前会先询问',previewScriptRevoke: (origin: string) => `撤销对 ${origin} 的访问`,- previewScriptRevoked: (plugin: string, origin: string) => `${plugin} 不能再在 ${origin} 上运行脚本。`+ previewScriptRevoked: (plugin: string, origin: string) => `${plugin} 不能再在 ${origin} 上运行脚本。`,+ previewScriptRevokeUnsaved: (plugin: string, origin: string) =>+ `无法保存此更改,因此它仅在 Hermes 重启前有效。目前 ${plugin} 在 ${origin} 上被阻止。`}diff --git a/apps/desktop/src/store/plugin-preview-grants.ts b/apps/desktop/src/store/plugin-preview-grants.tsindex fb559ba665b..1efc7897fc8 100644--- a/apps/desktop/src/store/plugin-preview-grants.ts+++ b/apps/desktop/src/store/plugin-preview-grants.ts@@ -17,6 +17,8 @@ import { readKey, writeKey } from '@/lib/storage'* app-level, not per profile.*/+const pairKey = (pluginId: string, origin: string) => `${pluginId}\n${origin}`+/** pluginId -> origins the user allowed. */export type PreviewScriptGrants = Record<string, string[]>@@ -60,11 +62,23 @@ function readStoredGrants(): PreviewScriptGrants {export const $previewScriptGrants = atom<PreviewScriptGrants>(readStoredGrants())-function commitGrants(next: PreviewScriptGrants): void {+/** Persist `next` and mirror what storage actually holds afterwards (writes+ * are best-effort: a full or blocked store keeps the old record). Returns+ * whether `next` was saved. */+function commitGrants(next: PreviewScriptGrants): boolean {writeKey(GRANTS_KEY, JSON.stringify(next))- $previewScriptGrants.set(next)+ const saved = readStoredGrants()++ $previewScriptGrants.set(saved)++ return JSON.stringify(saved) === JSON.stringify(next)}+/** Revokes the user made in this window that storage refused to save. They+ * still bind here (the call asks again), so a failed write never leaves a+ * revoked plugin running silently. */+const unsavedRevokes = new Set<string>()+if (typeof window !== 'undefined') {window.addEventListener('storage', event => {if (event.key === GRANTS_KEY || event.key === null) {@@ -76,7 +90,6 @@ if (typeof window !== 'undefined') {/** "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@@ -92,22 +105,33 @@ export function isGrantableOrigin(origin: string): boolean {}export function hasPreviewScriptGrant(pluginId: string, origin: string): boolean {- return readStoredGrants()[pluginId]?.includes(origin) ?? false+ return (+ !unsavedRevokes.has(pairKey(pluginId, origin)) && (readStoredGrants()[pluginId]?.includes(origin) ?? false)+ )}export function grantPreviewScript(pluginId: string, origin: string): void {const grants = readStoredGrants()const current = grants[pluginId] ?? []+ unsavedRevokes.delete(pairKey(pluginId, origin))commitGrants(current.includes(origin) ? grants : { ...grants, [pluginId]: [...current, origin] })}-/** Revoke one origin, or every origin for the plugin when omitted. */-export function revokePreviewScript(pluginId: string, origin?: string): void {+/** Revoke one origin, or every origin for the plugin when omitted. Returns+ * false when storage refused the change (it still binds this window). */+export function revokePreviewScript(pluginId: string, origin?: string): boolean {const { [pluginId]: current = [], ...rest } = readStoredGrants()- const kept = origin === undefined ? [] : current.filter(entry => entry !== origin)+ const revoked = origin === undefined ? current : current.filter(entry => entry === origin)+ const kept = current.filter(entry => !revoked.includes(entry))++ if (commitGrants(kept.length > 0 ? { ...rest, [pluginId]: kept } : rest)) {+ return true+ }++ revoked.forEach(entry => unsavedRevokes.add(pairKey(pluginId, entry)))- commitGrants(kept.length > 0 ? { ...rest, [pluginId]: kept } : rest)+ return false}export interface PreviewScriptConsentRequest {diff --git a/locales/_keys.desktop.json b/locales/_keys.desktop.jsonindex bfe18a443ff..c47003fed7b 100644--- a/locales/_keys.desktop.json+++ b/locales/_keys.desktop.json@@ -4857,6 +4857,7 @@"skills.plugins.previewScriptPromptRisk","skills.plugins.previewScriptPromptTitle","skills.plugins.previewScriptRevoke",+ "skills.plugins.previewScriptRevokeUnsaved","skills.plugins.previewScriptRevoked","skills.plugins.serverStates.app_not_running","skills.plugins.serverStates.connected",