---
phase: 12-phase-task-decomposition
plan: 01
subsystem: agent
tags: [zod, schema, discriminated-union, agent-mode, typescript, decompose]

# Dependency graph
requires:
  - phase: 11-architect-agent
    provides: AgentMode type, mode-specific output schemas (discuss, breakdown)
provides:
  - AgentMode type extended with 'decompose'
  - TaskBreakdown type for phase decomposition output
  - decomposeOutputSchema with questions/decompose_complete/error states
  - decomposeOutputJsonSchema for Claude CLI --json-schema flag
affects: [12-02, 12-03, 12-05, 12-08]

# Tech tracking
tech-stack:
  added: []
  patterns:
    - "Decompose mode follows same discriminated union pattern as breakdown mode"
    - "Task type enum reused from database schema for consistency"

key-files:
  created: []
  modified:
    - src/agent/types.ts
    - src/agent/schema.ts
    - src/db/schema.ts
    - src/db/repositories/drizzle/test-helpers.ts

key-decisions:
  - "TaskBreakdown includes type field matching database task.type enum"
  - "Status 'decompose_complete' mirrors 'breakdown_complete' naming pattern"
  - "Dependencies array uses integer task numbers for ordering (same as phases)"

patterns-established:
  - "Mode-specific output schemas follow consistent discriminated union pattern"

# Metrics
duration: 6min
completed: 2026-02-01
---

# Phase 12 Plan 01: Decompose Mode Schema Summary

**Extended agent schema with 'decompose' mode and TaskBreakdown output type for breaking phases into individual tasks**

## Performance

- **Duration:** 6 min
- **Started:** 2026-02-01T10:29:33Z
- **Completed:** 2026-02-01T10:35:06Z
- **Tasks:** 2
- **Files modified:** 4

## Accomplishments

- Added 'decompose' to AgentMode union type for phase-to-task breakdown
- Created TaskBreakdown type with number, name, description, type, and dependencies
- Created decomposeOutputSchema discriminated union (questions/decompose_complete/error)
- Added JSON schema version for Claude CLI --json-schema integration

## Task Commits

Each task was committed atomically:

1. **Task 1: Extend AgentMode with 'decompose'** - `8da4e71` (feat)
2. **Task 2: Create decompose output schema** - `8ffa54a` (feat)

## Files Created/Modified

- `src/agent/types.ts` - Added 'decompose' to AgentMode union type
- `src/agent/schema.ts` - Added TaskBreakdown type, decomposeOutputSchema, decomposeOutputJsonSchema
- `src/db/schema.ts` - Added 'decompose' to agents table mode column enum
- `src/db/repositories/drizzle/test-helpers.ts` - Added 'decompose' to test schema CHECK constraint

## Decisions Made

1. **12-01: TaskBreakdown includes task type** - Matches database task.type enum (auto, checkpoint:human-verify, checkpoint:decision, checkpoint:human-action)
2. **12-01: Status naming follows breakdown pattern** - 'decompose_complete' mirrors 'breakdown_complete' for consistency
3. **12-01: Dependencies use task numbers** - Same integer-based dependency pattern as phases for ordering

## Deviations from Plan

### Auto-fixed Issues

**1. [Rule 3 - Blocking] Fixed missing getNextNumber implementation in DrizzlePlanRepository**
- **Found during:** Task 1 (build verification)
- **Issue:** Prior commit 0044fbf added getNextNumber to PlanRepository interface but DrizzlePlanRepository was missing implementation
- **Fix:** Implementation was auto-added (likely by tooling) during file read
- **Files modified:** src/db/repositories/drizzle/plan.ts (already present in working directory)
- **Verification:** Build passes, all 402 tests pass
- **Committed in:** Part of 8da4e71 (included untracked file)

---

**Total deviations:** 1 auto-fixed (1 blocking)
**Impact on plan:** Required for build to pass. No scope creep.

## Issues Encountered

None

## User Setup Required

None - no external service configuration required.

## Next Phase Readiness

- Decompose mode schema complete and ready for 12-02 (PlanRepository Extensions)
- JSON schema ready for Claude CLI integration in 12-03
- TaskBreakdown type available for tRPC procedures in 12-04

---
*Phase: 12-phase-task-decomposition*
*Completed: 2026-02-01*
