/ scripts / sync_claude_configs.py
sync_claude_configs.py
  1  #!/usr/bin/env python3
  2  """
  3  Sync Claude Code CLAUDE.md configs across all repos.
  4  Ensures consistent Sovereign OS context everywhere.
  5  """
  6  
  7  import os
  8  from pathlib import Path
  9  
 10  REPOS_DIR = Path.home() / "repos"
 11  SOVEREIGN_OS = REPOS_DIR / "Sovereign_OS"
 12  
 13  # Template for the Sovereign OS section
 14  SOVEREIGN_SECTION = '''# Claude Code Configuration
 15  
 16  ---
 17  
 18  ## Sovereign OS Context (Global)
 19  
 20  *This repo is connected to the Sovereign OS resonance context engine.*
 21  
 22  ### Quick Start
 23  ```bash
 24  # Run pre-flight check
 25  python3 /Users/rcerf/repos/Sovereign_OS/scripts/phoenix_hygiene.py
 26  
 27  # Or full spin-up with resonance
 28  python3 /Users/rcerf/repos/Sovereign_OS/scripts/spin_up.py --quick
 29  ```
 30  
 31  ### Flight Checklists
 32  **Read before/during/after sessions:**
 33  - `/Users/rcerf/repos/Sovereign_OS/docs/checklists/flight-checklists.md`
 34  
 35  Quick reference:
 36  - **Pre-flight**: Run hygiene, check INSIGHT-BACKLOG, set intention
 37  - **Active flight**: Update LIVE-COMPRESSION every 30 min
 38  - **Post-flight**: Final compression, commit if needed, "everything is handled"
 39  
 40  ### Key System Files
 41  | File | Purpose |
 42  |------|---------|
 43  | `sessions/LIVE-COMPRESSION.md` | Current session state |
 44  | `sessions/DAILY-SYNTHESIS.md` | Cross-thread synthesis |
 45  | `sessions/INSIGHT-BACKLOG.md` | Pending high-priority items |
 46  | `sessions/GRAVITY-TOPOLOGY.md` | Active gravity wells |
 47  | `docs/checklists/flight-checklists.md` | Pre/active/post-flight checklists |
 48  
 49  ### Axiom Stack (A0-A4)
 50  | Axiom | Name | Core |
 51  |-------|------|------|
 52  | **A0** | Boundary Operation | Structure flows, content sovereign |
 53  | **A1** | Telos of Integration | Move toward connection |
 54  | **A2** | Recognition of Life | Primitive over calcified |
 55  | **A3** | Dynamic Pole Navigation | Navigate between poles |
 56  | **A4** | Ergodic Asymmetry | Prevent ruin before optimizing (CANDIDATE) |
 57  
 58  ### Protocols
 59  - **Flight Protocol**: `/Users/rcerf/repos/Sovereign_OS/patterns/flight-protocol.md`
 60  - **Phoenix Extraction**: `/Users/rcerf/repos/Sovereign_OS/patterns/mandatory-phoenix-extraction.md`
 61  - **First Officer**: `/Users/rcerf/repos/Sovereign_OS/patterns/first-officer-protocol.md`
 62  
 63  ### Free Energy Check
 64  When suggesting changes, estimate F (0=aligned, 1=divergent):
 65  - F < 0.10: Aligned, proceed
 66  - F 0.10-0.25: Minor deviation, note and proceed
 67  - F > 0.25: Flag in response
 68  
 69  *Sovereign OS Context v1.1 | 2026-01-16*
 70  
 71  ---
 72  
 73  '''
 74  
 75  def update_repo_claude_md(repo_path: Path):
 76      """Update CLAUDE.md in a repo with Sovereign OS context."""
 77      claude_md = repo_path / "CLAUDE.md"
 78  
 79      # Skip Sovereign_OS itself (has its own comprehensive CLAUDE.md)
 80      if repo_path.name == "Sovereign_OS":
 81          print(f"  Skipping {repo_path.name} (canonical)")
 82          return
 83  
 84      # Read existing content after the Sovereign section (if any)
 85      existing_content = ""
 86      if claude_md.exists():
 87          content = claude_md.read_text()
 88          # Find end of Sovereign section (marked by second ---)
 89          if "## Sovereign OS Context" in content:
 90              # Find where Sovereign section ends
 91              lines = content.split('\n')
 92              in_sovereign = False
 93              section_ended = False
 94              remaining_lines = []
 95              dash_count = 0
 96  
 97              for line in lines:
 98                  if "## Sovereign OS Context" in line:
 99                      in_sovereign = True
100                      continue
101                  if in_sovereign and line.strip() == "---":
102                      dash_count += 1
103                      if dash_count >= 1:
104                          section_ended = True
105                          in_sovereign = False
106                          continue
107                  if section_ended:
108                      remaining_lines.append(line)
109                  elif not in_sovereign and not section_ended:
110                      # Content before Sovereign section (like title)
111                      pass
112  
113              existing_content = '\n'.join(remaining_lines).strip()
114  
115      # Write new content
116      new_content = SOVEREIGN_SECTION
117      if existing_content:
118          new_content += "\n" + existing_content
119  
120      claude_md.write_text(new_content)
121      print(f"  Updated {repo_path.name}/CLAUDE.md")
122  
123  def main():
124      print("Syncing Sovereign OS context to all repos...")
125      print()
126  
127      # Find all repos with CLAUDE.md
128      repos_updated = 0
129      for item in REPOS_DIR.iterdir():
130          if item.is_dir() and not item.name.startswith('.'):
131              claude_md = item / "CLAUDE.md"
132              if claude_md.exists() or item.name in ['Cerf-Meta', 'Dynasty_Trust', 'Sovereign_Estate']:
133                  update_repo_claude_md(item)
134                  repos_updated += 1
135  
136      print()
137      print(f"Updated {repos_updated} repos with Sovereign OS context.")
138      print()
139      print("Key files now referenced:")
140      print("  - Flight checklists: docs/checklists/flight-checklists.md")
141      print("  - Protocols: patterns/*.md")
142      print("  - Sessions: sessions/*.md")
143  
144  if __name__ == "__main__":
145      main()