---
phase: 12-phase-task-decomposition
plan: 04
type: execute
wave: 2
depends_on: ["12-02"]
files_modified:
  - src/trpc/router.ts
  - src/trpc/context.ts
autonomous: true
---

<objective>
Add Plan and Task tRPC procedures for decomposition workflow.

Purpose: Enable CLI to create plans, create tasks from decomposition output, and query plans by phase. Completes the tRPC layer for the full hierarchy.

Output: Plan CRUD procedures, bulk task creation procedure (createTasksFromDecomposition).
</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

# Depends on Plan 02 for PlanRepository methods
@.planning/phases/12-phase-task-decomposition/12-02-SUMMARY.md

# Pattern reference from Phase 11 (tRPC procedures)
@.planning/phases/11-architect-agent/11-04-SUMMARY.md

# Source files
@src/trpc/router.ts
@src/trpc/context.ts
</context>

<tasks>

<task type="auto">
  <name>Task 1: Add PlanRepository to tRPC context</name>
  <files>src/trpc/context.ts</files>
  <action>
Add PlanRepository to tRPC context following existing pattern:

1. Import PlanRepository type from repositories
2. Add planRepository?: PlanRepository to Context type
3. Update createContext to include planRepository (optional, for backwards compatibility)
  </action>
  <verify>npm run build passes</verify>
  <done>PlanRepository available in tRPC context</done>
</task>

<task type="auto">
  <name>Task 2: Add Plan tRPC procedures</name>
  <files>src/trpc/router.ts</files>
  <action>
Add Plan CRUD procedures following Initiative/Phase pattern:

1. `createPlan` - Create a plan in a phase
   - Input: { phaseId, number?, name, description? }
   - If number not provided, use getNextNumber
   - Return created plan

2. `listPlans` - List plans for a phase
   - Input: { phaseId }
   - Return plans ordered by number

3. `getPlan` - Get a plan by ID
   - Input: { id }
   - Return plan or throw if not found

4. `updatePlan` - Update a plan
   - Input: { id, name?, description?, status? }
   - Return updated plan

Add requirePlanRepository helper following requireInitiativeRepository pattern.
  </action>
  <verify>npm run build passes</verify>
  <done>Plan CRUD procedures available via tRPC</done>
</task>

<task type="auto">
  <name>Task 3: Add createTasksFromDecomposition procedure</name>
  <files>src/trpc/router.ts</files>
  <action>
Add bulk task creation procedure for decompose output:

```typescript
createTasksFromDecomposition: publicProcedure
  .input(z.object({
    planId: z.string(),
    tasks: z.array(z.object({
      number: z.number().int().positive(),
      name: z.string(),
      description: z.string(),
      type: z.enum(['auto', 'checkpoint:human-verify', 'checkpoint:decision', 'checkpoint:human-action']).default('auto'),
      dependencies: z.array(z.number().int()).optional(),
    })),
  }))
  .mutation(async ({ ctx, input }) => {
    const taskRepo = requireTaskRepository(ctx);
    // Verify plan exists
    // Create tasks in order, map number to task ID for dependencies
    // Create task_dependencies after all tasks created
    // Return created tasks
  });
```

Handle dependency mapping: task numbers in input become task IDs via lookup map.
  </action>
  <verify>npm run build passes, npm test passes</verify>
  <done>createTasksFromDecomposition procedure creates tasks with dependencies from agent output</done>
</task>

</tasks>

<verification>
Before declaring plan complete:
- [ ] npm run build succeeds
- [ ] npm test passes all tests
- [ ] createPlan, listPlans, getPlan, updatePlan procedures exist
- [ ] createTasksFromDecomposition handles bulk task creation with dependencies
- [ ] PlanRepository in context
</verification>

<success_criteria>
- All tasks completed
- All verification checks pass
- No errors or warnings introduced
- Full Plan and Task tRPC layer ready for CLI
</success_criteria>

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