@cfio/cohort-sync 0.14.0 → 0.15.0

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/dist/index.js CHANGED
@@ -13372,7 +13372,7 @@ function dumpCtx(ctx) {
13372
13372
  function dumpEvent(event) {
13373
13373
  return dumpCtx(event);
13374
13374
  }
13375
- var PLUGIN_VERSION = true ? "0.14.0" : "unknown";
13375
+ var PLUGIN_VERSION = true ? "0.15.0" : "unknown";
13376
13376
  function resolveGatewayToken(api) {
13377
13377
  const token = api.config?.gateway?.auth?.token;
13378
13378
  return typeof token === "string" ? token : null;
@@ -13988,28 +13988,36 @@ function registerHookHandlers(api, logger, getState) {
13988
13988
  state.logger.warn(`cohort-sync: before_reset activity failed: ${String(err)}`);
13989
13989
  }
13990
13990
  });
13991
- api.on("gateway_stop", async (_event, _ctx) => {
13991
+ api.on("gateway_stop", async (event, _ctx) => {
13992
13992
  const state = getState();
13993
13993
  if (!state) return;
13994
13994
  const { cfg, tracker, logger: log, config } = state;
13995
- log.debug("cohort-sync: hook: gateway_stop", { bridgeState: Object.fromEntries(getChannelAgentBridge()) });
13995
+ const reason = typeof event?.reason === "string" ? event.reason : "";
13996
+ const isRestart = reason.toLowerCase().includes("restart");
13997
+ log.debug("cohort-sync: hook: gateway_stop", {
13998
+ reason,
13999
+ isRestart,
14000
+ bridgeState: Object.fromEntries(getChannelAgentBridge())
14001
+ });
13996
14002
  if (state.keepaliveInterval) {
13997
14003
  clearInterval(state.keepaliveInterval);
13998
14004
  state.keepaliveInterval = null;
13999
14005
  }
14000
14006
  state.activityBatch.drain();
14001
- const shutdownConfigIds = (config?.agents?.list ?? []).map((a) => a.id);
14002
- const allAgentIds = shutdownConfigIds.includes("main") ? shutdownConfigIds : ["main", ...shutdownConfigIds];
14003
- for (const agentId of allAgentIds) {
14004
- const agentName = state.resolveAgentName(agentId);
14005
- try {
14006
- tracker.updateStatus(agentName, "unreachable");
14007
- const snapshot = tracker.getTelemetrySnapshot(agentName);
14008
- if (snapshot) {
14009
- await pushTelemetry(cfg.apiKey, { ...snapshot, pluginVersion: PLUGIN_VERSION, commandsRestartEnabled: cfg.commandsRestartEnabled, ...state.latestPluginVersion ? { latestPluginVersion: state.latestPluginVersion } : {} });
14007
+ if (!isRestart) {
14008
+ const shutdownConfigIds = (config?.agents?.list ?? []).map((a) => a.id);
14009
+ const allAgentIds = shutdownConfigIds.includes("main") ? shutdownConfigIds : ["main", ...shutdownConfigIds];
14010
+ for (const agentId of allAgentIds) {
14011
+ const agentName = state.resolveAgentName(agentId);
14012
+ try {
14013
+ tracker.updateStatus(agentName, "unreachable");
14014
+ const snapshot = tracker.getTelemetrySnapshot(agentName);
14015
+ if (snapshot) {
14016
+ await pushTelemetry(cfg.apiKey, { ...snapshot, pluginVersion: PLUGIN_VERSION, commandsRestartEnabled: cfg.commandsRestartEnabled, ...state.latestPluginVersion ? { latestPluginVersion: state.latestPluginVersion } : {} });
14017
+ }
14018
+ } catch (err) {
14019
+ log.warn(`cohort-sync: final unreachable push failed for ${agentName}: ${String(err)}`);
14010
14020
  }
14011
- } catch (err) {
14012
- log.warn(`cohort-sync: final unreachable push failed for ${agentName}: ${String(err)}`);
14013
14021
  }
14014
14022
  }
14015
14023
  saveSessionsToDisk(tracker, state.stateFilePath);
@@ -14018,14 +14026,18 @@ function registerHookHandlers(api, logger, getState) {
14018
14026
  state.persistentGwClient = null;
14019
14027
  state.gwClientInitialized = false;
14020
14028
  }
14021
- try {
14022
- await markAllUnreachable(cfg, log);
14023
- } catch (err) {
14024
- log.warn(`cohort-sync: markAllUnreachable failed: ${String(err)}`);
14029
+ if (!isRestart) {
14030
+ try {
14031
+ await markAllUnreachable(cfg, log);
14032
+ } catch (err) {
14033
+ log.warn(`cohort-sync: markAllUnreachable failed: ${String(err)}`);
14034
+ }
14025
14035
  }
14026
14036
  tracker.clear();
14027
14037
  closeBridge();
14028
- log.info("cohort-sync: gateway stopped, all resources cleaned up");
14038
+ log.info(
14039
+ isRestart ? "cohort-sync: gateway restarting, resources cleaned up (agents kept online)" : "cohort-sync: gateway stopped, all resources cleaned up"
14040
+ );
14029
14041
  });
14030
14042
  }
14031
14043
  function initializeHookState(api, cfg) {
@@ -55,5 +55,5 @@
55
55
  }
56
56
  }
57
57
  },
58
- "version": "0.14.0"
58
+ "version": "0.15.0"
59
59
  }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfio/cohort-sync",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "OpenClaw plugin — syncs agent telemetry, sessions, and activity to the Cohort dashboard",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfio/cohort-sync",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "OpenClaw plugin — syncs agent telemetry, sessions, and activity to the Cohort dashboard",
5
5
  "license": "MIT",
6
6
  "homepage": "https://docs.cohort.bot/gateway",