opencode-supertask 0.1.5 → 0.1.7
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/cli/index.js +98 -7
- package/dist/cli/index.js.map +1 -1
- package/dist/plugin/supertask.js +93 -8
- package/dist/plugin/supertask.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -18846,8 +18846,8 @@ var require_CronFileParser = __commonJS({
|
|
|
18846
18846
|
* @throws If file cannot be read
|
|
18847
18847
|
*/
|
|
18848
18848
|
static parseFileSync(filePath) {
|
|
18849
|
-
const { readFileSync:
|
|
18850
|
-
const data =
|
|
18849
|
+
const { readFileSync: readFileSync4 } = __require("fs");
|
|
18850
|
+
const data = readFileSync4(filePath, "utf8");
|
|
18851
18851
|
return _CronFileParser.#parseContent(data);
|
|
18852
18852
|
}
|
|
18853
18853
|
/**
|
|
@@ -22759,6 +22759,16 @@ __export(pm2_exports, {
|
|
|
22759
22759
|
import { execSync, spawnSync } from "child_process";
|
|
22760
22760
|
import { join as join3, dirname as dirname3 } from "path";
|
|
22761
22761
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
22762
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
22763
|
+
function getPackageVersion() {
|
|
22764
|
+
try {
|
|
22765
|
+
const pkgPath = join3(__dirname, "../package.json");
|
|
22766
|
+
const pkg = JSON.parse(readFileSync3(pkgPath, "utf-8"));
|
|
22767
|
+
return pkg.version || "0.0.0";
|
|
22768
|
+
} catch {
|
|
22769
|
+
return "0.0.0";
|
|
22770
|
+
}
|
|
22771
|
+
}
|
|
22762
22772
|
function pm2Bin() {
|
|
22763
22773
|
return process.platform === "win32" ? "pm2.cmd" : "pm2";
|
|
22764
22774
|
}
|
|
@@ -22841,6 +22851,7 @@ function install() {
|
|
|
22841
22851
|
} else {
|
|
22842
22852
|
console.log("[supertask] Starting Gateway with pm2...");
|
|
22843
22853
|
const bunPath = findBunPath();
|
|
22854
|
+
const version2 = getPackageVersion();
|
|
22844
22855
|
const { ok, output } = pm2Exec([
|
|
22845
22856
|
"start",
|
|
22846
22857
|
GATEWAY_ENTRY,
|
|
@@ -22851,7 +22862,9 @@ function install() {
|
|
|
22851
22862
|
"--restart-delay",
|
|
22852
22863
|
"5000",
|
|
22853
22864
|
"--max-restarts",
|
|
22854
|
-
"30"
|
|
22865
|
+
"30",
|
|
22866
|
+
"--env",
|
|
22867
|
+
`SUPERTASK_VERSION=${version2}`
|
|
22855
22868
|
]);
|
|
22856
22869
|
if (!ok) {
|
|
22857
22870
|
throw new Error(`[supertask] pm2 start failed: ${output}`);
|
|
@@ -22886,10 +22899,37 @@ function uninstall() {
|
|
|
22886
22899
|
console.log("[supertask] To fully remove pm2 startup: pm2 unstartup");
|
|
22887
22900
|
}
|
|
22888
22901
|
function ensureGateway() {
|
|
22902
|
+
const currentVersion = getPackageVersion();
|
|
22889
22903
|
try {
|
|
22890
22904
|
const list = pm2JsonList();
|
|
22891
22905
|
const proc = list.find((p) => p.name === PROCESS_NAME);
|
|
22892
22906
|
if (proc && proc.pm2_env?.status === "online") {
|
|
22907
|
+
const runningVersion = proc.pm2_env.pm_exec_path ? void 0 : void 0;
|
|
22908
|
+
const envVersion = proc.pm2_env.env?.SUPERTASK_VERSION;
|
|
22909
|
+
if (envVersion === currentVersion) {
|
|
22910
|
+
return;
|
|
22911
|
+
}
|
|
22912
|
+
console.log(`[supertask] Version changed: ${envVersion ?? "unknown"} \u2192 ${currentVersion}, reloading Gateway...`);
|
|
22913
|
+
const bunPath = findBunPath();
|
|
22914
|
+
pm2Exec([
|
|
22915
|
+
"delete",
|
|
22916
|
+
PROCESS_NAME
|
|
22917
|
+
]);
|
|
22918
|
+
pm2Exec([
|
|
22919
|
+
"start",
|
|
22920
|
+
GATEWAY_ENTRY,
|
|
22921
|
+
"--name",
|
|
22922
|
+
PROCESS_NAME,
|
|
22923
|
+
"--interpreter",
|
|
22924
|
+
bunPath,
|
|
22925
|
+
"--restart-delay",
|
|
22926
|
+
"5000",
|
|
22927
|
+
"--max-restarts",
|
|
22928
|
+
"30",
|
|
22929
|
+
"--env",
|
|
22930
|
+
`SUPERTASK_VERSION=${currentVersion}`
|
|
22931
|
+
]);
|
|
22932
|
+
pm2Exec(["save"]);
|
|
22893
22933
|
return;
|
|
22894
22934
|
}
|
|
22895
22935
|
} catch {
|
|
@@ -22913,6 +22953,7 @@ function ensureGateway() {
|
|
|
22913
22953
|
pm2Exec(["restart", PROCESS_NAME]);
|
|
22914
22954
|
} else {
|
|
22915
22955
|
const bunPath = findBunPath();
|
|
22956
|
+
const version2 = getPackageVersion();
|
|
22916
22957
|
pm2Exec([
|
|
22917
22958
|
"start",
|
|
22918
22959
|
GATEWAY_ENTRY,
|
|
@@ -22923,7 +22964,9 @@ function ensureGateway() {
|
|
|
22923
22964
|
"--restart-delay",
|
|
22924
22965
|
"5000",
|
|
22925
22966
|
"--max-restarts",
|
|
22926
|
-
"30"
|
|
22967
|
+
"30",
|
|
22968
|
+
"--env",
|
|
22969
|
+
`SUPERTASK_VERSION=${version2}`
|
|
22927
22970
|
]);
|
|
22928
22971
|
}
|
|
22929
22972
|
pm2Exec(["save"]);
|
|
@@ -22959,6 +23002,37 @@ var {
|
|
|
22959
23002
|
init_task_service();
|
|
22960
23003
|
init_task_template_service();
|
|
22961
23004
|
init_db2();
|
|
23005
|
+
|
|
23006
|
+
// src/core/duration.ts
|
|
23007
|
+
var DURATION_REGEX = /^(\d+(?:\.\d+)?)\s*(ms|s|sec|seconds?|min|minutes?|m|h|hours?|d|days?|w|weeks?)$/i;
|
|
23008
|
+
var ISO8601_REGEX = /^P(?:([.\d]+)D)?(?:T(?:([.\d]+)H)?(?:([.\d]+)M)?(?:([.\d]+)S)?)?$/i;
|
|
23009
|
+
function parseDuration(input) {
|
|
23010
|
+
const trimmed = input.trim();
|
|
23011
|
+
const simple = DURATION_REGEX.exec(trimmed);
|
|
23012
|
+
if (simple) {
|
|
23013
|
+
const value = parseFloat(simple[1]);
|
|
23014
|
+
const unit = simple[2].toLowerCase();
|
|
23015
|
+
if (unit === "ms") return value;
|
|
23016
|
+
if (unit === "s" || unit === "sec" || unit === "second" || unit === "seconds") return value * 1e3;
|
|
23017
|
+
if (unit === "min" || unit === "minute" || unit === "minutes" || unit === "m") return value * 6e4;
|
|
23018
|
+
if (unit === "h" || unit === "hour" || unit === "hours") return value * 36e5;
|
|
23019
|
+
if (unit === "d" || unit === "day" || unit === "days") return value * 864e5;
|
|
23020
|
+
if (unit === "w" || unit === "week" || unit === "weeks") return value * 6048e5;
|
|
23021
|
+
}
|
|
23022
|
+
const iso = ISO8601_REGEX.exec(trimmed);
|
|
23023
|
+
if (iso) {
|
|
23024
|
+
const days = parseFloat(iso[1] ?? "0");
|
|
23025
|
+
const hours = parseFloat(iso[2] ?? "0");
|
|
23026
|
+
const minutes = parseFloat(iso[3] ?? "0");
|
|
23027
|
+
const seconds = parseFloat(iso[4] ?? "0");
|
|
23028
|
+
return (days * 86400 + hours * 3600 + minutes * 60 + seconds) * 1e3;
|
|
23029
|
+
}
|
|
23030
|
+
const asNumber = Number(trimmed);
|
|
23031
|
+
if (!isNaN(asNumber) && asNumber > 0) return asNumber;
|
|
23032
|
+
return null;
|
|
23033
|
+
}
|
|
23034
|
+
|
|
23035
|
+
// src/cli/index.ts
|
|
22962
23036
|
async function withDb(fn) {
|
|
22963
23037
|
try {
|
|
22964
23038
|
return await fn();
|
|
@@ -23091,7 +23165,24 @@ program2.command("delete").description("\u5220\u9664\u4EFB\u52A1").requiredOptio
|
|
|
23091
23165
|
console.log(JSON.stringify({ deleted, id: parseInt(options.id) }));
|
|
23092
23166
|
}));
|
|
23093
23167
|
program2.command("template").description("\u7BA1\u7406\u4EFB\u52A1\u8C03\u5EA6\u6A21\u677F").addCommand(
|
|
23094
|
-
new Command("add").description("\u521B\u5EFA\u8C03\u5EA6\u6A21\u677F").requiredOption("-n, --name <name>", "\u6A21\u677F\u540D\u79F0").requiredOption("-a, --agent <agent>", "Agent \u540D\u79F0").requiredOption("-p, --prompt <prompt>", "\u63D0\u793A\u8BCD").requiredOption("-t, --type <type>", "\u8C03\u5EA6\u7C7B\u578B\uFF1Acron/delayed/recurring").option("--cron <expr>", "cron \u8868\u8FBE\u5F0F\uFF08cron \u7C7B\u578B\u5FC5\u586B\uFF09").option("--
|
|
23168
|
+
new Command("add").description("\u521B\u5EFA\u8C03\u5EA6\u6A21\u677F").requiredOption("-n, --name <name>", "\u6A21\u677F\u540D\u79F0").requiredOption("-a, --agent <agent>", "Agent \u540D\u79F0").requiredOption("-p, --prompt <prompt>", "\u63D0\u793A\u8BCD").requiredOption("-t, --type <type>", "\u8C03\u5EA6\u7C7B\u578B\uFF1Acron/delayed/recurring").option("--cron <expr>", "cron \u8868\u8FBE\u5F0F\uFF08cron \u7C7B\u578B\u5FC5\u586B\uFF09").option("--delay <duration>", "\u5EF6\u8FDF\u65F6\u95F4\uFF08delayed \u7C7B\u578B\u5FC5\u586B\uFF09\uFF0C\u5982 30s / 5min / 1h / 2d").option("--interval <duration>", "\u5FAA\u73AF\u95F4\u9694\uFF08recurring \u7C7B\u578B\u5FC5\u586B\uFF09\uFF0C\u5982 1h / 30min / 5s").option("-m, --model <model>", "\u6A21\u578B").option("-c, --category <category>", "\u5206\u7C7B", "general").option("-i, --importance <number>", "\u91CD\u8981\u7A0B\u5EA6 1-5", "3").option("-u, --urgency <number>", "\u7D27\u6025\u7A0B\u5EA6 1-5", "3").option("--max-instances <number>", "\u6700\u5927\u5E76\u53D1\u5B9E\u4F8B\u6570", "1").option("--max-retries <number>", "\u6700\u5927\u91CD\u8BD5\u6B21\u6570", "3").option("--retry-backoff <ms>", "\u9000\u907F\u57FA\u7840\u95F4\u9694 ms", "30000").action(async (options) => withDb(async () => {
|
|
23169
|
+
let intervalMs = null;
|
|
23170
|
+
let runAt = null;
|
|
23171
|
+
if (options.interval) {
|
|
23172
|
+
intervalMs = parseDuration(options.interval);
|
|
23173
|
+
if (intervalMs === null) {
|
|
23174
|
+
console.error(JSON.stringify({ error: `Invalid interval: "${options.interval}". Use 30s / 5min / 1h / 2d` }));
|
|
23175
|
+
process.exit(1);
|
|
23176
|
+
}
|
|
23177
|
+
}
|
|
23178
|
+
if (options.delay) {
|
|
23179
|
+
const delayMs = parseDuration(options.delay);
|
|
23180
|
+
if (delayMs === null) {
|
|
23181
|
+
console.error(JSON.stringify({ error: `Invalid delay: "${options.delay}". Use 30s / 5min / 1h / 2d` }));
|
|
23182
|
+
process.exit(1);
|
|
23183
|
+
}
|
|
23184
|
+
runAt = Date.now() + delayMs;
|
|
23185
|
+
}
|
|
23095
23186
|
const tmpl = await TaskTemplateService.create({
|
|
23096
23187
|
name: options.name,
|
|
23097
23188
|
agent: options.agent,
|
|
@@ -23102,8 +23193,8 @@ program2.command("template").description("\u7BA1\u7406\u4EFB\u52A1\u8C03\u5EA6\u
|
|
|
23102
23193
|
urgency: parseInt(options.urgency),
|
|
23103
23194
|
scheduleType: options.type,
|
|
23104
23195
|
cronExpr: options.cron,
|
|
23105
|
-
intervalMs
|
|
23106
|
-
runAt
|
|
23196
|
+
intervalMs,
|
|
23197
|
+
runAt,
|
|
23107
23198
|
maxInstances: parseInt(options.maxInstances),
|
|
23108
23199
|
maxRetries: parseInt(options.maxRetries),
|
|
23109
23200
|
retryBackoffMs: parseInt(options.retryBackoff)
|