@ssamurias/dsh-fish 0.9.9 → 1.0.1

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 (86) hide show
  1. package/AGENTS.md +61 -24
  2. package/CHANGELOG.md +615 -392
  3. package/README.md +123 -165
  4. package/RELEASE-NOTES-0.8.3.md +71 -71
  5. package/RELEASE-NOTES-0.9.9.md +25 -53
  6. package/RELEASE-NOTES-1.0.0.md +196 -0
  7. package/RELEASE-NOTES-1.0.1.md +363 -0
  8. package/THIRD-PARTY-NOTICES.md +13 -3
  9. package/lib/appoint.js +5 -4
  10. package/lib/ask.js +4 -3
  11. package/lib/at.js +8 -7
  12. package/lib/autobackup.js +384 -0
  13. package/lib/backup.js +27 -4
  14. package/lib/bili.js +133 -22
  15. package/lib/browse.js +51 -18
  16. package/lib/capture.js +28 -4
  17. package/lib/client.js +1231 -317
  18. package/lib/cloudbackup.js +351 -0
  19. package/lib/cloudcrypto.js +161 -0
  20. package/lib/clouddrive.js +587 -0
  21. package/lib/cloudsmtp.js +331 -0
  22. package/lib/cloudtargets.js +227 -0
  23. package/lib/comment.js +28 -10
  24. package/lib/compact.js +36 -8
  25. package/lib/contract.js +266 -0
  26. package/lib/curiosity.js +3 -2
  27. package/lib/deliver.js +6 -3
  28. package/lib/derive.js +152 -7
  29. package/lib/desk.js +1 -1
  30. package/lib/doing.js +316 -0
  31. package/lib/events.js +79 -31
  32. package/lib/firstwake.js +74 -0
  33. package/lib/generator.js +35 -4
  34. package/lib/guard.js +184 -184
  35. package/lib/health.js +36 -0
  36. package/lib/home.js +49 -2
  37. package/lib/hook.js +1 -1
  38. package/lib/identity.js +451 -36
  39. package/lib/import.js +302 -302
  40. package/lib/index.js +18 -2
  41. package/lib/intent.js +5 -3
  42. package/lib/keep.js +3 -2
  43. package/lib/keepsake.js +3 -2
  44. package/lib/letter.js +3 -3
  45. package/lib/look.js +52 -4
  46. package/lib/material.js +69 -2
  47. package/lib/note.js +193 -36
  48. package/lib/observe.js +366 -37
  49. package/lib/persona.js +240 -93
  50. package/lib/pocket.js +2 -2
  51. package/lib/proactive.js +19 -11
  52. package/lib/pronoun.js +75 -35
  53. package/lib/pronounask.js +11 -2
  54. package/lib/quality.js +1 -1
  55. package/lib/readme.js +1 -1
  56. package/lib/recall.js +207 -27
  57. package/lib/report.js +14 -7
  58. package/lib/restrict.js +27 -1
  59. package/lib/say.js +14 -13
  60. package/lib/scheduler.js +255 -35
  61. package/lib/schema.js +24 -0
  62. package/lib/selfcheck.js +13 -1
  63. package/lib/selfdoc.js +19 -8
  64. package/lib/selfpronoun.js +112 -0
  65. package/lib/sessionnote.js +44 -0
  66. package/lib/settings.js +149 -4
  67. package/lib/sources.js +99 -0
  68. package/lib/speak.js +1 -1
  69. package/lib/speechanchor.js +132 -0
  70. package/lib/stance.js +4 -3
  71. package/lib/status.js +16 -8
  72. package/lib/sub.js +424 -0
  73. package/lib/talkmem.js +3 -2
  74. package/lib/turnexport.js +123 -0
  75. package/lib/turns.js +70 -24
  76. package/lib/use.js +21 -1
  77. package/lib/voices.js +24 -1
  78. package/lib/wish.js +3 -2
  79. package/media/principle-drive.svg +131 -0
  80. package/media/principle-loop.svg +3 -3
  81. package/media/principle-memory.svg +1 -1
  82. package/package.json +3 -3
  83. package/tools/check-install.mjs +237 -0
  84. package/RELEASE.md +0 -154
  85. package/media/principle-loop-2x.png +0 -0
  86. package/media/principle-memory-2x.png +0 -0
package/lib/index.js CHANGED
@@ -21,6 +21,7 @@ import { registerSpeak, speakOn } from './speak.js'
21
21
  import { registerRecall } from './recall.js'
22
22
  import { registerHerDiary } from './herdiary.js'
23
23
  import { registerWatch } from './watch.js'
24
+ import { registerSub } from './sub.js'
24
25
  import { registerLetter } from './letter.js'
25
26
  import { registerNote } from './note.js'
26
27
  import { registerAppoint } from './appoint.js'
@@ -30,6 +31,7 @@ import { registerPronounAsk } from './pronounask.js'
30
31
  import { answerCard } from './cardanswer.js'
31
32
  import { registerDream } from './dream.js'
32
33
  import { registerProactive } from './proactive.js'
34
+ import { registerDoingHooks } from './doing.js'
33
35
  import { registerObserve } from './observe.js'
34
36
  import { startScheduler } from './scheduler.js'
35
37
  import { registerTurns } from './turns.js'
@@ -56,7 +58,7 @@ export const name = 'dsh-fish'
56
58
  * 版本号,必须和 package.json 的 version 一样(test/boot.test.mjs 盯着)。
57
59
  * 不只是日志:升级自检和设置页的「检查更新」拿它当「正在跑的版本」。
58
60
  */
59
- export const VERSION = '0.9.9'
61
+ export const VERSION = '1.0.1'
60
62
 
61
63
  // ⚠️ 一个数组写全,不要拆成对象
62
64
  // 2026-10-30(m02961):`userQuestions` **不再写进 inject**。写进 inject 的东西缺一个,
@@ -418,6 +420,9 @@ export function apply(ctx, baseConfig = {}) {
418
420
  // issue #7:日记不进事件流,所以她需要一个只读的窗口回头翻(her_diary)。
419
421
  () => registerHerDiary(ctx, { root }),
420
422
  () => registerWatch(ctx, { root, tenant: tenancy }),
423
+ // 1.0(用户 m04014):字幕按句给,不按篇给。她想知道"里面说了哪几句"
424
+ // 的时候自己去查;不自动喂,一次最多三句。
425
+ () => registerSub(ctx, { root, tenant: tenancy }),
421
426
  // R4:留话(不审批)。和 growth_commit 一样是纯追加,但收件人明确。
422
427
  () => registerLetter(ctx, { root, tenant: tenancy }),
423
428
  // issue #22 乙档(2026-11-04):醒来看的那张便条。写完会不会到期、
@@ -457,6 +462,11 @@ export function apply(ctx, baseConfig = {}) {
457
462
  const obs = registerObserve(ctx, { root, version: VERSION, tenancy, install, compat })
458
463
  if (obs?.dispose) disposers.push(() => obs.dispose())
459
464
 
465
+ // 动手回合的闸与记账(2026-11-14,用户 m01237):只在主动回合里生效,
466
+ // 他自己找她、定时叫醒都不经过;拿不到会话时一律放行。
467
+ const doingOff = registerDoingHooks(ctx, { root, log: (...a) => logger.info(...a) })
468
+ if (doingOff) disposers.push(doingOff)
469
+
460
470
  // 生物钟:把屋子信息一起传下去。她每晚醒来说话要落进**同一个**会话,
461
471
  // 不是每晚新开一个藏起来的会话(用户定案:打开侧栏就该看见她)。
462
472
  //
@@ -507,8 +517,14 @@ export function apply(ctx, baseConfig = {}) {
507
517
  try { scheduler?.dispose?.() } catch { /* ignore */ }
508
518
  try { clearWakeSection() } catch { /* ignore */ }
509
519
  for (const d of disposers) { try { d() } catch { /* ignore */ } }
520
+ // 临走前抢刷一次兜底备份(用户 m00597):谁也不知道哪次启动是最后一次,
521
+ // 关机前这一下是最后的机会。跟 released 一起 race,且自带 2 秒上限——
522
+ // 磁盘卡住时不能把卸载也挂住,依赖这个插件的服务还在等它。
523
+ const flushed = Promise.resolve()
524
+ .then(() => scheduler?.flushBackup?.())
525
+ .catch(() => {})
510
526
  // 磁盘卡住时别把卸载也挂住,依赖这个插件的服务要等它。用不 ref 的定时器,它不该拖住进程
511
- return Promise.race([released, sleep(2000, undefined, { ref: false })])
527
+ return Promise.race([Promise.all([released, flushed]), sleep(2000, undefined, { ref: false })])
512
528
  }
513
529
 
514
530
  // 宿主的 cordis 4 没有 'dispose' 事件,也不管 apply 返回的 { dispose },只认 ctx.effect。
package/lib/intent.js CHANGED
@@ -10,6 +10,8 @@
10
10
  * 最后看不着、要不要看,仍然是她自己的决定(见 persona.js 的 WATCH_RULE)。
11
11
  */
12
12
 
13
+ import { fillOwner } from './pronoun.js'
14
+
13
15
  const BV_RE = /BV[0-9A-Za-z]{10}/g
14
16
  const LINK_RE = /(b23\.tv\/[0-9A-Za-z]+|bilibili\.com\/video\/(?:BV[0-9A-Za-z]{10}|av\d+))/i
15
17
 
@@ -89,9 +91,9 @@ export function watchHint(r) {
89
91
  // 2026-10-28:短链不再需要他重新给 BV 号——bili_look what=video 认得链接
90
92
  const which = r.bvid
91
93
  ? `BV 号是 ${r.bvid}`
92
- : '他给的是一条短链(给 bili_look what=video 就能打开)'
94
+ : '{T}给的是一条短链(给 bili_look what=video 就能打开)'
93
95
  if (r.intent === 'must') {
94
- return `他这条消息里有一条视频,${which}。他那句话是在要求你看。先看,再回他。`
96
+ return fillOwner(`{T}这条消息里有一条视频,${which}。{T}那句话是在要求你看。先看,再回{T}。`)
95
97
  }
96
- return `他这条消息里有一条视频,${which},但他没有一定让你看。你可以自己定:想看就看;不想看就直接问他,为什么是这条、这是什么。`
98
+ return fillOwner(`{T}这条消息里有一条视频,${which},但{T}没有一定让你看。你可以自己定:想看就看;不想看就直接问{T},为什么是这条、这是什么。`)
97
99
  }
package/lib/keep.js CHANGED
@@ -18,6 +18,7 @@ import { callerOf } from './tenant.js'
18
18
  import { activeOf, readOutings } from './outing.js'
19
19
  import { askKeepsake, decideKeepsake } from './keepsake.js'
20
20
  import { askInChat, picked } from './askinchat.js'
21
+ import { fillOwner } from './pronoun.js'
21
22
 
22
23
  /** 点头的两个选项。文案用她那个人的语气,不用「批准/拒绝」。 */
23
24
  export const YES = '准了'
@@ -55,7 +56,7 @@ async function askBack(ctx, root, { sessionId, item, signal, rawWhy }) {
55
56
  ],
56
57
  })
57
58
  // 超时 / 没人接 / 宿主没回答人:保持 asked,出门页仍可点头。
58
- if (!r.ok) return { state: 'unanswered', note: '问了。等他点头。', said: '' }
59
+ if (!r.ok) return { state: 'unanswered', note: fillOwner('问了。等{T}点头。'), said: '' }
59
60
 
60
61
  const said = picked(r.answers, 'keepsake')
61
62
  if (said === YES) {
@@ -70,7 +71,7 @@ async function askBack(ctx, root, { sessionId, item, signal, rawWhy }) {
70
71
  if (d.handled) return handledElsewhere(d)
71
72
  return { state: 'answered', note: '没带。', said: 'no' }
72
73
  }
73
- return { state: 'unanswered', note: '问了。等他点头。', said: '' }
74
+ return { state: 'unanswered', note: fillOwner('问了。等{T}点头。'), said: '' }
74
75
  }
75
76
 
76
77
  /** 注册 bring_back 工具。 */
package/lib/keepsake.js CHANGED
@@ -30,6 +30,7 @@ import {
30
30
  import { basename, join, resolve } from 'node:path'
31
31
 
32
32
  import { dateKey } from './settings.js'
33
+ import { fillOwner } from './pronoun.js'
33
34
 
34
35
  export const KEEPSAKE_MAX_BYTES = 20 * 1024 * 1024
35
36
  export const KEEPSAKES_PER_TRIP = 3
@@ -116,7 +117,7 @@ export function askKeepsake(root, { outing = null, sessionId = '', rel = '', why
116
117
  return { ok: false, note: '这一趟带得够多了。' }
117
118
  }
118
119
  if (open.length >= 1) {
119
- return { ok: false, note: open.some((it) => it.copyFailedAt) ? '上一件他点了头,只是没复制成,还没带回来。' : '上一件还等着点头。' }
120
+ return { ok: false, note: open.some((it) => it.copyFailedAt) ? fillOwner('上一件{T}点了头,只是没复制成,还没带回来。') : '上一件还等着点头。' }
120
121
  }
121
122
 
122
123
  const cwd = String(outing.cwd ?? '')
@@ -147,7 +148,7 @@ export function askKeepsake(root, { outing = null, sessionId = '', rel = '', why
147
148
  }
148
149
  db.items.push(item)
149
150
  writeDb(root, db)
150
- return { ok: true, item, note: '问了。等他点头。' }
151
+ return { ok: true, item, note: fillOwner('问了。等{T}点头。') }
151
152
  }
152
153
 
153
154
  /**
package/lib/letter.js CHANGED
@@ -109,7 +109,7 @@ export async function leaveLetter(root, text, { log, sessionId = '' } = {}) {
109
109
  const body = String(text ?? '').trim()
110
110
  if (!body) return { ok: false, id: '', note: '空白的,没留。' }
111
111
  if (body.length > LETTER_MAX) {
112
- return { ok: false, id: '', note: `太长了,他读不完。压到 ${LETTER_MAX} 字以内再说。` }
112
+ return { ok: false, id: '', note: `太长了,{T}读不完。压到 ${LETTER_MAX} 字以内再说。` }
113
113
  }
114
114
 
115
115
  try {
@@ -160,13 +160,13 @@ export async function leaveLetter(root, text, { log, sessionId = '' } = {}) {
160
160
  defineTool({
161
161
  name: 'her_leave',
162
162
  description:
163
- '留一句话给那个人。他不在的时候也留着,他回来会看到。' +
163
+ '留一句话给那个人。{T}不在的时候也留着,{T}回来会看到。' +
164
164
  '想留就留,不想留就不用调;不用为了回应而留。',
165
165
  parameters: toJsonSchema({
166
166
  text: {
167
167
  type: 'string',
168
168
  required: true,
169
- description: `要说给他听的那一句。写你自己的话,不要写成汇报。${LETTER_MAX} 字以内。`,
169
+ description: `要说给{T}听的那一句。写你自己的话,不要写成汇报。${LETTER_MAX} 字以内。`,
170
170
  },
171
171
  }),
172
172
  output: {
package/lib/look.js CHANGED
@@ -16,6 +16,7 @@
16
16
  import { createClient } from './bili.js'
17
17
  import { readMyReplies, renderMyReplies } from './comment.js'
18
18
  import { absorb, renderMaterial, rankVideos, seenBvids, metaTitle, LOOK_BRIEF, WATCH_RULE } from './browse.js'
19
+ import { indexedMaterialKeys, materialIndexLine } from './material.js'
19
20
  import { readEvents, rootDir, appendEvent } from './store.js'
20
21
  import { loadConfig, dateKey, biliOn } from './settings.js'
21
22
  // 评论区里别人的话(2026-10-24,用户 m02454)
@@ -27,6 +28,37 @@ import { guardWrite } from './tenant.js'
27
28
 
28
29
  import { defineTool } from './tool.js'
29
30
 
31
+ /**
32
+ * 「没读出回复」时到底该说什么(2026-11-13,issue #136 B)。
33
+ *
34
+ * 原来这里只有一句写死的话:「你最近没在谁的评论下面被人回过——也可能是我这边
35
+ * 查不到(B 站这会儿回了个 -412)」。可 -412 从没发生过,她照着这句去理解,
36
+ * 得到的是一个不存在的风控;真正的原因(没发过评论 / 没人回 / 网络没通)全被
37
+ * `readMyReplies` 里那句 `continue` 吞掉了。现在按 diag 里的事实分句说。
38
+ */
39
+ export function repliesMissNote(diag = {}, { bvid = '' } = {}) {
40
+ const days = Number(diag.days) || 0
41
+ const failed = Array.isArray(diag.failed) ? diag.failed : []
42
+ const codes = failed.map((f) => Number(f?.code))
43
+ if (diag.off) return 'B 站那边是关着的(设置里关了),现在没法去看。'
44
+ const risk = codes.find((n) => RISK_CODES.has(n))
45
+ if (risk) return `B 站这会儿没让我查(回了 ${risk}),过一会儿再看。`
46
+ if (failed.some((f) => String(f?.code) === 'NOT_LOGIN')) return 'B 站登录过期了,查不了回复。'
47
+ if (failed.some((f) => String(f?.code) === 'NETWORK')) return '网络没通,这次没查成回复。'
48
+ if (!diag.roots) {
49
+ return bvid
50
+ ? `你在 ${bvid} 下面没发过评论,所以没有「谁回你」可看。`
51
+ : `最近 ${days || '几'} 天你没在 B 站发过评论,所以没有「谁回你」可看。`
52
+ }
53
+ if (failed.length) return `有几条(${failed.length} 条)没查成,剩下那些下面没人回你。`
54
+ // 分不清就不能说成「没有人回你」:她自己是这么说的——「别把「没有」和「查不成」合成一句」。
55
+ if (Number(diag.unresolved) > 0) return `有 ${diag.unresolved} 条这次没打开(没拿到视频详情),所以分不清是不是有人回你,过一会儿再看。`
56
+ return '你发过的那几条评论下面还没有人说话。'
57
+ }
58
+
59
+ /** 风控码:只有这些才算「B 站不让我查」。 */
60
+ const RISK_CODES = new Set([-412, -352, -509])
61
+
30
62
  /**
31
63
  * 调一次"看":返回素材文本。永不抛出。
32
64
  * 单独抽出来是为了能在观测台/单测里直接调(不经模型)。
@@ -66,13 +98,15 @@ export async function lookOnce(o = {}) {
66
98
  // 而且那条提醒被她看过一次就被 cseen 掉了,回头再看永远是空的。
67
99
  // 这里给她一个自己去看的动作:不滤 cseen,带上回楼中楼要用的编号。
68
100
  if (what === 'replies') {
69
- const got = await readMyReplies({ root, client, events, bvid: String(o.bvid ?? '').trim() })
70
- const txt = renderMyReplies(got, { bvid: String(o.bvid ?? '').trim() })
101
+ const want = String(o.bvid ?? '').trim()
102
+ const diag = {}
103
+ const got = await readMyReplies({ root, client, events, bvid: want, diag })
104
+ const txt = renderMyReplies(got, { bvid: want })
71
105
  if (!txt) {
72
106
  return {
73
107
  ok: false,
74
108
  text: '',
75
- note: got.length ? '' : '你最近没在谁的评论下面被人回过——也可能是我这边还查不到(B 站这会儿回了个 -412)。',
109
+ note: repliesMissNote(diag, { bvid: want }),
76
110
  picks: [],
77
111
  }
78
112
  }
@@ -159,6 +193,8 @@ export async function lookOnce(o = {}) {
159
193
  const dk = dateKey()
160
194
  const who = { day: Number(o.model?.day ?? 0), stage: Number(o.model?.stage ?? 1), source: 'system' }
161
195
  const stamp = sessionId ? { sessionId } : {}
196
+ // 已经建过素材索引的 bvid(同一视频不重复记)
197
+ const indexedSeen = indexedMaterialKeys(events)
162
198
  for (const p of packs) {
163
199
  // 0.9.7 T2:标题跟着 `looked:` 落下来。她自己点名看的这条,是「她看过什么」
164
200
  // 里最该被她自己翻到的一类;只留 BV 号的话,回忆里只有一串编号。
@@ -181,6 +217,17 @@ export async function lookOnce(o = {}) {
181
217
  view: Number(p.video.view) || 0,
182
218
  }
183
219
  await appendEvent({ type: 'meta', text: `look:${dk} ${p.video.bvid} ${JSON.stringify(info)}`, ...stamp }, { ...who }, root).catch(() => {})
220
+ // 素材索引(1.0.0,用户 m05089):她点名看过的这条,把最多三句原话落一行。
221
+ // 与 browse.js 同一口径:只记原话,不记简介全文;同一 bvid 只记一次。
222
+ try {
223
+ if (!indexedSeen.has(p.video.bvid)) {
224
+ const line = materialIndexLine(p, { date: dk })
225
+ if (line) {
226
+ await appendEvent({ type: 'meta', text: line }, { ...who }, root)
227
+ indexedSeen.add(p.video.bvid)
228
+ }
229
+ }
230
+ } catch { /* 索引失败不影响这次浏览 */ }
184
231
  }
185
232
 
186
233
  // 评论区里别人的话(2026-10-24,用户 m02454):她自己去看的时候也可能读到一句。
@@ -301,6 +348,7 @@ export function registerLook(ctx, deps = {}) {
301
348
  '去看一眼 B 站:首页在推什么、搜一个词、看某条视频之后平台又接着推什么,' +
302
349
  '或者直接看指定的那一条(给 BV 号或链接)。' +
303
350
  '也可以看你自己发过的评论下面有没有人回你(what=replies)。' +
351
+ '别人在 B 站 @ 你,不在这个工具里——那时候那条内容会直接递进你的会话。' +
304
352
  '只读,不会留下痕迹。给的是标题、简介、标签、热评、弹幕——没有视频画面。' +
305
353
  '不用它也可以。',
306
354
  // 注意:必须 toJsonSchema 包一层。简写 DSL 直接发出去会被 provider 拒:
@@ -313,7 +361,7 @@ export function registerLook(ctx, deps = {}) {
313
361
  description: 'home=首页推给你的;search=你自己搜(要带 keyword);related=接着某条往下看(要带 bvid);video=看指定的那一条(要带 bvid);replies=看你自己发过的评论下面有没有人回你(可带 bvid 只看那一条)。',
314
362
  },
315
363
  keyword: { type: 'string', required: false, description: 'what=search 时搜什么。' },
316
- bvid: { type: 'string', required: false, description: 'what=related 时从哪条接着看;what=video 时看哪一条(BV 号,或者他递过来的链接);what=replies 时只看这一条视频下面的。' },
364
+ bvid: { type: 'string', required: false, description: 'what=related 时从哪条接着看;what=video 时看哪一条(BV 号,或者{T}递过来的链接);what=replies 时只看这一条视频下面的。' },
317
365
  }),
318
366
  output: {
319
367
  schema: {
package/lib/material.js CHANGED
@@ -18,6 +18,8 @@
18
18
  * 注意:grade 只用于渲染与后续判断,**不进身份文档、不打分、不出现「几级」字样**。
19
19
  */
20
20
 
21
+ import { coerceMaterial } from './contract.js'
22
+
21
23
  /** 素材分级。冻结,防止运行期被改。 */
22
24
  export const GRADE = Object.freeze({
23
25
  FACT: 1,
@@ -44,11 +46,16 @@ export function isDissent(text) {
44
46
  * 为什么不多:一次素材里出现两三条反例就够她对照了;给太多,素材会变成
45
47
  * 评论区吵架现场,她的注意力会被拽到争论上,而不是那件事本身。
46
48
  * 按点赞降序挑,最多 max 条。
49
+ *
50
+ * 2026-11-13(issue #135):传进来的列表来自 `sort=2`,是 B 站**热度序**,
51
+ * 赞数并不单调(实测 30/55/44/348…)。这句「按点赞降序」从 0.9.8 起就写在
52
+ * 注释里,代码却是照顺序取——现在真排一次,挑出来的才是「最多人赞同的那条反例」。
47
53
  */
48
54
  export function pickDisputes(comments = [], { max = 2 } = {}) {
49
55
  const out = []
50
56
  const seen = new Set()
51
- for (const c of comments) {
57
+ const ranked = [...comments].sort((a, b) => (Number(b?.like) || 0) - (Number(a?.like) || 0))
58
+ for (const c of ranked) {
52
59
  const text = String(c?.text ?? '').trim()
53
60
  if (!text || seen.has(text)) continue
54
61
  if (!isDissent(text)) continue
@@ -92,6 +99,12 @@ export function toMaterial(pack = {}, o = {}) {
92
99
  const text = String(c?.text ?? '').trim()
93
100
  if (text) quotes.push({ by: '评论', kind: 'comment', grade: GRADE.OPINION, text, like: Number(c?.like) || 0 })
94
101
  }
102
+ // 置顶评论(2026-11-13,issue #135):B 站单独放在 data.top 里,跟着一条标出来,
103
+ // 否则她读到的评论区和网页上看到的那组不是同一组。
104
+ for (const c of pack.pinned ?? []) {
105
+ const text = String(c?.text ?? '').trim()
106
+ if (text) quotes.push({ by: '评论', kind: 'pinned', grade: GRADE.OPINION, text, like: Number(c?.like) || 0 })
107
+ }
95
108
  for (const c of pack.disputes ?? []) {
96
109
  const text = String(c?.text ?? '').trim()
97
110
  if (text) quotes.push({ by: '评论', kind: 'dissent', grade: GRADE.OPINION, text, like: Number(c?.like) || 0 })
@@ -101,7 +114,7 @@ export function toMaterial(pack = {}, o = {}) {
101
114
  if (text) quotes.push({ by: '弹幕', kind: 'danmaku', grade: GRADE.OPINION, text })
102
115
  }
103
116
 
104
- return {
117
+ const raw = {
105
118
  source: String(o.source ?? 'bili'),
106
119
  key: String(v.bvid ?? ''),
107
120
  at: pack.pubdate ?? null,
@@ -113,6 +126,12 @@ export function toMaterial(pack = {}, o = {}) {
113
126
  canVerify: facts.length > 0,
114
127
  blocked: pack.blocked ?? undefined,
115
128
  }
129
+
130
+ // 走一遍同一份校验:B 站不是特例,和外面的来源受同样的约束。
131
+ // 校验不过(极少见,通常是没 bvid)就按原样交出去——不让一条素材
132
+ // 因为校验器变严而凭空消失。
133
+ const checked = coerceMaterial(raw, { source: raw.source, kind: 'fact' })
134
+ return checked.ok ? checked.material : raw
116
135
  }
117
136
 
118
137
  /** 一条素材里、某一级的所有原话(供将来按级别挑引文用,不在渲染里直接暴露级别) */
@@ -120,3 +139,51 @@ export function quotesOf(material, grade) {
120
139
  const list = material?.quotes ?? []
121
140
  return grade === undefined ? list : list.filter((q) => q.grade === grade)
122
141
  }
142
+
143
+ // ---------------------------------------------------------------------------
144
+ // 素材索引(1.0.0,用户 m05089):她看过的那几句原话,落一行 meta。
145
+ //
146
+ // 为什么只存原话、不存简介全文:正文会让事件流变成另一个素材库,而且噪声
147
+ // 大(简介里常是导航、推广)。存「谁说的、哪一句」就够她以后说
148
+ // 「这个说法我以前在哪看到过」,也够体检核对「她引的那句是不是真存在」。
149
+ // ---------------------------------------------------------------------------
150
+
151
+ export const MAT_PREFIX = 'mat:bili:'
152
+ export const MAT_QUOTE_MAX = 120
153
+ export const MAT_QUOTES = 3
154
+
155
+ /**
156
+ * 一条素材 → 一行 `mat:bili:<bvid> {t,d,q}`。
157
+ * 没有 bvid、没有原话,就不写(不硬凑)。
158
+ */
159
+ export function materialIndexLine(pack, { date = '' } = {}) {
160
+ const m = toMaterial(pack)
161
+ if (!m) return null
162
+ const bvid = String(pack?.video?.bvid ?? '').trim()
163
+ if (!bvid) return null
164
+ const q = []
165
+ for (const quote of m.quotes ?? []) {
166
+ const text = String(quote?.text ?? '').replace(/\s+/g, ' ').trim()
167
+ if (!text) continue
168
+ const one = { b: String(quote.by ?? ''), x: text.slice(0, MAT_QUOTE_MAX) }
169
+ if (Number(quote.like) > 0) one.l = Number(quote.like)
170
+ q.push(one)
171
+ if (q.length >= MAT_QUOTES) break
172
+ }
173
+ if (!q.length) return null
174
+ const payload = { t: String(m.title ?? '').slice(0, 120), d: String(date ?? ''), q }
175
+ return `${MAT_PREFIX}${bvid} ${JSON.stringify(payload)}`
176
+ }
177
+
178
+ /** 已经建过索引的 bvid(同一视频不重复记)。 */
179
+ export function indexedMaterialKeys(events = []) {
180
+ const out = new Set()
181
+ for (const e of events ?? []) {
182
+ if (e?.type !== 'meta') continue
183
+ const text = String(e.text ?? '')
184
+ if (!text.startsWith(MAT_PREFIX)) continue
185
+ const key = text.slice(MAT_PREFIX.length).split(/\s+/, 1)[0]
186
+ if (key) out.add(key)
187
+ }
188
+ return out
189
+ }