mintree 0.1.2

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 (64) hide show
  1. package/README.md +188 -0
  2. package/dist/cli.d.ts +2 -0
  3. package/dist/cli.js +12 -0
  4. package/dist/commands/dashboard.d.ts +2 -0
  5. package/dist/commands/dashboard.js +849 -0
  6. package/dist/commands/doctor.d.ts +2 -0
  7. package/dist/commands/doctor.js +327 -0
  8. package/dist/commands/helpers/index.d.ts +1 -0
  9. package/dist/commands/helpers/index.js +1 -0
  10. package/dist/commands/helpers/session-signal/end.d.ts +2 -0
  11. package/dist/commands/helpers/session-signal/end.js +9 -0
  12. package/dist/commands/helpers/session-signal/index.d.ts +1 -0
  13. package/dist/commands/helpers/session-signal/index.js +1 -0
  14. package/dist/commands/helpers/session-signal/install.d.ts +2 -0
  15. package/dist/commands/helpers/session-signal/install.js +25 -0
  16. package/dist/commands/helpers/session-signal/notification.d.ts +2 -0
  17. package/dist/commands/helpers/session-signal/notification.js +9 -0
  18. package/dist/commands/helpers/session-signal/prompt.d.ts +2 -0
  19. package/dist/commands/helpers/session-signal/prompt.js +9 -0
  20. package/dist/commands/helpers/session-signal/stop.d.ts +2 -0
  21. package/dist/commands/helpers/session-signal/stop.js +9 -0
  22. package/dist/commands/helpers/shell-init.d.ts +11 -0
  23. package/dist/commands/helpers/shell-init.js +111 -0
  24. package/dist/commands/index.d.ts +2 -0
  25. package/dist/commands/index.js +6 -0
  26. package/dist/commands/init.d.ts +2 -0
  27. package/dist/commands/init.js +129 -0
  28. package/dist/commands/worktree/clean.d.ts +11 -0
  29. package/dist/commands/worktree/clean.js +206 -0
  30. package/dist/commands/worktree/create.d.ts +18 -0
  31. package/dist/commands/worktree/create.js +93 -0
  32. package/dist/commands/worktree/index.d.ts +1 -0
  33. package/dist/commands/worktree/index.js +1 -0
  34. package/dist/commands/worktree/list.d.ts +10 -0
  35. package/dist/commands/worktree/list.js +143 -0
  36. package/dist/commands/worktree/remove.d.ts +12 -0
  37. package/dist/commands/worktree/remove.js +46 -0
  38. package/dist/commands/worktree/work.d.ts +15 -0
  39. package/dist/commands/worktree/work.js +192 -0
  40. package/dist/lib/branch.d.ts +26 -0
  41. package/dist/lib/branch.js +57 -0
  42. package/dist/lib/claude.d.ts +26 -0
  43. package/dist/lib/claude.js +67 -0
  44. package/dist/lib/dashboard.d.ts +50 -0
  45. package/dist/lib/dashboard.js +139 -0
  46. package/dist/lib/exec.d.ts +2 -0
  47. package/dist/lib/exec.js +15 -0
  48. package/dist/lib/git.d.ts +110 -0
  49. package/dist/lib/git.js +320 -0
  50. package/dist/lib/github.d.ts +7 -0
  51. package/dist/lib/github.js +15 -0
  52. package/dist/lib/markers.d.ts +21 -0
  53. package/dist/lib/markers.js +43 -0
  54. package/dist/lib/metadata.d.ts +18 -0
  55. package/dist/lib/metadata.js +44 -0
  56. package/dist/lib/session-signal.d.ts +63 -0
  57. package/dist/lib/session-signal.js +160 -0
  58. package/dist/lib/worktreeCreate.d.ts +36 -0
  59. package/dist/lib/worktreeCreate.js +184 -0
  60. package/dist/lib/worktreeRemove.d.ts +21 -0
  61. package/dist/lib/worktreeRemove.js +84 -0
  62. package/package.json +63 -0
  63. package/shell/init.bash +106 -0
  64. package/shell/init.zsh +125 -0
package/shell/init.zsh ADDED
@@ -0,0 +1,125 @@
1
+ # Mintree Shell Integration for Zsh
2
+ # ==================================
3
+ #
4
+ # Generated by `mintree helpers shell-init zsh`. Eval this in your ~/.zshrc:
5
+ # eval "$(mintree helpers shell-init zsh)"
6
+ #
7
+ # What it does:
8
+ # 1. Wraps the `mintree` binary so the parent shell can `cd` into a freshly
9
+ # created worktree. The binary itself can't change the parent's cwd, so
10
+ # it emits `MINTREE_CD:<path>` markers on stdout that this wrapper picks
11
+ # up and translates into a real `cd`.
12
+ # 2. When `worktree create --work` is used, also reads `MINTREE_WORK:1`,
13
+ # `MINTREE_WORK_PROMPT_FILE:<path>`, and `MINTREE_PERMISSION_MODE:<mode>`
14
+ # and chains a `mintree worktree work` invocation right after the cd.
15
+ # 3. Recovers the current shell when its cwd was deleted (e.g. after
16
+ # `mintree worktree remove`) — falls back to the main repo, then to $HOME.
17
+ # 4. Exposes the `mt` / `mtw` / `mtn` aliases (`mtn` prompts for a branch).
18
+ # 5. Exports MINTREE_SHELL_INTEGRATION=1 so `mintree doctor` can verify the
19
+ # wrapper is loaded.
20
+
21
+ export MINTREE_SHELL_INTEGRATION=1
22
+
23
+ function mintree() {
24
+ # Recover from a deleted cwd. If the current directory was a mintree
25
+ # worktree that was just removed, return to the main repo; otherwise
26
+ # bounce to $HOME so subsequent commands don't error out cryptically.
27
+ if [[ ! -d "$(pwd 2>/dev/null)" ]]; then
28
+ local current_path="$(pwd 2>/dev/null)"
29
+ if [[ "$current_path" == */.mintree/worktrees/* ]]; then
30
+ local main_repo="${current_path%%/.mintree/worktrees/*}"
31
+ if [[ -d "$main_repo" ]]; then
32
+ echo "⚠ Worktree directory deleted. Returning to main repo."
33
+ cd "$main_repo" || cd ~ || return 1
34
+ else
35
+ cd ~ || return 1
36
+ fi
37
+ else
38
+ echo "⚠ Current directory no longer exists. Returning to home."
39
+ cd ~ || return 1
40
+ fi
41
+ fi
42
+
43
+ # Walks a marker block (whatever `worktree create` emitted, captured into
44
+ # $1 with no ANSI) and turns the markers into shell side-effects: cd to
45
+ # the new worktree, then optionally chain `worktree work` with the right
46
+ # flags. Returns 0 when the cd succeeded, 1 when there was nothing to do.
47
+ _mintree_handle_markers() {
48
+ local clean_output="$1"
49
+ local target_dir
50
+ target_dir=$(echo "$clean_output" | grep "MINTREE_CD:" | sed 's/.*MINTREE_CD://')
51
+ if [[ -z "$target_dir" || ! -d "$target_dir" ]]; then
52
+ return 1
53
+ fi
54
+ cd "$target_dir" && echo "Switched to: $target_dir"
55
+
56
+ if [[ "$clean_output" != *MINTREE_WORK:* ]]; then
57
+ return 0
58
+ fi
59
+ local extra=()
60
+ local prompt_file
61
+ prompt_file=$(echo "$clean_output" | grep "MINTREE_WORK_PROMPT_FILE:" | sed 's/.*MINTREE_WORK_PROMPT_FILE://')
62
+ local perm_mode
63
+ perm_mode=$(echo "$clean_output" | grep "MINTREE_PERMISSION_MODE:" | sed 's/.*MINTREE_PERMISSION_MODE://')
64
+ [[ -n "$prompt_file" ]] && extra+=(--prompt-file "$prompt_file")
65
+ [[ -n "$perm_mode" ]] && extra+=(--permission-mode "$perm_mode")
66
+ command mintree worktree work "${extra[@]}"
67
+ return $?
68
+ }
69
+
70
+ # `worktree create`: capture stdout so we can grep for markers, print the
71
+ # rest to the user, then run the side-effects.
72
+ if [[ "$1" == "worktree" && "$2" == "create" ]]; then
73
+ local output
74
+ output=$(command mintree "$@" 2>&1)
75
+ local exit_code=$?
76
+
77
+ if [[ "$output" == *MINTREE_CD:* ]]; then
78
+ echo "$output" | grep -vE "MINTREE_(CD|WORK|WORK_PROMPT_FILE|PERMISSION_MODE):"
79
+ local clean_output=$(echo "$output" | sed 's/\x1b\[[0-9;]*m//g')
80
+ _mintree_handle_markers "$clean_output"
81
+ else
82
+ echo "$output"
83
+ fi
84
+ return $exit_code
85
+ fi
86
+
87
+ # `dashboard`: the TUI owns the TTY, so we can't capture stdout without
88
+ # breaking rendering. Instead, hand the binary a temp file via env var
89
+ # and let it write markers there directly. Once the dashboard exits we
90
+ # read whatever's in the file and run the same side-effects as create.
91
+ if [[ "$1" == "dashboard" ]]; then
92
+ local marker_file
93
+ marker_file=$(mktemp -t mintree-markers)
94
+ MINTREE_MARKER_FILE="$marker_file" command mintree "$@"
95
+ local exit_code=$?
96
+ if [[ -s "$marker_file" ]]; then
97
+ local clean_output=$(cat "$marker_file" | sed 's/\x1b\[[0-9;]*m//g')
98
+ _mintree_handle_markers "$clean_output"
99
+ fi
100
+ rm -f "$marker_file"
101
+ return $exit_code
102
+ fi
103
+
104
+ command mintree "$@"
105
+ }
106
+
107
+ # Aliases as functions so they survive `eval` (zsh expands aliases at
108
+ # parse time, which is too early when the eval and the call live on the
109
+ # same script line). Functions are looked up at call time and always work.
110
+ function mt() {
111
+ mintree "$@"
112
+ }
113
+
114
+ function mtw() {
115
+ mintree worktree "$@"
116
+ }
117
+
118
+ # `mtn` — interactive shortcut: prompt for a branch then create the worktree
119
+ # and start working on it. Equivalent to santree's `stn`.
120
+ function mtn() {
121
+ local branch
122
+ vared -p "Branch name: " branch
123
+ [[ -z "$branch" ]] && echo "Branch name required" && return 1
124
+ mintree worktree create "$branch" --work
125
+ }