Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
One list: keep the rail and the place pill; the one list is this computer's page only
milind-soni838c28136649
diff --git a/electron/cloud-rail.mjs b/electron/cloud-rail.mjsindex 9f444154cc..0fc67107c5 100644--- a/electron/cloud-rail.mjs+++ b/electron/cloud-rail.mjs@@ -68,17 +68,16 @@ const unlisted = (entry, { clouds, home, mine }) => Array.isArray(clouds) && (en* device, each with its places as they were kept: grouped by account after these (withAccounts). `profiles`: the workspaces* of this computer's own it may open (local-profiles.mjs; `active`: the one on screen, `settling`: it opens once that bot* finishes): first once My Cloud is home, as This computer was, else right after This computer. `computerSettling`: This- * computer opens once that bot finishes. `joined`: "This computer and My Cloud together" is on (places-together.mjs): when- * This computer and My Cloud are then the only places, one list in the sidebar holds both and there is no rail.- * @param {{ saved: { environments: any[], activeId: string }, home?: string | null, mine?: string | null, state?: any, offers?: (entry: any) => boolean, waiting?: (id: string) => boolean, accounts?: any[], profiles?: Array<{ id: string, name?: string | null, color?: string | null, swatch?: string | null, active?: boolean, settling?: string }>, computerSettling?: string | null, joined?: boolean }} input+ * computer opens once that bot finishes.+ * @param {{ saved: { environments: any[], activeId: string }, home?: string | null, mine?: string | null, state?: any, offers?: (entry: any) => boolean, waiting?: (id: string) => boolean, accounts?: any[], profiles?: Array<{ id: string, name?: string | null, color?: string | null, swatch?: string | null, active?: boolean, settling?: string }>, computerSettling?: string | null }} input*/-export function railPlaces({ saved, home = null, mine = null, state = null, offers = () => false, waiting = () => false, accounts = [], profiles = [], computerSettling = null, joined = false }) {+export function railPlaces({ saved, home = null, mine = null, state = null, offers = () => false, waiting = () => false, accounts = [], profiles = [], computerSettling = null }) {const connected = state?.status === "connected" ? state : null;const clouds = Array.isArray(connected?.clouds) ? connected.clouds : [];const order = entry => { const at = clouds.findIndex(cloud => cloud.origin === entry.origin); return at === -1 ? clouds.length : at; };const rank = entry => (entry.origin === mine || entry.home ? 0 : environments.listedPlace(entry) ? 1 : 2);- const shownRemote = saved.environments.filter(entry => entry.kind !== "local" && entry.origin && !(connected && unlisted(entry, { clouds: connected.clouds, home, mine })));- const remote = shownRemote.map((entry, index) => ({ entry, index }))+ const remote = saved.environments.filter(entry => entry.kind !== "local" && entry.origin && !(connected && unlisted(entry, { clouds: connected.clouds, home, mine })))+ .map((entry, index) => ({ entry, index })).sort((a, b) => rank(a.entry) - rank(b.entry) || order(a.entry) - order(b.entry) || a.index - b.index).map(({ entry }) => circle(entry, { activeId: saved.activeId, mine, state: connected, offers, waiting }));const making = otherOwnClouds(clouds).filter(cloud => !cloud.origin && ["checkout", "setting_up"].includes(cloud.status))@@ -98,7 +97,6 @@ export function railPlaces({ saved, home = null, mine = null, state = null, offe...(saved.activeId === environments.LOCAL_ID && !profileShown ? { active: true } : {}), ...(waiting(computer.id) ? { attention: true } : {}),...(typeof computerSettling === "string" ? { settling: computerSettling } : {}) }, ...own, ...places];if (accounts.length) return withAccounts(all, { saved, accounts, email: state?.account?.email ?? null });- if (joined && !home && !own.length && !servers.length && !making.length && shownRemote.length === 1 && shownRemote[0].origin === mine) return [];return all.length < (clouds.some(ownCloud) ? 1 : RAIL_MIN_PLACES) ? [] : all;}diff --git a/electron/cloud-rail.node-test.mjs b/electron/cloud-rail.node-test.mjsindex 2c871c9677..aef0a3730a 100644--- a/electron/cloud-rail.node-test.mjs+++ b/electron/cloud-rail.node-test.mjs@@ -43,22 +43,6 @@ test("the rail: My Cloud, the person's Clouds and teams' Clouds in the session's"once My Cloud is home, this computer is no circle, whatever its colour");});-test("one list for this computer and My Cloud: no rail while they are the only places; any other place keeps it", () => {- const pair = { activeId: "local", environments: [{ id: "home", kind: "remote", name: "My Cloud", origin: HOME, home: true }] };- const mine = session({ teams: [], clouds: parseCloudList([PRIMARY]) });- assert.deepEqual(railPlaces({ saved: pair, home: null, mine: HOME, state: mine }).map(place => place.id), ["local", "home"], "the switch off: the rail as it was");- assert.deepEqual(railPlaces({ saved: pair, home: null, mine: HOME, state: mine, joined: true }), [], "on, and only the pair: the one list is the way between them");- assert.deepEqual(railPlaces({ saved: pair, home: null, mine: HOME, state: null, joined: true }), [], "the same before the Admin answers");- const keeps = (label, input) => assert.ok(railPlaces({ saved: pair, home: null, mine: HOME, state: mine, joined: true, ...input }).length > 1, label);- keeps("a team's Cloud", { saved: { ...pair, environments: [...pair.environments, { id: "acme", kind: "remote", name: "Acme", origin: TEAM, team: { id: "team-acme", role: "member" } }] } });- keeps("a server saved by hand", { saved: { ...pair, environments: [...pair.environments, { id: "vps", kind: "remote", name: "Office", origin: VPS }] } });- keeps("another Cloud of the person's own", { saved: { ...pair, environments: [...pair.environments, { id: "a", kind: "remote", name: "Client A", origin: CLIENT_A, cloud: { id: "c-a", role: "owner" } }] } });- keeps("a workspace of this computer's own", { profiles: [{ id: "p1", name: "Side project" }] });- keeps("a Cloud still being made", { state: session({ teams: [], clouds: parseCloudList([PRIMARY, entry({ id: "c-new", name: "New", origin: null, status: "setting_up" })]) }) });- assert.ok(railPlaces({ saved: pair, home: null, mine: HOME, state: mine, joined: true, accounts: [{ id: "acct-2", email: "[email protected]", places: [], rows: [] }] }).length > 0, "another account signed in here");- assert.deepEqual(railPlaces({ saved: pair, home: HOME, mine: HOME, state: mine, joined: true }).map(place => place.id), ["home"], "after a whole move there is no pair to join");-});-test("a Cloud of your own is a rail even alone, for its +; otherwise one place, or none: no rail, the window as it was", () => {const alone = { activeId: "home", environments: [{ id: "home", kind: "remote", name: "My Cloud", origin: HOME, home: true }] };assert.deepEqual(railPlaces({ saved: alone, home: HOME, mine: HOME, state: session({ teams: [], clouds: parseCloudList([PRIMARY]) }) }).map(place => place.id), ["home"],diff --git a/electron/main.mjs b/electron/main.mjsindex 0067eb75aa..0bb7eec038 100644--- a/electron/main.mjs+++ b/electron/main.mjs@@ -2596,8 +2596,8 @@ function showHome(options) {return homeWindow.show(options).catch(error => slog(`home: ${error?.message ?? error}`));}const showStartPlace = () => openStartPlace({ home: homeWindow, places: homePlaces, profiles: localProfiles, log: slog, server: id => { const entry = environmentsState.environments.find(candidate => candidate.id === id && handSaved(candidate)); return entry ? reopenSavedServer(entry, { saved: () => environmentsState.environments.filter(handSaved), fetch: (...args) => session.defaultSession.fetch(...args), opened: async (found) => { if (!mainWindow || mainWindow.isDestroyed()) createWindow({ deferNavigation: true }); persistEnvironments(withActive(environmentsState, found.id)); return navigateMainWindow(activeOrigin()); } }) : Promise.resolve(false); } }).catch(error => slog(`start: ${error?.message ?? error}`)); const openOwnCloud = id => { homeWindow.cancel(); return showHome({ place: { cloud: id, name: environmentsState.environments.find(entry => entry.cloud?.id === id)?.name } }); };-const placeInbox = createPlaceInboxWatch({ places: () => [{ id: LOCAL_ID, local: true }, ...environmentsState.environments.filter(entry => entry.kind !== "local" && entry.origin)], activeId: () => environmentsState.activeId, local: localServerRequest, cloudFetch: (...args) => session.defaultSession.fetch(...args), asleep: origin => homeWindow.asleepAt(origin), shown: () => !desktopRemoteAccess && serverReady && Boolean(mainWindow && !mainWindow.isDestroyed() && mainWindow.isVisible()), changed: () => railChanged() }); const homeOfUrl = url => { let at = null; try { at = new URL(url); } catch { return "other"; } return at.origin === rendererOrigin() ? (at.pathname === HOME_SCREEN_PATH ? "waking" : "computer") : at.origin === myCloud() ? "cloud" : "other"; }; const placeShown = () => { const page = mainWindow && !mainWindow.isDestroyed() ? mainWindow.webContents : null; return page && !page.isLoadingMainFrame() ? homeOfUrl(page.getURL()) ?? "other" : null; }; const shownHome = () => { const place = placeShown(); return place === "computer" || place === "cloud" ? place : null; }; const placesTogether = installPlacesTogether({ ipcMain, asking: cloudPageAsking, together: createPlacesTogether({ pref: jsonFile(path.join(app.getPath("userData"), PLACES_TOGETHER_FILE)), onlyPair: () => railList().length === 0, switched: () => railChanged(), cloud: () => ({ origin: myCloud(), account: cloudAccount?.state().account?.id ?? null, asleep: cloudPower.asleep() }), powerChecked: async () => { const account = cloudAccount; if (!account) return false; await account.refresh(); return Date.now() - (account.state().verifiedAt ?? 0) < 5_000; }, computer: () => !(homeWindow.cloudOrigin() ?? ownHome?.origin()), local: localServerRequest, cloudFetch: (...args) => session.defaultSession.fetch(...args), napped: () => cloudPower.hold(), address: (home, botId) => botLink?.address(home, botId) ?? null, shown: placeShown, focused: () => powerMonitor.getSystemIdleState(60) !== "locked" && Boolean(mainWindow && !mainWindow.isDestroyed() && mainWindow.isFocused()), openPlace: home => { const entry = home === "cloud" ? environmentsState.environments.find(candidate => candidate.origin === myCloud()) : null; return home === "cloud" && (!entry || myCloud() === homeWindow.cloudOrigin()) ? showHome({ place: "cloud" }) : workspaceMenuAction(() => switchEnvironment(entry?.id ?? LOCAL_ID)); }, send: (channel, value) => { if (shownHome()) mainWindow.webContents.send(channel, value); }, changed: () => { botLink?.look(); if (shownHome()) mainWindow.webContents.send("places-together:changed"); } }) });-const localProfiles = createLocalProfiles({ registry: createProfileRegistry({ dataDir: desktopDataDir }), clean: cleanWorkspace, dataDir: desktopDataDir, allowed: () => app.isPackaged && !desktopRemoteAccess, home: () => (homeWindow.cloudOrigin() ? "cloud" : ownHome?.origin() || cleanWorkspace.marker().frozen ? null : "local"), window: { openProfile: id => homeWindow.openProfile(id), profile: () => homeWindow.profile(), showCloud: () => showHome({ place: "cloud" }) }, showLocal: () => { homeWindow.cancel(); persistEnvironments(withActive(environmentsState, LOCAL_ID)); return navigateMainWindow(rendererOrigin()); }, onLocal: () => Boolean(mainWindow && !mainWindow.isDestroyed() && senderIsLocal({ sender: mainWindow.webContents })), busy: async () => { const said = await (await localServerRequest("/api/move/freeze", { signal: AbortSignal.timeout(5_000) })).json(); return typeof said?.busy === "string" ? { name: said.busy, what: said.what } : null; }, trash: dir => shell.trashItem(dir), reserved: () => nativeT(process.platform === "darwin" ? "rail.thisMac" : "rail.thisPc"), remember: homePlaces.remember, changed: () => railChanged(), log: slog }); const railList = () => { ownHome?.refresh(); const settling = localProfiles.settling(); return railPlaces({ saved: environmentsState, waiting: placeInbox.waiting, home: homeWindow.cloudOrigin() ?? ownHome?.origin() ?? null, mine: myCloud(), state: desktopRemoteAccess ? null : cloudAccount?.state(), offers: entry => !desktopRemoteAccess && ownHome?.offers(entry) === true, accounts: accountRing.waiting(), profiles: localProfiles.places({ activeLocal: environmentsState.activeId === LOCAL_ID }), computerSettling: settling && settling.id === null ? settling.name : null, joined: placesTogether.on() }); };+const placeInbox = createPlaceInboxWatch({ places: () => [{ id: LOCAL_ID, local: true }, ...environmentsState.environments.filter(entry => entry.kind !== "local" && entry.origin)], activeId: () => environmentsState.activeId, local: localServerRequest, cloudFetch: (...args) => session.defaultSession.fetch(...args), asleep: origin => homeWindow.asleepAt(origin), shown: () => !desktopRemoteAccess && serverReady && Boolean(mainWindow && !mainWindow.isDestroyed() && mainWindow.isVisible()), changed: () => railChanged() }); const homeOfUrl = url => { let at = null; try { at = new URL(url); } catch { return "other"; } return at.origin === rendererOrigin() ? (at.pathname === HOME_SCREEN_PATH ? "waking" : "computer") : at.origin === myCloud() ? "cloud" : "other"; }; const placeShown = () => { const page = mainWindow && !mainWindow.isDestroyed() ? mainWindow.webContents : null; return page && !page.isLoadingMainFrame() ? homeOfUrl(page.getURL()) ?? "other" : null; }; const shownHome = () => { const place = placeShown(); return place === "computer" || place === "cloud" ? place : null; }; const placesTogether = installPlacesTogether({ ipcMain, asking: cloudPageAsking, together: createPlacesTogether({ pref: jsonFile(path.join(app.getPath("userData"), PLACES_TOGETHER_FILE)), cloud: () => ({ origin: myCloud(), account: cloudAccount?.state().account?.id ?? null, asleep: cloudPower.asleep() }), powerChecked: async () => { const account = cloudAccount; if (!account) return false; await account.refresh(); return Date.now() - (account.state().verifiedAt ?? 0) < 5_000; }, computer: () => !(homeWindow.cloudOrigin() ?? ownHome?.origin()), local: localServerRequest, cloudFetch: (...args) => session.defaultSession.fetch(...args), napped: () => cloudPower.hold(), address: (home, botId) => botLink?.address(home, botId) ?? null, shown: placeShown, focused: () => powerMonitor.getSystemIdleState(60) !== "locked" && Boolean(mainWindow && !mainWindow.isDestroyed() && mainWindow.isFocused()), openPlace: home => { const entry = home === "cloud" ? environmentsState.environments.find(candidate => candidate.origin === myCloud()) : null; return home === "cloud" && (!entry || myCloud() === homeWindow.cloudOrigin()) ? showHome({ place: "cloud" }) : workspaceMenuAction(() => switchEnvironment(entry?.id ?? LOCAL_ID)); }, send: (channel, value) => { if (shownHome()) mainWindow.webContents.send(channel, value); }, changed: () => { botLink?.look(); if (shownHome()) mainWindow.webContents.send("places-together:changed"); } }) });+const localProfiles = createLocalProfiles({ registry: createProfileRegistry({ dataDir: desktopDataDir }), clean: cleanWorkspace, dataDir: desktopDataDir, allowed: () => app.isPackaged && !desktopRemoteAccess, home: () => (homeWindow.cloudOrigin() ? "cloud" : ownHome?.origin() || cleanWorkspace.marker().frozen ? null : "local"), window: { openProfile: id => homeWindow.openProfile(id), profile: () => homeWindow.profile(), showCloud: () => showHome({ place: "cloud" }) }, showLocal: () => { homeWindow.cancel(); persistEnvironments(withActive(environmentsState, LOCAL_ID)); return navigateMainWindow(rendererOrigin()); }, onLocal: () => Boolean(mainWindow && !mainWindow.isDestroyed() && senderIsLocal({ sender: mainWindow.webContents })), busy: async () => { const said = await (await localServerRequest("/api/move/freeze", { signal: AbortSignal.timeout(5_000) })).json(); return typeof said?.busy === "string" ? { name: said.busy, what: said.what } : null; }, trash: dir => shell.trashItem(dir), reserved: () => nativeT(process.platform === "darwin" ? "rail.thisMac" : "rail.thisPc"), remember: homePlaces.remember, changed: () => railChanged(), log: slog }); const railList = () => { ownHome?.refresh(); const settling = localProfiles.settling(); return railPlaces({ saved: environmentsState, waiting: placeInbox.waiting, home: homeWindow.cloudOrigin() ?? ownHome?.origin() ?? null, mine: myCloud(), state: desktopRemoteAccess ? null : cloudAccount?.state(), offers: entry => !desktopRemoteAccess && ownHome?.offers(entry) === true, accounts: accountRing.waiting(), profiles: localProfiles.places({ activeLocal: environmentsState.activeId === LOCAL_ID }), computerSettling: settling && settling.id === null ? settling.name : null }); };// The rail as the window's own chrome (chrome-rail.mjs): this app's page beside every place's page, the one that lists.const placeSwitch = createPlaceSwitch({ changed: () => railChanged(), stop: () => homeWindow.stopOpening(), kept: () => homePlaces.remembered(), pageSettled: () => { const page = mainWindow && !mainWindow.isDestroyed() ? mainWindow.webContents : null; if (page?.isLoadingMainFrame()) return new Promise(done => { page.once("did-stop-loading", done); page.once("destroyed", done); }); } }); const openPlace = (id, stale) => workspaceMenuAction(async () => { if (id === LOCAL_ID) await cleanWorkspace.settled(); if (!stale()) await switchEnvironment(id, stale); }); const chromeRail = createChromeRail({ createView: options => new WebContentsView(options), preload: path.join(__dirname, "preload.cjs"), log: slog, prefs: () => desktopPrefs, changed: () => rail.changed(), openComputer: (page) => openComputerSettings({ window: () => mainWindow, onLocal: (win) => senderIsLocal({ sender: win.webContents }), showLocal: () => placeSwitch.ask(LOCAL_ID, stale => { localProfiles.cancel(); return openPlace(LOCAL_ID, stale); }) }, page),args: () => [...desktopCompanionRendererArguments(rendererOrigin(), desktopRemoteAccess), ...(app.isPackaged && !desktopRemoteAccess ? ["--omb-company-desktop=1"] : []), `--omb-app-version=${app.getVersion()}`],diff --git a/electron/places-together.d.mts b/electron/places-together.d.mtsindex 5d473173a9..d287cc3114 100644--- a/electron/places-together.d.mts+++ b/electron/places-together.d.mts@@ -38,10 +38,6 @@ export interface PlacesTogetherState {/** The other place's bots while the switch is on. `state`: how that place is doing: asleep, waking and offline keep the* bots it gave last; "signin" is a My Cloud this window has not signed in to yet, which lists none. */other: { home: BotHome; state: "ready" | "loading" | "asleep" | "waking" | "offline" | "signin"; bots: PlaceBotRow[]; newBot?: boolean } | null;- /** On, and this computer and My Cloud are the person's only places: the one list stands for both, so neither the rail- * of places nor the page's place pill is drawn. Absent while there is a Team Cloud, a server saved by hand, a- * workspace of this computer's own, another account or a Cloud still being made: those keep the rail and the pill. */- onlyPair?: true;}/** `window.ogb.placesTogether`: this computer's page and My Cloud's own page. */diff --git a/electron/places-together.mjs b/electron/places-together.mjsindex 4be63bc839..eee26100b3 100644--- a/electron/places-together.mjs+++ b/electron/places-together.mjs@@ -113,8 +113,6 @@ const needsSignIn = (response) => response?.status === 401 || response?.status =/*** @param {{* pref: { read(): unknown, write(value: unknown): void },- * onlyPair?(): boolean,- * switched?(): void,* cloud(): { origin: string | null, account: string | null, asleep: boolean },* powerChecked(): Promise<boolean>,* computer(): boolean,@@ -141,16 +139,13 @@ const needsSignIn = (response) => response?.status === 401 || response?.status =* own switch to that place, waking My Cloud as opening it always does. `send`: to the page on screen. `changed()`: the* list or the switch changed, so a page that draws it asks again. `address(home, botId)`: the address the link between* the two places gives that bot (electron/bot-link-main.mjs), or null while no link of this Cloud and account is on.- * `onlyPair()`: this computer and My Cloud are the person's only places, so with the switch on the one list stands for- * both and the rail of places is not drawn (cloud-rail.mjs `railPlaces` `joined`); the page hides its place pill too.- * `switched()`: the switch was turned, so the rail is drawn again.** Security: My Cloud is never asked while it sleeps, since any request would wake it and run up its hours. It is asked* only right after the Admin said it is awake, at most once a minute, and only while the person is using the window. What* remains is a Cloud that fell asleep in the seconds since the Admin answered; one that only agreed to sleep answers so* itself and is left alone. Rows are kept for the Cloud and account they came from, and dropped the moment either changes.*/-export function createPlacesTogether({ pref, onlyPair = () => false, switched = () => {}, cloud, powerChecked, computer, local, cloudFetch, napped = () => {}, address = () => null, shown, focused, openPlace, send, changed, now = Date.now,+export function createPlacesTogether({ pref, cloud, powerChecked, computer, local, cloudFetch, napped = () => {}, address = () => null, shown, focused, openPlace, send, changed, now = Date.now,setTimer = setInterval, clearTimer = clearInterval, later = setTimeout, cancelLater = clearTimeout }) {/** What each place gave last: its rows, when, and how the last read went. */const kept = new Map();@@ -325,16 +320,13 @@ export function createPlacesTogether({ pref, onlyPair = () => false, switched =if (!active()) return { v: 1, available: available(), on: isOn(), here, other: null };watch();void refresh(otherHome(here));- let pair = false;- try { pair = onlyPair() === true; } catch {}- return { v: 1, available: true, on: true, here, other: otherOf(here), ...(pair ? { onlyPair: true } : {}) };+ return { v: 1, available: true, on: true, here, other: otherOf(here) };},/** The switch. Off forgets every list. */set(asking, value) {on = value === true;pref.write({ v: 1, on });sameScope();- try { switched(); } catch {}tell();return this.state(asking);},diff --git a/electron/places-together.node-test.mjs b/electron/places-together.node-test.mjsindex 0f965e0b9a..afeb4891d3 100644--- a/electron/places-together.node-test.mjs+++ b/electron/places-together.node-test.mjs@@ -441,24 +441,6 @@ test("a row carries when its conversations last moved there: their own times, neassert.equal("lastAt" in botRow(bot("odd", "Odd", { tasks: [{ threadId: "t1", updatedAt: -5 }] }), "cloud"), false);});-test("with the switch on and this computer and My Cloud the only places, the page is told the one list stands for both; off, never", async () => {- let pair = true, switched = 0;- const f = setup({ deps: { onlyPair: () => pair, switched: () => { switched += 1; } } });- assert.equal(f.together.state("computer").onlyPair, true);- assert.equal(f.together.state("cloud").onlyPair, true);- pair = false;- assert.equal("onlyPair" in f.together.state("computer"), false);- pair = true;- f.together.set("computer", false);- assert.equal(switched, 1, "turning the switch draws the rail again");- assert.equal("onlyPair" in f.together.state("computer"), false);- f.together.set("computer", true);- assert.equal(switched, 2);- const broken = setup({ deps: { onlyPair: () => { throw new Error("no rail"); }, switched: () => { throw new Error("no rail"); } } });- assert.equal("onlyPair" in broken.together.state("computer"), false);- assert.doesNotThrow(() => broken.together.set("computer", false));-});-test("only this computer's page and My Cloud's own page are answered", async () => {const handlers = new Map();const f = setup();diff --git a/src/components/DesktopWorkspaceSwitcher.tsx b/src/components/DesktopWorkspaceSwitcher.tsxindex f9c6ace115..1415b91571 100644--- a/src/components/DesktopWorkspaceSwitcher.tsx+++ b/src/components/DesktopWorkspaceSwitcher.tsx@@ -7,7 +7,6 @@ import type { CloudPlanSnapshot } from "../../electron/cloud-account.mjs";import { cloudColor } from "@/lib/cloud-look";import { t } from "@/lib/i18n";import { railShown, usePlaces, windowPlaceName } from "@/lib/places";-import { useOnlyPair } from "@/lib/place-rows";import { CloudTile } from "./cloud-buy/parts";import { SIMPLE_RAIL_BUTTON } from "./SidebarSimpleTop";@@ -88,8 +87,6 @@ type SwitcherProps = {* instead: the window's own rail at every width, one drawn on the page on a wide window. */export function DesktopWorkspaceSwitcher(props: SwitcherProps) {const places = usePlaces();- // The one list holds this computer's bots and My Cloud's, and they are the only places: there is nothing to switch.- if (useOnlyPair()) return null;const switcher = <Switcher {...props} />;return railShown(places) ? <div data-switcher-beside-rail className={places.beside ? "hidden" : "contents md:hidden"}>{switcher}</div> : switcher;}diff --git a/src/components/OtherPlaceBots.dom.test.ts b/src/components/OtherPlaceBots.dom.test.tsindex b5d73a57f2..356d358a77 100644--- a/src/components/OtherPlaceBots.dom.test.ts+++ b/src/components/OtherPlaceBots.dom.test.ts@@ -74,12 +74,19 @@ it("a sleeping Cloud with nothing kept says so as normal, and opening it wakes iexpect(q("[data-other-place-line]")!.className).not.toContain("danger");await act(async () => q("button[data-other-place-line]")!.click());expect(openMyCloud).toHaveBeenCalledTimes(1);- for (const [home, line] of [["cloud", "My Cloud can't be reached right now."], ["computer", "This computer's bots can't be read right now."]] as const) {- said = state({ here: home === "cloud" ? "computer" : "cloud", other: { home, state: "offline", bots: [] } });+ said = state({ other: { home: "cloud", state: "offline", bots: [] } });+ await act(async () => changed());+ expect(q("[data-other-place-line]")!.textContent).toBe("My Cloud can't be reached right now.");+ expect(q("[data-other-place-line]")!.tagName).toBe("P");+ expect(q("[data-other-place-line]")!.getAttribute("role")).toBe("status");+});++it("My Cloud's page lists its own bots only: no line about this computer there, whatever main says", async () => {+ for (const power of ["offline", "ready", "loading"] as const) {+ said = state({ here: "cloud", other: { home: "computer", state: power, bots: [] } });+ await render(createElement(OtherPlaceLine, { key: "line" }));await act(async () => changed());- expect(q("[data-other-place-line]")!.textContent).toBe(line);- expect(q("[data-other-place-line]")!.tagName).toBe("P");- expect(q("[data-other-place-line]")!.getAttribute("role")).toBe("status");+ expect(q("[data-other-place]")).toBeNull();}});diff --git a/src/components/OtherPlaceBots.tsx b/src/components/OtherPlaceBots.tsxindex da922fc02e..a73e33c485 100644--- a/src/components/OtherPlaceBots.tsx+++ b/src/components/OtherPlaceBots.tsx@@ -2,10 +2,11 @@// place's own (src/lib/place-rows.ts), so this says something only when that place has no rows to show: My Cloud not// signed in to yet, or a place that is asleep or can't be reached with nothing kept from before. One quiet line in the// list's secondary text, not a card or a banner; it opens My Cloud where there is something to do there. Nothing while-// the first read is under way, and nothing with the switch off.+// the first read is under way, nothing with the switch off, and nothing on My Cloud's page, which lists its own bots only.import { Cloud, CloudMoon, CloudOff, MonitorOff } from "lucide-react";import { cn } from "@/lib/cn";import { t } from "@/lib/i18n";+import { oneListOn } from "@/lib/place-rows";import { usePlacesTogetherPart, type PlacesTogetherState } from "@/lib/places-together";import type { LocaleKey } from "@/locales";@@ -20,7 +21,7 @@ const SAID: Record<Said, { icon: typeof Cloud; words: LocaleKey; opens?: true }>};function saidOf(state: PlacesTogetherState | null): Said | null {- const other = state?.on ? state.other : null;+ const other = oneListOn(state) ? state!.other : null;if (!other || other.bots.length) return null;const said = `${other.home}:${other.state}`;return said in SAID ? said as Said : null;diff --git a/src/components/Sidebar.one-list.dom.test.ts b/src/components/Sidebar.one-list.dom.test.tsindex c2d8f9b04d..b57ae00466 100644--- a/src/components/Sidebar.one-list.dom.test.ts+++ b/src/components/Sidebar.one-list.dom.test.ts@@ -225,6 +225,26 @@ describe("switch on: one list", () => {expect(q('[data-sidebar-bot-row="git"]')!.getAttribute("aria-label")).toContain("On this computer");});+ it("the rail's two circles: this computer's page has the one list; My Cloud's page lists My Cloud's bots only, as with the switch off", async () => {+ window.ogb = { placesTogether: page } as never;+ await render();+ expect(ids('[data-sidebar-section-id="builtin:bots"]')).toEqual(["git", "ledger", "cloud:scout"]);+ await act(async () => root.unmount());+ resetPlacesTogetherForTest(); resetPlaceRowsForTest();+ root = createRoot(host);+ const cloudBots = [bot("maus", { chiefOfStaff: true }), bot("scout"), bot("atlas")];+ const offline = await htmlWith(null, cloudBots);+ answer = async () => said({ here: "cloud", other: { home: "computer", state: "ready", bots: [row("git", { home: "computer", unread: true }), row("ledger", { home: "computer" })] } });+ const cloudPage = await htmlWith({ placesTogether: page }, cloudBots);+ answer = async () => said({ here: "cloud", other: { home: "computer", state: "offline", bots: [] } });+ const cloudPageOffline = await htmlWith({ placesTogether: page }, cloudBots);+ expect(cloudPage).toBe(offline);+ expect(cloudPageOffline).toBe(offline);+ expect(cloudPage).not.toContain("computer:");+ expect(cloudPage).not.toContain("data-bot-place");+ expect(cloudPage).not.toContain("data-other-place");+ });+it("a place that never answers leaves this place's list whole, and the first answer adds its rows without a wait", async () => {window.ogb = { placesTogether: page } as never;let release!: (value: PlacesTogetherState) => void;diff --git a/src/lib/place-rows.ts b/src/lib/place-rows.tsindex 5c6e74bc33..e420f2ce79 100644--- a/src/lib/place-rows.ts+++ b/src/lib/place-rows.ts@@ -4,6 +4,9 @@// (`cloud:scout`), so two bots with one id in two places never meet, and nothing that writes to this place's server is// ever handed one: what such a row sends is either "open it", which main does where the bot lives, or dropped.//+// The one list is this computer's page's: the page the rail's first circle opens. My Cloud's page, opened from its own+// circle, lists My Cloud's bots only, as it does with the switch off, so the rail still shows the Cloud on its own.+//// Everything here is keyed by a place, not by "My Cloud": today the places are this computer and My Cloud, and a// person's own always-on machine (a server of their own, or a computer at home) is meant to join the same list later// as one more place, with its own key, kind, name and state.@@ -87,10 +90,13 @@ const NONE: readonly PlacedBot[] = Object.freeze([]);let lastState: PlacesTogetherState | null | undefined;let lastList: readonly PlacedBot[] = NONE;+/** The one list is on for this page: the switch is on, main lists the other place, and this is this computer's page. */+export const oneListOn = (state: PlacesTogetherState | null): boolean => state?.on === true && state.other !== null && state.here === "computer";+function placedList(state: PlacesTogetherState | null): readonly PlacedBot[] {if (state === lastState) return lastList;lastState = state;- const other = state?.on ? state.other : null;+ const other = oneListOn(state) ? state!.other : null;const kept = new Map<string, { row: PlaceBotRow; health: PlaceHealth; bot: PlacedBot }>();const next = (other?.bots ?? []).map((row) => {const key = placeKeyed(placeOfHome(row.home), row.id), had = adapted.get(key);@@ -194,8 +200,9 @@ export function placeMark(place: Place, health: PlaceHealth, working: boolean, nreturn mark(device.icon, kind === "my-cloud" ? t("together.onCloud") : kind === "this-computer" ? t("together.onComputer") : t("together.mark.on", { place: place.label }), "hover");}-/** This page's place while the one list is on; null while it is off, in a browser, and on any other place's page. */-const hereOf = (state: PlacesTogetherState | null): BotHome | null => (state?.on && state.other ? state.here : null);+/** This page's place while the one list is on; null while it is off, in a browser, on My Cloud's page and on any other+ * place's page. */+const hereOf = (state: PlacesTogetherState | null): BotHome | null => (oneListOn(state) ? state!.here : null);/** The mark a row draws, given this page's place while the one list is on (`here`, from useOneListHere once for the* whole list); none with it off. A row of this place lives here, and here is awake. */@@ -215,11 +222,6 @@ export function useOneList(): boolean {return usePlacesTogetherPart(hereOf) !== null;}-/** On, and this computer and My Cloud are the person's only places: no place pill (main draws no rail either). */-export function useOnlyPair(): boolean {- return usePlacesTogetherPart((state) => state?.on === true && state.other !== null && state.onlyPair === true);-}-export function resetPlaceRowsForTest(): void {adapted = new Map();lastState = undefined;