opencode-supertask 0.1.2 → 0.1.4

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.
@@ -26817,7 +26817,6 @@ function getMigrationsFolder() {
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
  }
@@ -27243,32 +27242,42 @@ function pm2JsonList() {
27243
27242
  return [];
27244
27243
  }
27245
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
+ }
27246
27253
  function ensureGateway() {
27247
27254
  try {
27248
- const list2 = pm2JsonList();
27249
- const proc = list2.find((p) => p.name === PROCESS_NAME);
27255
+ const list = pm2JsonList();
27256
+ const proc = list.find((p) => p.name === PROCESS_NAME);
27250
27257
  if (proc && proc.pm2_env?.status === "online") {
27251
27258
  return;
27252
27259
  }
27253
27260
  } catch {
27254
27261
  }
27255
27262
  if (!isPm2Installed()) {
27263
+ console.log("[supertask] Installing pm2 for Gateway process management...");
27256
27264
  try {
27257
27265
  execSync("npm install -g pm2", { stdio: "pipe" });
27258
27266
  } catch {
27259
27267
  try {
27260
27268
  execSync("bun install -g pm2", { stdio: "pipe" });
27261
27269
  } catch {
27270
+ console.warn("[supertask] Could not install pm2. Gateway will not auto-start. Run `supertask install` manually.");
27262
27271
  return;
27263
27272
  }
27264
27273
  }
27265
27274
  }
27266
- const list = pm2JsonList();
27267
- const existing = list.find((p) => p.name === PROCESS_NAME);
27275
+ const pm2List = pm2JsonList();
27276
+ const existing = pm2List.find((p) => p.name === PROCESS_NAME);
27268
27277
  if (existing) {
27269
27278
  pm2Exec(["restart", PROCESS_NAME]);
27270
27279
  } else {
27271
- const bunPath = process.execPath;
27280
+ const bunPath = findBunPath();
27272
27281
  pm2Exec([
27273
27282
  "start",
27274
27283
  GATEWAY_ENTRY,
@@ -27296,6 +27305,13 @@ function ensureInit() {
27296
27305
  console.error("[supertask] DB init failed:", err instanceof Error ? err.message : String(err));
27297
27306
  return;
27298
27307
  }
27308
+ try {
27309
+ const lockRow = sqlite.prepare("SELECT pid, heartbeat_at FROM gateway_lock WHERE id = 1").get();
27310
+ if (lockRow && Date.now() - lockRow.heartbeat_at < 3e4) {
27311
+ return;
27312
+ }
27313
+ } catch {
27314
+ }
27299
27315
  try {
27300
27316
  ensureGateway();
27301
27317
  } catch {