dsh-plugin-memory 0.11.0 → 0.13.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,38 @@
2
2
 
3
3
  所有记录跟随 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/) 风格;版本号与 `package.json` 保持一致。
4
4
 
5
+ ## [0.13.0] - 2026-10-30
6
+
7
+ ### Added(兼容声明 + 立即回顾 + 可访问性 + 工程化)
8
+
9
+ - **`engines.dsh` 兼容声明**:`package.json` 声明 `engines.dsh: "^0.2.1-rc.5"`——宿主引擎闸门用 semver(`includePrerelease: true`)校验,注意 `^0.2.1` / `>=0.2.0` 匹配不上 prerelease,必须写 `^0.2.1-rc.5`;旧宿主会被闸门拦住,而不是让插件半残运行。运行期缺失投影仍优雅降级(不发回顾/不抢发言权,绝不崩)。
10
+ - **「立即回顾」按钮 + 控制路由**:新增 `POST /api/memory/control`,action `growth-now` → 立即触发一次成长回顾。语义:尊重发言权仲裁;本周没有新内容就不发;**不受 `recallEnabled` 关闭影响**(显式手动操作),但要求插件启用、agent idle、成长回顾本身开启。响应 `{ ok, delivered, reason }`(`no-content` / `deferred` / `disabled` / `busy` / `growth-disabled` / `no-session` 等);非 POST → 405,未知 action / 坏 JSON → 400。面板按钮带「回顾中 / 已发送 / 另一插件正在说话 / 没有新内容 / 已关闭 / 失败」六态反馈。
11
+ - **面板可访问性**:按钮与表单补 `aria-label`,状态用 `role="status"`、错误用 `role="alert"`,键盘焦点加 `:focus-visible` 焦点环。
12
+ - **工程化**:`.github/workflows/ci.yml`(跑 `node --test` + `--self-test`)、Issue / PR 模板、`CONTRIBUTING.md`、`SECURITY.md`、`docs/PROACTIVE-PROTOCOL.md`(跨插件共享发言协议 v1 的公开说明;`docs/**` 在 `files` 内,因此该文档随 npm 包发布)。
13
+
14
+ ### Changed
15
+
16
+ - 面板控制逻辑把 `recallEnabled` 与「手动立即回顾」解耦:关闭自动追忆不再等于禁用用户显式发起的回顾。
17
+
18
+ ### Tests
19
+
20
+ - 新增 `test/control-route.test.mjs`、`test/growth-now.test.mjs`;`client-i18n` 补按钮文案与 a11y 契约。
21
+ - 全量单测 **255/255 通过**(0.12.0 基线 242,新增 13 条);`node scripts/memory.mjs --self-test` PASS。
22
+
23
+ ## [0.12.0] - 2026-10-30
24
+
25
+ ### Added(A 仲裁 + B 语气漂移 + C 表达层 + D 每周成长回顾)
26
+
27
+ - **A 发言权仲裁(与 heartbeat 插件共享协议)**:新增 `lib/proactive-lock.js`。所有主动消息(recall / digest / growth 三个通道)投递前先 claim 共享文件 `${DSH_HOME:-~/.dsh}/proactive-cooldown.json`(`{ version: 1, speaker: 'memory' | 'heartbeat', at: <epoch ms> }`,tmp+rename 原子写):若窗口内已有其他 speaker 的 claim,本条让位(日志 `... deferred for agent ... (... holds the lock)`)并**不消耗节奏**——下次触发自动重试;`proactiveCooldownSeconds`(默认 **180**,`0` = 关闭)。双方零 import,各自独立实现同一协议,任一方可单独装/卸。
28
+ - **B 语气漂移(`lib/tone.js`)**:boot 块在 SOUL 之后注入一小段 `## 语气(按语境微调)`(英文 `## Tone (adapt to context)`),共 ≤12 行:赶工/紧急修复短句先结论、深夜(23:00–06:00)更短更温和、报错/坏消息先给事实与修复动作、里程碑/完成可轻松一句、闲聊回默认小蓝口吻。`toneGuideEnabled`(默认 `true`)、`toneIntensity`(`low` / `medium` / `off`,默认 `low`);该段**计入 boot 预算**(先扣掉 tone 段的字符成本,再给文件分预算),不白嫖上下文。
29
+ - **C 表达层(只表达不假装)**:同一段语气规则内置表达边界——只描述**观察到的处境与关心**,不宣称内心情绪(禁「我很… / 我感到…」);仅允许三类场合:风险/坏消息、里程碑/完成、超过 3 天没联系后的第一次开口。原文例:「看你连着加班,有点担心你硬扛」。
30
+ - **D 每周成长回顾(`lib/growth.js`)**:`growthRecapEnabled`(默认 `true`)、`growthRecapIntervalDays`(默认 `7`);走 **recall 通道**(同一节律、同一每会话上限、同一仲裁锁),首人称「这周我记住了什么」;`<store>/.growth-recap.json` 记录上次投递,重启不会重复同一周的回顾;内容只从 `log.md` 标题与页面 mtime 派生——**不新增记账、不编造成长**。
31
+
32
+ ### Tests
33
+
34
+ - 新增 `test/tone.test.mjs`、`test/growth.test.mjs`、`test/proactive-lock.test.mjs`;`recall-nudge` / `digest-guard` / `plugin-metadata` 等补仲裁、语气、回顾用例。
35
+ - 全量单测 **242/242 通过**(0.11.0 基线 198,新增 44 条);`node scripts/memory.mjs --self-test` PASS。
36
+
5
37
  ## [0.11.0] - 2026-10-30
6
38
 
7
39
  ### Added(设置面板与侧栏 label 跟随语言:中英双语)
package/README.md CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  <p align="center">
6
6
  <a href="https://github.com/LittleBlackTong/dsh-plugin-memory"><img alt="GitHub" src="https://img.shields.io/badge/GitHub-LittleBlackTong%2Fdsh--plugin--memory-blue?logo=github"></a>
7
+ <a href="https://github.com/LittleBlackTong/dsh-plugin-memory/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/LittleBlackTong/dsh-plugin-memory/actions/workflows/ci.yml/badge.svg"></a>
7
8
  <a href="https://www.npmjs.com/package/dsh-plugin-memory"><img alt="npm" src="https://img.shields.io/npm/v/dsh-plugin-memory?logo=npm"></a>
8
9
  <img alt="license" src="https://img.shields.io/badge/license-MIT-blue">
9
10
  <img alt="node" src="https://img.shields.io/badge/node-%3E%3D18-green">
@@ -51,6 +52,15 @@ After that the loop is simple: the agent writes memories back as you work, and y
51
52
  - **Memory health dashboard**: below the same section is a **read-only** dashboard — memory pages / index routes / word count, an access-freshness bar chart (today / ≤7 / ≤30 / ≤90 / >90 days), four health verdicts (index links, orphan pages, frontmatter, freshness) with a health score, stale-page candidates, and the 5 most recent log entries. Data comes from the new `GET /api/memory/insights` (computed live per request, never cached), and its criteria share a source with `dsh-memory lint`, so the dashboard and the CLI cannot contradict each other.
52
53
  - **Zero build**: plain ESM JavaScript, no compilation step, usable straight after `pnpm add`.
53
54
 
55
+ ## Persona, politeness and growth (v0.12.0)
56
+
57
+ Four small additions turn the memory from "storage with a soul" into a companion that behaves:
58
+
59
+ - **Speech-right arbitration with other proactive plugins (A)**: before sending anything proactive — a recall, a digest reminder or a growth recap — the plugin claims the shared `${DSH_HOME:-~/.dsh}/proactive-cooldown.json` (`{ version: 1, speaker: 'memory' | 'heartbeat', at: <epoch ms> }`, atomic tmp+rename). If another speaker claimed inside `proactiveCooldownSeconds` (default **180**, `0` disables), the message is deferred and **the cadence is not consumed** — the next trigger retries. Neither plugin imports the other; both implement the same protocol independently, so either can be installed, upgraded or removed alone.
60
+ - **Tone drift (B)**: `lib/tone.js` injects a small `## Tone (adapt to context)` section right after SOUL (≤12 lines, **charged to the boot budget** — its character cost is deducted before the per-file allocation): crunch/urgent fix → short sentences, conclusion first, zero jokes; deep night (23:00–06:00) → shorter and gentler; errors/bad news → facts and the fix before any feelings; milestone/finished → one light line, then back to business. `toneGuideEnabled` (default `true`) switches it, `toneIntensity` (`low` / `medium` / `off`, default `low`) sets how visible it is.
61
+ - **Expression, never fake emotion (C)**: the same section draws the line — describe the **observed situation and care**, never claim inner feelings ("I am … / I feel …"); only three occasions are allowed: risk/bad news, milestones/completion, and the first line after 3+ days without contact.
62
+ - **Weekly growth recap (D)**: `growthRecapEnabled` (default `true`) and `growthRecapIntervalDays` (default `7`). It rides the **recall channel** (same cadence, same per-session cap, same arbitration lock) and reads only what the store already proves — recent `log.md` headlines and page mtimes — so there is no invented progress. `<store>/.growth-recap.json` remembers the last delivery, so a restart does not repeat the same week.
63
+
54
64
  ## Architecture
55
65
 
56
66
  The plugin owns the **workflow**, never the **data format**:
@@ -88,7 +98,7 @@ dsh plugin --profile <profile> add dsh-plugin-memory
88
98
 
89
99
  Restart the profile (restart the DSH Desktop app) to take effect.
90
100
 
91
- > 📌 **Version requirement: DSH session format v4 (official DeepSeek Harness 0.1.7+)**
101
+ > 📌 **Version requirement: DSH session format v4 + official DeepSeek Harness 0.2.1-rc.5 series** (0.13.x declares `engines.dsh`; older hosts are refused by the gate — see [Compatibility](#compatibility))
92
102
  >
93
103
  > Injected messages use the producer-owned source kind `plugin:memory`. v4's native admission explicitly rejects the v3-era `{ kind: 'plugin', plugin: 'memory' }` wrapper with
94
104
  > `format v4 message requires a producer-owned source kind` (the error is wrapped as `code: "UNKNOWN"`, so it surfaces in the UI as `... source kind UNKNOWN` — `UNKNOWN` is the error code, not a kind value).
@@ -121,6 +131,11 @@ Restart the profile (restart the DSH Desktop app) to take effect.
121
131
  | `recallIntervalMinMinutes` | `30` | Lower bound of the random interval (minutes, hot-editable) |
122
132
  | `recallIntervalMaxMinutes` | `240` | Upper bound of the random interval (minutes, hot-editable) |
123
133
  | `recallMaxPerSession` | `3` | Maximum recalls per session (hot-editable) |
134
+ | `proactiveCooldownSeconds` | `180` | Shared speech-floor cooldown against other proactive plugins (`0` = off) |
135
+ | `toneGuideEnabled` | `true` | Inject the context-sensitive tone section after SOUL |
136
+ | `toneIntensity` | `low` | `low` / `medium` / `off` (pure engineering voice) |
137
+ | `growthRecapEnabled` | `true` | Weekly growth recap on the recall channel |
138
+ | `growthRecapIntervalDays` | `7` | Days between growth recaps |
124
139
  | `autoCommit` | `true` | Git auto-commit switch for the store (composition) |
125
140
  | `autoCommitQuietSeconds` | `60` | How long changes must be quiet before committing (debounce) |
126
141
  | `autoCommitIntervalSeconds` | `60` | Change polling interval |
@@ -129,12 +144,18 @@ Restart the profile (restart the DSH Desktop app) to take effect.
129
144
 
130
145
  The section is registered as **"Memory"** in the English UI and **「记忆」** in the Chinese UI — it follows DSH's own language setting (see [Language](#language) below).
131
146
 
132
- Ten settings are editable in the "Memory" section of the DSH settings page and take effect **immediately**: `enabled` / `memoryDir` / `autoInject` / `deferUntilUserSpeaks` / `activeSessionOnly` / `registerSkill` / `recallEnabled` / `recallIntervalMinMinutes` / `recallIntervalMaxMinutes` / `recallMaxPerSession` — boot injection, the two polite gates, skill registration, and proactive recall (including its random interval and cap) all follow the change at once; switching the store directory scaffolds the new one automatically (when `scaffold: true`). The remaining keys (`bootFiles` / `bootMaxChars` / `bootFileBudgets` / `trackPageAccess` / `scaffold` / `configFile` / `digestNudge*` / `autoCommit*`) only apply at the composition layer and need a restart.
147
+ Fifteen settings are editable in the "Memory" section of the DSH settings page and take effect **immediately**: `enabled` / `memoryDir` / `autoInject` / `deferUntilUserSpeaks` / `activeSessionOnly` / `registerSkill` / `recallEnabled` / `recallIntervalMinMinutes` / `recallIntervalMaxMinutes` / `recallMaxPerSession` / `proactiveCooldownSeconds` / `toneGuideEnabled` / `toneIntensity` / `growthRecapEnabled` / `growthRecapIntervalDays` — boot injection, the two polite gates, skill registration, proactive recall (including its random interval and cap), speech-right arbitration, the tone section and the weekly growth recap all follow the change at once; switching the store directory scaffolds the new one automatically (when `scaffold: true`). The remaining keys (`bootFiles` / `bootMaxChars` / `bootFileBudgets` / `trackPageAccess` / `scaffold` / `configFile` / `digestNudge*` / `autoCommit*`) only apply at the composition layer and need a restart.
148
+
149
+ A **Review now** button sits beside them: it is a **control, not a setting** — it asks the plugin to send one growth recap immediately. It still respects the speech floor (it backs off if the other plugin is speaking), sends nothing when this week has no new material, works even while `recallEnabled` is off, and reports the outcome in the panel (sending / sent / deferred / no content / disabled / failed).
133
150
 
134
151
  ### Language
135
152
 
136
153
  The settings panel and its sidebar label follow DSH's own language setting (**Settings → General → Language**) and switch live — no restart: Chinese shows 「记忆」, English shows "Memory". Panel copy is registered as the `memory` locale namespace through `ctx.locale`, so the renderer re-renders the whole panel (form, health dashboard, graph card) in the active language and injects a `t(key)` seat into the section. The sidebar icon claim key is derived from that same label, so a language switch re-claims the right row. The dashboard's health-check labels **and details** are rebuilt client-side from locale-neutral `data` the insights route ships (`lib/insights.js` keeps the Chinese `label`/`detail` strings for the CLI); an older host payload without `data` falls back to those Chinese strings. User content (page titles, `log.md` headlines) and the CLI's own Chinese output are content, not UI copy, and stay as-is.
137
154
 
155
+ ### Compatibility
156
+
157
+ `package.json` declares `engines.dsh: "^0.2.1-rc.5"`, and the host enforces it with `semver.satisfies(..., { includePrerelease: true })` — the prerelease detail matters: `^0.2.1` or `>=0.2.0` do **not** match `0.2.1-rc.5`, so only the explicit prerelease range works (it also covers the eventual 0.2.1 stable). Two host services became load-bearing on the way here: the `locale` service (0.11+: the panel registers its dictionaries through it) and session projections (0.12+: speech arbitration and the growth recap read them). On an older host the gate refuses to load the plugin instead of letting it run half-broken; at runtime a missing projection still degrades gracefully — no recap, no speech-floor claim, never a crash.
158
+
138
159
  ### Boot budget allocation (why the index is not truncated first)
139
160
 
140
161
  `bootMaxChars` is a total budget, allocated per file rather than split evenly:
@@ -230,6 +251,8 @@ node scripts/memory.mjs --self-test # smoke test (no dependencies to install)
230
251
 
231
252
  Zero build: `lib/` is runtime code as-is, and `lib/types/index.d.ts` serves TypeScript consumers. `boot.js` / `scaffold.js` depend only on `node:*` built-ins and can be reused standalone.
232
253
 
254
+ The test suite (`node --test`) currently holds **255 tests**, and CI (`.github/workflows/ci.yml`) runs it together with `node scripts/memory.mjs --self-test`. Contribution and security policies live in [CONTRIBUTING.md](CONTRIBUTING.md) and [SECURITY.md](SECURITY.md); the cross-plugin speech-floor protocol is documented in [docs/PROACTIVE-PROTOCOL.md](docs/PROACTIVE-PROTOCOL.md).
255
+
233
256
  ## Roadmap
234
257
 
235
258
  - [ ] TypeScript rewrite (full types and a build step)
package/README.zh.md CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  <p align="center">
6
6
  <a href="https://github.com/LittleBlackTong/dsh-plugin-memory"><img alt="GitHub" src="https://img.shields.io/badge/GitHub-LittleBlackTong%2Fdsh--plugin--memory-blue?logo=github"></a>
7
+ <a href="https://github.com/LittleBlackTong/dsh-plugin-memory/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/LittleBlackTong/dsh-plugin-memory/actions/workflows/ci.yml/badge.svg"></a>
7
8
  <a href="https://www.npmjs.com/package/dsh-plugin-memory"><img alt="npm" src="https://img.shields.io/npm/v/dsh-plugin-memory?logo=npm"></a>
8
9
  <img alt="license" src="https://img.shields.io/badge/license-MIT-blue">
9
10
  <img alt="node" src="https://img.shields.io/badge/node-%3E%3D18-green">
@@ -51,6 +52,15 @@ dsh plugin --profile <profile> add dsh-plugin-memory
51
52
  - **记忆健康看板**:同一区块下方是一张**只读**看板——记忆页数 / index 路由数 / 记忆字数、访问新鲜度条形图(今天 / ≤7 / ≤30 / ≤90 / >90 天)、四项体检结论(index 链接、孤儿页、frontmatter、新鲜度)与健康分、陈旧页候选、最近 5 条动态。数据来自新增的 `GET /api/memory/insights`(每次请求实时统计,不缓存),体检口径与 `dsh-memory lint` 同源,所以看板与 CLI 不会互相打脸。
52
53
  - **零构建**:纯 ESM JavaScript,无编译步骤,`pnpm add` 即用。
53
54
 
55
+ ## 人格层、礼貌与成长(v0.12.0)
56
+
57
+ 四个小增量,把「带灵魂的存储」变成「会处事的伙伴」:
58
+
59
+ - **A 与其他主动插件的发言权仲裁**:任何主动消息——追忆、digest 提醒、成长回顾——发出前先 claim 共享文件 `${DSH_HOME:-~/.dsh}/proactive-cooldown.json`(`{ version: 1, speaker: 'memory' | 'heartbeat', at: <epoch ms> }`,tmp+rename 原子写)。若 `proactiveCooldownSeconds`(默认 **180**,`0` = 关闭)内有其他 speaker 先 claim,本条让位且**不消耗节奏**——下次触发自动重试。两个插件零 import、各自独立实现同一协议,任一方可单独装 / 升 / 卸。
60
+ - **B 语气漂移**:`lib/tone.js` 在 SOUL 之后注入一小段 `## 语气(按语境微调)`(≤12 行,**计入 boot 预算**——先扣掉该段字符成本再按文件分配):赶工/紧急修复 → 短句、先结论、零玩笑;深夜(23:00–06:00)→ 更短更温和;报错/坏消息 → 先给事实与修复动作再谈感受;里程碑/完成 → 轻松一句然后回正事。`toneGuideEnabled`(默认 `true`)开关,`toneIntensity`(`low` / `medium` / `off`,默认 `low`)控制明显程度。
61
+ - **C 表达层(只表达不假装)**:同一段语气规则画出边界——只描述**观察到的处境与关心**,不宣称内心情绪(禁「我很… / 我感到…」);仅允许三类场合:风险/坏消息、里程碑/完成、超过 3 天没联系后的第一次开口。
62
+ - **D 每周成长回顾**:`growthRecapEnabled`(默认 `true`)、`growthRecapIntervalDays`(默认 `7`)。走 **recall 通道**(同一节律、同一每会话上限、同一仲裁锁),内容只从记忆库已经证明的东西派生——最近的 `log.md` 标题与页面 mtime——不编造成长。`<store>/.growth-recap.json` 记录上次投递,重启不会重复同一周的回顾。
63
+
54
64
  ## 架构
55
65
 
56
66
  插件只拥有**工作流**,不拥有**数据格式**:
@@ -88,7 +98,7 @@ dsh plugin --profile <profile> add dsh-plugin-memory
88
98
 
89
99
  重启 profile(DSH Desktop 重启应用)后生效。
90
100
 
91
- > 📌 **版本要求:DSH session format v4(官方 DeepSeek Harness 0.1.7+)**
101
+ > 📌 **版本要求:DSH session format v4 + 官方 DeepSeek Harness 0.2.1-rc.5 系列**(0.13.x 已声明 `engines.dsh`;旧宿主会被闸门拒绝,见[兼容性](#兼容性))
92
102
  >
93
103
  > 注入消息的 source 使用 producer-owned kind `plugin:memory`。v4 的原生准入明确拒绝 v3 时代的
94
104
  > `{ kind: 'plugin', plugin: 'memory' }` wrapper,报
@@ -129,18 +139,29 @@ dsh plugin --profile <profile> add dsh-plugin-memory
129
139
  | `recallIntervalMinMinutes` | `30` | 随机间隔下限(分钟,面板可热改) |
130
140
  | `recallIntervalMaxMinutes` | `240` | 随机间隔上限(分钟,面板可热改) |
131
141
  | `recallMaxPerSession` | `3` | 每个会话最多追忆次数(面板可热改) |
142
+ | `proactiveCooldownSeconds` | `180` | 与其他主动插件的共享发言冷却(`0` = 关闭) |
143
+ | `toneGuideEnabled` | `true` | 在 SOUL 之后注入按语境微调的语气段 |
144
+ | `toneIntensity` | `low` | `low` / `medium` / `off`(off = 纯工程师语气) |
145
+ | `growthRecapEnabled` | `true` | 每周成长回顾(走 recall 通道) |
146
+ | `growthRecapIntervalDays` | `7` | 两次成长回顾间隔天数 |
132
147
  | `autoCommit` | `true` | 记忆库 git 自动提交开关(composition) |
133
148
  | `autoCommitQuietSeconds` | `60` | 变更静默多久后提交(防抖) |
134
149
  | `autoCommitIntervalSeconds` | `60` | 变更轮询间隔 |
135
150
 
136
151
  ### 设置面板(热改)
137
152
 
138
- `enabled` / `memoryDir` / `autoInject` / `deferUntilUserSpeaks` / `activeSessionOnly` / `registerSkill` / `recallEnabled` / `recallIntervalMinMinutes` / `recallIntervalMaxMinutes` / `recallMaxPerSession` 十项在 DSH 设置页的「记忆 / Memory」区块中可改(跟随语言),**即时生效**:boot 注入、两道礼貌闸门、技能注册、主动追忆(含随机间隔与次数)随修改立即生效;记忆目录切换时自动为新目录初始化脚手架(`scaffold: true` 时)。其余键(`bootFiles` / `bootMaxChars` / `bootFileBudgets` / `trackPageAccess` / `scaffold` / `configFile` / `digestNudge*` / `autoCommit*`)只在 composition 配置层生效,改完需重启。
153
+ `enabled` / `memoryDir` / `autoInject` / `deferUntilUserSpeaks` / `activeSessionOnly` / `registerSkill` / `recallEnabled` / `recallIntervalMinMinutes` / `recallIntervalMaxMinutes` / `recallMaxPerSession` / `proactiveCooldownSeconds` / `toneGuideEnabled` / `toneIntensity` / `growthRecapEnabled` / `growthRecapIntervalDays` 十五项在 DSH 设置页的「记忆 / Memory」区块中可改(跟随语言),**即时生效**:boot 注入、两道礼貌闸门、技能注册、主动追忆(含随机间隔与次数)、发言权仲裁、语气段与每周成长回顾随修改立即生效;记忆目录切换时自动为新目录初始化脚手架(`scaffold: true` 时)。其余键(`bootFiles` / `bootMaxChars` / `bootFileBudgets` / `trackPageAccess` / `scaffold` / `configFile` / `digestNudge*` / `autoCommit*`)只在 composition 配置层生效,改完需重启。
154
+
155
+ 旁边还有一个 **「立即回顾」按钮**:它是**控制动作,不是配置项**——让插件立刻发一次成长回顾。仍尊重发言权仲裁(别的插件在说话就让位)、本周没有新内容就不发、即使 `recallEnabled` 关闭也能用,并在面板里给出结果(回顾中 / 已发送 / 让位 / 没有新内容 / 已关闭 / 失败)。
139
156
 
140
157
  ### 语言 / Language
141
158
 
142
159
  设置面板与侧栏 label 跟随 DSH 自己的语言设置(**设置 → 通用设置 → 语言**),切换即时生效、无需重启:中文显示「记忆」,英文显示 "Memory"。面板文案通过 `ctx.locale` 注册在 `memory` 命名空间,renderer 会给区块注入 `t(key)` 座位,于是表单、健康看板、图谱卡片整体重渲染为当前语言;侧栏图标的认领键取自同一个 label 解析函数,语言切换后自动重新认领正确的那一行。健康看板的四项体检 **label 与 detail** 由 insights 路由新增的结构化 `data` 在客户端按语言重建(`lib/insights.js` 仍保留中文 `label`/`detail` 供 CLI 使用);旧版本宿主 payload 没有 `data` 时回退中文串。用户内容(页面标题、`log.md` 动态)与 CLI 自身的中文输出属于内容而非界面文案,不在翻译范围内。
143
160
 
161
+ ### 兼容性
162
+
163
+ `package.json` 声明 `engines.dsh: "^0.2.1-rc.5"`,宿主用 `semver.satisfies(..., { includePrerelease: true })` 强制校验——prerelease 细节很关键:`^0.2.1` / `>=0.2.0` **匹配不上** `0.2.1-rc.5`,只有显式写 prerelease range 才认(它同时覆盖将来的 0.2.1 正式版)。一路走来有两个宿主服务变成「承重」的:`locale` 服务(0.11+:面板通过它注册语言包)与会话投影(0.12+:发言权仲裁与成长回顾要读)。旧宿主会被闸门直接拒绝加载,而不是让插件半残运行;运行期缺投影则优雅降级——不发回顾、不抢发言权,绝不崩。
164
+
144
165
  ### boot 预算分配(为什么 index 不会先被截掉)
145
166
 
146
167
  `bootMaxChars` 是总预算,按文件分配而不是简单平摊:
@@ -236,6 +257,8 @@ node scripts/memory.mjs --self-test # 冒烟测试(无需安装依赖)
236
257
 
237
258
  零构建:`lib/` 直接是运行时代码,`lib/types/index.d.ts` 供 TS 消费方使用。`boot.js` / `scaffold.js` 只依赖 `node:*` 内置模块,可独立复用。
238
259
 
260
+ 测试用 `node --test`,当前共 **255 个用例**;CI(`.github/workflows/ci.yml`)会连同 `node scripts/memory.mjs --self-test` 一起跑。贡献与安全策略见 [CONTRIBUTING.md](CONTRIBUTING.md)、[SECURITY.md](SECURITY.md);跨插件发言协议见 [docs/PROACTIVE-PROTOCOL.md](docs/PROACTIVE-PROTOCOL.md)。
261
+
239
262
  ## 路线图
240
263
 
241
264
  - [ ] TypeScript 重写(带完整类型与构建步骤)
@@ -0,0 +1,81 @@
1
+ # Proactive-cooldown protocol (v1)
2
+
3
+ Two DSH plugins may independently decide, on their own timers, that the agent
4
+ should say something unprompted:
5
+
6
+ - **dsh-plugin-memory** — recall nudges, digest reminders, weekly growth recaps;
7
+ - **dsh-plugin-heartbeat** — L1 reports, L2 questions, L4 escalations.
8
+
9
+ Talking over each other in the same quiet window looks like a split
10
+ personality, so both plugins honour one shared, advisory **speech floor**. The
11
+ protocol deliberately lives in a **plain JSON file**, not an import: each plugin
12
+ ships its own tiny implementation, so either one can be installed, upgraded or
13
+ removed without touching the other (`zero cross-plugin imports`).
14
+
15
+ ## File
16
+
17
+ ```
18
+ ${DSH_HOME:-~/.dsh}/proactive-cooldown.json
19
+ ```
20
+
21
+ ```json
22
+ { "version": 1, "speaker": "memory" | "heartbeat", "at": 1760000000000 }
23
+ ```
24
+
25
+ - `at` is an epoch-millisecond timestamp of the last claim.
26
+ - Writes are atomic (`temp file + rename`): a reader never sees a partial
27
+ document.
28
+ - A missing, unreadable or malformed file means **"no lock"** — a broken
29
+ cooldown must never silence a plugin forever.
30
+
31
+ ## Claim algorithm
32
+
33
+ Before injecting a proactive followup, a plugin calls:
34
+
35
+ ```js
36
+ claimProactiveLock({ path, speaker, cooldownSeconds, now })
37
+ ```
38
+
39
+ 1. Read the file. If it is missing/corrupt → no lock.
40
+ 2. If `at > now - cooldownSeconds * 1000` **and** `speaker !== self`:
41
+ - return `{ ok: false, deferredBy: <other speaker> }`;
42
+ - the caller yields **for this attempt only** (do not consume its own
43
+ cadence or signal set — retry on a later trigger);
44
+ - heartbeat records the yield as `L0 · proactive-cooldown` and re-arms.
45
+ 3. Otherwise write `{ version: 1, speaker: self, at: now }` (atomic) and
46
+ return `{ ok: true }`.
47
+
48
+ `cooldownSeconds <= 0` disables arbitration: claim returns `{ ok: true }`
49
+ without writing anything.
50
+
51
+ ## Rules
52
+
53
+ - The lock is **advisory**: a failed write (read-only home, EACCES, …) must
54
+ degrade to "go ahead" — politeness, not a hard dependency.
55
+ - **Manual user actions bypass the floor** (e.g. heartbeat's *Beat now*), since
56
+ the user explicitly asked for speech.
57
+ - A speaker may re-claim/refresh its **own** lock (same `speaker`) at any time.
58
+ - Default cooldown: **180 seconds** (`proactiveCooldownSeconds` in both plugins;
59
+ `0` turns arbitration off).
60
+ - Old files without `version`/`speaker` are treated as no lock; only
61
+ `{version:1, speaker, at}` is written by both implementations.
62
+
63
+ ## Compatibility matrix
64
+
65
+ | Plugin | 0.12.x | 0.13.x | Notes |
66
+ | --- | --- | --- | --- |
67
+ | dsh-plugin-memory | v1 | v1 | since 0.12.0 |
68
+ | dsh-plugin-heartbeat | v1 | v1 | since 0.7.0 |
69
+
70
+ A third-party plugin is welcome to participate: implement the same claim
71
+ algorithm, use a unique `speaker` value, and read the same file. Unknown
72
+ speakers are treated as "someone else holds the floor" until the cooldown
73
+ expires.
74
+
75
+ ## Tests
76
+
77
+ Both repositories test the protocol independently and cross-check each other's
78
+ implementation (`test/proactive-lock.test.mjs` in
79
+ [dsh-plugin-memory](https://github.com/LittleBlackTong/dsh-plugin-memory) and
80
+ [dsh-plugin-heartbeat](https://github.com/LittleBlackTong/dsh-plugin-heartbeat))
81
+ with real files and real timestamps.
package/lib/boot.js CHANGED
@@ -22,6 +22,9 @@ export const DEFAULT_BOOT_FILES = ['SOUL.md', 'MEMORY.md', 'index.md']
22
22
  * signal, and this block is injected on every request. */
23
23
  export const RECENT_LOG_COUNT = 3
24
24
 
25
+ /** Separator joining the boot-block sections. */
26
+ const SECTION_SEPARATOR = '\n\n---\n\n'
27
+
25
28
  /** Read a file and cap it at `maxChars`, noting truncation when applied. */
26
29
  export function readCapped(path, maxChars) {
27
30
  if (!existsSync(path)) return undefined
@@ -224,7 +227,7 @@ export function needsSoulBootstrap(memoryDir) {
224
227
  * onboarding the user gets with a fresh OpenClaw instance.
225
228
  *
226
229
  * @param {string} memoryDir absolute path of the memory store
227
- * @param {{ bootFiles?: string[], bootMaxChars?: number, bootFileBudgets?: Record<string, number> }} options
230
+ * @param {{ bootFiles?: string[], bootMaxChars?: number, bootFileBudgets?: Record<string, number>, toneGuide?: string }} options
228
231
  * @returns {string} the model-facing boot block; '' when the store is empty
229
232
  */
230
233
  export function renderBootBlock(memoryDir, options = {}) {
@@ -232,20 +235,36 @@ export function renderBootBlock(memoryDir, options = {}) {
232
235
  ? options.bootFiles
233
236
  : DEFAULT_BOOT_FILES
234
237
  const total = Math.max(512, options.bootMaxChars ?? 6000)
238
+ // The tone section rides along on every request, so it is charged to the
239
+ // same budget as the store files: without this the persona paragraph would
240
+ // silently push the end of `index.md` out of the block.
241
+ const toneSection = typeof options.toneGuide === 'string' && options.toneGuide.trim().length > 0
242
+ ? options.toneGuide.trim()
243
+ : ''
244
+ const toneCost = toneSection.length > 0 ? toneSection.length + SECTION_SEPARATOR.length : 0
245
+ const fileBudget = Math.max(512, total - toneCost)
235
246
  const caps = allocateBootBudget(memoryDir, {
236
247
  files: bootFiles,
237
- total,
248
+ total: fileBudget,
238
249
  perFile: options.bootFileBudgets,
239
250
  })
240
251
 
241
252
  const sections = []
253
+ let toneInjected = false
242
254
  for (const fileName of bootFiles) {
243
255
  const path = join(memoryDir, fileName)
244
256
  const cap = caps.get(fileName) ?? 0
245
257
  const text = cap > 0 ? readCapped(path, cap) : undefined
246
258
  if (text === undefined || text.trim() === '') continue
247
259
  sections.push(`### ${fileName}\n\n${text}`)
260
+ // Personality first, then how to speak: the tone section goes right after
261
+ // the soul file so the rules are read as an extension of the persona.
262
+ if (fileName === 'SOUL.md' && toneSection.length > 0) {
263
+ sections.push(toneSection)
264
+ toneInjected = true
265
+ }
248
266
  }
267
+ if (toneSection.length > 0 && !toneInjected) sections.push(toneSection)
249
268
 
250
269
  if (sections.length === 0) return ''
251
270
 
@@ -258,7 +277,7 @@ export function renderBootBlock(memoryDir, options = {}) {
258
277
  sections.push(`### 最近动态(log.md 末尾 ${logEntries.length} 条)\n\n${logEntries.map((e) => `- ${e}`).join('\n')}`)
259
278
  }
260
279
 
261
- const body = sections.join('\n\n---\n\n')
280
+ const body = sections.join(SECTION_SEPARATOR)
262
281
  const header = `长期记忆(dsh-plugin-memory)。记忆库位于 ${memoryDir}。这是你跨会话的持久人格与记忆:以它为准,先读完再回复用户。若与当前对话冲突,优先相信用户的最新表述,并把差异写回记忆。**每次会话收尾前必须执行 memory digest:把本会话关键沉淀写回(更新页面 + index.md + 追加 log.md)。插件会注入 digest 提醒消息,收到后立即写回,不得拖延;若本会话确无值得持久化的内容,在 log.md 记一条「无新增」并说明原因。**`
263
282
 
264
283
  let result