Skip to content

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

feat: Show progress messages during batch worktree removal

Maximilian Roos04385e775aaa
diff --git a/CLAUDE.md b/CLAUDE.md
index 6259c8a01..ffb35f3c3 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -88,57 +88,99 @@ Command::new("sh")
.status()?;
```
-### Temporal Locality: Show Success When Actions Complete
+### Temporal Locality: Output Should Be Close to Operations
-**Principle: Emit success messages immediately when operations complete, not just in summaries.**
+**Core Principle: Output should appear immediately adjacent to the operations they describe.**
-Users need instant feedback that an operation succeeded. Summaries at the end are useful for context, but immediate feedback at the point of completion is critical for good UX.
+Users experience commands as temporal sequences. Output that appears far from its triggering operation creates confusion and breaks the mental model of what's happening.
-**Good pattern:**
-```
-πŸ”„ Squashing 3 commits into one...
-πŸ”„ Generating squash commit message...
- [commit message display]
-βœ… Squashed 3 commits into one ← Immediate feedback
-πŸ”„ Rebasing onto main...
-...
-βœ… Merged feature β†’ main ← Final summary
-Squashed 3 commits ← Context in summary
-```
+**The Two Patterns:**
+
+1. **Progress β†’ Operation β†’ Success** (for sequential operations)
+ ```
+ πŸ”„ Removing worktree for feature...
+ βœ… Removed worktree for feature
+ πŸ”„ Removing worktree for bugfix...
+ βœ… Removed worktree for bugfix
+ ```
-**Bad pattern:**
+2. **Progress β†’ Operation β†’ Success β†’ Summary** (for complex multi-step operations)
+ ```
+ πŸ”„ Squashing 3 commits into one...
+ πŸ”„ Generating commit message...
+ [commit message display]
+ βœ… Squashed 3 commits into one ← Immediate feedback
+ πŸ”„ Rebasing onto main...
+ ...
+ βœ… Merged feature β†’ main ← Final summary
+ Squashed 3 commits ← Context in summary
+ ```
+
+**Bad pattern - output decoupled from operations:**
```
-πŸ”„ Squashing 3 commits into one...
-πŸ”„ Generating squash commit message...
- [commit message display]
- ← No immediate feedback!
-πŸ”„ Rebasing onto main...
-...
-βœ… Merged feature β†’ main
-Squashed 3 commits ← Only mentioned in summary
+πŸ”„ Removing worktree for feature...
+πŸ”„ Removing worktree for bugfix...
+πŸ”„ Removing worktree for hotfix...
+ ← Long delay, no feedback
+Removed worktree for feature ← All output at the end
+Removed worktree for bugfix
+Removed worktree for hotfix
```
**Why this matters:**
-- **Temporal locality**: Feedback should appear when the action completes, not minutes later
-- **User confidence**: Immediate success messages confirm the operation worked
-- **Debugging**: If something fails later, users know which steps succeeded
+
+- **Temporal locality**: Feedback appears when the action completes, not seconds/minutes later
+- **User confidence**: Immediate success messages confirm each operation worked
+- **Debugging**: If something fails, users know exactly which operation failed
- **Progress visibility**: Users can see what's done vs. what's still in progress
+- **Interrupt recovery**: If user hits Ctrl+C, they know what completed
+- **Natural mental model**: Matches how users think about sequential operations
+
+**Implementation patterns:**
-**Implementation:**
```rust
-// After completing a significant operation, emit success immediately
-crate::output::success("Squashed 3 commits into one")?;
+// Pattern 1: Simple sequential operations (like batch remove)
+for item in items {
+ // Show what we're about to do
+ output::progress(format!("πŸ”„ {CYAN}Removing {item}...{CYAN:#}"))?;
+
+ // Do the operation
+ let result = perform_operation(item)?;
+
+ // Show immediate success
+ output::success(format!("Removed {item}"))?;
+}
+
+// Pattern 2: Complex operation with substeps
+output::progress("πŸ”„ Starting complex operation...")?;
-// The summary can still include this info for context
-let summary = format!("Merged {from} β†’ {to}\nSquashed {count} commits\n...");
-crate::output::success(summary)?;
+// Substep 1
+output::progress("πŸ”„ Validating...")?;
+validate()?;
+output::success("Validated")?;
+
+// Substep 2
+output::progress("πŸ”„ Processing...")?;
+process()?;
+output::success("Processed")?;
+
+// Final summary (optional, for context)
+output::success("Completed complex operation")?;
```
+**Red flags - violations of temporal locality:**
+
+1. **Collecting messages in a buffer**: `let mut messages = Vec::new(); messages.push(...)` β†’ emit immediately instead
+2. **Single success message for batch operations**: Loop that shows all successes at the end
+3. **No progress before slow operations**: User sees nothing, then suddenly output appears
+4. **Progress without matching success**: Progress messages that aren't followed by success/failure
+5. **Success before operation**: Showing success message before operation completes (async timing bugs)
+
**Apply this to:**
-- Squashing commits: Show "βœ… Squashed N commits" immediately after squashing
-- Pushing changes: Show "βœ… Pushed to branch" immediately after pushing
-- Committing changes: Show "βœ… Committed changes" immediately after committing
-- Any multi-step operation: Show success after each major step completes
+- Batch operations: Show progress + success for each item in the loop
+- Multi-step operations: Show success after each major step completes
+- Slow operations: Show progress immediately before starting
+- Error handling: Show failure immediately when detected, not collected for later
### Semantic Style Constants
diff --git a/src/main.rs b/src/main.rs
index 438c29ea3..660747b6e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -397,12 +397,28 @@ fn main() {
// Remove others first
for worktree in others.iter() {
+ // Show progress before starting removal
+ use anstyle::Style;
+ use worktrunk::styling::CYAN;
+ let bold = Style::new().bold();
+ output::progress(format!(
+ "πŸ”„ {CYAN}Removing worktree for {bold}{worktree}{bold:#}...{CYAN:#}"
+ ))?;
+
let result = handle_remove(Some(worktree.as_str()))?;
handle_remove_output(&result)?;
}
// Remove current worktree last (if it was in the list)
if let Some(current_name) = current {
+ // Show progress before starting removal
+ use anstyle::Style;
+ use worktrunk::styling::CYAN;
+ let bold = Style::new().bold();
+ output::progress(format!(
+ "πŸ”„ {CYAN}Removing worktree for {bold}{current_name}{bold:#}...{CYAN:#}"
+ ))?;
+
let result = handle_remove(Some(current_name.as_str()))?;
handle_remove_output(&result)?;
}