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(panel): 认出模型要图的其他写法:编号加粗、“请重新勾选”、check back in、restore(v0.1-19)
chipfighter7ba4a83f5edf
diff --git a/plugin/src/panel-state.ts b/plugin/src/panel-state.tsindex 0079b44..3fe6d56 100644--- a/plugin/src/panel-state.ts+++ b/plugin/src/panel-state.ts@@ -70,11 +70,26 @@ export type PanelOptions = { sessionsDir: string; dataRoot?: string };// "需要 IMG-004" or a list right after it ("需要 IMG-004、IMG-002 和 IMG-007"); a full stop ends the list. The English// wording (v0.1-14) asks for "need IMG-004", which the model may quote.+// v0.1-17 (self-test 2026-09-26): the model may also put the ids, or the whole list, in bold ("需要 **IMG-003**"), or ask+// the user to check them again in the note's own words ("请重新勾选 IMG-003 和 IMG-004", "please check IMG-004 back in",+// "please restore IMG-004"); "取消勾选" and a state ("已勾选", "没勾选", "was restored") are not asking.+const MARKS = "[“”\"'‘’「」*_`]*";+const item = (separators: string) => `(?:\\s*${MARKS}\\s*IMG-\\d{3,}\\s*${MARKS}\\s*(?:${separators})?)`;+const ZH_LIST = `(${item("[、,,/]|以及|和|与|及")}+)`;+const EN_LIST = `(${item(",|and")}+)`;const ASKED = [- /需要((?:\s*[“"'「]?\s*IMG-\d{3,}\s*[”"'」]?\s*(?:[、,,/]|以及|和|与|及)?)+)/g,- /\bneeds?((?:\s*["'“”‘’]?\s*IMG-\d{3,}\s*["'“”‘’]?\s*(?:,|and)?)+)/gi,+ new RegExp(`(?:需要|(?<!取消|已|已经|没|没有|未)(?:重新)?勾选)${ZH_LIST}`, "g"),+ new RegExp(`\\b(?:needs?|restore|re-?enable|re-?check|re-?select)${EN_LIST}`, "gi"),+ new RegExp(`\\bcheck${EN_LIST}\\s*(?:back|again)\\b`, "gi"),];+// The ids one reply asks for.+export function askedIn(text: string): string[] {+ const ids = new Set<string>();+ for (const pattern of ASKED) for (const match of text.matchAll(pattern)) for (const id of match[1].matchAll(/IMG-\d{3,}/gi)) ids.add(id[0].toUpperCase());+ return [...ids];+}+// Ids the model asked for ("需要 IMG-003") in its latest reply; a turn still running falls back to the one before.export function requestedIds(history: Record_[]): string[] {let current: string[] = [];@@ -88,11 +103,7 @@ export function requestedIds(history: Record_[]): string[] {for (const part of record.payload.content ?? []) if (typeof part?.text === "string") current.push(part.text);}}- const ids = new Set<string>();- for (const text of current.length ? current : previous) {- for (const pattern of ASKED) for (const match of text.matchAll(pattern)) for (const id of match[1].matchAll(/IMG-\d{3,}/gi)) ids.add(id[0].toUpperCase());- }- return [...ids];+ return [...new Set((current.length ? current : previous).flatMap(askedIn))];}export function sameContent(index: ThreadIndex, image: IndexedImage): string[] {diff --git a/spike/src/panel-state.test.ts b/spike/src/panel-state.test.tsindex 68bff71..7c5a29d 100644--- a/spike/src/panel-state.test.ts+++ b/spike/src/panel-state.test.ts@@ -23,6 +23,21 @@ test("the ids the model asked for come from its latest reply only", () => {assert.deepEqual(requestedIds(records(turn("t1") + assistant("To answer that I need \"IMG-004\" and IMG-002.", "t1"))), ["IMG-004", "IMG-002"], "the English wording, quoted");});+// v0.1-17 — replies seen in the 2026-09-26 self-test (unnamed tool screenshots, all unchecked): the model bolds the ids,+// or asks the user to check them again instead of writing "需要".+test("an asked-for id may be in bold, or asked for as checking it again; unchecking or a checked state is not asking", () => {+ const asked = (reply: string) => requestedIds(records(turn("t1") + assistant(reply, "t1")));+ assert.deepEqual(asked("需要 **IMG-003**(录像路径所在的设置页)。如果还想让我检查视频设置,也请勾选 **IMG-004**。"), ["IMG-003", "IMG-004"]);+ assert.deepEqual(asked("我无法根据当前画面确认设置是否已经保存。要我重新查看,请重新勾选 **IMG-003 和 IMG-004**。"), ["IMG-003", "IMG-004"]);+ assert.deepEqual(asked("To confirm it I need **IMG-004**."), ["IMG-004"]);+ assert.deepEqual(asked("你取消勾选了 IMG-003,所以现在看不到。IMG-002 已勾选,会照常发送;已勾选 IMG-001,没勾选 IMG-005。"), []);+ // English: "check it back in", "restore it" (the note says the user "can check it again").+ assert.deepEqual(asked("Please check **IMG-003** and **IMG-004** back into the conversation. IMG-003 shows the recording path settings, and IMG-004 shows the Video settings page."), ["IMG-003", "IMG-004"]);+ assert.deepEqual(asked("I can’t see IMG-004 now, so I can’t tell what color the shape is. Please check IMG-004 back in."), ["IMG-004"]);+ assert.deepEqual(asked("I can’t see that screenshot now because it was left out of the current context. If you want me to check the color, please restore IMG-004."), ["IMG-004"]);+ assert.deepEqual(asked("IMG-003 was restored earlier, and I will check IMG-004 carefully; I can't see IMG-002 now."), []);+});+test("panel state lists every image with checked, same-content and requested flags", () => {const options = sampleSessions();const state = loadPanelState(THREAD, options);