@ssamurias/dsh-fish 0.9.7 → 0.9.8

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/lib/herdiary.js CHANGED
@@ -26,6 +26,22 @@ import { defineTool } from './tool.js'
26
26
  /** 一次最多给她看这么多字(日记是她自己写的,但也不能一口气灌满上下文) */
27
27
  export const DIARY_READ_MAX = 3000
28
28
 
29
+ /**
30
+ * 日期清单一次列几天(2026-11-10,外部用户:写到第 90 天就「翻不到以前的了」)。
31
+ *
32
+ * 清单本身必须有上限,否则七十篇之后它自己就变成一次灌满上下文的操作。
33
+ * 但**上限不能再是静默的**:列不下就明说还差几天,否则她会以为那就是全部
34
+ * (原来 `slice(0, 60)` 什么也不说,这是她「翻着翻着就没了」的直接原因)。
35
+ */
36
+ export const DIARY_LIST_MAX = 60
37
+
38
+ /** 关键词搜索:一次最多列几处命中、每处前后各留多少字。 */
39
+ export const DIARY_HIT_MAX = 20
40
+ export const DIARY_HIT_WIDTH = 40
41
+
42
+ /** 关键词最长这么多个字:再长就不像「一个词」了,她自己也不会那样搜。 */
43
+ const KEYWORD_MAX = 60
44
+
29
45
  /** 只接受 `YYYY-MM-DD`。日期是惟一的入参形态,不拼路径。 */
30
46
  const DATE_RE = /^\d{4}-\d{2}-\d{2}$/
31
47
 
@@ -49,7 +65,19 @@ export function renderDiary({ date = '', text = '', dates = [], why = '', day, w
49
65
  const head = total > kept.length
50
66
  ? `你一共写过 ${total} 篇日记,现在翻得到的有 ${kept.length} 篇,更早的翻不到了。翻得到的日子:`
51
67
  : '你写过日记的日子:'
52
- return [head, ...kept.slice(0, 60).map((d) => `- ${d}`)].join('\n')
68
+ // 2026-11-10:原来这里是 `slice(0, 60)`,截了不说。她写到第 90 天时就以为
69
+ // 自己只剩最近 60 天——「翻着翻着就没了」的真正原因。现在列不下就明说还差几天,
70
+ // 并告诉她怎么要(按日期,或者按一个词去搜)。
71
+ const shown = kept.slice(0, DIARY_LIST_MAX)
72
+ const lines = [head, ...shown.map((d) => `- ${d}`)]
73
+ const rest = kept.length - shown.length
74
+ if (rest > 0) {
75
+ lines.push(
76
+ `(这里先列最近 ${shown.length} 天,更早的还有 ${rest} 天没列出来——它们都还在。` +
77
+ '想翻哪一天,直接把日期告诉我;只记得写过什么、不记得哪一天,就给个词,我去日记里找。)',
78
+ )
79
+ }
80
+ return lines.join('\n')
53
81
  }
54
82
  if (!date || text === null || text === undefined) {
55
83
  // 写过、但一篇都没留下:不能说「还没写过」,那是在替她抹掉写过的事。
@@ -70,6 +98,52 @@ export function renderDiary({ date = '', text = '', dates = [], why = '', day, w
70
98
  return [`${date} 那天你写的:`, body, note, where].filter(Boolean).join('\n').trim()
71
99
  }
72
100
 
101
+ /**
102
+ * 命中处前后各取一点上下文,凑成一行(2026-11-10)。
103
+ *
104
+ * 只给她「命中的那个词」没有用——她要的是想起来「那天我在说什么」。
105
+ * 所以按行切:先找出命中所在的那一行,再在这一行里左右各留 DIARY_HIT_WIDTH 字;
106
+ * 被切掉的两头加省略号,让她知道这里不是整句。不跨行,跨行读起来像两件事拼一起。
107
+ */
108
+ function snippetAround(body, at, len, width = DIARY_HIT_WIDTH) {
109
+ const lineStart = body.lastIndexOf('\n', at) + 1
110
+ const lineBreak = body.indexOf('\n', at)
111
+ const lineEnd = lineBreak < 0 ? body.length : lineBreak
112
+ const start = Math.max(lineStart, at - width)
113
+ const end = Math.min(lineEnd, at + len + width)
114
+ const piece = body.slice(start, end).replace(/\s+/g, ' ').trim()
115
+ return `${start > lineStart ? '…' : ''}${piece}${end < lineEnd ? '…' : ''}`
116
+ }
117
+
118
+ /**
119
+ * 关键词命中怎么念(2026-11-10,外部用户:日记写到第 90 天就翻不动了)。
120
+ *
121
+ * 这件事的根不是「有没有权限读」,是**没有索引**:她只记得写过什么,不记得哪一天。
122
+ * 所以给她按词找,找回来的每条都带日期——她拿着日期,就能用同一个工具读整天。
123
+ *
124
+ * 三条口径:
125
+ * - 数的是「处」不是「篇」:同一天提了两次就是两处,散在不同段落里本来也该分开看;
126
+ * - 一处都不许编:没找到就说没找到,绝不说「那天没有日记」(那天她可能真写过,只是没提这个词);
127
+ * - 超出上限就明说还有多少处,别让她以为就这些。
128
+ */
129
+ export function renderSearch({ keyword = '', hits = [], matched = 0, rest = 0, scanned = 0, pruned = 0 } = {}) {
130
+ const word = String(keyword)
131
+ const gone = pruned > 0 ? `更早的 ${pruned} 篇已经不在了,那些翻不到。` : ''
132
+ if (!matched) {
133
+ return [
134
+ `翻得到的 ${scanned} 篇日记里,没找到「${word}」。`,
135
+ '想按天翻,就把日期告诉我;换个词也行——我找的是原话里的字,记不清原句就挑一个还有印象的词。',
136
+ gone,
137
+ ].filter(Boolean).join('\n')
138
+ }
139
+ const lines = [`日记里提到「${word}」的 ${matched} 处(新的在前):`]
140
+ for (const h of hits) lines.push(`- ${h.date} ${h.snippet}`)
141
+ if (rest > 0) lines.push(`(这里只列了前 ${hits.length} 处,还有 ${rest} 处没列)`)
142
+ lines.push('想读一整天,把那个日期告诉我。')
143
+ if (gone) lines.push(gone)
144
+ return lines.join('\n')
145
+ }
146
+
73
147
  /**
74
148
  * 一篇日记的坐标:第几天、一共几篇、前后哪几天也写过。
75
149
  *
@@ -115,18 +189,26 @@ export function registerHerDiary(ctx, deps = {}) {
115
189
  name: 'her_diary',
116
190
  description:
117
191
  '翻你自己写过的日记。日记不在事件流里,her_recall 翻不到,只有这里能看。' +
118
- '不给日期就是最近那一篇;也可以只要一份日期清单。一次给你一份,太长的会截断。',
192
+ '不给日期就是最近那一篇;也可以只要一份日期清单;' +
193
+ '记不清哪一天、只记得写过什么,就给个词,它会去所有日记里找。一次给你一份,太长的会截断。',
119
194
  parameters: toJsonSchema({
120
195
  date: {
121
196
  type: 'string',
122
197
  required: false,
123
- description: '想看哪一天,写成 YYYY-MM-DD。不写就是最近那一篇。',
198
+ description: '想看哪一天,写成 YYYY-MM-DD。不写就是最近那一篇;跟 keyword 一起用就只在那天里找。',
124
199
  },
125
200
  list: {
126
201
  type: 'boolean',
127
202
  required: false,
128
203
  description: '只想知道写过哪些天:给 true 就只回一份日期清单。',
129
204
  },
205
+ // 2026-11-10:她要翻的往往正是「记不清哪一天」的那种事,只能按日期要就等于翻不动。
206
+ keyword: {
207
+ type: 'string',
208
+ required: false,
209
+ description: '记不清哪一天时用:给一个词(比如一件事、一个人名、一句原话里的字),' +
210
+ '它去翻得到的日记里找,回你每一处在哪一天、前后写了什么。',
211
+ },
130
212
  }),
131
213
  output: {
132
214
  schema: {
@@ -136,6 +218,8 @@ export function registerHerDiary(ctx, deps = {}) {
136
218
  text: { type: 'string' },
137
219
  // 写过、但文件已经被「日记留多久」清掉了:账上不能记成「那天没有日记」(use.js)
138
220
  gone: { type: 'boolean' },
221
+ // 按词找的时候带上:回执要说「找到了/没找到」,不能说「那天没有日记」(use.js)
222
+ keyword: { type: 'string' },
139
223
  },
140
224
  required: ['found', 'text'],
141
225
  },
@@ -172,6 +256,47 @@ export function registerHerDiary(ctx, deps = {}) {
172
256
  }
173
257
  }
174
258
  const dateKey = want || dates[0] || ''
259
+ // 2026-11-10(外部用户:写到第 90 天就翻不动了):她只记得写过什么,不记得哪天。
260
+ // 只认日期就等于要她先猜对日期才能翻——那正是她做不到的事。
261
+ // 所以给一个词,逐篇读、逐篇找;找回来的每一处都带日期,她拿着日期再读整天。
262
+ const word = String(args?.keyword ?? '').trim().slice(0, KEYWORD_MAX)
263
+ if (word) {
264
+ // 只搜「还翻得到的」:被「日记留多久」清掉的文件已经不在了,
265
+ // 假装它可能在里面,比直接说没有更糟。
266
+ const pool = want ? dates.filter((d) => d === want) : dates
267
+ const hits = []
268
+ let matched = 0
269
+ let scanned = 0
270
+ const lowerWord = word.toLowerCase()
271
+ for (const d of pool) {
272
+ const body = await readDaily('diaryDir', d, root)
273
+ if (body === null) continue
274
+ const raw = String(body)
275
+ const lower = raw.toLowerCase()
276
+ if (!lower.includes(lowerWord)) { scanned += 1; continue }
277
+ scanned += 1
278
+ let from = 0
279
+ for (;;) {
280
+ const at = lower.indexOf(lowerWord, from)
281
+ if (at < 0) break
282
+ matched += 1
283
+ if (hits.length < DIARY_HIT_MAX) hits.push({ date: d, snippet: snippetAround(raw, at, word.length) })
284
+ from = at + word.length
285
+ }
286
+ }
287
+ return {
288
+ found: matched > 0,
289
+ keyword: word,
290
+ text: renderSearch({
291
+ keyword: word,
292
+ hits,
293
+ matched,
294
+ rest: Math.max(0, matched - hits.length),
295
+ scanned,
296
+ pruned: want ? 0 : Math.max(0, written.length - dates.length),
297
+ }),
298
+ }
299
+ }
175
300
  if (!dateKey) {
176
301
  return { found: false, ...(gone ? { gone: true } : {}), text: renderDiary({ dates, written }) }
177
302
  }
package/lib/home.js CHANGED
@@ -26,13 +26,14 @@ import { promises as fs } from 'node:fs'
26
26
  import { join } from 'node:path'
27
27
  import { rootDir, paths, readJson, writeAtomic } from './store.js'
28
28
  import { withFileLock } from './tenant.js'
29
- import { recentExchanges, renderCarry } from './talkmem.js'
29
+ import { recentExchanges, renderCarry, TALK_KEEP } from './talkmem.js'
30
30
  // 只为了「换房间前她那句话」:从事件流里挑她这一轮说出口的话。
31
31
  // inbox.js 只依赖 store/schema,不反向引 home,不成环。
32
32
  import { newHerEventsSince } from './inbox.js'
33
33
  import { freshWakeText } from './wakeconst.js'
34
- import { dateKey } from './settings.js'
34
+ import { dateKey, loadConfig } from './settings.js'
35
35
  import { stripToolMarkup } from './markup.js'
36
+ import { stripTranscriptTail } from './transcript.js'
36
37
 
37
38
  const TITLE_WORKSPACE = '大肥鱼的家'
38
39
  const TITLE_SESSION = '跟大肥鱼说话'
@@ -839,7 +840,9 @@ async function askForLastWords(ctx, { sessionId, root, log } = {}) {
839
840
  if (b?.type !== 'text' || !b.text) continue
840
841
  // 2026-11-04(issue #25):同一份 assistant 正文里可能只剩工具调用标记,
841
842
  // 那种东西不能当成她留在上一个房间里的最后一句话。
842
- const t = stripToolMarkup(b.text)
843
+ // 2026-11-11(W49):同一份正文里还可能挂着她自己续写的 `user … / assistant …`
844
+ // 对话记录,那半段是编的,更不能当成「最后一句」。
845
+ const t = stripTranscriptTail(stripToolMarkup(b.text))
843
846
  if (t) say.push(t)
844
847
  }
845
848
  })
@@ -1042,7 +1045,11 @@ async function rotateTalkSessionOnce(ctx, { root = rootDir(), wsId, title = TITL
1042
1045
  // 2026-11-08(issue #60):`hearAt` 恰恰**不能**继承。它记的是「上次旁听记在
1043
1046
  // 第几轮」,而新会话的 `turns` 从 0 重新数——照搬旧值 39,`turns - hearAt`
1044
1047
  // 永远是负数,旁听从此再也不响。轮数归零,这个标记就跟着归零。
1045
- const carry = renderCarry(await recentExchanges(root))
1048
+ // 带几轮原话由设置页决定(chat.carry,2026-11-11 外部用户反馈;0 = 不带)。
1049
+ // 读配置失败就按默认 4——换会话本身不能因为一个设置读不出来而失败,
1050
+ // 而「少带几句」远比「这一轮换窗口直接报错」轻。
1051
+ const carryTurns = await carryTurnsFor(root)
1052
+ const carry = carryTurns > 0 ? renderCarry(await recentExchanges(root, carryTurns)) : ''
1046
1053
  // 写之前**重读一次**:函数开头那份 saved 可能已经被结账 / 旁听记账改过了,
1047
1054
  // 拿旧快照整体覆盖会把它们刚写进去的字段抹掉(同样是上面那个读-改-写问题)。
1048
1055
  try {
@@ -1218,6 +1225,23 @@ export async function adoptTalkSession(root = rootDir(), sessionId = '') {
1218
1225
  export const CARRY_DAYS = 3
1219
1226
  export const CARRY_TURNS = 8
1220
1227
 
1228
+ /**
1229
+ * 「换新会话带几轮原话」这一项读盘上的设置(2026-11-11)。
1230
+ *
1231
+ * 独立成函数是为了让失败有单一出口:读配置和 normalize 都可能抛,
1232
+ * 换会话是主流程,不能因为这个数读不出来就整趟失败。默认值取 TALK_KEEP,
1233
+ * 跟老版本写死的 4 一致——没设过的人升上来,行为一个字不变。
1234
+ */
1235
+ async function carryTurnsFor(root) {
1236
+ try {
1237
+ const { config } = await loadConfig(root)
1238
+ const n = Number(config?.chat?.carry)
1239
+ return Number.isFinite(n) ? Math.max(0, Math.trunc(n)) : TALK_KEEP
1240
+ } catch {
1241
+ return TALK_KEEP
1242
+ }
1243
+ }
1244
+
1221
1245
  export async function activeCarry(root = rootDir(), now = Date.now()) {
1222
1246
  const saved = (await readJson(homeFile(root), null)) ?? {}
1223
1247
  const text = String(saved.carry ?? '').trim()
package/lib/identity.js CHANGED
@@ -28,6 +28,7 @@ import { existsSync, readFileSync, statSync } from 'node:fs'
28
28
  import { selfDocPath } from './selfdoc.js'
29
29
  import { cwdOf, isHerHome, toolSurfaceFor } from './restrict.js'
30
30
  import { activeOutingSync, bindOutingSession } from './outing.js'
31
+ import { attachStreamScrub } from './scrub.js'
31
32
  import { deliverQueued } from './sessionnote.js'
32
33
 
33
34
  /** 段名与顺序:放在宿主自己的段之后、`complete` 段之前(order 越大越靠后)。 */
@@ -582,6 +583,13 @@ export function attachIdentity(agent, root, { frozen = '', herDir = '', log } =
582
583
  // 挂一个组装钩子摘掉它、把身份段提到紧跟 harness:identity —— 详情见 reorderForHer。
583
584
  const offAssemble = attachAssembleFix(agent, { log })
584
585
  if (offAssemble) remember(agent, 'hook', offAssemble)
586
+ // 2026-11-10(外部用户真机):模型偶尔把一次没组起来的工具调用当正文吐出来
587
+ // (`<her_note action="list" filter="open"/>`、成串的 `||DSML||` 收尾标记)。
588
+ // 宿主前端只渲染 append 原件,事后盖不掉;`llm/stream` 是落盘前唯一干净的拦截点,
589
+ // 详见 lib/scrub.js 顶部。挂不上(老宿主没这个 waterfall)就返回 undefined,
590
+ // 她只是接着漏,不算失败。
591
+ const offScrub = attachStreamScrub(agent, { log, sessionId: wakeSid })
592
+ if (offScrub) remember(agent, 'hook', offScrub)
585
593
  return { ok: true }
586
594
  } catch (err) {
587
595
  return { ok: false, why: String(err?.message ?? err).slice(0, 200) }
package/lib/index.js CHANGED
@@ -54,7 +54,7 @@ export const name = 'dsh-fish'
54
54
  * 版本号,必须和 package.json 的 version 一样(test/boot.test.mjs 盯着)。
55
55
  * 不只是日志:升级自检和设置页的「检查更新」拿它当「正在跑的版本」。
56
56
  */
57
- export const VERSION = '0.9.7'
57
+ export const VERSION = '0.9.8'
58
58
 
59
59
  // ⚠️ 一个数组写全,不要拆成对象
60
60
  // 2026-10-30(m02961):`userQuestions` **不再写进 inject**。写进 inject 的东西缺一个,
@@ -0,0 +1,122 @@
1
+ /**
2
+ * 素材的统一形状(0.9.8 / M3)
3
+ *
4
+ * 为什么要它:她看到的东西一直是「一条 B 站 pack」——标题、简介、热评、弹幕
5
+ * 混在一起,没有哪一句是「原话」、也没有哪句是「事实」。于是她能说的只有
6
+ * 总结,因为材料本身没给她可以引用的句子,也没告诉她哪些能核对。
7
+ *
8
+ * 这里定三件事,之后所有来源(B 站、以后的小说/帖子/文件)都按同一个形状交出来:
9
+ * - 一条素材 = 一件事(source + key + at);
10
+ * - 原话单独列(quotes[],每句带出处与分级,不改写);
11
+ * - 能不能当证据,由 grade 说清楚,不由她的语气决定。
12
+ *
13
+ * 分级(来源分级,不是给她看的标签):
14
+ * 1 = 可核对的事实(时长、UP 主、播放量、发布时间)
15
+ * 2 = 别人说的话(简介、评论、弹幕)——只能当观点,不能当证据
16
+ * 3 = 虚构(小说、梦、编出来的故事)——只能当素材
17
+ *
18
+ * 注意:grade 只用于渲染与后续判断,**不进身份文档、不打分、不出现「几级」字样**。
19
+ */
20
+
21
+ /** 素材分级。冻结,防止运行期被改。 */
22
+ export const GRADE = Object.freeze({
23
+ FACT: 1,
24
+ OPINION: 2,
25
+ FICTION: 3,
26
+ })
27
+
28
+ /**
29
+ * 「不同意见」的判据。
30
+ *
31
+ * 只用明确的反对词,不用「但是 / 其实 / 然而」这类转折词——那三个词在正常
32
+ * 评论里太常见,选出来的会是「随便一句带转折的话」,不是反例。
33
+ */
34
+ const DISSENT_RE = /不同意|不认同|不敢苟同|说错|错了|反对|胡说|瞎说|未必|夸大|标题党|翻车|纠正一下|反驳|争议|其实不是|并不|太扯|不靠谱|误导/
35
+
36
+ /** 这句评论/弹幕是不是在反对 */
37
+ export function isDissent(text) {
38
+ return DISSENT_RE.test(String(text ?? ''))
39
+ }
40
+
41
+ /**
42
+ * 从一堆评论里挑「不同意见」。
43
+ *
44
+ * 为什么不多:一次素材里出现两三条反例就够她对照了;给太多,素材会变成
45
+ * 评论区吵架现场,她的注意力会被拽到争论上,而不是那件事本身。
46
+ * 按点赞降序挑,最多 max 条。
47
+ */
48
+ export function pickDisputes(comments = [], { max = 2 } = {}) {
49
+ const out = []
50
+ const seen = new Set()
51
+ for (const c of comments) {
52
+ const text = String(c?.text ?? '').trim()
53
+ if (!text || seen.has(text)) continue
54
+ if (!isDissent(text)) continue
55
+ seen.add(text)
56
+ out.push({ text, like: Number(c?.like) || 0 })
57
+ if (out.length >= max) break
58
+ }
59
+ return out
60
+ }
61
+
62
+ function fmtDuration(sec) {
63
+ const n = Number(sec) || 0
64
+ if (!n) return ''
65
+ return `${Math.floor(n / 60)}分${String(n % 60).padStart(2, '0')}秒`
66
+ }
67
+
68
+ /**
69
+ * 一条来源 pack → 统一形状。
70
+ *
71
+ * pack 是现有的 B 站素材对象(video / desc / pubdate / tags / comments / danmaku),
72
+ * 这里只做规范化,不去抓数据、不改写任何一句话。
73
+ *
74
+ * @param {object} pack
75
+ * @param {{ source?: string }} [o]
76
+ */
77
+ export function toMaterial(pack = {}, o = {}) {
78
+ const v = pack.video ?? {}
79
+ const facts = []
80
+ const dur = fmtDuration(v.duration)
81
+ if (dur) facts.push({ label: '时长', value: dur, grade: GRADE.FACT })
82
+ if (v.up) facts.push({ label: 'UP 主', value: String(v.up), grade: GRADE.FACT })
83
+ if (v.view) facts.push({ label: '播放', value: String(v.view), grade: GRADE.FACT })
84
+ if (v.like) facts.push({ label: '点赞', value: String(v.like), grade: GRADE.FACT })
85
+ if (pack.pubdate) facts.push({ label: '发布', value: String(pack.pubdate).slice(0, 10), grade: GRADE.FACT })
86
+
87
+ const quotes = []
88
+ if (pack.desc) {
89
+ quotes.push({ by: 'UP 主', kind: 'desc', grade: GRADE.OPINION, text: String(pack.desc) })
90
+ }
91
+ for (const c of pack.comments ?? []) {
92
+ const text = String(c?.text ?? '').trim()
93
+ if (text) quotes.push({ by: '评论', kind: 'comment', grade: GRADE.OPINION, text, like: Number(c?.like) || 0 })
94
+ }
95
+ for (const c of pack.disputes ?? []) {
96
+ const text = String(c?.text ?? '').trim()
97
+ if (text) quotes.push({ by: '评论', kind: 'dissent', grade: GRADE.OPINION, text, like: Number(c?.like) || 0 })
98
+ }
99
+ for (const d of pack.danmaku ?? []) {
100
+ const text = String(d?.text ?? '').trim()
101
+ if (text) quotes.push({ by: '弹幕', kind: 'danmaku', grade: GRADE.OPINION, text })
102
+ }
103
+
104
+ return {
105
+ source: String(o.source ?? 'bili'),
106
+ key: String(v.bvid ?? ''),
107
+ at: pack.pubdate ?? null,
108
+ title: String(v.title ?? ''),
109
+ tags: [...(pack.tags ?? [])],
110
+ facts,
111
+ quotes,
112
+ // 只有「有可核对的事实」才算能当证据。纯观点素材(以后的帖子截图)就是 false。
113
+ canVerify: facts.length > 0,
114
+ blocked: pack.blocked ?? undefined,
115
+ }
116
+ }
117
+
118
+ /** 一条素材里、某一级的所有原话(供将来按级别挑引文用,不在渲染里直接暴露级别) */
119
+ export function quotesOf(material, grade) {
120
+ const list = material?.quotes ?? []
121
+ return grade === undefined ? list : list.filter((q) => q.grade === grade)
122
+ }
package/lib/observe.js CHANGED
@@ -89,7 +89,7 @@ import { publicOwner, saveOwner, saveAccount } from './owner.js'
89
89
  import { createClient } from './bili.js'
90
90
  import { historyFromEvents } from './history.js'
91
91
  import { runChecks } from './selfcheck.js'
92
- import { readRestrictState, knownToolNames, ownLayerNames, blockedTools, herToolsNow, herSceneToolsNow, currentAllowTools } from './restrict.js'
92
+ import { readRestrictState, knownToolNames, ownLayerNames, blockedTools, herToolsNow, herSceneToolsNow, currentAllowTools, refreshToolRestrict } from './restrict.js'
93
93
  import { riskState, clearRisk } from './risk.js'
94
94
  import { decodeBase64Image, saveImage } from './media.js'
95
95
  // 导出包里要写清「她那条会话用的哪个模型、吃不吃图」——只读探测,失败不影响导出。
@@ -723,6 +723,30 @@ export function registerObserve(ctx, deps = {}) {
723
723
  }
724
724
  const before = await loadConfig(root).catch(() => null)
725
725
  const next = await updateConfig(patch, root)
726
+ // 白名单一动就当场换刀(2026-11-11,外部用户反馈)。
727
+ // 以前这里存完就完事,工具面还是启动那一刻的那份;用户加了工具,
728
+ // 她照样按旧名单答「我手上没有这样东西」,只有重启 DSH 才认。
729
+ // 只有真的变了才换:自动保存每次都整表回传,没变也换会让每条会话白下一次刀。
730
+ const beforeAllow = JSON.stringify(before?.config?.tools?.allow ?? [])
731
+ const nextAllow = JSON.stringify(next?.tools?.allow ?? [])
732
+ // 梦开关不在这里换:her_dream 归不归她,跟着启动那一刻的梦状态走(issue #64 的取舍),
733
+ // 打开它仍要重启——否则得同时动身份文档与工具面,两处一变就不是「存一下」了。
734
+ let toolsLive = null
735
+ if (beforeAllow !== nextAllow) {
736
+ try {
737
+ const r = refreshToolRestrict({ extra: next?.tools?.allow ?? [] })
738
+ toolsLive = { ok: r?.ok === true, deferred: r?.deferred?.length ?? 0 }
739
+ logLine('info', [
740
+ 'tools.allow 已当场生效',
741
+ `allow=${(next?.tools?.allow ?? []).join(',') || '(空)'}`,
742
+ `换刀=${r?.applied?.length ?? 0}`,
743
+ r?.deferred?.length ? `延后=${r.deferred.length}` : '',
744
+ ], root)
745
+ } catch (err) {
746
+ // 换刀失败不影响设置本身存下去;下一次新建会话仍会按新名单收窄。
747
+ logLine('warn', ['白名单热更新没成(下次新建会话照样生效):', String(err?.message ?? err).slice(0, 200)], root)
748
+ }
749
+ }
726
750
  // issue #64:身份文档读的不止 sendTools 一项(日记、睡觉、白名单、上网、说话都读),
727
751
  // 所以保存后无条件重写一次。内容没变时 writeSelfDoc 自己就不写盘,不会多出写操作。
728
752
  await refreshSelfDoc(root).catch(() => {})
@@ -744,7 +768,7 @@ export function registerObserve(ctx, deps = {}) {
744
768
  `by=${Object.keys(patch).join(',')}`,
745
769
  ], root)
746
770
  }
747
- return send(res, 200, { ok: true, config: next, droppedTools })
771
+ return send(res, 200, { ok: true, config: next, droppedTools, toolsLive })
748
772
  }
749
773
  send(res, 405, { error: 'method not allowed' })
750
774
  }],
package/lib/persona.js CHANGED
@@ -310,8 +310,8 @@ export function buildSections(model, opts = {}) {
310
310
  * 「看到以前的日记,感觉像是另一个人写的,我只是能读」。
311
311
  *
312
312
  * 诊断:这份文档能永久留住的**全是结论**(立场、疤、拒绝、自我叙述),没有一条
313
- * 把她和「那些天是连着过的」绑在一起;续接用的 carry 只带 4 句原话、8 轮就消失
314
- * (见 home.activeCarry)。于是她知道自己说过某句,却不记得说过——不是记忆丢了,
313
+ * 把她和「那些天是连着过的」绑在一起;续接用的 carry 只带最近几轮原话(默认 4 轮,
314
+ * `config.chat.carry` 可调 0–20)、8 轮就消失(见 home.activeCarry)。于是她知道自己说过某句,却不记得说过——不是记忆丢了,
315
315
  * 是经历丢了。
316
316
  *
317
317
  * 为什么是核心段:被预算裁一次就等于那些天没发生过。跟疤同一条理由。
@@ -855,7 +855,9 @@ export const DIARY_BRIEF = [
855
855
  // her_recall,那句话就不成立了。现在真给了 her_diary,得把话说明白:
856
856
  // 想回头翻就走这个工具,它只读、一次一份。
857
857
  // 2026-11-09(用户 m00002):她自己的入口句补进这一段——想翻某一天,不是「有 her_diary」。
858
- '什么时候想起它——想回头翻的时候用 her_diary:想看看以前某一天写了什么,就去翻;那些字是我的,别人看不看是别人的事。',
858
+ // 2026-11-10:只按日期翻,她就得先记得日期;可要翻的往往正是「记不清哪一天」的那种事。
859
+ // 工具现在也能按词找,这一句得跟上,不然她永远只会按天试。
860
+ '什么时候想起它——想回头翻的时候用 her_diary:想看看以前某一天写了什么,就去翻;只记得写过什么、记不清哪一天,就给个词让它去找。那些字是我的,别人看不看是别人的事。',
859
861
  // 2026-10-29(用户 m01296 A):光说「每天记一笔」不够——三天零篇的直接原因就是
860
862
  // 这一段只讲了「会做这件事」,没讲「用哪个东西做」。同页 SLEEP_BRIEF 明写了
861
863
  // growth_commit / refs,她照着能做出来;这一段没写机制,就一次也没试过。