@restregular/dsh-memory 0.9.7 → 0.9.9
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 +16 -1
- package/lib/client.js +181 -69
- package/lib/inject/apply.js +41 -9
- package/lib/inject/inject.js +40 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,6 +17,10 @@ English: Local, durable memory for DeepSeek Harness — one npm package, one loa
|
|
|
17
17
|
|
|
18
18
|

|
|
19
19
|
|
|
20
|
+
设置页「记忆 → 设置」的卡片式布局:每个开关都有可见 label、说明和状态,自动召回标签在同卡编辑。
|
|
21
|
+
|
|
22
|
+

|
|
23
|
+
|
|
20
24
|
模型在对话里查记忆 —— `memory_search` 的入参与召回结果:
|
|
21
25
|
|
|
22
26
|

|
|
@@ -125,7 +129,7 @@ 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
|
-
- **标签触发的行为召回(0.9.7)**:设置里的 `autoRecall.tags` 是**标签**,不是正则;默认还会并入记忆库里已有的标签(`useMemoryTags`)
|
|
132
|
+
- **标签触发的行为召回(0.9.7)**:设置里的 `autoRecall.tags` 是**标签**,不是正则;默认还会并入记忆库里已有的标签(`useMemoryTags`)。自动召回只检索 **global + 当前会话 + 当前工作区**,不含自定义作用域 / fork 父会话;普通每轮召回仍按原配置。匹配源包括 `tool/call` 的 name / description / 参数、`tool/result` 的失败描述、可见 `assistant/message` 文本、`todo/write` 任务清单、`command/run`、`goal/change`。命中标签后,在下一个 `agent/pre-step` 用标签 + 命中片段检索;工具失败则始终用该工具调用自己的 `description`(取不到才退回错误类别)。中英标签有最小同义词映射(如 `deploy` ↔ 部署、`database` ↔ 数据库)。
|
|
129
133
|
- **去重**:已注入正文按 **sessionId + 记忆 id/版本** 跳过;只给过标签的会补正文;内容更新会重新评估;compaction 后重置摘要与去重状态。
|
|
130
134
|
- **标签可检索**:`search` 的词法通道把记录标签也并入检索文本,所以中文正文 + 英文标签也能被标签查询命中。
|
|
131
135
|
- **审计**:每次摘要/召回/规则评估写入内存审计环,`GET /memory/api/audit?session=<id>` 可查触发原因、阶段、候选、正文、标签、去重、省略原因与各通道预算;不记录凭据。
|
|
@@ -345,6 +349,17 @@ tools/build-single-package.mjs 构建(产物契约检查 + 可选加载验证)
|
|
|
345
349
|
|
|
346
350
|
## 版本
|
|
347
351
|
|
|
352
|
+
- **0.9.9** —— 收敛自动召回作用域与相关性:
|
|
353
|
+
- 自动召回只检索 **global + 当前会话 + 当前工作区** 三个标准作用域。
|
|
354
|
+
- 不再把 `inject.extraScopes` 的自定义作用域或 fork 父会话带进自动召回;普通每轮召回仍按原配置。
|
|
355
|
+
- 标签触发的召回要求命中记录真的带该标签(或同义词);一个泛标签不会再靠向量相似度把完全无关的全局记忆带进来。
|
|
356
|
+
- `pickQueryText` 只取**人类 user 消息**,跳过 memory / runtime / time / skill 等合成上下文,避免把上一块召回摘要当成下一轮查询。
|
|
357
|
+
- `autoRecallScopes()`、合成消息过滤、标签过滤都有单元测试。
|
|
358
|
+
- **0.9.8** —— 设置页重写为卡片式:
|
|
359
|
+
- 每个开关都有可见 label、说明和「已开启 / 已关闭」状态,不再只靠 tooltip;数值项也有独立 label 与提示。
|
|
360
|
+
- 分组改成卡片:每轮召回 / 印象形态 / 会话摘要 / 记忆使用策略 / 硬性规则 / 自动召回 / 轮末提醒 / 侧栏入口;规则卡显示当前规则条数与作用域数。
|
|
361
|
+
- 自动召回标签编辑器并入「自动召回」卡,保存按钮与说明同屏;数据导出 / 导入独立成卡。
|
|
362
|
+
- 窄面板自动单列;新增回归测试,断言每个开关都有可见 label、hint 和状态文案。
|
|
348
363
|
- **0.9.7** —— 行为召回从“固定发布/部署模式”改成**标签匹配**:
|
|
349
364
|
- `autoRecall.tags` 是可编辑标签列表,不再要求写正则;默认并入记忆库里已有的标签(`useMemoryTags`),所以不需要把每个标签抄进设置。
|
|
350
365
|
- 匹配源扩到可见 `assistant/message` text 块、`todo/write` 任务清单、`command/run`、`goal/change`、`tool/call` 的 name/description/参数,以及 `tool/result` 失败描述;不读取 hidden reasoning。
|
package/lib/client.js
CHANGED
|
@@ -164,6 +164,37 @@ 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}}',
|
|
167
198
|
'.memp .autorecall{flex:1 1 100%;display:flex;flex-direction:column;gap:6px;margin-top:6px}',
|
|
168
199
|
'.memp .autorecall textarea{min-height:150px;font-family:var(--ds-font-family-code, ui-monospace, monospace);font-size:11px;line-height:1.5}',
|
|
169
200
|
'.memp .autorecall .row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}',
|
|
@@ -1511,7 +1542,8 @@ window.__ModuleLoader__.load({
|
|
|
1511
1542
|
}
|
|
1512
1543
|
|
|
1513
1544
|
/** 设置项开关:轨道 + 圆点,与向量服务的 toggle 同一套视觉。 */
|
|
1514
|
-
function Switch({ checked, disabled, onChange, title }) {
|
|
1545
|
+
function Switch({ checked, disabled, onChange, title, label }) {
|
|
1546
|
+
const aria = title || label
|
|
1515
1547
|
return h('button', {
|
|
1516
1548
|
type: 'button',
|
|
1517
1549
|
className: 'switch' + (checked ? ' on' : ''),
|
|
@@ -1519,6 +1551,7 @@ window.__ModuleLoader__.load({
|
|
|
1519
1551
|
'aria-checked': Boolean(checked),
|
|
1520
1552
|
disabled: Boolean(disabled),
|
|
1521
1553
|
...(title ? { title } : {}),
|
|
1554
|
+
...(aria ? { 'aria-label': aria } : {}),
|
|
1522
1555
|
onClick: () => onChange(!checked),
|
|
1523
1556
|
}, h('span', { className: 'knob' }))
|
|
1524
1557
|
}
|
|
@@ -1533,67 +1566,73 @@ window.__ModuleLoader__.load({
|
|
|
1533
1566
|
const SETTINGS_GROUPS = [
|
|
1534
1567
|
{
|
|
1535
1568
|
key: 'recall', title: '每轮召回',
|
|
1536
|
-
desc: '
|
|
1569
|
+
desc: '按本轮用户消息检索记忆并插入上下文;内容没变不会重复注入。',
|
|
1537
1570
|
fields: [
|
|
1538
|
-
{ k: 'enabled', label: '启用', type: 'bool' },
|
|
1539
|
-
{ k: 'topK', label: '最多条数', type: 'num', min: 1, max: 20, step: 1 },
|
|
1540
|
-
{ 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 数。' },
|
|
1541
1574
|
],
|
|
1542
1575
|
},
|
|
1543
1576
|
{
|
|
1544
1577
|
key: 'impression', title: '印象形态',
|
|
1545
|
-
desc: '
|
|
1578
|
+
desc: '召回时只给每条记忆的开头,模型需要细节时再用 memory_get 取全文。',
|
|
1546
1579
|
fields: [
|
|
1547
|
-
{ k: 'enabled', label: '启用', type: 'bool' },
|
|
1548
|
-
{ 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: '每条记忆在召回块里保留多少字。' },
|
|
1549
1582
|
],
|
|
1550
1583
|
},
|
|
1551
1584
|
{
|
|
1552
1585
|
key: 'digest', title: '会话摘要',
|
|
1553
|
-
desc: '
|
|
1586
|
+
desc: '新会话第一步给一次项目 / 全局记忆概览;正文被截断时附一条可检索的标签索引。',
|
|
1554
1587
|
fields: [
|
|
1555
|
-
{ k: 'enabled', label: '启用', type: 'bool' },
|
|
1556
|
-
{ k: 'topK', label: '最多条数', type: 'num', min: 1, max: 30, step: 1 },
|
|
1557
|
-
{ k: 'tokenBudget', label: '
|
|
1558
|
-
{ k: 'hintBudget', label: '标签预算', type: 'num', min: 30, max: 1000, step: 10 },
|
|
1559
|
-
{ 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: '标签索引最多列几条。' },
|
|
1560
1593
|
],
|
|
1561
1594
|
},
|
|
1562
1595
|
{
|
|
1563
1596
|
key: 'policy', title: '记忆使用策略',
|
|
1564
|
-
desc: '
|
|
1565
|
-
fields: [
|
|
1597
|
+
desc: '系统提示常驻段:什么时候该查记忆、查到后怎么用、查不到怎么办。',
|
|
1598
|
+
fields: [
|
|
1599
|
+
{ k: 'enabled', label: '启用', type: 'bool', hint: '关闭只移除这段提示,不影响记忆检索。' },
|
|
1600
|
+
],
|
|
1566
1601
|
},
|
|
1567
1602
|
{
|
|
1568
1603
|
key: 'rules', title: '硬性规则',
|
|
1569
|
-
desc: '把 kind=rule
|
|
1570
|
-
hint: '
|
|
1604
|
+
desc: '把 kind=rule 的记忆放进系统提示常驻段;旧会话下一轮补一条新增 / 变更的规则。',
|
|
1605
|
+
hint: '关闭只影响系统提示常驻段,规则本身仍可被 memory_search 检索。',
|
|
1571
1606
|
fields: [
|
|
1572
|
-
{ k: 'enabled', label: '启用', type: 'bool' },
|
|
1573
|
-
{ k: 'maxItems', label: '最多条数', type: 'num', min: 1, max: 40, step: 1 },
|
|
1574
|
-
{ k: 'tokenBudget', label: 'token 预算', type: 'num', min: 50, max: 4000, step: 50 },
|
|
1575
|
-
{ 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: '旧会话在下一轮第一步补一条新增 / 编辑过的规则;没变化不重复。' },
|
|
1576
1611
|
],
|
|
1577
1612
|
},
|
|
1578
1613
|
{
|
|
1579
1614
|
key: 'autoRecall', title: '自动召回',
|
|
1580
|
-
desc: '从可见文本(assistant
|
|
1615
|
+
desc: '从可见文本(assistant 输出、任务清单、命令 / 工具描述、失败信息)匹配记忆标签,命中即检索。',
|
|
1581
1616
|
fields: [
|
|
1582
|
-
{ k: 'enabled', label: '启用', type: 'bool' },
|
|
1583
|
-
{ k: 'useToolDescription', label: '
|
|
1584
|
-
{ k: 'useMemoryTags', label: '
|
|
1585
|
-
{ k: 'maxQueryChars', label: '
|
|
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: '单次自动召回查询最多多少字,避免把整段命令塞进检索。' },
|
|
1586
1621
|
],
|
|
1587
1622
|
},
|
|
1588
1623
|
{
|
|
1589
1624
|
key: 'turnEnd', title: '轮末提醒',
|
|
1590
|
-
desc: '
|
|
1591
|
-
fields: [
|
|
1625
|
+
desc: '下一轮开头提醒把本轮结论落盘;默认关闭,避免打断连续对话。',
|
|
1626
|
+
fields: [
|
|
1627
|
+
{ k: 'enabled', label: '启用', type: 'bool', hint: '开启后每轮结束会给一条“有结论就记一条”的提醒。' },
|
|
1628
|
+
],
|
|
1592
1629
|
},
|
|
1593
1630
|
{
|
|
1594
1631
|
key: 'sidebar', title: '侧栏入口',
|
|
1595
|
-
desc: '
|
|
1596
|
-
fields: [
|
|
1632
|
+
desc: '在左侧栏「插件」下方显示「记忆」入口,点击在主界面打开面板。',
|
|
1633
|
+
fields: [
|
|
1634
|
+
{ k: 'enabled', label: '启用', type: 'bool', hint: '关闭只隐藏侧栏入口,设置页仍然可用。' },
|
|
1635
|
+
],
|
|
1597
1636
|
},
|
|
1598
1637
|
]
|
|
1599
1638
|
|
|
@@ -1623,6 +1662,87 @@ window.__ModuleLoader__.load({
|
|
|
1623
1662
|
)
|
|
1624
1663
|
}
|
|
1625
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
|
+
|
|
1626
1746
|
function SettingsTab() {
|
|
1627
1747
|
const [settings, setSettings] = React.useState(null)
|
|
1628
1748
|
const [error, setError] = React.useState('')
|
|
@@ -1705,49 +1825,40 @@ window.__ModuleLoader__.load({
|
|
|
1705
1825
|
if (!settings) return h('div', { className: 'empty' }, error || '加载设置…')
|
|
1706
1826
|
|
|
1707
1827
|
return h('div', { className: 'setp' },
|
|
1708
|
-
h('div', { className: '
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
type: 'number', min: field.min, max: field.max, step: field.step, value: value[field.k],
|
|
1723
|
-
onChange: (e) => patch(group.key, field.k, Number(e.target.value)),
|
|
1724
|
-
}))),
|
|
1725
|
-
h('span', { className: 'set-desc' }, group.desc),
|
|
1726
|
-
group.key === 'rules' && rulesCount !== null
|
|
1727
|
-
? h('span', { className: 'set-field' }, `${rulesCount.total} 条规则 / ${rulesCount.scopes} 个作用域(在「记录 → 新建」里选 kind=rule 添加)`)
|
|
1728
|
-
: null,
|
|
1729
|
-
)
|
|
1730
|
-
}),
|
|
1731
|
-
h('div', { className: 'setrow' },
|
|
1732
|
-
h('span', { className: 'set-title' }, '召回标签'),
|
|
1733
|
-
h('span', { className: 'set-desc' }, '工具调用命中标签,或工具失败时,用操作/失败描述检索记忆。'),
|
|
1734
|
-
h(AutoRecallTagsEditor, {
|
|
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,
|
|
1735
1842
|
tags: settings.autoRecall && Array.isArray(settings.autoRecall.tags) ? settings.autoRecall.tags : [],
|
|
1736
|
-
|
|
1737
|
-
}),
|
|
1843
|
+
})),
|
|
1738
1844
|
),
|
|
1739
|
-
h('
|
|
1740
|
-
h('
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
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
|
+
),
|
|
1747
1859
|
),
|
|
1748
1860
|
),
|
|
1749
1861
|
error ? h('div', { className: 'err' }, error) : null,
|
|
1750
|
-
notice ? h('div', { className: 'muted' }, notice) : null,
|
|
1751
1862
|
)
|
|
1752
1863
|
}
|
|
1753
1864
|
|
|
@@ -2412,6 +2523,7 @@ window.__ModuleLoader__.load({
|
|
|
2412
2523
|
RecordCard: RecordCard,
|
|
2413
2524
|
MemoryPanel: MemoryPanel,
|
|
2414
2525
|
MemoryTreeTab: MemoryTreeTab,
|
|
2526
|
+
SettingsTab: SettingsTab,
|
|
2415
2527
|
buildMemoryTree: buildMemoryTree,
|
|
2416
2528
|
KIND_META: KIND_META,
|
|
2417
2529
|
CSS: CSS,
|
package/lib/inject/apply.js
CHANGED
|
@@ -28,6 +28,7 @@ import { createUserMessage } from '@deepseek-ai/dsh-llm'
|
|
|
28
28
|
import {
|
|
29
29
|
MemoryDigester,
|
|
30
30
|
MemoryInjector,
|
|
31
|
+
autoRecallScopes,
|
|
31
32
|
hasRecallMessage,
|
|
32
33
|
normalizeExtraScopes,
|
|
33
34
|
pickQueryText,
|
|
@@ -116,6 +117,7 @@ export function apply(ctx , config = {}) {
|
|
|
116
117
|
const signals = new BehaviorSignalStore()
|
|
117
118
|
const callMeta = new Map ()
|
|
118
119
|
const sessionScopes = new Map ()
|
|
120
|
+
const sessionAutoScopes = new Map ()
|
|
119
121
|
const tagCache = new Map ()
|
|
120
122
|
let attachedMemory = null
|
|
121
123
|
|
|
@@ -164,6 +166,24 @@ export function apply(ctx , config = {}) {
|
|
|
164
166
|
return []
|
|
165
167
|
}
|
|
166
168
|
|
|
169
|
+
/** 自动召回专用范围:只保留 global + 当前会话 + 当前工作区。 */
|
|
170
|
+
const autoScopesForSession = (
|
|
171
|
+
sessionId ,
|
|
172
|
+
memory ,
|
|
173
|
+
session ,
|
|
174
|
+
fallback ,
|
|
175
|
+
) => {
|
|
176
|
+
const known = sessionAutoScopes.get(sessionId)
|
|
177
|
+
if (known !== undefined) return known
|
|
178
|
+
let resolved
|
|
179
|
+
try {
|
|
180
|
+
resolved = memory?.resolveReadScopes?.({ session })
|
|
181
|
+
} catch { resolved = undefined }
|
|
182
|
+
const scopes = autoRecallScopes(resolved ?? fallback)
|
|
183
|
+
if (scopes !== undefined) sessionAutoScopes.set(sessionId, scopes)
|
|
184
|
+
return scopes
|
|
185
|
+
}
|
|
186
|
+
|
|
167
187
|
/**
|
|
168
188
|
* 触发词 = 设置里的额外标签 ∪ 当前记忆库里已有的标签(可关)。
|
|
169
189
|
* 后者让“记忆标签”本身成为触发词,不需要用户把每个标签抄进设置。
|
|
@@ -272,6 +292,7 @@ export function apply(ctx , config = {}) {
|
|
|
272
292
|
signals.clear(sessionId)
|
|
273
293
|
digester.reset(sessionId)
|
|
274
294
|
sessionScopes.delete(sessionId)
|
|
295
|
+
sessionAutoScopes.delete(sessionId)
|
|
275
296
|
for (const key of tagCache.keys()) if (key.startsWith(`${sessionId}|`)) tagCache.delete(key)
|
|
276
297
|
callMeta.clear()
|
|
277
298
|
return
|
|
@@ -279,7 +300,9 @@ export function apply(ctx , config = {}) {
|
|
|
279
300
|
const settings = enabled ? settingsOf() : undefined
|
|
280
301
|
const auto = settings?.autoRecall
|
|
281
302
|
if (!auto?.enabled) return
|
|
282
|
-
const
|
|
303
|
+
const allScopes = scopesForSession(sessionId, memory , session)
|
|
304
|
+
const scopes = autoScopesForSession(sessionId, memory, session, allScopes)
|
|
305
|
+
if (scopes === undefined) return
|
|
283
306
|
const tags = triggerTags(memory , sessionId, scopes, auto)
|
|
284
307
|
|
|
285
308
|
if (type === 'tool/call') {
|
|
@@ -391,8 +414,14 @@ export function apply(ctx , config = {}) {
|
|
|
391
414
|
const sessionId = sessionIdOf(agent)
|
|
392
415
|
const scopes = readScopesFor(memory, agent)
|
|
393
416
|
if (sessionId !== undefined && scopes !== undefined) sessionScopes.set(sessionId, [...scopes])
|
|
417
|
+
let autoScopes
|
|
418
|
+
try { autoScopes = autoRecallScopes(memory.resolveReadScopes?.(agent) ) } catch { autoScopes = undefined }
|
|
419
|
+
if (autoScopes === undefined) autoScopes = autoRecallScopes(scopes)
|
|
420
|
+
if (sessionId !== undefined && autoScopes !== undefined) sessionAutoScopes.set(sessionId, [...autoScopes])
|
|
394
421
|
const exclude = excludedIds(memory, scopes)
|
|
422
|
+
const excludeAuto = excludedIds(memory, autoScopes)
|
|
395
423
|
const signal = sessionId === undefined ? undefined : signals.take(sessionId)
|
|
424
|
+
const usableSignal = autoScopes === undefined ? undefined : signal
|
|
396
425
|
const userQuery = pickQueryText(input.messages )
|
|
397
426
|
|
|
398
427
|
// 摘要(每个会话一次)、召回(每轮有新内容时)、轮末提醒(下一轮首步)合成
|
|
@@ -470,24 +499,27 @@ export function apply(ctx , config = {}) {
|
|
|
470
499
|
|
|
471
500
|
// 行为信号优先:发布/推送/失败事件触发定向查询;没有信号才走普通用户消息召回。
|
|
472
501
|
// 同一轮普通 query 已处理过时跳过重复检索(去重状态仍会兜底)。
|
|
473
|
-
const skipNormalRecall =
|
|
502
|
+
const skipNormalRecall = usableSignal === undefined && step > 1 && sessionId !== undefined
|
|
474
503
|
&& userQuery !== '' && injectionState.lastQueryOf(sessionId) === userQuery
|
|
475
504
|
if (!skipNormalRecall) {
|
|
505
|
+
const recallScopes = usableSignal === undefined ? scopes : autoScopes
|
|
506
|
+
const recallExclude = usableSignal === undefined ? exclude : excludeAuto
|
|
476
507
|
const recall = await injector.maybeInjectDetailed(
|
|
477
|
-
{ messages: input.messages , signal: input.signal, ...(
|
|
508
|
+
{ messages: input.messages , signal: input.signal, ...(recallScopes !== undefined ? { scopes: recallScopes } : {}), ...(sessionId !== undefined ? { sessionId } : {}) },
|
|
478
509
|
{ messages: decision.messages },
|
|
479
510
|
{
|
|
480
511
|
...(sessionId !== undefined ? { sessionId } : {}),
|
|
481
|
-
...(
|
|
482
|
-
|
|
512
|
+
...(usableSignal !== undefined ? { query: usableSignal.query, trigger: usableSignal.reason, force: true } : { trigger: 'turn_start' }),
|
|
513
|
+
...(usableSignal?.tag ? { tag: usableSignal.tag, requireTag: true } : {}),
|
|
514
|
+
excludeIds: recallExclude,
|
|
483
515
|
},
|
|
484
516
|
)
|
|
485
517
|
if (recall?.text) parts.push(recall.text)
|
|
486
518
|
if (recall) {
|
|
487
519
|
recordAudit({
|
|
488
520
|
...(sessionId !== undefined ? { sessionId } : {}),
|
|
489
|
-
trigger:
|
|
490
|
-
phase:
|
|
521
|
+
trigger: usableSignal?.reason ?? 'turn_start',
|
|
522
|
+
phase: usableSignal?.phase ?? detectPhase(userQuery),
|
|
491
523
|
...(auditQuery(recall.query) !== undefined ? { query: auditQuery(recall.query) } : {}),
|
|
492
524
|
candidates: recall.candidates,
|
|
493
525
|
contentIds: recall.ids,
|
|
@@ -496,8 +528,8 @@ export function apply(ctx , config = {}) {
|
|
|
496
528
|
dedupSkipped: recall.dedupSkipped,
|
|
497
529
|
budgets: { recall: auditBudget(settings.recall.tokenBudget, recall.tokens) },
|
|
498
530
|
retrieval: recall.retrieval,
|
|
499
|
-
...(
|
|
500
|
-
? { signal: { reason:
|
|
531
|
+
...(usableSignal !== undefined
|
|
532
|
+
? { signal: { reason: usableSignal.reason, ...(usableSignal.errorClass ? { errorClass: usableSignal.errorClass } : {}), ...(usableSignal.tool ? { tool: usableSignal.tool } : {}), ...(usableSignal.tag ? { tag: usableSignal.tag } : {}), ...(usableSignal.source ? { source: usableSignal.source } : {}) } }
|
|
501
533
|
: {}),
|
|
502
534
|
})
|
|
503
535
|
}
|
package/lib/inject/inject.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { estimateTokens } from '../provider/rerank.js'
|
|
10
10
|
import { normalizeScopeInput } from '../provider/scope.js'
|
|
11
|
+
import { textHasTag } from './signals.js'
|
|
11
12
|
import { InjectionState } from './state.js'
|
|
12
13
|
|
|
13
14
|
|
|
@@ -59,6 +60,20 @@ export function normalizeExtraScopes(raw , warn
|
|
|
59
60
|
return out
|
|
60
61
|
}
|
|
61
62
|
|
|
63
|
+
/**
|
|
64
|
+
* 自动召回的作用域:global + 当前会话 + 当前工作区。
|
|
65
|
+
*
|
|
66
|
+
* 普通每轮召回仍按用户配置使用 session + project + global(可额外加 extraScopes
|
|
67
|
+
* 或 fork 父会话);但行为信号触发的自动召回只认这三个标准范围,不把额外自定义
|
|
68
|
+
* 作用域 / 父会话一起搜进来。没有可用范围时返回 undefined,调用方跳过自动召回。
|
|
69
|
+
*/
|
|
70
|
+
export function autoRecallScopes(scopes ) {
|
|
71
|
+
if (scopes === undefined) return undefined
|
|
72
|
+
const out = scopes.filter((scope) =>
|
|
73
|
+
scope === 'global' || scope.startsWith('session:') || scope.startsWith('project:'))
|
|
74
|
+
return out.length > 0 ? out : undefined
|
|
75
|
+
}
|
|
76
|
+
|
|
62
77
|
/**
|
|
63
78
|
* 无显式 scope 时的召回范围:当前会话 + 当前项目 + global(provider 解析)
|
|
64
79
|
* + inject.extraScopes + 父会话(fork 时,只读召回)。
|
|
@@ -95,6 +110,8 @@ export function resolveInjectScopes(
|
|
|
95
110
|
|
|
96
111
|
|
|
97
112
|
|
|
113
|
+
|
|
114
|
+
|
|
98
115
|
|
|
99
116
|
|
|
100
117
|
|
|
@@ -115,14 +132,21 @@ export function resolveInjectScopes(
|
|
|
115
132
|
|
|
116
133
|
|
|
117
134
|
/**
|
|
118
|
-
* Extract the retrieval query: the text of the LAST user message.
|
|
119
|
-
*
|
|
120
|
-
*
|
|
135
|
+
* Extract the retrieval query: the text of the LAST **human** user message.
|
|
136
|
+
*
|
|
137
|
+
* Synthetic context messages are also role=user (memory recall, runtime/time
|
|
138
|
+
* context, skill catalog, file notices...). Taking the last user-role message
|
|
139
|
+
* blindly makes the next recall query the previous recall block itself — a
|
|
140
|
+
* cross-project self-recall loop (observed in a dsh-pocket session pulling a
|
|
141
|
+
* dsh-memory global record). Skip every known synthetic source; messages with
|
|
142
|
+
* no source (unit-test scaffolds / older hosts) are treated as human.
|
|
121
143
|
*/
|
|
122
144
|
export function pickQueryText(messages ) {
|
|
123
145
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
124
146
|
const m = messages[i]
|
|
125
147
|
if (m.role !== 'user') continue
|
|
148
|
+
const kind = m.source?.kind
|
|
149
|
+
if (kind !== undefined && kind !== '' && kind !== 'user') continue
|
|
126
150
|
const text = (m.content ?? [])
|
|
127
151
|
.filter((b) => b.type === 'text' && typeof b.text === 'string')
|
|
128
152
|
.map((b) => b.text )
|
|
@@ -239,6 +263,9 @@ export function recallText(text ) {
|
|
|
239
263
|
|
|
240
264
|
|
|
241
265
|
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
242
269
|
|
|
243
270
|
|
|
244
271
|
|
|
@@ -316,8 +343,17 @@ export class MemoryInjector {
|
|
|
316
343
|
// 成功检索后记住查询(即使没有新正文):同一 query 的后续 step 不再重复全量检索。
|
|
317
344
|
this.state.setLastQuery(sessionId, query)
|
|
318
345
|
|
|
346
|
+
// 标签触发的自动召回:只接受真正带该标签(或同义词)的记录。
|
|
347
|
+
// 否则一个泛标签(如 git)会把向量上勉强相关、但完全没有该标签的全局记忆
|
|
348
|
+
// 带进当前项目 —— 实测 dsh-pocket 会话因此注入过 dsh-memory 的 digest 记忆。
|
|
349
|
+
const requiredTag = options.requireTag === true && typeof options.tag === 'string' && options.tag.trim() !== ''
|
|
350
|
+
? options.tag.trim()
|
|
351
|
+
: ''
|
|
352
|
+
const taggedHits = requiredTag === ''
|
|
353
|
+
? hits
|
|
354
|
+
: hits.filter((hit) => (hit.record.tags ?? []).some((tag) => textHasTag(String(tag), requiredTag)))
|
|
319
355
|
const seenIds = options.excludeIds
|
|
320
|
-
const candidates = seenIds === undefined ?
|
|
356
|
+
const candidates = seenIds === undefined ? taggedHits : taggedHits.filter((hit) => !seenIds.has(hit.record.id))
|
|
321
357
|
const { fresh, deduplicated, updated } = this.state.filterNewContent(
|
|
322
358
|
sessionId,
|
|
323
359
|
candidates.map((hit) => hit.record),
|