From 24c35bbeacb758bde571257da4a2ffaa3d4b52db Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Mon, 17 Nov 2025 18:48:56 -0800 Subject: [PATCH 1/5] feat: Add PTY support for interactive command approval This commit introduces PTY-based tests for the interactive command approval prompts, ensuring that `wt` behaves correctly in real terminal environments. Changes include: - A new `GitError::NotInteractive` error is added and handled to prevent approval prompts from blocking in non-TTY environments (e.g., CI/CD). - The `prompt_for_batch_approval` function now checks `io::stdin().is_terminal()` before attempting to prompt, failing fast with `GitError::NotInteractive` if stdin is not a TTY. - New integration tests (`approval_pty.rs`) use `portable-pty` to simulate interactive terminal sessions, covering scenarios like accepting/declining commands, multiple commands, named commands, permission errors during config save, and mixed approved/unapproved commands. - The `TestRepo::test_env_vars` helper function is added to provide a consistent set of environment variables for PTY tests. - Existing UI tests (`approval_ui.rs`) are updated to reflect the new non-TTY behavior, where prompts now result in `NotInteractive` errors if stdin is not piped. - The `test_permission_error_user_output` test is moved from `approval_ui.rs` to `approval_pty.rs` to accurately test interactive behavior. --- src/commands/command_approval.rs | 11 +- src/git/error.rs | 10 + tests/common/mod.rs | 28 ++ tests/integration_tests/approval_pty.rs | 390 ++++++++++++++++++ tests/integration_tests/approval_ui.rs | 106 ++--- tests/integration_tests/mod.rs | 1 + ..._approval_pty__approval_prompt_accept.snap | 17 + ...approval_pty__approval_prompt_decline.snap | 15 + ...ompt_mixed_approved_unapproved_accept.snap | 26 ++ ...mpt_mixed_approved_unapproved_decline.snap | 18 + ...ty__approval_prompt_multiple_commands.snap | 29 ++ ...l_pty__approval_prompt_named_commands.snap | 29 ++ ...ty__approval_prompt_permission_error.snap} | 22 +- ...pproval_ui__approval_fails_in_non_tty.snap | 33 ++ ...i__approval_mixed_approved_unapproved.snap | 10 +- ...proval_ui__approval_multiple_commands.snap | 10 +- ..._approval_ui__approval_named_commands.snap | 10 +- ..._approval_ui__approval_single_command.snap | 10 +- ...ecline_approval_skips_only_unapproved.snap | 10 +- ...approval_ui__force_bypasses_tty_check.snap | 32 ++ ...ce_does_not_save_approvals_second_run.snap | 10 +- ...run_hook_post_merge_requires_approval.snap | 4 +- ..._run_hook_pre_merge_requires_approval.snap | 4 +- ...vals__ask_approvals_all_none_approved.snap | 12 +- 24 files changed, 726 insertions(+), 121 deletions(-) create mode 100644 tests/integration_tests/approval_pty.rs create mode 100644 tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap create mode 100644 tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_decline.snap create mode 100644 tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snap create mode 100644 tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_decline.snap create mode 100644 tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snap create mode 100644 tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snap rename tests/{snapshots/integration__integration_tests__approval_ui__permission_error_user_output.snap => integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap} (64%) create mode 100644 tests/snapshots/integration__integration_tests__approval_ui__approval_fails_in_non_tty.snap create mode 100644 tests/snapshots/integration__integration_tests__approval_ui__force_bypasses_tty_check.snap diff --git a/src/commands/command_approval.rs b/src/commands/command_approval.rs index 2eeeab1289..c7bb82e27e 100644 --- a/src/commands/command_approval.rs +++ b/src/commands/command_approval.rs @@ -75,8 +75,8 @@ pub fn approve_command_batch( Ok(true) } -fn prompt_for_batch_approval(commands: &[&Command], project_id: &str) -> std::io::Result { - use std::io::{self, Write}; +fn prompt_for_batch_approval(commands: &[&Command], project_id: &str) -> Result { + use std::io::{self, IsTerminal, Write}; let project_name = project_id.split('/').next_back().unwrap_or(project_id); let bold = AnstyleStyle::new().bold(); @@ -106,6 +106,13 @@ fn prompt_for_batch_approval(commands: &[&Command], project_id: &str) -> std::io eprintln!(); } + // Check if stdin is a TTY before attempting to prompt + // This happens AFTER showing the commands so they appear in CI/CD logs + // even when the prompt cannot be displayed (fail-fast principle) + if !io::stdin().is_terminal() { + return Err(GitError::NotInteractive); + } + // Flush stderr before showing prompt to ensure all output is visible stderr().flush()?; diff --git a/src/git/error.rs b/src/git/error.rs index 06fdbd76ae..8813e1cbce 100644 --- a/src/git/error.rs +++ b/src/git/error.rs @@ -44,6 +44,8 @@ pub enum GitError { MergeCommitsFound, /// Command was not approved by user CommandNotApproved, + /// Cannot prompt for approval in non-interactive environment + NotInteractive, /// Child process exited with non-zero code (preserves exit code for signals) ChildProcessExited { code: i32, message: String }, /// Push operation failed @@ -231,6 +233,14 @@ impl std::fmt::Display for GitError { Ok(()) // on_skip callback handles the printing } + // Not interactive (cannot prompt) + GitError::NotInteractive => { + write!( + f, + "{ERROR_EMOJI} {ERROR}Cannot prompt for approval in non-interactive environment{ERROR:#}\n\n{HINT_EMOJI} {HINT}In CI/CD, use --force to skip prompts. To pre-approve commands, use 'wt beta ask-approvals'{HINT:#}" + ) + } + // Child process exited with non-zero code // Display with error emoji - main.rs will use the exit code GitError::ChildProcessExited { code: _, message } => { diff --git a/tests/common/mod.rs b/tests/common/mod.rs index c1198cbcdd..d0e1afc202 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -171,6 +171,34 @@ impl TestRepo { cmd.env("SOURCE_DATE_EPOCH", "1761609600"); } + /// Get standard test environment variables as a vector + /// + /// This is useful for PTY tests and other cases where you need environment variables + /// as a vector rather than setting them on a Command. + pub fn test_env_vars(&self) -> Vec<(String, String)> { + vec![ + ("CLICOLOR_FORCE".to_string(), "1".to_string()), + ("COLUMNS".to_string(), "150".to_string()), + ("GIT_CONFIG_GLOBAL".to_string(), "/dev/null".to_string()), + ("GIT_CONFIG_SYSTEM".to_string(), "/dev/null".to_string()), + ( + "GIT_AUTHOR_DATE".to_string(), + "2025-01-01T00:00:00Z".to_string(), + ), + ( + "GIT_COMMITTER_DATE".to_string(), + "2025-01-01T00:00:00Z".to_string(), + ), + ("LC_ALL".to_string(), "C".to_string()), + ("LANG".to_string(), "C".to_string()), + ("SOURCE_DATE_EPOCH".to_string(), "1761609600".to_string()), + ( + "WORKTRUNK_CONFIG_PATH".to_string(), + self.test_config_path().display().to_string(), + ), + ] + } + /// Create a configured git command with args and current_dir set /// /// This is a convenience wrapper around configure_git_cmd that reduces boilerplate. diff --git a/tests/integration_tests/approval_pty.rs b/tests/integration_tests/approval_pty.rs new file mode 100644 index 0000000000..ef3bc9e332 --- /dev/null +++ b/tests/integration_tests/approval_pty.rs @@ -0,0 +1,390 @@ +//! PTY-based tests for interactive approval prompts +//! +//! These tests verify the approval workflow in a real PTY environment where stdin is a TTY. +//! This allows testing the actual interactive prompt behavior that users experience. +//! +//! Note: These tests are separate from `approval_ui.rs` because they require PTY setup +//! to simulate interactive terminals. The non-PTY tests in `approval_ui.rs` verify the +//! error case (non-TTY environments). + +use crate::common::TestRepo; +use insta::assert_snapshot; +use insta_cmd::get_cargo_bin; +use portable_pty::{CommandBuilder, PtySize, native_pty_system}; +use std::io::{Read, Write}; +use std::path::Path; + +/// Execute a command in a PTY with interactive input +/// +/// Returns (combined_output, exit_code) +fn exec_in_pty_with_input( + command: &str, + args: &[&str], + working_dir: &Path, + env_vars: &[(String, String)], + input: &str, +) -> (String, i32) { + let pty_system = native_pty_system(); + let pair = pty_system + .openpty(PtySize { + rows: 48, + cols: 200, + pixel_width: 0, + pixel_height: 0, + }) + .expect("Failed to open PTY"); + + // Spawn the command inside the PTY + let mut cmd = CommandBuilder::new(command); + for arg in args { + cmd.arg(arg); + } + cmd.cwd(working_dir); + + // Set minimal environment + cmd.env_clear(); + cmd.env( + "HOME", + std::env::var("HOME").unwrap_or_else(|_| "/tmp".to_string()), + ); + cmd.env( + "PATH", + std::env::var("PATH").unwrap_or_else(|_| "/usr/bin:/bin".to_string()), + ); + + // Add test-specific environment variables + for (key, value) in env_vars { + cmd.env(key, value); + } + + let mut child = pair + .slave + .spawn_command(cmd) + .expect("Failed to spawn command in PTY"); + drop(pair.slave); // Close slave in parent + + // Get reader and writer for the PTY master + let mut reader = pair + .master + .try_clone_reader() + .expect("Failed to clone PTY reader"); + let mut writer = pair.master.take_writer().expect("Failed to get PTY writer"); + + // Write input to the PTY (simulating user typing) + writer + .write_all(input.as_bytes()) + .expect("Failed to write input to PTY"); + writer.flush().expect("Failed to flush PTY writer"); + drop(writer); // Close writer so command sees EOF + + // Read all output + let mut buf = String::new(); + reader + .read_to_string(&mut buf) + .expect("Failed to read PTY output"); + + // Wait for child to exit + let exit_status = child.wait().expect("Failed to wait for child"); + let exit_code = exit_status.exit_code() as i32; + + (buf, exit_code) +} + +/// Normalize output for snapshot testing +fn normalize_output(output: &str) -> String { + // Remove repository paths + let output = regex::Regex::new(r"/[^\s]+\.tmp[^\s/]+") + .unwrap() + .replace_all(output, "[REPO]"); + + // Remove config paths + let output = regex::Regex::new(r"/var/folders/[^\s]+/test-config\.toml") + .unwrap() + .replace_all(&output, "[CONFIG]"); + + output.to_string() +} + +#[test] +fn test_approval_prompt_accept() { + let repo = TestRepo::new(); + repo.commit("Initial commit"); + repo.write_project_config(r#"post-create-command = "echo 'test command'""#); + repo.commit("Add config"); + + let env_vars = repo.test_env_vars(); + let (output, exit_code) = exec_in_pty_with_input( + get_cargo_bin("wt").to_str().unwrap(), + &["switch", "--create", "test-approve"], + repo.root_path(), + &env_vars, + "y\n", + ); + + let normalized = normalize_output(&output); + assert_eq!(exit_code, 0, "Command should succeed when approved"); + assert_snapshot!("approval_prompt_accept", normalized); +} + +#[test] +fn test_approval_prompt_decline() { + let repo = TestRepo::new(); + repo.commit("Initial commit"); + repo.write_project_config(r#"post-create-command = "echo 'test command'""#); + repo.commit("Add config"); + + let env_vars = repo.test_env_vars(); + let (output, exit_code) = exec_in_pty_with_input( + get_cargo_bin("wt").to_str().unwrap(), + &["switch", "--create", "test-decline"], + repo.root_path(), + &env_vars, + "n\n", + ); + + let normalized = normalize_output(&output); + assert_eq!(exit_code, 0, "Command should succeed even when declined"); + assert_snapshot!("approval_prompt_decline", normalized); +} + +#[test] +fn test_approval_prompt_multiple_commands() { + let repo = TestRepo::new(); + repo.commit("Initial commit"); + repo.write_project_config( + r#"post-create-command = [ + "echo 'First command'", + "echo 'Second command'", + "echo 'Third command'" +]"#, + ); + repo.commit("Add config"); + + let env_vars = repo.test_env_vars(); + let (output, exit_code) = exec_in_pty_with_input( + get_cargo_bin("wt").to_str().unwrap(), + &["switch", "--create", "test-multi"], + repo.root_path(), + &env_vars, + "y\n", + ); + + let normalized = normalize_output(&output); + assert_eq!(exit_code, 0); + assert_snapshot!("approval_prompt_multiple_commands", normalized); +} + +#[test] +fn test_approval_prompt_permission_error() { + let repo = TestRepo::new(); + repo.commit("Initial commit"); + repo.write_project_config(r#"post-create-command = "echo 'test command'""#); + repo.commit("Add config"); + + // Create config file and make it read-only to trigger permission error when saving approval + let config_path = repo.test_config_path(); + #[cfg(unix)] + { + use std::fs; + use std::os::unix::fs::PermissionsExt; + + // Create the config file first + fs::write(config_path, "# read-only config\n").unwrap(); + + // Make it read-only + let mut perms = fs::metadata(config_path).unwrap().permissions(); + perms.set_mode(0o444); // Read-only + fs::set_permissions(config_path, perms).unwrap(); + } + + let env_vars = repo.test_env_vars(); + let (output, exit_code) = exec_in_pty_with_input( + get_cargo_bin("wt").to_str().unwrap(), + &["switch", "--create", "test-permission"], + repo.root_path(), + &env_vars, + "y\n", + ); + + let normalized = normalize_output(&output); + assert_eq!( + exit_code, 0, + "Command should succeed even when saving approval fails" + ); + assert!( + normalized.contains("Failed to save command approval"), + "Should show permission error warning" + ); + assert!( + normalized.contains("You will be prompted again next time"), + "Should show hint about being prompted again" + ); + assert!( + normalized.contains("test command"), + "Command should still execute despite save failure" + ); + assert_snapshot!("approval_prompt_permission_error", normalized); +} + +#[test] +fn test_approval_prompt_named_commands() { + let repo = TestRepo::new(); + repo.commit("Initial commit"); + repo.write_project_config( + r#"[post-create-command] +install = "echo 'Installing dependencies...'" +build = "echo 'Building project...'" +test = "echo 'Running tests...'" +"#, + ); + repo.commit("Add config"); + + let env_vars = repo.test_env_vars(); + let (output, exit_code) = exec_in_pty_with_input( + get_cargo_bin("wt").to_str().unwrap(), + &["switch", "--create", "test-named"], + repo.root_path(), + &env_vars, + "y\n", + ); + + let normalized = normalize_output(&output); + assert_eq!(exit_code, 0, "Command should succeed when approved"); + assert!( + normalized.contains("install") && normalized.contains("Installing dependencies"), + "Should show command name 'install' and execute it" + ); + assert!( + normalized.contains("build") && normalized.contains("Building project"), + "Should show command name 'build' and execute it" + ); + assert!( + normalized.contains("test") && normalized.contains("Running tests"), + "Should show command name 'test' and execute it" + ); + assert_snapshot!("approval_prompt_named_commands", normalized); +} + +#[test] +fn test_approval_prompt_mixed_approved_unapproved_accept() { + let repo = TestRepo::new(); + repo.commit("Initial commit"); + repo.write_project_config( + r#"post-create-command = [ + "echo 'First command'", + "echo 'Second command'", + "echo 'Third command'" +]"#, + ); + repo.commit("Add config"); + + // Pre-approve the second command + let project_id = repo.root_path().file_name().unwrap().to_str().unwrap(); + repo.write_test_config(&format!( + r#"[projects."{}"] +approved-commands = ["echo 'Second command'"] +"#, + project_id + )); + + let env_vars = repo.test_env_vars(); + let (output, exit_code) = exec_in_pty_with_input( + get_cargo_bin("wt").to_str().unwrap(), + &["switch", "--create", "test-mixed-accept"], + repo.root_path(), + &env_vars, + "y\n", + ); + + let normalized = normalize_output(&output); + assert_eq!(exit_code, 0, "Command should succeed when approved"); + + // Check that only 2 commands are shown in the prompt (ANSI codes may be in between) + assert!( + normalized.contains("execute") + && normalized.contains("2") + && normalized.contains("command"), + "Should show 2 unapproved commands in prompt" + ); + assert!( + normalized.contains("First command"), + "Should execute first command" + ); + assert!( + normalized.contains("Second command"), + "Should execute pre-approved second command" + ); + assert!( + normalized.contains("Third command"), + "Should execute third command" + ); + assert_snapshot!( + "approval_prompt_mixed_approved_unapproved_accept", + normalized + ); +} + +#[test] +fn test_approval_prompt_mixed_approved_unapproved_decline() { + let repo = TestRepo::new(); + repo.commit("Initial commit"); + repo.write_project_config( + r#"post-create-command = [ + "echo 'First command'", + "echo 'Second command'", + "echo 'Third command'" +]"#, + ); + repo.commit("Add config"); + + // Pre-approve the second command + let project_id = repo.root_path().file_name().unwrap().to_str().unwrap(); + repo.write_test_config(&format!( + r#"[projects."{}"] +approved-commands = ["echo 'Second command'"] +"#, + project_id + )); + + let env_vars = repo.test_env_vars(); + let (output, exit_code) = exec_in_pty_with_input( + get_cargo_bin("wt").to_str().unwrap(), + &["switch", "--create", "test-mixed-decline"], + repo.root_path(), + &env_vars, + "n\n", + ); + + let normalized = normalize_output(&output); + + assert_eq!( + exit_code, 0, + "Command should succeed even when declined (worktree still created)" + ); + // Check that only 2 commands are shown in the prompt (ANSI codes may be in between) + assert!( + normalized.contains("execute") + && normalized.contains("2") + && normalized.contains("command"), + "Should show only 2 unapproved commands in prompt (not 3)" + ); + // When declined, ALL commands are skipped (including pre-approved ones) + assert!( + normalized.contains("Commands declined"), + "Should show 'Commands declined' message" + ); + // Commands appear in the prompt, but should not be executed + // Check for "Running post-create" which indicates execution + assert!( + !normalized.contains("Running post-create"), + "Should NOT execute any commands when declined" + ); + assert!( + normalized.contains("Created new worktree"), + "Should still create worktree even when commands declined" + ); + assert_snapshot!( + "approval_prompt_mixed_approved_unapproved_decline", + normalized + ); +} diff --git a/tests/integration_tests/approval_ui.rs b/tests/integration_tests/approval_ui.rs index 8d7e5950c7..8692c35ba0 100644 --- a/tests/integration_tests/approval_ui.rs +++ b/tests/integration_tests/approval_ui.rs @@ -239,67 +239,6 @@ test = "echo 'Running tests...'" ); } -/// Test that shows the full output when config save fails due to permission error -/// -/// This captures what users actually see when approve_command_batch() catches a save error -/// at src/commands/command_approval.rs:82-85. -#[test] -fn test_permission_error_user_output() { - use std::fs::Permissions; - use std::os::unix::fs::PermissionsExt; - - let repo = TestRepo::new(); - repo.commit("Initial commit"); - - // Set up project config with post-create command - repo.write_project_config(r#"post-create-command = "echo 'test command'""#); - - repo.commit("Add config"); - - // Create an initial config file and make it read-only BEFORE running the command - // This will cause the save operation to fail with a permission error - fs::write(repo.test_config_path(), "# read-only config\n").expect("Failed to create config"); - let readonly_perms = Permissions::from_mode(0o444); - fs::set_permissions(repo.test_config_path(), readonly_perms).expect("Failed to set read-only"); - - let settings = setup_snapshot_settings(&repo); - settings.bind(|| { - let mut cmd = make_snapshot_cmd(&repo, "switch", &["--create", "test-permission"], None); - cmd.stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()); - - let mut child = cmd.spawn().expect("Failed to spawn command"); - - // Approve the command - this will trigger the permission error when saving - { - let stdin = child.stdin.as_mut().expect("Failed to get stdin"); - stdin.write_all(b"y\n").expect("Failed to write to stdin"); - } - - let output = child - .wait_with_output() - .expect("Failed to wait for command"); - - // Restore write permissions to the config file for cleanup - let writable_perms = Permissions::from_mode(0o644); - fs::set_permissions(repo.test_config_path(), writable_perms) - .expect("Failed to restore permissions"); - - // Capture the full output showing the warning - let stdout = String::from_utf8_lossy(&output.stdout); - let stderr = String::from_utf8_lossy(&output.stderr); - let combined = format!( - "exit_code: {}\n----- stdout -----\n{}\n----- stderr -----\n{}", - output.status.code().unwrap_or(-1), - stdout, - stderr - ); - - insta::assert_snapshot!("permission_error_user_output", combined); - }); -} - /// Helper for run-hook snapshot tests with approval prompt fn snapshot_run_hook(test_name: &str, repo: &TestRepo, hook_type: &str, approve: bool) { let settings = setup_snapshot_settings(repo); @@ -383,3 +322,48 @@ fn test_run_hook_post_merge_requires_approval() { false, ); } + +/// Test that approval fails in non-TTY environment with clear error message +/// +/// When stdin is not a TTY (e.g., CI/CD, piped input), approval prompts cannot be shown. +/// The command should fail with a clear error telling users to use --force. +#[test] +fn test_approval_fails_in_non_tty() { + let repo = TestRepo::new(); + repo.commit("Initial commit"); + + repo.write_project_config(r#"post-create-command = "echo 'test command'""#); + repo.commit("Add config"); + + // Run WITHOUT piping stdin - this simulates non-TTY environment + // When running under cargo test, stdin is not a TTY + let settings = setup_snapshot_settings(&repo); + settings.bind(|| { + let mut cmd = make_snapshot_cmd(&repo, "switch", &["--create", "test-non-tty"], None); + assert_cmd_snapshot!("approval_fails_in_non_tty", cmd); + }); +} + +/// Test that --force flag bypasses TTY requirement +/// +/// Even in non-TTY environments, --force should allow commands to execute. +#[test] +fn test_force_bypasses_tty_check() { + let repo = TestRepo::new(); + repo.commit("Initial commit"); + + repo.write_project_config(r#"post-create-command = "echo 'test command'""#); + repo.commit("Add config"); + + // Run with --force to bypass approval entirely + let settings = setup_snapshot_settings(&repo); + settings.bind(|| { + let mut cmd = make_snapshot_cmd( + &repo, + "switch", + &["--create", "test-force-tty", "--force"], + None, + ); + assert_cmd_snapshot!("force_bypasses_tty_check", cmd); + }); +} diff --git a/tests/integration_tests/mod.rs b/tests/integration_tests/mod.rs index 65578c6b28..d64560509f 100644 --- a/tests/integration_tests/mod.rs +++ b/tests/integration_tests/mod.rs @@ -3,6 +3,7 @@ #![cfg(unix)] // column_alignment merged into spacing_edge_cases +pub mod approval_pty; pub mod approval_save; pub mod approval_ui; pub mod approvals; diff --git a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap new file mode 100644 index 0000000000..fb3a3c926e --- /dev/null +++ b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap @@ -0,0 +1,17 @@ +--- +source: tests/integration_tests/approval_pty.rs +expression: normalized +--- +y + +^D🟑 test-repo wants to execute 1 command: + +πŸ”„ post-create: +  echo 'test command' + +πŸ’‘ Allow and remember? [y/N] +πŸ”„ Running post-create: +  echo 'test command' +test command +βœ… Created new worktree for test-approve from main at [REPO]/test-repo.test-approve +πŸ’‘ To enable automatic cd, run: wt config shell diff --git a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_decline.snap b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_decline.snap new file mode 100644 index 0000000000..f9126dc375 --- /dev/null +++ b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_decline.snap @@ -0,0 +1,15 @@ +--- +source: tests/integration_tests/approval_pty.rs +expression: normalized +--- +n + +^D🟑 test-repo wants to execute 1 command: + +πŸ”„ post-create: +  echo 'test command' + +πŸ’‘ Allow and remember? [y/N] +βšͺ Commands declined, continuing worktree creation +βœ… Created new worktree for test-decline from main at [REPO]/test-repo.test-decline +πŸ’‘ To enable automatic cd, run: wt config shell diff --git a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snap b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snap new file mode 100644 index 0000000000..bf594e76d2 --- /dev/null +++ b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snap @@ -0,0 +1,26 @@ +--- +source: tests/integration_tests/approval_pty.rs +expression: normalized +--- +y + +^D🟑 test-repo wants to execute 2 commands: + +πŸ”„ post-create: +  echo 'First command' + +πŸ”„ post-create: +  echo 'Third command' + +πŸ’‘ Allow and remember? [y/N] +πŸ”„ Running post-create: +  echo 'First command' +First command +πŸ”„ Running post-create: +  echo 'Second command' +Second command +πŸ”„ Running post-create: +  echo 'Third command' +Third command +βœ… Created new worktree for test-mixed-accept from main at [REPO]/test-repo.test-mixed-accept +πŸ’‘ To enable automatic cd, run: wt config shell diff --git a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_decline.snap b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_decline.snap new file mode 100644 index 0000000000..4dbc2fbb90 --- /dev/null +++ b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_decline.snap @@ -0,0 +1,18 @@ +--- +source: tests/integration_tests/approval_pty.rs +expression: normalized +--- +n + +^D🟑 test-repo wants to execute 2 commands: + +πŸ”„ post-create: +  echo 'First command' + +πŸ”„ post-create: +  echo 'Third command' + +πŸ’‘ Allow and remember? [y/N] +βšͺ Commands declined, continuing worktree creation +βœ… Created new worktree for test-mixed-decline from main at [REPO]/test-repo.test-mixed-decline +πŸ’‘ To enable automatic cd, run: wt config shell diff --git a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snap b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snap new file mode 100644 index 0000000000..2fbfcd7ea8 --- /dev/null +++ b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snap @@ -0,0 +1,29 @@ +--- +source: tests/integration_tests/approval_pty.rs +expression: normalized +--- +y + +^D🟑 test-repo wants to execute 3 commands: + +πŸ”„ post-create: +  echo 'First command' + +πŸ”„ post-create: +  echo 'Second command' + +πŸ”„ post-create: +  echo 'Third command' + +πŸ’‘ Allow and remember? [y/N] +πŸ”„ Running post-create: +  echo 'First command' +First command +πŸ”„ Running post-create: +  echo 'Second command' +Second command +πŸ”„ Running post-create: +  echo 'Third command' +Third command +βœ… Created new worktree for test-multi from main at [REPO]/test-repo.test-multi +πŸ’‘ To enable automatic cd, run: wt config shell diff --git a/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snap b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snap new file mode 100644 index 0000000000..8aeefec16f --- /dev/null +++ b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snap @@ -0,0 +1,29 @@ +--- +source: tests/integration_tests/approval_pty.rs +expression: normalized +--- +y + +^D🟑 test-repo wants to execute 3 commands: + +πŸ”„ post-create install: +  echo 'Installing dependencies...' + +πŸ”„ post-create build: +  echo 'Building project...' + +πŸ”„ post-create test: +  echo 'Running tests...' + +πŸ’‘ Allow and remember? [y/N] +πŸ”„ Running post-create install: +  echo 'Installing dependencies...' +Installing dependencies... +πŸ”„ Running post-create build: +  echo 'Building project...' +Building project... +πŸ”„ Running post-create test: +  echo 'Running tests...' +Running tests... +βœ… Created new worktree for test-named from main at [REPO]/test-repo.test-named +πŸ’‘ To enable automatic cd, run: wt config shell diff --git a/tests/snapshots/integration__integration_tests__approval_ui__permission_error_user_output.snap b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap similarity index 64% rename from tests/snapshots/integration__integration_tests__approval_ui__permission_error_user_output.snap rename to tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap index 3a786a53ac..46d99d400f 100644 --- a/tests/snapshots/integration__integration_tests__approval_ui__permission_error_user_output.snap +++ b/tests/integration_tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap @@ -1,21 +1,19 @@ --- -source: tests/integration_tests/approval_ui.rs -expression: combined +source: tests/integration_tests/approval_pty.rs +expression: normalized --- -exit_code: 0 ------ stdout ----- -🟑 Failed to save command approval: Failed to write config file: Permission denied (os error 13) -πŸ’‘ You will be prompted again next time. -πŸ”„ Running post-create: -  echo 'test command' -βœ… Created new worktree for test-permission from main at [REPO].test-permission -πŸ’‘ To enable automatic cd, run: wt config shell +y ------ stderr ----- -🟑 test-repo wants to execute 1 command: +^D🟑 test-repo wants to execute 1 command: πŸ”„ post-create:   echo 'test command' πŸ’‘ Allow and remember? [y/N] +🟑 Failed to save command approval: Failed to write config file: Permission denied (os error 13) +πŸ’‘ You will be prompted again next time. +πŸ”„ Running post-create: +  echo 'test command' test command +βœ… Created new worktree for test-permission from main at [REPO]/test-repo.test-permission +πŸ’‘ To enable automatic cd, run: wt config shell diff --git a/tests/snapshots/integration__integration_tests__approval_ui__approval_fails_in_non_tty.snap b/tests/snapshots/integration__integration_tests__approval_ui__approval_fails_in_non_tty.snap new file mode 100644 index 0000000000..c7ee87efa1 --- /dev/null +++ b/tests/snapshots/integration__integration_tests__approval_ui__approval_fails_in_non_tty.snap @@ -0,0 +1,33 @@ +--- +source: tests/integration_tests/approval_ui.rs +info: + program: wt + args: + - switch + - "--create" + - test-non-tty + env: + CLICOLOR_FORCE: "1" + COLUMNS: "150" + GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z" + GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z" + GIT_CONFIG_GLOBAL: /dev/null + GIT_CONFIG_SYSTEM: /dev/null + GIT_EDITOR: "" + LANG: C + LC_ALL: C + SOURCE_DATE_EPOCH: "1761609600" + WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpSRSVBw/test-config.toml +--- +success: false +exit_code: 1 +----- stdout ----- +❌ Cannot prompt for approval in non-interactive environment + +πŸ’‘ In CI/CD, use --force to skip prompts. To pre-approve commands, use 'wt beta ask-approvals' + +----- stderr ----- +🟑 test-repo wants to execute 1 command: + +πŸ”„ post-create: +  echo 'test command' diff --git a/tests/snapshots/integration__integration_tests__approval_ui__approval_mixed_approved_unapproved.snap b/tests/snapshots/integration__integration_tests__approval_ui__approval_mixed_approved_unapproved.snap index bfd7aebaab..94ab0a06ee 100644 --- a/tests/snapshots/integration__integration_tests__approval_ui__approval_mixed_approved_unapproved.snap +++ b/tests/snapshots/integration__integration_tests__approval_ui__approval_mixed_approved_unapproved.snap @@ -2,11 +2,11 @@ source: tests/integration_tests/approval_ui.rs expression: combined --- -exit_code: 0 +exit_code: 1 ----- stdout ----- -βšͺ Commands declined, continuing worktree creation -βœ… Created new worktree for test-mixed from main at [REPO].test-mixed -πŸ’‘ To enable automatic cd, run: wt config shell +❌ Cannot prompt for approval in non-interactive environment + +πŸ’‘ In CI/CD, use --force to skip prompts. To pre-approve commands, use 'wt beta ask-approvals' ----- stderr ----- 🟑 test-repo wants to execute 2 commands: @@ -16,5 +16,3 @@ exit_code: 0 πŸ”„ post-create:   echo 'Third command' - -πŸ’‘ Allow and remember? [y/N] diff --git a/tests/snapshots/integration__integration_tests__approval_ui__approval_multiple_commands.snap b/tests/snapshots/integration__integration_tests__approval_ui__approval_multiple_commands.snap index 4960fc85e1..8d91e670e3 100644 --- a/tests/snapshots/integration__integration_tests__approval_ui__approval_multiple_commands.snap +++ b/tests/snapshots/integration__integration_tests__approval_ui__approval_multiple_commands.snap @@ -2,11 +2,11 @@ source: tests/integration_tests/approval_ui.rs expression: combined --- -exit_code: 0 +exit_code: 1 ----- stdout ----- -βšͺ Commands declined, continuing worktree creation -βœ… Created new worktree for test/nested-branch from main at [REPO].test-nested-branch -πŸ’‘ To enable automatic cd, run: wt config shell +❌ Cannot prompt for approval in non-interactive environment + +πŸ’‘ In CI/CD, use --force to skip prompts. To pre-approve commands, use 'wt beta ask-approvals' ----- stderr ----- 🟑 test-repo wants to execute 4 commands: @@ -22,5 +22,3 @@ exit_code: 0 πŸ”„ post-create:   cd [REPO].test-nested-branch && pwd - -πŸ’‘ Allow and remember? [y/N] diff --git a/tests/snapshots/integration__integration_tests__approval_ui__approval_named_commands.snap b/tests/snapshots/integration__integration_tests__approval_ui__approval_named_commands.snap index 2a65e354b4..c5fec5fd18 100644 --- a/tests/snapshots/integration__integration_tests__approval_ui__approval_named_commands.snap +++ b/tests/snapshots/integration__integration_tests__approval_ui__approval_named_commands.snap @@ -2,11 +2,11 @@ source: tests/integration_tests/approval_ui.rs expression: combined --- -exit_code: 0 +exit_code: 1 ----- stdout ----- -βšͺ Commands declined, continuing worktree creation -βœ… Created new worktree for test-named from main at [REPO].test-named -πŸ’‘ To enable automatic cd, run: wt config shell +❌ Cannot prompt for approval in non-interactive environment + +πŸ’‘ In CI/CD, use --force to skip prompts. To pre-approve commands, use 'wt beta ask-approvals' ----- stderr ----- 🟑 test-repo wants to execute 3 commands: @@ -19,5 +19,3 @@ exit_code: 0 πŸ”„ post-create test:   echo 'Running tests...' - -πŸ’‘ Allow and remember? [y/N] diff --git a/tests/snapshots/integration__integration_tests__approval_ui__approval_single_command.snap b/tests/snapshots/integration__integration_tests__approval_ui__approval_single_command.snap index 9436925611..8e4de590fe 100644 --- a/tests/snapshots/integration__integration_tests__approval_ui__approval_single_command.snap +++ b/tests/snapshots/integration__integration_tests__approval_ui__approval_single_command.snap @@ -2,16 +2,14 @@ source: tests/integration_tests/approval_ui.rs expression: combined --- -exit_code: 0 +exit_code: 1 ----- stdout ----- -βšͺ Commands declined, continuing worktree creation -βœ… Created new worktree for feature/test-approval from main at [REPO].feature-test-approval -πŸ’‘ To enable automatic cd, run: wt config shell +❌ Cannot prompt for approval in non-interactive environment + +πŸ’‘ In CI/CD, use --force to skip prompts. To pre-approve commands, use 'wt beta ask-approvals' ----- stderr ----- 🟑 test-repo wants to execute 1 command: πŸ”„ post-create:   echo 'Worktree path: [REPO].feature-test-approval' - -πŸ’‘ Allow and remember? [y/N] diff --git a/tests/snapshots/integration__integration_tests__approval_ui__decline_approval_skips_only_unapproved.snap b/tests/snapshots/integration__integration_tests__approval_ui__decline_approval_skips_only_unapproved.snap index 2b5ca7ed2d..94ab0a06ee 100644 --- a/tests/snapshots/integration__integration_tests__approval_ui__decline_approval_skips_only_unapproved.snap +++ b/tests/snapshots/integration__integration_tests__approval_ui__decline_approval_skips_only_unapproved.snap @@ -2,11 +2,11 @@ source: tests/integration_tests/approval_ui.rs expression: combined --- -exit_code: 0 +exit_code: 1 ----- stdout ----- -βšͺ Commands declined, continuing worktree creation -βœ… Created new worktree for test-decline from main at [REPO].test-decline -πŸ’‘ To enable automatic cd, run: wt config shell +❌ Cannot prompt for approval in non-interactive environment + +πŸ’‘ In CI/CD, use --force to skip prompts. To pre-approve commands, use 'wt beta ask-approvals' ----- stderr ----- 🟑 test-repo wants to execute 2 commands: @@ -16,5 +16,3 @@ exit_code: 0 πŸ”„ post-create:   echo 'Third command' - -πŸ’‘ Allow and remember? [y/N] diff --git a/tests/snapshots/integration__integration_tests__approval_ui__force_bypasses_tty_check.snap b/tests/snapshots/integration__integration_tests__approval_ui__force_bypasses_tty_check.snap new file mode 100644 index 0000000000..bac303c136 --- /dev/null +++ b/tests/snapshots/integration__integration_tests__approval_ui__force_bypasses_tty_check.snap @@ -0,0 +1,32 @@ +--- +source: tests/integration_tests/approval_ui.rs +info: + program: wt + args: + - switch + - "--create" + - test-force-tty + - "--force" + env: + CLICOLOR_FORCE: "1" + COLUMNS: "150" + GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z" + GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z" + GIT_CONFIG_GLOBAL: /dev/null + GIT_CONFIG_SYSTEM: /dev/null + GIT_EDITOR: "" + LANG: C + LC_ALL: C + SOURCE_DATE_EPOCH: "1761609600" + WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpmlvzfL/test-config.toml +--- +success: true +exit_code: 0 +----- stdout ----- +πŸ”„ Running post-create: +  echo 'test command' +βœ… Created new worktree for test-force-tty from main at [REPO].test-force-tty +πŸ’‘ To enable automatic cd, run: wt config shell + +----- stderr ----- +test command diff --git a/tests/snapshots/integration__integration_tests__approval_ui__force_does_not_save_approvals_second_run.snap b/tests/snapshots/integration__integration_tests__approval_ui__force_does_not_save_approvals_second_run.snap index 933ddef08a..2620b18227 100644 --- a/tests/snapshots/integration__integration_tests__approval_ui__force_does_not_save_approvals_second_run.snap +++ b/tests/snapshots/integration__integration_tests__approval_ui__force_does_not_save_approvals_second_run.snap @@ -2,16 +2,14 @@ source: tests/integration_tests/approval_ui.rs expression: combined --- -exit_code: 0 +exit_code: 1 ----- stdout ----- -βšͺ Commands declined, continuing worktree creation -βœ… Created new worktree for test-force-2 from main at [REPO].test-force-2 -πŸ’‘ To enable automatic cd, run: wt config shell +❌ Cannot prompt for approval in non-interactive environment + +πŸ’‘ In CI/CD, use --force to skip prompts. To pre-approve commands, use 'wt beta ask-approvals' ----- stderr ----- 🟑 test-repo wants to execute 1 command: πŸ”„ post-create:   echo 'test command' > output.txt - -πŸ’‘ Allow and remember? [y/N] diff --git a/tests/snapshots/integration__integration_tests__approval_ui__run_hook_post_merge_requires_approval.snap b/tests/snapshots/integration__integration_tests__approval_ui__run_hook_post_merge_requires_approval.snap index d95e1699ce..674623a8e3 100644 --- a/tests/snapshots/integration__integration_tests__approval_ui__run_hook_post_merge_requires_approval.snap +++ b/tests/snapshots/integration__integration_tests__approval_ui__run_hook_post_merge_requires_approval.snap @@ -4,12 +4,12 @@ expression: combined --- exit_code: 1 ----- stdout ----- +❌ Cannot prompt for approval in non-interactive environment +πŸ’‘ In CI/CD, use --force to skip prompts. To pre-approve commands, use 'wt beta ask-approvals' ----- stderr ----- 🟑 test-repo wants to execute 1 command: πŸ”„ post-merge:   echo 'Post-merge cleanup for main' - -πŸ’‘ Allow and remember? [y/N] diff --git a/tests/snapshots/integration__integration_tests__approval_ui__run_hook_pre_merge_requires_approval.snap b/tests/snapshots/integration__integration_tests__approval_ui__run_hook_pre_merge_requires_approval.snap index 8d82dac681..6b6e0e106b 100644 --- a/tests/snapshots/integration__integration_tests__approval_ui__run_hook_pre_merge_requires_approval.snap +++ b/tests/snapshots/integration__integration_tests__approval_ui__run_hook_pre_merge_requires_approval.snap @@ -4,12 +4,12 @@ expression: combined --- exit_code: 1 ----- stdout ----- +❌ Cannot prompt for approval in non-interactive environment +πŸ’‘ In CI/CD, use --force to skip prompts. To pre-approve commands, use 'wt beta ask-approvals' ----- stderr ----- 🟑 test-repo wants to execute 1 command: πŸ”„ pre-merge:   echo 'Running pre-merge checks on main' - -πŸ’‘ Allow and remember? [y/N] diff --git a/tests/snapshots/integration__integration_tests__approvals__ask_approvals_all_none_approved.snap b/tests/snapshots/integration__integration_tests__approvals__ask_approvals_all_none_approved.snap index 7984d6c063..fe0e47f840 100644 --- a/tests/snapshots/integration__integration_tests__approvals__ask_approvals_all_none_approved.snap +++ b/tests/snapshots/integration__integration_tests__approvals__ask_approvals_all_none_approved.snap @@ -17,17 +17,17 @@ info: LANG: C LC_ALL: C SOURCE_DATE_EPOCH: "1761609600" - WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpfCfS8A/test-config.toml + WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpuzpIU1/test-config.toml --- -success: true -exit_code: 0 +success: false +exit_code: 1 ----- stdout ----- -βšͺ Commands declined +❌ Cannot prompt for approval in non-interactive environment + +πŸ’‘ In CI/CD, use --force to skip prompts. To pre-approve commands, use 'wt beta ask-approvals' ----- stderr ----- 🟑 test-repo wants to execute 1 command: πŸ”„ post-create:   echo 'test' - -πŸ’‘ Allow and remember? [y/N] From acae2677cf8eab926033ce054a34b53ac8be7f5c Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Mon, 17 Nov 2025 19:10:26 -0800 Subject: [PATCH 2/5] Document best practices for Code Quality --- CLAUDE.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CLAUDE.md b/CLAUDE.md index dad103621a..b236c3af45 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -26,6 +26,17 @@ Examples of acceptable breaking changes: When the project reaches v1.0 or gains users, we'll adopt stability commitments. Until then, we're free to iterate rapidly. +## Code Quality + +Claude commonly makes the mistake of adding `#[allow(dead_code)]` when writing code that isn't immediately used. Don't suppress the warningβ€”either delete the code or add a TODO comment explaining when it will be used. + +Example of escalating instead of suppressing: + +```rust +// TODO(feature-name): Used by upcoming config validation +fn parse_config() { ... } +``` + ## CLI Output Formatting Standards ### User Message Principles From 9832f67eaf621a0bf7f042e51c491ec320c58c99 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Mon, 17 Nov 2025 19:35:47 -0800 Subject: [PATCH 3/5] docs: Refine CLAUDE.md for conciseness Reduces unnecessary words and redundant examples to improve clarity. --- CLAUDE.md | 320 ++++++++++-------------------------------------------- 1 file changed, 57 insertions(+), 263 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index b236c3af45..be41ac517d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -17,12 +17,7 @@ When making decisions, prioritize: 2. **Clean design** over maintaining old patterns 3. **Modern conventions** over legacy approaches -Examples of acceptable breaking changes: -- Changing config file locations (e.g., moving from `~/Library/Application Support` to `~/.config`) -- Renaming commands or flags for clarity -- Changing output formats -- Replacing dependencies with better alternatives -- Restructuring the codebase +Acceptable breaking changes: config locations, command/flag names, output formats, dependencies, codebase structure. When the project reaches v1.0 or gains users, we'll adopt stability commitments. Until then, we're free to iterate rapidly. @@ -41,50 +36,30 @@ fn parse_config() { ... } ### User Message Principles -Output messages should acknowledge user-supplied arguments (flags, options, values) by reflecting those choices in the message text. This confirms the program understood their intent and used their input correctly. - -**Examples:** +Output messages should acknowledge user-supplied arguments (flags, options, values) by reflecting those choices in the message text. ```rust // User runs: wt switch --create feature --base=main // βœ… GOOD - acknowledges the base branch "Created new worktree for feature from main at /path/to/worktree" - // ❌ BAD - ignores the base argument "Created new worktree for feature at /path/to/worktree" - -// User runs: wt merge --squash -// βœ… GOOD - acknowledges squash mode -"Squashing 3 commits into 1..." - -// ❌ BAD - doesn't mention squashing -"Merging commits..." ``` -This confirms the program understood user intent and used their input correctly. - -**Avoid redundant parenthesized content:** - -Parenthesized text should add new information, not restate what's already said. If the parentheses just rephrase the main message in different words, remove them. +**Avoid redundant parenthesized content:** Parenthesized text should add new information, not restate what's already said. ```rust // ❌ BAD - parentheses restate "no changes" "No changes after squashing 3 commits (commits resulted in no net changes)" - // βœ… GOOD - clear and concise "No changes after squashing 3 commits" - -// βœ… GOOD - parentheses add supplementary info (stats) +// βœ… GOOD - parentheses add supplementary info "Committing with default message... (3 files, +45, -12)" - -// βœ… GOOD - parentheses explain why -"Worktree preserved (--no-remove)" ``` ### The anstyle Ecosystem All styling uses the **anstyle ecosystem** for composable, auto-detecting terminal output: - - **`anstream`**: Auto-detecting I/O streams (println!, eprintln! macros) - **`anstyle`**: Core styling with inline pattern `{style}text{style:#}` - **Color detection**: Respects NO_COLOR, CLICOLOR_FORCE, TTY detection @@ -99,34 +74,18 @@ Six canonical message patterns with their emojis: 4. **Warnings**: 🟑 + yellow text (non-blocking issues) 5. **Hints**: πŸ’‘ + dimmed text (actionable suggestions, tips for user) 6. **Info**: βšͺ + text (neutral status, system feedback, metadata) - - **NOT dimmed**: Primary status messages that answer the user's question - - **Dimmed**: Supplementary metadata and contextual information + - **NOT dimmed**: Primary status messages + - **Dimmed**: Supplementary metadata -Every user-facing message requires either an emoji or a gutter for consistent visual separation. - -```rust -// βœ… GOOD - standalone message with emoji -println!("{SUCCESS_EMOJI} {GREEN}Created worktree{GREEN:#}"); - -// βœ… GOOD - quoted content with gutter -print!("{}", format_with_gutter(&command)); - -// βœ… GOOD - section header with emoji, followed by gutter content -println!("{INFO_EMOJI} Global Config: {bold}{}{bold:#}", path.display()); - -// ❌ BAD - standalone message without emoji or gutter -println!("{dim}Operation declined{dim:#}"); -``` +**Every user-facing message requires either an emoji or a gutter** for consistent visual separation. ### stdout vs stderr: Separation by Mode -Output separation differs between interactive and directive modes. - -Interactive mode: +**Interactive mode:** - stdout: All worktrunk output (messages, errors, warnings, progress) - stderr: Child process output (git, npm, user commands) + interactive prompts -Directive mode (--internal flag for shell integration): +**Directive mode** (--internal flag for shell integration): - stdout: Only directives (`__WORKTRUNK_CD__`, `__WORKTRUNK_EXEC__`) - NUL-terminated - stderr: All user-facing messages + child process output - streams in real-time @@ -135,31 +94,21 @@ Use the output system (`output::success()`, `output::progress()`, etc.) to handl ```rust // βœ… GOOD - use output system (handles both modes) output::success("Branch created")?; -output::change_directory(&path)?; // ❌ BAD - direct writes bypass output system println!("Branch created"); -writeln!(io::stderr(), "Progress...")?; ``` -Interactive prompts flush stderr before blocking on stdin to prevent interleaving: +Interactive prompts must flush stderr before blocking on stdin: ```rust eprint!("πŸ’‘ Allow and remember? [y/N] "); -stderr().flush()?; // Ensures prompt is visible before blocking +stderr().flush()?; io::stdin().read_line(&mut response)?; ``` -Child processes redirect stdout to stderr for deterministic ordering: -```rust -let wrapped = format!("{{ {}; }} 1>&2", command); -Command::new("sh").arg("-c").arg(&wrapped).status()?; -``` - ### Temporal Locality: Output Should Be Close to Operations -Output should appear immediately adjacent to the operations it describes. Output that appears far from its triggering operation breaks the user's mental model. - -Progress messages apply only to slow operations (>400ms): git operations, network requests, builds. Fast operations like file checks or config reads should not show progress. +Output should appear immediately adjacent to the operations it describes. Progress messages apply only to slow operations (>400ms): git operations, network requests, builds. Sequential operations should show immediate feedback: ```rust @@ -170,7 +119,7 @@ for item in items { } ``` -Output decoupled from operations creates confusion: +Bad example (output decoupled from operations): ``` πŸ”„ Removing worktree for feature... πŸ”„ Removing worktree for bugfix... @@ -179,7 +128,7 @@ Removed worktree for feature ← All output at the end Removed worktree for bugfix ``` -Signs of poor temporal locality: collecting messages in a buffer, single success message for batch operations, no progress before slow operations, progress without matching success. +Signs of poor temporal locality: collecting messages in a buffer, single success message for batch operations, no progress before slow operations. ### Information Display: Show Once, Not Twice @@ -190,17 +139,11 @@ Progress messages should include all relevant details (what's being done, counts output::progress("πŸ”„ Squashing 3 commits with working tree changes into 1 (5 files, +120, -45)...")?; perform_squash()?; output::success("βœ… Squashed @ a1b2c3d")?; - -// ❌ BAD - repeating detail in success message -output::progress("πŸ”„ Squashing 3 commits into 1...")?; -perform_squash()?; -output::success("βœ… Squashed 3 commits into 1 @ a1b2c3d")?; // Redundant ``` ### Semantic Style Constants Style constants defined in `src/styling.rs`: - - `ERROR`: Red (errors, conflicts) - `WARNING`: Yellow (warnings) - `HINT`: Dimmed (hints, secondary information) @@ -208,103 +151,48 @@ Style constants defined in `src/styling.rs`: - `ADDITION`: Green (diffs, additions) - `DELETION`: Red (diffs, deletions) -Emoji constants: - -- `ERROR_EMOJI`: ❌ (use with ERROR style) -- `WARNING_EMOJI`: 🟑 (use with WARNING style) -- `HINT_EMOJI`: πŸ’‘ (use with HINT style) -- `INFO_EMOJI`: βšͺ (use with dimmed style) +Emoji constants: `ERROR_EMOJI` (❌), `WARNING_EMOJI` (🟑), `HINT_EMOJI` (πŸ’‘), `INFO_EMOJI` (βšͺ) ### Inline Formatting Pattern Use anstyle's inline pattern `{style}text{style:#}` where `#` means reset: ```rust -use worktrunk::styling::{println, ERROR, ERROR_EMOJI, WARNING, WARNING_EMOJI, HINT, HINT_EMOJI, AnstyleStyle}; +use worktrunk::styling::{println, ERROR, ERROR_EMOJI, WARNING_EMOJI, HINT_EMOJI, AnstyleStyle}; use anstyle::{AnsiColor, Color}; -// Progress let cyan = AnstyleStyle::new().fg_color(Some(Color::Ansi(AnsiColor::Cyan))); println!("πŸ”„ {cyan}Rebasing onto main...{cyan:#}"); -// Success -let green = AnstyleStyle::new().fg_color(Some(Color::Ansi(AnsiColor::Green))); -println!("βœ… {green}Merged to main{green:#}"); - -// Error - ALL our output goes to stdout println!("{ERROR_EMOJI} {ERROR}Working tree has uncommitted changes{ERROR:#}"); - -// Warning - ALL our output goes to stdout -println!("{WARNING_EMOJI} {WARNING}Uncommitted changes detected{WARNING:#}"); - -// Hint println!("{HINT_EMOJI} {HINT}Use 'wt list' to see all worktrees{HINT:#}"); ``` ### Composing Styles -Compose styles using anstyle methods (`.bold()`, `.fg_color()`, etc.). Branch names in messages (not tables) should be bolded: +Compose styles using anstyle methods (`.bold()`, `.fg_color()`, etc.). Branch names in messages (not tables) should be bolded. Tables (`wt list`) use conditional styling for branch names to indicate worktree state (current/primary/other). -```rust -use worktrunk::styling::{println, AnstyleStyle, ERROR}; - -// Error message with bold branch name -let error_bold = ERROR.bold(); -println!("❌ Branch '{error_bold}{branch}{error_bold:#}' already exists"); - -// Success message with bold branch name -let bold = AnstyleStyle::new().bold(); -println!("Switched to worktree: {bold}{branch}{bold:#}"); -``` - -Tables (`wt list`) use conditional styling for branch names to indicate worktree state (current/primary/other), not bold. - -Nested style resets leak color. Compose all attributes into a single style object instead: +Nested style resets leak color. Compose all attributes into a single style object: ```rust // ❌ BAD - nested reset leaks color "{WARNING}Text with {bold}nested{bold:#} styles{WARNING:#}" - // βœ… GOOD - compose styles together let warning_bold = WARNING.bold(); "{WARNING}Text with {warning_bold}composed{warning_bold:#} styles{WARNING:#}" ``` -Resetting all styles requires `anstyle::Reset`, not `{:#}` on empty `Style`: - -```rust -// ❌ BAD - produces empty string -output.push_str(&format!("{:#}", Style::new())); - -// βœ… GOOD - produces \x1b[0m reset code -output.push_str(&format!("{}", anstyle::Reset)); -``` - -### Information Hierarchy & Styling - -Bold elements that answer the user's question; dim elements that provide context. - -Styled elements must maintain their surrounding color. Compose the color with the style using `.bold()` or `.dimmed()` to avoid leaking color. +Styled elements must maintain their surrounding color. Compose the color with the style to avoid leaking: ```rust // ❌ WRONG - styled element loses surrounding color let bold = AnstyleStyle::new().bold(); println!("βœ… {GREEN}Message {bold}{path}{bold:#}{GREEN:#}"); // Path will be black/white! - // βœ… RIGHT - compose color with style let green_bold = GREEN.bold(); -println!("βœ… {GREEN}Created worktree, changed directory to {green_bold}{}{green_bold:#}"); - -// Re-establish outer color after styled elements mid-message -let green_bold = GREEN.bold(); -println!("βœ… {GREEN}Already on {green_bold}{branch}{green_bold:#}{GREEN}, nothing to merge{GREEN:#}"); -// ^^^^^^^ Re-establish GREEN +println!("βœ… {GREEN}Created worktree at {green_bold}{path}{green_bold:#}{GREEN:#}"); ``` -### Indentation Policy - -No manual indentation - styling provides hierarchy. For quoted content, use `format_with_gutter()`. - ### Color Detection Colors automatically adjust based on environment (NO_COLOR, CLICOLOR_FORCE, TTY detection) via `anstream` macros. @@ -314,7 +202,6 @@ Styled print macros must be imported from `worktrunk::styling`, not stdlib: ```rust // ❌ BAD - uses standard library macro, bypasses anstream eprintln!("{}", styled_text); - // βœ… GOOD - import and use anstream-wrapped version use worktrunk::styling::eprintln; eprintln!("{}", styled_text); @@ -322,12 +209,11 @@ eprintln!("{}", styled_text); ### Design Principles -- **Use the ecosystem, not manual escape codes** - Use `anstyle` for colors, `osc8` for hyperlinks, `strip-ansi-escapes` for stripping. Never manually write ANSI codes (`\x1b[...`) in production code +- **Use the ecosystem, not manual escape codes** - Use `anstyle` for colors, `osc8` for hyperlinks, `strip-ansi-escapes` for stripping. Never manually write ANSI codes (`\x1b[...`) - **Inline over wrappers** - Use `{style}text{style:#}` pattern, not wrapper functions - **Composition over special cases** - Use `.bold()`, `.fg_color()`, not `format_X_with_Y()` - **Semantic constants** - Use `ERROR`, `WARNING`, not raw colors - **YAGNI for presentation** - Most output needs no styling -- **Minimal output** - Only use formatting where it adds clarity - **Unicode-aware** - Width calculations respect emoji and CJK characters (via `StyledLine`) - **Graceful degradation** - Must work without color support @@ -340,13 +226,9 @@ use worktrunk::styling::StyledLine; use anstyle::{AnsiColor, Color, Style}; let mut line = StyledLine::new(); -let dim = Style::new().dimmed(); -let cyan = Style::new().fg_color(Some(Color::Ansi(AnsiColor::Cyan))); - -line.push_styled("Branch", dim); +line.push_styled("Branch", Style::new().dimmed()); line.push_raw(" "); -line.push_styled("main", cyan); - +line.push_styled("main", Style::new().fg_color(Some(Color::Ansi(AnsiColor::Cyan)))); println!("{}", line.render()); ``` @@ -357,44 +239,28 @@ See `src/commands/list/render.rs` for advanced usage. Use `format_with_gutter()` for quoted content. Gutter content must be raw external output without our styling additions (emojis, colors). ```rust -use worktrunk::styling::format_with_gutter; -use worktrunk::git::GitError; - // βœ… GOOD - raw git output in gutter let raw_error = match &error { - GitError::CommandFailed(msg) => msg.as_str(), // Extract raw string + GitError::CommandFailed(msg) => msg.as_str(), _ => &error.to_string(), }; super::gutter(format_with_gutter(raw_error, "", None))?; -// ❌ BAD - includes our formatting in gutter -super::gutter(format_with_gutter(&error.to_string(), "", None))?; // Adds ❌ emoji - -// βœ… GOOD - command output -print!("{}", format_with_gutter(&command)); +// ❌ BAD - includes our formatting (❌ emoji) +super::gutter(format_with_gutter(&error.to_string(), "", None))?; ``` -**Linebreaks with gutter content:** Gutter content requires a single newline before it, never double newlines. The gutter's visual structure (background color, indentation) provides sufficient separation. - -Output functions (`progress()`, `success()`, etc.) use `println!()` internally, adding a trailing newline. Messages passed to these functions should not include `\n`, as this creates a blank line. +**Linebreaks:** Gutter content requires a single newline before it, never double newlines. Output functions (`progress()`, `success()`, etc.) use `println!()` internally, adding a trailing newline. Messages passed to these functions should not include `\n`: ```rust -// βœ… GOOD - output function adds newline automatically -output::progress(format!("{CYAN}Merging commits...{CYAN:#}"))?; -output::gutter(format_with_gutter(&log_output, "", None))?; - -// ❌ BAD - trailing \n creates double newline (blank line) -output::progress(format!("{CYAN}Merging commits...{CYAN:#}\n"))?; -output::gutter(format_with_gutter(&log_output, "", None))?; - -// βœ… GOOD - single newline in direct format!() -format!("{header}\n{}", format_with_gutter(error, "", None)) +// βœ… GOOD - no trailing \n +output::progress(format!("{CYAN}Merging...{CYAN:#}"))?; +output::gutter(format_with_gutter(&log, "", None))?; -// ❌ BAD - double newline creates blank line -format!("{header}\n\n{}", format_with_gutter(error, "", None)) +// ❌ BAD - trailing \n creates blank line +output::progress(format!("{CYAN}Merging...{CYAN:#}\n"))?; ``` - ### Snapshot Testing Requirement Every command output must have a snapshot test (`tests/integration_tests/`). Use this pattern: @@ -418,12 +284,6 @@ fn test_command_success() { repo.commit("Initial commit"); snapshot_command("command_success", &repo, &[]); } - -#[test] -fn test_command_no_data() { - let repo = TestRepo::new(); - snapshot_command("command_no_data", &repo, &[]); -} ``` Cover success/error states, with/without data, and flag variations. @@ -433,7 +293,6 @@ Cover success/error states, with/without data, and flag variations. ### Two Output Modes Worktrunk supports two output modes, selected once at program startup: - 1. **Interactive Mode** - Human-friendly output with colors, emojis, and hints 2. **Directive Mode** - Machine-readable NUL-terminated directives for shell integration @@ -443,77 +302,45 @@ The mode is determined at initialization in `main()` and never changes during ex Command code must never check which output mode is active. The output system uses enum dispatch - commands call output functions without knowing the mode. -**Bad - mode conditionals scattered through commands:** ```rust // ❌ NEVER DO THIS -use crate::output::OutputMode; - -fn some_command(mode: OutputMode) { - if mode == OutputMode::Interactive { - println!("βœ… Success!"); - } else { - println!("Success!\0"); - } +if mode == OutputMode::Interactive { + println!("βœ… Success!"); } -``` -**Good - use the output system:** -```rust // βœ… ALWAYS DO THIS -use crate::output; - -fn some_command() { - output::success("Success!")?; - // The output system handles formatting for both modes -} +output::success("Success!")?; ``` -### How It Works - -Decide once at the edge (`main()`), initialize globally, trust internally. +Decide once at the edge (`main()`), initialize globally, trust internally: ```rust // In main.rs - the only place that knows about modes -let mode = if internal { - OutputMode::Directive -} else { - OutputMode::Interactive -}; -output::initialize(mode); +output::initialize(if internal { OutputMode::Directive } else { OutputMode::Interactive }); // Everywhere else - just use the output functions output::success("Created worktree")?; output::change_directory(&path)?; -output::execute("git pull")?; ``` ### Available Output Functions -The output module (`src/output/global.rs`) provides these functions: +The output module (`src/output/global.rs`) provides: -- `success(message)` - Emit success messages (βœ…, both modes) -- `progress(message)` - Emit progress updates (πŸ”„, both modes) -- `info(message)` - Emit info messages (βšͺ, both modes) -- `warning(message)` - Emit warning messages (🟑, both modes) -- `hint(message)` - Emit hint messages (πŸ’‘, interactive only, suppressed in directive) +- `success(message)` - Successful completion (βœ…, both modes) +- `progress(message)` - Operations in progress (πŸ”„, both modes) +- `info(message)` - Neutral status/metadata (βšͺ, both modes) +- `warning(message)` - Non-blocking issues (🟑, both modes) +- `hint(message)` - Actionable suggestions (πŸ’‘, interactive only, suppressed in directive) - `change_directory(path)` - Request directory change (directive) or store for execution (interactive) - `execute(command)` - Execute command (interactive) or emit directive (directive mode) - `flush()` - Flush output buffers -Function usage: -- `success()` - Successful completion (e.g., "βœ… Committed changes") -- `progress()` - Operations in progress (e.g., "πŸ”„ Squashing commits...") -- `info()` - Neutral status/metadata (e.g., "βšͺ No changes detected") -- `warning()` - Non-blocking issues (e.g., "🟑 Uncommitted changes detected") -- `hint()` - Actionable suggestions for users (e.g., "πŸ’‘ Run 'wt config --help'") - For the complete API, see `src/output/global.rs`. ### Adding New Output Functions -Add the function to both handlers, add dispatch in `global.rs`, never add mode parameters. - -This maintains one canonical path: commands have ONE code path that works for both modes. Never check the mode in commands. +Add the function to both handlers, add dispatch in `global.rs`, never add mode parameters. This maintains one canonical path: commands have ONE code path that works for both modes. ### Architectural Constraint: --internal Commands Must Use Output System @@ -531,7 +358,6 @@ for line in reader.lines() { println!("{}", line); stdout().flush(); } - // ❌ BAD - buffering let lines: Vec<_> = reader.lines().collect(); ``` @@ -561,9 +387,7 @@ Use `wt list --format=json` for structured data access. The output is an array o ### Common Fields (all objects) - `type`: "worktree" | "branch" -- `head_sha`: commit SHA -- `timestamp`: commit timestamp (Unix epoch) -- `commit_message`: commit message text +- `head_sha`, `timestamp`, `commit_message`: commit info - `ahead`, `behind`: commits ahead/behind main branch - `branch_diff`: `{added, deleted}` - line diff vs main - `has_conflicts`: boolean - merge conflicts with main @@ -578,9 +402,7 @@ Use `wt list --format=json` for structured data access. The output is an array o - `bare`, `detached`: boolean flags - `locked`, `prunable`: reason strings (null if not applicable) - `working_tree_diff`: `{added, deleted}` - uncommitted changes -- `working_tree_diff_with_main`: `{added, deleted}` or null - - `null`: not computed (optimization when trees clearly differ) - - `{added: 0, deleted: 0}`: working tree matches main exactly +- `working_tree_diff_with_main`: `{added, deleted}` or null (null = not computed, `{0,0}` = matches main exactly) - `worktree_state`: "rebase" | "merge" | null - git operation in progress - `is_primary`: boolean - is main/primary worktree - `status_symbols`: structured status object (see below) @@ -593,53 +415,25 @@ Use `wt list --format=json` for structured data access. The output is an array o The `status_symbols` object provides structured access to status indicators: -- `has_conflicts`: boolean - merge conflicts detected -- `branch_state`: "" | "≑" | "βˆ…" - - "≑": working tree matches main - - "βˆ…": no commits and clean -- `git_operation`: "" | "↻" | "β‹ˆ" - - "↻": rebase in progress - - "β‹ˆ": merge in progress -- `worktree_attrs`: string - combination of: - - "β—‡": bare worktree - - "⊠": locked - - "⚠": prunable -- `main_divergence`: "" | "↑" | "↓" | "↕" - - "↑": ahead of main - - "↓": behind main - - "↕": diverged (both ahead and behind) -- `upstream_divergence`: "" | "⇑" | "⇣" | "β‡…" - - "⇑": ahead of remote - - "⇣": behind remote - - "β‡…": diverged from remote -- `working_tree`: string - combination of: - - "?": untracked files - - "!": modified files - - "+": staged changes - - "Β»": renamed files - - "✘": deleted files +- `has_conflicts`: boolean +- `branch_state`: "" | "≑" (matches main) | "βˆ…" (no commits and clean) +- `git_operation`: "" | "↻" (rebase) | "β‹ˆ" (merge) +- `worktree_attrs`: combination of "β—‡" (bare), "⊠" (locked), "⚠" (prunable) +- `main_divergence`: "" | "↑" (ahead) | "↓" (behind) | "↕" (diverged) +- `upstream_divergence`: "" | "⇑" (ahead) | "⇣" (behind) | "β‡…" (diverged) +- `working_tree`: combination of "?" (untracked), "!" (modified), "+" (staged), "Β»" (renamed), "✘" (deleted) ### Display Fields (json-pretty format only) -These fields contain ANSI-formatted strings for human-readable output: - -- `commits_display` (branches only) -- `branch_diff_display` (branches only) -- `upstream_display` (optional) -- `ci_status_display` (optional) -- `status_display`: - - Worktrees: rendered status symbols + user status - - Branches: user status or "Β·" +ANSI-formatted strings for human-readable output: +- `commits_display`, `branch_diff_display` (branches only) +- `upstream_display`, `ci_status_display` (optional) +- `status_display`: rendered status symbols + user status - `working_diff_display` (worktrees only, optional) -Note: Display fields are omitted when empty/null. - ### Query Examples ```bash -# Get main worktree info -jq '.[] | select(.branch == "main") | {path, ahead, behind}' - # Find worktrees with uncommitted changes jq '.[] | select(.type == "worktree" and .working_tree_diff.added > 0)' From 5cdbfeb5e61dcad7f50f97dcf6fb7500825bb5e0 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Mon, 17 Nov 2025 19:41:18 -0800 Subject: [PATCH 4/5] feat: Shorten CLI flag descriptions --- CLAUDE.md | 17 ++ src/cli.rs | 62 +++--- ...n__integration_tests__init__init_fish.snap | 128 ++++++------ ...on__integration_tests__init__init_zsh.snap | 196 +++++++++--------- 4 files changed, 210 insertions(+), 193 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index be41ac517d..f77a7a8e5f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -32,6 +32,23 @@ Example of escalating instead of suppressing: fn parse_config() { ... } ``` +### CLI Flag Descriptions + +Keep flag and argument descriptions briefβ€”aim for 3-5 words maximum. Use parenthetical defaults sparingly, only when the default isn't obvious from context. + +**Good examples:** +- `/// Skip approval prompts` +- `/// Show CI, conflicts, and full diffs` +- `/// Target branch (default: default branch)` +- `/// Branch, path, '@' (HEAD), or '-' (previous)` + +**Bad examples (too verbose):** +- `/// Auto-approve project commands without saving approvals.` +- `/// Run as if worktrunk was started in instead of the current working directory` +- `/// Show CI status, conflict detection, and complete diff statistics` + +The help text should be scannable. Users reading `wt switch --help` need to quickly understand what each flag does without parsing long sentences. + ## CLI Output Formatting Standards ### User Message Principles diff --git a/src/cli.rs b/src/cli.rs index 015d8ced4c..006340c9d7 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -35,11 +35,11 @@ pub enum OutputFormat { #[command(version = version_str())] #[command(disable_help_subcommand = true)] pub struct Cli { - /// Run as if worktrunk was started in `` instead of the current working directory + /// Change working directory #[arg(short = 'C', global = true, value_name = "path")] pub directory: Option, - /// Enable verbose output (show git commands and debug info) + /// Show git commands and debug info #[arg(long, short = 'v', global = true)] pub verbose: bool, @@ -99,7 +99,7 @@ Xonsh (~/.xonshrc): Oil Shell (~/.config/oil/oshrc): eval "$(wt init oil)""#)] Shell { - /// Specific shell to configure (default: all shells with existing config files) + /// Shell to configure #[arg(long, value_enum)] shell: Option, @@ -107,7 +107,7 @@ Oil Shell (~/.config/oil/oshrc): #[arg(short, long)] force: bool, - /// Command name to use (defaults to 'wt') + /// Command name (default: 'wt') #[arg(long, default_value = DEFAULT_COMMAND_NAME)] command_name: String, }, @@ -120,33 +120,33 @@ pub enum StandaloneCommand { /// Hook type to run hook_type: HookType, - /// Auto-approve project commands without saving approvals. + /// Skip approval prompts #[arg(short, long)] force: bool, }, /// Commit changes with LLM-generated message Commit { - /// Auto-approve project commands without saving approvals. + /// Skip approval prompts #[arg(short, long)] force: bool, - /// Skip pre-commit project hooks. + /// Skip pre-commit hooks #[arg(long)] no_verify: bool, }, /// Squash commits with LLM-generated message Squash { - /// Target branch to squash against (defaults to default branch) + /// Target branch (default: default branch) #[arg(add = crate::completion::branch_value_completer())] target: Option, - /// Auto-approve project commands without saving approvals. + /// Skip approval prompts #[arg(short, long)] force: bool, - /// Skip pre-commit project hooks + /// Skip pre-commit hooks #[arg(long)] no_verify: bool, }, @@ -156,36 +156,36 @@ pub enum StandaloneCommand { /// Automatically stashes non-conflicting edits in the target worktree before /// the push and restores them afterward so other agents' changes stay intact. Push { - /// Target branch (defaults to default branch) + /// Target branch (default: default branch) #[arg(add = crate::completion::branch_value_completer())] target: Option, - /// Allow pushing merge commits (non-linear history) + /// Allow merge commits #[arg(long)] allow_merge_commits: bool, }, /// Rebase current branch onto target branch Rebase { - /// Target branch to rebase onto (defaults to default branch) + /// Target branch (default: default branch) #[arg(add = crate::completion::branch_value_completer())] target: Option, }, /// Approve commands in the project config (shows unapproved by default) AskApprovals { - /// Auto-approve project commands without saving approvals. + /// Skip approval prompts #[arg(short, long)] force: bool, - /// Show all commands including already-approved ones + /// Show all commands #[arg(long)] all: bool, }, /// Clear approved commands from config ClearApprovals { - /// Clear approvals from global config (all projects) + /// Clear global approvals #[arg(short, long)] global: bool, }, @@ -209,7 +209,7 @@ pub enum Commands { /// Shell to generate code for shell: Shell, - /// Command name to use (defaults to 'wt') + /// Command name (default: 'wt') #[arg(long, default_value = DEFAULT_COMMAND_NAME)] command_name: String, }, @@ -315,7 +315,7 @@ Rows are dimmed when no unique work (≑ matches main OR βˆ… no commits)."#)] #[arg(long)] branches: bool, - /// Show CI status, conflict detection, and complete diff statistics + /// Show CI, conflicts, and full diffs /// /// Adds columns: CI (pipeline status), main…± (line diffs). /// Enables conflict detection (shows "=" symbol in Status column). @@ -381,7 +381,7 @@ Use '@' to refer to your current HEAD (following git's convention): wt switch --create new-feature --base=@ # Branch from current HEAD wt remove @ # Remove current worktree"#)] Switch { - /// Branch name, worktree path, '@' for current HEAD, or '-' for previous branch + /// Branch, path, '@' (HEAD), or '-' (previous) #[arg(add = crate::completion::worktree_branch_completer())] branch: String, @@ -389,7 +389,7 @@ Use '@' to refer to your current HEAD (following git's convention): #[arg(short = 'c', long)] create: bool, - /// Base branch to create from (only with --create). Use '@' for current HEAD + /// Base branch (with --create) #[arg(short = 'b', long, add = crate::completion::branch_value_completer())] base: Option, @@ -397,11 +397,11 @@ Use '@' to refer to your current HEAD (following git's convention): #[arg(short = 'x', long)] execute: Option, - /// Auto-approve project commands without saving approvals. + /// Skip approval prompts #[arg(short = 'f', long)] force: bool, - /// Skip all project hooks: post-create and post-start. + /// Skip project hooks #[arg(long)] no_verify: bool, }, @@ -454,11 +454,11 @@ Remove multiple worktrees: Switch to default in primary: wt remove # (when already in primary worktree)"#)] Remove { - /// Worktree names or branches to remove (use '@' for current, defaults to current if none specified) + /// Worktree or branch (@ for current) #[arg(add = crate::completion::worktree_branch_completer())] worktrees: Vec, - /// Don't delete the branch after removing the worktree (by default, branches are deleted) + /// Keep branch after removal #[arg(long = "no-delete-branch")] no_delete_branch: bool, }, @@ -515,31 +515,31 @@ Keep worktree after merging: Skip pre-merge commands: wt merge --no-verify"#)] Merge { - /// Target branch to merge into (defaults to default branch) + /// Target branch (default: default branch) #[arg(add = crate::completion::branch_value_completer())] target: Option, - /// Disable squashing commits (by default, commits are squashed into one before merging) + /// Don't squash commits #[arg(long = "no-squash", action = ArgAction::SetFalse, default_value_t = true)] squash_enabled: bool, - /// Push commits as-is without transformations (requires clean tree; implies --no-squash, --no-remove, and skips rebase) + /// Push without transformations #[arg(long)] no_commit: bool, - /// Keep the worktree after merging. + /// Keep worktree after merge #[arg(long = "no-remove")] no_remove: bool, - /// Skip pre-merge project hooks. + /// Skip pre-merge hooks #[arg(long)] no_verify: bool, - /// Auto-approve project commands without saving approvals. + /// Skip approval prompts #[arg(short, long)] force: bool, - /// Only stage tracked files (git add -u) instead of all files (git add -A) + /// Stage tracked files only #[arg(long)] tracked_only: bool, }, diff --git a/tests/snapshots/integration__integration_tests__init__init_fish.snap b/tests/snapshots/integration__integration_tests__init__init_fish.snap index f5605f0638..52f6f56953 100644 --- a/tests/snapshots/integration__integration_tests__init__init_fish.snap +++ b/tests/snapshots/integration__integration_tests__init__init_fish.snap @@ -16,7 +16,7 @@ info: LANG: C LC_ALL: C SOURCE_DATE_EPOCH: "1761609600" - WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp0zq2ID/test-config.toml + WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpjMnKcX/test-config.toml --- success: true exit_code: 0 @@ -183,8 +183,8 @@ function __fish_wt_using_subcommand contains -- $cmd[1] $argv end -complete -c wt -n "__fish_wt_needs_command" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F -complete -c wt -n "__fish_wt_needs_command" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_needs_command" -s C -d 'Change working directory' -r -F +complete -c wt -n "__fish_wt_needs_command" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_needs_command" -s h -l help -d 'Print help' complete -c wt -n "__fish_wt_needs_command" -s V -l version -d 'Print version' complete -c wt -n "__fish_wt_needs_command" -f -a "init" -d 'Generate shell integration code' @@ -194,36 +194,36 @@ complete -c wt -n "__fish_wt_needs_command" -f -a "list" -d 'List worktrees and complete -c wt -n "__fish_wt_needs_command" -f -a "switch" -d 'Switch to a worktree' complete -c wt -n "__fish_wt_needs_command" -f -a "remove" -d 'Finish current worktree, returning to primary if current' complete -c wt -n "__fish_wt_needs_command" -f -a "merge" -d 'Merge worktree into target branch' -complete -c wt -n "__fish_wt_using_subcommand init" -l command-name -d 'Command name to use (defaults to \'wt\')' -r -complete -c wt -n "__fish_wt_using_subcommand init" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F -complete -c wt -n "__fish_wt_using_subcommand init" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_using_subcommand init" -l command-name -d 'Command name (default: \'wt\')' -r +complete -c wt -n "__fish_wt_using_subcommand init" -s C -d 'Change working directory' -r -F +complete -c wt -n "__fish_wt_using_subcommand init" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_using_subcommand init" -s h -l help -d 'Print help' -complete -c wt -n "__fish_wt_using_subcommand config; and not __fish_seen_subcommand_from init list refresh-cache shell" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F -complete -c wt -n "__fish_wt_using_subcommand config; and not __fish_seen_subcommand_from init list refresh-cache shell" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_using_subcommand config; and not __fish_seen_subcommand_from init list refresh-cache shell" -s C -d 'Change working directory' -r -F +complete -c wt -n "__fish_wt_using_subcommand config; and not __fish_seen_subcommand_from init list refresh-cache shell" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_using_subcommand config; and not __fish_seen_subcommand_from init list refresh-cache shell" -s h -l help -d 'Print help (see more with \'--help\')' complete -c wt -n "__fish_wt_using_subcommand config; and not __fish_seen_subcommand_from init list refresh-cache shell" -f -a "init" -d 'Initialize global configuration file with examples' complete -c wt -n "__fish_wt_using_subcommand config; and not __fish_seen_subcommand_from init list refresh-cache shell" -f -a "list" -d 'List all configuration files and their locations' complete -c wt -n "__fish_wt_using_subcommand config; and not __fish_seen_subcommand_from init list refresh-cache shell" -f -a "refresh-cache" -d 'Refresh the cached default branch by querying the remote' complete -c wt -n "__fish_wt_using_subcommand config; and not __fish_seen_subcommand_from init list refresh-cache shell" -f -a "shell" -d 'Configure shell by writing to config files' -complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from init" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F -complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from init" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from init" -s C -d 'Change working directory' -r -F +complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from init" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from init" -s h -l help -d 'Print help' -complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from list" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F -complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from list" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from list" -s C -d 'Change working directory' -r -F +complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from list" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from list" -s h -l help -d 'Print help' -complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from refresh-cache" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F -complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from refresh-cache" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from refresh-cache" -s C -d 'Change working directory' -r -F +complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from refresh-cache" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from refresh-cache" -s h -l help -d 'Print help' -complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from shell" -l shell -d 'Specific shell to configure (default: all shells with existing config files)' -r -f -a "bash\t'' +complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from shell" -l shell -d 'Shell to configure' -r -f -a "bash\t'' fish\t'' zsh\t''" -complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from shell" -l command-name -d 'Command name to use (defaults to \'wt\')' -r -complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from shell" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F +complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from shell" -l command-name -d 'Command name (default: \'wt\')' -r +complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from shell" -s C -d 'Change working directory' -r -F complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from shell" -s f -l force -d 'Skip confirmation prompt' -complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from shell" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from shell" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from shell" -s h -l help -d 'Print help (see more with \'--help\')' -complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F -complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -s C -d 'Change working directory' -r -F +complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -s h -l help -d 'Print help' complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -f -a "run-hook" -d 'Run a project hook for testing' complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -f -a "commit" -d 'Commit changes with LLM-generated message' @@ -233,66 +233,66 @@ complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcomma complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -f -a "ask-approvals" -d 'Approve commands in the project config (shows unapproved by default)' complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -f -a "clear-approvals" -d 'Clear approved commands from config' complete -c wt -n "__fish_wt_using_subcommand beta; and not __fish_seen_subcommand_from run-hook commit squash push rebase ask-approvals clear-approvals select" -f -a "select" -d 'Interactive worktree selector' -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from run-hook" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from run-hook" -s f -l force -d 'Auto-approve project commands without saving approvals' -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from run-hook" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from run-hook" -s C -d 'Change working directory' -r -F +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from run-hook" -s f -l force -d 'Skip approval prompts' +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from run-hook" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from run-hook" -s h -l help -d 'Print help' -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from commit" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from commit" -s f -l force -d 'Auto-approve project commands without saving approvals' -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from commit" -l no-verify -d 'Skip pre-commit project hooks' -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from commit" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from commit" -s C -d 'Change working directory' -r -F +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from commit" -s f -l force -d 'Skip approval prompts' +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from commit" -l no-verify -d 'Skip pre-commit hooks' +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from commit" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from commit" -s h -l help -d 'Print help' -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from squash" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from squash" -s f -l force -d 'Auto-approve project commands without saving approvals' -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from squash" -l no-verify -d 'Skip pre-commit project hooks' -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from squash" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from squash" -s C -d 'Change working directory' -r -F +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from squash" -s f -l force -d 'Skip approval prompts' +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from squash" -l no-verify -d 'Skip pre-commit hooks' +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from squash" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from squash" -s h -l help -d 'Print help' -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from push" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from push" -l allow-merge-commits -d 'Allow pushing merge commits (non-linear history)' -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from push" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from push" -s C -d 'Change working directory' -r -F +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from push" -l allow-merge-commits -d 'Allow merge commits' +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from push" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from push" -s h -l help -d 'Print help (see more with \'--help\')' -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from rebase" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from rebase" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from rebase" -s C -d 'Change working directory' -r -F +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from rebase" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from rebase" -s h -l help -d 'Print help' -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from ask-approvals" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from ask-approvals" -s f -l force -d 'Auto-approve project commands without saving approvals' -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from ask-approvals" -l all -d 'Show all commands including already-approved ones' -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from ask-approvals" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from ask-approvals" -s C -d 'Change working directory' -r -F +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from ask-approvals" -s f -l force -d 'Skip approval prompts' +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from ask-approvals" -l all -d 'Show all commands' +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from ask-approvals" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from ask-approvals" -s h -l help -d 'Print help' -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from clear-approvals" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from clear-approvals" -s g -l global -d 'Clear approvals from global config (all projects)' -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from clear-approvals" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from clear-approvals" -s C -d 'Change working directory' -r -F +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from clear-approvals" -s g -l global -d 'Clear global approvals' +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from clear-approvals" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from clear-approvals" -s h -l help -d 'Print help' -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from select" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F -complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from select" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from select" -s C -d 'Change working directory' -r -F +complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from select" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_using_subcommand beta; and __fish_seen_subcommand_from select" -s h -l help -d 'Print help (see more with \'--help\')' complete -c wt -n "__fish_wt_using_subcommand list" -l format -d 'Output format' -r -f -a "table\t'Human-readable table format' json\t'Machine-readable JSON with display fields (includes styled unicode for rendering)'" -complete -c wt -n "__fish_wt_using_subcommand list" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F +complete -c wt -n "__fish_wt_using_subcommand list" -s C -d 'Change working directory' -r -F complete -c wt -n "__fish_wt_using_subcommand list" -l branches -d 'Include branches without worktrees' -complete -c wt -n "__fish_wt_using_subcommand list" -l full -d 'Show CI status, conflict detection, and complete diff statistics' -complete -c wt -n "__fish_wt_using_subcommand list" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_using_subcommand list" -l full -d 'Show CI, conflicts, and full diffs' +complete -c wt -n "__fish_wt_using_subcommand list" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_using_subcommand list" -s h -l help -d 'Print help (see more with \'--help\')' -complete -c wt -n "__fish_wt_using_subcommand switch" -s b -l base -f -d 'Base branch to create from (only with --create). Use \'@\' for current HEAD' -r +complete -c wt -n "__fish_wt_using_subcommand switch" -s b -l base -f -d 'Base branch (with --create)' -r complete -c wt -n "__fish_wt_using_subcommand switch" -s x -l execute -d 'Execute command after switching' -r -complete -c wt -n "__fish_wt_using_subcommand switch" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F +complete -c wt -n "__fish_wt_using_subcommand switch" -s C -d 'Change working directory' -r -F complete -c wt -n "__fish_wt_using_subcommand switch" -s c -l create -d 'Create a new branch' -complete -c wt -n "__fish_wt_using_subcommand switch" -s f -l force -d 'Auto-approve project commands without saving approvals' -complete -c wt -n "__fish_wt_using_subcommand switch" -l no-verify -d 'Skip all project hooks: post-create and post-start' -complete -c wt -n "__fish_wt_using_subcommand switch" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_using_subcommand switch" -s f -l force -d 'Skip approval prompts' +complete -c wt -n "__fish_wt_using_subcommand switch" -l no-verify -d 'Skip project hooks' +complete -c wt -n "__fish_wt_using_subcommand switch" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_using_subcommand switch" -s h -l help -d 'Print help' -complete -c wt -n "__fish_wt_using_subcommand remove" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F -complete -c wt -n "__fish_wt_using_subcommand remove" -l no-delete-branch -d 'Don\'t delete the branch after removing the worktree (by default, branches are deleted)' -complete -c wt -n "__fish_wt_using_subcommand remove" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_using_subcommand remove" -s C -d 'Change working directory' -r -F +complete -c wt -n "__fish_wt_using_subcommand remove" -l no-delete-branch -d 'Keep branch after removal' +complete -c wt -n "__fish_wt_using_subcommand remove" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_using_subcommand remove" -s h -l help -d 'Print help' -complete -c wt -n "__fish_wt_using_subcommand merge" -s C -d 'Run as if worktrunk was started in instead of the current working directory' -r -F -complete -c wt -n "__fish_wt_using_subcommand merge" -l no-squash -d 'Disable squashing commits (by default, commits are squashed into one before merging)' -complete -c wt -n "__fish_wt_using_subcommand merge" -l no-commit -d 'Push commits as-is without transformations (requires clean tree; implies --no-squash, --no-remove, and skips rebase)' -complete -c wt -n "__fish_wt_using_subcommand merge" -l no-remove -d 'Keep the worktree after merging' -complete -c wt -n "__fish_wt_using_subcommand merge" -l no-verify -d 'Skip pre-merge project hooks' -complete -c wt -n "__fish_wt_using_subcommand merge" -s f -l force -d 'Auto-approve project commands without saving approvals' -complete -c wt -n "__fish_wt_using_subcommand merge" -l tracked-only -d 'Only stage tracked files (git add -u) instead of all files (git add -A)' -complete -c wt -n "__fish_wt_using_subcommand merge" -s v -l verbose -d 'Enable verbose output (show git commands and debug info)' +complete -c wt -n "__fish_wt_using_subcommand merge" -s C -d 'Change working directory' -r -F +complete -c wt -n "__fish_wt_using_subcommand merge" -l no-squash -d 'Don\'t squash commits' +complete -c wt -n "__fish_wt_using_subcommand merge" -l no-commit -d 'Push without transformations' +complete -c wt -n "__fish_wt_using_subcommand merge" -l no-remove -d 'Keep worktree after merge' +complete -c wt -n "__fish_wt_using_subcommand merge" -l no-verify -d 'Skip pre-merge hooks' +complete -c wt -n "__fish_wt_using_subcommand merge" -s f -l force -d 'Skip approval prompts' +complete -c wt -n "__fish_wt_using_subcommand merge" -l tracked-only -d 'Stage tracked files only' +complete -c wt -n "__fish_wt_using_subcommand merge" -s v -l verbose -d 'Show git commands and debug info' complete -c wt -n "__fish_wt_using_subcommand merge" -s h -l help -d 'Print help (see more with \'--help\')' ----- stderr ----- diff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snap index ab47bb6bcd..9ae7a67fa5 100644 --- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap +++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap @@ -16,7 +16,7 @@ info: LANG: C LC_ALL: C SOURCE_DATE_EPOCH: "1761609600" - WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp5Os0LO/test-config.toml + WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpeaTQjA/test-config.toml --- success: true exit_code: 0 @@ -158,9 +158,9 @@ _wt() { local context curcontext="$curcontext" state line _arguments "${_arguments_options[@]}" : \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'-C+[Change working directory]:path:_files' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help]' \ '--help[Print help]' \ '-V[Print version]' \ @@ -176,10 +176,10 @@ _wt() { case $line[1] in (init) _arguments "${_arguments_options[@]}" : \ -'--command-name=[Command name to use (defaults to '\''wt'\'')]:COMMAND_NAME:_default' \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'--command-name=[Command name (default\: '\''wt'\'')]:COMMAND_NAME:_default' \ +'-C+[Change working directory]:path:_files' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help]' \ '--help[Print help]' \ ':shell -- Shell to generate code for:(bash fish zsh)' \ @@ -187,9 +187,9 @@ _arguments "${_arguments_options[@]}" : \ ;; (config) _arguments "${_arguments_options[@]}" : \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'-C+[Change working directory]:path:_files' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help (see more with '\''--help'\'')]' \ '--help[Print help (see more with '\''--help'\'')]' \ ":: :_wt__config_commands" \ @@ -204,40 +204,40 @@ _arguments "${_arguments_options[@]}" : \ case $line[1] in (init) _arguments "${_arguments_options[@]}" : \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'-C+[Change working directory]:path:_files' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help]' \ '--help[Print help]' \ && ret=0 ;; (list) _arguments "${_arguments_options[@]}" : \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'-C+[Change working directory]:path:_files' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help]' \ '--help[Print help]' \ && ret=0 ;; (refresh-cache) _arguments "${_arguments_options[@]}" : \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'-C+[Change working directory]:path:_files' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help]' \ '--help[Print help]' \ && ret=0 ;; (shell) _arguments "${_arguments_options[@]}" : \ -'--shell=[Specific shell to configure (default\: all shells with existing config files)]:SHELL:(bash fish zsh)' \ -'--command-name=[Command name to use (defaults to '\''wt'\'')]:COMMAND_NAME:_default' \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ +'--shell=[Shell to configure]:SHELL:(bash fish zsh)' \ +'--command-name=[Command name (default\: '\''wt'\'')]:COMMAND_NAME:_default' \ +'-C+[Change working directory]:path:_files' \ '-f[Skip confirmation prompt]' \ '--force[Skip confirmation prompt]' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help (see more with '\''--help'\'')]' \ '--help[Print help (see more with '\''--help'\'')]' \ && ret=0 @@ -248,9 +248,9 @@ esac ;; (beta) _arguments "${_arguments_options[@]}" : \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'-C+[Change working directory]:path:_files' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help]' \ '--help[Print help]' \ ":: :_wt__beta_commands" \ @@ -265,11 +265,11 @@ _arguments "${_arguments_options[@]}" : \ case $line[1] in (run-hook) _arguments "${_arguments_options[@]}" : \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ -'-f[Auto-approve project commands without saving approvals]' \ -'--force[Auto-approve project commands without saving approvals]' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'-C+[Change working directory]:path:_files' \ +'-f[Skip approval prompts]' \ +'--force[Skip approval prompts]' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help]' \ '--help[Print help]' \ ':hook_type -- Hook type to run:(post-create post-start pre-commit pre-merge post-merge)' \ @@ -277,78 +277,78 @@ _arguments "${_arguments_options[@]}" : \ ;; (commit) _arguments "${_arguments_options[@]}" : \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ -'-f[Auto-approve project commands without saving approvals]' \ -'--force[Auto-approve project commands without saving approvals]' \ -'--no-verify[Skip pre-commit project hooks]' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'-C+[Change working directory]:path:_files' \ +'-f[Skip approval prompts]' \ +'--force[Skip approval prompts]' \ +'--no-verify[Skip pre-commit hooks]' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help]' \ '--help[Print help]' \ && ret=0 ;; (squash) _arguments "${_arguments_options[@]}" : \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ -'-f[Auto-approve project commands without saving approvals]' \ -'--force[Auto-approve project commands without saving approvals]' \ -'--no-verify[Skip pre-commit project hooks]' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'-C+[Change working directory]:path:_files' \ +'-f[Skip approval prompts]' \ +'--force[Skip approval prompts]' \ +'--no-verify[Skip pre-commit hooks]' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help]' \ '--help[Print help]' \ -'::target -- Target branch to squash against (defaults to default branch):_default' \ +'::target -- Target branch (default\: default branch):_default' \ && ret=0 ;; (push) _arguments "${_arguments_options[@]}" : \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ -'--allow-merge-commits[Allow pushing merge commits (non-linear history)]' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'-C+[Change working directory]:path:_files' \ +'--allow-merge-commits[Allow merge commits]' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help (see more with '\''--help'\'')]' \ '--help[Print help (see more with '\''--help'\'')]' \ -'::target -- Target branch (defaults to default branch):_default' \ +'::target -- Target branch (default\: default branch):_default' \ && ret=0 ;; (rebase) _arguments "${_arguments_options[@]}" : \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'-C+[Change working directory]:path:_files' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help]' \ '--help[Print help]' \ -'::target -- Target branch to rebase onto (defaults to default branch):_default' \ +'::target -- Target branch (default\: default branch):_default' \ && ret=0 ;; (ask-approvals) _arguments "${_arguments_options[@]}" : \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ -'-f[Auto-approve project commands without saving approvals]' \ -'--force[Auto-approve project commands without saving approvals]' \ -'--all[Show all commands including already-approved ones]' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'-C+[Change working directory]:path:_files' \ +'-f[Skip approval prompts]' \ +'--force[Skip approval prompts]' \ +'--all[Show all commands]' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help]' \ '--help[Print help]' \ && ret=0 ;; (clear-approvals) _arguments "${_arguments_options[@]}" : \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ -'-g[Clear approvals from global config (all projects)]' \ -'--global[Clear approvals from global config (all projects)]' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'-C+[Change working directory]:path:_files' \ +'-g[Clear global approvals]' \ +'--global[Clear global approvals]' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help]' \ '--help[Print help]' \ && ret=0 ;; (select) _arguments "${_arguments_options[@]}" : \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'-C+[Change working directory]:path:_files' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help (see more with '\''--help'\'')]' \ '--help[Print help (see more with '\''--help'\'')]' \ && ret=0 @@ -361,60 +361,60 @@ esac _arguments "${_arguments_options[@]}" : \ '--format=[Output format]:FORMAT:((table\:"Human-readable table format" json\:"Machine-readable JSON with display fields (includes styled unicode for rendering)"))' \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ +'-C+[Change working directory]:path:_files' \ '--branches[Include branches without worktrees]' \ -'--full[Show CI status, conflict detection, and complete diff statistics]' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'--full[Show CI, conflicts, and full diffs]' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help (see more with '\''--help'\'')]' \ '--help[Print help (see more with '\''--help'\'')]' \ && ret=0 ;; (switch) _arguments "${_arguments_options[@]}" : \ -'-b+[Base branch to create from (only with --create). Use '\''@'\'' for current HEAD]:BASE:_default' \ -'--base=[Base branch to create from (only with --create). Use '\''@'\'' for current HEAD]:BASE:_default' \ +'-b+[Base branch (with --create)]:BASE:_default' \ +'--base=[Base branch (with --create)]:BASE:_default' \ '-x+[Execute command after switching]:EXECUTE:_default' \ '--execute=[Execute command after switching]:EXECUTE:_default' \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ +'-C+[Change working directory]:path:_files' \ '-c[Create a new branch]' \ '--create[Create a new branch]' \ -'-f[Auto-approve project commands without saving approvals]' \ -'--force[Auto-approve project commands without saving approvals]' \ -'--no-verify[Skip all project hooks\: post-create and post-start]' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'-f[Skip approval prompts]' \ +'--force[Skip approval prompts]' \ +'--no-verify[Skip project hooks]' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help]' \ '--help[Print help]' \ -':branch -- Branch name, worktree path, '\''@'\'' for current HEAD, or '\''-'\'' for previous branch:_default' \ +':branch -- Branch, path, '\''@'\'' (HEAD), or '\''-'\'' (previous):_default' \ && ret=0 ;; (remove) _arguments "${_arguments_options[@]}" : \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ -'--no-delete-branch[Don'\''t delete the branch after removing the worktree (by default, branches are deleted)]' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'-C+[Change working directory]:path:_files' \ +'--no-delete-branch[Keep branch after removal]' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help]' \ '--help[Print help]' \ -'*::worktrees -- Worktree names or branches to remove (use '\''@'\'' for current, defaults to current if none specified):_default' \ +'*::worktrees -- Worktree or branch (@ for current):_default' \ && ret=0 ;; (merge) _arguments "${_arguments_options[@]}" : \ -'-C+[Run as if worktrunk was started in instead of the current working directory]:path:_files' \ -'--no-squash[Disable squashing commits (by default, commits are squashed into one before merging)]' \ -'--no-commit[Push commits as-is without transformations (requires clean tree; implies --no-squash, --no-remove, and skips rebase)]' \ -'--no-remove[Keep the worktree after merging]' \ -'--no-verify[Skip pre-merge project hooks]' \ -'-f[Auto-approve project commands without saving approvals]' \ -'--force[Auto-approve project commands without saving approvals]' \ -'--tracked-only[Only stage tracked files (git add -u) instead of all files (git add -A)]' \ -'-v[Enable verbose output (show git commands and debug info)]' \ -'--verbose[Enable verbose output (show git commands and debug info)]' \ +'-C+[Change working directory]:path:_files' \ +'--no-squash[Don'\''t squash commits]' \ +'--no-commit[Push without transformations]' \ +'--no-remove[Keep worktree after merge]' \ +'--no-verify[Skip pre-merge hooks]' \ +'-f[Skip approval prompts]' \ +'--force[Skip approval prompts]' \ +'--tracked-only[Stage tracked files only]' \ +'-v[Show git commands and debug info]' \ +'--verbose[Show git commands and debug info]' \ '-h[Print help (see more with '\''--help'\'')]' \ '--help[Print help (see more with '\''--help'\'')]' \ -'::target -- Target branch to merge into (defaults to default branch):_default' \ +'::target -- Target branch (default\: default branch):_default' \ && ret=0 ;; esac From 98e5b6f40302ad4422422ff68ae4fda3d2799b4a Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Mon, 17 Nov 2025 20:24:42 -0800 Subject: [PATCH 5/5] feat: Migrate from markdown-link-check to lychee MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace markdown-link-check with lychee for link checking, following PRQL's proven patterns for better retry handling and performance. Changes: - Add .config/lychee.toml with retry logic and site exclusions - Replace markdown-link-check with dual-mode lychee pre-commit hooks - Fast PR mode: whitelist worktrunk domains + local files - Comprehensive mode: full checking (manual stage) - Add CI job for link checking (PRs: modified files, main: all files) - Add .lycheecache to .gitignore - Remove .markdown-link-check.json Benefits over markdown-link-check: - Better retry support for transient network errors - 1-day caching to reduce rate limiting - Faster execution with async checking - Proven in production by PRQL project πŸ€– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .config/lychee.toml | 34 +++++++++++++++++++++++++++++ .github/workflows/ci.yml | 45 +++++++++++++++++++++++++++++++++++++++ .gitignore | 3 +++ .markdown-link-check.json | 22 ------------------- .pre-commit-config.yaml | 24 +++++++++++++++------ 5 files changed, 100 insertions(+), 28 deletions(-) create mode 100644 .config/lychee.toml delete mode 100644 .markdown-link-check.json diff --git a/.config/lychee.toml b/.config/lychee.toml new file mode 100644 index 0000000000..41e4b5db6a --- /dev/null +++ b/.config/lychee.toml @@ -0,0 +1,34 @@ +# Lychee link checker configuration +# Based on PRQL's proven patterns: https://github.com/PRQL/prql + +# Network resilience - handles transient failures +max_retries = 5 +timeout = 20 +max_redirects = 5 + +# Accepted HTTP status codes +accept = [200, 206, 429] + +# Caching to reduce rate limiting and improve performance +cache = true +max_cache_age = "1d" + +# Exclude sites that block GitHub Actions or have reliability issues +exclude = [ + # Social media (blocks GitHub Actions) + "~twitter\\.com", + "~x\\.com", + + # Sites with reliability issues in CI + "~stackoverflow\\.com", + "~npmjs\\.com", + + # Package registries (frequently return 429 or block CI) + "~crates\\.io", + "~docs\\.rs", + "~img\\.shields\\.io", + + # Sites already excluded in markdown-link-check + "~opensource\\.org", + "~llm\\.datasette\\.io", +] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 54874070e7..13bda3ea55 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -102,3 +102,48 @@ jobs: with: command: doc args: --no-deps + + check-links: + name: Check links + runs-on: ubuntu-latest + steps: + - name: πŸ“‚ Checkout code + uses: actions/checkout@v5 + + - name: Install lychee + uses: baptiste0928/cargo-install@v3 + with: + crate: lychee + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install pre-commit + run: pip install pre-commit + + - name: Cache lychee results + uses: actions/cache@v4 + with: + path: .lycheecache + key: lychee-${{ github.sha }} + restore-keys: lychee- + + - name: Get modified markdown files + if: github.event_name == 'pull_request' + id: changed-files + uses: tj-actions/changed-files@v47 + with: + files: | + **/*.md + + - name: Link checker (modified files - PRs) + if: github.event_name == 'pull_request' && steps.changed-files.outputs.any_modified == 'true' + run: pre-commit run lychee --files ${{ steps.changed-files.outputs.all_changed_files }} + continue-on-error: true + + - name: Link checker (all files - main branch) + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + run: pre-commit run lychee --all-files + continue-on-error: true diff --git a/.gitignore b/.gitignore index ea8c4bf7f3..dab7be2844 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ /target + +# Lychee link checker cache +.lycheecache diff --git a/.markdown-link-check.json b/.markdown-link-check.json deleted file mode 100644 index 4fe59384fd..0000000000 --- a/.markdown-link-check.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "ignorePatterns": [ - { - "pattern": "^https://crates\\.io/crates/worktrunk$" - }, - { - "pattern": "^https://github\\.com/crate-ci/cargo-release$" - }, - { - "pattern": "^https://opensource\\.org/" - }, - { - "pattern": "^https://llm\\.datasette\\.io/" - }, - { - "pattern": "^https://docs\\.rs/" - }, - { - "pattern": "^https://img\\.shields\\.io/" - } - ] -} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8ea6cacb0b..3b5dd44a9c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,13 +24,25 @@ repos: hooks: - id: clippy args: ["--all-targets", "--", "-D", "warnings"] - - repo: https://github.com/tcort/markdown-link-check - rev: v3.14.1 + - repo: https://github.com/lycheeverse/lychee + rev: lychee-v0.21.0 hooks: - - id: markdown-link-check - name: markdown-link-check + # Fast PR mode - only check worktrunk domains and local files + - id: lychee + name: lychee (PR mode) types: [markdown] - args: ["--config", ".markdown-link-check.json"] + args: + - --include=^(https://(github\.com/worktrunk|worktrunk\.dev)|file://) + - --no-progress + # Comprehensive mode - check all links with full config + # Run manually: pre-commit run --hook-stage manual lychee-all --all-files + - id: lychee + name: lychee-all (comprehensive) + types: [markdown] + stages: [manual] + args: + - --config=.config/lychee.toml + - --no-progress - repo: local hooks: - id: no-dbg @@ -49,5 +61,5 @@ repos: ci: # Currently network access isn't supported in the CI product. - skip: [fmt, markdown-link-check] + skip: [fmt, lychee (PR mode)] autoupdate_commit_msg: "chore: pre-commit autoupdate"