wt-manager 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +343 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +26 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/commands/clean.d.ts +3 -0
  8. package/dist/commands/clean.d.ts.map +1 -0
  9. package/dist/commands/clean.js +339 -0
  10. package/dist/commands/clean.js.map +1 -0
  11. package/dist/commands/init.d.ts +3 -0
  12. package/dist/commands/init.d.ts.map +1 -0
  13. package/dist/commands/init.js +12 -0
  14. package/dist/commands/init.js.map +1 -0
  15. package/dist/commands/list.d.ts +3 -0
  16. package/dist/commands/list.d.ts.map +1 -0
  17. package/dist/commands/list.js +202 -0
  18. package/dist/commands/list.js.map +1 -0
  19. package/dist/commands/new.d.ts +3 -0
  20. package/dist/commands/new.d.ts.map +1 -0
  21. package/dist/commands/new.js +147 -0
  22. package/dist/commands/new.js.map +1 -0
  23. package/dist/commands/remove.d.ts +3 -0
  24. package/dist/commands/remove.d.ts.map +1 -0
  25. package/dist/commands/remove.js +192 -0
  26. package/dist/commands/remove.js.map +1 -0
  27. package/dist/commands/wt.d.ts +3 -0
  28. package/dist/commands/wt.d.ts.map +1 -0
  29. package/dist/commands/wt.js +78 -0
  30. package/dist/commands/wt.js.map +1 -0
  31. package/dist/commands/wtclean.d.ts +3 -0
  32. package/dist/commands/wtclean.d.ts.map +1 -0
  33. package/dist/commands/wtclean.js +190 -0
  34. package/dist/commands/wtclean.js.map +1 -0
  35. package/dist/commands/wtlist.d.ts +3 -0
  36. package/dist/commands/wtlist.d.ts.map +1 -0
  37. package/dist/commands/wtlist.js +202 -0
  38. package/dist/commands/wtlist.js.map +1 -0
  39. package/dist/index.d.ts +3 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +3 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/utils/clipboard.d.ts +2 -0
  44. package/dist/utils/clipboard.d.ts.map +1 -0
  45. package/dist/utils/clipboard.js +23 -0
  46. package/dist/utils/clipboard.js.map +1 -0
  47. package/dist/utils/git.d.ts +45 -0
  48. package/dist/utils/git.d.ts.map +1 -0
  49. package/dist/utils/git.js +202 -0
  50. package/dist/utils/git.js.map +1 -0
  51. package/dist/utils/github.d.ts +21 -0
  52. package/dist/utils/github.d.ts.map +1 -0
  53. package/dist/utils/github.js +113 -0
  54. package/dist/utils/github.js.map +1 -0
  55. package/package.json +61 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 David Durika
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,343 @@
1
+ # Git Worktree Manager
2
+
3
+ The dashboard Git forgot to include.
4
+
5
+ ## The Problem
6
+
7
+ Git worktrees let you work on multiple branches simultaneously—but managing them? That's where the fun ends.
8
+
9
+ - **"Which folder was that again?"** - You have 5 worktree directories and zero memory of which one has `feature/auth`
10
+ - **The GitHub tab dance** - Constantly switching to check if that PR got merged yet, or if it's still sitting in review purgatory
11
+ - **Stale worktree graveyard** - Merged PRs pile up as forgotten worktrees, each one silently judging your organizational skills
12
+ - **Three tools, zero coordination** - Git knows your worktrees. GitHub knows your PRs. Your filesystem knows your folders. They don't talk to each other.
13
+
14
+ ## The Solution
15
+
16
+ `wt` gives you the dashboard Git forgot to include.
17
+
18
+ ![wt list output](./wt-list.png)
19
+
20
+ The `wt list` command shows you everything:
21
+ - All your worktrees with their PR status (open/draft/merged/closed)
22
+ - Which branches are ahead/behind
23
+ - CI check status (passing/failing)
24
+ - Uncommitted changes warnings
25
+
26
+ And when you're done? `wt clean` finds all merged/closed PRs and removes their worktrees and branches in one go. It even asks nicely before deleting anything.
27
+
28
+ ## Quick Start
29
+
30
+ **Requirements:** Node.js 22+, Git, and [GitHub CLI](https://cli.github.com/) (`gh auth login`)
31
+
32
+ ```bash
33
+ # Install globally
34
+ npm install -g .
35
+
36
+ # Create a new worktree
37
+ wt feature/my-feature
38
+
39
+ # See all worktrees with PR status
40
+ wt list
41
+
42
+ # Clean up merged/closed worktrees
43
+ wt clean
44
+ ```
45
+
46
+ ### Shell Integration
47
+
48
+ For the full workflow (create worktree → cd into it → open IDE → start Claude):
49
+
50
+ ```bash
51
+ # Add to ~/.zshrc
52
+ eval "$(wt init)"
53
+
54
+ # To initialize a new worktree and branch call
55
+ wt feature/my-feature
56
+ # To navigate to it, open WebStorm, and start Claude, run:
57
+ wtl ../repo-worktrees/feature-my-feature
58
+ ```
59
+
60
+ ## Commands
61
+
62
+ ### `wt <branch-name> [base-branch]`
63
+ ### `wt new <branch-name> [base-branch]`
64
+
65
+ Create a new worktree for a new branch. Worktrees are created in `../<repo>-worktrees/` directory.
66
+
67
+ ```bash
68
+ # Create worktree from default branch (shorthand)
69
+ wt feature/new-feature
70
+
71
+ # Create worktree from default branch (explicit)
72
+ wt new feature/new-feature
73
+
74
+ # Create worktree from specific base branch
75
+ wt new feature/new-feature develop
76
+ ```
77
+
78
+ **Arguments:**
79
+ - `<branch-name>` - Name of the new branch to create
80
+ - `[base-branch]` - Base branch to create from (default: auto-detected from origin/HEAD)
81
+
82
+ **Behavior:**
83
+ - Automatically creates the worktree directory structure
84
+ - Converts slashes in branch names to dashes for directory names (e.g., `feature/foo` → `feature-foo`)
85
+ - Shows spinner during creation
86
+ - Fails if branch already exists locally
87
+ - Symlinks `.env` file from main worktree if present
88
+ - Copies `.claude/settings.local.json` from main worktree if present
89
+ - Copies WebStorm `.idea` settings from main worktree (run configurations, code styles, inspection profiles, scopes, and project files)
90
+ - Copies worktree path to clipboard for easy navigation
91
+
92
+ ### `wt list`
93
+
94
+ List all worktrees with their status, PR information, and branch details.
95
+
96
+ ```bash
97
+ # List all worktrees with status
98
+ wt list
99
+
100
+ # JSON output format
101
+ wt list --json
102
+ ```
103
+
104
+ **Options:**
105
+ - `--json` - Output in JSON format (disables spinner)
106
+
107
+ **Output includes:**
108
+ - Worktree directory name
109
+ - PR status (open/draft/merged/closed/no-pr)
110
+ - Branch ahead/behind counts relative to default branch
111
+ - Uncommitted changes indicator
112
+ - CI check status (passing/failing)
113
+ - Current worktree indicator
114
+ - PR URL (if available)
115
+ - Summary statistics
116
+
117
+ **Example output:**
118
+ ```
119
+ Worktrees for my-repo:
120
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
121
+
122
+ feature-auth open (↑3 ↓0)
123
+ Branch: feature/auth
124
+ PR: https://github.com/owner/repo/pull/123
125
+
126
+ bugfix-login merged (↑0 ↓2)
127
+ Branch: bugfix/login
128
+
129
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
130
+ Summary: 2 worktrees (1 open, 1 merged)
131
+ 💡 Run 'wt clean' to remove 1 merged/closed worktree(s)
132
+ ```
133
+
134
+ ### `wt clean`
135
+
136
+ Remove worktrees for branches with merged or closed PRs, abandoned folders, and orphan worktrees. Uses interactive checkbox selection.
137
+
138
+ ```bash
139
+ # Clean up merged/closed worktrees (interactive)
140
+ wt clean
141
+
142
+ # Dry run to see what would be removed
143
+ wt clean --dry-run
144
+
145
+ # Skip interactive selection (select all)
146
+ wt clean --force
147
+ ```
148
+
149
+ **Options:**
150
+ - `-d, --dry-run` - Show what would be removed without actually removing
151
+ - `-f, --force` - Skip interactive selection (removes all cleanable items)
152
+
153
+ **What it detects:**
154
+ - **Merged/Closed worktrees** - Worktrees with merged or closed PRs
155
+ - **Abandoned folders** - Directories in worktrees folder without `.git` (leftover from manual deletions)
156
+ - **Orphan worktrees** - Directories with `.git` file pointing to non-existent gitdir
157
+
158
+ **Safety features:**
159
+ - Shows spinner while checking PR status
160
+ - Automatically skips worktrees with uncommitted changes (warns user)
161
+ - Skips the current worktree
162
+ - Interactive checkbox selection to choose what to remove
163
+ - Automatically deletes local branch when removing worktree
164
+ - Only processes worktrees in `<repo>-worktrees/` directory
165
+
166
+ **Example flow:**
167
+ ```
168
+ Scanning worktrees...
169
+ Checking PR status...
170
+ Scanning for abandoned folders...
171
+
172
+ ⚠ Skipped (uncommitted changes):
173
+ bugfix-draft (bugfix/draft)
174
+
175
+ ? Select worktrees to remove:
176
+ ❯ ◯ feature-old (MERGED)
177
+ ◯ bugfix-done (CLOSED)
178
+ ◯ leftover-dir (abandoned)
179
+ ◯ broken-wt (orphan)
180
+
181
+ Removing feature-old...
182
+ ✓ Removed: feature-old (branch deleted)
183
+
184
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
185
+ ✓ Cleaned up 1 worktree(s)!
186
+ Run 'wt list' to see remaining worktrees.
187
+ ```
188
+
189
+ ### `wt remove <name>`
190
+
191
+ Remove a specific worktree by name. Interactive with safety prompts for uncommitted changes and unpushed commits.
192
+
193
+ ```bash
194
+ # Remove by branch name
195
+ wt remove feature/my-feature
196
+
197
+ # Remove by directory name
198
+ wt remove feature-my-feature
199
+
200
+ # Keep the local branch (only remove worktree)
201
+ wt remove feature/my-feature --keep-branch
202
+
203
+ # Force removal (skip all prompts)
204
+ wt remove feature/my-feature --force
205
+ ```
206
+
207
+ **Arguments:**
208
+ - `<name>` - Worktree name (matches branch name or directory name)
209
+
210
+ **Options:**
211
+ - `--keep-branch` - Keep the local branch after removing the worktree
212
+ - `-f, --force` - Force removal even with uncommitted changes or unpushed commits
213
+
214
+ **Safety features:**
215
+ - Shows uncommitted changes before removal
216
+ - Option to view diff before discarding changes
217
+ - Warns about unpushed commits before branch deletion
218
+ - Warns about branches with no remote tracking
219
+ - Interactive prompts to abort, keep branch, or proceed
220
+
221
+ **Example flow:**
222
+ ```
223
+ Worktree: feature-my-feature
224
+ Path: /path/to/repo-worktrees/feature-my-feature
225
+ Branch: feature/my-feature
226
+
227
+ ⚠ Uncommitted changes detected:
228
+
229
+ Modified:
230
+ src/file.ts
231
+
232
+ ? What would you like to do?
233
+ ❯ Show diff
234
+ Discard changes and remove
235
+ Abort
236
+
237
+ ✓ Removed worktree: feature-my-feature
238
+ ✓ Deleted branch: feature/my-feature
239
+
240
+ Run 'wt list' to see remaining worktrees
241
+ ```
242
+
243
+ ### `wt init`
244
+
245
+ Output shell function for `~/.zshrc` integration. Creates a `wtl` command that automates the full workflow.
246
+
247
+ ```bash
248
+ # Add to ~/.zshrc:
249
+ eval "$(wt init)"
250
+ ```
251
+
252
+ **The `wtl` function:**
253
+ 1. Creates a new worktree (`wt new`)
254
+ 2. Changes to the worktree directory
255
+ 3. Opens WebStorm
256
+ 4. Starts Claude
257
+
258
+ ```bash
259
+ # Usage:
260
+ wtl feature/my-feature
261
+ ```
262
+
263
+ ## GitHub Integration
264
+
265
+ This tool integrates with GitHub to provide rich PR information:
266
+
267
+ - **PR Status** - Displays open/draft/merged/closed state
268
+ - **PR URLs** - Direct links to pull requests
269
+ - **CI Checks** - Shows if checks are passing or failing
270
+ - **Smart Cleanup** - Identifies branches safe to remove based on PR state
271
+ - **Draft Detection** - Shows when PRs are in draft state
272
+
273
+ ### Authentication
274
+
275
+ Uses existing GitHub CLI (`gh`) authentication. Make sure you're logged in:
276
+
277
+ ```bash
278
+ gh auth login
279
+ ```
280
+
281
+ The tool will show helpful error messages if:
282
+ - `gh` CLI is not installed
283
+ - You're not authenticated
284
+ - The repository doesn't have a GitHub remote
285
+
286
+ ### Without GitHub
287
+
288
+ The tool works without GitHub integration, but with limited functionality:
289
+ - `wt list` will show "no-pr" status for all worktrees
290
+ - `wt clean` requires GitHub CLI and won't work without it
291
+
292
+ ## Workflow Example
293
+
294
+ Here's a typical workflow using these tools:
295
+
296
+ ```bash
297
+ # Create a new worktree for a feature
298
+ wt feature/add-auth
299
+
300
+ # Navigate to the worktree
301
+ cd ../my-repo-worktrees/feature-add-auth
302
+
303
+ # Work on your feature...
304
+ git add .
305
+ git commit -m "Add authentication"
306
+ git push -u origin feature/add-auth
307
+
308
+ # Create PR via gh CLI
309
+ gh pr create --title "Add authentication" --body "Implements user auth"
310
+
311
+ # Check status of all worktrees
312
+ wt list
313
+ # Shows: feature-add-auth (open)
314
+
315
+ # After PR is merged, clean up
316
+ wt clean
317
+ # Removes merged worktree and deletes branch
318
+ ```
319
+
320
+ ## Development
321
+
322
+ ### Build
323
+
324
+ ```bash
325
+ npm run build
326
+ ```
327
+
328
+ ### Watch Mode
329
+
330
+ ```bash
331
+ npm run dev
332
+ ```
333
+
334
+ ### Linting
335
+
336
+ ```bash
337
+ npm run lint
338
+ npm run format
339
+ ```
340
+
341
+ ## License
342
+
343
+ MIT
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { createRequire } from 'node:module';
4
+ import { newCommand } from './commands/new.js';
5
+ import { listCommand } from './commands/list.js';
6
+ import { cleanCommand } from './commands/clean.js';
7
+ import { removeCommand } from './commands/remove.js';
8
+ import { initCommand } from './commands/init.js';
9
+ const require = createRequire(import.meta.url);
10
+ const pkg = require('../package.json');
11
+ const program = new Command();
12
+ program
13
+ .name('wt')
14
+ .description('Git Worktree Manager - Manage git worktrees with GitHub integration')
15
+ .version(pkg.version, '-v, --version', 'output the version number');
16
+ program.addCommand(newCommand());
17
+ program.addCommand(listCommand());
18
+ program.addCommand(cleanCommand());
19
+ program.addCommand(removeCommand());
20
+ program.addCommand(initCommand());
21
+ const args = process.argv.slice(2);
22
+ if (args.length > 0 && !['new', 'list', 'clean', 'remove', 'init', '-h', '--help', '-v', '--version'].includes(args[0])) {
23
+ process.argv.splice(2, 0, 'new');
24
+ }
25
+ program.parse();
26
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC9C,MAAM,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAwB,CAAA;AAE7D,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAA;AAE7B,OAAO;KACJ,IAAI,CAAC,IAAI,CAAC;KACV,WAAW,CAAC,qEAAqE,CAAC;KAClF,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,eAAe,EAAE,2BAA2B,CAAC,CAAA;AAGrE,OAAO,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,CAAA;AAChC,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAA;AACjC,OAAO,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC,CAAA;AAClC,OAAO,CAAC,UAAU,CAAC,aAAa,EAAE,CAAC,CAAA;AACnC,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAA;AAGjC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAClC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAExH,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAA;AAClC,CAAC;AAED,OAAO,CAAC,KAAK,EAAE,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ export declare function cleanCommand(): Command;
3
+ //# sourceMappingURL=clean.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/commands/clean.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAsJnC,wBAAgB,YAAY,YAiS3B"}