# Step 5: Execution Summary

## Objective

Generate a comprehensive summary of the epic execution, including statistics, any issues encountered, and next steps.

## Inputs

- `epic_id`: The executed epic
- Execution log from shell script
- All story files (with their final status)
- UAT document location

## Prompt Template

```
You are summarizing the execution of Epic: {epic_id}

## Execution Data

<execution_log>
{execution_log_contents}
</execution_log>

## Story Final States

{for each story}
<story id="{story_id}" status="{status}">
### Dev Agent Record
{dev_agent_record}

### Code Review Record  
{code_review_record}
</story>
{end for}

## Generate Execution Report

Create: `docs/sprints/epic-{epic_id}-execution.md`

```markdown
# Epic {epic_id} Execution Report

**Executed**: {timestamp}
**Duration**: {total_time}
**Mode**: Automated (BMAD epic-execute)

---

## Summary

| Metric | Value |
|--------|-------|
| Total Stories | {count} |
| Completed | {count} |
| Blocked | {count} |
| Failed | {count} |
| Total Commits | {count} |
| Lines Added | {count} |
| Lines Removed | {count} |
| Tests Added | {count} |

## Execution Timeline

| Time | Story | Phase | Result | Duration |
|------|-------|-------|--------|----------|
| {time} | story-1.1 | Dev | Complete | {duration} |
| {time} | story-1.1 | Review | Passed | {duration} |
| {time} | story-1.1 | Commit | Success | - |
| {time} | story-1.2 | Dev | Complete | {duration} |
| ... | ... | ... | ... | ... |

## Stories Completed

### story-{epic_id}.1 - {title}
- **Status**: Done ✓
- **Files Changed**: {count}
- **Tests Added**: {count}
- **Review**: Passed on first attempt

### story-{epic_id}.2 - {title}
- **Status**: Done ✓
- **Files Changed**: {count}
- **Tests Added**: {count}
- **Review**: Passed with fixes (minor style issues)

{continue for each story}

## Issues Encountered

### Resolved During Execution

| Story | Phase | Issue | Resolution |
|-------|-------|-------|------------|
| story-1.2 | Review | Missing input validation | Added validation, re-reviewed |
| story-1.4 | Dev | Test flakiness | Fixed timing issue |

### Unresolved (Requires Human Attention)

| Story | Phase | Issue | Impact |
|-------|-------|-------|--------|
| {story} | {phase} | {description} | {impact} |

## Code Quality Summary

### Patterns Used
- [Patterns established or followed during implementation]

### Technical Debt Introduced
- [Any shortcuts taken that should be addressed later]

### Recommendations
- [Suggestions for future development]

## Test Coverage

| Area | Before | After | Delta |
|------|--------|-------|-------|
| Statements | {%} | {%} | +{%} |
| Branches | {%} | {%} | +{%} |
| Functions | {%} | {%} | +{%} |
| Lines | {%} | {%} | +{%} |

## Deliverables

| Artifact | Location | Status |
|----------|----------|--------|
| Completed Stories | docs/stories/ | ✓ |
| Handoff Notes | docs/handoff/ | ✓ |
| UAT Document | docs/uat/epic-{epic_id}-uat.md | ✓ |
| This Report | docs/sprints/epic-{epic_id}-execution.md | ✓ |

## Next Steps

1. **Human Testing**: Execute UAT document at `docs/uat/epic-{epic_id}-uat.md`
2. **Address Issues**: {count} items need human review
3. **Merge**: Once UAT passes, merge to main branch
4. **Deploy**: Follow deployment checklist

---

## Git Log

```
{git log --oneline for this epic's commits}
```

---

*Generated by BMAD epic-execute workflow*
```

## Completion Signal

Output: `EPIC EXECUTION COMPLETE: {epic_id}`
```

## Orchestration Integration

This step can run in the same context as the shell script wrap-up, or as a final isolated context.

```bash
# Generate summary
claude -p "$(cat step-05-summary.md | envsubst)"

# Final output
echo ""
echo "=========================================="
echo "Epic $EPIC_ID execution complete"
echo "=========================================="
echo ""
echo "Deliverables:"
echo "  - Stories: docs/stories/"
echo "  - UAT: docs/uat/epic-${EPIC_ID}-uat.md"
echo "  - Report: docs/sprints/epic-${EPIC_ID}-execution.md"
echo ""
echo "Next: Run UAT with a human tester"
echo ""
```

## Cleanup

After summary generation:

1. Remove temporary handoff files (optional):
   ```bash
   rm -f docs/handoff/*-dev.md
   ```

2. Archive execution log:
   ```bash
   mv /tmp/epic-${EPIC_ID}-log.txt docs/sprints/
   ```

3. Update sprint status if applicable:
   ```bash
   # Mark stories as done in sprint tracker
   ```
