# Context Standard: Context Bundles

## Overview
Context bundles are compressed snapshots of feature state for resuming long-running sessions without re-reading all files.

## What a Bundle Contains

```json
{
  "bundleId": "morph-next-gen-20260219-001",
  "feature": "morph-next-gen",
  "createdAt": "2026-02-19T00:00:00Z",
  "tokensEstimated": 14800,
  "compressionRatio": 0.12,

  "spec": {
    "problem": "1-2 sentence problem statement",
    "solution": "1-2 sentence solution approach",
    "keyRequirements": ["REQ1", "REQ2", "REQ3"],
    "dataModel": ["Entity1 (fields)", "Entity2 (fields)"]
  },

  "decisions": [
    { "id": "ADR-001", "summary": "Chose X over Y because Z", "fullPath": "decisions.md#adr-001" }
  ],

  "tasks": {
    "completed": ["T001", "T002", "T003"],
    "inProgress": "T004",
    "pending": ["T005", "T006"],
    "total": 10,
    "progress": "30%"
  },

  "checkpoints": [
    { "num": 1, "passed": true, "validatorsRun": ["architecture", "security"] }
  ],

  "agents": ["dotnet-senior", "ef-modeler"],

  "resumeHints": [
    "Currently implementing: T004 - Create UserService",
    "Last file modified: Services/UserService.cs",
    "Pending issue: DbContext injection pattern needs review"
  ]
}
```

## Creating and Using Bundles

### Create a Bundle (auto or manual)
```bash
# Auto-created on task completion (configured in llm-interaction.json)
# Manual creation:
morph-spec bundle create morph-next-gen

# Output:
# ✅ Bundle created: .morph/bundles/morph-next-gen-20260219-001.json
# Original context: ~180,000 tokens
# Bundle: ~15,000 tokens (compression: 92%)
```

### Load Bundle for Resume
```bash
# Load latest bundle for feature
morph-spec bundle load morph-next-gen

# Generates resume context to stdout:
# "You are resuming the morph-next-gen feature. Current phase: implement.
#  Last completed: T003. Next task: T004 (Create UserService)..."
```

### List Bundles
```bash
morph-spec bundle list morph-next-gen

# ID                              Created       Tokens  Compression
# morph-next-gen-20260219-001     2026-02-19    14,800  92%
# morph-next-gen-20260218-001     2026-02-18    12,400  94%
```

## Bundle vs Full Context

| Scenario | Use |
|----------|-----|
| Starting fresh implementation | Full spec + tasks + standards |
| Resuming mid-session | Bundle (loads in seconds) |
| Micro-agent handoff | Bundle with agent-specific slice |
| Cross-day resume | Bundle + load specific changed files |

## Auto-Bundle Configuration
```json
// .morph/config/llm-interaction.json
{
  "contextOptimization": {
    "bundles": {
      "enabled": true,
      "directory": ".morph/bundles/",
      "createOnTaskDone": true,
      "maxBundles": 10
    }
  }
}
```

## Bundle Lifecycle
- Created: on task completion (if auto-enabled)
- Retained: last 10 bundles per feature
- Invalidated: when spec.md is modified (decisions changed)
- Deleted: when feature is archived
