@weaveprotocol/cli 0.2.4 → 0.2.5

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.
Files changed (2) hide show
  1. package/dist/weave.mjs +47 -3
  2. package/package.json +1 -1
package/dist/weave.mjs CHANGED
@@ -7527,14 +7527,18 @@ async function proveRead(access, label, provider) {
7527
7527
  }
7528
7528
  async function checkRead(access, peerDid, label, proof, provider) {
7529
7529
  const current = access.current();
7530
+ const admit = (readKey2) => {
7531
+ access.admitted?.(peerDid, readKey2);
7532
+ return true;
7533
+ };
7530
7534
  const claimed = typeof proof.readKey === "string" ? proof.readKey : current;
7531
7535
  if (claimed.startsWith("did:key:") && await verifyBy(provider, claimed, proof.read, label)) {
7532
- if (claimed === current) return true;
7533
- if (access.admits && await access.admits(peerDid, claimed, proof.member)) return true;
7536
+ if (claimed === current) return admit(current);
7537
+ if (access.admits && await access.admits(peerDid, claimed, proof.member)) return admit(claimed);
7534
7538
  }
7535
7539
  const earlier = Array.isArray(proof.earlier) ? proof.earlier.slice(0, MAX_EARLIER_READ_KEYS) : [];
7536
7540
  const ours = earlier.find((item) => item?.readKey === current);
7537
- return ours !== void 0 && current.startsWith("did:key:") && verifyBy(provider, current, ours.read, label);
7541
+ return ours !== void 0 && current.startsWith("did:key:") && await verifyBy(provider, current, ours.read, label) && admit(current);
7538
7542
  }
7539
7543
  function peerNonce() {
7540
7544
  return base64UrlEncode(globalThis.crypto.getRandomValues(new Uint8Array(16)));
@@ -8016,6 +8020,12 @@ function createMesh(config) {
8016
8020
  broadcast: (message) => {
8017
8021
  for (const peer of room.peers.keys()) send2(peer, message);
8018
8022
  },
8023
+ drop(peer) {
8024
+ if (rooms.get(name) !== room || !room.peers.has(peer)) return;
8025
+ sendFrame(peer, { room: name, type: LEAVE_MESSAGE });
8026
+ drop(room, peer);
8027
+ closeIfIdle(peer);
8028
+ },
8019
8029
  getPeers: () => [...room.peers.values()],
8020
8030
  on: room.events.on,
8021
8031
  off: room.events.off,
@@ -8066,6 +8076,9 @@ function createNetworkManager(config) {
8066
8076
  broadcast: (message) => {
8067
8077
  for (const peerId of peers.keys()) send2(peerId, message);
8068
8078
  },
8079
+ drop: (peerId) => {
8080
+ if (peers.has(peerId)) transport.close(peerId);
8081
+ },
8069
8082
  getPeers: () => [...peers.values()],
8070
8083
  on,
8071
8084
  off,
@@ -9011,6 +9024,8 @@ var writeCapability = (spaceId) => ({
9011
9024
  });
9012
9025
  var noteCid = (encoded) => cidFromBytes(utf8Encode(encoded));
9013
9026
  var NO_ACCOUNT = Object.freeze({ account: null, agent: false });
9027
+ var STALE_ADMISSION_MS = 6e4;
9028
+ var WHO_WAIT_MS = 1e4;
9014
9029
  var WHO_MESSAGE = "who";
9015
9030
  var LIVE_MESSAGE = "live";
9016
9031
  var MAX_LIVE_BYTES = 64 * 1024;
@@ -9564,6 +9579,8 @@ async function openSpaceRuntime(deps) {
9564
9579
  for (const mirror of mirrors) mirror.changed();
9565
9580
  void refreshHolds().catch(() => {
9566
9581
  });
9582
+ void letGoOfOutsiders().catch(() => {
9583
+ });
9567
9584
  };
9568
9585
  function currentKey2(state) {
9569
9586
  const epoch = state.keys.at(-1);
@@ -9721,6 +9738,7 @@ async function openSpaceRuntime(deps) {
9721
9738
  keysRunning = null;
9722
9739
  });
9723
9740
  }
9741
+ const admittedOn = /* @__PURE__ */ new Map();
9724
9742
  const readAccess = space2.visibility !== "private" ? null : {
9725
9743
  async key() {
9726
9744
  const held = newestKey((await access()).history.current);
@@ -9744,6 +9762,9 @@ async function openSpaceRuntime(deps) {
9744
9762
  if (!held) return false;
9745
9763
  const { account } = await accountOf(peerDid, await openWith(held, membership, membershipContext(space2.id)));
9746
9764
  return account !== null && readers(history.current).has(account);
9765
+ },
9766
+ admitted(peerDid, readKey2) {
9767
+ admittedOn.set(peerDid, { readKey: readKey2, at: Date.now() });
9747
9768
  }
9748
9769
  };
9749
9770
  const mirrors = [];
@@ -9853,6 +9874,24 @@ async function openSpaceRuntime(deps) {
9853
9874
  if (!routes.has(peer)) return;
9854
9875
  emit({ type: "message", space: space2.id, from: account, peer, agent, message: payload });
9855
9876
  }
9877
+ async function letGoOfOutsiders() {
9878
+ if (admittedOn.size === 0) return;
9879
+ const connected = new Set(connectedPeers());
9880
+ for (const [peer, { at }] of admittedOn) {
9881
+ if (!connected.has(peer) && Date.now() - at > STALE_ADMISSION_MS) admittedOn.delete(peer);
9882
+ }
9883
+ const allowed = readers((await access()).history.current);
9884
+ for (const peer of connected) {
9885
+ const admission = admittedOn.get(peer);
9886
+ if (!admission || admission.readKey === currentReadKey) continue;
9887
+ if (!peerAccounts.has(peer) && Date.now() - admission.at < WHO_WAIT_MS) continue;
9888
+ const { account } = await peerAccounts.get(peer) ?? NO_ACCOUNT;
9889
+ if (account !== null && allowed.has(account)) continue;
9890
+ if (admittedOn.get(peer) !== admission) continue;
9891
+ admittedOn.delete(peer);
9892
+ for (const network of networks) network.drop(peer);
9893
+ }
9894
+ }
9856
9895
  for (const network of networks) {
9857
9896
  network.on("message", (message) => {
9858
9897
  if (message.type === "sync") void sync.handleMessage(message.from, message.payload);
@@ -9864,6 +9903,8 @@ async function openSpaceRuntime(deps) {
9864
9903
  if (peerAccounts.get(message.from) !== checked) return;
9865
9904
  knownAccounts.set(message.from, known);
9866
9905
  emit({ type: "status", space: space2.id });
9906
+ void letGoOfOutsiders().catch(() => {
9907
+ });
9867
9908
  });
9868
9909
  } else if (message.type === LIVE_MESSAGE) void onLive(message.from, message.payload);
9869
9910
  });
@@ -9873,6 +9914,8 @@ async function openSpaceRuntime(deps) {
9873
9914
  sync.addPeer(info.did);
9874
9915
  sync.notifyPeers([info.did]);
9875
9916
  emit({ type: "status", space: space2.id });
9917
+ void letGoOfOutsiders().catch(() => {
9918
+ });
9876
9919
  });
9877
9920
  network.on("peer-disconnected", (info) => {
9878
9921
  if (routes.get(info.did) === network) {
@@ -9882,6 +9925,7 @@ async function openSpaceRuntime(deps) {
9882
9925
  knownAccounts.delete(info.did);
9883
9926
  liveAllowance.delete(info.did);
9884
9927
  }
9928
+ if (!connectedPeers().includes(info.did)) admittedOn.delete(info.did);
9885
9929
  emit({ type: "status", space: space2.id });
9886
9930
  });
9887
9931
  network.on("error", () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weaveprotocol/cli",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "The Weave protocol from a terminal: manage spaces, run an always-on node, serve MCP to agents",
5
5
  "type": "module",
6
6
  "bin": {