diff --git a/src/cli.ts b/src/cli.ts index 605bade..8969079 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,5 +1,6 @@ import { Command } from "commander"; import { assertNodeVersion } from "./utils/system.js"; +import { VERSION } from "./version.js"; import "./frameworks/definitions.js"; import { loadCustomFrameworks } from "./frameworks/custom.js"; import { runOnboard } from "./commands/onboard.js"; @@ -57,7 +58,7 @@ program .description( "Secure CLI platform for running AI agents in isolated Docker sandboxes", ) - .version("0.2.0", "-V, --version", "Print version") + .version(VERSION, "-V, --version", "Print version") .helpOption("-h, --help", "Show help"); // ── onboard ──────────────────────────────────────────────────────────────── diff --git a/src/commands/integrations.ts b/src/commands/integrations.ts index ced03cf..edd6ffe 100644 --- a/src/commands/integrations.ts +++ b/src/commands/integrations.ts @@ -18,6 +18,7 @@ import Table from "cli-table3"; import { readConfig, patchConfig } from "../config/manager.js"; import type { IntegrationConfig, IntegrationAuthType } from "../config/schema.js"; import { getTemplate, listTemplates } from "../integrations/templates.js"; +import { VERSION } from "../version.js"; import { log, section } from "../utils/logger.js"; // --------------------------------------------------------------------------- @@ -320,7 +321,7 @@ export async function runIntegrationsTest(name: string): Promise { method: "GET", timeout: 5000, headers: { - "user-agent": "SILO/0.2.0", + "user-agent": `SILO/${VERSION}`, }, }, (res) => { diff --git a/src/commands/onboard.ts b/src/commands/onboard.ts index 6d737d4..790b0f7 100644 --- a/src/commands/onboard.ts +++ b/src/commands/onboard.ts @@ -18,6 +18,7 @@ import { getPreset, } from "../policy/presets.js"; import type { Policy } from "../policy/engine.js"; +import { VERSION } from "../version.js"; // Default models per provider const DEFAULT_MODELS: Record = { @@ -193,7 +194,7 @@ async function animateWelcome(): Promise { } console.log(); - console.log(` ${chalk.bold.white("SILO")} ${chalk.cyan("v0.2.0")} ${chalk.dim("•")} ${chalk.white("Secure AI Agent Sandbox")}`); + console.log(` ${chalk.bold.white("SILO")} ${chalk.cyan(`v${VERSION}`)} ${chalk.dim("•")} ${chalk.white("Secure AI Agent Sandbox")}`); console.log(); // Play Star Wars style hyperspace jump animation under the logo @@ -206,7 +207,7 @@ async function animateWelcome(): Promise { console.log(" " + grad(line)); } console.log(); - console.log(` ${chalk.bold.white("SILO")} ${chalk.cyan("v0.2.0")} ${chalk.dim("•")} ${chalk.white("Secure AI Agent Sandbox")}`); + console.log(` ${chalk.bold.white("SILO")} ${chalk.cyan(`v${VERSION}`)} ${chalk.dim("•")} ${chalk.white("Secure AI Agent Sandbox")}`); console.log(); const os = `${platform()} ${arch()} (${release()})`; diff --git a/src/utils/logger.ts b/src/utils/logger.ts index 7c99549..073b5a4 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -1,5 +1,6 @@ import chalk from "chalk"; import boxen from "boxen"; +import { VERSION } from "../version.js"; const PREFIX = { info: chalk.cyan("ℹ"), @@ -39,7 +40,7 @@ export function printBanner(): void { const banner = boxen( chalk.bold.cyan("SILO") + " " + - chalk.dim("v0.2.0") + + chalk.dim(`v${VERSION}`) + "\n" + chalk.dim("Secure AI Agent Sandbox Orchestrator"), { diff --git a/src/version.ts b/src/version.ts new file mode 100644 index 0000000..94a9822 --- /dev/null +++ b/src/version.ts @@ -0,0 +1,14 @@ +/** + * The CLI version, read from package.json at runtime. + * + * `silo --version`, the banners, and the integration-test user-agent all use + * this, so a version bump in package.json is the only edit a release needs. + * `createRequire` resolves the path relative to this module, which works the + * same from src/ (tsx, vitest) and from the bundled files in dist/ — + * package.json sits one level up in both. + */ +import { createRequire } from "node:module"; + +const pkg = createRequire(import.meta.url)("../package.json") as { version: string }; + +export const VERSION: string = pkg.version; diff --git a/tests/version.test.ts b/tests/version.test.ts new file mode 100644 index 0000000..59cb540 --- /dev/null +++ b/tests/version.test.ts @@ -0,0 +1,16 @@ +import { describe, it, expect } from "vitest"; +import { readFileSync } from "node:fs"; +import { VERSION } from "../src/version.js"; + +describe("VERSION", () => { + it("matches the version in package.json", () => { + const pkg = JSON.parse( + readFileSync(new URL("../package.json", import.meta.url), "utf8"), + ) as { version: string }; + expect(VERSION).toBe(pkg.version); + }); + + it("is a semver string", () => { + expect(VERSION).toMatch(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/); + }); +});