dsh-cross-memory 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -6,7 +6,8 @@ window.__ModuleLoader__.load({
6
6
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
7
  const PACKAGE = "dsh-cross-memory";
8
8
  const REMOTE_INVOCATION_DATA = [{"method":"overview","parameters":[],"result":"overview"},{"method":"list","parameters":[{"name":"project","wire":"project","shape":"text","optional":true},{"name":"scope","wire":"scope","shape":"text","optional":true},{"name":"query","wire":"query","shape":"text","optional":true},{"name":"kind","wire":"kind","shape":"text","optional":true},{"name":"limit","wire":"limit","shape":"number","optional":true}],"result":"entries"},{"method":"add","parameters":[{"name":"project","wire":"project","shape":"text","optional":true},{"name":"scope","wire":"scope","shape":"text"},{"name":"kind","wire":"kind","shape":"text","optional":true},{"name":"title","wire":"title","shape":"text"},{"name":"body","wire":"body","shape":"text"},{"name":"tags","wire":"tags","shape":"text","optional":true}],"result":"entry"},{"method":"forget","parameters":[{"name":"project","wire":"project","shape":"text","optional":true},{"name":"scope","wire":"scope","shape":"text"},{"name":"id","wire":"id","shape":"text"}],"result":"removed"},{"method":"promoteSkill","parameters":[{"name":"name","wire":"name","shape":"text"}],"result":"skill"},{"method":"discardSkill","parameters":[{"name":"name","wire":"name","shape":"text"}],"result":"discard"},{"method":"persona","parameters":[],"result":"persona"},{"method":"savePersona","parameters":[{"name":"text","wire":"text","shape":"text"},{"name":"locked","wire":"locked","shape":"flag"}],"result":"persona"},{"method":"disputes","parameters":[],"result":"disputes"},{"method":"resolveDispute","parameters":[{"name":"id","wire":"id","shape":"text"},{"name":"decision","wire":"decision","shape":"text"}],"result":"text"}];
9
- // ---- client/card.js ----
9
+ // ---- .client-build/parts/card.js ----
10
+ "use strict";
10
11
  /**
11
12
  * The tunables card, embedded at the foot of the Memories settings page.
12
13
  *
@@ -18,432 +19,427 @@ window.__ModuleLoader__.load({
18
19
  * accepts, and a field the schema does not declare fails the save instead of
19
20
  * being silently dropped.
20
21
  */
21
-
22
22
  /** The profile entry whose form this card edits; must match the host's entry id. */
23
- const NS = 'memories'
24
-
23
+ const NS = 'memories';
25
24
  /** Per-locale chrome strings for the card frame. */
26
25
  const CARD_COPY = {
27
- zh: {
28
- reset: '恢复默认',
29
- saved: '已保存。',
30
- unavailable: '这个部署没有把 memories 条目暴露成可编辑的表单。',
31
- note: '改动写进 profile 配置并立即生效,无需重启。存储位置是部署层配置。',
32
- },
33
- en: {
34
- reset: 'Reset',
35
- saved: 'Saved.',
36
- unavailable: 'This deployment does not expose the memories entry as an editable form.',
37
- note: 'Changes are written to the profile config and apply immediately; no restart is needed. The store location is a deployment setting.',
38
- },
39
- }
40
-
26
+ zh: {
27
+ reset: '恢复默认',
28
+ saved: '已保存。',
29
+ unavailable: '这个部署没有把 memories 条目暴露成可编辑的表单。',
30
+ note: '改动写进 profile 配置并立即生效,无需重启。存储位置是部署层配置。',
31
+ },
32
+ en: {
33
+ reset: 'Reset',
34
+ saved: 'Saved.',
35
+ unavailable: 'This deployment does not expose the memories entry as an editable form.',
36
+ note: 'Changes are written to the profile config and apply immediately; no restart is needed. The store location is a deployment setting.',
37
+ },
38
+ };
41
39
  /** One row per tunable; `label`/`hint` are the `{ zh, en }` pair. */
42
40
  const FIELDS = [
43
- {
44
- field: 'maxSummaryBytes', kind: 'number', min: 0, step: 256,
45
- label: { zh: '摘要字节上限', en: 'Summary byte budget' },
46
- hint: { zh: '一次会话注入的记忆摘要最大字节数,默认 4096;0 表示关闭注入。', en: 'Bytes of memory summary injected once per conversation, default 4096. 0 disables injection.' },
47
- },
48
- {
49
- field: 'maxSummaryEntries', kind: 'number', min: 1, step: 1,
50
- label: { zh: '每作用域摘要条数', en: 'Summary entries per scope' },
51
- hint: { zh: '摘要里每个作用域列出多少条记忆。', en: 'How many memories each scope lists in the summary.' },
52
- },
53
- {
54
- field: 'globalSummaryEntries', kind: 'number', min: 0, step: 1,
55
- label: { zh: '全局段摘要条数', en: 'Global entries' },
56
- hint: { zh: '全局段最多列几条。两个作用域共用一份字节预算、全局段先渲染,不设上限时全局会吃掉项目段用不完的部分(实测某 2 条记忆的项目会话里全局占了 87%)。设为 0 则不注入全局段。', en: 'How many the GLOBAL section may list. Both scopes share one byte budget and global renders first, so without a cap it absorbs whatever the project half leaves (measured: 87% of a small project\'s summary). 0 removes the global section.' },
57
- },
58
- {
59
- field: 'globalSummaryBytes', kind: 'number', min: 0, step: 100,
60
- label: { zh: '全局段字节预算', en: 'Global bytes' },
61
- hint: { zh: '全局段单独占多少字节(在总预算之内)。只限条数不够:中文一条约 600 字节,4 条就吃掉 4KB 的 60%,实测全局段仍占 45–81%;按字节预留才真正给项目段留出位置。设为 0 则不注入全局段。', en: 'Byte budget for the GLOBAL section, inside the total. A count cap is not enough — four Chinese entries cost ~2.6 KB of a 4 KB block, and the global half still took 45–81% until bytes were reserved. 0 removes the global section.' },
62
- },
63
- {
64
- field: 'summaryFreshSlots', kind: 'number', min: 0, step: 1,
65
- label: { zh: '新记忆保底条数', en: 'Fresh-memory slots' },
66
- hint: { zh: '每个作用域预留几条给从未被注入过的记忆,且优先人手或模型显式写入的。作用域存满后纯按排序等于永远只展示同一批老记忆,新写的(包括用来纠正旧结论的那条)永远排不进来;设为 0 即恢复纯排序。', en: 'How many of each scope\'s entries are reserved for memories never listed before, preferring ones written deliberately over extracted ones. On a full scope pure ranking shows the same old set forever, so a correction never makes it in; 0 restores pure ranking.' },
67
- },
68
- {
69
- field: 'recallMode', kind: 'select',
70
- options: [
71
- { value: 'once', label: { zh: '仅一次', en: 'Once' } },
72
- { value: 'on-demand', label: { zh: '按需补充', en: 'On demand' } },
73
- { value: 'off', label: { zh: '关闭注入', en: 'Off' } },
74
- ],
75
- label: { zh: '记忆注入方式', en: 'Memory injection' },
76
- hint: { zh: 'once 只在会话开始时注入一次摘要;on-demand 额外在当前话题明显命中记忆时补一小块;off 完全关闭注入,只留记忆工具。', en: 'once injects the summary at the start of the conversation; on-demand also adds a small block when the current turn clearly matches a memory; off disables injection and leaves only the memory tool.' },
77
- },
78
- {
79
- field: 'recallMinScore', kind: 'number', min: 0, step: 1,
80
- label: { zh: '按需注入的相关度下限', en: 'Recall relevance floor' },
81
- hint: { zh: '补注需要达到的相关度分数,是一个"更严/更松"的旋钮。真正的精度由下面「补注所需命中词数」把关:中文提问共享两个词大约得 9–12 分,所以默认 9;只共用「日志」这类一个常见词大约 8 分,因此单靠相关度是拦不住的。', en: 'Relevance a memory must reach to be injected on demand. This is a strictness knob; precision comes from the strong-term requirement below. A Chinese paraphrase sharing two bigrams scores about 9-12, and one shared common word about 8, which is why the default sits at 9.' },
82
- },
83
- {
84
- field: 'recallMaxPerConversation', kind: 'number', min: 0, step: 1,
85
- label: { zh: '每会话补注条数上限', en: 'Recalled memories per conversation' },
86
- hint: { zh: '一个会话最多补注多少条记忆;0 关闭按需补注,只保留一次摘要。', en: 'Maximum memories injected on demand in one conversation. 0 keeps only the once-per-conversation summary.' },
87
- },
88
- {
89
- field: 'recallMaxBytes', kind: 'number', min: 0, step: 100,
90
- label: { zh: '补注字节上限', en: 'Recall block byte budget' },
91
- hint: { zh: '单次按需补注块的字节上限,0 表示关闭按需补注。', en: 'Byte budget for one on-demand recall block. 0 disables recall deltas.' },
92
- },
93
- {
94
- field: 'rawRecall', kind: 'boolean',
95
- label: { zh: '补注带原始会话片段', en: 'Recall with original excerpts' },
96
- hint: { zh: '开启后,按需补注块除了记忆摘要,还会附上这条记忆来源会话里的原始对话片段(已做凭据擦除、只读本机 session 日志、最多两条来源会话)。默认关闭,因为它会把别的会话的原文注入当前上下文。', en: 'Adds original conversation excerpts from the memories\' source sessions to the recall block. Credential-scrubbed, local session logs only, at most two source sessions. Off by default because it injects another session\'s prose.' },
97
- },
98
- {
99
- field: 'rawRecallBytes', kind: 'number', min: 0, step: 100,
100
- label: { zh: '原始片段字节上限', en: 'Original excerpt byte budget' },
101
- hint: { zh: '一次补注里原始会话片段的总字节上限;0 等于关闭原始片段(即使总开关打开)。', en: 'Byte budget for the raw-excerpt half of one recall block. 0 disables excerpts even when the master switch is on.' },
102
- },
103
- {
104
- field: 'rawRecallExcerpts', kind: 'number', min: 0, step: 1,
105
- label: { zh: '原始片段条数上限', en: 'Original excerpts per recall' },
106
- hint: { zh: '一次补注最多带几条原始片段;0 等于关闭。', en: 'Most original excerpts one recall block may carry. 0 disables them.' },
107
- },
108
- {
109
- field: 'recallMinQueryChars', kind: 'number', min: 0, step: 1,
110
- label: { zh: '触发补注的最短发问长度', en: 'Shortest turn worth recalling' },
111
- hint: { zh: '用户消息短于该字符数时不判定补注(例如「好」「继续」),避免为无意义的回合扫描整个记忆库。', en: 'A user turn shorter than this is skipped instead of scanning the store, so bare acknowledgements cost nothing.' },
112
- },
113
- {
114
- field: 'recallMinTerms', kind: 'number', min: 1, step: 1,
115
- label: { zh: '补注所需命中词数', en: 'Strong terms required to recall' },
116
- hint: { zh: '一条记忆要被按需补注,除了达到相关度下限,还必须在标题、别名、标签或「何时有用」里命中这么多个不同的提问词。中文提问尤其需要:只共用「插件」「日志」这类常见词不算证据,共享两个词才算。设为 1 就只按相关度打分判断(会明显更容易误补)。', en: 'Distinct query terms that must land in the title, keys, tags, or appliesTo before a memory may be recalled. This is what stops a Chinese turn from recalling everything that shares a common word; set it to 1 to gate on relevance alone.' },
117
- },
118
- {
119
- field: 'injectDelta', kind: 'boolean',
120
- label: { zh: '会后补注新记忆', en: 'Announce late memories' },
121
- hint: { zh: '摘要注入之后才写入的记忆(例如后台抽取、合并的结果)在下一步用一个很小的块补一次:每个会话最多两次、每次 800 字节,只列新增或更新的条目。', en: 'Memories written after the summary was shown (background extraction, consolidation) get one small block on the next step: at most twice per conversation, 800 bytes each, new or updated entries only.' },
122
- },
123
- {
124
- field: 'rotationEntries', kind: 'number', min: 0, step: 1,
125
- label: { zh: '每会话轮转标题数', en: 'Rotation titles per conversation' },
126
- hint: { zh: '摘要装不下的记忆,用一份只列标题的小块轮转:从未曝光的最先,其次是最久没出现过的,默认 16 条(12 全局 / 4 项目,硬分配)、约 1.6KB。0 关闭。它让整库在几十个会话里都能被看见,而不会永远只注入同一小批。', en: 'Memories the summary had no room for are rotated in as a title-only block: never-surfaced first, then the longest-unseen, default 16 per conversation (12 global / 4 project, hard split), about 1.6KB. 0 disables it.' },
127
- },
128
- {
129
- field: 'rotationEveryTurns', kind: 'number', min: 0, step: 1,
130
- label: { zh: '轮转间隔(用户轮次)', en: 'Rotation cadence (user turns)' },
131
- hint: { zh: '长会话里每隔这么多轮用户发言再补一次轮转块;0 表示整个会话只补一次。默认 8:一个几小时的会话会分批看到新标题,而不是首轮之后再也不更新。', en: 'Inside one long conversation, emit a fresh rotation block every this many user turns; 0 emits only once. The default 8 lets a multi-hour session meet new titles in batches instead of freezing after its first turn.' },
132
- },
133
- {
134
- field: 'reflectionEnabled', kind: 'boolean',
135
- label: { zh: '每周反思', en: 'Weekly reflection' },
136
- hint: { zh: '每周从记忆里综合出几条「没有哪一条记忆单独说过」的观察,比如跨项目的习惯、反复踩的坑。每条必须引用依据的记忆,否则丢弃。写成按日期归档的 markdown,不注入对话。', en: 'Once a week, synthesize observations no single memory states — cross-project habits, recurring pitfalls. Every observation must cite its evidence or it is dropped. Dated markdown files, never injected.' },
137
- },
138
- {
139
- field: 'noticeGate', kind: 'boolean',
140
- label: { zh: '没规矩的提醒先问 AI', en: 'Gate judgement notices' },
141
- hint: { zh: '有硬规则的提醒(日报、积压、到期承诺)不过闸门。只有「没有截止日期、躺了好几天」这类需要判断的,才先问一次模型值不值得打扰——答不上来就不打扰。', en: 'Rule-based notices (digest, backlog, a passed deadline) bypass the gate. Only judgement calls — an undated promise sitting for days — go to a model first, and a failure means silence.' },
142
- },
143
- {
144
- field: 'noticesEnabled', kind: 'boolean',
145
- label: { zh: '允许它主动开口', en: 'Let it speak first' },
146
- hint: { zh: '每天一条整理简报、待裁决积压超时提醒、到期承诺提醒,以系统通知的形式送达。关掉则只在你问的时候回答。', en: 'A daily digest, a backlog warning, and overdue-promise reminders, delivered as system notifications. Off means it only answers.' },
147
- },
148
- {
149
- field: 'noticeQuietHours', kind: 'text',
150
- label: { zh: '安静时段', en: 'Quiet hours' },
151
- hint: { zh: '本地时间的免打扰窗口,例如 "22:00-08:00";留空表示不限制。落在窗口内的通知会顺延到窗口结束,不会丢。', en: 'Local windows when nothing is delivered, e.g. "22:00-08:00". Held notices fire when the window ends; they are not dropped.' },
152
- },
153
- {
154
- field: 'personaMaxBytes', kind: 'number', min: 0, step: 100,
155
- label: { zh: '画像块字节预算', en: 'Persona block budget' },
156
- hint: { zh: '每会话开头注入的「关于你」块的上限。它由合并子代理从 voice=user 的记忆里维护,是整轮对话的上下文,不占记忆摘要的预算;设为 0 关闭。', en: 'Upper bound for the profile block injected once per conversation. It is maintained by the consolidation pass from voice=user memories and is turn-level context, so it does not compete with the memory summary budget. 0 disables it.' },
157
- },
158
- {
159
- field: 'autoDecide', kind: 'boolean',
160
- label: { zh: '合并争议交给 AI 裁决', en: 'Let an AI adjudicate merge disputes' },
161
- hint: { zh: '合并里那些「只是判断、不是承诺」的变更(例如这条被读过 2 次就想退役、改写后正文变短)改由一次受限子代理裁决:它只回答"有没有丢信息",答 accept 或 reject 并给置信度。永久保留、人手写两类仍然等你(作用域不归合并改,已有记忆钉在原作用域)。关掉则全部进「待裁决」。', en: 'Changes blocked only because they are a judgement rather than a promise are adjudicated by one tool-free child that answers accept or reject with a confidence. Permanent and user-written items still wait for you; a merge never moves a memory between scopes. Off sends everything to the panel.' },
162
- },
163
- {
164
- field: 'autoDecideMinConfidence', kind: 'number', min: 0, max: 1, step: 0.05,
165
- label: { zh: 'AI 裁决的最低置信度', en: 'AI verdict confidence floor' },
166
- hint: { zh: '低于该置信度视为「没有答案」,条目留在待裁决。', en: 'Below this the verdict counts as no answer and the item stays in the panel.' },
167
- },
168
- {
169
- field: 'evidenceMaxDf', kind: 'number', min: 0, max: 1, step: 0.05,
170
- label: { zh: '算作「常见词」的库占比', en: 'Share of the store that makes a word common' },
171
- hint: { zh: '一个提问词若出现在该作用域超过这个比例的记忆里,就不算补注所需的「证据词」。默认 0.15 是在真实库上量出来的:只命中一个词(dsh,占 22%),把「dsh 插件 配置」这类泛问的误纳入从 37 条降到 9 条,10 条标注探针一条不变。设为 0 关闭折扣。', en: 'A query term appearing in more than this share of one scope stops counting as recall evidence. 0.15 is measured on a real store: it catches one word (dsh, 22%) and takes a generic turn from 37 admitted memories to 9 while all ten labelled probes keep their verdict. 0 disables it.' },
172
- },
173
- {
174
- field: 'maxEntriesPerScope', kind: 'number', min: 1, step: 1,
175
- label: { zh: '每作用域保留条数', en: 'Stored memories per scope' },
176
- hint: { zh: '超过后归档最久未使用的记忆(可用 /memories restore 取回)。', en: 'Past this cap the least recently used memories are archived; /memories restore brings one back.' },
177
- },
178
- {
179
- field: 'maxUnusedDays', kind: 'number', min: 0, step: 10,
180
- label: { zh: '无用记忆归档天数', en: 'Archive unused after (days)' },
181
- hint: { zh: '这么久没有被读到、没有被注入摘要、也不是新写的记忆会被归档(可恢复)。0 关闭归档;人手写的记忆永不归档。', en: 'Archive a memory that has not been read, surfaced, or written for this many days. Recoverable with /memories restore. 0 disables archival; memories a person wrote are never archived.' },
182
- },
183
- {
184
- field: 'dedupeSimilarity', kind: 'number', min: 0, step: 0.05,
185
- label: { zh: '近似重复合并阈值', en: 'Near-duplicate threshold' },
186
- hint: { zh: '标题与正文词重叠超过该比例时,新记忆视为改写并取代旧记忆(0–1)。0 只保留完全相同才合并的规则。', en: 'Share of title and body words two memories must share before the newer one supersedes the older (0-1). 0 keeps only the exact-match rule.' },
187
- },
188
- {
189
- field: 'sweepIntervalHours', kind: 'number', min: 0, step: 1,
190
- label: { zh: '定期整理间隔(小时)', en: 'Maintenance sweep interval (hours)' },
191
- hint: { zh: '每隔多久对所有工作区做一次归档整理;0 关闭定期整理(仍可用 /memories sweep 手动执行)。', en: 'How often to run retention across every workspace. 0 disables the periodic sweep; /memories sweep still runs it on demand.' },
192
- },
193
- {
194
- field: 'autoExtract', kind: 'boolean',
195
- label: { zh: '后台抽取', en: 'Background extraction' },
196
- hint: { zh: '会话空闲后从最近对话里抽取值得长期保留的事实。', en: 'Mine finished sessions for durable facts once they have been idle.' },
197
- },
198
- {
199
- field: 'autoExtractIdleMs', kind: 'number', min: 1000, step: 1000,
200
- label: { zh: '抽取前空闲时长(毫秒)', en: 'Idle before extraction (ms)' },
201
- hint: { zh: '会话需空闲多久才开始挖掘。', en: 'How long a session must stay idle before it is mined.' },
202
- },
203
- {
204
- field: 'extractWindowMessages', kind: 'number', min: 1, step: 1,
205
- label: { zh: '抽取窗口(条消息)', en: 'Extraction window (messages)' },
206
- hint: { zh: '一次抽取最多读最近多少条对话消息。配合「周期性抽取间隔」使用:按一个间隔的增量来定,而不是按整段会话。', en: 'How many recent conversation messages one extraction reads. Size it for one periodic interval, not for a whole conversation.' },
207
- },
208
- {
209
- field: 'extractMaxInputChars', kind: 'number', min: 1, step: 1000,
210
- label: { zh: '抽取输入预算(字符)', en: 'Extraction input budget (chars)' },
211
- hint: { zh: '交给抽取器的对话文本字符上限。', en: 'Character budget for the transcript handed to the extractor.' },
212
- },
213
- {
214
- field: 'extractMaxOutputTokens', kind: 'number', min: 1, step: 128,
215
- label: { zh: '抽取输出 token 上限', en: 'Extraction output tokens' },
216
- hint: { zh: '一次抽取调用的输出 token 上限。', en: 'Output token cap for one extraction call.' },
217
- },
218
- {
219
- field: 'extractTimeoutMs', kind: 'number', min: 1000, step: 5000,
220
- label: { zh: '抽取超时(毫秒)', en: 'Extraction timeout (ms)' },
221
- hint: { zh: '一次抽取调用的超时时间。', en: 'Timeout for one extraction call.' },
222
- },
223
- {
224
- field: 'extractMaxMemories', kind: 'number', min: 1, step: 1,
225
- label: { zh: '每次抽取条数上限', en: 'Memories per extraction' },
226
- hint: { zh: '一次抽取最多写入多少条记忆。', en: 'Maximum memories one extraction pass may store.' },
227
- },
228
- {
229
- field: 'extractIntervalMinutes', kind: 'number', min: 0, step: 5,
230
- label: { zh: '周期性抽取间隔(分钟)', en: 'Periodic extraction interval (minutes)' },
231
- hint: { zh: '每隔这么久检查一次所有打开的会话,只要有新内容且会话当时空闲就抽一段——长会话因此不会因为「只在停止输入后抽一次」而丢掉中间的内容。没有新内容时不产生模型调用;仍受错峰时段与额度闸门限制。0 关闭周期检查。', en: 'How often to check every open session and mine a slice when there is new material and the session is momentarily idle — so a long working session does not lose its middle to a single end-of-session pass. A session with nothing new costs no model call; peak hours and the quota gate still apply. 0 disables the check.' },
232
- },
233
- {
234
- field: 'minIdleHours', kind: 'number', min: 0, step: 0.5,
235
- label: { zh: '挖掘前最短空闲(小时)', en: 'Minimum idle before mining (hours)' },
236
- hint: { zh: '会话至少要空闲这么久才会被挖掘,可填小数(0.5 = 半小时);实际等待取它与「抽取前空闲时长」的较大者。0 关闭该闸门。', en: 'A session must have been idle at least this long before it is mined. Fractions are allowed (0.5 = half an hour); the effective wait is the larger of this and the idle delay above. 0 disables the gate.' },
237
- },
238
- {
239
- field: 'maxAgeDays', kind: 'number', min: 0, step: 1,
240
- label: { zh: '超过天数不再挖掘(天)', en: 'Never mine sessions older than (days)' },
241
- hint: { zh: '最后活动早于该天数的会话永不挖掘,0 关闭该闸门。', en: 'Sessions whose last activity is older than this are never mined. 0 disables the gate.' },
242
- },
243
- {
244
- field: 'maxSessionsPerPass', kind: 'number', min: 1, step: 1,
245
- label: { zh: '每次挖掘的会话数', en: 'Sessions per pass' },
246
- hint: { zh: '一次抽取最多挖掘多少个会话,新的优先。', en: 'How many sessions one extraction pass may mine, newest first.' },
247
- },
248
- {
249
- field: 'consolidate', kind: 'boolean',
250
- label: { zh: '合并重整', en: 'Consolidation pass' },
251
- hint: { zh: '新记忆落盘后,用一个受限子代理合并、改写并相互协调。', en: 'After new memories land, merge and reconcile them through a restricted sub-agent.' },
252
- },
253
- {
254
- field: 'consolidateCooldownHours', kind: 'number', min: 0, step: 1,
255
- label: { zh: '合并冷却(小时)', en: 'Consolidation cooldown (hours)' },
256
- hint: { zh: '两次合并之间的最短小时数,约束后台额度消耗。', en: 'Minimum hours between consolidation passes; bounds background quota use.' },
257
- },
258
- {
259
- field: 'consolidateMaxEntries', kind: 'number', min: 1, step: 8,
260
- label: { zh: '每次合并条目上限', en: 'Memories per consolidation' },
261
- hint: { zh: '一次合并最多考虑多少条记忆。', en: 'How many memories one consolidation pass may consider.' },
262
- },
263
- {
264
- field: 'consolidateTimeoutMs', kind: 'number', min: 1000, step: 10000,
265
- label: { zh: '合并超时(毫秒)', en: 'Consolidation timeout (ms)' },
266
- hint: { zh: '一次合并子代理运行的超时时间。', en: 'Timeout for one consolidation sub-agent run.' },
267
- },
268
- {
269
- field: 'pauseOnQuotaError', kind: 'boolean',
270
- label: { zh: '额度紧张时暂停后台', en: 'Pause background work on quota errors' },
271
- hint: { zh: '提供方因限流或额度耗尽拒绝后,暂停后台抽取与合并,直到冷却结束。', en: 'After a rate-limit or exhausted-quota refusal, stop background extraction and consolidation until the cooldown elapses.' },
272
- },
273
- {
274
- field: 'quotaCooldownMinutes', kind: 'number', min: 0, step: 5,
275
- label: { zh: '额度冷却(分钟)', en: 'Quota cooldown (minutes)' },
276
- hint: { zh: '一次拒绝后等待多久;连续拒绝会翻倍。0 表示不暂停。', en: 'Wait after one refusal; doubles per consecutive refusal. 0 disables the pause.' },
277
- },
278
- {
279
- field: 'quotaCooldownMaxMinutes', kind: 'number', min: 0, step: 30,
280
- label: { zh: '额度冷却上限(分钟)', en: 'Quota cooldown ceiling (minutes)' },
281
- hint: { zh: '上面那个等待翻倍后的上限。', en: 'Upper bound as the wait doubles.' },
282
- },
283
- {
284
- field: 'snapshotMaxAgeDays', kind: 'number', min: 0, step: 10,
285
- label: { zh: '快照记忆保留天数', en: 'Snapshot lifetime (days)' },
286
- hint: { zh: '标记为「快照」的记忆(某个时刻的读数:数量、通过率、当前状态)从测量那天算起多少天后归档,与「多久没被读到」无关——过期数字再被读一次也不会变对。0 关闭快照过期。', en: 'Days a memory marked durability=snapshot survives before it is archived, counted from when it was measured rather than from when it was last read. A stale number does not become right by being read. 0 disables snapshot expiry.' },
287
- },
288
- {
289
- field: 'extractProvider', kind: 'text',
290
- label: { zh: '抽取提供方', en: 'Extraction provider' },
291
- hint: { zh: '抽取用的提供方路由;留空则复用该会话已记录的请求路由。', en: "Provider route for extraction. Empty reuses the session's own logged route." },
292
- },
293
- {
294
- field: 'extractModel', kind: 'text',
295
- label: { zh: '抽取模型', en: 'Extraction model' },
296
- hint: { zh: '抽取用的模型;留空则复用该会话已记录的请求路由。', en: "Model for extraction. Empty reuses the session's own logged route." },
297
- },
298
- {
299
- field: 'consolidateProvider', kind: 'text',
300
- label: { zh: '合并提供方', en: 'Consolidation provider' },
301
- hint: { zh: '合并用的提供方路由;留空则先回退到抽取路由,再回退到会话路由。', en: 'Provider route for consolidation. Empty falls back to the extraction route, then the session route.' },
302
- },
303
- {
304
- field: 'consolidateModel', kind: 'text',
305
- label: { zh: '合并模型', en: 'Consolidation model' },
306
- hint: { zh: '合并用的模型;留空则先回退到抽取路由,再回退到会话路由。', en: 'Model for consolidation. Empty falls back to the extraction route, then the session route.' },
307
- },
308
- {
309
- field: 'consolidateProposalMaxAgeHours', kind: 'number', min: 0, step: 6,
310
- label: { zh: '合并提案保鲜期(小时)', en: 'Proposal lifetime (hours)' },
311
- hint: { zh: '待确认的合并提案等多久还没被 /memories apply 或 reject,后续的自动整理才可以换一份新的。窗口内后台不重复生成(生成一次是模型调用,覆盖一个没人回答的问题没有意义);/memories consolidate 无视这个窗口。0 表示一直等你的答复。', en: 'Hours a staged consolidation proposal waits for /memories apply or reject before a background pass may replace it with a fresh one. Inside the window a pass leaves the pending question alone; /memories consolidate always proposes now. 0 keeps it until answered.' },
312
- },
313
- {
314
- field: 'enableTool', kind: 'boolean',
315
- label: { zh: '记忆工具', en: 'Memory tool' },
316
- hint: { zh: '是否注册面向模型的 memory 工具。立即生效。', en: 'Register the model-facing memory tool. Takes effect immediately.' },
317
- },
318
- {
319
- field: 'enableCommand', kind: 'boolean',
320
- label: { zh: '斜杠命令', en: 'Slash command' },
321
- hint: { zh: '是否注册 /memories 命令。立即生效。', en: 'Register the /memories command. Takes effect immediately.' },
322
- },
323
- {
324
- field: 'logLevel', kind: 'select',
325
- options: [
326
- { value: 'off', label: { zh: '不写日志', en: 'Off' } },
327
- { value: 'error', label: { zh: '仅错误', en: 'Errors' } },
328
- { value: 'warn', label: { zh: '错误 + 警告', en: 'Errors and warnings' } },
329
- { value: 'info', label: { zh: '再 + 每轮摘要(默认)', en: 'Plus pass summaries' } },
330
- { value: 'debug', label: { zh: '全部(含逐条决策)', en: 'Everything' } },
331
- ],
332
- label: { zh: '日志等级', en: 'Log level' },
333
- hint: { zh: '本插件日志文件的详细程度。默认 info:错误、警告,以及每轮抽取/合并摘要。debug 还会记录每条归档、补注、复审决策。文件路径见 /memories stats。', en: 'How much this plugin writes to its own log file. info keeps errors, warnings, and one line per pass; debug adds every retention, recall, and review decision. /memories stats prints the path.' },
334
- },
335
- {
336
- field: 'syncRemote', kind: 'text',
337
- label: { zh: '记忆库同步远端(Git)', en: 'Memory store remote (Git)' },
338
- hint: { zh: '记忆库本身就是一个 git 仓库,这里填一台私有仓库的地址(如 git@github.com:you/dsh-cross-memory-store.git),多台机器就会共用同一份记忆。留空则只在本机提交历史、不联网。写入路径只做本地提交,拉取与推送在后台按间隔进行。', en: 'The store is a git repository; point this at one private repository and every machine shares the same memories. Empty keeps local history only. Writes commit locally; fetch and push happen in the background.' },
339
- },
340
- {
341
- field: 'syncClock', kind: 'text',
342
- label: { zh: '定时同步时刻(本地时间)', en: 'Scheduled sync times (local)' },
343
- hint: { zh: '逗号分隔的 HH:MM,例如 12:05,18:05——默认在 DeepSeek 谷时开始后几分钟,冲突合并的模型调用最便宜。留空则改按下面的间隔同步。', en: 'Comma separated HH:MM, e.g. 12:05,18:05 — a few minutes after DeepSeek off-peak pricing starts, when a conflict merge costs least. Empty falls back to the interval below.' },
344
- },
345
- {
346
- field: 'syncIntervalMinutes', kind: 'number', min: 0, step: 5,
347
- label: { zh: '后台同步间隔(分钟)', en: 'Background sync interval (minutes)' },
348
- hint: { zh: '每隔这么久拉取、变基并推送一次。0 停止定时同步,只保留本地提交。', en: 'How often to fetch, rebase and push in the background. 0 stops the timer and keeps local commits only.' },
349
- },
350
- {
351
- field: 'syncDebounceSeconds', kind: 'number', min: 0, step: 1,
352
- label: { zh: '写入合并窗口(秒)', en: 'Write debounce (seconds)' },
353
- hint: { zh: '一串连续写入会在这么长时间内合并成一次提交,避免每条记忆一个 commit。真实网络动作永远不在写入路径上。', en: 'A burst of writes is folded into one commit within this window. Network work never runs on the write path.' },
354
- },
355
- {
356
- field: 'syncConflictProvider', kind: 'text',
357
- label: { zh: '冲突解析 Provider', en: 'Conflict resolver provider' },
358
- hint: { zh: '两台机器改了同一条记忆时,用来合并两次改动的模型提供方。留空回落到抽取路由;两者都没有时按 updated 取新版本,旧版本留在 git 历史里。', en: 'Provider used to merge two revisions of the same memory. Empty falls back to the extraction route; with neither, the newer updated wins and the older revision stays in git history.' },
359
- },
360
- {
361
- field: 'syncConflictModel', kind: 'text',
362
- label: { zh: '冲突解析 Model', en: 'Conflict resolver model' },
363
- hint: { zh: '合并冲突时使用的模型。留空回落到抽取模型。', en: 'Model used to merge a conflicting memory. Empty falls back to the extraction model.' },
364
- },
365
- {
366
- field: 'traceMaintenance', kind: 'boolean',
367
- label: { zh: '记录维护决策明细', en: 'Trace maintenance decisions' },
368
- hint: { zh: '把归档、按需补注、复审选择等决策提升到 info,默认等级就能看到;关闭时它们只在 debug 等级出现。', en: 'Log retention, recall, and selection decisions at info so a stock log level records them; off keeps them at debug.' },
369
- },
370
- {
371
- field: 'peakHours', kind: 'text',
372
- label: { zh: '错峰时段(避开高峰)', en: 'Peak hours to avoid' },
373
- hint: { zh: '本地时间的「高价时段」,后台抽取与合并会推迟到窗口之外;留空不限制。DeepSeek 用 "Mon-Fri 09:00-12:00, Mon-Fri 14:00-18:00"(北京时间,峰价是谷价 2 倍;周末与夜间全为谷时)。手动 /memories mine 与 consolidate 不受此限制。', en: 'Local-time windows whose tokens cost more; background extraction and consolidation are deferred out of them. Empty means no restriction. For DeepSeek use "Mon-Fri 09:00-12:00, Mon-Fri 14:00-18:00" (Beijing time; peak is double price and weekends are always off-peak). /memories mine and consolidate ignore this.' },
374
- },
375
- ]
376
-
41
+ {
42
+ field: 'maxSummaryBytes', kind: 'number', min: 0, step: 256,
43
+ label: { zh: '摘要字节上限', en: 'Summary byte budget' },
44
+ hint: { zh: '一次会话注入的记忆摘要最大字节数,默认 4096;0 表示关闭注入。', en: 'Bytes of memory summary injected once per conversation, default 4096. 0 disables injection.' },
45
+ },
46
+ {
47
+ field: 'maxSummaryEntries', kind: 'number', min: 1, step: 1,
48
+ label: { zh: '每作用域摘要条数', en: 'Summary entries per scope' },
49
+ hint: { zh: '摘要里每个作用域列出多少条记忆。', en: 'How many memories each scope lists in the summary.' },
50
+ },
51
+ {
52
+ field: 'globalSummaryEntries', kind: 'number', min: 0, step: 1,
53
+ label: { zh: '全局段摘要条数', en: 'Global entries' },
54
+ hint: { zh: '全局段最多列几条。两个作用域共用一份字节预算、全局段先渲染,不设上限时全局会吃掉项目段用不完的部分(实测某 2 条记忆的项目会话里全局占了 87%)。设为 0 则不注入全局段。', en: 'How many the GLOBAL section may list. Both scopes share one byte budget and global renders first, so without a cap it absorbs whatever the project half leaves (measured: 87% of a small project\'s summary). 0 removes the global section.' },
55
+ },
56
+ {
57
+ field: 'globalSummaryBytes', kind: 'number', min: 0, step: 100,
58
+ label: { zh: '全局段字节预算', en: 'Global bytes' },
59
+ hint: { zh: '全局段单独占多少字节(在总预算之内)。只限条数不够:中文一条约 600 字节,4 条就吃掉 4KB 的 60%,实测全局段仍占 45–81%;按字节预留才真正给项目段留出位置。设为 0 则不注入全局段。', en: 'Byte budget for the GLOBAL section, inside the total. A count cap is not enough — four Chinese entries cost ~2.6 KB of a 4 KB block, and the global half still took 45–81% until bytes were reserved. 0 removes the global section.' },
60
+ },
61
+ {
62
+ field: 'summaryFreshSlots', kind: 'number', min: 0, step: 1,
63
+ label: { zh: '新记忆保底条数', en: 'Fresh-memory slots' },
64
+ hint: { zh: '每个作用域预留几条给从未被注入过的记忆,且优先人手或模型显式写入的。作用域存满后纯按排序等于永远只展示同一批老记忆,新写的(包括用来纠正旧结论的那条)永远排不进来;设为 0 即恢复纯排序。', en: 'How many of each scope\'s entries are reserved for memories never listed before, preferring ones written deliberately over extracted ones. On a full scope pure ranking shows the same old set forever, so a correction never makes it in; 0 restores pure ranking.' },
65
+ },
66
+ {
67
+ field: 'recallMode', kind: 'select',
68
+ options: [
69
+ { value: 'once', label: { zh: '仅一次', en: 'Once' } },
70
+ { value: 'on-demand', label: { zh: '按需补充', en: 'On demand' } },
71
+ { value: 'off', label: { zh: '关闭注入', en: 'Off' } },
72
+ ],
73
+ label: { zh: '记忆注入方式', en: 'Memory injection' },
74
+ hint: { zh: 'once 只在会话开始时注入一次摘要;on-demand 额外在当前话题明显命中记忆时补一小块;off 完全关闭注入,只留记忆工具。', en: 'once injects the summary at the start of the conversation; on-demand also adds a small block when the current turn clearly matches a memory; off disables injection and leaves only the memory tool.' },
75
+ },
76
+ {
77
+ field: 'recallMinScore', kind: 'number', min: 0, step: 1,
78
+ label: { zh: '按需注入的相关度下限', en: 'Recall relevance floor' },
79
+ hint: { zh: '补注需要达到的相关度分数,是一个"更严/更松"的旋钮。真正的精度由下面「补注所需命中词数」把关:中文提问共享两个词大约得 9–12 分,所以默认 9;只共用「日志」这类一个常见词大约 8 分,因此单靠相关度是拦不住的。', en: 'Relevance a memory must reach to be injected on demand. This is a strictness knob; precision comes from the strong-term requirement below. A Chinese paraphrase sharing two bigrams scores about 9-12, and one shared common word about 8, which is why the default sits at 9.' },
80
+ },
81
+ {
82
+ field: 'recallMaxPerConversation', kind: 'number', min: 0, step: 1,
83
+ label: { zh: '每会话补注条数上限', en: 'Recalled memories per conversation' },
84
+ hint: { zh: '一个会话最多补注多少条记忆;0 关闭按需补注,只保留一次摘要。', en: 'Maximum memories injected on demand in one conversation. 0 keeps only the once-per-conversation summary.' },
85
+ },
86
+ {
87
+ field: 'recallMaxBytes', kind: 'number', min: 0, step: 100,
88
+ label: { zh: '补注字节上限', en: 'Recall block byte budget' },
89
+ hint: { zh: '单次按需补注块的字节上限,0 表示关闭按需补注。', en: 'Byte budget for one on-demand recall block. 0 disables recall deltas.' },
90
+ },
91
+ {
92
+ field: 'rawRecall', kind: 'boolean',
93
+ label: { zh: '补注带原始会话片段', en: 'Recall with original excerpts' },
94
+ hint: { zh: '开启后,按需补注块除了记忆摘要,还会附上这条记忆来源会话里的原始对话片段(已做凭据擦除、只读本机 session 日志、最多两条来源会话)。默认关闭,因为它会把别的会话的原文注入当前上下文。', en: 'Adds original conversation excerpts from the memories\' source sessions to the recall block. Credential-scrubbed, local session logs only, at most two source sessions. Off by default because it injects another session\'s prose.' },
95
+ },
96
+ {
97
+ field: 'rawRecallBytes', kind: 'number', min: 0, step: 100,
98
+ label: { zh: '原始片段字节上限', en: 'Original excerpt byte budget' },
99
+ hint: { zh: '一次补注里原始会话片段的总字节上限;0 等于关闭原始片段(即使总开关打开)。', en: 'Byte budget for the raw-excerpt half of one recall block. 0 disables excerpts even when the master switch is on.' },
100
+ },
101
+ {
102
+ field: 'rawRecallExcerpts', kind: 'number', min: 0, step: 1,
103
+ label: { zh: '原始片段条数上限', en: 'Original excerpts per recall' },
104
+ hint: { zh: '一次补注最多带几条原始片段;0 等于关闭。', en: 'Most original excerpts one recall block may carry. 0 disables them.' },
105
+ },
106
+ {
107
+ field: 'recallMinQueryChars', kind: 'number', min: 0, step: 1,
108
+ label: { zh: '触发补注的最短发问长度', en: 'Shortest turn worth recalling' },
109
+ hint: { zh: '用户消息短于该字符数时不判定补注(例如「好」「继续」),避免为无意义的回合扫描整个记忆库。', en: 'A user turn shorter than this is skipped instead of scanning the store, so bare acknowledgements cost nothing.' },
110
+ },
111
+ {
112
+ field: 'recallMinTerms', kind: 'number', min: 1, step: 1,
113
+ label: { zh: '补注所需命中词数', en: 'Strong terms required to recall' },
114
+ hint: { zh: '一条记忆要被按需补注,除了达到相关度下限,还必须在标题、别名、标签或「何时有用」里命中这么多个不同的提问词。中文提问尤其需要:只共用「插件」「日志」这类常见词不算证据,共享两个词才算。设为 1 就只按相关度打分判断(会明显更容易误补)。', en: 'Distinct query terms that must land in the title, keys, tags, or appliesTo before a memory may be recalled. This is what stops a Chinese turn from recalling everything that shares a common word; set it to 1 to gate on relevance alone.' },
115
+ },
116
+ {
117
+ field: 'injectDelta', kind: 'boolean',
118
+ label: { zh: '会后补注新记忆', en: 'Announce late memories' },
119
+ hint: { zh: '摘要注入之后才写入的记忆(例如后台抽取、合并的结果)在下一步用一个很小的块补一次:每个会话最多两次、每次 800 字节,只列新增或更新的条目。', en: 'Memories written after the summary was shown (background extraction, consolidation) get one small block on the next step: at most twice per conversation, 800 bytes each, new or updated entries only.' },
120
+ },
121
+ {
122
+ field: 'rotationEntries', kind: 'number', min: 0, step: 1,
123
+ label: { zh: '每会话轮转标题数', en: 'Rotation titles per conversation' },
124
+ hint: { zh: '摘要装不下的记忆,用一份只列标题的小块轮转:从未曝光的最先,其次是最久没出现过的,默认 16 条(12 全局 / 4 项目,硬分配)、约 1.6KB。0 关闭。它让整库在几十个会话里都能被看见,而不会永远只注入同一小批。', en: 'Memories the summary had no room for are rotated in as a title-only block: never-surfaced first, then the longest-unseen, default 16 per conversation (12 global / 4 project, hard split), about 1.6KB. 0 disables it.' },
125
+ },
126
+ {
127
+ field: 'rotationEveryTurns', kind: 'number', min: 0, step: 1,
128
+ label: { zh: '轮转间隔(用户轮次)', en: 'Rotation cadence (user turns)' },
129
+ hint: { zh: '长会话里每隔这么多轮用户发言再补一次轮转块;0 表示整个会话只补一次。默认 8:一个几小时的会话会分批看到新标题,而不是首轮之后再也不更新。', en: 'Inside one long conversation, emit a fresh rotation block every this many user turns; 0 emits only once. The default 8 lets a multi-hour session meet new titles in batches instead of freezing after its first turn.' },
130
+ },
131
+ {
132
+ field: 'reflectionEnabled', kind: 'boolean',
133
+ label: { zh: '每周反思', en: 'Weekly reflection' },
134
+ hint: { zh: '每周从记忆里综合出几条「没有哪一条记忆单独说过」的观察,比如跨项目的习惯、反复踩的坑。每条必须引用依据的记忆,否则丢弃。写成按日期归档的 markdown,不注入对话。', en: 'Once a week, synthesize observations no single memory states — cross-project habits, recurring pitfalls. Every observation must cite its evidence or it is dropped. Dated markdown files, never injected.' },
135
+ },
136
+ {
137
+ field: 'noticeGate', kind: 'boolean',
138
+ label: { zh: '没规矩的提醒先问 AI', en: 'Gate judgement notices' },
139
+ hint: { zh: '有硬规则的提醒(日报、积压、到期承诺)不过闸门。只有「没有截止日期、躺了好几天」这类需要判断的,才先问一次模型值不值得打扰——答不上来就不打扰。', en: 'Rule-based notices (digest, backlog, a passed deadline) bypass the gate. Only judgement calls — an undated promise sitting for days — go to a model first, and a failure means silence.' },
140
+ },
141
+ {
142
+ field: 'noticesEnabled', kind: 'boolean',
143
+ label: { zh: '允许它主动开口', en: 'Let it speak first' },
144
+ hint: { zh: '每天一条整理简报、待裁决积压超时提醒、到期承诺提醒,以系统通知的形式送达。关掉则只在你问的时候回答。', en: 'A daily digest, a backlog warning, and overdue-promise reminders, delivered as system notifications. Off means it only answers.' },
145
+ },
146
+ {
147
+ field: 'noticeQuietHours', kind: 'text',
148
+ label: { zh: '安静时段', en: 'Quiet hours' },
149
+ hint: { zh: '本地时间的免打扰窗口,例如 "22:00-08:00";留空表示不限制。落在窗口内的通知会顺延到窗口结束,不会丢。', en: 'Local windows when nothing is delivered, e.g. "22:00-08:00". Held notices fire when the window ends; they are not dropped.' },
150
+ },
151
+ {
152
+ field: 'personaMaxBytes', kind: 'number', min: 0, step: 100,
153
+ label: { zh: '画像块字节预算', en: 'Persona block budget' },
154
+ hint: { zh: '每会话开头注入的「关于你」块的上限。它由合并子代理从 voice=user 的记忆里维护,是整轮对话的上下文,不占记忆摘要的预算;设为 0 关闭。', en: 'Upper bound for the profile block injected once per conversation. It is maintained by the consolidation pass from voice=user memories and is turn-level context, so it does not compete with the memory summary budget. 0 disables it.' },
155
+ },
156
+ {
157
+ field: 'autoDecide', kind: 'boolean',
158
+ label: { zh: '合并争议交给 AI 裁决', en: 'Let an AI adjudicate merge disputes' },
159
+ hint: { zh: '合并里那些「只是判断、不是承诺」的变更(例如这条被读过 2 次就想退役、改写后正文变短)改由一次受限子代理裁决:它只回答"有没有丢信息",答 accept 或 reject 并给置信度。永久保留、人手写两类仍然等你(作用域不归合并改,已有记忆钉在原作用域)。关掉则全部进「待裁决」。', en: 'Changes blocked only because they are a judgement rather than a promise are adjudicated by one tool-free child that answers accept or reject with a confidence. Permanent and user-written items still wait for you; a merge never moves a memory between scopes. Off sends everything to the panel.' },
160
+ },
161
+ {
162
+ field: 'autoDecideMinConfidence', kind: 'number', min: 0, max: 1, step: 0.05,
163
+ label: { zh: 'AI 裁决的最低置信度', en: 'AI verdict confidence floor' },
164
+ hint: { zh: '低于该置信度视为「没有答案」,条目留在待裁决。', en: 'Below this the verdict counts as no answer and the item stays in the panel.' },
165
+ },
166
+ {
167
+ field: 'evidenceMaxDf', kind: 'number', min: 0, max: 1, step: 0.05,
168
+ label: { zh: '算作「常见词」的库占比', en: 'Share of the store that makes a word common' },
169
+ hint: { zh: '一个提问词若出现在该作用域超过这个比例的记忆里,就不算补注所需的「证据词」。默认 0.15 是在真实库上量出来的:只命中一个词(dsh,占 22%),把「dsh 插件 配置」这类泛问的误纳入从 37 条降到 9 条,10 条标注探针一条不变。设为 0 关闭折扣。', en: 'A query term appearing in more than this share of one scope stops counting as recall evidence. 0.15 is measured on a real store: it catches one word (dsh, 22%) and takes a generic turn from 37 admitted memories to 9 while all ten labelled probes keep their verdict. 0 disables it.' },
170
+ },
171
+ {
172
+ field: 'maxEntriesPerScope', kind: 'number', min: 1, step: 1,
173
+ label: { zh: '每作用域保留条数', en: 'Stored memories per scope' },
174
+ hint: { zh: '超过后归档最久未使用的记忆(可用 /memories restore 取回)。', en: 'Past this cap the least recently used memories are archived; /memories restore brings one back.' },
175
+ },
176
+ {
177
+ field: 'maxUnusedDays', kind: 'number', min: 0, step: 10,
178
+ label: { zh: '无用记忆归档天数', en: 'Archive unused after (days)' },
179
+ hint: { zh: '这么久没有被读到、没有被注入摘要、也不是新写的记忆会被归档(可恢复)。0 关闭归档;人手写的记忆永不归档。', en: 'Archive a memory that has not been read, surfaced, or written for this many days. Recoverable with /memories restore. 0 disables archival; memories a person wrote are never archived.' },
180
+ },
181
+ {
182
+ field: 'dedupeSimilarity', kind: 'number', min: 0, step: 0.05,
183
+ label: { zh: '近似重复合并阈值', en: 'Near-duplicate threshold' },
184
+ hint: { zh: '标题与正文词重叠超过该比例时,新记忆视为改写并取代旧记忆(0–1)。0 只保留完全相同才合并的规则。', en: 'Share of title and body words two memories must share before the newer one supersedes the older (0-1). 0 keeps only the exact-match rule.' },
185
+ },
186
+ {
187
+ field: 'sweepIntervalHours', kind: 'number', min: 0, step: 1,
188
+ label: { zh: '定期整理间隔(小时)', en: 'Maintenance sweep interval (hours)' },
189
+ hint: { zh: '每隔多久对所有工作区做一次归档整理;0 关闭定期整理(仍可用 /memories sweep 手动执行)。', en: 'How often to run retention across every workspace. 0 disables the periodic sweep; /memories sweep still runs it on demand.' },
190
+ },
191
+ {
192
+ field: 'autoExtract', kind: 'boolean',
193
+ label: { zh: '后台抽取', en: 'Background extraction' },
194
+ hint: { zh: '会话空闲后从最近对话里抽取值得长期保留的事实。', en: 'Mine finished sessions for durable facts once they have been idle.' },
195
+ },
196
+ {
197
+ field: 'autoExtractIdleMs', kind: 'number', min: 1000, step: 1000,
198
+ label: { zh: '抽取前空闲时长(毫秒)', en: 'Idle before extraction (ms)' },
199
+ hint: { zh: '会话需空闲多久才开始挖掘。', en: 'How long a session must stay idle before it is mined.' },
200
+ },
201
+ {
202
+ field: 'extractWindowMessages', kind: 'number', min: 1, step: 1,
203
+ label: { zh: '抽取窗口(条消息)', en: 'Extraction window (messages)' },
204
+ hint: { zh: '一次抽取最多读最近多少条对话消息。配合「周期性抽取间隔」使用:按一个间隔的增量来定,而不是按整段会话。', en: 'How many recent conversation messages one extraction reads. Size it for one periodic interval, not for a whole conversation.' },
205
+ },
206
+ {
207
+ field: 'extractMaxInputChars', kind: 'number', min: 1, step: 1000,
208
+ label: { zh: '抽取输入预算(字符)', en: 'Extraction input budget (chars)' },
209
+ hint: { zh: '交给抽取器的对话文本字符上限。', en: 'Character budget for the transcript handed to the extractor.' },
210
+ },
211
+ {
212
+ field: 'extractMaxOutputTokens', kind: 'number', min: 1, step: 128,
213
+ label: { zh: '抽取输出 token 上限', en: 'Extraction output tokens' },
214
+ hint: { zh: '一次抽取调用的输出 token 上限。', en: 'Output token cap for one extraction call.' },
215
+ },
216
+ {
217
+ field: 'extractTimeoutMs', kind: 'number', min: 1000, step: 5000,
218
+ label: { zh: '抽取超时(毫秒)', en: 'Extraction timeout (ms)' },
219
+ hint: { zh: '一次抽取调用的超时时间。', en: 'Timeout for one extraction call.' },
220
+ },
221
+ {
222
+ field: 'extractMaxMemories', kind: 'number', min: 1, step: 1,
223
+ label: { zh: '每次抽取条数上限', en: 'Memories per extraction' },
224
+ hint: { zh: '一次抽取最多写入多少条记忆。', en: 'Maximum memories one extraction pass may store.' },
225
+ },
226
+ {
227
+ field: 'extractIntervalMinutes', kind: 'number', min: 0, step: 5,
228
+ label: { zh: '周期性抽取间隔(分钟)', en: 'Periodic extraction interval (minutes)' },
229
+ hint: { zh: '每隔这么久检查一次所有打开的会话,只要有新内容且会话当时空闲就抽一段——长会话因此不会因为「只在停止输入后抽一次」而丢掉中间的内容。没有新内容时不产生模型调用;仍受错峰时段与额度闸门限制。0 关闭周期检查。', en: 'How often to check every open session and mine a slice when there is new material and the session is momentarily idle — so a long working session does not lose its middle to a single end-of-session pass. A session with nothing new costs no model call; peak hours and the quota gate still apply. 0 disables the check.' },
230
+ },
231
+ {
232
+ field: 'minIdleHours', kind: 'number', min: 0, step: 0.5,
233
+ label: { zh: '挖掘前最短空闲(小时)', en: 'Minimum idle before mining (hours)' },
234
+ hint: { zh: '会话至少要空闲这么久才会被挖掘,可填小数(0.5 = 半小时);实际等待取它与「抽取前空闲时长」的较大者。0 关闭该闸门。', en: 'A session must have been idle at least this long before it is mined. Fractions are allowed (0.5 = half an hour); the effective wait is the larger of this and the idle delay above. 0 disables the gate.' },
235
+ },
236
+ {
237
+ field: 'maxAgeDays', kind: 'number', min: 0, step: 1,
238
+ label: { zh: '超过天数不再挖掘(天)', en: 'Never mine sessions older than (days)' },
239
+ hint: { zh: '最后活动早于该天数的会话永不挖掘,0 关闭该闸门。', en: 'Sessions whose last activity is older than this are never mined. 0 disables the gate.' },
240
+ },
241
+ {
242
+ field: 'maxSessionsPerPass', kind: 'number', min: 1, step: 1,
243
+ label: { zh: '每次挖掘的会话数', en: 'Sessions per pass' },
244
+ hint: { zh: '一次抽取最多挖掘多少个会话,新的优先。', en: 'How many sessions one extraction pass may mine, newest first.' },
245
+ },
246
+ {
247
+ field: 'consolidate', kind: 'boolean',
248
+ label: { zh: '合并重整', en: 'Consolidation pass' },
249
+ hint: { zh: '新记忆落盘后,用一个受限子代理合并、改写并相互协调。', en: 'After new memories land, merge and reconcile them through a restricted sub-agent.' },
250
+ },
251
+ {
252
+ field: 'consolidateCooldownHours', kind: 'number', min: 0, step: 1,
253
+ label: { zh: '合并冷却(小时)', en: 'Consolidation cooldown (hours)' },
254
+ hint: { zh: '两次合并之间的最短小时数,约束后台额度消耗。', en: 'Minimum hours between consolidation passes; bounds background quota use.' },
255
+ },
256
+ {
257
+ field: 'consolidateMaxEntries', kind: 'number', min: 1, step: 8,
258
+ label: { zh: '每次合并条目上限', en: 'Memories per consolidation' },
259
+ hint: { zh: '一次合并最多考虑多少条记忆。', en: 'How many memories one consolidation pass may consider.' },
260
+ },
261
+ {
262
+ field: 'consolidateTimeoutMs', kind: 'number', min: 1000, step: 10000,
263
+ label: { zh: '合并超时(毫秒)', en: 'Consolidation timeout (ms)' },
264
+ hint: { zh: '一次合并子代理运行的超时时间。', en: 'Timeout for one consolidation sub-agent run.' },
265
+ },
266
+ {
267
+ field: 'pauseOnQuotaError', kind: 'boolean',
268
+ label: { zh: '额度紧张时暂停后台', en: 'Pause background work on quota errors' },
269
+ hint: { zh: '提供方因限流或额度耗尽拒绝后,暂停后台抽取与合并,直到冷却结束。', en: 'After a rate-limit or exhausted-quota refusal, stop background extraction and consolidation until the cooldown elapses.' },
270
+ },
271
+ {
272
+ field: 'quotaCooldownMinutes', kind: 'number', min: 0, step: 5,
273
+ label: { zh: '额度冷却(分钟)', en: 'Quota cooldown (minutes)' },
274
+ hint: { zh: '一次拒绝后等待多久;连续拒绝会翻倍。0 表示不暂停。', en: 'Wait after one refusal; doubles per consecutive refusal. 0 disables the pause.' },
275
+ },
276
+ {
277
+ field: 'quotaCooldownMaxMinutes', kind: 'number', min: 0, step: 30,
278
+ label: { zh: '额度冷却上限(分钟)', en: 'Quota cooldown ceiling (minutes)' },
279
+ hint: { zh: '上面那个等待翻倍后的上限。', en: 'Upper bound as the wait doubles.' },
280
+ },
281
+ {
282
+ field: 'snapshotMaxAgeDays', kind: 'number', min: 0, step: 10,
283
+ label: { zh: '快照记忆保留天数', en: 'Snapshot lifetime (days)' },
284
+ hint: { zh: '标记为「快照」的记忆(某个时刻的读数:数量、通过率、当前状态)从测量那天算起多少天后归档,与「多久没被读到」无关——过期数字再被读一次也不会变对。0 关闭快照过期。', en: 'Days a memory marked durability=snapshot survives before it is archived, counted from when it was measured rather than from when it was last read. A stale number does not become right by being read. 0 disables snapshot expiry.' },
285
+ },
286
+ {
287
+ field: 'extractProvider', kind: 'text',
288
+ label: { zh: '抽取提供方', en: 'Extraction provider' },
289
+ hint: { zh: '抽取用的提供方路由;留空则复用该会话已记录的请求路由。', en: "Provider route for extraction. Empty reuses the session's own logged route." },
290
+ },
291
+ {
292
+ field: 'extractModel', kind: 'text',
293
+ label: { zh: '抽取模型', en: 'Extraction model' },
294
+ hint: { zh: '抽取用的模型;留空则复用该会话已记录的请求路由。', en: "Model for extraction. Empty reuses the session's own logged route." },
295
+ },
296
+ {
297
+ field: 'consolidateProvider', kind: 'text',
298
+ label: { zh: '合并提供方', en: 'Consolidation provider' },
299
+ hint: { zh: '合并用的提供方路由;留空则先回退到抽取路由,再回退到会话路由。', en: 'Provider route for consolidation. Empty falls back to the extraction route, then the session route.' },
300
+ },
301
+ {
302
+ field: 'consolidateModel', kind: 'text',
303
+ label: { zh: '合并模型', en: 'Consolidation model' },
304
+ hint: { zh: '合并用的模型;留空则先回退到抽取路由,再回退到会话路由。', en: 'Model for consolidation. Empty falls back to the extraction route, then the session route.' },
305
+ },
306
+ {
307
+ field: 'consolidateProposalMaxAgeHours', kind: 'number', min: 0, step: 6,
308
+ label: { zh: '合并提案保鲜期(小时)', en: 'Proposal lifetime (hours)' },
309
+ hint: { zh: '待确认的合并提案等多久还没被 /memories apply 或 reject,后续的自动整理才可以换一份新的。窗口内后台不重复生成(生成一次是模型调用,覆盖一个没人回答的问题没有意义);/memories consolidate 无视这个窗口。0 表示一直等你的答复。', en: 'Hours a staged consolidation proposal waits for /memories apply or reject before a background pass may replace it with a fresh one. Inside the window a pass leaves the pending question alone; /memories consolidate always proposes now. 0 keeps it until answered.' },
310
+ },
311
+ {
312
+ field: 'enableTool', kind: 'boolean',
313
+ label: { zh: '记忆工具', en: 'Memory tool' },
314
+ hint: { zh: '是否注册面向模型的 memory 工具。立即生效。', en: 'Register the model-facing memory tool. Takes effect immediately.' },
315
+ },
316
+ {
317
+ field: 'enableCommand', kind: 'boolean',
318
+ label: { zh: '斜杠命令', en: 'Slash command' },
319
+ hint: { zh: '是否注册 /memories 命令。立即生效。', en: 'Register the /memories command. Takes effect immediately.' },
320
+ },
321
+ {
322
+ field: 'logLevel', kind: 'select',
323
+ options: [
324
+ { value: 'off', label: { zh: '不写日志', en: 'Off' } },
325
+ { value: 'error', label: { zh: '仅错误', en: 'Errors' } },
326
+ { value: 'warn', label: { zh: '错误 + 警告', en: 'Errors and warnings' } },
327
+ { value: 'info', label: { zh: '再 + 每轮摘要(默认)', en: 'Plus pass summaries' } },
328
+ { value: 'debug', label: { zh: '全部(含逐条决策)', en: 'Everything' } },
329
+ ],
330
+ label: { zh: '日志等级', en: 'Log level' },
331
+ hint: { zh: '本插件日志文件的详细程度。默认 info:错误、警告,以及每轮抽取/合并摘要。debug 还会记录每条归档、补注、复审决策。文件路径见 /memories stats。', en: 'How much this plugin writes to its own log file. info keeps errors, warnings, and one line per pass; debug adds every retention, recall, and review decision. /memories stats prints the path.' },
332
+ },
333
+ {
334
+ field: 'syncRemote', kind: 'text',
335
+ label: { zh: '记忆库同步远端(Git)', en: 'Memory store remote (Git)' },
336
+ hint: { zh: '记忆库本身就是一个 git 仓库,这里填一台私有仓库的地址(如 git@github.com:you/dsh-cross-memory-store.git),多台机器就会共用同一份记忆。留空则只在本机提交历史、不联网。写入路径只做本地提交,拉取与推送在后台按间隔进行。', en: 'The store is a git repository; point this at one private repository and every machine shares the same memories. Empty keeps local history only. Writes commit locally; fetch and push happen in the background.' },
337
+ },
338
+ {
339
+ field: 'syncClock', kind: 'text',
340
+ label: { zh: '定时同步时刻(本地时间)', en: 'Scheduled sync times (local)' },
341
+ hint: { zh: '逗号分隔的 HH:MM,例如 12:05,18:05——默认在 DeepSeek 谷时开始后几分钟,冲突合并的模型调用最便宜。留空则改按下面的间隔同步。', en: 'Comma separated HH:MM, e.g. 12:05,18:05 — a few minutes after DeepSeek off-peak pricing starts, when a conflict merge costs least. Empty falls back to the interval below.' },
342
+ },
343
+ {
344
+ field: 'syncIntervalMinutes', kind: 'number', min: 0, step: 5,
345
+ label: { zh: '后台同步间隔(分钟)', en: 'Background sync interval (minutes)' },
346
+ hint: { zh: '每隔这么久拉取、变基并推送一次。0 停止定时同步,只保留本地提交。', en: 'How often to fetch, rebase and push in the background. 0 stops the timer and keeps local commits only.' },
347
+ },
348
+ {
349
+ field: 'syncDebounceSeconds', kind: 'number', min: 0, step: 1,
350
+ label: { zh: '写入合并窗口(秒)', en: 'Write debounce (seconds)' },
351
+ hint: { zh: '一串连续写入会在这么长时间内合并成一次提交,避免每条记忆一个 commit。真实网络动作永远不在写入路径上。', en: 'A burst of writes is folded into one commit within this window. Network work never runs on the write path.' },
352
+ },
353
+ {
354
+ field: 'syncConflictProvider', kind: 'text',
355
+ label: { zh: '冲突解析 Provider', en: 'Conflict resolver provider' },
356
+ hint: { zh: '两台机器改了同一条记忆时,用来合并两次改动的模型提供方。留空回落到抽取路由;两者都没有时按 updated 取新版本,旧版本留在 git 历史里。', en: 'Provider used to merge two revisions of the same memory. Empty falls back to the extraction route; with neither, the newer updated wins and the older revision stays in git history.' },
357
+ },
358
+ {
359
+ field: 'syncConflictModel', kind: 'text',
360
+ label: { zh: '冲突解析 Model', en: 'Conflict resolver model' },
361
+ hint: { zh: '合并冲突时使用的模型。留空回落到抽取模型。', en: 'Model used to merge a conflicting memory. Empty falls back to the extraction model.' },
362
+ },
363
+ {
364
+ field: 'traceMaintenance', kind: 'boolean',
365
+ label: { zh: '记录维护决策明细', en: 'Trace maintenance decisions' },
366
+ hint: { zh: '把归档、按需补注、复审选择等决策提升到 info,默认等级就能看到;关闭时它们只在 debug 等级出现。', en: 'Log retention, recall, and selection decisions at info so a stock log level records them; off keeps them at debug.' },
367
+ },
368
+ {
369
+ field: 'peakHours', kind: 'text',
370
+ label: { zh: '错峰时段(避开高峰)', en: 'Peak hours to avoid' },
371
+ hint: { zh: '本地时间的「高价时段」,后台抽取与合并会推迟到窗口之外;留空不限制。DeepSeek 用 "Mon-Fri 09:00-12:00, Mon-Fri 14:00-18:00"(北京时间,峰价是谷价 2 倍;周末与夜间全为谷时)。手动 /memories mine 与 consolidate 不受此限制。', en: 'Local-time windows whose tokens cost more; background extraction and consolidation are deferred out of them. Empty means no restriction. For DeepSeek use "Mon-Fri 09:00-12:00, Mon-Fri 14:00-18:00" (Beijing time; peak is double price and weekends are always off-peak). /memories mine and consolidate ignore this.' },
372
+ },
373
+ ];
377
374
  /** Whether the user layer carries an override for one field. */
378
375
  function isOverridden(snapshot, field) {
379
- const user = snapshot.user
380
- return typeof user === 'object' && user !== null && Object.prototype.hasOwnProperty.call(user, field)
376
+ const user = snapshot.user;
377
+ return typeof user === 'object' && user !== null && Object.prototype.hasOwnProperty.call(user, field);
381
378
  }
382
-
383
379
  /** Pick one field's label/hint for the active locale. */
384
380
  function fieldText(field, lang) {
385
- return {
386
- label: field.label[lang] ?? field.label.zh,
387
- hint: field.hint[lang] ?? field.hint.zh,
388
- }
381
+ return {
382
+ label: field.label[lang] ?? field.label.zh,
383
+ hint: field.hint[lang] ?? field.hint.zh,
384
+ };
389
385
  }
390
-
391
386
  /** Render one row: label + hint on the left, control on the right. */
392
387
  function renderRow(React, field, snapshot, draft, onEdit, lang, copy) {
393
- const text = fieldText(field, lang)
394
- const current = draft !== undefined ? draft : snapshot.value === undefined ? undefined : snapshot.value[field.field]
395
- const disabled = snapshot.writable !== true || snapshot.status !== 'ready'
396
- const controls = []
397
- if (field.kind === 'boolean') {
398
- controls.push(React.createElement('input', {
399
- key: 'input',
400
- className: 'dshm-check',
401
- type: 'checkbox',
402
- checked: current === true,
403
- disabled,
404
- onChange: (event) => onEdit(field.field, event.target.checked),
405
- }))
406
- } else if (field.kind === 'select') {
407
- controls.push(React.createElement('select', {
408
- key: 'input',
409
- className: 'dshm-input',
410
- value: current === undefined || current === null ? '' : String(current),
411
- disabled,
412
- onChange: (event) => onEdit(field.field, event.target.value),
413
- }, (field.options ?? []).map((option) => React.createElement('option', {
414
- key: option.value,
415
- value: option.value,
416
- }, option.label[lang] ?? option.label.zh))))
417
- } else {
418
- controls.push(React.createElement('input', {
419
- key: 'input',
420
- className: 'dshm-input',
421
- type: field.kind === 'number' ? 'number' : 'text',
422
- value: current === undefined || current === null ? '' : String(current),
423
- min: field.min,
424
- step: field.step,
425
- disabled,
426
- onChange: (event) => onEdit(field.field, event.target.value),
427
- }))
428
- }
429
- if (!disabled && isOverridden(snapshot, field.field)) {
430
- controls.push(React.createElement('button', {
431
- key: 'reset',
432
- className: 'dshm-reset',
433
- type: 'button',
434
- title: copy.reset,
435
- onClick: () => onEdit(field.field, undefined),
436
- }, copy.reset))
437
- }
438
- return React.createElement('div', { key: field.field, className: 'dshm-row' }, [
439
- React.createElement('div', { key: 'label', className: 'dshm-label' }, [
440
- React.createElement('span', { key: 'name' }, text.label),
441
- React.createElement('span', { key: 'hint', className: 'dshm-hint' }, text.hint),
442
- ]),
443
- React.createElement('div', { key: 'control', className: 'dshm-control' }, controls),
444
- ])
388
+ const text = fieldText(field, lang);
389
+ const current = draft !== undefined ? draft : snapshot.value === undefined ? undefined : snapshot.value[field.field];
390
+ const disabled = snapshot.writable !== true || snapshot.status !== 'ready';
391
+ const controls = [];
392
+ if (field.kind === 'boolean') {
393
+ controls.push(React.createElement('input', {
394
+ key: 'input',
395
+ className: 'dshm-check',
396
+ type: 'checkbox',
397
+ checked: current === true,
398
+ disabled,
399
+ onChange: (event) => onEdit(field.field, event.target.checked),
400
+ }));
401
+ }
402
+ else if (field.kind === 'select') {
403
+ controls.push(React.createElement('select', {
404
+ key: 'input',
405
+ className: 'dshm-input',
406
+ value: current === undefined || current === null ? '' : String(current),
407
+ disabled,
408
+ onChange: (event) => onEdit(field.field, event.target.value),
409
+ }, (field.options ?? []).map((option) => React.createElement('option', {
410
+ key: option.value,
411
+ value: option.value,
412
+ }, option.label[lang] ?? option.label.zh))));
413
+ }
414
+ else {
415
+ controls.push(React.createElement('input', {
416
+ key: 'input',
417
+ className: 'dshm-input',
418
+ type: field.kind === 'number' ? 'number' : 'text',
419
+ value: current === undefined || current === null ? '' : String(current),
420
+ min: field.min,
421
+ step: field.step,
422
+ disabled,
423
+ onChange: (event) => onEdit(field.field, event.target.value),
424
+ }));
425
+ }
426
+ if (!disabled && isOverridden(snapshot, field.field)) {
427
+ controls.push(React.createElement('button', {
428
+ key: 'reset',
429
+ className: 'dshm-reset',
430
+ type: 'button',
431
+ title: copy.reset,
432
+ onClick: () => onEdit(field.field, undefined),
433
+ }, copy.reset));
434
+ }
435
+ return React.createElement('div', { key: field.field, className: 'dshm-row' }, [
436
+ React.createElement('div', { key: 'label', className: 'dshm-label' }, [
437
+ React.createElement('span', { key: 'name' }, text.label),
438
+ React.createElement('span', { key: 'hint', className: 'dshm-hint' }, text.hint),
439
+ ]),
440
+ React.createElement('div', { key: 'control', className: 'dshm-control' }, controls),
441
+ ]);
445
442
  }
446
-
447
443
  /**
448
444
  * Build the card component.
449
445
  *
@@ -457,60 +453,56 @@ window.__ModuleLoader__.load({
457
453
  * @returns the card component.
458
454
  */
459
455
  function createMemoriesCard(React) {
460
- return function MemoriesCard(props) {
461
- const scope = props.scope
462
- const snapshot = props.useSnapshot((value) => value)
463
- const lang = props.lang ?? 'zh'
464
- const copy = props.copy ?? CARD_COPY[lang]
465
- const [error, setError] = React.useState(null)
466
- const [saved, setSaved] = React.useState(false)
467
- const [pending, setPending] = React.useState({})
468
-
469
- const settle = (field) => {
470
- setPending((previous) => {
471
- const next = { ...previous }
472
- delete next[field]
473
- return next
474
- })
475
- }
476
-
477
- const onEdit = (field, value) => {
478
- setError(null)
479
- setSaved(false)
480
- setPending((previous) => ({ ...previous, [field]: value }))
481
- const operation = value === undefined ? scope.unset(field) : scope.set(field, value)
482
- Promise.resolve(operation).then(
483
- () => { settle(field); setSaved(true) },
484
- (failure) => { settle(field); setError(failure instanceof Error ? failure.message : String(failure)) },
485
- )
486
- }
487
-
488
- const statusLine = error !== null
489
- ? React.createElement('p', { key: 'status', className: 'dshm-status dshm-error' }, error)
490
- : saved
491
- ? React.createElement('p', { key: 'status', className: 'dshm-status dshm-ok' }, copy.saved)
492
- : null
493
-
494
- const children = [
495
- React.createElement('div', { key: 'head', className: 'dshm-head' }, [
496
- React.createElement('h3', { key: 'title', className: 'dshm-title' }, props.title ?? NS),
497
- React.createElement('span', { key: 'ns', className: 'dshm-ns' }, NS),
498
- ]),
499
- ]
500
- if (props.intro !== false) {
501
- children.push(React.createElement('p', { key: 'intro', className: 'dshm-intro' },
502
- props.intro ?? '跨会话记忆:项目作用域由本工作区所有会话共享,全局作用域由所有项目共享。'))
503
- }
504
- if (snapshot.status === 'unavailable') {
505
- children.push(React.createElement('p', { key: 'unavailable', className: 'dshm-status dshm-error' }, copy.unavailable))
506
- }
507
- for (const field of FIELDS) children.push(renderRow(React, field, snapshot, pending[field.field], onEdit, lang, copy))
508
- if (statusLine !== null) children.push(statusLine)
509
- children.push(React.createElement('p', { key: 'note', className: 'dshm-note' }, copy.note))
510
- return React.createElement('section', { className: 'dshm-card' }, children)
511
- }
456
+ return function MemoriesCard(props) {
457
+ const scope = props.scope;
458
+ const snapshot = props.useSnapshot((value) => value);
459
+ const lang = props.lang ?? 'zh';
460
+ const copy = props.copy ?? CARD_COPY[lang];
461
+ const [error, setError] = React.useState(null);
462
+ const [saved, setSaved] = React.useState(false);
463
+ const [pending, setPending] = React.useState({});
464
+ const settle = (field) => {
465
+ setPending((previous) => {
466
+ const next = { ...previous };
467
+ delete next[field];
468
+ return next;
469
+ });
470
+ };
471
+ const onEdit = (field, value) => {
472
+ setError(null);
473
+ setSaved(false);
474
+ setPending((previous) => ({ ...previous, [field]: value }));
475
+ const operation = value === undefined ? scope.unset(field) : scope.set(field, value);
476
+ Promise.resolve(operation).then(() => { settle(field); setSaved(true); }, (failure) => { settle(field); setError(failure instanceof Error ? failure.message : String(failure)); });
477
+ };
478
+ const statusLine = error !== null
479
+ ? React.createElement('p', { key: 'status', className: 'dshm-status dshm-error' }, error)
480
+ : saved
481
+ ? React.createElement('p', { key: 'status', className: 'dshm-status dshm-ok' }, copy.saved)
482
+ : null;
483
+ const children = [
484
+ React.createElement('div', { key: 'head', className: 'dshm-head' }, [
485
+ React.createElement('h3', { key: 'title', className: 'dshm-title' }, props.title ?? NS),
486
+ React.createElement('span', { key: 'ns', className: 'dshm-ns' }, NS),
487
+ ]),
488
+ ];
489
+ if (props.intro !== false) {
490
+ children.push(React.createElement('p', { key: 'intro', className: 'dshm-intro' }, props.intro ?? '跨会话记忆:项目作用域由本工作区所有会话共享,全局作用域由所有项目共享。'));
491
+ }
492
+ if (snapshot.status === 'unavailable') {
493
+ children.push(React.createElement('p', { key: 'unavailable', className: 'dshm-status dshm-error' }, copy.unavailable));
494
+ }
495
+ for (const field of FIELDS)
496
+ children.push(renderRow(React, field, snapshot, pending[field.field], onEdit, lang, copy));
497
+ if (statusLine !== null)
498
+ children.push(statusLine);
499
+ children.push(React.createElement('p', { key: 'note', className: 'dshm-note' }, copy.note));
500
+ return React.createElement('section', { className: 'dshm-card' }, children);
501
+ };
512
502
  }
513
- // ---- client/remote.js ----
503
+
504
+ // ---- .client-build/parts/remote.js ----
505
+ "use strict";
514
506
  /**
515
507
  * Browser half of the Host→browser Remote seam.
516
508
  *
@@ -528,45 +520,41 @@ window.__ModuleLoader__.load({
528
520
  * replaced the older `schema.parse` field in 0.1.6-alpha.2), so the browser
529
521
  * codec exposes the same pass-through parser through that factory.
530
522
  */
531
-
532
523
  /** npm package owning the Remote methods. */
533
- const REMOTE_PACKAGE = 'dsh-cross-memory'
524
+ const REMOTE_PACKAGE = 'dsh-cross-memory';
534
525
  /** Wire namespace, and the service key the gateway installs it under. */
535
- const REMOTE_NAMESPACE = 'memories'
526
+ const REMOTE_NAMESPACE = 'memories';
536
527
  /** Full Cordis key of the namespace service. */
537
- const REMOTE_SERVICE_KEY = `remote.${REMOTE_NAMESPACE}`
538
-
528
+ const REMOTE_SERVICE_KEY = `remote.${REMOTE_NAMESPACE}`;
539
529
  /** Build the browser-side codec for one shape. */
540
530
  function clientCodec(shape) {
541
- return {
542
- mode: 'strict',
543
- typeSymbol: `${REMOTE_PACKAGE}#${shape}`,
544
- create: () => ({ parse: (value) => value }),
545
- }
531
+ return {
532
+ mode: 'strict',
533
+ typeSymbol: `${REMOTE_PACKAGE}#${shape}`,
534
+ create: () => ({ parse: (value) => value }),
535
+ };
546
536
  }
547
-
548
537
  /** Expand the injected wire table into a client Remote contribution. */
549
538
  function clientContribution() {
550
- return {
551
- package: REMOTE_PACKAGE,
552
- descriptors: REMOTE_INVOCATION_DATA.map((invocation) => ({
553
- id: `${REMOTE_PACKAGE}#${REMOTE_NAMESPACE}/${invocation.method}`,
554
- service: REMOTE_NAMESPACE,
555
- namespace: REMOTE_NAMESPACE,
556
- method: invocation.method,
557
- invocation: { kind: 'direct' },
558
- parameters: invocation.parameters.map((parameter) => ({
559
- name: parameter.name,
560
- wire: parameter.wire,
561
- source: 'json',
562
- codec: clientCodec(parameter.shape),
563
- ...(parameter.optional === true ? { acceptsUndefined: true } : {}),
564
- })),
565
- result: clientCodec(invocation.result),
566
- })),
567
- }
539
+ return {
540
+ package: REMOTE_PACKAGE,
541
+ descriptors: REMOTE_INVOCATION_DATA.map((invocation) => ({
542
+ id: `${REMOTE_PACKAGE}#${REMOTE_NAMESPACE}/${invocation.method}`,
543
+ service: REMOTE_NAMESPACE,
544
+ namespace: REMOTE_NAMESPACE,
545
+ method: invocation.method,
546
+ invocation: { kind: 'direct' },
547
+ parameters: invocation.parameters.map((parameter) => ({
548
+ name: parameter.name,
549
+ wire: parameter.wire,
550
+ source: 'json',
551
+ codec: clientCodec(parameter.shape),
552
+ ...(parameter.optional === true ? { acceptsUndefined: true } : {}),
553
+ })),
554
+ result: clientCodec(invocation.result),
555
+ })),
556
+ };
568
557
  }
569
-
570
558
  /**
571
559
  * Unwrap one RemoteResult.
572
560
  *
@@ -579,15 +567,16 @@ window.__ModuleLoader__.load({
579
567
  * @returns the business value.
580
568
  */
581
569
  function unwrapRemote(endpoint, result) {
582
- if (result === null || typeof result !== 'object') {
583
- throw new Error(`dsh-cross-memory: ${endpoint} returned no result`)
584
- }
585
- if (result.ok === true) return result.value
586
- const failure = result.error
587
- if (failure instanceof Error) throw failure
588
- throw new Error(typeof failure?.message === 'string' ? failure.message : `dsh-cross-memory: ${endpoint} failed`)
570
+ if (result === null || typeof result !== 'object') {
571
+ throw new Error(`dsh-cross-memory: ${endpoint} returned no result`);
572
+ }
573
+ if (result.ok === true)
574
+ return result.value;
575
+ const failure = result.error;
576
+ if (failure instanceof Error)
577
+ throw failure;
578
+ throw new Error(typeof failure?.message === 'string' ? failure.message : `dsh-cross-memory: ${endpoint} failed`);
589
579
  }
590
-
591
580
  /**
592
581
  * Mount the contribution and resolve the namespace service.
593
582
  *
@@ -601,37 +590,40 @@ window.__ModuleLoader__.load({
601
590
  * deployment composes no gateway.
602
591
  */
603
592
  async function mountMemoriesRemote(ctx) {
604
- const remote = ctx.get('remote') ?? ctx.remote
605
- if (remote === undefined || typeof remote.$mount !== 'function') return undefined
606
- const dispose = await remote.$mount(clientContribution())
607
- ctx.effect(() => () => { void dispose() }, 'dsh-cross-memory: remote contribution')
608
- const namespace = ctx.get(REMOTE_SERVICE_KEY)
609
- if (namespace === undefined) return undefined
610
- const api = {}
611
- for (const invocation of REMOTE_INVOCATION_DATA) {
612
- api[invocation.method] = async (args) => {
613
- // The gateway takes one positional value per descriptor parameter and
614
- // rejects any other count, so the call is mapped by the descriptor's own
615
- // order. A missing optional value arrives as `undefined`, which the
616
- // gateway omits from the wire fields and the host's `acceptsUndefined`
617
- // descriptor allows.
618
- const supplied = args ?? {}
619
- // A positional call (`api.resolveDispute(id, decision)` spread over two
620
- // arguments) would otherwise reach the host as an empty field set and come
621
- // back as a gateway complaint — or, for a handler that swallows it, as a
622
- // dead button. Fail here instead, where the mistake actually is.
623
- if (invocation.parameters.length > 0 && (typeof supplied !== 'object' || Array.isArray(supplied))) {
624
- throw new Error(`dsh-cross-memory: ${invocation.method} takes one object keyed by its parameter names (${invocation.parameters.map((parameter) => parameter.name).join(', ')})`)
625
- }
626
- const values = invocation.parameters.map((parameter) => supplied[parameter.name])
627
- const result = await namespace[invocation.method](...values)
628
- return unwrapRemote(invocation.method, result)
593
+ const remote = ctx.get('remote') ?? ctx.remote;
594
+ if (remote === undefined || typeof remote.$mount !== 'function')
595
+ return undefined;
596
+ const dispose = await remote.$mount(clientContribution());
597
+ ctx.effect(() => () => { void dispose(); }, 'dsh-cross-memory: remote contribution');
598
+ const namespace = ctx.get(REMOTE_SERVICE_KEY);
599
+ if (namespace === undefined)
600
+ return undefined;
601
+ const api = {};
602
+ for (const invocation of REMOTE_INVOCATION_DATA) {
603
+ api[invocation.method] = async (args) => {
604
+ // The gateway takes one positional value per descriptor parameter and
605
+ // rejects any other count, so the call is mapped by the descriptor's own
606
+ // order. A missing optional value arrives as `undefined`, which the
607
+ // gateway omits from the wire fields and the host's `acceptsUndefined`
608
+ // descriptor allows.
609
+ const supplied = args ?? {};
610
+ // A positional call (`api.resolveDispute(id, decision)` spread over two
611
+ // arguments) would otherwise reach the host as an empty field set and come
612
+ // back as a gateway complaint — or, for a handler that swallows it, as a
613
+ // dead button. Fail here instead, where the mistake actually is.
614
+ if (invocation.parameters.length > 0 && (typeof supplied !== 'object' || Array.isArray(supplied))) {
615
+ throw new Error(`dsh-cross-memory: ${invocation.method} takes one object keyed by its parameter names (${invocation.parameters.map((parameter) => parameter.name).join(', ')})`);
616
+ }
617
+ const values = invocation.parameters.map((parameter) => supplied[parameter.name]);
618
+ const result = await namespace[invocation.method](...values);
619
+ return unwrapRemote(invocation.method, result);
620
+ };
629
621
  }
630
- }
631
- return api
622
+ return api;
632
623
  }
633
624
 
634
- // ---- client/section.js ----
625
+ // ---- .client-build/parts/section.js ----
626
+ "use strict";
635
627
  /**
636
628
  * The Memories settings page: one `settings.section` contribution.
637
629
  *
@@ -642,129 +634,125 @@ window.__ModuleLoader__.load({
642
634
  * this entry's own config form, so this page reads one store and one config and
643
635
  * never a private route.
644
636
  */
645
-
646
637
  /** Every string the page renders, per locale. */
647
638
  const SECTION_COPY = {
648
- zh: {
649
- lang: 'zh',
650
- label: '记忆',
651
- title: '记忆',
652
- intro: '跨会话记忆:全局库对所有项目生效,项目库只对同一个工作区生效。这里可以查看、搜索、新增和删除记忆。',
653
- store: '存储位置',
654
- global: '全局',
655
- project: '项目',
656
- unit: '条',
657
- search: '搜索记忆…',
658
- allScopes: '全部范围',
659
- allKinds: '全部类型',
660
- kindLabels: { preference: '偏好', failure: '失败教训', procedure: '流程', knowledge: '经验', fact: '事实' },
661
- empty: '没有匹配的记忆。',
662
- loading: '加载中…',
663
- forget: '删除',
664
- confirm: '删除这条记忆?',
665
- add: '新增记忆',
666
- cancel: '取消',
667
- save: '保存',
668
- titlePlaceholder: '标题:一行说清这条记忆',
669
- bodyPlaceholder: '正文:1-4 句话',
670
- tagsPlaceholder: '标签,逗号分隔(可选)',
671
- drafts: '待提升的 skill 草稿',
672
- promote: '提升到技能目录',
673
- discard: '丢弃',
674
- promoted: '已提升',
675
- tunables: '配置项',
676
- tabMemories: '记忆',
677
- tabPersona: '画像',
678
- tabConfig: '配置',
679
- tabDisputes: '待裁决',
680
- disputesTitle: '合并时需要你拍板的事',
681
- disputesIntro: '后台合并会自动执行可逆的改动(合并重复、收紧措辞、退役从没被读过的条目)。只有下面这些会伤到内容,才留给你决定——接受就按它改,驳回就原样保留,不动它过 72 小时会自动作废。',
682
- disputeRetire: '建议退役',
683
- disputeRewrite: '建议改写',
684
- accept: '接受',
685
- reject: '保留原样',
686
- noDisputes: '没有待裁决的事项。',
687
- unavailable: '本部署没有把 memories 远程接口暴露给浏览器,只能编辑可调项。',
688
- uses: '使用',
689
- session: '来自会话',
690
- updated: '更新于',
691
- saved: '已保存。',
692
- removed: '已删除。',
693
- personaIntro: '这就是每个会话开头注入的「这个人是谁」画像(<persona> 块)。手动保存后,后台合并默认仍可能按需改写;勾选锁定后,只有你的保存会改变它。',
694
- personaLock: '锁定画像:后台合并不要自动改写',
695
- personaLockHint: '锁定只阻止后台合并写入,不影响每个会话的注入。',
696
- personaPlaceholder: '这个人是谁:工作方式、偏好、不能违反的边界……',
697
- personaSave: '保存画像',
698
- personaSaved: '画像已保存。',
699
- personaBudgetNote: '注入字节预算在「配置」里的 personaMaxBytes 调整(默认 12000);超出预算的部分按行截断。',
700
- needTitle: '标题和正文都要填。',
701
- },
702
- en: {
703
- lang: 'en',
704
- label: 'Memories',
705
- title: 'Memories',
706
- intro: 'Cross-session memory: the global store applies to every project, the project store to one workspace. Inspect, search, add, and delete memories here.',
707
- store: 'Store',
708
- global: 'Global',
709
- project: 'Project',
710
- unit: 'memories',
711
- search: 'Search memories…',
712
- allScopes: 'All scopes',
713
- allKinds: 'All kinds',
714
- kindLabels: { preference: 'Preference', failure: 'Failure', procedure: 'Procedure', knowledge: 'Knowledge', fact: 'Fact' },
715
- empty: 'No memory matches.',
716
- loading: 'Loading…',
717
- forget: 'Delete',
718
- confirm: 'Delete this memory?',
719
- add: 'New memory',
720
- cancel: 'Cancel',
721
- save: 'Save',
722
- titlePlaceholder: 'Title: one line',
723
- bodyPlaceholder: 'Body: 1-4 sentences',
724
- tagsPlaceholder: 'Tags, comma separated (optional)',
725
- drafts: 'Staged skill drafts',
726
- promote: 'Promote to the skill root',
727
- discard: 'Discard',
728
- promoted: 'Promoted',
729
- tunables: 'Tunables',
730
- tabMemories: 'Memories',
731
- tabPersona: 'Persona',
732
- tabConfig: 'Configuration',
733
- tabDisputes: 'Needs review',
734
- disputesTitle: 'Decisions consolidation will not make on its own',
735
- disputesIntro: 'Background consolidation applies what is reversible by itself: folding duplicates, sharpening wording, retiring memories nothing ever read. The rows below would lose something — accept applies the change, reject keeps the memory as it is, and doing nothing expires the question after 72 hours.',
736
- disputeRetire: 'retire',
737
- disputeRewrite: 'rewrite',
738
- accept: 'Accept',
739
- reject: 'Keep as is',
740
- noDisputes: 'Nothing needs your decision.',
741
- unavailable: 'This deployment does not expose the memories Remote API to the browser; only the tunables can be edited.',
742
- uses: 'used',
743
- session: 'from',
744
- updated: 'updated',
745
- saved: 'Saved.',
746
- removed: 'Deleted.',
747
- personaIntro: 'This is the "who this user is" profile injected at the start of every conversation (the <persona> block). Saving it by hand still leaves background consolidation free to rewrite it; lock it to make your saves the only writes.',
748
- personaLock: 'Lock the profile: background consolidation must not rewrite it',
749
- personaLockHint: 'The lock only stops automatic writes; injection is unchanged.',
750
- personaPlaceholder: 'Who this person is: how they work, what they prefer, the boundaries they set…',
751
- personaSave: 'Save profile',
752
- personaSaved: 'Profile saved.',
753
- personaBudgetNote: 'The injection byte budget is personaMaxBytes under Configuration (default 12000); text beyond it is cut at a line boundary.',
754
- needTitle: 'A title and a body are both required.',
755
- },
756
- }
757
-
639
+ zh: {
640
+ lang: 'zh',
641
+ label: '记忆',
642
+ title: '记忆',
643
+ intro: '跨会话记忆:全局库对所有项目生效,项目库只对同一个工作区生效。这里可以查看、搜索、新增和删除记忆。',
644
+ store: '存储位置',
645
+ global: '全局',
646
+ project: '项目',
647
+ unit: '条',
648
+ search: '搜索记忆…',
649
+ allScopes: '全部范围',
650
+ allKinds: '全部类型',
651
+ kindLabels: { preference: '偏好', failure: '失败教训', procedure: '流程', knowledge: '经验', fact: '事实' },
652
+ empty: '没有匹配的记忆。',
653
+ loading: '加载中…',
654
+ forget: '删除',
655
+ confirm: '删除这条记忆?',
656
+ add: '新增记忆',
657
+ cancel: '取消',
658
+ save: '保存',
659
+ titlePlaceholder: '标题:一行说清这条记忆',
660
+ bodyPlaceholder: '正文:1-4 句话',
661
+ tagsPlaceholder: '标签,逗号分隔(可选)',
662
+ drafts: '待提升的 skill 草稿',
663
+ promote: '提升到技能目录',
664
+ discard: '丢弃',
665
+ promoted: '已提升',
666
+ tunables: '配置项',
667
+ tabMemories: '记忆',
668
+ tabPersona: '画像',
669
+ tabConfig: '配置',
670
+ tabDisputes: '待裁决',
671
+ disputesTitle: '合并时需要你拍板的事',
672
+ disputesIntro: '后台合并会自动执行可逆的改动(合并重复、收紧措辞、退役从没被读过的条目)。只有下面这些会伤到内容,才留给你决定——接受就按它改,驳回就原样保留,不动它过 72 小时会自动作废。',
673
+ disputeRetire: '建议退役',
674
+ disputeRewrite: '建议改写',
675
+ accept: '接受',
676
+ reject: '保留原样',
677
+ noDisputes: '没有待裁决的事项。',
678
+ unavailable: '本部署没有把 memories 远程接口暴露给浏览器,只能编辑可调项。',
679
+ uses: '使用',
680
+ session: '来自会话',
681
+ updated: '更新于',
682
+ saved: '已保存。',
683
+ removed: '已删除。',
684
+ personaIntro: '这就是每个会话开头注入的「这个人是谁」画像(<persona> 块)。手动保存后,后台合并默认仍可能按需改写;勾选锁定后,只有你的保存会改变它。',
685
+ personaLock: '锁定画像:后台合并不要自动改写',
686
+ personaLockHint: '锁定只阻止后台合并写入,不影响每个会话的注入。',
687
+ personaPlaceholder: '这个人是谁:工作方式、偏好、不能违反的边界……',
688
+ personaSave: '保存画像',
689
+ personaSaved: '画像已保存。',
690
+ personaBudgetNote: '注入字节预算在「配置」里的 personaMaxBytes 调整(默认 12000);超出预算的部分按行截断。',
691
+ needTitle: '标题和正文都要填。',
692
+ },
693
+ en: {
694
+ lang: 'en',
695
+ label: 'Memories',
696
+ title: 'Memories',
697
+ intro: 'Cross-session memory: the global store applies to every project, the project store to one workspace. Inspect, search, add, and delete memories here.',
698
+ store: 'Store',
699
+ global: 'Global',
700
+ project: 'Project',
701
+ unit: 'memories',
702
+ search: 'Search memories…',
703
+ allScopes: 'All scopes',
704
+ allKinds: 'All kinds',
705
+ kindLabels: { preference: 'Preference', failure: 'Failure', procedure: 'Procedure', knowledge: 'Knowledge', fact: 'Fact' },
706
+ empty: 'No memory matches.',
707
+ loading: 'Loading…',
708
+ forget: 'Delete',
709
+ confirm: 'Delete this memory?',
710
+ add: 'New memory',
711
+ cancel: 'Cancel',
712
+ save: 'Save',
713
+ titlePlaceholder: 'Title: one line',
714
+ bodyPlaceholder: 'Body: 1-4 sentences',
715
+ tagsPlaceholder: 'Tags, comma separated (optional)',
716
+ drafts: 'Staged skill drafts',
717
+ promote: 'Promote to the skill root',
718
+ discard: 'Discard',
719
+ promoted: 'Promoted',
720
+ tunables: 'Tunables',
721
+ tabMemories: 'Memories',
722
+ tabPersona: 'Persona',
723
+ tabConfig: 'Configuration',
724
+ tabDisputes: 'Needs review',
725
+ disputesTitle: 'Decisions consolidation will not make on its own',
726
+ disputesIntro: 'Background consolidation applies what is reversible by itself: folding duplicates, sharpening wording, retiring memories nothing ever read. The rows below would lose something — accept applies the change, reject keeps the memory as it is, and doing nothing expires the question after 72 hours.',
727
+ disputeRetire: 'retire',
728
+ disputeRewrite: 'rewrite',
729
+ accept: 'Accept',
730
+ reject: 'Keep as is',
731
+ noDisputes: 'Nothing needs your decision.',
732
+ unavailable: 'This deployment does not expose the memories Remote API to the browser; only the tunables can be edited.',
733
+ uses: 'used',
734
+ session: 'from',
735
+ updated: 'updated',
736
+ saved: 'Saved.',
737
+ removed: 'Deleted.',
738
+ personaIntro: 'This is the "who this user is" profile injected at the start of every conversation (the <persona> block). Saving it by hand still leaves background consolidation free to rewrite it; lock it to make your saves the only writes.',
739
+ personaLock: 'Lock the profile: background consolidation must not rewrite it',
740
+ personaLockHint: 'The lock only stops automatic writes; injection is unchanged.',
741
+ personaPlaceholder: 'Who this person is: how they work, what they prefer, the boundaries they set…',
742
+ personaSave: 'Save profile',
743
+ personaSaved: 'Profile saved.',
744
+ personaBudgetNote: 'The injection byte budget is personaMaxBytes under Configuration (default 12000); text beyond it is cut at a line boundary.',
745
+ needTitle: 'A title and a body are both required.',
746
+ },
747
+ };
758
748
  /** Message text of an unknown thrown value. */
759
749
  function errorText(error) {
760
- return error instanceof Error ? error.message : String(error)
750
+ return error instanceof Error ? error.message : String(error);
761
751
  }
762
-
763
752
  /** Render one timestamp as a short local string. */
764
753
  function whenText(ms) {
765
- return ms > 0 ? new Date(ms).toLocaleString() : '—'
754
+ return ms > 0 ? new Date(ms).toLocaleString() : '—';
766
755
  }
767
-
768
756
  /**
769
757
  * Split one disputed body into comparable tokens.
770
758
  *
@@ -773,13 +761,11 @@ window.__ModuleLoader__.load({
773
761
  * does not turn into three one-letter diffs, and whitespace groups with the
774
762
  * token after it so a moved space renders as part of the surrounding change.
775
763
  */
776
- const DIFF_TOKEN = /[A-Za-z0-9_]+|\s+|[\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff]|[^\s]/gu
777
-
764
+ const DIFF_TOKEN = /[A-Za-z0-9_]+|\s+|[\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff]|[^\s]/gu;
778
765
  /** Tokenize `text` for the word diff. */
779
766
  function diffSplit(text) {
780
- return text.match(DIFF_TOKEN) ?? []
767
+ return text.match(DIFF_TOKEN) ?? [];
781
768
  }
782
-
783
769
  /**
784
770
  * The word-level difference between two bodies.
785
771
  *
@@ -792,51 +778,69 @@ window.__ModuleLoader__.load({
792
778
  * @returns unchanged, removed, and added runs, in reading order.
793
779
  */
794
780
  function diffTokens(before, after) {
795
- const left = diffSplit(before)
796
- const right = diffSplit(after)
797
- let head = 0
798
- while (head < left.length && head < right.length && left[head] === right[head]) head += 1
799
- let tail = 0
800
- while (tail < left.length - head && tail < right.length - head && left[left.length - 1 - tail] === right[right.length - 1 - tail]) tail += 1
801
-
802
- const leftMid = left.slice(head, left.length - tail)
803
- const rightMid = right.slice(head, right.length - tail)
804
- const cols = rightMid.length + 1
805
- // `table[i][j]` is the longest common subsequence of `leftMid[i..]` and
806
- // `rightMid[j..]`, filled backwards so the walk below can go forwards and
807
- // emit each run at the position it is read at.
808
- const table = new Int32Array((leftMid.length + 1) * cols)
809
- for (let i = leftMid.length - 1; i >= 0; i -= 1) {
810
- for (let j = rightMid.length - 1; j >= 0; j -= 1) {
811
- table[i * cols + j] = leftMid[i] === rightMid[j]
812
- ? table[(i + 1) * cols + (j + 1)] + 1
813
- : Math.max(table[(i + 1) * cols + j], table[i * cols + (j + 1)])
781
+ const left = diffSplit(before);
782
+ const right = diffSplit(after);
783
+ let head = 0;
784
+ while (head < left.length && head < right.length && left[head] === right[head])
785
+ head += 1;
786
+ let tail = 0;
787
+ while (tail < left.length - head && tail < right.length - head && left[left.length - 1 - tail] === right[right.length - 1 - tail])
788
+ tail += 1;
789
+ const leftMid = left.slice(head, left.length - tail);
790
+ const rightMid = right.slice(head, right.length - tail);
791
+ const cols = rightMid.length + 1;
792
+ // `table[i][j]` is the longest common subsequence of `leftMid[i..]` and
793
+ // `rightMid[j..]`, filled backwards so the walk below can go forwards and
794
+ // emit each run at the position it is read at.
795
+ const table = new Int32Array((leftMid.length + 1) * cols);
796
+ for (let i = leftMid.length - 1; i >= 0; i -= 1) {
797
+ for (let j = rightMid.length - 1; j >= 0; j -= 1) {
798
+ table[i * cols + j] = leftMid[i] === rightMid[j]
799
+ ? table[(i + 1) * cols + (j + 1)] + 1
800
+ : Math.max(table[(i + 1) * cols + j], table[i * cols + (j + 1)]);
801
+ }
814
802
  }
815
- }
816
-
817
- const runs = []
818
- const push = (kind, text) => {
819
- const last = runs[runs.length - 1]
820
- if (last !== undefined && last.kind === kind) last.text += text
821
- else runs.push({ kind, text })
822
- }
823
- for (const token of left.slice(0, head)) push('same', token)
824
- let i = 0
825
- let j = 0
826
- while (i < leftMid.length && j < rightMid.length) {
827
- if (leftMid[i] === rightMid[j]) { push('same', leftMid[i]); i += 1; j += 1 }
828
- else if (table[(i + 1) * cols + j] >= table[i * cols + (j + 1)]) { push('del', leftMid[i]); i += 1 }
829
- else { push('ins', rightMid[j]); j += 1 }
830
- }
831
- while (i < leftMid.length) { push('del', leftMid[i]); i += 1 }
832
- while (j < rightMid.length) { push('ins', rightMid[j]); j += 1 }
833
- for (const token of left.slice(left.length - tail)) push('same', token)
834
- return runs
803
+ const runs = [];
804
+ const push = (kind, text) => {
805
+ const last = runs[runs.length - 1];
806
+ if (last !== undefined && last.kind === kind)
807
+ last.text += text;
808
+ else
809
+ runs.push({ kind, text });
810
+ };
811
+ for (const token of left.slice(0, head))
812
+ push('same', token);
813
+ let i = 0;
814
+ let j = 0;
815
+ while (i < leftMid.length && j < rightMid.length) {
816
+ if (leftMid[i] === rightMid[j]) {
817
+ push('same', leftMid[i]);
818
+ i += 1;
819
+ j += 1;
820
+ }
821
+ else if (table[(i + 1) * cols + j] >= table[i * cols + (j + 1)]) {
822
+ push('del', leftMid[i]);
823
+ i += 1;
824
+ }
825
+ else {
826
+ push('ins', rightMid[j]);
827
+ j += 1;
828
+ }
829
+ }
830
+ while (i < leftMid.length) {
831
+ push('del', leftMid[i]);
832
+ i += 1;
833
+ }
834
+ while (j < rightMid.length) {
835
+ push('ins', rightMid[j]);
836
+ j += 1;
837
+ }
838
+ for (const token of left.slice(left.length - tail))
839
+ push('same', token);
840
+ return runs;
835
841
  }
836
-
837
842
  /** The scope sentence older proposals put in a rewrite reason (no longer produced). */
838
- const SCOPE_REASON = /^作用域要从\s*(\S+)\s*改成\s*(\S+)$/u
839
-
843
+ const SCOPE_REASON = /^作用域要从\s*(\S+)\s*改成\s*(\S+)$/u;
840
844
  /**
841
845
  * Split a dispute reason into its grounds and its scope move.
842
846
  *
@@ -849,29 +853,30 @@ window.__ModuleLoader__.load({
849
853
  * @returns the scope move, if any, and the remaining grounds.
850
854
  */
851
855
  function splitDisputeReason(reason) {
852
- const reasons = []
853
- let scope = null
854
- const parts = typeof reason === 'string' ? reason.split(';') : []
855
- for (const part of parts) {
856
- const text = part.trim()
857
- if (text.length === 0) continue
858
- const move = SCOPE_REASON.exec(text)
859
- if (move !== null && scope === null) {
860
- scope = { from: move[1], to: move[2] }
861
- continue
856
+ const reasons = [];
857
+ let scope = null;
858
+ const parts = typeof reason === 'string' ? reason.split(';') : [];
859
+ for (const part of parts) {
860
+ const text = part.trim();
861
+ if (text.length === 0)
862
+ continue;
863
+ const move = SCOPE_REASON.exec(text);
864
+ if (move !== null && scope === null) {
865
+ scope = { from: move[1], to: move[2] };
866
+ continue;
867
+ }
868
+ reasons.push(text);
862
869
  }
863
- reasons.push(text)
864
- }
865
- return { scope, reasons }
870
+ return { scope, reasons };
866
871
  }
867
-
868
872
  /** The locale label for a memory scope, falling back to the raw value. */
869
873
  function scopeText(copy, scope) {
870
- if (scope === 'global') return copy.global
871
- if (scope === 'project') return copy.project
872
- return scope
874
+ if (scope === 'global')
875
+ return copy.global;
876
+ if (scope === 'project')
877
+ return copy.project;
878
+ return scope;
873
879
  }
874
-
875
880
  /**
876
881
  * Build the section component.
877
882
  *
@@ -880,585 +885,581 @@ window.__ModuleLoader__.load({
880
885
  * @returns the settings section component.
881
886
  */
882
887
  function createMemoriesSection(React, Card) {
883
- const h = React.createElement
884
-
885
- /**
886
- * One disputed body as a single reading line.
887
- *
888
- * There is no "before"/"after" pair any more: unchanged words read exactly as
889
- * stored, words the pass removes are struck, words it adds are highlighted, so
890
- * the difference is the layout instead of a caption. A retirement has no
891
- * replacement; identical text is still shown once, because deciding whether a
892
- * memory belongs where it is cannot be done without reading it.
893
- */
894
- function disputeBody(row) {
895
- if (row.action === 'retire') return h('p', { key: 'diff', className: 'dshm-diff dshm-retire' }, row.before)
896
- if (row.before === row.after) return h('p', { key: 'diff', className: 'dshm-diff' }, row.before)
897
- return h('p', { key: 'diff', className: 'dshm-diff' }, diffTokens(row.before, row.after).map((run, at) => {
898
- if (run.kind === 'same') return run.text
899
- const name = run.kind === 'del' ? 'dshm-del' : 'dshm-ins'
900
- return h(run.kind === 'del' ? 'del' : 'ins', { key: `${name}-${at}`, className: name }, run.text)
901
- }))
902
- }
903
-
904
- /** One entry row. */
905
- function EntryRow(props) {
906
- const copy = props.copy
907
- const entry = props.entry
908
- const badge = (text, extra) => h('span', { key: text, className: `dshm-badge${extra === true ? ' dshm-badge-global' : ''}` }, text)
909
- return h('li', { className: 'dshm-entry' }, [
910
- h('div', { key: 'head', className: 'dshm-entry-head' }, [
911
- h('h4', { key: 'title', className: 'dshm-entry-title' }, entry.title),
912
- badge(copy.kindLabels[entry.kind] ?? entry.kind),
913
- badge(entry.scope === 'global' ? copy.global : copy.project, entry.scope === 'global'),
914
- ]),
915
- h('p', { key: 'body', className: 'dshm-body' }, entry.body),
916
- h('div', { key: 'meta', className: 'dshm-meta' }, [
917
- h('span', { key: 'updated' }, `${copy.updated} ${whenText(entry.updatedAt)}`),
918
- h('span', { key: 'uses' }, `${copy.uses} ${entry.uses}`),
919
- entry.tags.length > 0 ? h('span', { key: 'tags' }, entry.tags.join(' · ')) : null,
920
- entry.sourceSession !== undefined && entry.sourceSession.length > 0
921
- ? h('span', { key: 'session' }, `${copy.session} ${entry.sourceSession}`)
922
- : null,
923
- ]),
924
- h('div', { key: 'actions', className: 'dshm-actions' }, [
925
- h('button', {
926
- key: 'forget',
927
- type: 'button',
928
- className: 'dshm-btn',
929
- disabled: props.busy,
930
- onClick: () => props.onForget(entry),
931
- }, copy.forget),
932
- ]),
933
- ])
934
- }
935
-
936
- /** One staged draft row. */
937
- function DraftRow(props) {
938
- const copy = props.copy
939
- const draft = props.draft
940
- return h('li', { key: draft.name, className: 'dshm-entry' }, [
941
- h('div', { key: 'head', className: 'dshm-entry-head' }, [
942
- h('h4', { key: 'name', className: 'dshm-entry-title' }, draft.name),
943
- draft.promoted ? h('span', { key: 'state', className: 'dshm-badge dshm-badge-global' }, copy.promoted) : null,
944
- ]),
945
- h('p', { key: 'desc', className: 'dshm-body' }, draft.description || '—'),
946
- h('div', { key: 'actions', className: 'dshm-actions' }, [
947
- h('button', {
948
- key: 'promote',
949
- type: 'button',
950
- className: 'dshm-btn dshm-btn-primary',
951
- disabled: props.busy,
952
- onClick: () => props.onPromote(draft),
953
- }, copy.promote),
954
- h('button', {
955
- key: 'discard',
956
- type: 'button',
957
- className: 'dshm-btn',
958
- disabled: props.busy,
959
- onClick: () => props.onDiscard(draft),
960
- }, copy.discard),
961
- ]),
962
- ])
963
- }
964
-
965
- return function MemoriesSection(props) {
966
- const copy = props.copy
967
- const api = props.api
968
- const [overview, setOverview] = React.useState(null)
969
- const [error, setError] = React.useState(null)
970
- const [notice, setNotice] = React.useState(null)
971
- const [entries, setEntries] = React.useState([])
972
- const [total, setTotal] = React.useState(0)
973
- const [loading, setLoading] = React.useState(true)
974
- const [busy, setBusy] = React.useState(false)
975
- const [query, setQuery] = React.useState('')
976
- const [settledQuery, setSettledQuery] = React.useState('')
977
- const [scope, setScope] = React.useState('all')
978
- const [kind, setKind] = React.useState('')
979
- const [project, setProject] = React.useState('')
980
- const [formOpen, setFormOpen] = React.useState(false)
981
- const [tab, setTab] = React.useState('memories')
982
- const [disputes, setDisputes] = React.useState([])
983
- const [draft, setDraft] = React.useState({ scope: 'global', kind: 'fact', title: '', body: '', tags: '' })
984
- const [personaDraft, setPersonaDraft] = React.useState('')
985
- const [personaLocked, setPersonaLocked] = React.useState(false)
986
- const [personaLoaded, setPersonaLoaded] = React.useState(false)
987
- const [personaBusy, setPersonaBusy] = React.useState(false)
988
-
989
- const loadOverview = React.useCallback(async () => {
990
- if (api === undefined) return
991
- try {
992
- setOverview(await api.overview())
993
- } catch (failure) {
994
- setError(errorText(failure))
995
- }
996
- }, [api])
997
-
998
- const loadEntries = React.useCallback(async () => {
999
- if (api === undefined) return
1000
- setLoading(true)
1001
- try {
1002
- const result = await api.list({
1003
- project,
1004
- scope: scope === 'all' ? '' : scope,
1005
- query: settledQuery,
1006
- kind,
1007
- limit: 100,
1008
- })
1009
- setEntries(result?.entries ?? [])
1010
- setTotal(result?.total ?? 0)
1011
- setError(null)
1012
- } catch (failure) {
1013
- setError(errorText(failure))
1014
- } finally {
1015
- setLoading(false)
1016
- }
1017
- }, [api, project, scope, kind, settledQuery])
1018
-
1019
- // Debounce typing so a search does not issue one call per keystroke.
1020
- React.useEffect(() => {
1021
- const timer = setTimeout(() => setSettledQuery(query), 250)
1022
- return () => clearTimeout(timer)
1023
- }, [query])
1024
-
1025
- // A decision waits for a person, so the count has to be visible without
1026
- // opening the tab — otherwise it is a question nobody knows was asked.
1027
- const loadDisputes = React.useCallback(async () => {
1028
- if (api === undefined || typeof api.disputes !== 'function') return
1029
- try {
1030
- const result = await api.disputes()
1031
- setDisputes(result?.disputes ?? [])
1032
- } catch (failure) {
1033
- setError(errorText(failure))
1034
- }
1035
- }, [api])
1036
-
1037
- const loadPersona = React.useCallback(async () => {
1038
- if (api === undefined || typeof api.persona !== 'function') return
1039
- try {
1040
- const result = await api.persona()
1041
- setPersonaDraft(result?.text ?? '')
1042
- setPersonaLocked(result?.locked === true)
1043
- setPersonaLoaded(true)
1044
- setError(null)
1045
- } catch (failure) {
1046
- setError(errorText(failure))
1047
- }
1048
- }, [api])
1049
-
1050
- // The profile is only read when its tab is opened: it is a document the
1051
- // user edits, not page furniture.
1052
- React.useEffect(() => {
1053
- if (tab === 'persona' && !personaLoaded) void loadPersona()
1054
- }, [tab, personaLoaded, loadPersona])
1055
-
1056
- React.useEffect(() => { void loadOverview() }, [loadOverview])
1057
- React.useEffect(() => { void loadEntries() }, [loadEntries])
1058
- React.useEffect(() => { void loadDisputes() }, [loadDisputes])
1059
-
1060
- // Preselect the newest project so the project filter has a subject.
1061
- React.useEffect(() => {
1062
- if (project !== '' || overview === null) return
1063
- const first = overview.projects?.[0]
1064
- if (first !== undefined) setProject(first.slug)
1065
- }, [overview, project])
1066
-
1067
- const refresh = async () => {
1068
- await Promise.all([loadOverview(), loadEntries(), loadDisputes()])
1069
- }
1070
-
1071
- /** Accept or reject one waiting decision, then reload what it changed. */
1072
- const onResolve = async (row, decision) => {
1073
- if (api === undefined || typeof api.resolveDispute !== 'function') {
1074
- setError(copy.unavailable)
1075
- return
1076
- }
1077
- setBusy(true)
1078
- setNotice(null)
1079
- try {
1080
- // One object keyed by the descriptor's own parameter names: the Remote
1081
- // wrapper maps those fields onto the gateway's positional arguments, so
1082
- // a positional call arrives as no arguments at all.
1083
- setNotice(await api.resolveDispute({ id: row.id, decision }))
1084
- await refresh()
1085
- setError(null)
1086
- } catch (failure) {
1087
- setError(errorText(failure))
1088
- } finally {
1089
- setBusy(false)
1090
- }
1091
- }
1092
-
1093
- const onSavePersona = async () => {
1094
- if (api === undefined || typeof api.savePersona !== 'function') {
1095
- setError(copy.unavailable)
1096
- return
1097
- }
1098
- setPersonaBusy(true)
1099
- setNotice(null)
1100
- try {
1101
- // One object keyed by the wire fields, like every other Remote call.
1102
- const result = await api.savePersona({ text: personaDraft, locked: personaLocked })
1103
- setPersonaDraft(result?.text ?? '')
1104
- setPersonaLocked(result?.locked === true)
1105
- setPersonaLoaded(true)
1106
- setNotice(copy.personaSaved)
1107
- setError(null)
1108
- } catch (failure) {
1109
- setError(errorText(failure))
1110
- } finally {
1111
- setPersonaBusy(false)
1112
- }
1113
- }
1114
-
1115
- const onForget = async (entry) => {
1116
- if (api === undefined) return
1117
- if (typeof window !== 'undefined' && !window.confirm(copy.confirm)) return
1118
- setBusy(true)
1119
- setNotice(null)
1120
- try {
1121
- await api.forget({ project, scope: entry.scope, id: entry.id })
1122
- setNotice(copy.removed)
1123
- await refresh()
1124
- } catch (failure) {
1125
- setError(errorText(failure))
1126
- } finally {
1127
- setBusy(false)
1128
- }
888
+ const h = React.createElement;
889
+ /**
890
+ * One disputed body as a single reading line.
891
+ *
892
+ * There is no "before"/"after" pair any more: unchanged words read exactly as
893
+ * stored, words the pass removes are struck, words it adds are highlighted, so
894
+ * the difference is the layout instead of a caption. A retirement has no
895
+ * replacement; identical text is still shown once, because deciding whether a
896
+ * memory belongs where it is cannot be done without reading it.
897
+ */
898
+ function disputeBody(row) {
899
+ if (row.action === 'retire')
900
+ return h('p', { key: 'diff', className: 'dshm-diff dshm-retire' }, row.before);
901
+ if (row.before === row.after)
902
+ return h('p', { key: 'diff', className: 'dshm-diff' }, row.before);
903
+ return h('p', { key: 'diff', className: 'dshm-diff' }, diffTokens(row.before, row.after).map((run, at) => {
904
+ if (run.kind === 'same')
905
+ return run.text;
906
+ const name = run.kind === 'del' ? 'dshm-del' : 'dshm-ins';
907
+ return h(run.kind === 'del' ? 'del' : 'ins', { key: `${name}-${at}`, className: name }, run.text);
908
+ }));
1129
909
  }
1130
-
1131
- const onPromote = async (staged) => {
1132
- if (api === undefined) return
1133
- setBusy(true)
1134
- try {
1135
- const result = await api.promoteSkill({ name: staged.name })
1136
- setNotice(`${copy.promoted}: ${result.path}`)
1137
- await refresh()
1138
- } catch (failure) {
1139
- setError(errorText(failure))
1140
- } finally {
1141
- setBusy(false)
1142
- }
1143
- }
1144
-
1145
- const onDiscard = async (staged) => {
1146
- if (api === undefined) return
1147
- setBusy(true)
1148
- try {
1149
- await api.discardSkill({ name: staged.name })
1150
- await refresh()
1151
- } catch (failure) {
1152
- setError(errorText(failure))
1153
- } finally {
1154
- setBusy(false)
1155
- }
910
+ /** One entry row. */
911
+ function EntryRow(props) {
912
+ const copy = props.copy;
913
+ const entry = props.entry;
914
+ const badge = (text, extra = false) => h('span', { key: text, className: `dshm-badge${extra === true ? ' dshm-badge-global' : ''}` }, text);
915
+ return h('li', { className: 'dshm-entry' }, [
916
+ h('div', { key: 'head', className: 'dshm-entry-head' }, [
917
+ h('h4', { key: 'title', className: 'dshm-entry-title' }, entry.title),
918
+ badge(copy.kindLabels[entry.kind] ?? entry.kind),
919
+ badge(entry.scope === 'global' ? copy.global : copy.project, entry.scope === 'global'),
920
+ ]),
921
+ h('p', { key: 'body', className: 'dshm-body' }, entry.body),
922
+ h('div', { key: 'meta', className: 'dshm-meta' }, [
923
+ h('span', { key: 'updated' }, `${copy.updated} ${whenText(entry.updatedAt)}`),
924
+ h('span', { key: 'uses' }, `${copy.uses} ${entry.uses}`),
925
+ entry.tags.length > 0 ? h('span', { key: 'tags' }, entry.tags.join(' · ')) : null,
926
+ entry.sourceSession !== undefined && entry.sourceSession.length > 0
927
+ ? h('span', { key: 'session' }, `${copy.session} ${entry.sourceSession}`)
928
+ : null,
929
+ ]),
930
+ h('div', { key: 'actions', className: 'dshm-actions' }, [
931
+ h('button', {
932
+ key: 'forget',
933
+ type: 'button',
934
+ className: 'dshm-btn',
935
+ disabled: props.busy,
936
+ onClick: () => props.onForget(entry),
937
+ }, copy.forget),
938
+ ]),
939
+ ]);
1156
940
  }
1157
-
1158
- const onSubmit = async (event) => {
1159
- event.preventDefault()
1160
- if (api === undefined) return
1161
- if (draft.title.trim().length === 0 || draft.body.trim().length === 0) {
1162
- setError(copy.needTitle)
1163
- return
1164
- }
1165
- setBusy(true)
1166
- setError(null)
1167
- try {
1168
- await api.add({ ...draft, project })
1169
- setDraft({ scope: draft.scope, kind: draft.kind, title: '', body: '', tags: '' })
1170
- setFormOpen(false)
1171
- setNotice(copy.saved)
1172
- await refresh()
1173
- } catch (failure) {
1174
- setError(errorText(failure))
1175
- } finally {
1176
- setBusy(false)
1177
- }
941
+ /** One staged draft row. */
942
+ function DraftRow(props) {
943
+ const copy = props.copy;
944
+ const draft = props.draft;
945
+ return h('li', { key: draft.name, className: 'dshm-entry' }, [
946
+ h('div', { key: 'head', className: 'dshm-entry-head' }, [
947
+ h('h4', { key: 'name', className: 'dshm-entry-title' }, draft.name),
948
+ draft.promoted ? h('span', { key: 'state', className: 'dshm-badge dshm-badge-global' }, copy.promoted) : null,
949
+ ]),
950
+ h('p', { key: 'desc', className: 'dshm-body' }, draft.description || '—'),
951
+ h('div', { key: 'actions', className: 'dshm-actions' }, [
952
+ h('button', {
953
+ key: 'promote',
954
+ type: 'button',
955
+ className: 'dshm-btn dshm-btn-primary',
956
+ disabled: props.busy,
957
+ onClick: () => props.onPromote(draft),
958
+ }, copy.promote),
959
+ h('button', {
960
+ key: 'discard',
961
+ type: 'button',
962
+ className: 'dshm-btn',
963
+ disabled: props.busy,
964
+ onClick: () => props.onDiscard(draft),
965
+ }, copy.discard),
966
+ ]),
967
+ ]);
1178
968
  }
1179
-
1180
- const setDraftField = (field, value) => setDraft((previous) => ({ ...previous, [field]: value }))
1181
-
1182
- const kindOptions = (overview?.kinds ?? ['preference', 'failure', 'procedure', 'knowledge', 'fact']).map((value) =>
1183
- h('option', { key: value, value }, copy.kindLabels[value] ?? value))
1184
-
1185
- // The host is the authority on shape, but a missing array must degrade to an
1186
- // empty list rather than blank the whole page.
1187
- const projects = overview?.projects ?? []
1188
- const staged = overview?.drafts ?? []
1189
-
1190
- const head = h('div', { key: 'head', className: 'dshm-head' }, [
1191
- h('h2', { key: 'title', className: 'dshm-title' }, copy.title),
1192
- ])
1193
-
1194
- const stats = overview === null ? null : h('p', { key: 'stats', className: 'dshm-note' }, [
1195
- `${copy.global} ${overview.globalCount ?? 0} ${copy.unit}`,
1196
- ' · ',
1197
- projects.map((row) => `${row.name} ${row.count}`).join(' · ') || `${copy.project} 0 ${copy.unit}`,
1198
- ])
1199
-
1200
- const toolbar = h('div', { key: 'toolbar', className: 'dshm-toolbar' }, [
1201
- h('input', {
1202
- key: 'search',
1203
- className: 'dshm-input dshm-grow',
1204
- type: 'search',
1205
- value: query,
1206
- placeholder: copy.search,
1207
- disabled: api === undefined,
1208
- onChange: (event) => setQuery(event.target.value),
1209
- }),
1210
- h('select', {
1211
- key: 'scope',
1212
- className: 'dshm-select',
1213
- value: scope,
1214
- disabled: api === undefined,
1215
- onChange: (event) => setScope(event.target.value),
1216
- }, [
1217
- h('option', { key: 'all', value: 'all' }, copy.allScopes),
1218
- h('option', { key: 'global', value: 'global' }, copy.global),
1219
- h('option', { key: 'project', value: 'project' }, copy.project),
1220
- ]),
1221
- h('select', {
1222
- key: 'kind',
1223
- className: 'dshm-select',
1224
- value: kind,
1225
- disabled: api === undefined,
1226
- onChange: (event) => setKind(event.target.value),
1227
- }, [h('option', { key: 'any', value: '' }, copy.allKinds), ...kindOptions]),
1228
- h('select', {
1229
- key: 'project',
1230
- className: 'dshm-select',
1231
- value: project,
1232
- disabled: api === undefined || projects.length === 0,
1233
- onChange: (event) => setProject(event.target.value),
1234
- }, projects.map((row) => h('option', { key: row.slug, value: row.slug }, `${row.name} (${row.count})`))),
1235
- h('button', {
1236
- key: 'add',
1237
- type: 'button',
1238
- className: 'dshm-btn dshm-btn-primary',
1239
- disabled: api === undefined,
1240
- onClick: () => setFormOpen((open) => !open),
1241
- }, copy.add),
1242
- ])
1243
-
1244
- const form = formOpen ? h('form', { key: 'form', className: 'dshm-form', onSubmit }, [
1245
- h('div', { key: 'row', className: 'dshm-form-row' }, [
1246
- h('select', {
1247
- key: 'scope',
1248
- className: 'dshm-select',
1249
- value: draft.scope,
1250
- onChange: (event) => setDraftField('scope', event.target.value),
1251
- }, [
1252
- h('option', { key: 'global', value: 'global' }, copy.global),
1253
- h('option', { key: 'project', value: 'project' }, copy.project),
1254
- ]),
1255
- h('select', {
1256
- key: 'kind',
1257
- className: 'dshm-select',
1258
- value: draft.kind,
1259
- onChange: (event) => setDraftField('kind', event.target.value),
1260
- }, kindOptions),
1261
- ]),
1262
- h('input', {
1263
- key: 'title',
1264
- className: 'dshm-input',
1265
- style: { width: '100%' },
1266
- value: draft.title,
1267
- placeholder: copy.titlePlaceholder,
1268
- onChange: (event) => setDraftField('title', event.target.value),
1269
- }),
1270
- h('textarea', {
1271
- key: 'body',
1272
- className: 'dshm-area',
1273
- value: draft.body,
1274
- placeholder: copy.bodyPlaceholder,
1275
- onChange: (event) => setDraftField('body', event.target.value),
1276
- }),
1277
- h('input', {
1278
- key: 'tags',
1279
- className: 'dshm-input',
1280
- style: { width: '100%' },
1281
- value: draft.tags,
1282
- placeholder: copy.tagsPlaceholder,
1283
- onChange: (event) => setDraftField('tags', event.target.value),
1284
- }),
1285
- h('div', { key: 'actions', className: 'dshm-actions' }, [
1286
- h('button', { key: 'save', type: 'submit', className: 'dshm-btn dshm-btn-primary', disabled: busy }, copy.save),
1287
- h('button', { key: 'cancel', type: 'button', className: 'dshm-btn', onClick: () => setFormOpen(false) }, copy.cancel),
1288
- ]),
1289
- ]) : null
1290
-
1291
- const list = loading && entries.length === 0
1292
- ? h('p', { key: 'loading', className: 'dshm-empty' }, copy.loading)
1293
- : entries.length === 0
1294
- ? h('p', { key: 'empty', className: 'dshm-empty' }, copy.empty)
1295
- : h('ul', { key: 'list', className: 'dshm-list' }, entries.map((entry) =>
1296
- h(EntryRow, { key: `${entry.scope}:${entry.id}`, entry, copy, busy, onForget })))
1297
-
1298
- const drafts = staged.length > 0
1299
- ? h('section', { key: 'drafts', className: 'dshm-card' }, [
1300
- h('h3', { key: 'title', className: 'dshm-section-title' }, copy.drafts),
1301
- h('ul', { key: 'list', className: 'dshm-list' }, staged.map((row) =>
1302
- h(DraftRow, { key: row.name, draft: row, copy, busy, onPromote, onDiscard }))),
1303
- ])
1304
- : null
1305
-
1306
- const tabList = h('div', { key: 'tabs', className: 'dshm-tabs', role: 'tablist' }, [
1307
- h('button', {
1308
- key: 'memories',
1309
- type: 'button',
1310
- role: 'tab',
1311
- 'aria-selected': tab === 'memories',
1312
- className: `dshm-tab${tab === 'memories' ? ' dshm-tab-active' : ''}`,
1313
- onClick: () => setTab('memories'),
1314
- }, copy.tabMemories),
1315
- h('button', {
1316
- key: 'persona',
1317
- type: 'button',
1318
- role: 'tab',
1319
- 'aria-selected': tab === 'persona',
1320
- className: `dshm-tab${tab === 'persona' ? ' dshm-tab-active' : ''}${personaLocked ? ' dshm-tab-locked' : ''}`,
1321
- onClick: () => setTab('persona'),
1322
- }, personaLocked ? `🔒 ${copy.tabPersona}` : copy.tabPersona),
1323
- h('button', {
1324
- key: 'config',
1325
- type: 'button',
1326
- role: 'tab',
1327
- 'aria-selected': tab === 'config',
1328
- className: `dshm-tab${tab === 'config' ? ' dshm-tab-active' : ''}`,
1329
- onClick: () => setTab('config'),
1330
- }, copy.tabConfig),
1331
- h('button', {
1332
- key: 'disputes',
1333
- type: 'button',
1334
- role: 'tab',
1335
- 'aria-selected': tab === 'disputes',
1336
- className: `dshm-tab${tab === 'disputes' ? ' dshm-tab-active' : ''}${disputes.length > 0 ? ' dshm-tab-alert' : ''}`,
1337
- onClick: () => setTab('disputes'),
1338
- }, disputes.length > 0 ? `${copy.tabDisputes} (${disputes.length})` : copy.tabDisputes),
1339
- ])
1340
-
1341
- // The two tabs keep the store's CONTENT and the plugin's SETTINGS apart: one
1342
- // page, one place to look, and neither surface buries the other.
1343
- const memoriesPanel = h('div', { key: 'panel-memories', role: 'tabpanel', className: 'dshm-panel' }, [
1344
- api === undefined ? h('p', { key: 'unavailable', className: 'dshm-status dshm-error' }, copy.unavailable) : null,
1345
- overview !== null && stats !== null ? stats : null,
1346
- toolbar,
1347
- form,
1348
- h('p', { key: 'count', className: 'dshm-note' }, `${entries.length} / ${total} ${copy.unit}`),
1349
- list,
1350
- drafts,
1351
- error !== null ? h('p', { key: 'error', className: 'dshm-status dshm-error' }, error) : null,
1352
- notice !== null ? h('p', { key: 'notice', className: 'dshm-status dshm-ok' }, notice) : null,
1353
- ])
1354
-
1355
- const configPanel = h('div', { key: 'panel-config', role: 'tabpanel', className: 'dshm-panel' }, [
1356
- h(Card, {
1357
- key: 'tunables',
1358
- scope: props.scope,
1359
- useSnapshot: props.useSnapshot,
1360
- title: copy.tunables,
1361
- intro: false,
1362
- lang: copy.lang,
1363
- }),
1364
- ])
1365
-
1366
- const personaPanel = h('div', { key: 'panel-persona', role: 'tabpanel', className: 'dshm-panel' }, [
1367
- h('p', { key: 'intro', className: 'dshm-note' }, copy.personaIntro),
1368
- api === undefined || typeof api.savePersona !== 'function'
1369
- ? h('p', { key: 'unavailable', className: 'dshm-status dshm-error' }, copy.unavailable)
1370
- : null,
1371
- h('textarea', {
1372
- key: 'text',
1373
- className: 'dshm-area',
1374
- rows: 14,
1375
- value: personaDraft,
1376
- placeholder: copy.personaPlaceholder,
1377
- disabled: api === undefined || personaBusy,
1378
- onChange: (event) => setPersonaDraft(event.target.value),
1379
- }),
1380
- h('label', { key: 'lock', className: 'dshm-inline' }, [
1381
- h('input', {
1382
- key: 'input',
1383
- className: 'dshm-check',
1384
- type: 'checkbox',
1385
- checked: personaLocked,
1386
- disabled: api === undefined || personaBusy,
1387
- onChange: (event) => setPersonaLocked(event.target.checked),
1388
- }),
1389
- copy.personaLock,
1390
- ]),
1391
- h('p', { key: 'lock-hint', className: 'dshm-note' }, copy.personaLockHint),
1392
- h('p', { key: 'budget', className: 'dshm-note' }, copy.personaBudgetNote),
1393
- h('div', { key: 'actions', className: 'dshm-actions' }, [
1394
- h('button', {
1395
- key: 'save',
1396
- type: 'button',
1397
- className: 'dshm-btn dshm-btn-primary',
1398
- disabled: personaBusy || api === undefined,
1399
- onClick: onSavePersona,
1400
- }, copy.personaSave),
1401
- ]),
1402
- notice !== null ? h('p', { key: 'notice', className: 'dshm-status dshm-ok' }, notice) : null,
1403
- error !== null ? h('p', { key: 'error', className: 'dshm-status dshm-error' }, error) : null,
1404
- ])
1405
-
1406
- // Only the decisions a pass refused to make alone. Each row is one reading
1407
- // of the disputed text with the change marked in place, and a scope move is
1408
- // stated in the head rather than buried in the reason sentence.
1409
- const disputeRows = disputes.map((row) => {
1410
- const parsed = splitDisputeReason(row.reason)
1411
- return h('li', { key: `${row.action}:${row.id}`, className: 'dshm-entry' }, [
1412
- h('div', { key: 'head', className: 'dshm-entry-head' }, [
1413
- h('h4', { key: 'title', className: 'dshm-entry-title' }, row.title),
1414
- parsed.scope === null ? null : h('span', { key: 'scope', className: 'dshm-scope' }, [
1415
- h('span', { key: 'from' }, scopeText(copy, parsed.scope.from)),
1416
- h('span', { key: 'arrow', className: 'dshm-scope-arrow', 'aria-hidden': true }, '→'),
1417
- h('span', { key: 'to' }, scopeText(copy, parsed.scope.to)),
1418
- ]),
1419
- h('span', { key: 'action', className: 'dshm-badge dshm-badge-global' }, row.action === 'retire' ? copy.disputeRetire : copy.disputeRewrite),
1420
- ]),
1421
- parsed.reasons.length === 0 ? null : h('div', { key: 'reasons', className: 'dshm-reasons' }, parsed.reasons.map((text, at) =>
1422
- h('span', { key: `${at}:${text}`, className: 'dshm-badge' }, text))),
1423
- disputeBody(row),
1424
- h('div', { key: 'actions', className: 'dshm-actions' }, [
1425
- h('button', {
1426
- key: 'accept',
1427
- type: 'button',
1428
- className: 'dshm-btn dshm-btn-primary',
1429
- disabled: busy,
1430
- onClick: () => onResolve(row, 'accept'),
1431
- }, copy.accept),
1432
- h('button', {
1433
- key: 'reject',
1434
- type: 'button',
1435
- className: 'dshm-btn',
1436
- disabled: busy,
1437
- onClick: () => onResolve(row, 'reject'),
1438
- }, copy.reject),
1439
- ]),
1440
- ])
1441
- })
1442
- const disputesPanel = h('div', { key: 'panel-disputes', role: 'tabpanel', className: 'dshm-panel' }, [
1443
- h('h3', { key: 'title', className: 'dshm-section-title' }, copy.disputesTitle),
1444
- h('p', { key: 'intro', className: 'dshm-note' }, copy.disputesIntro),
1445
- api === undefined ? h('p', { key: 'unavailable', className: 'dshm-status dshm-error' }, copy.unavailable) : null,
1446
- disputeRows.length > 0
1447
- ? h('ul', { key: 'list', className: 'dshm-list' }, disputeRows)
1448
- : h('p', { key: 'empty', className: 'dshm-note' }, copy.noDisputes),
1449
- notice !== null ? h('p', { key: 'notice', className: 'dshm-status dshm-ok' }, notice) : null,
1450
- error !== null ? h('p', { key: 'error', className: 'dshm-status dshm-error' }, error) : null,
1451
- ])
1452
-
1453
- const children = [head]
1454
- if (overview !== null) children.push(h('p', { key: 'store', className: 'dshm-path' }, `${copy.store}: ${overview.storePath}`))
1455
- children.push(tabList)
1456
- children.push(tab === 'config' ? configPanel : tab === 'disputes' ? disputesPanel : tab === 'persona' ? personaPanel : memoriesPanel)
1457
- return h('div', { className: 'dshm-page' }, children)
1458
- }
969
+ return function MemoriesSection(props) {
970
+ const copy = props.copy;
971
+ const api = props.api;
972
+ const [overview, setOverview] = React.useState(null);
973
+ const [error, setError] = React.useState(null);
974
+ const [notice, setNotice] = React.useState(null);
975
+ const [entries, setEntries] = React.useState([]);
976
+ const [total, setTotal] = React.useState(0);
977
+ const [loading, setLoading] = React.useState(true);
978
+ const [busy, setBusy] = React.useState(false);
979
+ const [query, setQuery] = React.useState('');
980
+ const [settledQuery, setSettledQuery] = React.useState('');
981
+ const [scope, setScope] = React.useState('all');
982
+ const [kind, setKind] = React.useState('');
983
+ const [project, setProject] = React.useState('');
984
+ const [formOpen, setFormOpen] = React.useState(false);
985
+ const [tab, setTab] = React.useState('memories');
986
+ const [disputes, setDisputes] = React.useState([]);
987
+ const [draft, setDraft] = React.useState({ scope: 'global', kind: 'fact', title: '', body: '', tags: '' });
988
+ const [personaDraft, setPersonaDraft] = React.useState('');
989
+ const [personaLocked, setPersonaLocked] = React.useState(false);
990
+ const [personaLoaded, setPersonaLoaded] = React.useState(false);
991
+ const [personaBusy, setPersonaBusy] = React.useState(false);
992
+ const loadOverview = React.useCallback(async () => {
993
+ if (api === undefined)
994
+ return;
995
+ try {
996
+ setOverview(await api.overview());
997
+ }
998
+ catch (failure) {
999
+ setError(errorText(failure));
1000
+ }
1001
+ }, [api]);
1002
+ const loadEntries = React.useCallback(async () => {
1003
+ if (api === undefined)
1004
+ return;
1005
+ setLoading(true);
1006
+ try {
1007
+ const result = await api.list({
1008
+ project,
1009
+ scope: scope === 'all' ? '' : scope,
1010
+ query: settledQuery,
1011
+ kind,
1012
+ limit: 100,
1013
+ });
1014
+ setEntries(result?.entries ?? []);
1015
+ setTotal(result?.total ?? 0);
1016
+ setError(null);
1017
+ }
1018
+ catch (failure) {
1019
+ setError(errorText(failure));
1020
+ }
1021
+ finally {
1022
+ setLoading(false);
1023
+ }
1024
+ }, [api, project, scope, kind, settledQuery]);
1025
+ // Debounce typing so a search does not issue one call per keystroke.
1026
+ React.useEffect(() => {
1027
+ const timer = setTimeout(() => setSettledQuery(query), 250);
1028
+ return () => clearTimeout(timer);
1029
+ }, [query]);
1030
+ // A decision waits for a person, so the count has to be visible without
1031
+ // opening the tab — otherwise it is a question nobody knows was asked.
1032
+ const loadDisputes = React.useCallback(async () => {
1033
+ if (api === undefined || typeof api.disputes !== 'function')
1034
+ return;
1035
+ try {
1036
+ const result = await api.disputes();
1037
+ setDisputes(result?.disputes ?? []);
1038
+ }
1039
+ catch (failure) {
1040
+ setError(errorText(failure));
1041
+ }
1042
+ }, [api]);
1043
+ const loadPersona = React.useCallback(async () => {
1044
+ if (api === undefined || typeof api.persona !== 'function')
1045
+ return;
1046
+ try {
1047
+ const result = await api.persona();
1048
+ setPersonaDraft(result?.text ?? '');
1049
+ setPersonaLocked(result?.locked === true);
1050
+ setPersonaLoaded(true);
1051
+ setError(null);
1052
+ }
1053
+ catch (failure) {
1054
+ setError(errorText(failure));
1055
+ }
1056
+ }, [api]);
1057
+ // The profile is only read when its tab is opened: it is a document the
1058
+ // user edits, not page furniture.
1059
+ React.useEffect(() => {
1060
+ if (tab === 'persona' && !personaLoaded)
1061
+ void loadPersona();
1062
+ }, [tab, personaLoaded, loadPersona]);
1063
+ React.useEffect(() => { void loadOverview(); }, [loadOverview]);
1064
+ React.useEffect(() => { void loadEntries(); }, [loadEntries]);
1065
+ React.useEffect(() => { void loadDisputes(); }, [loadDisputes]);
1066
+ // Preselect the newest project so the project filter has a subject.
1067
+ React.useEffect(() => {
1068
+ if (project !== '' || overview === null)
1069
+ return;
1070
+ const first = overview.projects?.[0];
1071
+ if (first !== undefined)
1072
+ setProject(first.slug);
1073
+ }, [overview, project]);
1074
+ const refresh = async () => {
1075
+ await Promise.all([loadOverview(), loadEntries(), loadDisputes()]);
1076
+ };
1077
+ /** Accept or reject one waiting decision, then reload what it changed. */
1078
+ const onResolve = async (row, decision) => {
1079
+ if (api === undefined || typeof api.resolveDispute !== 'function') {
1080
+ setError(copy.unavailable);
1081
+ return;
1082
+ }
1083
+ setBusy(true);
1084
+ setNotice(null);
1085
+ try {
1086
+ // One object keyed by the descriptor's own parameter names: the Remote
1087
+ // wrapper maps those fields onto the gateway's positional arguments, so
1088
+ // a positional call arrives as no arguments at all.
1089
+ setNotice(await api.resolveDispute({ id: row.id, decision }));
1090
+ await refresh();
1091
+ setError(null);
1092
+ }
1093
+ catch (failure) {
1094
+ setError(errorText(failure));
1095
+ }
1096
+ finally {
1097
+ setBusy(false);
1098
+ }
1099
+ };
1100
+ const onSavePersona = async () => {
1101
+ if (api === undefined || typeof api.savePersona !== 'function') {
1102
+ setError(copy.unavailable);
1103
+ return;
1104
+ }
1105
+ setPersonaBusy(true);
1106
+ setNotice(null);
1107
+ try {
1108
+ // One object keyed by the wire fields, like every other Remote call.
1109
+ const result = await api.savePersona({ text: personaDraft, locked: personaLocked });
1110
+ setPersonaDraft(result?.text ?? '');
1111
+ setPersonaLocked(result?.locked === true);
1112
+ setPersonaLoaded(true);
1113
+ setNotice(copy.personaSaved);
1114
+ setError(null);
1115
+ }
1116
+ catch (failure) {
1117
+ setError(errorText(failure));
1118
+ }
1119
+ finally {
1120
+ setPersonaBusy(false);
1121
+ }
1122
+ };
1123
+ const onForget = async (entry) => {
1124
+ if (api === undefined)
1125
+ return;
1126
+ if (typeof window !== 'undefined' && !window.confirm(copy.confirm))
1127
+ return;
1128
+ setBusy(true);
1129
+ setNotice(null);
1130
+ try {
1131
+ await api.forget({ project, scope: entry.scope, id: entry.id });
1132
+ setNotice(copy.removed);
1133
+ await refresh();
1134
+ }
1135
+ catch (failure) {
1136
+ setError(errorText(failure));
1137
+ }
1138
+ finally {
1139
+ setBusy(false);
1140
+ }
1141
+ };
1142
+ const onPromote = async (staged) => {
1143
+ if (api === undefined)
1144
+ return;
1145
+ setBusy(true);
1146
+ try {
1147
+ const result = await api.promoteSkill({ name: staged.name });
1148
+ setNotice(`${copy.promoted}: ${result.path}`);
1149
+ await refresh();
1150
+ }
1151
+ catch (failure) {
1152
+ setError(errorText(failure));
1153
+ }
1154
+ finally {
1155
+ setBusy(false);
1156
+ }
1157
+ };
1158
+ const onDiscard = async (staged) => {
1159
+ if (api === undefined)
1160
+ return;
1161
+ setBusy(true);
1162
+ try {
1163
+ await api.discardSkill({ name: staged.name });
1164
+ await refresh();
1165
+ }
1166
+ catch (failure) {
1167
+ setError(errorText(failure));
1168
+ }
1169
+ finally {
1170
+ setBusy(false);
1171
+ }
1172
+ };
1173
+ const onSubmit = async (event) => {
1174
+ event.preventDefault();
1175
+ if (api === undefined)
1176
+ return;
1177
+ if (draft.title.trim().length === 0 || draft.body.trim().length === 0) {
1178
+ setError(copy.needTitle);
1179
+ return;
1180
+ }
1181
+ setBusy(true);
1182
+ setError(null);
1183
+ try {
1184
+ await api.add({ ...draft, project });
1185
+ setDraft({ scope: draft.scope, kind: draft.kind, title: '', body: '', tags: '' });
1186
+ setFormOpen(false);
1187
+ setNotice(copy.saved);
1188
+ await refresh();
1189
+ }
1190
+ catch (failure) {
1191
+ setError(errorText(failure));
1192
+ }
1193
+ finally {
1194
+ setBusy(false);
1195
+ }
1196
+ };
1197
+ const setDraftField = (field, value) => setDraft((previous) => ({ ...previous, [field]: value }));
1198
+ const kindOptions = (overview?.kinds ?? ['preference', 'failure', 'procedure', 'knowledge', 'fact']).map((value) => h('option', { key: value, value }, copy.kindLabels[value] ?? value));
1199
+ // The host is the authority on shape, but a missing array must degrade to an
1200
+ // empty list rather than blank the whole page.
1201
+ const projects = overview?.projects ?? [];
1202
+ const staged = overview?.drafts ?? [];
1203
+ const head = h('div', { key: 'head', className: 'dshm-head' }, [
1204
+ h('h2', { key: 'title', className: 'dshm-title' }, copy.title),
1205
+ ]);
1206
+ const stats = overview === null ? null : h('p', { key: 'stats', className: 'dshm-note' }, [
1207
+ `${copy.global} ${overview.globalCount ?? 0} ${copy.unit}`,
1208
+ ' · ',
1209
+ projects.map((row) => `${row.name} ${row.count}`).join(' · ') || `${copy.project} 0 ${copy.unit}`,
1210
+ ]);
1211
+ const toolbar = h('div', { key: 'toolbar', className: 'dshm-toolbar' }, [
1212
+ h('input', {
1213
+ key: 'search',
1214
+ className: 'dshm-input dshm-grow',
1215
+ type: 'search',
1216
+ value: query,
1217
+ placeholder: copy.search,
1218
+ disabled: api === undefined,
1219
+ onChange: (event) => setQuery(event.target.value),
1220
+ }),
1221
+ h('select', {
1222
+ key: 'scope',
1223
+ className: 'dshm-select',
1224
+ value: scope,
1225
+ disabled: api === undefined,
1226
+ onChange: (event) => setScope(event.target.value),
1227
+ }, [
1228
+ h('option', { key: 'all', value: 'all' }, copy.allScopes),
1229
+ h('option', { key: 'global', value: 'global' }, copy.global),
1230
+ h('option', { key: 'project', value: 'project' }, copy.project),
1231
+ ]),
1232
+ h('select', {
1233
+ key: 'kind',
1234
+ className: 'dshm-select',
1235
+ value: kind,
1236
+ disabled: api === undefined,
1237
+ onChange: (event) => setKind(event.target.value),
1238
+ }, [h('option', { key: 'any', value: '' }, copy.allKinds), ...kindOptions]),
1239
+ h('select', {
1240
+ key: 'project',
1241
+ className: 'dshm-select',
1242
+ value: project,
1243
+ disabled: api === undefined || projects.length === 0,
1244
+ onChange: (event) => setProject(event.target.value),
1245
+ }, projects.map((row) => h('option', { key: row.slug, value: row.slug }, `${row.name} (${row.count})`))),
1246
+ h('button', {
1247
+ key: 'add',
1248
+ type: 'button',
1249
+ className: 'dshm-btn dshm-btn-primary',
1250
+ disabled: api === undefined,
1251
+ onClick: () => setFormOpen((open) => !open),
1252
+ }, copy.add),
1253
+ ]);
1254
+ const form = formOpen ? h('form', { key: 'form', className: 'dshm-form', onSubmit }, [
1255
+ h('div', { key: 'row', className: 'dshm-form-row' }, [
1256
+ h('select', {
1257
+ key: 'scope',
1258
+ className: 'dshm-select',
1259
+ value: draft.scope,
1260
+ onChange: (event) => setDraftField('scope', event.target.value),
1261
+ }, [
1262
+ h('option', { key: 'global', value: 'global' }, copy.global),
1263
+ h('option', { key: 'project', value: 'project' }, copy.project),
1264
+ ]),
1265
+ h('select', {
1266
+ key: 'kind',
1267
+ className: 'dshm-select',
1268
+ value: draft.kind,
1269
+ onChange: (event) => setDraftField('kind', event.target.value),
1270
+ }, kindOptions),
1271
+ ]),
1272
+ h('input', {
1273
+ key: 'title',
1274
+ className: 'dshm-input',
1275
+ style: { width: '100%' },
1276
+ value: draft.title,
1277
+ placeholder: copy.titlePlaceholder,
1278
+ onChange: (event) => setDraftField('title', event.target.value),
1279
+ }),
1280
+ h('textarea', {
1281
+ key: 'body',
1282
+ className: 'dshm-area',
1283
+ value: draft.body,
1284
+ placeholder: copy.bodyPlaceholder,
1285
+ onChange: (event) => setDraftField('body', event.target.value),
1286
+ }),
1287
+ h('input', {
1288
+ key: 'tags',
1289
+ className: 'dshm-input',
1290
+ style: { width: '100%' },
1291
+ value: draft.tags,
1292
+ placeholder: copy.tagsPlaceholder,
1293
+ onChange: (event) => setDraftField('tags', event.target.value),
1294
+ }),
1295
+ h('div', { key: 'actions', className: 'dshm-actions' }, [
1296
+ h('button', { key: 'save', type: 'submit', className: 'dshm-btn dshm-btn-primary', disabled: busy }, copy.save),
1297
+ h('button', { key: 'cancel', type: 'button', className: 'dshm-btn', onClick: () => setFormOpen(false) }, copy.cancel),
1298
+ ]),
1299
+ ]) : null;
1300
+ const list = loading && entries.length === 0
1301
+ ? h('p', { key: 'loading', className: 'dshm-empty' }, copy.loading)
1302
+ : entries.length === 0
1303
+ ? h('p', { key: 'empty', className: 'dshm-empty' }, copy.empty)
1304
+ : h('ul', { key: 'list', className: 'dshm-list' }, entries.map((entry) => h(EntryRow, { key: `${entry.scope}:${entry.id}`, entry, copy, busy, onForget })));
1305
+ const drafts = staged.length > 0
1306
+ ? h('section', { key: 'drafts', className: 'dshm-card' }, [
1307
+ h('h3', { key: 'title', className: 'dshm-section-title' }, copy.drafts),
1308
+ h('ul', { key: 'list', className: 'dshm-list' }, staged.map((row) => h(DraftRow, { key: row.name, draft: row, copy, busy, onPromote, onDiscard }))),
1309
+ ])
1310
+ : null;
1311
+ const tabList = h('div', { key: 'tabs', className: 'dshm-tabs', role: 'tablist' }, [
1312
+ h('button', {
1313
+ key: 'memories',
1314
+ type: 'button',
1315
+ role: 'tab',
1316
+ 'aria-selected': tab === 'memories',
1317
+ className: `dshm-tab${tab === 'memories' ? ' dshm-tab-active' : ''}`,
1318
+ onClick: () => setTab('memories'),
1319
+ }, copy.tabMemories),
1320
+ h('button', {
1321
+ key: 'persona',
1322
+ type: 'button',
1323
+ role: 'tab',
1324
+ 'aria-selected': tab === 'persona',
1325
+ className: `dshm-tab${tab === 'persona' ? ' dshm-tab-active' : ''}${personaLocked ? ' dshm-tab-locked' : ''}`,
1326
+ onClick: () => setTab('persona'),
1327
+ }, personaLocked ? `🔒 ${copy.tabPersona}` : copy.tabPersona),
1328
+ h('button', {
1329
+ key: 'config',
1330
+ type: 'button',
1331
+ role: 'tab',
1332
+ 'aria-selected': tab === 'config',
1333
+ className: `dshm-tab${tab === 'config' ? ' dshm-tab-active' : ''}`,
1334
+ onClick: () => setTab('config'),
1335
+ }, copy.tabConfig),
1336
+ h('button', {
1337
+ key: 'disputes',
1338
+ type: 'button',
1339
+ role: 'tab',
1340
+ 'aria-selected': tab === 'disputes',
1341
+ className: `dshm-tab${tab === 'disputes' ? ' dshm-tab-active' : ''}${disputes.length > 0 ? ' dshm-tab-alert' : ''}`,
1342
+ onClick: () => setTab('disputes'),
1343
+ }, disputes.length > 0 ? `${copy.tabDisputes} (${disputes.length})` : copy.tabDisputes),
1344
+ ]);
1345
+ // The two tabs keep the store's CONTENT and the plugin's SETTINGS apart: one
1346
+ // page, one place to look, and neither surface buries the other.
1347
+ const memoriesPanel = h('div', { key: 'panel-memories', role: 'tabpanel', className: 'dshm-panel' }, [
1348
+ api === undefined ? h('p', { key: 'unavailable', className: 'dshm-status dshm-error' }, copy.unavailable) : null,
1349
+ overview !== null && stats !== null ? stats : null,
1350
+ toolbar,
1351
+ form,
1352
+ h('p', { key: 'count', className: 'dshm-note' }, `${entries.length} / ${total} ${copy.unit}`),
1353
+ list,
1354
+ drafts,
1355
+ error !== null ? h('p', { key: 'error', className: 'dshm-status dshm-error' }, error) : null,
1356
+ notice !== null ? h('p', { key: 'notice', className: 'dshm-status dshm-ok' }, notice) : null,
1357
+ ]);
1358
+ const configPanel = h('div', { key: 'panel-config', role: 'tabpanel', className: 'dshm-panel' }, [
1359
+ h(Card, {
1360
+ key: 'tunables',
1361
+ scope: props.scope,
1362
+ useSnapshot: props.useSnapshot,
1363
+ title: copy.tunables,
1364
+ intro: false,
1365
+ lang: copy.lang,
1366
+ }),
1367
+ ]);
1368
+ const personaPanel = h('div', { key: 'panel-persona', role: 'tabpanel', className: 'dshm-panel' }, [
1369
+ h('p', { key: 'intro', className: 'dshm-note' }, copy.personaIntro),
1370
+ api === undefined || typeof api.savePersona !== 'function'
1371
+ ? h('p', { key: 'unavailable', className: 'dshm-status dshm-error' }, copy.unavailable)
1372
+ : null,
1373
+ h('textarea', {
1374
+ key: 'text',
1375
+ className: 'dshm-area',
1376
+ rows: 14,
1377
+ value: personaDraft,
1378
+ placeholder: copy.personaPlaceholder,
1379
+ disabled: api === undefined || personaBusy,
1380
+ onChange: (event) => setPersonaDraft(event.target.value),
1381
+ }),
1382
+ h('label', { key: 'lock', className: 'dshm-inline' }, [
1383
+ h('input', {
1384
+ key: 'input',
1385
+ className: 'dshm-check',
1386
+ type: 'checkbox',
1387
+ checked: personaLocked,
1388
+ disabled: api === undefined || personaBusy,
1389
+ onChange: (event) => setPersonaLocked(event.target.checked),
1390
+ }),
1391
+ copy.personaLock,
1392
+ ]),
1393
+ h('p', { key: 'lock-hint', className: 'dshm-note' }, copy.personaLockHint),
1394
+ h('p', { key: 'budget', className: 'dshm-note' }, copy.personaBudgetNote),
1395
+ h('div', { key: 'actions', className: 'dshm-actions' }, [
1396
+ h('button', {
1397
+ key: 'save',
1398
+ type: 'button',
1399
+ className: 'dshm-btn dshm-btn-primary',
1400
+ disabled: personaBusy || api === undefined,
1401
+ onClick: onSavePersona,
1402
+ }, copy.personaSave),
1403
+ ]),
1404
+ notice !== null ? h('p', { key: 'notice', className: 'dshm-status dshm-ok' }, notice) : null,
1405
+ error !== null ? h('p', { key: 'error', className: 'dshm-status dshm-error' }, error) : null,
1406
+ ]);
1407
+ // Only the decisions a pass refused to make alone. Each row is one reading
1408
+ // of the disputed text with the change marked in place, and a scope move is
1409
+ // stated in the head rather than buried in the reason sentence.
1410
+ const disputeRows = disputes.map((row) => {
1411
+ const parsed = splitDisputeReason(row.reason);
1412
+ return h('li', { key: `${row.action}:${row.id}`, className: 'dshm-entry' }, [
1413
+ h('div', { key: 'head', className: 'dshm-entry-head' }, [
1414
+ h('h4', { key: 'title', className: 'dshm-entry-title' }, row.title),
1415
+ parsed.scope === null ? null : h('span', { key: 'scope', className: 'dshm-scope' }, [
1416
+ h('span', { key: 'from' }, scopeText(copy, parsed.scope.from)),
1417
+ h('span', { key: 'arrow', className: 'dshm-scope-arrow', 'aria-hidden': true }, '→'),
1418
+ h('span', { key: 'to' }, scopeText(copy, parsed.scope.to)),
1419
+ ]),
1420
+ h('span', { key: 'action', className: 'dshm-badge dshm-badge-global' }, row.action === 'retire' ? copy.disputeRetire : copy.disputeRewrite),
1421
+ ]),
1422
+ parsed.reasons.length === 0 ? null : h('div', { key: 'reasons', className: 'dshm-reasons' }, parsed.reasons.map((text, at) => h('span', { key: `${at}:${text}`, className: 'dshm-badge' }, text))),
1423
+ disputeBody(row),
1424
+ h('div', { key: 'actions', className: 'dshm-actions' }, [
1425
+ h('button', {
1426
+ key: 'accept',
1427
+ type: 'button',
1428
+ className: 'dshm-btn dshm-btn-primary',
1429
+ disabled: busy,
1430
+ onClick: () => onResolve(row, 'accept'),
1431
+ }, copy.accept),
1432
+ h('button', {
1433
+ key: 'reject',
1434
+ type: 'button',
1435
+ className: 'dshm-btn',
1436
+ disabled: busy,
1437
+ onClick: () => onResolve(row, 'reject'),
1438
+ }, copy.reject),
1439
+ ]),
1440
+ ]);
1441
+ });
1442
+ const disputesPanel = h('div', { key: 'panel-disputes', role: 'tabpanel', className: 'dshm-panel' }, [
1443
+ h('h3', { key: 'title', className: 'dshm-section-title' }, copy.disputesTitle),
1444
+ h('p', { key: 'intro', className: 'dshm-note' }, copy.disputesIntro),
1445
+ api === undefined ? h('p', { key: 'unavailable', className: 'dshm-status dshm-error' }, copy.unavailable) : null,
1446
+ disputeRows.length > 0
1447
+ ? h('ul', { key: 'list', className: 'dshm-list' }, disputeRows)
1448
+ : h('p', { key: 'empty', className: 'dshm-note' }, copy.noDisputes),
1449
+ notice !== null ? h('p', { key: 'notice', className: 'dshm-status dshm-ok' }, notice) : null,
1450
+ error !== null ? h('p', { key: 'error', className: 'dshm-status dshm-error' }, error) : null,
1451
+ ]);
1452
+ const children = [head];
1453
+ if (overview !== null)
1454
+ children.push(h('p', { key: 'store', className: 'dshm-path' }, `${copy.store}: ${overview.storePath}`));
1455
+ children.push(tabList);
1456
+ children.push(tab === 'config' ? configPanel : tab === 'disputes' ? disputesPanel : tab === 'persona' ? personaPanel : memoriesPanel);
1457
+ return h('div', { className: 'dshm-page' }, children);
1458
+ };
1459
1459
  }
1460
1460
 
1461
- // ---- client/styles.js ----
1461
+ // ---- .client-build/parts/styles.js ----
1462
+ "use strict";
1462
1463
  /**
1463
1464
  * Stylesheet shared by the settings card and the Memories settings page.
1464
1465
  *
@@ -1468,91 +1469,92 @@ window.__ModuleLoader__.load({
1468
1469
  * `data-plugin-css`, which is what the HMR driver uses to retire a bundle's
1469
1470
  * owned styles.
1470
1471
  */
1471
-
1472
- /** The stylesheet text. */
1473
- const CSS = [
1474
- '.dshm-page{display:flex;flex-direction:column;gap:14px;max-width:760px}',
1475
- '.dshm-card{display:flex;flex-direction:column;gap:12px;border:.5px solid var(--dsw-alias-border-l4);border-radius:16px;padding:14px 16px;background:var(--dsw-alias-bg-module-platform);max-width:720px}',
1476
- '.dshm-head{display:flex;align-items:baseline;gap:8px}',
1477
- '.dshm-title{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:500;line-height:22px;margin:0}',
1478
- '.dshm-ns{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px;font-family:var(--ds-font-family-code)}',
1479
- '.dshm-intro{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px;margin:0}',
1480
- '.dshm-row{display:flex;align-items:flex-start;gap:12px;padding:8px 0;border-top:.5px solid var(--dsw-alias-border-l2)}',
1481
- '.dshm-row:first-of-type{border-top:none}',
1482
- '.dshm-label{display:flex;flex-direction:column;gap:2px;min-width:0;flex:1}',
1483
- '.dshm-label>span:first-child{color:var(--dsw-alias-label-primary);font-size:13px;line-height:20px}',
1484
- '.dshm-hint{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}',
1485
- '.dshm-control{flex:none;display:flex;align-items:center;gap:8px}',
1486
- '.dshm-input{box-sizing:border-box;width:150px;height:30px;font:inherit;font-size:13px;padding:0 8px;border-radius:8px;border:.5px solid var(--dsw-alias-border-l4);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary)}',
1487
- '.dshm-input:focus{outline:none;border-color:var(--dsw-alias-brand-primary)}',
1488
- '.dshm-input:disabled{opacity:.6}',
1489
- '.dshm-check{width:16px;height:16px;accent-color:var(--dsw-alias-brand-primary)}',
1490
- '.dshm-inline{display:flex;align-items:center;gap:8px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary);cursor:pointer}',
1491
- '.dshm-reset{height:26px;padding:0 8px;font:inherit;font-size:12px;border-radius:13px;border:.5px solid var(--dsw-alias-border-l3);background:transparent;color:var(--dsw-alias-label-tertiary);cursor:pointer}',
1492
- '.dshm-reset:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}',
1493
- '.dshm-status{font-size:12px;line-height:18px;margin:0}',
1494
- '.dshm-error{color:var(--dsw-alias-state-error-primary)}',
1495
- '.dshm-ok{color:var(--dsw-alias-state-success-primary)}',
1496
- '.dshm-note{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px;margin:0}',
1497
- '.dshm-path{font-family:var(--ds-font-family-code);font-size:11px;color:var(--dsw-alias-label-tertiary);word-break:break-all}',
1498
- '.dshm-toolbar{display:flex;flex-wrap:wrap;gap:8px;align-items:center}',
1499
- '.dshm-grow{flex:1;min-width:180px;width:auto}',
1500
- '.dshm-select{height:30px;font:inherit;font-size:13px;padding:0 6px;border-radius:8px;border:.5px solid var(--dsw-alias-border-l4);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary)}',
1501
- '.dshm-list{display:flex;flex-direction:column;gap:8px;margin:0;padding:0;list-style:none}',
1502
- '.dshm-entry{display:flex;flex-direction:column;gap:6px;border:.5px solid var(--dsw-alias-border-l2);border-radius:12px;padding:10px 12px;background:var(--dsw-alias-bg-layer-1)}',
1503
- '.dshm-entry-head{display:flex;flex-wrap:wrap;align-items:baseline;gap:8px}',
1504
- '.dshm-entry-title{color:var(--dsw-alias-label-primary);font-size:13px;font-weight:500;line-height:20px;margin:0;flex:1;min-width:120px}',
1505
- '.dshm-badge{font-size:11px;line-height:16px;padding:0 6px;border-radius:8px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);white-space:nowrap}',
1506
- '.dshm-badge-global{background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary)}',
1507
- '.dshm-body{white-space:pre-wrap;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:19px;margin:0}',
1508
- // A disputed body is one reading with the change marked in place: no before/
1509
- // after captions, the struck error run is what the pass removes and the
1510
- // success run is what it adds. Both tints are mixed from theme state tokens,
1511
- // so the marks keep their contrast in the dark theme too.
1512
- '.dshm-diff{white-space:pre-wrap;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:19px;margin:0}',
1513
- '.dshm-del{color:var(--dsw-alias-state-error-primary);background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 14%,transparent);border-radius:3px;padding:0 1px;text-decoration:line-through}',
1514
- '.dshm-ins{color:var(--dsw-alias-state-success-primary);background:color-mix(in srgb,var(--dsw-alias-state-success-primary) 14%,transparent);border-radius:3px;padding:0 1px;text-decoration:none}',
1515
- '.dshm-retire{color:var(--dsw-alias-label-tertiary);text-decoration:line-through}',
1516
- // The scope move is a fact about the row, so it sits in the head next to the
1517
- // action badge; the grounds stay as individual badges instead of one paragraph.
1518
- '.dshm-scope{display:inline-flex;align-items:center;gap:4px;font-size:11px;line-height:16px;padding:0 6px;border-radius:8px;background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary);white-space:nowrap}',
1519
- '.dshm-scope-arrow{color:var(--dsw-alias-label-tertiary)}',
1520
- '.dshm-reasons{display:flex;flex-wrap:wrap;gap:4px}',
1521
- '.dshm-meta{color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:16px;display:flex;flex-wrap:wrap;gap:8px}',
1522
- '.dshm-actions{display:flex;gap:6px;flex-wrap:wrap}',
1523
- '.dshm-btn{height:26px;padding:0 10px;font:inherit;font-size:12px;border-radius:13px;border:.5px solid var(--dsw-alias-border-l3);background:transparent;color:var(--dsw-alias-label-secondary);cursor:pointer}',
1524
- '.dshm-btn:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}',
1525
- '.dshm-btn:disabled{opacity:.5;cursor:default}',
1526
- '.dshm-btn-primary{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary)}',
1527
- '.dshm-empty{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px;margin:0}',
1528
- '.dshm-form{display:flex;flex-direction:column;gap:8px;border:.5px solid var(--dsw-alias-border-l2);border-radius:12px;padding:12px;background:var(--dsw-alias-bg-layer-1)}',
1529
- '.dshm-form-row{display:flex;gap:8px;flex-wrap:wrap}',
1530
- '.dshm-area{box-sizing:border-box;width:100%;min-height:64px;font:inherit;font-size:13px;padding:6px 8px;border-radius:8px;border:.5px solid var(--dsw-alias-border-l4);background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-primary);resize:vertical}',
1531
- '.dshm-area:focus{outline:none;border-color:var(--dsw-alias-brand-primary)}',
1532
- '.dshm-section-title{color:var(--dsw-alias-label-primary);font-size:13px;font-weight:500;line-height:20px;margin:0}',
1533
- '.dshm-tabs{display:flex;gap:4px;border-bottom:.5px solid var(--dsw-alias-border-l2);padding-bottom:4px}',
1534
- '.dshm-tab{height:28px;padding:0 12px;font:inherit;font-size:13px;border:none;border-radius:8px;background:transparent;color:var(--dsw-alias-label-tertiary);cursor:pointer}',
1535
- '.dshm-tab:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}',
1536
- '.dshm-tab-active{background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);font-weight:500}',
1537
- // A tab that is waiting for a decision has to look like it: the point of the
1538
- // disputed subset is that somebody notices it among everything else.
1539
- '.dshm-tab-alert{color:var(--dsw-alias-label-primary);box-shadow:inset 0 -2px 0 0 var(--dsw-alias-brand-primary,#d97706)}',
1540
- '.dshm-panel{display:flex;flex-direction:column;gap:12px}',
1541
- ].join('\n')
1542
-
1472
+ /** The stylesheet text (`CSS` itself is a DOM global, hence the other name). */
1473
+ const STYLESHEET = [
1474
+ '.dshm-page{display:flex;flex-direction:column;gap:14px;max-width:760px}',
1475
+ '.dshm-card{display:flex;flex-direction:column;gap:12px;border:.5px solid var(--dsw-alias-border-l4);border-radius:16px;padding:14px 16px;background:var(--dsw-alias-bg-module-platform);max-width:720px}',
1476
+ '.dshm-head{display:flex;align-items:baseline;gap:8px}',
1477
+ '.dshm-title{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:500;line-height:22px;margin:0}',
1478
+ '.dshm-ns{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px;font-family:var(--ds-font-family-code)}',
1479
+ '.dshm-intro{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px;margin:0}',
1480
+ '.dshm-row{display:flex;align-items:flex-start;gap:12px;padding:8px 0;border-top:.5px solid var(--dsw-alias-border-l2)}',
1481
+ '.dshm-row:first-of-type{border-top:none}',
1482
+ '.dshm-label{display:flex;flex-direction:column;gap:2px;min-width:0;flex:1}',
1483
+ '.dshm-label>span:first-child{color:var(--dsw-alias-label-primary);font-size:13px;line-height:20px}',
1484
+ '.dshm-hint{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}',
1485
+ '.dshm-control{flex:none;display:flex;align-items:center;gap:8px}',
1486
+ '.dshm-input{box-sizing:border-box;width:150px;height:30px;font:inherit;font-size:13px;padding:0 8px;border-radius:8px;border:.5px solid var(--dsw-alias-border-l4);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary)}',
1487
+ '.dshm-input:focus{outline:none;border-color:var(--dsw-alias-brand-primary)}',
1488
+ '.dshm-input:disabled{opacity:.6}',
1489
+ '.dshm-check{width:16px;height:16px;accent-color:var(--dsw-alias-brand-primary)}',
1490
+ '.dshm-inline{display:flex;align-items:center;gap:8px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary);cursor:pointer}',
1491
+ '.dshm-reset{height:26px;padding:0 8px;font:inherit;font-size:12px;border-radius:13px;border:.5px solid var(--dsw-alias-border-l3);background:transparent;color:var(--dsw-alias-label-tertiary);cursor:pointer}',
1492
+ '.dshm-reset:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}',
1493
+ '.dshm-status{font-size:12px;line-height:18px;margin:0}',
1494
+ '.dshm-error{color:var(--dsw-alias-state-error-primary)}',
1495
+ '.dshm-ok{color:var(--dsw-alias-state-success-primary)}',
1496
+ '.dshm-note{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px;margin:0}',
1497
+ '.dshm-path{font-family:var(--ds-font-family-code);font-size:11px;color:var(--dsw-alias-label-tertiary);word-break:break-all}',
1498
+ '.dshm-toolbar{display:flex;flex-wrap:wrap;gap:8px;align-items:center}',
1499
+ '.dshm-grow{flex:1;min-width:180px;width:auto}',
1500
+ '.dshm-select{height:30px;font:inherit;font-size:13px;padding:0 6px;border-radius:8px;border:.5px solid var(--dsw-alias-border-l4);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary)}',
1501
+ '.dshm-list{display:flex;flex-direction:column;gap:8px;margin:0;padding:0;list-style:none}',
1502
+ '.dshm-entry{display:flex;flex-direction:column;gap:6px;border:.5px solid var(--dsw-alias-border-l2);border-radius:12px;padding:10px 12px;background:var(--dsw-alias-bg-layer-1)}',
1503
+ '.dshm-entry-head{display:flex;flex-wrap:wrap;align-items:baseline;gap:8px}',
1504
+ '.dshm-entry-title{color:var(--dsw-alias-label-primary);font-size:13px;font-weight:500;line-height:20px;margin:0;flex:1;min-width:120px}',
1505
+ '.dshm-badge{font-size:11px;line-height:16px;padding:0 6px;border-radius:8px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);white-space:nowrap}',
1506
+ '.dshm-badge-global{background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary)}',
1507
+ '.dshm-body{white-space:pre-wrap;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:19px;margin:0}',
1508
+ // A disputed body is one reading with the change marked in place: no before/
1509
+ // after captions, the struck error run is what the pass removes and the
1510
+ // success run is what it adds. Both tints are mixed from theme state tokens,
1511
+ // so the marks keep their contrast in the dark theme too.
1512
+ '.dshm-diff{white-space:pre-wrap;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:19px;margin:0}',
1513
+ '.dshm-del{color:var(--dsw-alias-state-error-primary);background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 14%,transparent);border-radius:3px;padding:0 1px;text-decoration:line-through}',
1514
+ '.dshm-ins{color:var(--dsw-alias-state-success-primary);background:color-mix(in srgb,var(--dsw-alias-state-success-primary) 14%,transparent);border-radius:3px;padding:0 1px;text-decoration:none}',
1515
+ '.dshm-retire{color:var(--dsw-alias-label-tertiary);text-decoration:line-through}',
1516
+ // The scope move is a fact about the row, so it sits in the head next to the
1517
+ // action badge; the grounds stay as individual badges instead of one paragraph.
1518
+ '.dshm-scope{display:inline-flex;align-items:center;gap:4px;font-size:11px;line-height:16px;padding:0 6px;border-radius:8px;background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary);white-space:nowrap}',
1519
+ '.dshm-scope-arrow{color:var(--dsw-alias-label-tertiary)}',
1520
+ '.dshm-reasons{display:flex;flex-wrap:wrap;gap:4px}',
1521
+ '.dshm-meta{color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:16px;display:flex;flex-wrap:wrap;gap:8px}',
1522
+ '.dshm-actions{display:flex;gap:6px;flex-wrap:wrap}',
1523
+ '.dshm-btn{height:26px;padding:0 10px;font:inherit;font-size:12px;border-radius:13px;border:.5px solid var(--dsw-alias-border-l3);background:transparent;color:var(--dsw-alias-label-secondary);cursor:pointer}',
1524
+ '.dshm-btn:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}',
1525
+ '.dshm-btn:disabled{opacity:.5;cursor:default}',
1526
+ '.dshm-btn-primary{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary)}',
1527
+ '.dshm-empty{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px;margin:0}',
1528
+ '.dshm-form{display:flex;flex-direction:column;gap:8px;border:.5px solid var(--dsw-alias-border-l2);border-radius:12px;padding:12px;background:var(--dsw-alias-bg-layer-1)}',
1529
+ '.dshm-form-row{display:flex;gap:8px;flex-wrap:wrap}',
1530
+ '.dshm-area{box-sizing:border-box;width:100%;min-height:64px;font:inherit;font-size:13px;padding:6px 8px;border-radius:8px;border:.5px solid var(--dsw-alias-border-l4);background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-primary);resize:vertical}',
1531
+ '.dshm-area:focus{outline:none;border-color:var(--dsw-alias-brand-primary)}',
1532
+ '.dshm-section-title{color:var(--dsw-alias-label-primary);font-size:13px;font-weight:500;line-height:20px;margin:0}',
1533
+ '.dshm-tabs{display:flex;gap:4px;border-bottom:.5px solid var(--dsw-alias-border-l2);padding-bottom:4px}',
1534
+ '.dshm-tab{height:28px;padding:0 12px;font:inherit;font-size:13px;border:none;border-radius:8px;background:transparent;color:var(--dsw-alias-label-tertiary);cursor:pointer}',
1535
+ '.dshm-tab:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}',
1536
+ '.dshm-tab-active{background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);font-weight:500}',
1537
+ // A tab that is waiting for a decision has to look like it: the point of the
1538
+ // disputed subset is that somebody notices it among everything else.
1539
+ '.dshm-tab-alert{color:var(--dsw-alias-label-primary);box-shadow:inset 0 -2px 0 0 var(--dsw-alias-brand-primary,#d97706)}',
1540
+ '.dshm-panel{display:flex;flex-direction:column;gap:12px}',
1541
+ ].join('\n');
1543
1542
  /** Inject the stylesheet once per document. */
1544
1543
  function ensureStyles() {
1545
- if (typeof document === 'undefined') return
1546
- const id = 'dsh-cross-memory/settings.css'
1547
- if (document.querySelector(`style[data-plugin-css=${JSON.stringify(id)}]`) !== null) return
1548
- const tag = document.createElement('style')
1549
- tag.dataset.plugin = 'dsh-cross-memory'
1550
- tag.dataset.pluginCss = id
1551
- tag.textContent = CSS
1552
- document.head.appendChild(tag)
1544
+ if (typeof document === 'undefined')
1545
+ return;
1546
+ const id = 'dsh-cross-memory/settings.css';
1547
+ if (document.querySelector(`style[data-plugin-css=${JSON.stringify(id)}]`) !== null)
1548
+ return;
1549
+ const tag = document.createElement('style');
1550
+ tag.dataset.plugin = 'dsh-cross-memory';
1551
+ tag.dataset.pluginCss = id;
1552
+ tag.textContent = STYLESHEET;
1553
+ document.head.appendChild(tag);
1553
1554
  }
1554
1555
 
1555
- // ---- client/index.js ----
1556
+ // ---- .client-build/index.js ----
1557
+ "use strict";
1556
1558
  /**
1557
1559
  * `dsh-cross-memory` browser half.
1558
1560
  *
@@ -1582,74 +1584,70 @@ window.__ModuleLoader__.load({
1582
1584
  * defines `PACKAGE` (the package name, from `package.json`) and injects the
1583
1585
  * host's own wire table.
1584
1586
  */
1585
-
1586
1587
  /** Copy for the active locale. */
1587
1588
  function sectionCopy(ctx) {
1588
- const locale = ctx.get('locale')
1589
- const active = typeof locale?.getLocale === 'function' ? locale.getLocale().active : undefined
1590
- const isZh = typeof active === 'string' && active.length > 0
1591
- ? active.startsWith('zh')
1592
- : typeof navigator !== 'undefined' && String(navigator.language ?? '').startsWith('zh')
1593
- return SECTION_COPY[isZh ? 'zh' : 'en']
1589
+ const locale = ctx.get('locale');
1590
+ const active = typeof locale?.getLocale === 'function' ? locale.getLocale().active : undefined;
1591
+ const isZh = typeof active === 'string' && active.length > 0
1592
+ ? active.startsWith('zh')
1593
+ : typeof navigator !== 'undefined' && String(navigator.language ?? '').startsWith('zh');
1594
+ return SECTION_COPY[isZh ? 'zh' : 'en'];
1594
1595
  }
1595
-
1596
1596
  /**
1597
1597
  * Create the browser-half plugin from the bundle's `require`.
1598
1598
  * @param require - the module system's synchronous require.
1599
1599
  * @returns the plugin's `apply` and `inject`.
1600
1600
  */
1601
1601
  function createPlugin(require) {
1602
- const React = require('react')
1603
- const Card = createMemoriesCard(React)
1604
- const Section = createMemoriesSection(React, Card)
1605
-
1606
- const apply = async (ctx) => {
1607
- ensureStyles()
1608
- // The form is shared with every other editor of this entry and owned by the
1609
- // settings provider, so this half only subscribes to it (inside
1610
- // `useSnapshot`) and never disposes it.
1611
- const scope = ctx.configForms.get(NS)
1612
- const useSnapshot = (select) => {
1613
- const [value, setValue] = React.useState(() => select(scope.getSnapshot()))
1614
- React.useEffect(() => scope.subscribe(() => setValue(select(scope.getSnapshot()))), [scope])
1615
- return value
1616
- }
1617
-
1618
- // The page is useless without the host API, but the tunables card is not, so
1619
- // a missing gateway degrades this surface instead of failing the plugin.
1620
- let api
1621
- try {
1622
- api = await mountMemoriesRemote(ctx)
1623
- } catch (failure) {
1624
- ctx.logger?.warn?.('dsh-cross-memory: remote mount failed: %o', failure)
1625
- }
1626
- ctx.slots.inject('settings.section', () => ctx.slots.register({
1627
- name: 'settings.section',
1628
- id: 'memories',
1629
- order: 25,
1630
- label: () => sectionCopy(ctx).label,
1631
- inject: () => ({ api, scope, useSnapshot, copy: sectionCopy(ctx) }),
1632
- }, Section))
1633
- // The tunables card, mounted a second time on the Plugins page: slot
1634
- // `plugins.bundle.config`, key = the package name, rendered on this bundle's
1635
- // own page between its description and its rows. That slot hands **no**
1636
- // `form` in (unlike `plugins.row.config`), so the registration's inject face
1637
- // supplies the same shared props the page's own 配置 tab supplies — the same
1638
- // `scope` and `useSnapshot`, so both editors read one form and write through
1639
- // one path. The copy is resolved inside the face, like the page's, so a
1640
- // locale switch is picked up. `PACKAGE` is defined by
1641
- // `scripts/build-client.mjs`, which also uses it as the bundle id.
1642
- ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
1643
- name: 'plugins.bundle.config',
1644
- key: PACKAGE,
1645
- inject: () => {
1646
- const copy = sectionCopy(ctx)
1647
- return { scope, useSnapshot, title: copy.tunables, intro: false, lang: copy.lang }
1648
- },
1649
- }, Card))
1650
- }
1651
-
1652
- return { apply, inject: ['slots', 'configForms'] }
1602
+ const React = require('react');
1603
+ const Card = createMemoriesCard(React);
1604
+ const Section = createMemoriesSection(React, Card);
1605
+ const apply = async (ctx) => {
1606
+ ensureStyles();
1607
+ // The form is shared with every other editor of this entry and owned by the
1608
+ // settings provider, so this half only subscribes to it (inside
1609
+ // `useSnapshot`) and never disposes it.
1610
+ const scope = ctx.configForms.get(NS);
1611
+ const useSnapshot = (select) => {
1612
+ const [value, setValue] = React.useState(() => select(scope.getSnapshot()));
1613
+ React.useEffect(() => scope.subscribe(() => setValue(select(scope.getSnapshot()))), [scope]);
1614
+ return value;
1615
+ };
1616
+ // The page is useless without the host API, but the tunables card is not, so
1617
+ // a missing gateway degrades this surface instead of failing the plugin.
1618
+ let api;
1619
+ try {
1620
+ api = await mountMemoriesRemote(ctx);
1621
+ }
1622
+ catch (failure) {
1623
+ ctx.logger?.warn?.('dsh-cross-memory: remote mount failed: %o', failure);
1624
+ }
1625
+ ctx.slots.inject('settings.section', () => ctx.slots.register({
1626
+ name: 'settings.section',
1627
+ id: 'memories',
1628
+ order: 25,
1629
+ label: () => sectionCopy(ctx).label,
1630
+ inject: () => ({ api, scope, useSnapshot, copy: sectionCopy(ctx) }),
1631
+ }, Section));
1632
+ // The tunables card, mounted a second time on the Plugins page: slot
1633
+ // `plugins.bundle.config`, key = the package name, rendered on this bundle's
1634
+ // own page between its description and its rows. That slot hands **no**
1635
+ // `form` in (unlike `plugins.row.config`), so the registration's inject face
1636
+ // supplies the same shared props the page's own 配置 tab supplies — the same
1637
+ // `scope` and `useSnapshot`, so both editors read one form and write through
1638
+ // one path. The copy is resolved inside the face, like the page's, so a
1639
+ // locale switch is picked up. `PACKAGE` is defined by
1640
+ // `scripts/build-client.mjs`, which also uses it as the bundle id.
1641
+ ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
1642
+ name: 'plugins.bundle.config',
1643
+ key: PACKAGE,
1644
+ inject: () => {
1645
+ const copy = sectionCopy(ctx);
1646
+ return { scope, useSnapshot, title: copy.tunables, intro: false, lang: copy.lang };
1647
+ },
1648
+ }, Card));
1649
+ };
1650
+ return { apply, inject: ['slots', 'configForms'] };
1653
1651
  }
1654
1652
 
1655
1653
  const plugin = createPlugin(require);