def load(p):
    raw = open(p, encoding='utf-8', newline='').read()
    return raw.replace('\r\n', '\n'), '\r\n' in raw

def save(p, s, crlf):
    open(p, 'w', encoding='utf-8', newline='').write(s.replace('\n', '\r\n') if crlf else s)

def once(s, old, new):
    assert s.count(old) == 1, (old[:80], s.count(old))
    return s.replace(old, new)

p = 'crates/spt/src/cli.rs'
s, c = load(p)
s = once(s, '''    /// List registered adapters (active and soft-deregistered), each followed
    /// by its shipped + local profiles as composite options.
    List,''', '''    /// List installed adapters by type (harness, gateway, shell) with their
    /// versions and profiles, then the adapters subnet peers offer that this
    /// node does not have. --json also carries soft-deregistered adapters.
    // [impl->REQ-ADAPTER-LIST-SURFACE]
    List,''')
save(p, s, c)

p = 'docs-site/src/quickstart/adapter.md'
s, c = load(p)
s = once(s, '''$ spt adapter list
mock: Harness Copy active (from ./mock-adapter)
```''', '''$ spt adapter list
Types: HARNESS, GATEWAY, and SHELL

HARNESS
  mock v0.1.0
```

<!-- [doc->REQ-ADAPTER-LIST-SURFACE] -->
The list groups installed adapters by type: harness, then gateway (an adapter
whose `hostable_types` includes `"Gateway"`), then shell. Each row is the
adapter's name and version, marked `(built-in)` when its bytes came with an
spt-core release. Profiles nest under it: a shipped `:profile`, or
`:profile (custom)` for one you created locally. When subnet peers publish
adapters this node does not have, an **Available on subnet** section follows,
naming the peers that hold each one. Install from there with
`spt adapter add <name> --via-subnet`.''')
save(p, s, c)

p = 'docs-site/src/reference/json-shapes.md'
s, c = load(p)
s = once(s, '| `adapter list` | `{ adapters[] }` — each `{name, kind, mode, version, source_dir, active}` |',
         '| `adapter list` | `{ adapters[], available[] }` — each adapter `{name, kind, mode, version, source_dir, active, group, built_in, profiles[{name, custom}]}` (`group` is `harness`, `gateway` or `shell`); each available `{name, version, group, peers[]}`: adapters subnet peers publish that this node does not have <!-- [doc->REQ-ADAPTER-LIST-SURFACE] --> |')
save(p, s, c)
print('ok')
