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