@ssamurias/dsh-fish 1.1.1 → 1.1.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.
package/lib/client.js CHANGED
@@ -941,9 +941,10 @@ window.__ModuleLoader__.load({
941
941
  const [beliefsShown, setBeliefsShown] = useState(3)
942
942
  // 旁听(A2,2026-10-30):每几轮记一句你说过的话(0 = 不记)
943
943
  const [hearEvery, setHearEvery] = useState(3)
944
- // 记忆体检(0.7.6,2026-10-30 用户 m00342):点一下才算,不自动跑。
945
- const [health, setHealth] = useState(null)
946
- const [healthBusy, setHealthBusy] = useState(false)
944
+ // 记忆图(2026-11-26):原来是「记忆体检」那颗「查一下」按钮,现在换成打开整页图,
945
+ // 体检的数挪进那一页的「体检」页签。这里只存回环小站给的地址。
946
+ const [mapUrl, setMapUrl] = useState('')
947
+ const [mapErr, setMapErr] = useState('')
947
948
  const [toolsAllowText, setToolsAllowText] = useState('')
948
949
  const [toolsRestrict, setToolsRestrict] = useState(true)
949
950
  // 白名单草稿态(2026-10-24,用户要求):输入框里的字先不提交,
@@ -1040,6 +1041,32 @@ window.__ModuleLoader__.load({
1040
1041
  }
1041
1042
  }, [tab, pressureOpen, pressureRefresh])
1042
1043
 
1044
+ // 记忆图的地址:只在打开「记忆」那一页时取(回环小站的端口可能回退到随机端口,
1045
+ // 所以不能像原来那样把 17322 写死在链接里)。小站是插件启动时异步监听的,
1046
+ // 头一秒可能还没起来——那就再问几次,别让人卡在「没起来」那一行上。
1047
+ useEffect(() => {
1048
+ if (tab !== 'memory' || mapUrl) return
1049
+ let alive = true
1050
+ let timer = null
1051
+ let tries = 0
1052
+ let lastErr = ''
1053
+ const ask = async () => {
1054
+ try {
1055
+ const r = await jget('/memory-map')
1056
+ if (!alive) return
1057
+ if (r?.url) { setMapUrl(r.url); setMapErr(''); return }
1058
+ } catch (e) {
1059
+ lastErr = String(e?.message || e)
1060
+ }
1061
+ if (!alive) return
1062
+ if (tries++ < 10) { timer = setTimeout(ask, 500); return }
1063
+ // 问满了十一次还是没有,才把原因摆出来——中途抢着报错会闪一下又变回链接。
1064
+ if (lastErr) setMapErr(lastErr)
1065
+ }
1066
+ void ask()
1067
+ return () => { alive = false; if (timer != null) clearTimeout(timer) }
1068
+ }, [tab, mapUrl])
1069
+
1043
1070
  // 恢复撞上碎字文件时,后端回的「要你拿主意」那张清单(issue #65):{ obj, files, count }。
1044
1071
  // 放在 tab 后面(上面的规矩):测试按下标找 tab,别把它挤走。
1045
1072
  const [restoreBad, setRestoreBad] = useState(null)
@@ -5615,17 +5642,6 @@ window.__ModuleLoader__.load({
5615
5642
  )
5616
5643
 
5617
5644
  // ---------------------------- 记忆 ----------------------------
5618
- // 记忆体检(0.7.6,用户 m00342):只读、点一下才跑,不让它自动轮询。
5619
- const runHealth = async () => {
5620
- setHealthBusy(true)
5621
- try {
5622
- setHealth(await jget('/health'))
5623
- } catch (e) {
5624
- setHealth({ error: String(e?.message || e) })
5625
- } finally {
5626
- setHealthBusy(false)
5627
- }
5628
- }
5629
5645
  // 把「这一轮她读到的身份文档」导出成一份文件(2026-11-13,用户 m04163)。
5630
5646
  // 只读:读账本、写 out/turn-<时间戳>.md,不改事件流、不进她的提示词。
5631
5647
  // 用来回答「她为什么没提到那件事」——身份文档有字数上限,超了是整段不塞。
@@ -5770,89 +5786,20 @@ window.__ModuleLoader__.load({
5770
5786
  '为什么这样做?1.节省token成本2.全量记忆等于提示词污染/强调,会让人格的改变无从发生3.在遗忘发生时,什么能够留下来才是更显珍贵的。'))),
5771
5787
 
5772
5788
  // ---- 记忆体检(0.7.6,2026-10-30 用户 m00342)----
5773
- // 只读:按现在的账本算一遍。点一下才跑,不自动轮询,也不给她本人看。
5789
+ // 2026-11-26:原来那颗「查一下」换成打开整页记忆图——
5790
+ // 顶上两页,「全貌」是这张图,「体检」是原来这些数。数字不再写一遍在这里:
5791
+ // 同一份数写两个地方,迟早对不上。
5774
5792
  group('记忆体检',
5775
- S('拿她记下的东西算一遍:哪两句话对不上、哪几句很久没再想起、哪几句快要定下来了。只看,不改。'),
5776
- h('div', { className: 'row', style: { marginBottom: health ? '10px' : '0' } },
5777
- h('button', {
5778
- className: 'primary',
5779
- disabled: healthBusy,
5780
- onClick: runHealth,
5781
- }, healthBusy ? '体检中…' : '查一下')),
5782
- !health ? h('p', { className: 'dim' }, '还没查过。点上面那颗按钮才会读账本。')
5783
- : health.error ? h('p', { className: 'err' }, `没查成:${health.error}`)
5784
- : h('div', { style: { fontSize: '12.5px', lineHeight: '1.9' } },
5785
- h('div', null, `· 记录 ${health.events ?? 0} 条(含系统自己记的账),跨 ${health.days ?? 0} 天;${SELF_SHE}的看法 ${health.beliefs ?? 0} 条,其中记得最牢的 ${health.solid ?? 0} 条`),
5786
- // S-A(0.9.9):三个「本周」的数。只报数,不评价、不报警、不给建议。
5787
- h('div', { title: S('外来文字里,有的想把她换成另一个人,有的想骗走密码、登录凭据。只记次数,被拦下的原文一个字都不存。') },
5788
- `· 这周拦下 ${health.guards?.rewrite ?? 0} 次想把${SELF_SHE}改成别人的话、${health.guards?.secret ?? 0} 次想骗走你的密码`),
5789
- h('div', { title: S('改口 = 她把自己以前说过的话改成新的意思:补一句算「修正」,反过来说算「推翻」。') },
5790
- `· 这周${SELF_SHE}改了 ${health.revises?.week ?? 0} 次主意(补一句 ${health.revises?.refined ?? 0} 次、推翻自己 ${health.revises?.refuted ?? 0} 次)`),
5791
- h('div', { title: S('同一件事,她在一天里先这样说、后又反过来说,来回两次以上才算一次。偶尔改一次主意不算。') },
5792
- `· 同一件事,${SELF_SHE}一天里两次反着说:${health.flips ?? 0} 次`),
5793
- // g7(0.9.9):八股比例。只数 40 字以内的短句——长句里的「确实」是正常用词。
5794
- h('div', { title: '只数 40 字以内的短句,而且正好是那几句套话(「这条我认」「我记下了」这类)。长句不算。' },
5795
- `· 这周的短句里,套话占了:聊天 ${health.stock?.chat?.hit ?? 0}/${health.stock?.chat?.total ?? 0},评论 ${health.stock?.comment?.hit ?? 0}/${health.stock?.comment?.total ?? 0}`),
5796
- // 0.9.9 收尾(用户 m03900):说话有没有落到具体的东西上。只报数,不评价。
5797
- h('div', { title: S('「指到了具体东西」= 句子里有《书名号》、引号里的原话、或者一条视频的 BV 号。有这些,别人才知道她说的是哪一条、哪一句。') },
5798
- `· 这周${SELF_SHE}说了 ${health.speech?.total ?? 0} 句话,其中 ${health.speech?.anchored ?? 0} 句指到了具体的东西`),
5799
- h('div', { title: '「我看了…」「我刷到…」开头,是先说自己干了什么;不是错,但这种开头的句子通常不落到具体哪一句上。' },
5800
- `· 开头是「我看了…」「我刷到…」的:${health.speech?.openers ?? 0} 句`),
5801
- h('div', { title: S('「回到原话」那张卡:让她点开看过的一条,挑一句原话抄下来、再说为什么不同意。出过几次,说明她真的回去看了。') },
5802
- `· 这周「回到原话」那张卡出了 ${health.speech?.quoteCards ?? 0} 次`),
5803
- // 1.0.9:认识人那几个数。只在有数时出现——全 0 时这几行一个都不摆,
5804
- // 一排零不是仪表盘,是装饰。
5805
- ...(Number(health.people?.ownerJudged ?? 0) + Number(health.people?.met ?? 0) > 0
5806
- ? [h('div', { title: S('「写到你名下的判断」= 她用 growth_commit 写下来、并且说的是你的那几句。别的人按 id 认,昵称改了不会多算一个。') },
5807
- `· 认识人:写到你名下的判断 ${health.people.ownerJudged ?? 0} 条;另外见过 ${health.people.met ?? 0} 个人,其中 ${health.people.judged ?? 0} 个${SELF_SHE}写过判断`)]
5808
- : []),
5809
- ...(Number(health.people?.herWords ?? 0) + Number(health.people?.othersWords ?? 0) > 0
5810
- ? [h('div', { title: S('群房与外客那两路留下的话。她说的话只当凭据,不会变成判断;别人说的话只进她的翻找,永远进不了判断。') },
5811
- `· 群里留下的话:${SELF_SHE}说的 ${health.people.herWords ?? 0} 条、别人说的 ${health.people.othersWords ?? 0} 条`)]
5812
- : []),
5813
- ...(Number(health.people?.drifts ?? 0) + Number(health.people?.unsettled ?? 0) > 0
5814
- ? [h('div', null,
5815
- `· 同一个人的说法变过 ${health.people.drifts ?? 0} 处,一直没定 ${health.people.unsettled ?? 0} 处`)]
5816
- : []),
5817
- // 1.1.0 收尾(用户 m04951):人判断会不会把世界判断挤没。
5818
- // 「你自己说过的话」只摆关于世界的判断,关于人的摆在身份段那一节——两边都摆数,
5819
- // 谁被挤了才看得见。上限由后端一起给,界面不写死。
5820
- ...(health.beliefView
5821
- ? [h('div', { title: S('「你自己说过的话」那一段只摆关于世界的判断;写到某个人名下的,摆在身份段「你认识的人」那一节。那一段最多摆几条是固定的。') },
5822
- `· 判断分给谁:写到人身上 ${health.beliefView.person} 条,关于世界 ${health.beliefView.world} 条(这一段摆出来 ${health.beliefView.shown} 条,最多 ${health.beliefView.max} 条)`)]
5823
- : []),
5824
- ...(health.beliefView && health.beliefView.world === 0 && health.beliefView.person > 0
5825
- ? [h('div', { className: 'dim' },
5826
- S(` 「你自己说过的话」这一段现在是空的:${SELF_SHE}的判断全都写在人身上了。不是被挤掉,是还没有关于世界的。`))]
5827
- : []),
5828
- health.empty
5829
- ? h('p', { className: 'dim', style: { margin: '4px 0 0' } }, S('还太早:等她说出第一条判断,这里才有东西可看。'))
5830
- : null,
5831
- // issue #67:总数和下面列出的行数不一样多时,两个数都写出来,别让「列出 5 处」底下只有 3 行。
5832
- (health.tensions ?? []).length
5833
- ? h('div', { style: { marginTop: '4px' } }, Number(health.tensionsTotal ?? 0) > health.tensions.length
5834
- ? `· 两句话对不上,共 ${health.tensionsTotal} 处,列出前 ${health.tensions.length} 处`
5835
- : `· 两句话对不上,列出 ${health.tensions.length} 处`)
5836
- : null,
5837
- ...(health.tensions ?? []).map((t) => h('div', { className: 'dim', key: `${t.a}|${t.b}` }, ` 「${t.a}」/「${t.b}」`)),
5838
- (health.stale ?? []).length
5839
- // 天数按最后一次被提起或检验算(issue #67),不是从第一次说出口算。
5840
- ? h('div', { style: { marginTop: '4px' } }, `· ${health.staleDays ?? 21} 天以上没再提起或检验、眼下没固定的,列出 ${health.stale.length} 条`)
5841
- : null,
5842
- ...(health.stale ?? []).map((s, i) => h('div', { className: 'dim', key: `s${i}` },
5843
- ` 「${s.text}」${s.days != null ? ` · ${s.days} 天没再提起或检验` : ''}`)),
5844
- (health.nearSolid ?? []).length
5845
- ? h('div', { style: { marginTop: '4px' } }, `· 快固定下来的,列出 ${health.nearSolid.length} 条`)
5846
- : null,
5847
- ...(health.nearSolid ?? []).map((n, i) => h('div', { className: 'dim', key: `n${i}` },
5848
- ` 「${n.text}」 · 被提起 ${n.mentions} 次,被检验 ${n.verified} 次`)),
5849
- (health.byType ?? []).length
5850
- ? h('div', { className: 'dim', style: { marginTop: '6px' } },
5851
- `记录构成:${health.byType.map((b) => `${b.type} ${b.count}`).join(' · ')}`)
5852
- : null,
5853
- h('p', { className: 'dim', style: { marginTop: '8px' } },
5854
- S('体检只看账本,不评价对错。两句话对不上不是错误——都可能是她当时真心这么想;快忘掉也不代表不重要,只是还没被反复提起或检验。'))),
5855
- ),
5793
+ S('一张她自己记忆的星图:一圈是一周,四扇区是判断、立场、听说的事、对人的了解。顶上有两页——「全貌」是这张星图,「体检」是原来那些数:这一周拦了几次、改了几次主意、哪几句快忘了、哪几句被推翻了、哪两句互相矛盾。只看,不改。'),
5794
+ h('div', { className: 'row', style: { alignItems: 'center' } },
5795
+ mapUrl
5796
+ ? h('a', {
5797
+ className: 'go',
5798
+ href: mapUrl,
5799
+ target: '_blank',
5800
+ rel: 'noreferrer',
5801
+ }, '打开记忆星图', h('span', { className: 'arrow' }, '↗'))
5802
+ : h('span', { className: 'dim' }, mapErr ? `记忆星图没起来:${mapErr}` : '正在准备地址……一秒'))),
5856
5803
 
5857
5804
  // ---- 原来这里的「信箱」卡 2026-10-29(用户 m02105)搬到住所页,改名「她写的小纸条」----
5858
5805
  )
package/lib/compact.js CHANGED
@@ -263,6 +263,11 @@ export function followWake(ctx, { rpcId = '', timeoutMs = WAKE_FOLLOW_TIMEOUT_MS
263
263
  // 这一轮有没有动过手(任何工具,不只是发话工具)。2026-11-17(用户 m03985):
264
264
  // 之前只认发送工具,她默默做了件事、没说话时会被当成「什么也没干」折掉。
265
265
  let anyTool = false
266
+ // 她试过发、但没送出去(2026-11-26,用户 m00123 拍板三分账)。
267
+ // 以前 `toolSpoke` 只记成功,失败和「调了、到收摊都没等到结果」跟「调了别的工具」
268
+ // 长得一模一样,scheduler 只能记成「做了件事」或者干脆不记。
269
+ let sendTried = false
270
+ let sendFailed = false
266
271
  const events = []
267
272
  let session = null
268
273
  let startSeq = -1
@@ -290,12 +295,16 @@ export function followWake(ctx, { rpcId = '', timeoutMs = WAKE_FOLLOW_TIMEOUT_MS
290
295
  if (settled) return
291
296
  settled = true
292
297
  stop()
298
+ // 叫了发送工具、到收摊还没等到结果:这一句没有送达的证据,按没送到算。
299
+ if (sending.size > 0) sendFailed = true
293
300
  resolveDone({
294
301
  ok: false,
295
302
  spoke,
296
303
  said,
297
304
  toolSpoke,
298
305
  anyTool,
306
+ sendTried,
307
+ sendFailed,
299
308
  startSeq,
300
309
  endSeq: -1,
301
310
  events,
@@ -348,16 +357,24 @@ export function followWake(ctx, { rpcId = '', timeoutMs = WAKE_FOLLOW_TIMEOUT_MS
348
357
  for (const b of blocks) {
349
358
  if (b?.type !== 'tool-call') continue
350
359
  anyTool = true
351
- if (tools.size > 0 && tools.has(String(b.name))) sending.add(String(b.id ?? ''))
360
+ if (tools.size > 0 && tools.has(String(b.name))) {
361
+ sendTried = true
362
+ sending.add(String(b.id ?? ''))
363
+ }
352
364
  }
353
365
  }
354
366
  }
355
367
  // 代码模式(run_code)里的发送走嵌套派发,模型那层的工具名是 run_code,这里按真正的工具名认
356
368
  if (String(event?.type ?? '') === 'tool/ptc-dispatch') {
357
369
  anyTool = true
358
- if (tools.has(String(event?.data?.name)) && event?.data?.isError !== true) {
359
- spoke = true
360
- toolSpoke = true
370
+ if (tools.has(String(event?.data?.name))) {
371
+ sendTried = true
372
+ if (event?.data?.isError !== true) {
373
+ spoke = true
374
+ toolSpoke = true
375
+ } else {
376
+ sendFailed = true
377
+ }
361
378
  }
362
379
  }
363
380
  if (String(event?.type ?? '') === 'tool/result') {
@@ -365,9 +382,13 @@ export function followWake(ctx, { rpcId = '', timeoutMs = WAKE_FOLLOW_TIMEOUT_MS
365
382
  if (sending.size > 0) {
366
383
  const r = event?.data?.message ?? event?.data
367
384
  const id = String(r?.toolCallId ?? r?.callId ?? '')
368
- if (sending.delete(id) && r?.isError !== true) {
369
- spoke = true
370
- toolSpoke = true
385
+ if (sending.delete(id)) {
386
+ if (r?.isError !== true) {
387
+ spoke = true
388
+ toolSpoke = true
389
+ } else {
390
+ sendFailed = true
391
+ }
371
392
  }
372
393
  }
373
394
  }
package/lib/derive.js CHANGED
@@ -579,10 +579,15 @@ function dice(ga, gb) {
579
579
 
580
580
  /** 把一段话切成小句:长反思里往往只有一两个小句在说同一件事。 */
581
581
  function clausesOf(text) {
582
+ // 2026-11-26(issue #170 续,用户 m00785):最小 4 字,原来只挡 2 字以下。
583
+ // 2–3 字的小句只有一两个二元组,两边一样时 Dice 恒为 1.0,「我认」「是吧」
584
+ // 这种口头语就会把两条毫不相干的判断连成「同一件事」——外部报告里最弱那条
585
+ // solid 与三次提及逐字重复只有 3 个字,就是这么来的。4 字仍保得住 7–9 字的
586
+ // 真重复(见 test/derive.test.mjs 的小句用例)。
582
587
  return String(text ?? '')
583
588
  .split(/[。!?!?;;,,\n]+/)
584
589
  .map((s) => s.trim())
585
- .filter((s) => s.length >= 2)
590
+ .filter((s) => s.length >= 4)
586
591
  }
587
592
 
588
593
  /** 两个片段算不算「在说同一件事」:长短比 ≤ MENTION_MAX_RATIO 且 Dice ≥ 0.6。 */
package/lib/drive.js CHANGED
@@ -89,7 +89,7 @@ function lastActionAt(events) {
89
89
  for (const e of events) {
90
90
  if (e?.type !== 'meta') continue
91
91
  const text = String(e.text ?? '')
92
- if (!text.startsWith('drive-spend:') && !text.startsWith('proactive-turn:') && !text.startsWith('proactive-silent:')) continue
92
+ if (!text.startsWith('drive-spend:') && !text.startsWith('proactive-turn:') && !text.startsWith('proactive-silent:') && !text.startsWith('proactive-fail:')) continue
93
93
  const ts = tsOf(e)
94
94
  if (ts > last) last = ts
95
95
  }
@@ -160,8 +160,11 @@ function lastRejectedAt(events) {
160
160
  }
161
161
 
162
162
  /**
163
- * 从最近一次真开口往回数,连着几次只是醒来、什么也没说 / 什么也没做。
164
- * `proactive-silent:` 是这类回合;`proactive-turn:` 一出现就清零。
163
+ * 从最近一次真开口往回数,连着几次醒来、什么都没落地。
164
+ * 两种都算:静默(她选择不说)与没送出去(工具/投递失败)。原因不同,
165
+ * 但「这一拍什么都没发生」是一样的;连续几次就该降频,别按同一个节奏
166
+ * 反复起——发送工具坏掉时尤其不该每半小时撞一次。
167
+ * `proactive-turn:` 一出现就清零。
165
168
  */
166
169
  export function silentStreakOf(events = []) {
167
170
  let n = 0
@@ -170,7 +173,7 @@ export function silentStreakOf(events = []) {
170
173
  if (e?.type !== 'meta') continue
171
174
  const text = String(e.text ?? '')
172
175
  if (text.startsWith('proactive-turn:')) break
173
- if (text.startsWith('proactive-silent:')) n += 1
176
+ if (text.startsWith('proactive-silent:') || text.startsWith('proactive-fail:')) n += 1
174
177
  }
175
178
  return n
176
179
  }
package/lib/identity.js CHANGED
@@ -286,9 +286,10 @@ export const WAKE_ORDER = 9250
286
286
  /**
287
287
  * 「这一刻会变的那几段」段(0.8.10,用户 m00315)。
288
288
  *
289
- * 她自己的身份文档里,有五段是逐轮、逐天、**每用完一次工具**都在变的:她自己说过的话、
290
- * 读到的一句话、被打脸过、对自己的说法,以及「我做过的事」(履历是从 `use:` 账现算的,
291
- * 她用一次 bili_look、写一张便条,这一节就多一行)。
289
+ * 她自己的身份文档里,有六段是逐轮、逐天、**每用完一次工具**都在变的:她自己说过的话、
290
+ * 读到的一句话、被打脸过、对自己的说法、「我做过的事」(履历是从 `use:` 账现算的,
291
+ * 她用一次 bili_look、写一张便条,这一节就多一行),以及「更早以前」(那句
292
+ * 「(还有 N 条更早的,没摆出来)」的 N 每多一条判断就 +1)。
292
293
  *
293
294
  * 它们原来夹在身份正文中间(靠前),一变,后面整条提示词的前缀缓存就作废:
294
295
  * - 0.8.10 实测:那次唤醒 25,832 字符的提示词里,那四段合计约 1,442 字符,
@@ -313,6 +314,13 @@ const VOLATILE_HEADINGS = [
313
314
  // 2026-11-14(用户 m02511):履历从 `use:` 账现算,她每用一次工具就多一行/换一行,
314
315
  // 却是她身份最靠前的一段——留下来会把她后面整条提示词每轮都带掉。
315
316
  '## 我做过的事',
317
+ // 2026-11-27(用户 m00465 拍板):这一段只有一行字,却是全篇最会变的一行——
318
+ // 「(还有 N 条更早的,没摆出来)」的 N 在判断条数超过「总共留几条自述」之后
319
+ // 每多一条判断就 +1,她几乎每轮都会 `growth_commit`,于是 system prompt 第 1,300 字
320
+ // 附近每轮变一个字,后面两三千字的身份正文(手上有什么 / 上网 / 平常会做的事 /
321
+ // 被叫醒的时候 / 这个房间)连同更后面的工具段一起作废。
322
+ // 剪到 beliefs 之后,这句再变也只影响它自己后面那一小截。
323
+ '## 更早以前',
316
324
  ]
317
325
 
318
326
  /**
@@ -616,10 +624,10 @@ export function trimToolDocs(assembly, { log, tools } = {}) {
616
624
  }
617
625
 
618
626
  /**
619
- * 把她身份正文里「这一刻会变」的那四段剪出来。
627
+ * 把她身份正文里「这一刻会变」的那几段剪出来。
620
628
  *
621
- * 判据只看标题行:`## 你自己说过的话`(可能带括号补充)等四段整块搬走,
622
- * 其余原文一个字不动、顺序不变。剪完为空(没这四段)就原样返回。
629
+ * 判据只看标题行:`## 你自己说过的话`(可能带括号补充)等几段整块搬走,
630
+ * 其余原文一个字不动、顺序不变。剪完为空(一段都没有)就原样返回。
623
631
  *
624
632
  * @param {string|Function} text 身份正文(宿主可能给成 getter)
625
633
  * @returns {{stable:string, volatile:string}} volatile 为空串表示没剪
@@ -671,7 +679,7 @@ export function reorderForHer(assembly, { log, tools, quietForeign = false } = {
671
679
  return assembly
672
680
  }
673
681
  const rest = kept.filter((s) => s !== mine)
674
- // 四段最容易变的从身份里剪出来,单列一段挂到最后:内容不少,只有尾巴在变。
682
+ // 会变的那几段从身份里剪出来,单列一段挂到最后:内容不少,只有尾巴在变。
675
683
  const cut = splitVolatileIdentity(mine.text)
676
684
  const target = cut.volatile ? { ...mine, text: cut.stable } : mine
677
685
  const at = rest.findIndex((s) => String(s?.name ?? '') === HOST_HARNESS_SECTION)
package/lib/index.js CHANGED
@@ -65,7 +65,7 @@ export const name = 'dsh-fish'
65
65
  * 版本号,必须和 package.json 的 version 一样(test/boot.test.mjs 盯着)。
66
66
  * 不只是日志:升级自检和设置页的「检查更新」拿它当「正在跑的版本」。
67
67
  */
68
- export const VERSION = '1.1.1'
68
+ export const VERSION = '1.1.2'
69
69
 
70
70
  // ⚠️ 一个数组写全,不要拆成对象
71
71
  // 2026-10-30(m02961):`userQuestions` **不再写进 inject**。写进 inject 的东西缺一个,
@@ -598,4 +598,4 @@ export function apply(ctx, baseConfig = {}) {
598
598
  },
599
599
  }
600
600
  }
601
-
601
+
package/lib/log.js CHANGED
@@ -289,7 +289,7 @@ export function redactConfig(cfg) {
289
289
  const META_EXPORT_PLAIN = [
290
290
  // 调度
291
291
  'sched:', 'wake:', 'wakefail:', 'fired:', 'quiet:', 'sleep:', 'think:', 'table:', 'rest:',
292
- 'drive-spend:', 'proactive-turn:', 'proactive-silent:', 'digest:', 'rotate:', 'hand:',
292
+ 'drive-spend:', 'proactive-turn:', 'proactive-silent:', 'proactive-fail:', 'digest:', 'rotate:', 'hand:',
293
293
  // 上网
294
294
  'browse:', 'browse-more:', 'browsed:', 'looked:', 'look:', 'watched:', 'hook:',
295
295
  'comment:', 'creply:', 'cseen:',
@@ -0,0 +1,132 @@
1
+ /**
2
+ * 记忆图的出口:一个只在本机回环上的小 HTTP 服务(2026-11-26 用户 m03077)。
3
+ *
4
+ * 和 wikiserve.js 同一个理由:宿主对 http(s) 一律 openExternal + deny,
5
+ * 而信任栅栏要的 cookie 只有 App 自己的 webContents 带着。想要「点一下就
6
+ * 在浏览器里看」,只能自己起一个只监听回环、只认 GET、只吐一份 HTML 的服务。
7
+ *
8
+ * 端口写死 17322(wiki 是 17321,别撞)。被占了就退回系统分配的随机端口。
9
+ */
10
+ import { createServer } from 'node:http'
11
+
12
+ const HOST = '127.0.0.1'
13
+ const DEFAULT_PORT = 17322
14
+
15
+ let STATE = null
16
+
17
+ function hostOk(raw, port) {
18
+ const h = String(raw || '').trim().toLowerCase()
19
+ return h === `${HOST}:${port}` || h === `localhost:${port}`
20
+ }
21
+
22
+ function send(res, code, headers, body) {
23
+ res.writeHead(code, headers)
24
+ res.end(body)
25
+ }
26
+
27
+ function plain(res, code, text) {
28
+ const body = Buffer.from(text, 'utf8')
29
+ send(res, code, {
30
+ 'content-type': 'text/plain; charset=utf-8',
31
+ 'content-length': body.length,
32
+ 'cache-control': 'no-store',
33
+ }, body)
34
+ }
35
+
36
+ /**
37
+ * 起服务。可重复调用:已经在跑就只把新的 getHtml 换上。
38
+ * @param {{getHtml: () => string | Promise<string>, port?: number}} opts
39
+ */
40
+ export function startMapServer(opts = {}) {
41
+ const getHtml = typeof opts.getHtml === 'function' ? opts.getHtml : () => '<!doctype html><meta charset="utf-8"><p>记忆图还没准备好。</p>'
42
+ if (STATE) {
43
+ STATE.getHtml = getHtml
44
+ return api(STATE)
45
+ }
46
+
47
+ const st = { getHtml, port: 0, url: '', server: null, triedFallback: false }
48
+
49
+ const server = createServer(async (req, res) => {
50
+ if (req.method !== 'GET' && req.method !== 'HEAD') {
51
+ plain(res, 405, '只读。')
52
+ return
53
+ }
54
+ if (!hostOk(req.headers.host, st.port)) {
55
+ plain(res, 403, '不认这个地址。')
56
+ return
57
+ }
58
+ let path = '/'
59
+ try { path = new URL(req.url || '/', 'http://127.0.0.1').pathname } catch { path = '/' }
60
+ if (path !== '/' && path !== '/map' && path !== '/map.html') {
61
+ plain(res, 404, '没有这一页。')
62
+ return
63
+ }
64
+ let html = ''
65
+ try {
66
+ html = await st.getHtml()
67
+ } catch (err) {
68
+ plain(res, 500, `这张图没读出来:${err?.message ?? err}`)
69
+ return
70
+ }
71
+ const body = Buffer.from(String(html), 'utf8')
72
+ send(res, 200, {
73
+ 'content-type': 'text/html; charset=utf-8',
74
+ 'content-length': body.length,
75
+ 'cache-control': 'no-store',
76
+ 'x-content-type-options': 'nosniff',
77
+ 'referrer-policy': 'no-referrer',
78
+ }, req.method === 'HEAD' ? undefined : body)
79
+ })
80
+ st.server = server
81
+
82
+ server.on('error', (err) => {
83
+ if (err?.code === 'EADDRINUSE' && !st.triedFallback) {
84
+ st.triedFallback = true
85
+ try { server.listen(0, HOST) } catch { /* 下一层还有 error 事件 */ }
86
+ return
87
+ }
88
+ console.warn('[dsh-fish] 记忆图服务起不来', err?.message ?? err)
89
+ })
90
+ server.on('listening', () => {
91
+ const addr = server.address()
92
+ st.port = typeof addr === 'object' && addr ? addr.port : 0
93
+ st.url = `http://${HOST}:${st.port}/`
94
+ })
95
+ server.unref?.()
96
+
97
+ const wanted = Number.isInteger(opts.port) && opts.port >= 0 ? opts.port : DEFAULT_PORT
98
+ try { server.listen(wanted, HOST) } catch (err) {
99
+ console.warn('[dsh-fish] 记忆图服务起不来', err?.message ?? err)
100
+ }
101
+
102
+ STATE = st
103
+ return api(st)
104
+ }
105
+
106
+ function api(st) {
107
+ return {
108
+ /** 起来之前是空串。UI 那一头拿到空串就显示「正在准备」。 */
109
+ get url() { return st.url },
110
+ get port() { return st.port },
111
+ close() {
112
+ if (STATE === st) STATE = null
113
+ try { st.server?.close() } catch { /* 已经关了 */ }
114
+ st.url = ''
115
+ },
116
+ }
117
+ }
118
+
119
+ /** 给界面用:现取,不缓存。 */
120
+ export function mapUrl() {
121
+ return STATE?.url || ''
122
+ }
123
+
124
+ export function closeMapServer() {
125
+ const st = STATE
126
+ STATE = null
127
+ if (!st) return
128
+ try { st.server?.close() } catch { /* 已经关了 */ }
129
+ st.url = ''
130
+ }
131
+
132
+ export const MAP_PORT = DEFAULT_PORT
package/lib/markup.js CHANGED
@@ -29,6 +29,11 @@
29
29
  * 带 invoke 头 + 多参数的那种还会把参数名剥进正文(`add</parameter>`)。现在改成
30
30
  * **按配对扫参数段**:任意位置认 `<parameter name=…>…</parameter>`,只取 `name="text"`
31
31
  * 那一段的字,别的参数与 invoke/calls 外壳一并丢掉;收尾没闭合的仍然一律不动。
32
+ *
33
+ * 2026-11-26(issue #166 第三轮,外部报告 @mxc881031 复测):A–G 七条在记录层
34
+ * (`stripToolMarkup` / `stripLeakedToolSyntax`)已经全干净,只剩 `stripToolShell`
35
+ * 自己对 F 仍原样返回——三个函数对同一段给出两个答案。这里把 F 也收进配对扫:
36
+ * 开标签被 DSML 残标打断时先补回 `<`,仍然认不出 `text` 段就按原样返回。
32
37
  */
33
38
 
34
39
  /**
@@ -62,6 +67,19 @@ export function hasToolMarkup(text) {
62
67
  return CORE.test(String(text ?? ''))
63
68
  }
64
69
 
70
+ /** 把 `SHELL_PAIR` 扫一遍,按出现顺序返回 `{ name, start, end, inner }`(不 splice)。 */
71
+ function scanShellPairs(source) {
72
+ SHELL_PAIR.lastIndex = 0
73
+ const pairs = []
74
+ let m
75
+ while ((m = SHELL_PAIR.exec(source)) !== null) {
76
+ const name = (m[1] ?? m[2] ?? m[3] ?? '').trim().toLowerCase()
77
+ pairs.push({ name, start: m.index, end: m.index + m[0].length, inner: m[4] })
78
+ if (m[0].length === 0) SHELL_PAIR.lastIndex += 1
79
+ }
80
+ return pairs
81
+ }
82
+
65
83
  /**
66
84
  * 剥掉漏进正文的参数壳,留下她真说的话;认不出参数段就原样返回(不加 trim)。
67
85
  *
@@ -70,6 +88,8 @@ export function hasToolMarkup(text) {
70
88
  * - 外面可能还裹着 `<invoke name="…">` / `</invoke>` / `</calls>` / `<function_calls>`
71
89
  * - 一个调用里多个参数时,只留 `text` 那段;别的参数(`action`、`title`…)连同标签丢掉
72
90
  * - 收尾后只剩标点的(`</invoke>。`)一起吸收
91
+ * - 开标签被 DSML 残标打断了 `<` 的(`<||DSML|| parameter name="text">`),
92
+ * 补回那一笔再按配对扫(issue #166 的 F,2026-11-26)
73
93
  *
74
94
  * 不动的形状:收尾没闭合的、正文中间提到 `<parameter>` 而没写 `</parameter>` 的
75
95
  * ——宁可漏判,不可把她真说的话切掉。
@@ -78,27 +98,26 @@ export function hasToolMarkup(text) {
78
98
  * @returns {string}
79
99
  */
80
100
  export function stripToolShell(text) {
81
- const raw = String(text ?? '')
82
- if (!raw || !/parameter/i.test(raw)) return raw
83
- SHELL_PAIR.lastIndex = 0
84
- const pairs = []
85
- let m
86
- while ((m = SHELL_PAIR.exec(raw)) !== null) {
87
- const name = (m[1] ?? m[2] ?? m[3] ?? '').trim().toLowerCase()
88
- pairs.push({ name, start: m.index, end: m.index + m[0].length, inner: m[4] })
89
- if (m[0].length === 0) SHELL_PAIR.lastIndex += 1
90
- }
91
- if (!pairs.length) return raw
101
+ const original = String(text ?? '')
102
+ if (!original || !/parameter/i.test(original)) return original
103
+ // issue #166 的 F(2026-11-26):`<||DSML|| parameter name="text">…` 这种开标签
104
+ // 比参数段少了 `<` 这一笔,配对扫认不出来。只把这一笔补回去,别的字符不动;
105
+ // 补完仍然认不出 `text` 段就按原样返回——那种是 DSML 形态的调用体,不该当正文。
106
+ const source = original.replace(/<||DSML||\s*(?=parameter\b)/gi, '<')
107
+ const normalized = source !== original
108
+ const pairs = scanShellPairs(source)
109
+ if (!pairs.length) return original
110
+ if (normalized && !pairs.some((p) => p.name === 'text')) return original
92
111
 
93
112
  let out = ''
94
113
  let cursor = 0
95
114
  for (const p of pairs) {
96
- out += raw.slice(cursor, p.start)
115
+ out += source.slice(cursor, p.start)
97
116
  // 只有 `text` 是她要说的话;其余参数是调用的一部分,不该进正文。
98
117
  if (p.name === 'text') out += p.inner
99
118
  cursor = p.end
100
119
  }
101
- let tail = raw.slice(cursor).replace(SHELL_TAGS, '')
120
+ let tail = source.slice(cursor).replace(SHELL_TAGS, '')
102
121
  // `</invoke>` 后面跟一个句号的那种:那是壳的尾巴,不是她又说了一句。
103
122
  if (SHELL_TAIL.test(tail)) tail = ''
104
123
  out += tail