claudemesh-cli 1.34.15 → 1.34.16

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.
@@ -104,7 +104,7 @@ __export(exports_urls, {
104
104
  VERSION: () => VERSION,
105
105
  URLS: () => URLS
106
106
  });
107
- var URLS, VERSION = "1.34.15", env;
107
+ var URLS, VERSION = "1.34.16", env;
108
108
  var init_urls = __esm(() => {
109
109
  URLS = {
110
110
  BROKER: process.env.CLAUDEMESH_BROKER_URL ?? "wss://ic.claudemesh.com/ws",
@@ -10899,6 +10899,10 @@ function connectWsWithBackoff(opts) {
10899
10899
  status = s;
10900
10900
  opts.onStatusChange?.(s);
10901
10901
  };
10902
+ const PING_INTERVAL_MS = 30000;
10903
+ const STALE_THRESHOLD_MS = 75000;
10904
+ let lastActivity = Date.now();
10905
+ let watchdogTimer = null;
10902
10906
  const openOnce = () => {
10903
10907
  if (closed)
10904
10908
  return Promise.reject(new Error("client_closed"));
@@ -10906,6 +10910,7 @@ function connectWsWithBackoff(opts) {
10906
10910
  log2("info", "ws_open_attempt", { url: opts.url });
10907
10911
  const sock = new WebSocket2(opts.url);
10908
10912
  ws = sock;
10913
+ lastActivity = Date.now();
10909
10914
  return new Promise((resolve, reject) => {
10910
10915
  sock.on("open", () => {
10911
10916
  log2("info", "ws_open_ok", { url: opts.url });
@@ -10928,6 +10933,7 @@ function connectWsWithBackoff(opts) {
10928
10933
  })();
10929
10934
  });
10930
10935
  sock.on("message", (raw) => {
10936
+ lastActivity = Date.now();
10931
10937
  let msg;
10932
10938
  try {
10933
10939
  msg = JSON.parse(raw.toString());
@@ -10942,16 +10948,43 @@ function connectWsWithBackoff(opts) {
10942
10948
  setStatus("open");
10943
10949
  reconnectAttempt = 0;
10944
10950
  log2("info", "ws_hello_acked", { url: opts.url });
10951
+ if (watchdogTimer)
10952
+ clearInterval(watchdogTimer);
10953
+ watchdogTimer = setInterval(() => {
10954
+ if (sock.readyState !== sock.OPEN)
10955
+ return;
10956
+ const idle = Date.now() - lastActivity;
10957
+ if (idle > STALE_THRESHOLD_MS) {
10958
+ log2("warn", "ws_stale_terminate", { url: opts.url, idle_ms: idle });
10959
+ try {
10960
+ sock.terminate();
10961
+ } catch {}
10962
+ return;
10963
+ }
10964
+ try {
10965
+ sock.ping();
10966
+ } catch {}
10967
+ }, PING_INTERVAL_MS);
10945
10968
  resolve();
10946
10969
  return;
10947
10970
  }
10948
10971
  opts.onMessage(msg);
10949
10972
  });
10973
+ sock.on("ping", () => {
10974
+ lastActivity = Date.now();
10975
+ });
10976
+ sock.on("pong", () => {
10977
+ lastActivity = Date.now();
10978
+ });
10950
10979
  sock.on("close", (code, reason) => {
10951
10980
  if (helloTimer) {
10952
10981
  clearTimeout(helloTimer);
10953
10982
  helloTimer = null;
10954
10983
  }
10984
+ if (watchdogTimer) {
10985
+ clearInterval(watchdogTimer);
10986
+ watchdogTimer = null;
10987
+ }
10955
10988
  const reasonStr = reason.toString("utf8");
10956
10989
  log2("warn", "ws_closed", { url: opts.url, code, reason: reasonStr, status });
10957
10990
  opts.onBeforeReconnect?.(code, reasonStr);
@@ -10995,6 +11028,10 @@ function connectWsWithBackoff(opts) {
10995
11028
  clearTimeout(helloTimer);
10996
11029
  helloTimer = null;
10997
11030
  }
11031
+ if (watchdogTimer) {
11032
+ clearInterval(watchdogTimer);
11033
+ watchdogTimer = null;
11034
+ }
10998
11035
  try {
10999
11036
  ws?.close();
11000
11037
  } catch {}
@@ -21249,4 +21286,4 @@ main().catch((err) => {
21249
21286
  process.exit(EXIT.INTERNAL_ERROR);
21250
21287
  });
21251
21288
 
21252
- //# debugId=89AC9B5F79C7438764756E2164756E21
21289
+ //# debugId=8D95F82FF933574E64756E2164756E21