fix(thinking): 짧은 응답 — 영어 혼잣말 뒤에 공백 없이 붙은 한글 답이 마지막 문장 하나로 줄던 문제. 봉합점 앞이 한글 없는 추론 말투면 단락 수 증거 없이도 셀프토크로 보고 그 뒤 한글을 통째로 답으로

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5.5 committed 2026-10-01 15:44:43 +09:00
1 parent 0d1df19b78
commit a25b63e20e
2 files changed
+29 -2

No files matched your search

+13 -2
View File
@@ -129,6 +129,9 @@ function koreanAnswerTail(cleaned: string): { reply: string; thinking: string }
const SEAM_RE = /([A-Za-z0-9 .,;:'"()\-]{40,}[.!?:][")]?)([가-힣])/g;
const SCRATCH_LABEL_RE = /^(Also note|Also mention|Answer format|Key message|Key points|Keep it|Actually the rule|Note that|Remember that|Final note|One more thing)\b/i;
// 봉합점 앞 영어가 "내 할 일을 중얼거리는" 말투인지(키워드는 보조 증거일 뿐 — 한글 없음 + 봉합점이 핵심 구조 신호).
const INNER_MONOLOGUE_RE = /^(The (user|note|answer|tool|file|result|search|response|rules?)\b|I (need|should|will|have|can|am)\b|Let me\b|Now,? |Okay|Ok,|Hmm|Wait|So,? |First,? |Done\b|Good\b|Alright)/i;
function stripEnglishScratchPrefix(text: string): { reply: string; thinking: string } | null {
if (!text) return null;
const HANGUL = /[가-힣]/;
@@ -140,15 +143,23 @@ function stripEnglishScratchPrefix(text: string): { reply: string; thinking: str
for (const m of text.matchAll(SEAM_RE)) {
const before = text.slice(0, m.index);
const prior = before.split(/\n{2,}/).map(p => p.trim()).filter(Boolean);
// 짧은 응답(2026-10-01 작업실 채팅): "The note was added…. Let me give a brief closing confirmation.메모에…"처럼
// 영어 한두 단락이 통째로 자기 혼잣말이고(한글 없음, 추론 말투) 한글이 공백 없이 바로 붙는 경우.
// 단락 수 증거가 없어도, 봉합점 앞이 전부 영어이고 추론 말투로 시작하면 셀프토크로 본다.
// before는 봉합점의 영어 런(m[1]) 앞까지라서, 런 자체를 합쳐서 본다.
const beforeAll = (before + m[1]).trim();
const strongSolo = !HANGUL.test(beforeAll) && INNER_MONOLOGUE_RE.test(beforeAll);
const hasEvidence =
strongSolo ||
prior.some(p => SCRATCH_LABEL_RE.test(p)) ||
prior.filter(p => p.length >= 40 && !HANGUL.test(p)).length >= 2;
if (!hasEvidence) continue;
const hangulPos = m.index + m[1].length;
const reply = text.slice(hangulPos);
if (reply.replace(/\s/g, '').length < 40) continue; // 너무 잘려나가면 다음 후보로
return { reply, thinking: before.trim() };
// 너무 잘려나가면 다음 후보로 — 단, 앞이 확실한 혼잣말이면 짧은 한글 답도 인정한다.
if (reply.replace(/\s/g, '').length < (strongSolo ? 10 : 40)) continue;
return { reply, thinking: text.slice(0, hangulPos).trim() };
}
return null;
}
+16
View File
@@ -129,4 +129,20 @@ describe('glm 영어 셀프토크 접두사 분리', () => {
assert.equal(separateThinkingFromContent(reasoning + '\n\n' + answer).reply, answer);
});
});
// ── 2026-10-01 실사례 2: 짧은 응답 — 영어 혼잣말 뒤에 공백 없이 한글 답이 붙음 ──
describe('짧은 영어 혼잣말 + 공백 없이 붙은 한글 답', () => {
const FUSED = 'The note was added successfully. The answer is complete. Let me give a brief closing confirmation.메모에 정확도 스펙을 저장했습니다. 공식 정확도는 약 0.4°입니다. 조립 시 AGC 레지스터 값이 중간에 오도록 맞추는 것만 기억하시면 됩니다.';
test('한글 답 전체가 남고 영어 혼잣말은 생각으로 간다(마지막 문장 하나만 남지 않음)', () => {
const { reply, thinking } = separateThinkingFromContent(FUSED);
assert.equal(reply, '메모에 정확도 스펙을 저장했습니다. 공식 정확도는 약 0.4°입니다. 조립 시 AGC 레지스터 값이 중간에 오도록 맞추는 것만 기억하시면 됩니다.');
assert.match(thinking, /^The note was added/);
});
test('정상 응답의 "영어 문장.한글" 붙임(혼잣말 말투 아님)은 건드리지 않는다', () => {
const normal = 'Open-Meteo and KMA are both fine sources for this kind of daily forecast request.아쉽게도 내일은 비가 옵니다.';
assert.equal(separateThinkingFromContent(normal).reply, normal);
});
});
});