AI-native design editor. Open-source Figma alternative.
feat: notify when an AI agent needs you, finishes, or fails (#1623)
Danila Poyarkov7fc52ab76b7e
diff --git a/bun.lock b/bun.lockindex 642101ca3..e6747831d 100644--- a/bun.lock+++ b/bun.lock@@ -54,6 +54,7 @@"@tauri-apps/plugin-clipboard-manager": "^2.4.1","@tauri-apps/plugin-dialog": "^2.8.1","@tauri-apps/plugin-fs": "^2.6.0",+ "@tauri-apps/plugin-notification": "^2.8.0","@tauri-apps/plugin-opener": "^2.7.0","@tauri-apps/plugin-os": "^2.3.2","@tauri-apps/plugin-process": "^2.3.1",@@ -81,6 +82,10 @@"js-base64": "^3.9.3","jspdf": "^4.2.1","lib0": "^0.2.117",+ "mdast-util-from-markdown": "^2.0.3",+ "mdast-util-gfm": "^3",+ "mdast-util-to-string": "^4.0.0",+ "micromark-extension-gfm": "^3","motion-v": "^2.5.2","nanostores": "^1.5.4","partial-json": "^0.1.7",@@ -133,6 +138,7 @@"@tauri-apps/cli": "2.12.1","@types/bun": "^1.3.14","@types/culori": "^4.0.1",+ "@types/mdast": "^4.0.4","@types/node": "^25.9.9","@types/qrcode": "1.5.5","@types/ws": "^8.18.1",@@ -160,7 +166,6 @@"knip": "6.20.0","kysely-pglite-dialect": "1.3.1","mdast": "^3.0.0",- "mdast-util-from-markdown": "^2.0.3","mitata": "^1.0.34","oxfmt": "^0.75.0","oxlint": "1.90.0",@@ -2375,6 +2380,8 @@"@tauri-apps/plugin-fs": ["@tauri-apps/[email protected]", "", { "dependencies": { "@tauri-apps/api": "^2.12.0" } }, "sha512-MhBAZ4rryd+h9fijd/GWDfArqiAeGI0ZNduV4wuRyUVI6wDZ+oDBY7atqtoXKDwlTUVSvpvmWJAY0ehQd/v6Uw=="],+ "@tauri-apps/plugin-notification": ["@tauri-apps/[email protected]", "", { "dependencies": { "@tauri-apps/api": "^2.12.0" } }, "sha512-BB9Kk2emiNHyMjIQr3k/ye8RKD2RJeOPCjM5OZLF+4/pO6Kfjl9RtkX4hVCe1vqgbAx5HjHXjf0O8rtdW2F2dw=="],+"@tauri-apps/plugin-opener": ["@tauri-apps/[email protected]", "", { "dependencies": { "@tauri-apps/api": "^2.12.0" } }, "sha512-mBorYfVKh9Lt7s4ZFtKbMUTxBw+Y/sVmSlKCtkkoBgMTC/DIbt/kaPm67L/2djAUqDI1wbixy5OHHVmipjuGMw=="],"@tauri-apps/plugin-os": ["@tauri-apps/[email protected]", "", { "dependencies": { "@tauri-apps/api": "^2.8.0" } }, "sha512-n+nXWeuSeF9wcEsSPmRnBEGrRgOy6jjkSU+UVCOV8YUGKb2erhDOxis7IqRXiRVHhY8XMKks00BJ0OAdkpf6+A=="],@@ -3997,6 +4004,20 @@"micromark-extension-frontmatter": ["[email protected]", "", { "dependencies": { "fault": "^2.0.0", "micromark-util-character": "^2.0.0", "micromark-util-symbol": "^2.0.0", "micromark-util-types": "^2.0.0" } }, "sha512-C4AkuM3dA58cgZha7zVnuVxBhDsbttIMiytjgsM2XbHAB2faRVaHRle40558FBN+DJcrLNCoqG5mlrpdU4cRtg=="],+ "micromark-extension-gfm": ["[email protected]", "", { "dependencies": { "micromark-extension-gfm-autolink-literal": "^2.0.0", "micromark-extension-gfm-footnote": "^2.0.0", "micromark-extension-gfm-strikethrough": "^2.0.0", "micromark-extension-gfm-table": "^2.0.0", "micromark-extension-gfm-tagfilter": "^2.0.0", "micromark-extension-gfm-task-list-item": "^2.0.0", "micromark-util-combine-extensions": "^2.0.0", "micromark-util-types": "^2.0.0" } }, "sha512-vsKArQsicm7t0z2GugkCKtZehqUm31oeGBV/KVSorWSy8ZlNAv7ytjFhvaryUiCUJYqs+NoE6AFhpQvBTM6Q4w=="],++ "micromark-extension-gfm-autolink-literal": ["[email protected]", "", { "dependencies": { "micromark-util-character": "^2.0.0", "micromark-util-sanitize-uri": "^2.0.0", "micromark-util-symbol": "^2.0.0", "micromark-util-types": "^2.0.0" } }, "sha512-oOg7knzhicgQ3t4QCjCWgTmfNhvQbDDnJeVu9v81r7NltNCVmhPy1fJRX27pISafdjL+SVc4d3l48Gb6pbRypw=="],++ "micromark-extension-gfm-footnote": ["[email protected]", "", { "dependencies": { "devlop": "^1.0.0", "micromark-core-commonmark": "^2.0.0", "micromark-factory-space": "^2.0.0", "micromark-util-character": "^2.0.0", "micromark-util-normalize-identifier": "^2.0.0", "micromark-util-sanitize-uri": "^2.0.0", "micromark-util-symbol": "^2.0.0", "micromark-util-types": "^2.0.0" } }, "sha512-/yPhxI1ntnDNsiHtzLKYnE3vf9JZ6cAisqVDauhp4CEHxlb4uoOTxOCJ+9s51bIB8U1N1FJ1RXOKTIlD5B/gqw=="],++ "micromark-extension-gfm-strikethrough": ["[email protected]", "", { "dependencies": { "devlop": "^1.0.0", "micromark-util-chunked": "^2.0.0", "micromark-util-classify-character": "^2.0.0", "micromark-util-resolve-all": "^2.0.0", "micromark-util-symbol": "^2.0.0", "micromark-util-types": "^2.0.0" } }, "sha512-ADVjpOOkjz1hhkZLlBiYA9cR2Anf8F4HqZUO6e5eDcPQd0Txw5fxLzzxnEkSkfnD0wziSGiv7sYhk/ktvbf1uw=="],++ "micromark-extension-gfm-table": ["[email protected]", "", { "dependencies": { "devlop": "^1.0.0", "micromark-factory-space": "^2.0.0", "micromark-util-character": "^2.0.0", "micromark-util-symbol": "^2.0.0", "micromark-util-types": "^2.0.0" } }, "sha512-pRzm4kDTu0MjlmBkxmS9yYhw60nncfcEwu9NNdPFSQEFXS95ZKyIIyTSHu/o3ReBUrLKYEq+7YaXCRn/bPB4MA=="],++ "micromark-extension-gfm-tagfilter": ["[email protected]", "", { "dependencies": { "micromark-util-types": "^2.0.0" } }, "sha512-xHlTOmuCSotIA8TW1mDIM6X2O1SiX5P9IuDtqGonFhEK0qgRI4yeC6vMxEV2dgyr2TiD+2PQ10o+cOhdVAcwfg=="],++ "micromark-extension-gfm-task-list-item": ["[email protected]", "", { "dependencies": { "devlop": "^1.0.0", "micromark-factory-space": "^2.0.0", "micromark-util-character": "^2.0.0", "micromark-util-symbol": "^2.0.0", "micromark-util-types": "^2.0.0" } }, "sha512-qIBZhqxqI6fjLDYFTBIa4eivDMnP+OZqsNwmQ3xNLE4Cxwc+zfQEfbs6tzAo2Hjq+bh6q5F+Z8/cksrLFYWQQw=="],+"micromark-factory-destination": ["[email protected]", "", { "dependencies": { "micromark-util-character": "^2.0.0", "micromark-util-symbol": "^2.0.0", "micromark-util-types": "^2.0.0" } }, "sha512-Xe6rDdJlkmbFRExpTOmRj9N3MaWmbAgdpSrBQvCFqhezUn4AHqJHbaEnfbVYYiexVSs//tqOdY/DxhjdCiJnIA=="],"micromark-factory-label": ["[email protected]", "", { "dependencies": { "devlop": "^1.0.0", "micromark-util-character": "^2.0.0", "micromark-util-symbol": "^2.0.0", "micromark-util-types": "^2.0.0" } }, "sha512-VFMekyQExqIW7xIChcXn4ok29YE3rnuyveW3wZQWWqF4Nv9Wk5rgJ99KzPvHjkmPXF93FXIbBp6YdW3t71/7Vg=="],diff --git a/changes/1623/added.md b/changes/1623/added.mdnew file mode 100644index 000000000..9d36b2704--- /dev/null+++ b/changes/1623/added.md@@ -0,0 +1 @@+- OpenPencil sends a system notification when an AI agent waits for your permission while OpenPencil is in the background or shows another document, and can also notify when a reply finishes or fails; clicking it opens that document's chat. Choose them under Settings › Notifications.diff --git a/desktop/Cargo.lock b/desktop/Cargo.lockindex c5a7409bd..640e60574 100644--- a/desktop/Cargo.lock+++ b/desktop/Cargo.lock@@ -2705,6 +2705,20 @@ version = "0.1.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154"+[[package]]+name = "mac-notification-sys"+version = "0.6.15"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "fd604973958ddcc11b561193c0fb96ba146506ef2f231ef2e7c35fd2cbc9beca"+dependencies = [+ "cc",+ "log",+ "objc2",+ "objc2-foundation",+ "time",+ "uuid",+]+[[package]]name = "markup5ever"version = "0.39.0"@@ -2899,6 +2913,20 @@ dependencies = ["walkdir",]+[[package]]+name = "notify-rust"+version = "4.18.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4587364a9a0074333429b3df75a30a205340c56a536ca3eb6ca0e59b87bbf8af"+dependencies = [+ "futures-lite",+ "log",+ "mac-notification-sys",+ "serde",+ "tauri-winrt-notification",+ "zbus",+]+[[package]]name = "notify-types"version = "2.1.0"@@ -3302,6 +3330,7 @@ dependencies = ["tauri-plugin-deep-link","tauri-plugin-dialog","tauri-plugin-fs",+ "tauri-plugin-notification","tauri-plugin-opener","tauri-plugin-os","tauri-plugin-process",@@ -5098,6 +5127,26 @@ dependencies = ["url",]+[[package]]+name = "tauri-plugin-notification"+version = "2.8.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5bc6c194a95a535abdfbe3bc1af9a43935b8b9b29c216b8e71af8b59132703cf"+dependencies = [+ "log",+ "notify-rust",+ "rand",+ "serde",+ "serde_json",+ "serde_repr",+ "tauri",+ "tauri-plugin",+ "thiserror 2.0.20",+ "time",+ "url",+ "zbus",+]+[[package]]name = "tauri-plugin-opener"version = "2.7.0"@@ -5352,6 +5401,17 @@ dependencies = ["toml 1.1.4+spec-1.1.0",]+[[package]]+name = "tauri-winrt-notification"+version = "0.8.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f37a6c354fd28fc9e322ed9bd47e3959576dad28c9d58ea1cf888cce1c7ccb36"+dependencies = [+ "thiserror 2.0.20",+ "windows 0.62.2",+ "windows-version",+]+[[package]]name = "tempfile"version = "3.27.0"diff --git a/desktop/Cargo.toml b/desktop/Cargo.tomlindex 30b391c82..c79fbda60 100644--- a/desktop/Cargo.toml+++ b/desktop/Cargo.toml@@ -35,6 +35,7 @@ tokio = { version = "1", features = ["sync"] }tauri-plugin-dialog = "2.6.0"tauri-plugin-fs = { version = "2.4.5", features = ["watch"] }tauri-plugin-shell = "2"+tauri-plugin-notification = "2.8.0"zstd = "0.13"zip = { version = "2", default-features = false }which = "7.0.3"diff --git a/desktop/capabilities/default.json b/desktop/capabilities/default.jsonindex 5bb102f50..5ba942c95 100644--- a/desktop/capabilities/default.json+++ b/desktop/capabilities/default.json@@ -10,6 +10,7 @@"core:window:allow-set-focus","core:window:allow-unminimize","opener:default",+ "notification:default","dialog:default","dialog:allow-save","dialog:allow-open",diff --git a/desktop/src/lib.rs b/desktop/src/lib.rsindex 08796551d..a9810389c 100644--- a/desktop/src/lib.rs+++ b/desktop/src/lib.rs@@ -107,6 +107,7 @@ pub fn run() {.plugin(tauri_plugin_clipboard_manager::init()).plugin(tauri_plugin_fs::init()).plugin(tauri_plugin_shell::init())+ .plugin(tauri_plugin_notification::init()).plugin(tauri_plugin_updater::Builder::new().build()).plugin(tauri_plugin_process::init()).plugin(tauri_plugin_os::init())diff --git a/package.json b/package.jsonindex af465aa47..b9232edf5 100644--- a/package.json+++ b/package.json@@ -172,6 +172,7 @@"@tauri-apps/plugin-clipboard-manager": "^2.4.1","@tauri-apps/plugin-dialog": "^2.8.1","@tauri-apps/plugin-fs": "^2.6.0",+ "@tauri-apps/plugin-notification": "^2.8.0","@tauri-apps/plugin-opener": "^2.7.0","@tauri-apps/plugin-os": "^2.3.2","@tauri-apps/plugin-process": "^2.3.1",@@ -199,6 +200,10 @@"js-base64": "^3.9.3","jspdf": "^4.2.1","lib0": "^0.2.117",+ "mdast-util-from-markdown": "^2.0.3",+ "mdast-util-gfm": "^3",+ "mdast-util-to-string": "^4.0.0",+ "micromark-extension-gfm": "^3","motion-v": "^2.5.2","nanostores": "^1.5.4","partial-json": "^0.1.7",@@ -251,6 +256,7 @@"@tauri-apps/cli": "2.12.1","@types/bun": "^1.3.14","@types/culori": "^4.0.1",+ "@types/mdast": "^4.0.4","@types/node": "^25.9.9","@types/qrcode": "1.5.5","@types/ws": "^8.18.1",@@ -278,7 +284,6 @@"knip": "6.20.0","kysely-pglite-dialect": "1.3.1","mdast": "^3.0.0",- "mdast-util-from-markdown": "^2.0.3","mitata": "^1.0.34","oxfmt": "^0.75.0","oxlint": "1.90.0",diff --git a/packages/docs/development/ai-chat.md b/packages/docs/development/ai-chat.mdindex 02ecfb763..bf0841537 100644--- a/packages/docs/development/ai-chat.md+++ b/packages/docs/development/ai-chat.md@@ -60,6 +60,8 @@ When the chat's own `onFinish` reports a reply that was stopped, failed, or cutDiagnostics record `chat.completed`, `chat.stopped`, or `chat.failed`.+A reply that finished or failed on its own, rather than one you stopped or one cut off by a disconnect, also reaches `notifyReplyEnded` (`chat/notifications.ts`). It quotes the last text part as plain text and sends it through the shared notification service (`shell/notifications/`), which sends nothing while you are looking at that document. An ACP agent's permission request that is still unanswered after `AGENT_INPUT_NOTIFY_DELAY_MS` notifies through the same service, by the `onUnanswered` callback of `requestPermissionFromUser`.+`reply/undo.ts` records the reply's turn (`reply/turns.ts`) once the run settles, so an edit landing after Stop belongs to the reply.## An ACP replydiff --git a/packages/docs/programmable/ai-chat.md b/packages/docs/programmable/ai-chat.mdindex cfff310e8..ca5c6eab6 100644--- a/packages/docs/programmable/ai-chat.md+++ b/packages/docs/programmable/ai-chat.md@@ -122,6 +122,10 @@ Your next message tells the assistant which of its edits you undid or redid, soWith **Follow agents** on, the crosshair button at the top of the AI panel, your view follows the assistant while it works, including to another page when it edits layers there. Following ends when the reply finishes, is stopped, or fails. Clicking, scrolling, zooming, switching pages, or Escape stops following yourself.+## Notifications++When an agent asks for permission and you have not answered for a few seconds, OpenPencil sends a system notification, so you can work in another app while it runs. **Settings → Notifications** also turns on notifications when a reply finishes or fails. They are sent only while OpenPencil is in the background or shows another document, and clicking one opens that document's chat. In the browser, click **Allow notifications** there first; the desktop app follows your system's notification settings.+## Example Prompts- "Create a card with a title, description, and a blue button"diff --git a/packages/vue/src/i18n/locales/de/ai.json b/packages/vue/src/i18n/locales/de/ai.jsonindex 57c646b07..f99751fa8 100644--- a/packages/vue/src/i18n/locales/de/ai.json+++ b/packages/vue/src/i18n/locales/de/ai.json@@ -213,6 +213,21 @@"chatActions": "Unterhaltungsaktionen","continueChat": "Fortfahren","chatSettings": "Chat",+ "notificationsHint": "Nur während OpenPencil im Hintergrund ist oder ein anderes Dokument zeigt.",+ "notifyNeedsInput": "Ein Agent braucht dich",+ "notifyNeedsInputHint": "Eine Berechtigungsanfrage wartet seit einigen Sekunden auf eine Antwort.",+ "notifyFinished": "Eine Antwort ist fertig",+ "notifyFailed": "Eine Antwort ist fehlgeschlagen",+ "notificationsAllow": "Mitteilungen erlauben",+ "notificationsAllowHint": "Dein Browser fragt einmal, ob OpenPencil Mitteilungen zeigen darf.",+ "notificationsBlocked": "Mitteilungen sind für diese Website blockiert. Erlaube sie in den Website-Einstellungen des Browsers.",+ "notificationsUnsupported": "Dieser Browser kann keine Mitteilungen zeigen.",+ "notificationsSystemHint": "Wenn keine erscheinen, erlaube OpenPencil in den Mitteilungseinstellungen deines Systems.",+ "notifyTitle": "{agent} · {document}",+ "notifyPermission": "Bittet um Erlaubnis.",+ "notifyPermissionAction": "Bittet um Erlaubnis: {action}",+ "notifyReplyFinished": "Die KI-Antwort ist fertig.",+ "notifyReplyFailed": "Die KI-Antwort wurde mit einem Fehler beendet.","reasoningDisplay": "Anzeige der Überlegungen","reasoningCollapsed": "Standardmäßig eingeklappt","reasoningWhileThinking": "Beim Nachdenken ausklappen",diff --git a/packages/vue/src/i18n/locales/es/ai.json b/packages/vue/src/i18n/locales/es/ai.jsonindex 39b3990a0..dbb1d07cf 100644--- a/packages/vue/src/i18n/locales/es/ai.json+++ b/packages/vue/src/i18n/locales/es/ai.json@@ -213,6 +213,21 @@"chatActions": "Acciones de la conversación","continueChat": "Continuar","chatSettings": "Chat",+ "notificationsHint": "Solo mientras OpenPencil está en segundo plano o muestra otro documento.",+ "notifyNeedsInput": "Un agente te necesita",+ "notifyNeedsInputHint": "Una solicitud de permiso lleva unos segundos sin respuesta.",+ "notifyFinished": "Una respuesta terminó",+ "notifyFailed": "Una respuesta falló",+ "notificationsAllow": "Permitir notificaciones",+ "notificationsAllowHint": "El navegador pregunta una vez si OpenPencil puede mostrar notificaciones.",+ "notificationsBlocked": "Las notificaciones están bloqueadas para este sitio. Permítelas en la configuración del sitio del navegador.",+ "notificationsUnsupported": "Este navegador no puede mostrar notificaciones.",+ "notificationsSystemHint": "Si no aparece ninguna, permite OpenPencil en la configuración de notificaciones del sistema.",+ "notifyTitle": "{agent} · {document}",+ "notifyPermission": "Pide permiso.",+ "notifyPermissionAction": "Pide permiso: {action}",+ "notifyReplyFinished": "La respuesta de la IA terminó.",+ "notifyReplyFailed": "La respuesta de la IA se detuvo con un error.","reasoningDisplay": "Visualización del razonamiento","reasoningCollapsed": "Contraído por defecto","reasoningWhileThinking": "Expandir al razonar",diff --git a/packages/vue/src/i18n/locales/fr/ai.json b/packages/vue/src/i18n/locales/fr/ai.jsonindex ff07fe7c7..58981d4fa 100644--- a/packages/vue/src/i18n/locales/fr/ai.json+++ b/packages/vue/src/i18n/locales/fr/ai.json@@ -213,6 +213,21 @@"chatActions": "Actions de la discussion","continueChat": "Continuer","chatSettings": "Discussion",+ "notificationsHint": "Uniquement quand OpenPencil est en arrière-plan ou affiche un autre document.",+ "notifyNeedsInput": "Un agent a besoin de vous",+ "notifyNeedsInputHint": "Une demande d’autorisation attend une réponse depuis quelques secondes.",+ "notifyFinished": "Une réponse est terminée",+ "notifyFailed": "Une réponse a échoué",+ "notificationsAllow": "Autoriser les notifications",+ "notificationsAllowHint": "Le navigateur demande une fois si OpenPencil peut afficher des notifications.",+ "notificationsBlocked": "Les notifications sont bloquées pour ce site. Autorisez-les dans les paramètres du site du navigateur.",+ "notificationsUnsupported": "Ce navigateur ne peut pas afficher de notifications.",+ "notificationsSystemHint": "Si rien n’apparaît, autorisez OpenPencil dans les réglages de notifications du système.",+ "notifyTitle": "{agent} · {document}",+ "notifyPermission": "Demande une autorisation.",+ "notifyPermissionAction": "Demande une autorisation : {action}",+ "notifyReplyFinished": "La réponse de l’IA est terminée.",+ "notifyReplyFailed": "La réponse de l’IA s’est arrêtée sur une erreur.","reasoningDisplay": "Affichage du raisonnement","reasoningCollapsed": "Replié par défaut","reasoningWhileThinking": "Déplier pendant le raisonnement",diff --git a/packages/vue/src/i18n/locales/it/ai.json b/packages/vue/src/i18n/locales/it/ai.jsonindex 467bbbf7f..90525a766 100644--- a/packages/vue/src/i18n/locales/it/ai.json+++ b/packages/vue/src/i18n/locales/it/ai.json@@ -213,6 +213,21 @@"chatActions": "Azioni della conversazione","continueChat": "Continua","chatSettings": "Chat",+ "notificationsHint": "Solo mentre OpenPencil è in background o mostra un altro documento.",+ "notifyNeedsInput": "Un agente ha bisogno di te",+ "notifyNeedsInputHint": "Una richiesta di autorizzazione attende una risposta da qualche secondo.",+ "notifyFinished": "Una risposta è terminata",+ "notifyFailed": "Una risposta non è riuscita",+ "notificationsAllow": "Consenti notifiche",+ "notificationsAllowHint": "Il browser chiede una volta se OpenPencil può mostrare notifiche.",+ "notificationsBlocked": "Le notifiche sono bloccate per questo sito. Consentile nelle impostazioni del sito del browser.",+ "notificationsUnsupported": "Questo browser non può mostrare notifiche.",+ "notificationsSystemHint": "Se non ne compare nessuna, consenti OpenPencil nelle impostazioni di notifica del sistema.",+ "notifyTitle": "{agent} · {document}",+ "notifyPermission": "Chiede un’autorizzazione.",+ "notifyPermissionAction": "Chiede un’autorizzazione: {action}",+ "notifyReplyFinished": "La risposta dell’IA è terminata.",+ "notifyReplyFailed": "La risposta dell’IA si è interrotta con un errore.","reasoningDisplay": "Visualizzazione del ragionamento","reasoningCollapsed": "Compresso per impostazione predefinita","reasoningWhileThinking": "Espandi durante il ragionamento",diff --git a/packages/vue/src/i18n/locales/ja/ai.json b/packages/vue/src/i18n/locales/ja/ai.jsonindex e49df77c5..0e3a0d8d2 100644--- a/packages/vue/src/i18n/locales/ja/ai.json+++ b/packages/vue/src/i18n/locales/ja/ai.json@@ -213,6 +213,21 @@"chatActions": "会話の操作","continueChat": "続ける","chatSettings": "チャット",+ "notificationsHint": "OpenPencil がバックグラウンドにあるか、別のドキュメントを表示しているときだけ送ります。",+ "notifyNeedsInput": "エージェントが応答を待っているとき",+ "notifyNeedsInputHint": "許可のリクエストが数秒間応答されていないとき。",+ "notifyFinished": "返信が完了したとき",+ "notifyFailed": "返信が失敗したとき",+ "notificationsAllow": "通知を許可",+ "notificationsAllowHint": "OpenPencil に通知を許可するか、ブラウザが一度だけ確認します。",+ "notificationsBlocked": "このサイトの通知はブロックされています。ブラウザのサイト設定で許可してください。",+ "notificationsUnsupported": "このブラウザは通知を表示できません。",+ "notificationsSystemHint": "表示されない場合は、システムの通知設定で OpenPencil を許可してください。",+ "notifyTitle": "{agent} · {document}",+ "notifyPermission": "許可を求めています。",+ "notifyPermissionAction": "許可を求めています: {action}",+ "notifyReplyFinished": "AI の返信が完了しました。",+ "notifyReplyFailed": "AI の返信がエラーで停止しました。","reasoningDisplay": "推論の表示","reasoningCollapsed": "既定で折りたたむ","reasoningWhileThinking": "思考中に展開",diff --git a/packages/vue/src/i18n/locales/pl/ai.json b/packages/vue/src/i18n/locales/pl/ai.jsonindex 08e06f18f..292535b40 100644--- a/packages/vue/src/i18n/locales/pl/ai.json+++ b/packages/vue/src/i18n/locales/pl/ai.json@@ -213,6 +213,21 @@"chatActions": "Działania rozmowy","continueChat": "Kontynuuj","chatSettings": "Czat",+ "notificationsHint": "Tylko gdy OpenPencil działa w tle lub pokazuje inny dokument.",+ "notifyNeedsInput": "Agent potrzebuje ciebie",+ "notifyNeedsInputHint": "Prośba o zgodę od kilku sekund czeka na odpowiedź.",+ "notifyFinished": "Odpowiedź jest gotowa",+ "notifyFailed": "Odpowiedź się nie powiodła",+ "notificationsAllow": "Zezwól na powiadomienia",+ "notificationsAllowHint": "Przeglądarka raz zapyta, czy OpenPencil może pokazywać powiadomienia.",+ "notificationsBlocked": "Powiadomienia są zablokowane dla tej witryny. Zezwól na nie w ustawieniach witryny w przeglądarce.",+ "notificationsUnsupported": "Ta przeglądarka nie może pokazywać powiadomień.",+ "notificationsSystemHint": "Jeśli żadne się nie pojawiają, zezwól OpenPencil w systemowych ustawieniach powiadomień.",+ "notifyTitle": "{agent} · {document}",+ "notifyPermission": "Prosi o zgodę.",+ "notifyPermissionAction": "Prosi o zgodę: {action}",+ "notifyReplyFinished": "Odpowiedź AI jest gotowa.",+ "notifyReplyFailed": "Odpowiedź AI zatrzymała się z błędem.","reasoningDisplay": "Wyświetlanie rozumowania","reasoningCollapsed": "Domyślnie zwinięte","reasoningWhileThinking": "Rozwijaj podczas rozumowania",diff --git a/packages/vue/src/i18n/locales/ru/ai.json b/packages/vue/src/i18n/locales/ru/ai.jsonindex 10c528bda..a41f6b2f5 100644--- a/packages/vue/src/i18n/locales/ru/ai.json+++ b/packages/vue/src/i18n/locales/ru/ai.json@@ -213,6 +213,21 @@"chatActions": "Действия с чатом","continueChat": "Продолжить","chatSettings": "Чат",+ "notificationsHint": "Только когда OpenPencil в фоне или показывает другой документ.",+ "notifyNeedsInput": "Агенту нужен ваш ответ",+ "notifyNeedsInputHint": "Запрос разрешения несколько секунд ждёт ответа.",+ "notifyFinished": "Ответ готов",+ "notifyFailed": "Ответ завершился ошибкой",+ "notificationsAllow": "Разрешить уведомления",+ "notificationsAllowHint": "Браузер один раз спросит, может ли OpenPencil показывать уведомления.",+ "notificationsBlocked": "Уведомления для этого сайта заблокированы. Разрешите их в настройках сайта в браузере.",+ "notificationsUnsupported": "Этот браузер не умеет показывать уведомления.",+ "notificationsSystemHint": "Если уведомления не появляются, разрешите их для OpenPencil в системных настройках уведомлений.",+ "notifyTitle": "{agent} · {document}",+ "notifyPermission": "Просит разрешения.",+ "notifyPermissionAction": "Просит разрешения: {action}",+ "notifyReplyFinished": "Ответ ИИ готов.",+ "notifyReplyFailed": "Ответ ИИ остановился с ошибкой.","reasoningDisplay": "Отображение рассуждений","reasoningCollapsed": "Свёрнуто по умолчанию","reasoningWhileThinking": "Разворачивать во время размышлений",diff --git a/packages/vue/src/i18n/locales/zh-cn/ai.json b/packages/vue/src/i18n/locales/zh-cn/ai.jsonindex a6a9cae54..94ddd13d3 100644--- a/packages/vue/src/i18n/locales/zh-cn/ai.json+++ b/packages/vue/src/i18n/locales/zh-cn/ai.json@@ -213,6 +213,21 @@"chatActions": "对话操作","continueChat": "继续","chatSettings": "聊天",+ "notificationsHint": "仅在 OpenPencil 处于后台或显示其他文档时发送。",+ "notifyNeedsInput": "智能体需要你处理",+ "notifyNeedsInputHint": "一个权限请求已等待几秒仍未回复。",+ "notifyFinished": "回复完成",+ "notifyFailed": "回复失败",+ "notificationsAllow": "允许通知",+ "notificationsAllowHint": "浏览器会询问一次是否允许 OpenPencil 显示通知。",+ "notificationsBlocked": "此网站的通知已被阻止。请在浏览器的网站设置中允许。",+ "notificationsUnsupported": "此浏览器无法显示通知。",+ "notificationsSystemHint": "如果没有显示,请在系统的通知设置中允许 OpenPencil。",+ "notifyTitle": "{agent} · {document}",+ "notifyPermission": "请求权限。",+ "notifyPermissionAction": "请求权限:{action}",+ "notifyReplyFinished": "AI 回复已完成。",+ "notifyReplyFailed": "AI 回复因错误而停止。","reasoningDisplay": "推理显示","reasoningCollapsed": "默认折叠","reasoningWhileThinking": "思考时展开",diff --git a/packages/vue/src/i18n/messages/ai.ts b/packages/vue/src/i18n/messages/ai.tsindex c871ab86b..abd9ab200 100644--- a/packages/vue/src/i18n/messages/ai.ts+++ b/packages/vue/src/i18n/messages/ai.ts@@ -5,6 +5,23 @@ import { i18n } from '#vue/i18n/create'export const aiMessageDefaults = {jumpToLatest: 'Jump to latest',chatSettings: 'Chat',+ notificationsHint: 'Sent only while OpenPencil is in the background or shows another document.',+ notifyNeedsInput: 'An agent needs you',+ notifyNeedsInputHint: 'A permission request has waited a few seconds without an answer.',+ notifyFinished: 'A reply finished',+ notifyFailed: 'A reply failed',+ notificationsAllow: 'Allow notifications',+ notificationsAllowHint: 'Your browser asks once whether OpenPencil may show notifications.',+ notificationsBlocked:+ 'Notifications are blocked for this site. Allow them in the browser’s site settings.',+ notificationsUnsupported: 'This browser cannot show notifications.',+ notificationsSystemHint:+ 'If none appear, allow OpenPencil in your system’s notification settings.',+ notifyTitle: params('{agent} · {document}'),+ notifyPermission: 'Asks for permission.',+ notifyPermissionAction: params('Asks for permission: {action}'),+ notifyReplyFinished: 'The AI reply finished.',+ notifyReplyFailed: 'The AI reply stopped with an error.',maxAgentSteps: 'Maximum steps per message',maxAgentStepsCustom: 'Custom…',maxAgentStepsHint:diff --git a/src/AGENTS.md b/src/AGENTS.mdindex 03d0b40c2..96dfc9fc4 100644--- a/src/AGENTS.md+++ b/src/AGENTS.md@@ -53,6 +53,7 @@ The supported browser baseline lives in `src/app/shell/support/baseline.ts` and- Browser and native menus share `src/app/shell/menu/schema.ts`; handle IDs in `use.ts` or editor commands, and regenerate `desktop/generated/menu.json` with `bun run generate:tauri-menu`.- Motion policy lives in `src/app/shell/motion/`: resolve the persisted System/Off preference and OS reduction once. The root `data-motion` attribute and the Tailwind `motion-safe`/`motion-reduce` variants represent the effective policy, including portalled content. Use the policy-aware Motion adapters rather than repeating preference conditionals in components.- Canvas shortcuts stop while a dialog, menu, or listbox is open. A dialog that edits the document listens for undo and redo on its own content with `useDocumentShortcuts`, so keys in menus it portals never reach it; there is one history, the editor's (`src/app/shell/keyboard/document.ts`, `src/components/variables/VariablesDialog.vue`).+- System notifications go through `notify` in `src/app/shell/notifications/`: each event has a preference under `notifications`, nothing is sent while the person is looking at the tab it concerns, and the click shows that tab. Features describe the event and what to open; they never call the Notification API or the Tauri plugin themselves (`tests/e2e/chat/notifications.spec.ts`).- Code that can only run inline, such as the code panel's opaque-origin sandbox frame and the `blob:` worker it starts, is an ordinary module imported as `?script`, which bundles it into a string (`vite/inline-script.ts`); never write it as a source string or serialize functions (`src/app/code/sandbox/frame.ts`).- Keep the app manifest in `vite/pwa.ts`; use `BrandMark` for in-app branding; never symlink web assets to desktop icons (`tools/AGENTS.md`, Brand assets).diff --git a/src/app/ai/agents/acp/permission.ts b/src/app/ai/agents/acp/permission.tsindex 3e1553a65..240517565 100644--- a/src/app/ai/agents/acp/permission.ts+++ b/src/app/ai/agents/acp/permission.ts@@ -1,12 +1,14 @@import type { RequestPermissionRequest, RequestPermissionResponse } from '@agentclientprotocol/sdk'import { computed, shallowRef } from 'vue'-import { ACP_PERMISSION_TIMEOUT_MS } from '@/constants'+import { ACP_PERMISSION_TIMEOUT_MS, AGENT_INPUT_NOTIFY_DELAY_MS } from '@/constants'export interface PendingPermission {request: RequestPermissionRequestresolve: (response: RequestPermissionResponse) => voidtimer: ReturnType<typeof setTimeout>+ /** Calls `onUnanswered` if the request is still waiting by then. */+ notice: ReturnType<typeof setTimeout> | null}export const permissionQueue = shallowRef<PendingPermission[]>([])@@ -19,19 +21,32 @@ function findRejectOption(request: RequestPermissionRequest): string {function removeEntry(entry: PendingPermission) {clearTimeout(entry.timer)+ if (entry.notice) clearTimeout(entry.notice)permissionQueue.value = permissionQueue.value.filter((e) => e !== entry)}+/**+ * Queues the request for the permission dialog. One left unanswered for a few seconds calls+ * `onUnanswered`, which notifies the person, as one answered at once needs no notification; it is+ * rejected once it times out.+ */export function requestPermissionFromUser(- params: RequestPermissionRequest+ params: RequestPermissionRequest,+ onUnanswered?: () => void): Promise<RequestPermissionResponse> {return new Promise((resolve) => {const timer = setTimeout(() => {removeEntry(entry)resolve({ outcome: { outcome: 'selected', optionId: findRejectOption(params) } })}, ACP_PERMISSION_TIMEOUT_MS)+ const notice = onUnanswered+ ? setTimeout(() => {+ entry.notice = null+ onUnanswered()+ }, AGENT_INPUT_NOTIFY_DELAY_MS)+ : null- const entry: PendingPermission = { request: params, resolve, timer }+ const entry: PendingPermission = { request: params, resolve, timer, notice }permissionQueue.value = [...permissionQueue.value, entry]})}diff --git a/src/app/ai/chat/notifications.ts b/src/app/ai/chat/notifications.tsnew file mode 100644index 000000000..2eae73cd2--- /dev/null+++ b/src/app/ai/chat/notifications.ts@@ -0,0 +1,101 @@+import type { UIMessage } from 'ai'+import type { RootContent } from 'mdast'++import { aiMessages } from '@open-pencil/vue/i18n'++import { showChatPanel } from '@/app/ai/chat/panel'+import type { EditorStore } from '@/app/editor/session'+import { appPreferences } from '@/app/settings/preferences/store'+import { notify, type NotificationEvent } from '@/app/shell/notifications'+import { getTabForStore, switchTab } from '@/app/tabs'++/** How much of a finished reply the notification quotes, as Codex quotes 200 characters. */+const REPLY_PREVIEW_LENGTH = 200++/**+ * The reply's last text, which is its answer, as plain text: text before its tool calls only+ * announced them, and a notification shows markdown, links, and code as their raw source.+ */+async function replyPreview(message: UIMessage): Promise<string> {+ const answer = message.parts.findLast((part) => part.type === 'text')+ if (!answer) return ''+ const [{ fromMarkdown }, { toString }, { gfmFromMarkdown }, { gfm }] = await Promise.all([+ import('mdast-util-from-markdown'),+ import('mdast-util-to-string'),+ import('mdast-util-gfm'),+ import('micromark-extension-gfm')+ ])+ const root = fromMarkdown(answer.text, {+ extensions: [gfm()],+ mdastExtensions: [gfmFromMarkdown()]+ })+ // Lines of text read as their words; lists and quotes as their lines in turn, while tables+ // and code do not read as a sentence, so the preview keeps to the prose.+ const lines = (node: RootContent): string[] => {+ if (node.type === 'paragraph' || node.type === 'heading') return [toString(node)]+ if (node.type === 'list' || node.type === 'listItem' || node.type === 'blockquote')+ return node.children.flatMap(lines)+ return []+ }+ const text = root.children.flatMap(lines).join(' ').replaceAll(/\s+/g, ' ').trim()+ if (text.length <= REPLY_PREVIEW_LENGTH) return text+ const cut = text.slice(0, REPLY_PREVIEW_LENGTH)+ return `${cut.slice(0, cut.lastIndexOf(' ') + 1 || REPLY_PREVIEW_LENGTH).trimEnd()}…`+}++/**+ * Notifies about the chat of `store`'s document, titled with who replied and where; a click shows+ * that tab's chat, with the panels the person may have hidden. A document whose tab closed has no+ * chat to show, so it sends nothing, and a click after its tab closed does nothing.+ */+function notifyChat(+ event: NotificationEvent,+ store: EditorStore,+ agent: string,+ body: string+): void {+ const tabId = getTabForStore(store)?.id+ if (!tabId) return+ notify({+ event,+ title: aiMessages.get().notifyTitle({ agent, document: store.state.documentName }),+ body,+ tabId,+ // One per tab, so an agent that keeps working replaces its last notification.+ tag: `agent:${tabId}`,+ open: () => {+ if (!switchTab(tabId)) return+ store.state.showUI = true+ showChatPanel()+ }+ })+}++/** A reply by `agent` ended on its own: `message` is the reply, or null when it failed. */+export async function notifyReplyEnded(+ store: EditorStore,+ agent: string,+ message: UIMessage | null+): Promise<void> {+ const messages = aiMessages.get()+ if (!message) {+ notifyChat('agentFailed', store, agent, messages.notifyReplyFailed)+ return+ }+ // The preview loads a Markdown parser, which a reply nobody asked to hear about does not need.+ if (!appPreferences.value.notifications.agentFinished) return+ // A parser that fails to load leaves the plain announcement rather than no notification.+ const preview = await replyPreview(message).catch(() => '')+ notifyChat('agentFinished', store, agent, preview || messages.notifyReplyFinished)+}++/** An agent's permission request is still waiting for an answer. */+export function notifyPermissionWaiting(store: EditorStore, agent: string, action: string): void {+ const messages = aiMessages.get()+ notifyChat(+ 'agentNeedsInput',+ store,+ agent,+ action ? messages.notifyPermissionAction({ action }) : messages.notifyPermission+ )+}diff --git a/src/app/ai/chat/panel.ts b/src/app/ai/chat/panel.tsnew file mode 100644index 000000000..4b30bda6b--- /dev/null+++ b/src/app/ai/chat/panel.ts@@ -0,0 +1,10 @@+import { ref } from 'vue'++export type PropertiesTab = 'design' | 'code' | 'ai' | 'lint'++/** The properties panel's tab; `ai` shows the chat. */+export const propertiesTab = ref<PropertiesTab>('design')++export function showChatPanel(): void {+ propertiesTab.value = 'ai'+}diff --git a/src/app/ai/chat/session.ts b/src/app/ai/chat/session.tsindex 238248cc9..611869749 100644--- a/src/app/ai/chat/session.ts+++ b/src/app/ai/chat/session.ts@@ -8,6 +8,7 @@ import type { ACPAgentID, AIProviderID } from '@open-pencil/core/constants'import { AgentSetupError, assertAgentReady } from '@/app/ai/agents/setup/readiness'import { classifyAIChatError, type AIChatFailure } from '@/app/ai/chat/failure'+import { notifyReplyEnded } from '@/app/ai/chat/notifications'import { hasSteeringMessage } from '@/app/ai/chat/queue'import SYSTEM_PROMPT from '@/app/ai/chat/system-prompt'import { chatThinkingLevel } from '@/app/ai/chat/thinking'@@ -78,6 +79,12 @@ async function settleEndedReply()}+/** The agent or provider a chat runs on, as the composer names it. */+function providerName(id: AIProviderID): string {+ const agent = ACP_AGENTS.find((candidate) => `acp:${candidate.id}` === id)+ return agent?.name ?? AI_PROVIDERS.find((provider) => provider.id === id)?.name ?? id+}+export function createChatSessionManager({isConfigured,isACPProvider,@@ -295,6 +302,13 @@ export function createChatSessionManager({if (event.isAbort || event.isDisconnect || event.isError) {void settleEndedReply(created, store, event.message.id, event.isAbort)}+ // A reply stopped by the person, or cut off with its connection, ends unannounced.+ if (!event.isAbort && !event.isDisconnect)+ void notifyReplyEnded(+ store,+ providerName(chatProviderID),+ event.isError ? null : event.message+ )}})chat = createddiff --git a/src/app/ai/chat/use.ts b/src/app/ai/chat/use.tsindex c883dee90..abbe44123 100644--- a/src/app/ai/chat/use.ts+++ b/src/app/ai/chat/use.ts@@ -1,8 +1,7 @@-import { ref } from 'vue'-import { IS_BROWSER } from '@open-pencil/core/constants'import { createConversationHistory } from '@/app/ai/chat/history/controller'+import { propertiesTab } from '@/app/ai/chat/panel'import { createChatSessionManager } from '@/app/ai/chat/session'import {apiKeyStatus,@@ -33,10 +32,6 @@ import {setRememberCredentials} from '@/app/settings/credentials/media'-export type PropertiesTab = 'design' | 'code' | 'ai' | 'lint'--const activeTab = ref<PropertiesTab>('design')-const chatSession = createChatSessionManager({isConfigured,isACPProvider,@@ -83,7 +78,7 @@ export function useAIChat() {setRememberCredentials,unsplashKeyStatus,setUnsplashKey,- activeTab,+ activeTab: propertiesTab,isConfigured,history,ensureChat: history.ensureChat,diff --git a/src/app/ai/transports/acp.ts b/src/app/ai/transports/acp.tsindex 768d305db..9aca2a89c 100644--- a/src/app/ai/transports/acp.ts+++ b/src/app/ai/transports/acp.ts@@ -295,13 +295,21 @@ export class ACPChatTransport implements ChatTransport<UIMessage> {// Set once the session exists; the client reads it to record the model the agent names.let sessionRef: ACPSession | null = nullconst agentId = this.agentDef.id+ const { agentDef, store } = thisconst clientImpl: Client = {async requestPermission(params: RequestPermissionRequest): Promise<RequestPermissionResponse> {- const { requestPermissionFromUser } = await import('@/app/ai/agents/acp/permission')- return requestPermissionFromUser(params)+ const [{ requestPermissionFromUser }, { notifyPermissionWaiting }] = await Promise.all([+ import('@/app/ai/agents/acp/permission'),+ import('@/app/ai/chat/notifications')+ ])+ const title = params.toolCall.title ?? ''+ return requestPermissionFromUser(+ params,+ store ? () => notifyPermissionWaiting(store, agentDef.name, title) : undefined+ )},async sessionUpdate(params: SessionNotification): Promise<void> {diff --git a/src/app/settings/dialog.ts b/src/app/settings/dialog.tsindex 9e1409161..1619fe735 100644--- a/src/app/settings/dialog.ts+++ b/src/app/settings/dialog.ts@@ -6,6 +6,7 @@ export type SettingsSection =| 'editor'| 'fonts'| 'storage'+ | 'notifications'| 'cloud'| 'ai'| 'tools'diff --git a/src/app/settings/preferences/store.ts b/src/app/settings/preferences/store.tsindex e41042cbc..680b116cc 100644--- a/src/app/settings/preferences/store.ts+++ b/src/app/settings/preferences/store.ts@@ -71,6 +71,16 @@ export interface SharingPreferences {export const AI_SETUP_STATES = ['pending', 'done'] as constexport type AISetupState = (typeof AI_SETUP_STATES)[number]+/** Which events send a system notification while OpenPencil is out of view. */+export interface NotificationPreferences {+ /** An agent waits on a permission request. */+ agentNeedsInput: boolean+ /** An AI reply finished. */+ agentFinished: boolean+ /** An AI reply ended with an error. */+ agentFailed: boolean+}+export interface AppPreferences {appearance: { animations: AnimationPreference; accent: AccentPreference }chat: {@@ -101,6 +111,7 @@ export interface AppPreferences {aiSetup: AISetupState}sharing: SharingPreferences+ notifications: NotificationPreferences}export const DEFAULT_APP_PREFERENCES: Readonly<AppPreferences> = {@@ -129,7 +140,8 @@ export const DEFAULT_APP_PREFERENCES: Readonly<AppPreferences> = {},toolbar: structuredClone(DEFAULT_TOOLBAR_LAYOUT),onboarding: { aiSetup: 'pending' },- sharing: { dailyPing: true, usageStats: 'unset' }+ sharing: { dailyPing: true, usageStats: 'unset' },+ notifications: { agentNeedsInput: true, agentFinished: false, agentFailed: false }}const STORAGE_KEY = 'open-pencil:preferences:v1'@@ -215,6 +227,11 @@ const appPreferencesSchema = section({sharing: section({dailyPing: v.fallback(v.boolean(), defaults.sharing.dailyPing),usageStats: v.fallback(v.picklist(USAGE_STATS_CONSENTS), defaults.sharing.usageStats)+ }),+ notifications: section({+ agentNeedsInput: v.fallback(v.boolean(), defaults.notifications.agentNeedsInput),+ agentFinished: v.fallback(v.boolean(), defaults.notifications.agentFinished),+ agentFailed: v.fallback(v.boolean(), defaults.notifications.agentFailed)})})@@ -260,6 +277,13 @@ export function updateSharingPreferences(changes: Partial<SharingPreferences>):}}+export function updateNotificationPreferences(changes: Partial<NotificationPreferences>): void {+ appPreferences.value = {+ ...appPreferences.value,+ notifications: { ...appPreferences.value.notifications, ...changes }+ }+}+export function updateCanvasRenderingMode(canvasMode: CanvasRenderingMode): void {appPreferences.value = {...appPreferences.value,diff --git a/src/app/shell/external-links.ts b/src/app/shell/external-links.tsindex 70aaf68af..d1de81d20 100644--- a/src/app/shell/external-links.ts+++ b/src/app/shell/external-links.ts@@ -10,6 +10,8 @@ import { openExternalLink } from './ui'* `shell:allow-open`, which the app does not grant, even when the link handles its click itself,* as a chat link does to ask first; such a link opens with `window.open`, which the desktop shell* sends to the browser (`open_new_window_externally` in `desktop/src/system/opener.rs`).+ * The shell plugin offers no way to leave its handler out on v2; once it does+ * (tauri-apps/plugins-workspace#3753), turning it off replaces this listener.*/export function useExternalLinks() {if (!isTauri()) returndiff --git a/src/app/shell/keyboard/actions.ts b/src/app/shell/keyboard/actions.tsindex eccc38dde..44da22bd3 100644--- a/src/app/shell/keyboard/actions.ts+++ b/src/app/shell/keyboard/actions.ts@@ -5,7 +5,7 @@ import { generatedFrameText } from '@open-pencil/scene-graph/generated'import type { useEditorCommands } from '@open-pencil/vue/editor/commands'import type { useViewportKind } from '@open-pencil/vue/editor/viewport-kind'-import type { PropertiesTab } from '@/app/ai/chat/use'+import type { PropertiesTab } from '@/app/ai/chat/panel'import { useComments } from '@/app/comments/use'import type { EditorStore } from '@/app/editor/active-store'diff --git a/src/app/shell/notifications/index.ts b/src/app/shell/notifications/index.tsnew file mode 100644index 000000000..a5660bc45--- /dev/null+++ b/src/app/shell/notifications/index.ts@@ -0,0 +1,134 @@+import { useDocumentVisibility, useWindowFocus } from '@vueuse/core'+import { watch } from 'vue'++import { IS_TAURI } from '@open-pencil/core/constants'+import { randomInt } from '@open-pencil/scene-graph/random'++import { appPreferences, type NotificationPreferences } from '@/app/settings/preferences/store'+import { activeTab } from '@/app/tabs'++import { browserNotificationPermission } from './permission'++/** Each kind of event a notification reports, named by the preference that turns it on. */+export type NotificationEvent = keyof NotificationPreferences++export interface AppNotification {+ event: NotificationEvent+ title: string+ body: string+ /** The tab the event happened in; it is shown when the notification is clicked. */+ tabId: string | null+ /**+ * In browsers a newer notification with the same tag replaces an older one that is still shown.+ * The desktop shell cannot replace or remove one on macOS and Windows, so each stays.+ */+ tag: string+ /** Shows what the notification is about, after the window comes forward. */+ open: () => void+}++/**+ * Notifications the desktop shell showed, by id, kept to open them when clicked. macOS and Windows+ * do not report a dismissed one, so only the latest are kept; an older one brings the window+ * forward when clicked, as the system does for any notification of the app.+ */+const shownOnDesktop = new Map<number, () => void>()+const DESKTOP_CLICKS_KEPT = 50+/** Browser notifications still shown, with their tab, closed once the person sees that tab. */+const shownInBrowser = new Map<Notification, string | null>()+let desktopClicks: Promise<void> | null = null++const windowFocused = useWindowFocus()+const documentVisibility = useDocumentVisibility()++/** The person is looking at this tab of the focused window, so a notification would only repeat it. */+function isWatching(tabId: string | null): boolean {+ if (documentVisibility.value !== 'visible' || !windowFocused.value) return false+ return tabId === null || tabId === activeTab.value?.id+}++// What a browser notification reports is in view once the person looks at its tab, so it no+// longer needs one; those about other tabs stay to be clicked.+watch([windowFocused, documentVisibility, () => activeTab.value?.id], () => {+ for (const [shown, tabId] of shownInBrowser) if (isWatching(tabId)) shown.close()+})++async function focusDesktopWindow(): Promise<void> {+ const { getCurrentWindow } = await import('@tauri-apps/api/window')+ const window = getCurrentWindow()+ await window.unminimize()+ await window.setFocus()+}++/**+ * Clicks reach the shell only for notifications shown after a listener exists, so it is added+ * before the first one. Windows reports a click only while the toast is on screen, not once it+ * moved to the Action Center.+ */+async function addDesktopClickListener(): Promise<void> {+ const { onAction } = await import('@tauri-apps/plugin-notification')+ await onAction(({ actionId, notification }) => {+ const id = notification?.id+ const open = id === undefined ? undefined : shownOnDesktop.get(id)+ if (actionId !== 'tap' || !open || id === undefined) return+ shownOnDesktop.delete(id)+ void focusDesktopWindow().finally(open)+ })+}++function listenForDesktopClicks(): Promise<void> {+ // A listener that could not be added is tried again with the next notification.+ desktopClicks ??= addDesktopClickListener().catch((error: unknown) => {+ desktopClicks = null+ throw error+ })+ return desktopClicks+}++async function showOnDesktop(notification: AppNotification): Promise<void> {+ await listenForDesktopClicks()+ const { sendNotification } = await import('@tauri-apps/plugin-notification')+ const id = randomInt()+ shownOnDesktop.set(id, notification.open)+ for (const old of shownOnDesktop.keys()) {+ if (shownOnDesktop.size <= DESKTOP_CLICKS_KEPT) break+ shownOnDesktop.delete(old)+ }+ sendNotification({ id, title: notification.title, body: notification.body })+}++function showInBrowser(notification: AppNotification): void {+ if (browserNotificationPermission.value !== 'granted') return+ let shown: Notification+ try {+ shown = new Notification(notification.title, {+ body: notification.body,+ tag: notification.tag+ })+ } catch {+ // Mobile browsers show notifications only through a service worker and throw here.+ return+ }+ shownInBrowser.set(shown, notification.tabId)+ shown.addEventListener('close', () => shownInBrowser.delete(shown))+ shown.addEventListener('click', () => {+ window.focus()+ shown.close()+ notification.open()+ })+}++/**+ * Sends a system notification for `event` when its preference is on and the person is away:+ * the window is hidden or unfocused, or shows another tab. Browsers show it only once the person+ * allowed notifications; the desktop shell always may, unless the system settings turned them off.+ */+export function notify(notification: AppNotification): void {+ if (!appPreferences.value.notifications[notification.event]) return+ if (isWatching(notification.tabId)) return+ if (IS_TAURI)+ void showOnDesktop(notification).catch((error) =>+ console.warn('[Notifications] Not shown:', error)+ )+ else showInBrowser(notification)+}diff --git a/src/app/shell/notifications/permission.ts b/src/app/shell/notifications/permission.tsnew file mode 100644index 000000000..810af66e5--- /dev/null+++ b/src/app/shell/notifications/permission.ts@@ -0,0 +1,32 @@+import { usePermission } from '@vueuse/core'+import { readonly, shallowRef, watch } from 'vue'++import { IS_TAURI } from '@open-pencil/core/constants'++/** Whether this browser lets the page show notifications; `unsupported` where it has none. */+export type BrowserNotificationPermission = NotificationPermission | 'unsupported'++function current(): BrowserNotificationPermission {+ // The desktop shell needs no permission; whether the system shows notifications is up to its+ // own settings, which the app cannot read.+ if (IS_TAURI) return 'granted'+ return typeof Notification === 'undefined' ? 'unsupported' : Notification.permission+}++const permission = shallowRef(current())+// The person can change the site setting while the page is open.+watch(usePermission('notifications'), () => {+ permission.value = current()+})++/** The page's notification permission, kept current as the site setting changes. */+export const browserNotificationPermission = readonly(permission)++/**+ * Asks the browser for permission. It must run from a click: Firefox and Safari refuse requests+ * that are not, and a refused request is not asked again.+ */+export async function requestBrowserNotificationPermission(): Promise<void> {+ if (typeof Notification === 'undefined') return+ permission.value = await Notification.requestPermission()+}diff --git a/src/app/shell/notifications/preferences.ts b/src/app/shell/notifications/preferences.tsnew file mode 100644index 000000000..e8a63f1ca--- /dev/null+++ b/src/app/shell/notifications/preferences.ts@@ -0,0 +1,13 @@+import { computed } from 'vue'++import { appPreferences, updateNotificationPreferences } from '@/app/settings/preferences/store'++import type { NotificationEvent } from '.'++/** Whether `event` sends a notification, as a model for its switch in Settings. */+export function notificationPreference(event: NotificationEvent) {+ return computed({+ get: () => appPreferences.value.notifications[event],+ set: (enabled: boolean) => updateNotificationPreferences({ [event]: enabled })+ })+}diff --git a/src/components/settings/SettingsDialog.vue b/src/components/settings/SettingsDialog.vueindex ab0050276..d4f138a3d 100644--- a/src/components/settings/SettingsDialog.vue+++ b/src/components/settings/SettingsDialog.vue@@ -3,6 +3,7 @@ import { tryOnScopeDispose } from '@vueuse/core'import { AlertDialogCancel, DialogClose } from 'reka-ui'import { computed, type Component } from 'vue'import IconActivity from '~icons/lucide/activity'+import IconBell from '~icons/lucide/bell'import IconBookOpen from '~icons/lucide/book-open'import IconChartNoAxesCombined from '~icons/lucide/chart-no-axes-combined'import IconCloud from '~icons/lucide/cloud'@@ -38,6 +39,7 @@ import SettingsPage from '@/components/settings/layout/SettingsPage.vue'import MCPWorkspacePanel from '@/components/settings/mcp/MCPWorkspacePanel.vue'import MediaSettingsPanel from '@/components/settings/media/MediaSettingsPanel.vue'import ModelsPanel from '@/components/settings/models/ModelsPanel.vue'+import NotificationSettingsSection from '@/components/settings/notifications/NotificationSettingsSection.vue'import PrivacySettingsPanel from '@/components/settings/privacy/PrivacySettingsPanel.vue'import SkillsSettingsPanel from '@/components/settings/skills/SkillsSettingsPanel.vue'import StorageSettingsPanel from '@/components/settings/storage/StorageSettingsPanel.vue'@@ -79,6 +81,7 @@ const groups = computed<{ label: string; sections: SectionItem[] }[]>(() => [{ value: 'editor', label: settings.value.editor, icon: IconPenTool },{ value: 'fonts', label: settings.value.fonts, icon: IconType },{ value: 'storage', label: settings.value.storage, icon: IconDatabase },+ { value: 'notifications', label: settings.value.notifications, icon: IconBell },...(CLOUD_INCLUDED? [{ value: 'cloud' as const, label: settings.value.cloud, icon: IconCloud }]: [])@@ -201,6 +204,9 @@ function onOpenChange(open: boolean): void {<AppTabsContent value="storage" as-child><StorageSettingsPanel /></AppTabsContent>+ <AppTabsContent value="notifications" as-child>+ <SettingsPage><NotificationSettingsSection /></SettingsPage>+ </AppTabsContent><AppTabsContent v-if="CLOUD_INCLUDED" value="cloud" as-child><CloudSettingsSection /></AppTabsContent>diff --git a/src/components/settings/notifications/NotificationSettingsSection.vue b/src/components/settings/notifications/NotificationSettingsSection.vuenew file mode 100644index 000000000..a7d97fc1f--- /dev/null+++ b/src/components/settings/notifications/NotificationSettingsSection.vue@@ -0,0 +1,63 @@+<script setup lang="ts">+import { IS_TAURI } from '@open-pencil/core/constants'+import { useI18n } from '@open-pencil/vue/i18n'++import {+ browserNotificationPermission,+ requestBrowserNotificationPermission+} from '@/app/shell/notifications/permission'+import { notificationPreference } from '@/app/shell/notifications/preferences'+import SettingsGroup from '@/components/settings/layout/SettingsGroup.vue'+import SettingsRow from '@/components/settings/layout/SettingsRow.vue'+import SettingsSection from '@/components/settings/layout/SettingsSection.vue'+import AppButton from '@/components/ui/button/AppButton.vue'+import AppAlert from '@/components/ui/feedback/AppAlert.vue'+import AppSwitch from '@/components/ui/toggle/AppSwitch.vue'++const { ai, settings } = useI18n()+const needsInput = notificationPreference('agentNeedsInput')+const finished = notificationPreference('agentFinished')+const failed = notificationPreference('agentFailed')+</script>++<template>+ <SettingsSection data-test-id="settings-notifications">+ <template #title>{{ settings.notifications }}</template>+ <template #description>{{+ IS_TAURI ? `${ai.notificationsHint} ${ai.notificationsSystemHint}` : ai.notificationsHint+ }}</template>+ <SettingsGroup>+ <SettingsRow+ v-if="browserNotificationPermission === 'default'"+ :label="ai.notificationsAllow"+ :description="ai.notificationsAllowHint"+ >+ <AppButton+ size="xs"+ variant="outline"+ data-test-id="settings-notifications-allow"+ @click="requestBrowserNotificationPermission()"+ >{{ ai.notificationsAllow }}</AppButton+ >+ </SettingsRow>+ <SettingsRow :label="ai.notifyNeedsInput" :description="ai.notifyNeedsInputHint">+ <AppSwitch v-model="needsInput" :label="ai.notifyNeedsInput" />+ </SettingsRow>+ <SettingsRow :label="ai.notifyFinished">+ <AppSwitch v-model="finished" :label="ai.notifyFinished" />+ </SettingsRow>+ <SettingsRow :label="ai.notifyFailed">+ <AppSwitch v-model="failed" :label="ai.notifyFailed" />+ </SettingsRow>+ </SettingsGroup>+ <AppAlert+ v-if="browserNotificationPermission === 'denied'"+ tone="warning"+ :heading="ai.notificationsBlocked"+ />+ <AppAlert+ v-else-if="browserNotificationPermission === 'unsupported'"+ :heading="ai.notificationsUnsupported"+ />+ </SettingsSection>+</template>diff --git a/src/constants.ts b/src/constants.tsindex d75868b37..4f68e4091 100644--- a/src/constants.ts+++ b/src/constants.ts@@ -160,3 +160,5 @@ export const DEFAULT_TEXT_WIDTH = 200export const DEFAULT_TEXT_HEIGHT = 24export const ACP_PERMISSION_TIMEOUT_MS = 60_000+/** How long a request waits unanswered before a notification says an agent needs you. */+export const AGENT_INPUT_NOTIFY_DELAY_MS = 6_000diff --git a/tests/e2e/chat/notifications.spec.ts b/tests/e2e/chat/notifications.spec.tsnew file mode 100644index 000000000..c0cca2cb2--- /dev/null+++ b/tests/e2e/chat/notifications.spec.ts@@ -0,0 +1,148 @@+import type { Page } from '@playwright/test'+import * as v from 'valibot'++import { expect, test as chatTest } from '#tests/helpers/chat/fixture'+import type { ChatHarness } from '#tests/helpers/chat/harness'++const shownSchema = v.array(v.object({ title: v.string(), body: v.string(), tag: v.string() }))++/**+ * Replaces the browser's notifications, before the app reads their permission, with allowed ones+ * that are only recorded with how many closed. `notification-click` clicks the last one.+ */+const test = chatTest.extend({+ page: async ({ page }, use) => {+ await page.addInitScript(() => {+ const shown: { title: string; body: string; tag: string }[] = []+ class RecordedNotification extends EventTarget {+ static readonly permission = 'granted'+ static async requestPermission() {+ return 'granted'+ }+ constructor(title: string, options: NotificationOptions = {}) {+ super()+ shown.push({ title, body: options.body ?? '', tag: options.tag ?? '' })+ document.documentElement.dataset.notifications = JSON.stringify(shown)+ const index = shown.length - 1+ document.addEventListener('notification-click', () => {+ if (index === shown.length - 1) this.dispatchEvent(new Event('click'))+ })+ }+ close() {+ const closed = Number(document.documentElement.dataset.closedNotifications ?? 0)+ document.documentElement.dataset.closedNotifications = String(closed + 1)+ this.dispatchEvent(new Event('close'))+ }+ }+ Object.defineProperty(window, 'Notification', { value: RecordedNotification })+ })+ await use(page)+ }+})++/** Takes focus from the window, as switching to another app does, or gives it back. */+async function setWindowFocus(page: Page, focused: boolean) {+ await page.evaluate((type) => window.dispatchEvent(new Event(type)), focused ? 'focus' : 'blur')+}++async function shownNotifications(page: Page) {+ const json = await page.evaluate(() => document.documentElement.dataset.notifications ?? '[]')+ return v.parse(v.pipe(v.string(), v.parseJson(), shownSchema), json)+}++async function turnOnInSettings(page: Page, label: string) {+ await page.keyboard.press(process.platform === 'darwin' ? 'Meta+,' : 'Control+,')+ await page.getByRole('tab', { name: 'Notifications' }).click()+ await page.getByTestId('settings-notifications').getByRole('switch', { name: label }).click()+ await page.getByTestId('app-settings-done').click()+}++async function reply(chat: ChatHarness, text: string, count: number) {+ await chat.submit(text)+ await expect(chat.page.getByTestId('chat-message-assistant')).toHaveCount(count)+}++test('a finished reply notifies only when turned on and away, and its click shows that chat', async ({+ configuredChat: chat,+ page+}) => {+ await setWindowFocus(page, false)+ await reply(chat, 'First request', 1)+ await expect(chat.assistantMessage()).toContainText('mock response')+ expect(await shownNotifications(page)).toEqual([])++ await turnOnInSettings(page, 'A reply finished')+ // Text before a reply's tool calls only announces them; the answer is its last text.+ await reply(chat, 'Answer in multiple parts', 2)+ await expect+ .poll(() => shownNotifications(page))+ .toEqual([+ {+ // The title names who replied and where.+ title: expect.stringMatching(/OpenRouter.*Untitled/),+ body: 'Second',+ tag: expect.stringMatching(/^agent:/)+ }+ ])++ // Markdown reads as its text, without tables, task boxes, code ticks, or link targets.+ await reply(chat, 'Show a markdown table', 3)+ await expect.poll(() => shownNotifications(page)).toHaveLength(2)+ const preview = (await shownNotifications(page)).at(-1)?.body ?? ''+ expect(preview).toMatch(+ /^The button now has these states: Variants created Checked in preview See the guide\.$/+ )+ expect(preview).not.toMatch(/[|*`[\]]/)++ // Coming back to the window with the chat's tab in view closes what reported on it.+ await setWindowFocus(page, true)+ await expect+ .poll(() => page.evaluate(() => document.documentElement.dataset.closedNotifications))+ .toBe('2')++ // Another document and the Design tab are in view when the notification is clicked.+ // The tab bar starts with Home; the chat's document is the tab after it.+ const tabs = page.getByTestId('tabbar-tab')+ const chatDocument = tabs.nth(1)+ await expect(chatDocument).toHaveAttribute('aria-selected', 'true')+ await page.getByTestId('tabbar-new').click()+ await expect(tabs.last()).toHaveAttribute('aria-selected', 'true')+ await chat.designTab.click()+ await page.evaluate(() => document.dispatchEvent(new Event('notification-click')))+ await expect(chatDocument).toHaveAttribute('aria-selected', 'true')+ await expect(chat.chatTab).toHaveAttribute('aria-selected', 'true')++ // With the panels hidden, the click shows them again.+ await chat.designTab.click()+ await page.keyboard.press('ControlOrMeta+Backslash')+ await expect(chat.chatTab).toBeHidden()+ await page.evaluate(() => document.dispatchEvent(new Event('notification-click')))+ await expect(chat.chatTab).toHaveAttribute('aria-selected', 'true')+})++test('a failed reply notifies when turned on, but not while its chat is in view', async ({+ configuredChat: chat,+ page+}) => {+ await turnOnInSettings(page, 'A reply failed')+ const failure = page.locator('[data-slot="toast"]').filter({ hasText: 'invalid or expired' })++ await setWindowFocus(page, true)+ await chat.submit('Use the expired key')+ await expect(failure).toBeVisible()+ expect(await shownNotifications(page)).toEqual([])++ await setWindowFocus(page, false)+ await chat.submit('Use the expired key again')+ await expect+ .poll(() => shownNotifications(page))+ .toEqual([+ {+ title: expect.stringMatching(/OpenRouter.*Untitled/),+ // A failure is announced as one, not quoted from the reply.+ body: expect.not.stringContaining('expired key'),+ tag: expect.stringMatching(/^agent:/)+ }+ ])+ expect((await shownNotifications(page)).at(0)?.body.trim()).toBeTruthy()+})diff --git a/tests/engine/acp/permission.test.ts b/tests/engine/acp/permission.test.tsindex c287ffb5a..6c1bde54e 100644--- a/tests/engine/acp/permission.test.ts+++ b/tests/engine/acp/permission.test.ts@@ -1,4 +1,4 @@-import { describe, expect, test, beforeEach } from 'bun:test'+import { describe, expect, test, beforeEach, jest } from 'bun:test'import type { RequestPermissionRequest, RequestPermissionResponse } from '@agentclientprotocol/sdk'@@ -9,6 +9,7 @@ import {respondToPermission,rejectCurrentPermission} from '@/app/ai/agents/acp/permission'+import { AGENT_INPUT_NOTIFY_DELAY_MS } from '@/constants'function makeRequest(options: { optionId: string; kind: string; name: string }[] = [@@ -146,4 +147,24 @@ describe('acp-permission', () => {expect(selectedOptionId(result)).toBe('reject')expect(permissionQueue.value).toHaveLength(0)})++ test('a request left unanswered calls onUnanswered once, and an answered one never', () => {+ jest.useFakeTimers()+ try {+ let unanswered = 0+ void requestPermissionFromUser(makeRequest(), () => unanswered++)+ jest.advanceTimersByTime(AGENT_INPUT_NOTIFY_DELAY_MS - 1)+ expect(unanswered).toBe(0)+ jest.advanceTimersByTime(1)+ expect(unanswered).toBe(1)+ respondToPermission('allow')++ void requestPermissionFromUser(makeRequest(), () => unanswered++)+ respondToPermission('allow')+ jest.advanceTimersByTime(AGENT_INPUT_NOTIFY_DELAY_MS)+ expect(unanswered).toBe(1)+ } finally {+ jest.useRealTimers()+ }+ })})diff --git a/tools/checks/i18n/mixed-script-baseline.txt b/tools/checks/i18n/mixed-script-baseline.txtindex 998f31c25..727cbcc8e 100644--- a/tools/checks/i18n/mixed-script-baseline.txt+++ b/tools/checks/i18n/mixed-script-baseline.txt@@ -596,4 +596,14 @@ zh-cn:ai.skillsTrustDescriptionzh-cn:ai.queueMessageja:ai.queueMessageja:ai.skillsDescription+ja:ai.notificationsHint+ja:ai.notificationsAllowHint+ja:ai.notificationsSystemHint+ja:ai.notifyReplyFinished+ja:ai.notifyReplyFailedzh-cn:ai.skillsDescription+zh-cn:ai.notificationsHint+zh-cn:ai.notificationsAllowHint+zh-cn:ai.notificationsSystemHint+zh-cn:ai.notifyReplyFinished+zh-cn:ai.notifyReplyFaileddiff --git a/tools/checks/i18n/translation-baseline.txt b/tools/checks/i18n/translation-baseline.txtindex 26a86fd42..7310c508a 100644--- a/tools/checks/i18n/translation-baseline.txt+++ b/tools/checks/i18n/translation-baseline.txt@@ -80,6 +80,7 @@ es:ai.chatSettingses:ai.completionses:ai.responseses:ai.toolError+es:ai.notifyTitlees:automation.statusErrores:code.editorDesignLabeles:code.sourceDesignJSX@@ -207,6 +208,7 @@ it:ai.aiSetupAgentAccountit:ai.chatSettingsit:ai.completionsit:ai.responses+it:ai.notifyTitleit:code.editorDesignLabelit:code.sourceDesignJSXit:code.sourceHTML@@ -275,6 +277,7 @@ pl:ai.completionspl:ai.modelAgentConnectionpl:ai.modelConfigurationpl:ai.responses+pl:ai.notifyTitlepl:automation.portpl:code.editorDesignLabelpl:code.sourceDesignJSX@@ -309,6 +312,7 @@ pl:storage.providerR2pl:storage.regionru:ai.completionsru:ai.responses+ru:ai.notifyTitleru:code.editorDesignLabelru:code.sourceDesignJSXru:code.sourceHTML@@ -331,6 +335,7 @@ ru:storage.cloudTitleru:storage.waitlistPlaceholderzh-cn:ai.completionszh-cn:ai.responses+zh-cn:ai.notifyTitlezh-cn:code.editorDesignLabelzh-cn:code.sourceDesignJSXzh-cn:code.sourceHTML@@ -531,13 +536,16 @@ ru:cloud.homeCloudOnHostru:cloud.inviteEmailPlaceholderde:settings.skillsde:ai.chatReferenceSkills+de:ai.notifyTitlefr:ai.chatReferencePages+fr:ai.notifyTitlede:settings.groupAppde:settings.editores:settings.editorit:settings.groupAppit:settings.editorja:settings.groupAI+ja:ai.notifyTitlepl:settings.groupAIzh-cn:settings.groupAIde:settings.cloud