opencode-supertask 0.1.4 → 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.
@@ -27200,6 +27200,35 @@ var TaskTemplateService = class {
27200
27200
  }
27201
27201
  };
27202
27202
 
27203
+ // src/core/duration.ts
27204
+ var DURATION_REGEX = /^(\d+(?:\.\d+)?)\s*(ms|s|sec|seconds?|min|minutes?|m|h|hours?|d|days?|w|weeks?)$/i;
27205
+ var ISO8601_REGEX = /^P(?:([.\d]+)D)?(?:T(?:([.\d]+)H)?(?:([.\d]+)M)?(?:([.\d]+)S)?)?$/i;
27206
+ function parseDuration(input) {
27207
+ const trimmed = input.trim();
27208
+ const simple = DURATION_REGEX.exec(trimmed);
27209
+ if (simple) {
27210
+ const value = parseFloat(simple[1]);
27211
+ const unit = simple[2].toLowerCase();
27212
+ if (unit === "ms") return value;
27213
+ if (unit === "s" || unit === "sec" || unit === "second" || unit === "seconds") return value * 1e3;
27214
+ if (unit === "min" || unit === "minute" || unit === "minutes" || unit === "m") return value * 6e4;
27215
+ if (unit === "h" || unit === "hour" || unit === "hours") return value * 36e5;
27216
+ if (unit === "d" || unit === "day" || unit === "days") return value * 864e5;
27217
+ if (unit === "w" || unit === "week" || unit === "weeks") return value * 6048e5;
27218
+ }
27219
+ const iso = ISO8601_REGEX.exec(trimmed);
27220
+ if (iso) {
27221
+ const days = parseFloat(iso[1] ?? "0");
27222
+ const hours = parseFloat(iso[2] ?? "0");
27223
+ const minutes = parseFloat(iso[3] ?? "0");
27224
+ const seconds = parseFloat(iso[4] ?? "0");
27225
+ return (days * 86400 + hours * 3600 + minutes * 60 + seconds) * 1e3;
27226
+ }
27227
+ const asNumber = Number(trimmed);
27228
+ if (!isNaN(asNumber) && asNumber > 0) return asNumber;
27229
+ return null;
27230
+ }
27231
+
27203
27232
  // src/daemon/pm2.ts
27204
27233
  import { execSync, spawnSync } from "child_process";
27205
27234
  import { join as join2, dirname as dirname2 } from "path";
@@ -27681,8 +27710,8 @@ var SuperTaskPlugin = async () => {
27681
27710
  schedule: tool.schema.object({
27682
27711
  type: tool.schema.enum(["cron", "delayed", "recurring"]).describe("\u8C03\u5EA6\u7C7B\u578B"),
27683
27712
  cron_expr: tool.schema.string().optional().describe("cron \u8868\u8FBE\u5F0F\uFF08cron \u7C7B\u578B\u5FC5\u586B\uFF0C\u5982 '0 9 * * 1-5'\uFF09"),
27684
- run_at: tool.schema.number().optional().describe("\u6267\u884C\u65F6\u95F4\u6233 ms\uFF08delayed \u7C7B\u578B\u5FC5\u586B\uFF09"),
27685
- interval_ms: tool.schema.number().optional().describe("\u95F4\u9694\u6BEB\u79D2\uFF08recurring \u7C7B\u578B\u5FC5\u586B\uFF09")
27713
+ delay: tool.schema.string().optional().describe("\u5EF6\u8FDF\u65F6\u95F4\uFF08delayed \u7C7B\u578B\u5FC5\u586B\uFF09\uFF0C\u53CB\u597D\u683C\u5F0F\u5982 '30s' '5min' '1h' '2d'\uFF0C\u4E5F\u652F\u6301 ISO 8601 duration \u5982 'PT30M'"),
27714
+ interval: tool.schema.string().optional().describe("\u5FAA\u73AF\u95F4\u9694\uFF08recurring \u7C7B\u578B\u5FC5\u586B\uFF09\uFF0C\u53CB\u597D\u683C\u5F0F\u5982 '1h' '30min' '5s'\uFF0C\u4E5F\u652F\u6301 ISO 8601 duration \u5982 'PT1H'")
27686
27715
  }).describe("\u8C03\u5EA6\u914D\u7F6E"),
27687
27716
  max_instances: tool.schema.number().optional().describe("\u6700\u5927\u5E76\u53D1\u5B9E\u4F8B\u6570\uFF0C\u9ED8\u8BA4 1"),
27688
27717
  max_retries: tool.schema.number().optional().describe("\u514B\u9686\u7ED9 task \u7684\u6700\u5927\u91CD\u8BD5\u6B21\u6570\uFF0C\u9ED8\u8BA4 3"),
@@ -27694,6 +27723,22 @@ var SuperTaskPlugin = async () => {
27694
27723
  return JSON.stringify({ error: "schedule is required" });
27695
27724
  }
27696
27725
  const scheduleType = args.schedule.type;
27726
+ let cronExpr = args.schedule.cron_expr;
27727
+ let intervalMs = null;
27728
+ let runAt = null;
27729
+ if (scheduleType === "delayed" && args.schedule.delay) {
27730
+ const delayMs = parseDuration(args.schedule.delay);
27731
+ if (delayMs === null) {
27732
+ return JSON.stringify({ error: `Invalid delay format: "${args.schedule.delay}". Use formats like "30s", "5min", "1h", "2d"` });
27733
+ }
27734
+ runAt = Date.now() + delayMs;
27735
+ }
27736
+ if (scheduleType === "recurring" && args.schedule.interval) {
27737
+ intervalMs = parseDuration(args.schedule.interval);
27738
+ if (intervalMs === null) {
27739
+ return JSON.stringify({ error: `Invalid interval format: "${args.schedule.interval}". Use formats like "30s", "5min", "1h", "2d"` });
27740
+ }
27741
+ }
27697
27742
  const tmpl = await TaskTemplateService.create({
27698
27743
  name: args.name,
27699
27744
  agent: args.agent,
@@ -27703,9 +27748,9 @@ var SuperTaskPlugin = async () => {
27703
27748
  importance: args.importance ?? 3,
27704
27749
  urgency: args.urgency ?? 3,
27705
27750
  scheduleType,
27706
- cronExpr: args.schedule.cron_expr,
27707
- intervalMs: args.schedule.interval_ms,
27708
- runAt: args.schedule.run_at,
27751
+ cronExpr,
27752
+ intervalMs,
27753
+ runAt,
27709
27754
  maxInstances: args.max_instances,
27710
27755
  maxRetries: args.max_retries,
27711
27756
  retryBackoffMs: args.retry_backoff_ms