/**
 * @module        paths
 * @description   项目与会话的文件路径解析
 *
 * @author        eddy
 * @organization  wykj
 * @ownership     wykj/eddy
 *
 * @created       2026-03-19
 * @updated       2026-04-03
 *
 * @role          config
 * @layer         core
 * @boundedContext project
 */
import { existsSync } from 'node:fs';
import { resolve } from 'node:path';
const HOME = process.env.HOME || '/home/coral';
export function resolveProjectPaths(projectName, overrides) {
    const instanceDir = resolve(HOME, '.coral', 'projects', projectName);
    const runtimeDir = resolve(instanceDir, 'runtime');
    const repoDir = overrides?.projectDir
        ? resolve(overrides.projectDir)
        : resolve(HOME, 'projects', projectName);
    const worktreeRoot = overrides?.worktreeDir
        ? resolve(overrides.worktreeDir, projectName)
        : resolve(HOME, '.coral', 'worktrees', projectName);
    return {
        instanceDir,
        confFile: resolve(instanceDir, 'conf'),
        logsDir: resolve(instanceDir, 'logs'),
        runtimeDir,
        stateFile: resolve(runtimeDir, 'state.json'),
        acpStateFile: resolve(runtimeDir, 'acp-state.json'),
        tickLockFile: resolve(runtimeDir, 'tick.lock'),
        pmMetaDir: resolve(instanceDir, 'pm_meta'),
        pipelineOrderFile: resolve(instanceDir, 'pipeline_order.json'),
        repoDir,
        worktreeRoot,
    };
}
export function resolveWorktreePath(projectName, seq, worktreeDir) {
    const root = worktreeDir
        ? resolve(worktreeDir, projectName)
        : resolve(HOME, '.coral', 'worktrees', projectName);
    return resolve(root, String(seq));
}
export function resolveSessionPaths() {
    const stateDir = resolve(HOME, '.coral', 'sessions');
    return {
        stateDir,
        logsDir: resolve(stateDir, 'logs'),
        stateFile: resolve(stateDir, 'state.json'),
    };
}
export function checkPathExists(path) {
    return existsSync(path);
}
//# sourceMappingURL=paths.js.map