Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat: add [switch.picker] config with configurable timeout (#1087)
Maximilian Roos41eaf85aad82
diff --git a/dev/config.example.toml b/dev/config.example.tomlindex 96de01395..35d976a1f 100644--- a/dev/config.example.toml+++ b/dev/config.example.toml@@ -71,16 +71,18 @@# remove = true # Remove worktree after merge (--no-remove to keep)# verify = true # Run project hooks (--no-verify to skip)#-# ### Select+# ### Switch picker#-# Pager behavior for `wt switch` interactive picker diff previews.+# Configuration for `wt switch` interactive picker.#-# [select]-# # Pager command with flags for diff preview (overrides git's core.pager)-# # Use this to specify pager flags needed for non-TTY contexts-# # Example:+# [switch.picker]+# # Pager command for diff preview (overrides git's core.pager)# # pager = "delta --paging=never"#+# # Timeout (ms) for git commands during picker loading (default: 200)+# # Lower values show the TUI faster; 0 disables timeouts+# # timeout-ms = 200+## ### User project-specific settings## For context:diff --git a/docs/content/config.md b/docs/content/config.mdindex 1d8fa33b9..ef1dc6227 100644--- a/docs/content/config.md+++ b/docs/content/config.md@@ -148,16 +148,18 @@ remove = true # Remove worktree after merge (--no-remove to keep)verify = true # Run project hooks (--no-verify to skip)```-### Select+### Switch picker-Pager behavior for `wt switch` interactive picker diff previews.+Configuration for `wt switch` interactive picker.```toml-[select]-# Pager command with flags for diff preview (overrides git's core.pager)-# Use this to specify pager flags needed for non-TTY contexts-# Example:+[switch.picker]+# Pager command for diff preview (overrides git's core.pager)# pager = "delta --paging=never"++# Timeout (ms) for git commands during picker loading (default: 200)+# Lower values show the TUI faster; 0 disables timeouts+# timeout-ms = 200```### User project-specific settingsdiff --git a/docs/content/switch.md b/docs/content/switch.mdindex 7e866862a..088dab3f1 100644--- a/docs/content/switch.md+++ b/docs/content/switch.md@@ -108,7 +108,7 @@ When called without arguments, `wt switch` opens an interactive picker to browse**Pager configuration:** The preview panel pipes diff output through git's pager. Override in user config:```toml-[select]+[switch.picker]pager = "delta --paging=never --width=$COLUMNS"```diff --git a/skills/worktrunk/reference/config.md b/skills/worktrunk/reference/config.mdindex f2a0d3a2b..792dc7e97 100644--- a/skills/worktrunk/reference/config.md+++ b/skills/worktrunk/reference/config.md@@ -140,16 +140,18 @@ remove = true # Remove worktree after merge (--no-remove to keep)verify = true # Run project hooks (--no-verify to skip)```-### Select+### Switch picker-Pager behavior for `wt switch` interactive picker diff previews.+Configuration for `wt switch` interactive picker.```toml-[select]-# Pager command with flags for diff preview (overrides git's core.pager)-# Use this to specify pager flags needed for non-TTY contexts-# Example:+[switch.picker]+# Pager command for diff preview (overrides git's core.pager)# pager = "delta --paging=never"++# Timeout (ms) for git commands during picker loading (default: 200)+# Lower values show the TUI faster; 0 disables timeouts+# timeout-ms = 200```### User project-specific settingsdiff --git a/skills/worktrunk/reference/switch.md b/skills/worktrunk/reference/switch.mdindex 3f722f897..ad4e738c8 100644--- a/skills/worktrunk/reference/switch.md+++ b/skills/worktrunk/reference/switch.md@@ -86,7 +86,7 @@ When called without arguments, `wt switch` opens an interactive picker to browse**Pager configuration:** The preview panel pipes diff output through git's pager. Override in user config:```toml-[select]+[switch.picker]pager = "delta --paging=never --width=$COLUMNS"```diff --git a/src/cli/mod.rs b/src/cli/mod.rsindex c97c1ff47..ea416d7be 100644--- a/src/cli/mod.rs+++ b/src/cli/mod.rs@@ -335,7 +335,7 @@ When called without arguments, `wt switch` opens an interactive picker to browse**Pager configuration:** The preview panel pipes diff output through git's pager. Override in user config:```toml-[select]+[switch.picker]pager = "delta --paging=never --width=$COLUMNS"```@@ -1590,16 +1590,18 @@ remove = true # Remove worktree after merge (--no-remove to keep)verify = true # Run project hooks (--no-verify to skip)```-### Select+### Switch picker-Pager behavior for `wt switch` interactive picker diff previews.+Configuration for `wt switch` interactive picker.```toml-[select]-# Pager command with flags for diff preview (overrides git's core.pager)-# Use this to specify pager flags needed for non-TTY contexts-# Example:+[switch.picker]+# Pager command for diff preview (overrides git's core.pager)# pager = "delta --paging=never"++# Timeout (ms) for git commands during picker loading (default: 200)+# Lower values show the TUI faster; 0 disables timeouts+# timeout-ms = 200```### User project-specific settingsdiff --git a/src/commands/select/mod.rs b/src/commands/select/mod.rsindex e5996feed..9f310ad4e 100644--- a/src/commands/select/mod.rs+++ b/src/commands/select/mod.rs@@ -54,11 +54,9 @@ pub fn handle_select(cli_branches: bool, cli_remotes: bool) -> anyhow::Result<().into_iter().collect();- // Use 500ms timeout for git commands to show TUI faster on large repos.- // Typical slow operations: merge-tree ~400-1800ms, rev-list ~200-600ms.- // 500ms allows most operations to complete while cutting off tail latency.+ // Configurable timeout for git commands to show TUI faster on large repos.// Operations that timeout fail silently (data not shown), but TUI stays responsive.- let command_timeout = Some(std::time::Duration::from_millis(500));+ let command_timeout = config.switch_picker.picker_command_timeout();let Some(list_data) = collect::collect(&repo,diff --git a/src/commands/select/pager.rs b/src/commands/select/pager.rsindex ced5d56f8..70c925b0c 100644--- a/src/commands/select/pager.rs+++ b/src/commands/select/pager.rs@@ -41,16 +41,17 @@ fn needs_paging_disabled(pager_cmd: &str) -> bool {////// Returns the pager command with any necessary flags (like `--paging=never`)/// already appended. Precedence:-/// 1. `[select] pager` in user config (used as-is)-/// 2. `GIT_PAGER` environment variable (auto-detection applied)-/// 3. `core.pager` git config (auto-detection applied)+/// 1. `[switch.picker] pager` in user config (used as-is)+/// 2. `[select] pager` in user config (deprecated, used as-is)+/// 3. `GIT_PAGER` environment variable (auto-detection applied)+/// 4. `core.pager` git config (auto-detection applied)pub(super) fn get_diff_pager() -> Option<&'static String> {CACHED_PAGER.get_or_init(|| {// Check user config first - use exactly as specified (no auto-detection)+ // Uses switch_picker() accessor which handles [switch.picker] → [select] fallbackif let Ok(config) = UserConfig::load()- && let Some(select_config) = config.configs.select- && let Some(pager) = select_config.pager+ && let Some(pager) = config.switch_picker(None).pager&& !pager.trim().is_empty(){return Some(pager);diff --git a/src/config/deprecation.rs b/src/config/deprecation.rsindex 4d14cc38c..3acfd3cc4 100644--- a/src/config/deprecation.rs+++ b/src/config/deprecation.rs@@ -57,7 +57,7 @@ const DEPRECATED_VARS: &[(&str, &str)] = &[/// Top-level section keys that are deprecated and handled separately./// Callers should filter these out before calling `warn_unknown_fields` to avoid duplicate warnings.-pub const DEPRECATED_SECTION_KEYS: &[&str] = &["commit-generation"];+pub const DEPRECATED_SECTION_KEYS: &[&str] = &["commit-generation", "select"];/// Normalize a template string by replacing deprecated variables with their canonical names.///@@ -186,12 +186,17 @@ pub struct Deprecations {pub commit_gen: CommitGenerationDeprecations,/// Has `approved-commands` in any `[projects."..."]` section (moved to approvals.toml)pub approved_commands: bool,+ /// Has `[select]` section (moved to `[switch.picker]`)+ pub select: bool,}impl Deprecations {/// Returns true if any deprecations were foundpub fn is_empty(&self) -> bool {- self.vars.is_empty() && self.commit_gen.is_empty() && !self.approved_commands+ self.vars.is_empty()+ && self.commit_gen.is_empty()+ && !self.approved_commands+ && !self.select}}@@ -204,6 +209,7 @@ pub fn detect_deprecations(content: &str) -> Deprecations {vars: find_deprecated_vars(content),commit_gen: find_commit_generation_deprecations(content),approved_commands: find_approved_commands_deprecation(content),+ select: find_select_deprecation(content),}}@@ -462,6 +468,88 @@ pub fn remove_approved_commands_from_config(content: &str) -> String {}}+/// Check if config has a deprecated `[select]` section without a corresponding `[switch.picker]`.+///+/// Returns true if `[select]` exists, is non-empty, and `[switch.picker]` does not exist.+pub fn find_select_deprecation(content: &str) -> bool {+ let Ok(doc) = content.parse::<toml_edit::DocumentMut>() else {+ return false;+ };++ // Check if new [switch.picker] already exists+ let has_new_section = doc+ .get("switch")+ .and_then(|s| s.as_table())+ .and_then(|t| t.get("picker"))+ .is_some_and(|p| p.is_table() || p.is_inline_table());++ if has_new_section {+ return false;+ }++ // Check if [select] exists and is non-empty+ if let Some(section) = doc.get("select") {+ if let Some(table) = section.as_table() {+ return !table.is_empty();+ }+ if let Some(inline) = section.as_inline_table() {+ return !inline.is_empty();+ }+ }++ false+}++/// Migrate `[select]` section to `[switch.picker]`.+///+/// Renames `[select]` to `[switch.picker]`, preserving all fields.+/// Skips migration if `[switch.picker]` already exists.+pub fn migrate_select_to_switch_picker(content: &str) -> String {+ let Ok(mut doc) = content.parse::<toml_edit::DocumentMut>() else {+ return content.to_string();+ };++ // Check if [switch.picker] already exists+ let has_new_section = doc+ .get("switch")+ .and_then(|s| s.as_table())+ .and_then(|t| t.get("picker"))+ .is_some_and(|p| p.is_table() || p.is_inline_table());++ if has_new_section {+ return content.to_string();+ }++ // Remove [select] and migrate to [switch.picker]+ let Some(old_section) = doc.remove("select") else {+ return content.to_string();+ };++ let table_opt = match old_section {+ toml_edit::Item::Table(t) => Some(t),+ toml_edit::Item::Value(toml_edit::Value::InlineTable(it)) => Some(it.into_table()),+ _ => None,+ };++ let Some(table) = table_opt else {+ return content.to_string();+ };++ // Ensure [switch] section exists (implicit so only [switch.picker] renders)+ if !doc.contains_key("switch") {+ let mut switch_table = toml_edit::Table::new();+ switch_table.set_implicit(true);+ doc.insert("switch", toml_edit::Item::Table(switch_table));+ }++ // Move to [switch.picker]+ if let Some(switch_table) = doc["switch"].as_table_mut() {+ switch_table.insert("picker", toml_edit::Item::Table(table));+ }++ doc.to_string()+}+/// Copy approved-commands from config.toml to approvals.toml.////// Called during migration to ensure approved-commands are preserved before@@ -763,6 +851,9 @@ pub fn write_migration_file(if deprecations.approved_commands {new_content = remove_approved_commands_from_config(&new_content);}+ if deprecations.select {+ new_content = migrate_select_to_switch_picker(&new_content);+ }if let Err(e) = std::fs::write(&new_path, &new_content) {// Log write failure but don't block config loading@@ -871,6 +962,17 @@ pub fn format_deprecation_warnings(info: &DeprecationInfo) -> String {}}+ if info.deprecations.select {+ let _ = writeln!(+ out,+ "{}",+ warning_message(format!(+ "{} uses deprecated config section: [select] → [switch.picker]",+ info.label+ ))+ );+ }+out}@@ -2074,6 +2176,7 @@ approved-commands = ["npm install"]vars: vec![],commit_gen: CommitGenerationDeprecations::default(),approved_commands: true,+ select: false,},label: "User config".to_string(),in_linked_worktree: false,@@ -2101,6 +2204,7 @@ approved-commands = ["npm install"]vars: vec![],commit_gen: CommitGenerationDeprecations::default(),approved_commands: true,+ select: false,},label: "User config".to_string(),in_linked_worktree: false,@@ -2129,6 +2233,7 @@ approved-commands = ["npm install"]vars: vec![],commit_gen: CommitGenerationDeprecations::default(),approved_commands: true,+ select: false,};let result = write_migration_file(&config_path, content, &deprecations, None);assert!(@@ -2240,4 +2345,197 @@ worktree-path = ".worktrees/{{ branch | sanitize }}""Should have [commit.generation] header");}++ // Tests for [select] → [switch.picker] deprecation++ #[test]+ fn test_find_select_deprecation_none() {+ let content = r#"+[switch.picker]+pager = "delta --paging=never"+"#;+ assert!(!find_select_deprecation(content));+ }++ #[test]+ fn test_find_select_deprecation_present() {+ let content = r#"+[select]+pager = "delta --paging=never"+"#;+ assert!(find_select_deprecation(content));+ }++ #[test]+ fn test_find_select_deprecation_empty_not_flagged() {+ let content = r#"+[select]+"#;+ assert!(!find_select_deprecation(content));+ }++ #[test]+ fn test_find_select_deprecation_skips_when_new_exists() {+ // When both [select] and [switch.picker] exist, don't flag+ let content = r#"+[select]+pager = "old"++[switch.picker]+pager = "new"+"#;+ assert!(!find_select_deprecation(content));+ }++ #[test]+ fn test_find_select_deprecation_inline_table() {+ let content = r#"+select = { pager = "delta" }+"#;+ assert!(find_select_deprecation(content));+ }++ #[test]+ fn test_find_select_deprecation_empty_inline_table() {+ let content = r#"+select = {}+"#;+ assert!(!find_select_deprecation(content));+ }++ #[test]+ fn test_migrate_select_simple() {+ let content = r#"+[select]+pager = "delta --paging=never"+"#;+ let result = migrate_select_to_switch_picker(content);+ assert!(+ result.contains("[switch.picker]"),+ "Should have [switch.picker]: {result}"+ );+ assert!(+ result.contains("pager = \"delta --paging=never\""),+ "Should preserve pager: {result}"+ );+ assert!(+ !result.contains("[select]"),+ "Should remove [select]: {result}"+ );+ }++ #[test]+ fn test_migrate_select_skips_when_new_exists() {+ let content = r#"+[select]+pager = "old"++[switch.picker]+pager = "new"+"#;+ let result = migrate_select_to_switch_picker(content);+ assert_eq!(+ result, content,+ "Should not migrate when new section exists"+ );+ }++ #[test]+ fn test_migrate_select_invalid_toml() {+ let content = "this is { not valid toml";+ let result = migrate_select_to_switch_picker(content);+ assert_eq!(result, content, "Invalid TOML should be returned unchanged");+ }++ #[test]+ fn test_migrate_select_no_select_section() {+ let content = r#"+[list]+full = true+"#;+ let result = migrate_select_to_switch_picker(content);+ assert_eq!(result, content, "No [select] section means no migration");+ }++ #[test]+ fn test_detect_deprecations_includes_select() {+ let content = r#"+[select]+pager = "delta"+"#;+ let deprecations = detect_deprecations(content);+ assert!(deprecations.select);+ assert!(!deprecations.is_empty());+ }++ #[test]+ fn snapshot_migrate_select_to_switch_picker() {+ let content = r#"worktree-path = "../{{ repo }}.{{ branch | sanitize }}"++[select]+pager = "delta --paging=never"++[list]+branches = true+"#;+ let result = migrate_select_to_switch_picker(content);+ insta::assert_snapshot!(migration_diff(content, &result));+ }++ #[test]+ fn test_format_deprecation_details_select() {+ let info = DeprecationInfo {+ config_path: std::path::PathBuf::from("/tmp/test-config.toml"),+ migration_path: None,+ deprecations: Deprecations {+ vars: vec![],+ commit_gen: CommitGenerationDeprecations::default(),+ approved_commands: false,+ select: true,+ },+ label: "User config".to_string(),+ in_linked_worktree: false,+ approvals_copied_to: None,+ };+ let output = format_deprecation_details(&info);+ assert!(+ output.contains("[select]"),+ "Should mention [select] in output: {output}"+ );+ assert!(+ output.contains("[switch.picker]"),+ "Should mention [switch.picker]: {output}"+ );+ }++ #[test]+ fn test_write_migration_file_with_select() {+ let temp_dir = tempfile::TempDir::new().unwrap();+ let config_path = temp_dir.path().join("config.toml");+ let content = r#"worktree-path = "../{{ repo }}.{{ branch | sanitize }}"++[select]+pager = "delta --paging=never"+"#;+ std::fs::write(&config_path, content).unwrap();++ let deprecations = Deprecations {+ vars: vec![],+ commit_gen: CommitGenerationDeprecations::default(),+ approved_commands: false,+ select: true,+ };+ let result = write_migration_file(&config_path, content, &deprecations, None);+ assert!(result.is_some(), "Should write migration file for select");+ let migration_path = result.unwrap();+ let migrated = std::fs::read_to_string(&migration_path).unwrap();+ assert!(+ migrated.contains("[switch.picker]"),+ "Migrated content should have [switch.picker]: {migrated}"+ );+ assert!(+ !migrated.contains("[select]"),+ "Migrated content should not have [select]: {migrated}"+ );+ }}diff --git a/src/config/mod.rs b/src/config/mod.rsindex 78b7525a3..e6e06162a 100644--- a/src/config/mod.rs+++ b/src/config/mod.rs@@ -95,9 +95,9 @@ pub use project::{};pub use user::{CommitConfig, CommitGenerationConfig, ListConfig, MergeConfig, OverridableConfig,- ResolvedConfig, SelectConfig, StageMode, UserConfig, UserProjectOverrides,- default_system_config_path, find_unknown_keys as find_unknown_user_keys, get_config_path,- get_system_config_path, set_config_path,+ ResolvedConfig, SelectConfig, StageMode, SwitchConfig, SwitchPickerConfig, UserConfig,+ UserProjectOverrides, default_system_config_path, find_unknown_keys as find_unknown_user_keys,+ get_config_path, get_system_config_path, set_config_path,};#[cfg(test)]diff --git a/src/config/snapshots/worktrunk__config__deprecation__tests__snapshot_migrate_select_to_switch_picker.snap b/src/config/snapshots/worktrunk__config__deprecation__tests__snapshot_migrate_select_to_switch_picker.snapnew file mode 100644index 000000000..ee0b50288--- /dev/null+++ b/src/config/snapshots/worktrunk__config__deprecation__tests__snapshot_migrate_select_to_switch_picker.snap@@ -0,0 +1,12 @@+---+source: src/config/deprecation.rs+expression: "migration_diff(content, &result)"+---+ worktree-path = "../{{ repo }}.{{ branch | sanitize }}"++-[select]++[switch.picker]+ pager = "delta --paging=never"++ [list]+ branches = truediff --git a/src/config/user/accessors.rs b/src/config/user/accessors.rsindex 05827d5eb..8686e3136 100644--- a/src/config/user/accessors.rs+++ b/src/config/user/accessors.rs@@ -11,7 +11,7 @@ use crate::config::expansion::{TemplateExpandError, expand_template};use super::UserConfig;use super::merge::{Merge, merge_optional};use super::sections::{- CommitConfig, CommitGenerationConfig, ListConfig, MergeConfig, SelectConfig,+ CommitConfig, CommitGenerationConfig, ListConfig, MergeConfig, SelectConfig, SwitchPickerConfig,};/// Default worktree path template@@ -112,7 +112,7 @@ impl UserConfig {merge_optional(self.configs.merge.as_ref(), project_config)}- /// Returns the select config for a specific project.+ /// Returns the select config for a specific project (deprecated path).////// Merges project-specific settings with global settings, where project/// settings take precedence for fields that are set.@@ -123,6 +123,51 @@ impl UserConfig {merge_optional(self.configs.select.as_ref(), project_config)}+ /// Returns the switch picker config for a specific project.+ ///+ /// Prefers `[switch.picker]` (new format), falls back to `[select]` (deprecated).+ /// Merges project-specific settings with global settings, where project+ /// settings take precedence for fields that are set.+ pub fn switch_picker(&self, project: Option<&str>) -> SwitchPickerConfig {+ // Get global config: prefer switch.picker, fall back to select+ let global = self+ .configs+ .switch+ .as_ref()+ .and_then(|s| s.picker.as_ref())+ .cloned()+ .unwrap_or_else(|| {+ self.configs+ .select+ .as_ref()+ .map(|sel| SwitchPickerConfig {+ pager: sel.pager.clone(),+ timeout_ms: None,+ })+ .unwrap_or_default()+ });++ // Get project override (also checks both locations)+ let project_config = project.and_then(|p| self.projects.get(p)).and_then(|c| {+ c.overrides+ .switch+ .as_ref()+ .and_then(|s| s.picker.as_ref())+ .cloned()+ .or_else(|| {+ c.overrides.select.as_ref().map(|sel| SwitchPickerConfig {+ pager: sel.pager.clone(),+ timeout_ms: None,+ })+ })+ });++ match project_config {+ Some(pc) => global.merge_with(&pc),+ None => global,+ }+ }+/// Returns effective hooks for a specific project.////// Merges global hooks with per-project hooks using append semantics.diff --git a/src/config/user/mod.rs b/src/config/user/mod.rsindex 4d86e86e8..558e37d6d 100644--- a/src/config/user/mod.rs+++ b/src/config/user/mod.rs@@ -26,7 +26,7 @@ pub use resolved::ResolvedConfig;pub use schema::{find_unknown_keys, valid_user_config_keys};pub use sections::{CommitConfig, CommitGenerationConfig, ListConfig, MergeConfig, OverridableConfig, SelectConfig,- StageMode, UserProjectOverrides,+ StageMode, SwitchConfig, SwitchPickerConfig, UserProjectOverrides,};/// User-level configuration for worktree path formatting and LLM integration.@@ -86,7 +86,7 @@ pub struct UserConfig {#[serde(default)]pub projects: std::collections::BTreeMap<String, UserProjectOverrides>,- /// Settings that can be overridden per-project (worktree-path, list, commit, merge, select, hooks)+ /// Settings that can be overridden per-project (worktree-path, list, commit, merge, switch, select, hooks)#[serde(flatten, default)]pub configs: OverridableConfig,diff --git a/src/config/user/persistence.rs b/src/config/user/persistence.rsindex b62cb0f7b..6b391053c 100644--- a/src/config/user/persistence.rs+++ b/src/config/user/persistence.rs@@ -143,6 +143,12 @@ impl UserConfig {"merge",project_config.overrides.merge.as_ref(),);+ Self::serialize_project_config_section(+ projects,+ project_id,+ "switch",+ project_config.overrides.switch.as_ref(),+ );Self::serialize_project_config_section(projects,project_id,diff --git a/src/config/user/resolved.rs b/src/config/user/resolved.rsindex 5f063d6f9..dd375896b 100644--- a/src/config/user/resolved.rs+++ b/src/config/user/resolved.rs@@ -6,7 +6,7 @@use super::UserConfig;use super::sections::{- CommitConfig, CommitGenerationConfig, ListConfig, MergeConfig, SelectConfig,+ CommitConfig, CommitGenerationConfig, ListConfig, MergeConfig, SwitchPickerConfig,};/// All resolved configuration for a specific project context.@@ -17,10 +17,11 @@ use super::sections::{/// # Example/// ```ignore/// let resolved = config.resolved(project);-/// let full = resolved.list.full(); // bool, default applied-/// let squash = resolved.merge.squash(); // bool, default applied-/// let stage = resolved.commit.stage(); // StageMode, default applied-/// let pager = resolved.select.pager(); // Option<&str>+/// let full = resolved.list.full(); // bool, default applied+/// let squash = resolved.merge.squash(); // bool, default applied+/// let stage = resolved.commit.stage(); // StageMode, default applied+/// let pager = resolved.switch_picker.pager(); // Option<&str>+/// let timeout = resolved.switch_picker.picker_command_timeout(); // Option<Duration>/// ```#[derive(Debug, Clone, PartialEq)]pub struct ResolvedConfig {@@ -29,7 +30,8 @@ pub struct ResolvedConfig {pub commit: CommitConfig,/// Resolved commit generation config (handles deprecated `[commit-generation]` fallback)pub commit_generation: CommitGenerationConfig,- pub select: SelectConfig,+ /// Resolved switch picker config (handles deprecated `[select]` fallback)+ pub switch_picker: SwitchPickerConfig,}impl ResolvedConfig {@@ -40,7 +42,7 @@ impl ResolvedConfig {merge: config.merge(project).unwrap_or_default(),commit: config.commit(project).unwrap_or_default(),commit_generation: config.commit_generation(project),- select: config.select(project).unwrap_or_default(),+ switch_picker: config.switch_picker(project),}}}diff --git a/src/config/user/sections.rs b/src/config/user/sections.rsindex d51f1f8e7..07ca85d33 100644--- a/src/config/user/sections.rs+++ b/src/config/user/sections.rs@@ -285,10 +285,30 @@ impl Merge for MergeConfig {}}-/// Configuration for the `wt switch` interactive picker.-// TODO(#890): Rename to SwitchPickerConfig and [switch.picker] once migration is confirmed+/// **DEPRECATED**: Use `[switch.picker]` instead.+///+/// Configuration for the `wt switch` interactive picker (old format).+/// Kept for backward-compatible deserialization of `[select]` sections.#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, JsonSchema)]pub struct SelectConfig {+ /// Pager command with flags for diff preview+ #[serde(skip_serializing_if = "Option::is_none")]+ pub pager: Option<String>,+}++impl Merge for SelectConfig {+ fn merge_with(&self, other: &Self) -> Self {+ Self {+ pager: other.pager.clone().or_else(|| self.pager.clone()),+ }+ }+}++/// Configuration for the `wt switch` interactive picker.+///+/// New format under `[switch.picker]`. Replaces the deprecated `[select]` section.+#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, JsonSchema)]+pub struct SwitchPickerConfig {/// Pager command with flags for diff preview////// Overrides git's core.pager for the interactive picker's preview panel.@@ -297,19 +317,66 @@ pub struct SelectConfig {/// Example: `pager = "delta --paging=never"`#[serde(skip_serializing_if = "Option::is_none")]pub pager: Option<String>,++ /// Picker command timeout in milliseconds.+ ///+ /// Controls how long to wait for git commands when populating the picker.+ /// Commands that exceed this timeout fail silently (data not shown).+ ///+ /// - Unset: 200ms default+ /// - `0`: No timeout+ /// - Positive value: Custom timeout in milliseconds+ #[serde(rename = "timeout-ms", skip_serializing_if = "Option::is_none")]+ pub timeout_ms: Option<u64>,}-impl SelectConfig {- /// Pager command with flags for diff preview (default: None, uses git default)+impl SwitchPickerConfig {+ /// Pager command for diff preview (default: None, uses git default)pub fn pager(&self) -> Option<&str> {self.pager.as_deref()}++ /// Command timeout for the picker.+ ///+ /// Returns `None` when timeout is disabled (timeout_ms = 0),+ /// the configured timeout, or the 200ms default. The 200ms default+ /// aggressively cuts tail latency so the TUI appears near-instantly;+ /// users on large repos can raise it via `timeout-ms`.+ pub fn picker_command_timeout(&self) -> Option<std::time::Duration> {+ match self.timeout_ms {+ Some(0) => None,+ Some(ms) => Some(std::time::Duration::from_millis(ms)),+ None => Some(std::time::Duration::from_millis(200)),+ }+ }}-impl Merge for SelectConfig {+impl Merge for SwitchPickerConfig {fn merge_with(&self, other: &Self) -> Self {Self {pager: other.pager.clone().or_else(|| self.pager.clone()),+ timeout_ms: other.timeout_ms.or(self.timeout_ms),+ }+ }+}++/// Configuration for the `wt switch` command+#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, JsonSchema)]+pub struct SwitchConfig {+ /// Picker settings for the interactive selector+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub picker: Option<SwitchPickerConfig>,+}++impl Merge for SwitchConfig {+ fn merge_with(&self, other: &Self) -> Self {+ Self {+ picker: match (&self.picker, &other.picker) {+ (None, None) => None,+ (Some(s), None) => Some(s.clone()),+ (None, Some(o)) => Some(o.clone()),+ (Some(s), Some(o)) => Some(s.merge_with(o)),+ },}}}@@ -353,7 +420,11 @@ pub struct OverridableConfig {#[serde(default, skip_serializing_if = "Option::is_none")]pub merge: Option<MergeConfig>,- /// Configuration for the `wt switch` interactive picker+ /// Configuration for the `wt switch` command+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub switch: Option<SwitchConfig>,++ /// **DEPRECATED**: Use `[switch.picker]` instead.#[serde(default, skip_serializing_if = "Option::is_none")]pub select: Option<SelectConfig>,}@@ -368,6 +439,7 @@ impl OverridableConfig {&& self.list.is_none()&& self.commit.is_none()&& self.merge.is_none()+ && self.switch.is_none()&& self.select.is_none()}}@@ -385,6 +457,7 @@ impl Merge for OverridableConfig {list: merge_optional(self.list.as_ref(), other.list.as_ref()),commit: merge_optional(self.commit.as_ref(), other.commit.as_ref()),merge: merge_optional(self.merge.as_ref(), other.merge.as_ref()),+ switch: merge_optional(self.switch.as_ref(), other.switch.as_ref()),select: merge_optional(self.select.as_ref(), other.select.as_ref()),}}@@ -431,7 +504,7 @@ pub struct UserProjectOverrides {)]pub commit_generation: Option<CommitGenerationConfig>,- /// Per-project overrides (worktree-path, list, commit, merge, select)+ /// Per-project overrides (worktree-path, list, commit, merge, switch, select)#[serde(flatten, default)]pub overrides: OverridableConfig,}diff --git a/src/config/user/tests.rs b/src/config/user/tests.rsindex fcfcf66e9..b08533798 100644--- a/src/config/user/tests.rs+++ b/src/config/user/tests.rs@@ -987,18 +987,270 @@ fn test_commit_config_accessor_methods() {}#[test]-fn test_select_config_accessor_methods() {+fn test_select_config_fields() {let config = SelectConfig::default();- assert!(config.pager().is_none());+ assert!(config.pager.is_none());let config = SelectConfig {pager: Some("delta --paging=never".to_string()),};+ assert_eq!(config.pager.as_deref(), Some("delta --paging=never"));+}++// =========================================================================+// SwitchPickerConfig tests+// =========================================================================++#[test]+fn test_switch_picker_config_accessor_methods() {+ use crate::config::user::SwitchPickerConfig;++ let config = SwitchPickerConfig::default();+ assert!(config.pager().is_none());+ // Default timeout is 200ms+ assert_eq!(+ config.picker_command_timeout(),+ Some(std::time::Duration::from_millis(200))+ );++ let config = SwitchPickerConfig {+ pager: Some("delta --paging=never".to_string()),+ timeout_ms: Some(500),+ };assert_eq!(config.pager(), Some("delta --paging=never"));+ assert_eq!(+ config.picker_command_timeout(),+ Some(std::time::Duration::from_millis(500))+ );+}++#[test]+fn test_switch_picker_timeout_zero_disables() {+ use crate::config::user::SwitchPickerConfig;++ let config = SwitchPickerConfig {+ timeout_ms: Some(0),+ ..Default::default()+ };+ assert!(config.picker_command_timeout().is_none());+}++#[test]+fn test_switch_picker_timeout_none_uses_default() {+ use crate::config::user::SwitchPickerConfig;++ let config = SwitchPickerConfig::default();+ assert_eq!(+ config.picker_command_timeout(),+ Some(std::time::Duration::from_millis(200))+ );+}++#[test]+fn test_switch_picker_config_parse_toml() {+ let content = r#"+[switch.picker]+pager = "delta --paging=never"+timeout-ms = 300+"#;+ let config: UserConfig = toml::from_str(content).unwrap();+ let picker = config+ .configs+ .switch+ .as_ref()+ .unwrap()+ .picker+ .as_ref()+ .unwrap();+ assert_eq!(picker.pager.as_deref(), Some("delta --paging=never"));+ assert_eq!(picker.timeout_ms, Some(300));+}++#[test]+fn test_switch_picker_merge() {+ use crate::config::user::{Merge, SwitchPickerConfig};++ let base = SwitchPickerConfig {+ pager: Some("delta".to_string()),+ timeout_ms: Some(500),+ };+ let override_config = SwitchPickerConfig {+ pager: None, // Fall back to base+ timeout_ms: Some(0), // Override: disable timeout+ };++ let merged = base.merge_with(&override_config);+ assert_eq!(merged.pager.as_deref(), Some("delta"));+ assert_eq!(merged.timeout_ms, Some(0));+}++#[test]+fn test_switch_config_merge() {+ use crate::config::user::{Merge, SwitchConfig, SwitchPickerConfig};++ // Both have picker+ let base = SwitchConfig {+ picker: Some(SwitchPickerConfig {+ pager: Some("delta".to_string()),+ timeout_ms: None,+ }),+ };+ let other = SwitchConfig {+ picker: Some(SwitchPickerConfig {+ pager: None,+ timeout_ms: Some(300),+ }),+ };+ let merged = base.merge_with(&other);+ assert_eq!(+ merged.picker.as_ref().unwrap().pager.as_deref(),+ Some("delta")+ );+ assert_eq!(merged.picker.as_ref().unwrap().timeout_ms, Some(300));++ // Base has picker, other doesn't+ let other_none = SwitchConfig { picker: None };+ let merged = base.merge_with(&other_none);+ assert_eq!(+ merged.picker.as_ref().unwrap().pager.as_deref(),+ Some("delta")+ );++ // Neither has picker+ let base_none = SwitchConfig { picker: None };+ let merged = base_none.merge_with(&other_none);+ assert!(merged.picker.is_none());+}++#[test]+fn test_switch_picker_fallback_from_select() {+ // When only [select] is configured, switch_picker() should use its pager+ let config = UserConfig {+ configs: OverridableConfig {+ select: Some(SelectConfig {+ pager: Some("bat".to_string()),+ }),+ ..Default::default()+ },+ ..Default::default()+ };++ let picker = config.switch_picker(None);+ assert_eq!(picker.pager.as_deref(), Some("bat"));+ // timeout_ms not available from select, so default applies+ assert_eq!(picker.timeout_ms, None);+ assert_eq!(+ picker.picker_command_timeout(),+ Some(std::time::Duration::from_millis(200))+ );+}++#[test]+fn test_switch_picker_prefers_new_over_select() {+ use crate::config::user::{SwitchConfig, SwitchPickerConfig};++ // When both [switch.picker] and [select] are configured, switch.picker wins+ let config = UserConfig {+ configs: OverridableConfig {+ switch: Some(SwitchConfig {+ picker: Some(SwitchPickerConfig {+ pager: Some("delta".to_string()),+ timeout_ms: Some(100),+ }),+ }),+ select: Some(SelectConfig {+ pager: Some("bat".to_string()),+ }),+ ..Default::default()+ },+ ..Default::default()+ };++ let picker = config.switch_picker(None);+ assert_eq!(picker.pager.as_deref(), Some("delta"));+ assert_eq!(picker.timeout_ms, Some(100));+}++#[test]+fn test_switch_picker_project_override() {+ use crate::config::user::{SwitchConfig, SwitchPickerConfig};++ let mut config = UserConfig {+ configs: OverridableConfig {+ switch: Some(SwitchConfig {+ picker: Some(SwitchPickerConfig {+ pager: Some("delta".to_string()),+ timeout_ms: Some(200),+ }),+ }),+ ..Default::default()+ },+ ..Default::default()+ };++ config.projects.insert(+ "github.com/user/repo".to_string(),+ UserProjectOverrides {+ overrides: OverridableConfig {+ switch: Some(SwitchConfig {+ picker: Some(SwitchPickerConfig {+ pager: Some("bat".to_string()),+ timeout_ms: None, // Fall back to global+ }),+ }),+ ..Default::default()+ },+ ..Default::default()+ },+ );++ let picker = config.switch_picker(Some("github.com/user/repo"));+ assert_eq!(picker.pager.as_deref(), Some("bat")); // From project+ assert_eq!(picker.timeout_ms, Some(200)); // From global+}++#[test]+fn test_switch_picker_project_fallback_from_select() {+ // Project has [select], global has [switch.picker]+ // Project's select pager should be used+ use crate::config::user::{SwitchConfig, SwitchPickerConfig};++ let mut config = UserConfig {+ configs: OverridableConfig {+ switch: Some(SwitchConfig {+ picker: Some(SwitchPickerConfig {+ pager: Some("delta".to_string()),+ timeout_ms: Some(300),+ }),+ }),+ ..Default::default()+ },+ ..Default::default()+ };++ config.projects.insert(+ "github.com/user/repo".to_string(),+ UserProjectOverrides {+ overrides: OverridableConfig {+ select: Some(SelectConfig {+ pager: Some("bat".to_string()),+ }),+ ..Default::default()+ },+ ..Default::default()+ },+ );++ let picker = config.switch_picker(Some("github.com/user/repo"));+ assert_eq!(picker.pager.as_deref(), Some("bat")); // Project select fallback+ assert_eq!(picker.timeout_ms, Some(300)); // From global (select has no timeout)}#[test]fn test_resolved_config_for_project() {+ use crate::config::user::SwitchConfig;+ use crate::config::user::SwitchPickerConfig;+let config = UserConfig {configs: OverridableConfig {list: Some(ListConfig {@@ -1013,8 +1265,11 @@ fn test_resolved_config_for_project() {stage: Some(StageMode::None),..Default::default()}),- select: Some(SelectConfig {- pager: Some("less".to_string()),+ switch: Some(SwitchConfig {+ picker: Some(SwitchPickerConfig {+ pager: Some("less".to_string()),+ timeout_ms: Some(300),+ }),}),..Default::default()},@@ -1029,7 +1284,8 @@ fn test_resolved_config_for_project() {assert!(!resolved.merge.squash()); // Overridden to falseassert!(resolved.merge.commit()); // Default trueassert_eq!(resolved.commit.stage(), StageMode::None);- assert_eq!(resolved.select.pager(), Some("less"));+ assert_eq!(resolved.switch_picker.pager(), Some("less"));+ assert_eq!(resolved.switch_picker.timeout_ms, Some(300));}// =========================================================================@@ -1738,7 +1994,7 @@ fn test_valid_user_config_keys_all_deserialize() {"worktree-path" => {scalar_lines.push(format!("{key} = \"test-value\""));}- "list" | "commit" | "merge" | "select" | "commit-generation" => {+ "list" | "commit" | "merge" | "switch" | "select" | "commit-generation" => {// Table sections with minimal contenttable_lines.push(format!("[{key}]"));}diff --git a/tests/integration_tests/readme_sync.rs b/tests/integration_tests/readme_sync.rsindex 36bc2aa00..f7309b639 100644--- a/tests/integration_tests/readme_sync.rs+++ b/tests/integration_tests/readme_sync.rs@@ -1045,6 +1045,53 @@ fn test_config_source_generates_example_toml() {}}+/// Verify that all config section keys appear in the user config documentation.+///+/// When a new config section is added (e.g., `[switch.picker]`), this test ensures+/// it also appears in the user config docs in `src/cli/mod.rs`. Without this, new+/// config sections can ship undocumented.+#[test]+fn test_config_docs_include_all_sections() {+ let project_root = Path::new(env!("CARGO_MANIFEST_DIR"));+ let cli_mod_path = project_root.join("src/cli/mod.rs");+ let cli_mod_content = fs::read_to_string(&cli_mod_path).unwrap();+ let user_config_content = extract_user_config_from_cli(&cli_mod_content);++ // Config sections that MUST be documented (non-deprecated, non-hook table sections).+ // When adding a new config section, add it here — the test will fail if it's+ // missing from the docs.+ let required_sections = [+ "list",+ "commit",+ "commit.generation",+ "merge",+ "switch.picker",+ ];++ // Deprecated sections — should NOT appear in docs (old users get migration guidance)+ let deprecated_sections = ["select", "commit-generation"];++ // Check required sections appear as TOML headers in code blocks+ for section in &required_sections {+ let header = format!("[{section}]");+ assert!(+ user_config_content.contains(&header),+ "Config section `{header}` is missing from user config docs in src/cli/mod.rs.\n\+ All config sections must be documented between USER_CONFIG_START/END markers."+ );+ }++ // Check deprecated sections do NOT appear as TOML headers+ for section in &deprecated_sections {+ let header = format!("[{section}]");+ assert!(+ !user_config_content.contains(&header),+ "Deprecated section `{header}` should not appear in user config docs.\n\+ Use the new section name instead."+ );+ }+}+#[test]fn test_config_source_templates_are_in_sync() {let project_root = Path::new(env!("CARGO_MANIFEST_DIR"));diff --git a/tests/snapshots/integration__integration_tests__help__help_config_create.snap b/tests/snapshots/integration__integration_tests__help__help_config_create.snapindex 87c3b3145..2ff14c801 100644--- a/tests/snapshots/integration__integration_tests__help__help_config_create.snap+++ b/tests/snapshots/integration__integration_tests__help__help_config_create.snap@@ -18,6 +18,7 @@ info:TERM: alacrittyWORKTRUNK_APPROVALS_PATH: /nonexistent/test/approvals.tomlWORKTRUNK_CONFIG_PATH: /nonexistent/test/config.toml+ WORKTRUNK_SYSTEM_CONFIG_PATH: /etc/xdg/worktrunk/config.tomlWORKTRUNK_TEST_CLAUDE_INSTALLED: "0"WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"WORKTRUNK_TEST_EPOCH: "1735776000"@@ -128,16 +129,18 @@ Creates [2m~/.config/worktrunk/config.toml[0m with the following content:[2m# remove = true # Remove worktree after merge (--no-remove to keep)[0m[2m# verify = true # Run project hooks (--no-verify to skip)[0m[2m#[0m- [2m# ### Select[0m+ [2m# ### Switch picker[0m[2m#[0m- [2m# Pager behavior for `wt switch` interactive picker diff previews.[0m+ [2m# Configuration for `wt switch` interactive picker.[0m[2m#[0m- [2m# [select][0m- [2m# # Pager command with flags for diff preview (overrides git's core.pager)[0m- [2m# # Use this to specify pager flags needed for non-TTY contexts[0m- [2m# # Example:[0m+ [2m# [switch.picker][0m+ [2m# # Pager command for diff preview (overrides git's core.pager)[0m[2m# # pager = "delta --paging=never"[0m[2m#[0m+ [2m# # Timeout (ms) for git commands during picker loading (default: 200)[0m+ [2m# # Lower values show the TUI faster; 0 disables timeouts[0m+ [2m# # timeout-ms = 200[0m+ [2m#[0m[2m# ### User project-specific settings[0m[2m#[0m[2m# For context:[0mdiff --git a/tests/snapshots/integration__integration_tests__help__help_config_long.snap b/tests/snapshots/integration__integration_tests__help__help_config_long.snapindex 06551ccf4..e3f40be7b 100644--- a/tests/snapshots/integration__integration_tests__help__help_config_long.snap+++ b/tests/snapshots/integration__integration_tests__help__help_config_long.snap@@ -174,15 +174,17 @@ All flags are on by default. Set to false to change default behavior.[2mremove = true # Remove worktree after merge (--no-remove to keep)[0m[2mverify = true # Run project hooks (--no-verify to skip)[0m-[32mSelect[0m+[32mSwitch picker[0m-Pager behavior for [2mwt switch[0m interactive picker diff previews.+Configuration for [2mwt switch[0m interactive picker.- [2m[select][0m- [2m# Pager command with flags for diff preview (overrides git's core.pager)[0m- [2m# Use this to specify pager flags needed for non-TTY contexts[0m- [2m# Example:[0m+ [2m[switch.picker][0m+ [2m# Pager command for diff preview (overrides git's core.pager)[0m[2m# pager = "delta --paging=never"[0m+ [2m[0m+ [2m# Timeout (ms) for git commands during picker loading (default: 200)[0m+ [2m# Lower values show the TUI faster; 0 disables timeouts[0m+ [2m# timeout-ms = 200[0m[32mUser project-specific settings[0mdiff --git a/tests/snapshots/integration__integration_tests__help__help_switch_long.snap b/tests/snapshots/integration__integration_tests__help__help_switch_long.snapindex 60a350a28..41cc3c618 100644--- a/tests/snapshots/integration__integration_tests__help__help_switch_long.snap+++ b/tests/snapshots/integration__integration_tests__help__help_switch_long.snap@@ -180,7 +180,7 @@ When called without arguments, [2mwt switch[0m opens an interactive picker to[1mPager configuration:[0m The preview panel pipes diff output through git's pager. Override in user config:- [2m[select][0m+ [2m[switch.picker][0m[2mpager = "delta --paging=never --width=$COLUMNS"[0mAvailable on Unix only (macOS, Linux). On Windows, use [2mwt list[0m or [2mwt switch <branch>[0m directly.