GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(app): add question notifications and sounds (#60358) · jonBoone/opencode@d09e2c6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/app
    • e2e
      • regression
        • settings.spec.ts
      • utils
        • notifications.ts
    • src
      • runtime/i18n
        • en.ts
      • settings
        • general
          • controllers.ts
        • model.test.ts
        • model.tsx
        • notifications
          • notifications.tsx
        • search-catalog.ts
      • shell/notifications
        • notification.tsx
    • test-browser
      • server-notification-state.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/app/e2e/regression/settings.spec.ts‎

Copy file name to clipboardExpand all lines: packages/app/e2e/regression/settings.spec.ts
+142Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { ConfigEntry, OpenCodeEvent, SessionMessageInfo, WorktreeDirectory
33
import { NO_PROVIDER, REMOTE_SERVER, SERVER, holdRoute, project, seed, session } from "../utils/app"
44
import { mockMissingLocation, mockOpenCodeServer } from "../utils/mock-server"
55
import { mockRemoteServer, mockWorkspace, openSession, openSettings, type WorkspaceInput } from "../utils/workspace"
6+
import { recordNotifications } from "../utils/notifications"
7+
import { installSseTransport } from "../utils/sse-transport"
68

79
const directory = "C:/Projects/settings-demo"
810

@@ -94,6 +96,146 @@ test("a settings page survives refresh", async ({ page }) => {
9496
await expect(page).toHaveURL("/settings?tab=appearance")
9597
})
9698

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+
97239
for (const locale of ["en", "ar"]) {
98240
test(`background activity alignment stays physical and persists (${locale})`, async ({ page }) => {
99241
const id = "ses_activity_settings"
Collapse file

‎packages/app/e2e/utils/notifications.ts‎

Copy file name to clipboard
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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

‎packages/app/src/runtime/i18n/en.ts‎

Copy file name to clipboardExpand all lines: packages/app/src/runtime/i18n/en.ts
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,8 @@ export const dict = {
550550
"error.chain.configInvalidWithMessage": "Config file at {{path}} is invalid: {{message}}",
551551

552552
"notification.permission.title": "Permission required",
553+
"notification.question.title": "Question requires an answer",
554+
"notification.elicitation.title": "Input requested",
553555

554556
"notification.session.responseReady.title": "Response ready",
555557
"notification.session.error.title": "Session error",
@@ -1055,13 +1057,17 @@ export const dict = {
10551057
"Show system notification when the agent is complete or needs attention",
10561058
"settings.general.notifications.permissions.title": "Permissions",
10571059
"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",
10581062
"settings.general.notifications.errors.title": "Errors",
10591063
"settings.general.notifications.errors.description": "Show system notification when an error occurs",
10601064

10611065
"settings.general.sounds.agent.title": "Agent",
10621066
"settings.general.sounds.agent.description": "Play sound when the agent is complete or needs attention",
10631067
"settings.general.sounds.permissions.title": "Permissions",
10641068
"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",
10651071
"settings.general.sounds.errors.title": "Errors",
10661072
"settings.general.sounds.errors.description": "Play sound when an error occurs",
10671073
"settings.general.sounds.interface.title": "Interface",
Collapse file

‎packages/app/src/settings/general/controllers.ts‎

Copy file name to clipboardExpand all lines: packages/app/src/settings/general/controllers.ts
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ export function createSoundSettingsController() {
177177
(value) => settings.sounds.setPermissionsEnabled(value),
178178
(id) => settings.sounds.setPermissions(id),
179179
),
180+
questions: channel(
181+
settings.sounds.questionsEnabled,
182+
settings.sounds.questions,
183+
(value) => settings.sounds.setQuestionsEnabled(value),
184+
(id) => settings.sounds.setQuestions(id),
185+
),
180186
errors: channel(
181187
settings.sounds.errorsEnabled,
182188
settings.sounds.errors,
Collapse file

‎packages/app/src/settings/model.test.ts‎

Copy file name to clipboardExpand all lines: packages/app/src/settings/model.test.ts
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,14 @@ describe("settings schema", () => {
112112
keybinds: {},
113113
permissions: { autoApprove: false, autoApproveProjects: {} },
114114
workspaces: { defaultDestination: "last-used", lastUsed: {} },
115-
notifications: { agent: false, permissions: true, errors: false },
115+
notifications: { agent: false, permissions: true, questions: true, errors: false },
116116
sounds: {
117117
agentEnabled: true,
118118
agent: "staplebops-01",
119119
permissionsEnabled: true,
120120
permissions: "staplebops-02",
121+
questionsEnabled: true,
122+
questions: "staplebops-02",
121123
errorsEnabled: true,
122124
errors: "nope-03",
123125
interfaceEnabled: true,
@@ -165,7 +167,7 @@ describe("settings schema", () => {
165167
expect(settings.permissions).toEqual({ autoApprove: true, autoApproveProjects: { on: true, off: false } })
166168
expect(settings.workspaces).toEqual({ defaultDestination: "new", lastUsed: { good: "workspace" } })
167169
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 })
169171
expect(settings.sounds).toMatchObject({ agent: "custom", agentEnabled: false, permissions: "staplebops-02" })
170172
expect(decode(encode(settings))).toEqual(settings)
171173
})
Collapse file

‎packages/app/src/settings/model.tsx‎

Copy file name to clipboardExpand all lines: packages/app/src/settings/model.tsx
+18-1Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ const workspacesSchema = Persistence.struct({
169169
const notificationsSchema = Persistence.struct({
170170
agent: Schema.Boolean,
171171
permissions: Schema.Boolean,
172+
questions: Schema.Boolean,
172173
errors: Schema.Boolean,
173174
})
174175

@@ -177,6 +178,8 @@ const soundsSchema = Persistence.struct({
177178
agent: Schema.String,
178179
permissionsEnabled: Schema.Boolean,
179180
permissions: Schema.String,
181+
questionsEnabled: Schema.Boolean,
182+
questions: Schema.String,
180183
errorsEnabled: Schema.Boolean,
181184
errors: Schema.String,
182185
interfaceEnabled: Schema.optional(Schema.Boolean),
@@ -310,12 +313,14 @@ export const defaultSettings: Settings = {
310313
keybinds: {},
311314
permissions: { autoApprove: false, autoApproveProjects: {} },
312315
workspaces: { defaultDestination: "last-used", lastUsed: {} },
313-
notifications: { agent: false, permissions: true, errors: false },
316+
notifications: { agent: false, permissions: true, questions: true, errors: false },
314317
sounds: {
315318
agentEnabled: true,
316319
agent: "staplebops-01",
317320
permissionsEnabled: true,
318321
permissions: "staplebops-02",
322+
questionsEnabled: true,
323+
questions: "staplebops-02",
319324
errorsEnabled: true,
320325
errors: "nope-03",
321326
interfaceEnabled: true,
@@ -540,6 +545,10 @@ export const { use: useSettings, provider: SettingsProvider } = createSimpleCont
540545
setPermissions(value: boolean) {
541546
setStore("notifications", "permissions", value)
542547
},
548+
questions: withFallback(() => store.notifications?.questions, defaultSettings.notifications.questions),
549+
setQuestions(value: boolean) {
550+
setStore("notifications", "questions", value)
551+
},
543552
errors: withFallback(() => store.notifications?.errors, defaultSettings.notifications.errors),
544553
setErrors(value: boolean) {
545554
setStore("notifications", "errors", value)
@@ -565,6 +574,14 @@ export const { use: useSettings, provider: SettingsProvider } = createSimpleCont
565574
setPermissions(value: string) {
566575
setStore("sounds", "permissions", value)
567576
},
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+
},
568585
errorsEnabled: withFallback(() => store.sounds?.errorsEnabled, defaultSettings.sounds.errorsEnabled),
569586
setErrorsEnabled(value: boolean) {
570587
setStore("sounds", "errorsEnabled", value)
Collapse file

‎packages/app/src/settings/notifications/notifications.tsx‎

Copy file name to clipboardExpand all lines: packages/app/src/settings/notifications/notifications.tsx
+22-1Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ const soundSettings = {
2323
title: "settings.general.sounds.permissions.title",
2424
description: "settings.general.sounds.permissions.description",
2525
},
26+
questions: {
27+
action: "settings-sounds-questions",
28+
title: "settings.general.sounds.questions.title",
29+
description: "settings.general.sounds.questions.description",
30+
},
2631
errors: {
2732
action: "settings-sounds-errors",
2833
title: "settings.general.sounds.errors.title",
@@ -31,7 +36,7 @@ const soundSettings = {
3136
} as const
3237

3338
const SoundSetting: Component<{
34-
kind: "agent" | "permissions" | "errors"
39+
kind: "agent" | "permissions" | "questions" | "errors"
3540
channel: SoundSettingsController["agent"]
3641
}> = (props) => {
3742
const language = useLanguage()
@@ -100,6 +105,21 @@ export const SettingsNotifications: Component = () => {
100105
</div>
101106
</SettingsRow>
102107

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+
103123
<SettingsRow
104124
title={language.t("settings.general.notifications.errors.title")}
105125
description={language.t("settings.general.notifications.errors.description")}
@@ -119,6 +139,7 @@ export const SettingsNotifications: Component = () => {
119139
<SettingsList>
120140
<SoundSetting kind="agent" channel={sounds.agent} />
121141
<SoundSetting kind="permissions" channel={sounds.permissions} />
142+
<SoundSetting kind="questions" channel={sounds.questions} />
122143
<SoundSetting kind="errors" channel={sounds.errors} />
123144
<SettingsRow
124145
title={language.t("settings.general.sounds.interface.title")}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.