@co0ontty/wand 4.55.3 → 4.56.0-beta.ga71d7db
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/build-info.json +4 -4
- package/dist/github-connector.d.ts +22 -0
- package/dist/github-connector.js +117 -0
- package/dist/missions.js +42 -9
- package/dist/server-github-routes.d.ts +10 -0
- package/dist/server-github-routes.js +239 -0
- package/dist/server-settings-routes.d.ts +2 -0
- package/dist/server-settings-routes.js +1 -0
- package/dist/server-task-routes.d.ts +4 -0
- package/dist/server-task-routes.js +99 -0
- package/dist/server-workspace-routes.js +70 -27
- package/dist/server.js +25 -0
- package/dist/storage.d.ts +42 -0
- package/dist/storage.js +223 -0
- package/dist/structured-provider-common.js +2 -1
- package/dist/task-types.d.ts +19 -0
- package/dist/task-types.js +1 -0
- package/dist/taskboard-bridge.d.ts +11 -0
- package/dist/taskboard-bridge.js +360 -0
- package/dist/web-ui/content/scripts.js +123 -127
- package/dist/web-ui/content/styles.css +1 -1
- package/dist/web-ui/embedded-assets.js +2 -2
- package/dist/web-ui/index.js +1 -0
- package/package.json +4 -2
- package/vendor/codex-taskboard/LICENSE +201 -0
- package/vendor/codex-taskboard/server/ai-chat-catalog.mjs +1031 -0
- package/vendor/codex-taskboard/server/ai-chat-process.mjs +462 -0
- package/vendor/codex-taskboard/server/ai-chat.mjs +1237 -0
- package/vendor/codex-taskboard/server/ai-turn-owner.mjs +39 -0
- package/vendor/codex-taskboard/server/app.mjs +3211 -0
- package/vendor/codex-taskboard/server/cloud-config.mjs +188 -0
- package/vendor/codex-taskboard/server/cloud-proxy.mjs +310 -0
- package/vendor/codex-taskboard/server/codex-app-server.mjs +376 -0
- package/vendor/codex-taskboard/server/codex-slash-commands-0.139.0.json +62 -0
- package/vendor/codex-taskboard/server/database.mjs +2845 -0
- package/vendor/codex-taskboard/server/index.mjs +41 -0
- package/vendor/codex-taskboard/server/jira-config.mjs +181 -0
- package/vendor/codex-taskboard/server/jira-integration.mjs +487 -0
- package/vendor/codex-taskboard/server/project-summary.mjs +159 -0
- package/vendor/codex-taskboard/shared/api-fields.mjs +163 -0
- package/vendor/codex-taskboard/shared/codex-environment.mjs +5 -0
- package/vendor/codex-taskboard/shared/codex-executable.mjs +77 -0
- package/vendor/codex-taskboard/shared/codex-permissions.mjs +9 -0
- package/vendor/codex-taskboard/shared/composer-reference.d.mts +19 -0
- package/vendor/codex-taskboard/shared/composer-reference.mjs +90 -0
- package/vendor/codex-taskboard/shared/domain.mjs +34 -0
- package/vendor/codex-taskboard/shared/executable-command.mjs +13 -0
- package/vendor/codex-taskboard/shared/process-tree.mjs +27 -0
- package/vendor/codex-taskboard/shared/task-input.mjs +308 -0
- package/vendor/codex-taskboard/shared/task-records.mjs +199 -0
- package/vendor/codex-taskboard/shared/task-relations.mjs +55 -0
- package/vendor/codex-taskboard/shared/taskboard-automation.mjs +277 -0
- package/vendor/codex-taskboard/skills/manage-taskboard/SKILL.md +45 -0
- package/vendor/codex-taskboard/skills/manage-taskboard/agents/openai.yaml +4 -0
- package/vendor/codex-taskboard/skills/manage-taskboard/references/cli.md +211 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { mkdir } from "node:fs/promises";
|
|
2
|
+
import { request as httpRequest } from "node:http";
|
|
3
|
+
import { createServer } from "node:net";
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
function freePort() {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
const probe = createServer();
|
|
10
|
+
probe.once("error", reject);
|
|
11
|
+
probe.listen(0, "127.0.0.1", () => {
|
|
12
|
+
const address = probe.address();
|
|
13
|
+
if (!address || typeof address === "string") {
|
|
14
|
+
probe.close();
|
|
15
|
+
reject(new Error("无法分配任务面板端口。"));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
probe.close((error) => error ? reject(error) : resolve(address.port));
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function waitForReady(port, child) {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
const deadline = Date.now() + 15_000;
|
|
25
|
+
let timer;
|
|
26
|
+
const check = () => {
|
|
27
|
+
if (Date.now() > deadline) {
|
|
28
|
+
reject(new Error("任务面板服务启动超时。"));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const request = httpRequest({ hostname: "127.0.0.1", port, path: "/health", method: "GET", timeout: 1_000 }, (response) => {
|
|
32
|
+
response.resume();
|
|
33
|
+
if ((response.statusCode ?? 500) >= 200 && (response.statusCode ?? 500) < 300) {
|
|
34
|
+
clearTimeout(timer);
|
|
35
|
+
resolve();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
timer = setTimeout(check, 100);
|
|
39
|
+
timer.unref();
|
|
40
|
+
});
|
|
41
|
+
request.on("error", () => { timer = setTimeout(check, 100); timer.unref(); });
|
|
42
|
+
request.end();
|
|
43
|
+
};
|
|
44
|
+
child.once("exit", (code) => { if (code !== null && code !== 0)
|
|
45
|
+
reject(new Error(`任务面板服务退出(${code})。`)); });
|
|
46
|
+
check();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function validId(value) {
|
|
50
|
+
return typeof value === "string" && value.length > 0 && value.length <= 256 && /^[A-Za-z0-9._:-]+$/.test(value);
|
|
51
|
+
}
|
|
52
|
+
export function taskboardIntegrationScript() {
|
|
53
|
+
return `<script>
|
|
54
|
+
(() => {
|
|
55
|
+
const query = new URLSearchParams(location.search);
|
|
56
|
+
const currentSessionId = query.get("wandSessionId") || "";
|
|
57
|
+
const originalFetch = window.fetch.bind(window);
|
|
58
|
+
window.fetch = (input, init = {}) => {
|
|
59
|
+
const headers = new Headers(init.headers || {});
|
|
60
|
+
if (currentSessionId) headers.set("X-Wand-Session-Id", currentSessionId);
|
|
61
|
+
return originalFetch(input, { ...init, headers });
|
|
62
|
+
};
|
|
63
|
+
const providerLabel = (provider) => ({claude:"Claude",codex:"Codex",opencode:"OpenCode",grok:"Grok",qoder:"Qoder",pi:"Pi"}[provider] || provider || "Agent");
|
|
64
|
+
const providers = ["claude", "codex", "opencode", "grok", "qoder", "pi"];
|
|
65
|
+
let catalogPromise;
|
|
66
|
+
const loadCatalog = () => catalogPromise || (catalogPromise = originalFetch("/api/models", {credentials:"same-origin"}).then((response) => response.ok ? response.json() : {}).catch(() => ({})));
|
|
67
|
+
const modelsFor = async (provider) => {
|
|
68
|
+
const catalog = await loadCatalog();
|
|
69
|
+
const entries = Array.isArray(catalog[provider + "Models"]) ? catalog[provider + "Models"] : [];
|
|
70
|
+
const fallback = catalog.defaultModels && catalog.defaultModels[provider] || catalog["default" + provider[0].toUpperCase() + provider.slice(1) + "Model"] || "";
|
|
71
|
+
const options = entries.map((entry) => ({id: String(entry.id || ""), label: String(entry.label || entry.id || "")})).filter((entry) => entry.id);
|
|
72
|
+
if (!options.some((entry) => entry.id === "default")) options.unshift({id:"default", label:fallback ? "跟随服务端默认(" + fallback + ")" : "跟随服务端默认"});
|
|
73
|
+
return options;
|
|
74
|
+
};
|
|
75
|
+
const style = document.createElement("style");
|
|
76
|
+
style.textContent = ".wand-session-links{display:flex;flex-wrap:wrap;align-items:center;gap:5px;margin-top:10px;padding-top:8px;border-top:1px solid color-mix(in srgb, currentColor 12%, transparent);font-size:11px}.wand-session-links button{border:1px solid color-mix(in srgb, currentColor 18%, transparent);border-radius:5px;padding:3px 7px;background:color-mix(in srgb, currentColor 5%, transparent);color:inherit;cursor:pointer;font:inherit}.wand-session-links button:hover{background:color-mix(in srgb, currentColor 12%, transparent)}.wand-session-link{color:#3678c9}.wand-session-bind,.wand-agent-assign{color:#777}.wand-session-empty,.wand-session-loading{opacity:.55}.wand-agent-dialog{border:0;border-radius:14px;padding:0;color:#202124;background:#fff;box-shadow:0 20px 70px rgb(0 0 0 / 28%);width:min(430px,calc(100vw - 32px))}.wand-agent-dialog::backdrop{background:rgb(0 0 0 / 35%);backdrop-filter:blur(3px)}.wand-agent-dialog form{display:grid;gap:14px;padding:20px}.wand-agent-dialog h2{margin:0;font-size:18px}.wand-agent-dialog p{margin:-6px 0 0;color:#6b7280;font-size:12px}.wand-agent-field{display:grid;gap:6px}.wand-agent-field label{font-size:12px;font-weight:650;color:#4b5563}.wand-agent-field select{min-height:34px;border:1px solid #d1d5db;border-radius:7px;padding:0 9px;background:#fff;color:#111827}.wand-agent-actions{display:flex;justify-content:flex-end;gap:8px}.wand-agent-actions button{border:1px solid #d1d5db;border-radius:7px;padding:7px 12px;background:#fff;cursor:pointer}.wand-agent-actions button[type=submit]{border-color:#2563eb;background:#2563eb;color:#fff}.wand-agent-error{margin:0;color:#b91c1c;font-size:12px}.wand-agent-assignment{color:#2563eb;font-weight:650}";
|
|
77
|
+
document.head.appendChild(style);
|
|
78
|
+
const openAssignDialog = async (taskId, card) => {
|
|
79
|
+
if (document.querySelector(".wand-agent-dialog")) return;
|
|
80
|
+
const dialog = document.createElement("dialog");
|
|
81
|
+
dialog.className = "wand-agent-dialog";
|
|
82
|
+
dialog.innerHTML = '<form method="dialog"><h2>指派 Wand Agent</h2><p>选择执行 Agent、模型和思考深度;创建后会话会自动绑定到此任务。</p><div class="wand-agent-field"><label for="wand-agent-provider">Agent</label><select id="wand-agent-provider" name="provider">' + providers.map((provider) => '<option value="' + provider + '">' + providerLabel(provider) + '</option>').join("") + '</select></div><div class="wand-agent-field"><label for="wand-agent-model">模型</label><select id="wand-agent-model" name="model"><option>加载中…</option></select></div><div class="wand-agent-field"><label for="wand-agent-effort">思考深度</label><select id="wand-agent-effort" name="thinkingEffort"><option value="off">关闭</option><option value="standard">标准</option><option value="deep">深入</option><option value="max">最大</option></select></div><p class="wand-agent-error" hidden></p><div class="wand-agent-actions"><button type="button" data-cancel>取消</button><button type="submit">开始执行</button></div></form>';
|
|
83
|
+
document.body.appendChild(dialog);
|
|
84
|
+
const form = dialog.querySelector("form");
|
|
85
|
+
const provider = dialog.querySelector("[name=provider]");
|
|
86
|
+
const model = dialog.querySelector("[name=model]");
|
|
87
|
+
const error = dialog.querySelector(".wand-agent-error");
|
|
88
|
+
const submit = dialog.querySelector("button[type=submit]");
|
|
89
|
+
const refreshModels = async () => {
|
|
90
|
+
const selected = provider.value;
|
|
91
|
+
model.innerHTML = '<option>加载中…</option>';
|
|
92
|
+
for (const entry of await modelsFor(selected)) {
|
|
93
|
+
const option = document.createElement("option"); option.value = entry.id; option.textContent = entry.label; model.appendChild(option);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
provider.addEventListener("change", () => void refreshModels());
|
|
97
|
+
dialog.querySelector("[data-cancel]").addEventListener("click", () => dialog.close());
|
|
98
|
+
form.addEventListener("submit", async (event) => {
|
|
99
|
+
event.preventDefault();
|
|
100
|
+
error.hidden = true; submit.disabled = true; submit.textContent = "正在启动…";
|
|
101
|
+
try {
|
|
102
|
+
const response = await originalFetch("/taskboard/api/wand/assign", {method:"POST", headers:{"Content-Type":"application/json", "X-Wand-Session-Id":currentSessionId}, body:JSON.stringify({taskId, provider:provider.value, model:model.value, thinkingEffort:form.querySelector("[name=thinkingEffort]").value})});
|
|
103
|
+
const payload = await response.json().catch(() => ({}));
|
|
104
|
+
if (!response.ok) throw new Error(payload.error || "指派失败");
|
|
105
|
+
dialog.close();
|
|
106
|
+
dialog.remove();
|
|
107
|
+
card.querySelector(".wand-session-links")?.remove();
|
|
108
|
+
setup(card);
|
|
109
|
+
} catch (caught) {
|
|
110
|
+
error.textContent = caught instanceof Error ? caught.message : "指派失败";
|
|
111
|
+
error.hidden = false; submit.disabled = false; submit.textContent = "开始执行";
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
dialog.addEventListener("close", () => dialog.remove(), {once:true});
|
|
115
|
+
dialog.showModal();
|
|
116
|
+
await refreshModels();
|
|
117
|
+
};
|
|
118
|
+
const setup = (card) => {
|
|
119
|
+
const taskId = card.getAttribute("data-task-id");
|
|
120
|
+
if (!taskId) return;
|
|
121
|
+
let links = card.querySelector(".wand-session-links");
|
|
122
|
+
if (!links) {
|
|
123
|
+
links = document.createElement("div"); links.className = "wand-session-links";
|
|
124
|
+
links.innerHTML = '<span class="wand-session-loading">Wand 会话…</span>';
|
|
125
|
+
card.appendChild(links);
|
|
126
|
+
}
|
|
127
|
+
if (!links.querySelector(".wand-agent-assign")) {
|
|
128
|
+
const assign = document.createElement("button");
|
|
129
|
+
assign.type = "button"; assign.className = "wand-agent-assign"; assign.textContent = "+ 指派 Agent";
|
|
130
|
+
assign.onclick = (event) => { event.stopPropagation(); event.preventDefault(); void openAssignDialog(taskId, card); };
|
|
131
|
+
links.appendChild(assign);
|
|
132
|
+
}
|
|
133
|
+
if (links.dataset.wandSessionsLoaded === taskId) return;
|
|
134
|
+
links.dataset.wandSessionsLoaded = taskId;
|
|
135
|
+
originalFetch("/taskboard/api/wand/sessions?taskId=" + encodeURIComponent(taskId), {headers: currentSessionId ? {"X-Wand-Session-Id": currentSessionId} : {}})
|
|
136
|
+
.then((response) => response.ok ? response.json() : {sessions: []})
|
|
137
|
+
.then((payload) => {
|
|
138
|
+
const sessions = Array.isArray(payload.sessions) ? payload.sessions : [];
|
|
139
|
+
[...links.children].filter((node) => !node.classList.contains("wand-agent-assign")).forEach((node) => node.remove());
|
|
140
|
+
if (!sessions.length) {
|
|
141
|
+
const empty = document.createElement("span"); empty.className = "wand-session-empty"; empty.textContent = currentSessionId ? "尚未绑定 Wand 会话" : "未绑定 Wand 会话"; links.prepend(empty);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
sessions.forEach((session) => {
|
|
145
|
+
const button = document.createElement("button"); button.type = "button"; button.className = "wand-session-link wand-agent-assignment";
|
|
146
|
+
button.textContent = providerLabel(session.provider) + (session.model ? " · " + session.model : "") + " · " + ({off:"关闭",standard:"标准",deep:"深入",max:"最大"}[session.thinkingEffort] || session.thinkingEffort || "关闭");
|
|
147
|
+
button.title = "打开 Wand 会话"; button.onclick = (event) => { event.stopPropagation(); window.parent.postMessage({type:"wand-taskboard-open-session", sessionId: session.id}, location.origin); };
|
|
148
|
+
links.prepend(button);
|
|
149
|
+
});
|
|
150
|
+
}).catch(() => {
|
|
151
|
+
[...links.children].filter((node) => !node.classList.contains("wand-agent-assign")).forEach((node) => node.remove());
|
|
152
|
+
const unavailable = document.createElement("span"); unavailable.className = "wand-session-empty"; unavailable.textContent = "Wand 会话不可用"; links.prepend(unavailable);
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
const scan = () => document.querySelectorAll("[data-task-id]").forEach(setup);
|
|
156
|
+
new MutationObserver(scan).observe(document.documentElement, {childList:true, subtree:true});
|
|
157
|
+
scan();
|
|
158
|
+
})();
|
|
159
|
+
</script>`;
|
|
160
|
+
}
|
|
161
|
+
const TASKBOARD_PROVIDERS = new Set(["claude", "codex", "opencode", "grok", "qoder", "pi"]);
|
|
162
|
+
const TASKBOARD_EFFORTS = new Set(["off", "standard", "deep", "max"]);
|
|
163
|
+
function readJsonBody(request) {
|
|
164
|
+
return new Promise((resolve, reject) => {
|
|
165
|
+
const chunks = [];
|
|
166
|
+
request.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
|
|
167
|
+
request.on("end", () => {
|
|
168
|
+
try {
|
|
169
|
+
resolve(JSON.parse(Buffer.concat(chunks).toString("utf8") || "{}"));
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
reject(new Error("请求体不是有效 JSON。"));
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
request.on("error", reject);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function upstreamJson(port, requestPath) {
|
|
179
|
+
return new Promise((resolve, reject) => {
|
|
180
|
+
const request = httpRequest({ hostname: "127.0.0.1", port, path: requestPath, method: "GET" }, (response) => {
|
|
181
|
+
const chunks = [];
|
|
182
|
+
response.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
|
|
183
|
+
response.on("end", () => {
|
|
184
|
+
try {
|
|
185
|
+
const value = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
186
|
+
if ((response.statusCode ?? 500) >= 400)
|
|
187
|
+
reject(new Error(value?.error || "任务面板读取失败。"));
|
|
188
|
+
else
|
|
189
|
+
resolve(value);
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
reject(new Error("任务面板返回了无效数据。"));
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
request.on("error", reject);
|
|
197
|
+
request.end();
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
function rewriteTaskboardHtml(body) {
|
|
201
|
+
const html = body.toString("utf8");
|
|
202
|
+
const script = taskboardIntegrationScript();
|
|
203
|
+
const marker = html.toLowerCase().lastIndexOf("</head>");
|
|
204
|
+
return Buffer.from(marker >= 0 ? `${html.slice(0, marker)}${script}${html.slice(marker)}` : `${html}${script}`);
|
|
205
|
+
}
|
|
206
|
+
export async function startTaskboardBridge(configDir, storage, sessions, structured, fallbackCwd) {
|
|
207
|
+
const port = await freePort();
|
|
208
|
+
const vendorRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../vendor/codex-taskboard");
|
|
209
|
+
const dataDir = path.join(configDir, "taskboard");
|
|
210
|
+
await mkdir(dataDir, { recursive: true });
|
|
211
|
+
const child = spawn(process.execPath, [path.join(vendorRoot, "server/index.mjs")], {
|
|
212
|
+
cwd: vendorRoot,
|
|
213
|
+
env: {
|
|
214
|
+
...process.env,
|
|
215
|
+
CODEX_TASKBOARD_HOST: "127.0.0.1",
|
|
216
|
+
CODEX_TASKBOARD_PORT: String(port),
|
|
217
|
+
CODEX_TASKBOARD_DATA_DIR: dataDir,
|
|
218
|
+
},
|
|
219
|
+
stdio: "ignore",
|
|
220
|
+
});
|
|
221
|
+
await waitForReady(port, child);
|
|
222
|
+
const handler = async (req, res) => {
|
|
223
|
+
const incoming = new URL(req.originalUrl, "http://127.0.0.1");
|
|
224
|
+
const pathname = incoming.pathname.replace(/^\/taskboard/, "") || "/";
|
|
225
|
+
const query = incoming.search;
|
|
226
|
+
const taskId = typeof incoming.searchParams.get("taskId") === "string" ? incoming.searchParams.get("taskId") ?? "" : "";
|
|
227
|
+
const sessionId = typeof req.headers["x-wand-session-id"] === "string" ? req.headers["x-wand-session-id"] : "";
|
|
228
|
+
if (storage && sessions && structured && pathname === "/api/wand/assign" && req.method === "POST") {
|
|
229
|
+
try {
|
|
230
|
+
const body = await readJsonBody(req);
|
|
231
|
+
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
232
|
+
throw new Error("请求体必须是对象。");
|
|
233
|
+
const input = body;
|
|
234
|
+
const targetTaskId = validId(input.taskId) ? input.taskId : "";
|
|
235
|
+
const provider = typeof input.provider === "string" ? input.provider.trim() : "";
|
|
236
|
+
const model = typeof input.model === "string" ? input.model.trim() : "";
|
|
237
|
+
const thinkingEffort = typeof input.thinkingEffort === "string" ? input.thinkingEffort.trim() : "off";
|
|
238
|
+
if (!targetTaskId || !TASKBOARD_PROVIDERS.has(provider))
|
|
239
|
+
throw new Error("请选择有效的 Agent。");
|
|
240
|
+
if (model.length > 128)
|
|
241
|
+
throw new Error("模型名称过长。");
|
|
242
|
+
if (!TASKBOARD_EFFORTS.has(thinkingEffort))
|
|
243
|
+
throw new Error("思考深度无效。");
|
|
244
|
+
const taskPayload = await upstreamJson(port, `/api/tasks/${encodeURIComponent(targetTaskId)}`);
|
|
245
|
+
const task = taskPayload?.task;
|
|
246
|
+
if (!task || task.source === "jira")
|
|
247
|
+
throw new Error("只能指派本地任务。");
|
|
248
|
+
const projectsPayload = await upstreamJson(port, "/api/projects");
|
|
249
|
+
const project = Array.isArray(projectsPayload?.projects) ? projectsPayload.projects.find((item) => item?.id === task.projectId) : null;
|
|
250
|
+
const current = sessionId ? sessions.get(sessionId) : null;
|
|
251
|
+
const cwd = typeof task.developmentContext?.path === "string" && task.developmentContext.path.trim()
|
|
252
|
+
? task.developmentContext.path.trim()
|
|
253
|
+
: typeof project?.workspacePath === "string" && project.workspacePath.trim()
|
|
254
|
+
? project.workspacePath.trim()
|
|
255
|
+
: current?.cwd || fallbackCwd;
|
|
256
|
+
if (!cwd)
|
|
257
|
+
throw new Error("任务没有可用的工作目录,请先为 Taskboard 项目配置工作目录。");
|
|
258
|
+
const prompt = [task.title, typeof task.description === "string" ? task.description.trim() : ""].filter(Boolean).join("\n\n");
|
|
259
|
+
const session = structured.createSession({
|
|
260
|
+
cwd,
|
|
261
|
+
mode: "agent",
|
|
262
|
+
provider,
|
|
263
|
+
model: model && model !== "default" ? model : undefined,
|
|
264
|
+
thinkingEffort,
|
|
265
|
+
worktreeEnabled: false,
|
|
266
|
+
sessionSource: "automation",
|
|
267
|
+
automationId: `taskboard:${targetTaskId}`,
|
|
268
|
+
});
|
|
269
|
+
storage.bindTaskboardTaskSession(targetTaskId, session.id);
|
|
270
|
+
const completion = structured.sendMessage(session.id, prompt || task.title || "执行此任务");
|
|
271
|
+
completion.catch((error) => console.error(`[Taskboard] Agent dispatch failed for ${targetTaskId}:`, error));
|
|
272
|
+
res.status(202).json({ ok: true, taskId: targetTaskId, session: { id: session.id, provider, model: session.selectedModel, thinkingEffort: session.thinkingEffort, cwd: session.cwd } });
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
res.status(400).json({ error: error instanceof Error ? error.message : String(error) });
|
|
276
|
+
}
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (storage && sessions && pathname === "/api/wand/sessions" && req.method === "GET") {
|
|
280
|
+
const ids = storage.listTaskboardTaskSessions(taskId);
|
|
281
|
+
const result = ids.flatMap((id) => {
|
|
282
|
+
const session = sessions.getLatest(id);
|
|
283
|
+
return session ? [{ id: session.id, provider: session.provider ?? "", sessionKind: session.sessionKind ?? "", title: session.title || session.description || session.command, status: session.status, cwd: session.cwd, model: session.selectedModel || session.structuredState?.model || "", thinkingEffort: session.thinkingEffort || "off" }] : [];
|
|
284
|
+
});
|
|
285
|
+
res.json({ sessions: result });
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (storage && sessions && pathname === "/api/wand/bindings" && req.method === "POST") {
|
|
289
|
+
const body = req.body;
|
|
290
|
+
const targetTaskId = validId(body?.taskId) ? body.taskId : "";
|
|
291
|
+
const targetSessionId = validId(body?.sessionId) ? body.sessionId : sessionId;
|
|
292
|
+
if (!targetTaskId || !targetSessionId || !sessions.get(targetSessionId)) {
|
|
293
|
+
res.status(400).json({ error: "任务或会话无效。" });
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
storage.bindTaskboardTaskSession(targetTaskId, targetSessionId);
|
|
297
|
+
res.status(201).json({ ok: true, taskId: targetTaskId, sessionId: targetSessionId });
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const headers = { ...req.headers };
|
|
301
|
+
delete headers.host;
|
|
302
|
+
delete headers.connection;
|
|
303
|
+
headers["x-forwarded-host"] = req.get("host") ?? undefined;
|
|
304
|
+
const upstream = httpRequest({ hostname: "127.0.0.1", port, path: pathname + query, method: req.method, headers }, (response) => {
|
|
305
|
+
res.status(response.statusCode ?? 502);
|
|
306
|
+
const isHtml = String(response.headers["content-type"] ?? "").includes("text/html");
|
|
307
|
+
const captureTaskMutation = storage && sessions && req.method !== "GET" && req.method !== "HEAD" && pathname.startsWith("/api/tasks");
|
|
308
|
+
if (!isHtml && !captureTaskMutation) {
|
|
309
|
+
for (const [name, value] of Object.entries(response.headers))
|
|
310
|
+
if (value !== undefined && name !== "transfer-encoding" && name !== "connection")
|
|
311
|
+
res.setHeader(name, value);
|
|
312
|
+
response.pipe(res);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
const chunks = [];
|
|
316
|
+
response.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
|
|
317
|
+
response.on("end", () => {
|
|
318
|
+
let body = Buffer.concat(chunks);
|
|
319
|
+
if (isHtml)
|
|
320
|
+
body = rewriteTaskboardHtml(body);
|
|
321
|
+
if (captureTaskMutation) {
|
|
322
|
+
try {
|
|
323
|
+
const payload = JSON.parse(body.toString("utf8"));
|
|
324
|
+
const createdTaskId = typeof payload.task?.id === "string" ? payload.task.id : "";
|
|
325
|
+
if (sessionId && createdTaskId && sessions.get(sessionId))
|
|
326
|
+
storage.bindTaskboardTaskSession(createdTaskId, sessionId);
|
|
327
|
+
}
|
|
328
|
+
catch { /* preserve the upstream response */ }
|
|
329
|
+
}
|
|
330
|
+
for (const [name, value] of Object.entries(response.headers))
|
|
331
|
+
if (value !== undefined && name !== "transfer-encoding" && name !== "connection" && name !== "content-length")
|
|
332
|
+
res.setHeader(name, value);
|
|
333
|
+
res.setHeader("content-length", body.byteLength);
|
|
334
|
+
res.end(body);
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
upstream.once("error", () => { if (!res.headersSent)
|
|
338
|
+
res.status(502).json({ error: "任务面板服务不可用。" });
|
|
339
|
+
else
|
|
340
|
+
res.destroy(); });
|
|
341
|
+
const contentType = String(req.headers["content-type"] ?? "");
|
|
342
|
+
if (contentType.includes("application/json") && req.body !== undefined) {
|
|
343
|
+
const payload = JSON.stringify(req.body);
|
|
344
|
+
delete headers["content-length"];
|
|
345
|
+
upstream.setHeader("content-length", Buffer.byteLength(payload));
|
|
346
|
+
upstream.end(payload);
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
req.pipe(upstream);
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
return {
|
|
353
|
+
handler,
|
|
354
|
+
close: async () => {
|
|
355
|
+
if (!child.killed)
|
|
356
|
+
child.kill("SIGTERM");
|
|
357
|
+
await new Promise((resolve) => { const timer = setTimeout(resolve, 1_000); child.once("exit", () => { clearTimeout(timer); resolve(); }); });
|
|
358
|
+
},
|
|
359
|
+
};
|
|
360
|
+
}
|