Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Backups leave out a bot folder's dangling and outside links, and browser profiles, and say which
milind-soni3838ab1c6185
diff --git a/server/workspace-backup-policy.ts b/server/workspace-backup-policy.tsindex cd9074067e..94a3cd2e13 100644--- a/server/workspace-backup-policy.ts+++ b/server/workspace-backup-policy.ts@@ -94,5 +94,15 @@ export function installedDependencyFolder(source: string, name: string, stat: Sttry { return lstatSync(join(source, "pyvenv.cfg")).isFile(); } catch { return false; }}+/** A Chromium browser's own profile folder (it holds "Local State"), as a bot's project may keep one: its sign-ins and+ * cookies stay on the computer they were made on, as the app's own browser profiles do, and its caches are large. */+export function browserProfileFolder(source: string, stat: Stats): boolean {+ if (!stat.isDirectory()) return false;+ try { return lstatSync(join(source, "Local State")).isFile(); } catch { return false; }+}++/** Up to three of `paths`, for a note that names what was left out. */+export const examplePaths = (paths: readonly string[]): string => `${paths.slice(0, 3).join(", ")}${paths.length > 3 ? ", …" : ""}`;+/** Python's bytecode cache, written again the next time the code runs. */export const bytecodeCache = (name: string, stat: Stats): boolean => name === "__pycache__" && (stat.isDirectory() || stat.isSymbolicLink());diff --git a/server/workspace-backup.test.ts b/server/workspace-backup.test.tsindex 4b0290f9da..1b0fbf53b4 100644--- a/server/workspace-backup.test.ts+++ b/server/workspace-backup.test.ts@@ -722,7 +722,7 @@ describe("encrypted full workspace backups", () => {expect(existsSync(join(data, "task-workspaces", "bot", "thread", "node_modules"))).toBe(false);expect(existsSync(join(data, "task-workspaces", "bot", "thread", "linked-secret"))).toBe(false);expect(existsSync(join(data, "workspaces", "bot", "project", "node_modules"))).toBe(false);- symlinkSync(join(outside, "secret"), join(root, "workspaces", "bot", "external"));+ symlinkSync(join(outside, "secret"), join(root, "external"));await expect(createWorkspaceBackup(root, { password: PASSWORD })).rejects.toThrow(/outside the workspace/);});@@ -763,8 +763,45 @@ describe("encrypted full workspace backups", () => {expect(existsSync(join(data, "task-workspaces", "bot", "thread", "env"))).toBe(false);expect(existsSync(join(data, "workspaces", "bot", "app", "__pycache__"))).toBe(false);- symlinkSync(join(outside, "python3"), join(bot, "venv", "python"));- await expect(createWorkspaceBackup(root, { password: PASSWORD })).rejects.toThrow("Cannot back up symbolic link outside the workspace: workspaces/bot/venv/python");+ expect(exported.summary.warnings.some((warning) => warning.includes("symbolic link(s) in bot folders"))).toBe(false);+ });++ it("leaves out a bot folder's links to nothing or outside, and browser profiles, and names them; elsewhere such links still stop it", async () => {+ const root = directory();+ const outside = directory();+ writeFileSync(join(outside, "secret"), "must never be read");+ const bot = join(root, "workspaces", "bot");+ // A Chromium profile a bot's project keeps: known by its "Local State", left out whole with its lock links.+ const profile = join(bot, "broker", "state", "chrome-profile");+ mkdirSync(join(profile, "Default"), { recursive: true });+ writeFileSync(join(profile, "Local State"), "{}");+ writeFileSync(join(profile, "Default", "Cookies"), "cookies");+ symlinkSync("gone-12345", join(profile, "SingletonLock"));+ symlinkSync(join(outside, "missing"), join(profile, "RunningChromeVersion"));+ // The same kinds of link outside a browser profile: left out and named.+ mkdirSync(join(bot, "notes"), { recursive: true });+ writeFileSync(join(bot, "notes", "todo.md"), "keep me");+ symlinkSync(join(outside, "missing"), join(bot, "notes", "dangling"));+ symlinkSync(join(outside, "secret"), join(bot, "notes", "outside"));+ symlinkSync(outside, join(bot, "outside-folder"), process.platform === "win32" ? "junction" : "dir");++ const exported = await createWorkspaceBackup(root, { password: PASSWORD });+ expect(exported.summary.warnings).toContain("1 browser profile folder(s) in bot folders were left out with their sign-ins, cookies and caches; sign in again after restoring: workspaces/bot/broker/state/chrome-profile.");+ expect(exported.summary.warnings).toContain("3 symbolic link(s) in bot folders were left out because they point to nothing or outside this backup: workspaces/bot/notes/dangling, workspaces/bot/notes/outside, workspaces/bot/outside-folder.");+ const target = directory();+ const staged = await stageWorkspaceBackup(target, exported.path, { password: PASSWORD });+ const data = join(target, ".backups", staged.id, "staged", "data", "workspaces", "bot");+ expect(readFileSync(join(data, "notes", "todo.md"), "utf8")).toBe("keep me");+ expect(existsSync(join(data, "broker", "state"))).toBe(true);+ expect(existsSync(join(data, "broker", "state", "chrome-profile"))).toBe(false);+ for (const left of ["notes/dangling", "notes/outside", "outside-folder"]) expect(existsSync(join(data, left)), left).toBe(false);++ // Outside a bot's folder the rules stand: a dangling link still stops the backup, and so does a loop.+ symlinkSync(join(outside, "missing"), join(root, "dangling"));+ await expect(createWorkspaceBackup(root, { password: PASSWORD })).rejects.toThrow("Cannot back up dangling symbolic link: dangling");+ rmSync(join(root, "dangling"));+ symlinkSync(".", join(bot, "notes", "loop"), process.platform === "win32" ? "junction" : "dir");+ await expect(createWorkspaceBackup(root, { password: PASSWORD })).rejects.toThrow("symbolic link to the folder that contains it");});it("counts the app's skill links in work folders as managed, not as outside data", async () => {diff --git a/server/workspace-backup.ts b/server/workspace-backup.tsindex 574f1c0474..dd6b913746 100644--- a/server/workspace-backup.ts+++ b/server/workspace-backup.ts@@ -15,7 +15,7 @@ import { userErrorFields, userErrorThrown } from "./user-errors.ts";import { WORKSPACE_BACKUP_CLIENT_KEYS } from "../shared/workspace-backup-client.ts";import { INSTRUCTION_FILE, restorePaths, validRelative } from "./workspace-backup-paths.ts";import { cjkSearchText } from "./cjk-search.ts";-import { bytecodeCache, dataEngineSpillPath, ephemeralWorkspaceTokenPath, excludedWorkspaceAuthPath, installedDependencyFolder, managedTaskSkillLink, portableWorkspaceConfig, redownloadedOrgLibraryPath, restoredWorkspaceConfig } from "./workspace-backup-policy.ts";+import { browserProfileFolder, bytecodeCache, dataEngineSpillPath, examplePaths, ephemeralWorkspaceTokenPath, excludedWorkspaceAuthPath, installedDependencyFolder, managedTaskSkillLink, portableWorkspaceConfig, redownloadedOrgLibraryPath, restoredWorkspaceConfig } from "./workspace-backup-policy.ts";import { omittedAsTeamPrivate, routinesWithoutTeamPrivate, stripTeamPrivate, TEAM_PRIVATE_NOTE, teamPrivateAttachments, teamPrivateThreads, withoutTeamPrivate } from "./workspace-backup-team-private.ts";import { flushLaterSaves } from "./save-batch.ts";import { DATA_TABLES, foldLegacySidecars, LEGACY_SIDECARS, LIVE_DATABASE_SIDECARS, SNAPSHOT_DATABASES, snapshotDatabases, tooLargeError } from "./workspace-backup-databases.ts";@@ -68,7 +68,7 @@ const EXCLUSION_NOTES = ["Device pairing, server identity, live leases and runtime files (existing destination identities are preserved).","Saved credentials, provider and MCP connections, managed provider login homes and browser login profiles are not transferred. Destination connections are preserved; reconnect on a new device.","Downloaded tools and caches (they can be installed again), and recorded browser step screenshots (export them from a conversation to keep them).",- "Installed dependency folders (node_modules, Python virtual environments), Python bytecode caches and symbolic links inside conversation work folders; reinstall or recreate them in the project.",+ "Installed dependency folders (node_modules, Python virtual environments), Python bytecode caches, browser profile folders, symbolic links inside conversation work folders, and links in bot folders to nothing or to outside this backup; reinstall or recreate them in the project.","External project folders, CLI login homes, browser session homes, OS keychains, companion devices and other servers.","VM/container disk layers and remote cloud data; durable files inside this workspace are included.","Waits bots set up: they end within a week, so ask the bot again after restoring.",@@ -331,6 +331,7 @@ export async function createWorkspaceBackupSnapshot(dataDir: string, options: Crlet skippedDependencies = 0;let skippedWorkLinks = 0;let copiedLinks = 0;+ const leftLinks: string[] = [], leftProfiles: string[] = [];try {const root = realpathSync(dataDir);await snapshotDatabases(root, snapshot);@@ -356,6 +357,7 @@ export async function createWorkspaceBackupSnapshot(dataDir: string, options: Crcontinue;}if (bytecodeCache(name, stat)) continue;+ if (prefix && browserProfileFolder(source, stat)) { leftProfiles.push(path); continue; }// A link a bot made in a conversation's folder, or in Team files (which a bot may be let to write), is never// followed or carried, and never stops the backup.if (stat.isSymbolicLink() && path.startsWith("team-files/")) {@@ -368,9 +370,13 @@ export async function createWorkspaceBackupSnapshot(dataDir: string, options: Cr}if (stat.isSymbolicLink()) {let target: string;- try { target = realpathSync(source); } catch { throw new Error(`Cannot back up dangling symbolic link: ${path}`); }+ // In a bot's folder, a link to nothing (a browser's SingletonLock) or to outside the data folder is left out and+ // named in the backup's note; anywhere else it still stops the backup.+ const leave = path.startsWith("workspaces/");+ try { target = realpathSync(source); } catch { if (leave) { leftLinks.push(path); continue; } throw new Error(`Cannot back up dangling symbolic link: ${path}`); }const rel = relative(root, target);if (rel === ".." || rel.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) || isAbsolute(rel)) {+ if (leave) { leftLinks.push(path); continue; }throw new Error(`Cannot back up symbolic link outside the workspace: ${path}`);}const portableRel = rel.replaceAll("\\", "/");@@ -428,6 +434,8 @@ export async function createWorkspaceBackupSnapshot(dataDir: string, options: Crif (skippedLinks) warnings.push(`${skippedLinks} managed skill discovery link(s) were omitted and are recreated by the app.`);if (skippedDependencies) warnings.push(`${skippedDependencies} installed dependency folder(s) (node_modules or Python virtual environments) were omitted; reinstall them in the project after restoring.`);if (copiedLinks) warnings.push(`${copiedLinks} symbolic link(s) inside a workspace were saved as copies of what they point to; restoring creates regular files and folders there.`);+ if (leftProfiles.length) warnings.push(`${leftProfiles.length} browser profile folder(s) in bot folders were left out with their sign-ins, cookies and caches; sign in again after restoring: ${examplePaths(leftProfiles)}.`);+ if (leftLinks.length) warnings.push(`${leftLinks.length} symbolic link(s) in bot folders were left out because they point to nothing or outside this backup: ${examplePaths(leftLinks)}.`);if (skippedWorkLinks) warnings.push(`${skippedWorkLinks} symbolic link(s) in conversation work folders were omitted; what they point to is outside this backup.`);const summary: WorkspaceBackupSummary = {format: "openmaus.workspace-backup", version: 1, id: job.id, createdAt: new Date().toISOString(),