feat(cli): add client commands and home-based local runtime defaults

This commit is contained in:
Forgotten
2026-02-20 07:10:58 -06:00
parent 8e3c2fae35
commit 8f3fc077fa
40 changed files with 2284 additions and 138 deletions

View File

@@ -1,22 +1,24 @@
import fs from "node:fs";
import path from "node:path";
import { expandHomePrefix } from "../config/home.js";
function unique(items: string[]): string[] {
return Array.from(new Set(items));
}
export function resolveRuntimeLikePath(value: string, configPath?: string): string {
if (path.isAbsolute(value)) return value;
const expanded = expandHomePrefix(value);
if (path.isAbsolute(expanded)) return path.resolve(expanded);
const cwd = process.cwd();
const configDir = configPath ? path.dirname(configPath) : null;
const workspaceRoot = configDir ? path.resolve(configDir, "..") : cwd;
const candidates = unique([
path.resolve(workspaceRoot, "server", value),
path.resolve(workspaceRoot, value),
path.resolve(cwd, value),
...(configDir ? [path.resolve(configDir, value)] : []),
...(configDir ? [path.resolve(configDir, expanded)] : []),
path.resolve(workspaceRoot, "server", expanded),
path.resolve(workspaceRoot, expanded),
path.resolve(cwd, expanded),
]);
return candidates.find((candidate) => fs.existsSync(candidate)) ?? candidates[0];