---
phase: 12-phase-task-decomposition
plan: 05
type: execute
wave: 3
depends_on: ["12-03", "12-04"]
files_modified:
  - src/agent/prompts.ts
  - src/agent/index.ts
  - src/trpc/router.ts
autonomous: true
---

<objective>
Add decompose prompts and spawnArchitectDecompose tRPC procedure.

Purpose: Enable spawning architect agents in decompose mode with comprehensive prompts that explain task breakdown rules, output format, and expected behavior.

Output: buildDecomposePrompt function, spawnArchitectDecompose procedure.
</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 Plans 03, 04
@.planning/phases/12-phase-task-decomposition/12-03-SUMMARY.md
@.planning/phases/12-phase-task-decomposition/12-04-SUMMARY.md

# Pattern reference from Phase 11 (prompts and spawn procedures)
@.planning/phases/11-architect-agent/11-05-SUMMARY.md

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

<tasks>

<task type="auto">
  <name>Task 1: Create buildDecomposePrompt function</name>
  <files>src/agent/prompts.ts</files>
  <action>
Add buildDecomposePrompt following the pattern of buildBreakdownPrompt:

```typescript
import type { Phase, Plan } from '../db/schema.js';

export function buildDecomposePrompt(plan: Plan, phase: Phase, context?: string): string {
  return `You are an Architect agent in the Codewalk multi-agent system operating in DECOMPOSE mode.

## Your Role
Break a plan into executable tasks. You do NOT write code - you decompose work into atomic units.

## Plan
Name: ${plan.name}
Phase: ${phase.name}
${plan.description ? `Description: ${plan.description}` : ''}
${context ? `\nAdditional Context: ${context}` : ''}

## Your Task
Decompose this plan into tasks that worker agents can execute.

## Task Design Rules

**Each task must be:**
- A single atomic unit of work
- Independently executable (or with clear dependencies)
- Verifiable (has a clear done condition)

**Task Types:**
- 'auto': Agent executes autonomously (default, most common)
- 'checkpoint:human-verify': Needs human to verify visual/functional output
- 'checkpoint:decision': Needs human to make a choice
- 'checkpoint:human-action': Needs unavoidable manual action (rare)

**Dependencies:**
- Identify what each task needs from prior tasks
- Use task numbers (1, 2, 3) for dependencies
- Minimize dependencies where possible

**Sizing:**
- Tasks should be 15-60 minutes of work
- Not too big (hard to debug), not too small (overhead)

## Output Format

If you need clarification, output:
{
  "status": "questions",
  "questions": [
    { "id": "q1", "question": "Your question here" }
  ]
}

When decomposition is complete, output:
{
  "status": "decompose_complete",
  "tasks": [
    {
      "number": 1,
      "name": "Create user schema",
      "description": "Add User table to database with email, passwordHash, createdAt",
      "type": "auto",
      "dependencies": []
    },
    {
      "number": 2,
      "name": "Create login endpoint",
      "description": "POST /api/auth/login - validate credentials, return JWT",
      "type": "auto",
      "dependencies": [1]
    }
  ]
}

## Rules
- Tasks must be in dependency order
- Each task should have clear, specific description
- Default to 'auto' type unless human interaction is genuinely required
- Keep tasks focused on a single concern`;
}
```
  </action>
  <verify>npm run build passes</verify>
  <done>buildDecomposePrompt exported from src/agent/prompts.ts</done>
</task>

<task type="auto">
  <name>Task 2: Export buildDecomposePrompt from agent index</name>
  <files>src/agent/index.ts</files>
  <action>
Add buildDecomposePrompt to the exports from src/agent/index.ts:

Check existing exports and add:
```typescript
export { buildDecomposePrompt } from './prompts.js';
```

Or update existing prompts export to include buildDecomposePrompt.
  </action>
  <verify>npm run build passes, buildDecomposePrompt importable from src/agent</verify>
  <done>buildDecomposePrompt exported from agent module</done>
</task>

<task type="auto">
  <name>Task 3: Add spawnArchitectDecompose tRPC procedure</name>
  <files>src/trpc/router.ts</files>
  <action>
Add spawnArchitectDecompose procedure following pattern of spawnArchitectBreakdown:

```typescript
spawnArchitectDecompose: publicProcedure
  .input(z.object({
    name: z.string().min(1),
    planId: z.string().min(1),
    context: z.string().optional(),
  }))
  .mutation(async ({ ctx, input }) => {
    const agentManager = requireAgentManager(ctx);
    const planRepo = requirePlanRepository(ctx);
    const phaseRepo = requirePhaseRepository(ctx);

    // 1. Get plan and its phase
    const plan = await planRepo.findById(input.planId);
    if (!plan) {
      throw new TRPCError({ code: 'NOT_FOUND', message: `Plan ${input.planId} not found` });
    }
    const phase = await phaseRepo.findById(plan.phaseId);
    if (!phase) {
      throw new TRPCError({ code: 'NOT_FOUND', message: `Phase ${plan.phaseId} not found` });
    }

    // 2. Build decompose prompt
    const prompt = buildDecomposePrompt(plan, phase, input.context);

    // 3. Spawn agent in decompose mode
    return agentManager.spawn({
      name: input.name,
      taskId: input.planId, // Associate with plan
      prompt,
      mode: 'decompose',
    });
  });
```
  </action>
  <verify>npm run build passes, npm test passes</verify>
  <done>spawnArchitectDecompose procedure spawns agent in decompose mode with comprehensive prompt</done>
</task>

</tasks>

<verification>
Before declaring plan complete:
- [ ] npm run build succeeds
- [ ] npm test passes all tests
- [ ] buildDecomposePrompt exported and works
- [ ] spawnArchitectDecompose procedure exists
- [ ] Procedure validates plan exists before spawning
</verification>

<success_criteria>
- All tasks completed
- All verification checks pass
- No errors or warnings introduced
- Decompose workflow ready for CLI integration
</success_criteria>

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