---
phase: 03-git-integration
plan: 01
type: execute
wave: 1
depends_on: []
files_modified: [src/events/types.ts, src/git/types.ts, src/git/index.ts]
autonomous: true
---

<objective>
Create git domain events and WorktreeManager port interface.

Purpose: Establish typed foundation for git worktree operations following hexagonal architecture.
Output: Git events added to event system, WorktreeManager port interface ready for adapter implementation.
</objective>

<execution_context>
@~/.claude/get-shit-done/workflows/execute-plan.md
@~/.claude/get-shit-done/templates/summary.md
</execution_context>

<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md

# Prior phase context - established patterns
@.planning/phases/02-data-layer/02-02-SUMMARY.md

# Existing event system to extend
@src/events/types.ts
@src/events/bus.ts
@src/events/index.ts
</context>

<tasks>

<task type="auto">
  <name>Task 1: Add git domain events to event types</name>
  <files>src/events/types.ts, src/events/index.ts</files>
  <action>
Add git worktree events following the established DomainEvent pattern:

1. In src/events/types.ts, add these typed event interfaces after the existing Log Events section:
   - WorktreeCreatedEvent (type: 'worktree:created', payload: { worktreeId, branch, path })
   - WorktreeRemovedEvent (type: 'worktree:removed', payload: { worktreeId, branch })
   - WorktreeMergedEvent (type: 'worktree:merged', payload: { worktreeId, sourceBranch, targetBranch })
   - WorktreeConflictEvent (type: 'worktree:conflict', payload: { worktreeId, sourceBranch, targetBranch, conflictingFiles })

2. Add all new events to the DomainEventMap union type

Follow the exact pattern of ProcessSpawnedEvent, ProcessStoppedEvent etc. - extends DomainEvent, specific type literal, typed payload.
  </action>
  <verify>npm run build passes with no TypeScript errors</verify>
  <done>Four git events defined and added to DomainEventMap union</done>
</task>

<task type="auto">
  <name>Task 2: Create WorktreeManager port interface</name>
  <files>src/git/types.ts, src/git/index.ts</files>
  <action>
Create new git module with port interface:

1. Create src/git/types.ts with:
   - Worktree type: { id: string, branch: string, path: string, isMainWorktree: boolean }
   - WorktreeDiff type: { files: Array<{ path: string, status: 'added' | 'modified' | 'deleted' }>, summary: string }
   - MergeResult type: { success: boolean, conflicts?: string[], message: string }
   - WorktreeManager interface (PORT) with methods:
     * create(id: string, branch: string, baseBranch?: string): Promise<Worktree>
     * remove(id: string): Promise<void>
     * list(): Promise<Worktree[]>
     * get(id: string): Promise<Worktree | null>
     * diff(id: string): Promise<WorktreeDiff>
     * merge(id: string, targetBranch: string): Promise<MergeResult>

2. Create src/git/index.ts that re-exports all types from types.ts

Follow the EventBus pattern - interface is the PORT, implementation will be the ADAPTER. Include JSDoc comments explaining the port-adapter relationship.
  </action>
  <verify>npm run build passes, new types are importable from src/git</verify>
  <done>WorktreeManager port interface defined with all method signatures for CRUD, diff, and merge operations</done>
</task>

</tasks>

<verification>
Before declaring plan complete:
- [ ] npm run build succeeds without errors
- [ ] Git events visible in DomainEventMap type
- [ ] WorktreeManager interface importable from src/git
- [ ] All types have proper JSDoc documentation
</verification>

<success_criteria>

- All tasks completed
- All verification checks pass
- No errors or warnings introduced
- Git events follow established DomainEvent pattern exactly
- WorktreeManager interface covers all 4 requirements (GIT-01 through GIT-04)
</success_criteria>

<output>
After completion, create `.planning/phases/03-git-integration/03-01-SUMMARY.md`
</output>
