Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

fix(fs): use expandTilde in statAbs for cross-platform path resolution

kdahal7228efaeb79ab
diff --git a/src/main/fs.ts b/src/main/fs.ts
index 1cc6f98c..327f76b5 100644
--- a/src/main/fs.ts
+++ b/src/main/fs.ts
@@ -218,9 +218,8 @@ export function normalizeHiveHome(
* the home dir). Read-only metadata: returns whether a regular file exists and
* the normalized absolute path; never file contents. */
export async function statAbs(p: string): Promise<{ exists: boolean; isFile: boolean; path: string }> {
- let abs = p.startsWith('~/') ? join(homedir(), p.slice(2)) : p;
+ const abs = expandTilde(p);
if (!isAbsolute(abs)) return { exists: false, isFile: false, path: p };
- abs = normalize(abs);
try {
const s = await stat(abs);
return { exists: true, isFile: s.isFile(), path: abs };
diff --git a/test/expand-tilde.test.cjs b/test/expand-tilde.test.cjs
index f818b0fc..278f0592 100644
--- a/test/expand-tilde.test.cjs
+++ b/test/expand-tilde.test.cjs
@@ -13,7 +13,7 @@ const os = require('node:os');
const path = require('node:path');
const loadTs = require('./load-ts.cjs');
-const { expandTilde } = loadTs('src/main/fs.ts');
+const { expandTilde, statAbs } = loadTs('src/main/fs.ts');
const HOME = os.homedir();
@@ -121,3 +121,24 @@ test('#140: both entry points agree on the same directory', () => {
const typed = '~/HarnessAgents';
assert.equal(expandTilde(typed), normalizeHiveHome(typed).home);
});
+
+test('statAbs expands bare ~, Windows-style ~\\, and whitespace paths', async () => {
+ const fileBasename = `.md-statabs-${process.pid}`;
+ const inHome = path.join(HOME, fileBasename);
+ fs.writeFileSync(inHome, 'x');
+ try {
+ const resSlash = await statAbs(`~/${fileBasename}`);
+ assert.equal(resSlash.exists, true);
+ assert.equal(resSlash.isFile, true);
+
+ const resWin = await statAbs(`~\\${fileBasename}`);
+ assert.equal(resWin.exists, true);
+ assert.equal(resWin.isFile, true);
+
+ const resPadded = await statAbs(` ~/${fileBasename} `);
+ assert.equal(resPadded.exists, true);
+ assert.equal(resPadded.isFile, true);
+ } finally {
+ fs.rmSync(inHome, { force: true });
+ }
+});