import io

# ---------------------------------------------------------------- brief text (agent-facing)
bp = r"C:\Users\decid\Documents\projects\spt-claude-code\adapter\strings\briefs\live-ops.md"
b = io.open(bp, encoding="utf-8").read()
old = """  tracked mind asynchronously — fire-and-forget. Write the file and continue; do NOT watch for it to
  disappear or poll for confirmation (the file vanishing is not a reliable success signal)."""
assert b.count(old) == 1
new = """  tracked mind asynchronously — fire-and-forget. Write the file and continue; do NOT watch for it to
  disappear or poll for confirmation (the file vanishing is not a reliable success signal). **Any tool
  may write it** — Write, a Bash heredoc, whatever you have — the drop file is what counts, not how it
  got there."""
io.open(bp, "w", encoding="utf-8", newline="\n").write(b.replace(old, new))

# ---------------------------------------------------------------- manifest: version + history
mp = r"C:\Users\decid\Documents\projects\spt-claude-code\adapter\claude-spt.toml"
m = io.open(mp, encoding="utf-8").read()
assert m.count('version = "0.36.0"') == 1
history = """# 0.37.0 (2026-09-06): THE ACROSS-COMMUNE BOUNDARY NOW KEYS ON THE DROP, NOT ON THE TOOL.
# `is_commune_write` asked `tool == "Write" && file_path.ends_with("<id>-commune.md")`, so an agent
# writing its commune with Bash (heredoc, `cat >`), `Edit` or python got NO boundary at all — the
# commune ingested, the context rebuilt, and the session it was meant to end just kept running,
# silently, at both ends. Operator reports the Bash-authored write is now the common shape.
# spt-core's model was always the opposite: a commune is a FILE-DROP, "any harness that can write a
# file can commune", with `[session].commune_dir` the declared seam. The predicate now stats
# `<cwd>/.claude/<id>-commune.md` at the three hooks that already fire and already carry a cwd —
# PostToolUse (matcher stays Write, the fastest leg), PreToolUse (mid-turn, every other instrument)
# and Stop (backstop for a drop written by the turn's final tool call). No new hook registration, so
# no plugin republish and no extra per-tool-call spawn. REQ-COMMUNE-DROP-DETECT.
# The trigger thereby stops being an EVENT (one Write call, seen once) and becomes a STATE (a file
# that persists until core ingests it, >15s), so `state/commune-seen/<eid>.stamp` records the last
# EXAMINED identity: an unchanged drop is a stat, never a re-read, and one drop arms exactly once.
# REQ-HAZARD-COMMUNE-DROP-REARM, KNOWN-HAZARDS 9.1. The io funnel's COMMUNE kind is the right
# predicate and api.md names this construct as its motivating case, but it fires only once ingest
# completes, when no hook is running, and needs an authenticated poll no between-turns process can
# make (spt-bs-releases#275, filed NOT blocking). Floor unchanged 0.66.0. Skeleton unchanged 0.1.18
# — the revised commune brief ships in adapter.spt, not the cplugs skeleton.
version = "0.37.0\""""
m = m.replace('version = "0.36.0"', history, 1)
io.open(mp, "w", encoding="utf-8", newline="\n").write(m)

# ---------------------------------------------------------------- CHANGELOG (user-facing, UX only)
cp = r"C:\Users\decid\Documents\projects\spt-claude-code\CHANGELOG.md"
c = io.open(cp, encoding="utf-8").read()
anchor = "## [0.36.0] - 2026-08-29"
assert c.count(anchor) == 1
entry = """## [0.37.0] - 2026-09-06

> Requires spt-core **v0.66.0 or newer** (unchanged). Update with `spt adapter update claude-spt`. Plugin skeleton **0.1.18** (unchanged — no reinstall needed; the revised briefing text ships with the adapter).

### Fixed
- **A commune-across now resets your agent's context no matter how the commune file was written.** Previously the reset only fired when the file was written with the Write tool; an agent that wrote the same commune with a Bash heredoc, `cat`, `Edit` or a script got no reset at all — the commune was saved and the session simply carried on, with nothing to indicate the handoff had not happened. What matters now is the commune file itself, not the tool that produced it.
- If you have been working around this by re-writing a commune with Write to make the reset fire, you no longer need to.

### Changed
- The commune briefing your agent reads now says outright that any tool may write the file.

"""
c = c.replace(anchor, entry + anchor, 1)
io.open(cp, "w", encoding="utf-8", newline="\n").write(c)

# The 0.35.0 edit that ate a version heading is why this is checked rather than assumed.
import re

heads = re.findall(r"^## \[(\d+\.\d+\.\d+)\]", c, re.M)
assert heads[:3] == ["0.37.0", "0.36.0", "0.35.0"], heads[:5]
print("ok, headings intact:", heads[:4])
