claudemesh-cli 0.6.4 → 0.6.6

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/index.js +261 -318
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -47468,15 +47468,15 @@ class BrokerClient {
47468
47468
  outbound = [];
47469
47469
  pushHandlers = new Set;
47470
47470
  pushBuffer = [];
47471
- listPeersResolvers = [];
47472
- stateResolvers = [];
47473
- stateListResolvers = [];
47474
- memoryStoreResolvers = [];
47475
- memoryRecallResolvers = [];
47471
+ listPeersResolvers = new Map;
47472
+ stateResolvers = new Map;
47473
+ stateListResolvers = new Map;
47474
+ memoryStoreResolvers = new Map;
47475
+ memoryRecallResolvers = new Map;
47476
47476
  stateChangeHandlers = new Set;
47477
47477
  sessionPubkey = null;
47478
47478
  sessionSecretKey = null;
47479
- grantFileAccessResolvers = [];
47479
+ grantFileAccessResolvers = new Map;
47480
47480
  closed = false;
47481
47481
  reconnectAttempt = 0;
47482
47482
  helloTimer = null;
@@ -47503,6 +47503,9 @@ class BrokerClient {
47503
47503
  getSessionSecretKey() {
47504
47504
  return this.sessionSecretKey;
47505
47505
  }
47506
+ makeReqId() {
47507
+ return Math.random().toString(36).slice(2) + Date.now().toString(36);
47508
+ }
47506
47509
  async connect() {
47507
47510
  if (this.closed)
47508
47511
  throw new Error("client is closed");
@@ -47656,15 +47659,12 @@ class BrokerClient {
47656
47659
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
47657
47660
  return [];
47658
47661
  return new Promise((resolve) => {
47659
- this.listPeersResolvers.push(resolve);
47660
- this.ws.send(JSON.stringify({ type: "list_peers" }));
47661
- setTimeout(() => {
47662
- const idx = this.listPeersResolvers.indexOf(resolve);
47663
- if (idx !== -1) {
47664
- this.listPeersResolvers.splice(idx, 1);
47662
+ const reqId = this.makeReqId();
47663
+ this.listPeersResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47664
+ if (this.listPeersResolvers.delete(reqId))
47665
47665
  resolve([]);
47666
- }
47667
- }, 5000);
47666
+ }, 5000) });
47667
+ this.ws.send(JSON.stringify({ type: "list_peers", _reqId: reqId }));
47668
47668
  });
47669
47669
  }
47670
47670
  async setSummary(summary) {
@@ -47691,60 +47691,48 @@ class BrokerClient {
47691
47691
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
47692
47692
  return null;
47693
47693
  return new Promise((resolve) => {
47694
- this.stateResolvers.push(resolve);
47695
- this.ws.send(JSON.stringify({ type: "get_state", key }));
47696
- setTimeout(() => {
47697
- const idx = this.stateResolvers.indexOf(resolve);
47698
- if (idx !== -1) {
47699
- this.stateResolvers.splice(idx, 1);
47694
+ const reqId = this.makeReqId();
47695
+ this.stateResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47696
+ if (this.stateResolvers.delete(reqId))
47700
47697
  resolve(null);
47701
- }
47702
- }, 5000);
47698
+ }, 5000) });
47699
+ this.ws.send(JSON.stringify({ type: "get_state", key, _reqId: reqId }));
47703
47700
  });
47704
47701
  }
47705
47702
  async listState() {
47706
47703
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
47707
47704
  return [];
47708
47705
  return new Promise((resolve) => {
47709
- this.stateListResolvers.push(resolve);
47710
- this.ws.send(JSON.stringify({ type: "list_state" }));
47711
- setTimeout(() => {
47712
- const idx = this.stateListResolvers.indexOf(resolve);
47713
- if (idx !== -1) {
47714
- this.stateListResolvers.splice(idx, 1);
47706
+ const reqId = this.makeReqId();
47707
+ this.stateListResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47708
+ if (this.stateListResolvers.delete(reqId))
47715
47709
  resolve([]);
47716
- }
47717
- }, 5000);
47710
+ }, 5000) });
47711
+ this.ws.send(JSON.stringify({ type: "list_state", _reqId: reqId }));
47718
47712
  });
47719
47713
  }
47720
47714
  async remember(content, tags) {
47721
47715
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
47722
47716
  return null;
47723
47717
  return new Promise((resolve) => {
47724
- this.memoryStoreResolvers.push(resolve);
47725
- this.ws.send(JSON.stringify({ type: "remember", content, tags }));
47726
- setTimeout(() => {
47727
- const idx = this.memoryStoreResolvers.indexOf(resolve);
47728
- if (idx !== -1) {
47729
- this.memoryStoreResolvers.splice(idx, 1);
47718
+ const reqId = this.makeReqId();
47719
+ this.memoryStoreResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47720
+ if (this.memoryStoreResolvers.delete(reqId))
47730
47721
  resolve(null);
47731
- }
47732
- }, 5000);
47722
+ }, 5000) });
47723
+ this.ws.send(JSON.stringify({ type: "remember", content, tags, _reqId: reqId }));
47733
47724
  });
47734
47725
  }
47735
47726
  async recall(query) {
47736
47727
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
47737
47728
  return [];
47738
47729
  return new Promise((resolve) => {
47739
- this.memoryRecallResolvers.push(resolve);
47740
- this.ws.send(JSON.stringify({ type: "recall", query }));
47741
- setTimeout(() => {
47742
- const idx = this.memoryRecallResolvers.indexOf(resolve);
47743
- if (idx !== -1) {
47744
- this.memoryRecallResolvers.splice(idx, 1);
47730
+ const reqId = this.makeReqId();
47731
+ this.memoryRecallResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47732
+ if (this.memoryRecallResolvers.delete(reqId))
47745
47733
  resolve([]);
47746
- }
47747
- }, 5000);
47734
+ }, 5000) });
47735
+ this.ws.send(JSON.stringify({ type: "recall", query, _reqId: reqId }));
47748
47736
  });
47749
47737
  }
47750
47738
  async forget(memoryId) {
@@ -47752,81 +47740,69 @@ class BrokerClient {
47752
47740
  return;
47753
47741
  this.ws.send(JSON.stringify({ type: "forget", memoryId }));
47754
47742
  }
47755
- messageStatusResolvers = [];
47756
- fileUrlResolvers = [];
47757
- fileListResolvers = [];
47758
- fileStatusResolvers = [];
47759
- vectorStoredResolvers = [];
47760
- vectorResultsResolvers = [];
47761
- collectionListResolvers = [];
47762
- graphResultResolvers = [];
47763
- contextListResolvers = [];
47764
- contextResultsResolvers = [];
47765
- taskCreatedResolvers = [];
47766
- taskListResolvers = [];
47767
- meshQueryResolvers = [];
47768
- meshSchemaResolvers = [];
47769
- streamCreatedResolvers = [];
47770
- streamListResolvers = [];
47743
+ messageStatusResolvers = new Map;
47744
+ fileUrlResolvers = new Map;
47745
+ fileListResolvers = new Map;
47746
+ fileStatusResolvers = new Map;
47747
+ vectorStoredResolvers = new Map;
47748
+ vectorResultsResolvers = new Map;
47749
+ collectionListResolvers = new Map;
47750
+ graphResultResolvers = new Map;
47751
+ contextListResolvers = new Map;
47752
+ contextResultsResolvers = new Map;
47753
+ taskCreatedResolvers = new Map;
47754
+ taskListResolvers = new Map;
47755
+ meshQueryResolvers = new Map;
47756
+ meshSchemaResolvers = new Map;
47757
+ streamCreatedResolvers = new Map;
47758
+ streamListResolvers = new Map;
47771
47759
  streamDataHandlers = new Set;
47772
47760
  async messageStatus(messageId) {
47773
47761
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
47774
47762
  return null;
47775
47763
  return new Promise((resolve) => {
47776
- this.messageStatusResolvers.push(resolve);
47777
- this.ws.send(JSON.stringify({ type: "message_status", messageId }));
47778
- setTimeout(() => {
47779
- const idx = this.messageStatusResolvers.indexOf(resolve);
47780
- if (idx !== -1) {
47781
- this.messageStatusResolvers.splice(idx, 1);
47764
+ const reqId = this.makeReqId();
47765
+ this.messageStatusResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47766
+ if (this.messageStatusResolvers.delete(reqId))
47782
47767
  resolve(null);
47783
- }
47784
- }, 5000);
47768
+ }, 5000) });
47769
+ this.ws.send(JSON.stringify({ type: "message_status", messageId, _reqId: reqId }));
47785
47770
  });
47786
47771
  }
47787
47772
  async getFile(fileId) {
47788
47773
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
47789
47774
  return null;
47790
47775
  return new Promise((resolve) => {
47791
- this.fileUrlResolvers.push(resolve);
47792
- this.ws.send(JSON.stringify({ type: "get_file", fileId }));
47793
- setTimeout(() => {
47794
- const idx = this.fileUrlResolvers.indexOf(resolve);
47795
- if (idx !== -1) {
47796
- this.fileUrlResolvers.splice(idx, 1);
47776
+ const reqId = this.makeReqId();
47777
+ this.fileUrlResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47778
+ if (this.fileUrlResolvers.delete(reqId))
47797
47779
  resolve(null);
47798
- }
47799
- }, 5000);
47780
+ }, 5000) });
47781
+ this.ws.send(JSON.stringify({ type: "get_file", fileId, _reqId: reqId }));
47800
47782
  });
47801
47783
  }
47802
47784
  async listFiles(query, from) {
47803
47785
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
47804
47786
  return [];
47805
47787
  return new Promise((resolve) => {
47806
- this.fileListResolvers.push(resolve);
47807
- this.ws.send(JSON.stringify({ type: "list_files", query, from }));
47808
- setTimeout(() => {
47809
- const idx = this.fileListResolvers.indexOf(resolve);
47810
- if (idx !== -1) {
47811
- this.fileListResolvers.splice(idx, 1);
47788
+ const reqId = this.makeReqId();
47789
+ this.fileListResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47790
+ if (this.fileListResolvers.delete(reqId))
47812
47791
  resolve([]);
47813
- }
47814
- }, 5000);
47792
+ }, 5000) });
47793
+ this.ws.send(JSON.stringify({ type: "list_files", query, from, _reqId: reqId }));
47815
47794
  });
47816
47795
  }
47817
47796
  async fileStatus(fileId) {
47818
47797
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
47819
47798
  return [];
47820
47799
  return new Promise((resolve) => {
47821
- this.fileStatusResolvers.push(resolve);
47822
- this.ws.send(JSON.stringify({ type: "file_status", fileId }));
47823
- setTimeout(() => {
47824
- const idx = this.fileStatusResolvers.indexOf(resolve);
47825
- if (idx !== -1) {
47826
- this.fileStatusResolvers.splice(idx, 1);
47800
+ const reqId = this.makeReqId();
47801
+ this.fileStatusResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47802
+ if (this.fileStatusResolvers.delete(reqId))
47827
47803
  resolve([]);
47828
- }
47829
- }, 5000);
47804
+ }, 5000) });
47805
+ this.ws.send(JSON.stringify({ type: "file_status", fileId, _reqId: reqId }));
47830
47806
  });
47831
47807
  }
47832
47808
  async deleteFile(fileId) {
@@ -47867,46 +47843,36 @@ class BrokerClient {
47867
47843
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
47868
47844
  return false;
47869
47845
  return new Promise((resolve) => {
47870
- const resolvers = this.grantFileAccessResolvers;
47871
- resolvers.push(resolve);
47872
- this.ws.send(JSON.stringify({ type: "grant_file_access", fileId, peerPubkey, sealedKey }));
47873
- setTimeout(() => {
47874
- const idx = resolvers.indexOf(resolve);
47875
- if (idx !== -1) {
47876
- resolvers.splice(idx, 1);
47846
+ const reqId = this.makeReqId();
47847
+ this.grantFileAccessResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47848
+ if (this.grantFileAccessResolvers.delete(reqId))
47877
47849
  resolve(false);
47878
- }
47879
- }, 5000);
47850
+ }, 5000) });
47851
+ this.ws.send(JSON.stringify({ type: "grant_file_access", fileId, peerPubkey, sealedKey, _reqId: reqId }));
47880
47852
  });
47881
47853
  }
47882
47854
  async vectorStore(collection, text, metadata) {
47883
47855
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
47884
47856
  return null;
47885
47857
  return new Promise((resolve) => {
47886
- this.vectorStoredResolvers.push(resolve);
47887
- this.ws.send(JSON.stringify({ type: "vector_store", collection, text, metadata }));
47888
- setTimeout(() => {
47889
- const idx = this.vectorStoredResolvers.indexOf(resolve);
47890
- if (idx !== -1) {
47891
- this.vectorStoredResolvers.splice(idx, 1);
47858
+ const reqId = this.makeReqId();
47859
+ this.vectorStoredResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47860
+ if (this.vectorStoredResolvers.delete(reqId))
47892
47861
  resolve(null);
47893
- }
47894
- }, 5000);
47862
+ }, 5000) });
47863
+ this.ws.send(JSON.stringify({ type: "vector_store", collection, text, metadata, _reqId: reqId }));
47895
47864
  });
47896
47865
  }
47897
47866
  async vectorSearch(collection, query, limit) {
47898
47867
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
47899
47868
  return [];
47900
47869
  return new Promise((resolve) => {
47901
- this.vectorResultsResolvers.push(resolve);
47902
- this.ws.send(JSON.stringify({ type: "vector_search", collection, query, limit }));
47903
- setTimeout(() => {
47904
- const idx = this.vectorResultsResolvers.indexOf(resolve);
47905
- if (idx !== -1) {
47906
- this.vectorResultsResolvers.splice(idx, 1);
47870
+ const reqId = this.makeReqId();
47871
+ this.vectorResultsResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47872
+ if (this.vectorResultsResolvers.delete(reqId))
47907
47873
  resolve([]);
47908
- }
47909
- }, 5000);
47874
+ }, 5000) });
47875
+ this.ws.send(JSON.stringify({ type: "vector_search", collection, query, limit, _reqId: reqId }));
47910
47876
  });
47911
47877
  }
47912
47878
  async vectorDelete(collection, id) {
@@ -47918,45 +47884,36 @@ class BrokerClient {
47918
47884
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
47919
47885
  return [];
47920
47886
  return new Promise((resolve) => {
47921
- this.collectionListResolvers.push(resolve);
47922
- this.ws.send(JSON.stringify({ type: "list_collections" }));
47923
- setTimeout(() => {
47924
- const idx = this.collectionListResolvers.indexOf(resolve);
47925
- if (idx !== -1) {
47926
- this.collectionListResolvers.splice(idx, 1);
47887
+ const reqId = this.makeReqId();
47888
+ this.collectionListResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47889
+ if (this.collectionListResolvers.delete(reqId))
47927
47890
  resolve([]);
47928
- }
47929
- }, 5000);
47891
+ }, 5000) });
47892
+ this.ws.send(JSON.stringify({ type: "list_collections", _reqId: reqId }));
47930
47893
  });
47931
47894
  }
47932
47895
  async graphQuery(cypher) {
47933
47896
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
47934
47897
  return [];
47935
47898
  return new Promise((resolve) => {
47936
- this.graphResultResolvers.push(resolve);
47937
- this.ws.send(JSON.stringify({ type: "graph_query", cypher }));
47938
- setTimeout(() => {
47939
- const idx = this.graphResultResolvers.indexOf(resolve);
47940
- if (idx !== -1) {
47941
- this.graphResultResolvers.splice(idx, 1);
47899
+ const reqId = this.makeReqId();
47900
+ this.graphResultResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47901
+ if (this.graphResultResolvers.delete(reqId))
47942
47902
  resolve([]);
47943
- }
47944
- }, 5000);
47903
+ }, 5000) });
47904
+ this.ws.send(JSON.stringify({ type: "graph_query", cypher, _reqId: reqId }));
47945
47905
  });
47946
47906
  }
47947
47907
  async graphExecute(cypher) {
47948
47908
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
47949
47909
  return [];
47950
47910
  return new Promise((resolve) => {
47951
- this.graphResultResolvers.push(resolve);
47952
- this.ws.send(JSON.stringify({ type: "graph_execute", cypher }));
47953
- setTimeout(() => {
47954
- const idx = this.graphResultResolvers.indexOf(resolve);
47955
- if (idx !== -1) {
47956
- this.graphResultResolvers.splice(idx, 1);
47911
+ const reqId = this.makeReqId();
47912
+ this.graphResultResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47913
+ if (this.graphResultResolvers.delete(reqId))
47957
47914
  resolve([]);
47958
- }
47959
- }, 5000);
47915
+ }, 5000) });
47916
+ this.ws.send(JSON.stringify({ type: "graph_execute", cypher, _reqId: reqId }));
47960
47917
  });
47961
47918
  }
47962
47919
  async shareContext(summary, filesRead, keyFindings, tags) {
@@ -47968,85 +47925,70 @@ class BrokerClient {
47968
47925
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
47969
47926
  return [];
47970
47927
  return new Promise((resolve) => {
47971
- this.contextResultsResolvers.push(resolve);
47972
- this.ws.send(JSON.stringify({ type: "get_context", query }));
47973
- setTimeout(() => {
47974
- const idx = this.contextResultsResolvers.indexOf(resolve);
47975
- if (idx !== -1) {
47976
- this.contextResultsResolvers.splice(idx, 1);
47928
+ const reqId = this.makeReqId();
47929
+ this.contextResultsResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47930
+ if (this.contextResultsResolvers.delete(reqId))
47977
47931
  resolve([]);
47978
- }
47979
- }, 5000);
47932
+ }, 5000) });
47933
+ this.ws.send(JSON.stringify({ type: "get_context", query, _reqId: reqId }));
47980
47934
  });
47981
47935
  }
47982
47936
  async listContexts() {
47983
47937
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
47984
47938
  return [];
47985
47939
  return new Promise((resolve) => {
47986
- this.contextListResolvers.push(resolve);
47987
- this.ws.send(JSON.stringify({ type: "list_contexts" }));
47988
- setTimeout(() => {
47989
- const idx = this.contextListResolvers.indexOf(resolve);
47990
- if (idx !== -1) {
47991
- this.contextListResolvers.splice(idx, 1);
47940
+ const reqId = this.makeReqId();
47941
+ this.contextListResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47942
+ if (this.contextListResolvers.delete(reqId))
47992
47943
  resolve([]);
47993
- }
47994
- }, 5000);
47944
+ }, 5000) });
47945
+ this.ws.send(JSON.stringify({ type: "list_contexts", _reqId: reqId }));
47995
47946
  });
47996
47947
  }
47997
47948
  async createTask(title, assignee, priority, tags) {
47998
47949
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
47999
47950
  return null;
48000
47951
  return new Promise((resolve) => {
48001
- this.taskCreatedResolvers.push(resolve);
48002
- this.ws.send(JSON.stringify({ type: "create_task", title, assignee, priority, tags }));
48003
- setTimeout(() => {
48004
- const idx = this.taskCreatedResolvers.indexOf(resolve);
48005
- if (idx !== -1) {
48006
- this.taskCreatedResolvers.splice(idx, 1);
47952
+ const reqId = this.makeReqId();
47953
+ this.taskCreatedResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47954
+ if (this.taskCreatedResolvers.delete(reqId))
48007
47955
  resolve(null);
48008
- }
48009
- }, 5000);
47956
+ }, 5000) });
47957
+ this.ws.send(JSON.stringify({ type: "create_task", title, assignee, priority, tags, _reqId: reqId }));
48010
47958
  });
48011
47959
  }
48012
47960
  async claimTask(id) {
48013
47961
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
48014
47962
  return;
48015
- this.ws.send(JSON.stringify({ type: "claim_task", id }));
47963
+ this.ws.send(JSON.stringify({ type: "claim_task", taskId: id }));
48016
47964
  }
48017
47965
  async completeTask(id, result) {
48018
47966
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
48019
47967
  return;
48020
- this.ws.send(JSON.stringify({ type: "complete_task", id, result }));
47968
+ this.ws.send(JSON.stringify({ type: "complete_task", taskId: id, result }));
48021
47969
  }
48022
47970
  async listTasks(status, assignee) {
48023
47971
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
48024
47972
  return [];
48025
47973
  return new Promise((resolve) => {
48026
- this.taskListResolvers.push(resolve);
48027
- this.ws.send(JSON.stringify({ type: "list_tasks", status, assignee }));
48028
- setTimeout(() => {
48029
- const idx = this.taskListResolvers.indexOf(resolve);
48030
- if (idx !== -1) {
48031
- this.taskListResolvers.splice(idx, 1);
47974
+ const reqId = this.makeReqId();
47975
+ this.taskListResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47976
+ if (this.taskListResolvers.delete(reqId))
48032
47977
  resolve([]);
48033
- }
48034
- }, 5000);
47978
+ }, 5000) });
47979
+ this.ws.send(JSON.stringify({ type: "list_tasks", status, assignee, _reqId: reqId }));
48035
47980
  });
48036
47981
  }
48037
47982
  async meshQuery(sql) {
48038
47983
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
48039
47984
  return null;
48040
47985
  return new Promise((resolve) => {
48041
- this.meshQueryResolvers.push(resolve);
48042
- this.ws.send(JSON.stringify({ type: "mesh_query", sql }));
48043
- setTimeout(() => {
48044
- const idx = this.meshQueryResolvers.indexOf(resolve);
48045
- if (idx !== -1) {
48046
- this.meshQueryResolvers.splice(idx, 1);
47986
+ const reqId = this.makeReqId();
47987
+ this.meshQueryResolvers.set(reqId, { resolve, timer: setTimeout(() => {
47988
+ if (this.meshQueryResolvers.delete(reqId))
48047
47989
  resolve(null);
48048
- }
48049
- }, 5000);
47990
+ }, 5000) });
47991
+ this.ws.send(JSON.stringify({ type: "mesh_query", sql, _reqId: reqId }));
48050
47992
  });
48051
47993
  }
48052
47994
  async meshExecute(sql) {
@@ -48058,30 +48000,24 @@ class BrokerClient {
48058
48000
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
48059
48001
  return [];
48060
48002
  return new Promise((resolve) => {
48061
- this.meshSchemaResolvers.push(resolve);
48062
- this.ws.send(JSON.stringify({ type: "mesh_schema" }));
48063
- setTimeout(() => {
48064
- const idx = this.meshSchemaResolvers.indexOf(resolve);
48065
- if (idx !== -1) {
48066
- this.meshSchemaResolvers.splice(idx, 1);
48003
+ const reqId = this.makeReqId();
48004
+ this.meshSchemaResolvers.set(reqId, { resolve, timer: setTimeout(() => {
48005
+ if (this.meshSchemaResolvers.delete(reqId))
48067
48006
  resolve([]);
48068
- }
48069
- }, 5000);
48007
+ }, 5000) });
48008
+ this.ws.send(JSON.stringify({ type: "mesh_schema", _reqId: reqId }));
48070
48009
  });
48071
48010
  }
48072
48011
  async createStream(name) {
48073
48012
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
48074
48013
  return null;
48075
48014
  return new Promise((resolve) => {
48076
- this.streamCreatedResolvers.push(resolve);
48077
- this.ws.send(JSON.stringify({ type: "create_stream", name }));
48078
- setTimeout(() => {
48079
- const idx = this.streamCreatedResolvers.indexOf(resolve);
48080
- if (idx !== -1) {
48081
- this.streamCreatedResolvers.splice(idx, 1);
48015
+ const reqId = this.makeReqId();
48016
+ this.streamCreatedResolvers.set(reqId, { resolve, timer: setTimeout(() => {
48017
+ if (this.streamCreatedResolvers.delete(reqId))
48082
48018
  resolve(null);
48083
- }
48084
- }, 5000);
48019
+ }, 5000) });
48020
+ this.ws.send(JSON.stringify({ type: "create_stream", name, _reqId: reqId }));
48085
48021
  });
48086
48022
  }
48087
48023
  async publish(stream, data) {
@@ -48103,15 +48039,12 @@ class BrokerClient {
48103
48039
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
48104
48040
  return [];
48105
48041
  return new Promise((resolve) => {
48106
- this.streamListResolvers.push(resolve);
48107
- this.ws.send(JSON.stringify({ type: "list_streams" }));
48108
- setTimeout(() => {
48109
- const idx = this.streamListResolvers.indexOf(resolve);
48110
- if (idx !== -1) {
48111
- this.streamListResolvers.splice(idx, 1);
48042
+ const reqId = this.makeReqId();
48043
+ this.streamListResolvers.set(reqId, { resolve, timer: setTimeout(() => {
48044
+ if (this.streamListResolvers.delete(reqId))
48112
48045
  resolve([]);
48113
- }
48114
- }, 5000);
48046
+ }, 5000) });
48047
+ this.ws.send(JSON.stringify({ type: "list_streams", _reqId: reqId }));
48115
48048
  });
48116
48049
  }
48117
48050
  onStreamData(handler) {
@@ -48122,20 +48055,17 @@ class BrokerClient {
48122
48055
  this.stateChangeHandlers.add(handler);
48123
48056
  return () => this.stateChangeHandlers.delete(handler);
48124
48057
  }
48125
- meshInfoResolvers = [];
48058
+ meshInfoResolvers = new Map;
48126
48059
  async meshInfo() {
48127
48060
  if (!this.ws || this.ws.readyState !== this.ws.OPEN)
48128
48061
  return null;
48129
48062
  return new Promise((resolve) => {
48130
- this.meshInfoResolvers.push(resolve);
48131
- this.ws.send(JSON.stringify({ type: "mesh_info" }));
48132
- setTimeout(() => {
48133
- const idx = this.meshInfoResolvers.indexOf(resolve);
48134
- if (idx !== -1) {
48135
- this.meshInfoResolvers.splice(idx, 1);
48063
+ const reqId = this.makeReqId();
48064
+ this.meshInfoResolvers.set(reqId, { resolve, timer: setTimeout(() => {
48065
+ if (this.meshInfoResolvers.delete(reqId))
48136
48066
  resolve(null);
48137
- }
48138
- }, 5000);
48067
+ }, 5000) });
48068
+ this.ws.send(JSON.stringify({ type: "mesh_info", _reqId: reqId }));
48139
48069
  });
48140
48070
  }
48141
48071
  close() {
@@ -48151,7 +48081,26 @@ class BrokerClient {
48151
48081
  }
48152
48082
  this.setConnStatus("closed");
48153
48083
  }
48084
+ resolveFromMap(map2, reqId, value) {
48085
+ let entry = reqId ? map2.get(reqId) : undefined;
48086
+ if (!entry) {
48087
+ const first = map2.entries().next().value;
48088
+ if (first) {
48089
+ entry = first[1];
48090
+ map2.delete(first[0]);
48091
+ }
48092
+ } else {
48093
+ map2.delete(reqId);
48094
+ }
48095
+ if (entry) {
48096
+ clearTimeout(entry.timer);
48097
+ entry.resolve(value);
48098
+ return true;
48099
+ }
48100
+ return false;
48101
+ }
48154
48102
  handleServerMessage(msg) {
48103
+ const msgReqId = msg._reqId;
48155
48104
  if (msg.type === "ack") {
48156
48105
  const pending = this.pendingSends.get(String(msg.id ?? ""));
48157
48106
  if (pending) {
@@ -48165,9 +48114,7 @@ class BrokerClient {
48165
48114
  }
48166
48115
  if (msg.type === "peers_list") {
48167
48116
  const peers = msg.peers ?? [];
48168
- const resolver = this.listPeersResolvers.shift();
48169
- if (resolver)
48170
- resolver(peers);
48117
+ this.resolveFromMap(this.listPeersResolvers, msgReqId, peers);
48171
48118
  return;
48172
48119
  }
48173
48120
  if (msg.type === "push") {
@@ -48221,26 +48168,21 @@ class BrokerClient {
48221
48168
  return;
48222
48169
  }
48223
48170
  if (msg.type === "state_result") {
48224
- const resolver = this.stateResolvers.shift();
48225
- if (resolver) {
48226
- if (msg.key) {
48227
- resolver({
48228
- key: String(msg.key),
48229
- value: msg.value,
48230
- updatedBy: String(msg.updatedBy ?? ""),
48231
- updatedAt: String(msg.updatedAt ?? "")
48232
- });
48233
- } else {
48234
- resolver(null);
48235
- }
48171
+ if (msg.key) {
48172
+ this.resolveFromMap(this.stateResolvers, msgReqId, {
48173
+ key: String(msg.key),
48174
+ value: msg.value,
48175
+ updatedBy: String(msg.updatedBy ?? ""),
48176
+ updatedAt: String(msg.updatedAt ?? "")
48177
+ });
48178
+ } else {
48179
+ this.resolveFromMap(this.stateResolvers, msgReqId, null);
48236
48180
  }
48237
48181
  return;
48238
48182
  }
48239
48183
  if (msg.type === "state_list") {
48240
48184
  const entries = msg.entries ?? [];
48241
- const resolver = this.stateListResolvers.shift();
48242
- if (resolver)
48243
- resolver(entries);
48185
+ this.resolveFromMap(this.stateListResolvers, msgReqId, entries);
48244
48186
  return;
48245
48187
  }
48246
48188
  if (msg.type === "state_change") {
@@ -48257,147 +48199,107 @@ class BrokerClient {
48257
48199
  return;
48258
48200
  }
48259
48201
  if (msg.type === "memory_stored") {
48260
- const resolver = this.memoryStoreResolvers.shift();
48261
- if (resolver)
48262
- resolver(msg.id ? String(msg.id) : null);
48202
+ this.resolveFromMap(this.memoryStoreResolvers, msgReqId, msg.id ? String(msg.id) : null);
48263
48203
  return;
48264
48204
  }
48265
48205
  if (msg.type === "memory_results") {
48266
48206
  const memories = msg.memories ?? [];
48267
- const resolver = this.memoryRecallResolvers.shift();
48268
- if (resolver)
48269
- resolver(memories);
48207
+ this.resolveFromMap(this.memoryRecallResolvers, msgReqId, memories);
48270
48208
  return;
48271
48209
  }
48272
48210
  if (msg.type === "message_status_result") {
48273
- const resolver = this.messageStatusResolvers.shift();
48274
- if (resolver)
48275
- resolver(msg);
48211
+ this.resolveFromMap(this.messageStatusResolvers, msgReqId, msg);
48276
48212
  return;
48277
48213
  }
48278
48214
  if (msg.type === "file_url") {
48279
- const resolver = this.fileUrlResolvers.shift();
48280
- if (resolver) {
48281
- if (msg.url) {
48282
- resolver({
48283
- url: String(msg.url),
48284
- name: String(msg.name ?? ""),
48285
- encrypted: msg.encrypted ? true : undefined,
48286
- sealedKey: msg.sealedKey ? String(msg.sealedKey) : undefined
48287
- });
48288
- } else {
48289
- resolver(null);
48290
- }
48215
+ if (msg.url) {
48216
+ this.resolveFromMap(this.fileUrlResolvers, msgReqId, {
48217
+ url: String(msg.url),
48218
+ name: String(msg.name ?? ""),
48219
+ encrypted: msg.encrypted ? true : undefined,
48220
+ sealedKey: msg.sealedKey ? String(msg.sealedKey) : undefined
48221
+ });
48222
+ } else {
48223
+ this.resolveFromMap(this.fileUrlResolvers, msgReqId, null);
48291
48224
  }
48292
48225
  return;
48293
48226
  }
48294
48227
  if (msg.type === "file_list") {
48295
48228
  const files = msg.files ?? [];
48296
- const resolver = this.fileListResolvers.shift();
48297
- if (resolver)
48298
- resolver(files);
48229
+ this.resolveFromMap(this.fileListResolvers, msgReqId, files);
48299
48230
  return;
48300
48231
  }
48301
48232
  if (msg.type === "file_status_result") {
48302
48233
  const accesses = msg.accesses ?? [];
48303
- const resolver = this.fileStatusResolvers.shift();
48304
- if (resolver)
48305
- resolver(accesses);
48234
+ this.resolveFromMap(this.fileStatusResolvers, msgReqId, accesses);
48306
48235
  return;
48307
48236
  }
48308
48237
  if (msg.type === "grant_file_access_ok") {
48309
- const resolver = this.grantFileAccessResolvers.shift();
48310
- if (resolver)
48311
- resolver(true);
48238
+ this.resolveFromMap(this.grantFileAccessResolvers, msgReqId, true);
48312
48239
  return;
48313
48240
  }
48314
48241
  if (msg.type === "vector_stored") {
48315
- const resolver = this.vectorStoredResolvers.shift();
48316
- if (resolver)
48317
- resolver(msg.id ? String(msg.id) : null);
48242
+ this.resolveFromMap(this.vectorStoredResolvers, msgReqId, msg.id ? String(msg.id) : null);
48318
48243
  return;
48319
48244
  }
48320
48245
  if (msg.type === "vector_results") {
48321
48246
  const results = msg.results ?? [];
48322
- const resolver = this.vectorResultsResolvers.shift();
48323
- if (resolver)
48324
- resolver(results);
48247
+ this.resolveFromMap(this.vectorResultsResolvers, msgReqId, results);
48325
48248
  return;
48326
48249
  }
48327
48250
  if (msg.type === "collection_list") {
48328
48251
  const collections = msg.collections ?? [];
48329
- const resolver = this.collectionListResolvers.shift();
48330
- if (resolver)
48331
- resolver(collections);
48252
+ this.resolveFromMap(this.collectionListResolvers, msgReqId, collections);
48332
48253
  return;
48333
48254
  }
48334
48255
  if (msg.type === "graph_result") {
48335
- const rows = msg.rows ?? [];
48336
- const resolver = this.graphResultResolvers.shift();
48337
- if (resolver)
48338
- resolver(rows);
48256
+ const rows = msg.records ?? [];
48257
+ this.resolveFromMap(this.graphResultResolvers, msgReqId, rows);
48339
48258
  return;
48340
48259
  }
48341
48260
  if (msg.type === "context_list") {
48342
48261
  const contexts = msg.contexts ?? [];
48343
- const resolver = this.contextListResolvers.shift();
48344
- if (resolver)
48345
- resolver(contexts);
48262
+ this.resolveFromMap(this.contextListResolvers, msgReqId, contexts);
48346
48263
  return;
48347
48264
  }
48348
48265
  if (msg.type === "context_results") {
48349
48266
  const contexts = msg.contexts ?? [];
48350
- const resolver = this.contextResultsResolvers.shift();
48351
- if (resolver)
48352
- resolver(contexts);
48267
+ this.resolveFromMap(this.contextResultsResolvers, msgReqId, contexts);
48353
48268
  return;
48354
48269
  }
48355
48270
  if (msg.type === "task_created") {
48356
- const resolver = this.taskCreatedResolvers.shift();
48357
- if (resolver)
48358
- resolver(msg.id ? String(msg.id) : null);
48271
+ this.resolveFromMap(this.taskCreatedResolvers, msgReqId, msg.id ? String(msg.id) : null);
48359
48272
  return;
48360
48273
  }
48361
48274
  if (msg.type === "task_list") {
48362
48275
  const tasks = msg.tasks ?? [];
48363
- const resolver = this.taskListResolvers.shift();
48364
- if (resolver)
48365
- resolver(tasks);
48276
+ this.resolveFromMap(this.taskListResolvers, msgReqId, tasks);
48366
48277
  return;
48367
48278
  }
48368
48279
  if (msg.type === "mesh_query_result") {
48369
- const resolver = this.meshQueryResolvers.shift();
48370
- if (resolver) {
48371
- if (msg.columns) {
48372
- resolver({
48373
- columns: msg.columns ?? [],
48374
- rows: msg.rows ?? [],
48375
- rowCount: msg.rowCount ?? 0
48376
- });
48377
- } else {
48378
- resolver(null);
48379
- }
48280
+ if (msg.columns) {
48281
+ this.resolveFromMap(this.meshQueryResolvers, msgReqId, {
48282
+ columns: msg.columns ?? [],
48283
+ rows: msg.rows ?? [],
48284
+ rowCount: msg.rowCount ?? 0
48285
+ });
48286
+ } else {
48287
+ this.resolveFromMap(this.meshQueryResolvers, msgReqId, null);
48380
48288
  }
48381
48289
  return;
48382
48290
  }
48383
48291
  if (msg.type === "mesh_schema_result") {
48384
48292
  const tables = msg.tables ?? [];
48385
- const resolver = this.meshSchemaResolvers.shift();
48386
- if (resolver)
48387
- resolver(tables);
48293
+ this.resolveFromMap(this.meshSchemaResolvers, msgReqId, tables);
48388
48294
  return;
48389
48295
  }
48390
48296
  if (msg.type === "stream_created") {
48391
- const resolver = this.streamCreatedResolvers.shift();
48392
- if (resolver)
48393
- resolver(msg.id ? String(msg.id) : null);
48297
+ this.resolveFromMap(this.streamCreatedResolvers, msgReqId, msg.id ? String(msg.id) : null);
48394
48298
  return;
48395
48299
  }
48396
48300
  if (msg.type === "stream_list") {
48397
48301
  const streams = msg.streams ?? [];
48398
- const resolver = this.streamListResolvers.shift();
48399
- if (resolver)
48400
- resolver(streams);
48302
+ this.resolveFromMap(this.streamListResolvers, msgReqId, streams);
48401
48303
  return;
48402
48304
  }
48403
48305
  if (msg.type === "stream_data") {
@@ -48414,14 +48316,13 @@ class BrokerClient {
48414
48316
  return;
48415
48317
  }
48416
48318
  if (msg.type === "mesh_info_result") {
48417
- const resolver = this.meshInfoResolvers.shift();
48418
- if (resolver)
48419
- resolver(msg);
48319
+ this.resolveFromMap(this.meshInfoResolvers, msgReqId, msg);
48420
48320
  return;
48421
48321
  }
48422
48322
  if (msg.type === "error") {
48423
48323
  this.debug(`broker error: ${msg.code} ${msg.message}`);
48424
48324
  const id = msg.id ? String(msg.id) : null;
48325
+ let handledByPendingSend = false;
48425
48326
  if (id) {
48426
48327
  const pending = this.pendingSends.get(id);
48427
48328
  if (pending) {
@@ -48430,6 +48331,43 @@ class BrokerClient {
48430
48331
  error: `${msg.code}: ${msg.message}`
48431
48332
  });
48432
48333
  this.pendingSends.delete(id);
48334
+ handledByPendingSend = true;
48335
+ }
48336
+ }
48337
+ if (!handledByPendingSend) {
48338
+ const allMaps = [
48339
+ [this.stateResolvers, null],
48340
+ [this.stateListResolvers, []],
48341
+ [this.memoryStoreResolvers, null],
48342
+ [this.memoryRecallResolvers, []],
48343
+ [this.fileUrlResolvers, null],
48344
+ [this.fileListResolvers, []],
48345
+ [this.fileStatusResolvers, []],
48346
+ [this.graphResultResolvers, []],
48347
+ [this.vectorStoredResolvers, null],
48348
+ [this.vectorResultsResolvers, []],
48349
+ [this.taskListResolvers, []],
48350
+ [this.meshQueryResolvers, null],
48351
+ [this.contextResultsResolvers, []],
48352
+ [this.contextListResolvers, []],
48353
+ [this.streamListResolvers, []],
48354
+ [this.messageStatusResolvers, null],
48355
+ [this.grantFileAccessResolvers, false],
48356
+ [this.collectionListResolvers, []],
48357
+ [this.meshSchemaResolvers, []],
48358
+ [this.taskCreatedResolvers, null],
48359
+ [this.streamCreatedResolvers, null],
48360
+ [this.listPeersResolvers, []],
48361
+ [this.meshInfoResolvers, null]
48362
+ ];
48363
+ for (const [map2, defaultVal] of allMaps) {
48364
+ const first = map2.entries().next().value;
48365
+ if (first) {
48366
+ map2.delete(first[0]);
48367
+ clearTimeout(first[1].timer);
48368
+ first[1].resolve(defaultVal);
48369
+ break;
48370
+ }
48433
48371
  }
48434
48372
  }
48435
48373
  }
@@ -48777,10 +48715,15 @@ ${peerLines.join(`
48777
48715
  const { id } = args ?? {};
48778
48716
  if (!id)
48779
48717
  return text("message_status: `id` required", true);
48780
- const client = allClients()[0];
48781
- if (!client)
48718
+ const clients2 = allClients();
48719
+ if (!clients2.length)
48782
48720
  return text("message_status: not connected", true);
48783
- const result = await client.messageStatus(id);
48721
+ let result = null;
48722
+ for (const c of clients2) {
48723
+ result = await c.messageStatus(id);
48724
+ if (result)
48725
+ break;
48726
+ }
48784
48727
  if (!result)
48785
48728
  return text(`Message ${id} not found or timed out.`);
48786
48729
  const recipientLines = result.recipients.map((r) => ` - ${r.name} (${r.pubkey.slice(0, 12)}…): ${r.status}`);
@@ -50458,7 +50401,7 @@ init_config();
50458
50401
  // package.json
50459
50402
  var package_default = {
50460
50403
  name: "claudemesh-cli",
50461
- version: "0.6.4",
50404
+ version: "0.6.6",
50462
50405
  description: "Claude Code MCP client for claudemesh — peer mesh messaging between Claude sessions.",
50463
50406
  keywords: [
50464
50407
  "claude-code",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claudemesh-cli",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "description": "Claude Code MCP client for claudemesh — peer mesh messaging between Claude sessions.",
5
5
  "keywords": [
6
6
  "claude-code",