@maxiaochao/pi-toolkit 0.4.0 → 0.5.1

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 2026-09-11 - v0.5.1
2
+
3
+ - fix pi-worktree: remove now cleans up the branch automatically — merged branches are deleted without prompting, unmerged ones confirm once (one prompt covers both worktree removal and branch deletion), so recreating the same name no longer silently reuses a stale branch
4
+
5
+ ## 2026-09-11 - v0.5.0
6
+
7
+ - fix pi-worktree: new worktrees now branch from the current branch instead of a stale origin/main (worktree content no longer misses current work); add start --base <ref> to branch from an explicit ref
8
+
1
9
  ## 2026-09-11 - v0.4.0
2
10
 
3
11
  - bundle the chrome-cdp skill for attaching to a live Chrome with remote debugging (derived from pasky/chrome-cdp-skill, MIT); pi-worktree: add explicit start subcommand and skip dirty-workspace prompt when reusing an existing worktree
package/README.md CHANGED
@@ -57,7 +57,7 @@ pi-worktree remove feat-ui # remove the worktree (refuses unmerged branches)
57
57
  pi-worktree prune # drop stale registrations for manually deleted dirs
58
58
  ```
59
59
 
60
- Typical loop: `pi-worktree start <name>` to start (Tab completes existing worktree names), commit inside Pi, `pi-worktree out` + `git merge <name>` to land the work, `pi-worktree remove <name>` to clean up. New branches are created from `origin/main` (falling back to `main`, then `HEAD`), and the base commit is recorded in `branch.<name>.base` config so `info` can always tell you where the branch came from. Bash completion covers subcommands and existing worktree names (`pi-worktree feat<Tab>`).
60
+ Typical loop: `pi-worktree start <name>` to start (Tab completes existing worktree names), commit inside Pi, `pi-worktree out` + `git merge <name>` to land the work, `pi-worktree remove <name>` to clean up. New branches are created from the branch you're currently on (or `HEAD` when detached), and the base commit is recorded in `branch.<name>.base` config so `info` can always tell you where the branch came from. Bash completion covers subcommands and existing worktree names (`pi-worktree feat<Tab>`).
61
61
 
62
62
  The bundled `web-browser` skill provides reusable scripts for starting Chrome/Chromium with remote debugging, navigating tabs, evaluating JavaScript, emulating devices, taking screenshots, dismissing cookie dialogs, and inspecting browser logs. It auto-detects common Chrome/Chromium installations on macOS and Linux, including Windows Chrome when Pi runs under WSL; set `BROWSER_BIN` when the binary is elsewhere.
63
63
 
package/bin/pi-worktree CHANGED
@@ -3,6 +3,7 @@
3
3
  #
4
4
  # Usage:
5
5
  # pi-worktree start <name> [pi args...] # enter worktree <name> and start pi
6
+ # pi-worktree start --base <ref> <name> [pi args...] # branch from <ref> instead of current branch
6
7
  # pi-worktree -l | --list # list worktrees (main checkout marked "main checkout")
7
8
  # pi-worktree -i <name> # show base commit, ahead/behind, unique commits
8
9
  # pi-worktree -o | --out # cd back to the main checkout
@@ -39,17 +40,28 @@ in_linked_worktree() {
39
40
 
40
41
  wt_dir() { echo ".worktrees/$1"; }
41
42
 
42
- # Best available base ref: origin/main > main > HEAD
43
+ # Best available base ref: current branch > HEAD (worktrees should branch
44
+ # from where you actually are; a stale origin/main must not win)
43
45
  pick_base() {
44
- if git show-ref --verify --quiet refs/remotes/origin/main; then
45
- echo origin/main
46
- elif git show-ref --verify --quiet refs/heads/main; then
47
- echo main
46
+ local cur; cur=$(git branch --show-current 2>/dev/null || true)
47
+ if [[ -n "$cur" ]]; then
48
+ echo "$cur"
48
49
  else
49
50
  echo HEAD
50
51
  fi
51
52
  }
52
53
 
54
+ # Resolve base ref for a new worktree: explicit --base wins, else current branch.
55
+ resolve_base() {
56
+ if [[ -n "${BASE_OVERRIDE:-}" ]]; then
57
+ git rev-parse --verify --quiet "${BASE_OVERRIDE}^{commit}" >/dev/null \
58
+ || die "base ref not found: $BASE_OVERRIDE"
59
+ echo "$BASE_OVERRIDE"
60
+ else
61
+ pick_base
62
+ fi
63
+ }
64
+
53
65
  ensure_gitignore() {
54
66
  if ! git check-ignore -q .worktrees 2>/dev/null; then
55
67
  printf '.worktrees/\n' >> .gitignore
@@ -132,12 +144,31 @@ cmd_remove() {
132
144
  [[ -d "$dir" ]] || die "worktree not found: $dir"
133
145
  # refuse to remove if the branch is not merged into main
134
146
  local branch; branch=$(git -C "$dir" branch --show-current)
147
+ local rm_anyway=0
135
148
  if [[ -n "$branch" ]] && ! git merge-base --is-ancestor "$branch" main 2>/dev/null; then
136
149
  warn "branch '$branch' does not appear merged into 'main' (or no main branch exists)."
137
150
  read -rp "Remove anyway? [y/N] " ans
138
151
  [[ "$ans" =~ ^[Yy]$ ]] || die "aborted"
152
+ rm_anyway=1
139
153
  fi
140
154
  git worktree remove "$dir" && ok "removed: $dir"
155
+ # The branch survives `git worktree remove`; recreating the same name would
156
+ # silently reuse this stale branch. Delete merged branches automatically.
157
+ if [[ -n "$branch" ]] && git show-ref --verify --quiet "refs/heads/$branch"; then
158
+ if git branch -d "$branch" 2>/dev/null; then
159
+ ok "deleted merged branch: $branch"
160
+ elif [[ "$rm_anyway" == 1 ]]; then
161
+ git branch -D "$branch" && ok "deleted unmerged branch: $branch (confirmed above)"
162
+ else
163
+ warn "branch '$branch' has unmerged commits."
164
+ read -rp "Delete anyway? [y/N] " ans
165
+ if [[ "$ans" =~ ^[Yy]$ ]]; then
166
+ git branch -D "$branch" && ok "deleted branch: $branch"
167
+ else
168
+ warn "branch '$branch' kept; 'pi-worktree start $branch' will reuse it as-is"
169
+ fi
170
+ fi
171
+ fi
141
172
  }
142
173
 
143
174
  cd_wt() {
@@ -177,7 +208,7 @@ cd_wt() {
177
208
  [[ -n "$mb" ]] && git config "branch.$name.base" "$(git rev-parse --short "$mb")" \
178
209
  && git config "branch.$name.baseRef" main
179
210
  else
180
- local base; base=$(pick_base)
211
+ local base; base=$(resolve_base)
181
212
  git worktree add "$dir" -b "$name" "$base"
182
213
  git config "branch.$name.base" "$(git rev-parse --short "$base")"
183
214
  git config "branch.$name.baseRef" "$base"
@@ -197,6 +228,11 @@ case "${1:-}" in
197
228
  -p|--prune|prune) shift; subcmd_prune ;;
198
229
  -h|--help|help) sed -n '2,10p' "$0" | sed 's/^# \{0,1\}//' ;;
199
230
  start) shift
231
+ BASE_OVERRIDE=""
232
+ if [[ "${1:-}" == "--base" ]]; then
233
+ shift; [[ $# -ge 2 ]] || die "usage: pi-worktree start --base <ref> <name> [pi args...]"
234
+ BASE_OVERRIDE="$1"; shift
235
+ fi
200
236
  [[ $# -ge 1 ]] || die "usage: pi-worktree start <name> [pi args...]"
201
237
  name="$1"; shift; cd_wt "$name" "$@" ;;
202
238
  "") die "usage: pi-worktree start <name> [pi args...] (or list / info / out / remove / prune)" ;;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maxiaochao/pi-toolkit",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "Personal pi coding agent toolkit: /todos, /btw, /cache_export extensions, browser automation, and bundled theme/skills.",
5
5
  "type": "module",
6
6
  "keywords": [