Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(spaces): open a notification to read it in full (CUA-1636) (#5196)

ddupont45822615665b
diff --git a/apps/cua-spaces-desktop/src/bridge/methods.ts b/apps/cua-spaces-desktop/src/bridge/methods.ts
index f6f5df339d..3b58d72ec6 100644
--- a/apps/cua-spaces-desktop/src/bridge/methods.ts
+++ b/apps/cua-spaces-desktop/src/bridge/methods.ts
@@ -30,7 +30,7 @@ export const METHODS = [
"devices.get", "devices.enroll", "devices.checkEnrolled", "devices.approve", "devices.rename",
"devices.revoke", "devices.confirmMachine", "devices.createPairingCode", "devices.pairingCodes",
"devices.revokePairingCode", "teams.list", "storage.get", "storage.run",
- "notifications.list", "notifications.markAllRead",
+ "notifications.list", "notifications.markAllRead", "notifications.markRead",
"telemetry.track", "spaces.usage", "spaces.windows", "stream.pip",
"spaces.thumbnail",
"spaces.chooseFiles", "spaces.droppedFiles", "spaces.sendFiles",
diff --git a/apps/cua-spaces-desktop/src/bridge/notifications.ts b/apps/cua-spaces-desktop/src/bridge/notifications.ts
index de203d55ec..24acc737d3 100644
--- a/apps/cua-spaces-desktop/src/bridge/notifications.ts
+++ b/apps/cua-spaces-desktop/src/bridge/notifications.ts
@@ -18,11 +18,19 @@ export function notificationsMethods(ctx: BridgeContext): Handlers {
"notifications.list": async () => {
const n = feed();
await n.poll();
- return encode(n.feed);
+ // The core's entries, each with the Space it is about (Open Space).
+ return n.feed.map((e) => ({ ...(encode(e) as Record<string, unknown>), space: n.spaceOf(e.id) }));
},
"notifications.markAllRead": async () => {
await feed().markAllRead();
return null;
},
+ "notifications.markRead": async (args) => {
+ const n = feed();
+ const ids = args.ids;
+ if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string")) throw Failure.badArgs("ids: array of strings");
+ await n.markRead(ids);
+ return null;
+ },
};
}
diff --git a/apps/cua-spaces-desktop/src/model/notifications.ts b/apps/cua-spaces-desktop/src/model/notifications.ts
index 7182fcdfa2..3f8e5b4f45 100644
--- a/apps/cua-spaces-desktop/src/model/notifications.ts
+++ b/apps/cua-spaces-desktop/src/model/notifications.ts
@@ -18,6 +18,9 @@ const rows = (v: unknown, key: string): Record<string, unknown>[] => {
export class NotificationsModel {
feed: AppNotificationInput[] = [];
+ /** The Space each entry is about, by id (the core's input has no Space;
+ * the web page's Open Space reads it). */
+ private spaces = new Map<string, string>();
/** Cua Volume's sync status (the menu's sync line), when read. */
driveSync: AppDriveSyncInput | null = null;
/** `volume_storage`'s backend (the menu hides sync on this machine's store with no other device). */
@@ -65,6 +68,9 @@ export class NotificationsModel {
return;
}
this.feed = typed;
+ this.spaces = new Map(
+ rows(r, "notifications").flatMap((n) => (typeof n.id === "string" && typeof n.space === "string" && n.space ? [[n.id, n.space] as const] : [])),
+ );
const before = this.seen.get();
const plan = this.native.appNotificationsPlan(typed, before);
for (const note of plan.post) this.post?.(note);
@@ -77,6 +83,19 @@ export class NotificationsModel {
await this.poll();
}
+ /** Marks these entries read (one was opened); none marks nothing, never
+ * all (the daemon reads an empty list as every entry). */
+ async markRead(ids: string[]): Promise<void> {
+ if (!ids.length) return;
+ await this.call("notifications_ack", { ids }).catch(() => null);
+ await this.poll();
+ }
+
+ /** The Space entry `id` is about, if any (the daemon's `space`). */
+ spaceOf(id: string): string | null {
+ return this.spaces.get(id) ?? null;
+ }
+
/** The Volume's backend and sync status (the menu bar item polls them). */
async refreshSync(): Promise<void> {
const storage = await this.call("volume_storage").catch(() => null);
diff --git a/apps/cua-spaces-desktop/test/host-bridge.test.ts b/apps/cua-spaces-desktop/test/host-bridge.test.ts
index 11be934af2..f71189e948 100644
--- a/apps/cua-spaces-desktop/test/host-bridge.test.ts
+++ b/apps/cua-spaces-desktop/test/host-bridge.test.ts
@@ -50,7 +50,9 @@ const tick = (ms = 0) => new Promise((r) => setTimeout(r, ms));
/** The daemon's tools as the fixture daemon answers them. */
class ToolBackend extends FixtureSpacesBackend {
readonly tools: [string, Record<string, unknown>][] = [];
- notifications = [{ id: "n1", at_ms: 1000, agent: "ada", kind: "answer", title: "Done", body: "The report is ready", read: false }];
+ notifications: { id: string; at_ms: number; agent: string; kind: string; title: string; body: string; read: boolean; space?: string }[] = [
+ { id: "n1", at_ms: 1000, agent: "ada", kind: "answer", title: "Done", body: "The report is ready", read: false },
+ ];
agents: unknown[] = [];
override async tool(tool: string, args: Record<string, unknown> = {}): Promise<unknown> {
this.tools.push([tool, args]);
@@ -73,9 +75,12 @@ class ToolBackend extends FixtureSpacesBackend {
return { ok: true, reachable: true, authorized: true, versioning: true, detail: null, applied: !args.dry_run };
case "notifications_list":
return { notifications: this.notifications };
- case "notifications_ack":
- this.notifications = this.notifications.map((n) => ({ ...n, read: true }));
+ case "notifications_ack": {
+ // As the daemon's feed: no ids is every entry.
+ const ids = Array.isArray(args.ids) ? (args.ids as string[]) : [];
+ this.notifications = this.notifications.map((n) => (ids.length === 0 || ids.includes(n.id) ? { ...n, read: true } : n));
return {};
+ }
case "persistent_agent_list":
return { agents: this.agents };
case "volume_approve":
@@ -192,6 +197,7 @@ describe.skipIf(!built)("This machine, Devices and Settings on the app core", ()
["storage.get", {}],
["storage.run", { request: { kind: "clear-cache" } }],
["notifications.list", {}],
+ ["notifications.markRead", { ids: ["n1"] }],
["notifications.markAllRead", {}],
["host.setUp", { request: { mode: "direct", direct: "0.0.0.0:3211" } }],
["host.action", { action: "provide-spaces" }],
@@ -226,6 +232,7 @@ describe.skipIf(!built)("This machine, Devices and Settings on the app core", ()
"devices.confirmMachine": { id: "m2" },
"devices.createPairingCode": { team: null },
"devices.revokePairingCode": { id: "pc_fixture1" },
+ "notifications.markRead": { ids: ["n1"] },
"storage.run": { request: { kind: "clear-cache" } } as never,
"host.setUp": { request: { mode: "direct", direct: "0.0.0.0:3211" } } as never,
"host.action": { action: "provide-spaces" } as never,
@@ -699,6 +706,7 @@ describe.skipIf(!built)("This machine, Devices and Settings on the app core", ()
await make({ servicesIn: false });
expect(await code("volume.overview")).toBe("unsupported");
expect(await code("notifications.list")).toBe("unsupported");
+ expect(await code("notifications.markRead", { ids: ["n1"] })).toBe("unsupported");
expect(await code("storage.run", { request: { kind: "mount" } })).toBe("unsupported");
expect(await call("volume.storage")).toBeNull();
});
@@ -719,6 +727,32 @@ describe.skipIf(!built)("This machine, Devices and Settings on the app core", ()
expect(parts.notifications.feed[0]?.read).toBe(true);
});
+ it("marks one opened entry read, never all, and lists the Space each is about", async () => {
+ backend.notifications = [
+ { id: "n1", at_ms: 1000, agent: "ada", kind: "answer", title: "Done", body: "The report is ready", read: false, space: "local:dev" },
+ { id: "n2", at_ms: 2000, agent: "ada", kind: "message", title: "Ada", body: "Second", read: false },
+ ];
+ type Row = { id: string; read: boolean; space: string | null; body: string };
+ const list = async () => new Map(((await call("notifications.list")) as Row[]).map((r) => [r.id, r]));
+ const before = await list();
+ expect(before.get("n1")).toMatchObject({ space: "local:dev", read: false, body: "The report is ready" });
+ expect(before.get("n2")?.space).toBeNull();
+
+ expect(await call("notifications.markRead", { ids: ["n1"] })).toBeNull();
+ expect(backend.tools.filter(([t]) => t === "notifications_ack").at(-1)).toEqual(["notifications_ack", { ids: ["n1"] }]);
+ const after = await list();
+ expect(after.get("n1")?.read).toBe(true);
+ expect(after.get("n2")?.read).toBe(false);
+
+ // No ids marks nothing (the daemon would read it as every entry).
+ const acks = backend.tools.filter(([t]) => t === "notifications_ack").length;
+ await call("notifications.markRead", { ids: [] });
+ expect(backend.tools.filter(([t]) => t === "notifications_ack").length).toBe(acks);
+ expect((await list()).get("n2")?.read).toBe(false);
+ expect(await code("notifications.markRead", {})).toBe("bad_args");
+ expect(await code("notifications.markRead", { ids: [1] })).toBe("bad_args");
+ });
+
// MARK: The first run
it("is due until the page finishes it, which applies Launch at login and asks for Local Network", async () => {
diff --git a/apps/cua-spaces-desktop/test/host-fixtures.ts b/apps/cua-spaces-desktop/test/host-fixtures.ts
index d16e0811af..e7f465e4f2 100644
--- a/apps/cua-spaces-desktop/test/host-fixtures.ts
+++ b/apps/cua-spaces-desktop/test/host-fixtures.ts
@@ -306,7 +306,7 @@ export const HOST_METHODS = [
"about.get", "about.set", "about.checkNow", "loginItem.get", "loginItem.set", "loginItem.openSettings",
"devices.get", "devices.enroll", "devices.checkEnrolled", "devices.approve", "devices.rename", "devices.revoke", "devices.confirmMachine",
"devices.createPairingCode", "devices.pairingCodes", "devices.revokePairingCode", "teams.list",
- "storage.get", "storage.run", "notifications.list", "notifications.markAllRead",
+ "storage.get", "storage.run", "notifications.list", "notifications.markAllRead", "notifications.markRead",
"host.setUp", "host.action", "host.openSettings", "settings.get", "settings.choose",
"onboarding.get", "onboarding.complete",
];
@@ -318,6 +318,6 @@ export const HOST_OPS = [
"about.get", "about.set", "about.checkNow", "loginItem.get", "loginItem.set", "loginItem.openSettings",
"devices.get", "devices.enroll", "devices.checkEnrolled", "devices.approve", "devices.rename", "devices.revoke", "devices.confirmMachine",
"devices.createPairingCode", "devices.pairingCodes", "devices.revokePairingCode", "teams.list",
- "storage.get", "storage.run", "notifications.list", "notifications.markAllRead",
+ "storage.get", "storage.run", "notifications.list", "notifications.markAllRead", "notifications.markRead",
"host.setUp", "host.action", "host.openSettings", "settings.get", "settings.set", "settings.choose", "experiments.set", "session.completeOnboarding",
];
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/PersistentModel.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/PersistentModel.swift
index c4223952f0..d31a60e9a8 100644
--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/PersistentModel.swift
+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/PersistentModel.swift
@@ -58,6 +58,9 @@ public final class PersistentModel {
NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: full)])
}
public private(set) var feed: [AppNotificationInput] = []
+ /// The Space each feed entry is about, by id (the core's input has no
+ /// Space; the web page's Open Space reads it).
+ private var feedSpaces: [String: String] = [:]
/// Cua Volume's sync status (the menu bar's sync line), when read.
public private(set) var driveSync: AppDriveSyncInput?
/// `volume_storage`'s backend (the menu hides sync on this Mac's store
@@ -295,6 +298,10 @@ public final class PersistentModel {
}
guard let typed = try? appNotificationsFromJson(json: json(rows)) else { return }
feed = typed
+ feedSpaces = Dictionary(r.arr("notifications").compactMap { n -> (String, String)? in
+ guard let id = n["id"] as? String, let space = n["space"] as? String, !space.isEmpty else { return nil }
+ return (id, space)
+ }, uniquingKeysWith: { a, _ in a })
let seen = seenMs()
let plan = appNotificationsPlan(feed: typed, seenMs: seen)
plan.post.forEach { post?($0) }
@@ -306,6 +313,24 @@ public final class PersistentModel {
await pollNotifications()
}
+ /// Marks these entries read (one was opened); none marks nothing, never
+ /// all (the daemon reads an empty list as every entry).
+ public func markRead(ids: [String]) async {
+ guard !ids.isEmpty else { return }
+ _ = try? await call("notifications_ack", ["ids": ids])
+ await pollNotifications()
+ }
+
+ /// The feed as the web page reads it (`NotificationInput`): the core's
+ /// entries, each with the Space it is about when it has one.
+ func feedRows() -> [[String: Any]] {
+ feed.map { n in
+ var row = (BridgeValue.encode(n) as? [String: Any]) ?? [:]
+ row["space"] = feedSpaces[n.id] ?? NSNull()
+ return row
+ }
+ }
+
/// Polls every `seconds` while the app runs (the daemon owns the feed).
public func startPolling(every seconds: Double = 5) -> Task<Void, Never> {
Task { [weak self] in
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIBridge+Pages.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIBridge+Pages.swift
index 2b3646fe79..72c7095d25 100644
--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIBridge+Pages.swift
+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIBridge+Pages.swift
@@ -139,11 +139,16 @@ extension WebUIBridge {
case "notifications.list":
guard model.persistent.canCallTools else { throw Failure.unsupported("Notifications need the cua daemon") }
await model.persistent.pollNotifications()
- return BridgeValue.encode(model.persistent.feed)
+ return model.persistent.feedRows()
case "notifications.markAllRead":
guard model.persistent.canCallTools else { throw Failure.unsupported("Notifications need the cua daemon") }
await model.persistent.markAllRead()
return NSNull()
+ case "notifications.markRead":
+ guard model.persistent.canCallTools else { throw Failure.unsupported("Notifications need the cua daemon") }
+ guard let ids = args["ids"] as? [String] else { throw Failure.badArgs("ids: array of strings") }
+ await model.persistent.markRead(ids: ids)
+ return NSNull()
// Usage events
case "telemetry.track":
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIBridge.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIBridge.swift
index e77c7b907a..b59ec31a68 100644
--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIBridge.swift
+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIBridge.swift
@@ -89,7 +89,7 @@ final class WebUIBridge: NSObject, WKScriptMessageHandlerWithReply {
"devices.get", "devices.enroll", "devices.checkEnrolled", "devices.approve", "devices.rename",
"devices.revoke", "devices.confirmMachine", "devices.createPairingCode", "devices.pairingCodes",
"devices.revokePairingCode", "teams.list", "storage.get", "storage.run",
- "notifications.list", "notifications.markAllRead",
+ "notifications.list", "notifications.markAllRead", "notifications.markRead",
"telemetry.track", "spaces.usage", "spaces.windows", "stream.pip",
// A Space's thumbnail (WebUIBridge+Thumbnails.swift).
"spaces.thumbnail",
diff --git a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/AgentsPagesTests.swift b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/AgentsPagesTests.swift
index 2d108b609a..893b6a630d 100644
--- a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/AgentsPagesTests.swift
+++ b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/AgentsPagesTests.swift
@@ -15,6 +15,11 @@ final class FakeAgentsTools: AgentsToolRunning, @unchecked Sendable {
var paused = false
var grants: [[String: Any]] = []
let now: Int64 = 1_790_000_000_000
+ /// The feed (`notifications_list`); `notifications_ack` marks entries read.
+ lazy var notifications: [[String: Any]] = [
+ ["id": "n1", "at_ms": now - 60_000, "agent": "ada", "kind": "turn_ended", "title": "ada", "body": "Your research is ready.",
+ "space": "local:dev", "read": false],
+ ]
/// The model calls this from concurrent tasks; one lock keeps the
/// recorded calls and state consistent.
private let lock = NSLock()
@@ -53,7 +58,17 @@ final class FakeAgentsTools: AgentsToolRunning, @unchecked Sendable {
return ["requests": [["id": "q1", "principal": "agent:ada", "prefix": "agents/writer/outputs/", "mode": "r", "reason": "cite the draft"]]]
case "volume_grants": return ["grants": []]
case "notifications_list":
- return ["notifications": [["id": "n1", "at_ms": now - 60_000, "agent": "ada", "kind": "turn_ended", "title": "ada", "body": "Your research is ready.", "read": false]]]
+ return ["notifications": notifications]
+ case "notifications_ack":
+ // As the daemon's feed: no ids is every entry.
+ let ids = args["ids"] as? [String] ?? []
+ var marked = 0
+ notifications = notifications.map { n in
+ guard ids.isEmpty || ids.contains(n["id"] as? String ?? ""), n["read"] as? Bool != true else { return n }
+ marked += 1
+ return n.merging(["read": true]) { _, new in new }
+ }
+ return ["marked": marked]
default: throw AgentsToolError(message: "unknown tool \(tool)")
}
}
diff --git a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/BridgeContractTests.swift b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/BridgeContractTests.swift
index 18ad212846..e0a3ab19ba 100644
--- a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/BridgeContractTests.swift
+++ b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/BridgeContractTests.swift
@@ -231,7 +231,7 @@ struct BridgeContractTests {
("teams.list", [:]),
("devices.revokePairingCode", ["id": "pc_fixture1"]),
("storage.get", [:]), ("storage.run", ["request": ["kind": "clear-cache"]]),
- ("notifications.list", [:]), ("notifications.markAllRead", [:]),
+ ("notifications.list", [:]), ("notifications.markRead", ["ids": ["n1"]]), ("notifications.markAllRead", [:]),
("telemetry.track", ["signals": [["type": "step", "step": "app_launched", "ok": true]]]),
("spaces.usage", ["spaceId": space]), ("spaces.windows", ["spaceId": space]),
("spaces.thumbnail", ["spaceId": space]),
diff --git a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/WebUIHostTests.swift b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/WebUIHostTests.swift
index 1237e7e0f5..1e8b573deb 100644
--- a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/WebUIHostTests.swift
+++ b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/WebUIHostTests.swift
@@ -283,6 +283,34 @@ struct WebUIHostTests {
#expect(removed?.first { $0["agent"] as? String == "claude-code" }?["configured"] as? Bool == false)
}
+ /// The page opens one notification and marks just that one read; the
+ /// list carries the Space each entry is about (its Open Space).
+ @Test func oneNotificationIsMarkedReadAndCarriesItsSpace() async throws {
+ let backend = BridgeContractTests.ToolBackend(FixtureSpacesBackend())
+ backend.agents.notifications.append(["id": "n2", "at_ms": backend.agents.now - 30_000, "agent": "ada", "kind": "message",
+ "title": "ada", "body": "Second.", "read": false])
+ let (bridge, _) = bridge(backend: backend)
+ func list() async throws -> [String: [String: Any]] {
+ let rows = try await bridge.handle("notifications.list", [:]) as? [[String: Any]] ?? []
+ return Dictionary(rows.map { ($0["id"] as? String ?? "", $0) }, uniquingKeysWith: { a, _ in a })
+ }
+ let before = try await list()
+ #expect(before["n1"]?["space"] as? String == "local:dev")
+ #expect(before["n2"]?["space"] is NSNull)
+ #expect(before["n1"]?["body"] as? String == "Your research is ready.")
+ #expect(before["n1"]?["read"] as? Bool == false)
+
+ #expect(try await bridge.handle("notifications.markRead", ["ids": ["n1"]]) is NSNull)
+ let after = try await list()
+ #expect(after["n1"]?["read"] as? Bool == true)
+ #expect(after["n2"]?["read"] as? Bool == false)
+
+ // No ids marks nothing (the daemon would read it as every entry).
+ _ = try await bridge.handle("notifications.markRead", ["ids": [String]()])
+ #expect(try await list()["n2"]?["read"] as? Bool == false)
+ #expect(await failure(bridge, "notifications.markRead", [:]) == "bad_args")
+ }
+
@Test func persistentAgentsListAsCamelCaseRecords() async throws {
let m = PersistentModel(tools: FakeAgentsTools())
let agents = try await m.listAgents()
@@ -426,6 +454,7 @@ struct WebUIHostTests {
let (bridge, _) = bridge()
#expect(await failure(bridge, "volume.overview", [:]) == "unsupported")
#expect(await failure(bridge, "notifications.list", [:]) == "unsupported")
+ #expect(await failure(bridge, "notifications.markRead", ["ids": ["n1"]]) == "unsupported")
#expect(await failure(bridge, "about.set", ["autoCheck": true]) == "unsupported")
#expect(await failure(bridge, "host.openSettings", ["url": "https://example.com"]) == "bad_args")
#expect(await failure(bridge, "volume.reveal", ["path": "/etc/hosts"]) == "bad_args")
diff --git a/apps/cua-spaces-web/src/__tests__/notifications-open.test.tsx b/apps/cua-spaces-web/src/__tests__/notifications-open.test.tsx
new file mode 100644
index 0000000000..4f2c2702a4
--- /dev/null
+++ b/apps/cua-spaces-web/src/__tests__/notifications-open.test.tsx
@@ -0,0 +1,116 @@
+// SPDX-License-Identifier: FSL-1.1-MIT
+// Copyright (c) 2026 Cua AI, Inc.
+
+// Notifications (CUA-1636): a line opens in place to its whole title and
+// body, and closes again; opening it marks that one entry read; one about a
+// Space offers Open Space, which goes to that Space's page. Mouse and
+// keyboard alike.
+
+import { act, cleanup, fireEvent, waitFor } from "@testing-library/react";
+import { afterEach, describe, expect, it } from "vitest";
+import type { NotificationInput } from "@/bridge";
+import { wasmBuilt } from "@/bridge/__tests__/testCore";
+import { mountApp, stubBrowserApis } from "./app-harness";
+
+afterEach(cleanup);
+stubBrowserApis();
+
+const LONG = `The nightly build passed on all three Spaces. ${"Every suite ran green, the flaky stream test included, and the release notes are drafted. ".repeat(4)}\nSecond paragraph: two follow-ups are in your Volume.`;
+
+async function mount(spaceId: string | null) {
+ const now = Date.now();
+ let feed: NotificationInput[] = [
+ { id: "n-long", atMs: now - 60_000, agent: "hermes", kind: "message", title: "hermes", body: LONG, read: false, space: spaceId },
+ { id: "n-old", atMs: now - 3_600_000, agent: "ada", kind: "turn_ended", title: "ada", body: "Done.", read: true },
+ ];
+ const acks: string[][] = [];
+ const app = await mountApp("/notifications", {
+ failsCreates: false,
+ listsGhost: false,
+ intercept: (op, args) => {
+ if (op === "notifications.list") return feed.map((n) => ({ ...n }));
+ if (op === "notifications.markRead") {
+ const { ids } = args as { ids: string[] };
+ acks.push(ids);
+ feed = feed.map((n) => (ids.includes(n.id) ? { ...n, read: true } : n));
+ return null;
+ }
+ return undefined;
+ },
+ });
+ await waitFor(() => expect(row("n-long")).not.toBeNull(), { timeout: 8000 });
+ return { ...app, acks };
+}
+
+const row = (id: string) => document.querySelector<HTMLElement>(`[data-notification="${id}"]`);
+const toggle = (id: string) => row(id)!.querySelector<HTMLButtonElement>("[data-notification-toggle]")!;
+const text = (id: string) => row(id)!.querySelector<HTMLElement>("[data-notification-text]")!;
+
+describe.skipIf(!wasmBuilt)("Notifications page", () => {
+ it("opens a cut-off line in place to the whole text, marks it read, and closes it again", async () => {
+ const { acks } = await mount(null);
+ expect(row("n-long")!.dataset.unread).toBe("true");
+ expect(toggle("n-long").getAttribute("aria-expanded")).toBe("false");
+ expect(text("n-long").className).toContain("truncate");
+ // The cut-off tooltip is gone: opening the line is how to read it.
+ expect(text("n-long").hasAttribute("title")).toBe(false);
+ expect(row("n-long")!.querySelector("[data-notification-detail]")).toBeNull();
+
+ await act(async () => fireEvent.click(toggle("n-long")));
+ expect(toggle("n-long").getAttribute("aria-expanded")).toBe("true");
+ const detail = row("n-long")!.querySelector<HTMLElement>("[data-notification-detail]")!;
+ expect(toggle("n-long").getAttribute("aria-controls")).toBe(detail.id);
+ expect(text("n-long").className).not.toContain("truncate");
+ expect(text("n-long").textContent).toBe("hermes");
+ expect(detail.querySelector("[data-notification-body]")!.textContent).toBe(LONG.trim());
+ expect(detail.querySelector("[data-notification-open-space]")).toBeNull();
+
+ await waitFor(() => expect(acks).toEqual([["n-long"]]));
+ await waitFor(() => expect(row("n-long")!.dataset.unread).toBe("false"));
+ expect(document.querySelector("[data-mark-all]")).toBeNull();
+
+ await act(async () => fireEvent.click(toggle("n-long")));
+ expect(toggle("n-long").getAttribute("aria-expanded")).toBe("false");
+ expect(row("n-long")!.querySelector("[data-notification-detail]")).toBeNull();
+ expect(text("n-long").className).toContain("truncate");
+ });
+
+ it("does not ack an entry that is already read", async () => {
+ const { acks } = await mount(null);
+ await act(async () => fireEvent.click(toggle("n-old")));
+ expect(row("n-old")!.querySelector("[data-notification-body]")!.textContent).toBe("Done.");
+ await new Promise((r) => setTimeout(r, 50));
+ expect(acks).toEqual([]);
+ });
+
+ it("is a focusable native button, so Enter and Space open and close it", async () => {
+ await mount(null);
+ const button = toggle("n-long");
+ // A <button type="button"> turns Enter and Space into its click in every
+ // browser (jsdom has no such activation, so the click stands in for it).
+ expect(button.tagName).toBe("BUTTON");
+ expect(button.type).toBe("button");
+ expect(button.tabIndex).toBe(0);
+ button.focus();
+ expect(document.activeElement).toBe(button);
+ await act(async () => button.click());
+ expect(button.getAttribute("aria-expanded")).toBe("true");
+ expect(document.activeElement).toBe(button);
+ await act(async () => button.click());
+ expect(button.getAttribute("aria-expanded")).toBe("false");
+ });
+
+ it("offers Open Space for a note about a Space, and it goes to that Space's page", async () => {
+ const { demo } = await mount(null);
+ const spaces = (await demo.call("spaces.list" as never, {} as never)) as { id: string }[];
+ const spaceId = spaces[0]!.id;
+ cleanup();
+ const app = await mount(spaceId);
+ await act(async () => fireEvent.click(toggle("n-long")));
+ const open = row("n-long")!.querySelector<HTMLElement>("[data-notification-open-space]")!;
+ expect(open.textContent).toBe("Open Space");
+ expect(row("n-old")!.querySelector("[data-notification-open-space]")).toBeNull();
+ await act(async () => fireEvent.click(open));
+ await waitFor(() => expect(app.router.state.location.pathname).toBe(`/spaces/${encodeURIComponent(spaceId)}`));
+ });
+});
diff --git a/apps/cua-spaces-web/src/bridge/README.md b/apps/cua-spaces-web/src/bridge/README.md
index 3380f5a2a2..3f951b439d 100644
--- a/apps/cua-spaces-web/src/bridge/README.md
+++ b/apps/cua-spaces-web/src/bridge/README.md
@@ -438,6 +438,7 @@ mechanism. Types are in `contracts/settings.ts`, `contracts/devices.ts` and
| `storage.run` | `{ request: StorageRequest }` | `DriveCheckInput` for test, save and adopt; else `null` | `agents_tool` (`volume_*`), `drive_reveal`, `host_open_settings` | `StorageModel`'s request runner |
| `notifications.list` | `{}` | `NotificationInput[]` (camelCase) | `agents_tool` `notifications_list` | `PersistentModel.feed` |
| `notifications.markAllRead` | `{}` | `null` | `agents_tool` `notifications_ack {ids: []}` | `PersistentModel.markAllRead` |
+| `notifications.markRead` | `{ ids }` | `null` | `agents_tool` `notifications_ack {ids}` (nothing for no ids) | `PersistentModel.markRead(ids:)` |
**Electron.** The Swift host's methods, as they are ported
(`apps/cua-spaces-desktop/test/not-yet.ts`).
diff --git a/apps/cua-spaces-web/src/bridge/__tests__/contract-args.ts b/apps/cua-spaces-web/src/bridge/__tests__/contract-args.ts
index d83572c83a..abedb05925 100644
--- a/apps/cua-spaces-web/src/bridge/__tests__/contract-args.ts
+++ b/apps/cua-spaces-web/src/bridge/__tests__/contract-args.ts
@@ -123,6 +123,7 @@ export const DEMO_ARGS: { [K in OpName]: OpArgs<K> } = {
"storage.run": { request: { kind: "clear-cache" } },
"notifications.list": {},
"notifications.markAllRead": {},
+ "notifications.markRead": { ids: ["n1"] },
"telemetry.track": { signals: [{ type: "step", step: "app_launched", ok: true }] },
"spaces.usage": { spaceId: SPACE },
"spaces.windows": { spaceId: SPACE },
diff --git a/apps/cua-spaces-web/src/bridge/__tests__/coverage.test.ts b/apps/cua-spaces-web/src/bridge/__tests__/coverage.test.ts
index bb96aa2595..7c9c670c45 100644
--- a/apps/cua-spaces-web/src/bridge/__tests__/coverage.test.ts
+++ b/apps/cua-spaces-web/src/bridge/__tests__/coverage.test.ts
@@ -107,6 +107,7 @@ const ARGS: { [K in OpName]: OpArgs<K> } = {
"storage.run": { request: { kind: "clear-cache" } },
"notifications.list": {},
"notifications.markAllRead": {},
+ "notifications.markRead": { ids: ["n1"] },
"telemetry.track": { signals: [{ type: "step", step: "app_launched", ok: true }] },
"spaces.usage": { spaceId: "s1" },
"spaces.windows": { spaceId: "s1" },
diff --git a/apps/cua-spaces-web/src/bridge/__tests__/hosts.test.ts b/apps/cua-spaces-web/src/bridge/__tests__/hosts.test.ts
index 7cbd89ebb2..eb916ab9d2 100644
--- a/apps/cua-spaces-web/src/bridge/__tests__/hosts.test.ts
+++ b/apps/cua-spaces-web/src/bridge/__tests__/hosts.test.ts
@@ -109,6 +109,7 @@ describe("tauri adapter", () => {
spaceId: "s",
agents: null,
signals: [],
+ ids: ["n1"],
// storage.run takes a StorageRequest; host.setUp the host form's request.
request: op === "host.setUp" ? { mode: "relay" } : { kind: "clear-cache" },
action: "stop-sharing",
diff --git a/apps/cua-spaces-web/src/bridge/adapters/demo/settings.ts b/apps/cua-spaces-web/src/bridge/adapters/demo/settings.ts
index a10b5d07ac..c9c1a6c504 100644
--- a/apps/cua-spaces-web/src/bridge/adapters/demo/settings.ts
+++ b/apps/cua-spaces-web/src/bridge/adapters/demo/settings.ts
@@ -344,5 +344,9 @@ export function createDemoSettings(ctx: DemoSettingsContext): Handlers {
feed = feed.map((n) => ({ ...n, read: true }));
return null;
},
+ "notifications.markRead": ({ ids }) => {
+ feed = feed.map((n) => (ids.includes(n.id) ? { ...n, read: true } : n));
+ return null;
+ },
};
}
diff --git a/apps/cua-spaces-web/src/bridge/contracts/bridge-shapes.json b/apps/cua-spaces-web/src/bridge/contracts/bridge-shapes.json
index 35170159a0..8c78af5486 100644
--- a/apps/cua-spaces-web/src/bridge/contracts/bridge-shapes.json
+++ b/apps/cua-spaces-web/src/bridge/contracts/bridge-shapes.json
@@ -1753,6 +1753,12 @@
},
"read": {
"type": "boolean"
+ },
+ "space": {
+ "type": [
+ "string",
+ "null"
+ ]
}
},
"required": [
@@ -4498,6 +4504,9 @@
"notifications.markAllRead": {
"type": "null"
},
+ "notifications.markRead": {
+ "type": "null"
+ },
"presence.join": {
"type": "object",
"properties": {
@@ -6011,6 +6020,9 @@
"notifications.markAllRead": {
"type": "null"
},
+ "notifications.markRead": {
+ "type": "null"
+ },
"relay.usage": {
"type": [
"object",
diff --git a/apps/cua-spaces-web/src/bridge/contracts/notifications.ts b/apps/cua-spaces-web/src/bridge/contracts/notifications.ts
index 7c7ecdf1c5..e5a8f2d63f 100644
--- a/apps/cua-spaces-web/src/bridge/contracts/notifications.ts
+++ b/apps/cua-spaces-web/src/bridge/contracts/notifications.ts
@@ -18,6 +18,8 @@ export interface NotificationInput {
title: string;
body: string;
read?: boolean;
+ /** The Space it is about (a Space id), when the daemon says. */
+ space?: string | null;
}
export interface SystemNote {
diff --git a/apps/cua-spaces-web/src/bridge/contracts/shapes.ts b/apps/cua-spaces-web/src/bridge/contracts/shapes.ts
index f8f738f104..b66bc1c8bb 100644
--- a/apps/cua-spaces-web/src/bridge/contracts/shapes.ts
+++ b/apps/cua-spaces-web/src/bridge/contracts/shapes.ts
@@ -366,7 +366,7 @@ const VolumeShape = ref(
const NotificationShape = ref(
"NotificationInput",
- obj<NotificationInput>()({ id: str, atMs: num, agent: optNull(str), kind: str, title: str, body: str, read: opt(bool) }),
+ obj<NotificationInput>()({ id: str, atMs: num, agent: optNull(str), kind: str, title: str, body: str, read: opt(bool), space: optNull(str) }),
);
const AgentKeysShape = ref(
@@ -854,6 +854,7 @@ export const OP_SHAPES: Record<OpName, Schema> = {
"storage.run": nullable(DriveCheckShape),
"notifications.list": list(NotificationShape),
"notifications.markAllRead": nul,
+ "notifications.markRead": nul,
"telemetry.track": nul,
"spaces.usage": nullable(
@@ -1162,6 +1163,7 @@ export const WEBKIT_SHAPES: Partial<Record<WebkitMethod, Schema>> = {
"storage.run": nullable(DriveCheckShape),
"notifications.list": list(NotificationShape),
"notifications.markAllRead": nul,
+ "notifications.markRead": nul,
"telemetry.track": nul,
"spaces.usage": OP_SHAPES["spaces.usage"],
"spaces.windows": OP_SHAPES["spaces.windows"],
diff --git a/apps/cua-spaces-web/src/bridge/coverage.ts b/apps/cua-spaces-web/src/bridge/coverage.ts
index 66c3451c53..06e2164ca3 100644
--- a/apps/cua-spaces-web/src/bridge/coverage.ts
+++ b/apps/cua-spaces-web/src/bridge/coverage.ts
@@ -156,6 +156,7 @@ export const HOST_COVERAGE = {
// Notifications (ops/notifications.ts).
"notifications.list": { webkit: { methods: ["notifications.list"] }, tauri: NT["notifications.list"] },
"notifications.markAllRead": { webkit: { methods: ["notifications.markAllRead"] }, tauri: NT["notifications.markAllRead"] },
+ "notifications.markRead": { webkit: { methods: ["notifications.markRead"] }, tauri: NT["notifications.markRead"] },
...TELEMETRY_COVERAGE,
...SPACE_DETAIL_COVERAGE,
...HOST_SETUP_COVERAGE,
diff --git a/apps/cua-spaces-web/src/bridge/ops/notifications.ts b/apps/cua-spaces-web/src/bridge/ops/notifications.ts
index 4d5805b64b..86a617497c 100644
--- a/apps/cua-spaces-web/src/bridge/ops/notifications.ts
+++ b/apps/cua-spaces-web/src/bridge/ops/notifications.ts
@@ -16,11 +16,13 @@ export interface NotificationsOperations {
"notifications.list": { args: Empty; result: NotificationInput[] };
/** Marks every entry read (`notifications_ack` with no ids). */
"notifications.markAllRead": { args: Empty; result: null };
+ /** Marks these entries read (`notifications_ack` with their ids). */
+ "notifications.markRead": { args: { ids: string[] }; result: null };
}
export type NotificationsOpName = keyof NotificationsOperations;
-export const NOTIFICATIONS_OPERATIONS = ["notifications.list", "notifications.markAllRead"] as const satisfies readonly NotificationsOpName[];
+export const NOTIFICATIONS_OPERATIONS = ["notifications.list", "notifications.markAllRead", "notifications.markRead"] as const satisfies readonly NotificationsOpName[];
type Handlers = { [K in NotificationsOpName]: (args: NotificationsOperations[K]["args"]) => Promise<NotificationsOperations[K]["result"]> };
type Invoke = <T>(cmd: string, args?: Record<string, unknown>) => Promise<T>;
@@ -38,6 +40,7 @@ export function notificationsFromTool(answer: unknown): NotificationInput[] {
title: String(n.title ?? ""),
body: String(n.body ?? ""),
read: Boolean(n.read),
+ space: typeof n.space === "string" && n.space ? n.space : null,
};
});
}
@@ -50,10 +53,16 @@ export function tauriNotificationsOps(invoke: Invoke): Handlers {
await invoke("agents_tool", { tool: "notifications_ack", args: { ids: [] } });
return null;
},
+ "notifications.markRead": async ({ ids }) => {
+ // An empty list would mark every entry read.
+ if (ids.length) await invoke("agents_tool", { tool: "notifications_ack", args: { ids } });
+ return null;
+ },
};
}
export const NOTIFICATIONS_TAURI_COMMANDS = {
"notifications.list": ["agents_tool"],
"notifications.markAllRead": ["agents_tool"],
+ "notifications.markRead": ["agents_tool"],
} as const satisfies Record<NotificationsOpName, readonly string[]>;
diff --git a/apps/cua-spaces-web/src/bridge/ops/webkit-pages.ts b/apps/cua-spaces-web/src/bridge/ops/webkit-pages.ts
index 270da1e842..eb6fb6672d 100644
--- a/apps/cua-spaces-web/src/bridge/ops/webkit-pages.ts
+++ b/apps/cua-spaces-web/src/bridge/ops/webkit-pages.ts
@@ -85,6 +85,7 @@ export const WEBKIT_PAGE_OPS = [
"storage.run",
"notifications.list",
"notifications.markAllRead",
+ "notifications.markRead",
"telemetry.track",
"spaces.usage",
"spaces.windows",
@@ -258,6 +259,7 @@ export function webkitPageOps(request: Request, toHostStatus: (h: WkHostState) =
"storage.run": call("storage.run"),
"notifications.list": list("notifications.list"),
"notifications.markAllRead": none("notifications.markAllRead"),
+ "notifications.markRead": none("notifications.markRead"),
// Only known signals of fixed words leave the page; the host drops
// them all while usage data is off.
diff --git a/apps/cua-spaces-web/src/bridge/settings-feature.ts b/apps/cua-spaces-web/src/bridge/settings-feature.ts
index e4946d5b68..88e3a19b2a 100644
--- a/apps/cua-spaces-web/src/bridge/settings-feature.ts
+++ b/apps/cua-spaces-web/src/bridge/settings-feature.ts
@@ -706,12 +706,33 @@ export class SettingsFeature {
await this.refresh("notifications");
}
+ /** Marks one entry read (it was opened): this app's own entries here,
+ * the daemon's through `notifications.markRead`. Shown read at once. */
+ async markRead(id: string): Promise<void> {
+ if (this.local.some((n) => n.id === id && !n.read)) {
+ this.local = this.local.map((n) => (n.id === id ? { ...n, read: true } : n));
+ this.saveLocal();
+ this.publish("notifications");
+ return;
+ }
+ if (!this.feed.some((n) => n.id === id && !n.read)) return;
+ this.feed = this.feed.map((n) => (n.id === id ? { ...n, read: true } : n));
+ this.publish("notifications");
+ if (this.pinned.has("notifications")) return;
+ await this.adapter.call("notifications.markRead", { ids: [id] });
+ // A poll that started before the ack may answer it unread: read again after it.
+ await this.inflight.get("notifications");
+ await this.refresh("notifications");
+ }
+
/** Adds one of this app's own entries (a Space became ready, a create
* failed and why) to the list, so a missed toast can still be read. */
- record(note: { kind: "message" | "error"; title: string; body?: string }): void {
+ record(note: { kind: "message" | "error"; title: string; body?: string; space?: string }): void {
const atMs = this.options.now();
const id = `app:${atMs}:${Math.random().toString(36).slice(2, 8)}`;
- this.local = [...this.local, { id, atMs, agent: null, kind: note.kind, title: note.title, body: note.body ?? "", read: false }].slice(-LOCAL_LIMIT);
+ const entry: NotificationInput = { id, atMs, agent: null, kind: note.kind, title: note.title, body: note.body ?? "", read: false };
+ if (note.space) entry.space = note.space;
+ this.local = [...this.local, entry].slice(-LOCAL_LIMIT);
this.saveLocal();
if (this.resources.notifications.data !== undefined) this.publish("notifications");
}
diff --git a/apps/cua-spaces-web/src/bridge/settings-hooks.ts b/apps/cua-spaces-web/src/bridge/settings-hooks.ts
index 57c4243124..7d5bb5d6aa 100644
--- a/apps/cua-spaces-web/src/bridge/settings-hooks.ts
+++ b/apps/cua-spaces-web/src/bridge/settings-hooks.ts
@@ -157,13 +157,15 @@ export function useStorageSettings(): StorageHook {
export interface NotificationsHook extends Hook<NotificationsData> {
markAllRead(): Promise<void>;
+ /** Marks one entry read (it was opened). */
+ markRead(id: string): Promise<void>;
}
/** The daemon's notifications feed, polled every 5 s while the app is open. */
export function useNotifications(): NotificationsHook {
const r = useFeature<NotificationsData>("notifications");
const run = useRun();
- return { ...r, markAllRead: () => run((f) => f.markAllRead()) };
+ return { ...r, markAllRead: () => run((f) => f.markAllRead()), markRead: (id) => run((f) => f.markRead(id)) };
}
/** Calls `listener` for each entry the core says to announce. */
diff --git a/apps/cua-spaces-web/src/bridge/store.ts b/apps/cua-spaces-web/src/bridge/store.ts
index 5d777943c9..8cdd9ae4cf 100644
--- a/apps/cua-spaces-web/src/bridge/store.ts
+++ b/apps/cua-spaces-web/src/bridge/store.ts
@@ -568,7 +568,7 @@ export class BridgeStore {
this.createRequests.delete(pendingId);
await this.refresh("spaces");
const space = (this.resources.spaces.data as Space[] | undefined)?.find((s) => s.id === row.id) ?? rowsToSpaces(this.core, [row], this.now())[0]!;
- this.extras.record({ kind: "message", title: `${space.name} is ready` });
+ this.extras.record({ kind: "message", title: `${space.name} is ready`, space: space.id });
return space;
} catch (e) {
const message = toError(e).message;
diff --git a/apps/cua-spaces-web/src/bridge/webkit-protocol.ts b/apps/cua-spaces-web/src/bridge/webkit-protocol.ts
index ccd28a32b8..7d81419f4a 100644
--- a/apps/cua-spaces-web/src/bridge/webkit-protocol.ts
+++ b/apps/cua-spaces-web/src/bridge/webkit-protocol.ts
@@ -121,6 +121,7 @@ export const WEBKIT_METHODS = [
"storage.run",
"notifications.list",
"notifications.markAllRead",
+ "notifications.markRead",
"telemetry.track",
"spaces.usage",
"spaces.windows",
diff --git a/apps/cua-spaces-web/src/routes/notifications/index.tsx b/apps/cua-spaces-web/src/routes/notifications/index.tsx
index 71c09df65d..5eca21b5ef 100644
--- a/apps/cua-spaces-web/src/routes/notifications/index.tsx
+++ b/apps/cua-spaces-web/src/routes/notifications/index.tsx
@@ -1,10 +1,11 @@
// SPDX-License-Identifier: FSL-1.1-MIT
// Copyright (c) 2026 Cua AI, Inc.
-import { createFileRoute } from "@tanstack/react-router";
+import { createFileRoute, Link } from "@tanstack/react-router";
import { BellIcon } from "lucide-react";
+import { useState } from "react";
-import { useNotifications } from "@/bridge";
+import { useNotifications, type NotificationInput, type NotificationLine } from "@/bridge";
import { EmptyState, Page, PageHeader } from "@/components/page";
import { Button } from "@/components/ui/button";
import { toastError } from "@/components/ui/toast";
@@ -14,12 +15,26 @@ export const Route = createFileRoute("/notifications/")({ component: Notificatio
/**
* Notifications: the daemon's feed, one line each, newest first, unread in
- * bold, and Mark all read while any is unread. Everything shown is the app
- * core's `notifications::view`, as in the SwiftUI app's `NotificationsPageView`.
+ * bold, and Mark all read while any is unread. Each line is the app core's
+ * `notifications::view`, as in the SwiftUI app's `NotificationsPageView`.
+ * Clicking a line opens it in place (the whole title and body, and Open
+ * Space when it is about one) and marks it read; clicking again closes it.
*/
function NotificationsPage() {
- const { data, unsupported, error, markAllRead } = useNotifications();
+ const { data, unsupported, error, markAllRead, markRead } = useNotifications();
const view = data?.view;
+ const [open, setOpen] = useState<ReadonlySet<string>>(() => new Set());
+ const toggle = (row: NotificationLine) => {
+ const opening = !open.has(row.id);
+ setOpen((was) => {
+ const next = new Set(was);
+ if (opening) next.add(row.id);
+ else next.delete(row.id);
+ return next;
+ });
+ // Reading it is the point; a host that can't mark one read just leaves it bold.
+ if (opening && row.on) void markRead(row.id).catch(() => undefined);
+ };
return (
<Page className="max-w-3xl">
<PageHeader
@@ -45,18 +60,55 @@ function NotificationsPage() {
) : (
<div className="divide-y overflow-hidden rounded-xl border bg-card shadow-xs" data-notifications>
{view.rows.map((row) => (
- <div key={row.id} data-notification={row.id} data-unread={String(Boolean(row.on))} className="flex min-h-11 items-center gap-3 px-4 py-2.5">
- <span className={cn("size-1.5 shrink-0 rounded-full", row.on ? "bg-brand" : "bg-transparent")} aria-hidden />
- <span className={cn("min-w-0 flex-1 truncate text-[13px]", row.on && "font-semibold")} title={row.text} data-notification-text>
- {row.text}
- </span>
- <span className="shrink-0 text-xs text-muted-foreground tabular-nums" data-notification-time>
- {row.trailing}
- </span>
- </div>
+ <NotificationRow
+ key={row.id}
+ row={row}
+ entry={data?.feed.find((n) => n.id === row.id)}
+ open={open.has(row.id)}
+ onToggle={() => toggle(row)}
+ />
))}
</div>
)}
</Page>
);
}
+
+function NotificationRow({ row, entry, open, onToggle }: { row: NotificationLine; entry: NotificationInput | undefined; open: boolean; onToggle: () => void }) {
+ const detailId = `notification-${row.id}`;
+ const body = entry?.body.trim() ?? "";
+ return (
+ <div data-notification={row.id} data-unread={String(Boolean(row.on))} data-open={String(open)}>
+ <button
+ type="button"
+ aria-expanded={open}
+ aria-controls={open ? detailId : undefined}
+ onClick={onToggle}
+ className="flex min-h-11 w-full cursor-default items-center gap-3 px-4 py-2.5 text-left outline-none hover:bg-accent/50 focus-visible:bg-accent/50 focus-visible:ring-2 focus-visible:ring-ring/60 focus-visible:ring-inset"
+ data-notification-toggle
+ >
+ <span className={cn("size-1.5 shrink-0 rounded-full", row.on ? "bg-brand" : "bg-transparent")} aria-hidden />
+ <span className={cn("min-w-0 flex-1 text-[13px]", open ? "break-words" : "truncate", row.on && "font-semibold")} data-notification-text>
+ {open ? (entry?.title ?? row.text) : row.text}
+ </span>
+ <span className={cn("shrink-0 text-xs text-muted-foreground tabular-nums", open && "self-start pt-0.5")} data-notification-time>
+ {row.trailing}
+ </span>
+ </button>
+ {open ? (
+ <div id={detailId} className="space-y-2.5 pr-4 pb-3 pl-[2.125rem]" data-notification-detail>
+ {entry && body ? (
+ <p className="whitespace-pre-wrap break-words text-[13px] text-muted-foreground" data-notification-body>
+ {body}
+ </p>
+ ) : null}
+ {entry?.space ? (
+ <Button variant="outline" size="sm" render={<Link to="/spaces/$spaceId" params={{ spaceId: entry.space }} />} data-notification-open-space>
+ Open Space
+ </Button>
+ ) : null}
+ </div>
+ ) : null}
+ </div>
+ );
+}