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
|
@@ -0,0 +1,648 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* diagnostics.mjs —— 可操作诊断框架(FR-79)。
|
|
3
|
+
*
|
|
4
|
+
* 设计对齐 hermes `Diagnostic / DiagnosticAction`(见 设计/hermes-kanban评估-2026-10-16.md §6.4):
|
|
5
|
+
* · 每条诊断 = 类型(kind) + 严重度(severity) + 标题 + 说明 + 恢复动作(可多条,标首选) + suggested
|
|
6
|
+
* · 诊断只在"人能处理"时出现(看护规则命中才产出);问题消失即自动消解(落库时收口)
|
|
7
|
+
* · 同一问题持续 → count / last_seen_at 递增,不重复刷屏(同一 kind 只留一条)
|
|
8
|
+
* · 卡片只带 {count, kinds, highestSeverity} 摘要;详情带完整列表(一次请求取回)
|
|
9
|
+
*
|
|
10
|
+
* 本模块只做纯规则 + 只读上下文装配;写库统一交给 store.saveTaskDiagnostics(),
|
|
11
|
+
* 这样规则可单测、可回放,也不产生与 store.mjs 的循环依赖(store 不反向 import 本模块)。
|
|
12
|
+
*/
|
|
13
|
+
import { BLOCK_RECURRENCE_LIMIT, DEFAULT_FAILURE_LIMIT, QUOTA_AUTH_ERROR_RE } from "./store.mjs";
|
|
14
|
+
import { STALL_THRESHOLD_MS, assessTask, latestProgressComment, runInFlight } from "./watchdog.mjs";
|
|
15
|
+
import { REVIEW_IDLE_MS, detectReviewDeadlock } from "./review.mjs";
|
|
16
|
+
import { categoryLabel, classifyHumanReview, isHumanReviewTask } from "./human-review.mjs";
|
|
17
|
+
import { detectUntakenDelivery } from "./delivery.mjs";
|
|
18
|
+
|
|
19
|
+
/** 诊断类型(FR-79 验收里逐个点名的八类规则)。 */
|
|
20
|
+
export const DIAGNOSTIC_KINDS = Object.freeze([
|
|
21
|
+
"stalled", "awaiting_decision", "repeated_failure", "repeated_crash",
|
|
22
|
+
"stuck_blocked", "block_loop", "unclaimed", "review_deadlock",
|
|
23
|
+
"human_review_required",
|
|
24
|
+
// 2026-10-22 补口:把「投递到会话但没交作业」从**静默回收**变成**可见 + 有恢复动作**。
|
|
25
|
+
"delivery_untaken",
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
/** 严重度取值;high 最重(UI 用它排序与着色)。 */
|
|
29
|
+
export const DIAGNOSTIC_SEVERITIES = Object.freeze(["high", "medium", "low"]);
|
|
30
|
+
export const SEVERITY_RANK = Object.freeze({ high: 3, medium: 2, low: 1 });
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* FR-85 升级门的**显式申报**通道(2026-10-18 真机补)。
|
|
34
|
+
*
|
|
35
|
+
* 背景:四类情形里「真实 bug 阻塞」能靠运行痕迹(复发 + 失败证据)自动判定,
|
|
36
|
+
* 但「需求异化 / 技术架构变化 / 与上游需求不符」这三类**没有任何可持久化来源** ——
|
|
37
|
+
* 真机实测:即便把最明确的申报写进任务评论,升级门仍回 400「输入未提供任何可用证据或信号」,
|
|
38
|
+
* 即 FR-85 的四类里只有一类真正可达。
|
|
39
|
+
*
|
|
40
|
+
* 口径:**只认这一种机器可读写法** —— 评论里出现 `【人工校验申报】` 且随带 `类别=<四类之一>`。
|
|
41
|
+
* 评论的**自由正文一律不当证据**(原有决策不变:否则一句"退出码 0"的评论就能造出误升级);
|
|
42
|
+
* 因此这里读的是**结构化声明**,不是散文,既不违反红线,也让三类情形重新可达。
|
|
43
|
+
*
|
|
44
|
+
* 写法(任选一行放在评论正文里即可):
|
|
45
|
+
* 【人工校验申报】类别=需求异化;证据=<与哪条需求条目/上游条款如何矛盾>
|
|
46
|
+
* 【人工校验申报】类别=架构变化;证据=<要改哪块基线架构/跨模块契约>
|
|
47
|
+
* 【人工校验申报】类别=与上游需求不符;证据=<哪条验收口径无法满足/需求已被取代>
|
|
48
|
+
*/
|
|
49
|
+
export const HUMAN_REVIEW_DECLARATION_MARKER = "【人工校验申报】";
|
|
50
|
+
/** 申报类别(中/英/下划线三种写法都认)→ 与 `classifyHumanReview` 四类判定一一对应。 */
|
|
51
|
+
export const HUMAN_REVIEW_DECLARATION_CATEGORIES = Object.freeze({
|
|
52
|
+
"需求异化": "requirement-drift", "requirement-drift": "requirement-drift", "requirement_drift": "requirement-drift",
|
|
53
|
+
"架构变化": "architecture-change", "技术架构变化": "architecture-change",
|
|
54
|
+
"architecture-change": "architecture-change", "architecture_change": "architecture-change",
|
|
55
|
+
"与上游需求不符": "upstream-mismatch", "上游不符": "upstream-mismatch",
|
|
56
|
+
"upstream-mismatch": "upstream-mismatch", "upstream_mismatch": "upstream-mismatch",
|
|
57
|
+
});
|
|
58
|
+
/** 申报可映射到的三个类别(`real-bug-blocked` 不靠申报 —— 它由复发 + 失败证据自动判定)。 */
|
|
59
|
+
const DECLARABLE_CATEGORIES = new Set(["requirement-drift", "architecture-change", "upstream-mismatch"]);
|
|
60
|
+
|
|
61
|
+
const collapse = (s) => String(s ?? "").replace(/\s+/g, " ").trim();
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 从评论里抽出**显式申报**证据(纯函数,只认标记,不猜散文)。
|
|
65
|
+
* 返回结构化证据:`kind` = 四类之一(下游判定器按 kind 精确命中),`ref` = 评论 id(可回溯原文)。
|
|
66
|
+
*/
|
|
67
|
+
export function declarationEvidence(comments = []) {
|
|
68
|
+
const out = [];
|
|
69
|
+
for (const c of Array.isArray(comments) ? comments : []) {
|
|
70
|
+
const text = String(c?.body ?? "");
|
|
71
|
+
const at = text.indexOf(HUMAN_REVIEW_DECLARATION_MARKER);
|
|
72
|
+
if (at < 0) continue;
|
|
73
|
+
const tail = text.slice(at + HUMAN_REVIEW_DECLARATION_MARKER.length);
|
|
74
|
+
const m = /类别\s*[=::]\s*([^\n;;,,]+)/.exec(tail);
|
|
75
|
+
const raw = collapse(m ? m[1] : "");
|
|
76
|
+
const kind = HUMAN_REVIEW_DECLARATION_CATEGORIES[raw] ?? HUMAN_REVIEW_DECLARATION_CATEGORIES[raw.toLowerCase()] ?? null;
|
|
77
|
+
const body = collapse(tail).slice(0, 300);
|
|
78
|
+
out.push({
|
|
79
|
+
kind: kind ?? "human-review-declaration",
|
|
80
|
+
summary: kind ? `人工校验显式申报(${raw}):${body}` : `人工校验显式申报(未识别类别「${raw}」):${body}`,
|
|
81
|
+
text: body,
|
|
82
|
+
ref: c?.id ?? null,
|
|
83
|
+
at: c?.createdAt ?? null,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* FR-85 升级门「已结论」水位线(2026-10-19 真机补)。
|
|
91
|
+
*
|
|
92
|
+
* 现场:任务 `taskboard-workbench-90` 的申报评论(`【人工校验申报】类别=与上游需求不符`)已按门径落了卡
|
|
93
|
+
* `-91`,人也给出了结论 `continue`(`-91` → `canceled`)。但**申报评论永远留在评论历史里**,而
|
|
94
|
+
* `human_review_required` 的幂等只对「**待结论**」的同类卡去重 ⇒ 结论之后诊断照旧每轮产出,
|
|
95
|
+
* 它给的**主按钮还会再造一张同类卡**(`createHumanReviewTask` 同样只挡 pending)—— 这扇门再也关不上。
|
|
96
|
+
*
|
|
97
|
+
* 口径(最小改动、不削弱 FR-85):只有当本次判定**由申报评论驱动**、且该申报**不晚于**同类别的结论时,
|
|
98
|
+
* 才算「人已经就这条证据回答过」→ 不再提示、不得再造卡。**结论之后又出现更新的申报**(新证据)则门重新成立;
|
|
99
|
+
* 由**运行痕迹**驱动的类别(如 `real-bug-blocked`)**不适用**本水位线 —— 那是「又坏了一次」,本就应该重新升级。
|
|
100
|
+
*
|
|
101
|
+
* @returns 命中的那张已结论人工校验任务;未命中返回 `null`。
|
|
102
|
+
*/
|
|
103
|
+
export function humanReviewAnsweredBy(classification, declarations = [], concluded = []) {
|
|
104
|
+
const category = classification?.category ?? null;
|
|
105
|
+
if (!category) return null;
|
|
106
|
+
const declAt = (Array.isArray(declarations) ? declarations : [])
|
|
107
|
+
.filter((d) => d && DECLARABLE_CATEGORIES.has(d.kind))
|
|
108
|
+
.map((d) => Date.parse(String(d.at ?? "")))
|
|
109
|
+
.filter((t) => Number.isFinite(t))
|
|
110
|
+
.reduce((a, b) => Math.max(a, b), -Infinity);
|
|
111
|
+
if (!Number.isFinite(declAt)) return null;
|
|
112
|
+
const rows = (Array.isArray(concluded) ? concluded : [])
|
|
113
|
+
.filter((t) => (t?.humanReviewCategory ?? null) === category)
|
|
114
|
+
.map((t) => ({ t, at: Date.parse(String(t?.humanReviewConcludedAt ?? t?.updatedAt ?? "")) }))
|
|
115
|
+
.filter((x) => Number.isFinite(x.at))
|
|
116
|
+
.sort((a, b) => b.at - a.at);
|
|
117
|
+
if (!rows.length) return null;
|
|
118
|
+
return declAt <= rows[0].at ? rows[0].t : null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** 阈值(可被调用方覆盖,便于单测与真机调参)。 */
|
|
122
|
+
export const DEFAULT_THRESHOLDS = Object.freeze({
|
|
123
|
+
/** 停滞:沿用 FR-75 的 10 分钟口径。 */
|
|
124
|
+
stallMs: STALL_THRESHOLD_MS,
|
|
125
|
+
/** 卡在受阻:默认 1 小时无人处理才算"卡住"(低于此值只是正常等待)。 */
|
|
126
|
+
blockedMs: 60 * 60 * 1000,
|
|
127
|
+
/** 循环阻断:复发阈值沿用 FR-80。 */
|
|
128
|
+
recurrenceLimit: BLOCK_RECURRENCE_LIMIT,
|
|
129
|
+
/** 评审停摆:无人评审多久算死锁(FR-83)。 */
|
|
130
|
+
reviewIdleMs: REVIEW_IDLE_MS,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
/** 崩溃类错误特征("重复崩溃"规则的兜底判据)。 */
|
|
134
|
+
export const CRASH_ERROR_RE = /\b(segfault|crash(ed)?|panic|killed|SIGKILL|SIGSEGV|OOM|out of memory|exit code|ENOENT|ELIFECYCLE|EPERM|EACCES)\b/i;
|
|
135
|
+
|
|
136
|
+
const encodeRef = (ref) => encodeURIComponent(String(ref));
|
|
137
|
+
|
|
138
|
+
/** 构造一条恢复动作(UI 可直接按 method/path/body 渲染成按钮)。 */
|
|
139
|
+
function action(id, label, { kind = "secondary", method = "POST", path = null, body = null, hint = null, needs = null } = {}) {
|
|
140
|
+
return { id, label, kind, method, path, body, hint, needs };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 会话引用解析(FR-84):任务自身会话 → 项目主会话 → 项目已关联会话(排除 rejected,取最新)。
|
|
145
|
+
* 返回 `{ sessionId, source, projectId }`;三级都拿不到时 `sessionId === null`。
|
|
146
|
+
*/
|
|
147
|
+
export function resolveSessionRef(store, task) {
|
|
148
|
+
const own = task?.sessionId ?? null;
|
|
149
|
+
if (own) return { sessionId: own, source: "task", projectId: task?.projectId ?? null };
|
|
150
|
+
const project = (typeof store?.getProject === "function" && task?.projectId) ? store.getProject(task.projectId) ?? null : null;
|
|
151
|
+
if (project?.initialSessionId) return { sessionId: project.initialSessionId, source: "project-main", projectId: project.id };
|
|
152
|
+
const bound = (typeof store?.listProjectSessions === "function" && task?.projectId)
|
|
153
|
+
? (store.listProjectSessions(task.projectId).filter((row) => row.sessionId && row.status !== "rejected").at(-1) ?? null)
|
|
154
|
+
: null;
|
|
155
|
+
if (bound) return { sessionId: bound.sessionId, source: "project-bound", projectId: task.projectId };
|
|
156
|
+
return { sessionId: null, source: null, projectId: task?.projectId ?? null };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 会话类动作(FR-84):**有可解析会话才产出「打开执行会话」**;
|
|
161
|
+
* 一个都解析不到时改为「重建并绑定项目主会话」——避免产出空会话标识的打开动作
|
|
162
|
+
* (真机事故:点「打开执行会话」→ "无法自动打开,已复制会话标识:-")。
|
|
163
|
+
*/
|
|
164
|
+
function sessionActions(ctx, { kind = "secondary", label = "打开执行会话" } = {}) {
|
|
165
|
+
const ref = ctx.task.identifier;
|
|
166
|
+
const sid = ctx.sessionRef?.sessionId ?? null;
|
|
167
|
+
if (sid) return [action("open_session", label, { kind, path: `/api/tasks/${encodeRef(ref)}/open-session`, hint: `会话来源:${ctx.sessionRef?.source ?? "task"}` })];
|
|
168
|
+
const projectId = ctx.sessionRef?.projectId ?? ctx.task.projectId ?? null;
|
|
169
|
+
if (!projectId) return [];
|
|
170
|
+
return [action("bind_session", "重建并绑定项目主会话", {
|
|
171
|
+
kind,
|
|
172
|
+
path: `/api/projects/${encodeRef(projectId)}/sessions/rebind`,
|
|
173
|
+
body: { confirm: true },
|
|
174
|
+
hint: "任务与项目都无可用会话引用:先重建主会话再谈打开",
|
|
175
|
+
})];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** 恢复动作的公共部分:绝大多数诊断都能"退回待办重派 / 打开(或重建)会话 / 标记失败"。 */
|
|
179
|
+
function commonActions(ctx, { retryLabel = "退回待办(重新派发)", retryHint = null } = {}) {
|
|
180
|
+
const enc = encodeRef(ctx.task.identifier);
|
|
181
|
+
return [
|
|
182
|
+
action("retry", retryLabel, { kind: "secondary", path: `/api/tasks/${enc}/execution/retry`, hint: retryHint }),
|
|
183
|
+
...sessionActions(ctx),
|
|
184
|
+
action("fail", "标记失败(留证据)", { path: `/api/tasks/${enc}/execution/fail` }),
|
|
185
|
+
];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** 人工忽略留痕标记:`已忽略诊断「<kind>」…`(FR-79「忽略即消解且保留原文可回溯」)。 */
|
|
189
|
+
const DISMISS_RE = /已忽略诊断[「"]?([a-zA-Z_]+)/;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* 已被人工忽略的诊断类型(且忽略发生在最近一次进展之后)。
|
|
193
|
+
* 口径:忽略留痕比"最近一次有进展意义的评论"更新 → 该项不再产出;
|
|
194
|
+
* 一旦出现更新的进展评论(说明情形已变),诊断重新生效。
|
|
195
|
+
*/
|
|
196
|
+
export function dismissedKinds(comments = []) {
|
|
197
|
+
const last = latestProgressComment(comments);
|
|
198
|
+
const lastAt = last?.createdAt ? new Date(last.createdAt).getTime() : -Infinity;
|
|
199
|
+
const out = new Set();
|
|
200
|
+
for (const c of comments) {
|
|
201
|
+
const m = DISMISS_RE.exec(String(c?.body ?? ""));
|
|
202
|
+
if (!m) continue;
|
|
203
|
+
const at = c.createdAt ? new Date(c.createdAt).getTime() : 0;
|
|
204
|
+
if (at >= lastAt) out.add(m[1].toLowerCase());
|
|
205
|
+
}
|
|
206
|
+
return out;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const minutesOf = (fromIso, now) => (fromIso ? Math.max(0, Math.round((now - new Date(fromIso).getTime()) / 60000)) : null);
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* 规则集:每条规则吃同一个上下文 ctx,返回诊断(未命中返回 null)。
|
|
213
|
+
* ctx 字段由 collectContext 装配:task / comments / watchdog / claim / sessionState /
|
|
214
|
+
* failures / runs / review / now / thresholds / dismissed。
|
|
215
|
+
*/
|
|
216
|
+
/**
|
|
217
|
+
* 诊断 detail 里的证据渲染(2026-10-19 真机补)。
|
|
218
|
+
*
|
|
219
|
+
* 证据项是**结构化对象**(`{kind, summary, text, ref, at}`,见 `humanReviewProbe`),
|
|
220
|
+
* 早前直接 `String(e)` 拼串 ⇒ 真机上「可核验证据」两行渲染成 `· [object Object]`,
|
|
221
|
+
* 人要据此判断「是否升级人工校验」,看到的却是乱码。
|
|
222
|
+
*/
|
|
223
|
+
function evidenceText(e) {
|
|
224
|
+
if (e === null || e === undefined) return "";
|
|
225
|
+
if (typeof e === "string") return e;
|
|
226
|
+
const text = e.summary ?? e.text ?? e.title ?? null;
|
|
227
|
+
if (typeof text === "string" && text !== "") return text;
|
|
228
|
+
try { return JSON.stringify(e); } catch { return String(e); }
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export const DIAGNOSTIC_RULES = Object.freeze([
|
|
232
|
+
{
|
|
233
|
+
kind: "block_loop",
|
|
234
|
+
evaluate(ctx) {
|
|
235
|
+
const { task, thresholds, dismissed } = ctx;
|
|
236
|
+
if (dismissed.has("block_loop")) return null;
|
|
237
|
+
const rec = Number(task.blockRecurrences ?? 0);
|
|
238
|
+
if (!(task.triageAt || rec >= thresholds.recurrenceLimit) || !task.blockKind) return null;
|
|
239
|
+
const enc = encodeRef(task.identifier);
|
|
240
|
+
return {
|
|
241
|
+
kind: "block_loop", severity: "high",
|
|
242
|
+
title: `阻断循环:同因阻断 ${rec} 次`,
|
|
243
|
+
detail: `阻断类型=${task.blockKind},同因阻断已复发 ${rec} 次(阈值 ${thresholds.recurrenceLimit})→ 已转「人工兜底」,自动重派已停止;需人判断是改方案还是调依赖。`,
|
|
244
|
+
suggested: "retry",
|
|
245
|
+
actions: [
|
|
246
|
+
action("retry", "重新派发(你已介入)", { kind: "primary", path: `/api/tasks/${enc}/execution/retry`, hint: "复发计数不会清零(FR-80)" }),
|
|
247
|
+
...sessionActions(ctx),
|
|
248
|
+
action("dismiss", "忽略此项", { path: `/api/tasks/${enc}/diagnostics/dismiss`, body: { kind: "block_loop" } }),
|
|
249
|
+
],
|
|
250
|
+
};
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
kind: "stalled",
|
|
255
|
+
evaluate(ctx) {
|
|
256
|
+
const { task, watchdog, dismissed } = ctx;
|
|
257
|
+
if (dismissed.has("stalled")) return null;
|
|
258
|
+
if (watchdog?.state !== "stalled") return null;
|
|
259
|
+
const enc = encodeRef(task.identifier);
|
|
260
|
+
const offline = watchdog.reason === "session-offline";
|
|
261
|
+
return {
|
|
262
|
+
kind: "stalled", severity: "high",
|
|
263
|
+
title: `疑似停滞:${watchdog.minutes} 分钟无进展`,
|
|
264
|
+
detail: `任务仍在「进行中」,但执行会话${offline ? "未在线" : "已空闲"}且已 ${watchdog.minutes} 分钟无进展回报。任务会一直占着「进行中」列,需要人决定重派还是收尾。`,
|
|
265
|
+
suggested: "retry",
|
|
266
|
+
actions: [
|
|
267
|
+
action("retry", "退回待办(重新派发)", { kind: "primary", path: `/api/tasks/${enc}/execution/retry` }),
|
|
268
|
+
...sessionActions(ctx),
|
|
269
|
+
action("fail", "标记失败(留证据)", { path: `/api/tasks/${enc}/execution/fail` }),
|
|
270
|
+
action("dismiss", "忽略此项", { path: `/api/tasks/${enc}/diagnostics/dismiss`, body: { kind: "stalled" } }),
|
|
271
|
+
],
|
|
272
|
+
};
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
kind: "unclaimed",
|
|
277
|
+
evaluate(ctx) {
|
|
278
|
+
const { task, claim, sessionState, currentRun, dismissed } = ctx;
|
|
279
|
+
if (dismissed.has("unclaimed")) return null;
|
|
280
|
+
if (task.status !== "in_progress") return null;
|
|
281
|
+
// 2026-10-22(真机 `-122` 同批):在途的 CLI 执行也必须排除 —— `direct-handoff` 那条路
|
|
282
|
+
// (非 todo 状态手工点执行)**不建认领锁**,只判 claim 就会把真在跑的子进程报成"没人干",
|
|
283
|
+
// 主按钮变「回收失效认领(退回来源列)」⇒ 与仍在写文件的子进程并发(同 FR-86 双写风险)。
|
|
284
|
+
// 与看护同一份口径:**会话不可判**(CLI 路径)时才用尝试心跳兜底的"在途"信号。
|
|
285
|
+
if (sessionState?.running) return null;
|
|
286
|
+
if (!sessionState?.sessionId && runInFlight(currentRun, { now: ctx.now, thresholdMs: ctx.thresholds?.stallMs })) return null;
|
|
287
|
+
if (claim?.locked && !claim?.expired) return null;
|
|
288
|
+
const why = claim?.locked && claim?.expired ? "认领已过期" : claim?.locked ? "认领心跳陈旧" : "未被执行者认领";
|
|
289
|
+
return {
|
|
290
|
+
kind: "unclaimed", severity: "high",
|
|
291
|
+
title: "无人认领的「进行中」任务",
|
|
292
|
+
detail: `任务处于「进行中」,但${why}(无有效认领锁),且执行会话不在运行——这条任务事实上没人干。`,
|
|
293
|
+
suggested: "reclaim",
|
|
294
|
+
actions: [
|
|
295
|
+
action("reclaim", "回收失效认领(退回来源列)", { kind: "primary", path: `/api/tasks/${encodeRef(task.identifier)}/reclaim` }),
|
|
296
|
+
...commonActions(ctx),
|
|
297
|
+
],
|
|
298
|
+
};
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
/**
|
|
303
|
+
* 2026-10-22 补口(真机续二十二):看板把派发指令投进会话后,会话里的 agent 可能**干了活但不回报**
|
|
304
|
+
* (改了文件、没提交「待验收」、没留评论)⇒ 看护按心跳陈旧回收、任务静默退回「todo」,而看板上
|
|
305
|
+
* 只有一句「认领已回收」,看不出"成果可能已经落在工作区"。这条规则把它变成**可见 + 有恢复动作**:
|
|
306
|
+
* 判据与文案见 `core/delivery.mjs`(纯函数,与 store 收口留痕共用同一份判定,防漂移)。
|
|
307
|
+
*/
|
|
308
|
+
kind: "delivery_untaken",
|
|
309
|
+
evaluate(ctx) {
|
|
310
|
+
const { task, runs, comments, dismissed } = ctx;
|
|
311
|
+
if (dismissed.has("delivery_untaken")) return null;
|
|
312
|
+
const hit = detectUntakenDelivery({ task, runs, comments });
|
|
313
|
+
if (!hit) return null;
|
|
314
|
+
const enc = encodeRef(task.identifier);
|
|
315
|
+
const sid = String(hit.run.sessionId ?? "");
|
|
316
|
+
return {
|
|
317
|
+
kind: "delivery_untaken", severity: "medium",
|
|
318
|
+
title: "投递到会话后没有收尾(成果可能与看板脱钩)",
|
|
319
|
+
detail: `第 ${hit.run.attempt} 次尝试是**投递到执行会话**${sid ? ` ${sid.slice(0, 18)}…` : ""} 的,`
|
|
320
|
+
+ `但会话里没有交作业(无「待验收」提交,且该次尝试开始后没有任何评论)⇒ 已按「${hit.reason}」收口。`
|
|
321
|
+
+ `\n工作区可能已有未提交的改动:请先人工核对(点「打开执行会话」看现场,或直接看工作目录 diff),再决定重派还是作废。`,
|
|
322
|
+
suggested: "open_session",
|
|
323
|
+
actions: [
|
|
324
|
+
...sessionActions(ctx, { kind: "primary", label: "打开执行会话(看现场)" }),
|
|
325
|
+
action("dismiss", "忽略此项(已人工核对工作区)", { path: `/api/tasks/${enc}/diagnostics/dismiss`, body: { kind: "delivery_untaken" }, hint: "写一条忽略留痕,原文可回溯" }),
|
|
326
|
+
],
|
|
327
|
+
};
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
kind: "repeated_failure",
|
|
332
|
+
evaluate(ctx) {
|
|
333
|
+
const { task, failures, dismissed } = ctx;
|
|
334
|
+
if (dismissed.has("repeated_failure")) return null;
|
|
335
|
+
if (failures.consecutive < failures.limit) return null;
|
|
336
|
+
const quota = QUOTA_AUTH_ERROR_RE.test(String(task.lastFailureError ?? ""));
|
|
337
|
+
const tail = task.lastFailureError ? `\n最近失败:${String(task.lastFailureError).slice(0, 300)}` : "";
|
|
338
|
+
return {
|
|
339
|
+
kind: "repeated_failure", severity: "high",
|
|
340
|
+
title: quota ? "配额/鉴权类失败:不重试" : `连续失败 ${failures.consecutive}/${failures.limit}`,
|
|
341
|
+
detail: `${quota ? "上次失败属配额或鉴权类错误(重试不会让配额回来)," : ""}连续非成功已达 ${failures.consecutive} 次(阈值 ${failures.limit},来源 ${failures.limitSource})→ 已熔断,自动派发停止。${tail}`,
|
|
342
|
+
suggested: "reset_failures",
|
|
343
|
+
actions: [
|
|
344
|
+
action("reset_failures", "重置失败计数(放行重派)", { kind: "primary", path: `/api/tasks/${encodeRef(task.identifier)}/reset-failures`, hint: "人工显式重跑 = 新意图" }),
|
|
345
|
+
...commonActions(ctx),
|
|
346
|
+
],
|
|
347
|
+
};
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
kind: "repeated_crash",
|
|
352
|
+
evaluate(ctx) {
|
|
353
|
+
const { task, runs, failures, dismissed } = ctx;
|
|
354
|
+
if (dismissed.has("repeated_crash")) return null;
|
|
355
|
+
const crashed = (runs ?? []).filter((r) => ["crash", "crashed", "timeout", "killed"].includes(String(r.outcome ?? r.result ?? "").toLowerCase()));
|
|
356
|
+
const byError = failures.consecutive >= 2 && CRASH_ERROR_RE.test(String(task.lastFailureError ?? ""));
|
|
357
|
+
if (crashed.length < 2 && !byError) return null;
|
|
358
|
+
const lastRun = crashed[crashed.length - 1];
|
|
359
|
+
const evidence = crashed.length >= 2
|
|
360
|
+
? `${crashed.length} 次尝试以崩溃/超时结束(最近:${lastRun?.summary ?? lastRun?.outcome ?? "crash"})`
|
|
361
|
+
: `最近失败疑似崩溃类:${String(task.lastFailureError ?? "").slice(0, 200)}`;
|
|
362
|
+
const enc = encodeRef(task.identifier);
|
|
363
|
+
return {
|
|
364
|
+
kind: "repeated_crash", severity: "high",
|
|
365
|
+
title: "重复崩溃 / 超时",
|
|
366
|
+
detail: `同一任务反复以崩溃或超时收场(${evidence})。自动化重试大概率还会崩,需要人看日志或先修环境。`,
|
|
367
|
+
suggested: "open_session",
|
|
368
|
+
actions: [
|
|
369
|
+
...sessionActions(ctx, { kind: "primary", label: "打开执行会话(看日志)" }),
|
|
370
|
+
action("reset_failures", "重置失败计数", { path: `/api/tasks/${enc}/reset-failures` }),
|
|
371
|
+
action("retry", "退回待办(重新派发)", { path: `/api/tasks/${enc}/execution/retry` }),
|
|
372
|
+
],
|
|
373
|
+
};
|
|
374
|
+
},
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
kind: "stuck_blocked",
|
|
378
|
+
evaluate(ctx) {
|
|
379
|
+
const { task, thresholds, now, dismissed } = ctx;
|
|
380
|
+
if (dismissed.has("stuck_blocked")) return null;
|
|
381
|
+
if (task.status !== "blocked") return null;
|
|
382
|
+
const minutes = minutesOf(task.blockedAt, now);
|
|
383
|
+
if (minutes === null || minutes * 60000 < thresholds.blockedMs) return null;
|
|
384
|
+
const enc = encodeRef(task.identifier);
|
|
385
|
+
const kindLabel = task.blockKind ? `类型=${task.blockKind}` : "类型=未分类";
|
|
386
|
+
return {
|
|
387
|
+
kind: "stuck_blocked", severity: task.triageAt ? "high" : "medium",
|
|
388
|
+
title: `卡在受阻 ${minutes} 分钟`,
|
|
389
|
+
detail: `已受阻 ${minutes} 分钟(${kindLabel}),期间无人处理。受阻任务不会自己动——需要人给料、改判或撤障。`,
|
|
390
|
+
suggested: "retry",
|
|
391
|
+
actions: [
|
|
392
|
+
action("retry", "退回待办(重新派发)", { kind: "primary", path: `/api/tasks/${enc}/execution/retry` }),
|
|
393
|
+
...sessionActions(ctx),
|
|
394
|
+
action("dismiss", "忽略此项", { path: `/api/tasks/${enc}/diagnostics/dismiss`, body: { kind: "stuck_blocked" } }),
|
|
395
|
+
],
|
|
396
|
+
};
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
kind: "awaiting_decision",
|
|
401
|
+
evaluate(ctx) {
|
|
402
|
+
const { task, watchdog, dismissed } = ctx;
|
|
403
|
+
if (dismissed.has("awaiting_decision")) return null;
|
|
404
|
+
if (watchdog?.state !== "awaiting-decision") return null;
|
|
405
|
+
const items = (watchdog.followups ?? []).slice(0, 3);
|
|
406
|
+
const enc = encodeRef(task.identifier);
|
|
407
|
+
return {
|
|
408
|
+
kind: "awaiting_decision", severity: "medium",
|
|
409
|
+
title: watchdog.question ? "等你确认:执行侧在提问" : "待决策:有「下一步」建议",
|
|
410
|
+
detail: `执行会话已空闲并留下可跟进项(不算卡死,算等人):${items.length ? `\n- ${items.join("\n- ")}` : ""}`,
|
|
411
|
+
suggested: "derive",
|
|
412
|
+
actions: [
|
|
413
|
+
action("derive", "派生为子任务", { kind: "primary", path: `/api/tasks/${enc}/followup`, body: { action: "derive" }, needs: "title", hint: "父任务=原任务、归因同一需求条目、状态=待办池" }),
|
|
414
|
+
action("dismiss", "忽略此项", { path: `/api/tasks/${enc}/diagnostics/dismiss`, body: { kind: "awaiting_decision" }, hint: "写一条忽略留痕,原文可回溯" }),
|
|
415
|
+
...sessionActions(ctx),
|
|
416
|
+
],
|
|
417
|
+
};
|
|
418
|
+
},
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
kind: "review_deadlock",
|
|
422
|
+
evaluate(ctx) {
|
|
423
|
+
const { task, review, dismissed } = ctx;
|
|
424
|
+
if (dismissed.has("review_deadlock")) return null;
|
|
425
|
+
if (!review?.deadlocked) return null;
|
|
426
|
+
const enc = encodeRef(task.identifier);
|
|
427
|
+
return {
|
|
428
|
+
kind: "review_deadlock", severity: "high",
|
|
429
|
+
title: "评审死锁",
|
|
430
|
+
detail: `评审链无法推进:${review.reason ?? "评审者不可用或评审依赖成环"}。任务会一直停在「待验收」,等人来打破。`,
|
|
431
|
+
suggested: "review",
|
|
432
|
+
actions: [
|
|
433
|
+
action("review", "请求评审 / 指派评审者", { kind: "primary", path: `/api/tasks/${enc}/execution/review` }),
|
|
434
|
+
...sessionActions(ctx),
|
|
435
|
+
action("dismiss", "忽略此项", { path: `/api/tasks/${enc}/diagnostics/dismiss`, body: { kind: "review_deadlock" } }),
|
|
436
|
+
],
|
|
437
|
+
};
|
|
438
|
+
},
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
kind: "human_review_required",
|
|
442
|
+
evaluate(ctx) {
|
|
443
|
+
const { task, humanReview, dismissed } = ctx;
|
|
444
|
+
if (dismissed.has("human_review_required")) return null;
|
|
445
|
+
// 人工校验任务自己不再触发升级门(否则会自我繁殖)
|
|
446
|
+
if (ctx.isHumanReviewTask) return null;
|
|
447
|
+
const c = humanReview?.classification ?? null;
|
|
448
|
+
// FR-85 红线:判不准就不升级 —— confident=false 时**绝不产出**(不许自动臆断)
|
|
449
|
+
if (!c?.confident || !c.category) return null;
|
|
450
|
+
// 幂等:同项目同类已有待结论的人工校验任务 → 不重复造卡(否则诊断每轮都造一条)
|
|
451
|
+
if (humanReview.pendingSameCategory) return null;
|
|
452
|
+
// 2026-10-19 真机补:同类**已给出结论**、且本次判定由**更早的**申报驱动 ⇒ 这扇门已被人回答过。
|
|
453
|
+
// 否则一条常驻的申报评论会让 `-90` 这类卡在人已结论后**永远**挂着 high 级「需人工校验」。
|
|
454
|
+
if (humanReview.answeredSameCategory) return null;
|
|
455
|
+
const enc = encodeRef(task.identifier);
|
|
456
|
+
const label = categoryLabel(c.category) ?? c.category;
|
|
457
|
+
const evidence = (humanReview.evidence ?? []).slice(0, 5);
|
|
458
|
+
const tail = evidence.length ? `\n可核验证据:\n${evidence.map((e) => ` · ${evidenceText(e).slice(0, 200)}`).join("\n")}` : "";
|
|
459
|
+
return {
|
|
460
|
+
kind: "human_review_required", severity: "high",
|
|
461
|
+
title: `需人工校验:${label}`,
|
|
462
|
+
detail: `${c.confidenceReason ?? "证据充分"}——已命中 FR-85 的四类情形之一,自动化到此为止。派发人工校验任务后**停手等人**:结论(继续 / 变更需求 / 关闭)给出前,本任务与下游都不会被自动推进。${tail}`,
|
|
463
|
+
suggested: "human_review",
|
|
464
|
+
actions: [
|
|
465
|
+
action("human_review", "派发人工校验任务(停手等人)", { kind: "primary", path: `/api/tasks/${enc}/human-review`, hint: `类别=${label};执行侧不得认领、不得置 done` }),
|
|
466
|
+
action("dismiss", "忽略此项", { path: `/api/tasks/${enc}/diagnostics/dismiss`, body: { kind: "human_review_required" }, hint: "忽略后同类情形不再提示,直到出现更新的进展评论" }),
|
|
467
|
+
],
|
|
468
|
+
};
|
|
469
|
+
},
|
|
470
|
+
},
|
|
471
|
+
]);
|
|
472
|
+
|
|
473
|
+
/** 纯函数:按规则集产出诊断列表(按严重度 → kind 稳定排序)。 */
|
|
474
|
+
export function buildDiagnostics(ctx) {
|
|
475
|
+
const out = [];
|
|
476
|
+
for (const rule of DIAGNOSTIC_RULES) {
|
|
477
|
+
let d = null;
|
|
478
|
+
try { d = rule.evaluate(ctx); } catch { d = null; }
|
|
479
|
+
if (!d || !DIAGNOSTIC_KINDS.includes(d.kind)) continue;
|
|
480
|
+
const actions = d.actions ?? [];
|
|
481
|
+
// FR-84:`suggested` 必须指向**真实存在**的动作——会话类动作可能因"无可解析会话"
|
|
482
|
+
// 被换成「重建并绑定主会话」(id: bind_session),此时不能宣称"首选=打开执行会话"。
|
|
483
|
+
let suggested = d.suggested;
|
|
484
|
+
if (actions.length && !actions.some((a) => a.id === suggested)) {
|
|
485
|
+
suggested = (actions.find((a) => a.kind === "primary") ?? actions[0]).id;
|
|
486
|
+
}
|
|
487
|
+
out.push({ ...d, suggested, actions });
|
|
488
|
+
}
|
|
489
|
+
return out.sort((a, b) => (SEVERITY_RANK[b.severity] - SEVERITY_RANK[a.severity]) || a.kind.localeCompare(b.kind));
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/** 卡片摘要(FR-79:卡片只带 {count, kinds, highestSeverity})。 */
|
|
493
|
+
export function summarizeDiagnostics(list = []) {
|
|
494
|
+
const rows = (list ?? []).filter(Boolean);
|
|
495
|
+
if (!rows.length) return null;
|
|
496
|
+
const highest = rows.reduce((acc, d) => (SEVERITY_RANK[d.severity] > SEVERITY_RANK[acc] ? d.severity : acc), "low");
|
|
497
|
+
return { count: rows.length, kinds: [...new Set(rows.map((d) => d.kind))].sort(), highestSeverity: highest };
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/** 项目级汇总:按严重度与 kind 计数。 */
|
|
501
|
+
export function summarizeProject(rows = []) {
|
|
502
|
+
const bySeverity = { high: 0, medium: 0, low: 0 };
|
|
503
|
+
const byKind = {};
|
|
504
|
+
for (const r of rows) {
|
|
505
|
+
bySeverity[r.severity] = (bySeverity[r.severity] ?? 0) + 1;
|
|
506
|
+
byKind[r.kind] = (byKind[r.kind] ?? 0) + 1;
|
|
507
|
+
}
|
|
508
|
+
return { total: rows.length, bySeverity, byKind };
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/** 装配规则上下文(只读 store;不写库)。 */
|
|
512
|
+
/**
|
|
513
|
+
* FR-85b:把任务的当前状态收敛成"人在环升级门"的判定输入(只读,不写库)。
|
|
514
|
+
*
|
|
515
|
+
* 证据只取**可核验的运行痕迹**(尝试记录的结论/错误 + 最近失败原因)与**已落库的诊断**;
|
|
516
|
+
* **不把聊天/评论正文当证据** —— 否则一句"退出码 0"的评论就足以造出误升级。
|
|
517
|
+
*/
|
|
518
|
+
export function humanReviewProbe(store, task, runs = null) {
|
|
519
|
+
const attempts = runs ?? (typeof store.listTaskRuns === "function" ? store.listTaskRuns(task) : []);
|
|
520
|
+
let persisted = [];
|
|
521
|
+
try { persisted = typeof store.listTaskDiagnostics === "function" ? store.listTaskDiagnostics(task) : []; } catch { persisted = []; }
|
|
522
|
+
// FR-85(2026-10-18 真机补):显式申报是「需求异化 / 架构变化 / 与上游不符」三类**唯一**的可持久化来源。
|
|
523
|
+
let comments = [];
|
|
524
|
+
try { comments = typeof store.listComments === "function" ? store.listComments(task.id) : []; } catch { comments = []; }
|
|
525
|
+
// 需求条目(真实关联,不是猜的):判定「需求已被取代/作废」分支要用它。
|
|
526
|
+
let requirementItem = null;
|
|
527
|
+
try {
|
|
528
|
+
requirementItem = (task.requirementId && typeof store.getRequirementItemById === "function")
|
|
529
|
+
? store.getRequirementItemById(task.requirementId) ?? null
|
|
530
|
+
: null;
|
|
531
|
+
} catch { requirementItem = null; }
|
|
532
|
+
const failedRuns = attempts.filter((r) => r.outcome && r.outcome !== "success");
|
|
533
|
+
// 2026-10-18 真机发现:这些证据此前被折成**纯字符串**,于是丢掉 kind → `kindIn(e,["failure",…])` 永不命中,
|
|
534
|
+
// 升级门对"反复真实失败"的任务恒报「失败证据 0 条」。改为带上 `kind: "failure"` 的结构化证据
|
|
535
|
+
// (仍保留同一份可读文本),语义与既有的 `outcome !== "success"` 过滤口径一致。
|
|
536
|
+
const declarations = declarationEvidence(comments);
|
|
537
|
+
const evidence = [
|
|
538
|
+
...declarations,
|
|
539
|
+
...failedRuns.map((r) => ({
|
|
540
|
+
kind: "failure",
|
|
541
|
+
summary: `${r.outcome}${r.summary ? `:${r.summary}` : ""}`,
|
|
542
|
+
text: `${r.outcome}${r.summary ? `:${r.summary}` : ""}${r.error ? `。${r.error}` : ""}`,
|
|
543
|
+
ref: r.id ?? null,
|
|
544
|
+
})),
|
|
545
|
+
task.lastFailureError ? `最近失败:${task.lastFailureError}` : "",
|
|
546
|
+
].filter(Boolean);
|
|
547
|
+
const input = {
|
|
548
|
+
task,
|
|
549
|
+
requirementItem,
|
|
550
|
+
// 显式申报的类别(若有):判定器据此直接出该类别结论(见 human-review.classifyHumanReview 的"申报优先")。
|
|
551
|
+
declaration: (declarations.find((d) => DECLARABLE_CATEGORIES.has(d.kind)) ?? null)?.kind ?? null,
|
|
552
|
+
blockRecurrences: Number(task.blockRecurrences ?? 0),
|
|
553
|
+
blockKind: task.blockKind ?? null,
|
|
554
|
+
diagnosis: persisted.map((d) => ({ kind: d.kind, severity: d.severity, title: d.title, detail: d.detail, count: d.count })),
|
|
555
|
+
evidence,
|
|
556
|
+
};
|
|
557
|
+
return { input, classification: classifyHumanReview(input), evidence, declarations };
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/** 规则上下文里的 FR-85b 切片:判定结果 + 该项目下已待结论的人工校验任务(去重用)。 */
|
|
561
|
+
function humanReviewContext(store, task, runs = null) {
|
|
562
|
+
const probe = humanReviewProbe(store, task, runs);
|
|
563
|
+
let pending = [];
|
|
564
|
+
try { pending = typeof store.humanReviewPending === "function" ? store.humanReviewPending(task.projectId) : []; } catch { pending = []; }
|
|
565
|
+
let concluded = [];
|
|
566
|
+
try { concluded = typeof store.listHumanReviews === "function" ? store.listHumanReviews({ projectId: task.projectId, state: "concluded" }) : []; } catch { concluded = []; }
|
|
567
|
+
const own = isHumanReviewTask(task);
|
|
568
|
+
const category = probe.classification.confident ? probe.classification.category ?? null : null;
|
|
569
|
+
return {
|
|
570
|
+
humanReview: {
|
|
571
|
+
...probe,
|
|
572
|
+
pending,
|
|
573
|
+
pendingSameCategory: category ? pending.find((t) => (t.humanReviewCategory ?? null) === category) ?? null : null,
|
|
574
|
+
// FR-85 已结论水位线:由**申报**驱动且申报不晚于结论 ⇒ 人已答过(见 humanReviewAnsweredBy)。
|
|
575
|
+
answeredSameCategory: category ? humanReviewAnsweredBy(probe.classification, probe.declarations, concluded) : null,
|
|
576
|
+
},
|
|
577
|
+
isHumanReviewTask: own,
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
export function collectContext(store, task, { now = Date.now(), thresholds = DEFAULT_THRESHOLDS, runs = null, review = null } = {}) {
|
|
581
|
+
const comments = store.listComments(task.id);
|
|
582
|
+
const sessionState = store.taskSessionState(task);
|
|
583
|
+
const limitOverride = task.maxRetries ?? null;
|
|
584
|
+
// FR-82:尝试记录是"重复崩溃"诊断的**一等判据**(不再只靠错误文本猜)
|
|
585
|
+
const attempts = runs ?? (typeof store.listTaskRuns === "function" ? store.listTaskRuns(task) : []);
|
|
586
|
+
// 2026-10-22:当前尝试(CLI 执行器**唯一**的在途信号 —— 那条路 sessionId 恒为 null)。
|
|
587
|
+
// 必须与看护共用同一份,否则 /execution 与诊断会给出两套口径。
|
|
588
|
+
const currentRun = typeof store.getCurrentRun === "function" ? store.getCurrentRun(task) : null;
|
|
589
|
+
return {
|
|
590
|
+
task,
|
|
591
|
+
comments,
|
|
592
|
+
claim: store.taskClaimState(task, { now }),
|
|
593
|
+
sessionState,
|
|
594
|
+
currentRun,
|
|
595
|
+
// FR-84:会话引用解析结果(供"打开会话 / 重建主会话"动作抉择)
|
|
596
|
+
sessionRef: resolveSessionRef(store, task),
|
|
597
|
+
// FR-85b:人在环升级门的判定(含 pending 去重信息)
|
|
598
|
+
...humanReviewContext(store, task, attempts),
|
|
599
|
+
watchdog: assessTask({ task, comments, sessionState, currentRun, now, thresholdMs: thresholds.stallMs }),
|
|
600
|
+
failures: {
|
|
601
|
+
consecutive: Number(task.consecutiveFailures ?? 0),
|
|
602
|
+
limit: limitOverride != null ? Number(limitOverride) : DEFAULT_FAILURE_LIMIT,
|
|
603
|
+
limitSource: limitOverride != null ? "task" : "default",
|
|
604
|
+
},
|
|
605
|
+
runs: attempts,
|
|
606
|
+
// FR-83:评审死锁由**真实判定**给出(调用方可显式覆盖,便于单测/回放)
|
|
607
|
+
review: review === null
|
|
608
|
+
? detectReviewDeadlock(store, task, { now, idleMs: thresholds.reviewIdleMs ?? REVIEW_IDLE_MS })
|
|
609
|
+
: review,
|
|
610
|
+
now,
|
|
611
|
+
thresholds,
|
|
612
|
+
dismissed: dismissedKinds(comments),
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* 评估单个任务并落库(诊断的唯一写入口)。
|
|
618
|
+
* 返回 { task, diagnostics(当前生效,含 count/firstSeenAt), summary, resolved }。
|
|
619
|
+
* `persist:false` 用于只读预览(不写库、不带计数)。
|
|
620
|
+
*/
|
|
621
|
+
export function evaluateTaskDiagnostics(store, ref, { now = Date.now(), thresholds = DEFAULT_THRESHOLDS, persist = true, runs = null, review = null } = {}) {
|
|
622
|
+
const task = ref && typeof ref === "object" && ref.id ? ref : store.requireTaskRef(ref);
|
|
623
|
+
const ctx = collectContext(store, task, { now, thresholds, runs, review });
|
|
624
|
+
const found = buildDiagnostics(ctx);
|
|
625
|
+
if (!persist) {
|
|
626
|
+
const preview = found.map((d) => ({ ...d, id: `preview:${task.id}:${d.kind}`, taskId: task.id, taskIdentifier: task.identifier, count: 1, firstSeenAt: null, lastSeenAt: new Date(now).toISOString(), resolvedAt: null }));
|
|
627
|
+
return { task, diagnostics: preview, summary: summarizeDiagnostics(preview), resolved: [] };
|
|
628
|
+
}
|
|
629
|
+
const saved = store.saveTaskDiagnostics(task.identifier, found, { now });
|
|
630
|
+
return { task, diagnostics: saved.active, summary: summarizeDiagnostics(saved.active), resolved: saved.resolved };
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* 项目级诊断:对"可能需要人介入"的任务逐个评估(进行中 / 受阻 / 待验收),
|
|
635
|
+
* 返回 { rows, summary }。只读路径也可以调用(会同步落库,保证 count 有意义)。
|
|
636
|
+
*/
|
|
637
|
+
export function projectDiagnostics(store, projectId, { now = Date.now(), thresholds = DEFAULT_THRESHOLDS, persist = true } = {}) {
|
|
638
|
+
const statuses = new Set(["in_progress", "blocked", "in_review"]);
|
|
639
|
+
const tasks = store.listTasks({ projectId }).filter((t) => statuses.has(t.status) || t.triageAt);
|
|
640
|
+
const rows = [];
|
|
641
|
+
for (const task of tasks) {
|
|
642
|
+
const r = evaluateTaskDiagnostics(store, task, { now, thresholds, persist });
|
|
643
|
+
for (const d of r.diagnostics) rows.push({ ...d, identifier: task.identifier, title: task.title, status: task.status });
|
|
644
|
+
}
|
|
645
|
+
rows.sort((a, b) => (SEVERITY_RANK[b.severity] - SEVERITY_RANK[a.severity]) || String(a.identifier).localeCompare(String(b.identifier)));
|
|
646
|
+
return { rows, summary: summarizeProject(rows) };
|
|
647
|
+
}
|
|
648
|
+
|