Conversation
…bility ## Summary - Created new `internal/operations/` layer to centralize business logic - Extracted duplicated code from CLI commands into reusable operations - Added comprehensive test coverage (85.9%) for core business logic - Eliminated major code duplication across 13+ locations ## New Operations Layer - **SessionOperations**: Session CRUD, lookup, and recreation logic - **CleanupOperations**: Comprehensive cleanup with detailed stats - **StatusFormat**: Unified formatting for tmux/claude/git status ## Refactored CLI Commands - `cwt new`: Uses operations for session creation - `cwt delete`: Uses operations for session lookup and deletion - `cwt cleanup`: Completely rewritten using operations layer - `cwt attach`: Uses operations for session recreation - `cwt list`: Uses operations for formatting and session retrieval - `cwt status`: Uses operations for consistent formatting ## Code Elimination - Removed duplicate `FindSessionByName` logic (13+ instances) - Removed duplicate `findClaudeExecutable` functions (3 instances) - Removed duplicate formatting functions (80+ lines from list.go) - Removed duplicate session recreation logic (attach.go) ## Testing Improvements - Added 22 comprehensive test cases for operations layer - Mock-based testing for clean isolation - Edge case coverage for error scenarios - Improved overall project test coverage significantly ## Architecture Benefits - Single source of truth for business logic - Clean separation of CLI parsing vs business operations - Reusable operations for future TUI integration - Consistent error handling patterns - Future-proof for additional CLI commands 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Claude finished @jlaneve's task —— View job Claude Code is reviewing this PR… Review Tasks
Code Review✅ Overall Assessment: Excellent RefactoringThis is a high-quality refactoring that significantly improves the codebase's maintainability and testability. The new operations layer follows solid architectural principles and eliminates substantial code duplication. 🏗️ Architecture & DesignStrengths:
Suggestions:
🔒 Security (Excellent)Strong security practices found:
Security validation functions are thorough: // internal/operations/cleanup.go:216-242
func isValidWorktreeName(name string) bool {
// Excellent coverage of attack vectors
}
// internal/operations/sessions.go:115-137
func isValidExecutablePath(path string) bool {
// Good shell injection prevention
}🧪 Test Coverage (Very Good)Strengths:
Areas for improvement:
🐛 Potential IssuesMinor Issues:
if existingSessionID, err := s.stateManager.GetClaudeChecker().FindSessionID(session.Core.WorktreePath); err == nil && existingSessionID != "" {This swallows errors. Consider logging or handling the error case.
Suggestions:
func (s *SessionOperations) CreateSessionWithContext(ctx context.Context, name string) error
type CreateSessionResult struct {
Session *types.Session
Warnings []string
}⚡ PerformanceGood performance characteristics:
Considerations:
🎯 Code QualityExcellent practices:
Minor improvements:
📊 Test Quality Deep DiveWell-structured test files:
Good testing patterns: // Proper setup and teardown
tmpDir := t.TempDir()
defer manager.Close()
// Descriptive test names
func TestIsValidWorktreeName(t *testing.T)
// Comprehensive input validation testing
tests := []struct {
name string
input string
expected bool
}🔄 Refactoring ImpactPositive changes:
Clean CLI integration: // Before: 200+ lines in cleanup.go
// After: 85 lines using operations layer
cleanupOps := operations.NewCleanupOperations(sm)
stats, err := cleanupOps.FindAndCleanupStaleResources(dryRun)🚀 RecommendationsImmediate (for this PR):
Future enhancements:
🏆 SummaryThis is an exemplary refactoring that significantly improves code quality while maintaining all existing functionality. The new operations layer provides a solid foundation for future features (TUI, enhanced testing) and eliminates major technical debt. Key wins:
Recommendation: Approve with minor suggestions The code quality is high, security practices are excellent, and the architectural improvements are substantial. The minor issues identified are non-blocking and can be addressed in follow-up PRs. |
## Formatting Fixes - Fixed Go formatting issues across all files - Applied `go fmt ./...` to ensure consistent formatting - All tests now pass without formatting errors ## CI Workflow Improvements - Separated CI into 3 distinct jobs for clarity: - **Code Quality**: Formatting, go mod tidy, linting (go vet) - **Build**: Compilation check - **Tests**: Test execution with coverage - Added clear emojis and status messages for each step - Jobs run in parallel for faster feedback - Easy to identify which specific area is failing ## Benefits - Faster identification of formatting vs test failures - Parallel execution improves CI speed - Clear visual feedback with emojis and status messages - Better developer experience with specific error messages 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Addresses security issues identified in PR #4 review: - Add path validation in FindClaudeExecutable() to prevent directory traversal attacks - Add command injection prevention in removeWorktree() function - Implement isValidExecutablePath() to validate Claude executable paths - Implement isValidWorktreeName() and isPathWithinDataDir() for worktree safety - Add comprehensive test coverage for all security validation functions Security mitigations: - Reject paths with "..", null bytes, and shell metacharacters - Allow $HOME expansion only at path start for legitimate use - Validate worktree names against command injection patterns - Ensure worktree paths stay within expected data directory boundaries - Reject names starting with dash to prevent flag injection 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>

Summary
internal/operations/layer to centralize business logicNew Operations Layer
Refactored CLI Commands
cwt new: Uses operations for session creationcwt delete: Uses operations for session lookup and deletioncwt cleanup: Completely rewritten using operations layercwt attach: Uses operations for session recreationcwt list: Uses operations for formatting and session retrievalcwt status: Uses operations for consistent formattingCode Elimination
FindSessionByNamelogic (13+ instances)findClaudeExecutablefunctions (3 instances)Testing Improvements
Architecture Benefits
🤖 Generated with Claude Code