dsh-plugin-memory 0.17.8 → 0.18.0

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,24 @@
2
2
 
3
3
  所有记录跟随 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/) 风格;版本号与 `package.json` 保持一致。
4
4
 
5
+ ## [0.18.0] - 2026-11-10
6
+
7
+ ### Added
8
+
9
+ - **`bootSnapshot: session | live`(issue #8)**:`session` 在会话首次注入时固化 boot 文本,会话中途写记忆不再改变系统提示前缀;新会话重新读盘。默认 `live`(不改变现有体验)。配置项进入「设置 → 记忆」(第 17 个热改项),`/memory on|off`、配置变更、切换模式都会重置快照。
10
+ - **「最近动态」拆成独立 runtime-context 段**(order 900):boot 块只含 SOUL/MEMORY/index + 语气段,log 尾部单独注入;会话中途 digest 只让这段尾部变更,缓存失效范围从「整段前缀」缩到「尾部」。
11
+ - **双击记忆节点 → 在 DSH 右侧栏打开该 md 文件**(兼容 macOS / Windows / Linux):客户端调用 `ctx.sidebarRight.openResource` 打开 `file` 资源;服务不可用或失败时自动回退「在 Finder/资源管理器中显示」。
12
+
13
+ ### Changed
14
+
15
+ - 图谱双击行为:由「直接 reveal」改为「优先侧栏打开、失败回退 reveal」;选中节点仍保留「在 Finder 中显示 / 复制路径」按钮。
16
+
17
+ ## [0.17.9] - 2026-11-06
18
+
19
+ ### Fixed
20
+
21
+ - **「保存人格」按钮在深色主题下变成全白块**:按钮背景用了 `--dsw-alias-brand-primary`(深色主题映射为白色),文字又是写死的白色 → 白底白字。改为与宿主一致的反色主按钮:主文字色填充 + 背景色文字(深色主题=浅底深字、浅色主题=深底浅字)。
22
+
5
23
  ## [0.17.8] - 2026-11-06
6
24
 
7
25
  ### Fixed
package/README.md CHANGED
@@ -43,7 +43,7 @@ then install **Memory** from the list. (A JSON index in the official format, ser
43
43
  - **You stay in control** — per-session switch (chip / `/memory on|off` / panel) and `disabledWorkspaces` defaults.
44
44
  - **A companion** — digest nudge, proactive recall, weekly growth recap, context-sensitive tone; shared speech floor with other proactive plugins.
45
45
  - **Portable** — plain markdown + git, `pack`/`unpack`, optional auto-commit.
46
- - **Memory graph** — interactive 3D sphere: rotate / zoom / drag nodes, search-to-focus, hover or click to light up neighbours; select a node → **Reveal in Finder** or **Copy path**.
46
+ - **Memory graph** — interactive 3D sphere: rotate / zoom / drag nodes, search-to-focus, hover or click to light up neighbours; select a node → **Reveal in Finder** or **Copy path**; **double-click a node to open its file in the DSH sidebar** (falls back to the OS file manager).
47
47
  - **Health tools** — dashboard, `checkup`, `lint`, `doctor`, automatic `last_access` stamping.
48
48
  - **Zero build, bilingual panel, hot-editable config.**
49
49
 
@@ -67,7 +67,7 @@ then install **Memory** from the list. (A JSON index in the official format, ser
67
67
 
68
68
  ## Configuration
69
69
 
70
- Sixteen hot keys edit live under **Settings → Memory**. The full table, boot-budget rules and composition overrides are in [docs/CONFIGURATION.md](docs/CONFIGURATION.md).
70
+ Seventeen hot keys edit live under **Settings → Memory** — including `bootSnapshot` (`live` by default; `session` freezes the boot block for the session so mid-session writes can't invalidate the prompt-prefix cache). The full table, boot-budget rules and composition overrides are in [docs/CONFIGURATION.md](docs/CONFIGURATION.md).
71
71
 
72
72
  ## CLI
73
73
 
package/README.zh.md CHANGED
@@ -43,7 +43,7 @@ https://raw.githubusercontent.com/LittleBlackTong/dsh-plugin-memory/main/docs/ma
43
43
  - **你说了算** —— 会话级开关(chip / `/memory on|off` / 面板)+ `disabledWorkspaces` 工作区默认。
44
44
  - **像个搭子** —— digest 提醒、主动追忆、每周成长回顾、按语境调语气;与其它主动插件共享发言权仲裁。
45
45
  - **可迁移** —— 纯 markdown + git,`pack`/`unpack` 搬家,可选自动提交。
46
- - **记忆图谱** —— 可交互 3D 球面:旋转/缩放/拖节点整理、搜索定位、悬停或点击点亮邻居;选中节点可 **在 Finder 中显示** 或 **复制路径**。
46
+ - **记忆图谱** —— 可交互 3D 球面:旋转/缩放/拖节点整理、搜索定位、悬停或点击点亮邻居;选中节点可 **在 Finder 中显示** 或 **复制路径**;**双击节点直接在 DSH 侧栏打开该文件**(打不开时回退系统文件管理器)。
47
47
  - **健康工具** —— 看板、`checkup`、`lint`、`doctor`、自动 `last_access`。
48
48
  - **零构建、面板双语、配置热改。**
49
49
 
@@ -67,7 +67,7 @@ https://raw.githubusercontent.com/LittleBlackTong/dsh-plugin-memory/main/docs/ma
67
67
 
68
68
  ## 配置
69
69
 
70
- 十六个热改项在 **设置 → 记忆** 里即时生效。完整配置表、boot 预算规则与组合层覆盖示例见 [docs/CONFIGURATION.md](docs/CONFIGURATION.md)。
70
+ 十七个热改项在 **设置 → 记忆** 里即时生效——含 `bootSnapshot`(默认 `live`;设为 `session` 会在本会话固化 boot 块,会话中途写记忆不再让前缀缓存失效)。完整配置表、boot 预算规则与组合层覆盖示例见 [docs/CONFIGURATION.md](docs/CONFIGURATION.md)。
71
71
 
72
72
  ## CLI
73
73
 
@@ -20,6 +20,7 @@ All keys below are read from the composition layer (`cordis.patch.yml`) unless m
20
20
  | `growthRecapEnabled` **hot** | `true` | Weekly growth recap on the recall channel |
21
21
  | `growthRecapIntervalDays` **hot** | `7` | Days between growth recaps |
22
22
  | `disabledWorkspaces` **hot** | `[]` | Session cwd patterns that default to memory off (`~` expanded, path-boundary match, case-insensitive on Windows) |
23
+ | `bootSnapshot` **hot** | `live` | `live` re-reads the store every turn; `session` freezes the boot block for the session (mid-session writes apply from the next session) so the prompt-prefix cache stays hit |
23
24
  | `bootFiles` | `[SOUL.md, MEMORY.md, index.md]` | Files injected at session start |
24
25
  | `bootMaxChars` | `12000` | Total boot-block character budget |
25
26
  | `bootFileBudgets` | — | Per-file caps, e.g. `{ index.md: 3500 }` |
@@ -38,7 +39,7 @@ All keys below are read from the composition layer (`cordis.patch.yml`) unless m
38
39
 
39
40
  ## Settings panel
40
41
 
41
- Sixteen **hot** keys are editable under **Settings → Memory** and apply immediately: `enabled`, `memoryDir`, `autoInject`, `deferUntilUserSpeaks`, `activeSessionOnly`, `registerSkill`, `recallEnabled`, `recallIntervalMinMinutes`, `recallIntervalMaxMinutes`, `recallMaxPerSession`, `proactiveCooldownSeconds`, `toneGuideEnabled`, `toneIntensity`, `growthRecapEnabled`, `growthRecapIntervalDays`, `disabledWorkspaces`. Changing `memoryDir` scaffolds the new store automatically (when `scaffold: true`). Everything else is composition-layer and needs a restart.
42
+ Seventeen **hot** keys are editable under **Settings → Memory** and apply immediately: `enabled`, `memoryDir`, `autoInject`, `bootSnapshot`, `deferUntilUserSpeaks`, `activeSessionOnly`, `registerSkill`, `recallEnabled`, `recallIntervalMinMinutes`, `recallIntervalMaxMinutes`, `recallMaxPerSession`, `proactiveCooldownSeconds`, `toneGuideEnabled`, `toneIntensity`, `growthRecapEnabled`, `growthRecapIntervalDays`, `disabledWorkspaces`. Changing `memoryDir` scaffolds the new store automatically (when `scaffold: true`). Everything else is composition-layer and needs a restart.
42
43
 
43
44
  The panel also has a **Review now** button (a control, not a setting): it sends one growth recap immediately, still respecting the shared speech floor, and reports the outcome (sending / sent / deferred / session busy / no content / disabled / failed) for 5 seconds.
44
45
 
@@ -26,8 +26,8 @@
26
26
  },
27
27
  "versions": [
28
28
  {
29
- "version": "0.17.7",
30
- "publishTimestamp": 1793957459,
29
+ "version": "0.17.9",
30
+ "publishTimestamp": 1793958188,
31
31
  "source": {
32
32
  "type": "npm"
33
33
  },
package/lib/boot.js CHANGED
@@ -25,6 +25,24 @@ export const DEFAULT_BOOT_FILES = ['SOUL.md', 'MEMORY.md', 'index.md']
25
25
  * signal, and this block is injected on every request. */
26
26
  export const RECENT_LOG_COUNT = 3
27
27
 
28
+ /**
29
+ * Render the recent-activity section on its own.
30
+ *
31
+ * It moved out of `renderBootBlock` so a boot snapshot can stay frozen for a
32
+ * whole session while the volatile tail (new log entries) rides in a separate
33
+ * runtime-context segment later in the prompt (order 900 vs -200), keeping
34
+ * prompt-prefix cache misses small (issue #8).
35
+ */
36
+ export function renderRecentActivity(memoryDir, options = {}) {
37
+ const count = Number.isInteger(options.count) && options.count > 0 ? options.count : RECENT_LOG_COUNT
38
+ const logPath = join(memoryDir, 'log.md')
39
+ const logEntries = existsSync(logPath)
40
+ ? parseLogEntries(readTailCapped(logPath, 4096) ?? '', count)
41
+ : []
42
+ if (logEntries.length === 0) return ''
43
+ return `### 最近动态(log.md 末尾 ${logEntries.length} 条)\n\n${logEntries.map((e) => `- ${e}`).join('\n')}`
44
+ }
45
+
28
46
  /** Separator joining the boot-block sections. */
29
47
  const SECTION_SEPARATOR = '\n\n---\n\n'
30
48
 
@@ -293,14 +311,10 @@ export function renderBootBlock(memoryDir, options = {}) {
293
311
 
294
312
  if (sections.length === 0) return ''
295
313
 
296
- // Read the tail: log.md is append-only, so the head is ancient history.
297
- const logPath = join(memoryDir, 'log.md')
298
- const logEntries = existsSync(logPath)
299
- ? parseLogEntries(readTailCapped(logPath, 4096) ?? '', RECENT_LOG_COUNT)
300
- : []
301
- if (logEntries.length > 0) {
302
- sections.push(`### 最近动态(log.md 末尾 ${logEntries.length} 条)\n\n${logEntries.map((e) => `- ${e}`).join('\n')}`)
303
- }
314
+ const recent = options.includeRecentActivity === false
315
+ ? ''
316
+ : renderRecentActivity(memoryDir, { count: RECENT_LOG_COUNT })
317
+ if (recent.length > 0) sections.push(recent)
304
318
 
305
319
  const body = sections.join(SECTION_SEPARATOR)
306
320
  const header = `长期记忆(dsh-plugin-memory)。记忆库位于 ${memoryDir}。这是你跨会话的持久人格与记忆:以它为准,先读完再回复用户。若与当前对话冲突,优先相信用户的最新表述,并把差异写回记忆。**每次会话收尾前必须执行 memory digest:把本会话关键沉淀写回(更新页面 + index.md + 追加 log.md)。插件会注入 digest 提醒消息,收到后立即写回,不得拖延;若本会话确无值得持久化的内容,在 log.md 记一条「无新增」并说明原因。**`
package/lib/client.js CHANGED
@@ -55,6 +55,8 @@ window.__ModuleLoader__.load({
55
55
  deferUntilUserSpeaksHint: '开启后,新会话在你发出第一条消息前不会注入任何记忆 / 追忆 / digest 提醒',
56
56
  activeSessionOnly: '仅当前激活会话注入',
57
57
  activeSessionOnlyHint: '开启后,只有最近收到你消息的会话才会注入记忆(后台会话不打扰)',
58
+ bootSnapshot: '固化 boot 快照',
59
+ bootSnapshotHint: '开启后本会话内不再重读记忆库,会话中途写入的改动下个会话才生效(省前缀缓存);关闭=每轮实时重读',
58
60
  registerSkill: '注册 memory 技能',
59
61
  registerSkillHint: '让 agent 获得 remember / recall / consolidate / forget 操作协议',
60
62
  recall: '主动追忆',
@@ -210,6 +212,8 @@ window.__ModuleLoader__.load({
210
212
  deferUntilUserSpeaksHint: 'When on, a new session injects no memory / recall / digest reminder before your first message',
211
213
  activeSessionOnly: 'Inject into the active session only',
212
214
  activeSessionOnlyHint: 'When on, only the session that most recently received a message from you gets memory (background sessions are left alone)',
215
+ bootSnapshot: 'Pin boot snapshot',
216
+ bootSnapshotHint: 'On: freeze the boot block for this session — memory written mid-session applies from the next session (saves prompt-cache misses); off: re-read live every turn',
213
217
  registerSkill: 'Register the memory skill',
214
218
  registerSkillHint: 'Give the agent the remember / recall / consolidate / forget protocol',
215
219
  recall: 'Proactive recall',
@@ -905,9 +909,13 @@ window.__ModuleLoader__.load({
905
909
  fontSize: '13px',
906
910
  lineHeight: '18px',
907
911
  borderRadius: '6px',
908
- border: '1px solid var(--dsw-alias-border-l2, #d4d4d8)',
909
- background: 'var(--dsw-alias-brand-primary, #4c8bf5)',
910
- color: '#fff',
912
+ border: '1px solid transparent',
913
+ // Host-style inverted primary button: label-primary fill with a
914
+ // background-coloured label. Dark theme = light button + dark text,
915
+ // light theme = dark button + light text. Brand-primary maps to white
916
+ // on dark themes, which turned this into an unreadable white block.
917
+ background: 'var(--dsw-alias-label-primary, #1f2328)',
918
+ color: 'var(--dsw-alias-bg-layer-1, #ffffff)',
911
919
  cursor: busy ? 'not-allowed' : 'pointer',
912
920
  opacity: busy ? 0.6 : 1,
913
921
  },
@@ -1327,6 +1335,18 @@ window.__ModuleLoader__.load({
1327
1335
  onChange: (next) => apply({ autoInject: next }),
1328
1336
  }),
1329
1337
  ),
1338
+ React.createElement('div', { style: rowStyle },
1339
+ React.createElement('div', null,
1340
+ React.createElement('div', { style: labelStyle }, t('bootSnapshot')),
1341
+ React.createElement('div', { style: subStyle }, t('bootSnapshotHint')),
1342
+ ),
1343
+ React.createElement(Toggle, {
1344
+ label: t('bootSnapshot'),
1345
+ checked: value.bootSnapshot === 'session',
1346
+ disabled,
1347
+ onChange: (next) => apply({ bootSnapshot: next ? 'session' : 'live' }),
1348
+ }),
1349
+ ),
1330
1350
  React.createElement('div', { style: rowStyle },
1331
1351
  React.createElement('div', null,
1332
1352
  React.createElement('div', { style: labelStyle }, t('deferUntilUserSpeaks')),
@@ -2018,6 +2038,41 @@ window.__ModuleLoader__.load({
2018
2038
  })
2019
2039
  }
2020
2040
 
2041
+ /** 双击节点:优先在 DSH 右侧栏打开该 md 文件;不可用时回退系统文件管理器。 */
2042
+ const openInSidebar = async (id) => {
2043
+ const sidebar = sidebarRightService
2044
+ if (!sidebar || typeof sidebar.openResource !== 'function') return false
2045
+ const pathInfo = await fetch(`${GRAPH_PATH_URL}?id=${encodeURIComponent(id)}`)
2046
+ .then((response) => response.json())
2047
+ .catch(() => null)
2048
+ if (!pathInfo || pathInfo.ok !== true || typeof pathInfo.path !== 'string') return false
2049
+ const absolute = pathInfo.path.replace(/\\/g, '/')
2050
+ const session = await fetch(SESSION_URL)
2051
+ .then((response) => response.json())
2052
+ .catch(() => null)
2053
+ if (!session || session.ok !== true || typeof session.sessionId !== 'string') return false
2054
+ const root = typeof session.cwd === 'string' && session.cwd.length > 0
2055
+ ? session.cwd.replace(/\\/g, '/').replace(/\/+$/, '')
2056
+ : undefined
2057
+ const encodePath = (path) => path.split('/')
2058
+ .map((segment, index) => (index === 0 && /^[A-Za-z]:$/.test(segment) ? segment : encodeURIComponent(segment)))
2059
+ .join('/')
2060
+ let address
2061
+ if (root !== undefined && (absolute === root || absolute.startsWith(`${root}/`))) {
2062
+ const relative = absolute.slice(root.length).replace(/^\/+/, '')
2063
+ address = `dsh-resource://file/session/${encodeURIComponent(session.sessionId)}/${encodePath(relative)}`
2064
+ } else {
2065
+ address = `dsh-resource://file/absolute/${encodePath(absolute.replace(/^\/+/, ''))}`
2066
+ }
2067
+ await sidebar.openResource(address)
2068
+ return true
2069
+ }
2070
+ const openNode = (id) => {
2071
+ openInSidebar(id)
2072
+ .then((opened) => { if (!opened) revealNode(id) })
2073
+ .catch(() => revealNode(id))
2074
+ }
2075
+
2021
2076
  React.useEffect(() => { stateRef.current.selected = selected }, [selected])
2022
2077
  React.useEffect(() => { stateRef.current.spin = spin }, [spin])
2023
2078
 
@@ -2155,7 +2210,7 @@ window.__ModuleLoader__.load({
2155
2210
  if (hit !== null) {
2156
2211
  stateRef.current.selected = hit.id
2157
2212
  setSelected(hit.id)
2158
- revealNode(hit.id)
2213
+ openNode(hit.id)
2159
2214
  return
2160
2215
  }
2161
2216
  stateRef.current.view = { yaw: 0.55, pitch: -0.2, zoom: 1 }
@@ -2412,6 +2467,8 @@ window.__ModuleLoader__.load({
2412
2467
  // 挂载后按 label 认出自己那一行,藏掉齿轮、用 mask 画自己的标记。
2413
2468
  // 官方哪天给 settings.section 长出 icon 字段,这段即可删除。
2414
2469
  const NAV_ROW_SELECTOR = '[role="dialog"] nav button'
2470
+ // Right-sidebar navigation service (0.18.0, DSH ≥ 0.2.2); undefined on older hosts.
2471
+ let sidebarRightService
2415
2472
  const NAV_ICON_ATTR = 'data-dsh-memory-nav-icon'
2416
2473
  // The label is resolved from DICTS by `sectionLabel(language)`: it is both the
2417
2474
  // displayed text and the claim key, so both must come from that one function.
@@ -2478,6 +2535,13 @@ window.__ModuleLoader__.load({
2478
2535
  }
2479
2536
 
2480
2537
  function apply(ctx) {
2538
+ // Right-sidebar navigation (double-click a graph node opens the file in
2539
+ // the sidebar). Optional service: older hosts just fall back to reveal.
2540
+ try {
2541
+ sidebarRightService = ctx.get?.('sidebarRight') ?? ctx.sidebarRight ?? undefined
2542
+ } catch {
2543
+ sidebarRightService = undefined
2544
+ }
2481
2545
  // Language packs ride DSH's own locale layer: the panel follows
2482
2546
  // 设置 → 通用设置 → 语言 instead of guessing from navigator.language.
2483
2547
  ctx.effect(() => ctx.locale.register(LOCALE_NS, DICTS), 'memory: dictionaries')
@@ -23,7 +23,7 @@ export function defaultConfigPath() {
23
23
  return join(process.env.DSH_HOME || join(homedir(), '.dsh'), MEMORY_CONFIG_FILENAME)
24
24
  }
25
25
 
26
- const FIELDS = ['enabled', 'memoryDir', 'autoInject', 'registerSkill', 'deferUntilUserSpeaks', 'activeSessionOnly', 'recallEnabled', 'recallIntervalMinMinutes', 'recallIntervalMaxMinutes', 'recallMaxPerSession', 'proactiveCooldownSeconds', 'toneGuideEnabled', 'toneIntensity', 'growthRecapEnabled', 'growthRecapIntervalDays', 'disabledWorkspaces']
26
+ const FIELDS = ['enabled', 'memoryDir', 'autoInject', 'registerSkill', 'deferUntilUserSpeaks', 'activeSessionOnly', 'recallEnabled', 'recallIntervalMinMinutes', 'recallIntervalMaxMinutes', 'recallMaxPerSession', 'proactiveCooldownSeconds', 'toneGuideEnabled', 'toneIntensity', 'growthRecapEnabled', 'growthRecapIntervalDays', 'disabledWorkspaces', 'bootSnapshot']
27
27
 
28
28
  /** Tone intensity values the schema accepts; invalid composition input falls back to low. */
29
29
  const TONE_INTENSITIES = ['low', 'medium', 'off']
@@ -72,6 +72,7 @@ export class MemoryConfigStore {
72
72
  growthRecapEnabled: options.base?.growthRecapEnabled !== false,
73
73
  growthRecapIntervalDays: options.base?.growthRecapIntervalDays ?? 7,
74
74
  disabledWorkspaces: Array.isArray(options.base?.disabledWorkspaces) ? options.base.disabledWorkspaces : [],
75
+ bootSnapshot: options.base?.bootSnapshot === 'session' ? 'session' : 'live',
75
76
  }
76
77
  this.config = { ...this.base }
77
78
  this.watchers = new Set()
@@ -109,6 +110,7 @@ export class MemoryConfigStore {
109
110
  growthRecapEnabled: resolved.growthRecapEnabled,
110
111
  growthRecapIntervalDays: resolved.growthRecapIntervalDays,
111
112
  disabledWorkspaces: resolved.disabledWorkspaces,
113
+ bootSnapshot: resolved.bootSnapshot,
112
114
  }
113
115
  } catch {
114
116
  // schema validation failed: keep last good config
@@ -154,6 +156,7 @@ export class MemoryConfigStore {
154
156
  growthRecapEnabled: next.growthRecapEnabled,
155
157
  growthRecapIntervalDays: next.growthRecapIntervalDays,
156
158
  disabledWorkspaces: next.disabledWorkspaces,
159
+ bootSnapshot: next.bootSnapshot,
157
160
  }
158
161
  this.persist()
159
162
  for (const watcher of this.watchers) {
package/lib/index.js CHANGED
@@ -88,7 +88,7 @@
88
88
  import { homedir } from 'node:os'
89
89
  import { join, resolve } from 'node:path'
90
90
  import z from '@deepseek-ai/schemastery'
91
- import { renderBootBlock, DEFAULT_BOOT_FILES, needsSoulBootstrap, readBootstrapStatus } from './boot.js'
91
+ import { renderBootBlock, renderRecentActivity, DEFAULT_BOOT_FILES, needsSoulBootstrap, readBootstrapStatus } from './boot.js'
92
92
  import {
93
93
  accessSummary,
94
94
  extractReferencedPages,
@@ -155,6 +155,9 @@ export const Config = z.object({
155
155
  // file takes at most twice the even share (see allocateBootBudget).
156
156
  bootFileBudgets: z.union([z.dict(z.number()), z.const(undefined)]),
157
157
  autoInject: z.boolean().default(true),
158
+ // 0.18.0 (issue #8): `session` freezes the boot block until the session ends;
159
+ // `live` re-reads the store every turn (0.17 behaviour).
160
+ bootSnapshot: z.union([z.const('live'), z.const('session')]).default('live'),
158
161
  registerSkill: z.boolean().default(true),
159
162
  scaffold: z.boolean().default(true),
160
163
  configFile: z.union([z.string(), z.const(undefined)]),
@@ -305,6 +308,7 @@ export function apply(ctx, config = {}) {
305
308
  }
306
309
  if (arg === 'on' || arg === 'off') {
307
310
  sessionGate.setOverride(agent.id, arg === 'on', cwd)
311
+ bootSnapshots.delete(agent.id)
308
312
  return { kind: 'success', text: `Memory is now ${arg.toUpperCase()} for this session.` }
309
313
  }
310
314
  if (arg === 'workspace-off' || arg === 'workspace-on') {
@@ -322,16 +326,34 @@ export function apply(ctx, config = {}) {
322
326
  }
323
327
 
324
328
  let bootDispose
329
+ let recentDispose
325
330
  let skillDispose
326
331
  let scaffoldedDir
327
332
  let committer
328
333
  let currentMemoryDir = resolveMemoryDir(store.get().memoryDir)
329
334
 
335
+ // 0.18.0 (issue #8): with `bootSnapshot: session` the rendered boot text is
336
+ // frozen per agent, so a mid-session digest cannot invalidate the prompt
337
+ // prefix. Cleared on config changes and on any /memory on|off toggle.
338
+ const bootSnapshots = new Map()
339
+ const clearBootSnapshots = () => bootSnapshots.clear()
340
+ const snapshotSignature = (resolved, dir) => [
341
+ dir,
342
+ JSON.stringify(bootFiles),
343
+ bootMaxChars,
344
+ JSON.stringify(bootFileBudgets ?? null),
345
+ resolved.toneGuideEnabled === false ? 'off' : String(resolved.toneIntensity ?? 'low'),
346
+ ].join('|')
347
+
330
348
  const disposeBoot = () => {
331
349
  if (bootDispose !== undefined) {
332
350
  bootDispose()
333
351
  bootDispose = undefined
334
352
  }
353
+ if (recentDispose !== undefined) {
354
+ recentDispose()
355
+ recentDispose = undefined
356
+ }
335
357
  }
336
358
 
337
359
  const disposeSkill = () => {
@@ -404,7 +426,37 @@ export function apply(ctx, config = {}) {
404
426
  const toneGuide = resolved.toneGuideEnabled
405
427
  ? buildToneGuide({ intensity: resolved.toneIntensity, language: 'zh' })
406
428
  : ''
407
- return renderBootBlock(memoryDir, { bootFiles, bootMaxChars, bootFileBudgets, toneGuide })
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
445
+ }
446
+ return renderBootBlock(memoryDir, options)
447
+ },
448
+ })
449
+ // The volatile tail (recent log entries) lives in its own segment with a
450
+ // late order, so a mid-session digest changes only that suffix.
451
+ recentDispose = ctx.systemPrompt.context({
452
+ name: 'memory-recent',
453
+ order: 900,
454
+ 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)
408
460
  },
409
461
  })
410
462
  } else {
@@ -604,7 +656,7 @@ export function apply(ctx, config = {}) {
604
656
 
605
657
  // Settings-panel hot edits: any store change re-applies the config.
606
658
  ctx.effect(() => {
607
- const unwatch = store.watch(() => rebuild())
659
+ const unwatch = store.watch(() => { clearBootSnapshots(); rebuild() })
608
660
  return () => {
609
661
  unwatch()
610
662
  }
@@ -743,6 +795,8 @@ export function apply(ctx, config = {}) {
743
795
  sendJson(200, { ok: false, reason: 'no-session' })
744
796
  return
745
797
  }
798
+ // A gate change invalidates the frozen boot text for this agent.
799
+ bootSnapshots.delete(agent.id)
746
800
  sendJson(200, { ok: true, ...describeSession(agent, store.get()) })
747
801
  return
748
802
  }
package/lib/schema.js CHANGED
@@ -36,4 +36,8 @@ export const SettingsSchema = z.object({
36
36
  // Workspaces that default to memory off (session gate layer 3). A session
37
37
  // inside one of these roots starts muted until the user turns it back on.
38
38
  disabledWorkspaces: z.array(z.string()).default([]),
39
+ // 0.18.0: freeze the boot block for the whole session so mid-session writes
40
+ // do not invalidate the prompt-prefix cache (issue #8). `live` keeps the
41
+ // 0.17 behaviour of re-reading the store on every turn.
42
+ bootSnapshot: z.union([z.const('live'), z.const('session')]).default('live'),
39
43
  })
@@ -77,6 +77,12 @@ export interface MemoryConfig {
77
77
  * Default `[]`.
78
78
  */
79
79
  disabledWorkspaces?: string[]
80
+ /**
81
+ * `session` — freeze the rendered boot block for the whole session so a
82
+ * mid-session digest cannot invalidate the prompt-prefix cache (issue #8);
83
+ * `live` (default) — re-read the store on every turn.
84
+ */
85
+ bootSnapshot?: 'live' | 'session'
80
86
  /** Where per-session overrides live (default `<dshHome>/memory-sessions.json`). */
81
87
  sessionStateFile?: string
82
88
  /** Days a session override stays valid before it is pruned. Default `7`. */
@@ -134,6 +140,8 @@ export interface MemorySettings {
134
140
  growthRecapEnabled?: boolean
135
141
  growthRecapIntervalDays?: number
136
142
  disabledWorkspaces?: string[]
143
+ /** `live` (default) re-reads every turn; `session` freezes the boot block. */
144
+ bootSnapshot?: 'live' | 'session'
137
145
  }
138
146
 
139
147
  /** Schemastery schema for {@link MemorySettings}. */
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.17.8",
4
+ "version": "0.18.0",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "lib/index.js",