diff --git a/src/gateway/chat/followup-hints.ts b/src/gateway/chat/followup-hints.ts index e6f89ad..18bcefe 100644 --- a/src/gateway/chat/followup-hints.ts +++ b/src/gateway/chat/followup-hints.ts @@ -8,6 +8,8 @@ */ const WEATHER_RE = /강수|비가|비\s?(?:와|올|오|왔)|눈\s?(?:이|올|오)|날씨|기온|온도|바람|풍속|습도|미세먼지|초미세|예보|우산|폭우|태풍|안개|서리|더워|추워|추울|더울/; const TIME_BEFORE_GAJI = /(?:오늘|내일|모레|글피|주말|이번\s?주|다음\s?주|아침|점심|저녁|오전|오후|밤|새벽|\d{1,2}\s?시|\d{1,2}\s?일|[월화수목금토일]요일)\s*가지(?=\s|$|[?.!,])/; +const UNTIL_RE = /(?:오늘|내일|모레|글피|주말|이번\s?주|\d{1,2}\s?일|[월화수목금토일]요일)\s*(?:까지|가지(?=\s|$|[?.!,]))/; +const AMOUNT_RE = /강수량|비\s?양|적설|몇\s?mm|얼마나\s*(?:오|올|내릴|내려)/; const MAX_FOLLOWUP_CHARS = 40; export function weatherFollowUpHint( @@ -22,6 +24,11 @@ export function weatherFollowUpHint( notes.push(`"가지" in the user's message is almost certainly a typo for "까지" ("until/by") — read it as: ${msg.replace(/가지(?=\s|$|[?.!,])/, '까지')}`); } + // "내일까지 강수량" = 지금부터 그 날 끝까지의 누적. 그 날 하루치만 답하면 오늘 남은 비가 빠진다. + if (UNTIL_RE.test(msg) && AMOUNT_RE.test(msg)) { + notes.push('"X까지 강수량" means the CUMULATIVE amount from now until the end of X, not just X itself: add the rest of today\'s forecast to the days up to and including X, show the per-day breakdown, and state the total.'); + } + // 직전 몇 턴 안의 날씨 질문 — 지역을 이어받을 근거 const recent = history.slice(-6).filter(h => h.role === 'user').map(h => String(h.content || '').trim()).filter(Boolean); const prev = [...recent].reverse().find(q => WEATHER_RE.test(q)); diff --git a/tests/followup-hints.test.ts b/tests/followup-hints.test.ts index 1a7dc3a..7630fb4 100644 --- a/tests/followup-hints.test.ts +++ b/tests/followup-hints.test.ts @@ -18,3 +18,7 @@ test('날씨 맥락이 없으면 지역 힌트 없음', () => { test('날씨 질문이 아니면 null', () => assert.equal(weatherFollowUpHint('내일 가지 볶음 레시피', H), null)); test('긴 질문은 건드리지 않음', () => assert.equal(weatherFollowUpHint('내일 구미와 서울과 부산과 대구와 광주와 대전의 날씨와 기온과 강수량을 모두 자세히 비교해서 알려줘', H), null)); test('"가지"가 채소면 오타로 보지 않음', () => assert.equal(weatherFollowUpHint('가지 키우기 좋은 날씨야?', []), null)); + +test('"내일까지 강수량"은 누적 힌트', () => assert.match(weatherFollowUpHint('내일까지 현풍 강수량은?', [])!, /CUMULATIVE/)); +test('오타 "내일 가지 강수량"도 누적 힌트', () => assert.match(weatherFollowUpHint('내일 가지 예상 강수량은?', [])!, /CUMULATIVE/)); +test('"내일 강수량"(까지 없음)은 누적 힌트 없음', () => assert.equal(weatherFollowUpHint('내일 강수량은?', []), null));