taskboard-workbench 0.0.0-stage → 0.3.0
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/CHANGELOG.md +403 -0
- package/LICENSE +21 -0
- package/README.md +210 -2
- package/cli/tb.mjs +314 -0
- package/cordis.patch.yml +5 -0
- package/index.js +633 -0
- package/lib/client.js +522 -0
- package/package.json +96 -4
- package/scripts/tb-flow.mjs +86 -0
- package/skills/taskboard-flow/SKILL.md +89 -0
- package/skills/taskboard-flow/references/errors.md +61 -0
- package/skills/taskboard-flow/references/injection.md +70 -0
- package/skills/taskboard-flow/references/steps/S0.md +31 -0
- package/skills/taskboard-flow/references/steps/S1.md +28 -0
- package/skills/taskboard-flow/references/steps/S2.md +31 -0
- package/skills/taskboard-flow/references/steps/S3.md +22 -0
- package/skills/taskboard-flow/references/steps/S4.md +25 -0
- package/skills/taskboard-flow/references/steps/S5.md +36 -0
- package/skills/taskboard-flow/references/steps/S6.md +30 -0
- package/skills/taskboard-flow/references/steps/S7.md +23 -0
- package/spec/norms/acceptance.md +36 -0
- package/spec/norms/card-update.md +39 -0
- package/spec/norms/doc-editing.md +30 -0
- package/spec/norms/flow.md +45 -0
- package/spec/norms/manifest.json +41 -0
- package/spec/norms/project-defaults.md +33 -0
- package/spec//345/233/242/351/230/237agent.md +171 -0
- package/src/core/acceptance.mjs +62 -0
- package/src/core/advance.mjs +192 -0
- package/src/core/agent-teams.mjs +48 -0
- package/src/core/binding.mjs +44 -0
- package/src/core/config.mjs +22 -0
- package/src/core/contract.mjs +287 -0
- package/src/core/debug-dispatch.mjs +94 -0
- package/src/core/delivery.mjs +93 -0
- package/src/core/deps.mjs +53 -0
- package/src/core/diagnostics.mjs +648 -0
- package/src/core/domain.mjs +235 -0
- package/src/core/empty-state.mjs +240 -0
- package/src/core/errors.mjs +142 -0
- package/src/core/evidence.mjs +86 -0
- package/src/core/executor.mjs +645 -0
- package/src/core/human-review.mjs +773 -0
- package/src/core/intake.mjs +179 -0
- package/src/core/kickoff.mjs +147 -0
- package/src/core/loop.mjs +498 -0
- package/src/core/memory.mjs +193 -0
- package/src/core/next-step.mjs +377 -0
- package/src/core/notify.mjs +183 -0
- package/src/core/owner.mjs +41 -0
- package/src/core/requirements.mjs +292 -0
- package/src/core/review.mjs +82 -0
- package/src/core/session-naming.mjs +64 -0
- package/src/core/split-ask.mjs +107 -0
- package/src/core/store.mjs +3442 -0
- package/src/core/team.mjs +170 -0
- package/src/core/ticket-stage.mjs +150 -0
- package/src/core/verify.mjs +170 -0
- package/src/core/watchdog.mjs +144 -0
- package/src/host/ai-elaborator.mjs +26 -0
- package/src/host/team-engine.mjs +125 -0
- package/src/host/tool-surface.mjs +205 -0
- package/src/mcp/flow-block.mjs +173 -0
- package/src/mcp/server.mjs +156 -0
- package/src/mcp/tools.mjs +764 -0
- package/src/server/api.mjs +2050 -0
- package/src/server/events.mjs +32 -0
- package/src/server/kickoff.mjs +46 -0
- package/src/server/server.mjs +214 -0
- package/src/server/verify.mjs +112 -0
- package/tools/env-check.mjs +35 -0
- package/tools/seed.mjs +67 -0
- package/web/app.js +5337 -0
- package/web/index.html +15 -0
- package/web/tokens.css +1151 -0
package/index.js
ADDED
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* index.js —— DSH 宿主侧 Cordis 插件(零依赖,无静态 @deepseek-ai/* import)。
|
|
3
|
+
*
|
|
4
|
+
* 职责:把已实现的 HTTP API(src/server/api.mjs,与独立验证台共用同一路由逻辑)
|
|
5
|
+
* 挂到独立命名空间 /integrations/taskboard-workbench 下,并同时托管 web/ 静态资源
|
|
6
|
+
* (客户端面板通过同源脚本加载复用 web/app.js 的看板渲染)。
|
|
7
|
+
*
|
|
8
|
+
* 数据目录:插件配置 dataDir > 宿主 `ctx.get("config").dataDir` > TB_DATA_DIR > 系统临时目录
|
|
9
|
+
* (默认不写代码仓库)。**不得直接读 `ctx.config`**:本插件 `inject` 只声明了 `webServer`,
|
|
10
|
+
* cordis 会对未声明属性抛「cannot get property "config" without inject」⇒ 装载期整条 entry
|
|
11
|
+
* 不激活(2026-10-26 用隔离真宿主 `--from-default-profile` 复现;真实 profile 因为用户层
|
|
12
|
+
* patch 显式给了 `config.dataDir`,把 `??` 右边短路掉,才一直没暴露)。
|
|
13
|
+
*/
|
|
14
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
15
|
+
import { createRequire } from "node:module";
|
|
16
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
|
|
19
|
+
import { resolveDataDir } from "./src/core/config.mjs";
|
|
20
|
+
import { openStore } from "./src/core/store.mjs";
|
|
21
|
+
import { createRequestHandler, ensureDefaultProject, WEB_DIR } from "./src/server/server.mjs";
|
|
22
|
+
import { createEventHub } from "./src/server/events.mjs";
|
|
23
|
+
import { runExecutionLoop, listLoopProjects } from "./src/core/loop.mjs";
|
|
24
|
+
import { createLlmElaborator } from "./src/host/ai-elaborator.mjs";
|
|
25
|
+
import { createTeamEnginePort } from "./src/host/team-engine.mjs";
|
|
26
|
+
|
|
27
|
+
export const name = "taskboard-workbench";
|
|
28
|
+
export const inject = ["webServer"];
|
|
29
|
+
|
|
30
|
+
export const PREFIX = "/integrations/taskboard-workbench";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* HostSessionPort —— 宿主会话能力真实 adapter(切片2 收口)。
|
|
34
|
+
*
|
|
35
|
+
* 对齐 agent-teams 的**懒取**模式:不在 apply 时 eager 取服务,而是每次调用时经 `getService(name)` 现取,
|
|
36
|
+
* 因此服务在插件之后出现/被替换时自然生效(无需 eager 注入)。
|
|
37
|
+
* - createSession({preset,cwd,title}):`sessionController.create()`(退回 `sessions.create`);`cwd` 透传工作区;
|
|
38
|
+
* 宿主 `create()` **不收 title** ⇒ `title` 走**建完再 `rename()`**(改名失败如实回 `titleApplied:false` + 原因,不谎报);
|
|
39
|
+
* **尝试**预置内容,失败不抛错。
|
|
40
|
+
* - renameSession(id, title):会话改名(2026-10-23 命名约束的宿主出口)。
|
|
41
|
+
* - sendPrompt(id, text):**任务下发**。经 `sessionController.prompt({mode:"queue"})` 把指令投递给该会话的 Agent。
|
|
42
|
+
* - openSession(id):宿主侧无此能力(返回 ui-workspace-unavailable);会话切换由**客户端** uiWorkspace 完成(见 lib/client.js)。
|
|
43
|
+
* - getCurrentSessionId():宿主工具面才有 `exec.agent?.id`,此处恒返回 null(接口占位)。
|
|
44
|
+
*/
|
|
45
|
+
export function createHostSessionPort({ getService, getCtx } = {}) {
|
|
46
|
+
const sessions = () => getService?.("sessions");
|
|
47
|
+
const sessionController = () => getService?.("sessionController");
|
|
48
|
+
const agents = () => getService?.("agents");
|
|
49
|
+
const uiWorkspace = () => getService?.("uiWorkspace");
|
|
50
|
+
const mkRequestId = () =>
|
|
51
|
+
(globalThis.crypto?.randomUUID?.() ?? `tb-${Date.now()}-${Math.random().toString(36).slice(2)}`);
|
|
52
|
+
// ---- 作用域取服务(FR-71 投递修复)------------------------------------------
|
|
53
|
+
// DSH 的 agent preset 绑定要求 ctx 带作用域(`scopeOf(ctx) = ctx[kScope]`);插件激活时拿到的是
|
|
54
|
+
// **根作用域** ctx,其内部 ctx 无 kScope → `sessionController.create/prompt` 恒抛
|
|
55
|
+
// "Agent preset binding requires a scoped context"。这里用 dsh-scope 的公开导出 `createScope`
|
|
56
|
+
// 自铸一个作用域再取服务;**取不到就回落旧路径并如实降级**(不静默、不谎报成功)。
|
|
57
|
+
let scopeFactoryState = "unresolved";
|
|
58
|
+
// ---- 会话工作区归属缓存(FR-84 补口)----------------------------------------
|
|
59
|
+
// `sessionQuery.listSessions()` 一次性返回全部会话头(含 cwd);按请求反复调用没必要,故加短 TTL 缓存。
|
|
60
|
+
const SESSION_ORIGIN_TTL_MS = 15000;
|
|
61
|
+
// map: sessionId -> { cwd, title, updatedAt }(FR-84 补口 2026-10-22 起带标题,供「绑定已有会话」列表展示)
|
|
62
|
+
const originCache = { at: 0, map: null };
|
|
63
|
+
/**
|
|
64
|
+
* 构建会话索引并**如实返回失败原因**(FR-84 补口 2026-10-22;真机教训:原实现把 `listSessions()` 的异常
|
|
65
|
+
* 静默 catch 成 `unavailable`,于是「改绑已有会话」在真机上只剩一句「不可用」,无从排障)。
|
|
66
|
+
* ⚠️ 必须以**闭包函数**形式存在(而非对象方法):`sessionIndex()`/`listSessions()` 等对象方法是**裸标识符**调用,
|
|
67
|
+
* 对象方法之间不共享作用域,写成对象方法会 ReferenceError(真机 2026-10-22 复现:index-threw:buildSessionIndex is not defined)。
|
|
68
|
+
* 返回 `{ map, source, reason }`:成功 `map` 为 Map;失败 `map=null` 且 `reason` 说明原因。
|
|
69
|
+
*/
|
|
70
|
+
const buildSessionIndex = async () => {
|
|
71
|
+
const q = getService?.("sessionQuery");
|
|
72
|
+
if (!q) return { map: null, source: "unavailable", reason: "sessionQuery-service-unavailable" };
|
|
73
|
+
const method = typeof q.listSessions === "function" ? "listSessions" : (typeof q.list === "function" ? "list" : null);
|
|
74
|
+
if (!method) return { map: null, source: "unavailable", reason: "sessionQuery-has-no-list-method" };
|
|
75
|
+
const now = Date.now();
|
|
76
|
+
if (now - originCache.at > SESSION_ORIGIN_TTL_MS) { originCache.at = now; originCache.map = null; }
|
|
77
|
+
if (!originCache.map) {
|
|
78
|
+
let records = null;
|
|
79
|
+
try { records = await q[method](); }
|
|
80
|
+
catch (error) {
|
|
81
|
+
const reason = `list-failed:${error?.code ?? error?.message ?? String(error)}`;
|
|
82
|
+
console.error(`[taskboard-workbench] sessionQuery.${method}() 失败:${reason}`);
|
|
83
|
+
return { map: null, source: "error", reason };
|
|
84
|
+
}
|
|
85
|
+
const map = new Map();
|
|
86
|
+
for (const rec of records ?? []) {
|
|
87
|
+
const header = rec?.header ?? rec;
|
|
88
|
+
const id = header?.id ?? rec?.sessionId ?? null;
|
|
89
|
+
if (!id) continue;
|
|
90
|
+
map.set(id, {
|
|
91
|
+
cwd: header?.cwd ?? rec?.cwd ?? null,
|
|
92
|
+
title: header?.title ?? rec?.title ?? null,
|
|
93
|
+
updatedAt: header?.updatedAt ?? rec?.updatedAt ?? null,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
originCache.map = map;
|
|
97
|
+
}
|
|
98
|
+
return { map: originCache.map, source: `sessionQuery.${method}`, reason: null };
|
|
99
|
+
};
|
|
100
|
+
let scopeFactoryPromise = null;
|
|
101
|
+
const scopedCtxs = new Map();
|
|
102
|
+
/**
|
|
103
|
+
* 解析 `@deepseek-ai/dsh-scope`。本插件是**软链**安装(`~/.dsh/profiles/<p>/node_modules/<name>` →
|
|
104
|
+
* 本仓库),ESM 裸导入会从**仓库真实路径**向上找 node_modules,因此**必然找不到**(仓库零依赖)。
|
|
105
|
+
* 故按"多策略"解析,全部失败则如实降级(不谎报):
|
|
106
|
+
* ① 裸导入(上游若把 dsh-scope 提升到 profile 可见处,这条会先中);
|
|
107
|
+
* ② 从 **DSH 自身入口**(`process.argv[1]`,即 `dsh` bin,require 会跟随软链)解析;
|
|
108
|
+
* ③ 从已解析出的 dsh 包目录解析(兜底)。
|
|
109
|
+
* 说明:②③ 与 DSH 的安装布局耦合,故一律 try/catch;拿不到就回落旧路径并在日志里写明原因。
|
|
110
|
+
*/
|
|
111
|
+
function scopeCandidates() {
|
|
112
|
+
const out = ["@deepseek-ai/dsh-scope"];
|
|
113
|
+
const bases = [];
|
|
114
|
+
for (const raw of [process.argv?.[1], process.env?.DSH_BIN]) {
|
|
115
|
+
if (!raw) continue;
|
|
116
|
+
// 关键:`dsh` 是**符号链接**(bin/dsh → lib/bin.js),而 createRequire **不跟随软链**,
|
|
117
|
+
// 直接拿 argv[1] 解析会 MODULE_NOT_FOUND。这里先 realpath 再解析。
|
|
118
|
+
try { bases.push(existsSync(raw) ? realpathSync(raw) : raw); } catch { bases.push(raw); }
|
|
119
|
+
}
|
|
120
|
+
for (const base of bases) {
|
|
121
|
+
try {
|
|
122
|
+
const resolved = createRequire(base).resolve("@deepseek-ai/dsh-scope");
|
|
123
|
+
if (resolved && !out.includes(resolved)) out.push(resolved);
|
|
124
|
+
} catch { /* 继续尝试下一个 */ }
|
|
125
|
+
}
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
function loadScopeFactory() {
|
|
129
|
+
if (scopeFactoryPromise) return scopeFactoryPromise;
|
|
130
|
+
scopeFactoryPromise = (async () => {
|
|
131
|
+
const candidates = scopeCandidates();
|
|
132
|
+
const errors = [];
|
|
133
|
+
for (const candidate of candidates) {
|
|
134
|
+
try {
|
|
135
|
+
const spec = candidate.startsWith("/") ? pathToFileURL(candidate).href : candidate;
|
|
136
|
+
const mod = await import(spec);
|
|
137
|
+
if (typeof mod?.createScope === "function") {
|
|
138
|
+
scopeFactoryState = candidate.startsWith("/") ? `ready:${path.dirname(path.dirname(candidate))}` : "ready:bare";
|
|
139
|
+
console.log(`[taskboard-workbench] dsh-scope 已解析:${candidate}(作用域投递可用)`);
|
|
140
|
+
return mod.createScope;
|
|
141
|
+
}
|
|
142
|
+
errors.push(`${candidate}: 无 createScope 导出`);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
errors.push(`${candidate}: ${error?.code ?? error?.message ?? "import-failed"}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
scopeFactoryState = `unavailable:${errors.join(" | ")}`;
|
|
148
|
+
console.error(`[taskboard-workbench] dsh-scope 解析失败 → 投递回落根作用域(会因 preset binding 被拒):${scopeFactoryState}`);
|
|
149
|
+
return null;
|
|
150
|
+
})();
|
|
151
|
+
return scopeFactoryPromise;
|
|
152
|
+
}
|
|
153
|
+
/** 自铸(并缓存)一个作用域 ctx;宿主/模块不可得时返回 null。 */
|
|
154
|
+
async function scopedCtx(key) {
|
|
155
|
+
const root = typeof getCtx === "function" ? getCtx() : null;
|
|
156
|
+
if (!root || typeof root.get !== "function" || typeof root.plugin !== "function") return null;
|
|
157
|
+
if (scopedCtxs.has(key)) return scopedCtxs.get(key);
|
|
158
|
+
const createScope = await loadScopeFactory();
|
|
159
|
+
if (typeof createScope !== "function") return null;
|
|
160
|
+
try {
|
|
161
|
+
const scoped = createScope(root, key)?.ctx ?? null;
|
|
162
|
+
if (scoped) scopedCtxs.set(key, scoped);
|
|
163
|
+
return scoped;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
console.error(`[taskboard-workbench] createScope failed: ${error?.message ?? error}`);
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async function scopedSessionController(key) {
|
|
170
|
+
const scoped = await scopedCtx(key);
|
|
171
|
+
if (!scoped) return null;
|
|
172
|
+
try { return scoped.get?.("sessionController") ?? null; } catch { return null; }
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* 往目标会话投递一条"用户指令"(任务下发/继续调试)。
|
|
176
|
+
* 首选宿主 `sessionController.prompt`(真实把消息送入会话 Agent inbox);退回 `sessions.sendMessage`。
|
|
177
|
+
*/
|
|
178
|
+
async function deliver(sessionId, text) {
|
|
179
|
+
if (!sessionId || !text) return { sent: false, reason: "no-target" };
|
|
180
|
+
const scoped = await scopedSessionController(`tb-session:${sessionId}`);
|
|
181
|
+
const sc = scoped ?? sessionController();
|
|
182
|
+
if (typeof sc?.prompt === "function") {
|
|
183
|
+
try {
|
|
184
|
+
await sc.prompt(
|
|
185
|
+
{ requestId: mkRequestId(), sessionId, mode: "queue", content: [{ type: "text", text }] },
|
|
186
|
+
new AbortController().signal,
|
|
187
|
+
);
|
|
188
|
+
return { sent: true, via: scoped ? "scoped.sessionController.prompt" : "sessionController.prompt" };
|
|
189
|
+
} catch (error) {
|
|
190
|
+
console.error(`[taskboard-workbench] sessionController.prompt failed: ${error?.message ?? error}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const api = sessions();
|
|
194
|
+
if (typeof api?.sendMessage === "function") {
|
|
195
|
+
try {
|
|
196
|
+
await api.sendMessage(sessionId, text);
|
|
197
|
+
return { sent: true, via: "sessions.sendMessage" };
|
|
198
|
+
} catch (error) {
|
|
199
|
+
return { sent: false, reason: error?.message ?? String(error) };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return { sent: false, reason: "prompt-unavailable" };
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* 会话改名(2026-10-23 用户命名约束)。
|
|
206
|
+
* 宿主契约实测:`sessionController.create()` **不接受 title**(`SessionCreateRequest` 只有
|
|
207
|
+
* workspaceId/cwd/sessionId/agentPreset),只有 `rename({ sessionId, title })`
|
|
208
|
+
* (jsDoc「Rename one Session after explicitly resuming it」)⇒ 一律**建完再改名**。
|
|
209
|
+
* **得不到确认就如实回失败原因**,绝不谎报改名成功。
|
|
210
|
+
*/
|
|
211
|
+
async function renameSession(sessionId, title) {
|
|
212
|
+
if (!sessionId) return { renamed: false, reason: "no-session" };
|
|
213
|
+
if (!title) return { renamed: false, reason: "no-title" };
|
|
214
|
+
const sc = (await scopedSessionController(`tb-session:rename:${sessionId}`)) ?? sessionController();
|
|
215
|
+
if (typeof sc?.rename !== "function") return { renamed: false, reason: "rename-unavailable" };
|
|
216
|
+
try {
|
|
217
|
+
const res = await sc.rename({ sessionId, title });
|
|
218
|
+
return { renamed: true, title: res?.title ?? title, seq: res?.seq ?? null };
|
|
219
|
+
} catch (error) {
|
|
220
|
+
console.error(`[taskboard-workbench] sessionController.rename failed: ${error?.message ?? error}`);
|
|
221
|
+
return { renamed: false, reason: error?.code ?? String(error?.message ?? error) };
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/** 建完补标题:未给 title / 未建出会话 / 改名失败 ⇒ 一律**如实**回报,供上层决定是否提示用户。 */
|
|
225
|
+
async function applyTitle(sessionId, title) {
|
|
226
|
+
if (!title) return { titleApplied: false, titleReason: "no-title" };
|
|
227
|
+
const r = await renameSession(sessionId, title);
|
|
228
|
+
return { titleApplied: Boolean(r.renamed), titleReason: r.renamed ? null : (r.reason ?? "rename-failed") };
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
/** 动态可用性:能否建会话 / 投递指令。 */
|
|
232
|
+
get available() {
|
|
233
|
+
return typeof sessionController()?.create === "function" || typeof sessions()?.create === "function";
|
|
234
|
+
},
|
|
235
|
+
async createSession({ preset, cwd, title } = {}) {
|
|
236
|
+
const sc = (await scopedSessionController("tb-session:new")) ?? sessionController();
|
|
237
|
+
if (typeof sc?.create === "function") {
|
|
238
|
+
try {
|
|
239
|
+
// 2026-10-19 修复:宿主 `session.create({cwd})`(`dsh-api-session-controller`)**支持指定工作目录**,
|
|
240
|
+
// 不传则落在 `defaultCwd`(=dsh 进程的工作目录)。真机复现的后果:项目 workspacePath ≠ 进程目录时,
|
|
241
|
+
// 「重建并绑定项目主会话」建出来的会话 cwd 是进程目录 → 会被 FR-84 的**工作区归属门**继续拦下
|
|
242
|
+
// (`session-other-workspace`),形成「重建了还是打不开」的锁死。故这里把项目工作区透传给宿主。
|
|
243
|
+
const created = await sc.create(cwd ? { cwd } : {});
|
|
244
|
+
const sessionId = typeof created === "string" ? created : (created?.sessionId ?? created?.id ?? null);
|
|
245
|
+
const named = await applyTitle(sessionId, title);
|
|
246
|
+
const presetApplied = sessionId && preset ? (await deliver(sessionId, preset)).sent : false;
|
|
247
|
+
return { sessionId, presetApplied, titleApplied: named.titleApplied, titleReason: named.titleReason };
|
|
248
|
+
} catch (error) {
|
|
249
|
+
console.error(`[taskboard-workbench] sessionController.create failed: ${error?.message ?? error}`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const api = sessions();
|
|
253
|
+
if (typeof api?.create !== "function") return { sessionId: null, presetApplied: false, titleApplied: false, titleReason: title ? "session-create-failed" : "no-title" };
|
|
254
|
+
let sessionId = null;
|
|
255
|
+
try {
|
|
256
|
+
// DSH `sessions.create(id, options)`:**第一个参数是 id**,缺省才由 store 自铸 `session-<n>`。
|
|
257
|
+
// 传 `create({})` 会把对象当成 id → `session header id "[object Object]" does not match session id`。
|
|
258
|
+
const created = await api.create();
|
|
259
|
+
sessionId = typeof created === "string" ? created : (created?.id ?? created?.sessionId ?? null);
|
|
260
|
+
} catch (error) {
|
|
261
|
+
console.error(`[taskboard-workbench] sessions.create failed: ${error?.message ?? error}`);
|
|
262
|
+
return { sessionId: null, presetApplied: false, titleApplied: false, titleReason: title ? "session-create-failed" : "no-title" };
|
|
263
|
+
}
|
|
264
|
+
const namedFallback = await applyTitle(sessionId, title);
|
|
265
|
+
const presetApplied = sessionId && preset ? (await deliver(sessionId, preset)).sent : false;
|
|
266
|
+
return { sessionId, presetApplied, titleApplied: namedFallback.titleApplied, titleReason: namedFallback.titleReason };
|
|
267
|
+
},
|
|
268
|
+
/**
|
|
269
|
+
* 会话改名(2026-10-23 用户命名约束「【任务】/【项目】+ 时间/备注」的宿主出口)。
|
|
270
|
+
* 宿主契约(实测):`SessionRenameRequest = { sessionId, title }` → `SessionRenameValue = { title, seq }`。
|
|
271
|
+
* **失败如实回 `renamed:false` + 原因**,让上层能如实提示(不谎报成功)。
|
|
272
|
+
*/
|
|
273
|
+
async renameSession(sessionId, title) {
|
|
274
|
+
return renameSession(sessionId, title);
|
|
275
|
+
},
|
|
276
|
+
/** 任务下发:把指令投递到会话(供执行循环/团队派发复用)。 */
|
|
277
|
+
async sendPrompt(sessionId, text) {
|
|
278
|
+
return deliver(sessionId, text);
|
|
279
|
+
},
|
|
280
|
+
/**
|
|
281
|
+
* 跟踪执行会话是否仍在执行(宿主 `agents` 注册表):
|
|
282
|
+
* - live:该会话当前有活跃 Agent(进程内注册表命中)
|
|
283
|
+
* - running:`agent.status === "running"`(驱动中,未回到 idle)
|
|
284
|
+
* - pending:inbox 里尚未消费的消息数(nextTurn + nextStep)
|
|
285
|
+
* 用途:派发前判定"已有执行会话在执行且未返回结论"→ 停止再次下发。
|
|
286
|
+
*/
|
|
287
|
+
sessionState(sessionId) {
|
|
288
|
+
const empty = { sessionId: sessionId ?? null, live: false, running: false, status: null, pending: 0 };
|
|
289
|
+
if (!sessionId) return empty;
|
|
290
|
+
let agent = null;
|
|
291
|
+
try { agent = agents()?.get?.(sessionId) ?? null; } catch { agent = null; }
|
|
292
|
+
if (!agent) return empty;
|
|
293
|
+
const inbox = agent.inbox ?? {};
|
|
294
|
+
const pending = (inbox.nextTurn?.length ?? 0) + (inbox.nextStep?.length ?? 0);
|
|
295
|
+
return { sessionId, live: true, running: agent.status === "running", status: agent.status ?? null, pending };
|
|
296
|
+
},
|
|
297
|
+
/**
|
|
298
|
+
* 会话存在性判定(FR-84):优先查**持久化**会话(`sessionQuery.observeSession`),
|
|
299
|
+
* 其次看进程内 `agents` 注册表。**判不准时返回 `exists:null`(未知)——不得把"查不到"谎报成"已失效"**。
|
|
300
|
+
*/
|
|
301
|
+
async sessionExists(sessionId) {
|
|
302
|
+
if (!sessionId) return { sessionId: null, exists: false, source: "none" };
|
|
303
|
+
const q = getService?.("sessionQuery");
|
|
304
|
+
if (typeof q?.observeSession === "function") {
|
|
305
|
+
try {
|
|
306
|
+
const observed = await q.observeSession(sessionId);
|
|
307
|
+
if (typeof observed?.[Symbol.dispose] === "function") { try { observed[Symbol.dispose](); } catch { /* ignore */ } }
|
|
308
|
+
return { sessionId, exists: observed !== undefined && observed !== null, source: "sessionQuery.observeSession" };
|
|
309
|
+
} catch (error) {
|
|
310
|
+
if (error?.code === "SESSION_QUERY_SESSION_NOT_FOUND") return { sessionId, exists: false, source: "sessionQuery.observeSession" };
|
|
311
|
+
return { sessionId, exists: null, source: `sessionQuery-error:${error?.code ?? error?.message ?? "unknown"}` };
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
const agent = (() => { try { return agents()?.get?.(sessionId) ?? null; } catch { return null; } })();
|
|
315
|
+
if (agent) return { sessionId, exists: true, source: "agents" };
|
|
316
|
+
return { sessionId, exists: null, source: "unavailable" };
|
|
317
|
+
},
|
|
318
|
+
/**
|
|
319
|
+
* 宿主**已持久化会话索引**(FR-84 补口 2026-10-22):`sessionId → { cwd, title, updatedAt }`。
|
|
320
|
+
* 数据源 `sessionQuery.listSessions()`(返回带 `header.cwd` 的记录)+ 短 TTL 缓存;
|
|
321
|
+
* **取不到一律回 `null`**(不臆断、不谎报「没有会话」)。
|
|
322
|
+
*/
|
|
323
|
+
async sessionIndex() {
|
|
324
|
+
const built = await buildSessionIndex();
|
|
325
|
+
return built.map;
|
|
326
|
+
},
|
|
327
|
+
/**
|
|
328
|
+
* 列出宿主会话(可按工作区过滤)。用途:任务台「把**本工作区已有会话**绑定为项目主会话」——
|
|
329
|
+
* 当宿主**建会话**能力不可用时(实例未加载宿主 shim → `create()` 抛 scoped context 错),
|
|
330
|
+
* 这是把「从任务台接续回项目主会话」走通的唯一出口。
|
|
331
|
+
*/
|
|
332
|
+
async listSessions({ cwd } = {}) {
|
|
333
|
+
let built = null;
|
|
334
|
+
try { built = await buildSessionIndex(); }
|
|
335
|
+
catch (error) { built = { map: null, source: "error", reason: `index-threw:${error?.message ?? error}` }; }
|
|
336
|
+
if (!built?.map) return { sessions: [], source: built?.source ?? "unavailable", reason: built?.reason ?? "unknown" };
|
|
337
|
+
const all = [...built.map.entries()].map(([sessionId, v]) => ({ sessionId, cwd: v?.cwd ?? null, title: v?.title ?? null, updatedAt: v?.updatedAt ?? null }));
|
|
338
|
+
const sessions = cwd ? all.filter((s) => s.cwd === cwd) : all;
|
|
339
|
+
return { sessions, source: built.source, reason: null };
|
|
340
|
+
},
|
|
341
|
+
/**
|
|
342
|
+
* 会话**工作区归属**(FR-84 补口):给出该会话创建时的 cwd,用于判定「这个接续会话到底是不是本项目的」。
|
|
343
|
+
* 真机背景:`taskboard-workbench` 项目的主会话指针曾被指到**另一个项目工作区**的 6.3 MB 会话上,
|
|
344
|
+
* 于是每张卡「打开执行会话」都会打开一个**别人的、巨大的**会话 → 页面长时间只显示输入框。
|
|
345
|
+
*
|
|
346
|
+
* 数据源:优先 `sessionQuery.listSessions()`(返回带 `header.cwd` 的记录;一次调用 + 短 TTL 缓存),
|
|
347
|
+
* 退化到 `readSession(id).session.cwd`。**取不到一律回 `cwd:null`,不臆断归属**(判不准 ≠ 判定不属于)。
|
|
348
|
+
*/
|
|
349
|
+
async sessionOrigin(sessionId) {
|
|
350
|
+
if (!sessionId) return { sessionId: null, cwd: null, source: "none" };
|
|
351
|
+
const q = getService?.("sessionQuery");
|
|
352
|
+
if (!q) return { sessionId, cwd: null, source: "unavailable" };
|
|
353
|
+
try {
|
|
354
|
+
const index = await sessionIndex();
|
|
355
|
+
if (index?.has(sessionId)) {
|
|
356
|
+
return { sessionId, cwd: index.get(sessionId)?.cwd ?? null, source: "sessionQuery.listSessions" };
|
|
357
|
+
}
|
|
358
|
+
} catch { /* 列不出就退回单会话读取 */ }
|
|
359
|
+
if (typeof q.readSession === "function") {
|
|
360
|
+
try {
|
|
361
|
+
const read = await q.readSession(sessionId);
|
|
362
|
+
return { sessionId, cwd: read?.session?.cwd ?? null, source: "sessionQuery.readSession" };
|
|
363
|
+
} catch (error) {
|
|
364
|
+
if (error?.code === "SESSION_QUERY_SESSION_NOT_FOUND") return { sessionId, cwd: null, exists: false, source: "sessionQuery.readSession" };
|
|
365
|
+
return { sessionId, cwd: null, source: `error:${error?.code ?? error?.message ?? "unknown"}` };
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return { sessionId, cwd: null, source: "unavailable" };
|
|
369
|
+
},
|
|
370
|
+
async openSession(id) {
|
|
371
|
+
const ui = uiWorkspace();
|
|
372
|
+
if (!id) return { opened: false, reason: "no-session" };
|
|
373
|
+
if (typeof ui?.openSession !== "function") return { opened: false, reason: "ui-workspace-unavailable" };
|
|
374
|
+
try {
|
|
375
|
+
await ui.openSession(id);
|
|
376
|
+
return { opened: true };
|
|
377
|
+
} catch (error) {
|
|
378
|
+
return { opened: false, reason: error?.message ?? String(error) };
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
getCurrentSessionId() {
|
|
382
|
+
return null;
|
|
383
|
+
},
|
|
384
|
+
/** 诊断:各宿主服务在**调用时刻**是否已就绪(懒取模式下的真实可见性)。 */
|
|
385
|
+
/**
|
|
386
|
+
* 只读探测(FR-84 补口 · 2026-10-22 续二):判断「宿主建会话」这条路**此刻通不通**,
|
|
387
|
+
* **绝不去真的建会话**(建会话=写用户数据,需用户授权)。
|
|
388
|
+
* 背景:宿主 dsh 的 `agent preset binding` 只接受**带作用域**的 ctx;本插件是软链安装、
|
|
389
|
+
* 仓库零依赖,裸导入 `@deepseek-ai/dsh-scope` 必然失败,故 `loadScopeFactory()` 会按
|
|
390
|
+
* 「裸导入 → 从 dsh 入口 realpath 反查 → 从已解析 dsh 包反查」依次尝试。
|
|
391
|
+
* 该探测就是把这套解析**跑一遍并如实报结果**,供真机排障与前端「先探测再动作」使用。
|
|
392
|
+
*/
|
|
393
|
+
async probeHost() {
|
|
394
|
+
const root = typeof getCtx === "function" ? getCtx() : null;
|
|
395
|
+
const out = {
|
|
396
|
+
requested: { getCtx: typeof getCtx === "function", getService: typeof getService === "function" },
|
|
397
|
+
rootCtx: {
|
|
398
|
+
present: Boolean(root),
|
|
399
|
+
get: typeof root?.get === "function",
|
|
400
|
+
plugin: typeof root?.plugin === "function",
|
|
401
|
+
},
|
|
402
|
+
rootCreate: typeof sessionController()?.create === "function",
|
|
403
|
+
rootPrompt: typeof sessionController()?.prompt === "function",
|
|
404
|
+
// FR-95 命名那一跳要用的方法:此前探针只探 create/prompt ⇒「改名能不能成」从未被真机探过。
|
|
405
|
+
rootRename: typeof sessionController()?.rename === "function",
|
|
406
|
+
scopeFactory: scopeFactoryState,
|
|
407
|
+
scopedCtx: false,
|
|
408
|
+
scopedCreate: false,
|
|
409
|
+
scopedPrompt: false,
|
|
410
|
+
scopedRename: false,
|
|
411
|
+
sameControllerAsRoot: null,
|
|
412
|
+
verdict: "unknown",
|
|
413
|
+
};
|
|
414
|
+
try {
|
|
415
|
+
const createScope = await loadScopeFactory();
|
|
416
|
+
out.scopeFactory = scopeFactoryState;
|
|
417
|
+
if (typeof createScope !== "function") { out.verdict = "scope-factory-unavailable"; return out; }
|
|
418
|
+
const scoped = await scopedCtx("tb-probe");
|
|
419
|
+
out.scopedCtx = Boolean(scoped);
|
|
420
|
+
if (!scoped) { out.verdict = "scoped-ctx-unavailable"; return out; }
|
|
421
|
+
let sc = null;
|
|
422
|
+
try { sc = scoped.get?.("sessionController") ?? null; } catch { sc = null; }
|
|
423
|
+
out.scopedCreate = typeof sc?.create === "function";
|
|
424
|
+
out.scopedPrompt = typeof sc?.prompt === "function";
|
|
425
|
+
out.scopedRename = typeof sc?.rename === "function";
|
|
426
|
+
const rootSc = sessionController();
|
|
427
|
+
out.sameControllerAsRoot = sc && rootSc ? sc === rootSc : null;
|
|
428
|
+
// 命名(FR-95)可用性单独成键:**不改变既有 verdict 语义**(老 verdict 只讲建会话),
|
|
429
|
+
// 免得既有调用方(前端「先探测再动作」)按新语义误判。
|
|
430
|
+
out.rename = {
|
|
431
|
+
root: out.rootRename,
|
|
432
|
+
scoped: out.scopedRename,
|
|
433
|
+
verdict: out.scopedRename || out.rootRename ? "rename-available" : "rename-unavailable",
|
|
434
|
+
};
|
|
435
|
+
out.verdict = out.scopedCreate ? "create-available" : (out.rootCreate ? "create-root-only" : "create-unavailable");
|
|
436
|
+
} catch (error) {
|
|
437
|
+
out.verdict = "probe-threw:" + (error?.message ?? String(error));
|
|
438
|
+
out.rename = {
|
|
439
|
+
root: out.rootRename,
|
|
440
|
+
scoped: out.scopedRename,
|
|
441
|
+
verdict: out.rootRename ? "rename-available" : "rename-unavailable",
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
return out;
|
|
445
|
+
},
|
|
446
|
+
capabilities() {
|
|
447
|
+
const sc = sessionController();
|
|
448
|
+
return {
|
|
449
|
+
sessionController: Boolean(sc),
|
|
450
|
+
prompt: typeof sc?.prompt === "function",
|
|
451
|
+
create: typeof sc?.create === "function",
|
|
452
|
+
agents: Boolean(agents()),
|
|
453
|
+
sessions: Boolean(sessions()),
|
|
454
|
+
uiWorkspace: Boolean(uiWorkspace()),
|
|
455
|
+
sessionQuery: Boolean(getService?.("sessionQuery")),
|
|
456
|
+
scopeFactory: scopeFactoryState,
|
|
457
|
+
};
|
|
458
|
+
},
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export function createPluginRuntime(options = {}) {
|
|
463
|
+
const dataDir = resolveDataDir({ dataDir: options.dataDir, env: options.env ?? process.env });
|
|
464
|
+
const store = openStore({ dataDir });
|
|
465
|
+
const ensured = ensureDefaultProject(store);
|
|
466
|
+
// SSE 事件中心(FR-41/FR-49:状态变化实时回流工作台,无需手动刷新)。
|
|
467
|
+
// 之前插件路径未接事件中心 → `/api/events` 失效、状态不会自动回流;此处补齐。
|
|
468
|
+
const events = options.events ?? createEventHub();
|
|
469
|
+
const handler = createRequestHandler({
|
|
470
|
+
store,
|
|
471
|
+
webDir: options.webDir ?? WEB_DIR,
|
|
472
|
+
basePath: PREFIX,
|
|
473
|
+
aiElaborator: options.aiElaborator,
|
|
474
|
+
events,
|
|
475
|
+
});
|
|
476
|
+
const migration = store.stats().migration;
|
|
477
|
+
return {
|
|
478
|
+
dataDir,
|
|
479
|
+
store,
|
|
480
|
+
handler,
|
|
481
|
+
events,
|
|
482
|
+
ensured,
|
|
483
|
+
migration,
|
|
484
|
+
prefix: PREFIX,
|
|
485
|
+
webDir: options.webDir ?? WEB_DIR,
|
|
486
|
+
close: () => store.close(),
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
export function apply(ctx, config) {
|
|
491
|
+
const llm = typeof ctx?.get === "function" ? ctx.get("llm") : undefined;
|
|
492
|
+
const aiElaborator = createLlmElaborator({
|
|
493
|
+
llm,
|
|
494
|
+
provider: config?.elaborateProvider,
|
|
495
|
+
model: config?.elaborateModel,
|
|
496
|
+
});
|
|
497
|
+
// 宿主数据目录三级:插件 config.dataDir > 宿主 config(服务 / 上下文两种取法)> 环境变量 / TEMP 兜底。
|
|
498
|
+
// ⚠ 不得**裸读** `ctx.config`:本插件 `inject` 只声明 `webServer`,cordis 对未声明属性直接抛
|
|
499
|
+
// 「cannot get property "config" without inject」⇒ 装载期整条 entry 不激活(2026-10-26 用隔离真宿主
|
|
500
|
+
// `--from-default-profile` 复现)。故先走**不触发守卫**的 `ctx.get("config")`,历史写法只保留在 try 里。
|
|
501
|
+
const hostDataDir = (() => {
|
|
502
|
+
try {
|
|
503
|
+
const viaService = ctx?.get?.("config")?.dataDir;
|
|
504
|
+
if (viaService) return viaService;
|
|
505
|
+
} catch {
|
|
506
|
+
/* 服务不可解析 ⇒ 继续走下一级 */
|
|
507
|
+
}
|
|
508
|
+
try {
|
|
509
|
+
return ctx?.config?.dataDir;
|
|
510
|
+
} catch {
|
|
511
|
+
return undefined;
|
|
512
|
+
}
|
|
513
|
+
})();
|
|
514
|
+
const runtime = createPluginRuntime({ dataDir: config?.dataDir ?? hostDataDir, aiElaborator });
|
|
515
|
+
// 挂载宿主会话能力(懒取服务);api 层经 store.hostSessionPort 使用。
|
|
516
|
+
runtime.store.hostSessionPort = createHostSessionPort({ getService: (name) => ctx?.get?.(name), getCtx: () => ctx });
|
|
517
|
+
// 团队引擎端口(默认 P2 指令降级;TEAM_ENGINE=agent-teams 切 P1)。
|
|
518
|
+
const teamEngineMode = config?.teamEngine ?? process.env.TEAM_ENGINE ?? "instruction";
|
|
519
|
+
runtime.store.teamEnginePort = createTeamEnginePort({ getService: (name) => ctx?.get?.(name), mode: teamEngineMode });
|
|
520
|
+
// 宿主会话能力探测(懒取,仅用于日志;真正调用仍在 hostSessionPort 内现取)。
|
|
521
|
+
const probeService = (name) => { try { return Boolean(ctx?.get?.(name)); } catch { return false; } };
|
|
522
|
+
console.log(
|
|
523
|
+
`[taskboard-workbench] host ready: prefix=${PREFIX} dataDir=${runtime.dataDir} projects=${runtime.ensured.projects.length} migration=${JSON.stringify(runtime.migration)} aiElaborate=${Boolean(aiElaborator)} teamEngine=${teamEngineMode} services=${JSON.stringify({ sessionController: probeService("sessionController"), sessions: probeService("sessions"), uiWorkspace: probeService("uiWorkspace"), tools: probeService("tools") })}`,
|
|
524
|
+
);
|
|
525
|
+
|
|
526
|
+
const registered = [];
|
|
527
|
+
let disposed = false;
|
|
528
|
+
let toolDisposer = null;
|
|
529
|
+
const unregisterAll = () => {
|
|
530
|
+
for (const dispose of registered.splice(0)) {
|
|
531
|
+
try {
|
|
532
|
+
dispose?.();
|
|
533
|
+
} catch (_) {}
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
// 懒取宿主服务(对齐 agent-teams:ctx.get('webServer') ?? ctx.get('httpServer') ?? ctx.webServer)。
|
|
537
|
+
const getWebServer = () => ctx?.get?.("webServer") ?? ctx.get?.("httpServer") ?? ctx?.webServer;
|
|
538
|
+
const registerRoutes = (webServer) => {
|
|
539
|
+
if (!webServer || disposed) return;
|
|
540
|
+
unregisterAll(); // 先注销旧注册:避免 HMR/服务替换导致的“重复注册→前缀路由缺失”
|
|
541
|
+
for (const spec of [
|
|
542
|
+
{ kind: "prefix", path: PREFIX, handler: runtime.handler },
|
|
543
|
+
{ kind: "exact", path: PREFIX, handler: runtime.handler },
|
|
544
|
+
]) {
|
|
545
|
+
try {
|
|
546
|
+
registered.push(webServer.register(spec));
|
|
547
|
+
console.log(`[taskboard-workbench] route registered: ${spec.kind} ${spec.path}`);
|
|
548
|
+
} catch (error) {
|
|
549
|
+
console.error(`[taskboard-workbench] route ${spec.kind} ${spec.path} failed: ${error?.message ?? error}`);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
// 反向链路:把 taskboard_* 工具注册给宿主(懒取 tools 服务;动态 import 以便脱离 DSH 时静默跳过)。
|
|
554
|
+
const registerTools = (toolsService) => {
|
|
555
|
+
if (!toolsService || typeof toolsService.register !== "function" || toolDisposer) return;
|
|
556
|
+
import("./src/host/tool-surface.mjs")
|
|
557
|
+
.then((m) => {
|
|
558
|
+
toolDisposer = m.registerTaskboardTools({ tools: toolsService, store: runtime.store, events: runtime.events });
|
|
559
|
+
console.log("[taskboard-workbench] tools registered: taskboard_*");
|
|
560
|
+
})
|
|
561
|
+
.catch((error) => console.error(`[taskboard-workbench] tools register failed: ${error?.message ?? error}`));
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
try {
|
|
565
|
+
ctx.effect(() => {
|
|
566
|
+
disposed = false;
|
|
567
|
+
registerRoutes(getWebServer());
|
|
568
|
+
registerTools(ctx?.get?.("tools") ?? ctx?.tools);
|
|
569
|
+
// FR-82 收口(启动口径):上一进程留下的「进行中」尝试不会有人闭合 —— 启动时一次结清(**不看时长**)。
|
|
570
|
+
try {
|
|
571
|
+
const rec = runtime.store.reconcileOrphanRuns({ boot: true });
|
|
572
|
+
if (rec.ended.length || rec.ghostClaims.length) {
|
|
573
|
+
console.log(`[taskboard-workbench] boot reconcile: 收口孤儿尝试 ${rec.ended.length} 条(${rec.ended.map((r) => `${r.identifier}#${r.attempt}→${r.outcome}`).join(", ")});清幽灵认领 ${rec.ghostClaims.length} 条`);
|
|
574
|
+
}
|
|
575
|
+
} catch (error) {
|
|
576
|
+
console.error(`[taskboard-workbench] boot reconcile failed: ${error?.message ?? error}`);
|
|
577
|
+
}
|
|
578
|
+
// 看板执行循环定时器(FR-70):仅对"已开启循环"的项目按活跃引擎自动派发待执行任务
|
|
579
|
+
const loopTimer = setInterval(() => {
|
|
580
|
+
// FR-77:回收失效认领(认领过期 / 心跳陈旧)——执行侧仍存活则延后,避免重复派发。
|
|
581
|
+
try {
|
|
582
|
+
const reclaimed = runtime.store.reclaimStaleClaims();
|
|
583
|
+
for (const r of reclaimed) {
|
|
584
|
+
console.log(`[taskboard-workbench] reclaim ${r.identifier} → ${r.status}`);
|
|
585
|
+
try { runtime.events?.publish?.("task.updated", { identifier: r.identifier, status: r.status }); } catch (_) { /* ignore */ }
|
|
586
|
+
}
|
|
587
|
+
} catch (error) {
|
|
588
|
+
console.error(`[taskboard-workbench] reclaim error: ${error?.message ?? error}`);
|
|
589
|
+
}
|
|
590
|
+
// FR-82 收口(定时器口径):只收**超过运行时上限**的尝试(尊重该次自己的 max_ms),绝不误杀正在跑的。
|
|
591
|
+
try {
|
|
592
|
+
const rec = runtime.store.reconcileOrphanRuns();
|
|
593
|
+
for (const r of rec.ended) console.log(`[taskboard-workbench] run reconcile ${r.identifier}#${r.attempt} → ${r.outcome}`);
|
|
594
|
+
} catch (error) {
|
|
595
|
+
console.error(`[taskboard-workbench] run reconcile error: ${error?.message ?? error}`);
|
|
596
|
+
}
|
|
597
|
+
for (const project of listLoopProjects(runtime.store)) {
|
|
598
|
+
runExecutionLoop({ store: runtime.store, events: runtime.events, projectId: project.id })
|
|
599
|
+
.then((r) => {
|
|
600
|
+
if (r.dispatched.length) console.log(`[taskboard-workbench] loop ${project.id}: dispatched ${r.dispatched.length} delivered=${r.delivered} (engine=${r.engine})`);
|
|
601
|
+
})
|
|
602
|
+
.catch((error) => console.error(`[taskboard-workbench] loop error: ${error?.message ?? error}`));
|
|
603
|
+
}
|
|
604
|
+
}, 30000);
|
|
605
|
+
loopTimer.unref?.();
|
|
606
|
+
// 服务在插件 apply 之后才出现/被替换时,重新注册(agent-teams 同款做法)。
|
|
607
|
+
const onService = (name) => {
|
|
608
|
+
if (name === "webServer" || name === "httpServer") registerRoutes(getWebServer());
|
|
609
|
+
if (name === "tools") registerTools(ctx?.get?.("tools") ?? ctx?.tools);
|
|
610
|
+
};
|
|
611
|
+
const off = ctx?.on?.("internal/service", onService);
|
|
612
|
+
return () => {
|
|
613
|
+
disposed = true;
|
|
614
|
+
try { clearInterval(loopTimer); } catch (_) {}
|
|
615
|
+
try {
|
|
616
|
+
off?.();
|
|
617
|
+
} catch (_) {}
|
|
618
|
+
unregisterAll();
|
|
619
|
+
try { toolDisposer?.(); } catch (_) {}
|
|
620
|
+
toolDisposer = null;
|
|
621
|
+
runtime.close();
|
|
622
|
+
console.log("[taskboard-workbench] host disposed");
|
|
623
|
+
};
|
|
624
|
+
}, "taskboard-workbench: routes");
|
|
625
|
+
} catch (error) {
|
|
626
|
+
console.error(`[taskboard-workbench] ctx.effect failed: ${error?.message ?? error}`);
|
|
627
|
+
throw error;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
return runtime;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
export const manifestPath = fileURLToPath(new URL("./cordis.patch.yml", import.meta.url));
|