Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Merge the clean workspace follow-up; groups keep a fixed order on the rail
milind-sonibf398d11d988
diff --cc electron/accounts-main.mjsindex 2d4d9d25a3,188345023d..f80590e8da--- a/electron/accounts-main.mjs+++ b/electron/accounts-main.mjs@@@ -70,17 -34,22 +70,18 @@@ export function createDesktopRing(deps* placePage(event: unknown): boolean,* account(): { state(): any } | null,* client(): { state(): any, signOut(): Promise<any> },+ * ring(): ReturnType<typeof import("./cloud-accounts.mjs").createCloudAccounts> | null,* holdSheet(open: boolean): void,* tellSheet(): void,- * leaving(): void,- * leave: ReturnType<typeof createAccountLeave>,- * show(): Promise<unknown>,* tell(): void,- * }} deps `ownPage`: this app's own page in the window, or the rail's. `placePage`: the page of a place of the person's own+ * clean?(): boolean,+ * }} deps `clean`: the clean workspace runs (clean-workspace.mjs). `ownPage`: this app's own page in the window, or the rail's. `placePage`: the page of a place of the person's own- * or their team's, which may offer the sheet. `holdSheet`: the rail's page stays up for the sheet, even for someone who hid- * the rail. `leaving`: the home window lets go of what it was doing for this account; `leave`: createAccountLeave's;- * `show`: the window goes where it belongs now; `tell`: this app's pages read the list again.+ * or their team's, which may offer the sheet. `ring`: the accounts kept on this device. `holdSheet`: the rail's page stays up+ * for the sheet, even for someone who hid the rail. `tell`: this app's pages read the list again.*/- export function installAccounts({ ipcMain, ownPage, placePage, account, client, ring, holdSheet, tellSheet, tell }) {-export function installAccounts({ ipcMain, ownPage, placePage, account, client, holdSheet, tellSheet, leaving, leave, show, tell, clean = () => false }) {- let sheetPending = false, queue = Promise.resolve();++export function installAccounts({ ipcMain, ownPage, placePage, account, client, ring, holdSheet, tellSheet, tell, clean = () => false }) {+ let sheetPending = false;- const view = () => accountsView(account()?.state());+ const view = () => ({ ...accountsView(account()?.state()), ...(clean() ? { clean: true } : {}) });- const serial = (work) => { const run = queue.then(work, work); queue = run.catch(() => {}); return run; };const own = (channel, handler) => ipcMain.handle(channel, (event, ...args) => {if (!ownPage(event)) throw new Error(`${channel} is only available on this app's own page`);return handler(...args);diff --cc electron/accounts-main.node-test.mjsindex 549bf99697,55853a02c7..0a2de741a6--- a/electron/accounts-main.node-test.mjs+++ b/electron/accounts-main.node-test.mjs@@@ -226,3 -143,14 +226,14 @@@ test("a My Cloud saved by hand is the aassert.equal(withoutPlaces(changed, [byHand]).activeId, "local");assert.equal(withoutPlaces(changed, []), changed, "nothing to remove: the same list");});++ test("the view says when the clean workspace runs, for the You menu's Sign in; nothing changes otherwise", async () => {+ const handlers = new Map();+ let clean = true;+ const client = { state: () => ({ status: "signed-out" }) };+ installAccounts({ ipcMain: { handle: (channel, handler) => handlers.set(channel, handler) }, ownPage: () => true, placePage: () => true, account: () => client, client: () => client, clean: () => clean,- holdSheet() {}, tellSheet() {}, leaving() {}, leave: { places: () => [], finish: async () => [] }, show: async () => {}, tell() {} });- assert.deepEqual(await handlers.get("accounts:list")({}), { active: null, others: [], clean: true });++ ring: () => null, holdSheet() {}, tellSheet() {}, tell() {} });++ assert.deepEqual(await handlers.get("accounts:list")({}), { active: null, clean: true });+ clean = false;- assert.deepEqual(await handlers.get("accounts:list")({}), { active: null, others: [] });++ assert.deepEqual(await handlers.get("accounts:list")({}), { active: null });+ });diff --cc electron/cloud-account.d.mtsindex 50faf71588,8af5360fb5..186a3a18de--- a/electron/cloud-account.d.mts+++ b/electron/cloud-account.d.mts@@@ -174,15 -174,8 +174,16 @@@ export interface CloudAccountBridge}/** Who is signed in on this device, as the You menu shows it. `signIn`: this account's sign-in has ended here. */export interface AccountRow { id: string; email: string; signIn?: true }- export interface AccountsView { active: AccountRow | null }+ /** `clean`: the clean workspace runs on this computer, whose line asks the person to sign in. */-export interface AccountsView { active: AccountRow | null; others: AccountRow[]; clean?: true }++export interface AccountsView { active: AccountRow | null; clean?: true }+export interface AccountSwitchResult { outcome: "switched" | "signed-out" | "moving" | "sign-in" | "gone" | "failed"; email?: string; view: AccountsView }+/** What a click on a place of another account answers when it didn't switch: nothing moved. `sign-in`: that sign-in has ended. */+export interface RailOpenResult { outcome: "switched" | "moving" | "sign-in" | "gone" | "failed"; email?: string }+/** `added`: kept signed in, not switched to, while this computer's move finishes; `already`: that account is the one signed in. */+export type AccountAddResult =+ | { outcome: "switched" | "added" | "already"; email?: string; view: AccountsView }+ | { outcome: "wrong-code"; triesLeft: number }+ | { outcome: Exclude<import("./cloud-signin.mjs").CloudSignInVerifyFailure, "wrong-code"> };/** This app's own pages only: main refuses any other page. Absent on an older app. */export interface AccountsBridge {list(): Promise<AccountsView>;diff --cc electron/main.mjsindex 5188267904,338dd50a41..dde97fb576--- a/electron/main.mjs+++ b/electron/main.mjs@@@ -2688,8 -2688,8 +2688,8 @@@ const chromeRail = createChromeRail({ cchromeRail.install(ipcMain);function railChanged() { chromeRail.refresh(); rail.changed(); }const accountPages = [() => (mainWindow && !mainWindow.isDestroyed() && senderIsLocal({ sender: mainWindow.webContents }) ? mainWindow.webContents : null), () => ({ send: channel => chromeRail.send(channel) })];- const accountRing = createDesktopRing({ allowed: () => app.isPackaged && !desktopRemoteAccess, active: cloudAccountStore, savedStore: () => createCloudAccountStore({ file: path.join(app.getPath("userData"), cloudTarget(process.env).saved), encryption: cloudEncryption }), stash: () => jsonFile(path.join(app.getPath("userData"), cloudTarget(process.env).places)), client: ensureCloudAccount, origin: cloudTarget(process.env).origin, makeClient: ({ store, onState }) => createCloudAccountClient({ store, onState, platform: process.platform, deviceName: os.hostname().slice(0, 100) || "My computer", appVersion: app.getVersion(), origin: cloudTarget(process.env).origin, openBrowser: url => shell.openExternal(url) }), saved: () => environmentsState, persist: persistEnvironments, session: () => session.defaultSession, mine: () => myCloud(), leaveWindow: () => (mainWindow && !mainWindow.isDestroyed() && !senderIsLocal({ sender: mainWindow.webContents }) ? navigateMainWindow(rendererOrigin()) : null), rows: () => railList(), holding: () => oneHome.holding(), letGo: id => { homeWindow.accountLeaving(); homePlaces.remember(null); computerSharing?.leaveAccount(id); }, lendingDone: () => computerSharing?.goodbyesDone(), settled: () => showHome(), forgetLending: env => sharingController().forget(env), tell: () => { accounts.tell(); railChanged(); }, log: slog }); const accounts = installAccounts({ ipcMain, ownPage: event => chromeRail.owns(event) || cloudPageAsking(event) === "local", placePage: event => cloudPageAsking(event) !== null || ownCloudPage(event) !== null || homeWindow.homePage(event) || (Boolean(ownHome?.home()) && activeEnvironment(environmentsState)?.origin === ownHome.home().origin && workspaceSenderAllowed(event, mainWindow?.webContents, environmentsState, rendererOrigin())), account: () => (app.isPackaged && !desktopRemoteAccess ? cloudAccount : null), client: ensureCloudAccount, ring: accountRing, holdSheet: open => chromeRail.holdOpen(open), tellSheet: () => chromeRail.send("accounts:open-sheet"), tell: () => { for (const page of accountPages) page()?.send("accounts:changed"); } });-const accounts = installAccounts({ ipcMain, clean: () => cleanWorkspace.active(), ownPage: event => chromeRail.owns(event) || cloudPageAsking(event) === "local", placePage: event => cloudPageAsking(event) !== null || ownCloudPage(event) !== null || homeWindow.homePage(event) || (Boolean(ownHome?.home()) && activeEnvironment(environmentsState)?.origin === ownHome.home().origin && workspaceSenderAllowed(event, mainWindow?.webContents, environmentsState, rendererOrigin())), account: () => (app.isPackaged && !desktopRemoteAccess ? cloudAccount : null), client: ensureCloudAccount, holdSheet: open => chromeRail.holdOpen(open), tellSheet: () => chromeRail.send("accounts:open-sheet"), leaving: () => homeWindow.accountLeaving(), leave: createAccountLeave({ saved: () => environmentsState, persist: persistEnvironments, session: () => session.defaultSession, mine: () => myCloud(), leaveWindow: () => (mainWindow && !mainWindow.isDestroyed() && !senderIsLocal({ sender: mainWindow.webContents }) ? navigateMainWindow(rendererOrigin()) : null), settled: () => computerSharing?.goodbyesDone(), log: slog }), show: () => showHome(), tell: () => { for (const page of accountPages) page()?.send("accounts:changed"); } });-const rail = installCloudRail({ ipcMain, clipboard, openCloud: openOwnCloud, account: () => (app.isPackaged && !desktopRemoteAccess ? cloudAccount : null),++const accountRing = createDesktopRing({ allowed: () => app.isPackaged && !desktopRemoteAccess, active: cloudAccountStore, savedStore: () => createCloudAccountStore({ file: path.join(app.getPath("userData"), cloudTarget(process.env).saved), encryption: cloudEncryption }), stash: () => jsonFile(path.join(app.getPath("userData"), cloudTarget(process.env).places)), client: ensureCloudAccount, origin: cloudTarget(process.env).origin, makeClient: ({ store, onState }) => createCloudAccountClient({ store, onState, platform: process.platform, deviceName: os.hostname().slice(0, 100) || "My computer", appVersion: app.getVersion(), origin: cloudTarget(process.env).origin, openBrowser: url => shell.openExternal(url) }), saved: () => environmentsState, persist: persistEnvironments, session: () => session.defaultSession, mine: () => myCloud(), leaveWindow: () => (mainWindow && !mainWindow.isDestroyed() && !senderIsLocal({ sender: mainWindow.webContents }) ? navigateMainWindow(rendererOrigin()) : null), rows: () => railList(), holding: () => oneHome.holding(), letGo: id => { homeWindow.accountLeaving(); homePlaces.remember(null); computerSharing?.leaveAccount(id); }, lendingDone: () => computerSharing?.goodbyesDone(), settled: () => showHome(), forgetLending: env => sharingController().forget(env), tell: () => { accounts.tell(); railChanged(); }, log: slog }); const accounts = installAccounts({ ipcMain, clean: () => cleanWorkspace.active(), ownPage: event => chromeRail.owns(event) || cloudPageAsking(event) === "local", placePage: event => cloudPageAsking(event) !== null || ownCloudPage(event) !== null || homeWindow.homePage(event) || (Boolean(ownHome?.home()) && activeEnvironment(environmentsState)?.origin === ownHome.home().origin && workspaceSenderAllowed(event, mainWindow?.webContents, environmentsState, rendererOrigin())), account: () => (app.isPackaged && !desktopRemoteAccess ? cloudAccount : null), client: ensureCloudAccount, ring: accountRing, holdSheet: open => chromeRail.holdOpen(open), tellSheet: () => chromeRail.send("accounts:open-sheet"), tell: () => { for (const page of accountPages) page()?.send("accounts:changed"); } });+const rail = installCloudRail({ ipcMain, clipboard, openCloud: openOwnCloud, switchAccount: id => accountRing().switchTo(id), account: () => (app.isPackaged && !desktopRemoteAccess ? cloudAccount : null),guard: handler => (event, ...args) => (chromeRail.owns(event) ? handler(event, ...args) : workspaceOnly(handler)(event, ...args)),lists: event => chromeRail.owns(event), trusted: event => chromeRail.owns(event) || senderIsLocal(event), beside: () => chromeRail.shown(),targets: () => [mainWindow && !mainWindow.isDestroyed() ? mainWindow.webContents : null, { send: channel => chromeRail.send(channel), isDestroyed: () => false }],diff --cc electron/rail-accounts.mjsindex 13bb3e34d7,0000000000..08e2b36f9emode 100644,000000..100644--- a/electron/rail-accounts.mjs+++ b/electron/rail-accounts.mjs@@@ -1,48 -1,0 +1,48 @@@+// The rail with several accounts signed in on this device: it lists places, each place knows its account, and a click on a+// place of another account switches first (cloud-rail.mjs `workspaces:open`). An account that waits makes no request and has no+// timer, so its places show as they looked when it was last the one in use, with no counts or live state.+//+// Security: these rows go only to the rail's own page (cloud-rail.mjs), the one page allowed to know other accounts' addresses.+// With one account nothing here changes the rail at all.++/** A place of no Cloud: an account with nothing on the rail still has one way to reach it. */+export const ACCOUNT_PLACE = "account:";+const ACTIVE = "active", HAND = "hand";++/** The account's places as the rail shows them now, to keep while it waits: what they are and how they look, nothing that would+ * need asking again and nothing to act on but opening. This computer and a server saved by hand aren't any account's. */+export function accountRows(rows) {+ return rows.filter((row) => row.opens && row.kind !== "computer" && !row.forget && !row.account)+ .map(({ id, name, color, kind, ended }) => ({ id, name, color, kind, opens: true, ...(ended ? { ended: true } : {}) }));+}++/**- * The rail's rows, grouped: This computer, the account in use, each account that waits, then servers saved by hand. A Cloud two- * accounts can reach (a team's) is one row: the account in use's when it can, else the first that waits. An account left with- * no row gets one of its own.++ * The rail's rows, grouped: This computer, each account by its address, then servers saved by hand. A Cloud two accounts can reach++ * (a team's) is one row: the account in use's when it can, else the first that waits. An account that waits, left with no row, gets++ * one of its own.+ * @param {any[]} all the account in use's rows, from railPlaces.+ * @param {{ saved: { environments: any[] }, email?: string | null, waiting?: Array<{ id: string, email: string, signIn?: true, places: any[], rows: any[] }> }} input+ */+export function withAccounts(all, { saved, email = null, waiting = [] }) {+ if (!waiting.length) return all;+ const taken = new Set(saved.environments.map((entry) => entry.origin).filter(Boolean));+ const first = (account, row) => {+ const origin = account.places.find((entry) => entry.id === row.id)?.origin;+ if (!origin) return true;+ if (taken.has(origin)) return false;+ taken.add(origin);+ return true;+ };- const others = waiting.flatMap((account) => {++ const rowsOf = (account) => {+ const mark = { account: account.id, group: account.id, email: account.email, ...(account.signIn ? { signIn: true } : {}) };+ const rows = account.rows.filter((row) => first(account, row)).map((row) => ({ ...row, ...mark }));+ return rows.length ? rows : [{ id: `${ACCOUNT_PLACE}${account.id}`, name: account.email, color: null, kind: "account", opens: true, ...mark }];- });++ };+ const isComputer = (row) => row.kind === "computer";- return [- ...all.filter(isComputer),- ...all.filter((row) => !isComputer(row) && !row.forget).map((row) => ({ ...row, group: ACTIVE, ...(email ? { email } : {}) })),- ...others,- ...all.filter((row) => row.forget).map((row) => ({ ...row, group: HAND })),- ];++ // The first claim to a Cloud two accounts share is the account in use's, whatever the order they show in.++ const waited = waiting.map((account) => ({ email: account.email, rows: rowsOf(account) }));++ const own = all.filter((row) => !isComputer(row) && !row.forget).map((row) => ({ ...row, group: ACTIVE, ...(email ? { email } : {}) }));++ // In a fixed order, so a click that makes another account the one in use doesn't move the row under the pointer.++ const groups = [...(own.length ? [{ email: email ?? "", rows: own }] : []), ...waited].sort((a, b) => a.email.localeCompare(b.email));++ return [...all.filter(isComputer), ...groups.flatMap((group) => group.rows), ...all.filter((row) => row.forget).map((row) => ({ ...row, group: HAND }))];+}diff --cc electron/rail-accounts.node-test.mjsindex 456f4cd246,0000000000..dc9bf93c1dmode 100644,000000..100644--- a/electron/rail-accounts.node-test.mjs+++ b/electron/rail-accounts.node-test.mjs@@@ -1,167 -1,0 +1,175 @@@+import assert from "node:assert/strict";+import test from "node:test";++import environments from "./environments.cjs";+import { installCloudRail, railPlaces } from "./cloud-rail.mjs";+import { accountRows, ACCOUNT_PLACE, withAccounts } from "./rail-accounts.mjs";++const { LOCAL_ID } = environments;+// The owner's list of cases for the rail with several accounts: each is a test here, by its number.+const myCloud = (origin, id = origin) => ({ id, kind: "remote", origin, name: "My Cloud", home: true });+const ownCloud = (origin, name, id = origin) => ({ id, kind: "remote", origin, name, cloud: { id: `c-${id}`, role: "owner" } });+const teamCloud = (origin, name, id = origin) => ({ id, kind: "remote", origin, name, team: { id: `t-${origin}`, role: "member" } });+const byHand = (origin, name) => ({ id: origin, kind: "remote", origin, name });+const signedIn = (email, extra = {}) => ({ status: "connected", account: { id: email, email }, ...extra });+const list = (environmentsList, activeId = LOCAL_ID) => ({ environments: environmentsList, activeId });+const waits = (email, places, rows = places.map((entry) => ({ id: entry.id, name: entry.name, color: null, kind: entry.team ? "team" : "cloud", opens: true }))) => ({ id: email, email, places, rows });+const ids = (rows) => rows.map((row) => row.id);+const dividers = (rows) => rows.slice(1).filter((row, at) => row.group !== rows[at].group).length;++test("1. no account: This computer and hand-connected servers only, as ever, with no grouping", () => {+ assert.deepEqual(railPlaces({ saved: list([]) }), [], "only This computer: no rail");+ const rows = railPlaces({ saved: list([byHand("https://hand.test", "Hand")]) });+ assert.deepEqual(ids(rows), [LOCAL_ID, "https://hand.test"]);+ assert.equal(dividers(rows), 0);+ assert.equal(rows.some((row) => row.email || row.group), false);+});++test("2, 3, 4, 5. one account: exactly today's rail, with no grouping, divider or address", () => {+ const shapes = [+ [myCloud("https://a.test")],+ [myCloud("https://a.test"), ownCloud("https://a2.test", "Two"), ownCloud("https://a3.test", "Three"), ownCloud("https://a4.test", "Four"), ownCloud("https://a5.test", "Five")],+ [myCloud("https://a.test"), teamCloud("https://t.test", "Team")],+ [teamCloud("https://t.test", "Team")],+ ];+ for (const places of shapes) {+ const state = signedIn(A);+ const none = railPlaces({ saved: list(places), mine: "https://a.test", state });+ assert.deepEqual(railPlaces({ saved: list(places), mine: "https://a.test", state, waiting: [] }), none);+ assert.equal(dividers(none), 0);+ assert.equal(JSON.stringify(none).includes("@"), false, "no address");+ assert.equal(none.some((row) => row.group !== undefined), false);+ }+});++test("6. two accounts, one Cloud each, both called My Cloud: told apart by group, divider and address; This computer on top", () => {+ const rows = railPlaces({ saved: list([myCloud("https://a.test", "a-home")]), mine: "https://a.test", state: signedIn(A), waiting: [waits(B, [myCloud("https://b.test", "b-home")])] });+ assert.deepEqual(ids(rows), [LOCAL_ID, "a-home", "b-home"]);+ assert.deepEqual(rows.map((row) => row.name), ["This computer", "My Cloud", "My Cloud"]);+ assert.deepEqual(rows.map((row) => row.email ?? null), [null, A, B]);+ assert.equal(rows[0].group, undefined, "This computer is no account's");+ assert.equal(dividers(rows), 2);+ assert.equal(rows[1].account, undefined, "a click on the account in use's own place doesn't switch");+ assert.equal(rows[2].account, B);+});+- test("7. two accounts with several Clouds and teams: the account in use first, each group in its order, colours per Cloud", () => {++test("7. two accounts with several Clouds and teams: groups in a fixed order by address, each in its order, colours per Cloud", () => {+ const b = [myCloud("https://b.test", "b1"), ownCloud("https://b2.test", "B Two", "b2"), teamCloud("https://bt.test", "B Team", "b3")];+ const rows = railPlaces({ saved: list([myCloud("https://a.test", "a1"), ownCloud("https://a2.test", "A Two", "a2"), teamCloud("https://at.test", "A Team", "a3")]), mine: "https://a.test", state: signedIn(A),+ waiting: [waits(B, b, [{ id: "b1", name: "My Cloud", color: "red", kind: "cloud", opens: true }, { id: "b2", name: "B Two", color: "blue", kind: "cloud", opens: true }, { id: "b3", name: "B Team", color: null, kind: "team", opens: true }])] });+ assert.deepEqual(ids(rows), [LOCAL_ID, "a1", "a2", "a3", "b1", "b2", "b3"]);+ assert.deepEqual(rows.slice(4).map((row) => row.color), ["red", "blue", null], "as they looked");+ assert.equal(new Set(rows.slice(1, 4).map((row) => row.group)).size, 1);+ assert.equal(new Set(rows.slice(4).map((row) => row.group)).size, 1);+});++test("8. an account with no Clouds has one row of its own while it waits; while it's the one in use, it has none", () => {+ const rows = railPlaces({ saved: list([myCloud("https://a.test", "a1")]), mine: "https://a.test", state: signedIn(A), waiting: [{ id: C, email: C, places: [], rows: [] }] });+ assert.deepEqual(ids(rows), [LOCAL_ID, "a1", `${ACCOUNT_PLACE}${C}`]);+ assert.deepEqual({ kind: rows[2].kind, name: rows[2].name, opens: rows[2].opens, account: rows[2].account }, { kind: "account", name: C, opens: true, account: C });+ const active = railPlaces({ saved: list([]), state: signedIn(C), waiting: [waits(A, [myCloud("https://a.test", "a1")])] });+ assert.deepEqual(ids(active), [LOCAL_ID, "a1"], "the rail stands though the one in use has nothing on it");+});++test("9. the same team under both accounts is one row: the account in use's when it's a member, else the first that waits", () => {+ const mine = teamCloud("https://t.test", "Team", "t-as-a"), theirs = teamCloud("https://t.test", "Team", "t-as-b");+ const both = railPlaces({ saved: list([mine]), state: signedIn(A), waiting: [waits(B, [theirs])] });- assert.deepEqual(ids(both), [LOCAL_ID, "t-as-a", `${ACCOUNT_PLACE}${B}`], "one row, opened as the account in use, and B can still be reached");++ assert.deepEqual(ids(both).sort(), [LOCAL_ID, "t-as-a", `${ACCOUNT_PLACE}${B}`].sort(), "one row, opened as the account in use, and B can still be reached");+ assert.equal(both[1].account, undefined);+ const notMine = railPlaces({ saved: list([]), state: signedIn(A), waiting: [waits(B, [theirs]), waits(C, [teamCloud("https://t.test", "Team", "t-as-c")])] });+ assert.deepEqual(ids(notMine), [LOCAL_ID, "t-as-b", `${ACCOUNT_PLACE}${C}`]);+ assert.equal(notMine[1].account, B, "a click switches to the one that is a member");+});++test("10. a Cloud that ended keeps looking so while it waits; once its account is in use, today's rows say the rest", () => {+ const rows = accountRows([{ id: "x", name: "Old", color: "red", kind: "cloud", opens: true, ended: true, removable: true, cloudId: "c1", attention: true, progress: 0.2, paint: {} }]);+ assert.deepEqual(rows, [{ id: "x", name: "Old", color: "red", kind: "cloud", opens: true, ended: true }], "no Remove here: it needs the account in use, which a click makes it");+});++test("11. hand-connected servers stay outside any account's group, after them, and aren't kept with an account", () => {+ const rows = railPlaces({ saved: list([myCloud("https://a.test", "a1"), byHand("https://hand.test", "Hand")]), mine: "https://a.test", state: signedIn(A), waiting: [waits(B, [myCloud("https://b.test", "b1")])] });+ assert.deepEqual(ids(rows), [LOCAL_ID, "a1", "b1", "https://hand.test"]);+ assert.equal(rows[3].group, "hand");+ assert.equal(rows[3].email, undefined);+ assert.equal(rows[3].account, undefined);+ assert.deepEqual(accountRows(rows), [{ id: "a1", name: "My Cloud", color: null, kind: "cloud", opens: true }], "this computer, a hand-saved server and another account's rows aren't this account's");+});++test("12. a place that waits carries no live state: nothing on the rail can say it is lent or busy", () => {+ const rows = railPlaces({ saved: list([]), state: signedIn(A), waiting: [waits(B, [myCloud("https://b.test", "b1")], accountRows([{ id: "b1", name: "My Cloud", color: null, kind: "cloud", opens: true, active: true, progress: 0.4, attention: true, update: {}, offline: true, server: true }]))] });+ assert.deepEqual(Object.keys(rows[1]).sort(), ["account", "color", "email", "group", "id", "kind", "name", "opens"]);+});++test("14. a moved computer whose home is a Cloud of the account that waits: its row is there, and This computer is the clean workspace's", () => {+ const rows = railPlaces({ saved: list([]), home: null, state: signedIn(B), waiting: [waits(A, [myCloud("https://a.test", "a1")])] });+ assert.deepEqual(ids(rows), [LOCAL_ID, "a1"]);+ assert.equal(rows[1].account, A);+ const home = railPlaces({ saved: list([myCloud("https://a.test", "a1")]), home: "https://a.test", mine: "https://a.test", state: signedIn(A), waiting: [waits(B, [myCloud("https://b.test", "b1")])] });+ assert.deepEqual(ids(home), ["a1", "b1"], "home on the account in use: as today, no This computer, and the other account's Clouds beside it");+});++test("an account whose sign-in ended keeps its rows, and says so", () => {+ const rows = withAccounts([], { saved: list([]), waiting: [{ ...waits(B, [myCloud("https://b.test", "b1")]), signIn: true }] });+ assert.equal(rows[0].signIn, true);+ assert.equal(rows[0].opens, true);+});++function railWith({ rows, switched = async () => ({ outcome: "switched" }), after = rows }) {+ const handlers = new Map(), opened = [], asked = [];+ let current = rows;+ installCloudRail({ ipcMain: { handle: (channel, handler) => handlers.set(channel, handler) }, guard: (handler) => handler, trusted: () => true, lists: (event) => event.rail === true, places: () => current, open: async (id) => opened.push(id),+ add: { choices: () => ({ cloud: false, link: false, address: false }), run() {} }, account: () => null, clipboard: {}, openCloud: async (id) => opened.push(`cloud:${id}`), targets: () => [],+ switchAccount: async (id) => { asked.push(id); const said = await switched(id); if (said.outcome === "switched") current = after; return said; } });+ return { call: (channel, ...args) => handlers.get(channel)({ rail: true }, ...args), page: (channel, ...args) => handlers.get(channel)({ rail: false }, ...args), opened, asked };+}+const mineRow = { id: "a1", name: "My Cloud", kind: "cloud", opens: true, group: "active", email: A };+const theirRow = { id: "b1", name: "My Cloud", kind: "cloud", opens: true, group: B, email: B, account: B };+const theirsActive = { id: "b1", name: "My Cloud", kind: "cloud", opens: true, group: "active", email: B };++test("a click on the account in use's place opens it, with no switch", async () => {+ const f = railWith({ rows: [mineRow, theirRow] });+ await f.call("workspaces:open", "a1");+ assert.deepEqual([f.asked, f.opened], [[], ["a1"]]);+});++test("a click on another account's place switches first, then opens it as that account's own", async () => {+ const f = railWith({ rows: [mineRow, theirRow], after: [theirsActive, { ...mineRow, account: A }] });+ assert.deepEqual(await f.call("workspaces:open", "b1"), { outcome: "switched" });+ assert.deepEqual([f.asked, f.opened], [[B], ["b1"]]);+});++test("a click during a move is refused with the plain outcome, and nothing moves", async () => {+ const f = railWith({ rows: [mineRow, theirRow], switched: async () => ({ outcome: "moving" }) });+ assert.deepEqual(await f.call("workspaces:open", "b1"), { outcome: "moving" });+ assert.deepEqual(f.opened, []);+});++test("a saved sign-in past its time: the click asks for the code for that address, and nothing moves", async () => {+ const f = railWith({ rows: [mineRow, { ...theirRow, signIn: true }], switched: async () => ({ outcome: "sign-in", email: B }) });+ assert.deepEqual(await f.call("workspaces:open", "b1"), { outcome: "sign-in", email: B });+ assert.deepEqual(f.opened, []);+});++test("a click on an account with no place of its own switches, and the window goes where that account belongs", async () => {+ const id = `${ACCOUNT_PLACE}${C}`;+ const f = railWith({ rows: [mineRow, { id, name: C, kind: "account", opens: true, group: C, email: C, account: C }], after: [{ ...mineRow, account: A }] });+ assert.deepEqual(await f.call("workspaces:open", id), { outcome: "switched" });+ assert.deepEqual([f.asked, f.opened], [[C], []]);+});++test("no page but the rail's reads the rows, and the rail's never hears which account main switches to", async () => {+ const f = railWith({ rows: [mineRow, theirRow] });+ const seen = await f.call("workspaces:places");+ assert.equal(JSON.stringify(seen.places).includes('"account"'), false);+ assert.deepEqual((await f.page("workspaces:places")).places, []);+ assert.throws(() => f.page("workspaces:open", "b1"), /only available/);+});++++test("the groups keep their order whichever account is in use, so a click doesn't move the row under the pointer", () => {++ const a = [myCloud("https://a.test", "a1")], b = [myCloud("https://b.test", "b1")];++ const asAlice = railPlaces({ saved: list(a), mine: "https://a.test", state: signedIn(A), waiting: [waits(B, b)] });++ const asBob = railPlaces({ saved: list(b), mine: "https://b.test", state: signedIn(B), waiting: [waits(A, a)] });++ assert.deepEqual(ids(asAlice), ids(asBob));++ assert.deepEqual(ids(asAlice), [LOCAL_ID, "a1", "b1"], "alice before bob");++});diff --cc src/components/AccountMenu.test.tsindex 9e344007c5,27de9c3164..ec19b5b538--- a/src/components/AccountMenu.test.ts+++ b/src/components/AccountMenu.test.ts@@@ -1,36 -1,19 +1,36 @@@import { afterEach, expect, it, vi } from "vitest";- import { accountMenuItems, switchNote } from "./AccountMenu";-import { accountMenuItems, cloudRowLabel } from "./AccountMenu";++import { accountMenuItems, cloudRowLabel, switchNote } from "./AccountMenu";-afterEach(() => vi.unstubAllGlobals());-const signOut = vi.fn();+afterEach(() => vi.clearAllMocks());+const actions = { signOut: vi.fn(), add: vi.fn() };+const a = { id: "a", email: "[email protected]" };-it("one account: its address, then Sign out", () => {- const items = accountMenuItems({ view: { active: { id: "a", email: "[email protected]" }, others: [] }, openSheet: null, signOut });+it("the You menu: just the address and Sign out, with no list of accounts", () => {+ const items = accountMenuItems({ view: { active: a }, openSheet: null, noRail: false, ...actions });expect(items.map((item) => item.label)).toEqual(["[email protected]", "Sign out"]);+ expect(items[0].disabled).toBe(true);items[1].onSelect();- expect(signOut).toHaveBeenCalledWith("a");+ expect(actions.signOut).toHaveBeenCalledWith("a");});-it("signed out, or a page that isn't offered the sheet: no rows", () => {- expect(accountMenuItems({ view: { active: null, others: [] }, openSheet: null, signOut })).toEqual([]);- expect(accountMenuItems({ view: null, openSheet: null, signOut })).toEqual([]);+it("with no rail beside the page, its + can't be reached, so Add another account stays here", () => {+ const items = accountMenuItems({ view: { active: a }, openSheet: null, noRail: true, ...actions });+ expect(items.map((item) => item.label)).toEqual(["[email protected]", "Add another account", "Sign out"]);+ items[1].onSelect();+ expect(actions.add).toHaveBeenCalledWith();+});++it("an account whose sign-in ended says so, and its tap goes to the sign-in", () => {+ const items = accountMenuItems({ view: { active: { ...a, signIn: true as const } }, openSheet: null, noRail: false, ...actions });+ expect(items[0].subtitle).toBe("Sign in again");+ expect(items[0].disabled).toBe(false);+ items[0].onSelect();+ expect(actions.add).toHaveBeenCalledWith("[email protected]");+});++it("no rows on a page that isn't offered the sheet, or while nobody is signed in here", () => {+ expect(accountMenuItems({ view: { active: null }, openSheet: null, noRail: true, ...actions })).toEqual([]);+ expect(accountMenuItems({ view: null, openSheet: null, noRail: true, ...actions })).toEqual([]);});it("another place's page shows no address, only the row that asks main for the sheet", () => {@@@ -42,10 -25,9 +42,17 @@@expect(openSheet).toHaveBeenCalled();});+it("what a click or sign-out that didn't go through says, in plain words", () => {+ expect(switchNote({ outcome: "moving" })).toContain("moving to the Cloud");+ expect(switchNote({ outcome: "gone" })).toContain("isn't signed in here");+ expect(switchNote({ outcome: "failed" })).toContain("Try again");+ expect(switchNote({ outcome: "switched" })).toBeNull();+ expect(switchNote({ outcome: "signed-out" })).toBeNull();+});+++ it("the MausBot Cloud row says Sign in only while the clean workspace's line asks for it", () => {- expect(cloudRowLabel({ active: null, others: [], clean: true })).toBe("Sign in");- expect(cloudRowLabel({ active: null, others: [] })).toBe("MausBot Cloud");- expect(cloudRowLabel({ active: { id: "b", email: "[email protected]" }, others: [], clean: true })).toBe("MausBot Cloud");++ expect(cloudRowLabel({ active: null, clean: true })).toBe("Sign in");++ expect(cloudRowLabel({ active: null })).toBe("MausBot Cloud");++ expect(cloudRowLabel({ active: { id: "b", email: "[email protected]" }, clean: true })).toBe("MausBot Cloud");+ expect(cloudRowLabel(null)).toBe("MausBot Cloud");+ });diff --cc src/components/AccountMenu.tsxindex d35c96b5d4,1d471b7f29..f22bb08f08--- a/src/components/AccountMenu.tsx+++ b/src/components/AccountMenu.tsx@@@ -62,10 -40,14 +62,16 @@@ export function useAccounts(): Accounts};}+ /** The You menu's row for the MausBot Cloud page: with the clean workspace open and nobody signed in, the line there asks the person+ * to sign in, and this row is how. */+ export function cloudRowLabel(view: AccountsView | null): string {+ return t(view?.clean && !view.active ? "accounts.signIn" : "settings.section.cloudAccount");+ }+-/** The You menu's last rows. On another page, one row that opens the sheet. Signed out: nothing, as Settings has the sign-in. */-export function accountMenuItems({ view, openSheet, signOut }: AccountsAccess): SidebarMenuItem[] {+/** The You menu's last rows: who is signed in here and Sign out. The other accounts are on the rail, and so is Add another account,+ * in its +; with no rail beside this page (nothing to list but This computer, or the person hid it) it is here. On another page,+ * one row that opens the sheet, with no address. Signed out: nothing, as Settings has the sign-in. */+export function accountMenuItems({ view, openSheet, noRail, signOut, add }: AccountsAccess): SidebarMenuItem[] {if (openSheet) return [{ key: "accounts-sheet", label: t("accounts.manage"), icon: <UserRound size={18} />, onSelect: openSheet }];const active = view?.active;if (!active) return [];diff --cc src/components/SidebarProfileMenu.tsxindex 19c0a80a84,2289034b70..0062caedf4--- a/src/components/SidebarProfileMenu.tsx+++ b/src/components/SidebarProfileMenu.tsx@@@ -23,7 -23,7 +23,7 @@@ importZap,} from "lucide-react";- import { accountMenuItems, AccountsSheet, useAccounts } from "./AccountMenu";-import { accountMenuItems, cloudRowLabel, useAccounts } from "./AccountMenu";++import { accountMenuItems, AccountsSheet, cloudRowLabel, useAccounts } from "./AccountMenu";import { AccountMoveStatus, useAccountMove, type AccountMoveKind } from "./AccountMove";import { InitialsAvatar } from "./Avatar";import { DiscordIcon } from "./DiscordIcon";