Milestone 1.3: Implement git_worktree_list tool (#3) #16

Merged
david merged 2 commits from issue-3 into main 2026-07-24 13:11:09 +00:00
Owner

Summary

Implement the git_worktree_list tool that parses git worktree list output into structured data with path, branch, commit hash, and current directory marker.

Changes

  • Implemented parseWorktreeList() helper to parse raw git worktree list output
    • Handles standard branches (e.g., [main])
    • Handles detached HEAD (marked as (detached))
    • Marks the current working directory with isCurrent: true
  • Wired parser into git_worktree_list tool execute function
  • Returns both formatted display text and structured details.worktrees array
  • Added error handling for non-git-repo directories
  • Restructured tool definitions inside extension factory to capture pi via closure

Testing

  • Parsing logic verified against real git worktree list output (3 worktrees)
  • Manual verification in pi TUI pending extension load test

Checklist

  • Self-reviewed the diff
  • Code follows project conventions (AGENTS.md, DESIGN.md, DOMAIN.md)
  • Descriptive naming (no single-character variables)
  • Error handling with clear messages and suggestions
## Summary Implement the `git_worktree_list` tool that parses `git worktree list` output into structured data with path, branch, commit hash, and current directory marker. ## Changes - Implemented `parseWorktreeList()` helper to parse raw `git worktree list` output - Handles standard branches (e.g., `[main]`) - Handles detached HEAD (marked as `(detached)`) - Marks the current working directory with `isCurrent: true` - Wired parser into `git_worktree_list` tool execute function - Returns both formatted display text and structured `details.worktrees` array - Added error handling for non-git-repo directories - Restructured tool definitions inside extension factory to capture `pi` via closure ## Testing - [x] Parsing logic verified against real `git worktree list` output (3 worktrees) - [ ] Manual verification in pi TUI pending extension load test ## Checklist - [x] Self-reviewed the diff - [x] Code follows project conventions (AGENTS.md, DESIGN.md, DOMAIN.md) - [x] Descriptive naming (no single-character variables) - [x] Error handling with clear messages and suggestions
david added 1 commit 2026-07-24 12:53:28 +00:00
- Implement parseWorktreeList() to parse /home/david/Projects/extensions/pi-worktrees         e597520 [issue-1-tmp]
/home/david/Projects/extensions/pi-worktrees/issue-3 dd2202f [issue-3]
/home/david/Projects/extensions/pi-worktrees/main    dd2202f [main] output
  into structured WorktreeEntry[] with path, commit, branch, isCurrent
- Handle detached HEAD (no brackets → '(detached)')
- Wire the parser into git_worktree_list execute function
- Return formatted display text + structured details for downstream use
- Move tool definitions inside extension factory to capture  closure
- Add error handling with clear message when not in a git repo
david added 1 commit 2026-07-24 13:09:22 +00:00
Critical fixes:
- Normalize path comparison with path.resolve() (Task 001)
- Add validation guards for malformed lines in parser (Task 002)

Major fixes:
- Extract tool definitions to factory functions (Task 003)
- Use WorktreeListResult interface with enriched metadata (Tasks 004, 010)
- Add unit tests for parseWorktreeList — 12 tests covering edge cases (Task 005)
- Return warning message when zero worktrees found (Task 006)

Minor fixes:
- Apply consistent JSDoc to all functions including factories (Task 007)
- Replace em-dash with ASCII separator for encoding safety (Task 008)
- Add section comments between tool factories and command registration (Task 009)

Suggestions implemented:
- Export parseWorktreeList in separate testable module (Task 011)
david merged commit 3d1b2f5443 into main 2026-07-24 13:11:09 +00:00
david deleted branch issue-3 2026-07-24 13:11:09 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: david/pi-worktrees#16
No description provided.