@restregular/dsh-memory 0.22.3 → 0.23.0
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 +16 -0
- package/README.md +8 -6
- package/lib/client.js +129 -11
- package/lib/panel.js +88 -5
- package/lib/provider/apply.js +30 -0
- package/lib/provider/index.js +206 -29
- package/lib/provider/session-visibility.js +22 -5
- package/lib/provider/workspace-bindings.js +128 -0
- package/lib/tools/index.js +139 -66
- package/lib/tools/render.js +9 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
本项目的版本记录。安装 id 与 npm 版本一一对应。
|
|
4
4
|
|
|
5
|
+
## 0.23.0 — 修正版编辑与记录页筛选;作用域绑定 / 可读 / 可写状态
|
|
6
|
+
|
|
7
|
+
- **编辑记忆 = 新建修正版(不再原地修改)**:
|
|
8
|
+
- 面板 `POST /memory/api/update` 改为调用 provider 的 `reviseRecord()`:新建一条记录、把 `supersedes` 指向旧记录,旧记录内容与元数据保持原样。
|
|
9
|
+
- 内容、类型、标签、重要度、触发词、过期时间都按提交值写入新记录;内容为空 / 超长 / 命中凭据扫描时的行为与 `memory_save` 一致。
|
|
10
|
+
- 返回 `{ record, superseded }`;`/records` 反查 `supersededBy`,旧记录仍可 `memory_get` / 面板历史查看,检索默认隐藏。
|
|
11
|
+
- **记录页「是否被修正」筛选**:默认「隐藏已修正」;可切到「显示全部」「只看已修正」。审计 / 审批跳转过来的目标记录即使被隐藏也会补一张卡并展开。
|
|
12
|
+
- **每个作用域的【绑定 / 可读 / 可写】状态按钮**:
|
|
13
|
+
- **绑定**是工作区级:写入 `<storeDir>/bindings/<hash>.json`;同一工作区里没有显式覆盖的会话,默认范围额外包含已绑定作用域(`resolveReadScopes` / `visibilityPolicy` 同口径)。会话作用域不可绑定。
|
|
14
|
+
- **可读 / 可写**是会话级、独立生效:`read:false` 的作用域不进入读取集合,搜索命中 / `memory_get` 返回 `withheld.reason='read-disabled'` 且不会发起审批;`write:false` 的保存 / 删除直接拒绝并返回 `SCOPE_READ_ONLY`。
|
|
15
|
+
- 状态按钮与 `Scope visibility` 一起提交:`visibility.scopes[{ scope, read?, write? }]` + `bindings: string[]`;只落 `false`,旧文件 / 旧客户端默认都可读可写。
|
|
16
|
+
- **失败回复讲真实原因**:绝对限制下被挡住的读取 / 写入 / 删除不再伪装成「不存在」。
|
|
17
|
+
- 读:`memory_search` / `memory_list` / `memory_get` 返回 `withheld.reason='absolute'`;被挡住的 id 不再进 `missing`,渲染层提示「绝对限制,不会发起审批」及调整方式。
|
|
18
|
+
- 写 / 删:工具返回 `VISIBILITY_ABSOLUTE`(绝对限制)或 `SCOPE_READ_ONLY`(可写开关关闭);普通限制的拒绝 / 超时 / 无法审批保持原有真实原因。
|
|
19
|
+
- **测试**:provider 的 read/write 开关、工作区绑定持久化与默认范围、`reviseRecord` 修正链、`/update` 旧记录保留、记录页筛选、状态按钮与 POST 载荷、绝对限制 `withheld` / 删除错误原因。全套通过(441 tests / 0 fail)。
|
|
20
|
+
|
|
5
21
|
## 0.22.3 — 审批卡高度与宿主同口径,矮窗口也给列表留空间
|
|
6
22
|
|
|
7
23
|
- 0.22.2 把详情行锁成 `flex:none` 后,矮窗口里 `max-height: min(--dsh-composer-text-max-height, 46vh)` 那层 `46vh` 会让头部占满高度、条目列表只剩十几像素(437px 高窗口实测 ~18px)。
|
package/README.md
CHANGED
|
@@ -45,12 +45,13 @@ JSONL 落盘 · 本机向量检索 · 五个模型工具 · 自动召回 · 硬
|
|
|
45
45
|
| **自动召回** | 每轮按用户问题召回;新会话第一步注入项目 / global 摘要;发布、部署、工具失败等行为按标签触发定向召回 |
|
|
46
46
|
| **印象形态** | 每轮只给每条记忆的短摘要;模型判断相关但需要细节时再 `memory_get` 取全文,省 token 也不丢信息 |
|
|
47
47
|
| **硬性规则** | `kind: rule` 进系统提示常驻段;行首带 8 位 id,注入的是摘要,需要全文时用 `memory_get`;旧会话会收到新增 / 编辑提醒;超预算有明确警告,不静默丢弃 |
|
|
48
|
-
| **会话可见域** | 输入框旁的「记忆范围」按钮设置本会话可读的作用域 + 限制等级(绝对 / 普通 /
|
|
48
|
+
| **会话可见域** | 输入框旁的「记忆范围」按钮设置本会话可读的作用域 + 限制等级(绝对 / 普通 / 无限制);每个作用域还有**绑定 / 可读 / 可写**状态按钮——绑定到当前工作区后新会话默认可见,可读 / 可写独立影响工具读写;Agent 及其子 Agent 都按它检索、注入与 `memory_get` |
|
|
49
|
+
| **修正版编辑** | 面板里编辑一条记忆 = 新建一条修正版并通过 `supersedes` 指向旧记录,旧记录不原地修改;记录页「是否被修正」筛选默认隐藏旧版本,可切到全部 / 只看已修正 |
|
|
49
50
|
| **范围外审批** | 普通限制下,工具命中可见域外的记忆时会在**对应会话的输入框上方**出现审批卡(样式与系统权限审批一致):展示工具、Agent 说明、查询关键词与范围外记忆摘要,支持逐条勾选 / 全选 / 取消全选(「允许选中的 N 条」或整单「允许一次」)或「拒绝」;点记忆 ID 直接跳到面板「记录」页并展开该条 |
|
|
50
51
|
| **上下文去重** | `memory_search` / `memory_list` 返回过的条目记进会话上下文状态;同一版本再次命中只回记忆 ID(`memory_search` 的裸 ID 与带摘要条目之间空一行),并提示用 `memory_get` 取全文(内容更新后重新给摘要) |
|
|
51
52
|
| **状态记忆** | `kind: state` 默认 7 天 TTL;注入带「状态,使用前验证」;过期后默认不进检索 / 摘要 / 召回,但 `memory_get` 与面板仍可取 |
|
|
52
53
|
| **流程索引** | `kind: procedure` 的目录进系统提示:按当前工作区 + 触发词(工具名 / 关键词)列 `id · 触发词 → 标题`,需要时再用 `memory_get` 取全文 |
|
|
53
|
-
| **可视化管理** | 记录浏览 / 搜索 / 新建 / 编辑 /
|
|
54
|
+
| **可视化管理** | 记录浏览 / 搜索 / 新建 / 编辑 / 删除(编辑生成修正版);**记录页可主动做语义检索**(与 `memory_search` 同一套排序),并有「是否被修正」筛选;记忆树展示作用域、类型与修正链;设置改完即存;导入导出 |
|
|
54
55
|
| **一键向量后端** | 面板里下载 llama.cpp 运行时与内置模型,按 CPU / 内存 / 显卡推荐;换模型自动重建向量 |
|
|
55
56
|
| **跨进程安全** | 每个作用域一把写锁,锁内重新读盘再合并;多个 DSH 实例或 MCP server 共用一个 store 不丢数据 |
|
|
56
57
|
|
|
@@ -87,20 +88,21 @@ JSONL 落盘 · 本机向量检索 · 五个模型工具 · 自动召回 · 硬
|
|
|
87
88
|
|
|
88
89
|
输入框工具行右侧有「记忆范围」按钮。**打开会话时就会读取这个会话的设置**,按钮上的数字是当前生效的作用域数量,边框样式表示限制等级(绝对限制 = 橙黄实线 / 普通限制 = 蓝色实线 / 无限制 = 灰色虚线;`title` 里写明「已设置 / 使用默认 / 继承父会话 + 数量 + 等级」)。点开的浮窗使用毛玻璃背景,按当前会话列出可选作用域(当前会话 / 当前项目 / global / 已有自定义作用域):
|
|
89
90
|
|
|
90
|
-
- **默认范围**:没有显式设置时(新会话)按默认设置生效 —— **当前会话 + 当前项目 + global
|
|
91
|
+
- **默认范围**:没有显式设置时(新会话)按默认设置生效 —— **当前会话 + 当前项目 + global + 已绑定的作用域** + **普通限制**;面板按同一份默认范围预选,不会出现空面板。
|
|
91
92
|
- **搜索与批量**:顶部可搜索作用域,支持「全选 / 取消全选」;列表最大高度受限,作用域多时在浮窗内滚动。
|
|
93
|
+
- **状态按钮(0.23.0)**:作用域列表每行有【绑定】、【可读】|【可写】。**绑定**是工作区级:绑定后,同一工作区里没有显式覆盖的新会话默认范围会包含它;**可读 / 可写**是会话级,独立控制该作用域的读取与写入(关掉可读 → 搜索 / 读取跳过并说明原因;关掉可写 → 保存 / 删除被拒绝并说明原因)。
|
|
92
94
|
- **限制等级**:
|
|
93
|
-
-
|
|
95
|
+
- **绝对限制**:可见域外的读取 / 写入 / 删除一律不执行;命中被挡住时会明确告诉 Agent 是「绝对限制」以及怎么调整(不再假装记忆不存在)。
|
|
94
96
|
- **普通限制**(默认):可见域内正常返回;命中范围外记忆时,工具会暂停并在**该会话**的输入框上方显示审批卡,展示 Agent 的查询关键词与范围外记忆摘要;读审批可以逐条勾选,只允许其中一条或多条。用户拒绝 / 5 分钟未回答时,工具结果里会明确写出真实原因(「用户拒绝了本次访问」/「审批超时」),模型不会误以为记忆不存在。范围外写入 / 删除同样走审批。
|
|
95
97
|
- **无限制**:不启用范围白名单,可以读写任意作用域(选择仍会保存,供下次切换)。
|
|
96
98
|
- **不再按记忆类型收窄**:0.19.1 起只按作用域限制;旧配置里的 `kinds` 会被忽略,同一作用域下的事实 / 规则 / 流程等都可读。
|
|
97
99
|
- **审批卡(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 = 拒绝(焦点在卡片内时)。
|
|
98
100
|
- 子 Agent 自动继承父会话 / 根会话的设置;在子 Agent 自己的会话里再设置,只影响那一个会话。
|
|
99
101
|
- 保存后,下一次 Agent 步骤会通过注入的上下文消息收到「可见域已更新」通知(包含可见范围与限制等级),不需要重启会话。
|
|
100
|
-
- 「恢复默认」清除覆盖,回到默认设置(会话 + 项目 + global + 普通限制)。
|
|
102
|
+
- 「恢复默认」清除覆盖,回到默认设置(会话 + 项目 + global + 已绑定的作用域 + 普通限制)。
|
|
101
103
|
- 覆盖按会话落盘在 `<storeDir>/visibility/<session>.json`,浏览器刷新 / 插件重载后仍在;0.18 的旧文件按「绝对限制」兼容读取。
|
|
102
104
|
- 浮窗与审批卡的半透明背景、边框、文字颜色全部走宿主主题 token;勾选框选中态、保存按钮、限制等级选中态使用 `--dsw-alias-state-business-primary` + `--dsw-alias-label-primary-foreground`,深色模式下不会出现白底白勾 / 白底白字;按钮三档边框用 `state-warn-primary`(橙黄)/ `state-business-primary`(蓝)/ 虚线灰;阴影已收敛为小范围投影,滚动列表高度收紧到 `min(220px, 32vh)`。
|
|
103
|
-
- **可见范围 = 可操作范围(0.20.0
|
|
105
|
+
- **可见范围 = 可操作范围(0.20.0 起,0.23.0 拆分读写)**:`memory_search` / `memory_list` / `memory_get` 与 `memory_save` / `memory_forget` 共用同一份可见域;0.23.0 起每个作用域的「可读 / 可写」状态独立生效,失败原因会写进工具回复。面板管理页仍是用户本人的操作,不受会话语义限制。
|
|
104
106
|
|
|
105
107
|
### 向量服务
|
|
106
108
|
|
package/lib/client.js
CHANGED
|
@@ -530,6 +530,15 @@ window.__ModuleLoader__.load({
|
|
|
530
530
|
'.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}',
|
|
531
531
|
'.mem-scope-label:hover{color:var(--dsw-alias-brand-primary);border:none}',
|
|
532
532
|
'.mem-scope-row .cnt{flex:none;color:var(--dsw-alias-label-secondary);font-size:10.5px}',
|
|
533
|
+
// 0.23.0:每个作用域的状态按钮行 —— 绑定 | 可读 | 可写。
|
|
534
|
+
'.mem-scope-state-row{display:flex;align-items:center;gap:4px;padding-left:26px}',
|
|
535
|
+
'.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}',
|
|
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
|
+
'.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
|
+
'.mem-scope-state.bind.on{border-style:dashed}',
|
|
539
|
+
'.mem-scope-state:disabled{opacity:.42;cursor:default}',
|
|
540
|
+
'.mem-scope-state:focus-visible{outline:1px solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}',
|
|
541
|
+
'.mem-scope-sep{width:1px;height:12px;margin:0 1px;background:var(--dsw-alias-border-l1);flex:none}',
|
|
533
542
|
'.mem-scope-foot{display:flex;align-items:center;gap:8px}',
|
|
534
543
|
'.mem-scope-foot .spacer{flex:1}',
|
|
535
544
|
'.mem-scope-reset{padding:6px 13px;border:1px solid var(--dsw-alias-border-l1);border-radius:9px;background:transparent;color:var(--dsw-alias-label-secondary);font-size:12px;cursor:pointer;transition:border-color .12s ease,color .12s ease}',
|
|
@@ -1049,9 +1058,10 @@ window.__ModuleLoader__.load({
|
|
|
1049
1058
|
: null,
|
|
1050
1059
|
),
|
|
1051
1060
|
h('div', { className: 'acts' },
|
|
1052
|
-
h('button', { disabled: busy, onClick: save }, busy ? '保存中…' : '
|
|
1061
|
+
h('button', { disabled: busy, onClick: save }, busy ? '保存中…' : '保存修正版'),
|
|
1053
1062
|
h('button', { disabled: busy, onClick: cancelEdit }, '取消'),
|
|
1054
1063
|
),
|
|
1064
|
+
h('div', { className: 'hint' }, '保存会新建一条修正版(supersedes 当前记录),旧记录保留;记录页默认隐藏已被修正的旧版本。'),
|
|
1055
1065
|
)
|
|
1056
1066
|
: h('div', null,
|
|
1057
1067
|
h('div', { className: 'content' }, rec.content),
|
|
@@ -3413,6 +3423,9 @@ window.__ModuleLoader__.load({
|
|
|
3413
3423
|
const [installRequested, setInstallRequested] = React.useState(false)
|
|
3414
3424
|
const [dangerAsk, setDangerAsk] = React.useState('')
|
|
3415
3425
|
const [scopeFilter, setScopeFilter] = React.useState('')
|
|
3426
|
+
// 0.23.0:记录页「是否被修正」筛选。默认隐藏已被 supersede 的旧记录,
|
|
3427
|
+
// 但历史仍可切到「显示全部 / 只看已修正」查看。
|
|
3428
|
+
const [supersededFilter, setSupersededFilter] = React.useState('hide')
|
|
3416
3429
|
const [q, setQ] = React.useState('')
|
|
3417
3430
|
// 语义检索:默认关(记录页原本是"关键词过滤");开启后搜索走 /search,
|
|
3418
3431
|
// 由 provider 用向量 + 词法同一套排序,列表按相关度排。
|
|
@@ -3688,7 +3701,7 @@ window.__ModuleLoader__.load({
|
|
|
3688
3701
|
notice = h('div', { className: 'hint err' }, `安装失败:${install.error || install.message}`)
|
|
3689
3702
|
}
|
|
3690
3703
|
|
|
3691
|
-
const filtering = q.trim() !== '' || scopeFilter !== ''
|
|
3704
|
+
const filtering = q.trim() !== '' || scopeFilter !== '' || supersededFilter !== 'hide'
|
|
3692
3705
|
|
|
3693
3706
|
// 三个标签的内容分开构建:记录(概览) / 数据(列表) / 设置。
|
|
3694
3707
|
const statsCard = h('div', { className: 'stats' },
|
|
@@ -3807,9 +3820,21 @@ window.__ModuleLoader__.load({
|
|
|
3807
3820
|
disabled: loading,
|
|
3808
3821
|
onChange: (next) => { setScopeFilter(next); load(q, next) },
|
|
3809
3822
|
}),
|
|
3823
|
+
// 0.23.0:是否被修正。默认隐藏旧版本;要看历史关系时切到另外两档。
|
|
3824
|
+
h(Dropdown, {
|
|
3825
|
+
items: [
|
|
3826
|
+
{ value: 'hide', label: '隐藏已修正' },
|
|
3827
|
+
{ value: 'all', label: '显示全部' },
|
|
3828
|
+
{ value: 'only', label: '只看已修正' },
|
|
3829
|
+
],
|
|
3830
|
+
value: supersededFilter,
|
|
3831
|
+
disabled: loading,
|
|
3832
|
+
title: '是否被修正:默认隐藏已被新版本取代的旧记录',
|
|
3833
|
+
onChange: setSupersededFilter,
|
|
3834
|
+
}),
|
|
3810
3835
|
h('button', { onClick: () => setCreating((v) => !v), disabled: loading }, creating ? '收起' : '新建'),
|
|
3811
3836
|
h('button', { onClick: () => load(q, scopeFilter), disabled: loading }, loading ? '刷新中…' : '刷新'),
|
|
3812
|
-
filtering ? h('button', { className: 'linkbtn', onClick: () => { setQ(''); setScopeFilter(''); setSearchInfo(null); load('', '', semantic) } }, '清空筛选') : null,
|
|
3837
|
+
filtering ? h('button', { className: 'linkbtn', onClick: () => { setQ(''); setScopeFilter(''); setSupersededFilter('hide'); setSearchInfo(null); load('', '', semantic) } }, '清空筛选') : null,
|
|
3813
3838
|
)
|
|
3814
3839
|
// 语义检索结果的出处:真跑了向量,还是因为服务/向量缺失退回了词法 —— 明说,
|
|
3815
3840
|
// 不把词法结果冒充成"语义找到的"。
|
|
@@ -3848,11 +3873,18 @@ window.__ModuleLoader__.load({
|
|
|
3848
3873
|
})
|
|
3849
3874
|
: null
|
|
3850
3875
|
const emptyText = searchInfo ? '没有语义相关的记忆' : filtering ? '没有匹配的记忆' : '还没有记忆'
|
|
3851
|
-
//
|
|
3876
|
+
// 0.23.0:「是否被修正」筛选。默认隐藏已被 supersede 的旧记录,
|
|
3877
|
+
// 历史核对时可切到「显示全部 / 只看已修正」。
|
|
3878
|
+
const supersededRecords = supersededFilter === 'all'
|
|
3879
|
+
? records
|
|
3880
|
+
: supersededFilter === 'only'
|
|
3881
|
+
? records.filter((rec) => Boolean(rec.supersededBy))
|
|
3882
|
+
: records.filter((rec) => !rec.supersededBy)
|
|
3883
|
+
// 从审计跳过来的目标记录如果不在当前筛选结果里,先把它补到列表最前面,
|
|
3852
3884
|
// 否则跳转后列表里根本没有这张卡,focus 自然也无法展开。
|
|
3853
|
-
const displayRecords = focusRecordData !== null && !
|
|
3854
|
-
? [focusRecordData, ...
|
|
3855
|
-
:
|
|
3885
|
+
const displayRecords = focusRecordData !== null && !supersededRecords.some((rec) => rec.id === focusRecordData.id)
|
|
3886
|
+
? [focusRecordData, ...supersededRecords]
|
|
3887
|
+
: supersededRecords
|
|
3856
3888
|
const listBody = !loading && !error && displayRecords.length === 0
|
|
3857
3889
|
? h('div', { className: 'empty' },
|
|
3858
3890
|
emptyText,
|
|
@@ -4514,8 +4546,14 @@ window.__ModuleLoader__.load({
|
|
|
4514
4546
|
* - 不再按记忆类型收窄,只选作用域。
|
|
4515
4547
|
*
|
|
4516
4548
|
* 读写走 /memory/api/visibility:
|
|
4517
|
-
* GET ?session=<id> → { override, effective, inherited, defaults, scopes }
|
|
4518
|
-
* POST { session, visibility: { scopes: [{ scope }], level } | null
|
|
4549
|
+
* GET ?session=<id> → { override, effective, inherited, defaults, workspace, bindings, scopes }
|
|
4550
|
+
* POST { session, visibility: { scopes: [{ scope, read?, write? }], level } | null,
|
|
4551
|
+
* bindings: string[] } → 同上
|
|
4552
|
+
*
|
|
4553
|
+
* 0.23.0:
|
|
4554
|
+
* - 每个作用域有「绑定 / 可读 / 可写」状态按钮;绑定是工作区级(新会话默认可见),
|
|
4555
|
+
* 可读 / 可写是会话级,直接影响工具读到 / 写到该作用域时的结果与失败原因;
|
|
4556
|
+
* - 保存时 read/write 只在关掉时提交 false,绑定整体提交。
|
|
4519
4557
|
*/
|
|
4520
4558
|
function MemoryVisibilityButton({ sessionId } = {}) {
|
|
4521
4559
|
const [open, setOpen] = React.useState(false)
|
|
@@ -4525,6 +4563,8 @@ window.__ModuleLoader__.load({
|
|
|
4525
4563
|
const [data, setData] = React.useState(null)
|
|
4526
4564
|
const [level, setLevel] = React.useState('normal')
|
|
4527
4565
|
const [entries, setEntries] = React.useState({})
|
|
4566
|
+
const [perms, setPerms] = React.useState({})
|
|
4567
|
+
const [bound, setBound] = React.useState({})
|
|
4528
4568
|
const [catalog, setCatalog] = React.useState([])
|
|
4529
4569
|
const [search, setSearch] = React.useState('')
|
|
4530
4570
|
const [anchor, setAnchor] = React.useState(null)
|
|
@@ -4591,8 +4631,30 @@ window.__ModuleLoader__.load({
|
|
|
4591
4631
|
}
|
|
4592
4632
|
const nextEntries = {}
|
|
4593
4633
|
for (const item of nextCatalog) nextEntries[item.scope] = selected.has(item.scope)
|
|
4634
|
+
// 0.23.0:每个作用域的 read / write 状态 + 工作区绑定。
|
|
4635
|
+
const ruleByScope = new Map()
|
|
4636
|
+
for (const rule of selectedRules) {
|
|
4637
|
+
const scope = typeof rule === 'string' ? rule : rule && typeof rule.scope === 'string' ? rule.scope : ''
|
|
4638
|
+
if (scope !== '' && !ruleByScope.has(scope)) ruleByScope.set(scope, rule)
|
|
4639
|
+
}
|
|
4640
|
+
const boundSet = new Set(
|
|
4641
|
+
(Array.isArray(value.bindings) ? value.bindings : [])
|
|
4642
|
+
.filter((scope) => typeof scope === 'string' && scope !== ''),
|
|
4643
|
+
)
|
|
4644
|
+
const nextPerms = {}
|
|
4645
|
+
const nextBound = {}
|
|
4646
|
+
for (const item of nextCatalog) {
|
|
4647
|
+
const rule = ruleByScope.get(item.scope)
|
|
4648
|
+
nextPerms[item.scope] = {
|
|
4649
|
+
read: rule ? rule.read !== false : item.read !== false,
|
|
4650
|
+
write: rule ? rule.write !== false : item.write !== false,
|
|
4651
|
+
}
|
|
4652
|
+
nextBound[item.scope] = boundSet.has(item.scope) || item.bound === true
|
|
4653
|
+
}
|
|
4594
4654
|
setCatalog(nextCatalog)
|
|
4595
4655
|
setEntries(nextEntries)
|
|
4656
|
+
setPerms(nextPerms)
|
|
4657
|
+
setBound(nextBound)
|
|
4596
4658
|
}
|
|
4597
4659
|
|
|
4598
4660
|
const load = () => {
|
|
@@ -4629,6 +4691,19 @@ window.__ModuleLoader__.load({
|
|
|
4629
4691
|
setEntries((prev) => ({ ...prev, [scope]: !prev[scope] }))
|
|
4630
4692
|
}
|
|
4631
4693
|
|
|
4694
|
+
/** 切换某个作用域的可读 / 可写状态(会话级)。 */
|
|
4695
|
+
const togglePerm = (scope, key) => {
|
|
4696
|
+
setPerms((prev) => {
|
|
4697
|
+
const current = prev[scope] ?? { read: true, write: true }
|
|
4698
|
+
return { ...prev, [scope]: { ...current, [key]: !current[key] } }
|
|
4699
|
+
})
|
|
4700
|
+
}
|
|
4701
|
+
|
|
4702
|
+
/** 切换某个作用域是否绑定到当前工作区(工作区级,新会话默认可见)。 */
|
|
4703
|
+
const toggleBound = (scope) => {
|
|
4704
|
+
setBound((prev) => ({ ...prev, [scope]: !prev[scope] }))
|
|
4705
|
+
}
|
|
4706
|
+
|
|
4632
4707
|
const selectAll = () => {
|
|
4633
4708
|
setEntries((prev) => {
|
|
4634
4709
|
const next = { ...prev }
|
|
@@ -4648,7 +4723,11 @@ window.__ModuleLoader__.load({
|
|
|
4648
4723
|
const save = (config) => {
|
|
4649
4724
|
setBusy(true)
|
|
4650
4725
|
setError('')
|
|
4651
|
-
|
|
4726
|
+
// 绑定是工作区级、与本次会话的显式覆盖一起提交;会话作用域不能绑定。
|
|
4727
|
+
const bindings = catalog
|
|
4728
|
+
.filter((item) => bound[item.scope] && !String(item.scope).startsWith('session:'))
|
|
4729
|
+
.map((item) => item.scope)
|
|
4730
|
+
api('visibility', { session: sessionId, visibility: config, bindings })
|
|
4652
4731
|
.then((value) => {
|
|
4653
4732
|
applyPayload(value)
|
|
4654
4733
|
setOpen(false)
|
|
@@ -4658,7 +4737,11 @@ window.__ModuleLoader__.load({
|
|
|
4658
4737
|
}
|
|
4659
4738
|
|
|
4660
4739
|
const saveDraft = () => {
|
|
4661
|
-
const scopes = catalog.filter((item) => entries[item.scope]).map((item) => ({
|
|
4740
|
+
const scopes = catalog.filter((item) => entries[item.scope]).map((item) => ({
|
|
4741
|
+
scope: item.scope,
|
|
4742
|
+
read: perms[item.scope]?.read !== false,
|
|
4743
|
+
write: perms[item.scope]?.write !== false,
|
|
4744
|
+
}))
|
|
4662
4745
|
if (scopes.length === 0) { setError('至少选择一个可见范围'); return }
|
|
4663
4746
|
save({ scopes, level })
|
|
4664
4747
|
}
|
|
@@ -4779,6 +4862,41 @@ window.__ModuleLoader__.load({
|
|
|
4779
4862
|
}, item.label || item.scope),
|
|
4780
4863
|
h('span', { className: 'cnt' }, `${item.records ?? 0}`),
|
|
4781
4864
|
),
|
|
4865
|
+
// 0.23.0:状态按钮 —— 绑定(工作区级) / 可读 | 可写(会话级)。
|
|
4866
|
+
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
|
+
}, '绑定'),
|
|
4878
|
+
h('span', { className: 'mem-scope-sep', 'aria-hidden': 'true' }),
|
|
4879
|
+
h('button', {
|
|
4880
|
+
type: 'button',
|
|
4881
|
+
className: `mem-scope-state read${perms[item.scope]?.read !== false ? ' on' : ''}`,
|
|
4882
|
+
'aria-pressed': perms[item.scope]?.read !== false,
|
|
4883
|
+
disabled: !entries[item.scope],
|
|
4884
|
+
title: entries[item.scope]
|
|
4885
|
+
? (perms[item.scope]?.read !== false ? '可读:搜索 / 读取会命中该作用域' : '不可读:搜索 / 读取会跳过该作用域')
|
|
4886
|
+
: '先勾选该作用域再调整可读 / 可写',
|
|
4887
|
+
onClick: () => togglePerm(item.scope, 'read'),
|
|
4888
|
+
}, '可读'),
|
|
4889
|
+
h('button', {
|
|
4890
|
+
type: 'button',
|
|
4891
|
+
className: `mem-scope-state write${perms[item.scope]?.write !== false ? ' on' : ''}`,
|
|
4892
|
+
'aria-pressed': perms[item.scope]?.write !== false,
|
|
4893
|
+
disabled: !entries[item.scope],
|
|
4894
|
+
title: entries[item.scope]
|
|
4895
|
+
? (perms[item.scope]?.write !== false ? '可写:保存 / 删除会作用到该作用域' : '不可写:保存 / 删除会被拒绝并告知原因')
|
|
4896
|
+
: '先勾选该作用域再调整可读 / 可写',
|
|
4897
|
+
onClick: () => togglePerm(item.scope, 'write'),
|
|
4898
|
+
}, '可写'),
|
|
4899
|
+
),
|
|
4782
4900
|
)),
|
|
4783
4901
|
),
|
|
4784
4902
|
error ? h('div', { className: 'mem-scope-err' }, error) : null,
|
package/lib/panel.js
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
* GET /status 各 scope 记录数 + 待嵌入数 + 展示标签
|
|
12
12
|
* GET /records ?scope=&q= 枚举/过滤记录
|
|
13
13
|
* GET /search ?scope=&q=&topK= 语义检索(向量 + 词法,provider 排序)
|
|
14
|
-
* POST /update {id, content?, kind?, importance?, tags?,
|
|
14
|
+
* POST /update {id, content?, kind?, importance?, tags?, triggers?, expiresAt?/ttlMs?}
|
|
15
|
+
* → 新建一条修正版(supersedes=id),旧记录保留(0.23.0)
|
|
15
16
|
* POST /delete {id}
|
|
16
17
|
* scope 惰性加载是同步的(store.peek(),**读路径不创建**),无需 ready 门。内容编辑会作废旧
|
|
17
18
|
* 向量并加入 embedPending,由 provider 的回填队列重新嵌入。
|
|
@@ -505,7 +506,7 @@ function visibilityPayload(ctx, memory, sessionId) {
|
|
|
505
506
|
|
|
506
507
|
let refs
|
|
507
508
|
try { if (session !== undefined) refs = resolveCurrentScopes({ session }) } catch { refs = undefined }
|
|
508
|
-
// 没有显式覆盖时,面板仍预选"当前默认读取集合"(会话 + 项目 + global),
|
|
509
|
+
// 没有显式覆盖时,面板仍预选"当前默认读取集合"(会话 + 项目 + global + 工作区绑定),
|
|
509
510
|
// 让用户看到 Agent 现在实际能看到什么;保存后才变成显式覆盖。
|
|
510
511
|
let defaults = []
|
|
511
512
|
try {
|
|
@@ -513,6 +514,22 @@ function visibilityPayload(ctx, memory, sessionId) {
|
|
|
513
514
|
if (Array.isArray(resolved)) defaults = resolved
|
|
514
515
|
} catch { /* 降级为空 */ }
|
|
515
516
|
|
|
517
|
+
// 0.23.0:工作区级绑定 + 每个作用域的 read / write 状态。
|
|
518
|
+
let workspace = null
|
|
519
|
+
let bindings = []
|
|
520
|
+
try {
|
|
521
|
+
if (typeof memory.projectKeyFor === 'function') workspace = memory.projectKeyFor(agentLike)
|
|
522
|
+
if (typeof memory.workspaceBindings === 'function') {
|
|
523
|
+
const list = memory.workspaceBindings(agentLike)
|
|
524
|
+
if (Array.isArray(list)) bindings = list
|
|
525
|
+
}
|
|
526
|
+
} catch { /* 绑定是增强;拿不到就按"没有绑定"处理 */ }
|
|
527
|
+
const bound = new Set(bindings)
|
|
528
|
+
const rules = new Map()
|
|
529
|
+
for (const rule of (Array.isArray(effective?.scopes) ? effective.scopes : [])) {
|
|
530
|
+
if (rule && typeof rule.scope === 'string' && !rules.has(rule.scope)) rules.set(rule.scope, rule)
|
|
531
|
+
}
|
|
532
|
+
|
|
516
533
|
const stats = typeof memory.scopeStats === 'function' ? memory.scopeStats() : []
|
|
517
534
|
const byScope = new Map()
|
|
518
535
|
for (const item of Array.isArray(stats) ? stats : []) {
|
|
@@ -530,10 +547,21 @@ function visibilityPayload(ctx, memory, sessionId) {
|
|
|
530
547
|
ensure(projectScope)
|
|
531
548
|
ensure('global')
|
|
532
549
|
for (const scope of defaults) ensure(scope)
|
|
550
|
+
for (const scope of bindings) ensure(scope)
|
|
533
551
|
const rank = (scope) => scope === sessionScope ? 0 : scope === projectScope ? 1 : scope === 'global' ? 2 : 3
|
|
534
552
|
const scopes = [...byScope.values()]
|
|
535
553
|
.sort((a, b) => rank(a.scope) - rank(b.scope) || String(a.scope).localeCompare(String(b.scope)))
|
|
536
|
-
.map((item) =>
|
|
554
|
+
.map((item) => {
|
|
555
|
+
const rule = rules.get(item.scope)
|
|
556
|
+
return {
|
|
557
|
+
...item,
|
|
558
|
+
label: item.name ?? scopeLabel(ctx, item.scope),
|
|
559
|
+
read: rule === undefined ? true : rule.read !== false,
|
|
560
|
+
write: rule === undefined ? true : rule.write !== false,
|
|
561
|
+
bound: bound.has(item.scope),
|
|
562
|
+
bindable: !String(item.scope).startsWith('session:'),
|
|
563
|
+
}
|
|
564
|
+
})
|
|
537
565
|
return {
|
|
538
566
|
sessionId,
|
|
539
567
|
override: own,
|
|
@@ -541,6 +569,8 @@ function visibilityPayload(ctx, memory, sessionId) {
|
|
|
541
569
|
inherited,
|
|
542
570
|
source,
|
|
543
571
|
defaults,
|
|
572
|
+
workspace,
|
|
573
|
+
bindings: [...bound],
|
|
544
574
|
scopes,
|
|
545
575
|
}
|
|
546
576
|
}
|
|
@@ -633,7 +663,7 @@ async function handle(ctx, routePath, req, res) {
|
|
|
633
663
|
if (sessionId === '') throw new ApiError(400, 'SESSION_REQUIRED', 'session 不能为空')
|
|
634
664
|
let next = null
|
|
635
665
|
const rawConfig = body?.visibility
|
|
636
|
-
// 新协议:{ visibility: { scopes: [{ scope }], level } } | null
|
|
666
|
+
// 新协议:{ visibility: { scopes: [{ scope, read?, write? }], level } } | null
|
|
637
667
|
// 兼容 0.19.0 的 { scopes: [{ scope, kinds? }] } 与 0.18 的 { scopes: string[] }:
|
|
638
668
|
// 0.19.1 起不再限制记忆类型,提交里的 kinds 一律忽略。
|
|
639
669
|
const rawScopes = rawConfig !== null && rawConfig !== undefined && typeof rawConfig === 'object'
|
|
@@ -654,12 +684,43 @@ async function handle(ctx, routePath, req, res) {
|
|
|
654
684
|
throw new ApiError(400, 'SCOPE_INVALID', `可见范围必须是具体作用域键: ${JSON.stringify(scopeRaw)}`)
|
|
655
685
|
}
|
|
656
686
|
if (normalized.scope === undefined || scopes.some((item) => item.scope === normalized.scope)) continue
|
|
657
|
-
|
|
687
|
+
// 0.23.0:read / write 状态。省略 = 可读可写;只有显式 false 才落盘。
|
|
688
|
+
const read = typeof raw === 'object' && raw !== null && raw.read === false
|
|
689
|
+
const write = typeof raw === 'object' && raw !== null && raw.write === false
|
|
690
|
+
scopes.push({
|
|
691
|
+
scope: normalized.scope,
|
|
692
|
+
...(read ? { read: false } : {}),
|
|
693
|
+
...(write ? { write: false } : {}),
|
|
694
|
+
})
|
|
658
695
|
}
|
|
659
696
|
const levelRaw = rawConfig !== null && rawConfig !== undefined && typeof rawConfig === 'object' ? rawConfig.level : 'absolute'
|
|
660
697
|
const level = levelRaw === 'normal' || levelRaw === 'none' ? levelRaw : 'absolute'
|
|
661
698
|
next = { scopes, level }
|
|
662
699
|
}
|
|
700
|
+
// 工作区级绑定:省略 = 不改;数组 = 整体替换。与可见范围同一个保存动作提交。
|
|
701
|
+
const rawBindings = body?.bindings
|
|
702
|
+
if (rawBindings !== undefined) {
|
|
703
|
+
if (!Array.isArray(rawBindings)) throw new ApiError(400, 'SCOPE_INVALID', 'bindings 必须是字符串数组')
|
|
704
|
+
if (typeof memory.setWorkspaceBindings !== 'function') {
|
|
705
|
+
throw new ApiError(501, 'NOT_SUPPORTED', 'provider 未提供工作区绑定接口(请升级 @restregular/dsh-memory)')
|
|
706
|
+
}
|
|
707
|
+
const bindings = []
|
|
708
|
+
for (const raw of rawBindings) {
|
|
709
|
+
if (typeof raw !== 'string' || raw.trim() === '') throw new ApiError(400, 'SCOPE_INVALID', '绑定项必须是非空字符串')
|
|
710
|
+
const normalized = normalizeScopeInput(raw)
|
|
711
|
+
if (!normalized.ok) throw new ApiError(400, normalized.code, normalized.message)
|
|
712
|
+
if (normalized.kind === 'all' || normalized.kind === 'current-project' || normalized.kind === 'current-session' || normalized.scope === undefined) {
|
|
713
|
+
throw new ApiError(400, 'SCOPE_INVALID', `绑定必须是具体作用域键: ${JSON.stringify(raw)}`)
|
|
714
|
+
}
|
|
715
|
+
if (normalized.scope.startsWith('session:')) {
|
|
716
|
+
throw new ApiError(400, 'SCOPE_INVALID', '会话作用域不能绑定到工作区')
|
|
717
|
+
}
|
|
718
|
+
if (!bindings.includes(normalized.scope)) bindings.push(normalized.scope)
|
|
719
|
+
}
|
|
720
|
+
let session
|
|
721
|
+
try { session = ctx.get('sessions')?.get?.(sessionId) } catch { session = undefined }
|
|
722
|
+
memory.setWorkspaceBindings({ session: session !== undefined ? session : { id: sessionId } }, bindings)
|
|
723
|
+
}
|
|
663
724
|
memory.setSessionVisibility(sessionId, next)
|
|
664
725
|
writeJson(res, { ok: true, value: visibilityPayload(ctx, memory, sessionId) })
|
|
665
726
|
return
|
|
@@ -944,6 +1005,28 @@ async function handle(ctx, routePath, req, res) {
|
|
|
944
1005
|
if (method === 'POST' && path === '/update') {
|
|
945
1006
|
const body = await readJsonBody(req)
|
|
946
1007
|
const id = String(body.id ?? '')
|
|
1008
|
+
// 0.23.0:编辑 = 新建一条修正版,旧记录不原地修改。旧 provider 没有
|
|
1009
|
+
// reviseRecord 时才退回原来的原地编辑,避免版本错配直接报错。
|
|
1010
|
+
if (typeof memory.reviseRecord === 'function') {
|
|
1011
|
+
const input = { id }
|
|
1012
|
+
if (body.content !== undefined) input.content = String(body.content)
|
|
1013
|
+
if (body.kind !== undefined) input.kind = String(body.kind)
|
|
1014
|
+
if (body.importance !== undefined) input.importance = Number(body.importance)
|
|
1015
|
+
if (body.tags !== undefined) input.tags = Array.isArray(body.tags) ? body.tags.map(String) : []
|
|
1016
|
+
if (body.triggers !== undefined) input.triggers = Array.isArray(body.triggers) ? body.triggers.map(String) : []
|
|
1017
|
+
if (body.expiredAt === null) input.expiresAt = null
|
|
1018
|
+
else if (typeof body.expiresAt === 'number') input.expiresAt = body.expiresAt
|
|
1019
|
+
else if (typeof body.ttlMs === 'number' && body.ttlMs > 0) input.ttlMs = body.ttlMs
|
|
1020
|
+
const { record, superseded } = await memory.reviseRecord(input)
|
|
1021
|
+
const scopeStore = store.peek(record.scope) ?? { embedPending: new Map(), vectors: new Map() }
|
|
1022
|
+
let supersededBy = null
|
|
1023
|
+
for (const other of scopeStore.records.values()) {
|
|
1024
|
+
if (other.supersedes === record.id) { supersededBy = other.id; break }
|
|
1025
|
+
}
|
|
1026
|
+
console.log(`[dsh-memory-panel] 修正记忆 ${superseded} -> ${record.id}`)
|
|
1027
|
+
writeJson(res, { ok: true, value: { record: wireRecord(record, scopeStore, supersededBy), superseded } })
|
|
1028
|
+
return
|
|
1029
|
+
}
|
|
947
1030
|
let target = null
|
|
948
1031
|
for (const s of store.allScopes()) {
|
|
949
1032
|
const rec = s.records.get(id)
|
package/lib/provider/apply.js
CHANGED
|
@@ -151,6 +151,11 @@ export class CordisMemoryService extends Service {
|
|
|
151
151
|
return this.impl.createRecord(input)
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
+
/** 面板编辑:新建一条修正版并通过 supersedes 指向旧记录(0.23.0)。 */
|
|
155
|
+
reviseRecord(input ) {
|
|
156
|
+
return this.impl.reviseRecord(input)
|
|
157
|
+
}
|
|
158
|
+
|
|
154
159
|
/** 面板导出:纯文本 + 元数据,不含向量。 */
|
|
155
160
|
exportAll() {
|
|
156
161
|
return this.impl.exportAll()
|
|
@@ -253,6 +258,31 @@ export class CordisMemoryService extends Service {
|
|
|
253
258
|
return this.impl.isScopeOperable(agent, scope)
|
|
254
259
|
}
|
|
255
260
|
|
|
261
|
+
/** 某个作用域是否可读(0.23.0 的 read 开关)。 */
|
|
262
|
+
isScopeReadable(agent , scope ) {
|
|
263
|
+
return this.impl.isScopeReadable(agent, scope)
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** 某个作用域是否可写(0.23.0 的 write 开关)。 */
|
|
267
|
+
isScopeWritable(agent , scope ) {
|
|
268
|
+
return this.impl.isScopeWritable(agent, scope)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** 当前工作区 key(= 会话 cwd 解析出的 project scope)。 */
|
|
272
|
+
workspaceKeyFor(agent ) {
|
|
273
|
+
return this.impl.workspaceKeyFor(agent)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** 面板:当前工作区绑定的作用域。 */
|
|
277
|
+
workspaceBindings(agent ) {
|
|
278
|
+
return this.impl.workspaceBindings(agent)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** 面板:设置当前工作区绑定的作用域。 */
|
|
282
|
+
setWorkspaceBindings(agent , scopes ) {
|
|
283
|
+
return this.impl.setWorkspaceBindings(agent, scopes)
|
|
284
|
+
}
|
|
285
|
+
|
|
256
286
|
/** 某个 scope 下允许的记忆类型(undefined = 不限制)。 */
|
|
257
287
|
visibleKinds(agent , scope ) {
|
|
258
288
|
return this.impl.visibleKinds(agent, scope)
|