Skip to content

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

fix(sidebar): a hidden MausBot comes back when renamed or moved, and search finds it

AdityaUmale04a614865db6
diff --git a/server/default-bot.e2e.test.ts b/server/default-bot.e2e.test.ts
index db90b199bc..a27d85955a 100644
--- a/server/default-bot.e2e.test.ts
+++ b/server/default-bot.e2e.test.ts
@@ -53,6 +53,18 @@ it("makes MausBot a new install's first bot, never deleted, hidden by its switch
expect((await bots()).find((bot) => bot.id === maus.id)?.sidebarHidden).toBe(true);
expect((await api("PATCH", `/api/bots/${maus.id}`, { sidebarHidden: false })).status).toBe(200);
expect((await bots()).find((bot) => bot.id === maus.id)?.sidebarHidden).toBe(false);
+ // A hidden MausBot comes back when it is renamed or moved to a department, unless the change itself says hidden.
+ const hiddenAfter = async (patch: Record<string, unknown>) => {
+ expect((await api("PATCH", `/api/bots/${maus.id}`, { sidebarHidden: true })).status).toBe(200);
+ expect((await api("PATCH", `/api/bots/${maus.id}`, patch)).status).toBe(200);
+ return (await bots()).find((bot) => bot.id === maus.id)?.sidebarHidden;
+ };
+ expect(await hiddenAfter({ color: "blue" })).toBe(true);
+ expect(await hiddenAfter({ name: "Nova" })).toBe(false);
+ expect(await hiddenAfter({ section: "C Suite" })).toBe(false);
+ expect(await hiddenAfter({ section: "C Suite" })).toBe(true);
+ expect(await hiddenAfter({ name: "Nova Two", sidebarHidden: true })).toBe(true);
+ expect((await api("PATCH", `/api/bots/${maus.id}`, { name: maus.name, section: null, sidebarHidden: false })).status).toBe(200);
const { bot: clive } = await control(["new-bot", "--name", "Clive"]);
expect((await api("PATCH", `/api/bots/${clive.id}`, { sidebarHidden: true })).status).toBe(400);
diff --git a/server/store.ts b/server/store.ts
index 71601fd75c..053ca33802 100644
--- a/server/store.ts
+++ b/server/store.ts
@@ -5,7 +5,7 @@ import { OwnedFile, writeFileAtomic } from "./atomic.ts"; import { saveSoon } fr
import { commitRegistryChange, keptRevocation, saveRegistryFor, touchesPermissions } from "./registry-save.ts";
import { parseToolScope, toolScopeWidens } from "../shared/tool-scope.ts"; import { grantScopedApps } from "../shared/connector-scopes.ts"; import { dropRetiredApps } from "./retired-apps.ts";
import { reorderStable } from "../shared/bot-order.ts"; import { trimOutboundPolicy } from "../shared/outbound.ts";
-import { botOwner, chiefConflict, chiefScope, ownerEmail } from "../shared/bot-owner.ts";
+import { botOwner, chiefConflict, chiefScope, ownerEmail } from "../shared/bot-owner.ts"; import { reshowWhenMoved } from "../shared/default-bot.ts";
import { ensureSections, readSections, changeEmptySection } from "./section-context.ts";
import type { TeamComputers } from "./team-computers.ts";
import { removeBotFolder, soulFile, soulHash, writeSoulMirror } from "./bot-folder.ts";
@@ -1506,7 +1506,7 @@ export class Store {
patchBot(id: string, patch: Partial<BotRecord>): BotRecord | null {
const bot = this.bot(id);
- if (!bot) return null;
+ if (!bot) return null; patch = reshowWhenMoved(bot, patch);
if (patch.connectorTools !== undefined) {
const parsed = parseConnectorTools(patch.connectorTools);
if (!parsed.ok) throw new Error(parsed.error);
diff --git a/shared/default-bot.ts b/shared/default-bot.ts
index bf619e1bd0..52bc8930a4 100644
--- a/shared/default-bot.ts
+++ b/shared/default-bot.ts
@@ -34,3 +34,15 @@ export function viewersDefaultBot<T extends DefaultBotFields>(bots: readonly T[]
return (person ? bots.find((bot) => bot.defaultBot && defaultBotPerson(bot) === person) : undefined)
?? bots.find((bot) => bot.defaultBot && !defaultBotPerson(bot));
}
+
+/** A MausBot hidden from the sidebar comes back when it is renamed or moved to another department, unless the same
+ * change says whether to show it. Returns the patch to save. */
+export function reshowWhenMoved<P extends { name?: string; section?: string; sidebarHidden?: boolean }>(
+ bot: DefaultBotFields & { name: string; section?: string },
+ patch: P,
+): P {
+ if (!bot.defaultBot || !bot.sidebarHidden || Object.hasOwn(patch, "sidebarHidden")) return patch;
+ const renamed = patch.name !== undefined && patch.name.trim() !== bot.name.trim();
+ const moved = Object.hasOwn(patch, "section") && (patch.section?.trim() ?? "") !== (bot.section?.trim() ?? "");
+ return renamed || moved ? { ...patch, sidebarHidden: false } : patch;
+}
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx
index fdb9e74486..d3739f6391 100644
--- a/src/components/Sidebar.tsx
+++ b/src/components/Sidebar.tsx
@@ -1101,7 +1101,7 @@ export function Sidebar({ open, onClose, collapseToIcons = false }: {
);
const visibleGroups = state.groups.filter((g) => !q || g.name.toLowerCase().includes(q) || g.tasks?.some((task) => task.title.toLowerCase().includes(q)));
const viewerEmail = useViewerEmail();
- const parts = partitionSidebarBots(botDrag.preview(matchingBots), { universalPins, viewerEmail, welcoming: useWelcomingBot() });
+ const parts = partitionSidebarBots(botDrag.preview(matchingBots), { universalPins, viewerEmail, welcoming: useWelcomingBot(), searching: Boolean(q) });
const saved = simpleDesk ? withPrimaryTile(parts, myDefaultBot(state.bots, viewerEmail)?.id) : { ...parts, primary: null };
// Shown order only: drag and Alt+Up/Down keep working on the saved order, so a reorder never stores this one.
const { primary, unsectionedChief, pinnedBots, sectionChiefs, sectionedBots, unsectionedBots } = { ...saved, ...activeBotsFirst(saved, (bot) => {
diff --git a/src/lib/sidebar-layout.test.ts b/src/lib/sidebar-layout.test.ts
index 14849653a6..d0758a7202 100644
--- a/src/lib/sidebar-layout.test.ts
+++ b/src/lib/sidebar-layout.test.ts
@@ -117,6 +117,13 @@ describe("sidebar virtual sections", () => {
expect(home.section).toBe("Home");
});
+ it("finds the viewer's own hidden MausBot in a search, never someone else's", () => {
+ const mine = { id: "nova", defaultBot: {}, sidebarHidden: true, section: "C Suite" };
+ const theirs = { id: "theirs", defaultBot: { person: "[email protected]" }, section: "C Suite" };
+ expect(partitionSidebarBots([mine, theirs], { viewerEmail: null }).sectionedBots).toEqual([]);
+ expect(partitionSidebarBots([mine, theirs], { viewerEmail: null, searching: true }).sectionedBots).toEqual([mine]);
+ });
+
it("lists a group's pinned Chief with the pinned bots on every client; the main Chief keeps its own top slot", () => {
const bots = [
{ id: "work-chief", chiefOfStaff: true, section: "Work", pinned: true },
diff --git a/src/lib/sidebar-layout.ts b/src/lib/sidebar-layout.ts
index a109209608..02c60fb365 100644
--- a/src/lib/sidebar-layout.ts
+++ b/src/lib/sidebar-layout.ts
@@ -3,7 +3,7 @@ import type { ConnectorCardData } from "../../shared/connector-card";
import { t } from "./i18n";
import type { LocaleKey } from "@/locales";
import type { DefaultBotFields } from "../../shared/default-bot";
-import { hiddenFromSidebar } from "./default-bot";
+import { hiddenFromSidebar, someoneElsesDefaultBot } from "./default-bot";
export const PINNED_SECTION_ID = "builtin:pinned";
export const CHANNELS_SECTION_ID = "builtin:channels";
@@ -109,10 +109,12 @@ export function pinnedCircleThreadListVisible(
export function partitionSidebarBots<T extends SidebarBot>(
bots: T[],
- options?: { universalPins?: boolean; viewerEmail?: string | null; welcoming?: string | null },
+ options?: { universalPins?: boolean; viewerEmail?: string | null; welcoming?: string | null; searching?: boolean },
) {
const universalPins = options?.universalPins === true;
- const visible = bots.filter((bot) => !bot.hidden && !hiddenFromSidebar(bot, options?.viewerEmail) && bot.id !== options?.welcoming);
+ // A search also finds the viewer's own MausBot when it is hidden from the sidebar, so it can always be reached.
+ const listed = (bot: T) => !hiddenFromSidebar(bot, options?.viewerEmail) || (options?.searching === true && !someoneElsesDefaultBot(bot, options.viewerEmail));
+ const visible = bots.filter((bot) => !bot.hidden && listed(bot) && bot.id !== options?.welcoming);
// The pin flag is the server's, the same on every client. Only the main Chief keeps its own top slot when pins are
// not universal (a device's layout choice); a pinned Chief of a group is listed with the other pinned bots.
const pinnedBots = visible.filter((bot) => Boolean(bot.pinned) && (universalPins || !bot.chiefOfStaff || Boolean(bot.section)));