opencode-supertask 0.1.0 → 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 +273 -67
- package/dist/cli/index.js.map +1 -1
- package/dist/gateway/index.js +53 -0
- package/dist/gateway/index.js.map +1 -1
- package/dist/plugin/supertask.js +157 -4
- package/dist/plugin/supertask.js.map +1 -1
- package/dist/web/index.js +53 -0
- package/dist/web/index.js.map +1 -1
- package/dist/worker/index.js +53 -0
- package/dist/worker/index.js.map +1 -1
- package/package.json +1 -1
package/dist/plugin/supertask.js
CHANGED
|
@@ -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
|
|
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 =
|
|
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((
|
|
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((
|
|
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") {
|
|
@@ -26678,6 +26678,44 @@ function drizzle(...params) {
|
|
|
26678
26678
|
drizzle2.mock = mock;
|
|
26679
26679
|
})(drizzle || (drizzle = {}));
|
|
26680
26680
|
|
|
26681
|
+
// node_modules/drizzle-orm/migrator.js
|
|
26682
|
+
import crypto from "crypto";
|
|
26683
|
+
import fs from "fs";
|
|
26684
|
+
function readMigrationFiles(config2) {
|
|
26685
|
+
const migrationFolderTo = config2.migrationsFolder;
|
|
26686
|
+
const migrationQueries = [];
|
|
26687
|
+
const journalPath = `${migrationFolderTo}/meta/_journal.json`;
|
|
26688
|
+
if (!fs.existsSync(journalPath)) {
|
|
26689
|
+
throw new Error(`Can't find meta/_journal.json file`);
|
|
26690
|
+
}
|
|
26691
|
+
const journalAsString = fs.readFileSync(`${migrationFolderTo}/meta/_journal.json`).toString();
|
|
26692
|
+
const journal = JSON.parse(journalAsString);
|
|
26693
|
+
for (const journalEntry of journal.entries) {
|
|
26694
|
+
const migrationPath = `${migrationFolderTo}/${journalEntry.tag}.sql`;
|
|
26695
|
+
try {
|
|
26696
|
+
const query = fs.readFileSync(`${migrationFolderTo}/${journalEntry.tag}.sql`).toString();
|
|
26697
|
+
const result = query.split("--> statement-breakpoint").map((it) => {
|
|
26698
|
+
return it;
|
|
26699
|
+
});
|
|
26700
|
+
migrationQueries.push({
|
|
26701
|
+
sql: result,
|
|
26702
|
+
bps: journalEntry.breakpoints,
|
|
26703
|
+
folderMillis: journalEntry.when,
|
|
26704
|
+
hash: crypto.createHash("sha256").update(query).digest("hex")
|
|
26705
|
+
});
|
|
26706
|
+
} catch {
|
|
26707
|
+
throw new Error(`No file ${migrationPath} found in ${migrationFolderTo} folder`);
|
|
26708
|
+
}
|
|
26709
|
+
}
|
|
26710
|
+
return migrationQueries;
|
|
26711
|
+
}
|
|
26712
|
+
|
|
26713
|
+
// node_modules/drizzle-orm/bun-sqlite/migrator.js
|
|
26714
|
+
function migrate(db2, config2) {
|
|
26715
|
+
const migrations = readMigrationFiles(config2);
|
|
26716
|
+
db2.dialect.migrate(migrations, db2.session, config2);
|
|
26717
|
+
}
|
|
26718
|
+
|
|
26681
26719
|
// src/core/db/schema.ts
|
|
26682
26720
|
var schema_exports = {};
|
|
26683
26721
|
__export(schema_exports, {
|
|
@@ -26768,11 +26806,18 @@ var taskTemplates = sqliteTable("task_templates", {
|
|
|
26768
26806
|
import { existsSync, mkdirSync } from "fs";
|
|
26769
26807
|
import { homedir } from "os";
|
|
26770
26808
|
import { join, dirname } from "path";
|
|
26809
|
+
import { fileURLToPath } from "url";
|
|
26771
26810
|
var DB_FILE_PATH = join(homedir(), ".local/share/opencode/tasks.db");
|
|
26772
26811
|
var _sqlite = null;
|
|
26773
26812
|
var _db = null;
|
|
26813
|
+
var _migrationRan = false;
|
|
26814
|
+
function getMigrationsFolder() {
|
|
26815
|
+
const __dirname2 = dirname(fileURLToPath(import.meta.url));
|
|
26816
|
+
return join(__dirname2, "../../drizzle");
|
|
26817
|
+
}
|
|
26774
26818
|
function initDb() {
|
|
26775
26819
|
const dataDir = dirname(DB_FILE_PATH);
|
|
26820
|
+
const dbExisted = existsSync(DB_FILE_PATH);
|
|
26776
26821
|
if (!existsSync(dataDir)) {
|
|
26777
26822
|
mkdirSync(dataDir, { recursive: true });
|
|
26778
26823
|
}
|
|
@@ -26788,6 +26833,14 @@ function initDb() {
|
|
|
26788
26833
|
);
|
|
26789
26834
|
`);
|
|
26790
26835
|
_db = drizzle(_sqlite, { schema: schema_exports });
|
|
26836
|
+
if (!_migrationRan) {
|
|
26837
|
+
_migrationRan = true;
|
|
26838
|
+
try {
|
|
26839
|
+
migrate(_db, { migrationsFolder: getMigrationsFolder() });
|
|
26840
|
+
} catch (err) {
|
|
26841
|
+
console.error("[supertask] migration failed:", err instanceof Error ? err.message : String(err));
|
|
26842
|
+
}
|
|
26843
|
+
}
|
|
26791
26844
|
return _db;
|
|
26792
26845
|
}
|
|
26793
26846
|
function getDb() {
|
|
@@ -27148,7 +27201,106 @@ var TaskTemplateService = class {
|
|
|
27148
27201
|
}
|
|
27149
27202
|
};
|
|
27150
27203
|
|
|
27204
|
+
// src/daemon/pm2.ts
|
|
27205
|
+
import { execSync, spawnSync } from "child_process";
|
|
27206
|
+
import { join as join2, dirname as dirname2 } from "path";
|
|
27207
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
27208
|
+
var __dirname = dirname2(fileURLToPath2(import.meta.url));
|
|
27209
|
+
var GATEWAY_ENTRY = join2(__dirname, "../gateway/index.js");
|
|
27210
|
+
var PROCESS_NAME = "supertask-gateway";
|
|
27211
|
+
function pm2Bin() {
|
|
27212
|
+
return process.platform === "win32" ? "pm2.cmd" : "pm2";
|
|
27213
|
+
}
|
|
27214
|
+
function isPm2Installed() {
|
|
27215
|
+
try {
|
|
27216
|
+
const cmd = process.platform === "win32" ? "where pm2" : "which pm2";
|
|
27217
|
+
execSync(cmd, { stdio: "pipe" });
|
|
27218
|
+
return true;
|
|
27219
|
+
} catch {
|
|
27220
|
+
return false;
|
|
27221
|
+
}
|
|
27222
|
+
}
|
|
27223
|
+
function pm2Exec(args) {
|
|
27224
|
+
const bin = pm2Bin();
|
|
27225
|
+
try {
|
|
27226
|
+
const result = spawnSync(bin, args, {
|
|
27227
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
27228
|
+
encoding: "utf-8",
|
|
27229
|
+
shell: process.platform === "win32"
|
|
27230
|
+
});
|
|
27231
|
+
const output = (result.stdout ?? "") + (result.stderr ?? "");
|
|
27232
|
+
return { ok: result.status === 0, output };
|
|
27233
|
+
} catch (err) {
|
|
27234
|
+
return { ok: false, output: err instanceof Error ? err.message : String(err) };
|
|
27235
|
+
}
|
|
27236
|
+
}
|
|
27237
|
+
function pm2JsonList() {
|
|
27238
|
+
const { ok, output } = pm2Exec(["jlist"]);
|
|
27239
|
+
if (!ok) return [];
|
|
27240
|
+
try {
|
|
27241
|
+
return JSON.parse(output);
|
|
27242
|
+
} catch {
|
|
27243
|
+
return [];
|
|
27244
|
+
}
|
|
27245
|
+
}
|
|
27246
|
+
function ensureGateway() {
|
|
27247
|
+
try {
|
|
27248
|
+
const list2 = pm2JsonList();
|
|
27249
|
+
const proc = list2.find((p) => p.name === PROCESS_NAME);
|
|
27250
|
+
if (proc && proc.pm2_env?.status === "online") {
|
|
27251
|
+
return;
|
|
27252
|
+
}
|
|
27253
|
+
} catch {
|
|
27254
|
+
}
|
|
27255
|
+
if (!isPm2Installed()) {
|
|
27256
|
+
try {
|
|
27257
|
+
execSync("npm install -g pm2", { stdio: "pipe" });
|
|
27258
|
+
} catch {
|
|
27259
|
+
try {
|
|
27260
|
+
execSync("bun install -g pm2", { stdio: "pipe" });
|
|
27261
|
+
} catch {
|
|
27262
|
+
return;
|
|
27263
|
+
}
|
|
27264
|
+
}
|
|
27265
|
+
}
|
|
27266
|
+
const list = pm2JsonList();
|
|
27267
|
+
const existing = list.find((p) => p.name === PROCESS_NAME);
|
|
27268
|
+
if (existing) {
|
|
27269
|
+
pm2Exec(["restart", PROCESS_NAME]);
|
|
27270
|
+
} else {
|
|
27271
|
+
const bunPath = process.execPath;
|
|
27272
|
+
pm2Exec([
|
|
27273
|
+
"start",
|
|
27274
|
+
GATEWAY_ENTRY,
|
|
27275
|
+
"--name",
|
|
27276
|
+
PROCESS_NAME,
|
|
27277
|
+
"--interpreter",
|
|
27278
|
+
bunPath,
|
|
27279
|
+
"--restart-delay",
|
|
27280
|
+
"5000",
|
|
27281
|
+
"--max-restarts",
|
|
27282
|
+
"30"
|
|
27283
|
+
]);
|
|
27284
|
+
}
|
|
27285
|
+
pm2Exec(["save"]);
|
|
27286
|
+
}
|
|
27287
|
+
|
|
27151
27288
|
// plugin/supertask.ts
|
|
27289
|
+
var _initialized = false;
|
|
27290
|
+
function ensureInit() {
|
|
27291
|
+
if (_initialized) return;
|
|
27292
|
+
_initialized = true;
|
|
27293
|
+
try {
|
|
27294
|
+
getDb();
|
|
27295
|
+
} catch (err) {
|
|
27296
|
+
console.error("[supertask] DB init failed:", err instanceof Error ? err.message : String(err));
|
|
27297
|
+
return;
|
|
27298
|
+
}
|
|
27299
|
+
try {
|
|
27300
|
+
ensureGateway();
|
|
27301
|
+
} catch {
|
|
27302
|
+
}
|
|
27303
|
+
}
|
|
27152
27304
|
var RUNNER_PROMPT = `\u4F60\u662F **SuperTask \u4EFB\u52A1\u6267\u884C\u5668**\u3002
|
|
27153
27305
|
|
|
27154
27306
|
## \u5DE5\u4F5C\u6D41\u7A0B
|
|
@@ -27235,6 +27387,7 @@ var SuperTaskPlugin = async () => {
|
|
|
27235
27387
|
bash: "allow"
|
|
27236
27388
|
}
|
|
27237
27389
|
};
|
|
27390
|
+
ensureInit();
|
|
27238
27391
|
},
|
|
27239
27392
|
async "experimental.chat.system.transform"(input, output) {
|
|
27240
27393
|
output.system.push(SYSTEM_INSTRUCTION);
|