Skip to content

Commit 30d7b4d

Browse files
committed
fix(scope): review 观察点——resolver 透传 logger、scopeMultiplier 注释对齐实际语义
#153 观察 1:tools.js/inject.js 的 createScopeResolver 补传 logger: ctx.logger,registry 反查失败时 warnOnce 才有出口(否则静默降级无观测)。观察 2(workspaceRegistry 经 cordis Proxy 访问可能抛错)已有 try/catch 兜底降级 header.cwd,维持现状。观察 3:scopeMultiplier 实际语义=只有确立 foreign(记忆带标注+当前维度可解析+值不等)才吃 ×0.5,未标注行与命中行同列吃 BOOST ×1.25 而非 ×1 中性——常量注释、searchMemories 注释与测试标题三处对齐(行为不变,仅注释与标题)。
1 parent 91a6c00 commit 30d7b4d

7 files changed

Lines changed: 32 additions & 22 deletions

File tree

‎dsh-mneme/lib/inject.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ export function createInjector(ctx, service, settings, config) {
8888
const threshold = config.importanceThreshold ?? 3;
8989
// v0.8.0 A3(issue #17):注入路径的会话 scope 解析——strictScope 硬过滤
9090
// 需要。渲染 ctx 与工具 exec 同形(agent.session),解析器直接复用。
91-
const resolveSessionScope = createScopeResolver({ ctx, config });
91+
// logger 透传:registry 反查失败时 warnOnce 才有出口。
92+
const resolveSessionScope = createScopeResolver({ ctx, config, logger: ctx.logger });
9293

9394
// Bug6: bound the injected memory block. Each entry's content is truncated to
9495
// MAX_CONTENT chars (trailing `…`); the whole block gets a MAX_BLOCK budget

‎dsh-mneme/lib/service.js‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ function scopeKeyOf(v) {
4646
return typeof v === "string" && v.trim() ? v.trim() : null;
4747
}
4848

49-
// v0.8.0 A2(issue #17)scope 检索加权系数:当前会话 scope 两维都命中 → 加成;
50-
// 任一维度带着他 scope → 降权但保留可见(硬过滤是 A3 strictScope)。未标注行
51-
// (NULL)与无法比较的维度恒中性——全局/存量记忆不因加权掉位。系数是模块常量
52-
// 而非配置项:A2 只定性行为,数值要等线上检索质量反馈再调(加配置面=提前优化)。
49+
// v0.8.0 A2(issue #17)scope 检索加权系数:两维都无法确立 foreign 的候选
50+
// (命中行、未标注行、当前侧维度解析不到的行)→ 加成;只有确立了 foreign
51+
// (记忆带标注 + 当前维度可解析 + 值不等)→ 降权但保留可见(硬过滤是 A3
52+
// strictScope)。即未标注行与命中行同列、不吃惩罚,但注意它们吃的是 BOOST
53+
// 而非 ×1 中性。系数是模块常量而非配置项:A2 只定性行为,数值要等线上检索
54+
// 质量反馈再调(加配置面=提前优化)。
5355
const SCOPE_MATCH_BOOST = 1.25;
5456
const SCOPE_FOREIGN_PENALTY = 0.5;
5557

@@ -769,10 +771,11 @@ export function createService({ store, mirror, config, onWrite, logger }) {
769771
.slice(0, lim);
770772
}
771773

772-
// v0.8.0 A2(issue #17):scope 检索加权——当前会话 scope 两维命中的候选
773-
// 加成、带他 scope 的候选降权但保留可见(硬过滤是 A3 strictScope)。未标注
774-
// 行与无法比较的维度恒中性;flag 关或调用方未传 scope 时不动分,排序与
775-
// A2 前逐字节一致。与 epistemic 加权同款收尾:乘分 → 降序 → 截 topK。
774+
// v0.8.0 A2(issue #17):scope 检索加权——两维都无法确立 foreign 的候选
775+
// (命中/未标注/当前侧解析不到)加成,确立 foreign 的候选降权但保留可见
776+
// (硬过滤是 A3 strictScope);未标注行与命中行同列吃 BOOST、不被压制。
777+
// flag 关或调用方未传 scope 时不动分,排序与 A2 前逐字节一致。与
778+
// epistemic 加权同款收尾:乘分 → 降序 → 截 topK。
776779
if (config.scopeEnabled === true && scope && (scope.agent_scope || scope.workspace_scope)) {
777780
result = result
778781
.map((m) => ({ ...m, score: (m.score ?? 0) * scopeMultiplier(m, scope) }))

‎dsh-mneme/lib/tools.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ export function createTools(ctx, service, config, embedder) {
7373
}
7474
// v0.8.0 A1/A2(issue #17):会话 scope 解析(agentPreset + workspace 反查)。
7575
// flag 关闭时恒返回 null——写入不标注,检索不加权,行为与 A1 前完全一致。
76-
const resolveSessionScope = createScopeResolver({ ctx, config });
76+
// logger 透传:registry 反查失败时 warnOnce 才有出口(否则静默降级无观测)。
77+
const resolveSessionScope = createScopeResolver({ ctx, config, logger: ctx.logger });
7778
const tools = [
7879
defineTool({
7980
name: "memory_save",

‎dsh-mneme/src/inject.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ export function createInjector(ctx, service, settings, config) {
8888
const threshold = config.importanceThreshold ?? 3;
8989
// v0.8.0 A3(issue #17):注入路径的会话 scope 解析——strictScope 硬过滤
9090
// 需要。渲染 ctx 与工具 exec 同形(agent.session),解析器直接复用。
91-
const resolveSessionScope = createScopeResolver({ ctx, config });
91+
// logger 透传:registry 反查失败时 warnOnce 才有出口。
92+
const resolveSessionScope = createScopeResolver({ ctx, config, logger: ctx.logger });
9293

9394
// Bug6: bound the injected memory block. Each entry's content is truncated to
9495
// MAX_CONTENT chars (trailing `…`); the whole block gets a MAX_BLOCK budget

‎dsh-mneme/src/service.js‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ function scopeKeyOf(v) {
4646
return typeof v === "string" && v.trim() ? v.trim() : null;
4747
}
4848

49-
// v0.8.0 A2(issue #17)scope 检索加权系数:当前会话 scope 两维都命中 → 加成;
50-
// 任一维度带着他 scope → 降权但保留可见(硬过滤是 A3 strictScope)。未标注行
51-
// (NULL)与无法比较的维度恒中性——全局/存量记忆不因加权掉位。系数是模块常量
52-
// 而非配置项:A2 只定性行为,数值要等线上检索质量反馈再调(加配置面=提前优化)。
49+
// v0.8.0 A2(issue #17)scope 检索加权系数:两维都无法确立 foreign 的候选
50+
// (命中行、未标注行、当前侧维度解析不到的行)→ 加成;只有确立了 foreign
51+
// (记忆带标注 + 当前维度可解析 + 值不等)→ 降权但保留可见(硬过滤是 A3
52+
// strictScope)。即未标注行与命中行同列、不吃惩罚,但注意它们吃的是 BOOST
53+
// 而非 ×1 中性。系数是模块常量而非配置项:A2 只定性行为,数值要等线上检索
54+
// 质量反馈再调(加配置面=提前优化)。
5355
const SCOPE_MATCH_BOOST = 1.25;
5456
const SCOPE_FOREIGN_PENALTY = 0.5;
5557

@@ -769,10 +771,11 @@ export function createService({ store, mirror, config, onWrite, logger }) {
769771
.slice(0, lim);
770772
}
771773

772-
// v0.8.0 A2(issue #17):scope 检索加权——当前会话 scope 两维命中的候选
773-
// 加成、带他 scope 的候选降权但保留可见(硬过滤是 A3 strictScope)。未标注
774-
// 行与无法比较的维度恒中性;flag 关或调用方未传 scope 时不动分,排序与
775-
// A2 前逐字节一致。与 epistemic 加权同款收尾:乘分 → 降序 → 截 topK。
774+
// v0.8.0 A2(issue #17):scope 检索加权——两维都无法确立 foreign 的候选
775+
// (命中/未标注/当前侧解析不到)加成,确立 foreign 的候选降权但保留可见
776+
// (硬过滤是 A3 strictScope);未标注行与命中行同列吃 BOOST、不被压制。
777+
// flag 关或调用方未传 scope 时不动分,排序与 A2 前逐字节一致。与
778+
// epistemic 加权同款收尾:乘分 → 降序 → 截 topK。
776779
if (config.scopeEnabled === true && scope && (scope.agent_scope || scope.workspace_scope)) {
777780
result = result
778781
.map((m) => ({ ...m, score: (m.score ?? 0) * scopeMultiplier(m, scope) }))

‎dsh-mneme/src/tools.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ export function createTools(ctx, service, config, embedder) {
7373
}
7474
// v0.8.0 A1/A2(issue #17):会话 scope 解析(agentPreset + workspace 反查)。
7575
// flag 关闭时恒返回 null——写入不标注,检索不加权,行为与 A1 前完全一致。
76-
const resolveSessionScope = createScopeResolver({ ctx, config });
76+
// logger 透传:registry 反查失败时 warnOnce 才有出口(否则静默降级无观测)。
77+
const resolveSessionScope = createScopeResolver({ ctx, config, logger: ctx.logger });
7778
const tools = [
7879
defineTool({
7980
name: "memory_save",

‎dsh-mneme/test/scope-retrieval.test.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ test("searchMemories weighting is off entirely when the flag is off", async () =
9898
assert.deepEqual(rows.map((m) => m.title), ["alpha needle", "beta"]);
9999
});
100100

101-
test("unscoped rows stay neutral under weighting (global memories keep their rank)", async () => {
101+
test("unscoped rows rank with matched rows under weighting (never suppressed)", async () => {
102102
const store = createStore(":memory:");
103103
const service = createService({ store, mirror: null, config: { scopeEnabled: true } });
104104
store.save({ type: "project", title: "global needle", content: "x" });
@@ -107,7 +107,7 @@ test("unscoped rows stay neutral under weighting (global memories keep their ran
107107
mode: "keyword",
108108
scope: { agent_scope: "me", workspace_scope: null }
109109
});
110-
// global 行命中 ×1.25,foreign 行 ×0.5——未标注行不该被任何会话的加权压掉。
110+
// 未标注行与命中行同列吃 BOOST(×1.25),foreign 行 ×0.5——不被任何会话压掉。
111111
assert.deepEqual(rows.map((m) => m.title), ["global needle", "foreign"]);
112112
});
113113

0 commit comments

Comments
 (0)