@ssamurias/dsh-fish 1.1.0 → 1.1.2
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/AGENTS.md +377 -367
- package/CHANGELOG.md +234 -0
- package/README.md +417 -377
- package/RELEASE-NOTES-1.1.1.md +61 -0
- package/RELEASE-NOTES-1.1.2.md +103 -0
- package/docs/troubleshooting.md +24 -4
- package/docs//350/256/244/344/272/272/345/210/244/346/215/256.md +33 -5
- package/lib/bridgeclaim.js +158 -0
- package/lib/claim.js +183 -13
- package/lib/client/01-state-load.js +30 -3
- package/lib/client/06-tab-status-grow.js +12 -1
- package/lib/client/08-tab-memory-plugins.js +675 -755
- package/lib/client/11-tab-data-frame.js +3 -1
- package/lib/client.js +58 -98
- package/lib/compact.js +28 -7
- package/lib/derive.js +6 -1
- package/lib/drive.js +7 -4
- package/lib/identity.js +53 -27
- package/lib/index.js +9 -4
- package/lib/log.js +1 -1
- package/lib/mapserve.js +132 -0
- package/lib/markup.js +32 -13
- package/lib/memorymap-html.js +2 -0
- package/lib/memorymap.js +456 -0
- package/lib/meta.js +2 -1
- package/lib/observe-home.js +58 -3
- package/lib/observe-state.js +19 -1
- package/lib/observe.js +31 -2
- package/lib/persona.js +32 -7
- package/lib/proactive.js +57 -1
- package/lib/restrict.js +58 -18
- package/lib/say.js +76 -28
- package/lib/scheduler.js +17 -5
- package/lib/scrub.js +10 -5
- package/lib/settings.js +20 -0
- package/lib/tenant.js +21 -4
- package/lib/transcript.js +12 -2
- package/lib/turns.js +50 -4
- package/lib/types.d.ts +9 -0
- package/lib/use.js +3 -3
- package/lib/wiki.js +14 -2
- package/package.json +1 -1
- package/scripts/build-client.mjs +15 -1
- package/tools/check-install.mjs +64 -23
package/lib/memorymap.js
ADDED
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 记忆图(2026-11-26 用户 m03077):把事件流和派生结果排成一张可交互的图。
|
|
3
|
+
*
|
|
4
|
+
* 这里是从 02-我的项目/大肥鱼/记忆可视化/build.mjs 搬进来的,只做了三件事:
|
|
5
|
+
* · 不再自己读盘——事件、model、stances 都由调用方传进来;
|
|
6
|
+
* · 不再写文件——返回 view 对象,由 renderMemoryMapHtml 内联进页面;
|
|
7
|
+
* · 变成纯函数,方便测试和复算。
|
|
8
|
+
*
|
|
9
|
+
* 排版规则一句话:半径=时间(sqrt 摊开),角度=扇区里第几个(螺旋),
|
|
10
|
+
* 叶子从中轴斜岔出去,四种扇区固定在四个 90° 象限里。
|
|
11
|
+
* 位置是稳定的——同样的数据画两次长得一样,第二次打开还认得哪块是哪块。
|
|
12
|
+
*/
|
|
13
|
+
import { deriveSelf } from './derive.js'
|
|
14
|
+
import { buildStances } from './stance.js'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 她自己的名字——从事件流里取,不写死。
|
|
18
|
+
*
|
|
19
|
+
* 用户 2026-11-27 的原话:要「用户实际和大肥鱼共同决定的名字」,也就是她自己说
|
|
20
|
+
* 我想叫做「XXX」、或者他给她起的那个名字;没有就留空,标题只写「记忆星图」。
|
|
21
|
+
* 真机上那句话是「他给我起了名字:大肥鱼。」(2026-10-25 那条 utterance),
|
|
22
|
+
* 后面她改口「不是为我造的,是从外面挑的」时名字没变,所以这里取**最后一次**命中。
|
|
23
|
+
*
|
|
24
|
+
* 三种说法:① 起了名字:X ② 以后叫我 X ③ 我想叫做「X」。
|
|
25
|
+
* 都限死在一行内容里、名字不超过 16 字,取不到就返回空串——宁可不写,也不写半句。
|
|
26
|
+
*/
|
|
27
|
+
const HER_NAME_PATTERNS = [
|
|
28
|
+
/(?:给|替)(?:我|她)?(?:起|取)(?:了|个)?(?:个)?名字\s*[::]\s*([^\s,。;、!?::「」『』"'()()]{1,16})/,
|
|
29
|
+
/以后(?:就)?叫我\s*[「『"']?([^\s,。;、!?「」『』"'()()]{1,12})/,
|
|
30
|
+
/我想叫[做]?\s*[「『"']([^」』"']{1,12})[」』"']/,
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
export function herNameOf(events) {
|
|
34
|
+
let out = ''
|
|
35
|
+
for (const e of events || []) {
|
|
36
|
+
const text = String(e && e.text ? e.text : '')
|
|
37
|
+
if (!text || text.length > 400) continue
|
|
38
|
+
for (const re of HER_NAME_PATTERNS) {
|
|
39
|
+
const m = text.match(re)
|
|
40
|
+
if (m && m[1]) {
|
|
41
|
+
out = m[1]
|
|
42
|
+
.trim()
|
|
43
|
+
.replace(/[,。;、!?::]+$/, '')
|
|
44
|
+
.replace(/[吧呀啊哦嘛啦呢]+$/, '')
|
|
45
|
+
break
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return out
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** 图例里四个扇区的名字(2026-11-27 用户要求:「人」→「对人的了解」、「听说的」→「听说的事」)。 */
|
|
53
|
+
import { MEMORY_MAP_HTML_B64 } from './memorymap-html.js'
|
|
54
|
+
import { readEvents } from './store.js'
|
|
55
|
+
import { examine } from './health.js'
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {any[]} events
|
|
59
|
+
* @param {any} model deriveSelf 的返回值
|
|
60
|
+
* @param {any[]} stances buildStances 的返回值
|
|
61
|
+
* @param {number} [now]
|
|
62
|
+
*/
|
|
63
|
+
export function buildViewData(events, model, stances, now = Date.now()) {
|
|
64
|
+
// who 在 S1 之后可能是 {id, name}:渲染层只会印字符串,这里统一折成名字
|
|
65
|
+
const whoName = (w) => (w && typeof w === 'object' ? (w.name || w.id || '') : (w || ''))
|
|
66
|
+
const at = (ev) => Date.parse(ev.ts || ev.at || 0) || 0
|
|
67
|
+
const t0 = Math.min(...events.map(at).filter(Boolean))
|
|
68
|
+
if (!Number.isFinite(t0)) return { meta: { t0: now, t1: now, counts: {} }, sectors: [], spines: {}, tracks: [], nodes: [], edges: [] }
|
|
69
|
+
|
|
70
|
+
// ── 扇区定义:角度从 -90°(正上)开始顺时针
|
|
71
|
+
const SECTORS = [
|
|
72
|
+
{ key: 'belief', label: '判断', color: '#6fc8ff', from: -90, to: 0 },
|
|
73
|
+
{ key: 'heard', label: '听说的事', color: '#7ff0b6', from: 0, to: 90 },
|
|
74
|
+
{ key: 'person', label: '对人的了解', color: '#ffd479', from: 90, to: 180 },
|
|
75
|
+
{ key: 'stance', label: '立场', color: '#ff9ad5', from: 180, to: 270 },
|
|
76
|
+
]
|
|
77
|
+
const sectorOf = (k) => SECTORS.find((s) => s.key === k) || SECTORS[0]
|
|
78
|
+
|
|
79
|
+
// ── 收集节点
|
|
80
|
+
const nodes = []
|
|
81
|
+
const edgeMap = new Map()
|
|
82
|
+
const addEdge = (a, b, kind) => {
|
|
83
|
+
if (!a || !b || a === b) return
|
|
84
|
+
const k = a < b ? a + '|' + b + '|' + kind : b + '|' + a + '|' + kind
|
|
85
|
+
if (!edgeMap.has(k)) edgeMap.set(k, { a: a < b ? a : b, b: a < b ? b : a, kind })
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const beliefIds = new Set((model.beliefs || []).map((b) => b.id))
|
|
89
|
+
const historyIds = new Set((model.beliefsHistory || []).map((b) => b.id))
|
|
90
|
+
const solidIds = new Set((model.solid || []).map((b) => b.id))
|
|
91
|
+
|
|
92
|
+
// 1. 判断(含被推翻的旧句)
|
|
93
|
+
for (const b of model.beliefsHistory || []) {
|
|
94
|
+
const t = Date.parse(b.since) || 0
|
|
95
|
+
const ref = (model.ranked || []).find((r) => r.id === b.id) || b
|
|
96
|
+
nodes.push({
|
|
97
|
+
id: b.id, kind: 'belief',
|
|
98
|
+
text: b.text, at: t,
|
|
99
|
+
verdict: b.verdict || null,
|
|
100
|
+
status: b.status || 'active',
|
|
101
|
+
confidence: Number(b.confidence ?? 0.5),
|
|
102
|
+
topic: b.topic || '',
|
|
103
|
+
// who 现在可能是 {id,name} 这样的对象(S1「谁说的」之后):面板直接印会出一个
|
|
104
|
+
// [object Object]。这里就折成名字,别把这个坑留给渲染层。
|
|
105
|
+
who: whoName(b.who),
|
|
106
|
+
mentions: Number(ref.mentions || 0),
|
|
107
|
+
verified: Number(ref.verified || 0),
|
|
108
|
+
solid: solidIds.has(b.id),
|
|
109
|
+
stale: Boolean(ref.stale),
|
|
110
|
+
// 最后一次被想起的时间——「快忘了」要按观察时刻现算,不能读死的 stale 布尔
|
|
111
|
+
lastTouch: Number(ref.lastTouchedAt || 0),
|
|
112
|
+
active: beliefIds.has(b.id),
|
|
113
|
+
})
|
|
114
|
+
// 两条判断互相矛盾(derive 的 clash:同一周内、方向相反)——这是唯一一种
|
|
115
|
+
// 「她自己跟自己过不去」的边,画面上要能一眼看见。
|
|
116
|
+
if (ref.conflictWith) addEdge(b.id, String(ref.conflictWith), 'conflict')
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// 2. 她听来的话(从评论区)+ 事件里的 heard
|
|
120
|
+
for (const v of model.voices || []) {
|
|
121
|
+
nodes.push({
|
|
122
|
+
id: v.id, kind: 'heard', text: v.text, at: Date.parse(v.at) || 0,
|
|
123
|
+
from: v.bvid ? `BV ${v.bvid}` : '', echoed: Boolean(v.echoed),
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
for (const e of events.filter((x) => x.type === 'heard')) {
|
|
127
|
+
if (nodes.some((n) => n.id === e.id)) continue
|
|
128
|
+
nodes.push({ id: e.id, kind: 'heard', text: e.text, at: at(e), from: whoName(e.who) })
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 3. 人物(界面上不写主人的真名——公开版不该把用户的名字烙进图里)
|
|
132
|
+
for (const p of model.people || []) {
|
|
133
|
+
const pid = 'person:' + (p.id || p.name)
|
|
134
|
+
nodes.push({
|
|
135
|
+
id: pid, kind: 'person',
|
|
136
|
+
text: p.id === 'owner' ? '主人' : (p.name || '一个人'),
|
|
137
|
+
at: p.firstAt || t0,
|
|
138
|
+
judged: Number(p.judged || 0),
|
|
139
|
+
judgmentIds: p.judgmentIds || [],
|
|
140
|
+
})
|
|
141
|
+
for (const jid of p.judgmentIds || []) addEdge(pid, jid, 'about')
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// 4. 立场
|
|
145
|
+
for (const s of stances) {
|
|
146
|
+
const id = 'stance:' + (s.key || s.id || Math.random().toString(36).slice(2))
|
|
147
|
+
// since 可能是 ISO 字符串(buildStances 直接给的):不转成毫秒的话,
|
|
148
|
+
// 后面按时间算半径会得到 NaN,节点就静默消失了——HUD 上数得到、图上没有。
|
|
149
|
+
const since = typeof s.since === 'number' ? s.since : (Date.parse(s.since) || now)
|
|
150
|
+
nodes.push({
|
|
151
|
+
id, kind: 'stance', text: s.text || s.title || '', at: since,
|
|
152
|
+
kindOf: s.kind || '', group: s.group || [],
|
|
153
|
+
})
|
|
154
|
+
for (const m of s.group || []) {
|
|
155
|
+
const mid = typeof m === 'string' ? m : m && m.id
|
|
156
|
+
if (mid) addEdge(id, mid, 'stance')
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// 5. 原话:所有 utterance(其中已是判断的复用,其余标记为未认领)
|
|
161
|
+
const beliefNodeIds = new Set(nodes.filter((n) => n.kind === 'belief').map((n) => n.id))
|
|
162
|
+
for (const e of events.filter((x) => x.type === 'utterance')) {
|
|
163
|
+
if (beliefNodeIds.has(e.id)) continue
|
|
164
|
+
nodes.push({
|
|
165
|
+
id: e.id, kind: 'said', text: e.text, at: at(e),
|
|
166
|
+
confidence: Number(e.confidence ?? 0.5),
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// 6. 她看过的东西
|
|
171
|
+
const matByBvid = new Map()
|
|
172
|
+
for (const mt of model.materials || []) {
|
|
173
|
+
const id = 'material:' + mt.key
|
|
174
|
+
matByBvid.set(mt.key, id)
|
|
175
|
+
nodes.push({ id, kind: 'material', text: mt.title || mt.key, at: mt.at || 0, key: mt.key })
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ── 边
|
|
179
|
+
// 改口链:revise 的 refs 指向旧判断
|
|
180
|
+
for (const e of events.filter((x) => x.type === 'revise' && Array.isArray(x.refs))) {
|
|
181
|
+
for (const r of e.refs) addEdge(e.id, r, 'revise')
|
|
182
|
+
}
|
|
183
|
+
// 同一支 B 站的听闻 → 看过的那条视频
|
|
184
|
+
for (const v of model.voices || []) {
|
|
185
|
+
if (!v.bvid) continue
|
|
186
|
+
const bid = matByBvid.get(v.bvid)
|
|
187
|
+
if (bid) addEdge(v.id, bid, 'about')
|
|
188
|
+
}
|
|
189
|
+
// 同 topic / 同 who
|
|
190
|
+
const byTopic = new Map(), byWho = new Map()
|
|
191
|
+
for (const n of nodes.filter((x) => x.kind === 'belief')) {
|
|
192
|
+
if (n.topic) { (byTopic.get(n.topic) || byTopic.set(n.topic, []).get(n.topic)).push(n.id) }
|
|
193
|
+
if (n.who) { (byWho.get(n.who) || byWho.set(n.who, []).get(n.who)).push(n.id) }
|
|
194
|
+
}
|
|
195
|
+
for (const ids of byTopic.values()) for (let i = 1; i < ids.length; i++) addEdge(ids[0], ids[i], 'topic')
|
|
196
|
+
for (const ids of byWho.values()) for (let i = 1; i < ids.length; i++) addEdge(ids[0], ids[i], 'who')
|
|
197
|
+
|
|
198
|
+
// 关系边:文本相似度在这份数据上连不出东西——35 条判断两两最高只有 0.27,
|
|
199
|
+
// 因为每一句都在说不同的事,措辞也不重复。真正能把两句连起来的是它们
|
|
200
|
+
// **引用了同一个东西**:同一句被引号括起来的话、同一个名字。这一层不看修辞,看指称。
|
|
201
|
+
const QUOTE_STOP = new Set(['我也在', '因为什么', '太绕了', '一个字', '一句话'])
|
|
202
|
+
const quotesOf = (t) => [...String(t).matchAll(/[「『"“]([^」』"”]{2,24})[」』"”]/g)]
|
|
203
|
+
.map((m) => m[1].trim())
|
|
204
|
+
.filter((q) => q.length >= 3 && !QUOTE_STOP.has(q))
|
|
205
|
+
{
|
|
206
|
+
const bs = nodes.filter((n) => n.kind === 'belief')
|
|
207
|
+
const qmap = new Map()
|
|
208
|
+
for (const n of bs) {
|
|
209
|
+
for (const q of new Set(quotesOf(n.text))) {
|
|
210
|
+
const arr = qmap.get(q) || qmap.set(q, []).get(q)
|
|
211
|
+
arr.push(n.id)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
for (const [q, ids] of qmap) {
|
|
215
|
+
// 只有两句到四句共享才算关系;五句以上同一个词,那多半是"大肥鱼"这种
|
|
216
|
+
// 到处都在说的名字,全连起来就成了一根柱子,反而看不出什么。
|
|
217
|
+
if (ids.length < 2 || ids.length > 4) continue
|
|
218
|
+
for (let i = 1; i < ids.length; i++) addEdge(ids[0], ids[i], 'quote')
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// 同一天长出来的判断:不是语义关系,是「那几天在想的事」。
|
|
223
|
+
// 单独一种边、单独一种画法(虚线),别和改口链混在一起看。
|
|
224
|
+
{
|
|
225
|
+
const byDay = new Map()
|
|
226
|
+
for (const n of nodes.filter((x) => x.kind === 'belief')) {
|
|
227
|
+
const d = Math.floor((n.at - t0) / 86400000)
|
|
228
|
+
const arr = byDay.get(d) || byDay.set(d, []).get(d)
|
|
229
|
+
arr.push(n)
|
|
230
|
+
}
|
|
231
|
+
for (const arr of byDay.values()) {
|
|
232
|
+
if (arr.length < 2) continue
|
|
233
|
+
arr.sort((a, b) => a.at - b.at)
|
|
234
|
+
for (let i = 1; i < arr.length; i++) addEdge(arr[i - 1].id, arr[i].id, 'day')
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// ── 布局:极坐标(角度=扇区,半径=时间与序位混合),再轻轻推开重叠
|
|
239
|
+
// 半径按「成长期」而不是「已经过了几天」摊开:装完第一天打开时,整只盘
|
|
240
|
+
// 不该只有中间两圈是亮的——外面那一圈圈是「还没走到」,不是画错了。
|
|
241
|
+
const growMs = Math.max(1, Number(model.growthDays) || 30) * 86400000
|
|
242
|
+
const span = Math.max(now - t0, growMs, 1)
|
|
243
|
+
const hash = (s) => { let h = 2166136261; for (let i = 0; i < s.length; i++) { h ^= s.charCodeAt(i); h = Math.imul(h, 16777619) } return ((h >>> 0) % 10000) / 10000 }
|
|
244
|
+
|
|
245
|
+
// 扇区是固定的 90°:位置稳定,看图的人第二次打开还认得哪块是哪块。
|
|
246
|
+
// 空的立场扇区就让它空着——「这里还没长出东西」本身就是信息。
|
|
247
|
+
const SECTOR_DEG = 90
|
|
248
|
+
|
|
249
|
+
// 布局 = 螺旋。半径严格按时间走(时间是硬的,不能为好看挪动),
|
|
250
|
+
// 角度按扇区内的时间位次从 from 扫到 to——于是每一类记忆都是一条从中心盘出来的螺线,
|
|
251
|
+
// 时间密的那几天自然挤成同一圈上的一段弧,稀疏的那几段就一格一格往外跳。
|
|
252
|
+
for (const s of SECTORS) {
|
|
253
|
+
const list = nodes.filter((n) => n.kind === s.key).sort((a, b) => a.at - b.at)
|
|
254
|
+
const m = list.length
|
|
255
|
+
for (let i = 0; i < m; i++) {
|
|
256
|
+
const n = list[i]
|
|
257
|
+
// at 万一不是毫秒数(字符串 / undefined),这里兜一下:宁可位置贴到起点,
|
|
258
|
+
// 也别让这颗点算出 NaN 然后被画布静默跳过——「计数里有、图上没有」就是这么来的。
|
|
259
|
+
const rawAt = Number(n.at)
|
|
260
|
+
const t = Math.min(Math.max(Number.isFinite(rawAt) ? rawAt : t0, t0), now)
|
|
261
|
+
const timeRatio = span > 0 ? (t - t0) / span : 0
|
|
262
|
+
const rankRatio = m > 1 ? i / (m - 1) : 0.5
|
|
263
|
+
// 半径用 sqrt:真实时间里 90% 的记忆挤在前 1/3,线性半径会把整张图压成一个点。
|
|
264
|
+
// sqrt 只是把同一段路程摊开,不改变谁先谁后。
|
|
265
|
+
const rBase = 0.07 + 0.89 * Math.sqrt(timeRatio)
|
|
266
|
+
const aBase = s.from + (s.to - s.from) * (0.06 + 0.88 * rankRatio)
|
|
267
|
+
// 枝条:同一话题的判断走同一条岔枝(角度偏移一样),不同话题分开。
|
|
268
|
+
// 全压在一个角度上时,几百条判断就是一条粗线——图上看不出这里有三十件事。
|
|
269
|
+
// 半径只做毫米级的抖,时间还是硬的:谁先谁后不会因为好看被挪。
|
|
270
|
+
const brancher = n.topic ? hash('t:' + n.topic) : hash('id:' + n.id)
|
|
271
|
+
const branchDeg = (brancher - 0.5) * 15
|
|
272
|
+
const jitterR = 0.014 * (hash(n.id + '|r') * 2 - 1)
|
|
273
|
+
n.sr = rBase
|
|
274
|
+
n.sa = aBase
|
|
275
|
+
n.r = Math.max(0.05, Math.min(0.97, rBase + jitterR))
|
|
276
|
+
n.a = aBase + branchDeg
|
|
277
|
+
const rad = (n.a * Math.PI) / 180
|
|
278
|
+
n.x = Math.cos(rad) * n.r
|
|
279
|
+
n.y = Math.sin(rad) * n.r
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// 「看过的东西」不进那四条螺线:它们是她在边上碰到的东西,不是长出来的判断。
|
|
284
|
+
// 它们也不该按时间摆——看到一样东西,不代表那是「很久以前看的」。
|
|
285
|
+
// 所以放在**最外圈、时间刻度带之外**(r > 1):读法是「她身边的东西」,
|
|
286
|
+
// 不是「某一天的事」。角度按 id 散开、位置稳定——第二次打开还在原处。
|
|
287
|
+
// (以前这一层没给坐标,画的时候算出 NaN 被静默跳过:计数里有、图上没有。)
|
|
288
|
+
for (const n of nodes) {
|
|
289
|
+
if (n.kind !== 'material') continue
|
|
290
|
+
n.offTime = true
|
|
291
|
+
n.r = 1.09 + 0.035 * hash(n.id)
|
|
292
|
+
n.a = -90 + 360 * hash(n.id + '|a')
|
|
293
|
+
const rad = (n.a * Math.PI) / 180
|
|
294
|
+
n.x = Math.cos(rad) * n.r
|
|
295
|
+
n.y = Math.sin(rad) * n.r
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// 她对自己的说法(narration):不是判断,是「她怎么讲自己」。
|
|
299
|
+
// 放在中心那只鲸鱼身上——那是她的位置,不是某一类记忆的扇区。
|
|
300
|
+
if (model.narrative && model.narrative.text) {
|
|
301
|
+
const at = Date.parse(model.narrative.at) || now
|
|
302
|
+
nodes.push({
|
|
303
|
+
id: 'self:0', kind: 'self', text: model.narrative.text, at,
|
|
304
|
+
r: 0.165, a: -62, x: 0, y: 0,
|
|
305
|
+
})
|
|
306
|
+
}
|
|
307
|
+
// 一直没定的事(unsettled):clash 里搁了 14 天还没定下来的那一对。
|
|
308
|
+
// 它和「打架」不一样——打架是硬的,悬着是软的,所以画成一条淡的紫虚线。
|
|
309
|
+
for (const t of model.unsettled || []) {
|
|
310
|
+
const a = String((t.a && t.a.id) || '')
|
|
311
|
+
const b = String((t.b && t.b.id) || '')
|
|
312
|
+
if (a && b) {
|
|
313
|
+
addEdge(a, b, 'unsettled')
|
|
314
|
+
// 两端都记一笔,点开卡片时能说「这条和另一条还悬着」
|
|
315
|
+
for (const id of [a, b]) {
|
|
316
|
+
const n = nodes.find((x) => x.id === id)
|
|
317
|
+
if (n) n.unsettled = true
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// 生长脊:每个扇区把节点按时序连成一条折线——这是"枝",也是她这一类记忆长出来的轨迹。
|
|
323
|
+
const spines = {}
|
|
324
|
+
for (const s of SECTORS) {
|
|
325
|
+
const list = nodes.filter((n) => n.kind === s.key).sort((a, b) => a.at - b.at)
|
|
326
|
+
if (list.length < 2) { spines[s.key] = []; continue }
|
|
327
|
+
// 脊只走中轴:不跟着叶子偏,否则主干会被叶子拽成一条麻花
|
|
328
|
+
// 脊走「主干」角度:叶子(岔枝)偏出去,主干仍在原处,才看得出哪根枝分了几岔。
|
|
329
|
+
spines[s.key] = list.map((n) => {
|
|
330
|
+
const rad = ((n.sa != null ? n.sa : n.a) * Math.PI) / 180
|
|
331
|
+
const rr = n.sr != null ? n.sr : n.r
|
|
332
|
+
// 第三个值是时间:画的时候按 cursor 截断,脊才是一路长出来的
|
|
333
|
+
return [Math.cos(rad) * rr, Math.sin(rad) * rr, n.at]
|
|
334
|
+
})
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// ── 统计
|
|
338
|
+
const counts = {}
|
|
339
|
+
for (const n of nodes) counts[n.kind] = (counts[n.kind] || 0) + 1
|
|
340
|
+
|
|
341
|
+
// ── 横轴曲线:一条线 = 一条判断的命
|
|
342
|
+
// 出生(第一次说出口)→ 被想起时的起伏 → 被改写/被推翻时的转折。
|
|
343
|
+
// 起伏的次数和转折的时间都来自真事件,不补假点。
|
|
344
|
+
const reviseAt = new Map()
|
|
345
|
+
for (const r of events.filter((e) => e.type === 'revise')) {
|
|
346
|
+
for (const ref of (r.refs || [])) {
|
|
347
|
+
if (!reviseAt.has(ref)) reviseAt.set(ref, [])
|
|
348
|
+
reviseAt.get(ref).push(Date.parse(r.ts))
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const tracks = []
|
|
353
|
+
for (const b of model.beliefsHistory || []) {
|
|
354
|
+
const born = Date.parse(b.since)
|
|
355
|
+
if (!Number.isFinite(born)) continue
|
|
356
|
+
const pivots = (reviseAt.get(b.id) || []).filter(Number.isFinite).sort((a, c) => a - c)
|
|
357
|
+
const base = typeof b.confidence === 'number' ? b.confidence : 0.6
|
|
358
|
+
const pts = [[born, Math.max(0.06, base * 0.5)]]
|
|
359
|
+
const recalls = Math.min(6, b.mentions || 0)
|
|
360
|
+
for (let i = 1; i <= recalls; i++) {
|
|
361
|
+
pts.push([born + (now - born) * (i / (recalls + 1)), Math.min(0.92, base * 0.5 + 0.08 * i)])
|
|
362
|
+
}
|
|
363
|
+
for (const p of pivots) pts.push([p, Math.min(0.95, base + 0.15)])
|
|
364
|
+
const tail = b.verdict === 'refuted' ? 0.04 : b.verdict === 'refined' ? base * 0.75 : Math.min(0.98, base + 0.2)
|
|
365
|
+
pts.push([pivots.length ? Math.max(pivots[pivots.length - 1], now - 86400000) : now, tail])
|
|
366
|
+
tracks.push({ id: b.id, text: String(b.text || ''), solid: solidIds.has(b.id), verdict: b.verdict || null, pts })
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const view = {
|
|
370
|
+
meta: {
|
|
371
|
+
// 这张图上写谁的名字:写她自己认下的那个(从事件流里取),不写他的;
|
|
372
|
+
// 她还没有名字时留空,页面只写「记忆星图」。
|
|
373
|
+
// 曾经错取过 model.name——那是「她怎么称呼他」,用户 2026-11-27 指出:时梦尘是他,不是她。
|
|
374
|
+
name: herNameOf(events),
|
|
375
|
+
day: model.day,
|
|
376
|
+
stage: model.stageName,
|
|
377
|
+
generatedAt: now,
|
|
378
|
+
t0, t1: now,
|
|
379
|
+
counts,
|
|
380
|
+
facts: model.facts,
|
|
381
|
+
solid: (model.solid || []).length,
|
|
382
|
+
faded: (model.faded || []).length,
|
|
383
|
+
stances: stances.length,
|
|
384
|
+
people: (model.people || []).length,
|
|
385
|
+
days: Math.max(1, Math.round((now - t0) / 86400000)),
|
|
386
|
+
growth: Math.max(1, Number(model.growthDays) || 30),
|
|
387
|
+
// 她经历过的每一个事件(含系统记账)的时间戳。用来在外圈刻刻度——
|
|
388
|
+
// 密的那几天就是她活得最凶的那几天,这是真数据,不是装饰。
|
|
389
|
+
ticks: events.map(at).filter(Boolean),
|
|
390
|
+
// 他不在的那几段。absence.ts 是「发现他不在」的那一刻,days 是空了几天,
|
|
391
|
+
// 所以区间是 [ts - days*DAY, ts]——那几天她一个人待着。
|
|
392
|
+
absences: events
|
|
393
|
+
.filter((e) => e.type === 'absence' && Number.isFinite(Date.parse(e.ts)))
|
|
394
|
+
.map((e) => {
|
|
395
|
+
const to = Date.parse(e.ts)
|
|
396
|
+
const d = Math.max(1, Number(e.days) || 1)
|
|
397
|
+
return { from: to - d * 86400000, to, days: d }
|
|
398
|
+
})
|
|
399
|
+
.sort((a, b) => a.from - b.from),
|
|
400
|
+
// 传记的刻度:不是「数据里有什么」,是「她第一次做了什么」。
|
|
401
|
+
// 只取第一次——第二次就不叫第一次了,图上放五条正好。
|
|
402
|
+
moments: (() => {
|
|
403
|
+
const sorted = [...events].sort((a, b) => (a.ts < b.ts ? -1 : 1));
|
|
404
|
+
const list = [];
|
|
405
|
+
const take = (pred, label, sub) => {
|
|
406
|
+
const e = sorted.find(pred);
|
|
407
|
+
if (e) list.push({ at: Date.parse(e.ts), label, sub: sub || '', text: String(e.text || '').slice(0, 160) });
|
|
408
|
+
};
|
|
409
|
+
take((e) => e.type === 'utterance', '她第一次开口', '在这个屋子里说的第一句话');
|
|
410
|
+
take((e) => e.type === 'revise', '她第一次改口', '也是第一次认错——同一件事');
|
|
411
|
+
// 不写死「大肥鱼」——别人家的鱼不叫这个名字
|
|
412
|
+
take((e) => /起了(个)?名字|给我起名|管我叫|以后叫我/.test(String(e.text || '')), '她第一次被叫名字', '名字是那天给的');
|
|
413
|
+
take((e) => e.type === 'absentee' || e.type === 'absence', '她第一次被冷落', '两天没人应声');
|
|
414
|
+
take((e) => e.type === 'narration', '她第一次描述自己', '从「看」转到「问来源」');
|
|
415
|
+
// 这两条本机都还是 0 条;机制先留着,真有那一天自动长出来
|
|
416
|
+
take((e) => e.type === 'refusal', '她第一次说不', '第一次明确拒掉一件事');
|
|
417
|
+
if (stances.length) {
|
|
418
|
+
// since 可能是 ISO 字符串:不换算成毫秒,比较是 NaN、排序是乱序,
|
|
419
|
+
// 这条刻度还会被前端的「at <= cursor」判掉——于是它算出来了却不显示。
|
|
420
|
+
const ms = (v) => (typeof v === 'number' ? v : (Date.parse(v) || 0));
|
|
421
|
+
const s0 = [...stances].sort((x, y) => ms(x.since) - ms(y.since))[0];
|
|
422
|
+
const at0 = s0 ? ms(s0.since) : 0;
|
|
423
|
+
if (s0 && at0) {
|
|
424
|
+
list.push({ at: at0, label: '她第一次形成立场', sub: '同一条判断被反复想起、又被应验', text: String(s0.text || s0.claim || '').slice(0, 160) });
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return list.sort((a, b) => a.at - b.at);
|
|
428
|
+
})(),
|
|
429
|
+
},
|
|
430
|
+
sectors: SECTORS,
|
|
431
|
+
spines,
|
|
432
|
+
tracks,
|
|
433
|
+
nodes,
|
|
434
|
+
edges: [...edgeMap.values()],
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return view
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* 拼出完整页面:模板(base64 内嵌)+ 实时数据(替换掉模板里那行 view.js 引用)。
|
|
442
|
+
* @param {string} root 插件数据家(~/.dsh-fish)
|
|
443
|
+
*/
|
|
444
|
+
export async function renderMemoryMapHtml(root) {
|
|
445
|
+
const { events } = await readEvents(root)
|
|
446
|
+
const model = deriveSelf(events, { growthDays: 30 })
|
|
447
|
+
const stances = buildStances(model)
|
|
448
|
+
const view = buildViewData(events, model, stances)
|
|
449
|
+
// 体检页要和图上用同一份 events,否则页面里的数字和图上的点对不上
|
|
450
|
+
const health = examine(events, { growthDays: 30 })
|
|
451
|
+
const html = Buffer.from(MEMORY_MAP_HTML_B64, 'base64').toString('utf8')
|
|
452
|
+
const data =
|
|
453
|
+
'<script>window.__VIEW__=' + JSON.stringify(view) +
|
|
454
|
+
';window.__HEALTH__=' + JSON.stringify(health) + ';</script>'
|
|
455
|
+
return html.replace('<script src="view.js"></script>', data)
|
|
456
|
+
}
|
package/lib/meta.js
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* 怎么算",不做"写的时候删掉什么"。
|
|
11
11
|
* 2. **meta 不等于噪音。** 绝大多数 meta 前缀是有业务语义的定点标记
|
|
12
12
|
* (`seen:` / `looked:` / `sched:` / `wake:` / `diary:` / `sleep:` / `fired:` /
|
|
13
|
-
* `browse:` / `look:` / `watched:` / `proactive-turn:` / `proactive-
|
|
13
|
+
* `browse:` / `look:` / `watched:` / `proactive-turn:` / `proactive-silent:` /
|
|
14
|
+
* `proactive-fail:` / `proactive-say:` /
|
|
14
15
|
* `ask-no:` / `ask-done:` / `outing-reject:` / `possess-reject:` / `absence-reject:`),有读取方按前缀解析。
|
|
15
16
|
* 只有 NOISE_PREFIXES 里这两类**没有任何读取方需要逐条历史**,才归到"纯记账"。
|
|
16
17
|
* 3. **记账是必要的。** 别为了数字好看去堵写入——上面那些前缀一旦不写,
|
package/lib/observe-home.js
CHANGED
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
|
|
10
10
|
import fs from 'node:fs'
|
|
11
11
|
import { join } from 'node:path'
|
|
12
|
+
import { timingSafeEqual } from 'node:crypto'
|
|
12
13
|
import { fileURLToPath } from 'node:url'
|
|
13
14
|
import { readEvents, paths } from './store.js'
|
|
15
|
+
import { claimBridgeSession, releaseBridgeSession } from './bridgeclaim.js'
|
|
14
16
|
import { loadConfig, updateConfig, dateKey } from './settings.js'
|
|
15
17
|
import { selfPronounOf, fillSelf } from './selfpronoun.js'
|
|
16
18
|
import { deriveSelf } from './derive.js'
|
|
@@ -95,17 +97,66 @@ export function createBridgeHandlers(env) {
|
|
|
95
97
|
})
|
|
96
98
|
}
|
|
97
99
|
|
|
98
|
-
|
|
100
|
+
const tokenOk = (req, want) => {
|
|
101
|
+
if (!want) return false
|
|
102
|
+
const got = String(req?.headers?.['x-fish-token'] ?? '')
|
|
103
|
+
if (!got || got.length !== want.length) return false
|
|
104
|
+
try { return timingSafeEqual(Buffer.from(got), Buffer.from(want)) } catch { return false }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** 认领口与 /say 共用 token;配置没开、没配 token 都当不存在。 */
|
|
108
|
+
const claimGate = async () => {
|
|
109
|
+
const { config } = await loadConfig(root)
|
|
110
|
+
const b = config?.bridge ?? {}
|
|
111
|
+
if (!b.claim) return { code: 'disabled', status: 404, error: '认领口没开' }
|
|
112
|
+
if (!b.token) return { code: 'no_token', status: 503, error: '没有配置 bridge.token,认领口不接客' }
|
|
113
|
+
return { token: String(b.token) }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const claimHandler = async (req, res) => {
|
|
117
|
+
if (req.method !== 'POST') return send(res, 405, { error: 'method not allowed' })
|
|
118
|
+
const gate = await claimGate()
|
|
119
|
+
if (gate.code) return send(res, gate.status, { ok: false, code: gate.code, error: gate.error })
|
|
120
|
+
if (!tokenOk(req, gate.token)) return send(res, 401, { ok: false, code: 'bad_token', error: 'token 不对' })
|
|
121
|
+
const raw = await readBody(req, 20_000)
|
|
122
|
+
/** @type {Record<string, any>} */
|
|
123
|
+
let body = {}
|
|
124
|
+
try { body = JSON.parse(raw || '{}') } catch { return send(res, 400, { ok: false, code: 'bad_body', error: 'body 不是 JSON' }) }
|
|
125
|
+
const r = claimBridgeSession({
|
|
126
|
+
root,
|
|
127
|
+
sessionId: body?.sessionId,
|
|
128
|
+
herDir: paths(root).herDir,
|
|
129
|
+
log: flog('warn'),
|
|
130
|
+
})
|
|
131
|
+
const status = r.ok ? 200 : r.code === 'unknown_session' ? 400 : 409
|
|
132
|
+
return send(res, status, { ...r, error: r.ok ? undefined : (r.why ?? r.code) })
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const releaseHandler = async (req, res) => {
|
|
136
|
+
if (req.method !== 'POST') return send(res, 405, { error: 'method not allowed' })
|
|
137
|
+
const gate = await claimGate()
|
|
138
|
+
if (gate.code) return send(res, gate.status, { ok: false, code: gate.code, error: gate.error })
|
|
139
|
+
if (!tokenOk(req, gate.token)) return send(res, 401, { ok: false, code: 'bad_token', error: 'token 不对' })
|
|
140
|
+
const raw = await readBody(req, 20_000)
|
|
141
|
+
/** @type {Record<string, any>} */
|
|
142
|
+
let body = {}
|
|
143
|
+
try { body = JSON.parse(raw || '{}') } catch { return send(res, 400, { ok: false, code: 'bad_body', error: 'body 不是 JSON' }) }
|
|
144
|
+
const r = await releaseBridgeSession({ root, sessionId: body?.sessionId, herDir: paths(root).herDir })
|
|
145
|
+
const status = r.ok ? 200 : r.code === 'unknown_session' ? 404 : 409
|
|
146
|
+
return send(res, status, { ...r, error: r.ok ? undefined : (r.why ?? r.code) })
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return { sayHandler, whoamiHandler, claimHandler, releaseHandler }
|
|
99
150
|
}
|
|
100
151
|
|
|
101
152
|
/**
|
|
102
153
|
* @param {import('./types.js').ObserveEnv} env
|
|
103
|
-
* @param {{ sayHandler: import('./types.js').ObserveHandler, whoamiHandler: import('./types.js').ObserveHandler }} bridgeHandlers
|
|
154
|
+
* @param {{ sayHandler: import('./types.js').ObserveHandler, whoamiHandler: import('./types.js').ObserveHandler, claimHandler: import('./types.js').ObserveHandler, releaseHandler: import('./types.js').ObserveHandler }} bridgeHandlers
|
|
104
155
|
* @returns {import('./types.js').ObserveRouteEntry[]}
|
|
105
156
|
*/
|
|
106
157
|
export function buildHomeRoutes(env, bridgeHandlers) {
|
|
107
158
|
const { ctx, root, flog, inflight, awayFromBeat, reclaimTenant } = env
|
|
108
|
-
const { sayHandler, whoamiHandler } = bridgeHandlers
|
|
159
|
+
const { sayHandler, whoamiHandler, claimHandler, releaseHandler } = bridgeHandlers
|
|
109
160
|
|
|
110
161
|
return [
|
|
111
162
|
['/wake', async (req, res) => {
|
|
@@ -118,6 +169,8 @@ export function buildHomeRoutes(env, bridgeHandlers) {
|
|
|
118
169
|
|
|
119
170
|
['/say', sayHandler],
|
|
120
171
|
['/whoami', whoamiHandler],
|
|
172
|
+
['/claim', claimHandler],
|
|
173
|
+
['/release', releaseHandler],
|
|
121
174
|
|
|
122
175
|
['/inbox', async (req, res) => {
|
|
123
176
|
if (req.method === 'POST') {
|
|
@@ -382,3 +435,5 @@ export function buildHomeRoutes(env, bridgeHandlers) {
|
|
|
382
435
|
}],
|
|
383
436
|
]
|
|
384
437
|
}
|
|
438
|
+
|
|
439
|
+
|
package/lib/observe-state.js
CHANGED
|
@@ -147,7 +147,25 @@ export function buildStateRoutes(env) {
|
|
|
147
147
|
return { id: p.id, rule: p.grant?.rule, title: r?.title ?? '', text: p.text ?? '', day: p.day ?? null }
|
|
148
148
|
})(),
|
|
149
149
|
grants: activeGrants(events, Date.now()),
|
|
150
|
-
|
|
150
|
+
// 2026-11-26(外部反馈「一天最多几版」填 10、重开又回 2):这一份是设置页的
|
|
151
|
+
// 回填白名单。客户端 `s.config?.X` 读到的每个键都必须在这儿出现——缺一个,
|
|
152
|
+
// 界面就落回硬编码默认值(`?? 2`),用户看到的是「没生效」,下一次整表保存
|
|
153
|
+
// 还可能把默认值写回盘上。加设置项时两边一起加;下面有 guard 测试盯着。
|
|
154
|
+
config: {
|
|
155
|
+
window: config.window,
|
|
156
|
+
wakesPerDay: config.wakesPerDay,
|
|
157
|
+
daily: config.daily,
|
|
158
|
+
diary: { enabled: config.diary.enabled, visible: config.diary.visible },
|
|
159
|
+
absenceAfterDays: config.absenceAfterDays,
|
|
160
|
+
works: { versionsPerDay: config.works.versionsPerDay, keepVersions: config.works.keepVersions },
|
|
161
|
+
drive: { enabled: config.drive.enabled },
|
|
162
|
+
interest: { enabled: config.interest.enabled },
|
|
163
|
+
dream: { enabled: config.dream.enabled },
|
|
164
|
+
cue: { enabled: config.cue.enabled },
|
|
165
|
+
memory: { selfWake: config.memory.selfWake, echo: config.memory.echo },
|
|
166
|
+
proactive: config.proactive,
|
|
167
|
+
self: { pronoun: selfPronounOf(config) },
|
|
168
|
+
},
|
|
151
169
|
meta: { root, skippedLines: skipped, configFresh: fresh, configBroken: broken, dateKey: dateKey(), version: normalizeVersion(deps.version) || String(deps.version ?? '') },
|
|
152
170
|
tenancy: (() => {
|
|
153
171
|
const t = deps.tenancy
|
package/lib/observe.js
CHANGED
|
@@ -19,6 +19,8 @@ import { registerSessionPressure } from './session-pressure.js'
|
|
|
19
19
|
import { createQrLogin } from './biliqr.js'
|
|
20
20
|
import { renderWikiPage } from './wiki.js'
|
|
21
21
|
import { startWikiServer, closeWikiServer } from './wikiserve.js'
|
|
22
|
+
import { startMapServer, closeMapServer, mapUrl } from './mapserve.js'
|
|
23
|
+
import { renderMemoryMapHtml } from './memorymap.js'
|
|
22
24
|
import { startBridgeServer, closeBridgeServer } from './bridgeserve.js'
|
|
23
25
|
import { restoreBackup, RESTORE_MAX_BYTES } from './backup.js'
|
|
24
26
|
import { logLine } from './log.js'
|
|
@@ -114,7 +116,7 @@ export function registerObserve(ctx, deps = {}) {
|
|
|
114
116
|
disposers.push(pressure.dispose)
|
|
115
117
|
|
|
116
118
|
let bridgePortLive = 0
|
|
117
|
-
/** @type {{ sayHandler: import('./types.js').ObserveHandler, whoamiHandler: import('./types.js').ObserveHandler } | null} */
|
|
119
|
+
/** @type {{ sayHandler: import('./types.js').ObserveHandler, whoamiHandler: import('./types.js').ObserveHandler, claimHandler: import('./types.js').ObserveHandler, releaseHandler: import('./types.js').ObserveHandler } | null} */
|
|
118
120
|
let bridgeHandlers = null
|
|
119
121
|
|
|
120
122
|
/**
|
|
@@ -135,7 +137,12 @@ export function registerObserve(ctx, deps = {}) {
|
|
|
135
137
|
try { closeBridgeServer() } catch { /* 没起过 */ }
|
|
136
138
|
const st = startBridgeServer({
|
|
137
139
|
port,
|
|
138
|
-
handlers: {
|
|
140
|
+
handlers: {
|
|
141
|
+
'/say': bridgeHandlers.sayHandler,
|
|
142
|
+
'/whoami': bridgeHandlers.whoamiHandler,
|
|
143
|
+
'/claim': bridgeHandlers.claimHandler,
|
|
144
|
+
'/release': bridgeHandlers.releaseHandler,
|
|
145
|
+
},
|
|
139
146
|
log: (/** @type {unknown[]} */ ...a) => logLine('warn', ['桥接投递口:', ...a.map((x) => String(x))], root),
|
|
140
147
|
})
|
|
141
148
|
bridgePortLive = port
|
|
@@ -163,6 +170,7 @@ export function registerObserve(ctx, deps = {}) {
|
|
|
163
170
|
|
|
164
171
|
bridgeHandlers = createBridgeHandlers(env)
|
|
165
172
|
|
|
173
|
+
/** @type {import('./types.js').ObserveRouteEntry[]} */
|
|
166
174
|
const routes = [
|
|
167
175
|
...buildStateRoutes(env),
|
|
168
176
|
...buildConfigRoutes(env),
|
|
@@ -170,6 +178,14 @@ export function registerObserve(ctx, deps = {}) {
|
|
|
170
178
|
...buildHomeRoutes(env, bridgeHandlers),
|
|
171
179
|
...buildDataRoutes(env),
|
|
172
180
|
...buildOutingRoutes(env),
|
|
181
|
+
['/memory-map', async (_req, res) => {
|
|
182
|
+
// 页面本身在独立端口上,这里只把地址告诉前端
|
|
183
|
+
const url = mapUrl()
|
|
184
|
+
try {
|
|
185
|
+
res.writeHead(url ? 200 : 503, { 'content-type': 'application/json; charset=utf-8' })
|
|
186
|
+
res.end(JSON.stringify(url ? { url } : { error: '记忆图没起来' }))
|
|
187
|
+
} catch { /* ignore */ }
|
|
188
|
+
}],
|
|
173
189
|
]
|
|
174
190
|
|
|
175
191
|
const webServer = safeGet(ctx, 'webServer')
|
|
@@ -198,6 +214,18 @@ export function registerObserve(ctx, deps = {}) {
|
|
|
198
214
|
})
|
|
199
215
|
disposers.push(() => { try { closeWikiServer() } catch { /* ignore */ } })
|
|
200
216
|
|
|
217
|
+
startMapServer({
|
|
218
|
+
getHtml: async () => {
|
|
219
|
+
try {
|
|
220
|
+
return await renderMemoryMapHtml(root)
|
|
221
|
+
} catch (err) {
|
|
222
|
+
logLine('warn', ['记忆图生成失败', String(/** @type {any} */ (err)?.message ?? err)], root)
|
|
223
|
+
throw err
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
})
|
|
227
|
+
disposers.push(() => { try { closeMapServer() } catch { /* ignore */ } })
|
|
228
|
+
|
|
201
229
|
void (async () => {
|
|
202
230
|
try {
|
|
203
231
|
const { config: bc } = await loadConfig(root)
|
|
@@ -215,3 +243,4 @@ export function registerObserve(ctx, deps = {}) {
|
|
|
215
243
|
},
|
|
216
244
|
}
|
|
217
245
|
}
|
|
246
|
+
|