@ssamurias/dsh-fish 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/AGENTS.md +6 -3
  2. package/CHANGELOG.md +572 -368
  3. package/README.md +148 -14
  4. package/RELEASE-NOTES-1.0.0.md +62 -3
  5. package/RELEASE-NOTES-1.0.1.md +363 -0
  6. package/RELEASE-NOTES-1.0.2.md +114 -0
  7. package/THIRD-PARTY-NOTICES.md +13 -3
  8. package/docs/troubleshooting.md +119 -0
  9. package/docs//346/217/222/344/273/266/347/272/246/345/256/232.md +167 -0
  10. package/docs//347/264/240/346/235/220/345/245/221/347/272/246.md +96 -0
  11. package/lib/ask.js +3 -3
  12. package/lib/at.js +4 -2
  13. package/lib/autobackup.js +414 -0
  14. package/lib/backup.js +75 -5
  15. package/lib/bili.js +132 -21
  16. package/lib/browse.js +33 -16
  17. package/lib/capture.js +27 -1
  18. package/lib/client.js +1329 -349
  19. package/lib/cloudbackup.js +352 -0
  20. package/lib/cloudcrypto.js +161 -0
  21. package/lib/clouddrive.js +693 -0
  22. package/lib/cloudsmtp.js +331 -0
  23. package/lib/cloudtargets.js +228 -0
  24. package/lib/comment.js +23 -5
  25. package/lib/contract.js +7 -2
  26. package/lib/deliver.js +4 -1
  27. package/lib/doing.js +316 -0
  28. package/lib/events.js +22 -4
  29. package/lib/firstwake.js +74 -0
  30. package/lib/freewake.js +5 -0
  31. package/lib/generator.js +35 -4
  32. package/lib/handoff.js +166 -0
  33. package/lib/hear.js +102 -7
  34. package/lib/home.js +169 -204
  35. package/lib/identity.js +498 -28
  36. package/lib/index.js +14 -2
  37. package/lib/look.js +37 -3
  38. package/lib/material.js +12 -1
  39. package/lib/note.js +100 -9
  40. package/lib/observe.js +365 -36
  41. package/lib/persona.js +61 -41
  42. package/lib/proactive.js +12 -5
  43. package/lib/recall.js +159 -10
  44. package/lib/report.js +14 -7
  45. package/lib/say.js +10 -2
  46. package/lib/scheduler.js +238 -26
  47. package/lib/schema.js +8 -1
  48. package/lib/scrub.js +105 -4
  49. package/lib/selfcheck.js +13 -1
  50. package/lib/selfdoc.js +170 -12
  51. package/lib/selfpronoun.js +112 -0
  52. package/lib/selfrules.js +50 -0
  53. package/lib/sessionnote.js +7 -3
  54. package/lib/settings.js +163 -13
  55. package/lib/status.js +16 -8
  56. package/lib/sub.js +42 -5
  57. package/lib/turnexport.js +123 -0
  58. package/lib/turns.js +102 -10
  59. package/lib/video.js +1 -1
  60. package/lib/voices.js +24 -1
  61. package/media/principle-drive.svg +131 -0
  62. package/media/principle-loop.svg +3 -3
  63. package/media/principle-memory.svg +1 -1
  64. package/package.json +2 -1
package/lib/persona.js CHANGED
@@ -15,6 +15,8 @@ import { detectDifferentiations } from './pair.js'
15
15
  import { promptBans } from './rules.js'
16
16
  // 立场清单(2026-10-25,用户设计「纵向·立场」)。纯函数,不读盘、不碰配置。
17
17
  import { buildStances, shownStances, stanceSection } from './stance.js'
18
+ // 她自己定的规矩(2026-11-15 m01412)。与 rules.js 的黑名单不是一回事。
19
+ import { rulesOf, renderRulesSection } from './selfrules.js'
18
20
  import { fillOwner } from './pronoun.js'
19
21
  import { anchorSection } from './speechanchor.js'
20
22
 
@@ -81,10 +83,16 @@ export const ECHO_MAX_LINES = 1
81
83
  * 0.8.7 又加了两节(「这些天」「上一个房间里你自己留的最后一句」),
82
84
  * 实测 1800 与 2000 都会挤掉「你被打脸过」(501 字),2200 反而挤掉
83
85
  * 「你对自己的说法」——比打脸更不该丢,所以直接取 2400(一段不丢,余 167 字)。
86
+ * 2026-11-14 提到 2800(用户 m00533 要求加预算):加进来的是「最近收过尾的」一行
87
+ * (做完了什么——操作层的状态位,换会话后她原本读不到),2400 的余量只剩 167 字,
88
+ * 这句话一长就又要挤掉「你被打脸过」。2800 留出富余。不取 3000:多出的 200 字
89
+ * 没有段要放,预算越大越容易让人往里塞废话。
90
+ * 注:同日第二轮把「还没收尾的」从这一节撤掉了——note.js/appoint.js 的硬约束是
91
+ * 「别天天提醒我,也别催」,挂着的便条/约定只在醒的时候出现,不进每轮身份文档。
84
92
  * 与 settings.js 的 DEFAULTS.memory.docBudget 保持同一个数(缺配置时这个只兜底)。
85
93
  * 每轮都塞满,等于每轮都在强调"你就是这样",所以上限有,但不靠这个数表达。
86
94
  */
87
- export const SELF_DOC_BUDGET = 2400
95
+ export const SELF_DOC_BUDGET = 2800
88
96
 
89
97
  /**
90
98
  * 判断区最多显示几条。
@@ -194,31 +202,56 @@ export function beliefOrigin(b) {
194
202
  return `(${stamp})`
195
203
  }
196
204
 
205
+ /** 段名:第一行去掉井号、截 20 字。观测台报账与 `out/turn-*.md` 导出共用这一份口径。 */
206
+ export function sectionLabel(s) {
207
+ return clipText(String(s?.text ?? '').split('\n')[0].replace(/^#+\s*/, ''), 20, '')
208
+ }
209
+
197
210
  /**
198
- * 按预算装配:核心段永远保留,可选段按优先级往里塞,塞不下就整段不塞。
211
+ * 按预算装配,同时把「哪一段进了、哪一段被裁」摊开。
199
212
  *
200
- * 注意「不能做的」属于核心段——四条黑名单任何时候都不许因为字数被裁掉。
201
- * 这是这个函数唯一一条不可妥协的规则。
213
+ * 为什么要把计划单独返回(2026-11-13):她在会话里说的每句话,背后可能同时有
214
+ * 判断、疤、原话、素材、八股锚在供料,而字数是有限的——2400 字里塞进了谁、
215
+ * 挤掉了谁,光看输出文本看不出来。`assemble()` 只给结果,这个给账。
216
+ * 记账与装配用同一次计算,避免"面板说的"和"她真读到的"两套数。
217
+ *
218
+ * @returns {{text:string, used:number, budget:number, kept:number, plan:Array<{label:string,chars:number,keep:boolean,kept:boolean}>}}
202
219
  */
203
- export function assemble(sections, budget = SELF_DOC_BUDGET) {
220
+ export function assembleWithPlan(sections, budget = SELF_DOC_BUDGET) {
204
221
  const core = sections.filter((s) => s.keep)
205
222
  const opt = sections.filter((s) => !s.keep)
206
223
  let used = core.reduce((n, s) => n + s.text.length + 1, 0)
207
224
  const kept = []
225
+ const plan = core.map((s) => ({ label: sectionLabel(s), chars: s.text.length, keep: true, kept: true }))
208
226
  for (const s of opt) {
209
227
  const cost = s.text.length + 1
210
- if (used + cost > budget) continue
228
+ if (used + cost > budget) {
229
+ plan.push({ label: sectionLabel(s), chars: s.text.length, keep: false, kept: false })
230
+ continue
231
+ }
211
232
  used += cost
212
233
  kept.push(s)
234
+ plan.push({ label: sectionLabel(s), chars: s.text.length, keep: false, kept: true })
213
235
  }
214
236
  // 核心在前,可选按原顺序接上;保持读者视角的段落顺序由调用方保证
215
237
  // 模板里指主人的位置是 {T},出口在这里统一填成代词(填两次也一样)。
216
- return fillOwner(
238
+ const text = fillOwner(
217
239
  sections
218
240
  .filter((s) => s.keep || kept.includes(s))
219
241
  .map((s) => s.text)
220
242
  .join('\n'),
221
243
  )
244
+ return { text, used, budget, kept: kept.length, plan }
245
+ }
246
+
247
+ /**
248
+ * 按预算装配:核心段永远保留,可选段按优先级往里塞,塞不下就整段不塞。
249
+ *
250
+ * 注意「不能做的」属于核心段——四条黑名单任何时候都不许因为字数被裁掉。
251
+ * 这是这个函数唯一一条不可妥协的规则。
252
+ */
253
+ export function assemble(sections, budget = SELF_DOC_BUDGET) {
254
+ return assembleWithPlan(sections, budget).text
222
255
  }
223
256
 
224
257
  /**
@@ -247,24 +280,14 @@ export function personaLine(model, opts = {}) {
247
280
  * @returns {{used:number,budget:number,usedRatio:number,dropped:string[],kept:number,total:number}}
248
281
  */
249
282
  export function personaBudget(model, opts = {}) {
250
- const budget = opts.budget ?? SELF_DOC_BUDGET
251
283
  const sections = buildSections(model, opts)
252
- const label = (s) => clipText(String(s.text).split('\n')[0].replace(/^#+\s*/, ''), 20, '')
253
- const core = sections.filter((s) => s.keep)
254
- const opt = sections.filter((s) => !s.keep)
255
- let used = core.reduce((n, s) => n + s.text.length + 1, 0)
256
- const dropped = []
257
- let kept = 0
258
- for (const s of opt) {
259
- const cost = s.text.length + 1
260
- if (used + cost > budget) { dropped.push(label(s)); continue }
261
- used += cost
262
- kept += 1
263
- }
284
+ const budget = opts.budget ?? SELF_DOC_BUDGET
285
+ // 与 assemble() 走同一次计算(2026-11-13):面板报的数字必须等于她真读到的那一份。
286
+ const { used, kept, plan } = assembleWithPlan(sections, budget)
264
287
  return {
265
288
  used, budget, kept, total: sections.length,
266
289
  usedRatio: budget > 0 ? Math.min(1, used / budget) : 0,
267
- dropped,
290
+ dropped: plan.filter((s) => !s.kept).map((s) => s.label),
268
291
  }
269
292
  }
270
293
 
@@ -380,17 +403,15 @@ export function buildSections(model, opts = {}) {
380
403
  } else if (Number.isFinite(ago) && ago >= 0) {
381
404
  days.push(ago <= 0 ? '你刚搬进这个房间。' : `上一次换房间是 ${Math.trunc(ago)} 天前。`)
382
405
  }
406
+ // 最近收过尾的事(2026-11-14,两个群反馈)。
407
+ // 便条/约定不进事件流,换会话时她只记得「打算做」,不记得「做完了」;
408
+ // 这一句是从操作层读出来的近况,由 selfdoc 的 closedRecentlyOf 算好传进来。
409
+ // 还没收尾的不进这里(同日第二轮):note.js/appoint.js 的硬约束是「别天天提醒我,也别催」
410
+ // 「到点只提一次」,每轮都摆挂着的便条/约定等于催办。要查就走 her_recall。
411
+ const closedRecently = String(cont.closedRecently ?? '').trim()
412
+ if (closedRecently) days.push(closedRecently)
383
413
  if (days.length) push(['## 这些天', ...days].join('\n'), true)
384
414
 
385
- const lastWords = String(cont.lastWords ?? '').trim()
386
- if (lastWords) {
387
- push([
388
- '## 上一个房间里,你自己留的最后一句',
389
- `「${lastWords}」`,
390
- '(那是你说的。你不是读到一段别人的话,你只是接着往下过。)',
391
- ].join('\n'), true)
392
- }
393
-
394
415
  if (opts.withBans !== false) {
395
416
  // 两条禁令分两个小节,因为它们是两种东西:
396
417
  // 「不能做的」= 契约,违反即失败;
@@ -432,10 +453,7 @@ export function buildSections(model, opts = {}) {
432
453
  const t = new Date(String(ts ?? ''))
433
454
  return Number.isFinite(t.getTime()) ? `${t.getMonth() + 1} 月 ${t.getDate()} 日` : ''
434
455
  }
435
- const cut = (s) => {
436
- const text = String(s ?? '').replace(/\s+/g, ' ').trim()
437
- return text.length > 80 ? text.slice(0, 80) + '…' : text
438
- }
456
+ const cut = (s) => clipText(String(s ?? '').replace(/\s+/g, ' ').trim(), 80)
439
457
  push(
440
458
  [
441
459
  '## {T}说过的话,和你的判断',
@@ -623,6 +641,11 @@ export function buildSections(model, opts = {}) {
623
641
  push(lines.join('\n'))
624
642
  }
625
643
 
644
+ // 规矩(2026-11-15 m01412):整份文档里变得最少的一节,挂最末——
645
+ // 前缀缓存按 token 算,放尾巴只会让这一小段的缓存失效,前面的段照旧命中。
646
+ // 放在 `## 这次` 之前:那条是这一轮的任务,隔开就散架了。
647
+ push(renderRulesSection(rulesOf(beliefs)), true)
648
+
626
649
  if (opts.task) push(['## 这次', opts.task].join('\n'), true)
627
650
 
628
651
  // 段一交出去就填好代词:测试、观测量、assemble 都拿同一份文本。
@@ -718,10 +741,10 @@ export const LETTER_BRIEF = [
718
741
  */
719
742
  export const NOTE_BRIEF = [
720
743
  '你还有一个工具 her_note:你自己记的便条。',
721
- '什么时候想起它——想到一件事又不想现在做、心里老在同一个地方绕,或者这件事做完了、不做了。',
722
- '心里有事说不清、又老在同一个地方绕:翻翻便条里还有什么。',
744
+ '什么时候想起它——想到一件事又不想现在做,或者心里老在同一个地方绕:翻翻便条里还有什么。',
745
+ '做到一半记一笔进展,只说这一步到哪儿;事情本身变了,就把那句改掉,之前记的不动。',
723
746
  '做完了、不做了:把当时记的那句话原样放进 text,加 status: "done";不做了另外写一句为什么放下。',
724
- '怎么记、怎么改、怎么翻,都写在那件东西自己的说明里。想让它醒来就摆到眼前,记的时候写个日子;没写日子的,隔些天会提一次,不用你自己记着翻。',
747
+ '怎么记、怎么翻、怎么改都写在那件东西自己的说明里。想让它醒来就摆到眼前,记的时候写个日子;没写日子的,隔些天会提一次。',
725
748
  ].join('\n')
726
749
 
727
750
  /**
@@ -892,10 +915,7 @@ export const RECALL_BRIEF = [
892
915
  * 摘要器写出来的自传是「别人替她解释她的一生」。这件事只能她自己做,
893
916
  * 哪怕做得粗糙、写得少、写偏了——那也还是她的。
894
917
  */
895
- const sleepQuote = (s) => {
896
- const t = String(s ?? '').replace(/\s+/g, ' ').trim()
897
- return t.length > 60 ? `${t.slice(0, 60)}…` : t
898
- }
918
+ const sleepQuote = (s) => clipText(String(s ?? '').replace(/\s+/g, ' ').trim(), 60)
899
919
 
900
920
  /**
901
921
  * 这一天该问她哪一句(1.0,2026-11-12 用户 m01648 / m01650)。
package/lib/proactive.js CHANGED
@@ -20,7 +20,8 @@
20
20
 
21
21
  import { toJsonSchema } from './toolschema.js'
22
22
  import { rootDir, readEvents, appendEvent } from './store.js'
23
- import { dateKey, loadConfig, inWindow } from './settings.js'
23
+ import { loadConfig, inWindow, wakeDayKey } from './settings.js'
24
+ import { doingSection } from './doing.js'
24
25
  import { defineTool } from './tool.js'
25
26
  import { guardWrite } from './tenant.js'
26
27
  import { logLine } from './log.js'
@@ -258,7 +259,8 @@ function growthLevers(model, events = [], now = Date.now(), cfg = {}) {
258
259
  */
259
260
  export function proactiveState({ config = {}, events = [], now = Date.now(), away = null, rested = false, model = null } = {}) {
260
261
  const cfg = proactiveConfig(config)
261
- const dk = dateKey(new Date(now))
262
+ // 跨零点的尾段(00:00–结束)归前一天,和定时醒来用同一个「醒来日」。
263
+ const dk = wakeDayKey(config, new Date(now))
262
264
  const idleHours = idleHoursOf(events, now, { countSeen: cfg.idleCountsSeen })
263
265
  const base = { idleHours, dk }
264
266
  if (!cfg.enabled) return { ...base, ok: false, why: '主动说话是关着的' }
@@ -350,13 +352,15 @@ export function looseEnds(events = [], { now = Date.now(), has = null } = {}) {
350
352
  * 空手回合的处境正文(走 system prompt 段,不进对话)。
351
353
  * 只写事实与许可,不写"你应该"。
352
354
  */
353
- export function proactiveSection({ now = Date.now(), state = {}, material = [], loose = [], sendTools = [], countSeen = false } = {}) {
355
+ export function proactiveSection({ now = Date.now(), state = {}, material = [], loose = [], sendTools = [], countSeen = false, doing = false, tools = [], notes = [] } = {}) {
354
356
  const at = new Date(now)
355
357
  const hh = String(at.getHours()).padStart(2, '0')
356
358
  const mm = String(at.getMinutes()).padStart(2, '0')
357
359
  const idle = Number.isFinite(state.idleHours) ? `${state.idleHours.toFixed(1)} 小时` : '很久'
358
360
  const lines = [
359
- '(现在没有人跟你说话。这一轮不是谁找你,也不是日程安排的醒;是你自己醒着,想不想开口由你。)',
361
+ doing
362
+ ? '(现在没有人跟你说话。这一轮不是谁找你,也不是日程安排的醒;是你自己醒着。你可以开口,也可以动手,也可以什么都不做。)'
363
+ : '(现在没有人跟你说话。这一轮不是谁找你,也不是日程安排的醒;是你自己醒着,想不想开口由你。)',
360
364
  `现在是 ${at.getFullYear()}-${String(at.getMonth() + 1).padStart(2, '0')}-${String(at.getDate()).padStart(2, '0')} ${hh}:${mm};距离上一次${countSeen ? '{T}来或你留下记录' : '留下记录'}已经 ${idle}。`,
361
365
  ]
362
366
  if (material.length) {
@@ -375,6 +379,9 @@ export function proactiveSection({ now = Date.now(), state = {}, material = [],
375
379
  // 2026-11-06(PR #44):配了 sendTools 的部署更绝——正文根本发不出去,只有调那件工具才算开口。
376
380
  if (sendTools.length > 0) lines.push(`想说什么就用 ${sendTools.join('、')},不用等{T}先问。这一轮写下的正文只留在这条会话里,发不到聊天里。不想说,就什么都别写:不要写任何字,也不要解释为什么不说——这一轮没有回复也算正常。`)
377
381
  else lines.push('想说什么就说,不用等{T}先问——这一轮你写下的字会落进你们俩这条对话里。也可以再用 her_say 把它记进你自己的流水(refs 指回上面真实发生的事,1–6 条 id)。不想说,就什么都别写:不要写任何字,也不要解释为什么不说——这一轮没有回复也算正常。')
382
+ // 动手回合(2026-11-14):只多给一句许可,不换掉上面「也可以不说」的边界。
383
+ // 只在她的记录里点到过某件手边工具时才点名,不列全量清单(用户 m01618)。
384
+ if (doing) lines.push(doingSection({ material, loose, tools, notes }))
378
385
  return fillOwner(lines.join('\n'))
379
386
  }
380
387
 
@@ -407,7 +414,7 @@ export async function writeSay(root, { text = '', refs = [], sessionId = '', why
407
414
 
408
415
  const { config } = await loadConfig(root)
409
416
  const cfg = proactiveConfig(config)
410
- const dk = dateKey(new Date(now))
417
+ const dk = wakeDayKey(config, new Date(now))
411
418
  // 2026-11-06(issue #41):说明书与设置页都写着「一天最多几次」、到了上限就说不出去,
412
419
  // 但这里原来读了 config 根本没看——maxPerDay 设 0 也能一句接一句地写。
413
420
  // 现在按她自己记下的 `proactive-say:` 数到位就停。开关(enabled)只管「要不要自己开一轮」,
package/lib/recall.js CHANGED
@@ -40,6 +40,8 @@ import { dateKey } from './settings.js'
40
40
  import { anchorOf } from './anchor.js'
41
41
  import { parseWatchedLine, parseLookLine } from './whatseen.js'
42
42
  import { fillOwner } from './pronoun.js'
43
+ import { readNotes } from './note.js'
44
+ import { readAppointments } from './appoint.js'
43
45
 
44
46
  import { defineTool } from './tool.js'
45
47
 
@@ -57,6 +59,16 @@ export const RECALL_SNIPPET = 200
57
59
  export const RECALL_BRIEF_SNIPPET = 40
58
60
  /** 默认往回翻多少天;0 = 全部 */
59
61
  export const RECALL_DAYS = 0
62
+ /**
63
+ * 一次最多并进来几条便条/约定(2026-11-14)。
64
+ *
65
+ * 事件流是她的经历,便条与约定是她的**操作层**。这两层以前各记各的:
66
+ * 她翻回忆只翻事件流,于是在群里被问「那件事你做完了吗」时只看到「我打算做」。
67
+ * 并进来是为了让她翻到「后来我自己划掉了」,不是把本子整个倒出来——所以只给 3 条。
68
+ */
69
+ export const RECALL_OPS_MAX = 3
70
+ /** 便条/约定那一行的字数上限。 */
71
+ export const RECALL_OPS_SNIPPET = 80
60
72
 
61
73
  /** 参与排序加权的类型:这些事件引用了某一条,说明那条被检验/修正/回答过 */
62
74
  const REF_TYPES = new Set(['test', 'answer', 'revise'])
@@ -168,6 +180,19 @@ function matOf(ev) {
168
180
  }
169
181
  const isMatLine = (ev) => Boolean(matOf(ev))
170
182
 
183
+ /**
184
+ * 第三类放行的 meta:她真的动过手(2026-11-14,用户 m01618)。
185
+ *
186
+ * `use:` 只包得住插件自己的 12 件工具;别人放行的写代码/看小说/玩游戏工具
187
+ * 她用了也不会留下 `use:`。`did:` 是动手回合里按 tools/result 写的账,
188
+ * 记的是「这件事是用哪件工具做的、成没成」——不放行的话,她做完就翻不到,
189
+ * 「做过 → 记得 → 下次还做」这条回路是断的。
190
+ *
191
+ * 形状见 lib/doing.js:`did:<cls>:<tool>:ok|fail:<key>`。
192
+ */
193
+ export const DID_LINE = /^did:(?:produce|consume|effect|self):([^:\s]+):(ok|fail):([\s\S]*)$/
194
+ const isDidLine = (ev) => ev?.type === 'meta' && DID_LINE.test(String(ev?.text ?? '').trim())
195
+
171
196
  /** 2026-11-13 → 11 月 13 日;不是这个形状就原样返回。 */
172
197
  function mmdd(dk) {
173
198
  const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(dk)
@@ -175,7 +200,7 @@ function mmdd(dk) {
175
200
  }
176
201
 
177
202
  /** 这条事件进不进回忆。 */
178
- const usable = (ev) => Boolean(ev) && (!SKIP_TYPES.has(ev.type) || isUseLine(ev) || isSeenLine(ev) || isMatLine(ev))
203
+ const usable = (ev) => Boolean(ev) && (!SKIP_TYPES.has(ev.type) || isUseLine(ev) || isSeenLine(ev) || isMatLine(ev) || isDidLine(ev))
179
204
 
180
205
  const DAY_MS = 86_400_000
181
206
 
@@ -234,6 +259,16 @@ function labelled(type, text, scene = '') {
234
259
  }
235
260
  const seen = seenOf({ type, text })
236
261
  if (seen) return seenLabel(seen)
262
+ // 她真的动过手(2026-11-14,用户 m01618):`did:` 记的是工具名与做成/没成,
263
+ // 翻出来要能当「我做过这件事」用,不能还是机器写法。
264
+ const d = DID_LINE.exec(text)
265
+ if (d) {
266
+ const [, tool, head, rawKey] = d
267
+ const key = String(rawKey ?? '').trim()
268
+ const shown = key.startsWith(`${tool}:`) ? key.slice(tool.length + 1) : key
269
+ if (head === 'fail') return `你用 ${tool} 试过${shown ? `:${shown}` : '一件事'},没成`
270
+ return `你用 ${tool} 做成了一件事${shown ? `:${shown}` : ''}`
271
+ }
237
272
  const m = USE_LINE.exec(text)
238
273
  if (m) {
239
274
  const [, tool, head, said] = m
@@ -479,7 +514,10 @@ export function searchEvents(events, query, o = {}) {
479
514
  if (!text) continue
480
515
  const ts = Date.parse(ev.ts)
481
516
  if (!Number.isFinite(ts) || ts < since) continue
482
- cand.push({ ev, text, ts, lower: text.toLowerCase() })
517
+ // 话题标签也算进可搜的字里(2026-11-15 m01412):她给一句判断打上「规矩」,
518
+ // 换了一间房子再搜「规矩」就该翻得到——否则那个标签只是个摆设。
519
+ const topic = String(ev.topic ?? '').trim()
520
+ cand.push({ ev, text, ts, lower: (topic ? `${text} ${topic}` : text).toLowerCase() })
483
521
  }
484
522
 
485
523
  // df:这批候选里有多少条出现过这个词。见 idfWeight() 上面那段。
@@ -565,11 +603,22 @@ export function searchEvents(events, query, o = {}) {
565
603
  kept.push(s)
566
604
  }
567
605
 
568
- // 改口关系不受 days、kind 影响:被改的那句在时间窗外,也照样引出来。
606
+ // 改口关系与「补丁」都要按 id 回查原话:只要有一条带 re 的 heard,就得建表。
569
607
  const byId = new Map()
570
- if (revisions.size) {
571
- for (const ev of events ?? []) if (usable(ev)) byId.set(String(ev.id), ev)
608
+ for (const ev of events ?? []) if (usable(ev)) byId.set(String(ev.id), ev)
609
+ // 补丁表:被接的那条 id → 最新一条接在它后面的短状态句(见 lib/hear.js 的 latestHeardId)。
610
+ const patchOf = new Map()
611
+ for (const ev of byId.values()) {
612
+ if (String(ev.type ?? '') !== 'heard' || !ev.re) continue
613
+ const key = String(ev.re)
614
+ const prev = patchOf.get(key)
615
+ if (!prev || (Date.parse(String(ev.ts ?? '')) || 0) >= (Date.parse(String(prev.ts ?? '')) || 0)) patchOf.set(key, ev)
572
616
  }
617
+ const when = (ev) => {
618
+ const t = Date.parse(String(ev?.ts ?? ''))
619
+ return Number.isFinite(t) ? { date: dateKey(new Date(t)), clock: localClock(t) } : { date: '', clock: '' }
620
+ }
621
+ const plain = (ev) => clip(oneLine(String(ev?.text ?? '')), snippet)
573
622
  const said = (ev, verdict) => ({
574
623
  id: String(ev.id ?? ''),
575
624
  verdict: verdict ?? null,
@@ -609,6 +658,14 @@ export function searchEvents(events, query, o = {}) {
609
658
  // her_recall 不能按 id 查——只给 id 她翻不到,等于还得猜。
610
659
  ...(last ? { later: said(last, last === next ? next.verdict : null) } : {}),
611
660
  ...(earlier ? { earlier: said(earlier, ev.verdict) } : {}),
661
+ // 短状态句接的那句旧话,以及接在这条后面的最新一句短状态(2026-11-14,用户 m00533 的 ②)。
662
+ // 只在有链接时出现;老事件没有 re,什么都不变。
663
+ ...(ev.re && byId.get(String(ev.re))
664
+ ? { reTo: { ...when(byId.get(String(ev.re))), text: plain(byId.get(String(ev.re))) } }
665
+ : {}),
666
+ ...(patchOf.get(String(ev.id))
667
+ ? { patched: { ...when(patchOf.get(String(ev.id))), text: plain(patchOf.get(String(ev.id))) } }
668
+ : {}),
612
669
  // issue #133:seen 行先翻成人话再截断。`look:`/`watched:` 后面挂着整段
613
670
  // JSON,先截再翻会把标题连 JSON 一起截坏,brief 档里只剩一个 BV 号。
614
671
  text: fillOwner(clip(oneLine(seen ? seenLabel(seen) : text), snippet)),
@@ -637,6 +694,65 @@ function relationLines(r, brief) {
637
694
  return out
638
695
  }
639
696
 
697
+ /**
698
+ * 在便条与预约簿里找(2026-11-14,用户 m00242 第二个反馈)。
699
+ *
700
+ * 起因:她定了一张卡、做完划掉、还写了日记;换会话后她又把这事提了一遍,
701
+ * 一问才知道「只看了事件流」。三处都记着,换会话只读其中一处——
702
+ * 因为便条/约定**故意不进事件流**(`lib/note.js:30-32`),而 her_recall 只翻事件流。
703
+ *
704
+ * 口径:
705
+ * - 只并进来命中关键词的那几条,最多 3 条;不是把本子整个倒出来(那等于读档)。
706
+ * - 关掉的那些要标出来「后来你自己划掉了」——这一句才是这次要补的东西。
707
+ * - 纯函数:读盘由 registerRecall 做,测试可以直接喂 fixture。
708
+ *
709
+ * @param {{notes?:object[], appointments?:object[]}} store readNotes/readAppointments 的结果
710
+ * @param {string} query 她给的关键词
711
+ * @returns {string[]} 每行一句;没有命中就是空数组
712
+ */
713
+ export function searchOps({ notes = [], appointments = [] } = {}, query, { now = Date.now(), limit = RECALL_OPS_MAX, days = 0 } = {}) {
714
+ const toks = tokensOf(query).filter((t) => t.length >= 2)
715
+ if (!toks.length) return []
716
+ const hit = (text) => {
717
+ const low = String(text ?? '').toLowerCase()
718
+ return toks.some((t) => low.includes(t))
719
+ }
720
+ const msOf = (v) => {
721
+ const ms = Date.parse(String(v ?? ''))
722
+ return Number.isFinite(ms) ? ms : NaN
723
+ }
724
+ const md = (ms) => mmdd(dateKey(new Date(ms)))
725
+ const rows = []
726
+ for (const n of notes ?? []) {
727
+ if (!n || !hit(n.text)) continue
728
+ const closed = String(n.status ?? 'open') !== 'open'
729
+ const raw = closed ? msOf(n.closedAt) : msOf(n.created)
730
+ const at = Number.isFinite(raw) ? raw : Number(now)
731
+ const line = n.status === 'done'
732
+ ? `你记着「${n.text}」——后来你自己划掉了(${md(at)})`
733
+ : n.status === 'dropped'
734
+ ? `你记着「${n.text}」——后来你放下了`
735
+ : `你记着「${n.text}」(便条上,还没划掉)`
736
+ rows.push({ at, line })
737
+ }
738
+ for (const a of appointments ?? []) {
739
+ if (!a || !hit(a.what)) continue
740
+ const closed = String(a.status ?? 'open') !== 'open'
741
+ const raw = closed ? msOf(a.closedAt) : msOf(a.created)
742
+ const at = Number.isFinite(raw) ? raw : Number(now)
743
+ const line = a.status === 'done'
744
+ ? `你和{T}约的「${a.what}」——已经做完了(${md(at)})`
745
+ : a.status === 'cancelled'
746
+ ? `你和{T}约的「${a.what}」——后来你取消了`
747
+ : `你和{T}约的「${a.what}」(日子是 ${a.due},还没到)`
748
+ rows.push({ at, line })
749
+ }
750
+ rows.sort((x, y) => y.at - x.at)
751
+ const lim = Math.max(1, Math.min(RECALL_OPS_MAX, Number(limit) || RECALL_OPS_MAX))
752
+ const kept = Number(days) > 0 ? rows.filter((r) => r.at >= Number(now) - Number(days) * DAY_MS) : rows
753
+ return kept.slice(0, lim).map((r) => clip(oneLine(r.line), RECALL_OPS_SNIPPET))
754
+ }
755
+
640
756
  /**
641
757
  * 渲染成她能读的一段(不是 JSON)
642
758
  *
@@ -647,13 +763,18 @@ function relationLines(r, brief) {
647
763
  * 3. 聊天里随口说的标出来。不是不许看,是要让她知道自己当时不是在记东西。
648
764
  */
649
765
  export function renderRecall(rows, o = {}) {
650
- if (!rows?.length) return '你翻了,没翻到。'
766
+ // 便条/约定那几行(searchOps,2026-11-14):事件流一条都没命中也可能有——
767
+ // 那正是这次要补的洞,所以不能因为 rows 空就回「没翻到」。
768
+ const ops = Array.isArray(o.ops) ? o.ops.filter(Boolean) : []
769
+ if (!rows?.length && !ops.length) return '你翻了,没翻到。'
651
770
  const brief = Boolean(o.brief)
652
771
  // 时间线和她给了词的翻找要分开说:前者是「最近这些」,后者才是「你翻到的」。
653
772
  // 混用会让她以为没给关键词也能命中什么。
654
- const head = brief
655
- ? '有这些(只报了开头,要看全的再说一次):'
656
- : (o.timeline ? '最近这些(从近到远摆的):' : '你翻到的:')
773
+ const head = !rows?.length
774
+ ? '你翻了,事件流里没翻到。'
775
+ : brief
776
+ ? '有这些(只报了开头,要看全的再说一次):'
777
+ : (o.timeline ? '最近这些(从近到远摆的):' : '你翻到的:')
657
778
  const lines = [head]
658
779
  for (const r of rows) {
659
780
  // id 用小括号挂在最后:她要 revise / narration 时原样抄进来。
@@ -678,6 +799,22 @@ export function renderRecall(rows, o = {}) {
678
799
  body += to ? `(${how} ${to},那是更早说的)` : `(${how},那是更早说的)`
679
800
  }
680
801
  lines.push(`- ${at}${ago}|${body}${mark}`, ...relationLines(r, brief))
802
+ // 短状态句(「好了」「不胀了」)自己看不出在说什么:把它接的那句旧话一并摆出来。
803
+ // 反过来,旧话那行也带上后来那句,免得她翻到「肚子胀」就以为还没好(用户 m00242 原话)。
804
+ if (!brief && r.reTo?.text) {
805
+ lines.push(` 接的是{T}说过的「${r.reTo.text}」${r.reTo.date ? `(${r.reTo.date})` : ''}`)
806
+ }
807
+ if (!brief && r.patched?.text) {
808
+ const at2 = r.patched.date ? `${r.patched.date}${r.patched.clock ? ` ${r.patched.clock}` : ''},` : ''
809
+ lines.push(` ${at2}{T}后来接着说:${r.patched.text}`)
810
+ }
811
+ }
812
+ // 便条与约定单独一段:它们不是事件流里的事,混在她自己的话里会把「来源」抹掉。
813
+ if (ops.length) {
814
+ lines.push(
815
+ rows?.length ? '另外,你自己的本子上记着(便条与约定):' : '不过你自己的本子上记着(便条与约定):',
816
+ ...ops.map((s) => `- ${s}`),
817
+ )
681
818
  }
682
819
  // issue #133 的 B:这里只摆了 top-k,原来什么都不说,于是「没翻到 / 只翻到这几条」
683
820
  // 被她读成「没有这回事」,还会被复述出去。不报条数(报数字等于催她再翻一次),
@@ -731,7 +868,19 @@ export function registerRecall(ctx, deps = {}) {
731
868
  // 渲染层不必再按栏位切一刀(两处口径会打架)。
732
869
  snippet: brief ? RECALL_BRIEF_SNIPPET : RECALL_SNIPPET,
733
870
  })
734
- return { found: rows.length > 0, text: renderRecall(rows, { brief, total, truncated, timeline }) }
871
+ // 她的本子(便条、约定)不进事件流,是她自己的操作层:
872
+ // 她说"我只翻了事件流"时,就是这里没查。只在没限 kind 时并进来。
873
+ const ops = args?.kind
874
+ ? []
875
+ : searchOps(
876
+ { notes: await readNotes(root), appointments: await readAppointments(root) },
877
+ args?.query,
878
+ { days: args?.days },
879
+ )
880
+ return {
881
+ found: rows.length > 0 || ops.length > 0,
882
+ text: renderRecall(rows, { brief, total, truncated, timeline, ops }),
883
+ }
735
884
  } catch {
736
885
  // 翻不动就说翻不动,不要装作记得
737
886
  return { found: false, text: '你翻了,没翻到。' }
package/lib/report.js CHANGED
@@ -14,8 +14,10 @@
14
14
 
15
15
  import { promises as fs } from 'node:fs'
16
16
  import { join } from 'node:path'
17
- import { paths, writeAtomic, readEvents, readDaily } from './store.js'
17
+ import { paths, writeAtomic, readEvents, readDaily, readConfig } from './store.js'
18
18
  import { dateKey } from './settings.js'
19
+ // 她自己的第三人称(1.0.1,issue #139):只填固定标题里的 {S},不碰引用的原话。
20
+ import { normalizeSelfPronoun, fillSelf } from './selfpronoun.js'
19
21
 
20
22
  /** 她的话(可引用进报告的):只取 HER_TYPES,meta 一律不进正文 */
21
23
  const QUOTABLE = new Set(['utterance', 'revise', 'reunion', 'narration', 'refusal', 'answer'])
@@ -129,6 +131,8 @@ function lineOf(item, i) {
129
131
  */
130
132
  export function buildReport(o = {}) {
131
133
  const dk = o.dateKey ?? dateKey()
134
+ // 旁观者视角的固定标题用 {S};引用的原话(quotes/chat)一条都不经过它。
135
+ const SHE = normalizeSelfPronoun(o.selfPronoun)
132
136
  const seen = o.seen ?? { watched: [], glanced: Array.isArray(o.items) ? o.items : [], handed: [] }
133
137
  const watched = Array.isArray(seen.watched) ? seen.watched : []
134
138
  const glanced = Array.isArray(seen.glanced) ? seen.glanced : []
@@ -162,7 +166,7 @@ export function buildReport(o = {}) {
162
166
  if (handed.length) {
163
167
  L.push('## 你递过来的')
164
168
  L.push('')
165
- L.push('_递到她手上了,她还没看。_')
169
+ L.push(fillSelf('_递到{S}手上了,{S}还没看。_', SHE))
166
170
  L.push('')
167
171
  for (const it of handed) {
168
172
  L.push(`- **[${it.bvid}](https://www.bilibili.com/video/${it.bvid})**`)
@@ -170,7 +174,7 @@ export function buildReport(o = {}) {
170
174
  L.push('')
171
175
  }
172
176
 
173
- L.push('## 她说了什么')
177
+ L.push(fillSelf('## {S}说了什么', SHE))
174
178
  L.push('')
175
179
  if (quotes.length) {
176
180
  for (const q of quotes) {
@@ -183,7 +187,7 @@ export function buildReport(o = {}) {
183
187
  } else {
184
188
  // 不能一律写「今天她什么都没说」——她可能只是在对话里说过,没认领下来,
185
189
  // 那样印出来的是一句假话。两种情形要分开说。
186
- L.push(chat.length ? '这一节今天是空的,聊天时说的在下面。' : '今天她什么都没说。')
190
+ L.push(chat.length ? '这一节今天是空的,聊天时说的在下面。' : fillSelf('今天{S}什么都没说。', SHE))
187
191
  L.push('')
188
192
  }
189
193
 
@@ -195,7 +199,7 @@ export function buildReport(o = {}) {
195
199
  if (chat.length) {
196
200
  L.push('## 聊天时说过的')
197
201
  L.push('')
198
- L.push('_她在对话里说出口的话。_')
202
+ L.push(fillSelf('_{S}在对话里说出口的话。_', SHE))
199
203
  L.push('')
200
204
  for (const q of chat.slice(-REPORT_CHAT_LINES)) {
201
205
  // 换行会把「一行一段」压坏;按 UTF-16 截时别把 emoji 切成半个。
@@ -215,7 +219,7 @@ export function buildReport(o = {}) {
215
219
  // 日记:默认不出现。只有配置里 visible=true 才贴进来。
216
220
  // 注意这里读的是 diary/ 目录,不是事件流——日记压根不进事件流(见 capture.js)。
217
221
  if (o.diaryVisible && o.diary) {
218
- L.push('## 她的日记')
222
+ L.push(fillSelf('## {S}的日记', SHE))
219
223
  L.push('')
220
224
  L.push(o.diary.trim())
221
225
  L.push('')
@@ -224,7 +228,7 @@ export function buildReport(o = {}) {
224
228
  if (Array.isArray(o.notes) && o.notes.length) {
225
229
  L.push('---')
226
230
  L.push('')
227
- L.push('### 抓取备注(不是她的话)')
231
+ L.push(fillSelf('### 抓取备注(不是{S}的话)', SHE))
228
232
  for (const n of o.notes) L.push(`- ${n}`)
229
233
  L.push('')
230
234
  }
@@ -255,9 +259,12 @@ export async function flushReport(root, o = {}) {
255
259
  const dk = o.dateKey ?? dateKey()
256
260
  try {
257
261
  const { events } = await readEvents(root)
262
+ // 固定标题里的 {S}:读不到配置就按默认「她」,不影响落盘。
263
+ const cfg = await readConfig(root).catch(() => null)
258
264
  const diary = o.diary !== undefined ? o.diary : await readDaily('diaryDir', dk, root).catch(() => null)
259
265
  const md = buildReport({
260
266
  dateKey: dk,
267
+ selfPronoun: cfg?.self?.pronoun,
261
268
  items: o.items ?? [],
262
269
  // 不传 seen 时按旧口径(items = 翻到过)走,老调用方不炸。
263
270
  seen: o.seen ?? { watched: [], glanced: o.items ?? [], handed: [] },
package/lib/say.js CHANGED
@@ -30,7 +30,7 @@ import { loadConfig, dateKey } from './settings.js'
30
30
  import { deriveSelf } from './derive.js'
31
31
  import { writeInboxFile, newHerEventsSince } from './inbox.js'
32
32
  import { assistantText } from './turns.js'
33
- import { bumpTurns, rotateTalkSession, talkSessionId, homeStatus } from './home.js'
33
+ import { bumpTurns, rotationHold, rotateTalkSession, talkSessionId, homeStatus } from './home.js'
34
34
  import { addExchange } from './talkmem.js'
35
35
  import { hearTurn, rememberGroupWord } from './hear.js'
36
36
  import { slashed } from './posix.js'
@@ -556,7 +556,15 @@ export async function sayToHer(ctx, text, deps = {}) {
556
556
  ).catch(() => null)
557
557
  }
558
558
  const rotateAfter = Number(config?.chat?.rotateAfter ?? 0)
559
- if (atHome && rotateAfter > 0 && turns >= rotateAfter) {
559
+ // 「等说完再换」(2026-11-15,用户 m00648):和 turns 结账那条路同一套判据——
560
+ // 上一轮刚说过话就先不换,最多再延 ROTATE_GRACE_TURNS 轮。
561
+ const hold = atHome && rotateAfter > 0 && turns >= rotateAfter
562
+ ? await rotationHold(root, { turns, rotateAfter })
563
+ : null
564
+ if (hold) {
565
+ log(`say · 聊满 ${turns} 轮,但上一轮才隔了 ${Math.round(hold.gap / 60000)} 分钟,先不换;宽限还剩 ${hold.graceLeft} 轮`)
566
+ }
567
+ if (atHome && rotateAfter > 0 && turns >= rotateAfter && !hold) {
560
568
  // from:这句话落在哪条会话里。另一条入口(turns 结账)抢先换过的话,
561
569
  // Home 会拿这个 id 和 home.json 比对,直接跳过,不再多建一条(0.8.8)。
562
570
  const rot = await rotateTalkSession(ctx, { root, wsId: deps.wsId, log, from: sessionId })