@johnhenry/browsermesh-sync 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,7 +15,7 @@ CRDT sync engine, delta sync, file transfer, and real-time collaboration for Bro
15
15
 
16
16
  ## Provenance
17
17
 
18
- Extracted from the private `clawser` monorepo (previously `packages/browsermesh-sync`), where it was manually published to npm, unscoped, as `browsermesh-sync@0.1.0` (2026-07-17) with no CI ever automating that publish. This is its first release as part of the `@johnhenry/browsermesh` monorepo; the version restarts at `0.0.0` per family convention.
18
+ Extracted from a private monorepo (previously `packages/browsermesh-sync`), where it was manually published to npm, unscoped, as `browsermesh-sync@0.1.0` (2026-07-17) with no CI ever automating that publish. This is its first release as part of the `@johnhenry/browsermesh` monorepo; the version restarts at `0.0.0` per family convention.
19
19
 
20
20
 
21
21
  ## Modules
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnhenry/browsermesh-sync",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "CRDT sync engine, delta sync, file transfer, and collaboration for BrowserMesh",
5
5
  "type": "module",
6
6
  "main": "./src/index.mjs",
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  // STATUS: EXPERIMENTAL — wires peer-collab CRDT into mesh transport layer
3
- * clawser-peer-collab-bridge.js — Connects the CollabSession (Yjs CRDT)
3
+ * collab-bridge.mjs — Connects the CollabSession (Yjs CRDT)
4
4
  * and MeshSyncEngine to the PeerSession transport and SyncCoordinator.
5
5
  *
6
6
  * CollabBridge: per-peer adapter that bridges CollabSession's simple
@@ -20,7 +20,7 @@
20
20
  * collabManager.attach(peerNode);
21
21
  *
22
22
  * Run tests:
23
- * node --import ./web/test/_setup-globals.mjs --test web/test/clawser-peer-collab-bridge.test.mjs
23
+ * cd packages/browsermesh-sync && node --import ./test/_setup-globals.mjs --test test/collab-bridge.test.mjs
24
24
  */
25
25
 
26
26
  import {
@@ -52,16 +52,16 @@ export const CRDT_SYNC_SERVICE_TYPE = 'crdt-sync'
52
52
  * One CollabBridge per connected peer.
53
53
  */
54
54
  export class CollabBridge {
55
- /** @type {import('./clawser-peer-session.js').PeerSession} */
55
+ /** @type {PeerSession} */
56
56
  #peerSession
57
57
 
58
58
  /** @type {Map<string, CollabSession>} docId -> CollabSession */
59
59
  #collabSessions = new Map()
60
60
 
61
- /** @type {import('./clawser-mesh-sync.js').MeshSyncEngine|null} */
61
+ /** @type {import('./sync.mjs').MeshSyncEngine|null} */
62
62
  #syncEngine
63
63
 
64
- /** @type {import('./clawser-mesh-delta-sync.js').SyncCoordinator|null} */
64
+ /** @type {import('./delta-sync.mjs').SyncCoordinator|null} */
65
65
  #syncCoordinator
66
66
 
67
67
  /** @type {string} */
@@ -78,9 +78,9 @@ export class CollabBridge {
78
78
 
79
79
  /**
80
80
  * @param {object} opts
81
- * @param {import('./clawser-peer-session.js').PeerSession} opts.peerSession
82
- * @param {import('./clawser-mesh-sync.js').MeshSyncEngine} [opts.syncEngine]
83
- * @param {import('./clawser-mesh-delta-sync.js').SyncCoordinator} [opts.syncCoordinator]
81
+ * @param {PeerSession} opts.peerSession
82
+ * @param {import('./sync.mjs').MeshSyncEngine} [opts.syncEngine]
83
+ * @param {import('./delta-sync.mjs').SyncCoordinator} [opts.syncCoordinator]
84
84
  * @param {Function} [opts.onLog]
85
85
  */
86
86
  constructor({ peerSession, syncEngine, syncCoordinator, onLog }) {
@@ -340,13 +340,13 @@ export class CollabManager {
340
340
  /** @type {Map<string, CollabBridge>} remotePodId -> CollabBridge */
341
341
  #bridges = new Map()
342
342
 
343
- /** @type {import('./clawser-mesh-sync.js').MeshSyncEngine|null} */
343
+ /** @type {import('./sync.mjs').MeshSyncEngine|null} */
344
344
  #syncEngine
345
345
 
346
- /** @type {import('./clawser-mesh-delta-sync.js').SyncCoordinator|null} */
346
+ /** @type {import('./delta-sync.mjs').SyncCoordinator|null} */
347
347
  #syncCoordinator
348
348
 
349
- /** @type {import('./clawser-peer-session.js').SessionManager|null} */
349
+ /** @type {SessionManager|null} */
350
350
  #sessionManager
351
351
 
352
352
  /** @type {string} */
@@ -373,9 +373,9 @@ export class CollabManager {
373
373
  /**
374
374
  * @param {object} opts
375
375
  * @param {string} opts.localPodId
376
- * @param {import('./clawser-mesh-sync.js').MeshSyncEngine} [opts.syncEngine]
377
- * @param {import('./clawser-mesh-delta-sync.js').SyncCoordinator} [opts.syncCoordinator]
378
- * @param {import('./clawser-peer-session.js').SessionManager} [opts.sessionManager]
376
+ * @param {import('./sync.mjs').MeshSyncEngine} [opts.syncEngine]
377
+ * @param {import('./delta-sync.mjs').SyncCoordinator} [opts.syncCoordinator]
378
+ * @param {SessionManager} [opts.sessionManager]
379
379
  * @param {Function} [opts.onLog]
380
380
  */
381
381
  constructor({ localPodId, syncEngine, syncCoordinator, sessionManager, onLog }) {
@@ -400,7 +400,7 @@ export class CollabManager {
400
400
  /**
401
401
  * Attach to a PeerNode to auto-manage bridges on peer lifecycle events.
402
402
  *
403
- * @param {import('./clawser-peer-node.js').PeerNode} peerNode
403
+ * @param {PeerNode} peerNode
404
404
  */
405
405
  attach(peerNode) {
406
406
  if (this.#peerNode) this.detach()
@@ -496,7 +496,7 @@ export class CollabManager {
496
496
  * falls back to direct PeerNode session lookup.
497
497
  *
498
498
  * @param {string} peerId
499
- * @returns {import('./clawser-peer-session.js').PeerSession|null}
499
+ * @returns {PeerSession|null}
500
500
  */
501
501
  #findPeerSession(peerId) {
502
502
  // Try SessionManager first (provides full PeerSession with handler routing)
package/src/collab.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  // STATUS: EXPERIMENTAL — complete implementation, not yet integrated into main application
3
- * clawser-peer-collab.js -- Real-time collaborative editing via Yjs CRDT.
3
+ * collab.mjs -- Real-time collaborative editing via Yjs CRDT.
4
4
  *
5
5
  * YjsAdapter: wraps Yjs Doc with shared types and sync primitives.
6
6
  * AwarenessState: cursor/selection presence (custom, no Yjs awareness dep).
@@ -11,7 +11,7 @@
11
11
  * No browser-only imports at module level.
12
12
  *
13
13
  * Run tests:
14
- * node --import ./web/test/_setup-globals.mjs --test web/test/clawser-peer-collab.test.mjs
14
+ * cd packages/browsermesh-sync && node --import ./test/_setup-globals.mjs --test test/collab.test.mjs
15
15
  */
16
16
 
17
17
  // ---------------------------------------------------------------------------
@@ -1,6 +1,6 @@
1
1
  /**
2
- // STATUS: INTEGRATED — wired into ClawserPod lifecycle, proven via E2E testing
3
- * clawser-mesh-delta-sync.js -- Delta-Based Synchronization Protocol.
2
+ // STATUS: INTEGRATED — wired into Pod (@johnhenry/browsermesh-pod) lifecycle, proven via E2E testing
3
+ * delta-sync.mjs -- Delta-Based Synchronization Protocol.
4
4
  *
5
5
  * Efficient state synchronization using delta (diff) encoding:
6
6
  *
@@ -14,7 +14,7 @@
14
14
  * No browser-only imports at module level.
15
15
  *
16
16
  * Run tests:
17
- * node --import ./web/test/_setup-globals.mjs --test web/test/clawser-mesh-delta-sync.test.mjs
17
+ * cd packages/browsermesh-sync && node --import ./test/_setup-globals.mjs --test test/delta-sync.test.mjs
18
18
  */
19
19
 
20
20
  // ---------------------------------------------------------------------------
package/src/files.mjs CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
- // STATUS: INTEGRATED — wired into ClawserPod lifecycle, proven via E2E testing
3
- * Clawser Mesh Files
2
+ // STATUS: INTEGRATED — wired into Pod (@johnhenry/browsermesh-pod) lifecycle, proven via E2E testing
3
+ * Mesh Files
4
4
  *
5
5
  * Content-addressed file transfer with SHA-256 chunking, progress tracking,
6
6
  * and resume support. Builds on the streams module for transport.
7
7
  *
8
- * @module clawser-mesh-files
8
+ * @module files
9
9
  */
10
10
 
11
11
  import { MESH_TYPE, MESH_ERROR } from '@johnhenry/browsermesh-primitives';
@@ -1,6 +1,6 @@
1
1
  /**
2
- // STATUS: INTEGRATED — wired into ClawserPod lifecycle, proven via E2E testing
3
- * clawser-peer-memory-sync.js — CRDT-backed agent memory replication.
2
+ // STATUS: INTEGRATED — wired into Pod (@johnhenry/browsermesh-pod) lifecycle, proven via E2E testing
3
+ * memory-sync.mjs — CRDT-backed agent memory replication.
4
4
  *
5
5
  * Replicate agent memory across the mesh using CRDTs. An agent's memory
6
6
  * survives device failure — when the user reconnects, memory resyncs
@@ -18,7 +18,7 @@
18
18
  * - trust: use podId to look up trust scores
19
19
  *
20
20
  * Run tests:
21
- * node --import ./web/test/_setup-globals.mjs --test web/test/clawser-peer-memory-sync.test.mjs
21
+ * cd packages/browsermesh-sync && node --import ./test/_setup-globals.mjs --test test/memory-sync.test.mjs
22
22
  */
23
23
 
24
24
  // ---------------------------------------------------------------------------
package/src/migration.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import { silentCatch } from './silent-catch.mjs'
2
2
  /**
3
- // STATUS: INTEGRATED — wired into ClawserPod lifecycle, proven via E2E testing
4
- * clawser-mesh-migration.js -- Pod State Migration Between Peers.
3
+ // STATUS: INTEGRATED — wired into Pod (@johnhenry/browsermesh-pod) lifecycle, proven via E2E testing
4
+ * migration.mjs -- Pod State Migration Between Peers.
5
5
  *
6
6
  * Manages checkpointing, transferring, verifying, and activating pod state
7
7
  * on a target peer. Supports zero-downtime handoff via a dual-active window.
8
8
  *
9
9
  * Run tests:
10
- * node --import ./web/test/_setup-globals.mjs --test web/test/clawser-mesh-migration.test.mjs
10
+ * cd packages/browsermesh-sync && node --import ./test/_setup-globals.mjs --test test/migration.test.mjs
11
11
  */
12
12
 
13
13
  // ---------------------------------------------------------------------------
@@ -913,7 +913,7 @@ export class MigrationEngine {
913
913
  if (valid) {
914
914
  this.#checkpoints.set(payload.migrationId || checkpoint.checkpointId, checkpoint);
915
915
  }
916
- } catch (e) { silentCatch('clawser-mesh-migration', 'ignore-malformed-checkpoints', e) }
916
+ } catch (e) { silentCatch('migration', 'ignore-malformed-checkpoints', e) }
917
917
  });
918
918
 
919
919
  // Inbound: state transfer payload
@@ -2,31 +2,43 @@
2
2
  * silent-catch.mjs — debug-gated structured logger for the
3
3
  * `try { … } catch { /* ignore *\/ }` pattern.
4
4
  *
5
- * Vendored from clawser-silent-catch.mjs (fully standalone, no other
6
- * clawser-app imports) so this package doesn't need to reach into web/.
5
+ * Standalone module (no other imports) so this package is self-contained.
7
6
  *
8
7
  * Replaces silent catches with an opt-in inspectable record. Default
9
8
  * behaviour is unchanged (silent), so this is a drop-in replacement.
10
9
  * Users surface the events by enabling debug mode:
11
10
  *
12
- * localStorage.setItem('clawser_debug', 'true') // persistent
13
- * // or, in DevTools: clawserDebug.enable()
11
+ * localStorage.setItem('browsermesh_debug', 'true') // persistent
12
+ * // or, in DevTools: browsermeshDebug.enable()
13
+ *
14
+ * The old `clawser_debug` localStorage key and `clawserDebug` global are
15
+ * deprecated aliases, kept for compatibility.
14
16
  */
15
17
 
18
+ /** localStorage key that enables debug mode. */
19
+ const DEBUG_KEY = 'browsermesh_debug';
20
+ /** Deprecated alias for DEBUG_KEY, kept for compatibility. */
21
+ const LEGACY_DEBUG_KEY = 'clawser_debug';
22
+
23
+ function readDebugFlag() {
24
+ return localStorage.getItem(DEBUG_KEY) === 'true'
25
+ || localStorage.getItem(LEGACY_DEBUG_KEY) === 'true';
26
+ }
27
+
16
28
  let enabled = false;
17
29
  try {
18
30
  if (typeof localStorage !== 'undefined') {
19
- enabled = localStorage.getItem('clawser_debug') === 'true';
31
+ enabled = readDebugFlag();
20
32
  }
21
33
  } catch {
22
34
  // localStorage may throw in privacy / sandbox contexts — treat as disabled
23
35
  }
24
36
 
25
- /** Re-check the localStorage flag; called by clawserDebug.enable/disable. */
37
+ /** Re-check the localStorage flag; called by browsermeshDebug.enable/disable. */
26
38
  export function refreshSilentCatchState() {
27
39
  try {
28
40
  if (typeof localStorage !== 'undefined') {
29
- enabled = localStorage.getItem('clawser_debug') === 'true';
41
+ enabled = readDebugFlag();
30
42
  }
31
43
  } catch {
32
44
  enabled = false;
@@ -36,7 +48,7 @@ export function refreshSilentCatchState() {
36
48
  /**
37
49
  * Log a silent-catch event. No-op unless debug mode is enabled.
38
50
  *
39
- * @param {string} module — file/component (e.g. 'clawser-pod')
51
+ * @param {string} module — file/component (e.g. 'pod')
40
52
  * @param {string} operation — what was attempted (e.g. 'relay-disconnect')
41
53
  * @param {*} error — the caught value
42
54
  * @param {object} [context] — extra structured fields
@@ -51,5 +63,5 @@ export function silentCatch(module, operation, error, context) {
51
63
  }
52
64
  const entry = { module, operation, error: error?.message || String(error) };
53
65
  if (context) Object.assign(entry, context);
54
- console.warn('[clawser:silent-catch]', entry);
66
+ console.warn('[browsermesh:silent-catch]', entry);
55
67
  }
package/src/sync.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * clawser-mesh-sync.js — CRDT State Replication Engine.
2
+ * sync.mjs — CRDT State Replication Engine.
3
3
  * Manages CRDT documents with storage persistence and delta-based peer sync.
4
4
  *
5
5
  * Usage: