From 28e71786d96c0fbc78ca6abbde9e8779519d2bb8 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 02:11:41 +0800 Subject: [PATCH] fix: carry the user's reply to a pending question verbatim (BUG-2284 follow-up) The split model completed the user's answer with a clause they never said. The answer line is now assembled by program from the user's own clauses; situation statements without a pending question are carried the same way. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq --- docs/BUG_HISTORY.md | 1 + frontend/src/lib/consultation-turn-split.ts | 47 ++++++++++--- frontend/src/mastra/product-voice.ts | 1 + .../chat-answer-to-question-2284.test.ts | 66 ++++++++++++++++++- 4 files changed, 103 insertions(+), 12 deletions(-) diff --git a/docs/BUG_HISTORY.md b/docs/BUG_HISTORY.md index 698997927..6ed1f5102 100644 --- a/docs/BUG_HISTORY.md +++ b/docs/BUG_HISTORY.md @@ -30873,4 +30873,5 @@ - 关联记录:BUG-1980(反馈隔离、只有反馈的一轮)、BUG-1977、BUG-2161 / BUG-2160(计划时机先确认)、BUG-2179(固定追问走免费结算)、BUG-1539(追问建议调用)、BUG-2241(结尾那句问话归正文)。 - 未做:个人报告和年运报告问答的拆分没有带上一轮回答(那里的回答不会存 `pendingQuestion`);BUG-2281 的结构化回答上线后,问用户的那一句可改由写作调用直接输出。 - 合并到 BUG-2281(2026-11-24,分支 `claude/chat-ux-2284`):问用户的那一句现在从哪来——BUG-2281 让回答自己写「## 接着问」,原来那次单独的追问建议调用只给没写接着问的回答兜底,不能再靠它找「问用户:」。改为回答自己带出:写法规则(`product-voice.ts` 首轮和追问轮、`consultation-thinking-plan.ts` 两处结构说明、`plan-timing-clarify.ts` PLAN_TIMING_RULE)要求把唯一要问用户的那件事写进单独一节「## 问你一句」(五块正文之后、接着问之前;不需要问就不写;别处不问用户),`chat-answer-shape.ts` 的 `answerPendingQuestion` 从回答原文读出这一节,路由只在原文里有这一节时存 `pendingQuestion`,没有新增任何模型调用;`consultation-follow-up-agent.ts` 去掉「问用户:」那一行和相关解析,只保留关思考。页面把这一句显示为正文最后一行(不显示标题、不做成接着问按钮);不在新形状里的回答(一句话的计划追问)也只去掉标题。三条接着问照常显示,但和这一句重复的那条去掉(`withoutPendingQuestionDuplicates`,回答自带的和兜底生成的都过滤)。固定的计划时机确认句仍按原样识别(`isPlanTimingClarifyReply`)。补写放置表把「问你一句」算作固定节。测试 `chat-answer-to-question-2284` 第一条改成读回答原文(原值/新值/原因写在测试里)。 +- 补充修复(2026-11-24 真实对话实测,分支 `claude/chat-ux-final`):上一轮存了「你希望这段关系最后走到哪一步?」,用户回「已经聊了两个多月了,还没确定关系」,交给解读的问题里多了一句用户没说的「希望走到确定关系那一步」。来源:`consultation-turn-split.ts` 拆分提示要求有 previous_question 时「ask 写用户对它的回答」,`settleTurnSplit` 直接把模型的 ask 拼进「我的回答:」,模型照上下文替用户补了答案。修复:「我的回答:」由程序用用户原话拼(`verbatimStatement`:模型 ask 的每个分句都必须是用户原话里的整句才用,否则用用户原话,只按原有规则去掉核对旧预测和过去经历的分句);没有待回答问题、route 为 situation 时同样原话带过去;拆分提示改为只摘原话、不补全;追问轮写法加一句:用户没真正答到所问时,照他说的收窄,没答到的部分不替他假设。测试 `chat-answer-to-question-2284` 加三条(补了一句、改写、截断分句都退回原话;现状加核对混在一起只留现状;无待回答问题的现状原话),两处原值改为用户原话(原值/新值/原因写在测试里)。 - 修复版本:分支 `claude/feedback-misroute-2284`;合并后 `claude/chat-ux-2284`(本地提交,待父会话推送)。 diff --git a/frontend/src/lib/consultation-turn-split.ts b/frontend/src/lib/consultation-turn-split.ts index a573c5886..6c90e8699 100644 --- a/frontend/src/lib/consultation-turn-split.ts +++ b/frontend/src/lib/consultation-turn-split.ts @@ -73,13 +73,14 @@ export const TURN_SPLIT_INSTRUCTIONS = `你只把用户这一轮的话拆开, - technical_check:用户指出星盘计算或引用上的具体错误(某颗星的星座、宫位、度数、上升、大运日期写错)时,只写被质疑的那一项,例如「月亮星座:用户说是处女」;没有就是 null。 - rectification_request:用户明确要做生时纠正、核对或校正出生时间。 - birth_input_change:用户明确要修改出生日期、时间或地点。 -- 有 previous_question 时,ask 写用户对它的回答(用用户的口吻,保留现状,去掉经历和结果)。 +- 有 previous_question 时,ask 只摘用户这一轮的原话(去掉经历和结果),不改写、不补全,不替用户回答他没说到的部分。 +- route 是 situation 时,ask 同样只摘用户的原话,不改写、不补全。 例子: 「我去年离婚了,还能再婚吗」→ route question,ask「我现在离异,还能再婚吗」,feedback true。 「我已经结婚了,婚姻能长久吗」→ route question,ask「我已经结婚了,婚姻能长久吗」,feedback false。 「分手了三个月,还能复合吗」→ route question,ask「还能和前任复合吗」,feedback true。 「我是足球运动员,明年事业怎么样」→ route question,ask「我是足球运动员,明年事业怎么样」,feedback false。 -「已经聊了有俩个多月了」(previous_question「你们现在是刚认识、在暧昧,还是已经在一起了?」)→ route situation,ask「我们已经聊了两个多月了」,feedback false。 +「已经聊了有俩个多月了」(previous_question「你们现在是刚认识、在暧昧,还是已经在一起了?」)→ route situation,ask「已经聊了有俩个多月了」,feedback false。 「你说的那段我反而亏了钱,是不是说反了」→ route verification,ask「」,feedback true。 「你上次说今年会升职,结果没有,明年呢」→ route question,ask「明年事业上有没有升职的机会」,feedback true。 「我的月亮明明在处女,你写成天蝎了」→ route question,ask「」,feedback false,technical_check「月亮星座:用户说是处女」。 @@ -175,19 +176,47 @@ export function isFeedbackOnlyTurn(split: TurnSplit): boolean { /** BUG-2284: what a follow-up is asked when nothing new was split out (the fixed product wording, not the user's). */ export const CONTINUE_ASK = "接着上一轮的回答继续说。"; +const CLAUSE_BREAKS = "。!?!?;;\n"; +const clausesOf = (text: string) => splitAfterSentencePunctuation(text, CLAUSE_BREAKS) + .flatMap((sentence) => sentence.split(/[,,、]/)) + .map((part) => part.replace(/[。!?!?;;\s]+$/u, "").trim()) + .filter(Boolean); +const bare = (text: string) => text.replace(/[\s\p{P}\p{S}]+/gu, ""); + +/** + * BUG-2284 follow-up (real exchange 2026-11-24): with a pending question the split model wrote the user's answer as + * 「已经聊了两个多月了,还没确定关系,希望走到确定关系那一步」, the last clause inferred, never said. The user's statement + * is carried in the user's own words: the model may drop clauses (outcome feedback), never add, paraphrase or complete. + * Its text is used only when every clause of it is a whole clause of the user's message; otherwise the user's + * message is used, with clauses that report outcomes or the past or judge a reading removed (the existing stripping). + */ +export function verbatimStatement(modelAsk: string, question: string): string { + // Whole clauses only: a clause cut short (「没确定关系」 → 「确定关系」) is not the user's words. + const userClauses = new Set(clausesOf(question).map(bare)); + const modelClauses = clausesOf(modelAsk); + if (modelClauses.length && modelClauses.every((clause) => userClauses.has(bare(clause)))) { + return modelClauses.filter((clause) => !FEEDBACK_VERDICT.test(clause)).join(","); + } + return clausesOf(question).filter((clause) => !FEEDBACK_VERDICT.test(clause) && !PAST_WORDS.test(clause)).join(","); +} + /** * BUG-2284: the reading's question for a turn that is not feedback-only. A reply to the question the previous answer - * asked becomes 「你上一轮问我:X 我的回答:Y」 so the reading narrows the earlier answer with it. + * asked becomes 「你上一轮问我:X 我的回答:Y」 so the reading narrows the earlier answer with it; Y is the user's own + * words (`verbatimStatement`), assembled here by program. A situation statement with no pending question is carried + * the same way. */ -export function settleTurnSplit(split: TurnSplit, pendingQuestion: string | null): TurnSplit { +export function settleTurnSplit(split: TurnSplit, pendingQuestion: string | null, question: string): TurnSplit { if (pendingQuestion) { - const answer = split.ask - ? `我的回答:${split.ask.replace(/[。.]$/u, "")}。按这个情况把上一轮的判断再收窄。` + const statement = split.ask ? verbatimStatement(split.ask, question) : ""; + const answer = statement + ? `我的回答:${statement}。按这个情况把上一轮的判断再收窄。` : `这一轮没有直接回答。${CONTINUE_ASK}`; return { ...split, ask: `你上一轮问我:${pendingQuestion}\n${answer}`, answersPendingQuestion: true }; } - if (isFeedbackOnlyTurn(split) || split.ask || split.technicalCheck || split.birthInputChange || split.rectificationRequest) return split; - return { ...split, ask: CONTINUE_ASK }; + const settled = split.route === "situation" && split.ask ? { ...split, ask: verbatimStatement(split.ask, question) } : split; + if (isFeedbackOnlyTurn(settled) || settled.ask || settled.technicalCheck || settled.birthInputChange || settled.rectificationRequest) return settled; + return { ...settled, ask: CONTINUE_ASK }; } export type PreviousAssistantTurn = Readonly<{ @@ -258,7 +287,7 @@ export async function splitConsultationTurn(input: { }): Promise { const startedAt = Date.now(); const pendingQuestion = input.previous?.pendingQuestion ?? null; - const settle = (split: TurnSplit) => settleTurnSplit(split, pendingQuestion); + const settle = (split: TurnSplit) => settleTurnSplit(split, pendingQuestion, input.question); const content = JSON.stringify({ ...(input.previous?.excerpt ? { previous_answer: input.previous.excerpt } : {}), ...(pendingQuestion ? { previous_question: pendingQuestion } : {}), diff --git a/frontend/src/mastra/product-voice.ts b/frontend/src/mastra/product-voice.ts index 0b7737fd7..e55bc29db 100644 --- a/frontend/src/mastra/product-voice.ts +++ b/frontend/src/mastra/product-voice.ts @@ -298,6 +298,7 @@ ${bodyHeadingLines()} - 本命盘上的 Sahams 和年盘上的 Sahams 是两组不同的点:判断依据里写哪一组就照哪一组的行,写明是哪一张盘上的。 - 卡上 precomputed_tables 是按卡算好的表(宫主、行星、运期起止和时长、细运和行运的重叠、慢星时间表、双重行运、土星压力段、其他运程):判断时只照这些表,不自己重新数、不自己推算时长;它们每行前面的〔编号〕用来在「判断依据」和时间线里引用。 - 追问轮写得轻一些:先「## ${VERDICT_HEADING}」一句话直接回答这一句(上面那组标签里用得上的可以带一两行);再只写和它直接相关的几条,每条同样先一句加粗的结论、再两三句,段末写〔编号〕;正文的写法和首轮完全一样,一句盘面上的理由都不写(不写星、宫、运期、方法名,也不写两种方法对没对上),这些都写进「判断依据」;问的是时间时才写时间那一节(格式同上,每条末尾写〔编号〕);需要问用户现状时写「## ${ASK_USER_HEADING}」(同上);然后「## ${FOLLOW_UP_HEADING}」三条;最后写「## 判断依据」,只列这一轮的判断,格式同上(编号照写)。只有用户问依据、问为什么,或者自己用了专业词时,正文才可以说出是哪颗星、哪一块、哪一段运期,每个专业词第一次出现时用几个字解释。 +- 用户这一轮是在回答上一轮问的那一句(「你上一轮问我:……/我的回答:……」)而没有真正答到所问时(问的是想走到哪一步,答的是聊了多久),就照他说了的去收窄,没答到的那部分不替他假设、不当成已知。 ${NO_BLAME_LINE} 方法状态那一句(只有一种方法指向、两套没对上)是证据本身的事实,写在「判断依据」那一条里,不算这一类。 红线(这几条之外靠你的判断): diff --git a/frontend/tests/chat-answer-to-question-2284.test.ts b/frontend/tests/chat-answer-to-question-2284.test.ts index 1871de90c..2ae4b961e 100644 --- a/frontend/tests/chat-answer-to-question-2284.test.ts +++ b/frontend/tests/chat-answer-to-question-2284.test.ts @@ -131,7 +131,9 @@ test("the screenshot exchange: the reply to the stored question is a normal foll assert.doesNotMatch(sent.previous_answer, /判断依据/); assert.equal(isFeedbackOnlyTurn(split), false); assert.equal(split.answersPendingQuestion, true); - assert.equal(split.ask, `你上一轮问我:${RELATIONSHIP_QUESTION}\n我的回答:我们已经聊了两个多月了。按这个情况把上一轮的判断再收窄。`); + // 原值:「我的回答:我们已经聊了两个多月了」(the split model's paraphrase);新值:the user's own words; + // 原因:BUG-2284 follow-up, the user's statement is carried verbatim, never rewritten by the split model. + assert.equal(split.ask, `你上一轮问我:${RELATIONSHIP_QUESTION}\n我的回答:已经聊了有俩个多月了。按这个情况把上一轮的判断再收窄。`); // The split model failing changes nothing about the route. const failed = await splitConsultationTurn({ model, question: "已经聊了有俩个多月了", previous, generate: async () => { throw new Error("down"); } }); assert.deepEqual([failed.source, isFeedbackOnlyTurn(failed), failed.answersPendingQuestion], ["fallback", false, true]); @@ -186,7 +188,7 @@ test("the pending question is used once: after the next user turn it is gone", ( test("only a confident pure verification gets the feedback-only reply; anything uncertain is a follow-up", async () => { assert.match(TURN_SPLIT_INSTRUCTIONS, /拿不准时选 question/); - assert.match(TURN_SPLIT_INSTRUCTIONS, /「已经聊了有俩个多月了」(previous_question/); + assert.match(TURN_SPLIT_INSTRUCTIONS, /「已经聊了有俩个多月了」(previous_question[^\n]*ask「已经聊了有俩个多月了」/); const previous = previousAssistantTurn(session("现在到 2027 年 3 月话多但落实少。")); const verification = await splitConsultationTurn({ model, question: "你上次说的那件事发生了", previous, generate: reply({ route: "verification", reason: "只核对之前的预测", ask: "", feedback: true }) }); @@ -197,9 +199,10 @@ test("only a confident pure verification gets the feedback-only reply; anything generate: reply({ route: "question", ask: "", feedback: true }) }); assert.deepEqual([isFeedbackOnlyTurn(ambiguous), ambiguous.ask], [false, CONTINUE_ASK]); // A state with no earlier question, judged as situation, is read. + // 原值:ask「我们已经聊了两个多月了」;新值:the user's words; 原因:BUG-2284 follow-up, situations are carried verbatim. const situation = await splitConsultationTurn({ model, question: "已经聊了有俩个多月了", previous, generate: reply({ route: "situation", ask: "我们已经聊了两个多月了", feedback: false }) }); - assert.deepEqual([isFeedbackOnlyTurn(situation), situation.ask], [false, "我们已经聊了两个多月了"]); + assert.deepEqual([isFeedbackOnlyTurn(situation), situation.ask], [false, "已经聊了有俩个多月了"]); // The fallback cannot judge: never feedback-only. const fallback = fallbackTurnSplit("你说的那段我反而亏了钱,是不是说反了"); assert.deepEqual([fallback.route, isFeedbackOnlyTurn(fallback)], ["question", false]); @@ -224,3 +227,60 @@ test("a chart whose time was settled in 生时纠正 is not sent back there", as assert.match(route, /turnSplitNotes\(splitTurn, \{ rectified: birthTimeRectified \}\)/); assert.match(route, /feedbackReply\(\{ model: selectedModel, previousAnswer, rectified: birthTimeRectified/); }); + +// BUG-2284 follow-up (real exchange 2026-11-24): the split model wrote the user's answer with a clause the user never +// said (「希望走到确定关系那一步」), inferred from the pending question. The answer is the user's own words. +const GOAL_QUESTION = "你希望这段关系最后走到哪一步?"; +const GOAL_ANSWER = "已经聊了两个多月了,还没确定关系"; + +test("a reply to the pending question is passed on in the user's own words, nothing added", async () => { + assert.match(TURN_SPLIT_INSTRUCTIONS, /有 previous_question 时,ask 只摘用户这一轮的原话[^\n]*不替用户回答他没说到的部分/); + assert.match(chatConversationVoice, /没有真正答到所问时(问的是想走到哪一步,答的是聊了多久),就照他说了的去收窄,没答到的那部分不替他假设/); + const previous = previousAssistantTurn(session(RELATIONSHIP_ANSWER, { pendingQuestion: GOAL_QUESTION })); + const expected = `你上一轮问我:${GOAL_QUESTION}\n我的回答:${GOAL_ANSWER}。按这个情况把上一轮的判断再收窄。`; + // The model completed the user's answer: its text is not used. + const completed = await splitConsultationTurn({ model, question: GOAL_ANSWER, previous, + generate: reply({ route: "situation", ask: "已经聊了两个多月了,还没确定关系,希望走到确定关系那一步", feedback: false }) }); + assert.equal(completed.ask, expected); + assert.doesNotMatch(completed.ask, /希望走到/); + // A paraphrase and a clause cut short are not the user's words either. + for (const ask of ["我们聊了两个月,还没在一起", "已经聊了两个多月了,确定关系"]) { + const split = await splitConsultationTurn({ model, question: GOAL_ANSWER, previous, generate: reply({ route: "situation", ask, feedback: false }) }); + assert.equal(split.ask, expected, ask); + } + // The model's own text copied word for word is fine; so is the fallback. + const exact = await splitConsultationTurn({ model, question: GOAL_ANSWER, previous, generate: reply({ route: "situation", ask: GOAL_ANSWER, feedback: false }) }); + assert.equal(exact.ask, expected); + const failed = await splitConsultationTurn({ model, question: GOAL_ANSWER, previous, generate: async () => { throw new Error("down"); } }); + assert.equal(failed.ask, expected); +}); + +test("a reply that mixes a situation and a verification keeps the situation verbatim and drops the verification", async () => { + const previous = previousAssistantTurn(session(RELATIONSHIP_ANSWER, { pendingQuestion: GOAL_QUESTION })); + const question = "还在暧昧,你上次说他会主动,结果没发生"; + const expected = `你上一轮问我:${GOAL_QUESTION}\n我的回答:还在暧昧。按这个情况把上一轮的判断再收窄。`; + // The model dropped the verification and kept the user's clause as said. + const kept = await splitConsultationTurn({ model, question, previous, generate: reply({ route: "situation", ask: "还在暧昧", feedback: true }) }); + assert.deepEqual([kept.ask, kept.feedback, isFeedbackOnlyTurn(kept)], [expected, true, false]); + // The model rewrote it (and added a goal): the user's message is used, the verification still stripped. + const rewritten = await splitConsultationTurn({ model, question, previous, + generate: reply({ route: "situation", ask: "我们现在在暧昧,希望能在一起", feedback: true }) }); + assert.equal(rewritten.ask, expected); + assert.doesNotMatch(rewritten.ask.split("\n")[1], /上次|没发生|主动|希望/); + // Without a pending question, a situation statement is carried the same way. + const plain = previousAssistantTurn(session("现在到 2027 年 3 月话多但落实少。")); + const situation = await splitConsultationTurn({ model, question, previous: plain, + generate: reply({ route: "situation", ask: "我们现在在暧昧,希望能在一起", feedback: true }) }); + assert.deepEqual([situation.ask, situation.answersPendingQuestion, situation.feedback], ["还在暧昧", false, true]); +}); + +test("without a pending question, a situation is carried verbatim; a new question keeps the split's rewrite", async () => { + const previous = previousAssistantTurn(session("现在到 2027 年 3 月话多但落实少。")); + const situation = await splitConsultationTurn({ model, question: GOAL_ANSWER, previous, + generate: reply({ route: "situation", ask: "已经聊了两个多月了,还没确定关系,希望走到确定关系那一步", feedback: false }) }); + assert.deepEqual([situation.ask, situation.answersPendingQuestion], [GOAL_ANSWER, false]); + // A new question is still written as a question by the split (BUG-1980: experiences out, stated situation kept). + const asked = await splitConsultationTurn({ model, question: "我去年离婚了,还能再婚吗", previous, + generate: reply({ route: "question", ask: "我现在离异,还能再婚吗", feedback: true }) }); + assert.equal(asked.ask, "我现在离异,还能再婚吗"); +});