Skip to content

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.

fix(claude): 压缩说明讲清补回的图为什么出现在之前的回复前面

chipfighter2cfeeb8de3a3
diff --git a/plugin/src/rewrite.ts b/plugin/src/rewrite.ts
index 65e3fb2..579705a 100644
--- a/plugin/src/rewrite.ts
+++ b/plugin/src/rewrite.ts
@@ -89,7 +89,7 @@ const WORDS: Record<Lang, Words> = {
// 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 ? `即使它之前被省略过${auto ? "" : "、或者正是你要过的图"},也是这样:用户${auto ? "固定发送" : "勾回"}的图回到这里,不会出现在用户的新消息里,不要让用户重新附上。` : ""}你之前说过看不到哪张图,那是因为它当时被省略了,没有说错。`,
+ `${missing === null ? "上下文管理说明(来自用户安装的上下文素材管理工具):" : "上下文管理说明:"}上面这条消息里,摘要之前的对话中有这些图片:${list}。压缩对话时它们被移出了上下文;这个工具把用户${auto ? "固定发送" : "勾选要发送"}的那些放回了摘要后面,前面标着“[图片 IMG-xxx 已提供…]”,紧接着就是原图:它们现在就在你面前,被问到时直接看图回答,不要说看不到。${missing === null ? `即使它之前被省略过${auto ? "" : "、或者正是你要过的图"},也是这样:用户${auto ? "固定发送" : "勾回"}的图回到这里,不会出现在用户的新消息里,不要让用户重新附上。` : ""}这一段是这个工具每次请求时重新放的:图被省略的那些请求里,这里并没有它;它现在出现在你之前的回复前面,只是因为这次放了回来。所以你之前说看不到哪张图,当时是实情,不是错误,不用纠正。`,
...(missing === null ? [] : [
`这次没有提供的是 ${missing}(${auto ? "自动选图开着,之前各轮的图默认不发" : "用户取消了勾选"},为了节省上下文):摘要后面它们的位置换成了“[图片 IMG-xxx 已省略…]”这样的占位文字,那是这次请求才换上的。你之前看过它们的原图:在压缩之前的对话里,有的在压缩之后也提供过;你对它们的描述和据此做出的判断,不管是在摘要里还是在后面的回复里,都是看着原图做出的,仍然有效,不要收回,也不要说成是猜测或编造。${auto ? "现在你看不到它们,不要补充之前没说过的细节。" : "现在你看不到它们:被问到时,如实说现在看不到(被用户省略了),不要补充之前没说过的细节。"}`,
auto
@@ -138,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 ? ` 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 ? "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.` : ""} This tool rebuilds this part for every request: in the requests where an image was left out, it was not here; it shows up before your earlier replies now only because it was put back for this request. So if you said before that you could not see an image, that was true then, not a mistake; do not correct it.`,
...(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."}`,
auto
diff --git a/spike/src/claude-rewrite.test.ts b/spike/src/claude-rewrite.test.ts
index 7c3fd92..2afc919 100644
--- a/spike/src/claude-rewrite.test.ts
+++ b/spike/src/claude-rewrite.test.ts
@@ -212,7 +212,7 @@ test("v0.5: after a compaction, the images from before it go back right after th
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/);
+ for (const text of [note, all.messages[1].content]) assert.match(text, /it shows up before your earlier replies now only because it was put back for this request. So if you said before that you could not see an image, that was true then, 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" });