@restregular/dsh-memory 0.9.6 → 0.9.8

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/README.md CHANGED
@@ -17,6 +17,10 @@ English: Local, durable memory for DeepSeek Harness — one npm package, one loa
17
17
 
18
18
  ![记忆树](./preview/memory-tree.png)
19
19
 
20
+ 设置页「记忆 → 设置」的卡片式布局:每个开关都有可见 label、说明和状态,自动召回标签在同卡编辑。
21
+
22
+ ![设置页卡片](./preview/memory-settings.png)
23
+
20
24
  模型在对话里查记忆 —— `memory_search` 的入参与召回结果:
21
25
 
22
26
  ![memory_search 工具调用](./preview/memory-search.png)
@@ -111,13 +115,13 @@ memory_save({
111
115
  - **服务**:「向量服务」:状态、地址、启停开关、**模型与硬件**(见下)、维护(卸载向量服务 / 清空记忆数据,两步确认)
112
116
  - **记录**(默认打开):顶部统计(记忆数 / 作用域数 / 待嵌入向量数)、搜索、按作用域筛选、**新建**(任意作用域 + 类型,类型里含 `rule`)、展开编辑 / 删除;列表放在独立的滚动容器里(记忆再多也不把面板撑长),滚动条是自定义的细圆头样式,从侧栏入口打开时容器还会跟着窗口长高;作用域下拉**动态枚举实际存在的作用域**(`global` 显示「全局」、project 显示 cwd、会话 scope 显示会话标题、自定义 scope 显示原名)
113
117
  - **记忆树**:所有作用域的记忆按 **作用域 → 类型 → 记录** 三层展开,根节点显示总数;记录卡按类型着色,`supersedes` / `supersededBy` 用金色虚线把「修正版」和「被修正的旧版」连起来。支持搜索(命中高亮、其余淡出)、按类型逐个开关、按作用域筛选、折叠作用域 / 类型、缩放与「适应」、以及点击记录打开的详情抽屉(全文、标签、重要度、时间、id 与双向修正链)。修正是**关系**而不是层级,所以不改变树结构,只叠在右侧;悬停或选中一条记录时,整条修正链一起点亮
114
- - **设置**:注入链路逐项开关 —— 每轮召回(topK / 预算)、印象形态(每条字数)、会话摘要(条数 / 正文预算 / 截断标签预算 / 标签条数)、记忆使用策略段、硬性规则段(条数 / 预算 / 变更提醒,并显示当前规则条数)、轮末提醒、侧栏入口;底部「数据」:导出全部 / 导入文件。改完**即保存**,不需要点按钮
118
+ - **设置**:注入链路逐项开关 —— 每轮召回(topK / 预算)、印象形态(每条字数)、会话摘要(条数 / 正文预算 / 截断标签预算 / 标签条数)、记忆使用策略段、硬性规则段(条数 / 预算 / 变更提醒,并显示当前规则条数)、自动召回(标签 / 是否用工具 description / 是否并入记忆库标签 / 查询字数)、轮末提醒、侧栏入口;底部「数据」:导出全部 / 导入文件。改完**即保存**,不需要点按钮
115
119
 
116
120
  > **导入 / 导出**:导出的是纯文本 —— 作用域、类型、内容、标签、重要度、时间戳,**没有向量**。导入时逐条走保存路径,按**当前模型重新嵌入**,并按「作用域 + 内容」去重(重复的计入「跳过」)。一次最多 5000 条。
117
121
 
118
122
  面板后端在 `/memory/api`,全部路由:`GET /status`、`GET /records`、`GET /settings`、`POST /settings`、`GET /audit`、`POST /create`、`POST /update`、`POST /delete`、`GET /export`、`POST /import`、`GET /embed/status`、`POST /embed/start|stop`、`GET /embed/model`、`POST /embed/model/refresh|install|install/cancel|uninstall`、`POST /data/wipe`。
119
123
 
120
- ## 注入可靠性(0.9.6)
124
+ ## 注入可靠性(0.9.6 – 0.9.7)
121
125
 
122
126
  摘要和规则不再静默截断:
123
127
 
@@ -125,9 +129,11 @@ memory_save({
125
129
  - **截断标签**:正文因 `topK` / 预算没注入时,附一条独立的「相关记忆索引」——每条只给 8 位 id、标签/主题、类型、作用域,以及 `memory_search` 检索指引;标签有 `digest.hintBudget` / `digest.hintMaxItems` 独立预算。标签也溢出时报告省略数量与原因。
126
130
  - **退役规则**:被 `supersedes` 指向的旧记录不再进入摘要、规则段和自动召回;`memory_search` / `memory_get` 仍可查历史。
127
131
  - **mandatory / pinned**:规则标签里写 `mandatory` / `pinned`(或 `必含` / `强制`)的条目排在规则段最前;超预算时输出明确警告,不静默丢弃。
128
- - **行为感知召回**:监听 `session/event` 的 `tool/call` / `tool/result` / compaction。命中 `npm publish`、`git push`、部署等高风险操作,或工具失败(凭据/权限/超时/abort 分类)后,在下一个 `agent/pre-step` 用任务查询做一次增量召回;已注入正文按 **sessionId + 记忆 id/版本** 去重,只给过标签的会补正文,内容更新会重新评估。
129
- - **审计**:每次摘要/召回/规则评估写入内存审计环,`GET /memory/api/audit?session=<id>` 可查候选、正文、标签、去重、省略原因与各通道预算;不记录凭据或令牌。
130
- - **限制**:当前行为召回基于 `session/event` 的 `tool/call` / `tool/result`,召回发生在**下一个** `agent/pre-step`;宿主虽有 `tools/pre-execute`,本插件没有用它做操作前阻断,因此"发布/推送前强制检查"仍是告警 + 召回,不是硬阻断。工具失败若底层只返回 aborted,审计会保留 `ABORTED_UNKNOWN`,不会臆测成凭据问题。
132
+ - **标签触发的行为召回(0.9.7)**:设置里的 `autoRecall.tags` 是**标签**,不是正则;默认还会并入记忆库里已有的标签(`useMemoryTags`)。匹配源包括 `tool/call` 的 name / description / 参数、`tool/result` 的失败描述、可见 `assistant/message` 文本、`todo/write` 任务清单、`command/run`、`goal/change`。命中标签后,在下一个 `agent/pre-step` 用标签 + 命中片段检索;工具失败则始终用该工具调用自己的 `description`(取不到才退回错误类别)。中英标签有最小同义词映射(如 `deploy` ↔ 部署、`database` ↔ 数据库)。
133
+ - **去重**:已注入正文按 **sessionId + 记忆 id/版本** 跳过;只给过标签的会补正文;内容更新会重新评估;compaction 后重置摘要与去重状态。
134
+ - **标签可检索**:`search` 的词法通道把记录标签也并入检索文本,所以中文正文 + 英文标签也能被标签查询命中。
135
+ - **审计**:每次摘要/召回/规则评估写入内存审计环,`GET /memory/api/audit?session=<id>` 可查触发原因、阶段、候选、正文、标签、去重、省略原因与各通道预算;不记录凭据。
136
+ - **限制**:行为召回发生在**下一个** `agent/pre-step`;宿主虽有 `tools/pre-execute`,本插件没有用它做操作前硬阻断。不读取隐藏思维链:只消费可见 text 块、任务清单、命令/工具描述与失败信息。工具失败若底层只返回 aborted,审计会保留 `ABORTED_UNKNOWN`,不会臆测成凭据问题。
131
137
 
132
138
  ## 数据与文件布局
133
139
 
@@ -343,6 +349,18 @@ tools/build-single-package.mjs 构建(产物契约检查 + 可选加载验证)
343
349
 
344
350
  ## 版本
345
351
 
352
+ - **0.9.8** —— 设置页重写为卡片式:
353
+ - 每个开关都有可见 label、说明和「已开启 / 已关闭」状态,不再只靠 tooltip;数值项也有独立 label 与提示。
354
+ - 分组改成卡片:每轮召回 / 印象形态 / 会话摘要 / 记忆使用策略 / 硬性规则 / 自动召回 / 轮末提醒 / 侧栏入口;规则卡显示当前规则条数与作用域数。
355
+ - 自动召回标签编辑器并入「自动召回」卡,保存按钮与说明同屏;数据导出 / 导入独立成卡。
356
+ - 窄面板自动单列;新增回归测试,断言每个开关都有可见 label、hint 和状态文案。
357
+ - **0.9.7** —— 行为召回从“固定发布/部署模式”改成**标签匹配**:
358
+ - `autoRecall.tags` 是可编辑标签列表,不再要求写正则;默认并入记忆库里已有的标签(`useMemoryTags`),所以不需要把每个标签抄进设置。
359
+ - 匹配源扩到可见 `assistant/message` text 块、`todo/write` 任务清单、`command/run`、`goal/change`、`tool/call` 的 name/description/参数,以及 `tool/result` 失败描述;不读取 hidden reasoning。
360
+ - 工具失败始终用该调用自己的 `description` 做检索查询;取不到才退回错误类别。
361
+ - 标签支持中英最小同义词(`deploy` ↔ 部署、`database` ↔ 数据库等);词法检索把记录标签并入可检索文本。
362
+ - 面板新增自动召回设置与标签编辑器;审计 signal 记录命中标签与来源。
363
+ - 测试覆盖标签触发、description 优先、assistant text/todo/command/goal 提取、跨语言标签、标签检索与设置归一化。
346
364
  - **0.9.6** —— 注入可靠性改造:
347
365
  - 摘要默认正文预算 400 → 800;旧版 `settings.json` 里仍是 400 且没有 `hintBudget` 的配置会在加载时迁移到 800,显式带 `hintBudget` 的配置不动。新增候选/正文/`top_k`/预算/退役/过期互斥统计,任何截断都有原因。
348
366
  - 被截断记录生成独立标签索引(id + 标签/主题 + 类型 + 作用域),标签有独立预算与条数上限;mandatory/pinned 与发布/部署/凭据类标签优先保留。
package/lib/client.js CHANGED
@@ -164,6 +164,40 @@ window.__ModuleLoader__.load({
164
164
  '.memp .switch .knob{position:absolute;top:2px;left:2px;width:16px;height:16px;border-radius:50%;background:#fff;transition:left .12s ease;box-shadow:0 1px 2px rgba(0,0,0,.25)}',
165
165
  '.memp .switch.on .knob{left:16px}',
166
166
  '.memp .setfoot{display:flex;align-items:center;gap:10px;padding-top:12px}',
167
+ // 新版设置页:卡片 + 可见 label + 状态文案 + 字段说明
168
+ '.memp .setp{display:flex;flex-direction:column;gap:10px}',
169
+ '.memp .sethead{display:flex;align-items:flex-end;gap:12px;padding:0 2px 2px}',
170
+ '.memp .sethead-text{flex:1;min-width:0}',
171
+ '.memp .sethead-title{font-size:14px;font-weight:600;line-height:1.35}',
172
+ '.memp .sethead-sub{font-size:11.5px;color:var(--dsw-alias-label-secondary);line-height:1.5;margin-top:2px}',
173
+ '.memp .sethead-saved{flex:none;font-size:11.5px;color:var(--dsw-alias-brand-primary);padding-bottom:2px}',
174
+ '.memp .setcards{display:flex;flex-direction:column;gap:9px}',
175
+ '.memp .setcard{border:1px solid var(--dsw-alias-border-l1);border-radius:12px;background:var(--dsw-alias-bg-layer-1);overflow:hidden}',
176
+ '.memp .setcard-head{display:flex;align-items:flex-start;gap:14px;padding:11px 13px;background:linear-gradient(120deg,color-mix(in srgb,var(--dsw-alias-brand-primary) 5%,var(--dsw-alias-bg-layer-1)),var(--dsw-alias-bg-layer-1) 62%)}',
177
+ '.memp .setcard-heading{flex:1;min-width:0}',
178
+ '.memp .setcard-title{display:flex;align-items:center;gap:8px;font-size:13px;font-weight:600;line-height:1.4}',
179
+ '.memp .setcard-desc{font-size:11.5px;color:var(--dsw-alias-label-secondary);line-height:1.55;margin-top:3px}',
180
+ '.memp .setcard-pill{font-size:10px;font-weight:400;line-height:1.7;padding:0 7px;border-radius:999px;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);white-space:nowrap}',
181
+ '.memp .setcard-enable{display:flex;align-items:center;gap:6px;flex:none;padding-top:1px}',
182
+ '.memp .setcard-enable-label{font-size:11.5px;color:var(--dsw-alias-label-secondary)}',
183
+ '.memp .setcard-enable-state{font-size:10px;color:var(--dsw-alias-label-secondary);min-width:42px;text-align:right}',
184
+ '.memp .setcard-body{display:grid;grid-template-columns:repeat(auto-fit,minmax(245px,1fr));gap:8px;padding:11px 13px;border-top:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1)}',
185
+ '.memp .setcard-body.data-body{display:block}',
186
+ '.memp .setcard-note{padding:0 13px 11px;font-size:11px;color:var(--dsw-alias-label-secondary);line-height:1.5}',
187
+ '.memp .setfield{display:flex;align-items:center;gap:10px;min-width:0;padding:7px 9px;border:1px solid var(--dsw-alias-border-l1);border-radius:9px;background:var(--dsw-alias-bg-layer-2)}',
188
+ '.memp .setfield-main{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px}',
189
+ '.memp .setfield-label{font-size:12px;font-weight:500;line-height:1.45;color:var(--dsw-alias-label-primary)}',
190
+ '.memp .setfield-hint{font-size:10.5px;line-height:1.45;color:var(--dsw-alias-label-secondary)}',
191
+ '.memp .setfield-control{display:flex;align-items:center;gap:5px;flex:none}',
192
+ '.memp .setfield-state{font-size:10px;color:var(--dsw-alias-label-secondary);min-width:38px;text-align:right}',
193
+ '.memp .setfield input[type=number]{width:82px;padding:4px 7px;background:var(--dsw-alias-bg-layer-1)}',
194
+ '.memp .setcard-body .autorecall{grid-column:1/-1}',
195
+ '.memp .setcard-body .autorecall textarea{min-height:132px;background:var(--dsw-alias-bg-layer-1)}',
196
+ '.memp .setcard.datacard .setcard-head{background:var(--dsw-alias-bg-layer-1)}',
197
+ '@media (max-width:560px){.memp .setcard-head{flex-wrap:wrap}.memp .setcard-enable{margin-left:auto}.memp .setcard-body{grid-template-columns:1fr}}',
198
+ '.memp .autorecall{flex:1 1 100%;display:flex;flex-direction:column;gap:6px;margin-top:6px}',
199
+ '.memp .autorecall textarea{min-height:150px;font-family:var(--ds-font-family-code, ui-monospace, monospace);font-size:11px;line-height:1.5}',
200
+ '.memp .autorecall .row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}',
167
201
  '.memp .create{padding:10px 12px;border:1px solid var(--dsw-alias-border-l1);border-radius:8px;margin:8px 0;background:var(--dsw-alias-bg-layer-2)}',
168
202
  '.memp .create .row{display:flex;gap:8px;align-items:center;margin:6px 0;flex-wrap:wrap}',
169
203
  '.memp .create textarea{width:100%;min-height:64px}',
@@ -1508,7 +1542,8 @@ window.__ModuleLoader__.load({
1508
1542
  }
1509
1543
 
1510
1544
  /** 设置项开关:轨道 + 圆点,与向量服务的 toggle 同一套视觉。 */
1511
- function Switch({ checked, disabled, onChange, title }) {
1545
+ function Switch({ checked, disabled, onChange, title, label }) {
1546
+ const aria = title || label
1512
1547
  return h('button', {
1513
1548
  type: 'button',
1514
1549
  className: 'switch' + (checked ? ' on' : ''),
@@ -1516,6 +1551,7 @@ window.__ModuleLoader__.load({
1516
1551
  'aria-checked': Boolean(checked),
1517
1552
  disabled: Boolean(disabled),
1518
1553
  ...(title ? { title } : {}),
1554
+ ...(aria ? { 'aria-label': aria } : {}),
1519
1555
  onClick: () => onChange(!checked),
1520
1556
  }, h('span', { className: 'knob' }))
1521
1557
  }
@@ -1530,60 +1566,183 @@ window.__ModuleLoader__.load({
1530
1566
  const SETTINGS_GROUPS = [
1531
1567
  {
1532
1568
  key: 'recall', title: '每轮召回',
1533
- desc: '按本轮问题检索记忆并插入上下文,内容没变不重复注入。',
1569
+ desc: '按本轮用户消息检索记忆并插入上下文;内容没变不会重复注入。',
1534
1570
  fields: [
1535
- { k: 'enabled', label: '启用', type: 'bool' },
1536
- { k: 'topK', label: '最多条数', type: 'num', min: 1, max: 20, step: 1 },
1537
- { k: 'tokenBudget', label: 'token 预算', type: 'num', min: 50, max: 4000, step: 50 },
1571
+ { k: 'enabled', label: '启用', type: 'bool', hint: '关闭后每轮不再按问题检索记忆。' },
1572
+ { k: 'topK', label: '最多条数', type: 'num', min: 1, max: 20, step: 1, hint: '每次最多注入几条相关记忆。' },
1573
+ { k: 'tokenBudget', label: 'token 预算', type: 'num', min: 50, max: 4000, step: 50, hint: '召回块允许占用的最大 token 数。' },
1538
1574
  ],
1539
1575
  },
1540
1576
  {
1541
1577
  key: 'impression', title: '印象形态',
1542
- desc: '每条只给摘要,细节由模型用 memory_get 取。',
1578
+ desc: '召回时只给每条记忆的开头,模型需要细节时再用 memory_get 取全文。',
1543
1579
  fields: [
1544
- { k: 'enabled', label: '启用', type: 'bool' },
1545
- { k: 'chars', label: '每条字数', type: 'num', min: 40, max: 800, step: 20 },
1580
+ { k: 'enabled', label: '启用', type: 'bool', hint: '关闭后召回直接给长文摘要。' },
1581
+ { k: 'chars', label: '每条字数', type: 'num', min: 40, max: 800, step: 20, hint: '每条记忆在召回块里保留多少字。' },
1546
1582
  ],
1547
1583
  },
1548
1584
  {
1549
1585
  key: 'digest', title: '会话摘要',
1550
- desc: '会话第一步给一次项目 / 全局的记忆概览;正文被截断时附一条标签索引。',
1586
+ desc: '新会话第一步给一次项目 / 全局记忆概览;正文被截断时附一条可检索的标签索引。',
1551
1587
  fields: [
1552
- { k: 'enabled', label: '启用', type: 'bool' },
1553
- { k: 'topK', label: '最多条数', type: 'num', min: 1, max: 30, step: 1 },
1554
- { k: 'tokenBudget', label: 'token 预算', type: 'num', min: 50, max: 4000, step: 50 },
1555
- { k: 'hintBudget', label: '标签预算', type: 'num', min: 30, max: 1000, step: 10 },
1556
- { k: 'hintMaxItems', label: '标签条数', type: 'num', min: 1, max: 30, step: 1 },
1588
+ { k: 'enabled', label: '启用', type: 'bool', hint: '关闭后新会话不再收到记忆摘要。' },
1589
+ { k: 'topK', label: '最多条数', type: 'num', min: 1, max: 30, step: 1, hint: '摘要正文最多列几条。' },
1590
+ { k: 'tokenBudget', label: '正文预算', type: 'num', min: 50, max: 4000, step: 50, hint: '正文摘要的 token 预算;超出部分转成标签索引。' },
1591
+ { k: 'hintBudget', label: '标签预算', type: 'num', min: 30, max: 1000, step: 10, hint: '标签索引独立预算,不占正文。' },
1592
+ { k: 'hintMaxItems', label: '标签条数', type: 'num', min: 1, max: 30, step: 1, hint: '标签索引最多列几条。' },
1557
1593
  ],
1558
1594
  },
1559
1595
  {
1560
1596
  key: 'policy', title: '记忆使用策略',
1561
- desc: '系统提示常驻段:何时查、查到怎么用、查不到怎么办。',
1562
- fields: [{ k: 'enabled', label: '启用', type: 'bool' }],
1597
+ desc: '系统提示常驻段:什么时候该查记忆、查到后怎么用、查不到怎么办。',
1598
+ fields: [
1599
+ { k: 'enabled', label: '启用', type: 'bool', hint: '关闭只移除这段提示,不影响记忆检索。' },
1600
+ ],
1563
1601
  },
1564
1602
  {
1565
1603
  key: 'rules', title: '硬性规则',
1566
- desc: '把 kind=rule 的记忆放进系统提示常驻段;旧会话下一轮补一条新增/变更的规则。',
1567
- hint: '关闭只影响系统提示常驻段,记忆本身仍可被检索',
1604
+ desc: '把 kind=rule 的记忆放进系统提示常驻段;旧会话下一轮补一条新增 / 变更的规则。',
1605
+ hint: '关闭只影响系统提示常驻段,规则本身仍可被 memory_search 检索。',
1568
1606
  fields: [
1569
- { k: 'enabled', label: '启用', type: 'bool' },
1570
- { k: 'maxItems', label: '最多条数', type: 'num', min: 1, max: 40, step: 1 },
1571
- { k: 'tokenBudget', label: 'token 预算', type: 'num', min: 50, max: 4000, step: 50 },
1572
- { k: 'delta', label: '变更提醒', type: 'bool', hint: '旧会话在下一轮第一步补一条新增/编辑过的规则;没变化的不重复' },
1607
+ { k: 'enabled', label: '启用', type: 'bool', hint: '关闭后规则不再进入系统提示常驻段。' },
1608
+ { k: 'maxItems', label: '最多条数', type: 'num', min: 1, max: 40, step: 1, hint: '规则段最多列几条。' },
1609
+ { k: 'tokenBudget', label: 'token 预算', type: 'num', min: 50, max: 4000, step: 50, hint: '规则段的 token 上限;mandatory 溢出会额外警告。' },
1610
+ { k: 'delta', label: '变更提醒', type: 'bool', hint: '旧会话在下一轮第一步补一条新增 / 编辑过的规则;没变化不重复。' },
1611
+ ],
1612
+ },
1613
+ {
1614
+ key: 'autoRecall', title: '自动召回',
1615
+ desc: '从可见文本(assistant 输出、任务清单、命令 / 工具描述、失败信息)匹配记忆标签,命中即检索。',
1616
+ fields: [
1617
+ { k: 'enabled', label: '启用', type: 'bool', hint: '关闭后只保留普通每轮召回与工具失败召回。' },
1618
+ { k: 'useToolDescription', label: '使用工具 description', type: 'bool', hint: '失败或命中时优先用工具调用自己写的 description 做检索。' },
1619
+ { k: 'useMemoryTags', label: '使用记忆标签', type: 'bool', hint: '自动把记忆库里已有的标签并入触发词。' },
1620
+ { k: 'maxQueryChars', label: '查询字数上限', type: 'num', min: 40, max: 500, step: 10, hint: '单次自动召回查询最多多少字,避免把整段命令塞进检索。' },
1573
1621
  ],
1574
1622
  },
1575
1623
  {
1576
1624
  key: 'turnEnd', title: '轮末提醒',
1577
- desc: '下一轮开头提醒把本轮结论落盘,默认关闭。',
1578
- fields: [{ k: 'enabled', label: '启用', type: 'bool' }],
1625
+ desc: '下一轮开头提醒把本轮结论落盘;默认关闭,避免打断连续对话。',
1626
+ fields: [
1627
+ { k: 'enabled', label: '启用', type: 'bool', hint: '开启后每轮结束会给一条“有结论就记一条”的提醒。' },
1628
+ ],
1579
1629
  },
1580
1630
  {
1581
1631
  key: 'sidebar', title: '侧栏入口',
1582
- desc: '在左侧栏「插件」下方显示记忆入口,点击打开面板。',
1583
- fields: [{ k: 'enabled', label: '启用', type: 'bool' }],
1632
+ desc: '在左侧栏「插件」下方显示「记忆」入口,点击在主界面打开面板。',
1633
+ fields: [
1634
+ { k: 'enabled', label: '启用', type: 'bool', hint: '关闭只隐藏侧栏入口,设置页仍然可用。' },
1635
+ ],
1584
1636
  },
1585
1637
  ]
1586
1638
 
1639
+ /**
1640
+ * 自动召回“模式”编辑器:模式就是一组标签,每行一个。
1641
+ * 工具 name / description / 参数命中任一标签就召回;失败调用始终用 description。
1642
+ */
1643
+ function AutoRecallTagsEditor({ tags, onSave }) {
1644
+ const [text, setText] = React.useState((tags ?? []).join('\n'))
1645
+ return h('div', { className: 'autorecall' },
1646
+ h('div', { className: 'hint' },
1647
+ '每行一个额外标签。记忆库里已有的标签会自动并入(可关);',
1648
+ '可见文本命中任一个就触发召回,工具失败时始终用 description 检索。'),
1649
+ h('textarea', {
1650
+ rows: 8,
1651
+ spellCheck: false,
1652
+ value: text,
1653
+ placeholder: 'release\npublish\ndeploy\ndatabase\ncredentials\n发布\n部署',
1654
+ onChange: (e) => setText(e.target.value),
1655
+ }),
1656
+ h('div', { className: 'row' },
1657
+ h('button', {
1658
+ onClick: () => onSave(text.split(/[\n,,]+/).map((tag) => tag.trim()).filter(Boolean)),
1659
+ }, '保存标签'),
1660
+ h('span', { className: 'muted' }, '额外标签为空时仍会使用记忆库标签和失败召回'),
1661
+ ),
1662
+ )
1663
+ }
1664
+
1665
+ /** 单个数值 / 开关字段:label 和 hint 都必须是可见文本,不能只放在 title 里。 */
1666
+ function SettingField({ field, value, onPatch }) {
1667
+ if (field.type === 'bool') {
1668
+ const checked = Boolean(value)
1669
+ return h('div', { className: 'setfield' },
1670
+ h('div', { className: 'setfield-main' },
1671
+ h('span', { className: 'setfield-label' }, field.label),
1672
+ field.hint ? h('span', { className: 'setfield-hint' }, field.hint) : null,
1673
+ ),
1674
+ h('div', { className: 'setfield-control' },
1675
+ h(Switch, {
1676
+ checked,
1677
+ label: field.label,
1678
+ title: field.hint || field.label,
1679
+ onChange: onPatch,
1680
+ }),
1681
+ h('span', { className: 'setfield-state' }, checked ? '已开启' : '已关闭'),
1682
+ ),
1683
+ )
1684
+ }
1685
+ return h('label', { className: 'setfield' },
1686
+ h('span', { className: 'setfield-main' },
1687
+ h('span', { className: 'setfield-label' }, field.label),
1688
+ field.hint ? h('span', { className: 'setfield-hint' }, field.hint) : null,
1689
+ ),
1690
+ h('input', {
1691
+ type: 'number', min: field.min, max: field.max, step: field.step, value: value,
1692
+ onChange: (e) => onPatch(Number(e.target.value)),
1693
+ }),
1694
+ )
1695
+ }
1696
+
1697
+ /** 一张设置卡:标题 + 描述 + 显式的「启用」开关 + 字段网格。 */
1698
+ function SettingsCard({ group, value, rulesCount, patch, tags }) {
1699
+ const enabledField = group.fields.find((field) => field.k === 'enabled' && field.type === 'bool')
1700
+ const fields = group.fields.filter((field) => field !== enabledField)
1701
+ const enabled = enabledField ? Boolean(value[enabledField.k]) : true
1702
+ return h('section', { className: 'setcard' },
1703
+ h('div', { className: 'setcard-head' },
1704
+ h('div', { className: 'setcard-heading' },
1705
+ h('div', { className: 'setcard-title' },
1706
+ group.title,
1707
+ group.key === 'rules' && rulesCount !== null
1708
+ ? h('span', { className: 'setcard-pill' }, `${rulesCount.total} 条规则 / ${rulesCount.scopes} 个作用域`)
1709
+ : null,
1710
+ ),
1711
+ h('div', { className: 'setcard-desc' }, group.desc),
1712
+ ),
1713
+ enabledField
1714
+ ? h('div', { className: 'setcard-enable' },
1715
+ h('span', { className: 'setcard-enable-label' }, enabledField.label || '启用'),
1716
+ h(Switch, {
1717
+ checked: enabled,
1718
+ label: enabledField.label,
1719
+ title: enabledField.hint || `${group.title}:${enabledField.label}`,
1720
+ onChange: (next) => patch(group.key, enabledField.k, next),
1721
+ }),
1722
+ h('span', { className: 'setcard-enable-state' }, enabled ? '已开启' : '已关闭'),
1723
+ )
1724
+ : null,
1725
+ ),
1726
+ fields.length > 0 || group.key === 'autoRecall'
1727
+ ? h('div', { className: 'setcard-body' },
1728
+ fields.map((field) => h(SettingField, {
1729
+ key: field.k,
1730
+ field,
1731
+ value: value[field.k],
1732
+ onPatch: (next) => patch(group.key, field.k, next),
1733
+ })),
1734
+ group.key === 'autoRecall'
1735
+ ? h(AutoRecallTagsEditor, {
1736
+ tags,
1737
+ onSave: (next) => patch('autoRecall', 'tags', next),
1738
+ })
1739
+ : null,
1740
+ )
1741
+ : null,
1742
+ group.hint ? h('div', { className: 'setcard-note' }, group.hint) : null,
1743
+ )
1744
+ }
1745
+
1587
1746
  function SettingsTab() {
1588
1747
  const [settings, setSettings] = React.useState(null)
1589
1748
  const [error, setError] = React.useState('')
@@ -1666,41 +1825,40 @@ window.__ModuleLoader__.load({
1666
1825
  if (!settings) return h('div', { className: 'empty' }, error || '加载设置…')
1667
1826
 
1668
1827
  return h('div', { className: 'setp' },
1669
- h('div', { className: 'hint' }, '设置保存在记忆数据目录的 settings.json。'),
1670
- SETTINGS_GROUPS.map((group) => {
1671
- const value = settings[group.key] || {}
1672
- return h('div', { className: 'setrow', key: group.key },
1673
- h('span', { className: 'set-title' }, group.title),
1674
- group.fields.map((field) => field.type === 'bool'
1675
- ? h(Switch, {
1676
- key: field.k,
1677
- checked: Boolean(value[field.k]),
1678
- title: field.hint || group.hint || field.label,
1679
- onChange: (next) => patch(group.key, field.k, next),
1680
- })
1681
- : h('label', { className: 'set-field', key: field.k }, field.label, ' ',
1682
- h('input', {
1683
- type: 'number', min: field.min, max: field.max, step: field.step, value: value[field.k],
1684
- onChange: (e) => patch(group.key, field.k, Number(e.target.value)),
1685
- }))),
1686
- h('span', { className: 'set-desc' }, group.desc),
1687
- group.key === 'rules' && rulesCount !== null
1688
- ? h('span', { className: 'set-field' }, `${rulesCount.total} 条规则 / ${rulesCount.scopes} 个作用域(在「记录 → 新建」里选 kind=rule 添加)`)
1689
- : null,
1690
- )
1691
- }),
1692
- h('div', { className: 'setrow data' },
1693
- h('span', { className: 'set-title' }, '数据'),
1694
- h('span', { className: 'set-desc' }, '导出文本(不含向量),导入按当前模型重新嵌入并按内容去重。'),
1695
- h('div', { className: 'row' },
1696
- h('button', { onClick: exportAll }, '导出全部'),
1697
- h('label', { className: 'set-field' }, '导入文件',
1698
- h('input', { type: 'file', accept: '.json,application/json', onChange: importFile })),
1699
- dataNotice ? h('span', { className: 'muted' }, dataNotice) : null,
1828
+ h('div', { className: 'sethead' },
1829
+ h('div', { className: 'sethead-text' },
1830
+ h('div', { className: 'sethead-title' }, '注入设置'),
1831
+ h('div', { className: 'sethead-sub' }, '修改后立即保存到 settings.json;开关旁显示当前状态,字段下方是说明。'),
1832
+ ),
1833
+ notice ? h('span', { className: 'sethead-saved' }, notice) : null,
1834
+ ),
1835
+ h('div', { className: 'setcards' },
1836
+ SETTINGS_GROUPS.map((group) => h(SettingsCard, {
1837
+ key: group.key,
1838
+ group,
1839
+ value: settings[group.key] || {},
1840
+ rulesCount,
1841
+ patch,
1842
+ tags: settings.autoRecall && Array.isArray(settings.autoRecall.tags) ? settings.autoRecall.tags : [],
1843
+ })),
1844
+ ),
1845
+ h('section', { className: 'setcard datacard' },
1846
+ h('div', { className: 'setcard-head' },
1847
+ h('div', { className: 'setcard-heading' },
1848
+ h('div', { className: 'setcard-title' }, '数据'),
1849
+ h('div', { className: 'setcard-desc' }, '导出文本不含向量;导入按当前模型重新嵌入,并按「作用域 + 内容」去重。'),
1850
+ ),
1851
+ ),
1852
+ h('div', { className: 'setcard-body data-body' },
1853
+ h('div', { className: 'row' },
1854
+ h('button', { onClick: exportAll }, '导出全部'),
1855
+ h('label', { className: 'set-field' }, '导入文件',
1856
+ h('input', { type: 'file', accept: '.json,application/json', onChange: importFile })),
1857
+ dataNotice ? h('span', { className: 'muted' }, dataNotice) : null,
1858
+ ),
1700
1859
  ),
1701
1860
  ),
1702
1861
  error ? h('div', { className: 'err' }, error) : null,
1703
- notice ? h('div', { className: 'muted' }, notice) : null,
1704
1862
  )
1705
1863
  }
1706
1864
 
@@ -2365,6 +2523,7 @@ window.__ModuleLoader__.load({
2365
2523
  RecordCard: RecordCard,
2366
2524
  MemoryPanel: MemoryPanel,
2367
2525
  MemoryTreeTab: MemoryTreeTab,
2526
+ SettingsTab: SettingsTab,
2368
2527
  buildMemoryTree: buildMemoryTree,
2369
2528
  KIND_META: KIND_META,
2370
2529
  CSS: CSS,