Metadata-Version: 2.4
Name: medre-adapter-xmpp
Version: 0.2.0
Summary: XMPP direct chat and multi-user rooms for MEDRE
License-Expression: MIT
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: medre<0.3.0,>=0.2.0
Requires-Dist: slixmpp==1.17.0
Provides-Extra: test
Requires-Dist: pytest==9.2.0; extra == "test"
Requires-Dist: pytest-asyncio==1.5.0; extra == "test"
Requires-Dist: pytest-timeout==2.4.0; extra == "test"
Requires-Dist: jsonschema==4.26.0; extra == "test"
Dynamic: license-file

# MEDRE XMPP adapter

Bridge live text between configured XMPP contacts, multi-user rooms and other
[MEDRE](https://github.com/jeremiah-k/medre) transports. The adapter uses Slixmpp
for XMPP negotiation, authentication, TLS and MUC; MEDRE handles routing,
persistence, policy and delivery planning.

## Install

For a MEDRE installation managed by uv tools, install the provider explicitly:

```bash
uv tool install medre
medre adapters install xmpp
medre adapters check
```

Core 0.1.1 and later default fresh adapter requests to index packages.
Existing saved Git requests and catalogs retain their sources. On Windows,
run the printed uv installation command after MEDRE exits. No sibling
clones are required. To opt into Git development, a custom source catalog
can provide an `xmpp` alias (pin a full merged commit for reproducibility):

```yaml
adapters:
  xmpp: medre-adapter-xmpp @ git+https://github.com/jeremiah-k/medre-adapter-xmpp.git@main
```

Use `medre adapters install xmpp --sources /path/to/sources.yaml` with that catalog.
The catalog chooses package sources; runtime YAML contains connection settings.

## Configure

Create an account on an XMPP server with a publicly trusted TLS certificate and
join permissions for the selected rooms. Protect the runtime config as private.

`medre config native --transport xmpp --adapter-id chat` collects the connection
fields offline: the account JID, an optional password, the optional room
nickname, and optional host/port overrides. The form contacts no server, writes
a private YAML file only after the typed config validates, and stores an entered
password only in that file. Creating the TLS account, selecting rooms and peers,
and granting join permissions stay manual: the form references an existing
account and cannot provision one.

```yaml
adapters:
  xmpp:
    chat:
      adapter_kind: real
      jid: bridge@example.org/medre
      nickname: medre
      rooms: [bridge@conference.example.org]
      peers: [friend@example.org]
      origin_label: XMPP
      # password is supplied through the environment, not version control.
```

Set `MEDRE_ADAPTER__CHAT__PASSWORD` in the process environment through the secret
management mechanism used for the deployment; an environment override keeps
precedence over a password stored in the file. Both the account's
domain and configured conversations use prepared JIDs. Host and port overrides
are optional and must appear together; omit both to use DNS SRV discovery. The
connection requires verified TLS and offers no plaintext or certificate-check
bypass. Transport encryption is not end-to-end encryption.

Use `medre config bridge` to connect the instance to another configured adapter.
Use the room's bare JID as its context, or a configured peer's bare JID for a
direct conversation. `medre routes plan` previews the routes offline. The
adapter rejects destinations absent from `rooms` and `peers` and does not infer
rooms from server names. The source side of room messages identifies the actual
occupant (`room@service/nick`); direct messages use the contact's bare JID.

`medre config sample` includes SDK-free fake XMPP values after installation.
Fake smoke evidence exercises routing and rendering; it proves no server login
or native transport delivery.

## Behavior

- Relay text with MEDRE's shared attribution formatter. `relay_prefix`
  defaults to `[{origin_label}] {sender}:` followed by a space; an empty string suppresses it.
- Join every configured MUC room before readiness, request zero history, and
  rejoin after disconnect. Authentication rejection requires operator action.
- Exclude self echoes, delayed history, bodyless typing/receipt notifications,
  and unsupported edit/retract/reaction compatibility bodies.
- Bridge native replies with destination-scoped references and readable quote
  fallback; use textual relation fallback when the native target is unavailable.
- Preserve bounded XEP-0393 presentation and explicit unstyled content; retain
  plain text when semantic styles cannot be represented safely.
- Forward opt-in transient typing through XEP-0085, with negotiated direct
  peers and configured MUC rooms; activity stays outside message history.
- Bound pending inbound work and reject oversized output without silent clipping.
- Correlate own MUC echoes with trusted room-issued IDs, with bounded waits;
  missing correlation does not turn a completed transport write into a retry.
- Report local TLS transport writes separately from recipient delivery/read state.
- Record supplied native metadata honestly: the negotiated TLS state on the
  transport slot, the room's XEP-0421 occupant-id, and a bounded opted-in
  `public_facts` projection (message type, stanza-ID trust outcome) feeding
  core's bridge context. None of these imply end-to-end encryption or sender
  authority.

This live bridge does not recover offline messages or room archives. XHTML,
attachments, presence, read receipts, native mutations,
OMEMO and puppeting are not implemented or advertised. The
[protocol design](docs/protocol-design.md) explains the standards and seams for
those extensions. The [adapter contract](docs/spec/adapter.md) defines behavior;
[configuration](docs/schemas/config.schema.json) and
[native metadata](docs/schemas/native.schema.json) schemas publish the shapes.

## Develop and test

Keep the core checkout and provider checkout anywhere. From the core checkout:

```bash
uv sync --locked --extra dev
uv run --no-sync medre dev sync --sources /path/to/sources.yaml \
  --editable xmpp=/path/to/medre-adapter-xmpp xmpp
uv run --no-sync medre dev test --sources /path/to/sources.yaml \
  --editable xmpp=/path/to/medre-adapter-xmpp xmpp -- -q
```

The source catalog above adds the alias while the editable path selects the
actual checkout. Use `dev sync --sdk` to install native dependencies, then
the SDK-only selection in [contributing](CONTRIBUTING.md) for pinned SDK
contracts. Keep the same catalog and editable selection on both commands; a local `.medre-dev.yaml`
profile can remember them. No temporary core branch is recorded in package
requirements, lockfiles or CI variables.

For an existing Python environment, install the chosen core checkout and this
provider using that interpreter's pip interface. The deterministic suite needs
core's dev dependencies; the SDK tier additionally needs the pinned Slixmpp SDK.
CI checks core `main`, resolved once per run, on Python 3.11–3.14 with SDK-free
and native SDK jobs. Keep `MEDRE_CORE_REF` unset; `core_ref` is a one-run
qualification input, not a committed dependency.
An authenticated live-server test is separate from these offline checks.

### Opt-in native server proof

A two-account test verifies actual MUC ingress and direct egress. Use a dedicated
test server that permits temporary MUC creation. The test creates a uniquely
named room and destroys it in cleanup; it never configures an existing room.
Set `MEDRE_XMPP_TEST_CONFIG` to a private JSON file outside the checkout:

```json
{
  "bot_jid": "bot@example.org/medre",
  "bot_password": "REPLACE_IN_PRIVATE_FILE",
  "peer_jid": "peer@example.org/test",
  "peer_password": "REPLACE_IN_PRIVATE_FILE",
  "muc_domain": "conference.example.org"
}
```

Optional `host` and `port` entries override DNS discovery together. For a local
server using a dedicated test CA, `SSL_CERT_FILE` can select that trusted CA;
certificate validation and hostname checks stay enabled. Run the adapter suite
with `-m live` after installing its SDK. Credentials, private keys and runtime
state stay outside Git. The offline CI jobs do not start an authenticated server.

### Discovery cleanup

Stopping an XMPP connection cancels and awaits its pending entity-capability
lookups as well as session setup and outgoing filters. Capability discovery
remains enabled while connected; unanswered peer queries cannot retain
background callbacks after shutdown.

## Development tooling

See [contributing](CONTRIBUTING.md) for the shared Trunk quality gate and uv-based
editable development workflow.
