dsh-plugin-memory 0.10.1 → 0.12.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 +30 -0
- package/README.md +21 -1
- package/README.zh.md +22 -4
- package/lib/boot.js +22 -3
- package/lib/client.js +495 -78
- package/lib/config-store.js +19 -1
- package/lib/digest-guard.js +35 -1
- package/lib/growth.js +201 -0
- package/lib/index.js +54 -2
- package/lib/insights.js +17 -3
- package/lib/proactive-lock.js +122 -0
- package/lib/recall-nudge.js +122 -1
- package/lib/schema.js +10 -0
- package/lib/settings-nav-icon.js +17 -4
- package/lib/tone.js +86 -0
- package/lib/types/index.d.ts +44 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
所有记录跟随 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/) 风格;版本号与 `package.json` 保持一致。
|
|
4
4
|
|
|
5
|
+
## [0.12.0] - 2026-10-30
|
|
6
|
+
|
|
7
|
+
### Added(A 仲裁 + B 语气漂移 + C 表达层 + D 每周成长回顾)
|
|
8
|
+
|
|
9
|
+
- **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,各自独立实现同一协议,任一方可单独装/卸。
|
|
10
|
+
- **B 语气漂移(`lib/tone.js`)**:boot 块在 SOUL 之后注入一小段 `## 语气(按语境微调)`(英文 `## Tone (adapt to context)`),共 ≤12 行:赶工/紧急修复短句先结论、深夜(23:00–06:00)更短更温和、报错/坏消息先给事实与修复动作、里程碑/完成可轻松一句、闲聊回默认小蓝口吻。`toneGuideEnabled`(默认 `true`)、`toneIntensity`(`low` / `medium` / `off`,默认 `low`);该段**计入 boot 预算**(先扣掉 tone 段的字符成本,再给文件分预算),不白嫖上下文。
|
|
11
|
+
- **C 表达层(只表达不假装)**:同一段语气规则内置表达边界——只描述**观察到的处境与关心**,不宣称内心情绪(禁「我很… / 我感到…」);仅允许三类场合:风险/坏消息、里程碑/完成、超过 3 天没联系后的第一次开口。原文例:「看你连着加班,有点担心你硬扛」。
|
|
12
|
+
- **D 每周成长回顾(`lib/growth.js`)**:`growthRecapEnabled`(默认 `true`)、`growthRecapIntervalDays`(默认 `7`);走 **recall 通道**(同一节律、同一每会话上限、同一仲裁锁),首人称「这周我记住了什么」;`<store>/.growth-recap.json` 记录上次投递,重启不会重复同一周的回顾;内容只从 `log.md` 标题与页面 mtime 派生——**不新增记账、不编造成长**。
|
|
13
|
+
|
|
14
|
+
### Tests
|
|
15
|
+
|
|
16
|
+
- 新增 `test/tone.test.mjs`、`test/growth.test.mjs`、`test/proactive-lock.test.mjs`;`recall-nudge` / `digest-guard` / `plugin-metadata` 等补仲裁、语气、回顾用例。
|
|
17
|
+
- 全量单测 **242/242 通过**(0.11.0 基线 198,新增 44 条);`node scripts/memory.mjs --self-test` PASS。
|
|
18
|
+
|
|
19
|
+
## [0.11.0] - 2026-10-30
|
|
20
|
+
|
|
21
|
+
### Added(设置面板与侧栏 label 跟随语言:中英双语)
|
|
22
|
+
|
|
23
|
+
- **面板接 DSH 官方语言层**:客户端半 `exports.inject = ['slots', 'locale']`,`apply()` 里 `ctx.locale.register('memory', { zh, en })`,`settings.section` 注册项声明 `locale: 'memory'` → renderer 会注入 `t(key)` 座位,在「设置 → 通用设置 → 语言」切换时整块面板(表单 / 健康看板 / 图谱卡片)自动重渲染;不读 `navigator.language`、无需重启。共 **86 个翻译 key**,中英一一对齐(测试强制校验,且源码里不允许出现字典外的中文字面量)。
|
|
24
|
+
- **侧栏 label 跟随语言**:中文「记忆」/ 英文 "Memory",由纯函数 `sectionLabel(language)` 解析(`lib/settings-nav-icon.js` 与客户端内联副本各一份,测试校验两处一致);`claimNavIcon` 的认领键用同一个函数,语言切换后 MutationObserver 重新认领正确行,不会盖掉别人的图标。
|
|
25
|
+
- **健康看板可全英文**:`lib/insights.js` 对 `health.checks[]` 追加 **additive 的结构化 `data`**(`index → {routes, missing}` / `orphans → {count, sample}` / `frontmatter → {missingSalience, missingType}` / `freshness → {atRisk}`),并新增 `typeCounts[]` 作为 `byType` 的语言中立别名(同样带 `type`/`label`/`count`)。客户端用 `t()` + `data` 重建 label/detail,英文界面不再残留中文体检结论;**旧字段 `label`/`detail` 原样保留**,CLI(`checkup`/`status`)与旧前端不受影响,缺 `data` 的旧 payload 回退中文。
|
|
26
|
+
- **图谱与文字细节**:节点 tooltip 的「N 条关系」、类型图例/tooltip、统计行、孤立页提示、图例说明、`aria-label` 全部走语言包;`type` 按已知 8 类 + `unknown` 翻译,未知类型回退原值。图标规格不变(16×16 / stroke 1.3 / 纯黑 alpha)。
|
|
27
|
+
|
|
28
|
+
### Tests
|
|
29
|
+
|
|
30
|
+
- 新增 `test/client-i18n.test.mjs`(15 条,`node:vm` 假 DOM/MutationObserver/React 加载 `lib/client.js`):inject 含 `locale`、`slot.locale = 'memory'`、字典中英 key 完全对齐、无死 key、源码无字典外中文字面量、不读 `navigator.language`、中英 label 与图标认领、语言切换后 MutationObserver 重新认领、teardown 摘干净、`t` 座位缺失回退中文不崩、注入的 `t` 优先、整块表单/健康看板/图谱英文渲染**零中文残留**(用带中文 label/detail 的假 payload 证明看板 label/detail 来自英文语言包)、旧 payload 向后兼容。
|
|
31
|
+
- `test/settings-nav-icon.test.mjs` 改为动态 label:`sectionLabel('zh') === '记忆'` / `sectionLabel('en') === 'Memory'`、未知或缺失语言回退中文、两种语言互不认领对方的行。
|
|
32
|
+
- `test/insights.test.mjs` / `test/insights-route.test.mjs` 补新字段断言(`checks[].data`、`typeCounts` 与 `byType` 一致、中文 `label`/`detail` 原样保留),不削弱既有断言;`test/graph-card.test.mjs` 的 React stub 补 `createContext`/`useContext`。
|
|
33
|
+
- 全量 **198/198 通过**(0.10.1 基线 181,新增 17 条);`node scripts/memory.mjs --self-test` PASS;`npm pack --dry-run` 正常(文件清单不变)。
|
|
34
|
+
|
|
5
35
|
## [0.10.1] - 2026-10-30
|
|
6
36
|
|
|
7
37
|
### Changed(文档)
|
package/README.md
CHANGED
|
@@ -51,6 +51,15 @@ After that the loop is simple: the agent writes memories back as you work, and y
|
|
|
51
51
|
- **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
52
|
- **Zero build**: plain ESM JavaScript, no compilation step, usable straight after `pnpm add`.
|
|
53
53
|
|
|
54
|
+
## Persona, politeness and growth (v0.12.0)
|
|
55
|
+
|
|
56
|
+
Four small additions turn the memory from "storage with a soul" into a companion that behaves:
|
|
57
|
+
|
|
58
|
+
- **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.
|
|
59
|
+
- **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.
|
|
60
|
+
- **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.
|
|
61
|
+
- **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.
|
|
62
|
+
|
|
54
63
|
## Architecture
|
|
55
64
|
|
|
56
65
|
The plugin owns the **workflow**, never the **data format**:
|
|
@@ -121,13 +130,24 @@ Restart the profile (restart the DSH Desktop app) to take effect.
|
|
|
121
130
|
| `recallIntervalMinMinutes` | `30` | Lower bound of the random interval (minutes, hot-editable) |
|
|
122
131
|
| `recallIntervalMaxMinutes` | `240` | Upper bound of the random interval (minutes, hot-editable) |
|
|
123
132
|
| `recallMaxPerSession` | `3` | Maximum recalls per session (hot-editable) |
|
|
133
|
+
| `proactiveCooldownSeconds` | `180` | Shared speech-floor cooldown against other proactive plugins (`0` = off) |
|
|
134
|
+
| `toneGuideEnabled` | `true` | Inject the context-sensitive tone section after SOUL |
|
|
135
|
+
| `toneIntensity` | `low` | `low` / `medium` / `off` (pure engineering voice) |
|
|
136
|
+
| `growthRecapEnabled` | `true` | Weekly growth recap on the recall channel |
|
|
137
|
+
| `growthRecapIntervalDays` | `7` | Days between growth recaps |
|
|
124
138
|
| `autoCommit` | `true` | Git auto-commit switch for the store (composition) |
|
|
125
139
|
| `autoCommitQuietSeconds` | `60` | How long changes must be quiet before committing (debounce) |
|
|
126
140
|
| `autoCommitIntervalSeconds` | `60` | Change polling interval |
|
|
127
141
|
|
|
128
142
|
### Settings panel (hot edits)
|
|
129
143
|
|
|
130
|
-
|
|
144
|
+
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).
|
|
145
|
+
|
|
146
|
+
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.
|
|
147
|
+
|
|
148
|
+
### Language
|
|
149
|
+
|
|
150
|
+
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.
|
|
131
151
|
|
|
132
152
|
### Boot budget allocation (why the index is not truncated first)
|
|
133
153
|
|
package/README.zh.md
CHANGED
|
@@ -42,7 +42,7 @@ dsh plugin --profile <profile> add dsh-plugin-memory
|
|
|
42
42
|
- **防懒 digest 唤醒**:每轮结束后,若 agent 空闲且记忆库超过 `digestNudgeAfterMinutes` 未写入,插件注入一条 digest 提醒(合成消息,走 `agent.followup`),把"会话收尾沉淀"从靠自觉变成有机制兜底;带冷却与每会话限次,不骚扰。**独立于 dsh-plugin-heartbeat**,两插件各自可装、互不依赖。
|
|
43
43
|
- **主动追忆(拟人化)**:对话空下来时,插件会以第一人称主动提起一件**真实记得**的、关于用户或你们之间的事(偏好、往事、未了的决定、最近的进展),把记忆从"只写回"变成"也用起来"——像老友自然想起那样,而非报状态。间隔在最短/最长之间**随机取值**(不固定节奏),配合每会话限次,不骚扰、不编造、不硬聊;纯对话行为,不写记忆库。**同样独立于 heartbeat**。
|
|
44
44
|
- **git 自动提交**:记忆库变更静默 `autoCommitQuietSeconds` 后自动 `git add -A && git commit`(无 `.git` 则跳过)——历史可回滚不再依赖 agent 记得 commit。
|
|
45
|
-
- **设置面板**:在 DSH 设置页提供「记忆 Memory
|
|
45
|
+
- **设置面板**:在 DSH 设置页提供「记忆 / Memory」区块(跟随语言)——总开关、记忆目录、开机注入、技能注册、主动追忆(开关 + 随机间隔范围 + 每会话次数)均可热改,立即生效,无需重启。
|
|
46
46
|
- **index 自动整理(声明式编译)**:索引行不再手写。页面在 frontmatter 里声明 `summary:`,`dsh-memory index --write` 把行重写为它的投影(标签 ≤32 / 摘要 ≤48 / 整行 ≤132 字符),**只改行内容,分节与顺序逐字节保留**,且幂等。`index --check` 给机器判定(有漂移退出码非 0),`index --sync-frontmatter` 把已写在 index 里的摘要回填进页面(老库一次性迁移)。digest 提醒会在索引漂移时附一句提示,agent 顺手就能修。
|
|
47
47
|
- **互链成为默认动作**:`index.md` 是目录(谁存在),页间互链才是**关系**(谁和谁有关)——实测一个真实记忆库里 29 页只有 1 条真互链,而图谱与跨页综合全都建立在这层关系上。现在三处一起推:`skills/memory.md` 的 remember 流程、`MEMORY.md` 模板的工作流、以及 digest 提醒的收尾指令,都明确要求"给这次碰过的页面各补 1–3 条相关页链接"。
|
|
48
48
|
- **补链建议**:`dsh-memory graph --suggest` 列出「只有索引入口、没有任何内容关系」的页面该引用谁——按共享主题 tag、标题词、同类型打分,并说明理由(`共享 #dsh` / `标题词 dsh` / `同类型`)。只报告不写入:是否连、怎么连由 agent 决定。`GET /api/memory/graph?suggest=1` 同源。
|
|
@@ -51,6 +51,15 @@ dsh plugin --profile <profile> add dsh-plugin-memory
|
|
|
51
51
|
- **记忆健康看板**:同一区块下方是一张**只读**看板——记忆页数 / index 路由数 / 记忆字数、访问新鲜度条形图(今天 / ≤7 / ≤30 / ≤90 / >90 天)、四项体检结论(index 链接、孤儿页、frontmatter、新鲜度)与健康分、陈旧页候选、最近 5 条动态。数据来自新增的 `GET /api/memory/insights`(每次请求实时统计,不缓存),体检口径与 `dsh-memory lint` 同源,所以看板与 CLI 不会互相打脸。
|
|
52
52
|
- **零构建**:纯 ESM JavaScript,无编译步骤,`pnpm add` 即用。
|
|
53
53
|
|
|
54
|
+
## 人格层、礼貌与成长(v0.12.0)
|
|
55
|
+
|
|
56
|
+
四个小增量,把「带灵魂的存储」变成「会处事的伙伴」:
|
|
57
|
+
|
|
58
|
+
- **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、各自独立实现同一协议,任一方可单独装 / 升 / 卸。
|
|
59
|
+
- **B 语气漂移**:`lib/tone.js` 在 SOUL 之后注入一小段 `## 语气(按语境微调)`(≤12 行,**计入 boot 预算**——先扣掉该段字符成本再按文件分配):赶工/紧急修复 → 短句、先结论、零玩笑;深夜(23:00–06:00)→ 更短更温和;报错/坏消息 → 先给事实与修复动作再谈感受;里程碑/完成 → 轻松一句然后回正事。`toneGuideEnabled`(默认 `true`)开关,`toneIntensity`(`low` / `medium` / `off`,默认 `low`)控制明显程度。
|
|
60
|
+
- **C 表达层(只表达不假装)**:同一段语气规则画出边界——只描述**观察到的处境与关心**,不宣称内心情绪(禁「我很… / 我感到…」);仅允许三类场合:风险/坏消息、里程碑/完成、超过 3 天没联系后的第一次开口。
|
|
61
|
+
- **D 每周成长回顾**:`growthRecapEnabled`(默认 `true`)、`growthRecapIntervalDays`(默认 `7`)。走 **recall 通道**(同一节律、同一每会话上限、同一仲裁锁),内容只从记忆库已经证明的东西派生——最近的 `log.md` 标题与页面 mtime——不编造成长。`<store>/.growth-recap.json` 记录上次投递,重启不会重复同一周的回顾。
|
|
62
|
+
|
|
54
63
|
## 架构
|
|
55
64
|
|
|
56
65
|
插件只拥有**工作流**,不拥有**数据格式**:
|
|
@@ -65,7 +74,7 @@ dsh-plugin-memory(本插件)
|
|
|
65
74
|
├── lib/digest-guard.js # 防懒 digest 唤醒(空闲 + 记忆库久未写 → followup 提醒)
|
|
66
75
|
├── lib/recall-nudge.js # 主动追忆(空闲 → 第一人称提起一件真实往事,纯对话不写库)
|
|
67
76
|
├── lib/scaffold.js # 记忆库脚手架(模板只建不覆盖)
|
|
68
|
-
├── lib/client.js # 客户端半:设置面板「记忆 Memory
|
|
77
|
+
├── lib/client.js # 客户端半:设置面板「记忆 / Memory」区块(跟随语言)+ 记忆健康看板
|
|
69
78
|
├── skills/memory.md # 内嵌技能的操作协议正文
|
|
70
79
|
└── scripts/memory.mjs # CLI:init/search/touch/lint/status/pack/unpack
|
|
71
80
|
|
|
@@ -129,13 +138,22 @@ dsh plugin --profile <profile> add dsh-plugin-memory
|
|
|
129
138
|
| `recallIntervalMinMinutes` | `30` | 随机间隔下限(分钟,面板可热改) |
|
|
130
139
|
| `recallIntervalMaxMinutes` | `240` | 随机间隔上限(分钟,面板可热改) |
|
|
131
140
|
| `recallMaxPerSession` | `3` | 每个会话最多追忆次数(面板可热改) |
|
|
141
|
+
| `proactiveCooldownSeconds` | `180` | 与其他主动插件的共享发言冷却(`0` = 关闭) |
|
|
142
|
+
| `toneGuideEnabled` | `true` | 在 SOUL 之后注入按语境微调的语气段 |
|
|
143
|
+
| `toneIntensity` | `low` | `low` / `medium` / `off`(off = 纯工程师语气) |
|
|
144
|
+
| `growthRecapEnabled` | `true` | 每周成长回顾(走 recall 通道) |
|
|
145
|
+
| `growthRecapIntervalDays` | `7` | 两次成长回顾间隔天数 |
|
|
132
146
|
| `autoCommit` | `true` | 记忆库 git 自动提交开关(composition) |
|
|
133
147
|
| `autoCommitQuietSeconds` | `60` | 变更静默多久后提交(防抖) |
|
|
134
148
|
| `autoCommitIntervalSeconds` | `60` | 变更轮询间隔 |
|
|
135
149
|
|
|
136
150
|
### 设置面板(热改)
|
|
137
151
|
|
|
138
|
-
`enabled` / `memoryDir` / `autoInject` / `deferUntilUserSpeaks` / `activeSessionOnly` / `registerSkill` / `recallEnabled` / `recallIntervalMinMinutes` / `recallIntervalMaxMinutes` / `recallMaxPerSession`
|
|
152
|
+
`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 配置层生效,改完需重启。
|
|
153
|
+
|
|
154
|
+
### 语言 / Language
|
|
155
|
+
|
|
156
|
+
设置面板与侧栏 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 自身的中文输出属于内容而非界面文案,不在翻译范围内。
|
|
139
157
|
|
|
140
158
|
### boot 预算分配(为什么 index 不会先被截掉)
|
|
141
159
|
|
|
@@ -151,7 +169,7 @@ dsh plugin --profile <profile> add dsh-plugin-memory
|
|
|
151
169
|
|
|
152
170
|
### 记忆健康看板
|
|
153
171
|
|
|
154
|
-
设置页「记忆 Memory」区块下方是一张**只读**看板,数据来自 `GET /api/memory/insights`:
|
|
172
|
+
设置页「记忆 / Memory」区块下方是一张**只读**看板,数据来自 `GET /api/memory/insights`:
|
|
155
173
|
|
|
156
174
|
| 展示 | 含义 |
|
|
157
175
|
|---|---|
|
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
|
|
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(
|
|
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
|