GeezerVison is showing github.com — feat(app): OS notifications for Agent HQ asks and tasks ready for review · Mikedan37/opencodeSpicyEdition@0291040
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/ide-discoverability.spec.ts +94Lines changed: 94 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -130,6 +130,100 @@ test("the one-time card points at the strip and the panel; dismissed, it stays g | 130 | 130 | await expect(card).toHaveCount(0) | 131 | 131 | }) | 132 | 132 |
| | 133 | +test("an agent's ask and a task ready for review raise OS notifications that open them", async ({ page }) => { | | 134 | + // The browser's Notification, recorded, with the window out of focus (notify only fires when it is). | | 135 | + await page.addInitScript(() => { | | 136 | + const sent: { title: string; body: string }[] = [] | | 137 | + const scope = window as unknown as Record<string, unknown> | | 138 | + scope.__notifications = sent | | 139 | + scope.Notification = class { | | 140 | + static permission = "granted" | | 141 | + static requestPermission = async () => "granted" | | 142 | + onclick: (() => void) | null = null | | 143 | + constructor(title: string, options?: { body?: string }) { | | 144 | + sent.push({ title, body: options?.body ?? "" }) | | 145 | + scope.__lastNotification = this | | 146 | + } | | 147 | + close() {} | | 148 | + } | | 149 | + document.hasFocus = () => false | | 150 | + }) | | 151 | + const { mock, open } = await mockWorkbench(page, { directory, title }) | | 152 | + mock.agents = [{ ...ada, projectDirectory: directory }] | | 153 | + const session = { | | 154 | + id: "ags_1", | | 155 | + agentID: "agt_ada", | | 156 | + provider: "opencode", | | 157 | + title: "Notes", | | 158 | + status: "working", | | 159 | + pendingPermissions: 0, | | 160 | + createdAt: 1, | | 161 | + updatedAt: 1, | | 162 | + } | | 163 | + mock.agentSessions = [session] | | 164 | + const task = { | | 165 | + id: "tsk_1", | | 166 | + title: "Write the notes", | | 167 | + assignee: "agt_ada", | | 168 | + dependsOn: [], | | 169 | + status: "running", | | 170 | + isolated: false, | | 171 | + createdAt: 1, | | 172 | + updatedAt: 1, | | 173 | + } | | 174 | + mock.tasks = [task] | | 175 | + await open() | | 176 | + const sent = () => page.evaluate(() => (window as unknown as { __notifications: unknown[] }).__notifications) | | 177 | + const strip = page.locator('[data-component="workbench-status"]') | | 178 | + await expect(strip.locator('[data-status="agents"]')).toHaveText("Agents") | | 179 | + | | 180 | + // The agent asks: a notification, and the strip counts it. | | 181 | + mock.emit( | | 182 | + { | | 183 | + type: "agenthq.session.event", | | 184 | + properties: { | | 185 | + envelope: { | | 186 | + sessionID: "ags_1", | | 187 | + seq: 0, | | 188 | + at: 2, | | 189 | + event: { | | 190 | + type: "permission.requested", | | 191 | + requestID: "perm_1", | | 192 | + title: "Edit notes.txt", | | 193 | + options: [{ id: "once", label: "Allow once", kind: "allow_once" }], | | 194 | + }, | | 195 | + }, | | 196 | + }, | | 197 | + }, | | 198 | + { | | 199 | + type: "agenthq.session.updated", | | 200 | + properties: { session: { ...session, status: "needs_approval", pendingPermissions: 1, updatedAt: 2 } }, | | 201 | + }, | | 202 | + ) | | 203 | + await expect.poll(sent).toEqual([{ title: "Permission required", body: "Ada asks: Edit notes.txt" }]) | | 204 | + await expect(strip.locator('[data-status="agents"]')).toHaveText("Agents1 needs you") | | 205 | + // Clicking it opens the agent's session in the Agents tab. | | 206 | + await page.evaluate(() => | | 207 | + (window as unknown as { __lastNotification: { onclick: () => void } }).__lastNotification.onclick(), | | 208 | + ) | | 209 | + await expect(page.locator('[data-component="workbench-panel"]')).toHaveAttribute("data-tab", "agents") | | 210 | + await expect(page.locator('[data-component="agenthq-workspace"] [data-session="ags_1"]')).toHaveAttribute( | | 211 | + "aria-current", | | 212 | + "true", | | 213 | + ) | | 214 | + | | 215 | + // The task reaches review: one notification, not one per later update. | | 216 | + mock.emit({ type: "agenthq.task.updated", properties: { task: { ...task, status: "review", updatedAt: 3 } } }) | | 217 | + mock.emit({ type: "agenthq.task.updated", properties: { task: { ...task, status: "review", updatedAt: 4 } } }) | | 218 | + await expect.poll(sent).toHaveLength(2) | | 219 | + expect((await sent())[1]).toEqual({ | | 220 | + title: "Ready for review", | | 221 | + body: "Write the notes by Ada is waiting for your review", | | 222 | + }) | | 223 | + await page.waitForTimeout(500) | | 224 | + expect(await sent()).toHaveLength(2) | | 225 | +}) | | 226 | + | 133 | 227 | async function palette(page: Page, command: string) { | 134 | 228 | await openPalette(page) | 135 | 229 | await page.getByPlaceholder("Search files, commands, and sessions").fill(command) | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/e2e/utils/workbench-mock.ts +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -48,8 +48,9 @@ export async function mockWorkbench( | 48 | 48 | files: {} as Record<string, string>, | 49 | 49 | debugSessions: [] as unknown[], | 50 | 50 | doctor: undefined as unknown, | 51 | | - // GET /agenthq/agents, /agenthq/tasks | | 51 | + // GET /agenthq/agents, /agenthq/agents/:id/sessions, /agenthq/tasks | 52 | 52 | agents: [] as unknown[], | | 53 | + agentSessions: [] as { agentID: string }[], | 53 | 54 | tasks: [] as unknown[], | 54 | 55 | // What the app sent: this session's prompts, Agent HQ messages, checks, config changes, permission replies. | 55 | 56 | prompts: [] as { path: string; body: unknown }[], | @@ -158,6 +159,12 @@ export async function mockWorkbench( | 158 | 159 | const path = new URL(request.url()).pathname | 159 | 160 | if (path === "/agenthq/agents" && request.method() === "GET") return json(route, mock.agents) | 160 | 161 | if (path === "/agenthq/tasks" && request.method() === "GET") return json(route, mock.tasks) | | 162 | + const sessionsOf = path.match(/^\/agenthq\/agents\/([^/]+)\/sessions$/)?.[1] | | 163 | + if (sessionsOf && request.method() === "GET") | | 164 | + return json( | | 165 | + route, | | 166 | + mock.agentSessions.filter((item) => item.agentID === sessionsOf), | | 167 | + ) | 161 | 168 | if (path === "/agenthq/messages" && request.method() === "POST") { | 162 | 169 | const body = request.postDataJSON() as { to: string; text: string } | 163 | 170 | mock.messages.push(body) | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/agenthq/context.tsx +39-1Lines changed: 39 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -6,6 +6,10 @@ import { AgentHQ } from "@opencode-ai/schema/agent-hq" | 6 | 6 | import { useSDK } from "@/context/sdk" | 7 | 7 | import { useServerSDK } from "@/context/server-sdk" | 8 | 8 | import { usePlatform } from "@/context/platform" | | 9 | +import { useCommand } from "@/context/command" | | 10 | +import { useLanguage } from "@/context/language" | | 11 | +import { useSettings } from "@/context/settings" | | 12 | +import { playSoundById } from "@/utils/sound" | 9 | 13 | import { Persist, persisted } from "@/utils/persist" | 10 | 14 | import { createAgentHQStore } from "./store" | 11 | 15 | import { createTasksState } from "./tasks" | @@ -29,6 +33,9 @@ export const { use: useAgentHQ, provider: AgentHQProvider } = createSimpleContex | 29 | 33 | const sdk = useSDK() | 30 | 34 | const serverSDK = useServerSDK() | 31 | 35 | const platform = usePlatform() | | 36 | + const settings = useSettings() | | 37 | + const command = useCommand() | | 38 | + const language = useLanguage() | 32 | 39 | // The session page remounts this provider per workspace, so the directory is fixed for its lifetime. | 33 | 40 | const directory = sdk().directory | 34 | 41 | const client = createWorkbenchClient({ server: serverSDK().server.http, directory, fetch: platform.fetch }) | @@ -74,12 +81,34 @@ export const { use: useAgentHQ, provider: AgentHQProvider } = createSimpleContex | 74 | 81 | (error: unknown) => store.failHistory(sessionID, errorText(error)), | 75 | 82 | ) | 76 | 83 |
| | 84 | + // UX #6: an agent's permission ask and a task ready for review reach the user like the main session's asks do | | 85 | + // (the same sound and OS notification settings); the notification opens it in the Agents tab. | | 86 | + const alertUser = (title: string, description: string, open: () => void) => { | | 87 | + if (settings.sounds.permissionsEnabled()) void playSoundById(settings.sounds.permissions()) | | 88 | + if (settings.notifications.permissions()) | | 89 | + void platform.notify(title, description, () => { | | 90 | + open() | | 91 | + command.trigger("workbench.agents") | | 92 | + }) | | 93 | + } | | 94 | + const agentName = (agentID: string | undefined) => | | 95 | + store.state.agents.find((agent) => agent.id === agentID)?.name ?? agentID ?? "" | | 96 | + | 77 | 97 | // Every project's events: an agent's events carry its own project directory, which may not be the open one. | 78 | 98 | const stop = serverSDK().event.listen((event) => { | 79 | 99 | const details = event.details as { type?: string; properties?: unknown } | 80 | 100 | if (!details.type?.startsWith("agenthq.")) return | 81 | 101 | if (details.type === "agenthq.session.event") | 82 | 102 | return Option.map(events[details.type](details.properties), (data) => { | | 103 | + const asked = data.envelope.event | | 104 | + if (asked.type === "permission.requested") { | | 105 | + const agentID = store.state.sessions[data.envelope.sessionID]?.agentID | | 106 | + alertUser( | | 107 | + language.t("notification.permission.title"), | | 108 | + language.t("agenthq.notify.permission", { agent: agentName(agentID), title: asked.title }), | | 109 | + () => setUi({ view: "agents", agentID, sessionID: data.envelope.sessionID }), | | 110 | + ) | | 111 | + } | 83 | 112 | if (store.receive(data.envelope) === "gap") void resync(data.envelope.sessionID) | 84 | 113 | }) | 85 | 114 | if (details.type === "agenthq.session.updated") | @@ -91,7 +120,16 @@ export const { use: useAgentHQ, provider: AgentHQProvider } = createSimpleContex | 91 | 120 | if (details.type === "agenthq.provider.updated") | 92 | 121 | return Option.map(events[details.type](details.properties), (data) => store.upsertProvider(data.provider)) | 93 | 122 | if (details.type === "agenthq.task.updated") | 94 | | - return Option.map(events[details.type](details.properties), (data) => tasks.upsert(data.task)) | | 123 | + return Option.map(events[details.type](details.properties), (data) => { | | 124 | + const before = tasks.state.tasks.find((task) => task.id === data.task.id)?.status | | 125 | + if (data.task.status === "review" && before !== "review") | | 126 | + alertUser( | | 127 | + language.t("agenthq.notify.review.title"), | | 128 | + language.t("agenthq.notify.review", { task: data.task.title, agent: agentName(data.task.assignee) }), | | 129 | + () => setUi({ view: "tasks", taskID: data.task.id, agentID: undefined, sessionID: undefined }), | | 130 | + ) | | 131 | + tasks.upsert(data.task) | | 132 | + }) | 95 | 133 | if (details.type === "agenthq.task.removed") | 96 | 134 | return Option.map(events[details.type](details.properties), (data) => tasks.remove(data.id)) | 97 | 135 | if (details.type === "agenthq.message") | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/workbench/en.ts +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -603,4 +603,7 @@ export const dict = { | 603 | 603 | "agenthq.message.placeholder": "Write a message", | 604 | 604 | "agenthq.message.notDelivered": "Not delivered", | 605 | 605 | "agenthq.message.failed": "Message not sent", | | 606 | + "agenthq.notify.permission": "{{agent}} asks: {{title}}", | | 607 | + "agenthq.notify.review.title": "Ready for review", | | 608 | + "agenthq.notify.review": "{{task}} by {{agent}} is waiting for your review", | 606 | 609 | } |
|