/**
 * Read the CLI's version from the package.json that ships alongside
 * the bundled `dist/index.js`.
 *
 * Lives in its own module so callers other than the CLI's main entry
 * (e.g. `host-cp.ts buildComposeEnv` propagating the version into the
 * host-cp container) can read the same source of truth without
 * duplicating the lookup logic.
 *
 * Resolution: the bundle lives at `packages/cli/dist/index.js`; the
 * package.json is its sibling at `packages/cli/package.json`. We resolve
 * relative to `import.meta.url` so the lookup works whether the bundle
 * was loaded from a global install (npm) or a local checkout (tsx).
 */
import * as fs from 'node:fs';
import * as path from 'node:path';
import { fileURLToPath } from 'node:url';
export function readCliVersion() {
    try {
        const here = path.dirname(fileURLToPath(import.meta.url));
        // Walk up from dist/ to package root.
        for (const candidate of [
            path.join(here, 'package.json'),
            path.join(here, '..', 'package.json'),
            path.join(here, '..', '..', 'package.json'),
        ]) {
            if (fs.existsSync(candidate)) {
                const pkg = JSON.parse(fs.readFileSync(candidate, 'utf-8'));
                if (typeof pkg.version === 'string' && pkg.version.length > 0)
                    return pkg.version;
            }
        }
    }
    catch {
        // fall through
    }
    return '0.0.0-unknown';
}
//# sourceMappingURL=cli-version.js.map