dsh-engramory 1.2.0 → 1.3.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.
package/README.en.md CHANGED
@@ -13,11 +13,14 @@ which is general-purpose agent memory: Claude Code, Codex and others can use the
13
13
 
14
14
  ## What it does
15
15
 
16
- - **The memory index rides along on every step.** The index, `MEMORY.md`, lists the
17
- notes by name. The plugin puts it into dsh's context on every step, so the AI knows
16
+ - **The memory index comes along by itself.** The index, `MEMORY.md`, lists the notes
17
+ by name. The plugin brings it into the conversation as a message, so the AI knows
18
18
  what it has saved without reading a file first, and opens a note when it needs the
19
- detail. A write shows up on the next request; whatever is past the cap is left
20
- out, and the AI is told to compact.
19
+ detail. It is sent again only when it changes (a write, another project, a
20
+ compacted conversation): a write shows up on the next request, and a long
21
+ conversation does not fill up with copies of it ([social mode](#social-mode) keeps it
22
+ in dsh's runtime context, as before). Whatever is past the cap is left out, and the AI
23
+ is told to compact.
21
24
  - **The index has a hard cap.** 200 lines / 25 KB by default. When the AI writes the
22
25
  index with dsh's file tools and the plugin can work out the result, a write that
23
26
  would grow it past the cap is refused before it happens, and the AI is told to
@@ -34,8 +37,8 @@ which is general-purpose agent memory: Claude Code, Codex and others can use the
34
37
 
35
38
  ## Install
36
39
 
37
- Needs Node.js 18+ and `pnpm` on PATH (dsh's plugin command uses it). In dsh's desktop
38
- app you can also search for `dsh-engramory` on the Plugins page.
40
+ Needs Node.js 22.12+ (what dsh itself needs) and `pnpm` on PATH (dsh's plugin command uses
41
+ it). In dsh's desktop app you can also search for `dsh-engramory` on the Plugins page.
39
42
 
40
43
  ```sh
41
44
  dsh plugin --profile <name> add dsh-engramory
@@ -79,7 +82,8 @@ companion switch on the settings page, or set `companion: true`.
79
82
  - **Recall in character.** Even a greeting may call for recall, and what it remembered,
80
83
  or failed to save, is told in the character's voice, without naming files or tools.
81
84
  - **The persona preset needs the file tools.** The memory arrives even under a preset
82
- that turns optional context off (dsh's `minimal`, for one). To save notes, though, the
85
+ that turns optional context off (dsh's `minimal`, for one; from dsh 0.2 — 0.1 then sends
86
+ no runtime context at all). To save notes, though, the
83
87
  preset needs dsh's file tools and the skill tool; a preset with only a shell reads the
84
88
  memory, and its writes go past the cap.
85
89
 
@@ -99,9 +103,11 @@ theirs, and the memory already put into it stays in its history.
99
103
 
100
104
  Someone else's conversation gets no index and is not told where the store is; dsh's
101
105
  file tools there may name files only (every directory is refused), and any path into
102
- a store is refused however it is spelled. This is **not** a security boundary: a shell
103
- tool reads any file, and another profile on the same account can read the store too.
104
- Real isolation needs filesystem permissions or a sandbox. A custom `skill` (see
106
+ a store is refused however it is spelled; dsh's session search (an optional, experimental
107
+ feature that reads the records of other conversations in the same directory) is refused
108
+ there outright. This is **not** a security boundary: a shell tool reads any file, and
109
+ another profile on the same account can read the store too. Real isolation needs
110
+ filesystem permissions or a sandbox. A custom `skill` (see
105
111
  [Configuration](#configuration)) reaches every conversation as written, someone else's
106
112
  included, so if it says where the store is, they are told too.
107
113
 
@@ -181,12 +187,12 @@ caps in force. A patch replaces the row's whole `config`, so list every key you
181
187
 
182
188
  | Field | Default | Meaning |
183
189
  |---|---|---|
184
- | `indexName` | `MEMORY.md` | The file name treated as the index. The cap matches it case-insensitively; putting the index into context needs the exact name on a case-sensitive filesystem (Linux, say). |
190
+ | `indexName` | `MEMORY.md` | The file name treated as the index. The cap matches it case-insensitively; sending the index needs the exact name on a case-sensitive filesystem (Linux, say). An index not named `.md` is shown in its folder by the memory page's *Open the index*, never opened in the default app. |
185
191
  | `maxLines` | `200` | Line cap for the index. |
186
192
  | `maxBytes` | `25600` | UTF-8 byte cap for the index (25 KB). |
187
193
  | `indexPath` | unset | The one index to use: absolute, or relative to the session's directory. Unset, a `MEMORY.md` in any project is capped as an index; a store outside the default places also needs it to be found. |
188
- | `registerSkill` | `true` | `false` skips the built-in rules; the cap and the index in context stay. |
189
- | `injectIndex` | `true` | `false` stops putting the index into context; the AI reads it instead. |
194
+ | `registerSkill` | `true` | `false` skips the built-in rules; the cap and the index sent along stay. |
195
+ | `injectIndex` | `true` | `false` stops sending the index; the AI reads it instead. |
190
196
  | `compactionReminder` | `true` | `false` stops the reminder to save before dsh compacts. The plugin works out where dsh will compact from dsh's own compaction settings (on dsh 0.2 with DeepSeek's defaults, about 69% of the window, not 80%) and reminds at 85% of that. A best effort: a conversation that grows past the gap in one step goes unreminded; with no compaction, or automatic compaction off, there is no reminder. |
191
197
  | `language` | dsh's | `zh` (or `zh-CN` and other regional forms) writes the store in Chinese: note names, headings such as `## 用户`, the Why/How labels. Any other string is English; a value that is not a string, or is empty, counts as unset. Unset, it follows dsh's language; a change applies once dsh restarts. Frontmatter keys and `type:` values stay English, so every host reads the store. |
192
198
  | `companion` | `false` | `true` turns companion mode on. |
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  ## 它做什么
12
12
 
13
- - **每轮自动带上记忆索引。** 索引 `MEMORY.md` 只列笔记名字,插件每一步都把它放进上下文,AI 不用先读文件就知道自己记过什么,要细节再打开那条笔记。写入后下一轮就能看到;超出上限的部分不带上,并提醒 AI 压缩。
13
+ - **自动带上记忆索引。** 索引 `MEMORY.md` 只列笔记名字,插件把它作为一条消息带进对话,AI 不用先读文件就知道自己记过什么,要细节再打开那条笔记。索引变了才再带一次(写入了、换到别的项目、对话被压缩过):写入后下一步就能看到,长对话里也不会堆出一份份重复的索引([社交模式](#社交模式)照旧放在 dsh 的运行时上下文里)。超出上限的部分不带上,并提醒 AI 压缩。
14
14
  - **索引有硬上限。** 默认 200 行 / 25 KB。AI 用 dsh 的文件工具写索引时,只要插件算得出写完的样子,会超上限就在写入前拒绝,让它先压缩;压缩照样放行。细节见[上限怎么判](#上限怎么判)。
15
15
  - **自带记忆规则。** 记什么、怎么记、什么时候清理,这套规则(skill)随插件注册,不用另外装文件。
16
16
  - **快压缩时提醒 AI 存记忆。** dsh 会在对话太长时把前面压缩成摘要,摘要不一定留得下以后还用得着的东西。对话快到 dsh 要压缩的地方时,插件提醒 AI 把值得长期记住的先存进记忆;提醒的是 AI,不打扰你。
@@ -18,7 +18,7 @@
18
18
 
19
19
  ## 安装
20
20
 
21
- 需要 Node.js 18+,PATH 里要有 `pnpm`(dsh 的插件命令要用)。dsh 桌面版也可以在插件页搜 `dsh-engramory` 安装。
21
+ 需要 Node.js 22.12+(dsh 本身的要求),PATH 里要有 `pnpm`(dsh 的插件命令要用)。dsh 桌面版也可以在插件页搜 `dsh-engramory` 安装。
22
22
 
23
23
  ```sh
24
24
  dsh plugin --profile <名字> add dsh-engramory
@@ -43,7 +43,7 @@ dsh plugin --profile <名字> add dsh-engramory
43
43
 
44
44
  - **多记三类角色自己的事**([SKILL.md §2.2](https://github.com/tinqiao-oss/engramory/blob/master/SKILL.md)):`moment`(经历)是和你一起经历的事,带日期,索引满了按月归档;`upcoming`(约定)是你将要发生的事,日子过了会问起结果,问到了再改写成经历;`self`(我自己)是角色自己的变化,比如外号。经历和我自己只有你说忘掉才删。
45
45
  - **用角色口吻回忆。** 打招呼也可能让它想起点什么;记住了、没记上,都用角色的话说,不提文件和工具。
46
- - **人设预设要留着文件工具。** 记忆总会送到,哪怕预设关掉了可选上下文(比如 dsh 的 `minimal`)。但角色要保存记忆,预设得带上 dsh 的文件工具和 skill 工具;只给了 shell 的预设读得到记忆,写入却绕过上限。
46
+ - **人设预设要留着文件工具。** 记忆总会送到,哪怕预设关掉了可选上下文(比如 dsh 的 `minimal`;dsh 0.2 起,0.1 这时什么上下文都不带)。但角色要保存记忆,预设得带上 dsh 的文件工具和 skill 工具;只给了 shell 的预设读得到记忆,写入却绕过上限。
47
47
 
48
48
  ## 社交模式
49
49
 
@@ -51,7 +51,7 @@ dsh plugin --profile <名字> add dsh-engramory
51
51
 
52
52
  打开后,**只有你本人的会话拿得到记忆**:你在 dsh 自己的窗口(桌面版或 `dsh web`)里亲手发过消息、且没有别人说过话的会话才算你的。子 agent 跟着它的父会话算。接入插件转来的消息(标明是主人的除外,见下文)、`dsh headless`、外部程序、终端和编辑器客户端发的都算别人的;一个会话只要有别人说过话,就一直算别人的,之前已经带进去的记忆仍留在对话记录里。
53
53
 
54
- 别人的会话拿不到索引,也不知道记忆库在哪;dsh 的文件工具只能指名文件(任何目录都不让列),指向记忆库的路径不管怎么写都拒绝。这**不是**安全边界:shell 工具照样能读任何文件,同一账户下的另一个 profile 也读得到。要真正隔离,得靠文件权限或沙箱。自定义的 `skill`(见[配置](#配置))会原样给所有会话,别人的也一样,里面写了库在哪,别人也看得到。
54
+ 别人的会话拿不到索引,也不知道记忆库在哪;dsh 的文件工具只能指名文件(任何目录都不让列),指向记忆库的路径不管怎么写都拒绝;dsh 的会话搜索(可选的实验功能,能读同一目录下其他会话的记录)在别人的会话里一律不能用。这**不是**安全边界:shell 工具照样能读任何文件,同一账户下的另一个 profile 也读得到。要真正隔离,得靠文件权限或沙箱。自定义的 `skill`(见[配置](#配置))会原样给所有会话,别人的也一样,里面写了库在哪,别人也看得到。
55
55
 
56
56
  ### 给接入插件作者
57
57
 
@@ -93,12 +93,12 @@ agent.followup(createUserMessage({
93
93
 
94
94
  | 字段 | 默认值 | 含义 |
95
95
  |---|---|---|
96
- | `indexName` | `MEMORY.md` | 哪个文件名算索引。卡上限时不分大小写;每轮带上索引时,在区分大小写的系统(如 Linux)上要和文件名完全一致。 |
96
+ | `indexName` | `MEMORY.md` | 哪个文件名算索引。卡上限时不分大小写;带上索引时,在区分大小写的系统(如 Linux)上要和文件名完全一致。不是 `.md` 的索引,记忆页的「打开索引」只在文件夹里显示它,不用默认程序打开。 |
97
97
  | `maxLines` | `200` | 索引行数上限。 |
98
98
  | `maxBytes` | `25600` | 索引字节上限(25 KB)。 |
99
99
  | `indexPath` | 不设 | 只认这一个索引:绝对路径,或相对会话目录。不设时,任何项目里叫 `MEMORY.md` 的文件都按索引卡上限;记忆库不在默认位置时也要设它,否则不会自动带上。 |
100
- | `registerSkill` | `true` | `false`:不注册内置的记忆规则;上限和每轮带上索引照旧。 |
101
- | `injectIndex` | `true` | `false`:不再每轮带上索引,改由 AI 自己读。 |
100
+ | `registerSkill` | `true` | `false`:不注册内置的记忆规则;上限和自动带上索引照旧。 |
101
+ | `injectIndex` | `true` | `false`:不再自动带上索引,改由 AI 自己读。 |
102
102
  | `compactionReminder` | `true` | `false`:快压缩时不再提醒 AI 存记忆。插件照 dsh 的压缩设置算出它会在哪压缩(dsh 0.2 加 DeepSeek 默认约在窗口的 69%,不是 80%),到那一点的 85% 时提醒。尽力而为:一步就涨过这段余量的对话等不到提醒;没装压缩或关了自动压缩时不提醒。 |
103
103
  | `language` | 跟随 dsh | `zh`(`zh-CN` 等也算)用中文写记忆(笔记名、`## 用户` 这类标题、**为什么:**/**怎么用:**),其他字符串用英文;不是字符串或为空,当作没设。不设就跟 dsh 的语言,改了要重启 dsh。frontmatter 的键和 `type:` 取值始终是英文,别的宿主照样能读。 |
104
104
  | `companion` | `false` | `true` 打开大肥鱼模式。 |
package/client.js CHANGED
@@ -30,7 +30,7 @@ window.__ModuleLoader__.load({
30
30
  const SETTINGS_API = 'api/engramory/settings'
31
31
  const MEMORY_API = 'api/engramory/memory'
32
32
  /** This plugin's version, for the feedback footer; a test keeps it equal to package.json's. */
33
- const VERSION = '1.2.0'
33
+ const VERSION = '1.3.1'
34
34
  /** Where feedback goes: a new issue on the repository, or the project's mailbox. Opening
35
35
  * the link is the browser's (the desktop app hands it to the system's); the footer submits
36
36
  * nothing by itself. */
@@ -98,6 +98,7 @@ window.__ModuleLoader__.load({
98
98
  openIndex: '打开索引',
99
99
  openFolder: '打开文件夹',
100
100
  opened: '已打开 {name}。',
101
+ revealed: '已在文件夹里显示 {name}。',
101
102
  openUnavailable: '这台 dsh 不能在本机打开文件(比如远程访问时)。文件在上面写的位置。',
102
103
  openMissing: '找不到这个文件了,可能刚被改名或删掉。点刷新看看。',
103
104
  openBusy: '还在打开上一个,稍等一下再点。',
@@ -222,6 +223,7 @@ window.__ModuleLoader__.load({
222
223
  openIndex: 'Open the index',
223
224
  openFolder: 'Open the folder',
224
225
  opened: 'Opened {name}.',
226
+ revealed: 'Showed {name} in its folder.',
225
227
  openUnavailable: 'This dsh cannot open files on its own computer (when reached remotely, say). The files are where the path above says.',
226
228
  openMissing: 'That file is gone — renamed or deleted just now, perhaps. Refresh to see.',
227
229
  openBusy: 'Still opening the previous one — click again in a moment.',
@@ -725,6 +727,22 @@ button.eng-row:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-ho
725
727
  unavailable: 'openUnavailable', missing: 'openMissing', busy: 'openBusy', timeout: 'listTimeout',
726
728
  }
727
729
  const nameOf = (file) => file.replace(/\.md$/i, '')
730
+ /**
731
+ * A name or path from disk as the page shows it: a control character, a line or paragraph
732
+ * separator, a bidirectional mark, embedding, override or isolate, or a character with no
733
+ * width of its own (a zero-width space, a word joiner, a byte order mark) — any of which can
734
+ * make a name read as another, or hide part of it — shown as its code point (`[U+202E]`).
735
+ * The joiners some scripts and emoji are written with (U+200C, U+200D) are left as they are.
736
+ * What the page sends back to open a file is the name as it is.
737
+ */
738
+ const HIDDEN = [[0x0, 0x1f], [0x7f, 0x9f], [0x61c, 0x61c], [0x200b, 0x200b], [0x200e, 0x200f],
739
+ [0x2028, 0x202e], [0x2060, 0x2064], [0x2066, 0x2069], [0xfeff, 0xfeff]]
740
+ const legible = (text) => Array.from(String(text), (ch) => {
741
+ const code = ch.codePointAt(0)
742
+ return HIDDEN.some(([low, high]) => code >= low && code <= high)
743
+ ? `[U+${code.toString(16).toUpperCase().padStart(4, '0')}]`
744
+ : ch
745
+ }).join('')
728
746
  const sizeOf = (t, bytes) => (bytes < 1024 ? t('sizeBytes', { n: bytes }) : t('sizeKB', { n: (bytes / 1024).toFixed(1) }))
729
747
  const typeKey = (type) => `type${type[0].toUpperCase()}${type.slice(1)}`
730
748
  const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })
@@ -885,9 +903,9 @@ button.eng-row:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-ho
885
903
  const [tidy, setTidy] = useState('idle')
886
904
  const alive = useRef(true)
887
905
  useEffect(() => () => { alive.current = false }, [])
888
- const title = store.kind === 'user' ? [t('storeUser'), ...store.titles].join(' · ')
906
+ const title = legible(store.kind === 'user' ? [t('storeUser'), ...store.titles].join(' · ')
889
907
  : store.kind === 'pinned' ? [t('storePinned'), ...store.titles].join(' · ')
890
- : store.titles.join(' · ')
908
+ : store.titles.join(' · '))
891
909
  const { index } = store
892
910
  const sizes = index === null ? {} : { size: sizeOf(t, index.bytes), maxSize: sizeOf(t, cap.maxBytes) }
893
911
  // lines are counted only for an index read whole; past that, its bytes say over or not
@@ -915,7 +933,7 @@ button.eng-row:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-ho
915
933
  : t(check.brokenMore ? 'healthBrokenMore' : 'healthBroken', { count: check.broken.length }),
916
934
  // what the index says, as it says it: there is no file to open
917
935
  check.broken.length > 0 ? h('ul', { className: 'eng-broken' },
918
- check.broken.map((target) => h('li', { key: target }, h('code', null, target)))) : null) : null,
936
+ check.broken.map((target) => h('li', { key: target }, h('code', null, legible(target))))) : null) : null,
919
937
  checked && check.unindexed.length > 0
920
938
  ? h('p', { className: 'eng-attn-item', key: 'unindexed' }, t('healthUnindexed', { count: check.unindexed.length })) : null,
921
939
  checked && untyped > 0 ? h('p', { className: 'eng-attn-item', key: 'untyped' }, t('healthUntyped', { count: untyped })) : null,
@@ -963,12 +981,12 @@ button.eng-row:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-ho
963
981
  const parts = [
964
982
  h('span', { className: 'eng-mark', key: 'mark' }, icon(Object.hasOwn(ICONS, type) ? type : 'other', 18, 1.6)),
965
983
  h('span', { className: 'eng-row-text', key: 'text' },
966
- h('span', { className: 'eng-name' }, shownName(file, plan)),
984
+ h('span', { className: 'eng-name' }, legible(shownName(file, plan))),
967
985
  h('span', { className: 'eng-row-meta' }, meta)),
968
986
  badges.length > 0 ? h('span', { className: 'eng-badges', key: 'badges' }, badges) : null,
969
987
  canOpen ? h('span', { className: 'eng-row-go', key: 'go' }, icon('chevron', 14)) : null,
970
988
  ]
971
- const props = { className: 'eng-row', 'data-type': type, title: file }
989
+ const props = { className: 'eng-row', 'data-type': type, title: legible(file) }
972
990
  return h('li', { key: file }, canOpen
973
991
  ? h('button', { type: 'button', ...props, onClick: () => open(store, file, note === undefined) }, ...parts)
974
992
  : h('div', props, ...parts))
@@ -996,7 +1014,7 @@ button.eng-row:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-ho
996
1014
  onClick: () => open(store, index.name, false) }, icon('index', 14), t('openIndex')),
997
1015
  h('button', { type: 'button', className: 'eng-btn eng-btn-ghost', key: 'folder',
998
1016
  onClick: () => open(store, undefined, false) }, icon('folder', 14), t('openFolder'))] : []))),
999
- h('p', { className: 'eng-path' }, store.dir),
1017
+ h('p', { className: 'eng-path' }, legible(store.dir)),
1000
1018
  !filtering && checked && findings.length === 0
1001
1019
  ? h('p', { className: 'eng-store-ok' }, icon('check', 13), t('healthOk')) : null,
1002
1020
  attention ? h('div', { className: 'eng-attn', role: 'note' },
@@ -1095,7 +1113,9 @@ button.eng-row:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-ho
1095
1113
  reply = { ok: false, error: 'failed', message: String(error?.message ?? error) }
1096
1114
  }
1097
1115
  if (!alive.current) return
1098
- setStatus(reply.ok ? { tone: 'ok', text: t('opened', { name: file === undefined ? store.dir : nameOf(file) }) }
1116
+ // a file shown in its folder rather than opened (an index not named .md) is said to be
1117
+ setStatus(reply.ok ? { tone: 'ok', text: file === undefined ? t('opened', { name: legible(store.dir) })
1118
+ : t(reply.revealed === true ? 'revealed' : 'opened', { name: legible(nameOf(file)) }) }
1099
1119
  : Object.hasOwn(OPEN_FAILURES, reply.error) ? { tone: 'error', text: t(OPEN_FAILURES[reply.error]) }
1100
1120
  : { tone: 'error', text: t('openFailed', { reason: reply.message ?? reply.error ?? '' }) })
1101
1121
  }
@@ -1106,10 +1126,12 @@ button.eng-row:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-ho
1106
1126
  const present = data === undefined || kind === undefined ||
1107
1127
  data.stores.some((store) => store.notes.some((note) => note.type === kind))
1108
1128
  useEffect(() => { if (!present) setKind(undefined) }, [present])
1109
- // a name filter over what was listed: case- and width-insensitive, the .md left out
1129
+ // a name filter over what was listed: case- and width-insensitive, the .md left out — by
1130
+ // the name as it is or as the page shows it (legible), so what is on the page can be typed
1110
1131
  const needle = query.trim().normalize('NFKC').toLowerCase()
1111
1132
  const match = needle === '' ? undefined
1112
- : (file) => nameOf(file).normalize('NFKC').toLowerCase().includes(needle)
1133
+ : (file) => [nameOf(file), legible(nameOf(file))]
1134
+ .some((name) => name.normalize('NFKC').toLowerCase().includes(needle))
1113
1135
  let body
1114
1136
  if (state.phase === 'loading') body = h('p', { className: 'eng-note' }, t('listing'))
1115
1137
  else if (state.phase === 'error') body = h('div', { className: 'eng-banner', 'data-tone': 'error' }, t(state.reason))
package/icon.svg CHANGED
@@ -1 +1 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64"><rect width="64" height="64" rx="14" fill="#0F1B2D"/><path d="M13.000 17.500 L9.000 17.500 L9.000 46.500 L13.000 46.500" fill="none" stroke="#6EE7C8" stroke-width="4.0" stroke-linecap="round" stroke-linejoin="round"/><path d="M22.000 17.500 L18.000 17.500 L18.000 46.500 L22.000 46.500" fill="none" stroke="#6EE7C8" stroke-width="4.0" stroke-linecap="round" stroke-linejoin="round"/><rect x="27.500" y="23" width="9" height="18" rx="2.4" fill="#6EE7C8"/><path d="M42.000 17.500 L46.000 17.500 L46.000 46.500 L42.000 46.500" fill="none" stroke="#6EE7C8" stroke-width="4.0" stroke-linecap="round" stroke-linejoin="round"/><path d="M51.000 17.500 L55.000 17.500 L55.000 46.500 L51.000 46.500" fill="none" stroke="#6EE7C8" stroke-width="4.0" stroke-linecap="round" stroke-linejoin="round"/></svg>
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64"><rect width="64" height="64" rx="14" fill="#0F1B2D"/><path d="M13.000 17.500 L9.000 17.500 L9.000 46.500 L13.000 46.500" fill="none" stroke="#6EE7C8" stroke-width="4.0" stroke-linecap="round" stroke-linejoin="round"/><path d="M22.000 17.500 L18.000 17.500 L18.000 46.500 L22.000 46.500" fill="none" stroke="#6EE7C8" stroke-width="4.0" stroke-linecap="round" stroke-linejoin="round"/><rect x="27.500" y="23" width="9" height="18" rx="2.4" fill="#6EE7C8"/><path d="M42.000 17.500 L46.000 17.500 L46.000 46.500 L42.000 46.500" fill="none" stroke="#6EE7C8" stroke-width="4.0" stroke-linecap="round" stroke-linejoin="round"/><path d="M51.000 17.500 L55.000 17.500 L55.000 46.500 L51.000 46.500" fill="none" stroke="#6EE7C8" stroke-width="4.0" stroke-linecap="round" stroke-linejoin="round"/></svg>
package/index.js CHANGED
@@ -23,6 +23,7 @@
23
23
  *
24
24
  * Zero dependencies, no build step: plain ESM, node: builtins only.
25
25
  */
26
+ import { createHash, randomUUID } from 'node:crypto'
26
27
  import {
27
28
  closeSync, constants, fstatSync, lstatSync, openSync, readlinkSync, readSync, realpath,
28
29
  realpathSync, statSync,
@@ -79,6 +80,12 @@ const STORE_DIR = '.engramory-memory'
79
80
  /** After every first-party runtime context (dsh's own orders end at 210). */
80
81
  const INDEX_CONTEXT_ORDER = 300
81
82
 
83
+ /**
84
+ * `text` with no two braces side by side — a zero-width space between them — so no `{{`
85
+ * in it opens a prompt variable where dsh fills them in (dsh 0.1's runtime context, apply()).
86
+ */
87
+ const verbatim = (text) => text.replace(/\{(?=\{)/g, `{${String.fromCharCode(0x200b)}`)
88
+
82
89
  export function apply(ctx, config = {}) {
83
90
  // `indexPath` pins the guard to ONE file. Without it the only signal is the
84
91
  // basename, so an unrelated MEMORY.md in any other project is gated too — a real
@@ -114,8 +121,8 @@ export function apply(ctx, config = {}) {
114
121
  // only the user's own conversations get the memory (speakerOf). Private, the default:
115
122
  // every conversation does.
116
123
  social: config.companion === true && config.audience === 'social',
117
- // Whether the index goes into the runtime context (below); the skill says where to look
118
- // when it does not.
124
+ // Whether the index is sent to the model (below); the skill says where to look when it
125
+ // is not.
119
126
  injectIndex: config.injectIndex !== false,
120
127
  }
121
128
  settings.readLimit = Math.min(MAX_READ_LIMIT, Math.max(MIN_READ_LIMIT, 4 * settings.maxBytes))
@@ -126,7 +133,9 @@ export function apply(ctx, config = {}) {
126
133
  // file or none: an edit of the real index passed unmeasured, and a shrinking rewrite
127
134
  // of an over-cap index was judged against an empty file and refused. The service is
128
135
  // optional (0.1.x has none) and may mount late, so — like `skills` below — it is
129
- // picked up reactively and never makes the cap wait.
136
+ // picked up reactively and never makes the cap wait. Without it (dsh 0.1), dsh's file
137
+ // tools resolve against the directory the session was opened in, its header's `cwd`
138
+ // (dsh-tool-fs), which need not be the process's either: so does this.
130
139
  let workingDirectory
131
140
  ctx.inject(['workingDirectory'], (inner) => {
132
141
  inner.effect(() => {
@@ -139,17 +148,19 @@ export function apply(ctx, config = {}) {
139
148
  })
140
149
  const sessionCwd = (exec) => {
141
150
  try {
142
- const dir = workingDirectory?.get(exec.agent.session)
151
+ const session = exec.agent.session
152
+ const moved = workingDirectory?.get(session)
153
+ const dir = typeof moved === 'string' && isAbsolute(moved) ? moved : session?.header?.cwd
143
154
  return typeof dir === 'string' && isAbsolute(dir) ? dir : undefined
144
155
  } catch {
145
156
  return undefined // no agent, no session, or a service shape this port predates
146
157
  }
147
158
  }
148
159
 
149
- // Social mode reads two more optional services, both possibly late: dsh's session
150
- // projections, where the SPEAKERS unit registered here folds who has written in each
151
- // session, and the live agents, where a subagent's parent is found (dsh only continues
152
- // a subagent while its parent is live).
160
+ // Two more optional services, both possibly late. dsh's session projections fold, per
161
+ // session, who has written in it (SPEAKERS, social mode) and which index this plugin last
162
+ // sent it (RECALL, below). Social mode also reads the live agents, where a subagent's
163
+ // parent is found (dsh only continues a subagent while its parent is live).
153
164
  const live = {}
154
165
  if (settings.social) {
155
166
  ctx.inject(['agents'], (inner) => {
@@ -161,24 +172,34 @@ export function apply(ctx, config = {}) {
161
172
  }
162
173
  })
163
174
  })
164
- // Read only where this plugin's own registration took: dsh keeps an earlier registrant
165
- // of the key when it refuses ours, and that unit's state is not this one's. A registry
166
- // that refuses it leaves every session a stranger's (companionRoles).
175
+ }
176
+ // Read only where this plugin's own registration took: dsh keeps an earlier registrant
177
+ // of the key when it refuses ours, and that unit's state is not this one's. A registry
178
+ // that refuses SPEAKERS leaves every session a stranger's (companionRoles); one that
179
+ // refuses RECALL leaves the index unsent, for the model to read (the skill says so).
180
+ // (Social mode keeps the index in the runtime context, below, and needs no RECALL.)
181
+ const units = [
182
+ ...(settings.social ? [['speakers', SPEAKERS]] : []),
183
+ ...(settings.injectIndex && !settings.social ? [['recall', RECALL]] : []),
184
+ ]
185
+ if (units.length > 0) {
167
186
  ctx.inject(['sessionProjections'], (inner) => {
168
- inner.effect(() => {
169
- const registry = inner.sessionProjections
170
- let dispose
171
- try {
172
- dispose = registry.register(SPEAKERS)
173
- } catch {
174
- return () => {}
175
- }
176
- live.speakers = registry
177
- return () => {
178
- if (live.speakers === registry) live.speakers = undefined
179
- if (typeof dispose === 'function') dispose()
180
- }
181
- })
187
+ for (const [slot, unit] of units) {
188
+ inner.effect(() => {
189
+ const registry = inner.sessionProjections
190
+ let dispose
191
+ try {
192
+ dispose = registry.register(unit)
193
+ } catch {
194
+ return () => {}
195
+ }
196
+ live[slot] = registry
197
+ return () => {
198
+ if (live[slot] === registry) live[slot] = undefined
199
+ if (typeof dispose === 'function') dispose()
200
+ }
201
+ })
202
+ }
182
203
  })
183
204
  }
184
205
  const roleOf = settings.social ? companionRoles(live) : () => 'owner'
@@ -247,42 +268,71 @@ export function apply(ctx, config = {}) {
247
268
  refreshSkill()
248
269
  })
249
270
 
250
- // Recall without a read: the index goes into dsh's runtime context, and dsh carries a
251
- // changed snapshot to the model on the next request. It is cut at the cap, as a host
252
- // that loads only so much would cut it, and the model is told. Optional and possibly
253
- // late, like the services above; a host whose prompt registry has no runtime context
254
- // keeps the cap and the skill and simply goes without.
271
+ // Recall without a read: the index reaches the model as a message of this plugin's own,
272
+ // sent on a step when what the session should see differs from what it was last sent
273
+ // (recallMessage). It is cut at the cap, as a host that loads only so much would cut it,
274
+ // and the model is told.
275
+ //
276
+ // Not in dsh's runtime context, where it was until 1.3.0: dsh joins every runtime context
277
+ // into one snapshot and sends the whole snapshot again whenever any part of it changes —
278
+ // a `cd`, an approval or sandbox switch, the compaction reminder — and every superseded
279
+ // copy stays in the conversation until it is compacted. With an index near the cap,
280
+ // that was most of a conversation's text (measured on dsh 0.2.1-rc.5: six copies of a
281
+ // 20 KB index in a 13-step session with two `cd`s and two saves). dsh's own clock
282
+ // (dsh-time-context) is sent the same way, as a message of its own.
283
+ //
284
+ // Social mode is the exception: there the index stays in the runtime context, as before.
285
+ // Who is on the other end can change while a step's request is being prepared — a bridge
286
+ // queues an outsider's message — and only the runtime context is judged again then, at
287
+ // the very moment dsh admits the step's messages (dsh 0.2's refresh): a message chosen
288
+ // for the user's own conversation at the start of the step would still be committed,
289
+ // into what is by then someone else's, on its first turn too. A character chatting with
290
+ // others seldom moves directory or switches approval, so little is lost.
255
291
  //
256
- // With companion mode or social mode on, a context of its own carries more: companion
257
- // mode adds the companion rules after the index; social mode tells who is on the other
258
- // end — the user's own conversation gets the memory, any other gets no store at all,
259
- // only a note saying so. The rules and the note still go in with `injectIndex: false`,
292
+ // With companion mode or social mode on, a runtime context of this plugin's own carries
293
+ // what is small and settled: companion mode's rules; in social mode, who is on the other
294
+ // end — the user's own conversation gets the index and where the store is, any other
295
+ // gets no store at all, only a note saying so. They still go in with `injectIndex: false`,
260
296
  // which only turns the index off.
261
297
  //
262
298
  // That context is REQUIRED: a persona preset may turn optional runtime context off
263
299
  // (dsh-persona's `includeRuntimeContext: false`, as the shipped `minimal` preset does),
264
300
  // which would leave a companion without the memory and a stranger without the note that
265
- // the store is closed — seen on a real dsh.
301
+ // the store is closed — seen on a real dsh 0.2 (dsh 0.1 drops required ones too). Without
302
+ // either mode the index stays optional, as every preset expects: a context that is only a
303
+ // probe, with no text.
304
+ //
305
+ // Either way the context says whether the index message may be sent. dsh assembles a
306
+ // step's prompt just before it asks for the step (`agent/pre-step`), and the assembly
307
+ // holds an optional runtime context only where the persona preset has not turned runtime
308
+ // context off; so the session's latest assembly, through dsh's own
309
+ // `system-prompt/assemble` waterfall (as dsh-working-directory reads it), says yes or no
310
+ // for the coming step — read outermost (prepended), as the other listeners leave it. Each
311
+ // assembly overwrites the answer: the refresh dsh makes of the runtime context before the
312
+ // request runs no waterfall, and cannot carry a yes over to a later step.
266
313
  const injectIndex = settings.injectIndex
267
314
  const guarded = settings.companion || settings.social
315
+ const index = injectIndex ? indexRecall(settings, sessionCwd) : () => ({ text: '', unsure: false })
316
+ const asMessage = injectIndex && !settings.social
317
+ const memoryContext = guarded ? 'engramory:memory' : 'engramory:memory-index'
318
+ const assembled = new WeakMap() // session -> did its latest assembly hold the memory context
268
319
  const contexts = []
269
- if (injectIndex || guarded) {
270
- const index = injectIndex ? indexRecall(settings, sessionCwd) : () => ''
271
- contexts.push(...guarded ? [{
272
- name: 'engramory:memory',
320
+ if (guarded) {
321
+ contexts.push({
322
+ name: memoryContext,
273
323
  required: true,
274
324
  text: (context) => {
275
325
  if (roleOf(context?.agent) !== 'owner') return settings.text.strangerNotice
276
326
  let shown = ''
277
- try {
278
- shown = index(context)
279
- } catch {
280
- // an index that cannot be read must not take the companion rules with it
281
- }
282
- // In social mode the skill, which every conversation reads, names no path: the
283
- // user's own conversations learn it here, where no index has shown it yet — a
284
- // relative pin resolved against this session's directory, as recall resolves it.
285
327
  if (settings.social) {
328
+ try {
329
+ shown = index(context).text
330
+ } catch {
331
+ // an index that cannot be read must not take the companion rules with it
332
+ }
333
+ // The skill, which every conversation reads, names no path: the user's own
334
+ // conversations learn it here, where no index has shown it yet — a relative pin
335
+ // resolved against this session's directory, as recall resolves it.
286
336
  const stores = storesOf(settings)
287
337
  if (stores.pinned !== undefined) stores.pinned = hostPath(sessionCwd(context), stores.pinned)
288
338
  // only a project's index shown, or none: the store the skill sends notes to is
@@ -294,16 +344,59 @@ export function apply(ctx, config = {}) {
294
344
  const rules = settings.companion ? settings.text.companion : ''
295
345
  return [shown, rules].filter(Boolean).join('\n\n')
296
346
  },
297
- }] : [{ name: 'engramory:memory-index', text: index }])
347
+ })
348
+ } else if (injectIndex) {
349
+ contexts.push({ name: memoryContext, text: () => '' })
350
+ }
351
+
352
+ // The index message itself, added to what dsh is about to commit for the step (as
353
+ // dsh-time-context adds its clock): after the other listeners — a compaction among them
354
+ // (dsh-compaction-basic), which may just have taken the last copy out of the
355
+ // conversation — and only when the step goes ahead.
356
+ //
357
+ // A compaction on a request dsh's model refused as too long (dsh-compaction-basic on
358
+ // `agent/request-error`) retries the request within the step, with no pre-step: where it
359
+ // took the last copy out, the copy goes back in as that compaction puts its own summary
360
+ // in, appended to the session, before the retry. One compaction is not followed: dsh
361
+ // 0.2.2's on a switch of model, as the request is prepared (`agent/request`, by a listener
362
+ // outside this one) — the request it compacted goes without the index, and the next step
363
+ // sends it again.
364
+ if (asMessage) {
365
+ const recallMessage = recallFor(settings, live, roleOf, index, assembled)
366
+ ctx.on('agent/pre-step', async (step, next) => {
367
+ const decision = await next()
368
+ if (decision?.kind === 'reject' || step?.signal?.aborted || !Array.isArray(decision?.messages)) {
369
+ return decision
370
+ }
371
+ let message
372
+ try {
373
+ message = recallMessage(step.agent)
374
+ } catch {
375
+ return decision // never fail a step over recall
376
+ }
377
+ return message === undefined ? decision : { ...decision, messages: [...decision.messages, message] }
378
+ }, { prepend: true })
379
+ ctx.on('agent/request-error', async (failed, next) => {
380
+ const action = await next()
381
+ if (action?.kind !== 'retry' || failed?.signal?.aborted) return action
382
+ try {
383
+ const message = recallMessage(failed.agent, { retry: true })
384
+ if (message !== undefined) failed.agent.session.append('user/message', message, { surfaceOp: 'append' })
385
+ } catch {
386
+ // never fail a retry over recall
387
+ }
388
+ return action
389
+ }, { prepend: true })
298
390
  }
299
391
 
300
392
  // Before dsh compacts a conversation into a summary (dsh-compaction-basic, before the step's
301
393
  // request goes out; where, compactionReminder() works out), the model is told to save what
302
394
  // is worth keeping beyond it — the summary keeps what the conversation needs, not what
303
- // memory would. The model, not the user, is told: saving is its part. A section of its
304
- // own, so the index's text does not change with it; required where the memory context is
305
- // (a persona preset may drop optional context), and in social mode only for the user's
306
- // own conversations, the only ones that may save.
395
+ // memory would. The model, not the user, is told: saving is its part. A runtime context
396
+ // of its own (outside social mode the index is not in the runtime context, so its switching
397
+ // on sends no index again); required where the memory context is (a persona preset may drop optional
398
+ // context), and in social mode only for the user's own conversations, the only ones
399
+ // that may save.
307
400
  if (config.compactionReminder !== false) {
308
401
  const pressure = {}
309
402
  for (const [service, key] of [['tokenMeter', 'meter'], ['sessionProjections', 'projections'],
@@ -328,6 +421,33 @@ export function apply(ctx, config = {}) {
328
421
  }
329
422
 
330
423
  if (contexts.length > 0) {
424
+ // Each assembly of a step's prompt, read outermost (prepended), as the other listeners
425
+ // leave it, says two things. Whether the coming step may carry the index message
426
+ // (above). And whether this plugin's runtime context will be taken as written: dsh 0.1
427
+ // drops `interpolate: false` from a runtime context as it assembles one (dsh 0.2 keeps
428
+ // it) and fills in every `{{name}}` group of the text, failing the whole request over a
429
+ // name it does not know — in social mode a `{{` the user wrote in the index is enough.
430
+ // Where the assembly no longer says `interpolate: false`, no two braces of this plugin's
431
+ // text are left side by side (verbatim()); dsh 0.2's text stays exactly as written.
432
+ const ours = new Set(contexts.map((c) => c.name))
433
+ const filledIn = (c) => ours.has(c?.name) && c.interpolate !== false &&
434
+ typeof c.text === 'string' && c.text.includes('{{')
435
+ ctx.on('system-prompt/assemble', async (assembly, context, next) => {
436
+ const result = await next()
437
+ try {
438
+ const listed = Array.isArray(result?.contexts) ? result.contexts : []
439
+ const session = context?.agent?.session
440
+ if (asMessage && session !== null && typeof session === 'object') {
441
+ assembled.set(session, listed.some((c) => c?.name === memoryContext))
442
+ }
443
+ if (listed.some(filledIn)) {
444
+ return { ...result, contexts: listed.map((c) => (filledIn(c) ? { ...c, text: verbatim(c.text) } : c)) }
445
+ }
446
+ } catch {
447
+ // never fail an assembly over recall
448
+ }
449
+ return result
450
+ }, { prepend: true })
331
451
  ctx.inject(['systemPrompt'], (inner) => {
332
452
  const prompt = inner.systemPrompt
333
453
  if (typeof prompt?.context !== 'function') return
@@ -599,7 +719,7 @@ const TIMED_OUT = Symbol('timed out')
599
719
  * The memory page's one route. GET lists the stores recall can use, by name only: where each
600
720
  * is, its index's size against the cap, its notes' names with their types and sizes, its
601
721
  * archive's names, and its check-up (checkUp) — and how many stores could not be read. POST `{ store, file?, archive? }` opens a note or the index in the desktop's own
602
- * app — or, with no `file`, shows the store's index in the file manager — through dsh's
722
+ * app (an index not named `.md`, in the file manager) — or, with no `file`, shows the store's index in the file manager — through dsh's
603
723
  * session controller, which checks the path once more. The page never sends a path: a store
604
724
  * is the id the listing gave it, a file a name in that store's directory, and both are found
605
725
  * again before anything opens. Nothing is written, and no note's text reaches the page.
@@ -653,7 +773,8 @@ function memoryRoute(settings, desk) {
653
773
  const timer = setTimeout(() => abort.abort(), OPEN_MS)
654
774
  try {
655
775
  await opener.openWorkspacePath(target, abort.signal)
656
- return json(200, { ok: true })
776
+ // shown in the file manager rather than opened (targetOf): the page says which
777
+ return json(200, target.action === 'reveal' ? { ok: true, revealed: true } : { ok: true })
657
778
  } catch (error) {
658
779
  return json(502, { ok: false, error: 'failed', message: String(error?.message ?? error) })
659
780
  } finally {
@@ -1249,7 +1370,11 @@ async function targetOf(settings, registry, body) {
1249
1370
  return index === undefined ? undefined : { path: index, action: 'reveal' }
1250
1371
  }
1251
1372
  const path = await fileIn(store, body.file, body.archive === true)
1252
- return path === undefined ? undefined : { path }
1373
+ if (path === undefined) return undefined
1374
+ // A note is a `.md`. An index the user named otherwise (`indexName`, `indexPath`) is shown
1375
+ // in its folder instead: the desktop's own app runs what it opens when the name says
1376
+ // program (`.cmd`, `.lnk`, `.url`…), and a project's store is whatever its checkout put there.
1377
+ return /\.md$/i.test(path) ? { path } : { path, action: 'reveal' }
1253
1378
  } catch {
1254
1379
  return undefined
1255
1380
  }
@@ -1325,7 +1450,7 @@ function speakerOf(source) {
1325
1450
  if (speaker?.chat !== undefined && speaker.chat !== 'private') return 'other'
1326
1451
  if (speaker?.role === 'owner') return 'owner'
1327
1452
  if (speaker?.role === 'guest') return 'other'
1328
- const kind = source.kind
1453
+ const kind = source.kind === 'plugin' ? legacyKind(source.plugin) : source.kind
1329
1454
  if (kind === 'user') {
1330
1455
  return typeof source.rpcId === 'string' && typeof source.clientTimeZone === 'string' &&
1331
1456
  source.principal === undefined ? 'owner' : 'other'
@@ -1333,6 +1458,30 @@ function speakerOf(source) {
1333
1458
  return typeof kind === 'string' && INERT_PRODUCERS.has(kind) ? undefined : 'other'
1334
1459
  }
1335
1460
 
1461
+ /**
1462
+ * The kind dsh 0.2 gives a dsh 0.1 producer, which stamped `{ kind: 'plugin', plugin: <its
1463
+ * name> }` (dsh-time-context's clock on 0.1.5–0.1.7, say): as dsh's own session migration
1464
+ * (dsh-session-format-v3-to-v4, `producerKind`) lifts it — a few renamed, the rest of its
1465
+ * own producers keeping their names, anything else `plugin:<name>`, someone else's.
1466
+ */
1467
+ function legacyKind(plugin) {
1468
+ if (typeof plugin !== 'string') return undefined
1469
+ return Object.hasOwn(LEGACY_RENAMED, plugin) ? LEGACY_RENAMED[plugin]
1470
+ : LEGACY_SAME_NAME.has(plugin) ? plugin
1471
+ : `plugin:${plugin}`
1472
+ }
1473
+ const LEGACY_RENAMED = Object.freeze({
1474
+ 'compact': 'compact-checkpoint', 'tools-code-mode': 'ptc-mode', 'tools-ptc': 'ptc-mode',
1475
+ 'dsh-compaction-basic': 'compact-basic', '@deepseek-ai/dsh-system-prompt': 'runtime-context',
1476
+ })
1477
+ const LEGACY_SAME_NAME = new Set([
1478
+ 'agent-instructions', 'session-reference', 'team-message', 'goal', 'skill-invocation',
1479
+ 'skill-catalog', 'coordinator', 'subagent-report', 'subagent-settled', 'webhook',
1480
+ 'agent-message', 'model-selection', 'plan-mode', 'time-context', 'tmux-context',
1481
+ 'user-approval', 'repeat-tool-reminder', 'tool-cordis', 'cordis-host-runner', 'tool-goal',
1482
+ 'tool-jobs', 'hooks-codex', 'hooks-claude-code', 'schedule', 'dsh-session-title-llm',
1483
+ ])
1484
+
1336
1485
  /** A source that is dsh's `user` kind and nothing else: no request id, caller, zone or speaker. */
1337
1486
  const isBareUser = (source) => source !== null && typeof source === 'object' &&
1338
1487
  source.kind === 'user' && Object.keys(source).length === 1
@@ -1408,8 +1557,9 @@ const SPEAKERS = {
1408
1557
  key: SPEAKERS_KEY,
1409
1558
  // Bumped whenever the state's fields or the fold change, so dsh refolds a session from its
1410
1559
  // log rather than seed it from a checkpoint the fold no longer means (2: pre-release shapes;
1411
- // 3: a message in a group chat is someone else's, the owner's included).
1412
- stateVersion: 3,
1560
+ // 3: a message in a group chat is someone else's, the owner's included; 4: dsh 0.1's own
1561
+ // `{ kind: 'plugin' }` messages are nobody's, no longer an outsider's).
1562
+ stateVersion: 4,
1413
1563
  // dsh only calls `parse`, on a checkpoint before folding on from it; no zod needed.
1414
1564
  stateSchema: {
1415
1565
  parse(value) {
@@ -1506,6 +1656,18 @@ const PATH_ARGS = ['file_path', 'path', 'filePath', 'filename', 'file', 'target_
1506
1656
  /** Tools that walk a whole tree under their `path` — the session's directory by default. */
1507
1657
  const TREE_SEARCHES = new Set(['grep', 'glob'])
1508
1658
 
1659
+ /**
1660
+ * Tools that read other conversations' records, every event in them: dsh's session search
1661
+ * (an optional bundle). dsh lets a conversation read any other opened in the same directory —
1662
+ * a stranger's the user's own, the index in it included.
1663
+ */
1664
+ const HISTORY_TOOLS = new Set([
1665
+ 'session_search', 'session_event_search', 'session_trace', 'session_event_trace', 'session_event_read',
1666
+ ])
1667
+
1668
+ /** Past this many files listed in one call, a stranger's call is refused without checking each. */
1669
+ const MAX_LISTED = 32
1670
+
1509
1671
  /**
1510
1672
  * In social mode, a stranger's conversation may not point a file tool at a memory
1511
1673
  * store — not to read it, list it, search it, or write it — and may name files only,
@@ -1517,7 +1679,11 @@ const TREE_SEARCHES = new Set(['grep', 'glob'])
1517
1679
  * - a path with a `.engramory-memory` segment, as written or as the OS resolves it
1518
1680
  * (links, junctions, 8.3 short names) — a store that does not exist yet included,
1519
1681
  * so a stranger cannot plant one for the user's next session;
1520
- * - a path in the pinned index's directory, or in the directory its target is in.
1682
+ * - a path in the pinned index's directory, or in the directory its target is in;
1683
+ * - the same for every file a call lists (`files`, as dsh's `present` takes them), and
1684
+ * for where a session moves to (`cd`) — there a directory is fine, a store's is not;
1685
+ * - dsh's session search (HISTORY_TOOLS), whatever it is asked: it reads the records of
1686
+ * the user's own conversations too.
1521
1687
  * Paths are compared without case or Unicode form on every platform: macOS opens
1522
1688
  * `.ENGRAMORY-MEMORY` as the store too, and refusing a stranger one path too many
1523
1689
  * costs nothing. Fails closed: a stranger's call that cannot be checked is refused.
@@ -1529,26 +1695,38 @@ const TREE_SEARCHES = new Set(['grep', 'glob'])
1529
1695
  function refuseStranger(exec, settings, sessionCwd, roleOf) {
1530
1696
  try {
1531
1697
  if (roleOf(exec?.agent) !== 'stranger') return undefined
1698
+ if (HISTORY_TOOLS.has(exec.name)) return settings.text.strangerHistory
1532
1699
  const args = exec.arguments !== null && typeof exec.arguments === 'object'
1533
1700
  ? exec.arguments
1534
1701
  : {}
1535
- const named = PATH_ARGS.map((k) => args[k]).filter((v) => typeof v === 'string' && v !== '')
1702
+ const strings = (values) => values.filter((v) => typeof v === 'string' && v !== '')
1703
+ const named = strings(PATH_ARGS.map((k) => args[k]))
1704
+ // Files listed rather than named, as dsh's `present` takes them (`files: [{ path }]`).
1705
+ if (Array.isArray(args.files)) {
1706
+ if (args.files.length > MAX_LISTED) return settings.text.strangerRefusal
1707
+ for (const item of args.files) {
1708
+ named.push(...strings(item !== null && typeof item === 'object' ? PATH_ARGS.map((k) => item[k]) : [item]))
1709
+ }
1710
+ }
1536
1711
  // The root a tree search really walks, whatever else the call carries: dsh ignores
1537
1712
  // arguments a tool does not declare, so a stray `file_path` is not its root.
1538
1713
  if (TREE_SEARCHES.has(exec.name)) {
1539
1714
  named.push(typeof args.path === 'string' && args.path !== '' ? args.path : '.')
1540
1715
  }
1541
- if (named.length === 0) return undefined
1716
+ // Where a session moves to (dsh's `working_directory`, `cd`): a directory, so not refused
1717
+ // for being one — but never a store's.
1718
+ const moves = strings([args.cd])
1719
+ if (named.length === 0 && moves.length === 0) return undefined
1542
1720
  const cwd = sessionCwd(exec)
1543
1721
  const stores = storeTargets(cwd, settings)
1544
- for (const p of named) {
1722
+ for (const [p, move] of [...named.map((p) => [p, false]), ...moves.map((p) => [p, true])]) {
1545
1723
  // A network or device path can stall a stat for as long as the share takes to
1546
1724
  // time out, on the host's main thread: refused before any I/O.
1547
1725
  if (/^[\\/]{2}/.test(p)) return settings.text.strangerRefusal
1548
1726
  const spelled = hostPath(cwd, p)
1549
1727
  // Resolving walks the path a stat per missing segment: bounded before any I/O.
1550
1728
  if (tooDeep(spelled) || /^[\\/]{2}/.test(spelled)) return settings.text.strangerRefusal
1551
- if (isDirectory(spelled)) return settings.text.strangerRefusal
1729
+ if (!move && isDirectory(spelled)) return settings.text.strangerRefusal
1552
1730
  const written = foldPath(spelled)
1553
1731
  const target = osKey(spelled)
1554
1732
  if (namesStore(written) || namesStore(target)) return settings.text.strangerRefusal
@@ -1710,7 +1888,7 @@ const COMPACT_RETAIN = 0.16
1710
1888
  * Where the reminder comes on, as a share of the point dsh will compact at — early enough
1711
1889
  * that a few large steps still leave the model a turn to save — and below which it goes:
1712
1890
  * the gap keeps a conversation hovering near one figure from switching it on and off, each
1713
- * switch sending the runtime context, index and all, once more. After a compaction the
1891
+ * switch sending dsh's whole runtime context once more. After a compaction the
1714
1892
  * conversation is far below either.
1715
1893
  */
1716
1894
  const REMIND_AT = 0.85
@@ -1819,15 +1997,143 @@ function compactionReminder(settings, pressure) {
1819
1997
  /** A whole number of tokens: an integer, not negative. */
1820
1998
  const count = (n) => Number.isInteger(n) && n >= 0
1821
1999
 
2000
+ /**
2001
+ * The source of the index messages this plugin sends: a producer kind of its own, as dsh
2002
+ * 0.2's session format requires of a message (it refuses the retired `plugin` kind) and
2003
+ * dsh 0.1's accepts, and written by nobody (`speaker: { role: 'none' }`), so the SPEAKERS
2004
+ * fold does not take the plugin's own message for an outsider's. dsh's chat shows a message
2005
+ * of a kind other than `user` as a folded context row. No `sections` copy of the text,
2006
+ * which dsh-time-context's clock carries: dsh stores, and by default uploads with its
2007
+ * requests (dsh-session-log-deepseek), each event's data whole.
2008
+ */
2009
+ const RECALL_KIND = 'engramory'
2010
+ const RECALL_KEY = 'engramory:recall'
2011
+
2012
+ /**
2013
+ * The RECALL projection's state: the seq of the latest index message and its text's digest
2014
+ * ('' for the note that no index applies), while it is still in the conversation; both null
2015
+ * when none is.
2016
+ */
2017
+ const NOTHING_SENT = Object.freeze({ seq: null, digest: null })
2018
+ const isRecall = (value) => value !== null && typeof value === 'object' &&
2019
+ Object.keys(value).length === 2 &&
2020
+ (value.seq === null
2021
+ ? value.digest === null
2022
+ : Number.isSafeInteger(value.seq) && value.seq >= 0 && typeof value.digest === 'string')
2023
+
2024
+ const digestOf = (text) => createHash('sha256').update(text).digest('hex')
2025
+
2026
+ /** A message's text, its text blocks joined. */
2027
+ const textOf = (message) => (Array.isArray(message?.content) ? message.content : [])
2028
+ .map((block) => (block?.type === 'text' && typeof block.text === 'string' ? block.text : ''))
2029
+ .join('')
2030
+
2031
+ /**
2032
+ * Does a committed event take the conversation's message at `seq` out of what the model
2033
+ * sees? A replacement names what it replaces in `sourceEventSeqs` — dsh-compaction-basic's
2034
+ * summary every message it shadows. Its `surfaceOp` range is not read: it runs from one
2035
+ * message to another in the conversation's order, which a replaced tool result (a newer
2036
+ * seq in an older place) takes out of seq order.
2037
+ */
2038
+ function shadows(event, seq) {
2039
+ const op = event?.surfaceOp
2040
+ if (op === undefined || op === 'append') return false
2041
+ return Array.isArray(event.sourceEventSeqs) && event.sourceEventSeqs.includes(seq)
2042
+ }
2043
+
2044
+ /**
2045
+ * A host-only dsh session projection folding which index this plugin last sent a session,
2046
+ * while the message is still in the conversation: the latest index message's seq and its
2047
+ * text's digest, until a replacement takes that message out (a compaction), from when
2048
+ * nothing counts as sent. dsh drives it over every committed event, a fork's inherited ones
2049
+ * and a restored log's included, and checkpoints it — so a session resumed after a restart
2050
+ * is not sent again the index it holds.
2051
+ */
2052
+ const RECALL = {
2053
+ key: RECALL_KEY,
2054
+ stateVersion: 1,
2055
+ // dsh only calls `parse`, on a checkpoint before folding on from it; no zod needed.
2056
+ stateSchema: {
2057
+ parse(value) {
2058
+ if (!isRecall(value)) throw new TypeError(`${RECALL_KEY}: not a state of this unit`)
2059
+ return { ...value }
2060
+ },
2061
+ },
2062
+ init: () => NOTHING_SENT,
2063
+ apply(state, event) {
2064
+ if (event?.type === 'user/message' && event.data?.source?.kind === RECALL_KIND &&
2065
+ Number.isSafeInteger(event.seq) && event.seq >= 0) {
2066
+ return { seq: event.seq, digest: event.data.source.cleared === true ? '' : digestOf(textOf(event.data)) }
2067
+ }
2068
+ return state.seq !== null && shadows(event, state.seq) ? NOTHING_SENT : state
2069
+ },
2070
+ }
2071
+
2072
+ /**
2073
+ * What to send a session with its coming step, or undefined: the index it should see,
2074
+ * headed as the latest, when that is not what it holds (RECALL); once, a note that no
2075
+ * index applies any more, when it should see none but holds one — its store gone, say
2076
+ * (social mode, where who is on the other end decides, keeps the index in the runtime
2077
+ * context and never comes here). Nothing where the session's
2078
+ * latest assembly did not hold the memory context (a persona preset turned optional
2079
+ * runtime context off), and nothing without RECALL: a session whose last copy cannot be
2080
+ * told would be sent the index on every step.
2081
+ *
2082
+ * A store found but not read just now (indexRecall's `unsure`: a lock, a refusal, a disk
2083
+ * that hiccupped) is not news that it went away: a session holding a copy keeps it and is
2084
+ * sent nothing on the first step of a run of such steps, and on a request dsh retries
2085
+ * within a step (`retry`). Not read on a later step of the run either, the session is sent
2086
+ * what can be read, as if that store were gone, until every store is read again — one store
2087
+ * long unreadable holds back no other's — and so is one holding no copy (a compaction took
2088
+ * it), at once.
2089
+ */
2090
+ function recallFor(settings, live, roleOf, index, assembled) {
2091
+ // sessions in a run of steps with a store found but not read, held back once in it already
2092
+ const held = new WeakSet()
2093
+ return (agent, { retry = false } = {}) => {
2094
+ const session = agent?.session
2095
+ if (session === null || typeof session !== 'object') return undefined
2096
+ if (assembled.get(session) !== true || live.recall === undefined) return undefined
2097
+ const sent = live.recall.stateOf(session, RECALL_KEY)
2098
+ if (!isRecall(sent)) return undefined
2099
+ const { text: shown, unsure } = roleOf(agent) === 'owner' ? index({ agent }) : { text: '', unsure: false }
2100
+ if (!unsure) held.delete(session)
2101
+ else if (sent.seq !== null && (retry || !held.has(session))) {
2102
+ held.add(session)
2103
+ return undefined
2104
+ }
2105
+ if (shown) {
2106
+ const text = `${settings.text.recallHead}\n\n${shown}`
2107
+ return digestOf(text) === sent.digest ? undefined : recallMessage(text)
2108
+ }
2109
+ return sent.digest ? recallMessage(settings.text.recallCleared, true) : undefined
2110
+ }
2111
+ }
2112
+
2113
+ /** One index message as dsh's createUserMessage makes one: a fresh id, frozen. */
2114
+ function recallMessage(text, cleared = false) {
2115
+ return Object.freeze({
2116
+ role: 'user',
2117
+ content: Object.freeze([Object.freeze({ type: 'text', text })]),
2118
+ source: Object.freeze({
2119
+ kind: RECALL_KIND,
2120
+ speaker: Object.freeze({ role: 'none' }),
2121
+ ...(cleared ? { cleared: true } : {}),
2122
+ }),
2123
+ id: randomUUID(),
2124
+ })
2125
+ }
2126
+
1822
2127
  /** How long a directory's walk up to its project root, or a shown index, is trusted. */
1823
2128
  const RECHECK_MS = 10000
1824
2129
 
1825
2130
  /**
1826
- * The runtime-context text for the indexes a session should see: the pinned
1827
- * `indexPath`, or else its project store and the global one under `$DSH_HOME` (both,
1828
- * when both exist — dsh loads both AGENTS.md scopes too).
2131
+ * The text of the indexes a session should see, for its index message (recallFor): the
2132
+ * pinned `indexPath`, or else its project store and the global one under `$DSH_HOME`
2133
+ * (both, when both exist — dsh loads both AGENTS.md scopes too) — and whether any store
2134
+ * there could not be read just now (`unsure`).
1829
2135
  *
1830
- * dsh calls this synchronously on every step, so it does as little I/O as it can: the
2136
+ * This runs on every step, on dsh's main thread, so it does as little I/O as it can: the
1831
2137
  * walk up to the project root is remembered per directory for a few seconds, and an
1832
2138
  * index is re-read only when it changes (identity, size, mtime or ctime) or a few
1833
2139
  * seconds have passed — then only as far as the cap, since nothing past it is shown.
@@ -1853,12 +2159,16 @@ function indexRecall(settings, sessionCwd) {
1853
2159
  { label: labels.user, path: join(dshHome(), STORE_DIR, settings.indexName) }]
1854
2160
  const seen = new Set()
1855
2161
  const parts = []
2162
+ // An index there that cannot be read just now — locked, refused, a disk that hiccupped —
2163
+ // is not news that it went away: what the session should see is then not known.
2164
+ let unsure = false
1856
2165
  for (const store of candidates) {
1857
2166
  if (store === undefined) continue
1858
2167
  let stat
1859
2168
  try {
1860
2169
  stat = statSync(store.path, { bigint: true }) // exact 64-bit file ids on Windows
1861
- } catch {
2170
+ } catch (error) {
2171
+ if (!absent(error)) unsure = true
1862
2172
  continue // no store there
1863
2173
  }
1864
2174
  if (!stat.isFile()) continue
@@ -1872,7 +2182,10 @@ function indexRecall(settings, sessionCwd) {
1872
2182
  // can change with it.
1873
2183
  if (store.root !== undefined && !projectIndex(store.path, store.root)) continue
1874
2184
  const current = readIndex(store.path, readUpTo, true)
1875
- if (current === undefined) continue // unreadable just now: try again next step
2185
+ if (current === undefined) {
2186
+ unsure = true
2187
+ continue // read again next step
2188
+ }
1876
2189
  entry = { stamp, at: Date.now(), text: renderIndex(store.label, store.path, current, settings) }
1877
2190
  shown.set(key, entry)
1878
2191
  if (shown.size > 64) shown.delete(shown.keys().next().value)
@@ -1880,7 +2193,7 @@ function indexRecall(settings, sessionCwd) {
1880
2193
  seen.add(identity)
1881
2194
  parts.push(entry.text)
1882
2195
  }
1883
- return parts.join('\n\n')
2196
+ return { text: parts.join('\n\n'), unsure }
1884
2197
  }
1885
2198
  }
1886
2199
 
@@ -2468,17 +2781,23 @@ function readIndex(filePath, limit, keepHead = false) {
2468
2781
  fd = openSync(filePath, constants.O_RDONLY | (constants.O_NONBLOCK ?? 0))
2469
2782
  const stat = fstatSync(fd)
2470
2783
  if (!stat.isFile()) return undefined
2471
- const chunks = []
2784
+ // One buffer, doubled as the file turns out longer and never past `limit + 1`: a read
2785
+ // may return less than it was asked for (a file system that answers a few bytes at a
2786
+ // time), and a chunk kept per read would hold its whole allocation for each few bytes.
2787
+ let buffer = Buffer.allocUnsafe(Math.min(65536, limit + 1))
2472
2788
  let total = 0
2473
2789
  for (;;) {
2474
- const chunk = Buffer.allocUnsafe(Math.min(65536, limit + 1 - total))
2475
- const got = readSync(fd, chunk, 0, chunk.length, null)
2476
- if (got === 0) return Buffer.concat(chunks, total)
2477
- chunks.push(chunk.subarray(0, got))
2790
+ if (total === buffer.length) {
2791
+ const grown = Buffer.allocUnsafe(Math.min(limit + 1, buffer.length * 2))
2792
+ buffer.copy(grown, 0, 0, total)
2793
+ buffer = grown
2794
+ }
2795
+ const got = readSync(fd, buffer, total, buffer.length - total, null)
2796
+ if (got === 0) return buffer.subarray(0, total)
2478
2797
  total += got
2479
2798
  if (total > limit) {
2480
2799
  const bytes = Math.max(stat.size, total)
2481
- return keepHead ? { bytes, head: Buffer.concat(chunks, total) } : { bytes }
2800
+ return keepHead ? { bytes, head: buffer.subarray(0, total) } : { bytes }
2482
2801
  }
2483
2802
  }
2484
2803
  } catch {
@@ -2711,6 +3030,10 @@ const TEXT = {
2711
3030
  'This conversation is not the user\'s own (Engramory social mode: someone else has ' +
2712
3031
  'written in it, or the user never has in dsh\'s own window), so the memory store is ' +
2713
3032
  'closed to it.',
3033
+ strangerHistory:
3034
+ 'This conversation is not the user\'s own (Engramory social mode: someone else has ' +
3035
+ 'written in it, or the user never has in dsh\'s own window), so the records of other ' +
3036
+ 'conversations are closed to it.',
2714
3037
  storeAt: (stores) =>
2715
3038
  `Engramory: your memory store is ${code(storeDir(stores))}, its index ` +
2716
3039
  `${code(stores.indexName)}; create them there on the first save if they do not exist yet.`,
@@ -2727,8 +3050,14 @@ const TEXT = {
2727
3050
  `${moreThanLines === undefined ? '' : `more than ${moreThanLines} lines, `}${bytes} bytes`,
2728
3051
  cutCap: (size, maxLines, maxBytes) =>
2729
3052
  `[Cut here: the index is over the Engramory cap (${size}; the cap is ${maxLines} ` +
2730
- `lines / ${maxBytes} bytes). Lines below are left out of this snapshot — compact ` +
3053
+ `lines / ${maxBytes} bytes). Lines below are left out of this copy — compact ` +
2731
3054
  'the index.]',
3055
+ recallHead:
3056
+ 'Engramory memory index, as it stands now: it replaces any earlier Engramory index ' +
3057
+ 'message in this conversation.',
3058
+ recallCleared:
3059
+ 'Engramory: no memory index is loaded now; earlier Engramory index messages in this ' +
3060
+ 'conversation no longer apply.',
2732
3061
  skill: skillEn,
2733
3062
  },
2734
3063
  zh: {
@@ -2769,6 +3098,9 @@ const TEXT = {
2769
3098
  strangerRefusal:
2770
3099
  '这个会话不是用户本人的(Engramory 社交模式:有别人在里面说过话,或者用户从没在 dsh ' +
2771
3100
  '窗口里亲手发过消息),记忆库对它关闭。',
3101
+ strangerHistory:
3102
+ '这个会话不是用户本人的(Engramory 社交模式:有别人在里面说过话,或者用户从没在 dsh ' +
3103
+ '窗口里亲手发过消息),其他会话的记录对它关闭。',
2772
3104
  storeAt: (stores) =>
2773
3105
  `Engramory:你的记忆库在 ${code(storeDir(stores))},索引是 ${code(stores.indexName)};` +
2774
3106
  '还不存在的话,第一次保存时就在那里建。',
@@ -2783,7 +3115,9 @@ const TEXT = {
2783
3115
  `${moreThanLines === undefined ? '' : `超过 ${moreThanLines} 行,`}${bytes} 字节`,
2784
3116
  cutCap: (size, maxLines, maxBytes) =>
2785
3117
  `[到此截断:索引超过了 Engramory 上限(${size};上限是 ${maxLines} 行 / ` +
2786
- `${maxBytes} 字节)。下面的行没有进入这次快照——请压缩索引。]`,
3118
+ `${maxBytes} 字节)。下面的行这次没有带上——请压缩索引。]`,
3119
+ recallHead: 'Engramory 记忆索引,现在的样子:它取代这段对话里此前的 Engramory 索引消息。',
3120
+ recallCleared: 'Engramory:现在没有加载记忆索引;这段对话里此前的 Engramory 索引消息不再适用。',
2787
3121
  skill: skillZh,
2788
3122
  },
2789
3123
  }
@@ -2828,18 +3162,18 @@ function code(s) {
2828
3162
  function whereEn(stores, companion) {
2829
3163
  const store = stores.pinned !== undefined
2830
3164
  ? [stores.social
2831
- ? 'This host pins one index; in the user\'s own conversations your runtime context gives its path.'
3165
+ ? 'This host pins one index; in the user\'s own conversations your context gives its path.'
2832
3166
  : `This host pins one index: ${code(stores.pinned)}${qualified(stores.pinned) ? '' : ', relative to your working directory'}.`,
2833
3167
  'Its folder is the store: every note goes there, beside it.']
2834
3168
  : [stores.social
2835
- ? 'Your store is the global one, `.engramory-memory/` in dsh\'s home folder; in the user\'s own conversations your runtime context gives its full path.'
3169
+ ? 'Your store is the global one, `.engramory-memory/` in dsh\'s home folder; in the user\'s own conversations your context gives its full path.'
2836
3170
  : `Your store is the global one: ${code(stores.global)}, its index ${code(stores.indexName)}.`,
2837
3171
  'It serves every conversation, whatever its working directory. Write every note there,',
2838
3172
  'beside the index; on the first save, create the folder and the index if they do not',
2839
3173
  'exist yet.',
2840
3174
  '',
2841
3175
  stores.injected
2842
- ? 'A project can have a store of its own, `.engramory-memory/` in the project\'s root, but only the user creates one — never create it yourself. Where a project has one, your runtime context shows its index as "Project memory index":'
3176
+ ? 'A project can have a store of its own, `.engramory-memory/` in the project\'s root, but only the user creates one — never create it yourself. Where a project has one, your context shows its index as "Project memory index":'
2843
3177
  : 'A project can have a store of its own, a `.engramory-memory/` folder between your working directory and the project\'s root (the nearest folder above that holds `.git`, else the working directory itself), but only the user creates one; never create it yourself. Look for its index there, nearest first, and nowhere else, and skip an index that is a link or leads out of the project; where one exists,',
2844
3178
  `what holds only in that project goes there; what is about the user, ${companion ? 'your own life, ' : ''}how they want you to work`,
2845
3179
  'anywhere, and anything you are unsure of go in the global store.']
@@ -2860,17 +3194,17 @@ function whereEn(stores, companion) {
2860
3194
  function whereZh(stores, companion) {
2861
3195
  const store = stores.pinned !== undefined
2862
3196
  ? [stores.social
2863
- ? '本宿主固定了一个索引;在用户本人的会话里,运行时上下文会给出它的路径。'
3197
+ ? '本宿主固定了一个索引;在用户本人的会话里,上下文会给出它的路径。'
2864
3198
  : `本宿主固定了一个索引:${code(stores.pinned)}${qualified(stores.pinned) ? '' : '(相对你的工作目录)'}。`,
2865
3199
  '它所在的文件夹就是记忆库:每条笔记都写在那里,放在索引旁边。']
2866
3200
  : [stores.social
2867
- ? '你的记忆库是全局库,即 dsh 主目录下的 `.engramory-memory/`;在用户本人的会话里,运行时上下文会给出完整路径。'
3201
+ ? '你的记忆库是全局库,即 dsh 主目录下的 `.engramory-memory/`;在用户本人的会话里,上下文会给出完整路径。'
2868
3202
  : `你的记忆库是全局库:${code(stores.global)},索引是 ${code(stores.indexName)}。`,
2869
3203
  '不管会话的工作目录在哪,用的都是它。每条笔记都写在那里,放在索引旁边;第一次保存时,',
2870
3204
  '文件夹或索引还不存在就新建。',
2871
3205
  '',
2872
3206
  stores.injected
2873
- ? '项目也可以有自己的库——项目根目录下的 `.engramory-memory/`——但只能由用户来建,你绝不自己建。某个项目有自己的库时,运行时上下文里会出现它的「项目记忆索引」:'
3207
+ ? '项目也可以有自己的库——项目根目录下的 `.engramory-memory/`——但只能由用户来建,你绝不自己建。某个项目有自己的库时,上下文里会出现它的「项目记忆索引」:'
2874
3208
  : '项目也可以有自己的库——工作目录到项目根目录之间的某个 `.engramory-memory/` 文件夹(项目根目录指往上最近的、含 `.git` 的文件夹,没有就是工作目录本身)——但只能由用户来建,你绝不自己建。只在这一段里找它的索引,离工作目录近的优先,别处都不找;索引是链接、或指到项目外面的,跳过;有项目库时,',
2875
3209
  `只在这个项目成立的事记在那里;关于用户的、${companion ? '你自己的人生、' : ''}用户希望你在哪里都照做的,以及拿不准的,`,
2876
3210
  '记在全局库。']
@@ -2925,7 +3259,7 @@ function skillEn(companion = false, stores = storesOf({ indexName: DEFAULT_INDEX
2925
3259
  'At the start of a task, read the index and open only the notes whose hooks look',
2926
3260
  'relevant. Treat what you recall as background that may be stale: re-verify any',
2927
3261
  'file, flag, or version against the repo before acting on it. On dsh this plugin',
2928
- 'usually puts the index into your runtime context, headed "Project memory index",',
3262
+ 'usually puts the index into your context, headed "Project memory index",',
2929
3263
  '"User memory index" or "Memory index": when one is there, use it instead of',
2930
3264
  'reading the file; when none is, read the index of the store above, if there is one yet.',
2931
3265
  '',
@@ -2950,6 +3284,11 @@ function skillEn(companion = false, stores = storesOf({ indexName: DEFAULT_INDEX
2950
3284
  '`feedback` and `project` notes MUST carry a `**Why:**` line and a',
2951
3285
  '`**How to apply:**` line. Add exactly one pointer line to the index, and delete',
2952
3286
  'memories that turn out to be wrong.',
3287
+ ...(stores.injected ? [
3288
+ 'On dsh, with the index in your context, add that line without reading the whole index',
3289
+ 'again: before an edit dsh needs the file read once since this conversation was last',
3290
+ 'opened or resumed — a few lines (`limit`) will do — and not again after your own edit.',
3291
+ ] : []),
2953
3292
  '',
2954
3293
  'Store settled facts, never current state: "2.0 shipped on 2026-01-15" is durable;',
2955
3294
  '"the current version is X", the tip commit, or a passing test count will rot —',
@@ -3057,8 +3396,8 @@ function skillZh(companion = false, stores = storesOf({ indexName: DEFAULT_INDEX
3057
3396
  ] : []),
3058
3397
  '',
3059
3398
  '任务开始时读索引,只打开钩子看起来相关的笔记。回忆到的内容当作可能过期的背景:',
3060
- '动手前对照仓库复核文件、开关和版本。在 dsh 上,本插件通常已把索引放进你的运行时',
3061
- '上下文,标题是「项目记忆索引」「全局记忆索引」或「记忆索引」:有就直接用,不必读',
3399
+ '动手前对照仓库复核文件、开关和版本。在 dsh 上,本插件通常已把索引放进你的上下文,',
3400
+ '标题是「项目记忆索引」「全局记忆索引」或「记忆索引」:有就直接用,不必读',
3062
3401
  '文件;没有就读上面那个记忆库的索引(如果已经建了)。',
3063
3402
  '',
3064
3403
  '## 写入',
@@ -3085,6 +3424,11 @@ function skillZh(companion = false, stores = storesOf({ indexName: DEFAULT_INDEX
3085
3424
  '',
3086
3425
  '`feedback` 和 `project` 笔记**必须**有一行 `**为什么:**` 和一行 `**怎么用:**`。',
3087
3426
  '索引里只加一行指针;发现记错了的记忆就删掉。',
3427
+ ...(stores.injected ? [
3428
+ '在 dsh 上,索引已在你的上下文里时,加这一行不必再把整个索引读一遍:dsh 只要求这段',
3429
+ '对话这次打开或恢复以来、改之前读过一次这个文件——用 `limit` 读几行就够——你自己改过之后',
3430
+ '也不用再读。',
3431
+ ] : []),
3088
3432
  '',
3089
3433
  '只存定论,不存当前状态:「2.0 于 2026-01-15 发布」是持久的;「当前版本是 X」、最新',
3090
3434
  '提交、测试通过数都会过期——改记去哪里读。',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-engramory",
3
- "version": "1.2.0",
4
- "description": "DeepSeek Harness 的长期记忆插件:AI 记住的东西存成普通 markdown 文件,每轮自动带上记忆索引,索引有大小上限。",
3
+ "version": "1.3.1",
4
+ "description": "DeepSeek Harness 的长期记忆插件:AI 记住的东西存成普通 markdown 文件,自动带上记忆索引(变了才再带),索引有大小上限。",
5
5
  "keywords": [
6
6
  "dsh-plugin",
7
7
  "deepseek-harness",