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/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,321 @@ 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
+ toneGuide: '语气引导',
64
+ toneGuideHint: '按语境微调说话方式(赶工、深夜、坏消息、里程碑),不改变事实、不越 SOUL 边界',
65
+ toneIntensity: '语气强度',
66
+ toneIntensityHint: 'low 仅调味 / medium 更明显 / off 纯工程口吻;任何档位都以事实优先',
67
+ toneLow: 'low(仅调味)',
68
+ toneMedium: 'medium(更明显)',
69
+ toneOff: 'off(纯工程口吻)',
70
+ growthRecap: '每周成长回顾',
71
+ growthRecapHint: '每周在追忆通道里说一次「这周我记住了什么」(第一人称,最多五句,可随时关闭)',
72
+ minutesPlaceholder: '30',
73
+ maxMinutesPlaceholder: '240',
74
+ maxPerSessionPlaceholder: '3',
75
+ saveFailed: '保存失败:',
76
+ footerDisabled: '当前:已停用。修改即时生效。',
77
+ footerEnabled: '当前:记忆库位于 {dir}。修改即时生效。',
78
+ unconfigured: '(未配置)',
79
+ feedback: '🐛 反馈 / 提 issue',
80
+ insightsLoading: '正在统计记忆库…',
81
+ insightsTitle: '记忆健康',
82
+ scoreOutOf: ' / 100',
83
+ insightsSub: '只读统计:页数、访问新鲜度、体检结论与最近动态。',
84
+ metricPages: '记忆页',
85
+ metricIndexRoutes: 'index 路由',
86
+ metricChars: '记忆字数',
87
+ freshness: '访问新鲜度',
88
+ bucketToday: '今天',
89
+ bucketWeek: '≤7 天',
90
+ bucketMonth: '≤30 天',
91
+ bucketQuarter: '≤90 天',
92
+ bucketStale: '>90 天',
93
+ bucketNever: '从未',
94
+ checks: '体检',
95
+ checkIndex: 'index 链接完整',
96
+ checkOrphans: '无孤儿页',
97
+ checkFrontmatter: 'frontmatter 完整',
98
+ checkFreshness: '访问新鲜度',
99
+ checkIndexOk: '{routes} 条路由全部有效',
100
+ checkIndexFail: '{count} 条指向不存在的页',
101
+ checkOrphansOk: '每页都在 index 里',
102
+ checkOrphansFail: '{count} 页未收录:{list}{more}',
103
+ checkFrontmatterOk: 'title/type/salience 齐全',
104
+ checkFrontmatterFail: '缺 salience {salience} 页 / 缺 type {type} 页',
105
+ checkFreshnessOk: '没有超过 90 天未访问的页',
106
+ checkFreshnessFail: '{count} 页陈旧或从未戳记',
107
+ neverStamped: '从未戳记',
108
+ daysSinceAccess: '天未访问',
109
+ staleCandidates: '陈旧候选(前 {count})',
110
+ recent: '最近动态',
111
+ listSeparator: '、',
112
+ graphLoading: '正在构建记忆图谱…',
113
+ graphTitle: '记忆图谱',
114
+ graphResetView: '重置视图',
115
+ graphStats: '{pages} 页 · {links} 条页间互链 · {tagEdges} 条共享 tag',
116
+ graphIndexRoutes: '{count} 条索引路由(虚线)',
117
+ graphIsolated: '{count} 页暂时孤立',
118
+ graphUpdatedAt: '更新于 {time}',
119
+ graphRelations: '{count} 条关系',
120
+ graphNoLinks: '页面之间还没有互相引用——图谱目前只靠共享 tag 连接。写下「见 [某页](path)」会让关系变实。',
121
+ graphIsolatedHint: '这 {count} 页还没和别的记忆连上:{list}{more}',
122
+ graphMore: ' 等',
123
+ legendLinks: '━ 页间互链',
124
+ legendIndexRoutes: '┄ 索引路由',
125
+ graphHint: '细线=共享 tag。滚轮缩放 · 拖空白处平移 · 拖节点整理视图 · 悬停高亮关系;只读、实时。',
126
+ typeIdentity: '自我',
127
+ typeUser: '关于你',
128
+ typeUserPreference: '偏好',
129
+ typeProject: '项目',
130
+ typeSkill: '程序性',
131
+ typeDecision: '决策',
132
+ typeConcept: '概念',
133
+ typeFact: '事实',
134
+ typeUnknown: '未标注',
135
+ },
136
+ en: {
137
+ sectionLabel: 'Memory',
138
+ loading: 'Loading configuration…',
139
+ loadFailed: 'Failed to load memory settings: ',
140
+ unknownError: 'unknown error',
141
+ enabled: 'Enable memory plugin',
142
+ enabledHint: 'Master switch: when off, no memory is injected and the memory skill is not registered',
143
+ memoryDir: 'Memory directory',
144
+ memoryDirHint: 'Path holding SOUL/MEMORY/index/log; a leading ~ is expanded. Switching applies immediately and scaffolds a missing directory.',
145
+ dirPlaceholder: '~/.memory',
146
+ autoInject: 'Inject memory at session start',
147
+ autoInjectHint: 'Inject the memory snapshot into context when each session starts',
148
+ deferUntilUserSpeaks: 'Inject only after you speak',
149
+ deferUntilUserSpeaksHint: 'When on, a new session injects no memory / recall / digest reminder before your first message',
150
+ activeSessionOnly: 'Inject into the active session only',
151
+ activeSessionOnlyHint: 'When on, only the session that most recently received a message from you gets memory (background sessions are left alone)',
152
+ registerSkill: 'Register the memory skill',
153
+ registerSkillHint: 'Give the agent the remember / recall / consolidate / forget protocol',
154
+ recall: 'Proactive recall',
155
+ recallHint: 'When the conversation is idle, bring up a memory about you in first person (personified); can be turned off anytime',
156
+ recallInterval: 'Recall interval (minutes)',
157
+ recallIntervalHint: 'A random interval between min and max each time, so the rhythm never feels fixed',
158
+ recallMaxPerSession: 'Recalls per session',
159
+ recallMaxPerSessionHint: 'Maximum proactive recalls in one session, to stay unobtrusive',
160
+ toneGuide: 'Tone guidance',
161
+ toneGuideHint: 'Shift register by context (crunch, late night, bad news, milestones) without changing facts or crossing the SOUL boundary',
162
+ toneIntensity: 'Tone intensity',
163
+ toneIntensityHint: 'low = light seasoning / medium = more visible / off = pure engineering voice; facts always win',
164
+ toneLow: 'low (light seasoning)',
165
+ toneMedium: 'medium (more visible)',
166
+ toneOff: 'off (pure engineering voice)',
167
+ growthRecap: 'Weekly growth recap',
168
+ growthRecapHint: 'Once a week, on the recall channel, say what I kept this week (first person, at most five sentences; can be turned off)',
169
+ minutesPlaceholder: '30',
170
+ maxMinutesPlaceholder: '240',
171
+ maxPerSessionPlaceholder: '3',
172
+ saveFailed: 'Save failed: ',
173
+ footerDisabled: 'Current: disabled. Changes apply immediately.',
174
+ footerEnabled: 'Current: memory store at {dir}. Changes apply immediately.',
175
+ unconfigured: '(not configured)',
176
+ feedback: '🐛 Feedback / open an issue',
177
+ insightsLoading: 'Counting the memory store…',
178
+ insightsTitle: 'Memory health',
179
+ scoreOutOf: ' / 100',
180
+ insightsSub: 'Read-only stats: page count, access freshness, health checks and recent activity.',
181
+ metricPages: 'memory pages',
182
+ metricIndexRoutes: 'index routes',
183
+ metricChars: 'memory chars',
184
+ freshness: 'Access freshness',
185
+ bucketToday: 'today',
186
+ bucketWeek: '≤7 days',
187
+ bucketMonth: '≤30 days',
188
+ bucketQuarter: '≤90 days',
189
+ bucketStale: '>90 days',
190
+ bucketNever: 'never',
191
+ checks: 'Health checks',
192
+ checkIndex: 'index links complete',
193
+ checkOrphans: 'no orphan pages',
194
+ checkFrontmatter: 'frontmatter complete',
195
+ checkFreshness: 'access freshness',
196
+ checkIndexOk: '{routes} routes all valid',
197
+ checkIndexFail: '{count} routes point at missing pages',
198
+ checkOrphansOk: 'every page is in the index',
199
+ checkOrphansFail: '{count} pages not in the index: {list}{more}',
200
+ checkFrontmatterOk: 'title/type/salience complete',
201
+ checkFrontmatterFail: 'missing salience on {salience} pages / missing type on {type} pages',
202
+ checkFreshnessOk: 'no page has gone unread for over 90 days',
203
+ checkFreshnessFail: '{count} pages are stale or never stamped',
204
+ neverStamped: 'never stamped',
205
+ daysSinceAccess: 'days since last access',
206
+ staleCandidates: 'Stale candidates (top {count})',
207
+ recent: 'Recent activity',
208
+ listSeparator: ', ',
209
+ graphLoading: 'Building the memory graph…',
210
+ graphTitle: 'Memory graph',
211
+ graphResetView: 'Reset view',
212
+ graphStats: '{pages} pages · {links} page links · {tagEdges} shared tags',
213
+ graphIndexRoutes: '{count} index routes (dashed)',
214
+ graphIsolated: '{count} pages isolated',
215
+ graphUpdatedAt: 'updated {time}',
216
+ graphRelations: '{count} relations',
217
+ 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.',
218
+ graphIsolatedHint: 'These {count} pages are not connected to any other memory yet: {list}{more}',
219
+ graphMore: ' and more',
220
+ legendLinks: '━ page links',
221
+ legendIndexRoutes: '┄ index routes',
222
+ 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.',
223
+ typeIdentity: 'identity',
224
+ typeUser: 'about you',
225
+ typeUserPreference: 'preference',
226
+ typeProject: 'project',
227
+ typeSkill: 'procedural',
228
+ typeDecision: 'decision',
229
+ typeConcept: 'concept',
230
+ typeFact: 'fact',
231
+ typeUnknown: 'untagged',
232
+ },
233
+ }
234
+
235
+ /** Fill `{name}` placeholders in a translated template. */
236
+ function fill(template, params) {
237
+ let out = String(template)
238
+ for (const [name, value] of Object.entries(params ?? {})) {
239
+ out = out.split(`{${name}}`).join(String(value))
240
+ }
241
+ return out
242
+ }
243
+
244
+ /** Fallback translate for tests or a missing slot `t` seat (default Chinese). */
245
+ function fallbackT(key, params) {
246
+ const template = DICTS.zh[key] ?? key
247
+ return params === undefined ? template : fill(template, params)
248
+ }
249
+
250
+ /**
251
+ * The `t` seat travels by React context: MemorySection wraps the whole panel
252
+ * tree once, so every card/input reads the same translation function without
253
+ * drilling props through GraphCard → GraphView → renderNode.
254
+ */
255
+ const LocaleContext = React.createContext(fallbackT)
256
+
257
+ /** Translation for one component: a slot-injected `t` prop wins, context is the norm. */
258
+ function useT(props) {
259
+ const contextT = React.useContext(LocaleContext)
260
+ return typeof props?.t === 'function' ? props.t : contextT
261
+ }
262
+
263
+ /** Sidebar label in the requested language (zh `记忆` / en `Memory`). */
264
+ function sectionLabel(language) {
265
+ return DICTS[language === 'en' ? 'en' : 'zh'].sectionLabel
266
+ }
267
+
268
+ /** Freshness bucket label; unknown keys fall back to the server's own label. */
269
+ function bucketLabel(bucket, t) {
270
+ switch (bucket?.key) {
271
+ case 'today': return t('bucketToday')
272
+ case 'week': return t('bucketWeek')
273
+ case 'month': return t('bucketMonth')
274
+ case 'quarter': return t('bucketQuarter')
275
+ case 'stale': return t('bucketStale')
276
+ default: return bucket?.label ?? ''
277
+ }
278
+ }
279
+
280
+ /** Health-check title; unknown ids fall back to the server's own label. */
281
+ function checkLabel(check, t) {
282
+ switch (check?.id) {
283
+ case 'index': return t('checkIndex')
284
+ case 'orphans': return t('checkOrphans')
285
+ case 'frontmatter': return t('checkFrontmatter')
286
+ case 'freshness': return t('checkFreshness')
287
+ default: return check?.label ?? ''
288
+ }
289
+ }
290
+
291
+ /**
292
+ * Health-check detail rebuilt from the locale-neutral `data` the host sends
293
+ * (lib/insights.js). An older host payload without `data` keeps its Chinese
294
+ * `detail` verbatim — the panel never renders an empty sentence.
295
+ */
296
+ function checkDetail(check, t) {
297
+ const data = check?.data
298
+ if (data === undefined || data === null) return check?.detail ?? ''
299
+ switch (check?.id) {
300
+ case 'index':
301
+ return check.ok
302
+ ? fill(t('checkIndexOk'), { routes: data.routes })
303
+ : fill(t('checkIndexFail'), { count: data.missing })
304
+ case 'orphans':
305
+ return check.ok
306
+ ? t('checkOrphansOk')
307
+ : fill(t('checkOrphansFail'), {
308
+ count: data.count,
309
+ list: (data.sample ?? []).join(t('listSeparator')),
310
+ more: data.count > 3 ? '…' : '',
311
+ })
312
+ case 'frontmatter':
313
+ return check.ok
314
+ ? t('checkFrontmatterOk')
315
+ : fill(t('checkFrontmatterFail'), { salience: data.missingSalience, type: data.missingType })
316
+ case 'freshness':
317
+ return check.ok
318
+ ? t('checkFreshnessOk')
319
+ : fill(t('checkFreshnessFail'), { count: data.atRisk })
320
+ default:
321
+ return check?.detail ?? ''
322
+ }
323
+ }
324
+
325
+ /** Page-type label for the legend/tooltip; unknown types stay as the raw key. */
326
+ function typeLabel(type, t, fallback) {
327
+ switch (type) {
328
+ case 'identity': return t('typeIdentity')
329
+ case 'user': return t('typeUser')
330
+ case 'user-preference': return t('typeUserPreference')
331
+ case 'project': return t('typeProject')
332
+ case 'skill': return t('typeSkill')
333
+ case 'decision': return t('typeDecision')
334
+ case 'concept': return t('typeConcept')
335
+ case 'fact': return t('typeFact')
336
+ case 'unknown': return t('typeUnknown')
337
+ default: return fallback ?? type
338
+ }
339
+ }
340
+
23
341
  const rowStyle = {
24
342
  display: 'flex',
25
343
  alignItems: 'center',
@@ -75,8 +393,9 @@ window.__ModuleLoader__.load({
75
393
  }
76
394
 
77
395
  function ErrorText({ message }) {
396
+ const t = useT()
78
397
  return React.createElement('div', { style: { padding: '14px 16px', fontSize: '13px', lineHeight: '20px', color: 'var(--dsw-alias-state-error-primary, #e5484d)' } },
79
- '记忆设置页加载失败:', message)
398
+ t('loadFailed'), message)
80
399
  }
81
400
 
82
401
  /** 渲染期兜底:任何异常都以文案形式显示,绝不空白。 */
@@ -94,17 +413,20 @@ window.__ModuleLoader__.load({
94
413
  }
95
414
  }
96
415
 
97
- function MemorySection() {
416
+ function MemorySection(props) {
98
417
  // `gen` bumps after every successful config write so the read-only health
99
418
  // card re-mounts and re-reads the store (e.g. after a memoryDir switch).
100
419
  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),
420
+ const t = useT(props)
421
+ return React.createElement(LocaleContext.Provider, { value: t },
422
+ React.createElement(SectionBoundary, null,
423
+ React.createElement(MemoryForm, { onSaved: () => setGen((value) => value + 1) }),
424
+ React.createElement(SectionBoundary, { key: gen },
425
+ React.createElement(InsightsCard),
426
+ ),
427
+ React.createElement(SectionBoundary, { key: `graph-${gen}` },
428
+ React.createElement(GraphCard),
429
+ ),
108
430
  ),
109
431
  )
110
432
  }
@@ -157,7 +479,8 @@ window.__ModuleLoader__.load({
157
479
  }
158
480
 
159
481
  /** 记忆健康看板:只读,数据来自 /api/memory/insights,打开面板时拉取一次。 */
160
- function InsightsCard() {
482
+ function InsightsCard(props) {
483
+ const t = useT(props)
161
484
  const [data, setData] = React.useState(undefined)
162
485
  const [status, setStatus] = React.useState('loading')
163
486
 
@@ -182,7 +505,7 @@ window.__ModuleLoader__.load({
182
505
  }, [])
183
506
 
184
507
  if (status === 'loading') {
185
- return React.createElement('div', { style: { ...cardStyle, fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #888)' } }, '正在统计记忆库…')
508
+ return React.createElement('div', { style: { ...cardStyle, fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #888)' } }, t('insightsLoading'))
186
509
  }
187
510
  // 看板是附加信息:拿不到就静默隐藏,绝不影响设置页可用。
188
511
  if (status === 'failed' || data === undefined) return null
@@ -193,59 +516,61 @@ window.__ModuleLoader__.load({
193
516
  const buckets = (data.freshness && data.freshness.buckets) || []
194
517
  const stale = data.stalePages ?? []
195
518
  const recent = data.recent ?? []
196
- const formatDays = (days) => (days === null || days === undefined ? '从未戳记' : `${days} 天未访问`)
519
+ const formatDays = (days) => (days === null || days === undefined
520
+ ? t('neverStamped')
521
+ : `${days} ${t('daysSinceAccess')}`)
197
522
 
198
523
  return React.createElement('div', { style: cardStyle },
199
524
  React.createElement('div', { style: { display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: '8px' } },
200
- React.createElement('div', { style: cardTitleStyle }, '记忆健康'),
525
+ React.createElement('div', { style: cardTitleStyle }, t('insightsTitle')),
201
526
  React.createElement('div', { style: { fontSize: '20px', lineHeight: '26px', fontWeight: '700', color: scoreColor(health.score) } },
202
527
  `${health.score}`,
203
- React.createElement('span', { style: { fontSize: '11px', fontWeight: '400', color: 'var(--dsw-alias-label-secondary, #999)' } }, ' / 100'),
528
+ React.createElement('span', { style: { fontSize: '11px', fontWeight: '400', color: 'var(--dsw-alias-label-secondary, #999)' } }, t('scoreOutOf')),
204
529
  ),
205
530
  ),
206
- React.createElement('div', { style: cardSubStyle }, '只读统计:页数、访问新鲜度、体检结论与最近动态。'),
531
+ React.createElement('div', { style: cardSubStyle }, t('insightsSub')),
207
532
 
208
533
  React.createElement('div', { style: metricRowStyle },
209
534
  React.createElement('div', { style: metricBoxStyle },
210
535
  React.createElement('div', { style: metricValueStyle }, String(pages)),
211
- React.createElement('div', { style: metricLabelStyle }, '记忆页'),
536
+ React.createElement('div', { style: metricLabelStyle }, t('metricPages')),
212
537
  ),
213
538
  React.createElement('div', { style: metricBoxStyle },
214
539
  React.createElement('div', { style: metricValueStyle }, String(overview.indexEntries ?? 0)),
215
- React.createElement('div', { style: metricLabelStyle }, 'index 路由'),
540
+ React.createElement('div', { style: metricLabelStyle }, t('metricIndexRoutes')),
216
541
  ),
217
542
  React.createElement('div', { style: metricBoxStyle },
218
543
  React.createElement('div', { style: metricValueStyle }, `~${overview.chars ?? 0}`),
219
- React.createElement('div', { style: metricLabelStyle }, '记忆字数'),
544
+ React.createElement('div', { style: metricLabelStyle }, t('metricChars')),
220
545
  ),
221
546
  ),
222
547
 
223
- React.createElement('div', { style: sectionLabelStyle }, '访问新鲜度'),
548
+ React.createElement('div', { style: sectionLabelStyle }, t('freshness')),
224
549
  ...buckets.map((bucket) =>
225
550
  React.createElement(Bar, {
226
551
  key: bucket.key,
227
- label: bucket.label,
552
+ label: bucketLabel(bucket, t),
228
553
  count: bucket.count,
229
554
  total: pages,
230
555
  color: barColor(bucket.key),
231
556
  })),
232
557
  (data.freshness && data.freshness.never > 0)
233
- ? React.createElement(Bar, { label: '从未', count: data.freshness.never, total: pages, color: 'var(--dsw-alias-label-secondary, #888)' })
558
+ ? React.createElement(Bar, { label: t('bucketNever'), count: data.freshness.never, total: pages, color: 'var(--dsw-alias-label-secondary, #888)' })
234
559
  : null,
235
560
 
236
- React.createElement('div', { style: sectionLabelStyle }, '体检'),
561
+ React.createElement('div', { style: sectionLabelStyle }, t('checks')),
237
562
  ...health.checks.map((check) =>
238
563
  React.createElement('div', { key: check.id, style: { display: 'flex', gap: '8px', alignItems: 'baseline', marginBottom: '4px' } },
239
564
  React.createElement('span', { style: { color: checkColor(check.ok), fontSize: '12px', width: '14px', flexShrink: 0 } }, check.ok ? '✓' : '!'),
240
565
  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}`),
566
+ checkLabel(check, t),
567
+ React.createElement('span', { style: { color: 'var(--dsw-alias-label-secondary, #999)' } }, ` · ${checkDetail(check, t)}`),
243
568
  ),
244
569
  )),
245
570
 
246
571
  stale.length > 0
247
572
  ? React.createElement('div', null,
248
- React.createElement('div', { style: sectionLabelStyle }, `陈旧候选(前 ${stale.length})`),
573
+ React.createElement('div', { style: sectionLabelStyle }, fill(t('staleCandidates'), { count: stale.length })),
249
574
  ...stale.map((page) =>
250
575
  React.createElement('div', { key: page.path, style: { fontSize: '12px', lineHeight: '18px', display: 'flex', justifyContent: 'space-between', gap: '8px', marginBottom: '3px' } },
251
576
  React.createElement('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, page.title || page.path),
@@ -256,7 +581,7 @@ window.__ModuleLoader__.load({
256
581
 
257
582
  recent.length > 0
258
583
  ? React.createElement('div', null,
259
- React.createElement('div', { style: sectionLabelStyle }, '最近动态'),
584
+ React.createElement('div', { style: sectionLabelStyle }, t('recent')),
260
585
  ...recent.map((line, index) =>
261
586
  React.createElement('div', {
262
587
  key: `${index}-${line}`,
@@ -269,6 +594,7 @@ window.__ModuleLoader__.load({
269
594
 
270
595
  /** 目录输入:草稿态编辑,blur / Enter 才写回,避免每次按键触发 Host 重排。 */
271
596
  function DirInput({ value, disabled, onCommit }) {
597
+ const t = useT()
272
598
  const [draft, setDraft] = React.useState(undefined)
273
599
  const shown = draft !== undefined ? draft : (value ?? '')
274
600
  const commit = () => {
@@ -279,7 +605,7 @@ window.__ModuleLoader__.load({
279
605
  }
280
606
  return React.createElement('input', {
281
607
  type: 'text',
282
- placeholder: '~/.memory',
608
+ placeholder: t('dirPlaceholder'),
283
609
  disabled,
284
610
  value: shown,
285
611
  onChange: (event) => setDraft(event.target.value),
@@ -317,7 +643,20 @@ window.__ModuleLoader__.load({
317
643
  })
318
644
  }
319
645
 
320
- function MemoryForm({ onSaved }) {
646
+ /** 下拉选择:语气强度这类枚举配置,改动立即写回。 */
647
+ function SelectInput({ value, disabled, options, onChange }) {
648
+ return React.createElement('select', {
649
+ disabled,
650
+ value: value ?? '',
651
+ onChange: (event) => onChange(event.target.value),
652
+ style: { ...inputStyle, width: '190px', cursor: 'pointer' },
653
+ }, (options ?? []).map((option) =>
654
+ React.createElement('option', { key: option.value, value: option.value }, option.label)))
655
+ }
656
+
657
+ function MemoryForm(props) {
658
+ const t = useT(props)
659
+ const { onSaved } = props
321
660
  const [config, setConfig] = React.useState(undefined)
322
661
  const [status, setStatus] = React.useState('loading')
323
662
  const [error, setError] = React.useState(undefined)
@@ -366,9 +705,9 @@ window.__ModuleLoader__.load({
366
705
  }
367
706
 
368
707
  if (status === 'loading') {
369
- return React.createElement('div', { style: { padding: '14px 16px', fontSize: '13px', color: 'var(--dsw-alias-label-secondary, #888)' } }, '读取配置中…')
708
+ return React.createElement('div', { style: { padding: '14px 16px', fontSize: '13px', color: 'var(--dsw-alias-label-secondary, #888)' } }, t('loading'))
370
709
  }
371
- if (status === 'failed') return React.createElement(ErrorText, { message: error ?? 'unknown' })
710
+ if (status === 'failed') return React.createElement(ErrorText, { message: error ?? t('unknownError') })
372
711
 
373
712
  const value = config ?? {}
374
713
  const disabled = saving
@@ -376,8 +715,8 @@ window.__ModuleLoader__.load({
376
715
  return React.createElement('div', { style: { padding: '8px 0' } },
377
716
  React.createElement('div', { style: rowStyle },
378
717
  React.createElement('div', null,
379
- React.createElement('div', { style: labelStyle }, '启用记忆插件'),
380
- React.createElement('div', { style: subStyle }, '总开关:关闭后不再注入记忆,也不注册 memory 技能'),
718
+ React.createElement('div', { style: labelStyle }, t('enabled')),
719
+ React.createElement('div', { style: subStyle }, t('enabledHint')),
381
720
  ),
382
721
  React.createElement(Toggle, {
383
722
  checked: value.enabled !== false,
@@ -387,8 +726,8 @@ window.__ModuleLoader__.load({
387
726
  ),
388
727
  React.createElement('div', { style: rowStyle },
389
728
  React.createElement('div', null,
390
- React.createElement('div', { style: labelStyle }, '记忆目录'),
391
- React.createElement('div', { style: subStyle }, '存放 SOUL/MEMORY/index/log 的路径,支持 ~ 开头;修改后立即切换,目录不存在时自动初始化'),
729
+ React.createElement('div', { style: labelStyle }, t('memoryDir')),
730
+ React.createElement('div', { style: subStyle }, t('memoryDirHint')),
392
731
  ),
393
732
  React.createElement(DirInput, {
394
733
  value: value.memoryDir,
@@ -398,8 +737,8 @@ window.__ModuleLoader__.load({
398
737
  ),
399
738
  React.createElement('div', { style: rowStyle },
400
739
  React.createElement('div', null,
401
- React.createElement('div', { style: labelStyle }, '开机注入记忆'),
402
- React.createElement('div', { style: subStyle }, '每次会话开始把记忆快照注入上下文'),
740
+ React.createElement('div', { style: labelStyle }, t('autoInject')),
741
+ React.createElement('div', { style: subStyle }, t('autoInjectHint')),
403
742
  ),
404
743
  React.createElement(Toggle, {
405
744
  checked: value.autoInject !== false,
@@ -409,8 +748,8 @@ window.__ModuleLoader__.load({
409
748
  ),
410
749
  React.createElement('div', { style: rowStyle },
411
750
  React.createElement('div', null,
412
- React.createElement('div', { style: labelStyle }, '提问后才注入'),
413
- React.createElement('div', { style: subStyle }, '开启后,新会话在你发出第一条消息前不会注入任何记忆 / 追忆 / digest 提醒'),
751
+ React.createElement('div', { style: labelStyle }, t('deferUntilUserSpeaks')),
752
+ React.createElement('div', { style: subStyle }, t('deferUntilUserSpeaksHint')),
414
753
  ),
415
754
  React.createElement(Toggle, {
416
755
  checked: value.deferUntilUserSpeaks !== false,
@@ -420,8 +759,8 @@ window.__ModuleLoader__.load({
420
759
  ),
421
760
  React.createElement('div', { style: rowStyle },
422
761
  React.createElement('div', null,
423
- React.createElement('div', { style: labelStyle }, '仅当前激活会话注入'),
424
- React.createElement('div', { style: subStyle }, '开启后,只有最近收到你消息的会话才会注入记忆(后台会话不打扰)'),
762
+ React.createElement('div', { style: labelStyle }, t('activeSessionOnly')),
763
+ React.createElement('div', { style: subStyle }, t('activeSessionOnlyHint')),
425
764
  ),
426
765
  React.createElement(Toggle, {
427
766
  checked: value.activeSessionOnly !== false,
@@ -431,8 +770,8 @@ window.__ModuleLoader__.load({
431
770
  ),
432
771
  React.createElement('div', { style: rowStyle },
433
772
  React.createElement('div', null,
434
- React.createElement('div', { style: labelStyle }, '注册 memory 技能'),
435
- React.createElement('div', { style: subStyle }, '让 agent 获得 remember / recall / consolidate / forget 操作协议'),
773
+ React.createElement('div', { style: labelStyle }, t('registerSkill')),
774
+ React.createElement('div', { style: subStyle }, t('registerSkillHint')),
436
775
  ),
437
776
  React.createElement(Toggle, {
438
777
  checked: value.registerSkill !== false,
@@ -442,8 +781,8 @@ window.__ModuleLoader__.load({
442
781
  ),
443
782
  React.createElement('div', { style: rowStyle },
444
783
  React.createElement('div', null,
445
- React.createElement('div', { style: labelStyle }, '主动追忆'),
446
- React.createElement('div', { style: subStyle }, '对话空闲时,以第一人称主动提起一件关于你的往事(拟人化),可随时关闭'),
784
+ React.createElement('div', { style: labelStyle }, t('recall')),
785
+ React.createElement('div', { style: subStyle }, t('recallHint')),
447
786
  ),
448
787
  React.createElement(Toggle, {
449
788
  checked: value.recallEnabled !== false,
@@ -453,40 +792,80 @@ window.__ModuleLoader__.load({
453
792
  ),
454
793
  React.createElement('div', { style: rowStyle },
455
794
  React.createElement('div', null,
456
- React.createElement('div', { style: labelStyle }, '追忆间隔(分钟)'),
457
- React.createElement('div', { style: subStyle }, '每次随机在最短 ~ 最长之间取一个间隔,避免固定节奏'),
795
+ React.createElement('div', { style: labelStyle }, t('recallInterval')),
796
+ React.createElement('div', { style: subStyle }, t('recallIntervalHint')),
458
797
  ),
459
798
  React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: '8px' } },
460
799
  React.createElement(NumberInput, {
461
800
  value: value.recallIntervalMinMinutes,
462
801
  disabled,
463
- placeholder: '30',
802
+ placeholder: t('minutesPlaceholder'),
464
803
  onCommit: (next) => apply({ recallIntervalMinMinutes: next }),
465
804
  }),
466
805
  React.createElement('span', { style: { color: 'var(--dsw-alias-label-secondary, #999)' } }, '~'),
467
806
  React.createElement(NumberInput, {
468
807
  value: value.recallIntervalMaxMinutes,
469
808
  disabled,
470
- placeholder: '240',
809
+ placeholder: t('maxMinutesPlaceholder'),
471
810
  onCommit: (next) => apply({ recallIntervalMaxMinutes: next }),
472
811
  }),
473
812
  ),
474
813
  ),
475
814
  React.createElement('div', { style: rowStyle },
476
815
  React.createElement('div', null,
477
- React.createElement('div', { style: labelStyle }, '每会话追忆次数'),
478
- React.createElement('div', { style: subStyle }, '一个会话内最多主动追忆几次,避免打扰'),
816
+ React.createElement('div', { style: labelStyle }, t('recallMaxPerSession')),
817
+ React.createElement('div', { style: subStyle }, t('recallMaxPerSessionHint')),
479
818
  ),
480
819
  React.createElement(NumberInput, {
481
820
  value: value.recallMaxPerSession,
482
821
  disabled,
483
- placeholder: '3',
822
+ placeholder: t('maxPerSessionPlaceholder'),
484
823
  onCommit: (next) => apply({ recallMaxPerSession: next }),
485
824
  }),
486
825
  ),
487
- error !== undefined ? React.createElement('div', { style: errorStyle }, '保存失败:', error) : null,
826
+ React.createElement('div', { style: rowStyle },
827
+ React.createElement('div', null,
828
+ React.createElement('div', { style: labelStyle }, t('toneGuide')),
829
+ React.createElement('div', { style: subStyle }, t('toneGuideHint')),
830
+ ),
831
+ React.createElement(Toggle, {
832
+ checked: value.toneGuideEnabled !== false,
833
+ disabled,
834
+ onChange: (next) => apply({ toneGuideEnabled: next }),
835
+ }),
836
+ ),
837
+ React.createElement('div', { style: rowStyle },
838
+ React.createElement('div', null,
839
+ React.createElement('div', { style: labelStyle }, t('toneIntensity')),
840
+ React.createElement('div', { style: subStyle }, t('toneIntensityHint')),
841
+ ),
842
+ React.createElement(SelectInput, {
843
+ value: value.toneIntensity ?? 'low',
844
+ disabled: disabled || value.toneGuideEnabled === false,
845
+ options: [
846
+ { value: 'low', label: t('toneLow') },
847
+ { value: 'medium', label: t('toneMedium') },
848
+ { value: 'off', label: t('toneOff') },
849
+ ],
850
+ onChange: (next) => apply({ toneIntensity: next }),
851
+ }),
852
+ ),
853
+ React.createElement('div', { style: rowStyle },
854
+ React.createElement('div', null,
855
+ React.createElement('div', { style: labelStyle }, t('growthRecap')),
856
+ React.createElement('div', { style: subStyle }, t('growthRecapHint')),
857
+ ),
858
+ React.createElement(Toggle, {
859
+ checked: value.growthRecapEnabled !== false,
860
+ disabled,
861
+ onChange: (next) => apply({ growthRecapEnabled: next }),
862
+ }),
863
+ ),
864
+ error !== undefined ? React.createElement('div', { style: errorStyle }, t('saveFailed'), error) : null,
488
865
  React.createElement('div', { style: { padding: '14px 16px', fontSize: '12px', lineHeight: '18px', color: 'var(--dsw-alias-label-secondary, #888)' } },
489
- `当前:${value.enabled === false ? '已停用' : `记忆库位于 ${value.memoryDir ?? '(未配置)'}`}。修改即时生效。`,
866
+ value.enabled === false
867
+ ? t('footerDisabled')
868
+ : fill(t('footerEnabled'), { dir: value.memoryDir ?? t('unconfigured') }),
490
869
  ),
491
870
  // 反馈入口:做成按钮而不是小字链接,方便一眼看到。
492
871
  // 外部 HTTPS 在 DSH Desktop 里由系统浏览器打开(不带内嵌会话或 token)。
@@ -509,7 +888,7 @@ window.__ModuleLoader__.load({
509
888
  color: 'var(--dsw-alias-label-primary, #18181b)',
510
889
  textDecoration: 'none',
511
890
  },
512
- }, '🐛 反馈 / 提 issue'),
891
+ }, t('feedback')),
513
892
  ),
514
893
  )
515
894
  }
@@ -615,7 +994,9 @@ window.__ModuleLoader__.load({
615
994
  * 图谱视图:拿到 nodes/edges 就画(纯渲染,无副作用)。拖动与悬停是它
616
995
  * 自己维护的临时状态;`memo` 隔断父级重渲染带来的 hooks 调用。
617
996
  */
618
- const GraphView = React.memo(function GraphView({ graph, fetchedAt }) {
997
+ const GraphView = React.memo(function GraphView(props) {
998
+ const { graph, fetchedAt } = props
999
+ const t = useT(props)
619
1000
  const [hover, setHover] = React.useState(undefined)
620
1001
  const [dragPositions, setDragPositions] = React.useState(undefined)
621
1002
  const [dragging, setDragging] = React.useState(false)
@@ -782,10 +1163,10 @@ window.__ModuleLoader__.load({
782
1163
  const p = posOf(node)
783
1164
  const dx = p.x - node.x
784
1165
  const dy = p.y - node.y
785
- const tip = `${node.label}\n${node.type}`
1166
+ const tip = `${node.label}\n${typeLabel(node.type, t)}`
786
1167
  + `${node.salience ? ` · salience:${node.salience}` : ''}`
787
1168
  + `${node.tags && node.tags.length > 0 ? `\n#${node.tags.join(' #')}` : ''}`
788
- + `\n${node.degree ?? 0} 条关系`
1169
+ + `\n${fill(t('graphRelations'), { count: node.degree ?? 0 })}`
789
1170
  const showLabel = node.hub || (node.degree ?? 0) >= 2
790
1171
  const label = String(node.label).length > 16 ? `${String(node.label).slice(0, 15)}…` : String(node.label)
791
1172
  return React.createElement('g', {
@@ -836,7 +1217,7 @@ window.__ModuleLoader__.load({
836
1217
  cursor: zoomed ? 'grab' : 'default',
837
1218
  },
838
1219
  role: 'img',
839
- 'aria-label': '记忆图谱',
1220
+ 'aria-label': t('graphTitle'),
840
1221
  onPointerDown: panStart,
841
1222
  onPointerMove: panMove,
842
1223
  onPointerUp: panEnd,
@@ -872,13 +1253,13 @@ window.__ModuleLoader__.load({
872
1253
  style: { display: 'inline-flex', alignItems: 'center', gap: '4px', fontSize: '11px', color: 'var(--dsw-alias-label-secondary, #999)', marginRight: '10px' },
873
1254
  },
874
1255
  React.createElement('span', { style: { width: '7px', height: '7px', borderRadius: '4px', background: colourOf(type), display: 'inline-block' } }),
875
- type,
1256
+ typeLabel(type, t),
876
1257
  ))
877
1258
 
878
1259
  const isolated = stats.isolated ?? []
879
1260
  return React.createElement('div', { style: cardStyle },
880
1261
  React.createElement('div', { style: { display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: '8px' } },
881
- React.createElement('div', { style: cardTitleStyle }, '记忆图谱'),
1262
+ React.createElement('div', { style: cardTitleStyle }, t('graphTitle')),
882
1263
  zoomed
883
1264
  ? React.createElement('button', {
884
1265
  type: 'button',
@@ -892,36 +1273,41 @@ window.__ModuleLoader__.load({
892
1273
  background: 'transparent',
893
1274
  color: 'var(--dsw-alias-label-secondary, #999)',
894
1275
  },
895
- }, '重置视图')
1276
+ }, t('graphResetView'))
896
1277
  : null,
897
1278
  ),
898
1279
  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()}` : ''}`,
1280
+ fill(t('graphStats'), { pages: stats.pages ?? nodes.length, links: stats.links ?? 0, tagEdges: stats.tagEdges ?? 0 })
1281
+ + (stats.indexLinks ? ` · ${fill(t('graphIndexRoutes'), { count: stats.indexLinks })}` : '')
1282
+ + (isolated.length > 0 ? ` · ${fill(t('graphIsolated'), { count: isolated.length })}` : '')
1283
+ + (fetchedAt instanceof Date ? ` · ${fill(t('graphUpdatedAt'), { time: fetchedAt.toLocaleTimeString() })}` : ''),
903
1284
  ),
904
1285
  svg,
905
1286
  React.createElement('div', { style: { marginTop: '8px' } }, ...chips),
906
1287
  ((stats.links ?? 0) === 0 || isolated.length > 0)
907
1288
  ? React.createElement('div', { style: { fontSize: '11px', lineHeight: '17px', color: 'var(--dsw-alias-label-secondary, #888)', marginTop: '6px' } },
908
1289
  (stats.links ?? 0) === 0
909
- ? '页面之间还没有互相引用——图谱目前只靠共享 tag 连接。写下"见 [某页](path)"会让关系变实。'
910
- : `这 ${isolated.length} 页还没和别的记忆连上:${isolated.slice(0, 3).map((id) => id.replace(/\.md$/, '')).join('、')}${isolated.length > 3 ? ' 等' : ''}`,
1290
+ ? t('graphNoLinks')
1291
+ : fill(t('graphIsolatedHint'), {
1292
+ count: isolated.length,
1293
+ list: isolated.slice(0, 3).map((id) => id.replace(/\.md$/, '')).join(t('listSeparator')),
1294
+ more: isolated.length > 3 ? t('graphMore') : '',
1295
+ }),
911
1296
  )
912
1297
  : null,
913
1298
  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)' } }, '━ 页间互链'),
1299
+ React.createElement('span', { style: { color: 'var(--dsw-alias-brand-primary, #4c8bf5)' } }, t('legendLinks')),
915
1300
  ' · ',
916
- React.createElement('span', { style: { color: '#8b8f96' } }, '┄ 索引路由'),
1301
+ React.createElement('span', { style: { color: '#8b8f96' } }, t('legendIndexRoutes')),
917
1302
  ' · ',
918
- '细线=共享 tag。滚轮缩放 · 拖空白处平移 · 拖节点整理视图 · 悬停高亮关系;只读、实时。',
1303
+ t('graphHint'),
919
1304
  ),
920
1305
  )
921
1306
  })
922
1307
 
923
1308
  /** 记忆图谱卡片:负责取数(含轮询)与生命周期,渲染交给 GraphView。 */
924
- function GraphCard() {
1309
+ function GraphCard(props) {
1310
+ const t = useT(props)
925
1311
  const [graph, setGraph] = React.useState(undefined)
926
1312
  const [status, setStatus] = React.useState('loading')
927
1313
  const [fetchedAt, setFetchedAt] = React.useState(undefined)
@@ -955,7 +1341,7 @@ window.__ModuleLoader__.load({
955
1341
  }, [])
956
1342
 
957
1343
  if (status === 'loading') {
958
- return React.createElement('div', { style: { ...cardStyle, fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #888)' } }, '正在构建记忆图谱…')
1344
+ return React.createElement('div', { style: { ...cardStyle, fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #888)' } }, t('graphLoading'))
959
1345
  }
960
1346
  if (status === 'failed' || graph === undefined) return null
961
1347
  return React.createElement(GraphView, { graph, fetchedAt })
@@ -973,7 +1359,8 @@ window.__ModuleLoader__.load({
973
1359
  // 官方哪天给 settings.section 长出 icon 字段,这段即可删除。
974
1360
  const NAV_ROW_SELECTOR = '[role="dialog"] nav button'
975
1361
  const NAV_ICON_ATTR = 'data-dsh-memory-nav-icon'
976
- const MEMORY_SECTION_LABEL = 'Memory'
1362
+ // The label is resolved from DICTS by `sectionLabel(language)`: it is both the
1363
+ // displayed text and the claim key, so both must come from that one function.
977
1364
  const MEMORY_FEEDBACK_URL = 'https://github.com/LittleBlackTong/dsh-plugin-memory/issues/new'
978
1365
  const ICON_MEDIUM_STROKE = 1.3
979
1366
  const BRAIN_CIRCUIT_PATHS = [
@@ -1037,24 +1424,54 @@ window.__ModuleLoader__.load({
1037
1424
  }
1038
1425
 
1039
1426
  function apply(ctx) {
1427
+ // Language packs ride DSH's own locale layer: the panel follows
1428
+ // 设置 → 通用设置 → 语言 instead of guessing from navigator.language.
1429
+ ctx.effect(() => ctx.locale.register(LOCALE_NS, DICTS), 'memory: dictionaries')
1430
+ /** Sidebar label in the active language (zh `记忆` / en `Memory`). */
1431
+ const labelOf = () => {
1432
+ let active = 'zh'
1433
+ try {
1434
+ active = ctx.locale.getSnapshot().active === 'en' ? 'en' : 'zh'
1435
+ } catch {
1436
+ active = 'zh'
1437
+ }
1438
+ return sectionLabel(active)
1439
+ }
1040
1440
  ctx.slots.inject('settings.section', () => ctx.slots.register({
1041
1441
  name: 'settings.section',
1042
1442
  id: 'memory',
1043
1443
  order: 100,
1044
- label: () => MEMORY_SECTION_LABEL,
1444
+ locale: LOCALE_NS,
1445
+ label: labelOf,
1045
1446
  }, MemorySection))
1046
- // 官方 settings.section 没有 icon 字段,侧栏标记只能靠自己认领。
1047
- ctx.effect(() => claimNavIcon(() => MEMORY_SECTION_LABEL), 'memory: settings nav icon')
1447
+ // 官方 settings.section 没有 icon 字段,侧栏标记只能靠自己认领;
1448
+ // 认领键就是当前语言的 label(语言切换后 MutationObserver 会重新对齐)。
1449
+ ctx.effect(() => claimNavIcon(labelOf), 'memory: settings nav icon')
1048
1450
  }
1049
1451
 
1050
1452
  exports.apply = apply
1051
- exports.inject = ['slots']
1453
+ exports.inject = ['slots', 'locale']
1052
1454
  // Test seam: the browser half cannot be imported by Node, so the pure
1053
1455
  // helpers and the component itself are exposed for a vm-based harness.
1054
1456
  // Underscore-prefixed and additive: the host only reads `apply`/`inject`.
1055
1457
  exports.__test = {
1458
+ MemorySection,
1459
+ MemoryForm,
1460
+ InsightsCard,
1056
1461
  GraphCard,
1057
1462
  GraphView,
1463
+ DICTS,
1464
+ LOCALE_NS,
1465
+ fallbackT,
1466
+ fill,
1467
+ sectionLabel,
1468
+ bucketLabel,
1469
+ checkLabel,
1470
+ checkDetail,
1471
+ typeLabel,
1472
+ useT,
1473
+ isOwnNavRow,
1474
+ claimNavIcon,
1058
1475
  applyDrag,
1059
1476
  releasePositions,
1060
1477
  clampToBox,