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(config): expand ~ in the harness-home path before mkdir and persist (#140)

Gastón Péchieu0ca0e8dbaf45
diff --git a/package.json b/package.json
index 8dc851de..3261242d 100644
--- a/package.json
+++ b/package.json
@@ -19,7 +19,7 @@
"typecheck:node": "tsc --noEmit -p tsconfig.node.json",
"typecheck:web": "tsc --noEmit -p tsconfig.web.json",
"typecheck": "npm run typecheck:node && npm run typecheck:web",
- "test:focused": "node --test test/codex-remote.test.cjs test/control.test.cjs test/provider-automation.test.cjs test/provider-config.test.cjs test/queue-delivery.test.cjs test/terminal-automation.test.cjs test/terminal-recovery.test.cjs test/roster.test.cjs test/proc-kill.test.cjs test/expand-tilde.test.cjs test/hive-cwd.test.cjs test/hive-hook-node.test.cjs test/hive-roster-injection.test.cjs test/hive-runtime-path.test.cjs test/cli-install-ladder.test.cjs test/node-install.test.cjs test/office-gl-recovery.test.cjs test/update-state.test.cjs test/transcript-project-dir.test.cjs test/commit-graph.test.cjs",
+ "test:focused": "node --test test/codex-remote.test.cjs test/control.test.cjs test/provider-automation.test.cjs test/provider-config.test.cjs test/queue-delivery.test.cjs test/terminal-automation.test.cjs test/terminal-recovery.test.cjs test/roster.test.cjs test/proc-kill.test.cjs test/expand-tilde.test.cjs test/hive-cwd.test.cjs test/hive-hook-node.test.cjs test/hive-roster-injection.test.cjs test/hive-runtime-path.test.cjs test/cli-install-ladder.test.cjs test/node-install.test.cjs test/office-gl-recovery.test.cjs test/update-state.test.cjs test/transcript-project-dir.test.cjs test/commit-graph.test.cjs test/harness-home-tilde.test.cjs",
"check:links": "node tools/check-release-links.cjs",
"dist": "npm run build && electron-builder",
"dist:mac": "npm run build && electron-builder --mac",
diff --git a/src/main/config.ts b/src/main/config.ts
index f2d5292b..3cb8e025 100644
--- a/src/main/config.ts
+++ b/src/main/config.ts
@@ -600,12 +600,19 @@ export function writeConfig(patch: Partial<HarnessConfig>): HarnessConfig {
.map((r) => expandTilde(r))
.filter((r) => r && !seen.has(r) && (seen.add(r), true));
}
- // Track recently-opened hive homes so the launch picker can list them. Any write
- // that SETS harnessHome (onboarding finish, changeHome) promotes it to the front,
- // deduped and capped. Skips empty/null so a clear doesn't pollute the list.
+ // Home INGESTION — same rule as registeredRepos above: onboarding lets the
+ // user TYPE this path ("~/HarnessAgents"), and every derived path (hive root,
+ // palace, roster) joins on the persisted value, so a literal `~` breaks them
+ // all (issue #140: onboarding finish died on `ENOENT: mkdir '~/HarnessAgents'`).
if (typeof patch.harnessHome === 'string' && patch.harnessHome) {
+ const home = expandTilde(patch.harnessHome);
+ next.harnessHome = home;
+ // Track recently-opened hive homes so the launch picker can list them. Any
+ // write that SETS harnessHome (onboarding finish, changeHome) promotes it to
+ // the front, deduped and capped. Skips empty/null so a clear doesn't pollute
+ // the list.
const prior = current.recentHives ?? [];
- next.recentHives = [patch.harnessHome, ...prior.filter((h) => h !== patch.harnessHome)].slice(0, 8);
+ next.recentHives = [home, ...prior.filter((h) => h !== home)].slice(0, 8);
}
return persistConfig(next);
}
@@ -671,10 +678,12 @@ export function commandForAutoMode(
return flag ? `${base} ${flag}` : base;
}
-/** Ensure harnessHome exists on disk. */
+/** Ensure harnessHome exists on disk. Expands `~` first — the onboarding wizard
+ * lets the user type the path, and mkdir treats a literal `~` as a plain
+ * directory name (issue #140's `ENOENT: mkdir '~/HarnessAgents'`). */
export function ensureHarnessHome(path: string): { ok: boolean; error?: string } {
try {
- mkdirSync(path, { recursive: true });
+ mkdirSync(expandTilde(path), { recursive: true });
return { ok: true };
} catch (e) {
return { ok: false, error: e instanceof Error ? e.message : String(e) };
diff --git a/src/main/index.ts b/src/main/index.ts
index cb30da18..3ad17c3d 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -2876,7 +2876,9 @@ ipcMain.handle('config:changeHome', async (_evt, payload: unknown) => {
const p = (payload ?? {}) as { newHome?: unknown; mode?: unknown };
if (typeof p.newHome !== 'string' || !p.newHome) return { ok: false, error: 'invalid newHome' };
const mode: 'move' | 'fresh' = p.mode === 'fresh' ? 'fresh' : 'move';
- const newHome = resolve(p.newHome);
+ // A typed path may carry `~` (issue #140); bare resolve() would anchor it to
+ // the process cwd as a literal directory named `~`.
+ const newHome = resolve(expandTilde(p.newHome));
const oldRaw = readConfig().harnessHome;
const oldHome = oldRaw ? resolve(oldRaw) : null;
diff --git a/test/harness-home-tilde.test.cjs b/test/harness-home-tilde.test.cjs
new file mode 100644
index 00000000..0deeb836
--- /dev/null
+++ b/test/harness-home-tilde.test.cjs
@@ -0,0 +1,56 @@
+'use strict';
+
+/**
+ * #140 — onboarding died on `ENOENT: mkdir '~/HarnessAgents'`. The wizard lets
+ * the user TYPE the harness-home path, and Node's mkdir treats `~` as a literal
+ * directory name. ensureHarnessHome must expand it before touching the disk.
+ */
+
+const test = require('node:test');
+const assert = require('node:assert/strict');
+const fs = require('node:fs');
+const os = require('node:os');
+const path = require('node:path');
+const loadTs = require('./load-ts.cjs');
+
+const { ensureHarnessHome } = loadTs('src/main/config.ts');
+
+test('ensureHarnessHome expands ~ before mkdir (issue #140)', () => {
+ const rel = `.md-issue140-test-${process.pid}`;
+ const target = path.join(os.homedir(), rel);
+ const literalTilde = path.join(process.cwd(), '~');
+ try {
+ const res = ensureHarnessHome(`~/${rel}`);
+ assert.equal(res.ok, true, res.error);
+ assert.ok(fs.existsSync(target), 'created under the real home directory');
+ assert.ok(!fs.existsSync(literalTilde), 'no literal "~" directory appeared in cwd');
+ } finally {
+ fs.rmSync(target, { recursive: true, force: true });
+ }
+});
+
+test('an absolute path still works exactly as before', () => {
+ const target = fs.mkdtempSync(path.join(os.tmpdir(), 'md-home-'));
+ const inner = path.join(target, 'nested', 'home');
+ try {
+ const res = ensureHarnessHome(inner);
+ assert.equal(res.ok, true, res.error);
+ assert.ok(fs.existsSync(inner));
+ } finally {
+ fs.rmSync(target, { recursive: true, force: true });
+ }
+});
+
+test('a failing mkdir still reports ok:false with the error', () => {
+ // A path THROUGH a regular file cannot be created.
+ const target = fs.mkdtempSync(path.join(os.tmpdir(), 'md-home-'));
+ const file = path.join(target, 'plain-file');
+ fs.writeFileSync(file, 'x');
+ try {
+ const res = ensureHarnessHome(path.join(file, 'child'));
+ assert.equal(res.ok, false);
+ assert.ok(res.error && res.error.length > 0);
+ } finally {
+ fs.rmSync(target, { recursive: true, force: true });
+ }
+});