fix: make paired evidence loss visible (#202)

This commit is contained in:
Eyejoker
2026-05-31 16:20:09 +09:00
committed by GitHub
parent 6eca648c47
commit 239c7ff1e6
19 changed files with 644 additions and 67 deletions

View File

@@ -1,27 +1,64 @@
import fs from 'fs';
import path from 'path';
import { extractImageTagPaths } from 'ejclaw-runners-shared';
import {
extractImageTagPaths,
imageTagCaption,
missingImageTagCaption,
splitImageTagPromptParts,
} from 'ejclaw-runners-shared';
import type { AppServerInputItem } from './app-server-client.js';
const SUPPORTED_LOCAL_IMAGE_EXTENSIONS = new Set([
'.jpg',
'.jpeg',
'.png',
'.gif',
'.webp',
]);
export function parseAppServerInput(
text: string,
log: (message: string) => void = () => undefined,
): AppServerInputItem[] {
const { cleanText, imagePaths } = extractImageTagPaths(text);
const { imagePaths } = extractImageTagPaths(text);
const input: AppServerInputItem[] = [];
const pushText = (value: string) => {
const trimmed = value.trim();
if (trimmed) input.push({ type: 'text', text: trimmed });
};
if (cleanText) {
input.push({ type: 'text', text: cleanText });
}
if (imagePaths.length > 0) {
for (const part of splitImageTagPromptParts(text)) {
if (part.type === 'text') {
pushText(part.text);
continue;
}
if (!fs.existsSync(part.path)) {
log(`Image not found, skipping: ${part.path}`);
pushText(missingImageTagCaption(part, 'file not found'));
continue;
}
for (const imgPath of imagePaths) {
if (fs.existsSync(imgPath)) {
input.push({ type: 'localImage', path: imgPath });
log(`Adding image input: ${imgPath}`);
} else {
log(`Image not found, skipping: ${imgPath}`);
const ext = path.extname(part.path).toLowerCase();
if (!SUPPORTED_LOCAL_IMAGE_EXTENSIONS.has(ext)) {
log(`Unsupported image type, skipping: ${part.path}`);
pushText(
missingImageTagCaption(
part,
`unsupported image type ${ext || 'unknown'}`,
),
);
continue;
}
pushText(imageTagCaption(part));
input.push({ type: 'localImage', path: part.path });
log(`Adding image input: ${part.path}`);
}
} else if (text) {
input.push({ type: 'text', text });
}
if (input.length === 0) {

View File

@@ -34,8 +34,56 @@ describe('codex app-server input', () => {
expect(input).toEqual([
{ type: 'text', text: '리뷰 증거' },
{
type: 'text',
text: 'Image evidence: settings-v0.1.92-deployed-390.png',
},
{ type: 'localImage', path: imagePath },
]);
expect(logs).toContain(`Adding image input: ${imagePath}`);
});
it('keeps missing image evidence visible in Codex prompts', () => {
const missingPath = path.join(
os.tmpdir(),
'ejclaw-missing-codex-image-evidence.png',
);
const logs: string[] = [];
const input = parseAppServerInput(
`리뷰 증거\n[Image: expected-render.png → ${missingPath}]`,
(message) => logs.push(message),
);
expect(input).toEqual([
{ type: 'text', text: '리뷰 증거' },
{
type: 'text',
text: `[Image unavailable: expected-render.png → ${missingPath} — file not found]`,
},
]);
expect(logs).toContain(`Image not found, skipping: ${missingPath}`);
});
it('keeps unsupported image evidence visible in Codex prompts', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ejclaw-codex-bmp-'));
cleanupDirs.push(dir);
const imagePath = path.join(dir, 'settings.bmp');
fs.writeFileSync(imagePath, Buffer.from('BMunsupported'));
const logs: string[] = [];
const input = parseAppServerInput(
`리뷰 증거\n[Image: settings.bmp → ${imagePath}]`,
(message) => logs.push(message),
);
expect(input).toEqual([
{ type: 'text', text: '리뷰 증거' },
{
type: 'text',
text: `[Image unavailable: settings.bmp → ${imagePath} — unsupported image type .bmp]`,
},
]);
expect(logs).toContain(`Unsupported image type, skipping: ${imagePath}`);
});
});