import io
def edit(p, pairs):
    s=io.open(p,encoding='utf-8',newline='').read()
    nl='\r\n' if '\r\n' in s else '\n'
    for old,new in pairs:
        old=old.replace('\n',nl); new=new.replace('\n',nl)
        assert s.count(old)==1,(p,s.count(old),old[:80]); s=s.replace(old,new)
    io.open(p,'w',encoding='utf-8',newline='').write(s)
edit('docs/GOLDEN-CI.md',[
('''Thin `ci.yml` retains its main-branch run record, lint and traceability. Its
`changes` job keeps the existing `code` classifier and separately publishes
`run-unit`, defaulting to `true`. Only a `push` to `refs/heads/main` may set it
to `false`, through `.github/ci/push-main-unit-reuse.py`. PR classification and
manual dispatch are unchanged; this is not a release-name or golden-green
exemption.''',
'''Thin `ci.yml` retains its main-branch run record and traceability. Its
`changes` job publishes TWO outputs, and a push to main skips unit through
exactly one of two mechanisms:

- `code` (IR-147, [below](#push-main-docs-only-classification)): a docs-only
  push range sets it to `false`, which skips lint AND unit and needs no PR
  proof at all.
- `run-unit` (IR-144, this section): defaults to `true`. Only a `push` to
  `refs/heads/main` whose `code` is `true` may set it to `false`, through
  `.github/ci/push-main-unit-reuse.py` and exact-SHA PR proof. Lint still
  runs.

Manual dispatch is unchanged. Neither mechanism is a release-name or
golden-green exemption.'''),
('''IR-144 implementation is authored for HANDED-FILE, **acceptance pending the
first real post-merge run**. A qualifying push must show the exact PR proof
in changes, both unit legs skipped, and lint/traceability still executing;
an unproved SHA must still execute both unit legs. Fixture checks are not
field acceptance.''',
'''IR-144 implementation is authored for HANDED-FILE, **acceptance pending the
first real post-merge run**. A qualifying IR-144 push is a CODE push (`code`
true). It must show the exact PR proof in changes, both unit legs skipped,
and lint and traceability still executing. An unproved code SHA must still
execute both unit legs. A docs-only push (`code` false) is the OTHER class:
it carries no PR proof and skips lint too, by the IR-147 classifier, so it
is not evidence for or against IR-144. Fixture checks are not field
acceptance.'''),
])
edit('traceable-reqs.toml',[
('''# NOTE 2026-09-24: this entry's "superseded for main pushes by ADR-0050" clause is itself
# superseded for DOCS-ONLY pushes by REQ-CI-PUSH-DOCS-ONLY-THIN (IR-147, doyle ruling). The
# ruled text below is kept verbatim; read both.''',
'''# NOTE 2026-09-24 (IR-147): "thin" carries TWO senses across these entries. HERE, "Main
# pushes also run thin CI only" means ci.yml rather than golden (units still ran on every
# main push). In REQ-CI-PUSH-DOCS-ONLY-THIN, thin means lint+unit SKIPPED, and it now applies
# to docs-only main pushes too (doyle ruling). The ruled text below is kept verbatim; read both.'''),
('title = "IR-147 (doyle ruling 2026-09-24, fix candidate (a)): a push to main whose WHOLE push range github.event.before..github.sha is docs-only runs thin CI like a docs-only PR,',
 'title = "IR-147 (doyle ruling 2026-09-24, fix candidate (a)): a push to main whose WHOLE push range github.event.before..github.sha is docs-only SKIPS lint and unit (thin in the units-skipped sense, as a docs-only PR does; not merely ci.yml-rather-than-golden),'),
])
print('ok')
