@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
@@ -0,0 +1,123 @@
1
+ /**
2
+ * turnexport.js —— 把「这一轮她读到的身份文档」导出成一份 markdown
3
+ *
4
+ * 为什么要有这个(2026-11-13,用户 m04163 认可缩小后的版本):
5
+ * 她每说一句话,背后同时有判断、疤、原话、素材、八股锚在供料,而身份文档的
6
+ * 字数是有上限的(默认 2400 字)。超了怎么办?**整段不塞,不是截断**——
7
+ * 所以「她为什么没提到我上周说的那件事」的答案,很可能只是那一段被挤掉了。
8
+ * 这一点在界面上看不出来,只能把「这一轮的账」摊开给人看。
9
+ *
10
+ * 做成文件而不是面板,是为了守住「没有人格设置界面」:文件是死的,只能读。
11
+ * 一旦做成面板,下一步就会有人想加「删掉她这条判断」的按钮,那就绕过事件流了。
12
+ *
13
+ * 两件事刻意不做:
14
+ * · 不往她的提示词里加任何东西(这份文件她读不到)
15
+ * · 不改人格逻辑(只读现成的 persona 装配结果)
16
+ *
17
+ * 谁调它:`GET /dsh-fish/turn/export`(设置页「说话」那一节底下的一颗只读按钮)。
18
+ */
19
+
20
+ import { promises as fs } from 'node:fs'
21
+ import { join } from 'node:path'
22
+ import { rootDir, paths, readEvents, writeAtomic } from './store.js'
23
+ import { loadConfig } from './settings.js'
24
+ import { deriveSelf } from './derive.js'
25
+ import { buildSections, assembleWithPlan, SELF_DOC_BUDGET } from './persona.js'
26
+ import { selfDocPath, writeSelfDoc, continuityOf } from './selfdoc.js'
27
+ import { pronounOf } from './pronoun.js'
28
+
29
+ const pad = (n) => String(n).padStart(2, '0')
30
+
31
+ /** 文件名用的本地时刻:20261113-2315。用本地时间,因为人看的是本机的钟。 */
32
+ export function turnStamp(now = new Date()) {
33
+ return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}`
34
+ }
35
+
36
+ const human = (now) => `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}`
37
+
38
+ /**
39
+ * 写一份 `out/turn-<时间戳>.md`。
40
+ *
41
+ * 先 `writeSelfDoc(root)` 再读文件:身份文档是派生物,落盘时才顺手重算;
42
+ * 这样导出里的原文与「她此刻真读到的那份」是同一份,不是另算一遍。
43
+ * 记账那部分(哪些段被裁)用 persona 装配时的同一套计算,避免两套数字。
44
+ *
45
+ * 永不抛:导出是调试用的旁路,失败只回报原因,不打断调用方。
46
+ */
47
+ export async function writeTurnExport(root = rootDir(), now = new Date()) {
48
+ const stamp = turnStamp(now)
49
+ const file = join(paths(root).outDir, `turn-${stamp}.md`)
50
+ try {
51
+ await writeSelfDoc(root)
52
+
53
+ let text = ''
54
+ try {
55
+ text = await fs.readFile(selfDocPath(root), 'utf8')
56
+ } catch {
57
+ // 第一次还没写出身份文件:下面照常出账,原文留空并说明。
58
+ }
59
+
60
+ const { events } = await readEvents(root)
61
+ const { config } = await loadConfig(root)
62
+ const model = deriveSelf(events, { growthDays: config.growthDays })
63
+ const sections = buildSections(model, {
64
+ budget: config?.memory?.docBudget,
65
+ shown: config?.memory?.beliefsShown,
66
+ sleepKeep: config?.memory?.sleepKeep,
67
+ echo: config?.memory?.echo !== false,
68
+ anchor: config?.chat?.anchor === true,
69
+ pronoun: pronounOf(config),
70
+ continuity: await continuityOf(root, now.getTime(), events),
71
+ // 导进来的这一位跳过我方那两条提示词禁令(与 writeSelfDoc 同一判定:只看 model)
72
+ withBans: model?.persona?.imported !== true,
73
+ now: now.getTime(),
74
+ })
75
+ const budget = Number(config?.memory?.docBudget ?? SELF_DOC_BUDGET)
76
+ const plan = assembleWithPlan(sections, budget)
77
+ const dropped = plan.plan.filter((s) => !s.kept)
78
+
79
+ const rows = plan.plan
80
+ .map((s) => `| ${s.label} | ${s.chars} | ${s.keep ? '核心(必留)' : s.kept ? '保留' : '**裁掉**'} |`)
81
+ .join('\n')
82
+
83
+ const md = [
84
+ '# 这一轮,她读到的身份文档',
85
+ '',
86
+ `导出于 ${human(now)}(本机时间)。`,
87
+ '',
88
+ `**预算**:用了 ${plan.used} / ${plan.budget} 字;留下 ${plan.kept} 段,裁掉 ${dropped.length} 段。`,
89
+ '',
90
+ '## 每段去了哪',
91
+ '',
92
+ '| 段 | 字数 | 结果 |',
93
+ '| --- | --- | --- |',
94
+ rows,
95
+ '',
96
+ dropped.length
97
+ ? '被裁掉的段是**整段不塞**,不是截断——那几句她这一轮完全没看到。'
98
+ : '这一轮没有段被裁掉:预算够,所有段都塞进去了。',
99
+ '',
100
+ '## 原文',
101
+ '',
102
+ '下面这一份和她这一轮读到的逐字相同(也就是 `她的身份.md` 本身)。',
103
+ '',
104
+ '---',
105
+ '',
106
+ text || '(这一次还没写出身份文件。)',
107
+ '',
108
+ ].join('\n')
109
+
110
+ await writeAtomic(file, md)
111
+ return {
112
+ ok: true,
113
+ file,
114
+ used: plan.used,
115
+ budget: plan.budget,
116
+ kept: plan.kept,
117
+ total: plan.plan.length,
118
+ dropped: dropped.map((s) => s.label),
119
+ }
120
+ } catch (e) {
121
+ return { ok: false, why: String(e?.message || e), file }
122
+ }
123
+ }
package/lib/turns.js CHANGED
@@ -294,10 +294,15 @@ export function classifyMessage(data) {
294
294
  if (MACHINE_KINDS.has(kind) || kind.startsWith('plugin:')) return 'context'
295
295
  if (MACHINE_FORMS.has(src.form)) return 'context'
296
296
  const rid = String(src.rpcId ?? '')
297
- if (rid && PLUGIN_RPC.test(rid)) return 'plugin'
298
297
  // 桥登记过这条 requestId 的来历,就按它说的算(2026-11-09,issue #96)。
299
298
  // 这一条必须排在「带 rpcId 就当人」前面:prompt() 送来的群聊和定时提醒
300
299
  // 也只有 rpcId 能认,不查登记就全被算成他本人。
300
+ //
301
+ // 2026-11-13(外部反馈:QQ 上说的话没进记忆):还得排在**插件前缀**前面。
302
+ // 桥给群友的话用 `sys-` 开头做记号(下标在主人在场里那几个非主人场景),
303
+ // 而前缀表里恰好也有 `sys`(0.9.1 加进去挡宿主自己的机器回合);先扫前缀
304
+ // 的话,桥前一步刚登记的 rpcId 永远轮不到,那条消息连一行日志都没有地消失。
305
+ // 登记是更窄的判据(只有桥自己报上来的 id 才在里面),所以先看它。
301
306
  const decl = rid ? declaredFor(rid) : null
302
307
  if (decl) {
303
308
  if (decl.machine) return 'plugin'
@@ -305,6 +310,7 @@ export function classifyMessage(data) {
305
310
  if (decl.scene === 'group') return decl.owner ? 'group-owner' : 'group'
306
311
  return 'human'
307
312
  }
313
+ if (rid && PLUGIN_RPC.test(rid)) return 'plugin'
308
314
  if (kind === 'user') {
309
315
  // 客户端(桌面/网页侧栏)打的字一定带时区——宿主从浏览器那边取的。
310
316
  // 桥走宿主 prompt 时不带时区,但每条都有 rpcId(宿主把 kind 写死成
@@ -583,9 +589,29 @@ export function registerTurns(ctx, deps = {}) {
583
589
  // (home.js 的 rotateTalkSession 第 4 步),但**换会话那一刻已经在说话的人**
584
590
  // 不会因为新会话出现了就自动搬过去,所以这里必须认回来。
585
591
  //
586
- // 判据宁窄勿宽:只认「home.json 记着的、刚被换下来的那条」(rotatedFrom)。
587
- // 不认任意会话——认宽了等于谁在别处跟她说一句都能把她的家搬走。
588
- if (!home.rotatedFrom || home.rotatedFrom !== sessionId) {
592
+ // 判据宁窄勿宽:只认「home.json 记着的那一对」——刚被换下来的那条
593
+ // (rotatedFrom)与这次轮换**建出来**的那条(rotatedTo)。不认任意会话:
594
+ // 认宽了等于谁在别处跟她说一句都能把她的家搬走。
595
+ //
596
+ // 2026-11-13(外部反馈:轮换后「家」停在旧会话,自动醒落回旧对话):
597
+ // 换房那一刻他还在旧窗口里说话,下面那支会把家认回旧会话;之后他搬进
598
+ // 新会话聊了一整夜,却没有依据把家跟过去——新会话在插件眼里只是
599
+ // 「认识的会话之外的动静」,自动醒照着 home.json 叫回旧对话(383K tok 那条)。
600
+ // 现在轮换对称记下 rotatedTo:他在那条里说话,家就跟过去。
601
+ // 这条判据比 rotatedFrom 更窄——这个 id 只可能是轮换自己建的。
602
+ const isRotatedTo = Boolean(home.rotatedTo) && home.rotatedTo === sessionId
603
+ const isRotatedFrom = Boolean(home.rotatedFrom) && home.rotatedFrom === sessionId
604
+ if (isRotatedTo) {
605
+ // 不限时:这条会话是轮换替他开的新房间,他在里头说话,家在哪儿都是错的。
606
+ // 代价上限是「家搬进了一间本来就该住人的房」;这一对只在下次轮换时被换掉。
607
+ const ok = await adoptTalkSession(root, sessionId)
608
+ log(
609
+ ok
610
+ ? `turns · 他搬进轮换新开的那条会话里说话,屋子跟过去(${sessionId})`
611
+ : `turns · 他搬进轮换新开的那条会话里说话,但屋子没跟过去(${sessionId})`,
612
+ )
613
+ if (!ok) return
614
+ } else if (!isRotatedFrom) {
589
615
  // 2026-11-03(issue #18):这不再是「什么都不做」。
590
616
  //
591
617
  // 外渠道(QQ 桥 / 别的桥)按我们的桥接约定**自己建 DSH 会话**(AGENTS.md §7),
@@ -621,34 +647,54 @@ export function registerTurns(ctx, deps = {}) {
621
647
  if (fromDeskClient) {
622
648
  const herRoom = await isChannelSession(root, sessionId).catch(() => false)
623
649
  if (!herRoom) return
650
+ } else if (srcKind === 'user') {
651
+ // 2026-11-13(用户 m01538 报的:两天没主动找她,冷落钟还是被清了):
652
+ // 宿主里别的插件也会往**自己的**会话里塞 kind:'user' 的消息——dsh-auto-memory
653
+ // 的「记忆中枢」会话初始化、定时任务、子代理 prompt 全是这个形状:带 rpcId、
654
+ // 没有 clientTimeZone。老判法把它们当成他本人,一写 seen 冷落钟就归零;
655
+ // 真机上就是 11-13 00:00:40 那条「记忆中枢 · 初始化」把 48 小时的等待清掉了。
656
+ //
657
+ // 桥走 prompt() 时同样是 kind:'user',但桥必须在发之前登记 rpcId
658
+ // (AGENTS.md §7.2 第 6 条);认不出来的那些退回老判法会把插件当成他。
659
+ // 所以这里只放两种过去:桌面客户端亲手打的(上面那支),和桥登记过的。
660
+ const rid = String(src.rpcId ?? '')
661
+ if (!rid || !declaredFor(rid)) {
662
+ const now = Date.now()
663
+ if (now - (unknownLoggedAt.get('injected') ?? 0) > 60 * 60_000) {
664
+ unknownLoggedAt.set('injected', now)
665
+ log(`turns · 有插件往别的会话里塞了 prompt,不是他(${sessionId})`)
666
+ }
667
+ return
668
+ }
624
669
  }
625
670
  if (Date.now() - lastSeenAt > 60_000) {
626
671
  await markSeen()
627
672
  log(`turns · 认识的会话之外的动静,只记他来过(${sessionId})`)
628
673
  }
629
674
  return
630
- }
631
- // 认回也要看时候(2026-11-10,用户反馈「换会话又落回旧的老会话」):
632
- // `rotatedFrom` 会一直留到下一次轮换,不设窗口的话,他几天后翻回那条
633
- // 「…之前」随口说一句,屋子就搬回去,`turns` 还是新会话的 0——
634
- // 那条已经满 40 轮的会话等于又重新拿到一整段预算。
635
- const rotatedAt = Date.parse(String(home.rotatedAt ?? ''))
636
- const stillThere = Number(home.turns ?? 0) === 0
637
- || (Number.isFinite(rotatedAt) && Date.now() - rotatedAt < ADOPT_WINDOW_MS)
638
- if (!stillThere) {
639
- if (Date.now() - lastSeenAt > 60_000) {
640
- await markSeen()
641
- log(`turns · 他回到换下来那条会话里说话,但屋子已经搬走了(${sessionId})`)
675
+ } else {
676
+ // 认回也要看时候(2026-11-10,用户反馈「换会话又落回旧的老会话」):
677
+ // `rotatedFrom` 会一直留到下一次轮换,不设窗口的话,他几天后翻回那条
678
+ // 「…之前」随口说一句,屋子就搬回去,`turns` 还是新会话的 0——
679
+ // 那条已经满 40 轮的会话等于又重新拿到一整段预算。
680
+ const rotatedAt = Date.parse(String(home.rotatedAt ?? ''))
681
+ const stillThere = Number(home.turns ?? 0) === 0
682
+ || (Number.isFinite(rotatedAt) && Date.now() - rotatedAt < ADOPT_WINDOW_MS)
683
+ if (!stillThere) {
684
+ if (Date.now() - lastSeenAt > 60_000) {
685
+ await markSeen()
686
+ log(`turns · 他回到换下来那条会话里说话,但屋子已经搬走了(${sessionId})`)
687
+ }
688
+ return
642
689
  }
643
- return
690
+ const ok = await adoptTalkSession(root, sessionId)
691
+ log(
692
+ ok
693
+ ? `turns · 他还在换下来那条会话里说话,屋子认回它(${sessionId})`
694
+ : `turns · 他还在换下来那条会话里说话,但认不回来(${sessionId})`,
695
+ )
696
+ if (!ok) return
644
697
  }
645
- const ok = await adoptTalkSession(root, sessionId)
646
- log(
647
- ok
648
- ? `turns · 他还在换下来那条会话里说话,屋子认回它(${sessionId})`
649
- : `turns · 他还在换下来那条会话里说话,但认不回来(${sessionId})`,
650
- )
651
- if (!ok) return
652
698
  }
653
699
  const text = cut(stripChannelNote(messageText(data)))
654
700
  if (!text) {
package/lib/use.js CHANGED
@@ -20,6 +20,7 @@ import { similarity } from './derive.js'
20
20
  import { noteRegisteredTool } from './toolreg.js'
21
21
  import { callerInRoot } from './tenant.js'
22
22
  import { setToolUseWrap } from './tool.js'
23
+ import { fillOwner, fillOwnerDeep, primePronoun, pronounFor } from './pronoun.js'
23
24
 
24
25
  /** 一句话的上限:她在回忆里看到的是一条,不是一段。 */
25
26
  export const USE_LINE_MAX = 80
@@ -155,11 +156,28 @@ export async function recordUse(root, { tool, out, sessionId, now = Date.now() }
155
156
  export function withUse(def, { root, tool }) {
156
157
  const run = def?.execute
157
158
  if (typeof run !== 'function') return def
159
+ // 工具说明是注册期一次性交出去的(之后不会再求值),所以先按 root 把代词读进来:
160
+ // 模板里写的是 `{T}`,这里填成 他 / 她 / TA(1.0.0,issue #127 的彻底方案)。
161
+ primePronoun(root)
158
162
  // 按属性描述符复制,不用 `{ ...def }`:展开会把 getter 当场求值成死值。
159
163
  // bili_speak 的说明是 getter(随「能不能说话」现取),展开之后就定格在启动那一刻,
160
164
  // 之后开关怎么翻,她读到的说明都不变(issue #62 后续)。
161
165
  const props = Object.getOwnPropertyDescriptors(def)
162
166
  delete props.execute
167
+ // 说明与参数描述里的 `{T}` 也在这一层填:这是「注册期的一次性文本」,
168
+ // 填完就固定了;getter 说明则包一层,每次读都按当前配置填。
169
+ for (const key of ['description', 'brief']) {
170
+ const d = props[key]
171
+ if (!d) continue
172
+ if ('value' in d && typeof d.value === 'string') d.value = fillOwner(d.value, pronounFor(root))
173
+ else if (typeof d.get === 'function') {
174
+ const orig = d.get
175
+ d.get = () => fillOwner(orig.call(def), pronounFor(root))
176
+ }
177
+ }
178
+ if (props.parameters && 'value' in props.parameters) {
179
+ props.parameters.value = fillOwnerDeep(props.parameters.value, pronounFor(root))
180
+ }
163
181
  const wrapped = Object.create(Object.getPrototypeOf(def), props)
164
182
  async function execute(args, exec) {
165
183
  // 记录之前先问一句「这次调用是不是发生在这个家里」(2026-11-09 外部用户报告):
@@ -168,7 +186,9 @@ export function withUse(def, { root, tool }) {
168
186
  // 出门 / 请神那条会话仍然算她(判据在 callerInRoot 里与 checkCaller 一致)。
169
187
  const own = callerInRoot(root, exec)
170
188
  try {
171
- const out = await run(args, exec)
189
+ // 返回值里的 `{T}` 在这里填:卡片、便条回执、回忆正文都走这条出口。
190
+ // 只认这一个记号,所以返回值里她的原话、用户原话都不会被碰。
191
+ const out = fillOwnerDeep(await run(args, exec), pronounFor(root))
172
192
  if (own) await recordUse(root, { tool, out, sessionId: exec?.sessionId })
173
193
  return out
174
194
  } catch (err) {
package/lib/voices.js CHANGED
@@ -11,7 +11,8 @@
11
11
  * 2. **量要小。** 每次浏览最多留 1 条;同一句 30 天内不再出现;
12
12
  * 优先留跨视频重复出现的那句(那说明它在人群里是共识),其次高赞短句,最后才 25% 随机抽。
13
13
  * 3. **认下来才算数。** deriveSelf 会检查:这条评论出现后三天内,她有没有说过一句
14
- * 意思相近的话(similarity ≥ 0.7)。说了就叫"回声",那条 utterance 本身已经是一条判断,
14
+ * 意思相近的话(similarity ≥ 0.7,且**否定词奇偶相同**——否则「我不觉得…」会被
15
+ * 当成附和,见 2026-11-13 的反例)。说了就叫"回声",那条 utterance 本身已经是一条判断,
15
16
  * 于是它能和旧判断打架、能被固化、能进「你有两句话对不上」——**认知循环是从这里接上的**。
16
17
  *
17
18
  * 落盘类型是 `voice`(系统侧写,她写不了,不在 HER_TYPES 里):
@@ -60,6 +61,21 @@ export function voiceKey(text) {
60
61
  return normVoice(text)
61
62
  }
62
63
 
64
+ /**
65
+ * 否定词的奇偶:0 和 1 分表「肯定」「否定」两层,2 层再折回来。
66
+ *
67
+ * 为什么只数奇偶、不做句法:这里要拦的是**整句被否定掉**这一类反话,
68
+ * 不是精确语义。`不 / 没 / 别 / 未 / 甭 / 勿 / 莫` 各算一次;
69
+ * 「别人」「非常」这类会被误数(少认一次回声不伤人;
70
+ * 误认一次会把她相反的话记成附和,还要把那条评论从她眼前拿走)。
71
+ */
72
+ const NEGATION_RE = /[不没别未甭勿莫]/g
73
+
74
+ export function negationParity(text) {
75
+ const hits = String(text ?? '').match(NEGATION_RE)
76
+ return (hits?.length ?? 0) % 2
77
+ }
78
+
63
79
  /**
64
80
  * 从一轮浏览的素材包里把所有评论摊平。
65
81
  *
@@ -178,11 +194,17 @@ export async function recordVoice({ packs = [], events = [], model = {}, root, c
178
194
  *
179
195
  * 只在评论之后 ECHO_WINDOW_MS 内找她说的话,比她说过什么更重要——
180
196
  * 隔了两个月忽然说了句相似的话,那是她自己想起来的,不是被这条评论带的。
197
+ *
198
+ * 2026-11-13(外部反例,Codex 离线复现,1.0.0):光看字面相似度会把**反话**当成附和。
199
+ * 评论原话「这个游戏根本不值得买」,她留下的是「我不觉得这个游戏根本不值得买。」
200
+ * ——两句意思相反,Dice 相似度却有 0.82(阈值 0.7)。所以先比否定词的奇偶:
201
+ * 奇偶不同就不是认下,是她在跟这条评论抬杠。
181
202
  */
182
203
  export function findEcho(voice, events = []) {
183
204
  const t0 = Date.parse(voice.at ?? '')
184
205
  if (!Number.isFinite(t0)) return null
185
206
  const mine = normVoice(voice.text)
207
+ const mineNeg = negationParity(voice.text)
186
208
  // 只在**这条评论之后**的事件里找。按事件流里的先后判,不按毫秒:
187
209
  // 同一天里"先读到、后开口"时两条的 ts 可能只差几秒,甚至测试里是同一毫秒。
188
210
  const idx = events.findIndex((e) => e.id && e.id === voice.id)
@@ -193,6 +215,7 @@ export function findEcho(voice, events = []) {
193
215
  if (Array.isArray(e.flags) && e.flags.includes('uncommitted')) continue
194
216
  const t = Date.parse(e.ts ?? '')
195
217
  if (!Number.isFinite(t) || t - t0 > ECHO_WINDOW_MS) continue
218
+ if (negationParity(e.text) !== mineNeg) continue
196
219
  if (similarity(mine, normVoice(e.text)) >= ECHO_MIN_SIM) return e
197
220
  }
198
221
  return null
package/lib/wish.js CHANGED
@@ -53,6 +53,7 @@
53
53
 
54
54
  import { tsMs } from './schema.js'
55
55
  import { similarity } from './derive.js'
56
+ import { fillOwner } from './pronoun.js'
56
57
 
57
58
  /** 一次最多摆几条。多了就成了许愿清单。 */
58
59
  export const WISH_SHOW_MAX = 2
@@ -193,8 +194,8 @@ export function toolArrived(e, has) {
193
194
 
194
195
  /** 她那句话怎么收尾——只陈述结局,不给建议。 */
195
196
  export function wishTail(verdict) {
196
- if (verdict === 'approve') return '他答应了,还没见到'
197
- if (verdict === 'later') return '他说以后再说'
197
+ if (verdict === 'approve') return fillOwner('{T}答应了,还没见到')
198
+ if (verdict === 'later') return fillOwner('{T}说以后再说')
198
199
  if (verdict === 'reject') return '那次不行'
199
200
  return '你问过,还没有答复'
200
201
  }
@@ -0,0 +1,131 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1400 900" width="1400" height="900" font-family="'Noto Sans SC','PingFang SC','Microsoft YaHei',sans-serif">
2
+ <defs>
3
+ <marker id="ar" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="7" markerHeight="7" orient="auto">
4
+ <path d="M0,0 L10,5 L0,10 z" fill="#0f766e"/>
5
+ </marker>
6
+ <marker id="ar2" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="7" markerHeight="7" orient="auto">
7
+ <path d="M0,0 L10,5 L0,10 z" fill="#b45309"/>
8
+ </marker>
9
+ </defs>
10
+
11
+ <rect width="1400" height="900" fill="#faf9f7"/>
12
+
13
+ <text x="56" y="82" font-size="40" font-weight="700" fill="#1c1917">她为什么会自己动起来</text>
14
+ <text x="56" y="120" font-size="17" fill="#57534e">不是定时器推的:先慢慢攒出一股劲,再看桌上有没有真事;开口和动手是两个出口,都有刹车。</text>
15
+ <text x="56" y="146" font-size="15" fill="#9ca3af">下面每个数字都是代码里的初始值,不是心理学结论;改之前先看它原来在补什么。</text>
16
+
17
+ <!-- 左:劲从哪来 -->
18
+ <g>
19
+ <rect x="56" y="176" width="360" height="600" rx="16" fill="#ffffff" stroke="#d6d3d1"/>
20
+ <text x="80" y="212" font-size="22" font-weight="700" fill="#0f766e">劲从哪来</text>
21
+ <text x="80" y="238" font-size="14" fill="#78716c">从事件流现算,不落盘;只回答「开不开」</text>
22
+
23
+ <rect x="80" y="262" width="312" height="92" rx="10" fill="#f0fdfa" stroke="#99f6e4"/>
24
+ <text x="96" y="288" font-size="15" font-weight="700" fill="#0f766e">底噪</text>
25
+ <text x="96" y="312" font-size="14" fill="#44403c">每小时 +0.12,几周不动也会自己涨</text>
26
+ <text x="96" y="336" font-size="13" fill="#78716c">保证她不会因为「没素材」永远沉默</text>
27
+
28
+ <text x="80" y="384" font-size="15" font-weight="700" fill="#1c1917">桌上真有东西时,再加一笔</text>
29
+ <g font-size="13.5" fill="#44403c">
30
+ <rect x="80" y="398" width="312" height="34" rx="8" fill="#fafaf9" stroke="#e7e5e4"/>
31
+ <text x="94" y="420">旧句子又被想起(7–30 天前,之后再没提过)</text>
32
+ <rect x="80" y="440" width="312" height="34" rx="8" fill="#fafaf9" stroke="#e7e5e4"/>
33
+ <text x="94" y="462">她问过、但一直没答案的问题</text>
34
+ <rect x="80" y="482" width="312" height="34" rx="8" fill="#fafaf9" stroke="#e7e5e4"/>
35
+ <text x="94" y="504">你回了她留的话 / 你提到了她记着的事</text>
36
+ <rect x="80" y="524" width="312" height="34" rx="8" fill="#fafaf9" stroke="#e7e5e4"/>
37
+ <text x="94" y="546">够不着的事、撞过的墙</text>
38
+ </g>
39
+
40
+ <rect x="80" y="580" width="312" height="84" rx="10" fill="#fffbeb" stroke="#fde68a"/>
41
+ <text x="96" y="606" font-size="15" font-weight="700" fill="#b45309">上次开口,没人接</text>
42
+ <text x="96" y="630" font-size="13.5" fill="#44403c">下一次攒得慢(×0.7)</text>
43
+ <text x="96" y="650" font-size="13" fill="#78716c">打扰是有成本的,不是想说话就该说</text>
44
+
45
+ <text x="80" y="700" font-size="13" fill="#78716c">门槛 0.8,约 6.7 小时底噪攒满;</text>
46
+ <text x="80" y="722" font-size="13" fill="#78716c">攒满只说明「可以开」,不说明「必须说」。</text>
47
+ </g>
48
+
49
+ <!-- 中:这一轮开不开 -->
50
+ <g>
51
+ <rect x="452" y="176" width="440" height="600" rx="16" fill="#ffffff" stroke="#d6d3d1"/>
52
+ <text x="476" y="212" font-size="22" font-weight="700" fill="#0f766e">这一轮开不开</text>
53
+ <text x="476" y="238" font-size="14" fill="#78716c">四个条件同时成立,才开一轮;开不开 ≠ 说什么</text>
54
+
55
+ <g font-size="14" fill="#44403c">
56
+ <rect x="476" y="258" width="392" height="36" rx="8" fill="#f0fdfa" stroke="#99f6e4"/>
57
+ <text x="492" y="281">① 在她的醒着时段里</text>
58
+ <rect x="476" y="302" width="392" height="36" rx="8" fill="#f0fdfa" stroke="#99f6e4"/>
59
+ <text x="492" y="325">② 今天还有额度(默认 0–6 次)</text>
60
+ <rect x="476" y="346" width="392" height="36" rx="8" fill="#f0fdfa" stroke="#99f6e4"/>
61
+ <text x="492" y="369">③ 确实有一阵没说话(默认 6 小时)</text>
62
+ <rect x="476" y="390" width="392" height="36" rx="8" fill="#f0fdfa" stroke="#99f6e4"/>
63
+ <text x="492" y="413">④ 桌上至少有一件真能说 / 能做的事</text>
64
+ </g>
65
+
66
+ <rect x="476" y="448" width="392" height="52" rx="10" fill="#f5f5f4" stroke="#d6d3d1"/>
67
+ <text x="492" y="480" font-size="14" fill="#57534e">空桌不醒:宁可这一轮不叫她,也不拿废话凑数。</text>
68
+
69
+ <line x1="672" y1="500" x2="672" y2="514" stroke="#0f766e" stroke-width="2"/>
70
+ <line x1="569" y1="514" x2="775" y2="514" stroke="#0f766e" stroke-width="2"/>
71
+ <line x1="569" y1="514" x2="569" y2="540" stroke="#0f766e" stroke-width="2" marker-end="url(#ar)"/>
72
+ <line x1="775" y1="514" x2="775" y2="540" stroke="#0f766e" stroke-width="2" marker-end="url(#ar)"/>
73
+
74
+ <rect x="476" y="548" width="186" height="98" rx="12" fill="#ecfdf5" stroke="#6ee7b7"/>
75
+ <text x="494" y="578" font-size="18" font-weight="700" fill="#0f766e">开口</text>
76
+ <text x="494" y="602" font-size="13" fill="#44403c">说一句、留一句话</text>
77
+ <text x="494" y="622" font-size="13" fill="#44403c">或者什么都不说</text>
78
+
79
+ <rect x="682" y="548" width="186" height="98" rx="12" fill="#fff7ed" stroke="#fdba74"/>
80
+ <text x="700" y="578" font-size="18" font-weight="700" fill="#b45309">动手</text>
81
+ <text x="700" y="602" font-size="13" fill="#44403c">手边有工具能做,</text>
82
+ <text x="700" y="622" font-size="13" fill="#44403c">就做一件,做完就收</text>
83
+
84
+ <text x="476" y="678" font-size="13" fill="#78716c">「动手」不是新定时器:只在这一轮多一个形态,</text>
85
+ <text x="476" y="700" font-size="13" fill="#78716c">不占搭话额度,也不改变「一天最多几次」。</text>
86
+ <text x="476" y="728" font-size="13" fill="#78716c">两个出口都可以选「什么都不做」。</text>
87
+ </g>
88
+
89
+ <!-- 右:桌上摆什么 / 什么拦着 -->
90
+ <g>
91
+ <rect x="920" y="176" width="424" height="600" rx="16" fill="#ffffff" stroke="#d6d3d1"/>
92
+ <text x="944" y="212" font-size="22" font-weight="700" fill="#0f766e">桌上摆什么</text>
93
+ <text x="944" y="238" font-size="14" fill="#78716c">只摆事实,不派活;不出现分数、次数</text>
94
+
95
+ <g font-size="13.5" fill="#44403c">
96
+ <rect x="944" y="256" width="376" height="34" rx="8" fill="#fafaf9" stroke="#e7e5e4"/>
97
+ <text x="958" y="278">最近说过的话(原话,60 字以内)</text>
98
+ <rect x="944" y="298" width="376" height="34" rx="8" fill="#fafaf9" stroke="#e7e5e4"/>
99
+ <text x="958" y="320">没答案的问题 / 悬着的事</text>
100
+ <rect x="944" y="340" width="376" height="34" rx="8" fill="#fafaf9" stroke="#e7e5e4"/>
101
+ <text x="958" y="362">旧句子(她自己写的,7–30 天前)</text>
102
+ <rect x="944" y="382" width="376" height="34" rx="8" fill="#fafaf9" stroke="#e7e5e4"/>
103
+ <text x="958" y="404">她自己记下的便条(最多两张,不催)</text>
104
+ <rect x="944" y="424" width="376" height="34" rx="8" fill="#fafaf9" stroke="#e7e5e4"/>
105
+ <text x="958" y="446">兴趣只排序:先摆最近总回到的那件事</text>
106
+ </g>
107
+
108
+ <text x="944" y="496" font-size="22" font-weight="700" fill="#b45309">什么拦着</text>
109
+ <g font-size="13.5" fill="#44403c">
110
+ <rect x="944" y="512" width="376" height="34" rx="8" fill="#fffbeb" stroke="#fde68a"/>
111
+ <text x="958" y="534">一天 0–6 次;两次至少隔 45 分钟</text>
112
+ <rect x="944" y="554" width="376" height="34" rx="8" fill="#fffbeb" stroke="#fde68a"/>
113
+ <text x="958" y="576">消耗类一天 1 次;同一件 3 天内不重复</text>
114
+ <rect x="944" y="596" width="376" height="34" rx="8" fill="#fffbeb" stroke="#fde68a"/>
115
+ <text x="958" y="618">连着三次同类 → 停一周</text>
116
+ <rect x="944" y="638" width="376" height="34" rx="8" fill="#fffbeb" stroke="#fde68a"/>
117
+ <text x="958" y="660">一轮只做一件;第二次直接拦下</text>
118
+ </g>
119
+ <text x="944" y="700" font-size="13" fill="#78716c">额度是环境的边界,不写进人格;</text>
120
+ <text x="944" y="722" font-size="13" fill="#78716c">额度用完,只能来问你(1 天 1 次)。</text>
121
+ </g>
122
+
123
+ <!-- 底部 -->
124
+ <g>
125
+ <rect x="56" y="786" width="1288" height="78" rx="12" fill="#f0fdfa" stroke="#99f6e4"/>
126
+ <text x="76" y="812" font-size="14" fill="#0f766e">做过的会留下:</text>
127
+ <text x="196" y="812" font-size="14" fill="#44403c">did:&lt;类别&gt;:&lt;工具&gt;:ok|fail:&lt;那件事&gt; —— 下一轮 her_recall 翻得到,读成「你用 X 做成了一件事」或「试过,没成」。</text>
128
+ <text x="76" y="836" font-size="12.5" fill="#57534e">理论出处:自我决定论(Deci &amp; Ryan, 1985)+ 效能动机(White, 1959)+ 中断成本(Horvitz, 2007);前瞻记忆(Einstein &amp; McDaniel, 1990)</text>
129
+ <text x="76" y="854" font-size="12.5" fill="#57534e">+ 实施意图(Gollwitzer, 1999);计划者-行动者(Thaler &amp; Shefrin, 1981)。</text>
130
+ </g>
131
+ </svg>
@@ -24,7 +24,7 @@
24
24
  <!-- ============ 标题 ============ -->
25
25
  <text x="48" y="66" font-size="40" font-weight="700" fill="#111827">认知是怎么长出来的</text>
26
26
  <text x="48" y="106" font-size="18" fill="#6b7280">五步循环:表态 → 撞上 → 落差 → 改写 → 回顾。走完一圈,一条判断变硬一点;两句话对不上,就长成一处矛盾。</text>
27
- <text x="48" y="132" font-size="18" fill="#6b7280">四个阶段按天推进、三个瓶颈要她自己走;全部走完之后,才开始长「立场清单」。</text>
27
+ <text x="48" y="132" font-size="18" fill="#6b7280">四个阶段按天推进、三个瓶颈要她自己走;三道瓶颈都真过之后,才开始长「立场清单」。</text>
28
28
  <line x1="48" y1="158" x2="1352" y2="158" stroke="#e5e7eb"/>
29
29
 
30
30
  <!-- ============ 左:输入 ============ -->
@@ -113,7 +113,7 @@
113
113
  <!-- ============ 四个阶段 ============ -->
114
114
  <line x1="48" y1="648" x2="1352" y2="648" stroke="#e5e7eb"/>
115
115
  <text x="48" y="686" font-size="17" font-weight="700" fill="#111827">四个阶段按天推进,三个瓶颈要她自己走</text>
116
- <text x="470" y="686" font-size="12.5" fill="#9ca3af">瓶颈没过,天数到了也停在原地——这是「快慢」和「是不是她」的分界</text>
116
+ <text x="470" y="686" font-size="12.5" fill="#9ca3af">天数到了、门没过:兜底放行,但兜底不算真过;立场要三道门都真过。</text>
117
117
 
118
118
  <g font-size="12.5">
119
119
  <rect x="48" y="708" width="300" height="78" rx="12" fill="#ffffff" stroke="#d1d5db"/>
@@ -147,7 +147,7 @@
147
147
  <rect x="48" y="846" width="1304" height="184" rx="18" fill="url(#stanceFill)" stroke="#5eead4" stroke-width="1.4"/>
148
148
  <rect x="48" y="846" width="9" height="184" rx="4" fill="#0d9488"/>
149
149
 
150
- <text x="88" y="892" font-size="24" font-weight="700" fill="#0f766e">走完四个阶段之后长出来的:立场清单</text>
150
+ <text x="88" y="892" font-size="24" font-weight="700" fill="#0f766e">三道瓶颈都真过之后长出来的:立场清单</text>
151
151
  <text x="88" y="920" font-size="13" fill="#0f766e">四个阶段到此为止,之后不再加阶段、也没有「通关」——往后一直变厚的就是这一张清单。</text>
152
152
 
153
153
  <g font-size="13">
@@ -96,7 +96,7 @@
96
96
  <g>
97
97
  <rect x="764" y="238" width="572" height="486" rx="16" fill="#ffffff" stroke="#e5e7eb" filter="url(#soft2)"/>
98
98
  <text x="792" y="274" font-size="16" font-weight="700" fill="#111827">这一次真正摆在她眼前的</text>
99
- <text x="792" y="298" font-size="12.5" fill="#6b7280">身份文档:默认 1200 字预算,超了就按下面的顺序摆</text>
99
+ <text x="792" y="298" font-size="12.5" fill="#6b7280">身份文档:默认 2400 字预算,超了就按下面的顺序摆</text>
100
100
 
101
101
  <!-- 核心段 -->
102
102
  <rect x="792" y="314" width="516" height="112" rx="10" fill="#fef2f2" stroke="#fecaca"/>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssamurias/dsh-fish",
3
- "version": "0.9.9",
3
+ "version": "1.0.1",
4
4
  "description": "养一条会自己长大的鱼:没有人格设置,通过事件流长大。她可以自己刷 B 站、会写日记给你看,四个阶段完成后才会开始有立场。状态库在 ~/.dsh-fish,不能删除记录。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -19,8 +19,8 @@
19
19
  "AGENTS.md",
20
20
  "CHANGELOG.md",
21
21
  "RELEASE-NOTES-*.md",
22
- "RELEASE.md",
23
- "scripts"
22
+ "scripts",
23
+ "tools"
24
24
  ],
25
25
  "scripts": {
26
26
  "test": "node --test"