diff --git a/src/cli/index.ts b/src/cli/index.ts index f67a8e1..cb87b95 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -11,11 +11,12 @@ import { program } from "commander"; import { registerCommands } from "./commands/index.js"; +import { VERSION } from "./version.js"; program .name("trail") .description("Leave a trail of your work for others to follow") - .version("0.1.0") + .version(VERSION) .option( "--data-dir ", "Override trajectory storage directory (or set TRAJECTORIES_DATA_DIR)", diff --git a/src/cli/runner.ts b/src/cli/runner.ts index 49ee75e..909b217 100644 --- a/src/cli/runner.ts +++ b/src/cli/runner.ts @@ -6,6 +6,7 @@ import { Command } from "commander"; import { registerCommands } from "./commands/index.js"; +import { VERSION } from "./version.js"; export interface CommandResult { success: boolean; @@ -37,7 +38,7 @@ export async function runCommand(args: string[]): Promise { program .name("traj") .description("Capture the complete train of thought of agent work") - .version("0.1.0") + .version(VERSION) .exitOverride() // Don't exit process on error .configureOutput({ writeOut: (str) => { diff --git a/src/cli/version.ts b/src/cli/version.ts new file mode 100644 index 0000000..d8304ba --- /dev/null +++ b/src/cli/version.ts @@ -0,0 +1,30 @@ +import fs from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +function findPackageJson(startDir: string): string { + let dir = startDir; + while (dir !== path.dirname(dir)) { + const candidate = path.join(dir, "package.json"); + if (fs.existsSync(candidate)) { + return candidate; + } + dir = path.dirname(dir); + } + throw new Error("Could not find package.json"); +} + +function resolveCliVersion(): string { + try { + const here = path.dirname(fileURLToPath(import.meta.url)); + const packageJsonPath = findPackageJson(here); + const packageJson = JSON.parse( + fs.readFileSync(packageJsonPath, "utf-8"), + ) as { version?: string }; + return packageJson.version ?? "unknown"; + } catch { + return "unknown"; + } +} + +export const VERSION = resolveCliVersion();