opencode-supertask 0.1.18 → 0.1.20
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/README.md +87 -76
- package/dist/cli/index.js +48 -17
- package/dist/cli/index.js.map +1 -1
- package/dist/gateway/index.js +47 -18
- package/dist/gateway/index.js.map +1 -1
- package/dist/plugin/supertask.js +20362 -20950
- package/dist/plugin/supertask.js.map +1 -1
- package/dist/web/index.js +33 -13
- package/dist/web/index.js.map +1 -1
- package/dist/worker/index.js +19 -7
- package/dist/worker/index.js.map +1 -1
- package/package.json +1 -1
package/dist/gateway/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
|
|
3
1
|
var __create = Object.create;
|
|
4
2
|
var __defProp = Object.defineProperty;
|
|
5
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -6086,6 +6084,14 @@ import { join, dirname } from "path";
|
|
|
6086
6084
|
import { fileURLToPath } from "url";
|
|
6087
6085
|
function getMigrationsFolder() {
|
|
6088
6086
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
6087
|
+
let dir = __dirname;
|
|
6088
|
+
for (let i = 0; i < 5; i++) {
|
|
6089
|
+
const candidate = join(dir, "drizzle", "meta", "_journal.json");
|
|
6090
|
+
if (existsSync(candidate)) {
|
|
6091
|
+
return join(dir, "drizzle");
|
|
6092
|
+
}
|
|
6093
|
+
dir = dirname(dir);
|
|
6094
|
+
}
|
|
6089
6095
|
return join(__dirname, "../../drizzle");
|
|
6090
6096
|
}
|
|
6091
6097
|
function initDb() {
|
|
@@ -6110,7 +6116,9 @@ function initDb() {
|
|
|
6110
6116
|
try {
|
|
6111
6117
|
migrate(_db, { migrationsFolder: getMigrationsFolder() });
|
|
6112
6118
|
} catch (err) {
|
|
6113
|
-
|
|
6119
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
6120
|
+
console.error(`[supertask] migration failed: ${msg}`);
|
|
6121
|
+
throw new Error(`[supertask] DB migration failed: ${msg}`);
|
|
6114
6122
|
}
|
|
6115
6123
|
}
|
|
6116
6124
|
return _db;
|
|
@@ -6130,14 +6138,15 @@ function closeDb() {
|
|
|
6130
6138
|
_db = null;
|
|
6131
6139
|
}
|
|
6132
6140
|
}
|
|
6133
|
-
var DB_FILE_PATH, _sqlite, _db, _migrationRan, db, sqlite;
|
|
6141
|
+
var DEFAULT_DB_PATH, DB_FILE_PATH, _sqlite, _db, _migrationRan, db, sqlite;
|
|
6134
6142
|
var init_db2 = __esm({
|
|
6135
6143
|
"src/core/db/index.ts"() {
|
|
6136
6144
|
"use strict";
|
|
6137
6145
|
init_bun_sqlite();
|
|
6138
6146
|
init_migrator2();
|
|
6139
6147
|
init_schema();
|
|
6140
|
-
|
|
6148
|
+
DEFAULT_DB_PATH = join(homedir(), ".local/share/opencode/tasks.db");
|
|
6149
|
+
DB_FILE_PATH = process.env.SUPERTASK_DB_PATH || DEFAULT_DB_PATH;
|
|
6141
6150
|
_sqlite = null;
|
|
6142
6151
|
_db = null;
|
|
6143
6152
|
_migrationRan = false;
|
|
@@ -18291,6 +18300,10 @@ function formatDate(ts) {
|
|
|
18291
18300
|
const d = ts instanceof Date ? ts : new Date(ts);
|
|
18292
18301
|
return d.toLocaleString("zh-CN", { month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" });
|
|
18293
18302
|
}
|
|
18303
|
+
function esc(s) {
|
|
18304
|
+
if (!s) return "";
|
|
18305
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
18306
|
+
}
|
|
18294
18307
|
function readCurrentConfig() {
|
|
18295
18308
|
if (!existsSync3(CONFIG_PATH)) return {};
|
|
18296
18309
|
try {
|
|
@@ -18311,6 +18324,7 @@ async function retryTask(id){if(!confirm('\u786E\u5B9A\u91CD\u8BD5\u4EFB\u52A1 #
|
|
|
18311
18324
|
async function deleteTask(id){if(!confirm('\u786E\u5B9A\u5220\u9664\u4EFB\u52A1 #'+id+'?'))return;await fetch('/api/tasks/'+id,{method:'DELETE'});location.reload();}
|
|
18312
18325
|
async function showDetail(id){try{const r=await fetch('/api/tasks/'+id);const t=await r.json();document.getElementById('dc').textContent=JSON.stringify(t,null,2);document.getElementById('dd').showModal();}catch(e){alert('\u83B7\u53D6\u8BE6\u60C5\u5931\u8D25');}}
|
|
18313
18326
|
async function showRunDetail(id){try{const r=await fetch('/api/runs/'+id);const t=await r.json();document.getElementById('dc').textContent=JSON.stringify(t,null,2);document.getElementById('dd').showModal();}catch(e){alert('\u83B7\u53D6\u8BE6\u60C5\u5931\u8D25');}}
|
|
18327
|
+
async function showTemplateDetail(id){try{const r=await fetch('/api/templates/'+id);const t=await r.json();document.getElementById('dc').textContent=JSON.stringify(t,null,2);document.getElementById('dd').showModal();}catch(e){alert('\u83B7\u53D6\u8BE6\u60C5\u5931\u8D25');}}
|
|
18314
18328
|
async function enableTmpl(id){await fetch('/api/templates/'+id+'/enable',{method:'POST'});location.reload();}
|
|
18315
18329
|
async function disableTmpl(id){if(!confirm('\u786E\u5B9A\u7981\u7528\u6B64\u6A21\u677F?'))return;await fetch('/api/templates/'+id+'/disable',{method:'POST'});location.reload();}
|
|
18316
18330
|
async function deleteTmpl(id){if(!confirm('\u786E\u5B9A\u5220\u9664\u6B64\u6A21\u677F? \u6B64\u64CD\u4F5C\u4E0D\u53EF\u6062\u590D!'))return;await fetch('/api/templates/'+id,{method:'DELETE'});location.reload();}
|
|
@@ -18495,8 +18509,8 @@ var init_web = __esm({
|
|
|
18495
18509
|
const st = (task.status ?? "").toUpperCase();
|
|
18496
18510
|
rows += `<tr>
|
|
18497
18511
|
<td class="mu">#${task.id}</td>
|
|
18498
|
-
<td><div style="font-weight:500">${task.name}</div><div class="mu sm el">${task.prompt.substring(0, 120)}</div></td>
|
|
18499
|
-
<td><span class="tag">${task.agent}</span></td>
|
|
18512
|
+
<td><div style="font-weight:500">${esc(task.name)}</div><div class="mu sm el">${esc(task.prompt.substring(0, 120))}</div></td>
|
|
18513
|
+
<td><span class="tag">${esc(task.agent)}</span></td>
|
|
18500
18514
|
<td><span class="badge b-${task.status}">${st}</span></td>
|
|
18501
18515
|
<td class="sm ${task.status === "running" ? "" : "mu"}">${formatDuration(task.startedAt, task.finishedAt)}</td>
|
|
18502
18516
|
<td class="mu sm">${(task.retryCount ?? 0) > 0 ? task.retryCount : "-"}</td>
|
|
@@ -18552,15 +18566,15 @@ var init_web = __esm({
|
|
|
18552
18566
|
const toggleBtn = t.enabled ? `<button class="btn btn-sm btn-warn" onclick="disableTmpl(${t.id})">\u7981\u7528</button>` : `<button class="btn btn-sm" onclick="enableTmpl(${t.id})">\u542F\u7528</button>`;
|
|
18553
18567
|
rows += `<tr>
|
|
18554
18568
|
<td class="mu">#${t.id}</td>
|
|
18555
|
-
<td><div style="font-weight:500">${t.name}</div><div class="mu sm el">${t.prompt.substring(0, 100)}</div>
|
|
18556
|
-
<div class="sm" style="margin-top:2px"><span class="tag">${t.agent}</span>${t.model && t.model !== "default" ? ` <span class="tag">${t.model}</span>` : ""}</div></td>
|
|
18569
|
+
<td><div style="font-weight:500">${esc(t.name)}</div><div class="mu sm el">${esc(t.prompt.substring(0, 100))}</div>
|
|
18570
|
+
<div class="sm" style="margin-top:2px"><span class="tag">${esc(t.agent)}</span>${t.model && t.model !== "default" ? ` <span class="tag">${esc(t.model)}</span>` : ""}</div></td>
|
|
18557
18571
|
<td><span class="${typeClass}">${typeLabel}</span></td>
|
|
18558
18572
|
<td class="m sm">${rule}</td>
|
|
18559
18573
|
<td>${statusBadge}</td>
|
|
18560
18574
|
<td class="sm">${t.lastRunAt ? timeAgo(t.lastRunAt) : "-"}</td>
|
|
18561
18575
|
<td class="sm">${t.nextRunAt ? timeUntil(t.nextRunAt) : "-"}</td>
|
|
18562
18576
|
<td>
|
|
18563
|
-
<button class="btn btn-sm" onclick="
|
|
18577
|
+
<button class="btn btn-sm" onclick="showTemplateDetail(${t.id})">\u8BE6\u60C5</button>
|
|
18564
18578
|
<button class="btn btn-sm btn-primary" onclick="triggerTmpl(${t.id})">\u89E6\u53D1</button>
|
|
18565
18579
|
${toggleBtn}
|
|
18566
18580
|
<button class="btn btn-sm btn-danger" onclick="deleteTmpl(${t.id})">\u5220\u9664</button>
|
|
@@ -18612,9 +18626,9 @@ var init_web = __esm({
|
|
|
18612
18626
|
const logBtn = run.log ? `<button class="btn btn-sm" onclick="toggleLog(${run.id})">\u65E5\u5FD7</button>` : "";
|
|
18613
18627
|
rows += `<tr>
|
|
18614
18628
|
<td class="mu">#${run.id}</td>
|
|
18615
|
-
<td><div style="font-weight:500">${run.taskName} <span class="mu">(#${run.taskId})</span></div>
|
|
18616
|
-
${run.model ? `<div class="sm"><span class="tag">${run.model}</span></div>` : ""}</td>
|
|
18617
|
-
<td><span class="tag">${run.taskAgent}</span></td>
|
|
18629
|
+
<td><div style="font-weight:500">${esc(run.taskName)} <span class="mu">(#${run.taskId})</span></div>
|
|
18630
|
+
${run.model ? `<div class="sm"><span class="tag">${esc(run.model)}</span></div>` : ""}</td>
|
|
18631
|
+
<td><span class="tag">${esc(run.taskAgent)}</span></td>
|
|
18618
18632
|
<td><span class="badge b-${run.status}">${(run.status ?? "").toUpperCase()}</span></td>
|
|
18619
18633
|
<td class="sm">${formatDuration(run.startedAt, run.finishedAt)}</td>
|
|
18620
18634
|
<td class="sm mu">${run.heartbeatAt ? timeAgo(run.heartbeatAt) : "-"}</td>
|
|
@@ -18660,7 +18674,7 @@ var init_web = __esm({
|
|
|
18660
18674
|
runRows += `<tr>
|
|
18661
18675
|
<td class="mu">#${run.id}</td><td>#${run.taskId}</td>
|
|
18662
18676
|
<td class="m sm">${shortS}</td>
|
|
18663
|
-
<td class="sm">${run.model || "-"}</td>
|
|
18677
|
+
<td class="sm">${esc(run.model) || "-"}</td>
|
|
18664
18678
|
<td class="sm">${formatDate(run.startedAt)}</td>
|
|
18665
18679
|
<td class="sm">${run.heartbeatAt ? timeAgo(run.heartbeatAt) : "-"}</td>
|
|
18666
18680
|
<td class="m sm">W:${run.workerPid ?? "-"} C:${run.childPid ?? "-"}</td>
|
|
@@ -18749,6 +18763,12 @@ var init_web = __esm({
|
|
|
18749
18763
|
if (!run) return c.json({ error: "not found" }, 404);
|
|
18750
18764
|
return c.json(run);
|
|
18751
18765
|
});
|
|
18766
|
+
app.get("/api/templates/:id", async (c) => {
|
|
18767
|
+
const id = Number(c.req.param("id"));
|
|
18768
|
+
const tmpl = await TaskTemplateService.getById(id);
|
|
18769
|
+
if (!tmpl) return c.json({ error: "not found" }, 404);
|
|
18770
|
+
return c.json(tmpl);
|
|
18771
|
+
});
|
|
18752
18772
|
app.post("/api/tasks/:id/retry", async (c) => {
|
|
18753
18773
|
await TaskService.retry(Number(c.req.param("id")));
|
|
18754
18774
|
return c.json({ success: true });
|
|
@@ -18893,10 +18913,13 @@ var WorkerEngine = class {
|
|
|
18893
18913
|
status: "running"
|
|
18894
18914
|
});
|
|
18895
18915
|
const modelToUse = this.resolveModel(task.model);
|
|
18896
|
-
const
|
|
18897
|
-
|
|
18916
|
+
const args = ["run", "--agent", "supertask-runner", "--format", "json"];
|
|
18917
|
+
if (modelToUse) {
|
|
18918
|
+
args.push("-m", modelToUse);
|
|
18919
|
+
}
|
|
18920
|
+
args.push(`\u6267\u884C\u4EFB\u52A1 ID: ${task.id}${modelToUse ? ` OVERRIDE_MODEL=${modelToUse}` : ""}`);
|
|
18898
18921
|
const cwd = task.cwd || process.cwd();
|
|
18899
|
-
const child = spawn("
|
|
18922
|
+
const child = spawn("opencode", args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
18900
18923
|
await TaskRunService.updatePid(run.id, process.pid, child.pid ?? 0);
|
|
18901
18924
|
let output = "";
|
|
18902
18925
|
const handleData = (data) => {
|
|
@@ -19357,7 +19380,11 @@ async function main() {
|
|
|
19357
19380
|
await scheduler.start();
|
|
19358
19381
|
if (cfg.dashboard.enabled) {
|
|
19359
19382
|
const { dashboardApp: dashboardApp2 } = await Promise.resolve().then(() => (init_web(), web_exports));
|
|
19360
|
-
Bun.serve({
|
|
19383
|
+
Bun.serve({
|
|
19384
|
+
hostname: "127.0.0.1",
|
|
19385
|
+
port: cfg.dashboard.port,
|
|
19386
|
+
fetch: dashboardApp2.fetch
|
|
19387
|
+
});
|
|
19361
19388
|
console.log(JSON.stringify({
|
|
19362
19389
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
19363
19390
|
level: "info",
|
|
@@ -19399,9 +19426,11 @@ async function main() {
|
|
|
19399
19426
|
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
19400
19427
|
process.on("uncaughtException", (err) => {
|
|
19401
19428
|
console.error(JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), level: "fatal", msg: "uncaughtException", error: err.message, stack: err.stack }));
|
|
19429
|
+
process.exit(1);
|
|
19402
19430
|
});
|
|
19403
19431
|
process.on("unhandledRejection", (reason) => {
|
|
19404
19432
|
console.error(JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), level: "fatal", msg: "unhandledRejection", reason: String(reason) }));
|
|
19433
|
+
process.exit(1);
|
|
19405
19434
|
});
|
|
19406
19435
|
}
|
|
19407
19436
|
if (import.meta.main) {
|