dsh-plugin-memory 0.13.2 → 0.13.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  所有记录跟随 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/) 风格;版本号与 `package.json` 保持一致。
4
4
 
5
+ ## [0.13.3] - 2026-11-02
6
+
7
+ ### Fixed(boot 预算单位:字节 vs 字符)
8
+
9
+ - **中文 / 日文 / 韩文记忆库的 boot 文件被系统性低估预算**:`allocateBootBudget()` 用 `statSync().size`(UTF-8 字节)判断文件大小,`readCapped()` 却按字符 `slice()` 截断。中文 1 字 = 3 字节,于是每个 CJK 文件都被判成「超过均分额度」,cap 被抬到 `total/3`,pool 提前耗尽、短文件退回的余量永远不回流,真正长的文件被无谓截断。实测(12000 预算、`字` 每字 3 字节):6000 字符的 SOUL 被截到 4000,而此时预算还有 2000 字符空闲。
10
+ - 修复:`sizeOf()` 改为读取内容取 `.length`(字符),与 `readCapped` 及全仓其它口径(insights / checkup / doctor 均按字符)统一;同一 `allocateBootBudget()` 调用内缓存尺寸,读盘次数不增加量级。
11
+ - 影响面:英文库 1 字节 ≈ 1 字符,行为不变;CJK 库恢复按字符分配,短文件退回的余量可以回流给真正长的文件。
12
+ - **不变的部分**:`readCapped` 的截断提示、`renderBootBlock` 的总量兜底、`readTailCapped`(log)本来就是字符口径,未改动。
13
+
14
+ ### Tests
15
+
16
+ - `boot-budget` 新增 2 条 CJK 用例:`字` × 6000/1000/3000(长文件拿到回流、不截断);用户报告形状 `字` × 2141/3979/2744(短文件不再虚高吃 pool)。
17
+ - 全量 **262/262 通过**(0.13.2 基线 260 + 2);`node scripts/memory.mjs --self-test` PASS。
18
+
5
19
  ## [0.13.2] - 2026-10-30
6
20
 
7
21
  ### Fixed(reviewer 复核尾巴 + 结构修正)
package/lib/boot.js CHANGED
@@ -11,7 +11,7 @@
11
11
  * @module dsh-plugin-memory/boot
12
12
  */
13
13
 
14
- import { existsSync, readFileSync, statSync } from 'node:fs'
14
+ import { existsSync, readFileSync } from 'node:fs'
15
15
  import { join } from 'node:path'
16
16
 
17
17
  /** Files injected at session start when the config does not override them. */
@@ -92,8 +92,14 @@ export function parseLogEntries(logText, count = 5) {
92
92
  * twice the even share each): `index.md` first, then by size, so
93
93
  * truncation lands on bulky files no matter their order in `bootFiles`.
94
94
  *
95
- * While every file fits inside its even share this is byte-for-byte the old
96
- * behaviour; it only starts to differ once the store outgrows its share.
95
+ * While every file fits inside its even share this is character-for-character
96
+ * the old behaviour; it only starts to differ once the store outgrows its share.
97
+ *
98
+ * Budgets are expressed in **characters**, matching `readCapped` (`String.slice`)
99
+ * and every other size in the plugin. Sizing the files by `statSync().size` was
100
+ * a unit mismatch: a CJK file is ~3 UTF-8 bytes per character, so it looked 3x
101
+ * longer than it is, got capped at the even share, and the pool was spent before
102
+ * the surplus could flow back to the file that was actually long.
97
103
  *
98
104
  * @param {string} memoryDir absolute path of the memory store
99
105
  * @param {{ files?: string[], total?: number, perFile?: Record<string, number> }} [options]
@@ -102,13 +108,23 @@ export function parseLogEntries(logText, count = 5) {
102
108
  export function allocateBootBudget(memoryDir, options = {}) {
103
109
  const files = (options.files ?? []).filter((f) => typeof f === 'string' && f.length > 0)
104
110
  const total = Math.max(512, Number(options.total) || 6000)
105
- const sizeOf = (fileName) => {
106
- try {
107
- return statSync(join(memoryDir, fileName)).size
108
- } catch {
109
- return 0
111
+ const sizeOf = (() => {
112
+ const sizes = new Map()
113
+ return (fileName) => {
114
+ if (sizes.has(fileName)) return sizes.get(fileName)
115
+ let chars = 0
116
+ try {
117
+ // Characters, not bytes: caps are consumed by readCapped, which slices
118
+ // a UTF-16 string. A CJK file is ~3 bytes per character, so counting
119
+ // bytes would overstate it ~3x and starve the leftover pool.
120
+ chars = readFileSync(join(memoryDir, fileName), 'utf8').length
121
+ } catch {
122
+ chars = 0
123
+ }
124
+ sizes.set(fileName, chars)
125
+ return chars
110
126
  }
111
- }
127
+ })()
112
128
 
113
129
  const caps = new Map(files.map((f) => [f, 0]))
114
130
  const explicit = options.perFile ?? {}
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.13.2",
4
+ "version": "0.13.3",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "lib/index.js",