import { readFileSync } from 'node:fs';
import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = dirname(fileURLToPath(import.meta.url));
function readVersion() {
    try {
        const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8'));
        return pkg.version ?? '0.0.0';
    }
    catch {
        return '0.0.0';
    }
}
function readBuildInfo() {
    try {
        const raw = readFileSync(join(__dirname, 'build-info.json'), 'utf-8');
        const j = JSON.parse(raw);
        return {
            sha: typeof j.sha === 'string' ? j.sha : 'unknown',
            dirty: j.dirty === true,
            builtAt: typeof j.builtAt === 'string' ? j.builtAt : 'unknown',
        };
    }
    catch {
        // dev mode (tsx, no dist) or build-info.json missing.
        return { sha: 'dev', dirty: false, builtAt: 'dev' };
    }
}
export const VERSION = readVersion();
export const BUILD_INFO = readBuildInfo();
/** Short SHA + optional dirty marker for compact display. e.g. "ab12cd3" or
 *  "ab12cd3-dirty" or "dev". */
export function buildTag() {
    if (BUILD_INFO.sha === 'dev' || BUILD_INFO.sha === 'unknown')
        return BUILD_INFO.sha;
    const short = BUILD_INFO.sha.slice(0, 7);
    return BUILD_INFO.dirty ? `${short}-dirty` : short;
}
//# sourceMappingURL=version.js.map