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.
package/dist/cli/index.js CHANGED
@@ -4506,7 +4506,7 @@ var init_sql = __esm({
4506
4506
  return new SQL([new StringChunk(str)]);
4507
4507
  }
4508
4508
  sql2.raw = raw2;
4509
- function join3(chunks, separator) {
4509
+ function join4(chunks, separator) {
4510
4510
  const result = [];
4511
4511
  for (const [i, chunk] of chunks.entries()) {
4512
4512
  if (i > 0 && separator !== void 0) {
@@ -4516,7 +4516,7 @@ var init_sql = __esm({
4516
4516
  }
4517
4517
  return new SQL(result);
4518
4518
  }
4519
- sql2.join = join3;
4519
+ sql2.join = join4;
4520
4520
  function identifier(value) {
4521
4521
  return new Name(value);
4522
4522
  }
@@ -7132,7 +7132,7 @@ var init_select2 = __esm({
7132
7132
  return (table, on) => {
7133
7133
  const baseTableName = this.tableName;
7134
7134
  const tableName = getTableLikeName(table);
7135
- if (typeof tableName === "string" && this.config.joins?.some((join3) => join3.alias === tableName)) {
7135
+ if (typeof tableName === "string" && this.config.joins?.some((join4) => join4.alias === tableName)) {
7136
7136
  throw new Error(`Alias "${tableName}" is already used in this query`);
7137
7137
  }
7138
7138
  if (!this.isPartialSelect) {
@@ -7974,7 +7974,7 @@ var init_update = __esm({
7974
7974
  createJoin(joinType) {
7975
7975
  return (table, on) => {
7976
7976
  const tableName = getTableLikeName(table);
7977
- if (typeof tableName === "string" && this.config.joins.some((join3) => join3.alias === tableName)) {
7977
+ if (typeof tableName === "string" && this.config.joins.some((join4) => join4.alias === tableName)) {
7978
7978
  throw new Error(`Alias "${tableName}" is already used in this query`);
7979
7979
  }
7980
7980
  if (typeof on === "function") {
@@ -9399,12 +9399,11 @@ import { homedir } from "os";
9399
9399
  import { join, dirname } from "path";
9400
9400
  import { fileURLToPath } from "url";
9401
9401
  function getMigrationsFolder() {
9402
- const __dirname = dirname(fileURLToPath(import.meta.url));
9403
- return join(__dirname, "../../drizzle");
9402
+ const __dirname2 = dirname(fileURLToPath(import.meta.url));
9403
+ return join(__dirname2, "../../drizzle");
9404
9404
  }
9405
9405
  function initDb() {
9406
9406
  const dataDir = dirname(DB_FILE_PATH);
9407
- const dbExisted = existsSync(DB_FILE_PATH);
9408
9407
  if (!existsSync(dataDir)) {
9409
9408
  mkdirSync(dataDir, { recursive: true });
9410
9409
  }
@@ -22733,6 +22732,194 @@ var init_web = __esm({
22733
22732
  }
22734
22733
  });
22735
22734
 
22735
+ // src/daemon/pm2.ts
22736
+ var pm2_exports = {};
22737
+ __export(pm2_exports, {
22738
+ ensureGateway: () => ensureGateway,
22739
+ install: () => install,
22740
+ isGatewayRunning: () => isGatewayRunning,
22741
+ uninstall: () => uninstall
22742
+ });
22743
+ import { execSync, spawnSync } from "child_process";
22744
+ import { join as join3, dirname as dirname3 } from "path";
22745
+ import { fileURLToPath as fileURLToPath2 } from "url";
22746
+ function pm2Bin() {
22747
+ return process.platform === "win32" ? "pm2.cmd" : "pm2";
22748
+ }
22749
+ function isPm2Installed() {
22750
+ try {
22751
+ const cmd = process.platform === "win32" ? "where pm2" : "which pm2";
22752
+ execSync(cmd, { stdio: "pipe" });
22753
+ return true;
22754
+ } catch {
22755
+ return false;
22756
+ }
22757
+ }
22758
+ function installPm2() {
22759
+ console.log("[supertask] Installing pm2...");
22760
+ try {
22761
+ execSync("npm install -g pm2", { stdio: "inherit" });
22762
+ return true;
22763
+ } catch {
22764
+ try {
22765
+ execSync("bun install -g pm2", { stdio: "inherit" });
22766
+ return true;
22767
+ } catch {
22768
+ return false;
22769
+ }
22770
+ }
22771
+ }
22772
+ function pm2Exec(args) {
22773
+ const bin = pm2Bin();
22774
+ try {
22775
+ const result = spawnSync(bin, args, {
22776
+ stdio: ["pipe", "pipe", "pipe"],
22777
+ encoding: "utf-8",
22778
+ shell: process.platform === "win32"
22779
+ });
22780
+ const output = (result.stdout ?? "") + (result.stderr ?? "");
22781
+ return { ok: result.status === 0, output };
22782
+ } catch (err) {
22783
+ return { ok: false, output: err instanceof Error ? err.message : String(err) };
22784
+ }
22785
+ }
22786
+ function pm2JsonList() {
22787
+ const { ok, output } = pm2Exec(["jlist"]);
22788
+ if (!ok) return [];
22789
+ try {
22790
+ return JSON.parse(output);
22791
+ } catch {
22792
+ return [];
22793
+ }
22794
+ }
22795
+ function isGatewayRunning() {
22796
+ const list = pm2JsonList();
22797
+ const proc = list.find((p) => p.name === PROCESS_NAME);
22798
+ if (!proc) return false;
22799
+ return proc.pm2_env?.status === "online";
22800
+ }
22801
+ function findBunPath() {
22802
+ try {
22803
+ const cmd = process.platform === "win32" ? "where bun" : "which bun";
22804
+ return execSync(cmd, { stdio: "pipe" }).toString().trim().split("\n")[0];
22805
+ } catch {
22806
+ return process.execPath;
22807
+ }
22808
+ }
22809
+ function install() {
22810
+ if (!isPm2Installed()) {
22811
+ if (!installPm2()) {
22812
+ throw new Error("[supertask] Failed to install pm2. Please install it manually: npm install -g pm2");
22813
+ }
22814
+ }
22815
+ console.log("[supertask] pm2 ready");
22816
+ const list = pm2JsonList();
22817
+ const existing = list.find((p) => p.name === PROCESS_NAME);
22818
+ if (existing) {
22819
+ console.log("[supertask] Gateway process already registered, reloading...");
22820
+ const { ok } = pm2Exec(["reload", PROCESS_NAME]);
22821
+ if (!ok) {
22822
+ console.error("[supertask] pm2 reload failed, trying restart...");
22823
+ pm2Exec(["restart", PROCESS_NAME]);
22824
+ }
22825
+ } else {
22826
+ console.log("[supertask] Starting Gateway with pm2...");
22827
+ const bunPath = findBunPath();
22828
+ const { ok, output } = pm2Exec([
22829
+ "start",
22830
+ GATEWAY_ENTRY,
22831
+ "--name",
22832
+ PROCESS_NAME,
22833
+ "--interpreter",
22834
+ bunPath,
22835
+ "--restart-delay",
22836
+ "5000",
22837
+ "--max-restarts",
22838
+ "30"
22839
+ ]);
22840
+ if (!ok) {
22841
+ throw new Error(`[supertask] pm2 start failed: ${output}`);
22842
+ }
22843
+ }
22844
+ pm2Exec(["save"]);
22845
+ console.log("[supertask] Configuring startup...");
22846
+ const { ok: startupOk, output: startupOutput } = pm2Exec(["startup"]);
22847
+ if (!startupOk) {
22848
+ if (startupOutput.includes("sudo") || startupOutput.includes("run as root")) {
22849
+ console.log("[supertask] pm2 startup requires elevated permissions.");
22850
+ console.log("[supertask] Run the command shown above, or manually execute:");
22851
+ console.log(` pm2 startup`);
22852
+ console.log(` pm2 save`);
22853
+ } else if (process.platform === "win32") {
22854
+ console.log("[supertask] On Windows, use pm2-installer for startup:");
22855
+ console.log(" npm install -g pm2-windows-startup");
22856
+ console.log(" pm2-startup install");
22857
+ }
22858
+ }
22859
+ console.log("\n[supertask] Gateway installed and running!");
22860
+ console.log("[supertask] Manage with: pm2 status / pm2 logs supertask-gateway");
22861
+ }
22862
+ function uninstall() {
22863
+ console.log("[supertask] Stopping Gateway...");
22864
+ pm2Exec(["stop", PROCESS_NAME]);
22865
+ console.log("[supertask] Removing Gateway from pm2...");
22866
+ pm2Exec(["delete", PROCESS_NAME]);
22867
+ pm2Exec(["save"]);
22868
+ console.log("\n[supertask] Gateway removed from pm2.");
22869
+ console.log("[supertask] Note: pm2 startup config was not removed (you may have other pm2 processes).");
22870
+ console.log("[supertask] To fully remove pm2 startup: pm2 unstartup");
22871
+ }
22872
+ function ensureGateway() {
22873
+ try {
22874
+ const list2 = pm2JsonList();
22875
+ const proc = list2.find((p) => p.name === PROCESS_NAME);
22876
+ if (proc && proc.pm2_env?.status === "online") {
22877
+ return;
22878
+ }
22879
+ } catch {
22880
+ }
22881
+ if (!isPm2Installed()) {
22882
+ try {
22883
+ execSync("npm install -g pm2", { stdio: "pipe" });
22884
+ } catch {
22885
+ try {
22886
+ execSync("bun install -g pm2", { stdio: "pipe" });
22887
+ } catch {
22888
+ return;
22889
+ }
22890
+ }
22891
+ }
22892
+ const list = pm2JsonList();
22893
+ const existing = list.find((p) => p.name === PROCESS_NAME);
22894
+ if (existing) {
22895
+ pm2Exec(["restart", PROCESS_NAME]);
22896
+ } else {
22897
+ const bunPath = findBunPath();
22898
+ pm2Exec([
22899
+ "start",
22900
+ GATEWAY_ENTRY,
22901
+ "--name",
22902
+ PROCESS_NAME,
22903
+ "--interpreter",
22904
+ bunPath,
22905
+ "--restart-delay",
22906
+ "5000",
22907
+ "--max-restarts",
22908
+ "30"
22909
+ ]);
22910
+ }
22911
+ pm2Exec(["save"]);
22912
+ }
22913
+ var __dirname, GATEWAY_ENTRY, PROCESS_NAME;
22914
+ var init_pm2 = __esm({
22915
+ "src/daemon/pm2.ts"() {
22916
+ "use strict";
22917
+ __dirname = dirname3(fileURLToPath2(import.meta.url));
22918
+ GATEWAY_ENTRY = join3(__dirname, "../gateway/index.js");
22919
+ PROCESS_NAME = "supertask-gateway";
22920
+ }
22921
+ });
22922
+
22736
22923
  // node_modules/commander/esm.mjs
22737
22924
  var import_index = __toESM(require_commander(), 1);
22738
22925
  var {
@@ -22939,10 +23126,10 @@ program2.command("template").description("\u7BA1\u7406\u4EFB\u52A1\u8C03\u5EA6\u
22939
23126
  program2.command("init").description("Initialize SuperTask (create config + run migrations)").action(async () => withDb(async () => {
22940
23127
  const { existsSync: existsSync4, mkdirSync: mkdirSync3, writeFileSync: writeFileSync2 } = await import("fs");
22941
23128
  const { homedir: homedir3 } = await import("os");
22942
- const { join: join3, dirname: dirname3 } = await import("path");
23129
+ const { join: join4, dirname: dirname4 } = await import("path");
22943
23130
  const { CONFIG_PATH: CONFIG_PATH2 } = await Promise.resolve().then(() => (init_config(), config_exports));
22944
23131
  if (!existsSync4(CONFIG_PATH2)) {
22945
- const dir = dirname3(CONFIG_PATH2);
23132
+ const dir = dirname4(CONFIG_PATH2);
22946
23133
  if (!existsSync4(dir)) mkdirSync3(dir, { recursive: true });
22947
23134
  writeFileSync2(CONFIG_PATH2, JSON.stringify({
22948
23135
  worker: { maxConcurrency: 2, defaultModel: "zhipuai-coding-plan/glm-4.7" },
@@ -22955,18 +23142,18 @@ program2.command("init").description("Initialize SuperTask (create config + run
22955
23142
  const { getDb: getDb2 } = await Promise.resolve().then(() => (init_db2(), db_exports));
22956
23143
  const { migrate: migrate2 } = await Promise.resolve().then(() => (init_migrator2(), migrator_exports));
22957
23144
  const { join: pJoin, dirname: pDirname } = await import("path");
22958
- const { fileURLToPath: fileURLToPath2 } = await import("url");
22959
- const __dirname = pDirname(fileURLToPath2(import.meta.url));
22960
- migrate2(getDb2(), { migrationsFolder: pJoin(__dirname, "../../drizzle") });
23145
+ const { fileURLToPath: fileURLToPath3 } = await import("url");
23146
+ const __dirname2 = pDirname(fileURLToPath3(import.meta.url));
23147
+ migrate2(getDb2(), { migrationsFolder: pJoin(__dirname2, "../../drizzle") });
22961
23148
  console.log(JSON.stringify({ migrated: true }));
22962
23149
  }));
22963
23150
  program2.command("migrate").description("Run database migrations").action(async () => withDb(async () => {
22964
23151
  const { getDb: getDb2 } = await Promise.resolve().then(() => (init_db2(), db_exports));
22965
23152
  const { migrate: migrate2 } = await Promise.resolve().then(() => (init_migrator2(), migrator_exports));
22966
- const { join: join3, dirname: dirname3 } = await import("path");
22967
- const { fileURLToPath: fileURLToPath2 } = await import("url");
22968
- const __dirname = dirname3(fileURLToPath2(import.meta.url));
22969
- migrate2(getDb2(), { migrationsFolder: join3(__dirname, "../../drizzle") });
23153
+ const { join: join4, dirname: dirname4 } = await import("path");
23154
+ const { fileURLToPath: fileURLToPath3 } = await import("url");
23155
+ const __dirname2 = dirname4(fileURLToPath3(import.meta.url));
23156
+ migrate2(getDb2(), { migrationsFolder: join4(__dirname2, "../../drizzle") });
22970
23157
  console.log(JSON.stringify({ migrated: true }));
22971
23158
  }));
22972
23159
  program2.command("gateway").description("Start the Gateway process (foreground)").action(async () => {
@@ -22981,5 +23168,13 @@ program2.command("config").description("Show current configuration").action(asyn
22981
23168
  const cfg = loadConfig2();
22982
23169
  console.log(JSON.stringify(cfg, null, 2));
22983
23170
  });
23171
+ program2.command("install").description("Install Gateway as pm2 service (auto-start on boot, crash recovery)").action(async () => {
23172
+ const { install: pm2Install } = await Promise.resolve().then(() => (init_pm2(), pm2_exports));
23173
+ pm2Install();
23174
+ });
23175
+ program2.command("uninstall").description("Stop and remove Gateway pm2 service").action(async () => {
23176
+ const { uninstall: pm2Uninstall } = await Promise.resolve().then(() => (init_pm2(), pm2_exports));
23177
+ pm2Uninstall();
23178
+ });
22984
23179
  program2.parse();
22985
23180
  //# sourceMappingURL=index.js.map