From 9906cf2e8812118cd01d2d634f127c3ec42e5f04 Mon Sep 17 00:00:00 2001 From: Anthony Ettinger Date: Sun, 30 Aug 2026 14:35:11 +0000 Subject: [PATCH] fix(cli): print the installed version in the banner, not a hardcoded v0.1.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `banner()` printed a literal "All-in-one security agent daemon — v0.1.0" on every command, so a box running 0.11.6 reported a version ten minors stale. That reads as a failed upgrade and sent us hunting for a stale install that was not there. Resolve the version once in `core/version.ts` by reading the package manifest next to the bundle, and use it in both the banner and `index.ts`, which had its own copy of the same lookup plus its own stale fallback literal ("0.1.8"). Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_018NXz7vRz6C7vaGSwMgWZfD --- apps/cli/src/core/__tests__/version.test.ts | 26 +++++++++++++++++++++ apps/cli/src/core/logger.ts | 3 ++- apps/cli/src/core/version.ts | 21 +++++++++++++++++ apps/cli/src/index.ts | 7 +----- 4 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 apps/cli/src/core/__tests__/version.test.ts create mode 100644 apps/cli/src/core/version.ts diff --git a/apps/cli/src/core/__tests__/version.test.ts b/apps/cli/src/core/__tests__/version.test.ts new file mode 100644 index 0000000..a07634e --- /dev/null +++ b/apps/cli/src/core/__tests__/version.test.ts @@ -0,0 +1,26 @@ +import { describe, expect, it, vi } from "vitest"; +import { banner } from "../logger.js"; +import { PKG_VERSION } from "../version.js"; + +describe("banner", () => { + // The bug this file exists for: the banner printed a hardcoded + // "v0.1.0" on every command, so a box running 0.11.6 reported a version + // ten minors stale and looked like a failed upgrade. + it("reports the resolved package version, not a literal", () => { + const lines: string[] = []; + const spy = vi.spyOn(console, "log").mockImplementation((...args) => { + lines.push(args.join(" ")); + }); + + try { + banner(); + } finally { + spy.mockRestore(); + } + + const versionLine = lines.find((l) => l.includes("All-in-one security agent daemon")); + expect(versionLine).toBeDefined(); + expect(versionLine).toContain(`v${PKG_VERSION}`); + expect(versionLine).not.toContain("v0.1.0"); + }); +}); diff --git a/apps/cli/src/core/logger.ts b/apps/cli/src/core/logger.ts index 169ca02..57fd7bd 100644 --- a/apps/cli/src/core/logger.ts +++ b/apps/cli/src/core/logger.ts @@ -1,5 +1,6 @@ import chalk from 'chalk'; import type { EventSeverity } from '../types/events.js'; +import { PKG_VERSION } from './version.js'; const SEVERITY_COLORS: Record string> = { info: chalk.green, @@ -58,5 +59,5 @@ export function banner(): void { ██║ ██║ ██║██║ ██║███████╗██║ ██║ ██║ ╚██████╗██║ ██║╚██████╔╝███████║██║ ██║ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ `)); - console.log(chalk.gray(' All-in-one security agent daemon — v0.1.0\n')); + console.log(chalk.gray(` All-in-one security agent daemon — v${PKG_VERSION}\n`)); } diff --git a/apps/cli/src/core/version.ts b/apps/cli/src/core/version.ts new file mode 100644 index 0000000..e40e744 --- /dev/null +++ b/apps/cli/src/core/version.ts @@ -0,0 +1,21 @@ +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; + +// The bundles live in `dist/`, which sits at the package root once published, +// so the manifest is always one level up from `__dirname`. Reading it keeps the +// version in one place: a hardcoded literal reports whatever it was written at, +// no matter which release is actually installed. +const FALLBACK_VERSION = '0.0.0'; + +function readPackageVersion(): string { + try { + const pkg = JSON.parse( + readFileSync(join(__dirname, '..', 'package.json'), 'utf-8'), + ) as { version?: string }; + return pkg.version || FALLBACK_VERSION; + } catch { + return FALLBACK_VERSION; + } +} + +export const PKG_VERSION = readPackageVersion(); diff --git a/apps/cli/src/index.ts b/apps/cli/src/index.ts index d864df1..11d6d7a 100644 --- a/apps/cli/src/index.ts +++ b/apps/cli/src/index.ts @@ -42,12 +42,7 @@ import { shadowedUpdateWarning, type PackageManager, } from "./upgrade.js"; - -let PKG_VERSION = "0.1.8"; -try { - const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8")); - PKG_VERSION = pkg.version; -} catch {} +import { PKG_VERSION } from "./core/version.js"; const LOGO = ` ${chalk.green(" ████████╗██╗ ██╗██████╗ ███████╗ █████╗ ████████╗")}