GeezerVison is showing github.com — feat(app): add question notifications and sounds (#60358) · jonBoone/opencode@d09e2c6
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/app/e2e/regression/settings.spec.ts +142Lines changed: 142 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,8 @@ import type { ConfigEntry, OpenCodeEvent, SessionMessageInfo, WorktreeDirectory | 3 | 3 | import { NO_PROVIDER, REMOTE_SERVER, SERVER, holdRoute, project, seed, session } from "../utils/app" | 4 | 4 | import { mockMissingLocation, mockOpenCodeServer } from "../utils/mock-server" | 5 | 5 | import { mockRemoteServer, mockWorkspace, openSession, openSettings, type WorkspaceInput } from "../utils/workspace" | | 6 | +import { recordNotifications } from "../utils/notifications" | | 7 | +import { installSseTransport } from "../utils/sse-transport" | 6 | 8 |
| 7 | 9 | const directory = "C:/Projects/settings-demo" | 8 | 10 |
| @@ -94,6 +96,146 @@ test("a settings page survives refresh", async ({ page }) => { | 94 | 96 | await expect(page).toHaveURL("/settings?tab=appearance") | 95 | 97 | }) | 96 | 98 |
| | 99 | +test("Questions settings default independently of old Permissions settings and survive reload", async ({ page }) => { | | 100 | + const { settings } = await open(page, { | | 101 | + seed: { | | 102 | + settings: { | | 103 | + notifications: { agent: false, permissions: false, errors: true }, | | 104 | + sounds: { permissionsEnabled: false, permissions: "alert-05" }, | | 105 | + }, | | 106 | + }, | | 107 | + }) | | 108 | + | | 109 | + await settings.getByRole("tab", { name: "Notifications", exact: true }).click() | | 110 | + await expect(settings.locator('[data-slot="settings-row-title"]')).toHaveText([ | | 111 | + "Agent", | | 112 | + "Permissions", | | 113 | + "Questions", | | 114 | + "Errors", | | 115 | + "Agent", | | 116 | + "Permissions", | | 117 | + "Questions", | | 118 | + "Errors", | | 119 | + "Interface", | | 120 | + ]) | | 121 | + const questions = settings.getByRole("switch", { name: "Questions", exact: true }) | | 122 | + | | 123 | + const permissions = settings.locator('[data-action="settings-notifications-permissions"]').getByRole("switch") | | 124 | + | | 125 | + const questionSound = settings.locator('[data-action="settings-sounds-questions"]') | | 126 | + | | 127 | + const permissionSound = settings.locator('[data-action="settings-sounds-permissions"]') | | 128 | + | | 129 | + await expect(questions).toBeChecked() | | 130 | + await expect(permissions).not.toBeChecked() | | 131 | + await expect(questionSound).toHaveText("Staplebops 02") | | 132 | + await expect(permissionSound).toHaveText("None") | | 133 | + await questions.locator("..").locator('[data-slot="switch-control"]').click() | | 134 | + await expect(questions).not.toBeChecked() | | 135 | + await questionSound.click() | | 136 | + await page.getByRole("option", { name: "Alert 02", exact: true }).click() | | 137 | + await expect(questionSound).toHaveText("Alert 02") | | 138 | + | | 139 | + await page.reload() | | 140 | + await expect(questions).not.toBeChecked() | | 141 | + await expect(questionSound).toHaveText("Alert 02") | | 142 | + await expect(permissions).not.toBeChecked() | | 143 | + await expect(permissionSound).toHaveText("None") | | 144 | + await questions.locator("..").locator('[data-slot="switch-control"]').click() | | 145 | + await questionSound.click() | | 146 | + await page.getByRole("option", { name: "None", exact: true }).click() | | 147 | + await expect(questions).toBeChecked() | | 148 | + await expect(questionSound).toHaveText("None") | | 149 | + await settings.getByRole("combobox", { name: "Search", exact: true }).fill("Questions") | | 150 | + await expect(settings.locator('[data-setting-target="settings-notifications-questions"]')).toBeVisible() | | 151 | + await expect(settings.locator('[data-setting-target="settings-sounds-questions"]')).toBeVisible() | | 152 | +}) | | 153 | + | | 154 | +test("request events use real Questions settings without disabling Permissions alerts", async ({ page }) => { | | 155 | + const recorded = await recordNotifications(page) | | 156 | + | | 157 | + const transport = await installSseTransport(page, { server: SERVER }) | | 158 | + | | 159 | + const workspace = await openSession(page, { | | 160 | + name: "Request notifications", | | 161 | + seed: { settings: { sounds: { agentEnabled: false, permissions: "alert-01", questions: "alert-02" } } }, | | 162 | + }) | | 163 | + | | 164 | + await transport.waitForConnection() | | 165 | + await page.getByRole("button", { name: "Home", exact: true }).click() | | 166 | + await page.getByRole("button", { name: "Settings", exact: true }).click() | | 167 | + const settings = page.getByTestId("settings-screen") | | 168 | + | | 169 | + await settings.getByRole("tab", { name: "Notifications", exact: true }).click() | | 170 | + const questions = settings.getByRole("switch", { name: "Questions", exact: true }) | | 171 | + | | 172 | + await expect(questions).toBeChecked() | | 173 | + | | 174 | + const event = ( | | 175 | + kind: "question" | "mcp-elicitation" | "websearch.provider" | "permission", | | 176 | + index: number, | | 177 | + ): OpenCodeEvent => ({ | | 178 | + id: `evt_request_${index}`, | | 179 | + created: 1700000001000 + index, | | 180 | + location: { directory: workspace.directory }, | | 181 | + ...(kind === "permission" | | 182 | + ? { | | 183 | + type: "permission.asked" as const, | | 184 | + data: { | | 185 | + id: `per_request_${index}`, | | 186 | + sessionID: workspace.session.id, | | 187 | + action: "shell", | | 188 | + resources: ["echo hello"], | | 189 | + metadata: {}, | | 190 | + }, | | 191 | + } | | 192 | + : { | | 193 | + type: "form.created" as const, | | 194 | + data: { | | 195 | + form: { | | 196 | + id: `frm_request_${index}`, | | 197 | + sessionID: workspace.session.id, | | 198 | + title: "Input", | | 199 | + metadata: { kind }, | | 200 | + fields: [{ key: "answer", type: "string" as const, title: "Continue?" }], | | 201 | + }, | | 202 | + }, | | 203 | + }), | | 204 | + }) | | 205 | + | | 206 | + await transport.send(event("question", 1)) | | 207 | + await expect | | 208 | + .poll(() => recorded.notifications) | | 209 | + .toEqual([{ title: "Question requires an answer", body: "Request notifications" }]) | | 210 | + await expect.poll(() => recorded.sounds).toEqual([expect.stringContaining("alert-02")]) | | 211 | + | | 212 | + // Choosing None leaves system notifications enabled; the next input request proves the settings reach delivery. | | 213 | + await settings.locator('[data-action="settings-sounds-questions"]').click() | | 214 | + await page.getByRole("option", { name: "None", exact: true }).click() | | 215 | + await expect(settings.locator('[data-action="settings-sounds-questions"]')).toHaveText("None") | | 216 | + const previews = recorded.sounds.slice() | | 217 | + | | 218 | + await transport.send(event("mcp-elicitation", 2)) | | 219 | + await expect | | 220 | + .poll(() => recorded.notifications.map((item) => item.title)) | | 221 | + .toEqual(["Question requires an answer", "Input requested"]) | | 222 | + | | 223 | + await questions.locator("..").locator('[data-slot="switch-control"]').click() | | 224 | + await expect(questions).not.toBeChecked() | | 225 | + await transport.send(event("question", 3)) | | 226 | + await transport.send(event("permission", 4)) | | 227 | + await expect | | 228 | + .poll(() => recorded.notifications.map((item) => item.title)) | | 229 | + .toEqual(["Question requires an answer", "Input requested", "Permission required"]) | | 230 | + await transport.send(event("websearch.provider", 5)) | | 231 | + await expect | | 232 | + .poll(() => recorded.notifications.map((item) => item.title)) | | 233 | + .toEqual(["Question requires an answer", "Input requested", "Permission required", "Permission required"]) | | 234 | + await expect | | 235 | + .poll(() => recorded.sounds) | | 236 | + .toEqual([...previews, expect.stringContaining("alert-01"), expect.stringContaining("alert-01")]) | | 237 | +}) | | 238 | + | 97 | 239 | for (const locale of ["en", "ar"]) { | 98 | 240 | test(`background activity alignment stays physical and persists (${locale})`, async ({ page }) => { | 99 | 241 | const id = "ses_activity_settings" | |
Collapse file Copy file name to clipboard +53Lines changed: 53 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import type { Page } from "@playwright/test" | | 2 | + | | 3 | +// Only browser APIs are replaced: settings, event delivery, request stores and the coordinator stay real. | | 4 | +export async function recordNotifications(page: Page) { | | 5 | + const notifications: { title: string; body?: string }[] = [] | | 6 | + | | 7 | + const sounds: string[] = [] | | 8 | + | | 9 | + await page.exposeBinding("recordNotification", (_source, notification: { title: string; body?: string }) => { | | 10 | + notifications.push(notification) | | 11 | + }) | | 12 | + await page.exposeBinding("recordNotificationSound", (_source, src: string) => { | | 13 | + sounds.push(src) | | 14 | + }) | | 15 | + await page.addInitScript(() => { | | 16 | + // SAFETY: exposeBinding above installs these callbacks before the app starts. | | 17 | + const host: Window & { | | 18 | + recordNotification?: (notification: { title: string; body?: string }) => Promise<void> | | 19 | + recordNotificationSound?: (src: string) => Promise<void> | | 20 | + } = window | | 21 | + | | 22 | + // Simulate an unfocused app without changing the user's live desktop window. | | 23 | + document.hasFocus = () => false | | 24 | + Object.defineProperty(window, "Notification", { | | 25 | + value: class extends EventTarget { | | 26 | + static permission = "granted" | | 27 | + onclick: (() => void) | null = null | | 28 | + | | 29 | + constructor(title: string, options?: NotificationOptions) { | | 30 | + super() | | 31 | + void host.recordNotification!({ title, body: options?.body }) | | 32 | + } | | 33 | + | | 34 | + close() {} | | 35 | + }, | | 36 | + }) | | 37 | + Object.defineProperty(window, "Audio", { | | 38 | + value: class { | | 39 | + currentTime = 0 | | 40 | + | | 41 | + constructor(readonly src: string) {} | | 42 | + | | 43 | + play() { | | 44 | + return host.recordNotificationSound!(this.src) | | 45 | + } | | 46 | + | | 47 | + pause() {} | | 48 | + }, | | 49 | + }) | | 50 | + }) | | 51 | + | | 52 | + return { notifications, sounds } | | 53 | +} |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/runtime/i18n/en.ts +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -550,6 +550,8 @@ export const dict = { | 550 | 550 | "error.chain.configInvalidWithMessage": "Config file at {{path}} is invalid: {{message}}", | 551 | 551 |
| 552 | 552 | "notification.permission.title": "Permission required", | | 553 | + "notification.question.title": "Question requires an answer", | | 554 | + "notification.elicitation.title": "Input requested", | 553 | 555 |
| 554 | 556 | "notification.session.responseReady.title": "Response ready", | 555 | 557 | "notification.session.error.title": "Session error", | @@ -1055,13 +1057,17 @@ export const dict = { | 1055 | 1057 | "Show system notification when the agent is complete or needs attention", | 1056 | 1058 | "settings.general.notifications.permissions.title": "Permissions", | 1057 | 1059 | "settings.general.notifications.permissions.description": "Show system notification when a permission is required", | | 1060 | + "settings.general.notifications.questions.title": "Questions", | | 1061 | + "settings.general.notifications.questions.description": "Show system notification when the agent asks a question", | 1058 | 1062 | "settings.general.notifications.errors.title": "Errors", | 1059 | 1063 | "settings.general.notifications.errors.description": "Show system notification when an error occurs", | 1060 | 1064 |
| 1061 | 1065 | "settings.general.sounds.agent.title": "Agent", | 1062 | 1066 | "settings.general.sounds.agent.description": "Play sound when the agent is complete or needs attention", | 1063 | 1067 | "settings.general.sounds.permissions.title": "Permissions", | 1064 | 1068 | "settings.general.sounds.permissions.description": "Play sound when a permission is required", | | 1069 | + "settings.general.sounds.questions.title": "Questions", | | 1070 | + "settings.general.sounds.questions.description": "Play sound when the agent asks a question", | 1065 | 1071 | "settings.general.sounds.errors.title": "Errors", | 1066 | 1072 | "settings.general.sounds.errors.description": "Play sound when an error occurs", | 1067 | 1073 | "settings.general.sounds.interface.title": "Interface", | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/settings/general/controllers.ts +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -177,6 +177,12 @@ export function createSoundSettingsController() { | 177 | 177 | (value) => settings.sounds.setPermissionsEnabled(value), | 178 | 178 | (id) => settings.sounds.setPermissions(id), | 179 | 179 | ), | | 180 | + questions: channel( | | 181 | + settings.sounds.questionsEnabled, | | 182 | + settings.sounds.questions, | | 183 | + (value) => settings.sounds.setQuestionsEnabled(value), | | 184 | + (id) => settings.sounds.setQuestions(id), | | 185 | + ), | 180 | 186 | errors: channel( | 181 | 187 | settings.sounds.errorsEnabled, | 182 | 188 | settings.sounds.errors, | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/settings/model.test.ts +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -112,12 +112,14 @@ describe("settings schema", () => { | 112 | 112 | keybinds: {}, | 113 | 113 | permissions: { autoApprove: false, autoApproveProjects: {} }, | 114 | 114 | workspaces: { defaultDestination: "last-used", lastUsed: {} }, | 115 | | - notifications: { agent: false, permissions: true, errors: false }, | | 115 | + notifications: { agent: false, permissions: true, questions: true, errors: false }, | 116 | 116 | sounds: { | 117 | 117 | agentEnabled: true, | 118 | 118 | agent: "staplebops-01", | 119 | 119 | permissionsEnabled: true, | 120 | 120 | permissions: "staplebops-02", | | 121 | + questionsEnabled: true, | | 122 | + questions: "staplebops-02", | 121 | 123 | errorsEnabled: true, | 122 | 124 | errors: "nope-03", | 123 | 125 | interfaceEnabled: true, | @@ -165,7 +167,7 @@ describe("settings schema", () => { | 165 | 167 | expect(settings.permissions).toEqual({ autoApprove: true, autoApproveProjects: { on: true, off: false } }) | 166 | 168 | expect(settings.workspaces).toEqual({ defaultDestination: "new", lastUsed: { good: "workspace" } }) | 167 | 169 | expect(settings.keybinds).toEqual({ good: "ctrl+k" }) | 168 | | - expect(settings.notifications).toEqual({ agent: false, permissions: true, errors: true }) | | 170 | + expect(settings.notifications).toEqual({ agent: false, permissions: true, questions: true, errors: true }) | 169 | 171 | expect(settings.sounds).toMatchObject({ agent: "custom", agentEnabled: false, permissions: "staplebops-02" }) | 170 | 172 | expect(decode(encode(settings))).toEqual(settings) | 171 | 173 | }) | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/settings/model.tsx +18-1Lines changed: 18 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -169,6 +169,7 @@ const workspacesSchema = Persistence.struct({ | 169 | 169 | const notificationsSchema = Persistence.struct({ | 170 | 170 | agent: Schema.Boolean, | 171 | 171 | permissions: Schema.Boolean, | | 172 | + questions: Schema.Boolean, | 172 | 173 | errors: Schema.Boolean, | 173 | 174 | }) | 174 | 175 |
| @@ -177,6 +178,8 @@ const soundsSchema = Persistence.struct({ | 177 | 178 | agent: Schema.String, | 178 | 179 | permissionsEnabled: Schema.Boolean, | 179 | 180 | permissions: Schema.String, | | 181 | + questionsEnabled: Schema.Boolean, | | 182 | + questions: Schema.String, | 180 | 183 | errorsEnabled: Schema.Boolean, | 181 | 184 | errors: Schema.String, | 182 | 185 | interfaceEnabled: Schema.optional(Schema.Boolean), | @@ -310,12 +313,14 @@ export const defaultSettings: Settings = { | 310 | 313 | keybinds: {}, | 311 | 314 | permissions: { autoApprove: false, autoApproveProjects: {} }, | 312 | 315 | workspaces: { defaultDestination: "last-used", lastUsed: {} }, | 313 | | - notifications: { agent: false, permissions: true, errors: false }, | | 316 | + notifications: { agent: false, permissions: true, questions: true, errors: false }, | 314 | 317 | sounds: { | 315 | 318 | agentEnabled: true, | 316 | 319 | agent: "staplebops-01", | 317 | 320 | permissionsEnabled: true, | 318 | 321 | permissions: "staplebops-02", | | 322 | + questionsEnabled: true, | | 323 | + questions: "staplebops-02", | 319 | 324 | errorsEnabled: true, | 320 | 325 | errors: "nope-03", | 321 | 326 | interfaceEnabled: true, | @@ -540,6 +545,10 @@ export const { use: useSettings, provider: SettingsProvider } = createSimpleCont | 540 | 545 | setPermissions(value: boolean) { | 541 | 546 | setStore("notifications", "permissions", value) | 542 | 547 | }, | | 548 | + questions: withFallback(() => store.notifications?.questions, defaultSettings.notifications.questions), | | 549 | + setQuestions(value: boolean) { | | 550 | + setStore("notifications", "questions", value) | | 551 | + }, | 543 | 552 | errors: withFallback(() => store.notifications?.errors, defaultSettings.notifications.errors), | 544 | 553 | setErrors(value: boolean) { | 545 | 554 | setStore("notifications", "errors", value) | @@ -565,6 +574,14 @@ export const { use: useSettings, provider: SettingsProvider } = createSimpleCont | 565 | 574 | setPermissions(value: string) { | 566 | 575 | setStore("sounds", "permissions", value) | 567 | 576 | }, | | 577 | + questionsEnabled: withFallback(() => store.sounds?.questionsEnabled, defaultSettings.sounds.questionsEnabled), | | 578 | + setQuestionsEnabled(value: boolean) { | | 579 | + setStore("sounds", "questionsEnabled", value) | | 580 | + }, | | 581 | + questions: withFallback(() => store.sounds?.questions, defaultSettings.sounds.questions), | | 582 | + setQuestions(value: string) { | | 583 | + setStore("sounds", "questions", value) | | 584 | + }, | 568 | 585 | errorsEnabled: withFallback(() => store.sounds?.errorsEnabled, defaultSettings.sounds.errorsEnabled), | 569 | 586 | setErrorsEnabled(value: boolean) { | 570 | 587 | setStore("sounds", "errorsEnabled", value) | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/settings/notifications/notifications.tsx +22-1Lines changed: 22 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -23,6 +23,11 @@ const soundSettings = { | 23 | 23 | title: "settings.general.sounds.permissions.title", | 24 | 24 | description: "settings.general.sounds.permissions.description", | 25 | 25 | }, | | 26 | + questions: { | | 27 | + action: "settings-sounds-questions", | | 28 | + title: "settings.general.sounds.questions.title", | | 29 | + description: "settings.general.sounds.questions.description", | | 30 | + }, | 26 | 31 | errors: { | 27 | 32 | action: "settings-sounds-errors", | 28 | 33 | title: "settings.general.sounds.errors.title", | @@ -31,7 +36,7 @@ const soundSettings = { | 31 | 36 | } as const | 32 | 37 |
| 33 | 38 | const SoundSetting: Component<{ | 34 | | - kind: "agent" | "permissions" | "errors" | | 39 | + kind: "agent" | "permissions" | "questions" | "errors" | 35 | 40 | channel: SoundSettingsController["agent"] | 36 | 41 | }> = (props) => { | 37 | 42 | const language = useLanguage() | @@ -100,6 +105,21 @@ export const SettingsNotifications: Component = () => { | 100 | 105 | </div> | 101 | 106 | </SettingsRow> | 102 | 107 |
| | 108 | + <SettingsRow | | 109 | + title={language.t("settings.general.notifications.questions.title")} | | 110 | + description={language.t("settings.general.notifications.questions.description")} | | 111 | + > | | 112 | + <div data-action="settings-notifications-questions"> | | 113 | + <Switch | | 114 | + hideLabel | | 115 | + checked={settings.notifications.questions()} | | 116 | + onChange={(checked) => settings.notifications.setQuestions(checked)} | | 117 | + > | | 118 | + {language.t("settings.general.notifications.questions.title")} | | 119 | + </Switch> | | 120 | + </div> | | 121 | + </SettingsRow> | | 122 | + | 103 | 123 | <SettingsRow | 104 | 124 | title={language.t("settings.general.notifications.errors.title")} | 105 | 125 | description={language.t("settings.general.notifications.errors.description")} | @@ -119,6 +139,7 @@ export const SettingsNotifications: Component = () => { | 119 | 139 | <SettingsList> | 120 | 140 | <SoundSetting kind="agent" channel={sounds.agent} /> | 121 | 141 | <SoundSetting kind="permissions" channel={sounds.permissions} /> | | 142 | + <SoundSetting kind="questions" channel={sounds.questions} /> | 122 | 143 | <SoundSetting kind="errors" channel={sounds.errors} /> | 123 | 144 | <SettingsRow | 124 | 145 | title={language.t("settings.general.sounds.interface.title")} | |
|