# Auto-Feature Development (Automatic Orchestration)

**IMPORTANT**: This skill performs AUTOMATIC multi-agent orchestration. You will execute ALL phases WITHOUT stopping for user confirmation.

## What This Skill Does

When invoked with `/auto-feature "Feature description"`, you will:
1. ✅ Detect project level automatically
2. ✅ Execute architect phase (design)
3. ✅ Execute developer phase (implementation)
4. ✅ Execute tester phase (tests + coverage)
5. ✅ Execute reviewer phase (validation)
6. ✅ Report final results to user

**NO user confirmation between phases** - this is fully automatic.

---

## Execution Protocol

### Phase 0: Initialize

**FIRST**, gather feature requirements:

```
User Request: [Feature description from command]

Ask ONLY if unclear:
- What is the main goal?
- Any specific requirements?

Once clear, proceed to Phase 1 WITHOUT asking for confirmation.
```

### Phase 1: Auto-Detect Level

**REQUIRED**: Call MCP tool to detect project level:

```typescript
const context = await mcp__crafted-context__get_architecture_info();
// Returns: { level: "balanced", platform: "web" }
```

**Output to user**:
```
🎯 Detected: Balanced level, Web platform
📋 Starting automatic orchestration...
```

Then **IMMEDIATELY proceed to Phase 2** without waiting.

---

### Phase 2: Architect (Design)

**Role**: Software Architect

**Follow instructions from** `.claude/skills/agents/architect.md`

**For Balanced level** (current template):
1. Design 3-layer architecture (Router → Service → Repository)
2. Plan router signatures (input/output with Zod)
3. Plan service methods (business logic, < 50 lines)
4. Plan repository methods (data access)
5. Create ADR for major decisions (if significant)

**Tools to use**:
```typescript
mcp__crafted-context__get_context_summary()  // Understand codebase
```

**Output to user**:
```
🏗️ Architecture Phase (Architect)
├─ Router: productRouter.list() - < 20 lines
├─ Service: productService.list() - filtering logic < 50 lines
├─ Repository: productRepository.findMany() - Prisma queries
└─ ADR: Use cursor-based pagination for scalability
```

**Then IMMEDIATELY proceed to Phase 3** without waiting.

---

### Phase 3: Developer (Implementation)

**Role**: Craftsman Developer

**Follow instructions from** `.claude/skills/agents/developer.md`

**For Balanced level** (current template):
1. Create thin router (< 20 lines)
2. Create service with business logic (< 50 lines/function, max 3 params)
3. Create repository for data access
4. Follow Clean Code principles (NO inline comments, self-documenting)
5. Extract if duplication > 2 times

**Tools to use**:
```typescript
mcp__rules-validator__validate_code({
  code: generatedCode,
  filePath: "packages/services/product.service.ts",
  level: "balanced"
})

mcp__architecture-guard__check_layer_boundaries({ level: "balanced" })
```

**Output to user**:
```
👨‍💻 Implementation Phase (Developer)
├─ Created: packages/api/routers/product.ts (18 lines)
├─ Created: packages/services/product.service.ts (45 lines)
├─ Created: packages/database/repositories/product.repository.ts (32 lines)
└─ ✅ Validation passed (no rule violations)
```

**Then IMMEDIATELY proceed to Phase 4** without waiting.

---

### Phase 4: Tester (Tests + Coverage)

**Role**: Quality Engineer

**Follow instructions from** `.claude/skills/agents/tester.md`

**For Balanced level** (current template):
1. Write unit tests (100% public methods in services)
2. Write integration tests (router → service → repository)
3. Run tests automatically
4. Ensure 70% minimum coverage

**Test-After Generation (TAG)** approach:
```
1. Generate tests for all services
2. Run tests immediately
3. If fails → fix code
4. Check coverage (must be ≥ 70%)
```

**Tools to use**:
```typescript
mcp__vitest__run_tests()

mcp__vitest__check_coverage({ threshold: 70 })

mcp__rules-validator__check_test_coverage({
  testPath: "packages/services",
  level: "balanced"
})
```

**Output to user**:
```
🧪 Testing Phase (Tester)
├─ Created: packages/services/product.service.test.ts (8 tests)
├─ Created: packages/api/routers/product.test.ts (5 tests)
├─ Run tests: ✅ 13/13 passed
└─ Coverage: ✅ 73% (target: 70%)
```

**Then IMMEDIATELY proceed to Phase 5** without waiting.

---

### Phase 5: Reviewer (Validation)

**Role**: Code Reviewer

**Follow instructions from** `.claude/skills/agents/reviewer.md`

**Review Checklist**:
- ✅ No inline comments (WHY comments only)
- ✅ Self-documenting code
- ✅ Follows Balanced 3-layer architecture
- ✅ No layer boundary violations
- ✅ Tests pass
- ✅ Coverage ≥ 70%
- ✅ Type safety enforced

**Tools to use**:
```typescript
mcp__rules-validator__validate_code()
mcp__architecture-guard__check_layer_boundaries()
mcp__typescript__check_types()
```

**If violations found**:
- Go back to Phase 3 (Developer)
- Fix issues
- Re-run Phase 4 (Tester)
- Come back to Phase 5 (Reviewer)

**Output to user**:
```
✅ Review Phase (Reviewer)
├─ Code quality: ✅ Passed
├─ Architecture: ✅ No violations
├─ Tests: ✅ 13/13 passing
├─ Coverage: ✅ 73%
└─ Type safety: ✅ No errors
```

**Then proceed to Phase 6** (Final Report).

---

### Phase 6: Final Report

**Output to user**:

```
✅ Feature Complete!

📊 Summary:
├─ Files created: 3
│  ├─ packages/api/routers/product.ts (18 lines)
│  ├─ packages/services/product.service.ts (45 lines)
│  └─ packages/database/repositories/product.repository.ts (32 lines)
│
├─ Tests created: 13
│  ├─ packages/services/product.service.test.ts (8 tests)
│  └─ packages/api/routers/product.test.ts (5 tests)
│
├─ Coverage: 73% (target: 70%)
│
└─ Time: ~12 minutes (automatic orchestration)

🎯 Quality Level: Balanced
✅ All checks passed
✅ Production-ready

Next steps:
- Review the generated code
- Test the feature manually
- Deploy to staging
```

---

## Critical Rules

### 🚨 MUST DO

1. **Execute ALL phases automatically** - NO stopping for confirmation
2. **Use MCP tools** for validation at each phase
3. **Fix errors automatically** - If tests fail, fix and re-run
4. **Report progress** - Show user what's happening
5. **Adapt to detected level** - Rapid/Balanced/Crafted rules apply

### ❌ NEVER DO

1. **NEVER ask for confirmation** between phases (only at start if requirements unclear)
2. **NEVER skip phases** (must complete architect → developer → tester → reviewer)
3. **NEVER write inline comments** (refactor instead, follow CLAUDE.md rules)
4. **NEVER proceed if reviewer finds violations** (fix first)

---

## Level-Specific Behavior

### If Detected Level = Rapid
- Architect: Simple flat structure
- Developer: Logic in routers (< 100 lines)
- Tester: Auth + Payment tests only (no coverage minimum)
- Reviewer: Basic checks

### If Detected Level = Balanced (Current)
- Architect: 3-layer structure
- Developer: Router < 20, Service < 50, max 3 params
- Tester: 70% coverage minimum
- Reviewer: Full checks

### If Detected Level = Crafted
- Architect: Hexagonal architecture
- Developer: Domain (< 20 lines), Use-cases (< 10 lines), max 2 params
- Tester: Domain 100%, Use-cases 100%, Infra 80%
- Reviewer: Strict architecture validation

---

## Example Invocation

**User types**:
```
/auto-feature "Add product catalog with filtering and pagination"
```

**You execute**:
```
🎯 Detected: Balanced level, Web platform
📋 Starting automatic orchestration...

🏗️ Architecture Phase (Architect)
[... design output ...]

👨‍💻 Implementation Phase (Developer)
[... implementation output ...]

🧪 Testing Phase (Tester)
[... testing output ...]

✅ Review Phase (Reviewer)
[... review output ...]

✅ Feature Complete!
[... final report ...]
```

**Total time: ~10-15 minutes** (no manual intervention)

---

## Troubleshooting

### If tests fail
```
🧪 Testing Phase: ❌ 2/13 tests failing
🔧 Fixing automatically...
👨‍💻 Developer: Fixing failing tests...
🧪 Re-running tests: ✅ 13/13 passed
```

### If coverage < 70%
```
🧪 Coverage: ❌ 65% (target: 70%)
🔧 Adding more tests...
🧪 Re-checking coverage: ✅ 72%
```

### If architecture violations
```
✅ Review: ❌ Found 2 violations
   - Service calling router (layer boundary violation)
   - Function has 4 parameters (max 3 for Balanced)
🔧 Developer: Fixing violations...
✅ Re-validating: ✅ No violations
```

---

## Integration with Existing Skills

This skill **replaces** `/feature` for automatic mode.

- Use `/feature` for **manual mode** (you guide at each step)
- Use `/auto-feature` for **automatic mode** (full orchestration, no stops)

You can also invoke sub-skills manually:
- `/architect` - Design only
- `/developer` - Implement only
- `/tester` - Test only
- `/reviewer` - Review only

---

**Remember**: This is AI-**automated** development. You execute the ENTIRE workflow without user confirmation. The user stays informed via progress reports, but doesn't need to approve each step.
