diff --git a/.console/log.md b/.console/log.md index 058399c..4b22c7d 100644 --- a/.console/log.md +++ b/.console/log.md @@ -1,5 +1,11 @@ # Log +## 2026-05-21 — Fix console-context block overwriting repo-owned CLAUDE.md content + +bootstrap.py rewrote CLAUDE.md from the open marker to EOF (DOTALL), nuking anything below +the OC block. Fix: add closing fence; regex now replaces only the +fenced region. All existing CLAUDE.md files migrated to add the closing fence. + ## 2026-05-21 — Add ContextLifecycleProtocol to platform group and git watcher Added contextlifecycleprotocol to platform.yaml group list. diff --git a/CLAUDE.md b/CLAUDE.md index 6315a3f..5498521 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -18,3 +18,4 @@ The context file contains your current task, guidelines, backlog, log, and runti After meaningful progress, update `.console/backlog.md` and `.console/log.md`. Do not edit `.console/.context` directly — it is regenerated at each launch. + diff --git a/src/operator_console/bootstrap.py b/src/operator_console/bootstrap.py index b97f1ce..4ef0a6c 100644 --- a/src/operator_console/bootstrap.py +++ b/src/operator_console/bootstrap.py @@ -315,7 +315,8 @@ def ensure_claude_md( extra_files: list[str] | None = None, ) -> None: claude_md = repo_root / "CLAUDE.md" - marker = "" + marker = "" + end_marker = "" extra_lines = "" if extra_files: @@ -345,15 +346,24 @@ def ensure_claude_md( After meaningful progress, update `.console/backlog.md` and `.console/log.md`. Do not edit `.console/.context` directly — it is regenerated at each launch. -""" +{end_marker}""" if claude_md.exists(): import re existing = claude_md.read_text(encoding="utf-8") - if marker in existing: - # Replace existing marked block + if marker in existing and end_marker in existing: + # Replace only the fenced managed block; preserve content outside it + new_text = re.sub( + r".*?", + block, + existing, + flags=re.DOTALL, + ) + claude_md.write_text(new_text.rstrip() + "\n", encoding="utf-8") + elif marker in existing: + # Old format without closing fence — replace to end of file, append tail if any new_text = re.sub( r".*", - block.strip(), + block, existing, flags=re.DOTALL, ) @@ -362,7 +372,7 @@ def ensure_claude_md( # Old format without marker — replace from that heading onward new_text = re.sub( r"## OperatorConsole Context.*", - block.strip(), + block, existing, flags=re.DOTALL, )