Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
App settings: bots change settings in Simple mode without switching to Advanced
milind-soni9ec9245ac68f
diff --git a/server/app-settings/host.test.ts b/server/app-settings/host.test.tsindex 589ed2f910..867df38416 100644--- a/server/app-settings/host.test.ts+++ b/server/app-settings/host.test.ts@@ -135,7 +135,7 @@ describe("reads", () => {const none = await host.handle({ action: "find", query: "invoice" }, turn);expect(none.body.text).toMatch(/^No setting you can change matches "invoice"\. Where the person finds it in the app: Settings → Plan & billing/);expect((await host.handle({ action: "places", query: "spending" }, turn)).body.text).toMatch(/^Settings → Spending$/m);- expect((await host.handle({ action: "places", query: "storage" }, turn)).body.text).toMatch(/^Settings → Data.*\(shown in Advanced mode only/m);+ expect((await host.handle({ action: "places", query: "storage" }, turn)).body.text).toMatch(/^Settings → Data.*\(shown in Advanced mode; the switch is at the bottom of Settings\. Don't switch modes for it/m);const every = String((await host.handle({ action: "places" }, turn)).body.text).split("\n");expect(every[0]).toMatch(/^Settings opens from/);expect(every).toContain("Settings → AI → Other services");@@ -450,6 +450,51 @@ describe("pictures from a file the bot names", () => {});});+describe("Simple mode: a bot changes settings in the background and never switches the mode", () => {+ const simple = () => { const fx = fixture(); fx.windowValues.set("appearance.advanced", false); return fx; };++ it("changes a setting only Advanced mode shows while the app stays on Simple", async () => {+ const fx = simple();+ const got = JSON.parse(String((await fx.host.handle({ action: "get", id: "threads.maxConcurrentPerBot" }, fx.turn)).body.text)) as { where: string };+ expect(got.where).toMatch(/\(shown in Advanced mode; the switch is at the bottom of Settings\. Don't switch modes for it: change its setting yourself/);+ expect(got.where).not.toContain("appearance.advanced");+ expect((await fx.set("threads.maxConcurrentPerBot", "5")).status).toBe(200);+ expect(fx.cfg.threads?.maxConcurrentPerBot).toBe(5);+ expect(fx.windowValues.get("appearance.advanced")).toBe(false);+ expect(fx.cards().map((card) => card.card.appSettingRequest.settingId)).toEqual(["threads.maxConcurrentPerBot"]);+ });++ it("tells a bot to change the mode only when the person asks for it by name, and still changes it then", async () => {+ const fx = simple();+ const got = JSON.parse(String((await fx.host.handle({ action: "get", id: "appearance.advanced" }, fx.turn)).body.text)) as { help: string };+ expect(got.help).toContain("only when the person asks for Simple or Advanced mode by name, never to reach another setting");+ expect((await fx.set("appearance.advanced", "true")).status).toBe(200);+ expect(fx.windowValues.get("appearance.advanced")).toBe(true);+ });++ it.each([+ ["appearance.showThreads", "true"], ["appearance.toolsLayout", "toolbar"], ["appearance.pinnedCircles", "true"],+ ["appearance.pinnedPages", JSON.stringify([{ name: "Docs", url: "https://example.com" }])],+ ])("refuses %s, which Simple does not show, rather than claim a change nobody sees", async (id, value) => {+ const fx = simple();+ const refused = await fx.set(id, value);+ expect(refused.status).toBe(409);+ expect(refused.body.error).toMatch(/shows only in Advanced mode and this app is on Simple, so nothing changed\. Don't switch modes for it.*the switch at the bottom of Settings/);+ expect(fx.windowValues.has(id)).toBe(false);+ expect(fx.windowValues.get("appearance.advanced")).toBe(false);+ expect(fx.cards()).toEqual([]);+ fx.windowValues.set("appearance.advanced", true);+ expect((await fx.set(id, value)).status).toBe(200);+ });++ it("pins pages in Simple while the window frame's bar shows them", async () => {+ const fx = simple();+ fx.windowValues.set("appearance.windowFrame", true);+ expect((await fx.set("appearance.pinnedPages", JSON.stringify([{ name: "Docs", url: "https://example.com" }]))).status).toBe(200);+ expect(fx.windowValues.get("appearance.advanced")).toBe(false);+ });+});+describe("every other setting applies at once with Undo, Full access or not", () => {const written = (fx: ReturnType<typeof fixture>) => JSON.stringify([fx.botPatches, fx.saved, fx.routeCalls, [...fx.windowValues]]);diff --git a/server/app-settings/places.test.ts b/server/app-settings/places.test.tsindex b631faf8d1..11618a64b8 100644--- a/server/app-settings/places.test.ts+++ b/server/app-settings/places.test.ts@@ -14,7 +14,8 @@ describe("places", () => {it("name a place by its path, with when only Advanced mode or one kind of place shows it", () => {expect(placePath("keys")).toBe("Settings → AI → Other services");expect(placePath("language")).toBe("Settings → General → Language (in Simple mode it is at Settings → This app → Language)");- expect(placePath("send-key")).toBe("Settings → General → Send messages with (shown in Advanced mode only; app_settings set appearance.advanced true turns it on)");+ expect(placePath("send-key")).toBe("Settings → General → Send messages with (shown in Advanced mode; the switch is at the bottom of Settings. Don't switch modes for it: change its setting yourself, and give this path only if the person wants to look)");+ expect(placesList()).not.toContain("appearance.advanced");expect(placePath("wifi")).toMatch(/\(only in the desktop app, on this computer's own page\)$/);});diff --git a/server/app-settings/places.ts b/server/app-settings/places.tsindex 67491ce8b2..fd5c078ff3 100644--- a/server/app-settings/places.ts+++ b/server/app-settings/places.ts@@ -7,7 +7,7 @@ const byId = new Map(PLACES.map((place) => [place.id, place]));function described(place: SettingsPlace): string {const notes = [- ...(place.advanced ? [place.simplePath ? `in Simple mode it is at ${place.simplePath}` : "shown in Advanced mode only; app_settings set appearance.advanced true turns it on"] : []),+ ...(place.advanced ? [place.simplePath ? `in Simple mode it is at ${place.simplePath}` : "shown in Advanced mode; the switch is at the bottom of Settings. Don't switch modes for it: change its setting yourself, and give this path only if the person wants to look"] : []),...(place.only ? [`only in ${place.only}`] : []),];return notes.length ? `${place.path} (${notes.join("; ")})` : place.path;diff --git a/server/app-settings/registry-window.ts b/server/app-settings/registry-window.tsindex dcf9ec5d60..bff62e5ed5 100644--- a/server/app-settings/registry-window.ts+++ b/server/app-settings/registry-window.ts@@ -1,13 +1,19 @@// More preferences the app window keeps, or reaches through the desktop app's bridge, each applied with Undo on a card// saying what it does. A window that can't apply one (a browser has no desktop bridge) refuses it.-import { PLACE_SWATCHES, TALK_KEYS } from "../../shared/app-settings.ts";+import { PLACE_SWATCHES, TALK_KEYS, type WindowPrefId } from "../../shared/app-settings.ts";import { personOnly, type SettingEntry, type WindowPref } from "./registry.ts";const turn = (on: boolean, yes: string, no: string) => (on ? yes : no);-export function windowEntries(windowPref: WindowPref): SettingEntry[] {- const flag = (id: Parameters<WindowPref>[0], label: string, help: string, where: Parameters<WindowPref>[3], synonyms: string[], yes: string, no: string) =>- windowPref(id, label, help, where, synonyms, "true or false", { says: (on: boolean) => turn(on, yes, no) });+/** `read` is the window's last report of its preferences. */+export function windowEntries(windowPref: WindowPref, read: (id: WindowPrefId) => unknown): SettingEntry[] {+ /** Simple mode draws this one as if unset (unless `shown`), so a change while the window is on Simple would show nothing:+ * it is refused, and the bot never switches modes for it. */+ const advancedOnly = (label: string, shown = () => false) => () => (read("appearance.advanced") === false && !shown()+ ? `${label} shows only in Advanced mode and this app is on Simple, so nothing changed. Don't switch modes for it: tell the person in one line it applies once they turn on Advanced mode, with the switch at the bottom of Settings.`+ : null);+ const flag = (id: Parameters<WindowPref>[0], label: string, help: string, where: Parameters<WindowPref>[3], synonyms: string[], yes: string, no: string, refusal?: () => string | null) =>+ windowPref(id, label, help, where, synonyms, "true or false", { says: (on: boolean) => turn(on, yes, no), ...(refusal ? { refusal } : {}) });/** A way in to this computer: a bot may turn it on, but turning it off can cut off the device the person is using now. */const wayIn = (id: Parameters<WindowPref>[0], label: string, help: string, where: Parameters<WindowPref>[3], synonyms: string[], yes: string) =>windowPref(id, label, help, where, synonyms, "true (turning it off is done by the person, in Settings)",@@ -16,16 +22,18 @@ export function windowEntries(windowPref: WindowPref): SettingEntry[] {flag("appearance.userBubbles", "Coloured messages", "Your own messages take the bot's colour.", "bubbles", ["bubbles", "message color", "my messages"],"Colour your messages with each bot's colour", "Show your messages in plain grey"),flag("appearance.showThreads", "Threads in the sidebar", "List each bot's conversations under it in the sidebar.", "layout", ["threads", "conversations", "sidebar"],- "List each bot's threads in the sidebar", "Hide threads from the sidebar"),+ "List each bot's threads in the sidebar", "Hide threads from the sidebar", advancedOnly("Threads in the sidebar")),windowPref("appearance.toolsLayout", "Sidebar tools layout", "How the sidebar shows its tools: rows, or a toolbar of icons.", "layout", ["tools layout", "toolbar", "rows"], "rows or toolbar",- { says: (layout: "rows" | "toolbar") => (layout === "rows" ? "Show the sidebar's tools as rows" : "Show the sidebar's tools as a toolbar of icons") }),+ { says: (layout: "rows" | "toolbar") => (layout === "rows" ? "Show the sidebar's tools as rows" : "Show the sidebar's tools as a toolbar of icons"), refusal: advancedOnly("Sidebar tools layout") }),flag("appearance.pinnedCircles", "Pinned bots as circles", "Pinned bots show as a row of circles at the top of the sidebar.", "layout", ["pinned", "circles", "pins"],- "Show pinned bots as circles", "Show pinned bots as rows"),+ "Show pinned bots as circles", "Show pinned bots as rows", advancedOnly("Pinned bots as circles")),flag("appearance.universalPins", "Universal pins", "Pinned bots stay pinned in every place on the rail.", "layout", ["universal pins", "pins everywhere"],"Keep pinned bots pinned in every place", "Pin bots in each place on its own"),windowPref("appearance.pinnedPages", "Pinned pages", "Web pages pinned beside the chat. Send the full list; chat pages pinned from a conversation stay.", "layout",["pinned panels", "pinned pages", "web panel", "side page"], 'a list of up to 6 {"name","url"} with http(s) addresses; an empty list unpins every web page',- { says: (pages: Array<{ name: string; url: string }>) => (pages.length ? `Pin these pages beside the chat: ${pages.map((page) => `${page.name} (${page.url})`).join(", ")}` : "Unpin every web page beside the chat") }),+ { says: (pages: Array<{ name: string; url: string }>) => (pages.length ? `Pin these pages beside the chat: ${pages.map((page) => `${page.name} (${page.url})`).join(", ")}` : "Unpin every web page beside the chat"),+ // Simple shows pinned pages only in the window frame's top bar.+ refusal: advancedOnly("Pinned pages", () => read("appearance.windowFrame") === true) }),flag("appearance.showComputers", "Show your computers", "The rail of places down the side of the window (desktop app).", "layout", ["rail", "show your computers", "places"],"Show the rail of your computers and Clouds", "Hide the rail of your computers and Clouds"),flag("appearance.windowFrame", "Window frame", "Draw the system's own title bar around the window (desktop app; on Windows after a restart).", "layout", ["window frame", "title bar"],diff --git a/server/app-settings/registry.ts b/server/app-settings/registry.tsindex 1a5c08f0dd..19fea1faeb 100644--- a/server/app-settings/registry.ts+++ b/server/app-settings/registry.ts@@ -165,7 +165,7 @@ export function createSettingsRegistry(deps: RegistryDeps): SettingEntry[] {const safe: SettingEntry[] = [windowPref("appearance.skin", "Skin", "The window's built-in look; \"system\" follows the computer's light or dark mode. A custom look (any colours, fonts, CSS, pictures) is a theme: use action theme.", "theme", ["theme", "dark mode", "light mode", "colors", "look"], enumOf(WINDOW_PREFS["appearance.skin"].options)),- windowPref("appearance.advanced", "Advanced mode", "Advanced shows every setting and tool; Simple keeps the everyday ones.", "advanced-mode", ["simple mode", "advanced mode", "interface mode"], "true or false"),+ windowPref("appearance.advanced", "Advanced mode", "Advanced shows every setting and tool; Simple keeps the everyday ones. Change it only when the person asks for Simple or Advanced mode by name, never to reach another setting: those change in either mode.", "advanced-mode", ["simple mode", "advanced mode", "interface mode"], "true or false"),windowPref("appearance.font", "Font", "The app's typeface.", "tool-calls", ["typeface", "typography"], enumOf(WINDOW_PREFS["appearance.font"].options)),windowPref("appearance.chatWidth", "Chat width", "How wide the chat column is.", "tool-calls", ["layout", "column", "wide"], enumOf(WINDOW_PREFS["appearance.chatWidth"].options)),windowPref("general.sendKey", "Send key", "Which key sends a message in the composer.", "send-key", ["enter", "typing", "keyboard", "shortcut"], enumOf(WINDOW_PREFS["general.sendKey"].options)),@@ -343,7 +343,7 @@ export function createSettingsRegistry(deps: RegistryDeps): SettingEntry[] {["https", "public address"], () => "managed in Settings"),];- return [...safe, ...providers, engines, ...botEntries(deps, writable), ...pictureEntries(deps, writable), ...configEntries(deps, writable), ...windowEntries(windowPref), ...secret, ...owner];+ return [...safe, ...providers, engines, ...botEntries(deps, writable), ...pictureEntries(deps, writable), ...configEntries(deps, writable), ...windowEntries(windowPref, (id) => deps.window.read(id)), ...secret, ...owner];}export function findSettings(entries: readonly SettingEntry[], query: string, limit = 8): SettingEntry[] {