Skip to content

Stop paying the multimodal tax. Your AI agent keeps every image it has seen but only sends the ones it needs: lighter chats, no endless reconnecting, no starting over. Works with Codex, Claude Code, Cline, Gemini CLI, OpenCode, WorkBuddy and more. Install once, forget it.

feat(panel): 自动选图的开关、固定发送和“最近一轮模型取回”

chipfighter68d020ba1527
diff --git a/plugin/src/messages.ts b/plugin/src/messages.ts
index 99e4b28..99734ea 100644
--- a/plugin/src/messages.ts
+++ b/plugin/src/messages.ts
@@ -14,7 +14,7 @@ const zh = {
"tool.panel.title": "上下文素材",
"tool.panel.description": "上下文素材面板:查看这个任务里的历史图片,勾选下一条消息要发给模型的图片。由用户在侧边面板里打开,模型不需要调用。",
"tool.select.title": "上下文素材:勾选",
- "tool.select.description": "素材面板内部使用:勾选或取消图片。只有用户能操作,模型调用会被拒绝。",
+ "tool.select.description": "素材面板内部使用:勾选或取消图片,开关自动选图。只有用户能操作,模型调用会被拒绝。",
"tool.image.title": "上下文素材:图片",
"tool.image.description": "素材面板内部使用:读取一张图片的缩略图或预览图。模型不需要调用。",
"tool.setup.title": "上下文素材:启用或停用",
@@ -85,7 +85,7 @@ const en: Record<keyof typeof zh, string> = {
"tool.panel.title": "Context Assets",
"tool.panel.description": "Context Assets panel: see the images in this task's history and choose which go to the model with the next message. The user opens it from the side panel; the model does not need to call it.",
"tool.select.title": "Context Assets: check",
- "tool.select.description": "Used by the panel: check or uncheck images. Only the user can do this; calls from the model are refused.",
+ "tool.select.description": "Used by the panel: check or uncheck images, and switch automatic selection. Only the user can do this; calls from the model are refused.",
"tool.image.title": "Context Assets: image",
"tool.image.description": "Used by the panel: read an image's thumbnail or preview. The model does not need to call it.",
"tool.setup.title": "Context Assets: enable or disable",
diff --git a/plugin/src/panel-state.ts b/plugin/src/panel-state.ts
index dffe6f1..f885c0f 100644
--- a/plugin/src/panel-state.ts
+++ b/plugin/src/panel-state.ts
@@ -4,13 +4,15 @@
// the last full request as a size baseline, which images it carried, and whether the engine could not rewrite it.
// v0.1-9 — the task's name for the title (thread-names.ts). v0.1-13 — whether part of the history could not be found.
// v0.2 — each image's source, which the panel filters by.
+// v0.3 — automatic selection: the switch, the checkboxes meaning "pinned" while it is on (kept apart from the manual
+// checks), and the images the model fetched in the latest turn.
// Input: thread id, the sessions directory (rollouts are only read) and the tool's data directory.
// Output: PanelState as plain JSON; selection changes are written to <data dir>/selection/.
import type { ImageSource } from "./images.ts";
import { dataDir, requestStatsDirOf, selectionDirOf } from "./paths.ts";
import { readRequestStats, type RequestStats } from "./request-stats.ts";
-import { effectiveSelection, writeSelection } from "./selection.ts";
+import { effectiveSelection, writeSelection, type Mark, type Selection } from "./selection.ts";
import { buildIndex, imageData, readThreadHistory, type IndexedImage, type ThreadIndex } from "./thread-index.ts";
import { threadTitle } from "./thread-names.ts";
import { pngThumbnail } from "./thumbnail.ts";
@@ -22,7 +24,9 @@ export type PanelImage = {
// v0.2 — what the panel filters by; a PDF comment screenshot also says its page and the PDF's name when known.
source: ImageSource; pdfPage: number | null; pdfName: string | null;
width: number | null; height: number | null; bytes: number; base64Chars: number;
- sameAs: string[]; checked: boolean; replaceable: boolean; requested: boolean;
+ // checked: the box is ticked: sent with automatic selection off, pinned with it on (v0.3). fetched: the model fetched
+ // it in the latest turn.
+ sameAs: string[]; checked: boolean; replaceable: boolean; requested: boolean; fetched: boolean;
// Whether the last full request carried it (null: no such request recorded yet), and whether the next one will
// (carried last time, or added since; images compacted out of the history will not come back).
inLastRequest: boolean | null; inNextRequest: boolean;
@@ -38,8 +42,10 @@ export type SendInfo = {
// Codex prepared and then replaced (v0.1-8); that one never gets a rollout.
// historyMissing: an earlier part of the history is gone for good (e.g. the task a fork came from was deleted), so the
// images in it are not listed (v0.1-13).
+// auto: automatic selection is on (v0.3); fetched: the ids the model fetched in the latest turn.
export type PanelState = {
threadId: string; title: string | null; started: boolean; historyMissing: boolean; turns: number; images: PanelImage[]; requested: string[];
+ auto: boolean; fetched: string[];
totals: { images: number; unchecked: number; checkedBytes: number; allBytes: number };
send: SendInfo;
};
@@ -121,8 +127,10 @@ export function sameContent(index: ThreadIndex, image: IndexedImage): string[] {
.map((other) => other.id);
}
-export function panelState(threadId: string, history: Record_[], index: ThreadIndex, unchecked: Set<string>, stats: RequestStats | null, title: string | null = null): PanelState {
+// `unchecked`: the keys whose box is not ticked (v0.3: with automatic selection on, every image not pinned).
+export function panelState(threadId: string, history: Record_[], index: ThreadIndex, unchecked: Set<string>, stats: RequestStats | null, title: string | null = null, auto = false): PanelState {
const requested = requestedIds(history);
+ const fetched = [...new Set([...index.copies.values()].filter((copy) => copy.turn !== null && copy.turn === index.turns).map((copy) => copy.of))];
const carried: Record<string, number> | null = stats?.lastHttp?.imageSizes ?? null;
// Images after the last one that request carried, or from a later turn, were added since and go out next time.
const lastCarried = carried ? index.images.reduce((last, image, position) => (image.key in carried ? position : last), -1) : -1;
@@ -137,12 +145,13 @@ export function panelState(threadId: string, history: Record_[], index: ThreadIn
checked: !unchecked.has(image.key),
replaceable: image.replaceable,
requested: requested.includes(image.id),
+ fetched: fetched.includes(image.id),
inLastRequest: inLast,
inNextRequest: inLast !== false || position > lastCarried || (lastTurn !== null && image.turn !== null && image.turn > lastTurn),
};
});
return {
- threadId, title, started: history.length > 0, historyMissing: false, turns: index.turns, images, requested,
+ threadId, title, started: history.length > 0, historyMissing: false, turns: index.turns, images, requested, auto, fetched,
totals: {
images: images.length,
unchecked: images.filter((image) => !image.checked).length,
@@ -175,29 +184,47 @@ function load(threadId: string, options: PanelOptions) {
return { root, history, index, selection, stats, title, historyMissing: missing.length > 0 };
}
+// The keys whose box is not ticked: the unchecked ones; v0.3: with automatic selection on, every image that can be left
+// out and is not pinned.
+function offKeys(index: ThreadIndex, selection: Selection): Set<string> {
+ if (!selection.auto) return new Set(Object.keys(selection.unchecked));
+ const pinned = selection.pinned ?? {};
+ return new Set(index.images.filter((image) => image.replaceable && !pinned[image.key]).map((image) => image.key));
+}
+
export function loadPanelState(threadId: string, options: PanelOptions): PanelState {
const { history, index, selection, stats, title, historyMissing } = load(threadId, options);
- return { ...panelState(threadId, history, index, new Set(Object.keys(selection.unchecked)), stats, title), historyMissing };
+ return { ...panelState(threadId, history, index, offKeys(index, selection), stats, title, !!selection.auto), historyMissing };
}
-export function applySelection(threadId: string, change: { uncheck?: string[]; check?: string[]; checkAll?: boolean }, options: PanelOptions): PanelState {
+// v0.3: `auto` switches automatic selection; with `mode: "auto"` a tick pins an image instead of sending it, each kept
+// in its own record, so switching back finds the manual checks as they were.
+export function applySelection(threadId: string, change: { uncheck?: string[]; check?: string[]; checkAll?: boolean; auto?: boolean; mode?: "manual" | "auto" }, options: PanelOptions): PanelState {
const { root, history, index, selection, stats, title, historyMissing } = load(threadId, options);
- const unchecked = change.checkAll ? {} : { ...selection.unchecked };
+ const now = new Date().toISOString();
+ let next: Selection = { ...selection, threadId };
+ // Switched on for the first time, the thread is marked: from then on its history may hold copies the model fetched.
+ if (typeof change.auto === "boolean" && change.auto !== !!selection.auto) next = { ...next, auto: change.auto, autoAt: now, autoSince: selection.autoSince ?? now };
+ const pins = change.mode === "auto";
+ const marks: Record<string, Mark> = pins ? { ...(next.pinned ?? {}) } : change.checkAll ? {} : { ...next.unchecked };
const byId = new Map(index.images.map((image) => [image.id, image]));
- for (const id of change.uncheck ?? []) {
+ const imageOf = (id: string) => {
const image = byId.get(id);
if (!image) throw new Error(`${id} is not an image of this thread`);
+ return image;
+ };
+ for (const id of change.uncheck ?? []) {
+ const image = imageOf(id);
if (!image.replaceable) throw new Error(`${id} cannot be unchecked (hosted image generation result)`);
- unchecked[image.key] = { id, at: new Date().toISOString() };
+ if (pins) delete marks[image.key]; else marks[image.key] = { id, at: now };
}
for (const id of change.check ?? []) {
- const image = byId.get(id);
- if (!image) throw new Error(`${id} is not an image of this thread`);
- delete unchecked[image.key];
+ const image = imageOf(id);
+ if (pins) marks[image.key] = { id, at: now }; else delete marks[image.key];
}
- // The rest (v0.3: automatic selection's switch and pins) stays as it was.
- writeSelection({ ...selection, threadId, unchecked }, selectionDirOf(root));
- return { ...panelState(threadId, history, index, new Set(Object.keys(unchecked)), stats, title), historyMissing };
+ next = pins ? { ...next, pinned: marks } : { ...next, unchecked: marks };
+ writeSelection(next, selectionDirOf(root));
+ return { ...panelState(threadId, history, index, offKeys(index, next), stats, title, !!next.auto), historyMissing };
}
// One image for the panel: a PNG larger than maxSide is scaled down; smaller PNGs and other formats (which the
diff --git a/plugin/src/panel.html b/plugin/src/panel.html
index 44f2170..ac98fb1 100644
--- a/plugin/src/panel.html
+++ b/plugin/src/panel.html
@@ -29,6 +29,9 @@
v0.1-23: the panel never scrolls as a whole; only the list does (a turn's hidden checkbox once let it).
v0.2 (user 2026-09-29): a filter button next to 刷新 unfolds a bar of the task's sources (uploaded, PDF page, web page,
viewed, tool result, generated); picking some shows only their images. It changes what is shown, never what is sent.
+ v0.3 (user 2026-10-06): an automatic selection switch at the end of the footer. While it is on, a tick pins an image
+ (sent every turn; kept apart from the manual ticks), the others are left out unless the model fetches them, the bar
+ lists what the model fetched in the latest turn instead of what it asked for, and those rows say so.
-->
<style>
/* Fallbacks follow Codex's own widget palette; inside Codex its theme variables (MCP Apps host styles) win. */
@@ -114,6 +117,10 @@
.needs button { height: 22px; padding: 0 9px; border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); border-radius: 999px; background: var(--bg); color: var(--warn); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; cursor: pointer; transition: border-color .15s, transform .1s; }
.needs button:hover { border-color: var(--warn); }
.needs button:active { transform: scale(.96); }
+ /* v0.3: what the model fetched itself is news, not a request: the same bar in blue. */
+ .needs.fetched { background: var(--info-bg); color: var(--info); }
+ .needs.fetched button { border-color: color-mix(in srgb, var(--info) 35%, transparent); color: var(--info); }
+ .needs.fetched button:hover { border-color: var(--info); }
/* v0.2: rounded source buttons, drawn unlike the rows' square send checkboxes so the two are not confused. */
.filters { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { height: 26px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: 999px; background: transparent; color: var(--text-2); font-size: 12px; font-weight: 500; white-space: nowrap; cursor: pointer; transition: background .15s, border-color .15s, color .15s; }
@@ -173,6 +180,7 @@
.tags:empty { display: none; }
.tag { padding: 0 8px; border-radius: 999px; background: var(--bg-soft); color: var(--text-2); font-size: 11.5px; font-weight: 500; line-height: 20px; white-space: nowrap; }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
+ .tag.fetched { background: var(--info-bg); color: var(--info); }
.check input { position: absolute; opacity: 0; pointer-events: none; }
.box {
@@ -204,8 +212,17 @@
.empty strong { color: var(--text-2); font-weight: 500; font-size: 14px; }
.empty span { font-size: 12.5px; max-width: 260px; }
- footer { flex: none; display: flex; align-items: center; gap: 6px; padding: 12px 14px 12px 18px; border-top: 1px solid var(--border); background: var(--bg); }
+ footer { flex: none; display: flex; align-items: center; gap: 10px; padding: 12px 14px 12px 18px; border-top: 1px solid var(--border); background: var(--bg); }
.status { flex: 1; min-width: 0; color: var(--text-3); font-size: 12.5px; }
+ /* v0.3: the automatic selection switch, at the end of the footer whose line says what a tick means. */
+ .auto { flex: none; position: relative; display: inline-flex; align-items: center; gap: 7px; color: var(--text-2); font-size: 12.5px; font-weight: 500; cursor: pointer; user-select: none; white-space: nowrap; }
+ .auto input { position: absolute; opacity: 0; pointer-events: none; }
+ .auto .sw { position: relative; flex: none; width: 30px; height: 18px; border-radius: 999px; background: var(--border-strong); transition: background .15s; }
+ .auto .sw::after { content: ""; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--bg); box-shadow: 0 1px 2px rgb(0 0 0 / 25%); transition: left .15s; }
+ .auto input:checked + .sw { background: var(--accent); }
+ .auto input:checked + .sw::after { left: 14px; background: var(--accent-text); }
+ .auto input:disabled + .sw { opacity: .5; }
+ .auto input:focus-visible + .sw { outline: 2px solid var(--info); outline-offset: 2px; }
[hidden] { display: none !important; }
.viewer { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; background: rgb(19 19 19); color: rgb(245 245 245); }
@@ -241,6 +258,7 @@
<main id="main"></main>
<footer>
<div class="status" id="status"></div>
+ <label class="auto" id="auto" hidden><span class="auto-label"></span><input type="checkbox" role="switch"><span class="sw"></span></label>
</footer>
<div class="viewer" id="viewer" hidden role="dialog" aria-modal="true" aria-label="图片预览">
<div class="viewer-top">
@@ -276,10 +294,14 @@
"plan.failed": "读取失败",
"plan.empty": "还没有图片",
"plan.next": "下一条消息:发送 {sent} 张",
+ "plan.nextAuto": "下一条消息:固定发送 {sent} 张",
"plan.dropped": " · 占位 {dropped} 张",
"plan.duplicates": "(其中重复 {duplicates} 张)",
"plan.gone": " · {gone} 张已不在上下文",
"meter.request": "预计请求",
+ "meter.requestAuto": "预计请求",
+ "meter.atLeast": "{bytes} 起",
+ "meter.autoNote": "模型这一轮要取回的图不算在内(事先不知道会取哪几张)",
"meter.images": "预计图片数据",
"meter.full": "全部发送 {full} · 省 {percent}%",
"meter.none": "未取消任何图",
@@ -298,6 +320,8 @@
"tag.requested": "模型需要这张",
"needs.title": "模型需要 {count} 张没发送的图:",
"needs.jump": "在列表里定位到 {id}",
+ "fetched.title": "最近一轮模型取回 {count} 张:",
+ "tag.fetched": "模型取回",
"tag.replacedBy": "由 {id} 代替",
"tag.notSent": "不发送",
"tag.sameAs": "与 {id} 相同",
@@ -307,10 +331,15 @@
"turn.allEarlier": "发送更早的全部图片",
"turn.shown": "发送第 {n} 轮列出的图片",
"turn.shownEarlier": "发送更早列出的图片",
+ "turn.pinAll": "第 {n} 轮的全部图片固定发送",
+ "turn.pinAllEarlier": "更早的全部图片固定发送",
+ "turn.pinShown": "第 {n} 轮列出的图片固定发送",
+ "turn.pinShownEarlier": "更早列出的图片固定发送",
"row.unnamed": "未命名",
"row.pdfPage": "PDF 第 {page} 页",
"row.preview": "预览 {id}",
"row.send": "发送 {id}",
+ "row.pin": "固定发送 {id}",
"thumb.none": "无预览",
"empty.title": "这个任务里还没有图片",
"empty.text": "上传、查看或生成的图片会按时间顺序出现在这里。",
@@ -332,10 +361,14 @@
"chooser.title": "刚刚开始了好几个任务,这个面板要显示哪一个?",
"chooser.untitled": "新任务",
"footer.hint": "勾选的图片会随下一条消息发给模型",
+ "footer.hintAuto": "勾选的图每轮都发,其余由模型按需取回",
+ "auto.label": "自动选图",
+ "auto.title": "打开后,之前各轮的图默认不发,模型需要时自己按编号取回;勾选的图每轮都发",
"viewer.label": "图片预览",
"viewer.close": "关闭预览",
"viewer.closeTitle": "关闭(Esc)",
"viewer.send": "发送这张图",
+ "viewer.pin": "固定发送这张图",
"viewer.loading": "正在加载…",
"viewer.none": "这张图无法预览",
"error.load": "读取失败:{message}",
@@ -364,12 +397,17 @@
"plan.empty": "No images yet",
"plan.next": "Next message sends {sent} images",
"plan.next_one": "Next message sends {sent} image",
+ "plan.nextAuto": "Next message: {sent} pinned images",
+ "plan.nextAuto_one": "Next message: {sent} pinned image",
"plan.dropped": " · {dropped} as placeholders",
"plan.dropped_one": " · {dropped} as a placeholder",
"plan.duplicates": " ({duplicates} of them duplicates)",
"plan.duplicates_one": " ({duplicates} of them a duplicate)",
"plan.gone": " · {gone} no longer in context",
"meter.request": "Estimated request",
+ "meter.requestAuto": "At least",
+ "meter.atLeast": "{bytes}",
+ "meter.autoNote": "Images the model fetches this turn are not counted (they are not known beforehand)",
"meter.images": "Estimated image data",
"meter.full": "All images {full} · {percent}% saved",
"meter.none": "Nothing unchecked",
@@ -390,6 +428,9 @@
"needs.title": "The model needs {count} unsent images:",
"needs.title_one": "The model needs {count} unsent image:",
"needs.jump": "Show {id} in the list",
+ "fetched.title": "The model fetched {count} images in the latest turn:",
+ "fetched.title_one": "The model fetched {count} image in the latest turn:",
+ "tag.fetched": "Fetched by the model",
"tag.replacedBy": "Replaced by {id}",
"tag.notSent": "Not sent",
"tag.sameAs": "Same as {id}",
@@ -399,10 +440,15 @@
"turn.allEarlier": "Send all earlier images",
"turn.shown": "Send the listed images from turn {n}",
"turn.shownEarlier": "Send the listed earlier images",
+ "turn.pinAll": "Pin every image of turn {n}",
+ "turn.pinAllEarlier": "Pin every earlier image",
+ "turn.pinShown": "Pin the listed images of turn {n}",
+ "turn.pinShownEarlier": "Pin the listed earlier images",
"row.unnamed": "Unnamed",
"row.pdfPage": "PDF page {page}",
"row.preview": "Preview {id}",
"row.send": "Send {id}",
+ "row.pin": "Pin {id}",
"thumb.none": "No preview",
"empty.title": "No images in this task yet",
"empty.text": "Images you upload, and images the model views or generates, show up here in order.",
@@ -424,10 +470,14 @@
"chooser.title": "Several tasks just started. Which one should this panel show?",
"chooser.untitled": "New task",
"footer.hint": "Checked images go to the model with the next message",
+ "footer.hintAuto": "Checked images go every turn; the model fetches the rest as needed",
+ "auto.label": "Auto-select",
+ "auto.title": "When on, images from earlier turns are left out by default and the model fetches the ones it needs by id; checked images go every turn",
"viewer.label": "Image preview",
"viewer.close": "Close preview",
"viewer.closeTitle": "Close (Esc)",
"viewer.send": "Send this image",
+ "viewer.pin": "Pin this image",
"viewer.loading": "Loading…",
"viewer.none": "This image cannot be previewed",
"error.load": "Could not load: {message}",
@@ -575,6 +625,7 @@
switchingTask: false, // a cam_bind call is under way
manual: false, // the running refresh was asked for with the 刷新 button
filter: { open: false, sources: new Set() }, // v0.2: the filter bar, and the sources shown (none picked: all)
+ autoPending: null, // v0.3: the switch's new state while it is being saved
};
let lastFresh = 0; // when the panel last received the thread's state
// When this page was on screen (v0.1-10), sent with every read: a panel on a new chat is offered the threads started
@@ -586,6 +637,8 @@
const images = () => S.data?.images ?? [];
const byId = (id) => images().find((image) => image.id === id);
const isChecked = (image) => (S.unsaved.has(image.id) ? S.unsaved.get(image.id) : image.checked);
+ // v0.3: automatic selection; a tick then pins the image (the plugin keeps the two kinds of ticks apart).
+ const autoOn = () => S.autoPending ?? S.data?.auto ?? false;
function ingest(state) {
if (!state || !Array.isArray(state.images)) return;
@@ -641,7 +694,8 @@
const setChecked = (id, checked) => change([id], checked);
function change(ids, checked) {
const targets = ids.filter((id) => byId(id)?.replaceable);
- if (!targets.length) return;
+ // While the switch is being saved, a tick could land in the wrong record.
+ if (!targets.length || S.autoPending !== null) return;
for (const id of targets) S.unsaved.set(id, checked);
render();
flush();
@@ -656,6 +710,7 @@
const result = await callTool("cam_set_selection", {
check: batch.filter(([, checked]) => checked).map(([id]) => id),
uncheck: batch.filter(([, checked]) => !checked).map(([id]) => id),
+ mode: autoOn() ? "auto" : "manual",
});
// An image clicked again meanwhile keeps its newer choice, which the next round saves.
for (const [id, checked] of batch) if (S.unsaved.get(id) === checked) S.unsaved.delete(id);
@@ -672,6 +727,25 @@
render();
}
+ // ---- v0.3: the automatic selection switch, saved at once like a tick ----
+ // Ticks still being saved go first, in the mode they were made in; while the switch saves, no tick is taken.
+ async function setAuto(on) {
+ if (S.autoPending !== null) return;
+ S.autoPending = on;
+ render();
+ try {
+ while (S.saving || S.unsaved.size) { if (!S.saving) await flush(); else await new Promise((resolve) => setTimeout(resolve, 50)); }
+ lastSaveStarted = Date.now();
+ const result = await callTool("cam_set_selection", { auto: on });
+ S.autoPending = null;
+ ingest(result.structuredContent);
+ } catch (error) {
+ S.autoPending = null;
+ S.error = { key: "error.switch", message: error.message };
+ }
+ render();
+ }
+
// ---- a panel opened on a new chat follows the thread its first message starts (v0.1-10) ----
// The plugin offers only threads started while this page was on screen, so a panel left on another new chat does not
// take a task started elsewhere. One: switch to it. Several (e.g. two windows side by side): the user picks one.
@@ -768,6 +842,14 @@
if (!image.inNextRequest) { tags.push([t("tag.gone"), ""]); return tags; }
const checked = isChecked(image);
const sentCopy = sentCopyOf(image);
+ // v0.3: with automatic selection, what the model fetched in the latest turn; an image not pinned is left out by
+ // default, so that needs no word on every row.
+ if (autoOn()) {
+ if (image.fetched) tags.push([t("tag.fetched"), "fetched"]);
+ if (!checked && sentCopy) tags.push([t("tag.replacedBy", { id: sentCopy }), ""]);
+ else if (checked && image.sameAs.length) tags.push([t("tag.sameAs", { id: image.sameAs[0] }), ""]);
+ return tags;
+ }
if (!checked && image.requested) tags.push([t("tag.requested"), "warn"]);
if (!checked) tags.push([sentCopy ? t("tag.replacedBy", { id: sentCopy }) : t("tag.notSent"), ""]);
else if (image.sameAs.length) tags.push([t("tag.sameAs", { id: image.sameAs[0] }), ""]);
@@ -832,7 +914,8 @@
const checked = targets.filter(isChecked).length;
const box = label.querySelector(".check");
box.hidden = targets.length < 2;
- const all = turn === null ? t(filtering() ? "turn.shownEarlier" : "turn.allEarlier") : t(filtering() ? "turn.shown" : "turn.all", { n: turn });
+ const keys = autoOn() ? ["turn.pinShownEarlier", "turn.pinAllEarlier", "turn.pinShown", "turn.pinAll"] : ["turn.shownEarlier", "turn.allEarlier", "turn.shown", "turn.all"];
+ const all = turn === null ? t(filtering() ? keys[0] : keys[1]) : t(filtering() ? keys[2] : keys[3], { n: turn });
box.title = all;
const input = box.querySelector("input");
input.setAttribute("aria-label", all);
@@ -867,7 +950,7 @@
const input = row.querySelector("input");
input.checked = checked;
input.disabled = !image.replaceable;
- input.setAttribute("aria-label", t("row.send", { id: image.id }));
+ input.setAttribute("aria-label", t(autoOn() ? "row.pin" : "row.send", { id: image.id }));
row.querySelector(".check").classList.toggle("locked", !image.replaceable);
const tags = row.querySelector(".tags");
tags.replaceChildren(...tagsOf(image).map(([text, tone]) => {
@@ -896,13 +979,15 @@
}
const f = forecast();
plan.replaceChildren(
- ...rich("plan.next", { sent: f.sent, count: f.sent }, "sent"),
+ ...rich(autoOn() ? "plan.nextAuto" : "plan.next", { sent: f.sent, count: f.sent }, "sent"),
f.dropped ? t("plan.dropped", { dropped: f.dropped, count: f.dropped }) + (f.duplicates ? t("plan.duplicates", { duplicates: f.duplicates, count: f.duplicates }) : "") : "",
f.gone ? t("plan.gone", { gone: f.gone, count: f.gone }) : "",
);
$("meter").hidden = false;
- $("meterLabel").textContent = t(f.whole ? "meter.request" : "meter.images");
- $("meterValue").textContent = formatBytes(f.after);
+ // v0.3: with automatic selection, what the model will fetch comes on top, and is not known beforehand.
+ $("meterLabel").textContent = t(!f.whole ? "meter.images" : autoOn() ? "meter.requestAuto" : "meter.request");
+ $("meterValue").textContent = autoOn() ? t("meter.atLeast", { bytes: formatBytes(f.after) }) : formatBytes(f.after);
+ $("meter").title = autoOn() ? t("meter.autoNote") : "";
const saving = f.after < f.full;
const percent = (1 - f.after / f.full) * 100;
$("meterFull").textContent = saving ? t("meter.full", { full: formatBytes(f.full), percent: percent < 1 ? "<1" : Math.round(percent) }) : t("meter.none");
@@ -994,16 +1079,22 @@
// ---- v0.1-17: the images the model asked for that are not checked (the same test as the row's tag) ----
// Rebuilt only when that list changes, so hover and focus survive the polling.
+ // v0.3: with automatic selection on, the model fetches what it needs itself; the bar lists what it fetched in the
+ // latest turn instead, in blue, and works the same way.
let needsKey = "";
function renderNeeds() {
- const needed = images().filter((image) => image.requested && image.inNextRequest && image.replaceable && !isChecked(image));
+ const auto = autoOn();
+ const needed = auto
+ ? (S.data?.fetched ?? []).map(byId).filter(Boolean)
+ : images().filter((image) => image.requested && image.inNextRequest && image.replaceable && !isChecked(image));
const box = $("needs");
- const key = needed.length ? `${lang}|${needed.map((image) => image.id).join(",")}` : "";
+ const key = needed.length ? `${lang}|${auto}|${needed.map((image) => image.id).join(",")}` : "";
box.hidden = !key;
if (key === needsKey) return;
needsKey = key;
+ box.classList.toggle("fetched", auto);
box.replaceChildren(...(key ? [
- Object.assign(document.createElement("span"), { textContent: t("needs.title", { count: needed.length }) }),
+ Object.assign(document.createElement("span"), { textContent: t(auto ? "fetched.title" : "needs.title", { count: needed.length }) }),
...needed.map((image) => {
const button = Object.assign(document.createElement("button"), { type: "button", textContent: image.id, title: t("needs.jump", { id: image.id }) });
button.addEventListener("click", () => jumpTo(image.id));
@@ -1141,9 +1232,19 @@
for (const image of listed) queueThumb(image.id);
}
- // Always the same line: a check needs no word that it was saved (user 2026-09-28).
+ // Always the same line: a check needs no word that it was saved (user 2026-09-28). v0.3: the automatic selection
+ // switch sits next to it, and the line says what a tick means in each mode.
function renderFooter() {
- $("status").textContent = images().length ? t("footer.hint") : "";
+ const auto = autoOn();
+ $("status").textContent = images().length ? t(auto ? "footer.hintAuto" : "footer.hint") : "";
+ const control = $("auto");
+ control.hidden = !images().length && !S.data?.auto;
+ control.title = t("auto.title");
+ control.querySelector(".auto-label").textContent = t("auto.label");
+ const input = control.querySelector("input");
+ input.checked = auto;
+ input.disabled = S.autoPending !== null;
+ input.setAttribute("aria-label", t("auto.label"));
}
function renderViewer() {
@@ -1157,6 +1258,7 @@
const input = $("viewerCheck").querySelector("input");
input.checked = isChecked(image);
input.disabled = !image.replaceable;
+ $("viewerCheck").querySelector(".label").textContent = t(autoOn() ? "viewer.pin" : "viewer.send");
const stage = $("viewerStage");
const url = S.viewer.url ?? S.thumbs.get(image.id) ?? null;
stage.classList.toggle("loading", S.viewer.loading && !!url);
@@ -1194,6 +1296,7 @@
$("viewerStage").addEventListener("click", (event) => { if (event.target === event.currentTarget) closeViewer(); });
$("viewerCheck").querySelector("input").addEventListener("change", (event) => { if (S.viewer) setChecked(S.viewer.id, event.target.checked); });
document.addEventListener("keydown", (event) => { if (event.key === "Escape" && S.viewer) closeViewer(); });
+ $("auto").querySelector("input").addEventListener("change", (event) => setAuto(event.target.checked));
$("refresh").addEventListener("click", () => refresh(true));
$("filter").addEventListener("click", () => { S.filter.open = !S.filter.open; render(); });
diff --git a/plugin/src/plugin-server.ts b/plugin/src/plugin-server.ts
index 642ae5e..95a1842 100644
--- a/plugin/src/plugin-server.ts
+++ b/plugin/src/plugin-server.ts
@@ -61,7 +61,7 @@ export function toolsFor(lang: Lang) {
name: "cam_set_selection",
title: say(lang, "tool.select.title"),
description: say(lang, "tool.select.description"),
- inputSchema: { type: "object", properties: { ...shared, uncheck: { type: "array", items: { type: "string" } }, check: { type: "array", items: { type: "string" } }, checkAll: { type: "boolean" } } },
+ inputSchema: { type: "object", properties: { ...shared, uncheck: { type: "array", items: { type: "string" } }, check: { type: "array", items: { type: "string" } }, checkAll: { type: "boolean" }, auto: { type: "boolean" }, mode: { type: "string", enum: ["manual", "auto"] } } },
_meta: APP_ONLY,
},
{
@@ -176,7 +176,7 @@ export function callTool(name: string, args: Json, meta: Json | undefined, sessi
}
if (name === "cam_set_selection") {
if (fromModel(meta)) throw new Error(say(lang, "call.modelSelect"));
- const state = applySelection(threadId, { uncheck: args.uncheck, check: args.check, checkAll: args.checkAll }, options);
+ const state = applySelection(threadId, { uncheck: args.uncheck, check: args.check, checkAll: args.checkAll, auto: typeof args.auto === "boolean" ? args.auto : undefined, mode: args.mode === "auto" ? "auto" : "manual" }, options);
return { content: [{ type: "text", text: summary(lang, state) }], structuredContent: panel(state) };
}
if (name === "cam_bind") {
diff --git a/spike/scripts/panel-dev.ts b/spike/scripts/panel-dev.ts
index f424858..f6882ea 100644
--- a/spike/scripts/panel-dev.ts
+++ b/spike/scripts/panel-dev.ts
@@ -8,7 +8,9 @@
// with &newtask=1 the user then starts one task — the panel switches to it — and with &newtask=2 two at once;
// ?thread=gap for a fork whose original task was deleted, v0.1-13; ?lang=en for Codex in English, v0.1-14;
// ?thread=many for a task with 45 images whose last reply asks for two unchecked ones, v0.1-17;
-// ?demo=filter for the filter bar open with PDF pages picked, ?demo=filtered for the same folded away, v0.2).
+// ?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).
// 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
@@ -91,6 +93,19 @@ writeFileSync(join(day, `rollout-2026-09-24T10-00-00-${THREAD}.jsonl`),
{ type: "input_image", image_url: url(phonePage) },
]) + toolImage("c3", "image(await load('chart'));", chart) + say("需要 IMG-001 才能回答。", "t6"));
+// ?thread=auto (v0.3): the same history, then a turn in which the model fetched IMG-004 and IMG-007 with
+// cam_view_image (each image after the line naming it, as the plugin returns them).
+const AUTO = `${THREAD.slice(0, -4)}a070`;
+const sameHistory = readFileSync(join(day, `rollout-2026-09-24T10-00-00-${THREAD}.jsonl`), "utf8").split("\n").slice(1).join("\n");
+const fetchedBy = (callId: string, pairs: Array<[string, Buffer]>) =>
+ line("response_item", { type: "custom_tool_call", call_id: callId, name: "exec", input: `const r = await tools.mcp__codex_attachment_manager__cam_view_image({ids:${JSON.stringify(pairs.map(([label]) => /IMG-\d+/.exec(label)![0]))}}); for (const c of r.content) c.type === "image" ? image(c) : text(c.text);` }) +
+ line("response_item", { type: "custom_tool_call_output", id: `ctco_${callId}`, call_id: callId, output: [{ type: "input_text", text: "Script completed\nOutput:\n" }, ...pairs.flatMap(([label, bytes]) => [{ type: "input_text", text: label }, { type: "input_image", image_url: url(bytes) }])] });
+writeFileSync(join(day, `rollout-2026-09-24T10-30-00-${AUTO}.jsonl`),
+ line("session_meta", { id: AUTO }) + sameHistory +
+ turn("t7") + commented("msg_7", "t7", [{ type: "input_text", text: "按日落图和设置截图的风格,再出一版首页配色" }]) +
+ fetchedBy("c7", [["[图片 IMG-004 取回的原图|sunset.png|生成的图片|第 2 轮|768×512]", sunset], ["[图片 IMG-007 取回的原图|settings-screenshot.png|用户上传|第 4 轮|1280×720]", screenshot]]) +
+ say("新的一版配色在这里:主色沿用日落的橙黄,按钮用设置页的深灰。", "t7"));
+
// ?thread=gap: a fork whose history starts in a page of a task that was deleted since.
const GAP = `${THREAD.slice(0, -4)}0a90`;
writeFileSync(join(day, `rollout-2026-09-24T11-00-00-${GAP}.jsonl`),
@@ -124,6 +139,7 @@ writeFileSync(join(day, `rollout-2026-09-24T12-00-00-${MANY}.jsonl`), manyLog);
// 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" })}
`);
// New tasks the user starts after opening the panel on a new chat (?newtask=): Codex files them in today's folder.
@@ -157,6 +173,10 @@ const meta = { threadId: THREAD, thread_id: THREAD };
callTool("cam_set_selection", { uncheck: ["IMG-001", "IMG-005", "IMG-006"] }, meta, sessionsDir);
const manyMeta = { threadId: MANY, thread_id: MANY };
callTool("cam_set_selection", { uncheck: ["IMG-005", "IMG-012", "IMG-017", "IMG-024", "IMG-032", "IMG-040"] }, manyMeta, sessionsDir);
+// v0.3: automatic selection on, with IMG-002 pinned as a reference the user wants in every turn.
+const autoMeta = { threadId: AUTO, thread_id: AUTO };
+callTool("cam_set_selection", { auto: true }, autoMeta, sessionsDir);
+callTool("cam_set_selection", { check: ["IMG-002"], mode: "auto" }, autoMeta, 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.
@@ -175,6 +195,16 @@ function writeStats(kind: string): void {
if (kind === "websocket") recordRequest(THREAD, { at: new Date().toISOString(), transport: "websocket", event: "active-while-unchecked" }, dir);
}
+// The auto task's last full request came in turn 7: the images of earlier turns were left out, all but IMG-002 (pinned)
+// and the hosted result; the two copies the model fetched went out with it.
+{
+ const items = readFileSync(join(day, `rollout-2026-09-24T10-30-00-${AUTO}.jsonl`), "utf8").trim().split("\n").map((raw) => JSON.parse(raw)).filter((record) => record.type === "response_item").map((record) => record.payload);
+ const sizes = imageSizesOf(items);
+ const before = Object.values(sizes).reduce((sum, chars) => sum + chars, 0) + 180_000;
+ const replaced = ["IMG-001", "IMG-003", "IMG-004", "IMG-005", "IMG-006", "IMG-007", "IMG-009", "IMG-010", "IMG-011", "IMG-012", "IMG-013"].map((id) => ({ id, mode: "plain" }));
+ recordRequest(AUTO, { at: new Date(Date.now() - 2 * 60_000).toISOString(), transport: "http", turnId: "t7", decodedBytes: before, imageSizes: sizes, rewrite: { auto: true, replaced, decodedBefore: before, decodedAfter: Math.round(before * 0.14) } }, requestStatsDirOf(process.env.CAM_DATA_DIR));
+}
+
// ---- the host page: a stand-in for Codex's side panel ----
const HOST = `<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><title>面板开发页</title><style>
body { margin: 0; height: 100vh; display: flex; font: 13px system-ui, "Microsoft YaHei UI", sans-serif; background: #e9e9ec; }
@@ -210,7 +240,7 @@ const HOST = `<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><tit
// ?thread=fresh: a thread that has no rollout, like a panel opened on a new chat whose prepared thread was replaced.
// Each page load gets a thread of its own, so a switch made on an earlier load does not carry over.
const fresh = params.get("thread") === "fresh" ? Math.random().toString(16).slice(2, 6).padEnd(4, "0") : null;
- const query = fresh ? "?fresh=" + fresh : params.get("thread") === "gap" ? "?gap=1" : params.get("thread") === "many" ? "?many=1" : "";
+ const query = fresh ? "?fresh=" + fresh : params.get("thread") === "gap" ? "?gap=1" : params.get("thread") === "many" ? "?many=1" : params.get("thread") === "auto" ? "?auto=1" : "";
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;
@@ -276,7 +306,8 @@ createServer((request, response) => {
const freshId = `${THREAD.slice(0, -4)}${fresh}`;
const gap = new URL(request.url, "http://x").searchParams.has("gap");
const many = new URL(request.url, "http://x").searchParams.has("many");
- const threadMeta = fresh && /^[0-9a-f]{4}$/.test(fresh) ? { threadId: freshId, thread_id: freshId } : gap ? { threadId: GAP, thread_id: GAP } : many ? manyMeta : meta;
+ const auto = new URL(request.url, "http://x").searchParams.has("auto");
+ const threadMeta = fresh && /^[0-9a-f]{4}$/.test(fresh) ? { threadId: freshId, thread_id: freshId } : gap ? { threadId: GAP, thread_id: GAP } : many ? manyMeta : auto ? autoMeta : 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) }] })); }
});
diff --git a/spike/src/panel-state.test.ts b/spike/src/panel-state.test.ts
index 320e9d2..9794405 100644
--- a/spike/src/panel-state.test.ts
+++ b/spike/src/panel-state.test.ts
@@ -130,6 +130,26 @@ test("check and uncheck are kept per thread and validated", () => {
assert.throws(() => applySelection(THREAD, { uncheck: ["IMG-099"] }, options), /not an image of this thread/);
});
+test("with automatic selection on, a tick pins, and the latest turn's fetches are listed (v0.3)", () => {
+ // Turn 3: the model fetched IMG-001 with cam_view_image.
+ const fetched = turn("t3") +
+ line("response_item", { type: "custom_tool_call", call_id: "c3", name: "exec", input: 'await tools.mcp__codex_attachment_manager__cam_view_image({ids:["IMG-001"]})' }) +
+ line("response_item", { type: "custom_tool_call_output", call_id: "c3", output: [{ type: "input_text", text: "[图片 IMG-001 取回的原图|a.png|用户上传|第 1 轮|64×32]" }, { type: "input_image", image_url: `data:image/png;base64,${red.toString("base64")}` }] });
+ const options = sampleSessions(fetched);
+ applySelection(THREAD, { uncheck: ["IMG-003"] }, options);
+ let state = applySelection(THREAD, { auto: true }, options);
+ assert.deepEqual([state.auto, state.fetched, state.images.length], [true, ["IMG-001"], 3], "the copy is no row of its own");
+ assert.deepEqual(state.images.map((image) => [image.id, image.checked, image.fetched]), [["IMG-001", false, true], ["IMG-002", false, false], ["IMG-003", false, false]]);
+ state = applySelection(THREAD, { check: ["IMG-002"], mode: "auto" }, options);
+ assert.deepEqual(state.images.map((image) => image.checked), [false, true, false]);
+ assert.equal(state.totals.unchecked, 2);
+ // Switched off, the manual ticks are back as they were; switched on again, so is the pin.
+ state = applySelection(THREAD, { auto: false }, options);
+ assert.deepEqual([state.auto, state.images.map((image) => image.checked)], [false, [true, true, false]]);
+ assert.deepEqual(loadPanelState(THREAD, { ...options }).images.map((image) => image.checked), [true, true, false]);
+ assert.deepEqual(applySelection(THREAD, { auto: true }, options).images.map((image) => image.checked), [false, true, false]);
+});
+
test("checking and unchecking keep automatic selection's switch and pins (v0.3)", () => {
const options = sampleSessions();
const dir = join(options.dataRoot, "selection");