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.
@@ -9102,8 +9102,8 @@ var require_CronFileParser = __commonJS({
9102
9102
  * @throws If file cannot be read
9103
9103
  */
9104
9104
  static parseFileSync(filePath) {
9105
- const { readFileSync } = __require("fs");
9106
- const data = readFileSync(filePath, "utf8");
9105
+ const { readFileSync: readFileSync2 } = __require("fs");
9106
+ const data = readFileSync2(filePath, "utf8");
9107
9107
  return _CronFileParser.#parseContent(data);
9108
9108
  }
9109
9109
  /**
@@ -27200,13 +27200,52 @@ 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";
27206
27235
  import { fileURLToPath as fileURLToPath2 } from "url";
27236
+ import { readFileSync } from "fs";
27207
27237
  var __dirname = dirname2(fileURLToPath2(import.meta.url));
27208
27238
  var GATEWAY_ENTRY = join2(__dirname, "../gateway/index.js");
27209
27239
  var PROCESS_NAME = "supertask-gateway";
27240
+ function getPackageVersion() {
27241
+ try {
27242
+ const pkgPath = join2(__dirname, "../package.json");
27243
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
27244
+ return pkg.version || "0.0.0";
27245
+ } catch {
27246
+ return "0.0.0";
27247
+ }
27248
+ }
27210
27249
  function pm2Bin() {
27211
27250
  return process.platform === "win32" ? "pm2.cmd" : "pm2";
27212
27251
  }
@@ -27251,10 +27290,37 @@ function findBunPath() {
27251
27290
  }
27252
27291
  }
27253
27292
  function ensureGateway() {
27293
+ const currentVersion = getPackageVersion();
27254
27294
  try {
27255
27295
  const list = pm2JsonList();
27256
27296
  const proc = list.find((p) => p.name === PROCESS_NAME);
27257
27297
  if (proc && proc.pm2_env?.status === "online") {
27298
+ const runningVersion = proc.pm2_env.pm_exec_path ? void 0 : void 0;
27299
+ const envVersion = proc.pm2_env.env?.SUPERTASK_VERSION;
27300
+ if (envVersion === currentVersion) {
27301
+ return;
27302
+ }
27303
+ console.log(`[supertask] Version changed: ${envVersion ?? "unknown"} \u2192 ${currentVersion}, reloading Gateway...`);
27304
+ const bunPath = findBunPath();
27305
+ pm2Exec([
27306
+ "delete",
27307
+ PROCESS_NAME
27308
+ ]);
27309
+ pm2Exec([
27310
+ "start",
27311
+ GATEWAY_ENTRY,
27312
+ "--name",
27313
+ PROCESS_NAME,
27314
+ "--interpreter",
27315
+ bunPath,
27316
+ "--restart-delay",
27317
+ "5000",
27318
+ "--max-restarts",
27319
+ "30",
27320
+ "--env",
27321
+ `SUPERTASK_VERSION=${currentVersion}`
27322
+ ]);
27323
+ pm2Exec(["save"]);
27258
27324
  return;
27259
27325
  }
27260
27326
  } catch {
@@ -27278,6 +27344,7 @@ function ensureGateway() {
27278
27344
  pm2Exec(["restart", PROCESS_NAME]);
27279
27345
  } else {
27280
27346
  const bunPath = findBunPath();
27347
+ const version3 = getPackageVersion();
27281
27348
  pm2Exec([
27282
27349
  "start",
27283
27350
  GATEWAY_ENTRY,
@@ -27288,7 +27355,9 @@ function ensureGateway() {
27288
27355
  "--restart-delay",
27289
27356
  "5000",
27290
27357
  "--max-restarts",
27291
- "30"
27358
+ "30",
27359
+ "--env",
27360
+ `SUPERTASK_VERSION=${version3}`
27292
27361
  ]);
27293
27362
  }
27294
27363
  pm2Exec(["save"]);
@@ -27681,8 +27750,8 @@ var SuperTaskPlugin = async () => {
27681
27750
  schedule: tool.schema.object({
27682
27751
  type: tool.schema.enum(["cron", "delayed", "recurring"]).describe("\u8C03\u5EA6\u7C7B\u578B"),
27683
27752
  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")
27753
+ 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'"),
27754
+ 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
27755
  }).describe("\u8C03\u5EA6\u914D\u7F6E"),
27687
27756
  max_instances: tool.schema.number().optional().describe("\u6700\u5927\u5E76\u53D1\u5B9E\u4F8B\u6570\uFF0C\u9ED8\u8BA4 1"),
27688
27757
  max_retries: tool.schema.number().optional().describe("\u514B\u9686\u7ED9 task \u7684\u6700\u5927\u91CD\u8BD5\u6B21\u6570\uFF0C\u9ED8\u8BA4 3"),
@@ -27694,6 +27763,22 @@ var SuperTaskPlugin = async () => {
27694
27763
  return JSON.stringify({ error: "schedule is required" });
27695
27764
  }
27696
27765
  const scheduleType = args.schedule.type;
27766
+ let cronExpr = args.schedule.cron_expr;
27767
+ let intervalMs = null;
27768
+ let runAt = null;
27769
+ if (scheduleType === "delayed" && args.schedule.delay) {
27770
+ const delayMs = parseDuration(args.schedule.delay);
27771
+ if (delayMs === null) {
27772
+ return JSON.stringify({ error: `Invalid delay format: "${args.schedule.delay}". Use formats like "30s", "5min", "1h", "2d"` });
27773
+ }
27774
+ runAt = Date.now() + delayMs;
27775
+ }
27776
+ if (scheduleType === "recurring" && args.schedule.interval) {
27777
+ intervalMs = parseDuration(args.schedule.interval);
27778
+ if (intervalMs === null) {
27779
+ return JSON.stringify({ error: `Invalid interval format: "${args.schedule.interval}". Use formats like "30s", "5min", "1h", "2d"` });
27780
+ }
27781
+ }
27697
27782
  const tmpl = await TaskTemplateService.create({
27698
27783
  name: args.name,
27699
27784
  agent: args.agent,
@@ -27703,9 +27788,9 @@ var SuperTaskPlugin = async () => {
27703
27788
  importance: args.importance ?? 3,
27704
27789
  urgency: args.urgency ?? 3,
27705
27790
  scheduleType,
27706
- cronExpr: args.schedule.cron_expr,
27707
- intervalMs: args.schedule.interval_ms,
27708
- runAt: args.schedule.run_at,
27791
+ cronExpr,
27792
+ intervalMs,
27793
+ runAt,
27709
27794
  maxInstances: args.max_instances,
27710
27795
  maxRetries: args.max_retries,
27711
27796
  retryBackoffMs: args.retry_backoff_ms