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): 筛选按钮最多两行,其余收进“更多 N”,选中的始终露出来
chipfighter1b6edc146baa
diff --git a/plugin/src/panel.html b/plugin/src/panel.htmlindex 0de7552..fad03a7 100644--- a/plugin/src/panel.html+++ b/plugin/src/panel.html@@ -136,6 +136,11 @@.chip[aria-pressed="true"] { border-color: transparent; background: var(--accent); color: var(--accent-text); }.chip[aria-pressed="true"] .n { color: color-mix(in srgb, var(--accent-text) 70%, transparent); }.chips .sep { width: 1px; height: 16px; background: var(--border-strong); }+ /* At most two rows (user 2026-10-21): the rest fold into 更多 N, quieter than a filter. */+ .chip.fold { display: inline-flex; align-items: center; gap: 3px; padding: 0 6px 0 8px; border-color: transparent; color: var(--text-3); }+ .chip.fold:hover { color: var(--text-2); }+ .chip.fold svg { width: 13px; height: 13px; transition: transform .15s; }+ .chip.fold[aria-expanded="true"] svg { transform: rotate(180deg); }main { flex: 1; min-height: 0; overflow-y: auto; padding: 0 12px 16px; border-top: 1px solid var(--border); scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }.turn { position: relative; display: flex; align-items: center; gap: 10px; margin: 14px 4px 6px; color: var(--text-3); font-size: 12px; font-weight: 500; }@@ -331,6 +336,8 @@"chip.upload": "上传","chip.generated": "生成","chip.other": "其他",+ "chips.more": "更多 {count}",+ "chips.less": "收起","kind.upload": "用户上传","kind.view": "查看的图片","kind.generated": "生成的图片",@@ -454,6 +461,8 @@"chip.upload": "Uploaded","chip.generated": "Generated","chip.other": "Other",+ "chips.more": "{count} more",+ "chips.less": "Show less","kind.upload": "Uploaded","kind.view": "Viewed","kind.generated": "Generated",@@ -668,6 +677,7 @@switchingTask: false, // a cam_bind call is under waymanual: false, // the running refresh was asked for with the 刷新 buttonquery: "", chip: "all", // v0.8: the search and the one filter picked+ chipsOpen: false, // the filters beyond two rows shown (user 2026-10-21)cardOpen: false, // v0.8: the request card unfoldedautoPending: null, // v0.3: the switch's new state while it is being saved};@@ -693,7 +703,7 @@S.signature = signature;if (S.threadId && state.threadId !== S.threadId) {S.unsaved.clear(); S.thumbs.clear(); thumbQueue.length = 0; thumbsInFlight.clear();- S.preview = null; S.query = ""; S.chip = "all"; $("search").value = "";+ S.preview = null; S.query = ""; S.chip = "all"; S.chipsOpen = false; $("search").value = "";}S.threadId = state.threadId;S.data = state;@@ -1069,15 +1079,47 @@const button = Object.assign(document.createElement("button"), { type: "button", className: "chip" });button.dataset.chip = chip;button.append(label, Object.assign(document.createElement("span"), { className: "n", textContent: String(n) }));- button.addEventListener("click", () => { S.chip = chip; render(); });+ // Picking one folds the filters again: the one picked stays in view.+ button.addEventListener("click", () => { S.chip = chip; S.chipsOpen = false; render(); });return button;};// One filter alone (全部) says nothing either.const all = [...kinds, ...scenes];- box.replaceChildren(...(all.length < 2 ? [] : [...kinds.map(make), ...(scenes.length ? [Object.assign(document.createElement("span"), { className: "sep" })] : []), ...scenes.map(make)]));+ box.replaceChildren(...(all.length < 2 ? [] : [...kinds.map(make), ...(scenes.length ? [Object.assign(document.createElement("span"), { className: "sep" })] : []), ...scenes.map(make), foldButton]));}- for (const chip of box.querySelectorAll(".chip")) chip.setAttribute("aria-pressed", String(chip.dataset.chip === S.chip));+ for (const chip of box.querySelectorAll(".chip[data-chip]")) chip.setAttribute("aria-pressed", String(chip.dataset.chip === S.chip));+ foldChips();}+ // ---- at most two rows of filters (user 2026-10-21): the last ones fold into 更多 N, and the one picked stays in view+ // in front of it. Measured again only when the filters, the pick, the fold or the panel's width change. ----+ const foldButton = Object.assign(document.createElement("button"), { type: "button", className: "chip fold" });+ foldButton.innerHTML = '<span></span><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg>';+ foldButton.addEventListener("click", () => { S.chipsOpen = !S.chipsOpen; foldChips(); });+ let foldKey = "";+ function foldChips() {+ const box = $("chips");+ const key = `${chipsKey}|${S.chip}|${S.chipsOpen}|${box.clientWidth}`;+ if (key === foldKey) return;+ foldKey = key;+ const chips = [...box.querySelectorAll(".chip[data-chip]")];+ const label = foldButton.querySelector("span");+ for (const chip of chips) chip.hidden = false;+ foldButton.hidden = true;+ if (!chips.length || !box.clientWidth) return;+ const twoRows = 2 * chips[0].offsetHeight + (parseFloat(getComputedStyle(box).rowGap) || 0) + 1;+ if (box.offsetHeight <= twoRows) return;+ foldButton.hidden = false;+ foldButton.setAttribute("aria-expanded", String(S.chipsOpen));+ label.textContent = S.chipsOpen ? t("chips.less") : t("chips.more", { count: 0 });+ if (S.chipsOpen) return;+ let folded = 0;+ for (let i = chips.length - 1; i >= 0 && box.offsetHeight > twoRows; i--) {+ if (chips[i].dataset.chip === S.chip) continue;+ chips[i].hidden = true;+ label.textContent = t("chips.more", { count: ++folded });+ }+ }+ new ResizeObserver(() => foldChips()).observe($("chips"));// ---- the thumbnails, by turn, newest first ----const tiles = new Map();@@ -1381,7 +1423,8 @@input.setAttribute("aria-label", t("auto.label"));}- function render() { renderCard(); renderNeeds(); renderPlugin(); renderRefresh(); renderChips(); renderSearch(); renderList(); renderFooter(); renderViewer(); }+ // The search box and the filters show before the filters are folded, which measures them.+ function render() { renderCard(); renderNeeds(); renderPlugin(); renderRefresh(); renderSearch(); renderChips(); renderList(); renderFooter(); renderViewer(); }$("more").addEventListener("click", () => { S.cardOpen = !S.cardOpen; renderCard(); });$("search").addEventListener("input", (event) => { S.query = event.target.value; renderList(); });diff --git a/spike/scripts/panel-dev.ts b/spike/scripts/panel-dev.tsindex f26024b..b3e9878 100644--- a/spike/scripts/panel-dev.ts+++ b/spike/scripts/panel-dev.ts@@ -13,7 +13,7 @@// ?demo=filter for the filter bar open with PDF pages picked, ?demo=filtered for the same folded away, v0.2;// ?thread=auto for the same task with automatic selection on, IMG-002 pinned and a last turn in which the model fetched// IMG-004 and IMG-007, v0.3; ?thread=v08 for keyframes of one character in two scenes with the model's feature lines,-// and ?thread=v08m for the same in manual mode, v0.8).+// and ?thread=v08m for the same in manual mode, v0.8; ?thread=scenes for 28 scenes, more filters than two rows hold).// The demo task has a name, as if the user had renamed it in Codex (v0.1-9). Its last two turns (v0.2) hold comments on// a PDF and on a web page, as Codex desktop attaches them, and an image a tool returned.// Everything is written to a temporary folder, including a Codex home of its own: nothing in the user's Codex home is@@ -265,11 +265,34 @@ for (const [auto, manual, w] of V08_TASKS) {writeFileSync(join(day, `rollout-2026-09-24T13-30-00-${manual}.jsonl`), line("session_meta", { id: manual }) + v08Story(w) + say(w.needs, "v7"));}+// ?thread=scenes (user 2026-10-21): 40 generated keyframes over 10 turns, automatic selection on, the model naming+// nearly every image's scene after the place and what the image is for, as GPT-6 did in a user's MV task: 28 scenes,+// more filters than two rows hold.+const SCENES = `${THREAD.slice(0, -4)}a084`;+const PLACES = [["厨房", WARM, LAMP], ["街角", NIGHT, NEON], ["天台", [70, 110, 160], [255, 255, 255]], ["书店", [90, 70, 50], LAMP]] as const;+const PURPOSES = ["线稿", "首帧", "尾帧", "局部核对", "运镜检查", "构图草图v2", "构图草图v3"];+const SIZES = [["medium", "中景"], ["close", "近景"], ["wide", "远景"], ["medium", "中景"]] as const;+let scenesLog = line("session_meta", { id: SCENES });+for (let k = 0; k < 10; k++) {+ const id = `s${k + 1}`;+ const lines: string[] = [];+ scenesLog += turn(id) + ask(`msg_${id}`, id, `第三场再出四张${PURPOSES[k % 7]}。`);+ PLACES.forEach(([place, sky, glow], j) => {+ const n = k * 4 + j + 1;+ const [size, word] = SIZES[(k + j) % 4];+ scenesLog += made(`gs${n}`, `s-${n}.png`, keyframe([...sky], [...glow], size, 0.3 + ((n * 37) % 40) / 100), `${place} ${PURPOSES[k % 7]} ${word}`);+ lines.push(`[//]: # (cam IMG-${String(n).padStart(3, "0")} 03场${place}${PURPOSES[k % 7]}|${word},人物侧身,${place}背景)`);+ });+ scenesLog += say(`${lines.join("\n")}\n\n四张都好了。`, id);+}+writeFileSync(join(day, `rollout-2026-09-24T14-00-00-${SCENES}.jsonl`), scenesLog);+// Their names, as Codex keeps them next to the sessions folder (the panel's title).writeFileSync(join(root, "session_index.jsonl"), `${JSON.stringify({ id: THREAD, thread_name: "海报配色调整", updated_at: "2026-09-24T10:00:00Z" })}${JSON.stringify({ id: MANY, thread_name: "产品图批量修图", updated_at: "2026-09-24T12:00:00Z" })}${JSON.stringify({ id: AUTO, thread_name: "海报配色调整", updated_at: "2026-09-24T10:30:00Z" })}${V08_TASKS.flatMap(([auto, manual, w]) => [auto, manual].map((id) => JSON.stringify({ id, thread_name: w.name, updated_at: "2026-09-24T13:00:00Z" }))).join("\n")}+${JSON.stringify({ id: SCENES, thread_name: "宣传片第三场", updated_at: "2026-09-24T14:00:00Z" })}`);// New tasks the user starts after opening the panel on a new chat (?newtask=): Codex files them in today's folder.@@ -315,6 +338,7 @@ for (const [auto, manual] of V08_TASKS) {callTool("cam_set_selection", { auto: false }, metaOf(manual), sessionsDir);callTool("cam_set_selection", { uncheck: ["IMG-003", "IMG-008", "IMG-009"] }, metaOf(manual), sessionsDir);}+callTool("cam_set_selection", { auto: true }, metaOf(SCENES), sessionsDir);// What the engine would have recorded: the last full request came in turn 3 (turn 4's images are new since) and had// IMG-001, IMG-005 and IMG-006 replaced. ?stats=skipped|websocket|none shows the other cases.@@ -401,7 +425,7 @@ const HOST = `<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><titconst fresh = params.get("thread") === "fresh" ? Math.random().toString(16).slice(2, 6).padEnd(4, "0") : null;// ?thread=v08 and v08m with ?lang=en: the same task in English.const english = params.get("thread")?.startsWith("v08") && params.get("lang") === "en" ? "&en=1" : "";- const query = fresh ? "?fresh=" + fresh : ["gap", "many", "auto", "v08", "v08m"].includes(params.get("thread")) ? "?" + params.get("thread") + "=1" + english : "";+ const query = fresh ? "?fresh=" + fresh : ["gap", "many", "auto", "v08", "v08m", "scenes"].includes(params.get("thread")) ? "?" + params.get("thread") + "=1" + english : "";const call = (name, args) => fetch("/call" + query, { method: "POST", body: JSON.stringify({ name, arguments: args }) }).then((r) => r.json());window.addEventListener("message", async (event) => {const m = event.data;@@ -473,8 +497,9 @@ createServer((request, response) => {const auto = new URL(request.url, "http://x").searchParams.has("auto");const v08 = new URL(request.url, "http://x").searchParams.has("v08");const v08m = new URL(request.url, "http://x").searchParams.has("v08m");+ const scenes = new URL(request.url, "http://x").searchParams.has("scenes");const [v08Task, v08mTask] = V08_TASKS[new URL(request.url, "http://x").searchParams.has("en") ? 1 : 0];- const threadMeta = fresh && /^[0-9a-f]{4}$/.test(fresh) ? { threadId: freshId, thread_id: freshId } : gap ? { threadId: GAP, thread_id: GAP } : many ? manyMeta : auto ? autoMeta : v08 ? metaOf(v08Task) : v08m ? metaOf(v08mTask) : meta;+ const threadMeta = fresh && /^[0-9a-f]{4}$/.test(fresh) ? { threadId: freshId, thread_id: freshId } : gap ? { threadId: GAP, thread_id: GAP } : many ? manyMeta : auto ? autoMeta : v08 ? metaOf(v08Task) : v08m ? metaOf(v08mTask) : scenes ? metaOf(SCENES) : meta;try { reply(200, "application/json", JSON.stringify(callTool(name, args ?? {}, threadMeta, sessionsDir))); }catch (error) { reply(200, "application/json", JSON.stringify({ isError: true, content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }] })); }});