fix: carry paired turn attachments into review context (#201)
This commit is contained in:
32
runners/codex-runner/src/app-server-input.ts
Normal file
32
runners/codex-runner/src/app-server-input.ts
Normal 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;
|
||||
}
|
||||
@@ -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)}`,
|
||||
|
||||
41
runners/codex-runner/test/app-server-input.test.ts
Normal file
41
runners/codex-runner/test/app-server-input.test.ts
Normal 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}`);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user