Skip to content

feat(penpal): add git worktree awareness#357

Merged
loganj merged 1 commit intomainfrom
worktree-federated-squishing-axolotl
Mar 6, 2026
Merged

feat(penpal): add git worktree awareness#357
loganj merged 1 commit intomainfrom
worktree-federated-squishing-axolotl

Conversation

@loganj
Copy link
Collaborator

@loganj loganj commented Mar 6, 2026

Penpal now understands git worktrees. Each worktree is treated as a scoped view with its own file listing, comments, and branch context.

Why

Penpal had no worktree awareness — files from the wrong worktree would leak into views, and comments left on worktree files would show up unpredictably across checkouts.

What changed

Worktree discovery: Projects are scanned for git worktrees on startup. Each worktree's name, path, and branch are exposed to the frontend.

Scoped files and comments: Navigating to a worktree shows only its files. Threads are stored in the worktree's own .penpal/ sidecar directory — comments in one worktree don't appear in another.

Navigation: Worktrees appear as sub-items in the sidebar and on workspace project cards. URLs use @worktree suffix encoding (e.g., /file/ws/repo@my-worktree/path/to/file).

MCP tools: All MCP tools (list_threads, create_thread, reply, etc.) now accept an optional worktree parameter so Claude agents can scope operations to the correct worktree.

Startup readiness: Added /api/ready endpoint that blocks until file scanning completes, fixing an intermittent startup race where the UI loaded before projects were discovered.

Testing

Added tests for worktree discovery, cache resolution, MCP tool scoping, HTTP API routing, and FilePage worktree switching.

@loganj loganj added the ai-outer-loop Managed by outer-loop label Mar 6, 2026
@loganj loganj force-pushed the worktree-federated-squishing-axolotl branch from 02c05e9 to a2736b0 Compare March 6, 2026 19:14
@loganj
Copy link
Collaborator Author

loganj commented Mar 6, 2026

@codex review

Comment posted automatically by outer-loop

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a2736b0715

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@loganj loganj force-pushed the worktree-federated-squishing-axolotl branch 3 times, most recently from b687b69 to b9126e9 Compare March 6, 2026 19:43
Discover git worktrees for each project and expose them throughout the
stack — backend discovery, cache, file scanning, comments, MCP tools,
and frontend UI.

Backend:
- Discover worktrees via `git worktree list --porcelain` during project scan
- Add worktree-scoped file scanning (ScanProjectSourcesForWorktree) that
  remaps both tree and files sources to worktree paths
- Scope comments/threads to worktrees via optional worktree parameter
- Handle worktree `.git` files (not directories) in git info resolution
- Add `/api/ready` endpoint so Tauri waits for full server initialization
  before loading the webview, fixing a startup race condition
- File watcher monitors worktree paths for changes

Frontend:
- Parse `@worktree` suffix in URLs for worktree-scoped navigation
- Sidebar shows worktree sub-items with stacked name + branch layout
- Project cards show worktree list with stacked presentation
- File and project pages pass worktree param to all API calls
- Comments panel scopes threads to active worktree

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@loganj loganj force-pushed the worktree-federated-squishing-axolotl branch from b9126e9 to c4269a2 Compare March 6, 2026 19:48
@loganj loganj marked this pull request as ready for review March 6, 2026 22:45
@loganj loganj merged commit e65e1ac into main Mar 6, 2026
4 checks passed
@loganj loganj deleted the worktree-federated-squishing-axolotl branch March 6, 2026 22:45
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c4269a218e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const { setSidebarExtra } = useOutletContext<LayoutContext>();
const qn = location.pathname.replace(/^\/project\//, '');
const qnRaw = location.pathname.replace(/^\/project\//, '');
const { project: qn, worktree } = parseProjectWorktree(qnRaw);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Parse project routes without splitting literal '@' names

This page now unconditionally calls parseProjectWorktree(qnRaw), so any project qualified name that legitimately contains @ (e.g. Team/foo@bar) is misparsed into project Team/foo + worktree bar, and all subsequent API calls (getProjectFiles, getReviews, links) target the wrong project/worktree. Fresh evidence versus the earlier fallback-only discussion: this commit made the parse call unconditional in ProjectPage, so the misparse can persist for normal navigation.

Useful? React with 👍 / 👎.

Comment on lines +131 to +135
for _, wt := range p.Worktrees {
if wt.IsMain {
continue
}
// Watch worktree source directories (thoughts/, etc.)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Watch each worktree root for newly created content

The worktree watch setup only adds watches for directories that already exist (AutoDetectDir, remapped RootPath, and .penpal/comments), but it never watches wt.Path itself; as a result, creating new top-level worktree content (for example the first .penpal/comments tree or root-level files from a files source) produces no fsnotify event to attach new watches, so files/comments SSE updates can silently stop until a restart/rescan.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-outer-loop Managed by outer-loop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant