Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Refactor: Introduce emoji constants for message types
Maximilian Roosed698d5d336a
diff --git a/CLAUDE.md b/CLAUDE.mdindex 922905f08..2ee7f40cc 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -22,31 +22,36 @@ Three canonical message patterns with their emojis:### Semantic Style Constants-**Constants defined in `src/styling.rs`:**+**Style constants defined in `src/styling.rs`:**- **`ERROR`**: Red (errors, conflicts)- **`WARNING`**: Yellow (warnings)-- **`SUCCESS`**: Green (success)- **`HINT`**: Dimmed (hints, secondary information)- **`CURRENT`**: Magenta + bold (current worktree)- **`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)+### Inline Formatting PatternUse anstyle's inline pattern `{style}text{style:#}` where `#` means reset:```rust-use worktrunk::styling::{eprintln, ERROR, WARNING, HINT};+use worktrunk::styling::{eprintln, println, ERROR, ERROR_EMOJI, WARNING, WARNING_EMOJI, HINT, HINT_EMOJI};// Simple error-eprintln!("β {ERROR}Working tree has uncommitted changes{ERROR:#}");+eprintln!("{ERROR_EMOJI} {ERROR}Working tree has uncommitted changes{ERROR:#}");// Warning-eprintln!("π‘ {WARNING}Uncommitted changes detected{WARNING:#}");+eprintln!("{WARNING_EMOJI} {WARNING}Uncommitted changes detected{WARNING:#}");// Hint-println!("π‘ {HINT}Use 'wt list' to see all worktrees{HINT:#}");+println!("{HINT_EMOJI} {HINT}Use 'wt list' to see all worktrees{HINT:#}");```### Composing Styles@@ -110,25 +115,25 @@ All handled automatically by `anstream` macros.### Complete Examples```rust-use worktrunk::styling::{println, eprintln, AnstyleStyle, ERROR, WARNING, HINT, SUCCESS};+use worktrunk::styling::{+ eprintln, println, AnstyleStyle,+ ERROR, ERROR_EMOJI, WARNING, WARNING_EMOJI, HINT, HINT_EMOJI+};use anstyle::Style;// Simple error-eprintln!("β {ERROR}Working tree has uncommitted changes{ERROR:#}");+eprintln!("{ERROR_EMOJI} {ERROR}Working tree has uncommitted changes{ERROR:#}");// Error with bold branch namelet error_bold = ERROR.bold();-eprintln!("β Branch '{error_bold}{branch}{error_bold:#}' already exists");+eprintln!("{ERROR_EMOJI} Branch '{error_bold}{branch}{error_bold:#}' already exists");// Warning with boldlet warning_bold = WARNING.bold();-eprintln!("π‘ {warning_bold}Uncommitted changes detected{warning_bold:#}");+eprintln!("{WARNING_EMOJI} {warning_bold}Uncommitted changes detected{warning_bold:#}");// Hint-println!("π‘ {HINT}Use 'wt list' to see all worktrees{HINT:#}");--// Success message-println!("β {SUCCESS}Worktree created successfully{SUCCESS:#}");+println!("{HINT_EMOJI} {HINT}Use 'wt list' to see all worktrees{HINT:#}");// Bold branch name in regular messagelet bold = Style::new().bold();@@ -136,7 +141,7 @@ println!("Switched to worktree: {bold}{branch}{bold:#}");// Complex multi-part errorlet error_bold = ERROR.bold();-eprintln!("β Not a fast-forward from '{error_bold}{target_branch}{error_bold:#}' to HEAD");+eprintln!("{ERROR_EMOJI} Not a fast-forward from '{error_bold}{target_branch}{error_bold:#}' to HEAD");// Dimmed secondary infolet dim = Style::new().dimmed();diff --git a/src/commands/list/mod.rs b/src/commands/list/mod.rsindex d0f42548f..6088567cb 100644--- a/src/commands/list/mod.rs+++ b/src/commands/list/mod.rs@@ -6,7 +6,7 @@ mod spacing_test;use rayon::prelude::*;use worktrunk::git::{GitError, Repository};-use worktrunk::styling::{WARNING, eprintln};+use worktrunk::styling::{WARNING, WARNING_EMOJI, eprintln};use layout::calculate_responsive_layout;use render::{format_header_line, format_list_item_line};@@ -325,7 +325,7 @@ pub fn handle_list(format: crate::OutputFormat, show_branches: bool) -> Result<(Err(e) => {let warning_bold = WARNING.bold();eprintln!(- "π‘ Failed to enrich branch {warning_bold}{branch}{warning_bold:#}: {e}"+ "{WARNING_EMOJI} Failed to enrich branch {warning_bold}{branch}{warning_bold:#}: {e}");}}diff --git a/src/commands/merge.rs b/src/commands/merge.rsindex 538140ab9..a84078090 100644--- a/src/commands/merge.rs+++ b/src/commands/merge.rs@@ -1,6 +1,6 @@use worktrunk::config::WorktrunkConfig;use worktrunk::git::{GitError, Repository};-use worktrunk::styling::{AnstyleStyle, ERROR, println};+use worktrunk::styling::{AnstyleStyle, ERROR, ERROR_EMOJI, println};use super::worktree::handle_push;use super::worktree::handle_remove;@@ -16,7 +16,7 @@ pub fn handle_merge(// Get current branchlet current_branch = repo.current_branch()?.ok_or_else(|| {GitError::CommandFailed(format!(- "β {ERROR}Not on a branch (detached HEAD){ERROR:#}"+ "{ERROR_EMOJI} {ERROR}Not on a branch (detached HEAD){ERROR:#}"))})?;@@ -113,7 +113,7 @@ fn handle_squash(target_branch: &str) -> Result<(), GitError> {if commit_count == 0 && has_staged {// Just staged changes, no commits - would need to commit but this shouldn't happen in merge flowreturn Err(GitError::CommandFailed(format!(- "β {ERROR}Staged changes without commits - please commit them first{ERROR:#}"+ "{ERROR_EMOJI} {ERROR}Staged changes without commits - please commit them first{ERROR:#}")));}diff --git a/src/commands/worktree.rs b/src/commands/worktree.rsindex a11f7d8d1..ad29b8145 100644--- a/src/commands/worktree.rs+++ b/src/commands/worktree.rs@@ -72,7 +72,9 @@ use std::path::PathBuf;use worktrunk::config::{ProjectConfig, WorktrunkConfig, expand_template};use worktrunk::git::{GitError, Repository};use worktrunk::shell::Shell;-use worktrunk::styling::{AnstyleStyle, ERROR, HINT, WARNING, eprintln, println};+use worktrunk::styling::{+ AnstyleStyle, ERROR, ERROR_EMOJI, HINT, HINT_EMOJI, WARNING, WARNING_EMOJI, eprintln, println,+};/// Generate hint message for shell integration setup///@@ -206,13 +208,15 @@ pub fn handle_switch(if create && repo.branch_exists(branch)? {let error_bold = ERROR.bold();return Err(GitError::CommandFailed(format!(- "β Branch '{error_bold}{branch}{error_bold:#}' already exists. Remove --create flag to switch to it."+ "{ERROR_EMOJI} Branch '{error_bold}{branch}{error_bold:#}' already exists. Remove --create flag to switch to it.")));}// Check if base flag was provided without create flagif base.is_some() && !create {- eprintln!("π‘ {WARNING}--base flag is only used with --create, ignoring{WARNING:#}");+ eprintln!(+ "{WARNING_EMOJI} {WARNING}--base flag is only used with --create, ignoring{WARNING:#}"+ );}// Check if worktree already exists for this branch@@ -228,7 +232,7 @@ pub fn handle_switch(Some(_) => {let error_bold = ERROR.bold();return Err(GitError::CommandFailed(format!(- "β Worktree directory missing for '{error_bold}{branch}{error_bold:#}'. Run 'git worktree prune' to clean up."+ "{ERROR_EMOJI} Worktree directory missing for '{error_bold}{branch}{error_bold:#}'. Run 'git worktree prune' to clean up.")));}None => {}@@ -330,7 +334,7 @@ pub fn handle_remove() -> Result<RemoveResult, GitError> {// Remove the worktreeif let Err(e) = repo.remove_worktree(&worktree_root) {- eprintln!("π‘ {WARNING}Failed to remove worktree: {e}{WARNING:#}");+ eprintln!("{WARNING_EMOJI} {WARNING}Failed to remove worktree: {e}{WARNING:#}");eprintln!("You may need to run 'git worktree remove {}' manually",worktree_root.display()@@ -394,7 +398,7 @@ fn check_worktree_conflicts(.collect();if !overlapping.is_empty() {- eprintln!("β {ERROR}Cannot push: conflicting uncommitted changes in:{ERROR:#}");+ eprintln!("{ERROR_EMOJI} {ERROR}Cannot push: conflicting uncommitted changes in:{ERROR:#}");for file in &overlapping {eprintln!(" - {}", file);}@@ -431,11 +435,13 @@ fn expand_command_template(/// Prompt the user to approve a command for executionfn prompt_for_approval(command: &str, project_id: &str) -> io::Result<bool> {eprintln!();- eprintln!("β οΈ Project '{}' wants to run a command:", project_id);+ eprintln!("{WARNING_EMOJI} {WARNING}Project '{project_id}' wants to run a command:{WARNING:#}");eprintln!();eprintln!(" {}", command);eprintln!();- eprintln!("β οΈ WARNING: This will execute with FULL SHELL ACCESS in the new worktree.");+ eprintln!(+ "{WARNING_EMOJI} {WARNING}WARNING: This will execute with FULL SHELL ACCESS in the new worktree.{WARNING:#}"+ );eprintln!(" The command can read/write files, access network, run arbitrary code.");eprintln!();eprint!("Approve and remember for this project? [y/N] ");@@ -464,7 +470,7 @@ fn execute_post_start_commands(Ok(None) => return Ok(()), // No project configErr(e) => {eprintln!(- "Warning: Failed to load project config from {}",+ "{WARNING_EMOJI} {WARNING}Failed to load project config from {}{WARNING:#}",config_path.display());eprintln!("Error: {}", e);@@ -495,14 +501,15 @@ fn execute_post_start_commands(if let Err(e) =fresh_config.approve_command(project_id.clone(), command.clone()){- eprintln!("Warning: Failed to save command approval: {}", e);+ eprintln!(+ "{WARNING_EMOJI} {WARNING}Failed to save command approval: {e}{WARNING:#}"+ );eprintln!("You will be prompted again next time.");}}Err(e) => {eprintln!(- "Warning: Failed to reload config for saving approval: {}",- e+ "{WARNING_EMOJI} {WARNING}Failed to reload config for saving approval: {e}{WARNING:#}");eprintln!("You will be prompted again next time.");}@@ -514,7 +521,7 @@ fn execute_post_start_commands(false}Err(e) => {- eprintln!("Warning: Failed to read user input: {}", e);+ eprintln!("{WARNING_EMOJI} {WARNING}Failed to read user input: {e}{WARNING:#}");false}}@@ -527,7 +534,7 @@ fn execute_post_start_commands(eprintln!("Executing: {}", expanded_command);if let Err(e) = execute_command_in_worktree(worktree_path, &expanded_command) {- eprintln!("Warning: Command failed: {}", e);+ eprintln!("{WARNING_EMOJI} {WARNING}Command failed: {e}{WARNING:#}");// Continue with other commands even if one fails}}@@ -546,10 +553,10 @@ pub fn handle_push(target: Option<&str>, allow_merge_commits: bool) -> Result<()if !repo.is_ancestor(&target_branch, "HEAD")? {let error_bold = ERROR.bold();let error_msg = format!(- "β Not a fast-forward from '{error_bold}{target_branch}{error_bold:#}' to HEAD"+ "{ERROR_EMOJI} Not a fast-forward from '{error_bold}{target_branch}{error_bold:#}' to HEAD");let hint_msg = format!(- "π‘ {HINT}The target branch has commits not in your current branch. Consider 'git pull' or 'git rebase'{HINT:#}"+ "{HINT_EMOJI} {HINT}The target branch has commits not in your current branch. Consider 'git pull' or 'git rebase'{HINT:#}");return Err(GitError::CommandFailed(format!("{}\n{}",@@ -560,7 +567,7 @@ pub fn handle_push(target: Option<&str>, allow_merge_commits: bool) -> Result<()// Check for merge commits unless allowedif !allow_merge_commits && repo.has_merge_commits(&target_branch, "HEAD")? {return Err(GitError::CommandFailed(format!(- "β {ERROR}Found merge commits in push range. Use --allow-merge-commits to push non-linear history.{ERROR:#}"+ "{ERROR_EMOJI} {ERROR}Found merge commits in push range. Use --allow-merge-commits to push non-linear history.{ERROR:#}")));}diff --git a/src/git.rs b/src/git.rsindex f6aa3e81a..ee704faf8 100644--- a/src/git.rs+++ b/src/git.rs@@ -25,8 +25,8 @@ impl std::fmt::Display for GitError {GitError::CommandFailed(msg) => write!(f, "{}", msg),// ParseError messages need formattingGitError::ParseError(msg) => {- use crate::styling::ERROR;- write!(f, "β {ERROR}{msg}{ERROR:#}")+ use crate::styling::{ERROR, ERROR_EMOJI};+ write!(f, "{ERROR_EMOJI} {ERROR}{msg}{ERROR:#}")}}}@@ -183,9 +183,9 @@ impl Repository {/// Returns an error if there are uncommitted changes.pub fn ensure_clean_working_tree(&self) -> Result<(), GitError> {if self.is_dirty()? {- use crate::styling::ERROR;+ use crate::styling::{ERROR, ERROR_EMOJI};return Err(GitError::CommandFailed(format!(- "β {ERROR}Working tree has uncommitted changes. Commit or stash them first.{ERROR:#}"+ "{ERROR_EMOJI} {ERROR}Working tree has uncommitted changes. Commit or stash them first.{ERROR:#}")));}Ok(())diff --git a/src/llm.rs b/src/llm.rsindex 734164e6d..33afa60d6 100644--- a/src/llm.rs+++ b/src/llm.rs@@ -1,5 +1,6 @@use std::process;use worktrunk::config::LlmConfig;+use worktrunk::styling::{WARNING, WARNING_EMOJI, eprintln};pub fn generate_squash_message(target_branch: &str,@@ -14,7 +15,9 @@ pub fn generate_squash_message(return llm_message;}// If LLM fails, fall through to deterministic approach- eprintln!("Warning: LLM generation failed, using deterministic message");+ eprintln!(+ "{WARNING_EMOJI} {WARNING}LLM generation failed, using deterministic message{WARNING:#}"+ );}// Fallback: deterministic commit messagediff --git a/src/styling.rs b/src/styling.rsindex 28daf0c92..852e130cd 100644--- a/src/styling.rs+++ b/src/styling.rs@@ -38,15 +38,25 @@ pub use anstyle::Style as AnstyleStyle;/// Error style (red) - use as `{ERROR}text{ERROR:#}`pub const ERROR: Style = Style::new().fg_color(Some(Color::Ansi(AnsiColor::Red)));+// ============================================================================+// Message Emojis+// ============================================================================++/// Error emoji - use with ERROR style: `eprintln!("{ERROR_EMOJI} {ERROR}message{ERROR:#}");`+pub const ERROR_EMOJI: &str = "β";++/// Warning emoji - use with WARNING style: `eprintln!("{WARNING_EMOJI} {WARNING}message{WARNING:#}");`+pub const WARNING_EMOJI: &str = "π‘";++/// Hint emoji - use with HINT style: `println!("{HINT_EMOJI} {HINT}message{HINT:#}");`+pub const HINT_EMOJI: &str = "π‘";+/// Warning style (yellow) - use as `{WARNING}text{WARNING:#}`pub const WARNING: Style = Style::new().fg_color(Some(Color::Ansi(AnsiColor::Yellow)));/// Hint style (dimmed) - use as `{HINT}text{HINT:#}`pub const HINT: Style = Style::new().dimmed();-/// Success style (green) - use as `{SUCCESS}text{SUCCESS:#}`-pub const SUCCESS: Style = Style::new().fg_color(Some(Color::Ansi(AnsiColor::Green)));-/// Current worktree style (magenta + bold)pub const CURRENT: Style = Style::new().bold()diff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snapindex 53a7b60e3..07b409982 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_deterministic.snap@@ -33,4 +33,4 @@ Path: [REPO]To enable automatic cd, run: wt configure-shell----- stderr ------Warning: LLM generation failed, using deterministic message+π‘ [33mLLM generation failed, using deterministic message[0mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snapindex 189096255..b4b108bde 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snap@@ -34,4 +34,4 @@ Path: [REPO]To enable automatic cd, run: wt configure-shell----- stderr ------Warning: LLM generation failed, using deterministic message+π‘ [33mLLM generation failed, using deterministic message[0mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snapindex 45b106d3c..7784479c4 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snap@@ -35,4 +35,4 @@ Path: [REPO]To enable automatic cd, run: wt configure-shell----- stderr ------Warning: LLM generation failed, using deterministic message+π‘ [33mLLM generation failed, using deterministic message[0mdiff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_failing_command.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_failing_command.snapindex 4ea9e6c73..d70389080 100644--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_failing_command.snap+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_failing_command.snap@@ -26,4 +26,4 @@ To enable automatic cd, run: wt configure-shell----- stderr -----Executing: exit 1-Warning: Command failed: Command 'exit 1' failed with exit code 1+π‘ [33mCommand failed: Command 'exit 1' failed with exit code 1[0mdiff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_invalid_toml.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_invalid_toml.snapindex 8059ee3ae..37de9c630 100644--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_invalid_toml.snap+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_invalid_toml.snap@@ -25,7 +25,7 @@ Created new branch and worktree for [1mfeature[0m at [REPO].featureTo enable automatic cd, run: wt configure-shell----- stderr ------Warning: Failed to load project config from [REPO]/.config/wt.toml+π‘ [33mFailed to load project config from [REPO]/.config/wt.toml[0mError: TOML parse error at line 1, column 39|1 | post-start-commands = [invalid syntax