Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Never leave a bot's main thread out of its lists
luishron123d2321d8662c9
diff --git a/src/components/SidebarThreadRow.test.ts b/src/components/SidebarThreadRow.test.tsindex f5ed7ea098..11a808db32 100644--- a/src/components/SidebarThreadRow.test.ts+++ b/src/components/SidebarThreadRow.test.ts@@ -57,6 +57,14 @@ describe("sidebar thread visibility", () => {expect(visibleSidebarThreads(rows, "8", "", [], true)).toEqual(rows);});+ it("keeps the bot's main thread listed whatever its state: snoozed, an idle burst lane, a thread its opener closed", () => {+ const listed = (main: object) => visibleSidebarThreads([{ threadId: "open", title: "Open" }, { threadId: "main", title: "Main", ...main }], "open", "", [], false, [], "main").map((task) => task.threadId);+ expect(listed({ snoozedUntil: Date.now() + 3_600_000 })).toEqual(["open", "main"]);+ expect(listed({ openedBy: { botId: "maus", name: "Maus", burstId: "burst" } })).toEqual(["open", "main"]);+ expect(listed({ openedBy: { botId: "atlas", name: "Atlas" }, closedBy: { botId: "atlas", name: "Atlas" } })).toEqual(["open", "main"]);+ expect(visibleSidebarThreads([{ threadId: "open", title: "Open" }, { threadId: "main", title: "Main", snoozedUntil: Date.now() + 3_600_000 }], "open").map((task) => task.threadId)).toEqual(["open"]);+ });+it("keeps the bot's main thread listed when it is older than the six recent rows", () => {expect(visibleSidebarThreads(tasks, "0", "", [], false, [], "9").map((task) => task.threadId)).toEqual(["0", "1", "2", "3", "4", "5", "9"]);expect(visibleSidebarThreads(tasks, "0").map((task) => task.threadId)).toEqual(["0", "1", "2", "3", "4", "5"]);diff --git a/src/components/SidebarThreadRow.tsx b/src/components/SidebarThreadRow.tsxindex a6dc11c49e..8afbe0a613 100644--- a/src/components/SidebarThreadRow.tsx+++ b/src/components/SidebarThreadRow.tsx@@ -155,14 +155,14 @@ export function visibleSidebarThreads<T extends ThreadRowTask>(tasks: T[], activif (!seen || run.createdAt > seen.createdAt) newestRun.set(run.routineId, run);}return orderedThreadList(tasks).filter((task) => {- if (task.pinned === true) return true;+ if (task.pinned === true || task.threadId === mainId) return true;if (task.openedBy?.burstId) return task.threadId === activeId || demandsAttention(task, activeId);if (isArchived(task)) return task.threadId === activeId;const run = runOf.get(task.threadId);if (run && newestRun.get(run.routineId) !== run) return demandsAttention(task, activeId);return task.closedBy || isSnoozed(task)? demandsAttention(task, activeId)- : open++ < 6 || task.threadId === mainId || demandsAttention(task, activeId);+ : open++ < 6 || demandsAttention(task, activeId);});}diff --git a/src/components/sidebar-thread-labels.test.ts b/src/components/sidebar-thread-labels.test.tsindex 91b4ac0e6c..ec046cea1d 100644--- a/src/components/sidebar-thread-labels.test.ts+++ b/src/components/sidebar-thread-labels.test.ts@@ -39,6 +39,18 @@ describe("a bot's threads under its sidebar row", () => {expect(labels.more).toBe(2);});+ it("unfolded, lists the main thread first whoever opened it and whatever its state", () => {+ const listed = (main: Partial<Task>) => {+ const labels = threadLabels({ ...bot([thread("a", 1), thread("b", 2), thread("main", 30, main)], "a"), mainThreadId: "main" }, {}, { unfolded: true, current: "a", rowThreadId: "a", now: NOW });+ return labels.rows.map((row) => [row.task.threadId, row.main]);+ };+ const first = [["main", true], ["a", false], ["b", false]];+ expect(listed({ openedBy: { botId: "atlas", name: "Atlas", at: 1 } })).toEqual(first);+ expect(listed({ openedBy: { botId: "maus", name: "Maus", at: 1, burstId: "burst" } })).toEqual(first);+ expect(listed({ snoozedUntil: NOW + DAY })).toEqual(first);+ expect(canUnfold({ ...bot([thread("a", 1), thread("main", 30, { openedBy: { botId: "atlas", name: "Atlas", at: 1 } })]), mainThreadId: "main" })).toBe(true);+ });+it("leaves a week-old thread nobody touched in the count, not the list", () => {const labels = threadLabels(bot([thread("main", 1), thread("stale", 8)]), {}, { unfolded: true, rowThreadId: "main", now: NOW });expect(ids(labels)).toEqual(["main"]);diff --git a/src/components/sidebar-thread-labels.ts b/src/components/sidebar-thread-labels.tsindex 0ee33fd8b6..701a94c4df 100644--- a/src/components/sidebar-thread-labels.ts+++ b/src/components/sidebar-thread-labels.ts@@ -18,10 +18,11 @@ type LabelBot = Pick<Bot, "threadId"> & Partial<Pick<Bot, "mainThreadId" | "task/** The person started it: not a routine run, and not opened by a bot (its own new thread, a burst or a hand-off). */export const ownThread = (task: Pick<Task, "routineRunId" | "openedBy">): boolean => !task.routineRunId && !task.openedBy;-const ownOpen = (bot: Pick<LabelBot, "tasks">) => (bot.tasks ?? []).filter((task) => ownThread(task) && !isArchived(task) && !isSnoozed(task));+/** The threads a bot unfolds to: the person's own open ones, and its main thread whoever opened it and whatever its state. */+const ownOpen = (bot: Pick<LabelBot, "tasks" | "mainThreadId">) => (bot.tasks ?? []).filter((task) => task.threadId === bot.mainThreadId || (ownThread(task) && !isArchived(task) && !isSnoozed(task)));/** Only a bot with more than one thread of the person's own has anything to unfold. */-export const canUnfold = (bot: Pick<LabelBot, "tasks">): boolean => ownOpen(bot).length > 1;+export const canUnfold = (bot: Pick<LabelBot, "tasks" | "mainThreadId">): boolean => ownOpen(bot).length > 1;export function labelStatus(task: LabelTask): LabelStatus {if (task.activity === "waiting-on-you") return "waiting";