Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(sidebar): exclude hidden archived threads from folder count badge
luishron123e450dfa8bca5
diff --git a/src/components/Sidebar.folder-count-archived.dom.test.ts b/src/components/Sidebar.folder-count-archived.dom.test.tsnew file mode 100644index 0000000000..f9f6b3e8a1--- /dev/null+++ b/src/components/Sidebar.folder-count-archived.dom.test.ts@@ -0,0 +1,83 @@+// @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, 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"]>, threadId = "open-main"): Bot => ({+ id: "maus", threadId, name: "Maus", title: "", description: "", notifications: true,+ color: "green", unread: false, 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();+};+const folderCount = () => host.querySelectorAll('[data-sidebar-folder-label="taxes"] > span')[1]?.textContent;++beforeEach(() => {+ localStorage.clear();+ forgetSidebarShowAllForTests();+});+afterEach(() => { document.body.innerHTML = ""; });++describe("folder header count with archived threads", () => {+ it("shows 0 when a folder holds only hidden archived threads, offers Show all, and shows 2 once Show all is enabled", async () => {+ await mount(makeBot([+ { threadId: "open-main", title: "Main chat", createdAt: 10 },+ { threadId: "arch-1", title: "Q1 filing", createdAt: 5, projectId: "taxes", archivedAt: 20 },+ { threadId: "arch-2", title: "Q2 filing", createdAt: 6, projectId: "taxes", archivedAt: 25 },+ ]));++ expect(folderCount()).toBe("0");+ expect(host.querySelector('[data-sidebar-project="taxes"] [data-sidebar-thread-row]')).toBeNull();+ expect(host.querySelector('[data-sidebar-project="taxes"]')?.textContent).not.toContain("No threads yet");+ const showAll = host.querySelector<HTMLButtonElement>('[data-sidebar-folder-show-all="taxes"]');+ expect(showAll).not.toBeNull();++ await act(async () => {+ showAll!.click();+ });+ expect(folderCount()).toBe("2");+ expect(host.querySelectorAll('[data-sidebar-project="taxes"] [data-sidebar-thread-row]')).toHaveLength(2);+ await unmount();+ });++ it("counts only open threads plus an open-in-chat archived thread while Show all is off", async () => {+ await mount(makeBot([+ { threadId: "open-main", title: "Main chat", createdAt: 10 },+ { threadId: "open-filed", title: "Current return", createdAt: 9, projectId: "taxes" },+ { threadId: "arch-1", title: "Old return", createdAt: 5, projectId: "taxes", archivedAt: 20 },+ ]));+ expect(folderCount()).toBe("1");+ await unmount();++ await mount(makeBot([+ { threadId: "open-main", title: "Main chat", createdAt: 10 },+ { threadId: "arch-active", title: "Viewing archived return", createdAt: 8, projectId: "taxes", archivedAt: 20 },+ ], "arch-active"));+ expect(folderCount()).toBe("1");+ expect(host.querySelectorAll('[data-sidebar-project="taxes"] [data-sidebar-thread-row]')).toHaveLength(1);+ await unmount();+ });+});diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsxindex c52ddf3401..85acdef964 100644--- a/src/components/Sidebar.tsx+++ b/src/components/Sidebar.tsx@@ -599,7 +599,7 @@ export function BotThreadList({ bot, selected, drafting, query, pendingQueued, rreturn next;})} 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>+ <span className="shrink-0 text-[12px] font-normal opacity-50">{(showAll || bulk.active || Boolean(query.trim()) ? projectTasks : projectTasks.filter((task) => !isArchived(task) || task.threadId === bot.threadId || task.pinned === true)).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) => !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 })}