Skip to content

feat(penpal): live-detect worktree additions and removals#548

Draft
loganj wants to merge 2 commits intomainfrom
penpal-builderbot-worktree-dis
Draft

feat(penpal): live-detect worktree additions and removals#548
loganj wants to merge 2 commits intomainfrom
penpal-builderbot-worktree-dis

Conversation

@loganj
Copy link
Copy Markdown
Collaborator

@loganj loganj commented Mar 30, 2026

Summary

Previously, Penpal discovered git worktrees once at startup and never refreshed the list. If you ran git worktree add or git worktree remove while Penpal was running, the sidebar's worktree list went stale — showing deleted worktrees and missing new ones.

Now, Penpal watches each project's .git/worktrees/ directory for filesystem changes. When a worktree is added or removed, the worktree list updates automatically and the sidebar reflects the change within moments — no restart needed.

  • discovery/worktree.go — New GitWorktreesDir() resolves the .git/worktrees/ metadata directory via git rev-parse --git-common-dir, working for both main and linked worktrees
  • watcher/watcher.go — Base watches now include .git/worktrees/ dirs; events there trigger full re-discovery and an SSE broadcast so the frontend picks up the change
  • PRODUCT.md / ERD.md / TESTING.md — Added E-PENPAL-WORKTREE-WATCH requirement and updated P-PENPAL-WORKTREE to specify live updates

🤖 Generated with Claude Code

loganj and others added 2 commits March 30, 2026 00:23
Watch each project's .git/worktrees/ directory so that `git worktree
add` and `git worktree remove` are detected without restarting the
server. On change, full re-discovery runs and an SSE event pushes the
updated worktree list to the frontend.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Extract rediscoverProjects() helper to eliminate duplicated boilerplate
  across worktree, workspace, and source-detection event handlers
- Protect worktreeWatchDirs and gitDirWatches reads in handleEvent with
  focusMu to prevent concurrent map read/write panic
- Watch .git/ directory for projects without existing worktrees so the
  first `git worktree add` (which creates .git/worktrees/) is detected
- Add GitCommonDir() helper extracted from GitWorktreesDir()
- Add test for first-worktree creation detection via .git/ watch
- Update no-worktrees test to verify .git/ is watched

Co-Authored-By: Claude Opus 4.6 <[email protected]>
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.

1 participant