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): OS notifications for Agent HQ asks and tasks ready for review · Mikedan37/opencodeSpicyEdition@0291040

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/app
    • e2e
      • regression
        • ide-discoverability.spec.ts
      • utils
        • workbench-mock.ts
    • src
      • agenthq
        • context.tsx
      • workbench
        • en.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/app/e2e/regression/ide-discoverability.spec.ts‎

Copy file name to clipboardExpand all lines: packages/app/e2e/regression/ide-discoverability.spec.ts
+94Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,100 @@ test("the one-time card points at the strip and the panel; dismissed, it stays g
130130
await expect(card).toHaveCount(0)
131131
})
132132

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+
133227
async function palette(page: Page, command: string) {
134228
await openPalette(page)
135229
await page.getByPlaceholder("Search files, commands, and sessions").fill(command)
Collapse file

‎packages/app/e2e/utils/workbench-mock.ts‎

Copy file name to clipboardExpand all lines: packages/app/e2e/utils/workbench-mock.ts
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ export async function mockWorkbench(
4848
files: {} as Record<string, string>,
4949
debugSessions: [] as unknown[],
5050
doctor: undefined as unknown,
51-
// GET /agenthq/agents, /agenthq/tasks
51+
// GET /agenthq/agents, /agenthq/agents/:id/sessions, /agenthq/tasks
5252
agents: [] as unknown[],
53+
agentSessions: [] as { agentID: string }[],
5354
tasks: [] as unknown[],
5455
// What the app sent: this session's prompts, Agent HQ messages, checks, config changes, permission replies.
5556
prompts: [] as { path: string; body: unknown }[],
@@ -158,6 +159,12 @@ export async function mockWorkbench(
158159
const path = new URL(request.url()).pathname
159160
if (path === "/agenthq/agents" && request.method() === "GET") return json(route, mock.agents)
160161
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+
)
161168
if (path === "/agenthq/messages" && request.method() === "POST") {
162169
const body = request.postDataJSON() as { to: string; text: string }
163170
mock.messages.push(body)
Collapse file

‎packages/app/src/agenthq/context.tsx‎

Copy file name to clipboardExpand all lines: packages/app/src/agenthq/context.tsx
+39-1Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { AgentHQ } from "@opencode-ai/schema/agent-hq"
66
import { useSDK } from "@/context/sdk"
77
import { useServerSDK } from "@/context/server-sdk"
88
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"
913
import { Persist, persisted } from "@/utils/persist"
1014
import { createAgentHQStore } from "./store"
1115
import { createTasksState } from "./tasks"
@@ -29,6 +33,9 @@ export const { use: useAgentHQ, provider: AgentHQProvider } = createSimpleContex
2933
const sdk = useSDK()
3034
const serverSDK = useServerSDK()
3135
const platform = usePlatform()
36+
const settings = useSettings()
37+
const command = useCommand()
38+
const language = useLanguage()
3239
// The session page remounts this provider per workspace, so the directory is fixed for its lifetime.
3340
const directory = sdk().directory
3441
const client = createWorkbenchClient({ server: serverSDK().server.http, directory, fetch: platform.fetch })
@@ -74,12 +81,34 @@ export const { use: useAgentHQ, provider: AgentHQProvider } = createSimpleContex
7481
(error: unknown) => store.failHistory(sessionID, errorText(error)),
7582
)
7683

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+
7797
// Every project's events: an agent's events carry its own project directory, which may not be the open one.
7898
const stop = serverSDK().event.listen((event) => {
7999
const details = event.details as { type?: string; properties?: unknown }
80100
if (!details.type?.startsWith("agenthq.")) return
81101
if (details.type === "agenthq.session.event")
82102
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+
}
83112
if (store.receive(data.envelope) === "gap") void resync(data.envelope.sessionID)
84113
})
85114
if (details.type === "agenthq.session.updated")
@@ -91,7 +120,16 @@ export const { use: useAgentHQ, provider: AgentHQProvider } = createSimpleContex
91120
if (details.type === "agenthq.provider.updated")
92121
return Option.map(events[details.type](details.properties), (data) => store.upsertProvider(data.provider))
93122
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+
})
95133
if (details.type === "agenthq.task.removed")
96134
return Option.map(events[details.type](details.properties), (data) => tasks.remove(data.id))
97135
if (details.type === "agenthq.message")
Collapse file

‎packages/app/src/workbench/en.ts‎

Copy file name to clipboardExpand all lines: packages/app/src/workbench/en.ts
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,4 +603,7 @@ export const dict = {
603603
"agenthq.message.placeholder": "Write a message",
604604
"agenthq.message.notDelivered": "Not delivered",
605605
"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",
606609
}

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.