Skip to content

Commit 8c45d7d

Browse files
authored
Merge pull request #650 from slow-stack/feat/641-conflict-enforce
feat(recall): 取代链检索降权 + 矛盾感知(#641 beta 第三阶段续)
2 parents 6a557f5 + 66a88c5 commit 8c45d7d

25 files changed

Lines changed: 1467 additions & 70 deletions

‎SECURITY.md‎

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

‎dsh-mneme/docs/CONFIGURATION.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@
269269
| `conflictFreezeMaxPending` | `100` | 冻结队列上限(≤1000) | — |
270270
| `conflictAutoResolveEnabled` | `false` | 相似度极高的**同 scope** 重复对自动裁决(保留新条、归档旧条),不进人工队列 | opt-in。会归档记忆,所以默认关;跨 scope 对永不自动(归属是用户的决定,#170)。用 supersede 而非 conflict:注记写在被归档侧,幸存记忆正文不动 |
271271
| `conflictAutoResolveMinSimilarity` | `0.95` | 自动裁决的相似度门槛(0.85–1) | 实测 live 库 345 条有相似度的历史行里 ≥0.95 只占 5.8%、≥0.94 占 8.1%——这一档减的是峰值,不是把队列清零。低于 0.85 就不是「重复」而是「相似」,不该自动归档任何一条 |
272-
| `conflictLedgerMode` | `off` | 冲突分诊账本档位(`off` / `shadow`) | beta 第一阶段(#641)。`shadow` = 每轮巩固对冲突候选对做确定性分诊(近重复/跨作用域/演进/真矛盾四档,判据见 `src/dream/triage.js`)并落 `conflict_ledger` 账本,**冻结/LLM 路径零变化**——先测一周真实分布,预注册判据过了才切 enforce(处置接线在后续 PR)。现阶段枚举里没有 enforce:不存在「设了但没行为」的档位。不进 lightMode 强制关闭清单:shadow 只多一张 bookkeeping 表的写入,无 LLM 调用无注入物(同 `actionPipelineEnabled` 的定性) |
272+
| `conflictLedgerMode` | `off` | 冲突分诊账本档位(`off` / `shadow` / `enforce`) | beta(#641)。`shadow` = 每轮巩固对冲突候选对做确定性分诊(近重复/跨作用域/演进/真矛盾四档,判据见 `src/dream/triage.js`)并落 `conflict_ledger` 账本,**冻结/LLM 路径零变化**——先测一周真实分布再切档。`enforce` = 确定性处置:近重复对走信息量优先 supersede(败者归档、胜者正文不动),跨作用域重复与真矛盾只记账(不停车、不送 LLM、不动正文),时序演进落取代链(旧行 `superseded_by`/`superseded_at` 指向新行,两行都留着、正文都不动,检索侧降权),人审队列消失。与 `conflictFreezeEnabled` 同开时 freeze 让位(降级 + warn,#616 父子绑定不继承)。不进 lightMode 强制关闭清单:shadow 只多一张 bookkeeping 表的写入,enforce 零 LLM 调用(同 `actionPipelineEnabled` 的定性) |
273273
| `conflictLedgerDupMinSimilarity` | `0.9` | 分诊 T1(近重复)档的相似度下限(0.85–1) | 检测阈值(0.85)与自动档(0.95)之间的空带由它接管:真实库 788 对的相似度回声集中在 0.85–0.93,恰好是自动档开了也接不住的那段 |
274274

275275
## 实体

‎dsh-mneme/lib/api.js‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2318,6 +2318,38 @@ export function createApi(ctx, service, settings, commands, embedder, semantic =
23182318
}
23192319
});
23202320

2321+
// GET /conflicts/ledger(issue #641,beta 第三阶段):矛盾分诊账本的只读面——
2322+
// 分诊分布(按 tier 计数)+ 最近账本行。conflict_ledger 是 bookkeeping 表,
2323+
// 这里的行不是待办(处置由 enforce 档自动完成),面板只回答「账本里有什么、
2324+
// 分布如何」。policy 与 /conflicts 同级(token):行带标题级信息与检出时间,
2325+
// 不该对未持 token 的本地进程开放。
2326+
register({
2327+
kind: "exact",
2328+
path: "/api/dsh-mneme/conflicts/ledger",
2329+
policy: "token",
2330+
handler(req, res) {
2331+
try {
2332+
if (req.method !== "GET") {
2333+
sendJson(res, 404, { error: "not-found" });
2334+
return;
2335+
}
2336+
const url = new URL(req.url, "http://localhost");
2337+
const limit = Math.min(200, Math.max(1, Number(url.searchParams.get("limit") ?? 50) || 50));
2338+
const offset = Math.max(0, Number(url.searchParams.get("offset") ?? 0) || 0);
2339+
const items = service.listConflictLedger({ limit, offset });
2340+
const counts = {
2341+
dup: service.countConflictLedger({ tier: "dup" }),
2342+
"cross-scope-dup": service.countConflictLedger({ tier: "cross-scope-dup" }),
2343+
evolution: service.countConflictLedger({ tier: "evolution" }),
2344+
conflict: service.countConflictLedger({ tier: "conflict" })
2345+
};
2346+
sendJson(res, 200, { items, counts, total: service.countConflictLedger() });
2347+
} catch {
2348+
sendJson(res, 500, { error: "internal" });
2349+
}
2350+
}
2351+
});
2352+
23212353
register({
23222354
kind: "exact",
23232355
path: "/api/dsh-mneme/conflicts/resolve",

‎dsh-mneme/lib/client.js‎

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,11 @@ window.__ModuleLoader__.load({
10581058
"memory.features.bm25SearchEnabled.hint": "关键词一路的词法检索,与语义互补。",
10591059
"memory.features.conflictFreezeEnabled": "矛盾冻结",
10601060
"memory.features.conflictFreezeEnabled.hint": "整理发现矛盾先冻结待确认,不自动裁决。",
1061+
"memory.features.conflictLedgerMode": "矛盾处理档位",
1062+
"memory.features.conflictLedgerMode.hint": "off:矛盾走人审队列(现状)。shadow:分诊只记账零处置,先跑一周看分布。enforce:确定性处置(近重复自动归档、演进落取代链、矛盾注入标注),人审与 LLM 裁决退出。与「矛盾冻结」互斥,同开时冻结让位。",
1063+
"memory.features.conflictLedgerMode.off": "off(人审队列)",
1064+
"memory.features.conflictLedgerMode.shadow": "shadow(只记账)",
1065+
"memory.features.conflictLedgerMode.enforce": "enforce(确定性处置)",
10611066
"memory.features.scopeEnabled": "来源标注",
10621067
"memory.features.scopeEnabled.hint": "每条记忆标上来自哪个 Agent / 工作区。",
10631068
"memory.features.strictScope": "严格隔离",
@@ -1276,6 +1281,15 @@ window.__ModuleLoader__.load({
12761281
"memory.status.conflictQueue.markReviewed": "仅标记已处理",
12771282
"memory.status.conflictQueue.applyHint": "确认后:保留方正文追加已否决注记,另一方归档。",
12781283
"memory.status.conflictQueue.missing": "(该记忆已不存在)",
1284+
"memory.status.ledger.title": "矛盾账本(分诊 · 只读)",
1285+
"memory.status.ledger.dist": "分诊分布:",
1286+
"memory.status.ledger.total": "累计",
1287+
"memory.status.ledger.status": "状态",
1288+
"memory.status.ledger.loadError": "账本加载失败",
1289+
"memory.status.ledger.tier.dup": "近重复",
1290+
"memory.status.ledger.tier.cross-scope-dup": "跨作用域",
1291+
"memory.status.ledger.tier.evolution": "时序演进",
1292+
"memory.status.ledger.tier.conflict": "真矛盾",
12791293
"memory.status.conflictQueue.goto": "查看待确认冲突队列",
12801294
"memory.status.conflictQueue.resolved": "已裁决:保留{name}",
12811295
"memory.status.conflictQueue.refresh": "刷新队列",
@@ -2166,6 +2180,11 @@ window.__ModuleLoader__.load({
21662180
"memory.features.bm25SearchEnabled.hint": "Lexical keyword retrieval alongside semantics.",
21672181
"memory.features.conflictFreezeEnabled": "Conflict freeze",
21682182
"memory.features.conflictFreezeEnabled.hint": "Freezes contradictions for review instead of auto-deciding.",
2183+
"memory.features.conflictLedgerMode": "Conflict handling mode",
2184+
"memory.features.conflictLedgerMode.hint": "off: conflicts go to the human review queue (status quo). shadow: triage only records — zero disposition; run a week and inspect the distribution first. enforce: deterministic resolution (near-dups auto-archived, evolution chained, conflict pairs annotated); human review and LLM adjudication step out. Mutually exclusive with conflict freeze — freeze yields when both are on.",
2185+
"memory.features.conflictLedgerMode.off": "off (review queue)",
2186+
"memory.features.conflictLedgerMode.shadow": "shadow (record only)",
2187+
"memory.features.conflictLedgerMode.enforce": "enforce (deterministic)",
21692188
"memory.features.scopeEnabled": "Scope tagging",
21702189
"memory.features.scopeEnabled.hint": "Tags each memory with its agent/workspace origin.",
21712190
"memory.features.strictScope": "Strict isolation",
@@ -2384,6 +2403,15 @@ window.__ModuleLoader__.load({
23842403
"memory.status.conflictQueue.markReviewed": "Mark reviewed only",
23852404
"memory.status.conflictQueue.applyHint": "On confirm: a veto note is appended to the kept side and the other side is archived.",
23862405
"memory.status.conflictQueue.missing": "(memory no longer exists)",
2406+
"memory.status.ledger.title": "Conflict ledger (triage · read-only)",
2407+
"memory.status.ledger.dist": "Triage distribution:",
2408+
"memory.status.ledger.total": "total",
2409+
"memory.status.ledger.status": "status",
2410+
"memory.status.ledger.loadError": "Ledger failed to load",
2411+
"memory.status.ledger.tier.dup": "Near-dup",
2412+
"memory.status.ledger.tier.cross-scope-dup": "Cross-scope",
2413+
"memory.status.ledger.tier.evolution": "Evolution",
2414+
"memory.status.ledger.tier.conflict": "Conflict",
23872415
"memory.status.conflictQueue.goto": "View pending conflict queue",
23882416
"memory.status.conflictQueue.resolved": "Resolved: kept {name}",
23892417
"memory.status.conflictQueue.refresh": "Refresh queue",
@@ -5236,7 +5264,26 @@ window.__ModuleLoader__.load({
52365264
h(Icon, { name: showAdv ? "chevronDown" : "chevronRight", size: 12 }),
52375265
t("memory.features.advancedToggle"))
52385266
),
5239-
showAdv && FEATURE_ADVANCED_BOOLS.map((k) => boolRow(k))
5267+
showAdv && h(react.Fragment, null,
5268+
FEATURE_ADVANCED_BOOLS.map((k) => boolRow(k)),
5269+
// conflictLedgerMode(#641):三档枚举,紧挨 conflictFreezeEnabled
5270+
// 摆——两者语义关联(enforce 与 freeze 互斥,同开时冻结让位),
5271+
// 隔开摆放会让人以为各自独立。枚举键没有通用渲染器,手写下拉
5272+
// (choroSub 同款)。
5273+
h("div", { className: "mneme-featsub" },
5274+
h("div", { className: "mneme-featnum" },
5275+
h("span", { className: "mneme-featnumlabel" }, t("memory.features.conflictLedgerMode")),
5276+
h("select", {
5277+
className: "mneme-select",
5278+
value: eff.conflictLedgerMode || "off",
5279+
disabled: busy,
5280+
onChange: (e) => put({ conflictLedgerMode: e.target.value })
5281+
},
5282+
["off", "shadow", "enforce"].map((v) => h("option", { key: v, value: v }, t(`memory.features.conflictLedgerMode.${v}`))))
5283+
),
5284+
h("div", { className: "mneme-featsubhint" }, t("memory.features.conflictLedgerMode.hint"))
5285+
)
5286+
)
52405287
)
52415288
);
52425289
})()
@@ -7676,6 +7723,44 @@ window.__ModuleLoader__.load({
76767723
}));
76777724
}
76787725

7726+
// --- 矛盾分诊账本(#641,状态页只读卡)----------------------------------
7727+
// 与上面的冲突队列互补:队列是「等人来」的待办(freeze 模式),账本是
7728+
// 「机器观察/处置过什么」的只读面(shadow 记账、enforce 处置)。行不是
7729+
// 待办——处置由 enforce 档自动完成,这里只回答「账本里有什么、分布如何」。
7730+
// 空账本整块不渲染(与冲突队列同款:不打扰无矛盾实例)。
7731+
function ConflictLedger({ t }) {
7732+
const [data, setData] = useState(null);
7733+
const [loadError, setLoadError] = useState(false);
7734+
const load = () => {
7735+
apiFetch("/api/dsh-mneme/conflicts/ledger?limit=50")
7736+
.then((res) => { if (!res.ok) throw new Error("http"); return res.json(); })
7737+
.then((d) => { setData(d); setLoadError(false); })
7738+
.catch(() => { setData(null); setLoadError(true); });
7739+
};
7740+
useEffect(() => { load(); }, []);
7741+
if (loadError) {
7742+
return h("div", { className: "mneme-statuscard mneme-set-hint" }, t("memory.status.ledger.loadError"));
7743+
}
7744+
if (!data) return null;
7745+
const counts = data.counts || {};
7746+
const total = typeof data.total === "number" ? data.total : 0;
7747+
if (total === 0) return null;
7748+
const tierKey = (v) => "memory.status.ledger.tier." + v;
7749+
const tiers = [["dup"], ["cross-scope-dup"], ["evolution"], ["conflict"]];
7750+
const rows = (data.items || []).slice(0, 8);
7751+
return h("div", { className: "mneme-statuscard" },
7752+
h("div", { className: "mneme-set-h3" }, t("memory.status.ledger.title")),
7753+
h("div", { className: "mneme-set-hint" },
7754+
t("memory.status.ledger.dist")
7755+
+ " " + tiers.map(([k]) => `${t(tierKey(k))} ${counts[k] ?? 0}`).join(" · ")
7756+
+ " · " + t("memory.status.ledger.total") + " " + total),
7757+
h("div", { className: "mneme-conflictq" },
7758+
rows.map((r) => h("div", { key: r.memory_a + "|" + r.memory_b, className: "mneme-conflict-item" },
7759+
h("div", { className: "mneme-conflict-reason" },
7760+
`${t(tierKey(r.tier))} · ${t("memory.status.ledger.status")}: ${r.status} · ${String(r.first_seen_at || "").slice(0, 10)}`))))
7761+
);
7762+
}
7763+
76797764
// --- 状态页工作台:让用户切实看见插件在干活 ---
76807765
// 活动流合并 llm_audit 里 autoDream/autoSummarize 的后台调用(状态、
76817766
// token、沉淀条数);沉淀记忆列表用 audit 行携带的 related_memory_ids
@@ -8099,6 +8184,7 @@ window.__ModuleLoader__.load({
80998184
h("div", { className: "mneme-statushead" }, t("memory.status.sec.maintenance")),
81008185
h("div", { className: "mneme-statusgrid" }, h(MaintenanceCard, { t })),
81018186
h("div", { ref: queueRef }, h(ConflictsQueue, { t })),
8187+
h(ConflictLedger, { t }),
81028188
h(WorkbenchSection, { t, onBrowse })
81038189
);
81048190
}

‎dsh-mneme/lib/config.js‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -595,22 +595,28 @@ export const Config = z.object({
595595
conflictAutoResolveEnabled: z.boolean().default(false),
596596
conflictAutoResolveMinSimilarity: z.number().min(0.85).max(1).default(0.95),
597597

598-
// --- conflict ledger(issue #641,beta 第一阶段)--------------------------
598+
// --- conflict ledger(issue #641,beta)-----------------------------------
599599
// 冲突分诊账本的档位。真实库 788 对人审队列的全量分类:46% 近重复 + 20% 跨作用域
600600
// 重复 + 5% 时序演进,真矛盾只有 ~27%——现行窄 prompt 把前 71% 全逼成了「输赢」,
601601
// 再由人逐对裁决(≈30 条/天,且 92% 的对从未两侧同场)。分诊把「谁该机械处理、
602602
// 谁才是真矛盾」从 LLM 手里拿回来(E13b:winner-take-all 裁决 P(毒胜出)=86.8%)。
603603
//
604-
// "off" 默认。不分类、不记账,conflict 相位与 v0.13.0 逐字节一致。
605-
// "shadow" 只分类 + 落 conflict_ledger 账本(bookkeeping,不触发 write hooks),
606-
// freeze/LLM 路径零变化——beta 实验的测量期:shadow 一周拿真实分诊
607-
// 分布,验证是否复现 46/20/5/27,预注册判据过了才切 enforce(处置接线
608-
// 是后续 PR:T1 送合并、T2 去重账本、T3 取代链、T4 惰性消解)。
604+
// "off" 默认。不分类、不记账,conflict 相位与本键引入前逐字节一致。
605+
// "shadow" 只分类 + 落 conflict_ledger 账本(bookkeeping,不触发 write hooks),
606+
// freeze/LLM 路径零变化——beta 实验的测量期:shadow 一周拿真实分诊
607+
// 分布,验证是否复现 46/20/5/27。
608+
// "enforce" 确定性处置:T1(dup)走信息量优先 supersede(supersedeInfoFirstPair,
609+
// 败者归档、胜者正文不动、可追溯注记在被归档侧);T2(跨作用域重复)
610+
// 与 T4(真矛盾)只记账——不停车、不送 LLM、不动正文;T3(时序演进)
611+
// 落取代链:旧行 superseded_by/superseded_at 指向新行,两行都留着、
612+
// 正文都不动,检索侧按降权处理。人审队列与 LLM 裁决都不再消费冲突
613+
// 候选;与 conflictFreezeEnabled 同开时 freeze 让位(降级 shadow
614+
// + warn,#616 父子绑定不继承)。
609615
//
610-
// 现阶段枚举里不放 "enforce":宁可让配置挡住手滑,也不要一个「设了但没行为」的
611-
// 档位——#616 的「假成功」教训(autoMin 0.95 在现库覆盖为 0,开了等于没开,用户
612-
// 以为功能坏了)。判据唯一实现在 src/dream/triage.js。
613-
conflictLedgerMode: z.union([z.const("off"), z.const("shadow")]).default("off"),
616+
// 判据唯一实现在 src/dream/triage.js;处置共享实现在 decisions.js 的
617+
// supersedeInfoFirstPair。每个档位的行为都真实存在——#616 的「假成功」教训
618+
// (autoMin 0.95 在现库覆盖为 0,开了等于没开)。
619+
conflictLedgerMode: z.union([z.const("off"), z.const("shadow"), z.const("enforce")]).default("off"),
614620
// T1(dup)档的相似度下限。检测阈值(normal 0.85)与自动档 autoMin(0.95)之间
615621
// 的空带由它接管:真实库 reason 相似度回声集中在 0.85-0.93,正好落在两个阈值
616622
// 之间、自动档开了也接不住的那一段。下界与检测阈值同源。

0 commit comments

Comments
 (0)