From b4716a45132d86440858cbe11413d7a430ade34b Mon Sep 17 00:00:00 2001 From: kim Date: Sat, 17 Oct 2026 12:19:56 +0900 Subject: [PATCH] =?UTF-8?q?python=5Feval=20=EC=B0=A8=ED=8A=B8=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=EB=A5=BC=20=EB=AA=A8=EB=8D=B8=EC=9D=B4=20?= =?UTF-8?q?=EB=B9=A0=EB=9C=A8=EB=A6=AC=EB=A9=B4=20=EC=B5=9C=EC=A2=85=20?= =?UTF-8?q?=EB=8B=B5=EB=B3=80=EC=97=90=20=EC=BD=94=EB=93=9C=EB=A1=9C=20?= =?UTF-8?q?=EB=8D=A7=EB=B6=99=EC=9E=84?= 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/handle-chat.ts | 3 ++- src/gateway/chat/reply-content.ts | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/gateway/chat/handle-chat.ts b/src/gateway/chat/handle-chat.ts index 4b6f19c..146688f 100644 --- a/src/gateway/chat/handle-chat.ts +++ b/src/gateway/chat/handle-chat.ts @@ -83,7 +83,7 @@ import { createBrowserDesktopAdvisors, type BrowserDesktopAdvisorCtx } from './b import type { SkillsManager } from '../skills-manager'; import { selectToolsForTurn, bootAllowedTools, codeAiBlockedTools } from './tool-scope'; import { buildChatSystemPrompt, groundingResultReadingRule } from './system-prompt'; -import { replyLooksEmpty, appendDroppedSearchImages } from './reply-content'; +import { replyLooksEmpty, appendDroppedSearchImages, appendGeneratedChartImages } from './reply-content'; import { evaluateSearchBudget } from './search-budget'; import { decideAutoRecover, shouldForceMessagingRetry as decideMessagingRetry, shouldForceWorkshopSaveRetry, shouldForceWorkshopFileRetry, shouldForceUnverifiedSpecRetry, unverifiedSpecPrompt, shouldForceEmptyGroundingRetry as decideEmptyGroundingRetry, GROUNDING_TOOL_PATTERN } from './retry-decisions'; import { logToolSkip } from './tool-skip-log'; @@ -2500,6 +2500,7 @@ async function handleChat( } finalText = sanitizeFinalReply(finalText, { preflightReason: preflightReasonForTurn }) || 'Hey! How can I help?'; finalText = appendDroppedSearchImages(finalText, allToolResults); + finalText = appendGeneratedChartImages(finalText, allToolResults); logToDaily(workspacePath, 'SmallClaw', finalText, sessionId); if (fileOpV2Active) { diff --git a/src/gateway/chat/reply-content.ts b/src/gateway/chat/reply-content.ts index e9f93cb..97863aa 100644 --- a/src/gateway/chat/reply-content.ts +++ b/src/gateway/chat/reply-content.ts @@ -47,3 +47,27 @@ export function appendDroppedSearchImages( } return finalText; } + +const FILES_IMG_MD_G = /!\[[^\]]*\]\(\/api\/files\/[^)]+\)/g; + +/** + * python_eval reports charts it saved as `![name](/api/files/name.png)` in its result, but the model + * often answers "차트는 squares_chart.png 파일로 저장되었습니다" without the link, or with a bare + * `![x](x.png)` that resolves nowhere (2026-10-17, two restarts of prompt hints did not fix it). + * Append every generated chart whose /api/files/ URL the reply does not already carry. + */ +export function appendGeneratedChartImages( + finalText: string, + toolResults: ReadonlyArray<{ name?: string; error?: boolean; result?: string }> | undefined, +): string { + if (!toolResults?.length) return finalText; + const missing: string[] = []; + for (const r of toolResults) { + if (r?.name !== 'python_eval' || r.error || !r.result) continue; + for (const md of r.result.match(FILES_IMG_MD_G) || []) { + const url = md.slice(md.indexOf('](') + 2, -1); + if (!finalText.includes(url) && !missing.includes(md)) missing.push(md); + } + } + return missing.length ? `${finalText}\n\n${missing.join('\n\n')}`.trim() : finalText; +}