Skip to content

Commit 79d336e

Browse files
committed
Merge remote-tracking branch 'origin/main' into tmp/pr565-merge
2 parents a69808e + eb0a51a commit 79d336e

19 files changed

Lines changed: 920 additions & 65 deletions

‎dsh-mneme/docs/CONFIGURATION.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@
236236
| `reflectionFailureRetentionDays` | `90` | `failure_memories`(失败/纠正记录)的启动期清理保留天数(1–3650) | 只读 bundle 配置:未进 feature_flags 白名单,面板改不了。`dsh-mneme reclaim` 不读这个键(它对三个表用同一条 `--older-than`,本表不在其中)。此前这个 90 天是写死的(#275 伞下的欠账) |
237237
| `conflictFreezeEnabled` | `false` | 冲突不自动合并、冻结待人工复核 | opt-in |
238238
| `conflictFreezeMaxPending` | `100` | 冻结队列上限(≤1000) | — |
239+
| `conflictAutoResolveEnabled` | `false` | 相似度极高的**同 scope** 重复对自动裁决(保留新条、归档旧条),不进人工队列 | opt-in。会归档记忆,所以默认关;跨 scope 对永不自动(归属是用户的决定,#170)。用 supersede 而非 conflict:注记写在被归档侧,幸存记忆正文不动 |
240+
| `conflictAutoResolveMinSimilarity` | `0.95` | 自动裁决的相似度门槛(0.85–1) | 实测 live 库 345 条有相似度的历史行里 ≥0.95 只占 5.8%、≥0.94 占 8.1%——这一档减的是峰值,不是把队列清零。低于 0.85 就不是「重复」而是「相似」,不该自动归档任何一条 |
239241

240242
## 实体
241243

‎dsh-mneme/lib/client.js‎

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,9 @@ window.__ModuleLoader__.load({
11441144
"memory.status.conflictQueue.emptyTitle": "暂无待确认冲突",
11451145
"memory.status.conflictQueue.emptyBody": "当巩固发现两条互相矛盾或高度相似的记忆时,会先冻结在这里等你裁决,不会自动修改。裁决前双方都不参与注入。",
11461146
"memory.status.conflictQueue.applyHintTitle": "确认后:保留方正文追加已否决注记,另一方归档",
1147+
// #603 第 3 层:列表被服务端上限截断时必须明说。徽章上的总数与列表行数
1148+
// 不一致、却没有任何提示,是最容易让人以为「就这些了」的假成功。
1149+
"memory.status.conflictQueue.truncated": "已显示 {shown}/{total}(按相似度从高到低,其余请先处理上面的)",
11471150
"memory.status.workbench": "工作动态",
11481151
"memory.status.dreamConsolidate": "记忆巩固",
11491152
"memory.status.summarize": "总结提炼",
@@ -2092,6 +2095,7 @@ window.__ModuleLoader__.load({
20922095
"memory.status.conflictQueue.emptyTitle": "No pending conflicts",
20932096
"memory.status.conflictQueue.emptyBody": "When consolidation finds two contradictory or highly similar memories, it freezes them here for your review instead of changing anything automatically. Neither side participates in injection until resolved.",
20942097
"memory.status.conflictQueue.applyHintTitle": "On confirm: a veto note is appended to the kept side and the other side is archived",
2098+
"memory.status.conflictQueue.truncated": "Showing {shown} of {total} (most similar first; clear these before the rest appear)",
20952099
"memory.status.workbench": "Activity",
20962100
"memory.status.dreamConsolidate": "Consolidation",
20972101
"memory.status.summarize": "Summarization",
@@ -2693,6 +2697,7 @@ window.__ModuleLoader__.load({
26932697
// 冲突集中处理队列(v0.8.0):状态页的待确认冲突列表
26942698
".mneme-conflictq{display:flex;flex-direction:column;gap:10px}",
26952699
".mneme-conflictq-head{display:flex;align-items:center;gap:8px}",
2700+
".mneme-conflictq-truncated{flex:1;font-size:12px;line-height:16px;color:var(--mneme-fg-dim);text-align:right}",
26962701
".mneme-conflict-item{border:1px solid var(--dsw-alias-border-l1,var(--dsw-alias-interactive-bg-hover));border-radius:10px;padding:10px;display:flex;flex-direction:column;gap:8px}",
26972702
".mneme-conflict-reason{font-size:12px;line-height:17px;color:var(--dsw-alias-label-secondary)}",
26982703
".mneme-conflict-pair{display:grid;grid-template-columns:1fr 1fr;gap:8px}",
@@ -7233,6 +7238,11 @@ window.__ModuleLoader__.load({
72337238
// 队列为空时整块不渲染(不打扰无冲突实例)。
72347239
function ConflictsQueue({ t }) {
72357240
const [items, setItems] = useState(null);
7241+
// Issue #603 第 3 层:服务端一直返回 { items, total },这里此前把 total 丢掉、
7242+
// 请求也不带 limit —— 面板列 50 条而徽章显示 60,第 51–60 条既翻不到也没有
7243+
// 任何提示(「假成功」)。total 现在存下来,items.length < total 时明说
7244+
// 「已显示 X/Y」,并一次请求取满服务端上限 200。
7245+
const [total, setTotal] = useState(null);
72367246
const [loadError, setLoadError] = useState(false);
72377247
const [busy, setBusy] = useState(false);
72387248
// 展开态按冲突条目记(一对两侧同时展开,便于逐行对照);复制态按
@@ -7247,12 +7257,18 @@ window.__ModuleLoader__.load({
72477257
);
72487258
};
72497259
const load = (silent) => {
7250-
apiFetch("/api/dsh-mneme/conflicts")
7260+
// limit=200 = 服务端 Math.min(200, ...) 的上限(lib/api.js 的 conflicts 路由)。
7261+
apiFetch("/api/dsh-mneme/conflicts?limit=200")
72517262
.then((res) => { if (!res.ok) throw new Error("http"); return res.json(); })
7252-
.then((d) => { setItems(d.items || []); setLoadError(false); if (!silent) announce(t("memory.status.conflictQueue.refreshed")); })
7263+
.then((d) => {
7264+
setItems(d.items || []);
7265+
setTotal(typeof d.total === "number" ? d.total : null);
7266+
setLoadError(false);
7267+
if (!silent) announce(t("memory.status.conflictQueue.refreshed"));
7268+
})
72537269
// #295 评审:加载失败 ≠ 没有冲突——错误态渲染错误卡而不是空态教育卡,
72547270
// 不能让 500 把「暂时看不到」伪装成「没有冲突」。
7255-
.catch(() => { setItems([]); setLoadError(true); });
7271+
.catch(() => { setItems([]); setTotal(null); setLoadError(true); });
72567272
};
72577273
useEffect(() => { load(); }, []);
72587274
// 参与记忆在别处被删除/编辑时(通用失效广播),队列联表出的那一侧会失真
@@ -7344,18 +7360,28 @@ window.__ModuleLoader__.load({
73447360
title: `${t("memory.status.conflictQueue.frozenTitle")} ${t("memory.status.conflictQueue.applyHintTitle")}`
73457361
}, t("memory.status.conflictQueue.frozenBadge")))
73467362
);
7347-
// #177:相似度从 reason 文本中回收(sleep 路径写「相似度 0.87」,dream 路径
7348-
// 是 LLM 自由文本)——回收得到就画进度条,否则不画,绝不显示编造的数字。
7363+
// #177:相似度优先取服务端新落列的值(#603 第 2 层);老行与 LLM 裁决
7364+
// 路径没有该列 → 回落到从 reason 文本回收。回收不到就返回 null,绝不
7365+
// 显示编造的数字。
73497366
// 防误报:只认「相似度 0.87 / similarity 0.87」这类锚定短语,不在全文里
73507367
// 捞数字(否则 reason 里的年份、条数都会被当成相似度)。
7351-
const similarityOf = (reason) => {
7352-
const m = /(?:相似度|similarity)\s*([01](?:\.\d+)?)/i.exec(String(reason || ""));
7368+
const similarityOf = (it) => {
7369+
if (typeof it.similarity === "number" && it.similarity >= 0 && it.similarity <= 1) return it.similarity;
7370+
const m = /(?:相似度|similarity)\s*([01](?:\.\d+)?)/i.exec(String(it.reason || ""));
73537371
const v = m ? Number(m[1]) : NaN;
73547372
return v >= 0 && v <= 1 ? v : null;
73557373
};
7374+
const shown = items.length;
7375+
const hidden = typeof total === "number" && total > shown ? total - shown : 0;
73567376
return h("div", { className: "mneme-conflictq" },
73577377
h("div", { className: "mneme-conflictq-head" },
73587378
h("span", { className: "mneme-xcount" }, t("memory.status.conflicts")),
7379+
// Issue #603 第 3 层:截断必须说出来。此前 50/60 的差额只体现在徽章
7380+
// 数字上,列表本身看不出少了东西。
7381+
hidden > 0
7382+
? h("span", { className: "mneme-conflictq-truncated" },
7383+
t("memory.status.conflictQueue.truncated").replace("{shown}", String(shown)).replace("{total}", String(total)))
7384+
: null,
73597385
h("button", { className: "mneme-footbtn", onClick: () => load() },
73607386
h(Icon, { name: "refresh", size: 12 }), t("memory.status.conflictQueue.refresh"))),
73617387
// #177 空态教育卡:队列没有条目时也渲染(整块此前直接 return null),
@@ -7368,7 +7394,7 @@ window.__ModuleLoader__.load({
73687394
h("div", { className: "mneme-conflict-empty-title" }, t("memory.status.conflictQueue.emptyTitle")),
73697395
h("div", { className: "mneme-conflict-empty-body" }, t("memory.status.conflictQueue.emptyBody")))),
73707396
items.map((it) => {
7371-
const sim = similarityOf(it.reason);
7397+
const sim = similarityOf(it);
73727398
const open = openItems[it.id] === true;
73737399
const aText = (it.memory_a && it.memory_a.content) || "";
73747400
const bText = (it.memory_b && it.memory_b.content) || "";

‎dsh-mneme/lib/config.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,15 @@ export const Config = z.object({
525525
conflictFreezeEnabled: z.boolean().default(false),
526526
// Maximum number of frozen conflicts to keep pending for manual review.
527527
conflictFreezeMaxPending: z.natural().min(1).max(1000).default(100),
528+
// Issue #603 第 4 层(自动裁决档):freeze 模式里相似度极高的同 scope 对直接
529+
// 裁决(保留新条、归档旧条),不进人工队列——人只看模糊地带。默认关:这是
530+
// 会归档记忆的自动动作,必须显式打开。
531+
// 实测口径(live 库 345 条有相似度的历史行):>=0.95 只有 20 条(5.8%),
532+
// >=0.94 是 28 条(8.1%)。所以这一档减量约一半的峰值,减不到个位数;
533+
// 阈值留在配置里就是为了让人按自己队列的分布调,而不是信一个拍脑袋的数。
534+
// 跨 scope 对永不自动裁决:归属是用户的决定(v0.8.1 #170 的既有约束)。
535+
conflictAutoResolveEnabled: z.boolean().default(false),
536+
conflictAutoResolveMinSimilarity: z.number().min(0.85).max(1).default(0.95),
528537

529538
// --- entity gene (v0.3.0) -----------------------------------------------
530539
// Opt-in: when false (default) nothing in the pipeline extracts entities.

‎dsh-mneme/lib/dream.js‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,12 @@ export function createDreamScheduler({ onRun, thresholdCount = 10, thresholdChar
12641264
}
12651265

12661266
let listText;
1267+
// Issue #603 第 2 层:把预分组阶段算出的向量相似度留下来,供停车入队时落列。
1268+
// 这是**本进程内唯一**真实的相似度来源——LLM 裁决给出的只有理由文本,从文本
1269+
// 里回收数字是猜测。键与 conflict_pending 的对序归一化一致(sort 后的 id 对)。
1270+
// 拿不到(无向量、跨进程重放、模型自由裁决)就写 NULL,排序按「未知」处理。
1271+
const pairSimilarity = new Map();
1272+
const similarityKey = (x, y) => (x < y ? `${x}\u0000${y}` : `${y}\u0000${x}`);
12671273
if (semantic?.embedder && semantic?.vectorIndex) {
12681274
try {
12691275
const vectors = await collectVectors(memories, semantic);
@@ -1272,6 +1278,7 @@ export function createDreamScheduler({ onRun, thresholdCount = 10, thresholdChar
12721278
const clusters = clusterMemories(memories, vectors, k);
12731279
const conflicts = findPotentialConflicts(memories, vectors, 0.85);
12741280
const conflictIds = new Set(conflicts.flatMap((c) => [c.a.id, c.b.id]));
1281+
for (const c of conflicts) pairSimilarity.set(similarityKey(c.a.id, c.b.id), c.similarity);
12751282
const parts = [];
12761283
clusters.forEach((cluster, ci) => {
12771284
parts.push(STR.clusterHeader[language](ci + 1));
@@ -1488,8 +1495,10 @@ export function createDreamScheduler({ onRun, thresholdCount = 10, thresholdChar
14881495
try {
14891496
// 返回 undefined = 该对已被人工裁决且两侧内容未变(issue #170 复核
14901497
// 项 4:内容变了才重新入队)——不算停车、不进 frozenIds。
1491-
const parked = service.saveConflictPending({ run_id: runId, memory_a: d.winner, memory_b: d.loser, reason: d.reason });
1492-
if (parked == null) continue;
1498+
const parked = service.saveConflictPending({ run_id: runId, memory_a: d.winner, memory_b: d.loser, reason: d.reason, similarity: pairSimilarity.get(similarityKey(d.winner, d.loser)) });
1499+
// 只有真的新插了一行才算停车:这一对已在队列里时返回的是旧行
1500+
// (fresh=false),旧代码把它也算进 frozen,虚报由此而来(#603)。
1501+
if (parked?.fresh !== true) continue;
14931502
frozenCount++;
14941503
frozenIds.push(d.winner, d.loser);
14951504
} catch (error) {
@@ -1510,9 +1519,10 @@ export function createDreamScheduler({ onRun, thresholdCount = 10, thresholdChar
15101519
run_id: runId,
15111520
memory_a: d.winner,
15121521
memory_b: d.loser,
1513-
reason: STR.scopeConflictParkReason[language](d.reason)
1522+
reason: STR.scopeConflictParkReason[language](d.reason),
1523+
similarity: pairSimilarity.get(similarityKey(d.winner, d.loser))
15141524
});
1515-
if (parked != null) {
1525+
if (parked?.fresh === true) {
15161526
frozenCount++;
15171527
frozenIds.push(d.winner, d.loser);
15181528
}

0 commit comments

Comments
 (0)