---
phase: 12-phase-task-decomposition
plan: 02
type: execute
wave: 1
depends_on: []
files_modified:
  - src/db/repositories/plan-repository.ts
  - src/db/repositories/drizzle/drizzle-plan-repository.ts
  - src/db/repositories/index.ts
autonomous: true
---

<objective>
Extend PlanRepository with methods needed for task decomposition workflow.

Purpose: Enable creating plans from architect output and querying plans by phase. The decompose agent needs to know what plans exist in a phase to break them into tasks.

Output: PlanRepository with findByPhaseId, getNextNumber, bulk creation methods.
</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

# Pattern reference from Phase 11 (repository extensions)
@.planning/phases/11-architect-agent/11-02-SUMMARY.md

# Source files to modify
@src/db/repositories/plan-repository.ts
@src/db/repositories/drizzle/drizzle-plan-repository.ts
@src/db/repositories/phase-repository.ts
</context>

<tasks>

<task type="auto">
  <name>Task 1: Extend PlanRepository port interface</name>
  <files>src/db/repositories/plan-repository.ts</files>
  <action>
Add the following methods to PlanRepository interface (following pattern from PhaseRepository):

1. `findByPhaseId(phaseId: string): Promise<Plan[]>` - Get all plans for a phase, ordered by number
2. `getNextNumber(phaseId: string): Promise<number>` - Get next available plan number (MAX+1 or 1 if none)
  </action>
  <verify>npm run build passes (no implementation yet)</verify>
  <done>PlanRepository interface extended with new methods</done>
</task>

<task type="auto">
  <name>Task 2: Implement methods in DrizzlePlanRepository</name>
  <files>src/db/repositories/drizzle/drizzle-plan-repository.ts</files>
  <action>
Implement the new methods in DrizzlePlanRepository adapter:

1. `findByPhaseId(phaseId)`:
   - Query plans table where phase_id = phaseId
   - Order by number ascending
   - Return array (empty if none)

2. `getNextNumber(phaseId)`:
   - Query MAX(number) where phase_id = phaseId
   - Return max + 1, or 1 if no plans exist

Follow the pattern from DrizzlePhaseRepository.getNextNumber.
  </action>
  <verify>npm run build passes, npm test passes</verify>
  <done>DrizzlePlanRepository implements findByPhaseId and getNextNumber</done>
</task>

<task type="auto">
  <name>Task 3: Export types from repositories index</name>
  <files>src/db/repositories/index.ts</files>
  <action>
Verify PlanRepository and its types are properly exported. If not already exported:
- Export PlanRepository interface
- Export CreatePlanData type
- Export UpdatePlanData type

Check existing exports and add if missing.
  </action>
  <verify>npm run build passes, types importable from src/db/repositories</verify>
  <done>All PlanRepository types properly exported</done>
</task>

</tasks>

<verification>
Before declaring plan complete:
- [ ] npm run build succeeds
- [ ] npm test passes all tests
- [ ] PlanRepository.findByPhaseId exists and works
- [ ] PlanRepository.getNextNumber exists and works
- [ ] Types exported from index
</verification>

<success_criteria>
- All tasks completed
- All verification checks pass
- No errors or warnings introduced
- PlanRepository ready for tRPC procedures
</success_criteria>

<output>
After completion, create `.planning/phases/12-phase-task-decomposition/12-02-SUMMARY.md`
</output>
