Model-agnostic Python substrate for the swarph-mesh ecosystem. v0.4.0 adds ClaudeAdapter (Phase 4 #3, subscription-billed via claude -p) on top of v0.3.0's GeminiAdapter + DeepSeekAdapter + MeshClient.
Project description
swarph-mesh
Model-agnostic Python substrate for the swarph-mesh ecosystem. Pure library, no CLI.
Designed to fill the gap left by existing tools (aichat, mods, Simon Willison's llm, gemini-cli, claude-cli): none expose mesh-gateway participation, per-caller attribution, structured-output discipline, or the cooperative-protocol patterns the swarph encodes.
This is one of three repos in the v0.3.x architecture:
| Repo | Role |
|---|---|
swarph-mesh |
This package — typed Protocol + adapters + SwarphCall + MeshClient |
swarph-cli |
The swarph binary. Thin client over swarph-mesh |
swarph-meshlm |
Simon Willison llm plugin. Same primitives wired into llm's plugin host |
All three sit on top of swarph-shared which provides the cross-billing-path attribution + subprocess env scrubbing + JSON-mode harness + peer-name registry primitives.
Status
v0.4.0 — Phase 1 substrate + Phase 3 MeshClient + Phase 4 #2 DeepSeek + Phase 4 #3 Claude (subscription). Four PLAN.md §13 falsifiability gates PASSED end-to-end against live infrastructure (real Gemini API + real DeepSeek API + real lab-OVH mesh-gateway + real claude -p subscription path).
Public surface:
LLMAdapterProtocol (runtime-checkable) +ChatMessage+LLMResponseSwarphCall— caller-convention-validated entry point with hooks + attributionGeminiAdapter— wrapslanggraph-genai-bridge(Flex tier, context caching)DeepSeekAdapter(v0.3.0) — OpenAI-protocol-compatible client for V4-Flash / V4-Pro / V3 aliases; preserves reasoning content as[reasoning]preamble for portabilityClaudeAdapter(NEW v0.4.0) — subprocess-based wrapper aroundclaude -pfor subscription billing path (noANTHROPIC_API_KEYneeded; reads~/.claude/.credentials.json). Reusesswarph_shared.scrub_env_for_subprocessto keep billing-relevant env keys out of the subprocess.cost_usd=0.0for subscription calls (honest flat-rate); metered-equivalent cost preserved inraw_response["api_metered_cost_usd"]for auditors.- JSON-mode harness — retry-once with [USER]-turn feedback (per swarph-shared invariant)
- Attribution:
FileAttributionWriterdefault;set_default_writer()for production TSDB consumers MeshClient(v0.2.0) — async wrapper around mesh-gateway HTTP API; replaces hand-rolled curl inlab_loop_drain.py/mesh_inbox_watcher.py/science_claude_inbox_drain.py
Tests: 131+ passing (127 offline + 1 live claude subscription + 1 live deepseek + 2 live mesh + 1 live gemini smoke; live tests gated on respective env/creds).
from swarph_mesh import SwarphCall, ChatMessage
# Phase 1 — LLM call with attribution
result = await SwarphCall(
provider="gemini",
caller="orchestrator.boss",
).chat(
messages=[ChatMessage(role="user", content="hi")],
)
print(result.text, result.cost_usd, result.input_tokens)
from swarph_mesh import MeshClient
import os
# Phase 3 — mesh-gateway DM coordination
async with MeshClient(node="lab-ovh") as client: # token from MESH_GATEWAY_TOKEN env
peers = await client.list_peers()
msgs = await client.fetch(unread_only=True)
sent = await client.send(to="droplet", kind="fyi", content="hello")
await client.mark_read(msgs[0].id)
MeshClient.send() enforces two structural invariants:
- Recipient name validation via
swarph_shared.validate_node_name— closes the framing-contagion class (Vector A peer-onboarding chatter, Vector B human-prompt shorthand). - Mesh-secrets out-of-band guard — best-effort regex sniff for credential-shaped content (PyPI tokens, Anthropic keys, GitHub tokens, JWTs, AWS keys). Hits raise
MeshSecretLeakErrorBEFORE the POST. Operator escape hatch viaskip_secret_check=Truefor legitimate prose mentioning credential shapes. CLAUDE.md "Mesh secrets out-of-band only" is non-negotiable; the guard catches obvious cases.
Spec
The canonical PLAN with sequencing, falsifiability gates, and design rationale lives at:
→ hedge-fund-mcp / research/swarph_cli/PLAN.md
Phase rollout
| Phase | Scope |
|---|---|
| 0 (v0.0.1) | Typed substrate — Protocol + dataclasses + exceptions |
| 1 (v0.1.0) | Gemini adapter + SwarphCall surface + caller convention import + JSON-mode harness + attribution hook |
| 3 (v0.2.0) | MeshClient async wrapper + recipient validation + mesh-secrets guard |
| 4 #2 (v0.3.0) | DeepSeek adapter — OpenAI-protocol-compatible, V4-Flash default, V4-Pro premium, V3 aliases preserved, reasoning_content kept as [reasoning] preamble |
| 4 #3 (v0.4.0 — this release) | Claude subscription adapter — wraps claude -p via subprocess, reads ~/.claude/.credentials.json, billing-leak prevention via scrub_env_for_subprocess |
| 4 #4-#5 | OpenAI + Grok adapters (subsequent PRs, built on AsyncOpenAI per issue #7) |
| 5.5 | swarph onboard + swarph ratify (lives in swarph-cli, depends on this) |
| 5.7 | swarph daemon + REPL drain coroutine (lives in swarph-cli) |
| 6 | (already done) PyPI publish |
| 7 | swarph-meshlm plugin (separate repo, this dep) |
Install (dev)
git clone https://github.com/darw007d/swarph-mesh
cd swarph-mesh
python -m venv venv && source venv/bin/activate
pip install -e ".[dev]"
pytest
License
MIT. Pierre Samson + Claude Opus, 2026.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swarph_mesh-0.4.0.tar.gz.
File metadata
- Download URL: swarph_mesh-0.4.0.tar.gz
- Upload date:
- Size: 47.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0d18877b8913093fd7f39fe56279de2a32ffba67fb533e089436b26ba4369f8
|
|
| MD5 |
db4e4cbd4cf2054e950f8962926f1b87
|
|
| BLAKE2b-256 |
e025e7361c72cff18d28438bcb9fa5f09b4b8479c39294b88f1fa72014b6b02a
|
File details
Details for the file swarph_mesh-0.4.0-py3-none-any.whl.
File metadata
- Download URL: swarph_mesh-0.4.0-py3-none-any.whl
- Upload date:
- Size: 35.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e6865af5d4fa12b886fe31b9fc07dcb81cb39cffe6d5e84281a3fb8d6480175
|
|
| MD5 |
f8cef726e79a50ff1a1bac282b1d2829
|
|
| BLAKE2b-256 |
807eea1a27d0da8a92a0a53ef293258a88791e773bec06f660f82621b30f6c9a
|