From 49c35c752cfd8cc0d1e4fb75d5efbee58c2fc489 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 17 Jan 2026 12:30:11 +0000 Subject: [PATCH] fix: stamp build commit metadata --- CHANGELOG.md | 7 +++++- package.json | 4 ++-- scripts/write-build-info.ts | 48 +++++++++++++++++++++++++++++++++++++ src/infra/git-commit.ts | 17 +++++++++++++ 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 scripts/write-build-info.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index ea51e7503..b20fb074e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ Docs: https://docs.clawd.bot +## 2026.1.16-2 + +### Changes +- CLI: stamp build commit into dist metadata so banners show the commit in npm installs. + ## 2026.1.16-1 ### Highlights @@ -9,7 +14,7 @@ Docs: https://docs.clawd.bot - Media: add inbound media understanding (image/audio/video) with provider + CLI fallbacks. https://docs.clawd.bot/nodes/media-understanding - Plugins: add Zalo Personal plugin (`@clawdbot/zalouser`) and unify channel directory for plugins. (#1032) — thanks @suminhthanh. https://docs.clawd.bot/plugins/zalouser - Models: add Vercel AI Gateway auth choice + onboarding updates. (#1016) — thanks @timolins. https://docs.clawd.bot/providers/vercel-ai-gateway -- Sessions: add `session.identityLinks` for cross-platform DM session linking. (#1033) — thanks @thewilloftheshadow. https://docs.clawd.bot/concepts/session +- Sessions: add `session.identityLinks` for cross-platform DM session li nking. (#1033) — thanks @thewilloftheshadow. https://docs.clawd.bot/concepts/session - Web search: add `country`/`language` parameters (schema + Brave API) and docs. (#1046) — thanks @YuriNachos. https://docs.clawd.bot/tools/web ### Breaking diff --git a/package.json b/package.json index cbd3939fe..90ab992a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "clawdbot", - "version": "2026.1.16-1", + "version": "2026.1.16-2", "description": "WhatsApp gateway CLI (Baileys web) with Pi RPC agent", "type": "module", "main": "dist/index.js", @@ -66,7 +66,7 @@ "docs:bin": "bun build scripts/docs-list.ts --compile --outfile bin/docs-list", "docs:dev": "cd docs && mint dev", "docs:build": "cd docs && pnpm dlx --reporter append-only mint broken-links", - "build": "tsc -p tsconfig.json && tsx scripts/canvas-a2ui-copy.ts && tsx scripts/copy-hook-metadata.ts", + "build": "tsc -p tsconfig.json && tsx scripts/canvas-a2ui-copy.ts && tsx scripts/copy-hook-metadata.ts && tsx scripts/write-build-info.ts", "plugins:sync": "tsx scripts/sync-plugin-versions.ts", "release:check": "tsx scripts/release-check.ts", "ui:install": "node scripts/ui.js install", diff --git a/scripts/write-build-info.ts b/scripts/write-build-info.ts new file mode 100644 index 000000000..28b3499bc --- /dev/null +++ b/scripts/write-build-info.ts @@ -0,0 +1,48 @@ +import { execSync } from "node:child_process"; +import fs from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); +const distDir = path.join(rootDir, "dist"); +const pkgPath = path.join(rootDir, "package.json"); + +const readPackageVersion = () => { + try { + const raw = fs.readFileSync(pkgPath, "utf8"); + const parsed = JSON.parse(raw) as { version?: string }; + return parsed.version ?? null; + } catch { + return null; + } +}; + +const resolveCommit = () => { + const envCommit = process.env.GIT_COMMIT?.trim() || process.env.GIT_SHA?.trim(); + if (envCommit) return envCommit; + try { + return execSync("git rev-parse HEAD", { + cwd: rootDir, + stdio: ["ignore", "pipe", "ignore"], + }) + .toString() + .trim(); + } catch { + return null; + } +}; + +const version = readPackageVersion(); +const commit = resolveCommit(); + +const buildInfo = { + version, + commit, + builtAt: new Date().toISOString(), +}; + +fs.mkdirSync(distDir, { recursive: true }); +fs.writeFileSync( + path.join(distDir, "build-info.json"), + `${JSON.stringify(buildInfo, null, 2)}\n`, +); diff --git a/src/infra/git-commit.ts b/src/infra/git-commit.ts index b74499759..da351f17f 100644 --- a/src/infra/git-commit.ts +++ b/src/infra/git-commit.ts @@ -51,6 +51,18 @@ const readCommitFromPackageJson = () => { } }; +const readCommitFromBuildInfo = () => { + try { + const require = createRequire(import.meta.url); + const info = require("../build-info.json") as { + commit?: string | null; + }; + return formatCommit(info.commit ?? null); + } catch { + return null; + } +}; + export const resolveCommitHash = (options: { cwd?: string; env?: NodeJS.ProcessEnv } = {}) => { if (cachedCommit !== undefined) return cachedCommit; const env = options.env ?? process.env; @@ -60,6 +72,11 @@ export const resolveCommitHash = (options: { cwd?: string; env?: NodeJS.ProcessE cachedCommit = normalized; return cachedCommit; } + const buildInfoCommit = readCommitFromBuildInfo(); + if (buildInfoCommit) { + cachedCommit = buildInfoCommit; + return cachedCommit; + } const pkgCommit = readCommitFromPackageJson(); if (pkgCommit) { cachedCommit = pkgCommit;