taskboard-workbench 0.3.3 → 0.3.5

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.
@@ -12,6 +12,7 @@ import { EXIT, TbError, invalidField } from "../core/errors.mjs";
12
12
  import { resolveContext } from "../core/binding.mjs";
13
13
  import { scanProjectMaterials, buildMaterialIndex, collectExternalFiles } from "../core/intake.mjs";
14
14
  import { scanAgentTeams, OFFICIAL_TEAM } from "../core/agent-teams.mjs";
15
+ import { BRIDGE_MODE, BRIDGE_POLICY, BRIDGE_POLICY_TITLE, buildCardTaskMap, mapCardToTeamTasks, readPluginTeams, slimPluginTeam } from "../core/team-bridge.mjs";
15
16
  import { buildTeamDirective } from "../host/team-engine.mjs";
16
17
  import { runExecutionLoop, activeEngine } from "../core/loop.mjs";
17
18
  import { assertTeamTemplate, assertQualityGates, planTeamMembers } from "../core/team.mjs";
@@ -35,6 +36,7 @@ const PACKAGED_DOCS_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.ur
35
36
  const HOST_UNAVAILABLE_NEXT = "该实例没有宿主会话通道(独立进程,/api/health 的 host.capabilities 为 null):改到 DSH 内的任务工作台操作,或把返回的 prompt 直接粘到会话里手工投递";
36
37
 
37
38
  import { buildDebugDispatchPrompt } from "../core/debug-dispatch.mjs";
39
+ import { buildMainSessionCliPrompt } from "../core/cli-dispatch.mjs";
38
40
  import { buildSplitAskPrompt } from "../core/split-ask.mjs";
39
41
  import { buildReviewEvidence, detectUnrunnableVerify, formatVerifyComment, normalizeVerifyCommand, summarizeVerifyOutput, VERIFY_DEFAULT_COMMAND } from "../core/verify.mjs";
40
42
  import { buildGapPrompt, buildKickoffTodos, collectGaps, evaluateKickoff } from "../core/kickoff.mjs";
@@ -43,6 +45,8 @@ import { deriveEmptyState } from "../core/empty-state.mjs";
43
45
  import { buildAdvance, renderAdvanceBlock, applyDecision } from "../core/advance.mjs";
44
46
  import { renderMemoryBlock } from "../core/memory.mjs";
45
47
  import { taskSessionTitle, projectMainSessionTitle } from "../core/session-naming.mjs";
48
+ // 卡 `-264`(R188):派发目标解析 —— 「优先复用已绑定空闲会话,无则新建 + 首次授权」,纯逻辑 + 注入探活。
49
+ import { pickDispatchTarget, buildReuseDirective, buildAuthorizationDirective } from "../core/dispatch-target.mjs";
46
50
  import { collectKickoffFacts, hasEngineerExecutor, hasReviewerRole } from "./kickoff.mjs";
47
51
  import { runVerifyCommand, probeVerifyApplicability } from "./verify.mjs";
48
52
  import { DIAGNOSTIC_KINDS, evaluateTaskDiagnostics, projectDiagnostics, summarizeDiagnostics, resolveSessionRef, humanReviewProbe, humanReviewAnsweredBy } from "../core/diagnostics.mjs";
@@ -51,7 +55,7 @@ import { resolveCliExecutor, executeTaskWithCli, buildTaskPrompt, cliArgsFor, cl
51
55
  // 卡 `-238`(R174):执行者注册表 —— 按卡选「团队 / dsh / claude / codex / hermes」的唯一真源。
52
56
  // 本文件只用它**解析与校验**,参数与「指令怎么给」都由注册表给,路由不另写第二份。
53
57
  import { EXECUTOR_SPECS, EXECUTOR_KINDS, buildExecutorArgs, detectBinary, findExecutorSpec, isExecutorForbidden, listExecutors } from "../core/executors.mjs";
54
- import { DEFAULT_FAILURE_LIMIT } from "../core/store.mjs";
58
+ import { DEFAULT_FAILURE_LIMIT, displayRunSummary } from "../core/store.mjs";
55
59
  // 卡 `-177`(2026-10-29 · 口径 X):acceptance 缺省口径与 MCP **共用同一份**,不在本文件另写判断。
56
60
  import { markAcceptance, acceptanceFlag } from "../core/acceptance.mjs";
57
61
  // P5 档 C(卡 `-210`):开局注入的唯一实现(内容仍由 `buildFlowBlock()` 生成,本文件不复制正文)。
@@ -59,6 +63,41 @@ import { FLOW_INJECT_MANUAL, FLOW_INJECT_ROLES, injectFlow, normalizeFlowInjectP
59
63
 
60
64
  export const API_SCHEMA_VERSION = 2;
61
65
 
66
+ /**
67
+ * 修复动作后**重算诊断**(卡 `-248` · 需求 `R178` ⑤ ·「修复后自动 resolve」)。
68
+ *
69
+ * 诊断是「只增不减」的:规则只在**被评估**时才会重算,而评估只发生在读路径上
70
+ * (`GET /execution` / `GET /diagnostics`)。于是修复动作(重派 / 回收认领 / 请求评审 /
71
+ * 重置失败计数 / 改绑负责人)已经把成因消掉了,却没人重算 ⇒ 那条诊断一直挂着(`count` 还在涨),
72
+ * 人看到的是「我明明修好了,它还在喊」。
73
+ *
74
+ * 这里在**动作落库后立刻重算一次** ⇒ 成因已消的诊断当场消解(FR-79 的「问题消失即自动消解」)。
75
+ * 只重算**这一张卡**,不扫项目;写入走的是 `evaluateTaskDiagnostics`(诊断的唯一写入口)。
76
+ */
77
+ function refreshDiagnosticsAfterFix(store, ref) {
78
+ try { return evaluateTaskDiagnostics(store, ref); } catch { return null; }
79
+ }
80
+
81
+ /**
82
+ * 卡 `-268`(需求 `R184`)· **尝试记录的展示口径**:`summary` 字段不再露记账文案。
83
+ *
84
+ * 写路径(`-259`)只管得住**新行**;库里躺着 **22 行**老口径的「按成功完成记账(失败计数清零)」
85
+ * 与 **7 行**空摘要(真机读数 2026-11-13)⇒ 只修写路径,老卡打开仍是记账文案 —— 正是验收
86
+ * 第 2 条要禁的那句。
87
+ *
88
+ * 这里在**读路径**统一兜一次(`displayRunSummary` 是唯一判据,与 `normalizeRunSummary` 同源):
89
+ * · `summary` = **给人看的**(空 / 纯记账文案 ⇒ 「执行方未回写摘要」;执行方真写了 ⇒ 原样)
90
+ * · `summaryRaw` = **库里原文**(一字不改 —— 改历史 = 篡改过程证据)
91
+ * 在途尝试(`status="running"`)的 `summary` 恒为 null ⇒ **不套回落文案**:把「还在跑」说成
92
+ * 「没回写」是另一种撒谎。
93
+ */
94
+ function withDisplaySummary(run) {
95
+ if (!run) return null;
96
+ const raw = run.summary ?? null;
97
+ const summary = run.status === "running" ? raw : displayRunSummary(raw);
98
+ return { ...run, summary, summaryRaw: raw };
99
+ }
100
+
62
101
  export function httpStatusFor(error) {
63
102
  if (error.code === "STORE_UNAVAILABLE") return 503;
64
103
  if (error.code === "NOT_FOUND" || error.code.endsWith("_NOT_FOUND")) return 404;
@@ -313,12 +352,18 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
313
352
  }
314
353
  let sessionBound = null;
315
354
  let association = null;
355
+ // 卡 `-263`(需求 `R187`):绑定的**来源**与派生依据要说得出 —— 否则「执行会话」在配置页只显示一个
356
+ // 英文 role,用户无法判断它是「批准过的」还是「按任务归属派生的」,更无法知道它什么时候会消失。
357
+ let roleDerived = false;
358
+ let executorTasks = [];
316
359
  if (ctx.project && session) {
317
360
  // 首个进入该项目的会话成为"主会话"(首次绑定不改写)
318
361
  if (!ctx.project.initialSessionId) ctx = { ...ctx, project: store.bindInitialSession(ctx.project.id, session) };
319
362
  const binding = store.sessionBinding(ctx.project.id, session);
320
363
  sessionBound = binding.bound;
321
364
  association = binding.role;
365
+ roleDerived = binding.derived === true;
366
+ executorTasks = Array.isArray(binding.tasks) ? binding.tasks : [];
322
367
  }
323
368
  const mainSessionId = ctx.project ? (store.requireProject(ctx.project.id).initialSessionId ?? null) : null;
324
369
  // FR-84 补口(2026-10-23)· **实例工作区预检**:一个 DSH 实例只有一个工作区(宿主不给切换服务,
@@ -326,7 +371,7 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
326
371
  // 这里把「本会话落哪个工作区」如实交出来(只读探测),前端据此提前告知,不再让用户走
327
372
  // 「重建 → 还是说工作区不对」的弯路。
328
373
  const sessionOrigin = session ? await sessionOriginOf(session, ctx.project ?? null) : null;
329
- return { status: 200, payload: { cwd: cwd ?? null, session: session ?? null, project: ctx.project, requirementDoc: ctx.requirementDoc, sessionBound, mainSessionId, association, sessionOrigin } };
374
+ return { status: 200, payload: { cwd: cwd ?? null, session: session ?? null, project: ctx.project, requirementDoc: ctx.requirementDoc, sessionBound, mainSessionId, association, roleDerived, executorTasks, sessionOrigin } };
330
375
  }
331
376
  if (pathname === "/api/projects") {
332
377
  if (method === "GET") {
@@ -625,6 +670,38 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
625
670
  const thirdParty = await scanAgentTeams(project.workspacePath, { mainSessionId: project.initialSessionId ?? null });
626
671
  return { status: 200, payload: { mainSessionId: project.initialSessionId ?? null, teams: [OFFICIAL_TEAM, ...thirdParty], count: 1 + thirdParty.length } };
627
672
  }
673
+ // 团队任务 ↔ 看板卡映射(卡 `-247` · 需求 `R178` ④):**只读同步器**。
674
+ // 插件侧 `.agent-teams/<team>/team.json` 的任务只有自己的 t-id、没有卡号字段 ⇒ 映射由
675
+ // 「项目自有卡号在团队任务文本里全词命中」推导,附命中字段与片段。
676
+ // **不写 team_tasks、不改 .agent-teams/**(写进去会踩 `team_tasks_active_lock` 把看板卡锁死)。
677
+ const projectTeamBridgeRoute = /^\/api\/projects\/([^/]+)\/team-bridge$/.exec(pathname);
678
+ if (projectTeamBridgeRoute) {
679
+ if (method !== "GET") throw new TbError("USAGE_ERROR", "team-bridge 仅支持 GET(只读同步器)");
680
+ const project = store.requireProject(decodeURIComponent(projectTeamBridgeRoute[1]));
681
+ const teams = await readPluginTeams(project.workspacePath ?? null);
682
+ const cards = store.listTasks({ projectId: project.id }).map((task) => ({
683
+ id: task.id,
684
+ identifier: task.identifier,
685
+ title: task.title,
686
+ status: task.status,
687
+ }));
688
+ const { rows, unmapped, stats } = buildCardTaskMap({ cards, teams });
689
+ return {
690
+ status: 200,
691
+ payload: {
692
+ mode: BRIDGE_MODE,
693
+ policy: BRIDGE_POLICY,
694
+ policyTitle: BRIDGE_POLICY_TITLE,
695
+ projectId: project.id,
696
+ workspacePath: project.workspacePath ?? null,
697
+ mainSessionId: project.initialSessionId ?? null,
698
+ teams: teams.map(slimPluginTeam),
699
+ mappings: rows,
700
+ unmapped,
701
+ stats,
702
+ },
703
+ };
704
+ }
628
705
  const projectSessionsRoute = /^\/api\/projects\/([^/]+)\/sessions$/.exec(pathname);
629
706
  if (projectSessionsRoute) {
630
707
  const project = store.requireProject(decodeURIComponent(projectSessionsRoute[1]));
@@ -635,7 +712,40 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
635
712
  for (const row of rows) sessions.push({ ...row, liveness: await sessionStateOf(row.sessionId) });
636
713
  const mainSessionId = project.initialSessionId ?? null;
637
714
  const main = mainSessionId ? { sessionId: mainSessionId, role: "main", liveness: await sessionStateOf(mainSessionId) } : null;
638
- return { status: 200, payload: { sessions, main, staleMain: Boolean(main && main.liveness.exists === false) } };
715
+ // 卡 `-263`(需求 `R187`)· **执行会话**:按 `tasks.session_id` 聚合的「正在干本项目卡」的会话。
716
+ // 这是**只读派生**行(与上面 `sessions` 的批准记录不同源),所以:
717
+ // · 已经在主会话/批准列表里的,不再重复列(同一会话一行,避免「一处两条」);
718
+ // · 不给「解除」入口 —— 它的生命周期由任务状态决定(done/canceled 自动收回);
719
+ // · 明写 `derived:true`,前端据此标注来源,不要让人误以为是「批准过」。
720
+ const covered = new Set([mainSessionId, ...rows.map((r) => r.sessionId)].filter(Boolean));
721
+ const executors = [];
722
+ for (const ex of store.listExecutorSessions(project.id)) {
723
+ if (covered.has(ex.sessionId)) continue;
724
+ executors.push({ ...ex, derived: true, liveness: await sessionStateOf(ex.sessionId) });
725
+ }
726
+ return { status: 200, payload: { sessions, main, executors, staleMain: Boolean(main && main.liveness.exists === false) } };
727
+ }
728
+ // 卡 `-264`(需求 `R188`)· **派发目标预览**(只读,不建会话、不投递)。
729
+ // 用途:抽屉「下一步」区在点「启动执行」之前就告诉人「这条会交给谁」——
730
+ // reuse ⇒ 复用它(已绑定本项目的空闲会话)
731
+ // create-and-authorize ⇒ 没有可用绑定会话,点了会新建一条并**首次授权**
732
+ // 判据与 `/execute` 共用 `pickDispatchTarget`(**不写第二份**,避免「预览说 A、执行做 B」)。
733
+ const projectDispatchTargetRoute = /^\/api\/projects\/([^/]+)\/dispatch-target$/.exec(pathname);
734
+ if (projectDispatchTargetRoute) {
735
+ if (method !== "GET") throw new TbError("USAGE_ERROR", "dispatch-target 仅支持 GET");
736
+ const project = store.requireProject(decodeURIComponent(projectDispatchTargetRoute[1]));
737
+ const port = store.hostSessionPort;
738
+ if (!port?.available) {
739
+ return {
740
+ status: 200,
741
+ payload: {
742
+ projectId: project.id, decision: "degraded", target: null, candidates: [],
743
+ reason: "host-session-unavailable", hostAvailable: false,
744
+ },
745
+ };
746
+ }
747
+ const picked = await pickDispatchTarget(store, project.id, { sessionStateOf, sessionOriginOf });
748
+ return { status: 200, payload: { projectId: project.id, ...picked, hostAvailable: true } };
639
749
  }
640
750
  // FR-84 补口(2026-10-22)· **本工作区已有会话**候选列表。
641
751
  // 用途:宿主**建会话**能力不可用时(实例未加载宿主 shim → `create()` 抛
@@ -926,8 +1036,23 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
926
1036
  };
927
1037
  });
928
1038
  } catch { diagnostics = []; }
1039
+ // 卡 `-258`(需求 `R184`)· 抽屉「执行记录」聚合段的**唯一数据源**。
1040
+ // 真机(2026-11-12 · 卡 `-248`):结构化四节证据 `task_evidence` 早已写进库(verdict/deviation/
1041
+ // boundary/artifacts 齐全),但它在服务端**只被 `evaluateTaskDiagnostics` 读去判「有没有产物」**,
1042
+ // 从来没有回传给前端 —— 于是人打开一张「待验收」的卡,看不到任何执行记录,只能去翻评论。
1043
+ // 这里把「最近一次结构化证据 + 最近一次尝试」只读回传;**零写副作用**(本端点的不变量)。
1044
+ // 读不到就如实给 null / 0,不臆造(前端据此渲染显式空态)。
1045
+ let executionRun = currentRun;
1046
+ let runsCount = 0;
1047
+ try {
1048
+ const allRuns = typeof store.listTaskRuns === "function" ? store.listTaskRuns(task.identifier) : [];
1049
+ runsCount = Array.isArray(allRuns) ? allRuns.length : 0;
1050
+ if (!executionRun && runsCount > 0) executionRun = allRuns[runsCount - 1];
1051
+ } catch { /* 读失败按「无尝试」处理,不伪造 */ }
1052
+ // 卡 `-268`(需求 `R184`):摘要按**展示口径**回传(不再露记账文案),原文另存 `summaryRaw`。
1053
+ const executionRecord = { evidence, run: withDisplaySummary(executionRun), runsCount };
929
1054
  const stage = ticketStage(task, { evidence, decision: null, comments, sessionState, currentRun, diagnostics });
930
- return { status: 200, payload: { task, comments, reviewEvidence: buildReviewEvidence({ comments }), ticketStage: stage } };
1055
+ return { status: 200, payload: { task, comments, reviewEvidence: buildReviewEvidence({ comments }), ticketStage: stage, executionRecord } };
931
1056
  }
932
1057
  if (method === "PATCH") {
933
1058
  const task = store.updateTask(ref, {
@@ -951,6 +1076,7 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
951
1076
  // 漏带/带字符串一律按"没批准"处理(store 侧严格 `=== true`)⇒ 拖拽/脚本的静默收口必然被拒。
952
1077
  skipReview: body.skipReview,
953
1078
  });
1079
+ refreshDiagnosticsAfterFix(store, task.identifier); // 卡 `-248`:改绑负责人 / 改状态后重算
954
1080
  return { status: 200, payload: { task } };
955
1081
  }
956
1082
  if (method === "DELETE") {
@@ -1293,10 +1419,43 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
1293
1419
  // 于是被归因门 / 授权门 / 人工校验门拒绝的点击**照样留下副作用**(多一个空会话 + 视图被切走)。
1294
1420
  // 门序列的唯一来源仍是 store.assertExecutable(startTaskExecution 会再复检一次)。
1295
1421
  store.assertExecutable(ref);
1296
- // 宿主路径:可用则建会话(+尝试预置)并打开;不可用则降级(保留 directive 兜底)。
1422
+ // 卡 `-264`(需求 `R188`):**先解析派发目标**,再决定「复用已绑定空闲会话」还是「新建 + 首次授权」。
1423
+ // 旧行为是「没给 sessionId 就一律新建」—— 每张卡一条孤立会话,项目里空闲的主会话/已批准会话完全没被利用。
1424
+ let dispatch = null; // { decision, target, reason, candidates }
1425
+ let authorization = null; // 新建路径的授权留痕(回包给人看,也方便审计对齐)
1426
+ // 卡 `-272`(需求 `R188` 验收③):**新建路径的任务书是否真的送达**(preset 可能被宿主静默吞掉)。
1427
+ // null(不适用:复用路径 / 降级)· { delivered, via, reason } —— 界面的「已下发」必须以它为准。
1428
+ let bookDelivery = null;
1297
1429
  if (!sessionId && port?.available) {
1298
1430
  try {
1299
- const preset = `任务 ${execTask.identifier}:${execTask.title}\n操作指引:认领 → 执行 → 提交"待验收";不得置"完成"(人工确认)。`;
1431
+ dispatch = await pickDispatchTarget(store, execTask.projectId, { sessionStateOf, sessionOriginOf });
1432
+ } catch (error) {
1433
+ // 解析失败不阻断:如实记一句,走「新建 + 授权」这条保底路(至少不会派给一个不知道状态的会话)。
1434
+ dispatch = { decision: "create-and-authorize", target: null, candidates: [], reason: `resolve-error:${error?.code ?? error?.message ?? error}` };
1435
+ }
1436
+ }
1437
+ // ① 复用路径:只在**判得出空闲**时才走(判不准/跨工作区/在跑 都不选)。
1438
+ if (!sessionId && dispatch?.target?.sessionId) {
1439
+ const target = dispatch.target;
1440
+ let sent = null;
1441
+ let sendReason = null;
1442
+ try { sent = await port.sendPrompt(target.sessionId, buildReuseDirective({ task: execTask, project: store.getProject(execTask.projectId), target })); }
1443
+ catch (error) { sendReason = error?.code ?? String(error?.message ?? error); }
1444
+ if (Boolean(sent?.sent ?? sent?.delivered ?? false)) {
1445
+ sessionId = target.sessionId;
1446
+ reason = null;
1447
+ // 与新建路径同一 UX:把执行会话切到前台(用户刚点了「启动执行」,本来就该看到它在跑)。
1448
+ try { await port.openSession(sessionId); } catch { /* 打开失败不影响派发 */ }
1449
+ } else {
1450
+ // 投递失败 ⇒ **回落新建**(不谎报「已派给空闲会话」),原因如实带回去。
1451
+ reason = `reuse-send-failed:${sendReason ?? sent?.reason ?? "not-delivered"}`;
1452
+ }
1453
+ }
1454
+ // ② 新建路径(没有可用候选 / 复用投递失败):建会话 → **当场授权**(首次授权)→ 任务书带授权段。
1455
+ if (!sessionId && port?.available) {
1456
+ try {
1457
+ const project = store.getProject(execTask.projectId);
1458
+ const preset = buildAuthorizationDirective({ task: execTask, project });
1300
1459
  // 2026-10-23 用户命名约束(口径 1):任务会话统一「【任务】+ 任务标题 + 时间」。
1301
1460
  // 同时补 `cwd`(本仓旧缺漏):不传 cwd 时宿主把会话落在**进程目录**(真机取证到 `cwd="/"`),
1302
1461
  // 正是「接续会话跨工作区错乱」的一个来源。
@@ -1304,6 +1463,8 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
1304
1463
  sessionName = taskSessionTitle(execTask.title);
1305
1464
  const created = await port.createSession({
1306
1465
  preset,
1466
+ // 保持与 FR-95-15 守卫同一形状(`cwd: store.getProject(...)?.workspacePath ?? undefined`):
1467
+ // 这是「建会话必须带上项目工作区」的**行内可核对**证据,不要为了少一次读库把它改成变量。
1307
1468
  cwd: store.getProject(execTask.projectId)?.workspacePath ?? undefined,
1308
1469
  title: sessionName,
1309
1470
  // P5 档 C(卡 `-210`):执行会话 ⇒ 只吃「摘要版」(`main-only` 下**不注入**)。
@@ -1315,6 +1476,53 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
1315
1476
  presetApplied = Boolean(created.presetApplied);
1316
1477
  titleApplied = created.titleApplied ?? null;
1317
1478
  titleReason = created.titleReason ?? null;
1479
+ // 卡 `-272`(需求 `R188` 验收③)· **任务书必须真的送到**,不能「建了会话就算下发完成」。
1480
+ //
1481
+ // 实测缺口(旧口径必现):宿主 `createSession({preset})` 在 scope 解析不到时(`index.js`
1482
+ // `loadScopeFactory()` 失败 ⇒ preset binding 被拒)**会静静吞掉 preset**,只回
1483
+ // `presetApplied:false` —— 会话建出来了、授权行也写了、回包还是 `create-and-authorize`,
1484
+ // 而**授权指令与任务书一个字都没投进那条会话**,前端照样报「无需再申请关联」。
1485
+ // 这正是 `R188` ③「投递给该会话的任务书里含【授权】/ 不得再申请 / 回写四节」没有兑现。
1486
+ //
1487
+ // 处置:preset 未送达 ⇒ **用 sendPrompt 补投一次同一份任务书**(不是重复投递:preset
1488
+ // 那条路本来就失败了);补投仍失败 ⇒ **如实记账**(审计 + 卡上评论 = 人看得见的地方),
1489
+ // 回包 `launch.authorization.delivered=false` + 原因,界面据此不得谎称「已下发」。
1490
+ let bookDelivered = Boolean(created.presetApplied);
1491
+ let bookVia = bookDelivered ? "preset" : null;
1492
+ let bookReason = bookDelivered ? null : "preset-not-applied";
1493
+ if (!bookDelivered && typeof port.sendPrompt === "function") {
1494
+ let resent = null;
1495
+ try { resent = await port.sendPrompt(sessionId, preset); }
1496
+ catch (error) { bookReason = error?.code ?? String(error?.message ?? error); }
1497
+ if (Boolean(resent?.sent ?? resent?.delivered ?? false)) {
1498
+ bookDelivered = true;
1499
+ bookVia = "send-prompt-fallback";
1500
+ bookReason = null;
1501
+ } else if (resent) {
1502
+ bookReason = resent?.reason ?? bookReason ?? "not-delivered";
1503
+ }
1504
+ }
1505
+ bookDelivery = { delivered: bookDelivered, via: bookVia, reason: bookReason };
1506
+ if (!bookDelivered) {
1507
+ // 两条路(preset / 直投)都失败 ⇒ 人必须能看见「这张卡派下去了,但会话没收到任务书」。
1508
+ try { store.recordAudit({ actor: "board", action: "authorize-exec-deliver", target: execTask.identifier, allowed: false, reason: String(bookReason ?? "not-delivered"), detail: JSON.stringify({ sessionId, projectId: execTask.projectId, via: bookVia }) }); } catch { /* ignore */ }
1509
+ try { store.addComment(execTask.id, { body: `⚠ 执行会话已建并授权,但**任务书未送达**(${bookReason ?? "原因未知"})—— 这条会话不知道自己要做什么。\n- 会话:${sessionId}\n- 已尝试:createSession 的 preset(未生效)+ sendPrompt 补投(未送达)\n- 处置:点「打开执行会话」把本卡任务书手工贴过去,或解决宿主 preset 投递能力(dsh-scope 未解析)后重派` }); } catch { /* ignore */ }
1510
+ }
1511
+ // **新建即授权**:人点「启动执行」就是授权本身(需求 `R188` 的「或」分支)。
1512
+ // 不写这一行,就会退回 `-263` 之前的孤立会话:`project_sessions` 无行,只能靠派生兜底。
1513
+ const auth = store.approveSessionAssociation(execTask.projectId, sessionId);
1514
+ authorization = {
1515
+ mode: "execute-click", projectId: execTask.projectId, sessionId, status: auth.status,
1516
+ // 卡 `-272`:授权「已生效」与「任务书已送达」是两件事 —— 前者写库必然成功,后者靠宿主。
1517
+ // 回包把两者分开给,界面才不会拿「授权成功」冒充「任务书已送达」。
1518
+ delivered: bookDelivery?.delivered ?? null,
1519
+ deliveryVia: bookDelivery?.via ?? null,
1520
+ deliveryReason: bookDelivery?.reason ?? null,
1521
+ };
1522
+ try {
1523
+ store.recordAudit({ actor: "board", action: "authorize-exec-session", target: execTask.identifier, allowed: true, reason: "execute-click", detail: JSON.stringify({ sessionId, projectId: execTask.projectId, pickReason: dispatch?.reason ?? null }) });
1524
+ } catch { /* ignore */ }
1525
+ try { store.recordTaskEvent(execTask.id, { type: "session_authorized", actor: "board", detail: `新建执行会话 ${sessionId} 并首次授权绑定项目 ${execTask.projectId}(execute-click)` }); } catch { /* ignore */ }
1318
1526
  await port.openSession(sessionId);
1319
1527
  } else {
1320
1528
  reason = "session-create-failed";
@@ -1327,10 +1535,23 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
1327
1535
  }
1328
1536
  const result = store.startTaskExecution(ref, { sessionId });
1329
1537
  result.launch.presetApplied = presetApplied;
1538
+ // 卡 `-272`(需求 `R188` 验收③):`presetApplied` 是**宿主自述**(preset 有没有生效),
1539
+ // `bookDelivery` 是**任务书到底有没有送达**(preset 被吞 ⇒ 走 `sendPrompt` 补投,补投也失败 ⇒ false)。
1540
+ // 两者分开给:界面判定「已下发」只能看后者,不能拿前者冒充。
1541
+ result.launch.bookDelivery = bookDelivery;
1330
1542
  result.launch.titleApplied = titleApplied;
1331
1543
  if (titleApplied === false) result.launch.titleReason = titleReason;
1332
1544
  result.launch.sessionName = sessionName;
1545
+ // 卡 `-264`:派发决策要可判读 —— 「复用了谁 / 为什么没复用 / 是不是刚授权的」都能从回包读出来。
1546
+ result.launch.mode = sessionId ? (dispatch?.target?.sessionId === sessionId ? "reuse-bound" : (authorization ? "create-and-authorize" : "session")) : "degraded";
1547
+ // 需求 `R188` 验收①点名的字段:`reusedFrom` 说明「这次复用的是哪一类绑定会话」
1548
+ // (`main` 主会话 / `approved` 已批准关联 / `executor` 派生执行会话)。
1549
+ // 非复用路径一律给 `null`(**键恒在**):调用方不必区分「没这个字段」与「不是复用」。
1550
+ result.launch.reusedFrom = result.launch.mode === "reuse-bound" ? (dispatch?.target?.kind ?? null) : null;
1551
+ result.launch.dispatch = dispatch ? { decision: dispatch.decision, reason: dispatch.reason, target: dispatch.target, candidates: dispatch.candidates } : null;
1552
+ if (authorization) result.launch.authorization = authorization;
1333
1553
  if (!sessionId) result.launch.reason = reason ?? "host-session-unavailable";
1554
+ else if (reason) result.launch.fallbackReason = reason;
1334
1555
  emit("task.updated", { taskId: result.task.id, identifier: result.task.identifier, status: result.task.status });
1335
1556
  return { status: 200, payload: result };
1336
1557
  }
@@ -1361,7 +1582,14 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
1361
1582
  ? { sessionId: mainId, liveness: await sessionStateOf(mainId), origin: await sessionOriginOf(mainId, proj) }
1362
1583
  : null;
1363
1584
  }
1364
- return { status: 200, payload: { ...store.getTaskExecution(ref), claim: store.taskClaimState(ref), watchdog: assessTaskRef(store, ref), diagnostics: diag.diagnostics, diagnosticSummary: diag.summary, runs: store.listTaskRuns(ref), sessionRef } };
1585
+ // 卡 `-264`(需求 `R188`)· **派发目标预览**:抽屉点「启动执行」前先告诉人「会交给谁」。
1586
+ // 只在「还能派」的状态下算(in_review/done/canceled 不派发),且每候选要探活 ⇒ 不做无用功。
1587
+ let dispatchTarget = null;
1588
+ if (["todo", "blocked", "in_progress"].includes(diag.task.status) && store.hostSessionPort?.available) {
1589
+ try { dispatchTarget = await pickDispatchTarget(store, diag.task.projectId, { sessionStateOf, sessionOriginOf }); }
1590
+ catch (error) { dispatchTarget = { decision: "create-and-authorize", target: null, candidates: [], reason: `resolve-error:${error?.code ?? error?.message ?? error}` }; }
1591
+ }
1592
+ return { status: 200, payload: { ...store.getTaskExecution(ref), claim: store.taskClaimState(ref), watchdog: assessTaskRef(store, ref), diagnostics: diag.diagnostics, diagnosticSummary: diag.summary, runs: store.listTaskRuns(ref).map(withDisplaySummary), sessionRef, dispatchTarget } };
1365
1593
  }
1366
1594
  // FR-82:尝试记录(每次认领执行一条:状态/结果/摘要/错误/起止/心跳/运行时上限)
1367
1595
  const taskRunsRoute = /^\/api\/tasks\/([^/]+)\/runs$/.exec(pathname);
@@ -1369,7 +1597,7 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
1369
1597
  if (method !== "GET") throw new TbError("USAGE_ERROR", "runs 仅支持 GET");
1370
1598
  const task = store.requireTaskRef(decodeURIComponent(taskRunsRoute[1]));
1371
1599
  const runs = store.listTaskRuns(task);
1372
- return { status: 200, payload: { identifier: task.identifier, count: runs.length, currentRun: store.getCurrentRun(task), runs } };
1600
+ return { status: 200, payload: { identifier: task.identifier, count: runs.length, currentRun: withDisplaySummary(store.getCurrentRun(task)), runs: runs.map(withDisplaySummary) } };
1373
1601
  }
1374
1602
  // FR-82:任务事件流(追加式;`since` = 已见游标,返回增量)
1375
1603
  const taskEventsRoute = /^\/api\/tasks\/([^/]+)\/events$/.exec(pathname);
@@ -1432,6 +1660,7 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
1432
1660
  if (taskResetFailuresRoute) {
1433
1661
  if (method !== "POST") throw new TbError("USAGE_ERROR", "reset-failures 仅支持 POST");
1434
1662
  const task = store.resetTaskFailures(decodeURIComponent(taskResetFailuresRoute[1]));
1663
+ refreshDiagnosticsAfterFix(store, task.identifier); // 卡 `-248`:重置失败计数后重算(`repeated_failure` 消解)
1435
1664
  emit("task.updated", { taskId: task.id, identifier: task.identifier, status: task.status });
1436
1665
  return { status: 200, payload: { task, guard: store.dispatchGuard(task) } };
1437
1666
  }
@@ -1450,6 +1679,7 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
1450
1679
  const ref = decodeURIComponent(taskReclaimRoute[1]);
1451
1680
  const r = store.reclaimStaleClaim(ref);
1452
1681
  if (r.reclaimed) {
1682
+ refreshDiagnosticsAfterFix(store, ref); // 卡 `-248`:回收认领后重算(`unclaimed` 消解)
1453
1683
  const t = store.getTaskById(store.requireTaskRef(ref).id);
1454
1684
  emit("task.updated", { taskId: t.id, identifier: t.identifier, status: t.status });
1455
1685
  }
@@ -1529,7 +1759,21 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
1529
1759
  promptVia: chosenSpec?.promptVia ?? "stdin",
1530
1760
  prompt,
1531
1761
  };
1532
- if (body.dryRun === true || searchParams.get("dryRun") === "1") return { status: 200, payload: { ran: false, dryRun: true, plan } };
1762
+ // 卡 `-257`:预览也要**如实说清这条命令会怎么下发** —— 人看完预览才知道是「交主会话」还是「服务端直跑」。
1763
+ const wantMain = body.direct !== true && searchParams.get("direct") !== "1";
1764
+ if (body.dryRun === true || searchParams.get("dryRun") === "1") {
1765
+ const dryRef = wantMain ? resolveSessionRef(store, task) : { sessionId: null, source: null };
1766
+ const drySid = dryRef.sessionId ?? null;
1767
+ return { status: 200, payload: {
1768
+ ran: false, dryRun: true, plan,
1769
+ via: wantMain ? "main-session" : "direct",
1770
+ mainSession: wantMain ? {
1771
+ sessionId: drySid, source: dryRef.source ?? null,
1772
+ deliverable: Boolean(drySid) && typeof store.hostSessionPort?.sendPrompt === "function",
1773
+ } : null,
1774
+ promptToMainSession: wantMain && drySid ? buildMainSessionCliPrompt({ task, project, executor, plan }) : null,
1775
+ } };
1776
+ }
1533
1777
  const timeoutMs = Number(body.timeoutMs ?? 0) > 0 ? Number(body.timeoutMs) : DEFAULT_TIMEOUT_MS;
1534
1778
  // FR-40 归因门(2026-10-22 · CLI 链路验证台 `tools/bench-cli-chain.mjs` 抓到):
1535
1779
  // `/exec-cli` 是**第三条真的会干活的执行入口**(另两条=`/execute` 与 `POST /api/teams` 派发),
@@ -1541,6 +1785,75 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
1541
1785
  // 「进行中」),套 `assertExecutable` 会把这条设计挡掉。
1542
1786
  // `dryRun` 保持宽松:只回执行计划、无副作用,预览不该被归因门挡住。
1543
1787
  store.assertAttributed(task.identifier);
1788
+ // ── 卡 `-257`(需求 `R183`):CLI 执行器**默认经项目主会话下发并跟踪** ────────────────────
1789
+ // 用户拍板的口径:除「DSH 宿主会话」直接执行外,其他非绑定会话的 agent 执行者一律交
1790
+ // **项目主会话**下发并跟踪,卡片的执行反馈也由主会话回写。
1791
+ //
1792
+ // 为什么(真机 `-246` 的硬证):服务端直跑 `claude -p` 时,进程与任何会话都无关 ——
1793
+ // 人点「打开执行会话」只看得到项目主会话、里面一条记录都没有,`task_runs` 也只有
1794
+ // `actor=cli-executor` / `session_id=null`,磁盘上更没有输出。执行过程不可观察。
1795
+ //
1796
+ // 保留 `direct:true`(或 `?direct=1`)=服务端直跑:隔离验证台、无宿主实例、自动化脚本要走这条路,
1797
+ // 但它们**必须显式声明**,不再是被默认落到的静默旁路。
1798
+ //
1799
+ // 门序红线:本分支在 `assertAttributed` **之后** —— 未归因的卡连"投递"都不该发生。
1800
+ let fallbackNote = null; // 回落直跑时的如实标注(null ⇒ 不适用)
1801
+ const viaMain = wantMain; // 同一个判据(dryRun 已在上面早返回,不会走到这里)
1802
+ if (viaMain) {
1803
+ const resolved = resolveSessionRef(store, task);
1804
+ const mainSid = resolved.sessionId ?? null;
1805
+ const mainSource = resolved.source ?? null;
1806
+ const port = store.hostSessionPort;
1807
+ const canDispatch = Boolean(mainSid) && Boolean(port) && typeof port.sendPrompt === "function";
1808
+ if (canDispatch) {
1809
+ const cliPrompt = buildMainSessionCliPrompt({ task, project, executor, plan });
1810
+ let sent = null;
1811
+ let reason = null;
1812
+ try { sent = await port.sendPrompt(mainSid, cliPrompt); }
1813
+ catch (error) { reason = error?.code ?? String(error?.message ?? error); }
1814
+ const delivered = Boolean(sent?.sent ?? sent?.delivered ?? false);
1815
+ if (!delivered) {
1816
+ // **投递失败不回落直跑**:回落会让"记录在哪里"悄悄变掉,正是本轮要消除的不可观察性。
1817
+ // 如实回 200 + delivered:false + 原因,由人决定(重试 / 重建主会话 / 显式直跑)。
1818
+ const why = reason ?? sent?.reason ?? "not-delivered";
1819
+ 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 */ }
1820
+ return { status: 200, payload: {
1821
+ ran: false, via: "main-session", delivered: false,
1822
+ sessionId: mainSid, source: mainSource, executor: executor.id, reason: why,
1823
+ nextAction: "先「打开执行会话」确认主会话可用 / 重建并绑定项目主会话后重试;确需服务端直跑请显式传 direct:true",
1824
+ prompt: cliPrompt,
1825
+ } };
1826
+ }
1827
+ // ① 绑定会话:任务级引用 → 项目主会话(「打开执行会话」自此直达记录所在的那条会话)
1828
+ const bound = store.rebindTaskSession(task.identifier, mainSid);
1829
+ // ② 认领 + 进「进行中」+ 开尝试记录(会话标识一并落库,尝试记录也能反查到会话)
1830
+ const claim = claimForCliExecution(store, task.identifier, { actor: "cli-executor", sessionId: mainSid });
1831
+ const after = store.requireTaskRef(task.identifier);
1832
+ store.addComment(task.identifier, { body: [
1833
+ `已交项目主会话下发执行(CLI 执行器 ${executor.id})`,
1834
+ `- 会话:${mainSid}(来源 ${mainSource ?? "未知"})—— 执行记录就在这条会话里,点「打开执行会话」直达`,
1835
+ `- 工作目录:${plan.cwd ?? "(未设置)"}`,
1836
+ `- 命令:${plan.cli ?? ""} ${(plan.args ?? []).join(" ")}`.trim(),
1837
+ `- 回写要求:主会话跑完写四节证据 → 提交「待验收」(或写失败原因);完成仍由人确认`,
1838
+ ].join("\n") });
1839
+ 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 */ }
1840
+ emit("task.updated", { taskId: after.id, identifier: after.identifier, status: after.status });
1841
+ return { status: 202, payload: {
1842
+ ran: true, async: true, via: "main-session", delivered: true,
1843
+ sessionId: mainSid, source: mainSource, executor: executor.id,
1844
+ plan, prompt: cliPrompt, claim, status: after.status,
1845
+ } };
1846
+ }
1847
+ // 无主会话 / 无宿主通道 ⇒ 回落直跑,但**必须在卡片上留痕**:
1848
+ // 「这次执行不在任何会话里」是可观察性事实,不能只存在于这一次的 HTTP 响应里。
1849
+ const fallbackReason = mainSid ? "host-unavailable" : "no-main-session";
1850
+ fallbackNote = { via: "direct", delivered: false, fallbackReason, mainSession: { sessionId: mainSid, source: mainSource } };
1851
+ store.addComment(task.identifier, { body: `⚠ 未走项目主会话:${fallbackReason === "no-main-session" ? "任务与项目都没有可用会话引用" : "当前实例没有宿主会话通道"} ⇒ 本次由服务端**直跑** CLI。\n- 执行记录**不在任何会话里**(进程独立,退出后只剩本卡评论与尝试记录)\n- 要让它可观察:先「重建并绑定项目主会话」,再重新下发` });
1852
+ 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 */ }
1853
+ } else {
1854
+ // 显式 `direct:true` ⇒ 回包里也写明通道,否则「这次到底是哪条路」只能靠调用方记着自己传了什么。
1855
+ fallbackNote = { via: "direct", delivered: false, explicitDirect: true };
1856
+ }
1544
1857
  // 真实落盘:先认领并转「进行中」——否则看板只看到 todo / 原状态,且与执行循环之间没有互斥。
1545
1858
  // 口径见 `claimForCliExecution`:todo 走授权门;其它状态(人工显式点击即授权)也**必须如实
1546
1859
  // 进入「进行中」**,否则整个执行期看板显示错误的列(2026-10-18 实测 -73 停在「待办池」14 分钟)。
@@ -1555,7 +1868,7 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
1555
1868
  if (body.async === true || searchParams.get("async") === "1") {
1556
1869
  fire();
1557
1870
  emit("task.updated", { taskId: task.id, identifier: task.identifier, status: task.status });
1558
- return { status: 202, payload: { ran: true, async: true, executor: executor.id, plan, claim } };
1871
+ return { status: 202, payload: { ran: true, async: true, executor: executor.id, plan, claim, ...(fallbackNote ?? {}) } };
1559
1872
  }
1560
1873
  const r = await fire();
1561
1874
  emit("task.updated", { taskId: task.id, identifier: task.identifier, status: store.requireTaskRef(task.identifier).status });
@@ -1567,6 +1880,7 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
1567
1880
  durationMs: r.result?.durationMs ?? 0, cwd: r.result?.cwd ?? null, files: r.result?.diff?.files ?? [],
1568
1881
  stdout: r.result?.stdout ?? "", stderr: r.result?.stderr ?? "", comment: r.comment ?? null,
1569
1882
  claim,
1883
+ ...(fallbackNote ?? {}),
1570
1884
  status: store.requireTaskRef(task.identifier).status,
1571
1885
  },
1572
1886
  };
@@ -1701,11 +2015,31 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
1701
2015
  const directive = buildTeamDirective({ teamId: run.id, targetTask: task.identifier, targetRequirement: task.requirementId, members: members.map((m) => m.role), tasks: [{ task: task.identifier, subject: task.title }], qualityGates }, engine);
1702
2016
  return { run, members, tasks, directive };
1703
2017
  }).filter((e) => e.members.length > 0 || e.tasks.length > 0); // 跳过空 run,避免详情显示"空团队"掩盖真实反馈
2018
+ // 卡 `-247`(需求 `R178` ④):**团队侧反查** —— 这张卡在承载环境 agent-team 插件那边是哪个 t-id。
2019
+ // 只读同步:读工作区 `.agent-teams/<team>/team.json`,不写 team_tasks、不改插件产物。
2020
+ // 命中不到 ⇒ 如实给「看板只展示、不参与团队状态」的明文声明(不臆断"没有团队在跑")。
2021
+ let bridge = null;
2022
+ try {
2023
+ const project = store.requireProject(task.projectId);
2024
+ const pluginTeams = await readPluginTeams(project.workspacePath ?? null);
2025
+ const bridgeRows = mapCardToTeamTasks(task.identifier, pluginTeams);
2026
+ bridge = {
2027
+ mode: BRIDGE_MODE,
2028
+ policy: BRIDGE_POLICY,
2029
+ policyTitle: BRIDGE_POLICY_TITLE,
2030
+ workspacePath: project.workspacePath ?? null,
2031
+ pluginTeamCount: pluginTeams.length,
2032
+ mapped: bridgeRows.length > 0,
2033
+ rows: bridgeRows,
2034
+ };
2035
+ } catch {
2036
+ bridge = { mode: BRIDGE_MODE, policy: BRIDGE_POLICY, policyTitle: BRIDGE_POLICY_TITLE, workspacePath: null, pluginTeamCount: 0, mapped: false, rows: [] };
2037
+ }
1704
2038
  return {
1705
2039
  status: 200,
1706
2040
  payload: {
1707
2041
  task: { id: task.id, identifier: task.identifier, title: task.title, status: task.status, sessionId: task.sessionId ?? null },
1708
- engine, teams, count: teams.length, lock: store.getTaskLock(ref),
2042
+ engine, teams, count: teams.length, lock: store.getTaskLock(ref), bridge,
1709
2043
  },
1710
2044
  };
1711
2045
  }
@@ -1715,9 +2049,10 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
1715
2049
  const ref = decodeURIComponent(taskExecActionRoute[1]);
1716
2050
  const action = taskExecActionRoute[2];
1717
2051
  const task = action === "fail" ? store.recordTaskExecutionFailure(ref, { evidence: body.evidence, kind: body.kind })
1718
- : action === "review" ? store.submitTaskForReview(ref, { comment: body.comment })
2052
+ : action === "review" ? store.submitTaskForReview(ref, { comment: body.comment, summary: body.summary })
1719
2053
  : action === "retry" ? store.retryTaskExecution(ref)
1720
2054
  : store.releaseTaskAssignment(ref);
2055
+ refreshDiagnosticsAfterFix(store, task.identifier); // 卡 `-248`:修复动作后重算 ⇒ 该消的诊断当场消解
1721
2056
  emit("task.updated", { taskId: task.id, identifier: task.identifier, status: task.status });
1722
2057
  return { status: 200, payload: { task } };
1723
2058
  }
@@ -1740,11 +2075,12 @@ export function createApiRouter({ store, aiElaborator, events, executorProbe = d
1740
2075
  }
1741
2076
  if (method !== "POST") throw new TbError("USAGE_ERROR", "review 仅支持 GET / POST");
1742
2077
  const action = String(body.action ?? "request");
1743
- const result = action === "request" ? store.requestReview(ref, { reviewer: body.reviewer ?? null, dependsOn: body.dependsOn ?? null, comment: body.comment ?? "", actor: body.actor ?? "human" })
2078
+ const result = action === "request" ? store.requestReview(ref, { reviewer: body.reviewer ?? null, dependsOn: body.dependsOn ?? null, comment: body.comment ?? "", summary: body.summary ?? null, actor: body.actor ?? "human" })
1744
2079
  : action === "changes" ? store.requestChanges(ref, { comment: body.comment ?? "", actor: body.actor ?? "reviewer" })
1745
2080
  : action === "approve" ? store.approveReview(ref, { comment: body.comment ?? "", actor: body.actor ?? "reviewer" })
1746
2081
  : null;
1747
2082
  if (!result) throw invalidField("action", "action 只支持 request / changes / approve");
2083
+ refreshDiagnosticsAfterFix(store, result.task.identifier); // 卡 `-248`:指派评审者后重算(`review_deadlock` 消解)
1748
2084
  emit("task.updated", { taskId: result.task.id, identifier: result.task.identifier, status: result.task.status });
1749
2085
  return { status: 200, payload: result };
1750
2086
  }