Skip to content

Add slug auto-detection, new commands, JSON output, and aliases#14

Merged
smorin merged 1 commit intomainfrom
claude/codebase-improvement-recommendations-wxJVS
Mar 11, 2026
Merged

Add slug auto-detection, new commands, JSON output, and aliases#14
smorin merged 1 commit intomainfrom
claude/codebase-improvement-recommendations-wxJVS

Conversation

@smorin
Copy link
Copy Markdown
Contributor

@smorin smorin commented Mar 11, 2026

Summary

This PR adds several quality-of-life improvements to worktreeflow:

  • Slug auto-detection: Commands can now infer the slug from the current working directory when inside a worktree
  • New navigation commands: wt-cd, wt-open, and wt-reopen for easier worktree management
  • JSON output mode: --json flag for machine-readable output from commands like doctor, wt-list, and wt-status
  • Command aliases: Short aliases (e.g., newwt-new, pubwt-publish) for faster typing
  • Configuration wizard: New init command for interactive setup
  • Version command: Display worktreeflow version
  • Environment variable support: Global flags can now be set via WTF_* environment variables

Key Changes

Core Manager Enhancements (manager.py)

  • Added json_output parameter to GitWorkflowManager.__init__
  • Implemented _infer_slug_from_cwd() to detect slug from worktree path pattern {worktree_base}/{repo_name}/{slug}
  • Added resolve_slug() method to handle explicit slug or auto-detection with clear error messages
  • Added _require_gh() helper to validate GitHub CLI availability with helpful error messages
  • Refactored doctor() to support JSON output mode while maintaining rich table display
  • Enhanced wt_list() to show last activity dates, staleness indicators, and PR information
  • Enhanced wt_status() to support JSON output
  • Added three new navigation commands:
    • wt_cd(): Print worktree path for shell composition (cd $(wtf wt-cd slug))
    • wt_open(): Open worktree in editor (auto-detects from $EDITOR or tries code/vim/nano)
    • wt_reopen(): Recreate a worktree from an existing remote branch

CLI Interface (cli.py)

  • Implemented AliasGroup custom Click group class to support command aliases
  • Added alias mapping: new, pub, pr, up, clean, ls, st, cd, open, reopen
  • Added --json global flag for machine-readable output
  • Added environment variable support for global flags: WTF_DEBUG, WTF_DRY_RUN, WTF_QUIET, WTF_VERBOSE, WTF_BASE_BRANCH
  • Made slug argument optional for commands that support auto-detection: wt-publish, wt-pr, wt-update, wt-clean, wt-status, wt-cd, wt-open
  • Added version command to display worktreeflow version
  • Added init command for interactive configuration
  • Added --open flag to wt-new to open editor after creation
  • Updated help text and docstrings to document auto-detection and aliases

Configuration (config.py)

  • Added generate_config() function to programmatically generate .worktreeflow.toml content with customizable options

Tests (test_new_features.py)

  • Comprehensive test suite for all new features including:
    • Slug auto-detection logic
    • New navigation commands
    • JSON output modes
    • Command aliases
    • Configuration generation
    • GitHub CLI requirement validation

Notable Implementation Details

  • Slug auto-detection gracefully falls back to requiring explicit slug with helpful error message
  • JSON output is mutually exclusive with --verbose flag
  • The wt_open command respects dry-run mode and doesn't spawn editor processes during preview
  • PR information in wt_list is only fetched when gh CLI is available and fork/upstream are configured
  • All new commands maintain backward compatibility with existing workflows
  • Error messages are enhanced with actionable suggestions (e.g., installation links, example commands)

https://claude.ai/code/session_01A1Z3oDtv65NzXVqYaSsn8G

…wt-open, wt-reopen, --json, init, env vars

Major new features and CLI ergonomics improvements:

- `wtf version` command (table-stakes for any CLI tool)
- Command aliases: new, pub, pr, up, clean, ls, st, cd, open, reopen
- Auto-detect SLUG from current worktree (no more typing slug every time)
- `wtf wt-cd SLUG` — print worktree path for shell composition
- `wtf wt-open SLUG` — open worktree in editor ($EDITOR/code/vim/nano)
- `wtf wt-reopen SLUG` — recreate worktree from existing remote branch
- `wtf init` — interactive config wizard for .worktreeflow.toml
- `--json` global flag for machine-readable output (doctor, wt-list, wt-status)
- `--open` flag on wt-new to open editor after creation
- Environment variable overrides: WTF_BASE_BRANCH, WTF_DEBUG, WTF_DRY_RUN, etc.
- Enhanced wt-list: last activity dates, stale worktree detection (30+ days), PR status
- Centralized `_require_gh()` for consistent gh CLI prerequisite checks
- Updated tutorial and quickstart with all new features
- 30 new tests (158 total), all passing with clean lint

https://claude.ai/code/session_01A1Z3oDtv65NzXVqYaSsn8G
@smorin smorin merged commit 3de0732 into main Mar 11, 2026
5 checks passed
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