dsh-macro-memory 0.0.0-stage → 0.3.0
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 +457 -2
- package/cordis.patch.yml +6 -0
- package/lib/client.js +3623 -0
- package/lib/index.js +469 -0
- package/lib/macro/brand.js +82 -0
- package/lib/macro/bridge.js +158 -0
- package/lib/macro/chain.js +206 -0
- package/lib/macro/contract.js +471 -0
- package/lib/macro/cost.js +164 -0
- package/lib/macro/defs/admin.js +439 -0
- package/lib/macro/defs/dream.js +24 -0
- package/lib/macro/defs/link.js +257 -0
- package/lib/macro/defs/project.js +25 -0
- package/lib/macro/defs/read.js +145 -0
- package/lib/macro/defs/remember.js +213 -0
- package/lib/macro/defs/search.js +661 -0
- package/lib/macro/defs/update.js +161 -0
- package/lib/macro/dreamledger.js +1398 -0
- package/lib/macro/facade.js +135 -0
- package/lib/macro/fusion.js +182 -0
- package/lib/macro/linkflow.js +391 -0
- package/lib/macro/links.js +448 -0
- package/lib/macro/neighbor.js +209 -0
- package/lib/macro/panel.js +96 -0
- package/lib/macro/prompt.js +139 -0
- package/lib/macro/provenance.js +148 -0
- package/lib/macro/render.js +35 -0
- package/lib/macro/revisions.js +253 -0
- package/lib/macro/shared.js +113 -0
- package/lib/macro/store.js +103 -0
- package/lib/macro/tokencost.js +90 -0
- package/lib/macro/tools.js +67 -0
- package/package.json +54 -4
- package/vendor/VENDOR.json +23 -0
- package/vendor/dsh-memory-nebula/CONTRIBUTING.md +48 -0
- package/vendor/dsh-memory-nebula/LICENSE +21 -0
- package/vendor/dsh-memory-nebula/README.en.md +203 -0
- package/vendor/dsh-memory-nebula/README.md +253 -0
- package/vendor/dsh-memory-nebula/SECURITY.md +43 -0
- package/vendor/dsh-memory-nebula/SUPPORT.md +33 -0
- package/vendor/dsh-memory-nebula/cordis.patch.yml +4 -0
- package/vendor/dsh-memory-nebula/lib/client.js +105 -0
- package/vendor/dsh-memory-nebula/lib/host/adapters/index.js +279 -0
- package/vendor/dsh-memory-nebula/lib/host/adapters/ingest.js +230 -0
- package/vendor/dsh-memory-nebula/lib/host/adapters/meow.js +317 -0
- package/vendor/dsh-memory-nebula/lib/host/adapters/notes.js +305 -0
- package/vendor/dsh-memory-nebula/lib/host/adapters/sqlite.js +287 -0
- package/vendor/dsh-memory-nebula/lib/host/adapters/util.js +231 -0
- package/vendor/dsh-memory-nebula/lib/host/bridge.js +351 -0
- package/vendor/dsh-memory-nebula/lib/host/compress.js +97 -0
- package/vendor/dsh-memory-nebula/lib/host/demo.js +357 -0
- package/vendor/dsh-memory-nebula/lib/host/diagnostics.js +125 -0
- package/vendor/dsh-memory-nebula/lib/host/doctor.js +270 -0
- package/vendor/dsh-memory-nebula/lib/host/graph.js +1663 -0
- package/vendor/dsh-memory-nebula/lib/host/graphcache.js +282 -0
- package/vendor/dsh-memory-nebula/lib/host/http.js +993 -0
- package/vendor/dsh-memory-nebula/lib/host/injectcfg.js +95 -0
- package/vendor/dsh-memory-nebula/lib/host/ledger.js +175 -0
- package/vendor/dsh-memory-nebula/lib/host/live.js +204 -0
- package/vendor/dsh-memory-nebula/lib/host/nebula.js +2105 -0
- package/vendor/dsh-memory-nebula/lib/host/page.js +75 -0
- package/vendor/dsh-memory-nebula/lib/host/path.js +83 -0
- package/vendor/dsh-memory-nebula/lib/host/recall.js +451 -0
- package/vendor/dsh-memory-nebula/lib/host/share.js +633 -0
- package/vendor/dsh-memory-nebula/lib/host/sources.js +266 -0
- package/vendor/dsh-memory-nebula/lib/host/store.js +333 -0
- package/vendor/dsh-memory-nebula/lib/host/text.js +410 -0
- package/vendor/dsh-memory-nebula/lib/host/transcripts.js +396 -0
- package/vendor/dsh-memory-nebula/lib/index.js +759 -0
- package/vendor/dsh-memory-nebula/lib/standalone.mjs +315 -0
- package/vendor/dsh-memory-nebula/lib/web/api.js +426 -0
- package/vendor/dsh-memory-nebula/lib/web/app.js +4159 -0
- package/vendor/dsh-memory-nebula/lib/web/i18n.js +580 -0
- package/vendor/dsh-memory-nebula/lib/web/index.html +174 -0
- package/vendor/dsh-memory-nebula/lib/web/nav.js +132 -0
- package/vendor/dsh-memory-nebula/lib/web/render.js +1890 -0
- package/vendor/dsh-memory-nebula/lib/web/space3d.js +1883 -0
- package/vendor/dsh-memory-nebula/lib/web/style.css +1402 -0
- package/vendor/dsh-memory-nebula/locale/en.json +7 -0
- package/vendor/dsh-memory-nebula/locale/zh.json +7 -0
- package/vendor/dsh-memory-nebula/market/assets/icon-180.png +0 -0
- package/vendor/dsh-memory-nebula/market/assets/icon.svg +40 -0
- package/vendor/dsh-memory-nebula/market/index.json +101 -0
- package/vendor/dsh-memory-nebula/package.json +87 -0
- package/vendor/dsh-memory-nebula/sidecar.ps1 +119 -0
- package/vendor/meow-memory/LICENSE +21 -0
- package/vendor/meow-memory/README.en.md +192 -0
- package/vendor/meow-memory/README.md +174 -0
- package/vendor/meow-memory/README.pt-br.md +180 -0
- package/vendor/meow-memory/cordis.patch.yml +7 -0
- package/vendor/meow-memory/lib/client.js +3344 -0
- package/vendor/meow-memory/lib/client.js.map +7 -0
- package/vendor/meow-memory/lib/index.js +9567 -0
- package/vendor/meow-memory/lib/index.js.map +7 -0
- package/vendor/meow-memory/lib/prompts/README.md +65 -0
- package/vendor/meow-memory/lib/prompts/en/dream-atomic.md +36 -0
- package/vendor/meow-memory/lib/prompts/en/dream-header.md +9 -0
- package/vendor/meow-memory/lib/prompts/en/dream-project-summary.md +12 -0
- package/vendor/meow-memory/lib/prompts/en/dream-topic.md +27 -0
- package/vendor/meow-memory/lib/prompts/en/external-memory-notice.md +8 -0
- package/vendor/meow-memory/lib/prompts/en/first-create-notice.md +8 -0
- package/vendor/meow-memory/lib/prompts/en/labels.md +98 -0
- package/vendor/meow-memory/lib/prompts/en/reflect.md +31 -0
- package/vendor/meow-memory/lib/prompts/en/system-guide.md +121 -0
- package/vendor/meow-memory/lib/prompts/en/tools.md +83 -0
- package/vendor/meow-memory/lib/prompts/en/welcome-guide.md +12 -0
- package/vendor/meow-memory/lib/prompts/pt-br/dream-atomic.md +36 -0
- package/vendor/meow-memory/lib/prompts/pt-br/dream-header.md +9 -0
- package/vendor/meow-memory/lib/prompts/pt-br/dream-project-summary.md +12 -0
- package/vendor/meow-memory/lib/prompts/pt-br/dream-topic.md +27 -0
- package/vendor/meow-memory/lib/prompts/pt-br/external-memory-notice.md +8 -0
- package/vendor/meow-memory/lib/prompts/pt-br/first-create-notice.md +8 -0
- package/vendor/meow-memory/lib/prompts/pt-br/labels.md +98 -0
- package/vendor/meow-memory/lib/prompts/pt-br/reflect.md +31 -0
- package/vendor/meow-memory/lib/prompts/pt-br/system-guide.md +121 -0
- package/vendor/meow-memory/lib/prompts/pt-br/tools.md +83 -0
- package/vendor/meow-memory/lib/prompts/pt-br/welcome-guide.md +12 -0
- package/vendor/meow-memory/lib/prompts/zh/dream-atomic.md +36 -0
- package/vendor/meow-memory/lib/prompts/zh/dream-header.md +9 -0
- package/vendor/meow-memory/lib/prompts/zh/dream-project-summary.md +19 -0
- package/vendor/meow-memory/lib/prompts/zh/dream-topic.md +27 -0
- package/vendor/meow-memory/lib/prompts/zh/external-memory-notice.md +8 -0
- package/vendor/meow-memory/lib/prompts/zh/first-create-notice.md +8 -0
- package/vendor/meow-memory/lib/prompts/zh/labels.md +98 -0
- package/vendor/meow-memory/lib/prompts/zh/reflect.md +30 -0
- package/vendor/meow-memory/lib/prompts/zh/system-guide.md +119 -0
- package/vendor/meow-memory/lib/prompts/zh/tools.md +83 -0
- package/vendor/meow-memory/lib/prompts/zh/welcome-guide.md +12 -0
- package/vendor/meow-memory/package.json +64 -0
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
/* 单文件快照
|
|
2
|
+
*
|
|
3
|
+
* [macro-fusion 0.2.11] 快照标题跟着显示名改成「宏记忆 · 星图 · 离线快照」;
|
|
4
|
+
* 注意 put 的 needle 必须与 lib/web/index.html 的 <title> 保持一字不差,否则快照会抛「找不到 标题」。
|
|
5
|
+
*
|
|
6
|
+
* 把一张星图压成一个 HTML:样式、脚本、数据全部内联,双击就能看。
|
|
7
|
+
* 没有后端、没有网络请求 —— 搜索、点节点、证据链都在浏览器里本地算。
|
|
8
|
+
*
|
|
9
|
+
* 0.6.0 起支持「切片」:可以只导出一个工作区、一个项目,或某个节点周围 N 跳。
|
|
10
|
+
* 切片不是把整图藏起来,而是根本不把范围外的记忆写进文件——隐私不能靠前端隐藏。
|
|
11
|
+
*
|
|
12
|
+
* 注意:快照里包含记忆全文。它是一份「用户主动导出」的文件,
|
|
13
|
+
* 不是自动分享;界面上必须说清楚,别让人以为点一下就上传了。
|
|
14
|
+
*/
|
|
15
|
+
import { readFile } from 'node:fs/promises'
|
|
16
|
+
import { createHash } from 'node:crypto'
|
|
17
|
+
import { auditHygiene, auditHygieneAsync } from './graph.js'
|
|
18
|
+
|
|
19
|
+
// NEBULA_SHARE_PROFILE=1 时把切片与拼装的分段耗时打去 stderr。
|
|
20
|
+
// 导出慢的时候先问「慢在哪一段」,别拿总时长猜。
|
|
21
|
+
let shareT0 = 0
|
|
22
|
+
const shareTick = (label) => {
|
|
23
|
+
if (process.env.NEBULA_SHARE_PROFILE) console.error('[share] ' + label + ' +' + (Date.now() - shareT0) + 'ms')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const WEB = new URL('../web/', import.meta.url)
|
|
27
|
+
const MAX_HOPS = 5
|
|
28
|
+
// 快照分片:5 万条的整库快照单文件会到 40MB 上下,双击打开先卡半分钟。
|
|
29
|
+
// 默认只写前 2 万条(按重要度),其余分片导出;上限仍允许到 5 万,想全量得显式传 limit。
|
|
30
|
+
export const SHARE_NODE_CAP = 20000
|
|
31
|
+
export const SHARE_NODE_MAX = 50000
|
|
32
|
+
/** 快照里的边按列存,省掉 15 万条边重复的键名。客户端 api.js 会按列展开。 */
|
|
33
|
+
const EDGE_COLUMNS = ['s', 'd', 'w', 't', 'curated']
|
|
34
|
+
|
|
35
|
+
function packEdgeRows(edges) {
|
|
36
|
+
return (edges || []).map((e) => EDGE_COLUMNS.map((key) => (e[key] === undefined ? null : e[key])))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** 节点也按列存:20k 节点的字段名重复 20k 次,是快照体积的大头。 */
|
|
40
|
+
function packNodeRows(nodes) {
|
|
41
|
+
const columns = []
|
|
42
|
+
const seen = new Set()
|
|
43
|
+
for (const node of nodes || []) {
|
|
44
|
+
for (const key of Object.keys(node || {})) {
|
|
45
|
+
if (seen.has(key)) continue
|
|
46
|
+
seen.add(key)
|
|
47
|
+
columns.push(key)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const rows = (nodes || []).map((node) => columns.map((key) => (node[key] === undefined ? null : node[key])))
|
|
51
|
+
return { columns, rows }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function fail(status, message) {
|
|
55
|
+
const err = new Error(message)
|
|
56
|
+
err.status = status
|
|
57
|
+
return err
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 内联进 <script> 的 JSON:把可能提前闭合标签的字符转义掉。 */
|
|
61
|
+
function safeJson(value) {
|
|
62
|
+
return JSON.stringify(value)
|
|
63
|
+
.replace(/</g, '\\u003c')
|
|
64
|
+
.replace(/\u2028/g, '\\u2028')
|
|
65
|
+
.replace(/\u2029/g, '\\u2029')
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 内联进 <script> 的源码:只处理真正会闭合标签的那一处。 */
|
|
69
|
+
function inlineScript(source) {
|
|
70
|
+
return String(source).replace(/<\/script/gi, '<\\/script')
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function put(html, needle, replacement, what) {
|
|
74
|
+
if (!html.includes(needle)) throw new Error('share: 页面结构变了,找不到' + what)
|
|
75
|
+
// 用函数式 replace:源码里有 `$&` / `$1`(app.js 的转义正则就有),
|
|
76
|
+
// 当字符串替换会被当成替换模式展开,把源码改坏——这是真踩过的坑。
|
|
77
|
+
return html.replace(needle, () => replacement)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 解析 ?scope=。返回 null 表示整张图;格式错误抛 400。
|
|
82
|
+
* 支持的写法:
|
|
83
|
+
* ws:<工作区 slug 或显示名>
|
|
84
|
+
* project:<项目名>
|
|
85
|
+
* focus:<节点 id>
|
|
86
|
+
*/
|
|
87
|
+
export function parseShareScope(raw) {
|
|
88
|
+
const text = String(raw || '').trim()
|
|
89
|
+
if (!text || text === 'all') return null
|
|
90
|
+
const at = text.indexOf(':')
|
|
91
|
+
const kind = at > 0 ? text.slice(0, at).toLowerCase() : ''
|
|
92
|
+
const value = at > 0 ? text.slice(at + 1).trim() : ''
|
|
93
|
+
if (!kind || !value || !['ws', 'project', 'focus'].includes(kind)) {
|
|
94
|
+
throw fail(400, 'scope 要写成 ws:<工作区>、project:<项目> 或 focus:<节点 id>')
|
|
95
|
+
}
|
|
96
|
+
return { kind, value }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 解析 ?hops=(快照以 focus 为中心时的扩散跳数)。
|
|
101
|
+
* 不传按 2;写错直接 400,不静默回落到默认值——和 parseShareLimit 同一条道理:
|
|
102
|
+
* 「--hops 9」被悄悄按 5 处理、拼错被按 2 处理,用户会以为自己看到的是那个范围。
|
|
103
|
+
*/
|
|
104
|
+
export function parseShareHops(raw) {
|
|
105
|
+
const text = String(raw == null ? '' : raw).trim()
|
|
106
|
+
if (!text) return 2
|
|
107
|
+
const n = Number(text)
|
|
108
|
+
if (!/^\d+$/.test(text) || !Number.isFinite(n) || n < 1 || n > MAX_HOPS) {
|
|
109
|
+
throw fail(400, 'hops 需要 1–' + MAX_HOPS + ' 的整数,收到的是「' + text + '」')
|
|
110
|
+
}
|
|
111
|
+
return n
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 解析 ?limit=(快照分片上限)。不传就是默认 2 万条;
|
|
116
|
+
* 拼错直接 400,不静默回落到默认值——导出前的裁剪数量被悄悄改掉,
|
|
117
|
+
* 用户会以为「整库都在这份文件里」。
|
|
118
|
+
* @param {string|number|null} raw
|
|
119
|
+
*/
|
|
120
|
+
export function parseShareLimit(raw) {
|
|
121
|
+
const text = String(raw == null ? '' : raw).trim()
|
|
122
|
+
if (!text) return SHARE_NODE_CAP
|
|
123
|
+
if (!/^\d+$/.test(text)) throw fail(400, 'limit 需要 1–' + SHARE_NODE_MAX + ' 的整数,收到的是「' + text + '」')
|
|
124
|
+
const n = Number(text)
|
|
125
|
+
if (!Number.isFinite(n) || n < 1) throw fail(400, 'limit 需要 1–' + SHARE_NODE_MAX + ' 的整数')
|
|
126
|
+
if (n > SHARE_NODE_MAX) {
|
|
127
|
+
throw fail(400, 'limit 最多 ' + SHARE_NODE_MAX + ' 条;更大的库请按工作区切片,分几份导出')
|
|
128
|
+
}
|
|
129
|
+
return n
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 解析 ?hide=。可以重复传,也可以写成逗号分隔:
|
|
134
|
+
* hide=level:user
|
|
135
|
+
* hide=ws:日记&hide=project:私人
|
|
136
|
+
* 只接受白名单里的字段;拼错就 400,不静默忽略——导出前的隐私规则,
|
|
137
|
+
* 「我以为藏了」比「报错」危险得多。
|
|
138
|
+
*
|
|
139
|
+
* @param {string|string[]|null} raw
|
|
140
|
+
* @returns {{kind:'level'|'ws'|'project'|'status',value:string}[]}
|
|
141
|
+
*/
|
|
142
|
+
export function parseShareHide(raw) {
|
|
143
|
+
const parts = (Array.isArray(raw) ? raw : [raw])
|
|
144
|
+
.filter((x) => x != null)
|
|
145
|
+
.flatMap((x) => String(x).split(','))
|
|
146
|
+
.map((x) => x.trim())
|
|
147
|
+
.filter(Boolean)
|
|
148
|
+
const rules = []
|
|
149
|
+
for (const text of parts) {
|
|
150
|
+
const at = text.indexOf(':')
|
|
151
|
+
const kind = at > 0 ? text.slice(0, at).toLowerCase() : ''
|
|
152
|
+
const value = at > 0 ? text.slice(at + 1).trim() : ''
|
|
153
|
+
if (!kind || !value || !['level', 'ws', 'project', 'status'].includes(kind)) {
|
|
154
|
+
throw fail(400, 'hide 要写成 level:<层级>、ws:<工作区>、project:<项目> 或 status:<状态>')
|
|
155
|
+
}
|
|
156
|
+
rules.push({ kind, value })
|
|
157
|
+
}
|
|
158
|
+
return rules
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function hidesNode(node, rules) {
|
|
162
|
+
for (const rule of rules) {
|
|
163
|
+
if (rule.kind === 'level' && node.level === rule.value) return true
|
|
164
|
+
if (rule.kind === 'ws' && (node.cluster === rule.value || node.ws === rule.value)) return true
|
|
165
|
+
if (rule.kind === 'project' && String(node.project || '') === rule.value) return true
|
|
166
|
+
if (rule.kind === 'status' && node.status === rule.value) return true
|
|
167
|
+
}
|
|
168
|
+
return false
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** 概览里的来源会带本机路径;快照是拿出去给人看的,只留名字与规模。 */
|
|
172
|
+
function publicSources(list) {
|
|
173
|
+
return (list || []).map((s) => ({
|
|
174
|
+
key: s.key,
|
|
175
|
+
title: s.title,
|
|
176
|
+
size: s.size,
|
|
177
|
+
kind: s.kind,
|
|
178
|
+
count: s.count,
|
|
179
|
+
}))
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** 概览顶层还挂着数据库路径 / 上次错误;这些是本机诊断信息,不进快照。 */
|
|
183
|
+
function publicOverview(ov) {
|
|
184
|
+
const { dbPath, db, lastError, readErrors, ...rest } = ov || {}
|
|
185
|
+
// 读不动的库要留在快照里(不然拿到文件的人不知道少了哪一块),
|
|
186
|
+
// 但本机路径不能跟着出去:只留名字、标题与原因。
|
|
187
|
+
const safeReadErrors = (readErrors || []).map((e) => ({
|
|
188
|
+
key: e?.key || '',
|
|
189
|
+
title: e?.title || e?.key || '',
|
|
190
|
+
error: e?.error || '',
|
|
191
|
+
}))
|
|
192
|
+
return { ...rest, sources: publicSources(rest.sources), readErrors: safeReadErrors }
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function rawIndex(nebula) {
|
|
196
|
+
return nebula.index?.rawById || new Map((nebula.nodes || []).map((n) => [n.id, n]))
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function focusSet(full, id, hops) {
|
|
200
|
+
const byId = new Map((full.nodes || []).map((n, i) => [n.id, i]))
|
|
201
|
+
const start = byId.get(id)
|
|
202
|
+
if (start == null) throw fail(404, '找不到这条记忆:' + id)
|
|
203
|
+
const adj = new Map()
|
|
204
|
+
const link = (a, b) => {
|
|
205
|
+
if (!adj.has(a)) adj.set(a, [])
|
|
206
|
+
adj.get(a).push(b)
|
|
207
|
+
}
|
|
208
|
+
for (const e of full.edges || []) {
|
|
209
|
+
link(e.s, e.d)
|
|
210
|
+
link(e.d, e.s)
|
|
211
|
+
}
|
|
212
|
+
const seen = new Set([start])
|
|
213
|
+
let edge = [start]
|
|
214
|
+
for (let step = 0; step < hops; step++) {
|
|
215
|
+
const next = []
|
|
216
|
+
for (const at of edge) {
|
|
217
|
+
for (const to of adj.get(at) || []) {
|
|
218
|
+
if (seen.has(to)) continue
|
|
219
|
+
seen.add(to)
|
|
220
|
+
next.push(to)
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (!next.length) break
|
|
224
|
+
edge = next
|
|
225
|
+
}
|
|
226
|
+
return seen
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* 按范围切出一张自洽的公开图 + 该范围的 overview。
|
|
231
|
+
* 边会在切片后重新编号;统计、簇、体检都只针对切出来的这一片重算,
|
|
232
|
+
* 不让读者把「这个工作区的数字」误当成「整个库的数字」。
|
|
233
|
+
*
|
|
234
|
+
* @param {import('./nebula.js').Nebula} nebula
|
|
235
|
+
* @param {null|{kind:'ws'|'project'|'focus',value:string}} scope
|
|
236
|
+
* @param {{hops?:number}} [opts]
|
|
237
|
+
*/
|
|
238
|
+
/**
|
|
239
|
+
* 体检的入参:把切片节点还原成原始记忆(要正文与关键词),边换成下标。
|
|
240
|
+
* 只备料不算账——算账那一步必须留在两个壳里,不然同步体检会把事件循环按住 3 秒。
|
|
241
|
+
*/
|
|
242
|
+
function hygieneArgsFor(nodes, edges, rawById) {
|
|
243
|
+
return {
|
|
244
|
+
nodes: nodes.map(
|
|
245
|
+
(n) =>
|
|
246
|
+
rawById.get(n.id) || {
|
|
247
|
+
id: n.id,
|
|
248
|
+
level: n.level,
|
|
249
|
+
title: n.label,
|
|
250
|
+
content: '',
|
|
251
|
+
keywords: [],
|
|
252
|
+
status: n.status,
|
|
253
|
+
createdAt: n.createdAt,
|
|
254
|
+
updatedAt: n.createdAt,
|
|
255
|
+
hits: n.hits,
|
|
256
|
+
},
|
|
257
|
+
),
|
|
258
|
+
edges: edges.map((e) => ({ s: e.s, d: e.d, w: e.w, type: e.t || e.type })),
|
|
259
|
+
nodeIds: nodes.map((n) => n.id),
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function buildShareSlice(nebula, scope = null, opts = {}) {
|
|
264
|
+
shareT0 = Date.now()
|
|
265
|
+
// 必须拿整张图,不能拿默认的第一页:publicGraph() 对大库只会给前 1 万条,
|
|
266
|
+
// 于是「整张星图」的快照里其实只有 1 万条,而 scope.trimmed 还是 null(看起来没裁)。
|
|
267
|
+
// 5 万条的库上这条 bug 让 8.65MB 的快照只装了两成记忆,且毫无提示。
|
|
268
|
+
const full = nebula.publicGraph({ all: true })
|
|
269
|
+
shareTick('publicGraph(all)')
|
|
270
|
+
const rawById = rawIndex(nebula)
|
|
271
|
+
const rules =
|
|
272
|
+
Array.isArray(opts.hide) && opts.hide.length && typeof opts.hide[0] === 'object'
|
|
273
|
+
? opts.hide // 路由层已经 parse 过,别把 {kind,value} 再字符串化一次
|
|
274
|
+
: parseShareHide(opts.hide)
|
|
275
|
+
const hops = parseShareHops(opts.hops)
|
|
276
|
+
const withContent = (node) => {
|
|
277
|
+
const raw = rawById.get(node.id)
|
|
278
|
+
return raw?.content ? { ...node, content: raw.content } : { ...node }
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// 没范围也没隐藏规则:原样整图,保留完整的 cards / truth / externals。
|
|
282
|
+
// 但超过分片上限时不能走这条「原样」:那会绕过裁剪,把 40MB 全塞进一个文件。
|
|
283
|
+
if (!scope && !rules.length && (full.nodes || []).length <= parseShareLimit(opts.limit)) {
|
|
284
|
+
const ov = nebula.overview({ hygiene: false })
|
|
285
|
+
const nodes = (full.nodes || []).map(withContent)
|
|
286
|
+
return {
|
|
287
|
+
payload: {
|
|
288
|
+
graph: { ...full, sources: publicSources(full.sources), nodes },
|
|
289
|
+
overview: publicOverview(ov),
|
|
290
|
+
scope: { kind: 'all', value: '', label: '整张星图', hops: 0, hidden: 0, hide: [], trimmed: null },
|
|
291
|
+
},
|
|
292
|
+
// 整库视图不重算:直接按整库节点算一遍体检(异步壳上照样分片)
|
|
293
|
+
hygieneArgs: hygieneArgsFor(nodes, full.edges || [], rawById),
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
let keep
|
|
298
|
+
let seedIdx = -1
|
|
299
|
+
if (!scope) {
|
|
300
|
+
keep = new Set(full.nodes.map((_, i) => i))
|
|
301
|
+
} else if (scope.kind === 'focus') {
|
|
302
|
+
seedIdx = full.nodes.findIndex((n) => n.id === scope.value)
|
|
303
|
+
keep = focusSet(full, scope.value, hops)
|
|
304
|
+
} else {
|
|
305
|
+
keep = new Set()
|
|
306
|
+
for (let i = 0; i < full.nodes.length; i++) {
|
|
307
|
+
const n = full.nodes[i]
|
|
308
|
+
if (scope.kind === 'ws' && (n.cluster === scope.value || n.ws === scope.value)) keep.add(i)
|
|
309
|
+
else if (scope.kind === 'project' && String(n.project || '') === scope.value) keep.add(i)
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// 隐藏规则在范围之后生效:先选「分享哪一片」,再从中剔掉不该出门的记忆。
|
|
314
|
+
// 顺序反了会把「整个日记工作区」重新算成空范围,错误信息也会误导。
|
|
315
|
+
let hidden = 0
|
|
316
|
+
for (const i of [...keep]) {
|
|
317
|
+
if (hidesNode(full.nodes[i], rules)) {
|
|
318
|
+
keep.delete(i)
|
|
319
|
+
hidden++
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (scope?.kind === 'focus' && !keep.has(seedIdx)) {
|
|
323
|
+
throw fail(400, '起点这条记忆被 hide 排除了,没法以它为中心切片:' + scope.value)
|
|
324
|
+
}
|
|
325
|
+
if (!keep.size) {
|
|
326
|
+
throw fail(
|
|
327
|
+
404,
|
|
328
|
+
hidden > 0
|
|
329
|
+
? '这个范围里没有可分享的记忆(' + hidden + ' 条都被 hide 排除了)'
|
|
330
|
+
: '这个范围里没有记忆:' + (scope?.value || ''),
|
|
331
|
+
)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// 快照分片:范围选好之后再按上限裁一次。
|
|
335
|
+
// 5 万条的整库快照单文件 40MB 上下,双击打开会先卡住;这里按重要度取前 N 条,
|
|
336
|
+
// 并把「裁了多少」写进标签与 scope.trimmed —— 用户打开必须一眼看出这不是全量。
|
|
337
|
+
const limit = parseShareLimit(opts.limit)
|
|
338
|
+
const keptTotal = keep.size
|
|
339
|
+
let trimmed = null
|
|
340
|
+
if (keptTotal > limit) {
|
|
341
|
+
const ranked = [...keep]
|
|
342
|
+
.sort((ia, ib) => {
|
|
343
|
+
const a = full.nodes[ia]
|
|
344
|
+
const b = full.nodes[ib]
|
|
345
|
+
return (
|
|
346
|
+
(b.importance || 0) - (a.importance || 0) ||
|
|
347
|
+
(b.hits || 0) - (a.hits || 0) ||
|
|
348
|
+
(b.createdAt || 0) - (a.createdAt || 0) ||
|
|
349
|
+
(a.id < b.id ? -1 : a.id > b.id ? 1 : 0)
|
|
350
|
+
)
|
|
351
|
+
})
|
|
352
|
+
.slice(0, limit)
|
|
353
|
+
keep = new Set(ranked)
|
|
354
|
+
trimmed = { cap: limit, total: keptTotal, shown: keep.size, by: 'importance' }
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const oldToNew = new Map()
|
|
358
|
+
const nodes = []
|
|
359
|
+
for (let i = 0; i < full.nodes.length; i++) {
|
|
360
|
+
if (!keep.has(i)) continue
|
|
361
|
+
oldToNew.set(i, nodes.length)
|
|
362
|
+
nodes.push(withContent(full.nodes[i]))
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
shareTick('nodes ' + nodes.length)
|
|
366
|
+
const edges = []
|
|
367
|
+
const degree = new Array(nodes.length).fill(0)
|
|
368
|
+
for (const e of full.edges || []) {
|
|
369
|
+
const s = oldToNew.get(e.s)
|
|
370
|
+
const d = oldToNew.get(e.d)
|
|
371
|
+
if (s == null || d == null) continue
|
|
372
|
+
edges.push({ ...e, s, d })
|
|
373
|
+
degree[s]++
|
|
374
|
+
degree[d]++
|
|
375
|
+
}
|
|
376
|
+
for (let i = 0; i < nodes.length; i++) nodes[i].degree = degree[i]
|
|
377
|
+
|
|
378
|
+
shareTick('edges ' + edges.length)
|
|
379
|
+
const byWorkspace = {}
|
|
380
|
+
const byLevel = {}
|
|
381
|
+
const byType = {}
|
|
382
|
+
const sessions = new Set()
|
|
383
|
+
for (const n of nodes) {
|
|
384
|
+
byWorkspace[n.ws] = (byWorkspace[n.ws] || 0) + 1
|
|
385
|
+
byLevel[n.level] = (byLevel[n.level] || 0) + 1
|
|
386
|
+
const sid = rawById.get(n.id)?.sessionId
|
|
387
|
+
if (sid) sessions.add(sid)
|
|
388
|
+
}
|
|
389
|
+
for (const e of edges) byType[e.t] = (byType[e.t] || 0) + 1
|
|
390
|
+
|
|
391
|
+
const clusterMap = new Map()
|
|
392
|
+
for (const n of nodes) {
|
|
393
|
+
let c = clusterMap.get(n.cluster)
|
|
394
|
+
if (!c) {
|
|
395
|
+
const base = (full.clusters || []).find((x) => x.id === n.cluster || x.label === n.ws)
|
|
396
|
+
c = base
|
|
397
|
+
? { ...base, size: 0 }
|
|
398
|
+
: { id: n.cluster, title: n.ws, label: n.ws, size: 0, workspaces: [n.cluster] }
|
|
399
|
+
clusterMap.set(n.cluster, c)
|
|
400
|
+
}
|
|
401
|
+
c.size++
|
|
402
|
+
}
|
|
403
|
+
const clusters = [...clusterMap.values()].sort((a, b) => b.size - a.size)
|
|
404
|
+
|
|
405
|
+
shareTick('clusters ' + clusters.length)
|
|
406
|
+
const stats = {
|
|
407
|
+
nodes: nodes.length,
|
|
408
|
+
edges: edges.length,
|
|
409
|
+
workspaces: Object.keys(byWorkspace).length,
|
|
410
|
+
sessions: sessions.size,
|
|
411
|
+
byType,
|
|
412
|
+
byWorkspace,
|
|
413
|
+
byLevel,
|
|
414
|
+
orphans: degree.filter((d) => d === 0).length,
|
|
415
|
+
avgDegree: Math.round((edges.length * 2 * 100) / Math.max(1, nodes.length)) / 100,
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// 体检按切片重算:传原始节点(带正文)与切片后的下标边,不能拿整库的结果冒充。
|
|
419
|
+
// 只准备入参,算留给调用方:2 万条的重复检测要 3 秒,同步算完就把事件循环按住了,
|
|
420
|
+
// 所以同步壳用 auditHygiene、异步壳(HTTP / 快照导出)用 auditHygieneAsync。
|
|
421
|
+
const hygieneArgs = hygieneArgsFor(nodes, edges, rawById)
|
|
422
|
+
|
|
423
|
+
const baseOverview = nebula.overview({ hygiene: false })
|
|
424
|
+
shareTick('overview base')
|
|
425
|
+
const baseLabel = !scope
|
|
426
|
+
? '整张星图'
|
|
427
|
+
: scope.kind === 'ws'
|
|
428
|
+
? '工作区 · ' + (nodes[0]?.ws || scope.value)
|
|
429
|
+
: scope.kind === 'project'
|
|
430
|
+
? '项目 · ' + scope.value
|
|
431
|
+
: '以「' + (nodes.find((n) => n.id === scope.value)?.label || scope.value) + '」为中心 · ' + hops + ' 跳'
|
|
432
|
+
const label =
|
|
433
|
+
baseLabel +
|
|
434
|
+
(hidden ? ' · 已隐去 ' + hidden + ' 条' : '') +
|
|
435
|
+
(trimmed ? ' · 已裁剪 ' + trimmed.shown + ' / ' + trimmed.total + ' 条' : '')
|
|
436
|
+
const overview = {
|
|
437
|
+
...publicOverview(baseOverview),
|
|
438
|
+
stats,
|
|
439
|
+
workspaces: Object.entries(byWorkspace).map(([name, count]) => ({ name, count })),
|
|
440
|
+
levels: byLevel,
|
|
441
|
+
edgeTypes: byType,
|
|
442
|
+
clusters: clusters.slice(0, 8).map((c) => ({ label: c.label, size: c.size, workspaces: c.workspaces })),
|
|
443
|
+
hubs: nodes
|
|
444
|
+
.slice()
|
|
445
|
+
.sort((a, b) => b.degree * (1 + b.importance * 0.25) - a.degree * (1 + a.importance * 0.25))
|
|
446
|
+
.slice(0, 12)
|
|
447
|
+
.map((n) => ({ id: n.id, label: n.label, ws: n.ws, level: n.level, degree: n.degree, importance: n.importance })),
|
|
448
|
+
hygiene: null, // 由两个壳算完再填:算一次要 3 秒(2 万条),不能挡在这里
|
|
449
|
+
// 下面三块是「整库视角」的摘要;切片里留空,免得把全库结论带进局部快照。
|
|
450
|
+
cards: null,
|
|
451
|
+
truth: { total: 0, groups: [], scoped: true },
|
|
452
|
+
externals: null,
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
return {
|
|
456
|
+
payload: {
|
|
457
|
+
graph: { ...full, sources: publicSources(full.sources), nodes, edges, clusters, stats },
|
|
458
|
+
overview,
|
|
459
|
+
scope: {
|
|
460
|
+
kind: scope?.kind || 'all',
|
|
461
|
+
value: scope?.value || '',
|
|
462
|
+
label,
|
|
463
|
+
hops: scope?.kind === 'focus' ? hops : 0,
|
|
464
|
+
hidden,
|
|
465
|
+
hide: rules.map((r) => r.kind + ':' + r.value),
|
|
466
|
+
trimmed,
|
|
467
|
+
},
|
|
468
|
+
},
|
|
469
|
+
hygieneArgs,
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* 切片快照(同步壳):体检同步算完。MCP 工具与单测走这条。
|
|
475
|
+
* @param {import('./nebula.js').Nebula} nebula
|
|
476
|
+
* @param {null|{kind:string,value:string}} [scope]
|
|
477
|
+
* @param {{hops?:number|string, hide?:string|string[], limit?:number|string}} [opts]
|
|
478
|
+
*/
|
|
479
|
+
export function sliceShareGraph(nebula, scope = null, opts = {}) {
|
|
480
|
+
const { payload, hygieneArgs } = buildShareSlice(nebula, scope, opts)
|
|
481
|
+
if (hygieneArgs) payload.overview.hygiene = auditHygiene(hygieneArgs)
|
|
482
|
+
return payload
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* 切片快照(异步壳):体检按 6ms 一片算,让出事件循环。HTTP / 导出走这条。
|
|
487
|
+
*/
|
|
488
|
+
export async function sliceShareGraphAsync(nebula, scope = null, opts = {}) {
|
|
489
|
+
const { payload, hygieneArgs } = buildShareSlice(nebula, scope, opts)
|
|
490
|
+
if (hygieneArgs) payload.overview.hygiene = await auditHygieneAsync(hygieneArgs)
|
|
491
|
+
return payload
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* 生成快照 HTML。
|
|
496
|
+
* @param {import('./nebula.js').Nebula} nebula
|
|
497
|
+
* @param {{version?:string, build?:number}} [meta]
|
|
498
|
+
* @param {{scope?:null|{kind:string,value:string}, hops?:number|string, hide?:string|string[], limit?:number|string}} [opts]
|
|
499
|
+
*/
|
|
500
|
+
export async function buildShareHtml(nebula, meta = {}, opts = {}) {
|
|
501
|
+
shareT0 = Date.now()
|
|
502
|
+
// 走异步壳:体检(2 万条要 3 秒)分片算,导出期间 HTTP 事件循环照常回声。
|
|
503
|
+
const { graph, overview, scope } = await sliceShareGraphAsync(nebula, opts.scope || null, {
|
|
504
|
+
hops: opts.hops,
|
|
505
|
+
hide: opts.hide,
|
|
506
|
+
limit: opts.limit,
|
|
507
|
+
})
|
|
508
|
+
const nodes = graph.nodes || []
|
|
509
|
+
shareTick('slice')
|
|
510
|
+
const packedNodes = packNodeRows(nodes)
|
|
511
|
+
shareTick('pack')
|
|
512
|
+
const payload = {
|
|
513
|
+
version: meta.version || '',
|
|
514
|
+
build: meta.build || 0,
|
|
515
|
+
builtAt: Date.now(),
|
|
516
|
+
sig: (nebula.signature || '') + '-snapshot',
|
|
517
|
+
scope: { ...scope, nodes: nodes.length, edges: (graph.edges || []).length },
|
|
518
|
+
graph: {
|
|
519
|
+
...graph,
|
|
520
|
+
nodes: packedNodes.rows,
|
|
521
|
+
nodeColumns: packedNodes.columns,
|
|
522
|
+
edges: packEdgeRows(graph.edges),
|
|
523
|
+
edgeColumns: EDGE_COLUMNS,
|
|
524
|
+
},
|
|
525
|
+
overview,
|
|
526
|
+
inventory: graph.inventory || null,
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const [html, css, api, nav, i18n, render, space3d, app] = await Promise.all(
|
|
530
|
+
['index.html', 'style.css', 'api.js', 'nav.js', 'i18n.js', 'render.js', 'space3d.js', 'app.js'].map((name) =>
|
|
531
|
+
readFile(new URL(name, WEB), 'utf8'),
|
|
532
|
+
),
|
|
533
|
+
)
|
|
534
|
+
|
|
535
|
+
let out = html
|
|
536
|
+
out = put(out, '<title>宏记忆 · 星图</title>', '<title>宏记忆 · 星图 · 离线快照</title>', ' 标题')
|
|
537
|
+
out = put(
|
|
538
|
+
out,
|
|
539
|
+
'<link rel="stylesheet" href="style.css" />',
|
|
540
|
+
'<style>\n' + css + '\n</style>',
|
|
541
|
+
' 样式表',
|
|
542
|
+
)
|
|
543
|
+
// 原来的 space3d 是「动态插 script,404 就回落到独立引擎」;快照里没有服务器,直接内联。
|
|
544
|
+
out = out.replace(/<script>\s*\/\/ 三维视图脚本[\s\S]*?<\/script>/, () => '<script>\n' + inlineScript(space3d) + '\n</script>')
|
|
545
|
+
for (const [name, source] of [
|
|
546
|
+
['i18n.js', i18n],
|
|
547
|
+
['nav.js', nav],
|
|
548
|
+
['api.js', api],
|
|
549
|
+
['render.js', render],
|
|
550
|
+
['app.js', app],
|
|
551
|
+
]) {
|
|
552
|
+
out = put(
|
|
553
|
+
out,
|
|
554
|
+
'<script src="' + name + '"></script>',
|
|
555
|
+
'<script>\n' + inlineScript(source) + '\n</script>',
|
|
556
|
+
' ' + name,
|
|
557
|
+
)
|
|
558
|
+
}
|
|
559
|
+
// 数据必须比 api.js 先就位:客户端一启动就要判断「这是不是快照」。
|
|
560
|
+
//
|
|
561
|
+
// 校验和(1.11.0):快照会被聊天软件改写、被网盘截断、被编辑器重存成别的编码。
|
|
562
|
+
// 数据以 `<script type="application/json">` 的原始文本存下来,导出时对**这段文本**
|
|
563
|
+
// 算 sha256;客户端拿到的是同一段文本,能一对一比对——不靠重新序列化,也就不会
|
|
564
|
+
// 因为键序或数字格式不同而误报。`<` 已被 safeJson 转义,不会提前闭合 script。
|
|
565
|
+
const dataText = safeJson(payload)
|
|
566
|
+
shareTick('safeJson ' + Math.round(dataText.length / 1048576) + 'MB')
|
|
567
|
+
const dataBytes = Buffer.byteLength(dataText, 'utf8')
|
|
568
|
+
const dataSha = createHash('sha256').update(dataText, 'utf8').digest('hex')
|
|
569
|
+
const bootScript =
|
|
570
|
+
'<script type="application/json" id="nebula-snapshot-data">' +
|
|
571
|
+
dataText +
|
|
572
|
+
'</script>\n' +
|
|
573
|
+
'<script>window.__NEBULA_SNAPSHOT_DATA_TEXT__ = document.getElementById("nebula-snapshot-data").textContent;\n' +
|
|
574
|
+
'try { window.__NEBULA_SNAPSHOT__ = JSON.parse(window.__NEBULA_SNAPSHOT_DATA_TEXT__) }\n' +
|
|
575
|
+
'catch (err) { window.__NEBULA_SNAPSHOT__ = null; window.__NEBULA_SNAPSHOT_BROKEN__ = String((err && err.message) || err) }\n' +
|
|
576
|
+
'window.__NEBULA_SNAPSHOT_INTEGRITY__ = { algo: "sha256", bytes: ' +
|
|
577
|
+
dataBytes +
|
|
578
|
+
', sha256: "' +
|
|
579
|
+
dataSha +
|
|
580
|
+
'" };</script>'
|
|
581
|
+
out = put(out, '<body>', '<body>\n' + bootScript, ' <body>')
|
|
582
|
+
// 裁剪过的快照必须在画面上说清楚:用户打开文件看到 12 个点,
|
|
583
|
+
// 不能让他以为整库就这 12 条。这条提示是纯静态的,脚本没跑起来也在。
|
|
584
|
+
if (scope.trimmed) {
|
|
585
|
+
const note =
|
|
586
|
+
'这是一份裁剪过的离线快照:已写入 ' +
|
|
587
|
+
scope.trimmed.shown +
|
|
588
|
+
' / ' +
|
|
589
|
+
scope.trimmed.total +
|
|
590
|
+
' 条(按重要度与访问量取前 ' +
|
|
591
|
+
scope.trimmed.cap +
|
|
592
|
+
' 条)。完整数据请按工作区分片导出。'
|
|
593
|
+
out = put(
|
|
594
|
+
out,
|
|
595
|
+
'<body>',
|
|
596
|
+
'<body>\n<div id="snapshot-trim" role="note" style="position:fixed;left:50%;bottom:14px;transform:translateX(-50%);z-index:60;max-width:min(92vw,720px);padding:8px 14px;border-radius:999px;background:rgba(20,32,48,.92);border:1px solid rgba(120,170,220,.35);color:#cfe6f5;font:12px/1.5 system-ui;text-align:center">' +
|
|
597
|
+
note +
|
|
598
|
+
'</div>',
|
|
599
|
+
' 裁剪提示',
|
|
600
|
+
)
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// 快照的诚实性有两件事要说:裁过多少条(上面那条),以及**有没有库根本读不动**。
|
|
604
|
+
// 读不动的库在图上只是「少了」,导出给别人之后没人知道少了什么——所以这里单独立一条。
|
|
605
|
+
const readErrors = (overview.readErrors || []).filter((e) => e && e.error)
|
|
606
|
+
if (readErrors.length) {
|
|
607
|
+
const names = readErrors.map((e) => e.key || e.title || '?').join(' / ')
|
|
608
|
+
const note =
|
|
609
|
+
'这份快照里有 ' +
|
|
610
|
+
readErrors.length +
|
|
611
|
+
' 个来源读不动:' +
|
|
612
|
+
names +
|
|
613
|
+
'。它们的记忆没有进图(' +
|
|
614
|
+
String(readErrors[0].error).slice(0, 120) +
|
|
615
|
+
')。'
|
|
616
|
+
out = put(
|
|
617
|
+
out,
|
|
618
|
+
'<body>',
|
|
619
|
+
'<body>\n<div id="snapshot-readerr" role="note" style="position:fixed;left:50%;top:12px;transform:translateX(-50%);z-index:60;max-width:min(92vw,760px);padding:8px 14px;border-radius:10px;background:rgba(48,20,24,.94);border:1px solid rgba(255,150,150,.4);color:#ffd9d9;font:12px/1.5 system-ui;text-align:center">' +
|
|
620
|
+
note +
|
|
621
|
+
'</div>',
|
|
622
|
+
' 读不动提示',
|
|
623
|
+
)
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// 快照自己的界面提示(app.js 也会画一条;这里保证脚本没跑起来时也说得清)
|
|
627
|
+
out = out.replace( '<div id="boot" role="status" aria-live="polite">',
|
|
628
|
+
() => '<noscript><div style="position:fixed;inset:0;display:grid;place-items:center;background:#04060c;color:#cfe6f5;font:13px system-ui;z-index:99">这是一份离线快照,需要启用 JavaScript 才能点亮星图。</div></noscript>\n <div id="boot" role="status" aria-live="polite">',
|
|
629
|
+
)
|
|
630
|
+
|
|
631
|
+
const bytes = Buffer.byteLength(out, 'utf8')
|
|
632
|
+
return { html: out, bytes, nodes: nodes.length, edges: (graph.edges || []).length, scope }
|
|
633
|
+
}
|