import os
root = r'C:\Users\decid\Documents\projects\spt-core\.worktrees\351-w5'


def edit(rel, pairs):
    p = os.path.join(root, rel)
    s = open(p, encoding='utf-8', newline='').read()
    N = '\r\n' if '\r\n' in s else '\n'
    for o, n in pairs:
        o = o.replace('\n', N)
        n = n.replace('\n', N)
        assert s.count(o) == 1, (rel, o[:60], s.count(o))
        s = s.replace(o, n)
    open(p, 'w', encoding='utf-8', newline='').write(s)


edit('docs-site/src/messaging/overview.md', [
    ('''- Attribute values are line-safe because the **encoder makes them so**, not by
  construction. A receiver-composed attribute can carry newlines — the
  `trust-warning` block runs to several — and the envelope is line-framed, so an
  unencoded newline would split one delivery into several lines of which most
  are not envelopes.''', '''- Attribute values are line-safe because the **encoder makes them so**, not by
  construction. An attribute value can carry newlines, and the envelope is
  line-framed, so an unencoded newline would split one delivery into several
  lines of which most are not envelopes.'''),
    ('''This is the **envelope author's own field** — like `type`, `from`, or an
alarm's times — not one of the receiver-composed attributes
([`trust-warning`, `mnemonics-json`](../networking/monics.md)) your node
strips off inbound bodies before attaching its own.''', '''This is the **envelope author's own field** — like `type`, `from`, or an
alarm's times — not one of the receiver-composed attributes
([`mnemonics-json`](../networking/monics.md), and the retired `trust-warning`)
your node strips off inbound bodies before attaching its own.'''),
    ('''**For adapter authors: this attribute must be surfaced** — the same obligation
`trust-warning` carries. A pipeline''', '''**For adapter authors: this attribute must be surfaced.** A pipeline'''),
    ('''  only closed list in this contract is the receiver-composed **strip** class
  (`trust-warning`, `mnemonics-json`), and it is a strip list, not a render
  list; everything else rides.''', '''  only closed list in this contract is the receiver-composed **strip** class
  (`mnemonics-json`, and `trust-warning`, which no node composes any more but
  which is still stripped so a sender cannot plant one), and it is a strip list,
  not a render list; everything else rides.'''),
])
edit('docs-site/src/networking/monics.md', [
    ('''always composed by spt. Override text is agent-behavior instruction delivered
under a reserved system author, which makes it a prompt-injection surface, and''', '''always composed by spt. Override text is agent-behavior instruction that spt
itself delivers, in your now-signal, which makes it a prompt-injection surface, and'''),
])
edit('docs-site/src/shells/frames.md', [
    ('''construction: a receiver-composed attribute can carry newlines (the
`trust-warning` block runs to several), and the frame is a single line, so an
unencoded newline would split one delivery into several.''', '''construction: an attribute value can carry newlines, and the frame is a single
line, so an unencoded newline would split one delivery into several.'''),
])
print('ok')
