Metadata-Version: 2.4
Name: medre-adapter-lxmf
Version: 0.1.0
Summary: lxmf transport adapter for MEDRE
License-Expression: MIT
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: medre<0.2.0,>=0.1.0
Requires-Dist: lxmf==1.3.0
Requires-Dist: rns==1.6.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"
Requires-Dist: packaging==26.3; extra == "test"
Dynamic: license-file

# medre-adapter-lxmf

**LXMF provider for MEDRE.** This separately installed distribution owns its
transport SDK, configuration, native codec and offline fake. MEDRE core owns
routing, storage, lifecycle and delivery evidence.

## Install from Git

Use [uv](https://docs.astral.sh/uv/getting-started/installation/) and Git. For
a first trial, MEDRE can manage this provider in its persistent tool environment:

```bash
uv tool install 'git+https://github.com/jeremiah-k/medre.git@main'
medre adapters install lxmf
medre adapters
```

On Windows, the package-changing command prints a uv command to run **after**
`medre.exe` exits, rather than replacing an executable still in use.
The `main` branch is useful for trials; pin exact core and adapter commits for
repeatable operation. Use the [MEDRE Getting Started guide](https://github.com/jeremiah-k/medre/blob/main/docs/ops/getting-started.md)
for fake smoke, guided route creation and native setup. Use the
[adapter-source guide](https://github.com/jeremiah-k/medre/blob/main/docs/ops/adapter-installation.md)
for a locked uv deployment project, private Git, local checkouts, index sources,
and the same-environment requirement. Neither MEDRE nor the provider installs
packages during runtime startup.

## Using an existing Reticulum setup

Reticulum is the shared network service; LXMF is the messaging protocol used by
applications such as Sideband and Reticulum MeshChat. MEDRE acts as its own LXMF
contact and exchanges ordinary text messages with those applications. A dedicated
Reticulum instance is optional. See the [Reticulum sharing guide](https://reticulum.network/manual/using.html).

Keep MEDRE's LXMF identity and storage profile separate from another chat app's
profile. Select the existing Reticulum configuration with `reticulum_config_dir`,
or leave it unset to use the SDK's normal configuration discovery. Leaving
`identity_path` unset lets MEDRE persist a dedicated identity in `storage_path`.
Applications can share the network service without sharing their private keys,
ratchets, or local message databases. Original relay senders are represented by
MEDRE's configured attribution text and metadata, rather than separate native
LXMF signing identities. Reply/thread relations use the text fallback described
below; app-specific attachments and reactions are separate capabilities.

An offline setup form collects these connection settings without starting a
runtime, importing the transport SDKs, or contacting the network:

```bash
medre config native --transport lxmf --adapter-id bot --output connection.yaml
```

The form writes a new private YAML file and collects configuration values only.
It references an existing Reticulum identity file by path and never provisions,
generates, or modifies identity material. Preparing that identity, configuring
Reticulum interfaces, and discovering peer destination hashes for route
contexts remain native, manual steps: use the
[Reticulum sharing guide](https://reticulum.network/manual/using.html) and the
announces of the peers to reach. Leaving the identity path blank keeps the
documented behavior above: the worker persists a dedicated identity in the
storage path on first start.

Stopped snapshots cover MEDRE's LXMF application identity, ratchets, router state,
and handoff journal. They do not capture or stop a shared Reticulum service or
other chat applications. Keep that network setup available, or restore it using
its own procedure. The [native-worker specification](docs/spec/native-worker.md#stopped-state-capture-scope)
describes the detailed capture boundary.

## Packaging and provenance

This distribution registers the `medre.adapters` entry point and retains the
import namespace `medre.adapters.lxmf`. Its original adapter source history
was extracted from MEDRE commit `e59c29dd31a95860d1cdbc19e531896616627a68`;
Git author and committer identities remain preserved. Runtime configuration and
adapter discovery do not depend on this repository's distribution name.

## Ownership and imports

This distribution owns LXMF's transport implementation, configuration models,
runtime wrapper, fake adapter, native addressing behavior, SDK requirements,
and protocol/SDK tests. MEDRE core owns generic events, routing, lifecycle,
storage, evidence, configuration orchestration, and installed-package discovery.

| Surface         | Adapter-owned import                                   |
| --------------- | ------------------------------------------------------ |
| Config models   | `medre.config.adapters.lxmf`                           |
| Runtime wrapper | `medre.config.adapters.lxmf_runtime.LxmfRuntimeConfig` |
| SDK-free fake   | `medre.adapters.fakes.lxmf.FakeLxmfAdapter`            |

Import the runtime wrapper from this distribution directly. Core has no named
wrapper compatibility bridge or transport SDK extras. The supported MEDRE
interface range and native SDK pins are declared in this project's
`pyproject.toml`; use a matching core revision during pre-release development.
Community adapter authors can use their own distribution names, import packages,
and hosting sources with the same `medre.adapters` entry-point contract.

MEDRE-authored adapter source is [MIT-licensed](LICENSE). This grant does
not relicense installed dependencies. Their license terms still apply to any
combined deployment or redistribution. See [dependency license notes](DEPENDENCY_LICENSES.md).

## Offline samples and diagnostics

This distribution contributes native fake values and an opaque conversation
address to `medre config sample`. Core includes only installed contributors;
a single contributor gets two fake instances for offline routing. Native
packet simulation methods remain adapter-specific. Run-session canonical
callback injection uses `AdapterContract.publish_inbound(event)`.

`medre adapters check --config bridge.yaml` distinguishes missing distributions
from broken/conflicting entry points. Basic CLI help and unrelated healthy
providers remain available when another provider fails discovery.

Replies and threads relay as inline fallback text. They do not emit native
reply/thread operations. Delivery evidence identifies `fallback_text`;
reactions, edits, and deletes remain unsupported and are suppressed.
Fake adapters expose the same planning capabilities as their health reports.

## Tests

Protocol and SDK contract tests live in this repository with adapter-owned
helpers. Cross-adapter routing and lifecycle tests remain in MEDRE. Run the
following from this repository in a fresh virtual environment, with a matching
MEDRE checkout at any location. Set `MEDRE_CORE` to that checkout path.

```bash
# SDK-free fake tier: core dev supplies test tooling; skip this adapter's SDK deps.
python -m pip install -e "${MEDRE_CORE:?Set MEDRE_CORE to the core checkout}[dev]"
python -m pip install --no-deps -e .
python -m pytest -q

# Native SDK tier: this distribution supplies its own SDK pins.
python -m pip install -e '.[test]'
python -m pytest -v -m "lxmf_sdk and not local_integration and not soak and not live and not hardware and not docker"
```

The default pytest selection excludes SDK, service, hardware, local integration,
and soak tiers. Installing SDKs afterward leaves the same environment SDK-enabled;
use a fresh environment for a new SDK-free proof.

Local endpoint integration is also owned here. After installing
the SDK tier, select it explicitly:

```bash
python -m pytest -v -m "local_integration and not soak and not live and not hardware and not docker"
```

The shared-Reticulum capture/restore campaign starts an independent service,
chat peer, and MEDRE worker. It carries both `lxmf_sdk` and `local_integration`
marks, so the SDK API-contract selection excludes it and the dedicated local
integration selection includes both restore directions. Standalone CI runs
local integration on Python 3.13 and 3.14, retaining the interpreter coverage
that exposed the restore timeout. Core's required local integration job also
runs the campaign against its pinned adapter revision.

Soak remains opt-in and separate from local integration.

## Fake smoke sources

The fake provides a synchronous `make_event(text=..., event_kind=...)` returning
a canonical event with its own adapter instance ID. After installing all
providers referenced by a fake bridge config, exercise a source with:

```bash
medre smoke --config bridge.yaml --source-adapter ADAPTER_ID --json
```

Use the configured instance ID, which may differ from the transport name. Each
normal smoke tests one source; inspect `source_candidates` and
`coverage_scope: single_source` in its report. Eligible sources must have started
and provide the helper. A pass requires delivery for every matched configured
route target, including targets unavailable after construction or startup.
Factory errors fail the smoke and trigger runtime cleanup. The result proves
fake direct-pipeline behavior; native callbacks and recipient delivery have
separate qualification tiers.

## Coordinated CI

The repository CI installs MEDRE core and this adapter. Its fake job omits
native SDK dependencies; its SDK job installs this distribution's declared pins.
CI resolves MEDRE `main` once per run by default. Keep `MEDRE_CORE_REF` unset;
qualify a candidate pair with a one-run dispatch and a full core commit SHA:

```bash
gh workflow run test.yml --ref ADAPTER_BRANCH -f core_ref=FULL_CORE_COMMIT_SHA
```

Record both revisions with the result. The candidate run does not replace the
adapter PR's checks against core `main`. Follow the
[coordinated-change policy](https://github.com/jeremiah-k/medre/blob/main/docs/dev/coordinated-changes.md)
for dependency order and merged compatibility pins.

Core's compatibility matrix tests each selected adapter at the exact commit
recorded in its manifest, along with cross-adapter behavior. In a coordinated
checkout containing the selected sibling repos, run from MEDRE:

```bash
python scripts/ci/adapter_matrix.py --check-local
# Once all adapter changes are committed:
python scripts/ci/adapter_matrix.py --sync-local
```

The helper validates clean sibling checkouts and their entry points, and compares
Python distribution names using normalized case/separator spelling. Synchronizing
updates the manifest atomically without fetching or installing packages. Review
the manifest diff, merge adapter commits into their default branches first, then publish
the core pin update and run `python scripts/ci/adapter_matrix.py --check-merged`. A failed write preserves the original manifest and cleans up the temporary
file. Deployment projects should separately lock their chosen complete
package graph.

Standalone CI records the exact core and adapter SHAs tested against its
configured core baseline. MEDRE core CI qualifies the pinned compatibility
pair; a standalone green result does not qualify another core revision.
SDK qualification extras come from the selected core compatibility manifest,
while SDK versions remain authoritative in this adapter's package metadata.

## Provider contract and quality

The [registration reference](https://github.com/jeremiah-k/medre/blob/main/docs/dev/adapter-registration.md)
documents every hook, its loading phase, and the minimal fake constructor/event
calls. Shared native-metadata helpers are public under `medre.adapters.metadata`.
Conformance tests use `medre.testing`; SDK pin checks read this distribution's
installed metadata while this repository chooses its SDK qualification extras.
The fake constructor and explicit-keyword event factory are checked in the
SDK-free tier. Native schemas and validated examples live in `docs/schemas` here.

This repository declares its own Ruff/Black policy. CI checks all Python source
and tests, plus commit whitespace, alongside the fake/native qualification tiers.
The native adapter package includes its own `py.typed` marker.

## Startup and shutdown ownership

Real Reticulum adapters run native SDK construction, queues and callbacks in an
owned worker process. A blocked constructor cannot block core startup or replace
MEDRE's host signal handlers. The parent retains canonical admission and exact
core delivery-attempt provenance; native terminal facts become ordinary
post-handoff observations. SDK-free fakes keep the local session.

Each worker exclusively leases its identity and queue storage. Omitting
identity_path generates a persistent identity under storage_path. Preserve that
private directory across restarts. The local handoff journal fences repeated
submission of the same core attempt; an uncertain native outcome requires
operator reconciliation and suppresses automatic retry. Handoff acceptance does
not establish recipient delivery. Worker loss does not invent terminal facts.

See the [native worker contract](docs/spec/native-worker.md) for cancellation,
queue bounds, environment inheritance, restart limits and qualification, and the
[runtime ownership contract](docs/spec/runtime-ownership.md) for SDK embedding.
