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(claude): Claude 面板改经引擎的本机接口读写

chipfighterc2f6546f3c9d
diff --git a/hooks/register.js b/hooks/register.js
index d68ba86..63a26f3 100644
--- a/hooks/register.js
+++ b/hooks/register.js
@@ -7,12 +7,14 @@
// the engine forwards the same headers to api.anthropic.com.
// 2. The panel. /cam opens a pane listing the session's images by turn, with thumbnails, a check box each, a check box
// per turn, automatic selection and a preview, like the Codex panel (plugin/src/panel.html). It reads and changes
-// everything through the plugin service ($.mcp.call), never through the model.
+// everything through the engine's local panel API (proxy.ts, claudePanelApi), never through the model: a mod
+// reaches the plugin's MCP server only through Claude Code's tool permissions, a prompt for every call.
// Also: the model's cam_view_image call gets this session's id (the service may outlive a /clear or /resume).
-// Input: mod events. Output: env changes for this process, a pane, tool calls to the plugin's own MCP server.
+// Input: mod events. Output: env changes for this process, a pane, requests to the engine on 127.0.0.1.
const PLUGIN = 'codex-attachment-manager'
-const SERVER_KEY = 'codex_attachment_manager'
+// The engine's port (engine.ts, DEFAULT_PORT); the plugin's MCP server starts the engine on it.
+const ENGINE_PORT = 17891
const PANE = 'cam'
const PREVIEW = 'cam-preview'
const ROUTING = { plugin: 'codex-attachment-manager', key: 'routing' }
@@ -80,9 +82,8 @@ const WORDS = {
},
}
-// What the panel shows, kept between redraws: the plugin service's latest answer for the session, thumbnails by
-// session and id, the open preview, and whether the pane is open.
-let server = null
+// What the panel shows, kept between redraws: the engine's latest answer for the session, thumbnails by session and
+// id, the open preview, and whether the pane is open.
let panel = null
let panelSession = null
let lastError = null
@@ -94,22 +95,15 @@ let routingState = null
const thumbs = new Map()
const previews = new Map()
-async function serverName($) {
- if (server) return server
- const connected = await $.mcp.connect(SERVER_KEY)
- if (connected.isConnected) server = connected.server
- return server
-}
-
-// The plugin service answers the mod in JSON text (plugin-server.ts, callClaudeTool).
-async function call($, tool, args = {}) {
- const name = await serverName($)
- if (!name) throw new Error('the plugin service is not connected')
- const result = await $.mcp.call(name, tool, args)
- const text = (result.content ?? []).find((block) => block.type === 'text')?.text ?? ''
- if (result.isError) throw new Error(text || 'error')
- return JSON.parse(text)
+// The engine's panel API answers in JSON; the header marks a request as the panel's (a browser page cannot send it).
+async function api($, path, init = {}) {
+ const response = await $.http.fetch(`http://127.0.0.1:${ENGINE_PORT}${path}`, { ...init, headers: { 'x-cam-panel': '1', ...(init.headers ?? {}) } })
+ let body = null
+ try { body = response.text ? JSON.parse(response.text) : null } catch { body = null }
+ if (!response.ok) throw new Error(body?.error ?? `HTTP ${response.status}`)
+ return body
}
+const query = (params) => Object.entries(params).map(([key, value]) => `${key}=${encodeURIComponent(String(value))}`).join('&')
const words = () => WORDS[panel?.lang === 'en' ? 'en' : 'zh']
@@ -139,20 +133,18 @@ async function startRouting($) {
const providers = [await $.env.get('CLAUDE_CODE_USE_BEDROCK'), await $.env.get('CLAUDE_CODE_USE_VERTEX'), await $.env.get('CLAUDE_CODE_USE_FOUNDRY')]
if (providers.some((value) => value && value !== '0')) return writeRouting($, { active: false, port: null, originalBaseUrl: null, originalNoProxy: null, originalNoProxyLower: null, reason: 'provider' })
await writeRouting($, { active: false, port: null, originalBaseUrl: null, originalNoProxy: null, originalNoProxyLower: null, reason: 'waiting' })
- // The plugin service starts the engine with the session; wait for it to answer.
+ // The plugin's MCP server starts the engine with the session; wait for it to answer. An engine started by an older
+ // copy of the plugin (Codex's, not updated yet) does not forward Claude's requests: leave the session alone then.
let port = null
let reason = 'no-engine'
- for (let attempt = 0; attempt < 60 && port === null; attempt++) {
+ for (let attempt = 0; attempt < 60 && port === null && reason !== 'engine-old'; attempt++) {
try {
- const info = await call($, 'cam_engine', {})
- if (info.port) {
- const health = await $.http.fetch(`http://127.0.0.1:${info.port}/__cam/health`)
- const body = health.ok ? JSON.parse(health.text) : null
- if (body?.service === PLUGIN && Array.isArray(body.upstreams) && body.upstreams.includes('api.anthropic.com')) port = info.port
- else if (body?.service === PLUGIN) reason = 'engine-old'
- }
- } catch { /* the service or the engine is still starting */ }
- if (port === null) await $.clock.sleep(500)
+ const health = await $.http.fetch(`http://127.0.0.1:${ENGINE_PORT}/__cam/health`)
+ const body = health.ok ? JSON.parse(health.text) : null
+ if (body?.service === PLUGIN && Array.isArray(body.upstreams) && body.upstreams.includes('api.anthropic.com')) port = ENGINE_PORT
+ else if (body?.service === PLUGIN) reason = 'engine-old'
+ } catch { /* the engine is still starting */ }
+ if (port === null && reason !== 'engine-old') await $.clock.sleep(500)
}
if (port === null) return writeRouting($, { active: false, port: null, originalBaseUrl: null, originalNoProxy: null, originalNoProxyLower: null, reason })
const originalNoProxy = await $.env.get('NO_PROXY')
@@ -188,12 +180,12 @@ async function refresh($) {
try {
const sessionId = await $.session.id()
if (sessionId !== panelSession) { thumbs.clear(); previews.clear(); panelSession = sessionId }
- panel = await call($, 'cam_panel', { sessionId })
+ panel = await api($, `/__cam/claude/panel?${query({ session: sessionId })}`)
lastError = null
for (const image of panel.images) {
const key = `${sessionId}:${image.id}`
if (thumbs.has(key)) continue
- try { thumbs.set(key, (await call($, 'cam_image', { sessionId, id: image.id, maxSide: THUMB_SIDE })).dataUrl) } catch { thumbs.set(key, null) }
+ try { thumbs.set(key, (await api($, `/__cam/claude/image?${query({ session: sessionId, id: image.id, max: THUMB_SIDE })}`)).dataUrl) } catch { thumbs.set(key, null) }
}
} catch (error) {
lastError = String(error?.message ?? error)
@@ -205,7 +197,7 @@ async function refresh($) {
async function change($, args) {
try {
- panel = await call($, 'cam_set_selection', { sessionId: await $.session.id(), ...args })
+ panel = await api($, `/__cam/claude/select?${query({ session: await $.session.id() })}`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(args) })
lastError = null
} catch (error) {
lastError = String(error?.message ?? error)
@@ -226,7 +218,7 @@ async function openPreview($, id) {
const sessionId = await $.session.id()
const key = `${sessionId}:${id}`
if (!previews.has(key)) {
- try { previews.set(key, (await call($, 'cam_image', { sessionId, id, maxSide: PREVIEW_SIDE })).dataUrl) } catch { previews.set(key, null) }
+ try { previews.set(key, (await api($, `/__cam/claude/image?${query({ session: sessionId, id, max: PREVIEW_SIDE })}`)).dataUrl) } catch { previews.set(key, null) }
}
await $.ui.open({ id: PREVIEW, title: id, focus: true, closeOnEscape: true })
await $.ui.invalidate('ui.render')
diff --git a/plugin/src/plugin-server.ts b/plugin/src/plugin-server.ts
index b332027..2fd6efa 100644
--- a/plugin/src/plugin-server.ts
+++ b/plugin/src/plugin-server.ts
@@ -28,12 +28,12 @@ import { fileURLToPath } from "node:url";
import { codexHome } from "./codexconfig.ts";
import { bindThread, isUserThread, newThreads, resolveThread } from "./binding.ts";
import { loadClaudeIndex } from "./claude-index.ts";
-import { DEFAULT_PORT, ensureEngine, type Health } from "./engine.ts";
+import { DEFAULT_PORT, ensureEngine } from "./engine.ts";
import { isEntryPoint } from "./entry.ts";
import { currentLang, langOf, rememberLang, type Lang } from "./language.ts";
import { say } from "./messages.ts";
import { migrateDataOnce } from "./migrate-data.ts";
-import { applyClaudeSelection, applySelection, claudeImageFor, imageFor, loadClaudePanelState, loadPanelState, type ClaudePanelOptions, type PanelState } from "./panel-state.ts";
+import { applySelection, claudeImageFor, imageFor, loadPanelState, type ClaudePanelOptions, type PanelState } from "./panel-state.ts";
import { claudeSelectionDirOf, dataDir, pixelCacheDirOf, selectionDirOf } from "./paths.ts";
import { fetchedLabel, fetchWords } from "./rewrite.ts";
import { effectiveSelection, readSelection } from "./selection.ts";
@@ -102,8 +102,9 @@ export function toolsFor(lang: Lang) {
}
export const TOOLS = toolsFor("zh");
-// v0.4: under Claude Code. Claude Code lists a plugin's tools to the model, so only the fetch tool is listed; the mod
-// calls the panel's tools (and cam_engine) by name, and the model cannot change the user's selection.
+// v0.4: under Claude Code only the model's fetch tool is listed. The Claude panel (the mod) reads and changes a
+// session's state through the engine (proxy.ts, claudePanelApi): a mod reaches an MCP server only through Claude Code's
+// tool permissions, a prompt for every call, and Claude Code registers no app-only tool at all.
export const HOST: "codex" | "claude" = process.env.CAM_HOST === "claude" ? "claude" : "codex";
export const claudeToolsFor = (lang: Lang) => toolsFor(lang).filter((tool) => tool.name === "cam_view_image");
@@ -122,10 +123,8 @@ export function readResource(uri: string): Json {
return { contents: [{ uri, mimeType: PANEL_MIME, text, _meta: { ui: { csp: { connectDomains: [], resourceDomains: [] }, prefersBorder: false } } }] };
}
-// Whether this instance last found the engine running; null until the first check (and in tests). v0.4: and what the
-// engine said about itself then (the Claude plugin's mod switches only to an engine that forwards Claude's requests).
+// Whether this instance last found the engine running; null until the first check (and in tests).
let engineRunning: boolean | null = null;
-let lastHealth: Health | null = null;
const enginePort = Number(process.env.CAM_ENGINE_PORT ?? DEFAULT_PORT);
// v0.1-5: whether config.toml points Codex at the engine, and whether that differs from what it said when this instance
// started (about when Codex read it): only a difference waits for a restart, so 停用 then 启用 again needs none.
@@ -241,25 +240,14 @@ export function callTool(name: string, args: Json, meta: Json | undefined, sessi
throw new Error(`unknown tool ${name}`);
}
-// v0.4: the tools under Claude Code. The mod reads results as JSON text: Claude Code hands a mod the content blocks,
-// and structuredContent only for tools that declare an output schema.
+// v0.4: the model's fetch tool under Claude Code. The session is the one the call names (the mod adds it), else the
+// one Claude Code started this service for.
const SESSION_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
-const asJson = (data: Json) => ({ content: [{ type: "text", text: JSON.stringify(data) }], structuredContent: data });
export function callClaudeTool(name: string, args: Json, options: ClaudePanelOptions = {}, env: NodeJS.ProcessEnv = process.env): Json {
const lang = langOf(args.lang) ?? currentLang();
- if (name === "cam_engine") return asJson({ port: enginePort, running: engineRunning, health: lastHealth, lang });
const sessionId = String(args.sessionId ?? env.CLAUDE_CODE_SESSION_ID ?? "");
if (!SESSION_ID.test(sessionId)) throw new Error(say(lang, "call.noThread"));
- const panel = (state: PanelState) => asJson({ ...state, engineRunning, port: enginePort, lang });
- if (name === "cam_panel") return panel(loadClaudePanelState(sessionId, options));
- if (name === "cam_set_selection") {
- return panel(applyClaudeSelection(sessionId, { uncheck: args.uncheck, check: args.check, checkAll: args.checkAll, auto: typeof args.auto === "boolean" ? args.auto : undefined, mode: args.mode === "auto" ? "auto" : "manual" }, options));
- }
- if (name === "cam_image") {
- const image = claudeImageFor(sessionId, String(args.id), Number(args.maxSide ?? 160), options);
- return asJson({ id: image.id, available: image.dataUrl !== null, dataUrl: image.dataUrl });
- }
if (name === "cam_view_image") {
const words = fetchWords(lang);
const ids: string[] = Array.isArray(args.ids) ? args.ids.map(String) : typeof args.id === "string" ? [args.id] : [];
@@ -297,7 +285,6 @@ function main(): void {
if (result.state !== "running" || engineState !== "running") log({ event: "engine", host: HOST, state: result.state, enginePid: result.health?.pid ?? null, build: result.health?.build ?? null, ...replaced });
engineState = result.state;
engineRunning = result.state !== "failed";
- lastHealth = result.health;
};
log({ event: "start", ppid: process.ppid, host: HOST });
setupState(); // what Codex read when it started this session
diff --git a/plugin/src/proxy.ts b/plugin/src/proxy.ts
index d4d423d..0b1e4c6 100644
--- a/plugin/src/proxy.ts
+++ b/plugin/src/proxy.ts
@@ -32,6 +32,7 @@ import { findImages, type ImageRef } from "./images.ts";
import { isEntryPoint } from "./entry.ts";
import { currentLang } from "./language.ts";
import { migrateDataOnce } from "./migrate-data.ts";
+import { applyClaudeSelection, claudeImageFor, loadClaudePanelState, type ClaudePanelOptions } from "./panel-state.ts";
import { claudeRequestStatsDirOf, claudeSelectionDirOf, dataDir, pixelCacheDirOf, proxyLogDirOf } from "./paths.ts";
import { recordRequest } from "./request-stats.ts";
import { rewriteItems, type Described } from "./rewrite.ts";
@@ -358,6 +359,37 @@ export function rewriteClaudeBody(original: Buffer, encoding: string | undefined
return { body, report: { ...summary, decodedBefore: decoded.length, decodedAfter: next.length, encodedBefore: original.length, encodedAfter: body.length } };
}
+// v0.4: the Claude plugin's panel reads and changes a session's images here (hooks/register.js). The Codex panel goes
+// through the plugin's MCP server; a Claude mod can reach that server only through Claude Code's tool permissions (a
+// prompt for every call, and none at all for app-only tools), so it asks the engine, the one local HTTP service.
+// Loopback only, like everything the engine serves. A page in a browser cannot use it: it would send an Origin header,
+// and our own header makes its request one the browser asks about first, which the engine never answers.
+const SESSION_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
+export function claudePanelApi(method: string, url: string, headers: IncomingHttpHeaders, body: string | null, options: ClaudePanelOptions = {}): { status: number; body: Json } {
+ if (headers.origin !== undefined || headers["x-cam-panel"] !== "1") return { status: 403, body: { error: "forbidden" } };
+ const parsed = new URL(url, "http://localhost");
+ const session = parsed.searchParams.get("session") ?? "";
+ if (!SESSION_ID.test(session)) return { status: 400, body: { error: "no session" } };
+ const lang = currentLang();
+ try {
+ if (method === "GET" && parsed.pathname === "/__cam/claude/panel") return { status: 200, body: { ...loadClaudePanelState(session, options), lang } };
+ if (method === "GET" && parsed.pathname === "/__cam/claude/image") {
+ const max = Number(parsed.searchParams.get("max") ?? 160);
+ return { status: 200, body: claudeImageFor(session, String(parsed.searchParams.get("id") ?? ""), Number.isFinite(max) && max > 0 ? max : 160, options) };
+ }
+ if (method === "POST" && parsed.pathname === "/__cam/claude/select") {
+ if (body === null) return { status: 413, body: { error: "too large" } };
+ const change = JSON.parse(body || "{}");
+ const list = (value: unknown) => (Array.isArray(value) ? value.map(String) : undefined);
+ const state = applyClaudeSelection(session, { uncheck: list(change.uncheck), check: list(change.check), checkAll: change.checkAll === true, auto: typeof change.auto === "boolean" ? change.auto : undefined, mode: change.mode === "auto" ? "auto" : "manual" }, options);
+ return { status: 200, body: { ...state, lang } };
+ }
+ return { status: 404, body: { error: "not found" } };
+ } catch (error) {
+ return { status: 400, body: { error: error instanceof Error ? error.message : String(error) } };
+ }
+}
+
async function main(): Promise<void> {
migrateDataOnce(); // v0.1-15: Windows moved the data folder
const portIndex = process.argv.indexOf("--port");
@@ -466,6 +498,18 @@ async function main(): Promise<void> {
retire(String(req.headers["x-cam-build"] ?? ""));
return;
}
+ // v0.4: the Claude plugin's panel (claudePanelApi).
+ if ((req.url ?? "").startsWith("/__cam/claude/")) {
+ const chunks: Buffer[] = [];
+ let size = 0;
+ req.on("data", (chunk: Buffer) => { size += chunk.length; if (size <= 64 * 1024) chunks.push(chunk); });
+ req.on("end", () => {
+ const answer = claudePanelApi(req.method ?? "GET", req.url ?? "/", req.headers, size <= 64 * 1024 ? Buffer.concat(chunks).toString("utf8") : null);
+ res.writeHead(answer.status, { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" });
+ res.end(JSON.stringify(answer.body));
+ });
+ return;
+ }
inFlight++;
res.on("close", () => { inFlight--; });
// Once retired, no connection stays open for a next request.
diff --git a/spike/src/claude-panel.test.ts b/spike/src/claude-panel.test.ts
index a893777..6c62272 100644
--- a/spike/src/claude-panel.test.ts
+++ b/spike/src/claude-panel.test.ts
@@ -1,6 +1,7 @@
-// Purpose: v0.4 — the plugin service under Claude Code (callClaudeTool in plugin-server.ts): the panel's data for a
-// session, checking and unchecking, images for thumbnails, automatic selection and the model's cam_view_image, all
-// from the session's transcript and the selection kept for Claude sessions.
+// Purpose: v0.4 — the Claude panel's data: the engine's local panel API (claudePanelApi in proxy.ts) for a session's
+// images, checking and unchecking, images for thumbnails and automatic selection; and the plugin service's
+// cam_view_image under Claude Code (callClaudeTool in plugin-server.ts). All from the session's transcript and the
+// selection kept for Claude sessions.
// Input: a synthetic transcript under a temporary Claude config dir and a temporary data dir; output: assertions only.
import assert from "node:assert/strict";
@@ -8,12 +9,14 @@ import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
-import { callClaudeTool, claudeToolsFor } from "../../plugin/src/plugin-server.ts";
import { claudeSelectionDirOf } from "../../plugin/src/paths.ts";
+import { callClaudeTool, claudeToolsFor } from "../../plugin/src/plugin-server.ts";
+import { claudePanelApi } from "../../plugin/src/proxy.ts";
import { pngC, usualSession } from "./claude-fixtures.ts";
process.env.CAM_LANG = "zh";
const session = "11111111-2222-4333-8444-555555555555";
+const panelHeaders = { "x-cam-panel": "1" };
function setup() {
const home = mkdtempSync(join(tmpdir(), "cam-claude-home-"));
@@ -23,38 +26,49 @@ function setup() {
writeFileSync(join(home, "projects", "D--work", `${session}.jsonl`), t.records.map((record) => JSON.stringify(record)).join("\n") + "\n");
return { options: { home, dataRoot }, p1 };
}
-const json = (result: any) => JSON.parse(result.content[0].text);
+const get = (path: string, options: object) => claudePanelApi("GET", path, panelHeaders, "", options);
+const post = (path: string, change: object, options: object) => claudePanelApi("POST", path, panelHeaders, JSON.stringify(change), options);
test("under Claude Code only the fetch tool is listed for the model", () => {
assert.deepEqual(claudeToolsFor("zh").map((tool) => tool.name), ["cam_view_image"]);
});
-test("the panel's data for a session: images, turns, title, the ids the reply asked for", () => {
+test("the panel API answers only the panel: our header, no browser Origin, a session id", () => {
+ const { options } = setup();
+ assert.equal(claudePanelApi("GET", `/__cam/claude/panel?session=${session}`, {}, "", options).status, 403);
+ assert.equal(claudePanelApi("GET", `/__cam/claude/panel?session=${session}`, { ...panelHeaders, origin: "https://example.com" }, "", options).status, 403);
+ assert.equal(get("/__cam/claude/panel?session=nope", options).status, 400);
+ assert.equal(get(`/__cam/claude/other?session=${session}`, options).status, 404);
+ assert.equal(claudePanelApi("POST", `/__cam/claude/select?session=${session}`, panelHeaders, null, options).status, 413);
+});
+
+test("the panel's data for a session: images, turns, title, the language", () => {
const { options } = setup();
- const state = json(callClaudeTool("cam_panel", { sessionId: session }, options));
- assert.deepEqual(state.images.map((image: any) => [image.id, image.kind, image.turn, image.checked]), [["IMG-001", "upload", 1, true], ["IMG-002", "upload", 1, true], ["IMG-003", "view", 2, true], ["IMG-004", "upload", 3, true]]);
- assert.equal(state.title, "What are these?");
- assert.equal(state.started, true);
- assert.deepEqual(state.images[0].sameAs, ["IMG-004"]);
- assert.equal(state.turns, 3);
- assert.equal(state.auto, false);
+ const { status, body } = get(`/__cam/claude/panel?session=${session}`, options);
+ assert.equal(status, 200);
+ assert.deepEqual(body.images.map((image: any) => [image.id, image.kind, image.turn, image.checked]), [["IMG-001", "upload", 1, true], ["IMG-002", "upload", 1, true], ["IMG-003", "view", 2, true], ["IMG-004", "upload", 3, true]]);
+ assert.equal(body.title, "What are these?");
+ assert.equal(body.started, true);
+ assert.deepEqual(body.images[0].sameAs, ["IMG-004"]);
+ assert.equal(body.turns, 3);
+ assert.equal(body.auto, false);
+ assert.equal(body.lang, "zh");
});
test("unchecking and checking again are written to the Claude selection, by key", () => {
const { options, p1 } = setup();
- const state = json(callClaudeTool("cam_set_selection", { sessionId: session, uncheck: ["IMG-002"] }, options));
- assert.equal(state.totals.unchecked, 1);
+ const off = post(`/__cam/claude/select?session=${session}`, { uncheck: ["IMG-002"] }, options);
+ assert.equal(off.body.totals.unchecked, 1);
const file = JSON.parse(readFileSync(join(claudeSelectionDirOf(options.dataRoot), `${session}.json`), "utf8"));
assert.deepEqual(Object.keys(file.unchecked), [`${p1}#1`]);
- assert.equal(json(callClaudeTool("cam_set_selection", { sessionId: session, check: ["IMG-002"] }, options)).totals.unchecked, 0);
- assert.throws(() => callClaudeTool("cam_panel", { sessionId: "not-a-session" }, options));
+ assert.equal(post(`/__cam/claude/select?session=${session}`, { check: ["IMG-002"] }, options).body.totals.unchecked, 0);
+ assert.equal(post(`/__cam/claude/select?session=${session}`, { uncheck: ["IMG-099"] }, options).status, 400);
});
test("images for thumbnails come from the transcript", () => {
const { options } = setup();
- const image = json(callClaudeTool("cam_image", { sessionId: session, id: "IMG-003", maxSide: 160 }, options));
- assert.equal(image.available, true);
- assert.equal(image.dataUrl, `data:image/png;base64,${pngC}`);
+ const { body } = get(`/__cam/claude/image?session=${session}&id=IMG-003&max=72`, options);
+ assert.equal(body.dataUrl, `data:image/png;base64,${pngC}`);
});
test("cam_view_image works only with automatic selection on, and returns the original after its label", () => {
@@ -62,17 +76,12 @@ test("cam_view_image works only with automatic selection on, and returns the ori
const off = callClaudeTool("cam_view_image", { sessionId: session, ids: ["IMG-003"] }, options);
assert.equal(off.isError, true);
assert.match(off.content[0].text, /没有开自动选图/);
- callClaudeTool("cam_set_selection", { sessionId: session, auto: true }, options);
+ assert.equal(post(`/__cam/claude/select?session=${session}`, { auto: true }, options).body.auto, true);
const on = callClaudeTool("cam_view_image", { sessionId: session, ids: ["img-003", "IMG-099"] }, options);
assert.equal(on.isError, false);
assert.match(on.content[0].text, /^\[图片 IMG-003 取回的原图|c\.png|工具查看的图片|第 2 轮|16×8\]$/);
assert.deepEqual(on.content[1], { type: "image", data: pngC, mimeType: "image/png" });
assert.match(on.content[2].text, /没有 IMG-099/);
-});
-
-test("the session comes from the call, else from the session Claude Code started the service for", () => {
- const { options } = setup();
- assert.equal(json(callClaudeTool("cam_panel", {}, options, { CLAUDE_CODE_SESSION_ID: session })).images.length, 4);
- const engine = json(callClaudeTool("cam_engine", {}, options));
- assert.equal(typeof engine.port, "number");
+ // Without a session in the call, the one Claude Code started the service for.
+ assert.equal(callClaudeTool("cam_view_image", { ids: ["IMG-003"] }, options, { CLAUDE_CODE_SESSION_ID: session }).isError, false);
});