From e803935b338ea0184e7e8c80ce34431f4eb54d3c Mon Sep 17 00:00:00 2001 From: Mikkel Georgsen Date: Mon, 30 Mar 2026 23:06:46 +0200 Subject: [PATCH] feat(02-02): add ~/.nexus pointer-file resolution to server and CLI home-paths - Add resolveNexusPointerFile() helper to server/src/home-paths.ts - Add resolveNexusPointerFile() helper to cli/src/config/home.ts - Patch resolvePaperclipHomeDir() in both files: ~/.nexus > PAPERCLIP_HOME > ~/.paperclip - Add import fs from node:fs to both files --- cli/src/config/home.ts | 23 +++++++++++++++++++++++ server/src/home-paths.ts | 19 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/cli/src/config/home.ts b/cli/src/config/home.ts index ef4d8e09..86b8a047 100644 --- a/cli/src/config/home.ts +++ b/cli/src/config/home.ts @@ -1,10 +1,33 @@ +import fs from "node:fs"; import os from "node:os"; import path from "node:path"; const DEFAULT_INSTANCE_ID = "default"; const INSTANCE_ID_RE = /^[a-zA-Z0-9_-]+$/; +// [nexus] Read ~/.nexus pointer file for custom home directory +function resolveNexusPointerFile(): string | null { + const pointerPath = path.resolve(os.homedir(), ".nexus"); + try { + const raw = fs.readFileSync(pointerPath, "utf-8").trim(); + if (raw.length > 0) { + // Inline tilde expansion (expandHomePrefix is defined later in this file) + const expanded = raw === "~" ? os.homedir() + : raw.startsWith("~/") ? path.resolve(os.homedir(), raw.slice(2)) + : raw; + return path.resolve(expanded); + } + } catch { + // ~/.nexus does not exist or is unreadable — fall through + } + return null; +} + export function resolvePaperclipHomeDir(): string { + // [nexus] Pointer-file: ~/.nexus overrides all other home resolution + const nexusRoot = resolveNexusPointerFile(); + if (nexusRoot) return nexusRoot; + const envHome = process.env.PAPERCLIP_HOME?.trim(); if (envHome) return path.resolve(expandHomePrefix(envHome)); return path.resolve(os.homedir(), ".paperclip"); diff --git a/server/src/home-paths.ts b/server/src/home-paths.ts index f1174bbb..714f7513 100644 --- a/server/src/home-paths.ts +++ b/server/src/home-paths.ts @@ -1,3 +1,4 @@ +import fs from "node:fs"; import os from "node:os"; import path from "node:path"; @@ -12,7 +13,25 @@ function expandHomePrefix(value: string): string { return value; } +// [nexus] Read ~/.nexus pointer file for custom home directory +function resolveNexusPointerFile(): string | null { + const pointerPath = path.resolve(os.homedir(), ".nexus"); + try { + const raw = fs.readFileSync(pointerPath, "utf-8").trim(); + if (raw.length > 0) { + return path.resolve(expandHomePrefix(raw)); + } + } catch { + // ~/.nexus does not exist or is unreadable — fall through + } + return null; +} + export function resolvePaperclipHomeDir(): string { + // [nexus] Pointer-file: ~/.nexus overrides all other home resolution + const nexusRoot = resolveNexusPointerFile(); + if (nexusRoot) return nexusRoot; + const envHome = process.env.PAPERCLIP_HOME?.trim(); if (envHome) return path.resolve(expandHomePrefix(envHome)); return path.resolve(os.homedir(), ".paperclip");