"""Update plan.md to mark Task 1.1 as complete with commit SHA 5351389."""
from __future__ import annotations

import sys
from pathlib import Path

PLAN = Path("conductor/tracks/send_result_to_send_20260616/plan.md")
SHA = "5351389"

EDITS: list[tuple[str, str]] = [
 (
  "### Task 1.1: Rename `send_result` → `send` in `src/ai_client.py`\n\n- [ ] **Step 1: Snapshot the pre-rename state**",
  f"### Task 1.1: Rename `send_result` → `send` in `src/ai_client.py` [{SHA}]\n\n- [x] **Step 1: Snapshot the pre-rename state**",
 ),
 (
  "- [ ] **Step 2: Identify all 10 references in `src/ai_client.py`**",
  "- [x] **Step 2: Identify all 10 references in `src/ai_client.py`**",
 ),
 (
  "- [ ] **Step 3: Rename each reference**",
  "- [x] **Step 3: Rename each reference**",
 ),
 (
  "- [ ] **Step 4: Run the test suite — confirm the \"red\"**",
  "- [x] **Step 4: Run the test suite — confirm the \"red\"**",
 ),
 (
  "- [ ] **Step 5: Commit the red moment**",
  "- [x] **Step 5: Commit the red moment**",
 ),
 (
  "- [ ] **Step 6: Attach the git note**",
  "- [x] **Step 6: Attach the git note**",
 ),
]


def main() -> int:
 with PLAN.open("r", encoding="utf-8", newline="") as f:
  content = f.read()
 has_crlf = "\r\n" in content
 nl = "\r\n" if has_crlf else "\n"
 normalized = [(o.replace("\n", nl), n.replace("\n", nl)) for o, n in EDITS]
 new_content = content
 applied = 0
 for old, new in normalized:
  if old in new_content:
   new_content = new_content.replace(old, new, 1)
   applied += 1
  else:
   print(f"NOT FOUND: {old[:80]!r}", file=sys.stderr)
 if applied != len(EDITS):
  print(f"Only applied {applied}/{len(EDITS)} edits.", file=sys.stderr)
  return 1
 with PLAN.open("w", encoding="utf-8", newline="") as f:
  f.write(new_content)
 print(f"Applied {applied}/{len(EDITS)} edits. Line endings: {'CRLF' if has_crlf else 'LF'}")
 return 0


if __name__ == "__main__":
 raise SystemExit(main())
