import { homedir } from 'node:os'; import { isAbsolute, join, resolve } from 'node:path'; /** * The single canonical home for all VideoClaw projects: `~/videoclaw`. * Every project lives at `/projects//`. This is * the default workspace root for project creation, every project-reading * command, and Mission Control discovery — replacing the old per-invocation * `process.cwd()` default that scattered projects wherever `vclaw` happened to * run. */ export const CANONICAL_WORKSPACE_ROOT = join(homedir(), 'videoclaw'); /** Expand a leading `~/`, then make the path absolute. */ function expandWorkspacePath(p: string): string { if (p.startsWith('~/')) return join(homedir(), p.slice(2)); return isAbsolute(p) ? p : resolve(p); } /** * Resolve the workspace root from the environment alone (no CLI flags). * Precedence: `VCLAW_WORKSPACE` → `VIDEOCLAW_WORKSPACE` → the canonical home. * * Used as the default by library/test callers (workspace.ts, projects.ts) that * do not receive a `--root` flag; the arg-aware `resolveWorkspaceRoot` in * cli/args.ts layers explicit-flag precedence on top of this. A blank/whitespace * env value is ignored (falls through to the home), so an empty * `VCLAW_WORKSPACE=` never resolves projects to the filesystem root. */ export function resolveWorkspaceRootFromEnv(env: NodeJS.ProcessEnv = process.env): string { const raw = env.VCLAW_WORKSPACE ?? env.VIDEOCLAW_WORKSPACE; if (raw && raw.trim()) return expandWorkspacePath(raw.trim()); return CANONICAL_WORKSPACE_ROOT; }