Initial Commit

This commit is contained in:
2026-05-27 23:29:53 +01:00
commit fbc70f96e6
10000 changed files with 1102152 additions and 0 deletions

View File

@@ -0,0 +1,81 @@
# OpenSpec Change: network-discovery-trystero
- **Change ID**: network-discovery-trystero
- **Package**: `@suaveplan/network-discovery-trystero`
- **Category**: browser
- **Target path**: `packages/network/network-discovery-trystero`
- **Status**: PROPOSED
- **Date**: 2026-05-11
- **Parent**: `network-transport-family` (2026-05-11) — Wave 2
- **Migration source**: `../suaveplan/packages/browser/network-discovery-trystero` + `../suaveplan/enterprise/network-discovery-trystero.md`
---
## Summary
Migrate `@suaveplan/network-discovery-trystero` as a browser-tier `DiscoveryStrategy` for `@suaveplan/network`. Serverless WebRTC peer discovery via [Trystero](https://github.com/dmotz/trystero), with four interchangeable transports: BitTorrent trackers, Nostr relays, MQTT brokers, IPFS libp2p pubsub.
---
## Current-state audit
Upstream source layout (`../suaveplan/packages/browser/network-discovery-trystero/src/`):
- `trystero-discovery.ts` (259 L) — orchestrator
- `message-handlers.ts` (186 L)
- `room-config.ts` (178 L) — per-strategy room config
- `types-messages.ts` (176 L), `types-config.ts` (158 L)
- `intervals.ts` (132 L)
- `fallback.ts` — auto-fallback between transports
- `event-emitter.ts` — typed events
See `../suaveplan/enterprise/network-discovery-trystero.md` for full upstream surface inventory.
---
## Parity Checklist
| Capability | Upstream | Migrated | Notes |
|---|---|---|---|
| `DiscoveryStrategy` impl | ✅ | ✅ | |
| 4 transports (torrent / nostr / mqtt / ipfs) | ✅ | ✅ | Each transport selectable at construction. |
| Inter-transport fallback | ✅ | ✅ | Reuses `@suaveplan/retry` for backoff. |
| Public relay defaults | ⚠️ (insecure) | ⬆️ | Relay list REQUIRED in options; constructor throws `INVALID_OPTIONS` if missing. |
| Structured errors | 🚫 | ⬆️ | `defineCodes` registry with strategy-specific codes. |
| Zod boundary validation | 🚫 | ⬆️ | Every public option struct. |
| OTel instrumentation | 🚫 | ⬆️ | Spans + counters + histograms keyed by strategy. |
| AbortSignal | 🚫 | ⬆️ | Threaded through `start`/`stop`/`connect`. |
| `export *` barrels | check | ⬆️ | Convert to explicit named exports per §6a. |
| Test-runner imports | direct vitest | ⬆️ | Rewrite to `@suaveplan/testing/runner` per §7. |
| 100% test coverage | 🚫 | ⬆️ | Bring to 100/100/100/100. |
| Property tests | 🚫 | ⬆️ | fast-check property suite where applicable. |
---
## Available workspace deps on genesis
- `@suaveplan/network` ✅
- `@suaveplan/network-bootstrap` ⬅ Wave 1
- `@suaveplan/service-discovery` ⬅ Wave 1
- `@suaveplan/types`, `@suaveplan/error`, `@suaveplan/events`, `@suaveplan/timing` ✅
- `@suaveplan/testing` ✅
- External: `trystero` — add to root catalog under `network-discovery`.
**Blocking note.** Wave 1 must land first.
---
## Acceptance gate
1. `bunx turbo lint typecheck test --filter=@suaveplan/network-discovery-trystero` green.
2. `bunx turbo test:coverage --filter=@suaveplan/network-discovery-trystero` 100/100/100/100.
3. `bun run docs:check` green (sibling `.md` per `.ts`).
4. `STATUS.md` row flipped from `–` to `✅`.
5. `network-bootstrap` chain integration test demonstrates this strategy as a working entry.
---
## Out of scope
- Hosting / running any required relays or trackers (deployment concern).
- React Storybook stories — discovery is a universal/headless tier; UI lives in a dedicated devtools package (future).

View File

@@ -0,0 +1,56 @@
# Tasks — network-discovery-trystero
## Phase 1: Scaffold
- [ ] 1.1 Create `packages/network/network-discovery-trystero/` with standard feature-module layout.
- [ ] 1.2 `package.json` at `0.1.0`, `"sideEffects": false`, subpath exports per module.
- [ ] 1.3 Test config via `createTestConfig()`.
- [ ] 1.4 `tests/dep-graph.test.ts`.
## Phase 2: Types + errors
- [ ] 2.1 Port public types into `src/types/` + sibling `.md`.
- [ ] 2.2 `defineCodes` registry per parity checklist.
- [ ] 2.3 Zod schemas for every public option struct.
## Phase 3: Core strategy
- [ ] 3.1 Port the `DiscoveryStrategy` implementation module(s) listed in the audit.
- [ ] 3.2 Replace ad-hoc retry/event utilities with `@suaveplan/retry` + `@suaveplan/events`.
- [ ] 3.3 Inject `Clock` and `Rng` via `@suaveplan/types` contracts.
- [ ] 3.4 Thread `AbortSignal` through every async path.
## Phase 4: Observability
- [ ] 4.1 OTel spans for strategy lifecycle.
- [ ] 4.2 Counters for discovered peers / failures.
- [ ] 4.3 Histograms for handshake / signaling duration.
## Phase 5: Integration
- [ ] 5.1 Cross-package integration test with `@suaveplan/network-bootstrap`: register this strategy in the discovery chain, run a node, observe `peer:found` events.
- [ ] 5.2 Optional: register discovered peers into `@suaveplan/service-discovery`.
## Phase 6: Tests + docs
- [ ] 6.1 Unit tests per feature module via `@suaveplan/testing/runner`.
- [ ] 6.2 fast-check property tests where applicable (peer dedup, retry idempotency).
- [ ] 6.3 100/100/100/100 coverage gate.
- [ ] 6.4 Sibling `.md` doc per `.ts` impl file.
- [ ] 6.5 Root `README.md` with basic + advanced examples.
## Phase 7: Verification
- [ ] 7.1 `bunx turbo lint typecheck test --filter=@suaveplan/network-discovery-trystero` green.
- [ ] 7.2 `bunx turbo test:coverage --filter=@suaveplan/network-discovery-trystero` 100/100/100/100.
- [ ] 7.3 `bun run docs:check --filter=@suaveplan/network-discovery-trystero` green.
- [ ] 7.4 `MANIFEST.md` regen.
- [ ] 7.5 `STATUS.md` row flipped from `–` to `✅`.
## Pre-archive checklist
- [ ] Row 1 — Phase 7 green.
- [ ] Row 2 — Parity 🚫 list empty.
- [ ] Row 3 — `openspec/specs/network-discovery-trystero/spec.md` written.
- [ ] Row 4 — `network-bootstrap` integration test passes.
- [ ] Row 5 — Folder archived.