# PR-37 Delivery Planning — Reference

> Sprint Plan / Release Plan / Batch Plan / Capacity Plan / Roadmap Alignment

---

## Sprint Plan (Part F)

### Input

```js
generateSprintPlan({
  stories,        // SF-02 user stories
  dependencies,   // SF-02 dependency graph { nodes, edges }
  priorities,     // SF-02 priority entries [{ itemId, category, score }]
  config,         // { sprintDurationWeeks, teamVelocity, maxStoryPointsPerSprint }
})
```

### Output

```js
{
  sprints: [{
    sprintNumber: 1,
    sprintGoal: "Sprint 1: 浏览用户注册列表 / 查看用户注册详情 / ...",
    startDate: "Week 1",
    endDate: "Week 2",
    storyIds: ["us-1", "us-2", ...],
    totalStoryPoints: 20,
    epicIds: ["ep-1", "ep-2"],
    featureIds: ["ft-1", "ft-2", "ft-3"],
    criticalPath: ["us-1"],
    risks: []
  }, ...],
  metrics: {
    totalSprints: 6,
    totalPoints: 138,
    avgPointsPerSprint: 23,
    estimatedDurationWeeks: 12
  },
  unplannedStories: [],
  warnings: []
}
```

### Algorithm

1. Filter Must Have → Should Have → Could Have stories
2. Build dependency map from edges: `edge.from depends on edge.to`
3. Topological sort: Kahn's algorithm, deps come first
4. Assign to sprints by capacity (maxStoryPointsPerSprint / teamVelocity)
5. Dependency constraint: dependent story cannot be in earlier sprint than prerequisite

---

## Release Plan (Part G)

### Input

```js
generateReleasePlan({
  mvpScope,       // SF-02 MVP scope
  priorities,     // SF-02 priority entries
  dependencies,   // Dependency graph
  stories,        // User stories
  epics,          // Epics
  features,       // Features
})
```

### Output

```js
{
  releases: [
    {
      version: "1.0.0",
      name: "MVP — 最小可行产品",
      features: { epicCount: 2, epicNames: [...], featureCount: 2, featureNames: [...], storyCount: 10, storyPoints: 30 },
      description: "...",
      releaseGoals: "...",
      validationGates: ["All ACs pass", "Regression test pass", "Performance benchmark meet", "Security scan pass", "UAT sign-off"],
      dependencyCheck: { unresolvedIds: [], allResolved: true },
      releaseDate: "Week 8"
    },
    { version: "1.1.0", name: "MVP Polish", ... },
    { version: "2.0.0", name: "V1 — 第一完整版本", ... },
    { version: "3.0.0", name: "V2 — 功能增强版本", ... },
    { version: "4.0.0", name: "Global — 全球化版本", ... }
  ],
  warnings: []
}
```

---

## Batch Plan (Part H)

### Batch Types

| Batch Type | Description |
|------------|-------------|
| DevelopmentBatch L0 | 无依赖，可并行开发 |
| DevelopmentBatch L1 | 依赖 L0 完成 |
| DevelopmentBatch L2 | 依赖 L1 完成 |
| DevelopmentBatch L3+ | 深层依赖 |
| TestingBatch | 开发完成的进入测试 |
| ReleaseBatch | 测试通过的进入发布队列 |
| DeliveryBatch | 最终客户交付批次 |

### Output

```js
{
  batches: [{
    batchId: "batch-dev-l0-1",
    batchType: "DevelopmentBatch",
    name: "Development Level 0",
    storyIds: ["us-1", "us-7", "us-13", ...],
    featureIds: [...],
    epicIds: [...],
    parallelGroups: [["us-1", "us-7", "us-13"], ["us-19", "us-25"]],
    prerequisiteBatches: []
  }, ...]
}
```

---

## Capacity Plan (Part I)

### Configuration

```js
{
  teamSize: 5,           // 团队人数
  velocity: 20,           // 每 Sprint 完成点数
  availabilityFactor: 0.8, // 可用率（扣除会议/假期）
  complexityFactors: {
    high: 2.0,            // 高复杂度工作量倍率
    medium: 1.0,          // 中复杂度
    low: 0.5              // 低复杂度
  },
  riskBufferPercent: 20   // 风险缓冲百分比
}
```

### Output

```js
{
  totalEffort: 60,         // 复杂度调整后总工作量(pts)
  totalCapacity: 240,      // 团队总容量(pts)
  capacityUtilization: "25%",
  sprintBySprint: [{
    sprintNumber: 1,
    capacity: 16,
    allocated: 20,
    utilization: "125%",
    overCapacity: true
  }, ...],
  riskAdjustedEffort: 72,
  deliveryForecast: {
    optimistic: "Week 8 from project start",
    realistic: "Week 10 from project start",
    pessimistic: "Week 12 from project start"
  },
  resourceRecommendations: [
    "Sprint 1 is over capacity. Consider adding 1 team member or splitting stories."
  ],
  warnings: [...]
}
```

---

## Roadmap Alignment (Part J)

### Algorithm

1. **Phase Coverage**: 每个 Roadmap Phase 是否被 Release Plan 覆盖
2. **Story Coverage**: MVP/V1 Stories 是否被 Sprint Plan 完整分配
3. **Timeline Consistency**: Sprint 总周数是否在 Roadmap 时间范围内
4. **Budget Alignment**: Phase 预算与实际 Story Points × $/pt 是否一致（偏差 < 20%）
5. **Dependency Integrity**: Dev→Test→Release→Delivery 批次链是否完整

### Output

```js
{
  overallVerdict: "aligned",  // "aligned" / "partial" / "misaligned"
  alignmentScore: 85,         // 0-100
  phaseCoverage: { ... },
  storyCoverage: { ... },
  timelineCheck: { ... },
  budgetCheck: { ... },
  dependencyCheck: { ... },
  warnings: [...],
  recommendations: [...],
  summary: "## Roadmap Alignment: ALIGNED (85/100) ..."
}
```

---

## Factory Integration (Part K)

### Full Pipeline

```
SF-01 (Strategy) → SF-02 (Requirements) → PR-37 (Delivery Planning) → SF-03 (Design)
                          │                          │
                   ┌──────┘              ┌───────────┴────────────┐
                   │                     │                        │
              Domain Intelligence    Delivery Planning
                   │                     │
              ┌────┴─────┐       ┌───────┼───────┬──────────┐
         Classifier    Epics   Sprint  Release  Batch   Capacity → Align
              │          │      Plan    Plan    Plan      Plan      Report
              │     Features
         Validation  Validation
```

### API

```js
// Domain Intelligence
const di = createDomainIntelligenceFactory(
  { productName: "ERP系统" },
  { domainOverride: null, includeValidation: true }
);
// → { classification, epics, features, validation }

// Delivery Planning
const dp = createDeliveryPlanningFactory(
  sf02Output,  // upstreamArtifacts from SF-02
  { sprint: { teamVelocity: 20 }, capacity: { teamSize: 5 } }
);
// → { sprintPlan, releasePlan, batchPlan, capacityPlan, alignmentReport }
```
