fix: carry paired turn attachments into review context (#201)

This commit is contained in:
Eyejoker
2026-05-31 14:49:56 +09:00
committed by GitHub
parent 37b57b20bb
commit 6eca648c47
22 changed files with 615 additions and 67 deletions

View File

@@ -0,0 +1,49 @@
import fs from 'fs';
import os from 'os';
import path from 'path';
import { afterEach, describe, expect, it } from 'vitest';
import { buildMultimodalContent } from '../src/output-protocol.js';
const ONE_PIXEL_PNG = Buffer.from(
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=',
'base64',
);
const cleanupDirs: string[] = [];
afterEach(() => {
for (const dir of cleanupDirs.splice(0)) {
fs.rmSync(dir, { force: true, recursive: true });
}
});
describe('agent-runner multimodal prompts', () => {
it('loads labeled image tags as Claude image blocks', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ejclaw-image-tag-'));
cleanupDirs.push(dir);
const imagePath = path.join(dir, 'settings-v0.1.92-deployed-390.png');
fs.writeFileSync(imagePath, ONE_PIXEL_PNG);
const logs: string[] = [];
const content = buildMultimodalContent(
`리뷰 증거\n[Image: settings-v0.1.92-deployed-390.png → ${imagePath}]`,
(message) => logs.push(message),
);
expect(Array.isArray(content)).toBe(true);
expect(content).toEqual([
{ type: 'text', text: '리뷰 증거' },
{
type: 'image',
source: {
type: 'base64',
media_type: 'image/png',
data: ONE_PIXEL_PNG.toString('base64'),
},
},
]);
expect(logs).toContain(`Added image block: ${imagePath} (image/png)`);
});
});

View File

@@ -0,0 +1,32 @@
import fs from 'fs';
import { extractImageTagPaths } from 'ejclaw-runners-shared';
import type { AppServerInputItem } from './app-server-client.js';
export function parseAppServerInput(
text: string,
log: (message: string) => void = () => undefined,
): AppServerInputItem[] {
const { cleanText, imagePaths } = extractImageTagPaths(text);
const input: AppServerInputItem[] = [];
if (cleanText) {
input.push({ type: 'text', text: cleanText });
}
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}`);
}
}
if (input.length === 0) {
input.push({ type: 'text', text });
}
return input;
}

View File

@@ -17,7 +17,6 @@ import path from 'path';
import {
EJCLAW_ENV,
extractImageTagPaths,
IPC_CLOSE_SENTINEL,
IPC_INPUT_SUBDIR,
IPC_POLL_MS,
@@ -26,10 +25,8 @@ import {
type RunnerStructuredOutput,
} from 'ejclaw-runners-shared';
import {
CodexAppServerClient,
type AppServerInputItem,
} from './app-server-client.js';
import { CodexAppServerClient } from './app-server-client.js';
import { parseAppServerInput } from './app-server-input.js';
import {
prependRoomRoleHeader,
type RoomRoleContext,
@@ -173,37 +170,6 @@ function drainIpcInput(): string[] {
}
}
function extractImagePaths(text: string): {
cleanText: string;
imagePaths: string[];
} {
return extractImageTagPaths(text);
}
function parseAppServerInput(text: string): AppServerInputItem[] {
const { cleanText, imagePaths } = extractImagePaths(text);
const input: AppServerInputItem[] = [];
if (cleanText) {
input.push({ type: 'text', text: cleanText });
}
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}`);
}
}
if (input.length === 0) {
input.push({ type: 'text', text });
}
return input;
}
function formatProgressElapsed(ms: number): string {
const elapsedSeconds = Math.floor(ms / 10_000) * 10;
const hours = Math.floor(elapsedSeconds / 3600);
@@ -231,7 +197,7 @@ async function executeAppServerTurn(
let lastProgressMessage: string | null = null;
const activeTurn = await client.startTurn(
threadId,
parseAppServerInput(prompt),
parseAppServerInput(prompt, log),
{
cwd: EFFECTIVE_CWD,
model: CODEX_MODEL || undefined,
@@ -277,7 +243,7 @@ async function executeAppServerTurn(
const merged = messages.join('\n');
log(`Steering active turn with ${messages.length} queued message(s)`);
try {
await activeTurn.steer(parseAppServerInput(merged));
await activeTurn.steer(parseAppServerInput(merged, log));
} catch (err) {
log(
`turn/steer failed: ${err instanceof Error ? err.message : String(err)}`,

View File

@@ -0,0 +1,41 @@
import fs from 'fs';
import os from 'os';
import path from 'path';
import { afterEach, describe, expect, it } from 'vitest';
import { parseAppServerInput } from '../src/app-server-input.js';
const ONE_PIXEL_PNG = Buffer.from(
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=',
'base64',
);
const cleanupDirs: string[] = [];
afterEach(() => {
for (const dir of cleanupDirs.splice(0)) {
fs.rmSync(dir, { force: true, recursive: true });
}
});
describe('codex app-server input', () => {
it('loads labeled image tags as local image input items', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ejclaw-codex-image-'));
cleanupDirs.push(dir);
const imagePath = path.join(dir, 'settings-v0.1.92-deployed-390.png');
fs.writeFileSync(imagePath, ONE_PIXEL_PNG);
const logs: string[] = [];
const input = parseAppServerInput(
`리뷰 증거\n[Image: settings-v0.1.92-deployed-390.png → ${imagePath}]`,
(message) => logs.push(message),
);
expect(input).toEqual([
{ type: 'text', text: '리뷰 증거' },
{ type: 'localImage', path: imagePath },
]);
expect(logs).toContain(`Adding image input: ${imagePath}`);
});
});