Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(first-hour): link the day-two recap to the morning brief card

AdityaUmale7f3851bc8e49
diff --git a/docs/verification/first-hour.md b/docs/verification/first-hour.md
index 85acc78af4..468f5764c0 100644
--- a/docs/verification/first-hour.md
+++ b/docs/verification/first-hour.md
@@ -54,7 +54,8 @@ pnpm exec vitest run server/host/first-hour.test.ts server/host/brief-morning.te
paired after the first look; the day-two recap ("So far I've sorted 40
emails for your morning brief, drafted 6 replies and prepped 4 meetings:
about 2 hours back.") only after 8:00 on day two, once, and never when
- nothing was done.
+ nothing was done; with emails sorted, it replies to the newest brief card in
+ the same chat, so one tap opens that brief.
- `server/host/brief-morning.test.ts`: the brief posted and pushed at 8:00 in the person's
zone and not a minute before, once a day; its first line from the counts since
the person was last here, left out when they just were; a running watch run
diff --git a/server/host/brief.test.ts b/server/host/brief.test.ts
index c70b1f9109..ddb98c5e8a 100644
--- a/server/host/brief.test.ts
+++ b/server/host/brief.test.ts
@@ -155,6 +155,19 @@ describe("the brief", () => {
expect(JSON.stringify(today.widget!.root)).not.toContain(ENGLISH_BRIEF.intro);
});
+ it("gives the newest card, an earlier day's until today's is posted", async () => {
+ const s = setup({ needsYou: [{ kind: "signed-out", id: "x", at: 0, instanceId: "claude", botIds: [] }] });
+ expect(s.brief.latestCard()).toBeUndefined();
+ await s.brief.active("desktop", "UTC");
+ const first = s.card()!.id;
+ expect(s.brief.latestCard()).toEqual({ threadId: s.thread(), messageId: first });
+ s.advance(24 * 60 * MINUTE);
+ expect(s.brief.latestCard()).toEqual({ threadId: s.thread(), messageId: first });
+ await s.brief.active("desktop");
+ expect(s.card()!.id).not.toBe(first);
+ expect(s.brief.latestCard()).toEqual({ threadId: s.thread(), messageId: s.card()!.id });
+ });
+
it("speaks the language set in Settings, dates included", async () => {
const s = setup({ language: "pt-BR", needsYou: [{ kind: "signed-out", id: "x", at: 0, instanceId: "claude", botIds: [] }] });
await s.brief.active("desktop", "UTC");
diff --git a/server/host/brief.ts b/server/host/brief.ts
index 77dd003f07..775d899d67 100644
--- a/server/host/brief.ts
+++ b/server/host/brief.ts
@@ -590,6 +590,12 @@ export function createBrief(deps: BriefDeps) {
const bot = chief();
return bot ? currentCard(bot)?.row.widget?.root : undefined;
},
+ /** The newest brief card, from today or an earlier day, while it is still in its chat. */
+ latestCard: (): { threadId: string; messageId: string } | undefined => {
+ const card = state.card;
+ if (!card || !deps.store.messagesFor(card.threadId).some((row) => row.id === card.messageId && row.serverCard)) return undefined;
+ return { threadId: card.threadId, messageId: card.messageId };
+ },
/** The brief moved to another bot: from now on it lives in that bot's main chat, and its next card says what it
* does. Cards already posted stay where they are. */
moveTo: (botId: string): void => {
diff --git a/server/host/first-hour-host.ts b/server/host/first-hour-host.ts
index af903af552..a62ea359b1 100644
--- a/server/host/first-hour-host.ts
+++ b/server/host/first-hour-host.ts
@@ -100,6 +100,7 @@ export function startFirstHour(deps: FirstHourHostDeps): FirstHour | null {
},
briefOn: deps.briefOn,
ensureBrief: deps.ensureBrief,
+ briefCard: () => deps.proactive.brief.latestCard(),
phones: deps.phones,
startTurn: deps.startTurn,
notify: (bot, threadId, body) => deps.notify(bot.notifications === false ? null : { kind: "brief", botId: bot.id, botName: bot.name, threadId, title: bot.name, body, ...(bot.avatarUrl ? { avatarUrl: bot.avatarUrl } : {}) }),
diff --git a/server/host/first-hour.test.ts b/server/host/first-hour.test.ts
index 1b9cd2700f..31d13ebbef 100644
--- a/server/host/first-hour.test.ts
+++ b/server/host/first-hour.test.ts
@@ -31,6 +31,7 @@ function setup(options: { start?: string; connected?: { gmail?: boolean; googlec
connected: { gmail: false, googlecalendar: false, ...options.connected }, briefOn: false, phones: 0, busy: false,
pushed: [] as string[], turns: [] as Array<{ text: string; threadId: string }>, welcomeDone: 0, runs: [] as RoutineRun[],
reply: "This week: Standup Tue 10:00." as string | null,
+ briefCard: undefined as { threadId: string; messageId: string } | undefined,
/** While set, the first look's turn runs until this is called. */
held: null as null | (() => void), hold: false,
};
@@ -39,7 +40,7 @@ function setup(options: { start?: string; connected?: { gmail?: boolean; googlec
store, dataDir: dir, now: () => now, chief: () => store.bot(chief.id), mainThread: () => thread(), threadBusy: () => world.busy,
person: () => world.person, language: () => world.language, timeZone: () => world.zone,
apps: { reachable: () => true, connected: async () => ({ ...world.connected }), card: async (slug) => ({ label: slug === "gmail" ? "Gmail" : "Google Calendar", description: "" }) },
- briefOn: () => world.briefOn, ensureBrief: () => { world.briefOn = true; }, phones: () => world.phones,
+ briefOn: () => world.briefOn, ensureBrief: () => { world.briefOn = true; }, briefCard: () => world.briefCard, phones: () => world.phones,
startTurn: async (_botId, text, opts) => {
world.turns.push({ text, threadId: opts.threadId });
const end = () => {
@@ -251,6 +252,27 @@ describe("a new Cloud's first hour", () => {
expect(fh.tally()).toEqual({ sorted: 40, drafted: 6, prepped: 4, routines: 0 });
});
+ it("points the recap's sorted count to the morning brief card in the same chat, and nowhere else", () => {
+ const recapWith = (sorted: number, card: "here" | "none" | "elsewhere") => {
+ const s = setup({ start: "2026-10-27T09:00:00Z" });
+ const fh = s.make();
+ fh.begin();
+ const brief = s.store.appendMessage(s.thread(), { role: "bot", kind: "widget", text: "Your brief: 1 needs you", serverCard: true });
+ if (card !== "none") s.world.briefCard = { threadId: card === "here" ? s.thread() : "another-chat", messageId: brief.id };
+ if (sorted) s.ledger.add("sorted", sorted);
+ s.ledger.add("drafted", 2);
+ s.set("2026-10-28T09:00:00Z");
+ fh.tick();
+ return { recap: s.rows().findLast((row) => row.text?.startsWith("So far"))!, brief };
+ };
+ const linked = recapWith(12, "here");
+ expect(linked.recap.text).toBe("So far I've sorted 12 emails for your morning brief and drafted 2 replies: about 20 minutes back.");
+ expect(linked.recap.replyToId).toBe(linked.brief.id);
+ expect(recapWith(12, "none").recap.replyToId).toBeUndefined();
+ expect(recapWith(12, "elsewhere").recap.replyToId).toBeUndefined();
+ expect(recapWith(0, "here").recap.replyToId).toBeUndefined();
+ });
+
it("holds the recap while the person's newest message is still unanswered, so it never reads as the answer", () => {
const s = setup({ start: "2026-10-27T09:00:00Z" });
const fh = s.make();
diff --git a/server/host/first-hour.ts b/server/host/first-hour.ts
index 6414cbb73f..c2d8a7df35 100644
--- a/server/host/first-hour.ts
+++ b/server/host/first-hour.ts
@@ -104,6 +104,8 @@ export interface FirstHourDeps {
briefOn(): boolean;
/** An app it reads is in: the brief is made now if it was not yet. */
ensureBrief(): void;
+ /** The newest morning brief card, which the recap's sorted count points to. */
+ briefCard(): { threadId: string; messageId: string } | undefined;
phones(): number;
startTurn(botId: string, text: string, opts: { threadId: string; cardContinuation: true; onSettled: (outcome: HostTurnResult) => void }): Promise<unknown>;
notify(bot: BotRecord, threadId: string, body: string): void;
@@ -209,8 +211,8 @@ export function createFirstHour(deps: FirstHourDeps) {
const soon = (step: () => Promise<void>): void => { setTimeout(() => void step(), SOON_MS).unref?.(); };
/** One line from the Chief in its chat, unread, read by its next turn. */
- function say(bot: BotRecord, threadId: string, text: string): Message {
- const message = deps.store.appendMessage(threadId, { role: "bot", kind: "text", text });
+ function say(bot: BotRecord, threadId: string, text: string, replyToId?: string): Message {
+ const message = deps.store.appendMessage(threadId, { role: "bot", kind: "text", text, ...(replyToId ? { replyToId } : {}) });
deps.store.patchTask(bot.id, threadId, { unread: true });
deps.wrote(bot, threadId);
return message;
@@ -391,7 +393,8 @@ export function createFirstHour(deps: FirstHourDeps) {
return;
}
const w = words();
- say(place.bot, place.threadId, w.recap(doneLine(counts, w, w.briefSorted)!, w.time(minutesSaved(counts))));
+ const brief = counts.sorted ? deps.briefCard() : undefined;
+ say(place.bot, place.threadId, w.recap(doneLine(counts, w, w.briefSorted)!, w.time(minutesSaved(counts))), brief?.threadId === place.threadId ? brief.messageId : undefined);
mark({ recapAt: at });
}