@cfio/cohort-sync 0.4.0 → 0.4.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.
- package/dist/index.js +27 -10
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11728,7 +11728,7 @@ async function initSubscription(port, cfg, hooksToken, logger) {
|
|
|
11728
11728
|
}
|
|
11729
11729
|
state.unsubscribers = [...unsubscribers];
|
|
11730
11730
|
}
|
|
11731
|
-
function initCommandSubscription(cfg, logger) {
|
|
11731
|
+
function initCommandSubscription(cfg, logger, resolveAgentName) {
|
|
11732
11732
|
const c = getOrCreateClient();
|
|
11733
11733
|
if (!c) {
|
|
11734
11734
|
logger.warn("cohort-sync: no ConvexClient \u2014 command subscription skipped");
|
|
@@ -11760,7 +11760,10 @@ function initCommandSubscription(cfg, logger) {
|
|
|
11760
11760
|
handleCronCommand(cmd.type, cmd.payload.jobId, logger);
|
|
11761
11761
|
try {
|
|
11762
11762
|
const freshJobs = fetchCronJobs(logger);
|
|
11763
|
-
|
|
11763
|
+
if (freshJobs !== null) {
|
|
11764
|
+
const resolvedJobs = resolveAgentName ? freshJobs.map((j) => ({ ...j, agentId: j.agentId ? resolveAgentName(j.agentId) : j.agentId })) : freshJobs;
|
|
11765
|
+
await pushCronSnapshot(cfg.apiKey, resolvedJobs);
|
|
11766
|
+
}
|
|
11764
11767
|
} catch (snapErr) {
|
|
11765
11768
|
logger.warn(`cohort-sync: post-command snapshot push failed: ${String(snapErr)}`);
|
|
11766
11769
|
}
|
|
@@ -11964,7 +11967,7 @@ function fetchCronJobs(logger) {
|
|
|
11964
11967
|
}));
|
|
11965
11968
|
} catch (err) {
|
|
11966
11969
|
logger.warn(`cohort-sync: failed to fetch cron jobs: ${String(err)}`);
|
|
11967
|
-
return
|
|
11970
|
+
return null;
|
|
11968
11971
|
}
|
|
11969
11972
|
}
|
|
11970
11973
|
function formatSchedule(schedule) {
|
|
@@ -12847,6 +12850,18 @@ function registerHooks(api, cfg) {
|
|
|
12847
12850
|
setLogger(logger);
|
|
12848
12851
|
restoreFromHotReload(logger);
|
|
12849
12852
|
restoreRosterFromHotReload(getRosterHotState(), logger);
|
|
12853
|
+
const identityNameMap = {};
|
|
12854
|
+
const mainIdentity = parseIdentityFile(process.cwd());
|
|
12855
|
+
if (mainIdentity?.name) {
|
|
12856
|
+
identityNameMap["main"] = mainIdentity.name.toLowerCase();
|
|
12857
|
+
}
|
|
12858
|
+
for (const agent of config?.agents?.list ?? []) {
|
|
12859
|
+
const identity = resolveIdentity(agent.identity, agent.workspace);
|
|
12860
|
+
if (identity?.name) {
|
|
12861
|
+
identityNameMap[agent.id] = identity.name.toLowerCase();
|
|
12862
|
+
}
|
|
12863
|
+
}
|
|
12864
|
+
diag("IDENTITY_NAME_MAP", { identityNameMap });
|
|
12850
12865
|
if (tracker.getAgentNames().length === 0) {
|
|
12851
12866
|
loadSessionsFromDisk(tracker, logger);
|
|
12852
12867
|
const restoredAgents = tracker.getAgentNames();
|
|
@@ -12863,7 +12878,7 @@ function registerHooks(api, cfg) {
|
|
|
12863
12878
|
}
|
|
12864
12879
|
}
|
|
12865
12880
|
function resolveAgentName(agentId) {
|
|
12866
|
-
return (nameMap?.[agentId] ?? agentId).toLowerCase();
|
|
12881
|
+
return (nameMap?.[agentId] ?? identityNameMap[agentId] ?? agentId).toLowerCase();
|
|
12867
12882
|
}
|
|
12868
12883
|
function resolveAgentFromContext(ctx) {
|
|
12869
12884
|
const allCtxKeys = Object.keys(ctx);
|
|
@@ -13102,11 +13117,13 @@ Do not attempt to make more comments until ${resetAt}.`
|
|
|
13102
13117
|
saveSessionsToDisk(tracker);
|
|
13103
13118
|
try {
|
|
13104
13119
|
const cronJobs2 = fetchCronJobs(logger);
|
|
13105
|
-
|
|
13106
|
-
|
|
13107
|
-
|
|
13108
|
-
|
|
13109
|
-
|
|
13120
|
+
if (cronJobs2 !== null) {
|
|
13121
|
+
const resolvedJobs = cronJobs2.map((job) => ({
|
|
13122
|
+
...job,
|
|
13123
|
+
agentId: job.agentId ? resolveAgentName(job.agentId) : job.agentId
|
|
13124
|
+
}));
|
|
13125
|
+
await pushCronSnapshot(cfg.apiKey, resolvedJobs);
|
|
13126
|
+
}
|
|
13110
13127
|
} catch (err) {
|
|
13111
13128
|
logger.warn(`cohort-sync: heartbeat cron push failed: ${String(err)}`);
|
|
13112
13129
|
}
|
|
@@ -13155,7 +13172,7 @@ Do not attempt to make more comments until ${resetAt}.`
|
|
|
13155
13172
|
).catch((err) => {
|
|
13156
13173
|
logger.error(`cohort-sync: subscription init failed: ${String(err)}`);
|
|
13157
13174
|
});
|
|
13158
|
-
initCommandSubscription(cfg, logger);
|
|
13175
|
+
initCommandSubscription(cfg, logger, resolveAgentName);
|
|
13159
13176
|
const allAgentIds = ["main", ...(config?.agents?.list ?? []).map((a) => a.id)];
|
|
13160
13177
|
for (const agentId of allAgentIds) {
|
|
13161
13178
|
const agentName = resolveAgentName(agentId);
|
package/dist/package.json
CHANGED