Skip to content

Commit 258b619

Browse files
authored
feat(scope): strictScope 硬过滤只认显式声明——自动标注降为纯软加权(#170 第 3 步,4.3 已确认) (#173)
* feat(scope): sleep 冲突阶段跨 scope 分流——同内容跨归属对停车人工裁决(issue #170 第 2 步) - scopeKeyOf 从 service.js 上提为 scope.js 共享定义(去重键与配对同钥匙) - lang.js 新增 scopeCandidateReason 双语 reason 模板 - sleep.phaseConflicts:跨 scope 相似对(任一维标注键不等,含 NULL vs 已标注) 一律停车到 conflict_pending(专属 reason),绝不自动裁决——freeze 模式沿用 停车但换 scope reason;非 freeze 模式先停车跨 scope 对、同 scope 对才走 LLM (LLM prompt 里不再出现跨 scope 对);run 摘要带 scopeCandidates 计数 - 复用 #166 冲突待确认队列,不新造界面;同对跨轮去重天然防重复入队 - 测试 +4(scope-candidates.test.js),全量 1007(1006 过 + 1 既有 skip) * fix(scope): 人工已裁决的冲突对不再反复入队——内容变了才重新评审(issue #170 复核项 4) - store.saveConflictPending:同对存在已裁决行且两侧 updated_at 均未晚于 resolved_at 时抑制重报(返回 undefined)——否则跨 scope 对每轮 sleep 原样回来,『保留双方』的决定变成噪声 - sleep.parkPair 与 dream 冻结路径尊重返回值,抑制不计入停车数/摘要 - updated_at 是宽松代理:任何字段更新都会触发重新评审,宁可多看一眼 不静音真冲突 - 测试 +1(裁决后不再入队/改后重入);顺带修正 mock embed 的契约形状 (按输入条数返回等长数组——update 失效缓存后 sleep 回填走 embed()) * test(conflict-freeze): 重写「已解决对再次 pending」用例到新语义(issue #170 复核项 4) 跟随 store 抑制行为:真实记忆行 + 裁决后未变化被抑制 + 内容变化后重入。 旧用例用不存在的假 id,撞上抑制路径返回 undefined(CI 实抓)。 * fix(scope): 普通 dream 的跨 scope conflict 决策停车人工裁决(issue #170 复核项 3) - sleep 路径(scope-candidate-queue)拦截了跨 scope 相似对,但普通 dream 的 LLM 看得到全部记忆、可直接 conflict 归档别的 scope 的唯一副本——保护缺位 - dream.js:conflict 决策按 winner/loser 的 scope 键分流——跨 scope 对两种 模式都停车 conflict_pending(scopeConflictParkReason 专属 reason + 模型 裁决理由),绝不进 applyDecisions;同 scope 对照旧(freeze 停车/非 freeze 自动裁决) - 测试 +2:跨 scope 停车(loser 不归档/winner 无批注)+ 同 scope 照常裁决回归 * feat(scope): strictScope 硬过滤只认显式声明——自动标注降为纯软加权(issue #170 第 3 步,4.3 已确认) - service.isVisibleInScope:硬墙条件收窄为「该维有标注且来源=explicit」; auto 与 v0.8.0 存量 NULL 来源行不进硬过滤(A2 foreign ×0.5 软加权保留可见) - store.list/count 两处 visibility SQL 同口径收窄(IS NOT 为 NULL 安全比较); fail-closed 语义随之收窄:匿名会话只挡 explicit 行,不误杀软标注 - 面板 strictScope hint 双语对齐新语义(只对显式声明生效;物理隔离仍指 sensitivity)——回应 heptaspirit 对「严格隔离」命名易误读的意见 - scope-strict.test.js 重写到新语义(10 项:三态硬/软、混合来源、fail-closed 收窄、无存在性泄漏),全量 1008(1007 过 + 1 既有 skip) * docs(readme): strictScope 口径对齐 explicit-only 语义(issue #170 复核项 1) - 内层 README:特性表与 strictScope 配置行改为「显式声明收窄的归属硬隔离; 载体自动标注只降权;物理隔离请用 sensitivity」;配置行标注 v0.8.1 起语义 - 根 README 中英:特性段与快速配置表同步(explicit hard blocking only) - 历史 changelog/路线图行保持原样(如实描述 v0.8.0 已发布行为,0.8.1 变化 留待发版说明) - conflict-freeze.test.js:重写「已解决对再次 pending」用例到新语义 (裁决后未变化被抑制,内容变化后重入) * fix(scope): memory_update/memory_delete 补 strictScope 可见性校验——与 memory_get 对齐(issue #170 复核项 4) - get 按「不存在」拒绝他 scope 的 explicit 行,update/delete 却能凭 id 直改 直删——补齐同款无存在性泄漏:strictScope 下不可见行 update 抛 not found、 delete 视作不存在;auto/存量行不构成硬墙照常可操作(与 get 同口径) - 工具层实现为 createTools 闭包内共享 guard(update 以「展开恒为 undefined」 形态前置校验);strictScope 关时零行为变化 - 测试 +1:explicit 拒改拒删/auto 可改/owner 可改/flag 关回归
1 parent 79eb8a5 commit 258b619

10 files changed

Lines changed: 229 additions & 85 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
- 🧾 **可回放、可追责** — 每次自动整理都留一张「决策凭证」:输入快照 + 决策明细 + 结果哈希,同样的整理可复现回放,**不默默吞错、不留无法追溯的改动**。
4747
- ⚖️ **矛盾先冻结,等你裁决**(可关)— 两条记忆打架时,不擅自替你做主。可疑冲突会**挂起待审**,状态页冲突队列里并排对比、一键裁决(保留 A / 保留 B / 仅标记),确认后才生效。复杂判断,人永远在线。
48-
- 🔐 **记忆按 agent 与工作区隔离**(可关)— `scopeEnabled` 开启后,每条记忆标注由哪个 agent、在哪个工作区写入;检索时本会话作用域优先(命中加权,他 scope 降权仍可见);`strictScope` 再进一步——带他者作用域的记忆在检索/注入里完全不可见。多 Agent、多项目互不串台。
48+
- 🔐 **记忆按 agent 与工作区隔离**(可关)— `scopeEnabled` 开启后,每条记忆标注由哪个 agent、在哪个工作区写入;检索时本会话作用域优先(命中加权,他 scope 降权仍可见);`strictScope` 再进一步——**显式声明**收窄到他者作用域的记忆在检索/注入里完全不可见(载体自动标注只降权,不硬挡)。多 Agent、多项目互不串台。
4949
- 🌙 **夜深人静才动手**(可关)— 空闲时自动分层归档:常看的留在热区、久不用的压成摘要、陈旧的彻底归档。记忆库**越用越精炼,不膨胀**。
5050
- 🧠 **本地语义检索,默认离线** — 自带本地 Embedding 与精排,不强求 API Key,网络断了也能检索。
5151
- 📝 **Markdown 双向同步** — 记忆就是本地 `.md` 文件,随时打开编辑;**人工改动会被优先尊重**,不会被机器覆盖。
@@ -72,7 +72,7 @@ dsh web
7272
| 完全离线运行 | `embedProvider` | `openai` | 改为 `local` |
7373
| 删除对话时保留记忆 | `sessionLifecycleEnabled` | `false` | 改为 `true` |
7474
| 自动提取结构化实体 | `entityExtractionEnabled` | `false` | 改为 `true` |
75-
| 多 Agent / 多项目记忆隔离 | `scopeEnabled`(硬隔离再加 `strictScope`) | `false` | 改为 `true` |
75+
| 多 Agent / 多项目记忆隔离 | `scopeEnabled`(需要更强隔离再加 `strictScope`,硬隔离只对显式声明生效) | `false` | 改为 `true` |
7676

7777
> 以上均在 DSH 设置面板 → 记忆库设置 中修改。完整配置见 [配置章节](dsh-mneme/README.md)。
7878
@@ -205,7 +205,7 @@ Every time you start a new chat, the AI acts like it's never met you?
205205

206206
- 🧾 **Replayable, accountable** — every consolidation leaves a "decision receipt": input snapshot + decision detail + result hash. The same run reproduces the same outcome. **No silent mis-merges, no untraceable changes.**
207207
- ⚖️ **Conflicts freeze, you decide** (opt-in) — when two memories contradict, it does not take sides for you. The suspected conflict is **parked for review**, compared side-by-side in the status-page conflict queue, and resolved with one click (keep A / keep B / mark reviewed). On hard judgments, a human stays in the loop.
208-
- 🔐 **Memories isolated by agent & workspace** (opt-in) — with `scopeEnabled`, every memory is stamped with which agent wrote it and in which workspace; retrieval favors the current scope (weighted hits, out-of-scope demoted but visible); `strictScope` goes further — memories scoped to other agents/workspaces become invisible to search and injection. Multiple agents and projects, zero cross-talk.
208+
- 🔐 **Memories isolated by agent & workspace** (opt-in) — with `scopeEnabled`, every memory is stamped with which agent wrote it and in which workspace; retrieval favors the current scope (weighted hits, out-of-scope demoted but visible); `strictScope` goes further — memories **explicitly** scoped to other agents/workspaces become invisible to search and injection (auto carrier labels are demoted only, never hard-blocked). Multiple agents and projects, zero cross-talk.
209209
- 🌙 **It works while you sleep** (opt-in) — idle time triggers tiered archiving: frequent memories stay hot, stale ones compress to summaries, old ones archive. The store **stays lean as it grows**.
210210
- 🧠 **Local semantic search, offline by default** — built-in local Embedding + reranking. No API key required; retrieval still works without a network.
211211
- 📝 **Two-way Markdown sync** — memories are local `.md` files you can open and edit; **human edits are respected**, never clobbered by the machine.
@@ -232,7 +232,7 @@ It works out of the box. To feel its value in five minutes:
232232
| Fully offline | `embedProvider` | `openai` | Change to `local` |
233233
| Keep memories when deleting sessions | `sessionLifecycleEnabled` | `false` | Change to `true` |
234234
| Structured entity extraction | `entityExtractionEnabled` | `false` | Change to `true` |
235-
| Memory isolation per agent / workspace | `scopeEnabled` (hard isolation: add `strictScope`) | `false` | Change to `true` |
235+
| Memory isolation per agent / workspace | `scopeEnabled` (add `strictScope` for stronger isolation — hard blocking applies to explicit declarations only) | `false` | Change to `true` |
236236

237237
> All of these live in DSH Settings → Memory Settings. Full config docs in the [Configuration section](dsh-mneme/README.md) (Chinese, bilingual file).
238238

‎dsh-mneme/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
| ① 写入 | ② 存储 | ③ 进化 |
2323
|--------|--------|--------|
24-
| 对话中模型主动记录(`memory_save`,可带敏感度与事件时间);会话结束自动提炼(`autoSummarize`) | SQLite 主库 + 人类可编辑 Markdown 镜像;实体 / 属性 / 时间轴三层结构化;记忆带 agent / workspace / 敏感度 / 发生时间标注 | 新会话自动注入相关记忆(按当前作用域加权,strictScope 开启后硬隔离);autoDream 后台去重 / 合并 / 归档,冲突冻结待人工裁决 |
24+
| 对话中模型主动记录(`memory_save`,可带敏感度与事件时间);会话结束自动提炼(`autoSummarize`) | SQLite 主库 + 人类可编辑 Markdown 镜像;实体 / 属性 / 时间轴三层结构化;记忆带 agent / workspace / 敏感度 / 发生时间标注 | 新会话自动注入相关记忆(按当前作用域加权,strictScope 开启后显式收窄的归属硬隔离);autoDream 后台去重 / 合并 / 归档,冲突冻结待人工裁决 |
2525

2626
```bash
2727
# 30 秒上手
@@ -461,7 +461,7 @@ dsh web
461461
| `memoryQualityFilter` | `{enabled:true, archiveThreshold:30, degradeThreshold:60, minContentLength:10, exemptImportance:4}` | 记忆质量过滤(v0.4.6,默认开):写库前启发式打分 0-100,元记忆词汇/自指/过短/重复/近似重复扣分;≥60 正常存储,30-60 降权(注入排序按 importance×quality/100),<30 归档标记 `low_quality`(显式搜索仍可召回,永不自动注入;`exemptImportance` 豁免:importance ≥ 该值只降权不归档,#135) |
462462
| `llmAudit` | `{enabled:true, retentionDays:90}` | LLM 消耗审计(v0.4.6,默认开):每次后台 LLM 调用(autoDream/autoSummarize)写 `llm_audit_logs`(tokens/duration/status/source);失败记 error 不阻塞;只读 API `/api/dsh-mneme/semantic/llm-audit` + `/llm-audit/stats` |
463463
| `scopeEnabled` | `false` | 作用域隔离总开关(v0.8.0,issue #17):memory_save 按会话身份写入 agent / workspace 标注(agentPreset / 工作区路径,registry 反查取不到回退 header.cwd,再取不到 NULL);去重键扩展含作用域三元——跨作用域同标题不再物理合并;检索按当前会话作用域加权(命中 ×1.25、他 scope ×0.5 保留可见)。也走 feature_flags 白名单(面板可启停) |
464-
| `strictScope` | `false` | 作用域硬过滤(v0.8.0,依赖 `scopeEnabled`):检索 / 注入 / 列表 / 单取四路过滤,带他者作用域的记忆完全不可见;会话身份解析不到时 fail-closed 只见未标注行。关闭时为软隔离(降权保留可见)。也走 feature_flags 白名单 |
464+
| `strictScope` | `false` | 作用域硬过滤(v0.8.0 引入,v0.8.1 起只认显式声明;依赖 `scopeEnabled`):检索 / 注入 / 列表 / 单取四路过滤,**显式声明**收窄到他者作用域的记忆完全不可见;载体自动标注只降权保留可见——真正的物理隔离请用 sensitivity。会话身份解析不到时 fail-closed 只挡显式行。关闭时全部为软隔离(降权保留可见)。也走 feature_flags 白名单 |
465465
| `conflictFreezeEnabled` | `false` | 冲突冻结(v0.4.4):dream 发现矛盾对不自动裁决,冻结进冲突队列;状态页「冲突队列」支持并排对比与人工确认(保留 A / 保留 B / 仅标记已处理,v0.8.0) |
466466
| `escapePromptVariables` | `true` | 注入文本花括号转义(v0.8.0 恢复,issue #162):注入边界把 `{{...}}` 转义,防止 hot memory / 记忆原文里的 Go template / Vue 语法触发宿主 interpolate 抛错卡死会话(v0.7.4 曾修复、v0.7.11 误删) |
467467

‎dsh-mneme/lib/client.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ window.__ModuleLoader__.load({
351351
"memory.features.scopeEnabled": "作用域标注",
352352
"memory.features.scopeEnabled.hint": "按会话身份(agent/工作区)给新记忆打归属标注;重启 DSH 后生效",
353353
"memory.features.strictScope": "严格隔离",
354-
"memory.features.strictScope.hint": "检索与注入硬过滤:带他者作用域的记忆完全不可见(关闭时仅降权保留可见);重启 DSH 后生效",
354+
"memory.features.strictScope.hint": "检索与注入硬过滤,只对显式声明的归属生效:显式收窄到他者作用域的记忆不可见;载体自动标注只降权保留可见(真正的物理隔离请用 sensitivity)。重启 DSH 后生效",
355355
"memory.features.trustEpistemicWeighting": "可信度加权",
356356
"memory.features.trustEpistemicWeighting.hint": "按来源可信度调整召回排序(实验性)",
357357
"memory.features.reflectionFailureTracking": "反思失败追踪",
@@ -698,7 +698,7 @@ window.__ModuleLoader__.load({
698698
"memory.features.scopeEnabled": "Scope tagging",
699699
"memory.features.scopeEnabled.hint": "Stamp new memories with the writing session's identity (agent/workspace); takes effect after restarting DSH",
700700
"memory.features.strictScope": "Strict isolation",
701-
"memory.features.strictScope.hint": "Hard-filter search and injection: memories scoped to other agents/workspaces become invisible (off = demoted but visible); takes effect after restarting DSH",
701+
"memory.features.strictScope.hint": "Hard-filter search and injection for EXPLICITLY declared scopes only: memories explicitly narrowed to other agents/workspaces become invisible; auto carrier labels are demoted but stay visible (use sensitivity for true physical isolation). Takes effect after restarting DSH",
702702
"memory.features.trustEpistemicWeighting": "Credibility weighting",
703703
"memory.features.trustEpistemicWeighting.hint": "Adjust recall ranking by source credibility (experimental)",
704704
"memory.features.reflectionFailureTracking": "Reflection failure tracking",

‎dsh-mneme/lib/service.js‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,18 @@ function inOccurredBounds(m, bounds) {
9090
* 留给后续批次)。store.list 的 SQL 过滤与此谓词同口径(见 store.js visibility)。
9191
*/
9292
function isVisibleInScope(m, current) {
93-
const agent = scopeKeyOf(m.agent_scope);
94-
if (agent !== null && (current.agent_scope === null || agent !== current.agent_scope)) return false;
95-
const ws = scopeKeyOf(m.workspace_scope);
96-
if (ws !== null && (current.workspace_scope === null || ws !== current.workspace_scope)) return false;
93+
// v0.8.1 第 3 步(issue #170 4.3,作者已确认):硬过滤只认显式声明。某维
94+
// 仅当「该维有标注且来源为 explicit」才构成硬墙;auto(含 v0.8.0 存量的
95+
// NULL 来源行)只吃 A2 软加权(foreign ×0.5 保留可见),不进硬过滤。
96+
// 显式全局(值 NULL + source explicit)与未标注同形,天然恒可见。
97+
if (m.agent_scope_source === "explicit") {
98+
const agent = scopeKeyOf(m.agent_scope);
99+
if (agent !== null && (current.agent_scope === null || agent !== current.agent_scope)) return false;
100+
}
101+
if (m.workspace_scope_source === "explicit") {
102+
const ws = scopeKeyOf(m.workspace_scope);
103+
if (ws !== null && (current.workspace_scope === null || ws !== current.workspace_scope)) return false;
104+
}
97105
return true;
98106
}
99107

‎dsh-mneme/lib/store.js‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -773,17 +773,20 @@ export function createStore(path) {
773773
// occurred_at 闭区间:与 list() 同过滤(visibility 同口径),memory_list
774774
// 的 total 才能和过滤后的行保持一致。
775775
if (visibility) {
776+
// v0.8.1 第 3 步(issue #170 4.3):硬过滤只认显式声明——与
777+
// service.isVisibleInScope 同口径。IS NOT 是 NULL 安全比较:来源为
778+
// auto/NULL(v0.8.0 存量自动标注)的行不吃硬墙,只走 A2 软加权。
776779
if (visibility.agentScope != null) {
777-
clauses.push("(agent_scope IS NULL OR agent_scope = ?)");
780+
clauses.push("(agent_scope IS NULL OR agent_scope_source IS NOT 'explicit' OR agent_scope = ?)");
778781
params.push(visibility.agentScope);
779782
} else {
780-
clauses.push("agent_scope IS NULL");
783+
clauses.push("(agent_scope IS NULL OR agent_scope_source IS NOT 'explicit')");
781784
}
782785
if (visibility.workspaceScope != null) {
783-
clauses.push("(workspace_scope IS NULL OR workspace_scope = ?)");
786+
clauses.push("(workspace_scope IS NULL OR workspace_scope_source IS NOT 'explicit' OR workspace_scope = ?)");
784787
params.push(visibility.workspaceScope);
785788
} else {
786-
clauses.push("workspace_scope IS NULL");
789+
clauses.push("(workspace_scope IS NULL OR workspace_scope_source IS NOT 'explicit')");
787790
}
788791
}
789792
if (!includeForgotten) {
@@ -1122,21 +1125,25 @@ export function createStore(path) {
11221125
params.push(occurred.to);
11231126
}
11241127
// v0.8.0 A3(issue #17):strictScope 硬过滤(memory_list 分页路径)。
1125-
// SQL 与 service.isVisibleInScope 同口径:未标注(NULL)恒可见;当前维度
1126-
// 解析不到时该维度只放行未标注行(fail-closed)。只有显式传 visibility
1127-
// 的用户面调用才过滤——dream/质量过滤等内部 store.list 调用不受影响。
1128+
// SQL 与 service.isVisibleInScope 同口径:未标注(NULL)恒可见;v0.8.1 起
1129+
// 硬墙只认 explicit 来源(4.3),当前维度解析不到时该维度只放行未标注/
1130+
// 非显式行(fail-closed 收窄)。只有显式传 visibility 的用户面调用才
1131+
// 过滤——dream/质量过滤等内部 store.list 调用不受影响。
11281132
if (visibility) {
1133+
// v0.8.1 第 3 步(issue #170 4.3):硬过滤只认显式声明——与
1134+
// service.isVisibleInScope 同口径。IS NOT 是 NULL 安全比较:来源为
1135+
// auto/NULL(v0.8.0 存量自动标注)的行不吃硬墙,只走 A2 软加权。
11291136
if (visibility.agentScope != null) {
1130-
clauses.push("(agent_scope IS NULL OR agent_scope = ?)");
1137+
clauses.push("(agent_scope IS NULL OR agent_scope_source IS NOT 'explicit' OR agent_scope = ?)");
11311138
params.push(visibility.agentScope);
11321139
} else {
1133-
clauses.push("agent_scope IS NULL");
1140+
clauses.push("(agent_scope IS NULL OR agent_scope_source IS NOT 'explicit')");
11341141
}
11351142
if (visibility.workspaceScope != null) {
1136-
clauses.push("(workspace_scope IS NULL OR workspace_scope = ?)");
1143+
clauses.push("(workspace_scope IS NULL OR workspace_scope_source IS NOT 'explicit' OR workspace_scope = ?)");
11371144
params.push(visibility.workspaceScope);
11381145
} else {
1139-
clauses.push("workspace_scope IS NULL");
1146+
clauses.push("(workspace_scope IS NULL OR workspace_scope_source IS NOT 'explicit')");
11401147
}
11411148
}
11421149
if (!includeForgotten) {

‎dsh-mneme/lib/tools.js‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,26 @@ export function createTools(ctx, service, config, embedder) {
7979
// flag 关闭时恒返回 null——写入不标注,检索不加权,行为与 A1 前完全一致。
8080
// logger 透传:registry 反查失败时 warnOnce 才有出口(否则静默降级无观测)。
8181
const resolveSessionScope = createScopeResolver({ ctx, config, logger: ctx.logger });
82+
83+
// 复核项 4(issue #170):strictScope 下他 scope(explicit)的行对工具侧按
84+
// 「不存在」处理——update/delete 与 memory_get 同款无存在性泄漏。strictScope
85+
// 关、或会话身份取不到(scope 为 null)时恒可见(与 get 的短路语义一致)。
86+
const visibleUnderStrictScope = (memory, exec) => {
87+
if (config?.strictScope !== true) return true;
88+
const scope = resolveSessionScope(exec);
89+
return !scope || service.isVisibleInScope(memory, scope);
90+
};
91+
// 在调用点以「展开恒为 undefined」的形态前置校验(抛错即中止写入)。
92+
const assertVisibleForTool = (id, exec) => {
93+
const memory = id ? service.getById(id) : undefined;
94+
if (!visibleUnderStrictScope(memory, exec)) throw new Error("memory not found");
95+
return undefined;
96+
};
97+
// delete 侧需要目标行本身判断存在性(不可见 = 视作不存在,不抛错)。
98+
const visibleForTool = (id, exec) => {
99+
const memory = id ? service.getById(id) : undefined;
100+
return visibleUnderStrictScope(memory, exec) ? memory : undefined;
101+
};
82102
const tools = [
83103
defineTool({
84104
name: "memory_save",
@@ -336,6 +356,9 @@ export function createTools(ctx, service, config, embedder) {
336356
type: args.type,
337357
tags: args.tags,
338358
importance: args.importance,
359+
// 复核项 4(#170):strictScope 下他 scope 的行按「不存在」处理(与 get 对齐),
360+
// 展开恒为 undefined,仅承担写入前校验。
361+
...(assertVisibleForTool(args.id, arguments[1])),
339362
...(args.agent_scope !== undefined ? { agent_scope: args.agent_scope } : {}),
340363
...(args.workspace_scope !== undefined ? { workspace_scope: args.workspace_scope } : {})
341364
}, { query: args.reason });
@@ -358,9 +381,10 @@ export function createTools(ctx, service, config, embedder) {
358381
render: (_args, value) => TEXT_OUTPUT(value.deleted ? "Memory deleted." : "Memory not found.")
359382
},
360383
async execute(args) {
361-
const existed = service.getById(args.id) !== undefined;
362-
if (existed) service.remove(args.id);
363-
return { deleted: existed };
384+
// 复核项 4(#170):不可见(explicit 他 scope)= 视作不存在,无存在性泄漏。
385+
const target = visibleForTool(args.id, arguments[1]);
386+
if (target) service.remove(args.id);
387+
return { deleted: !!target };
364388
}
365389
}),
366390

‎dsh-mneme/src/service.js‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,18 @@ function inOccurredBounds(m, bounds) {
9090
* 留给后续批次)。store.list 的 SQL 过滤与此谓词同口径(见 store.js visibility)。
9191
*/
9292
function isVisibleInScope(m, current) {
93-
const agent = scopeKeyOf(m.agent_scope);
94-
if (agent !== null && (current.agent_scope === null || agent !== current.agent_scope)) return false;
95-
const ws = scopeKeyOf(m.workspace_scope);
96-
if (ws !== null && (current.workspace_scope === null || ws !== current.workspace_scope)) return false;
93+
// v0.8.1 第 3 步(issue #170 4.3,作者已确认):硬过滤只认显式声明。某维
94+
// 仅当「该维有标注且来源为 explicit」才构成硬墙;auto(含 v0.8.0 存量的
95+
// NULL 来源行)只吃 A2 软加权(foreign ×0.5 保留可见),不进硬过滤。
96+
// 显式全局(值 NULL + source explicit)与未标注同形,天然恒可见。
97+
if (m.agent_scope_source === "explicit") {
98+
const agent = scopeKeyOf(m.agent_scope);
99+
if (agent !== null && (current.agent_scope === null || agent !== current.agent_scope)) return false;
100+
}
101+
if (m.workspace_scope_source === "explicit") {
102+
const ws = scopeKeyOf(m.workspace_scope);
103+
if (ws !== null && (current.workspace_scope === null || ws !== current.workspace_scope)) return false;
104+
}
97105
return true;
98106
}
99107

0 commit comments

Comments
 (0)