diff --git a/.changeset/fix-cli-version.md b/.changeset/fix-cli-version.md new file mode 100644 index 0000000..97be2e7 --- /dev/null +++ b/.changeset/fix-cli-version.md @@ -0,0 +1,5 @@ +--- +"@promptc/cli": patch +--- + +Report the CLI package version from package.json instead of a stale hard-coded value. diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 3c4ac09..2614494 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -23,6 +23,7 @@ // 3 pass precondition failure (an explicitly-requested pass refused to run) import { parseArgs } from "node:util"; +import { readFileSync } from "node:fs"; import { validateIR, type SourceFormat } from "@promptc/ir"; import { codegen } from "@promptc/codegen"; @@ -30,7 +31,13 @@ import { runPipeline, type PassRecord, listAllPasses } from "./pipeline.js"; import { parseSource } from "./parse.js"; import { tokenCount } from "./tokens.js"; -const VERSION = "0.0.1"; +const VERSION = readPackageVersion(); + +function readPackageVersion(): string { + const packageJsonUrl = new URL("../package.json", import.meta.url); + const packageJson = JSON.parse(readFileSync(packageJsonUrl, "utf8")) as { version?: string }; + return packageJson.version ?? "0.0.0"; +} interface OptimizeFlags { target: "cost" | "tokens" | "none"; @@ -732,4 +739,3 @@ See docs/PASSES.md for per-pass preconditions, postconditions, and behavior-preservation arguments. `); } -