fix: replace hardcoded /Users/user fallback with os.homedir()

The HOME_DIR fallback '/Users/user' is macOS-specific and incorrect.
Use os.homedir() from Node's os module which works cross-platform
and returns the actual home directory from /etc/passwd on Linux.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
vaibhav
2026-02-06 17:52:16 +05:30
committed by gavrielc
parent 9003259675
commit 6e22abb1ba
2 changed files with 4 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
import os from 'os';
import path from 'path';
import { readEnvFile } from './env.js';
@@ -19,7 +20,7 @@ export const SCHEDULER_POLL_INTERVAL = 60000;
// Absolute paths needed for container mounts
const PROJECT_ROOT = process.cwd();
const HOME_DIR = process.env.HOME || '/Users/user';
const HOME_DIR = process.env.HOME || os.homedir();
// Mount security: allowlist stored OUTSIDE project root, never mounted into containers
export const MOUNT_ALLOWLIST_PATH = path.join(

View File

@@ -7,6 +7,7 @@
* Allowlist location: ~/.config/nanoclaw/mount-allowlist.json
*/
import fs from 'fs';
import os from 'os';
import path from 'path';
import pino from 'pino';
@@ -121,7 +122,7 @@ export function loadMountAllowlist(): MountAllowlist | null {
* Expand ~ to home directory and resolve to absolute path
*/
function expandPath(p: string): string {
const homeDir = process.env.HOME || '/Users/user';
const homeDir = process.env.HOME || os.homedir();
if (p.startsWith('~/')) {
return path.join(homeDir, p.slice(2));
}