@p697/clawket 0.6.1 → 0.6.2

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 +49 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6152,9 +6152,8 @@ var HermesRelayRuntime = class {
6152
6152
  } else {
6153
6153
  const payload = await response.json();
6154
6154
  if (!payload?.hasBridge) {
6155
- this.log("bridge status probe reported hasBridge=false; restarting relay socket");
6156
- this.relaySocket?.close();
6157
- this.bridgeSocket?.close();
6155
+ this.log("bridge status probe reported hasBridge=false; recycling relay socket");
6156
+ this.recycleRelaySocket("bridge status probe reported hasBridge=false");
6158
6157
  return;
6159
6158
  }
6160
6159
  }
@@ -6244,6 +6243,26 @@ var HermesRelayRuntime = class {
6244
6243
  clearTimeout(this.pendingBridgeHealthProbe.timeout);
6245
6244
  this.pendingBridgeHealthProbe = null;
6246
6245
  }
6246
+ recycleRelaySocket(reason) {
6247
+ const relay = this.relaySocket;
6248
+ if (!relay)
6249
+ return;
6250
+ this.relaySocket = null;
6251
+ this.clearBridgeStatusProbe();
6252
+ this.clearPendingBridgeHealthProbe();
6253
+ this.updateSnapshot({
6254
+ relayConnected: false,
6255
+ bridgeConnected: this.bridgeSocket?.readyState === WebSocket2.OPEN,
6256
+ lastError: reason
6257
+ });
6258
+ try {
6259
+ relay.close();
6260
+ } catch {
6261
+ }
6262
+ if (!this.stopped) {
6263
+ this.scheduleRelayReconnect();
6264
+ }
6265
+ }
6247
6266
  isRelayOpen() {
6248
6267
  return this.relaySocket?.readyState === WebSocket2.OPEN;
6249
6268
  }
@@ -9249,6 +9268,7 @@ function decidePairServiceAction(paired, service) {
9249
9268
  }
9250
9269
 
9251
9270
  // apps/bridge-cli/src/index.ts
9271
+ var HERMES_SERVICE_WATCHDOG_INTERVAL_MS = 3e4;
9252
9272
  async function main() {
9253
9273
  const [, , command = "help", ...args] = process.argv;
9254
9274
  const isServiceMode = hasFlag(args, "--service");
@@ -9426,6 +9446,9 @@ async function main() {
9426
9446
  instanceId: config.instanceId,
9427
9447
  serviceMode: isServiceMode
9428
9448
  });
9449
+ const hermesServiceWatchdog = isServiceMode ? startHermesServiceWatchdog((line) => {
9450
+ emitRuntimeLine(`[hermes-service] ${line}`);
9451
+ }) : null;
9429
9452
  if (isServiceMode) {
9430
9453
  await restoreHermesServiceRuntime((line) => {
9431
9454
  emitRuntimeLine(`[hermes-service] ${line}`);
@@ -9435,6 +9458,9 @@ async function main() {
9435
9458
  process.off("SIGINT", shutdown);
9436
9459
  process.off("SIGTERM", shutdown);
9437
9460
  await runtime.stop();
9461
+ if (hermesServiceWatchdog) {
9462
+ clearInterval(hermesServiceWatchdog);
9463
+ }
9438
9464
  unregisterRuntimeProcess(process.pid);
9439
9465
  if (isServiceMode) {
9440
9466
  clearServiceState(process.pid);
@@ -10288,6 +10314,16 @@ async function keepHermesBridgeAlive(bridge) {
10288
10314
  });
10289
10315
  }
10290
10316
  async function restoreHermesServiceRuntime(log) {
10317
+ await restoreHermesServiceRuntimeInternal(log, { silentIfHealthy: false });
10318
+ }
10319
+ function startHermesServiceWatchdog(log) {
10320
+ const timer = setInterval(() => {
10321
+ void restoreHermesServiceRuntimeInternal(log, { silentIfHealthy: true });
10322
+ }, HERMES_SERVICE_WATCHDOG_INTERVAL_MS);
10323
+ timer.unref?.();
10324
+ return timer;
10325
+ }
10326
+ async function restoreHermesServiceRuntimeInternal(log, options) {
10291
10327
  const bridgeConfig = readHermesBridgeCliConfig();
10292
10328
  const relayConfig = readHermesRelayConfig();
10293
10329
  if (!bridgeConfig && !relayConfig) {
@@ -10302,9 +10338,11 @@ async function restoreHermesServiceRuntime(log) {
10302
10338
  config: bridgeConfig,
10303
10339
  replaceExisting: false
10304
10340
  });
10305
- log(
10306
- bridgePid == null ? "Hermes bridge runtime already running." : `Started Hermes bridge runtime (pid ${bridgePid}).`
10307
- );
10341
+ if (bridgePid != null || !options.silentIfHealthy) {
10342
+ log(
10343
+ bridgePid == null ? "Hermes bridge runtime already running." : `Started Hermes bridge runtime (pid ${bridgePid}).`
10344
+ );
10345
+ }
10308
10346
  } catch (error) {
10309
10347
  log(`Hermes bridge restore failed: ${formatError3(error)}`);
10310
10348
  return;
@@ -10318,9 +10356,11 @@ async function restoreHermesServiceRuntime(log) {
10318
10356
  config: bridgeConfig,
10319
10357
  replaceExisting: false
10320
10358
  });
10321
- log(
10322
- relayPid == null ? "Hermes relay runtime already running." : `Started Hermes relay runtime (pid ${relayPid}).`
10323
- );
10359
+ if (relayPid != null || !options.silentIfHealthy) {
10360
+ log(
10361
+ relayPid == null ? "Hermes relay runtime already running." : `Started Hermes relay runtime (pid ${relayPid}).`
10362
+ );
10363
+ }
10324
10364
  } catch (error) {
10325
10365
  log(`Hermes relay restore failed: ${formatError3(error)}`);
10326
10366
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@p697/clawket",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-only",