Commit graph

3 commits

Author SHA1 Message Date
David Kong
a7c08e1a49 fix: address all code review findings from issue-4-review.md
Critical fixes:
- Align create_branch schema description with runtime default (true)
- Add ^ and . to branch name start-of-name validation regex

Major fixes:
- Move dynamic import('node:fs/promises') to static top-level import
- Add integration tests for git_worktree_create execute flow
- Use WorktreeError + formatValidationError for current-branch error

Minor fixes:
- Replace fragile .toContain() assertions with specific strings
- Add 14 new tests for branch name start/end and dangerous char validation
- Document resolveWorktreeTarget as dead code until switch/remove tools ship

Suggestions implemented:
- Reject leading dot in branch names (git compliance)
- Extract formatSuccessResponse() helper for consistency
2026-07-25 06:42:05 +10:00
David Kong
5bc15a1e69 Milestone 2.1: Implement git_worktree_create tool (#4)
- Add pi-worktree-create.ts with pure validation/command-building functions
- validateCreateWorktreeInput: checks path and branch name validity
- validatePathDoesNotExist: refuses if target path exists (injectable for testing)
- isCurrentBranch: prevents creating worktree on current branch
- buildWorktreeAddCommand: builds correct git command with -b flag support
- Full error messages match issue acceptance criteria exactly
- 17 new tests covering all validation paths and edge cases
2026-07-24 23:18:54 +10:00
3d1b2f5443 Milestone 1.3: Implement git_worktree_list tool (#3) (#16)
## 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

Co-authored-by: David Kong <davkon@gmail.com>
Reviewed-on: #16
2026-07-24 13:11:08 +00:00