dsh-selfnote 0.13.0 → 0.13.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 (2) hide show
  1. package/lib/index.js +12 -3
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -592,14 +592,23 @@ function trimSessionMap(map) {
592
592
  while (map.size > MAX_SESSION_TRACKED) map.delete(map.keys().next().value)
593
593
  }
594
594
 
595
+ /** 一个会话可能有两个 id(记录 id 与 header.id):两边都记,哪边先到都能命中。 */
596
+ function sessionKeysOf(session) {
597
+ const ids = [session?.id, session?.header?.id, session?.header?.sessionId]
598
+ return [...new Set(ids.filter((id) => typeof id === 'string' && id !== ''))]
599
+ }
600
+
595
601
  /** 压缩事件到达时按会话打个标记:下一轮照这个会话用过的东西补一遍。 */
596
- function noteCompaction(sessionId, event) {
602
+ function noteCompaction(session, event) {
597
603
  const type = String(event?.type ?? '')
598
604
  if (!COMPACTION_EVENTS.has(type)) return
599
605
  // 压缩失败/中止时窗口里还有原文,补了是重复
600
606
  const data = event?.data
601
607
  if (data !== null && typeof data === 'object' && 'error' in data && data.error !== undefined) return
602
- compactionPending.set(sessionId, { at: Date.now(), ids: [...(lastInjectedBySession.get(sessionId) ?? [])] })
608
+ const keys = sessionKeysOf(session)
609
+ if (keys.length === 0) return
610
+ const ids = [...new Set(keys.flatMap((key) => lastInjectedBySession.get(key) ?? []))]
611
+ for (const key of keys) compactionPending.set(key, { at: Date.now(), ids })
603
612
  trimSessionMap(compactionPending)
604
613
  }
605
614
 
@@ -2207,7 +2216,7 @@ export function apply(ctx, config) {
2207
2216
  const sessionId = session?.id
2208
2217
  if (typeof sessionId !== 'string' || sessionId === '') return
2209
2218
  // 压缩发生了就记一笔:下一轮把这个会话用过的记忆再贴一遍
2210
- noteCompaction(sessionId, event)
2219
+ noteCompaction(session, event)
2211
2220
  // 同一会话按到达顺序串行,避免 seq=11 先完成把游标推到 11、把 seq=10 挤掉
2212
2221
  enqueue(sessionId, () =>
2213
2222
  handleEvent(event, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-selfnote",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "type": "module",
5
5
  "description": "Self-narrative memory for DeepSeek Harness: the model writes notes to itself, which persist across sessions and are injected back. | 人格库:模型写给自己看的话,跨会话保留并每回合注入。",
6
6
  "keywords": [