Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Export follows a top-level folder linked to another drive
AdityaUmale670e47c53439
diff --git a/server/workspace-backup.test.ts b/server/workspace-backup.test.tsindex 1b0fbf53b4..ddb0cd0f32 100644--- a/server/workspace-backup.test.ts+++ b/server/workspace-backup.test.ts@@ -653,9 +653,10 @@ describe("encrypted full workspace backups", () => {const root = directory();const outside = directory();writeFileSync(join(outside, "secret"), "must never be read");- symlinkSync(join(outside, "secret"), join(root, "external"));+ mkdirSync(join(root, "files"));+ symlinkSync(join(outside, "secret"), join(root, "files", "external"));await expect(createWorkspaceBackup(root, { password: PASSWORD })).rejects.toThrow(/outside the workspace/);- rmSync(join(root, "external"));+ rmSync(join(root, "files"), { recursive: true });writeFileSync(join(root, "regular"), "data");symlinkSync(join(root, "regular"), join(root, "internal"));await expect(createWorkspaceBackup(root, { password: PASSWORD })).rejects.toThrow(/user-created symbolic link/);@@ -670,6 +671,37 @@ describe("encrypted full workspace backups", () => {expect(exported.summary.warnings.some((warning) => warning.includes("1 managed skill"))).toBe(true);});+ it("follows a top-level folder moved to another drive by a link, and says so; links inside it keep their rules", async () => {+ const root = directory();+ const drive = directory();+ const kind = process.platform === "win32" ? "junction" : "dir";+ mkdirSync(join(drive, "events"));+ writeFileSync(join(drive, "events", "2026-11.jsonl"), "{}\n");+ symlinkSync(join(drive, "events"), join(root, "events"), kind);+ const project = join(drive, "workspaces", "ws", "project");+ mkdirSync(join(project, ".agents", "skills", "review"), { recursive: true });+ mkdirSync(join(project, ".claude"), { recursive: true });+ writeFileSync(join(project, ".agents", "skills", "review", "SKILL.md"), "# Review");+ symlinkSync(join("..", ".agents", "skills"), join(project, ".claude", "skills"), kind);+ symlinkSync(join(drive, "workspaces"), join(root, "workspaces"), kind);+ const exported = await createWorkspaceBackup(root, { password: PASSWORD });+ expect(exported.summary.warnings).toContain("2 top-level item(s) of the data folder link to another place and were saved as copies of what they point to; restoring puts them back as regular folders and files: events, workspaces.");+ expect(exported.summary.warnings.some((warning) => warning.startsWith("1 symbolic link(s) inside a workspace were saved as copies"))).toBe(true);+ const target = directory();+ const staged = await stageWorkspaceBackup(target, exported.path, { password: PASSWORD });+ const data = join(target, ".backups", staged.id, "staged", "data");+ expect(readFileSync(join(data, "events", "2026-11.jsonl"), "utf8")).toBe("{}\n");+ expect(readFileSync(join(data, "workspaces", "ws", "project", ".claude", "skills", "review", "SKILL.md"), "utf8")).toBe("# Review");++ // A second top-level link into the same place would carry it twice.+ symlinkSync(join(drive, "events"), join(root, "logs"), kind);+ await expect(createWorkspaceBackup(root, { password: PASSWORD })).rejects.toThrow(/user-created symbolic link/);+ rmSync(join(root, "logs"));+ // A link to a folder that holds the data folder is a loop.+ symlinkSync(join(root, ".."), join(root, "up"), kind);+ await expect(createWorkspaceBackup(root, { password: PASSWORD })).rejects.toMatchObject({ errorKey: "serverError.backup.recursiveLink" });+ });+it("saves links inside one workspace as copies of what they point to, and refuses loops and links to other workspaces", async () => {const root = directory();const project = join(root, "workspaces", "ws", "project");@@ -722,7 +754,8 @@ 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, "external"));+ mkdirSync(join(root, "files"));+ symlinkSync(join(outside, "secret"), join(root, "files", "external"));await expect(createWorkspaceBackup(root, { password: PASSWORD })).rejects.toThrow(/outside the workspace/);});diff --git a/server/workspace-backup.ts b/server/workspace-backup.tsindex dd6b913746..e089fc4d13 100644--- a/server/workspace-backup.ts+++ b/server/workspace-backup.ts@@ -332,8 +332,23 @@ export async function createWorkspaceBackupSnapshot(dataDir: string, options: Crlet skippedWorkLinks = 0;let copiedLinks = 0;const leftLinks: string[] = [], leftProfiles: string[] = [];+ // A top-level item linked to another place (a folder moved to another drive, a Windows junction) is followed, and+ // what is under where it points counts as under its name here.+ const moved: { name: string; target: string }[] = [];try {const root = realpathSync(dataDir);+ const under = (folder: string, path: string) => {+ const rel = relative(folder, path);+ return rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel) ? undefined : rel;+ };+ const dataRelative = (target: string) => {+ const rel = under(root, target);+ if (rel !== undefined) return rel;+ for (const link of moved) {+ const inside = under(link.target, target);+ if (inside !== undefined) return inside ? join(link.name, inside) : link.name;+ }+ };await snapshotDatabases(root, snapshot);const teamPrivate = teamPrivateThreads({ starters: join(root, "thread-starters.json"), groups: join(root, "groups.json"), bots: join(root, "bots.json") });const privacy = teamPrivate && { ...teamPrivate, attachments: teamPrivateAttachments(root, join(snapshot, SNAPSHOT_DATABASES["messages.db"]!), teamPrivate) };@@ -374,28 +389,36 @@ export async function createWorkspaceBackupSnapshot(dataDir: string, options: Cr// 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("\\", "/");- // Only the app's disposable native-discovery links may be omitted; any other link is user data.- if (/^workspaces\/[^/]+\/\.(?:claude|agents|grok)\/skills\/[^/]+$/.test(path) &&- portableRel.startsWith(`workspaces/${path.split("/")[1]}/skills/`)) {- skippedLinks++;- continue;- }- const workspace = /^workspaces\/[^/]+\//.exec(path)?.[0];- if (!workspace || !portableRel.startsWith(workspace)) {- throw new Error(`Cannot back up user-created symbolic link; replace it with regular files first: ${path}`);+ const rel = dataRelative(target);+ const followed = rel === undefined && !prefix;+ if (!followed) {+ if (rel === undefined) {+ if (leave) { leftLinks.push(path); continue; }+ throw new Error(`Cannot back up symbolic link outside the workspace: ${path}`);+ }+ const portableRel = rel.replaceAll("\\", "/");+ // Only the app's disposable native-discovery links may be omitted; any other link is user data.+ if (/^workspaces\/[^/]+\/\.(?:claude|agents|grok)\/skills\/[^/]+$/.test(path) &&+ portableRel.startsWith(`workspaces/${path.split("/")[1]}/skills/`)) {+ skippedLinks++;+ continue;+ }+ const workspace = /^workspaces\/[^/]+\//.exec(path)?.[0];+ if (!workspace || !portableRel.startsWith(workspace)) {+ throw new Error(`Cannot back up user-created symbolic link; replace it with regular files first: ${path}`);+ }}if (chain.some((folder) => folder === target || folder.startsWith(`${target}${sep}`))) {throw userErrorThrown("serverError.backup.recursiveLink", { path });}+ // A second top-level link into a place already followed would carry it twice.+ if (followed && moved.some((link) => under(target, link.target) !== undefined)) {+ throw new Error(`Cannot back up user-created symbolic link; replace it with regular files first: ${path}`);+ }source = target;stat = lstatSync(source);- copiedLinks++;+ if (followed) moved.push({ name, target });+ else copiedLinks++;}if (entries.length >= MAX_WORKSPACE_BACKUP_FILES) throw new Error("The workspace exceeds the 100,000-entry backup limit.");const caseTwin = foldedPaths.get(path.toLowerCase());@@ -433,6 +456,7 @@ export async function createWorkspaceBackupSnapshot(dataDir: string, options: Crwalk(root);if (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 (moved.length) warnings.push(`${moved.length} top-level item(s) of the data folder link to another place and were saved as copies of what they point to; restoring puts them back as regular folders and files: ${examplePaths(moved.map((link) => link.name))}.`);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)}.`);