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,96 @@
# Tasks — network-plugin-state
> Blocked on: `network-core`, `network-plugin-registry`.
## 1. Scaffold
- [x] 1.1 `packages/network/network-plugin-state/` with `package.json` (`@suaveplan/network-plugin-state@0.0.0`), `tsconfig.json`, `vitest.config.ts`, `README.md`.
- [x] 1.2 Workspace deps: `@suaveplan/network`, `@suaveplan/error`, `@suaveplan/types`, `@suaveplan/events`, `@suaveplan/bitpacker`, `@suaveplan/serialize`, `@suaveplan/timing`, `@opentelemetry/api`, `zod`.
- [x] 1.3 `sideEffects: false`.
## 2. Types
- [x] 2.1 `src/types/state.types.ts` — `StateValue`, `StatePath`, `StateSequence`, `StateSnapshot`.
- [x] 2.2 `src/types/reconciliation.types.ts` — `ReconciliationStrategy`, `ConflictResolution`, `PathStrategy`.
- [x] 2.3 `src/types/sync.types.ts` — `SyncMode`, `DeltaMessage`, `FullSyncMessage`.
- [x] 2.4 `src/error-codes.ts` — `defineCodes("NET_STATE", [...])`.
## 3. State manager
- [x] 3.1 `src/state/state-manager.ts` — `StateManager`.
- [x] 3.2 Path-based access: `get(path)`, `set(path, value)`, `delete(path)`.
- [x] 3.3 Versioned history with sequence numbers and timestamps.
- [x] 3.4 Per-path subscriptions: `subscribe(path, callback)`.
## 4. Delta compressor
- [x] 4.1 `src/delta/delta-compressor.ts` — `DeltaCompressor`.
- [x] 4.2 Computes deltas using `@suaveplan/bitpacker`.
- [x] 4.3 Schema-aware compression for typed data.
- [x] 4.4 Roundtrip encode/decode verification.
## 5. State reconciler
- [x] 5.1 `src/reconciler/state-reconciler.ts` — `StateReconciler`.
- [x] 5.2 Strategies: `latest-wins`, `remote-wins`, `local-wins`, `deep-merge`, `custom`.
- [x] 5.3 Deterministic outcomes for same inputs.
- [x] 5.4 Reports conflicts with path, local value, remote value.
## 6. Path strategy registry
- [x] 6.1 `src/strategy/path-strategy-registry.ts` — `PathStrategyRegistry`.
- [x] 6.2 Maps glob/regex patterns to reconciliation strategies.
- [x] 6.3 Examples: `game/positions/*` → `latest-wins`, `game/inventory/*` → `deep-merge`.
## 7. Bloom filter comparator
- [x] 7.1 `src/bloom/bloom-filter-comparator.ts` — `BloomFilterComparator`.
- [x] 7.2 Generates compact Bloom filter from state paths.
- [x] 7.3 Detects divergence with configurable false-positive rate (default 1%).
## 8. State sync engine
- [x] 8.1 `src/sync/state-sync-engine.ts` — `StateSyncEngine`.
- [x] 8.2 Full-state sync for new peers.
- [x] 8.3 Delta sync for existing peers (Bloom filter divergence detection).
- [x] 8.4 Conflict resolution via `StateReconciler`.
- [x] 8.5 Notifies subscribers after sync.
## 9. Resource adapter
- [x] 9.1 `src/resource/resource-adapter.ts` — `ResourceAdapter`.
- [x] 9.2 Profiles: `EDGE`, `MOBILE`, `DESKTOP`, `CLOUD`.
- [x] 9.3 Adjusts compression level, history retention, sync frequency per profile.
## 10. State history pruner
- [x] 10.1 `src/pruner/state-history-pruner.ts` — `StateHistoryPruner`.
- [x] 10.2 Configurable retention window (default: 5 minutes).
- [x] 10.3 Memory-bound pruning: drops oldest when memory threshold exceeded.
## 11. Plugin wrapper
- [x] 11.1 `src/plugin/state-plugin.ts` — `StatePlugin` implements `NetworkPlugin`.
- [x] 11.2 Installs state manager, sync engine, pruner on `install()`.
- [x] 11.3 Subscribes to `peer:joined` for full-state sync, `peer:left` for cleanup.
## 12. Spec
- [x] 12.1 Update `openspec/specs/network/spec.md` with `NET-42`.
## 13. Conformance tests
- [x] 13.1 `src/state/state.spec-conformance.test.ts` — get/set, paths, history, subscriptions.
- [x] 13.2 `src/delta/delta.spec-conformance.test.ts` — delta compute, roundtrip, schema.
- [x] 13.3 `src/reconciler/reconciler.spec-conformance.test.ts` — 5 strategies, path-specific.
- [x] 13.4 `src/sync/sync.spec-conformance.test.ts` — divergence, delta request, full sync.
- [x] 13.5 `src/bloom/bloom.spec-conformance.test.ts` — filter comparison, false-positive tolerance.
- [x] 13.6 `src/resource/resource.spec-conformance.test.ts` — profile adaptation.
- [x] 13.7 `src/pruner/pruner.spec-conformance.test.ts` — retention, memory bounds.
- [x] 13.8 `src/error-codes.spec-conformance.test.ts` — frozen registry.
## 14. Verify
- [x] 14.1 `bunx turbo lint typecheck test --filter=@suaveplan/network-plugin-state` green.
- [x] 14.2 `bunx turbo test:coverage --filter=@suaveplan/network-plugin-state` 100/100/100/100.
- [x] 14.3 `bun scripts/openspec-conformance.ts @suaveplan/network-plugin-state` PASS.