뉴스: 일본 1면 피드(Yahoo!ニュース 主要) 추가 + 요약 없는 피드는 기사 페이지 og:description으로 채움, 넓은 요청에 category=top이 붙어도 politics,business 적용 — '오늘 일본 뉴스'가 NewsData 최신순으로 교토 소프트아이스크림·배당 공시가 나오고, 모델이 top을 붙여 남미 패치를 비켜 감. 피드당 6→8건. 프롬프트: 뉴스 표의 제목·매체명도 답 언어로(일본어 원문 남김 금지)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Opus 5.5 committed 2026-10-23 18:04:31 +09:00
1 parent 9d19373525
commit 66584255dc
4 files changed
+42 -8

No files matched your search

+1 -1
View File
@@ -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
+3 -2
View File
@@ -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 };
+28 -2
View File
@@ -33,10 +33,14 @@ const FEEDS: Record<string, string[]> = {
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<Headline[]> {
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<Headline[]> {
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(/<meta[^>]+(?:property|name)="(?:og:)?description"[^>]*content="([^"]*)"/i);
return m ? m[1] : '';
}
export function formatHeadlines(items: readonly Headline[], limit = 12): string {
+10 -3
View File
@@ -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 = `<?xml version="1.0"?><rss><channel>
<title>NYT &gt; Top Stories</title>
@@ -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('<meta name="description" content="佐川急便は…発表しました。"/>'), '佐川急便は…発表しました。');
assert.equal(extractMetaDescription('<meta property="og:description" content="A &amp; B"/>'), 'A &amp; B');
assert.equal(extractMetaDescription('<title>x</title>'), '');
});
});