Skip to content

Conversation

@schrockn
Copy link
Member

Decompose the 732-line create.py into a 1,589-line subpackage with 12 focused modules that each handle specific responsibilities. This refactoring improves maintainability, testability, and code clarity while preserving all existing functionality.

Architecture

New Module Organization

  • types.py - Centralized data structures (CreationRequest, CreationResult, variants)
  • validation.py - All input validation and option conflict checking
  • orchestrator.py - CLI entry point that parses arguments and dispatches to variants
  • worktree_ops.py - Git worktree creation and branch management
  • output.py - Result formatting (JSON, shell scripts, human-readable)
  • post_creation.py - .env file generation and post-create command execution
  • variants/ - Five specialized handlers for different creation modes:
    • regular.py - Standard worktree with optional branch creation
    • from_current_branch.py - Move current branch to new worktree
    • from_branch.py - Create worktree from existing branch
    • plan.py - Create from plan file with .plan/ folder setup
    • with_dot_plan.py - Copy .plan/ folder from source workstack

Key Design Improvements

  1. Data-Driven Flow - CreationRequest struct eliminates parameter passing through deep call stacks
  2. Single Responsibility - Each module handles one concern (validation, output, branch ops, etc.)
  3. Variant Dispatch - Clear separation of creation modes enables independent testing and enhancement
  4. Strong Typing - Frozen dataclasses provide compile-time safety and clarity
  5. Error Boundaries - Validation concentrated early before complex operations

Files Changed

Added (13 files)

  • create/__init__.py - Package exports
  • create/types.py - Data structures
  • create/orchestrator.py - CLI orchestration
  • create/validation.py - Input validation
  • create/worktree_ops.py - Git operations
  • create/output.py - Output formatting
  • create/post_creation.py - Post-create handling
  • create/variants/__init__.py - Variants package
  • create/variants/regular.py - Regular creation
  • create/variants/from_current_branch.py - Move branch
  • create/variants/from_branch.py - From existing branch
  • create/variants/plan.py - Plan file creation
  • create/variants/with_dot_plan.py - .plan/ folder copying

Deleted (1 file)

  • create.py - Original monolithic command

Modified (10 files)

  • jump.py, rename.py - Import path updates
  • .github/workflows/* - Git attribute normalization
  • kit.yaml - Devrun hook updates
  • Test fixtures - JSON formatting

Critical Notes

  • All functionality preserved - existing CLI behavior unchanged
  • No breaking changes to command-line interface
  • Easier to test individual creation variants independently
  • Future enhancements (new --flag options) can now be handled with minimal coupling

Copy link
Member Author

schrockn commented Nov 16, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

… with specialized modules

Decompose the 732-line create.py into a 1,589-line subpackage with 12 focused modules that each handle specific responsibilities. This refactoring improves maintainability, testability, and code clarity while preserving all existing functionality.

## Architecture

### New Module Organization

- **types.py** - Centralized data structures (CreationRequest, CreationResult, variants)
- **validation.py** - All input validation and option conflict checking
- **orchestrator.py** - CLI entry point that parses arguments and dispatches to variants
- **worktree_ops.py** - Git worktree creation and branch management
- **output.py** - Result formatting (JSON, shell scripts, human-readable)
- **post_creation.py** - .env file generation and post-create command execution
- **variants/** - Five specialized handlers for different creation modes:
  - `regular.py` - Standard worktree with optional branch creation
  - `from_current_branch.py` - Move current branch to new worktree
  - `from_branch.py` - Create worktree from existing branch
  - `plan.py` - Create from plan file with .plan/ folder setup
  - `with_dot_plan.py` - Copy .plan/ folder from source workstack

### Key Design Improvements

1. **Data-Driven Flow** - CreationRequest struct eliminates parameter passing through deep call stacks
2. **Single Responsibility** - Each module handles one concern (validation, output, branch ops, etc.)
3. **Variant Dispatch** - Clear separation of creation modes enables independent testing and enhancement
4. **Strong Typing** - Frozen dataclasses provide compile-time safety and clarity
5. **Error Boundaries** - Validation concentrated early before complex operations

## Files Changed

### Added (13 files)

- `create/__init__.py` - Package exports
- `create/types.py` - Data structures
- `create/orchestrator.py` - CLI orchestration
- `create/validation.py` - Input validation
- `create/worktree_ops.py` - Git operations
- `create/output.py` - Output formatting
- `create/post_creation.py` - Post-create handling
- `create/variants/__init__.py` - Variants package
- `create/variants/regular.py` - Regular creation
- `create/variants/from_current_branch.py` - Move branch
- `create/variants/from_branch.py` - From existing branch
- `create/variants/plan.py` - Plan file creation
- `create/variants/with_dot_plan.py` - .plan/ folder copying

### Deleted (1 file)

- `create.py` - Original monolithic command

### Modified (10 files)

- `jump.py`, `rename.py` - Import path updates
- `.github/workflows/*` - Git attribute normalization
- `kit.yaml` - Devrun hook updates
- Test fixtures - JSON formatting

## Critical Notes

- All functionality preserved - existing CLI behavior unchanged
- No breaking changes to command-line interface
- Easier to test individual creation variants independently
- Future enhancements (new --flag options) can now be handled with minimal coupling
@schrockn schrockn force-pushed the add-with-dot-flag-to-workstack-25-11-16 branch from 8011e11 to 6ab9122 Compare November 16, 2025 11:53
@schrockn schrockn force-pushed the refactor-create-function-25-11-16 branch from 5728497 to 6582bd3 Compare November 16, 2025 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants