openclaw/src/version.ts

99 lines
2.6 KiB
TypeScript
Raw Normal View History

import { createRequire } from "node:module";
2026-01-30 03:15:10 +01:00
declare const __OPENCLAW_VERSION__: string | undefined;
Ironclaw rebrand: rename user-facing strings, package identity, and CLI references Rebrand from OpenClaw to Ironclaw across 16 files: Web app (apps/web): - layout.tsx: update metadata title to "Ironclaw" and description to "AI CRM with an agent that connects to your apps and does the work for you" - page.tsx: change landing page heading from "OpenClaw Dench" to "Ironclaw" - agent-runner.ts: rename stderr log prefix to [ironclaw stderr] - package.json: rename package from "openclaw-web" to "ironclaw-web" Package identity (root): - package.json: rename package from "openclaw-ai-sdk" to "ironclaw", update description to reflect CRM/workspace focus, change bin entry from "openclaw-ai-sdk" to "ironclaw" - openclaw.mjs: update error message to reference "ironclaw" - src/version.ts: change CORE_PACKAGE_NAME to "ironclaw" CLI and TUI: - command-format.ts: extend CLI prefix regex to accept both "ironclaw" and "openclaw" for backward compatibility - register.agent.ts: update example identity name to "Ironclaw" with 🔩 emoji (replacing 🦞) - tui.ts: rename TUI header from "openclaw tui" to "ironclaw tui" Onboarding and configuration wizards: - configure.wizard.ts: rename engine selection prompts and wizard intro headers to "Ironclaw" - onboarding.ts: rename onboarding intro and security warning text - onboarding.finalize.ts: rename all dashboard/control-UI messages and Brave Search setup instructions to reference "Ironclaw" Security audit: - audit.ts: rename state-dir permission warning details to "Ironclaw" - audit-extra.ts: rename plugin remediation text to "Ironclaw" Telegram: - bot-message-context.ts: rename access-denied message to "Ironclaw"
2026-02-11 23:38:34 -08:00
const CORE_PACKAGE_NAME = "ironclaw";
const PACKAGE_JSON_CANDIDATES = [
"../package.json",
"../../package.json",
"../../../package.json",
"./package.json",
] as const;
const BUILD_INFO_CANDIDATES = [
"../build-info.json",
"../../build-info.json",
"./build-info.json",
] as const;
function readVersionFromJsonCandidates(
moduleUrl: string,
candidates: readonly string[],
opts: { requirePackageName?: boolean } = {},
): string | null {
try {
const require = createRequire(moduleUrl);
for (const candidate of candidates) {
try {
const parsed = require(candidate) as { name?: string; version?: string };
const version = parsed.version?.trim();
if (!version) {
continue;
}
if (opts.requirePackageName && parsed.name !== CORE_PACKAGE_NAME) {
continue;
}
return version;
} catch {
// ignore missing or unreadable candidate
}
}
return null;
} catch {
return null;
}
}
function firstNonEmpty(...values: Array<string | undefined>): string | undefined {
for (const value of values) {
const trimmed = value?.trim();
if (trimmed) {
return trimmed;
}
}
return undefined;
}
export function readVersionFromPackageJsonForModuleUrl(moduleUrl: string): string | null {
return readVersionFromJsonCandidates(moduleUrl, PACKAGE_JSON_CANDIDATES, {
requirePackageName: true,
});
}
export function readVersionFromBuildInfoForModuleUrl(moduleUrl: string): string | null {
return readVersionFromJsonCandidates(moduleUrl, BUILD_INFO_CANDIDATES);
}
export function resolveVersionFromModuleUrl(moduleUrl: string): string | null {
return (
readVersionFromPackageJsonForModuleUrl(moduleUrl) ||
readVersionFromBuildInfoForModuleUrl(moduleUrl)
);
}
export type RuntimeVersionEnv = {
[key: string]: string | undefined;
};
export function resolveRuntimeServiceVersion(
env: RuntimeVersionEnv = process.env as RuntimeVersionEnv,
fallback = "dev",
): string {
return (
firstNonEmpty(
env["OPENCLAW_VERSION"],
env["OPENCLAW_SERVICE_VERSION"],
env["npm_package_version"],
) ?? fallback
);
}
2026-01-30 03:15:10 +01:00
// Single source of truth for the current OpenClaw version.
// - Embedded/bundled builds: injected define or env var.
// - Dev/npm builds: package.json.
export const VERSION =
2026-01-30 03:15:10 +01:00
(typeof __OPENCLAW_VERSION__ === "string" && __OPENCLAW_VERSION__) ||
process.env.OPENCLAW_BUNDLED_VERSION ||
resolveVersionFromModuleUrl(import.meta.url) ||
"0.0.0";