@cfio/cohort-sync 0.4.3 → 0.4.4
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 +68 -69
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15,10 +15,10 @@ __export(keychain_exports, {
|
|
|
15
15
|
getCredential: () => getCredential,
|
|
16
16
|
setCredential: () => setCredential
|
|
17
17
|
});
|
|
18
|
-
import { execFile
|
|
18
|
+
import { execFile } from "node:child_process";
|
|
19
19
|
function securityCmd(args) {
|
|
20
20
|
return new Promise((resolve, reject) => {
|
|
21
|
-
|
|
21
|
+
execFile("security", args, { timeout: 5e3 }, (err, stdout, stderr) => {
|
|
22
22
|
if (err) {
|
|
23
23
|
reject(Object.assign(err, { stderr }));
|
|
24
24
|
} else {
|
|
@@ -88,8 +88,8 @@ var init_keychain = __esm({
|
|
|
88
88
|
});
|
|
89
89
|
|
|
90
90
|
// src/hooks.ts
|
|
91
|
-
import
|
|
92
|
-
import
|
|
91
|
+
import fs2 from "node:fs";
|
|
92
|
+
import path2 from "node:path";
|
|
93
93
|
|
|
94
94
|
// ../../node_modules/.pnpm/@sinclair+typebox@0.34.48/node_modules/@sinclair/typebox/build/esm/type/guard/value.mjs
|
|
95
95
|
var value_exports = {};
|
|
@@ -2698,8 +2698,10 @@ __export(type_exports2, {
|
|
|
2698
2698
|
var Type = type_exports2;
|
|
2699
2699
|
|
|
2700
2700
|
// src/sync.ts
|
|
2701
|
-
import {
|
|
2702
|
-
import
|
|
2701
|
+
import { execSync } from "node:child_process";
|
|
2702
|
+
import fs from "node:fs";
|
|
2703
|
+
import os from "node:os";
|
|
2704
|
+
import path from "node:path";
|
|
2703
2705
|
|
|
2704
2706
|
// ../../node_modules/.pnpm/convex@1.33.0_patch_hash=l43bztwr6e2lbmpd6ao6hmcg24_react@19.2.1/node_modules/convex/dist/esm/index.js
|
|
2705
2707
|
var version = "1.33.0";
|
|
@@ -4555,12 +4557,12 @@ function createApi(pathParts = []) {
|
|
|
4555
4557
|
`API path is expected to be of the form \`api.moduleName.functionName\`. Found: \`${found}\``
|
|
4556
4558
|
);
|
|
4557
4559
|
}
|
|
4558
|
-
const
|
|
4560
|
+
const path3 = pathParts.slice(0, -1).join("/");
|
|
4559
4561
|
const exportName = pathParts[pathParts.length - 1];
|
|
4560
4562
|
if (exportName === "default") {
|
|
4561
|
-
return
|
|
4563
|
+
return path3;
|
|
4562
4564
|
} else {
|
|
4563
|
-
return
|
|
4565
|
+
return path3 + ":" + exportName;
|
|
4564
4566
|
}
|
|
4565
4567
|
} else if (prop === Symbol.toStringTag) {
|
|
4566
4568
|
return "FunctionReference";
|
|
@@ -7629,16 +7631,16 @@ var require_constants = __commonJS({
|
|
|
7629
7631
|
});
|
|
7630
7632
|
var require_node_gyp_build = __commonJS({
|
|
7631
7633
|
"../common/temp/node_modules/.pnpm/node-gyp-build@4.8.4/node_modules/node-gyp-build/node-gyp-build.js"(exports, module) {
|
|
7632
|
-
var
|
|
7633
|
-
var
|
|
7634
|
-
var
|
|
7634
|
+
var fs3 = __require("fs");
|
|
7635
|
+
var path3 = __require("path");
|
|
7636
|
+
var os2 = __require("os");
|
|
7635
7637
|
var runtimeRequire = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require;
|
|
7636
7638
|
var vars = process.config && process.config.variables || {};
|
|
7637
7639
|
var prebuildsOnly = !!process.env.PREBUILDS_ONLY;
|
|
7638
7640
|
var abi = process.versions.modules;
|
|
7639
7641
|
var runtime = isElectron() ? "electron" : isNwjs() ? "node-webkit" : "node";
|
|
7640
|
-
var arch = process.env.npm_config_arch ||
|
|
7641
|
-
var platform = process.env.npm_config_platform ||
|
|
7642
|
+
var arch = process.env.npm_config_arch || os2.arch();
|
|
7643
|
+
var platform = process.env.npm_config_platform || os2.platform();
|
|
7642
7644
|
var libc = process.env.LIBC || (isAlpine(platform) ? "musl" : "glibc");
|
|
7643
7645
|
var armv = process.env.ARM_VERSION || (arch === "arm64" ? "8" : vars.arm_version) || "";
|
|
7644
7646
|
var uv = (process.versions.uv || "").split(".")[0];
|
|
@@ -7647,21 +7649,21 @@ var require_node_gyp_build = __commonJS({
|
|
|
7647
7649
|
return runtimeRequire(load.resolve(dir));
|
|
7648
7650
|
}
|
|
7649
7651
|
load.resolve = load.path = function(dir) {
|
|
7650
|
-
dir =
|
|
7652
|
+
dir = path3.resolve(dir || ".");
|
|
7651
7653
|
try {
|
|
7652
|
-
var name = runtimeRequire(
|
|
7654
|
+
var name = runtimeRequire(path3.join(dir, "package.json")).name.toUpperCase().replace(/-/g, "_");
|
|
7653
7655
|
if (process.env[name + "_PREBUILD"]) dir = process.env[name + "_PREBUILD"];
|
|
7654
7656
|
} catch (err) {
|
|
7655
7657
|
}
|
|
7656
7658
|
if (!prebuildsOnly) {
|
|
7657
|
-
var release = getFirst(
|
|
7659
|
+
var release = getFirst(path3.join(dir, "build/Release"), matchBuild);
|
|
7658
7660
|
if (release) return release;
|
|
7659
|
-
var debug = getFirst(
|
|
7661
|
+
var debug = getFirst(path3.join(dir, "build/Debug"), matchBuild);
|
|
7660
7662
|
if (debug) return debug;
|
|
7661
7663
|
}
|
|
7662
7664
|
var prebuild = resolve(dir);
|
|
7663
7665
|
if (prebuild) return prebuild;
|
|
7664
|
-
var nearby = resolve(
|
|
7666
|
+
var nearby = resolve(path3.dirname(process.execPath));
|
|
7665
7667
|
if (nearby) return nearby;
|
|
7666
7668
|
var target = [
|
|
7667
7669
|
"platform=" + platform,
|
|
@@ -7678,26 +7680,26 @@ var require_node_gyp_build = __commonJS({
|
|
|
7678
7680
|
].filter(Boolean).join(" ");
|
|
7679
7681
|
throw new Error("No native build was found for " + target + "\n loaded from: " + dir + "\n");
|
|
7680
7682
|
function resolve(dir2) {
|
|
7681
|
-
var tuples = readdirSync(
|
|
7683
|
+
var tuples = readdirSync(path3.join(dir2, "prebuilds")).map(parseTuple);
|
|
7682
7684
|
var tuple = tuples.filter(matchTuple(platform, arch)).sort(compareTuples)[0];
|
|
7683
7685
|
if (!tuple) return;
|
|
7684
|
-
var prebuilds =
|
|
7686
|
+
var prebuilds = path3.join(dir2, "prebuilds", tuple.name);
|
|
7685
7687
|
var parsed = readdirSync(prebuilds).map(parseTags);
|
|
7686
7688
|
var candidates = parsed.filter(matchTags(runtime, abi));
|
|
7687
7689
|
var winner = candidates.sort(compareTags(runtime))[0];
|
|
7688
|
-
if (winner) return
|
|
7690
|
+
if (winner) return path3.join(prebuilds, winner.file);
|
|
7689
7691
|
}
|
|
7690
7692
|
};
|
|
7691
7693
|
function readdirSync(dir) {
|
|
7692
7694
|
try {
|
|
7693
|
-
return
|
|
7695
|
+
return fs3.readdirSync(dir);
|
|
7694
7696
|
} catch (err) {
|
|
7695
7697
|
return [];
|
|
7696
7698
|
}
|
|
7697
7699
|
}
|
|
7698
7700
|
function getFirst(dir, filter) {
|
|
7699
7701
|
var files = readdirSync(dir).filter(filter);
|
|
7700
|
-
return files[0] &&
|
|
7702
|
+
return files[0] && path3.join(dir, files[0]);
|
|
7701
7703
|
}
|
|
7702
7704
|
function matchBuild(name) {
|
|
7703
7705
|
return /\.node$/.test(name);
|
|
@@ -7784,7 +7786,7 @@ var require_node_gyp_build = __commonJS({
|
|
|
7784
7786
|
return typeof window !== "undefined" && window.process && window.process.type === "renderer";
|
|
7785
7787
|
}
|
|
7786
7788
|
function isAlpine(platform2) {
|
|
7787
|
-
return platform2 === "linux" &&
|
|
7789
|
+
return platform2 === "linux" && fs3.existsSync("/etc/alpine-release");
|
|
7788
7790
|
}
|
|
7789
7791
|
load.parseTags = parseTags;
|
|
7790
7792
|
load.matchTags = matchTags;
|
|
@@ -11760,7 +11762,7 @@ function initCommandSubscription(cfg, logger, resolveAgentName) {
|
|
|
11760
11762
|
if (cmd.type.startsWith("cron") && cmd.payload?.jobId) {
|
|
11761
11763
|
handleCronCommand(cmd.type, cmd.payload.jobId, logger);
|
|
11762
11764
|
try {
|
|
11763
|
-
const freshJobs =
|
|
11765
|
+
const freshJobs = fetchCronJobs(logger);
|
|
11764
11766
|
if (freshJobs !== null) {
|
|
11765
11767
|
const resolvedJobs = resolveAgentName ? freshJobs.map((j) => ({ ...j, agentId: j.agentId ? resolveAgentName(j.agentId) : j.agentId })) : freshJobs;
|
|
11766
11768
|
await pushCronSnapshot(cfg.apiKey, resolvedJobs);
|
|
@@ -11915,7 +11917,6 @@ function getChannelAgent(channelId) {
|
|
|
11915
11917
|
}
|
|
11916
11918
|
|
|
11917
11919
|
// src/sync.ts
|
|
11918
|
-
var execFileAsync = promisify(execFile);
|
|
11919
11920
|
function extractJson(raw) {
|
|
11920
11921
|
const jsonStart = raw.search(/[\[{]/);
|
|
11921
11922
|
const jsonEndBracket = raw.lastIndexOf("]");
|
|
@@ -11926,14 +11927,15 @@ function extractJson(raw) {
|
|
|
11926
11927
|
}
|
|
11927
11928
|
return raw.slice(jsonStart, jsonEnd + 1);
|
|
11928
11929
|
}
|
|
11929
|
-
|
|
11930
|
+
function fetchSkills(logger) {
|
|
11930
11931
|
try {
|
|
11931
|
-
const
|
|
11932
|
+
const raw = execSync("openclaw skills list --json", {
|
|
11932
11933
|
encoding: "utf8",
|
|
11933
|
-
timeout:
|
|
11934
|
+
timeout: 3e4,
|
|
11935
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
11934
11936
|
env: { ...process.env, NO_COLOR: "1" }
|
|
11935
11937
|
});
|
|
11936
|
-
const parsed = JSON.parse(extractJson(
|
|
11938
|
+
const parsed = JSON.parse(extractJson(raw));
|
|
11937
11939
|
const list = Array.isArray(parsed) ? parsed : parsed?.skills ?? [];
|
|
11938
11940
|
return list.map((s) => ({
|
|
11939
11941
|
name: String(s.name ?? s.id ?? "unknown"),
|
|
@@ -11946,27 +11948,24 @@ async function fetchSkills(logger) {
|
|
|
11946
11948
|
return [];
|
|
11947
11949
|
}
|
|
11948
11950
|
}
|
|
11949
|
-
|
|
11951
|
+
function fetchCronJobs(logger) {
|
|
11950
11952
|
try {
|
|
11951
|
-
const
|
|
11952
|
-
|
|
11953
|
-
|
|
11954
|
-
|
|
11955
|
-
|
|
11956
|
-
|
|
11957
|
-
|
|
11958
|
-
return list.map((j) => ({
|
|
11959
|
-
id: String(j.jobId ?? j.id ?? "unknown"),
|
|
11960
|
-
text: String(j.name ?? j.text ?? ""),
|
|
11953
|
+
const storePath = path.join(os.homedir(), ".openclaw", "cron", "jobs.json");
|
|
11954
|
+
const raw = fs.readFileSync(storePath, "utf-8");
|
|
11955
|
+
const parsed = JSON.parse(raw);
|
|
11956
|
+
const jobs = Array.isArray(parsed?.jobs) ? parsed.jobs : [];
|
|
11957
|
+
return jobs.map((j) => ({
|
|
11958
|
+
id: String(j.id ?? "unknown"),
|
|
11959
|
+
text: String(j.name ?? ""),
|
|
11961
11960
|
schedule: formatSchedule(j.schedule),
|
|
11962
|
-
...j.
|
|
11963
|
-
...j.
|
|
11964
|
-
...j.lastStatus ? { lastStatus: String(j.lastStatus) } : {},
|
|
11961
|
+
...j.state?.nextRunAtMs != null ? { nextRun: Number(j.state.nextRunAtMs) } : {},
|
|
11962
|
+
...j.state?.lastRunAtMs != null ? { lastRun: Number(j.state.lastRunAtMs) } : {},
|
|
11963
|
+
...j.state?.lastStatus ? { lastStatus: String(j.state.lastStatus) } : {},
|
|
11965
11964
|
enabled: j.enabled !== false,
|
|
11966
11965
|
...j.agentId != null ? { agentId: String(j.agentId) } : {}
|
|
11967
11966
|
}));
|
|
11968
11967
|
} catch (err) {
|
|
11969
|
-
logger.warn(`cohort-sync: failed to
|
|
11968
|
+
logger.warn(`cohort-sync: failed to read cron store: ${String(err)}`);
|
|
11970
11969
|
return null;
|
|
11971
11970
|
}
|
|
11972
11971
|
}
|
|
@@ -11987,31 +11986,31 @@ var VALID_STATUSES = /* @__PURE__ */ new Set(["idle", "working", "waiting"]);
|
|
|
11987
11986
|
function normalizeStatus(status) {
|
|
11988
11987
|
return VALID_STATUSES.has(status) ? status : "idle";
|
|
11989
11988
|
}
|
|
11990
|
-
async function v1Get(apiUrl, apiKey,
|
|
11991
|
-
const res = await fetch(`${apiUrl.replace(/\/+$/, "")}${
|
|
11989
|
+
async function v1Get(apiUrl, apiKey, path3) {
|
|
11990
|
+
const res = await fetch(`${apiUrl.replace(/\/+$/, "")}${path3}`, {
|
|
11992
11991
|
headers: { Authorization: `Bearer ${apiKey}` },
|
|
11993
11992
|
signal: AbortSignal.timeout(1e4)
|
|
11994
11993
|
});
|
|
11995
|
-
if (!res.ok) throw new Error(`GET ${
|
|
11994
|
+
if (!res.ok) throw new Error(`GET ${path3} \u2192 ${res.status}`);
|
|
11996
11995
|
return res.json();
|
|
11997
11996
|
}
|
|
11998
|
-
async function v1Patch(apiUrl, apiKey,
|
|
11999
|
-
const res = await fetch(`${apiUrl.replace(/\/+$/, "")}${
|
|
11997
|
+
async function v1Patch(apiUrl, apiKey, path3, body) {
|
|
11998
|
+
const res = await fetch(`${apiUrl.replace(/\/+$/, "")}${path3}`, {
|
|
12000
11999
|
method: "PATCH",
|
|
12001
12000
|
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
12002
12001
|
body: JSON.stringify(body),
|
|
12003
12002
|
signal: AbortSignal.timeout(1e4)
|
|
12004
12003
|
});
|
|
12005
|
-
if (!res.ok) throw new Error(`PATCH ${
|
|
12004
|
+
if (!res.ok) throw new Error(`PATCH ${path3} \u2192 ${res.status}`);
|
|
12006
12005
|
}
|
|
12007
|
-
async function v1Post(apiUrl, apiKey,
|
|
12008
|
-
const res = await fetch(`${apiUrl.replace(/\/+$/, "")}${
|
|
12006
|
+
async function v1Post(apiUrl, apiKey, path3, body) {
|
|
12007
|
+
const res = await fetch(`${apiUrl.replace(/\/+$/, "")}${path3}`, {
|
|
12009
12008
|
method: "POST",
|
|
12010
12009
|
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
12011
12010
|
body: JSON.stringify(body),
|
|
12012
12011
|
signal: AbortSignal.timeout(1e4)
|
|
12013
12012
|
});
|
|
12014
|
-
if (!res.ok) throw new Error(`POST ${
|
|
12013
|
+
if (!res.ok) throw new Error(`POST ${path3} \u2192 ${res.status}`);
|
|
12015
12014
|
}
|
|
12016
12015
|
async function checkForUpdate(currentVersion, logger) {
|
|
12017
12016
|
try {
|
|
@@ -12172,7 +12171,7 @@ async function fullSync(agentName, model, cfg, logger, openClawAgents) {
|
|
|
12172
12171
|
} else {
|
|
12173
12172
|
await syncAgentStatus(agentName, "working", model, cfg, logger);
|
|
12174
12173
|
}
|
|
12175
|
-
const skills =
|
|
12174
|
+
const skills = fetchSkills(logger);
|
|
12176
12175
|
if (skills.length > 0) {
|
|
12177
12176
|
await syncSkillsToV1(skills, cfg, logger);
|
|
12178
12177
|
}
|
|
@@ -12688,7 +12687,7 @@ function diag(label, data) {
|
|
|
12688
12687
|
const line = `[${ts}] ${label}${payload}
|
|
12689
12688
|
`;
|
|
12690
12689
|
try {
|
|
12691
|
-
|
|
12690
|
+
fs2.appendFileSync(DIAG_LOG_PATH, line);
|
|
12692
12691
|
} catch {
|
|
12693
12692
|
}
|
|
12694
12693
|
}
|
|
@@ -12716,16 +12715,16 @@ function dumpEvent(event) {
|
|
|
12716
12715
|
}
|
|
12717
12716
|
var PLUGIN_VERSION = "unknown";
|
|
12718
12717
|
try {
|
|
12719
|
-
const pkgPath =
|
|
12720
|
-
const pkgJson = JSON.parse(
|
|
12718
|
+
const pkgPath = path2.join(path2.dirname(new URL(import.meta.url).pathname), "package.json");
|
|
12719
|
+
const pkgJson = JSON.parse(fs2.readFileSync(pkgPath, "utf8"));
|
|
12721
12720
|
PLUGIN_VERSION = pkgJson.version ?? "unknown";
|
|
12722
12721
|
} catch {
|
|
12723
12722
|
}
|
|
12724
12723
|
diag("MODULE_LOADED", { BUILD_ID, PLUGIN_VERSION });
|
|
12725
12724
|
function parseIdentityFile(workspaceDir) {
|
|
12726
12725
|
try {
|
|
12727
|
-
const filePath =
|
|
12728
|
-
const content =
|
|
12726
|
+
const filePath = path2.join(workspaceDir, "IDENTITY.md");
|
|
12727
|
+
const content = fs2.readFileSync(filePath, "utf-8");
|
|
12729
12728
|
const identity = {};
|
|
12730
12729
|
for (const line of content.split(/\r?\n/)) {
|
|
12731
12730
|
const cleaned = line.trim().replace(/^\s*-\s*/, "");
|
|
@@ -12763,8 +12762,8 @@ function getOrCreateTracker() {
|
|
|
12763
12762
|
state.tracker = fresh;
|
|
12764
12763
|
return fresh;
|
|
12765
12764
|
}
|
|
12766
|
-
var STATE_FILE_PATH =
|
|
12767
|
-
|
|
12765
|
+
var STATE_FILE_PATH = path2.join(
|
|
12766
|
+
path2.dirname(new URL(import.meta.url).pathname),
|
|
12768
12767
|
".session-state.json"
|
|
12769
12768
|
);
|
|
12770
12769
|
function saveSessionsToDisk(tracker) {
|
|
@@ -12781,14 +12780,14 @@ function saveSessionsToDisk(tracker) {
|
|
|
12781
12780
|
data.sessions.push({ agentName: name, key });
|
|
12782
12781
|
}
|
|
12783
12782
|
}
|
|
12784
|
-
|
|
12783
|
+
fs2.writeFileSync(STATE_FILE_PATH, JSON.stringify(data));
|
|
12785
12784
|
} catch {
|
|
12786
12785
|
}
|
|
12787
12786
|
}
|
|
12788
12787
|
function loadSessionsFromDisk(tracker, logger) {
|
|
12789
12788
|
try {
|
|
12790
|
-
if (!
|
|
12791
|
-
const data = JSON.parse(
|
|
12789
|
+
if (!fs2.existsSync(STATE_FILE_PATH)) return;
|
|
12790
|
+
const data = JSON.parse(fs2.readFileSync(STATE_FILE_PATH, "utf8"));
|
|
12792
12791
|
if (Date.now() - new Date(data.savedAt).getTime() > 864e5) {
|
|
12793
12792
|
logger.info("cohort-sync: disk session state too old (>24h), skipping");
|
|
12794
12793
|
return;
|
|
@@ -13116,7 +13115,7 @@ Do not attempt to make more comments until ${resetAt}.`
|
|
|
13116
13115
|
}
|
|
13117
13116
|
saveSessionsToDisk(tracker);
|
|
13118
13117
|
try {
|
|
13119
|
-
const cronJobs2 =
|
|
13118
|
+
const cronJobs2 = fetchCronJobs(logger);
|
|
13120
13119
|
if (cronJobs2 !== null) {
|
|
13121
13120
|
const resolvedJobs = cronJobs2.map((job) => ({
|
|
13122
13121
|
...job,
|
|
@@ -13506,7 +13505,7 @@ Do not attempt to make more comments until ${resetAt}.`
|
|
|
13506
13505
|
}
|
|
13507
13506
|
|
|
13508
13507
|
// src/cli.ts
|
|
13509
|
-
import { execFile as
|
|
13508
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
13510
13509
|
|
|
13511
13510
|
// src/device-auth.ts
|
|
13512
13511
|
function baseUrl(apiUrl) {
|
|
@@ -13587,7 +13586,7 @@ init_keychain();
|
|
|
13587
13586
|
function openBrowser(url) {
|
|
13588
13587
|
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
|
|
13589
13588
|
const args = process.platform === "win32" ? ["/c", "start", url] : [url];
|
|
13590
|
-
|
|
13589
|
+
execFile2(cmd, args, () => {
|
|
13591
13590
|
});
|
|
13592
13591
|
}
|
|
13593
13592
|
function registerCohortCli(ctx, cfg) {
|
package/dist/package.json
CHANGED