dsh-plugin-memory 0.10.1 → 0.11.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,22 @@
2
2
 
3
3
  所有记录跟随 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/) 风格;版本号与 `package.json` 保持一致。
4
4
 
5
+ ## [0.11.0] - 2026-10-30
6
+
7
+ ### Added(设置面板与侧栏 label 跟随语言:中英双语)
8
+
9
+ - **面板接 DSH 官方语言层**:客户端半 `exports.inject = ['slots', 'locale']`,`apply()` 里 `ctx.locale.register('memory', { zh, en })`,`settings.section` 注册项声明 `locale: 'memory'` → renderer 会注入 `t(key)` 座位,在「设置 → 通用设置 → 语言」切换时整块面板(表单 / 健康看板 / 图谱卡片)自动重渲染;不读 `navigator.language`、无需重启。共 **86 个翻译 key**,中英一一对齐(测试强制校验,且源码里不允许出现字典外的中文字面量)。
10
+ - **侧栏 label 跟随语言**:中文「记忆」/ 英文 "Memory",由纯函数 `sectionLabel(language)` 解析(`lib/settings-nav-icon.js` 与客户端内联副本各一份,测试校验两处一致);`claimNavIcon` 的认领键用同一个函数,语言切换后 MutationObserver 重新认领正确行,不会盖掉别人的图标。
11
+ - **健康看板可全英文**:`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 回退中文。
12
+ - **图谱与文字细节**:节点 tooltip 的「N 条关系」、类型图例/tooltip、统计行、孤立页提示、图例说明、`aria-label` 全部走语言包;`type` 按已知 8 类 + `unknown` 翻译,未知类型回退原值。图标规格不变(16×16 / stroke 1.3 / 纯黑 alpha)。
13
+
14
+ ### Tests
15
+
16
+ - 新增 `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 向后兼容。
17
+ - `test/settings-nav-icon.test.mjs` 改为动态 label:`sectionLabel('zh') === '记忆'` / `sectionLabel('en') === 'Memory'`、未知或缺失语言回退中文、两种语言互不认领对方的行。
18
+ - `test/insights.test.mjs` / `test/insights-route.test.mjs` 补新字段断言(`checks[].data`、`typeCounts` 与 `byType` 一致、中文 `label`/`detail` 原样保留),不削弱既有断言;`test/graph-card.test.mjs` 的 React stub 补 `createContext`/`useContext`。
19
+ - 全量 **198/198 通过**(0.10.1 基线 181,新增 17 条);`node scripts/memory.mjs --self-test` PASS;`npm pack --dry-run` 正常(文件清单不变)。
20
+
5
21
  ## [0.10.1] - 2026-10-30
6
22
 
7
23
  ### Changed(文档)
package/README.md CHANGED
@@ -127,8 +127,14 @@ Restart the profile (restart the DSH Desktop app) to take effect.
127
127
 
128
128
  ### Settings panel (hot edits)
129
129
 
130
+ 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
+
130
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.
131
133
 
134
+ ### Language
135
+
136
+ 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
+
132
138
  ### Boot budget allocation (why the index is not truncated first)
133
139
 
134
140
  `bootMaxChars` is a total budget, allocated per file rather than split evenly:
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` 同源。
@@ -65,7 +65,7 @@ dsh-plugin-memory(本插件)
65
65
  ├── lib/digest-guard.js # 防懒 digest 唤醒(空闲 + 记忆库久未写 → followup 提醒)
66
66
  ├── lib/recall-nudge.js # 主动追忆(空闲 → 第一人称提起一件真实往事,纯对话不写库)
67
67
  ├── lib/scaffold.js # 记忆库脚手架(模板只建不覆盖)
68
- ├── lib/client.js # 客户端半:设置面板「记忆 Memory」区块 + 记忆健康看板
68
+ ├── lib/client.js # 客户端半:设置面板「记忆 / Memory」区块(跟随语言)+ 记忆健康看板
69
69
  ├── skills/memory.md # 内嵌技能的操作协议正文
70
70
  └── scripts/memory.mjs # CLI:init/search/touch/lint/status/pack/unpack
71
71
 
@@ -135,7 +135,11 @@ dsh plugin --profile <profile> add dsh-plugin-memory
135
135
 
136
136
  ### 设置面板(热改)
137
137
 
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 配置层生效,改完需重启。
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 配置层生效,改完需重启。
139
+
140
+ ### 语言 / Language
141
+
142
+ 设置面板与侧栏 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
143
 
140
144
  ### boot 预算分配(为什么 index 不会先被截掉)
141
145
 
@@ -151,7 +155,7 @@ dsh plugin --profile <profile> add dsh-plugin-memory
151
155
 
152
156
  ### 记忆健康看板
153
157
 
154
- 设置页「记忆 Memory」区块下方是一张**只读**看板,数据来自 `GET /api/memory/insights`:
158
+ 设置页「记忆 / Memory」区块下方是一张**只读**看板,数据来自 `GET /api/memory/insights`:
155
159
 
156
160
  | 展示 | 含义 |
157
161
  |---|---|
package/lib/client.js CHANGED
@@ -1,10 +1,13 @@
1
1
  /**
2
2
  * dsh-plugin-memory 客户端半(零构建):
3
- * 在设置面板注册「记忆 Memory」区块 —— 总开关 + 记忆目录 + 两个子开关。
3
+ * 在设置面板注册「记忆 / Memory」区块 —— 总开关 + 记忆目录 + 两个子开关。
4
4
  *
5
5
  * 数据通道:settings wire 只服务硬编码白名单(memory 不在其中),
6
6
  * 因此本区块直连插件自建的 HTTP 路由(/api/memory/config):
7
7
  * GET 读配置、POST 部分更新,Host 校验并立即热应用。
8
+ *
9
+ * 文案走 DSH 官方语言层(ctx.locale + `memory` 命名空间,跟随设置 → 通用设置 →
10
+ * 语言):面板与侧栏 label 都随语言切换,不读 navigator.language,零依赖、零构建。
8
11
  */
9
12
  window.__ModuleLoader__.load({
10
13
  id: 'dsh-plugin-memory',
@@ -20,6 +23,303 @@ window.__ModuleLoader__.load({
20
23
  /** Poll while the panel is open, so memory edits show up without a reload. */
21
24
  const GRAPH_REFRESH_MS = 25000
22
25
 
26
+ /** Dictionary namespace owned by this plugin (registered via ctx.locale). */
27
+ const LOCALE_NS = 'memory'
28
+
29
+ /**
30
+ * Language packs; the active language comes from DSH settings
31
+ * (设置 → 通用设置 → 语言). Never guessed from navigator.language.
32
+ *
33
+ * Keys are shared verbatim between `zh` and `en` — a key must exist in both
34
+ * or in neither; `test/client-i18n.test.mjs` enforces the alignment.
35
+ * `{name}` placeholders are filled by {@link fill}, not by the `t` seat, so
36
+ * the panel renders correctly even if the host's `t` does no interpolation.
37
+ */
38
+ const DICTS = {
39
+ zh: {
40
+ sectionLabel: '记忆',
41
+ loading: '读取配置中…',
42
+ loadFailed: '记忆设置页加载失败:',
43
+ unknownError: '未知错误',
44
+ enabled: '启用记忆插件',
45
+ enabledHint: '总开关:关闭后不再注入记忆,也不注册 memory 技能',
46
+ memoryDir: '记忆目录',
47
+ memoryDirHint: '存放 SOUL/MEMORY/index/log 的路径,支持 ~ 开头;修改后立即切换,目录不存在时自动初始化',
48
+ dirPlaceholder: '~/.memory',
49
+ autoInject: '开机注入记忆',
50
+ autoInjectHint: '每次会话开始把记忆快照注入上下文',
51
+ deferUntilUserSpeaks: '提问后才注入',
52
+ deferUntilUserSpeaksHint: '开启后,新会话在你发出第一条消息前不会注入任何记忆 / 追忆 / digest 提醒',
53
+ activeSessionOnly: '仅当前激活会话注入',
54
+ activeSessionOnlyHint: '开启后,只有最近收到你消息的会话才会注入记忆(后台会话不打扰)',
55
+ registerSkill: '注册 memory 技能',
56
+ registerSkillHint: '让 agent 获得 remember / recall / consolidate / forget 操作协议',
57
+ recall: '主动追忆',
58
+ recallHint: '对话空闲时,以第一人称主动提起一件关于你的往事(拟人化),可随时关闭',
59
+ recallInterval: '追忆间隔(分钟)',
60
+ recallIntervalHint: '每次随机在最短 ~ 最长之间取一个间隔,避免固定节奏',
61
+ recallMaxPerSession: '每会话追忆次数',
62
+ recallMaxPerSessionHint: '一个会话内最多主动追忆几次,避免打扰',
63
+ minutesPlaceholder: '30',
64
+ maxMinutesPlaceholder: '240',
65
+ maxPerSessionPlaceholder: '3',
66
+ saveFailed: '保存失败:',
67
+ footerDisabled: '当前:已停用。修改即时生效。',
68
+ footerEnabled: '当前:记忆库位于 {dir}。修改即时生效。',
69
+ unconfigured: '(未配置)',
70
+ feedback: '🐛 反馈 / 提 issue',
71
+ insightsLoading: '正在统计记忆库…',
72
+ insightsTitle: '记忆健康',
73
+ scoreOutOf: ' / 100',
74
+ insightsSub: '只读统计:页数、访问新鲜度、体检结论与最近动态。',
75
+ metricPages: '记忆页',
76
+ metricIndexRoutes: 'index 路由',
77
+ metricChars: '记忆字数',
78
+ freshness: '访问新鲜度',
79
+ bucketToday: '今天',
80
+ bucketWeek: '≤7 天',
81
+ bucketMonth: '≤30 天',
82
+ bucketQuarter: '≤90 天',
83
+ bucketStale: '>90 天',
84
+ bucketNever: '从未',
85
+ checks: '体检',
86
+ checkIndex: 'index 链接完整',
87
+ checkOrphans: '无孤儿页',
88
+ checkFrontmatter: 'frontmatter 完整',
89
+ checkFreshness: '访问新鲜度',
90
+ checkIndexOk: '{routes} 条路由全部有效',
91
+ checkIndexFail: '{count} 条指向不存在的页',
92
+ checkOrphansOk: '每页都在 index 里',
93
+ checkOrphansFail: '{count} 页未收录:{list}{more}',
94
+ checkFrontmatterOk: 'title/type/salience 齐全',
95
+ checkFrontmatterFail: '缺 salience {salience} 页 / 缺 type {type} 页',
96
+ checkFreshnessOk: '没有超过 90 天未访问的页',
97
+ checkFreshnessFail: '{count} 页陈旧或从未戳记',
98
+ neverStamped: '从未戳记',
99
+ daysSinceAccess: '天未访问',
100
+ staleCandidates: '陈旧候选(前 {count})',
101
+ recent: '最近动态',
102
+ listSeparator: '、',
103
+ graphLoading: '正在构建记忆图谱…',
104
+ graphTitle: '记忆图谱',
105
+ graphResetView: '重置视图',
106
+ graphStats: '{pages} 页 · {links} 条页间互链 · {tagEdges} 条共享 tag',
107
+ graphIndexRoutes: '{count} 条索引路由(虚线)',
108
+ graphIsolated: '{count} 页暂时孤立',
109
+ graphUpdatedAt: '更新于 {time}',
110
+ graphRelations: '{count} 条关系',
111
+ graphNoLinks: '页面之间还没有互相引用——图谱目前只靠共享 tag 连接。写下「见 [某页](path)」会让关系变实。',
112
+ graphIsolatedHint: '这 {count} 页还没和别的记忆连上:{list}{more}',
113
+ graphMore: ' 等',
114
+ legendLinks: '━ 页间互链',
115
+ legendIndexRoutes: '┄ 索引路由',
116
+ graphHint: '细线=共享 tag。滚轮缩放 · 拖空白处平移 · 拖节点整理视图 · 悬停高亮关系;只读、实时。',
117
+ typeIdentity: '自我',
118
+ typeUser: '关于你',
119
+ typeUserPreference: '偏好',
120
+ typeProject: '项目',
121
+ typeSkill: '程序性',
122
+ typeDecision: '决策',
123
+ typeConcept: '概念',
124
+ typeFact: '事实',
125
+ typeUnknown: '未标注',
126
+ },
127
+ en: {
128
+ sectionLabel: 'Memory',
129
+ loading: 'Loading configuration…',
130
+ loadFailed: 'Failed to load memory settings: ',
131
+ unknownError: 'unknown error',
132
+ enabled: 'Enable memory plugin',
133
+ enabledHint: 'Master switch: when off, no memory is injected and the memory skill is not registered',
134
+ memoryDir: 'Memory directory',
135
+ memoryDirHint: 'Path holding SOUL/MEMORY/index/log; a leading ~ is expanded. Switching applies immediately and scaffolds a missing directory.',
136
+ dirPlaceholder: '~/.memory',
137
+ autoInject: 'Inject memory at session start',
138
+ autoInjectHint: 'Inject the memory snapshot into context when each session starts',
139
+ deferUntilUserSpeaks: 'Inject only after you speak',
140
+ deferUntilUserSpeaksHint: 'When on, a new session injects no memory / recall / digest reminder before your first message',
141
+ activeSessionOnly: 'Inject into the active session only',
142
+ activeSessionOnlyHint: 'When on, only the session that most recently received a message from you gets memory (background sessions are left alone)',
143
+ registerSkill: 'Register the memory skill',
144
+ registerSkillHint: 'Give the agent the remember / recall / consolidate / forget protocol',
145
+ recall: 'Proactive recall',
146
+ recallHint: 'When the conversation is idle, bring up a memory about you in first person (personified); can be turned off anytime',
147
+ recallInterval: 'Recall interval (minutes)',
148
+ recallIntervalHint: 'A random interval between min and max each time, so the rhythm never feels fixed',
149
+ recallMaxPerSession: 'Recalls per session',
150
+ recallMaxPerSessionHint: 'Maximum proactive recalls in one session, to stay unobtrusive',
151
+ minutesPlaceholder: '30',
152
+ maxMinutesPlaceholder: '240',
153
+ maxPerSessionPlaceholder: '3',
154
+ saveFailed: 'Save failed: ',
155
+ footerDisabled: 'Current: disabled. Changes apply immediately.',
156
+ footerEnabled: 'Current: memory store at {dir}. Changes apply immediately.',
157
+ unconfigured: '(not configured)',
158
+ feedback: '🐛 Feedback / open an issue',
159
+ insightsLoading: 'Counting the memory store…',
160
+ insightsTitle: 'Memory health',
161
+ scoreOutOf: ' / 100',
162
+ insightsSub: 'Read-only stats: page count, access freshness, health checks and recent activity.',
163
+ metricPages: 'memory pages',
164
+ metricIndexRoutes: 'index routes',
165
+ metricChars: 'memory chars',
166
+ freshness: 'Access freshness',
167
+ bucketToday: 'today',
168
+ bucketWeek: '≤7 days',
169
+ bucketMonth: '≤30 days',
170
+ bucketQuarter: '≤90 days',
171
+ bucketStale: '>90 days',
172
+ bucketNever: 'never',
173
+ checks: 'Health checks',
174
+ checkIndex: 'index links complete',
175
+ checkOrphans: 'no orphan pages',
176
+ checkFrontmatter: 'frontmatter complete',
177
+ checkFreshness: 'access freshness',
178
+ checkIndexOk: '{routes} routes all valid',
179
+ checkIndexFail: '{count} routes point at missing pages',
180
+ checkOrphansOk: 'every page is in the index',
181
+ checkOrphansFail: '{count} pages not in the index: {list}{more}',
182
+ checkFrontmatterOk: 'title/type/salience complete',
183
+ checkFrontmatterFail: 'missing salience on {salience} pages / missing type on {type} pages',
184
+ checkFreshnessOk: 'no page has gone unread for over 90 days',
185
+ checkFreshnessFail: '{count} pages are stale or never stamped',
186
+ neverStamped: 'never stamped',
187
+ daysSinceAccess: 'days since last access',
188
+ staleCandidates: 'Stale candidates (top {count})',
189
+ recent: 'Recent activity',
190
+ listSeparator: ', ',
191
+ graphLoading: 'Building the memory graph…',
192
+ graphTitle: 'Memory graph',
193
+ graphResetView: 'Reset view',
194
+ graphStats: '{pages} pages · {links} page links · {tagEdges} shared tags',
195
+ graphIndexRoutes: '{count} index routes (dashed)',
196
+ graphIsolated: '{count} pages isolated',
197
+ graphUpdatedAt: 'updated {time}',
198
+ graphRelations: '{count} relations',
199
+ graphNoLinks: 'Pages do not reference each other yet — the graph currently connects them only through shared tags. Writing "see [some page](path)" makes the relation real.',
200
+ graphIsolatedHint: 'These {count} pages are not connected to any other memory yet: {list}{more}',
201
+ graphMore: ' and more',
202
+ legendLinks: '━ page links',
203
+ legendIndexRoutes: '┄ index routes',
204
+ graphHint: 'Thin line = shared tag. Wheel to zoom · drag empty space to pan · drag a node to tidy the view · hover to highlight relations; read-only, live.',
205
+ typeIdentity: 'identity',
206
+ typeUser: 'about you',
207
+ typeUserPreference: 'preference',
208
+ typeProject: 'project',
209
+ typeSkill: 'procedural',
210
+ typeDecision: 'decision',
211
+ typeConcept: 'concept',
212
+ typeFact: 'fact',
213
+ typeUnknown: 'untagged',
214
+ },
215
+ }
216
+
217
+ /** Fill `{name}` placeholders in a translated template. */
218
+ function fill(template, params) {
219
+ let out = String(template)
220
+ for (const [name, value] of Object.entries(params ?? {})) {
221
+ out = out.split(`{${name}}`).join(String(value))
222
+ }
223
+ return out
224
+ }
225
+
226
+ /** Fallback translate for tests or a missing slot `t` seat (default Chinese). */
227
+ function fallbackT(key, params) {
228
+ const template = DICTS.zh[key] ?? key
229
+ return params === undefined ? template : fill(template, params)
230
+ }
231
+
232
+ /**
233
+ * The `t` seat travels by React context: MemorySection wraps the whole panel
234
+ * tree once, so every card/input reads the same translation function without
235
+ * drilling props through GraphCard → GraphView → renderNode.
236
+ */
237
+ const LocaleContext = React.createContext(fallbackT)
238
+
239
+ /** Translation for one component: a slot-injected `t` prop wins, context is the norm. */
240
+ function useT(props) {
241
+ const contextT = React.useContext(LocaleContext)
242
+ return typeof props?.t === 'function' ? props.t : contextT
243
+ }
244
+
245
+ /** Sidebar label in the requested language (zh `记忆` / en `Memory`). */
246
+ function sectionLabel(language) {
247
+ return DICTS[language === 'en' ? 'en' : 'zh'].sectionLabel
248
+ }
249
+
250
+ /** Freshness bucket label; unknown keys fall back to the server's own label. */
251
+ function bucketLabel(bucket, t) {
252
+ switch (bucket?.key) {
253
+ case 'today': return t('bucketToday')
254
+ case 'week': return t('bucketWeek')
255
+ case 'month': return t('bucketMonth')
256
+ case 'quarter': return t('bucketQuarter')
257
+ case 'stale': return t('bucketStale')
258
+ default: return bucket?.label ?? ''
259
+ }
260
+ }
261
+
262
+ /** Health-check title; unknown ids fall back to the server's own label. */
263
+ function checkLabel(check, t) {
264
+ switch (check?.id) {
265
+ case 'index': return t('checkIndex')
266
+ case 'orphans': return t('checkOrphans')
267
+ case 'frontmatter': return t('checkFrontmatter')
268
+ case 'freshness': return t('checkFreshness')
269
+ default: return check?.label ?? ''
270
+ }
271
+ }
272
+
273
+ /**
274
+ * Health-check detail rebuilt from the locale-neutral `data` the host sends
275
+ * (lib/insights.js). An older host payload without `data` keeps its Chinese
276
+ * `detail` verbatim — the panel never renders an empty sentence.
277
+ */
278
+ function checkDetail(check, t) {
279
+ const data = check?.data
280
+ if (data === undefined || data === null) return check?.detail ?? ''
281
+ switch (check?.id) {
282
+ case 'index':
283
+ return check.ok
284
+ ? fill(t('checkIndexOk'), { routes: data.routes })
285
+ : fill(t('checkIndexFail'), { count: data.missing })
286
+ case 'orphans':
287
+ return check.ok
288
+ ? t('checkOrphansOk')
289
+ : fill(t('checkOrphansFail'), {
290
+ count: data.count,
291
+ list: (data.sample ?? []).join(t('listSeparator')),
292
+ more: data.count > 3 ? '…' : '',
293
+ })
294
+ case 'frontmatter':
295
+ return check.ok
296
+ ? t('checkFrontmatterOk')
297
+ : fill(t('checkFrontmatterFail'), { salience: data.missingSalience, type: data.missingType })
298
+ case 'freshness':
299
+ return check.ok
300
+ ? t('checkFreshnessOk')
301
+ : fill(t('checkFreshnessFail'), { count: data.atRisk })
302
+ default:
303
+ return check?.detail ?? ''
304
+ }
305
+ }
306
+
307
+ /** Page-type label for the legend/tooltip; unknown types stay as the raw key. */
308
+ function typeLabel(type, t, fallback) {
309
+ switch (type) {
310
+ case 'identity': return t('typeIdentity')
311
+ case 'user': return t('typeUser')
312
+ case 'user-preference': return t('typeUserPreference')
313
+ case 'project': return t('typeProject')
314
+ case 'skill': return t('typeSkill')
315
+ case 'decision': return t('typeDecision')
316
+ case 'concept': return t('typeConcept')
317
+ case 'fact': return t('typeFact')
318
+ case 'unknown': return t('typeUnknown')
319
+ default: return fallback ?? type
320
+ }
321
+ }
322
+
23
323
  const rowStyle = {
24
324
  display: 'flex',
25
325
  alignItems: 'center',
@@ -75,8 +375,9 @@ window.__ModuleLoader__.load({
75
375
  }
76
376
 
77
377
  function ErrorText({ message }) {
378
+ const t = useT()
78
379
  return React.createElement('div', { style: { padding: '14px 16px', fontSize: '13px', lineHeight: '20px', color: 'var(--dsw-alias-state-error-primary, #e5484d)' } },
79
- '记忆设置页加载失败:', message)
380
+ t('loadFailed'), message)
80
381
  }
81
382
 
82
383
  /** 渲染期兜底:任何异常都以文案形式显示,绝不空白。 */
@@ -94,17 +395,20 @@ window.__ModuleLoader__.load({
94
395
  }
95
396
  }
96
397
 
97
- function MemorySection() {
398
+ function MemorySection(props) {
98
399
  // `gen` bumps after every successful config write so the read-only health
99
400
  // card re-mounts and re-reads the store (e.g. after a memoryDir switch).
100
401
  const [gen, setGen] = React.useState(0)
101
- return React.createElement(SectionBoundary, null,
102
- React.createElement(MemoryForm, { onSaved: () => setGen((value) => value + 1) }),
103
- React.createElement(SectionBoundary, { key: gen },
104
- React.createElement(InsightsCard),
105
- ),
106
- React.createElement(SectionBoundary, { key: `graph-${gen}` },
107
- React.createElement(GraphCard),
402
+ const t = useT(props)
403
+ return React.createElement(LocaleContext.Provider, { value: t },
404
+ React.createElement(SectionBoundary, null,
405
+ React.createElement(MemoryForm, { onSaved: () => setGen((value) => value + 1) }),
406
+ React.createElement(SectionBoundary, { key: gen },
407
+ React.createElement(InsightsCard),
408
+ ),
409
+ React.createElement(SectionBoundary, { key: `graph-${gen}` },
410
+ React.createElement(GraphCard),
411
+ ),
108
412
  ),
109
413
  )
110
414
  }
@@ -157,7 +461,8 @@ window.__ModuleLoader__.load({
157
461
  }
158
462
 
159
463
  /** 记忆健康看板:只读,数据来自 /api/memory/insights,打开面板时拉取一次。 */
160
- function InsightsCard() {
464
+ function InsightsCard(props) {
465
+ const t = useT(props)
161
466
  const [data, setData] = React.useState(undefined)
162
467
  const [status, setStatus] = React.useState('loading')
163
468
 
@@ -182,7 +487,7 @@ window.__ModuleLoader__.load({
182
487
  }, [])
183
488
 
184
489
  if (status === 'loading') {
185
- return React.createElement('div', { style: { ...cardStyle, fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #888)' } }, '正在统计记忆库…')
490
+ return React.createElement('div', { style: { ...cardStyle, fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #888)' } }, t('insightsLoading'))
186
491
  }
187
492
  // 看板是附加信息:拿不到就静默隐藏,绝不影响设置页可用。
188
493
  if (status === 'failed' || data === undefined) return null
@@ -193,59 +498,61 @@ window.__ModuleLoader__.load({
193
498
  const buckets = (data.freshness && data.freshness.buckets) || []
194
499
  const stale = data.stalePages ?? []
195
500
  const recent = data.recent ?? []
196
- const formatDays = (days) => (days === null || days === undefined ? '从未戳记' : `${days} 天未访问`)
501
+ const formatDays = (days) => (days === null || days === undefined
502
+ ? t('neverStamped')
503
+ : `${days} ${t('daysSinceAccess')}`)
197
504
 
198
505
  return React.createElement('div', { style: cardStyle },
199
506
  React.createElement('div', { style: { display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: '8px' } },
200
- React.createElement('div', { style: cardTitleStyle }, '记忆健康'),
507
+ React.createElement('div', { style: cardTitleStyle }, t('insightsTitle')),
201
508
  React.createElement('div', { style: { fontSize: '20px', lineHeight: '26px', fontWeight: '700', color: scoreColor(health.score) } },
202
509
  `${health.score}`,
203
- React.createElement('span', { style: { fontSize: '11px', fontWeight: '400', color: 'var(--dsw-alias-label-secondary, #999)' } }, ' / 100'),
510
+ React.createElement('span', { style: { fontSize: '11px', fontWeight: '400', color: 'var(--dsw-alias-label-secondary, #999)' } }, t('scoreOutOf')),
204
511
  ),
205
512
  ),
206
- React.createElement('div', { style: cardSubStyle }, '只读统计:页数、访问新鲜度、体检结论与最近动态。'),
513
+ React.createElement('div', { style: cardSubStyle }, t('insightsSub')),
207
514
 
208
515
  React.createElement('div', { style: metricRowStyle },
209
516
  React.createElement('div', { style: metricBoxStyle },
210
517
  React.createElement('div', { style: metricValueStyle }, String(pages)),
211
- React.createElement('div', { style: metricLabelStyle }, '记忆页'),
518
+ React.createElement('div', { style: metricLabelStyle }, t('metricPages')),
212
519
  ),
213
520
  React.createElement('div', { style: metricBoxStyle },
214
521
  React.createElement('div', { style: metricValueStyle }, String(overview.indexEntries ?? 0)),
215
- React.createElement('div', { style: metricLabelStyle }, 'index 路由'),
522
+ React.createElement('div', { style: metricLabelStyle }, t('metricIndexRoutes')),
216
523
  ),
217
524
  React.createElement('div', { style: metricBoxStyle },
218
525
  React.createElement('div', { style: metricValueStyle }, `~${overview.chars ?? 0}`),
219
- React.createElement('div', { style: metricLabelStyle }, '记忆字数'),
526
+ React.createElement('div', { style: metricLabelStyle }, t('metricChars')),
220
527
  ),
221
528
  ),
222
529
 
223
- React.createElement('div', { style: sectionLabelStyle }, '访问新鲜度'),
530
+ React.createElement('div', { style: sectionLabelStyle }, t('freshness')),
224
531
  ...buckets.map((bucket) =>
225
532
  React.createElement(Bar, {
226
533
  key: bucket.key,
227
- label: bucket.label,
534
+ label: bucketLabel(bucket, t),
228
535
  count: bucket.count,
229
536
  total: pages,
230
537
  color: barColor(bucket.key),
231
538
  })),
232
539
  (data.freshness && data.freshness.never > 0)
233
- ? React.createElement(Bar, { label: '从未', count: data.freshness.never, total: pages, color: 'var(--dsw-alias-label-secondary, #888)' })
540
+ ? React.createElement(Bar, { label: t('bucketNever'), count: data.freshness.never, total: pages, color: 'var(--dsw-alias-label-secondary, #888)' })
234
541
  : null,
235
542
 
236
- React.createElement('div', { style: sectionLabelStyle }, '体检'),
543
+ React.createElement('div', { style: sectionLabelStyle }, t('checks')),
237
544
  ...health.checks.map((check) =>
238
545
  React.createElement('div', { key: check.id, style: { display: 'flex', gap: '8px', alignItems: 'baseline', marginBottom: '4px' } },
239
546
  React.createElement('span', { style: { color: checkColor(check.ok), fontSize: '12px', width: '14px', flexShrink: 0 } }, check.ok ? '✓' : '!'),
240
547
  React.createElement('span', { style: { fontSize: '12px', lineHeight: '18px' } },
241
- check.label,
242
- React.createElement('span', { style: { color: 'var(--dsw-alias-label-secondary, #999)' } }, ` · ${check.detail}`),
548
+ checkLabel(check, t),
549
+ React.createElement('span', { style: { color: 'var(--dsw-alias-label-secondary, #999)' } }, ` · ${checkDetail(check, t)}`),
243
550
  ),
244
551
  )),
245
552
 
246
553
  stale.length > 0
247
554
  ? React.createElement('div', null,
248
- React.createElement('div', { style: sectionLabelStyle }, `陈旧候选(前 ${stale.length})`),
555
+ React.createElement('div', { style: sectionLabelStyle }, fill(t('staleCandidates'), { count: stale.length })),
249
556
  ...stale.map((page) =>
250
557
  React.createElement('div', { key: page.path, style: { fontSize: '12px', lineHeight: '18px', display: 'flex', justifyContent: 'space-between', gap: '8px', marginBottom: '3px' } },
251
558
  React.createElement('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, page.title || page.path),
@@ -256,7 +563,7 @@ window.__ModuleLoader__.load({
256
563
 
257
564
  recent.length > 0
258
565
  ? React.createElement('div', null,
259
- React.createElement('div', { style: sectionLabelStyle }, '最近动态'),
566
+ React.createElement('div', { style: sectionLabelStyle }, t('recent')),
260
567
  ...recent.map((line, index) =>
261
568
  React.createElement('div', {
262
569
  key: `${index}-${line}`,
@@ -269,6 +576,7 @@ window.__ModuleLoader__.load({
269
576
 
270
577
  /** 目录输入:草稿态编辑,blur / Enter 才写回,避免每次按键触发 Host 重排。 */
271
578
  function DirInput({ value, disabled, onCommit }) {
579
+ const t = useT()
272
580
  const [draft, setDraft] = React.useState(undefined)
273
581
  const shown = draft !== undefined ? draft : (value ?? '')
274
582
  const commit = () => {
@@ -279,7 +587,7 @@ window.__ModuleLoader__.load({
279
587
  }
280
588
  return React.createElement('input', {
281
589
  type: 'text',
282
- placeholder: '~/.memory',
590
+ placeholder: t('dirPlaceholder'),
283
591
  disabled,
284
592
  value: shown,
285
593
  onChange: (event) => setDraft(event.target.value),
@@ -317,7 +625,9 @@ window.__ModuleLoader__.load({
317
625
  })
318
626
  }
319
627
 
320
- function MemoryForm({ onSaved }) {
628
+ function MemoryForm(props) {
629
+ const t = useT(props)
630
+ const { onSaved } = props
321
631
  const [config, setConfig] = React.useState(undefined)
322
632
  const [status, setStatus] = React.useState('loading')
323
633
  const [error, setError] = React.useState(undefined)
@@ -366,9 +676,9 @@ window.__ModuleLoader__.load({
366
676
  }
367
677
 
368
678
  if (status === 'loading') {
369
- return React.createElement('div', { style: { padding: '14px 16px', fontSize: '13px', color: 'var(--dsw-alias-label-secondary, #888)' } }, '读取配置中…')
679
+ return React.createElement('div', { style: { padding: '14px 16px', fontSize: '13px', color: 'var(--dsw-alias-label-secondary, #888)' } }, t('loading'))
370
680
  }
371
- if (status === 'failed') return React.createElement(ErrorText, { message: error ?? 'unknown' })
681
+ if (status === 'failed') return React.createElement(ErrorText, { message: error ?? t('unknownError') })
372
682
 
373
683
  const value = config ?? {}
374
684
  const disabled = saving
@@ -376,8 +686,8 @@ window.__ModuleLoader__.load({
376
686
  return React.createElement('div', { style: { padding: '8px 0' } },
377
687
  React.createElement('div', { style: rowStyle },
378
688
  React.createElement('div', null,
379
- React.createElement('div', { style: labelStyle }, '启用记忆插件'),
380
- React.createElement('div', { style: subStyle }, '总开关:关闭后不再注入记忆,也不注册 memory 技能'),
689
+ React.createElement('div', { style: labelStyle }, t('enabled')),
690
+ React.createElement('div', { style: subStyle }, t('enabledHint')),
381
691
  ),
382
692
  React.createElement(Toggle, {
383
693
  checked: value.enabled !== false,
@@ -387,8 +697,8 @@ window.__ModuleLoader__.load({
387
697
  ),
388
698
  React.createElement('div', { style: rowStyle },
389
699
  React.createElement('div', null,
390
- React.createElement('div', { style: labelStyle }, '记忆目录'),
391
- React.createElement('div', { style: subStyle }, '存放 SOUL/MEMORY/index/log 的路径,支持 ~ 开头;修改后立即切换,目录不存在时自动初始化'),
700
+ React.createElement('div', { style: labelStyle }, t('memoryDir')),
701
+ React.createElement('div', { style: subStyle }, t('memoryDirHint')),
392
702
  ),
393
703
  React.createElement(DirInput, {
394
704
  value: value.memoryDir,
@@ -398,8 +708,8 @@ window.__ModuleLoader__.load({
398
708
  ),
399
709
  React.createElement('div', { style: rowStyle },
400
710
  React.createElement('div', null,
401
- React.createElement('div', { style: labelStyle }, '开机注入记忆'),
402
- React.createElement('div', { style: subStyle }, '每次会话开始把记忆快照注入上下文'),
711
+ React.createElement('div', { style: labelStyle }, t('autoInject')),
712
+ React.createElement('div', { style: subStyle }, t('autoInjectHint')),
403
713
  ),
404
714
  React.createElement(Toggle, {
405
715
  checked: value.autoInject !== false,
@@ -409,8 +719,8 @@ window.__ModuleLoader__.load({
409
719
  ),
410
720
  React.createElement('div', { style: rowStyle },
411
721
  React.createElement('div', null,
412
- React.createElement('div', { style: labelStyle }, '提问后才注入'),
413
- React.createElement('div', { style: subStyle }, '开启后,新会话在你发出第一条消息前不会注入任何记忆 / 追忆 / digest 提醒'),
722
+ React.createElement('div', { style: labelStyle }, t('deferUntilUserSpeaks')),
723
+ React.createElement('div', { style: subStyle }, t('deferUntilUserSpeaksHint')),
414
724
  ),
415
725
  React.createElement(Toggle, {
416
726
  checked: value.deferUntilUserSpeaks !== false,
@@ -420,8 +730,8 @@ window.__ModuleLoader__.load({
420
730
  ),
421
731
  React.createElement('div', { style: rowStyle },
422
732
  React.createElement('div', null,
423
- React.createElement('div', { style: labelStyle }, '仅当前激活会话注入'),
424
- React.createElement('div', { style: subStyle }, '开启后,只有最近收到你消息的会话才会注入记忆(后台会话不打扰)'),
733
+ React.createElement('div', { style: labelStyle }, t('activeSessionOnly')),
734
+ React.createElement('div', { style: subStyle }, t('activeSessionOnlyHint')),
425
735
  ),
426
736
  React.createElement(Toggle, {
427
737
  checked: value.activeSessionOnly !== false,
@@ -431,8 +741,8 @@ window.__ModuleLoader__.load({
431
741
  ),
432
742
  React.createElement('div', { style: rowStyle },
433
743
  React.createElement('div', null,
434
- React.createElement('div', { style: labelStyle }, '注册 memory 技能'),
435
- React.createElement('div', { style: subStyle }, '让 agent 获得 remember / recall / consolidate / forget 操作协议'),
744
+ React.createElement('div', { style: labelStyle }, t('registerSkill')),
745
+ React.createElement('div', { style: subStyle }, t('registerSkillHint')),
436
746
  ),
437
747
  React.createElement(Toggle, {
438
748
  checked: value.registerSkill !== false,
@@ -442,8 +752,8 @@ window.__ModuleLoader__.load({
442
752
  ),
443
753
  React.createElement('div', { style: rowStyle },
444
754
  React.createElement('div', null,
445
- React.createElement('div', { style: labelStyle }, '主动追忆'),
446
- React.createElement('div', { style: subStyle }, '对话空闲时,以第一人称主动提起一件关于你的往事(拟人化),可随时关闭'),
755
+ React.createElement('div', { style: labelStyle }, t('recall')),
756
+ React.createElement('div', { style: subStyle }, t('recallHint')),
447
757
  ),
448
758
  React.createElement(Toggle, {
449
759
  checked: value.recallEnabled !== false,
@@ -453,40 +763,42 @@ window.__ModuleLoader__.load({
453
763
  ),
454
764
  React.createElement('div', { style: rowStyle },
455
765
  React.createElement('div', null,
456
- React.createElement('div', { style: labelStyle }, '追忆间隔(分钟)'),
457
- React.createElement('div', { style: subStyle }, '每次随机在最短 ~ 最长之间取一个间隔,避免固定节奏'),
766
+ React.createElement('div', { style: labelStyle }, t('recallInterval')),
767
+ React.createElement('div', { style: subStyle }, t('recallIntervalHint')),
458
768
  ),
459
769
  React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: '8px' } },
460
770
  React.createElement(NumberInput, {
461
771
  value: value.recallIntervalMinMinutes,
462
772
  disabled,
463
- placeholder: '30',
773
+ placeholder: t('minutesPlaceholder'),
464
774
  onCommit: (next) => apply({ recallIntervalMinMinutes: next }),
465
775
  }),
466
776
  React.createElement('span', { style: { color: 'var(--dsw-alias-label-secondary, #999)' } }, '~'),
467
777
  React.createElement(NumberInput, {
468
778
  value: value.recallIntervalMaxMinutes,
469
779
  disabled,
470
- placeholder: '240',
780
+ placeholder: t('maxMinutesPlaceholder'),
471
781
  onCommit: (next) => apply({ recallIntervalMaxMinutes: next }),
472
782
  }),
473
783
  ),
474
784
  ),
475
785
  React.createElement('div', { style: rowStyle },
476
786
  React.createElement('div', null,
477
- React.createElement('div', { style: labelStyle }, '每会话追忆次数'),
478
- React.createElement('div', { style: subStyle }, '一个会话内最多主动追忆几次,避免打扰'),
787
+ React.createElement('div', { style: labelStyle }, t('recallMaxPerSession')),
788
+ React.createElement('div', { style: subStyle }, t('recallMaxPerSessionHint')),
479
789
  ),
480
790
  React.createElement(NumberInput, {
481
791
  value: value.recallMaxPerSession,
482
792
  disabled,
483
- placeholder: '3',
793
+ placeholder: t('maxPerSessionPlaceholder'),
484
794
  onCommit: (next) => apply({ recallMaxPerSession: next }),
485
795
  }),
486
796
  ),
487
- error !== undefined ? React.createElement('div', { style: errorStyle }, '保存失败:', error) : null,
797
+ error !== undefined ? React.createElement('div', { style: errorStyle }, t('saveFailed'), error) : null,
488
798
  React.createElement('div', { style: { padding: '14px 16px', fontSize: '12px', lineHeight: '18px', color: 'var(--dsw-alias-label-secondary, #888)' } },
489
- `当前:${value.enabled === false ? '已停用' : `记忆库位于 ${value.memoryDir ?? '(未配置)'}`}。修改即时生效。`,
799
+ value.enabled === false
800
+ ? t('footerDisabled')
801
+ : fill(t('footerEnabled'), { dir: value.memoryDir ?? t('unconfigured') }),
490
802
  ),
491
803
  // 反馈入口:做成按钮而不是小字链接,方便一眼看到。
492
804
  // 外部 HTTPS 在 DSH Desktop 里由系统浏览器打开(不带内嵌会话或 token)。
@@ -509,7 +821,7 @@ window.__ModuleLoader__.load({
509
821
  color: 'var(--dsw-alias-label-primary, #18181b)',
510
822
  textDecoration: 'none',
511
823
  },
512
- }, '🐛 反馈 / 提 issue'),
824
+ }, t('feedback')),
513
825
  ),
514
826
  )
515
827
  }
@@ -615,7 +927,9 @@ window.__ModuleLoader__.load({
615
927
  * 图谱视图:拿到 nodes/edges 就画(纯渲染,无副作用)。拖动与悬停是它
616
928
  * 自己维护的临时状态;`memo` 隔断父级重渲染带来的 hooks 调用。
617
929
  */
618
- const GraphView = React.memo(function GraphView({ graph, fetchedAt }) {
930
+ const GraphView = React.memo(function GraphView(props) {
931
+ const { graph, fetchedAt } = props
932
+ const t = useT(props)
619
933
  const [hover, setHover] = React.useState(undefined)
620
934
  const [dragPositions, setDragPositions] = React.useState(undefined)
621
935
  const [dragging, setDragging] = React.useState(false)
@@ -782,10 +1096,10 @@ window.__ModuleLoader__.load({
782
1096
  const p = posOf(node)
783
1097
  const dx = p.x - node.x
784
1098
  const dy = p.y - node.y
785
- const tip = `${node.label}\n${node.type}`
1099
+ const tip = `${node.label}\n${typeLabel(node.type, t)}`
786
1100
  + `${node.salience ? ` · salience:${node.salience}` : ''}`
787
1101
  + `${node.tags && node.tags.length > 0 ? `\n#${node.tags.join(' #')}` : ''}`
788
- + `\n${node.degree ?? 0} 条关系`
1102
+ + `\n${fill(t('graphRelations'), { count: node.degree ?? 0 })}`
789
1103
  const showLabel = node.hub || (node.degree ?? 0) >= 2
790
1104
  const label = String(node.label).length > 16 ? `${String(node.label).slice(0, 15)}…` : String(node.label)
791
1105
  return React.createElement('g', {
@@ -836,7 +1150,7 @@ window.__ModuleLoader__.load({
836
1150
  cursor: zoomed ? 'grab' : 'default',
837
1151
  },
838
1152
  role: 'img',
839
- 'aria-label': '记忆图谱',
1153
+ 'aria-label': t('graphTitle'),
840
1154
  onPointerDown: panStart,
841
1155
  onPointerMove: panMove,
842
1156
  onPointerUp: panEnd,
@@ -872,13 +1186,13 @@ window.__ModuleLoader__.load({
872
1186
  style: { display: 'inline-flex', alignItems: 'center', gap: '4px', fontSize: '11px', color: 'var(--dsw-alias-label-secondary, #999)', marginRight: '10px' },
873
1187
  },
874
1188
  React.createElement('span', { style: { width: '7px', height: '7px', borderRadius: '4px', background: colourOf(type), display: 'inline-block' } }),
875
- type,
1189
+ typeLabel(type, t),
876
1190
  ))
877
1191
 
878
1192
  const isolated = stats.isolated ?? []
879
1193
  return React.createElement('div', { style: cardStyle },
880
1194
  React.createElement('div', { style: { display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: '8px' } },
881
- React.createElement('div', { style: cardTitleStyle }, '记忆图谱'),
1195
+ React.createElement('div', { style: cardTitleStyle }, t('graphTitle')),
882
1196
  zoomed
883
1197
  ? React.createElement('button', {
884
1198
  type: 'button',
@@ -892,36 +1206,41 @@ window.__ModuleLoader__.load({
892
1206
  background: 'transparent',
893
1207
  color: 'var(--dsw-alias-label-secondary, #999)',
894
1208
  },
895
- }, '重置视图')
1209
+ }, t('graphResetView'))
896
1210
  : null,
897
1211
  ),
898
1212
  React.createElement('div', { style: cardSubStyle },
899
- `${stats.pages ?? nodes.length} 页 · ${stats.links ?? 0} 条页间互链 · ${stats.tagEdges ?? 0} 条共享 tag`
900
- + `${stats.indexLinks ? ` · ${stats.indexLinks} 条索引路由(虚线)` : ''}`
901
- + `${isolated.length > 0 ? ` · ${isolated.length} 页暂时孤立` : ''}`
902
- + `${fetchedAt instanceof Date ? ` · 更新于 ${fetchedAt.toLocaleTimeString()}` : ''}`,
1213
+ fill(t('graphStats'), { pages: stats.pages ?? nodes.length, links: stats.links ?? 0, tagEdges: stats.tagEdges ?? 0 })
1214
+ + (stats.indexLinks ? ` · ${fill(t('graphIndexRoutes'), { count: stats.indexLinks })}` : '')
1215
+ + (isolated.length > 0 ? ` · ${fill(t('graphIsolated'), { count: isolated.length })}` : '')
1216
+ + (fetchedAt instanceof Date ? ` · ${fill(t('graphUpdatedAt'), { time: fetchedAt.toLocaleTimeString() })}` : ''),
903
1217
  ),
904
1218
  svg,
905
1219
  React.createElement('div', { style: { marginTop: '8px' } }, ...chips),
906
1220
  ((stats.links ?? 0) === 0 || isolated.length > 0)
907
1221
  ? React.createElement('div', { style: { fontSize: '11px', lineHeight: '17px', color: 'var(--dsw-alias-label-secondary, #888)', marginTop: '6px' } },
908
1222
  (stats.links ?? 0) === 0
909
- ? '页面之间还没有互相引用——图谱目前只靠共享 tag 连接。写下"见 [某页](path)"会让关系变实。'
910
- : `这 ${isolated.length} 页还没和别的记忆连上:${isolated.slice(0, 3).map((id) => id.replace(/\.md$/, '')).join('、')}${isolated.length > 3 ? ' 等' : ''}`,
1223
+ ? t('graphNoLinks')
1224
+ : fill(t('graphIsolatedHint'), {
1225
+ count: isolated.length,
1226
+ list: isolated.slice(0, 3).map((id) => id.replace(/\.md$/, '')).join(t('listSeparator')),
1227
+ more: isolated.length > 3 ? t('graphMore') : '',
1228
+ }),
911
1229
  )
912
1230
  : null,
913
1231
  React.createElement('div', { style: { fontSize: '11px', lineHeight: '17px', color: 'var(--dsw-alias-label-secondary, #888)', marginTop: '6px' } },
914
- React.createElement('span', { style: { color: 'var(--dsw-alias-brand-primary, #4c8bf5)' } }, '━ 页间互链'),
1232
+ React.createElement('span', { style: { color: 'var(--dsw-alias-brand-primary, #4c8bf5)' } }, t('legendLinks')),
915
1233
  ' · ',
916
- React.createElement('span', { style: { color: '#8b8f96' } }, '┄ 索引路由'),
1234
+ React.createElement('span', { style: { color: '#8b8f96' } }, t('legendIndexRoutes')),
917
1235
  ' · ',
918
- '细线=共享 tag。滚轮缩放 · 拖空白处平移 · 拖节点整理视图 · 悬停高亮关系;只读、实时。',
1236
+ t('graphHint'),
919
1237
  ),
920
1238
  )
921
1239
  })
922
1240
 
923
1241
  /** 记忆图谱卡片:负责取数(含轮询)与生命周期,渲染交给 GraphView。 */
924
- function GraphCard() {
1242
+ function GraphCard(props) {
1243
+ const t = useT(props)
925
1244
  const [graph, setGraph] = React.useState(undefined)
926
1245
  const [status, setStatus] = React.useState('loading')
927
1246
  const [fetchedAt, setFetchedAt] = React.useState(undefined)
@@ -955,7 +1274,7 @@ window.__ModuleLoader__.load({
955
1274
  }, [])
956
1275
 
957
1276
  if (status === 'loading') {
958
- return React.createElement('div', { style: { ...cardStyle, fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #888)' } }, '正在构建记忆图谱…')
1277
+ return React.createElement('div', { style: { ...cardStyle, fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #888)' } }, t('graphLoading'))
959
1278
  }
960
1279
  if (status === 'failed' || graph === undefined) return null
961
1280
  return React.createElement(GraphView, { graph, fetchedAt })
@@ -973,7 +1292,8 @@ window.__ModuleLoader__.load({
973
1292
  // 官方哪天给 settings.section 长出 icon 字段,这段即可删除。
974
1293
  const NAV_ROW_SELECTOR = '[role="dialog"] nav button'
975
1294
  const NAV_ICON_ATTR = 'data-dsh-memory-nav-icon'
976
- const MEMORY_SECTION_LABEL = 'Memory'
1295
+ // The label is resolved from DICTS by `sectionLabel(language)`: it is both the
1296
+ // displayed text and the claim key, so both must come from that one function.
977
1297
  const MEMORY_FEEDBACK_URL = 'https://github.com/LittleBlackTong/dsh-plugin-memory/issues/new'
978
1298
  const ICON_MEDIUM_STROKE = 1.3
979
1299
  const BRAIN_CIRCUIT_PATHS = [
@@ -1037,24 +1357,54 @@ window.__ModuleLoader__.load({
1037
1357
  }
1038
1358
 
1039
1359
  function apply(ctx) {
1360
+ // Language packs ride DSH's own locale layer: the panel follows
1361
+ // 设置 → 通用设置 → 语言 instead of guessing from navigator.language.
1362
+ ctx.effect(() => ctx.locale.register(LOCALE_NS, DICTS), 'memory: dictionaries')
1363
+ /** Sidebar label in the active language (zh `记忆` / en `Memory`). */
1364
+ const labelOf = () => {
1365
+ let active = 'zh'
1366
+ try {
1367
+ active = ctx.locale.getSnapshot().active === 'en' ? 'en' : 'zh'
1368
+ } catch {
1369
+ active = 'zh'
1370
+ }
1371
+ return sectionLabel(active)
1372
+ }
1040
1373
  ctx.slots.inject('settings.section', () => ctx.slots.register({
1041
1374
  name: 'settings.section',
1042
1375
  id: 'memory',
1043
1376
  order: 100,
1044
- label: () => MEMORY_SECTION_LABEL,
1377
+ locale: LOCALE_NS,
1378
+ label: labelOf,
1045
1379
  }, MemorySection))
1046
- // 官方 settings.section 没有 icon 字段,侧栏标记只能靠自己认领。
1047
- ctx.effect(() => claimNavIcon(() => MEMORY_SECTION_LABEL), 'memory: settings nav icon')
1380
+ // 官方 settings.section 没有 icon 字段,侧栏标记只能靠自己认领;
1381
+ // 认领键就是当前语言的 label(语言切换后 MutationObserver 会重新对齐)。
1382
+ ctx.effect(() => claimNavIcon(labelOf), 'memory: settings nav icon')
1048
1383
  }
1049
1384
 
1050
1385
  exports.apply = apply
1051
- exports.inject = ['slots']
1386
+ exports.inject = ['slots', 'locale']
1052
1387
  // Test seam: the browser half cannot be imported by Node, so the pure
1053
1388
  // helpers and the component itself are exposed for a vm-based harness.
1054
1389
  // Underscore-prefixed and additive: the host only reads `apply`/`inject`.
1055
1390
  exports.__test = {
1391
+ MemorySection,
1392
+ MemoryForm,
1393
+ InsightsCard,
1056
1394
  GraphCard,
1057
1395
  GraphView,
1396
+ DICTS,
1397
+ LOCALE_NS,
1398
+ fallbackT,
1399
+ fill,
1400
+ sectionLabel,
1401
+ bucketLabel,
1402
+ checkLabel,
1403
+ checkDetail,
1404
+ typeLabel,
1405
+ useT,
1406
+ isOwnNavRow,
1407
+ claimNavIcon,
1058
1408
  applyDrag,
1059
1409
  releasePositions,
1060
1410
  clampToBox,
package/lib/insights.js CHANGED
@@ -158,18 +158,24 @@ export function collectInsights(memoryDir) {
158
158
  const staleCount = pages.filter((p) => p.daysSinceAccess !== undefined && p.daysSinceAccess > 90).length
159
159
 
160
160
  const atRisk = staleCount + never
161
+ // `label` / `detail` stay the Chinese strings the CLI and older clients read.
162
+ // `data` is an additive, locale-neutral copy of the same numbers so a client
163
+ // can render the sentence in its own language (see lib/client.js). Never drop
164
+ // the string fields: `dsh-memory checkup` and pre-0.11 panels depend on them.
161
165
  const checks = [
162
166
  {
163
167
  id: 'index',
164
168
  ok: missingLink.length === 0,
165
169
  label: 'index 链接完整',
166
170
  detail: missingLink.length === 0 ? `${indexEntries.length} 条路由全部有效` : `${missingLink.length} 条指向不存在的页`,
171
+ data: { routes: indexEntries.length, missing: missingLink.length },
167
172
  },
168
173
  {
169
174
  id: 'orphans',
170
175
  ok: orphans.length === 0,
171
176
  label: '无孤儿页',
172
177
  detail: orphans.length === 0 ? '每页都在 index 里' : `${orphans.length} 页未收录:${orphans.slice(0, 3).join('、')}${orphans.length > 3 ? '…' : ''}`,
178
+ data: { count: orphans.length, sample: orphans.slice(0, 3) },
173
179
  },
174
180
  {
175
181
  id: 'frontmatter',
@@ -178,12 +184,14 @@ export function collectInsights(memoryDir) {
178
184
  detail: missingSalience === 0 && missingType === 0
179
185
  ? 'title/type/salience 齐全'
180
186
  : `缺 salience ${missingSalience} 页 / 缺 type ${missingType} 页`,
187
+ data: { missingSalience, missingType },
181
188
  },
182
189
  {
183
190
  id: 'freshness',
184
191
  ok: atRisk === 0,
185
192
  label: '访问新鲜度',
186
193
  detail: atRisk === 0 ? '没有超过 90 天未访问的页' : `${atRisk} 页陈旧或从未戳记`,
194
+ data: { atRisk },
187
195
  },
188
196
  ]
189
197
 
@@ -217,6 +225,11 @@ export function collectInsights(memoryDir) {
217
225
  })()
218
226
  const newest = pages.reduce((max, p) => Math.max(max, p.mtimeMs), 0)
219
227
  const recent = readRecentLog(memoryDir, 5)
228
+ // Type distribution, locale-neutral: `type` is the machine key a client
229
+ // translates, `label` stays the Chinese display string for CLI consumers.
230
+ const typeCounts = [...byType.entries()]
231
+ .map(([type, count]) => ({ type, label: TYPE_LABELS[type] ?? type, count }))
232
+ .sort((a, b) => b.count - a.count)
220
233
 
221
234
  return {
222
235
  generatedAt: new Date().toISOString(),
@@ -234,9 +247,10 @@ export function collectInsights(memoryDir) {
234
247
  lastWrite: newest > 0 ? new Date(newest).toISOString() : null,
235
248
  neverAccessed: never,
236
249
  },
237
- byType: [...byType.entries()]
238
- .map(([type, count]) => ({ type, label: TYPE_LABELS[type] ?? type, count }))
239
- .sort((a, b) => b.count - a.count),
250
+ byType: typeCounts.map((row) => ({ ...row })),
251
+ // Additive alias of `byType` (same rows, same order), documented so a
252
+ // locale-aware client can read `typeCounts` without guessing field names.
253
+ typeCounts,
240
254
  pages: pages.map((p) => ({
241
255
  path: p.path,
242
256
  title: p.title,
@@ -22,12 +22,25 @@ export const NAV_ROW_SELECTOR = '[role="dialog"] nav button'
22
22
  export const NAV_ICON_ATTR = 'data-dsh-memory-nav-icon'
23
23
 
24
24
  /**
25
- * 本区块的 label。
25
+ * 本区块的 label(按 DSH 语言解析)。
26
26
  *
27
- * 它同时是**显示文案**和**认领时的匹配键**——两者必须是同一个字符串,
28
- * 否则语言切换后行与标记会对不上。
27
+ * 中文「记忆」/ 英文 `Memory`。它同时是**显示文案**和**认领时的匹配键**——
28
+ * 两者必须来自同一个解析函数,否则语言切换后行与标记会对不上。
29
29
  */
30
- export const MEMORY_SECTION_LABEL = 'Memory'
30
+ export const MEMORY_SECTION_LABELS = Object.freeze({ zh: '记忆', en: 'Memory' })
31
+
32
+ /**
33
+ * 取本区块在指定语言下的 label。
34
+ *
35
+ * 纯函数:未知 / 缺失语言回退中文(DSH 的默认语言)。设置侧栏标记与测试共用
36
+ * 这一个函数,保证显示文案与认领键永远一致。
37
+ *
38
+ * @param {string | null | undefined} language `ctx.locale.getSnapshot().active`。
39
+ * @returns {string} 该语言下的区块 label。
40
+ */
41
+ export function sectionLabel(language) {
42
+ return MEMORY_SECTION_LABELS[language === 'en' ? 'en' : 'zh']
43
+ }
31
44
 
32
45
  /**
33
46
  * 标记的绘图元素:一个闭合的大脑半球轮廓 + 三条从脑缘引出的线 + 五个节点
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.10.1",
4
+ "version": "0.11.0",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "lib/index.js",