Skip to content

Commit ca5e352

Browse files
altaywtfechoVicechoVic
authored
CLI: include commit hash in --version output (#39712)
* CLI: include commit hash in --version output * fix(version): harden commit SHA resolution and keep output consistent * CLI: keep install checks compatible with commit-tagged version output * fix(cli): include commit hash in root version fast path * test(cli): allow null commit-hash mocks * Installer: share version parser across install scripts * Installer: avoid sourcing helpers from stdin cwd * CLI: note commit-tagged version output * CLI: anchor commit hash resolution to module root * CLI: harden commit hash resolution * CLI: fix commit hash lookup edge cases * CLI: prefer live git metadata in dev builds * CLI: keep git lookup inside package root * Infra: tolerate invalid moduleUrl hints * CLI: cache baked commit metadata fallbacks * CLI: align changelog attribution with prep gate * CLI: restore changelog contributor credit --------- Co-authored-by: echoVic <[email protected]> Co-authored-by: echoVic <[email protected]>
1 parent c942655 commit ca5e352

File tree

19 files changed

+903
-42
lines changed

19 files changed

+903
-42
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Docs: https://docs.openclaw.ai
99
- TUI: infer the active agent from the current workspace when launched inside a configured agent workspace, while preserving explicit `agent:` session targets. (#39591) thanks @arceus77-7.
1010
- Tools/Brave web search: add opt-in `tools.web.search.brave.mode: "llm-context"` so `web_search` can call Brave's LLM Context endpoint and return extracted grounding snippets with source metadata, plus config/docs/test coverage. (#33383) Thanks @thirumaleshp.
1111
- Talk mode: add top-level `talk.silenceTimeoutMs` config so Talk waits a configurable amount of silence before auto-sending the current transcript, while keeping each platform's existing default pause window when unset. (#39607) Thanks @danodoesdesign. Fixes #17147.
12+
- CLI/install: include the short git commit hash in `openclaw --version` output when metadata is available, and keep installer version checks compatible with the decorated format. (#39712) thanks @sourman.
1213

1314
### Fixes
1415

scripts/docker/install-sh-common/cli-verify.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/usr/bin/env bash
22

3+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4+
# shellcheck source=./version-parse.sh
5+
source "$SCRIPT_DIR/version-parse.sh"
6+
37
verify_installed_cli() {
48
local package_name="$1"
59
local expected_version="$2"
@@ -32,6 +36,8 @@ verify_installed_cli() {
3236
installed_version="$(node "$entry_path" --version 2>/dev/null | head -n 1 | tr -d '\r')"
3337
fi
3438

39+
installed_version="$(extract_openclaw_semver "$installed_version")"
40+
3541
echo "cli=$cli_name installed=$installed_version expected=$expected_version"
3642
if [[ "$installed_version" != "$expected_version" ]]; then
3743
echo "ERROR: expected ${cli_name}@${expected_version}, got ${cli_name}@${installed_version}" >&2
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
extract_openclaw_semver() {
4+
local raw="${1:-}"
5+
local parsed=""
6+
parsed="$(
7+
printf '%s\n' "$raw" \
8+
| tr -d '\r' \
9+
| grep -Eo 'v?[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z]+(\.[0-9A-Za-z]+)*)?(\+[0-9A-Za-z.-]+)?' \
10+
| head -n 1 \
11+
|| true
12+
)"
13+
printf '%s' "${parsed#v}"
14+
}

scripts/docker/install-sh-e2e/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ RUN apt-get update \
88
git \
99
&& rm -rf /var/lib/apt/lists/*
1010

11+
COPY install-sh-common/version-parse.sh /usr/local/install-sh-common/version-parse.sh
1112
COPY run.sh /usr/local/bin/openclaw-install-e2e
1213
RUN chmod +x /usr/local/bin/openclaw-install-e2e
1314

scripts/docker/install-sh-e2e/run.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
VERIFY_HELPER_PATH="/usr/local/install-sh-common/version-parse.sh"
6+
if [[ ! -f "$VERIFY_HELPER_PATH" ]]; then
7+
VERIFY_HELPER_PATH="${SCRIPT_DIR}/../install-sh-common/version-parse.sh"
8+
fi
9+
# shellcheck source=../install-sh-common/version-parse.sh
10+
source "$VERIFY_HELPER_PATH"
11+
412
INSTALL_URL="${OPENCLAW_INSTALL_URL:-${CLAWDBOT_INSTALL_URL:-https://openclaw.bot/install.sh}}"
513
MODELS_MODE="${OPENCLAW_E2E_MODELS:-${CLAWDBOT_E2E_MODELS:-both}}" # both|openai|anthropic
614
INSTALL_TAG="${OPENCLAW_INSTALL_TAG:-${CLAWDBOT_INSTALL_TAG:-latest}}"
@@ -69,6 +77,7 @@ fi
6977

7078
echo "==> Verify installed version"
7179
INSTALLED_VERSION="$(openclaw --version 2>/dev/null | head -n 1 | tr -d '\r')"
80+
INSTALLED_VERSION="$(extract_openclaw_semver "$INSTALLED_VERSION")"
7281
echo "installed=$INSTALLED_VERSION expected=$EXPECTED_VERSION"
7382
if [[ "$INSTALLED_VERSION" != "$EXPECTED_VERSION" ]]; then
7483
echo "ERROR: expected openclaw@$EXPECTED_VERSION, got openclaw@$INSTALLED_VERSION" >&2

scripts/docker/install-sh-nonroot/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ ENV NPM_CONFIG_FUND=false
2727
ENV NPM_CONFIG_AUDIT=false
2828

2929
COPY install-sh-common/cli-verify.sh /usr/local/install-sh-common/cli-verify.sh
30+
COPY install-sh-common/version-parse.sh /usr/local/install-sh-common/version-parse.sh
3031
COPY install-sh-nonroot/run.sh /usr/local/bin/openclaw-install-nonroot
3132
RUN sudo chmod +x /usr/local/bin/openclaw-install-nonroot
3233

scripts/docker/install-sh-smoke/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ RUN set -eux; \
1919
&& rm -rf /var/lib/apt/lists/*
2020

2121
COPY install-sh-common/cli-verify.sh /usr/local/install-sh-common/cli-verify.sh
22+
COPY install-sh-common/version-parse.sh /usr/local/install-sh-common/version-parse.sh
2223
COPY install-sh-smoke/run.sh /usr/local/bin/openclaw-install-smoke
2324
RUN chmod +x /usr/local/bin/openclaw-install-smoke
2425

scripts/install.sh

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2085,14 +2085,52 @@ run_bootstrap_onboarding_if_needed() {
20852085
}
20862086
}
20872087

2088+
load_install_version_helpers() {
2089+
local source_path="${BASH_SOURCE[0]-}"
2090+
local script_dir=""
2091+
local helper_path=""
2092+
if [[ -z "$source_path" || ! -f "$source_path" ]]; then
2093+
return 0
2094+
fi
2095+
script_dir="$(cd "$(dirname "$source_path")" && pwd 2>/dev/null || true)"
2096+
helper_path="${script_dir}/docker/install-sh-common/version-parse.sh"
2097+
if [[ -n "$script_dir" && -r "$helper_path" ]]; then
2098+
# shellcheck source=docker/install-sh-common/version-parse.sh
2099+
source "$helper_path"
2100+
fi
2101+
}
2102+
2103+
load_install_version_helpers
2104+
2105+
if ! declare -F extract_openclaw_semver >/dev/null 2>&1; then
2106+
# Inline fallback when version-parse.sh could not be sourced (for example, stdin install).
2107+
extract_openclaw_semver() {
2108+
local raw="${1:-}"
2109+
local parsed=""
2110+
parsed="$(
2111+
printf '%s\n' "$raw" \
2112+
| tr -d '\r' \
2113+
| grep -Eo 'v?[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z]+(\.[0-9A-Za-z]+)*)?(\+[0-9A-Za-z.-]+)?' \
2114+
| head -n 1 \
2115+
|| true
2116+
)"
2117+
printf '%s' "${parsed#v}"
2118+
}
2119+
fi
2120+
20882121
resolve_openclaw_version() {
20892122
local version=""
2123+
local raw_version_output=""
20902124
local claw="${OPENCLAW_BIN:-}"
20912125
if [[ -z "$claw" ]] && command -v openclaw &> /dev/null; then
20922126
claw="$(command -v openclaw)"
20932127
fi
20942128
if [[ -n "$claw" ]]; then
2095-
version=$("$claw" --version 2>/dev/null | head -n 1 | tr -d '\r')
2129+
raw_version_output=$("$claw" --version 2>/dev/null | head -n 1 | tr -d '\r')
2130+
version="$(extract_openclaw_semver "$raw_version_output")"
2131+
if [[ -z "$version" ]]; then
2132+
version="$raw_version_output"
2133+
fi
20962134
fi
20972135
if [[ -z "$version" ]]; then
20982136
local npm_root=""

src/auto-reply/status.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ export function buildStatusMessage(args: StatusArgs): string {
655655
showFallbackAuth ? ` · 🔑 ${activeAuthLabelValue}` : ""
656656
} (${fallbackState.reason ?? "selected model unavailable"})`
657657
: null;
658-
const commit = resolveCommitHash();
658+
const commit = resolveCommitHash({ moduleUrl: import.meta.url });
659659
const versionLine = `🦞 OpenClaw ${VERSION}${commit ? ` (${commit})` : ""}`;
660660
const usagePair = formatUsagePair(inputTokens, outputTokens);
661661
const cacheLine = formatCacheLine(inputTokens, cacheRead, cacheWrite);

src/cli/banner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ function resolveTaglineMode(options: BannerOptions): TaglineMode | undefined {
5757
}
5858

5959
export function formatCliBannerLine(version: string, options: BannerOptions = {}): string {
60-
const commit = options.commit ?? resolveCommitHash({ env: options.env });
60+
const commit =
61+
options.commit ?? resolveCommitHash({ env: options.env, moduleUrl: import.meta.url });
6162
const commitLabel = commit ?? "unknown";
6263
const tagline = pickTagline({ ...options, mode: resolveTaglineMode(options) });
6364
const rich = options.richTty ?? isRich();

0 commit comments

Comments
 (0)