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
fix(claude): 压缩后全部勾回时,说明里写明勾回的图回到摘要后面
chipfighter969b76fbaa0a
diff --git a/plugin/src/rewrite.ts b/plugin/src/rewrite.tsindex d98f004..65e3fb2 100644--- a/plugin/src/rewrite.ts+++ b/plugin/src/rewrite.ts@@ -84,9 +84,12 @@ const WORDS: Record<Lang, Words> = {// 2026-10-12, Haiku 5.5: while this note sat inside the user message holding the summary, unchecking an image that// had been sent again made the model take back what it had said looking at it ("没有依据的数字,应当撤回") and ask// for it to be provided again, also once the note named it and said not to. Like v0.4's notes, it now follows that- // message as a system message, after the full note when something is left out (compactedNote).+ // message as a system message, after the full note when something is left out (compactedNote). Same test, with all+ // checked again: the model looked for the image it had asked for in the user's new message ("这次消息里没有附上"),+ // as GPT-6 Luna did in v0.1-25; with nothing left out the full note is not there to say where it comes back. Once it+ // answered from it, it called its earlier "需要 IMG-001" a mistake ("一直在我的上下文里"), in both languages.compacted: (list, missing, auto) => [- `${missing === null ? "上下文管理说明(来自用户安装的上下文素材管理工具):" : "上下文管理说明:"}上面这条消息里,摘要之前的对话中有这些图片:${list}。压缩对话时它们被移出了上下文;这个工具把用户${auto ? "固定发送" : "勾选要发送"}的那些放回了摘要后面,前面标着“[图片 IMG-xxx 已提供…]”,紧接着就是原图:它们现在就在你面前,被问到时直接看图回答,不要说看不到。`,+ `${missing === null ? "上下文管理说明(来自用户安装的上下文素材管理工具):" : "上下文管理说明:"}上面这条消息里,摘要之前的对话中有这些图片:${list}。压缩对话时它们被移出了上下文;这个工具把用户${auto ? "固定发送" : "勾选要发送"}的那些放回了摘要后面,前面标着“[图片 IMG-xxx 已提供…]”,紧接着就是原图:它们现在就在你面前,被问到时直接看图回答,不要说看不到。${missing === null ? `即使它之前被省略过${auto ? "" : "、或者正是你要过的图"},也是这样:用户${auto ? "固定发送" : "勾回"}的图回到这里,不会出现在用户的新消息里,不要让用户重新附上。` : ""}你之前说过看不到哪张图,那是因为它当时被省略了,没有说错。`,...(missing === null ? [] : [`这次没有提供的是 ${missing}(${auto ? "自动选图开着,之前各轮的图默认不发" : "用户取消了勾选"},为了节省上下文):摘要后面它们的位置换成了“[图片 IMG-xxx 已省略…]”这样的占位文字,那是这次请求才换上的。你之前看过它们的原图:在压缩之前的对话里,有的在压缩之后也提供过;你对它们的描述和据此做出的判断,不管是在摘要里还是在后面的回复里,都是看着原图做出的,仍然有效,不要收回,也不要说成是猜测或编造。${auto ? "现在你看不到它们,不要补充之前没说过的细节。" : "现在你看不到它们:被问到时,如实说现在看不到(被用户省略了),不要补充之前没说过的细节。"}`,auto@@ -135,7 +138,7 @@ const WORDS: Record<Lang, Words> = {hereAuto: (list) => `Context management note: in the message above, ${list} were original images at the time, and you looked at them then; what you said about them and the judgments you based on it remain valid, so do not take them back or call them guesses or made up. The placeholder text there was put in only for this request (automatic image selection); it is not what was there at the time. When what you said before is not enough, fetch the original with cam_view_image; do not add details you did not mention before.`,listItem: (id, name, kind) => `${id} (${[name, kind].filter(Boolean).join(", ")})`,compacted: (list, missing, auto) => [- `${missing === null ? "Context management note (from the context asset manager the user installed): " : "Context management note: "}in the message above, the conversation before the summary had these images: ${list}. Compacting the conversation took them out of context; this tool put the ones the user ${auto ? "pinned" : "checked to send"} back right after the summary, each marked "[Image IMG-xxx included…]" with the original image right after it. They are in front of you now: when asked about one, look at it and answer from it, and do not say you cannot see it.`,+ `${missing === null ? "Context management note (from the context asset manager the user installed): " : "Context management note: "}in the message above, the conversation before the summary had these images: ${list}. Compacting the conversation took them out of context; this tool put the ones the user ${auto ? "pinned" : "checked to send"} back right after the summary, each marked "[Image IMG-xxx included…]" with the original image right after it. They are in front of you now: when asked about one, look at it and answer from it, and do not say you cannot see it.${missing === null ? ` This holds even for an image omitted before${auto ? "" : " or one you asked for"}: an image the user ${auto ? "pins" : "checks again"} comes back there, not in the user's new message, so do not ask for it to be attached again.` : ""} If you said before that you could not see an image, that was because it was left out then; it was not a mistake.`,...(missing === null ? [] : [`Not included this time: ${missing} (${auto ? "automatic image selection is on, so images from earlier turns are left out by default" : "the user unchecked them"}, to save context). After the summary, where they would be, there is placeholder text such as "[Image IMG-xxx omitted…]", put in only for this request. You saw their originals: in the conversation before the compaction, and some also after it. What you said about them and the judgments you based on it, in the summary or in your later replies, were made looking at the original images and remain valid; do not take them back or call them guesses or made up. ${auto ? "You cannot see them now, so do not add details you did not mention before." : "You cannot see them now: if asked, say so truthfully (the user left them out), and do not add details you did not mention before."}`,autodiff --git a/spike/src/claude-rewrite.test.ts b/spike/src/claude-rewrite.test.tsindex f04ffcc..7c3fd92 100644--- a/spike/src/claude-rewrite.test.ts+++ b/spike/src/claude-rewrite.test.ts@@ -208,6 +208,11 @@ test("v0.5: after a compaction, the images from before it go back right after thassert.deepEqual(all.messages[0].content.map((b: any) => b.type === "image" ? "image" : b.text), ["summary", includedLabel(a, "en"), "image", includedLabel(c, "en"), "image"]);assert.ok(all.messages[1].content.startsWith("Context management note (from the context asset manager the user installed): "));assert.doesNotMatch(all.messages[1].content, /Not included this time/);+ // Without the full note, this one says where an image checked again comes back: not in the user's new message.+ assert.match(all.messages[1].content, /or one you asked for: an image the user checks again comes back there, not in the user's new message/);+ assert.doesNotMatch(note, /comes back there, not in the user's new message/);+ // Either way: saying earlier that it could not see one was no mistake.+ for (const text of [note, all.messages[1].content]) assert.match(text, /that was because it was left out then; it was not a mistake/);// Claude Code's own system message after the summary (an effort change): the note joins it, keeping its fields.const marked = [request[0], { role: "system", content: [], output_config: { effort: "low" } }, ...request.slice(1)];const joined = addCompacted(marked, "summary", [a, c], [{ image: c, block: block(pngC) }], { lang: "en" });