@restregular/dsh-memory 0.25.12 → 0.25.14

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,20 @@
2
2
 
3
3
  本项目的版本记录。安装 id 与 npm 版本一一对应。
4
4
 
5
+ ## 0.25.14 — 侧边栏给等待记忆审批的会话显示黄点 /「待审批」
6
+
7
+ - **问题**:范围外记忆审批以前只是插件自己画在 `conversation.input.dock` 的卡片;宿主的侧边栏会话列表并不认识它,所以工具在等审批时,那一行没有系统审批 / ask 工具那样的黄点,也不会被「待审批」水线自动顶出来。宿主这两类阻塞都来自 `ctx.uiSession` 的 pending-interaction 注册表(`dsh-client-ui-approval` 发 `kind:'approval'`,`dsh-client-ui-user-questions` 发 `kind:'question'`)。
8
+ - **做法**:客户端新增 `installApprovalPresence`,通过 `ctx.inject(['uiSession'], …)`(等 `uiSession` 就绪,不在 apply 里一次性取样)注册一个 pending-interaction domain;轮询轻量审批摘要,为每条待审批发布一个**合成 interaction** `{ sessionId, kind:'approval', key:'memory-approval:<id>', toolName }`,回答 / 超时后撤销。它**不是** `PendingApproval` 实例,所以宿主的审批卡不会抢着渲染,我们自己的审批卡仍是唯一 UI;但侧边栏黄点、紧凑文案「待审批」、悬停「等待审批」、会话水线提升、以及其它插件对 `uiSession.sessionStatus` 的读取,都和系统审批完全同构。按审批 id 增删,同一会话多条审批互不顶掉;点「拒绝 / 允许」后立即同步一次,不必等下一次轮询。
9
+ - **轻量接口**:`GET /memory/api/approvals?summary=1` 新增摘要口径,只回 `id / sessionId / tool / action / mode / createdAt / expiresAt`,不复制条目正文与查询语句;provider 新增 `pendingVisibilityApprovalPresence()`。旧 provider 没有该方法时回退完整列表,客户端只读 id + sessionId,兼容不破。
10
+ - **测试**:客户端新增「待审批发布成 approval 类型、空 sessionId 跳过、同一会话多条、回答一条只撤一条、卸载清空」用例;面板新增 `/approvals?summary=1` 的「无正文 / 按会话过滤 / grant mode / 旧 provider 回退」用例。
11
+
12
+ ## 0.25.13 — 「绑定」点一下立即保存;绑定不再往上下文注入提示
13
+
14
+ - **绑定即存**:记忆权限浮窗里每个作用域的【绑定】按钮以前只是草稿,必须再点「保存」才落盘——用户点完绑定看不出任何反馈,很容易以为没生效。现在点一下就走新接口 `POST /memory/api/bindings` 立即保存(再点一次 = 解除绑定),按钮先乐观更新、失败回滚原状态并把错误显示在浮窗里;「绑定」按钮的 `title` 与浮窗提示行都写清「点一下就保存」。绑定是工作区级设置(本工作区新会话的默认可见范围),与浮窗里「勾选范围 / 可读 / 可写」那份会话级草稿无关,所以**不需要**先设草稿;点「保存」时仍会幂等带上一次绑定,旧客户端 / 老服务端按原逻辑照旧生效。
15
+ - **绑定不再注入上下文提示**:`setWorkspaceBindings` 以前会给当前会话排一条「记忆权限已更新」通知。但绑定只影响本工作区**新会话**的默认范围,当前会话自己读什么并没有变,这条通知只会让 Agent 误以为自己刚被重新授权 / 撤销。现在绑定变化**不注入任何提示**;可见范围 / 会话授权的变更照旧通知(`renderPermissionNotice` 不变)。
16
+ - **服务端**:`/bindings` 只写工作区绑定,**不动**会话可见范围(这和 `POST /visibility` 带 `bindings` 的语义不同——那条会同时重置 / 写入覆盖)。绑定校验抽成 `normalizeBindings`:只接受具体作用域键(拒绝 `all` / 当前项目 / 当前会话别名)、会话作用域不能绑到工作区、重复项去重,非法输入 400 `SCOPE_INVALID`,缺 `session` 400 `SESSION_REQUIRED`。
17
+ - 测试:客户端新增「点绑定即 POST /bindings(不点保存)、再点解除、失败回滚并报错」用例,改写原有「保存带绑定」用例(绑定 POST 与可见范围 POST 分开断言);面板新增 `/bindings` 路由用例(立即落盘、不改会话覆盖、不排提示、空数组清除、非法输入 400);`memory-local` 的工作区绑定用例补「绑定变化不往上下文注入提示」断言。全套 507 tests / 506 pass / 1 skipped(`memory-local/test/multiprocess.test.ts` 需真起子进程)。
18
+
5
19
  ## 0.25.12 — `memory_save.supersedes` 明确要求传「完整 id」
6
20
 
7
21
  - **问题**:`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」。
package/README.md CHANGED
@@ -47,9 +47,9 @@ JSONL 落盘 · 本机向量检索 · 五个模型工具 · 自动召回 · 硬
47
47
  | **自动召回** | 每轮按用户问题召回;新会话第一步注入项目 / global 摘要;发布、部署、工具失败等行为按标签触发定向召回 |
48
48
  | **印象形态** | 每轮只给每条记忆的短摘要;模型判断相关但需要细节时再 `memory_get` 取全文,省 token 也不丢信息 |
49
49
  | **硬性规则** | `kind: rule` 进系统提示常驻段;行首带 8 位 id,注入的是摘要,需要全文时用 `memory_get`;旧会话会收到新增 / 编辑提醒;超预算有明确警告,不静默丢弃 |
50
- | **记忆权限** | 输入框旁的「记忆权限」按钮设置本会话可读的作用域 + 限制等级(绝对 / 普通 / 无限制);每个作用域一行就是一条设置:**勾选**表示本会话可访问,行内**【绑定】/【可读】/【可写】**控制工作区默认可见与读写权限——绑定到当前工作区后新会话默认可见,可读 / 可写独立影响工具读写;Agent 通过 `memory_scopes request` 申请到的范围外授权**也用勾选呈现**(名称右边挂一个「AI」气泡,样式与你自己勾选的行区分开),取消勾选只是草稿,**点「保存」才真正撤销**(0.25.4 起),且按钮数字 / 「已选」都把 AI 授权算进去(0.25.5 起)并**实时轮询**——浮窗关着,Agent 刚拿到的授权也会让按钮数字自己变(0.25.6 起);**整张作用域卡片都能点选**,点名称 / 计数 / 留白等同点勾选框(0.25.7 起),本会话那一行直接叫「**session:当前会话**」(0.25.8 起,0.25.10 起带类型前缀);**所有作用域名都以 `global:` / `project:` / `session:` / `custom:` 开头**(0.25.10 起);浮窗挂在页面根层,不会被输入框上方的浮动按钮盖住(0.25.8 起);Agent 及其子 Agent 都按它检索、注入与 `memory_get` |
50
+ | **记忆权限** | 输入框旁的「记忆权限」按钮设置本会话可读的作用域 + 限制等级(绝对 / 普通 / 无限制);每个作用域一行就是一条设置:**勾选**表示本会话可访问,行内**【绑定】/【可读】/【可写】**控制工作区默认可见与读写权限——**【绑定】点一下立即保存**(0.25.13 起),绑定到当前工作区后新会话默认可见,可读 / 可写独立影响工具读写;Agent 通过 `memory_scopes request` 申请到的范围外授权**也用勾选呈现**(名称右边挂一个「AI」气泡,样式与你自己勾选的行区分开),取消勾选只是草稿,**点「保存」才真正撤销**(0.25.4 起),且按钮数字 / 「已选」都把 AI 授权算进去(0.25.5 起)并**实时轮询**——浮窗关着,Agent 刚拿到的授权也会让按钮数字自己变(0.25.6 起);**整张作用域卡片都能点选**,点名称 / 计数 / 留白等同点勾选框(0.25.7 起),本会话那一行直接叫「**session:当前会话**」(0.25.8 起,0.25.10 起带类型前缀);**所有作用域名都以 `global:` / `project:` / `session:` / `custom:` 开头**(0.25.10 起);浮窗挂在页面根层,不会被输入框上方的浮动按钮盖住(0.25.8 起);Agent 及其子 Agent 都按它检索、注入与 `memory_get` |
51
51
  | **修正版编辑** | 面板里编辑一条记忆 = 新建一条修正版并通过 `supersedes` 指向旧记录,旧记录不原地修改;记录页「是否被修正」筛选默认隐藏旧版本,可切到全部 / 只看已修正 |
52
- | **范围外审批** | 普通限制下,工具命中可见域外的记忆时会在**对应会话的输入框上方**出现审批卡(样式与系统权限审批一致):展示工具、Agent 说明、查询关键词与范围外记忆摘要,支持逐条勾选 / 全选 / 取消全选(「允许选中的 N 条」或整单「允许一次」)或「拒绝」;点记忆 ID 直接跳到面板「记录」页并展开该条 |
52
+ | **范围外审批** | 普通限制下,工具命中可见域外的记忆时会在**对应会话的输入框上方**出现审批卡(样式与系统权限审批一致):展示工具、Agent 说明、查询关键词与范围外记忆摘要,支持逐条勾选 / 全选 / 取消全选(「允许选中的 N 条」或整单「允许一次」)或「拒绝」;点记忆 ID 直接跳到面板「记录」页并展开该条。**0.25.14 起**审批等待期间还会像系统审批 / ask 工具一样,在该会话的侧边栏行显示黄色圆点与「待审批」(含后台会话;回答或超时后撤销),其它插件也能从宿主 `uiSession.sessionStatus` 读到这条阻塞 |
53
53
  | **上下文去重** | `memory_search` / `memory_list` 返回过的条目记进会话上下文状态;同一版本再次命中只回记忆 ID(`memory_search` 的裸 ID 与带摘要条目之间空一行),并提示用 `memory_get` 取全文(内容更新后重新给摘要) |
54
54
  | **状态记忆** | `kind: state` 默认 7 天 TTL;注入带「状态,使用前验证」;过期后默认不进检索 / 摘要 / 召回,但 `memory_get` 与面板仍可取 |
55
55
  | **流程索引** | `kind: procedure` 的目录进系统提示:按当前工作区 + 触发词(工具名 / 关键词)列 `id · 触发词 → 标题`,需要时再用 `memory_get` 取全文 |
@@ -97,7 +97,7 @@ JSONL 落盘 · 本机向量检索 · 五个模型工具 · 自动召回 · 硬
97
97
  - **浮窗里能直接看到真实键**(0.25.11):显示名与真实键不一致时(项目别名 → 完整路径、会话短 id → 完整 uuid、自定义名 → 裸键),每行名称下面多一行等宽的完整键;**不做手工截断**,放不下就按容器宽度用 CSS 省略号收尾,窗口宽就多显示几个字符。键行是等宽小字、和勾选框左对齐。记录卡 / 记忆树 / 审批卡的作用域徽标都在 `title` 里给出「显示名 → 真实键」。
98
98
  - **搜索与批量**:顶部可搜索作用域,支持「全选 / 取消全选」;列表最大高度受限,作用域多时在浮窗内滚动。**整张作用域卡片都能点**(0.25.7 起)——点名称、记录数或行内留白等同点勾选框,只有行内的按钮(勾选框 / 绑定 / 可读 / 可写)各管各的,点它们不会再多切换一次。
99
99
  - **浮窗层级**(0.25.8):浮窗 portal 到 `document.body` 渲染,`z-index:900`,不会再被会话里的「回到底部」圆钮(z-index:8)之类浮动件盖住;同时仍低于宿主自己的对话框 / 提示层(1000 起)。
100
- - **状态按钮(0.23.0 / 0.23.1)**:作用域列表每行有【绑定】、【可读】|【可写】。**默认范围自带的会话 + 项目 + global 显示为已绑定且不可取消**;**绑定**按钮用于把其它作用域额外并入当前工作区的默认范围(没有显式覆盖的新会话可见);**可读 / 可写**是会话级,独立控制该作用域的读取与写入(关掉可读 → 搜索 / 读取跳过并说明原因;关掉可写 → 保存 / 删除被拒绝并说明原因)。
100
+ - **状态按钮(0.23.0 / 0.23.1,绑定即存 0.25.13)**:作用域列表每行有【绑定】、【可读】|【可写】。**默认范围自带的会话 + 项目 + global 显示为已绑定且不可取消**;**绑定**按钮用于把其它作用域额外并入当前工作区的默认范围(没有显式覆盖的新会话可见)——**点一下立即保存**(`POST /memory/api/bindings`),不用再点「保存」,写入失败会回滚按钮状态并在浮窗里报错;**可读 / 可写**是会话级,独立控制该作用域的读取与写入(关掉可读 → 搜索 / 读取跳过并说明原因;关掉可写 → 保存 / 删除被拒绝并说明原因),这两项仍是草稿,点「保存」才生效。绑定是工作区级设置(只影响本工作区**新会话**的默认范围),当前会话读什么并没有变,所以**绑定变化不注入上下文提示**。
101
101
  - **限制等级**:
102
102
  - **绝对限制**:可见域外的读取 / 写入 / 删除一律不执行;命中被挡住时会明确告诉 Agent 是「绝对限制」以及怎么调整(不再假装记忆不存在)。
103
103
  - **普通限制**(默认):可见域内正常返回;命中范围外记忆时,工具会暂停并在**该会话**的输入框上方显示审批卡,展示 Agent 的查询关键词与范围外记忆摘要;读审批可以逐条勾选,只允许其中一条或多条。用户拒绝 / 5 分钟未回答时,工具结果里会明确写出真实原因(「用户拒绝了本次访问」/「审批超时」),模型不会误以为记忆不存在。范围外写入 / 删除同样走审批。
@@ -106,7 +106,7 @@ JSONL 落盘 · 本机向量检索 · 五个模型工具 · 自动召回 · 硬
106
106
  - **不再按记忆类型收窄**:0.19.1 起只按作用域限制;旧配置里的 `kinds` 会被忽略,同一作用域下的事实 / 规则 / 流程等都可读。
107
107
  - **审批卡(0.21.0 / 0.22.x)**:注册在会话内的 `conversation.input.dock`,**只在发起审批的那个会话里显示**,切到别的会话看不到;视觉与系统自带的权限审批弹窗一致(警告色 strip、卡片、右对齐动作行,同一批主题 token)。按动作分为「记忆读取 / 写入 / 删除审批」。读审批默认全部勾选:可逐条取消、用「全选 / 取消全选」批量操作,**点条目任意位置即可切换选中**,再点「允许选中的 N 条」,工具只放行勾选的 id、其余写入 `withheld.reason='partial'`;全选时等价于原来的「允许一次」。strip 右侧可**折叠 / 展开**详情,折叠后仍保留「拒绝 / 允许」动作。写 / 删审批是单条,隐藏勾选框。**0.22.0 起**卡片展示工具调用的 `description`(普通限制下工具层强制模型提供),点记忆 ID 会打开记忆面板的「记录」标签页、选中并滚动到该条、自动展开;**0.22.2 起**查询与说明固定显示在条目列表上方,条目再多也不会被列表挤没(两行锁 `flex:none`,只有列表滚动);**0.22.3 起**审批卡高度只受 composer 文本区上限约束(与宿主审批卡同口径),矮窗口下列表也有空间。拒绝、超时或无法发起审批都会把原因告诉模型。Enter = 允许、Esc = 拒绝(焦点在卡片内时)。
108
108
  - 子 Agent 自动继承父会话 / 根会话的设置;在子 Agent 自己的会话里再设置,只影响那一个会话。
109
- - 保存后,下一次 Agent 步骤会通过注入的上下文消息收到「记忆权限已更新」通知(可见范围 + 限制等级 + 本次授权变更 + 当前会话授权);授权变化走同一条注入,不需要重启会话。
109
+ - 保存后,下一次 Agent 步骤会通过注入的上下文消息收到「记忆权限已更新」通知(可见范围 + 限制等级 + 本次授权变更 + 当前会话授权);授权变化走同一条注入,不需要重启会话。**唯一例外是「绑定」**:它只改工作区级默认范围,不注入任何提示(0.25.13 起)。
110
110
  - 「恢复默认」清除覆盖,回到默认设置(会话 + 项目 + global + 已绑定的作用域 + 普通限制)。
111
111
  - 覆盖按会话落盘在 `<storeDir>/visibility/<session>.json`,浏览器刷新 / 插件重载后仍在;0.18 的旧文件按「绝对限制」兼容读取。
112
112
  - 浮窗与审批卡的半透明背景、边框、文字颜色全部走宿主主题 token;勾选框选中态、保存按钮、限制等级选中态使用 `--dsw-alias-state-business-primary` + `--dsw-alias-label-primary-foreground`,深色模式下不会出现白底白勾 / 白底白字;按钮三档边框用 `state-warn-primary`(橙黄)/ `state-business-primary`(蓝)/ 虚线灰;阴影已收敛为小范围投影,滚动列表高度收紧到 `min(220px, 32vh)`。
package/lib/client.js CHANGED
@@ -4649,10 +4649,20 @@ window.__ModuleLoader__.load({
4649
4649
  * POST { session, visibility: { scopes: [{ scope, read?, write? }], level } | null,
4650
4650
  * bindings: string[] } → 同上
4651
4651
  *
4652
+ * 0.25.13 起还有只写绑定的 /bindings:
4653
+ * POST { session, bindings: string[] } → { sessionId, bindings }
4654
+ * 绑定是工作区级设置(本工作区新会话的默认可见范围),点一下就落盘,
4655
+ * 不等「保存」;也不需要给会话注入上下文提示。
4656
+ *
4652
4657
  * 0.23.0:
4653
4658
  * - 每个作用域有「绑定 / 可读 / 可写」状态按钮;绑定是工作区级(新会话默认可见),
4654
4659
  * 可读 / 可写是会话级,直接影响工具读到 / 写到该作用域时的结果与失败原因;
4655
4660
  * - 保存时 read/write 只在关掉时提交 false,绑定整体提交。
4661
+ *
4662
+ * 0.25.13:
4663
+ * - 「绑定」按钮点一下立即保存(工作区级,POST /bindings),不再等「保存」;
4664
+ * 勾选范围 / 可读 / 可写仍是草稿,点「保存」才生效。
4665
+ * - 绑定变化不注入「记忆权限已更新」上下文提示(当前会话读什么没变)。
4656
4666
  */
4657
4667
  function MemoryVisibilityButton({ sessionId } = {}) {
4658
4668
  const [open, setOpen] = React.useState(false)
@@ -4666,6 +4676,8 @@ window.__ModuleLoader__.load({
4666
4676
  const [pendingRevoke, setPendingRevoke] = React.useState({})
4667
4677
  const [perms, setPerms] = React.useState({})
4668
4678
  const [bound, setBound] = React.useState({})
4679
+ // 0.25.13:绑定按钮是**即时保存**的,这里记正在提交的作用域键(空 = 空闲)。
4680
+ const [bindBusy, setBindBusy] = React.useState('')
4669
4681
  const [defaultBound, setDefaultBound] = React.useState({})
4670
4682
  const [catalog, setCatalog] = React.useState([])
4671
4683
  const [search, setSearch] = React.useState('')
@@ -4916,7 +4928,37 @@ window.__ModuleLoader__.load({
4916
4928
 
4917
4929
  /** 切换某个作用域是否绑定到当前工作区(工作区级,新会话默认可见)。 */
4918
4930
  const toggleBound = (scope) => {
4919
- setBound((prev) => ({ ...prev, [scope]: !prev[scope] }))
4931
+ // 0.25.13:绑定**点一下就落盘**,不再等「保存」。
4932
+ // 理由:绑定是工作区级设置(本工作区新会话的默认可见范围),和浮窗里
4933
+ // 「勾选范围 / 可读可写」那份会话级草稿互不相干;以前混在一次保存里,
4934
+ // 用户点完「绑定」看不出任何反馈,还以为没生效。
4935
+ if (typeof sessionId !== 'string' || sessionId === '') return
4936
+ if (bindBusy !== '') return
4937
+ if (defaultBound[scope] || String(scope).startsWith('session:')) return
4938
+ const previous = { ...bound }
4939
+ const nextBound = { ...bound, [scope]: !bound[scope] }
4940
+ const bindings = catalog
4941
+ .filter((item) => nextBound[item.scope] && !defaultBound[item.scope] && !String(item.scope).startsWith('session:'))
4942
+ .map((item) => item.scope)
4943
+ setBound(nextBound) // 乐观更新:按钮立刻变成已绑定 / 已解除
4944
+ setBindBusy(scope)
4945
+ setError('')
4946
+ api('bindings', { session: sessionId, bindings })
4947
+ .then((value) => {
4948
+ // 以服务端返回的落盘结果为准(它会做去重 / 规范化)。
4949
+ const saved = Array.isArray(value && value.bindings) ? value.bindings : bindings
4950
+ const confirmed = {}
4951
+ for (const item of catalog) {
4952
+ confirmed[item.scope] = defaultBound[item.scope] === true || saved.includes(item.scope)
4953
+ }
4954
+ setBound(confirmed)
4955
+ setData((prev) => (prev && typeof prev === 'object' ? { ...prev, bindings: saved } : prev))
4956
+ })
4957
+ .catch((e) => {
4958
+ setBound(previous) // 失败回滚,别让按钮显示一个没落盘的状态
4959
+ setError(String((e && e.message) || e))
4960
+ })
4961
+ .finally(() => setBindBusy(''))
4920
4962
  }
4921
4963
 
4922
4964
  const selectAll = () => {
@@ -4952,6 +4994,8 @@ window.__ModuleLoader__.load({
4952
4994
  setBusy(true)
4953
4995
  setError('')
4954
4996
  // 只提交**额外**绑定:默认范围自带的会话 / 项目 / global 不需要也不允许写入。
4997
+ // 0.25.13 起绑定已经由 toggleBound **即时**写入 /bindings,这里再带上一次是
4998
+ // 幂等的兜底(同一份状态,旧客户端 / 老服务端仍能按一次保存生效)。
4955
4999
  const bindings = catalog
4956
5000
  .filter((item) => bound[item.scope] && !defaultBound[item.scope] && !String(item.scope).startsWith('session:'))
4957
5001
  .map((item) => item.scope)
@@ -5130,6 +5174,9 @@ window.__ModuleLoader__.load({
5130
5174
  h('button', { type: 'button', className: 'linkbtn', onClick: selectAll }, '全选'),
5131
5175
  h('button', { type: 'button', className: 'linkbtn', onClick: clearAll }, '取消全选'),
5132
5176
  ),
5177
+ // 0.25.13:两种设置的生命周期不同 —— 绑定是工作区级、点一下立即保存;
5178
+ // 勾选范围 / 可读 / 可写是本会话的草稿,点「保存」才生效。
5179
+ h('div', { className: 'hint' }, '「绑定」点一下立即保存(工作区级);勾选范围与可读 / 可写点「保存」后生效。'),
5133
5180
  loading && data === null
5134
5181
  ? h('div', { className: 'hint' }, '读取中…')
5135
5182
  : h('div', { className: 'mem-scope-list' },
@@ -5190,12 +5237,13 @@ window.__ModuleLoader__.load({
5190
5237
  type: 'button',
5191
5238
  className: `mem-scope-state bind${defaultBound[item.scope] || bound[item.scope] ? ' on' : ''}${defaultBound[item.scope] ? ' locked' : ''}`,
5192
5239
  'aria-pressed': Boolean(defaultBound[item.scope] || bound[item.scope]),
5193
- disabled: Boolean(defaultBound[item.scope]),
5240
+ 'aria-busy': bindBusy === item.scope,
5241
+ disabled: Boolean(defaultBound[item.scope]) || bindBusy !== '',
5194
5242
  title: defaultBound[item.scope]
5195
5243
  ? '默认可见范围已包含(会话 + 项目 + global 默认绑定),无需再绑定'
5196
5244
  : (bound[item.scope]
5197
- ? '已绑定到当前工作区:本工作区新会话的默认可见范围会包含它'
5198
- : '绑定到当前工作区:本工作区新会话的默认可见范围会包含它'),
5245
+ ? '已绑定到当前工作区(点一下立即解除绑定):本工作区新会话的默认可见范围会包含它'
5246
+ : '绑定到当前工作区(点一下立即保存,不用再点「保存」):本工作区新会话的默认可见范围会包含它'),
5199
5247
  onClick: () => { if (!defaultBound[item.scope]) toggleBound(item.scope) },
5200
5248
  }, '绑定'),
5201
5249
  h('span', { className: 'mem-scope-sep', 'aria-hidden': 'true' }),
@@ -5260,6 +5308,100 @@ window.__ModuleLoader__.load({
5260
5308
  : (createPortal !== null && portalTarget !== null ? createPortal(popover, portalTarget) : popover),
5261
5309
  )
5262
5310
  }
5311
+ /** 0.25.14:全局待审批快照的轮询周期。与审批卡同频,避免黄点比卡片晚太多。 */
5312
+ const APPROVAL_PRESENCE_POLL_MS = 1500
5313
+
5314
+ /**
5315
+ * 0.25.14:把「本会话正在等待记忆审批」传播成宿主的 pending interaction。
5316
+ *
5317
+ * 为什么需要它:`MemoryApprovalDock` 只是我们自己画的卡片(conversation.input.dock),
5318
+ * 宿主的侧边栏会话列表并不认识它 —— 黄点 /「待审批」/ 自动把会话提到水线以上,
5319
+ * 全部来自 `ctx.uiSession` 的 pending interaction 注册表。宿主自己的
5320
+ * `dsh-client-ui-approval` 和 `dsh-client-ui-user-questions` 就是通过
5321
+ * `registerPendingInteraction` 发布 `kind: 'approval' | 'question'` 的;
5322
+ * 我们照抄同一条通道,发布一个**合成 interaction**(kind='approval'):
5323
+ * - 侧边栏拿到 warning 状态 → 左上角黄点、紧凑文案「待审批」、悬停「等待审批」;
5324
+ * - 其它插件(包括宿主会话本体)也能从 `uiSession.sessionStatus` 读到这个阻塞,
5325
+ * 和系统审批 / ask 工具完全同构;
5326
+ * - 它**不是** `PendingApproval` 实例,所以宿主的审批卡片不会抢着渲染它,
5327
+ * 我们自己的 dock 仍然是唯一可见的审批 UI。
5328
+ *
5329
+ * 发布按审批 id 增删(一个会话可能同时有多条),回答 / 超时后由下一次轮询移除。
5330
+ * `summary=1` 只拿 id + sessionId,不把正文搬来搬去。
5331
+ */
5332
+ let approvalPresenceSync = null
5333
+
5334
+ function installApprovalPresence(ctx) {
5335
+ if (ctx === null || typeof ctx !== 'object' || typeof ctx.inject !== 'function') return
5336
+ try {
5337
+ // 不在 apply 里一次性 ctx.get('uiSession'):那会在服务尚未 provide 时拿到
5338
+ // undefined 且永不重试(插件冷启动丢注册的老坑)。inject 等就绪后再挂。
5339
+ ctx.inject(['uiSession'], (scope) => {
5340
+ const uiSession = scope.uiSession
5341
+ if (uiSession === null || typeof uiSession !== 'object'
5342
+ || typeof uiSession.registerPendingInteraction !== 'function') return
5343
+ const publish = uiSession.registerPendingInteraction(() => 0)
5344
+ if (typeof publish !== 'function') return
5345
+
5346
+ // approval id → 撤销发布函数。按 id 增删,避免同一会话的多条审批互相顶掉。
5347
+ const live = new Map()
5348
+ let active = true
5349
+
5350
+ const sync = async () => {
5351
+ let value
5352
+ try { value = await api('approvals?summary=1') } catch { return }
5353
+ if (!active) return
5354
+ const list = value && Array.isArray(value.approvals) ? value.approvals : []
5355
+ const seen = new Set()
5356
+ for (const item of list) {
5357
+ if (item === null || typeof item !== 'object') continue
5358
+ const id = typeof item.id === 'string' ? item.id : ''
5359
+ const sessionId = typeof item.sessionId === 'string' ? item.sessionId : ''
5360
+ if (id === '' || sessionId === '' || seen.has(id)) continue
5361
+ seen.add(id)
5362
+ if (live.has(id)) continue
5363
+ try {
5364
+ const remove = publish({
5365
+ sessionId,
5366
+ kind: 'approval',
5367
+ key: `memory-approval:${id}`,
5368
+ toolName: typeof item.tool === 'string' && item.tool !== '' ? item.tool : 'memory',
5369
+ }, () => {})
5370
+ if (typeof remove === 'function') live.set(id, remove)
5371
+ } catch { /* 单条发布失败不影响其它会话的提醒 */ }
5372
+ }
5373
+ for (const [id, remove] of [...live]) {
5374
+ if (seen.has(id)) continue
5375
+ live.delete(id)
5376
+ try { remove() } catch { /* 组件/服务已释放 */ }
5377
+ }
5378
+ }
5379
+
5380
+ approvalPresenceSync = () => { void sync() }
5381
+ void sync()
5382
+ let timer
5383
+ if (typeof setInterval === 'function') {
5384
+ timer = setInterval(() => {
5385
+ if (typeof document !== 'undefined' && document.hidden) return
5386
+ void sync()
5387
+ }, APPROVAL_PRESENCE_POLL_MS)
5388
+ // Node 测试环境:不因为一个轮询句柄让进程永不退出;浏览器没有 unref。
5389
+ if (timer && typeof timer.unref === 'function') timer.unref()
5390
+ }
5391
+ const stop = () => {
5392
+ if (!active) return
5393
+ active = false
5394
+ if (timer !== undefined) clearInterval(timer)
5395
+ timer = undefined
5396
+ approvalPresenceSync = null
5397
+ for (const remove of live.values()) { try { remove() } catch { /* 已释放 */ } }
5398
+ live.clear()
5399
+ }
5400
+ try { scope.effect(() => stop, 'dsh-memory: approval presence') } catch { /* 旧宿主没有 effect 时随服务释放 */ }
5401
+ })
5402
+ } catch { /* 旧宿主没有 ctx.inject:少一个侧边栏提醒,绝不让 client apply 失败 */ }
5403
+ }
5404
+
5263
5405
  /**
5264
5406
  * 普通限制下的「范围外记忆访问审批」卡片(0.21.0)。
5265
5407
  *
@@ -5391,6 +5533,8 @@ window.__ModuleLoader__.load({
5391
5533
  delete next[pending.id]
5392
5534
  return next
5393
5535
  })
5536
+ // 立刻撤销侧边栏黄点,不必等下一次 1.5s 轮询。
5537
+ if (approvalPresenceSync !== null) approvalPresenceSync()
5394
5538
  })
5395
5539
  .catch((e) => setError(String((e && e.message) || e)))
5396
5540
  .finally(() => setBusy(''))
@@ -5572,6 +5716,9 @@ window.__ModuleLoader__.load({
5572
5716
  const stopNavWatch = wrapSettingsNav()
5573
5717
  ctx.effect(() => () => { styleEl.remove(); stopNavWatch() }, 'dsh-memory: styles + nav icon')
5574
5718
 
5719
+ // 0.25.14:侧边栏黄点提示(独立于 slots;旧宿主没有 uiSession 时静默跳过)。
5720
+ installApprovalPresence(ctx)
5721
+
5575
5722
  const slots = ctx.get('slots')
5576
5723
  if (slots === undefined) return
5577
5724
  clientCtx = ctx
@@ -5835,6 +5982,9 @@ window.__ModuleLoader__.load({
5835
5982
  AuditTab: AuditTab,
5836
5983
  MemoryVisibilityButton: MemoryVisibilityButton,
5837
5984
  MemoryApprovalDock: MemoryApprovalDock,
5985
+ // 0.25.14:侧边栏阻塞提示的发布器(测试直接驱动,不等真实 1.5s 定时器)。
5986
+ installApprovalPresence: installApprovalPresence,
5987
+ approvalPresenceSync: () => approvalPresenceSync,
5838
5988
  openMemoryRecordPanel: openMemoryRecordPanel,
5839
5989
  requestRecordFocus: requestRecordFocus,
5840
5990
  takeRecordFocus: takeRecordFocus,
package/lib/panel.js CHANGED
@@ -595,6 +595,34 @@ function visibilityPayload(ctx, memory, sessionId) {
595
595
  }
596
596
  }
597
597
 
598
+ /**
599
+ * 校验并规范化「工作区绑定」提交(0.25.13)。
600
+ *
601
+ * `/visibility` 与 `/bindings` 共用同一套规则:只接受**具体作用域键**
602
+ * (不接受 `all` / 当前项目 / 当前会话这类别名),会话作用域不能绑定到工作区
603
+ * (它只属于某一次会话),重复项去重保序。
604
+ *
605
+ * @param rawBindings - 客户端提交的绑定数组(任意值都按非法处理)。
606
+ * @returns 规范化后的作用域键数组。
607
+ */
608
+ function normalizeBindings(rawBindings) {
609
+ if (!Array.isArray(rawBindings)) throw new ApiError(400, 'SCOPE_INVALID', 'bindings 必须是字符串数组')
610
+ const bindings = []
611
+ for (const raw of rawBindings) {
612
+ if (typeof raw !== 'string' || raw.trim() === '') throw new ApiError(400, 'SCOPE_INVALID', '绑定项必须是非空字符串')
613
+ const normalized = normalizeScopeInput(raw)
614
+ if (!normalized.ok) throw new ApiError(400, normalized.code, normalized.message)
615
+ if (normalized.kind === 'all' || normalized.kind === 'current-project' || normalized.kind === 'current-session' || normalized.scope === undefined) {
616
+ throw new ApiError(400, 'SCOPE_INVALID', `绑定必须是具体作用域键: ${JSON.stringify(raw)}`)
617
+ }
618
+ if (normalized.scope.startsWith('session:')) {
619
+ throw new ApiError(400, 'SCOPE_INVALID', '会话作用域不能绑定到工作区')
620
+ }
621
+ if (!bindings.includes(normalized.scope)) bindings.push(normalized.scope)
622
+ }
623
+ return bindings
624
+ }
625
+
598
626
  /**
599
627
  * 面板「记忆权限」的授权快照(0.25.0)。
600
628
  *
@@ -753,23 +781,10 @@ async function handle(ctx, routePath, req, res) {
753
781
  // 工作区级绑定:省略 = 不改;数组 = 整体替换。与可见范围同一个保存动作提交。
754
782
  const rawBindings = body?.bindings
755
783
  if (rawBindings !== undefined) {
756
- if (!Array.isArray(rawBindings)) throw new ApiError(400, 'SCOPE_INVALID', 'bindings 必须是字符串数组')
757
784
  if (typeof memory.setWorkspaceBindings !== 'function') {
758
785
  throw new ApiError(501, 'NOT_SUPPORTED', 'provider 未提供工作区绑定接口(请升级 @restregular/dsh-memory)')
759
786
  }
760
- const bindings = []
761
- for (const raw of rawBindings) {
762
- if (typeof raw !== 'string' || raw.trim() === '') throw new ApiError(400, 'SCOPE_INVALID', '绑定项必须是非空字符串')
763
- const normalized = normalizeScopeInput(raw)
764
- if (!normalized.ok) throw new ApiError(400, normalized.code, normalized.message)
765
- if (normalized.kind === 'all' || normalized.kind === 'current-project' || normalized.kind === 'current-session' || normalized.scope === undefined) {
766
- throw new ApiError(400, 'SCOPE_INVALID', `绑定必须是具体作用域键: ${JSON.stringify(raw)}`)
767
- }
768
- if (normalized.scope.startsWith('session:')) {
769
- throw new ApiError(400, 'SCOPE_INVALID', '会话作用域不能绑定到工作区')
770
- }
771
- if (!bindings.includes(normalized.scope)) bindings.push(normalized.scope)
772
- }
787
+ const bindings = normalizeBindings(rawBindings)
773
788
  let session
774
789
  try { session = ctx.get('sessions')?.get?.(sessionId) } catch { session = undefined }
775
790
  memory.setWorkspaceBindings({ session: session !== undefined ? session : { id: sessionId } }, bindings)
@@ -779,13 +794,40 @@ async function handle(ctx, routePath, req, res) {
779
794
  return
780
795
  }
781
796
 
797
+ // 记忆权限浮窗的「绑定」按钮**单独保存**(0.25.13):绑定是工作区级设置
798
+ // (本工作区新会话的默认可见范围),和「勾选范围 / 可读可写」的草稿无关,
799
+ // 所以点一下立即落盘,不需要用户再点「保存」;也不注入上下文提示。
800
+ if (method === 'POST' && path === '/bindings') {
801
+ if (typeof memory.setWorkspaceBindings !== 'function') {
802
+ throw new ApiError(501, 'NOT_SUPPORTED', 'provider 未提供工作区绑定接口(请升级 @restregular/dsh-memory)')
803
+ }
804
+ const body = await readJsonBody(req)
805
+ const sessionId = typeof body?.session === 'string' ? body.session.trim() : ''
806
+ if (sessionId === '') throw new ApiError(400, 'SESSION_REQUIRED', 'session 不能为空')
807
+ const bindings = normalizeBindings(body?.bindings)
808
+ let session
809
+ try { session = ctx.get('sessions')?.get?.(sessionId) } catch { session = undefined }
810
+ const written = memory.setWorkspaceBindings({ session: session !== undefined ? session : { id: sessionId } }, bindings)
811
+ writeJson(res, {
812
+ ok: true,
813
+ value: { sessionId, bindings: Array.isArray(written) ? written : bindings },
814
+ })
815
+ return
816
+ }
817
+
782
818
  // 普通限制下的范围外访问审批:客户端浮层轮询待审批,用户点「拒绝 / 允许一次」后回写。
819
+ // `summary=1` 是 0.25.14 新增的轻量口径:侧边栏阻塞提醒只需要 id + sessionId,
820
+ // 不带条目正文,避免全局 1.5s 轮询把审批内容一遍遍传一遍。
783
821
  if (method === 'GET' && path === '/approvals') {
784
822
  if (typeof memory.pendingVisibilityApprovals !== 'function') {
785
823
  throw new ApiError(501, 'NOT_SUPPORTED', 'provider 未提供可见域审批接口(请升级 @restregular/dsh-memory)')
786
824
  }
787
825
  const sessionId = (url.searchParams.get('session') ?? '').trim()
788
- writeJson(res, { ok: true, value: { approvals: memory.pendingVisibilityApprovals(sessionId === '' ? undefined : sessionId) } })
826
+ const summary = url.searchParams.get('summary') === '1'
827
+ const approvals = summary && typeof memory.pendingVisibilityApprovalPresence === 'function'
828
+ ? memory.pendingVisibilityApprovalPresence(sessionId === '' ? undefined : sessionId)
829
+ : memory.pendingVisibilityApprovals(sessionId === '' ? undefined : sessionId)
830
+ writeJson(res, { ok: true, value: { approvals } })
789
831
  return
790
832
  }
791
833
  if (method === 'POST' && path === '/approvals') {
@@ -383,6 +383,11 @@ export class CordisMemoryService extends Service {
383
383
  return this.impl.pendingVisibilityApprovals(sessionId)
384
384
  }
385
385
 
386
+ /** 侧边栏阻塞提醒:待审批的轻量快照(不带条目正文)。 */
387
+ pendingVisibilityApprovalPresence(sessionId ) {
388
+ return this.impl.pendingVisibilityApprovalPresence(sessionId)
389
+ }
390
+
386
391
  /** 面板:回答一条待审批(可带逐条勾选的 allowedIds)。 */
387
392
  answerVisibilityApproval(id , outcome , allowedIds ) {
388
393
  return this.impl.answerVisibilityApproval(id, outcome, allowedIds)
@@ -620,6 +620,24 @@ export function resolveConfig(config = {}) {
620
620
 
621
621
 
622
622
 
623
+ /**
624
+ * 侧边栏「阻塞提醒」用的轻量待审批快照(0.25.14)。
625
+ *
626
+ * 客户端要模仿宿主 approval / question 的传播方式:把「某会话正在等用户审批」
627
+ * 发布成宿主 `uiSession` 的 pending interaction,侧边栏才会显示黄点。这个轮询
628
+ * 只需要审批的身份与会话,**不需要条目正文** —— 正文仍由完整 `/approvals` 接口
629
+ * 按会话取,避免每 1.5 秒把几十 KB 的条目内容传到客户端。
630
+ */
631
+
632
+
633
+
634
+
635
+
636
+
637
+
638
+
639
+
640
+
623
641
  /** 一次审批的结局:允许(可只允许其中几条) / 拒绝 / 超时。 */
624
642
 
625
643
 
@@ -1835,8 +1853,11 @@ export class LocalMemoryService {
1835
1853
  * 面板:设置当前工作区绑定的作用域。
1836
1854
  *
1837
1855
  * 绑定只接受具体作用域键;会话作用域不能绑定(它属于某一次会话,不属于工作区)。
1838
- * 空数组 = 取消全部绑定。写入后给当前会话发一条可见域变更通知,下一次 pre-step
1839
- * 让 Agent 知道默认范围可能变了。
1856
+ * 空数组 = 取消全部绑定。
1857
+ *
1858
+ * 0.25.13:绑定**不**注入「记忆权限已更新」上下文提示。绑定是工作区级设置
1859
+ * (影响本工作区**新会话**的默认可见范围),当前会话自己读什么并没有变,给
1860
+ * Agent 塞一条权限通知只会误导它以为自己刚刚被重新授权 / 撤销。
1840
1861
  */
1841
1862
  setWorkspaceBindings(agent , scopes ) {
1842
1863
  const workspace = this.workspaceKeyFor(agent)
@@ -1856,12 +1877,6 @@ export class LocalMemoryService {
1856
1877
  out.push(scope)
1857
1878
  }
1858
1879
  const written = this.bindings.set(workspace, out)
1859
- const sessionId = this.rawSessionIdOf(agent)
1860
- if (sessionId !== undefined) {
1861
- // 通知的载荷是"本会话自己的覆盖";绑定变化不属于覆盖,但 Agent 需要知道
1862
- // 默认范围/状态变了,所以仍触发一次(配置取当前自己的覆盖)。
1863
- this.visibilityNotices.set(sessionId, { config: this.visibility.get(sessionId) ?? null, at: Date.now() })
1864
- }
1865
1880
  return written.map((scope) => this.canonicalScope(scope))
1866
1881
  }
1867
1882
 
@@ -2038,6 +2053,30 @@ export class LocalMemoryService {
2038
2053
  return out.sort((a, b) => a.createdAt - b.createdAt)
2039
2054
  }
2040
2055
 
2056
+ /**
2057
+ * 侧边栏阻塞提醒用的轻量快照(0.25.14):只要审批身份 + 会话。
2058
+ *
2059
+ * 与 `pendingVisibilityApprovals` 同一份内存真值,但**不复制条目正文**:
2060
+ * 客户端全局轮询它来发布 `pendingInteraction`,让宿主侧边栏给等待审批的会话
2061
+ * 显示黄色圆点 /「待审批」;完整 payload 仍由 dock 按当前会话拉取。
2062
+ */
2063
+ pendingVisibilityApprovalPresence(sessionId ) {
2064
+ const out = []
2065
+ for (const pending of this.pendingApprovals.values()) {
2066
+ if (sessionId !== undefined && sessionId !== '' && pending.sessionId !== sessionId) continue
2067
+ out.push({
2068
+ id: pending.id,
2069
+ sessionId: pending.sessionId,
2070
+ tool: pending.tool,
2071
+ action: pending.action,
2072
+ ...(pending.mode !== undefined ? { mode: pending.mode } : {}),
2073
+ createdAt: pending.createdAt,
2074
+ expiresAt: pending.expiresAt,
2075
+ })
2076
+ }
2077
+ return out.sort((a, b) => a.createdAt - b.createdAt)
2078
+ }
2079
+
2041
2080
  /** 面板:回答一条待审批。返回 false = 已经不存在/已超时。 */
2042
2081
  answerVisibilityApproval(id , outcome , allowedIds ) {
2043
2082
  const pending = this.pendingApprovals.get(id)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restregular/dsh-memory",
3
- "version": "0.25.12",
3
+ "version": "0.25.14",
4
4
  "description": "DeepSeek Harness 记忆系统(单包单入口):JSONL 存储 + 本地向量检索(BGE-M3)+ 五个模型工具 + 自动召回注入 + 管理面板。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",