Skip to content

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

App settings: keep the place note short and put the no-switch rule where a bot can set

milind-sonic7117aa781d7
diff --git a/server/app-settings/host.test.ts b/server/app-settings/host.test.ts
index 867df38416..cf429a5437 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; the switch is at the bottom of Settings\. Don't switch modes for it/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\)$/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");
@@ -455,9 +455,14 @@ describe("Simple mode: a bot changes settings in the background and never switch
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/);
+ const got = JSON.parse(String((await fx.host.handle({ action: "get", id: "threads.maxConcurrentPerBot" }, fx.turn)).body.text)) as { where: string; inSimple: string };
+ expect(got).toMatchObject({ where: expect.stringMatching(/\(shown in Advanced mode; the switch is at the bottom of Settings\)$/), inSimple: "set it as usual; never switch modes for it" });
expect(got.where).not.toContain("appearance.advanced");
+ const found = JSON.parse(String((await fx.host.handle({ action: "find", query: "parallel threads" }, fx.turn)).body.text)) as Array<{ id: string; inSimple?: string }>;
+ expect(found.find((hit) => hit.id === "threads.maxConcurrentPerBot")?.inSimple).toBe("set it as usual; never switch modes for it");
+ const personOnly = JSON.parse(String((await fx.host.handle({ action: "get", id: "remote.httpsAddress" }, fx.turn)).body.text)) as Record<string, unknown>;
+ expect(personOnly).toMatchObject({ change: "only the person, in Settings → Devices → How your phone reaches this computer → HTTPS address (shown in Advanced mode; the switch is at the bottom of Settings; only in the desktop app, on this computer's own page)" });
+ expect(personOnly).not.toHaveProperty("inSimple");
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);
@@ -479,7 +484,7 @@ describe("Simple mode: a bot changes settings in the background and never switch
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(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, then ask again\.$/);
expect(fx.windowValues.has(id)).toBe(false);
expect(fx.windowValues.get("appearance.advanced")).toBe(false);
expect(fx.cards()).toEqual([]);
diff --git a/server/app-settings/host.ts b/server/app-settings/host.ts
index ab41227cf1..235376409a 100644
--- a/server/app-settings/host.ts
+++ b/server/app-settings/host.ts
@@ -12,7 +12,7 @@ import type { BotRecord, GroupRecord, Store } from "../store.ts";
import type { ThemeTool } from "../themes/tool.ts";
import { cardElsewhere, cardNotInRoom, cardShownStatus, SETTINGS_CARDS } from "./cards.ts";
import type { TakenPicture } from "./picture-file.ts";
-import { findPlaces, placePath, placesList } from "./places.ts";
+import { advancedOnlyPlace, findPlaces, placePath, placesList } from "./places.ts";
import { findSettings, personOnly, type SettingEntry, type WritableEntry } from "./registry.ts";
export const TOOL = "app_settings";
@@ -91,7 +91,9 @@ export function createAppSettings(deps: AppSettingsDeps) {
const reply = (status: number, body: Record<string, unknown>) => ({ status, body });
const refuse = (status: number, error: string) => reply(status, { error });
- const describe = (entry: SettingEntry) => ({ id: entry.id, label: entry.label, tier: entry.tier, value: text(entry.read()), where: placePath(entry.where) });
+ const describe = (entry: SettingEntry) => ({ id: entry.id, label: entry.label, tier: entry.tier, value: text(entry.read()), where: placePath(entry.where),
+ // A bot changes it in Simple mode too; the person sees the path only when they want to look themselves.
+ ...(entry.tier !== "owner-only" && advancedOnlyPlace(entry.where) ? { inSimple: "set it as usual; never switch modes for it" } : {}) });
/** Null when the turn is the owner's own; otherwise why not, so the refusal can say what the person can do instead. */
const notOwners = (turn: Turn): NotOwners | null =>
deps.guestDriven(turn.threadId) ? "guest" : deps.turnOwner(turn) !== null ? null : (deps.ownerRefusal?.(turn) ?? "unknown");
diff --git a/server/app-settings/places.test.ts b/server/app-settings/places.test.ts
index 11618a64b8..2ea5acea16 100644
--- a/server/app-settings/places.test.ts
+++ b/server/app-settings/places.test.ts
@@ -14,7 +14,7 @@ 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; 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(placePath("send-key")).toBe("Settings → General → Send messages with (shown in Advanced mode; the switch is at the bottom of Settings)");
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.ts
index fd5c078ff3..5835d5e5c7 100644
--- a/server/app-settings/places.ts
+++ b/server/app-settings/places.ts
@@ -7,12 +7,15 @@ 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; 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.advanced ? [place.simplePath ? `in Simple mode it is at ${place.simplePath}` : "shown in Advanced mode; the switch is at the bottom of Settings"] : []),
...(place.only ? [`only in ${place.only}`] : []),
];
return notes.length ? `${place.path} (${notes.join("; ")})` : place.path;
}
+/** Whether only Advanced mode shows the place, with nowhere for it in Simple. */
+export const advancedOnlyPlace = (id: SettingsPlaceId): boolean => Boolean(byId.get(id)!.advanced && !byId.get(id)!.simplePath);
+
/** The place's path, with when only Advanced mode or one kind of place shows it. */
export const placePath = (id: SettingsPlaceId): string => described(byId.get(id)!);
diff --git a/server/app-settings/registry-window.ts b/server/app-settings/registry-window.ts
index bff62e5ed5..558ea09cb0 100644
--- a/server/app-settings/registry-window.ts
+++ b/server/app-settings/registry-window.ts
@@ -10,7 +10,7 @@ export function windowEntries(windowPref: WindowPref, read: (id: WindowPrefId) =
/** 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.`
+ ? `${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 that it shows in Advanced mode, which they turn on with the switch at the bottom of Settings, then ask again.`
: 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 } : {}) });