import { statSync } from 'node:fs';
import { homedir } from 'node:os';
import { join, resolve } from 'node:path';
export function expandHomePath(p) {
    return p.startsWith('~') ? join(homedir(), p.slice(1)) : p;
}
export function parseWorkingDirList(value) {
    if (Array.isArray(value)) {
        return value
            .flatMap(v => parseWorkingDirList(v))
            .filter(Boolean);
    }
    if (typeof value !== 'string')
        return [];
    return value.split(',').map(s => s.trim()).filter(Boolean);
}
export function configuredWorkingDirs(input) {
    const dirs = [
        ...parseWorkingDirList(input.workingDir),
        ...parseWorkingDirList(input.workingDirs),
    ];
    const seen = new Set();
    return dirs.filter(dir => {
        const resolved = resolve(expandHomePath(dir));
        if (seen.has(resolved))
            return false;
        seen.add(resolved);
        return true;
    });
}
export function invalidWorkingDirs(input) {
    const invalid = [];
    for (const dir of configuredWorkingDirs(input)) {
        const resolved = resolve(expandHomePath(dir));
        try {
            if (!statSync(resolved).isDirectory())
                invalid.push(resolved);
        }
        catch {
            invalid.push(resolved);
        }
    }
    return invalid;
}
//# sourceMappingURL=working-dir.js.map