Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

1.1 KB
Raw Blame
import os from "os";
import path from "path";

export function homeDir(): string {
  return os.homedir();
}

function expandHome(p: string): string {
  if (p === "~") return homeDir();
  if (p.startsWith("~/") || p.startsWith("~\\")) return path.join(homeDir(), p.slice(2));
  return p;
}

export function parseRootEnv(raw: string, delimiter = path.delimiter): string[] {
  return raw.split(delimiter).map((entry) => entry.trim()).filter(Boolean).map(expandHome);
}

function rootsFromEnv(name: string, fallback: string[]): string[] {
  const env = process.env[name];
  return env && env.trim() ? parseRootEnv(env) : fallback;
}

export function readRootList(): string[] {
  const h = homeDir();
  return rootsFromEnv("OS_FS_READ_ROOTS", [process.cwd(), path.join(h, "projects")]);
}

export function writeRootList(): string[] {
  const h = homeDir();
  return rootsFromEnv("OS_FS_WRITE_ROOTS", [h, path.join(h, "projects")]);
}

export function isUnderRoot(target: string, root: string): boolean {
  const rel = path.relative(root, target);
  return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
}