From 61c67721acb4a44eeec3e3a3724333866fe4cfde Mon Sep 17 00:00:00 2001 From: Muhammad Hamza Date: Sat, 28 Feb 2026 22:35:37 +0500 Subject: [PATCH] Fix version command --- src/main.ts | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main.ts b/src/main.ts index 1bab78a..2c48bdb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,6 +16,25 @@ import { ui, ansi } from './ui/index.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); +// Read version before heavy imports so --version works without agentlang loaded +let packageVersion = '0.0.0'; +try { + const packagePath = join(__dirname, '..', 'package.json'); + const packageJson = JSON.parse(readFileSync(packagePath, 'utf-8')) as { version?: string }; + packageVersion = packageJson.version || '0.0.0'; +} catch { + // Fallback to default version +} + +// Early exit for --version/-V — intercepts before heavy agentlang imports +if (process.argv.includes('--version') || process.argv.includes('-V')) { + ui.row([ + { text: 'agent', bold: true, color: 'cyan' }, + { text: ` v${packageVersion}`, color: 'white' }, + ]); + process.exit(0); +} + let agPath = 'agentlang'; // Check if ./node_modules/agentlang exists in the current directory, add to agPath const nodeModulesPath = path.resolve(process.cwd(), 'node_modules/agentlang'); @@ -61,16 +80,6 @@ import { startStudio } from './studio.js'; import { OpenAPIClientAxios } from 'openapi-client-axios'; import { forkApp, type ForkOptions } from './utils/forkApp.js'; -// Read package.json for version -let packageVersion = '0.0.0'; -try { - const packagePath = join(__dirname, '..', 'package.json'); - const packageJson = JSON.parse(readFileSync(packagePath, 'utf-8')) as { version?: string }; - packageVersion = packageJson.version || '0.0.0'; -} catch { - // Fallback to a default version -} - export interface GenerateOptions { destination?: string; }