dsh-plugin-memory 0.19.0 → 0.19.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/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  所有记录跟随 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/) 风格;版本号与 `package.json` 保持一致。
4
4
 
5
+ ## [0.19.2] - 2026-11-12
6
+
7
+ ### Fixed
8
+
9
+ - **rc.2 下开启插件后会话不可用(根因)**:DSH 0.2.2-rc.2 把 `ctx.agents.roots()` 换成了 `ctx.agents.list()`,而 `agent/created` 是 **serial 事件**——监听器抛错会**拒绝 agent 注册**,于是每个新会话都建不起来。现在注册表读取改为兼容实现(`list()` → `roots()` → 空数组,绝不抛错),并且四个 `agent/created` 监听器整体 try/catch;另加 rc.2 形状的单测(list-only / legacy-roots / 注册表抛错三种)。
10
+ - 侧栏会话兜底同步改用兼容注册表 `list()`,rc.2 下双击节点的 session 解析不会退回 no-session。
11
+
12
+ ## [0.19.1] - 2026-11-11
13
+
14
+ ### Fixed
15
+
16
+ - **开启 memory 后会话不可用(DSH 0.2.2-rc.2)**:`ctx.systemPrompt.context` 的两个 `text` 回调若抛错会让整个 prompt 构建失败、所有会话发不出消息。两个回调(boot / 最近动态)现在整体 try/catch,异常只记录日志并返回空串——最坏情况记忆不注入,会话照常可用。
17
+ - 会话 chip 兼容 rc.2 的 `conversation.input.left` 空 props:宿主不传 `sessionId` 时请求走 `/api/memory/session` 的活跃会话兜底(不再直接隐藏 chip)。
18
+
5
19
  ## [0.19.0] - 2026-11-11
6
20
 
7
21
  ### Changed
@@ -26,13 +26,13 @@
26
26
  },
27
27
  "versions": [
28
28
  {
29
- "version": "0.18.4",
30
- "publishTimestamp": 1794277785,
29
+ "version": "0.19.1",
30
+ "publishTimestamp": 1794410440,
31
31
  "source": {
32
32
  "type": "npm"
33
33
  },
34
34
  "engines": {
35
- "dsh": "^0.2.1-rc.5"
35
+ "dsh": "^0.2.1-rc.5 || ^0.2.2-rc.2"
36
36
  }
37
37
  }
38
38
  ]
package/lib/client.js CHANGED
@@ -1092,9 +1092,14 @@ window.__ModuleLoader__.load({
1092
1092
  const [open, setOpen] = React.useState(false)
1093
1093
  const [error, setError] = React.useState(undefined)
1094
1094
 
1095
+ // Some hosts (e.g. DSH 0.2.2-rc.2) render this slot without a sessionId;
1096
+ // the host route then falls back to the active session.
1097
+ const hasSessionId = typeof sessionId === 'string' && sessionId.length > 0
1095
1098
  const read = () => {
1096
- if (typeof sessionId !== 'string' || sessionId.length === 0) return
1097
- fetch(`${SESSION_URL}?sessionId=${encodeURIComponent(sessionId)}`)
1099
+ const url = hasSessionId
1100
+ ? `${SESSION_URL}?sessionId=${encodeURIComponent(sessionId)}`
1101
+ : SESSION_URL
1102
+ fetch(url)
1098
1103
  .then(async (response) => (response.ok ? response.json() : undefined))
1099
1104
  .then((value) => {
1100
1105
  if (value === undefined) return
@@ -1105,7 +1110,6 @@ window.__ModuleLoader__.load({
1105
1110
  }
1106
1111
 
1107
1112
  React.useEffect(() => {
1108
- if (typeof sessionId !== 'string' || sessionId.length === 0) return undefined
1109
1113
  read()
1110
1114
  const timer = typeof setInterval === 'function' ? setInterval(read, 10000) : undefined
1111
1115
  return () => {
@@ -1121,7 +1125,6 @@ window.__ModuleLoader__.load({
1121
1125
  return () => document.removeEventListener('mousedown', close)
1122
1126
  }, [open])
1123
1127
 
1124
- if (typeof sessionId !== 'string' || sessionId.length === 0) return null
1125
1128
  const enabled = state === undefined ? true : state.ok !== false && state.effective !== false
1126
1129
  const workspaceMuted = state?.workspaceDisabled === true
1127
1130
 
@@ -1131,7 +1134,7 @@ window.__ModuleLoader__.load({
1131
1134
  fetch(SESSION_URL, {
1132
1135
  method: 'POST',
1133
1136
  headers: { 'content-type': 'application/json' },
1134
- body: JSON.stringify({ action, sessionId }),
1137
+ body: JSON.stringify(hasSessionId ? { action, sessionId } : { action }),
1135
1138
  })
1136
1139
  .then(async (response) => {
1137
1140
  const body = await response.json().catch(() => ({}))
package/lib/index.js CHANGED
@@ -267,6 +267,31 @@ export function apply(ctx, config = {}) {
267
267
  ttlDays: config.sessionTtlDays,
268
268
  })
269
269
  const sessionCwd = (agent) => agent?.session?.header?.cwd
270
+
271
+ /**
272
+ * DSH 0.2.2-rc.2 replaced `ctx.agents.roots()` with `ctx.agents.list()`.
273
+ * Reading `roots()` on rc.2 throws; inside a serial `agent/created` listener
274
+ * that rejects the agent registration and makes every session unusable.
275
+ * Read the registry compatibly and never throw.
276
+ */
277
+ const rootAgents = () => {
278
+ try {
279
+ const service = ctx.agents
280
+ if (service === undefined) return []
281
+ if (typeof service.list === 'function') return service.list()
282
+ if (typeof service.roots === 'function') return service.roots()
283
+ } catch {
284
+ // registry not ready yet
285
+ }
286
+ return []
287
+ }
288
+ const isRootAgent = (agent) => {
289
+ if (agent === undefined) return false
290
+ const header = agent.session?.header
291
+ if (header !== undefined && (header.parent !== undefined || header.parentSessionId !== undefined)) return false
292
+ const all = rootAgents()
293
+ return all.length === 0 || all.includes(agent)
294
+ }
270
295
  const sessionEnabled = (agent, resolved) => sessionGate.effectiveEnabled(
271
296
  agent.id,
272
297
  sessionCwd(agent),
@@ -412,38 +437,46 @@ export function apply(ctx, config = {}) {
412
437
  name: 'memory-boot',
413
438
  order: -200,
414
439
  text: (context) => {
415
- // Per-agent gate: no agent context (e.g. a global preview) injects
416
- // unconditionally; an agent injects only once it has spoken and is
417
- // the active session.
418
- const resolved = store.get()
419
- const agent = context?.agent
420
- // User intent first (the session switch), then the two polite gates.
421
- if (agent && !sessionEnabled(agent, resolved)) return ''
422
- if (agent && !tracker.shouldInject(agent.id, resolved)) return ''
423
- // Tone drift rides on the boot block (charged to its budget). Read
424
- // live from the store so the Settings select applies on the next
425
- // prompt build without a reload.
426
- const toneGuide = resolved.toneGuideEnabled
427
- ? buildToneGuide({ intensity: resolved.toneIntensity, language: 'zh' })
428
- : ''
429
- const options = {
430
- bootFiles,
431
- bootMaxChars,
432
- bootFileBudgets,
433
- toneGuide,
434
- // The volatile log tail is injected by `memory-recent` instead.
435
- includeRecentActivity: false,
436
- }
437
- if (agent && resolved.bootSnapshot === 'session') {
438
- const signature = snapshotSignature(resolved, memoryDir)
439
- const hit = bootSnapshots.get(agent.id)
440
- if (hit !== undefined && hit.signature === signature) return hit.text
441
- const text = renderBootBlock(memoryDir, options)
442
- bootSnapshots.set(agent.id, { text, signature })
443
- if (bootSnapshots.size > 64) bootSnapshots.delete(bootSnapshots.keys().next().value)
444
- return text
440
+ // A throwing runtime-context callback fails the whole prompt build and
441
+ // makes every session unusable. Swallow errors: worst case memory is
442
+ // not injected, the session keeps working.
443
+ try {
444
+ // Per-agent gate: no agent context (e.g. a global preview) injects
445
+ // unconditionally; an agent injects only once it has spoken and is
446
+ // the active session.
447
+ const resolved = store.get()
448
+ const agent = context?.agent
449
+ // User intent first (the session switch), then the two polite gates.
450
+ if (agent && !sessionEnabled(agent, resolved)) return ''
451
+ if (agent && !tracker.shouldInject(agent.id, resolved)) return ''
452
+ // Tone drift rides on the boot block (charged to its budget). Read
453
+ // live from the store so the Settings select applies on the next
454
+ // prompt build without a reload.
455
+ const toneGuide = resolved.toneGuideEnabled
456
+ ? buildToneGuide({ intensity: resolved.toneIntensity, language: 'zh' })
457
+ : ''
458
+ const options = {
459
+ bootFiles,
460
+ bootMaxChars,
461
+ bootFileBudgets,
462
+ toneGuide,
463
+ // The volatile log tail is injected by `memory-recent` instead.
464
+ includeRecentActivity: false,
465
+ }
466
+ if (agent && resolved.bootSnapshot === 'session') {
467
+ const signature = snapshotSignature(resolved, memoryDir)
468
+ const hit = bootSnapshots.get(agent.id)
469
+ if (hit !== undefined && hit.signature === signature) return hit.text
470
+ const text = renderBootBlock(memoryDir, options)
471
+ bootSnapshots.set(agent.id, { text, signature })
472
+ if (bootSnapshots.size > 64) bootSnapshots.delete(bootSnapshots.keys().next().value)
473
+ return text
474
+ }
475
+ return renderBootBlock(memoryDir, options)
476
+ } catch (error) {
477
+ ctx.logger?.warn?.(`memory: boot context failed: ${error instanceof Error ? error.message : String(error)}`)
478
+ return ''
445
479
  }
446
- return renderBootBlock(memoryDir, options)
447
480
  },
448
481
  })
449
482
  // The volatile tail (recent log entries) lives in its own segment with a
@@ -452,11 +485,16 @@ export function apply(ctx, config = {}) {
452
485
  name: 'memory-recent',
453
486
  order: 900,
454
487
  text: (context) => {
455
- const resolved = store.get()
456
- const agent = context?.agent
457
- if (agent && !sessionEnabled(agent, resolved)) return ''
458
- if (agent && !tracker.shouldInject(agent.id, resolved)) return ''
459
- return renderRecentActivity(memoryDir)
488
+ try {
489
+ const resolved = store.get()
490
+ const agent = context?.agent
491
+ if (agent && !sessionEnabled(agent, resolved)) return ''
492
+ if (agent && !tracker.shouldInject(agent.id, resolved)) return ''
493
+ return renderRecentActivity(memoryDir)
494
+ } catch (error) {
495
+ ctx.logger?.warn?.(`memory: recent context failed: ${error instanceof Error ? error.message : String(error)}`)
496
+ return ''
497
+ }
460
498
  },
461
499
  })
462
500
  } else {
@@ -506,14 +544,19 @@ export function apply(ctx, config = {}) {
506
544
  // (has-user-spoken + active-session) see real user messages as they land.
507
545
  ctx.effect(() => {
508
546
  const stopCreated = ctx.on('agent/created', ({ agent }) => {
509
- if (!ctx.agents.roots().includes(agent)) return
510
- agent.ctx.effect(() => {
511
- tracker.attach(agent)
512
- return () => {
513
- tracker.detach(agent.id)
547
+ try {
548
+ if (!isRootAgent(agent)) return
549
+ agent.ctx.effect(() => {
550
+ tracker.attach(agent)
551
+ return () => {
552
+ tracker.detach(agent.id)
553
+ }
554
+ })
555
+
556
+ } catch (error) {
557
+ ctx.logger?.warn?.(`memory: agent/created listener failed: ${error instanceof Error ? error.message : String(error)}`)
514
558
  }
515
559
  })
516
- })
517
560
  return () => stopCreated()
518
561
  }, 'memory.activity-tracker()')
519
562
 
@@ -528,30 +571,35 @@ export function apply(ctx, config = {}) {
528
571
  const stamped = new Set()
529
572
  ctx.effect(() => {
530
573
  const stopCreated = ctx.on('agent/created', ({ agent }) => {
531
- if (!ctx.agents.roots().includes(agent)) return
532
- agent.ctx.effect(() => {
533
- const stopInserted = ctx.on('agent/inbox/inserted', ({ agent: target, message }) => {
534
- if (target?.id !== agent.id) return
535
- if (message?.source?.kind !== 'user') return
536
- if (stamped.has(agent.id)) return
537
- const resolved = store.get()
538
- if (!sessionEnabled(agent, resolved)) return
539
- if (!tracker.shouldInject(agent.id, resolved)) return
540
- stamped.add(agent.id)
541
- try {
542
- const memoryDir = currentMemoryDir
543
- const block = renderBootBlock(memoryDir, { bootFiles, bootMaxChars, bootFileBudgets })
544
- const referenced = extractReferencedPages(block, memoryDir)
545
- const touched = touchPages(memoryDir, [...bootFiles, ...referenced])
546
- if (touched.length > 0) {
547
- ctx.logger?.info?.(`memory: last_access stamped on ${touched.length} page(s)`)
574
+ try {
575
+ if (!isRootAgent(agent)) return
576
+ agent.ctx.effect(() => {
577
+ const stopInserted = ctx.on('agent/inbox/inserted', ({ agent: target, message }) => {
578
+ if (target?.id !== agent.id) return
579
+ if (message?.source?.kind !== 'user') return
580
+ if (stamped.has(agent.id)) return
581
+ const resolved = store.get()
582
+ if (!sessionEnabled(agent, resolved)) return
583
+ if (!tracker.shouldInject(agent.id, resolved)) return
584
+ stamped.add(agent.id)
585
+ try {
586
+ const memoryDir = currentMemoryDir
587
+ const block = renderBootBlock(memoryDir, { bootFiles, bootMaxChars, bootFileBudgets })
588
+ const referenced = extractReferencedPages(block, memoryDir)
589
+ const touched = touchPages(memoryDir, [...bootFiles, ...referenced])
590
+ if (touched.length > 0) {
591
+ ctx.logger?.info?.(`memory: last_access stamped on ${touched.length} page(s)`)
592
+ }
593
+ } catch (error) {
594
+ ctx.logger?.warn?.(`memory: last_access stamp failed: ${error instanceof Error ? error.message : String(error)}`)
548
595
  }
549
- } catch (error) {
550
- ctx.logger?.warn?.(`memory: last_access stamp failed: ${error instanceof Error ? error.message : String(error)}`)
551
- }
596
+ })
597
+ return () => stopInserted?.()
552
598
  })
553
- return () => stopInserted?.()
554
- })
599
+
600
+ } catch (error) {
601
+ ctx.logger?.warn?.(`memory: agent/created listener failed: ${error instanceof Error ? error.message : String(error)}`)
602
+ }
555
603
  })
556
604
  return () => stopCreated()
557
605
  }, 'memory.page-access()')
@@ -572,32 +620,37 @@ export function apply(ctx, config = {}) {
572
620
  if (config.digestNudgeEnabled !== false) {
573
621
  ctx.effect(() => {
574
622
  const stopCreated = ctx.on('agent/created', ({ agent }) => {
575
- if (!ctx.agents.roots().includes(agent)) return
576
- const guard = new DigestGuard(agent, {
577
- readConfig: () => {
578
- const resolved = store.get()
579
- return {
580
- enabled: resolved.enabled && sessionEnabled(agent, resolved),
581
- afterMinutes: config.digestNudgeAfterMinutes,
582
- cooldownMinutes: config.digestNudgeCooldownMinutes,
583
- maxPerSession: config.digestNudgeMaxPerSession,
584
- deferUntilUserSpeaks: resolved.deferUntilUserSpeaks,
585
- activeSessionOnly: resolved.activeSessionOnly,
586
- proactiveCooldownSeconds: resolved.proactiveCooldownSeconds,
623
+ try {
624
+ if (!isRootAgent(agent)) return
625
+ const guard = new DigestGuard(agent, {
626
+ readConfig: () => {
627
+ const resolved = store.get()
628
+ return {
629
+ enabled: resolved.enabled && sessionEnabled(agent, resolved),
630
+ afterMinutes: config.digestNudgeAfterMinutes,
631
+ cooldownMinutes: config.digestNudgeCooldownMinutes,
632
+ maxPerSession: config.digestNudgeMaxPerSession,
633
+ deferUntilUserSpeaks: resolved.deferUntilUserSpeaks,
634
+ activeSessionOnly: resolved.activeSessionOnly,
635
+ proactiveCooldownSeconds: resolved.proactiveCooldownSeconds,
636
+ }
637
+ },
638
+ getMemoryDir: () => currentMemoryDir,
639
+ agents: ctx.agents,
640
+ tracker,
641
+ logger: ctx.logger,
642
+ claimLock: claimSharedProactiveLock,
643
+ })
644
+ agent.ctx.effect(() => {
645
+ guard.start()
646
+ return () => {
647
+ guard.dispose()
587
648
  }
588
- },
589
- getMemoryDir: () => currentMemoryDir,
590
- agents: ctx.agents,
591
- tracker,
592
- logger: ctx.logger,
593
- claimLock: claimSharedProactiveLock,
594
- })
595
- agent.ctx.effect(() => {
596
- guard.start()
597
- return () => {
598
- guard.dispose()
599
- }
600
- })
649
+ })
650
+
651
+ } catch (error) {
652
+ ctx.logger?.warn?.(`memory: agent/created listener failed: ${error instanceof Error ? error.message : String(error)}`)
653
+ }
601
654
  })
602
655
  return () => stopCreated()
603
656
  }, 'memory.digest-guard()')
@@ -612,43 +665,48 @@ export function apply(ctx, config = {}) {
612
665
  {
613
666
  ctx.effect(() => {
614
667
  const stopCreated = ctx.on('agent/created', ({ agent }) => {
615
- if (!ctx.agents.roots().includes(agent)) return
616
- const nudge = new RecallNudge(agent, {
617
- readConfig: () => {
618
- const resolved = store.get()
619
- return {
620
- enabled: resolved.enabled && sessionEnabled(agent, resolved),
621
- recallEnabled: resolved.recallEnabled !== false,
622
- minMinutes: resolved.recallIntervalMinMinutes,
623
- maxMinutes: resolved.recallIntervalMaxMinutes,
624
- maxPerSession: resolved.recallMaxPerSession,
625
- deferUntilUserSpeaks: resolved.deferUntilUserSpeaks,
626
- activeSessionOnly: resolved.activeSessionOnly,
627
- proactiveCooldownSeconds: resolved.proactiveCooldownSeconds,
628
- }
629
- },
630
- readGrowthConfig: () => {
631
- const resolved = store.get()
632
- return {
633
- enabled: resolved.growthRecapEnabled !== false,
634
- intervalDays: resolved.growthRecapIntervalDays,
635
- language: 'zh',
668
+ try {
669
+ if (!isRootAgent(agent)) return
670
+ const nudge = new RecallNudge(agent, {
671
+ readConfig: () => {
672
+ const resolved = store.get()
673
+ return {
674
+ enabled: resolved.enabled && sessionEnabled(agent, resolved),
675
+ recallEnabled: resolved.recallEnabled !== false,
676
+ minMinutes: resolved.recallIntervalMinMinutes,
677
+ maxMinutes: resolved.recallIntervalMaxMinutes,
678
+ maxPerSession: resolved.recallMaxPerSession,
679
+ deferUntilUserSpeaks: resolved.deferUntilUserSpeaks,
680
+ activeSessionOnly: resolved.activeSessionOnly,
681
+ proactiveCooldownSeconds: resolved.proactiveCooldownSeconds,
682
+ }
683
+ },
684
+ readGrowthConfig: () => {
685
+ const resolved = store.get()
686
+ return {
687
+ enabled: resolved.growthRecapEnabled !== false,
688
+ intervalDays: resolved.growthRecapIntervalDays,
689
+ language: 'zh',
690
+ }
691
+ },
692
+ getMemoryDir: () => currentMemoryDir,
693
+ agents: ctx.agents,
694
+ tracker,
695
+ logger: ctx.logger,
696
+ claimLock: claimSharedProactiveLock,
697
+ })
698
+ nudges.set(agent.id, nudge)
699
+ agent.ctx.effect(() => {
700
+ nudge.start()
701
+ return () => {
702
+ nudges.delete(agent.id)
703
+ nudge.dispose()
636
704
  }
637
- },
638
- getMemoryDir: () => currentMemoryDir,
639
- agents: ctx.agents,
640
- tracker,
641
- logger: ctx.logger,
642
- claimLock: claimSharedProactiveLock,
643
- })
644
- nudges.set(agent.id, nudge)
645
- agent.ctx.effect(() => {
646
- nudge.start()
647
- return () => {
648
- nudges.delete(agent.id)
649
- nudge.dispose()
650
- }
651
- })
705
+ })
706
+
707
+ } catch (error) {
708
+ ctx.logger?.warn?.(`memory: agent/created listener failed: ${error instanceof Error ? error.message : String(error)}`)
709
+ }
652
710
  })
653
711
  return () => stopCreated()
654
712
  }, 'memory.recall-nudge()')
@@ -775,7 +833,7 @@ export function apply(ctx, config = {}) {
775
833
  const url = new URL(req.url ?? '/', 'http://localhost')
776
834
  const resolveAgent = (sessionId) => {
777
835
  const id = typeof sessionId === 'string' && sessionId.length > 0 ? sessionId : tracker.activeId()
778
- const roots = typeof ctx.agents?.roots === 'function' ? ctx.agents.roots() : []
836
+ const roots = rootAgents()
779
837
  if (id !== undefined) {
780
838
  const direct = ctx.agents.get?.(id)
781
839
  if (direct !== undefined) return direct
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-plugin-memory",
3
3
  "description": "Long-term memory plugin for DeepSeek Harness: persistent cross-session markdown memory with a soul/persona file, auto-injected at every session start, plus remember/recall/consolidate/forget workflows and portable migration tooling.",
4
- "version": "0.19.0",
4
+ "version": "0.19.2",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "lib/index.js",