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
HTML agent-harnessagent-orchestrationagentsai-agentsautonomous-agentsclaude-codecodexcoding-agentsdesktop-appdeveloper-toolselectrongemini-cliharnessharness-engineeringlocal-firstmemorymulti-agentopencodeorchestrationtypescript
fix(config): expand ~ at the two seams a pre-fix config can still reach
Gastón Péchieu19646be87eca
diff --git a/src/main/config.ts b/src/main/config.tsindex d9c8b308..737bb115 100644--- a/src/main/config.ts+++ b/src/main/config.ts@@ -575,12 +575,35 @@ export function readConfig(): HarnessConfig {try {const raw = readFileSync(p, 'utf8');const parsed = JSON.parse(raw);- return migrateTriggersV1(withTriggerDefaults({ ...DEFAULTS, ...parsed }));+ return normalizeStoredHomes(migrateTriggersV1(withTriggerDefaults({ ...DEFAULTS, ...parsed })));} catch {return withTriggerDefaults({ ...DEFAULTS });}}+/** (#140, the upgrade path) A config.json persisted BEFORE `writeConfig`+ * learned to expand `~` still holds literal `~/…` strings in `harnessHome` /+ * `recentHives`, and nothing rewrites the file until the next write — so the+ * hive picker renders the raw `~` string and feeds it straight back into+ * `config:changeHome`, which lands on `resolve()` → `<cwd>/~/…`, a real+ * directory named "~". `normalizeHiveHome` only cleans values on the way IN;+ * this cleans them on the way OUT, so no consumer can see a `~` path+ * regardless of the file's vintage. Expanded duplicates collapse (a stale+ * "~/X" next to its absolute twin becomes one entry). */+function normalizeStoredHomes(cfg: HarnessConfig): HarnessConfig {+ if (typeof cfg.harnessHome === 'string' && cfg.harnessHome.trim()) {+ cfg.harnessHome = expandTilde(cfg.harnessHome);+ }+ if (Array.isArray(cfg.recentHives)) {+ const seen = new Set<string>();+ cfg.recentHives = cfg.recentHives+ .filter((h): h is string => typeof h === 'string' && !!h.trim())+ .map((h) => expandTilde(h))+ .filter((h) => (seen.has(h) ? false : (seen.add(h), true)));+ }+ return cfg;+}+function persistConfig(next: HarnessConfig): HarnessConfig {const p = configPath();mkdirSync(dirname(p), { recursive: true });diff --git a/src/main/index.ts b/src/main/index.tsindex a8d31534..5118f5ae 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -3037,8 +3037,11 @@ 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';- // A typed path may carry `~` (issue #140); bare resolve() would anchor it to- // the process cwd as a literal directory named `~`.+ // expandTilde BEFORE resolve: both UI callers feed a folder-dialog result+ // (always absolute), but the hive picker's recents list can serve a literal+ // "~/…" persisted by a pre-#140 build — resolve() would anchor that at cwd+ // and the app would relaunch against a real directory named "~". Same+ // defence-in-depth-at-the-consumer rule as expandTilde's own doc.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.cjsindex 0deeb836..251c13d9 100644--- a/test/harness-home-tilde.test.cjs+++ b/test/harness-home-tilde.test.cjs@@ -1,9 +1,12 @@'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.+ * #140 — onboarding died on `ENOENT: mkdir '~/HarnessAgents'`: the wizard lets+ * the user TYPE the harness-home path, and Node's mkdir/resolve treat `~` as a+ * literal directory name. The write-side seams expand it now, but a config.json+ * PERSISTED by a pre-fix build still holds literal `~/…` strings that nothing+ * rewrites — the hive picker then renders them and feeds them straight back+ * into config:changeHome. So readConfig normalizes on the way OUT too.*/const test = require('node:test');@@ -13,7 +16,37 @@ const os = require('node:os');const path = require('node:path');const loadTs = require('./load-ts.cjs');-const { ensureHarnessHome } = loadTs('src/main/config.ts');+// config.ts pulls `app` from electron for its userData path; outside Electron+// that resolve gives a path string, so seed the cache with the surface it+// touches — pointed at a temp dir this test owns.+const userData = fs.mkdtempSync(path.join(os.tmpdir(), 'md-tilde-'));+const electron = require.resolve('electron');+require.cache[electron] = {+ id: electron,+ filename: electron,+ loaded: true,+ exports: { app: { getPath: () => userData } }+};++const { ensureHarnessHome, readConfig } = loadTs('src/main/config.ts');++test.after(() => { fs.rmSync(userData, { recursive: true, force: true }); });++test('readConfig serves a pre-fix config with every ~ expanded (the upgrade path)', () => {+ const home = os.homedir();+ fs.writeFileSync(path.join(userData, 'config.json'), JSON.stringify({+ harnessHome: '~/HarnessAgents',+ // A stale tilde entry, its already-absolute twin, and an unrelated recent.+ recentHives: ['~/HarnessAgents', path.join(home, 'HarnessAgents'), '~/OtherHive']+ }));+ const cfg = readConfig();+ assert.equal(cfg.harnessHome, path.join(home, 'HarnessAgents'));+ assert.deepEqual(cfg.recentHives, [+ path.join(home, 'HarnessAgents'), // tilde + absolute twin collapse to one+ path.join(home, 'OtherHive')+ ]);+ assert.ok(!JSON.stringify(cfg.recentHives).includes('~'), 'no consumer ever sees a ~ path');+});test('ensureHarnessHome expands ~ before mkdir (issue #140)', () => {const rel = `.md-issue140-test-${process.pid}`;@@ -29,18 +62,6 @@ test('ensureHarnessHome expands ~ before mkdir (issue #140)', () => {}});-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-'));