Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Open at login shows what Windows has
milind-soni8eb33a146209
diff --git a/electron/open-at-login.d.mts b/electron/open-at-login.d.mtsindex fe708780b3..914ce2d388 100644--- a/electron/open-at-login.d.mts+++ b/electron/open-at-login.d.mts@@ -4,7 +4,7 @@ type LoginItem = { follow(on: boolean): void; startedHidden(): boolean; availablexport declare function createOpenAtLogin(options: {app: {isPackaged: boolean;- getLoginItemSettings(options?: { args?: string[] }): { openAtLogin: boolean; wasOpenedAtLogin?: boolean; launchItems?: { name: string; enabled?: boolean }[] };+ getLoginItemSettings(options?: { args?: string[] }): { openAtLogin: boolean; wasOpenedAtLogin?: boolean; launchItems?: { name: string; args?: string[]; enabled?: boolean }[] };setLoginItemSettings(settings: { openAtLogin: boolean; args?: string[]; name?: string }): void;};file: string;diff --git a/electron/open-at-login.mjs b/electron/open-at-login.mjsindex 23b59ea258..41a13a84fc 100644--- a/electron/open-at-login.mjs+++ b/electron/open-at-login.mjs@@ -1,6 +1,6 @@// While this computer is lent, the app starts with the person's session, out of sight, so My Cloud's bots can use it-// again after a restart without anyone opening it. Only a login item this app added for lending is ever removed, and-// only such a launch starts hidden: one the person set up themselves, here or in the system's settings, opens the window.+// again after a restart without anyone opening it. Lending only ever removes a login item it added, and only such a+// launch starts hidden: one the person set up themselves, here or in the system's settings, opens the window.import fs from "node:fs";import path from "node:path";@@ -18,14 +18,22 @@ export function autostartEntry(exec, { lending = true } = {}) {}/**- * `file`: where this app records that it added the login item (macOS, where a login item carries no arguments).+ * `file`: where this app records that it added the login item (macOS, where a login item carries no arguments), and+ * that the person turned Open at login off (Windows, where lending then adds no entry of its own).* `follow(on)` keeps the login item in step with lending; `startedHidden()` says this launch came from it.- * `chosen()` and `choose(on)`: the person's own login item, which opens the window and which lending never removes.+ * `chosen()` and `choose(on)`: the person's own login item, which opens the window and which lending never removes; on+ * Windows, whether Windows starts the app at sign-in at all, as its Startup apps list shows.*/export function createOpenAtLogin({ app, file, platform = process.platform, env = process.env, home, argv = process.argv, execPath = process.execPath }) {const autostart = path.join(env.XDG_CONFIG_HOME || path.join(home, ".config"), "autostart", "openmausbot.desktop");- const added = () => { try { return JSON.parse(fs.readFileSync(file, "utf8")).added === true; } catch { return false; } };- const remember = (value) => { try { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, JSON.stringify({ added: value })); } catch {} };+ const saved = () => { try { return JSON.parse(fs.readFileSync(file, "utf8")) ?? {}; } catch { return {}; } };+ const store = (fields) => { try { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, JSON.stringify({ ...saved(), ...fields })); } catch {} };+ const added = () => saved().added === true;+ const remember = (value) => store({ added: value });+ /** Electron 43.7 on Windows: `openAtLogin` compares the Run entry's arguments with the `args` asked about (none by+ * default), so lending's `--omb-hidden` entry reads as off; `launchItems` lists the entries that start this executable,+ * each with its name, arguments and whether Task Manager has it enabled. */+ const windowsStartsApp = () => (app.getLoginItemSettings().launchItems ?? []).filter(item => item.enabled !== false);const ours = () => { try { return fs.readFileSync(autostart, "utf8").includes(MARK); } catch { return false; } };return {follow(on) {@@ -40,6 +48,7 @@ export function createOpenAtLogin({ app, file, platform = process.platform, env}if (platform === "win32") {const settings = { args: [HIDDEN_ARG] };+ if (on && saved().declined === true) return;if (app.getLoginItemSettings(settings).openAtLogin !== on) app.setLoginItemSettings({ openAtLogin: on, ...settings });return;}@@ -53,7 +62,7 @@ export function createOpenAtLogin({ app, file, platform = process.platform, envchosen() {try {if (platform === "linux") return fs.existsSync(autostart) && !ours();- if (platform === "win32") return (app.getLoginItemSettings().launchItems ?? []).some(item => item.name === CHOSEN_NAME && item.enabled !== false);+ if (platform === "win32") return windowsStartsApp().length > 0;return app.getLoginItemSettings().openAtLogin === true && !added();} catch { return false; }},@@ -66,7 +75,12 @@ export function createOpenAtLogin({ app, file, platform = process.platform, env} else if (!ours()) fs.rmSync(autostart, { force: true });return;}- if (platform === "win32") { app.setLoginItemSettings({ openAtLogin: on, args: [], name: CHOSEN_NAME }); return; }+ if (platform === "win32") {+ if (on) app.setLoginItemSettings({ openAtLogin: true, args: [], name: CHOSEN_NAME });+ else for (const item of windowsStartsApp()) app.setLoginItemSettings({ openAtLogin: false, args: item.args ?? [], name: item.name });+ store({ declined: !on });+ return;+ }app.setLoginItemSettings({ openAtLogin: on });remember(false);},diff --git a/electron/open-at-login.node-test.mjs b/electron/open-at-login.node-test.mjsindex efd5e6c241..39500360b6 100644--- a/electron/open-at-login.node-test.mjs+++ b/electron/open-at-login.node-test.mjs@@ -64,6 +64,48 @@ test("Windows: the person's item has a name of its own, apart from lending's hidassert.equal(login.chosen(), false);});+/** Electron 43's login item API on Windows: one Run entry per name (the AppUserModelId unless named), `openAtLogin` true+ * only for that default entry with exactly the asked `args`, and `launchItems` listing every entry for this executable. */+function windowsApp(entries = []) {+ const items = new Map(entries.map(({ name, args = [], enabled = true }) => [name, { args, enabled }]));+ const DEFAULT = "electron.app.OpenMausBot";+ return {+ isPackaged: true, items,+ getLoginItemSettings({ args = [] } = {}) {+ const own = items.get(DEFAULT);+ return {+ openAtLogin: Boolean(own) && JSON.stringify(own.args) === JSON.stringify(args),+ launchItems: [...items].map(([name, item]) => ({ name, path: "C:\\OpenMausBot\\OpenMausBot.exe", args: item.args, scope: "user", enabled: item.enabled })),+ };+ },+ setLoginItemSettings({ openAtLogin: on, args = [], name = DEFAULT }) { if (on) items.set(name, { args, enabled: true }); else items.delete(name); },+ };+}++test("Windows: Settings shows on while Windows already starts the app, even from lending's hidden entry", async t => {+ const dir = await temp(t);+ const app = windowsApp([{ name: "electron.app.OpenMausBot", args: ["--omb-hidden"] }]);+ const login = createOpenAtLogin({ app, file: path.join(dir, "win.json"), platform: "win32", home: dir, argv: ["OpenMausBot.exe"] });+ const handlers = new Map();+ installOpenAtLogin({ ipcMain: { handle: (channel, handler) => handlers.set(channel, handler) }, guard: (_channel, handler) => handler, loginItem: login, changed: () => {} });+ assert.deepEqual(await handlers.get("open-at-login:state")({}), { available: true, on: true });+ app.items.get("electron.app.OpenMausBot").enabled = false;+ assert.equal(login.chosen(), false, "an entry turned off in Task Manager starts nothing");+});++test("Windows: turning it off removes every entry that starts the app, and lending adds none until it is on again", async t => {+ const dir = await temp(t);+ const app = windowsApp([{ name: "electron.app.OpenMausBot", args: ["--omb-hidden"] }, { name: "OpenMausBot at login" }]);+ const login = createOpenAtLogin({ app, file: path.join(dir, "win.json"), platform: "win32", home: dir, argv: ["OpenMausBot.exe"] });+ login.choose(false);+ assert.deepEqual([...app.items.keys()], []);+ login.follow(true);+ assert.equal(login.chosen(), false, "lending keeps to the person's choice");+ login.choose(true);+ login.follow(true);+ assert.deepEqual([...app.items].sort(), [["OpenMausBot at login", { args: [], enabled: true }], ["electron.app.OpenMausBot", { args: ["--omb-hidden"], enabled: true }]]);+});+test("Linux: the person's autostart entry has no hidden flag and no lending mark, and lending never removes it", async t => {const dir = await temp(t);const config = path.join(dir, "config");