Skip to content

Commit d09041c

Browse files
committed
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)
1 parent 5f20fd1 commit d09041c

6 files changed

Lines changed: 138 additions & 73 deletions

File tree

‎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/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

‎dsh-mneme/src/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) {

0 commit comments

Comments
 (0)