From 7144862847927392dc754fc6c22426f789fb8b9b Mon Sep 17 00:00:00 2001 From: kim Date: Sun, 18 Oct 2026 19:33:57 +0900 Subject: [PATCH] =?UTF-8?q?=EB=82=A0=EC=94=A8=20=ED=9B=84=EC=86=8D=20?= =?UTF-8?q?=ED=9E=8C=ED=8A=B8:=20history=20=EB=81=9D=EC=97=90=20=ED=98=84?= =?UTF-8?q?=EC=9E=AC=20=EB=A9=94=EC=8B=9C=EC=A7=80=EA=B0=80=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=20=EC=9E=88=EC=96=B4=EB=8F=84=20=EC=A7=81=EC=A0=84=20?= =?UTF-8?q?=EB=82=A0=EC=94=A8=20=EC=A7=88=EB=AC=B8=EC=9D=84=20=EC=B0=BE?= =?UTF-8?q?=EB=8F=84=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5.5 --- src/gateway/chat/followup-hints.ts | 5 ++++- tests/followup-hints.test.ts | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/gateway/chat/followup-hints.ts b/src/gateway/chat/followup-hints.ts index d095992..a078daf 100644 --- a/src/gateway/chat/followup-hints.ts +++ b/src/gateway/chat/followup-hints.ts @@ -18,9 +18,12 @@ const CORRECTION_RE = /^(?:아니|아냐|아니요|그게\s*아니라|아니\s* export function weatherFollowUpHint( message: string, - history: ReadonlyArray<{ role: string; content?: any }>, + historyIn: ReadonlyArray<{ role: string; content?: any }>, ): string | null { const msg = String(message || '').trim(); + // 호출 시점의 history에 현재 메시지가 이미 들어 있을 수 있다 — 그 한 줄은 "이전 대화"가 아니므로 뺀다 + const history = historyIn.length && historyIn[historyIn.length - 1].role === 'user' && String(historyIn[historyIn.length - 1].content || '').trim() === msg + ? historyIn.slice(0, -1) : historyIn; if (!msg || msg.length > MAX_FOLLOWUP_CHARS) return null; if (!WEATHER_RE.test(msg)) return placeCorrectionHint(msg, history); const notes: string[] = []; diff --git a/tests/followup-hints.test.ts b/tests/followup-hints.test.ts index 71a0188..74433f3 100644 --- a/tests/followup-hints.test.ts +++ b/tests/followup-hints.test.ts @@ -28,3 +28,8 @@ test('"아니 서울" → 장소 정정 힌트', () => { const h = weatherFollow test('"부산으로" / "서울은?" → 정정 힌트', () => { assert.match(weatherFollowUpHint('부산으로', HW)!, /"부산"/); assert.match(weatherFollowUpHint('서울은?', HW)!, /"서울"/); }); test('날씨 맥락 없으면 정정 힌트 없음', () => assert.equal(weatherFollowUpHint('아니 서울', [{ role: 'user', content: '파스타 맛집' }]), null)); test('"고마워" 같은 짧은 응답은 제외', () => { assert.equal(weatherFollowUpHint('고마워', HW), null); assert.equal(weatherFollowUpHint('알겠어요', HW), null); }); + +test('history 끝에 현재 메시지가 이미 들어 있어도 직전 날씨 질문을 찾는다', () => { + const h = weatherFollowUpHint('아니 서울', [...HW, { role: 'user', content: '아니 서울' }])!; + assert.match(h, /"서울"/); +});