fde-console 0.0.0-stage → 2.9.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +128 -2
  3. package/README.zh-CN.md +130 -0
  4. package/assets/icon.svg +9 -0
  5. package/cordis.patch.yml +7 -0
  6. package/lib/agentActivity.js +1180 -0
  7. package/lib/agentContext.js +146 -0
  8. package/lib/agentTranscript.js +1398 -0
  9. package/lib/analyze.js +625 -0
  10. package/lib/attribute.js +205 -0
  11. package/lib/backup.js +366 -0
  12. package/lib/desktopAgents.js +123 -0
  13. package/lib/diary.js +333 -0
  14. package/lib/dingtalk.js +412 -0
  15. package/lib/feishu.js +580 -0
  16. package/lib/giteaClient.js +810 -0
  17. package/lib/giteeClient.js +372 -0
  18. package/lib/githubClient.js +361 -0
  19. package/lib/heatmap.js +99 -0
  20. package/lib/imNotify.js +378 -0
  21. package/lib/inbox.js +438 -0
  22. package/lib/instanceLock.js +122 -0
  23. package/lib/jobs.js +56 -0
  24. package/lib/learn.js +1388 -0
  25. package/lib/learnImport.js +283 -0
  26. package/lib/learnSeeds.js +97 -0
  27. package/lib/learnSeedsAiEng.js +77 -0
  28. package/lib/mcpCore.js +135 -0
  29. package/lib/members.js +160 -0
  30. package/lib/migration.js +403 -0
  31. package/lib/overview.js +376 -0
  32. package/lib/postmortem.js +148 -0
  33. package/lib/radarIgnore.js +134 -0
  34. package/lib/redact.js +76 -0
  35. package/lib/router.js +246 -0
  36. package/lib/routes-gitea.js +262 -0
  37. package/lib/routes-setup.js +40 -0
  38. package/lib/scorecard.js +111 -0
  39. package/lib/sessionRef.js +227 -0
  40. package/lib/sessionSnapshot.js +67 -0
  41. package/lib/sessionSuggest.js +186 -0
  42. package/lib/settings.js +783 -0
  43. package/lib/setupCheck.js +330 -0
  44. package/lib/ssrfGuard.js +145 -0
  45. package/lib/store.js +564 -0
  46. package/lib/storeDb.js +418 -0
  47. package/lib/taskEvents.js +243 -0
  48. package/lib/webhookOut.js +125 -0
  49. package/lib/weekly.js +439 -0
  50. package/lib/workSearch.js +220 -0
  51. package/locale/en.json +6 -0
  52. package/locale/zh.json +6 -0
  53. package/package.json +46 -4
  54. package/plugin/adapter.js +157 -0
  55. package/plugin/client.js +282 -0
  56. package/plugin/index.mjs +116 -0
  57. package/plugin/static.js +99 -0
  58. package/scripts/backup-data.js +41 -0
  59. package/scripts/mcp-server.mjs +68 -0
  60. package/scripts/migrate-data.js +301 -0
  61. package/scripts/migrate-storage.js +47 -0
  62. package/scripts/seed-demo.js +200 -0
  63. package/scripts/write-agent-context.js +43 -0
  64. package/test/helpers/appAssembler.js +1078 -0
  65. package/web/client/fde-client.js +292 -0
  66. package/web/css/app.css +1510 -0
  67. package/web/index.html +69 -0
  68. package/web/js/api.js +72 -0
  69. package/web/js/app.js +313 -0
  70. package/web/js/icons.js +48 -0
  71. package/web/js/mock.js +1150 -0
  72. package/web/js/state.js +7 -0
  73. package/web/js/ui.js +276 -0
  74. package/web/js/views/activity.js +410 -0
  75. package/web/js/views/agents.js +892 -0
  76. package/web/js/views/board.js +1656 -0
  77. package/web/js/views/learn.js +530 -0
  78. package/web/js/views/members.js +344 -0
  79. package/web/js/views/onboarding.js +103 -0
  80. package/web/js/views/overview.js +508 -0
  81. package/web/js/views/radar.js +1359 -0
  82. package/web/js/views/search.js +149 -0
  83. package/web/js/views/settings.js +1351 -0
  84. package/web/js/views/topology.js +471 -0
  85. package/web/mock.json +2363 -0
@@ -0,0 +1,146 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * agentContext.js — v2.9.27 Agent 上下文注入(数字员工互知)
5
+ *
6
+ * 「让 ZCode 知道 Codex 昨晚在这个项目干了什么」:把近 N 天各 agent 会话聚合为一份
7
+ * .fde/daily.md 落在项目根,agent 会话启动自动读到(AGENTS.md/上下文发现机制)。
8
+ *
9
+ * 安全边界(红线级):
10
+ * - 只写 config.agentContext.dirs 白名单里显式列出的目录(绝不写会话数据里出现的任意路径);
11
+ * - 写文件固定名 .fde/daily.md,先 mkdir -p <dir>/.fde 再原子写(tmp+rename);
12
+ * - enabled !== true 时 buildAgentContext 仍可用(只读聚合),writeAgentContext 直接 no-op;
13
+ * - 内容全部来自六源标题(已在 listAgentSessions 内 redact),再过一道 redact。
14
+ */
15
+
16
+ const fs = require('node:fs');
17
+ const path = require('node:path');
18
+ const at = require('./agentTranscript');
19
+ const snapshot = require('./sessionSnapshot');
20
+ const redactMod = require('./redact');
21
+
22
+ const DAY_MS = 24 * 3600 * 1000;
23
+ const DEFAULT_DAYS = 1;
24
+ const MAX_DAYS = 7;
25
+ const FILE_NAME = '.fde/daily.md';
26
+ const PER_PROJECT_CAP = 40; // 每项目最多列 40 条会话(防长项目刷屏)
27
+
28
+ function redactText(t) {
29
+ try {
30
+ return redactMod.redact(t);
31
+ } catch (e) {
32
+ return String(t);
33
+ }
34
+ }
35
+
36
+ function normalizeKey(p) {
37
+ return String(p || '').trim().replace(/[\\/]+$/, '').toLowerCase().replace(/[\\/]+/g, '\\');
38
+ }
39
+
40
+ /**
41
+ * buildAgentContext(config, opts) → {projects:[{dir, days, agents:[{agent, label, sessions:[{title,at}]}], total}]}
42
+ * 数据面=listAgentSessions(每源 50 条帽),按 projectId 归一聚合、只保留 dirs 白名单内的项目。
43
+ * @param {{days?:number, now?:number, adapters?:object}} opts adapters=纯注入模式(同 heatmap 语义)
44
+ */
45
+ function buildAgentContext(config, opts) {
46
+ const o = opts || {};
47
+ const now = Number.isFinite(o.now) ? o.now : Date.now();
48
+ const days = Math.min(Math.max(Number(o.days) || DEFAULT_DAYS, 1), MAX_DAYS);
49
+ const sinceMs = now - days * DAY_MS;
50
+ const sec = (config && config.agentContext) || {};
51
+ const whitelist = (Array.isArray(sec.dirs) ? sec.dirs : []).map(normalizeKey).filter(Boolean);
52
+ // v2.9.29 D3:六源会话统一走 sessionSnapshot(adapters 纯注入语义不变)
53
+ const { byAgent: snapByAgent } = snapshot.getSnapshot(config, { now, adapters: o.adapters });
54
+
55
+ const byProject = new Map(); // normDir -> {dir, agents: Map(agent -> [{title,at}])}
56
+ for (const agent of at.SOURCE_IDS) {
57
+ for (const it of snapByAgent[agent] || []) {
58
+ const at2 = Date.parse(it.lastActiveAt);
59
+ if (!Number.isFinite(at2) || at2 < sinceMs) continue;
60
+ const norm = normalizeKey(it.projectId);
61
+ if (!norm || !whitelist.includes(norm)) continue; // 白名单外零写入依据
62
+ if (!byProject.has(norm)) byProject.set(norm, { dir: it.projectId, agents: new Map() });
63
+ const rec = byProject.get(norm);
64
+ if (!rec.agents.has(agent)) rec.agents.set(agent, []);
65
+ const list = rec.agents.get(agent);
66
+ if (list.length >= PER_PROJECT_CAP) continue;
67
+ list.push({ title: String(it.title || '(未命名会话)'), at: it.lastActiveAt });
68
+ }
69
+ }
70
+
71
+ const projects = [...byProject.values()].map((rec) => ({
72
+ dir: rec.dir,
73
+ agents: [...rec.agents].map(([agent, sessions]) => ({
74
+ agent,
75
+ sessions: sessions.sort((a, b) => String(b.at || '').localeCompare(String(a.at || ''))),
76
+ })),
77
+ total: [...rec.agents.values()].reduce((n, s) => n + s.length, 0),
78
+ })).sort((a, b) => b.total - a.total);
79
+
80
+ return { projects, days, generatedAt: new Date(now).toISOString() };
81
+ }
82
+
83
+ /** 聚合结果 → markdown 文本(agent 会话启动可读的战况简报;HTML 元字符转义——.md 虽由 LLM 消费仍纵深防御) */
84
+ function renderMarkdown(ctxResult) {
85
+ const esc = (s) => String(s || '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
86
+ const lines = [
87
+ '# Agent 战况简报(FDE 指挥台自动生成)',
88
+ '',
89
+ `> 生成于 ${ctxResult.generatedAt} · 覆盖最近 ${ctxResult.days} 天(每源计最近 50 条会话) · 数据只读本机六源会话,本文件供 agent 会话启动时了解其他 agent 近期工作。`,
90
+ '',
91
+ ];
92
+ if (!ctxResult.projects.length) {
93
+ lines.push('(白名单项目近 ' + ctxResult.days + ' 天无 agent 会话活动。)', '');
94
+ return lines.join('\n');
95
+ }
96
+ const LABEL = { zcode: 'ZCode', claude: 'Claude Code', dsh: 'DSH', workbuddy: 'WorkBuddy', codex: 'Codex', opencode: 'OpenCode' };
97
+ for (const p of ctxResult.projects) {
98
+ lines.push(`## ${p.dir}`, '');
99
+ for (const a of p.agents) {
100
+ lines.push(`### ${LABEL[a.agent] || a.agent}(${a.sessions.length} 条)`, '');
101
+ for (const s of a.sessions) {
102
+ const t = String(s.at || '').replace('T', ' ').slice(0, 16);
103
+ lines.push(`- ${t} ${esc(redactText(s.title).replace(/\s+/g, ' ').slice(0, 100))}`);
104
+ }
105
+ lines.push('');
106
+ }
107
+ }
108
+ return lines.join('\n');
109
+ }
110
+
111
+ /**
112
+ * writeAgentContext(config, opts) → {written:[{dir,file}], skipped:[{dir,reason}]}
113
+ * 只写 enabled===true 且 dirs 白名单内的目录;单目录失败跳过不拖垮(EPERM 容忍)。
114
+ */
115
+ function writeAgentContext(config, opts) {
116
+ const o = opts || {};
117
+ const sec = (config && config.agentContext) || {};
118
+ if (sec.enabled !== true) return { written: [], skipped: [{ dir: '(all)', reason: 'agentContext.enabled !== true' }] };
119
+ const result = buildAgentContext(config, o);
120
+ const md = renderMarkdown(result);
121
+ const written = [];
122
+ const skipped = [];
123
+ for (const dirRaw of Array.isArray(sec.dirs) ? sec.dirs : []) {
124
+ const dir = String(dirRaw || '').trim();
125
+ if (!dir) continue;
126
+ const hasActivity = result.projects.some((p) => normalizeKey(p.dir) === normalizeKey(dir));
127
+ if (!hasActivity) {
128
+ skipped.push({ dir, reason: '近窗无会话活动(不写空文件)' });
129
+ continue;
130
+ }
131
+ try {
132
+ const target = path.join(dir, '.fde');
133
+ fs.mkdirSync(target, { recursive: true });
134
+ const file = path.join(target, 'daily.md');
135
+ const tmp = file + '.tmp';
136
+ fs.writeFileSync(tmp, md, 'utf8');
137
+ fs.renameSync(tmp, file);
138
+ written.push({ dir, file });
139
+ } catch (e) {
140
+ skipped.push({ dir, reason: String((e && e.message) || e) });
141
+ }
142
+ }
143
+ return { written, skipped };
144
+ }
145
+
146
+ module.exports = { buildAgentContext, renderMarkdown, writeAgentContext, normalizeKey, FILE_NAME, DEFAULT_DAYS, MAX_DAYS };