taskboard-workbench 0.3.2 → 0.3.4
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 +65 -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/cli-dispatch.mjs +90 -0
- package/src/core/config.mjs +12 -3
- package/src/core/data-dir-hint.mjs +52 -0
- package/src/core/diagnostics.mjs +125 -2
- package/src/core/errors.mjs +9 -0
- package/src/core/evidence.mjs +28 -0
- package/src/core/executor.mjs +34 -10
- 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 +240 -11
- package/web/app.js +521 -32
- 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
|
/**
|
|
@@ -34,8 +35,9 @@ const PACKAGED_DOCS_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.ur
|
|
|
34
35
|
const HOST_UNAVAILABLE_NEXT = "该实例没有宿主会话通道(独立进程,/api/health 的 host.capabilities 为 null):改到 DSH 内的任务工作台操作,或把返回的 prompt 直接粘到会话里手工投递";
|
|
35
36
|
|
|
36
37
|
import { buildDebugDispatchPrompt } from "../core/debug-dispatch.mjs";
|
|
38
|
+
import { buildMainSessionCliPrompt } from "../core/cli-dispatch.mjs";
|
|
37
39
|
import { buildSplitAskPrompt } from "../core/split-ask.mjs";
|
|
38
|
-
import { buildReviewEvidence, formatVerifyComment, normalizeVerifyCommand, summarizeVerifyOutput, VERIFY_DEFAULT_COMMAND } from "../core/verify.mjs";
|
|
40
|
+
import { buildReviewEvidence, detectUnrunnableVerify, formatVerifyComment, normalizeVerifyCommand, summarizeVerifyOutput, VERIFY_DEFAULT_COMMAND } from "../core/verify.mjs";
|
|
39
41
|
import { buildGapPrompt, buildKickoffTodos, collectGaps, evaluateKickoff } from "../core/kickoff.mjs";
|
|
40
42
|
import { deriveEmptyState } from "../core/empty-state.mjs";
|
|
41
43
|
// 2026-10-28 拍板 E1–E3 / D-M1–D-M5:项目推进清单(纯投影 + 幂等回写)与项目记忆(L2 条目 + L3 召回)。
|
|
@@ -47,6 +49,9 @@ import { runVerifyCommand, probeVerifyApplicability } from "./verify.mjs";
|
|
|
47
49
|
import { DIAGNOSTIC_KINDS, evaluateTaskDiagnostics, projectDiagnostics, summarizeDiagnostics, resolveSessionRef, humanReviewProbe, humanReviewAnsweredBy } from "../core/diagnostics.mjs";
|
|
48
50
|
import { summarizeNotifyDelivery } from "../core/notify.mjs";
|
|
49
51
|
import { resolveCliExecutor, executeTaskWithCli, buildTaskPrompt, cliArgsFor, claimForCliExecution, DEFAULT_TIMEOUT_MS } from "../core/executor.mjs";
|
|
52
|
+
// 卡 `-238`(R174):执行者注册表 —— 按卡选「团队 / dsh / claude / codex / hermes」的唯一真源。
|
|
53
|
+
// 本文件只用它**解析与校验**,参数与「指令怎么给」都由注册表给,路由不另写第二份。
|
|
54
|
+
import { EXECUTOR_SPECS, EXECUTOR_KINDS, buildExecutorArgs, detectBinary, findExecutorSpec, isExecutorForbidden, listExecutors } from "../core/executors.mjs";
|
|
50
55
|
import { DEFAULT_FAILURE_LIMIT } from "../core/store.mjs";
|
|
51
56
|
// 卡 `-177`(2026-10-29 · 口径 X):acceptance 缺省口径与 MCP **共用同一份**,不在本文件另写判断。
|
|
52
57
|
import { markAcceptance, acceptanceFlag } from "../core/acceptance.mjs";
|
|
@@ -62,7 +67,12 @@ export function httpStatusFor(error) {
|
|
|
62
67
|
return 400;
|
|
63
68
|
}
|
|
64
69
|
|
|
65
|
-
|
|
70
|
+
/**
|
|
71
|
+
* @param executorProbe 执行者探测(默认 `detectBinary`)。**可注入**是为了让「未安装」这条分支
|
|
72
|
+
* 能被测试真实走一遍 —— 否则本机四个 CLI 全装着,`EXECUTOR_NOT_INSTALLED` 永远测不到。
|
|
73
|
+
* 与 `TB_CLI_EXECUTOR_BIN` 同属「测试/宿主替身」这一层,不改变生产默认行为。
|
|
74
|
+
*/
|
|
75
|
+
export function createApiRouter({ store, aiElaborator, events, executorProbe = detectBinary } = {}) {
|
|
66
76
|
const emit = (type, payload) => { try { events?.publish?.(type, payload); } catch { /* ignore */ } };
|
|
67
77
|
/**
|
|
68
78
|
* 已有执行会话仍在执行(未返回结论)→ 不得再次下发。
|
|
@@ -195,6 +205,19 @@ export function createApiRouter({ store, aiElaborator, events } = {}) {
|
|
|
195
205
|
].join("\n");
|
|
196
206
|
}
|
|
197
207
|
async function route({ method, pathname, searchParams, body = {} }) {
|
|
208
|
+
// 卡 `-237`(需求 `R173`):同一个库同一时刻只允许一个写者。
|
|
209
|
+
// follower 一律只读 —— **所有非 GET 直接 409**,不做「部分放行」:
|
|
210
|
+
// 放行一半比全拒更难解释,也更容易踩到对端正跑着的执行。
|
|
211
|
+
// **现读**(fresh)而不是吃本地缓存:缓存最多滞后一个心跳周期,那 15s 就是真实双写窗口。
|
|
212
|
+
if (method !== "GET" && method !== "HEAD" && method !== "OPTIONS"
|
|
213
|
+
&& (typeof store.instanceRoleFresh === "function" ? store.instanceRoleFresh() : "writer") === "follower") {
|
|
214
|
+
const leaseOwner = typeof store.instanceLeaseOwnerFresh === "function" ? store.instanceLeaseOwnerFresh() : null;
|
|
215
|
+
throw new TbError(
|
|
216
|
+
"FOLLOWER_READ_ONLY",
|
|
217
|
+
`本实例是只读跟随者:另一个工作台实例正在写同一个库(${leaseOwner ? `${leaseOwner.host} · pid ${leaseOwner.pid}` : "对端实例"})。请到那个窗口操作,或等它退出后本窗口会自动接管。`,
|
|
218
|
+
{ role: "follower", leaseOwner, dataDir: store.dataDir },
|
|
219
|
+
);
|
|
220
|
+
}
|
|
198
221
|
if (pathname === "/api/health" && method === "GET") {
|
|
199
222
|
// 宿主能力可见性(诊断):投递指令 / 建会话 / 打开会话 各依赖的宿主服务是否已就绪。
|
|
200
223
|
const has = (fn) => { try { return typeof fn === "function"; } catch { return false; } };
|
|
@@ -229,6 +252,49 @@ export function createApiRouter({ store, aiElaborator, events } = {}) {
|
|
|
229
252
|
payload: { statuses: STATUSES, priorities: PRIORITIES, dataDir: store.dataDir, dbPath: store.dbPath },
|
|
230
253
|
};
|
|
231
254
|
}
|
|
255
|
+
if (pathname === "/api/executors" && method === "GET") {
|
|
256
|
+
// 卡 `-238`(R174):把「这张卡能交给谁跑」变成**可读数据**,前端照它渲染图标、按它的 id 派发。
|
|
257
|
+
// 只读:不 spawn 干活(仅 `--version` 探测,失败即 null)、不写库、不碰宿主会话。
|
|
258
|
+
// 项目维度的两处判据必须带 `projectId`:`forbiddenExecutors` 与 `executionTeam` 都是**项目设置**。
|
|
259
|
+
const projectId = searchParams.get("projectId") ?? searchParams.get("project") ?? null;
|
|
260
|
+
const settings = projectId ? store.getProjectSettings(projectId) : null;
|
|
261
|
+
const port = store.hostSessionPort;
|
|
262
|
+
// 与 `/api/health` 同口径(`createSession: Boolean(port?.available)`):宿主会话通道成不成立看它。
|
|
263
|
+
const hostSessionAvailable = Boolean(port && port.available);
|
|
264
|
+
// `executionTeam` 为空 ⇒ 团队派发没有落点。没带 projectId 时**判不准** ⇒ 传 null(按可用处理,不冒充不可用)。
|
|
265
|
+
const teamAvailable = projectId ? Boolean(settings?.teamTemplate?.executionTeam) : null;
|
|
266
|
+
const executors = await listExecutors({
|
|
267
|
+
settings,
|
|
268
|
+
hostSessionAvailable,
|
|
269
|
+
teamAvailable,
|
|
270
|
+
detect: executorProbe,
|
|
271
|
+
// 版本探测**默认关**:真机实测 `hermes --version` 不退出(>10s 才被杀),为它牺牲首屏
|
|
272
|
+
// 不划算(这个字段只用于展示)。要就显式 `?version=1`,那是诊断/人查的动作,不是页面必经之路。
|
|
273
|
+
withVersion: searchParams.get("version") === "1",
|
|
274
|
+
});
|
|
275
|
+
// `defaultId`=「**不换执行者**时这张卡本来会走谁」:优先项目 `roles[].executor`(走既有
|
|
276
|
+
// `resolveCliExecutor` 同一套解析,含 forbidden 过滤),解析不到就退宿主会话。
|
|
277
|
+
// 为什么由服务端给:前端不该知道 `teamTemplate.roles[].executor` 这种配置细节,
|
|
278
|
+
// 否则「默认选中项」会与真实派发口径各说一套。
|
|
279
|
+
const configured = (() => {
|
|
280
|
+
try { return resolveCliExecutor(settings, { role: "engineer" }); } catch { return null; }
|
|
281
|
+
})();
|
|
282
|
+
const configuredId = configured?.id ?? null;
|
|
283
|
+
const defaultId = (configuredId && executors.some((item) => item.id === configuredId && item.usable))
|
|
284
|
+
? configuredId
|
|
285
|
+
: (executors.some((item) => item.id === "host:dsh" && item.usable) ? "host:dsh" : executors.find((item) => item.usable)?.id ?? null);
|
|
286
|
+
return {
|
|
287
|
+
status: 200,
|
|
288
|
+
payload: {
|
|
289
|
+
schemaVersion: 2,
|
|
290
|
+
projectId,
|
|
291
|
+
executors,
|
|
292
|
+
defaultId,
|
|
293
|
+
hostSessionAvailable,
|
|
294
|
+
hostCapabilities: (() => { try { return port?.capabilities?.() ?? null; } catch { return null; } })(),
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
}
|
|
232
298
|
if (pathname === "/api/context" && method === "GET") {
|
|
233
299
|
// 工作区(cwd) → 项目 → 需求文档 的初始绑定;session= 时绑定/校验"主会话与关联"(FR-60/FR-62/FR-63)
|
|
234
300
|
const cwd = searchParams.get("cwd") ?? undefined;
|
|
@@ -898,6 +964,38 @@ export function createApiRouter({ store, aiElaborator, events } = {}) {
|
|
|
898
964
|
}
|
|
899
965
|
|
|
900
966
|
|
|
967
|
+
// ---- FR-106(0-B-b · 卡 -239)· 交付证据写入口(HTTP 侧)----
|
|
968
|
+
// 与 MCP `card_evidence_submit` **同源**:同一个 store 方法、同一道四字段硬门、同一套错误码。
|
|
969
|
+
// 本层只多做一件规则层不做的事:**入口层 kind 白名单**(非 {commit,file} 显式拒,而不是静默丢)。
|
|
970
|
+
const taskEvidenceRoute = /^\/api\/tasks\/([^/]+)\/evidence$/.exec(pathname);
|
|
971
|
+
if (taskEvidenceRoute) {
|
|
972
|
+
if (method !== "POST") throw new TbError("USAGE_ERROR", "交付证据入口仅支持 POST");
|
|
973
|
+
const ref = decodeURIComponent(taskEvidenceRoute[1]);
|
|
974
|
+
const submittedRefs = body.artifact_refs ?? body.artifactRefs;
|
|
975
|
+
const badKinds = artifactRefKindProblems(submittedRefs);
|
|
976
|
+
if (badKinds.length) {
|
|
977
|
+
throw new TbError(
|
|
978
|
+
"INVALID_ARTIFACT_REF",
|
|
979
|
+
`artifact_refs 只接受 ${EVIDENCE_REF_KINDS.join(" / ")}(非法项:第 ${badKinds.map((b) => b.index + 1).join("、")} 项)`,
|
|
980
|
+
{ problems: badKinds },
|
|
981
|
+
);
|
|
982
|
+
}
|
|
983
|
+
const evidence = store.addTaskEvidence(ref, {
|
|
984
|
+
verdict: body.verdict,
|
|
985
|
+
deviation: body.deviation,
|
|
986
|
+
boundary: body.boundary,
|
|
987
|
+
artifacts: body.artifacts,
|
|
988
|
+
artifactRefs: submittedRefs,
|
|
989
|
+
actor: body.actor ?? "agent",
|
|
990
|
+
});
|
|
991
|
+
const task = store.requireTaskRef(ref);
|
|
992
|
+
const stage = ticketStage(task, { evidence, comments: store.listComments(task.id) });
|
|
993
|
+
try {
|
|
994
|
+
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"}` });
|
|
995
|
+
} catch { /* 审计失败不影响业务写入 */ }
|
|
996
|
+
return { status: 201, payload: { evidence, ticketStage: stage } };
|
|
997
|
+
}
|
|
998
|
+
|
|
901
999
|
// ---- 需求文档(FR-34) ----
|
|
902
1000
|
if (pathname === "/api/requirements/docs") {
|
|
903
1001
|
if (method === "GET") {
|
|
@@ -1393,15 +1491,60 @@ export function createApiRouter({ store, aiElaborator, events } = {}) {
|
|
|
1393
1491
|
const project = store.getProject(task.projectId);
|
|
1394
1492
|
const settings = store.getProjectSettings(task.projectId);
|
|
1395
1493
|
const role = String(body.role ?? "engineer");
|
|
1396
|
-
|
|
1494
|
+
// 卡 `-238`(R174):**按卡选执行者**(可选)。不传 = 逐字节走原口径(项目 `roles[].executor` 决定),
|
|
1495
|
+
// 传了 = 只对这一张卡生效,且**不绕过任何既有门**(人工校验 / 归因 / 授权 / 评审一个不落,见下)。
|
|
1496
|
+
const requestedExecutor = body.executor ?? searchParams.get("executor") ?? null;
|
|
1497
|
+
let chosenSpec = null;
|
|
1498
|
+
let executor = null;
|
|
1499
|
+
let binPath = null;
|
|
1500
|
+
if (requestedExecutor !== null && String(requestedExecutor).trim() !== "") {
|
|
1501
|
+
chosenSpec = findExecutorSpec(requestedExecutor);
|
|
1502
|
+
const known = EXECUTOR_SPECS.map((spec) => spec.id).join(" / ");
|
|
1503
|
+
if (!chosenSpec) {
|
|
1504
|
+
throw new TbError("EXECUTOR_UNKNOWN", `未知执行者「${String(requestedExecutor)}」:可用 ${known}`, { requested: String(requestedExecutor), known: EXECUTOR_SPECS.map((spec) => spec.id) });
|
|
1505
|
+
}
|
|
1506
|
+
// 三条「选不了」**分开报**:人要据此决定去装 CLI、去改项目设置、还是换入口。
|
|
1507
|
+
if (chosenSpec.kind !== EXECUTOR_KINDS.CLI) {
|
|
1508
|
+
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 });
|
|
1509
|
+
}
|
|
1510
|
+
if (isExecutorForbidden(chosenSpec, settings)) {
|
|
1511
|
+
throw new TbError("EXECUTOR_FORBIDDEN", `执行者 ${chosenSpec.id} 在项目 forbiddenExecutors 中:项目禁用的执行者不得按卡选择(改项目设置后才可选)`, { executor: chosenSpec.id });
|
|
1512
|
+
}
|
|
1513
|
+
const probe = executorProbe(chosenSpec.command);
|
|
1514
|
+
if (!probe.installed) {
|
|
1515
|
+
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 });
|
|
1516
|
+
}
|
|
1517
|
+
binPath = probe.binPath;
|
|
1518
|
+
executor = { id: chosenSpec.id, cli: chosenSpec.command, binPath, role };
|
|
1519
|
+
} else {
|
|
1520
|
+
executor = resolveCliExecutor(settings, { role });
|
|
1521
|
+
}
|
|
1397
1522
|
if (!executor) throw new TbError("NO_CLI_EXECUTOR", `项目 ${task.projectId} 没有可用的 CLI 执行器(teamTemplate.roles[].executor 需为 cli:*,且不在 forbiddenExecutors 中)`);
|
|
1398
1523
|
const cwd = project?.workspacePath ?? null;
|
|
1524
|
+
const prompt = buildTaskPrompt(task, { project, requirementId: task.requirementId ?? null, verifyCommand: settings?.teamTemplate?.engineer?.verifyCommand ?? null });
|
|
1525
|
+
// 参数:显式选了执行者 ⇒ 由注册表给(claude 仍复用 `cliArgsFor`,含 engineer.args 覆盖语义);
|
|
1526
|
+
// 否则原样 `cliArgsFor`(老路径的 plan 一字不差)。
|
|
1399
1527
|
const plan = {
|
|
1400
|
-
executor: executor.id, cli: executor.cli, role: executor.role, cwd,
|
|
1401
|
-
args: cliArgsFor({ executorId: executor.id, cwd, settings }),
|
|
1402
|
-
|
|
1528
|
+
executor: executor.id, cli: binPath ?? executor.cli, role: executor.role ?? role, cwd,
|
|
1529
|
+
args: chosenSpec ? (buildExecutorArgs(chosenSpec, { cwd, settings, prompt }) ?? cliArgsFor({ executorId: executor.id, cwd, settings })) : cliArgsFor({ executorId: executor.id, cwd, settings }),
|
|
1530
|
+
promptVia: chosenSpec?.promptVia ?? "stdin",
|
|
1531
|
+
prompt,
|
|
1403
1532
|
};
|
|
1404
|
-
|
|
1533
|
+
// 卡 `-257`:预览也要**如实说清这条命令会怎么下发** —— 人看完预览才知道是「交主会话」还是「服务端直跑」。
|
|
1534
|
+
const wantMain = body.direct !== true && searchParams.get("direct") !== "1";
|
|
1535
|
+
if (body.dryRun === true || searchParams.get("dryRun") === "1") {
|
|
1536
|
+
const dryRef = wantMain ? resolveSessionRef(store, task) : { sessionId: null, source: null };
|
|
1537
|
+
const drySid = dryRef.sessionId ?? null;
|
|
1538
|
+
return { status: 200, payload: {
|
|
1539
|
+
ran: false, dryRun: true, plan,
|
|
1540
|
+
via: wantMain ? "main-session" : "direct",
|
|
1541
|
+
mainSession: wantMain ? {
|
|
1542
|
+
sessionId: drySid, source: dryRef.source ?? null,
|
|
1543
|
+
deliverable: Boolean(drySid) && typeof store.hostSessionPort?.sendPrompt === "function",
|
|
1544
|
+
} : null,
|
|
1545
|
+
promptToMainSession: wantMain && drySid ? buildMainSessionCliPrompt({ task, project, executor, plan }) : null,
|
|
1546
|
+
} };
|
|
1547
|
+
}
|
|
1405
1548
|
const timeoutMs = Number(body.timeoutMs ?? 0) > 0 ? Number(body.timeoutMs) : DEFAULT_TIMEOUT_MS;
|
|
1406
1549
|
// FR-40 归因门(2026-10-22 · CLI 链路验证台 `tools/bench-cli-chain.mjs` 抓到):
|
|
1407
1550
|
// `/exec-cli` 是**第三条真的会干活的执行入口**(另两条=`/execute` 与 `POST /api/teams` 派发),
|
|
@@ -1413,16 +1556,90 @@ export function createApiRouter({ store, aiElaborator, events } = {}) {
|
|
|
1413
1556
|
// 「进行中」),套 `assertExecutable` 会把这条设计挡掉。
|
|
1414
1557
|
// `dryRun` 保持宽松:只回执行计划、无副作用,预览不该被归因门挡住。
|
|
1415
1558
|
store.assertAttributed(task.identifier);
|
|
1559
|
+
// ── 卡 `-257`(需求 `R183`):CLI 执行器**默认经项目主会话下发并跟踪** ────────────────────
|
|
1560
|
+
// 用户拍板的口径:除「DSH 宿主会话」直接执行外,其他非绑定会话的 agent 执行者一律交
|
|
1561
|
+
// **项目主会话**下发并跟踪,卡片的执行反馈也由主会话回写。
|
|
1562
|
+
//
|
|
1563
|
+
// 为什么(真机 `-246` 的硬证):服务端直跑 `claude -p` 时,进程与任何会话都无关 ——
|
|
1564
|
+
// 人点「打开执行会话」只看得到项目主会话、里面一条记录都没有,`task_runs` 也只有
|
|
1565
|
+
// `actor=cli-executor` / `session_id=null`,磁盘上更没有输出。执行过程不可观察。
|
|
1566
|
+
//
|
|
1567
|
+
// 保留 `direct:true`(或 `?direct=1`)=服务端直跑:隔离验证台、无宿主实例、自动化脚本要走这条路,
|
|
1568
|
+
// 但它们**必须显式声明**,不再是被默认落到的静默旁路。
|
|
1569
|
+
//
|
|
1570
|
+
// 门序红线:本分支在 `assertAttributed` **之后** —— 未归因的卡连"投递"都不该发生。
|
|
1571
|
+
let fallbackNote = null; // 回落直跑时的如实标注(null ⇒ 不适用)
|
|
1572
|
+
const viaMain = wantMain; // 同一个判据(dryRun 已在上面早返回,不会走到这里)
|
|
1573
|
+
if (viaMain) {
|
|
1574
|
+
const resolved = resolveSessionRef(store, task);
|
|
1575
|
+
const mainSid = resolved.sessionId ?? null;
|
|
1576
|
+
const mainSource = resolved.source ?? null;
|
|
1577
|
+
const port = store.hostSessionPort;
|
|
1578
|
+
const canDispatch = Boolean(mainSid) && Boolean(port) && typeof port.sendPrompt === "function";
|
|
1579
|
+
if (canDispatch) {
|
|
1580
|
+
const cliPrompt = buildMainSessionCliPrompt({ task, project, executor, plan });
|
|
1581
|
+
let sent = null;
|
|
1582
|
+
let reason = null;
|
|
1583
|
+
try { sent = await port.sendPrompt(mainSid, cliPrompt); }
|
|
1584
|
+
catch (error) { reason = error?.code ?? String(error?.message ?? error); }
|
|
1585
|
+
const delivered = Boolean(sent?.sent ?? sent?.delivered ?? false);
|
|
1586
|
+
if (!delivered) {
|
|
1587
|
+
// **投递失败不回落直跑**:回落会让"记录在哪里"悄悄变掉,正是本轮要消除的不可观察性。
|
|
1588
|
+
// 如实回 200 + delivered:false + 原因,由人决定(重试 / 重建主会话 / 显式直跑)。
|
|
1589
|
+
const why = reason ?? sent?.reason ?? "not-delivered";
|
|
1590
|
+
try { store.recordAudit({ actor: "board", action: "exec-cli-via-main", target: task.identifier, allowed: false, reason: why, detail: `session=${mainSid} source=${mainSource ?? "null"} executor=${executor.id}` }); } catch { /* ignore */ }
|
|
1591
|
+
return { status: 200, payload: {
|
|
1592
|
+
ran: false, via: "main-session", delivered: false,
|
|
1593
|
+
sessionId: mainSid, source: mainSource, executor: executor.id, reason: why,
|
|
1594
|
+
nextAction: "先「打开执行会话」确认主会话可用 / 重建并绑定项目主会话后重试;确需服务端直跑请显式传 direct:true",
|
|
1595
|
+
prompt: cliPrompt,
|
|
1596
|
+
} };
|
|
1597
|
+
}
|
|
1598
|
+
// ① 绑定会话:任务级引用 → 项目主会话(「打开执行会话」自此直达记录所在的那条会话)
|
|
1599
|
+
const bound = store.rebindTaskSession(task.identifier, mainSid);
|
|
1600
|
+
// ② 认领 + 进「进行中」+ 开尝试记录(会话标识一并落库,尝试记录也能反查到会话)
|
|
1601
|
+
const claim = claimForCliExecution(store, task.identifier, { actor: "cli-executor", sessionId: mainSid });
|
|
1602
|
+
const after = store.requireTaskRef(task.identifier);
|
|
1603
|
+
store.addComment(task.identifier, { body: [
|
|
1604
|
+
`已交项目主会话下发执行(CLI 执行器 ${executor.id})`,
|
|
1605
|
+
`- 会话:${mainSid}(来源 ${mainSource ?? "未知"})—— 执行记录就在这条会话里,点「打开执行会话」直达`,
|
|
1606
|
+
`- 工作目录:${plan.cwd ?? "(未设置)"}`,
|
|
1607
|
+
`- 命令:${plan.cli ?? ""} ${(plan.args ?? []).join(" ")}`.trim(),
|
|
1608
|
+
`- 回写要求:主会话跑完写四节证据 → 提交「待验收」(或写失败原因);完成仍由人确认`,
|
|
1609
|
+
].join("\n") });
|
|
1610
|
+
try { store.recordAudit({ actor: "board", action: "exec-cli-via-main", target: task.identifier, allowed: true, reason: sent?.reason ?? "delivered", detail: `session=${mainSid} source=${mainSource ?? "null"} executor=${executor.id} sessionBound=${bound.changed}` }); } catch { /* ignore */ }
|
|
1611
|
+
emit("task.updated", { taskId: after.id, identifier: after.identifier, status: after.status });
|
|
1612
|
+
return { status: 202, payload: {
|
|
1613
|
+
ran: true, async: true, via: "main-session", delivered: true,
|
|
1614
|
+
sessionId: mainSid, source: mainSource, executor: executor.id,
|
|
1615
|
+
plan, prompt: cliPrompt, claim, status: after.status,
|
|
1616
|
+
} };
|
|
1617
|
+
}
|
|
1618
|
+
// 无主会话 / 无宿主通道 ⇒ 回落直跑,但**必须在卡片上留痕**:
|
|
1619
|
+
// 「这次执行不在任何会话里」是可观察性事实,不能只存在于这一次的 HTTP 响应里。
|
|
1620
|
+
const fallbackReason = mainSid ? "host-unavailable" : "no-main-session";
|
|
1621
|
+
fallbackNote = { via: "direct", delivered: false, fallbackReason, mainSession: { sessionId: mainSid, source: mainSource } };
|
|
1622
|
+
store.addComment(task.identifier, { body: `⚠ 未走项目主会话:${fallbackReason === "no-main-session" ? "任务与项目都没有可用会话引用" : "当前实例没有宿主会话通道"} ⇒ 本次由服务端**直跑** CLI。\n- 执行记录**不在任何会话里**(进程独立,退出后只剩本卡评论与尝试记录)\n- 要让它可观察:先「重建并绑定项目主会话」,再重新下发` });
|
|
1623
|
+
try { store.recordAudit({ actor: "board", action: "exec-cli-via-main", target: task.identifier, allowed: true, reason: `fallback-direct:${fallbackReason}`, detail: `session=${mainSid ?? "null"} executor=${executor.id}` }); } catch { /* ignore */ }
|
|
1624
|
+
} else {
|
|
1625
|
+
// 显式 `direct:true` ⇒ 回包里也写明通道,否则「这次到底是哪条路」只能靠调用方记着自己传了什么。
|
|
1626
|
+
fallbackNote = { via: "direct", delivered: false, explicitDirect: true };
|
|
1627
|
+
}
|
|
1416
1628
|
// 真实落盘:先认领并转「进行中」——否则看板只看到 todo / 原状态,且与执行循环之间没有互斥。
|
|
1417
1629
|
// 口径见 `claimForCliExecution`:todo 走授权门;其它状态(人工显式点击即授权)也**必须如实
|
|
1418
1630
|
// 进入「进行中」**,否则整个执行期看板显示错误的列(2026-10-18 实测 -73 停在「待办池」14 分钟)。
|
|
1419
1631
|
const claim = claimForCliExecution(store, task.identifier, { actor: "cli-executor" });
|
|
1420
1632
|
emit("task.updated", { taskId: task.id, identifier: task.identifier, status: store.requireTaskRef(task.identifier).status });
|
|
1421
|
-
const fire = () => executeTaskWithCli({
|
|
1633
|
+
const fire = () => executeTaskWithCli({
|
|
1634
|
+
store, task, project, settings, role, timeoutMs,
|
|
1635
|
+
resolvedExecutor: executor,
|
|
1636
|
+
argsOverride: chosenSpec ? plan.args : null,
|
|
1637
|
+
promptVia: plan.promptVia,
|
|
1638
|
+
}).catch((error) => ({ ran: false, reason: String(error?.message ?? error) }));
|
|
1422
1639
|
if (body.async === true || searchParams.get("async") === "1") {
|
|
1423
1640
|
fire();
|
|
1424
1641
|
emit("task.updated", { taskId: task.id, identifier: task.identifier, status: task.status });
|
|
1425
|
-
return { status: 202, payload: { ran: true, async: true, executor: executor.id, plan, claim } };
|
|
1642
|
+
return { status: 202, payload: { ran: true, async: true, executor: executor.id, plan, claim, ...(fallbackNote ?? {}) } };
|
|
1426
1643
|
}
|
|
1427
1644
|
const r = await fire();
|
|
1428
1645
|
emit("task.updated", { taskId: task.id, identifier: task.identifier, status: store.requireTaskRef(task.identifier).status });
|
|
@@ -1434,6 +1651,7 @@ export function createApiRouter({ store, aiElaborator, events } = {}) {
|
|
|
1434
1651
|
durationMs: r.result?.durationMs ?? 0, cwd: r.result?.cwd ?? null, files: r.result?.diff?.files ?? [],
|
|
1435
1652
|
stdout: r.result?.stdout ?? "", stderr: r.result?.stderr ?? "", comment: r.comment ?? null,
|
|
1436
1653
|
claim,
|
|
1654
|
+
...(fallbackNote ?? {}),
|
|
1437
1655
|
status: store.requireTaskRef(task.identifier).status,
|
|
1438
1656
|
},
|
|
1439
1657
|
};
|
|
@@ -1842,10 +2060,21 @@ export function createApiRouter({ store, aiElaborator, events } = {}) {
|
|
|
1842
2060
|
// 而该工作区是 Java 工程 ⇒ `ENOENT package.json` ⇒ 退出码 254 ⇒ 结论「失败」。
|
|
1843
2061
|
// 这是「命令不适用」,不是「测试失败」:不跑这条注定报错的命令,落一个**第三态**(不适用)+
|
|
1844
2062
|
// 一条明路(去填本卡复核动作)。人配过的命令(`configured` 非空)一律照跑,不替他判断。
|
|
2063
|
+
// 卡 `-249`(R179):**先判「这条命令能不能跑」再跑**。占位符没有替换时(`... <diff文件>`),
|
|
2064
|
+
// shell 会把它解析成重定向 ⇒ 语法错误 ⇒ 退出码 2,结论被写成「失败(退出码 2)」——
|
|
2065
|
+
// 把「配置写成了模板」谎报成「复核没过」。与 FR-94 同构:判「不适用」,不跑。
|
|
2066
|
+
const unrunnable = detectUnrunnableVerify(command);
|
|
1845
2067
|
const probe = configured ? { applicable: true, reason: null } : await probeVerifyApplicability({ command, cwd });
|
|
1846
|
-
const skipReason = probe.applicable ? null : probe.reason;
|
|
2068
|
+
const skipReason = unrunnable ? unrunnable.reason : (probe.applicable ? null : probe.reason);
|
|
1847
2069
|
const result = skipReason
|
|
1848
|
-
? {
|
|
2070
|
+
? {
|
|
2071
|
+
exitCode: null, timedOut: false, durationMs: 0,
|
|
2072
|
+
tail: `未执行:${skipReason}。\n${
|
|
2073
|
+
unrunnable
|
|
2074
|
+
? `请把占位符换成**真实文件路径**后重跑。注意:自动复核的工作目录 = 本项目的 workspacePath(${cwd}),相对路径要相对它写。`
|
|
2075
|
+
: "请在任务「编辑 → 复核动作」(或项目设置 envConfig.verifyCommand)里填本项目的复核命令后重跑,例如 Java 工程填 `mvn -q test`。"
|
|
2076
|
+
}`,
|
|
2077
|
+
}
|
|
1849
2078
|
: await runVerifyCommand({ command, cwd });
|
|
1850
2079
|
// FR-90 强化(真机反馈 2026-10-22:「执行结果只返回一个结果,应该在自动复核证据内自动填入
|
|
1851
2080
|
// 复核总结证据及结论」):除机器头外,再把**总结 / 失败点**一并落成证据,并回传前端供自动填入。
|