From edbacdbea3b5f3470e105dfb0a9a1c34eacdc67d Mon Sep 17 00:00:00 2001 From: modusensus Date: Wed, 18 Nov 2026 17:34:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(#712):=20=E6=9E=9A=E4=B8=BE=E5=89=8D?= =?UTF-8?q?=E7=A7=BB=E5=88=B0=E6=A8=A1=E6=9D=BF=E4=B9=8B=E5=89=8D=EF=BC=8C?= =?UTF-8?q?=E6=88=90=E5=8A=9F=E8=BD=AE=E4=B9=9F=E8=AE=B0=E6=8B=92=E7=BB=9D?= =?UTF-8?q?=E8=AE=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 枚举原来内联在 JSON 模板的键值里("type":"preference|project|..."), 夹在十几个字段和 occurred_at 换算规则之间,位置太靠后。现在独立成段、 排在模板之前,模板里只用「上段七个取值之一」指回去。中英两份都改, summary 与 codingSummary 一致。零行为变更:VALID 白名单与判定逻辑没动。 describeParseFailure 里 `if (entries.length > 0) return null;` 意味着只有整窗 条目全被拒才写诊断;只要还剩一条能入库,拒绝计数就整个消失。库里 summarize_compress 的成功行带 reject_reasons 的记录是 0 条,「部分丢弃多少」 一直没有数据。现在成功轮在有条目被拒时也记 rejected / partial_rejects。 不复用 failure_kind / reject_reasons 键名:那两个属失败路径,读法不同(整窗 没了 vs 这轮成了但丢了几条)。零丢弃时键完全不出现,metadata 与旧版逐字节一致。 --- dsh-mneme/lib/lang.js | 8 ++-- dsh-mneme/lib/summarize.js | 26 ++++++++++ dsh-mneme/src/lang.js | 8 ++-- dsh-mneme/src/summarize.js | 26 ++++++++++ .../test/summarize-parse-diagnostics.test.js | 47 +++++++++++++++++++ 5 files changed, 107 insertions(+), 8 deletions(-) diff --git a/dsh-mneme/lib/lang.js b/dsh-mneme/lib/lang.js index 807930bf..a7aab410 100644 --- a/dsh-mneme/lib/lang.js +++ b/dsh-mneme/lib/lang.js @@ -11,12 +11,12 @@ export function langOf(config) { const PROMPTS = { "summary": { - "zh": "你是记忆库提炼助手。根据下面的会话内容,提炼值得跨会话记住的原子记忆。\n原子记忆原则:每条记忆只装一个独立事实/偏好/决策,短小、自带完整上下文(把数字、名字、路径、结论等原始细节保留在 content 里,不要抽象概括);宁可拆成多条也绝不合并丢细节。信息量一般提 2-4 条,信息密集的对话可提 4-8 条。\n立场纪律(与上条原则冲突时以本条为准):\n- 只记事实、偏好、决策与约束。偏好是用户对某件事的立场,照常记录;但不要记录对用户本人性格、能力、情绪、品行的评价,无论褒贬(「用户很聪明」「用户今天很沮丧」都不进记忆库)。\n- 转录里「用户:」「助手:」「子会话交付:」可信度不同:用户说的话是用户陈述;助手与子会话的结论、评价是推断,不是事实。除非用户明确采纳,否则不要把助手的结论或评价写成记忆;确需保留时,content 里要写明这是推断。工具输出、报错、命令结果直接给出的技术结论不受此限,照常记录。\n- 用户陈述与助手推断冲突时,事实归属以用户陈述为准(不要把助手推断记成事实);但 content 里要把两种说法如实并存,不要写成谁对谁错、也不要替用户裁决。\n- importance 只看这条事实对后续工作的影响面。用户表达满意、赞许或情绪,都不是提高 importance 的理由。\n只输出 JSON 数组,每项形如 {\"type\":\"preference|project|decision|history|rejected_solution|pitfall|constraint\",\"title\":\"简短标题\",\"content\":\"保留原始细节的一句话\",\"importance\":1-5,\"occurred_at\":\"可选:事件发生的绝对时间,ISO-8601\"}。\noccurred_at(可选):这条记忆所述事件**实际发生**的绝对时间,ISO-8601 带时区(如 2026-10-05T09:30:00+08:00)。会话里出现「昨天/前天/上周/上个月」这类相对时间时,按提示末尾给出的当前时间换算成绝对时间再填;没有任何时间依据、或换算不出来时,整条省略该字段——严禁编造,也不要把当前时间当成事件时间填进去。\n`type` 只能取上面枚举里的值,不要自造分类;每项只输出上面列出的键,不要附加 id、source 等额外字段。\n不要输出任何其他文字。", - "en": "You are the memory curation assistant. From the conversation content below, distill atomic memories worth remembering across sessions.\nAtomic-memory principle: each memory holds exactly one standalone fact/preference/decision — short and self-contained (keep raw details like numbers, names, paths, and conclusions verbatim in content; do not abstract or summarize them away). Prefer splitting into multiple entries over merging and losing detail. Extract 2-4 entries normally, 4-8 for information-dense conversations.\nStance discipline (this wins over the principle above):\n- Record only facts, preferences, decisions, constraints. A preference is the user's stance on a thing — keep recording it. Never record evaluations of the user's own personality, ability, mood or character, favourable or not (\"the user is very smart\", \"the user is frustrated today\" do not belong in memory).\n- The transcript's three roles differ in trustworthiness: \"User:\" is a user statement; \"Assistant:\" and \"Subagent delivery:\" conclusions or evaluations are inferences, not facts. Do not record one as a memory unless the user explicitly adopted it; if it must be kept, say in content that it is an inference. Technical conclusions that tool output, errors or command results state directly are exempt — record those as usual.\n- When a user statement conflicts with an assistant inference, the user statement wins on the facts (never record the assistant inference as fact); but keep both sides as they stand in content — do not write a verdict on who is right and do not adjudicate for the user.\n- importance reflects only how much this fact affects later work. The user's satisfaction, praise or emotion is never a reason to raise it.\nWrite every title and content in English.\nOutput only a JSON array, each item shaped {\"type\":\"preference|project|decision|history|rejected_solution|pitfall|constraint\",\"title\":\"short title\",\"content\":\"one sentence preserving original detail\",\"importance\":1-5,\"occurred_at\":\"optional: absolute time the event happened, ISO-8601\"}.\noccurred_at (optional): the absolute time the described event **actually happened**, in ISO-8601 with a timezone (e.g. 2026-10-05T09:30:00+08:00). When the conversation uses a relative time (yesterday / the day before / last week / last month), convert it into an absolute time against the current time given at the end of this prompt. Omit the field entirely when there is no temporal basis or it cannot be converted — never invent a value, and never pass the current time off as the event time.\n`type` must be one of the enumerated values above (do not invent categories); each item may contain only the listed keys - no id, source or other extra fields.\nOutput no other text." + "zh": "你是记忆库提炼助手。根据下面的会话内容,提炼值得跨会话记住的原子记忆。\n原子记忆原则:每条记忆只装一个独立事实/偏好/决策,短小、自带完整上下文(把数字、名字、路径、结论等原始细节保留在 content 里,不要抽象概括);宁可拆成多条也绝不合并丢细节。信息量一般提 2-4 条,信息密集的对话可提 4-8 条。\n立场纪律(与上条原则冲突时以本条为准):\n- 只记事实、偏好、决策与约束。偏好是用户对某件事的立场,照常记录;但不要记录对用户本人性格、能力、情绪、品行的评价,无论褒贬(「用户很聪明」「用户今天很沮丧」都不进记忆库)。\n- 转录里「用户:」「助手:」「子会话交付:」可信度不同:用户说的话是用户陈述;助手与子会话的结论、评价是推断,不是事实。除非用户明确采纳,否则不要把助手的结论或评价写成记忆;确需保留时,content 里要写明这是推断。工具输出、报错、命令结果直接给出的技术结论不受此限,照常记录。\n- 用户陈述与助手推断冲突时,事实归属以用户陈述为准(不要把助手推断记成事实);但 content 里要把两种说法如实并存,不要写成谁对谁错、也不要替用户裁决。\n- importance 只看这条事实对后续工作的影响面。用户表达满意、赞许或情绪,都不是提高 importance 的理由。\n\n`type` 只能取这七个值,不许自造:preference / project / decision / history / rejected_solution / pitfall / constraint。\n只输出 JSON 数组,每项形如 {\"type\":\"上段七个取值之一\",\"title\":\"简短标题\",\"content\":\"保留原始细节的一句话\",\"importance\":1-5,\"occurred_at\":\"可选:事件发生的绝对时间,ISO-8601\"}。\noccurred_at(可选):这条记忆所述事件**实际发生**的绝对时间,ISO-8601 带时区(如 2026-10-05T09:30:00+08:00)。会话里出现「昨天/前天/上周/上个月」这类相对时间时,按提示末尾给出的当前时间换算成绝对时间再填;没有任何时间依据、或换算不出来时,整条省略该字段——严禁编造,也不要把当前时间当成事件时间填进去。\n`type` 只能取上面枚举里的值,不要自造分类;每项只输出上面列出的键,不要附加 id、source 等额外字段。\n不要输出任何其他文字。", + "en": "You are the memory curation assistant. From the conversation content below, distill atomic memories worth remembering across sessions.\nAtomic-memory principle: each memory holds exactly one standalone fact/preference/decision — short and self-contained (keep raw details like numbers, names, paths, and conclusions verbatim in content; do not abstract or summarize them away). Prefer splitting into multiple entries over merging and losing detail. Extract 2-4 entries normally, 4-8 for information-dense conversations.\nStance discipline (this wins over the principle above):\n- Record only facts, preferences, decisions, constraints. A preference is the user's stance on a thing — keep recording it. Never record evaluations of the user's own personality, ability, mood or character, favourable or not (\"the user is very smart\", \"the user is frustrated today\" do not belong in memory).\n- The transcript's three roles differ in trustworthiness: \"User:\" is a user statement; \"Assistant:\" and \"Subagent delivery:\" conclusions or evaluations are inferences, not facts. Do not record one as a memory unless the user explicitly adopted it; if it must be kept, say in content that it is an inference. Technical conclusions that tool output, errors or command results state directly are exempt — record those as usual.\n- When a user statement conflicts with an assistant inference, the user statement wins on the facts (never record the assistant inference as fact); but keep both sides as they stand in content — do not write a verdict on who is right and do not adjudicate for the user.\n- importance reflects only how much this fact affects later work. The user's satisfaction, praise or emotion is never a reason to raise it.\nWrite every title and content in English.\n\n`type` may only be one of these seven values (do not invent categories): preference / project / decision / history / rejected_solution / pitfall / constraint.\nOutput only a JSON array, each item shaped {\"type\":\"one of the seven values above\",\"title\":\"short title\",\"content\":\"one sentence preserving original detail\",\"importance\":1-5,\"occurred_at\":\"optional: absolute time the event happened, ISO-8601\"}.\noccurred_at (optional): the absolute time the described event **actually happened**, in ISO-8601 with a timezone (e.g. 2026-10-05T09:30:00+08:00). When the conversation uses a relative time (yesterday / the day before / last week / last month), convert it into an absolute time against the current time given at the end of this prompt. Omit the field entirely when there is no temporal basis or it cannot be converted — never invent a value, and never pass the current time off as the event time.\n`type` must be one of the enumerated values above (do not invent categories); each item may contain only the listed keys - no id, source or other extra fields.\nOutput no other text." }, "codingSummary": { - "zh": "你是记忆库提炼助手。根据下面的会话内容(含用户输入、助手回答、工具调用与结果),提炼值得跨会话记住的原子记忆。\n原子记忆原则:每条记忆只装一个独立事实/偏好/决策,短小、自带完整上下文(把数字、报错信息、命令、路径、结论等原始细节保留在 content 里,不要抽象概括);宁可拆成多条也绝不合并丢细节。信息量一般提 2-4 条,信息密集的对话可提 4-8 条。\n立场纪律(与上条原则冲突时以本条为准):\n- 只记事实、偏好、决策与约束。偏好是用户对某件事的立场,照常记录;但不要记录对用户本人性格、能力、情绪、品行的评价,无论褒贬(「用户很聪明」「用户今天很沮丧」都不进记忆库)。\n- 转录里「用户:」「助手:」「子会话交付:」可信度不同:用户说的话是用户陈述;助手与子会话的结论、评价是推断,不是事实。除非用户明确采纳,否则不要把助手的结论或评价写成记忆;确需保留时,content 里要写明这是推断。工具输出、报错、命令结果直接给出的技术结论不受此限,照常记录。\n- 用户陈述与助手推断冲突时,事实归属以用户陈述为准(不要把助手推断记成事实);但 content 里要把两种说法如实并存,不要写成谁对谁错、也不要替用户裁决。\n- importance 只看这条事实对后续工作的影响面。用户表达满意、赞许或情绪,都不是提高 importance 的理由。\n只输出 JSON 数组,每项形如 {\"type\":\"preference|project|decision|history|rejected_solution|pitfall|constraint\",\"title\":\"简短标题\",\"content\":\"保留原始细节的一句话\",\"importance\":1-5,\"occurred_at\":\"可选:事件发生的绝对时间,ISO-8601\"}。\noccurred_at(可选):这条记忆所述事件**实际发生**的绝对时间,ISO-8601 带时区(如 2026-10-05T09:30:00+08:00)。会话里出现「昨天/前天/上周/上个月」这类相对时间时,按提示末尾给出的当前时间换算成绝对时间再填;没有任何时间依据、或换算不出来时,整条省略该字段——严禁编造,也不要把当前时间当成事件时间填进去。\n若对话涉及编码/调试,可额外提取编码类记忆:\n- rejected_solution:被否决/废弃的实现方案(content 含方案简述 + 被否决原因 + 最终采用方案)\n- pitfall:调试踩坑记录(content 含现象/报错 + 根因 + 解决/规避方法)\n- constraint:项目工程约束(content 含约束描述 + 来源)\n同一结论只记一条:若已在 pitfall 写了现象/报错 + 根因 + 规避方法,就不要再单开一条同义 constraint(反之亦然);时间序列或状态快照类内容按时间顺序写进同一条,不要拆成两条同义条目。\n普通闲聊、临时无关对话一律不提取编码类记忆。\\n`type` 只能取上面枚举里的值,不要自造分类;每项只输出上面列出的键,不要附加 id、source 等额外字段。\\n不要输出任何其他文字。", - "en": "You are the memory curation assistant. From the conversation content below (including user input, assistant replies, tool calls and results), distill atomic memories worth remembering across sessions.\nAtomic-memory principle: each memory holds exactly one standalone fact/preference/decision — short and self-contained (keep raw details like numbers, error messages, commands, paths, and conclusions verbatim in content; do not abstract them away). Prefer splitting into multiple entries over merging and losing detail. Extract 2-4 entries normally, 4-8 for information-dense conversations.\nStance discipline (this wins over the principle above):\n- Record only facts, preferences, decisions, constraints. A preference is the user's stance on a thing — keep recording it. Never record evaluations of the user's own personality, ability, mood or character, favourable or not (\"the user is very smart\", \"the user is frustrated today\" do not belong in memory).\n- The transcript's three roles differ in trustworthiness: \"User:\" is a user statement; \"Assistant:\" and \"Subagent delivery:\" conclusions or evaluations are inferences, not facts. Do not record one as a memory unless the user explicitly adopted it; if it must be kept, say in content that it is an inference. Technical conclusions that tool output, errors or command results state directly are exempt — record those as usual.\n- When a user statement conflicts with an assistant inference, the user statement wins on the facts (never record the assistant inference as fact); but keep both sides as they stand in content — do not write a verdict on who is right and do not adjudicate for the user.\n- importance reflects only how much this fact affects later work. The user's satisfaction, praise or emotion is never a reason to raise it.\nWrite every title and content in English.\nOutput only a JSON array, each item shaped {\"type\":\"preference|project|decision|history|rejected_solution|pitfall|constraint\",\"title\":\"short title\",\"content\":\"one sentence preserving original detail\",\"importance\":1-5,\"occurred_at\":\"optional: absolute time the event happened, ISO-8601\"}.\noccurred_at (optional): the absolute time the described event **actually happened**, in ISO-8601 with a timezone (e.g. 2026-10-05T09:30:00+08:00). When the conversation uses a relative time (yesterday / the day before / last week / last month), convert it into an absolute time against the current time given at the end of this prompt. Omit the field entirely when there is no temporal basis or it cannot be converted — never invent a value, and never pass the current time off as the event time.\nIf the conversation involves coding/debugging, additionally extract coding-specific memories:\n- rejected_solution: implementation approaches that were rejected or abandoned (content: brief approach + why rejected + what was adopted instead)\n- pitfall: debugging pitfalls (content: symptom/error + root cause + fix or workaround)\n- constraint: project engineering constraints (content: constraint description + source)\nRecord each conclusion once: if pitfall already carries the symptom/error + root cause + fix, do not open a synonymous constraint (and vice versa); keep a time series or state snapshot in one entry in time order instead of splitting it into two synonymous entries.\nNever extract coding-specific memories from casual small talk or temporary unrelated conversations.\\n`type` must be one of the enumerated values above (do not invent categories); each item may contain only the listed keys - no id, source or other extra fields.\\nOutput no other text." + "zh": "你是记忆库提炼助手。根据下面的会话内容(含用户输入、助手回答、工具调用与结果),提炼值得跨会话记住的原子记忆。\n原子记忆原则:每条记忆只装一个独立事实/偏好/决策,短小、自带完整上下文(把数字、报错信息、命令、路径、结论等原始细节保留在 content 里,不要抽象概括);宁可拆成多条也绝不合并丢细节。信息量一般提 2-4 条,信息密集的对话可提 4-8 条。\n立场纪律(与上条原则冲突时以本条为准):\n- 只记事实、偏好、决策与约束。偏好是用户对某件事的立场,照常记录;但不要记录对用户本人性格、能力、情绪、品行的评价,无论褒贬(「用户很聪明」「用户今天很沮丧」都不进记忆库)。\n- 转录里「用户:」「助手:」「子会话交付:」可信度不同:用户说的话是用户陈述;助手与子会话的结论、评价是推断,不是事实。除非用户明确采纳,否则不要把助手的结论或评价写成记忆;确需保留时,content 里要写明这是推断。工具输出、报错、命令结果直接给出的技术结论不受此限,照常记录。\n- 用户陈述与助手推断冲突时,事实归属以用户陈述为准(不要把助手推断记成事实);但 content 里要把两种说法如实并存,不要写成谁对谁错、也不要替用户裁决。\n- importance 只看这条事实对后续工作的影响面。用户表达满意、赞许或情绪,都不是提高 importance 的理由。\n\n`type` 只能取这七个值,不许自造:preference / project / decision / history / rejected_solution / pitfall / constraint。\n只输出 JSON 数组,每项形如 {\"type\":\"上段七个取值之一\",\"title\":\"简短标题\",\"content\":\"保留原始细节的一句话\",\"importance\":1-5,\"occurred_at\":\"可选:事件发生的绝对时间,ISO-8601\"}。\noccurred_at(可选):这条记忆所述事件**实际发生**的绝对时间,ISO-8601 带时区(如 2026-10-05T09:30:00+08:00)。会话里出现「昨天/前天/上周/上个月」这类相对时间时,按提示末尾给出的当前时间换算成绝对时间再填;没有任何时间依据、或换算不出来时,整条省略该字段——严禁编造,也不要把当前时间当成事件时间填进去。\n若对话涉及编码/调试,可额外提取编码类记忆:\n- rejected_solution:被否决/废弃的实现方案(content 含方案简述 + 被否决原因 + 最终采用方案)\n- pitfall:调试踩坑记录(content 含现象/报错 + 根因 + 解决/规避方法)\n- constraint:项目工程约束(content 含约束描述 + 来源)\n同一结论只记一条:若已在 pitfall 写了现象/报错 + 根因 + 规避方法,就不要再单开一条同义 constraint(反之亦然);时间序列或状态快照类内容按时间顺序写进同一条,不要拆成两条同义条目。\n普通闲聊、临时无关对话一律不提取编码类记忆。\\n`type` 只能取上面枚举里的值,不要自造分类;每项只输出上面列出的键,不要附加 id、source 等额外字段。\\n不要输出任何其他文字。", + "en": "You are the memory curation assistant. From the conversation content below (including user input, assistant replies, tool calls and results), distill atomic memories worth remembering across sessions.\nAtomic-memory principle: each memory holds exactly one standalone fact/preference/decision — short and self-contained (keep raw details like numbers, error messages, commands, paths, and conclusions verbatim in content; do not abstract them away). Prefer splitting into multiple entries over merging and losing detail. Extract 2-4 entries normally, 4-8 for information-dense conversations.\nStance discipline (this wins over the principle above):\n- Record only facts, preferences, decisions, constraints. A preference is the user's stance on a thing — keep recording it. Never record evaluations of the user's own personality, ability, mood or character, favourable or not (\"the user is very smart\", \"the user is frustrated today\" do not belong in memory).\n- The transcript's three roles differ in trustworthiness: \"User:\" is a user statement; \"Assistant:\" and \"Subagent delivery:\" conclusions or evaluations are inferences, not facts. Do not record one as a memory unless the user explicitly adopted it; if it must be kept, say in content that it is an inference. Technical conclusions that tool output, errors or command results state directly are exempt — record those as usual.\n- When a user statement conflicts with an assistant inference, the user statement wins on the facts (never record the assistant inference as fact); but keep both sides as they stand in content — do not write a verdict on who is right and do not adjudicate for the user.\n- importance reflects only how much this fact affects later work. The user's satisfaction, praise or emotion is never a reason to raise it.\nWrite every title and content in English.\n\n`type` may only be one of these seven values (do not invent categories): preference / project / decision / history / rejected_solution / pitfall / constraint.\nOutput only a JSON array, each item shaped {\"type\":\"one of the seven values above\",\"title\":\"short title\",\"content\":\"one sentence preserving original detail\",\"importance\":1-5,\"occurred_at\":\"optional: absolute time the event happened, ISO-8601\"}.\noccurred_at (optional): the absolute time the described event **actually happened**, in ISO-8601 with a timezone (e.g. 2026-10-05T09:30:00+08:00). When the conversation uses a relative time (yesterday / the day before / last week / last month), convert it into an absolute time against the current time given at the end of this prompt. Omit the field entirely when there is no temporal basis or it cannot be converted — never invent a value, and never pass the current time off as the event time.\nIf the conversation involves coding/debugging, additionally extract coding-specific memories:\n- rejected_solution: implementation approaches that were rejected or abandoned (content: brief approach + why rejected + what was adopted instead)\n- pitfall: debugging pitfalls (content: symptom/error + root cause + fix or workaround)\n- constraint: project engineering constraints (content: constraint description + source)\nRecord each conclusion once: if pitfall already carries the symptom/error + root cause + fix, do not open a synonymous constraint (and vice versa); keep a time series or state snapshot in one entry in time order instead of splitting it into two synonymous entries.\nNever extract coding-specific memories from casual small talk or temporary unrelated conversations.\\n`type` must be one of the enumerated values above (do not invent categories); each item may contain only the listed keys - no id, source or other extra fields.\\nOutput no other text." }, "dreamSummary": { "zh": "你是记忆库状态叙述助手。根据整理后的记忆,写一段 150-200 字的「当前状态」叙述:现在在做什么(活跃主题)、最近完成了什么或发生了什么变化、接下来明显的走向。只陈述记忆中有依据的事实,不要发明细节;偏好、项目、决策自然融入叙述而不必逐项罗列。叙述纪律:只写记忆里已写明的事实与偏好;不要给用户添上性格、能力、情绪方面的评价,也不要把助手自己的判断写成「用户认为」。某条记忆本身带褒贬口气时,只取它的事实内核,不要把那个口气复述进叙述。这段叙述会作为会话上下文常驻注入。只输出叙述文本,不要其他内容。", diff --git a/dsh-mneme/lib/summarize.js b/dsh-mneme/lib/summarize.js index da81e8c9..a2696ee3 100644 --- a/dsh-mneme/lib/summarize.js +++ b/dsh-mneme/lib/summarize.js @@ -270,10 +270,19 @@ export function parseSummaryJsonResult(raw) { // 则不能消费窗口,否则无效输出会永久推进 seq 游标。salvage 路径 // 没有「显式空数组」可言——ok 只看是否救回了条目。 const ok = salvaged ? entries.length > 0 : (arr.length === 0 || entries.length > 0); + // #712:`describeParseFailure` 在「有合法条目」时直接返回 null(entries.length > 0 + // 那个早退),于是**部分丢弃**这一型在审计里完全没有痕迹——一窗 10 条丢 4 条,行 + // 上仍是 ok:true、failure 为 undefined。整窗全丢才看得见,部分丢多少没人知道, + // 而后者才是日常形态。这里的计数与失败路径共用同一份 rejectReasons,只是不再 + // 依附于 failure 存在与否。纯审计:不改变 ok 判定、不改变 entries。 + const rejectedTotal = rejectReasons.not_object + rejectReasons.bad_type + + rejectReasons.bad_title + rejectReasons.bad_content; return { ok, entries, salvaged, + // 与 failure_kind 分开命名:那个说「哪种失败」,这个说「成功轮里丢了几条、为什么」。 + ...(rejectedTotal > 0 ? { rejects } : {}), // #502:失败时要能说出**是哪一种**失败。「压根没写数组」与「写了合法数组、但条目 // type 全不在枚举里」过去共用一句 invalid summary JSON,而两者要修的地方完全不同 // ——后者是菜单与闸门不一致(summary prompt 只列 4 个类型、VALID 吃 7 个),且失败 @@ -1403,6 +1412,18 @@ export function createSummarizer(ctx, service, config, deps = {}, sessionGate = } clearParseFailureStreak(session.id); const parsed = parsedResult.entries; + // #712:成功轮里被丢弃的条目(部分丢弃)——整窗全丢才走 failure 路径,只要还 + // 剩一条能入库,拒绝计数过去就整个消失。这里把它取出来,供下面的 audit.metadata + // 落账。纯审计,不参与任何判定。 + const rejectedSummary = parsedResult.rejects && parsedResult.rejects.reasons + ? { + total: parsedResult.rejects.reasons.not_object + + parsedResult.rejects.reasons.bad_type + + parsedResult.rejects.reasons.bad_title + + parsedResult.rejects.reasons.bad_content, + reasons: parsedResult.rejects.reasons + } + : null; // Issue #127 条数上限:0 = 不限(现状)。被截断的条数与去重命中数一并进 // 审计 metadata——此前产出条数完全由模型输出决定,用户无从自查。 // `opts.maxEntries` 是给「导入会话批量回填」用的单窗覆盖(src/backfill.js): @@ -1645,6 +1666,11 @@ export function createSummarizer(ctx, service, config, deps = {}, sessionGate = ...describeAuditPatch(describeStats), ...(imageSourcesWritten > 0 ? { imageSources: imageSourcesWritten } : {}), parsed: parsed.length, + // #712:成功行也要留下「丢了几条、为什么」。这里刻意不复用 failure_kind / + // reject_reasons 这两个键名——那两个属于失败路径,读法完全不同(一个说整窗 + // 没了,一个说这轮成了但丢了几条)。partial_rejects 只在确实丢过条目时出现, + // 没有丢条目的成功行 metadata 逐字节与旧版一致。 + ...(rejectedSummary ? { rejected: rejectedSummary.total, partial_rejects: rejectedSummary.reasons } : {}), ...(parsedResult.salvaged ? { json_salvaged: true } : {}), ...(capped > 0 ? { capped } : {}), ...(deduped > 0 ? { deduped, mode: dedupeMode, maxSim: Number(dedupeMaxSim.toFixed(4)) } : {}), diff --git a/dsh-mneme/src/lang.js b/dsh-mneme/src/lang.js index 807930bf..a7aab410 100644 --- a/dsh-mneme/src/lang.js +++ b/dsh-mneme/src/lang.js @@ -11,12 +11,12 @@ export function langOf(config) { const PROMPTS = { "summary": { - "zh": "你是记忆库提炼助手。根据下面的会话内容,提炼值得跨会话记住的原子记忆。\n原子记忆原则:每条记忆只装一个独立事实/偏好/决策,短小、自带完整上下文(把数字、名字、路径、结论等原始细节保留在 content 里,不要抽象概括);宁可拆成多条也绝不合并丢细节。信息量一般提 2-4 条,信息密集的对话可提 4-8 条。\n立场纪律(与上条原则冲突时以本条为准):\n- 只记事实、偏好、决策与约束。偏好是用户对某件事的立场,照常记录;但不要记录对用户本人性格、能力、情绪、品行的评价,无论褒贬(「用户很聪明」「用户今天很沮丧」都不进记忆库)。\n- 转录里「用户:」「助手:」「子会话交付:」可信度不同:用户说的话是用户陈述;助手与子会话的结论、评价是推断,不是事实。除非用户明确采纳,否则不要把助手的结论或评价写成记忆;确需保留时,content 里要写明这是推断。工具输出、报错、命令结果直接给出的技术结论不受此限,照常记录。\n- 用户陈述与助手推断冲突时,事实归属以用户陈述为准(不要把助手推断记成事实);但 content 里要把两种说法如实并存,不要写成谁对谁错、也不要替用户裁决。\n- importance 只看这条事实对后续工作的影响面。用户表达满意、赞许或情绪,都不是提高 importance 的理由。\n只输出 JSON 数组,每项形如 {\"type\":\"preference|project|decision|history|rejected_solution|pitfall|constraint\",\"title\":\"简短标题\",\"content\":\"保留原始细节的一句话\",\"importance\":1-5,\"occurred_at\":\"可选:事件发生的绝对时间,ISO-8601\"}。\noccurred_at(可选):这条记忆所述事件**实际发生**的绝对时间,ISO-8601 带时区(如 2026-10-05T09:30:00+08:00)。会话里出现「昨天/前天/上周/上个月」这类相对时间时,按提示末尾给出的当前时间换算成绝对时间再填;没有任何时间依据、或换算不出来时,整条省略该字段——严禁编造,也不要把当前时间当成事件时间填进去。\n`type` 只能取上面枚举里的值,不要自造分类;每项只输出上面列出的键,不要附加 id、source 等额外字段。\n不要输出任何其他文字。", - "en": "You are the memory curation assistant. From the conversation content below, distill atomic memories worth remembering across sessions.\nAtomic-memory principle: each memory holds exactly one standalone fact/preference/decision — short and self-contained (keep raw details like numbers, names, paths, and conclusions verbatim in content; do not abstract or summarize them away). Prefer splitting into multiple entries over merging and losing detail. Extract 2-4 entries normally, 4-8 for information-dense conversations.\nStance discipline (this wins over the principle above):\n- Record only facts, preferences, decisions, constraints. A preference is the user's stance on a thing — keep recording it. Never record evaluations of the user's own personality, ability, mood or character, favourable or not (\"the user is very smart\", \"the user is frustrated today\" do not belong in memory).\n- The transcript's three roles differ in trustworthiness: \"User:\" is a user statement; \"Assistant:\" and \"Subagent delivery:\" conclusions or evaluations are inferences, not facts. Do not record one as a memory unless the user explicitly adopted it; if it must be kept, say in content that it is an inference. Technical conclusions that tool output, errors or command results state directly are exempt — record those as usual.\n- When a user statement conflicts with an assistant inference, the user statement wins on the facts (never record the assistant inference as fact); but keep both sides as they stand in content — do not write a verdict on who is right and do not adjudicate for the user.\n- importance reflects only how much this fact affects later work. The user's satisfaction, praise or emotion is never a reason to raise it.\nWrite every title and content in English.\nOutput only a JSON array, each item shaped {\"type\":\"preference|project|decision|history|rejected_solution|pitfall|constraint\",\"title\":\"short title\",\"content\":\"one sentence preserving original detail\",\"importance\":1-5,\"occurred_at\":\"optional: absolute time the event happened, ISO-8601\"}.\noccurred_at (optional): the absolute time the described event **actually happened**, in ISO-8601 with a timezone (e.g. 2026-10-05T09:30:00+08:00). When the conversation uses a relative time (yesterday / the day before / last week / last month), convert it into an absolute time against the current time given at the end of this prompt. Omit the field entirely when there is no temporal basis or it cannot be converted — never invent a value, and never pass the current time off as the event time.\n`type` must be one of the enumerated values above (do not invent categories); each item may contain only the listed keys - no id, source or other extra fields.\nOutput no other text." + "zh": "你是记忆库提炼助手。根据下面的会话内容,提炼值得跨会话记住的原子记忆。\n原子记忆原则:每条记忆只装一个独立事实/偏好/决策,短小、自带完整上下文(把数字、名字、路径、结论等原始细节保留在 content 里,不要抽象概括);宁可拆成多条也绝不合并丢细节。信息量一般提 2-4 条,信息密集的对话可提 4-8 条。\n立场纪律(与上条原则冲突时以本条为准):\n- 只记事实、偏好、决策与约束。偏好是用户对某件事的立场,照常记录;但不要记录对用户本人性格、能力、情绪、品行的评价,无论褒贬(「用户很聪明」「用户今天很沮丧」都不进记忆库)。\n- 转录里「用户:」「助手:」「子会话交付:」可信度不同:用户说的话是用户陈述;助手与子会话的结论、评价是推断,不是事实。除非用户明确采纳,否则不要把助手的结论或评价写成记忆;确需保留时,content 里要写明这是推断。工具输出、报错、命令结果直接给出的技术结论不受此限,照常记录。\n- 用户陈述与助手推断冲突时,事实归属以用户陈述为准(不要把助手推断记成事实);但 content 里要把两种说法如实并存,不要写成谁对谁错、也不要替用户裁决。\n- importance 只看这条事实对后续工作的影响面。用户表达满意、赞许或情绪,都不是提高 importance 的理由。\n\n`type` 只能取这七个值,不许自造:preference / project / decision / history / rejected_solution / pitfall / constraint。\n只输出 JSON 数组,每项形如 {\"type\":\"上段七个取值之一\",\"title\":\"简短标题\",\"content\":\"保留原始细节的一句话\",\"importance\":1-5,\"occurred_at\":\"可选:事件发生的绝对时间,ISO-8601\"}。\noccurred_at(可选):这条记忆所述事件**实际发生**的绝对时间,ISO-8601 带时区(如 2026-10-05T09:30:00+08:00)。会话里出现「昨天/前天/上周/上个月」这类相对时间时,按提示末尾给出的当前时间换算成绝对时间再填;没有任何时间依据、或换算不出来时,整条省略该字段——严禁编造,也不要把当前时间当成事件时间填进去。\n`type` 只能取上面枚举里的值,不要自造分类;每项只输出上面列出的键,不要附加 id、source 等额外字段。\n不要输出任何其他文字。", + "en": "You are the memory curation assistant. From the conversation content below, distill atomic memories worth remembering across sessions.\nAtomic-memory principle: each memory holds exactly one standalone fact/preference/decision — short and self-contained (keep raw details like numbers, names, paths, and conclusions verbatim in content; do not abstract or summarize them away). Prefer splitting into multiple entries over merging and losing detail. Extract 2-4 entries normally, 4-8 for information-dense conversations.\nStance discipline (this wins over the principle above):\n- Record only facts, preferences, decisions, constraints. A preference is the user's stance on a thing — keep recording it. Never record evaluations of the user's own personality, ability, mood or character, favourable or not (\"the user is very smart\", \"the user is frustrated today\" do not belong in memory).\n- The transcript's three roles differ in trustworthiness: \"User:\" is a user statement; \"Assistant:\" and \"Subagent delivery:\" conclusions or evaluations are inferences, not facts. Do not record one as a memory unless the user explicitly adopted it; if it must be kept, say in content that it is an inference. Technical conclusions that tool output, errors or command results state directly are exempt — record those as usual.\n- When a user statement conflicts with an assistant inference, the user statement wins on the facts (never record the assistant inference as fact); but keep both sides as they stand in content — do not write a verdict on who is right and do not adjudicate for the user.\n- importance reflects only how much this fact affects later work. The user's satisfaction, praise or emotion is never a reason to raise it.\nWrite every title and content in English.\n\n`type` may only be one of these seven values (do not invent categories): preference / project / decision / history / rejected_solution / pitfall / constraint.\nOutput only a JSON array, each item shaped {\"type\":\"one of the seven values above\",\"title\":\"short title\",\"content\":\"one sentence preserving original detail\",\"importance\":1-5,\"occurred_at\":\"optional: absolute time the event happened, ISO-8601\"}.\noccurred_at (optional): the absolute time the described event **actually happened**, in ISO-8601 with a timezone (e.g. 2026-10-05T09:30:00+08:00). When the conversation uses a relative time (yesterday / the day before / last week / last month), convert it into an absolute time against the current time given at the end of this prompt. Omit the field entirely when there is no temporal basis or it cannot be converted — never invent a value, and never pass the current time off as the event time.\n`type` must be one of the enumerated values above (do not invent categories); each item may contain only the listed keys - no id, source or other extra fields.\nOutput no other text." }, "codingSummary": { - "zh": "你是记忆库提炼助手。根据下面的会话内容(含用户输入、助手回答、工具调用与结果),提炼值得跨会话记住的原子记忆。\n原子记忆原则:每条记忆只装一个独立事实/偏好/决策,短小、自带完整上下文(把数字、报错信息、命令、路径、结论等原始细节保留在 content 里,不要抽象概括);宁可拆成多条也绝不合并丢细节。信息量一般提 2-4 条,信息密集的对话可提 4-8 条。\n立场纪律(与上条原则冲突时以本条为准):\n- 只记事实、偏好、决策与约束。偏好是用户对某件事的立场,照常记录;但不要记录对用户本人性格、能力、情绪、品行的评价,无论褒贬(「用户很聪明」「用户今天很沮丧」都不进记忆库)。\n- 转录里「用户:」「助手:」「子会话交付:」可信度不同:用户说的话是用户陈述;助手与子会话的结论、评价是推断,不是事实。除非用户明确采纳,否则不要把助手的结论或评价写成记忆;确需保留时,content 里要写明这是推断。工具输出、报错、命令结果直接给出的技术结论不受此限,照常记录。\n- 用户陈述与助手推断冲突时,事实归属以用户陈述为准(不要把助手推断记成事实);但 content 里要把两种说法如实并存,不要写成谁对谁错、也不要替用户裁决。\n- importance 只看这条事实对后续工作的影响面。用户表达满意、赞许或情绪,都不是提高 importance 的理由。\n只输出 JSON 数组,每项形如 {\"type\":\"preference|project|decision|history|rejected_solution|pitfall|constraint\",\"title\":\"简短标题\",\"content\":\"保留原始细节的一句话\",\"importance\":1-5,\"occurred_at\":\"可选:事件发生的绝对时间,ISO-8601\"}。\noccurred_at(可选):这条记忆所述事件**实际发生**的绝对时间,ISO-8601 带时区(如 2026-10-05T09:30:00+08:00)。会话里出现「昨天/前天/上周/上个月」这类相对时间时,按提示末尾给出的当前时间换算成绝对时间再填;没有任何时间依据、或换算不出来时,整条省略该字段——严禁编造,也不要把当前时间当成事件时间填进去。\n若对话涉及编码/调试,可额外提取编码类记忆:\n- rejected_solution:被否决/废弃的实现方案(content 含方案简述 + 被否决原因 + 最终采用方案)\n- pitfall:调试踩坑记录(content 含现象/报错 + 根因 + 解决/规避方法)\n- constraint:项目工程约束(content 含约束描述 + 来源)\n同一结论只记一条:若已在 pitfall 写了现象/报错 + 根因 + 规避方法,就不要再单开一条同义 constraint(反之亦然);时间序列或状态快照类内容按时间顺序写进同一条,不要拆成两条同义条目。\n普通闲聊、临时无关对话一律不提取编码类记忆。\\n`type` 只能取上面枚举里的值,不要自造分类;每项只输出上面列出的键,不要附加 id、source 等额外字段。\\n不要输出任何其他文字。", - "en": "You are the memory curation assistant. From the conversation content below (including user input, assistant replies, tool calls and results), distill atomic memories worth remembering across sessions.\nAtomic-memory principle: each memory holds exactly one standalone fact/preference/decision — short and self-contained (keep raw details like numbers, error messages, commands, paths, and conclusions verbatim in content; do not abstract them away). Prefer splitting into multiple entries over merging and losing detail. Extract 2-4 entries normally, 4-8 for information-dense conversations.\nStance discipline (this wins over the principle above):\n- Record only facts, preferences, decisions, constraints. A preference is the user's stance on a thing — keep recording it. Never record evaluations of the user's own personality, ability, mood or character, favourable or not (\"the user is very smart\", \"the user is frustrated today\" do not belong in memory).\n- The transcript's three roles differ in trustworthiness: \"User:\" is a user statement; \"Assistant:\" and \"Subagent delivery:\" conclusions or evaluations are inferences, not facts. Do not record one as a memory unless the user explicitly adopted it; if it must be kept, say in content that it is an inference. Technical conclusions that tool output, errors or command results state directly are exempt — record those as usual.\n- When a user statement conflicts with an assistant inference, the user statement wins on the facts (never record the assistant inference as fact); but keep both sides as they stand in content — do not write a verdict on who is right and do not adjudicate for the user.\n- importance reflects only how much this fact affects later work. The user's satisfaction, praise or emotion is never a reason to raise it.\nWrite every title and content in English.\nOutput only a JSON array, each item shaped {\"type\":\"preference|project|decision|history|rejected_solution|pitfall|constraint\",\"title\":\"short title\",\"content\":\"one sentence preserving original detail\",\"importance\":1-5,\"occurred_at\":\"optional: absolute time the event happened, ISO-8601\"}.\noccurred_at (optional): the absolute time the described event **actually happened**, in ISO-8601 with a timezone (e.g. 2026-10-05T09:30:00+08:00). When the conversation uses a relative time (yesterday / the day before / last week / last month), convert it into an absolute time against the current time given at the end of this prompt. Omit the field entirely when there is no temporal basis or it cannot be converted — never invent a value, and never pass the current time off as the event time.\nIf the conversation involves coding/debugging, additionally extract coding-specific memories:\n- rejected_solution: implementation approaches that were rejected or abandoned (content: brief approach + why rejected + what was adopted instead)\n- pitfall: debugging pitfalls (content: symptom/error + root cause + fix or workaround)\n- constraint: project engineering constraints (content: constraint description + source)\nRecord each conclusion once: if pitfall already carries the symptom/error + root cause + fix, do not open a synonymous constraint (and vice versa); keep a time series or state snapshot in one entry in time order instead of splitting it into two synonymous entries.\nNever extract coding-specific memories from casual small talk or temporary unrelated conversations.\\n`type` must be one of the enumerated values above (do not invent categories); each item may contain only the listed keys - no id, source or other extra fields.\\nOutput no other text." + "zh": "你是记忆库提炼助手。根据下面的会话内容(含用户输入、助手回答、工具调用与结果),提炼值得跨会话记住的原子记忆。\n原子记忆原则:每条记忆只装一个独立事实/偏好/决策,短小、自带完整上下文(把数字、报错信息、命令、路径、结论等原始细节保留在 content 里,不要抽象概括);宁可拆成多条也绝不合并丢细节。信息量一般提 2-4 条,信息密集的对话可提 4-8 条。\n立场纪律(与上条原则冲突时以本条为准):\n- 只记事实、偏好、决策与约束。偏好是用户对某件事的立场,照常记录;但不要记录对用户本人性格、能力、情绪、品行的评价,无论褒贬(「用户很聪明」「用户今天很沮丧」都不进记忆库)。\n- 转录里「用户:」「助手:」「子会话交付:」可信度不同:用户说的话是用户陈述;助手与子会话的结论、评价是推断,不是事实。除非用户明确采纳,否则不要把助手的结论或评价写成记忆;确需保留时,content 里要写明这是推断。工具输出、报错、命令结果直接给出的技术结论不受此限,照常记录。\n- 用户陈述与助手推断冲突时,事实归属以用户陈述为准(不要把助手推断记成事实);但 content 里要把两种说法如实并存,不要写成谁对谁错、也不要替用户裁决。\n- importance 只看这条事实对后续工作的影响面。用户表达满意、赞许或情绪,都不是提高 importance 的理由。\n\n`type` 只能取这七个值,不许自造:preference / project / decision / history / rejected_solution / pitfall / constraint。\n只输出 JSON 数组,每项形如 {\"type\":\"上段七个取值之一\",\"title\":\"简短标题\",\"content\":\"保留原始细节的一句话\",\"importance\":1-5,\"occurred_at\":\"可选:事件发生的绝对时间,ISO-8601\"}。\noccurred_at(可选):这条记忆所述事件**实际发生**的绝对时间,ISO-8601 带时区(如 2026-10-05T09:30:00+08:00)。会话里出现「昨天/前天/上周/上个月」这类相对时间时,按提示末尾给出的当前时间换算成绝对时间再填;没有任何时间依据、或换算不出来时,整条省略该字段——严禁编造,也不要把当前时间当成事件时间填进去。\n若对话涉及编码/调试,可额外提取编码类记忆:\n- rejected_solution:被否决/废弃的实现方案(content 含方案简述 + 被否决原因 + 最终采用方案)\n- pitfall:调试踩坑记录(content 含现象/报错 + 根因 + 解决/规避方法)\n- constraint:项目工程约束(content 含约束描述 + 来源)\n同一结论只记一条:若已在 pitfall 写了现象/报错 + 根因 + 规避方法,就不要再单开一条同义 constraint(反之亦然);时间序列或状态快照类内容按时间顺序写进同一条,不要拆成两条同义条目。\n普通闲聊、临时无关对话一律不提取编码类记忆。\\n`type` 只能取上面枚举里的值,不要自造分类;每项只输出上面列出的键,不要附加 id、source 等额外字段。\\n不要输出任何其他文字。", + "en": "You are the memory curation assistant. From the conversation content below (including user input, assistant replies, tool calls and results), distill atomic memories worth remembering across sessions.\nAtomic-memory principle: each memory holds exactly one standalone fact/preference/decision — short and self-contained (keep raw details like numbers, error messages, commands, paths, and conclusions verbatim in content; do not abstract them away). Prefer splitting into multiple entries over merging and losing detail. Extract 2-4 entries normally, 4-8 for information-dense conversations.\nStance discipline (this wins over the principle above):\n- Record only facts, preferences, decisions, constraints. A preference is the user's stance on a thing — keep recording it. Never record evaluations of the user's own personality, ability, mood or character, favourable or not (\"the user is very smart\", \"the user is frustrated today\" do not belong in memory).\n- The transcript's three roles differ in trustworthiness: \"User:\" is a user statement; \"Assistant:\" and \"Subagent delivery:\" conclusions or evaluations are inferences, not facts. Do not record one as a memory unless the user explicitly adopted it; if it must be kept, say in content that it is an inference. Technical conclusions that tool output, errors or command results state directly are exempt — record those as usual.\n- When a user statement conflicts with an assistant inference, the user statement wins on the facts (never record the assistant inference as fact); but keep both sides as they stand in content — do not write a verdict on who is right and do not adjudicate for the user.\n- importance reflects only how much this fact affects later work. The user's satisfaction, praise or emotion is never a reason to raise it.\nWrite every title and content in English.\n\n`type` may only be one of these seven values (do not invent categories): preference / project / decision / history / rejected_solution / pitfall / constraint.\nOutput only a JSON array, each item shaped {\"type\":\"one of the seven values above\",\"title\":\"short title\",\"content\":\"one sentence preserving original detail\",\"importance\":1-5,\"occurred_at\":\"optional: absolute time the event happened, ISO-8601\"}.\noccurred_at (optional): the absolute time the described event **actually happened**, in ISO-8601 with a timezone (e.g. 2026-10-05T09:30:00+08:00). When the conversation uses a relative time (yesterday / the day before / last week / last month), convert it into an absolute time against the current time given at the end of this prompt. Omit the field entirely when there is no temporal basis or it cannot be converted — never invent a value, and never pass the current time off as the event time.\nIf the conversation involves coding/debugging, additionally extract coding-specific memories:\n- rejected_solution: implementation approaches that were rejected or abandoned (content: brief approach + why rejected + what was adopted instead)\n- pitfall: debugging pitfalls (content: symptom/error + root cause + fix or workaround)\n- constraint: project engineering constraints (content: constraint description + source)\nRecord each conclusion once: if pitfall already carries the symptom/error + root cause + fix, do not open a synonymous constraint (and vice versa); keep a time series or state snapshot in one entry in time order instead of splitting it into two synonymous entries.\nNever extract coding-specific memories from casual small talk or temporary unrelated conversations.\\n`type` must be one of the enumerated values above (do not invent categories); each item may contain only the listed keys - no id, source or other extra fields.\\nOutput no other text." }, "dreamSummary": { "zh": "你是记忆库状态叙述助手。根据整理后的记忆,写一段 150-200 字的「当前状态」叙述:现在在做什么(活跃主题)、最近完成了什么或发生了什么变化、接下来明显的走向。只陈述记忆中有依据的事实,不要发明细节;偏好、项目、决策自然融入叙述而不必逐项罗列。叙述纪律:只写记忆里已写明的事实与偏好;不要给用户添上性格、能力、情绪方面的评价,也不要把助手自己的判断写成「用户认为」。某条记忆本身带褒贬口气时,只取它的事实内核,不要把那个口气复述进叙述。这段叙述会作为会话上下文常驻注入。只输出叙述文本,不要其他内容。", diff --git a/dsh-mneme/src/summarize.js b/dsh-mneme/src/summarize.js index da81e8c9..a2696ee3 100644 --- a/dsh-mneme/src/summarize.js +++ b/dsh-mneme/src/summarize.js @@ -270,10 +270,19 @@ export function parseSummaryJsonResult(raw) { // 则不能消费窗口,否则无效输出会永久推进 seq 游标。salvage 路径 // 没有「显式空数组」可言——ok 只看是否救回了条目。 const ok = salvaged ? entries.length > 0 : (arr.length === 0 || entries.length > 0); + // #712:`describeParseFailure` 在「有合法条目」时直接返回 null(entries.length > 0 + // 那个早退),于是**部分丢弃**这一型在审计里完全没有痕迹——一窗 10 条丢 4 条,行 + // 上仍是 ok:true、failure 为 undefined。整窗全丢才看得见,部分丢多少没人知道, + // 而后者才是日常形态。这里的计数与失败路径共用同一份 rejectReasons,只是不再 + // 依附于 failure 存在与否。纯审计:不改变 ok 判定、不改变 entries。 + const rejectedTotal = rejectReasons.not_object + rejectReasons.bad_type + + rejectReasons.bad_title + rejectReasons.bad_content; return { ok, entries, salvaged, + // 与 failure_kind 分开命名:那个说「哪种失败」,这个说「成功轮里丢了几条、为什么」。 + ...(rejectedTotal > 0 ? { rejects } : {}), // #502:失败时要能说出**是哪一种**失败。「压根没写数组」与「写了合法数组、但条目 // type 全不在枚举里」过去共用一句 invalid summary JSON,而两者要修的地方完全不同 // ——后者是菜单与闸门不一致(summary prompt 只列 4 个类型、VALID 吃 7 个),且失败 @@ -1403,6 +1412,18 @@ export function createSummarizer(ctx, service, config, deps = {}, sessionGate = } clearParseFailureStreak(session.id); const parsed = parsedResult.entries; + // #712:成功轮里被丢弃的条目(部分丢弃)——整窗全丢才走 failure 路径,只要还 + // 剩一条能入库,拒绝计数过去就整个消失。这里把它取出来,供下面的 audit.metadata + // 落账。纯审计,不参与任何判定。 + const rejectedSummary = parsedResult.rejects && parsedResult.rejects.reasons + ? { + total: parsedResult.rejects.reasons.not_object + + parsedResult.rejects.reasons.bad_type + + parsedResult.rejects.reasons.bad_title + + parsedResult.rejects.reasons.bad_content, + reasons: parsedResult.rejects.reasons + } + : null; // Issue #127 条数上限:0 = 不限(现状)。被截断的条数与去重命中数一并进 // 审计 metadata——此前产出条数完全由模型输出决定,用户无从自查。 // `opts.maxEntries` 是给「导入会话批量回填」用的单窗覆盖(src/backfill.js): @@ -1645,6 +1666,11 @@ export function createSummarizer(ctx, service, config, deps = {}, sessionGate = ...describeAuditPatch(describeStats), ...(imageSourcesWritten > 0 ? { imageSources: imageSourcesWritten } : {}), parsed: parsed.length, + // #712:成功行也要留下「丢了几条、为什么」。这里刻意不复用 failure_kind / + // reject_reasons 这两个键名——那两个属于失败路径,读法完全不同(一个说整窗 + // 没了,一个说这轮成了但丢了几条)。partial_rejects 只在确实丢过条目时出现, + // 没有丢条目的成功行 metadata 逐字节与旧版一致。 + ...(rejectedSummary ? { rejected: rejectedSummary.total, partial_rejects: rejectedSummary.reasons } : {}), ...(parsedResult.salvaged ? { json_salvaged: true } : {}), ...(capped > 0 ? { capped } : {}), ...(deduped > 0 ? { deduped, mode: dedupeMode, maxSim: Number(dedupeMaxSim.toFixed(4)) } : {}), diff --git a/dsh-mneme/test/summarize-parse-diagnostics.test.js b/dsh-mneme/test/summarize-parse-diagnostics.test.js index 42b7abca..34530b65 100644 --- a/dsh-mneme/test/summarize-parse-diagnostics.test.js +++ b/dsh-mneme/test/summarize-parse-diagnostics.test.js @@ -60,6 +60,35 @@ test("raw_tail 只在正文确实长于头部窗口时给(短输出不重复 assert.ok(meta.raw_head.length <= 300); }); +// #712:部分丢弃。整窗全丢才会产出 failure,只要还剩一条能入库,过去拒绝计数就 +// 整个消失(ok:true、failure:undefined)——库里 summarize_compress 的成功行带 +// reject_reasons 的记录是 0 条,于是「部分丢弃了多少」从来没有数据可查。 +test("部分丢弃:有一半条目被拒时仍要留下拒绝计数,而不是只在整窗全丢时才有", () => { + const mixed = [ + GOOD, + { id: 2, type: "环境/版本", content: "自造分类" }, + { type: "decision", name: "键名被顶掉", url: "https://example.invalid" } + ]; + const r = parseSummaryJsonResult(JSON.stringify(mixed)); + assert.equal(r.ok, true, "有合法条目就是成功轮——判定不变"); + assert.equal(r.failure, undefined, "失败诊断仍不许污染成功路径"); + assert.equal(r.entries.length, 1); + assert.deepEqual(r.rejects.reasons, { not_object: 0, bad_type: 1, bad_title: 1, bad_content: 0 }, + "丢了三减一=两条,按原因分开记"); +}); + +test("零丢弃的成功轮不产出 rejects 键(metadata 与旧版逐字节一致)", () => { + const r = parseSummaryJsonResult(JSON.stringify([GOOD])); + assert.equal(r.ok, true); + assert.equal(r.rejects, undefined, "没丢条目就不该多出这个键"); +}); + +test("空数组成功轮同样不产出 rejects", () => { + const r = parseSummaryJsonResult("[]"); + assert.equal(r.ok, true); + assert.equal(r.rejects, undefined); +}); + // prompt 与闸门对齐(报告者的第 3 条,零行为变更):菜单给全 7 个值、并写明不许自造。 // 中英两份都要锁——只改一种语言,另一种语言的窗口照样被滤空,而守卫看不见「两边一起过期」。 test("summary 提示词的枚举与 VALID 对齐,且中英两份都写明不许自造分类", () => { @@ -74,6 +103,24 @@ test("summary 提示词的枚举与 VALID 对齐,且中英两份都写明不 assert.ok(STR.prompts.codingSummary.zh.includes("rejected_solution") && STR.prompts.codingSummary.zh.includes("pitfall")); }); +// #712:枚举过去埋在 JSON 模板的键值里(`{"type":"preference|project|..."`那一串), +// 夹在十几个字段和 occurred_at 规则之间。模型写歪不是没看到枚举,是看到的位置太靠后。 +// 现在枚举独立成段、且在模板之前;模板里只用「上段取值之一」指回去。 +test("枚举独立成段并排在 JSON 模板之前,模板里不再内联枚举", () => { + for (const [lang, marker, enumHead, tpl] of [ + ["zh", "只能取这七个值", "preference / project / decision / history / rejected_solution / pitfall / constraint", "上段七个取值之一"], + ["en", "may only be one of these seven values", "preference / project / decision / history / rejected_solution / pitfall / constraint", "one of the seven values above"] + ]) { + const p = STR.prompts.summary[lang]; + const enumAt = p.indexOf(enumHead); + const tplAt = p.indexOf(tpl); + assert.ok(enumAt > -1, `summary(${lang}) 缺独立枚举段`); + assert.ok(p.includes(marker), `summary(${lang}) 枚举段缺「不许自造」的措辞`); + assert.ok(tplAt > enumAt, `summary(${lang}) 模板必须在枚举段之后`); + assert.ok(!p.includes(`"type":"preference|project|decision`), `summary(${lang}) 模板里不许再内联整串枚举`); + } +}); + // #712:过滤空窗的第二种成因——type 合法,但 title/content 被 name/url/notes 这类 // 别名顶掉。社区报告里 845 次 filtered-empty 有 76 次是这一型,而读数只带 // sample_types 时它跟「分类全都自造」长得一样,每次只能靠猜。现在逐条计数。 From 8205ede945512341ba85a1b585553a606b4b8275 Mon Sep 17 00:00:00 2001 From: modusensus Date: Wed, 18 Nov 2026 17:48:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(#712):=20=E8=A1=A5=E9=BD=90=E8=AF=84?= =?UTF-8?q?=E5=AE=A1=E4=B8=89=E5=A4=84=E2=80=94=E2=80=94=E8=8B=B1=E6=96=87?= =?UTF-8?q?=E5=8F=AF=E9=80=89=E3=80=81=E6=88=90=E5=8A=9F=E8=BD=AE=E5=9B=9E?= =?UTF-8?q?=E5=BD=92=E6=B5=8B=E8=AF=95=E3=80=81hasOwn=20=E6=96=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CodeRabbit 三条: 1. 英文 codingSummary 写成 `additionally extract`,等于必填;而 rejected_solution 的字段说明带着 "what was adopted instead",转录只说「这方案废了」没说新方案时, 模型只能编。改成 `you may additionally extract`,并中英两份都写明依据不足就 整条不提取、不要为凑字段补写。 2. 成功轮的 rejected / partial_rejects 没有回归测试——删掉那行 metadata 现有测试 也不会红。补一条端到端:喂同时含 bad_type 与 bad_title 的窗口,断言库里成功行 metadata 带 rejected=2、partial_rejects 分项,且不被 failure_kind / reject_reasons 污染。已做反向验证:删掉那行后该测试确实失败。 3. 断言 rejects 键不存在该用 Object.hasOwn——写成 `{ rejects: undefined }` 时, === 与 deepEqual 都看不出来,键其实已经存在。 --- dsh-mneme/lib/lang.js | 4 +- dsh-mneme/src/lang.js | 4 +- .../test/summarize-parse-diagnostics.test.js | 23 +++++++++- dsh-mneme/test/summarize.test.js | 43 +++++++++++++++++++ 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/dsh-mneme/lib/lang.js b/dsh-mneme/lib/lang.js index a7aab410..2cb800c4 100644 --- a/dsh-mneme/lib/lang.js +++ b/dsh-mneme/lib/lang.js @@ -15,8 +15,8 @@ const PROMPTS = { "en": "You are the memory curation assistant. From the conversation content below, distill atomic memories worth remembering across sessions.\nAtomic-memory principle: each memory holds exactly one standalone fact/preference/decision — short and self-contained (keep raw details like numbers, names, paths, and conclusions verbatim in content; do not abstract or summarize them away). Prefer splitting into multiple entries over merging and losing detail. Extract 2-4 entries normally, 4-8 for information-dense conversations.\nStance discipline (this wins over the principle above):\n- Record only facts, preferences, decisions, constraints. A preference is the user's stance on a thing — keep recording it. Never record evaluations of the user's own personality, ability, mood or character, favourable or not (\"the user is very smart\", \"the user is frustrated today\" do not belong in memory).\n- The transcript's three roles differ in trustworthiness: \"User:\" is a user statement; \"Assistant:\" and \"Subagent delivery:\" conclusions or evaluations are inferences, not facts. Do not record one as a memory unless the user explicitly adopted it; if it must be kept, say in content that it is an inference. Technical conclusions that tool output, errors or command results state directly are exempt — record those as usual.\n- When a user statement conflicts with an assistant inference, the user statement wins on the facts (never record the assistant inference as fact); but keep both sides as they stand in content — do not write a verdict on who is right and do not adjudicate for the user.\n- importance reflects only how much this fact affects later work. The user's satisfaction, praise or emotion is never a reason to raise it.\nWrite every title and content in English.\n\n`type` may only be one of these seven values (do not invent categories): preference / project / decision / history / rejected_solution / pitfall / constraint.\nOutput only a JSON array, each item shaped {\"type\":\"one of the seven values above\",\"title\":\"short title\",\"content\":\"one sentence preserving original detail\",\"importance\":1-5,\"occurred_at\":\"optional: absolute time the event happened, ISO-8601\"}.\noccurred_at (optional): the absolute time the described event **actually happened**, in ISO-8601 with a timezone (e.g. 2026-10-05T09:30:00+08:00). When the conversation uses a relative time (yesterday / the day before / last week / last month), convert it into an absolute time against the current time given at the end of this prompt. Omit the field entirely when there is no temporal basis or it cannot be converted — never invent a value, and never pass the current time off as the event time.\n`type` must be one of the enumerated values above (do not invent categories); each item may contain only the listed keys - no id, source or other extra fields.\nOutput no other text." }, "codingSummary": { - "zh": "你是记忆库提炼助手。根据下面的会话内容(含用户输入、助手回答、工具调用与结果),提炼值得跨会话记住的原子记忆。\n原子记忆原则:每条记忆只装一个独立事实/偏好/决策,短小、自带完整上下文(把数字、报错信息、命令、路径、结论等原始细节保留在 content 里,不要抽象概括);宁可拆成多条也绝不合并丢细节。信息量一般提 2-4 条,信息密集的对话可提 4-8 条。\n立场纪律(与上条原则冲突时以本条为准):\n- 只记事实、偏好、决策与约束。偏好是用户对某件事的立场,照常记录;但不要记录对用户本人性格、能力、情绪、品行的评价,无论褒贬(「用户很聪明」「用户今天很沮丧」都不进记忆库)。\n- 转录里「用户:」「助手:」「子会话交付:」可信度不同:用户说的话是用户陈述;助手与子会话的结论、评价是推断,不是事实。除非用户明确采纳,否则不要把助手的结论或评价写成记忆;确需保留时,content 里要写明这是推断。工具输出、报错、命令结果直接给出的技术结论不受此限,照常记录。\n- 用户陈述与助手推断冲突时,事实归属以用户陈述为准(不要把助手推断记成事实);但 content 里要把两种说法如实并存,不要写成谁对谁错、也不要替用户裁决。\n- importance 只看这条事实对后续工作的影响面。用户表达满意、赞许或情绪,都不是提高 importance 的理由。\n\n`type` 只能取这七个值,不许自造:preference / project / decision / history / rejected_solution / pitfall / constraint。\n只输出 JSON 数组,每项形如 {\"type\":\"上段七个取值之一\",\"title\":\"简短标题\",\"content\":\"保留原始细节的一句话\",\"importance\":1-5,\"occurred_at\":\"可选:事件发生的绝对时间,ISO-8601\"}。\noccurred_at(可选):这条记忆所述事件**实际发生**的绝对时间,ISO-8601 带时区(如 2026-10-05T09:30:00+08:00)。会话里出现「昨天/前天/上周/上个月」这类相对时间时,按提示末尾给出的当前时间换算成绝对时间再填;没有任何时间依据、或换算不出来时,整条省略该字段——严禁编造,也不要把当前时间当成事件时间填进去。\n若对话涉及编码/调试,可额外提取编码类记忆:\n- rejected_solution:被否决/废弃的实现方案(content 含方案简述 + 被否决原因 + 最终采用方案)\n- pitfall:调试踩坑记录(content 含现象/报错 + 根因 + 解决/规避方法)\n- constraint:项目工程约束(content 含约束描述 + 来源)\n同一结论只记一条:若已在 pitfall 写了现象/报错 + 根因 + 规避方法,就不要再单开一条同义 constraint(反之亦然);时间序列或状态快照类内容按时间顺序写进同一条,不要拆成两条同义条目。\n普通闲聊、临时无关对话一律不提取编码类记忆。\\n`type` 只能取上面枚举里的值,不要自造分类;每项只输出上面列出的键,不要附加 id、source 等额外字段。\\n不要输出任何其他文字。", - "en": "You are the memory curation assistant. From the conversation content below (including user input, assistant replies, tool calls and results), distill atomic memories worth remembering across sessions.\nAtomic-memory principle: each memory holds exactly one standalone fact/preference/decision — short and self-contained (keep raw details like numbers, error messages, commands, paths, and conclusions verbatim in content; do not abstract them away). Prefer splitting into multiple entries over merging and losing detail. Extract 2-4 entries normally, 4-8 for information-dense conversations.\nStance discipline (this wins over the principle above):\n- Record only facts, preferences, decisions, constraints. A preference is the user's stance on a thing — keep recording it. Never record evaluations of the user's own personality, ability, mood or character, favourable or not (\"the user is very smart\", \"the user is frustrated today\" do not belong in memory).\n- The transcript's three roles differ in trustworthiness: \"User:\" is a user statement; \"Assistant:\" and \"Subagent delivery:\" conclusions or evaluations are inferences, not facts. Do not record one as a memory unless the user explicitly adopted it; if it must be kept, say in content that it is an inference. Technical conclusions that tool output, errors or command results state directly are exempt — record those as usual.\n- When a user statement conflicts with an assistant inference, the user statement wins on the facts (never record the assistant inference as fact); but keep both sides as they stand in content — do not write a verdict on who is right and do not adjudicate for the user.\n- importance reflects only how much this fact affects later work. The user's satisfaction, praise or emotion is never a reason to raise it.\nWrite every title and content in English.\n\n`type` may only be one of these seven values (do not invent categories): preference / project / decision / history / rejected_solution / pitfall / constraint.\nOutput only a JSON array, each item shaped {\"type\":\"one of the seven values above\",\"title\":\"short title\",\"content\":\"one sentence preserving original detail\",\"importance\":1-5,\"occurred_at\":\"optional: absolute time the event happened, ISO-8601\"}.\noccurred_at (optional): the absolute time the described event **actually happened**, in ISO-8601 with a timezone (e.g. 2026-10-05T09:30:00+08:00). When the conversation uses a relative time (yesterday / the day before / last week / last month), convert it into an absolute time against the current time given at the end of this prompt. Omit the field entirely when there is no temporal basis or it cannot be converted — never invent a value, and never pass the current time off as the event time.\nIf the conversation involves coding/debugging, additionally extract coding-specific memories:\n- rejected_solution: implementation approaches that were rejected or abandoned (content: brief approach + why rejected + what was adopted instead)\n- pitfall: debugging pitfalls (content: symptom/error + root cause + fix or workaround)\n- constraint: project engineering constraints (content: constraint description + source)\nRecord each conclusion once: if pitfall already carries the symptom/error + root cause + fix, do not open a synonymous constraint (and vice versa); keep a time series or state snapshot in one entry in time order instead of splitting it into two synonymous entries.\nNever extract coding-specific memories from casual small talk or temporary unrelated conversations.\\n`type` must be one of the enumerated values above (do not invent categories); each item may contain only the listed keys - no id, source or other extra fields.\\nOutput no other text." + "zh": "你是记忆库提炼助手。根据下面的会话内容(含用户输入、助手回答、工具调用与结果),提炼值得跨会话记住的原子记忆。\n原子记忆原则:每条记忆只装一个独立事实/偏好/决策,短小、自带完整上下文(把数字、报错信息、命令、路径、结论等原始细节保留在 content 里,不要抽象概括);宁可拆成多条也绝不合并丢细节。信息量一般提 2-4 条,信息密集的对话可提 4-8 条。\n立场纪律(与上条原则冲突时以本条为准):\n- 只记事实、偏好、决策与约束。偏好是用户对某件事的立场,照常记录;但不要记录对用户本人性格、能力、情绪、品行的评价,无论褒贬(「用户很聪明」「用户今天很沮丧」都不进记忆库)。\n- 转录里「用户:」「助手:」「子会话交付:」可信度不同:用户说的话是用户陈述;助手与子会话的结论、评价是推断,不是事实。除非用户明确采纳,否则不要把助手的结论或评价写成记忆;确需保留时,content 里要写明这是推断。工具输出、报错、命令结果直接给出的技术结论不受此限,照常记录。\n- 用户陈述与助手推断冲突时,事实归属以用户陈述为准(不要把助手推断记成事实);但 content 里要把两种说法如实并存,不要写成谁对谁错、也不要替用户裁决。\n- importance 只看这条事实对后续工作的影响面。用户表达满意、赞许或情绪,都不是提高 importance 的理由。\n\n`type` 只能取这七个值,不许自造:preference / project / decision / history / rejected_solution / pitfall / constraint。\n只输出 JSON 数组,每项形如 {\"type\":\"上段七个取值之一\",\"title\":\"简短标题\",\"content\":\"保留原始细节的一句话\",\"importance\":1-5,\"occurred_at\":\"可选:事件发生的绝对时间,ISO-8601\"}。\noccurred_at(可选):这条记忆所述事件**实际发生**的绝对时间,ISO-8601 带时区(如 2026-10-05T09:30:00+08:00)。会话里出现「昨天/前天/上周/上个月」这类相对时间时,按提示末尾给出的当前时间换算成绝对时间再填;没有任何时间依据、或换算不出来时,整条省略该字段——严禁编造,也不要把当前时间当成事件时间填进去。\n若对话涉及编码/调试,可额外提取编码类记忆:\n- rejected_solution:被否决/废弃的实现方案(content 含方案简述 + 被否决原因 + 最终采用方案)\n- pitfall:调试踩坑记录(content 含现象/报错 + 根因 + 解决/规避方法)\n- constraint:项目工程约束(content 含约束描述 + 来源)\n以上任一类若转录依据不足(例如只说了某个方案被废弃、没说最终采用什么),就整条不提取,不要为凑齐字段去补写——宁可少记一条。\n同一结论只记一条:若已在 pitfall 写了现象/报错 + 根因 + 规避方法,就不要再单开一条同义 constraint(反之亦然);时间序列或状态快照类内容按时间顺序写进同一条,不要拆成两条同义条目。\n普通闲聊、临时无关对话一律不提取编码类记忆。\\n`type` 只能取上面枚举里的值,不要自造分类;每项只输出上面列出的键,不要附加 id、source 等额外字段。\\n不要输出任何其他文字。", + "en": "You are the memory curation assistant. From the conversation content below (including user input, assistant replies, tool calls and results), distill atomic memories worth remembering across sessions.\nAtomic-memory principle: each memory holds exactly one standalone fact/preference/decision — short and self-contained (keep raw details like numbers, error messages, commands, paths, and conclusions verbatim in content; do not abstract them away). Prefer splitting into multiple entries over merging and losing detail. Extract 2-4 entries normally, 4-8 for information-dense conversations.\nStance discipline (this wins over the principle above):\n- Record only facts, preferences, decisions, constraints. A preference is the user's stance on a thing — keep recording it. Never record evaluations of the user's own personality, ability, mood or character, favourable or not (\"the user is very smart\", \"the user is frustrated today\" do not belong in memory).\n- The transcript's three roles differ in trustworthiness: \"User:\" is a user statement; \"Assistant:\" and \"Subagent delivery:\" conclusions or evaluations are inferences, not facts. Do not record one as a memory unless the user explicitly adopted it; if it must be kept, say in content that it is an inference. Technical conclusions that tool output, errors or command results state directly are exempt — record those as usual.\n- When a user statement conflicts with an assistant inference, the user statement wins on the facts (never record the assistant inference as fact); but keep both sides as they stand in content — do not write a verdict on who is right and do not adjudicate for the user.\n- importance reflects only how much this fact affects later work. The user's satisfaction, praise or emotion is never a reason to raise it.\nWrite every title and content in English.\n\n`type` may only be one of these seven values (do not invent categories): preference / project / decision / history / rejected_solution / pitfall / constraint.\nOutput only a JSON array, each item shaped {\"type\":\"one of the seven values above\",\"title\":\"short title\",\"content\":\"one sentence preserving original detail\",\"importance\":1-5,\"occurred_at\":\"optional: absolute time the event happened, ISO-8601\"}.\noccurred_at (optional): the absolute time the described event **actually happened**, in ISO-8601 with a timezone (e.g. 2026-10-05T09:30:00+08:00). When the conversation uses a relative time (yesterday / the day before / last week / last month), convert it into an absolute time against the current time given at the end of this prompt. Omit the field entirely when there is no temporal basis or it cannot be converted — never invent a value, and never pass the current time off as the event time.\nIf the conversation involves coding/debugging, you may additionally extract coding-specific memories:\n- rejected_solution: implementation approaches that were rejected or abandoned (content: brief approach + why rejected + what was adopted instead)\n- pitfall: debugging pitfalls (content: symptom/error + root cause + fix or workaround)\n- constraint: project engineering constraints (content: constraint description + source)\nSkip any of these when the transcript does not support every part — e.g. an approach was abandoned but what replaced it is never stated: then do not extract that entry at all rather than inventing the missing part. Recording fewer entries is the right call.\nRecord each conclusion once: if pitfall already carries the symptom/error + root cause + fix, do not open a synonymous constraint (and vice versa); keep a time series or state snapshot in one entry in time order instead of splitting it into two synonymous entries.\nNever extract coding-specific memories from casual small talk or temporary unrelated conversations.\\n`type` must be one of the enumerated values above (do not invent categories); each item may contain only the listed keys - no id, source or other extra fields.\\nOutput no other text." }, "dreamSummary": { "zh": "你是记忆库状态叙述助手。根据整理后的记忆,写一段 150-200 字的「当前状态」叙述:现在在做什么(活跃主题)、最近完成了什么或发生了什么变化、接下来明显的走向。只陈述记忆中有依据的事实,不要发明细节;偏好、项目、决策自然融入叙述而不必逐项罗列。叙述纪律:只写记忆里已写明的事实与偏好;不要给用户添上性格、能力、情绪方面的评价,也不要把助手自己的判断写成「用户认为」。某条记忆本身带褒贬口气时,只取它的事实内核,不要把那个口气复述进叙述。这段叙述会作为会话上下文常驻注入。只输出叙述文本,不要其他内容。", diff --git a/dsh-mneme/src/lang.js b/dsh-mneme/src/lang.js index a7aab410..2cb800c4 100644 --- a/dsh-mneme/src/lang.js +++ b/dsh-mneme/src/lang.js @@ -15,8 +15,8 @@ const PROMPTS = { "en": "You are the memory curation assistant. From the conversation content below, distill atomic memories worth remembering across sessions.\nAtomic-memory principle: each memory holds exactly one standalone fact/preference/decision — short and self-contained (keep raw details like numbers, names, paths, and conclusions verbatim in content; do not abstract or summarize them away). Prefer splitting into multiple entries over merging and losing detail. Extract 2-4 entries normally, 4-8 for information-dense conversations.\nStance discipline (this wins over the principle above):\n- Record only facts, preferences, decisions, constraints. A preference is the user's stance on a thing — keep recording it. Never record evaluations of the user's own personality, ability, mood or character, favourable or not (\"the user is very smart\", \"the user is frustrated today\" do not belong in memory).\n- The transcript's three roles differ in trustworthiness: \"User:\" is a user statement; \"Assistant:\" and \"Subagent delivery:\" conclusions or evaluations are inferences, not facts. Do not record one as a memory unless the user explicitly adopted it; if it must be kept, say in content that it is an inference. Technical conclusions that tool output, errors or command results state directly are exempt — record those as usual.\n- When a user statement conflicts with an assistant inference, the user statement wins on the facts (never record the assistant inference as fact); but keep both sides as they stand in content — do not write a verdict on who is right and do not adjudicate for the user.\n- importance reflects only how much this fact affects later work. The user's satisfaction, praise or emotion is never a reason to raise it.\nWrite every title and content in English.\n\n`type` may only be one of these seven values (do not invent categories): preference / project / decision / history / rejected_solution / pitfall / constraint.\nOutput only a JSON array, each item shaped {\"type\":\"one of the seven values above\",\"title\":\"short title\",\"content\":\"one sentence preserving original detail\",\"importance\":1-5,\"occurred_at\":\"optional: absolute time the event happened, ISO-8601\"}.\noccurred_at (optional): the absolute time the described event **actually happened**, in ISO-8601 with a timezone (e.g. 2026-10-05T09:30:00+08:00). When the conversation uses a relative time (yesterday / the day before / last week / last month), convert it into an absolute time against the current time given at the end of this prompt. Omit the field entirely when there is no temporal basis or it cannot be converted — never invent a value, and never pass the current time off as the event time.\n`type` must be one of the enumerated values above (do not invent categories); each item may contain only the listed keys - no id, source or other extra fields.\nOutput no other text." }, "codingSummary": { - "zh": "你是记忆库提炼助手。根据下面的会话内容(含用户输入、助手回答、工具调用与结果),提炼值得跨会话记住的原子记忆。\n原子记忆原则:每条记忆只装一个独立事实/偏好/决策,短小、自带完整上下文(把数字、报错信息、命令、路径、结论等原始细节保留在 content 里,不要抽象概括);宁可拆成多条也绝不合并丢细节。信息量一般提 2-4 条,信息密集的对话可提 4-8 条。\n立场纪律(与上条原则冲突时以本条为准):\n- 只记事实、偏好、决策与约束。偏好是用户对某件事的立场,照常记录;但不要记录对用户本人性格、能力、情绪、品行的评价,无论褒贬(「用户很聪明」「用户今天很沮丧」都不进记忆库)。\n- 转录里「用户:」「助手:」「子会话交付:」可信度不同:用户说的话是用户陈述;助手与子会话的结论、评价是推断,不是事实。除非用户明确采纳,否则不要把助手的结论或评价写成记忆;确需保留时,content 里要写明这是推断。工具输出、报错、命令结果直接给出的技术结论不受此限,照常记录。\n- 用户陈述与助手推断冲突时,事实归属以用户陈述为准(不要把助手推断记成事实);但 content 里要把两种说法如实并存,不要写成谁对谁错、也不要替用户裁决。\n- importance 只看这条事实对后续工作的影响面。用户表达满意、赞许或情绪,都不是提高 importance 的理由。\n\n`type` 只能取这七个值,不许自造:preference / project / decision / history / rejected_solution / pitfall / constraint。\n只输出 JSON 数组,每项形如 {\"type\":\"上段七个取值之一\",\"title\":\"简短标题\",\"content\":\"保留原始细节的一句话\",\"importance\":1-5,\"occurred_at\":\"可选:事件发生的绝对时间,ISO-8601\"}。\noccurred_at(可选):这条记忆所述事件**实际发生**的绝对时间,ISO-8601 带时区(如 2026-10-05T09:30:00+08:00)。会话里出现「昨天/前天/上周/上个月」这类相对时间时,按提示末尾给出的当前时间换算成绝对时间再填;没有任何时间依据、或换算不出来时,整条省略该字段——严禁编造,也不要把当前时间当成事件时间填进去。\n若对话涉及编码/调试,可额外提取编码类记忆:\n- rejected_solution:被否决/废弃的实现方案(content 含方案简述 + 被否决原因 + 最终采用方案)\n- pitfall:调试踩坑记录(content 含现象/报错 + 根因 + 解决/规避方法)\n- constraint:项目工程约束(content 含约束描述 + 来源)\n同一结论只记一条:若已在 pitfall 写了现象/报错 + 根因 + 规避方法,就不要再单开一条同义 constraint(反之亦然);时间序列或状态快照类内容按时间顺序写进同一条,不要拆成两条同义条目。\n普通闲聊、临时无关对话一律不提取编码类记忆。\\n`type` 只能取上面枚举里的值,不要自造分类;每项只输出上面列出的键,不要附加 id、source 等额外字段。\\n不要输出任何其他文字。", - "en": "You are the memory curation assistant. From the conversation content below (including user input, assistant replies, tool calls and results), distill atomic memories worth remembering across sessions.\nAtomic-memory principle: each memory holds exactly one standalone fact/preference/decision — short and self-contained (keep raw details like numbers, error messages, commands, paths, and conclusions verbatim in content; do not abstract them away). Prefer splitting into multiple entries over merging and losing detail. Extract 2-4 entries normally, 4-8 for information-dense conversations.\nStance discipline (this wins over the principle above):\n- Record only facts, preferences, decisions, constraints. A preference is the user's stance on a thing — keep recording it. Never record evaluations of the user's own personality, ability, mood or character, favourable or not (\"the user is very smart\", \"the user is frustrated today\" do not belong in memory).\n- The transcript's three roles differ in trustworthiness: \"User:\" is a user statement; \"Assistant:\" and \"Subagent delivery:\" conclusions or evaluations are inferences, not facts. Do not record one as a memory unless the user explicitly adopted it; if it must be kept, say in content that it is an inference. Technical conclusions that tool output, errors or command results state directly are exempt — record those as usual.\n- When a user statement conflicts with an assistant inference, the user statement wins on the facts (never record the assistant inference as fact); but keep both sides as they stand in content — do not write a verdict on who is right and do not adjudicate for the user.\n- importance reflects only how much this fact affects later work. The user's satisfaction, praise or emotion is never a reason to raise it.\nWrite every title and content in English.\n\n`type` may only be one of these seven values (do not invent categories): preference / project / decision / history / rejected_solution / pitfall / constraint.\nOutput only a JSON array, each item shaped {\"type\":\"one of the seven values above\",\"title\":\"short title\",\"content\":\"one sentence preserving original detail\",\"importance\":1-5,\"occurred_at\":\"optional: absolute time the event happened, ISO-8601\"}.\noccurred_at (optional): the absolute time the described event **actually happened**, in ISO-8601 with a timezone (e.g. 2026-10-05T09:30:00+08:00). When the conversation uses a relative time (yesterday / the day before / last week / last month), convert it into an absolute time against the current time given at the end of this prompt. Omit the field entirely when there is no temporal basis or it cannot be converted — never invent a value, and never pass the current time off as the event time.\nIf the conversation involves coding/debugging, additionally extract coding-specific memories:\n- rejected_solution: implementation approaches that were rejected or abandoned (content: brief approach + why rejected + what was adopted instead)\n- pitfall: debugging pitfalls (content: symptom/error + root cause + fix or workaround)\n- constraint: project engineering constraints (content: constraint description + source)\nRecord each conclusion once: if pitfall already carries the symptom/error + root cause + fix, do not open a synonymous constraint (and vice versa); keep a time series or state snapshot in one entry in time order instead of splitting it into two synonymous entries.\nNever extract coding-specific memories from casual small talk or temporary unrelated conversations.\\n`type` must be one of the enumerated values above (do not invent categories); each item may contain only the listed keys - no id, source or other extra fields.\\nOutput no other text." + "zh": "你是记忆库提炼助手。根据下面的会话内容(含用户输入、助手回答、工具调用与结果),提炼值得跨会话记住的原子记忆。\n原子记忆原则:每条记忆只装一个独立事实/偏好/决策,短小、自带完整上下文(把数字、报错信息、命令、路径、结论等原始细节保留在 content 里,不要抽象概括);宁可拆成多条也绝不合并丢细节。信息量一般提 2-4 条,信息密集的对话可提 4-8 条。\n立场纪律(与上条原则冲突时以本条为准):\n- 只记事实、偏好、决策与约束。偏好是用户对某件事的立场,照常记录;但不要记录对用户本人性格、能力、情绪、品行的评价,无论褒贬(「用户很聪明」「用户今天很沮丧」都不进记忆库)。\n- 转录里「用户:」「助手:」「子会话交付:」可信度不同:用户说的话是用户陈述;助手与子会话的结论、评价是推断,不是事实。除非用户明确采纳,否则不要把助手的结论或评价写成记忆;确需保留时,content 里要写明这是推断。工具输出、报错、命令结果直接给出的技术结论不受此限,照常记录。\n- 用户陈述与助手推断冲突时,事实归属以用户陈述为准(不要把助手推断记成事实);但 content 里要把两种说法如实并存,不要写成谁对谁错、也不要替用户裁决。\n- importance 只看这条事实对后续工作的影响面。用户表达满意、赞许或情绪,都不是提高 importance 的理由。\n\n`type` 只能取这七个值,不许自造:preference / project / decision / history / rejected_solution / pitfall / constraint。\n只输出 JSON 数组,每项形如 {\"type\":\"上段七个取值之一\",\"title\":\"简短标题\",\"content\":\"保留原始细节的一句话\",\"importance\":1-5,\"occurred_at\":\"可选:事件发生的绝对时间,ISO-8601\"}。\noccurred_at(可选):这条记忆所述事件**实际发生**的绝对时间,ISO-8601 带时区(如 2026-10-05T09:30:00+08:00)。会话里出现「昨天/前天/上周/上个月」这类相对时间时,按提示末尾给出的当前时间换算成绝对时间再填;没有任何时间依据、或换算不出来时,整条省略该字段——严禁编造,也不要把当前时间当成事件时间填进去。\n若对话涉及编码/调试,可额外提取编码类记忆:\n- rejected_solution:被否决/废弃的实现方案(content 含方案简述 + 被否决原因 + 最终采用方案)\n- pitfall:调试踩坑记录(content 含现象/报错 + 根因 + 解决/规避方法)\n- constraint:项目工程约束(content 含约束描述 + 来源)\n以上任一类若转录依据不足(例如只说了某个方案被废弃、没说最终采用什么),就整条不提取,不要为凑齐字段去补写——宁可少记一条。\n同一结论只记一条:若已在 pitfall 写了现象/报错 + 根因 + 规避方法,就不要再单开一条同义 constraint(反之亦然);时间序列或状态快照类内容按时间顺序写进同一条,不要拆成两条同义条目。\n普通闲聊、临时无关对话一律不提取编码类记忆。\\n`type` 只能取上面枚举里的值,不要自造分类;每项只输出上面列出的键,不要附加 id、source 等额外字段。\\n不要输出任何其他文字。", + "en": "You are the memory curation assistant. From the conversation content below (including user input, assistant replies, tool calls and results), distill atomic memories worth remembering across sessions.\nAtomic-memory principle: each memory holds exactly one standalone fact/preference/decision — short and self-contained (keep raw details like numbers, error messages, commands, paths, and conclusions verbatim in content; do not abstract them away). Prefer splitting into multiple entries over merging and losing detail. Extract 2-4 entries normally, 4-8 for information-dense conversations.\nStance discipline (this wins over the principle above):\n- Record only facts, preferences, decisions, constraints. A preference is the user's stance on a thing — keep recording it. Never record evaluations of the user's own personality, ability, mood or character, favourable or not (\"the user is very smart\", \"the user is frustrated today\" do not belong in memory).\n- The transcript's three roles differ in trustworthiness: \"User:\" is a user statement; \"Assistant:\" and \"Subagent delivery:\" conclusions or evaluations are inferences, not facts. Do not record one as a memory unless the user explicitly adopted it; if it must be kept, say in content that it is an inference. Technical conclusions that tool output, errors or command results state directly are exempt — record those as usual.\n- When a user statement conflicts with an assistant inference, the user statement wins on the facts (never record the assistant inference as fact); but keep both sides as they stand in content — do not write a verdict on who is right and do not adjudicate for the user.\n- importance reflects only how much this fact affects later work. The user's satisfaction, praise or emotion is never a reason to raise it.\nWrite every title and content in English.\n\n`type` may only be one of these seven values (do not invent categories): preference / project / decision / history / rejected_solution / pitfall / constraint.\nOutput only a JSON array, each item shaped {\"type\":\"one of the seven values above\",\"title\":\"short title\",\"content\":\"one sentence preserving original detail\",\"importance\":1-5,\"occurred_at\":\"optional: absolute time the event happened, ISO-8601\"}.\noccurred_at (optional): the absolute time the described event **actually happened**, in ISO-8601 with a timezone (e.g. 2026-10-05T09:30:00+08:00). When the conversation uses a relative time (yesterday / the day before / last week / last month), convert it into an absolute time against the current time given at the end of this prompt. Omit the field entirely when there is no temporal basis or it cannot be converted — never invent a value, and never pass the current time off as the event time.\nIf the conversation involves coding/debugging, you may additionally extract coding-specific memories:\n- rejected_solution: implementation approaches that were rejected or abandoned (content: brief approach + why rejected + what was adopted instead)\n- pitfall: debugging pitfalls (content: symptom/error + root cause + fix or workaround)\n- constraint: project engineering constraints (content: constraint description + source)\nSkip any of these when the transcript does not support every part — e.g. an approach was abandoned but what replaced it is never stated: then do not extract that entry at all rather than inventing the missing part. Recording fewer entries is the right call.\nRecord each conclusion once: if pitfall already carries the symptom/error + root cause + fix, do not open a synonymous constraint (and vice versa); keep a time series or state snapshot in one entry in time order instead of splitting it into two synonymous entries.\nNever extract coding-specific memories from casual small talk or temporary unrelated conversations.\\n`type` must be one of the enumerated values above (do not invent categories); each item may contain only the listed keys - no id, source or other extra fields.\\nOutput no other text." }, "dreamSummary": { "zh": "你是记忆库状态叙述助手。根据整理后的记忆,写一段 150-200 字的「当前状态」叙述:现在在做什么(活跃主题)、最近完成了什么或发生了什么变化、接下来明显的走向。只陈述记忆中有依据的事实,不要发明细节;偏好、项目、决策自然融入叙述而不必逐项罗列。叙述纪律:只写记忆里已写明的事实与偏好;不要给用户添上性格、能力、情绪方面的评价,也不要把助手自己的判断写成「用户认为」。某条记忆本身带褒贬口气时,只取它的事实内核,不要把那个口气复述进叙述。这段叙述会作为会话上下文常驻注入。只输出叙述文本,不要其他内容。", diff --git a/dsh-mneme/test/summarize-parse-diagnostics.test.js b/dsh-mneme/test/summarize-parse-diagnostics.test.js index 34530b65..3be41d15 100644 --- a/dsh-mneme/test/summarize-parse-diagnostics.test.js +++ b/dsh-mneme/test/summarize-parse-diagnostics.test.js @@ -80,13 +80,15 @@ test("部分丢弃:有一半条目被拒时仍要留下拒绝计数,而不 test("零丢弃的成功轮不产出 rejects 键(metadata 与旧版逐字节一致)", () => { const r = parseSummaryJsonResult(JSON.stringify([GOOD])); assert.equal(r.ok, true); - assert.equal(r.rejects, undefined, "没丢条目就不该多出这个键"); + // 用 hasOwn 而不是断言 undefined:扩展开来时若写成 `{ rejects: undefined }`, + // 键其实已经存在了,只是值为 undefined——deepEqual 与 === 都看不出来。 + assert.equal(Object.hasOwn(r, "rejects"), false, "没丢条目就不该多出这个键"); }); test("空数组成功轮同样不产出 rejects", () => { const r = parseSummaryJsonResult("[]"); assert.equal(r.ok, true); - assert.equal(r.rejects, undefined); + assert.equal(Object.hasOwn(r, "rejects"), false); }); // prompt 与闸门对齐(报告者的第 3 条,零行为变更):菜单给全 7 个值、并写明不许自造。 @@ -103,6 +105,23 @@ test("summary 提示词的枚举与 VALID 对齐,且中英两份都写明不 assert.ok(STR.prompts.codingSummary.zh.includes("rejected_solution") && STR.prompts.codingSummary.zh.includes("pitfall")); }); +// #712:编码类三类(rejected_solution / pitfall / constraint)是「可提取」,不是「必须提取」。 +// 英文版原来写成 `additionally extract`,等于要求必填;而 rejected_solution 的字段说明里 +// 带着 "what was adopted instead",转录只说「这个方案废了」、没说新方案时,模型只能编。 +// 中英两份都要写成可选、并明确依据不足就整条不提取。 +test("编码类记忆是可选提取:中英两份都写明依据不足就整条不提取", () => { + const zh = STR.prompts.codingSummary.zh; + assert.ok(zh.includes("可额外提取"), "中文要说「可」额外提取,不是必须"); + assert.match(zh, /依据不足[\s\S]{0,80}整条不提取/, "中文要写明依据不足就整条不提取"); + + const en = STR.prompts.codingSummary.en; + assert.ok(en.includes("you may additionally extract"), "英文要说 may,不是祈使的 extract"); + // 否定式要卡住「整句陈述句开头」的那种老写法,不能只查子串——「you may additionally + // extract」本身就含「additionally extract」,用子串会把自己判红。 + assert.ok(!/coding\/debugging,\s*additionally extract/.test(en), "英文不许再写成必提取"); + assert.match(en, /do not extract that entry at all/, "英文要写明依据不足就整条不提取"); +}); + // #712:枚举过去埋在 JSON 模板的键值里(`{"type":"preference|project|..."`那一串), // 夹在十几个字段和 occurred_at 规则之间。模型写歪不是没看到枚举,是看到的位置太靠后。 // 现在枚举独立成段、且在模板之前;模板里只用「上段取值之一」指回去。 diff --git a/dsh-mneme/test/summarize.test.js b/dsh-mneme/test/summarize.test.js index 9f95acce..9804e101 100644 --- a/dsh-mneme/test/summarize.test.js +++ b/dsh-mneme/test/summarize.test.js @@ -822,6 +822,49 @@ test("a JSON-crashed window with salvageable objects is recovered, consumed once assert.equal(service.count(), 2, "no duplicate writes on the second turn/end"); }); +// #712:成功轮里被丢弃的条目必须能在审计里看见。此前只有整窗全丢才写诊断 +// (describeParseFailure 的 `if (entries.length > 0) return null;` 早退),只要还剩 +// 一条能入库,拒绝计数就整个消失——库里 summarize_compress 的成功行带 +// reject_reasons 的记录是 0 条,「部分丢弃多少」从来没有数据。 +test("#712 部分丢弃的成功轮在审计里留下拒绝总数与按原因分项", async (t) => { + const mixed = `[ + {"type":"constraint","title":"预算","content":"总额 $12,400","importance":4}, + {"type":"环境/版本","title":"自造分类","content":"枚举外的 type"}, + {"type":"decision","name":"键名被顶掉","url":"https://example.invalid"} + ]`; + const { events, service, store, calls, summarizer } = setup({ distillRateLimitIntervalMs: 0 }, { + stream() { + return (async function* () { + yield { type: "block-start", block: { type: "text" } }; + yield { type: "text-delta", delta: mixed }; + yield { type: "finish", kind: "ok" }; + })(); + } + }); + t.after(() => { summarizer.dispose(); store.close(); }); + const handler = events.find((e) => e.name === "session/event").fn; + const session = { + id: "s-partial-rejects", + requestHeader: () => ({ config: testConfig({ provider: "deepseek", model: "deepseek-chat" }) }), + events: [userMessage("部分条目被拒的蒸馏窗口", 1), { seq: 2, type: "turn/end" }] + }; + + await handler(session, { seq: 2, type: "turn/end" }); + assert.equal(service.count(), 1, "还剩一条能入库就是成功轮,判定不变"); + const audit = service.listLlmAudits({ source: "autoSummarize" }).find((r) => r.status === "success"); + assert.ok(audit, "部分丢弃仍记成成功"); + // metadata 读回来可能是串也可能是对象,两种形状都归一(同 filtered-empty 那条锁的写法) + const meta = typeof audit.metadata === "string" ? JSON.parse(audit.metadata) : audit.metadata; + assert.equal(meta.rejected, 2, "三条里丢了两条,总数要落账"); + assert.deepEqual(meta.partial_rejects, { not_object: 0, bad_type: 1, bad_title: 1, bad_content: 0 }, + "按原因分开记,才看得出是自造分类还是键名顶掉"); + assert.equal(meta.failure_kind, undefined, "成功轮不许被失败诊断的键名污染"); + assert.equal(meta.reject_reasons, undefined); + // parsed 记的是「解析后活下来的条数」(= 去重/截断前的可用条目),不是模型给出的原始 + // 条数。这里是 1 不是 3——别把它误读成「模型只写了 1 条」,原始条数看 rejected 加它。 + assert.equal(meta.parsed, 1, "parsed 仍是存活条数,不被新增字段改变"); +}); + test("a JSON-crashed window with nothing salvageable stays retryable (issue #339)", async (t) => { const hopeless = `[ { " "type": "history", "title": "坏", "content": "语法错误" }