taskboard-workbench 0.3.2 → 0.3.3
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 +43 -0
- package/index.js +73 -7
- package/package.json +1 -1
- package/skills/taskboard-flow/SKILL.md +1 -1
- package/skills/taskboard-flow/references/steps/S5.md +21 -1
- package/src/core/config.mjs +12 -3
- package/src/core/data-dir-hint.mjs +52 -0
- package/src/core/errors.mjs +9 -0
- package/src/core/evidence.mjs +28 -0
- package/src/core/executor.mjs +27 -7
- package/src/core/executors.mjs +279 -0
- package/src/core/instance-lease.mjs +113 -0
- package/src/core/store.mjs +182 -15
- package/src/core/verify.mjs +27 -0
- package/src/mcp/server.mjs +19 -6
- package/src/mcp/tools.mjs +96 -5
- package/src/server/api.mjs +153 -9
- package/web/app.js +468 -23
- package/web/tokens.css +29 -0
package/src/server/api.mjs
CHANGED
|
@@ -17,6 +17,7 @@ import { runExecutionLoop, activeEngine } from "../core/loop.mjs";
|
|
|
17
17
|
import { assertTeamTemplate, assertQualityGates, planTeamMembers } from "../core/team.mjs";
|
|
18
18
|
import { assessTaskRef, projectWatchdog } from "../core/watchdog.mjs";
|
|
19
19
|
import { ticketStage } from "../core/ticket-stage.mjs";
|
|
20
|
+
import { artifactRefKindProblems, EVIDENCE_REF_KINDS } from "../core/evidence.mjs";
|
|
20
21
|
import { isHumanReviewTask, planHumanReview } from "../core/human-review.mjs";
|
|
21
22
|
import { deriveNextStep } from "../core/next-step.mjs";
|
|
22
23
|
/**
|
|
@@ -35,7 +36,7 @@ const HOST_UNAVAILABLE_NEXT = "该实例没有宿主会话通道(独立进程
|
|
|
35
36
|
|
|
36
37
|
import { buildDebugDispatchPrompt } from "../core/debug-dispatch.mjs";
|
|
37
38
|
import { buildSplitAskPrompt } from "../core/split-ask.mjs";
|
|
38
|
-
import { buildReviewEvidence, formatVerifyComment, normalizeVerifyCommand, summarizeVerifyOutput, VERIFY_DEFAULT_COMMAND } from "../core/verify.mjs";
|
|
39
|
+
import { buildReviewEvidence, detectUnrunnableVerify, formatVerifyComment, normalizeVerifyCommand, summarizeVerifyOutput, VERIFY_DEFAULT_COMMAND } from "../core/verify.mjs";
|
|
39
40
|
import { buildGapPrompt, buildKickoffTodos, collectGaps, evaluateKickoff } from "../core/kickoff.mjs";
|
|
40
41
|
import { deriveEmptyState } from "../core/empty-state.mjs";
|
|
41
42
|
// 2026-10-28 拍板 E1–E3 / D-M1–D-M5:项目推进清单(纯投影 + 幂等回写)与项目记忆(L2 条目 + L3 召回)。
|
|
@@ -47,6 +48,9 @@ import { runVerifyCommand, probeVerifyApplicability } from "./verify.mjs";
|
|
|
47
48
|
import { DIAGNOSTIC_KINDS, evaluateTaskDiagnostics, projectDiagnostics, summarizeDiagnostics, resolveSessionRef, humanReviewProbe, humanReviewAnsweredBy } from "../core/diagnostics.mjs";
|
|
48
49
|
import { summarizeNotifyDelivery } from "../core/notify.mjs";
|
|
49
50
|
import { resolveCliExecutor, executeTaskWithCli, buildTaskPrompt, cliArgsFor, claimForCliExecution, DEFAULT_TIMEOUT_MS } from "../core/executor.mjs";
|
|
51
|
+
// 卡 `-238`(R174):执行者注册表 —— 按卡选「团队 / dsh / claude / codex / hermes」的唯一真源。
|
|
52
|
+
// 本文件只用它**解析与校验**,参数与「指令怎么给」都由注册表给,路由不另写第二份。
|
|
53
|
+
import { EXECUTOR_SPECS, EXECUTOR_KINDS, buildExecutorArgs, detectBinary, findExecutorSpec, isExecutorForbidden, listExecutors } from "../core/executors.mjs";
|
|
50
54
|
import { DEFAULT_FAILURE_LIMIT } from "../core/store.mjs";
|
|
51
55
|
// 卡 `-177`(2026-10-29 · 口径 X):acceptance 缺省口径与 MCP **共用同一份**,不在本文件另写判断。
|
|
52
56
|
import { markAcceptance, acceptanceFlag } from "../core/acceptance.mjs";
|
|
@@ -62,7 +66,12 @@ export function httpStatusFor(error) {
|
|
|
62
66
|
return 400;
|
|
63
67
|
}
|
|
64
68
|
|
|
65
|
-
|
|
69
|
+
/**
|
|
70
|
+
* @param executorProbe 执行者探测(默认 `detectBinary`)。**可注入**是为了让「未安装」这条分支
|
|
71
|
+
* 能被测试真实走一遍 —— 否则本机四个 CLI 全装着,`EXECUTOR_NOT_INSTALLED` 永远测不到。
|
|
72
|
+
* 与 `TB_CLI_EXECUTOR_BIN` 同属「测试/宿主替身」这一层,不改变生产默认行为。
|
|
73
|
+
*/
|
|
74
|
+
export function createApiRouter({ store, aiElaborator, events, executorProbe = detectBinary } = {}) {
|
|
66
75
|
const emit = (type, payload) => { try { events?.publish?.(type, payload); } catch { /* ignore */ } };
|
|
67
76
|
/**
|
|
68
77
|
* 已有执行会话仍在执行(未返回结论)→ 不得再次下发。
|
|
@@ -195,6 +204,19 @@ export function createApiRouter({ store, aiElaborator, events } = {}) {
|
|
|
195
204
|
].join("\n");
|
|
196
205
|
}
|
|
197
206
|
async function route({ method, pathname, searchParams, body = {} }) {
|
|
207
|
+
// 卡 `-237`(需求 `R173`):同一个库同一时刻只允许一个写者。
|
|
208
|
+
// follower 一律只读 —— **所有非 GET 直接 409**,不做「部分放行」:
|
|
209
|
+
// 放行一半比全拒更难解释,也更容易踩到对端正跑着的执行。
|
|
210
|
+
// **现读**(fresh)而不是吃本地缓存:缓存最多滞后一个心跳周期,那 15s 就是真实双写窗口。
|
|
211
|
+
if (method !== "GET" && method !== "HEAD" && method !== "OPTIONS"
|
|
212
|
+
&& (typeof store.instanceRoleFresh === "function" ? store.instanceRoleFresh() : "writer") === "follower") {
|
|
213
|
+
const leaseOwner = typeof store.instanceLeaseOwnerFresh === "function" ? store.instanceLeaseOwnerFresh() : null;
|
|
214
|
+
throw new TbError(
|
|
215
|
+
"FOLLOWER_READ_ONLY",
|
|
216
|
+
`本实例是只读跟随者:另一个工作台实例正在写同一个库(${leaseOwner ? `${leaseOwner.host} · pid ${leaseOwner.pid}` : "对端实例"})。请到那个窗口操作,或等它退出后本窗口会自动接管。`,
|
|
217
|
+
{ role: "follower", leaseOwner, dataDir: store.dataDir },
|
|
218
|
+
);
|
|
219
|
+
}
|
|
198
220
|
if (pathname === "/api/health" && method === "GET") {
|
|
199
221
|
// 宿主能力可见性(诊断):投递指令 / 建会话 / 打开会话 各依赖的宿主服务是否已就绪。
|
|
200
222
|
const has = (fn) => { try { return typeof fn === "function"; } catch { return false; } };
|
|
@@ -229,6 +251,49 @@ export function createApiRouter({ store, aiElaborator, events } = {}) {
|
|
|
229
251
|
payload: { statuses: STATUSES, priorities: PRIORITIES, dataDir: store.dataDir, dbPath: store.dbPath },
|
|
230
252
|
};
|
|
231
253
|
}
|
|
254
|
+
if (pathname === "/api/executors" && method === "GET") {
|
|
255
|
+
// 卡 `-238`(R174):把「这张卡能交给谁跑」变成**可读数据**,前端照它渲染图标、按它的 id 派发。
|
|
256
|
+
// 只读:不 spawn 干活(仅 `--version` 探测,失败即 null)、不写库、不碰宿主会话。
|
|
257
|
+
// 项目维度的两处判据必须带 `projectId`:`forbiddenExecutors` 与 `executionTeam` 都是**项目设置**。
|
|
258
|
+
const projectId = searchParams.get("projectId") ?? searchParams.get("project") ?? null;
|
|
259
|
+
const settings = projectId ? store.getProjectSettings(projectId) : null;
|
|
260
|
+
const port = store.hostSessionPort;
|
|
261
|
+
// 与 `/api/health` 同口径(`createSession: Boolean(port?.available)`):宿主会话通道成不成立看它。
|
|
262
|
+
const hostSessionAvailable = Boolean(port && port.available);
|
|
263
|
+
// `executionTeam` 为空 ⇒ 团队派发没有落点。没带 projectId 时**判不准** ⇒ 传 null(按可用处理,不冒充不可用)。
|
|
264
|
+
const teamAvailable = projectId ? Boolean(settings?.teamTemplate?.executionTeam) : null;
|
|
265
|
+
const executors = await listExecutors({
|
|
266
|
+
settings,
|
|
267
|
+
hostSessionAvailable,
|
|
268
|
+
teamAvailable,
|
|
269
|
+
detect: executorProbe,
|
|
270
|
+
// 版本探测**默认关**:真机实测 `hermes --version` 不退出(>10s 才被杀),为它牺牲首屏
|
|
271
|
+
// 不划算(这个字段只用于展示)。要就显式 `?version=1`,那是诊断/人查的动作,不是页面必经之路。
|
|
272
|
+
withVersion: searchParams.get("version") === "1",
|
|
273
|
+
});
|
|
274
|
+
// `defaultId`=「**不换执行者**时这张卡本来会走谁」:优先项目 `roles[].executor`(走既有
|
|
275
|
+
// `resolveCliExecutor` 同一套解析,含 forbidden 过滤),解析不到就退宿主会话。
|
|
276
|
+
// 为什么由服务端给:前端不该知道 `teamTemplate.roles[].executor` 这种配置细节,
|
|
277
|
+
// 否则「默认选中项」会与真实派发口径各说一套。
|
|
278
|
+
const configured = (() => {
|
|
279
|
+
try { return resolveCliExecutor(settings, { role: "engineer" }); } catch { return null; }
|
|
280
|
+
})();
|
|
281
|
+
const configuredId = configured?.id ?? null;
|
|
282
|
+
const defaultId = (configuredId && executors.some((item) => item.id === configuredId && item.usable))
|
|
283
|
+
? configuredId
|
|
284
|
+
: (executors.some((item) => item.id === "host:dsh" && item.usable) ? "host:dsh" : executors.find((item) => item.usable)?.id ?? null);
|
|
285
|
+
return {
|
|
286
|
+
status: 200,
|
|
287
|
+
payload: {
|
|
288
|
+
schemaVersion: 2,
|
|
289
|
+
projectId,
|
|
290
|
+
executors,
|
|
291
|
+
defaultId,
|
|
292
|
+
hostSessionAvailable,
|
|
293
|
+
hostCapabilities: (() => { try { return port?.capabilities?.() ?? null; } catch { return null; } })(),
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
}
|
|
232
297
|
if (pathname === "/api/context" && method === "GET") {
|
|
233
298
|
// 工作区(cwd) → 项目 → 需求文档 的初始绑定;session= 时绑定/校验"主会话与关联"(FR-60/FR-62/FR-63)
|
|
234
299
|
const cwd = searchParams.get("cwd") ?? undefined;
|
|
@@ -898,6 +963,38 @@ export function createApiRouter({ store, aiElaborator, events } = {}) {
|
|
|
898
963
|
}
|
|
899
964
|
|
|
900
965
|
|
|
966
|
+
// ---- FR-106(0-B-b · 卡 -239)· 交付证据写入口(HTTP 侧)----
|
|
967
|
+
// 与 MCP `card_evidence_submit` **同源**:同一个 store 方法、同一道四字段硬门、同一套错误码。
|
|
968
|
+
// 本层只多做一件规则层不做的事:**入口层 kind 白名单**(非 {commit,file} 显式拒,而不是静默丢)。
|
|
969
|
+
const taskEvidenceRoute = /^\/api\/tasks\/([^/]+)\/evidence$/.exec(pathname);
|
|
970
|
+
if (taskEvidenceRoute) {
|
|
971
|
+
if (method !== "POST") throw new TbError("USAGE_ERROR", "交付证据入口仅支持 POST");
|
|
972
|
+
const ref = decodeURIComponent(taskEvidenceRoute[1]);
|
|
973
|
+
const submittedRefs = body.artifact_refs ?? body.artifactRefs;
|
|
974
|
+
const badKinds = artifactRefKindProblems(submittedRefs);
|
|
975
|
+
if (badKinds.length) {
|
|
976
|
+
throw new TbError(
|
|
977
|
+
"INVALID_ARTIFACT_REF",
|
|
978
|
+
`artifact_refs 只接受 ${EVIDENCE_REF_KINDS.join(" / ")}(非法项:第 ${badKinds.map((b) => b.index + 1).join("、")} 项)`,
|
|
979
|
+
{ problems: badKinds },
|
|
980
|
+
);
|
|
981
|
+
}
|
|
982
|
+
const evidence = store.addTaskEvidence(ref, {
|
|
983
|
+
verdict: body.verdict,
|
|
984
|
+
deviation: body.deviation,
|
|
985
|
+
boundary: body.boundary,
|
|
986
|
+
artifacts: body.artifacts,
|
|
987
|
+
artifactRefs: submittedRefs,
|
|
988
|
+
actor: body.actor ?? "agent",
|
|
989
|
+
});
|
|
990
|
+
const task = store.requireTaskRef(ref);
|
|
991
|
+
const stage = ticketStage(task, { evidence, comments: store.listComments(task.id) });
|
|
992
|
+
try {
|
|
993
|
+
store.recordAudit({ actor: String(body.actor ?? "agent"), action: "evidence-submit", target: task.identifier, allowed: true, reason: evidence.deduped ? "deduped" : "created", detail: `http · kind=${evidence.refsState} · hash=${evidence.evidenceHash ?? "null"}` });
|
|
994
|
+
} catch { /* 审计失败不影响业务写入 */ }
|
|
995
|
+
return { status: 201, payload: { evidence, ticketStage: stage } };
|
|
996
|
+
}
|
|
997
|
+
|
|
901
998
|
// ---- 需求文档(FR-34) ----
|
|
902
999
|
if (pathname === "/api/requirements/docs") {
|
|
903
1000
|
if (method === "GET") {
|
|
@@ -1393,13 +1490,44 @@ export function createApiRouter({ store, aiElaborator, events } = {}) {
|
|
|
1393
1490
|
const project = store.getProject(task.projectId);
|
|
1394
1491
|
const settings = store.getProjectSettings(task.projectId);
|
|
1395
1492
|
const role = String(body.role ?? "engineer");
|
|
1396
|
-
|
|
1493
|
+
// 卡 `-238`(R174):**按卡选执行者**(可选)。不传 = 逐字节走原口径(项目 `roles[].executor` 决定),
|
|
1494
|
+
// 传了 = 只对这一张卡生效,且**不绕过任何既有门**(人工校验 / 归因 / 授权 / 评审一个不落,见下)。
|
|
1495
|
+
const requestedExecutor = body.executor ?? searchParams.get("executor") ?? null;
|
|
1496
|
+
let chosenSpec = null;
|
|
1497
|
+
let executor = null;
|
|
1498
|
+
let binPath = null;
|
|
1499
|
+
if (requestedExecutor !== null && String(requestedExecutor).trim() !== "") {
|
|
1500
|
+
chosenSpec = findExecutorSpec(requestedExecutor);
|
|
1501
|
+
const known = EXECUTOR_SPECS.map((spec) => spec.id).join(" / ");
|
|
1502
|
+
if (!chosenSpec) {
|
|
1503
|
+
throw new TbError("EXECUTOR_UNKNOWN", `未知执行者「${String(requestedExecutor)}」:可用 ${known}`, { requested: String(requestedExecutor), known: EXECUTOR_SPECS.map((spec) => spec.id) });
|
|
1504
|
+
}
|
|
1505
|
+
// 三条「选不了」**分开报**:人要据此决定去装 CLI、去改项目设置、还是换入口。
|
|
1506
|
+
if (chosenSpec.kind !== EXECUTOR_KINDS.CLI) {
|
|
1507
|
+
throw new TbError("EXECUTOR_NOT_CLI", `执行者 ${chosenSpec.id}(kind=${chosenSpec.kind})不是 CLI 通道:${chosenSpec.kind === EXECUTOR_KINDS.TEAM ? "团队派发请用 POST /api/teams" : "宿主会话请用 POST /api/tasks/:ref/execute"}`, { executor: chosenSpec.id, kind: chosenSpec.kind });
|
|
1508
|
+
}
|
|
1509
|
+
if (isExecutorForbidden(chosenSpec, settings)) {
|
|
1510
|
+
throw new TbError("EXECUTOR_FORBIDDEN", `执行者 ${chosenSpec.id} 在项目 forbiddenExecutors 中:项目禁用的执行者不得按卡选择(改项目设置后才可选)`, { executor: chosenSpec.id });
|
|
1511
|
+
}
|
|
1512
|
+
const probe = executorProbe(chosenSpec.command);
|
|
1513
|
+
if (!probe.installed) {
|
|
1514
|
+
throw new TbError("EXECUTOR_NOT_INSTALLED", `执行者 ${chosenSpec.id} 未安装:已查 PATH · ~/.npm-global/bin · ~/.local/bin · /opt/homebrew/bin,未找到 ${chosenSpec.command}`, { executor: chosenSpec.id, command: chosenSpec.command, searched: probe.searched });
|
|
1515
|
+
}
|
|
1516
|
+
binPath = probe.binPath;
|
|
1517
|
+
executor = { id: chosenSpec.id, cli: chosenSpec.command, binPath, role };
|
|
1518
|
+
} else {
|
|
1519
|
+
executor = resolveCliExecutor(settings, { role });
|
|
1520
|
+
}
|
|
1397
1521
|
if (!executor) throw new TbError("NO_CLI_EXECUTOR", `项目 ${task.projectId} 没有可用的 CLI 执行器(teamTemplate.roles[].executor 需为 cli:*,且不在 forbiddenExecutors 中)`);
|
|
1398
1522
|
const cwd = project?.workspacePath ?? null;
|
|
1523
|
+
const prompt = buildTaskPrompt(task, { project, requirementId: task.requirementId ?? null, verifyCommand: settings?.teamTemplate?.engineer?.verifyCommand ?? null });
|
|
1524
|
+
// 参数:显式选了执行者 ⇒ 由注册表给(claude 仍复用 `cliArgsFor`,含 engineer.args 覆盖语义);
|
|
1525
|
+
// 否则原样 `cliArgsFor`(老路径的 plan 一字不差)。
|
|
1399
1526
|
const plan = {
|
|
1400
|
-
executor: executor.id, cli: executor.cli, role: executor.role, cwd,
|
|
1401
|
-
args: cliArgsFor({ executorId: executor.id, cwd, settings }),
|
|
1402
|
-
|
|
1527
|
+
executor: executor.id, cli: binPath ?? executor.cli, role: executor.role ?? role, cwd,
|
|
1528
|
+
args: chosenSpec ? (buildExecutorArgs(chosenSpec, { cwd, settings, prompt }) ?? cliArgsFor({ executorId: executor.id, cwd, settings })) : cliArgsFor({ executorId: executor.id, cwd, settings }),
|
|
1529
|
+
promptVia: chosenSpec?.promptVia ?? "stdin",
|
|
1530
|
+
prompt,
|
|
1403
1531
|
};
|
|
1404
1532
|
if (body.dryRun === true || searchParams.get("dryRun") === "1") return { status: 200, payload: { ran: false, dryRun: true, plan } };
|
|
1405
1533
|
const timeoutMs = Number(body.timeoutMs ?? 0) > 0 ? Number(body.timeoutMs) : DEFAULT_TIMEOUT_MS;
|
|
@@ -1418,7 +1546,12 @@ export function createApiRouter({ store, aiElaborator, events } = {}) {
|
|
|
1418
1546
|
// 进入「进行中」**,否则整个执行期看板显示错误的列(2026-10-18 实测 -73 停在「待办池」14 分钟)。
|
|
1419
1547
|
const claim = claimForCliExecution(store, task.identifier, { actor: "cli-executor" });
|
|
1420
1548
|
emit("task.updated", { taskId: task.id, identifier: task.identifier, status: store.requireTaskRef(task.identifier).status });
|
|
1421
|
-
const fire = () => executeTaskWithCli({
|
|
1549
|
+
const fire = () => executeTaskWithCli({
|
|
1550
|
+
store, task, project, settings, role, timeoutMs,
|
|
1551
|
+
resolvedExecutor: executor,
|
|
1552
|
+
argsOverride: chosenSpec ? plan.args : null,
|
|
1553
|
+
promptVia: plan.promptVia,
|
|
1554
|
+
}).catch((error) => ({ ran: false, reason: String(error?.message ?? error) }));
|
|
1422
1555
|
if (body.async === true || searchParams.get("async") === "1") {
|
|
1423
1556
|
fire();
|
|
1424
1557
|
emit("task.updated", { taskId: task.id, identifier: task.identifier, status: task.status });
|
|
@@ -1842,10 +1975,21 @@ export function createApiRouter({ store, aiElaborator, events } = {}) {
|
|
|
1842
1975
|
// 而该工作区是 Java 工程 ⇒ `ENOENT package.json` ⇒ 退出码 254 ⇒ 结论「失败」。
|
|
1843
1976
|
// 这是「命令不适用」,不是「测试失败」:不跑这条注定报错的命令,落一个**第三态**(不适用)+
|
|
1844
1977
|
// 一条明路(去填本卡复核动作)。人配过的命令(`configured` 非空)一律照跑,不替他判断。
|
|
1978
|
+
// 卡 `-249`(R179):**先判「这条命令能不能跑」再跑**。占位符没有替换时(`... <diff文件>`),
|
|
1979
|
+
// shell 会把它解析成重定向 ⇒ 语法错误 ⇒ 退出码 2,结论被写成「失败(退出码 2)」——
|
|
1980
|
+
// 把「配置写成了模板」谎报成「复核没过」。与 FR-94 同构:判「不适用」,不跑。
|
|
1981
|
+
const unrunnable = detectUnrunnableVerify(command);
|
|
1845
1982
|
const probe = configured ? { applicable: true, reason: null } : await probeVerifyApplicability({ command, cwd });
|
|
1846
|
-
const skipReason = probe.applicable ? null : probe.reason;
|
|
1983
|
+
const skipReason = unrunnable ? unrunnable.reason : (probe.applicable ? null : probe.reason);
|
|
1847
1984
|
const result = skipReason
|
|
1848
|
-
? {
|
|
1985
|
+
? {
|
|
1986
|
+
exitCode: null, timedOut: false, durationMs: 0,
|
|
1987
|
+
tail: `未执行:${skipReason}。\n${
|
|
1988
|
+
unrunnable
|
|
1989
|
+
? `请把占位符换成**真实文件路径**后重跑。注意:自动复核的工作目录 = 本项目的 workspacePath(${cwd}),相对路径要相对它写。`
|
|
1990
|
+
: "请在任务「编辑 → 复核动作」(或项目设置 envConfig.verifyCommand)里填本项目的复核命令后重跑,例如 Java 工程填 `mvn -q test`。"
|
|
1991
|
+
}`,
|
|
1992
|
+
}
|
|
1849
1993
|
: await runVerifyCommand({ command, cwd });
|
|
1850
1994
|
// FR-90 强化(真机反馈 2026-10-22:「执行结果只返回一个结果,应该在自动复核证据内自动填入
|
|
1851
1995
|
// 复核总结证据及结论」):除机器头外,再把**总结 / 失败点**一并落成证据,并回传前端供自动填入。
|