Skip to content

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

fix(sidebar): exclude archived threads from unread indicators

luishron1238743dc61f222
diff --git a/server/archived-unread.test.ts b/server/archived-unread.test.ts
new file mode 100644
index 0000000000..7189727799
--- /dev/null
+++ b/server/archived-unread.test.ts
@@ -0,0 +1,68 @@
+import { mkdtempSync, rmSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { memberAudience } from "./audience.ts";
+import { memberBot, VisibleSet } from "./bot-visibility.ts";
+
+let home: string | undefined;
+
+async function freshStore() {
+ home = mkdtempSync(join(tmpdir(), "omb-archived-unread-"));
+ vi.resetModules();
+ vi.stubEnv("HOME", home);
+ vi.stubEnv("USERPROFILE", home);
+ const { Store } = await import("./store.ts");
+ return { store: new Store(() => ({ instanceId: "claude", model: "m" })) };
+}
+
+afterEach(async () => {
+ if (!home) return;
+ const { closeMessageDb } = await import("./message-db.ts");
+ closeMessageDb();
+ vi.unstubAllEnvs();
+ rmSync(home, { recursive: true, force: true });
+ home = undefined;
+});
+
+describe("archived threads and bot.unread", () => {
+ it("excludes archived threads from bot.unread across patches and reloads, and restores it when unarchived", async () => {
+ const { store } = await freshStore();
+ const bot = store.createBot();
+ const open = bot.threadId;
+ const hidden = store.createTask(bot.id, "Hidden unread", false)!;
+
+ store.patchTask(bot.id, hidden.threadId, { unread: true });
+ expect(store.bot(bot.id)!.unread).toBe(true);
+
+ store.patchTask(bot.id, hidden.threadId, { archivedAt: 1_000 });
+ expect(store.bot(bot.id)!.unread).toBe(false);
+ expect(store.taskByThread(bot.id, hidden.threadId)!.unread).toBe(true);
+
+ const { Store } = await import("./store.ts");
+ const reloaded = new Store(() => ({ instanceId: "claude", model: "m" }));
+ expect(reloaded.bot(bot.id)!.unread).toBe(false);
+
+ reloaded.patchTask(bot.id, hidden.threadId, { archivedAt: undefined });
+ expect(reloaded.bot(bot.id)!.unread).toBe(true);
+ expect(reloaded.bot(bot.id)!.threadId).toBe(open);
+ });
+
+ it("excludes archived threads when narrowing Team Cloud shownConversations unread state", () => {
+ const bot = {
+ id: "b1",
+ threadId: "t-open",
+ unread: true,
+ tasks: [
+ { threadId: "t-private", title: "Alice private", createdAt: 1, unread: true },
+ { threadId: "t-archived", title: "Team archived", createdAt: 2, unread: true, archivedAt: 500 },
+ { threadId: "t-open", title: "Team open", createdAt: 3, unread: false },
+ ],
+ };
+ const visible = new VisibleSet([bot], [], { kind: "member", email: "[email protected]" }, undefined, {
+ person: "bob",
+ of: (threadId) => (threadId === "t-private" ? memberAudience("alice") : "team"),
+ });
+ expect(memberBot(bot, visible).unread).toBe(false);
+ });
+});
diff --git a/server/bot-visibility.ts b/server/bot-visibility.ts
index 5ebff6f9fe..e952e7f3df 100644
--- a/server/bot-visibility.ts
+++ b/server/bot-visibility.ts
@@ -445,11 +445,11 @@ function shownConversations<T extends object>(bot: T, visible: VisibleSet): T {
const record = bot as T & Record<string, unknown>;
let out: Record<string, unknown> = record;
const tasks = Array.isArray(record.tasks) ? record.tasks as unknown[] : [];
- const isTask = (task: unknown): task is { threadId: string; unread?: boolean; routineRunId?: unknown } => Boolean(task) && typeof task === "object" && typeof (task as { threadId?: unknown }).threadId === "string";
+ const isTask = (task: unknown): task is { threadId: string; unread?: boolean; routineRunId?: unknown; archivedAt?: unknown } => Boolean(task) && typeof task === "object" && typeof (task as { threadId?: unknown }).threadId === "string";
const kept = tasks.filter((task) => !isTask(task) || visible.thread(task.threadId)).map((task) => (isTask(task) ? visible.ownTask(task) : task));
if (kept.length !== tasks.length || kept.some((task, index) => task !== tasks[index])) {
out = { ...record, tasks: kept };
- if (typeof record.unread === "boolean") out.unread = kept.some((task) => isTask(task) && task.unread === true && !task.routineRunId);
+ if (typeof record.unread === "boolean") out.unread = kept.some((task) => isTask(task) && task.unread === true && !task.routineRunId && task.archivedAt === undefined);
}
const main = typeof record.mainThreadId === "string" && visible.thread(record.mainThreadId) ? record.mainThreadId : teamConversation(kept);
if (typeof record.mainThreadId === "string" && record.mainThreadId !== main) {
diff --git a/server/store.ts b/server/store.ts
index 8d6cf32eb4..3237696369 100644
--- a/server/store.ts
+++ b/server/store.ts
@@ -255,8 +255,8 @@ export function pruneRoomHolds(group: Pick<GroupRecord, "memberIds" | "holds" |
}
}
-function taskCountsAsBotUnread(task: { unread?: boolean; routineRunId?: string }): boolean {
- return Boolean(task.unread) && !task.routineRunId;
+function taskCountsAsBotUnread(task: { unread?: boolean; routineRunId?: string; archivedAt?: number }): boolean {
+ return Boolean(task.unread) && !task.routineRunId && task.archivedAt === undefined;
}
export class Store {
diff --git a/src/components/PinnedCircleThreads.tsx b/src/components/PinnedCircleThreads.tsx
index 9a8f54a450..2dde2a22a6 100644
--- a/src/components/PinnedCircleThreads.tsx
+++ b/src/components/PinnedCircleThreads.tsx
@@ -18,7 +18,7 @@ import { PINNED_CIRCLE_DRAG_TYPE, pinnedCircleDropPlace, rankPinnedCircles, reor
import { sidebarSectionAttention } from "@/lib/sidebar-attention";
import { SidebarSectionHeader } from "./SidebarSectionHeader";
import { BotListItem, BotThreadList, type BotRowProps } from "./Sidebar";
-import { useUnreadNotice } from "./unread-notice";
+import { useBotUnread } from "./unread-notice";
function useVisibleMessages(bot: Bot): Message[] {
const { messages, activeLeafId } = bot;
@@ -189,8 +189,7 @@ export const PinnedBotCircle = memo(function PinnedBotCircle({
const activityTasks = sidebarBotActivityTasks(bot, pendingQueued);
const waiting = bot.activity === "waiting-on-you" || activityTasks.some((task) => task.activity === "waiting-on-you");
const working = !waiting && (Boolean(bot.busy) || activityTasks.some((task) => task.busy || task.activity === "working"));
- const unread = bot.unread || activityTasks.some((task) => task.unread);
- const noticing = useUnreadNotice(Boolean(bot.unread)); const beat = useMotionBeat(mascotMotion?.kind, mascotMotion?.nonce ?? 0);
+ const { unread, noticing } = useBotUnread(bot); const beat = useMotionBeat(mascotMotion?.kind, mascotMotion?.nonce ?? 0);
const radius = avatarCropRadius(botAvatarProfile(bot).avatarCrop);
return (
<div className="flex w-full min-w-0 flex-col items-center">
diff --git a/src/components/Sidebar.folder-archived.dom.test.ts b/src/components/Sidebar.folder-archived.dom.test.ts
new file mode 100644
index 0000000000..4661578e89
--- /dev/null
+++ b/src/components/Sidebar.folder-archived.dom.test.ts
@@ -0,0 +1,82 @@
+// @vitest-environment happy-dom
+import { act, createElement } from "react";
+import { createRoot, type Root } from "react-dom/client";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { initialState, reducer, type Bot } from "@/state/store";
+import { forgetSidebarShowAllForTests } from "@/lib/sidebar-preferences";
+
+vi.mock("./DesktopCapabilities", () => ({ useDesktopCapabilities: () => ({}) }));
+vi.mock("@/lib/interface-mode", async (original) => ({ ...await original<typeof import("@/lib/interface-mode")>(), useAdvancedMode: () => true }));
+
+const { BotThreadList, botRowProps } = await import("./Sidebar");
+
+(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+
+const makeBot = (tasks: NonNullable<Bot["tasks"]>): Bot => ({
+ id: "maus", threadId: "open-main", name: "Maus", title: "", description: "", notifications: true,
+ color: "green", unread: true, messages: [], modelSelection: { instanceId: "fake", model: "test" },
+ projects: [{ id: "taxes", name: "Taxes" }],
+ tasks,
+});
+
+let host: HTMLElement;
+let root: Root;
+const mount = async (candidate: Bot) => {
+ host = document.createElement("div");
+ document.body.append(host);
+ root = createRoot(host);
+ await act(async () => {
+ root.render(createElement(BotThreadList, { ...botRowProps(initialState, vi.fn(), candidate, { density: "comfortable", query: "", onMenu: vi.fn() }), selected: true }));
+ });
+};
+const unmount = async () => {
+ await act(async () => { root.unmount(); });
+ host.remove();
+};
+
+beforeEach(() => {
+ localStorage.clear();
+ forgetSidebarShowAllForTests();
+});
+afterEach(() => { document.body.innerHTML = ""; });
+
+describe("collapsed folder unread badge with archived threads", () => {
+ it("hides the unread dot when the folder's only unread thread is archived, and shows it for an open unread thread", async () => {
+ await mount(makeBot([
+ { threadId: "open-main", title: "Main chat", createdAt: 10, unread: false },
+ { threadId: "filed-archived", title: "Old receipt", createdAt: 5, projectId: "taxes", unread: true, archivedAt: 20 },
+ ]));
+ await act(async () => {
+ host.querySelector<HTMLButtonElement>('[aria-label="Collapse Taxes threads"]')!.click();
+ });
+ const folderLabel = host.querySelector('[data-sidebar-folder-label="taxes"]')!;
+ expect(folderLabel.querySelector('[aria-label="Unread threads"]')).toBeNull();
+ await unmount();
+
+ await mount(makeBot([
+ { threadId: "open-main", title: "Main chat", createdAt: 10, unread: false },
+ { threadId: "filed-open", title: "New receipt", createdAt: 5, projectId: "taxes", unread: true },
+ ]));
+ await act(async () => {
+ host.querySelector<HTMLButtonElement>('[aria-label="Collapse Taxes threads"]')!.click();
+ });
+ expect(host.querySelector('[data-sidebar-folder-label="taxes"] [aria-label="Unread threads"]')).not.toBeNull();
+ await unmount();
+ });
+
+ it("does not leave bot.unread true after select or taskSwitched when only archived or routine threads remain unread", () => {
+ const candidate = makeBot([
+ { threadId: "open-main", title: "Main chat", createdAt: 10, unread: true },
+ { threadId: "filed-archived", title: "Old receipt", createdAt: 5, projectId: "taxes", unread: true, archivedAt: 20 },
+ { threadId: "routine-run", title: "Morning run", createdAt: 6, unread: true, routineRunId: "run-1" },
+ ]);
+ const selected = reducer({ ...initialState, bots: [candidate], selectedId: "other" }, { type: "select", id: "maus" });
+ expect(selected.bots[0]!.unread).toBe(false);
+
+ const switched = reducer(
+ { ...initialState, bots: [{ ...candidate, threadId: "other-thread" }], selectedId: "maus", activeView: "chat" },
+ { type: "taskSwitched", bot: candidate },
+ );
+ expect(switched.bots[0]!.unread).toBe(false);
+ });
+});
diff --git a/src/components/Sidebar.pinned-circle-threads.test.ts b/src/components/Sidebar.pinned-circle-threads.test.ts
index fe316b33fc..ee54fdf0f4 100644
--- a/src/components/Sidebar.pinned-circle-threads.test.ts
+++ b/src/components/Sidebar.pinned-circle-threads.test.ts
@@ -94,6 +94,30 @@ describe("pinned circle frame", () => {
expect(clipped).toContain("border-radius:22%");
expect(clipped).not.toContain("rounded-full");
});
+
+ it("ignores archived unread threads on the circle and collapsed pinned section while marking open unread ones", () => {
+ const archivedOnly = bot({
+ unread: true,
+ tasks: [
+ { threadId: "thread-atlas", title: "Open read", createdAt: 2, unread: false },
+ { threadId: "thread-hidden", title: "Archived unread", createdAt: 1, unread: true, archivedAt: 10 },
+ ],
+ });
+ const circleMarkup = renderCircle(archivedOnly);
+ expect(circleMarkup).not.toContain('aria-label="Unread threads"');
+ expect(circleMarkup).not.toContain("Atlas · Unread");
+ expect(renderThreads(true, [archivedOnly])).not.toContain("unread");
+
+ const openUnread = bot({
+ unread: false,
+ tasks: [
+ { threadId: "thread-atlas", title: "Open read", createdAt: 2, unread: false },
+ { threadId: "thread-open", title: "Open unread", createdAt: 1, unread: true },
+ ],
+ });
+ expect(renderCircle(openUnread)).toContain('aria-label="Unread threads"');
+ expect(renderThreads(true, [openUnread])).toContain("1 unread");
+ });
});
describe("pinned circle thread list", () => {
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx
index cd214c953d..c52ddf3401 100644
--- a/src/components/Sidebar.tsx
+++ b/src/components/Sidebar.tsx
@@ -38,7 +38,7 @@ import { GroupThreadList } from "./SidebarGroupThreadList";
import { useOwnerOrAdmin } from "@/lib/use-owner-or-admin";
import { draggedFolder, FOLDER_DRAG_TYPE, moveFolder, placeFolder } from "@/lib/folder-order";
import { folderUnreadThreadIds, markFolderRead } from "@/lib/folder-read";
-import { HelperThreadGroup, orderedThreadList, partitionHelperThreads, SidebarThreadRow, stampClock, threadRecency, threadRowActions, useRelativeNow, useRevealedThreadRow, useSnoozeExpiry, visibleSidebarThreads } from "./SidebarThreadRow";
+import { HelperThreadGroup, isArchived, orderedThreadList, partitionHelperThreads, SidebarThreadRow, stampClock, threadRecency, threadRowActions, useRelativeNow, useRevealedThreadRow, useSnoozeExpiry, visibleSidebarThreads } from "./SidebarThreadRow";
import { setSidebarDensity, useSidebarDensity, usePinnedCircles, useSidebarShowAllThreads, useUniversalPins, type SidebarDensity } from "@/lib/sidebar-preferences";
import {
ATTENTION_SECTION_ID,
@@ -600,7 +600,7 @@ export function BotThreadList({ bot, selected, drafting, query, pendingQueued, r
})} className="flex min-h-8 min-w-0 flex-1 cursor-grab select-none items-center gap-1.5 py-1 text-left text-[13px] font-semibold active:cursor-grabbing" title={project.name}>
<span className="truncate">{project.name}</span>
<span className="shrink-0 text-[12px] font-normal opacity-50">{projectTasks.length}</span>
- {!open && (waiting ? <span className="text-[12px] text-warning">{t("task.waiting")}</span> : working ? <Loader2 size={10} className="shrink-0 animate-spin text-success" /> : projectTasks.some((task) => task.unread) ? <span className="size-1.5 shrink-0 rounded-full bg-accent" aria-label={t("task.unreadMany")} /> : null)}
+ {!open && (waiting ? <span className="text-[12px] text-warning">{t("task.waiting")}</span> : working ? <Loader2 size={10} className="shrink-0 animate-spin text-success" /> : projectTasks.some((task) => !isArchived(task) && task.unread) ? <span className="size-1.5 shrink-0 rounded-full bg-accent" aria-label={t("task.unreadMany")} /> : null)}
</button>
<button type="button" title={t("task.newIn", { name: project.name })} aria-label={t("task.newIn", { name: project.name })} onClick={() => dispatch({ type: "newTask", botId: bot.id, projectId: project.id })}
className="flex size-6 items-center justify-center rounded opacity-0 hover:bg-raised hover:text-ink focus-visible:opacity-100 group-hover/folder:opacity-100 max-md:opacity-70 touch:opacity-70"><Plus size={12} /></button>
diff --git a/src/components/SidebarBotMenu.tsx b/src/components/SidebarBotMenu.tsx
index 6aec518e60..2e4c205606 100644
--- a/src/components/SidebarBotMenu.tsx
+++ b/src/components/SidebarBotMenu.tsx
@@ -12,6 +12,7 @@ import { DemoteDefaultBotItem, HideDefaultBotItem } from "./DefaultBotControls";
import { navigateThreadMenu } from "./BotProjects";
import { useOwnerOrAdmin } from "@/lib/use-owner-or-admin";
import { userBotMenu } from "@/lib/own-team-bot";
+import { botShowsUnread } from "@/lib/bot-unread";
import { botUnreadThreadIds, markBotRead } from "@/lib/folder-read";
import { ownerMenuLabel, pickOwnerOf } from "./TeamOwner";
import { mayChangeOwner, mayRename, useTeamPeople } from "@/state/team-people";
@@ -265,7 +266,7 @@ export function BotContextMenu({
});
const owner = team && mayChangeOwner(bot, team) ? item(<Users size={16} className="text-ink-secondary" />, ownerMenuLabel(bot, team), () => pickOwnerOf(bot, team, shown)) : null;
const deleteAll = !member && allThreadRows(bot).length >= 2 ? [divider("more-threads"), item(<Trash2 size={16} />, t("task.deleteAllConversations"), () => clearThreads.ask(bot.id), { danger: true })] : [];
- const readState = readingBotId === bot.id || botUnreadThreadIds(bot).length > 0
+ const readState = readingBotId === bot.id || botShowsUnread(bot)
? item(
readingBotId === bot.id ? <Loader2 size={16} className="animate-spin text-ink-secondary" /> : <CheckCheck size={16} className="text-ink-secondary" />,
readingBotId === bot.id ? t("sidebar.bot.markingAllRead") : t("sidebar.bot.simple.markRead"),
diff --git a/src/components/SidebarBotRead.test.ts b/src/components/SidebarBotRead.test.ts
index 2968c05635..d246187737 100644
--- a/src/components/SidebarBotRead.test.ts
+++ b/src/components/SidebarBotRead.test.ts
@@ -120,6 +120,19 @@ describe("bot menu bulk reads", () => {
flushSync(() => button("Mark as unread").click());
expect(state.bots[0]!.unread).toBe(true);
});
+
+ it("offers Mark as unread in Simple mode when the only unread threads are archived or routine runs", () => {
+ mode.advanced = false;
+ state.bots[0]!.unread = false;
+ state.bots[0]!.tasks = [
+ { threadId: "selected", title: "Selected", createdAt: 1, unread: false },
+ { threadId: "hidden", title: "Archived unread", createdAt: 2, unread: true, archivedAt: 10 },
+ { threadId: "routine", title: "Routine run", createdAt: 3, unread: true, routineRunId: "run-1" },
+ ];
+ draw();
+ expect(button("Mark as read")).toBeUndefined();
+ expect(button("Mark as unread")).toBeDefined();
+ });
});
describe("Advanced mode's bot menu", () => {
diff --git a/src/lib/sidebar-attention.ts b/src/lib/sidebar-attention.ts
index f34f2cd0cd..632b6930bc 100644
--- a/src/lib/sidebar-attention.ts
+++ b/src/lib/sidebar-attention.ts
@@ -1,9 +1,11 @@
+import { botShowsUnread } from "./bot-unread";
import { t } from "./i18n";
export type SidebarAttentionBot = {
unread?: boolean;
busy?: boolean;
activity?: "working" | "waiting-on-you" | "idle" | "no-signal" | "dead" | "parked.computer";
+ tasks?: Parameters<typeof botShowsUnread>[0]["tasks"];
};
export type SidebarAttentionGroup = {
@@ -24,7 +26,7 @@ export function sidebarSectionAttention(
): SidebarSectionAttention {
return {
unread:
- bots.filter((bot) => Boolean(bot.unread)).length +
+ bots.filter(botShowsUnread).length +
groups.filter((group) => Boolean(group.unread)).length,
waiting: bots.filter((bot) => bot.activity === "waiting-on-you").length,
working:
diff --git a/src/state/store.tsx b/src/state/store.tsx
index c025413e49..c206a6020f 100644
--- a/src/state/store.tsx
+++ b/src/state/store.tsx
@@ -1063,7 +1063,7 @@ function reduceApp(state: AppState, action: Action): AppState {
"switch",
),
action.id,
- (b) => ({ ...b, unread: Boolean(b.tasks?.some((task) => task.threadId !== b.threadId && task.unread)), tasks: b.tasks?.map((task) => task.threadId === b.threadId ? { ...task, unread: false } : task) }),
+ (b) => ({ ...b, unread: Boolean(b.tasks?.some((task) => task.threadId !== b.threadId && task.unread && !task.routineRunId && task.archivedAt === undefined)), tasks: b.tasks?.map((task) => task.threadId === b.threadId ? { ...task, unread: false } : task) }),
);
}
case "answerCard": {
@@ -1715,7 +1715,7 @@ function reduceApp(state: AppState, action: Action): AppState {
switched = { ...switched, unreadDivider: openedUnreadDivider(switched, opened.threadId, threadOpensUnread(opened), visibleMessages(opened), threadReadCursor(opened), opened.hasMore) };
// The snapshot predates the switch's own announcement and must not put the unread dot back.
if (switched.activeView === "chat") switched = updateBot(switched, opened.id, (bot) => ({ ...bot,
- unread: Boolean(bot.tasks?.some((task) => task.threadId !== bot.threadId && task.unread)),
+ unread: Boolean(bot.tasks?.some((task) => task.threadId !== bot.threadId && task.unread && !task.routineRunId && task.archivedAt === undefined)),
tasks: bot.tasks?.map((task) => task.threadId === bot.threadId ? { ...task, unread: false } : task) }));
}
return reconcileModelVariantSessions(reconcileSnapshotQueues(switched, [action.bot]));