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
This commit is contained in:
parent
78538a7390
commit
302b0d4ae7
2 changed files with 42 additions and 0 deletions
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue