Intelligently implement tasks from a tasks.md file with analysis, validation, and progress tracking.
Given the tasks document path as an argument (e.g., "specs/002-feature/tasks.md"), perform:
- Pre-implementation analysis to understand current state
- Smart task selection respecting dependencies and priorities
- Implementation with validation and quality gates
- Progress tracking with checkbox updates
- Post-implementation testing and verification
Inputs
- Required: path to
tasks.md - Optional:
- Task range or specific tasks (e.g., "T001-T010" or "T001,T005,T009")
- Phase filter (e.g., "Phase 3.2" or "Tests")
- Category filter for review tasks (e.g., "[Security]" or "[Critical]")
- Skip completed flag (--skip-completed, default: true)
- Dry run mode (--dry-run, show what would be done)
Early Gates (stop if any fail)
-
Tasks Document Gate
- Verify tasks.md exists and is valid
- Parse all tasks and their dependencies
- If invalid format, output Status: "Invalid Tasks Document". STOP.
-
Completion Audit Gate
- Run intent-based analysis on all tasks (per validate-tasks.md logic)
- Identify: β Complete, π‘ Partial, πΆ Stub, β Not Started
- Build implementation queue of incomplete tasks
- If all tasks complete, output Status: "All Tasks Complete". STOP.
-
Dependency Analysis Gate
- Map task dependencies from document structure and explicit notes
- Verify prerequisites are met for each task
- Order tasks respecting: Setup β Tests β Implementation β Integration β Polish
- If circular dependencies found, output Status: "Circular Dependencies". STOP.
-
TDD Compliance Gate
- For implementation tasks, verify corresponding tests exist and fail
- For test tasks, ensure they will run before implementation
- If TDD violated, output Status: "TDD Violation - Tests Must Fail First". STOP.
Pre-Implementation Analysis (for each task) Before starting any task, perform comprehensive analysis:
-
Current State Assessment:
- What already exists for this task?
- Is there partial implementation to build upon?
- Are there related files that provide patterns to follow?
- Check git history for previous attempts
-
Context Gathering:
- Load related design documents (plan.md, research.md, data-model.md)
- Identify patterns from similar completed tasks
- Check for code review feedback (T0XX tasks) affecting this task
- Review constitutional requirements applicable to this task
-
Implementation Planning:
- Determine exact files to create/modify
- Identify required imports and dependencies
- Plan test scenarios if implementing features
- Note integration points with existing code
Task Implementation Strategies
By Task Type:
Setup Tasks (package.json, configs):
- Check for existing config files to extend
- Use established patterns from project
- Validate against TypeScript/ESLint after creation
- Ensure all dependencies are properly versioned
Test Tasks (*.test.ts, *.test.tsx):
- MUST be written to fail initially (TDD)
- Include comprehensive test cases:
- Happy path scenarios
- Error conditions
- Edge cases
- Security validations if applicable
- Use existing test setup/utilities
- Ensure proper async handling
- Add meaningful assertions, not just existence checks
Implementation Tasks (features, services):
- Follow established patterns in codebase
- Include proper error handling
- Add structured logging with context
- Implement security checks (auth, validation)
- Use dependency injection via service locator
- Include TypeScript types/interfaces
- Add JSDoc comments for public APIs
Fix/Review Tasks ([Category] fixes):
- First understand the specific issue
- Locate exact code needing change
- Apply minimal fix that resolves issue
- Verify fix doesn't break existing functionality
- Add/update tests to prevent regression
- Update related documentation
Integration Tasks (middleware, routes):
- Ensure proper connection between layers
- Add request/response validation
- Include correlation ID propagation
- Implement proper error boundaries
- Add integration tests
Configuration Tasks:
- Use environment variables for secrets
- Provide sensible defaults
- Add validation for required settings
- Document all configuration options
Quality Gates (apply to each implementation)
-
Code Quality:
- Passes TypeScript compilation
- No ESLint errors
- Follows project conventions
- No console.log statements (use logger)
- No commented-out code
- No TODO/FIXME without ticket reference
-
Security:
- Input validation on all user data
- No hardcoded secrets
- Proper authentication checks
- SQL injection prevention (parameterized queries)
- XSS prevention (output encoding)
-
Testing:
- Unit tests for new functions
- Integration tests for endpoints
- Tests actually test functionality, not just run
- Error cases are tested
- Minimum 80% code coverage for new code
-
Constitutional Compliance:
- Library-first: Features as libraries with CLI
- TDD: Tests written and failing first
- Service Locator: No singletons
- Structured Logging: JSON format with context
- Repository Pattern: Database access abstracted
- SOC 2: Audit fields, logging, error handling
Implementation Workflow
For each task in the implementation queue:
-
Pre-Implementation:
π Task: T001 - Create monorepo structure π Analyzing current state... β Found partial implementation: package.json exists β οΈ Missing: pnpm-workspace.yaml, turbo.json π Loading patterns from completed tasks... π― Implementation plan ready -
Implementation:
π Implementing T001... β Created pnpm-workspace.yaml β Updated package.json with workspace config β Added required dependencies π§ͺ Running validation... -
Validation:
β TypeScript: No errors β ESLint: Passed β Tests: N/A (config file) β Integration: pnpm install successful -
Progress Update:
β T001 Complete - Updating tasks.md π Progress: 1/50 tasks complete (2%)
Progress Tracking
-
Update task checkboxes in real-time:
- Change
- [ ] T001to- [x] T001when complete - Add completion timestamp comment:
<!-- completed: 2024-01-15 14:30 -->
- Change
-
Maintain implementation log:
## Implementation Log - <YYYY-MM-DD HH:MM> ### Session Summary - Tasks Attempted: 10 - Tasks Completed: 8 - Tasks Failed: 2 (T045, T046 - missing dependencies) - Time Elapsed: 45 minutes ### Completed Tasks β T001: Monorepo structure (5 min) β T002: Root package.json (3 min) [...] ### Failed Tasks β T045: Missing Clerk SDK configuration β T046: Database connection not available ### Next Steps - Configure Clerk authentication - Set up database connection - Retry failed tasks
Error Handling
When implementation fails:
- Log detailed error with context
- Attempt automatic recovery if possible
- Mark task as π‘ Partial if some progress made
- Document blockers in implementation log
- Continue with non-dependent tasks
- Provide clear remediation steps
Post-Implementation Actions
After completing all possible tasks:
-
Run Test Suite:
pnpm test pnpm typecheck pnpm lint -
Generate Summary Report:
## Implementation Summary ### Statistics - Total Tasks: 50 - Completed: 35 (70%) - Partial: 5 (10%) - Blocked: 3 (6%) - Not Started: 7 (14%) ### Quality Metrics - Test Coverage: 85% - TypeScript Errors: 0 - ESLint Warnings: 3 - Build Status: β Passing ### Blockers - Missing external dependencies - Unclear requirements for T047 - Database setup required for T040-T043 -
Update Documentation:
- Update CLAUDE.md with new patterns
- Add implementation notes to relevant tasks
- Document any workarounds or decisions made
Output Format
- Summary: Implementation Complete | Partial Implementation | Blocked by Dependencies | Implementation Failed
- Progress: XX/XX tasks implemented (XX%)
- β Completed: [count]
- π‘ Partial: [count]
- πΆ Stub: [count]
- β Failed: [count]
- Quality Gates: TypeScript β | ESLint β | Tests β | Coverage XX%
- Session Metrics:
- Time: XX minutes
- Files Created: XX
- Files Modified: XX
- Lines Added: XXXX
- Blockers: [list any blocking issues]
- Next Steps: [recommended actions]
Important Notes
- Always run in project root unless otherwise specified
- Respect .gitignore patterns when creating files
- Use atomic commits with descriptive messages
- If uncertain about implementation, mark as π‘ Partial and document uncertainty
- Never skip tests unless explicitly directed
- Keep security and performance in mind for all implementations