Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

feat(update): compare commit times when versions tie

RoversX482dd8d88bae
diff --git a/Cargo.lock b/Cargo.lock
index b7f7b241..121dc8a6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -9631,6 +9631,7 @@ dependencies = [
"config",
"hex",
"http_req",
+ "humantime",
"log",
"plist",
"semver",
diff --git a/ci/deploy.sh b/ci/deploy.sh
index c3cc79bc..4763cd1f 100755
--- a/ci/deploy.sh
+++ b/ci/deploy.sh
@@ -83,6 +83,12 @@ case $OSTYPE in
plutil -replace CFBundleShortVersionString -string "$MACOS_BUNDLE_VERSION" \
"$zipdir/ThinkTerm.app/Contents/Info.plist"
fi
+ # A package signed for distribution says so. Built on a laptop, its
+ # binaries carry a commit stamp like any package made by hand, and the
+ # update check must not take it for one and offer it its own release.
+ if [[ "${MACOS_SIGNING_MODE:-}" == developerid || ( -z "${MACOS_SIGNING_MODE:-}" && -n "${MACOS_TEAM_ID:-}" ) ]] ; then
+ plutil -replace ThinkTermReleasePackage -bool YES "$zipdir/ThinkTerm.app/Contents/Info.plist"
+ fi
# Omit MetalANGLE for now; it's a bit laggy compared to CGL,
# and on M1/Big Sur, CGL is implemented in terms of Metal anyway
rm $zipdir/ThinkTerm.app/*.dylib
diff --git a/config/src/version.rs b/config/src/version.rs
index 897a37a2..f38f171a 100644
--- a/config/src/version.rs
+++ b/config/src/version.rs
@@ -2,12 +2,23 @@ use std::sync::OnceLock;
static VERSION: OnceLock<&'static str> = OnceLock::new();
static TRIPLE: OnceLock<&'static str> = OnceLock::new();
+static COMMIT_TIME: OnceLock<Option<i64>> = OnceLock::new();
pub fn assign_version_info(version: &'static str, triple: &'static str) {
VERSION.set(version).unwrap();
TRIPLE.set(triple).unwrap();
}
+/// When the commit this build came from was made, seconds since the epoch;
+/// set once at startup beside the version.
+pub fn assign_commit_time(time: Option<i64>) {
+ let _ = COMMIT_TIME.set(time);
+}
+
+pub fn wezterm_commit_time() -> Option<i64> {
+ COMMIT_TIME.get().copied().flatten()
+}
+
pub fn wezterm_version() -> &'static str {
VERSION
.get()
diff --git a/env-bootstrap/src/lib.rs b/env-bootstrap/src/lib.rs
index 9cbfe136..c85cc32a 100644
--- a/env-bootstrap/src/lib.rs
+++ b/env-bootstrap/src/lib.rs
@@ -246,6 +246,7 @@ pub fn bootstrap() {
wezterm_version::wezterm_version(),
wezterm_version::wezterm_target_triple(),
);
+ config::assign_commit_time(wezterm_version::wezterm_commit_time());
setup_logger();
register_panic_hook();
diff --git a/thinkterm-i18n/i18n/de-DE.ftl b/thinkterm-i18n/i18n/de-DE.ftl
index 6bed1db6..48a0e381 100644
--- a/thinkterm-i18n/i18n/de-DE.ftl
+++ b/thinkterm-i18n/i18n/de-DE.ftl
@@ -909,6 +909,7 @@ settings-update-current = ThinkTerm ist auf dem neuesten Stand.
settings-update-current-detail = ThinkTerm { $version }
settings-update-available = Ein Update ist verfügbar.
settings-update-available-detail = ThinkTerm { $latest } — Sie haben { $current }
+settings-update-available-build-detail = Ein neuerer Build von ThinkTerm { $latest } als Ihrer
settings-update-local-build = Es läuft ein lokaler Build.
settings-update-local-build-detail = { $version } — kein Release-Build
settings-update-unknown = Es wurde noch nicht nach Updates gesucht.
@@ -958,8 +959,10 @@ settings-sidebar-snippets-description = Gespeicherte Befehle und Texte, die Sie
# Update-Hinweis (Mitteilung) und der Installationsablauf der Seite „Software-Update“.
update-toast-title = ThinkTerm-Update verfügbar
+update-toast-new-build-title = Neuer ThinkTerm-Build verfügbar
update-toast-body = Klicken, um die Neuerungen zu sehen
update-capsule-available = Update verfügbar
+update-capsule-new-build = Neuer Build verfügbar
update-capsule-downloading = Wird geladen
update-capsule-installing = Wird installiert
update-capsule-restart = Neu starten zum Aktualisieren
diff --git a/thinkterm-i18n/i18n/en-US.ftl b/thinkterm-i18n/i18n/en-US.ftl
index 5e702e18..fc636d0f 100644
--- a/thinkterm-i18n/i18n/en-US.ftl
+++ b/thinkterm-i18n/i18n/en-US.ftl
@@ -909,6 +909,7 @@ settings-update-current = ThinkTerm is up to date.
settings-update-current-detail = ThinkTerm { $version }
settings-update-available = An update is available.
settings-update-available-detail = ThinkTerm { $latest } — you have { $current }
+settings-update-available-build-detail = A newer build of ThinkTerm { $latest } than the one you have
settings-update-local-build = Running a local build.
settings-update-local-build-detail = { $version } — not a release build
settings-update-unknown = No update check has run yet.
@@ -958,8 +959,10 @@ settings-sidebar-snippets-description = Saved commands and text you can paste in
# Update notice (toast) and the Software Update page's install flow.
update-toast-title = ThinkTerm update available
+update-toast-new-build-title = New ThinkTerm build available
update-toast-body = Click to see what's new
update-capsule-available = Update available
+update-capsule-new-build = New build available
update-capsule-downloading = Downloading
update-capsule-installing = Installing
update-capsule-restart = Restart to update
diff --git a/thinkterm-i18n/i18n/fr-FR.ftl b/thinkterm-i18n/i18n/fr-FR.ftl
index 0784e598..f2812849 100644
--- a/thinkterm-i18n/i18n/fr-FR.ftl
+++ b/thinkterm-i18n/i18n/fr-FR.ftl
@@ -903,6 +903,7 @@ settings-update-current = ThinkTerm est à jour.
settings-update-current-detail = ThinkTerm { $version }
settings-update-available = Une mise à jour est disponible.
settings-update-available-detail = ThinkTerm { $latest } — vous avez { $current }
+settings-update-available-build-detail = Un build plus récent de ThinkTerm { $latest } que le vôtre
settings-update-local-build = Compilation locale en cours d’exécution.
settings-update-local-build-detail = { $version } — pas une version publiée
settings-update-unknown = Aucune vérification n’a encore eu lieu.
@@ -952,8 +953,10 @@ settings-sidebar-snippets-description = Commandes et textes enregistrés, à col
# Notification de mise à jour et installation depuis la page Mise à jour logicielle.
update-toast-title = Mise à jour de ThinkTerm disponible
+update-toast-new-build-title = Nouveau build de ThinkTerm disponible
update-toast-body = Cliquez pour voir les nouveautés
update-capsule-available = Mise à jour disponible
+update-capsule-new-build = Nouveau build disponible
update-capsule-downloading = Téléchargement
update-capsule-installing = Installation
update-capsule-restart = Redémarrer pour mettre à jour
diff --git a/thinkterm-i18n/i18n/ja-JP.ftl b/thinkterm-i18n/i18n/ja-JP.ftl
index 1ba56ab9..2eee8b74 100644
--- a/thinkterm-i18n/i18n/ja-JP.ftl
+++ b/thinkterm-i18n/i18n/ja-JP.ftl
@@ -879,6 +879,7 @@ settings-update-current = ThinkTerm は最新です。
settings-update-current-detail = ThinkTerm { $version }
settings-update-available = アップデートがあります。
settings-update-available-detail = ThinkTerm { $latest } — 現在は { $current }
+settings-update-available-build-detail = お使いのものより新しい ThinkTerm { $latest } のビルドがあります
settings-update-local-build = ローカルビルドで実行中です。
settings-update-local-build-detail = { $version } — リリースビルドではありません
settings-update-unknown = まだ確認していません。
@@ -928,8 +929,10 @@ settings-sidebar-snippets-description = 保存したコマンドやテキスト
# 更新通知(トースト)と「ソフトウェアアップデート」ページのインストール処理。
update-toast-title = ThinkTerm の新しいバージョンがあります
+update-toast-new-build-title = ThinkTerm の新しいビルドがあります
update-toast-body = クリックして更新内容を表示
update-capsule-available = アップデートがあります
+update-capsule-new-build = 新しいビルドがあります
update-capsule-downloading = ダウンロード中
update-capsule-installing = インストール中
update-capsule-restart = 再起動してアップデート
diff --git a/thinkterm-i18n/i18n/zh-CN.ftl b/thinkterm-i18n/i18n/zh-CN.ftl
index 673e2cb4..1c99fc05 100644
--- a/thinkterm-i18n/i18n/zh-CN.ftl
+++ b/thinkterm-i18n/i18n/zh-CN.ftl
@@ -879,6 +879,7 @@ settings-update-current = ThinkTerm 已是最新版本。
settings-update-current-detail = ThinkTerm { $version }
settings-update-available = 有可用更新。
settings-update-available-detail = ThinkTerm { $latest } — 当前版本 { $current }
+settings-update-available-build-detail = ThinkTerm { $latest } 有比你这份更新的构建
settings-update-local-build = 正在运行本地构建。
settings-update-local-build-detail = { $version } — 非发布版本
settings-update-unknown = 尚未检查过更新。
@@ -928,8 +929,10 @@ settings-sidebar-snippets-description = 保存的命令和文本,可以粘贴
# 更新提醒(系统通知)与"软件更新"页的安装流程。
update-toast-title = ThinkTerm 有新版本
+update-toast-new-build-title = ThinkTerm 有新构建
update-toast-body = 点击查看更新内容
update-capsule-available = 有新版本
+update-capsule-new-build = 有新构建
update-capsule-downloading = 正在下载
update-capsule-installing = 正在安装
update-capsule-restart = 重启以完成更新
diff --git a/thinkterm-update/Cargo.toml b/thinkterm-update/Cargo.toml
index b1825e50..b1576939 100644
--- a/thinkterm-update/Cargo.toml
+++ b/thinkterm-update/Cargo.toml
@@ -12,6 +12,7 @@ log.workspace = true
semver.workspace = true
sha2.workspace = true
hex.workspace = true
+humantime.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
tempfile.workspace = true
diff --git a/thinkterm-update/src/lib.rs b/thinkterm-update/src/lib.rs
index 28ca18fd..02c07753 100644
--- a/thinkterm-update/src/lib.rs
+++ b/thinkterm-update/src/lib.rs
@@ -33,6 +33,7 @@ pub const INSTALL_SCRIPT_URL: &str =
"https://raw.githubusercontent.com/RoversX/thinkterm/main/install.sh";
const API_RELEASES: &str = "https://api.github.com/repos/RoversX/thinkterm/releases";
+const API_COMMITS: &str = "https://api.github.com/repos/RoversX/thinkterm/commits";
/// The oldest glibc the Linux release binaries run on: the Ubuntu 22.04 base
/// they are built in. `install.sh` carries the same number and refuses
@@ -82,6 +83,11 @@ pub struct Release {
pub html_url: String,
pub tag_name: String,
pub assets: Vec<Asset>,
+ /// When the commit the release was made from was committed, in seconds
+ /// since the epoch. Not part of GitHub's answer: looked up, and kept in
+ /// the cached copy, only when it is what decides -- see `is_newer_build`.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub thinkterm_commit_time: Option<i64>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
@@ -511,7 +517,12 @@ fn version_from_info_plist(path: PathBuf) -> Option<String> {
/// `<date>-<hash>` commit stamp a plain checkout builds with. Only a release
/// has a tag on GitHub, so only a release can be fetched by name.
pub fn is_release_version(version: &str) -> bool {
- semver::Version::parse(version.trim_start_matches('v')).is_ok()
+ parse_release(version).is_some()
+}
+
+/// A release version, with or without the `v` older tags carried.
+fn parse_release(version: &str) -> Option<semver::Version> {
+ semver::Version::parse(version.trim_start_matches('v')).ok()
}
/// Is `latest` a release the running build should be told about?
@@ -523,8 +534,7 @@ pub fn is_release_version(version: &str) -> bool {
/// with `>` is what made every `v*` release look permanently newer than every
/// local build: 'v' sorts above every digit, so the banner never went away.
pub fn is_newer_release(latest: &str, current: &str) -> bool {
- let parse = |s: &str| semver::Version::parse(s.trim_start_matches('v')).ok();
- match (parse(latest), parse(current)) {
+ match (parse_release(latest), parse_release(current)) {
(Some(latest), Some(current)) => latest > current,
// Both on the commit-stamp scheme, which upstream still uses for its
// own tags. It starts with a zero-padded date, so lexicographic order
@@ -536,6 +546,165 @@ pub fn is_newer_release(latest: &str, current: &str) -> bool {
}
}
+/// Is `latest` -- a release made from a commit committed at
+/// `latest_commit_time` -- something the running build, `current` committed
+/// at `current_commit_time`, should be told about?
+///
+/// The versions decide, as `is_newer_release` has them. Only a tie goes on to
+/// the commits: a package made by hand from a checkout can carry the version
+/// of a release that does not exist yet, and when that release comes out its
+/// code is the later one. Committer times, in seconds since the epoch, so
+/// time zones and daylight saving never reorder them. A rebase or a squash
+/// dates its commits to when it ran, and a package made from a branch that
+/// missed some of the release's commits looks as new as its last commit:
+/// both only ever mislead a package made by hand, never a release's.
+pub fn is_newer_build(
+ latest: &str,
+ latest_commit_time: Option<i64>,
+ current: &str,
+ current_commit_time: Option<i64>,
+) -> bool {
+ if is_newer_release(latest, current) {
+ return true;
+ }
+ same_release_version(latest, current)
+ && matches!(
+ (latest_commit_time, current_commit_time),
+ (Some(latest), Some(current)) if latest > current
+ )
+}
+
+/// Whether two versions name the same release.
+pub fn same_release_version(a: &str, b: &str) -> bool {
+ matches!((parse_release(a), parse_release(b)), (Some(a), Some(b)) if a == b)
+}
+
+/// The commit time of the running build when that can tell it apart from a
+/// release of the same version: a package made by hand, whose binary carries
+/// the commit stamp of a checkout. None for a release package, which is the
+/// release whatever commit its tag points at -- so its users are never told
+/// about the very release they run.
+pub fn running_build_commit_time() -> Option<i64> {
+ #[cfg(target_os = "macos")]
+ if macos_bundle_is_release_package() {
+ return None;
+ }
+ build_commit_time(config::wezterm_version(), config::wezterm_commit_time())
+}
+
+fn build_commit_time(stamp: &str, time: Option<i64>) -> Option<i64> {
+ if is_release_version(stamp) {
+ None
+ } else {
+ time
+ }
+}
+
+/// The Info.plist key a package signed for a release carries (ci/deploy.sh
+/// writes it). A laptop-built one has a commit stamp in its binaries like
+/// any hand-made package, so the stamp alone cannot tell them apart.
+#[cfg(target_os = "macos")]
+const RELEASE_PACKAGE_KEY: &str = "ThinkTermReleasePackage";
+
+#[cfg(target_os = "macos")]
+fn macos_bundle_is_release_package() -> bool {
+ std::env::current_exe()
+ .ok()
+ .and_then(|exe| Some(exe.parent()?.parent()?.join("Info.plist")))
+ .and_then(|path| plist::Value::from_file(path).ok())
+ .and_then(|value| value.as_dictionary()?.get(RELEASE_PACKAGE_KEY)?.as_boolean())
+ .unwrap_or(false)
+}
+
+/// What a release is to the running build.
+#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
+pub struct UpdateVerdict {
+ /// Something to tell the person about.
+ pub newer: bool,
+ /// And it carries the running build's own version: the same release,
+ /// made from later code than this hand-made package of it.
+ pub new_build: bool,
+}
+
+/// Judge `latest` against the running build, `current`: by version, and on
+/// a tie by commit time (see `is_newer_build`). The tag's commit time, which
+/// only a tie needs, comes from `cached` -- the last check's copy of the
+/// same release -- before GitHub is asked, and is kept in `latest` for the
+/// next check: a published tag does not move, and every request counts
+/// against the anonymous API limit.
+pub fn judge_release(latest: &mut Release, current: &str, cached: Option<&Release>) -> UpdateVerdict {
+ judge_release_with(latest, current, cached, running_build_commit_time(), get_tag_commit_time)
+}
+
+fn judge_release_with(
+ latest: &mut Release,
+ current: &str,
+ cached: Option<&Release>,
+ build_time: Option<i64>,
+ lookup: impl FnOnce(&str) -> anyhow::Result<i64>,
+) -> UpdateVerdict {
+ let tie = same_release_version(&latest.tag_name, current);
+ if tie && build_time.is_some() && latest.thinkterm_commit_time.is_none() {
+ latest.thinkterm_commit_time = cached
+ .filter(|cached| cached.tag_name == latest.tag_name)
+ .and_then(|cached| cached.thinkterm_commit_time)
+ .or_else(|| match lookup(&latest.tag_name) {
+ Ok(time) => Some(time),
+ Err(err) => {
+ log::debug!("looking up the commit of {}: {err:#}", latest.tag_name);
+ None
+ }
+ });
+ }
+ let newer = is_newer_build(
+ &latest.tag_name,
+ latest.thinkterm_commit_time,
+ current,
+ build_time,
+ );
+ UpdateVerdict {
+ newer,
+ new_build: newer && tie,
+ }
+}
+
+/// When the commit tag `tag` points at was committed, from the commits API:
+/// the list form, which leaves out the changed files, started from the tag
+/// itself so that a branch of the same name cannot answer instead.
+pub fn get_tag_commit_time(tag: &str) -> anyhow::Result<i64> {
+ let uri = format!("{API_COMMITS}?sha=refs/tags/{}&per_page=1", percent_encode(tag));
+ let body = http_get(&uri)?;
+ let commits: serde_json::Value = serde_json::from_slice(&body)
+ .with_context(|| format!("parsing the GitHub commit list from {uri}"))?;
+ let date = commits
+ .get(0)
+ .and_then(|commit| commit.pointer("/commit/committer/date"))
+ .and_then(|date| date.as_str())
+ .ok_or_else(|| anyhow!("no commit date for {tag} in {uri}"))?;
+ parse_github_utc(date).ok_or_else(|| anyhow!("unexpected commit date {date:?} for {tag}"))
+}
+
+/// `text` safe inside a query string: everything but unreserved characters
+/// percent-encoded.
+fn percent_encode(text: &str) -> String {
+ text.bytes()
+ .map(|byte| match byte {
+ b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'.' | b'_' | b'~' => {
+ (byte as char).to_string()
+ }
+ _ => format!("%{byte:02X}"),
+ })
+ .collect()
+}
+
+/// Seconds since the epoch for a GitHub timestamp, which is always UTC:
+/// `2026-10-15T07:12:34Z`.
+fn parse_github_utc(date: &str) -> Option<i64> {
+ let time = humantime::parse_rfc3339(date).ok()?;
+ let seconds = time.duration_since(std::time::UNIX_EPOCH).ok()?.as_secs();
+ i64::try_from(seconds).ok()
+}
+
/// The shell one-liner that installs release `version` of `variant` for the
/// invoking user, as `install.sh` documents it. Used verbatim over ssh for
/// the remote update and quoted in messages that tell a person what to run.
@@ -751,6 +920,99 @@ mod tests {
assert!(!is_newer_release("20260903-120000-abcdef12", "0.2.0"));
}
+ #[test]
+ fn the_version_decides_and_only_a_tie_goes_on_to_the_commits() {
+ // A higher or lower version settles it, whatever the commits.
+ assert!(is_newer_build("0.2.1", None, "0.2.0", None));
+ assert!(!is_newer_build("0.1.9", Some(900), "0.2.0", Some(100)));
+ // The same version, made from a later commit: a newer build.
+ assert!(is_newer_build("0.2.0", Some(200), "0.2.0", Some(100)));
+ assert!(is_newer_build("v0.2.0", Some(200), "0.2.0", Some(100)));
+ // The same commit, or an earlier one, is nothing to offer.
+ assert!(!is_newer_build("0.2.0", Some(100), "0.2.0", Some(100)));
+ assert!(!is_newer_build("0.2.0", Some(50), "0.2.0", Some(100)));
+ // Either time unknown: the versions alone, as before.
+ assert!(!is_newer_build("0.2.0", None, "0.2.0", Some(100)));
+ assert!(!is_newer_build("0.2.0", Some(200), "0.2.0", None));
+ // A commit stamp is not the release's version.
+ assert!(!is_newer_build("0.2.0", Some(200), "20261015-023205-79a8bed2", Some(100)));
+ }
+
+ #[test]
+ fn only_a_build_stamped_with_a_commit_has_a_commit_time_to_compare() {
+ assert_eq!(build_commit_time("20261015-023205-79a8bed2", Some(100)), Some(100));
+ assert_eq!(build_commit_time("20261015-023205-79a8bed2-dirty", Some(100)), Some(100));
+ // A release package is the release: never told about itself.
+ assert_eq!(build_commit_time("0.2.0", Some(100)), None);
+ }
+
+ fn release(tag: &str, commit_time: Option<i64>) -> Release {
+ let mut release: Release = serde_json::from_value(serde_json::json!({
+ "url": "", "body": "", "html_url": "", "tag_name": tag, "assets": []
+ }))
+ .unwrap();
+ release.thinkterm_commit_time = commit_time;
+ release
+ }
+
+ #[test]
+ fn a_tie_is_settled_by_the_tag_s_commit_time_asked_once() {
+ let asked = std::cell::Cell::new(0);
+ let lookup = |time: i64| {
+ let asked = &asked;
+ move |_: &str| {
+ asked.set(asked.get() + 1);
+ Ok(time)
+ }
+ };
+ // A later commit behind the same version: a new build, asked once.
+ let mut latest = release("0.2.0", None);
+ let verdict = judge_release_with(&mut latest, "0.2.0", None, Some(100), lookup(200));
+ assert_eq!(verdict, UpdateVerdict { newer: true, new_build: true });
+ assert_eq!((latest.thinkterm_commit_time, asked.get()), (Some(200), 1));
+ // The next check takes it from the cached copy of the same tag.
+ let cached = latest.clone();
+ let mut latest = release("0.2.0", None);
+ judge_release_with(&mut latest, "0.2.0", Some(&cached), Some(100), lookup(999));
+ assert_eq!((latest.thinkterm_commit_time, asked.get()), (Some(200), 1));
+ // A different version, or a release package: nothing to ask.
+ let mut latest = release("0.2.1", None);
+ let verdict = judge_release_with(&mut latest, "0.2.0", None, Some(100), lookup(50));
+ assert_eq!(verdict, UpdateVerdict { newer: true, new_build: false });
+ let mut latest = release("0.2.0", None);
+ let verdict = judge_release_with(&mut latest, "0.2.0", None, None, lookup(200));
+ assert_eq!(verdict, UpdateVerdict::default());
+ assert_eq!(asked.get(), 1);
+ }
+
+ #[test]
+ fn a_tag_commit_github_cannot_date_leaves_the_versions_to_decide() {
+ let mut latest = release("0.2.0", None);
+ let verdict = judge_release_with(&mut latest, "0.2.0", None, Some(100), |_: &str| {
+ Err(anyhow!("rate limited"))
+ });
+ assert_eq!(verdict, UpdateVerdict::default());
+ assert_eq!(latest.thinkterm_commit_time, None);
+ }
+
+ #[test]
+ fn a_tag_goes_into_the_query_string_encoded() {
+ assert_eq!(percent_encode("0.2.0"), "0.2.0");
+ assert_eq!(percent_encode("1.0.0+build.5"), "1.0.0%2Bbuild.5");
+ assert_eq!(percent_encode("a b/c"), "a%20b%2Fc");
+ }
+
+ #[test]
+ fn github_timestamps_are_read_as_utc() {
+ assert_eq!(parse_github_utc("1970-01-01T00:00:00Z"), Some(0));
+ assert_eq!(parse_github_utc("2000-02-29T12:00:00Z"), Some(951_825_600));
+ // A commit made at 02:32:05 +11:00 on the 15th.
+ assert_eq!(parse_github_utc("2026-10-14T15:32:05Z"), Some(1_791_991_925));
+ assert_eq!(parse_github_utc("2026-10-14T15:32:05+11:00"), None);
+ assert_eq!(parse_github_utc("2026-13-01T00:00:00Z"), None);
+ assert_eq!(parse_github_utc("not a date"), None);
+ }
+
#[test]
fn only_semver_is_a_release_version() {
assert!(is_release_version("0.1.0"));
diff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rs
index e584ef87..210e17b5 100644
--- a/wezterm-gui/src/settings_window.rs
+++ b/wezterm-gui/src/settings_window.rs
@@ -593,7 +593,9 @@ pub(crate) fn installs_updates_itself() -> bool {
/// Where an update stands, as the update capsule shows it.
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum UpdateCapsuleStatus {
- Available { version: String },
+ /// `new_build`: the release has the running build's own version, made
+ /// from later code than this hand-made package of it.
+ Available { version: String, new_build: bool },
/// `fraction` is None before the first report and once the download is
/// in and the installer runs.
Installing { fraction: Option<f32> },
@@ -620,6 +622,7 @@ pub(crate) fn update_capsule_status() -> Option<UpdateCapsuleStatus> {
Some(UpdateInstall::Failed { .. }) => UpdateCapsuleStatus::Failed,
None => UpdateCapsuleStatus::Available {
version: crate::update::available_version()?,
+ new_build: crate::update::available_is_new_build(),
},
})
}
@@ -739,8 +742,11 @@ enum UpdateHero {
/// unreadable. Either way there is nothing to compare against.
Unknown,
UpToDate,
+ /// `new_build`: the release carries this build's own version, made from
+ /// later code than this hand-made package of it.
Available {
tag: String,
+ new_build: bool,
},
/// A commit-stamped build from a plain checkout. It has no ordering
/// against any release tag, so releases simply do not apply to it.
@@ -14527,6 +14533,10 @@ impl SettingsWindow {
match (&status.latest, status.update_available) {
(Some(latest), true) => UpdateHero::Available {
tag: latest.tag_name.clone(),
+ new_build: crate::update::same_release_version(
+ &latest.tag_name,
+ &status.current_version,
+ ),
},
(Some(_), false) => UpdateHero::UpToDate,
(None, _) => UpdateHero::Unknown,
@@ -15384,10 +15394,14 @@ impl SettingsWindow {
crate::i18n::tr("settings-update-current"),
settings_tr("settings-update-current-detail", &[("version", version)]),
),
- UpdateHero::Available { tag } => (
+ UpdateHero::Available { tag, new_build } => (
crate::i18n::tr("settings-update-available"),
settings_tr(
- "settings-update-available-detail",
+ if *new_build {
+ "settings-update-available-build-detail"
+ } else {
+ "settings-update-available-detail"
+ },
&[("latest", tag.clone()), ("current", version)],
),
),
diff --git a/wezterm-gui/src/termwindow/render/update_capsule.rs b/wezterm-gui/src/termwindow/render/update_capsule.rs
index 9fae934f..7561e5f7 100644
--- a/wezterm-gui/src/termwindow/render/update_capsule.rs
+++ b/wezterm-gui/src/termwindow/render/update_capsule.rs
@@ -190,8 +190,12 @@ impl crate::TermWindow {
let kind = Kind::of(&status);
let (main, sub, sub_room) = match &status {
- UpdateCapsuleStatus::Available { version } => (
- crate::i18n::tr("update-capsule-available"),
+ UpdateCapsuleStatus::Available { version, new_build } => (
+ crate::i18n::tr(if *new_build {
+ "update-capsule-new-build"
+ } else {
+ "update-capsule-available"
+ }),
version.clone(),
None,
),
@@ -954,7 +958,10 @@ mod tests {
fn the_capsule_reads_each_status_as_its_kind() {
let version = || "1.2.3".to_string();
assert_eq!(
- Kind::of(&UpdateCapsuleStatus::Available { version: version() }),
+ Kind::of(&UpdateCapsuleStatus::Available {
+ version: version(),
+ new_build: false,
+ }),
Kind::Available
);
assert_eq!(
diff --git a/wezterm-gui/src/update.rs b/wezterm-gui/src/update.rs
index 49f91ab1..205a8456 100644
--- a/wezterm-gui/src/update.rs
+++ b/wezterm-gui/src/update.rs
@@ -9,8 +9,8 @@ use wezterm_toast_notification::*;
// shared with `thinkterm update` and the mux client's remote update; the GUI
// keeps its names for them so the Settings pages and the toast read the same.
pub use thinkterm_update::{
- get_latest_release_info, is_newer_release, release_tag_url, releases_url,
- running_release_version, Release, REPO_URL,
+ get_latest_release_info, is_newer_build, judge_release, release_tag_url, releases_url,
+ running_build_commit_time, running_release_version, same_release_version, Release, REPO_URL,
};
lazy_static::lazy_static! {
@@ -47,6 +47,16 @@ pub fn available_release() -> Option<Release> {
AVAILABLE_RELEASE.lock().ok()?.clone()
}
+/// Whether the update on offer carries the running build's own version: a
+/// release made from later code than this hand-made package of it. A flag
+/// for the same reason `UPDATE_AVAILABLE` is one: the capsule reads it on
+/// every paint, and on macOS the running version comes from a file.
+static AVAILABLE_IS_NEW_BUILD: AtomicBool = AtomicBool::new(false);
+
+pub fn available_is_new_build() -> bool {
+ update_available() && AVAILABLE_IS_NEW_BUILD.load(Ordering::Relaxed)
+}
+
/// The newer release's version, without its `v`, while one is known.
pub fn available_version() -> Option<String> {
if !update_available() {
@@ -63,7 +73,8 @@ pub fn available_version() -> Option<String> {
/// names the new release. Only the checker thread and a check asked for
/// from Settings call this: both run once the GUI is up, and spawning onto
/// the main thread needs its scheduler.
-fn set_update_available(available: bool, latest: &Release) {
+fn set_update_available(available: bool, new_build: bool, latest: &Release) {
+ AVAILABLE_IS_NEW_BUILD.store(new_build, Ordering::Relaxed);
let renamed = AVAILABLE_RELEASE
.lock()
.map(|mut release| {
@@ -90,6 +101,14 @@ pub fn load_last_release_info() {
return;
}
let status = cached_update_status();
+ AVAILABLE_IS_NEW_BUILD.store(
+ status.update_available
+ && status
+ .latest
+ .as_ref()
+ .is_some_and(|latest| same_release_version(&latest.tag_name, &status.current_version)),
+ Ordering::Relaxed,
+ );
if let Ok(mut release) = AVAILABLE_RELEASE.lock() {
release.clone_from(&status.latest);
}
@@ -127,20 +146,30 @@ impl CachedUpdateStatus {
/// stamp. A commit-stamped build has no ordering against any release, so
/// the UI must say so instead of claiming to be up to date.
pub fn running_a_release_build(&self) -> bool {
- semver::Version::parse(self.current_version.trim_start_matches('v')).is_ok()
+ thinkterm_update::is_release_version(&self.current_version)
}
}
+/// The release the last check recorded, if it could be read back.
+fn cached_release() -> Option<Release> {
+ std::fs::read(config::DATA_DIR.join("check_update"))
+ .ok()
+ .and_then(|data| serde_json::from_slice::<Release>(&data).ok())
+}
+
pub fn cached_update_status() -> CachedUpdateStatus {
let current_version = running_release_version();
let path = config::DATA_DIR.join("check_update");
let last_checked = path.metadata().and_then(|meta| meta.modified()).ok();
- let latest = std::fs::read(&path)
- .ok()
- .and_then(|data| serde_json::from_slice::<Release>(&data).ok());
- let update_available = latest
- .as_ref()
- .is_some_and(|latest| is_newer_release(&latest.tag_name, &current_version));
+ let latest = cached_release();
+ let update_available = latest.as_ref().is_some_and(|latest| {
+ is_newer_build(
+ &latest.tag_name,
+ latest.thinkterm_commit_time,
+ &current_version,
+ running_build_commit_time(),
+ )
+ });
CachedUpdateStatus {
current_version,
@@ -152,7 +181,7 @@ pub fn cached_update_status() -> CachedUpdateStatus {
#[cfg(test)]
mod update_version_tests {
- use super::is_newer_release;
+ use thinkterm_update::is_newer_release;
const STAMP: &str = "20260819-153532-9d50c4cc";
@@ -185,9 +214,13 @@ mod update_version_tests {
/// network, so callers run it off the UI thread. No toast: whoever asked is
/// looking at the answer.
pub fn check_now() -> anyhow::Result<()> {
- let latest = get_latest_release_info()?;
- let newer = is_newer_release(&latest.tag_name, &running_release_version());
- set_update_available(newer || always_show_update_ui(), &latest);
+ let mut latest = get_latest_release_info()?;
+ let verdict = judge_release(&mut latest, &running_release_version(), cached_release().as_ref());
+ set_update_available(
+ verdict.newer || always_show_update_ui(),
+ verdict.new_build,
+ &latest,
+ );
// Settings shows what it reads back from the cache: an answer that could
// not be kept there is, as far as the page can tell, no answer.
record_latest_release(&latest)
@@ -232,10 +265,13 @@ fn update_checker() {
let socks = wezterm_client::discovery::discover_gui_socks();
if configuration().check_for_updates {
- if let Ok(latest) = get_latest_release_info() {
+ if let Ok(mut latest) = get_latest_release_info() {
let current = running_release_version();
- let newer = is_newer_release(&latest.tag_name, &current);
- set_update_available(newer || force_ui, &latest);
+ // A package made by hand with this release's version is told
+ // about the release once its code is the later one.
+ let verdict = judge_release(&mut latest, &current, cached_release().as_ref());
+ let newer = verdict.newer;
+ set_update_available(newer || force_ui, verdict.new_build, &latest);
if newer || force_ui {
log::info!(
"latest release {} is newer than current build {}",
@@ -247,7 +283,11 @@ fn update_checker() {
if force_ui || socks.is_empty() || socks[0] == my_sock {
persistent_toast_notification_with_click_to_open_url(
- &crate::i18n::tr("update-toast-title"),
+ &crate::i18n::tr(if verdict.new_build {
+ "update-toast-new-build-title"
+ } else {
+ "update-toast-title"
+ }),
&crate::i18n::tr("update-toast-body"),
&url,
);
diff --git a/wezterm-version/build.rs b/wezterm-version/build.rs
index 6c16e3ea..9142f774 100644
--- a/wezterm-version/build.rs
+++ b/wezterm-version/build.rs
@@ -30,6 +30,10 @@ fn main() {
.unwrap_or_default()
.trim()
.to_string();
+ // When the commit being built was made: its committer time, which a
+ // rebase or a squash moves on to the moment it was rewritten. Seconds
+ // since the epoch, so time zones and daylight saving never enter into it.
+ let mut commit_time = String::new();
if let Ok(repo) = git2::Repository::discover(".") {
// HEAD can switch branches without changing the ref that the old
@@ -41,6 +45,9 @@ fn main() {
if let Some(name) = head.name() {
watch_git_path(name);
}
+ if let Ok(commit) = head.peel_to_commit() {
+ commit_time = commit.committer().when().seconds().to_string();
+ }
}
// Index mtimes do not change for unstaged edits. Watch tracked inputs
// rather than the checkout directory (which contains target and logs).
@@ -82,4 +89,5 @@ fn main() {
let target = std::env::var("TARGET").unwrap_or_else(|_| "unknown".to_string());
println!("cargo:rustc-env=WEZTERM_TARGET_TRIPLE={target}");
println!("cargo:rustc-env=WEZTERM_CI_TAG={ci_tag}");
+ println!("cargo:rustc-env=THINKTERM_COMMIT_TIME={commit_time}");
}
diff --git a/wezterm-version/src/lib.rs b/wezterm-version/src/lib.rs
index 7c7f2128..9c84f46e 100644
--- a/wezterm-version/src/lib.rs
+++ b/wezterm-version/src/lib.rs
@@ -3,7 +3,27 @@ pub fn wezterm_version() -> &'static str {
env!("WEZTERM_CI_TAG")
}
+/// When the commit this was built from was made, in seconds since the Unix
+/// epoch. None for a build from outside a git checkout.
+pub fn wezterm_commit_time() -> Option<i64> {
+ // See build.rs
+ env!("THINKTERM_COMMIT_TIME").parse().ok()
+}
+
pub fn wezterm_target_triple() -> &'static str {
// See build.rs
env!("WEZTERM_TARGET_TRIPLE")
}
+
+#[cfg(test)]
+mod tests {
+ #[test]
+ fn a_build_from_a_checkout_knows_when_its_commit_was_made() {
+ // A source archive builds without git, and so without a commit time.
+ let checkout = concat!(env!("CARGO_MANIFEST_DIR"), "/../.git");
+ if !std::path::Path::new(checkout).exists() {
+ return;
+ }
+ assert!(super::wezterm_commit_time().is_some_and(|time| time > 1_700_000_000));
+ }
+}
diff --git a/wezterm/src/main.rs b/wezterm/src/main.rs
index 95461ba8..ea9290e6 100644
--- a/wezterm/src/main.rs
+++ b/wezterm/src/main.rs
@@ -809,7 +809,7 @@ impl UpdateCommand {
let current = thinkterm_update::running_release_version();
let method = InstallMethod::detect();
- let target = match &self.version {
+ let mut target = match &self.version {
Some(tag) => thinkterm_update::get_release_by_tag(tag.trim_start_matches('v'))
.or_else(|_| thinkterm_update::get_release_by_tag(tag))
.with_context(|| format!("release {tag} not found"))?,
@@ -826,7 +826,10 @@ impl UpdateCommand {
}
println!("install: {}", method.how_to_update());
- let newer = thinkterm_update::is_newer_release(&target.tag_name, &current);
+ // A package made by hand with the release's own version is behind it
+ // once the release's code is the later one.
+ let verdict = thinkterm_update::judge_release(&mut target, &current, None);
+ let newer = verdict.newer;
if self.version.is_none() && !newer {
if thinkterm_update::is_release_version(&current) {
println!("You are on the latest release.");
@@ -840,7 +843,9 @@ impl UpdateCommand {
return Ok(());
}
if self.check {
- if newer {
+ if verdict.new_build {
+ println!("A newer build of {target_version} is available: {}", target.html_url);
+ } else if newer {
println!("A newer release is available: {}", target.html_url);
} else {
println!("Release page: {}", target.html_url);