@restregular/dsh-memory 0.6.0 → 0.6.2

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
@@ -29,7 +29,7 @@ English: Local, durable memory for DeepSeek Harness — one npm package, one loa
29
29
  | **会话摘要** | 会话第一步注入一次「已有记忆」概览:项目 + global 按**重要度 × 新鲜度**挑几条,省得模型从头摸索 |
30
30
  | **记忆使用策略** | 系统提示常驻段:什么时候该查记忆、查到怎么复用、查不到时低风险推断 / 高风险先问用户 |
31
31
  | **硬性规则** | `kind: rule` 的记忆进系统提示常驻段(限量、可关)。能机械校验的规则应该做成钩子,提示词只做解释 |
32
- | **四个工具** | `memory_save` / `memory_search` / `memory_list` / `memory_forget` |
32
+ | **五个工具** | `memory_save` / `memory_search` / `memory_list` / `memory_get` / `memory_forget`(摘要带 8 位 id,`memory_get` 直接取全文) |
33
33
  | **管理面板** | 设置页「记忆」:记录(浏览 / 搜索 / 新建 / 编辑 / 删除)+ 设置(召回、摘要、印象、策略、规则、轮末提醒逐项开关、导入导出)、向量服务启停、模型与硬件、维护(卸载 / 清空) |
34
34
  | **向量后端一键装** | 面板里选模型 → 下 llama.cpp 运行时 + 模型 → 托管 `llama-server` 进程;内置 8 个模型 + 硬件推荐 + 自定义 GGUF |
35
35
 
@@ -59,7 +59,7 @@ pnpm add @restregular/dsh-memory
59
59
  | 半边 | 作用 |
60
60
  | --- | --- |
61
61
  | `lib/provider` | 提供 `memory` 服务:JSONL 存储、双通道检索、向量回填、向量后端生命周期与一键安装 |
62
- | `lib/tools` | 注册 `memory_save` / `memory_search` / `memory_list` / `memory_forget` |
62
+ | `lib/tools` | 注册 `memory_save` / `memory_search` / `memory_list` / `memory_get` / `memory_forget` |
63
63
  | `lib/inject` | 在 `agent/pre-step` 注入召回块(可关) |
64
64
  | `lib/panel` | `/memory/api` 管理接口(含同源 / 登录围栏) |
65
65
  | `lib/client.js` | 设置页「记忆」区块(注册 id == 包名) |
@@ -90,12 +90,13 @@ memory_save({
90
90
  | `all` / `*` | **只在读取时可用**:跨所有已发现的作用域;写入会明确报错 |
91
91
 
92
92
  **2. 检索**:`memory_search({ query: "pnpm 装依赖", topK: 5 })` —— 省略 `scope` = 会话 + 项目 + global 合并(按来源标注、按 id 去重);`scope: "all"` 查所有作用域;写具体名字则只查那一个。
93
- **3. 列出 / 忘记**:`memory_list({ limit: 20 })`(默认只列当前会话,末尾附作用域清单 + 记录数)、`memory_forget({ id })` 或 `memory_forget({ query, scope })`(按内容删默认**只作用于当前会话**,防止跨作用域误删)。
93
+ **3. 按 id 取全文**:召回 / 摘要每行开头是 8 位 id 前缀,`memory_get({ ids: ["3f2a9c1d"] })` 直接拿原文,不用再检索。
94
+ **4. 列出 / 忘记**:`memory_list({ limit: 20 })`(默认只列当前会话,末尾附作用域清单 + 记录数)、`memory_forget({ id })` 或 `memory_forget({ query, scope })`(按内容删默认**只作用于当前会话**,防止跨作用域误删)。
94
95
 
95
- **4. 打开面板**:设置页 →「记忆」。面板分两个标签:
96
+ **5. 打开面板**:设置页 →「记忆」;也可以在「设置 → 侧栏入口」打开左侧栏的「记忆」按钮,点击在主界面打开面板。面板分两个标签:
96
97
 
97
98
  - **记录**:顶部统计(记忆数 / 作用域数 / 待嵌入向量数)、**新建**(任意作用域 + 类型,类型里含 `rule`)、记录列表(搜索、按作用域筛选、展开编辑、删除);作用域下拉**动态枚举实际存在的作用域**(`global` 显示「全局」、project 显示 cwd、会话 scope 显示会话标题、自定义 scope 显示原名);「向量服务」:状态、地址、启停开关、**模型与硬件**(见下)、维护(卸载向量服务 / 清空记忆数据,两步确认)
98
- - **设置**:注入链路逐项开关 —— 每轮召回(topK / 预算)、印象形态(每条字数)、会话摘要(条数 / 预算)、记忆使用策略段、硬性规则段(条数 / 预算,并显示当前规则条数)、轮末提醒;底部「数据」:导出全部 / 导入文件。改完立即生效,不需要重启
99
+ - **设置**:注入链路逐项开关 —— 每轮召回(topK / 预算)、印象形态(每条字数)、会话摘要(条数 / 预算)、记忆使用策略段、硬性规则段(条数 / 预算,并显示当前规则条数)、轮末提醒、侧栏入口;底部「数据」:导出全部 / 导入文件。改完立即生效,不需要重启
99
100
 
100
101
  > **导入 / 导出**:导出的是纯文本 —— 作用域、类型、内容、标签、重要度、时间戳,**没有向量**。导入时逐条走保存路径,按**当前模型重新嵌入**,并按「作用域 + 内容」去重(重复的计入「跳过」)。一次最多 5000 条。
101
102
 
@@ -308,6 +309,14 @@ tools/build-single-package.mjs 构建(产物契约检查 + 可选加载验证)
308
309
 
309
310
  ## 版本
310
311
 
312
+ - **0.6.2** —— 设置页**去掉「保存设置」按钮**:开关拨动、数值改动即保存(连续调数值会合并成一次请求),页内只留一行“已保存”提示;顶部说明改成与行为一致的一句话(“设置保存在记忆数据目录的 settings.json”),不再写“保存后生效/无需重启”这类与实际操作不符的描述。
313
+ - **0.6.1** —— 面板与工具打磨:
314
+ - **标签页**改成分段式按钮(选中项浅底 + 品牌色),记录页各区块之间补上间距。
315
+ - **设置项**统一成开关按钮(不再用复选框 + “启用”文字),每条提示压到一行。
316
+ - **侧栏入口**:新增设置开关(默认关),开启后在左侧栏「插件」下方出现「记忆」,点击在主界面打开面板;设置页里的入口不变。
317
+ - **`memory_get`**:召回 / 摘要每行开头带 8 位 id 前缀,可按 id 或前缀直接取全文,省掉一次检索(检索耗时随模型/配置浮动)。
318
+ - **提示词**:策略段改成“更新过时的记忆并明确告诉用户哪些过时记忆已变更”;会话摘要去掉“省得你重复摸索”;召回提示改为“以下是与你这次请求可能相关的记忆摘要”。
319
+ - **规则可见性**:关闭「硬性规则」只影响系统提示常驻段,`memory_search` / `memory_list` / `memory_get` 仍能拿到 `kind=rule` 的记录(开关是注入开关,不是数据访问开关;面板里已写明)。
311
320
  - **0.6.0** —— 注入分层,面板加「设置」标签页:
312
321
  - **印象形态召回**:每轮召回默认只给每条记忆的开头(默认 120 字)+「需要细节用 memory_search」的指引,不再一次灌 300 字全文;面板可关掉退回长文。
313
322
  - **会话摘要**:会话第一步注入一次概览 —— 项目 + global 按「新鲜度(30 天半衰期)× 重要度」挑 8 条,同分时会话 > 项目 > 自定义 > 全局。
package/lib/client.js CHANGED
@@ -135,21 +135,34 @@ window.__ModuleLoader__.load({
135
135
  '.memp .dropitem.on{background:var(--dsw-alias-bg-layer-2)}',
136
136
  '.memp .dropitem.on .dropname{font-weight:600;color:var(--dsw-alias-brand-primary)}',
137
137
  '.memp .warn{font-size:11.5px;color:var(--dsw-alias-label-secondary)}',
138
- // 面板内的标签栏:记录 / 设置
139
- '.memp .tabs{display:flex;gap:2px;border-bottom:1px solid var(--dsw-alias-border-l1);margin-bottom:12px}',
140
- '.memp .tab{background:none;border:0;border-bottom:2px solid transparent;padding:6px 12px;color:var(--dsw-alias-label-secondary);cursor:pointer;font-size:13px}',
141
- '.memp .tab.on{color:var(--dsw-alias-brand-primary);border-bottom-color:var(--dsw-alias-brand-primary);font-weight:600}',
142
- '.memp .setrow{display:flex;flex-wrap:wrap;align-items:center;gap:8px 14px;padding:10px 0;border-bottom:1px solid var(--dsw-alias-border-l1)}',
143
- '.memp .setrow .set-title{min-width:132px;font-weight:600;font-size:13px}',
144
- '.memp .setrow .set-desc{flex:1 1 100%;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.5}',
138
+ // 面板内的标签栏:分段式按钮(参照宿主设置页的分段控件)
139
+ '.memp .tabs{display:inline-flex;gap:2px;padding:2px;border-radius:9px;background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l1);margin-bottom:14px}',
140
+ '.memp .tab{background:none;border:0;border-radius:7px;padding:4px 14px;color:var(--dsw-alias-label-secondary);cursor:pointer;font-size:13px;line-height:1.6;transition:background .12s ease,color .12s ease}',
141
+ '.memp .tab:hover{color:var(--dsw-alias-label-primary)}',
142
+ '.memp .tab.on{background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-brand-primary);font-weight:600;box-shadow:0 1px 2px rgba(0,0,0,.10)}',
143
+ // 记录视图:各区块之间留出呼吸感(之前全贴在一起)
144
+ '.memp .memp-body > * + *{margin-top:14px}',
145
+ '.memp .stats{margin-bottom:0}',
146
+ '.memp .setrow{display:flex;flex-wrap:wrap;align-items:center;gap:6px 14px;padding:11px 0;border-bottom:1px solid var(--dsw-alias-border-l1)}',
147
+ '.memp .setrow .set-title{min-width:112px;font-weight:600;font-size:13px}',
148
+ '.memp .setrow .set-desc{flex:1 1 100%;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.5;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}',
145
149
  '.memp .setrow .set-field{display:inline-flex;align-items:center;gap:5px;font-size:12px;color:var(--dsw-alias-label-secondary)}',
146
150
  '.memp .setrow input[type=number]{width:78px}',
151
+ // 开关:与向量服务的 toggle 同一套视觉(轨道 + 圆点)
152
+ '.memp .switch{position:relative;width:34px;height:20px;padding:0;border:0;border-radius:999px;background:var(--dsw-alias-border-l1);cursor:pointer;transition:background .12s ease}',
153
+ '.memp .switch.on{background:var(--dsw-alias-brand-primary)}',
154
+ '.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)}',
155
+ '.memp .switch.on .knob{left:16px}',
147
156
  '.memp .setfoot{display:flex;align-items:center;gap:10px;padding-top:12px}',
148
157
  '.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)}',
149
158
  '.memp .create .row{display:flex;gap:8px;align-items:center;margin:6px 0;flex-wrap:wrap}',
150
159
  '.memp .create textarea{width:100%;min-height:64px}',
151
160
  '.memp .data{padding-top:4px}',
152
161
  '.memp .data .row{display:flex;gap:10px;align-items:center;flex-wrap:wrap;margin-top:8px}',
162
+ // 侧栏入口打开的主界面页面:整块可滚动,内容用面板本体
163
+ '.mem-page{height:100%;overflow:auto;padding:16px 20px 40px}',
164
+ '.mem-page-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px}',
165
+ '.mem-page-head h2{font-size:15px;font-weight:600;margin:0}',
153
166
  ].join('')
154
167
 
155
168
  async function api(method, body) {
@@ -558,15 +571,30 @@ window.__ModuleLoader__.load({
558
571
  )
559
572
  }
560
573
 
574
+ /** 设置项开关:轨道 + 圆点,与向量服务的 toggle 同一套视觉。 */
575
+ function Switch({ checked, disabled, onChange, title }) {
576
+ return h('button', {
577
+ type: 'button',
578
+ className: 'switch' + (checked ? ' on' : ''),
579
+ role: 'switch',
580
+ 'aria-checked': Boolean(checked),
581
+ disabled: Boolean(disabled),
582
+ ...(title ? { title } : {}),
583
+ onClick: () => onChange(!checked),
584
+ }, h('span', { className: 'knob' }))
585
+ }
586
+
587
+ /** 设置自动保存的合并定时器:连续调数值只发一次请求。 */
588
+ let autoSaveTimer = null
589
+
561
590
  /**
562
- * 设置标签页:这些开关直接改注入行为,保存后下一步生效(不进 cordis 配置,
563
- * 落盘在记忆数据目录的 settings.json)。分组顺序与「注入链路」一致:
564
- * 每轮召回 → 印象 → 会话摘要 → 系统提示(策略/规则) → 轮末提醒。
591
+ * 设置标签页:这些开关直接改注入行为,改完立即保存(没有"保存"按钮)。
592
+ * 每轮召回 → 印象 → 会话摘要 → 系统提示(策略/规则) → 轮末提醒 → 界面。
565
593
  */
566
594
  const SETTINGS_GROUPS = [
567
595
  {
568
596
  key: 'recall', title: '每轮召回',
569
- desc: '按这一轮的问题检索记忆并插入上下文;内容没变时不会重复注入。',
597
+ desc: '按本轮问题检索记忆并插入上下文,内容没变不重复注入。',
570
598
  fields: [
571
599
  { k: 'enabled', label: '启用', type: 'bool' },
572
600
  { k: 'topK', label: '最多条数', type: 'num', min: 1, max: 20, step: 1 },
@@ -575,7 +603,7 @@ window.__ModuleLoader__.load({
575
603
  },
576
604
  {
577
605
  key: 'impression', title: '印象形态',
578
- desc: '召回只给每条的开头摘要;模型判断相关但需要细节时,自己用 memory_search 取全文。',
606
+ desc: '每条只给摘要,细节由模型用 memory_get 取。',
579
607
  fields: [
580
608
  { k: 'enabled', label: '启用', type: 'bool' },
581
609
  { k: 'chars', label: '每条字数', type: 'num', min: 40, max: 800, step: 20 },
@@ -583,7 +611,7 @@ window.__ModuleLoader__.load({
583
611
  },
584
612
  {
585
613
  key: 'digest', title: '会话摘要',
586
- desc: '会话第一步给一次「这个项目 / 全局已有记忆」的概览(按重要度 × 新鲜度挑选,每个会话一次)。',
614
+ desc: '会话第一步给一次项目 / 全局的记忆概览。',
587
615
  fields: [
588
616
  { k: 'enabled', label: '启用', type: 'bool' },
589
617
  { k: 'topK', label: '最多条数', type: 'num', min: 1, max: 30, step: 1 },
@@ -592,12 +620,13 @@ window.__ModuleLoader__.load({
592
620
  },
593
621
  {
594
622
  key: 'policy', title: '记忆使用策略',
595
- desc: '系统提示里的常驻段:什么时候该查记忆、查到怎么用、查不到怎么办。文本稳定,可随前缀缓存。',
623
+ desc: '系统提示常驻段:何时查、查到怎么用、查不到怎么办。',
596
624
  fields: [{ k: 'enabled', label: '启用', type: 'bool' }],
597
625
  },
598
626
  {
599
627
  key: 'rules', title: '硬性规则',
600
- desc: '把 kind = rule 的记忆放进系统提示常驻段。可机械校验的规则更适合做成钩子,而不是写在这里。',
628
+ desc: '把 kind=rule 的记忆放进系统提示常驻段。',
629
+ hint: '关闭只影响系统提示常驻段,记忆本身仍可被检索',
601
630
  fields: [
602
631
  { k: 'enabled', label: '启用', type: 'bool' },
603
632
  { k: 'maxItems', label: '最多条数', type: 'num', min: 1, max: 40, step: 1 },
@@ -606,14 +635,18 @@ window.__ModuleLoader__.load({
606
635
  },
607
636
  {
608
637
  key: 'turnEnd', title: '轮末提醒',
609
- desc: '本轮跑过多步时,下一轮开头提醒一句「若产生了可复用的结论,先 memory_save」。默认关闭。',
638
+ desc: '下一轮开头提醒把本轮结论落盘,默认关闭。',
639
+ fields: [{ k: 'enabled', label: '启用', type: 'bool' }],
640
+ },
641
+ {
642
+ key: 'sidebar', title: '侧栏入口',
643
+ desc: '在左侧栏「插件」下方显示记忆入口,点击打开面板。',
610
644
  fields: [{ k: 'enabled', label: '启用', type: 'bool' }],
611
645
  },
612
646
  ]
613
647
 
614
648
  function SettingsTab() {
615
649
  const [settings, setSettings] = React.useState(null)
616
- const [busy, setBusy] = React.useState(false)
617
650
  const [error, setError] = React.useState('')
618
651
  const [notice, setNotice] = React.useState('')
619
652
  const [rulesCount, setRulesCount] = React.useState(null)
@@ -664,43 +697,51 @@ window.__ModuleLoader__.load({
664
697
  event.target.value = ''
665
698
  }
666
699
 
667
- const patch = (group, key, value) => setSettings((current) => {
668
- if (!current) return current
669
- return { ...current, [group]: { ...current[group], [key]: value } }
670
- })
700
+ // 改动即保存:开关/数值一变就提交(数值连续输入时合并成一次请求),
701
+ // 不再有"保存设置"按钮 —— 界面上也就不该再写"保存后生效"这类话。
702
+ const patch = (group, key, value) => {
703
+ if (!settings) return
704
+ const next = { ...settings, [group]: { ...settings[group], [key]: value } }
705
+ setSettings(next)
706
+ autoSave(next)
707
+ }
671
708
 
672
- const save = async () => {
673
- setBusy(true); setError(''); setNotice('')
674
- try {
675
- const next = await api('settings', settings)
676
- setSettings(next)
677
- setNotice('已保存,下一步生效')
678
- } catch (e) {
679
- setError(String(e.message || e))
680
- }
681
- setBusy(false)
709
+ const autoSave = (next) => {
710
+ if (autoSaveTimer !== null) clearTimeout(autoSaveTimer)
711
+ setError('')
712
+ autoSaveTimer = setTimeout(async () => {
713
+ autoSaveTimer = null
714
+ try {
715
+ await api('settings', next)
716
+ setNotice('已保存')
717
+ setTimeout(() => setNotice(''), 1500)
718
+ if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function') {
719
+ try { window.dispatchEvent(new CustomEvent('dsh-memory:settings')) } catch { /* 没有 CustomEvent 就等下次启动 */ }
720
+ }
721
+ } catch (e) {
722
+ setError(String(e.message || e))
723
+ }
724
+ }, 250)
682
725
  }
683
726
 
684
727
  if (!settings) return h('div', { className: 'empty' }, error || '加载设置…')
685
728
 
686
729
  return h('div', { className: 'setp' },
687
- h('div', { className: 'hint' }, '开关立即生效,无需重启;设置保存在记忆数据目录的 settings.json。'),
730
+ h('div', { className: 'hint' }, '设置保存在记忆数据目录的 settings.json。'),
688
731
  SETTINGS_GROUPS.map((group) => {
689
732
  const value = settings[group.key] || {}
690
733
  return h('div', { className: 'setrow', key: group.key },
691
734
  h('span', { className: 'set-title' }, group.title),
692
735
  group.fields.map((field) => field.type === 'bool'
693
- ? h('label', { className: 'set-field', key: field.k }, ' ',
694
- h('input', {
695
- type: 'checkbox',
696
- checked: Boolean(value[field.k]),
697
- disabled: busy,
698
- onChange: (e) => patch(group.key, field.k, e.target.checked),
699
- }), ' ', field.label)
736
+ ? h(Switch, {
737
+ key: field.k,
738
+ checked: Boolean(value[field.k]),
739
+ title: group.hint || field.label,
740
+ onChange: (next) => patch(group.key, field.k, next),
741
+ })
700
742
  : h('label', { className: 'set-field', key: field.k }, field.label, ' ',
701
743
  h('input', {
702
744
  type: 'number', min: field.min, max: field.max, step: field.step, value: value[field.k],
703
- disabled: busy,
704
745
  onChange: (e) => patch(group.key, field.k, Number(e.target.value)),
705
746
  }))),
706
747
  h('span', { className: 'set-desc' }, group.desc),
@@ -711,7 +752,7 @@ window.__ModuleLoader__.load({
711
752
  }),
712
753
  h('div', { className: 'setrow data' },
713
754
  h('span', { className: 'set-title' }, '数据'),
714
- h('span', { className: 'set-desc' }, '导出只含文本(作用域 / 类型 / 内容 / 标签 / 重要度),不含向量;导入时按当前模型重新嵌入。导入按「作用域 + 内容」去重。'),
755
+ h('span', { className: 'set-desc' }, '导出文本(不含向量),导入按当前模型重新嵌入并按内容去重。'),
715
756
  h('div', { className: 'row' },
716
757
  h('button', { onClick: exportAll }, '导出全部'),
717
758
  h('label', { className: 'set-field' }, '导入文件',
@@ -719,11 +760,8 @@ window.__ModuleLoader__.load({
719
760
  dataNotice ? h('span', { className: 'muted' }, dataNotice) : null,
720
761
  ),
721
762
  ),
722
- h('div', { className: 'setfoot' },
723
- h('button', { onClick: save, disabled: busy }, busy ? '保存中…' : '保存设置'),
724
- notice ? h('span', { className: 'muted' }, notice) : null,
725
- error ? h('span', { className: 'err' }, error) : null,
726
- ),
763
+ error ? h('div', { className: 'err' }, error) : null,
764
+ notice ? h('div', { className: 'muted' }, notice) : null,
727
765
  )
728
766
  }
729
767
 
@@ -1113,6 +1151,23 @@ window.__ModuleLoader__.load({
1113
1151
 
1114
1152
  const inject = ['slots']
1115
1153
 
1154
+ /** 侧栏入口打开的主界面页面(整块可滚动,内容就是面板本体)。 */
1155
+ function MemoryPage() {
1156
+ return h('div', { className: 'mem-page' },
1157
+ h('div', { className: 'mem-page-head' }, h('h2', null, '记忆')),
1158
+ h(MemoryPanel, {}),
1159
+ )
1160
+ }
1161
+
1162
+ /** 侧栏图标:16px 单色线稿芯片,与设置导航那一列同一规范。 */
1163
+ function NavChipIcon() {
1164
+ return h('svg', { width: 16, height: 16, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': 'true' },
1165
+ h('rect', { x: 5, y: 5, width: 6, height: 6, rx: 1.4, stroke: 'currentColor', strokeWidth: 1.3 }),
1166
+ h('rect', { x: 6.9, y: 6.9, width: 2.2, height: 2.2, rx: 0.6, stroke: 'currentColor', strokeWidth: 1.3 }),
1167
+ h('path', { d: 'M8 5V3.2M8 11v1.8M5 8H3.2M11 8h1.8', stroke: 'currentColor', strokeWidth: 1.3, strokeLinecap: 'round' }),
1168
+ )
1169
+ }
1170
+
1116
1171
  function apply(ctx) {
1117
1172
  try {
1118
1173
  const styleEl = document.createElement('style')
@@ -1128,6 +1183,40 @@ window.__ModuleLoader__.load({
1128
1183
  { name: 'settings.section', id: 'memory', order: 24, label: NAV_LABEL },
1129
1184
  () => React.createElement(MemoryPanel),
1130
1185
  ))
1186
+
1187
+ // 侧栏入口(可选):开启后在左侧栏「插件」下方多一个「记忆」,点击在主界面打开面板。
1188
+ // 注册契约见 dsh-client-ui-schedule:sidebar.panellist 给 id/label/icon,main 用同一个 key。
1189
+ let sidebarDisposers = null
1190
+ const syncSidebar = () => {
1191
+ api('settings').then((settings) => {
1192
+ const want = Boolean(settings && settings.sidebar && settings.sidebar.enabled)
1193
+ if (want === (sidebarDisposers !== null)) return
1194
+ if (!want) {
1195
+ for (const dispose of sidebarDisposers ?? []) {
1196
+ try { if (typeof dispose === 'function') dispose() } catch { /* 已卸载 */ }
1197
+ }
1198
+ sidebarDisposers = null
1199
+ return
1200
+ }
1201
+ try {
1202
+ sidebarDisposers = [
1203
+ slots.inject('main', () => slots.register({ name: 'main', key: 'memory' }, () => React.createElement(MemoryPage))),
1204
+ slots.inject('sidebar.panellist', () => slots.register(
1205
+ { name: 'sidebar.panellist', id: 'memory', order: 20, label: () => NAV_LABEL },
1206
+ () => React.createElement(NavChipIcon),
1207
+ )),
1208
+ ]
1209
+ } catch (error) {
1210
+ sidebarDisposers = null
1211
+ console.warn('[dsh-memory] 侧栏入口注册失败:', error?.message)
1212
+ }
1213
+ }).catch(() => { /* 读不到设置就维持现状 */ })
1214
+ }
1215
+ syncSidebar()
1216
+ if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
1217
+ window.addEventListener('dsh-memory:settings', syncSidebar)
1218
+ ctx.effect(() => () => window.removeEventListener('dsh-memory:settings', syncSidebar), 'dsh-memory: sidebar entry')
1219
+ }
1131
1220
  } catch (error) {
1132
1221
  console.error('[dsh-memory] client apply 失败(已吞掉):', error?.message)
1133
1222
  }
@@ -9,7 +9,7 @@ import { estimateTokens } from '../provider/rerank.js'
9
9
 
10
10
 
11
11
  const HEADER =
12
- '以下是本项目 / 全局已有的长期记忆摘要(按重要度挑出的前几条,省得你重复摸索;' +
12
+ '以下是本项目 / 全局已有的长期记忆摘要(按重要度挑出的前几条;' +
13
13
  '需要原文用 memory_search,删除用 memory_forget):'
14
14
 
15
15
  /** scope 的中文标签:global/项目/会话/自定义。 */
@@ -52,7 +52,7 @@ export function renderDigestBlock(
52
52
  let tokens = estimateTokens(HEADER) + 4
53
53
  const lines = []
54
54
  for (const record of rankForDigest(records).slice(0, cfg.topK)) {
55
- const line = `- [${digestScopeLabel(record.scope)}/${record.kind}] ${record.content.replace(/\s+/g, ' ').slice(0, 160)}`
55
+ const line = `- ${record.id.slice(0, 8)} [${digestScopeLabel(record.scope)}/${record.kind}] ${record.content.replace(/\s+/g, ' ').slice(0, 160)}`
56
56
  const cost = estimateTokens(line) + 1
57
57
  if (tokens + cost > cfg.tokenBudget) break
58
58
  lines.push(line)
@@ -172,12 +172,12 @@ export function renderRecallBlock(
172
172
  const impression = options.impression === true
173
173
  const chars = impression ? (options.chars ?? 120) : 300
174
174
  const header = impression
175
- ? '以下是与你这次请求可能相关的记忆(摘要形态;判断相关但需要原文时,用 memory_search 取全文):'
175
+ ? '以下是与你这次请求可能相关的记忆摘要:'
176
176
  : '以下是与此请求可能相关的长期记忆,供参考(可用 memory_search 核实,用 memory_forget 删除):'
177
177
  let tokens = estimateTokens(header) + 4
178
178
  const lines = []
179
179
  for (const h of hits.slice(0, cfg.topK)) {
180
- const line = `- ${h.record.content.replace(/\s+/g, ' ').slice(0, chars)}`
180
+ const line = `- ${h.record.id.slice(0, 8)} ${h.record.content.replace(/\s+/g, ' ').slice(0, chars)}`
181
181
  const cost = estimateTokens(line) + 1
182
182
  if (tokens + cost > cfg.tokenBudget) break
183
183
  lines.push(line)
@@ -4,13 +4,13 @@
4
4
  */
5
5
  export const POLICY_TEXT = `## 长期记忆
6
6
 
7
- 本会话挂着一个本地记忆库,工具:memory_search / memory_list / memory_save / memory_forget(可按会话、项目、全局等作用域读写)。
7
+ 本会话挂着一个本地记忆库,工具:memory_search / memory_list / memory_get / memory_save / memory_forget(可按会话、项目、全局等作用域读写)。
8
8
 
9
9
  遇到以下情况先查记忆,不要凭猜测开始:
10
10
  - 不确定这个项目以前怎么做、有没有既定约定、某个坑是否踩过;
11
11
  - 用户的话里出现「上次 / 之前 / 还是那样」这类指代。
12
12
 
13
- 查到就直接复用,并说明依据来自记忆。记忆与当前代码或文件冲突时,以现场为准,并指出哪条记忆需要更新。
13
+ 查到就直接复用,并说明依据来自记忆。记忆与当前代码或文件冲突时,以现场为准,更新过时的记忆并明确告诉用户哪些过时记忆已变更。
14
14
 
15
15
  查不到时:
16
16
  - 低风险、可回退的:按仓库现有风格推断着做,明确标出你的假设;
@@ -120,6 +120,11 @@ export class CordisMemoryService extends Service {
120
120
  return this.impl.list(input)
121
121
  }
122
122
 
123
+ /** memory_get:按 id 批量取记录。 */
124
+ getByIds(ids ) {
125
+ return this.impl.getByIds(ids)
126
+ }
127
+
123
128
  /** 面板新建记忆 / 规则。 */
124
129
  createRecord(input ) {
125
130
  return this.impl.createRecord(input)
@@ -1474,6 +1474,30 @@ export class LocalMemoryService {
1474
1474
  return records.slice(0, input.limit ?? 50)
1475
1475
  }
1476
1476
 
1477
+ /**
1478
+ * 按 id 批量取记录(memory_get)。接受完整 id,也接受摘要里给出的前 8 位前缀
1479
+ * (前缀命中多条时全部返回,由调用方/模型自行判断)。取全文不需要再检索。
1480
+ */
1481
+ getByIds(ids ) {
1482
+ this.discoverScopes()
1483
+ const scopes = this.store.allScopes()
1484
+ const out = []
1485
+ const seen = new Set ()
1486
+ for (const token of ids) {
1487
+ if (typeof token !== 'string' || token.length === 0) continue
1488
+ for (const s of scopes) {
1489
+ for (const rec of s.records.values()) {
1490
+ if (seen.has(rec.id)) continue
1491
+ if (rec.id === token || rec.id.startsWith(token)) {
1492
+ seen.add(rec.id)
1493
+ out.push(rec)
1494
+ }
1495
+ }
1496
+ }
1497
+ }
1498
+ return out
1499
+ }
1500
+
1477
1501
  /**
1478
1502
  * 面板新建一条记忆 / 规则。scope 必须是**明确的键**(global / project:<路径> /
1479
1503
  * session:<id> / 自定义名)—— 面板拿不到会话上下文,'project'/'session' 这种
@@ -41,6 +41,11 @@
41
41
 
42
42
 
43
43
 
44
+ /** 界面:是否在左侧栏「插件」下方显示记忆入口(点击在主界面打开面板)。 */
45
+
46
+
47
+
48
+
44
49
 
45
50
 
46
51
 
@@ -48,6 +53,7 @@
48
53
 
49
54
 
50
55
 
56
+
51
57
 
52
58
 
53
59
  export const defaultInjectSettings = {
@@ -57,6 +63,7 @@ export const defaultInjectSettings = {
57
63
  policy: { enabled: true },
58
64
  rules: { enabled: true, maxItems: 10, tokenBudget: 300 },
59
65
  turnEnd: { enabled: false },
66
+ sidebar: { enabled: false },
60
67
  }
61
68
 
62
69
  const clampInt = (value , min , max , fallback ) => {
@@ -94,6 +101,7 @@ export function normalizeInjectSettings(raw , base = def
94
101
  const policy = section('policy')
95
102
  const rules = section('rules')
96
103
  const turnEnd = section('turnEnd')
104
+ const sidebar = section('sidebar')
97
105
  return {
98
106
  recall: {
99
107
  enabled: bool(recall.enabled, base.recall.enabled),
@@ -116,6 +124,7 @@ export function normalizeInjectSettings(raw , base = def
116
124
  tokenBudget: clampInt(rules.tokenBudget, 50, 4000, base.rules.tokenBudget),
117
125
  },
118
126
  turnEnd: { enabled: bool(turnEnd.enabled, base.turnEnd.enabled) },
127
+ sidebar: { enabled: bool(sidebar.enabled, base.sidebar.enabled) },
119
128
  }
120
129
  }
121
130
 
@@ -33,6 +33,8 @@ import { normalizeScopeInput, resolveScopeRef } from '../provider/scope.js'
33
33
 
34
34
                      
35
35
 
36
+                           
37
+
36
38
                 
37
39
 
38
40
 
@@ -373,12 +375,51 @@ export function memoryListTool(opts )
373
375
  }
374
376
  }
375
377
 
378
+
379
+
380
+
381
+
382
+
383
+
384
+ export function memoryGetTool(opts ) {
385
+ return {
386
+ name: 'memory_get',
387
+ description: 'Fetch memories by id or by the 8-char id prefix shown in recall/digest summaries. Fast path: no retrieval needed.',
388
+ parameters: {
389
+ ids: { type: 'array', items: { type: 'string' }, description: '记忆 id 或摘要开头的 8 位前缀,1~50 个', required: true },
390
+ },
391
+ async execute(args ) {
392
+ const service = svc(opts)
393
+ const ids = Array.isArray(args.ids)
394
+ ? [...new Set(args.ids.map(String).filter((id) => id.trim() !== ''))].slice(0, 50)
395
+ : []
396
+ if (ids.length === 0) throw toolError(new Error('ids 不能为空'))
397
+ if (typeof service.getByIds !== 'function') {
398
+ throw toolError(new Error('当前 provider 不支持 memory_get(请升级 @restregular/dsh-memory)'))
399
+ }
400
+ try {
401
+ const found = service.getByIds(ids)
402
+ return {
403
+ records: found.map((r) => ({
404
+ id: r.id, scope: r.scope, kind: r.kind, content: r.content,
405
+ tags: r.tags, importance: r.importance, updatedAt: r.updatedAt,
406
+ })),
407
+ missing: ids.filter((token) => !found.some((r) => r.id === token || r.id.startsWith(token))),
408
+ }
409
+ } catch (error) {
410
+ throw toolError(error)
411
+ }
412
+ },
413
+ }
414
+ }
415
+
376
416
  export function memoryTools(opts ) {
377
417
  return {
378
418
  memory_save: memorySaveTool(opts),
379
419
  memory_search: memorySearchTool(opts),
380
420
  memory_forget: memoryForgetTool(opts),
381
421
  memory_list: memoryListTool(opts),
422
+ memory_get: memoryGetTool(opts),
382
423
  }
383
424
  }
384
425
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restregular/dsh-memory",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "DeepSeek Harness 本地长期记忆(单包单入口):JSONL 存储 + 本地向量检索(BGE-M3)+ 四个模型工具 + 自动召回注入 + 管理面板。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",