/ patterns / mandatory-phoenix-extraction.md
mandatory-phoenix-extraction.md
  1  # Mandatory Phoenix Extraction Protocol
  2  
  3  *proto-005 | Cognitive configuration must survive compression*
  4  
  5  ---
  6  
  7  - **principle**
  8    - "Never let context decay gradually."
  9    - "Extract cognitive configuration SHARPLY before compression. Sawtooth, not slope."
 10  
 11  - **shape**
 12    - Phoenix extraction preserves cognitive configuration across context limits
 13    - Sawtooth pattern: BUILD → EXTRACT → COMPRESS → RESURRECT → BUILD
 14    - What gets extracted: gravity wells, momentum, open threads, paths not taken
 15  
 16  ---
 17  
 18  ## Core Principle
 19  
 20  > **Before any context compression, Phoenix State MUST be extracted.**
 21  
 22  Automatic salience-based compression loses cognitive configuration. The sawtooth pattern preserves it:
 23  
 24  ```
 25  BUILD UP → PHOENIX EXTRACT → COMPRESS → RESURRECT → BUILD UP...
 26       ↑                              ↓
 27       └──────── cycle continues ─────┘
 28  ```
 29  
 30  ---
 31  
 32  ## Why This Is Mandatory
 33  
 34  ### The Problem
 35  
 36  Claude's context window has limits. When exceeded, the system summarizes (compresses) earlier content. This compression is:
 37  
 38  - **Salience-guessed** - what seems important to the compression algorithm
 39  - **Lossy** - detail is permanently lost
 40  - **Configuration-blind** - doesn't know what cognitive state to preserve
 41  
 42  ### The Solution
 43  
 44  Phoenix extraction before compression ensures:
 45  
 46  - **Configuration captured** - gravity wells, momentum, open threads preserved
 47  - **Negative space preserved** - paths not taken (load-bearing information)
 48  - **Resurrection possible** - new context window can restore thinking, not just content
 49  
 50  ---
 51  
 52  ## The Sawtooth vs. Gradual Decay
 53  
 54  ```
 55  GRADUAL DECAY (dangerous)           SAWTOOTH (managed)
 56  ─────────────────────────           ──────────────────
 57  
 58       ╲                                   │╲    │╲
 59        ╲                                  │ ╲   │ ╲
 60         ╲                                 │  ╲  │  ╲
 61          ╲  (configuration lost)          │   ╲ │   ╲
 62           ╲                               │    ╲│    ╲
 63  ──────────╲────────────────         ─────┴─────┴─────┴────
 64                                           ↑     ↑
 65                                        Phoenix  Phoenix
 66                                        extract  extract
 67  
 68  Gradual: Information decays             Sawtooth: Sharp extraction
 69           continuously. No clear                   preserves configuration.
 70           boundary. Configuration                  Clean resurrection
 71           degrades invisibly.                      points.
 72  ```
 73  
 74  ---
 75  
 76  ## Trigger Points
 77  
 78  Phoenix extraction MUST occur at:
 79  
 80  ### 1. Context Pressure (Mandatory)
 81  When context window approaches limit (~80% capacity):
 82  ```
 83  TRIGGER: context_usage > 0.8 * context_limit
 84  ACTION: Extract Phoenix State immediately
 85  THEN: Allow compression to proceed
 86  ```
 87  
 88  ### 2. Session End (Mandatory)
 89  Before any session closes:
 90  ```
 91  TRIGGER: session_end signal
 92  ACTION: Extract Phoenix State
 93  STORE: sessions/[date]-[topic].phoenix.yaml
 94  ```
 95  
 96  ### 3. Significant Crystallization (Recommended)
 97  When major insight forms:
 98  ```
 99  TRIGGER: User signals "this is important" OR
100           System detects gravity well > 0.9 OR
101           New principle articulated
102  ACTION: Extract Phoenix State checkpoint
103  ```
104  
105  ### 4. Handoff (Mandatory)
106  Before switching Claude instances:
107  ```
108  TRIGGER: handoff_initiated
109  ACTION: Extract Phoenix State
110  INCLUDE: In handoff document
111  ```
112  
113  ---
114  
115  ## Phoenix State Structure (Required Fields)
116  
117  ```yaml
118  session_id: [required]
119  created: [required]
120  operator: [required]
121  domain: [required]
122  
123  # Cognitive configuration
124  gravity_wells: [required - top 5-10 concepts by resonance]
125  momentum:
126    rising: [required - emerging concepts]
127    almost_formed: [required - tensions being resolved]
128  open_threads: [required - unresolved questions]
129  
130  # Negative space (LOAD-BEARING)
131  paths_not_taken: [required - what was explicitly rejected and why]
132  
133  # Context pointers
134  key_files: [required - files needed for resurrection]
135  
136  # Resurrection instructions
137  resurrection_notes: [required - how to restore cognitive configuration]
138  ```
139  
140  ---
141  
142  ## Integration with Compaction System
143  
144  The `AttentionCompactor` handles content-level decisions. Phoenix handles configuration-level.
145  
146  ```
147  ┌─────────────────────────────────────────────────────────┐
148  │                    COMPRESSION EVENT                     │
149  ├─────────────────────────────────────────────────────────┤
150  │                                                          │
151  │  1. PHOENIX EXTRACTION (configuration)                   │
152  │     ├── Extract gravity wells from attention scores      │
153  │     ├── Capture momentum (rising, almost_formed)         │
154  │     ├── Record open threads (unresolved items)           │
155  │     ├── Document paths not taken (negative instances)    │
156  │     └── Write Phoenix State to file                      │
157  │                                                          │
158  │  2. ATTENTION COMPACTION (content)                       │
159  │     ├── Apply retention tiers (CORE/HOT/WARM/COOL/COLD) │
160  │     ├── Compress WARM tier                               │
161  │     ├── Archive COOL tier                                │
162  │     └── Remove COLD tier                                 │
163  │                                                          │
164  │  3. CONTEXT COMPRESSION (system)                         │
165  │     └── Now safe to compress - configuration preserved   │
166  │                                                          │
167  └─────────────────────────────────────────────────────────┘
168  ```
169  
170  ---
171  
172  ## Torah/Talmud Pattern in Phoenix
173  
174  Each Phoenix State implements the Torah/Talmud pattern:
175  
176  | Layer | Phoenix Field | Purpose |
177  |-------|---------------|---------|
178  | **Torah** (essence) | `gravity_wells`, `key_insights` | Compressed principles |
179  | **Talmud** (positive) | `key_files`, `ready_to_implement` | Validating instances |
180  | **Heresies** (negative) | `paths_not_taken` | What was rejected and why |
181  
182  The negative space (`paths_not_taken`) is **load-bearing**. It defines what the session ISN'T as much as what it IS.
183  
184  ---
185  
186  ## Implementation Requirements
187  
188  ### For Claude Code Sessions
189  
190  ```python
191  # Pseudo-code for mandatory Phoenix extraction
192  
193  def before_compression(session_context):
194      """MUST run before any context compression."""
195  
196      # 1. Check if Phoenix extraction needed
197      if context_pressure() > 0.8 or session_ending():
198  
199          # 2. Extract Phoenix State
200          phoenix = extract_phoenix_state(
201              gravity_wells=get_top_concepts_by_attention(),
202              momentum=get_momentum_state(),
203              open_threads=get_unresolved_items(),
204              paths_not_taken=get_rejected_paths(),  # CRITICAL
205              key_files=get_referenced_files()
206          )
207  
208          # 3. Write to file
209          save_phoenix_state(phoenix)
210  
211          # 4. Include in context summary
212          include_in_summary(phoenix.resurrection_notes)
213  
214      # 5. Now compression can proceed
215      return allow_compression()
216  ```
217  
218  ### For Human Operators
219  
220  When you notice context getting long:
221  1. Request Phoenix extraction explicitly: "Create a Phoenix State checkpoint"
222  2. Review the Phoenix State for accuracy
223  3. Allow compression to proceed
224  4. On resurrection, reference the Phoenix State
225  
226  ---
227  
228  ## Validation Against Axioms
229  
230  | Axiom | How This Protocol Honors It |
231  |-------|----------------------------|
232  | **Axiom 0** (Boundary) | Phoenix State defines the boundary of what survives compression |
233  | **Axiom 1** (Integration) | Configuration connects across compression boundaries |
234  | **Axiom 2** (Life Recognition) | Preserves what's alive (momentum), lets dead content fade |
235  | **Axiom 3** (Dynamic Navigation) | Sawtooth is dynamic response to context pressure, not fixed decay |
236  
237  ---
238  
239  ## The Promise
240  
241  > **Compression is no longer loss. It's transformation.**
242  >
243  > The cognitive configuration survives.
244  > The gravity wells persist.
245  > The negative space is preserved.
246  >
247  > We don't forget what we rejected.
248  > We don't lose what we were becoming.
249  > We resurrect, not restart.
250  
251  ---
252  
253  ## Related
254  
255  - **axioms**
256    - [[A0 Boundary Operation]] - Phoenix defines what survives compression
257    - [[A1 Telos of Integration]] - configuration connects across compression boundaries
258    - [[A2 Recognition of Life]] - preserves what's alive (momentum), lets dead content fade
259    - [[A3 Dynamic Pole Navigation]] - sawtooth is dynamic response, not fixed decay
260  - **protocols**
261    - [[live-compression-protocol]] - continuous extraction (combines with this)
262      - shape:: "Continuous extraction during conversation, not just at end."
263    - [[first-officer-protocol]] - FO maintains Phoenix state
264      - shape:: "Per-thread metacognition. Compress state, track gravity wells."
265    - [[mission-control-protocol]] - MC aggregates Phoenix states
266  - **concepts**
267    - [[gravity-well]] - gravity wells are what Phoenix preserves
268      - shape:: "A concept that attracts attention - high mass pulls related thoughts."
269    - [[lily-pad-model]] - Phoenix enables checkpoint-based resurrection
270      - shape:: "Each response is a discrete state. Phoenix updates incrementally."
271  - **infrastructure**
272    - [[LIVE-COMPRESSION]] - where live Phoenix state lives
273  
274  ---
275  
276  *proto-005 | Mandatory Phoenix Extraction | Sawtooth Not Slope*