@ssamurias/dsh-fish 1.0.7 → 1.0.9
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 +32 -3
- package/CHANGELOG.md +4366 -4265
- package/README.md +243 -627
- package/RELEASE-NOTES-1.0.8.md +81 -0
- package/RELEASE-NOTES-1.0.9.md +79 -0
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/docs/troubleshooting.md +79 -1
- package/docs//350/256/244/344/272/272/345/210/244/346/215/256.md +112 -0
- package/lib/appoint.js +106 -22
- package/lib/ask.js +8 -3
- package/lib/at.js +16 -1
- package/lib/capture.js +51 -1
- package/lib/claim.js +103 -0
- package/lib/client/00-shell.js +500 -0
- package/lib/client/01-state-load.js +860 -0
- package/lib/client/02-actions.js +670 -0
- package/lib/client/03-widgets-header.js +721 -0
- package/lib/client/04-pressure-lab.js +891 -0
- package/lib/client/05-pressure-charts.js +431 -0
- package/lib/client/06-tab-status-grow.js +468 -0
- package/lib/client/07-tab-home-bili.js +542 -0
- package/lib/client/08-tab-memory-plugins.js +733 -0
- package/lib/client/09-tab-outing.js +710 -0
- package/lib/client/10-data-handlers.js +519 -0
- package/lib/client/11-tab-data-frame.js +661 -0
- package/lib/client/12-pressure-chip-mount.js +565 -0
- package/lib/client.js +109 -24
- package/lib/comment.js +18 -3
- package/lib/cue.js +102 -5
- package/lib/deliver.js +3 -1
- package/lib/derive.js +308 -41
- package/lib/doing.js +31 -15
- package/lib/drive.js +3 -5
- package/lib/env.d.ts +224 -0
- package/lib/health.js +56 -0
- package/lib/hear.js +70 -0
- package/lib/home.js +48 -20
- package/lib/identity.js +25 -2
- package/lib/index.js +32 -18
- package/lib/look.js +2 -1
- package/lib/loops.js +39 -0
- package/lib/make.js +60 -12
- package/lib/markup.js +77 -1
- package/lib/match.js +262 -0
- package/lib/observe-bili.js +331 -0
- package/lib/observe-config.js +223 -0
- package/lib/observe-data.js +522 -0
- package/lib/observe-home.js +383 -0
- package/lib/observe-http.js +250 -0
- package/lib/observe-outing.js +650 -0
- package/lib/observe-state.js +419 -0
- package/lib/observe-trip.js +286 -0
- package/lib/observe.js +99 -3574
- package/lib/persona.js +187 -40
- package/lib/proactive.js +48 -47
- package/lib/pronounask.js +15 -1
- package/lib/restrict.js +146 -9
- package/lib/say.js +68 -4
- package/lib/scheduler.js +63 -25
- package/lib/schema.js +57 -4
- package/lib/scrub.js +16 -1
- package/lib/settings.js +128 -12
- package/lib/stance.js +131 -19
- package/lib/status.js +14 -5
- package/lib/store.js +24 -2
- package/lib/sub.js +7 -1
- package/lib/talkmem.js +12 -8
- package/lib/transcript.js +205 -0
- package/lib/turns.js +147 -19
- package/lib/types.d.ts +513 -0
- package/lib/voices.js +26 -1
- package/lib/wiki.js +47 -13
- package/lib/works.js +200 -49
- package/media/banner.jpg +0 -0
- package/package.json +1 -1
- package/scripts/build-client.mjs +83 -0
- package/scripts/sync-pressure-formulas.mjs +12 -15
package/lib/settings.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
/**
|
|
2
3
|
* settings.js —— 唯一配置入口
|
|
3
4
|
*
|
|
@@ -98,24 +99,24 @@ export const DEFAULTS = {
|
|
|
98
99
|
// 到点不一定开口;这里只剩频次与冷却(概率那套已按 issue #67 删除)。
|
|
99
100
|
proactive: {
|
|
100
101
|
enabled: false, // 默认关;功能公开可见,但不替用户打开
|
|
101
|
-
maxPerDay: 2, //
|
|
102
|
-
|
|
103
|
-
cooldownHours: 4, // 两次之间至少隔多久
|
|
102
|
+
maxPerDay: 2, // 一天最多开几次空手回合(设置页 0–12,跟着配置走)
|
|
103
|
+
quietMinutes: 360, // 距上一次有人说话不足这么多分钟就不打扰(10–1440,默认 6 小时)
|
|
104
104
|
// 下面三项给「对话要靠工具才发得出去」的部署(比如宿主里另有插件把多个聊天接进这条会话,
|
|
105
105
|
// 再给她一个发送工具)。默认值和原来的行为一样。
|
|
106
106
|
sendTools: [], // 这些工具调成功才算她开了口;空 = 只认正文
|
|
107
107
|
foldSilent: true, // 没开口的一轮折成一行;一条会话用很久、上下文很大时可以关
|
|
108
|
-
idleCountsSeen:
|
|
108
|
+
idleCountsSeen: true, // 「他来过」(seen:)也算打断安静;2026-11-22 起默认开
|
|
109
109
|
// 主动做事(2026-11-14,用户 m01237):只在主动回合里多一个「做一件」的出口。
|
|
110
110
|
// 默认关;消耗类另有日限/同件冷却/连续同类歇一周,规则真身在 lib/doing.js。
|
|
111
111
|
allowDoing: false,
|
|
112
112
|
// 兴趣门(2026-11-17,用户 m04366):同一件事反复出现、七天没因它起过、
|
|
113
113
|
// 劲儿到 0.9 才允许为它起一轮;一天最多一次。默认关,规则在 lib/interest.js。
|
|
114
114
|
interestGate: false,
|
|
115
|
+
// 消耗类上限(2026-11-23,用户 m05101):日限与滚动七天周限都可在设置里调;
|
|
116
|
+
// 0 次 = 不做,周限 0 = 不限。原来的「连着三次歇一周」由周限接替。
|
|
115
117
|
consumePerDay: 1,
|
|
118
|
+
consumePerWeek: 3,
|
|
116
119
|
itemCooldownDays: 3,
|
|
117
|
-
bingeLimit: 3,
|
|
118
|
-
bingeRestDays: 7,
|
|
119
120
|
// 外部工具的分类(2026-11-14,用户 m01618):工具名 → produce|consume|effect|self。
|
|
120
121
|
// 没标的按 effect:不拦,也不自动当消耗类摆上桌。分类真身在 lib/doing.js。
|
|
121
122
|
toolClasses: {},
|
|
@@ -191,6 +192,10 @@ export const DEFAULTS = {
|
|
|
191
192
|
// 他这句话碰到她的旧判断时,摆不摆那一行(lib/cue.js,1.0.7)。
|
|
192
193
|
// 关掉只是以后不再摆;已经发生的事情不动。
|
|
193
194
|
cue: { enabled: true },
|
|
195
|
+
// 比对器的冷却(lib/match.js,1.0.8):同一件事 × 同一份材料隔几天才允许
|
|
196
|
+
// 再摆一次。0 = 不冷却,上限 14。没有设置页入口——放上去反而会让人以为
|
|
197
|
+
// 这是「她多久想一次」的开关,那个不是它管的。
|
|
198
|
+
match: { cooldownDays: 3 },
|
|
194
199
|
|
|
195
200
|
// 看画面(2026-10-23 加)
|
|
196
201
|
// 她看一条视频的**画面**:抽 9 帧拼成一张图,她 read_image 看。
|
|
@@ -241,6 +246,32 @@ export const DEFAULTS = {
|
|
|
241
246
|
backoffUntil: '', // 内部用:风控/网络失败后退避到什么时候
|
|
242
247
|
},
|
|
243
248
|
|
|
249
|
+
// 认识主人以外的其他人(2026-11-23,认识人 S2-a)
|
|
250
|
+
//
|
|
251
|
+
// 这个开关管的是**落盘**,不只是展示:关着的时候,她在群聊/外客那儿说的话一条都不留。
|
|
252
|
+
// 默认关——大多数人只有书房,开着也是空的;有群聊桥的人才需要打开。
|
|
253
|
+
//
|
|
254
|
+
// 打开之后落的也只是**她自己的话**(且已经过 exit 脱敏),别人的话一条都不进。
|
|
255
|
+
// 这四个数管的是「一天最多写多少到硬盘」,不决定「什么算认知」——
|
|
256
|
+
// 她真想写清一个人,走的是 growth_commit 那条路,不受这里约束。
|
|
257
|
+
people: {
|
|
258
|
+
others: {
|
|
259
|
+
enabled: false, // 记录她自己说过的话(群聊 / 外客私聊)
|
|
260
|
+
perDayMax: 8, // 一天最多几条(按人散开,8 条才轮得上 8 个人)
|
|
261
|
+
charMax: 300, // 一条最多几字
|
|
262
|
+
perPersonPerDay: 1, // 同一个人当天最多几条:要的是「今天和这人说过话」,不是十句
|
|
263
|
+
// 群里别人说的那一句(认识人 S2-b,2026-11-23,用户 m03903)。
|
|
264
|
+
// 和上面那颗是两个开关,因为动的东西不一样:上面记的是**她自己的话**,
|
|
265
|
+
// 这一颗记的是**别人的话**——写进 events.jsonl 就撤不回来(只能追加),
|
|
266
|
+
// 所以必须由人自己开,默认关。关着的时候和以前一模一样,一条都不留。
|
|
267
|
+
rememberOthers: false,
|
|
268
|
+
// 下面三个是 S2-b 的量闸,不走设置页:这是硬上限,不是旋钮。
|
|
269
|
+
othersPerDayMax: 5,
|
|
270
|
+
othersCharMax: 160, // 对齐 HEAR_SNIPPET
|
|
271
|
+
othersPerPersonPerDay: 1,
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
|
|
244
275
|
// 对话与会话(2026-10-23 加)
|
|
245
276
|
// 一个侧栏会话聊到几百轮,上下文必然撑爆——不是"变慢",是每轮为几十万字付费,
|
|
246
277
|
// 最后直接失败。所以到点上换新会话,旧的改名留档(不删),原话搬几句过去。
|
|
@@ -273,6 +304,24 @@ export const DEFAULTS = {
|
|
|
273
304
|
anchor: false,
|
|
274
305
|
},
|
|
275
306
|
|
|
307
|
+
// 她留下的东西(2026-11-23,用户 m01320)。
|
|
308
|
+
//
|
|
309
|
+
// 条数上限(一天起一件、七天三件)是作品库的形状,不是设置项;
|
|
310
|
+
// 这里只放「一天最多几版」——原来写死 2,有人想让她一天多改几版,
|
|
311
|
+
// 她自己也会因为改不动而停在第二版(issue #176 里那条真机观察)。
|
|
312
|
+
works: {
|
|
313
|
+
// 一天最多几版,含当天留的第一版:2 = 留一件 + 改一版。
|
|
314
|
+
// 改版次数按本地日期数,跨天重置;范围 1–20(0 不采用:那等于当天不许留东西)。
|
|
315
|
+
versionsPerDay: 2,
|
|
316
|
+
// 每一版都留着,还是只留最后一版(2026-11-23,issue #176 / 用户 m01616)。
|
|
317
|
+
// 默认 true:现有用户的行为一点不变,旧版不覆盖。
|
|
318
|
+
// 改成 false 之后,改版会把上一版换掉(文件也删掉),台账只留当前一版;
|
|
319
|
+
// 「改过几次、哪几天改过」另记 rev / revDays,用来算一天最多几版。
|
|
320
|
+
// 为什么不做成默认只留最后一版:有人想留着东西长过来的样子,
|
|
321
|
+
// 一旦内置成默认,这部分人就没有开关可以关掉(晴猫在 issue #176 的意见)。
|
|
322
|
+
keepVersions: true,
|
|
323
|
+
},
|
|
324
|
+
|
|
276
325
|
// 房间(2026-11-05,用户 m00304)
|
|
277
326
|
// 群房按「建了多久」轮换,不按轮数:群和群的热度差几十倍,同一阈值要么小群
|
|
278
327
|
// 永远换不了,要么热闹的群一天换三间。7 天是用户定的默认值;0 = 不轮换。
|
|
@@ -427,6 +476,14 @@ const LIMITS = {
|
|
|
427
476
|
'comment.scanEveryMin': [5, 720],
|
|
428
477
|
'at.scanEveryMin': [1, 60],
|
|
429
478
|
'at.perDayMax': [0, 100],
|
|
479
|
+
// 认识其他人(2026-11-23):上限不是为了省空间,是为了别让一天几千字的群聊
|
|
480
|
+
// 把「她对这个人的印象」冲成流水账;下限 1 条,写 0 等于关,关这件事走 enabled。
|
|
481
|
+
'people.others.perDayMax': [1, 50],
|
|
482
|
+
'people.others.charMax': [50, 2000],
|
|
483
|
+
'people.others.perPersonPerDay': [1, 10],
|
|
484
|
+
// 留东西(2026-11-23,用户 m01320):原来写死 2,改成可调。
|
|
485
|
+
// 下限 1:0 等于当天一件都不许留,那件事该走别的开关,不该藏在这里。
|
|
486
|
+
'works.versionsPerDay': [1, 20],
|
|
430
487
|
'chat.rotateAfter': [0, 500],
|
|
431
488
|
'chat.carry': [0, CARRY_MAX],
|
|
432
489
|
'chat.replyChars': [0, 2000],
|
|
@@ -440,10 +497,15 @@ const LIMITS = {
|
|
|
440
497
|
'memory.hearEvery': [0, 50],
|
|
441
498
|
'rules.holdDays': [1, 30],
|
|
442
499
|
'rules.cooldownDays': [1, 30],
|
|
443
|
-
// issue #69 / PR #76:卡面一直是 1–24,后端却放到 0–240,写进 0
|
|
500
|
+
// issue #69 / PR #76:卡面一直是 1–24,后端却放到 0–240,写进 0 等于关掉「安静多久」。
|
|
501
|
+
// 2026-11-22(用户 m00851):新键按分钟,10 分钟–24 小时;老键保留给旧客户端。
|
|
502
|
+
'proactive.quietMinutes': [10, 24 * 60],
|
|
444
503
|
'proactive.minIdleHours': [1, 24],
|
|
445
504
|
// 2026-11-15:这一项原来不在 LIMITS 里(只有 proactive.js 自己夹 0–12),两边写法不一致,补进来对齐。
|
|
446
505
|
'proactive.maxPerDay': [0, 12],
|
|
506
|
+
// 消耗类上限(2026-11-23,用户 m05101):日限抬到 20、周限到 100;0 在日限是「不做」,在周限是「不限」。
|
|
507
|
+
'proactive.consumePerDay': [0, 20],
|
|
508
|
+
'proactive.consumePerWeek': [0, 100],
|
|
447
509
|
// 自动备份(2026-11-14):1 是最勤的档(一天一份);0 不用留,关这件事走 enabled。
|
|
448
510
|
'backup.everyDays': [1, 30],
|
|
449
511
|
'backup.keep': [1, 60],
|
|
@@ -471,7 +533,13 @@ function setPath(obj, dotted, val) {
|
|
|
471
533
|
cur[last] = val
|
|
472
534
|
}
|
|
473
535
|
|
|
474
|
-
|
|
536
|
+
/**
|
|
537
|
+
* @param {unknown} v
|
|
538
|
+
* @param {readonly number[]} range
|
|
539
|
+
* @param {number} dflt
|
|
540
|
+
*/
|
|
541
|
+
function clampNum(v, range, dflt) {
|
|
542
|
+
const [lo, hi] = range
|
|
475
543
|
const n = Number(v)
|
|
476
544
|
if (!Number.isFinite(n)) return dflt
|
|
477
545
|
return Math.max(lo, Math.min(hi, n))
|
|
@@ -507,12 +575,17 @@ function fillDefaults(defaults, actual) {
|
|
|
507
575
|
* 又需要知道某个开关,就读这里。没读过盘时是 null——调用方自己决定缺省值,
|
|
508
576
|
* 别在这猜。
|
|
509
577
|
*/
|
|
578
|
+
/** @type {import('./types.js').FishConfig | null} */
|
|
510
579
|
let lastConfig = null
|
|
511
580
|
export function configCache() {
|
|
512
581
|
return lastConfig
|
|
513
582
|
}
|
|
514
583
|
|
|
515
|
-
/**
|
|
584
|
+
/**
|
|
585
|
+
* 规范化 + 夹值。永远返回一个可用的完整配置。
|
|
586
|
+
* @param {Record<string, any> | null} [raw]
|
|
587
|
+
* @returns {import('./types.js').FishConfig}
|
|
588
|
+
*/
|
|
516
589
|
export function normalizeConfig(raw = {}) {
|
|
517
590
|
const cfg = fillDefaults(DEFAULTS, raw || {})
|
|
518
591
|
|
|
@@ -535,6 +608,11 @@ export function normalizeConfig(raw = {}) {
|
|
|
535
608
|
cfg.diary.visible = Boolean(cfg.diary.visible)
|
|
536
609
|
cfg.diary.enabled = Boolean(cfg.diary.enabled)
|
|
537
610
|
|
|
611
|
+
// 她留下的东西(2026-11-23,issue #176):只把明确的 false 留下,其它值一律当 true。
|
|
612
|
+
// 老配置里没有这一项 = 保留每一版,和以前一样;读不出来的坏值也不该悄悄改成只留一版。
|
|
613
|
+
cfg.works = { ...DEFAULTS.works, ...(cfg.works && typeof cfg.works === 'object' && !Array.isArray(cfg.works) ? cfg.works : {}) }
|
|
614
|
+
cfg.works.keepVersions = cfg.works.keepVersions !== false
|
|
615
|
+
|
|
538
616
|
// 黑名单:去重、去空、保序(用户以后往数组里 push 就行,加一条不用改代码)
|
|
539
617
|
cfg.avoid = { ...DEFAULTS.avoid, ...cfg.avoid }
|
|
540
618
|
cfg.avoid.keywords = dedupe(cfg.avoid.keywords)
|
|
@@ -590,12 +668,36 @@ export function normalizeConfig(raw = {}) {
|
|
|
590
668
|
cfg.at.lastScanAt = String(cfg.at.lastScanAt ?? '')
|
|
591
669
|
cfg.at.backoffUntil = String(cfg.at.backoffUntil ?? '')
|
|
592
670
|
|
|
671
|
+
// 认识其他人(2026-11-23,认识人 S2-a):两层的对象都要展开,
|
|
672
|
+
// 老配置里根本没有这一组,坏值一律退回 DEFAULTS(别让 "yes" 这种字符串当开关用)。
|
|
673
|
+
cfg.people = { ...DEFAULTS.people, ...(cfg.people && typeof cfg.people === 'object' && !Array.isArray(cfg.people) ? cfg.people : {}) }
|
|
674
|
+
cfg.people.others = {
|
|
675
|
+
...DEFAULTS.people.others,
|
|
676
|
+
...(cfg.people.others && typeof cfg.people.others === 'object' && !Array.isArray(cfg.people.others) ? cfg.people.others : {}),
|
|
677
|
+
}
|
|
678
|
+
cfg.people.others.enabled = Boolean(cfg.people.others.enabled)
|
|
679
|
+
// S2-b(2026-11-23,用户 m03903):同一个严格化,坏值不当开关用。
|
|
680
|
+
cfg.people.others.rememberOthers = Boolean(cfg.people.others.rememberOthers)
|
|
681
|
+
// 量闸是硬上限,不开放成旋钮:写错类型或超出范围就退回默认,不让它变成「调大就能多存别人」。
|
|
682
|
+
const clampOther = (v, lo, hi, bad) => {
|
|
683
|
+
const n = Math.trunc(Number(v))
|
|
684
|
+
return Number.isFinite(n) ? Math.min(hi, Math.max(lo, n)) : bad
|
|
685
|
+
}
|
|
686
|
+
cfg.people.others.othersPerDayMax = clampOther(cfg.people.others.othersPerDayMax, 1, 20, DEFAULTS.people.others.othersPerDayMax)
|
|
687
|
+
cfg.people.others.othersCharMax = clampOther(cfg.people.others.othersCharMax, 40, 400, DEFAULTS.people.others.othersCharMax)
|
|
688
|
+
cfg.people.others.othersPerPersonPerDay = clampOther(cfg.people.others.othersPerPersonPerDay, 1, 3, DEFAULTS.people.others.othersPerPersonPerDay)
|
|
689
|
+
|
|
593
690
|
// 出门:只存一个布尔(老配置里没有这一组)
|
|
594
691
|
cfg.outing = { ...DEFAULTS.outing, ...cfg.outing }
|
|
595
692
|
cfg.outing.ack = Boolean(cfg.outing.ack)
|
|
596
693
|
|
|
597
694
|
// 主动说话(0.8.1 本机实验):布尔严格化 + 数值夹紧(夹紧规则真身在 proactive.js)
|
|
598
695
|
cfg.proactive = { ...DEFAULTS.proactive, ...cfg.proactive }
|
|
696
|
+
// 2026-11-22(用户 m00851):老配置只有 minIdleHours(小时),这里一次性换算成分钟。
|
|
697
|
+
// 新键存在时以新键为准;换算后仍按 10–1440 夹一次。
|
|
698
|
+
if (raw?.proactive?.quietMinutes === undefined && raw?.proactive?.minIdleHours !== undefined) {
|
|
699
|
+
cfg.proactive.quietMinutes = Math.round(clampNum(Number(raw.proactive.minIdleHours) * 60, [10, 24 * 60], 360))
|
|
700
|
+
}
|
|
599
701
|
cfg.memory.selfWake = cfg.memory.selfWake !== false
|
|
600
702
|
// 0.9.7 T1:回声开关。只认 true/false,缺省按开。写成字符串"false"也当开——
|
|
601
703
|
// 这里不是解析用户意图的地方,界面只发布尔。
|
|
@@ -604,6 +706,15 @@ export function normalizeConfig(raw = {}) {
|
|
|
604
706
|
cfg.interest = { enabled: cfg.interest?.enabled !== false }
|
|
605
707
|
cfg.dream = { enabled: cfg.dream?.enabled !== false }
|
|
606
708
|
cfg.cue = { enabled: cfg.cue?.enabled !== false }
|
|
709
|
+
// 比对器冷却:整数天,0–14;没写就是 3。只有 config.json 认这个键。
|
|
710
|
+
cfg.match = {
|
|
711
|
+
cooldownDays: cfg.match?.cooldownDays === '' || cfg.match?.cooldownDays === null || cfg.match?.cooldownDays === undefined
|
|
712
|
+
? 3
|
|
713
|
+
: Math.round(clampNum(cfg.match.cooldownDays, [0, 14], 3)),
|
|
714
|
+
dayMax: cfg.match?.dayMax === '' || cfg.match?.dayMax === null || cfg.match?.dayMax === undefined
|
|
715
|
+
? 2
|
|
716
|
+
: Math.round(clampNum(cfg.match.dayMax, [1, 5], 2)),
|
|
717
|
+
}
|
|
607
718
|
cfg.proactive.enabled = Boolean(cfg.proactive.enabled)
|
|
608
719
|
|
|
609
720
|
// 她的工具面:preset 名 trim(空 = 用宿主默认组合),allow 去重去空
|
|
@@ -838,10 +949,15 @@ export function biliOn(cfg) {
|
|
|
838
949
|
return cfg?.bili?.enabled !== false
|
|
839
950
|
}
|
|
840
951
|
|
|
841
|
-
/**
|
|
952
|
+
/**
|
|
953
|
+
* 当前是否落在今天的活跃时间窗内
|
|
954
|
+
* @param {{ window?: string[] | null } | null | undefined} cfg
|
|
955
|
+
* @param {Date} [now]
|
|
956
|
+
*/
|
|
842
957
|
export function inWindow(cfg, now = new Date()) {
|
|
843
|
-
const
|
|
844
|
-
const [
|
|
958
|
+
const w = Array.isArray(cfg?.window) && cfg.window.length >= 2 ? cfg.window : DEFAULTS.window
|
|
959
|
+
const [sh, sm] = String(w[0]).split(':').map(Number)
|
|
960
|
+
const [eh, em] = String(w[1]).split(':').map(Number)
|
|
845
961
|
const cur = now.getHours() * 60 + now.getMinutes()
|
|
846
962
|
const start = sh * 60 + sm
|
|
847
963
|
const end = eh * 60 + em
|
package/lib/stance.js
CHANGED
|
@@ -37,6 +37,8 @@ export const STANCE_MAX = 12
|
|
|
37
37
|
* 提到 8 条;真正的天花板是身份文档的字数预算(`memory.docBudget`),
|
|
38
38
|
* 摆不下时会由 assemble() 按预算收,不会把别的段落挤到没人管。 */
|
|
39
39
|
export const STANCE_PROMPT_MAX = 8
|
|
40
|
+
/** 判不出先后的两条,摆满这么多天还没定,就降成一行「一直没定」(2026-11-22,用户定 14 天)。 */
|
|
41
|
+
export const CONFLICT_QUIET_DAYS = 14
|
|
40
42
|
/** 归组的相似度阈值(与「反复提起」同一套字面判据,宁可少归)。 */
|
|
41
43
|
export const STANCE_SIM = 0.45
|
|
42
44
|
|
|
@@ -124,7 +126,10 @@ function costOf(group, scars) {
|
|
|
124
126
|
mentions += Number(b.mentions ?? 0)
|
|
125
127
|
verified += Number(b.verified ?? 0)
|
|
126
128
|
}
|
|
127
|
-
|
|
129
|
+
// 2026-11-23(外部报告:revise 让立场静默消失,修 A):疤原先只跟 group[0] 比。
|
|
130
|
+
// 她把这句改短、group[0] 换成新说法之后,同一道疤就认不出来了——可疤是
|
|
131
|
+
// 「这件事上我栽过一次」,不是「这一句话被顶回来过」。跟组里任何一句对得上都算。
|
|
132
|
+
const hit = scars.filter((s) => group.some((b) => similarity(s.quote ?? '', b.text ?? '') >= STANCE_SIM))
|
|
128
133
|
return { mentions, verified, scars: hit.length }
|
|
129
134
|
}
|
|
130
135
|
|
|
@@ -268,6 +273,29 @@ export function buildStances(model = {}, { limit = STANCE_MAX } = {}) {
|
|
|
268
273
|
// 只有还站着的判断能进立场:被推翻/被修正过的那条已经不算数了,
|
|
269
274
|
// 拿它当立场,等于把已经作废的话又念一遍。
|
|
270
275
|
const live = beliefs.filter((x) => !x.status || x.status === 'active')
|
|
276
|
+
// 2026-11-23(外部报告:revise 让立场静默消失,修 B):refined 的旧句不再只是
|
|
277
|
+
// 「作废」——它在改写后那句的 refs 里留了链,作为**影子成员**回来。影子不占组员
|
|
278
|
+
// 名额(一条判断换了个说法仍然是一条判断),但它的 mentions / verified / 疤继续算数。
|
|
279
|
+
// refuted 不回来:那是真的不认了。
|
|
280
|
+
const byId = new Map()
|
|
281
|
+
for (const b of beliefs) byId.set(String(b.id), b)
|
|
282
|
+
const shadowsOf = (b, kind) => {
|
|
283
|
+
const out = []
|
|
284
|
+
const seen = new Set()
|
|
285
|
+
const walk = (x) => {
|
|
286
|
+
for (const r of Array.isArray(x?.refs) ? x.refs : []) {
|
|
287
|
+
const o = byId.get(String(r))
|
|
288
|
+
if (!o || seen.has(String(o.id)) || o.status !== 'refined') continue
|
|
289
|
+
// 改口改到另一边(不喜欢 → 喜欢)不算同一句话的新说法,别继承背书。
|
|
290
|
+
if (classifyStance(o.text) !== kind) continue
|
|
291
|
+
seen.add(String(o.id))
|
|
292
|
+
out.push(o)
|
|
293
|
+
walk(o)
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
walk(b)
|
|
297
|
+
return out
|
|
298
|
+
}
|
|
271
299
|
for (const b of live) {
|
|
272
300
|
if (used.has(b.id)) continue
|
|
273
301
|
const kind = classifyStance(b.text)
|
|
@@ -283,15 +311,37 @@ export function buildStances(model = {}, { limit = STANCE_MAX } = {}) {
|
|
|
283
311
|
used.add(o.id)
|
|
284
312
|
}
|
|
285
313
|
}
|
|
286
|
-
const
|
|
314
|
+
const shadows = []
|
|
315
|
+
const seenShadow = new Set()
|
|
316
|
+
for (const m of group) {
|
|
317
|
+
for (const s of shadowsOf(m, kind)) {
|
|
318
|
+
if (seenShadow.has(String(s.id))) continue
|
|
319
|
+
seenShadow.add(String(s.id))
|
|
320
|
+
shadows.push(s)
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
const cost = costOf([...group, ...shadows], scars)
|
|
287
324
|
const backed = cost.scars > 0 || cost.mentions >= STANCE_MIN_MENTIONS || cost.verified >= STANCE_MIN_VERIFIED
|
|
325
|
+
// 影子不算「同一件事上的第二条判断」——它只是这句话的前一个说法。
|
|
288
326
|
if (group.length < STANCE_MIN_GROUP && !backed) continue
|
|
327
|
+
// 代表句取组里**时间最新**的一条(她最近一次怎么说,就用那句)。
|
|
328
|
+
// 不能取 group 的最后一条:group 是按 derive 的显著性顺序塞进来的(solid 先、
|
|
329
|
+
// 同分新的先),最后一条往往是最旧、最不显著的那条,`since` 也会跟着退回旧日期。
|
|
330
|
+
// 2026-11-22 修:真机上两条同向判断,代表句和「什么时候站住的」都取到了最旧那条。
|
|
331
|
+
const latest = group.reduce((best, x) => {
|
|
332
|
+
const tx = sinceOf(x)
|
|
333
|
+
const tb = sinceOf(best)
|
|
334
|
+
if (tx === null) return best
|
|
335
|
+
if (tb === null || tx > tb) return x
|
|
336
|
+
return best
|
|
337
|
+
}, group[0])
|
|
289
338
|
groups.push({
|
|
290
339
|
kind,
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
340
|
+
text: String(latest.text ?? '').trim(),
|
|
341
|
+
// members 把影子也列进来:her_stance 的明细是给她核对「这条是怎么长出来的」,
|
|
342
|
+
// 旧说法也是来历的一部分。
|
|
343
|
+
members: [...group, ...shadows].map((x) => x.id),
|
|
344
|
+
since: latest.since ?? null,
|
|
295
345
|
...cost,
|
|
296
346
|
backed,
|
|
297
347
|
})
|
|
@@ -382,7 +432,12 @@ function resolveConflicts(groups) {
|
|
|
382
432
|
const a = sinceOf(other)
|
|
383
433
|
const b = sinceOf(g)
|
|
384
434
|
if (a === null || b === null || a === b) {
|
|
385
|
-
|
|
435
|
+
// 判不出先后:不替她选,也不把两条一起删(2026-11-22,用户 m00360)。
|
|
436
|
+
// 两条都留,互相记一个成员 id;渲染时合成一个单独的冲突块。
|
|
437
|
+
// 两边都不挂 changedFrom——她没改过口,只是还没定。
|
|
438
|
+
if (!other.conflictWith) other.conflictWith = String(g.members?.[0] ?? '')
|
|
439
|
+
if (!g.conflictWith) g.conflictWith = String(other.members?.[0] ?? '')
|
|
440
|
+
out.push(g)
|
|
386
441
|
continue
|
|
387
442
|
}
|
|
388
443
|
if (b > a) {
|
|
@@ -393,6 +448,16 @@ function resolveConflicts(groups) {
|
|
|
393
448
|
other.changedFrom = g.text
|
|
394
449
|
}
|
|
395
450
|
}
|
|
451
|
+
// 一方被「后来的算数」挤掉时,另一方可能还留着指向它的 conflictWith。
|
|
452
|
+
// 只保留互相指认的那一对;指空或单向的都清掉,免得渲染时误压「改过口」。
|
|
453
|
+
const byMember = new Map()
|
|
454
|
+
for (const s of out) for (const id of s.members ?? []) byMember.set(String(id), s)
|
|
455
|
+
for (const s of out) {
|
|
456
|
+
if (!s.conflictWith) continue
|
|
457
|
+
const other = byMember.get(String(s.conflictWith))
|
|
458
|
+
const back = other ? String(other.conflictWith ?? '') : ''
|
|
459
|
+
if (!other || !(s.members ?? []).some((id) => String(id) === back)) delete s.conflictWith
|
|
460
|
+
}
|
|
396
461
|
return out
|
|
397
462
|
}
|
|
398
463
|
|
|
@@ -430,7 +495,7 @@ export function stanceLine(s) {
|
|
|
430
495
|
: s.mentions >= STANCE_MIN_MENTIONS
|
|
431
496
|
? '(这句话我说过不止一次)'
|
|
432
497
|
: ''
|
|
433
|
-
const flip = s.changedFrom ? '(这件事我改过口,以前不是这么说的)' : ''
|
|
498
|
+
const flip = s.changedFrom && !s.conflictWith ? '(这件事我改过口,以前不是这么说的)' : ''
|
|
434
499
|
return `- ${s.text}${cost}${flip}`
|
|
435
500
|
}
|
|
436
501
|
|
|
@@ -440,20 +505,65 @@ export function stanceLine(s) {
|
|
|
440
505
|
* 排在后面没摆出来的拒绝不能算「已经升格」,不然两头都没有,这件事就从文档里消失了。
|
|
441
506
|
*/
|
|
442
507
|
export function shownStances(stances = []) {
|
|
443
|
-
|
|
508
|
+
const pair = conflictPair(stances)
|
|
509
|
+
const inPair = new Set(pair ?? [])
|
|
510
|
+
const normal = stances.filter((s) => !inPair.has(s)).slice(0, STANCE_PROMPT_MAX)
|
|
511
|
+
return pair ? [...normal, ...pair] : normal
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/** 找到清单里唯一要单独摆出来的那组「判不出先后」的冲突。 */
|
|
515
|
+
function conflictPair(stances = []) {
|
|
516
|
+
for (const s of stances) {
|
|
517
|
+
if (!s.conflictWith) continue
|
|
518
|
+
const other = stances.find((o) => o !== s && (
|
|
519
|
+
String(o.conflictWith ?? '') === String(s.members?.[0] ?? '')
|
|
520
|
+
|| String(s.conflictWith) === String(o.members?.[0] ?? '')
|
|
521
|
+
))
|
|
522
|
+
if (other) return [s, other]
|
|
523
|
+
}
|
|
524
|
+
return null
|
|
444
525
|
}
|
|
445
526
|
|
|
446
527
|
/** 身份文档里的那一段(空清单返回空串,不占预算)。 */
|
|
447
|
-
export function stanceSection(stances = []) {
|
|
448
|
-
const
|
|
449
|
-
|
|
528
|
+
export function stanceSection(stances = [], { now = Date.now() } = {}) {
|
|
529
|
+
const pair = conflictPair(stances)
|
|
530
|
+
const inPair = new Set(pair ?? [])
|
|
531
|
+
const list = stances.filter((s) => !inPair.has(s)).slice(0, STANCE_PROMPT_MAX)
|
|
532
|
+
const body = []
|
|
533
|
+
|
|
450
534
|
const refused = list.filter((s) => s.kind === 'refused')
|
|
451
535
|
const nevers = list.filter((s) => s.kind === 'never')
|
|
452
536
|
const likes = list.filter((s) => s.kind === 'like')
|
|
453
|
-
|
|
454
|
-
if (
|
|
455
|
-
if (
|
|
456
|
-
|
|
537
|
+
if (refused.length) body.push(...refused.map(stanceLine))
|
|
538
|
+
if (nevers.length) body.push(...nevers.map(stanceLine))
|
|
539
|
+
if (likes.length) body.push(...likes.map(stanceLine))
|
|
540
|
+
|
|
541
|
+
if (pair) {
|
|
542
|
+
// 冲突块不占那 8 条的名额:它回答的是「哪件事我还没定」,不是「我站住过什么」。
|
|
543
|
+
// 14 天还没定就降成一行——不逼她,也不让一件悬着的事永远占着两行。
|
|
544
|
+
const [a, b] = pair
|
|
545
|
+
const ts = Math.max(...pair.map((s) => sinceOf(s) ?? -Infinity))
|
|
546
|
+
const quiet = Number.isFinite(ts) && now - ts > CONFLICT_QUIET_DAYS * 86400000
|
|
547
|
+
if (quiet) {
|
|
548
|
+
body.push(`- 有件事你一直没定:「${bare(a.text)}」/「${bare(b.text)}」`)
|
|
549
|
+
body.push('原文还在,用 her_stance 翻得到。')
|
|
550
|
+
} else {
|
|
551
|
+
body.push('这两句对不上:')
|
|
552
|
+
body.push(`- 「${bare(a.text)}」`)
|
|
553
|
+
body.push(`- 「${bare(b.text)}」`)
|
|
554
|
+
body.push('这两句不能同时算数,你还没定。想收掉一边:growth_commit,type=revise,verdict=refuted,refs 填 her_stance 里那一条下面所有的编号。')
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
if (!body.length) return ''
|
|
559
|
+
const lines = [
|
|
560
|
+
'## 我站哪边',
|
|
561
|
+
'这些不是设定,是这些事上我确实站住过。同类的事再来,我按这个来,不重新演一遍。',
|
|
562
|
+
...body,
|
|
563
|
+
]
|
|
564
|
+
const shown = list.length + (pair ? pair.length : 0)
|
|
565
|
+
const rest = stances.length - shown
|
|
566
|
+
if (rest > 0) lines.push(`还有 ${rest} 条没摆出来,用 her_stance 翻得到。`)
|
|
457
567
|
return lines.join('\n')
|
|
458
568
|
}
|
|
459
569
|
|
|
@@ -493,8 +603,10 @@ export function stanceDetail(model = {}, { limit = Number.MAX_SAFE_INTEGER } = {
|
|
|
493
603
|
const byId = new Map(
|
|
494
604
|
[...beliefs, ...refusals].filter((x) => x?.id).map((x) => [String(x.id), x]),
|
|
495
605
|
)
|
|
496
|
-
|
|
497
|
-
|
|
606
|
+
const shownIds = new Set(shownStances(stances).map((s) => String(s.members?.[0] ?? '')))
|
|
607
|
+
return stances.map((s) => ({
|
|
608
|
+
shown: shownIds.has(String(s.members?.[0] ?? '')),
|
|
609
|
+
conflict: Boolean(s.conflictWith),
|
|
498
610
|
kind: s.kind,
|
|
499
611
|
text: s.text,
|
|
500
612
|
line: stanceLine(s).replace(/^-\s+/, ''),
|
|
@@ -550,7 +662,7 @@ export function renderDetail(rows, near = []) {
|
|
|
550
662
|
}
|
|
551
663
|
const written = rows.filter((r) => r.shown).length
|
|
552
664
|
const lines = [
|
|
553
|
-
`你把这件事翻了一遍,一共 ${rows.length}
|
|
665
|
+
`你把这件事翻了一遍,一共 ${rows.length} 条。写进身份文档的有 ${written} 条,下面标了哪些没写进去。`,
|
|
554
666
|
]
|
|
555
667
|
for (const r of rows) {
|
|
556
668
|
lines.push('')
|
package/lib/status.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
/**
|
|
2
3
|
* status.js —— 「现在在干什么」的旁观者视角。
|
|
3
4
|
*
|
|
@@ -41,7 +42,12 @@ function dayMarker(text, prefix, dk) {
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
/**
|
|
44
|
-
* @
|
|
45
|
+
* @typedef {{ at: number, kind: string, text: string, n?: number }} StatusAction
|
|
46
|
+
* @typedef {{ at: number, wake: string | null, actions: StatusAction[], idle?: boolean }} StatusBlock
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @param {{events?:Array<any>, config?:Record<string, any>, now?:Date}} [input]
|
|
45
51
|
* @returns {{phase:string, label:string, detail:string, since:string, minutesAgo:number|null,
|
|
46
52
|
* plannedWakeAt:string|null, nextWakeAt:string|null, awake:boolean,
|
|
47
53
|
* today:{wakes:number,idleWakes:number,browsed:number,said:number,chat:number,comments:number,dairies:number},
|
|
@@ -78,12 +84,15 @@ export function deriveStatus({ events = [], config = {}, now = new Date() } = {}
|
|
|
78
84
|
const quietToday = today.some(({ e }) => e?.type === 'meta' && String(textOf(e) ?? '').startsWith(`quiet:${dk}`))
|
|
79
85
|
|
|
80
86
|
// ---- 把今天切成"醒来块":每个 wake: 是起点,动作挂到它下面 ----
|
|
87
|
+
/** @type {StatusBlock[]} */
|
|
81
88
|
const blocks = []
|
|
82
89
|
// chat(issue #32):对话里她说的那些行。它们**不是**她在这一轮里主动做的事——
|
|
83
90
|
// 一次叫醒正好撞上他连说几十句,时间线 40 条会被这些行占满,`idleWakes` 也会被
|
|
84
91
|
// 一句「嗯」清零。所以单列一个计数,不进 said、不算 done、时间线上折叠成一行。
|
|
85
92
|
const counts = { wakes: 0, idleWakes: 0, browsed: 0, said: 0, chat: 0, comments: 0, dairies: 0 }
|
|
93
|
+
/** @type {StatusBlock | null} */
|
|
86
94
|
let cur = null
|
|
95
|
+
/** @type {StatusBlock} */
|
|
87
96
|
const orphan = { at: today[0]?.t ?? nowMs, actions: [], wake: null }
|
|
88
97
|
|
|
89
98
|
const push = (at, kind, text, extra = {}) => {
|
|
@@ -155,7 +164,7 @@ export function deriveStatus({ events = [], config = {}, now = new Date() } = {}
|
|
|
155
164
|
const prev = last.actions[last.actions.length - 1]
|
|
156
165
|
// 连续多句合进同一条,别让一次长对话把时间线刷成弹幕。
|
|
157
166
|
if (prev && prev.kind === 'chat') {
|
|
158
|
-
prev.n
|
|
167
|
+
prev.n = (prev.n ?? 1) + 1
|
|
159
168
|
prev.at = t
|
|
160
169
|
prev.text = `聊了 ${prev.n} 句`
|
|
161
170
|
} else {
|
|
@@ -204,10 +213,10 @@ export function deriveStatus({ events = [], config = {}, now = new Date() } = {}
|
|
|
204
213
|
const recent = Number.isFinite(lastActMs) && nowMs - lastActMs <= ACTIVE_MS
|
|
205
214
|
const lastKind = activeBlock?.actions?.length ? activeBlock.actions[activeBlock.actions.length - 1].kind : null
|
|
206
215
|
|
|
207
|
-
if (recent && lastKind === 'browse') {
|
|
216
|
+
if (recent && activeBlock && lastKind === 'browse') {
|
|
208
217
|
phase = 'browsing'; label = '在看别人的视频'
|
|
209
218
|
detail = activeBlock.actions[activeBlock.actions.length - 1].text
|
|
210
|
-
} else if (recent && lastKind === 'say') {
|
|
219
|
+
} else if (recent && activeBlock && lastKind === 'say') {
|
|
211
220
|
phase = 'talking'; label = '在想怎么回你'
|
|
212
221
|
detail = activeBlock.actions[activeBlock.actions.length - 1].text
|
|
213
222
|
} else if (recent && lastKind === 'chat') {
|
|
@@ -253,7 +262,7 @@ export function deriveStatus({ events = [], config = {}, now = new Date() } = {}
|
|
|
253
262
|
}
|
|
254
263
|
|
|
255
264
|
// since:当前状态是从什么时候开始的
|
|
256
|
-
if (phase === 'browsing' || phase === 'talking' || phase === 'writing') {
|
|
265
|
+
if ((phase === 'browsing' || phase === 'talking' || phase === 'writing') && activeBlock) {
|
|
257
266
|
const a = activeBlock.actions[activeBlock.actions.length - 1]
|
|
258
267
|
since = new Date(a.at).toISOString()
|
|
259
268
|
} else if (phase === 'awake-idle' && activeBlock) {
|
package/lib/store.js
CHANGED
|
@@ -65,8 +65,25 @@ export function paths(root = rootDir()) {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
// 2026-11-21(用户 m00612):events.jsonl 偶发「silent 分支跑了、事件没落盘」。
|
|
69
|
+
// 失败点在 `ensureDir`:它在 `appendEvent` 的 try 外,抛错时连「事件没写进去」
|
|
70
|
+
// 都不会打;调用方又普遍 `.catch(() => {})`,于是整条静默丢写。
|
|
71
|
+
// Windows 上目录被另一个句柄/杀软短暂占住会返回 EPERM/EACCES/EBUSY,隔几十毫秒
|
|
72
|
+
// 重试通常就过——和 writeAtomic 的 rename 重试同一个理由。
|
|
73
|
+
// 只重试这类瞬时错误;目录被一个文件占住(EEXIST/ENOTDIR)重试没用,直接抛。
|
|
74
|
+
const ENSURE_WAIT = [0, 20, 60, 120]
|
|
75
|
+
const ENSURE_RETRY = new Set(['EPERM', 'EACCES', 'EBUSY', 'ENOTEMPTY', 'EAGAIN'])
|
|
76
|
+
|
|
68
77
|
async function ensureDir(dir) {
|
|
69
|
-
|
|
78
|
+
for (let i = 0; i < ENSURE_WAIT.length; i++) {
|
|
79
|
+
if (ENSURE_WAIT[i]) await new Promise((r) => setTimeout(r, ENSURE_WAIT[i]))
|
|
80
|
+
try {
|
|
81
|
+
await fs.mkdir(dir, { recursive: true })
|
|
82
|
+
return
|
|
83
|
+
} catch (err) {
|
|
84
|
+
if (!ENSURE_RETRY.has(err?.code) || i === ENSURE_WAIT.length - 1) throw err
|
|
85
|
+
}
|
|
86
|
+
}
|
|
70
87
|
}
|
|
71
88
|
|
|
72
89
|
/**
|
|
@@ -293,14 +310,19 @@ export async function appendEvent(raw, ctx = {}, root = rootDir()) {
|
|
|
293
310
|
logLine('warn', [
|
|
294
311
|
'事件被校验拒收:',
|
|
295
312
|
`type=${type || '?'}`,
|
|
313
|
+
// 2026-11-22(外部 issue):只记 type=? 看不出「是漏了字段还是值写错」。
|
|
314
|
+
// 补上收到的键名(type 缺失时这里就是现场),排查不用再翻会话日志。
|
|
315
|
+
`keys=${raw && typeof raw === 'object' ? Object.keys(raw).join(',') || '(空对象)' : typeof raw}`,
|
|
296
316
|
`source=${String(ctx?.source ?? '?')}`,
|
|
297
317
|
String(err?.message ?? err).slice(0, 300),
|
|
298
318
|
], root)
|
|
299
319
|
throw err
|
|
300
320
|
}
|
|
301
321
|
const p = paths(root)
|
|
302
|
-
await ensureDir(p.root)
|
|
303
322
|
try {
|
|
323
|
+
// 2026-11-21(用户 m00612):ensureDir 原来在 try 外,失败时连一行日志都没有。
|
|
324
|
+
// 放进 try,和 appendLine 共用同一个「事件没写进去」出口;错误继续往上抛。
|
|
325
|
+
await ensureDir(p.root)
|
|
304
326
|
await appendLine(p.events, JSON.stringify(ev), root)
|
|
305
327
|
} catch (err) {
|
|
306
328
|
// 2026-10-29(用户 m02241):写失败以前是**完全静默**的——磁盘满、权限、文件被独占,
|
package/lib/sub.js
CHANGED
|
@@ -20,6 +20,7 @@ import { defineTool } from './tool.js'
|
|
|
20
20
|
import { guardWrite } from './tenant.js'
|
|
21
21
|
import { logLine } from './log.js'
|
|
22
22
|
import { toJsonSchema } from './toolschema.js'
|
|
23
|
+
import { materialFlash } from './cue.js'
|
|
23
24
|
|
|
24
25
|
/** 一次最多给几句。多了就变成"看全片"了。 */
|
|
25
26
|
export const SUB_MAX = 3
|
|
@@ -461,7 +462,12 @@ export function registerSub(ctx, deps = {}) {
|
|
|
461
462
|
root,
|
|
462
463
|
model: deps.model,
|
|
463
464
|
})
|
|
464
|
-
|
|
465
|
+
// 她正在读的这一段,若碰上了还悬着的事,就附一行在字幕后面——
|
|
466
|
+
// 当轮就能看到,不用等下一次醒来(1.0.8,用户 m02704)。
|
|
467
|
+
const flash = r.ok && r.text
|
|
468
|
+
? await materialFlash({ root, text: r.text, materialId: `bili_sub:${String(args?.bvid ?? '')}:${String(args?.from ?? '')}` }).catch(() => '')
|
|
469
|
+
: ''
|
|
470
|
+
return { ok: r.ok, text: r.text + flash, note: r.note }
|
|
465
471
|
},
|
|
466
472
|
}),
|
|
467
473
|
)
|
package/lib/talkmem.js
CHANGED
|
@@ -110,14 +110,18 @@ export async function amendLastExchange(root = rootDir(), { me, her } = {}) {
|
|
|
110
110
|
const more = cut(her)
|
|
111
111
|
if (!a || !more) return { ok: false }
|
|
112
112
|
try {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
113
|
+
// 和 addExchange 排同一队:不排的话,补话和另一轮结账(/say、群聊那一桶)撞上时
|
|
114
|
+
// 各读各的旧快照,后落盘的把先落盘的整份盖掉,两边都回 ok。
|
|
115
|
+
return await mutateJson(file(root), async () => {
|
|
116
|
+
const saved = await readJson(file(root), null)
|
|
117
|
+
const buckets = readBuckets(saved)
|
|
118
|
+
const list = buckets[BUCKET_HOME]
|
|
119
|
+
const last = list[list.length - 1]
|
|
120
|
+
if (!last || last.me !== a) return { ok: false }
|
|
121
|
+
last.her = cut([last.her, more].filter(Boolean).join(' '))
|
|
122
|
+
await writeAtomic(file(root), JSON.stringify({ version: 2, buckets }, null, 2))
|
|
123
|
+
return { ok: true }
|
|
124
|
+
})
|
|
121
125
|
} catch {
|
|
122
126
|
return { ok: false }
|
|
123
127
|
}
|