Skip to content
82 linesCodeBlameRaw

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.

Chat and workspace agents: channels, DMs and named agents you talk to1import { test } from "node:test";
2import assert from "node:assert/strict";
3
Workspace agents are told where they are and who is in the conversation every turn, and hand work to a colleague with a hand_off tool instead of an @mention: the brief is posted where the colleague already is, or in a group message of the person who asked, the agent and the colleague with a card linking to it; an agent's messages no longer wake other agents, its mentions of anyone outside the conversation show as plain names, and the agents and chat guides and the workspace plan say how.4import { MAX_HOPS, chainFor, deliveries, delivery, handOffPlace, handOffRefusal } from "./delivery.ts";
Chat and workspace agents: channels, DMs and named agents you talk to5
6const ship = { id: "a1", handle: "ship" };
7const docs = { id: "a2", handle: "docs" };
8
9test("a person's direct message wakes every agent in it, at hop 0", () => {
10 assert.deepEqual(deliveries({ author: "user:u", hops: 3, channelKind: "dm", agents: [ship, docs], mentioned: [] }), [
11 { agent_id: "a1", hops: 0 },
12 { agent_id: "a2", hops: 0 },
13 ]);
14});
15
Workspace agents are told where they are and who is in the conversation every turn, and hand work to a colleague with a hand_off tool instead of an @mention: the brief is posted where the colleague already is, or in a group message of the person who asked, the agent and the colleague with a card linking to it; an agent's messages no longer wake other agents, its mentions of anyone outside the conversation show as plain names, and the agents and chat guides and the workspace plan say how.16test("in a group direct message, a person who mentions some of its agents wakes only those", () => {
17 assert.deepEqual(deliveries({ author: "user:u", hops: 0, channelKind: "dm", agents: [ship, docs], mentioned: ["docs"] }), [{ agent_id: "a2", hops: 0 }]);
18 // Mentioning someone who isn't in it is no mention of its agents: all of them answer.
19 assert.deepEqual(deliveries({ author: "user:u", hops: 0, channelKind: "dm", agents: [ship, docs], mentioned: ["mike"] }), [
20 { agent_id: "a1", hops: 0 },
21 { agent_id: "a2", hops: 0 },
22 ]);
23});
24
Chat and workspace agents: channels, DMs and named agents you talk to25test("in a channel, a person wakes only the agent members they mention", () => {
26 assert.deepEqual(deliveries({ author: "user:u", hops: 0, channelKind: "channel", agents: [ship, docs], mentioned: [] }), []);
27 assert.deepEqual(
28 deliveries({ author: "user:u", hops: 0, channelKind: "channel", agents: [ship, docs], mentioned: ["Ship", "nobody"] }),
29 [{ agent_id: "a1", hops: 0 }],
30 );
31});
32
Workspace agents are told where they are and who is in the conversation every turn, and hand work to a colleague with a hand_off tool instead of an @mention: the brief is posted where the colleague already is, or in a group message of the person who asked, the agent and the colleague with a card linking to it; an agent's messages no longer wake other agents, its mentions of anyone outside the conversation show as plain names, and the agents and chat guides and the workspace plan say how.33test("an agent's message wakes nobody, even when it @mentions an agent member", () => {
Chat and workspace agents: channels, DMs and named agents you talk to34 assert.deepEqual(deliveries({ author: "agent:a1", hops: 0, channelKind: "dm", agents: [ship, docs], mentioned: [] }), []);
Workspace agents are told where they are and who is in the conversation every turn, and hand work to a colleague with a hand_off tool instead of an @mention: the brief is posted where the colleague already is, or in a group message of the person who asked, the agent and the colleague with a card linking to it; an agent's messages no longer wake other agents, its mentions of anyone outside the conversation show as plain names, and the agents and chat guides and the workspace plan say how.35 assert.deepEqual(deliveries({ author: "agent:a1", hops: 0, channelKind: "dm", agents: [ship, docs], mentioned: ["docs"] }), []);
36 assert.deepEqual(deliveries({ author: "agent:a1", hops: 2, channelKind: "channel", agents: [ship, docs], mentioned: ["docs", "ship"] }), []);
Chat and workspace agents: channels, DMs and named agents you talk to37});
38
39test("a delivery carries the chain's asker on g1t's own chat, and the wake's hops", () => {
40 const asker = { username: "ada", role: "member", can_write: false };
41 const place = { workspace: "acme", workspace_id: "w1", channel_id: "c1", channel_kind: "channel", channel_name: "ops" };
42 assert.deepEqual(
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)43 delivery(place, { agent_id: "a2", hops: 3 }, { id: "m1", thread_root: "m0" }, { hops: 2, asked_by: "u1", asker, chain: ["a1"] }),
44 { ...place, agent_id: "a2", message_id: "m1", thread_root: "m0", asked_by: "u1", asker, chain: ["a1"], hops: 3, surface: "g1t" },
Chat and workspace agents: channels, DMs and named agents you talk to45 );
46 // An agent that passed no asker back hands on none.
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)47 assert.equal(delivery(place, { agent_id: "a2", hops: 1 }, { id: "m1", thread_root: null }, { hops: 0, asked_by: "u1", asker: null, chain: [] }).asker, null);
48});
49
50test("mentioning @g1t in a channel brings it in once; never into a DM", async () => {
51 const { addsOrchestrator } = await import("./delivery.ts");
52 assert.equal(addsOrchestrator({ channelKind: "channel", mentioned: ["G1T"], orchestratorIsMember: false }), true);
53 assert.equal(addsOrchestrator({ channelKind: "channel", mentioned: ["g1t"], orchestratorIsMember: true }), false, "already in");
54 assert.equal(addsOrchestrator({ channelKind: "channel", mentioned: ["ship"], orchestratorIsMember: false }), false);
55 assert.equal(addsOrchestrator({ channelKind: "dm", mentioned: ["g1t"], orchestratorIsMember: false }), false);
56 // Once in, it is woken like any mentioned agent member.
57 const g1t = { id: "a9", handle: "g1t" };
58 assert.deepEqual(deliveries({ author: "user:u", hops: 0, channelKind: "channel", agents: [ship, g1t], mentioned: ["g1t"] }), [{ agent_id: "a9", hops: 0 }]);
59});
60
Workspace agents are told where they are and who is in the conversation every turn, and hand work to a colleague with a hand_off tool instead of an @mention: the brief is posted where the colleague already is, or in a group message of the person who asked, the agent and the colleague with a card linking to it; an agent's messages no longer wake other agents, its mentions of anyone outside the conversation show as plain names, and the agents and chat guides and the workspace plan say how.61test("a chain is the agents that handled a request, with the poster added", () => {
62 assert.deepEqual(chainFor(["a9"], "a1"), ["a9", "a1"]);
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)63 assert.deepEqual(chainFor("nonsense", "a1"), ["a1"]);
64});
65
Workspace agents are told where they are and who is in the conversation every turn, and hand work to a colleague with a hand_off tool instead of an @mention: the brief is posted where the colleague already is, or in a group message of the person who asked, the agent and the colleague with a card linking to it; an agent's messages no longer wake other agents, its mentions of anyone outside the conversation show as plain names, and the agents and chat guides and the workspace plan say how.66test("a hand-off goes here when the colleague is in this channel or group DM, else to a group DM", () => {
67 assert.equal(handOffPlace({ channelKind: "channel", members: 40, colleagueHere: true }), "here");
68 assert.equal(handOffPlace({ channelKind: "dm", members: 3, colleagueHere: true }), "here");
69 assert.equal(handOffPlace({ channelKind: "channel", members: 40, colleagueHere: false }), "group_dm");
70 // The 1:1 DM the user saw: @g1t and the person, Mike not in it.
71 assert.equal(handOffPlace({ channelKind: "dm", members: 2, colleagueHere: false }), "group_dm");
72});
73
74test("a hand-off is refused to itself, to @g1t, back along the chain, and past the hop limit", () => {
75 const ok = { agent: "a9", colleague: { id: "a1" }, chain: [], hops: 0 };
76 assert.equal(handOffRefusal(ok), null);
77 assert.match(handOffRefusal({ ...ok, colleague: { id: "a9" } })!, /itself/);
78 assert.match(handOffRefusal({ ...ok, agent: "a1", colleague: { id: "a9", builtin: true } })!, /@g1t/);
79 assert.match(handOffRefusal({ ...ok, agent: "a2", chain: ["a1", "a2"] })!, /already handled/);
80 assert.equal(handOffRefusal({ ...ok, hops: MAX_HOPS - 1 }), null);
81 assert.match(handOffRefusal({ ...ok, hops: MAX_HOPS })!, /too many times/);
Chat and workspace agents: channels, DMs and named agents you talk to82});

This file's history is long; its oldest lines are credited to the oldest commit read.