Skip to content

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

Unify `var` and `cache` into `state` subcommand (#178)

Maximilian Roos4ad3d4e00f9a
diff --git a/docs/content/config.md b/docs/content/config.md
index a713bcbf7..6a75fd5b7 100644
--- a/docs/content/config.md
+++ b/docs/content/config.md
@@ -569,31 +569,43 @@ Global Options:
```
-## wt config var
+## wt config state
-Variables are runtime values stored in git config, separate from
-configuration files. Use `wt config show` to view file-based configuration.
+Runtime state is stored in git config, separate from configuration files.
+Use `wt config show` to view file-based configuration.
-### Available variables
+### Keys
-- **default-branch**: The repository's default branch (read-only, cached)
+- **default-branch**: The repository's default branch (main, master, etc.)
+- **ci-status**: CI/PR status for a branch (passed, running, failed, conflicts, noci)
- **marker**: Custom status marker for a branch (shown in `wt list`)
+- **logs**: Background operation logs
### Examples
Get the default branch:
```bash
-wt config var get default-branch
+wt config state get default-branch
+```
+
+Set the default branch manually:
+```bash
+wt config state set default-branch main
```
Set a marker for current branch:
```bash
-wt config var set marker "🚧 WIP"
+wt config state set marker "🚧 WIP"
+```
+
+Clear all CI status cache:
+```bash
+wt config state clear ci-status --all
```
-Clear markers:
+Show all cached state:
```bash
-wt config var clear marker --all
+wt config state show
```
---
@@ -601,14 +613,16 @@ wt config var clear marker --all
### Command reference
```
-wt config var - Get or set runtime variables (stored in git config)
+wt config state - Get, set, or clear runtime state (stored in git config)
-Usage: wt config var [OPTIONS] <COMMAND>
+Usage: wt config state [OPTIONS] <COMMAND>
Commands:
- get Get a variable value
- set Set a variable value
- clear Clear a variable value
+ default-branch Manage default branch setting
+ ci-status Manage CI status cache
+ marker Manage branch markers
+ logs Manage background operation logs
+ show Show all cached state
Options:
-h, --help
@@ -638,8 +652,7 @@ Commands:
shell Shell integration setup
create Create configuration file
show Show configuration files & locations
- cache Manage caches (CI status, default branch)
- var Get or set runtime variables (stored in git config)
+ state Get, set, or clear runtime state (stored in git config)
Options:
-h, --help
diff --git a/docs/content/list.md b/docs/content/list.md
index b65294a84..cb577b21c 100644
--- a/docs/content/list.md
+++ b/docs/content/list.md
@@ -99,7 +99,7 @@ The CI column shows GitHub/GitLab pipeline status:
| <span style='color:#888'>●</span> gray | No checks configured |
| (blank) | No upstream or no PR/MR |
-CI indicators are clickable links to the PR or pipeline page. Any CI dot appears dimmed when there are unpushed local changes (stale status). PRs/MRs are checked first, then branch workflows/pipelines for branches with an upstream. Local-only branches show blank. Results are cached for 30-60 seconds; use `wt config cache` to view or clear.
+CI indicators are clickable links to the PR or pipeline page. Any CI dot appears dimmed when there are unpushed local changes (stale status). PRs/MRs are checked first, then branch workflows/pipelines for branches with an upstream. Local-only branches show blank. Results are cached for 30-60 seconds; use `wt config state` to view or clear.
## Status symbols
diff --git a/src/cli.rs b/src/cli.rs
index 15071aa04..fd22ed624 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -388,168 +388,221 @@ commit messages."#
full: bool,
},
- /// Manage caches (CI status, default branch)
- #[command(after_long_help = r#"## Default branch detection
-
-Worktrunk determines the default branch using:
-
-1. **Local cache** β€” Check `refs/remotes/origin/HEAD`, a symbolic ref that git
- uses to track the remote's default branch. This is created by `git clone`
- or `git remote set-head`. Instant, no network required.
-
-2. **Remote query** β€” If the local cache doesn't exist, query the remote with
- `git ls-remote --symref origin HEAD` to see what branch HEAD points to.
- This requires network access (100ms–2s). The result is cached locally via
- `git remote set-head origin <branch>`.
-
-3. **Local inference** β€” If no remote is configured: check git's
- `init.defaultBranch` config, then look for branches named `main`, `master`,
- `develop`, or `trunk`.
-
-Use `wt config cache refresh` when the remote's default branch has changed
-(e.g., renamed from `master` to `main`)."#)]
- Cache {
- #[command(subcommand)]
- action: CacheCommand,
- },
-
- /// Get or set runtime variables (stored in git config)
+ /// Get, set, or clear runtime state (stored in git config)
#[command(
- after_long_help = r#"Variables are runtime values stored in git config, separate from
-configuration files. Use `wt config show` to view file-based configuration.
+ after_long_help = r#"Runtime state is stored in git config, separate from configuration files.
+Use `wt config show` to view file-based configuration.
-## Available variables
+## Keys
-- **default-branch**: The repository's default branch (read-only, cached)
+- **default-branch**: The repository's default branch (main, master, etc.)
+- **ci-status**: CI/PR status for a branch (passed, running, failed, conflicts, noci)
- **marker**: Custom status marker for a branch (shown in `wt list`)
+- **logs**: Background operation logs
## Examples
Get the default branch:
```console
-wt config var get default-branch
+wt config state get default-branch
+```
+
+Set the default branch manually:
+```console
+wt config state set default-branch main
```
Set a marker for current branch:
```console
-wt config var set marker "🚧 WIP"
+wt config state set marker "🚧 WIP"
```
-Clear markers:
+Clear all CI status cache:
```console
-wt config var clear marker --all
+wt config state clear ci-status --all
+```
+
+Show all cached state:
+```console
+wt config state show
```"#
)]
- Var {
+ State {
#[command(subcommand)]
- action: VarCommand,
+ action: StateCommand,
},
}
#[derive(Subcommand)]
-pub enum CacheCommand {
- /// Show cached data
- #[command(after_long_help = r#"Shows all cached data including:
+pub enum StateCommand {
+ /// Manage default branch setting
+ #[command(name = "default-branch")]
+ DefaultBranch {
+ #[command(subcommand)]
+ action: DefaultBranchAction,
+ },
+
+ /// Manage CI status cache
+ #[command(name = "ci-status")]
+ CiStatus {
+ #[command(subcommand)]
+ action: CiStatusAction,
+ },
+
+ /// Manage branch markers
+ Marker {
+ #[command(subcommand)]
+ action: MarkerAction,
+ },
+
+ /// Manage background operation logs
+ Logs {
+ #[command(subcommand)]
+ action: LogsAction,
+ },
+
+ /// Show all cached state
+ #[command(after_long_help = r#"Shows all cached state including:
- **Default branch**: Cached result of querying remote for default branch
- **CI status**: Cached GitHub/GitLab CI status per branch (30s TTL)
CI cache entries show status, age, and the commit SHA they were fetched for."#)]
Show,
+}
- /// Clear cached data
- Clear {
- /// Cache type: 'ci', 'default-branch', or 'logs' (default: all)
- #[arg(value_parser = ["ci", "default-branch", "logs"])]
- cache_type: Option<String>,
+#[derive(Subcommand)]
+pub enum DefaultBranchAction {
+ /// Get the default branch
+ #[command(after_long_help = r#"## Examples
+
+Get the default branch:
+```console
+wt config state default-branch get
+```
+
+Force refresh from remote:
+```console
+wt config state default-branch get --refresh
+```"#)]
+ Get {
+ /// Force refresh from remote
+ #[arg(long)]
+ refresh: bool,
},
- /// Refresh default branch from remote
- #[command(
- after_long_help = r#"Queries the remote to determine the default branch and caches the result.
+ /// Set the default branch
+ #[command(after_long_help = r#"## Examples
-Use when the remote default branch has changed. The cached value is used by
-`wt merge`, `wt list`, and other commands that reference the default branch."#
- )]
- Refresh,
+Set the default branch:
+```console
+wt config state default-branch set main
+```"#)]
+ Set {
+ /// Branch name to set as default
+ #[arg(add = crate::completion::branch_value_completer())]
+ branch: String,
+ },
+
+ /// Clear the default branch cache
+ Clear,
}
#[derive(Subcommand)]
-pub enum VarCommand {
- /// Get a variable value
- #[command(after_long_help = r#"Variables:
-
-- **default-branch**: The repository's default branch (main, master, etc.)
-- **marker**: Custom status marker for a branch (shown in `wt list`)
-- **ci-status**: CI/PR status for a branch (passed, running, failed, conflicts, noci)
+pub enum CiStatusAction {
+ /// Get CI status for a branch
+ #[command(
+ after_long_help = r#"Returns: passed, running, failed, conflicts, noci, or error.
## Examples
-Get the default branch:
+Get CI status for current branch:
```console
-wt config var get default-branch
+wt config state ci-status get
```
-Force refresh from remote:
+Force refresh from GitHub/GitLab:
```console
-wt config var get default-branch --refresh
+wt config state ci-status get --refresh
```
-Get marker for current branch:
+Get CI status for a specific branch:
```console
-wt config var get marker
-```
+wt config state ci-status get --branch=feature
+```"#
+ )]
+ Get {
+ /// Force refresh from GitHub/GitLab
+ #[arg(long)]
+ refresh: bool,
-Get marker for a specific branch:
+ /// Target branch (defaults to current)
+ #[arg(long, add = crate::completion::branch_value_completer())]
+ branch: Option<String>,
+ },
+
+ /// Clear CI status cache
+ #[command(after_long_help = r#"## Examples
+
+Clear CI status for current branch:
```console
-wt config var get marker --branch=feature
+wt config state ci-status clear
```
-Get CI status for current branch:
+Clear CI status for a specific branch:
```console
-wt config var get ci-status
+wt config state ci-status clear --branch=feature
```
-Force refresh CI status (bypass cache):
+Clear all CI status cache:
```console
-wt config var get ci-status --refresh
+wt config state ci-status clear --all
```"#)]
- Get {
- /// Variable: 'default-branch', 'marker', or 'ci-status'
- #[arg(value_parser = ["default-branch", "marker", "ci-status"])]
- key: String,
+ Clear {
+ /// Target branch (defaults to current)
+ #[arg(long, add = crate::completion::branch_value_completer(), conflicts_with = "all")]
+ branch: Option<String>,
- /// Force refresh (for cached variables)
+ /// Clear all CI status cache
#[arg(long)]
- refresh: bool,
+ all: bool,
+ },
+}
+
+#[derive(Subcommand)]
+pub enum MarkerAction {
+ /// Get marker for a branch
+ #[command(after_long_help = r#"## Examples
- /// Target branch (for branch-scoped variables)
+Get marker for current branch:
+```console
+wt config state marker get
+```
+
+Get marker for a specific branch:
+```console
+wt config state marker get --branch=feature
+```"#)]
+ Get {
+ /// Target branch (defaults to current)
#[arg(long, add = crate::completion::branch_value_completer())]
branch: Option<String>,
},
- /// Set a variable value
- #[command(after_long_help = r#"Variables:
-
-- **marker**: Custom status marker displayed in `wt list` output
-
-## Examples
+ /// Set marker for a branch
+ #[command(after_long_help = r#"## Examples
Set marker for current branch:
```console
-wt config var set marker "🚧 WIP"
+wt config state marker set "🚧 WIP"
```
Set marker for a specific branch:
```console
-wt config var set marker "βœ… ready" --branch=feature
+wt config state marker set "βœ… ready" --branch=feature
```"#)]
Set {
- /// Variable: 'marker'
- #[arg(value_parser = ["marker"])]
- key: String,
-
- /// Value to set
+ /// Marker text (shown in `wt list` output)
value: String,
/// Target branch (defaults to current)
@@ -557,42 +610,53 @@ wt config var set marker "βœ… ready" --branch=feature
branch: Option<String>,
},
- /// Clear a variable value
- #[command(after_long_help = r#"Variables:
-
-- **marker**: Custom status marker for a branch
-
-## Examples
+ /// Clear marker for a branch
+ #[command(after_long_help = r#"## Examples
Clear marker for current branch:
```console
-wt config var clear marker
+wt config state marker clear
```
Clear marker for a specific branch:
```console
-wt config var clear marker --branch=feature
+wt config state marker clear --branch=feature
```
Clear all markers:
```console
-wt config var clear marker --all
+wt config state marker clear --all
```"#)]
Clear {
- /// Variable: 'marker'
- #[arg(value_parser = ["marker"])]
- key: String,
-
/// Target branch (defaults to current)
#[arg(long, add = crate::completion::branch_value_completer(), conflicts_with = "all")]
branch: Option<String>,
- /// Clear all values
+ /// Clear all markers
#[arg(long)]
all: bool,
},
}
+#[derive(Subcommand)]
+pub enum LogsAction {
+ /// List background operation log files
+ #[command(
+ after_long_help = r#"Lists log files from background operations like post-start commands and worktree removal.
+
+## Examples
+
+List log files:
+```console
+wt config state logs get
+```"#
+ )]
+ Get,
+
+ /// Clear background operation logs
+ Clear,
+}
+
/// Run individual workflow operations
#[derive(Subcommand)]
pub enum StepCommand {
@@ -1110,7 +1174,7 @@ WORKTRUNK_COMMIT_GENERATION__ARGS="test: automated commit" \
<!-- subdoc: create -->
-<!-- subdoc: var -->
+<!-- subdoc: state -->
"#
)]
Config {
@@ -1615,7 +1679,7 @@ The CI column shows GitHub/GitLab pipeline status:
| `●` gray | No checks configured |
| (blank) | No upstream or no PR/MR |
-CI indicators are clickable links to the PR or pipeline page. Any CI dot appears dimmed when there are unpushed local changes (stale status). PRs/MRs are checked first, then branch workflows/pipelines for branches with an upstream. Local-only branches show blank. Results are cached for 30-60 seconds; use `wt config cache` to view or clear.
+CI indicators are clickable links to the PR or pipeline page. Any CI dot appears dimmed when there are unpushed local changes (stale status). PRs/MRs are checked first, then branch workflows/pipelines for branches with an upstream. Local-only branches show blank. Results are cached for 30-60 seconds; use `wt config state` to view or clear.
## Status symbols
diff --git a/src/commands/config.rs b/src/commands/config.rs
index e5f8c9c52..ed062c37a 100644
--- a/src/commands/config.rs
+++ b/src/commands/config.rs
@@ -15,6 +15,7 @@ use worktrunk::styling::{
use super::configure_shell::{ConfigAction, scan_shell_configs};
use super::list::ci_status::CachedCiStatus;
+use crate::display::format_relative_time_short;
use crate::help_pager::show_help_in_pager;
use crate::llm::test_commit_generation;
use crate::output;
@@ -556,8 +557,35 @@ fn require_user_config_path() -> anyhow::Result<PathBuf> {
})
}
-/// Handle the var get command
-pub fn handle_var_get(key: &str, refresh: bool, branch: Option<String>) -> anyhow::Result<()> {
+/// Clear all log files from the wt-logs directory
+fn clear_logs(repo: &Repository) -> anyhow::Result<usize> {
+ let git_common_dir = repo.git_common_dir()?;
+ let log_dir = git_common_dir.join("wt-logs");
+
+ if !log_dir.exists() {
+ return Ok(0);
+ }
+
+ let mut cleared = 0;
+ for entry in std::fs::read_dir(&log_dir)? {
+ let entry = entry?;
+ let path = entry.path();
+ if path.is_file() && path.extension().is_some_and(|ext| ext == "log") {
+ std::fs::remove_file(&path)?;
+ cleared += 1;
+ }
+ }
+
+ // Remove the directory if empty
+ if std::fs::read_dir(&log_dir)?.next().is_none() {
+ let _ = std::fs::remove_dir(&log_dir);
+ }
+
+ Ok(cleared)
+}
+
+/// Handle the state get command
+pub fn handle_state_get(key: &str, refresh: bool, branch: Option<String>) -> anyhow::Result<()> {
use super::list::ci_status::PrStatus;
let repo = Repository::current();
@@ -613,7 +641,6 @@ pub fn handle_var_get(key: &str, refresh: bool, branch: Option<String>) -> anyho
let has_upstream = repo.upstream_branch(&branch_name).ok().flatten().is_some();
match PrStatus::detect(&branch_name, &head, &repo_root, has_upstream) {
Some(status) => {
- // Output the CI status as a simple string for piping
let status_str = match status.ci_status {
super::list::ci_status::CiStatus::Passed => "passed",
super::list::ci_status::CiStatus::Running => "running",
@@ -629,25 +656,82 @@ pub fn handle_var_get(key: &str, refresh: bool, branch: Option<String>) -> anyho
}
}
}
- _ => anyhow::bail!(
- "Unknown variable: {key}. Valid variables: default-branch, marker, ci-status"
- ),
+ "logs" => {
+ let git_common_dir = repo.git_common_dir()?;
+ let log_dir = git_common_dir.join("wt-logs");
+
+ if !log_dir.exists() {
+ crate::output::print(info_message("No logs"))?;
+ return Ok(());
+ }
+
+ let mut entries: Vec<_> = std::fs::read_dir(&log_dir)?
+ .filter_map(|e| e.ok())
+ .filter(|e| {
+ e.path().is_file() && e.path().extension().is_some_and(|ext| ext == "log")
+ })
+ .collect();
+
+ if entries.is_empty() {
+ crate::output::print(info_message("No logs"))?;
+ return Ok(());
+ }
+
+ // Sort by modification time (newest first)
+ entries.sort_by(|a, b| {
+ let a_time = a.metadata().and_then(|m| m.modified()).ok();
+ let b_time = b.metadata().and_then(|m| m.modified()).ok();
+ b_time.cmp(&a_time)
+ });
+
+ // Build table
+ let mut table = String::from("| File | Size | Modified |\n");
+ table.push_str("|------|------|----------|\n");
+
+ for entry in entries {
+ let path = entry.path();
+ let name = path.file_name().unwrap_or_default().to_string_lossy();
+ let meta = entry.metadata().ok();
+
+ let size = meta.as_ref().map(|m| m.len()).unwrap_or(0);
+ let size_str = if size < 1024 {
+ format!("{size}B")
+ } else {
+ format!("{}K", size / 1024)
+ };
+
+ let age = meta
+ .and_then(|m| m.modified().ok())
+ .and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok())
+ .map(|d| format_relative_time_short(d.as_secs() as i64))
+ .unwrap_or_else(|| "?".to_string());
+
+ table.push_str(&format!("| {name} | {size_str} | {age} |\n"));
+ }
+
+ let rendered = crate::md_help::render_markdown_table(&table);
+ crate::output::table(rendered.trim_end())?;
+ }
+ _ => {
+ anyhow::bail!("Unknown key: {key}. Valid keys: default-branch, ci-status, marker, logs")
+ }
}
Ok(())
}
-/// Handle the var set command
-pub fn handle_var_set(key: &str, value: String, branch: Option<String>) -> anyhow::Result<()> {
+/// Handle the state set command
+pub fn handle_state_set(key: &str, value: String, branch: Option<String>) -> anyhow::Result<()> {
let repo = Repository::current();
match key {
+ "default-branch" => {
+ repo.set_default_branch(&value)?;
+ crate::output::print(success_message(cformat!(
+ "Set default branch to <bold>{value}</>"
+ )))?;
+ }
"marker" => {
- // TODO: Worktree-specific marker (worktrunk.marker with --worktree flag) would allow
- // different markers per worktree, but requires extensions.worktreeConfig which adds
- // complexity. Our intended workflow is one branch per worktree, so branch-keyed marker
- // is sufficient for now.
-
let branch_name = match branch {
Some(b) => b,
None => repo.require_current_branch("set marker for current branch")?,
@@ -660,22 +744,58 @@ pub fn handle_var_set(key: &str, value: String, branch: Option<String>) -> anyho
"Set marker for <bold>{branch_name}</> to <bold>{value}</>"
)))?;
}
- _ => anyhow::bail!("Unknown variable: {key}. Valid variables: marker"),
+ _ => anyhow::bail!("Unknown key: {key}. Valid keys: default-branch, marker"),
}
Ok(())
}
-/// Handle the var clear command
-pub fn handle_var_clear(key: &str, branch: Option<String>, all: bool) -> anyhow::Result<()> {
+/// Handle the state clear command
+pub fn handle_state_clear(key: &str, branch: Option<String>, all: bool) -> anyhow::Result<()> {
let repo = Repository::current();
match key {
+ "default-branch" => {
+ repo.clear_default_branch_cache()?;
+ crate::output::print(success_message("Cleared default branch cache"))?;
+ }
+ "ci-status" => {
+ if all {
+ let cleared = CachedCiStatus::clear_all(&repo);
+ if cleared == 0 {
+ crate::output::print(info_message("No CI cache entries to clear"))?;
+ } else {
+ crate::output::print(success_message(cformat!(
+ "Cleared <bold>{cleared}</> CI cache entr{}",
+ if cleared == 1 { "y" } else { "ies" }
+ )))?;
+ }
+ } else {
+ // Clear CI status for specific branch
+ let branch_name = match branch {
+ Some(b) => b,
+ None => repo.require_current_branch("clear ci-status for current branch")?,
+ };
+ let config_key = format!(
+ "worktrunk.ci.{}",
+ super::list::ci_status::CachedCiStatus::escape_branch(&branch_name)
+ );
+ if repo
+ .run_command(&["config", "--unset", &config_key])
+ .is_ok()
+ {
+ crate::output::print(success_message(cformat!(
+ "Cleared CI cache for <bold>{branch_name}</>"
+ )))?;
+ } else {
+ crate::output::print(info_message(cformat!(
+ "No CI cache for <bold>{branch_name}</>"
+ )))?;
+ }
+ }
+ }
"marker" => {
if all {
- // Clear all branch-keyed markers
- // Note: git config --get-regexp exits with code 1 when no matches found,
- // so we treat errors the same as empty output (both mean "no markers")
let output = repo
.run_command(&["config", "--get-regexp", "^worktrunk\\.marker\\."])
.unwrap_or_default();
@@ -697,7 +817,6 @@ pub fn handle_var_clear(key: &str, branch: Option<String>, all: bool) -> anyhow:
)))?;
}
} else {
- // Clear specific branch marker
let branch_name = match branch {
Some(b) => b,
None => repo.require_current_branch("clear marker for current branch")?,
@@ -712,18 +831,31 @@ pub fn handle_var_clear(key: &str, branch: Option<String>, all: bool) -> anyhow:
)))?;
}
}
- _ => anyhow::bail!("Unknown variable: {key}. Valid variables: marker"),
+ "logs" => {
+ let cleared = clear_logs(&repo)?;
+ if cleared == 0 {
+ crate::output::print(info_message("No logs to clear"))?;
+ } else {
+ crate::output::print(success_message(cformat!(
+ "Cleared <bold>{cleared}</> log file{}",
+ if cleared == 1 { "" } else { "s" }
+ )))?;
+ }
+ }
+ _ => {
+ anyhow::bail!("Unknown key: {key}. Valid keys: default-branch, ci-status, marker, logs")
+ }
}
Ok(())
}
-/// Handle the cache show command
-pub fn handle_cache_show() -> anyhow::Result<()> {
+/// Handle the state show command
+pub fn handle_state_show() -> anyhow::Result<()> {
let repo = Repository::current();
- // Show default branch cache (value from git config, so use gutter)
- crate::output::print(info_message("Default branch cache:"))?;
+ // Show default branch cache
+ crate::output::print(info_message("Default branch:"))?;
match repo.default_branch() {
Ok(branch) => crate::output::gutter(format_with_gutter(&branch, "", None))?,
Err(_) => crate::output::gutter(format_with_gutter("(not cached)", "", None))?,
@@ -772,106 +904,6 @@ pub fn handle_cache_show() -> anyhow::Result<()> {
Ok(())
}
-/// Handle the cache clear command
-pub fn handle_cache_clear(cache_type: Option<String>) -> anyhow::Result<()> {
- let repo = Repository::current();
-
- match cache_type.as_deref() {
- Some("ci") => {
- let cleared = CachedCiStatus::clear_all(&repo);
- if cleared == 0 {
- crate::output::print(info_message("No CI cache entries to clear"))?;
- } else {
- crate::output::print(success_message(cformat!(
- "Cleared <bold>{cleared}</> CI cache entr{}",
- if cleared == 1 { "y" } else { "ies" }
- )))?;
- }
- }
- Some("default-branch") => {
- if repo
- .run_command(&["config", "--unset", "worktrunk.defaultBranch"])
- .is_ok()
- {
- crate::output::print(success_message("Cleared default branch cache"))?;
- } else {
- crate::output::print(info_message("No default branch cache to clear"))?;
- }
- }
- Some("logs") => {
- let cleared = clear_logs(&repo)?;
- if cleared == 0 {
- crate::output::print(info_message("No logs to clear"))?;
- } else {
- crate::output::print(success_message(cformat!(
- "Cleared <bold>{cleared}</> log file{}",
- if cleared == 1 { "" } else { "s" }
- )))?;
- }
- }
- None => {
- let cleared_default = repo
- .run_command(&["config", "--unset", "worktrunk.defaultBranch"])
- .is_ok();
- let cleared_ci = CachedCiStatus::clear_all(&repo) > 0;
- let cleared_logs = clear_logs(&repo)? > 0;
-
- if cleared_default || cleared_ci || cleared_logs {
- crate::output::print(success_message("Cleared all caches"))?;
- } else {
- crate::output::print(info_message("No caches to clear"))?;
- }
- }
- Some(unknown) => {
- anyhow::bail!("Unknown cache type: {unknown}. Valid types: ci, default-branch, logs");
- }
- }
-
- Ok(())
-}
-
-/// Clear all log files from the wt-logs directory
-fn clear_logs(repo: &Repository) -> anyhow::Result<usize> {
- let git_common_dir = repo.git_common_dir()?;
- let log_dir = git_common_dir.join("wt-logs");
-
- if !log_dir.exists() {
- return Ok(0);
- }
-
- let mut cleared = 0;
- for entry in std::fs::read_dir(&log_dir)? {
- let entry = entry?;
- let path = entry.path();
- if path.is_file() && path.extension().is_some_and(|ext| ext == "log") {
- std::fs::remove_file(&path)?;
- cleared += 1;
- }
- }
-
- // Remove the directory if empty
- if std::fs::read_dir(&log_dir)?.next().is_none() {
- let _ = std::fs::remove_dir(&log_dir);
- }
-
- Ok(cleared)
-}
-
-/// Handle the cache refresh command (refreshes default branch)
-pub fn handle_cache_refresh() -> anyhow::Result<()> {
- let repo = Repository::current();
-
- crate::output::print(progress_message("Querying remote for default branch..."))?;
-
- let branch = repo.refresh_default_branch()?;
-
- crate::output::print(success_message(cformat!(
- "Cache refreshed: <bold>{branch}</>"
- )))?;
-
- Ok(())
-}
-
#[cfg(test)]
mod tests {
use super::*;
diff --git a/src/commands/list/mod.rs b/src/commands/list/mod.rs
index 16e67e797..198e48776 100644
--- a/src/commands/list/mod.rs
+++ b/src/commands/list/mod.rs
@@ -16,7 +16,7 @@
//! 2. **Default branch lookup** (~1-5ms)
//! - Reads cached value from `.git/refs/remotes/origin/HEAD`
//! - Falls back to `git remote show origin` if not cached (~100-300ms network)
-//! - Refresh with `wt config cache refresh`
+//! - Refresh with `wt config state get default-branch --refresh`
//!
//! 3. **Sort worktrees** (<1ms)
//! - Orders by: current β†’ main β†’ rest by timestamp (most recent first)
@@ -95,7 +95,7 @@
//! This is a git-native cache stored in `.git/refs/remotes/origin/HEAD`. All other data is
//! fetched fresh on each `wt list` invocation.
//!
-//! Refresh with: `wt config cache refresh`
+//! Refresh with: `wt config state get default-branch --refresh`
//!
//! ## Performance Characteristics
//!
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index a30b49750..b76c6d00b 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -20,8 +20,8 @@ pub mod worktree;
pub use command_approval::approve_hooks;
pub use config::{
- handle_cache_clear, handle_cache_refresh, handle_cache_show, handle_config_create,
- handle_config_show, handle_var_clear, handle_var_get, handle_var_set,
+ handle_config_create, handle_config_show, handle_state_clear, handle_state_get,
+ handle_state_set, handle_state_show,
};
pub use configure_shell::{
ConfigAction, handle_configure_shell, handle_show_theme, handle_unconfigure_shell,
diff --git a/src/git/repository/mod.rs b/src/git/repository/mod.rs
index 72bd5317c..4f6d6591a 100644
--- a/src/git/repository/mod.rs
+++ b/src/git/repository/mod.rs
@@ -423,7 +423,7 @@ impl Repository {
// Fallback: No remote or remote query failed, try to infer locally
// TODO: Show message to user when using inference fallback:
// "No remote configured. Using inferred default branch: {branch}"
- // "To cache the default branch, set up a remote and run: wt config cache refresh"
+ // "To cache the default branch, set up a remote and run: wt config state get default-branch --refresh"
// Problem: git.rs is in lib crate, output module is in binary.
// Options: (1) Return info about whether fallback was used, let callers show message
// (2) Add messages in specific commands (merge.rs, worktree.rs)
@@ -1261,6 +1261,26 @@ impl Repository {
Ok(branch)
}
+ /// Set the default branch manually.
+ ///
+ /// This sets the local cache (`refs/remotes/<remote>/HEAD`) to point to the
+ /// specified branch. Use `--refresh` to re-query the remote and overwrite
+ /// this value.
+ pub fn set_default_branch(&self, branch: &str) -> anyhow::Result<()> {
+ let remote = self.primary_remote()?;
+ self.cache_default_branch(&remote, branch)
+ }
+
+ /// Clear the default branch cache.
+ ///
+ /// Removes `refs/remotes/<remote>/HEAD` so the next call to `default_branch()`
+ /// will re-query the remote.
+ pub fn clear_default_branch_cache(&self) -> anyhow::Result<()> {
+ let remote = self.primary_remote()?;
+ self.run_command(&["remote", "set-head", "-d", &remote])?;
+ Ok(())
+ }
+
/// Check if two refs have identical tree content (same files/directories).
/// Returns true when content is identical even if commit history differs.
///
diff --git a/src/main.rs b/src/main.rs
index e2e756fd5..c24d96d6a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -27,18 +27,18 @@ use commands::handle_select;
use commands::worktree::{SwitchResult, handle_push};
use commands::{
ConfigAction, RebaseResult, SquashResult, add_approvals, approve_hooks, clear_approvals,
- compute_worktree_path, handle_cache_clear, handle_cache_refresh, handle_cache_show,
- handle_config_create, handle_config_show, handle_configure_shell, handle_hook_show,
- handle_init, handle_list, handle_merge, handle_rebase, handle_remove, handle_remove_by_path,
- handle_remove_current, handle_show_theme, handle_squash, handle_switch,
- handle_unconfigure_shell, handle_var_clear, handle_var_get, handle_var_set,
- resolve_worktree_path_first, run_hook, step_commit, step_for_each,
+ compute_worktree_path, handle_config_create, handle_config_show, handle_configure_shell,
+ handle_hook_show, handle_init, handle_list, handle_merge, handle_rebase, handle_remove,
+ handle_remove_by_path, handle_remove_current, handle_show_theme, handle_squash,
+ handle_state_clear, handle_state_get, handle_state_set, handle_state_show, handle_switch,
+ handle_unconfigure_shell, resolve_worktree_path_first, run_hook, step_commit, step_for_each,
};
use output::{execute_user_command, handle_remove_output, handle_switch_output};
use cli::{
- ApprovalsCommand, CacheCommand, Cli, Commands, ConfigCommand, ConfigShellCommand, HookCommand,
- ListSubcommand, StepCommand, VarCommand,
+ ApprovalsCommand, CiStatusAction, Cli, Commands, ConfigCommand, ConfigShellCommand,
+ DefaultBranchAction, HookCommand, ListSubcommand, LogsAction, MarkerAction, StateCommand,
+ StepCommand,
};
use worktrunk::HookType;
@@ -898,19 +898,38 @@ fn main() {
}
ConfigCommand::Create { project } => handle_config_create(project),
ConfigCommand::Show { full } => handle_config_show(full),
- ConfigCommand::Cache { action } => match action {
- CacheCommand::Show => handle_cache_show(),
- CacheCommand::Clear { cache_type } => handle_cache_clear(cache_type),
- CacheCommand::Refresh => handle_cache_refresh(),
- },
- ConfigCommand::Var { action } => match action {
- VarCommand::Get {
- key,
- refresh,
- branch,
- } => handle_var_get(&key, refresh, branch),
- VarCommand::Set { key, value, branch } => handle_var_set(&key, value, branch),
- VarCommand::Clear { key, branch, all } => handle_var_clear(&key, branch, all),
+ ConfigCommand::State { action } => match action {
+ StateCommand::DefaultBranch { action } => match action {
+ DefaultBranchAction::Get { refresh } => {
+ handle_state_get("default-branch", refresh, None)
+ }
+ DefaultBranchAction::Set { branch } => {
+ handle_state_set("default-branch", branch, None)
+ }
+ DefaultBranchAction::Clear => handle_state_clear("default-branch", None, false),
+ },
+ StateCommand::CiStatus { action } => match action {
+ CiStatusAction::Get { refresh, branch } => {
+ handle_state_get("ci-status", refresh, branch)
+ }
+ CiStatusAction::Clear { branch, all } => {
+ handle_state_clear("ci-status", branch, all)
+ }
+ },
+ StateCommand::Marker { action } => match action {
+ MarkerAction::Get { branch } => handle_state_get("marker", false, branch),
+ MarkerAction::Set { value, branch } => {
+ handle_state_set("marker", value, branch)
+ }
+ MarkerAction::Clear { branch, all } => {
+ handle_state_clear("marker", branch, all)
+ }
+ },
+ StateCommand::Logs { action } => match action {
+ LogsAction::Get => handle_state_get("logs", false, None),
+ LogsAction::Clear => handle_state_clear("logs", None, false),
+ },
+ StateCommand::Show => handle_state_show(),
},
},
Commands::Step { action } => match action {
diff --git a/tests/integration_tests/config_cache.rs b/tests/integration_tests/config_cache.rs
deleted file mode 100644
index 1a62d1c98..000000000
--- a/tests/integration_tests/config_cache.rs
+++ /dev/null
@@ -1,208 +0,0 @@
-use crate::common::{TEST_EPOCH, TestRepo, repo, wt_command};
-use insta::assert_snapshot;
-use rstest::rstest;
-use std::process::Command;
-
-fn wt_config_cache_cmd(repo: &TestRepo, args: &[&str]) -> Command {
- let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
- cmd.args(["config", "cache"]);
- cmd.args(args);
- cmd.current_dir(repo.root_path());
- cmd
-}
-
-// ============================================================================
-// cache show
-// ============================================================================
-
-#[rstest]
-fn test_config_cache_show_empty(repo: TestRepo) {
- let output = wt_config_cache_cmd(&repo, &["show"]).output().unwrap();
- assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @r"
- βšͺ Default branch cache:
-   main
-
- βšͺ CI status cache:
-   (empty)
- ");
-}
-
-#[rstest]
-fn test_config_cache_show_with_default_branch(repo: TestRepo) {
- // Set default branch cache manually
- repo.git_command(&["config", "worktrunk.defaultBranch", "main"])
- .status()
- .unwrap();
-
- let output = wt_config_cache_cmd(&repo, &["show"]).output().unwrap();
- assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @r"
- βšͺ Default branch cache:
-   main
-
- βšͺ CI status cache:
-   (empty)
- ");
-}
-
-#[rstest]
-fn test_config_cache_show_with_ci_entries(repo: TestRepo) {
- // Add CI cache entries - use TEST_EPOCH for deterministic age=0s in snapshots
- repo.git_command(&[
- "config",
- "worktrunk.ci.feature",
- &format!(r#"{{"status":{{"ci_status":"passed","source":"pullrequest","is_stale":false}},"checked_at":{TEST_EPOCH},"head":"abc12345def67890"}}"#),
- ])
- .status()
- .unwrap();
-
- repo.git_command(&[
- "config",
- "worktrunk.ci.bugfix",
- &format!(r#"{{"status":{{"ci_status":"failed","source":"branch","is_stale":true}},"checked_at":{TEST_EPOCH},"head":"111222333444555"}}"#),
- ])
- .status()
- .unwrap();
-
- repo.git_command(&[
- "config",
- "worktrunk.ci.main",
- &format!(r#"{{"status":null,"checked_at":{TEST_EPOCH},"head":"deadbeef12345678"}}"#),
- ])
- .status()
- .unwrap();
-
- let output = wt_config_cache_cmd(&repo, &["show"]).output().unwrap();
- assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr));
-}
-
-// ============================================================================
-// cache clear
-// ============================================================================
-
-#[rstest]
-fn test_config_cache_clear_all_empty(repo: TestRepo) {
- let output = wt_config_cache_cmd(&repo, &["clear"]).output().unwrap();
- assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βšͺ No caches to clear");
-}
-
-#[rstest]
-fn test_config_cache_clear_all_with_data(repo: TestRepo) {
- // Set default branch cache
- repo.git_command(&["config", "worktrunk.defaultBranch", "main"])
- .status()
- .unwrap();
-
- let output = wt_config_cache_cmd(&repo, &["clear"]).output().unwrap();
- assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Cleared all caches");
-}
-
-#[rstest]
-fn test_config_cache_clear_default_branch(repo: TestRepo) {
- // Set default branch cache
- repo.git_command(&["config", "worktrunk.defaultBranch", "main"])
- .status()
- .unwrap();
-
- let output = wt_config_cache_cmd(&repo, &["clear", "default-branch"])
- .output()
- .unwrap();
- assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Cleared default branch cache");
-}
-
-#[rstest]
-fn test_config_cache_clear_default_branch_empty(repo: TestRepo) {
- let output = wt_config_cache_cmd(&repo, &["clear", "default-branch"])
- .output()
- .unwrap();
- assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βšͺ No default branch cache to clear");
-}
-
-#[rstest]
-fn test_config_cache_clear_ci_empty(repo: TestRepo) {
- let output = wt_config_cache_cmd(&repo, &["clear", "ci"])
- .output()
- .unwrap();
- assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βšͺ No CI cache entries to clear");
-}
-
-#[rstest]
-fn test_config_cache_clear_unknown_type(repo: TestRepo) {
- let output = wt_config_cache_cmd(&repo, &["clear", "unknown"])
- .output()
- .unwrap();
- assert!(!output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @r"
- error: invalid value 'unknown' for '[CACHE_TYPE]'
- [possible values: ci, default-branch, logs]
-
- For more information, try '--help'.
- ");
-}
-
-#[rstest]
-fn test_config_cache_clear_logs_empty(repo: TestRepo) {
- let output = wt_config_cache_cmd(&repo, &["clear", "logs"])
- .output()
- .unwrap();
- assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βšͺ No logs to clear");
-}
-
-#[rstest]
-fn test_config_cache_clear_logs_with_files(repo: TestRepo) {
- // Create wt-logs directory with some log files
- let git_dir = repo.root_path().join(".git");
- let log_dir = git_dir.join("wt-logs");
- std::fs::create_dir_all(&log_dir).unwrap();
- std::fs::write(log_dir.join("feature-post-start-npm.log"), "npm output").unwrap();
- std::fs::write(log_dir.join("bugfix-remove.log"), "remove output").unwrap();
-
- let output = wt_config_cache_cmd(&repo, &["clear", "logs"])
- .output()
- .unwrap();
- assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Cleared 2 log files");
-
- // Verify logs are gone
- assert!(!log_dir.exists());
-}
-
-#[rstest]
-fn test_config_cache_clear_logs_single_file(repo: TestRepo) {
- // Create wt-logs directory with one log file
- let git_dir = repo.root_path().join(".git");
- let log_dir = git_dir.join("wt-logs");
- std::fs::create_dir_all(&log_dir).unwrap();
- std::fs::write(log_dir.join("feature-remove.log"), "remove output").unwrap();
-
- let output = wt_config_cache_cmd(&repo, &["clear", "logs"])
- .output()
- .unwrap();
- assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Cleared 1 log file");
-}
-
-#[rstest]
-fn test_config_cache_clear_all_with_logs(repo: TestRepo) {
- // Create wt-logs directory with a log file
- let git_dir = repo.root_path().join(".git");
- let log_dir = git_dir.join("wt-logs");
- std::fs::create_dir_all(&log_dir).unwrap();
- std::fs::write(log_dir.join("feature-remove.log"), "remove output").unwrap();
-
- let output = wt_config_cache_cmd(&repo, &["clear"]).output().unwrap();
- assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Cleared all caches");
-
- // Verify logs are gone
- assert!(!log_dir.exists());
-}
diff --git a/tests/integration_tests/config_state.rs b/tests/integration_tests/config_state.rs
new file mode 100644
index 000000000..714ec2af8
--- /dev/null
+++ b/tests/integration_tests/config_state.rs
@@ -0,0 +1,421 @@
+use crate::common::{TEST_EPOCH, TestRepo, repo, wt_command};
+use insta::assert_snapshot;
+use rstest::rstest;
+use std::process::Command;
+
+/// Create a command for `wt config state <key> <action> [args...]`
+fn wt_state_cmd(repo: &TestRepo, key: &str, action: &str, args: &[&str]) -> Command {
+ let mut cmd = wt_command();
+ repo.clean_cli_env(&mut cmd);
+ cmd.args(["config", "state", key, action]);
+ cmd.args(args);
+ cmd.current_dir(repo.root_path());
+ cmd
+}
+
+fn wt_state_show_cmd(repo: &TestRepo) -> Command {
+ let mut cmd = wt_command();
+ repo.clean_cli_env(&mut cmd);
+ cmd.args(["config", "state", "show"]);
+ cmd.current_dir(repo.root_path());
+ cmd
+}
+
+// ============================================================================
+// default-branch
+// ============================================================================
+
+#[rstest]
+fn test_state_get_default_branch(repo: TestRepo) {
+ let output = wt_state_cmd(&repo, "default-branch", "get", &[])
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+ // data() writes to stdout for piping
+ assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "main");
+}
+
+#[rstest]
+fn test_state_get_default_branch_no_remote(repo: TestRepo) {
+ // Without remote, should infer from local branches
+ let output = wt_state_cmd(&repo, "default-branch", "get", &[])
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+ // Should return the current branch name (main)
+ assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "main");
+}
+
+#[rstest]
+fn test_state_set_default_branch(mut repo: TestRepo) {
+ // First set up a remote so set_default_branch works
+ repo.setup_remote("main");
+
+ // Create and push a develop branch so we can set it as default
+ repo.git_command(&["checkout", "-b", "develop"])
+ .status()
+ .unwrap();
+ repo.git_command(&["push", "origin", "develop"])
+ .status()
+ .unwrap();
+ repo.git_command(&["checkout", "main"]).status().unwrap();
+
+ let output = wt_state_cmd(&repo, "default-branch", "set", &["develop"])
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Set default branch to develop");
+
+ // Verify it was set by checking origin/HEAD
+ let output = repo
+ .git_command(&["symbolic-ref", "refs/remotes/origin/HEAD"])
+ .output()
+ .unwrap();
+ assert_eq!(
+ String::from_utf8_lossy(&output.stdout).trim(),
+ "refs/remotes/origin/develop"
+ );
+}
+
+#[rstest]
+fn test_state_clear_default_branch(mut repo: TestRepo) {
+ // Set up remote and set default branch first
+ repo.setup_remote("main");
+
+ let output = wt_state_cmd(&repo, "default-branch", "clear", &[])
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Cleared default branch cache");
+
+ // Verify it was cleared - origin/HEAD should not exist
+ let output = repo
+ .git_command(&["symbolic-ref", "refs/remotes/origin/HEAD"])
+ .output()
+ .unwrap();
+ assert!(!output.status.success());
+}
+
+// ============================================================================
+// ci-status
+// ============================================================================
+
+#[rstest]
+fn test_state_get_ci_status(repo: TestRepo) {
+ // Without any CI configured, should return "noci"
+ let output = wt_state_cmd(&repo, "ci-status", "get", &[])
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "noci");
+}
+
+#[rstest]
+fn test_state_get_ci_status_specific_branch(repo: TestRepo) {
+ repo.git_command(&["branch", "feature"]).status().unwrap();
+
+ // Without any CI configured, should return "noci"
+ let output = wt_state_cmd(&repo, "ci-status", "get", &["--branch", "feature"])
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "noci");
+}
+
+#[rstest]
+fn test_state_get_ci_status_nonexistent_branch(repo: TestRepo) {
+ // Should error for nonexistent branch
+ let output = wt_state_cmd(&repo, "ci-status", "get", &["--branch", "nonexistent"])
+ .output()
+ .unwrap();
+ assert!(!output.status.success());
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ assert!(stderr.contains("not found") || stderr.contains("nonexistent"));
+}
+
+#[rstest]
+fn test_state_clear_ci_status_all_empty(repo: TestRepo) {
+ let output = wt_state_cmd(&repo, "ci-status", "clear", &["--all"])
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βšͺ No CI cache entries to clear");
+}
+
+#[rstest]
+fn test_state_clear_ci_status_branch(repo: TestRepo) {
+ // Add CI cache entry
+ repo.git_command(&[
+ "config",
+ "worktrunk.ci.main",
+ &format!(r#"{{"status":{{"ci_status":"passed","source":"pullrequest","is_stale":false}},"checked_at":{TEST_EPOCH},"head":"abc12345"}}"#),
+ ])
+ .status()
+ .unwrap();
+
+ let output = wt_state_cmd(&repo, "ci-status", "clear", &[])
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Cleared CI cache for main");
+}
+
+#[rstest]
+fn test_state_clear_ci_status_branch_not_cached(repo: TestRepo) {
+ let output = wt_state_cmd(&repo, "ci-status", "clear", &[])
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βšͺ No CI cache for main");
+}
+
+// ============================================================================
+// marker
+// ============================================================================
+
+#[rstest]
+fn test_state_get_marker(repo: TestRepo) {
+ // Set a marker first
+ repo.git_command(&["config", "worktrunk.marker.main", "🚧"])
+ .status()
+ .unwrap();
+
+ let output = wt_state_cmd(&repo, "marker", "get", &[]).output().unwrap();
+ assert!(output.status.success());
+ // data() writes to stdout for piping
+ assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "🚧");
+}
+
+#[rstest]
+fn test_state_get_marker_empty(repo: TestRepo) {
+ let output = wt_state_cmd(&repo, "marker", "get", &[]).output().unwrap();
+ assert!(output.status.success());
+ // Empty output when no marker is set
+ assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "");
+}
+
+#[rstest]
+fn test_state_get_marker_specific_branch(repo: TestRepo) {
+ repo.git_command(&["branch", "feature"]).status().unwrap();
+
+ // Set a marker for feature branch
+ repo.git_command(&["config", "worktrunk.marker.feature", "πŸ”§"])
+ .status()
+ .unwrap();
+
+ let output = wt_state_cmd(&repo, "marker", "get", &["--branch", "feature"])
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+ // data() writes to stdout for piping
+ assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "πŸ”§");
+}
+
+#[rstest]
+fn test_state_set_marker_branch_default(repo: TestRepo) {
+ let output = wt_state_cmd(&repo, "marker", "set", &["🚧"])
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Set marker for main to 🚧");
+
+ // Verify it was set
+ let output = repo
+ .git_command(&["config", "--get", "worktrunk.marker.main"])
+ .output()
+ .unwrap();
+ assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "🚧");
+}
+
+#[rstest]
+fn test_state_set_marker_branch_specific(repo: TestRepo) {
+ repo.git_command(&["branch", "feature"]).status().unwrap();
+
+ let output = wt_state_cmd(&repo, "marker", "set", &["πŸ”§", "--branch", "feature"])
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Set marker for feature to πŸ”§");
+
+ // Verify it was set
+ let output = repo
+ .git_command(&["config", "--get", "worktrunk.marker.feature"])
+ .output()
+ .unwrap();
+ assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "πŸ”§");
+}
+
+#[rstest]
+fn test_state_clear_marker_branch_default(repo: TestRepo) {
+ // Set a marker first
+ repo.git_command(&["config", "worktrunk.marker.main", "🚧"])
+ .status()
+ .unwrap();
+
+ let output = wt_state_cmd(&repo, "marker", "clear", &[])
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Cleared marker for main");
+
+ // Verify it was unset
+ let output = repo
+ .git_command(&["config", "--get", "worktrunk.marker.main"])
+ .output()
+ .unwrap();
+ assert!(!output.status.success());
+}
+
+#[rstest]
+fn test_state_clear_marker_branch_specific(repo: TestRepo) {
+ // Set a marker first
+ repo.git_command(&["config", "worktrunk.marker.feature", "πŸ”§"])
+ .status()
+ .unwrap();
+
+ let output = wt_state_cmd(&repo, "marker", "clear", &["--branch", "feature"])
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Cleared marker for feature");
+
+ // Verify it was unset
+ let output = repo
+ .git_command(&["config", "--get", "worktrunk.marker.feature"])
+ .output()
+ .unwrap();
+ assert!(!output.status.success());
+}
+
+#[rstest]
+fn test_state_clear_marker_all(repo: TestRepo) {
+ // Set multiple markers
+ repo.git_command(&["config", "worktrunk.marker.main", "🚧"])
+ .status()
+ .unwrap();
+ repo.git_command(&["config", "worktrunk.marker.feature", "πŸ”§"])
+ .status()
+ .unwrap();
+ repo.git_command(&["config", "worktrunk.marker.bugfix", "πŸ›"])
+ .status()
+ .unwrap();
+
+ let output = wt_state_cmd(&repo, "marker", "clear", &["--all"])
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Cleared 3 markers");
+
+ // Verify all were unset
+ let output = repo
+ .git_command(&["config", "--get-regexp", "^worktrunk\\.marker\\."])
+ .output()
+ .unwrap();
+ assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "");
+}
+
+#[rstest]
+fn test_state_clear_marker_all_empty(repo: TestRepo) {
+ let output = wt_state_cmd(&repo, "marker", "clear", &["--all"])
+ .output()
+ .unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βšͺ No markers to clear");
+}
+
+// ============================================================================
+// logs
+// ============================================================================
+
+#[rstest]
+fn test_state_get_logs_empty(repo: TestRepo) {
+ let output = wt_state_cmd(&repo, "logs", "get", &[]).output().unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βšͺ No logs");
+}
+
+#[rstest]
+fn test_state_clear_logs_empty(repo: TestRepo) {
+ let output = wt_state_cmd(&repo, "logs", "clear", &[]).output().unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βšͺ No logs to clear");
+}
+
+#[rstest]
+fn test_state_clear_logs_with_files(repo: TestRepo) {
+ // Create wt-logs directory with some log files
+ let git_dir = repo.root_path().join(".git");
+ let log_dir = git_dir.join("wt-logs");
+ std::fs::create_dir_all(&log_dir).unwrap();
+ std::fs::write(log_dir.join("feature-post-start-npm.log"), "npm output").unwrap();
+ std::fs::write(log_dir.join("bugfix-remove.log"), "remove output").unwrap();
+
+ let output = wt_state_cmd(&repo, "logs", "clear", &[]).output().unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Cleared 2 log files");
+
+ // Verify logs are gone
+ assert!(!log_dir.exists());
+}
+
+#[rstest]
+fn test_state_clear_logs_single_file(repo: TestRepo) {
+ // Create wt-logs directory with one log file
+ let git_dir = repo.root_path().join(".git");
+ let log_dir = git_dir.join("wt-logs");
+ std::fs::create_dir_all(&log_dir).unwrap();
+ std::fs::write(log_dir.join("feature-remove.log"), "remove output").unwrap();
+
+ let output = wt_state_cmd(&repo, "logs", "clear", &[]).output().unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Cleared 1 log file");
+}
+
+// ============================================================================
+// state show
+// ============================================================================
+
+#[rstest]
+fn test_state_show_empty(repo: TestRepo) {
+ let output = wt_state_show_cmd(&repo).output().unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @r"
+ βšͺ Default branch:
+   main
+
+ βšͺ CI status cache:
+   (empty)
+ ");
+}
+
+#[rstest]
+fn test_state_show_with_ci_entries(repo: TestRepo) {
+ // Add CI cache entries - use TEST_EPOCH for deterministic age=0s in snapshots
+ repo.git_command(&[
+ "config",
+ "worktrunk.ci.feature",
+ &format!(r#"{{"status":{{"ci_status":"passed","source":"pullrequest","is_stale":false}},"checked_at":{TEST_EPOCH},"head":"abc12345def67890"}}"#),
+ ])
+ .status()
+ .unwrap();
+
+ repo.git_command(&[
+ "config",
+ "worktrunk.ci.bugfix",
+ &format!(r#"{{"status":{{"ci_status":"failed","source":"branch","is_stale":true}},"checked_at":{TEST_EPOCH},"head":"111222333444555"}}"#),
+ ])
+ .status()
+ .unwrap();
+
+ repo.git_command(&[
+ "config",
+ "worktrunk.ci.main",
+ &format!(r#"{{"status":null,"checked_at":{TEST_EPOCH},"head":"deadbeef12345678"}}"#),
+ ])
+ .status()
+ .unwrap();
+
+ let output = wt_state_show_cmd(&repo).output().unwrap();
+ assert!(output.status.success());
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr));
+}
diff --git a/tests/integration_tests/config_var.rs b/tests/integration_tests/config_var.rs
deleted file mode 100644
index 5f801c5f3..000000000
--- a/tests/integration_tests/config_var.rs
+++ /dev/null
@@ -1,225 +0,0 @@
-use crate::common::{TestRepo, repo, wt_command};
-use insta::assert_snapshot;
-use rstest::rstest;
-use std::process::Command;
-
-fn wt_var_set_cmd(repo: &TestRepo, args: &[&str]) -> Command {
- let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
- cmd.args(["config", "var", "set"]);
- cmd.args(args);
- cmd.current_dir(repo.root_path());
- cmd
-}
-
-fn wt_var_clear_cmd(repo: &TestRepo, args: &[&str]) -> Command {
- let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
- cmd.args(["config", "var", "clear"]);
- cmd.args(args);
- cmd.current_dir(repo.root_path());
- cmd
-}
-
-fn wt_var_get_cmd(repo: &TestRepo, args: &[&str]) -> Command {
- let mut cmd = wt_command();
- repo.clean_cli_env(&mut cmd);
- cmd.args(["config", "var", "get"]);
- cmd.args(args);
- cmd.current_dir(repo.root_path());
- cmd
-}
-
-#[rstest]
-fn test_var_set_marker_branch_default(repo: TestRepo) {
- let output = wt_var_set_cmd(&repo, &["marker", "🚧"]).output().unwrap();
- assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Set marker for main to 🚧");
-
- // Verify it was set
- let output = repo
- .git_command(&["config", "--get", "worktrunk.marker.main"])
- .output()
- .unwrap();
- assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "🚧");
-}
-
-#[rstest]
-fn test_var_set_marker_branch_specific(repo: TestRepo) {
- repo.git_command(&["branch", "feature"]).status().unwrap();
-
- let output = wt_var_set_cmd(&repo, &["marker", "πŸ”§", "--branch", "feature"])
- .output()
- .unwrap();
- assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Set marker for feature to πŸ”§");
-
- // Verify it was set
- let output = repo
- .git_command(&["config", "--get", "worktrunk.marker.feature"])
- .output()
- .unwrap();
- assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "πŸ”§");
-}
-
-#[rstest]
-fn test_var_clear_marker_branch_default(repo: TestRepo) {
- // Set a marker first
- repo.git_command(&["config", "worktrunk.marker.main", "🚧"])
- .status()
- .unwrap();
-
- let output = wt_var_clear_cmd(&repo, &["marker"]).output().unwrap();
- assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Cleared marker for main");
-
- // Verify it was unset
- let output = repo
- .git_command(&["config", "--get", "worktrunk.marker.main"])
- .output()
- .unwrap();
- assert!(!output.status.success());
-}
-
-#[rstest]
-fn test_var_clear_marker_branch_specific(repo: TestRepo) {
- // Set a marker first
- repo.git_command(&["config", "worktrunk.marker.feature", "πŸ”§"])
- .status()
- .unwrap();
-
- let output = wt_var_clear_cmd(&repo, &["marker", "--branch", "feature"])
- .output()
- .unwrap();
- assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Cleared marker for feature");
-
- // Verify it was unset
- let output = repo
- .git_command(&["config", "--get", "worktrunk.marker.feature"])
- .output()
- .unwrap();
- assert!(!output.status.success());
-}
-
-#[rstest]
-fn test_var_clear_marker_all(repo: TestRepo) {
- // Set multiple markers
- repo.git_command(&["config", "worktrunk.marker.main", "🚧"])
- .status()
- .unwrap();
- repo.git_command(&["config", "worktrunk.marker.feature", "πŸ”§"])
- .status()
- .unwrap();
- repo.git_command(&["config", "worktrunk.marker.bugfix", "πŸ›"])
- .status()
- .unwrap();
-
- let output = wt_var_clear_cmd(&repo, &["marker", "--all"])
- .output()
- .unwrap();
- assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βœ… Cleared 3 markers");
-
- // Verify all were unset
- let output = repo
- .git_command(&["config", "--get-regexp", "^worktrunk\\.marker\\."])
- .output()
- .unwrap();
- assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "");
-}
-
-#[rstest]
-fn test_var_clear_marker_all_empty(repo: TestRepo) {
- let output = wt_var_clear_cmd(&repo, &["marker", "--all"])
- .output()
- .unwrap();
- assert!(output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @"βšͺ No markers to clear");
-}
-
-#[rstest]
-fn test_var_get_marker(repo: TestRepo) {
- // Set a marker first
- repo.git_command(&["config", "worktrunk.marker.main", "🚧"])
- .status()
- .unwrap();
-
- let output = wt_var_get_cmd(&repo, &["marker"]).output().unwrap();
- assert!(output.status.success());
- // data() writes to stdout for piping
- assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "🚧");
-}
-
-#[rstest]
-fn test_var_get_marker_empty(repo: TestRepo) {
- let output = wt_var_get_cmd(&repo, &["marker"]).output().unwrap();
- assert!(output.status.success());
- // Empty output when no marker is set
- assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "");
-}
-
-#[rstest]
-fn test_var_get_marker_specific_branch(repo: TestRepo) {
- repo.git_command(&["branch", "feature"]).status().unwrap();
-
- // Set a marker for feature branch
- repo.git_command(&["config", "worktrunk.marker.feature", "πŸ”§"])
- .status()
- .unwrap();
-
- let output = wt_var_get_cmd(&repo, &["marker", "--branch", "feature"])
- .output()
- .unwrap();
- assert!(output.status.success());
- // data() writes to stdout for piping
- assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "πŸ”§");
-}
-
-#[rstest]
-fn test_var_get_default_branch(repo: TestRepo) {
- let output = wt_var_get_cmd(&repo, &["default-branch"]).output().unwrap();
- assert!(output.status.success());
- // data() writes to stdout for piping
- assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "main");
-}
-
-#[rstest]
-fn test_var_get_default_branch_no_remote(repo: TestRepo) {
- // Without remote, should infer from local branches
- let output = wt_var_get_cmd(&repo, &["default-branch"]).output().unwrap();
- assert!(output.status.success());
- // Should return the current branch name (main)
- assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "main");
-}
-
-#[rstest]
-fn test_var_get_ci_status(repo: TestRepo) {
- // Without any CI configured, should return "noci"
- let output = wt_var_get_cmd(&repo, &["ci-status"]).output().unwrap();
- assert!(output.status.success());
- assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "noci");
-}
-
-#[rstest]
-fn test_var_get_ci_status_specific_branch(repo: TestRepo) {
- repo.git_command(&["branch", "feature"]).status().unwrap();
-
- // Without any CI configured, should return "noci"
- let output = wt_var_get_cmd(&repo, &["ci-status", "--branch", "feature"])
- .output()
- .unwrap();
- assert!(output.status.success());
- assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "noci");
-}
-
-#[rstest]
-fn test_var_get_ci_status_nonexistent_branch(repo: TestRepo) {
- // Should error for nonexistent branch
- let output = wt_var_get_cmd(&repo, &["ci-status", "--branch", "nonexistent"])
- .output()
- .unwrap();
- assert!(!output.status.success());
- let stderr = String::from_utf8_lossy(&output.stderr);
- assert!(stderr.contains("not found") || stderr.contains("nonexistent"));
-}
diff --git a/tests/integration_tests/help.rs b/tests/integration_tests/help.rs
index 1b37c9426..07295b77b 100644
--- a/tests/integration_tests/help.rs
+++ b/tests/integration_tests/help.rs
@@ -51,10 +51,15 @@ fn snapshot_help(test_name: &str, args: &[&str]) {
#[case("help_config_shell", "config shell --help")]
#[case("help_config_create", "config create --help")]
#[case("help_config_show", "config show --help")]
-#[case("help_config_var", "config var --help")]
-#[case("help_config_var_get", "config var get --help")]
-#[case("help_config_var_set", "config var set --help")]
-#[case("help_config_var_clear", "config var clear --help")]
+#[case("help_config_state", "config state --help")]
+#[case(
+ "help_config_state_default_branch",
+ "config state default-branch --help"
+)]
+#[case("help_config_state_ci_status", "config state ci-status --help")]
+#[case("help_config_state_marker", "config state marker --help")]
+#[case("help_config_state_logs", "config state logs --help")]
+#[case("help_config_state_show", "config state show --help")]
#[case("help_hook_approvals", "hook approvals --help")]
#[case("help_hook_approvals_add", "hook approvals add --help")]
#[case("help_hook_approvals_clear", "hook approvals clear --help")]
diff --git a/tests/integration_tests/mod.rs b/tests/integration_tests/mod.rs
index 6905d3a85..e22596680 100644
--- a/tests/integration_tests/mod.rs
+++ b/tests/integration_tests/mod.rs
@@ -14,11 +14,10 @@ pub mod bare_repository;
pub mod column_alignment_verification;
pub mod completion;
pub mod completion_validation;
-pub mod config_cache;
pub mod config_init;
pub mod config_show;
pub mod config_show_theme;
-pub mod config_var;
+pub mod config_state;
pub mod configure_shell;
pub mod default_branch;
pub mod directives;
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__config_cache__config_cache_show_with_ci_entries.snap b/tests/integration_tests/snapshots/integration__integration_tests__config_state__state_show_with_ci_entries.snap
similarity index 80%
rename from tests/integration_tests/snapshots/integration__integration_tests__config_cache__config_cache_show_with_ci_entries.snap
rename to tests/integration_tests/snapshots/integration__integration_tests__config_state__state_show_with_ci_entries.snap
index 08e440156..97417a04e 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__config_cache__config_cache_show_with_ci_entries.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__config_state__state_show_with_ci_entries.snap
@@ -1,8 +1,8 @@
---
-source: tests/integration_tests/config_cache.rs
+source: tests/integration_tests/config_state.rs
expression: "String::from_utf8_lossy(&output.stderr)"
---
-βšͺ Default branch cache:
+βšͺ Default branch:
  main
βšͺ CI status cache:
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_long.snap b/tests/snapshots/integration__integration_tests__help__help_config_long.snap
index 5cb5615bf..cef91c772 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_long.snap
@@ -25,8 +25,7 @@ Usage: wt config [OPTIONS] <COMMAND>
shell Shell integration setup
create Create configuration file
show Show configuration files & locations
- cache Manage caches (CI status, default branch)
- var Get or set runtime variables (stored in git config)
+ state Get, set, or clear runtime state (stored in git config)
Options:
-h, --help
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_short.snap b/tests/snapshots/integration__integration_tests__help__help_config_short.snap
index 929be7ed3..3adcb1539 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_short.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_short.snap
@@ -25,8 +25,7 @@ Usage: wt config [OPTIONS] <COMMAND>
shell Shell integration setup
create Create configuration file
show Show configuration files & locations
- cache Manage caches (CI status, default branch)
- var Get or set runtime variables (stored in git config)
+ state Get, set, or clear runtime state (stored in git config)
Options:
-h, --help Print help (see more with '--help')
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_var_get.snap b/tests/snapshots/integration__integration_tests__help__help_config_state.snap
similarity index 50%
rename from tests/snapshots/integration__integration_tests__help__help_config_var_get.snap
rename to tests/snapshots/integration__integration_tests__help__help_config_state.snap
index d48b126e4..8417b7a53 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_var_get.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_state.snap
@@ -4,8 +4,7 @@ info:
program: wt
args:
- config
- - var
- - get
+ - state
- "--help"
env:
CLICOLOR_FORCE: "1"
@@ -19,23 +18,18 @@ exit_code: 0
----- stdout -----
----- stderr -----
-wt config var get - Get a variable value
+wt config state - Get, set, or clear runtime state (stored in git config)
-Usage: wt config var get [OPTIONS] <KEY>
+Usage: wt config state [OPTIONS] <COMMAND>
-Arguments:
- <KEY>
- Variable: 'default-branch', 'marker', or 'ci-status'
-
- [possible values: default-branch, marker, ci-status]
+Commands:
+ default-branch Manage default branch setting
+ ci-status Manage CI status cache
+ marker Manage branch markers
+ logs Manage background operation logs
+ show Show all cached state
Options:
- --refresh
- Force refresh (for cached variables)
-
- --branch <BRANCH>
- Target branch (for branch-scoped variables)
-
-h, --help
Print help (see a summary with '-h')
@@ -49,28 +43,29 @@ Usage: wt config var get [OPTIONS] <KEY>
-v, --verbose
Show commands and debug info
-Variables:
+Runtime state is stored in git config, separate from configuration files.
+Use wt config show to view file-based configuration.
+
+Keys
- default-branch: The repository's default branch (main, master, etc.)
-- marker: Custom status marker for a branch (shown in wt list)
- ci-status: CI/PR status for a branch (passed, running, failed, conflicts, noci)
+- marker: Custom status marker for a branch (shown in wt list)
+- logs: Background operation logs
Examples
Get the default branch:
- wt config var get default-branch
-
-Force refresh from remote:
- wt config var get default-branch --refresh
+ wt config state get default-branch
-Get marker for current branch:
- wt config var get marker
+Set the default branch manually:
+ wt config state set default-branch main
-Get marker for a specific branch:
- wt config var get marker --branch=feature
+Set a marker for current branch:
+ wt config state set marker "🚧 WIP"
-Get CI status for current branch:
- wt config var get ci-status
+Clear all CI status cache:
+ wt config state clear ci-status --all
-Force refresh CI status (bypass cache):
- wt config var get ci-status --refresh
+Show all cached state:
+ wt config state show
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_state_ci_status.snap b/tests/snapshots/integration__integration_tests__help__help_config_state_ci_status.snap
new file mode 100644
index 000000000..d2ad43791
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__help__help_config_state_ci_status.snap
@@ -0,0 +1,36 @@
+---
+source: tests/integration_tests/help.rs
+info:
+ program: wt
+ args:
+ - config
+ - state
+ - ci-status
+ - "--help"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_EDITOR: ""
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: /nonexistent/test/config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+wt config state ci-status - Manage CI status cache
+
+Usage: wt config state ci-status [OPTIONS] <COMMAND>
+
+Commands:
+ get Get CI status for a branch
+ clear Clear CI status cache
+
+Options:
+ -h, --help Print help
+
+Global Options:
+ -C <path> Working directory for this command
+ --config <path> User config file path
+ -v, --verbose Show commands and debug info
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_state_default_branch.snap b/tests/snapshots/integration__integration_tests__help__help_config_state_default_branch.snap
new file mode 100644
index 000000000..4304700fb
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__help__help_config_state_default_branch.snap
@@ -0,0 +1,37 @@
+---
+source: tests/integration_tests/help.rs
+info:
+ program: wt
+ args:
+ - config
+ - state
+ - default-branch
+ - "--help"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_EDITOR: ""
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: /nonexistent/test/config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+wt config state default-branch - Manage default branch setting
+
+Usage: wt config state default-branch [OPTIONS] <COMMAND>
+
+Commands:
+ get Get the default branch
+ set Set the default branch
+ clear Clear the default branch cache
+
+Options:
+ -h, --help Print help
+
+Global Options:
+ -C <path> Working directory for this command
+ --config <path> User config file path
+ -v, --verbose Show commands and debug info
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_state_logs.snap b/tests/snapshots/integration__integration_tests__help__help_config_state_logs.snap
new file mode 100644
index 000000000..fde16e0bf
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__help__help_config_state_logs.snap
@@ -0,0 +1,36 @@
+---
+source: tests/integration_tests/help.rs
+info:
+ program: wt
+ args:
+ - config
+ - state
+ - logs
+ - "--help"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_EDITOR: ""
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: /nonexistent/test/config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+wt config state logs - Manage background operation logs
+
+Usage: wt config state logs [OPTIONS] <COMMAND>
+
+Commands:
+ get List background operation log files
+ clear Clear background operation logs
+
+Options:
+ -h, --help Print help
+
+Global Options:
+ -C <path> Working directory for this command
+ --config <path> User config file path
+ -v, --verbose Show commands and debug info
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_state_marker.snap b/tests/snapshots/integration__integration_tests__help__help_config_state_marker.snap
new file mode 100644
index 000000000..23d809db7
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__help__help_config_state_marker.snap
@@ -0,0 +1,37 @@
+---
+source: tests/integration_tests/help.rs
+info:
+ program: wt
+ args:
+ - config
+ - state
+ - marker
+ - "--help"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_EDITOR: ""
+ SOURCE_DATE_EPOCH: "1735776000"
+ WORKTRUNK_CONFIG_PATH: /nonexistent/test/config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+wt config state marker - Manage branch markers
+
+Usage: wt config state marker [OPTIONS] <COMMAND>
+
+Commands:
+ get Get marker for a branch
+ set Set marker for a branch
+ clear Clear marker for a branch
+
+Options:
+ -h, --help Print help
+
+Global Options:
+ -C <path> Working directory for this command
+ --config <path> User config file path
+ -v, --verbose Show commands and debug info
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_var_set.snap b/tests/snapshots/integration__integration_tests__help__help_config_state_show.snap
similarity index 51%
rename from tests/snapshots/integration__integration_tests__help__help_config_var_set.snap
rename to tests/snapshots/integration__integration_tests__help__help_config_state_show.snap
index 784a70063..bfdcd618c 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_var_set.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_state_show.snap
@@ -4,8 +4,8 @@ info:
program: wt
args:
- config
- - var
- - set
+ - state
+ - show
- "--help"
env:
CLICOLOR_FORCE: "1"
@@ -19,23 +19,11 @@ exit_code: 0
----- stdout -----
----- stderr -----
-wt config var set - Set a variable value
+wt config state show - Show all cached state
-Usage: wt config var set [OPTIONS] <KEY> <VALUE>
-
-Arguments:
- <KEY>
- Variable: 'marker'
-
- [possible values: marker]
-
- <VALUE>
- Value to set
+Usage: wt config state show [OPTIONS]
Options:
- --branch <BRANCH>
- Target branch (defaults to current)
-
-h, --help
Print help (see a summary with '-h')
@@ -49,14 +37,9 @@ Usage: wt config var set [OPTIONS] <KEY> <VA
-v, --verbose
Show commands and debug info
-Variables:
-
-- marker: Custom status marker displayed in wt list output
-
-Examples
+Shows all cached state including:
-Set marker for current branch:
- wt config var set marker "🚧 WIP"
+- Default branch: Cached result of querying remote for default branch
+- CI status: Cached GitHub/GitLab CI status per branch (30s TTL)
-Set marker for a specific branch:
- wt config var set marker "βœ… ready" --branch=feature
+CI cache entries show status, age, and the commit SHA they were fetched for.
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_var.snap b/tests/snapshots/integration__integration_tests__help__help_config_var.snap
deleted file mode 100644
index 3ee91fbc4..000000000
--- a/tests/snapshots/integration__integration_tests__help__help_config_var.snap
+++ /dev/null
@@ -1,61 +0,0 @@
----
-source: tests/integration_tests/help.rs
-info:
- program: wt
- args:
- - config
- - var
- - "--help"
- env:
- CLICOLOR_FORCE: "1"
- COLUMNS: "150"
- GIT_EDITOR: ""
- SOURCE_DATE_EPOCH: "1735776000"
- WORKTRUNK_CONFIG_PATH: /nonexistent/test/config.toml
----
-success: true
-exit_code: 0
------ stdout -----
-
------ stderr -----
-wt config var - Get or set runtime variables (stored in git config)
-
-Usage: wt config var [OPTIONS] <COMMAND>
-
-Commands:
- get Get a variable value
- set Set a variable value
- clear Clear a variable value
-
-Options:
- -h, --help
- Print help (see a summary with '-h')
-
-Global Options:
- -C <path>
- Working directory for this command
-
- --config <path>
- User config file path
-
- -v, --verbose
- Show commands and debug info
-
-Variables are runtime values stored in git config, separate from
-configuration files. Use wt config show to view file-based configuration.
-
-Available variables
-
-- default-branch: The repository's default branch (read-only, cached)
-- marker: Custom status marker for a branch (shown in wt list)
-
-Examples
-
-Get the default branch:
- wt config var get default-branch
-
-Set a marker for current branch:
- wt config var set marker "🚧 WIP"
-
-Clear markers:
- wt config var clear marker --all
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_var_clear.snap b/tests/snapshots/integration__integration_tests__help__help_config_var_clear.snap
deleted file mode 100644
index 31dac3173..000000000
--- a/tests/snapshots/integration__integration_tests__help__help_config_var_clear.snap
+++ /dev/null
@@ -1,65 +0,0 @@
----
-source: tests/integration_tests/help.rs
-info:
- program: wt
- args:
- - config
- - var
- - clear
- - "--help"
- env:
- CLICOLOR_FORCE: "1"
- COLUMNS: "150"
- GIT_EDITOR: ""
- SOURCE_DATE_EPOCH: "1735776000"
- WORKTRUNK_CONFIG_PATH: /nonexistent/test/config.toml
----
-success: true
-exit_code: 0
------ stdout -----
-
------ stderr -----
-wt config var clear - Clear a variable value
-
-Usage: wt config var clear [OPTIONS] <KEY>
-
-Arguments:
- <KEY>
- Variable: 'marker'
-
- [possible values: marker]
-
-Options:
- --branch <BRANCH>
- Target branch (defaults to current)
-
- --all
- Clear all values
-
- -h, --help
- Print help (see a summary with '-h')
-
-Global Options:
- -C <path>
- Working directory for this command
-
- --config <path>
- User config file path
-
- -v, --verbose
- Show commands and debug info
-
-Variables:
-
-- marker: Custom status marker for a branch
-
-Examples
-
-Clear marker for current branch:
- wt config var clear marker
-
-Clear marker for a specific branch:
- wt config var clear marker --branch=feature
-
-Clear all markers:
- wt config var clear marker --all
diff --git a/tests/snapshots/integration__integration_tests__help__help_list_long.snap b/tests/snapshots/integration__integration_tests__help__help_list_long.snap
index 53b94e7cc..de16a4dd5 100644
--- a/tests/snapshots/integration__integration_tests__help__help_list_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_list_long.snap
@@ -113,7 +113,7 @@ The CI column shows GitHub/GitLab pipeline status:
CI indicators are clickable links to the PR or pipeline page. Any CI dot appears dimmed when there are unpushed local changes (stale status). PRs/MRs
are checked first, then branch workflows/pipelines for branches with an upstream. Local-only branches show blank. Results are cached for 30-60
-seconds; use wt config cache to view or clear.
+seconds; use wt config state to view or clear.
Status symbols