Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Folder links: give up on a folder check that never answers, and open nothing when it answers late
AdityaUmale18e9494245c6
diff --git a/electron/save-file.mjs b/electron/save-file.mjsindex 1b96104b20..01aeeded71 100644--- a/electron/save-file.mjs+++ b/electron/save-file.mjs@@ -139,23 +139,33 @@ export async function revealInFolder(rawPath, { reveal, fsp = fs.promises, pathA// shell.openPath runs whatever it is given, so only a plain folder may reach it: never a file, a Mac app bundle// (Name.app, or a folder with Contents/Info.plist), or a link to either.-export async function openFolder(rawPath, { open, fsp = fs.promises, pathApi = path }) {+// A dead network mount can leave these checks pending: past checkMs the link falls back, and a late answer opens nothing.+export async function openFolder(rawPath, { open, fsp = fs.promises, pathApi = path, checkMs = 3_000 }) {const target = localTarget(rawPath, pathApi);if (!target) return "invalid";+ let timer;+ const checked = await Promise.race([+ plainFolder(target, fsp, pathApi),+ new Promise((resolve) => { timer = setTimeout(() => resolve({ problem: "not-folder" }), checkMs); }),+ ]).finally(() => clearTimeout(timer));+ if (checked.problem) return checked.problem;+ let error = "";+ try { error = await open(checked.real); } catch (failure) { error = failure?.message ?? String(failure); }+ return error ? "failed" : "opened";+}++async function plainFolder(target, fsp, pathApi) {let real;let stats;try {real = await fsp.realpath(target);stats = await fsp.stat(real);} catch {- return "missing";+ return { problem: "missing" };}- if (!stats.isDirectory() || /.\.[^.]+$/.test(pathApi.basename(real))) return "not-folder";+ if (!stats.isDirectory() || /.\.[^.]+$/.test(pathApi.basename(real))) return { problem: "not-folder" };const bundle = await fsp.stat(pathApi.join(real, "Contents", "Info.plist")).then(() => true, () => false);- if (bundle) return "not-folder";- let error = "";- try { error = await open(real); } catch (failure) { error = failure?.message ?? String(failure); }- return error ? "failed" : "opened";+ return bundle ? { problem: "not-folder" } : { real };}/** This app's own logs folder in Explorer or Finder, made first if nothing has been logged yet. The folder is main'sdiff --git a/electron/save-file.node-test.mjs b/electron/save-file.node-test.mjsindex 862c774243..5d1a67f102 100644--- a/electron/save-file.node-test.mjs+++ b/electron/save-file.node-test.mjs@@ -329,6 +329,21 @@ describe("openFolder for a folder a chat links to", () => {assert.equal(await openFolder("C:\\Users\\Maus\\Reports\\..\\Reports", { open, fsp, pathApi: path.win32 }), "opened");assert.deepEqual(opened, ["C:\\Users\\Maus\\Reports"]);});++ it("gives up on a check that never answers (dead mount) and opens nothing when it answers late", async () => {+ const { opened, open } = shell();+ let answer;+ const fsp = {+ realpath: async (target) => target,+ stat: (target) => target.endsWith("Info.plist")+ ? new Promise((resolve, reject) => { answer = () => reject(Object.assign(new Error("gone"), { code: "ENOENT" })); })+ : Promise.resolve({ isFile: () => false, isDirectory: () => true }),+ };+ assert.equal(await openFolder("/Volumes/stale/Reports", { open, fsp, checkMs: 20 }), "not-folder");+ answer();+ await new Promise((resolve) => setTimeout(resolve, 10));+ assert.deepEqual(opened, []);+ });});describe("openLogsFolder", () => {