Commit graph

2 commits

Author SHA1 Message Date
a18e6fe64a Milestone 2.1: Implement git_worktree_create tool (#4) (#17)
## Summary
Implements the `git_worktree_create` tool with full validation and error handling per issue #4 acceptance criteria.

## Changes
- New `pi-worktree-create.ts` module with pure, testable functions (no pi SDK deps)
- `validateCreateWorktreeInput()` — validates path and branch name parameters
- `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
- Integrated all helpers into `createCreateWorktreeTool()` in main extension
- 17 new tests covering all validation paths and edge cases (29 total, all passing)

## Testing
- [x] All 29 tests pass (`bun test .pi/extensions/*.test.ts`)
- [x] Full test suite run with no regressions
- [ ] Manual verification (requires pi runtime)

## Checklist
- [x] Self-reviewed the diff
- [x] Code follows project conventions
- [x] Descriptive naming (no single-character variables)
- [x] Documentation updated (JSDoc on all new functions)

Co-authored-by: David Kong <davkon@gmail.com>
Reviewed-on: #17
2026-07-24 20:50:45 +00: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