opencode-supertask 0.1.5 → 0.1.6
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 +51 -3
- package/dist/cli/index.js.map +1 -1
- package/dist/plugin/supertask.js +50 -5
- package/dist/plugin/supertask.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -22959,6 +22959,37 @@ var {
|
|
|
22959
22959
|
init_task_service();
|
|
22960
22960
|
init_task_template_service();
|
|
22961
22961
|
init_db2();
|
|
22962
|
+
|
|
22963
|
+
// src/core/duration.ts
|
|
22964
|
+
var DURATION_REGEX = /^(\d+(?:\.\d+)?)\s*(ms|s|sec|seconds?|min|minutes?|m|h|hours?|d|days?|w|weeks?)$/i;
|
|
22965
|
+
var ISO8601_REGEX = /^P(?:([.\d]+)D)?(?:T(?:([.\d]+)H)?(?:([.\d]+)M)?(?:([.\d]+)S)?)?$/i;
|
|
22966
|
+
function parseDuration(input) {
|
|
22967
|
+
const trimmed = input.trim();
|
|
22968
|
+
const simple = DURATION_REGEX.exec(trimmed);
|
|
22969
|
+
if (simple) {
|
|
22970
|
+
const value = parseFloat(simple[1]);
|
|
22971
|
+
const unit = simple[2].toLowerCase();
|
|
22972
|
+
if (unit === "ms") return value;
|
|
22973
|
+
if (unit === "s" || unit === "sec" || unit === "second" || unit === "seconds") return value * 1e3;
|
|
22974
|
+
if (unit === "min" || unit === "minute" || unit === "minutes" || unit === "m") return value * 6e4;
|
|
22975
|
+
if (unit === "h" || unit === "hour" || unit === "hours") return value * 36e5;
|
|
22976
|
+
if (unit === "d" || unit === "day" || unit === "days") return value * 864e5;
|
|
22977
|
+
if (unit === "w" || unit === "week" || unit === "weeks") return value * 6048e5;
|
|
22978
|
+
}
|
|
22979
|
+
const iso = ISO8601_REGEX.exec(trimmed);
|
|
22980
|
+
if (iso) {
|
|
22981
|
+
const days = parseFloat(iso[1] ?? "0");
|
|
22982
|
+
const hours = parseFloat(iso[2] ?? "0");
|
|
22983
|
+
const minutes = parseFloat(iso[3] ?? "0");
|
|
22984
|
+
const seconds = parseFloat(iso[4] ?? "0");
|
|
22985
|
+
return (days * 86400 + hours * 3600 + minutes * 60 + seconds) * 1e3;
|
|
22986
|
+
}
|
|
22987
|
+
const asNumber = Number(trimmed);
|
|
22988
|
+
if (!isNaN(asNumber) && asNumber > 0) return asNumber;
|
|
22989
|
+
return null;
|
|
22990
|
+
}
|
|
22991
|
+
|
|
22992
|
+
// src/cli/index.ts
|
|
22962
22993
|
async function withDb(fn) {
|
|
22963
22994
|
try {
|
|
22964
22995
|
return await fn();
|
|
@@ -23091,7 +23122,24 @@ program2.command("delete").description("\u5220\u9664\u4EFB\u52A1").requiredOptio
|
|
|
23091
23122
|
console.log(JSON.stringify({ deleted, id: parseInt(options.id) }));
|
|
23092
23123
|
}));
|
|
23093
23124
|
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("--
|
|
23125
|
+
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 () => {
|
|
23126
|
+
let intervalMs = null;
|
|
23127
|
+
let runAt = null;
|
|
23128
|
+
if (options.interval) {
|
|
23129
|
+
intervalMs = parseDuration(options.interval);
|
|
23130
|
+
if (intervalMs === null) {
|
|
23131
|
+
console.error(JSON.stringify({ error: `Invalid interval: "${options.interval}". Use 30s / 5min / 1h / 2d` }));
|
|
23132
|
+
process.exit(1);
|
|
23133
|
+
}
|
|
23134
|
+
}
|
|
23135
|
+
if (options.delay) {
|
|
23136
|
+
const delayMs = parseDuration(options.delay);
|
|
23137
|
+
if (delayMs === null) {
|
|
23138
|
+
console.error(JSON.stringify({ error: `Invalid delay: "${options.delay}". Use 30s / 5min / 1h / 2d` }));
|
|
23139
|
+
process.exit(1);
|
|
23140
|
+
}
|
|
23141
|
+
runAt = Date.now() + delayMs;
|
|
23142
|
+
}
|
|
23095
23143
|
const tmpl = await TaskTemplateService.create({
|
|
23096
23144
|
name: options.name,
|
|
23097
23145
|
agent: options.agent,
|
|
@@ -23102,8 +23150,8 @@ program2.command("template").description("\u7BA1\u7406\u4EFB\u52A1\u8C03\u5EA6\u
|
|
|
23102
23150
|
urgency: parseInt(options.urgency),
|
|
23103
23151
|
scheduleType: options.type,
|
|
23104
23152
|
cronExpr: options.cron,
|
|
23105
|
-
intervalMs
|
|
23106
|
-
runAt
|
|
23153
|
+
intervalMs,
|
|
23154
|
+
runAt,
|
|
23107
23155
|
maxInstances: parseInt(options.maxInstances),
|
|
23108
23156
|
maxRetries: parseInt(options.maxRetries),
|
|
23109
23157
|
retryBackoffMs: parseInt(options.retryBackoff)
|