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

<objective>
Add coordination domain events and CoordinationManager port interface.

Purpose: Establish the contract for merge coordination following hexagonal architecture patterns.
Output: Coordination types, CoordinationManager interface, and four merge lifecycle events.
</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 - git integration provides merge capability
@.planning/phases/03-git-integration/03-01-SUMMARY.md
@.planning/phases/03-git-integration/03-02-SUMMARY.md

# Existing patterns to follow
@src/events/types.ts
@src/dispatch/types.ts
@src/git/types.ts
</context>

<tasks>

<task type="auto">
  <name>Task 1: Add coordination domain events to event types</name>
  <files>src/events/types.ts, src/events/index.ts</files>
  <action>
Add four coordination events following existing event patterns:

1. MergeQueuedEvent - when a completed task is queued for merge
   - payload: { taskId, agentId, worktreeId, priority }

2. MergeStartedEvent - when merge attempt begins
   - payload: { taskId, agentId, worktreeId, targetBranch }

3. MergeCompletedEvent - when merge succeeds
   - payload: { taskId, agentId, worktreeId, targetBranch }

4. MergeConflictedEvent - when merge has conflicts (triggers bounce-back)
   - payload: { taskId, agentId, worktreeId, targetBranch, conflictingFiles: string[] }

Add all four to DomainEventMap union type. Export from index.ts.
  </action>
  <verify>npm run build passes, grep shows all four events in types.ts</verify>
  <done>Four merge events added to DomainEventMap, exported from events module</done>
</task>

<task type="auto">
  <name>Task 2: Create CoordinationManager port interface</name>
  <files>src/coordination/types.ts, src/coordination/index.ts</files>
  <action>
Create src/coordination/ module following same pattern as src/dispatch/:

**types.ts:**

1. MergeQueueItem type:
   - taskId: string
   - agentId: string
   - worktreeId: string
   - priority: 'low' | 'medium' | 'high'
   - queuedAt: Date
   - dependsOn: string[] (task IDs that must merge first)

2. MergeStatus type: 'queued' | 'in_progress' | 'merged' | 'conflict'

3. MergeResult type (mirrors git MergeResult but with task context):
   - taskId: string
   - success: boolean
   - conflicts?: string[]
   - message: string

4. CoordinationManager interface:
   - queueMerge(taskId: string): Promise<void>
     Queue a completed task for merge. Extracts agent/worktree from task.

   - getNextMergeable(): Promise<MergeQueueItem | null>
     Returns next task ready to merge (all dependencies already merged).

   - processMerges(targetBranch: string): Promise<MergeResult[]>
     Process all ready merges in dependency order. Returns results.

   - handleConflict(taskId: string, conflicts: string[]): Promise<void>
     Create conflict-resolution task and assign back to agent.

   - getQueueState(): Promise<{
       queued: MergeQueueItem[];
       inProgress: MergeQueueItem[];
       merged: string[]; // task IDs
       conflicted: Array<{ taskId: string; conflicts: string[] }>;
     }>

**index.ts:**
Export all types and interface.

Include JSDoc comments explaining the port-adapter pattern.
  </action>
  <verify>npm run build passes, src/coordination/index.ts exports CoordinationManager</verify>
  <done>CoordinationManager port interface created with full type definitions</done>
</task>

</tasks>

<verification>
Before declaring plan complete:
- [ ] npm run build succeeds
- [ ] Four merge events exist in src/events/types.ts
- [ ] CoordinationManager interface exists in src/coordination/types.ts
- [ ] All types exported from respective index.ts files
</verification>

<success_criteria>
- All tasks completed
- All verification checks pass
- No TypeScript errors
- Patterns match existing EventBus, DispatchManager, WorktreeManager
</success_criteria>

<output>
After completion, create `.planning/phases/06-coordination/06-01-SUMMARY.md`
</output>
