Skip to content

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.md
index 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 Pattern
Use 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 name
let 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 bold
let 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 message
let bold = Style::new().bold();
@@ -136,7 +141,7 @@ println!("Switched to worktree: {bold}{branch}{bold:#}");
// Complex multi-part error
let 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 info
let dim = Style::new().dimmed();
diff --git a/src/commands/list/mod.rs b/src/commands/list/mod.rs
index 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.rs
index 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 branch
let 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 flow
return 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.rs
index 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 flag
if 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 worktree
if 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 execution
fn 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 config
Err(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 allowed
if !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.rs
index 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 formatting
GitError::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.rs
index 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 message
diff --git a/src/styling.rs b/src/styling.rs
index 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.snap
index 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
+🟑 LLM generation failed, using deterministic message
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_llm_fallback.snap
index 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
+🟑 LLM generation failed, using deterministic message
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snap b/tests/snapshots/integration__integration_tests__merge__merge_squash_with_llm.snap
index 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
+🟑 LLM generation failed, using deterministic message
diff --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.snap
index 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
+🟑 Command failed: Command 'exit 1' failed with exit code 1
diff --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.snap
index 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 feature at [REPO].feature
To enable automatic cd, run: wt configure-shell
----- stderr -----
-Warning: Failed to load project config from [REPO]/.config/wt.toml
+🟑 Failed to load project config from [REPO]/.config/wt.toml
Error: TOML parse error at line 1, column 39
|
1 | post-start-commands = [invalid syntax