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
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* learnImport.js — 学习资料的导入器(v2.9.56)
|
|
5
|
+
*
|
|
6
|
+
* 约束:**零第三方依赖**(AGENTS 红线 1),只用 Node 内置模块。
|
|
7
|
+
* 支持:.md / .txt / .html(.htm) / .docx / .pdf
|
|
8
|
+
* - docx = zip + word/document.xml,自己解 zip(中央目录 + inflateRaw)
|
|
9
|
+
* - html = 去 script/style、块级标签换行、解实体
|
|
10
|
+
* - pdf = 解 FlateDecode 流 + 抓文本操作符;**子集字体/扫描件会抽不出字**,如实报错而不是塞垃圾
|
|
11
|
+
*
|
|
12
|
+
* 产出:把文本写成 `data/learn/imports/<slug>.md`(本地学习库),页面索引里用 `import:` 前缀,
|
|
13
|
+
* **绝不写入用户的知识库**。
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const fs = require('node:fs');
|
|
17
|
+
const path = require('node:path');
|
|
18
|
+
const zlib = require('node:zlib');
|
|
19
|
+
|
|
20
|
+
const KINDS = {
|
|
21
|
+
'.md': 'md',
|
|
22
|
+
'.markdown': 'md',
|
|
23
|
+
'.txt': 'txt',
|
|
24
|
+
'.html': 'html',
|
|
25
|
+
'.htm': 'html',
|
|
26
|
+
'.docx': 'docx',
|
|
27
|
+
'.pdf': 'pdf',
|
|
28
|
+
};
|
|
29
|
+
const MAX_FILE_BYTES = 40 * 1024 * 1024;
|
|
30
|
+
const MAX_FILES = 200;
|
|
31
|
+
|
|
32
|
+
function kindOf(filePath) {
|
|
33
|
+
return KINDS[path.extname(String(filePath)).toLowerCase()] || null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function decodeEntities(text) {
|
|
37
|
+
return String(text)
|
|
38
|
+
.replace(/ /gi, ' ')
|
|
39
|
+
.replace(/</gi, '<')
|
|
40
|
+
.replace(/>/gi, '>')
|
|
41
|
+
.replace(/"/gi, '"')
|
|
42
|
+
.replace(/'|'/gi, "'")
|
|
43
|
+
.replace(/&/gi, '&')
|
|
44
|
+
.replace(/&#(\d+);/g, (m, d) => String.fromCodePoint(Number(d)))
|
|
45
|
+
.replace(/&#x([0-9a-f]+);/gi, (m, h) => String.fromCodePoint(parseInt(h, 16)));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** HTML → 纯文本:去脚本样式、块级换行、解实体、压空白 */
|
|
49
|
+
function htmlToText(html) {
|
|
50
|
+
let s = String(html || '');
|
|
51
|
+
s = s.replace(/<!--[\s\S]*?-->/g, ' ');
|
|
52
|
+
s = s.replace(/<(script|style|noscript|svg|head)[\s\S]*?<\/\1>/gi, ' ');
|
|
53
|
+
s = s.replace(/<\/(p|div|section|article|h[1-6]|li|tr|blockquote|pre)>/gi, '\n');
|
|
54
|
+
s = s.replace(/<br\s*\/?>/gi, '\n');
|
|
55
|
+
s = s.replace(/<li[^>]*>/gi, '- ');
|
|
56
|
+
s = s.replace(/<h([1-6])[^>]*>/gi, (m, n) => `${'#'.repeat(Number(n))} `);
|
|
57
|
+
s = s.replace(/<[^>]+>/g, ' ');
|
|
58
|
+
s = decodeEntities(s);
|
|
59
|
+
return s
|
|
60
|
+
.replace(/[ \t\u00a0]+/g, ' ')
|
|
61
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
62
|
+
.split('\n')
|
|
63
|
+
.map((line) => line.trim())
|
|
64
|
+
.join('\n')
|
|
65
|
+
.trim();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// ---------- zip(docx 用) ----------
|
|
69
|
+
|
|
70
|
+
const SIG_EOCD = 0x06054b50;
|
|
71
|
+
const SIG_CENTRAL = 0x02014b50;
|
|
72
|
+
const SIG_LOCAL = 0x04034b50;
|
|
73
|
+
|
|
74
|
+
/** 极简 zip 读取:返回 { [name]: Buffer }(只支持 store/deflate,足够读 docx) */
|
|
75
|
+
function readZip(buf) {
|
|
76
|
+
const entries = {};
|
|
77
|
+
let eocd = -1;
|
|
78
|
+
for (let i = buf.length - 22; i >= 0 && i > buf.length - 66000; i--) {
|
|
79
|
+
if (buf.readUInt32LE(i) === SIG_EOCD) {
|
|
80
|
+
eocd = i;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (eocd < 0) throw new Error('不是有效的 zip/docx(找不到中央目录)');
|
|
85
|
+
const count = buf.readUInt16LE(eocd + 10);
|
|
86
|
+
let off = buf.readUInt32LE(eocd + 16);
|
|
87
|
+
for (let i = 0; i < count; i++) {
|
|
88
|
+
if (off + 46 > buf.length || buf.readUInt32LE(off) !== SIG_CENTRAL) break;
|
|
89
|
+
const method = buf.readUInt16LE(off + 10);
|
|
90
|
+
const compSize = buf.readUInt32LE(off + 20);
|
|
91
|
+
const nameLen = buf.readUInt16LE(off + 28);
|
|
92
|
+
const extraLen = buf.readUInt16LE(off + 30);
|
|
93
|
+
const commentLen = buf.readUInt16LE(off + 32);
|
|
94
|
+
const localOff = buf.readUInt32LE(off + 42);
|
|
95
|
+
const name = buf.slice(off + 46, off + 46 + nameLen).toString('utf8');
|
|
96
|
+
off += 46 + nameLen + extraLen + commentLen;
|
|
97
|
+
if (localOff + 30 > buf.length || buf.readUInt32LE(localOff) !== SIG_LOCAL) continue;
|
|
98
|
+
const lNameLen = buf.readUInt16LE(localOff + 26);
|
|
99
|
+
const lExtraLen = buf.readUInt16LE(localOff + 28);
|
|
100
|
+
const dataStart = localOff + 30 + lNameLen + lExtraLen;
|
|
101
|
+
const raw = buf.slice(dataStart, dataStart + compSize);
|
|
102
|
+
if (!raw.length) continue;
|
|
103
|
+
try {
|
|
104
|
+
entries[name] = method === 0 ? raw : zlib.inflateRawSync(raw);
|
|
105
|
+
} catch (e) {
|
|
106
|
+
/* 单个条目坏了不影响其它 */
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return entries;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** docx → 文本:<w:p> 分段、<w:t> 取字 */
|
|
113
|
+
function docxToText(buf) {
|
|
114
|
+
const files = readZip(buf);
|
|
115
|
+
const docName = Object.keys(files).find((n) => /^word\/document\d*\.xml$/.test(n));
|
|
116
|
+
if (!docName) throw new Error('docx 里找不到 word/document.xml');
|
|
117
|
+
const xml = files[docName].toString('utf8');
|
|
118
|
+
const body = xml.replace(/<w:tbl[\s\S]*?<\/w:tbl>/g, (tbl) => `${tbl}\n`);
|
|
119
|
+
const paragraphs = body.split(/<\/w:p>/);
|
|
120
|
+
const lines = [];
|
|
121
|
+
for (const p of paragraphs) {
|
|
122
|
+
const texts = Array.from(p.matchAll(/<w:t(?:\s[^>]*)?>([\s\S]*?)<\/w:t>/g)).map((m) => m[1]);
|
|
123
|
+
if (!texts.length) continue;
|
|
124
|
+
lines.push(decodeEntities(texts.join('')).replace(/\s+/g, ' ').trim());
|
|
125
|
+
}
|
|
126
|
+
return lines.filter(Boolean).join('\n');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// ---------- pdf ----------
|
|
130
|
+
|
|
131
|
+
function decodePdfString(s) {
|
|
132
|
+
return s
|
|
133
|
+
.replace(/\\([nrtbf])/g, (m, c) => ({ n: '\n', r: '\n', t: '\t', b: '', f: '' }[c] || c))
|
|
134
|
+
.replace(/\\([()\\])/g, '$1')
|
|
135
|
+
.replace(/\\(\d{1,3})/g, (m, oct) => String.fromCharCode(parseInt(oct, 8)));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** 从解压后的内容流里抓文本操作符(Tj / TJ / ' / ") */
|
|
139
|
+
function textFromContent(content) {
|
|
140
|
+
const out = [];
|
|
141
|
+
const pickStrings = (chunk) => {
|
|
142
|
+
const parts = [];
|
|
143
|
+
for (const m of chunk.matchAll(/\(((?:\\.|[^\\()])*)\)/g)) parts.push(decodePdfString(m[1]));
|
|
144
|
+
return parts.join('');
|
|
145
|
+
};
|
|
146
|
+
for (const m of content.matchAll(/\[([\s\S]*?)\]\s*TJ/g)) out.push(pickStrings(m[1]));
|
|
147
|
+
for (const m of content.matchAll(/\(((?:\\.|[^\\()])*)\)\s*(?:Tj|'|")/g)) out.push(decodePdfString(m[1]));
|
|
148
|
+
return out.join('');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** pdf → 文本(尽力而为;抽不出来就明确失败,不塞垃圾) */
|
|
152
|
+
function pdfToText(buf) {
|
|
153
|
+
const raw = buf.toString('latin1');
|
|
154
|
+
const chunks = [];
|
|
155
|
+
const re = /stream\r?\n/g;
|
|
156
|
+
let m;
|
|
157
|
+
while ((m = re.exec(raw)) !== null) {
|
|
158
|
+
const start = m.index + m[0].length;
|
|
159
|
+
const end = raw.indexOf('endstream', start);
|
|
160
|
+
if (end < 0) break;
|
|
161
|
+
const slice = buf.slice(start, end);
|
|
162
|
+
let content = null;
|
|
163
|
+
try {
|
|
164
|
+
content = zlib.inflateSync(slice).toString('latin1');
|
|
165
|
+
} catch (e) {
|
|
166
|
+
// 未压缩流:直接当文本内容试一次
|
|
167
|
+
content = slice.toString('latin1');
|
|
168
|
+
}
|
|
169
|
+
if (content && /(Tj|TJ)\b/.test(content)) chunks.push(textFromContent(content));
|
|
170
|
+
re.lastIndex = end + 9;
|
|
171
|
+
}
|
|
172
|
+
const text = chunks
|
|
173
|
+
.join('\n')
|
|
174
|
+
.replace(/[ \t]+/g, ' ')
|
|
175
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
176
|
+
.trim();
|
|
177
|
+
const usable = (text.match(/[\u4e00-\u9fa5A-Za-z0-9]/g) || []).length;
|
|
178
|
+
return { text, usable };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ---------- 统一入口 ----------
|
|
182
|
+
|
|
183
|
+
/** 读一个文件并抽取文本:返回 {ok, kind, text, chars, warning?} */
|
|
184
|
+
function extractText(filePath) {
|
|
185
|
+
const kind = kindOf(filePath);
|
|
186
|
+
if (!kind) return { ok: false, kind: null, reason: '不支持的格式(支持 md/txt/html/docx/pdf)' };
|
|
187
|
+
let st;
|
|
188
|
+
try {
|
|
189
|
+
st = fs.statSync(filePath);
|
|
190
|
+
} catch (e) {
|
|
191
|
+
return { ok: false, kind, reason: `读不到文件:${path.basename(filePath)}` };
|
|
192
|
+
}
|
|
193
|
+
if (st.size > MAX_FILE_BYTES) return { ok: false, kind, reason: '文件超过 40MB,先拆分' };
|
|
194
|
+
let buf;
|
|
195
|
+
try {
|
|
196
|
+
buf = fs.readFileSync(filePath);
|
|
197
|
+
} catch (e) {
|
|
198
|
+
return { ok: false, kind, reason: '读取失败(权限或文件被占用)' };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
let text = '';
|
|
202
|
+
let warning = null;
|
|
203
|
+
try {
|
|
204
|
+
if (kind === 'md' || kind === 'txt') {
|
|
205
|
+
text = buf.toString('utf8');
|
|
206
|
+
} else if (kind === 'html') {
|
|
207
|
+
text = htmlToText(buf.toString('utf8'));
|
|
208
|
+
} else if (kind === 'docx') {
|
|
209
|
+
text = docxToText(buf);
|
|
210
|
+
} else if (kind === 'pdf') {
|
|
211
|
+
const r = pdfToText(buf);
|
|
212
|
+
text = r.text;
|
|
213
|
+
if (r.usable < 120) {
|
|
214
|
+
return {
|
|
215
|
+
ok: false,
|
|
216
|
+
kind,
|
|
217
|
+
reason: 'PDF 没抽出可用文本(扫描件或子集字体编码)——先用 OCR/转换工具转成 md 再导入',
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
if (r.usable < 400) warning = '抽取到的文本较少,可能是版式复杂或部分页面为图片';
|
|
221
|
+
}
|
|
222
|
+
} catch (e) {
|
|
223
|
+
return { ok: false, kind, reason: String((e && e.message) || e).slice(0, 200) };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
text = String(text || '').trim();
|
|
227
|
+
if (text.length < 20) return { ok: false, kind, reason: '抽取出的文本太少(<20 字),放弃导入' };
|
|
228
|
+
return { ok: true, kind, text, chars: text.length, warning };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** 从路径收集待导入文件(文件 → 单个;目录 → 递归受支持格式) */
|
|
232
|
+
function collectFiles(inputPath) {
|
|
233
|
+
const abs = path.resolve(String(inputPath || '').trim());
|
|
234
|
+
let st;
|
|
235
|
+
try {
|
|
236
|
+
st = fs.statSync(abs);
|
|
237
|
+
} catch (e) {
|
|
238
|
+
return { ok: false, reason: `路径不存在:${inputPath}` };
|
|
239
|
+
}
|
|
240
|
+
if (st.isFile()) {
|
|
241
|
+
return kindOf(abs) ? { ok: true, files: [abs] } : { ok: false, reason: '该文件格式不在支持范围(md/txt/html/docx/pdf)' };
|
|
242
|
+
}
|
|
243
|
+
const files = [];
|
|
244
|
+
const walk = (dir) => {
|
|
245
|
+
if (files.length >= MAX_FILES) return;
|
|
246
|
+
let entries;
|
|
247
|
+
try {
|
|
248
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
249
|
+
} catch (e) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
for (const ent of entries) {
|
|
253
|
+
if (files.length >= MAX_FILES) return;
|
|
254
|
+
if (ent.name.startsWith('.')) continue;
|
|
255
|
+
const full = path.join(dir, ent.name);
|
|
256
|
+
if (ent.isDirectory()) walk(full);
|
|
257
|
+
else if (kindOf(ent.name)) files.push(full);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
walk(abs);
|
|
261
|
+
if (!files.length) return { ok: false, reason: '目录里没有可导入的文件' };
|
|
262
|
+
return { ok: true, files };
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function slugify(filePath) {
|
|
266
|
+
const base = path.basename(filePath).replace(/\.[^.]+$/, '');
|
|
267
|
+
const ascii = base.replace(/[^\w\u4e00-\u9fa5-]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 60);
|
|
268
|
+
const hash = require('node:crypto').createHash('sha1').update(filePath).digest('hex').slice(0, 6);
|
|
269
|
+
return `${ascii || 'doc'}-${hash}`;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
module.exports = {
|
|
273
|
+
KINDS,
|
|
274
|
+
MAX_FILES,
|
|
275
|
+
kindOf,
|
|
276
|
+
htmlToText,
|
|
277
|
+
readZip,
|
|
278
|
+
docxToText,
|
|
279
|
+
pdfToText,
|
|
280
|
+
extractText,
|
|
281
|
+
collectFiles,
|
|
282
|
+
slugify,
|
|
283
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* learnSeeds.js — 内置主题知识点(v2.9.52)
|
|
5
|
+
*
|
|
6
|
+
* 为什么需要:知识库只读、且以业务/行业笔记为主,缺工程侧的系统知识。这些主题跟插件一起走,
|
|
7
|
+
* 不联网、不写 vault;和 vault 抽出来的知识点走同一套调度与会话流程。
|
|
8
|
+
*
|
|
9
|
+
* 每条:term(术语)+ definition(≤60 字白话)+ why(≤40 字,为什么重要)。
|
|
10
|
+
* 只放**靠得住、不随时间快速过期**的条目(模型/语言/Agent 工程的基础概念),
|
|
11
|
+
* 版本号、榜单、参数推荐这类会过期的内容一律不进。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const SEEDS = {
|
|
15
|
+
'模型与推理': [
|
|
16
|
+
{ term: '上下文窗口', definition: '模型一次能看到的 token 上限,含输入与输出;超出就得截断或压缩', why: '决定长文档/长对话怎么切,以及成本上限' },
|
|
17
|
+
{ term: 'KV cache', definition: '把已算过的注意力 Key/Value 缓存下来,后续 token 复用,避免重算', why: '长上下文能跑起来靠它,显存占用也主要吃它' },
|
|
18
|
+
{ term: '预填充 vs 解码', definition: '预填充并行处理整段输入、吃算力;解码逐 token 生成、吃显存带宽', why: '两类负载瓶颈不同,优化手段也不同' },
|
|
19
|
+
{ term: '温度与 Top-p', definition: '温度缩放概率分布,Top-p 截断候选集合;都为 0/1 时趋近确定性输出', why: '要稳定判分就压低,要发散创意就调高' },
|
|
20
|
+
{ term: '量化', definition: '把权重/激活从 FP16 压到 INT8/INT4 等低精度表示,换显存与速度', why: '同样的卡能跑更大模型,代价是精度与长尾能力' },
|
|
21
|
+
{ term: 'MoE 稀疏激活', definition: '多个专家子网络,每个 token 只激活其中少数几个,参数总量大但计算量小', why: '解释为什么"参数很多却很便宜",以及专家负载不均的坑' },
|
|
22
|
+
{ term: '注意力复杂度', definition: '标准注意力代价随序列长度平方增长;FlashAttention 靠分块与重算降显存', why: '长上下文成本从哪来、为什么有上限' },
|
|
23
|
+
{ term: '投机解码', definition: '小模型先草拟若干 token,大模型一次并行校验,接受的直接采纳', why: '不降质提速的典型工程手段' },
|
|
24
|
+
{ term: 'LoRA 微调', definition: '冻结原权重,只训练低秩旁路矩阵,用极少参数改变行为', why: '个人/小团队做领域适配的默认选择' },
|
|
25
|
+
{ term: 'RLHF 与 DPO', definition: '用人类偏好把模型往"更有用更安全"对齐;DPO 省掉显式奖励模型', why: '理解对齐训练与"为什么模型话术这么像"的来源' },
|
|
26
|
+
{ term: '幻觉的成因', definition: '模型优化的是下一个 token 的似然,不是事实性;缺知识时会生成流畅的错', why: '决定要不要检索、要不要让它"不确定就说不确定"' },
|
|
27
|
+
{ term: '评测集污染', definition: '训练数据里混进了评测题,分数虚高但真实能力没提升', why: '看到"某模型某项 90 分"先问污染' },
|
|
28
|
+
{ term: '提示注入', definition: '把恶意指令藏在被检索的内容里,模型把它当成指令执行', why: '凡是读外部内容的 Agent 都必须防' },
|
|
29
|
+
{ term: '结构化输出约束', definition: '用 JSON schema / 语法解码限制输出形态,而不是靠提示词"请输出 JSON"', why: '下游要解析就必须上硬约束,别赌模型听话' },
|
|
30
|
+
],
|
|
31
|
+
'Java': [
|
|
32
|
+
{ term: 'JMM 与 happens-before', definition: 'Java 内存模型规定线程间可见性规则;happens-before 是判断"能否看到写入"的依据', why: '并发 bug 的根因几乎都在这' },
|
|
33
|
+
{ term: 'volatile 语义', definition: '保证可见性与禁止重排序,但**不保证**复合操作原子性', why: '别拿它当锁用(i++ 仍会丢更新)' },
|
|
34
|
+
{ term: 'CAS 与 ABA', definition: '比较并交换实现无锁更新;值被改回原样时可能漏判,需版本号', why: '原子类的底层,也是无锁栈的经典坑' },
|
|
35
|
+
{ term: '锁升级', definition: '偏向锁→轻量级锁(自旋)→重量级锁,按竞争程度升级', why: '解释"synchronized 为什么没想象中慢"' },
|
|
36
|
+
{ term: '垃圾回收分代', definition: '按对象存活时间分年轻代/老年代,各自用不同算法回收', why: '调优参数与停顿来源都从这里推' },
|
|
37
|
+
{ term: 'G1 与 ZGC', definition: 'G1 按 Region 增量回收、可预测停顿;ZGC 靠染色指针与并发整理做到毫秒级停顿', why: '大堆低延迟场景怎么选' },
|
|
38
|
+
{ term: '类加载双亲委派', definition: '加载类时先交给父加载器,父加载器找不到才自己加载', why: '解释同名类冲突、SPI 为什么需要打破它' },
|
|
39
|
+
{ term: '线程池核心参数', definition: '核心/最大线程数、队列、拒绝策略、空闲回收共同决定行为', why: '队列选错会让"扩容"永远不触发,任务堆积' },
|
|
40
|
+
{ term: '虚拟线程', definition: '由 JVM 调度的轻量线程,阻塞时自动让出载体线程', why: '把"一请求一线程"重新变得可行' },
|
|
41
|
+
{ term: '逃逸分析与 JIT', definition: 'JIT 判断对象不逃逸就栈上分配/标量替换,热点代码编译成本地码', why: '解释"为什么小对象没想象中贵"' },
|
|
42
|
+
{ term: '集合 fail-fast', definition: '迭代中结构性修改会抛 ConcurrentModificationException(基于 modCount)', why: '别在 for-each 里删元素' },
|
|
43
|
+
{ term: 'HashMap 扩容与树化', definition: '负载因子 0.75 触发扩容翻倍;链表超 8 且容量≥64 转红黑树', why: '预分配容量避免反复 rehash' },
|
|
44
|
+
{ term: 'CompletableFuture 组合', definition: '用 thenApply/thenCompose/allOf 表达异步编排与依赖关系', why: '比回调地狱可读,也比并行流可控' },
|
|
45
|
+
{ term: 'JPMS 模块化', definition: '用 module-info 声明依赖与导出,强封装内部包', why: '大工程拆分与依赖收敛的手段' },
|
|
46
|
+
],
|
|
47
|
+
'Agent 开发': [
|
|
48
|
+
{ term: '工具调用协议', definition: '模型输出结构化调用(name+arguments),运行时执行后把结果作为消息回灌', why: 'Agent 的手脚全靠它,schema 质量决定成功率' },
|
|
49
|
+
{ term: 'ReAct 循环', definition: '思考→行动→观察的循环,每步根据观察结果再决定下一步', why: '最基础的 Agent 骨架,也是"为什么会绕圈"的来源' },
|
|
50
|
+
{ term: '上下文工程', definition: '决定每一步把哪些信息放进窗口、以什么顺序放、何时裁剪', why: '比提示词措辞更决定上限' },
|
|
51
|
+
{ term: '记忆分层', definition: '短期(对话窗口)/工作(任务清单)/长期(外部存储检索)三层', why: '混在一起就会既忘事又塞满窗口' },
|
|
52
|
+
{ term: '规划与反思', definition: '先拆计划再执行,失败后回看轨迹修正,而不是一条路走到黑', why: '长任务成功率主要靠这个' },
|
|
53
|
+
{ term: '子代理编排', definition: '主代理把独立子任务派给隔离上下文的子代理,回收结论而非全过程', why: '省上下文、可并行,但要防结论失真' },
|
|
54
|
+
{ term: 'MCP', definition: 'Model Context Protocol:把工具/资源以标准协议暴露给任意 Agent 宿主', why: '一次接入、多客户端复用' },
|
|
55
|
+
{ term: 'RAG 检索增强', definition: '先检索相关片段再让模型基于片段回答,把"记忆"外置', why: '事实性问题的默认解法,难点在切分与召回' },
|
|
56
|
+
{ term: '轨迹回放', definition: '把一次运行的每步输入输出存下来,可重放、可对比、可回归', why: 'Agent 调试与评测的地基' },
|
|
57
|
+
{ term: '幂等与重试', definition: '同一请求重发不产生副作用;配合退避与超时才敢重试', why: 'Agent 一定会重试,工具不做幂等就会写脏数据' },
|
|
58
|
+
{ term: '沙箱与权限边界', definition: '把文件/网络/命令能力按最小权限授予,并按操作风险分级审批', why: 'Agent 犯错是常态,边界决定损失上限' },
|
|
59
|
+
{ term: '成本与延迟预算', definition: '每次调用都有 token 与时间预算,超预算降级(换小模型/裁剪上下文)', why: '没有预算的 Agent 会自己把自己烧死' },
|
|
60
|
+
{ term: '可观测性 span', definition: '把一次运行拆成带耗时与状态的 span 树,定位瓶颈与失败点', why: '出问题先看 trace,别靠猜' },
|
|
61
|
+
{ term: '评测:判据而非感觉', definition: '用固定用例 + 可判定的通过条件(断言、打分器)衡量改动是否真的更好', why: 'LLM 应用最容易"感觉变好了"' },
|
|
62
|
+
],
|
|
63
|
+
'Python': [
|
|
64
|
+
{ term: 'GIL', definition: 'CPython 全局解释器锁,同一时刻只有一个线程执行字节码', why: '解释为什么多线程吃不满 CPU、要换多进程' },
|
|
65
|
+
{ term: 'asyncio 事件循环', definition: '单线程协作式并发:await 处让出控制权,循环调度其他任务', why: 'IO 密集高并发的主力,但阻塞调用会卡死全队' },
|
|
66
|
+
{ term: '生成器与协程', definition: 'yield 产出值并暂停;async/await 是其上的协程语法', why: '流式处理与异步的共同底层' },
|
|
67
|
+
{ term: '描述符协议', definition: '__get__/__set__ 定义属性访问行为,property/classmethod 都是它的应用', why: '读懂 ORM 与框架魔法' },
|
|
68
|
+
{ term: 'MRO 与 C3', definition: '多继承的方法解析顺序,按 C3 线性化保证单调性', why: 'super() 到底调用谁,靠它' },
|
|
69
|
+
{ term: '上下文管理器', definition: 'with 语句靠 __enter__/__exit__ 保证资源释放与异常处理', why: '文件/锁/事务的标准写法' },
|
|
70
|
+
{ term: '可变默认参数陷阱', definition: 'def f(x=[]) 的默认值在函数定义时只创建一次,会被跨调用共享', why: '经典 bug,改成 None 再判断' },
|
|
71
|
+
{ term: '引用计数与循环 GC', definition: '主要靠引用计数回收,循环引用交给分代循环检测器', why: '解释 __del__ 与内存泄漏排查' },
|
|
72
|
+
{ term: 'dataclass 与 slots', definition: '@dataclass 生成样板方法;slots=True 用固定槽位省内存', why: '数据类优先用它,而不是手写 __init__' },
|
|
73
|
+
{ term: '类型提示与 TypeVar', definition: '注解不参与运行,靠类型检查器校验;TypeVar 表达泛型约束', why: '大项目里 type hint 就是文档与护栏' },
|
|
74
|
+
{ term: '打包与依赖解析', definition: 'pyproject.toml 声明构建与依赖,wheel 是预构建分发格式', why: '别再用 setup.py 裸写,锁文件才可复现' },
|
|
75
|
+
{ term: 'C 扩展与 Cython', definition: '把热点逻辑用 C/Cython 编译,绕开解释器开销', why: '纯 Python 提速的最后手段' },
|
|
76
|
+
{ term: '鸭子类型与 Protocol', definition: '看行为不看类型;typing.Protocol 让静态检查也认这套', why: '写可替换组件时的正确姿势' },
|
|
77
|
+
{ term: 'GIL 之外:multiprocessing', definition: '多进程各持独立解释器与内存,靠序列化通信', why: 'CPU 密集任务的常规解法,代价是内存与 IPC' },
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// v2.9.53 追加「AI 工程」:来自 aieng-zh.cn 术语表(MIT)的精选,定义由本仓库自写
|
|
82
|
+
SEEDS['AI 工程'] = require('./learnSeedsAiEng').CONCEPTS;
|
|
83
|
+
const DOMAINS = Object.keys(SEEDS);
|
|
84
|
+
|
|
85
|
+
/** 主题名 → 条目(带 id 种子用) */
|
|
86
|
+
function seedConcepts(domain) {
|
|
87
|
+
const list = SEEDS[domain];
|
|
88
|
+
if (!Array.isArray(list)) return [];
|
|
89
|
+
return list.map((c) => ({
|
|
90
|
+
domain,
|
|
91
|
+
term: c.term,
|
|
92
|
+
definition: c.definition,
|
|
93
|
+
why: c.why || '',
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
module.exports = { SEEDS, DOMAINS, seedConcepts };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* learnSeedsAiEng.js — 「AI 工程从零开始」(aieng-zh.cn) 术语表精选(v2.9.53)
|
|
5
|
+
*
|
|
6
|
+
* 来源:https://aieng-zh.cn/glossary.html(开源 · MIT)。这里**只取术语名**,
|
|
7
|
+
* 定义与"为什么重要"由本仓库自行撰写(不逐字复制原站文案),便于二次分发。
|
|
8
|
+
* 选材原则:补 `lib/learnSeeds.js` 里没覆盖的维度——检索/RAG、服务与基础设施、
|
|
9
|
+
* 评估方法论、可靠性、AI-native 工程实践;已有条目(KV cache、量化、MoE、上下文工程…)不重复收。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const CONCEPTS = [
|
|
13
|
+
// —— 检索与生成 ——
|
|
14
|
+
{ term: '分块 Chunking', definition: '把长文档切成检索单元,按语义边界切比按固定字数切好', why: '切坏了,再好的向量模型也救不回来' },
|
|
15
|
+
{ term: '稠密检索 Dense Retrieval', definition: '用向量相似度找语义相近的片段,不依赖关键词命中', why: '能召回"换了说法"的内容,也会召回"看起来像"的错东西' },
|
|
16
|
+
{ term: '混合检索 Hybrid Retrieval', definition: '关键词(BM25)与向量检索并用,再融合两路结果', why: '专有名词靠关键词、同义表达靠向量,单路总有盲区' },
|
|
17
|
+
{ term: 'RRF 倒数排名融合', definition: '按各路的排名取倒数求和来合并结果,不需要分数可比', why: '两路检索分数量纲不同,用它最省事也最稳' },
|
|
18
|
+
{ term: '重排 Reranker', definition: '对初筛出的 Top-N 用交叉编码器精排,代价高但准', why: '召回靠便宜模型,精度靠这一步' },
|
|
19
|
+
{ term: 'HNSW', definition: '分层可导航小世界图,近似最近邻索引的常用结构', why: '向量库的性能与召回率主要取决于它和参数' },
|
|
20
|
+
{ term: 'Recall@K', definition: '前 K 个结果里命中正确条目的比例', why: 'RAG 的上限由召回决定,先量它再谈生成' },
|
|
21
|
+
{ term: 'Grounding 落地性', definition: '回答能否追溯到给定材料,而不是模型自己编的', why: '没有落地性就没有可审计性' },
|
|
22
|
+
{ term: '语义缓存', definition: '按语义相似度命中历史答案,避免重复调用模型', why: '客服/FAQ 场景最省钱的优化,但要防答错题被复用' },
|
|
23
|
+
|
|
24
|
+
// —— 服务与基础设施 ——
|
|
25
|
+
{ term: 'TTFT 首字延迟', definition: '从请求发出到收到第一个 token 的时间', why: '用户体感主要由它决定,而不是总时长' },
|
|
26
|
+
{ term: 'TPOT 每 token 时间', definition: '首字之后平均每个输出 token 的耗时', why: '决定"读起来顺不顺"' },
|
|
27
|
+
{ term: '持续批处理', definition: '不等整批结束,边跑边把新请求插进批次', why: '吞吐提升的关键,也是延迟抖动的来源' },
|
|
28
|
+
{ term: '分页 KV Cache', definition: '把 KV 缓存按页管理,像虚拟内存一样按需分配', why: '解决长上下文下显存碎片与浪费' },
|
|
29
|
+
{ term: '前缀缓存', definition: '相同前缀(系统提示、长文档)的 KV 直接复用', why: '同一份长材料反复问,成本能差好几倍' },
|
|
30
|
+
{ term: '张量并行', definition: '把单层权重切到多卡上算,卡间频繁通信', why: '大模型单卡放不下时的第一选择' },
|
|
31
|
+
{ term: '分离式服务', definition: '预填充与解码跑在不同实例上,各自按瓶颈选硬件', why: '两类负载瓶颈不同,混跑谁都跑不好' },
|
|
32
|
+
{ term: 'Goodput 有效吞吐', definition: '满足延迟目标的那部分吞吐,而非总吞吐', why: '总吞吐漂亮但超时一堆,等于没服务' },
|
|
33
|
+
|
|
34
|
+
// —— 评估方法论 ——
|
|
35
|
+
{ term: '评测集 Eval Set', definition: '固定、可复现、带判据的样本集合,用来对比改动', why: '没有它,所有"感觉变好了"都不算数' },
|
|
36
|
+
{ term: 'LLM 当裁判', definition: '用强模型按 rubric 给输出打分,代替人工评', why: '规模化评估的现实手段,但要防位置/长度偏见' },
|
|
37
|
+
{ term: '判定口径 Calibration', definition: '模型自报的置信度与实际正确率是否一致', why: '自评 90% 实际 30% 的系统不能自动放行' },
|
|
38
|
+
{ term: 'Pass@k', definition: '采样 k 次至少有一次通过的比例', why: '衡量"能不能做对",而不是"一次就对"' },
|
|
39
|
+
{ term: '精确率与召回率', definition: '精确率=报对的占报出的比例;召回率=报出的占该报的比例', why: '二者互斥,先定业务更要哪个' },
|
|
40
|
+
{ term: '验证门 Verification Gate', definition: '产出必须通过可判定检查(测试/断言)才算完成', why: '把"看似完成"挡在门外' },
|
|
41
|
+
{ term: '护栏 Guardrails', definition: '对输入输出做规则/模型双重拦截:越权、敏感、格式', why: '模型不可信,护栏是最后一道闸' },
|
|
42
|
+
|
|
43
|
+
// —— 可靠性 ——
|
|
44
|
+
{ term: 'SLI 与 SLO', definition: 'SLI 是可测指标(成功率/延迟分位),SLO 是它的目标值', why: '没有 SLO 就没法判断"该不该回滚"' },
|
|
45
|
+
{ term: '错误预算', definition: '允许失败的那部分额度,用完就冻结变更', why: '把可靠性变成可协商的资源,而不是口号' },
|
|
46
|
+
{ term: '尾延迟', definition: 'P95/P99 这类长尾延迟,而不是平均值', why: '用户感知的是最慢的那几次' },
|
|
47
|
+
{ term: '优雅降级', definition: '依赖挂了时退到更弱但仍可用的路径', why: '大模型不可用不等于功能不可用' },
|
|
48
|
+
{ term: '熔断 Circuit Breaker', definition: '连续失败达到阈值就快速失败,不再打下游', why: '防止雪崩,给下游恢复时间' },
|
|
49
|
+
{ term: '退避重试', definition: '失败后按指数退避加抖动重试,并设总预算', why: '无节制重试会把小故障放大成事故' },
|
|
50
|
+
{ term: '幂等性', definition: '同一请求重复执行,结果与副作用只发生一次', why: 'Agent 一定会重试,工具不幂等就会写脏数据' },
|
|
51
|
+
{ term: '读就绪探针', definition: '启动完成、依赖可用才接流量', why: '避免把请求打给还没准备好的实例' },
|
|
52
|
+
{ term: '灰度发布', definition: '先给一小部分流量,观察指标再扩大', why: '模型/提示词改动的爆炸半径要可控' },
|
|
53
|
+
{ term: '复盘 Postmortem', definition: '事故后写清时间线、根因、改进项与责任人', why: '不写复盘,同样的坑会再踩' },
|
|
54
|
+
|
|
55
|
+
// —— Agent 与工具 ——
|
|
56
|
+
{ term: '工具契约 Tool Contract', definition: '工具的入参、出参、错误码与副作用必须写死并被校验', why: '模型靠描述猜用法,描述含糊就会乱调' },
|
|
57
|
+
{ term: '结构化输出', definition: '用 schema/语法约束模型输出形态,而不是"请返回 JSON"', why: '下游要解析就必须上硬约束' },
|
|
58
|
+
{ term: 'Agent 宿主 Harness', definition: '包在模型外面的运行时:工具、权限、循环、持久化', why: '同一模型换个 harness,能力差一个档' },
|
|
59
|
+
{ term: '终止条件', definition: '明确何时停:达成目标、超预算、连续失败、需人工', why: '没有终止条件的 agent 会烧钱到天亮' },
|
|
60
|
+
{ term: '人工介入 HITL', definition: '高风险动作前挂审批,由人放行', why: '不可逆操作的唯一保险' },
|
|
61
|
+
{ term: '委派 Delegation', definition: '把独立子任务交给隔离子代理,只回收结论', why: '省上下文、可并行,但结论会失真' },
|
|
62
|
+
{ term: '持久执行 Durable Execution', definition: '每步状态落盘,进程崩了能从断点续跑', why: '长任务不能因为一次重启全丢' },
|
|
63
|
+
{ term: '补偿动作', definition: '已发生的副作用用反向操作抵消,而不是假装没发生', why: '分布式里没有事务,只有补偿' },
|
|
64
|
+
{ term: '权限最小化', definition: '只授予完成任务所需的最小能力与范围', why: 'Agent 犯错是常态,边界决定损失上限' },
|
|
65
|
+
|
|
66
|
+
// —— AI-native 工程 ——
|
|
67
|
+
{ term: '模型路由', definition: '按任务难度/成本把请求分给不同模型', why: '80% 简单请求不该用最贵的模型' },
|
|
68
|
+
{ term: '可观测性', definition: '日志/指标/追踪三者齐备,能回答"刚才那步为什么慢/错"', why: '出问题先看数据,别靠猜' },
|
|
69
|
+
{ term: '任务成功成本', definition: '完成一个任务的平均花费(含重试与人工),不是单次调用价', why: '便宜模型但重试 5 次,可能更贵' },
|
|
70
|
+
{ term: '回归测试', definition: '改一处后重跑固定用例集,确认没把别处改坏', why: '提示词的改动最容易"这边好那边崩"' },
|
|
71
|
+
{ term: '抖动测试 Flaky Test', definition: '同一输入时过时不过的用例', why: '它让整个测试集失去公信力,必须隔离' },
|
|
72
|
+
{ term: '范围契约 Scope Contract', definition: '明确本次任务做什么、不做什么、可改哪些文件', why: '防 agent 顺手改一堆无关代码' },
|
|
73
|
+
{ term: '渐进披露', definition: '先给最小必要信息,需要时再展开细节', why: '上下文有限,一次灌满反而更笨' },
|
|
74
|
+
{ term: '仓储地图 Repository Map', definition: '给 agent 一张"哪个文件负责什么"的索引', why: '省掉盲目搜索的几十次工具调用' },
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
module.exports = { CONCEPTS, SOURCE: 'https://aieng-zh.cn/glossary.html(MIT)' };
|
package/lib/mcpCore.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* mcpCore.js — v2.9.27 MCP 协议核心(JSON-RPC 2.0 消息分发,纯函数可直测)
|
|
5
|
+
*
|
|
6
|
+
* scripts/mcp-server.mjs 是 stdio 壳(stdin/stdout 接线);本模块是无副作用的消息处理器:
|
|
7
|
+
* handle(msg, configLoader) → 响应对象 | null(通知不回包)。
|
|
8
|
+
* 三工具全只读:fde_list_tasks / fde_search_work / fde_agent_status——复用 lib 层纯函数,
|
|
9
|
+
* config 由 configLoader() 注入(测试注入合成配置,绝不触真实 ~/.dsh)。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const at = require('./agentTranscript');
|
|
13
|
+
const { workSearch } = require('./workSearch');
|
|
14
|
+
const { buildHeatmap } = require('./heatmap');
|
|
15
|
+
const store = require('./store');
|
|
16
|
+
|
|
17
|
+
const SERVER_INFO = { name: 'fde-console', version: require('../package.json').version };
|
|
18
|
+
|
|
19
|
+
const TOOLS = [
|
|
20
|
+
{
|
|
21
|
+
name: 'fde_list_tasks',
|
|
22
|
+
description: '列出 FDE 指挥台任务看板的任务(可按状态过滤:todo/doing/review/done)',
|
|
23
|
+
inputSchema: {
|
|
24
|
+
type: 'object',
|
|
25
|
+
properties: {
|
|
26
|
+
status: { type: 'string', description: '可选状态过滤', enum: ['todo', 'doing', 'review', 'done'] },
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'fde_search_work',
|
|
32
|
+
description: '跨任务标题/派工词/会话标题/提交说明/日报全文的统一搜索(多词 AND)',
|
|
33
|
+
inputSchema: {
|
|
34
|
+
type: 'object',
|
|
35
|
+
properties: { q: { type: 'string', description: '查询词,空格分隔多词' } },
|
|
36
|
+
required: ['q'],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'fde_agent_status',
|
|
41
|
+
description: '六源 agent 观测状态(健康 + 近 28 天会话数与活跃分钟)',
|
|
42
|
+
inputSchema: { type: 'object', properties: {} },
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
function dataPath(cfg, name) {
|
|
47
|
+
const path = require('node:path');
|
|
48
|
+
const root = require('node:path').resolve(__dirname, '..');
|
|
49
|
+
const dir = path.isAbsolute(cfg.dataDir) ? cfg.dataDir : path.join(root, cfg.dataDir);
|
|
50
|
+
return path.join(dir, name);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function toolListTasks(configLoader, args) {
|
|
54
|
+
const cfg = configLoader();
|
|
55
|
+
const data = store.loadTasks({ tasksPath: dataPath(cfg, 'tasks.json') });
|
|
56
|
+
const want = typeof args.status === 'string' ? args.status : null;
|
|
57
|
+
const tasks = (data.tasks || [])
|
|
58
|
+
.filter((t) => t && (!want || t.status === want))
|
|
59
|
+
.map((t) => ({ id: t.id, title: t.title, status: t.status, priority: t.priority, dueDate: t.dueDate, projectDir: t.projectDir || null }));
|
|
60
|
+
return { content: [{ type: 'text', text: JSON.stringify(tasks, null, 2) }] };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function toolSearchWork(configLoader, args) {
|
|
64
|
+
const r = workSearch(configLoader(), String(args.q || ''), {});
|
|
65
|
+
return { content: [{ type: 'text', text: JSON.stringify(r.groups, null, 2) }] };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function toolAgentStatus(configLoader) {
|
|
69
|
+
const cfg = configLoader();
|
|
70
|
+
const hm = buildHeatmap(cfg, { days: 28 });
|
|
71
|
+
const health = {};
|
|
72
|
+
for (const agent of at.SOURCE_IDS) {
|
|
73
|
+
try {
|
|
74
|
+
const page = at.listAgentSessions(cfg, { agent, limit: 1 });
|
|
75
|
+
const it = (page.items || [])[0];
|
|
76
|
+
health[agent] = { ok: true, lastActiveAt: it ? it.lastActiveAt : null };
|
|
77
|
+
} catch (e) {
|
|
78
|
+
health[agent] = { ok: false };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
content: [{
|
|
83
|
+
type: 'text',
|
|
84
|
+
text: JSON.stringify({ health, heatmap: { totalSessions: hm.totalSessions, totalMinutes: hm.totalMinutes, agents: hm.agents } }, null, 2),
|
|
85
|
+
}],
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const TOOL_HANDLERS = {
|
|
90
|
+
fde_list_tasks: toolListTasks,
|
|
91
|
+
fde_search_work: toolSearchWork,
|
|
92
|
+
fde_agent_status: toolAgentStatus,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* handle(msg, configLoader) → 响应对象 | null(通知不回包)
|
|
97
|
+
* @param {{jsonrpc?:string, id?:number|string, method:string, params?:object}} msg
|
|
98
|
+
* @param {() => object} configLoader
|
|
99
|
+
*/
|
|
100
|
+
function handle(msg, configLoader) {
|
|
101
|
+
const { id, method, params } = msg || {};
|
|
102
|
+
if (method === 'notifications/initialized' || method === 'notifications/cancelled') return null;
|
|
103
|
+
if (method === 'initialize') {
|
|
104
|
+
return {
|
|
105
|
+
jsonrpc: '2.0',
|
|
106
|
+
id,
|
|
107
|
+
result: {
|
|
108
|
+
protocolVersion: (params && params.protocolVersion) || '2024-11-05',
|
|
109
|
+
capabilities: { tools: {} },
|
|
110
|
+
serverInfo: SERVER_INFO,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
if (method === 'ping') return { jsonrpc: '2.0', id, result: {} };
|
|
115
|
+
if (method === 'tools/list') return { jsonrpc: '2.0', id, result: { tools: TOOLS } };
|
|
116
|
+
if (method === 'tools/call') {
|
|
117
|
+
const name = params && params.name;
|
|
118
|
+
const fn = TOOL_HANDLERS[name];
|
|
119
|
+
if (!fn) return { jsonrpc: '2.0', id, error: { code: -32602, message: `未知工具: ${name}` } };
|
|
120
|
+
try {
|
|
121
|
+
const result = fn(configLoader, (params && params.arguments) || {});
|
|
122
|
+
return { jsonrpc: '2.0', id, result };
|
|
123
|
+
} catch (e) {
|
|
124
|
+
return {
|
|
125
|
+
jsonrpc: '2.0',
|
|
126
|
+
id,
|
|
127
|
+
result: { content: [{ type: 'text', text: `工具执行失败: ${e.message}` }], isError: true },
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (id !== undefined && id !== null) return { jsonrpc: '2.0', id, error: { code: -32601, message: `未知方法: ${method}` } };
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
module.exports = { handle, TOOLS, SERVER_INFO };
|