@restregular/dsh-memory 0.23.0 → 0.23.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/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  本项目的版本记录。安装 id 与 npm 版本一一对应。
4
4
 
5
+ ## 0.23.1 — 默认作用域显示为已绑定;绑定保存后可恢复
6
+
7
+ - **修复「绑定后重开又变成未绑定」的观感与保存范围**:
8
+ - 默认可见范围自带的 **会话 + 项目 + global** 现在由 provider 的 `defaultScopes()` 明确返回,面板把它们显示为「绑定已开」且不可取消(`defaultBound`),只有额外作用域才需要点「绑定」。这解决了「默认的那几个作用域本来就是默认可见,却显示成未绑定」的困惑。
9
+ - 客户端保存时**只提交额外绑定**(`bound && !defaultBound && !session:`),不会把默认作用域或会话作用域写进 `bindings`;服务端仍拒绝会话作用域绑定。
10
+ - `GET /memory/api/visibility` 新增 `defaultScopes` 与每个目录项的 `defaultBound`;`bindings` 仍是显式绑定的额外作用域。旧服务端没有 `defaultScopes` 时客户端按会话 / 项目 / global 兜底。
11
+ - **注意(本次「保存后又变未绑定」的根因)**:0.23.0 安装后,客户端 bundle 已更新(所以能看到绑定按钮),但宿主进程仍是 14:05 启动时加载的旧服务端代码,旧 `POST /visibility` 会忽略 `bindings`,只保存会话可见范围。**升级到 0.23.1 后需要重启一次 DSH**(或让插件管理器真正重载服务端),绑定才会落盘到 `<storeDir>/bindings/<hash>.json`;之后重开面板会从 `GET /visibility` 恢复。
12
+ - 测试:默认 / 额外绑定的服务端载荷、客户端按钮默认锁定、只提交额外绑定、`defaultScopes` 不包含额外绑定。全套通过。
13
+
5
14
  ## 0.23.0 — 修正版编辑与记录页筛选;作用域绑定 / 可读 / 可写状态
6
15
 
7
16
  - **编辑记忆 = 新建修正版(不再原地修改)**:
package/README.md CHANGED
@@ -90,7 +90,7 @@ JSONL 落盘 · 本机向量检索 · 五个模型工具 · 自动召回 · 硬
90
90
 
91
91
  - **默认范围**:没有显式设置时(新会话)按默认设置生效 —— **当前会话 + 当前项目 + global + 已绑定的作用域** + **普通限制**;面板按同一份默认范围预选,不会出现空面板。
92
92
  - **搜索与批量**:顶部可搜索作用域,支持「全选 / 取消全选」;列表最大高度受限,作用域多时在浮窗内滚动。
93
- - **状态按钮(0.23.0)**:作用域列表每行有【绑定】、【可读】|【可写】。**绑定**是工作区级:绑定后,同一工作区里没有显式覆盖的新会话默认范围会包含它;**可读 / 可写**是会话级,独立控制该作用域的读取与写入(关掉可读 → 搜索 / 读取跳过并说明原因;关掉可写 → 保存 / 删除被拒绝并说明原因)。
93
+ - **状态按钮(0.23.0 / 0.23.1)**:作用域列表每行有【绑定】、【可读】|【可写】。**默认范围自带的会话 + 项目 + global 显示为已绑定且不可取消**;**绑定**按钮用于把其它作用域额外并入当前工作区的默认范围(没有显式覆盖的新会话可见);**可读 / 可写**是会话级,独立控制该作用域的读取与写入(关掉可读 → 搜索 / 读取跳过并说明原因;关掉可写 → 保存 / 删除被拒绝并说明原因)。
94
94
  - **限制等级**:
95
95
  - **绝对限制**:可见域外的读取 / 写入 / 删除一律不执行;命中被挡住时会明确告诉 Agent 是「绝对限制」以及怎么调整(不再假装记忆不存在)。
96
96
  - **普通限制**(默认):可见域内正常返回;命中范围外记忆时,工具会暂停并在**该会话**的输入框上方显示审批卡,展示 Agent 的查询关键词与范围外记忆摘要;读审批可以逐条勾选,只允许其中一条或多条。用户拒绝 / 5 分钟未回答时,工具结果里会明确写出真实原因(「用户拒绝了本次访问」/「审批超时」),模型不会误以为记忆不存在。范围外写入 / 删除同样走审批。
package/lib/client.js CHANGED
@@ -536,6 +536,7 @@ window.__ModuleLoader__.load({
536
536
  '.mem-scope-state:hover:not(:disabled){border-color:color-mix(in srgb,var(--dsw-alias-brand-primary) 45%,var(--dsw-alias-border-l1));color:var(--dsw-alias-label-primary)}',
537
537
  '.mem-scope-state.on{border-color:color-mix(in srgb,var(--dsw-alias-state-business-primary) 58%,var(--dsw-alias-border-l1));background:color-mix(in srgb,var(--dsw-alias-state-business-primary) 14%,transparent);color:var(--dsw-alias-state-business-primary)}',
538
538
  '.mem-scope-state.bind.on{border-style:dashed}',
539
+ '.mem-scope-state.bind.locked{opacity:.82;cursor:default}',
539
540
  '.mem-scope-state:disabled{opacity:.42;cursor:default}',
540
541
  '.mem-scope-state:focus-visible{outline:1px solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}',
541
542
  '.mem-scope-sep{width:1px;height:12px;margin:0 1px;background:var(--dsw-alias-border-l1);flex:none}',
@@ -4565,6 +4566,7 @@ window.__ModuleLoader__.load({
4565
4566
  const [entries, setEntries] = React.useState({})
4566
4567
  const [perms, setPerms] = React.useState({})
4567
4568
  const [bound, setBound] = React.useState({})
4569
+ const [defaultBound, setDefaultBound] = React.useState({})
4568
4570
  const [catalog, setCatalog] = React.useState([])
4569
4571
  const [search, setSearch] = React.useState('')
4570
4572
  const [anchor, setAnchor] = React.useState(null)
@@ -4641,20 +4643,32 @@ window.__ModuleLoader__.load({
4641
4643
  (Array.isArray(value.bindings) ? value.bindings : [])
4642
4644
  .filter((scope) => typeof scope === 'string' && scope !== ''),
4643
4645
  )
4646
+ // 默认基础范围(会话 + 项目 + global)天然包含在默认范围里:展示为已绑定、
4647
+ // 不可取消;只有额外绑定才进 bound 状态、才会随保存提交。
4648
+ const defaultSet = new Set(
4649
+ (Array.isArray(value.defaultScopes)
4650
+ ? value.defaultScopes
4651
+ : (Array.isArray(value.defaults) ? value.defaults : []).filter((scope) => typeof scope === 'string'
4652
+ && (scope === 'global' || scope.startsWith('session:') || scope.startsWith('project:'))))
4653
+ .filter((scope) => typeof scope === 'string' && scope !== ''),
4654
+ )
4644
4655
  const nextPerms = {}
4645
4656
  const nextBound = {}
4657
+ const nextDefaultBound = {}
4646
4658
  for (const item of nextCatalog) {
4647
4659
  const rule = ruleByScope.get(item.scope)
4648
4660
  nextPerms[item.scope] = {
4649
4661
  read: rule ? rule.read !== false : item.read !== false,
4650
4662
  write: rule ? rule.write !== false : item.write !== false,
4651
4663
  }
4652
- nextBound[item.scope] = boundSet.has(item.scope) || item.bound === true
4664
+ nextBound[item.scope] = boundSet.has(item.scope)
4665
+ nextDefaultBound[item.scope] = defaultSet.has(item.scope) || item.defaultBound === true
4653
4666
  }
4654
4667
  setCatalog(nextCatalog)
4655
4668
  setEntries(nextEntries)
4656
4669
  setPerms(nextPerms)
4657
4670
  setBound(nextBound)
4671
+ setDefaultBound(nextDefaultBound)
4658
4672
  }
4659
4673
 
4660
4674
  const load = () => {
@@ -4723,9 +4737,9 @@ window.__ModuleLoader__.load({
4723
4737
  const save = (config) => {
4724
4738
  setBusy(true)
4725
4739
  setError('')
4726
- // 绑定是工作区级、与本次会话的显式覆盖一起提交;会话作用域不能绑定。
4740
+ // 只提交**额外**绑定:默认范围自带的会话 / 项目 / global 不需要也不允许写入。
4727
4741
  const bindings = catalog
4728
- .filter((item) => bound[item.scope] && !String(item.scope).startsWith('session:'))
4742
+ .filter((item) => bound[item.scope] && !defaultBound[item.scope] && !String(item.scope).startsWith('session:'))
4729
4743
  .map((item) => item.scope)
4730
4744
  api('visibility', { session: sessionId, visibility: config, bindings })
4731
4745
  .then((value) => {
@@ -4864,17 +4878,18 @@ window.__ModuleLoader__.load({
4864
4878
  ),
4865
4879
  // 0.23.0:状态按钮 —— 绑定(工作区级) / 可读 | 可写(会话级)。
4866
4880
  h('div', { className: 'mem-scope-state-row' },
4867
- item.bindable === false || String(item.scope).startsWith('session:')
4868
- ? null
4869
- : h('button', {
4870
- type: 'button',
4871
- className: `mem-scope-state bind${bound[item.scope] ? ' on' : ''}`,
4872
- 'aria-pressed': Boolean(bound[item.scope]),
4873
- title: bound[item.scope]
4874
- ? '已绑定到当前工作区:本工作区新会话的默认可见范围会包含它'
4875
- : '绑定到当前工作区:本工作区新会话的默认可见范围会包含它',
4876
- onClick: () => toggleBound(item.scope),
4877
- }, '绑定'),
4881
+ h('button', {
4882
+ type: 'button',
4883
+ className: `mem-scope-state bind${defaultBound[item.scope] || bound[item.scope] ? ' on' : ''}${defaultBound[item.scope] ? ' locked' : ''}`,
4884
+ 'aria-pressed': Boolean(defaultBound[item.scope] || bound[item.scope]),
4885
+ disabled: Boolean(defaultBound[item.scope]),
4886
+ title: defaultBound[item.scope]
4887
+ ? '默认可见范围已包含(会话 + 项目 + global 默认绑定),无需再绑定'
4888
+ : (bound[item.scope]
4889
+ ? '已绑定到当前工作区:本工作区新会话的默认可见范围会包含它'
4890
+ : '绑定到当前工作区:本工作区新会话的默认可见范围会包含它'),
4891
+ onClick: () => { if (!defaultBound[item.scope]) toggleBound(item.scope) },
4892
+ }, '绑定'),
4878
4893
  h('span', { className: 'mem-scope-sep', 'aria-hidden': 'true' }),
4879
4894
  h('button', {
4880
4895
  type: 'button',
package/lib/panel.js CHANGED
@@ -543,6 +543,17 @@ function visibilityPayload(ctx, memory, sessionId) {
543
543
  }
544
544
  const sessionScope = refs?.session ?? defaults.find((scope) => scope.startsWith('session:'))
545
545
  const projectScope = refs?.project ?? defaults.find((scope) => scope.startsWith('project:'))
546
+ // 默认范围的**基础集合** = 会话 + 项目 + global。它们天然包含在默认范围里,
547
+ // 面板按「已绑定」展示且不可取消;工作区绑定只负责额外并入其它作用域。
548
+ let defaultScopes = []
549
+ try {
550
+ const list = typeof memory.defaultScopes === 'function' ? memory.defaultScopes(agentLike) : undefined
551
+ if (Array.isArray(list)) defaultScopes = list.filter((scope) => typeof scope === 'string' && scope !== '')
552
+ } catch { /* 旧 provider:退回下面的本地面包 */ }
553
+ if (defaultScopes.length === 0) {
554
+ defaultScopes = [sessionScope, projectScope, 'global'].filter((scope) => typeof scope === 'string' && scope !== '')
555
+ }
556
+ const defaultBound = new Set(defaultScopes)
546
557
  ensure(sessionScope)
547
558
  ensure(projectScope)
548
559
  ensure('global')
@@ -558,8 +569,10 @@ function visibilityPayload(ctx, memory, sessionId) {
558
569
  label: item.name ?? scopeLabel(ctx, item.scope),
559
570
  read: rule === undefined ? true : rule.read !== false,
560
571
  write: rule === undefined ? true : rule.write !== false,
561
- bound: bound.has(item.scope),
562
- bindable: !String(item.scope).startsWith('session:'),
572
+ // bound = 显式绑定或默认范围自带;defaultBound 告诉客户端这一项不能取消。
573
+ bound: bound.has(item.scope) || defaultBound.has(item.scope),
574
+ defaultBound: defaultBound.has(item.scope),
575
+ bindable: !String(item.scope).startsWith('session:') && !defaultBound.has(item.scope),
563
576
  }
564
577
  })
565
578
  return {
@@ -569,6 +582,7 @@ function visibilityPayload(ctx, memory, sessionId) {
569
582
  inherited,
570
583
  source,
571
584
  defaults,
585
+ defaultScopes,
572
586
  workspace,
573
587
  bindings: [...bound],
574
588
  scopes,
@@ -278,6 +278,11 @@ export class CordisMemoryService extends Service {
278
278
  return this.impl.workspaceBindings(agent)
279
279
  }
280
280
 
281
+ /** 面板:默认范围的基础集合(会话 + 项目 + global),不含工作区绑定。 */
282
+ defaultScopes(agent ) {
283
+ return this.impl.defaultScopes(agent)
284
+ }
285
+
281
286
  /** 面板:设置当前工作区绑定的作用域。 */
282
287
  setWorkspaceBindings(agent , scopes ) {
283
288
  return this.impl.setWorkspaceBindings(agent, scopes)
@@ -1470,7 +1470,8 @@ export class LocalMemoryService {
1470
1470
  }
1471
1471
 
1472
1472
  /** 没有显式覆盖时的默认可见域范围(会话 + 项目 + global + 工作区绑定的作用域)。 */
1473
- defaultReadScopes(agent ) {
1473
+ /** 默认三路(会话 + 项目 + global),**不含**工作区绑定;各自开关生效。 */
1474
+ baseDefaultScopes(agent ) {
1474
1475
  const refs = this.scopeRefs(agent)
1475
1476
  const out = []
1476
1477
  const push = (scope , enabled ) => {
@@ -1480,12 +1481,32 @@ export class LocalMemoryService {
1480
1481
  push(refs.session, this.cfg.sessionEnabled)
1481
1482
  push(refs.project, this.cfg.projectEnabled)
1482
1483
  push('global', this.cfg.globalEnabled)
1484
+ return out
1485
+ }
1486
+
1487
+ /**
1488
+ * 面板:默认可见范围的**基础集合**(会话 + 项目 + global)。
1489
+ * 这些作用域天然包含在默认范围里,面板把它们显示为「已绑定」且不可取消;
1490
+ * 工作区绑定只用于**额外**并入的作用域。
1491
+ */
1492
+ defaultScopes(agent ) {
1493
+ return this.baseDefaultScopes(agent)
1494
+ }
1495
+
1496
+ /** 没有显式覆盖时的默认可见域范围(基础三路 + 工作区绑定的额外作用域)。 */
1497
+ defaultReadScopes(agent ) {
1498
+ const out = this.baseDefaultScopes(agent)
1499
+ const push = (scope ) => {
1500
+ if (out.includes(scope)) return
1501
+ out.push(scope)
1502
+ }
1483
1503
  // 0.23.0:工作区绑定的作用域默认可见。会话作用域不能绑定,这里再守一次。
1504
+ const refs = this.scopeRefs(agent)
1484
1505
  for (const raw of this.bindings.get(refs.project)) {
1485
1506
  const scope = this.canonicalScope(raw)
1486
1507
  if (scopeKind(scope) === 'session') continue
1487
1508
  if (!this.scopeEnabled(scope)) continue
1488
- push(scope, true)
1509
+ push(scope)
1489
1510
  }
1490
1511
  return out
1491
1512
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restregular/dsh-memory",
3
- "version": "0.23.0",
3
+ "version": "0.23.1",
4
4
  "description": "DeepSeek Harness 记忆系统(单包单入口):JSONL 存储 + 本地向量检索(BGE-M3)+ 五个模型工具 + 自动召回注入 + 管理面板。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",