fde-console 0.0.0-stage → 2.9.68

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.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +128 -2
  3. package/README.zh-CN.md +130 -0
  4. package/assets/icon.svg +9 -0
  5. package/cordis.patch.yml +7 -0
  6. package/lib/agentActivity.js +1180 -0
  7. package/lib/agentContext.js +146 -0
  8. package/lib/agentTranscript.js +1398 -0
  9. package/lib/analyze.js +625 -0
  10. package/lib/attribute.js +205 -0
  11. package/lib/backup.js +366 -0
  12. package/lib/desktopAgents.js +123 -0
  13. package/lib/diary.js +333 -0
  14. package/lib/dingtalk.js +412 -0
  15. package/lib/feishu.js +580 -0
  16. package/lib/giteaClient.js +810 -0
  17. package/lib/giteeClient.js +372 -0
  18. package/lib/githubClient.js +361 -0
  19. package/lib/heatmap.js +99 -0
  20. package/lib/imNotify.js +378 -0
  21. package/lib/inbox.js +438 -0
  22. package/lib/instanceLock.js +122 -0
  23. package/lib/jobs.js +56 -0
  24. package/lib/learn.js +1388 -0
  25. package/lib/learnImport.js +283 -0
  26. package/lib/learnSeeds.js +97 -0
  27. package/lib/learnSeedsAiEng.js +77 -0
  28. package/lib/mcpCore.js +135 -0
  29. package/lib/members.js +160 -0
  30. package/lib/migration.js +403 -0
  31. package/lib/overview.js +376 -0
  32. package/lib/postmortem.js +148 -0
  33. package/lib/radarIgnore.js +134 -0
  34. package/lib/redact.js +76 -0
  35. package/lib/router.js +246 -0
  36. package/lib/routes-gitea.js +262 -0
  37. package/lib/routes-setup.js +40 -0
  38. package/lib/scorecard.js +111 -0
  39. package/lib/sessionRef.js +227 -0
  40. package/lib/sessionSnapshot.js +67 -0
  41. package/lib/sessionSuggest.js +186 -0
  42. package/lib/settings.js +783 -0
  43. package/lib/setupCheck.js +330 -0
  44. package/lib/ssrfGuard.js +145 -0
  45. package/lib/store.js +564 -0
  46. package/lib/storeDb.js +418 -0
  47. package/lib/taskEvents.js +243 -0
  48. package/lib/webhookOut.js +125 -0
  49. package/lib/weekly.js +439 -0
  50. package/lib/workSearch.js +220 -0
  51. package/locale/en.json +6 -0
  52. package/locale/zh.json +6 -0
  53. package/package.json +46 -4
  54. package/plugin/adapter.js +157 -0
  55. package/plugin/client.js +282 -0
  56. package/plugin/index.mjs +116 -0
  57. package/plugin/static.js +99 -0
  58. package/scripts/backup-data.js +41 -0
  59. package/scripts/mcp-server.mjs +68 -0
  60. package/scripts/migrate-data.js +301 -0
  61. package/scripts/migrate-storage.js +47 -0
  62. package/scripts/seed-demo.js +200 -0
  63. package/scripts/write-agent-context.js +43 -0
  64. package/test/helpers/appAssembler.js +1078 -0
  65. package/web/client/fde-client.js +292 -0
  66. package/web/css/app.css +1510 -0
  67. package/web/index.html +69 -0
  68. package/web/js/api.js +72 -0
  69. package/web/js/app.js +313 -0
  70. package/web/js/icons.js +48 -0
  71. package/web/js/mock.js +1150 -0
  72. package/web/js/state.js +7 -0
  73. package/web/js/ui.js +276 -0
  74. package/web/js/views/activity.js +410 -0
  75. package/web/js/views/agents.js +892 -0
  76. package/web/js/views/board.js +1656 -0
  77. package/web/js/views/learn.js +530 -0
  78. package/web/js/views/members.js +344 -0
  79. package/web/js/views/onboarding.js +103 -0
  80. package/web/js/views/overview.js +508 -0
  81. package/web/js/views/radar.js +1359 -0
  82. package/web/js/views/search.js +149 -0
  83. package/web/js/views/settings.js +1351 -0
  84. package/web/js/views/topology.js +471 -0
  85. package/web/mock.json +2363 -0
@@ -0,0 +1,376 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * overview.js — B5 总览聚合 + 成员进度(v1.1)+ 手工名册聚合(v1.2)
5
+ * - GET /api/overview:任务分布/智能体数/24h 动态/gitea 健康
6
+ * (读 data/gitea-status.json,只读)
7
+ * v2.2:gatewayExternalRunning 字段已随 网关集成整体移除(业主 2026-10-20);
8
+ * v2.3:sessionsRunning 字段已随会话登记表退役移除(规格 §6——会话观测唯一入口
9
+ * = GET /api/agent-sessions,登记表已无数据消费方)
10
+ * - GET /api/members:读时聚合不落盘;桌面 agent 注册表四源并列(workbuddy/zcode/codex/
11
+ * opencode,v2.6 起硅基成员来源,读 config.agentActivity.sources 各源 enabled/root/dbPath)
12
+ * ∪ Gitea 成员缓存 ∪ 动态中出现的人类 actor ∪ 手工名册 members.json(manual:true,giteaLogin
13
+ * 命中则归因其 Gitea 活动数据)。agents.json CLI 注册表仍不进成员册(仅用于人类派生时的
14
+ * actor 排除)。
15
+ */
16
+
17
+ const store = require('./store');
18
+ const { redact } = require('./redact');
19
+ const { sendJSON } = require('./router');
20
+ const { collectDesktopMembers, collectDesktopSourceHealth } = require('./desktopAgents');
21
+ const diaryMod = require('./diary');
22
+
23
+ const HOUR_MS = 3600 * 1000;
24
+ const DAY_MS = 24 * HOUR_MS;
25
+ const WEEK_MS = 7 * DAY_MS;
26
+
27
+ // v1.4:优先级合法集(与 server.js registerTaskRoutes 内同款;历史数据缺字段时回退 medium)
28
+ const PRIORITIES = ['high', 'medium', 'low'];
29
+
30
+ function parseTs(iso) {
31
+ const t = Date.parse(iso);
32
+ return Number.isFinite(t) ? t : null;
33
+ }
34
+
35
+ function ageSec(now, iso) {
36
+ const t = parseTs(iso);
37
+ if (t === null) return null;
38
+ return Math.max(0, Math.floor((now - t) / 1000));
39
+ }
40
+
41
+ function computeOverview(ctx) {
42
+ const now = Date.now();
43
+ const { columns, tasks } = store.loadTasks(ctx);
44
+
45
+ const counts = {};
46
+ [...columns]
47
+ .sort((a, b) => (a.order || 0) - (b.order || 0))
48
+ .forEach((col) => {
49
+ counts[col.id] = 0;
50
+ });
51
+ for (const t of tasks) {
52
+ counts[t.status] = (counts[t.status] || 0) + 1;
53
+ }
54
+
55
+ // v1.4:逾期任务数——按天比较(YYYY-MM-DD 字符串序比较即可),严格早于今天才逾期,今天到期不算
56
+ const n = new Date();
57
+ const pad2 = (x) => String(x).padStart(2, '0');
58
+ const todayYmd = `${n.getFullYear()}-${pad2(n.getMonth() + 1)}-${pad2(n.getDate())}`;
59
+ const overdue = tasks.filter((t) => typeof t.dueDate === 'string' && t.dueDate < todayYmd).length;
60
+
61
+ const agents = store.loadAgents(ctx.agentsPath).length;
62
+
63
+ const activities = store.loadActivities(ctx);
64
+ const activities24h = activities.filter((a) => {
65
+ const t = parseTs(a && a.occurredAt);
66
+ return t !== null && now - t >= 0 && now - t <= DAY_MS;
67
+ }).length;
68
+
69
+ // 日报未填人数(2026-11-03 驾驶舱行动条):名下有「进行中」任务、但今天没有任何 doing 任务
70
+ // 填了日报的**人类负责人**去重计数——纯 tasks+diary 数据零源扫描(/api/members 口径的 diaryToday
71
+ // 同源;评审修正:agentId 属主不参与——diary 是人工日报,硅基属主恒计「未填」属虚计)
72
+ let diaryMissing = 0;
73
+ try {
74
+ const withDiary = diaryMod.taskIdsWithDiaryOn(ctx, diaryMod.localYmd());
75
+ const doingByOwner = new Map();
76
+ for (const t of tasks) {
77
+ if (t.status !== 'doing') continue;
78
+ const owner = typeof t.memberId === 'string' ? t.memberId.trim() : ''; // 仅人类属主(memberId)
79
+ if (!owner) continue;
80
+ if (!doingByOwner.has(owner)) doingByOwner.set(owner, { any: 0, covered: 0 });
81
+ const slot = doingByOwner.get(owner);
82
+ slot.any += 1;
83
+ if (withDiary.has(t.id)) slot.covered += 1;
84
+ }
85
+ for (const slot of doingByOwner.values()) {
86
+ if (slot.any > 0 && slot.covered === 0) diaryMissing += 1;
87
+ }
88
+ } catch (e) {
89
+ console.error(redact(`[overview] diaryMissing 聚合失败(行动条该项按 0 计): ${(e && e.message) || e}`));
90
+ }
91
+
92
+ return {
93
+ tasks: { ...counts, overdue }, // v1.4:响应形状仅增 overdue 键,其余键一律不动
94
+ agents,
95
+ activities24h,
96
+ diaryMissing, // v2026-11-03 只增:驾驶舱行动条「日报未填」数据源
97
+ gitea: store.loadGiteaStatus(ctx),
98
+ };
99
+ }
100
+
101
+ // ---------- 成员进度 ----------
102
+
103
+ // v2.9.1:actorMatches 随「动态流 actor 派生成员」整条退役(原用于智能体 actor 排除)。
104
+
105
+ /** 合成/占位 actor 不得参与聚合(qoder #4) */
106
+ function isSyntheticActor(actor) {
107
+ return !actor || String(actor).trim().toLowerCase() === 'unknown';
108
+ }
109
+
110
+ /** #7:仅接受 http(s) URL 的动态,杜绝 javascript: 等伪协议流入前端渲染 */
111
+ function isSafeActivityUrl(url) {
112
+ return typeof url === 'string' && /^https?:\/\/\S+$/i.test(url);
113
+ }
114
+
115
+ /** 分支精确相等,或 title/branch 互为 ≥4 字子串(SPEC §3 模糊匹配规则) */
116
+ function fuzzyMatch(a, b) {
117
+ if (typeof a !== 'string' || typeof b !== 'string' || !a || !b) return false;
118
+ if (a === b) return true;
119
+ if (a.length >= 4 && b.includes(a)) return true;
120
+ if (b.length >= 4 && a.includes(b)) return true;
121
+ return false;
122
+ }
123
+
124
+ function activityMatchesTask(act, task) {
125
+ return (
126
+ fuzzyMatch(act.branch, task.branch) ||
127
+ fuzzyMatch(act.title, task.title) ||
128
+ fuzzyMatch(act.branch, task.title) ||
129
+ fuzzyMatch(act.title, task.branch)
130
+ );
131
+ }
132
+
133
+ /** 按成员谓词聚合动态统计:24h 提交数、7d 开放 PR 列表、最近动态时间 */
134
+ function memberActivityStats(activities, predicate, now) {
135
+ let todayCommits = 0;
136
+ let lastAct = null;
137
+ const openedPRs = [];
138
+ const mergedUrls = new Set();
139
+ for (const act of activities) {
140
+ if (!act || !predicate(act.actor)) continue;
141
+ const t = parseTs(act.occurredAt);
142
+ if (t !== null && (lastAct === null || t > lastAct)) lastAct = t;
143
+ const fresh = t !== null && now - t >= 0;
144
+ // 提交判定:feeds 词表 'commit';存量词表 commit_pushed 容错(过渡期 activities.json 两词表并存)
145
+ if (fresh && now - t <= DAY_MS && (act.type === 'commit_pushed' || act.type === 'commit')) todayCommits += 1;
146
+ if (fresh && now - t <= WEEK_MS) {
147
+ // 开放 PR 判定:'pr'(feeds 词表)视作开放 PR——feeds 统一后 opened/merged 同 url 经
148
+ // mergeActivities type|url 去重合并为一条,无法区分合并态,按开放计(近似口径);
149
+ // 存量 pr_opened 容错保留
150
+ if ((act.type === 'pr_opened' || act.type === 'pr') && isSafeActivityUrl(act.url)) openedPRs.push(act);
151
+ if (act.type === 'pr_merged' && isSafeActivityUrl(act.url)) mergedUrls.add(act.url); // 存量容错
152
+ }
153
+ }
154
+ const openPRs = openedPRs.filter((p) => !mergedUrls.has(p.url));
155
+ return { todayCommits, lastAct, openPRs };
156
+ }
157
+
158
+ /** progress 推导(SPEC §3 演示值):todo 0 / doing 无 PR 0.3 / doing 有 PR 0.6 / review 0.85 / done 1 */
159
+ function progressFor(task, openPRs) {
160
+ switch (task.status) {
161
+ case 'todo':
162
+ return 0;
163
+ case 'doing':
164
+ return openPRs.some((p) => activityMatchesTask(p, task)) ? 0.6 : 0.3;
165
+ case 'review':
166
+ return 0.85;
167
+ case 'done':
168
+ return 1;
169
+ default:
170
+ return 0;
171
+ }
172
+ }
173
+
174
+ function computeMembers(ctx) {
175
+ const now = Date.now();
176
+ const giteaCfg = ctx.config.gitea || {};
177
+ const staleWarnSec = Number(giteaCfg.staleWarnSec) > 0 ? Number(giteaCfg.staleWarnSec) : 14400;
178
+
179
+ const agents = store.loadAgents(ctx.agentsPath); // v2.5 起仅用于人类派生时的智能体 actor 排除,不再是成员来源
180
+ const { tasks } = store.loadTasks(ctx);
181
+ const activities = store.loadActivities(ctx);
182
+
183
+ // 全量开放 PR 列表(7d 内 pr_opened 或 feeds 'pr',且未被存量 pr_merged 命中):任务进度匹配用,
184
+ // 不限 actor——任务的 PR 可能由协作者开启,匹配看分支/标题而非作者。
185
+ // 'pr' 视作开放 PR(近似口径):feeds 词表统一后 opened/merged 同 url 合并为一条
186
+ // (mergeActivities type|url 去重),合并态不可辨;pr_merged 判定保留(存量容错)
187
+ const openedAll = [];
188
+ const mergedUrls = new Set();
189
+ for (const act of activities) {
190
+ if (!act || isSyntheticActor(act.actor)) continue;
191
+ const t = parseTs(act.occurredAt);
192
+ if (t === null || now - t < 0 || now - t > WEEK_MS) continue;
193
+ if ((act.type === 'pr_opened' || act.type === 'pr') && isSafeActivityUrl(act.url)) openedAll.push(act);
194
+ if (act.type === 'pr_merged' && isSafeActivityUrl(act.url)) mergedUrls.add(act.url);
195
+ }
196
+ const globalOpenPRs = openedAll.filter((p) => !mergedUrls.has(p.url));
197
+
198
+ const memberEntries = [];
199
+
200
+ // 「当前任务推导 + sinceUpdateSec + status + weekDone」统一入口(v1.2 起 agent 与两类 human 共用):
201
+ // current = 归领任务中 updatedAt 最新的未完成任务;human 条目 session 恒为 null。
202
+ // v1.4 修订(goose 真机验收 P1-2):活动锚点 = max(名下未完成任务中最新的 updatedAt, 最近一条
203
+ // Gitea 动态时间)——有在办任务时任务本身就是活动证据,刚派任务不再被陈旧 Gitea 动态拖成
204
+ // 「超时危险」;无任务成员维持纯 Gitea 锚点不变。lastActivityAt 响应字段同步用合并锚点。
205
+ function deriveTaskView(myTasks, lastAct, sess) {
206
+ const current = myTasks
207
+ .filter((t) => t.status !== 'done')
208
+ .sort((a, b) => String(b.updatedAt || '').localeCompare(String(a.updatedAt || '')))[0] || null;
209
+
210
+ const taskTs = current ? parseTs(current.updatedAt) : null;
211
+ let anchorTs = lastAct;
212
+ if (taskTs !== null && (anchorTs === null || taskTs > anchorTs)) anchorTs = taskTs;
213
+
214
+ const sinceUpdateSec = anchorTs !== null ? Math.max(0, Math.floor((now - anchorTs) / 1000)) : null;
215
+
216
+ const hasDoing = myTasks.some((t) => t.status === 'doing');
217
+ let status = 'idle';
218
+ if (hasDoing && sinceUpdateSec !== null && sinceUpdateSec > staleWarnSec) status = 'stale';
219
+ else if (hasDoing || (sess && sess.alive)) status = 'working';
220
+
221
+ const weekDone = myTasks.filter((t) => {
222
+ if (t.status !== 'done') return false;
223
+ const u = parseTs(t.updatedAt);
224
+ return u !== null && now - u >= 0 && now - u <= WEEK_MS;
225
+ }).length;
226
+
227
+ return {
228
+ status,
229
+ currentTask: current
230
+ ? {
231
+ id: current.id,
232
+ title: current.title,
233
+ status: current.status,
234
+ dueDate: typeof current.dueDate === 'string' ? current.dueDate : null, // v1.4:透传截止时间(历史数据缺字段回退 null)
235
+ priority: PRIORITIES.includes(current.priority) ? current.priority : 'medium', // v1.4:透传优先级(历史数据缺字段回退 medium)
236
+ ageSec: ageSec(now, current.updatedAt),
237
+ sinceUpdateSec,
238
+ progress: progressFor(current, globalOpenPRs),
239
+ }
240
+ : null,
241
+ weekDone,
242
+ lastActivityAt: anchorTs !== null ? new Date(anchorTs).toISOString() : null, // v1.4 修订:合并锚点
243
+ };
244
+ }
245
+
246
+ // v2.6 硅基成员泛化(业主 2026-10-20):桌面 agent 注册表四源并列——workbuddy/zcode/codex/
247
+ // opencode 各自从本机会话库派生(适配器复用 agentActivity,见 lib/desktopAgents.js)。
248
+ // 开关与路径沿用 config.agentActivity.sources 各源 enabled/root/dbPath;每源独立 try/catch,
249
+ // 单源失败该源缺席不拖垮。状态/任务推导沿用 deriveTaskView:源侧最近会话 active 视作 alive 会话。
250
+ const desktopMembers = collectDesktopMembers(ctx.config && ctx.config.agentActivity, {
251
+ now,
252
+ tasks,
253
+ deriveTaskView,
254
+ adapters: ctx.adapters, // 测试注入缝(v2.9.14):桌面源适配器覆盖,prod 恒缺省
255
+ });
256
+ memberEntries.push(...desktopMembers);
257
+ const desktopIds = new Set(desktopMembers.map((m) => String(m.id).toLowerCase()));
258
+
259
+ // 手工名册(v1.2):members.json 条目并入视图——无 Gitea 缓存/动态也出现;
260
+ // giteaLogin 命中动态 actor(小写精确相等)→ 归因其活动数据(todayCommits/openPrs/lastActivityAt)
261
+ const roster = ctx.membersPath ? store.loadMembers(ctx.membersPath) : [];
262
+ const claimedLogins = new Set(
263
+ roster
264
+ .map((m) => (m && typeof m.giteaLogin === 'string' ? m.giteaLogin.trim().toLowerCase() : ''))
265
+ .filter(Boolean)
266
+ );
267
+ for (const m of roster) {
268
+ // v2.6:与桌面派生成员 id 冲突的手工条目跳过(派生胜出:保活动/会话态,防前端重复 key)
269
+ if (desktopIds.has(String(m.id).toLowerCase())) continue;
270
+ const login = typeof m.giteaLogin === 'string' ? m.giteaLogin.trim() : '';
271
+ const stats = login
272
+ ? memberActivityStats(activities, (actor) => String(actor).toLowerCase() === login.toLowerCase(), now)
273
+ : { todayCommits: 0, lastAct: null, openPRs: [] };
274
+ // v1.2:手工条目同样按 memberId 归领任务,currentTask/status/weekDone 与 agent 同规则推导
275
+ const derived = deriveTaskView(
276
+ tasks.filter((t) => t.memberId === m.id),
277
+ stats.lastAct,
278
+ null
279
+ );
280
+ memberEntries.push({
281
+ id: m.id,
282
+ name: m.name,
283
+ kind: 'human',
284
+ manual: true,
285
+ role: typeof m.role === 'string' ? m.role : '',
286
+ status: derived.status,
287
+ currentTask: derived.currentTask,
288
+ lastActivityAt: derived.lastActivityAt, // v1.4 修订:max(任务 updatedAt, Gitea 动态)
289
+ todayCommits: stats.todayCommits,
290
+ openPrs: stats.openPRs.length,
291
+ weekDone: derived.weekDone,
292
+ session: null,
293
+ });
294
+ }
295
+
296
+ // 人类成员 = 手工名册 ∪ Gitea 成员缓存(已被手工名册 giteaLogin 认领的 login 不重复出现)。
297
+ // v2.9.1:动态流 actor 自动派生整条退役(业主指令「动态流 actor 派生的先不接入」)——
298
+ // 组织外/机器人账号(如忘忧、qianqi)不再因推过代码就长成成员;团队动态里仍按
299
+ // 未登记 actor 降级展示(中性图标+账号名),只是不入册。
300
+ // v2.9.2:gitea.ignoreLogins 忽略账号(默认 ["admin"])——管理员/机器人类组织账号不入册
301
+ // (业主拍板 admin 过滤);config.json 手改,大小写不敏感。
302
+ const knownAgentIds = new Set([...agents.map((a) => String(a.id).toLowerCase()), ...desktopIds]);
303
+ const ignoreLogins = new Set(
304
+ ((giteaCfg.ignoreLogins || [])).map((s) => String(s).trim().toLowerCase()).filter(Boolean)
305
+ );
306
+ const humans = new Map();
307
+ for (const h of store.loadGiteaMembers(ctx)) {
308
+ if (!h.id) continue;
309
+ const key = String(h.id).toLowerCase();
310
+ if (knownAgentIds.has(key)) continue;
311
+ if (ignoreLogins.has(key)) continue; // 忽略账号(admin 等非干活账号)
312
+ if (claimedLogins.has(key)) continue; // 手工条目已归因该 login,不再输出派生重复项
313
+ humans.set(key, { id: h.id, name: h.name || h.id, role: h.role || '' });
314
+ }
315
+
316
+ for (const h of humans.values()) {
317
+ const stats = memberActivityStats(activities, (actor) => String(actor).toLowerCase() === String(h.id).toLowerCase(), now);
318
+ // v1.2:Gitea 派生条目同样按 memberId 归领任务,推导规则与 agent 完全相同
319
+ const derived = deriveTaskView(
320
+ tasks.filter((t) => t.memberId === h.id),
321
+ stats.lastAct,
322
+ null
323
+ );
324
+ memberEntries.push({
325
+ id: h.id,
326
+ name: h.name,
327
+ kind: 'human',
328
+ manual: false,
329
+ role: h.role,
330
+ status: derived.status,
331
+ currentTask: derived.currentTask,
332
+ lastActivityAt: derived.lastActivityAt, // v1.4 修订:max(任务 updatedAt, Gitea 动态)
333
+ todayCommits: stats.todayCommits,
334
+ openPrs: stats.openPRs.length,
335
+ weekDone: derived.weekDone,
336
+ session: null,
337
+ });
338
+ }
339
+
340
+ // v2.7 成员日报联动:diaryToday = 该成员名下「进行中」(内置 doing 列)任务当天(服务器本地
341
+ // 今天)是否有日报——供前端标「今日未填」。currentTask/最近产出口径一概不动,仅增此字段。
342
+ // 归领规则与各条目推导路径一致:agent 类条目(桌面源)= agentId 或 memberId 命中;human 类
343
+ // 条目(手工名册 ∪ Gitea 派生)= memberId 命中。
344
+ const withDiaryToday = diaryMod.taskIdsWithDiaryOn(ctx, diaryMod.localYmd());
345
+ for (const entry of memberEntries) {
346
+ const isAgentLike = entry.kind === 'agent';
347
+ const hasDiary = tasks.some((t) => {
348
+ const owned = isAgentLike
349
+ ? t.agentId === entry.id || t.memberId === entry.id
350
+ : t.memberId === entry.id;
351
+ return owned && t.status === 'doing' && withDiaryToday.has(t.id);
352
+ });
353
+ entry.diaryToday = hasDiary;
354
+ }
355
+
356
+ return memberEntries;
357
+ }
358
+
359
+ function registerOverviewRoutes(router, ctx) {
360
+ router.add('GET', '/api/overview', (c) => {
361
+ sendJSON(c.res, 200, computeOverview(ctx));
362
+ });
363
+ router.add('GET', '/api/members', (c) => {
364
+ sendJSON(c.res, 200, computeMembers(ctx));
365
+ });
366
+ // 桌面源健康探针(2026-11-03 评审尾巴):逐源 ok/detail 外显,治「单源故障静默缺席无信号」。
367
+ // 只读轻探(limit:1),与 /api/agent-activity 的 sources[] 相互独立(那条链路本就有健康徽标)
368
+ router.add('GET', '/api/members/source-health', (c) => {
369
+ sendJSON(c.res, 200, collectDesktopSourceHealth(ctx.config && ctx.config.agentActivity, {
370
+ now: Date.now(),
371
+ adapters: ctx.adapters, // 测试注入缝(同 collectDesktopMembers)
372
+ }));
373
+ });
374
+ }
375
+
376
+ module.exports = { registerOverviewRoutes, computeOverview, computeMembers };
@@ -0,0 +1,148 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * postmortem.js — v2.9.28 任务复盘闭环(done 时刻的确定性蒸馏)
5
+ *
6
+ * 「任务验收完成 ≠ 经验沉淀」——本模块把任务关联的证据(会话派工词/提交/日报)蒸馏为
7
+ * 一页复盘数据:数字(会话/提交/日报/跨度)+ 证据列表(当时怎么派工的、做了哪些提交、
8
+ * 哪天留了痕)。确定性聚合零 LLM(引擎蒸馏版待观察窗后评估)。
9
+ *
10
+ * 证据来源(全部只读):
11
+ * - session 形态 artifacts(挂接的会话)→ ref 回读派工词(getDispatchPrompt 120s 缓存兜底)
12
+ * - commit/pr 形态 artifacts → repo/title/at(归因或手动挂接一视同仁)
13
+ * - diary.json → 本任务日报(日期+首行摘录)
14
+ * 跨度口径:证据时间戳(会话 lastActive / 提交 at / 日报 updatedAt)min..max → 天数;
15
+ * 证据为空 → spans 全 null(诚实空态,不拿任务 createdAt 充数)。
16
+ */
17
+
18
+ const { HttpError, sendJSON } = require('./router');
19
+ const store = require('./store');
20
+ const at = require('./agentTranscript');
21
+ const diaryMod = require('./diary');
22
+
23
+ const DAY_MS = 24 * 3600 * 1000;
24
+ const EVIDENCE_CAP = 8; // 每类证据列表最多 8 条(复盘是一页纸不是流水账)
25
+ const DISPATCH_CAP = 160;
26
+ const DIARY_EXCERPT_CAP = 80;
27
+
28
+ function msOf(v) {
29
+ const t = Date.parse(String(v || ''));
30
+ return Number.isFinite(t) ? t : null;
31
+ }
32
+
33
+ /**
34
+ * buildPostmortem(ctx, taskId, opts) → 复盘对象;任务不存在 404。
35
+ * @param {{tasksPath:string, diaryPath:string, config:object}} ctx
36
+ * @param {{now?:number}} opts
37
+ */
38
+ function buildPostmortem(ctx, taskId, opts) {
39
+ const o = opts || {};
40
+ const now = Number.isFinite(o.now) ? o.now : Date.now();
41
+ const data = store.loadTasks(ctx);
42
+ const task = (Array.isArray(data.tasks) ? data.tasks : []).find((t) => t && t.id === taskId);
43
+ if (!task) throw new HttpError(404, 'TASK_NOT_FOUND', '任务不存在');
44
+
45
+ const arts = Array.isArray(task.artifacts) ? task.artifacts : [];
46
+ const commits = [];
47
+ const dispatchWords = [];
48
+ const seenRefs = new Set();
49
+ const times = [];
50
+
51
+ for (const a of arts) {
52
+ if (!a) continue;
53
+ if (a.kind === 'commit' || a.kind === 'pr') {
54
+ commits.push({ kind: a.kind, repo: a.repo || null, title: String(a.title || ''), at: a.at || null });
55
+ const t = msOf(a.at);
56
+ if (t != null) times.push(t);
57
+ } else if (a.kind === 'session' && typeof a.sessionRef === 'string' && !seenRefs.has(a.sessionRef)) {
58
+ seenRefs.add(a.sessionRef);
59
+ let dispatchText = '';
60
+ try {
61
+ const d = at.getDispatchPrompt(ctx.config, a.sessionRef, { now });
62
+ if (d && d.found) dispatchText = String(d.text || '');
63
+ } catch (e) { /* 会话消失/源故障:降级为仅标题 */ }
64
+ dispatchWords.push({
65
+ agent: null, // ref 解码可得源——按需再算,保持 payload 精简
66
+ ref: a.sessionRef,
67
+ title: String(a.title || ''),
68
+ dispatchText: dispatchText.length > DISPATCH_CAP ? dispatchText.slice(0, DISPATCH_CAP) : dispatchText,
69
+ at: a.at || null,
70
+ });
71
+ const t = msOf(a.at);
72
+ if (t != null) times.push(t);
73
+ }
74
+ }
75
+ commits.sort((x, y) => String(y.at || '').localeCompare(String(x.at || '')));
76
+
77
+ let diaries = [];
78
+ try {
79
+ diaries = diaryMod
80
+ .loadDiaries({ diaryPath: ctx.diaryPath })
81
+ .filter((d) => d && d.taskId === taskId)
82
+ .sort((x, y) => String(y.date || '').localeCompare(String(x.date || '')))
83
+ .slice(0, EVIDENCE_CAP)
84
+ .map((d) => ({
85
+ date: d.date,
86
+ excerpt: String(d.content || '').replace(/\s+/g, ' ').slice(0, DIARY_EXCERPT_CAP),
87
+ updatedAt: d.updatedAt || null,
88
+ }));
89
+ for (const d of diaries) {
90
+ const t = msOf(d.updatedAt);
91
+ if (t != null) times.push(t);
92
+ }
93
+ } catch (e) { /* diary 缺失:日报计数 0 */ }
94
+
95
+ // 补充证据时间:任务创建/完成(有证据才有跨度意义,但完成时刻参与 min/max 不虚增下限——
96
+ // 只在已有证据时并入,避免「创建即 0 天」的空任务也出跨度)
97
+ if (times.length > 0) {
98
+ const doneMs = msOf(task.completedAt);
99
+ if (doneMs != null) times.push(doneMs);
100
+ }
101
+
102
+ let span = { firstAt: null, lastAt: null, days: null };
103
+ if (times.length > 0) {
104
+ const min = Math.min(...times);
105
+ const max = Math.max(...times);
106
+ span = {
107
+ firstAt: new Date(min).toISOString(),
108
+ lastAt: new Date(max).toISOString(),
109
+ days: Math.round((max - min) / DAY_MS),
110
+ };
111
+ }
112
+
113
+ return {
114
+ task: {
115
+ id: task.id,
116
+ title: task.title || '',
117
+ status: task.status || '',
118
+ completedAt: task.completedAt || null,
119
+ acceptorId: task.acceptorId || null,
120
+ },
121
+ counts: {
122
+ commits: commits.length,
123
+ prs: commits.filter((c) => c.kind === 'pr').length,
124
+ sessions: dispatchWords.length,
125
+ diaries: diaries.length,
126
+ },
127
+ span,
128
+ evidence: {
129
+ dispatchWords: dispatchWords.slice(0, EVIDENCE_CAP),
130
+ commits: commits.slice(0, EVIDENCE_CAP),
131
+ diaries,
132
+ },
133
+ generatedAt: new Date(now).toISOString(),
134
+ };
135
+ }
136
+
137
+ /** 路由挂载:GET /api/tasks/:id/postmortem(appAssembler 任务路由之后) */
138
+ function registerPostmortemRoute(router, ctx) {
139
+ router.add('GET', '/api/tasks/:id/postmortem', (c) => {
140
+ sendJSON(
141
+ c.res,
142
+ 200,
143
+ buildPostmortem({ tasksPath: ctx.tasksPath, diaryPath: ctx.diaryPath, config: ctx.config }, c.params.id, {})
144
+ );
145
+ });
146
+ }
147
+
148
+ module.exports = { buildPostmortem, registerPostmortemRoute, EVIDENCE_CAP };
@@ -0,0 +1,134 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * radarIgnore.js — 任务雷达的"别再回来"名单(v2.9.63)
5
+ *
6
+ * 背景:钉钉听记同步是**拉取式**的——删掉一条纪要后本地没了记录,下次同步会当成新纪要
7
+ * 重新拉回来并重新分析,收件箱候选于是"删了又出现"。这里给两条闸:
8
+ * ① 墓碑(tombstone):删除纪要时记下 id,同步时直接跳过;
9
+ * ② 规则(rules):关键词 / 标题片段匹配就跳过,管"以后同类也别进来"。
10
+ *
11
+ * 数据:`<base>/data/radar-ignore.json` —— { messages: {id:{title,at}}, rules:{keywords[],titles[]} }
12
+ * 只在拉取/分析入口判一次;不参与脱敏(内容只有标题与用户自己填的词)。
13
+ */
14
+
15
+ const path = require('node:path');
16
+ const store = require('./store');
17
+ const { HttpError, sendJSON } = require('./router');
18
+
19
+ const MAX_RULES = 50;
20
+ const MAX_RULE_LEN = 60;
21
+
22
+ function fileOf(ctx) {
23
+ return path.join(ctx.dataDir, 'radar-ignore.json');
24
+ }
25
+
26
+ function load(ctx) {
27
+ const d = store.readJSON(fileOf(ctx), null);
28
+ const o = store.isPlainObject(d) ? d : {};
29
+ const rules = store.isPlainObject(o.rules) ? o.rules : {};
30
+ const clean = (arr) => (Array.isArray(arr) ? arr.map((x) => String(x).trim()).filter(Boolean).slice(0, MAX_RULES) : []);
31
+ return {
32
+ messages: store.isPlainObject(o.messages) ? o.messages : {},
33
+ rules: { keywords: clean(rules.keywords), titles: clean(rules.titles) },
34
+ };
35
+ }
36
+
37
+ function save(ctx, data) {
38
+ store.writeJSON(fileOf(ctx), data);
39
+ }
40
+
41
+ /** 规则命中判定:标题/正文前 2000 字里包含即算(大小写不敏感) */
42
+ function matchRule(msg, rules) {
43
+ if (!msg || !rules) return null;
44
+ const title = String(msg.title || '');
45
+ const hay = `${title}\n${String(msg.content || '').slice(0, 2000)}`.toLowerCase();
46
+ for (const k of rules.keywords || []) {
47
+ if (k && hay.includes(String(k).toLowerCase())) return `关键词「${k}」`;
48
+ }
49
+ for (const k of rules.titles || []) {
50
+ if (k && title.includes(String(k))) return `标题包含「${k}」`;
51
+ }
52
+ return null;
53
+ }
54
+
55
+ /** 是否该跳过:返回原因字符串(跳过)或 null(正常处理) */
56
+ function ignoredReason(ctx, input) {
57
+ const data = load(ctx);
58
+ const id = input && input.id;
59
+ const msg = input && input.msg;
60
+ if (id && data.messages[id]) return '已删除过的纪要(忽略名单)';
61
+ const hit = matchRule(msg, data.rules);
62
+ return hit || null;
63
+ }
64
+
65
+ function addTombstone(ctx, id, title) {
66
+ const data = load(ctx);
67
+ if (!id) return data;
68
+ data.messages[String(id)] = { title: String(title || '').slice(0, 120), at: new Date().toISOString() };
69
+ save(ctx, data);
70
+ return data;
71
+ }
72
+
73
+ function removeTombstone(ctx, id) {
74
+ const data = load(ctx);
75
+ delete data.messages[String(id)];
76
+ save(ctx, data);
77
+ return data;
78
+ }
79
+
80
+ /** 设置规则(整体替换;逐条裁剪长度与数量) */
81
+ function setRules(ctx, rules) {
82
+ const data = load(ctx);
83
+ const clamp = (arr) => (Array.isArray(arr)
84
+ ? arr.map((x) => String(x).trim().slice(0, MAX_RULE_LEN)).filter(Boolean).slice(0, MAX_RULES)
85
+ : []);
86
+ data.rules = { keywords: clamp(rules && rules.keywords), titles: clamp(rules && rules.titles) };
87
+ save(ctx, data);
88
+ return data;
89
+ }
90
+
91
+ function view(ctx) {
92
+ const data = load(ctx);
93
+ const messages = Object.entries(data.messages)
94
+ .map(([id, v]) => ({ id, title: (v && v.title) || '', at: (v && v.at) || null }))
95
+ .sort((a, b) => String(b.at || '').localeCompare(String(a.at || '')))
96
+ .slice(0, 200);
97
+ return { messages, messageCount: Object.keys(data.messages).length, rules: data.rules };
98
+ }
99
+
100
+ function registerRadarIgnoreRoutes(router, ctx) {
101
+ router.add('GET', '/api/radar/ignore', (c) => {
102
+ sendJSON(c.res, 200, view(ctx));
103
+ });
104
+
105
+ router.add('POST', '/api/radar/ignore', (c) => {
106
+ const body = c.body || {};
107
+ if (!store.isPlainObject(body.rules)) throw new HttpError(400, 'RADAR_IGNORE_INVALID', 'rules 必须为对象');
108
+ for (const k of ['keywords', 'titles']) {
109
+ const v = body.rules[k];
110
+ if (v !== undefined && (!Array.isArray(v) || v.some((x) => typeof x !== 'string'))) {
111
+ throw new HttpError(400, 'RADAR_IGNORE_INVALID', `rules.${k} 必须为字符串数组`);
112
+ }
113
+ }
114
+ setRules(ctx, body.rules);
115
+ sendJSON(c.res, 200, view(ctx));
116
+ });
117
+
118
+ router.add('DELETE', '/api/radar/ignore/messages/:id', (c) => {
119
+ const data = removeTombstone(ctx, c.params.id);
120
+ sendJSON(c.res, 200, { ok: true, remaining: Object.keys(data.messages).length });
121
+ });
122
+ }
123
+
124
+ module.exports = {
125
+ load,
126
+ save,
127
+ matchRule,
128
+ ignoredReason,
129
+ addTombstone,
130
+ removeTombstone,
131
+ setRules,
132
+ view,
133
+ registerRadarIgnoreRoutes,
134
+ };