From 66584255dc14291dea77ba8f907dacd2528c17c0 Mon Sep 17 00:00:00 2001 From: kim Date: Fri, 23 Oct 2026 18:04:31 +0900 Subject: [PATCH] =?UTF-8?q?=EB=89=B4=EC=8A=A4:=20=EC=9D=BC=EB=B3=B8=201?= =?UTF-8?q?=EB=A9=B4=20=ED=94=BC=EB=93=9C(Yahoo!=E3=83=8B=E3=83=A5?= =?UTF-8?q?=E3=83=BC=E3=82=B9=20=E4=B8=BB=E8=A6=81)=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20+=20=EC=9A=94=EC=95=BD=20=EC=97=86=EB=8A=94=20=ED=94=BC?= =?UTF-8?q?=EB=93=9C=EB=8A=94=20=EA=B8=B0=EC=82=AC=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20og:description=EC=9C=BC=EB=A1=9C=20=EC=B1=84?= =?UTF-8?q?=EC=9B=80,=20=EB=84=93=EC=9D=80=20=EC=9A=94=EC=B2=AD=EC=97=90?= =?UTF-8?q?=20category=3Dtop=EC=9D=B4=20=EB=B6=99=EC=96=B4=EB=8F=84=20poli?= =?UTF-8?q?tics,business=20=EC=A0=81=EC=9A=A9=20=E2=80=94=20'=EC=98=A4?= =?UTF-8?q?=EB=8A=98=20=EC=9D=BC=EB=B3=B8=20=EB=89=B4=EC=8A=A4'=EA=B0=80?= =?UTF-8?q?=20NewsData=20=EC=B5=9C=EC=8B=A0=EC=88=9C=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EA=B5=90=ED=86=A0=20=EC=86=8C=ED=94=84=ED=8A=B8=EC=95=84?= =?UTF-8?q?=EC=9D=B4=EC=8A=A4=ED=81=AC=EB=A6=BC=C2=B7=EB=B0=B0=EB=8B=B9=20?= =?UTF-8?q?=EA=B3=B5=EC=8B=9C=EA=B0=80=20=EB=82=98=EC=98=A4=EA=B3=A0,=20?= =?UTF-8?q?=EB=AA=A8=EB=8D=B8=EC=9D=B4=20top=EC=9D=84=20=EB=B6=99=EC=97=AC?= =?UTF-8?q?=20=EB=82=A8=EB=AF=B8=20=ED=8C=A8=EC=B9=98=EB=A5=BC=20=EB=B9=84?= =?UTF-8?q?=EC=BC=9C=20=EA=B0=90.=20=ED=94=BC=EB=93=9C=EB=8B=B9=206?= =?UTF-8?q?=E2=86=928=EA=B1=B4.=20=ED=94=84=EB=A1=AC=ED=94=84=ED=8A=B8:=20?= =?UTF-8?q?=EB=89=B4=EC=8A=A4=20=ED=91=9C=EC=9D=98=20=EC=A0=9C=EB=AA=A9?= =?UTF-8?q?=C2=B7=EB=A7=A4=EC=B2=B4=EB=AA=85=EB=8F=84=20=EB=8B=B5=20?= =?UTF-8?q?=EC=96=B8=EC=96=B4=EB=A1=9C(=EC=9D=BC=EB=B3=B8=EC=96=B4=20?= =?UTF-8?q?=EC=9B=90=EB=AC=B8=20=EB=82=A8=EA=B9=80=20=EA=B8=88=EC=A7=80)?= 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/system-prompt.ts | 2 +- src/tools/news.ts | 5 +++-- src/tools/top-headlines.ts | 30 ++++++++++++++++++++++++++++-- tests/top-headlines.test.ts | 13 ++++++++++--- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/gateway/chat/system-prompt.ts b/src/gateway/chat/system-prompt.ts index 2ca64c9..77d06c5 100644 --- a/src/gateway/chat/system-prompt.ts +++ b/src/gateway/chat/system-prompt.ts @@ -184,7 +184,7 @@ export function buildChatSystemPrompt(input: SystemPromptInput): string { // 2026-10-23: 뉴스·날씨의 "더 길게" 문구(07-24, gemma4가 너무 짧게 답하던 때)를 낮췄다. Haiku는 원래 길게 쓰는 // 편이라 그 문구와 "다시 줄이지 말 것" 예외가 장황함을 부추겼다. 날씨의 출처 선택·수치 덧붙이기 금지는 그대로. const newsFormatRule = hasNewsTool - ? ' For news specifically: use a table with columns 제목|요약|출처, but write each 요약 as 1-2 sentences covering the article\'s actual content — not a headline fragment restated. Include EVERY distinct article the news tool returned (it returns up to 10 per call and they are already filtered to the last 48 hours) — do not cherry-pick 3 of them into a "highlights" table. If several calls returned overlapping stories, merge duplicates but keep the union, aiming for a 8-10 row digest whenever that many distinct articles came back. Don\'t add lines about the articles\' dates or freshness (they come from the last 48 hours) or about articles you left out.' + ? ' For news specifically: use a table with columns 제목|요약|출처, but write each 요약 as 1-2 sentences covering the article\'s actual content — not a headline fragment restated. Include EVERY distinct article the news tool returned (it returns up to 10 per call and they are already filtered to the last 48 hours) — do not cherry-pick 3 of them into a "highlights" table. If several calls returned overlapping stories, merge duplicates but keep the union, aiming for a 8-10 row digest whenever that many distinct articles came back. Don\'t add lines about the articles\' dates or freshness (they come from the last 48 hours) or about articles you left out. Write every cell in the answer\'s language — translate foreign titles and outlet names (京都新聞 → 교토신문); no Japanese, Chinese or other original-script words left in the table.' : ''; const weatherFormatRule = hasWeatherTools diff --git a/src/tools/news.ts b/src/tools/news.ts index 9c2ae4f..c1adb4d 100644 --- a/src/tools/news.ts +++ b/src/tools/news.ts @@ -306,7 +306,8 @@ export const newsSearchTool = { // 1면 피드가 없는 나라의 넓은 요청("남미 뉴스")은 NewsData 최신순이라 맛집 개점·동물원 사고 같은 가벼운 기사가 // 섞여 나온다(2026-10-23 실측). 정치·경제 분류를 걸면 주요 기사 쪽으로 기운다 — 결과가 너무 적으면 분류 없이 다시. - const broadCategory = (broad && country && !category) ? 'politics,business' : ''; + // 'top'도 넓은 요청이다 — 모델이 "오늘 일본 뉴스"에 category:"top"을 붙여 이 분기를 비켜 갔다(10-23). + const broadCategory = (broad && country) ? 'politics,business' : ''; const fetchOnce = async (q: string, cat: string = category) => { const params = new URLSearchParams({ apikey: apiKey }); if (q) params.set('q', q); @@ -339,7 +340,7 @@ export const newsSearchTool = { return { success: true, stdout: formatArticles(results), - data: { query, country, language, category: category || broadCategory || undefined, totalResults: data.totalResults, raw: results }, + data: { query, country, language, category: broadCategory || category || undefined, totalResults: data.totalResults, raw: results }, }; } catch (err: any) { return { success: false, error: err.message }; diff --git a/src/tools/top-headlines.ts b/src/tools/top-headlines.ts index da487b3..84a7fb9 100644 --- a/src/tools/top-headlines.ts +++ b/src/tools/top-headlines.ts @@ -33,10 +33,14 @@ const FEEDS: Record = { fr: ['https://www.lemonde.fr/rss/une.xml'], it: ['https://xml2.corriereobjects.it/rss/homepage.xml'], es: ['https://feeds.elpais.com/mrss-s/pages/ep/site/elpais.com/portada'], + // Yahoo!ニュース「主要」 — 편집자가 고른 8건(일본 포털의 1면). 신문사 쪽은 맞지 않았다(10-23 실측): + // NHK cat0은 8월에 멈춤, 아사히 속보는 최신순, Japan Times 톱스토리는 2024년 기사. 요약이 없는 + // 피드라 fillMissingSummaries가 기사 페이지에서 채운다. + jp: ['https://news.yahoo.co.jp/rss/topics/top-picks.xml'], }; const FETCH_TIMEOUT_MS = 10_000; -const PER_FEED = 6; +const PER_FEED = 8; // Yahoo!ニュース 主要이 8건 export interface Headline { title: string; link: string; source: string; summary: string } @@ -126,7 +130,29 @@ export async function fetchTopHeadlines(country: string): Promise { for (const list of lists) if (list[i]) merged.push(list[i]); if (merged.length === before) break; } - return merged; + return fillMissingSummaries(merged); +} + +/** + * Some front pages (Yahoo!ニュース) ship titles only. Without a summary the model either restates + * the headline as its 요약 or goes to web_fetch each article — so take the article page's own + * og:description instead, in parallel. A page that fails just keeps its empty summary. + */ +async function fillMissingSummaries(items: Headline[], limit = 12): Promise { + await Promise.allSettled(items.slice(0, limit).filter(h => !h.summary && h.link).map(async (h) => { + const res = await fetch(h.link, { + headers: { 'User-Agent': 'Mozilla/5.0 (compatible; SmallClaw/1.0)' }, + signal: AbortSignal.timeout(FETCH_TIMEOUT_MS), + }); + if (!res.ok) return; + h.summary = cleanSummary(extractMetaDescription(await res.text())).slice(0, 400); + })); + return items; +} + +export function extractMetaDescription(html: string): string { + const m = String(html || '').match(/]+(?:property|name)="(?:og:)?description"[^>]*content="([^"]*)"/i); + return m ? m[1] : ''; } export function formatHeadlines(items: readonly Headline[], limit = 12): string { diff --git a/tests/top-headlines.test.ts b/tests/top-headlines.test.ts index 671a578..7d1181a 100644 --- a/tests/top-headlines.test.ts +++ b/tests/top-headlines.test.ts @@ -9,7 +9,7 @@ import { test, describe } from 'node:test'; import assert from 'node:assert/strict'; -import { parseFeedItems, hasTopHeadlineFeeds, formatHeadlines } from '../src/tools/top-headlines'; +import { parseFeedItems, hasTopHeadlineFeeds, formatHeadlines, extractMetaDescription } from '../src/tools/top-headlines'; const RSS = ` NYT > Top Stories @@ -56,7 +56,7 @@ describe('parseFeedItems', () => { describe('hasTopHeadlineFeeds', () => { test('피드가 있는 나라', () => { - for (const c of ['us', 'gb', 'de', 'fr', 'it', 'es']) assert.equal(hasTopHeadlineFeeds(c), true, c); + for (const c of ['us', 'gb', 'de', 'fr', 'it', 'es', 'jp']) assert.equal(hasTopHeadlineFeeds(c), true, c); }); test('다국가 목록은 하나라도 있으면 참', () => { @@ -66,7 +66,6 @@ describe('hasTopHeadlineFeeds', () => { test('피드가 없는 나라 — NewsData 경로로 간다', () => { assert.equal(hasTopHeadlineFeeds('kr'), false); - assert.equal(hasTopHeadlineFeeds('jp'), false); assert.equal(hasTopHeadlineFeeds(''), false); }); }); @@ -143,3 +142,11 @@ describe('요약 추출', () => { assert.ok(!/\n\s*\n/.test(formatHeadlines(parseFeedItems(xml, 'x')))); }); }); + +describe('extractMetaDescription', () => { + test('기사 페이지의 og:description/description을 꺼낸다', () => { + assert.equal(extractMetaDescription(''), '佐川急便は…発表しました。'); + assert.equal(extractMetaDescription(''), 'A & B'); + assert.equal(extractMetaDescription('x'), ''); + }); +});