import { readFileSync } from 'node:fs'; /** Read the installed package version so the CLI output cannot drift from package.json. */ export function getCliVersion(): string { const packageJsonUrl = new URL('../package.json', import.meta.url); const packageJson: unknown = JSON.parse(readFileSync(packageJsonUrl, 'utf8')); if ( typeof packageJson === 'object' && packageJson !== null && 'version' in packageJson && typeof packageJson.version === 'string' ) { return packageJson.version; } throw new Error('Unable to determine CLI version from package.json'); }