Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002) | 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; | |
| 3 | ||
| 4 | import type { MemberProfile } from "@g1t/contracts"; | |
| 5 | ||
| Write a thread up in Docs from chat; cards' buttons in notifications; a session's card stays at the top of its thread | 6 | import { asksToAct, conversationHref, countsAfterRead, messageDeliveries, notificationCard, preview, recipients, type Person } from "./notify.ts"; |
| Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002) | 7 | |
| 8 | const person = (id: string, username: string, muted = false): Person => ({ key: `user:${id}`, user_id: id, username, muted }); | |
| 9 | const ana = person("u1", "ana"); | |
| 10 | const bo = person("u2", "bo"); | |
| 11 | const cy = person("u3", "cy", true); | |
| 12 | ||
| 13 | const kinds = (list: ReturnType<typeof recipients>) => Object.fromEntries(list.map((r) => [r.user_id, r.kind])); | |
| 14 | ||
| 15 | test("a direct message notifies everyone else in it, muted or not, never the author", () => { | |
| 16 | const out = recipients({ author: "user:u1", channelKind: "dm", people: [ana, bo, cy], mentioned: [], thread: null }); | |
| 17 | assert.deepEqual(kinds(out), { u2: "dm", u3: "dm" }); | |
| 18 | }); | |
| 19 | ||
| 20 | test("in a channel, a mention notifies the person named even when muted; the rest only count", () => { | |
| 21 | const out = recipients({ author: "user:u1", channelKind: "channel", people: [ana, bo, cy], mentioned: ["CY"], thread: null }); | |
| 22 | assert.deepEqual(kinds(out), { u2: null, u3: "mention" }); | |
| 23 | assert.deepEqual( | |
| 24 | out.map((r) => [r.user_id, r.mentioned, r.muted]), | |
| 25 | [ | |
| 26 | ["u2", false, false], | |
| 27 | ["u3", true, true], | |
| 28 | ], | |
| 29 | ); | |
| 30 | }); | |
| 31 | ||
| 32 | test("a reply notifies the people in its thread unless they muted the conversation", () => { | |
| 33 | const out = recipients({ author: "user:u1", channelKind: "channel", people: [ana, bo, cy], mentioned: [], thread: new Set(["user:u1", "user:u2", "user:u3"]) }); | |
| 34 | assert.deepEqual(kinds(out), { u2: "thread_reply", u3: null }); | |
| 35 | }); | |
| 36 | ||
| 37 | test("an agent's message notifies the people in its DM and counts for everyone", () => { | |
| 38 | const out = recipients({ author: "agent:a1", channelKind: "dm", people: [ana], mentioned: [], thread: null }); | |
| 39 | assert.deepEqual(kinds(out), { u1: "dm" }); | |
| 40 | }); | |
| 41 | ||
| 42 | test("deliveries: counts for everyone, a notification for those it is for, the author's count cleared", () => { | |
| 43 | const author: MemberProfile = { kind: "user", id: "u1", name: "ana", display_name: "Ana Lima", avatar: "abc", role: null, avatar_seed: null }; | |
| 44 | const items = messageDeliveries({ | |
| 45 | slug: "acme", | |
| 46 | channel: { id: "chn_1", kind: "channel", name: "design" }, | |
| 47 | message: { id: "msg_1", author: "user:u1", body: "hey **@bo** look", card_title: null, thread_root: null, created_at: "2026-10-08T00:00:00Z" }, | |
| 48 | author, | |
| 49 | recipients: recipients({ author: "user:u1", channelKind: "channel", people: [ana, bo, cy], mentioned: ["bo"], thread: null }), | |
| 50 | }); | |
| 51 | assert.equal(items.length, 3); | |
| 52 | const [toBo, toCy, self] = items; | |
| 53 | assert.deepEqual(toBo.counts, { channel_id: "chn_1", unread: 1, mentions: 1, muted: false }); | |
| 54 | assert.equal(toBo.notification?.kind, "mention"); | |
| 55 | assert.equal(toBo.notification?.title, "Ana Lima in #design"); | |
| 56 | assert.equal(toBo.notification?.body, "hey @bo look"); | |
| 57 | assert.equal(toBo.notification?.href, "/acme/-/chat/design"); | |
| 58 | assert.equal(toBo.notification?.actor.avatar, "abc"); | |
| 59 | assert.deepEqual(toCy.counts, { channel_id: "chn_1", unread: 1, mentions: 0, muted: true }); | |
| 60 | assert.equal(toCy.notification, null); | |
| 61 | assert.deepEqual(self, { user_id: "u1", workspace: "acme", counts: { channel_id: "chn_1", unread: 0, mentions: 0, set: true }, notification: null }); | |
| 62 | }); | |
| 63 | ||
| Cards you act on in chat; agents comment and review as themselves; names shown cleanly; commits on the calendar | 64 | test("a person without a display name is named by their username as they wrote it", () => { |
| 65 | const author: MemberProfile = { kind: "user", id: "u1", name: "ana", display_username: "Ana", display_name: "", avatar: null, role: null, avatar_seed: null }; | |
| 66 | const [toBo] = messageDeliveries({ | |
| 67 | slug: "acme", | |
| 68 | channel: { id: "chn_9", kind: "dm", name: null }, | |
| 69 | message: { id: "msg_2", author: "user:u1", body: "hi", card_title: null, thread_root: null, created_at: "2026-10-08T00:00:00Z" }, | |
| 70 | author, | |
| 71 | recipients: recipients({ author: "user:u1", channelKind: "dm", people: [ana, bo], mentioned: [], thread: null }), | |
| 72 | }); | |
| 73 | assert.equal(toBo.notification?.title, "Ana"); | |
| 74 | assert.equal(toBo.notification?.actor.name, "Ana"); | |
| 75 | }); | |
| 76 | ||
| Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002) | 77 | test("a reply links to its thread; a DM to the DM", () => { |
| 78 | assert.equal(conversationHref("acme", { id: "chn_9", kind: "dm", name: null }, null), "/acme/-/chat/dm/chn_9"); | |
| 79 | assert.equal(conversationHref("acme", { id: "chn_1", kind: "channel", name: "ops" }, "msg_1"), "/acme/-/chat/ops?thread=msg_1"); | |
| 80 | }); | |
| 81 | ||
| 82 | test("previews are one short line without markup", () => { | |
| 83 | assert.equal(preview("**bold** and `code`\n\nnext [link](https://x)"), "bold and code next link"); | |
| Merge main into Artifacts Phase 2 | 84 | assert.equal(preview("```\nlong code\n```"), "long code"); |
| 85 | assert.equal(preview("## Done\n- shipped **#412** in #web\n- see \\*notes\\*"), "Done shipped #412 in #web see *notes*"); | |
| 86 | assert.equal(preview("snake_case and ~/src stay, <b>as typed</b>"), "snake_case and ~/src stay, <b>as typed</b>"); | |
| Merge the workspace shell: navigation and phone shell, g1t as orchestrator, agents in roles with audience-checked reads, reactions and custom emoji, live notifications and browser push, the homepage tour (agents 0002, chat 0002) | 87 | assert.equal(preview("x".repeat(300)).length, 140); |
| 88 | }); | |
| 89 | ||
| 90 | test("counts after a read: what is left past the mark, mentions included, never your own", () => { | |
| 91 | const rows = [ | |
| 92 | { channel_id: "c", id: "m3", author: "user:u2", mentions: " ana " }, | |
| 93 | { channel_id: "c", id: "m4", author: "user:u1", mentions: "" }, | |
| 94 | { channel_id: "c", id: "m5", author: "agent:a1", mentions: "" }, | |
| 95 | ]; | |
| 96 | assert.deepEqual(countsAfterRead(rows, "c", "user:u1", "ana", "m2"), { unread: 2, mentions: 1 }); | |
| 97 | assert.deepEqual(countsAfterRead([], "c", "user:u1", "ana", "m9"), { unread: 0, mentions: 0 }); | |
| 98 | }); | |
| Write a thread up in Docs from chat; cards' buttons in notifications; a session's card stays at the top of its thread | 99 | |
| 100 | test("a card's actions ride on a notification only when it has an owner and something to press", () => { | |
| 101 | const draft = { | |
| 102 | kind: "draft_issue", | |
| 103 | title: "Fix the login", | |
| 104 | owner: "agents", | |
| 105 | actions: [ | |
| 106 | { id: "file", label: "File issue", style: "primary" }, | |
| 107 | { id: "discard", label: "Discard" }, | |
| 108 | ], | |
| 109 | }; | |
| 110 | const card = notificationCard("chn_1", "msg_1", draft)!; | |
| 111 | assert.deepEqual(card, { channel_id: "chn_1", message_id: "msg_1", actions: draft.actions }); | |
| 112 | assert.ok(asksToAct(card)); | |
| 113 | // Links only, no owner, or no actions: nothing to press from a toast. | |
| 114 | assert.equal(notificationCard("chn_1", "msg_1", { ...draft, actions: [{ id: "open", label: "Open", href: "/x" }] }), null); | |
| 115 | assert.equal(notificationCard("chn_1", "msg_1", { ...draft, owner: null }), null); | |
| 116 | assert.equal(notificationCard("chn_1", "msg_1", { kind: "pull", title: "t" }), null); | |
| 117 | assert.equal(notificationCard("chn_1", "msg_1", null), null); | |
| 118 | // A working session's card (Message, Stop, Open) is pressable but asks nobody. | |
| 119 | const working = notificationCard("chn_1", "msg_2", { | |
| 120 | owner: "agents", | |
| 121 | actions: [ | |
| 122 | { id: "steer", label: "Message", input: { kind: "text", label: "Tell it" } }, | |
| 123 | { id: "stop", label: "Stop", style: "danger" }, | |
| 124 | { id: "open", label: "Open", href: "/acme/-/agents/g1t/sessions/s1" }, | |
| 125 | ], | |
| 126 | }); | |
| 127 | assert.equal(working?.actions.length, 3); | |
| 128 | assert.equal(asksToAct(working), false); | |
| 129 | }); | |
| 130 | ||
| 131 | test("an agent's card that asks someone to act notifies whoever asked, with its actions", () => { | |
| 132 | const g1t: MemberProfile = { kind: "agent", id: "a1", name: "g1t", display_username: null, display_name: "g1t", avatar: null, role: null }; | |
| 133 | const card = notificationCard("chn_1", "msg_9", { owner: "agents", actions: [{ id: "file", label: "File issue", style: "primary" }, { id: "discard", label: "Discard" }] }); | |
| 134 | const items = messageDeliveries({ | |
| 135 | slug: "acme", | |
| 136 | channel: { id: "chn_1", kind: "channel", name: "design" }, | |
| 137 | message: { id: "msg_9", author: "agent:a1", body: "", card_title: "Fix the login", thread_root: "msg_1", created_at: "2026-10-08T00:00:00Z" }, | |
| 138 | author: g1t, | |
| 139 | card, | |
| 140 | recipients: recipients({ author: "agent:a1", channelKind: "channel", people: [ana, bo], mentioned: [], thread: new Set(["user:u2"]), waitingOn: "user:u1" }), | |
| 141 | }); | |
| 142 | const [toAna, toBo] = items; | |
| 143 | assert.equal(toAna.notification?.kind, "agent_waiting"); | |
| 144 | assert.equal(toAna.notification?.body, "Fix the login"); | |
| 145 | assert.deepEqual(toAna.notification?.card, card); | |
| 146 | assert.equal(toBo.notification?.kind, "thread_reply"); | |
| 147 | assert.equal(toBo.notification?.card?.message_id, "msg_9"); | |
| 148 | // A mention still reads as a mention. | |
| 149 | assert.deepEqual(kinds(recipients({ author: "agent:a1", channelKind: "channel", people: [ana], mentioned: ["ana"], thread: null, waitingOn: "user:u1" })), { u1: "mention" }); | |
| 150 | }); |
This file's history is long; its oldest lines are credited to the oldest commit read.