@cfio/cohort-sync 0.11.3 → 0.11.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.
package/dist/index.js CHANGED
@@ -2722,6 +2722,22 @@ async function reconcileRoster(openClawAgents, cfg, logger) {
2722
2722
  const agentName = (cfg.agentNameMap?.[oc.id] ?? oc.identity?.name ?? oc.id).toLowerCase();
2723
2723
  const existing = cohortByName.get(agentName);
2724
2724
  if (!existing) {
2725
+ if (agentName === oc.id.toLowerCase() && oc.identity?.name) {
2726
+ const identityName = oc.identity.name.toLowerCase();
2727
+ if (cohortByName.has(identityName)) {
2728
+ logger.info(`cohort-sync: skipping phantom "${agentName}" \u2014 agent exists as "${identityName}"`);
2729
+ continue;
2730
+ }
2731
+ }
2732
+ if (agentName === oc.id.toLowerCase() && cohortByName.size > 0) {
2733
+ const alreadyRegistered = cohortAgents.some(
2734
+ (ca) => openClawNames.has(ca.name.toLowerCase()) && ca.name.toLowerCase() !== agentName
2735
+ );
2736
+ if (alreadyRegistered) {
2737
+ logger.info(`cohort-sync: skipping raw-ID agent "${agentName}" \u2014 identity-resolved agent already exists`);
2738
+ continue;
2739
+ }
2740
+ }
2725
2741
  try {
2726
2742
  await v1Post(cfg.apiUrl, cfg.apiKey, "/api/v1/agents", {
2727
2743
  name: agentName,
@@ -12046,13 +12062,14 @@ async function startNotificationSubscription(port, cfg, hooksToken, logger, gwCl
12046
12062
  );
12047
12063
  }
12048
12064
  const sourceMap = resolvedNameMap ?? cfg.agentNameMap ?? { main: "main" };
12049
- const reverseNameMap = {};
12065
+ const subscriptionTargets = /* @__PURE__ */ new Map();
12050
12066
  for (const [openclawId, cohortName] of Object.entries(sourceMap)) {
12051
- reverseNameMap[cohortName] = openclawId;
12067
+ subscriptionTargets.set(cohortName, openclawId);
12068
+ if (openclawId !== cohortName) {
12069
+ subscriptionTargets.set(openclawId, openclawId);
12070
+ }
12052
12071
  }
12053
- const agentNames = Array.from(new Set(Object.values(sourceMap)));
12054
- for (const agentName of agentNames) {
12055
- const openclawAgentId = reverseNameMap[agentName] ?? agentName;
12072
+ for (const [agentName, openclawAgentId] of subscriptionTargets) {
12056
12073
  logger.info(`cohort-sync: subscribing to notifications for agent "${agentName}" (openclawId: "${openclawAgentId}")`);
12057
12074
  let processing = false;
12058
12075
  const apiKeyHash = hashApiKey(cfg.apiKey);
@@ -13333,7 +13350,7 @@ function dumpCtx(ctx) {
13333
13350
  function dumpEvent(event) {
13334
13351
  return dumpCtx(event);
13335
13352
  }
13336
- var PLUGIN_VERSION = true ? "0.11.3" : "unknown";
13353
+ var PLUGIN_VERSION = true ? "0.11.5" : "unknown";
13337
13354
  function resolveGatewayToken(api) {
13338
13355
  const token = api.config?.gateway?.auth?.token;
13339
13356
  return typeof token === "string" ? token : null;
@@ -13514,7 +13531,8 @@ async function handleGatewayStart(event, state) {
13514
13531
  logger.debug("cohort-sync: no gateway token");
13515
13532
  logger.warn("cohort-sync: no gateway auth token \u2014 cron operations disabled");
13516
13533
  }
13517
- const allAgentIds = ["main", ...(config?.agents?.list ?? []).map((a) => a.id)];
13534
+ const configIds = (config?.agents?.list ?? []).map((a) => a.id);
13535
+ const allAgentIds = configIds.includes("main") ? configIds : ["main", ...configIds];
13518
13536
  const resolvedNameMap = {};
13519
13537
  for (const agentId of allAgentIds) {
13520
13538
  resolvedNameMap[agentId] = state.resolveAgentName(agentId);
@@ -13953,7 +13971,8 @@ function registerHookHandlers(api, logger, getState) {
13953
13971
  state.keepaliveInterval = null;
13954
13972
  }
13955
13973
  state.activityBatch.drain();
13956
- const allAgentIds = ["main", ...(config?.agents?.list ?? []).map((a) => a.id)];
13974
+ const shutdownConfigIds = (config?.agents?.list ?? []).map((a) => a.id);
13975
+ const allAgentIds = shutdownConfigIds.includes("main") ? shutdownConfigIds : ["main", ...shutdownConfigIds];
13957
13976
  for (const agentId of allAgentIds) {
13958
13977
  const agentName = state.resolveAgentName(agentId);
13959
13978
  try {
@@ -13991,16 +14010,19 @@ function initializeHookState(api, cfg) {
13991
14010
  createClient(convexUrl);
13992
14011
  setLogger(logger);
13993
14012
  const identityNameMap = {};
13994
- const mainIdentity = parseIdentityFile(process.cwd());
13995
- if (mainIdentity?.name) {
13996
- identityNameMap["main"] = mainIdentity.name.toLowerCase();
13997
- }
13998
14013
  for (const agent of config?.agents?.list ?? []) {
13999
- const identity = resolveIdentity(agent.identity, agent.workspace);
14014
+ const workspaceDir = agent.workspace ?? (agent.id === "main" ? process.cwd() : void 0);
14015
+ const identity = resolveIdentity(agent.identity, workspaceDir);
14000
14016
  if (identity?.name) {
14001
14017
  identityNameMap[agent.id] = identity.name.toLowerCase();
14002
14018
  }
14003
14019
  }
14020
+ if (!identityNameMap["main"]) {
14021
+ const mainIdentity = parseIdentityFile(process.cwd());
14022
+ if (mainIdentity?.name) {
14023
+ identityNameMap["main"] = mainIdentity.name.toLowerCase();
14024
+ }
14025
+ }
14004
14026
  logger.debug("cohort-sync: identity name map", { identityNameMap });
14005
14027
  function resolveAgentName(agentId) {
14006
14028
  return (nameMap?.[agentId] ?? identityNameMap[agentId] ?? agentId).toLowerCase();
@@ -55,5 +55,5 @@
55
55
  }
56
56
  }
57
57
  },
58
- "version": "0.11.3"
58
+ "version": "0.11.5"
59
59
  }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfio/cohort-sync",
3
- "version": "0.11.3",
3
+ "version": "0.11.5",
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.11.3",
3
+ "version": "0.11.5",
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",