@restregular/dsh-memory 0.6.0 → 0.6.1

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,13 @@ tools/build-single-package.mjs 构建(产物契约检查 + 可选加载验证)
308
309
 
309
310
  ## 版本
310
311
 
312
+ - **0.6.1** —— 面板与工具打磨:
313
+ - **标签页**改成分段式按钮(选中项浅底 + 品牌色),记录页各区块之间补上间距。
314
+ - **设置项**统一成开关按钮(不再用复选框 + “启用”文字),每条提示压到一行。
315
+ - **侧栏入口**:新增设置开关(默认关),开启后在左侧栏「插件」下方出现「记忆」,点击在主界面打开面板;设置页里的入口不变。
316
+ - **`memory_get`**:召回 / 摘要每行开头带 8 位 id 前缀,可按 id 或前缀直接取全文,省掉一次检索(检索耗时随模型/配置浮动)。
317
+ - **提示词**:策略段改成“更新过时的记忆并明确告诉用户哪些过时记忆已变更”;会话摘要去掉“省得你重复摸索”;召回提示改为“以下是与你这次请求可能相关的记忆摘要”。
318
+ - **规则可见性**:关闭「硬性规则」只影响系统提示常驻段,`memory_search` / `memory_list` / `memory_get` 仍能拿到 `kind=rule` 的记录(开关是注入开关,不是数据访问开关;面板里已写明)。
311
319
  - **0.6.0** —— 注入分层,面板加「设置」标签页:
312
320
  - **印象形态召回**:每轮召回默认只给每条记忆的开头(默认 120 字)+「需要细节用 memory_search」的指引,不再一次灌 300 字全文;面板可关掉退回长文。
313
321
  - **会话摘要**:会话第一步注入一次概览 —— 项目 + 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,28 @@ 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
+
561
587
  /**
562
588
  * 设置标签页:这些开关直接改注入行为,保存后下一步生效(不进 cordis 配置,
563
589
  * 落盘在记忆数据目录的 settings.json)。分组顺序与「注入链路」一致:
564
- * 每轮召回 → 印象 → 会话摘要 → 系统提示(策略/规则) → 轮末提醒。
590
+ * 每轮召回 → 印象 → 会话摘要 → 系统提示(策略/规则) → 轮末提醒 → 界面。
565
591
  */
566
592
  const SETTINGS_GROUPS = [
567
593
  {
568
594
  key: 'recall', title: '每轮召回',
569
- desc: '按这一轮的问题检索记忆并插入上下文;内容没变时不会重复注入。',
595
+ desc: '按本轮问题检索记忆并插入上下文,内容没变不重复注入。',
570
596
  fields: [
571
597
  { k: 'enabled', label: '启用', type: 'bool' },
572
598
  { k: 'topK', label: '最多条数', type: 'num', min: 1, max: 20, step: 1 },
@@ -575,7 +601,7 @@ window.__ModuleLoader__.load({
575
601
  },
576
602
  {
577
603
  key: 'impression', title: '印象形态',
578
- desc: '召回只给每条的开头摘要;模型判断相关但需要细节时,自己用 memory_search 取全文。',
604
+ desc: '每条只给摘要,细节由模型用 memory_get 取。',
579
605
  fields: [
580
606
  { k: 'enabled', label: '启用', type: 'bool' },
581
607
  { k: 'chars', label: '每条字数', type: 'num', min: 40, max: 800, step: 20 },
@@ -583,7 +609,7 @@ window.__ModuleLoader__.load({
583
609
  },
584
610
  {
585
611
  key: 'digest', title: '会话摘要',
586
- desc: '会话第一步给一次「这个项目 / 全局已有记忆」的概览(按重要度 × 新鲜度挑选,每个会话一次)。',
612
+ desc: '会话第一步给一次项目 / 全局的记忆概览。',
587
613
  fields: [
588
614
  { k: 'enabled', label: '启用', type: 'bool' },
589
615
  { k: 'topK', label: '最多条数', type: 'num', min: 1, max: 30, step: 1 },
@@ -592,12 +618,13 @@ window.__ModuleLoader__.load({
592
618
  },
593
619
  {
594
620
  key: 'policy', title: '记忆使用策略',
595
- desc: '系统提示里的常驻段:什么时候该查记忆、查到怎么用、查不到怎么办。文本稳定,可随前缀缓存。',
621
+ desc: '系统提示常驻段:何时查、查到怎么用、查不到怎么办。',
596
622
  fields: [{ k: 'enabled', label: '启用', type: 'bool' }],
597
623
  },
598
624
  {
599
625
  key: 'rules', title: '硬性规则',
600
- desc: '把 kind = rule 的记忆放进系统提示常驻段。可机械校验的规则更适合做成钩子,而不是写在这里。',
626
+ desc: '把 kind=rule 的记忆放进系统提示常驻段。',
627
+ hint: '关闭只影响系统提示常驻段,记忆本身仍可被检索',
601
628
  fields: [
602
629
  { k: 'enabled', label: '启用', type: 'bool' },
603
630
  { k: 'maxItems', label: '最多条数', type: 'num', min: 1, max: 40, step: 1 },
@@ -606,7 +633,12 @@ window.__ModuleLoader__.load({
606
633
  },
607
634
  {
608
635
  key: 'turnEnd', title: '轮末提醒',
609
- desc: '本轮跑过多步时,下一轮开头提醒一句「若产生了可复用的结论,先 memory_save」。默认关闭。',
636
+ desc: '下一轮开头提醒把本轮结论落盘,默认关闭。',
637
+ fields: [{ k: 'enabled', label: '启用', type: 'bool' }],
638
+ },
639
+ {
640
+ key: 'sidebar', title: '侧栏入口',
641
+ desc: '在左侧栏「插件」下方显示记忆入口,点击打开面板。',
610
642
  fields: [{ k: 'enabled', label: '启用', type: 'bool' }],
611
643
  },
612
644
  ]
@@ -675,6 +707,9 @@ window.__ModuleLoader__.load({
675
707
  const next = await api('settings', settings)
676
708
  setSettings(next)
677
709
  setNotice('已保存,下一步生效')
710
+ if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function') {
711
+ try { window.dispatchEvent(new CustomEvent('dsh-memory:settings')) } catch { /* 没有 CustomEvent 就等下次启动 */ }
712
+ }
678
713
  } catch (e) {
679
714
  setError(String(e.message || e))
680
715
  }
@@ -690,13 +725,13 @@ window.__ModuleLoader__.load({
690
725
  return h('div', { className: 'setrow', key: group.key },
691
726
  h('span', { className: 'set-title' }, group.title),
692
727
  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)
728
+ ? h(Switch, {
729
+ key: field.k,
730
+ checked: Boolean(value[field.k]),
731
+ disabled: busy,
732
+ title: group.hint || field.label,
733
+ onChange: (next) => patch(group.key, field.k, next),
734
+ })
700
735
  : h('label', { className: 'set-field', key: field.k }, field.label, ' ',
701
736
  h('input', {
702
737
  type: 'number', min: field.min, max: field.max, step: field.step, value: value[field.k],
@@ -711,7 +746,7 @@ window.__ModuleLoader__.load({
711
746
  }),
712
747
  h('div', { className: 'setrow data' },
713
748
  h('span', { className: 'set-title' }, '数据'),
714
- h('span', { className: 'set-desc' }, '导出只含文本(作用域 / 类型 / 内容 / 标签 / 重要度),不含向量;导入时按当前模型重新嵌入。导入按「作用域 + 内容」去重。'),
749
+ h('span', { className: 'set-desc' }, '导出文本(不含向量),导入按当前模型重新嵌入并按内容去重。'),
715
750
  h('div', { className: 'row' },
716
751
  h('button', { onClick: exportAll }, '导出全部'),
717
752
  h('label', { className: 'set-field' }, '导入文件',
@@ -1113,6 +1148,23 @@ window.__ModuleLoader__.load({
1113
1148
 
1114
1149
  const inject = ['slots']
1115
1150
 
1151
+ /** 侧栏入口打开的主界面页面(整块可滚动,内容就是面板本体)。 */
1152
+ function MemoryPage() {
1153
+ return h('div', { className: 'mem-page' },
1154
+ h('div', { className: 'mem-page-head' }, h('h2', null, '记忆')),
1155
+ h(MemoryPanel, {}),
1156
+ )
1157
+ }
1158
+
1159
+ /** 侧栏图标:16px 单色线稿芯片,与设置导航那一列同一规范。 */
1160
+ function NavChipIcon() {
1161
+ return h('svg', { width: 16, height: 16, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': 'true' },
1162
+ h('rect', { x: 5, y: 5, width: 6, height: 6, rx: 1.4, stroke: 'currentColor', strokeWidth: 1.3 }),
1163
+ h('rect', { x: 6.9, y: 6.9, width: 2.2, height: 2.2, rx: 0.6, stroke: 'currentColor', strokeWidth: 1.3 }),
1164
+ h('path', { d: 'M8 5V3.2M8 11v1.8M5 8H3.2M11 8h1.8', stroke: 'currentColor', strokeWidth: 1.3, strokeLinecap: 'round' }),
1165
+ )
1166
+ }
1167
+
1116
1168
  function apply(ctx) {
1117
1169
  try {
1118
1170
  const styleEl = document.createElement('style')
@@ -1128,6 +1180,40 @@ window.__ModuleLoader__.load({
1128
1180
  { name: 'settings.section', id: 'memory', order: 24, label: NAV_LABEL },
1129
1181
  () => React.createElement(MemoryPanel),
1130
1182
  ))
1183
+
1184
+ // 侧栏入口(可选):开启后在左侧栏「插件」下方多一个「记忆」,点击在主界面打开面板。
1185
+ // 注册契约见 dsh-client-ui-schedule:sidebar.panellist 给 id/label/icon,main 用同一个 key。
1186
+ let sidebarDisposers = null
1187
+ const syncSidebar = () => {
1188
+ api('settings').then((settings) => {
1189
+ const want = Boolean(settings && settings.sidebar && settings.sidebar.enabled)
1190
+ if (want === (sidebarDisposers !== null)) return
1191
+ if (!want) {
1192
+ for (const dispose of sidebarDisposers ?? []) {
1193
+ try { if (typeof dispose === 'function') dispose() } catch { /* 已卸载 */ }
1194
+ }
1195
+ sidebarDisposers = null
1196
+ return
1197
+ }
1198
+ try {
1199
+ sidebarDisposers = [
1200
+ slots.inject('main', () => slots.register({ name: 'main', key: 'memory' }, () => React.createElement(MemoryPage))),
1201
+ slots.inject('sidebar.panellist', () => slots.register(
1202
+ { name: 'sidebar.panellist', id: 'memory', order: 20, label: () => NAV_LABEL },
1203
+ () => React.createElement(NavChipIcon),
1204
+ )),
1205
+ ]
1206
+ } catch (error) {
1207
+ sidebarDisposers = null
1208
+ console.warn('[dsh-memory] 侧栏入口注册失败:', error?.message)
1209
+ }
1210
+ }).catch(() => { /* 读不到设置就维持现状 */ })
1211
+ }
1212
+ syncSidebar()
1213
+ if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
1214
+ window.addEventListener('dsh-memory:settings', syncSidebar)
1215
+ ctx.effect(() => () => window.removeEventListener('dsh-memory:settings', syncSidebar), 'dsh-memory: sidebar entry')
1216
+ }
1131
1217
  } catch (error) {
1132
1218
  console.error('[dsh-memory] client apply 失败(已吞掉):', error?.message)
1133
1219
  }
@@ -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.1",
4
4
  "description": "DeepSeek Harness 本地长期记忆(单包单入口):JSONL 存储 + 本地向量检索(BGE-M3)+ 四个模型工具 + 自动召回注入 + 管理面板。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",