# Deviation Rules

> **Purpose:** Codify when generation can auto-fix issues vs. when it must flag for review.
> **Philosophy:** All deviations are handled through regeneration. Human intervention comes later during `/rewrite`.
> **Numeric values (word counts, etc.):** See `/CONSTANTS.md`

---

## Classification Matrix

| Issue Type | Severity | Action | Rationale |
|------------|----------|--------|-----------|
| Word count 450-500 (per CONSTANTS.md) | OK | Pass | Within range |
| Word count 501-530 | Minor | Auto-regenerate (1x) | Try once to trim |
| Word count >530 | Minor | Auto-regenerate (1x) | Try once to trim |
| Word count 501+ after 2 tries | Low | Flag + continue | Over is OK, review at rewrite |
| Word count <450 | Minor | Auto-regenerate (∞) | Keep trying until ≥450 |
| Dialogue 40-45% | Minor | Auto-trim | Convert dialogue to action |
| Dialogue >45% | Moderate | Auto-regenerate | Regenerate with dialogue cap reminder |
| Pattern 3x consecutive | Minor | Log warning | At limit, flag for next episode |
| Pattern 4x+ consecutive | Moderate | Auto-regenerate | Regenerate with pattern interrupt |
| Voice drift detected | Moderate | Auto-regenerate | Regenerate with character context reload |
| Character repetition | Minor | Auto-vary | Regenerate with different DNA element emphasis |

---

## Auto-Fix Protocols

### Word Count Over

**Philosophy:** Longer is better than shorter. Over-written episodes have more material to work with.

1. Log the deviation
2. Regenerate with: "Target 475 words. Trim action prose, not substance."
3. If 2nd attempt still over (501+):
   - Flag for review (content is there, may need manual trim)
   - Continue generation (don't block)
   - Review at rewrite phase

### Word Count Under

**Philosophy:** Under means missing content. Always regenerate until within range.

1. Log the deviation
2. Regenerate with: "Target 490 words. Add texture, sensory detail, character behavior."
3. If 2nd attempt still under:
   - Regenerate again with richer context from treatment
4. If 3rd attempt still under:
   - Regenerate with specific additions: "Expand ESCALATION section with [X]"
5. Keep regenerating until ≥450 (no flag, no skip)

### Dialogue Excess

1. Log the deviation
2. Regenerate with: "Dialogue maximum 35%. Convert expository dialogue to action."
3. If 2nd attempt fails, auto-trim dialogue to action prose

### Pattern Violation

1. Log the deviation
2. Regenerate with: "Previous 3 episodes used [type]. This episode MUST use [opposite]."
3. Specify exact hook/cliffhanger type in regeneration prompt

### Voice Drift

1. Log the deviation
2. Reload `characters.md` into context
3. Regenerate with specific character voice samples included
4. If 2nd attempt fails, flag for `/dramatic-qc --lens voice` review

### Character Repetition

1. Log the deviation (same DNA element used in consecutive episodes)
2. Regenerate with: "Previous episode showed [behavior]. This episode show [different behavior] instead."
3. Reference the Character Expression Variety table in CONSTANTS.md

---

## Severity Levels

| Level | Description | Blocking |
|-------|-------------|----------|
| OK | Within all constraints | No |
| Minor | Easily auto-fixed | No (after fix) |
| Moderate | Requires regeneration | No (after regeneration) |
| Major | Requires human review | No (flagged for review) |
| Critical | Structural failure | Yes (must fix before continuing) |

**Note:** No deviations block generation permanently. All issues are either auto-fixed or flagged for the `/rewrite` phase.

---

## Regeneration Limits

| Issue | Max Attempts | If Exceeded |
|-------|--------------|-------------|
| Word count over | 2 | Flag + continue |
| Word count under | ∞ (escalating strategy) | Keep trying — escalate context at attempts 2, 3, 4+ (see protocol below) |
| Dialogue excess | 2 | Auto-trim + continue |
| Pattern violation | 2 | Force pattern interrupt |
| Voice drift | 2 | Flag for QC review |
| Character repetition | 1 | Force different element |

---

## Logging

All deviations are logged to `state/deviation_log.json`:

```json
{
  "episode": 15,
  "batch": 3,
  "deviation_type": "word_count_over",
  "original_value": 537,
  "action_taken": "auto_regenerate",
  "attempts": 2,
  "final_value": 498,
  "resolved": true,
  "flagged_for_review": false
}
```

### Log Structure

```json
{
  "deviation_tracking": {
    "total": 0,
    "auto_fixed": 0,
    "flagged": 0,
    "history": []
  }
}
```

### Complete Entry Schema

Each entry in the `history` array must contain all of these fields:

```json
{
  "batch": 3,
  "episode": 15,
  "type": "word_count_over | word_count_under | dialogue_excess | pattern_violation | voice_drift | character_repetition",
  "details": "537 words, max 500",
  "original_value": 537,
  "action_taken": "auto_regenerate | auto_trim | flag_for_review | force_pattern_interrupt",
  "attempts": 2,
  "final_value": 498,
  "resolved": true,
  "severity": "minor | moderate | major | critical",
  "flagged_for_review": false,
  "resolution": null
}
```

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `batch` | int | Yes | Batch number (1-12) |
| `episode` | int | Yes | Episode number (1-60) |
| `type` | string | Yes | Deviation category (see Classification Matrix) |
| `details` | string | Yes | Human-readable description of the issue |
| `original_value` | number/string | Yes | The original metric value that triggered deviation |
| `action_taken` | string | Yes | What auto-fix protocol was applied |
| `attempts` | int | Yes | Number of regeneration attempts |
| `final_value` | number/string | Yes | The metric value after fix attempts |
| `resolved` | bool | Yes | Whether the issue was resolved within auto-fix limits |
| `severity` | string | Yes | `minor`, `moderate`, `major`, or `critical` |
| `flagged_for_review` | bool | Yes | Whether this needs human review during `/rewrite` |
| `resolution` | string/null | No | Human-provided resolution note (filled during `/rewrite`) |

---

## Integration Points

| Phase | How Deviation Rules Apply |
|-------|---------------------------|
| Generation | Auto-fix during episode creation |
| Checkpoint | Validate batch, log unresolved deviations |
| Assessment | `/assess` uses deviation history to prioritize fixes |
| Rewrite | `/rewrite` receives flagged deviations as input |

---

## Deviation Prevention

The best deviation is one that never happens. Before generating:

1. **Read treatment.md** — Know the target content
2. **Check pattern history** — Know what types were recently used
3. **Load characters.md** — Fresh voice patterns in context
4. **Review last 2 episodes** — Continuity and variety awareness

---

*This document is referenced by `/skills/orchestration_process/SKILL.md`.*
*Deviation tracking integrates with `state/current_state.json`.*
