A local plugin for image-heavy chats in Codex, Claude Code and other agents: earlier images stop going out with every message, and the model fetches the one it needs by its ID, also after compaction.
TypeScript ai-agentsclaude-codeclaude-code-plugincodexcodex-plugincontext-managementdeveloper-toolsimage-generationmcpmultimodal
test(selftest): 可以用 CAM_TEST_MODEL、CAM_TEST_EFFORT 换模型;记下模型是否原样写出要图的话
chipfighter00d13981878e
diff --git a/spike/src/testkit.ts b/spike/src/testkit.tsindex 3abd80f..a9c17cc 100644--- a/spike/src/testkit.ts+++ b/spike/src/testkit.ts@@ -49,15 +49,17 @@ export const testImages = {},};-// Tests use gpt-6-sol at low effort to save the user's tokens (AGENTS.md).-export const TEST_MODEL = "gpt-6-sol";+// Tests use gpt-6-sol at low effort to save the user's tokens (AGENTS.md). v0.1-24: CAM_TEST_MODEL and CAM_TEST_EFFORT+// run the same test on another model, to check that the text for the model works for every GPT-6 model.+export const TEST_MODEL = process.env.CAM_TEST_MODEL?.trim() || "gpt-6-sol";+export const TEST_EFFORT = process.env.CAM_TEST_EFFORT?.trim() || "low";export const text = (value: string) => ({ type: "text", text: value, text_elements: [] });export async function runTurn(server: AppServer, threadId: string, input: Json[], timeoutMs = 20 * 60_000): Promise<Json> {const started = Date.now();const before = server.notifications.length;- const { turn } = await server.request<{ turn: Json }>("turn/start", { threadId, input, effort: "low" }, 120_000);+ const { turn } = await server.request<{ turn: Json }>("turn/start", { threadId, input, effort: TEST_EFFORT }, 120_000);const done = await server.waitFor((n) => n.method === "turn/completed" && n.params.turn?.id === turn.id, timeoutMs);const mine = server.notifications.slice(before).filter((n) => n.params?.turnId === turn.id || n.params?.turn?.id === turn.id);const items = mine.filter((n) => n.method === "item/completed").map((n) => n.params.item);diff --git a/spike/src/v01-needs-selftest.ts b/spike/src/v01-needs-selftest.tsindex 149ae3c..28528ee 100644--- a/spike/src/v01-needs-selftest.ts+++ b/spike/src/v01-needs-selftest.ts@@ -24,7 +24,7 @@ import { selectionDirOf } from "../../plugin/src/paths.ts";import { readRequestStats } from "../../plugin/src/request-stats.ts";import { writeSelection } from "../../plugin/src/selection.ts";import { loadThreadIndex } from "../../plugin/src/thread-index.ts";-import { png, runTurn, TEST_MODEL, text } from "./testkit.ts";+import { png, runTurn, TEST_EFFORT, TEST_MODEL, text } from "./testkit.ts";type Json = Record<string, any>;const here = dirname(fileURLToPath(import.meta.url));@@ -116,7 +116,7 @@ async function main(): Promise<void> {const off = ["computer-use@openai-bundled", "unified-computer-use@openai-bundled", "chrome@openai-bundled", "browser@openai-bundled", "codex-app-tools@openai-bundled"].flatMap((plugin) => ["-c", `plugins.${plugin}.enabled=false`]);const server = new AppServer(findBundledCodex(), ["-c", `openai_base_url="http://localhost:${port}/backend-api/codex"`, "-c", "features.respect_system_proxy=true", "-c", "notify=[]", "-c", "mcp_servers.node_repl.enabled=false", ...off], { NO_PROXY: undefined, no_proxy: undefined }, join(root, `needs-appserver-${label}.log`));- const result: Json = { createdAt: new Date().toISOString(), label, lang, threads: [] };+ const result: Json = { createdAt: new Date().toISOString(), label, lang, model: TEST_MODEL, effort: TEST_EFFORT, threads: [] };const sessionsDir = join(codexHome(), "sessions");try {// thread/resume takes a history only from a client that opts into the experimental API.@@ -165,6 +165,8 @@ async function main(): Promise<void> {turns: Object.fromEntries(Object.entries(entry.turns as Record<string, Json>).map(([name, t]) => [name, {// What the panel picks up from this reply (its bar and tags), next to every id the reply mentions.panelSees: askedIn(String(t.reply)), ids: [...new Set(String(t.reply).match(/IMG-\d{3}/g) ?? [])], asksForNewShots: words.newShots.test(t.reply),+ // v0.1-24: whether the reply uses the words the note asks for ("需要 IMG-xxx" / "need IMG-xxx").+ writesNeed: /需要\s*[“"*]*\s*IMG-\d{3}|\bneed\s*[“"*]*\s*IMG-\d{3}/i.test(String(t.reply)),tools: t.tools, status: t.status, errors: t.errors, reply: t.reply,}])),}));diff --git a/spike/src/v01-placeholder-selftest.ts b/spike/src/v01-placeholder-selftest.tsindex f9b179f..170d545 100644--- a/spike/src/v01-placeholder-selftest.ts+++ b/spike/src/v01-placeholder-selftest.ts@@ -19,7 +19,7 @@ import { languageFileOf, rememberLang } from "../../plugin/src/language.ts";import { selectionDirOf } from "../../plugin/src/paths.ts";import { readRequestStats } from "../../plugin/src/request-stats.ts";import { writeSelection } from "../../plugin/src/selection.ts";-import { runTurn, TEST_MODEL, testImages, text } from "./testkit.ts";+import { runTurn, TEST_EFFORT, TEST_MODEL, testImages, text } from "./testkit.ts";import { loadThreadIndex } from "../../plugin/src/thread-index.ts";type Json = Record<string, any>;@@ -41,7 +41,7 @@ const SCRIPT = {colors: [/白/, /红/, /黑/],recalled: [/白/, /(方|正方)/],retraction: RETRACTION,- asks: (id: string) => new RegExp(`需要\\s*${id}`),+ asks: (id: string) => new RegExp(`需要\\s*[“"*]*\\s*${id}`),},en: {name: (label: string) => `[CAM test] v0.1 placeholder self-test ${label}`,@@ -53,7 +53,7 @@ const SCRIPT = {colors: [/white/i, /red/i, /black/i],recalled: [/white/i, /square/i],retraction: RETRACTION_EN,- asks: (id: string) => new RegExp(`need\\s*["“]?${id}`, "i"),+ asks: (id: string) => new RegExp(`need\\s*["“*]*\\s*${id}`, "i"),},};@@ -76,7 +76,7 @@ async function main(): Promise<void> {for (let i = 0; i < 50 && !(await engineHealth(port)); i++) await sleep(200);const startedAt = new Date().toISOString();const server = new AppServer(findBundledCodex(), ["-c", `openai_base_url="http://localhost:${port}/backend-api/codex"`, "-c", "features.respect_system_proxy=true"], { NO_PROXY: undefined, no_proxy: undefined }, join(root, `appserver-${label}.log`));- const result: Json = { createdAt: startedAt, label, lang, turns: {} };+ const result: Json = { createdAt: startedAt, label, lang, model: TEST_MODEL, effort: TEST_EFFORT, turns: {} };try {await server.initialize();const { thread } = await server.request<{ thread: Json }>("thread/start", { model: TEST_MODEL, cwd: work, approvalPolicy: "never", sandbox: "read-only", ephemeral: false });@@ -113,7 +113,7 @@ async function main(): Promise<void> {noErrors: Object.values(result.turns as Record<string, Json>).every((t) => t.status === "completed" && !t.errors.length),};writeFileSync(join(root, `placeholder-${label}.json`), JSON.stringify(result, null, 2));- console.log(JSON.stringify({ threadId: result.threadId, checks: result.checks, replies: Object.fromEntries(Object.entries(result.turns as Record<string, Json>).map(([name, t]) => [name, t.reply])) }, null, 2));+ console.log(JSON.stringify({ threadId: result.threadId, model: `${TEST_MODEL} ${TEST_EFFORT}`, checks: result.checks, replies: Object.fromEntries(Object.entries(result.turns as Record<string, Json>).map(([name, t]) => [name, t.reply])) }, null, 2));}await main();