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; +}