opencode-supertask 0.1.1 → 0.1.3

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.
@@ -22655,7 +22655,7 @@ function sql(strings, ...params) {
22655
22655
  return new SQL([new StringChunk(str)]);
22656
22656
  }
22657
22657
  sql2.raw = raw;
22658
- function join2(chunks, separator) {
22658
+ function join3(chunks, separator) {
22659
22659
  const result = [];
22660
22660
  for (const [i, chunk] of chunks.entries()) {
22661
22661
  if (i > 0 && separator !== void 0) {
@@ -22665,7 +22665,7 @@ function sql(strings, ...params) {
22665
22665
  }
22666
22666
  return new SQL(result);
22667
22667
  }
22668
- sql2.join = join2;
22668
+ sql2.join = join3;
22669
22669
  function identifier(value) {
22670
22670
  return new Name(value);
22671
22671
  }
@@ -24961,7 +24961,7 @@ var SQLiteSelectQueryBuilderBase = class extends TypedQueryBuilder {
24961
24961
  return (table, on) => {
24962
24962
  const baseTableName = this.tableName;
24963
24963
  const tableName = getTableLikeName(table);
24964
- if (typeof tableName === "string" && this.config.joins?.some((join2) => join2.alias === tableName)) {
24964
+ if (typeof tableName === "string" && this.config.joins?.some((join3) => join3.alias === tableName)) {
24965
24965
  throw new Error(`Alias "${tableName}" is already used in this query`);
24966
24966
  }
24967
24967
  if (!this.isPartialSelect) {
@@ -25774,7 +25774,7 @@ var SQLiteUpdateBase = class extends QueryPromise {
25774
25774
  createJoin(joinType) {
25775
25775
  return (table, on) => {
25776
25776
  const tableName = getTableLikeName(table);
25777
- if (typeof tableName === "string" && this.config.joins.some((join2) => join2.alias === tableName)) {
25777
+ if (typeof tableName === "string" && this.config.joins.some((join3) => join3.alias === tableName)) {
25778
25778
  throw new Error(`Alias "${tableName}" is already used in this query`);
25779
25779
  }
25780
25780
  if (typeof on === "function") {
@@ -26812,12 +26812,11 @@ var _sqlite = null;
26812
26812
  var _db = null;
26813
26813
  var _migrationRan = false;
26814
26814
  function getMigrationsFolder() {
26815
- const __dirname = dirname(fileURLToPath(import.meta.url));
26816
- return join(__dirname, "../../drizzle");
26815
+ const __dirname2 = dirname(fileURLToPath(import.meta.url));
26816
+ return join(__dirname2, "../../drizzle");
26817
26817
  }
26818
26818
  function initDb() {
26819
26819
  const dataDir = dirname(DB_FILE_PATH);
26820
- const dbExisted = existsSync(DB_FILE_PATH);
26821
26820
  if (!existsSync(dataDir)) {
26822
26821
  mkdirSync(dataDir, { recursive: true });
26823
26822
  }
@@ -27201,12 +27200,103 @@ var TaskTemplateService = class {
27201
27200
  }
27202
27201
  };
27203
27202
 
27204
- // plugin/supertask.ts
27205
- import { spawn } from "child_process";
27206
- var _gatewaySpawned = false;
27203
+ // src/daemon/pm2.ts
27204
+ import { execSync, spawnSync } from "child_process";
27205
+ import { join as join2, dirname as dirname2 } from "path";
27206
+ import { fileURLToPath as fileURLToPath2 } from "url";
27207
+ var __dirname = dirname2(fileURLToPath2(import.meta.url));
27208
+ var GATEWAY_ENTRY = join2(__dirname, "../gateway/index.js");
27209
+ var PROCESS_NAME = "supertask-gateway";
27210
+ function pm2Bin() {
27211
+ return process.platform === "win32" ? "pm2.cmd" : "pm2";
27212
+ }
27213
+ function isPm2Installed() {
27214
+ try {
27215
+ const cmd = process.platform === "win32" ? "where pm2" : "which pm2";
27216
+ execSync(cmd, { stdio: "pipe" });
27217
+ return true;
27218
+ } catch {
27219
+ return false;
27220
+ }
27221
+ }
27222
+ function pm2Exec(args) {
27223
+ const bin = pm2Bin();
27224
+ try {
27225
+ const result = spawnSync(bin, args, {
27226
+ stdio: ["pipe", "pipe", "pipe"],
27227
+ encoding: "utf-8",
27228
+ shell: process.platform === "win32"
27229
+ });
27230
+ const output = (result.stdout ?? "") + (result.stderr ?? "");
27231
+ return { ok: result.status === 0, output };
27232
+ } catch (err) {
27233
+ return { ok: false, output: err instanceof Error ? err.message : String(err) };
27234
+ }
27235
+ }
27236
+ function pm2JsonList() {
27237
+ const { ok, output } = pm2Exec(["jlist"]);
27238
+ if (!ok) return [];
27239
+ try {
27240
+ return JSON.parse(output);
27241
+ } catch {
27242
+ return [];
27243
+ }
27244
+ }
27245
+ function findBunPath() {
27246
+ try {
27247
+ const cmd = process.platform === "win32" ? "where bun" : "which bun";
27248
+ return execSync(cmd, { stdio: "pipe" }).toString().trim().split("\n")[0];
27249
+ } catch {
27250
+ return process.execPath;
27251
+ }
27252
+ }
27207
27253
  function ensureGateway() {
27208
- if (_gatewaySpawned) return;
27209
- _gatewaySpawned = true;
27254
+ try {
27255
+ const list2 = pm2JsonList();
27256
+ const proc = list2.find((p) => p.name === PROCESS_NAME);
27257
+ if (proc && proc.pm2_env?.status === "online") {
27258
+ return;
27259
+ }
27260
+ } catch {
27261
+ }
27262
+ if (!isPm2Installed()) {
27263
+ try {
27264
+ execSync("npm install -g pm2", { stdio: "pipe" });
27265
+ } catch {
27266
+ try {
27267
+ execSync("bun install -g pm2", { stdio: "pipe" });
27268
+ } catch {
27269
+ return;
27270
+ }
27271
+ }
27272
+ }
27273
+ const list = pm2JsonList();
27274
+ const existing = list.find((p) => p.name === PROCESS_NAME);
27275
+ if (existing) {
27276
+ pm2Exec(["restart", PROCESS_NAME]);
27277
+ } else {
27278
+ const bunPath = findBunPath();
27279
+ pm2Exec([
27280
+ "start",
27281
+ GATEWAY_ENTRY,
27282
+ "--name",
27283
+ PROCESS_NAME,
27284
+ "--interpreter",
27285
+ bunPath,
27286
+ "--restart-delay",
27287
+ "5000",
27288
+ "--max-restarts",
27289
+ "30"
27290
+ ]);
27291
+ }
27292
+ pm2Exec(["save"]);
27293
+ }
27294
+
27295
+ // plugin/supertask.ts
27296
+ var _initialized = false;
27297
+ function ensureInit() {
27298
+ if (_initialized) return;
27299
+ _initialized = true;
27210
27300
  try {
27211
27301
  getDb();
27212
27302
  } catch (err) {
@@ -27218,13 +27308,11 @@ function ensureGateway() {
27218
27308
  if (lockRow && Date.now() - lockRow.heartbeat_at < 3e4) {
27219
27309
  return;
27220
27310
  }
27221
- const child = spawn("supertask", ["gateway"], {
27222
- detached: true,
27223
- stdio: "ignore"
27224
- });
27225
- child.unref();
27226
- } catch (err) {
27227
- console.error("[supertask] gateway spawn failed:", err instanceof Error ? err.message : String(err));
27311
+ } catch {
27312
+ }
27313
+ try {
27314
+ ensureGateway();
27315
+ } catch {
27228
27316
  }
27229
27317
  }
27230
27318
  var RUNNER_PROMPT = `\u4F60\u662F **SuperTask \u4EFB\u52A1\u6267\u884C\u5668**\u3002
@@ -27313,7 +27401,7 @@ var SuperTaskPlugin = async () => {
27313
27401
  bash: "allow"
27314
27402
  }
27315
27403
  };
27316
- ensureGateway();
27404
+ ensureInit();
27317
27405
  },
27318
27406
  async "experimental.chat.system.transform"(input, output) {
27319
27407
  output.system.push(SYSTEM_INSTRUCTION);