Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

feat(web): notify the desktop of a new Another Me message

muterC53eaa5a0cd5c
diff --git a/apps/web/src/features/rooms/another-me-notifications.test.ts b/apps/web/src/features/rooms/another-me-notifications.test.ts
new file mode 100644
index 00000000..3e6c88ba
--- /dev/null
+++ b/apps/web/src/features/rooms/another-me-notifications.test.ts
@@ -0,0 +1,78 @@
+import { describe, expect, it } from "vitest";
+
+import type { TeamHubRoomListItem } from "@/features/teamhub/teamhub-types";
+
+import { anotherMeNotice } from "./another-me-notifications";
+
+const agent = {
+ id: "actor_agent",
+ tenant_id: "tenant_1",
+ kind: "agent",
+ display_name: "Another Me",
+} as const;
+const human = {
+ ...agent,
+ id: "actor_human",
+ kind: "human",
+ display_name: "Bo",
+} as const;
+
+function room(
+ latest?: Partial<NonNullable<TeamHubRoomListItem["latest_message"]>>,
+): TeamHubRoomListItem {
+ return {
+ id: "room_1",
+ tenant_id: "tenant_1",
+ kind: "direct",
+ name: "Another Me",
+ created_by: human,
+ created_at: "2026-11-11T00:00:00Z",
+ updated_at: "2026-11-11T00:00:00Z",
+ latest_room_seq: 2,
+ read_through_room_seq: 1,
+ unread_message_count: 1,
+ unread_mention_count: 0,
+ latest_message: latest
+ ? {
+ id: "msg_2",
+ room_seq: 2,
+ author: agent,
+ raw_message: "**Sam's birthday** is in 12 days.",
+ created_at: "2026-11-11T00:00:00Z",
+ ...latest,
+ }
+ : undefined,
+ };
+}
+
+describe("anotherMeNotice", () => {
+ it("announces a new Message from the Another Me as plain text", () => {
+ expect(anotherMeNotice(room({}), agent.id, "msg_1")).toEqual({
+ messageId: "msg_2",
+ title: "Another Me",
+ body: "Sam's birthday is in 12 days.",
+ });
+ });
+
+ it("stays quiet on the first reading, a seen Message, or the Human's own", () => {
+ expect(anotherMeNotice(room({}), agent.id, undefined)).toBeUndefined();
+ expect(anotherMeNotice(room({}), agent.id, "msg_2")).toBeUndefined();
+ expect(
+ anotherMeNotice(room({ author: human }), agent.id, "msg_1"),
+ ).toBeUndefined();
+ expect(anotherMeNotice(room(), agent.id, null)).toBeUndefined();
+ });
+
+ it("announces the first Message of an empty Chat", () => {
+ expect(anotherMeNotice(room({}), agent.id, null)?.messageId).toBe("msg_2");
+ });
+
+ it("shortens a long Message", () => {
+ const notice = anotherMeNotice(
+ room({ raw_message: "a".repeat(400) }),
+ agent.id,
+ "msg_1",
+ );
+ expect(notice?.body).toHaveLength(161);
+ });
+});
diff --git a/apps/web/src/features/rooms/another-me-notifications.ts b/apps/web/src/features/rooms/another-me-notifications.ts
new file mode 100644
index 00000000..bf286a23
--- /dev/null
+++ b/apps/web/src/features/rooms/another-me-notifications.ts
@@ -0,0 +1,79 @@
+import { useEffect, useRef } from "react";
+
+import { markdownPlainText } from "@/features/teamhub/markdown-plain-text";
+import type { TeamHubRoomListItem } from "@/features/teamhub/teamhub-types";
+
+const BODY_LIMIT = 160;
+
+export interface AnotherMeNotice {
+ messageId: string;
+ title: string;
+ body: string;
+}
+
+/**
+ * The system notice for the Another Me Chat's latest Message, when it is a new
+ * one from the Another Me itself. The first reading only records the latest
+ * Message, so loading the app never replays an old one.
+ */
+export function anotherMeNotice(
+ room: TeamHubRoomListItem | undefined,
+ agentActorId: string | undefined,
+ seenMessageId: string | null | undefined,
+): AnotherMeNotice | undefined {
+ const message = room?.latest_message;
+ if (!message || !agentActorId || seenMessageId === undefined) return;
+ if (message.id === seenMessageId || message.author.id !== agentActorId)
+ return;
+ const text = markdownPlainText(message.raw_message).trim();
+ if (!text) return;
+ return {
+ messageId: message.id,
+ title: message.author.display_name,
+ body: text.length > BODY_LIMIT ? `${text.slice(0, BODY_LIMIT)}…` : text,
+ };
+}
+
+/**
+ * Shows a system notification when the Another Me posts in its Chat while this
+ * window is not in front, such as a proactive reminder. Clicking it brings the
+ * window back on that Chat. Nothing is shown until the Human allowed
+ * notifications; the desktop app allows them for its own server.
+ */
+export function useAnotherMeNotifications({
+ rooms,
+ roomId,
+ agentActorId,
+ open,
+}: {
+ rooms: readonly TeamHubRoomListItem[] | undefined;
+ roomId: string | undefined;
+ agentActorId: string | undefined;
+ open: (roomId: string) => void;
+}) {
+ // undefined until the first reading; null when the Chat had no Message yet.
+ const seen = useRef<string | null | undefined>(undefined);
+ const room = roomId ? rooms?.find((item) => item.id === roomId) : undefined;
+
+ useEffect(() => {
+ if (!rooms || !roomId) return;
+ const notice = anotherMeNotice(room, agentActorId, seen.current);
+ seen.current = room?.latest_message?.id ?? null;
+ if (
+ !notice ||
+ typeof Notification === "undefined" ||
+ Notification.permission !== "granted" ||
+ document.hasFocus()
+ )
+ return;
+ const notification = new Notification(notice.title, {
+ body: notice.body,
+ tag: notice.messageId,
+ });
+ notification.onclick = () => {
+ window.focus();
+ open(roomId);
+ notification.close();
+ };
+ }, [agentActorId, open, room, roomId, rooms]);
+}
diff --git a/apps/web/src/features/rooms/room-shell.tsx b/apps/web/src/features/rooms/room-shell.tsx
index 5d57601e..d139025a 100644
--- a/apps/web/src/features/rooms/room-shell.tsx
+++ b/apps/web/src/features/rooms/room-shell.tsx
@@ -49,6 +49,7 @@ import {
RoomNavigationLoading,
} from "./route-loading-surface";
import { TeamHubEventSync } from "./event-sync";
+import { useAnotherMeNotifications } from "./another-me-notifications";
import { requireRoomRouteParam } from "./room-route-params";
import { useScrollPaneActivity } from "./use-scroll-pane-activity";
import {
@@ -120,6 +121,20 @@ function RoomShellReady({
}
}, [anotherMeRoomId, gated, navigate, tenantId]);
+ const openRoom = useCallback(
+ (roomId: string) =>
+ void navigate(
+ `/t/${encodeURIComponent(tenantId)}/rooms/${encodeURIComponent(roomId)}/chat`,
+ ),
+ [navigate, tenantId],
+ );
+ useAnotherMeNotifications({
+ rooms: roomsQuery.data?.items,
+ roomId: anotherMeRoomId,
+ agentActorId: anotherMe?.agent_actor_id,
+ open: openRoom,
+ });
+
useEffect(() => {
document.title = `${spaceOwnerName}'s space`;
}, [spaceOwnerName]);