Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

feat(config): add version check to `wt config show --full` (#1011)

Maximilian Roos4acb2d74b6a9
diff --git a/docs/content/config.md b/docs/content/config.md
index 7ac4460ab..163484ff8 100644
--- a/docs/content/config.md
+++ b/docs/content/config.md
@@ -413,6 +413,7 @@ wt config show --full
This tests:
- **CI tool status** — Whether `gh` (GitHub) or `glab` (GitLab) is installed and authenticated
- **Commit generation** — Whether the LLM command can generate commit messages
+- **Version check** — Whether a newer version is available on GitHub
### Command reference
@@ -423,7 +424,7 @@ Usage: <b><span class=c>wt config show</span></b> <span class=c>[OPTIONS]</span>
<b><span class=g>Options:</span></b>
<b><span class=c>--full</span></b>
- Run diagnostic checks (CI tools, commit generation)
+ Run diagnostic checks (CI tools, commit generation, version)
<b><span class=c>-h</span></b>, <b><span class=c>--help</span></b>
Print help (see a summary with &#39;-h&#39;)
diff --git a/skills/worktrunk/reference/config.md b/skills/worktrunk/reference/config.md
index 73358aa61..6253b7384 100644
--- a/skills/worktrunk/reference/config.md
+++ b/skills/worktrunk/reference/config.md
@@ -403,6 +403,7 @@ wt config show --full
This tests:
- **CI tool status** — Whether `gh` (GitHub) or `glab` (GitLab) is installed and authenticated
- **Commit generation** — Whether the LLM command can generate commit messages
+- **Version check** — Whether a newer version is available on GitHub
### Command reference
@@ -412,7 +413,7 @@ Usage: <b><span class=c>wt config show</span></b> <span class=c>[OPTIONS]</span>
<b><span class=g>Options:</span></b>
<b><span class=c>--full</span></b>
- Run diagnostic checks (CI tools, commit generation)
+ Run diagnostic checks (CI tools, commit generation, version)
<b><span class=c>-h</span></b>, <b><span class=c>--help</span></b>
Print help (see a summary with &#39;-h&#39;)
diff --git a/src/cli/config.rs b/src/cli/config.rs
index 3954ab4a1..2a2493d85 100644
--- a/src/cli/config.rs
+++ b/src/cli/config.rs
@@ -222,10 +222,11 @@ wt config show --full
This tests:
- **CI tool status** — Whether `gh` (GitHub) or `glab` (GitLab) is installed and authenticated
-- **Commit generation** — Whether the LLM command can generate commit messages"#
+- **Commit generation** — Whether the LLM command can generate commit messages
+- **Version check** — Whether a newer version is available on GitHub"#
)]
Show {
- /// Run diagnostic checks (CI tools, commit generation)
+ /// Run diagnostic checks (CI tools, commit generation, version)
#[arg(long)]
full: bool,
},
diff --git a/src/commands/config/show.rs b/src/commands/config/show.rs
index d8f834b2d..d71c5d5f2 100644
--- a/src/commands/config/show.rs
+++ b/src/commands/config/show.rs
@@ -298,6 +298,9 @@ fn render_diagnostics(out: &mut String) -> anyhow::Result<()> {
}
}
+ // Check for newer version on GitHub
+ render_version_check(out)?;
+
// Test commit generation - use effective config for current project
let config = UserConfig::load()?;
let project_id = Repository::current()
@@ -307,31 +310,30 @@ fn render_diagnostics(out: &mut String) -> anyhow::Result<()> {
if !commit_config.is_configured() {
writeln!(out, "{}", hint_message("Commit generation not configured"))?;
- return Ok(());
- }
-
- let command_display = commit_config.command.as_ref().unwrap().clone();
+ } else {
+ let command_display = commit_config.command.as_ref().unwrap().clone();
- match test_commit_generation(&commit_config) {
- Ok(message) => {
- writeln!(
- out,
- "{}",
- success_message(cformat!(
- "Commit generation working (<bold>{command_display}</>)"
- ))
- )?;
- writeln!(out, "{}", format_with_gutter(&message, None))?;
- }
- Err(e) => {
- writeln!(
- out,
- "{}",
- error_message(cformat!(
- "Commit generation failed (<bold>{command_display}</>)"
- ))
- )?;
- writeln!(out, "{}", format_with_gutter(&e.to_string(), None))?;
+ match test_commit_generation(&commit_config) {
+ Ok(message) => {
+ writeln!(
+ out,
+ "{}",
+ success_message(cformat!(
+ "Commit generation working (<bold>{command_display}</>)"
+ ))
+ )?;
+ writeln!(out, "{}", format_with_gutter(&message, None))?;
+ }
+ Err(e) => {
+ writeln!(
+ out,
+ "{}",
+ error_message(cformat!(
+ "Commit generation failed (<bold>{command_display}</>)"
+ ))
+ )?;
+ writeln!(out, "{}", format_with_gutter(&e.to_string(), None))?;
+ }
}
}
@@ -966,6 +968,92 @@ pub(super) fn render_ci_tool_status(
Ok(())
}
+/// Render version update check (fetches from GitHub)
+fn render_version_check(out: &mut String) -> anyhow::Result<()> {
+ match fetch_latest_version() {
+ Ok(latest) => {
+ let current = crate::cli::version_str();
+ let current_semver = env!("CARGO_PKG_VERSION");
+ if is_newer_version(&latest, current_semver) {
+ writeln!(
+ out,
+ "{}",
+ info_message(cformat!(
+ "Update available: <bold>{latest}</> (current: {current})"
+ ))
+ )?;
+ } else {
+ writeln!(
+ out,
+ "{}",
+ success_message(cformat!("Up to date (<bold>{current}</>)"))
+ )?;
+ }
+ }
+ Err(e) => {
+ log::debug!("Version check failed: {e}");
+ writeln!(out, "{}", hint_message("Version check unavailable"))?;
+ }
+ }
+ Ok(())
+}
+
+/// Fetch the latest release version from GitHub
+fn fetch_latest_version() -> anyhow::Result<String> {
+ // Allow tests to inject a version without network access.
+ // Set to "error" to simulate a fetch failure.
+ if let Ok(version) = std::env::var("WORKTRUNK_TEST_LATEST_VERSION") {
+ if version == "error" {
+ anyhow::bail!("simulated fetch failure");
+ }
+ return Ok(version);
+ }
+
+ let user_agent = format!(
+ "worktrunk/{} (https://worktrunk.dev)",
+ env!("CARGO_PKG_VERSION")
+ );
+ let output = Cmd::new("curl")
+ .args([
+ "--silent",
+ "--fail",
+ "--max-time",
+ "5",
+ "--header",
+ &format!("User-Agent: {user_agent}"),
+ "https://api.github.com/repos/max-sixty/worktrunk/releases/latest",
+ ])
+ .run()?;
+
+ if !output.status.success() {
+ anyhow::bail!("GitHub API request failed");
+ }
+
+ let json: serde_json::Value = serde_json::from_slice(&output.stdout)?;
+ let tag = json["tag_name"]
+ .as_str()
+ .ok_or_else(|| anyhow::anyhow!("missing tag_name in response"))?;
+
+ // Strip leading 'v' prefix (e.g., "v0.23.2" -> "0.23.2")
+ Ok(tag.strip_prefix('v').unwrap_or(tag).to_string())
+}
+
+/// Compare two semver version strings (e.g., "0.24.0" > "0.23.2")
+fn is_newer_version(latest: &str, current: &str) -> bool {
+ let parse = |s: &str| -> Option<(u32, u32, u32)> {
+ let mut parts = s.splitn(3, '.');
+ Some((
+ parts.next()?.parse().ok()?,
+ parts.next()?.parse().ok()?,
+ parts.next()?.parse().ok()?,
+ ))
+ };
+ match (parse(latest), parse(current)) {
+ (Some(l), Some(c)) => l > c,
+ _ => false,
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -980,4 +1068,24 @@ mod tests {
assert!(version.chars().next().unwrap().is_ascii_digit());
assert!(version.contains('.'));
}
+
+ #[test]
+ fn test_is_newer_version() {
+ // Newer versions
+ assert!(is_newer_version("0.24.0", "0.23.2"));
+ assert!(is_newer_version("1.0.0", "0.99.99"));
+ assert!(is_newer_version("0.23.3", "0.23.2"));
+ assert!(is_newer_version("0.23.2", "0.23.1"));
+
+ // Same version
+ assert!(!is_newer_version("0.23.2", "0.23.2"));
+
+ // Older versions
+ assert!(!is_newer_version("0.23.1", "0.23.2"));
+ assert!(!is_newer_version("0.22.0", "0.23.2"));
+
+ // Invalid input
+ assert!(!is_newer_version("invalid", "0.23.2"));
+ assert!(!is_newer_version("0.23.2", "invalid"));
+ }
}
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 510dfbca1..180204c4b 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -2712,6 +2712,12 @@ fn setup_snapshot_settings_for_paths_with_home(
r"(git: \x1b\[1m)[0-9]+\.[0-9]+\.[0-9]+[^\x1b]*",
"${1}[VERSION]",
);
+ // Version check: "Up to date (<bold>VERSION</>)" or "current: VERSION)"
+ // version_str() can be: v0.8.5, v0.8.5-2-gabcdef, v0.8.5-dirty, 0.8.5, or bare hash (8465a1f)
+ settings.add_filter(
+ r"(current: |Up to date \(\x1b\[1m)(?:v?[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9]+-g[0-9a-f]+)?(?:-dirty)?|[0-9a-f]{7,40})",
+ "${1}[VERSION]",
+ );
// Normalize project root paths in "Binary invoked as:" debug output
// Tests run cargo which produces paths like /path/to/worktrunk/target/debug/wt
diff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rs
index 41d9261f1..343543dd5 100644
--- a/tests/integration_tests/config_show.rs
+++ b/tests/integration_tests/config_show.rs
@@ -652,6 +652,8 @@ fn test_config_show_full_not_configured(mut repo: TestRepo, temp_home: TempDir)
repo.configure_mock_commands(&mut cmd);
// Override WORKTRUNK_CONFIG_PATH to point to our test config
cmd.env("WORKTRUNK_CONFIG_PATH", &config_path);
+ // Inject current version for deterministic version check output
+ cmd.env("WORKTRUNK_TEST_LATEST_VERSION", env!("CARGO_PKG_VERSION"));
cmd.arg("config")
.arg("show")
.arg("--full")
@@ -688,6 +690,72 @@ command = "nonexistent-llm-command-12345 -m test-model"
repo.configure_mock_commands(&mut cmd);
// Override WORKTRUNK_CONFIG_PATH to point to our test config
cmd.env("WORKTRUNK_CONFIG_PATH", &config_path);
+ // Inject current version for deterministic version check output
+ cmd.env("WORKTRUNK_TEST_LATEST_VERSION", env!("CARGO_PKG_VERSION"));
+ cmd.arg("config")
+ .arg("show")
+ .arg("--full")
+ .current_dir(repo.root_path());
+ set_temp_home_env(&mut cmd, temp_home.path());
+
+ assert_cmd_snapshot!(cmd);
+ });
+}
+
+#[rstest]
+fn test_config_show_full_update_available(mut repo: TestRepo, temp_home: TempDir) {
+ // Setup mock gh/glab for deterministic BINARIES output
+ repo.setup_mock_ci_tools_unauthenticated();
+
+ // Create isolated config directory
+ let global_config_dir = temp_home.path().join(".config").join("worktrunk");
+ fs::create_dir_all(&global_config_dir).unwrap();
+ let config_path = global_config_dir.join("config.toml");
+ fs::write(
+ &config_path,
+ "worktree-path = \"../{{ repo }}.{{ branch }}\"",
+ )
+ .unwrap();
+
+ let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.configure_wt_cmd(&mut cmd);
+ repo.configure_mock_commands(&mut cmd);
+ cmd.env("WORKTRUNK_CONFIG_PATH", &config_path);
+ // Inject a higher version to trigger update-available message
+ cmd.env("WORKTRUNK_TEST_LATEST_VERSION", "99.0.0");
+ cmd.arg("config")
+ .arg("show")
+ .arg("--full")
+ .current_dir(repo.root_path());
+ set_temp_home_env(&mut cmd, temp_home.path());
+
+ assert_cmd_snapshot!(cmd);
+ });
+}
+
+#[rstest]
+fn test_config_show_full_version_check_unavailable(mut repo: TestRepo, temp_home: TempDir) {
+ repo.setup_mock_ci_tools_unauthenticated();
+
+ let global_config_dir = temp_home.path().join(".config").join("worktrunk");
+ fs::create_dir_all(&global_config_dir).unwrap();
+ let config_path = global_config_dir.join("config.toml");
+ fs::write(
+ &config_path,
+ "worktree-path = \"../{{ repo }}.{{ branch }}\"",
+ )
+ .unwrap();
+
+ let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.configure_wt_cmd(&mut cmd);
+ repo.configure_mock_commands(&mut cmd);
+ cmd.env("WORKTRUNK_CONFIG_PATH", &config_path);
+ // Simulate a fetch failure
+ cmd.env("WORKTRUNK_TEST_LATEST_VERSION", "error");
cmd.arg("config")
.arg("show")
.arg("--full")
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_full_command_not_found.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_full_command_not_found.snap
index f4f1f451e..86bd25648 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_full_command_not_found.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_full_command_not_found.snap
@@ -14,6 +14,7 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
GIT_TERMINAL_PROMPT: "0"
HOME: "[TEST_HOME]"
LANG: C
@@ -27,6 +28,7 @@ info:
USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_LATEST_VERSION: 0.23.2
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
WT_TEST_DELAYED_STREAM_MS: "-1"
@@ -60,6 +62,7 @@ exit_code: 0
DIAGNOSTICS
↳ CI status requires GitHub or GitLab remote
+✓ Up to date ([VERSION])
✗ Commit generation failed (nonexistent-llm-command-12345 -m test-model)
  ✗ Commit generation command failed
    sh: nonexistent-llm-command-12345: command not found
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_full_not_configured.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_full_not_configured.snap
index 2f5ca3e36..22138a0d5 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_full_not_configured.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_full_not_configured.snap
@@ -14,6 +14,7 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
GIT_TERMINAL_PROMPT: "0"
HOME: "[TEST_HOME]"
LANG: C
@@ -27,6 +28,7 @@ info:
USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_LATEST_VERSION: 0.23.2
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
WT_TEST_DELAYED_STREAM_MS: "-1"
@@ -57,6 +59,7 @@ exit_code: 0
DIAGNOSTICS
↳ CI status requires GitHub or GitLab remote
+✓ Up to date ([VERSION])
↳ Commit generation not configured
OTHER
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_full_update_available.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_full_update_available.snap
new file mode 100644
index 000000000..b9356aec6
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_full_update_available.snap
@@ -0,0 +1,68 @@
+---
+source: tests/integration_tests/config_show.rs
+info:
+ program: wt
+ args:
+ - config
+ - show
+ - "--full"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_LATEST_VERSION: 99.0.0
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WT_TEST_DELAYED_STREAM_MS: "-1"
+ WT_TEST_EPOCH: "1735776000"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+USER CONFIG ~/.config/worktrunk/config.toml
+  worktree-path = "../{{ repo }}.{{ branch }}"
+
+PROJECT CONFIG _REPO_/.config/wt.toml
+↳ Not found
+
+SHELL INTEGRATION
+▲ Shell integration not active
+  Invoked as: [PROJECT_ROOT]/target/debug/wt
+
+○ bash: Skipped; ~/.bashrc not found
+○ zsh: Skipped; ~/.zshrc not found
+○ fish: Skipped; ~/.config/fish/functions not found
+
+CLAUDE CODE
+○ claude CLI not installed
+
+DIAGNOSTICS
+↳ CI status requires GitHub or GitLab remote
+○ Update available: 99.0.0 (current: [VERSION])
+↳ Commit generation not configured
+
+OTHER
+○ wt: [VERSION]
+○ git: [VERSION]
+○ Hyperlinks: inactive
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_full_version_check_unavailable.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_full_version_check_unavailable.snap
new file mode 100644
index 000000000..9cee66d5c
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_full_version_check_unavailable.snap
@@ -0,0 +1,68 @@
+---
+source: tests/integration_tests/config_show.rs
+info:
+ program: wt
+ args:
+ - config
+ - show
+ - "--full"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_LATEST_VERSION: error
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WT_TEST_DELAYED_STREAM_MS: "-1"
+ WT_TEST_EPOCH: "1735776000"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+USER CONFIG ~/.config/worktrunk/config.toml
+  worktree-path = "../{{ repo }}.{{ branch }}"
+
+PROJECT CONFIG _REPO_/.config/wt.toml
+↳ Not found
+
+SHELL INTEGRATION
+▲ Shell integration not active
+  Invoked as: [PROJECT_ROOT]/target/debug/wt
+
+○ bash: Skipped; ~/.bashrc not found
+○ zsh: Skipped; ~/.zshrc not found
+○ fish: Skipped; ~/.config/fish/functions not found
+
+CLAUDE CODE
+○ claude CLI not installed
+
+DIAGNOSTICS
+↳ CI status requires GitHub or GitLab remote
+↳ Version check unavailable
+↳ Commit generation not configured
+
+OTHER
+○ wt: [VERSION]
+○ git: [VERSION]
+○ Hyperlinks: inactive
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_show.snap b/tests/snapshots/integration__integration_tests__help__help_config_show.snap
index b2d487e40..d4c7947fe 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_show.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_show.snap
@@ -9,6 +9,7 @@ info:
env:
CLICOLOR_FORCE: "1"
COLUMNS: "500"
+ GIT_EDITOR: ""
LANG: C
LC_ALL: C
PSModulePath: ""
@@ -33,7 +34,7 @@ Usage: wt config show [OPTIONS]
Options:
--full
- Run diagnostic checks (CI tools, commit generation)
+ Run diagnostic checks (CI tools, commit generation, version)
-h, --help
Print help (see a summary with '-h')
@@ -62,3 +63,4 @@ Use --full to run diagnostic checks:
This tests:
- CI tool status — Whether gh (GitHub) or glab (GitLab) is installed and authenticated
- Commit generation — Whether the LLM command can generate commit messages
+- Version check — Whether a newer version is available on GitHub