From 2ae7aa74bde6ad485d398b405099995e882c6a0a Mon Sep 17 00:00:00 2001 From: kim Date: Sat, 24 Oct 2026 10:42:28 +0900 Subject: [PATCH] =?UTF-8?q?=EB=89=B4=EC=8A=A4=20=EB=8B=B5:=20=ED=91=9C=20?= =?UTF-8?q?=EB=B0=94=EA=B9=A5=20=EB=82=A0=EC=A7=9C=20=EA=B8=B0=EC=A4=80?= =?UTF-8?q?=C2=B7=EC=A0=9C=EC=99=B8=20=EA=B8=B0=EC=82=AC=20=EB=A9=94?= =?UTF-8?q?=EB=AA=A8=EB=A5=BC=20=EC=BD=94=EB=93=9C=EB=A1=9C=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0(stripNewsMetaNotes)=20+=20=EC=9D=BC=EB=B3=B8=20?= =?UTF-8?q?=EA=B8=B0=EC=82=AC=20=E8=8F=AF=E7=81=AB=E2=86=92=E8=8A=B1?= =?UTF-8?q?=E7=81=AB=20=E2=80=94=20'=EC=98=A4=EB=8A=98=20=EC=9D=BC?= =?UTF-8?q?=EB=B3=B8=20=EB=89=B4=EC=8A=A4'=EC=97=90=20Haiku=EA=B0=80=20?= =?UTF-8?q?=ED=94=84=EB=A1=AC=ED=94=84=ED=8A=B8=20=EA=B8=88=EC=A7=80?= =?UTF-8?q?=EC=97=90=EB=8F=84=20'10=EC=9B=94=2023=EC=9D=BC(=EA=B8=88)=20?= =?UTF-8?q?=EA=B8=B0=EC=A4=80=20=E2=80=A6=208=EA=B1=B4',=20'=EA=B2=BD?= =?UTF-8?q?=EC=A0=9C=C2=B7=ED=99=98=EC=9C=A8=20=EA=B8=B0=EC=82=AC=EB=8A=94?= =?UTF-8?q?=20=ED=8F=AC=ED=95=A8=EB=90=98=EC=A7=80=20=EC=95=8A=EC=95=98?= =?UTF-8?q?=EC=8A=B5=EB=8B=88=EB=8B=A4'=EB=A5=BC=20=EB=B6=99=EC=9D=B4?= =?UTF-8?q?=EA=B3=A0,=20=E6=9D=B1=E4=BA=AC=E6=B9=BE=E5=A4=A7=E8=8F=AF?= =?UTF-8?q?=E7=81=AB=E7=A5=AD=EB=A5=BC=20'=EB=8F=84=EC=BF=84=EB=A7=8C=20?= =?UTF-8?q?=EB=8C=80=ED=99=94=ED=99=94=EC=A0=9C'=EB=A1=9C=20=EC=9D=8C?= =?UTF-8?q?=EC=B0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- src/gateway/chat/handle-chat.ts | 8 ++++++++ src/gateway/guards/prompt-gates.ts | 18 ++++++++++++++++++ src/tools/top-headlines.ts | 8 ++++++-- tests/prompt-gates.test.ts | 17 +++++++++++++++++ tests/top-headlines.test.ts | 8 ++++++++ 5 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/gateway/chat/handle-chat.ts b/src/gateway/chat/handle-chat.ts index b8bb868..31709d0 100644 --- a/src/gateway/chat/handle-chat.ts +++ b/src/gateway/chat/handle-chat.ts @@ -14,6 +14,7 @@ import { isFactualInfoRequest, isFactualThreadFollowUp, isNewsEntityFollowUp, + stripNewsMetaNotes, confirmsUserGuessWithoutGrounding, looksLikeUnverifiedSpecClaim, isExemptFromVerification, @@ -2590,6 +2591,13 @@ async function handleChat( } finalText = appendDroppedSearchImages(finalText, allToolResults); finalText = appendGeneratedChartImages(finalText, allToolResults); + if (allToolResults.some((r: any) => r?.name === 'news_search')) { + const _stripped = stripNewsMetaNotes(finalText); + if (_stripped !== finalText) { + console.log('[v2] NEWS META STRIP: removed date/excluded-article notes around the news table.'); + finalText = _stripped; + } + } { // 날씨 도구가 전부 실패했는데 수치를 말하는 답은 지어낸 것 — EMPTY-GROUNDING 재프롬프트(1회) 뒤에도 남았다면 여기서 교체. const _fabricated = weatherFabricationReplacement(finalText, allToolResults); diff --git a/src/gateway/guards/prompt-gates.ts b/src/gateway/guards/prompt-gates.ts index 9a988eb..1ae1da1 100644 --- a/src/gateway/guards/prompt-gates.ts +++ b/src/gateway/guards/prompt-gates.ts @@ -213,6 +213,24 @@ export function isFactualThreadFollowUp(message: string, previousUserMessage: st return /[??]$/.test(m) || /(까|나요|니|냐|지|는가|은가|어때|얼마|몇|뭐|무엇|어디|언제|누구|왜|어떻게)\s*[??]?$/.test(m); } +/** + * 뉴스 표 바깥의 메타 문장 제거 — 프롬프트에 '날짜·신선도, 뺀 기사 얘기 금지'가 있어도 Haiku가 + * "검색 결과는 10월 23일(금) 기준 … 8건입니다", "참고로 … 경제·환율 기사는 포함되지 않았습니다"를 + * 붙였다(2026-10-24). 표 행은 건드리지 않고, 표 바깥 문장 중 날짜+기준 / 포함 안 됨·제외 표현이 있는 + * 문장만 뺀다. "기준금리" 같은 내용어는 날짜가 앞에 붙지 않으니 안 걸린다. + */ +export function stripNewsMetaNotes(answer: string): string { + const text = String(answer || ''); + if (!/\|\s*제목\s*\|/.test(text)) return text; + const META = /(\d{1,2}\s*일\s*(\([^)]*\))?\s*(오전|오후|\d{1,2}시)?\s*기준|포함되지\s*않|포함하지\s*않|빠졌|빠져\s*있|제외(했|되|된|하였))/; + const out = text.split('\n').map(line => { + if (!line.trim() || /^\s*\|/.test(line)) return line; + const kept = line.split(/(?<=[.!?。])\s+/).filter(s => !META.test(s)); + return kept.length ? kept.join(' ') : null; + }).filter((l): l is string => l !== null); + return out.join('\n').replace(/\n{3,}/g, '\n\n').trim(); +} + /** * 방금 뉴스 표에 나온 인물을 묻는 후속 질문("무라카미 류 누구지?"). * diff --git a/src/tools/top-headlines.ts b/src/tools/top-headlines.ts index 84a7fb9..6a2aced 100644 --- a/src/tools/top-headlines.ts +++ b/src/tools/top-headlines.ts @@ -155,11 +155,15 @@ export function extractMetaDescription(html: string): string { return m ? m[1] : ''; } +// 華火는 花火의 옛 표기(東京湾大華火祭 등) — 모델이 '대화화제'로 음차했다(2026-10-24). 흔한 표기로 바꿔 '불꽃'으로 읽히게. +const JA_VARIANT_SPELLINGS: Array<[RegExp, string]> = [[/華火/g, '花火']]; +const normalizeVariants = (s: string) => JA_VARIANT_SPELLINGS.reduce((t, [re, to]) => t.replace(re, to), s); + export function formatHeadlines(items: readonly Headline[], limit = 12): string { return items.slice(0, limit) .map((h, i) => { - const lines = [`[${i + 1}] ${h.title}`]; - if (h.summary) lines.push(` ${h.summary}`); + const lines = [`[${i + 1}] ${normalizeVariants(h.title)}`]; + if (h.summary) lines.push(` ${normalizeVariants(h.summary)}`); lines.push(` ${h.link}`, ` Source: ${h.source}`); return lines.join('\n'); }) diff --git a/tests/prompt-gates.test.ts b/tests/prompt-gates.test.ts index 65b5966..4c12f45 100644 --- a/tests/prompt-gates.test.ts +++ b/tests/prompt-gates.test.ts @@ -17,6 +17,7 @@ import { test, describe } from 'node:test'; import assert from 'node:assert/strict'; import { isNewsEntityFollowUp, + stripNewsMetaNotes, looksLikeUnverifiedSpecClaim, isExemptFromVerification, isFactualInfoRequest, @@ -571,3 +572,19 @@ describe('isNewsEntityFollowUp', () => { assert.equal(isNewsEntityFollowUp('무라카미 류 작품 뭐 있어?', newsTable), false); }); }); + +describe('stripNewsMetaNotes', () => { + const table = '| 제목 | 요약 | 출처 |\n|---|---|---|\n| 프랑스 시위에 경찰 7만 명 | 24일 집회에 동원. | 로이터 |'; + test('[2026-10-24] drops the date-basis and excluded-article sentences, keeps the rest', () => { + const ans = `오늘 일본 뉴스입니다. 검색 결과는 10월 23일(금) 기준 주요 매체 1면 톱기사 8건입니다.\n\n${table}\n\n참고로 이 결과는 1면 톱기사 목록이라 경제·환율 기사는 포함되지 않았습니다.`; + assert.equal(stripNewsMetaNotes(ans), `오늘 일본 뉴스입니다.\n\n${table}`); + }); + test('content words like 기준금리 survive', () => { + const ans = `한국은행 기준금리 동결 기사가 많습니다.\n\n${table}`; + assert.equal(stripNewsMetaNotes(ans), ans); + }); + test('answers without a news table are untouched', () => { + const ans = '10월 23일 기준 환율은 확인되지 않았습니다. 일부 기사는 제외했습니다.'; + assert.equal(stripNewsMetaNotes(ans), ans); + }); +}); diff --git a/tests/top-headlines.test.ts b/tests/top-headlines.test.ts index 7d1181a..64054ae 100644 --- a/tests/top-headlines.test.ts +++ b/tests/top-headlines.test.ts @@ -150,3 +150,11 @@ describe('extractMetaDescription', () => { assert.equal(extractMetaDescription('x'), ''); }); }); + +describe('formatHeadlines variant spellings', () => { + test('[2026-10-24] 華火 → 花火 so the model reads it as fireworks', () => { + const out = formatHeadlines([{ title: '東京湾大華火祭 11年ぶり', link: 'https://x', source: 'yahoo.co.jp', summary: '大華火祭が24日開催' }]); + assert.ok(out.includes('東京湾大花火祭') && out.includes('大花火祭が')); + assert.ok(!out.includes('華火')); + }); +});