Metadata-Version: 2.4
Name: medre-adapter-meshtastic
Version: 0.2.0
Summary: meshtastic 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.3.0,>=0.2.0
Requires-Dist: mtjk==2.7.11.post14
Requires-Dist: PyPubSub==4.0.7
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-meshtastic

**Meshtastic 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

Use [uv](https://docs.astral.sh/uv/getting-started/installation/) to install
MEDRE and this provider in the same persistent tool environment:

```bash
uv tool install medre
medre adapters install meshtastic
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.
Core 0.1.1 and later use package-index defaults for new adapter requests.
Existing saved Git requests and catalogs are preserved; Git is needed when
using those sources. For reproducible deployments, pin released versions in
a locked project or select exact Git revisions. 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.

## Packaging and provenance

This distribution registers the `medre.adapters` entry point and retains the
import namespace `medre.adapters.meshtastic`. 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 Meshtastic'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.meshtastic`                                 |
| Runtime wrapper | `medre.config.adapters.meshtastic_runtime.MeshtasticRuntimeConfig` |
| SDK-free fake   | `medre.adapters.fakes.meshtastic.FakeMeshtasticAdapter`            |

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 compatible released core, or the exact qualified
core revision for development and native qualification.
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.

## 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
tests through the locked uv core environment described in
[contributing](CONTRIBUTING.md). That workflow supports arbitrary core and
provider checkouts, including forks, without a separate manually configured
virtual environment. Select SDK, service, hardware, local integration and soak
tiers explicitly. Re-run the SDK-free sync before claiming an SDK-free proof.

## 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 the repository Actions variable
`MEDRE_CORE_REF` unset so pull-request checks retain that baseline. 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.

Python policy is declared in pyproject.toml. Local work and CI use the same
committed Trunk launcher and pinned tools for all-file checks, alongside the
fake/native qualification tiers.
The native adapter package includes its own `py.typed` marker.

## Outbound pacing

The default message_delay_seconds is 2.2 seconds, leaving a margin above
current firmware's two-second phone-originated text limit. Shorter configured
intervals can cause RATE_LIMIT_EXCEEDED even when the SDK returns a packet ID.
Use a lower interval only with separately qualified firmware. A local transport
handoff is not proof of RF reception; verify delivery on an independent node.
The firmware rule is implemented in
[PhoneAPI.cpp](https://github.com/meshtastic/firmware/blob/master/src/mesh/PhoneAPI.cpp).

## Default relay attribution

Matrix messages sent to Meshtastic default to `Alice[M]: message`, using the
first five display-name characters. The prefix shares the 227-byte UTF-8 budget
with the body. Other source platforms retain generic short-name attribution.
Set `relay_prefix: ""` to disable it or supply a custom generic template;
omitted/null selects the source-aware default.

Templates use generic variables such as `{sender}` and `{sender_short}`.
Because radio displays are constrained, the label variables `sender`,
`sender_short`, and `origin_label` also accept truncation suffixes:
`{sender3}` renders the first three Unicode code points of the sender
label (N must be at least 1). A numeric suffix on any other variable
passes through unchanged.

## Offline startup and recovery

An offline radio no longer holds up the runtime for the SDK's multi-minute
connection defaults. The existing sync_timeout_ms setting defaults to 30000:
MEDRE waits up to 30 seconds for that instance's initial connection, then starts
it degraded and proceeds with the remaining adapters. Each offline instance has
its own budget; startup still visits adapter instances in order.

Routes involving a started, degraded radio remain available. Recovery retains
one connection attempt at a time and retries with capped backoff until the radio
returns or MEDRE stops. Use `medre diagnostics --refresh-health` to inspect the
live connection state. A connection returning after shutdown is closed.

Set sync_timeout_ms on the Meshtastic instance to change the initial wait and
native SDK phase limits. It must be a positive integer in milliseconds. Invalid
configuration and missing dependencies still fail startup. The async deadline
does not forcibly terminate a blocking SDK thread; see the
[connection lifecycle contract](docs/spec/connection-lifecycle.md) for ownership
and shutdown limits. Native handoff still requires independent RF qualification.

## Development tooling

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