Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(sidebar): keep the rail reorder inside each list
pepeneifd3f1434470c6
diff --git a/src/components/Sidebar.departments.test.ts b/src/components/Sidebar.departments.test.tsindex 46080596dc..acd8d6858c 100644--- a/src/components/Sidebar.departments.test.ts+++ b/src/components/Sidebar.departments.test.ts@@ -168,6 +168,36 @@ describe("Simple's sidebar before anyone drags", () => {expect(props.botDrag!.row(props.bot.id).draggable).toBe(true);}});++ it("reorders inside the rail's own list, and nothing else: no department is created or left unseen", () => {+ // The rail hides department names and its naming field, so a drop there must only move a tile within its list.+ fixture.storage.set(SIDEBAR_DENSITY_KEY, "avatars");+ drag("cleo");+ row("atlas").botDrag!.row("atlas").onDrop(at(5) as never);+ expect(actions()).toEqual([{ type: "botsOrdered", botIds: ["cleo", "atlas", "bea"] }]);+ expect(sections()).not.toContain(userSectionId(NEW_DEPARTMENT));+ fixture.dispatch.mockClear();++ // Onto the middle of a bot: a place above or below, never a new department whose name field the rail hides.+ drag("cleo");+ row("atlas").botDrag!.row("atlas").onDragOver(at() as never);+ expect(row("atlas").botDrop).toBe("after");+ row("atlas").botDrag!.row("atlas").onDrop(at() as never);+ expect(actions()).toEqual([{ type: "botsOrdered", botIds: ["atlas", "cleo", "bea"] }]);+ expect(sections()).not.toContain(userSectionId(NEW_DEPARTMENT));+ });++ it("refuses in the rail a drop that would change department, which the person cannot see there", () => {+ fixture.storage.set(SIDEBAR_DENSITY_KEY, "avatars");+ drag("dodo");+ expect(section(userSectionId("Work")).onDragOver).toBeInstanceOf(Function);+ const over = at();+ section(BOTS_SECTION_ID).onDragOver(over as never);+ expect(over.preventDefault).not.toHaveBeenCalled();+ section(BOTS_SECTION_ID).onDrop(over as never);+ expect(actions()).toEqual([]);+ expect(rows().every((props) => !props.botDragging)).toBe(true);+ });});describe("dragging a bot", () => {diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsxindex a85dd2a535..73ab09ffc2 100644--- a/src/components/Sidebar.tsx+++ b/src/components/Sidebar.tsx@@ -1120,7 +1120,7 @@ export function Sidebar({ open, onClose, collapseToIcons = false }: {for (const group of sectionedRooms) {if (!sectionNames.includes(group.section!)) sectionNames.push(group.section!);}- const drops = botDrag.arrange({ enabled: (sections.interactive || density === "icons") && !phone, main: saved.unsectionedBots, sectioned: saved.sectionedBots, departments: sectionNames, bots: state.bots, taken: departmentNames(state) });+ const drops = botDrag.arrange({ enabled: (sections.interactive || density === "icons") && !phone, withinList: density === "icons", main: saved.unsectionedBots, sectioned: saved.sectionedBots, departments: sectionNames, bots: state.bots, taken: departmentNames(state) });const naturalSectionIds = [...(pinnedBots.length > 0 && !universalPins && !simpleDesk ? [PINNED_SECTION_ID] : []),...(unsectionedRooms.length > 0 ? [CHANNELS_SECTION_ID] : []),diff --git a/src/components/SidebarBotDrag.tsx b/src/components/SidebarBotDrag.tsxindex 601838eaa5..f07b5ddcda 100644--- a/src/components/SidebarBotDrag.tsx+++ b/src/components/SidebarBotDrag.tsx@@ -21,7 +21,7 @@ export type SectionNaming = { value: string; label: string; onCommit: (name: strtype Naming = { kind: "new"; botIds: string[]; name: string } | { kind: "rename"; section: string };-type Arranged = { enabled: boolean; lists: Map<string, string[]>; bots: Bot[]; taken: string[] };+type Arranged = { enabled: boolean; lists: Map<string, string[]>; bots: Bot[]; taken: string[]; withinList: boolean };const carries = (event: DragEvent<HTMLElement>) => event.dataTransfer.types.includes(BOT_ROW_DRAG_TYPE);const failure = (cause: unknown) => (cause instanceof Error ? cause.message : String(cause));@@ -49,7 +49,7 @@ export function useSidebarBotDrag({ dispatch, announce, onNamed, onRenamed, onErconst [drop, setDrop] = useState<BotDrop | null>(null);const [naming, setNaming] = useState<Naming | null>(null);const mayMove = useMayMoveBots();- const latest = useRef<Arranged>({ enabled: false, lists: new Map(), bots: [], taken: [] });+ const latest = useRef<Arranged>({ enabled: false, lists: new Map(), bots: [], taken: [], withinList: false });const moving = useRef<{ botId: string | null; drop: BotDrop | null }>({ botId: null, drop: null });const controller = useRef<BotRowDrag | null>(null);const actions = useRef({ dispatch, announce });@@ -76,15 +76,27 @@ export function useSidebarBotDrag({ dispatch, announce, onNamed, onRenamed, onEractions.current.announce(t("sidebar.section.moved", { name, position: move.order.indexOf(botId) + 1, count: move.order.length }));requestAnimationFrame(() => document.querySelector<HTMLElement>(`[data-sidebar-bot-row="${CSS.escape(botId)}"]`)?.focus());};+ const allowed = (botId: string, move: BotMove | null): BotMove | null => {+ if (!move) return null;+ // The icon rail shows no department names, so there a drop only reorders inside the bot's own list.+ if (!latest.current.withinList) return move;+ const from = botListOf(latest.current.lists, botId);+ if (move.kind !== "move" || move.section !== from) return null;+ return move;+ };const finish = (target: BotDrop | null) => {const botId = moving.current.botId;end();const move = botId && target && latest.current.enabled ? planBotDrop(latest.current.lists, botId, target) : null;- if (botId && move) apply(botId, move, false);+ if (botId && move) {+ const next = allowed(botId, move);+ if (next) apply(botId, next, false);+ }};const rowDrop = (event: DragEvent<HTMLElement>, botId: string): BotDrop => {const box = event.currentTarget.getBoundingClientRect();- return { kind: "row", botId, place: botDropPlace(event.clientY - box.top, box.height, botListOf(latest.current.lists, botId) === "") };+ const canGroup = !latest.current.withinList && botListOf(latest.current.lists, botId) === "";+ return { kind: "row", botId, place: botDropPlace(event.clientY - box.top, box.height, canGroup) };};controller.current ??= {@@ -136,13 +148,13 @@ export function useSidebarBotDrag({ dispatch, announce, onNamed, onRenamed, onErpreview: <T extends Bot>(bots: T[]): T[] => naming?.kind === "new" ? bots.map((bot) => (naming.botIds.includes(bot.id) ? { ...bot, section: NEW_DEPARTMENT } : bot)) : bots,startNew: (botIds: string[]) => startNew(botIds),startRename: (section: string) => setNaming({ kind: "rename", section }),- arrange({ enabled, main, sectioned, departments, bots, taken }: {- enabled: boolean; main: Bot[]; sectioned: Bot[]; departments: string[]; bots: Bot[]; taken: string[];+ arrange({ enabled, withinList = false, main, sectioned, departments, bots, taken }: {+ enabled: boolean; withinList?: boolean; main: Bot[]; sectioned: Bot[]; departments: string[]; bots: Bot[]; taken: string[];}) {const movable = enabled && mayMove;const lists = new Map<string, string[]>([["", main.map((bot) => bot.id)]]);for (const name of departments) if (name !== NEW_DEPARTMENT) lists.set(name, sectioned.filter((bot) => bot.section === name).map((bot) => bot.id));- latest.current = { enabled: movable, lists, bots, taken };+ latest.current = { enabled: movable, lists, bots, taken, withinList };const active = movable && dragging !== null && botListOf(lists, dragging) !== undefined ? dragging : null;const shown = active ? drop : null;const mainIds = lists.get("")!.filter((id) => id !== active);@@ -168,7 +180,9 @@ export function useSidebarBotDrag({ dispatch, announce, onNamed, onRenamed, onEronDragOver: (event) => {if (!carries(event)) return fallback.onDragOver(event);const list = listFor(sectionId);- if (!moving.current.botId || list === null || !lists.has(list)) return show(null);+ const dragged = moving.current.botId;+ if (!dragged || list === null || !lists.has(list)) return show(null);+ if (withinList && list !== botListOf(lists, dragged)) return show(null);event.preventDefault();event.dataTransfer.dropEffect = "move";const target = zoneDrop(event, list);