@restregular/dsh-memory 0.25.10 → 0.25.12

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/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  本项目的版本记录。安装 id 与 npm 版本一一对应。
4
4
 
5
+ ## 0.25.12 — `memory_save.supersedes` 明确要求传「完整 id」
6
+
7
+ - **问题**:`supersedes` 的参数说明只有一句英文 `Record id this corrects/replaces`,没说要传完整 id。而检索 / 列表 / 摘要 / 规则索引里显示的 id 全是 **8 位短 id**(`shortId`),`memory_get` 也接受 8 位前缀 —— 模型很容易把短 id 直接塞给 `supersedes`;provider 那边是按 id **精确查找**目标记录(`records.get(id)`),短 id 必然查不到,只会得到 `SUPERSEDES_UNKNOWN`,报错里也没有提示「你用了短 id」。
8
+ - **口径**:`supersedes` 的 schema 说明改成明确的中文说明 —— 必须传**完整 id(36 位 UUID)**,不能传 `memory_search` / `memory_list` / 摘要 / 规则索引里的 8 位短 id;手头只有短 id 时先用 `memory_get` 取回(它结果里每段首行的 `[id]` 就是完整 id)。同时把语义写清楚:旧记录标记为「已修正」,默认退出检索 / 规则 / 自动召回,`memory_get` 仍可查历史。
9
+ - README 第 2 节「存一条记忆」补同一段说明;`SaveArgs.supersedes` 的注释同步(行为不变,仍是精确 id 查找,不会静默接受短 id)。
10
+ - 测试:`source/tool-memory/test/tools.test.ts` 增加守卫用例 —— `supersedes` 的说明里必须出现「完整 id」「8 位短 id」「memory_get」,防止以后再被改回一句模糊英文。全套 505 tests(新增 1)/ 504 pass / 1 skipped(`memory-local/test/multiprocess.test.ts` 需真起子进程)。
11
+
12
+ ## 0.25.11 — 「记忆权限」浮窗里能直接看到真实键;摘要里的自定义作用域补 `custom:` 前缀
13
+
14
+ - **浮窗露出完整键**:显示名与真实键不一致时(项目别名 → 完整路径、会话短 id → 完整 uuid、自定义名 → 裸键),作用域行的名字下面多一行等宽小字,就是完整键。**不做手工截断**——键保持原样,放不下由 CSS 按容器宽度省略(`text-overflow:ellipsis`),窗口变宽就多显示几个字符。名义上相同(例如没有别名的项目作用域 `project:D:\w` 显示名就是键)则不再重复一行。
15
+ - **`title` 统一成「显示名 → 真实键」**:记录卡作用域徽标、记忆树节点、审批卡的作用域 pill、浮窗行名称的悬停提示都按这个格式(显示名与键相同时只给键)。项目作用域因此一眼能看出「别名是哪,路径是哪」。
16
+ - **摘要里的自定义作用域**:会话第一步注入的摘要 / 标签索引里,作用域是**紧凑分类词**(全局 / 项目 / 会话);自定义作用域以前直接吐裸名字(`· handbook`),和分类词混在一起分不清,现在是 `custom:handbook`。
17
+ - **不改真实键**:键仍是 `global` / `project:<路径>` / `session:<完整 uuid>` / 自定义裸名,存储、配置、授权、绑定与历史记忆都不迁移,无需重建向量。
18
+ - 测试:新增「只有显示名与键不同才渲染键行」「键行靠 CSS 省略、不手工截断」「`scopeTitle` 的显示名 → 键格式」用例与 `.mem-scope-key` 的 CSS 断言;摘要标签用例补 `custom:` 断言;全套 504 tests / 503 pass / 1 skipped。
19
+
5
20
  ## 0.25.10 — 作用域名字统一带类型前缀(`global:` / `project:` / `session:` / `custom:`)
6
21
 
7
22
  - **背景**:作用域名此前是「裸名字」——项目显示成 cwd、会话显示成短 id、global 显示成「全局」、自定义作用域显示成它自己的名字。列表里几种作用域混在一起时看不出种类;尤其 `global:` 与 `custom:` 完全没有前缀可依,因为这两种 scope 的**键本身就不带前缀**(`global` 是个关键字,自定义就是裸名字)。
package/README.md CHANGED
@@ -94,6 +94,7 @@ JSONL 落盘 · 本机向量检索 · 五个模型工具 · 自动召回 · 硬
94
94
  - **本会话那一行的名字**(0.25.8):本会话 `session:<id>` 那一行固定显示「**当前会话**」(0.25.10 起叫 `session:当前会话`,原始 scope 键仍在 `title` 里),别的会话的 scope 仍按标题 / 短 id 显示;搜索也按显示名匹配,输入「当前会话」即可筛到这一行。
95
95
  - **作用域名字带类型前缀**(0.25.10):所有展示名都以 `global:` / `project:` / `session:` / `custom:` 开头 —— `global:全局`、`project:D:\repositories\dsh-memory`、`session:session-1a2b3c4d`、`custom:handbook`。**global 与自定义作用域最容易被漏掉**:它们的 scope 键本身没有前缀(`global` 是个关键字、自定义就是裸名字),前缀必须按类型补。项目 / 自定义作用域有别名时是 `project:<别名>` / `custom:<别名>`,会话有标题时是 `session:<标题>(session-1a2b3c4d)`。
96
96
  - **会话作用域的短 id**(0.25.9):会话 id 取**前 16 位**(`session-` + 8 位 uuid)。以前取前 8 位,而真机会话 id 恰好以 `session-` 开头(正好 8 个字符),结果所有会话作用域都显示成同一个名字——等于没给 id。
97
+ - **浮窗里能直接看到真实键**(0.25.11):显示名与真实键不一致时(项目别名 → 完整路径、会话短 id → 完整 uuid、自定义名 → 裸键),每行名称下面多一行等宽的完整键;**不做手工截断**,放不下就按容器宽度用 CSS 省略号收尾,窗口宽就多显示几个字符。键行是等宽小字、和勾选框左对齐。记录卡 / 记忆树 / 审批卡的作用域徽标都在 `title` 里给出「显示名 → 真实键」。
97
98
  - **搜索与批量**:顶部可搜索作用域,支持「全选 / 取消全选」;列表最大高度受限,作用域多时在浮窗内滚动。**整张作用域卡片都能点**(0.25.7 起)——点名称、记录数或行内留白等同点勾选框,只有行内的按钮(勾选框 / 绑定 / 可读 / 可写)各管各的,点它们不会再多切换一次。
98
99
  - **浮窗层级**(0.25.8):浮窗 portal 到 `document.body` 渲染,`z-index:900`,不会再被会话里的「回到底部」圆钮(z-index:8)之类浮动件盖住;同时仍低于宿主自己的对话框 / 提示层(1000 起)。
99
100
  - **状态按钮(0.23.0 / 0.23.1)**:作用域列表每行有【绑定】、【可读】|【可写】。**默认范围自带的会话 + 项目 + global 显示为已绑定且不可取消**;**绑定**按钮用于把其它作用域额外并入当前工作区的默认范围(没有显式覆盖的新会话可见);**可读 / 可写**是会话级,独立控制该作用域的读取与写入(关掉可读 → 搜索 / 读取跳过并说明原因;关掉可写 → 保存 / 删除被拒绝并说明原因)。
@@ -192,6 +193,11 @@ memory_save({
192
193
  })
193
194
  ```
194
195
 
196
+ **`supersedes` 要传完整 id(0.25.12)**:它是「这条新记忆修正 / 替换掉哪条旧记录」,provider 按 id **精确查找**
197
+ 目标记录,所以必须给**完整 id**(36 位 UUID)——不能用 `memory_search` / `memory_list` / 摘要 / 规则索引里显示的
198
+ 8 位短 id(那些是短 id,传进去会被 `SUPERSEDES_UNKNOWN` 拒绝)。手头只有短 id 时先 `memory_get`,它结果里每段
199
+ 首行的 `[id]` 就是完整 id。旧记录会被标记为「已修正」,默认不再出现在检索、规则和自动召回里,但 `memory_get` 仍能查到。
200
+
195
201
  ### 3. 检索、取全文、列出、忘记
196
202
 
197
203
  ```jsonc
@@ -292,7 +298,7 @@ memory_scopes({
292
298
  | 层 | 触发 | 作用 |
293
299
  | --- | --- | --- |
294
300
  | `recall` | 每轮 `agent/pre-step` | 按本轮用户问题检索,按 topK / token 预算注入;默认只给每条 120 字摘要 + `memory_get` 指引 |
295
- | `digest` | 会话第一步 | 注入项目 + global 概览:按重要度 × 新鲜度挑选;`kind=rule` 不进摘要(已常驻系统提示);正文超预算时附可检索的标签索引 |
301
+ | `digest` | 会话第一步 | 注入项目 + global 概览:按重要度 × 新鲜度挑选;`kind=rule` 不进摘要(已常驻系统提示);正文超预算时附可检索的标签索引。每行末尾的作用域是**紧凑分类词**(全局 / 项目 / 会话),自定义作用域给 `custom:<名字>`(0.25.11 起,否则裸名字和分类词混在一起分不清) |
296
302
  | `policy` | 系统提示常驻 | 什么时候查记忆、查到怎么复用、查不到时低风险推断 / 高风险先问用户 |
297
303
  | `rules` | 系统提示常驻 | `kind: rule` 的硬性规则摘要;每行 `id · 正文`,需要全文时 `memory_get`;限量与预算;`mandatory` / `pinned` 排在最前 |
298
304
  | `procedures` | 系统提示常驻 | `kind: procedure` 的目录:当前工作区 + 触发词命中的流程,每行 `id · 触发词 → 标题`;正文按需 `memory_get` |
package/lib/client.js CHANGED
@@ -558,6 +558,11 @@ window.__ModuleLoader__.load({
558
558
  '.mem-scope-label{flex:1;min-width:0;padding:0;border:none;background:transparent;color:var(--dsw-alias-label-primary);font-size:12.5px;text-align:left;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;cursor:pointer}',
559
559
  '.mem-scope-label:hover{color:var(--dsw-alias-brand-primary);border:none}',
560
560
  '.mem-scope-row .cnt{flex:none;color:var(--dsw-alias-label-secondary);font-size:10.5px}',
561
+ // 0.25.11:显示名与真实键不一致时露出完整键(项目别名→路径、会话短 id→uuid、
562
+ // 自定义名→裸键)。**不手工截断**:容器多宽就显示多少,放不下按 CSS 省略 ——
563
+ // 与勾选框左对齐,字号比名字小一档,便于扫读又不会抢戏。
564
+ '.mem-scope-key{min-width:0;padding:0 0 0 26px;font-family:var(--ds-font-family-code, ui-monospace, monospace);font-size:10px;line-height:1.45;color:color-mix(in srgb,var(--dsw-alias-label-secondary) 88%,transparent);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}',
565
+ '.mem-scope-item:hover .mem-scope-key{color:var(--dsw-alias-label-secondary)}',
561
566
  // 0.23.0:每个作用域的状态按钮行 —— 绑定 | 可读 | 可写。
562
567
  '.mem-scope-state-row{display:flex;align-items:center;gap:4px;padding-left:26px}',
563
568
  '.mem-scope-state{padding:1px 7px;border:1px solid var(--dsw-alias-border-l1);border-radius:6px;background:transparent;color:var(--dsw-alias-label-secondary);font-size:10.5px;line-height:1.65;cursor:pointer;transition:border-color .12s ease,background .12s ease,color .12s ease}',
@@ -728,6 +733,19 @@ window.__ModuleLoader__.load({
728
733
  return scopeDisplayName(scope)
729
734
  }
730
735
 
736
+ /**
737
+ * 悬停提示里的作用域身份:`显示名 → 真实键`。
738
+ *
739
+ * 0.25.11:项目作用域有别名时显示名是 `project:dsh-pocket`,真实键却是完整路径;
740
+ * 会话与自定义作用域同理(短 id / 裸键)。只给键看不出它是哪个项目,只给名字又拿不到
741
+ * 能直接粘进工具参数的值,所以两段都给。显示名与键相同时不重复。
742
+ */
743
+ function scopeTitle(scope, label) {
744
+ const key = String(scope === null || scope === undefined ? '' : scope)
745
+ const name = typeof label === 'string' && label !== '' ? label : scopeDisplayName(scope)
746
+ return key === '' || key === name ? key : `${name} → ${key}`
747
+ }
748
+
731
749
  /** 记忆类型 → 中文名 + 树里的强调色(与宿主主题无关的固定色相,底色用 color-mix 自适应)。 */
732
750
  const KIND_ORDER = ['fact', 'decision', 'preference', 'procedure', 'note', 'rule', 'state']
733
751
  const KIND_META = {
@@ -1081,7 +1099,7 @@ window.__ModuleLoader__.load({
1081
1099
  },
1082
1100
  },
1083
1101
  h('span', { className: open ? 'chev open' : 'chev' }, '▶'),
1084
- h('span', { className: 'badge scope', title: rec.scope }, scopeLabel(rec.scope, labels)),
1102
+ h('span', { className: 'badge scope', title: scopeTitle(rec.scope, scopeLabel(rec.scope, labels)) }, scopeLabel(rec.scope, labels)),
1085
1103
  h('span', { className: 'badge' }, rec.kind),
1086
1104
  score !== null && score !== undefined && Number.isFinite(Number(score))
1087
1105
  ? h('span', {
@@ -1231,7 +1249,7 @@ window.__ModuleLoader__.load({
1231
1249
  role: 'button',
1232
1250
  tabIndex: 0,
1233
1251
  'aria-expanded': !node.collapsed,
1234
- title: `${node.scope} · 点击${node.collapsed ? '展开' : '折叠'}`,
1252
+ title: `${scopeTitle(node.scope, node.label)} · 点击${node.collapsed ? '展开' : '折叠'}`,
1235
1253
  onClick: () => onToggle(node.scope),
1236
1254
  onKeyDown: (event) => {
1237
1255
  if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); onToggle(node.scope) }
@@ -5131,6 +5149,7 @@ window.__ModuleLoader__.load({
5131
5149
  && target.closest('button,input,textarea,select,a,label')) return
5132
5150
  toggleScope(row.scope)
5133
5151
  }
5152
+ const shownName = displayName(row.scope, item ? item.label : row.grant.label)
5134
5153
  return h('div', {
5135
5154
  className: `mem-scope-item${checked ? ' on' : ''}${aiOnly ? ' ai' : ''}`,
5136
5155
  key: row.scope,
@@ -5153,12 +5172,18 @@ window.__ModuleLoader__.load({
5153
5172
  h('button', {
5154
5173
  type: 'button',
5155
5174
  className: 'mem-scope-label',
5156
- title: item ? row.scope : `${row.scope}(目录中已不可见)`,
5175
+ title: item ? scopeTitle(row.scope, shownName) : `${row.scope}(目录中已不可见)`,
5157
5176
  onClick: () => toggleScope(row.scope),
5158
- }, displayName(row.scope, item ? item.label : row.grant.label)),
5177
+ }, shownName),
5159
5178
  grant ? grantTag(grant, row.scope) : null,
5160
5179
  h('span', { className: 'cnt' }, item ? `${item.records ?? 0}` : '目录中已不可见'),
5161
5180
  ),
5181
+ // 0.25.11:显示名与真实键不一致时,把**完整键**单独一行放出来
5182
+ // (项目别名 → 完整路径、会话短 id → 完整 uuid、自定义名 → 裸键)。
5183
+ // 不做手工截断:CSS 按可用宽度省略,容器宽就多显示几个字符,窗口变窄自动收。
5184
+ shownName === String(row.scope)
5185
+ ? null
5186
+ : h('div', { className: 'mem-scope-key', title: String(row.scope) }, String(row.scope)),
5162
5187
  item
5163
5188
  ? h('div', { className: 'mem-scope-state-row' },
5164
5189
  h('button', {
@@ -5500,8 +5525,8 @@ window.__ModuleLoader__.load({
5500
5525
  : h('span', { className: 'mem-approval-id', title: item.id }, grantMode
5501
5526
  ? (item.grantPermission === 'write' ? '可写' : '只读')
5502
5527
  : (String(item.id).length > 12 ? `${item.id.slice(0, 8)}…${item.id.slice(-4)}` : String(item.id))),
5503
- // 作用域显示名带类型前缀;精确的 scope 键留在 title 里。
5504
- h('span', { className: 'audit-pill mute', title: item.scope }, scopeLabel(item.scope)),
5528
+ // 作用域显示名带类型前缀;title 里给出「显示名 → 真实键」。
5529
+ h('span', { className: 'audit-pill mute', title: scopeTitle(item.scope, scopeLabel(item.scope)) }, scopeLabel(item.scope)),
5505
5530
  grantMode
5506
5531
  ? h('span', { className: 'audit-pill mute' }, item.grantPermission === 'write' ? '写入 / 删除' : '只读访问')
5507
5532
  : h('span', { className: 'audit-pill mute' }, item.kind ? kindMeta(item.kind).label : '未知'),
@@ -5818,6 +5843,7 @@ window.__ModuleLoader__.load({
5818
5843
  sessionShortId: sessionShortId,
5819
5844
  scopeDisplayName: scopeDisplayName,
5820
5845
  scopeTypePrefix: scopeTypePrefix,
5846
+ scopeTitle: scopeTitle,
5821
5847
  scopeLabel: scopeLabel,
5822
5848
  KIND_META: KIND_META,
5823
5849
  CSS: CSS,
@@ -72,12 +72,18 @@ const HINT_FOOTER = '这些条目的正文尚未加载;遇到相关任务时
72
72
 
73
73
 
74
74
 
75
- /** scope 的中文标签:global/项目/会话/自定义。 */
75
+ /**
76
+ * scope 的紧凑分类标签:global/项目/会话/自定义。
77
+ *
78
+ * 前三种是**分类词**(摘要按预算只给类型,不给完整名字);自定义作用域没有分类可归,
79
+ * 所以给 `custom:<名字>` —— 0.25.11 起补上前缀,否则摘要里它是个裸名字,和全局/项目/
80
+ * 会话这些分类词混在一起看不出是什么。
81
+ */
76
82
  export function digestScopeLabel(scope ) {
77
83
  if (scope === 'global') return '全局'
78
84
  if (scope === 'project' || scope.startsWith('project:')) return '项目'
79
85
  if (scope === 'session' || scope.startsWith('session:')) return '会话'
80
- return scope
86
+ return `custom:${scope}`
81
87
  }
82
88
 
83
89
  /**
@@ -459,6 +459,15 @@ function withheldReasonFor(
459
459
  return 'read-disabled'
460
460
  }
461
461
 
462
+ /**
463
+ * memory_save 的 supersedes 参数说明(模型可见)。
464
+ * 检索 / 列表 / 摘要 / 规则索引里给的 id 都是 8 位短 id,而 supersedes 在 provider
465
+ * 里是**按 id 精确查找**(records.get(id)),传短 id 只会得到 SUPERSEDES_UNKNOWN。
466
+ * 所以必须明确要求「完整 id」,并给出拿完整 id 的路径(memory_get 首行就是完整 id)。
467
+ */
468
+ const SUPERSEDES_PARAM_DESCRIPTION =
469
+ '被这条新记忆修正 / 替换掉的旧记录 id。必须传**完整 id**(36 位 UUID),不能传 memory_search / memory_list / 摘要 / 规则索引里显示的 8 位短 id;手头只有短 id 时先用 memory_get 取回 —— 它结果里每段首行的 [id] 就是完整 id。旧记录会被标记为「已修正」,默认不再出现在检索、规则和自动召回里,但 memory_get 仍能查到。'
470
+
462
471
  /** memory_* 的 description 参数说明(模型可见)。 */
463
472
  const DESCRIPTION_PARAM_DESCRIPTION =
464
473
  '本次调用要做什么(一句话,给用户看)。本会话「记忆范围」为普通限制时必填:审批范围外记忆时,弹窗会把它展示给用户。'
@@ -730,6 +739,7 @@ function resolveScope(
730
739
 
731
740
 
732
741
 
742
+                            
733
743
 
734
744
                           
735
745
 
@@ -780,7 +790,7 @@ export function memorySaveTool(opts )
780
790
  kind: { type: 'string', enum: ['fact', 'decision', 'preference', 'procedure', 'note', 'rule', 'state'] },
781
791
  tags: { type: 'array', items: { type: 'string' } },
782
792
  importance: { type: 'number', description: '0~1, higher = more important' },
783
- supersedes: { type: 'string', description: 'Record id this corrects/replaces' },
793
+ supersedes: { type: 'string', description: SUPERSEDES_PARAM_DESCRIPTION },
784
794
  expiresAt: { type: 'number', description: '过期时间(毫秒时间戳)。kind=state 不传时按设置里的默认 TTL(7 天)' },
785
795
  ttlMs: { type: 'number', description: '相对有效期(毫秒)。与 expiresAt 二选一,expiresAt 优先' },
786
796
  triggers: { type: 'array', items: { type: 'string' }, description: '流程触发词(kind=procedure):工具名/关键词/路径;缺省用 tags' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restregular/dsh-memory",
3
- "version": "0.25.10",
3
+ "version": "0.25.12",
4
4
  "description": "DeepSeek Harness 记忆系统(单包单入口):JSONL 存储 + 本地向量检索(BGE-M3)+ 五个模型工具 + 自动召回注入 + 管理面板。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",