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.
- package/LICENSE +21 -0
- package/README.md +128 -2
- package/README.zh-CN.md +130 -0
- package/assets/icon.svg +9 -0
- package/cordis.patch.yml +7 -0
- package/lib/agentActivity.js +1180 -0
- package/lib/agentContext.js +146 -0
- package/lib/agentTranscript.js +1398 -0
- package/lib/analyze.js +625 -0
- package/lib/attribute.js +205 -0
- package/lib/backup.js +366 -0
- package/lib/desktopAgents.js +123 -0
- package/lib/diary.js +333 -0
- package/lib/dingtalk.js +412 -0
- package/lib/feishu.js +580 -0
- package/lib/giteaClient.js +810 -0
- package/lib/giteeClient.js +372 -0
- package/lib/githubClient.js +361 -0
- package/lib/heatmap.js +99 -0
- package/lib/imNotify.js +378 -0
- package/lib/inbox.js +438 -0
- package/lib/instanceLock.js +122 -0
- package/lib/jobs.js +56 -0
- package/lib/learn.js +1388 -0
- package/lib/learnImport.js +283 -0
- package/lib/learnSeeds.js +97 -0
- package/lib/learnSeedsAiEng.js +77 -0
- package/lib/mcpCore.js +135 -0
- package/lib/members.js +160 -0
- package/lib/migration.js +403 -0
- package/lib/overview.js +376 -0
- package/lib/postmortem.js +148 -0
- package/lib/radarIgnore.js +134 -0
- package/lib/redact.js +76 -0
- package/lib/router.js +246 -0
- package/lib/routes-gitea.js +262 -0
- package/lib/routes-setup.js +40 -0
- package/lib/scorecard.js +111 -0
- package/lib/sessionRef.js +227 -0
- package/lib/sessionSnapshot.js +67 -0
- package/lib/sessionSuggest.js +186 -0
- package/lib/settings.js +783 -0
- package/lib/setupCheck.js +330 -0
- package/lib/ssrfGuard.js +145 -0
- package/lib/store.js +564 -0
- package/lib/storeDb.js +418 -0
- package/lib/taskEvents.js +243 -0
- package/lib/webhookOut.js +125 -0
- package/lib/weekly.js +439 -0
- package/lib/workSearch.js +220 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +46 -4
- package/plugin/adapter.js +157 -0
- package/plugin/client.js +282 -0
- package/plugin/index.mjs +116 -0
- package/plugin/static.js +99 -0
- package/scripts/backup-data.js +41 -0
- package/scripts/mcp-server.mjs +68 -0
- package/scripts/migrate-data.js +301 -0
- package/scripts/migrate-storage.js +47 -0
- package/scripts/seed-demo.js +200 -0
- package/scripts/write-agent-context.js +43 -0
- package/test/helpers/appAssembler.js +1078 -0
- package/web/client/fde-client.js +292 -0
- package/web/css/app.css +1510 -0
- package/web/index.html +69 -0
- package/web/js/api.js +72 -0
- package/web/js/app.js +313 -0
- package/web/js/icons.js +48 -0
- package/web/js/mock.js +1150 -0
- package/web/js/state.js +7 -0
- package/web/js/ui.js +276 -0
- package/web/js/views/activity.js +410 -0
- package/web/js/views/agents.js +892 -0
- package/web/js/views/board.js +1656 -0
- package/web/js/views/learn.js +530 -0
- package/web/js/views/members.js +344 -0
- package/web/js/views/onboarding.js +103 -0
- package/web/js/views/overview.js +508 -0
- package/web/js/views/radar.js +1359 -0
- package/web/js/views/search.js +149 -0
- package/web/js/views/settings.js +1351 -0
- package/web/js/views/topology.js +471 -0
- package/web/mock.json +2363 -0
package/web/js/mock.js
ADDED
|
@@ -0,0 +1,1150 @@
|
|
|
1
|
+
// mock 后端:加载 web/mock.json 到内存,按 §3 契约处理全部 /api/* 请求(零出网)
|
|
2
|
+
// 写操作直接改内存副本,便于在 mock 模式下完整演示增删改与错误分支
|
|
3
|
+
import { ApiError, registerMock } from './api.js';
|
|
4
|
+
|
|
5
|
+
let db = null;
|
|
6
|
+
const bootMs = Date.now();
|
|
7
|
+
// v1.7:completedAt(任务完成时间)/ decidedAt(候选决定时间)一并按锚点平移,保证 30 天统计窗口演示数据恒新鲜
|
|
8
|
+
const DATE_KEY = /^(createdAt|updatedAt|occurredAt|fetchedAt|startedAt|lastPollAt|lastActivityAt|completedAt|decidedAt)$/;
|
|
9
|
+
|
|
10
|
+
const clone = (v) => JSON.parse(JSON.stringify(v));
|
|
11
|
+
const nowIso = () => new Date().toISOString();
|
|
12
|
+
const genTaskId = () => `t-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`;
|
|
13
|
+
const genColId = () => `col-${Math.random().toString(16).slice(2, 4)}`;
|
|
14
|
+
|
|
15
|
+
// ---- dueDate / priority 契约(v1.4)----
|
|
16
|
+
const YMD_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
17
|
+
const PRIORITIES = ['high', 'medium', 'low'];
|
|
18
|
+
const p2 = (n) => String(n).padStart(2, '0');
|
|
19
|
+
const localYMD = (d) => `${d.getFullYear()}-${p2(d.getMonth() + 1)}-${p2(d.getDate())}`;
|
|
20
|
+
// 手工拆解构造(不用 Date.parse):纯日期串按 UTC 解析会在东八区偏移一天
|
|
21
|
+
const parseYMD = (s) => {
|
|
22
|
+
if (typeof s !== 'string' || !YMD_RE.test(s)) return null;
|
|
23
|
+
const [y, m, d] = s.split('-').map(Number);
|
|
24
|
+
const dt = new Date(y, m - 1, d);
|
|
25
|
+
return (dt.getFullYear() === y && dt.getMonth() === m - 1 && dt.getDate() === d) ? dt : null;
|
|
26
|
+
};
|
|
27
|
+
const today0 = () => { const d = new Date(); d.setHours(0, 0, 0, 0); return d; };
|
|
28
|
+
// dueDate 距今天的天数(负=逾期);非法输入返回 null
|
|
29
|
+
const dueDayDiff = (ymd) => {
|
|
30
|
+
const d = parseYMD(ymd);
|
|
31
|
+
return d ? Math.round((d.getTime() - today0().getTime()) / 86400000) : null;
|
|
32
|
+
};
|
|
33
|
+
const validDueDate = (v) => v === null || v === undefined || parseYMD(v) !== null;
|
|
34
|
+
|
|
35
|
+
function shiftDates(o, delta) {
|
|
36
|
+
if (Array.isArray(o)) { o.forEach((x) => shiftDates(x, delta)); return; }
|
|
37
|
+
if (o && typeof o === 'object') {
|
|
38
|
+
for (const k of Object.keys(o)) {
|
|
39
|
+
const v = o[k];
|
|
40
|
+
if (typeof v === 'string' && DATE_KEY.test(k) && /^\d{4}-\d{2}-\d{2}T/.test(v)) {
|
|
41
|
+
const t = Date.parse(v);
|
|
42
|
+
if (!isNaN(t)) o[k] = new Date(t + delta).toISOString();
|
|
43
|
+
} else {
|
|
44
|
+
shiftDates(v, delta);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function load() {
|
|
51
|
+
if (db) return db;
|
|
52
|
+
const url = new URL('../mock.json', import.meta.url);
|
|
53
|
+
let text;
|
|
54
|
+
if (url.protocol === 'file:') {
|
|
55
|
+
// Node 直测用(浏览器永不走此分支)
|
|
56
|
+
text = (await import('node:fs')).readFileSync(url, 'utf8');
|
|
57
|
+
} else {
|
|
58
|
+
const res = await fetch(url);
|
|
59
|
+
if (!res.ok) throw new Error(`mock.json 加载失败(HTTP ${res.status})`);
|
|
60
|
+
text = await res.text();
|
|
61
|
+
}
|
|
62
|
+
db = JSON.parse(text);
|
|
63
|
+
const base = Date.parse((db.overview && db.overview.gitea && db.overview.gitea.lastPollAt) || '') || 0;
|
|
64
|
+
const delta = Math.max(0, Date.now() - base);
|
|
65
|
+
if (delta > 0) shiftDates(db, delta);
|
|
66
|
+
// dueDate 以 dueAnchor 为书写基准日,加载时按「天数差不变」平移到今天——
|
|
67
|
+
// 逾期/今天到期/明天到期等徽标状态不随真实日期流逝而失效(演示数据恒可用)
|
|
68
|
+
const anchor = parseYMD(db.dueAnchor);
|
|
69
|
+
for (const t of db.tasks || []) {
|
|
70
|
+
if (!PRIORITIES.includes(t.priority)) t.priority = 'medium'; // 契约:缺省 medium
|
|
71
|
+
// v1.7:events[].at 键名太通用('at' 会误伤听记 speakerSegments),不进 DATE_KEY,这里按同一 delta 平移
|
|
72
|
+
for (const ev of t.events || []) {
|
|
73
|
+
const ts = Date.parse(ev.at);
|
|
74
|
+
if (!isNaN(ts)) ev.at = new Date(ts + delta).toISOString();
|
|
75
|
+
}
|
|
76
|
+
// 叙事线第一批:artifacts[].at 同 events 口径平移,保证演示数据时间恒新鲜
|
|
77
|
+
for (const art of t.artifacts || []) {
|
|
78
|
+
const ts = Date.parse(art.at);
|
|
79
|
+
if (!isNaN(ts)) art.at = new Date(ts + delta).toISOString();
|
|
80
|
+
}
|
|
81
|
+
const td = parseYMD(t.dueDate);
|
|
82
|
+
if (!td) continue;
|
|
83
|
+
if (!anchor) continue;
|
|
84
|
+
const days = Math.round((td.getTime() - anchor.getTime()) / 86400000);
|
|
85
|
+
const shifted = today0();
|
|
86
|
+
shifted.setDate(shifted.getDate() + days);
|
|
87
|
+
t.dueDate = localYMD(shifted);
|
|
88
|
+
}
|
|
89
|
+
// 本批任务日报:diaries[].date 以 diaryAnchor 为书写基准日,按「天数差不变」平移到今天——
|
|
90
|
+
// 「今天/昨天/三天前」的演示语义不随真实日期流逝失效(与 dueAnchor 同一口径)。
|
|
91
|
+
// 条目的 updatedAt 是 ISO 时间戳,已被上方 shiftDates 按 DATE_KEY 平移,无需在此处理
|
|
92
|
+
const diaryAnchor = parseYMD(db.diaryAnchor);
|
|
93
|
+
if (diaryAnchor) {
|
|
94
|
+
for (const list of Object.values(db.diaries || {})) {
|
|
95
|
+
if (!Array.isArray(list)) continue;
|
|
96
|
+
for (const e of list) {
|
|
97
|
+
const ed = parseYMD(e && e.date);
|
|
98
|
+
if (!ed) continue;
|
|
99
|
+
const days = Math.round((ed.getTime() - diaryAnchor.getTime()) / 86400000);
|
|
100
|
+
const shifted = today0();
|
|
101
|
+
shifted.setDate(shifted.getDate() + days);
|
|
102
|
+
e.date = localYMD(shifted);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// v2.3 智能体动态演示数据:startedAgoSec/lastActiveAgoSec 同口径一次性换算(相对本页会话锚定),
|
|
107
|
+
// 保证「N 分钟前」相对时间与 preview 截断演示不随真实日期流逝而失效
|
|
108
|
+
for (const rec of ((db.agentActivity && db.agentActivity.items) || [])) {
|
|
109
|
+
if (!rec.startedAt && rec.startedAgoSec != null) {
|
|
110
|
+
rec.startedAt = new Date(Date.now() - rec.startedAgoSec * 1000).toISOString();
|
|
111
|
+
}
|
|
112
|
+
if (!rec.lastActiveAt && rec.lastActiveAgoSec != null) {
|
|
113
|
+
rec.lastActiveAt = new Date(Date.now() - rec.lastActiveAgoSec * 1000).toISOString();
|
|
114
|
+
}
|
|
115
|
+
delete rec.startedAgoSec;
|
|
116
|
+
delete rec.lastActiveAgoSec;
|
|
117
|
+
}
|
|
118
|
+
// v2.3 会话列表/全文(SPEC-READER §3.1/§3.2 mock 契约):相对时间换算 + ref 签发 + 转录 ts/seq 补齐 +
|
|
119
|
+
// 长转录生成 + kind:"session" 成果样例注入。ref = base64url(JSON{s,k,v})(D1),mock 与真实后端同构
|
|
120
|
+
for (const src of Object.keys(db.agentSessions || {})) {
|
|
121
|
+
for (const rec of db.agentSessions[src]) {
|
|
122
|
+
if (!rec.startedAt && rec.startedAgoSec != null) {
|
|
123
|
+
rec.startedAt = new Date(Date.now() - rec.startedAgoSec * 1000).toISOString();
|
|
124
|
+
}
|
|
125
|
+
if (!rec.lastActiveAt && rec.lastActiveAgoSec != null) {
|
|
126
|
+
rec.lastActiveAt = new Date(Date.now() - rec.lastActiveAgoSec * 1000).toISOString();
|
|
127
|
+
}
|
|
128
|
+
delete rec.startedAgoSec;
|
|
129
|
+
delete rec.lastActiveAgoSec;
|
|
130
|
+
rec.ref = signRef(src, rec.id);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// 静态转录补 ts/seq:ts 按 startedAt 起每条 +45s 递增(startedAgoSec 已换算,时间轴观感成立即可)
|
|
134
|
+
for (const [sid, tr] of Object.entries(db.agentTranscripts || {})) {
|
|
135
|
+
let startMs = 0;
|
|
136
|
+
for (const src of Object.keys(db.agentSessions || {})) {
|
|
137
|
+
const rec = (db.agentSessions[src] || []).find((x) => x.id === sid);
|
|
138
|
+
if (rec) { startMs = Date.parse(rec.startedAt); break; }
|
|
139
|
+
}
|
|
140
|
+
if (!startMs) startMs = Date.now() - 3600 * 1000;
|
|
141
|
+
(tr.messages || []).forEach((msg, i) => {
|
|
142
|
+
msg.seq = i + 1;
|
|
143
|
+
msg.ts = new Date(startMs + i * 45000).toISOString();
|
|
144
|
+
if (!('tool' in msg)) msg.tool = null;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
buildLongTranscript(db); // zc-long:855 条 user/assistant/tool 交错(阅读器懒渲染验收样例)
|
|
148
|
+
injectSessionArtifact(db); // 「接入 SSO 登录」任务预置一条 kind:"session" 成果(看板会话徽标演示)
|
|
149
|
+
return db;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ---- v2.3 会话 mock 工具 ----
|
|
153
|
+
// base64url:浏览器/Node 通用走 btoa/atob + UTF-8 桥(escape/unescape 为引擎级内置,零依赖)
|
|
154
|
+
const b64urlEnc = (s) => btoa(unescape(encodeURIComponent(s))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
155
|
+
const b64urlDec = (s) => decodeURIComponent(escape(atob(String(s).replace(/-/g, '+').replace(/_/g, '/'))));
|
|
156
|
+
// D1:ref = base64url(JSON{s:源 id, k:locator 种类, v:locator 对象}),不透明串
|
|
157
|
+
const signRef = (src, id) => b64urlEnc(JSON.stringify({ s: src, k: 'session', v: { id } }));
|
|
158
|
+
|
|
159
|
+
// ref 解析(§3.3 校验的 mock 简化版:解码/源白名单/k/locator 存在性四闸),通过返回 {src, rec}
|
|
160
|
+
function resolveSessionRef(ref) {
|
|
161
|
+
const d = db;
|
|
162
|
+
if (!d || !d.agentSessions) return null;
|
|
163
|
+
let obj = null;
|
|
164
|
+
try { obj = JSON.parse(b64urlDec(ref)); } catch { return null; }
|
|
165
|
+
if (!obj || typeof obj !== 'object' || typeof obj.s !== 'string' || obj.k !== 'session') return null;
|
|
166
|
+
if (!Object.prototype.hasOwnProperty.call(d.agentSessions, obj.s)) return null;
|
|
167
|
+
const id = obj.v && obj.v.id;
|
|
168
|
+
const rec = (d.agentSessions[obj.s] || []).find((x) => x.id === id);
|
|
169
|
+
return rec ? { src: obj.s, rec } : null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// 长转录样例:zc-long 固定 855 条,user/assistant/tool 交错(每 6 条一轮:
|
|
173
|
+
// 用户指令 → 助手拆解 → 工具读 → 助手结论 → 工具改/跑 → 工具状态汇报),少量 error/running 状态点缀
|
|
174
|
+
function buildLongTranscript(d) {
|
|
175
|
+
if (!d.agentSessions || !d.agentSessions.zcode) return;
|
|
176
|
+
const rec = d.agentSessions.zcode.find((x) => x.id === 'zc-long');
|
|
177
|
+
if (!rec || (d.agentTranscripts && d.agentTranscripts['zc-long'])) return;
|
|
178
|
+
d.agentTranscripts = d.agentTranscripts || {};
|
|
179
|
+
const TOOLS = ['read_file', 'grep', 'edit_file', 'run_tests'];
|
|
180
|
+
const msgs = [];
|
|
181
|
+
const total = 855;
|
|
182
|
+
for (let i = 0; i < total; i++) {
|
|
183
|
+
if (i === total - 1) {
|
|
184
|
+
// 收尾消息固定 running 工具态(阅读器「进行中」徽标演示),不随 phase 轮换
|
|
185
|
+
msgs.push({ role: 'tool', tool: { name: 'run_tests', status: 'running' }, text: '全量回归执行中…(阅读器懒渲染样例:最后一条保持 running 态演示)' });
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const phase = i % 6;
|
|
189
|
+
if (phase === 0) {
|
|
190
|
+
msgs.push({ role: 'user', text: `第 ${Math.floor(i / 6) + 1} 轮:继续对照确认稿核查动态面板,本轮先处理上一轮遗留的 ${['徽标透明度', '行距偏差', '轮询节流', '空态文案', '滚动抖动', '转义遗漏'][i % 6]}。` });
|
|
191
|
+
} else if (phase === 1) {
|
|
192
|
+
msgs.push({ role: 'assistant', text: `收到。第 ${i + 1} 步:先读现状定位差异来源,再决定改样式层还是渲染层;改动会控制在单文件内,避免波及七视图。` });
|
|
193
|
+
} else if (phase === 2) {
|
|
194
|
+
msgs.push({ role: 'tool', tool: { name: TOOLS[i % 2], status: 'ok' }, text: `web/js/views/agents.js · 定位到行 ${320 + (i % 300)}\n确认差异:${['徽标底透明度 .16→.13', '组头字重 600→500', '行高 1.45→1.5', '空态图标规格 22→20'][i % 4]}` });
|
|
195
|
+
} else if (phase === 3) {
|
|
196
|
+
msgs.push({ role: 'assistant', text: `定位完成(消息 ${i + 1}/855)。差异在样式层,改一行即可;顺手核对该选择器无其他视图复用,零波及。` });
|
|
197
|
+
} else if (phase === 4) {
|
|
198
|
+
const bad = i % 61 === 59;
|
|
199
|
+
msgs.push({ role: 'tool', tool: { name: bad ? 'run_tests' : TOOLS[2 + (i % 2)], status: bad ? 'error' : 'ok' }, text: bad ? 'node --test 1 项失败:badge 透明度断言期望 .13 实际 .16\n→ 上一步编辑未保存(编辑器缓冲),已重新写入' : `web/css/app.css +1 -1(消息 ${i + 1})\n改动落地:视觉回归通过` });
|
|
200
|
+
} else {
|
|
201
|
+
msgs.push({ role: 'tool', tool: { name: 'run_tests', status: 'ok' }, text: `node --check 4 文件通过 · node --test ${240 + (i % 10)} 项全绿(消息 ${i + 1})` });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// ts 按 startedAt→lastActiveAt 区间线性铺满,seq 升序
|
|
205
|
+
const startMs = Date.parse(rec.startedAt);
|
|
206
|
+
const step = Math.max(1, (Date.parse(rec.lastActiveAt) - startMs) / total);
|
|
207
|
+
msgs.forEach((m, i) => {
|
|
208
|
+
m.seq = i + 1;
|
|
209
|
+
m.ts = new Date(startMs + i * step).toISOString();
|
|
210
|
+
if (!('tool' in m)) m.tool = null;
|
|
211
|
+
});
|
|
212
|
+
d.agentTranscripts['zc-long'] = { messages: msgs };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// kind:"session" 成果样例:注入「接入 SSO 登录」任务(D3 契约:url/repo/ref 一律 null + sessionRef/title 独立字段),
|
|
216
|
+
// 让看板成果区/时间轴开箱即有会话徽标演示数据;重复加载有幂等守卫
|
|
217
|
+
function injectSessionArtifact(d) {
|
|
218
|
+
const task = (d.tasks || []).find((t) => t.id === 't-m4ek9a-3f21');
|
|
219
|
+
const rec = d.agentSessions && d.agentSessions.claude
|
|
220
|
+
? d.agentSessions.claude.find((x) => x.id === 'cl-sso') : null;
|
|
221
|
+
if (!task || !rec) return;
|
|
222
|
+
if ((task.artifacts || []).some((a) => a && a.kind === 'session')) return;
|
|
223
|
+
const at = new Date(Date.now() - 7200 * 1000).toISOString();
|
|
224
|
+
task.artifacts = task.artifacts || [];
|
|
225
|
+
task.artifacts.push({ kind: 'session', sessionRef: rec.ref, title: rec.title, url: null, repo: null, ref: null, attributedBy: 'auto', at });
|
|
226
|
+
task.events = task.events || [];
|
|
227
|
+
task.events.push({ type: 'artifact', from: null, to: null, detail: `自动归因:session ${String(rec.title).slice(0, 40)}`, at });
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function computedOverview(d) {
|
|
231
|
+
const counts = { todo: 0, doing: 0, review: 0, done: 0 };
|
|
232
|
+
for (const t of d.tasks) counts[t.status] = (counts[t.status] || 0) + 1;
|
|
233
|
+
// 契约 v1.4:overdue = 有截止且已过期且未完成(done 列不追责)
|
|
234
|
+
const overdue = d.tasks.filter((t) => t.status !== 'done' && t.dueDate && dueDayDiff(t.dueDate) < 0).length;
|
|
235
|
+
const dayAgo = Date.now() - 86400 * 1000;
|
|
236
|
+
const acts24h = d.activities.filter((a) => Date.parse(a.occurredAt) >= dayAgo).length;
|
|
237
|
+
// v1.8.1 外部经网关的运行中调用数已随 cli-gateway 监控整体退役(业主 2026-10-20):
|
|
238
|
+
// 契约字段保留恒 0(overview.js/顶栏 v2.5 起不再并入展示)
|
|
239
|
+
// v2.3 会话退役:sessionsRunning 同口径恒 0(指挥台本地会话表已退役,会话观测唯一入口
|
|
240
|
+
// 是智能体动态面板;overview.js/顶栏契约字段保留,消费方默认 0 展示)
|
|
241
|
+
return {
|
|
242
|
+
tasks: Object.assign(counts, { overdue }),
|
|
243
|
+
agents: d.agents.length,
|
|
244
|
+
sessionsRunning: 0,
|
|
245
|
+
gatewayExternalRunning: 0,
|
|
246
|
+
activities24h: acts24h,
|
|
247
|
+
gitea: clone(d.overview.gitea)
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// 演示开关(headless 验收用):localStorage['fde-mock-topo'] = 'ok'(默认) | 'empty'(任务列表清空,
|
|
252
|
+
// 供总览页「任务拓扑」空态点击验证;仅影响 /api/tasks 列表,验证后立即清除)
|
|
253
|
+
function topoSimMode() {
|
|
254
|
+
try {
|
|
255
|
+
return (typeof localStorage !== 'undefined' && localStorage.getItem('fde-mock-topo') === 'empty') ? 'empty' : 'ok';
|
|
256
|
+
} catch { return 'ok'; }
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// 演示开关(headless 验收用):localStorage['fde-mock-act'] = 'ok'(默认) | 'empty'(活动流空态) |
|
|
260
|
+
// 'allfail'(四源全失败态);仅影响 /api/agent-activity,验证后立即清除
|
|
261
|
+
function actSimMode() {
|
|
262
|
+
try {
|
|
263
|
+
const v = typeof localStorage !== 'undefined' ? localStorage.getItem('fde-mock-act') : null;
|
|
264
|
+
return ['ok', 'empty', 'allfail'].includes(v) ? v : 'ok';
|
|
265
|
+
} catch { return 'ok'; }
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const columnIds = (d) => d.columns.map((c) => c.id);
|
|
269
|
+
const requireTask = (d, id) => {
|
|
270
|
+
const t = d.tasks.find((x) => x.id === id);
|
|
271
|
+
if (!t) throw new ApiError(404, 'TASK_NOT_FOUND', '任务不存在');
|
|
272
|
+
return t;
|
|
273
|
+
};
|
|
274
|
+
// v1.7 任务动态事件:追加到 task.events(内存按时间正序存,GET 详情返回倒序)
|
|
275
|
+
const pushEvent = (t, type, { from = null, to = null, detail = '' } = {}) => {
|
|
276
|
+
if (!Array.isArray(t.events)) t.events = [];
|
|
277
|
+
t.events.push({ type, from, to, detail, at: nowIso() });
|
|
278
|
+
};
|
|
279
|
+
// PATCH 事件文案:字段键 → 中文名(edit 事件 detail 用)
|
|
280
|
+
const EDIT_LABELS = { title: '标题', desc: '描述', repo: '仓库', branch: '分支', prUrl: 'PR 链接', notes: '备注' };
|
|
281
|
+
const requireColumn = (d, id) => {
|
|
282
|
+
const c = d.columns.find((x) => x.id === id);
|
|
283
|
+
if (!c) throw new ApiError(404, 'COLUMN_NOT_FOUND', '列不存在');
|
|
284
|
+
return c;
|
|
285
|
+
};
|
|
286
|
+
// 本批任务日报:db.diaries 以任务 id 为键的条目数组 [{date,content,updatedAt}](内存态,写操作直接改副本)
|
|
287
|
+
const diariesOf = (d, taskId) => {
|
|
288
|
+
const map = d.diaries || (d.diaries = {});
|
|
289
|
+
if (!Array.isArray(map[taskId])) map[taskId] = [];
|
|
290
|
+
return map[taskId];
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
async function handle(path, { method = 'GET', body } = {}) {
|
|
294
|
+
const d = await load();
|
|
295
|
+
const u = new URL(path, 'http://mock.local');
|
|
296
|
+
const seg = u.pathname.split('/').filter(Boolean).slice(1); // 去掉 'api'
|
|
297
|
+
const m = method.toUpperCase();
|
|
298
|
+
const q = u.searchParams;
|
|
299
|
+
|
|
300
|
+
// ---- 通用 / 总览 ----
|
|
301
|
+
if (seg[0] === 'health' && seg.length === 1 && m === 'GET') {
|
|
302
|
+
return { ok: true, version: '1.1.0-mock', uptimeSec: Math.round((Date.now() - bootMs) / 1000) };
|
|
303
|
+
}
|
|
304
|
+
if (seg[0] === 'overview' && seg.length === 1 && m === 'GET') return computedOverview(d);
|
|
305
|
+
// v2.9.37 版本与兼容性矩阵:ping 契约与后端同形(engines/runtime 只增不改)
|
|
306
|
+
if (seg[0] === 'ping' && seg.length === 1 && m === 'GET') {
|
|
307
|
+
return {
|
|
308
|
+
pong: true,
|
|
309
|
+
name: 'fde-console',
|
|
310
|
+
version: '1.1.0-mock',
|
|
311
|
+
uptimeSec: Math.round((Date.now() - bootMs) / 1000),
|
|
312
|
+
pid: 0,
|
|
313
|
+
engines: { node: '>=22.13', dsh: '>=0.2.1-rc.2 <0.3.0-0' },
|
|
314
|
+
runtime: { node: 'v22.13.0-mock', platform: 'mock', arch: 'mock' }
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// ---- 列 ----
|
|
319
|
+
if (seg[0] === 'columns' && seg.length === 1) {
|
|
320
|
+
if (m === 'GET') return clone(d.columns).sort((a, b) => a.order - b.order);
|
|
321
|
+
if (m === 'POST') {
|
|
322
|
+
const name = String((body && body.name) || '').trim();
|
|
323
|
+
if (!name || name.length > 20) throw new ApiError(400, 'VALIDATION', '列名必填且不超过 20 字');
|
|
324
|
+
const col = { id: genColId(), name, order: d.columns.length + 1 };
|
|
325
|
+
d.columns.push(col);
|
|
326
|
+
return clone(col);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if (seg[0] === 'columns' && seg.length === 2) {
|
|
330
|
+
const col = requireColumn(d, seg[1]);
|
|
331
|
+
if (m === 'PATCH') {
|
|
332
|
+
if (body && body.name !== undefined) {
|
|
333
|
+
const name = String(body.name).trim();
|
|
334
|
+
if (!name || name.length > 20) throw new ApiError(400, 'VALIDATION', '列名必填且不超过 20 字');
|
|
335
|
+
col.name = name;
|
|
336
|
+
}
|
|
337
|
+
if (body && body.order !== undefined) {
|
|
338
|
+
// 契约:order 必须为正整数,服务端归一化为 1..n(其余列顺次让位)
|
|
339
|
+
const n = d.columns.length;
|
|
340
|
+
const req = Number(body.order);
|
|
341
|
+
if (!Number.isInteger(req) || req < 1) throw new ApiError(400, 'VALIDATION', 'order 必须为正整数');
|
|
342
|
+
const target = Math.min(req, n);
|
|
343
|
+
const old = col.order;
|
|
344
|
+
if (target !== old) {
|
|
345
|
+
for (const c of d.columns) {
|
|
346
|
+
if (c.id === col.id) continue;
|
|
347
|
+
if (old < target && c.order > old && c.order <= target) c.order -= 1;
|
|
348
|
+
else if (old > target && c.order >= target && c.order < old) c.order += 1;
|
|
349
|
+
}
|
|
350
|
+
col.order = target;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return clone(col);
|
|
354
|
+
}
|
|
355
|
+
if (m === 'DELETE') {
|
|
356
|
+
const n = d.tasks.filter((t) => t.status === col.id).length;
|
|
357
|
+
if (n > 0) throw new ApiError(409, 'COLUMN_NOT_EMPTY', `先移走该列的 ${n} 个任务`);
|
|
358
|
+
d.columns = d.columns.filter((c) => c.id !== col.id);
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// ---- 任务 ----
|
|
364
|
+
if (seg[0] === 'tasks' && seg.length === 1 && m === 'GET') {
|
|
365
|
+
let list = d.tasks.slice();
|
|
366
|
+
if (topoSimMode() === 'empty') list = []; // 演示开关:拓扑空态验证用(见 topoSimMode 注释)
|
|
367
|
+
const status = q.get('status');
|
|
368
|
+
const memberId = q.get('memberId');
|
|
369
|
+
const priority = q.get('priority'); // 契约 v1.4:?priority= 过滤(前端暂无 UI 入口,backlog)
|
|
370
|
+
const kw = (q.get('q') || '').toLowerCase();
|
|
371
|
+
if (status) list = list.filter((t) => t.status === status);
|
|
372
|
+
if (memberId) list = list.filter((t) => t.memberId === memberId);
|
|
373
|
+
if (priority) list = list.filter((t) => (t.priority || 'medium') === priority);
|
|
374
|
+
if (kw) list = list.filter((t) => [t.title, t.branch, t.notes, t.desc].some((s) => s && String(s).toLowerCase().includes(kw)));
|
|
375
|
+
// 契约:events 仅 GET /api/tasks/:id 返回,列表不携带(卡片无需动态)
|
|
376
|
+
return clone(list).map((x) => { delete x.events; return x; })
|
|
377
|
+
.sort((a, b) => Date.parse(b.updatedAt) - Date.parse(a.updatedAt));
|
|
378
|
+
}
|
|
379
|
+
if (seg[0] === 'tasks' && seg.length === 1 && m === 'POST') {
|
|
380
|
+
const title = String((body && body.title) || '').trim();
|
|
381
|
+
if (!title || title.length > 200) throw new ApiError(400, 'VALIDATION', '标题必填且不超过 200 字');
|
|
382
|
+
const desc = (body && body.desc !== undefined) ? body.desc : '';
|
|
383
|
+
if (typeof desc !== 'string' || desc.length > 2000) throw new ApiError(400, 'VALIDATION', 'desc 必须为不超过 2000 字的字符串');
|
|
384
|
+
const status = (body && body.status) || 'todo';
|
|
385
|
+
if (!columnIds(d).includes(status)) throw new ApiError(400, 'COLUMN_NOT_FOUND', '状态列不存在');
|
|
386
|
+
if (!validDueDate(body && body.dueDate)) throw new ApiError(400, 'VALIDATION', 'dueDate 必须为 YYYY-MM-DD 格式或 null');
|
|
387
|
+
const priority = (body && body.priority) || 'medium';
|
|
388
|
+
if (!PRIORITIES.includes(priority)) throw new ApiError(400, 'VALIDATION', 'priority 必须为 high/medium/low');
|
|
389
|
+
// v2.0 契约:创建即带验收人时,时间轴同步落一条 accept 事件(detail 含验收人名)
|
|
390
|
+
const accId = (body && body.acceptorId) || null;
|
|
391
|
+
const accMem = accId ? (d.members || []).find((x) => x.id === accId) : null;
|
|
392
|
+
const accName = accMem ? accMem.name : accId;
|
|
393
|
+
const t = {
|
|
394
|
+
id: genTaskId(),
|
|
395
|
+
title,
|
|
396
|
+
status,
|
|
397
|
+
desc,
|
|
398
|
+
priority,
|
|
399
|
+
dueDate: (body && body.dueDate) || null,
|
|
400
|
+
agentId: (body && body.agentId) || null,
|
|
401
|
+
memberId: (body && body.memberId) || null,
|
|
402
|
+
acceptorId: accId, // v2.0 契约:验收人(成员 id 或 null)
|
|
403
|
+
repo: (body && body.repo) || null,
|
|
404
|
+
branch: (body && body.branch) || null,
|
|
405
|
+
prUrl: (body && body.prUrl) || null,
|
|
406
|
+
notes: (body && body.notes) || '',
|
|
407
|
+
artifacts: [], // 叙事线第一批:成果挂接列表(POST/DELETE /api/tasks/:id/artifacts 维护)
|
|
408
|
+
completedAt: null, // v1.7 契约:status 进 done 自动置、移出清空
|
|
409
|
+
createdAt: nowIso(),
|
|
410
|
+
updatedAt: nowIso(),
|
|
411
|
+
events: [
|
|
412
|
+
{ type: 'created', from: null, to: status, detail: '', at: nowIso() },
|
|
413
|
+
...(accId ? [{ type: 'accept', from: null, to: accName, detail: `验收人:${accName}`, at: nowIso() }] : [])
|
|
414
|
+
]
|
|
415
|
+
};
|
|
416
|
+
d.tasks.push(t);
|
|
417
|
+
return clone(t);
|
|
418
|
+
}
|
|
419
|
+
if (seg[0] === 'tasks' && seg.length === 2) {
|
|
420
|
+
const t = requireTask(d, seg[1]);
|
|
421
|
+
if (m === 'GET') {
|
|
422
|
+
const out = clone(t);
|
|
423
|
+
// v1.7 契约:events 倒序(最新在前)。先稳定升序再整体反转:
|
|
424
|
+
// 同毫秒事件(一次 PATCH 记多条)保持“后插入 = 更新”语义(如 completed 排在 status 前)
|
|
425
|
+
out.events = (out.events || []).slice()
|
|
426
|
+
.sort((a, b) => Date.parse(a.at || 0) - Date.parse(b.at || 0))
|
|
427
|
+
.reverse();
|
|
428
|
+
return out;
|
|
429
|
+
}
|
|
430
|
+
if (m === 'PATCH') {
|
|
431
|
+
const writable = ['title', 'status', 'desc', 'priority', 'dueDate', 'agentId', 'memberId', 'acceptorId', 'repo', 'branch', 'prUrl', 'notes'];
|
|
432
|
+
// v1.7 动态事件:名称解析(列名/成员名/智能体名),from/to 存人读值
|
|
433
|
+
const colName = (cid) => (d.columns.find((c) => c.id === cid) || {}).name || cid || null;
|
|
434
|
+
const memName = (mid) => {
|
|
435
|
+
if (!mid) return null;
|
|
436
|
+
const mm = (d.members || []).find((x) => x.id === mid);
|
|
437
|
+
return mm ? mm.name : mid;
|
|
438
|
+
};
|
|
439
|
+
const agName = (aid) => {
|
|
440
|
+
if (!aid) return null;
|
|
441
|
+
const aa = d.agents.find((x) => x.id === aid);
|
|
442
|
+
return aa ? aa.name : aid;
|
|
443
|
+
};
|
|
444
|
+
const changed = (a, b) => JSON.stringify(a === undefined ? null : a) !== JSON.stringify(b === undefined ? null : b);
|
|
445
|
+
for (const k of writable) {
|
|
446
|
+
if (body && body[k] !== undefined) {
|
|
447
|
+
if (k === 'status' && !columnIds(d).includes(body[k])) throw new ApiError(400, 'COLUMN_NOT_FOUND', '状态列不存在');
|
|
448
|
+
if (k === 'title' && (!String(body[k]).trim() || String(body[k]).length > 200)) throw new ApiError(400, 'VALIDATION', '标题必填且不超过 200 字');
|
|
449
|
+
if (k === 'desc' && (typeof body[k] !== 'string' || body[k].length > 2000)) throw new ApiError(400, 'VALIDATION', 'desc 必须为不超过 2000 字的字符串');
|
|
450
|
+
if (k === 'dueDate' && !validDueDate(body[k])) throw new ApiError(400, 'VALIDATION', 'dueDate 必须为 YYYY-MM-DD 格式或 null');
|
|
451
|
+
if (k === 'priority' && !PRIORITIES.includes(body[k])) throw new ApiError(400, 'VALIDATION', 'priority 必须为 high/medium/low');
|
|
452
|
+
const prev = t[k];
|
|
453
|
+
t[k] = body[k];
|
|
454
|
+
if (!changed(prev, body[k])) continue; // 值没变不记动态
|
|
455
|
+
if (k === 'status') {
|
|
456
|
+
pushEvent(t, 'status', { from: colName(prev), to: colName(body[k]) });
|
|
457
|
+
// 契约:status 进 done 自动置 completedAt,移出清空
|
|
458
|
+
if (body[k] === 'done') {
|
|
459
|
+
t.completedAt = nowIso();
|
|
460
|
+
pushEvent(t, 'completed', { from: null, to: null, detail: '任务完成' });
|
|
461
|
+
} else if (prev === 'done') {
|
|
462
|
+
t.completedAt = null;
|
|
463
|
+
}
|
|
464
|
+
} else if (k === 'priority') {
|
|
465
|
+
pushEvent(t, 'priority', { from: prev || null, to: body[k] });
|
|
466
|
+
} else if (k === 'dueDate') {
|
|
467
|
+
pushEvent(t, 'due', { from: prev || null, to: body[k] || null });
|
|
468
|
+
} else if (k === 'memberId') {
|
|
469
|
+
pushEvent(t, 'assign', { from: memName(prev), to: memName(body[k]), detail: body[k] ? `负责成员:${memName(body[k])}` : '取消负责成员' });
|
|
470
|
+
} else if (k === 'acceptorId') {
|
|
471
|
+
// v2.0 契约:events 新增 type:"accept",detail 含验收人名(时间轴金色「验收」节点)
|
|
472
|
+
pushEvent(t, 'accept', { from: memName(prev), to: memName(body[k]), detail: body[k] ? `验收人:${memName(body[k])}` : '取消验收人' });
|
|
473
|
+
} else if (k === 'agentId') {
|
|
474
|
+
pushEvent(t, 'assign', { from: agName(prev), to: agName(body[k]), detail: body[k] ? `负责智能体:${agName(body[k])}` : '取消负责智能体' });
|
|
475
|
+
} else {
|
|
476
|
+
pushEvent(t, 'edit', { from: null, to: null, detail: `更新了${EDIT_LABELS[k] || k}` });
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
t.updatedAt = nowIso();
|
|
481
|
+
return clone(t);
|
|
482
|
+
}
|
|
483
|
+
if (m === 'DELETE') {
|
|
484
|
+
d.tasks = d.tasks.filter((x) => x.id !== t.id);
|
|
485
|
+
return null;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// ---- 叙事线第一批:任务成果挂接(POST 挂 / DELETE 按 idx 解),动作都写 artifact 事件 ----
|
|
490
|
+
// v2.3 D3 契约扩展:kind 增 'session'——不带 url,sessionRef(≤512)/title(≤200)为独立必填字段,
|
|
491
|
+
// url/repo/ref 一律不入库置 null(不复用 ref 字段:board.js 按「PR 序号/commit 哈希」语义渲染,双义会漏)
|
|
492
|
+
if (seg[0] === 'tasks' && seg.length === 3 && seg[2] === 'artifacts' && m === 'POST') {
|
|
493
|
+
const t = requireTask(d, seg[1]);
|
|
494
|
+
const kind = String((body && body.kind) || '');
|
|
495
|
+
if (!Array.isArray(t.artifacts)) t.artifacts = [];
|
|
496
|
+
if (kind === 'session') {
|
|
497
|
+
const sessionRef = String((body && body.sessionRef) || '').trim();
|
|
498
|
+
const title = String((body && body.title) || '').trim();
|
|
499
|
+
if (!sessionRef || sessionRef.length > 512) throw new ApiError(400, 'VALIDATION', 'sessionRef 必填且不超过 512 字符');
|
|
500
|
+
if (!title || title.length > 200) throw new ApiError(400, 'VALIDATION', 'title 必填且不超过 200 字符');
|
|
501
|
+
if (!resolveSessionRef(sessionRef)) throw new ApiError(400, 'BAD_REF', 'sessionRef 无法解析或会话不存在');
|
|
502
|
+
t.artifacts.push({ kind, sessionRef, title, url: null, repo: null, ref: null, at: nowIso() });
|
|
503
|
+
pushEvent(t, 'artifact', { from: null, to: null, detail: `挂接成果:session ${title.slice(0, 40)}` });
|
|
504
|
+
t.updatedAt = nowIso();
|
|
505
|
+
return clone(t);
|
|
506
|
+
}
|
|
507
|
+
const url = String((body && body.url) || '').trim();
|
|
508
|
+
if (!/^https?:\/\//i.test(url)) throw new ApiError(400, 'VALIDATION', 'url 必填且必须为 http(s) 链接');
|
|
509
|
+
if (!['commit', 'pr'].includes(kind)) throw new ApiError(400, 'VALIDATION', 'kind 必须为 commit、pr 或 session');
|
|
510
|
+
const repo = (body && body.repo != null && String(body.repo).trim()) ? String(body.repo).trim() : null;
|
|
511
|
+
const ref = (body && body.ref != null && String(body.ref).trim()) ? String(body.ref).trim() : null;
|
|
512
|
+
t.artifacts.push({ url, kind, repo, ref, at: nowIso() });
|
|
513
|
+
pushEvent(t, 'artifact', { from: null, to: url, detail: `挂接成果:${kind === 'pr' ? 'PR' : 'commit'}${repo ? ' · ' + repo : ''}` });
|
|
514
|
+
t.updatedAt = nowIso();
|
|
515
|
+
return clone(t);
|
|
516
|
+
}
|
|
517
|
+
if (seg[0] === 'tasks' && seg.length === 4 && seg[2] === 'artifacts' && m === 'DELETE') {
|
|
518
|
+
const t = requireTask(d, seg[1]);
|
|
519
|
+
const idx = Number(seg[3]);
|
|
520
|
+
if (!Array.isArray(t.artifacts) || !Number.isInteger(idx) || idx < 0 || idx >= t.artifacts.length) {
|
|
521
|
+
throw new ApiError(404, 'ARTIFACT_NOT_FOUND', '成果不存在或已被解除');
|
|
522
|
+
}
|
|
523
|
+
const rm = t.artifacts.splice(idx, 1)[0];
|
|
524
|
+
const kindLabel = rm.kind === 'pr' ? 'PR' : rm.kind === 'session' ? 'session' : 'commit';
|
|
525
|
+
pushEvent(t, 'artifact', { from: rm.url, to: null, detail: `解除成果挂接:${kindLabel}${rm.kind === 'session' ? ' ' + String(rm.title || '').slice(0, 40) : rm.repo ? ' · ' + rm.repo : ''}` });
|
|
526
|
+
t.updatedAt = nowIso();
|
|
527
|
+
return clone(t);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// ---- 本批任务日报(diary):多日任务的过程留痕(后端并行开发中,前端按此 mock 契约先行)----
|
|
531
|
+
// GET /api/tasks/:id/diary → [{date,content,updatedAt}](date 倒序)
|
|
532
|
+
// PUT /api/tasks/:id/diary {date,content} → upsert(同日覆盖),返回该条
|
|
533
|
+
// DELETE /api/tasks/:id/diary/:date → 204
|
|
534
|
+
// GET /api/tasks/:id/diary/prefill?date= → {giteaCommits:[{sha,title,url}], memoUpdates:[{quote,note}], draft}
|
|
535
|
+
if (seg[0] === 'tasks' && seg.length === 3 && seg[2] === 'diary') {
|
|
536
|
+
const t = requireTask(d, seg[1]);
|
|
537
|
+
if (m === 'GET') {
|
|
538
|
+
return clone(diariesOf(d, t.id)).sort((a, b) => (a.date < b.date ? 1 : -1));
|
|
539
|
+
}
|
|
540
|
+
if (m === 'PUT') {
|
|
541
|
+
const date = body && body.date;
|
|
542
|
+
if (parseYMD(date) === null) throw new ApiError(400, 'VALIDATION', 'date 必须为 YYYY-MM-DD 格式');
|
|
543
|
+
const content = body && body.content;
|
|
544
|
+
if (typeof content !== 'string' || !content.trim()) throw new ApiError(400, 'VALIDATION', 'content 必填(1..2000 字)');
|
|
545
|
+
if (content.length > 2000) throw new ApiError(400, 'VALIDATION', `content 不能超过 2000 字(当前 ${content.length} 字)`);
|
|
546
|
+
const list = diariesOf(d, t.id);
|
|
547
|
+
const hit = list.find((x) => x.date === date); // 同日覆盖(upsert 语义)
|
|
548
|
+
if (hit) {
|
|
549
|
+
hit.content = content;
|
|
550
|
+
hit.updatedAt = nowIso();
|
|
551
|
+
} else {
|
|
552
|
+
list.push({ date, content, updatedAt: nowIso() });
|
|
553
|
+
}
|
|
554
|
+
return clone(list.find((x) => x.date === date));
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
if (seg[0] === 'tasks' && seg.length === 4 && seg[2] === 'diary' && m === 'DELETE') {
|
|
558
|
+
const t = requireTask(d, seg[1]);
|
|
559
|
+
const date = decodeURIComponent(seg[3]);
|
|
560
|
+
if (parseYMD(date) === null) throw new ApiError(400, 'VALIDATION', 'date 必须为 YYYY-MM-DD 格式');
|
|
561
|
+
const list = diariesOf(d, t.id);
|
|
562
|
+
const at = list.findIndex((x) => x.date === date);
|
|
563
|
+
if (at < 0) throw new ApiError(404, 'DIARY_NOT_FOUND', '该日期无日报');
|
|
564
|
+
list.splice(at, 1);
|
|
565
|
+
return null; // 204
|
|
566
|
+
}
|
|
567
|
+
if (seg[0] === 'tasks' && seg.length === 4 && seg[2] === 'diary' && seg[3] === 'prefill' && m === 'GET') {
|
|
568
|
+
const t = requireTask(d, seg[1]);
|
|
569
|
+
const date = q.get('date') || localYMD(new Date());
|
|
570
|
+
if (parseYMD(date) === null) throw new ApiError(400, 'VALIDATION', 'date 必须为 YYYY-MM-DD 格式');
|
|
571
|
+
// 数据源一 Gitea 提交:活动流中按匹配归到本任务的 commit_pushed(分支约定 / [#任务id] 归因)。
|
|
572
|
+
// 优先取请求日期当天的;演示数据时间随加载平移可能不完全落在当天,取不到再退回最近匹配的 5 条
|
|
573
|
+
const matched = (d.activities || []).filter((a) => a.type === 'commit_pushed' && (a.matchedTaskIds || []).includes(t.id));
|
|
574
|
+
const onDate = matched.filter((a) => localYMD(new Date(a.occurredAt)) === date);
|
|
575
|
+
const giteaCommits = (onDate.length ? onDate : matched).slice(0, 5).map((a) => ({
|
|
576
|
+
sha: a.sha || String(a.url || '').split('/').filter(Boolean).pop() || '',
|
|
577
|
+
title: a.title || a.messageBody || '',
|
|
578
|
+
url: a.url || ''
|
|
579
|
+
}));
|
|
580
|
+
// 数据源二 纪要提及:任务更新提案确认时落在 origin.relatedMemos 的结构化留痕(quote+note)
|
|
581
|
+
const rel = (t.origin && Array.isArray(t.origin.relatedMemos)) ? t.origin.relatedMemos : [];
|
|
582
|
+
const memoUpdates = rel.slice(-3).reverse()
|
|
583
|
+
.map((mm) => ({ quote: String((mm && mm.quote) || ''), note: String((mm && mm.note) || '') }));
|
|
584
|
+
// 拼好的草稿文本:前端「从今日动态预填」直接填入编辑器(已有内容则追加不覆盖)
|
|
585
|
+
const lines = [];
|
|
586
|
+
if (giteaCommits.length) {
|
|
587
|
+
lines.push('今日提交:');
|
|
588
|
+
for (const c of giteaCommits) lines.push(`· ${c.title}${c.sha ? `(${c.sha})` : ''}`);
|
|
589
|
+
}
|
|
590
|
+
if (memoUpdates.length) {
|
|
591
|
+
lines.push('纪要同步:');
|
|
592
|
+
for (const mm of memoUpdates) lines.push(`· “${mm.quote}”${mm.note ? `(备注:${mm.note})` : ''}`);
|
|
593
|
+
}
|
|
594
|
+
if (!lines.length) lines.push('(当日暂无 Gitea 提交与纪要提及,可手动记录进展 / 卡点 / 下一步)');
|
|
595
|
+
lines.push('', '(草稿由当日动态自动拼装,可修改后保存)');
|
|
596
|
+
return { giteaCommits, memoUpdates, draft: lines.join('\n') };
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// ---- 组织仓库(本批:看板任务表单「仓库」可搜索下拉数据源,后端并行开发中按此 mock 契约先行)----
|
|
600
|
+
// GET /api/repos → [{fullName, name, private, updatedAt}](配置组织下全部仓库,无分页;
|
|
601
|
+
// updatedAt 键在 DATE_KEY 内,加载时随全局锚点平移,演示数据时间恒新鲜)。
|
|
602
|
+
// 过滤不做在 mock 侧:board.js 下拉对全量列表按 fullName/name 大小写不敏感过滤
|
|
603
|
+
if (seg[0] === 'repos' && seg.length === 1 && m === 'GET') return clone(d.repos || []);
|
|
604
|
+
|
|
605
|
+
// ---- 智能体 ----
|
|
606
|
+
// v2.7 注册表退役(业主 2026-10-20「退役本地 CLI 启动体系」):POST/PATCH/DELETE /api/agents 与
|
|
607
|
+
// /api/agents/:id/launch 随本地 CLI 启动体系下线——前端已无调用入口(真实后端由并行岗同步移除),
|
|
608
|
+
// gwStatus/gwSimMode 启动判定与 BRIEFING 黑名单校验一并删除;GET 保留:看板「AI 执行」执行者下拉、
|
|
609
|
+
// 智能体观测卡、会话表/拓扑的名称映射仍依赖
|
|
610
|
+
if (seg[0] === 'agents' && seg.length === 1 && m === 'GET') return clone(d.agents);
|
|
611
|
+
|
|
612
|
+
// ---- 会话(v2.3 退役 + 新增)----
|
|
613
|
+
// GET /api/sessions 过渡桩:会话登记表/停止/日志已随 v2.3 退役(真实后端由并行岗同步下线)。
|
|
614
|
+
// 总览页「运行中会话」面板仍消费该端点(其退役未列入 SPEC-READER §6 清单),暂回空列表保七视图可用;
|
|
615
|
+
// overview.js 收口后此桩一并删除
|
|
616
|
+
if (seg[0] === 'sessions' && seg.length === 1 && m === 'GET') return [];
|
|
617
|
+
|
|
618
|
+
// GET /api/agent-sessions?agent=&limit=&cursor=(§3.1):该源会话列表,lastActiveAt 倒序 + 键集游标分页
|
|
619
|
+
// 演示开关(headless 验收用):localStorage['fde-mock-sess'] = 'fail' → 本端点 500(拓扑会话源加载失败空态验证)
|
|
620
|
+
if (seg[0] === 'agent-sessions' && seg.length === 1 && m === 'GET') {
|
|
621
|
+
const sessFail = (() => {
|
|
622
|
+
try {
|
|
623
|
+
return (typeof localStorage !== 'undefined' && localStorage.getItem('fde-mock-sess') === 'fail');
|
|
624
|
+
} catch { return false; }
|
|
625
|
+
})();
|
|
626
|
+
if (sessFail) throw new ApiError(500, 'SOURCE_DOWN', '会话源探测失败(fde-mock-sess=fail 演示态)');
|
|
627
|
+
const agent = q.get('agent') || '';
|
|
628
|
+
if (!d.agentSessions || !Object.prototype.hasOwnProperty.call(d.agentSessions, agent)) {
|
|
629
|
+
throw new ApiError(400, 'BAD_AGENT', `agent 必填且须为已接入会话源(现有:${Object.keys(d.agentSessions || {}).join('、') || '无'})`);
|
|
630
|
+
}
|
|
631
|
+
let limit = Number(q.get('limit') || 20);
|
|
632
|
+
if (!isFinite(limit) || limit < 1) limit = 20;
|
|
633
|
+
if (limit > 50) limit = 50; // §3.1:上限 50,超出按 50
|
|
634
|
+
const sorted = d.agentSessions[agent].slice()
|
|
635
|
+
.sort((a, b) => Date.parse(b.lastActiveAt || 0) - Date.parse(a.lastActiveAt || 0) || (a.id < b.id ? 1 : -1));
|
|
636
|
+
let start = 0;
|
|
637
|
+
const cur = q.get('cursor');
|
|
638
|
+
if (cur) {
|
|
639
|
+
let c = null;
|
|
640
|
+
try { c = JSON.parse(b64urlDec(cur)); } catch { c = null; }
|
|
641
|
+
// 键集游标:定位 (lastActiveAt, id) 锚点取其后一页;游标失效(数据已翻页翻过)→ 空页,客户端停止加载
|
|
642
|
+
const at = c ? sorted.findIndex((x) => x.lastActiveAt === c.t && x.id === c.id) : -1;
|
|
643
|
+
start = at >= 0 ? at + 1 : sorted.length;
|
|
644
|
+
}
|
|
645
|
+
const page = sorted.slice(start, start + limit);
|
|
646
|
+
const anchor = start + limit < sorted.length ? sorted[start + limit - 1] : null;
|
|
647
|
+
return {
|
|
648
|
+
agent,
|
|
649
|
+
items: page.map((rec) => ({
|
|
650
|
+
ref: rec.ref, id: rec.id, title: rec.title, projectId: rec.projectId,
|
|
651
|
+
startedAt: rec.startedAt, lastActiveAt: rec.lastActiveAt, state: rec.state || '',
|
|
652
|
+
// 可选 taskId(B5 拓扑联动):会话与任务的显式关联,真实后端按源能力回填(缺省 null)
|
|
653
|
+
taskId: rec.taskId || null
|
|
654
|
+
})),
|
|
655
|
+
nextCursor: anchor ? b64urlEnc(JSON.stringify({ t: anchor.lastActiveAt, id: anchor.id })) : null
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// GET /api/agent-session?ref=(§3.2):会话全文;workbuddy 恒降级(D4,不造数据)
|
|
660
|
+
if (seg[0] === 'agent-session' && seg.length === 1 && m === 'GET') {
|
|
661
|
+
const ref = q.get('ref') || '';
|
|
662
|
+
const hit = resolveSessionRef(ref);
|
|
663
|
+
if (!hit) throw new ApiError(400, 'BAD_REF', 'ref 无效(解码 / 来源白名单 / 会话存在性任一不过)');
|
|
664
|
+
const { src, rec } = hit;
|
|
665
|
+
const base = { ref, agent: src, title: rec.title, projectId: rec.projectId, startedAt: rec.startedAt, lastActiveAt: rec.lastActiveAt };
|
|
666
|
+
if (src === 'workbuddy') {
|
|
667
|
+
return Object.assign(base, { degraded: true, reason: 'SOURCE_NO_TRANSCRIPT', messages: [] });
|
|
668
|
+
}
|
|
669
|
+
const tr = (d.agentTranscripts || {})[rec.id];
|
|
670
|
+
const messages = tr && Array.isArray(tr.messages) ? clone(tr.messages) : [];
|
|
671
|
+
return Object.assign(base, { degraded: false, total: messages.length, truncated: false, messages });
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
// ---- 成员 ----
|
|
675
|
+
// 契约对齐 lib/members.js:id ^[a-z][a-z0-9.-]{0,31}$;name 必填 1..50;role/giteaLogin 可选 ≤50 字
|
|
676
|
+
// 聚合视图每条带 manual:true/false(manual 为手工名册条目,其余由智能体注册表/Gitea 同步派生)
|
|
677
|
+
const MEMBER_ID_RE = /^[a-z][a-z0-9.-]{0,31}$/;
|
|
678
|
+
const requireMemberName = (v) => {
|
|
679
|
+
const s = String(v == null ? '' : v).trim();
|
|
680
|
+
if (s.length < 1 || s.length > 50) throw new ApiError(400, 'MEMBER_INVALID', 'name 必填且为 1..50 字符');
|
|
681
|
+
return s;
|
|
682
|
+
};
|
|
683
|
+
const optionalMemberField = (v, label) => {
|
|
684
|
+
if (v === undefined || v === null || v === '') return '';
|
|
685
|
+
if (typeof v !== 'string' || v.trim().length > 50) {
|
|
686
|
+
throw new ApiError(400, 'MEMBER_INVALID', `${label} 可省略,提供时必须为 ≤50 字符的字符串`);
|
|
687
|
+
}
|
|
688
|
+
return v.trim();
|
|
689
|
+
};
|
|
690
|
+
if (seg[0] === 'members' && seg.length === 1 && m === 'GET') {
|
|
691
|
+
// 契约 v1.4:currentTask 附带 dueDate/priority,从任务源实时带出(mock 编辑任务后成员行同步)
|
|
692
|
+
// 本批:diaryToday = 该成员当前任务今日已有日报(写入口在任务详情「日报」区,两态供成员页轻提醒)
|
|
693
|
+
const today = localYMD(new Date());
|
|
694
|
+
return clone(d.members).map((x) => {
|
|
695
|
+
if (x.manual !== true) x = Object.assign({ manual: false }, x);
|
|
696
|
+
if (x.currentTask) {
|
|
697
|
+
const t = d.tasks.find((y) => y.id === x.currentTask.id);
|
|
698
|
+
if (t) {
|
|
699
|
+
x.currentTask.dueDate = t.dueDate || null;
|
|
700
|
+
x.currentTask.priority = t.priority || 'medium';
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
x.diaryToday = !!(x.currentTask && diariesOf(d, x.currentTask.id).some((e) => e && e.date === today));
|
|
704
|
+
return x;
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
if (seg[0] === 'members' && seg.length === 1 && m === 'POST') {
|
|
708
|
+
const b = body || {};
|
|
709
|
+
if (typeof b.id !== 'string' || !MEMBER_ID_RE.test(b.id)) {
|
|
710
|
+
throw new ApiError(400, 'MEMBER_INVALID', 'id 必填且须匹配 ^[a-z][a-z0-9.-]{0,31}$');
|
|
711
|
+
}
|
|
712
|
+
if (d.members.some((x) => x.id === b.id)) throw new ApiError(409, 'MEMBER_EXISTS', '该 id 已存在于手工名册');
|
|
713
|
+
if (b.enabled !== undefined && typeof b.enabled !== 'boolean') {
|
|
714
|
+
throw new ApiError(400, 'MEMBER_INVALID', 'enabled 必须为布尔值');
|
|
715
|
+
}
|
|
716
|
+
const row = {
|
|
717
|
+
id: b.id,
|
|
718
|
+
name: requireMemberName(b.name),
|
|
719
|
+
kind: 'human',
|
|
720
|
+
role: optionalMemberField(b.role, 'role'),
|
|
721
|
+
giteaLogin: optionalMemberField(b.giteaLogin, 'giteaLogin'),
|
|
722
|
+
enabled: b.enabled === undefined ? true : b.enabled,
|
|
723
|
+
manual: true,
|
|
724
|
+
status: 'idle',
|
|
725
|
+
currentTask: null,
|
|
726
|
+
lastActivityAt: null,
|
|
727
|
+
todayCommits: 0,
|
|
728
|
+
openPrs: 0,
|
|
729
|
+
weekDone: 0,
|
|
730
|
+
session: null
|
|
731
|
+
};
|
|
732
|
+
d.members.push(row);
|
|
733
|
+
return clone(row);
|
|
734
|
+
}
|
|
735
|
+
if (seg[0] === 'members' && seg.length === 2) {
|
|
736
|
+
const row = d.members.find((x) => x.id === seg[1]);
|
|
737
|
+
if (m === 'PATCH') {
|
|
738
|
+
// 与后端一致:手工名册之外的 id(含派生成员)一律 404
|
|
739
|
+
if (!row || row.manual !== true) throw new ApiError(404, 'MEMBER_NOT_FOUND', '手工名册中不存在该成员(智能体与 Gitea 派生成员不经此接口修改)');
|
|
740
|
+
const b = body || {};
|
|
741
|
+
if (b.name !== undefined) row.name = requireMemberName(b.name);
|
|
742
|
+
if (b.role !== undefined) row.role = optionalMemberField(b.role, 'role');
|
|
743
|
+
if (b.giteaLogin !== undefined) row.giteaLogin = optionalMemberField(b.giteaLogin, 'giteaLogin');
|
|
744
|
+
if (b.enabled !== undefined) {
|
|
745
|
+
if (typeof b.enabled !== 'boolean') throw new ApiError(400, 'MEMBER_INVALID', 'enabled 必须为布尔值');
|
|
746
|
+
row.enabled = b.enabled;
|
|
747
|
+
}
|
|
748
|
+
return clone(row);
|
|
749
|
+
}
|
|
750
|
+
if (m === 'DELETE') {
|
|
751
|
+
if (!row) throw new ApiError(404, 'MEMBER_NOT_FOUND', '成员不存在');
|
|
752
|
+
if (row.manual !== true) throw new ApiError(409, 'MEMBER_IMMUTABLE', '该成员非手工名册条目,不可删除(智能体走 /api/agents,Gitea 成员为派生只读)');
|
|
753
|
+
d.members = d.members.filter((x) => x.id !== row.id);
|
|
754
|
+
return null; // 204
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// ---- 动态 ----
|
|
759
|
+
if (seg[0] === 'activities' && seg.length === 1 && m === 'GET') {
|
|
760
|
+
const list = clone(d.activities).sort((a, b) => Date.parse(b.occurredAt) - Date.parse(a.occurredAt));
|
|
761
|
+
void q.get('refresh'); // mock 下刷新等于重读缓存
|
|
762
|
+
return list;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// ---- 设置 ----
|
|
766
|
+
if (seg[0] === 'settings') {
|
|
767
|
+
if (m === 'GET') return clone(d.settings);
|
|
768
|
+
if (m === 'PATCH') {
|
|
769
|
+
if (body && body.host !== undefined && body.host !== '127.0.0.1') throw new ApiError(400, 'HOST_FORBIDDEN', 'host 仅允许 127.0.0.1');
|
|
770
|
+
const src = body && body.gitea;
|
|
771
|
+
if (src && typeof src === 'object') {
|
|
772
|
+
for (const k of Object.keys(src)) {
|
|
773
|
+
if (k in d.settings.gitea) d.settings.gitea[k] = src[k];
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
const dt = body && body.dingtalk;
|
|
777
|
+
if (dt && typeof dt === 'object') {
|
|
778
|
+
if (!d.settings.dingtalk) d.settings.dingtalk = { enabled: true, hostWhitelist: ['dingtalk.com'] };
|
|
779
|
+
for (const k of Object.keys(dt)) {
|
|
780
|
+
if (k in d.settings.dingtalk) d.settings.dingtalk[k] = dt[k];
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
const az = body && body.analyze;
|
|
784
|
+
if (az && typeof az === 'object') {
|
|
785
|
+
if (!d.settings.analyze) d.settings.analyze = { timeoutSec: 120, maxTasksPerMessage: 10 };
|
|
786
|
+
for (const k of Object.keys(az)) {
|
|
787
|
+
if (k in d.settings.analyze) d.settings.analyze[k] = az[k];
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
const gw = body && body.gateway;
|
|
791
|
+
if (gw && typeof gw === 'object') {
|
|
792
|
+
if (!d.settings.gateway) d.settings.gateway = { enabled: true, timeoutSec: 600, bin: 'cli-gateway', minVersion: '0.9.0' };
|
|
793
|
+
if (gw.enabled !== undefined && typeof gw.enabled !== 'boolean') {
|
|
794
|
+
throw new ApiError(400, 'VALIDATION', 'gateway.enabled 必须为布尔值');
|
|
795
|
+
}
|
|
796
|
+
if (gw.timeoutSec !== undefined) {
|
|
797
|
+
const v = Number(gw.timeoutSec);
|
|
798
|
+
if (!isFinite(v) || v < 30 || v > 3600) {
|
|
799
|
+
throw new ApiError(400, 'VALIDATION', 'gateway.timeoutSec 必须为 30..3600 的数字');
|
|
800
|
+
}
|
|
801
|
+
gw.timeoutSec = v;
|
|
802
|
+
}
|
|
803
|
+
// 契约:gateway 节仅 enabled/timeoutSec 可改;bin/minVersion 只读展示(传入即忽略)
|
|
804
|
+
for (const k of ['enabled', 'timeoutSec']) {
|
|
805
|
+
if (gw[k] !== undefined) d.settings.gateway[k] = gw[k];
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
// 环境体检二期新键:security.trustedHosts(字符串数组;localhost/127.0.0.1 为后端内置信任,存盘值不含)
|
|
809
|
+
const sec = body && body.security;
|
|
810
|
+
if (sec && typeof sec === 'object') {
|
|
811
|
+
if (!d.settings.security) d.settings.security = { trustedHosts: [] };
|
|
812
|
+
if (sec.trustedHosts !== undefined) {
|
|
813
|
+
if (!Array.isArray(sec.trustedHosts) || sec.trustedHosts.some((h) => typeof h !== 'string')) {
|
|
814
|
+
throw new ApiError(400, 'VALIDATION', 'security.trustedHosts 必须为字符串数组');
|
|
815
|
+
}
|
|
816
|
+
const seen = new Set();
|
|
817
|
+
d.settings.security.trustedHosts = [];
|
|
818
|
+
for (const raw of sec.trustedHosts) {
|
|
819
|
+
const h = raw.trim();
|
|
820
|
+
const key = h.toLowerCase();
|
|
821
|
+
if (!h || seen.has(key)) continue;
|
|
822
|
+
seen.add(key);
|
|
823
|
+
d.settings.security.trustedHosts.push(h);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
return clone(d.settings);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
// ---- 环境体检(设置页产品化二期):GET /api/setup/check,六项 node/dws/dsh/llmRoute/gitea/cliGateway ----
|
|
832
|
+
// 演示开关(headless 验收用):localStorage['fde-mock-setup'] = 'ok'(默认全过) | 'fail'(2 项失败演示态)
|
|
833
|
+
if (seg[0] === 'setup' && seg[1] === 'check' && seg.length === 2 && m === 'GET') {
|
|
834
|
+
const setupSim = (() => {
|
|
835
|
+
try {
|
|
836
|
+
return (typeof localStorage !== 'undefined' && localStorage.getItem('fde-mock-setup') === 'fail') ? 'fail' : 'ok';
|
|
837
|
+
} catch { return 'ok'; }
|
|
838
|
+
})();
|
|
839
|
+
await new Promise((r) => setTimeout(r, 300)); // 模拟真实探测耗时,让「体检中」骨架态可见
|
|
840
|
+
const out = clone(d.setupCheck);
|
|
841
|
+
if (setupSim === 'fail' && d.setupCheckFail && d.setupCheckFail.overrides) {
|
|
842
|
+
for (const it of out.items) {
|
|
843
|
+
const o = d.setupCheckFail.overrides[it.id];
|
|
844
|
+
if (o) { it.ok = !!o.ok; it.detail = o.detail; it.hint = o.hint; }
|
|
845
|
+
}
|
|
846
|
+
out.allOk = out.items.every((i) => i.ok);
|
|
847
|
+
}
|
|
848
|
+
out.checkedAt = nowIso();
|
|
849
|
+
return out;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
// ---- Gitea 测试 ----
|
|
853
|
+
if (seg[0] === 'gitea' && seg[1] === 'test' && m === 'POST') {
|
|
854
|
+
const raw = String((body && body.baseUrl) || d.settings.gitea.baseUrl);
|
|
855
|
+
let host = '';
|
|
856
|
+
try { host = new URL(raw).hostname.toLowerCase(); } catch { throw new ApiError(400, 'VALIDATION', 'baseUrl 不是合法 URL'); }
|
|
857
|
+
if (!d.settings.gitea.hostWhitelist.some((h) => h.toLowerCase() === host)) {
|
|
858
|
+
throw new ApiError(400, 'HOST_NOT_ALLOWED', 'host 不在白名单');
|
|
859
|
+
}
|
|
860
|
+
return { ok: true, latencyMs: 80 + Math.floor(Math.random() * 120), apiVersion: '1.22.0' };
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
// ---- cli-gateway(v1.5.1 → v2.6 退役):/api/gateway/* mock 路由已随网关监控整体下线;
|
|
864
|
+
// v2.7 注册表退役:launch 路由与 gwStatus 启动判定一并下线;
|
|
865
|
+
// v2.3 会话退役:sessions/:id/log 路由与 sessionLogs 样例随会话表「日志」弹层一并删除(该端点后端本无注册,死链) ----
|
|
866
|
+
|
|
867
|
+
// ---- 网关动态(v1.7.2 → v2.6 随 cli-gateway 监控整体退役):gateway/invocations 列表与
|
|
868
|
+
// 详情 mock 路由及 gatewayInvocations 样例已删除,演示开关 fde-mock-gwinv 一并下线 ----
|
|
869
|
+
|
|
870
|
+
// ---- 智能体动态(v2.3):跨源活动流聚合(契约:items 四字段 agent/agentName/projectId/title/
|
|
871
|
+
// preview(≤200字)/startedAt/lastActiveAt/state;state 为各源原生状态,原样展示不翻译)----
|
|
872
|
+
// 演示开关(headless 验收用):localStorage['fde-mock-act'] = 'ok'(默认) | 'empty'(活动流空态) |
|
|
873
|
+
// 'allfail'(四源全失败态);仅影响本接口,验证后立即清除
|
|
874
|
+
if (seg[0] === 'agent-activity' && seg.length === 1 && m === 'GET') {
|
|
875
|
+
const sim = actSimMode();
|
|
876
|
+
const src = d.agentActivity || { items: [], sources: [] };
|
|
877
|
+
const srcs = clone(src.sources || []);
|
|
878
|
+
if (sim === 'empty') {
|
|
879
|
+
return { allOk: true, items: [], sources: srcs.map((s) => ({ id: s.id, ok: true, detail: s.detail })), checkedAt: nowIso() };
|
|
880
|
+
}
|
|
881
|
+
if (sim === 'allfail') {
|
|
882
|
+
return {
|
|
883
|
+
allOk: false, items: [],
|
|
884
|
+
sources: srcs.map((s) => ({ id: s.id, ok: false, detail: `${s.id} 会话库探测超时(allfail 演示态)` })),
|
|
885
|
+
checkedAt: nowIso()
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
const items = (src.items || []).slice()
|
|
889
|
+
.sort((a, b) => Date.parse(b.lastActiveAt || 0) - Date.parse(a.lastActiveAt || 0));
|
|
890
|
+
return { allOk: srcs.length > 0 && srcs.every((s) => s.ok), items: clone(items), sources: srcs, checkedAt: nowIso() };
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
// ---- 任务雷达(PRD-task-inbox):同步/分析走异步 job,收件箱/统计/别名同步返回 ----
|
|
894
|
+
const radarJobs = d.__radarJobs || (d.__radarJobs = {});
|
|
895
|
+
let jobSeq = d.__jobSeq || (d.__jobSeq = 0);
|
|
896
|
+
const mkJob = (kind, total) => {
|
|
897
|
+
const id = `job-${++jobSeq}-${Math.random().toString(36).slice(2, 6)}`;
|
|
898
|
+
const job = { id, kind, state: 'running', total, done: 0, current: null, results: [], startedAt: nowIso(), finishedAt: null, error: null };
|
|
899
|
+
radarJobs[id] = job;
|
|
900
|
+
return job;
|
|
901
|
+
};
|
|
902
|
+
const finishMockJob = (job) => { job.state = 'done'; job.finishedAt = nowIso(); };
|
|
903
|
+
|
|
904
|
+
if (seg[0] === 'radar' && seg[1] === 'sync' && m === 'POST') {
|
|
905
|
+
const job = mkJob('sync', (d.radarMessages || []).length);
|
|
906
|
+
setTimeout(() => { job.done = job.total; job.results.push({ item: 'sync', ok: true, added: 0, skippedExisting: (d.radarMessages || []).length, failed: [] }); finishMockJob(job); }, 500);
|
|
907
|
+
return { jobId: job.id };
|
|
908
|
+
}
|
|
909
|
+
if (seg[0] === 'radar' && seg[1] === 'jobs' && seg.length === 3 && m === 'GET') {
|
|
910
|
+
const job = radarJobs[seg[2]];
|
|
911
|
+
if (!job) throw new ApiError(404, 'JOB_NOT_FOUND', '任务不存在');
|
|
912
|
+
return clone(job);
|
|
913
|
+
}
|
|
914
|
+
if (seg[0] === 'radar' && seg[1] === 'messages' && seg.length === 2 && m === 'GET') {
|
|
915
|
+
return clone(d.radarMessages || [])
|
|
916
|
+
.sort((a, b) => Date.parse(b.occurredAt) - Date.parse(a.occurredAt))
|
|
917
|
+
.map((x) => ({
|
|
918
|
+
id: x.id, source: x.source, kind: x.kind, title: x.title, occurredAt: x.occurredAt,
|
|
919
|
+
ref: x.ref, analyzedAt: x.analyzedAt, analyzeState: x.analyzeState || '', analyzeError: x.analyzeError || null,
|
|
920
|
+
segmentCount: (x.speakerSegments || []).length, truncated: !!x.truncated
|
|
921
|
+
}));
|
|
922
|
+
}
|
|
923
|
+
if (seg[0] === 'radar' && seg[1] === 'messages' && seg.length === 3 && m === 'GET') {
|
|
924
|
+
const msg = (d.radarMessages || []).find((x) => x.id === seg[2]);
|
|
925
|
+
if (!msg) throw new ApiError(404, 'MESSAGE_NOT_FOUND', '消息不存在');
|
|
926
|
+
return clone(msg);
|
|
927
|
+
}
|
|
928
|
+
if (seg[0] === 'radar' && seg[1] === 'engine' && seg.length === 2 && m === 'GET') {
|
|
929
|
+
const dt = d.settings.dingtalk || {};
|
|
930
|
+
const az = d.settings.analyze || {};
|
|
931
|
+
return {
|
|
932
|
+
dingtalk: { enabled: dt.enabled !== false, dwsBin: 'C:\\mock\\dws.exe', fixtureMode: false },
|
|
933
|
+
dsh: { bin: 'C:\\mock\\dsh-bin.js', found: true, fixtureMode: false, timeoutSec: az.timeoutSec || 120 }
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
if (seg[0] === 'radar' && seg[1] === 'engine' && seg[2] === 'test' && m === 'POST') {
|
|
937
|
+
return { ok: true, latencyMs: 900 + Math.floor(Math.random() * 800), reply: 'OK(mock)' };
|
|
938
|
+
}
|
|
939
|
+
if (seg[0] === 'radar' && seg[1] === 'analyze' && seg.length === 2 && m === 'POST') {
|
|
940
|
+
const ids = (body && body.messageIds) || [];
|
|
941
|
+
if (!Array.isArray(ids) || !ids.length || ids.length > 50) throw new ApiError(400, 'FIELD_INVALID', 'messageIds 必填且为 1..50 个消息 id 的数组');
|
|
942
|
+
const eligible = [];
|
|
943
|
+
const skipped = [];
|
|
944
|
+
for (const id of ids) {
|
|
945
|
+
const msg = (d.radarMessages || []).find((x) => x.id === id);
|
|
946
|
+
if (!msg) { skipped.push({ messageId: id, reason: 'NOT_FOUND' }); continue; }
|
|
947
|
+
if (msg.analyzedAt && msg.analyzeState !== 'ANALYZE_FAILED') { skipped.push({ messageId: id, reason: 'ALREADY_ANALYZED' }); continue; }
|
|
948
|
+
eligible.push(msg);
|
|
949
|
+
}
|
|
950
|
+
const job = mkJob('analyze', eligible.length);
|
|
951
|
+
setTimeout(() => {
|
|
952
|
+
for (const msg of eligible) {
|
|
953
|
+
const fx = msg.mockAnalysis;
|
|
954
|
+
if (!fx) { job.results.push({ item: msg.id, ok: false, error: 'mock 数据缺 mockAnalysis' }); msg.analyzeState = 'ANALYZE_FAILED'; msg.analyzedAt = null; }
|
|
955
|
+
else {
|
|
956
|
+
let added = 0;
|
|
957
|
+
for (const t of (fx.tasks || [])) {
|
|
958
|
+
if ((t.confidence || 0) < 0.5) continue;
|
|
959
|
+
if ((d.inbox || []).some((c) => c.messageId === msg.id && c.quote === t.quote && c.title === t.title)) continue;
|
|
960
|
+
d.inbox.push({
|
|
961
|
+
id: `cand-${Math.random().toString(36).slice(2, 8)}`,
|
|
962
|
+
messageId: msg.id, messageTitle: msg.title, occurredAt: msg.occurredAt,
|
|
963
|
+
title: t.title, desc: t.desc || '', priority: t.priority || 'unset',
|
|
964
|
+
suggestedMemberId: t.suggestedMemberId || '',
|
|
965
|
+
matchSource: t.matchSource || null, // v1.8 透传:归人依据(真实后端 analyze 已带,预选说话人依赖它)
|
|
966
|
+
dueHint: t.dueHint || '',
|
|
967
|
+
confidence: t.confidence, quote: t.quote || '', rationale: t.rationale || '',
|
|
968
|
+
speakerRaw: t.speakerRaw || '', state: 'pending', decidedAt: null, createdAt: nowIso()
|
|
969
|
+
});
|
|
970
|
+
added += 1;
|
|
971
|
+
}
|
|
972
|
+
msg.analyzedAt = nowIso();
|
|
973
|
+
msg.analyzeState = 'ok';
|
|
974
|
+
msg.analyzeError = null;
|
|
975
|
+
msg.noise = (fx.noise || []).map((n) => ({ quote: n.quote || '', reason: n.reason || '' }));
|
|
976
|
+
job.results.push({ item: msg.id, ok: true, added });
|
|
977
|
+
}
|
|
978
|
+
job.done += 1;
|
|
979
|
+
}
|
|
980
|
+
finishMockJob(job);
|
|
981
|
+
}, 900);
|
|
982
|
+
return { jobId: job.id, accepted: eligible.length, skipped };
|
|
983
|
+
}
|
|
984
|
+
if (seg[0] === 'inbox' && seg.length === 1 && m === 'GET') {
|
|
985
|
+
const state = q.get('state');
|
|
986
|
+
let list = (d.inbox || []).slice();
|
|
987
|
+
if (state) list = list.filter((x) => x.state === state);
|
|
988
|
+
list.sort((a, b) => (a.state === 'pending' && b.state === 'pending')
|
|
989
|
+
? b.confidence - a.confidence || Date.parse(b.createdAt) - Date.parse(a.createdAt)
|
|
990
|
+
: Date.parse(b.decidedAt || b.createdAt) - Date.parse(a.decidedAt || a.createdAt));
|
|
991
|
+
return clone(list);
|
|
992
|
+
}
|
|
993
|
+
if (seg[0] === 'inbox' && seg[1] === 'stats' && seg.length === 2 && m === 'GET') {
|
|
994
|
+
const cutoff = Date.now() - 30 * 86400 * 1000;
|
|
995
|
+
const counts = { pending: 0, confirmed: 0, rejected: 0, done_already: 0 };
|
|
996
|
+
let c30 = 0, r30 = 0, d30 = 0;
|
|
997
|
+
for (const c of d.inbox || []) {
|
|
998
|
+
if (counts[c.state] !== undefined) counts[c.state] += 1;
|
|
999
|
+
if ((c.state === 'confirmed' || c.state === 'rejected' || c.state === 'done_already')
|
|
1000
|
+
&& c.decidedAt && Date.parse(c.decidedAt) >= cutoff) {
|
|
1001
|
+
if (c.state === 'confirmed') c30 += 1;
|
|
1002
|
+
else if (c.state === 'rejected') r30 += 1;
|
|
1003
|
+
else d30 += 1;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
// v1.7 契约:rejectRate30d = 拒/(确+已完成+拒)——已完成不再被当作误识
|
|
1007
|
+
const den = c30 + d30 + r30;
|
|
1008
|
+
return {
|
|
1009
|
+
...counts,
|
|
1010
|
+
doneAlready: counts.done_already,
|
|
1011
|
+
confirmed30d: c30,
|
|
1012
|
+
rejected30d: r30,
|
|
1013
|
+
doneAlready30d: d30,
|
|
1014
|
+
rejectRate30d: den ? Math.round((r30 / den) * 10000) / 10000 : null
|
|
1015
|
+
};
|
|
1016
|
+
}
|
|
1017
|
+
if (seg[0] === 'inbox' && seg.length === 3 && seg[2] === 'confirm' && m === 'POST') {
|
|
1018
|
+
const cand = (d.inbox || []).find((x) => x.id === seg[1]);
|
|
1019
|
+
if (!cand) throw new ApiError(404, 'CANDIDATE_NOT_FOUND', '候选卡不存在');
|
|
1020
|
+
if (cand.state !== 'pending') throw new ApiError(409, 'ALREADY_DECIDED', `该候选已${cand.state === 'confirmed' ? '确认' : '拒绝'},不可重复决定`);
|
|
1021
|
+
const b = body || {};
|
|
1022
|
+
// 叙事线第一批:任务更新提案(kind:"update")——不建任务,memo 事件写入关联任务时间轴 + origin.relatedMemos 留痕
|
|
1023
|
+
if (cand.kind === 'update') {
|
|
1024
|
+
const target = d.tasks.find((x) => x.id === cand.existingTaskId);
|
|
1025
|
+
if (!target) throw new ApiError(400, 'TASK_NOT_FOUND', '关联任务不存在(可能已被删除),无法记入时间轴');
|
|
1026
|
+
const note = (b.note != null && b.note !== undefined) ? String(b.note).trim() : '';
|
|
1027
|
+
if (note.length > 500) throw new ApiError(400, 'VALIDATION', 'note 备注不能超过 500 字');
|
|
1028
|
+
const now = nowIso();
|
|
1029
|
+
pushEvent(target, 'memo', {
|
|
1030
|
+
from: null, to: null,
|
|
1031
|
+
detail: `${cand.messageTitle || '纪要'}:“${cand.quote || ''}”${note ? ' · 备注:' + note : ''}`
|
|
1032
|
+
});
|
|
1033
|
+
if (!target.origin) target.origin = { type: 'manual', relatedMemos: [] };
|
|
1034
|
+
if (!Array.isArray(target.origin.relatedMemos)) target.origin.relatedMemos = [];
|
|
1035
|
+
target.origin.relatedMemos.push({
|
|
1036
|
+
candidateId: cand.id, messageId: cand.messageId || null,
|
|
1037
|
+
quote: cand.quote || '', note, at: now
|
|
1038
|
+
});
|
|
1039
|
+
target.updatedAt = now;
|
|
1040
|
+
cand.state = 'confirmed';
|
|
1041
|
+
cand.decidedAt = now;
|
|
1042
|
+
cand.note = note;
|
|
1043
|
+
return clone({ task: target, candidate: cand, memoRecorded: true });
|
|
1044
|
+
}
|
|
1045
|
+
const title = b.title !== undefined ? String(b.title).trim() : cand.title;
|
|
1046
|
+
if (!title || title.length > 200) throw new ApiError(400, 'FIELD_INVALID', 'title 必填且为 1..200 字符');
|
|
1047
|
+
let memberId = b.memberId !== undefined ? b.memberId : cand.suggestedMemberId;
|
|
1048
|
+
memberId = memberId || null;
|
|
1049
|
+
let priority = b.priority !== undefined ? b.priority : cand.priority;
|
|
1050
|
+
if (!PRIORITIES.includes(priority)) priority = 'medium';
|
|
1051
|
+
const dueDate = b.dueDate || null;
|
|
1052
|
+
// v1.8 说话人/负责人解耦:别名写「说话人」的名册身份 speakerMemberId(谁说的),与负责成员 memberId(谁做)无关;
|
|
1053
|
+
// 契约:rememberAlias:true 但说话人未映射(未选人/无原始昵称)→ 不写别名,响应 rememberedAlias:null + reason:'SPEAKER_UNRESOLVED'
|
|
1054
|
+
const speakerMemberId = (b.speakerMemberId !== undefined ? b.speakerMemberId : '') || null;
|
|
1055
|
+
let aliasReason = null;
|
|
1056
|
+
let created = false; // 说话人映射目标自动建档/转正时置 true,响应带回(P1-C 语义沿用,落点改为说话人)
|
|
1057
|
+
let rememberedAlias = null;
|
|
1058
|
+
if (b.rememberAlias === true) {
|
|
1059
|
+
if (!cand.speakerRaw || !speakerMemberId) {
|
|
1060
|
+
aliasReason = 'SPEAKER_UNRESOLVED'; // 静默跳过别名,不阻断任务入库
|
|
1061
|
+
} else {
|
|
1062
|
+
let mem = (d.members || []).find((x) => x.id === speakerMemberId);
|
|
1063
|
+
if (!mem) {
|
|
1064
|
+
// P1-C 契约:目标成员不存在(手工名册 + 派生都没有)→ 自动建立名册档案,created:true
|
|
1065
|
+
mem = {
|
|
1066
|
+
id: speakerMemberId, name: String(speakerMemberId), kind: 'human', role: '', giteaLogin: '',
|
|
1067
|
+
enabled: true, manual: true, aliases: [], status: 'idle', currentTask: null,
|
|
1068
|
+
lastActivityAt: null, todayCommits: 0, openPrs: 0, weekDone: 0, session: null
|
|
1069
|
+
};
|
|
1070
|
+
d.members.push(mem);
|
|
1071
|
+
created = true;
|
|
1072
|
+
} else if (mem.manual !== true) {
|
|
1073
|
+
mem.manual = true; // Gitea 派生成员转正为名册条目,created:true
|
|
1074
|
+
created = true;
|
|
1075
|
+
}
|
|
1076
|
+
if (!Array.isArray(mem.aliases)) mem.aliases = [];
|
|
1077
|
+
if (!mem.aliases.some((a) => String(a).toLowerCase() === cand.speakerRaw.toLowerCase())) mem.aliases.push(cand.speakerRaw);
|
|
1078
|
+
rememberedAlias = { memberId: mem.id, alias: cand.speakerRaw, memberCreated: created };
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
const now = nowIso();
|
|
1082
|
+
const task = {
|
|
1083
|
+
id: genTaskId(), title, status: 'todo', agentId: null, memberId, repo: null, branch: null, prUrl: null,
|
|
1084
|
+
notes: '', desc: b.desc !== undefined ? b.desc : (cand.desc || ''), dueDate, priority,
|
|
1085
|
+
artifacts: [],
|
|
1086
|
+
completedAt: null,
|
|
1087
|
+
createdAt: now, updatedAt: now,
|
|
1088
|
+
events: [{ type: 'created', from: null, to: 'todo', detail: '来自任务雷达确认入库', at: now }],
|
|
1089
|
+
origin: { type: 'inbox', refId: cand.id, quote: cand.quote || '' }
|
|
1090
|
+
};
|
|
1091
|
+
d.tasks.push(task);
|
|
1092
|
+
cand.state = 'confirmed';
|
|
1093
|
+
cand.decidedAt = now;
|
|
1094
|
+
cand.confirmedTaskId = task.id;
|
|
1095
|
+
cand.title = title;
|
|
1096
|
+
cand.suggestedMemberId = memberId;
|
|
1097
|
+
cand.speakerMemberId = speakerMemberId; // v1.8 审计留痕:说话人最终映射的身份(null=未映射)
|
|
1098
|
+
cand.dueDate = dueDate;
|
|
1099
|
+
const resp = { task, candidate: cand, created, rememberedAlias };
|
|
1100
|
+
if (aliasReason) resp.reason = aliasReason;
|
|
1101
|
+
return clone(resp);
|
|
1102
|
+
}
|
|
1103
|
+
if (seg[0] === 'inbox' && seg.length === 3 && seg[2] === 'reject' && m === 'POST') {
|
|
1104
|
+
const cand = (d.inbox || []).find((x) => x.id === seg[1]);
|
|
1105
|
+
if (!cand) throw new ApiError(404, 'CANDIDATE_NOT_FOUND', '候选卡不存在');
|
|
1106
|
+
if (cand.state !== 'pending') throw new ApiError(409, 'ALREADY_DECIDED', `该候选已决定过(${cand.state}),不可重复决定`);
|
|
1107
|
+
// v1.7 契约:reason 必填(duplicate/wont_do/invalid/other),缺失 → 400 REASON_REQUIRED
|
|
1108
|
+
const REASONS = ['duplicate', 'wont_do', 'invalid', 'other'];
|
|
1109
|
+
const reason = body && body.reason;
|
|
1110
|
+
if (!REASONS.includes(reason)) {
|
|
1111
|
+
throw new ApiError(400, 'REASON_REQUIRED', '缺少必填的拒绝原因 reason(duplicate / wont_do / invalid / other 四选一)');
|
|
1112
|
+
}
|
|
1113
|
+
const note = (body && body.note !== undefined && body.note !== null) ? String(body.note) : '';
|
|
1114
|
+
if (note.length > 500) throw new ApiError(400, 'VALIDATION', 'note 备注不能超过 500 字');
|
|
1115
|
+
cand.state = 'rejected';
|
|
1116
|
+
cand.reason = reason;
|
|
1117
|
+
cand.note = note;
|
|
1118
|
+
cand.decidedAt = nowIso();
|
|
1119
|
+
return clone(cand);
|
|
1120
|
+
}
|
|
1121
|
+
// v1.7 新增:标记为已完成(这事已经做完了)→ state=done_already,不入看板、计入误识率分母
|
|
1122
|
+
if (seg[0] === 'inbox' && seg.length === 3 && seg[2] === 'done-already' && m === 'POST') {
|
|
1123
|
+
const cand = (d.inbox || []).find((x) => x.id === seg[1]);
|
|
1124
|
+
if (!cand) throw new ApiError(404, 'CANDIDATE_NOT_FOUND', '候选卡不存在');
|
|
1125
|
+
if (cand.state !== 'pending') throw new ApiError(409, 'ALREADY_DECIDED', `该候选已决定过(${cand.state}),不可重复决定`);
|
|
1126
|
+
// 叙事线第一批契约:任务更新提案不适用「已完成」(它不是待办,是对已有任务的补充)
|
|
1127
|
+
if (cand.kind === 'update') {
|
|
1128
|
+
throw new ApiError(409, 'NOT_APPLICABLE', '任务更新提案不适用「已完成」:请确认以记入关联任务时间轴,或拒绝');
|
|
1129
|
+
}
|
|
1130
|
+
const note = (body && body.note !== undefined && body.note !== null) ? String(body.note) : '';
|
|
1131
|
+
if (note.length > 500) throw new ApiError(400, 'VALIDATION', 'note 备注不能超过 500 字');
|
|
1132
|
+
cand.state = 'done_already';
|
|
1133
|
+
cand.note = note;
|
|
1134
|
+
cand.decidedAt = nowIso();
|
|
1135
|
+
return clone(cand);
|
|
1136
|
+
}
|
|
1137
|
+
if (seg[0] === 'members' && seg.length === 3 && seg[2] === 'aliases' && m === 'POST') {
|
|
1138
|
+
const row = (d.members || []).find((x) => x.id === seg[1] && x.manual === true);
|
|
1139
|
+
if (!row) throw new ApiError(404, 'MEMBER_NOT_FOUND', '手工名册中不存在该成员');
|
|
1140
|
+
const alias = String((body && body.alias) || '').trim();
|
|
1141
|
+
if (!alias || alias.length > 50) throw new ApiError(400, 'MEMBER_INVALID', 'alias 必填且为 1..50 字符');
|
|
1142
|
+
if (!Array.isArray(row.aliases)) row.aliases = [];
|
|
1143
|
+
if (!row.aliases.some((a) => String(a).toLowerCase() === alias.toLowerCase())) row.aliases.push(alias);
|
|
1144
|
+
return clone(row);
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
throw new ApiError(404, 'NOT_FOUND', `接口不存在(mock):${m} ${u.pathname}`);
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
registerMock(handle);
|